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"
190 #ifdef HAVE_X_WINDOWS
197 #define min(a, b) ((a) < (b) ? (a) : (b))
198 #define max(a, b) ((a) > (b) ? (a) : (b))
200 #define INFINITY 10000000
202 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
203 extern void set_frame_menubar ();
204 extern int pending_menu_activation
;
207 extern int interrupt_input
;
208 extern int command_loop_level
;
210 extern int minibuffer_auto_raise
;
212 extern Lisp_Object Qface
;
214 extern Lisp_Object Voverriding_local_map
;
215 extern Lisp_Object Voverriding_local_map_menu_flag
;
216 extern Lisp_Object Qmenu_item
;
218 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
219 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
220 Lisp_Object Qredisplay_end_trigger_functions
;
221 Lisp_Object Qinhibit_point_motion_hooks
;
222 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
223 Lisp_Object Qfontified
;
225 /* Functions called to fontify regions of text. */
227 Lisp_Object Vfontification_functions
;
228 Lisp_Object Qfontification_functions
;
230 /* Non-zero means draw tool bar buttons raised when the mouse moves
233 int auto_raise_tool_bar_buttons_p
;
235 /* Margin around tool bar buttons in pixels. */
237 int tool_bar_button_margin
;
239 /* Thickness of shadow to draw around tool bar buttons. */
241 int tool_bar_button_relief
;
243 /* Non-zero means automatically resize tool-bars so that all tool-bar
244 items are visible, and no blank lines remain. */
246 int auto_resize_tool_bars_p
;
248 /* Non-nil means don't actually do any redisplay. */
250 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
252 /* Names of text properties relevant for redisplay. */
254 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
255 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
257 /* Symbols used in text property values. */
259 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
260 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
262 extern Lisp_Object Qheight
;
264 /* Non-nil means highlight trailing whitespace. */
266 Lisp_Object Vshow_trailing_whitespace
;
268 /* Name of the face used to highlight trailing whitespace. */
270 Lisp_Object Qtrailing_whitespace
;
272 /* The symbol `image' which is the car of the lists used to represent
277 /* Non-zero means print newline to stdout before next mini-buffer
280 int noninteractive_need_newline
;
282 /* Non-zero means print newline to message log before next message. */
284 static int message_log_need_newline
;
287 /* The buffer position of the first character appearing entirely or
288 partially on the line of the selected window which contains the
289 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
290 redisplay optimization in redisplay_internal. */
292 static struct text_pos this_line_start_pos
;
294 /* Number of characters past the end of the line above, including the
295 terminating newline. */
297 static struct text_pos this_line_end_pos
;
299 /* The vertical positions and the height of this line. */
301 static int this_line_vpos
;
302 static int this_line_y
;
303 static int this_line_pixel_height
;
305 /* X position at which this display line starts. Usually zero;
306 negative if first character is partially visible. */
308 static int this_line_start_x
;
310 /* Buffer that this_line_.* variables are referring to. */
312 static struct buffer
*this_line_buffer
;
314 /* Nonzero means truncate lines in all windows less wide than the
317 int truncate_partial_width_windows
;
319 /* A flag to control how to display unibyte 8-bit character. */
321 int unibyte_display_via_language_environment
;
323 /* Nonzero means we have more than one non-mini-buffer-only frame.
324 Not guaranteed to be accurate except while parsing
325 frame-title-format. */
329 Lisp_Object Vglobal_mode_string
;
331 /* Marker for where to display an arrow on top of the buffer text. */
333 Lisp_Object Voverlay_arrow_position
;
335 /* String to display for the arrow. Only used on terminal frames. */
337 Lisp_Object Voverlay_arrow_string
;
339 /* Values of those variables at last redisplay. However, if
340 Voverlay_arrow_position is a marker, last_arrow_position is its
341 numerical position. */
343 static Lisp_Object last_arrow_position
, last_arrow_string
;
345 /* Like mode-line-format, but for the title bar on a visible frame. */
347 Lisp_Object Vframe_title_format
;
349 /* Like mode-line-format, but for the title bar on an iconified frame. */
351 Lisp_Object Vicon_title_format
;
353 /* List of functions to call when a window's size changes. These
354 functions get one arg, a frame on which one or more windows' sizes
357 static Lisp_Object Vwindow_size_change_functions
;
359 Lisp_Object Qmenu_bar_update_hook
;
361 /* Nonzero if overlay arrow has been displayed once in this window. */
363 static int overlay_arrow_seen
;
365 /* Nonzero means highlight the region even in nonselected windows. */
367 int highlight_nonselected_windows
;
369 /* If cursor motion alone moves point off frame, try scrolling this
370 many lines up or down if that will bring it back. */
372 static int scroll_step
;
374 /* Non-0 means scroll just far enough to bring point back on the
375 screen, when appropriate. */
377 static int scroll_conservatively
;
379 /* Recenter the window whenever point gets within this many lines of
380 the top or bottom of the window. This value is translated into a
381 pixel value by multiplying it with CANON_Y_UNIT, which means that
382 there is really a fixed pixel height scroll margin. */
386 /* Number of windows showing the buffer of the selected window (or
387 another buffer with the same base buffer). keyboard.c refers to
392 /* Vector containing glyphs for an ellipsis `...'. */
394 static Lisp_Object default_invis_vector
[3];
396 /* Nonzero means display mode line highlighted. */
398 int mode_line_inverse_video
;
400 /* Prompt to display in front of the mini-buffer contents. */
402 Lisp_Object minibuf_prompt
;
404 /* Width of current mini-buffer prompt. Only set after display_line
405 of the line that contains the prompt. */
407 int minibuf_prompt_width
;
408 int minibuf_prompt_pixel_width
;
410 /* This is the window where the echo area message was displayed. It
411 is always a mini-buffer window, but it may not be the same window
412 currently active as a mini-buffer. */
414 Lisp_Object echo_area_window
;
416 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
417 pushes the current message and the value of
418 message_enable_multibyte on the stack, the function restore_message
419 pops the stack and displays MESSAGE again. */
421 Lisp_Object Vmessage_stack
;
423 /* Nonzero means multibyte characters were enabled when the echo area
424 message was specified. */
426 int message_enable_multibyte
;
428 /* True if we should redraw the mode lines on the next redisplay. */
430 int update_mode_lines
;
432 /* Nonzero if window sizes or contents have changed since last
433 redisplay that finished */
435 int windows_or_buffers_changed
;
437 /* Nonzero after display_mode_line if %l was used and it displayed a
440 int line_number_displayed
;
442 /* Maximum buffer size for which to display line numbers. */
444 static int line_number_display_limit
;
446 /* line width to consider when repostioning for line number display */
448 static int line_number_display_limit_width
;
450 /* Number of lines to keep in the message log buffer. t means
451 infinite. nil means don't log at all. */
453 Lisp_Object Vmessage_log_max
;
455 /* Current, index 0, and last displayed echo area message. Either
456 buffers from echo_buffers, or nil to indicate no message. */
458 Lisp_Object echo_area_buffer
[2];
460 /* The buffers referenced from echo_area_buffer. */
462 static Lisp_Object echo_buffer
[2];
464 /* A vector saved used in with_area_buffer to reduce consing. */
466 static Lisp_Object Vwith_echo_area_save_vector
;
468 /* Non-zero means display_echo_area should display the last echo area
469 message again. Set by redisplay_preserve_echo_area. */
471 static int display_last_displayed_message_p
;
473 /* Nonzero if echo area is being used by print; zero if being used by
476 int message_buf_print
;
478 /* Maximum height for resizing mini-windows. Either a float
479 specifying a fraction of the available height, or an integer
480 specifying a number of lines. */
482 static Lisp_Object Vmax_mini_window_height
;
484 /* Non-zero means we want a hollow cursor in windows that are not
485 selected. Zero means there's no cursor in such windows. */
487 int cursor_in_non_selected_windows
;
489 /* A scratch glyph row with contents used for generating truncation
490 glyphs. Also used in direct_output_for_insert. */
492 #define MAX_SCRATCH_GLYPHS 100
493 struct glyph_row scratch_glyph_row
;
494 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
496 /* Ascent and height of the last line processed by move_it_to. */
498 static int last_max_ascent
, last_height
;
500 /* The maximum distance to look ahead for text properties. Values
501 that are too small let us call compute_char_face and similar
502 functions too often which is expensive. Values that are too large
503 let us call compute_char_face and alike too often because we
504 might not be interested in text properties that far away. */
506 #define TEXT_PROP_DISTANCE_LIMIT 100
508 /* Non-zero means print traces of redisplay if compiled with
512 int trace_redisplay_p
;
515 /* Non-zero means automatically scroll windows horizontally to make
518 int automatic_hscrolling_p
;
520 /* Value returned from text property handlers (see below). */
525 HANDLED_RECOMPUTE_PROPS
,
526 HANDLED_OVERLAY_STRING_CONSUMED
,
530 /* A description of text properties that redisplay is interested
535 /* The name of the property. */
538 /* A unique index for the property. */
541 /* A handler function called to set up iterator IT from the property
542 at IT's current position. Value is used to steer handle_stop. */
543 enum prop_handled (*handler
) P_ ((struct it
*it
));
546 static enum prop_handled handle_face_prop
P_ ((struct it
*));
547 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
548 static enum prop_handled handle_display_prop
P_ ((struct it
*));
549 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
550 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
551 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
553 /* Properties handled by iterators. */
555 static struct props it_props
[] =
557 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
558 /* Handle `face' before `display' because some sub-properties of
559 `display' need to know the face. */
560 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
561 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
562 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
563 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
567 /* Value is the position described by X. If X is a marker, value is
568 the marker_position of X. Otherwise, value is X. */
570 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
572 /* Enumeration returned by some move_it_.* functions internally. */
576 /* Not used. Undefined value. */
579 /* Move ended at the requested buffer position or ZV. */
580 MOVE_POS_MATCH_OR_ZV
,
582 /* Move ended at the requested X pixel position. */
585 /* Move within a line ended at the end of a line that must be
589 /* Move within a line ended at the end of a line that would
590 be displayed truncated. */
593 /* Move within a line ended at a line end. */
599 /* Function prototypes. */
601 static void ensure_echo_area_buffers
P_ ((void));
602 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
604 struct glyph_row
*));
605 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
606 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
607 static void clear_garbaged_frames
P_ ((void));
608 static int current_message_1
P_ ((Lisp_Object
*));
609 static int truncate_message_1
P_ ((int));
610 static int set_message_1
P_ ((char *s
, Lisp_Object
, int, int));
611 static int display_echo_area
P_ ((struct window
*));
612 static int display_echo_area_1
P_ ((struct window
*));
613 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
614 static int string_char_and_length
P_ ((unsigned char *, int, int *));
615 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
617 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
618 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
619 static Lisp_Object eval_form
P_ ((Lisp_Object
));
620 static void insert_left_trunc_glyphs
P_ ((struct it
*));
621 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
622 static void extend_face_to_end_of_line
P_ ((struct it
*));
623 static int append_space
P_ ((struct it
*, int));
624 static void make_cursor_line_fully_visible
P_ ((struct window
*));
625 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
626 static int trailing_whitespace_p
P_ ((int));
627 static int message_log_check_duplicate
P_ ((int, int, int, int));
628 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
629 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
630 static void push_it
P_ ((struct it
*));
631 static void pop_it
P_ ((struct it
*));
632 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
633 static void redisplay_internal
P_ ((int));
634 static int echo_area_display
P_ ((int));
635 static void redisplay_windows
P_ ((Lisp_Object
));
636 static void redisplay_window
P_ ((Lisp_Object
, int));
637 static void update_menu_bar
P_ ((struct frame
*, int));
638 static int try_window_reusing_current_matrix
P_ ((struct window
*));
639 static int try_window_id
P_ ((struct window
*));
640 static int display_line
P_ ((struct it
*));
641 static void display_mode_lines
P_ ((struct window
*));
642 static void display_mode_line
P_ ((struct window
*, enum face_id
,
644 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
645 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
646 static void display_menu_bar
P_ ((struct window
*));
647 static int display_count_lines
P_ ((int, int, int, int, int *));
648 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
649 int, int, struct it
*, int, int, int, int));
650 static void compute_line_metrics
P_ ((struct it
*));
651 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
652 static int get_overlay_strings
P_ ((struct it
*));
653 static void next_overlay_string
P_ ((struct it
*));
654 void set_iterator_to_next
P_ ((struct it
*));
655 static void reseat
P_ ((struct it
*, struct text_pos
, int));
656 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
657 static void back_to_previous_visible_line_start
P_ ((struct it
*));
658 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
659 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
660 static int next_element_from_display_vector
P_ ((struct it
*));
661 static int next_element_from_string
P_ ((struct it
*));
662 static int next_element_from_c_string
P_ ((struct it
*));
663 static int next_element_from_buffer
P_ ((struct it
*));
664 static int next_element_from_composition
P_ ((struct it
*));
665 static int next_element_from_image
P_ ((struct it
*));
666 static int next_element_from_stretch
P_ ((struct it
*));
667 static void load_overlay_strings
P_ ((struct it
*));
668 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
669 struct display_pos
*));
670 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
671 Lisp_Object
, int, int, int, int));
672 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
674 void move_it_vertically_backward
P_ ((struct it
*, int));
675 static void init_to_row_start
P_ ((struct it
*, struct window
*,
676 struct glyph_row
*));
677 static void init_to_row_end
P_ ((struct it
*, struct window
*,
678 struct glyph_row
*));
679 static void back_to_previous_line_start
P_ ((struct it
*));
680 static void forward_to_next_line_start
P_ ((struct it
*));
681 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
683 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
684 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
685 static int number_of_chars
P_ ((unsigned char *, int));
686 static void compute_stop_pos
P_ ((struct it
*));
687 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
689 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
690 static int next_overlay_change
P_ ((int));
691 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
692 Lisp_Object
, struct text_pos
*));
694 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
695 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
697 #ifdef HAVE_WINDOW_SYSTEM
699 static void update_tool_bar
P_ ((struct frame
*, int));
700 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
701 static int redisplay_tool_bar
P_ ((struct frame
*));
702 static void display_tool_bar_line
P_ ((struct it
*));
704 #endif /* HAVE_WINDOW_SYSTEM */
707 /***********************************************************************
708 Window display dimensions
709 ***********************************************************************/
711 /* Return the window-relative maximum y + 1 for glyph rows displaying
712 text in window W. This is the height of W minus the height of a
713 mode line, if any. */
716 window_text_bottom_y (w
)
719 struct frame
*f
= XFRAME (w
->frame
);
720 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
722 if (WINDOW_WANTS_MODELINE_P (w
))
723 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
728 /* Return the pixel width of display area AREA of window W. AREA < 0
729 means return the total width of W, not including bitmap areas to
730 the left and right of the window. */
733 window_box_width (w
, area
)
737 struct frame
*f
= XFRAME (w
->frame
);
738 int width
= XFASTINT (w
->width
);
740 if (!w
->pseudo_window_p
)
742 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
744 if (area
== TEXT_AREA
)
746 if (INTEGERP (w
->left_margin_width
))
747 width
-= XFASTINT (w
->left_margin_width
);
748 if (INTEGERP (w
->right_margin_width
))
749 width
-= XFASTINT (w
->right_margin_width
);
751 else if (area
== LEFT_MARGIN_AREA
)
752 width
= (INTEGERP (w
->left_margin_width
)
753 ? XFASTINT (w
->left_margin_width
) : 0);
754 else if (area
== RIGHT_MARGIN_AREA
)
755 width
= (INTEGERP (w
->right_margin_width
)
756 ? XFASTINT (w
->right_margin_width
) : 0);
759 return width
* CANON_X_UNIT (f
);
763 /* Return the pixel height of the display area of window W, not
764 including mode lines of W, if any.. */
767 window_box_height (w
)
770 struct frame
*f
= XFRAME (w
->frame
);
771 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
773 if (WINDOW_WANTS_MODELINE_P (w
))
774 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
776 if (WINDOW_WANTS_HEADER_LINE_P (w
))
777 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
783 /* Return the frame-relative coordinate of the left edge of display
784 area AREA of window W. AREA < 0 means return the left edge of the
785 whole window, to the right of any bitmap area at the left side of
789 window_box_left (w
, area
)
793 struct frame
*f
= XFRAME (w
->frame
);
794 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
796 if (!w
->pseudo_window_p
)
798 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
799 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
801 if (area
== TEXT_AREA
)
802 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
803 else if (area
== RIGHT_MARGIN_AREA
)
804 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
805 + window_box_width (w
, TEXT_AREA
));
812 /* Return the frame-relative coordinate of the right edge of display
813 area AREA of window W. AREA < 0 means return the left edge of the
814 whole window, to the left of any bitmap area at the right side of
818 window_box_right (w
, area
)
822 return window_box_left (w
, area
) + window_box_width (w
, area
);
826 /* Get the bounding box of the display area AREA of window W, without
827 mode lines, in frame-relative coordinates. AREA < 0 means the
828 whole window, not including bitmap areas to the left and right of
829 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
830 coordinates of the upper-left corner of the box. Return in
831 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
834 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
837 int *box_x
, *box_y
, *box_width
, *box_height
;
839 struct frame
*f
= XFRAME (w
->frame
);
841 *box_width
= window_box_width (w
, area
);
842 *box_height
= window_box_height (w
);
843 *box_x
= window_box_left (w
, area
);
844 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
845 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
846 if (WINDOW_WANTS_HEADER_LINE_P (w
))
847 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
851 /* Get the bounding box of the display area AREA of window W, without
852 mode lines. AREA < 0 means the whole window, not including bitmap
853 areas to the left and right of the window. Return in *TOP_LEFT_X
854 and TOP_LEFT_Y the frame-relative pixel coordinates of the
855 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
856 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
860 window_box_edges (w
, area
, top_left_x
, top_left_y
,
861 bottom_right_x
, bottom_right_y
)
864 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
866 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
868 *bottom_right_x
+= *top_left_x
;
869 *bottom_right_y
+= *top_left_y
;
874 /***********************************************************************
876 ***********************************************************************/
878 /* Return the next character from STR which is MAXLEN bytes long.
879 Return in *LEN the length of the character. This is like
880 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
881 we find one, we return a `?', but with the length of the illegal
885 string_char_and_length (str
, maxlen
, len
)
891 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
892 if (!CHAR_VALID_P (c
, 1))
893 /* We may not change the length here because other places in Emacs
894 don't use this function, i.e. they silently accept illegal
903 /* Given a position POS containing a valid character and byte position
904 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
906 static struct text_pos
907 string_pos_nchars_ahead (pos
, string
, nchars
)
912 xassert (STRINGP (string
) && nchars
>= 0);
914 if (STRING_MULTIBYTE (string
))
916 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
917 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
922 string_char_and_length (p
, rest
, &len
);
923 p
+= len
, rest
-= len
;
926 BYTEPOS (pos
) += len
;
930 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
936 /* Value is the text position, i.e. character and byte position,
937 for character position CHARPOS in STRING. */
939 static INLINE
struct text_pos
940 string_pos (charpos
, string
)
945 xassert (STRINGP (string
));
946 xassert (charpos
>= 0);
947 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
952 /* Value is a text position, i.e. character and byte position, for
953 character position CHARPOS in C string S. MULTIBYTE_P non-zero
954 means recognize multibyte characters. */
956 static struct text_pos
957 c_string_pos (charpos
, s
, multibyte_p
)
965 xassert (charpos
>= 0);
969 int rest
= strlen (s
), len
;
971 SET_TEXT_POS (pos
, 0, 0);
974 string_char_and_length (s
, rest
, &len
);
975 s
+= len
, rest
-= len
;
978 BYTEPOS (pos
) += len
;
982 SET_TEXT_POS (pos
, charpos
, charpos
);
988 /* Value is the number of characters in C string S. MULTIBYTE_P
989 non-zero means recognize multibyte characters. */
992 number_of_chars (s
, multibyte_p
)
1000 int rest
= strlen (s
), len
;
1001 unsigned char *p
= (unsigned char *) s
;
1003 for (nchars
= 0; rest
> 0; ++nchars
)
1005 string_char_and_length (p
, rest
, &len
);
1006 rest
-= len
, p
+= len
;
1010 nchars
= strlen (s
);
1016 /* Compute byte position NEWPOS->bytepos corresponding to
1017 NEWPOS->charpos. POS is a known position in string STRING.
1018 NEWPOS->charpos must be >= POS.charpos. */
1021 compute_string_pos (newpos
, pos
, string
)
1022 struct text_pos
*newpos
, pos
;
1025 xassert (STRINGP (string
));
1026 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1028 if (STRING_MULTIBYTE (string
))
1029 *newpos
= string_pos_nchars_ahead (pos
, string
,
1030 CHARPOS (*newpos
) - CHARPOS (pos
));
1032 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1037 /***********************************************************************
1038 Lisp form evaluation
1039 ***********************************************************************/
1041 /* Error handler for eval_form. */
1051 /* Evaluate SEXPR and return the result, or nil if something went
1058 int count
= specpdl_ptr
- specpdl
;
1060 specbind (Qinhibit_redisplay
, Qt
);
1061 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1062 return unbind_to (count
, val
);
1067 /***********************************************************************
1069 ***********************************************************************/
1073 /* Define CHECK_IT to perform sanity checks on iterators.
1074 This is for debugging. It is too slow to do unconditionally. */
1080 if (it
->method
== next_element_from_string
)
1082 xassert (STRINGP (it
->string
));
1083 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1085 else if (it
->method
== next_element_from_buffer
)
1087 /* Check that character and byte positions agree. */
1088 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1092 xassert (it
->current
.dpvec_index
>= 0);
1094 xassert (it
->current
.dpvec_index
< 0);
1097 #define CHECK_IT(IT) check_it ((IT))
1101 #define CHECK_IT(IT) (void) 0
1108 /* Check that the window end of window W is what we expect it
1109 to be---the last row in the current matrix displaying text. */
1112 check_window_end (w
)
1115 if (!MINI_WINDOW_P (w
)
1116 && !NILP (w
->window_end_valid
))
1118 struct glyph_row
*row
;
1119 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1120 XFASTINT (w
->window_end_vpos
)),
1122 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1123 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1127 #define CHECK_WINDOW_END(W) check_window_end ((W))
1129 #else /* not GLYPH_DEBUG */
1131 #define CHECK_WINDOW_END(W) (void) 0
1133 #endif /* not GLYPH_DEBUG */
1137 /***********************************************************************
1138 Iterator initialization
1139 ***********************************************************************/
1141 /* Initialize IT for displaying current_buffer in window W, starting
1142 at character position CHARPOS. CHARPOS < 0 means that no buffer
1143 position is specified which is useful when the iterator is assigned
1144 a position later. BYTEPOS is the byte position corresponding to
1145 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1147 If ROW is not null, calls to produce_glyphs with IT as parameter
1148 will produce glyphs in that row.
1150 BASE_FACE_ID is the id of a base face to use. It must be one of
1151 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1152 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1153 displaying the tool-bar.
1155 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1156 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1157 corresponding mode line glyph row of the desired matrix of W. */
1160 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1163 int charpos
, bytepos
;
1164 struct glyph_row
*row
;
1165 enum face_id base_face_id
;
1167 int highlight_region_p
;
1169 /* Some precondition checks. */
1170 xassert (w
!= NULL
&& it
!= NULL
);
1171 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1173 /* If face attributes have been changed since the last redisplay,
1174 free realized faces now because they depend on face definitions
1175 that might have changed. */
1176 if (face_change_count
)
1178 face_change_count
= 0;
1179 free_all_realized_faces (Qnil
);
1182 /* Use one of the mode line rows of W's desired matrix if
1186 if (base_face_id
== MODE_LINE_FACE_ID
)
1187 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1188 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1189 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1193 bzero (it
, sizeof *it
);
1194 it
->current
.overlay_string_index
= -1;
1195 it
->current
.dpvec_index
= -1;
1196 it
->base_face_id
= base_face_id
;
1198 /* The window in which we iterate over current_buffer: */
1199 XSETWINDOW (it
->window
, w
);
1201 it
->f
= XFRAME (w
->frame
);
1203 /* Extra space between lines (on window systems only). */
1204 if (base_face_id
== DEFAULT_FACE_ID
1205 && FRAME_WINDOW_P (it
->f
))
1207 if (NATNUMP (current_buffer
->extra_line_spacing
))
1208 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1209 else if (it
->f
->extra_line_spacing
> 0)
1210 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1213 /* If realized faces have been removed, e.g. because of face
1214 attribute changes of named faces, recompute them. */
1215 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1216 recompute_basic_faces (it
->f
);
1218 /* Current value of the `space-width', and 'height' properties. */
1219 it
->space_width
= Qnil
;
1220 it
->font_height
= Qnil
;
1222 /* Are control characters displayed as `^C'? */
1223 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1225 /* -1 means everything between a CR and the following line end
1226 is invisible. >0 means lines indented more than this value are
1228 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1229 ? XFASTINT (current_buffer
->selective_display
)
1230 : (!NILP (current_buffer
->selective_display
)
1232 it
->selective_display_ellipsis_p
1233 = !NILP (current_buffer
->selective_display_ellipses
);
1235 /* Display table to use. */
1236 it
->dp
= window_display_table (w
);
1238 /* Are multibyte characters enabled in current_buffer? */
1239 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1241 /* Non-zero if we should highlight the region. */
1243 = (!NILP (Vtransient_mark_mode
)
1244 && !NILP (current_buffer
->mark_active
)
1245 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1247 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1248 start and end of a visible region in window IT->w. Set both to
1249 -1 to indicate no region. */
1250 if (highlight_region_p
1251 /* Maybe highlight only in selected window. */
1252 && (/* Either show region everywhere. */
1253 highlight_nonselected_windows
1254 /* Or show region in the selected window. */
1255 || w
== XWINDOW (selected_window
)
1256 /* Or show the region if we are in the mini-buffer and W is
1257 the window the mini-buffer refers to. */
1258 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1259 && w
== XWINDOW (Vminibuf_scroll_window
))))
1261 int charpos
= marker_position (current_buffer
->mark
);
1262 it
->region_beg_charpos
= min (PT
, charpos
);
1263 it
->region_end_charpos
= max (PT
, charpos
);
1266 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1268 /* Get the position at which the redisplay_end_trigger hook should
1269 be run, if it is to be run at all. */
1270 if (MARKERP (w
->redisplay_end_trigger
)
1271 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1272 it
->redisplay_end_trigger_charpos
1273 = marker_position (w
->redisplay_end_trigger
);
1274 else if (INTEGERP (w
->redisplay_end_trigger
))
1275 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1277 /* Correct bogus values of tab_width. */
1278 it
->tab_width
= XINT (current_buffer
->tab_width
);
1279 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1282 /* Are lines in the display truncated? */
1283 it
->truncate_lines_p
1284 = (base_face_id
!= DEFAULT_FACE_ID
1285 || XINT (it
->w
->hscroll
)
1286 || (truncate_partial_width_windows
1287 && !WINDOW_FULL_WIDTH_P (it
->w
))
1288 || !NILP (current_buffer
->truncate_lines
));
1290 /* Get dimensions of truncation and continuation glyphs. These are
1291 displayed as bitmaps under X, so we don't need them for such
1293 if (!FRAME_WINDOW_P (it
->f
))
1295 if (it
->truncate_lines_p
)
1297 /* We will need the truncation glyph. */
1298 xassert (it
->glyph_row
== NULL
);
1299 produce_special_glyphs (it
, IT_TRUNCATION
);
1300 it
->truncation_pixel_width
= it
->pixel_width
;
1304 /* We will need the continuation glyph. */
1305 xassert (it
->glyph_row
== NULL
);
1306 produce_special_glyphs (it
, IT_CONTINUATION
);
1307 it
->continuation_pixel_width
= it
->pixel_width
;
1310 /* Reset these values to zero becaue the produce_special_glyphs
1311 above has changed them. */
1312 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1313 it
->phys_ascent
= it
->phys_descent
= 0;
1316 /* Set this after getting the dimensions of truncation and
1317 continuation glyphs, so that we don't produce glyphs when calling
1318 produce_special_glyphs, above. */
1319 it
->glyph_row
= row
;
1320 it
->area
= TEXT_AREA
;
1322 /* Get the dimensions of the display area. The display area
1323 consists of the visible window area plus a horizontally scrolled
1324 part to the left of the window. All x-values are relative to the
1325 start of this total display area. */
1326 if (base_face_id
!= DEFAULT_FACE_ID
)
1328 /* Mode lines, menu bar in terminal frames. */
1329 it
->first_visible_x
= 0;
1330 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1335 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1336 it
->last_visible_x
= (it
->first_visible_x
1337 + window_box_width (w
, TEXT_AREA
));
1339 /* If we truncate lines, leave room for the truncator glyph(s) at
1340 the right margin. Otherwise, leave room for the continuation
1341 glyph(s). Truncation and continuation glyphs are not inserted
1342 for window-based redisplay. */
1343 if (!FRAME_WINDOW_P (it
->f
))
1345 if (it
->truncate_lines_p
)
1346 it
->last_visible_x
-= it
->truncation_pixel_width
;
1348 it
->last_visible_x
-= it
->continuation_pixel_width
;
1351 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1352 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1355 /* Leave room for a border glyph. */
1356 if (!FRAME_WINDOW_P (it
->f
)
1357 && !WINDOW_RIGHTMOST_P (it
->w
))
1358 it
->last_visible_x
-= 1;
1360 it
->last_visible_y
= window_text_bottom_y (w
);
1362 /* For mode lines and alike, arrange for the first glyph having a
1363 left box line if the face specifies a box. */
1364 if (base_face_id
!= DEFAULT_FACE_ID
)
1368 it
->face_id
= base_face_id
;
1370 /* If we have a boxed mode line, make the first character appear
1371 with a left box line. */
1372 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1373 if (face
->box
!= FACE_NO_BOX
)
1374 it
->start_of_box_run_p
= 1;
1377 /* If a buffer position was specified, set the iterator there,
1378 getting overlays and face properties from that position. */
1381 it
->end_charpos
= ZV
;
1383 IT_CHARPOS (*it
) = charpos
;
1385 /* Compute byte position if not specified. */
1387 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1389 IT_BYTEPOS (*it
) = bytepos
;
1391 /* Compute faces etc. */
1392 reseat (it
, it
->current
.pos
, 1);
1399 /* Initialize IT for the display of window W with window start POS. */
1402 start_display (it
, w
, pos
)
1405 struct text_pos pos
;
1407 int start_at_line_beg_p
;
1408 struct glyph_row
*row
;
1409 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1412 row
= w
->desired_matrix
->rows
+ first_vpos
;
1413 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1414 first_y
= it
->current_y
;
1416 /* If window start is not at a line start, move back to the line
1417 start. This makes sure that we take continuation lines into
1419 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1420 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1421 if (!start_at_line_beg_p
)
1422 reseat_at_previous_visible_line_start (it
);
1424 /* If window start is not at a line start, skip forward to POS to
1425 get the correct continuation_lines_width and current_x. */
1426 if (!start_at_line_beg_p
)
1428 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1430 /* If lines are continued, this line may end in the middle of a
1431 multi-glyph character (e.g. a control character displayed as
1432 \003, or in the middle of an overlay string). In this case
1433 move_it_to above will not have taken us to the start of
1434 the continuation line but to the end of the continued line. */
1435 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1437 if (it
->current
.dpvec_index
>= 0
1438 || it
->current
.overlay_string_index
>= 0)
1440 set_iterator_to_next (it
);
1441 move_it_in_display_line_to (it
, -1, -1, 0);
1443 it
->continuation_lines_width
+= it
->current_x
;
1446 it
->current_y
= first_y
;
1448 it
->current_x
= it
->hpos
= 0;
1451 #if 0 /* Don't assert the following because start_display is sometimes
1452 called intentionally with a window start that is not at a
1453 line start. Please leave this code in as a comment. */
1455 /* Window start should be on a line start, now. */
1456 xassert (it
->continuation_lines_width
1457 || IT_CHARPOS (it
) == BEGV
1458 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1463 /* Initialize IT for stepping through current_buffer in window W,
1464 starting at position POS that includes overlay string and display
1465 vector/ control character translation position information. */
1468 init_from_display_pos (it
, w
, pos
)
1471 struct display_pos
*pos
;
1473 /* Keep in mind: the call to reseat in init_iterator skips invisible
1474 text, so we might end up at a position different from POS. This
1475 is only a problem when POS is a row start after a newline and an
1476 overlay starts there with an after-string, and the overlay has an
1477 invisible property. Since we don't skip invisible text in
1478 display_line and elsewhere immediately after consuming the
1479 newline before the row start, such a POS will not be in a string,
1480 but the call to init_iterator below will move us to the
1482 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1483 NULL
, DEFAULT_FACE_ID
);
1485 /* If position is within an overlay string, set up IT to
1486 the right overlay string. */
1487 if (pos
->overlay_string_index
>= 0)
1491 /* We already have the first chunk of overlay strings in
1492 IT->overlay_strings. Load more until the one for
1493 pos->overlay_string_index is in IT->overlay_strings. */
1494 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1496 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1497 it
->current
.overlay_string_index
= 0;
1500 load_overlay_strings (it
);
1501 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1505 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1506 relative_index
= (it
->current
.overlay_string_index
1507 % OVERLAY_STRING_CHUNK_SIZE
);
1508 it
->string
= it
->overlay_strings
[relative_index
];
1509 it
->current
.string_pos
= pos
->string_pos
;
1510 it
->method
= next_element_from_string
;
1512 else if (CHARPOS (pos
->string_pos
) >= 0)
1514 /* Recorded position is not in an overlay string, but in another
1515 string. This can only be a string from a `display' property.
1516 IT should already be filled with that string. */
1517 it
->current
.string_pos
= pos
->string_pos
;
1518 xassert (STRINGP (it
->string
));
1521 /* Restore position in display vector translations or control
1522 character translations. */
1523 if (pos
->dpvec_index
>= 0)
1525 /* This fills IT->dpvec. */
1526 get_next_display_element (it
);
1527 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1528 it
->current
.dpvec_index
= pos
->dpvec_index
;
1535 /* Initialize IT for stepping through current_buffer in window W
1536 starting at ROW->start. */
1539 init_to_row_start (it
, w
, row
)
1542 struct glyph_row
*row
;
1544 init_from_display_pos (it
, w
, &row
->start
);
1545 it
->continuation_lines_width
= row
->continuation_lines_width
;
1550 /* Initialize IT for stepping through current_buffer in window W
1551 starting in the line following ROW, i.e. starting at ROW->end. */
1554 init_to_row_end (it
, w
, row
)
1557 struct glyph_row
*row
;
1559 init_from_display_pos (it
, w
, &row
->end
);
1561 if (row
->continued_p
)
1562 it
->continuation_lines_width
= (row
->continuation_lines_width
1563 + row
->pixel_width
);
1570 /***********************************************************************
1572 ***********************************************************************/
1574 /* Called when IT reaches IT->stop_charpos. Handle text property and
1575 overlay changes. Set IT->stop_charpos to the next position where
1582 enum prop_handled handled
;
1583 int handle_overlay_change_p
= 1;
1587 it
->current
.dpvec_index
= -1;
1591 handled
= HANDLED_NORMALLY
;
1593 /* Call text property handlers. */
1594 for (p
= it_props
; p
->handler
; ++p
)
1596 handled
= p
->handler (it
);
1598 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1600 else if (handled
== HANDLED_RETURN
)
1602 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1603 handle_overlay_change_p
= 0;
1606 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1608 /* Don't check for overlay strings below when set to deliver
1609 characters from a display vector. */
1610 if (it
->method
== next_element_from_display_vector
)
1611 handle_overlay_change_p
= 0;
1613 /* Handle overlay changes. */
1614 if (handle_overlay_change_p
)
1615 handled
= handle_overlay_change (it
);
1617 /* Determine where to stop next. */
1618 if (handled
== HANDLED_NORMALLY
)
1619 compute_stop_pos (it
);
1622 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1626 /* Compute IT->stop_charpos from text property and overlay change
1627 information for IT's current position. */
1630 compute_stop_pos (it
)
1633 register INTERVAL iv
, next_iv
;
1634 Lisp_Object object
, limit
, position
;
1636 /* If nowhere else, stop at the end. */
1637 it
->stop_charpos
= it
->end_charpos
;
1639 if (STRINGP (it
->string
))
1641 /* Strings are usually short, so don't limit the search for
1643 object
= it
->string
;
1645 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1651 /* If next overlay change is in front of the current stop pos
1652 (which is IT->end_charpos), stop there. Note: value of
1653 next_overlay_change is point-max if no overlay change
1655 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1656 if (charpos
< it
->stop_charpos
)
1657 it
->stop_charpos
= charpos
;
1659 /* If showing the region, we have to stop at the region
1660 start or end because the face might change there. */
1661 if (it
->region_beg_charpos
> 0)
1663 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1664 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1665 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1666 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1669 /* Set up variables for computing the stop position from text
1670 property changes. */
1671 XSETBUFFER (object
, current_buffer
);
1672 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1673 XSETFASTINT (position
, IT_CHARPOS (*it
));
1677 /* Get the interval containing IT's position. Value is a null
1678 interval if there isn't such an interval. */
1679 iv
= validate_interval_range (object
, &position
, &position
, 0);
1680 if (!NULL_INTERVAL_P (iv
))
1682 Lisp_Object values_here
[LAST_PROP_IDX
];
1685 /* Get properties here. */
1686 for (p
= it_props
; p
->handler
; ++p
)
1687 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1689 /* Look for an interval following iv that has different
1691 for (next_iv
= next_interval (iv
);
1692 (!NULL_INTERVAL_P (next_iv
)
1694 || XFASTINT (limit
) > next_iv
->position
));
1695 next_iv
= next_interval (next_iv
))
1697 for (p
= it_props
; p
->handler
; ++p
)
1699 Lisp_Object new_value
;
1701 new_value
= textget (next_iv
->plist
, *p
->name
);
1702 if (!EQ (values_here
[p
->idx
], new_value
))
1710 if (!NULL_INTERVAL_P (next_iv
))
1712 if (INTEGERP (limit
)
1713 && next_iv
->position
>= XFASTINT (limit
))
1714 /* No text property change up to limit. */
1715 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1717 /* Text properties change in next_iv. */
1718 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1722 xassert (STRINGP (it
->string
)
1723 || (it
->stop_charpos
>= BEGV
1724 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1728 /* Return the position of the next overlay change after POS in
1729 current_buffer. Value is point-max if no overlay change
1730 follows. This is like `next-overlay-change' but doesn't use
1734 next_overlay_change (pos
)
1739 Lisp_Object
*overlays
;
1743 /* Get all overlays at the given position. */
1745 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1746 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1747 if (noverlays
> len
)
1750 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1751 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1754 /* If any of these overlays ends before endpos,
1755 use its ending point instead. */
1756 for (i
= 0; i
< noverlays
; ++i
)
1761 oend
= OVERLAY_END (overlays
[i
]);
1762 oendpos
= OVERLAY_POSITION (oend
);
1763 endpos
= min (endpos
, oendpos
);
1771 /***********************************************************************
1773 ***********************************************************************/
1775 /* Handle changes in the `fontified' property of the current buffer by
1776 calling hook functions from Qfontification_functions to fontify
1779 static enum prop_handled
1780 handle_fontified_prop (it
)
1783 Lisp_Object prop
, pos
;
1784 enum prop_handled handled
= HANDLED_NORMALLY
;
1785 struct gcpro gcpro1
;
1787 /* Get the value of the `fontified' property at IT's current buffer
1788 position. (The `fontified' property doesn't have a special
1789 meaning in strings.) If the value is nil, call functions from
1790 Qfontification_functions. */
1791 if (!STRINGP (it
->string
)
1793 && !NILP (Vfontification_functions
)
1794 && (pos
= make_number (IT_CHARPOS (*it
)),
1795 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1798 Lisp_Object args
[2];
1801 /* Run the hook functions. */
1802 args
[0] = Qfontification_functions
;
1804 Frun_hook_with_args (2, args
);
1806 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1807 something. This avoids an endless loop if they failed to
1808 fontify the text for which reason ever. */
1809 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1810 handled
= HANDLED_RECOMPUTE_PROPS
;
1819 /***********************************************************************
1821 ***********************************************************************/
1823 /* Set up iterator IT from face properties at its current position.
1824 Called from handle_stop. */
1826 static enum prop_handled
1827 handle_face_prop (it
)
1830 int new_face_id
, next_stop
;
1832 if (!STRINGP (it
->string
))
1835 = face_at_buffer_position (it
->w
,
1837 it
->region_beg_charpos
,
1838 it
->region_end_charpos
,
1841 + TEXT_PROP_DISTANCE_LIMIT
),
1844 /* Is this a start of a run of characters with box face?
1845 Caveat: this can be called for a freshly initialized
1846 iterator; face_id is -1 is this case. We know that the new
1847 face will not change until limit, i.e. if the new face has a
1848 box, all characters up to limit will have one. But, as
1849 usual, we don't know whether limit is really the end. */
1850 if (new_face_id
!= it
->face_id
)
1852 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1854 /* If new face has a box but old face has not, this is
1855 the start of a run of characters with box, i.e. it has
1856 a shadow on the left side. The value of face_id of the
1857 iterator will be -1 if this is the initial call that gets
1858 the face. In this case, we have to look in front of IT's
1859 position and see whether there is a face != new_face_id. */
1860 it
->start_of_box_run_p
1861 = (new_face
->box
!= FACE_NO_BOX
1862 && (it
->face_id
>= 0
1863 || IT_CHARPOS (*it
) == BEG
1864 || new_face_id
!= face_before_it_pos (it
)));
1865 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1871 = face_at_string_position (it
->w
,
1873 IT_STRING_CHARPOS (*it
),
1874 (it
->current
.overlay_string_index
>= 0
1877 it
->region_beg_charpos
,
1878 it
->region_end_charpos
,
1882 #if 0 /* This shouldn't be neccessary. Let's check it. */
1883 /* If IT is used to display a mode line we would really like to
1884 use the mode line face instead of the frame's default face. */
1885 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1886 && new_face_id
== DEFAULT_FACE_ID
)
1887 new_face_id
= MODE_LINE_FACE_ID
;
1890 /* Is this a start of a run of characters with box? Caveat:
1891 this can be called for a freshly allocated iterator; face_id
1892 is -1 is this case. We know that the new face will not
1893 change until the next check pos, i.e. if the new face has a
1894 box, all characters up to that position will have a
1895 box. But, as usual, we don't know whether that position
1896 is really the end. */
1897 if (new_face_id
!= it
->face_id
)
1899 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1900 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1902 /* If new face has a box but old face hasn't, this is the
1903 start of a run of characters with box, i.e. it has a
1904 shadow on the left side. */
1905 it
->start_of_box_run_p
1906 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1907 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1911 it
->face_id
= new_face_id
;
1912 return HANDLED_NORMALLY
;
1916 /* Compute the face one character before or after the current position
1917 of IT. BEFORE_P non-zero means get the face in front of IT's
1918 position. Value is the id of the face. */
1921 face_before_or_after_it_pos (it
, before_p
)
1926 int next_check_charpos
;
1927 struct text_pos pos
;
1929 xassert (it
->s
== NULL
);
1931 if (STRINGP (it
->string
))
1933 /* No face change past the end of the string (for the case
1934 we are padding with spaces). No face change before the
1936 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1937 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1940 /* Set pos to the position before or after IT's current position. */
1942 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1944 /* For composition, we must check the character after the
1946 pos
= (it
->what
== IT_COMPOSITION
1947 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
1948 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
1950 /* Get the face for ASCII, or unibyte. */
1952 = face_at_string_position (it
->w
,
1955 (it
->current
.overlay_string_index
>= 0
1958 it
->region_beg_charpos
,
1959 it
->region_end_charpos
,
1960 &next_check_charpos
,
1963 /* Correct the face for charsets different from ASCII. Do it
1964 for the multibyte case only. The face returned above is
1965 suitable for unibyte text if IT->string is unibyte. */
1966 if (STRING_MULTIBYTE (it
->string
))
1968 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1969 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1971 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
1973 c
= string_char_and_length (p
, rest
, &len
);
1974 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
1979 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
1980 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
1983 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1984 pos
= it
->current
.pos
;
1987 DEC_TEXT_POS (pos
, it
->multibyte_p
);
1990 if (it
->what
== IT_COMPOSITION
)
1991 /* For composition, we must check the position after the
1993 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
1995 INC_TEXT_POS (pos
, it
->multibyte_p
);
1997 /* Determine face for CHARSET_ASCII, or unibyte. */
1998 face_id
= face_at_buffer_position (it
->w
,
2000 it
->region_beg_charpos
,
2001 it
->region_end_charpos
,
2002 &next_check_charpos
,
2005 /* Correct the face for charsets different from ASCII. Do it
2006 for the multibyte case only. The face returned above is
2007 suitable for unibyte text if current_buffer is unibyte. */
2008 if (it
->multibyte_p
)
2010 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2011 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2012 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2021 /***********************************************************************
2023 ***********************************************************************/
2025 /* Set up iterator IT from invisible properties at its current
2026 position. Called from handle_stop. */
2028 static enum prop_handled
2029 handle_invisible_prop (it
)
2032 enum prop_handled handled
= HANDLED_NORMALLY
;
2034 if (STRINGP (it
->string
))
2036 extern Lisp_Object Qinvisible
;
2037 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2039 /* Get the value of the invisible text property at the
2040 current position. Value will be nil if there is no such
2042 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2043 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2047 handled
= HANDLED_RECOMPUTE_PROPS
;
2049 /* Get the position at which the next change of the
2050 invisible text property can be found in IT->string.
2051 Value will be nil if the property value is the same for
2052 all the rest of IT->string. */
2053 XSETINT (limit
, XSTRING (it
->string
)->size
);
2054 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2057 /* Text at current position is invisible. The next
2058 change in the property is at position end_charpos.
2059 Move IT's current position to that position. */
2060 if (INTEGERP (end_charpos
)
2061 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2063 struct text_pos old
;
2064 old
= it
->current
.string_pos
;
2065 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2066 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2070 /* The rest of the string is invisible. If this is an
2071 overlay string, proceed with the next overlay string
2072 or whatever comes and return a character from there. */
2073 if (it
->current
.overlay_string_index
>= 0)
2075 next_overlay_string (it
);
2076 /* Don't check for overlay strings when we just
2077 finished processing them. */
2078 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2082 struct Lisp_String
*s
= XSTRING (it
->string
);
2083 IT_STRING_CHARPOS (*it
) = s
->size
;
2084 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2091 int visible_p
, newpos
, next_stop
;
2092 Lisp_Object pos
, prop
;
2094 /* First of all, is there invisible text at this position? */
2095 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2096 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2098 /* If we are on invisible text, skip over it. */
2099 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2101 /* Record whether we have to display an ellipsis for the
2103 int display_ellipsis_p
2104 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2106 handled
= HANDLED_RECOMPUTE_PROPS
;
2108 /* Loop skipping over invisible text. The loop is left at
2109 ZV or with IT on the first char being visible again. */
2112 /* Try to skip some invisible text. Return value is the
2113 position reached which can be equal to IT's position
2114 if there is nothing invisible here. This skips both
2115 over invisible text properties and overlays with
2116 invisible property. */
2117 newpos
= skip_invisible (IT_CHARPOS (*it
),
2118 &next_stop
, ZV
, it
->window
);
2120 /* If we skipped nothing at all we weren't at invisible
2121 text in the first place. If everything to the end of
2122 the buffer was skipped, end the loop. */
2123 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2127 /* We skipped some characters but not necessarily
2128 all there are. Check if we ended up on visible
2129 text. Fget_char_property returns the property of
2130 the char before the given position, i.e. if we
2131 get visible_p = 1, this means that the char at
2132 newpos is visible. */
2133 XSETFASTINT (pos
, newpos
);
2134 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2135 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2138 /* If we ended up on invisible text, proceed to
2139 skip starting with next_stop. */
2141 IT_CHARPOS (*it
) = next_stop
;
2145 /* The position newpos is now either ZV or on visible text. */
2146 IT_CHARPOS (*it
) = newpos
;
2147 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2149 /* Maybe return `...' next for the end of the invisible text. */
2150 if (display_ellipsis_p
)
2153 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2155 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2156 it
->dpvec
= v
->contents
;
2157 it
->dpend
= v
->contents
+ v
->size
;
2161 /* Default `...'. */
2162 it
->dpvec
= default_invis_vector
;
2163 it
->dpend
= default_invis_vector
+ 3;
2166 /* The ellipsis display does not replace the display of
2167 the character at the new position. Indicate this by
2168 setting IT->dpvec_char_len to zero. */
2169 it
->dpvec_char_len
= 0;
2171 it
->current
.dpvec_index
= 0;
2172 it
->method
= next_element_from_display_vector
;
2182 /***********************************************************************
2184 ***********************************************************************/
2186 /* Set up iterator IT from `display' property at its current position.
2187 Called from handle_stop. */
2189 static enum prop_handled
2190 handle_display_prop (it
)
2193 Lisp_Object prop
, object
;
2194 struct text_pos
*position
;
2195 int space_or_image_found_p
;
2197 if (STRINGP (it
->string
))
2199 object
= it
->string
;
2200 position
= &it
->current
.string_pos
;
2205 position
= &it
->current
.pos
;
2208 /* Reset those iterator values set from display property values. */
2209 it
->font_height
= Qnil
;
2210 it
->space_width
= Qnil
;
2213 /* We don't support recursive `display' properties, i.e. string
2214 values that have a string `display' property, that have a string
2215 `display' property etc. */
2216 if (!it
->string_from_display_prop_p
)
2217 it
->area
= TEXT_AREA
;
2219 prop
= Fget_char_property (make_number (position
->charpos
),
2222 return HANDLED_NORMALLY
;
2224 space_or_image_found_p
= 0;
2226 && CONSP (XCAR (prop
))
2227 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2229 /* A list of sub-properties. */
2230 while (CONSP (prop
))
2232 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2233 space_or_image_found_p
= 1;
2237 else if (VECTORP (prop
))
2240 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2241 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2243 space_or_image_found_p
= 1;
2247 if (handle_single_display_prop (it
, prop
, object
, position
))
2248 space_or_image_found_p
= 1;
2251 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2255 /* Value is the position of the end of the `display' property starting
2256 at START_POS in OBJECT. */
2258 static struct text_pos
2259 display_prop_end (it
, object
, start_pos
)
2262 struct text_pos start_pos
;
2265 struct text_pos end_pos
;
2267 end
= next_single_char_property_change (make_number (CHARPOS (start_pos
)),
2268 Qdisplay
, object
, Qnil
);
2269 CHARPOS (end_pos
) = XFASTINT (end
);
2270 if (STRINGP (object
))
2271 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2273 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2279 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2280 is the object in which the `display' property was found. *POSITION
2281 is the position at which it was found.
2283 If PROP is a `space' or `image' sub-property, set *POSITION to the
2284 end position of the `display' property.
2286 Value is non-zero if a `space' or `image' property value was found. */
2289 handle_single_display_prop (it
, prop
, object
, position
)
2293 struct text_pos
*position
;
2296 int space_or_image_found_p
= 0;
2300 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2301 evaluated. If the result is nil, VALUE is ignored. */
2303 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2312 if (!NILP (form
) && !EQ (form
, Qt
))
2314 struct gcpro gcpro1
;
2315 struct text_pos end_pos
, pt
;
2317 end_pos
= display_prop_end (it
, object
, *position
);
2320 /* Temporarily set point to the end position, and then evaluate
2321 the form. This makes `(eolp)' work as FORM. */
2323 BYTEPOS (pt
) = PT_BYTE
;
2324 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2325 form
= eval_form (form
);
2326 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2334 && EQ (XCAR (prop
), Qheight
)
2335 && CONSP (XCDR (prop
)))
2337 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2340 /* `(height HEIGHT)'. */
2341 it
->font_height
= XCAR (XCDR (prop
));
2342 if (!NILP (it
->font_height
))
2344 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2345 int new_height
= -1;
2347 if (CONSP (it
->font_height
)
2348 && (EQ (XCAR (it
->font_height
), Qplus
)
2349 || EQ (XCAR (it
->font_height
), Qminus
))
2350 && CONSP (XCDR (it
->font_height
))
2351 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2353 /* `(+ N)' or `(- N)' where N is an integer. */
2354 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2355 if (EQ (XCAR (it
->font_height
), Qplus
))
2357 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2359 else if (SYMBOLP (it
->font_height
))
2361 /* Call function with current height as argument.
2362 Value is the new height. */
2363 Lisp_Object form
, height
;
2364 struct gcpro gcpro1
;
2366 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2367 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2369 height
= eval_form (form
);
2370 if (NUMBERP (height
))
2371 new_height
= XFLOATINT (height
);
2374 else if (NUMBERP (it
->font_height
))
2376 /* Value is a multiple of the canonical char height. */
2379 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2380 new_height
= (XFLOATINT (it
->font_height
)
2381 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2385 /* Evaluate IT->font_height with `height' bound to the
2386 current specified height to get the new height. */
2388 int count
= specpdl_ptr
- specpdl
;
2390 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2391 value
= eval_form (it
->font_height
);
2392 unbind_to (count
, Qnil
);
2394 if (NUMBERP (value
))
2395 new_height
= XFLOATINT (value
);
2399 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2402 else if (CONSP (prop
)
2403 && EQ (XCAR (prop
), Qspace_width
)
2404 && CONSP (XCDR (prop
)))
2406 /* `(space_width WIDTH)'. */
2407 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2410 value
= XCAR (XCDR (prop
));
2411 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2412 it
->space_width
= value
;
2414 else if (CONSP (prop
)
2415 && EQ (XCAR (prop
), Qraise
)
2416 && CONSP (XCDR (prop
)))
2418 /* `(raise FACTOR)'. */
2419 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2422 #ifdef HAVE_WINDOW_SYSTEM
2423 value
= XCAR (XCDR (prop
));
2424 if (NUMBERP (value
))
2426 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2427 it
->voffset
= - (XFLOATINT (value
)
2428 * (FONT_HEIGHT (face
->font
)));
2430 #endif /* HAVE_WINDOW_SYSTEM */
2432 else if (!it
->string_from_display_prop_p
)
2434 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2435 VALUE) or `((margin nil) VALUE)' or VALUE. */
2436 Lisp_Object location
, value
;
2437 struct text_pos start_pos
;
2440 /* Characters having this form of property are not displayed, so
2441 we have to find the end of the property. */
2442 space_or_image_found_p
= 1;
2443 start_pos
= *position
;
2444 *position
= display_prop_end (it
, object
, start_pos
);
2447 /* Let's stop at the new position and assume that all
2448 text properties change there. */
2449 it
->stop_charpos
= position
->charpos
;
2451 location
= Qunbound
;
2452 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2456 value
= XCDR (prop
);
2458 value
= XCAR (value
);
2461 if (EQ (XCAR (tem
), Qmargin
)
2462 && (tem
= XCDR (tem
),
2463 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2465 || EQ (tem
, Qleft_margin
)
2466 || EQ (tem
, Qright_margin
))))
2470 if (EQ (location
, Qunbound
))
2476 #ifdef HAVE_WINDOW_SYSTEM
2477 if (FRAME_TERMCAP_P (it
->f
))
2478 valid_p
= STRINGP (value
);
2480 valid_p
= (STRINGP (value
)
2481 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2482 || valid_image_p (value
));
2483 #else /* not HAVE_WINDOW_SYSTEM */
2484 valid_p
= STRINGP (value
);
2485 #endif /* not HAVE_WINDOW_SYSTEM */
2487 if ((EQ (location
, Qleft_margin
)
2488 || EQ (location
, Qright_margin
)
2492 /* Save current settings of IT so that we can restore them
2493 when we are finished with the glyph property value. */
2496 if (NILP (location
))
2497 it
->area
= TEXT_AREA
;
2498 else if (EQ (location
, Qleft_margin
))
2499 it
->area
= LEFT_MARGIN_AREA
;
2501 it
->area
= RIGHT_MARGIN_AREA
;
2503 if (STRINGP (value
))
2506 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2507 it
->current
.overlay_string_index
= -1;
2508 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2509 it
->end_charpos
= it
->string_nchars
2510 = XSTRING (it
->string
)->size
;
2511 it
->method
= next_element_from_string
;
2512 it
->stop_charpos
= 0;
2513 it
->string_from_display_prop_p
= 1;
2515 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2517 it
->method
= next_element_from_stretch
;
2519 it
->current
.pos
= it
->position
= start_pos
;
2521 #ifdef HAVE_WINDOW_SYSTEM
2524 it
->what
= IT_IMAGE
;
2525 it
->image_id
= lookup_image (it
->f
, value
);
2526 it
->position
= start_pos
;
2527 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2528 it
->method
= next_element_from_image
;
2530 /* Say that we don't have consumed the characters with
2531 `display' property yet. The call to pop_it in
2532 set_iterator_to_next will clean this up. */
2533 *position
= start_pos
;
2535 #endif /* HAVE_WINDOW_SYSTEM */
2539 return space_or_image_found_p
;
2544 /***********************************************************************
2545 `composition' property
2546 ***********************************************************************/
2548 /* Set up iterator IT from `composition' property at its current
2549 position. Called from handle_stop. */
2551 static enum prop_handled
2552 handle_composition_prop (it
)
2555 Lisp_Object prop
, string
;
2556 int pos
, pos_byte
, end
;
2557 enum prop_handled handled
= HANDLED_NORMALLY
;
2559 if (STRINGP (it
->string
))
2561 pos
= IT_STRING_CHARPOS (*it
);
2562 pos_byte
= IT_STRING_BYTEPOS (*it
);
2563 string
= it
->string
;
2567 pos
= IT_CHARPOS (*it
);
2568 pos_byte
= IT_BYTEPOS (*it
);
2572 /* If there's a valid composition and point is not inside of the
2573 composition (in the case that the composition is from the current
2574 buffer), draw a glyph composed from the composition components. */
2575 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2576 && COMPOSITION_VALID_P (pos
, end
, prop
)
2577 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2579 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2583 it
->method
= next_element_from_composition
;
2585 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2586 /* For a terminal, draw only the first character of the
2588 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2589 it
->len
= (STRINGP (it
->string
)
2590 ? string_char_to_byte (it
->string
, end
)
2591 : CHAR_TO_BYTE (end
)) - pos_byte
;
2592 it
->stop_charpos
= end
;
2593 handled
= HANDLED_RETURN
;
2602 /***********************************************************************
2604 ***********************************************************************/
2606 /* The following structure is used to record overlay strings for
2607 later sorting in load_overlay_strings. */
2609 struct overlay_entry
2617 /* Set up iterator IT from overlay strings at its current position.
2618 Called from handle_stop. */
2620 static enum prop_handled
2621 handle_overlay_change (it
)
2624 /* Overlays are handled in current_buffer only. */
2625 if (STRINGP (it
->string
))
2626 return HANDLED_NORMALLY
;
2628 return (get_overlay_strings (it
)
2629 ? HANDLED_RECOMPUTE_PROPS
2630 : HANDLED_NORMALLY
);
2634 /* Set up the next overlay string for delivery by IT, if there is an
2635 overlay string to deliver. Called by set_iterator_to_next when the
2636 end of the current overlay string is reached. If there are more
2637 overlay strings to display, IT->string and
2638 IT->current.overlay_string_index are set appropriately here.
2639 Otherwise IT->string is set to nil. */
2642 next_overlay_string (it
)
2645 ++it
->current
.overlay_string_index
;
2646 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2648 /* No more overlay strings. Restore IT's settings to what
2649 they were before overlay strings were processed, and
2650 continue to deliver from current_buffer. */
2652 xassert (it
->stop_charpos
>= BEGV
2653 && it
->stop_charpos
<= it
->end_charpos
);
2655 it
->current
.overlay_string_index
= -1;
2656 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2657 it
->n_overlay_strings
= 0;
2658 it
->method
= next_element_from_buffer
;
2662 /* There are more overlay strings to process. If
2663 IT->current.overlay_string_index has advanced to a position
2664 where we must load IT->overlay_strings with more strings, do
2666 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2668 if (it
->current
.overlay_string_index
&& i
== 0)
2669 load_overlay_strings (it
);
2671 /* Initialize IT to deliver display elements from the overlay
2673 it
->string
= it
->overlay_strings
[i
];
2674 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2675 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2676 it
->method
= next_element_from_string
;
2677 it
->stop_charpos
= 0;
2684 /* Compare two overlay_entry structures E1 and E2. Used as a
2685 comparison function for qsort in load_overlay_strings. Overlay
2686 strings for the same position are sorted so that
2688 1. All after-strings come in front of before-strings.
2690 2. Within after-strings, strings are sorted so that overlay strings
2691 from overlays with higher priorities come first.
2693 2. Within before-strings, strings are sorted so that overlay
2694 strings from overlays with higher priorities come last.
2696 Value is analogous to strcmp. */
2700 compare_overlay_entries (e1
, e2
)
2703 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2704 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2707 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2708 /* Let after-strings appear in front of before-strings. */
2709 result
= entry1
->after_string_p
? -1 : 1;
2710 else if (entry1
->after_string_p
)
2711 /* After-strings sorted in order of decreasing priority. */
2712 result
= entry2
->priority
- entry1
->priority
;
2714 /* Before-strings sorted in order of increasing priority. */
2715 result
= entry1
->priority
- entry2
->priority
;
2721 /* Load the vector IT->overlay_strings with overlay strings from IT's
2722 current buffer position. Set IT->n_overlays to the total number of
2723 overlay strings found.
2725 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2726 a time. On entry into load_overlay_strings,
2727 IT->current.overlay_string_index gives the number of overlay
2728 strings that have already been loaded by previous calls to this
2731 Overlay strings are sorted so that after-string strings come in
2732 front of before-string strings. Within before and after-strings,
2733 strings are sorted by overlay priority. See also function
2734 compare_overlay_entries. */
2737 load_overlay_strings (it
)
2740 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2741 Lisp_Object ov
, overlay
, window
, str
;
2745 struct overlay_entry
*entries
2746 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2748 /* Append the overlay string STRING of overlay OVERLAY to vector
2749 `entries' which has size `size' and currently contains `n'
2750 elements. AFTER_P non-zero means STRING is an after-string of
2752 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2755 Lisp_Object priority; \
2759 int new_size = 2 * size; \
2760 struct overlay_entry *old = entries; \
2762 (struct overlay_entry *) alloca (new_size \
2763 * sizeof *entries); \
2764 bcopy (old, entries, size * sizeof *entries); \
2768 entries[n].string = (STRING); \
2769 priority = Foverlay_get ((OVERLAY), Qpriority); \
2770 entries[n].priority \
2771 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2772 entries[n].after_string_p = (AFTER_P); \
2777 /* Process overlay before the overlay center. */
2778 for (ov
= current_buffer
->overlays_before
;
2782 overlay
= XCAR (ov
);
2783 xassert (OVERLAYP (overlay
));
2784 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2785 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2787 if (end
< IT_CHARPOS (*it
))
2790 /* Skip this overlay if it doesn't start or end at IT's current
2792 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2795 /* Skip this overlay if it doesn't apply to IT->w. */
2796 window
= Foverlay_get (overlay
, Qwindow
);
2797 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2800 /* If overlay has a non-empty before-string, record it. */
2801 if (start
== IT_CHARPOS (*it
)
2802 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2803 && XSTRING (str
)->size
)
2804 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2806 /* If overlay has a non-empty after-string, record it. */
2807 if (end
== IT_CHARPOS (*it
)
2808 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2809 && XSTRING (str
)->size
)
2810 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2813 /* Process overlays after the overlay center. */
2814 for (ov
= current_buffer
->overlays_after
;
2818 overlay
= XCAR (ov
);
2819 xassert (OVERLAYP (overlay
));
2820 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2821 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2823 if (start
> IT_CHARPOS (*it
))
2826 /* Skip this overlay if it doesn't start or end at IT's current
2828 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2831 /* Skip this overlay if it doesn't apply to IT->w. */
2832 window
= Foverlay_get (overlay
, Qwindow
);
2833 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2836 /* If overlay has a non-empty before-string, record it. */
2837 if (start
== IT_CHARPOS (*it
)
2838 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2839 && XSTRING (str
)->size
)
2840 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2842 /* If overlay has a non-empty after-string, record it. */
2843 if (end
== IT_CHARPOS (*it
)
2844 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2845 && XSTRING (str
)->size
)
2846 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2849 #undef RECORD_OVERLAY_STRING
2852 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2854 /* Record the total number of strings to process. */
2855 it
->n_overlay_strings
= n
;
2857 /* IT->current.overlay_string_index is the number of overlay strings
2858 that have already been consumed by IT. Copy some of the
2859 remaining overlay strings to IT->overlay_strings. */
2861 j
= it
->current
.overlay_string_index
;
2862 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2863 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2869 /* Get the first chunk of overlay strings at IT's current buffer
2870 position. Value is non-zero if at least one overlay string was
2874 get_overlay_strings (it
)
2877 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2878 process. This fills IT->overlay_strings with strings, and sets
2879 IT->n_overlay_strings to the total number of strings to process.
2880 IT->pos.overlay_string_index has to be set temporarily to zero
2881 because load_overlay_strings needs this; it must be set to -1
2882 when no overlay strings are found because a zero value would
2883 indicate a position in the first overlay string. */
2884 it
->current
.overlay_string_index
= 0;
2885 load_overlay_strings (it
);
2887 /* If we found overlay strings, set up IT to deliver display
2888 elements from the first one. Otherwise set up IT to deliver
2889 from current_buffer. */
2890 if (it
->n_overlay_strings
)
2892 /* Make sure we know settings in current_buffer, so that we can
2893 restore meaningful values when we're done with the overlay
2895 compute_stop_pos (it
);
2896 xassert (it
->face_id
>= 0);
2898 /* Save IT's settings. They are restored after all overlay
2899 strings have been processed. */
2900 xassert (it
->sp
== 0);
2903 /* Set up IT to deliver display elements from the first overlay
2905 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2906 it
->stop_charpos
= 0;
2907 it
->string
= it
->overlay_strings
[0];
2908 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2909 xassert (STRINGP (it
->string
));
2910 it
->method
= next_element_from_string
;
2915 it
->current
.overlay_string_index
= -1;
2916 it
->method
= next_element_from_buffer
;
2921 /* Value is non-zero if we found at least one overlay string. */
2922 return STRINGP (it
->string
);
2927 /***********************************************************************
2928 Saving and restoring state
2929 ***********************************************************************/
2931 /* Save current settings of IT on IT->stack. Called, for example,
2932 before setting up IT for an overlay string, to be able to restore
2933 IT's settings to what they were after the overlay string has been
2940 struct iterator_stack_entry
*p
;
2942 xassert (it
->sp
< 2);
2943 p
= it
->stack
+ it
->sp
;
2945 p
->stop_charpos
= it
->stop_charpos
;
2946 xassert (it
->face_id
>= 0);
2947 p
->face_id
= it
->face_id
;
2948 p
->string
= it
->string
;
2949 p
->pos
= it
->current
;
2950 p
->end_charpos
= it
->end_charpos
;
2951 p
->string_nchars
= it
->string_nchars
;
2953 p
->multibyte_p
= it
->multibyte_p
;
2954 p
->space_width
= it
->space_width
;
2955 p
->font_height
= it
->font_height
;
2956 p
->voffset
= it
->voffset
;
2957 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2962 /* Restore IT's settings from IT->stack. Called, for example, when no
2963 more overlay strings must be processed, and we return to delivering
2964 display elements from a buffer, or when the end of a string from a
2965 `display' property is reached and we return to delivering display
2966 elements from an overlay string, or from a buffer. */
2972 struct iterator_stack_entry
*p
;
2974 xassert (it
->sp
> 0);
2976 p
= it
->stack
+ it
->sp
;
2977 it
->stop_charpos
= p
->stop_charpos
;
2978 it
->face_id
= p
->face_id
;
2979 it
->string
= p
->string
;
2980 it
->current
= p
->pos
;
2981 it
->end_charpos
= p
->end_charpos
;
2982 it
->string_nchars
= p
->string_nchars
;
2984 it
->multibyte_p
= p
->multibyte_p
;
2985 it
->space_width
= p
->space_width
;
2986 it
->font_height
= p
->font_height
;
2987 it
->voffset
= p
->voffset
;
2988 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
2993 /***********************************************************************
2995 ***********************************************************************/
2997 /* Set IT's current position to the previous line start. */
3000 back_to_previous_line_start (it
)
3003 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3004 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3008 /* Set IT's current position to the next line start. */
3011 forward_to_next_line_start (it
)
3014 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
3015 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3019 /* Set IT's current position to the previous visible line start. Skip
3020 invisible text that is so either due to text properties or due to
3021 selective display. Caution: this does not change IT->current_x and
3025 back_to_previous_visible_line_start (it
)
3030 /* Go back one newline if not on BEGV already. */
3031 if (IT_CHARPOS (*it
) > BEGV
)
3032 back_to_previous_line_start (it
);
3034 /* Move over lines that are invisible because of selective display
3035 or text properties. */
3036 while (IT_CHARPOS (*it
) > BEGV
3041 /* If selective > 0, then lines indented more than that values
3043 if (it
->selective
> 0
3044 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3051 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3052 Qinvisible
, it
->window
);
3053 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3057 /* Back one more newline if the current one is invisible. */
3059 back_to_previous_line_start (it
);
3062 xassert (IT_CHARPOS (*it
) >= BEGV
);
3063 xassert (IT_CHARPOS (*it
) == BEGV
3064 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3069 /* Reseat iterator IT at the previous visible line start. Skip
3070 invisible text that is so either due to text properties or due to
3071 selective display. At the end, update IT's overlay information,
3072 face information etc. */
3075 reseat_at_previous_visible_line_start (it
)
3078 back_to_previous_visible_line_start (it
);
3079 reseat (it
, it
->current
.pos
, 1);
3084 /* Reseat iterator IT on the next visible line start in the current
3085 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3086 preceding the line start. Skip over invisible text that is so
3087 because of selective display. Compute faces, overlays etc at the
3088 new position. Note that this function does not skip over text that
3089 is invisible because of text properties. */
3092 reseat_at_next_visible_line_start (it
, on_newline_p
)
3096 /* Restore the buffer position when currently not delivering display
3097 elements from the current buffer. This is the case, for example,
3098 when called at the end of a truncated overlay string. */
3101 it
->method
= next_element_from_buffer
;
3103 /* Otherwise, scan_buffer would not work. */
3104 if (IT_CHARPOS (*it
) < ZV
)
3106 /* If on a newline, advance past it. Otherwise, find the next
3107 newline which automatically gives us the position following
3109 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3115 forward_to_next_line_start (it
);
3117 /* We must either have reached the end of the buffer or end up
3119 xassert (IT_CHARPOS (*it
) == ZV
3120 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3122 /* Skip over lines that are invisible because they are indented
3123 more than the value of IT->selective. */
3124 if (it
->selective
> 0)
3125 while (IT_CHARPOS (*it
) < ZV
3126 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3128 forward_to_next_line_start (it
);
3130 /* Position on the newline if we should. */
3132 && IT_CHARPOS (*it
) > BEGV
3133 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n')
3136 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3139 /* Set the iterator there. The 0 as the last parameter of
3140 reseat means don't force a text property lookup. The lookup
3141 is then only done if we've skipped past the iterator's
3142 check_charpos'es. This optimization is important because
3143 text property lookups tend to be expensive. */
3144 reseat (it
, it
->current
.pos
, 0);
3152 /***********************************************************************
3153 Changing an iterator's position
3154 ***********************************************************************/
3156 /* Change IT's current position to POS in current_buffer. If FORCE_P
3157 is non-zero, always check for text properties at the new position.
3158 Otherwise, text properties are only looked up if POS >=
3159 IT->check_charpos of a property. */
3162 reseat (it
, pos
, force_p
)
3164 struct text_pos pos
;
3167 int original_pos
= IT_CHARPOS (*it
);
3169 reseat_1 (it
, pos
, 0);
3171 /* Determine where to check text properties. Avoid doing it
3172 where possible because text property lookup is very expensive. */
3174 || CHARPOS (pos
) > it
->stop_charpos
3175 || CHARPOS (pos
) < original_pos
)
3182 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3183 IT->stop_pos to POS, also. */
3186 reseat_1 (it
, pos
, set_stop_p
)
3188 struct text_pos pos
;
3191 /* Don't call this function when scanning a C string. */
3192 xassert (it
->s
== NULL
);
3194 /* POS must be a reasonable value. */
3195 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3197 it
->current
.pos
= it
->position
= pos
;
3198 XSETBUFFER (it
->object
, current_buffer
);
3200 it
->current
.dpvec_index
= -1;
3201 it
->current
.overlay_string_index
= -1;
3202 IT_STRING_CHARPOS (*it
) = -1;
3203 IT_STRING_BYTEPOS (*it
) = -1;
3205 it
->method
= next_element_from_buffer
;
3209 it
->stop_charpos
= CHARPOS (pos
);
3213 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3214 If S is non-null, it is a C string to iterate over. Otherwise,
3215 STRING gives a Lisp string to iterate over.
3217 If PRECISION > 0, don't return more then PRECISION number of
3218 characters from the string.
3220 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3221 characters have been returned. FIELD_WIDTH < 0 means an infinite
3224 MULTIBYTE = 0 means disable processing of multibyte characters,
3225 MULTIBYTE > 0 means enable it,
3226 MULTIBYTE < 0 means use IT->multibyte_p.
3228 IT must be initialized via a prior call to init_iterator before
3229 calling this function. */
3232 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3237 int precision
, field_width
, multibyte
;
3239 /* No region in strings. */
3240 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3242 /* No text property checks performed by default, but see below. */
3243 it
->stop_charpos
= -1;
3245 /* Set iterator position and end position. */
3246 bzero (&it
->current
, sizeof it
->current
);
3247 it
->current
.overlay_string_index
= -1;
3248 it
->current
.dpvec_index
= -1;
3249 xassert (charpos
>= 0);
3251 /* Use the setting of MULTIBYTE if specified. */
3253 it
->multibyte_p
= multibyte
> 0;
3257 xassert (STRINGP (string
));
3258 it
->string
= string
;
3260 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3261 it
->method
= next_element_from_string
;
3262 it
->current
.string_pos
= string_pos (charpos
, string
);
3269 /* Note that we use IT->current.pos, not it->current.string_pos,
3270 for displaying C strings. */
3271 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3272 if (it
->multibyte_p
)
3274 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3275 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3279 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3280 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3283 it
->method
= next_element_from_c_string
;
3286 /* PRECISION > 0 means don't return more than PRECISION characters
3288 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3289 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3291 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3292 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3293 FIELD_WIDTH < 0 means infinite field width. This is useful for
3294 padding with `-' at the end of a mode line. */
3295 if (field_width
< 0)
3296 field_width
= INFINITY
;
3297 if (field_width
> it
->end_charpos
- charpos
)
3298 it
->end_charpos
= charpos
+ field_width
;
3300 /* Use the standard display table for displaying strings. */
3301 if (DISP_TABLE_P (Vstandard_display_table
))
3302 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3304 it
->stop_charpos
= charpos
;
3310 /***********************************************************************
3312 ***********************************************************************/
3314 /* Load IT's display element fields with information about the next
3315 display element from the current position of IT. Value is zero if
3316 end of buffer (or C string) is reached. */
3319 get_next_display_element (it
)
3322 /* Non-zero means that we found an display element. Zero means that
3323 we hit the end of what we iterate over. Performance note: the
3324 function pointer `method' used here turns out to be faster than
3325 using a sequence of if-statements. */
3326 int success_p
= (*it
->method
) (it
);
3328 if (it
->what
== IT_CHARACTER
)
3330 /* Map via display table or translate control characters.
3331 IT->c, IT->len etc. have been set to the next character by
3332 the function call above. If we have a display table, and it
3333 contains an entry for IT->c, translate it. Don't do this if
3334 IT->c itself comes from a display table, otherwise we could
3335 end up in an infinite recursion. (An alternative could be to
3336 count the recursion depth of this function and signal an
3337 error when a certain maximum depth is reached.) Is it worth
3339 if (success_p
&& it
->dpvec
== NULL
)
3344 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3347 struct Lisp_Vector
*v
= XVECTOR (dv
);
3349 /* Return the first character from the display table
3350 entry, if not empty. If empty, don't display the
3351 current character. */
3354 it
->dpvec_char_len
= it
->len
;
3355 it
->dpvec
= v
->contents
;
3356 it
->dpend
= v
->contents
+ v
->size
;
3357 it
->current
.dpvec_index
= 0;
3358 it
->method
= next_element_from_display_vector
;
3361 success_p
= get_next_display_element (it
);
3364 /* Translate control characters into `\003' or `^C' form.
3365 Control characters coming from a display table entry are
3366 currently not translated because we use IT->dpvec to hold
3367 the translation. This could easily be changed but I
3368 don't believe that it is worth doing.
3370 Non-printable multibyte characters are also translated
3372 else if ((it
->c
< ' '
3373 && (it
->area
!= TEXT_AREA
3374 || (it
->c
!= '\n' && it
->c
!= '\t')))
3377 || !CHAR_PRINTABLE_P (it
->c
))
3379 /* IT->c is a control character which must be displayed
3380 either as '\003' or as `^C' where the '\\' and '^'
3381 can be defined in the display table. Fill
3382 IT->ctl_chars with glyphs for what we have to
3383 display. Then, set IT->dpvec to these glyphs. */
3386 if (it
->c
< 128 && it
->ctl_arrow_p
)
3388 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3390 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3391 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3392 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3394 g
= FAST_MAKE_GLYPH ('^', 0);
3395 XSETINT (it
->ctl_chars
[0], g
);
3397 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3398 XSETINT (it
->ctl_chars
[1], g
);
3400 /* Set up IT->dpvec and return first character from it. */
3401 it
->dpvec_char_len
= it
->len
;
3402 it
->dpvec
= it
->ctl_chars
;
3403 it
->dpend
= it
->dpvec
+ 2;
3404 it
->current
.dpvec_index
= 0;
3405 it
->method
= next_element_from_display_vector
;
3406 get_next_display_element (it
);
3410 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3411 int len
= CHAR_STRING (it
->c
, str
);
3415 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3417 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3418 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3419 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3421 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3423 for (i
= 0; i
< len
; i
++)
3425 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3426 /* Insert three more glyphs into IT->ctl_chars for
3427 the octal display of the character. */
3428 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3429 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3430 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3431 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3432 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3433 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3436 /* Set up IT->dpvec and return the first character
3438 it
->dpvec_char_len
= it
->len
;
3439 it
->dpvec
= it
->ctl_chars
;
3440 it
->dpend
= it
->dpvec
+ len
* 4;
3441 it
->current
.dpvec_index
= 0;
3442 it
->method
= next_element_from_display_vector
;
3443 get_next_display_element (it
);
3448 /* Adjust face id for a multibyte character. There are no
3449 multibyte character in unibyte text. */
3452 && FRAME_WINDOW_P (it
->f
))
3454 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3455 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3459 /* Is this character the last one of a run of characters with
3460 box? If yes, set IT->end_of_box_run_p to 1. */
3467 it
->end_of_box_run_p
3468 = ((face_id
= face_after_it_pos (it
),
3469 face_id
!= it
->face_id
)
3470 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3471 face
->box
== FACE_NO_BOX
));
3474 /* Value is 0 if end of buffer or string reached. */
3479 /* Move IT to the next display element.
3481 Functions get_next_display_element and set_iterator_to_next are
3482 separate because I find this arrangement easier to handle than a
3483 get_next_display_element function that also increments IT's
3484 position. The way it is we can first look at an iterator's current
3485 display element, decide whether it fits on a line, and if it does,
3486 increment the iterator position. The other way around we probably
3487 would either need a flag indicating whether the iterator has to be
3488 incremented the next time, or we would have to implement a
3489 decrement position function which would not be easy to write. */
3492 set_iterator_to_next (it
)
3495 if (it
->method
== next_element_from_buffer
)
3497 /* The current display element of IT is a character from
3498 current_buffer. Advance in the buffer, and maybe skip over
3499 invisible lines that are so because of selective display. */
3500 if (ITERATOR_AT_END_OF_LINE_P (it
))
3501 reseat_at_next_visible_line_start (it
, 0);
3504 xassert (it
->len
!= 0);
3505 IT_BYTEPOS (*it
) += it
->len
;
3506 IT_CHARPOS (*it
) += 1;
3507 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3510 else if (it
->method
== next_element_from_composition
)
3512 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3513 if (STRINGP (it
->string
))
3515 IT_STRING_BYTEPOS (*it
) += it
->len
;
3516 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3517 it
->method
= next_element_from_string
;
3518 goto consider_string_end
;
3522 IT_BYTEPOS (*it
) += it
->len
;
3523 IT_CHARPOS (*it
) += it
->cmp_len
;
3524 it
->method
= next_element_from_buffer
;
3527 else if (it
->method
== next_element_from_c_string
)
3529 /* Current display element of IT is from a C string. */
3530 IT_BYTEPOS (*it
) += it
->len
;
3531 IT_CHARPOS (*it
) += 1;
3533 else if (it
->method
== next_element_from_display_vector
)
3535 /* Current display element of IT is from a display table entry.
3536 Advance in the display table definition. Reset it to null if
3537 end reached, and continue with characters from buffers/
3539 ++it
->current
.dpvec_index
;
3541 /* Restore face of the iterator to what they were before the
3542 display vector entry (these entries may contain faces). */
3543 it
->face_id
= it
->saved_face_id
;
3545 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3548 it
->method
= next_element_from_c_string
;
3549 else if (STRINGP (it
->string
))
3550 it
->method
= next_element_from_string
;
3552 it
->method
= next_element_from_buffer
;
3555 it
->current
.dpvec_index
= -1;
3557 /* Skip over characters which were displayed via IT->dpvec. */
3558 if (it
->dpvec_char_len
< 0)
3559 reseat_at_next_visible_line_start (it
, 1);
3560 else if (it
->dpvec_char_len
> 0)
3562 it
->len
= it
->dpvec_char_len
;
3563 set_iterator_to_next (it
);
3567 else if (it
->method
== next_element_from_string
)
3569 /* Current display element is a character from a Lisp string. */
3570 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3571 IT_STRING_BYTEPOS (*it
) += it
->len
;
3572 IT_STRING_CHARPOS (*it
) += 1;
3574 consider_string_end
:
3576 if (it
->current
.overlay_string_index
>= 0)
3578 /* IT->string is an overlay string. Advance to the
3579 next, if there is one. */
3580 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3581 next_overlay_string (it
);
3585 /* IT->string is not an overlay string. If we reached
3586 its end, and there is something on IT->stack, proceed
3587 with what is on the stack. This can be either another
3588 string, this time an overlay string, or a buffer. */
3589 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3593 if (!STRINGP (it
->string
))
3594 it
->method
= next_element_from_buffer
;
3598 else if (it
->method
== next_element_from_image
3599 || it
->method
== next_element_from_stretch
)
3601 /* The position etc with which we have to proceed are on
3602 the stack. The position may be at the end of a string,
3603 if the `display' property takes up the whole string. */
3606 if (STRINGP (it
->string
))
3608 it
->method
= next_element_from_string
;
3609 goto consider_string_end
;
3612 it
->method
= next_element_from_buffer
;
3615 /* There are no other methods defined, so this should be a bug. */
3618 /* Reset flags indicating start and end of a sequence of
3619 characters with box. */
3620 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3622 xassert (it
->method
!= next_element_from_string
3623 || (STRINGP (it
->string
)
3624 && IT_STRING_CHARPOS (*it
) >= 0));
3628 /* Load IT's display element fields with information about the next
3629 display element which comes from a display table entry or from the
3630 result of translating a control character to one of the forms `^C'
3631 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3634 next_element_from_display_vector (it
)
3638 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3640 /* Remember the current face id in case glyphs specify faces.
3641 IT's face is restored in set_iterator_to_next. */
3642 it
->saved_face_id
= it
->face_id
;
3644 if (INTEGERP (*it
->dpvec
)
3645 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3650 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3651 it
->c
= FAST_GLYPH_CHAR (g
);
3652 it
->len
= CHAR_LEN (it
->c
);
3654 /* The entry may contain a face id to use. Such a face id is
3655 the id of a Lisp face, not a realized face. A face id of
3656 zero means no face. */
3657 lface_id
= FAST_GLYPH_FACE (g
);
3660 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3663 it
->face_id
= face_id
;
3668 /* Display table entry is invalid. Return a space. */
3669 it
->c
= ' ', it
->len
= 1;
3671 /* Don't change position and object of the iterator here. They are
3672 still the values of the character that had this display table
3673 entry or was translated, and that's what we want. */
3674 it
->what
= IT_CHARACTER
;
3679 /* Load IT with the next display element from Lisp string IT->string.
3680 IT->current.string_pos is the current position within the string.
3681 If IT->current.overlay_string_index >= 0, the Lisp string is an
3685 next_element_from_string (it
)
3688 struct text_pos position
;
3690 xassert (STRINGP (it
->string
));
3691 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3692 position
= it
->current
.string_pos
;
3694 /* Time to check for invisible text? */
3695 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3696 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3700 /* Since a handler may have changed IT->method, we must
3702 return get_next_display_element (it
);
3705 if (it
->current
.overlay_string_index
>= 0)
3707 /* Get the next character from an overlay string. In overlay
3708 strings, There is no field width or padding with spaces to
3710 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3715 else if (STRING_MULTIBYTE (it
->string
))
3717 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3718 - IT_STRING_BYTEPOS (*it
));
3719 unsigned char *s
= (XSTRING (it
->string
)->data
3720 + IT_STRING_BYTEPOS (*it
));
3721 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3725 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3731 /* Get the next character from a Lisp string that is not an
3732 overlay string. Such strings come from the mode line, for
3733 example. We may have to pad with spaces, or truncate the
3734 string. See also next_element_from_c_string. */
3735 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3740 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3742 /* Pad with spaces. */
3743 it
->c
= ' ', it
->len
= 1;
3744 CHARPOS (position
) = BYTEPOS (position
) = -1;
3746 else if (STRING_MULTIBYTE (it
->string
))
3748 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3749 - IT_STRING_BYTEPOS (*it
));
3750 unsigned char *s
= (XSTRING (it
->string
)->data
3751 + IT_STRING_BYTEPOS (*it
));
3752 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3756 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3761 /* Record what we have and where it came from. Note that we store a
3762 buffer position in IT->position although it could arguably be a
3764 it
->what
= IT_CHARACTER
;
3765 it
->object
= it
->string
;
3766 it
->position
= position
;
3771 /* Load IT with next display element from C string IT->s.
3772 IT->string_nchars is the maximum number of characters to return
3773 from the string. IT->end_charpos may be greater than
3774 IT->string_nchars when this function is called, in which case we
3775 may have to return padding spaces. Value is zero if end of string
3776 reached, including padding spaces. */
3779 next_element_from_c_string (it
)
3785 it
->what
= IT_CHARACTER
;
3786 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3789 /* IT's position can be greater IT->string_nchars in case a field
3790 width or precision has been specified when the iterator was
3792 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3794 /* End of the game. */
3798 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3800 /* Pad with spaces. */
3801 it
->c
= ' ', it
->len
= 1;
3802 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3804 else if (it
->multibyte_p
)
3806 /* Implementation note: The calls to strlen apparently aren't a
3807 performance problem because there is no noticeable performance
3808 difference between Emacs running in unibyte or multibyte mode. */
3809 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3810 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3814 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3820 /* Set up IT to return characters from an ellipsis, if appropriate.
3821 The definition of the ellipsis glyphs may come from a display table
3822 entry. This function Fills IT with the first glyph from the
3823 ellipsis if an ellipsis is to be displayed. */
3826 next_element_from_ellipsis (it
)
3829 if (it
->selective_display_ellipsis_p
)
3831 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3833 /* Use the display table definition for `...'. Invalid glyphs
3834 will be handled by the method returning elements from dpvec. */
3835 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3836 it
->dpvec_char_len
= it
->len
;
3837 it
->dpvec
= v
->contents
;
3838 it
->dpend
= v
->contents
+ v
->size
;
3839 it
->current
.dpvec_index
= 0;
3840 it
->method
= next_element_from_display_vector
;
3844 /* Use default `...' which is stored in default_invis_vector. */
3845 it
->dpvec_char_len
= it
->len
;
3846 it
->dpvec
= default_invis_vector
;
3847 it
->dpend
= default_invis_vector
+ 3;
3848 it
->current
.dpvec_index
= 0;
3849 it
->method
= next_element_from_display_vector
;
3853 reseat_at_next_visible_line_start (it
, 1);
3855 return get_next_display_element (it
);
3859 /* Deliver an image display element. The iterator IT is already
3860 filled with image information (done in handle_display_prop). Value
3865 next_element_from_image (it
)
3868 it
->what
= IT_IMAGE
;
3873 /* Fill iterator IT with next display element from a stretch glyph
3874 property. IT->object is the value of the text property. Value is
3878 next_element_from_stretch (it
)
3881 it
->what
= IT_STRETCH
;
3886 /* Load IT with the next display element from current_buffer. Value
3887 is zero if end of buffer reached. IT->stop_charpos is the next
3888 position at which to stop and check for text properties or buffer
3892 next_element_from_buffer (it
)
3897 /* Check this assumption, otherwise, we would never enter the
3898 if-statement, below. */
3899 xassert (IT_CHARPOS (*it
) >= BEGV
3900 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3902 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3904 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3906 int overlay_strings_follow_p
;
3908 /* End of the game, except when overlay strings follow that
3909 haven't been returned yet. */
3910 if (it
->overlay_strings_at_end_processed_p
)
3911 overlay_strings_follow_p
= 0;
3914 it
->overlay_strings_at_end_processed_p
= 1;
3915 overlay_strings_follow_p
= get_overlay_strings (it
);
3918 if (overlay_strings_follow_p
)
3919 success_p
= get_next_display_element (it
);
3923 it
->position
= it
->current
.pos
;
3930 return get_next_display_element (it
);
3935 /* No face changes, overlays etc. in sight, so just return a
3936 character from current_buffer. */
3939 /* Maybe run the redisplay end trigger hook. Performance note:
3940 This doesn't seem to cost measurable time. */
3941 if (it
->redisplay_end_trigger_charpos
3943 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3944 run_redisplay_end_trigger_hook (it
);
3946 /* Get the next character, maybe multibyte. */
3947 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3948 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
3950 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3951 - IT_BYTEPOS (*it
));
3952 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3955 it
->c
= *p
, it
->len
= 1;
3957 /* Record what we have and where it came from. */
3958 it
->what
= IT_CHARACTER
;;
3959 it
->object
= it
->w
->buffer
;
3960 it
->position
= it
->current
.pos
;
3962 /* Normally we return the character found above, except when we
3963 really want to return an ellipsis for selective display. */
3968 /* A value of selective > 0 means hide lines indented more
3969 than that number of columns. */
3970 if (it
->selective
> 0
3971 && IT_CHARPOS (*it
) + 1 < ZV
3972 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3973 IT_BYTEPOS (*it
) + 1,
3976 success_p
= next_element_from_ellipsis (it
);
3977 it
->dpvec_char_len
= -1;
3980 else if (it
->c
== '\r' && it
->selective
== -1)
3982 /* A value of selective == -1 means that everything from the
3983 CR to the end of the line is invisible, with maybe an
3984 ellipsis displayed for it. */
3985 success_p
= next_element_from_ellipsis (it
);
3986 it
->dpvec_char_len
= -1;
3991 /* Value is zero if end of buffer reached. */
3992 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
3997 /* Run the redisplay end trigger hook for IT. */
4000 run_redisplay_end_trigger_hook (it
)
4003 Lisp_Object args
[3];
4005 /* IT->glyph_row should be non-null, i.e. we should be actually
4006 displaying something, or otherwise we should not run the hook. */
4007 xassert (it
->glyph_row
);
4009 /* Set up hook arguments. */
4010 args
[0] = Qredisplay_end_trigger_functions
;
4011 args
[1] = it
->window
;
4012 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4013 it
->redisplay_end_trigger_charpos
= 0;
4015 /* Since we are *trying* to run these functions, don't try to run
4016 them again, even if they get an error. */
4017 it
->w
->redisplay_end_trigger
= Qnil
;
4018 Frun_hook_with_args (3, args
);
4020 /* Notice if it changed the face of the character we are on. */
4021 handle_face_prop (it
);
4025 /* Deliver a composition display element. The iterator IT is already
4026 filled with composition information (done in
4027 handle_composition_prop). Value is always 1. */
4030 next_element_from_composition (it
)
4033 it
->what
= IT_COMPOSITION
;
4034 it
->position
= (STRINGP (it
->string
)
4035 ? it
->current
.string_pos
4042 /***********************************************************************
4043 Moving an iterator without producing glyphs
4044 ***********************************************************************/
4046 /* Move iterator IT to a specified buffer or X position within one
4047 line on the display without producing glyphs.
4049 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4050 whichever is reached first.
4052 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4054 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4055 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4056 TO_X includes the amount by which a window is horizontally
4061 MOVE_POS_MATCH_OR_ZV
4062 - when TO_POS or ZV was reached.
4065 -when TO_X was reached before TO_POS or ZV were reached.
4068 - when we reached the end of the display area and the line must
4072 - when we reached the end of the display area and the line is
4076 - when we stopped at a line end, i.e. a newline or a CR and selective
4079 static enum move_it_result
4080 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4082 int to_charpos
, to_x
, op
;
4084 enum move_it_result result
= MOVE_UNDEFINED
;
4085 struct glyph_row
*saved_glyph_row
;
4087 /* Don't produce glyphs in produce_glyphs. */
4088 saved_glyph_row
= it
->glyph_row
;
4089 it
->glyph_row
= NULL
;
4095 /* Stop when ZV or TO_CHARPOS reached. */
4096 if (!get_next_display_element (it
)
4097 || ((op
& MOVE_TO_POS
) != 0
4098 && BUFFERP (it
->object
)
4099 && IT_CHARPOS (*it
) >= to_charpos
))
4101 result
= MOVE_POS_MATCH_OR_ZV
;
4105 /* The call to produce_glyphs will get the metrics of the
4106 display element IT is loaded with. We record in x the
4107 x-position before this display element in case it does not
4110 PRODUCE_GLYPHS (it
);
4112 if (it
->area
!= TEXT_AREA
)
4114 set_iterator_to_next (it
);
4118 /* The number of glyphs we get back in IT->nglyphs will normally
4119 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4120 character on a terminal frame, or (iii) a line end. For the
4121 second case, IT->nglyphs - 1 padding glyphs will be present
4122 (on X frames, there is only one glyph produced for a
4123 composite character.
4125 The behavior implemented below means, for continuation lines,
4126 that as many spaces of a TAB as fit on the current line are
4127 displayed there. For terminal frames, as many glyphs of a
4128 multi-glyph character are displayed in the current line, too.
4129 This is what the old redisplay code did, and we keep it that
4130 way. Under X, the whole shape of a complex character must
4131 fit on the line or it will be completely displayed in the
4134 Note that both for tabs and padding glyphs, all glyphs have
4138 /* More than one glyph or glyph doesn't fit on line. All
4139 glyphs have the same width. */
4140 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4143 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4145 new_x
= x
+ single_glyph_width
;
4147 /* We want to leave anything reaching TO_X to the caller. */
4148 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4151 result
= MOVE_X_REACHED
;
4154 else if (/* Lines are continued. */
4155 !it
->truncate_lines_p
4156 && (/* And glyph doesn't fit on the line. */
4157 new_x
> it
->last_visible_x
4158 /* Or it fits exactly and we're on a window
4160 || (new_x
== it
->last_visible_x
4161 && FRAME_WINDOW_P (it
->f
))))
4163 if (/* IT->hpos == 0 means the very first glyph
4164 doesn't fit on the line, e.g. a wide image. */
4166 || (new_x
== it
->last_visible_x
4167 && FRAME_WINDOW_P (it
->f
)))
4170 it
->current_x
= new_x
;
4171 if (i
== it
->nglyphs
- 1)
4172 set_iterator_to_next (it
);
4177 result
= MOVE_LINE_CONTINUED
;
4180 else if (new_x
> it
->first_visible_x
)
4182 /* Glyph is visible. Increment number of glyphs that
4183 would be displayed. */
4188 /* Glyph is completely off the left margin of the display
4189 area. Nothing to do. */
4193 if (result
!= MOVE_UNDEFINED
)
4196 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4198 /* Stop when TO_X specified and reached. This check is
4199 necessary here because of lines consisting of a line end,
4200 only. The line end will not produce any glyphs and we
4201 would never get MOVE_X_REACHED. */
4202 xassert (it
->nglyphs
== 0);
4203 result
= MOVE_X_REACHED
;
4207 /* Is this a line end? If yes, we're done. */
4208 if (ITERATOR_AT_END_OF_LINE_P (it
))
4210 result
= MOVE_NEWLINE_OR_CR
;
4214 /* The current display element has been consumed. Advance
4216 set_iterator_to_next (it
);
4218 /* Stop if lines are truncated and IT's current x-position is
4219 past the right edge of the window now. */
4220 if (it
->truncate_lines_p
4221 && it
->current_x
>= it
->last_visible_x
)
4223 result
= MOVE_LINE_TRUNCATED
;
4228 /* Restore the iterator settings altered at the beginning of this
4230 it
->glyph_row
= saved_glyph_row
;
4235 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4236 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4237 the description of enum move_operation_enum.
4239 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4240 screen line, this function will set IT to the next position >
4244 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4246 int to_charpos
, to_x
, to_y
, to_vpos
;
4249 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4254 if (op
& MOVE_TO_VPOS
)
4256 /* If no TO_CHARPOS and no TO_X specified, stop at the
4257 start of the line TO_VPOS. */
4258 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4260 if (it
->vpos
== to_vpos
)
4262 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4266 /* TO_VPOS >= 0 means stop at TO_X in the line at
4267 TO_VPOS, or at TO_POS, whichever comes first. */
4268 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4270 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4272 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4274 /* We have reached TO_X but not in the line we want. */
4275 skip
= move_it_in_display_line_to (it
, to_charpos
,
4277 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4282 else if (op
& MOVE_TO_Y
)
4284 struct it it_backup
;
4287 /* TO_Y specified means stop at TO_X in the line containing
4288 TO_Y---or at TO_CHARPOS if this is reached first. The
4289 problem is that we can't really tell whether the line
4290 contains TO_Y before we have completely scanned it, and
4291 this may skip past TO_X. What we do is to first scan to
4294 If TO_X is not specified, use a TO_X of zero. The reason
4295 is to make the outcome of this function more predictable.
4296 If we didn't use TO_X == 0, we would stop at the end of
4297 the line which is probably not what a caller would expect
4299 skip
= move_it_in_display_line_to (it
, to_charpos
,
4303 | (op
& MOVE_TO_POS
)));
4305 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4306 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4309 /* If TO_X was reached, we would like to know whether TO_Y
4310 is in the line. This can only be said if we know the
4311 total line height which requires us to scan the rest of
4314 if (skip
== MOVE_X_REACHED
)
4317 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4321 /* Now, decide whether TO_Y is in this line. */
4322 line_height
= it
->max_ascent
+ it
->max_descent
;
4324 if (to_y
>= it
->current_y
4325 && to_y
< it
->current_y
+ line_height
)
4327 if (skip
== MOVE_X_REACHED
)
4328 /* If TO_Y is in this line and TO_X was reached above,
4329 we scanned too far. We have to restore IT's settings
4330 to the ones before skipping. */
4334 else if (skip
== MOVE_X_REACHED
)
4337 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4345 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4349 case MOVE_POS_MATCH_OR_ZV
:
4352 case MOVE_NEWLINE_OR_CR
:
4353 set_iterator_to_next (it
);
4354 it
->continuation_lines_width
= 0;
4357 case MOVE_LINE_TRUNCATED
:
4358 it
->continuation_lines_width
= 0;
4359 reseat_at_next_visible_line_start (it
, 0);
4360 if ((op
& MOVE_TO_POS
) != 0
4361 && IT_CHARPOS (*it
) > to_charpos
)
4365 case MOVE_LINE_CONTINUED
:
4366 it
->continuation_lines_width
+= it
->current_x
;
4373 /* Reset/increment for the next run. */
4374 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4375 it
->current_x
= it
->hpos
= 0;
4376 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4378 last_height
= it
->max_ascent
+ it
->max_descent
;
4379 last_max_ascent
= it
->max_ascent
;
4380 it
->max_ascent
= it
->max_descent
= 0;
4386 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4388 If DY > 0, move IT backward at least that many pixels. DY = 0
4389 means move IT backward to the preceding line start or BEGV. This
4390 function may move over more than DY pixels if IT->current_y - DY
4391 ends up in the middle of a line; in this case IT->current_y will be
4392 set to the top of the line moved to. */
4395 move_it_vertically_backward (it
, dy
)
4399 int nlines
, h
, line_height
;
4401 int start_pos
= IT_CHARPOS (*it
);
4405 /* Estimate how many newlines we must move back. */
4406 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4408 /* Set the iterator's position that many lines back. */
4409 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4410 back_to_previous_visible_line_start (it
);
4412 /* Reseat the iterator here. When moving backward, we don't want
4413 reseat to skip forward over invisible text, set up the iterator
4414 to deliver from overlay strings at the new position etc. So,
4415 use reseat_1 here. */
4416 reseat_1 (it
, it
->current
.pos
, 1);
4418 /* We are now surely at a line start. */
4419 it
->current_x
= it
->hpos
= 0;
4421 /* Move forward and see what y-distance we moved. First move to the
4422 start of the next line so that we get its height. We need this
4423 height to be able to tell whether we reached the specified
4426 it2
.max_ascent
= it2
.max_descent
= 0;
4427 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4428 MOVE_TO_POS
| MOVE_TO_VPOS
);
4429 xassert (IT_CHARPOS (*it
) >= BEGV
);
4430 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4431 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4432 xassert (IT_CHARPOS (*it
) >= BEGV
);
4433 h
= it2
.current_y
- it
->current_y
;
4434 nlines
= it2
.vpos
- it
->vpos
;
4436 /* Correct IT's y and vpos position. */
4442 /* DY == 0 means move to the start of the screen line. The
4443 value of nlines is > 0 if continuation lines were involved. */
4445 move_it_by_lines (it
, nlines
, 1);
4446 xassert (IT_CHARPOS (*it
) <= start_pos
);
4450 /* The y-position we try to reach. Note that h has been
4451 subtracted in front of the if-statement. */
4452 int target_y
= it
->current_y
+ h
- dy
;
4454 /* If we did not reach target_y, try to move further backward if
4455 we can. If we moved too far backward, try to move forward. */
4456 if (target_y
< it
->current_y
4457 && IT_CHARPOS (*it
) > BEGV
)
4459 move_it_vertically (it
, target_y
- it
->current_y
);
4460 xassert (IT_CHARPOS (*it
) >= BEGV
);
4462 else if (target_y
>= it
->current_y
+ line_height
4463 && IT_CHARPOS (*it
) < ZV
)
4465 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4466 xassert (IT_CHARPOS (*it
) >= BEGV
);
4472 /* Move IT by a specified amount of pixel lines DY. DY negative means
4473 move backwards. DY = 0 means move to start of screen line. At the
4474 end, IT will be on the start of a screen line. */
4477 move_it_vertically (it
, dy
)
4482 move_it_vertically_backward (it
, -dy
);
4485 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4486 MOVE_TO_POS
| MOVE_TO_Y
);
4488 /* If buffer ends in ZV without a newline, move to the start of
4489 the line to satisfy the post-condition. */
4490 if (IT_CHARPOS (*it
) == ZV
4491 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4492 move_it_by_lines (it
, 0, 0);
4497 /* Return non-zero if some text between buffer positions START_CHARPOS
4498 and END_CHARPOS is invisible. IT->window is the window for text
4502 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4504 int start_charpos
, end_charpos
;
4506 Lisp_Object prop
, limit
;
4507 int invisible_found_p
;
4509 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4511 /* Is text at START invisible? */
4512 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4514 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4515 invisible_found_p
= 1;
4518 limit
= next_single_char_property_change (make_number (start_charpos
),
4520 make_number (end_charpos
));
4521 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4524 return invisible_found_p
;
4528 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4529 negative means move up. DVPOS == 0 means move to the start of the
4530 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4531 NEED_Y_P is zero, IT->current_y will be left unchanged.
4533 Further optimization ideas: If we would know that IT->f doesn't use
4534 a face with proportional font, we could be faster for
4535 truncate-lines nil. */
4538 move_it_by_lines (it
, dvpos
, need_y_p
)
4540 int dvpos
, need_y_p
;
4542 struct position pos
;
4544 if (!FRAME_WINDOW_P (it
->f
))
4546 struct text_pos textpos
;
4548 /* We can use vmotion on frames without proportional fonts. */
4549 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4550 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4551 reseat (it
, textpos
, 1);
4552 it
->vpos
+= pos
.vpos
;
4553 it
->current_y
+= pos
.vpos
;
4555 else if (dvpos
== 0)
4557 /* DVPOS == 0 means move to the start of the screen line. */
4558 move_it_vertically_backward (it
, 0);
4559 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4563 /* If there are no continuation lines, and if there is no
4564 selective display, try the simple method of moving forward
4565 DVPOS newlines, then see where we are. */
4566 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4568 int shortage
= 0, charpos
;
4570 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4571 charpos
= IT_CHARPOS (*it
) + 1;
4573 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4576 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4578 struct text_pos pos
;
4579 CHARPOS (pos
) = charpos
;
4580 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4581 reseat (it
, pos
, 1);
4582 it
->vpos
+= dvpos
- shortage
;
4583 it
->hpos
= it
->current_x
= 0;
4588 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4593 int start_charpos
, i
;
4595 /* If there are no continuation lines, and if there is no
4596 selective display, try the simple method of moving backward
4598 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4601 int charpos
= IT_CHARPOS (*it
);
4602 int bytepos
= IT_BYTEPOS (*it
);
4604 /* If in the middle of a line, go to its start. */
4605 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4607 charpos
= find_next_newline_no_quit (charpos
, -1);
4608 bytepos
= CHAR_TO_BYTE (charpos
);
4611 if (charpos
== BEGV
)
4613 struct text_pos pos
;
4614 CHARPOS (pos
) = charpos
;
4615 BYTEPOS (pos
) = bytepos
;
4616 reseat (it
, pos
, 1);
4617 it
->hpos
= it
->current_x
= 0;
4622 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4623 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4625 struct text_pos pos
;
4626 CHARPOS (pos
) = charpos
;
4627 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4628 reseat (it
, pos
, 1);
4629 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4630 it
->hpos
= it
->current_x
= 0;
4636 /* Go back -DVPOS visible lines and reseat the iterator there. */
4637 start_charpos
= IT_CHARPOS (*it
);
4638 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4639 back_to_previous_visible_line_start (it
);
4640 reseat (it
, it
->current
.pos
, 1);
4641 it
->current_x
= it
->hpos
= 0;
4643 /* Above call may have moved too far if continuation lines
4644 are involved. Scan forward and see if it did. */
4646 it2
.vpos
= it2
.current_y
= 0;
4647 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4648 it
->vpos
-= it2
.vpos
;
4649 it
->current_y
-= it2
.current_y
;
4650 it
->current_x
= it
->hpos
= 0;
4652 /* If we moved too far, move IT some lines forward. */
4653 if (it2
.vpos
> -dvpos
)
4655 int delta
= it2
.vpos
+ dvpos
;
4656 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4663 /***********************************************************************
4665 ***********************************************************************/
4668 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
4672 add_to_log (format
, arg1
, arg2
)
4674 Lisp_Object arg1
, arg2
;
4676 Lisp_Object args
[3];
4677 Lisp_Object msg
, fmt
;
4680 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4683 GCPRO4 (fmt
, msg
, arg1
, arg2
);
4685 args
[0] = fmt
= build_string (format
);
4688 msg
= Fformat (3, args
);
4690 len
= STRING_BYTES (XSTRING (msg
)) + 1;
4691 buffer
= (char *) alloca (len
);
4692 strcpy (buffer
, XSTRING (msg
)->data
);
4694 message_dolog (buffer
, len
, 1, 0);
4699 /* Output a newline in the *Messages* buffer if "needs" one. */
4702 message_log_maybe_newline ()
4704 if (message_log_need_newline
)
4705 message_dolog ("", 0, 1, 0);
4709 /* Add a string M of length LEN to the message log, optionally
4710 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4711 nonzero, means interpret the contents of M as multibyte. This
4712 function calls low-level routines in order to bypass text property
4713 hooks, etc. which might not be safe to run. */
4716 message_dolog (m
, len
, nlflag
, multibyte
)
4718 int len
, nlflag
, multibyte
;
4720 if (!NILP (Vmessage_log_max
))
4722 struct buffer
*oldbuf
;
4723 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4724 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4725 int point_at_end
= 0;
4727 Lisp_Object old_deactivate_mark
, tem
;
4728 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4730 old_deactivate_mark
= Vdeactivate_mark
;
4731 oldbuf
= current_buffer
;
4732 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4733 current_buffer
->undo_list
= Qt
;
4735 oldpoint
= Fpoint_marker ();
4736 oldbegv
= Fpoint_min_marker ();
4737 oldzv
= Fpoint_max_marker ();
4738 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4746 BEGV_BYTE
= BEG_BYTE
;
4749 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4751 /* Insert the string--maybe converting multibyte to single byte
4752 or vice versa, so that all the text fits the buffer. */
4754 && NILP (current_buffer
->enable_multibyte_characters
))
4757 unsigned char work
[1];
4759 /* Convert a multibyte string to single-byte
4760 for the *Message* buffer. */
4761 for (i
= 0; i
< len
; i
+= nbytes
)
4763 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4764 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4766 : multibyte_char_to_unibyte (c
, Qnil
));
4767 insert_1_both (work
, 1, 1, 1, 0, 0);
4770 else if (! multibyte
4771 && ! NILP (current_buffer
->enable_multibyte_characters
))
4774 unsigned char *msg
= (unsigned char *) m
;
4775 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4776 /* Convert a single-byte string to multibyte
4777 for the *Message* buffer. */
4778 for (i
= 0; i
< len
; i
++)
4780 c
= unibyte_char_to_multibyte (msg
[i
]);
4781 nbytes
= CHAR_STRING (c
, str
);
4782 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
4786 insert_1 (m
, len
, 1, 0, 0);
4790 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4791 insert_1 ("\n", 1, 1, 0, 0);
4793 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4795 this_bol_byte
= PT_BYTE
;
4799 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4801 prev_bol_byte
= PT_BYTE
;
4803 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4804 this_bol
, this_bol_byte
);
4807 del_range_both (prev_bol
, prev_bol_byte
,
4808 this_bol
, this_bol_byte
, 0);
4814 /* If you change this format, don't forget to also
4815 change message_log_check_duplicate. */
4816 sprintf (dupstr
, " [%d times]", dup
);
4817 duplen
= strlen (dupstr
);
4818 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4819 insert_1 (dupstr
, duplen
, 1, 0, 1);
4824 if (NATNUMP (Vmessage_log_max
))
4826 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4827 -XFASTINT (Vmessage_log_max
) - 1, 0);
4828 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4831 BEGV
= XMARKER (oldbegv
)->charpos
;
4832 BEGV_BYTE
= marker_byte_position (oldbegv
);
4841 ZV
= XMARKER (oldzv
)->charpos
;
4842 ZV_BYTE
= marker_byte_position (oldzv
);
4846 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4848 /* We can't do Fgoto_char (oldpoint) because it will run some
4850 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4851 XMARKER (oldpoint
)->bytepos
);
4854 free_marker (oldpoint
);
4855 free_marker (oldbegv
);
4856 free_marker (oldzv
);
4858 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4859 set_buffer_internal (oldbuf
);
4861 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4862 message_log_need_newline
= !nlflag
;
4863 Vdeactivate_mark
= old_deactivate_mark
;
4868 /* We are at the end of the buffer after just having inserted a newline.
4869 (Note: We depend on the fact we won't be crossing the gap.)
4870 Check to see if the most recent message looks a lot like the previous one.
4871 Return 0 if different, 1 if the new one should just replace it, or a
4872 value N > 1 if we should also append " [N times]". */
4875 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4876 int prev_bol
, this_bol
;
4877 int prev_bol_byte
, this_bol_byte
;
4880 int len
= Z_BYTE
- 1 - this_bol_byte
;
4882 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4883 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4885 for (i
= 0; i
< len
; i
++)
4887 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4896 if (*p1
++ == ' ' && *p1
++ == '[')
4899 while (*p1
>= '0' && *p1
<= '9')
4900 n
= n
* 10 + *p1
++ - '0';
4901 if (strncmp (p1
, " times]\n", 8) == 0)
4908 /* Display an echo area message M with a specified length of LEN
4909 chars. The string may include null characters. If M is 0, clear
4910 out any existing message, and let the mini-buffer text show through.
4912 The buffer M must continue to exist until after the echo area gets
4913 cleared or some other message gets displayed there. This means do
4914 not pass text that is stored in a Lisp string; do not pass text in
4915 a buffer that was alloca'd. */
4918 message2 (m
, len
, multibyte
)
4923 /* First flush out any partial line written with print. */
4924 message_log_maybe_newline ();
4926 message_dolog (m
, len
, 1, multibyte
);
4927 message2_nolog (m
, len
, multibyte
);
4931 /* The non-logging counterpart of message2. */
4934 message2_nolog (m
, len
, multibyte
)
4938 struct frame
*sf
= SELECTED_FRAME ();
4939 message_enable_multibyte
= multibyte
;
4943 if (noninteractive_need_newline
)
4944 putc ('\n', stderr
);
4945 noninteractive_need_newline
= 0;
4947 fwrite (m
, len
, 1, stderr
);
4948 if (cursor_in_echo_area
== 0)
4949 fprintf (stderr
, "\n");
4952 /* A null message buffer means that the frame hasn't really been
4953 initialized yet. Error messages get reported properly by
4954 cmd_error, so this must be just an informative message; toss it. */
4955 else if (INTERACTIVE
4956 && sf
->glyphs_initialized_p
4957 && FRAME_MESSAGE_BUF (sf
))
4959 Lisp_Object mini_window
;
4962 /* Get the frame containing the mini-buffer
4963 that the selected frame is using. */
4964 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
4965 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4967 FRAME_SAMPLE_VISIBILITY (f
);
4968 if (FRAME_VISIBLE_P (sf
)
4969 && ! FRAME_VISIBLE_P (f
))
4970 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4974 set_message (m
, Qnil
, len
, multibyte
);
4975 if (minibuffer_auto_raise
)
4976 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4979 clear_message (1, 1);
4981 do_pending_window_change (0);
4982 echo_area_display (1);
4983 do_pending_window_change (0);
4984 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4985 (*frame_up_to_date_hook
) (f
);
4990 /* Display an echo area message M with a specified length of NBYTES
4991 bytes. The string may include null characters. If M is not a
4992 string, clear out any existing message, and let the mini-buffer
4993 text show through. */
4996 message3 (m
, nbytes
, multibyte
)
5001 struct gcpro gcpro1
;
5005 /* First flush out any partial line written with print. */
5006 message_log_maybe_newline ();
5008 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5009 message3_nolog (m
, nbytes
, multibyte
);
5015 /* The non-logging version of message3. */
5018 message3_nolog (m
, nbytes
, multibyte
)
5020 int nbytes
, multibyte
;
5022 struct frame
*sf
= SELECTED_FRAME ();
5023 message_enable_multibyte
= multibyte
;
5027 if (noninteractive_need_newline
)
5028 putc ('\n', stderr
);
5029 noninteractive_need_newline
= 0;
5031 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5032 if (cursor_in_echo_area
== 0)
5033 fprintf (stderr
, "\n");
5036 /* A null message buffer means that the frame hasn't really been
5037 initialized yet. Error messages get reported properly by
5038 cmd_error, so this must be just an informative message; toss it. */
5039 else if (INTERACTIVE
5040 && sf
->glyphs_initialized_p
5041 && FRAME_MESSAGE_BUF (sf
))
5043 Lisp_Object mini_window
;
5047 /* Get the frame containing the mini-buffer
5048 that the selected frame is using. */
5049 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5050 frame
= XWINDOW (mini_window
)->frame
;
5053 FRAME_SAMPLE_VISIBILITY (f
);
5054 if (FRAME_VISIBLE_P (sf
)
5055 && !FRAME_VISIBLE_P (f
))
5056 Fmake_frame_visible (frame
);
5058 if (STRINGP (m
) && XSTRING (m
)->size
)
5060 set_message (NULL
, m
, nbytes
, multibyte
);
5061 if (minibuffer_auto_raise
)
5062 Fraise_frame (frame
);
5065 clear_message (1, 1);
5067 do_pending_window_change (0);
5068 echo_area_display (1);
5069 do_pending_window_change (0);
5070 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5071 (*frame_up_to_date_hook
) (f
);
5076 /* Display a null-terminated echo area message M. If M is 0, clear
5077 out any existing message, and let the mini-buffer text show through.
5079 The buffer M must continue to exist until after the echo area gets
5080 cleared or some other message gets displayed there. Do not pass
5081 text that is stored in a Lisp string. Do not pass text in a buffer
5082 that was alloca'd. */
5088 message2 (m
, (m
? strlen (m
) : 0), 0);
5092 /* The non-logging counterpart of message1. */
5098 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5101 /* Display a message M which contains a single %s
5102 which gets replaced with STRING. */
5105 message_with_string (m
, string
, log
)
5114 if (noninteractive_need_newline
)
5115 putc ('\n', stderr
);
5116 noninteractive_need_newline
= 0;
5117 fprintf (stderr
, m
, XSTRING (string
)->data
);
5118 if (cursor_in_echo_area
== 0)
5119 fprintf (stderr
, "\n");
5123 else if (INTERACTIVE
)
5125 /* The frame whose minibuffer we're going to display the message on.
5126 It may be larger than the selected frame, so we need
5127 to use its buffer, not the selected frame's buffer. */
5128 Lisp_Object mini_window
;
5129 struct frame
*f
, *sf
= SELECTED_FRAME ();
5131 /* Get the frame containing the minibuffer
5132 that the selected frame is using. */
5133 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5134 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5136 /* A null message buffer means that the frame hasn't really been
5137 initialized yet. Error messages get reported properly by
5138 cmd_error, so this must be just an informative message; toss it. */
5139 if (FRAME_MESSAGE_BUF (f
))
5143 a
[0] = (char *) XSTRING (string
)->data
;
5145 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5146 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5149 message2 (FRAME_MESSAGE_BUF (f
), len
,
5150 STRING_MULTIBYTE (string
));
5152 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5153 STRING_MULTIBYTE (string
));
5155 /* Print should start at the beginning of the message
5156 buffer next time. */
5157 message_buf_print
= 0;
5163 /* Dump an informative message to the minibuf. If M is 0, clear out
5164 any existing message, and let the mini-buffer text show through. */
5168 message (m
, a1
, a2
, a3
)
5170 EMACS_INT a1
, a2
, a3
;
5176 if (noninteractive_need_newline
)
5177 putc ('\n', stderr
);
5178 noninteractive_need_newline
= 0;
5179 fprintf (stderr
, m
, a1
, a2
, a3
);
5180 if (cursor_in_echo_area
== 0)
5181 fprintf (stderr
, "\n");
5185 else if (INTERACTIVE
)
5187 /* The frame whose mini-buffer we're going to display the message
5188 on. It may be larger than the selected frame, so we need to
5189 use its buffer, not the selected frame's buffer. */
5190 Lisp_Object mini_window
;
5191 struct frame
*f
, *sf
= SELECTED_FRAME ();
5193 /* Get the frame containing the mini-buffer
5194 that the selected frame is using. */
5195 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5196 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5198 /* A null message buffer means that the frame hasn't really been
5199 initialized yet. Error messages get reported properly by
5200 cmd_error, so this must be just an informative message; toss
5202 if (FRAME_MESSAGE_BUF (f
))
5213 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5214 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5216 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5217 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5219 #endif /* NO_ARG_ARRAY */
5221 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5226 /* Print should start at the beginning of the message
5227 buffer next time. */
5228 message_buf_print
= 0;
5234 /* The non-logging version of message. */
5237 message_nolog (m
, a1
, a2
, a3
)
5239 EMACS_INT a1
, a2
, a3
;
5241 Lisp_Object old_log_max
;
5242 old_log_max
= Vmessage_log_max
;
5243 Vmessage_log_max
= Qnil
;
5244 message (m
, a1
, a2
, a3
);
5245 Vmessage_log_max
= old_log_max
;
5249 /* Display the current message in the current mini-buffer. This is
5250 only called from error handlers in process.c, and is not time
5256 if (!NILP (echo_area_buffer
[0]))
5259 string
= Fcurrent_message ();
5260 message3 (string
, XSTRING (string
)->size
,
5261 !NILP (current_buffer
->enable_multibyte_characters
));
5266 /* Make sure echo area buffers in echo_buffers[] are life. If they
5267 aren't, make new ones. */
5270 ensure_echo_area_buffers ()
5274 for (i
= 0; i
< 2; ++i
)
5275 if (!BUFFERP (echo_buffer
[i
])
5276 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5279 sprintf (name
, " *Echo Area %d*", i
);
5280 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5285 /* Call FN with args A1..A5 with either the current or last displayed
5286 echo_area_buffer as current buffer.
5288 WHICH zero means use the current message buffer
5289 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5290 from echo_buffer[] and clear it.
5292 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5293 suitable buffer from echo_buffer[] and clear it.
5295 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5296 that the current message becomes the last displayed one, make
5297 choose a suitable buffer for echo_area_buffer[0], and clear it.
5299 Value is what FN returns. */
5302 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
)
5306 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
;
5309 int this_one
, the_other
, clear_buffer_p
, rc
;
5310 int count
= specpdl_ptr
- specpdl
;
5312 /* If buffers aren't life, make new ones. */
5313 ensure_echo_area_buffers ();
5318 this_one
= 0, the_other
= 1;
5320 this_one
= 1, the_other
= 0;
5323 this_one
= 0, the_other
= 1;
5326 /* We need a fresh one in case the current echo buffer equals
5327 the one containing the last displayed echo area message. */
5328 if (!NILP (echo_area_buffer
[this_one
])
5329 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5330 echo_area_buffer
[this_one
] = Qnil
;
5333 /* Choose a suitable buffer from echo_buffer[] is we don't
5335 if (NILP (echo_area_buffer
[this_one
]))
5337 echo_area_buffer
[this_one
]
5338 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5339 ? echo_buffer
[the_other
]
5340 : echo_buffer
[this_one
]);
5344 buffer
= echo_area_buffer
[this_one
];
5346 record_unwind_protect (unwind_with_echo_area_buffer
,
5347 with_echo_area_buffer_unwind_data (w
));
5349 /* Make the echo area buffer current. Note that for display
5350 purposes, it is not necessary that the displayed window's buffer
5351 == current_buffer, except for text property lookup. So, let's
5352 only set that buffer temporarily here without doing a full
5353 Fset_window_buffer. We must also change w->pointm, though,
5354 because otherwise an assertions in unshow_buffer fails, and Emacs
5356 set_buffer_internal_1 (XBUFFER (buffer
));
5360 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5362 current_buffer
->truncate_lines
= Qnil
;
5363 current_buffer
->undo_list
= Qt
;
5364 current_buffer
->read_only
= Qnil
;
5366 if (clear_buffer_p
&& Z
> BEG
)
5369 xassert (BEGV
>= BEG
);
5370 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5372 rc
= fn (a1
, a2
, a3
, a4
, a5
);
5374 xassert (BEGV
>= BEG
);
5375 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5377 unbind_to (count
, Qnil
);
5382 /* Save state that should be preserved around the call to the function
5383 FN called in with_echo_area_buffer. */
5386 with_echo_area_buffer_unwind_data (w
)
5392 /* Reduce consing by keeping one vector in
5393 Vwith_echo_area_save_vector. */
5394 vector
= Vwith_echo_area_save_vector
;
5395 Vwith_echo_area_save_vector
= Qnil
;
5398 vector
= Fmake_vector (make_number (7), Qnil
);
5400 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5401 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5402 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5406 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5407 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5408 XVECTOR (vector
)->contents
[i
++]
5409 = make_number (XMARKER (w
->pointm
)->charpos
);
5410 XVECTOR (vector
)->contents
[i
++]
5411 = make_number (XMARKER (w
->pointm
)->bytepos
);
5417 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5420 xassert (i
== XVECTOR (vector
)->size
);
5425 /* Restore global state from VECTOR which was created by
5426 with_echo_area_buffer_unwind_data. */
5429 unwind_with_echo_area_buffer (vector
)
5434 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5435 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5436 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5438 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5441 Lisp_Object buffer
, charpos
, bytepos
;
5443 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5444 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5445 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5446 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5449 set_marker_both (w
->pointm
, buffer
,
5450 XFASTINT (charpos
), XFASTINT (bytepos
));
5453 Vwith_echo_area_save_vector
= vector
;
5458 /* Set up the echo area for use by print functions. MULTIBYTE_P
5459 non-zero means we will print multibyte. */
5462 setup_echo_area_for_printing (multibyte_p
)
5465 ensure_echo_area_buffers ();
5467 if (!message_buf_print
)
5469 /* A message has been output since the last time we printed.
5470 Choose a fresh echo area buffer. */
5471 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5472 echo_area_buffer
[0] = echo_buffer
[1];
5474 echo_area_buffer
[0] = echo_buffer
[0];
5476 /* Switch to that buffer and clear it. */
5477 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5480 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5482 /* Set up the buffer for the multibyteness we need. */
5484 != !NILP (current_buffer
->enable_multibyte_characters
))
5485 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5487 /* Raise the frame containing the echo area. */
5488 if (minibuffer_auto_raise
)
5490 struct frame
*sf
= SELECTED_FRAME ();
5491 Lisp_Object mini_window
;
5492 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5493 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5496 message_buf_print
= 1;
5500 if (NILP (echo_area_buffer
[0]))
5502 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5503 echo_area_buffer
[0] = echo_buffer
[1];
5505 echo_area_buffer
[0] = echo_buffer
[0];
5508 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5509 /* Someone switched buffers between print requests. */
5510 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5515 /* Display an echo area message in window W. Value is non-zero if W's
5516 height is changed. If display_last_displayed_message_p is
5517 non-zero, display the message that was last displayed, otherwise
5518 display the current message. */
5521 display_echo_area (w
)
5524 int i
, no_message_p
, window_height_changed_p
, count
;
5526 /* Temporarily disable garbage collections while displaying the echo
5527 area. This is done because a GC can print a message itself.
5528 That message would modify the echo area buffer's contents while a
5529 redisplay of the buffer is going on, and seriously confuse
5531 count
= inhibit_garbage_collection ();
5533 /* If there is no message, we must call display_echo_area_1
5534 nevertheless because it resizes the window. But we will have to
5535 reset the echo_area_buffer in question to nil at the end because
5536 with_echo_area_buffer will sets it to an empty buffer. */
5537 i
= display_last_displayed_message_p
? 1 : 0;
5538 no_message_p
= NILP (echo_area_buffer
[i
]);
5540 window_height_changed_p
5541 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5542 (int (*) ()) display_echo_area_1
, w
);
5545 echo_area_buffer
[i
] = Qnil
;
5547 unbind_to (count
, Qnil
);
5548 return window_height_changed_p
;
5552 /* Helper for display_echo_area. Display the current buffer which
5553 contains the current echo area message in window W, a mini-window.
5554 Change the height of W so that all of the message is displayed.
5555 Value is non-zero if height of W was changed. */
5558 display_echo_area_1 (w
)
5562 struct text_pos start
;
5563 int window_height_changed_p
= 0;
5565 /* Do this before displaying, so that we have a large enough glyph
5566 matrix for the display. */
5567 window_height_changed_p
= resize_mini_window (w
, 0);
5570 clear_glyph_matrix (w
->desired_matrix
);
5571 XSETWINDOW (window
, w
);
5572 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5573 try_window (window
, start
);
5575 return window_height_changed_p
;
5579 /* Resize the echo area window to exactly the size needed for the
5580 currently displayed message, if there is one. */
5583 resize_echo_area_axactly ()
5585 if (BUFFERP (echo_area_buffer
[0])
5586 && WINDOWP (echo_area_window
))
5588 struct window
*w
= XWINDOW (echo_area_window
);
5591 resized_p
= with_echo_area_buffer (w
, 0,
5592 (int (*) ()) resize_mini_window
,
5596 ++windows_or_buffers_changed
;
5597 ++update_mode_lines
;
5598 redisplay_internal (0);
5604 /* Resize mini-window W to fit the size of its contents. EXACT:P
5605 means size the window exactly to the size needed. Otherwise, it's
5606 only enlarged until W's buffer is empty. Value is non-zero if
5607 the window height has been changed. */
5610 resize_mini_window (w
, exact_p
)
5614 struct frame
*f
= XFRAME (w
->frame
);
5615 int window_height_changed_p
= 0;
5617 xassert (MINI_WINDOW_P (w
));
5619 /* Nil means don't try to resize. */
5620 if (NILP (Vmax_mini_window_height
)
5621 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
5624 if (!FRAME_MINIBUF_ONLY_P (f
))
5627 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5628 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5629 int height
, max_height
;
5630 int unit
= CANON_Y_UNIT (f
);
5631 struct text_pos start
;
5633 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5635 /* Compute the max. number of lines specified by the user. */
5636 if (FLOATP (Vmax_mini_window_height
))
5637 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5638 else if (INTEGERP (Vmax_mini_window_height
))
5639 max_height
= XINT (Vmax_mini_window_height
);
5641 max_height
= total_height
/ 4;
5643 /* Correct that max. height if it's bogus. */
5644 max_height
= max (1, max_height
);
5645 max_height
= min (total_height
, max_height
);
5647 /* Find out the height of the text in the window. */
5649 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5650 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
5651 height
= it
.current_y
+ last_height
;
5653 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
5654 height
= (height
+ unit
- 1) / unit
;
5656 /* Compute a suitable window start. */
5657 if (height
> max_height
)
5659 height
= max_height
;
5660 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5661 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5662 start
= it
.current
.pos
;
5665 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5666 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5668 /* Let it grow only, until we display an empty message, in which
5669 case the window shrinks again. */
5670 if (height
> XFASTINT (w
->height
))
5672 int old_height
= XFASTINT (w
->height
);
5673 freeze_window_starts (f
, 1);
5674 grow_mini_window (w
, height
- XFASTINT (w
->height
));
5675 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5677 else if (height
< XFASTINT (w
->height
)
5678 && (exact_p
|| BEGV
== ZV
))
5680 int old_height
= XFASTINT (w
->height
);
5681 freeze_window_starts (f
, 0);
5682 shrink_mini_window (w
);
5683 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5687 return window_height_changed_p
;
5691 /* Value is the current message, a string, or nil if there is no
5699 if (NILP (echo_area_buffer
[0]))
5703 with_echo_area_buffer (0, 0, (int (*) ()) current_message_1
, &msg
);
5705 echo_area_buffer
[0] = Qnil
;
5713 current_message_1 (msg
)
5717 *msg
= make_buffer_string (BEG
, Z
, 1);
5724 /* Push the current message on Vmessage_stack for later restauration
5725 by restore_message. Value is non-zero if the current message isn't
5726 empty. This is a relatively infrequent operation, so it's not
5727 worth optimizing. */
5733 msg
= current_message ();
5734 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
5735 return STRINGP (msg
);
5739 /* Restore message display from the top of Vmessage_stack. */
5746 xassert (CONSP (Vmessage_stack
));
5747 msg
= XCAR (Vmessage_stack
);
5749 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
5751 message3_nolog (msg
, 0, 0);
5755 /* Pop the top-most entry off Vmessage_stack. */
5760 xassert (CONSP (Vmessage_stack
));
5761 Vmessage_stack
= XCDR (Vmessage_stack
);
5765 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
5766 exits. If the stack is not empty, we have a missing pop_message
5770 check_message_stack ()
5772 if (!NILP (Vmessage_stack
))
5777 /* Truncate to NCHARS what will be displayed in the echo area the next
5778 time we display it---but don't redisplay it now. */
5781 truncate_echo_area (nchars
)
5785 echo_area_buffer
[0] = Qnil
;
5786 /* A null message buffer means that the frame hasn't really been
5787 initialized yet. Error messages get reported properly by
5788 cmd_error, so this must be just an informative message; toss it. */
5789 else if (!noninteractive
5791 && !NILP (echo_area_buffer
[0]))
5793 struct frame
*sf
= SELECTED_FRAME ();
5794 if (FRAME_MESSAGE_BUF (sf
))
5795 with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1
, nchars
);
5800 /* Helper function for truncate_echo_area. Truncate the current
5801 message to at most NCHARS characters. */
5804 truncate_message_1 (nchars
)
5807 if (BEG
+ nchars
< Z
)
5808 del_range (BEG
+ nchars
, Z
);
5810 echo_area_buffer
[0] = Qnil
;
5815 /* Set the current message to a substring of S or STRING.
5817 If STRING is a Lisp string, set the message to the first NBYTES
5818 bytes from STRING. NBYTES zero means use the whole string. If
5819 STRING is multibyte, the message will be displayed multibyte.
5821 If S is not null, set the message to the first LEN bytes of S. LEN
5822 zero means use the whole string. MULTIBYTE_P non-zero means S is
5823 multibyte. Display the message multibyte in that case. */
5826 set_message (s
, string
, nbytes
, multibyte_p
)
5831 message_enable_multibyte
5832 = ((s
&& multibyte_p
)
5833 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
5835 with_echo_area_buffer (0, -1, (int (*) ()) set_message_1
,
5836 s
, string
, nbytes
, multibyte_p
);
5837 message_buf_print
= 0;
5841 /* Helper function for set_message. Arguments have the same meaning
5842 as there. This function is called with the echo area buffer being
5846 set_message_1 (s
, string
, nbytes
, multibyte_p
)
5849 int nbytes
, multibyte_p
;
5853 /* Change multibyteness of the echo buffer appropriately. */
5854 if (message_enable_multibyte
5855 != !NILP (current_buffer
->enable_multibyte_characters
))
5856 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
5858 /* Insert new message at BEG. */
5859 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5861 if (STRINGP (string
))
5866 nbytes
= XSTRING (string
)->size_byte
;
5867 nchars
= string_byte_to_char (string
, nbytes
);
5869 /* This function takes care of single/multibyte conversion. We
5870 just have to ensure that the echo area buffer has the right
5871 setting of enable_multibyte_characters. */
5872 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
5877 nbytes
= strlen (s
);
5879 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
5881 /* Convert from multi-byte to single-byte. */
5883 unsigned char work
[1];
5885 /* Convert a multibyte string to single-byte. */
5886 for (i
= 0; i
< nbytes
; i
+= n
)
5888 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
5889 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5891 : multibyte_char_to_unibyte (c
, Qnil
));
5892 insert_1_both (work
, 1, 1, 1, 0, 0);
5895 else if (!multibyte_p
5896 && !NILP (current_buffer
->enable_multibyte_characters
))
5898 /* Convert from single-byte to multi-byte. */
5900 unsigned char *msg
= (unsigned char *) s
;
5901 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5903 /* Convert a single-byte string to multibyte. */
5904 for (i
= 0; i
< nbytes
; i
++)
5906 c
= unibyte_char_to_multibyte (msg
[i
]);
5907 n
= CHAR_STRING (c
, str
);
5908 insert_1_both (str
, 1, n
, 1, 0, 0);
5912 insert_1 (s
, nbytes
, 1, 0, 0);
5919 /* Clear messages. CURRENT_P non-zero means clear the current
5920 message. LAST_DISPLAYED_P non-zero means clear the message
5924 clear_message (current_p
, last_displayed_p
)
5925 int current_p
, last_displayed_p
;
5928 echo_area_buffer
[0] = Qnil
;
5930 if (last_displayed_p
)
5931 echo_area_buffer
[1] = Qnil
;
5933 message_buf_print
= 0;
5936 /* Clear garbaged frames.
5938 This function is used where the old redisplay called
5939 redraw_garbaged_frames which in turn called redraw_frame which in
5940 turn called clear_frame. The call to clear_frame was a source of
5941 flickering. I believe a clear_frame is not necessary. It should
5942 suffice in the new redisplay to invalidate all current matrices,
5943 and ensure a complete redisplay of all windows. */
5946 clear_garbaged_frames ()
5950 Lisp_Object tail
, frame
;
5952 FOR_EACH_FRAME (tail
, frame
)
5954 struct frame
*f
= XFRAME (frame
);
5956 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5958 clear_current_matrices (f
);
5964 ++windows_or_buffers_changed
;
5969 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
5970 is non-zero update selected_frame. Value is non-zero if the
5971 mini-windows height has been changed. */
5974 echo_area_display (update_frame_p
)
5977 Lisp_Object mini_window
;
5980 int window_height_changed_p
= 0;
5981 struct frame
*sf
= SELECTED_FRAME ();
5983 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5984 w
= XWINDOW (mini_window
);
5985 f
= XFRAME (WINDOW_FRAME (w
));
5987 /* Don't display if frame is invisible or not yet initialized. */
5988 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
5991 #ifdef HAVE_WINDOW_SYSTEM
5992 /* When Emacs starts, selected_frame may be a visible terminal
5993 frame, even if we run under a window system. If we let this
5994 through, a message would be displayed on the terminal. */
5995 if (EQ (selected_frame
, Vterminal_frame
)
5996 && !NILP (Vwindow_system
))
5998 #endif /* HAVE_WINDOW_SYSTEM */
6000 /* Redraw garbaged frames. */
6002 clear_garbaged_frames ();
6004 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6006 echo_area_window
= mini_window
;
6007 window_height_changed_p
= display_echo_area (w
);
6008 w
->must_be_updated_p
= 1;
6012 /* Not called from redisplay_internal. If we changed
6013 window configuration, we must redisplay thoroughly.
6014 Otherwise, we can do with updating what we displayed
6016 if (window_height_changed_p
)
6018 ++windows_or_buffers_changed
;
6019 ++update_mode_lines
;
6020 redisplay_internal (0);
6022 else if (FRAME_WINDOW_P (f
))
6024 update_single_window (w
, 1);
6025 rif
->flush_display (f
);
6028 update_frame (f
, 1, 1);
6031 else if (!EQ (mini_window
, selected_window
))
6032 windows_or_buffers_changed
++;
6034 /* Last displayed message is now the current message. */
6035 echo_area_buffer
[1] = echo_area_buffer
[0];
6037 /* Prevent redisplay optimization in redisplay_internal by resetting
6038 this_line_start_pos. This is done because the mini-buffer now
6039 displays the message instead of its buffer text. */
6040 if (EQ (mini_window
, selected_window
))
6041 CHARPOS (this_line_start_pos
) = 0;
6043 return window_height_changed_p
;
6048 /***********************************************************************
6050 ***********************************************************************/
6053 #ifdef HAVE_WINDOW_SYSTEM
6055 /* A buffer for constructing frame titles in it; allocated from the
6056 heap in init_xdisp and resized as needed in store_frame_title_char. */
6058 static char *frame_title_buf
;
6060 /* The buffer's end, and a current output position in it. */
6062 static char *frame_title_buf_end
;
6063 static char *frame_title_ptr
;
6066 /* Store a single character C for the frame title in frame_title_buf.
6067 Re-allocate frame_title_buf if necessary. */
6070 store_frame_title_char (c
)
6073 /* If output position has reached the end of the allocated buffer,
6074 double the buffer's size. */
6075 if (frame_title_ptr
== frame_title_buf_end
)
6077 int len
= frame_title_ptr
- frame_title_buf
;
6078 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6079 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6080 frame_title_buf_end
= frame_title_buf
+ new_size
;
6081 frame_title_ptr
= frame_title_buf
+ len
;
6084 *frame_title_ptr
++ = c
;
6088 /* Store part of a frame title in frame_title_buf, beginning at
6089 frame_title_ptr. STR is the string to store. Do not copy more
6090 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6091 the whole string. Pad with spaces until FIELD_WIDTH number of
6092 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6093 Called from display_mode_element when it is used to build a frame
6097 store_frame_title (str
, field_width
, precision
)
6099 int field_width
, precision
;
6103 /* Copy at most PRECISION chars from STR. */
6104 while ((precision
<= 0 || n
< precision
)
6107 store_frame_title_char (*str
++);
6111 /* Fill up with spaces until FIELD_WIDTH reached. */
6112 while (field_width
> 0
6115 store_frame_title_char (' ');
6123 /* Set the title of FRAME, if it has changed. The title format is
6124 Vicon_title_format if FRAME is iconified, otherwise it is
6125 frame_title_format. */
6128 x_consider_frame_title (frame
)
6131 struct frame
*f
= XFRAME (frame
);
6133 if (FRAME_WINDOW_P (f
)
6134 || FRAME_MINIBUF_ONLY_P (f
)
6135 || f
->explicit_name
)
6137 /* Do we have more than one visible frame on this X display? */
6140 struct buffer
*obuf
;
6144 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6146 struct frame
*tf
= XFRAME (XCAR (tail
));
6149 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6150 && !FRAME_MINIBUF_ONLY_P (tf
)
6151 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6155 /* Set global variable indicating that multiple frames exist. */
6156 multiple_frames
= CONSP (tail
);
6158 /* Switch to the buffer of selected window of the frame. Set up
6159 frame_title_ptr so that display_mode_element will output into it;
6160 then display the title. */
6161 obuf
= current_buffer
;
6162 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6163 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6164 frame_title_ptr
= frame_title_buf
;
6165 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6166 NULL
, DEFAULT_FACE_ID
);
6167 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6168 frame_title_ptr
= NULL
;
6169 set_buffer_internal (obuf
);
6171 /* Set the title only if it's changed. This avoids consing in
6172 the common case where it hasn't. (If it turns out that we've
6173 already wasted too much time by walking through the list with
6174 display_mode_element, then we might need to optimize at a
6175 higher level than this.) */
6176 if (! STRINGP (f
->name
)
6177 || STRING_BYTES (XSTRING (f
->name
)) != len
6178 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6179 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6183 #else /* not HAVE_WINDOW_SYSTEM */
6185 #define frame_title_ptr ((char *)0)
6186 #define store_frame_title(str, mincol, maxcol) 0
6188 #endif /* not HAVE_WINDOW_SYSTEM */
6193 /***********************************************************************
6195 ***********************************************************************/
6198 /* Prepare for redisplay by updating menu-bar item lists when
6199 appropriate. This can call eval. */
6202 prepare_menu_bars ()
6205 struct gcpro gcpro1
, gcpro2
;
6207 struct frame
*tooltip_frame
;
6209 #ifdef HAVE_X_WINDOWS
6210 tooltip_frame
= tip_frame
;
6212 tooltip_frame
= NULL
;
6215 /* Update all frame titles based on their buffer names, etc. We do
6216 this before the menu bars so that the buffer-menu will show the
6217 up-to-date frame titles. */
6218 #ifdef HAVE_WINDOW_SYSTEM
6219 if (windows_or_buffers_changed
|| update_mode_lines
)
6221 Lisp_Object tail
, frame
;
6223 FOR_EACH_FRAME (tail
, frame
)
6226 if (f
!= tooltip_frame
6227 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6228 x_consider_frame_title (frame
);
6231 #endif /* HAVE_WINDOW_SYSTEM */
6233 /* Update the menu bar item lists, if appropriate. This has to be
6234 done before any actual redisplay or generation of display lines. */
6235 all_windows
= (update_mode_lines
6236 || buffer_shared
> 1
6237 || windows_or_buffers_changed
);
6240 Lisp_Object tail
, frame
;
6241 int count
= specpdl_ptr
- specpdl
;
6243 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6245 FOR_EACH_FRAME (tail
, frame
)
6249 /* Ignore tooltip frame. */
6250 if (f
== tooltip_frame
)
6253 /* If a window on this frame changed size, report that to
6254 the user and clear the size-change flag. */
6255 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6257 Lisp_Object functions
;
6259 /* Clear flag first in case we get an error below. */
6260 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6261 functions
= Vwindow_size_change_functions
;
6262 GCPRO2 (tail
, functions
);
6264 while (CONSP (functions
))
6266 call1 (XCAR (functions
), frame
);
6267 functions
= XCDR (functions
);
6273 update_menu_bar (f
, 0);
6274 #ifdef HAVE_WINDOW_SYSTEM
6275 update_tool_bar (f
, 0);
6280 unbind_to (count
, Qnil
);
6284 struct frame
*sf
= SELECTED_FRAME ();
6285 update_menu_bar (sf
, 1);
6286 #ifdef HAVE_WINDOW_SYSTEM
6287 update_tool_bar (sf
, 1);
6291 /* Motif needs this. See comment in xmenu.c. Turn it off when
6292 pending_menu_activation is not defined. */
6293 #ifdef USE_X_TOOLKIT
6294 pending_menu_activation
= 0;
6299 /* Update the menu bar item list for frame F. This has to be done
6300 before we start to fill in any display lines, because it can call
6303 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6306 update_menu_bar (f
, save_match_data
)
6308 int save_match_data
;
6311 register struct window
*w
;
6313 window
= FRAME_SELECTED_WINDOW (f
);
6314 w
= XWINDOW (window
);
6316 if (update_mode_lines
)
6317 w
->update_mode_line
= Qt
;
6319 if (FRAME_WINDOW_P (f
)
6321 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6322 FRAME_EXTERNAL_MENU_BAR (f
)
6324 FRAME_MENU_BAR_LINES (f
) > 0
6326 : FRAME_MENU_BAR_LINES (f
) > 0)
6328 /* If the user has switched buffers or windows, we need to
6329 recompute to reflect the new bindings. But we'll
6330 recompute when update_mode_lines is set too; that means
6331 that people can use force-mode-line-update to request
6332 that the menu bar be recomputed. The adverse effect on
6333 the rest of the redisplay algorithm is about the same as
6334 windows_or_buffers_changed anyway. */
6335 if (windows_or_buffers_changed
6336 || !NILP (w
->update_mode_line
)
6337 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6338 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6339 != !NILP (w
->last_had_star
))
6340 || ((!NILP (Vtransient_mark_mode
)
6341 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6342 != !NILP (w
->region_showing
)))
6344 struct buffer
*prev
= current_buffer
;
6345 int count
= specpdl_ptr
- specpdl
;
6347 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6348 if (save_match_data
)
6349 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6350 if (NILP (Voverriding_local_map_menu_flag
))
6352 specbind (Qoverriding_terminal_local_map
, Qnil
);
6353 specbind (Qoverriding_local_map
, Qnil
);
6356 /* Run the Lucid hook. */
6357 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6359 /* If it has changed current-menubar from previous value,
6360 really recompute the menu-bar from the value. */
6361 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6362 call0 (Qrecompute_lucid_menubar
);
6364 safe_run_hooks (Qmenu_bar_update_hook
);
6365 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6367 /* Redisplay the menu bar in case we changed it. */
6368 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6369 if (FRAME_WINDOW_P (f
))
6370 set_frame_menubar (f
, 0, 0);
6372 /* On a terminal screen, the menu bar is an ordinary screen
6373 line, and this makes it get updated. */
6374 w
->update_mode_line
= Qt
;
6375 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6376 /* In the non-toolkit version, the menu bar is an ordinary screen
6377 line, and this makes it get updated. */
6378 w
->update_mode_line
= Qt
;
6379 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6381 unbind_to (count
, Qnil
);
6382 set_buffer_internal_1 (prev
);
6389 /***********************************************************************
6391 ***********************************************************************/
6393 #ifdef HAVE_WINDOW_SYSTEM
6395 /* Update the tool-bar item list for frame F. This has to be done
6396 before we start to fill in any display lines. Called from
6397 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6398 and restore it here. */
6401 update_tool_bar (f
, save_match_data
)
6403 int save_match_data
;
6405 if (WINDOWP (f
->tool_bar_window
)
6406 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6411 window
= FRAME_SELECTED_WINDOW (f
);
6412 w
= XWINDOW (window
);
6414 /* If the user has switched buffers or windows, we need to
6415 recompute to reflect the new bindings. But we'll
6416 recompute when update_mode_lines is set too; that means
6417 that people can use force-mode-line-update to request
6418 that the menu bar be recomputed. The adverse effect on
6419 the rest of the redisplay algorithm is about the same as
6420 windows_or_buffers_changed anyway. */
6421 if (windows_or_buffers_changed
6422 || !NILP (w
->update_mode_line
)
6423 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6424 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6425 != !NILP (w
->last_had_star
))
6426 || ((!NILP (Vtransient_mark_mode
)
6427 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6428 != !NILP (w
->region_showing
)))
6430 struct buffer
*prev
= current_buffer
;
6431 int count
= specpdl_ptr
- specpdl
;
6433 /* Set current_buffer to the buffer of the selected
6434 window of the frame, so that we get the right local
6436 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6438 /* Save match data, if we must. */
6439 if (save_match_data
)
6440 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6442 /* Make sure that we don't accidentally use bogus keymaps. */
6443 if (NILP (Voverriding_local_map_menu_flag
))
6445 specbind (Qoverriding_terminal_local_map
, Qnil
);
6446 specbind (Qoverriding_local_map
, Qnil
);
6449 /* Build desired tool-bar items from keymaps. */
6450 f
->desired_tool_bar_items
6451 = tool_bar_items (f
->desired_tool_bar_items
,
6452 &f
->n_desired_tool_bar_items
);
6454 /* Redisplay the tool-bar in case we changed it. */
6455 w
->update_mode_line
= Qt
;
6457 unbind_to (count
, Qnil
);
6458 set_buffer_internal_1 (prev
);
6464 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6465 F's desired tool-bar contents. F->desired_tool_bar_items must have
6466 been set up previously by calling prepare_menu_bars. */
6469 build_desired_tool_bar_string (f
)
6472 int i
, size
, size_needed
, string_idx
;
6473 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6474 Lisp_Object image
, plist
, props
;
6476 image
= plist
= props
= Qnil
;
6477 GCPRO3 (image
, plist
, props
);
6479 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6480 Otherwise, make a new string. */
6482 /* The size of the string we might be able to reuse. */
6483 size
= (STRINGP (f
->desired_tool_bar_string
)
6484 ? XSTRING (f
->desired_tool_bar_string
)->size
6487 /* Each image in the string we build is preceded by a space,
6488 and there is a space at the end. */
6489 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6491 /* Reuse f->desired_tool_bar_string, if possible. */
6492 if (size
< size_needed
)
6493 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6497 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6498 Fremove_text_properties (make_number (0), make_number (size
),
6499 props
, f
->desired_tool_bar_string
);
6502 /* Put a `display' property on the string for the images to display,
6503 put a `menu_item' property on tool-bar items with a value that
6504 is the index of the item in F's tool-bar item vector. */
6505 for (i
= 0, string_idx
= 0;
6506 i
< f
->n_desired_tool_bar_items
;
6507 ++i
, string_idx
+= 1)
6510 (XVECTOR (f->desired_tool_bar_items) \
6511 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6513 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6514 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6516 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6517 extern Lisp_Object Qlaplace
;
6519 /* If image is a vector, choose the image according to the
6521 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6522 if (VECTORP (image
))
6524 enum tool_bar_item_image idx
;
6528 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6529 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6532 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6533 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6535 xassert (XVECTOR (image
)->size
>= idx
);
6536 image
= XVECTOR (image
)->contents
[idx
];
6539 /* Ignore invalid image specifications. */
6540 if (!valid_image_p (image
))
6543 /* Display the tool-bar button pressed, or depressed. */
6544 plist
= Fcopy_sequence (XCDR (image
));
6546 /* Compute margin and relief to draw. */
6547 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6548 margin
= relief
+ max (0, tool_bar_button_margin
);
6550 if (auto_raise_tool_bar_buttons_p
)
6552 /* Add a `:relief' property to the image spec if the item is
6556 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6562 /* If image is selected, display it pressed, i.e. with a
6563 negative relief. If it's not selected, display it with a
6565 plist
= Fplist_put (plist
, QCrelief
,
6567 ? make_number (-relief
)
6568 : make_number (relief
)));
6572 /* Put a margin around the image. */
6574 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6576 /* If button is not enabled, make the image appear disabled by
6577 applying an appropriate algorithm to it. */
6579 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6581 /* Put a `display' text property on the string for the image to
6582 display. Put a `menu-item' property on the string that gives
6583 the start of this item's properties in the tool-bar items
6585 image
= Fcons (Qimage
, plist
);
6586 props
= list4 (Qdisplay
, image
,
6587 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
6588 Fadd_text_properties (make_number (string_idx
),
6589 make_number (string_idx
+ 1),
6590 props
, f
->desired_tool_bar_string
);
6598 /* Display one line of the tool-bar of frame IT->f. */
6601 display_tool_bar_line (it
)
6604 struct glyph_row
*row
= it
->glyph_row
;
6605 int max_x
= it
->last_visible_x
;
6608 prepare_desired_row (row
);
6609 row
->y
= it
->current_y
;
6611 while (it
->current_x
< max_x
)
6613 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6615 /* Get the next display element. */
6616 if (!get_next_display_element (it
))
6619 /* Produce glyphs. */
6620 x_before
= it
->current_x
;
6621 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6622 PRODUCE_GLYPHS (it
);
6624 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6629 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6631 if (x
+ glyph
->pixel_width
> max_x
)
6633 /* Glyph doesn't fit on line. */
6634 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6640 x
+= glyph
->pixel_width
;
6644 /* Stop at line ends. */
6645 if (ITERATOR_AT_END_OF_LINE_P (it
))
6648 set_iterator_to_next (it
);
6653 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6654 extend_face_to_end_of_line (it
);
6655 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6656 last
->right_box_line_p
= 1;
6657 compute_line_metrics (it
);
6659 /* If line is empty, make it occupy the rest of the tool-bar. */
6660 if (!row
->displays_text_p
)
6662 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6663 row
->ascent
= row
->phys_ascent
= 0;
6666 row
->full_width_p
= 1;
6667 row
->continued_p
= 0;
6668 row
->truncated_on_left_p
= 0;
6669 row
->truncated_on_right_p
= 0;
6671 it
->current_x
= it
->hpos
= 0;
6672 it
->current_y
+= row
->height
;
6678 /* Value is the number of screen lines needed to make all tool-bar
6679 items of frame F visible. */
6682 tool_bar_lines_needed (f
)
6685 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6688 /* Initialize an iterator for iteration over
6689 F->desired_tool_bar_string in the tool-bar window of frame F. */
6690 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6691 it
.first_visible_x
= 0;
6692 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6693 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6695 while (!ITERATOR_AT_END_P (&it
))
6697 it
.glyph_row
= w
->desired_matrix
->rows
;
6698 clear_glyph_row (it
.glyph_row
);
6699 display_tool_bar_line (&it
);
6702 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
6706 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
6707 height should be changed. */
6710 redisplay_tool_bar (f
)
6715 struct glyph_row
*row
;
6716 int change_height_p
= 0;
6718 /* If frame hasn't a tool-bar window or if it is zero-height, don't
6719 do anything. This means you must start with tool-bar-lines
6720 non-zero to get the auto-sizing effect. Or in other words, you
6721 can turn off tool-bars by specifying tool-bar-lines zero. */
6722 if (!WINDOWP (f
->tool_bar_window
)
6723 || (w
= XWINDOW (f
->tool_bar_window
),
6724 XFASTINT (w
->height
) == 0))
6727 /* Set up an iterator for the tool-bar window. */
6728 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6729 it
.first_visible_x
= 0;
6730 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6733 /* Build a string that represents the contents of the tool-bar. */
6734 build_desired_tool_bar_string (f
);
6735 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6737 /* Display as many lines as needed to display all tool-bar items. */
6738 while (it
.current_y
< it
.last_visible_y
)
6739 display_tool_bar_line (&it
);
6741 /* It doesn't make much sense to try scrolling in the tool-bar
6742 window, so don't do it. */
6743 w
->desired_matrix
->no_scrolling_p
= 1;
6744 w
->must_be_updated_p
= 1;
6746 if (auto_resize_tool_bars_p
)
6750 /* If there are blank lines at the end, except for a partially
6751 visible blank line at the end that is smaller than
6752 CANON_Y_UNIT, change the tool-bar's height. */
6753 row
= it
.glyph_row
- 1;
6754 if (!row
->displays_text_p
6755 && row
->height
>= CANON_Y_UNIT (f
))
6756 change_height_p
= 1;
6758 /* If row displays tool-bar items, but is partially visible,
6759 change the tool-bar's height. */
6760 if (row
->displays_text_p
6761 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6762 change_height_p
= 1;
6764 /* Resize windows as needed by changing the `tool-bar-lines'
6767 && (nlines
= tool_bar_lines_needed (f
),
6768 nlines
!= XFASTINT (w
->height
)))
6770 extern Lisp_Object Qtool_bar_lines
;
6773 XSETFRAME (frame
, f
);
6774 clear_glyph_matrix (w
->desired_matrix
);
6775 Fmodify_frame_parameters (frame
,
6776 Fcons (Fcons (Qtool_bar_lines
,
6777 make_number (nlines
)),
6779 fonts_changed_p
= 1;
6783 return change_height_p
;
6787 /* Get information about the tool-bar item which is displayed in GLYPH
6788 on frame F. Return in *PROP_IDX the index where tool-bar item
6789 properties start in F->current_tool_bar_items. Value is zero if
6790 GLYPH doesn't display a tool-bar item. */
6793 tool_bar_item_info (f
, glyph
, prop_idx
)
6795 struct glyph
*glyph
;
6801 /* Get the text property `menu-item' at pos. The value of that
6802 property is the start index of this item's properties in
6803 F->current_tool_bar_items. */
6804 prop
= Fget_text_property (make_number (glyph
->charpos
),
6805 Qmenu_item
, f
->current_tool_bar_string
);
6806 if (INTEGERP (prop
))
6808 *prop_idx
= XINT (prop
);
6817 #endif /* HAVE_WINDOW_SYSTEM */
6821 /************************************************************************
6822 Horizontal scrolling
6823 ************************************************************************/
6825 static int hscroll_window_tree
P_ ((Lisp_Object
));
6826 static int hscroll_windows
P_ ((Lisp_Object
));
6828 /* For all leaf windows in the window tree rooted at WINDOW, set their
6829 hscroll value so that PT is (i) visible in the window, and (ii) so
6830 that it is not within a certain margin at the window's left and
6831 right border. Value is non-zero if any window's hscroll has been
6835 hscroll_window_tree (window
)
6838 int hscrolled_p
= 0;
6840 while (WINDOWP (window
))
6842 struct window
*w
= XWINDOW (window
);
6844 if (WINDOWP (w
->hchild
))
6845 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6846 else if (WINDOWP (w
->vchild
))
6847 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6848 else if (w
->cursor
.vpos
>= 0)
6850 int hscroll_margin
, text_area_x
, text_area_y
;
6851 int text_area_width
, text_area_height
;
6852 struct glyph_row
*current_cursor_row
6853 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
6854 struct glyph_row
*desired_cursor_row
6855 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
6856 struct glyph_row
*cursor_row
6857 = (desired_cursor_row
->enabled_p
6858 ? desired_cursor_row
6859 : current_cursor_row
);
6861 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6862 &text_area_width
, &text_area_height
);
6864 /* Scroll when cursor is inside this scroll margin. */
6865 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6867 if ((XFASTINT (w
->hscroll
)
6868 && w
->cursor
.x
< hscroll_margin
)
6869 || (cursor_row
->enabled_p
6870 && cursor_row
->truncated_on_right_p
6871 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6875 struct buffer
*saved_current_buffer
;
6878 /* Find point in a display of infinite width. */
6879 saved_current_buffer
= current_buffer
;
6880 current_buffer
= XBUFFER (w
->buffer
);
6882 if (w
== XWINDOW (selected_window
))
6883 pt
= BUF_PT (current_buffer
);
6886 pt
= marker_position (w
->pointm
);
6887 pt
= max (BEGV
, pt
);
6891 /* Move iterator to pt starting at cursor_row->start in
6892 a line with infinite width. */
6893 init_to_row_start (&it
, w
, cursor_row
);
6894 it
.last_visible_x
= INFINITY
;
6895 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6896 current_buffer
= saved_current_buffer
;
6898 /* Center cursor in window. */
6899 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6900 / CANON_X_UNIT (it
.f
));
6902 /* Don't call Fset_window_hscroll if value hasn't
6903 changed because it will prevent redisplay
6905 if (XFASTINT (w
->hscroll
) != hscroll
)
6907 Fset_window_hscroll (window
, make_number (hscroll
));
6916 /* Value is non-zero if hscroll of any leaf window has been changed. */
6921 /* Set hscroll so that cursor is visible and not inside horizontal
6922 scroll margins for all windows in the tree rooted at WINDOW. See
6923 also hscroll_window_tree above. Value is non-zero if any window's
6924 hscroll has been changed. If it has, desired matrices on the frame
6925 of WINDOW are cleared. */
6928 hscroll_windows (window
)
6933 if (automatic_hscrolling_p
)
6935 hscrolled_p
= hscroll_window_tree (window
);
6937 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6946 /************************************************************************
6948 ************************************************************************/
6950 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6951 to a non-zero value. This is sometimes handy to have in a debugger
6956 /* First and last unchanged row for try_window_id. */
6958 int debug_first_unchanged_at_end_vpos
;
6959 int debug_last_unchanged_at_beg_vpos
;
6961 /* Delta vpos and y. */
6963 int debug_dvpos
, debug_dy
;
6965 /* Delta in characters and bytes for try_window_id. */
6967 int debug_delta
, debug_delta_bytes
;
6969 /* Values of window_end_pos and window_end_vpos at the end of
6972 int debug_end_pos
, debug_end_vpos
;
6974 /* Append a string to W->desired_matrix->method. FMT is a printf
6975 format string. A1...A9 are a supplement for a variable-length
6976 argument list. If trace_redisplay_p is non-zero also printf the
6977 resulting string to stderr. */
6980 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
6983 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
6986 char *method
= w
->desired_matrix
->method
;
6987 int len
= strlen (method
);
6988 int size
= sizeof w
->desired_matrix
->method
;
6989 int remaining
= size
- len
- 1;
6991 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
6992 if (len
&& remaining
)
6998 strncpy (method
+ len
, buffer
, remaining
);
7000 if (trace_redisplay_p
)
7001 fprintf (stderr
, "%p (%s): %s\n",
7003 ((BUFFERP (w
->buffer
)
7004 && STRINGP (XBUFFER (w
->buffer
)->name
))
7005 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7010 #endif /* GLYPH_DEBUG */
7013 /* This counter is used to clear the face cache every once in a while
7014 in redisplay_internal. It is incremented for each redisplay.
7015 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7018 #define CLEAR_FACE_CACHE_COUNT 10000
7019 static int clear_face_cache_count
;
7021 /* Record the previous terminal frame we displayed. */
7023 static struct frame
*previous_terminal_frame
;
7025 /* Non-zero while redisplay_internal is in progress. */
7030 /* Value is non-zero if all changes in window W, which displays
7031 current_buffer, are in the text between START and END. START is a
7032 buffer position, END is given as a distance from Z. Used in
7033 redisplay_internal for display optimization. */
7036 text_outside_line_unchanged_p (w
, start
, end
)
7040 int unchanged_p
= 1;
7042 /* If text or overlays have changed, see where. */
7043 if (XFASTINT (w
->last_modified
) < MODIFF
7044 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7046 /* Gap in the line? */
7047 if (GPT
< start
|| Z
- GPT
< end
)
7050 /* Changes start in front of the line, or end after it? */
7052 && (BEG_UNCHANGED
< start
- 1
7053 || END_UNCHANGED
< end
))
7056 /* If selective display, can't optimize if changes start at the
7057 beginning of the line. */
7059 && INTEGERP (current_buffer
->selective_display
)
7060 && XINT (current_buffer
->selective_display
) > 0
7061 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7069 /* Do a frame update, taking possible shortcuts into account. This is
7070 the main external entry point for redisplay.
7072 If the last redisplay displayed an echo area message and that message
7073 is no longer requested, we clear the echo area or bring back the
7074 mini-buffer if that is in use. */
7079 redisplay_internal (0);
7082 /* Return 1 if point moved out of or into a composition. Otherwise
7083 return 0. PREV_BUF and PREV_PT are the last point buffer and
7084 position. BUF and PT are the current point buffer and position. */
7087 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7088 struct buffer
*prev_buf
, *buf
;
7095 XSETBUFFER (buffer
, buf
);
7096 /* Check a composition at the last point if point moved within the
7098 if (prev_buf
== buf
)
7101 /* Point didn't move. */
7104 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7105 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7106 && COMPOSITION_VALID_P (start
, end
, prop
)
7107 && start
< prev_pt
&& end
> prev_pt
)
7108 /* The last point was within the composition. Return 1 iff
7109 point moved out of the composition. */
7110 return (pt
<= start
|| pt
>= end
);
7113 /* Check a composition at the current point. */
7114 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7115 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7116 && COMPOSITION_VALID_P (start
, end
, prop
)
7117 && start
< pt
&& end
> pt
);
7120 /* Reconsider the setting of B->clip_changed which is displayed
7124 reconsider_clip_changes (w
, b
)
7128 if (b
->prevent_redisplay_optimizations_p
)
7129 b
->clip_changed
= 1;
7130 else if (b
->clip_changed
7131 && !NILP (w
->window_end_valid
)
7132 && w
->current_matrix
->buffer
== b
7133 && w
->current_matrix
->zv
== BUF_ZV (b
)
7134 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7135 b
->clip_changed
= 0;
7137 /* If display wasn't paused, and W is not a tool bar window, see if
7138 point has been moved into or out of a composition. In that case,
7139 we set b->clip_changed to 1 to force updating the screen. If
7140 b->clip_changed has already been set to 1, we can skip this
7142 if (!b
->clip_changed
7143 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7147 if (w
== XWINDOW (selected_window
))
7148 pt
= BUF_PT (current_buffer
);
7150 pt
= marker_position (w
->pointm
);
7152 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7153 || pt
!= XINT (w
->last_point
))
7154 && check_point_in_composition (w
->current_matrix
->buffer
,
7155 XINT (w
->last_point
),
7156 XBUFFER (w
->buffer
), pt
))
7157 b
->clip_changed
= 1;
7162 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7163 response to any user action; therefore, we should preserve the echo
7164 area. (Actually, our caller does that job.) Perhaps in the future
7165 avoid recentering windows if it is not necessary; currently that
7166 causes some problems. */
7169 redisplay_internal (preserve_echo_area
)
7170 int preserve_echo_area
;
7172 struct window
*w
= XWINDOW (selected_window
);
7173 struct frame
*f
= XFRAME (w
->frame
);
7175 int must_finish
= 0;
7176 struct text_pos tlbufpos
, tlendpos
;
7177 int number_of_visible_frames
;
7179 struct frame
*sf
= SELECTED_FRAME ();
7181 /* Non-zero means redisplay has to consider all windows on all
7182 frames. Zero means, only selected_window is considered. */
7183 int consider_all_windows_p
;
7185 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7187 /* No redisplay if running in batch mode or frame is not yet fully
7188 initialized, or redisplay is explicitly turned off by setting
7189 Vinhibit_redisplay. */
7191 || !NILP (Vinhibit_redisplay
)
7192 || !f
->glyphs_initialized_p
)
7195 /* The flag redisplay_performed_directly_p is set by
7196 direct_output_for_insert when it already did the whole screen
7197 update necessary. */
7198 if (redisplay_performed_directly_p
)
7200 redisplay_performed_directly_p
= 0;
7201 if (!hscroll_windows (selected_window
))
7205 #ifdef USE_X_TOOLKIT
7206 if (popup_activated ())
7210 /* I don't think this happens but let's be paranoid. */
7214 /* Record a function that resets redisplaying_p to its old value
7215 when we leave this function. */
7216 count
= specpdl_ptr
- specpdl
;
7217 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7222 reconsider_clip_changes (w
, current_buffer
);
7224 /* If new fonts have been loaded that make a glyph matrix adjustment
7225 necessary, do it. */
7226 if (fonts_changed_p
)
7228 adjust_glyphs (NULL
);
7229 ++windows_or_buffers_changed
;
7230 fonts_changed_p
= 0;
7233 if (! FRAME_WINDOW_P (sf
)
7234 && previous_terminal_frame
!= sf
)
7236 /* Since frames on an ASCII terminal share the same display
7237 area, displaying a different frame means redisplay the whole
7239 windows_or_buffers_changed
++;
7240 SET_FRAME_GARBAGED (sf
);
7241 XSETFRAME (Vterminal_frame
, sf
);
7243 previous_terminal_frame
= sf
;
7245 /* Set the visible flags for all frames. Do this before checking
7246 for resized or garbaged frames; they want to know if their frames
7247 are visible. See the comment in frame.h for
7248 FRAME_SAMPLE_VISIBILITY. */
7250 Lisp_Object tail
, frame
;
7252 number_of_visible_frames
= 0;
7254 FOR_EACH_FRAME (tail
, frame
)
7256 struct frame
*f
= XFRAME (frame
);
7258 FRAME_SAMPLE_VISIBILITY (f
);
7259 if (FRAME_VISIBLE_P (f
))
7260 ++number_of_visible_frames
;
7261 clear_desired_matrices (f
);
7265 /* Notice any pending interrupt request to change frame size. */
7266 do_pending_window_change (1);
7268 /* Clear frames marked as garbaged. */
7270 clear_garbaged_frames ();
7272 /* Build menubar and tool-bar items. */
7273 prepare_menu_bars ();
7275 if (windows_or_buffers_changed
)
7276 update_mode_lines
++;
7278 /* Detect case that we need to write or remove a star in the mode line. */
7279 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7281 w
->update_mode_line
= Qt
;
7282 if (buffer_shared
> 1)
7283 update_mode_lines
++;
7286 /* If %c is in the mode line, update it if needed. */
7287 if (!NILP (w
->column_number_displayed
)
7288 /* This alternative quickly identifies a common case
7289 where no change is needed. */
7290 && !(PT
== XFASTINT (w
->last_point
)
7291 && XFASTINT (w
->last_modified
) >= MODIFF
7292 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7293 && XFASTINT (w
->column_number_displayed
) != current_column ())
7294 w
->update_mode_line
= Qt
;
7296 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7298 /* The variable buffer_shared is set in redisplay_window and
7299 indicates that we redisplay a buffer in different windows. See
7301 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7303 /* If specs for an arrow have changed, do thorough redisplay
7304 to ensure we remove any arrow that should no longer exist. */
7305 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7306 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7307 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7309 /* Normally the message* functions will have already displayed and
7310 updated the echo area, but the frame may have been trashed, or
7311 the update may have been preempted, so display the echo area
7312 again here. Checking both message buffers captures the case that
7313 the echo area should be cleared. */
7314 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7316 int window_height_changed_p
= echo_area_display (0);
7319 if (fonts_changed_p
)
7321 else if (window_height_changed_p
)
7323 consider_all_windows_p
= 1;
7324 ++update_mode_lines
;
7325 ++windows_or_buffers_changed
;
7327 /* If window configuration was changed, frames may have been
7328 marked garbaged. Clear them or we will experience
7329 surprises wrt scrolling. */
7331 clear_garbaged_frames ();
7334 else if (w
== XWINDOW (minibuf_window
)
7335 && (current_buffer
->clip_changed
7336 || XFASTINT (w
->last_modified
) < MODIFF
7337 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7338 && resize_mini_window (w
, 0))
7340 /* Resized active mini-window to fit the size of what it is
7341 showing if its contents might have changed. */
7343 consider_all_windows_p
= 1;
7344 ++windows_or_buffers_changed
;
7345 ++update_mode_lines
;
7347 /* If window configuration was changed, frames may have been
7348 marked garbaged. Clear them or we will experience
7349 surprises wrt scrolling. */
7351 clear_garbaged_frames ();
7355 /* If showing the region, and mark has changed, we must redisplay
7356 the whole window. The assignment to this_line_start_pos prevents
7357 the optimization directly below this if-statement. */
7358 if (((!NILP (Vtransient_mark_mode
)
7359 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7360 != !NILP (w
->region_showing
))
7361 || (!NILP (w
->region_showing
)
7362 && !EQ (w
->region_showing
,
7363 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7364 CHARPOS (this_line_start_pos
) = 0;
7366 /* Optimize the case that only the line containing the cursor in the
7367 selected window has changed. Variables starting with this_ are
7368 set in display_line and record information about the line
7369 containing the cursor. */
7370 tlbufpos
= this_line_start_pos
;
7371 tlendpos
= this_line_end_pos
;
7372 if (!consider_all_windows_p
7373 && CHARPOS (tlbufpos
) > 0
7374 && NILP (w
->update_mode_line
)
7375 && !current_buffer
->clip_changed
7376 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7377 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7378 /* Make sure recorded data applies to current buffer, etc. */
7379 && this_line_buffer
== current_buffer
7380 && current_buffer
== XBUFFER (w
->buffer
)
7381 && NILP (w
->force_start
)
7382 /* Point must be on the line that we have info recorded about. */
7383 && PT
>= CHARPOS (tlbufpos
)
7384 && PT
<= Z
- CHARPOS (tlendpos
)
7385 /* All text outside that line, including its final newline,
7386 must be unchanged */
7387 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7388 CHARPOS (tlendpos
)))
7390 if (CHARPOS (tlbufpos
) > BEGV
7391 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7392 && (CHARPOS (tlbufpos
) == ZV
7393 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7394 /* Former continuation line has disappeared by becoming empty */
7396 else if (XFASTINT (w
->last_modified
) < MODIFF
7397 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7398 || MINI_WINDOW_P (w
))
7400 /* We have to handle the case of continuation around a
7401 wide-column character (See the comment in indent.c around
7404 For instance, in the following case:
7406 -------- Insert --------
7407 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7408 J_I_ ==> J_I_ `^^' are cursors.
7412 As we have to redraw the line above, we should goto cancel. */
7415 int line_height_before
= this_line_pixel_height
;
7417 /* Note that start_display will handle the case that the
7418 line starting at tlbufpos is a continuation lines. */
7419 start_display (&it
, w
, tlbufpos
);
7421 /* Implementation note: It this still necessary? */
7422 if (it
.current_x
!= this_line_start_x
)
7425 TRACE ((stderr
, "trying display optimization 1\n"));
7426 w
->cursor
.vpos
= -1;
7427 overlay_arrow_seen
= 0;
7428 it
.vpos
= this_line_vpos
;
7429 it
.current_y
= this_line_y
;
7430 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7433 /* If line contains point, is not continued,
7434 and ends at same distance from eob as before, we win */
7435 if (w
->cursor
.vpos
>= 0
7436 /* Line is not continued, otherwise this_line_start_pos
7437 would have been set to 0 in display_line. */
7438 && CHARPOS (this_line_start_pos
)
7439 /* Line ends as before. */
7440 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7441 /* Line has same height as before. Otherwise other lines
7442 would have to be shifted up or down. */
7443 && this_line_pixel_height
== line_height_before
)
7445 /* If this is not the window's last line, we must adjust
7446 the charstarts of the lines below. */
7447 if (it
.current_y
< it
.last_visible_y
)
7449 struct glyph_row
*row
7450 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7451 int delta
, delta_bytes
;
7453 if (Z
- CHARPOS (tlendpos
) == ZV
)
7455 /* This line ends at end of (accessible part of)
7456 buffer. There is no newline to count. */
7458 - CHARPOS (tlendpos
)
7459 - MATRIX_ROW_START_CHARPOS (row
));
7460 delta_bytes
= (Z_BYTE
7461 - BYTEPOS (tlendpos
)
7462 - MATRIX_ROW_START_BYTEPOS (row
));
7466 /* This line ends in a newline. Must take
7467 account of the newline and the rest of the
7468 text that follows. */
7470 - CHARPOS (tlendpos
)
7471 - MATRIX_ROW_START_CHARPOS (row
));
7472 delta_bytes
= (Z_BYTE
7473 - BYTEPOS (tlendpos
)
7474 - MATRIX_ROW_START_BYTEPOS (row
));
7477 increment_matrix_positions (w
->current_matrix
,
7479 w
->current_matrix
->nrows
,
7480 delta
, delta_bytes
);
7483 /* If this row displays text now but previously didn't,
7484 or vice versa, w->window_end_vpos may have to be
7486 if ((it
.glyph_row
- 1)->displays_text_p
)
7488 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7489 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7491 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7492 && this_line_vpos
> 0)
7493 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7494 w
->window_end_valid
= Qnil
;
7496 /* Update hint: No need to try to scroll in update_window. */
7497 w
->desired_matrix
->no_scrolling_p
= 1;
7500 *w
->desired_matrix
->method
= 0;
7501 debug_method_add (w
, "optimization 1");
7508 else if (/* Cursor position hasn't changed. */
7509 PT
== XFASTINT (w
->last_point
)
7510 /* Make sure the cursor was last displayed
7511 in this window. Otherwise we have to reposition it. */
7512 && 0 <= w
->cursor
.vpos
7513 && XINT (w
->height
) > w
->cursor
.vpos
)
7517 do_pending_window_change (1);
7519 /* We used to always goto end_of_redisplay here, but this
7520 isn't enough if we have a blinking cursor. */
7521 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7522 goto end_of_redisplay
;
7526 /* If highlighting the region, or if the cursor is in the echo area,
7527 then we can't just move the cursor. */
7528 else if (! (!NILP (Vtransient_mark_mode
)
7529 && !NILP (current_buffer
->mark_active
))
7530 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7531 || highlight_nonselected_windows
)
7532 && NILP (w
->region_showing
)
7533 && NILP (Vshow_trailing_whitespace
)
7534 && !cursor_in_echo_area
)
7537 struct glyph_row
*row
;
7539 /* Skip from tlbufpos to PT and see where it is. Note that
7540 PT may be in invisible text. If so, we will end at the
7541 next visible position. */
7542 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7543 NULL
, DEFAULT_FACE_ID
);
7544 it
.current_x
= this_line_start_x
;
7545 it
.current_y
= this_line_y
;
7546 it
.vpos
= this_line_vpos
;
7548 /* The call to move_it_to stops in front of PT, but
7549 moves over before-strings. */
7550 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7552 if (it
.vpos
== this_line_vpos
7553 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7556 xassert (this_line_vpos
== it
.vpos
);
7557 xassert (this_line_y
== it
.current_y
);
7558 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7566 /* Text changed drastically or point moved off of line. */
7567 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7570 CHARPOS (this_line_start_pos
) = 0;
7571 consider_all_windows_p
|= buffer_shared
> 1;
7572 ++clear_face_cache_count
;
7575 /* Build desired matrices. If consider_all_windows_p is non-zero,
7576 do it for all windows on all frames. Otherwise do it for
7577 selected_window, only. */
7579 if (consider_all_windows_p
)
7581 Lisp_Object tail
, frame
;
7583 /* Clear the face cache eventually. */
7584 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7586 clear_face_cache (0);
7587 clear_face_cache_count
= 0;
7590 /* Recompute # windows showing selected buffer. This will be
7591 incremented each time such a window is displayed. */
7594 FOR_EACH_FRAME (tail
, frame
)
7596 struct frame
*f
= XFRAME (frame
);
7597 if (FRAME_WINDOW_P (f
) || f
== sf
)
7599 /* Mark all the scroll bars to be removed; we'll redeem
7600 the ones we want when we redisplay their windows. */
7601 if (condemn_scroll_bars_hook
)
7602 (*condemn_scroll_bars_hook
) (f
);
7604 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7605 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7607 /* Any scroll bars which redisplay_windows should have
7608 nuked should now go away. */
7609 if (judge_scroll_bars_hook
)
7610 (*judge_scroll_bars_hook
) (f
);
7614 else if (FRAME_VISIBLE_P (sf
)
7615 && !FRAME_OBSCURED_P (sf
))
7616 redisplay_window (selected_window
, 1);
7619 /* Compare desired and current matrices, perform output. */
7623 /* If fonts changed, display again. */
7624 if (fonts_changed_p
)
7627 /* Prevent various kinds of signals during display update.
7628 stdio is not robust about handling signals,
7629 which can cause an apparent I/O error. */
7630 if (interrupt_input
)
7634 if (consider_all_windows_p
)
7643 /* See if we have to hscroll. */
7644 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7645 if (FRAMEP (XCAR (tail
)))
7647 f
= XFRAME (XCAR (tail
));
7649 if ((FRAME_WINDOW_P (f
)
7651 && FRAME_VISIBLE_P (f
)
7652 && !FRAME_OBSCURED_P (f
)
7653 && hscroll_windows (f
->root_window
))
7660 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7662 if (!FRAMEP (XCAR (tail
)))
7665 f
= XFRAME (XCAR (tail
));
7667 if ((FRAME_WINDOW_P (f
) || f
== sf
)
7668 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7670 /* Mark all windows as to be updated. */
7671 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7672 pause
|= update_frame (f
, 0, 0);
7675 mark_window_display_accurate (f
->root_window
, 1);
7676 if (frame_up_to_date_hook
!= 0)
7677 (*frame_up_to_date_hook
) (f
);
7684 if (FRAME_VISIBLE_P (sf
)
7685 && !FRAME_OBSCURED_P (sf
))
7687 if (hscroll_windows (selected_window
))
7690 XWINDOW (selected_window
)->must_be_updated_p
= 1;
7691 pause
= update_frame (sf
, 0, 0);
7696 /* We may have called echo_area_display at the top of this
7697 function. If the echo area is on another frame, that may
7698 have put text on a frame other than the selected one, so the
7699 above call to update_frame would not have caught it. Catch
7702 Lisp_Object mini_window
;
7703 struct frame
*mini_frame
;
7705 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7706 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7708 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
7710 XWINDOW (mini_window
)->must_be_updated_p
= 1;
7711 pause
|= update_frame (mini_frame
, 0, 0);
7712 if (!pause
&& hscroll_windows (mini_window
))
7718 /* If display was paused because of pending input, make sure we do a
7719 thorough update the next time. */
7722 /* Prevent the optimization at the beginning of
7723 redisplay_internal that tries a single-line update of the
7724 line containing the cursor in the selected window. */
7725 CHARPOS (this_line_start_pos
) = 0;
7727 /* Let the overlay arrow be updated the next time. */
7728 if (!NILP (last_arrow_position
))
7730 last_arrow_position
= Qt
;
7731 last_arrow_string
= Qt
;
7734 /* If we pause after scrolling, some rows in the current
7735 matrices of some windows are not valid. */
7736 if (!WINDOW_FULL_WIDTH_P (w
)
7737 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
7738 update_mode_lines
= 1;
7741 /* Now text on frame agrees with windows, so put info into the
7742 windows for partial redisplay to follow. */
7745 register struct buffer
*b
= XBUFFER (w
->buffer
);
7747 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
7748 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
7749 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
7750 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
7752 if (consider_all_windows_p
)
7753 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
7756 XSETFASTINT (w
->last_point
, BUF_PT (b
));
7757 w
->last_cursor
= w
->cursor
;
7758 w
->last_cursor_off_p
= w
->cursor_off_p
;
7760 b
->clip_changed
= 0;
7761 b
->prevent_redisplay_optimizations_p
= 0;
7762 w
->update_mode_line
= Qnil
;
7763 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
7764 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
7766 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7769 /* Record if we are showing a region, so can make sure to
7770 update it fully at next redisplay. */
7771 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
7772 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7773 || highlight_nonselected_windows
)
7774 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
7775 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
7778 w
->window_end_valid
= w
->buffer
;
7779 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7780 last_arrow_string
= Voverlay_arrow_string
;
7781 if (frame_up_to_date_hook
!= 0)
7782 (*frame_up_to_date_hook
) (sf
);
7784 w
->current_matrix
->buffer
= b
;
7785 w
->current_matrix
->begv
= BUF_BEGV (b
);
7786 w
->current_matrix
->zv
= BUF_ZV (b
);
7789 update_mode_lines
= 0;
7790 windows_or_buffers_changed
= 0;
7793 /* Start SIGIO interrupts coming again. Having them off during the
7794 code above makes it less likely one will discard output, but not
7795 impossible, since there might be stuff in the system buffer here.
7796 But it is much hairier to try to do anything about that. */
7797 if (interrupt_input
)
7801 /* If a frame has become visible which was not before, redisplay
7802 again, so that we display it. Expose events for such a frame
7803 (which it gets when becoming visible) don't call the parts of
7804 redisplay constructing glyphs, so simply exposing a frame won't
7805 display anything in this case. So, we have to display these
7806 frames here explicitly. */
7809 Lisp_Object tail
, frame
;
7812 FOR_EACH_FRAME (tail
, frame
)
7814 int this_is_visible
= 0;
7816 if (XFRAME (frame
)->visible
)
7817 this_is_visible
= 1;
7818 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
7819 if (XFRAME (frame
)->visible
)
7820 this_is_visible
= 1;
7822 if (this_is_visible
)
7826 if (new_count
!= number_of_visible_frames
)
7827 windows_or_buffers_changed
++;
7830 /* Change frame size now if a change is pending. */
7831 do_pending_window_change (1);
7833 /* If we just did a pending size change, or have additional
7834 visible frames, redisplay again. */
7835 if (windows_or_buffers_changed
&& !pause
)
7840 unbind_to (count
, Qnil
);
7844 /* Redisplay, but leave alone any recent echo area message unless
7845 another message has been requested in its place.
7847 This is useful in situations where you need to redisplay but no
7848 user action has occurred, making it inappropriate for the message
7849 area to be cleared. See tracking_off and
7850 wait_reading_process_input for examples of these situations. */
7853 redisplay_preserve_echo_area ()
7855 if (!NILP (echo_area_buffer
[1]))
7857 /* We have a previously displayed message, but no current
7858 message. Redisplay the previous message. */
7859 display_last_displayed_message_p
= 1;
7860 redisplay_internal (1);
7861 display_last_displayed_message_p
= 0;
7864 redisplay_internal (1);
7868 /* Function registered with record_unwind_protect in
7869 redisplay_internal. Clears the flag indicating that a redisplay is
7873 unwind_redisplay (old_redisplaying_p
)
7874 Lisp_Object old_redisplaying_p
;
7876 redisplaying_p
= XFASTINT (old_redisplaying_p
);
7881 /* Mark the display of windows in the window tree rooted at WINDOW as
7882 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
7883 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
7884 the next time redisplay_internal is called. */
7887 mark_window_display_accurate (window
, accurate_p
)
7893 for (; !NILP (window
); window
= w
->next
)
7895 w
= XWINDOW (window
);
7897 if (BUFFERP (w
->buffer
))
7899 struct buffer
*b
= XBUFFER (w
->buffer
);
7901 XSETFASTINT (w
->last_modified
,
7902 accurate_p
? BUF_MODIFF (b
) : 0);
7903 XSETFASTINT (w
->last_overlay_modified
,
7904 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7905 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7908 #if 0 /* I don't think this is necessary because display_line does it.
7910 /* Record if we are showing a region, so can make sure to
7911 update it fully at next redisplay. */
7913 = (!NILP (Vtransient_mark_mode
)
7914 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7915 || highlight_nonselected_windows
)
7916 && (!NILP (b
->mark_active
)
7917 ? Fmarker_position (b
->mark
)
7923 b
->clip_changed
= 0;
7924 b
->prevent_redisplay_optimizations_p
= 0;
7925 w
->current_matrix
->buffer
= b
;
7926 w
->current_matrix
->begv
= BUF_BEGV (b
);
7927 w
->current_matrix
->zv
= BUF_ZV (b
);
7928 w
->last_cursor
= w
->cursor
;
7929 w
->last_cursor_off_p
= w
->cursor_off_p
;
7930 if (w
== XWINDOW (selected_window
))
7931 w
->last_point
= make_number (BUF_PT (b
));
7933 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
7937 w
->window_end_valid
= w
->buffer
;
7938 w
->update_mode_line
= Qnil
;
7940 if (!NILP (w
->vchild
))
7941 mark_window_display_accurate (w
->vchild
, accurate_p
);
7942 if (!NILP (w
->hchild
))
7943 mark_window_display_accurate (w
->hchild
, accurate_p
);
7948 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7949 last_arrow_string
= Voverlay_arrow_string
;
7953 /* Force a thorough redisplay the next time by setting
7954 last_arrow_position and last_arrow_string to t, which is
7955 unequal to any useful value of Voverlay_arrow_... */
7956 last_arrow_position
= Qt
;
7957 last_arrow_string
= Qt
;
7962 /* Return value in display table DP (Lisp_Char_Table *) for character
7963 C. Since a display table doesn't have any parent, we don't have to
7964 follow parent. Do not call this function directly but use the
7965 macro DISP_CHAR_VECTOR. */
7968 disp_char_vector (dp
, c
)
7969 struct Lisp_Char_Table
*dp
;
7975 if (SINGLE_BYTE_CHAR_P (c
))
7976 return (dp
->contents
[c
]);
7978 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
7981 else if (code
[2] < 32)
7984 /* Here, the possible range of code[0] (== charset ID) is
7985 128..max_charset. Since the top level char table contains data
7986 for multibyte characters after 256th element, we must increment
7987 code[0] by 128 to get a correct index. */
7989 code
[3] = -1; /* anchor */
7991 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
7993 val
= dp
->contents
[code
[i
]];
7994 if (!SUB_CHAR_TABLE_P (val
))
7995 return (NILP (val
) ? dp
->defalt
: val
);
7998 /* Here, val is a sub char table. We return the default value of
8000 return (dp
->defalt
);
8005 /***********************************************************************
8007 ***********************************************************************/
8009 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8012 redisplay_windows (window
)
8015 while (!NILP (window
))
8017 struct window
*w
= XWINDOW (window
);
8019 if (!NILP (w
->hchild
))
8020 redisplay_windows (w
->hchild
);
8021 else if (!NILP (w
->vchild
))
8022 redisplay_windows (w
->vchild
);
8024 redisplay_window (window
, 0);
8031 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8032 DELTA is the number of bytes by which positions recorded in ROW
8033 differ from current buffer positions. */
8036 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8038 struct glyph_row
*row
;
8039 struct glyph_matrix
*matrix
;
8040 int delta
, delta_bytes
, dy
, dvpos
;
8042 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8043 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8045 int pt_old
= PT
- delta
;
8047 /* Skip over glyphs not having an object at the start of the row.
8048 These are special glyphs like truncation marks on terminal
8050 if (row
->displays_text_p
)
8052 && INTEGERP (glyph
->object
)
8053 && glyph
->charpos
< 0)
8055 x
+= glyph
->pixel_width
;
8060 && !INTEGERP (glyph
->object
)
8061 && (!BUFFERP (glyph
->object
)
8062 || glyph
->charpos
< pt_old
))
8064 x
+= glyph
->pixel_width
;
8068 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8070 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8071 w
->cursor
.y
= row
->y
+ dy
;
8073 if (w
== XWINDOW (selected_window
))
8075 if (!row
->continued_p
8076 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8079 this_line_buffer
= XBUFFER (w
->buffer
);
8081 CHARPOS (this_line_start_pos
)
8082 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8083 BYTEPOS (this_line_start_pos
)
8084 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8086 CHARPOS (this_line_end_pos
)
8087 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8088 BYTEPOS (this_line_end_pos
)
8089 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8091 this_line_y
= w
->cursor
.y
;
8092 this_line_pixel_height
= row
->height
;
8093 this_line_vpos
= w
->cursor
.vpos
;
8094 this_line_start_x
= row
->x
;
8097 CHARPOS (this_line_start_pos
) = 0;
8102 /* Run window scroll functions, if any, for WINDOW with new window
8103 start STARTP. Sets the window start of WINDOW to that position.
8105 We assume that the window's buffer is really current. */
8107 static INLINE
struct text_pos
8108 run_window_scroll_functions (window
, startp
)
8110 struct text_pos startp
;
8112 struct window
*w
= XWINDOW (window
);
8113 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8115 if (current_buffer
!= XBUFFER (w
->buffer
))
8118 if (!NILP (Vwindow_scroll_functions
))
8120 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8121 make_number (CHARPOS (startp
)));
8122 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8123 /* In case the hook functions switch buffers. */
8124 if (current_buffer
!= XBUFFER (w
->buffer
))
8125 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8132 /* Modify the desired matrix of window W and W->vscroll so that the
8133 line containing the cursor is fully visible. */
8136 make_cursor_line_fully_visible (w
)
8139 struct glyph_matrix
*matrix
;
8140 struct glyph_row
*row
;
8141 int header_line_height
;
8143 /* It's not always possible to find the cursor, e.g, when a window
8144 is full of overlay strings. Don't do anything in that case. */
8145 if (w
->cursor
.vpos
< 0)
8148 matrix
= w
->desired_matrix
;
8149 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8151 /* If row->y == top y of window display area, the window isn't tall
8152 enough to display a single line. There is nothing we can do
8154 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
8155 if (row
->y
== header_line_height
)
8158 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
8160 int dy
= row
->height
- row
->visible_height
;
8163 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8165 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
))
8167 int dy
= - (row
->height
- row
->visible_height
);
8170 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8173 /* When we change the cursor y-position of the selected window,
8174 change this_line_y as well so that the display optimization for
8175 the cursor line of the selected window in redisplay_internal uses
8176 the correct y-position. */
8177 if (w
== XWINDOW (selected_window
))
8178 this_line_y
= w
->cursor
.y
;
8182 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8183 non-zero means only WINDOW is redisplayed in redisplay_internal.
8184 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8185 in redisplay_window to bring a partially visible line into view in
8186 the case that only the cursor has moved.
8190 1 if scrolling succeeded
8192 0 if scrolling didn't find point.
8194 -1 if new fonts have been loaded so that we must interrupt
8195 redisplay, adjust glyph matrices, and try again. */
8198 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8199 scroll_step
, temp_scroll_step
)
8201 int just_this_one_p
;
8202 int scroll_conservatively
, scroll_step
;
8203 int temp_scroll_step
;
8205 struct window
*w
= XWINDOW (window
);
8206 struct frame
*f
= XFRAME (w
->frame
);
8207 struct text_pos scroll_margin_pos
;
8208 struct text_pos pos
;
8209 struct text_pos startp
;
8211 Lisp_Object window_end
;
8212 int this_scroll_margin
;
8215 int line_height
, rc
;
8216 int amount_to_scroll
= 0;
8217 Lisp_Object aggressive
;
8221 debug_method_add (w
, "try_scrolling");
8224 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8226 /* Compute scroll margin height in pixels. We scroll when point is
8227 within this distance from the top or bottom of the window. */
8228 if (scroll_margin
> 0)
8230 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8231 this_scroll_margin
*= CANON_Y_UNIT (f
);
8234 this_scroll_margin
= 0;
8236 /* Compute how much we should try to scroll maximally to bring point
8239 scroll_max
= scroll_step
;
8240 else if (scroll_conservatively
)
8241 scroll_max
= scroll_conservatively
;
8242 else if (temp_scroll_step
)
8243 scroll_max
= temp_scroll_step
;
8244 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8245 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8246 /* We're trying to scroll because of aggressive scrolling
8247 but no scroll_step is set. Choose an arbitrary one. Maybe
8248 there should be a variable for this. */
8252 scroll_max
*= CANON_Y_UNIT (f
);
8254 /* Decide whether we have to scroll down. Start at the window end
8255 and move this_scroll_margin up to find the position of the scroll
8257 window_end
= Fwindow_end (window
, Qt
);
8258 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8259 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8260 if (this_scroll_margin
)
8262 start_display (&it
, w
, scroll_margin_pos
);
8263 move_it_vertically (&it
, - this_scroll_margin
);
8264 scroll_margin_pos
= it
.current
.pos
;
8267 if (PT
>= CHARPOS (scroll_margin_pos
))
8271 /* Point is in the scroll margin at the bottom of the window, or
8272 below. Compute a new window start that makes point visible. */
8274 /* Compute the distance from the scroll margin to PT.
8275 Give up if the distance is greater than scroll_max. */
8276 start_display (&it
, w
, scroll_margin_pos
);
8278 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8279 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8280 line_height
= (it
.max_ascent
+ it
.max_descent
8281 ? it
.max_ascent
+ it
.max_descent
8283 dy
= it
.current_y
+ line_height
- y0
;
8284 if (dy
> scroll_max
)
8287 /* Move the window start down. If scrolling conservatively,
8288 move it just enough down to make point visible. If
8289 scroll_step is set, move it down by scroll_step. */
8290 start_display (&it
, w
, startp
);
8292 if (scroll_conservatively
)
8293 amount_to_scroll
= dy
;
8294 else if (scroll_step
|| temp_scroll_step
)
8295 amount_to_scroll
= scroll_max
;
8298 aggressive
= current_buffer
->scroll_down_aggressively
;
8299 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8300 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8301 if (NUMBERP (aggressive
))
8302 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8305 if (amount_to_scroll
<= 0)
8308 move_it_vertically (&it
, amount_to_scroll
);
8309 startp
= it
.current
.pos
;
8313 /* See if point is inside the scroll margin at the top of the
8315 scroll_margin_pos
= startp
;
8316 if (this_scroll_margin
)
8318 start_display (&it
, w
, startp
);
8319 move_it_vertically (&it
, this_scroll_margin
);
8320 scroll_margin_pos
= it
.current
.pos
;
8323 if (PT
< CHARPOS (scroll_margin_pos
))
8325 /* Point is in the scroll margin at the top of the window or
8326 above what is displayed in the window. */
8329 /* Compute the vertical distance from PT to the scroll
8330 margin position. Give up if distance is greater than
8332 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8333 start_display (&it
, w
, pos
);
8335 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8336 it
.last_visible_y
, -1,
8337 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8338 dy
= it
.current_y
- y0
;
8339 if (dy
> scroll_max
)
8342 /* Compute new window start. */
8343 start_display (&it
, w
, startp
);
8345 if (scroll_conservatively
)
8346 amount_to_scroll
= dy
;
8347 else if (scroll_step
|| temp_scroll_step
)
8348 amount_to_scroll
= scroll_max
;
8351 aggressive
= current_buffer
->scroll_up_aggressively
;
8352 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8353 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8354 if (NUMBERP (aggressive
))
8355 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8358 if (amount_to_scroll
<= 0)
8361 move_it_vertically (&it
, - amount_to_scroll
);
8362 startp
= it
.current
.pos
;
8366 /* Run window scroll functions. */
8367 startp
= run_window_scroll_functions (window
, startp
);
8369 /* Display the window. Give up if new fonts are loaded, or if point
8371 if (!try_window (window
, startp
))
8373 else if (w
->cursor
.vpos
< 0)
8375 clear_glyph_matrix (w
->desired_matrix
);
8380 /* Maybe forget recorded base line for line number display. */
8381 if (!just_this_one_p
8382 || current_buffer
->clip_changed
8383 || BEG_UNCHANGED
< CHARPOS (startp
))
8384 w
->base_line_number
= Qnil
;
8386 /* If cursor ends up on a partially visible line, shift display
8387 lines up or down. */
8388 make_cursor_line_fully_visible (w
);
8396 /* Compute a suitable window start for window W if display of W starts
8397 on a continuation line. Value is non-zero if a new window start
8400 The new window start will be computed, based on W's width, starting
8401 from the start of the continued line. It is the start of the
8402 screen line with the minimum distance from the old start W->start. */
8405 compute_window_start_on_continuation_line (w
)
8408 struct text_pos pos
, start_pos
;
8409 int window_start_changed_p
= 0;
8411 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8413 /* If window start is on a continuation line... Window start may be
8414 < BEGV in case there's invisible text at the start of the
8415 buffer (M-x rmail, for example). */
8416 if (CHARPOS (start_pos
) > BEGV
8417 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8420 struct glyph_row
*row
;
8422 /* Handle the case that the window start is out of range. */
8423 if (CHARPOS (start_pos
) < BEGV
)
8424 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8425 else if (CHARPOS (start_pos
) > ZV
)
8426 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8428 /* Find the start of the continued line. This should be fast
8429 because scan_buffer is fast (newline cache). */
8430 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8431 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8432 row
, DEFAULT_FACE_ID
);
8433 reseat_at_previous_visible_line_start (&it
);
8435 /* If the line start is "too far" away from the window start,
8436 say it takes too much time to compute a new window start. */
8437 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8438 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8440 int min_distance
, distance
;
8442 /* Move forward by display lines to find the new window
8443 start. If window width was enlarged, the new start can
8444 be expected to be > the old start. If window width was
8445 decreased, the new window start will be < the old start.
8446 So, we're looking for the display line start with the
8447 minimum distance from the old window start. */
8448 pos
= it
.current
.pos
;
8449 min_distance
= INFINITY
;
8450 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8451 distance
< min_distance
)
8453 min_distance
= distance
;
8454 pos
= it
.current
.pos
;
8455 move_it_by_lines (&it
, 1, 0);
8458 /* Set the window start there. */
8459 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8460 window_start_changed_p
= 1;
8464 return window_start_changed_p
;
8468 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8469 selected_window is redisplayed. */
8472 redisplay_window (window
, just_this_one_p
)
8474 int just_this_one_p
;
8476 struct window
*w
= XWINDOW (window
);
8477 struct frame
*f
= XFRAME (w
->frame
);
8478 struct buffer
*buffer
= XBUFFER (w
->buffer
);
8479 struct buffer
*old
= current_buffer
;
8480 struct text_pos lpoint
, opoint
, startp
;
8481 int update_mode_line
;
8484 /* Record it now because it's overwritten. */
8485 int current_matrix_up_to_date_p
= 0;
8486 int really_switched_buffer
= 0;
8487 int temp_scroll_step
= 0;
8488 int count
= specpdl_ptr
- specpdl
;
8490 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8493 /* W must be a leaf window here. */
8494 xassert (!NILP (w
->buffer
));
8496 *w
->desired_matrix
->method
= 0;
8499 specbind (Qinhibit_point_motion_hooks
, Qt
);
8501 reconsider_clip_changes (w
, buffer
);
8503 /* Has the mode line to be updated? */
8504 update_mode_line
= (!NILP (w
->update_mode_line
)
8505 || update_mode_lines
8506 || buffer
->clip_changed
);
8508 if (MINI_WINDOW_P (w
))
8510 if (w
== XWINDOW (echo_area_window
)
8511 && !NILP (echo_area_buffer
[0]))
8513 if (update_mode_line
)
8514 /* We may have to update a tty frame's menu bar or a
8515 tool-bar. Example `M-x C-h C-h C-g'. */
8516 goto finish_menu_bars
;
8518 /* We've already displayed the echo area glyphs in this window. */
8519 goto finish_scroll_bars
;
8521 else if (w
!= XWINDOW (minibuf_window
))
8523 /* W is a mini-buffer window, but it's not the currently
8524 active one, so clear it. */
8525 int yb
= window_text_bottom_y (w
);
8526 struct glyph_row
*row
;
8529 for (y
= 0, row
= w
->desired_matrix
->rows
;
8531 y
+= row
->height
, ++row
)
8532 blank_row (w
, row
, y
);
8533 goto finish_scroll_bars
;
8537 /* Otherwise set up data on this window; select its buffer and point
8539 if (update_mode_line
)
8541 /* Really select the buffer, for the sake of buffer-local
8543 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8544 really_switched_buffer
= 1;
8547 set_buffer_temp (XBUFFER (w
->buffer
));
8548 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
8550 current_matrix_up_to_date_p
8551 = (!NILP (w
->window_end_valid
)
8552 && !current_buffer
->clip_changed
8553 && XFASTINT (w
->last_modified
) >= MODIFF
8554 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
8556 /* When windows_or_buffers_changed is non-zero, we can't rely on
8557 the window end being valid, so set it to nil there. */
8558 if (windows_or_buffers_changed
)
8560 /* If window starts on a continuation line, maybe adjust the
8561 window start in case the window's width changed. */
8562 if (XMARKER (w
->start
)->buffer
== current_buffer
)
8563 compute_window_start_on_continuation_line (w
);
8565 w
->window_end_valid
= Qnil
;
8568 /* Some sanity checks. */
8569 CHECK_WINDOW_END (w
);
8570 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
8572 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
8575 /* If %c is in mode line, update it if needed. */
8576 if (!NILP (w
->column_number_displayed
)
8577 /* This alternative quickly identifies a common case
8578 where no change is needed. */
8579 && !(PT
== XFASTINT (w
->last_point
)
8580 && XFASTINT (w
->last_modified
) >= MODIFF
8581 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8582 && XFASTINT (w
->column_number_displayed
) != current_column ())
8583 update_mode_line
= 1;
8585 /* Count number of windows showing the selected buffer. An indirect
8586 buffer counts as its base buffer. */
8587 if (!just_this_one_p
)
8589 struct buffer
*current_base
, *window_base
;
8590 current_base
= current_buffer
;
8591 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8592 if (current_base
->base_buffer
)
8593 current_base
= current_base
->base_buffer
;
8594 if (window_base
->base_buffer
)
8595 window_base
= window_base
->base_buffer
;
8596 if (current_base
== window_base
)
8600 /* Point refers normally to the selected window. For any other
8601 window, set up appropriate value. */
8602 if (!EQ (window
, selected_window
))
8604 int new_pt
= XMARKER (w
->pointm
)->charpos
;
8605 int new_pt_byte
= marker_byte_position (w
->pointm
);
8609 new_pt_byte
= BEGV_BYTE
;
8610 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
8612 else if (new_pt
> (ZV
- 1))
8615 new_pt_byte
= ZV_BYTE
;
8616 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
8619 /* We don't use SET_PT so that the point-motion hooks don't run. */
8620 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
8623 /* If any of the character widths specified in the display table
8624 have changed, invalidate the width run cache. It's true that
8625 this may be a bit late to catch such changes, but the rest of
8626 redisplay goes (non-fatally) haywire when the display table is
8627 changed, so why should we worry about doing any better? */
8628 if (current_buffer
->width_run_cache
)
8630 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
8632 if (! disptab_matches_widthtab (disptab
,
8633 XVECTOR (current_buffer
->width_table
)))
8635 invalidate_region_cache (current_buffer
,
8636 current_buffer
->width_run_cache
,
8638 recompute_width_table (current_buffer
, disptab
);
8642 /* If window-start is screwed up, choose a new one. */
8643 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
8646 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8648 /* If someone specified a new starting point but did not insist,
8649 check whether it can be used. */
8650 if (!NILP (w
->optional_new_start
)
8651 && CHARPOS (startp
) >= BEGV
8652 && CHARPOS (startp
) <= ZV
)
8654 w
->optional_new_start
= Qnil
;
8655 /* This takes a mini-buffer prompt into account. */
8656 start_display (&it
, w
, startp
);
8657 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8658 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8659 if (IT_CHARPOS (it
) == PT
)
8660 w
->force_start
= Qt
;
8663 /* Handle case where place to start displaying has been specified,
8664 unless the specified location is outside the accessible range. */
8665 if (!NILP (w
->force_start
)
8666 || w
->frozen_window_start_p
)
8668 w
->force_start
= Qnil
;
8670 w
->window_end_valid
= Qnil
;
8672 /* Forget any recorded base line for line number display. */
8673 if (!current_matrix_up_to_date_p
8674 || current_buffer
->clip_changed
)
8675 w
->base_line_number
= Qnil
;
8677 /* Redisplay the mode line. Select the buffer properly for that.
8678 Also, run the hook window-scroll-functions
8679 because we have scrolled. */
8680 /* Note, we do this after clearing force_start because
8681 if there's an error, it is better to forget about force_start
8682 than to get into an infinite loop calling the hook functions
8683 and having them get more errors. */
8684 if (!update_mode_line
8685 || ! NILP (Vwindow_scroll_functions
))
8687 if (!really_switched_buffer
)
8689 set_buffer_temp (old
);
8690 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8691 really_switched_buffer
= 1;
8694 update_mode_line
= 1;
8695 w
->update_mode_line
= Qt
;
8696 startp
= run_window_scroll_functions (window
, startp
);
8699 XSETFASTINT (w
->last_modified
, 0);
8700 XSETFASTINT (w
->last_overlay_modified
, 0);
8701 if (CHARPOS (startp
) < BEGV
)
8702 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
8703 else if (CHARPOS (startp
) > ZV
)
8704 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
8706 /* Redisplay, then check if cursor has been set during the
8707 redisplay. Give up if new fonts were loaded. */
8708 if (!try_window (window
, startp
))
8710 w
->force_start
= Qt
;
8711 clear_glyph_matrix (w
->desired_matrix
);
8712 goto restore_buffers
;
8715 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
8717 /* If point does not appear, or on a line that is not fully
8718 visible, move point so it does appear. The desired
8719 matrix has been built above, so we can use it. */
8720 int height
= window_box_height (w
) / 2;
8721 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
8723 while (row
->y
< height
)
8726 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
8727 MATRIX_ROW_START_BYTEPOS (row
));
8729 if (w
!= XWINDOW (selected_window
))
8730 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
8731 else if (current_buffer
== old
)
8732 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8734 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
8736 /* If we are highlighting the region, then we just changed
8737 the region, so redisplay to show it. */
8738 if (!NILP (Vtransient_mark_mode
)
8739 && !NILP (current_buffer
->mark_active
))
8741 clear_glyph_matrix (w
->desired_matrix
);
8742 if (!try_window (window
, startp
))
8743 goto restore_buffers
;
8747 make_cursor_line_fully_visible (w
);
8749 debug_method_add (w
, "forced window start");
8754 /* Handle case where text has not changed, only point, and it has
8755 not moved off the frame. */
8756 if (current_matrix_up_to_date_p
8757 /* Point may be in this window. */
8758 && PT
>= CHARPOS (startp
)
8759 /* If we don't check this, we are called to move the cursor in a
8760 horizontally split window with a current matrix that doesn't
8762 && !windows_or_buffers_changed
8763 /* Selective display hasn't changed. */
8764 && !current_buffer
->clip_changed
8765 /* If force-mode-line-update was called, really redisplay;
8766 that's how redisplay is forced after e.g. changing
8767 buffer-invisibility-spec. */
8768 && NILP (w
->update_mode_line
)
8769 /* Can't use this case if highlighting a region. When a
8770 region exists, cursor movement has to do more than just
8772 && !(!NILP (Vtransient_mark_mode
)
8773 && !NILP (current_buffer
->mark_active
))
8774 && NILP (w
->region_showing
)
8775 && NILP (Vshow_trailing_whitespace
)
8776 /* Right after splitting windows, last_point may be nil. */
8777 && INTEGERP (w
->last_point
)
8778 /* This code is not used for mini-buffer for the sake of the case
8779 of redisplaying to replace an echo area message; since in
8780 that case the mini-buffer contents per se are usually
8781 unchanged. This code is of no real use in the mini-buffer
8782 since the handling of this_line_start_pos, etc., in redisplay
8783 handles the same cases. */
8784 && !EQ (window
, minibuf_window
)
8785 /* When splitting windows or for new windows, it happens that
8786 redisplay is called with a nil window_end_vpos or one being
8787 larger than the window. This should really be fixed in
8788 window.c. I don't have this on my list, now, so we do
8789 approximately the same as the old redisplay code. --gerd. */
8790 && INTEGERP (w
->window_end_vpos
)
8791 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8792 && (FRAME_WINDOW_P (f
)
8793 || !MARKERP (Voverlay_arrow_position
)
8794 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8796 int this_scroll_margin
;
8797 struct glyph_row
*row
;
8801 debug_method_add (w
, "cursor movement");
8804 /* Scroll if point within this distance from the top or bottom
8805 of the window. This is a pixel value. */
8806 this_scroll_margin
= max (0, scroll_margin
);
8807 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8808 this_scroll_margin
*= CANON_Y_UNIT (f
);
8810 /* Start with the row the cursor was displayed during the last
8811 not paused redisplay. Give up if that row is not valid. */
8812 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8814 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8815 if (row
->mode_line_p
)
8817 if (!row
->enabled_p
)
8821 if (PT
> XFASTINT (w
->last_point
))
8823 /* Point has moved forward. */
8824 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8826 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
8827 /* The end position of a row equals the start
8828 position of the next row. If PT is there, we
8829 would rather display it in the next line, except
8830 when this line ends in ZV. */
8831 || (MATRIX_ROW_END_CHARPOS (row
) == PT
8832 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8833 || !row
->ends_at_zv_p
)))
8834 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8836 xassert (row
->enabled_p
);
8840 /* If within the scroll margin, scroll. Note that
8841 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
8842 next line would be drawn, and that this_scroll_margin can
8844 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8845 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8846 /* Line is completely visible last line in window and PT
8847 is to be set in the next line. */
8848 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8849 && PT
== MATRIX_ROW_END_CHARPOS (row
)
8850 && !row
->ends_at_zv_p
8851 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
8854 else if (PT
< XFASTINT (w
->last_point
))
8856 /* Cursor has to be moved backward. Note that PT >=
8857 CHARPOS (startp) because of the outer if-statement. */
8858 while (!row
->mode_line_p
8859 && (MATRIX_ROW_START_CHARPOS (row
) > PT
8860 || (MATRIX_ROW_START_CHARPOS (row
) == PT
8861 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
8862 && (row
->y
> this_scroll_margin
8863 || CHARPOS (startp
) == BEGV
))
8865 xassert (row
->enabled_p
);
8869 /* Consider the following case: Window starts at BEGV, there
8870 is invisible, intangible text at BEGV, so that display
8871 starts at some point START > BEGV. It can happen that
8872 we are called with PT somewhere between BEGV and START.
8873 Try to handle that case. */
8874 if (row
< w
->current_matrix
->rows
8875 || row
->mode_line_p
)
8877 row
= w
->current_matrix
->rows
;
8878 if (row
->mode_line_p
)
8882 /* Due to newlines in overlay strings, we may have to skip
8883 forward over overlay strings. */
8884 while (MATRIX_ROW_END_CHARPOS (row
) == PT
8885 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
8886 && !row
->ends_at_zv_p
)
8889 /* If within the scroll margin, scroll. */
8890 if (row
->y
< this_scroll_margin
8891 && CHARPOS (startp
) != BEGV
)
8895 /* if PT is not in the glyph row, give up. */
8896 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8897 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8900 /* If we end up in a partially visible line, let's make it fully
8901 visible. This can be done most easily by using the existing
8903 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8905 temp_scroll_step
= 1;
8911 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8915 /* If current starting point was originally the beginning of a line
8916 but no longer is, find a new starting point. */
8917 else if (!NILP (w
->start_at_line_beg
)
8918 && !(CHARPOS (startp
) <= BEGV
8919 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8922 debug_method_add (w
, "recenter 1");
8927 /* Try scrolling with try_window_id. */
8928 else if (/* Windows and buffers haven't changed. */
8929 !windows_or_buffers_changed
8930 /* Window must be either use window-based redisplay or
8932 && (FRAME_WINDOW_P (f
)
8933 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
8934 && !MINI_WINDOW_P (w
)
8935 /* Point is not known NOT to appear in window. */
8936 && PT
>= CHARPOS (startp
)
8937 && XFASTINT (w
->last_modified
)
8938 /* Window is not hscrolled. */
8939 && XFASTINT (w
->hscroll
) == 0
8940 /* Selective display has not changed. */
8941 && !current_buffer
->clip_changed
8942 /* Current matrix is up to date. */
8943 && !NILP (w
->window_end_valid
)
8944 /* Can't use this case if highlighting a region because
8945 a cursor movement will do more than just set the cursor. */
8946 && !(!NILP (Vtransient_mark_mode
)
8947 && !NILP (current_buffer
->mark_active
))
8948 && NILP (w
->region_showing
)
8949 && NILP (Vshow_trailing_whitespace
)
8950 /* Overlay arrow position and string not changed. */
8951 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8952 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8953 /* Value is > 0 if update has been done, it is -1 if we
8954 know that the same window start will not work. It is 0
8955 if unsuccessful for some other reason. */
8956 && (tem
= try_window_id (w
)) != 0)
8959 debug_method_add (w
, "try_window_id");
8962 if (fonts_changed_p
)
8963 goto restore_buffers
;
8966 /* Otherwise try_window_id has returned -1 which means that we
8967 don't want the alternative below this comment to execute. */
8969 else if (CHARPOS (startp
) >= BEGV
8970 && CHARPOS (startp
) <= ZV
8971 && PT
>= CHARPOS (startp
)
8972 && (CHARPOS (startp
) < ZV
8973 /* Avoid starting at end of buffer. */
8974 || CHARPOS (startp
) == BEGV
8975 || (XFASTINT (w
->last_modified
) >= MODIFF
8976 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8979 debug_method_add (w
, "same window start");
8982 /* Try to redisplay starting at same place as before.
8983 If point has not moved off frame, accept the results. */
8984 if (!current_matrix_up_to_date_p
8985 /* Don't use try_window_reusing_current_matrix in this case
8986 because a window scroll function can have changed the
8988 || !NILP (Vwindow_scroll_functions
)
8989 || MINI_WINDOW_P (w
)
8990 || !try_window_reusing_current_matrix (w
))
8992 IF_DEBUG (debug_method_add (w
, "1"));
8993 try_window (window
, startp
);
8996 if (fonts_changed_p
)
8997 goto restore_buffers
;
8999 if (w
->cursor
.vpos
>= 0)
9001 if (!just_this_one_p
9002 || current_buffer
->clip_changed
9003 || BEG_UNCHANGED
< CHARPOS (startp
))
9004 /* Forget any recorded base line for line number display. */
9005 w
->base_line_number
= Qnil
;
9007 make_cursor_line_fully_visible (w
);
9011 clear_glyph_matrix (w
->desired_matrix
);
9016 XSETFASTINT (w
->last_modified
, 0);
9017 XSETFASTINT (w
->last_overlay_modified
, 0);
9019 /* Redisplay the mode line. Select the buffer properly for that. */
9020 if (!update_mode_line
)
9022 if (!really_switched_buffer
)
9024 set_buffer_temp (old
);
9025 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9026 really_switched_buffer
= 1;
9028 update_mode_line
= 1;
9029 w
->update_mode_line
= Qt
;
9032 /* Try to scroll by specified few lines. */
9033 if ((scroll_conservatively
9036 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9037 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9038 && !current_buffer
->clip_changed
9039 && CHARPOS (startp
) >= BEGV
9040 && CHARPOS (startp
) <= ZV
)
9042 /* The function returns -1 if new fonts were loaded, 1 if
9043 successful, 0 if not successful. */
9044 int rc
= try_scrolling (window
, just_this_one_p
,
9045 scroll_conservatively
,
9051 goto restore_buffers
;
9054 /* Finally, just choose place to start which centers point */
9059 debug_method_add (w
, "recenter");
9062 /* w->vscroll = 0; */
9064 /* Forget any previously recorded base line for line number display. */
9065 if (!current_matrix_up_to_date_p
9066 || current_buffer
->clip_changed
)
9067 w
->base_line_number
= Qnil
;
9069 /* Move backward half the height of the window. */
9070 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9071 it
.current_y
= it
.last_visible_y
;
9072 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9073 xassert (IT_CHARPOS (it
) >= BEGV
);
9075 /* The function move_it_vertically_backward may move over more
9076 than the specified y-distance. If it->w is small, e.g. a
9077 mini-buffer window, we may end up in front of the window's
9078 display area. Start displaying at the start of the line
9079 containing PT in this case. */
9080 if (it
.current_y
<= 0)
9082 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9083 move_it_vertically (&it
, 0);
9084 xassert (IT_CHARPOS (it
) <= PT
);
9088 it
.current_x
= it
.hpos
= 0;
9090 /* Set startp here explicitly in case that helps avoid an infinite loop
9091 in case the window-scroll-functions functions get errors. */
9092 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9094 /* Run scroll hooks. */
9095 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9097 /* Redisplay the window. */
9098 if (!current_matrix_up_to_date_p
9099 || windows_or_buffers_changed
9100 /* Don't use try_window_reusing_current_matrix in this case
9101 because it can have changed the buffer. */
9102 || !NILP (Vwindow_scroll_functions
)
9104 || MINI_WINDOW_P (w
)
9105 || !try_window_reusing_current_matrix (w
))
9106 try_window (window
, startp
);
9108 /* If new fonts have been loaded (due to fontsets), give up. We
9109 have to start a new redisplay since we need to re-adjust glyph
9111 if (fonts_changed_p
)
9112 goto restore_buffers
;
9114 /* If cursor did not appear assume that the middle of the window is
9115 in the first line of the window. Do it again with the next line.
9116 (Imagine a window of height 100, displaying two lines of height
9117 60. Moving back 50 from it->last_visible_y will end in the first
9119 if (w
->cursor
.vpos
< 0)
9121 if (!NILP (w
->window_end_valid
)
9122 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9124 clear_glyph_matrix (w
->desired_matrix
);
9125 move_it_by_lines (&it
, 1, 0);
9126 try_window (window
, it
.current
.pos
);
9128 else if (PT
< IT_CHARPOS (it
))
9130 clear_glyph_matrix (w
->desired_matrix
);
9131 move_it_by_lines (&it
, -1, 0);
9132 try_window (window
, it
.current
.pos
);
9136 /* Not much we can do about it. */
9140 /* Consider the following case: Window starts at BEGV, there is
9141 invisible, intangible text at BEGV, so that display starts at
9142 some point START > BEGV. It can happen that we are called with
9143 PT somewhere between BEGV and START. Try to handle that case. */
9144 if (w
->cursor
.vpos
< 0)
9146 struct glyph_row
*row
= w
->current_matrix
->rows
;
9147 if (row
->mode_line_p
)
9149 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9152 make_cursor_line_fully_visible (w
);
9156 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9157 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9158 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9161 /* Display the mode line, if we must. */
9162 if ((update_mode_line
9163 /* If window not full width, must redo its mode line
9164 if (a) the window to its side is being redone and
9165 (b) we do a frame-based redisplay. This is a consequence
9166 of how inverted lines are drawn in frame-based redisplay. */
9167 || (!just_this_one_p
9168 && !FRAME_WINDOW_P (f
)
9169 && !WINDOW_FULL_WIDTH_P (w
))
9170 /* Line number to display. */
9171 || INTEGERP (w
->base_line_pos
)
9172 /* Column number is displayed and different from the one displayed. */
9173 || (!NILP (w
->column_number_displayed
)
9174 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9175 /* This means that the window has a mode line. */
9176 && (WINDOW_WANTS_MODELINE_P (w
)
9177 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9179 display_mode_lines (w
);
9181 /* If mode line height has changed, arrange for a thorough
9182 immediate redisplay using the correct mode line height. */
9183 if (WINDOW_WANTS_MODELINE_P (w
)
9184 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9186 fonts_changed_p
= 1;
9187 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9188 = DESIRED_MODE_LINE_HEIGHT (w
);
9191 /* If top line height has changed, arrange for a thorough
9192 immediate redisplay using the correct mode line height. */
9193 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9194 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9196 fonts_changed_p
= 1;
9197 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9198 = DESIRED_HEADER_LINE_HEIGHT (w
);
9201 if (fonts_changed_p
)
9202 goto restore_buffers
;
9205 if (!line_number_displayed
9206 && !BUFFERP (w
->base_line_pos
))
9208 w
->base_line_pos
= Qnil
;
9209 w
->base_line_number
= Qnil
;
9214 /* When we reach a frame's selected window, redo the frame's menu bar. */
9215 if (update_mode_line
9216 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9218 int redisplay_menu_p
= 0;
9220 if (FRAME_WINDOW_P (f
))
9222 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
9223 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9225 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9229 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9231 if (redisplay_menu_p
)
9232 display_menu_bar (w
);
9234 #ifdef HAVE_WINDOW_SYSTEM
9235 if (WINDOWP (f
->tool_bar_window
)
9236 && (FRAME_TOOL_BAR_LINES (f
) > 0
9237 || auto_resize_tool_bars_p
))
9238 redisplay_tool_bar (f
);
9244 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9246 int start
, end
, whole
;
9248 /* Calculate the start and end positions for the current window.
9249 At some point, it would be nice to choose between scrollbars
9250 which reflect the whole buffer size, with special markers
9251 indicating narrowing, and scrollbars which reflect only the
9254 Note that mini-buffers sometimes aren't displaying any text. */
9255 if (!MINI_WINDOW_P (w
)
9256 || (w
== XWINDOW (minibuf_window
)
9257 && NILP (echo_area_buffer
[0])))
9260 start
= marker_position (w
->start
) - BEGV
;
9261 /* I don't think this is guaranteed to be right. For the
9262 moment, we'll pretend it is. */
9263 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9267 if (whole
< (end
- start
))
9268 whole
= end
- start
;
9271 start
= end
= whole
= 0;
9273 /* Indicate what this scroll bar ought to be displaying now. */
9274 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9276 /* Note that we actually used the scroll bar attached to this
9277 window, so it shouldn't be deleted at the end of redisplay. */
9278 (*redeem_scroll_bar_hook
) (w
);
9283 /* Restore current_buffer and value of point in it. */
9284 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9285 if (really_switched_buffer
)
9286 set_buffer_internal_1 (old
);
9288 set_buffer_temp (old
);
9289 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9291 unbind_to (count
, Qnil
);
9295 /* Build the complete desired matrix of WINDOW with a window start
9296 buffer position POS. Value is non-zero if successful. It is zero
9297 if fonts were loaded during redisplay which makes re-adjusting
9298 glyph matrices necessary. */
9301 try_window (window
, pos
)
9303 struct text_pos pos
;
9305 struct window
*w
= XWINDOW (window
);
9307 struct glyph_row
*last_text_row
= NULL
;
9309 /* Make POS the new window start. */
9310 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9312 /* Mark cursor position as unknown. No overlay arrow seen. */
9313 w
->cursor
.vpos
= -1;
9314 overlay_arrow_seen
= 0;
9316 /* Initialize iterator and info to start at POS. */
9317 start_display (&it
, w
, pos
);
9319 /* Display all lines of W. */
9320 while (it
.current_y
< it
.last_visible_y
)
9322 if (display_line (&it
))
9323 last_text_row
= it
.glyph_row
- 1;
9324 if (fonts_changed_p
)
9328 /* If bottom moved off end of frame, change mode line percentage. */
9329 if (XFASTINT (w
->window_end_pos
) <= 0
9330 && Z
!= IT_CHARPOS (it
))
9331 w
->update_mode_line
= Qt
;
9333 /* Set window_end_pos to the offset of the last character displayed
9334 on the window from the end of current_buffer. Set
9335 window_end_vpos to its row number. */
9338 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9339 w
->window_end_bytepos
9340 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9341 XSETFASTINT (w
->window_end_pos
,
9342 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9343 XSETFASTINT (w
->window_end_vpos
,
9344 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9345 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9350 w
->window_end_bytepos
= 0;
9351 XSETFASTINT (w
->window_end_pos
, 0);
9352 XSETFASTINT (w
->window_end_vpos
, 0);
9355 /* But that is not valid info until redisplay finishes. */
9356 w
->window_end_valid
= Qnil
;
9362 /************************************************************************
9363 Window redisplay reusing current matrix when buffer has not changed
9364 ************************************************************************/
9366 /* Try redisplay of window W showing an unchanged buffer with a
9367 different window start than the last time it was displayed by
9368 reusing its current matrix. Value is non-zero if successful.
9369 W->start is the new window start. */
9372 try_window_reusing_current_matrix (w
)
9375 struct frame
*f
= XFRAME (w
->frame
);
9376 struct glyph_row
*row
, *bottom_row
;
9379 struct text_pos start
, new_start
;
9380 int nrows_scrolled
, i
;
9381 struct glyph_row
*last_text_row
;
9382 struct glyph_row
*last_reused_text_row
;
9383 struct glyph_row
*start_row
;
9384 int start_vpos
, min_y
, max_y
;
9386 /* Right now this function doesn't handle terminal frames. */
9387 if (!FRAME_WINDOW_P (f
))
9390 /* Can't do this if region may have changed. */
9391 if ((!NILP (Vtransient_mark_mode
)
9392 && !NILP (current_buffer
->mark_active
))
9393 || !NILP (w
->region_showing
)
9394 || !NILP (Vshow_trailing_whitespace
))
9397 /* If top-line visibility has changed, give up. */
9398 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9399 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9402 /* Give up if old or new display is scrolled vertically. We could
9403 make this function handle this, but right now it doesn't. */
9404 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9405 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9408 /* The variable new_start now holds the new window start. The old
9409 start `start' can be determined from the current matrix. */
9410 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9411 start
= start_row
->start
.pos
;
9412 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9414 /* Clear the desired matrix for the display below. */
9415 clear_glyph_matrix (w
->desired_matrix
);
9417 if (CHARPOS (new_start
) <= CHARPOS (start
))
9421 IF_DEBUG (debug_method_add (w
, "twu1"));
9423 /* Display up to a row that can be reused. The variable
9424 last_text_row is set to the last row displayed that displays
9426 start_display (&it
, w
, new_start
);
9427 first_row_y
= it
.current_y
;
9428 w
->cursor
.vpos
= -1;
9429 last_text_row
= last_reused_text_row
= NULL
;
9430 while (it
.current_y
< it
.last_visible_y
9431 && IT_CHARPOS (it
) < CHARPOS (start
)
9432 && !fonts_changed_p
)
9433 if (display_line (&it
))
9434 last_text_row
= it
.glyph_row
- 1;
9436 /* A value of current_y < last_visible_y means that we stopped
9437 at the previous window start, which in turn means that we
9438 have at least one reusable row. */
9439 if (it
.current_y
< it
.last_visible_y
)
9441 nrows_scrolled
= it
.vpos
;
9443 /* Find PT if not already found in the lines displayed. */
9444 if (w
->cursor
.vpos
< 0)
9446 int dy
= it
.current_y
- first_row_y
;
9448 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9449 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9451 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9452 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9454 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9455 dy
, nrows_scrolled
);
9459 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9465 /* Give up if point was not found. This shouldn't
9466 happen often; not more often than with try_window
9468 if (w
->cursor
.vpos
< 0)
9470 clear_glyph_matrix (w
->desired_matrix
);
9475 /* Scroll the display. Do it before the current matrix is
9476 changed. The problem here is that update has not yet
9477 run, i.e. part of the current matrix is not up to date.
9478 scroll_run_hook will clear the cursor, and use the
9479 current matrix to get the height of the row the cursor is
9481 run
.current_y
= first_row_y
;
9482 run
.desired_y
= it
.current_y
;
9483 run
.height
= it
.last_visible_y
- it
.current_y
;
9485 && run
.current_y
!= run
.desired_y
)
9488 rif
->update_window_begin_hook (w
);
9489 rif
->scroll_run_hook (w
, &run
);
9490 rif
->update_window_end_hook (w
, 0);
9494 /* Shift current matrix down by nrows_scrolled lines. */
9495 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9496 rotate_matrix (w
->current_matrix
,
9498 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9501 /* Disable lines not reused. */
9502 for (i
= 0; i
< it
.vpos
; ++i
)
9503 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9505 /* Re-compute Y positions. */
9506 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9507 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9508 max_y
= it
.last_visible_y
;
9509 while (row
< bottom_row
)
9511 row
->y
= it
.current_y
;
9514 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9515 else if (row
->y
+ row
->height
> max_y
)
9517 = row
->height
- (row
->y
+ row
->height
- max_y
);
9519 row
->visible_height
= row
->height
;
9521 it
.current_y
+= row
->height
;
9524 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9525 last_reused_text_row
= row
;
9526 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9532 /* Update window_end_pos etc.; last_reused_text_row is the last
9533 reused row from the current matrix containing text, if any.
9534 The value of last_text_row is the last displayed line
9536 if (last_reused_text_row
)
9538 w
->window_end_bytepos
9539 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9540 XSETFASTINT (w
->window_end_pos
,
9541 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9542 XSETFASTINT (w
->window_end_vpos
,
9543 MATRIX_ROW_VPOS (last_reused_text_row
,
9544 w
->current_matrix
));
9546 else if (last_text_row
)
9548 w
->window_end_bytepos
9549 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9550 XSETFASTINT (w
->window_end_pos
,
9551 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9552 XSETFASTINT (w
->window_end_vpos
,
9553 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9557 /* This window must be completely empty. */
9558 w
->window_end_bytepos
= 0;
9559 XSETFASTINT (w
->window_end_pos
, 0);
9560 XSETFASTINT (w
->window_end_vpos
, 0);
9562 w
->window_end_valid
= Qnil
;
9564 /* Update hint: don't try scrolling again in update_window. */
9565 w
->desired_matrix
->no_scrolling_p
= 1;
9568 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9572 else if (CHARPOS (new_start
) > CHARPOS (start
))
9574 struct glyph_row
*pt_row
, *row
;
9575 struct glyph_row
*first_reusable_row
;
9576 struct glyph_row
*first_row_to_display
;
9578 int yb
= window_text_bottom_y (w
);
9580 IF_DEBUG (debug_method_add (w
, "twu2"));
9582 /* Find the row starting at new_start, if there is one. Don't
9583 reuse a partially visible line at the end. */
9584 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9585 while (first_reusable_row
->enabled_p
9586 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9587 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9588 < CHARPOS (new_start
)))
9589 ++first_reusable_row
;
9591 /* Give up if there is no row to reuse. */
9592 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9593 || !first_reusable_row
->enabled_p
9594 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9595 != CHARPOS (new_start
)))
9598 /* We can reuse fully visible rows beginning with
9599 first_reusable_row to the end of the window. Set
9600 first_row_to_display to the first row that cannot be reused.
9601 Set pt_row to the row containing point, if there is any. */
9602 first_row_to_display
= first_reusable_row
;
9604 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9606 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9607 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9608 pt_row
= first_row_to_display
;
9610 ++first_row_to_display
;
9613 /* Start displaying at the start of first_row_to_display. */
9614 xassert (first_row_to_display
->y
< yb
);
9615 init_to_row_start (&it
, w
, first_row_to_display
);
9616 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9617 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9619 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9621 /* Display lines beginning with first_row_to_display in the
9622 desired matrix. Set last_text_row to the last row displayed
9623 that displays text. */
9624 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9626 w
->cursor
.vpos
= -1;
9627 last_text_row
= NULL
;
9628 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9629 if (display_line (&it
))
9630 last_text_row
= it
.glyph_row
- 1;
9632 /* Give up If point isn't in a row displayed or reused. */
9633 if (w
->cursor
.vpos
< 0)
9635 clear_glyph_matrix (w
->desired_matrix
);
9639 /* If point is in a reused row, adjust y and vpos of the cursor
9643 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
9645 w
->cursor
.y
-= first_reusable_row
->y
;
9648 /* Scroll the display. */
9649 run
.current_y
= first_reusable_row
->y
;
9650 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9651 run
.height
= it
.last_visible_y
- run
.current_y
;
9654 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9656 rif
->update_window_begin_hook (w
);
9657 rif
->scroll_run_hook (w
, &run
);
9658 rif
->update_window_end_hook (w
, 0);
9662 /* Adjust Y positions of reused rows. */
9663 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9664 row
= first_reusable_row
;
9665 dy
= first_reusable_row
->y
;
9666 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9667 max_y
= it
.last_visible_y
;
9668 while (row
< first_row_to_display
)
9672 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9673 else if (row
->y
+ row
->height
> max_y
)
9675 = row
->height
- (row
->y
+ row
->height
- max_y
);
9677 row
->visible_height
= row
->height
;
9681 /* Disable rows not reused. */
9682 while (row
< bottom_row
)
9688 /* Scroll the current matrix. */
9689 xassert (nrows_scrolled
> 0);
9690 rotate_matrix (w
->current_matrix
,
9692 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9695 /* Adjust window end. A null value of last_text_row means that
9696 the window end is in reused rows which in turn means that
9697 only its vpos can have changed. */
9700 w
->window_end_bytepos
9701 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9702 XSETFASTINT (w
->window_end_pos
,
9703 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9704 XSETFASTINT (w
->window_end_vpos
,
9705 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9709 XSETFASTINT (w
->window_end_vpos
,
9710 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
9713 w
->window_end_valid
= Qnil
;
9714 w
->desired_matrix
->no_scrolling_p
= 1;
9717 debug_method_add (w
, "try_window_reusing_current_matrix 2");
9727 /************************************************************************
9728 Window redisplay reusing current matrix when buffer has changed
9729 ************************************************************************/
9731 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
9732 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
9734 static struct glyph_row
*
9735 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
9736 struct glyph_row
*));
9739 /* Return the last row in MATRIX displaying text. If row START is
9740 non-null, start searching with that row. IT gives the dimensions
9741 of the display. Value is null if matrix is empty; otherwise it is
9742 a pointer to the row found. */
9744 static struct glyph_row
*
9745 find_last_row_displaying_text (matrix
, it
, start
)
9746 struct glyph_matrix
*matrix
;
9748 struct glyph_row
*start
;
9750 struct glyph_row
*row
, *row_found
;
9752 /* Set row_found to the last row in IT->w's current matrix
9753 displaying text. The loop looks funny but think of partially
9756 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
9757 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9759 xassert (row
->enabled_p
);
9761 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
9770 /* Return the last row in the current matrix of W that is not affected
9771 by changes at the start of current_buffer that occurred since the
9772 last time W was redisplayed. Value is null if no such row exists.
9774 The global variable beg_unchanged has to contain the number of
9775 bytes unchanged at the start of current_buffer. BEG +
9776 beg_unchanged is the buffer position of the first changed byte in
9777 current_buffer. Characters at positions < BEG + beg_unchanged are
9778 at the same buffer positions as they were when the current matrix
9781 static struct glyph_row
*
9782 get_last_unchanged_at_beg_row (w
)
9785 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
9786 struct glyph_row
*row
;
9787 struct glyph_row
*row_found
= NULL
;
9788 int yb
= window_text_bottom_y (w
);
9790 /* Find the last row displaying unchanged text. */
9791 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9792 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
9793 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
9795 if (/* If row ends before first_changed_pos, it is unchanged,
9796 except in some case. */
9797 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
9798 /* When row ends in ZV and we write at ZV it is not
9800 && !row
->ends_at_zv_p
9801 /* When first_changed_pos is the end of a continued line,
9802 row is not unchanged because it may be no longer
9804 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
9805 && row
->continued_p
))
9808 /* Stop if last visible row. */
9809 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
9819 /* Find the first glyph row in the current matrix of W that is not
9820 affected by changes at the end of current_buffer since the last
9821 time the window was redisplayed. Return in *DELTA the number of
9822 chars by which buffer positions in unchanged text at the end of
9823 current_buffer must be adjusted. Return in *DELTA_BYTES the
9824 corresponding number of bytes. Value is null if no such row
9825 exists, i.e. all rows are affected by changes. */
9827 static struct glyph_row
*
9828 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
9830 int *delta
, *delta_bytes
;
9832 struct glyph_row
*row
;
9833 struct glyph_row
*row_found
= NULL
;
9835 *delta
= *delta_bytes
= 0;
9837 /* A value of window_end_pos >= end_unchanged means that the window
9838 end is in the range of changed text. If so, there is no
9839 unchanged row at the end of W's current matrix. */
9840 xassert (!NILP (w
->window_end_valid
));
9841 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
9844 /* Set row to the last row in W's current matrix displaying text. */
9845 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9847 /* If matrix is entirely empty, no unchanged row exists. */
9848 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9850 /* The value of row is the last glyph row in the matrix having a
9851 meaningful buffer position in it. The end position of row
9852 corresponds to window_end_pos. This allows us to translate
9853 buffer positions in the current matrix to current buffer
9854 positions for characters not in changed text. */
9855 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
9856 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
9857 int last_unchanged_pos
, last_unchanged_pos_old
;
9858 struct glyph_row
*first_text_row
9859 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9862 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
9864 /* Set last_unchanged_pos to the buffer position of the last
9865 character in the buffer that has not been changed. Z is the
9866 index + 1 of the last byte in current_buffer, i.e. by
9867 subtracting end_unchanged we get the index of the last
9868 unchanged character, and we have to add BEG to get its buffer
9870 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
9871 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
9873 /* Search backward from ROW for a row displaying a line that
9874 starts at a minimum position >= last_unchanged_pos_old. */
9875 while (row
>= first_text_row
)
9877 xassert (row
->enabled_p
);
9878 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9880 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
9886 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
9891 /* Make sure that glyph rows in the current matrix of window W
9892 reference the same glyph memory as corresponding rows in the
9893 frame's frame matrix. This function is called after scrolling W's
9894 current matrix on a terminal frame in try_window_id and
9895 try_window_reusing_current_matrix. */
9898 sync_frame_with_window_matrix_rows (w
)
9901 struct frame
*f
= XFRAME (w
->frame
);
9902 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
9904 /* Preconditions: W must be a leaf window and full-width. Its frame
9905 must have a frame matrix. */
9906 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9907 xassert (WINDOW_FULL_WIDTH_P (w
));
9908 xassert (!FRAME_WINDOW_P (f
));
9910 /* If W is a full-width window, glyph pointers in W's current matrix
9911 have, by definition, to be the same as glyph pointers in the
9912 corresponding frame matrix. */
9913 window_row
= w
->current_matrix
->rows
;
9914 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9915 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9916 while (window_row
< window_row_end
)
9920 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9921 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9923 /* Disable frame rows whose corresponding window rows have
9924 been disabled in try_window_id. */
9925 if (!window_row
->enabled_p
)
9926 frame_row
->enabled_p
= 0;
9928 ++window_row
, ++frame_row
;
9933 /* Find the glyph row in window W containing CHARPOS. Consider all
9934 rows between START and END (not inclusive). END null means search
9935 all rows to the end of the display area of W. Value is the row
9936 containing CHARPOS or null. */
9938 static struct glyph_row
*
9939 row_containing_pos (w
, charpos
, start
, end
)
9942 struct glyph_row
*start
, *end
;
9944 struct glyph_row
*row
= start
;
9947 /* If we happen to start on a header-line, skip that. */
9948 if (row
->mode_line_p
)
9951 if ((end
&& row
>= end
) || !row
->enabled_p
)
9954 last_y
= window_text_bottom_y (w
);
9956 while ((end
== NULL
|| row
< end
)
9957 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
9958 /* The end position of a row equals the start
9959 position of the next row. If CHARPOS is there, we
9960 would rather display it in the next line, except
9961 when this line ends in ZV. */
9962 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
9963 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
9964 || !row
->ends_at_zv_p
)))
9965 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9968 /* Give up if CHARPOS not found. */
9969 if ((end
&& row
>= end
)
9970 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
9971 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
9978 /* Try to redisplay window W by reusing its existing display. W's
9979 current matrix must be up to date when this function is called,
9980 i.e. window_end_valid must not be nil.
9984 1 if display has been updated
9985 0 if otherwise unsuccessful
9986 -1 if redisplay with same window start is known not to succeed
9988 The following steps are performed:
9990 1. Find the last row in the current matrix of W that is not
9991 affected by changes at the start of current_buffer. If no such row
9994 2. Find the first row in W's current matrix that is not affected by
9995 changes at the end of current_buffer. Maybe there is no such row.
9997 3. Display lines beginning with the row + 1 found in step 1 to the
9998 row found in step 2 or, if step 2 didn't find a row, to the end of
10001 4. If cursor is not known to appear on the window, give up.
10003 5. If display stopped at the row found in step 2, scroll the
10004 display and current matrix as needed.
10006 6. Maybe display some lines at the end of W, if we must. This can
10007 happen under various circumstances, like a partially visible line
10008 becoming fully visible, or because newly displayed lines are displayed
10009 in smaller font sizes.
10011 7. Update W's window end information. */
10013 /* Check that window end is what we expect it to be. */
10019 struct frame
*f
= XFRAME (w
->frame
);
10020 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10021 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10022 struct glyph_row
*last_unchanged_at_beg_row
;
10023 struct glyph_row
*first_unchanged_at_end_row
;
10024 struct glyph_row
*row
;
10025 struct glyph_row
*bottom_row
;
10028 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10029 struct text_pos start_pos
;
10031 int first_unchanged_at_end_vpos
= 0;
10032 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10033 struct text_pos start
;
10035 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10037 /* Check pre-conditions. Window end must be valid, otherwise
10038 the current matrix would not be up to date. */
10039 xassert (!NILP (w
->window_end_valid
));
10040 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10041 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10043 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10044 only if buffer has really changed. The reason is that the gap is
10045 initially at Z for freshly visited files. The code below would
10046 set end_unchanged to 0 in that case. */
10047 if (MODIFF
> SAVE_MODIFF
10048 /* This seems to happen sometimes after saving a buffer. */
10049 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10051 if (GPT
- BEG
< BEG_UNCHANGED
)
10052 BEG_UNCHANGED
= GPT
- BEG
;
10053 if (Z
- GPT
< END_UNCHANGED
)
10054 END_UNCHANGED
= Z
- GPT
;
10057 /* If window starts after a line end, and the last change is in
10058 front of that newline, then changes don't affect the display.
10059 This case happens with stealth-fontification. Note that although
10060 the display is unchanged, glyph positions in the matrix have to
10061 be adjusted, of course. */
10062 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10063 if (CHARPOS (start
) > BEGV
10064 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10065 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10066 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10068 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10069 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10073 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10074 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10076 increment_matrix_positions (w
->current_matrix
,
10077 MATRIX_ROW_VPOS (r0
, current_matrix
),
10078 MATRIX_ROW_VPOS (r1
, current_matrix
),
10079 delta
, delta_bytes
);
10082 #if 0 /* If changes are all in front of the window start, the
10083 distance of the last displayed glyph from Z hasn't
10086 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10087 w
->window_end_bytepos
10088 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10094 /* Return quickly if changes are all below what is displayed in the
10095 window, and if PT is in the window. */
10096 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10097 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10099 /* We have to update window end positions because the buffer's
10100 size has changed. */
10102 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10103 w
->window_end_bytepos
10104 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10108 /* Check that window start agrees with the start of the first glyph
10109 row in its current matrix. Check this after we know the window
10110 start is not in changed text, otherwise positions would not be
10112 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10113 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10116 /* Compute the position at which we have to start displaying new
10117 lines. Some of the lines at the top of the window might be
10118 reusable because they are not displaying changed text. Find the
10119 last row in W's current matrix not affected by changes at the
10120 start of current_buffer. Value is null if changes start in the
10121 first line of window. */
10122 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
10123 if (last_unchanged_at_beg_row
)
10125 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10126 start_pos
= it
.current
.pos
;
10128 /* Start displaying new lines in the desired matrix at the same
10129 vpos we would use in the current matrix, i.e. below
10130 last_unchanged_at_beg_row. */
10131 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10133 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10134 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10136 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10140 /* There are no reusable lines at the start of the window.
10141 Start displaying in the first line. */
10142 start_display (&it
, w
, start
);
10143 start_pos
= it
.current
.pos
;
10146 /* Find the first row that is not affected by changes at the end of
10147 the buffer. Value will be null if there is no unchanged row, in
10148 which case we must redisplay to the end of the window. delta
10149 will be set to the value by which buffer positions beginning with
10150 first_unchanged_at_end_row have to be adjusted due to text
10152 first_unchanged_at_end_row
10153 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10154 IF_DEBUG (debug_delta
= delta
);
10155 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10157 /* Set stop_pos to the buffer position up to which we will have to
10158 display new lines. If first_unchanged_at_end_row != NULL, this
10159 is the buffer position of the start of the line displayed in that
10160 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10161 that we don't stop at a buffer position. */
10163 if (first_unchanged_at_end_row
)
10165 xassert (last_unchanged_at_beg_row
== NULL
10166 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10168 /* If this is a continuation line, move forward to the next one
10169 that isn't. Changes in lines above affect this line.
10170 Caution: this may move first_unchanged_at_end_row to a row
10171 not displaying text. */
10172 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10173 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10174 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10175 < it
.last_visible_y
))
10176 ++first_unchanged_at_end_row
;
10178 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10179 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10180 >= it
.last_visible_y
))
10181 first_unchanged_at_end_row
= NULL
;
10184 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10186 first_unchanged_at_end_vpos
10187 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10188 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10191 else if (last_unchanged_at_beg_row
== NULL
)
10197 /* Either there is no unchanged row at the end, or the one we have
10198 now displays text. This is a necessary condition for the window
10199 end pos calculation at the end of this function. */
10200 xassert (first_unchanged_at_end_row
== NULL
10201 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10203 debug_last_unchanged_at_beg_vpos
10204 = (last_unchanged_at_beg_row
10205 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10207 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10209 #endif /* GLYPH_DEBUG != 0 */
10212 /* Display new lines. Set last_text_row to the last new line
10213 displayed which has text on it, i.e. might end up as being the
10214 line where the window_end_vpos is. */
10215 w
->cursor
.vpos
= -1;
10216 last_text_row
= NULL
;
10217 overlay_arrow_seen
= 0;
10218 while (it
.current_y
< it
.last_visible_y
10219 && !fonts_changed_p
10220 && (first_unchanged_at_end_row
== NULL
10221 || IT_CHARPOS (it
) < stop_pos
))
10223 if (display_line (&it
))
10224 last_text_row
= it
.glyph_row
- 1;
10227 if (fonts_changed_p
)
10231 /* Compute differences in buffer positions, y-positions etc. for
10232 lines reused at the bottom of the window. Compute what we can
10234 if (first_unchanged_at_end_row
10235 /* No lines reused because we displayed everything up to the
10236 bottom of the window. */
10237 && it
.current_y
< it
.last_visible_y
)
10240 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10242 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10243 run
.current_y
= first_unchanged_at_end_row
->y
;
10244 run
.desired_y
= run
.current_y
+ dy
;
10245 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10249 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10250 first_unchanged_at_end_row
= NULL
;
10252 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10255 /* Find the cursor if not already found. We have to decide whether
10256 PT will appear on this window (it sometimes doesn't, but this is
10257 not a very frequent case.) This decision has to be made before
10258 the current matrix is altered. A value of cursor.vpos < 0 means
10259 that PT is either in one of the lines beginning at
10260 first_unchanged_at_end_row or below the window. Don't care for
10261 lines that might be displayed later at the window end; as
10262 mentioned, this is not a frequent case. */
10263 if (w
->cursor
.vpos
< 0)
10265 /* Cursor in unchanged rows at the top? */
10266 if (PT
< CHARPOS (start_pos
)
10267 && last_unchanged_at_beg_row
)
10269 row
= row_containing_pos (w
, PT
,
10270 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10271 last_unchanged_at_beg_row
+ 1);
10272 xassert (row
&& row
<= last_unchanged_at_beg_row
);
10273 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10276 /* Start from first_unchanged_at_end_row looking for PT. */
10277 else if (first_unchanged_at_end_row
)
10279 row
= row_containing_pos (w
, PT
- delta
,
10280 first_unchanged_at_end_row
, NULL
);
10282 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10283 delta_bytes
, dy
, dvpos
);
10286 /* Give up if cursor was not found. */
10287 if (w
->cursor
.vpos
< 0)
10289 clear_glyph_matrix (w
->desired_matrix
);
10294 /* Don't let the cursor end in the scroll margins. */
10296 int this_scroll_margin
, cursor_height
;
10298 this_scroll_margin
= max (0, scroll_margin
);
10299 this_scroll_margin
= min (this_scroll_margin
,
10300 XFASTINT (w
->height
) / 4);
10301 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10302 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10304 if ((w
->cursor
.y
< this_scroll_margin
10305 && CHARPOS (start
) > BEGV
)
10306 /* Don't take scroll margin into account at the bottom because
10307 old redisplay didn't do it either. */
10308 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10310 w
->cursor
.vpos
= -1;
10311 clear_glyph_matrix (w
->desired_matrix
);
10316 /* Scroll the display. Do it before changing the current matrix so
10317 that xterm.c doesn't get confused about where the cursor glyph is
10319 if (dy
&& run
.height
)
10323 if (FRAME_WINDOW_P (f
))
10325 rif
->update_window_begin_hook (w
);
10326 rif
->scroll_run_hook (w
, &run
);
10327 rif
->update_window_end_hook (w
, 0);
10331 /* Terminal frame. In this case, dvpos gives the number of
10332 lines to scroll by; dvpos < 0 means scroll up. */
10333 int first_unchanged_at_end_vpos
10334 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10335 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10336 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10338 /* Perform the operation on the screen. */
10341 /* Scroll last_unchanged_at_beg_row to the end of the
10342 window down dvpos lines. */
10343 set_terminal_window (end
);
10345 /* On dumb terminals delete dvpos lines at the end
10346 before inserting dvpos empty lines. */
10347 if (!scroll_region_ok
)
10348 ins_del_lines (end
- dvpos
, -dvpos
);
10350 /* Insert dvpos empty lines in front of
10351 last_unchanged_at_beg_row. */
10352 ins_del_lines (from
, dvpos
);
10354 else if (dvpos
< 0)
10356 /* Scroll up last_unchanged_at_beg_vpos to the end of
10357 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10358 set_terminal_window (end
);
10360 /* Delete dvpos lines in front of
10361 last_unchanged_at_beg_vpos. ins_del_lines will set
10362 the cursor to the given vpos and emit |dvpos| delete
10364 ins_del_lines (from
+ dvpos
, dvpos
);
10366 /* On a dumb terminal insert dvpos empty lines at the
10368 if (!scroll_region_ok
)
10369 ins_del_lines (end
+ dvpos
, -dvpos
);
10372 set_terminal_window (0);
10378 /* Shift reused rows of the current matrix to the right position.
10379 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10381 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10382 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10385 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10386 bottom_vpos
, dvpos
);
10387 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10390 else if (dvpos
> 0)
10392 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10393 bottom_vpos
, dvpos
);
10394 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10395 first_unchanged_at_end_vpos
+ dvpos
, 0);
10398 /* For frame-based redisplay, make sure that current frame and window
10399 matrix are in sync with respect to glyph memory. */
10400 if (!FRAME_WINDOW_P (f
))
10401 sync_frame_with_window_matrix_rows (w
);
10403 /* Adjust buffer positions in reused rows. */
10405 increment_matrix_positions (current_matrix
,
10406 first_unchanged_at_end_vpos
+ dvpos
,
10407 bottom_vpos
, delta
, delta_bytes
);
10409 /* Adjust Y positions. */
10411 shift_glyph_matrix (w
, current_matrix
,
10412 first_unchanged_at_end_vpos
+ dvpos
,
10415 if (first_unchanged_at_end_row
)
10416 first_unchanged_at_end_row
+= dvpos
;
10418 /* If scrolling up, there may be some lines to display at the end of
10420 last_text_row_at_end
= NULL
;
10423 /* Set last_row to the glyph row in the current matrix where the
10424 window end line is found. It has been moved up or down in
10425 the matrix by dvpos. */
10426 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10427 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10429 /* If last_row is the window end line, it should display text. */
10430 xassert (last_row
->displays_text_p
);
10432 /* If window end line was partially visible before, begin
10433 displaying at that line. Otherwise begin displaying with the
10434 line following it. */
10435 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10437 init_to_row_start (&it
, w
, last_row
);
10438 it
.vpos
= last_vpos
;
10439 it
.current_y
= last_row
->y
;
10443 init_to_row_end (&it
, w
, last_row
);
10444 it
.vpos
= 1 + last_vpos
;
10445 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10449 /* We may start in a continuation line. If so, we have to get
10450 the right continuation_lines_width and current_x. */
10451 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10452 it
.hpos
= it
.current_x
= 0;
10454 /* Display the rest of the lines at the window end. */
10455 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10456 while (it
.current_y
< it
.last_visible_y
10457 && !fonts_changed_p
)
10459 /* Is it always sure that the display agrees with lines in
10460 the current matrix? I don't think so, so we mark rows
10461 displayed invalid in the current matrix by setting their
10462 enabled_p flag to zero. */
10463 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10464 if (display_line (&it
))
10465 last_text_row_at_end
= it
.glyph_row
- 1;
10469 /* Update window_end_pos and window_end_vpos. */
10470 if (first_unchanged_at_end_row
10471 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10472 && !last_text_row_at_end
)
10474 /* Window end line if one of the preserved rows from the current
10475 matrix. Set row to the last row displaying text in current
10476 matrix starting at first_unchanged_at_end_row, after
10478 xassert (first_unchanged_at_end_row
->displays_text_p
);
10479 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10480 first_unchanged_at_end_row
);
10481 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10483 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10484 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10485 XSETFASTINT (w
->window_end_vpos
,
10486 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10488 else if (last_text_row_at_end
)
10490 XSETFASTINT (w
->window_end_pos
,
10491 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10492 w
->window_end_bytepos
10493 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10494 XSETFASTINT (w
->window_end_vpos
,
10495 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10497 else if (last_text_row
)
10499 /* We have displayed either to the end of the window or at the
10500 end of the window, i.e. the last row with text is to be found
10501 in the desired matrix. */
10502 XSETFASTINT (w
->window_end_pos
,
10503 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10504 w
->window_end_bytepos
10505 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10506 XSETFASTINT (w
->window_end_vpos
,
10507 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10509 else if (first_unchanged_at_end_row
== NULL
10510 && last_text_row
== NULL
10511 && last_text_row_at_end
== NULL
)
10513 /* Displayed to end of window, but no line containing text was
10514 displayed. Lines were deleted at the end of the window. */
10516 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10518 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10519 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10520 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10521 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10522 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10525 w
->window_end_vpos
= make_number (vpos
);
10530 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10531 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10533 /* Record that display has not been completed. */
10534 w
->window_end_valid
= Qnil
;
10535 w
->desired_matrix
->no_scrolling_p
= 1;
10541 /***********************************************************************
10542 More debugging support
10543 ***********************************************************************/
10547 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10548 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10551 /* Dump the contents of glyph matrix MATRIX on stderr. If
10552 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10555 dump_glyph_matrix (matrix
, with_glyphs_p
)
10556 struct glyph_matrix
*matrix
;
10560 for (i
= 0; i
< matrix
->nrows
; ++i
)
10561 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10565 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10566 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10569 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10570 struct glyph_matrix
*matrix
;
10571 int vpos
, with_glyphs_p
;
10573 struct glyph_row
*row
;
10575 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10578 row
= MATRIX_ROW (matrix
, vpos
);
10580 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
10581 fprintf (stderr
, "=============================================\n");
10583 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d\n",
10584 row
- matrix
->rows
,
10585 MATRIX_ROW_START_CHARPOS (row
),
10586 MATRIX_ROW_END_CHARPOS (row
),
10587 row
->used
[TEXT_AREA
],
10588 row
->contains_overlapping_glyphs_p
,
10591 row
->truncated_on_left_p
,
10592 row
->truncated_on_right_p
,
10593 row
->overlay_arrow_p
,
10595 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10596 row
->displays_text_p
,
10602 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10603 row
->end
.overlay_string_index
);
10604 fprintf (stderr
, "%9d %5d\n",
10605 CHARPOS (row
->start
.string_pos
),
10606 CHARPOS (row
->end
.string_pos
));
10607 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10608 row
->end
.dpvec_index
);
10612 struct glyph
*glyph
, *glyph_end
;
10613 int prev_had_glyphs_p
;
10615 glyph
= row
->glyphs
[TEXT_AREA
];
10616 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10618 /* Glyph for a line end in text. */
10619 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
10622 if (glyph
< glyph_end
)
10624 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
10625 prev_had_glyphs_p
= 1;
10628 prev_had_glyphs_p
= 0;
10630 while (glyph
< glyph_end
)
10632 if (glyph
->type
== CHAR_GLYPH
)
10635 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10636 glyph
- row
->glyphs
[TEXT_AREA
],
10639 glyph
->pixel_width
,
10641 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
10645 glyph
->left_box_line_p
,
10646 glyph
->right_box_line_p
);
10648 else if (glyph
->type
== STRETCH_GLYPH
)
10651 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10652 glyph
- row
->glyphs
[TEXT_AREA
],
10655 glyph
->pixel_width
,
10659 glyph
->left_box_line_p
,
10660 glyph
->right_box_line_p
);
10662 else if (glyph
->type
== IMAGE_GLYPH
)
10665 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10666 glyph
- row
->glyphs
[TEXT_AREA
],
10669 glyph
->pixel_width
,
10673 glyph
->left_box_line_p
,
10674 glyph
->right_box_line_p
);
10682 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
10683 Sdump_glyph_matrix
, 0, 1, "p",
10684 "Dump the current matrix of the selected window to stderr.\n\
10685 Shows contents of glyph row structures. With non-nil optional\n\
10686 parameter WITH-GLYPHS-P, dump glyphs as well.")
10689 struct window
*w
= XWINDOW (selected_window
);
10690 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10692 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
10693 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
10694 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
10695 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
10696 fprintf (stderr
, "=============================================\n");
10697 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
10702 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
10703 "Dump glyph row ROW to stderr.")
10707 CHECK_NUMBER (row
, 0);
10708 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
10713 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
10717 struct frame
*sf
= SELECTED_FRAME ();
10718 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
10720 dump_glyph_row (m
, 0, 1);
10725 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
10726 Strace_redisplay_toggle
, 0, 0, "",
10727 "Toggle tracing of redisplay.")
10730 trace_redisplay_p
= !trace_redisplay_p
;
10735 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
10736 "Print STRING to stderr.")
10738 Lisp_Object string
;
10740 CHECK_STRING (string
, 0);
10741 fprintf (stderr
, "%s", XSTRING (string
)->data
);
10745 #endif /* GLYPH_DEBUG */
10749 /***********************************************************************
10750 Building Desired Matrix Rows
10751 ***********************************************************************/
10753 /* Return a temporary glyph row holding the glyphs of an overlay
10754 arrow. Only used for non-window-redisplay windows. */
10756 static struct glyph_row
*
10757 get_overlay_arrow_glyph_row (w
)
10760 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10761 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10762 struct buffer
*old
= current_buffer
;
10763 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
10764 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
10765 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
10769 int n_glyphs_before
;
10771 set_buffer_temp (buffer
);
10772 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
10773 it
.glyph_row
->used
[TEXT_AREA
] = 0;
10774 SET_TEXT_POS (it
.position
, 0, 0);
10776 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
10778 while (p
< arrow_end
)
10780 Lisp_Object face
, ilisp
;
10782 /* Get the next character. */
10784 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
10786 it
.c
= *p
, it
.len
= 1;
10789 /* Get its face. */
10790 XSETFASTINT (ilisp
, p
- arrow_string
);
10791 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
10792 it
.face_id
= compute_char_face (f
, it
.c
, face
);
10794 /* Compute its width, get its glyphs. */
10795 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
10796 SET_TEXT_POS (it
.position
, -1, -1);
10797 PRODUCE_GLYPHS (&it
);
10799 /* If this character doesn't fit any more in the line, we have
10800 to remove some glyphs. */
10801 if (it
.current_x
> it
.last_visible_x
)
10803 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
10808 set_buffer_temp (old
);
10809 return it
.glyph_row
;
10813 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
10814 glyphs are only inserted for terminal frames since we can't really
10815 win with truncation glyphs when partially visible glyphs are
10816 involved. Which glyphs to insert is determined by
10817 produce_special_glyphs. */
10820 insert_left_trunc_glyphs (it
)
10823 struct it truncate_it
;
10824 struct glyph
*from
, *end
, *to
, *toend
;
10826 xassert (!FRAME_WINDOW_P (it
->f
));
10828 /* Get the truncation glyphs. */
10830 truncate_it
.current_x
= 0;
10831 truncate_it
.face_id
= DEFAULT_FACE_ID
;
10832 truncate_it
.glyph_row
= &scratch_glyph_row
;
10833 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
10834 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
10835 truncate_it
.object
= make_number (0);
10836 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
10838 /* Overwrite glyphs from IT with truncation glyphs. */
10839 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
10840 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
10841 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
10842 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
10847 /* There may be padding glyphs left over. Remove them. */
10849 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
10851 while (from
< toend
)
10854 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
10858 /* Compute the pixel height and width of IT->glyph_row.
10860 Most of the time, ascent and height of a display line will be equal
10861 to the max_ascent and max_height values of the display iterator
10862 structure. This is not the case if
10864 1. We hit ZV without displaying anything. In this case, max_ascent
10865 and max_height will be zero.
10867 2. We have some glyphs that don't contribute to the line height.
10868 (The glyph row flag contributes_to_line_height_p is for future
10869 pixmap extensions).
10871 The first case is easily covered by using default values because in
10872 these cases, the line height does not really matter, except that it
10873 must not be zero. */
10876 compute_line_metrics (it
)
10879 struct glyph_row
*row
= it
->glyph_row
;
10882 if (FRAME_WINDOW_P (it
->f
))
10884 int i
, header_line_height
;
10886 /* The line may consist of one space only, that was added to
10887 place the cursor on it. If so, the row's height hasn't been
10889 if (row
->height
== 0)
10891 if (it
->max_ascent
+ it
->max_descent
== 0)
10892 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
10893 row
->ascent
= it
->max_ascent
;
10894 row
->height
= it
->max_ascent
+ it
->max_descent
;
10895 row
->phys_ascent
= it
->max_phys_ascent
;
10896 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10899 /* Compute the width of this line. */
10900 row
->pixel_width
= row
->x
;
10901 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
10902 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10904 xassert (row
->pixel_width
>= 0);
10905 xassert (row
->ascent
>= 0 && row
->height
> 0);
10907 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
10908 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
10910 /* If first line's physical ascent is larger than its logical
10911 ascent, use the physical ascent, and make the row taller.
10912 This makes accented characters fully visible. */
10913 if (row
== it
->w
->desired_matrix
->rows
10914 && row
->phys_ascent
> row
->ascent
)
10916 row
->height
+= row
->phys_ascent
- row
->ascent
;
10917 row
->ascent
= row
->phys_ascent
;
10920 /* Compute how much of the line is visible. */
10921 row
->visible_height
= row
->height
;
10923 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
10924 if (row
->y
< header_line_height
)
10925 row
->visible_height
-= header_line_height
- row
->y
;
10928 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
10929 if (row
->y
+ row
->height
> max_y
)
10930 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10935 row
->pixel_width
= row
->used
[TEXT_AREA
];
10936 row
->ascent
= row
->phys_ascent
= 0;
10937 row
->height
= row
->phys_height
= row
->visible_height
= 1;
10940 /* Compute a hash code for this row. */
10942 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
10943 for (i
= 0; i
< row
->used
[area
]; ++i
)
10944 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
10945 + row
->glyphs
[area
][i
].u
.val
10946 + row
->glyphs
[area
][i
].face_id
10947 + row
->glyphs
[area
][i
].padding_p
10948 + (row
->glyphs
[area
][i
].type
<< 2));
10950 it
->max_ascent
= it
->max_descent
= 0;
10951 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
10955 /* Append one space to the glyph row of iterator IT if doing a
10956 window-based redisplay. DEFAULT_FACE_P non-zero means let the
10957 space have the default face, otherwise let it have the same face as
10958 IT->face_id. Value is non-zero if a space was added.
10960 This function is called to make sure that there is always one glyph
10961 at the end of a glyph row that the cursor can be set on under
10962 window-systems. (If there weren't such a glyph we would not know
10963 how wide and tall a box cursor should be displayed).
10965 At the same time this space let's a nicely handle clearing to the
10966 end of the line if the row ends in italic text. */
10969 append_space (it
, default_face_p
)
10971 int default_face_p
;
10973 if (FRAME_WINDOW_P (it
->f
))
10975 int n
= it
->glyph_row
->used
[TEXT_AREA
];
10977 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
10978 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
10980 /* Save some values that must not be changed. */
10981 int saved_x
= it
->current_x
;
10982 struct text_pos saved_pos
;
10983 int saved_what
= it
->what
;
10984 int saved_face_id
= it
->face_id
;
10985 Lisp_Object saved_object
;
10988 saved_object
= it
->object
;
10989 saved_pos
= it
->position
;
10991 it
->what
= IT_CHARACTER
;
10992 bzero (&it
->position
, sizeof it
->position
);
10993 it
->object
= make_number (0);
10997 if (default_face_p
)
10998 it
->face_id
= DEFAULT_FACE_ID
;
10999 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11000 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11002 PRODUCE_GLYPHS (it
);
11004 it
->current_x
= saved_x
;
11005 it
->object
= saved_object
;
11006 it
->position
= saved_pos
;
11007 it
->what
= saved_what
;
11008 it
->face_id
= saved_face_id
;
11017 /* Extend the face of the last glyph in the text area of IT->glyph_row
11018 to the end of the display line. Called from display_line.
11019 If the glyph row is empty, add a space glyph to it so that we
11020 know the face to draw. Set the glyph row flag fill_line_p. */
11023 extend_face_to_end_of_line (it
)
11027 struct frame
*f
= it
->f
;
11029 /* If line is already filled, do nothing. */
11030 if (it
->current_x
>= it
->last_visible_x
)
11033 /* Face extension extends the background and box of IT->face_id
11034 to the end of the line. If the background equals the background
11035 of the frame, we haven't to do anything. */
11036 face
= FACE_FROM_ID (f
, it
->face_id
);
11037 if (FRAME_WINDOW_P (f
)
11038 && face
->box
== FACE_NO_BOX
11039 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11043 /* Set the glyph row flag indicating that the face of the last glyph
11044 in the text area has to be drawn to the end of the text area. */
11045 it
->glyph_row
->fill_line_p
= 1;
11047 /* If current character of IT is not ASCII, make sure we have the
11048 ASCII face. This will be automatically undone the next time
11049 get_next_display_element returns a multibyte character. Note
11050 that the character will always be single byte in unibyte text. */
11051 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11053 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11056 if (FRAME_WINDOW_P (f
))
11058 /* If the row is empty, add a space with the current face of IT,
11059 so that we know which face to draw. */
11060 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11062 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11063 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11064 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11069 /* Save some values that must not be changed. */
11070 int saved_x
= it
->current_x
;
11071 struct text_pos saved_pos
;
11072 Lisp_Object saved_object
;
11073 int saved_what
= it
->what
;
11075 saved_object
= it
->object
;
11076 saved_pos
= it
->position
;
11078 it
->what
= IT_CHARACTER
;
11079 bzero (&it
->position
, sizeof it
->position
);
11080 it
->object
= make_number (0);
11084 PRODUCE_GLYPHS (it
);
11086 while (it
->current_x
<= it
->last_visible_x
)
11087 PRODUCE_GLYPHS (it
);
11089 /* Don't count these blanks really. It would let us insert a left
11090 truncation glyph below and make us set the cursor on them, maybe. */
11091 it
->current_x
= saved_x
;
11092 it
->object
= saved_object
;
11093 it
->position
= saved_pos
;
11094 it
->what
= saved_what
;
11099 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11100 trailing whitespace. */
11103 trailing_whitespace_p (charpos
)
11106 int bytepos
= CHAR_TO_BYTE (charpos
);
11109 while (bytepos
< ZV_BYTE
11110 && (c
= FETCH_CHAR (bytepos
),
11111 c
== ' ' || c
== '\t'))
11114 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11116 if (bytepos
!= PT_BYTE
)
11123 /* Highlight trailing whitespace, if any, in ROW. */
11126 highlight_trailing_whitespace (f
, row
)
11128 struct glyph_row
*row
;
11130 int used
= row
->used
[TEXT_AREA
];
11134 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11135 struct glyph
*glyph
= start
+ used
- 1;
11137 /* Skip over the space glyph inserted to display the
11138 cursor at the end of a line. */
11139 if (glyph
->type
== CHAR_GLYPH
11140 && glyph
->u
.ch
== ' '
11141 && INTEGERP (glyph
->object
))
11144 /* If last glyph is a space or stretch, and it's trailing
11145 whitespace, set the face of all trailing whitespace glyphs in
11146 IT->glyph_row to `trailing-whitespace'. */
11148 && BUFFERP (glyph
->object
)
11149 && (glyph
->type
== STRETCH_GLYPH
11150 || (glyph
->type
== CHAR_GLYPH
11151 && glyph
->u
.ch
== ' '))
11152 && trailing_whitespace_p (glyph
->charpos
))
11154 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11156 while (glyph
>= start
11157 && BUFFERP (glyph
->object
)
11158 && (glyph
->type
== STRETCH_GLYPH
11159 || (glyph
->type
== CHAR_GLYPH
11160 && glyph
->u
.ch
== ' ')))
11161 (glyph
--)->face_id
= face_id
;
11167 /* Construct the glyph row IT->glyph_row in the desired matrix of
11168 IT->w from text at the current position of IT. See dispextern.h
11169 for an overview of struct it. Value is non-zero if
11170 IT->glyph_row displays text, as opposed to a line displaying ZV
11177 struct glyph_row
*row
= it
->glyph_row
;
11179 /* We always start displaying at hpos zero even if hscrolled. */
11180 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11182 /* We must not display in a row that's not a text row. */
11183 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11184 < it
->w
->desired_matrix
->nrows
);
11186 /* Is IT->w showing the region? */
11187 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11189 /* Clear the result glyph row and enable it. */
11190 prepare_desired_row (row
);
11192 row
->y
= it
->current_y
;
11193 row
->start
= it
->current
;
11194 row
->continuation_lines_width
= it
->continuation_lines_width
;
11195 row
->displays_text_p
= 1;
11197 /* Arrange the overlays nicely for our purposes. Usually, we call
11198 display_line on only one line at a time, in which case this
11199 can't really hurt too much, or we call it on lines which appear
11200 one after another in the buffer, in which case all calls to
11201 recenter_overlay_lists but the first will be pretty cheap. */
11202 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11204 /* Move over display elements that are not visible because we are
11205 hscrolled. This may stop at an x-position < IT->first_visible_x
11206 if the first glyph is partially visible or if we hit a line end. */
11207 if (it
->current_x
< it
->first_visible_x
)
11208 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11209 MOVE_TO_POS
| MOVE_TO_X
);
11211 /* Get the initial row height. This is either the height of the
11212 text hscrolled, if there is any, or zero. */
11213 row
->ascent
= it
->max_ascent
;
11214 row
->height
= it
->max_ascent
+ it
->max_descent
;
11215 row
->phys_ascent
= it
->max_phys_ascent
;
11216 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11218 /* Loop generating characters. The loop is left with IT on the next
11219 character to display. */
11222 int n_glyphs_before
, hpos_before
, x_before
;
11225 /* Retrieve the next thing to display. Value is zero if end of
11227 if (!get_next_display_element (it
))
11229 /* Maybe add a space at the end of this line that is used to
11230 display the cursor there under X. Set the charpos of the
11231 first glyph of blank lines not corresponding to any text
11233 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11234 || row
->used
[TEXT_AREA
] == 0)
11236 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11237 row
->displays_text_p
= 0;
11239 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11240 row
->indicate_empty_line_p
= 1;
11243 it
->continuation_lines_width
= 0;
11244 row
->ends_at_zv_p
= 1;
11248 /* Now, get the metrics of what we want to display. This also
11249 generates glyphs in `row' (which is IT->glyph_row). */
11250 n_glyphs_before
= row
->used
[TEXT_AREA
];
11252 PRODUCE_GLYPHS (it
);
11254 /* If this display element was in marginal areas, continue with
11256 if (it
->area
!= TEXT_AREA
)
11258 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11259 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11260 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11261 row
->phys_height
= max (row
->phys_height
,
11262 it
->max_phys_ascent
+ it
->max_phys_descent
);
11263 set_iterator_to_next (it
);
11267 /* Does the display element fit on the line? If we truncate
11268 lines, we should draw past the right edge of the window. If
11269 we don't truncate, we want to stop so that we can display the
11270 continuation glyph before the right margin. If lines are
11271 continued, there are two possible strategies for characters
11272 resulting in more than 1 glyph (e.g. tabs): Display as many
11273 glyphs as possible in this line and leave the rest for the
11274 continuation line, or display the whole element in the next
11275 line. Original redisplay did the former, so we do it also. */
11276 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11277 hpos_before
= it
->hpos
;
11281 && it
->current_x
< it
->last_visible_x
)
11284 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11285 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11286 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11287 row
->phys_height
= max (row
->phys_height
,
11288 it
->max_phys_ascent
+ it
->max_phys_descent
);
11289 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11290 row
->x
= x
- it
->first_visible_x
;
11295 struct glyph
*glyph
;
11297 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11299 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11300 new_x
= x
+ glyph
->pixel_width
;
11302 if (/* Lines are continued. */
11303 !it
->truncate_lines_p
11304 && (/* Glyph doesn't fit on the line. */
11305 new_x
> it
->last_visible_x
11306 /* Or it fits exactly on a window system frame. */
11307 || (new_x
== it
->last_visible_x
11308 && FRAME_WINDOW_P (it
->f
))))
11310 /* End of a continued line. */
11313 || (new_x
== it
->last_visible_x
11314 && FRAME_WINDOW_P (it
->f
)))
11316 /* Current glyph fits exactly on the line. We
11317 must continue the line because we can't draw
11318 the cursor after the glyph. */
11319 row
->continued_p
= 1;
11320 it
->current_x
= new_x
;
11321 it
->continuation_lines_width
+= new_x
;
11323 if (i
== nglyphs
- 1)
11324 set_iterator_to_next (it
);
11328 /* Display element draws past the right edge of
11329 the window. Restore positions to values
11330 before the element. The next line starts
11331 with current_x before the glyph that could
11332 not be displayed, so that TAB works right. */
11333 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11335 /* Display continuation glyphs. */
11336 if (!FRAME_WINDOW_P (it
->f
))
11337 produce_special_glyphs (it
, IT_CONTINUATION
);
11338 row
->continued_p
= 1;
11341 it
->continuation_lines_width
+= x
;
11345 else if (new_x
> it
->first_visible_x
)
11347 /* Increment number of glyphs actually displayed. */
11350 if (x
< it
->first_visible_x
)
11351 /* Glyph is partially visible, i.e. row starts at
11352 negative X position. */
11353 row
->x
= x
- it
->first_visible_x
;
11357 /* Glyph is completely off the left margin of the
11358 window. This should not happen because of the
11359 move_it_in_display_line at the start of
11365 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11366 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11367 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11368 row
->phys_height
= max (row
->phys_height
,
11369 it
->max_phys_ascent
+ it
->max_phys_descent
);
11371 /* End of this display line if row is continued. */
11372 if (row
->continued_p
)
11376 /* Is this a line end? If yes, we're also done, after making
11377 sure that a non-default face is extended up to the right
11378 margin of the window. */
11379 if (ITERATOR_AT_END_OF_LINE_P (it
))
11381 int used_before
= row
->used
[TEXT_AREA
];
11383 /* Add a space at the end of the line that is used to
11384 display the cursor there. */
11385 append_space (it
, 0);
11387 /* Extend the face to the end of the line. */
11388 extend_face_to_end_of_line (it
);
11390 /* Make sure we have the position. */
11391 if (used_before
== 0)
11392 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11394 /* Consume the line end. This skips over invisible lines. */
11395 set_iterator_to_next (it
);
11396 it
->continuation_lines_width
= 0;
11400 /* Proceed with next display element. Note that this skips
11401 over lines invisible because of selective display. */
11402 set_iterator_to_next (it
);
11404 /* If we truncate lines, we are done when the last displayed
11405 glyphs reach past the right margin of the window. */
11406 if (it
->truncate_lines_p
11407 && (FRAME_WINDOW_P (it
->f
)
11408 ? (it
->current_x
>= it
->last_visible_x
)
11409 : (it
->current_x
> it
->last_visible_x
)))
11411 /* Maybe add truncation glyphs. */
11412 if (!FRAME_WINDOW_P (it
->f
))
11414 --it
->glyph_row
->used
[TEXT_AREA
];
11415 produce_special_glyphs (it
, IT_TRUNCATION
);
11418 row
->truncated_on_right_p
= 1;
11419 it
->continuation_lines_width
= 0;
11420 reseat_at_next_visible_line_start (it
, 0);
11421 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11422 it
->hpos
= hpos_before
;
11423 it
->current_x
= x_before
;
11428 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11429 at the left window margin. */
11430 if (it
->first_visible_x
11431 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11433 if (!FRAME_WINDOW_P (it
->f
))
11434 insert_left_trunc_glyphs (it
);
11435 row
->truncated_on_left_p
= 1;
11438 /* If the start of this line is the overlay arrow-position, then
11439 mark this glyph row as the one containing the overlay arrow.
11440 This is clearly a mess with variable size fonts. It would be
11441 better to let it be displayed like cursors under X. */
11442 if (MARKERP (Voverlay_arrow_position
)
11443 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11444 && (MATRIX_ROW_START_CHARPOS (row
)
11445 == marker_position (Voverlay_arrow_position
))
11446 && STRINGP (Voverlay_arrow_string
)
11447 && ! overlay_arrow_seen
)
11449 /* Overlay arrow in window redisplay is a bitmap. */
11450 if (!FRAME_WINDOW_P (it
->f
))
11452 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11453 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11454 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11455 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11456 struct glyph
*p2
, *end
;
11458 /* Copy the arrow glyphs. */
11459 while (glyph
< arrow_end
)
11462 /* Throw away padding glyphs. */
11464 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11465 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11471 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11475 overlay_arrow_seen
= 1;
11476 row
->overlay_arrow_p
= 1;
11479 /* Compute pixel dimensions of this line. */
11480 compute_line_metrics (it
);
11482 /* Remember the position at which this line ends. */
11483 row
->end
= it
->current
;
11485 /* Maybe set the cursor. If you change this, it's probably a good
11486 idea to also change the code in redisplay_window for cursor
11487 movement in an unchanged window. */
11488 if (it
->w
->cursor
.vpos
< 0
11489 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11490 && MATRIX_ROW_END_CHARPOS (row
) >= PT
11491 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
11492 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11493 || !row
->ends_at_zv_p
)))
11494 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11496 /* Highlight trailing whitespace. */
11497 if (!NILP (Vshow_trailing_whitespace
))
11498 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11500 /* Prepare for the next line. This line starts horizontally at (X
11501 HPOS) = (0 0). Vertical positions are incremented. As a
11502 convenience for the caller, IT->glyph_row is set to the next
11504 it
->current_x
= it
->hpos
= 0;
11505 it
->current_y
+= row
->height
;
11508 return row
->displays_text_p
;
11513 /***********************************************************************
11515 ***********************************************************************/
11517 /* Redisplay the menu bar in the frame for window W.
11519 The menu bar of X frames that don't have X toolkit support is
11520 displayed in a special window W->frame->menu_bar_window.
11522 The menu bar of terminal frames is treated specially as far as
11523 glyph matrices are concerned. Menu bar lines are not part of
11524 windows, so the update is done directly on the frame matrix rows
11525 for the menu bar. */
11528 display_menu_bar (w
)
11531 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11536 /* Don't do all this for graphical frames. */
11538 if (!NILP (Vwindow_system
))
11541 #ifdef USE_X_TOOLKIT
11546 #ifdef USE_X_TOOLKIT
11547 xassert (!FRAME_WINDOW_P (f
));
11548 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
11549 it
.first_visible_x
= 0;
11550 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11551 #else /* not USE_X_TOOLKIT */
11552 if (FRAME_WINDOW_P (f
))
11554 /* Menu bar lines are displayed in the desired matrix of the
11555 dummy window menu_bar_window. */
11556 struct window
*menu_w
;
11557 xassert (WINDOWP (f
->menu_bar_window
));
11558 menu_w
= XWINDOW (f
->menu_bar_window
);
11559 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
11561 it
.first_visible_x
= 0;
11562 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11566 /* This is a TTY frame, i.e. character hpos/vpos are used as
11568 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
11570 it
.first_visible_x
= 0;
11571 it
.last_visible_x
= FRAME_WIDTH (f
);
11573 #endif /* not USE_X_TOOLKIT */
11575 /* Clear all rows of the menu bar. */
11576 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
11578 struct glyph_row
*row
= it
.glyph_row
+ i
;
11579 clear_glyph_row (row
);
11580 row
->enabled_p
= 1;
11581 row
->full_width_p
= 1;
11584 /* Make the first line of the menu bar appear in reverse video. */
11585 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11587 /* Display all items of the menu bar. */
11588 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
11589 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
11591 Lisp_Object string
;
11593 /* Stop at nil string. */
11594 string
= XVECTOR (items
)->contents
[i
+ 1];
11598 /* Remember where item was displayed. */
11599 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
11601 /* Display the item, pad with one space. */
11602 if (it
.current_x
< it
.last_visible_x
)
11603 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
11604 XSTRING (string
)->size
+ 1, 0, 0, -1);
11607 /* Fill out the line with spaces. */
11608 if (it
.current_x
< it
.last_visible_x
)
11609 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
11611 /* Compute the total height of the lines. */
11612 compute_line_metrics (&it
);
11617 /***********************************************************************
11619 ***********************************************************************/
11621 /* Display the mode and/or top line of window W. */
11624 display_mode_lines (w
)
11627 /* These will be set while the mode line specs are processed. */
11628 line_number_displayed
= 0;
11629 w
->column_number_displayed
= Qnil
;
11631 if (WINDOW_WANTS_MODELINE_P (w
))
11632 display_mode_line (w
, MODE_LINE_FACE_ID
,
11633 current_buffer
->mode_line_format
);
11635 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11636 display_mode_line (w
, HEADER_LINE_FACE_ID
,
11637 current_buffer
->header_line_format
);
11641 /* Display mode or top line of window W. FACE_ID specifies which line
11642 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
11643 FORMAT is the mode line format to display. */
11646 display_mode_line (w
, face_id
, format
)
11648 enum face_id face_id
;
11649 Lisp_Object format
;
11654 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
11655 prepare_desired_row (it
.glyph_row
);
11657 /* Temporarily make frame's keyboard the current kboard so that
11658 kboard-local variables in the mode_line_format will get the right
11660 push_frame_kboard (it
.f
);
11661 display_mode_element (&it
, 0, 0, 0, format
);
11662 pop_frame_kboard ();
11664 /* Fill up with spaces. */
11665 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
11667 compute_line_metrics (&it
);
11668 it
.glyph_row
->full_width_p
= 1;
11669 it
.glyph_row
->mode_line_p
= 1;
11670 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11671 it
.glyph_row
->continued_p
= 0;
11672 it
.glyph_row
->truncated_on_left_p
= 0;
11673 it
.glyph_row
->truncated_on_right_p
= 0;
11675 /* Make a 3D mode-line have a shadow at its right end. */
11676 face
= FACE_FROM_ID (it
.f
, face_id
);
11677 extend_face_to_end_of_line (&it
);
11678 if (face
->box
!= FACE_NO_BOX
)
11680 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
11681 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
11682 last
->right_box_line_p
= 1;
11687 /* Contribute ELT to the mode line for window IT->w. How it
11688 translates into text depends on its data type.
11690 IT describes the display environment in which we display, as usual.
11692 DEPTH is the depth in recursion. It is used to prevent
11693 infinite recursion here.
11695 FIELD_WIDTH is the number of characters the display of ELT should
11696 occupy in the mode line, and PRECISION is the maximum number of
11697 characters to display from ELT's representation. See
11698 display_string for details. *
11700 Returns the hpos of the end of the text generated by ELT. */
11703 display_mode_element (it
, depth
, field_width
, precision
, elt
)
11706 int field_width
, precision
;
11709 int n
= 0, field
, prec
;
11717 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
11721 /* A string: output it and check for %-constructs within it. */
11723 unsigned char *this = XSTRING (elt
)->data
;
11724 unsigned char *lisp_string
= this;
11726 while ((precision
<= 0 || n
< precision
)
11728 && (frame_title_ptr
11729 || it
->current_x
< it
->last_visible_x
))
11731 unsigned char *last
= this;
11733 /* Advance to end of string or next format specifier. */
11734 while ((c
= *this++) != '\0' && c
!= '%')
11737 if (this - 1 != last
)
11739 /* Output to end of string or up to '%'. Field width
11740 is length of string. Don't output more than
11741 PRECISION allows us. */
11742 prec
= --this - last
;
11743 if (precision
> 0 && prec
> precision
- n
)
11744 prec
= precision
- n
;
11746 if (frame_title_ptr
)
11747 n
+= store_frame_title (last
, prec
, prec
);
11749 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
11750 it
, 0, prec
, 0, -1);
11752 else /* c == '%' */
11754 unsigned char *percent_position
= this;
11756 /* Get the specified minimum width. Zero means
11759 while ((c
= *this++) >= '0' && c
<= '9')
11760 field
= field
* 10 + c
- '0';
11762 /* Don't pad beyond the total padding allowed. */
11763 if (field_width
- n
> 0 && field
> field_width
- n
)
11764 field
= field_width
- n
;
11766 /* Note that either PRECISION <= 0 or N < PRECISION. */
11767 prec
= precision
- n
;
11770 n
+= display_mode_element (it
, depth
, field
, prec
,
11771 Vglobal_mode_string
);
11774 unsigned char *spec
11775 = decode_mode_spec (it
->w
, c
, field
, prec
);
11777 if (frame_title_ptr
)
11778 n
+= store_frame_title (spec
, field
, prec
);
11782 = it
->glyph_row
->used
[TEXT_AREA
];
11784 = percent_position
- XSTRING (elt
)->data
;
11786 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
11787 field
, prec
, 0, -1);
11789 /* Assign to the glyphs written above the
11790 string where the `%x' came from, position
11794 struct glyph
*glyph
11795 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
11799 for (i
= 0; i
< nwritten
; ++i
)
11801 glyph
[i
].object
= elt
;
11802 glyph
[i
].charpos
= charpos
;
11815 /* A symbol: process the value of the symbol recursively
11816 as if it appeared here directly. Avoid error if symbol void.
11817 Special case: if value of symbol is a string, output the string
11820 register Lisp_Object tem
;
11821 tem
= Fboundp (elt
);
11824 tem
= Fsymbol_value (elt
);
11825 /* If value is a string, output that string literally:
11826 don't check for % within it. */
11829 prec
= XSTRING (tem
)->size
;
11830 if (precision
> 0 && prec
> precision
- n
)
11831 prec
= precision
- n
;
11832 if (frame_title_ptr
)
11833 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
11835 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
11838 else if (!EQ (tem
, elt
))
11840 /* Give up right away for nil or t. */
11850 register Lisp_Object car
, tem
;
11852 /* A cons cell: three distinct cases.
11853 If first element is a string or a cons, process all the elements
11854 and effectively concatenate them.
11855 If first element is a negative number, truncate displaying cdr to
11856 at most that many characters. If positive, pad (with spaces)
11857 to at least that many characters.
11858 If first element is a symbol, process the cadr or caddr recursively
11859 according to whether the symbol's value is non-nil or nil. */
11861 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
11863 /* An element of the form (:eval FORM) means evaluate FORM
11864 and use the result as mode line elements. */
11865 struct gcpro gcpro1
;
11868 spec
= eval_form (XCAR (XCDR (elt
)));
11870 n
+= display_mode_element (it
, depth
, field_width
- n
,
11871 precision
- n
, spec
);
11874 else if (SYMBOLP (car
))
11876 tem
= Fboundp (car
);
11880 /* elt is now the cdr, and we know it is a cons cell.
11881 Use its car if CAR has a non-nil value. */
11884 tem
= Fsymbol_value (car
);
11891 /* Symbol's value is nil (or symbol is unbound)
11892 Get the cddr of the original list
11893 and if possible find the caddr and use that. */
11897 else if (!CONSP (elt
))
11902 else if (INTEGERP (car
))
11904 register int lim
= XINT (car
);
11908 /* Negative int means reduce maximum width. */
11909 if (precision
<= 0)
11912 precision
= min (precision
, -lim
);
11916 /* Padding specified. Don't let it be more than
11917 current maximum. */
11919 lim
= min (precision
, lim
);
11921 /* If that's more padding than already wanted, queue it.
11922 But don't reduce padding already specified even if
11923 that is beyond the current truncation point. */
11924 field_width
= max (lim
, field_width
);
11928 else if (STRINGP (car
) || CONSP (car
))
11930 register int limit
= 50;
11931 /* Limit is to protect against circular lists. */
11934 && (precision
<= 0 || n
< precision
))
11936 n
+= display_mode_element (it
, depth
, field_width
- n
,
11937 precision
- n
, XCAR (elt
));
11946 if (frame_title_ptr
)
11947 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
11949 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
11950 precision
- n
, 0, 0);
11954 /* Pad to FIELD_WIDTH. */
11955 if (field_width
> 0 && n
< field_width
)
11957 if (frame_title_ptr
)
11958 n
+= store_frame_title ("", field_width
- n
, 0);
11960 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
11968 /* Write a null-terminated, right justified decimal representation of
11969 the positive integer D to BUF using a minimal field width WIDTH. */
11972 pint2str (buf
, width
, d
)
11973 register char *buf
;
11974 register int width
;
11977 register char *p
= buf
;
11985 *p
++ = d
% 10 + '0';
11990 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12001 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12002 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12003 type of CODING_SYSTEM. Return updated pointer into BUF. */
12005 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12008 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12009 Lisp_Object coding_system
;
12010 register char *buf
;
12014 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12015 unsigned char *eol_str
;
12017 /* The EOL conversion we are using. */
12018 Lisp_Object eoltype
;
12020 val
= Fget (coding_system
, Qcoding_system
);
12022 if (!VECTORP (val
)) /* Not yet decided. */
12027 eoltype
= eol_mnemonic_undecided
;
12028 /* Don't mention EOL conversion if it isn't decided. */
12032 Lisp_Object eolvalue
;
12034 eolvalue
= Fget (coding_system
, Qeol_type
);
12037 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12041 /* The EOL conversion that is normal on this system. */
12043 if (NILP (eolvalue
)) /* Not yet decided. */
12044 eoltype
= eol_mnemonic_undecided
;
12045 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12046 eoltype
= eol_mnemonic_undecided
;
12047 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12048 eoltype
= (XFASTINT (eolvalue
) == 0
12049 ? eol_mnemonic_unix
12050 : (XFASTINT (eolvalue
) == 1
12051 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12057 /* Mention the EOL conversion if it is not the usual one. */
12058 if (STRINGP (eoltype
))
12060 eol_str
= XSTRING (eoltype
)->data
;
12061 eol_str_len
= XSTRING (eoltype
)->size
;
12063 else if (INTEGERP (eoltype
)
12064 && CHAR_VALID_P (XINT (eoltype
), 0))
12066 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12067 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12071 eol_str
= invalid_eol_type
;
12072 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12074 bcopy (eol_str
, buf
, eol_str_len
);
12075 buf
+= eol_str_len
;
12081 /* Return a string for the output of a mode line %-spec for window W,
12082 generated by character C. PRECISION >= 0 means don't return a
12083 string longer than that value. FIELD_WIDTH > 0 means pad the
12084 string returned with spaces to that value. */
12086 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12089 decode_mode_spec (w
, c
, field_width
, precision
)
12092 int field_width
, precision
;
12095 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12096 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12097 struct buffer
*b
= XBUFFER (w
->buffer
);
12104 if (!NILP (b
->read_only
))
12106 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12111 /* This differs from %* only for a modified read-only buffer. */
12112 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12114 if (!NILP (b
->read_only
))
12119 /* This differs from %* in ignoring read-only-ness. */
12120 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12132 if (command_loop_level
> 5)
12134 p
= decode_mode_spec_buf
;
12135 for (i
= 0; i
< command_loop_level
; i
++)
12138 return decode_mode_spec_buf
;
12146 if (command_loop_level
> 5)
12148 p
= decode_mode_spec_buf
;
12149 for (i
= 0; i
< command_loop_level
; i
++)
12152 return decode_mode_spec_buf
;
12159 /* Let lots_of_dashes be a string of infinite length. */
12160 if (field_width
<= 0
12161 || field_width
> sizeof (lots_of_dashes
))
12163 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12164 decode_mode_spec_buf
[i
] = '-';
12165 decode_mode_spec_buf
[i
] = '\0';
12166 return decode_mode_spec_buf
;
12169 return lots_of_dashes
;
12178 int col
= current_column ();
12179 XSETFASTINT (w
->column_number_displayed
, col
);
12180 pint2str (decode_mode_spec_buf
, field_width
, col
);
12181 return decode_mode_spec_buf
;
12185 /* %F displays the frame name. */
12186 if (!NILP (f
->title
))
12187 return (char *) XSTRING (f
->title
)->data
;
12188 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12189 return (char *) XSTRING (f
->name
)->data
;
12198 int startpos
= XMARKER (w
->start
)->charpos
;
12199 int startpos_byte
= marker_byte_position (w
->start
);
12200 int line
, linepos
, linepos_byte
, topline
;
12202 int height
= XFASTINT (w
->height
);
12204 /* If we decided that this buffer isn't suitable for line numbers,
12205 don't forget that too fast. */
12206 if (EQ (w
->base_line_pos
, w
->buffer
))
12208 /* But do forget it, if the window shows a different buffer now. */
12209 else if (BUFFERP (w
->base_line_pos
))
12210 w
->base_line_pos
= Qnil
;
12212 /* If the buffer is very big, don't waste time. */
12213 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
12215 w
->base_line_pos
= Qnil
;
12216 w
->base_line_number
= Qnil
;
12220 if (!NILP (w
->base_line_number
)
12221 && !NILP (w
->base_line_pos
)
12222 && XFASTINT (w
->base_line_pos
) <= startpos
)
12224 line
= XFASTINT (w
->base_line_number
);
12225 linepos
= XFASTINT (w
->base_line_pos
);
12226 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12231 linepos
= BUF_BEGV (b
);
12232 linepos_byte
= BUF_BEGV_BYTE (b
);
12235 /* Count lines from base line to window start position. */
12236 nlines
= display_count_lines (linepos
, linepos_byte
,
12240 topline
= nlines
+ line
;
12242 /* Determine a new base line, if the old one is too close
12243 or too far away, or if we did not have one.
12244 "Too close" means it's plausible a scroll-down would
12245 go back past it. */
12246 if (startpos
== BUF_BEGV (b
))
12248 XSETFASTINT (w
->base_line_number
, topline
);
12249 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12251 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12252 || linepos
== BUF_BEGV (b
))
12254 int limit
= BUF_BEGV (b
);
12255 int limit_byte
= BUF_BEGV_BYTE (b
);
12257 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12259 if (startpos
- distance
> limit
)
12261 limit
= startpos
- distance
;
12262 limit_byte
= CHAR_TO_BYTE (limit
);
12265 nlines
= display_count_lines (startpos
, startpos_byte
,
12267 - (height
* 2 + 30),
12269 /* If we couldn't find the lines we wanted within
12270 line_number_display_limit_width chars per line,
12271 give up on line numbers for this window. */
12272 if (position
== limit_byte
&& limit
== startpos
- distance
)
12274 w
->base_line_pos
= w
->buffer
;
12275 w
->base_line_number
= Qnil
;
12279 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12280 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12283 /* Now count lines from the start pos to point. */
12284 nlines
= display_count_lines (startpos
, startpos_byte
,
12285 PT_BYTE
, PT
, &junk
);
12287 /* Record that we did display the line number. */
12288 line_number_displayed
= 1;
12290 /* Make the string to show. */
12291 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12292 return decode_mode_spec_buf
;
12295 char* p
= decode_mode_spec_buf
;
12296 int pad
= field_width
- 2;
12301 return decode_mode_spec_buf
;
12307 obj
= b
->mode_name
;
12311 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12317 int pos
= marker_position (w
->start
);
12318 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12320 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12322 if (pos
<= BUF_BEGV (b
))
12327 else if (pos
<= BUF_BEGV (b
))
12331 if (total
> 1000000)
12332 /* Do it differently for a large value, to avoid overflow. */
12333 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12335 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12336 /* We can't normally display a 3-digit number,
12337 so get us a 2-digit number that is close. */
12340 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12341 return decode_mode_spec_buf
;
12345 /* Display percentage of size above the bottom of the screen. */
12348 int toppos
= marker_position (w
->start
);
12349 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12350 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12352 if (botpos
>= BUF_ZV (b
))
12354 if (toppos
<= BUF_BEGV (b
))
12361 if (total
> 1000000)
12362 /* Do it differently for a large value, to avoid overflow. */
12363 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12365 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12366 /* We can't normally display a 3-digit number,
12367 so get us a 2-digit number that is close. */
12370 if (toppos
<= BUF_BEGV (b
))
12371 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12373 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12374 return decode_mode_spec_buf
;
12379 /* status of process */
12380 obj
= Fget_buffer_process (w
->buffer
);
12382 return "no process";
12383 #ifdef subprocesses
12384 obj
= Fsymbol_name (Fprocess_status (obj
));
12388 case 't': /* indicate TEXT or BINARY */
12389 #ifdef MODE_LINE_BINARY_TEXT
12390 return MODE_LINE_BINARY_TEXT (b
);
12396 /* coding-system (not including end-of-line format) */
12398 /* coding-system (including end-of-line type) */
12400 int eol_flag
= (c
== 'Z');
12401 char *p
= decode_mode_spec_buf
;
12403 if (! FRAME_WINDOW_P (f
))
12405 /* No need to mention EOL here--the terminal never needs
12406 to do EOL conversion. */
12407 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12408 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12410 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12413 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12414 #ifdef subprocesses
12415 obj
= Fget_buffer_process (Fcurrent_buffer ());
12416 if (PROCESSP (obj
))
12418 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12420 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12423 #endif /* subprocesses */
12426 return decode_mode_spec_buf
;
12431 return (char *) XSTRING (obj
)->data
;
12437 /* Count up to COUNT lines starting from START / START_BYTE.
12438 But don't go beyond LIMIT_BYTE.
12439 Return the number of lines thus found (always nonnegative).
12441 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12444 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12445 int start
, start_byte
, limit_byte
, count
;
12448 register unsigned char *cursor
;
12449 unsigned char *base
;
12451 register int ceiling
;
12452 register unsigned char *ceiling_addr
;
12453 int orig_count
= count
;
12455 /* If we are not in selective display mode,
12456 check only for newlines. */
12457 int selective_display
= (!NILP (current_buffer
->selective_display
)
12458 && !INTEGERP (current_buffer
->selective_display
));
12462 while (start_byte
< limit_byte
)
12464 ceiling
= BUFFER_CEILING_OF (start_byte
);
12465 ceiling
= min (limit_byte
- 1, ceiling
);
12466 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
12467 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
12470 if (selective_display
)
12471 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
12474 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
12477 if (cursor
!= ceiling_addr
)
12481 start_byte
+= cursor
- base
+ 1;
12482 *byte_pos_ptr
= start_byte
;
12486 if (++cursor
== ceiling_addr
)
12492 start_byte
+= cursor
- base
;
12497 while (start_byte
> limit_byte
)
12499 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
12500 ceiling
= max (limit_byte
, ceiling
);
12501 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
12502 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
12505 if (selective_display
)
12506 while (--cursor
!= ceiling_addr
12507 && *cursor
!= '\n' && *cursor
!= 015)
12510 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
12513 if (cursor
!= ceiling_addr
)
12517 start_byte
+= cursor
- base
+ 1;
12518 *byte_pos_ptr
= start_byte
;
12519 /* When scanning backwards, we should
12520 not count the newline posterior to which we stop. */
12521 return - orig_count
- 1;
12527 /* Here we add 1 to compensate for the last decrement
12528 of CURSOR, which took it past the valid range. */
12529 start_byte
+= cursor
- base
+ 1;
12533 *byte_pos_ptr
= limit_byte
;
12536 return - orig_count
+ count
;
12537 return orig_count
- count
;
12543 /***********************************************************************
12545 ***********************************************************************/
12547 /* Display a NUL-terminated string, starting with index START.
12549 If STRING is non-null, display that C string. Otherwise, the Lisp
12550 string LISP_STRING is displayed.
12552 If FACE_STRING is not nil, FACE_STRING_POS is a position in
12553 FACE_STRING. Display STRING or LISP_STRING with the face at
12554 FACE_STRING_POS in FACE_STRING:
12556 Display the string in the environment given by IT, but use the
12557 standard display table, temporarily.
12559 FIELD_WIDTH is the minimum number of output glyphs to produce.
12560 If STRING has fewer characters than FIELD_WIDTH, pad to the right
12561 with spaces. If STRING has more characters, more than FIELD_WIDTH
12562 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
12564 PRECISION is the maximum number of characters to output from
12565 STRING. PRECISION < 0 means don't truncate the string.
12567 This is roughly equivalent to printf format specifiers:
12569 FIELD_WIDTH PRECISION PRINTF
12570 ----------------------------------------
12576 MULTIBYTE zero means do not display multibyte chars, > 0 means do
12577 display them, and < 0 means obey the current buffer's value of
12578 enable_multibyte_characters.
12580 Value is the number of glyphs produced. */
12583 display_string (string
, lisp_string
, face_string
, face_string_pos
,
12584 start
, it
, field_width
, precision
, max_x
, multibyte
)
12585 unsigned char *string
;
12586 Lisp_Object lisp_string
;
12587 Lisp_Object face_string
;
12588 int face_string_pos
;
12591 int field_width
, precision
, max_x
;
12594 int hpos_at_start
= it
->hpos
;
12595 int saved_face_id
= it
->face_id
;
12596 struct glyph_row
*row
= it
->glyph_row
;
12598 /* Initialize the iterator IT for iteration over STRING beginning
12599 with index START. We assume that IT may be modified here (which
12600 means that display_line has to do something when displaying a
12601 mini-buffer prompt, which it does). */
12602 reseat_to_string (it
, string
, lisp_string
, start
,
12603 precision
, field_width
, multibyte
);
12605 /* If displaying STRING, set up the face of the iterator
12606 from LISP_STRING, if that's given. */
12607 if (STRINGP (face_string
))
12613 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
12614 0, it
->region_beg_charpos
,
12615 it
->region_end_charpos
,
12616 &endptr
, it
->base_face_id
);
12617 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12618 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
12621 /* Set max_x to the maximum allowed X position. Don't let it go
12622 beyond the right edge of the window. */
12624 max_x
= it
->last_visible_x
;
12626 max_x
= min (max_x
, it
->last_visible_x
);
12628 /* Skip over display elements that are not visible. because IT->w is
12630 if (it
->current_x
< it
->first_visible_x
)
12631 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
12632 MOVE_TO_POS
| MOVE_TO_X
);
12634 row
->ascent
= it
->max_ascent
;
12635 row
->height
= it
->max_ascent
+ it
->max_descent
;
12636 row
->phys_ascent
= it
->max_phys_ascent
;
12637 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12639 /* This condition is for the case that we are called with current_x
12640 past last_visible_x. */
12641 while (it
->current_x
< max_x
)
12643 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
12645 /* Get the next display element. */
12646 if (!get_next_display_element (it
))
12649 /* Produce glyphs. */
12650 x_before
= it
->current_x
;
12651 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
12652 PRODUCE_GLYPHS (it
);
12654 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
12657 while (i
< nglyphs
)
12659 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12661 if (!it
->truncate_lines_p
12662 && x
+ glyph
->pixel_width
> max_x
)
12664 /* End of continued line or max_x reached. */
12665 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12669 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
12671 /* Glyph is at least partially visible. */
12673 if (x
< it
->first_visible_x
)
12674 it
->glyph_row
->x
= x
- it
->first_visible_x
;
12678 /* Glyph is off the left margin of the display area.
12679 Should not happen. */
12683 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12684 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12685 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12686 row
->phys_height
= max (row
->phys_height
,
12687 it
->max_phys_ascent
+ it
->max_phys_descent
);
12688 x
+= glyph
->pixel_width
;
12692 /* Stop if max_x reached. */
12696 /* Stop at line ends. */
12697 if (ITERATOR_AT_END_OF_LINE_P (it
))
12699 it
->continuation_lines_width
= 0;
12703 set_iterator_to_next (it
);
12705 /* Stop if truncating at the right edge. */
12706 if (it
->truncate_lines_p
12707 && it
->current_x
>= it
->last_visible_x
)
12709 /* Add truncation mark, but don't do it if the line is
12710 truncated at a padding space. */
12711 if (IT_CHARPOS (*it
) < it
->string_nchars
)
12713 if (!FRAME_WINDOW_P (it
->f
))
12714 produce_special_glyphs (it
, IT_TRUNCATION
);
12715 it
->glyph_row
->truncated_on_right_p
= 1;
12721 /* Maybe insert a truncation at the left. */
12722 if (it
->first_visible_x
12723 && IT_CHARPOS (*it
) > 0)
12725 if (!FRAME_WINDOW_P (it
->f
))
12726 insert_left_trunc_glyphs (it
);
12727 it
->glyph_row
->truncated_on_left_p
= 1;
12730 it
->face_id
= saved_face_id
;
12732 /* Value is number of columns displayed. */
12733 return it
->hpos
- hpos_at_start
;
12738 /* This is like a combination of memq and assq. Return 1 if PROPVAL
12739 appears as an element of LIST or as the car of an element of LIST.
12740 If PROPVAL is a list, compare each element against LIST in that
12741 way, and return 1 if any element of PROPVAL is found in LIST.
12742 Otherwise return 0. This function cannot quit. */
12745 invisible_p (propval
, list
)
12746 register Lisp_Object propval
;
12749 register Lisp_Object tail
, proptail
;
12750 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12752 register Lisp_Object tem
;
12754 if (EQ (propval
, tem
))
12756 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12759 if (CONSP (propval
))
12760 for (proptail
= propval
; CONSP (proptail
);
12761 proptail
= XCDR (proptail
))
12763 Lisp_Object propelt
;
12764 propelt
= XCAR (proptail
);
12765 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12767 register Lisp_Object tem
;
12769 if (EQ (propelt
, tem
))
12771 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12779 /* Return 1 if PROPVAL appears as the car of an element of LIST and
12780 the cdr of that element is non-nil. If PROPVAL is a list, check
12781 each element of PROPVAL in that way, and the first time some
12782 element is found, return 1 if the cdr of that element is non-nil.
12783 Otherwise return 0. This function cannot quit. */
12786 invisible_ellipsis_p (propval
, list
)
12787 register Lisp_Object propval
;
12790 register Lisp_Object tail
, proptail
;
12792 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12794 register Lisp_Object tem
;
12796 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12797 return ! NILP (XCDR (tem
));
12800 if (CONSP (propval
))
12801 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
12803 Lisp_Object propelt
;
12804 propelt
= XCAR (proptail
);
12805 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12807 register Lisp_Object tem
;
12809 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12810 return ! NILP (XCDR (tem
));
12819 /***********************************************************************
12821 ***********************************************************************/
12826 Vwith_echo_area_save_vector
= Qnil
;
12827 staticpro (&Vwith_echo_area_save_vector
);
12829 Vmessage_stack
= Qnil
;
12830 staticpro (&Vmessage_stack
);
12832 Qinhibit_redisplay
= intern ("inhibit-redisplay");
12833 staticpro (&Qinhibit_redisplay
);
12836 defsubr (&Sdump_glyph_matrix
);
12837 defsubr (&Sdump_glyph_row
);
12838 defsubr (&Sdump_tool_bar_row
);
12839 defsubr (&Strace_redisplay_toggle
);
12840 defsubr (&Strace_to_stderr
);
12843 staticpro (&Qmenu_bar_update_hook
);
12844 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
12846 staticpro (&Qoverriding_terminal_local_map
);
12847 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
12849 staticpro (&Qoverriding_local_map
);
12850 Qoverriding_local_map
= intern ("overriding-local-map");
12852 staticpro (&Qwindow_scroll_functions
);
12853 Qwindow_scroll_functions
= intern ("window-scroll-functions");
12855 staticpro (&Qredisplay_end_trigger_functions
);
12856 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
12858 staticpro (&Qinhibit_point_motion_hooks
);
12859 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
12861 QCdata
= intern (":data");
12862 staticpro (&QCdata
);
12863 Qdisplay
= intern ("display");
12864 staticpro (&Qdisplay
);
12865 Qspace_width
= intern ("space-width");
12866 staticpro (&Qspace_width
);
12867 Qraise
= intern ("raise");
12868 staticpro (&Qraise
);
12869 Qspace
= intern ("space");
12870 staticpro (&Qspace
);
12871 Qmargin
= intern ("margin");
12872 staticpro (&Qmargin
);
12873 Qleft_margin
= intern ("left-margin");
12874 staticpro (&Qleft_margin
);
12875 Qright_margin
= intern ("right-margin");
12876 staticpro (&Qright_margin
);
12877 Qalign_to
= intern ("align-to");
12878 staticpro (&Qalign_to
);
12879 QCalign_to
= intern (":align-to");
12880 staticpro (&QCalign_to
);
12881 Qrelative_width
= intern ("relative-width");
12882 staticpro (&Qrelative_width
);
12883 QCrelative_width
= intern (":relative-width");
12884 staticpro (&QCrelative_width
);
12885 QCrelative_height
= intern (":relative-height");
12886 staticpro (&QCrelative_height
);
12887 QCeval
= intern (":eval");
12888 staticpro (&QCeval
);
12889 Qwhen
= intern ("when");
12890 staticpro (&Qwhen
);
12891 QCfile
= intern (":file");
12892 staticpro (&QCfile
);
12893 Qfontified
= intern ("fontified");
12894 staticpro (&Qfontified
);
12895 Qfontification_functions
= intern ("fontification-functions");
12896 staticpro (&Qfontification_functions
);
12897 Qtrailing_whitespace
= intern ("trailing-whitespace");
12898 staticpro (&Qtrailing_whitespace
);
12899 Qimage
= intern ("image");
12900 staticpro (&Qimage
);
12902 last_arrow_position
= Qnil
;
12903 last_arrow_string
= Qnil
;
12904 staticpro (&last_arrow_position
);
12905 staticpro (&last_arrow_string
);
12907 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
12908 staticpro (&echo_buffer
[0]);
12909 staticpro (&echo_buffer
[1]);
12911 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
12912 staticpro (&echo_area_buffer
[0]);
12913 staticpro (&echo_area_buffer
[1]);
12915 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
12916 "Non-nil means highlight trailing whitespace.\n\
12917 The face used for trailing whitespace is `trailing-whitespace'.");
12918 Vshow_trailing_whitespace
= Qnil
;
12920 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
12921 "Non-nil means don't actually do any redisplay.\n\
12922 This is used for internal purposes.");
12923 Vinhibit_redisplay
= Qnil
;
12925 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
12926 "String (or mode line construct) included (normally) in `mode-line-format'.");
12927 Vglobal_mode_string
= Qnil
;
12929 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
12930 "Marker for where to display an arrow on top of the buffer text.\n\
12931 This must be the beginning of a line in order to work.\n\
12932 See also `overlay-arrow-string'.");
12933 Voverlay_arrow_position
= Qnil
;
12935 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
12936 "String to display as an arrow. See also `overlay-arrow-position'.");
12937 Voverlay_arrow_string
= Qnil
;
12939 DEFVAR_INT ("scroll-step", &scroll_step
,
12940 "*The number of lines to try scrolling a window by when point moves out.\n\
12941 If that fails to bring point back on frame, point is centered instead.\n\
12942 If this is zero, point is always centered after it moves off frame.");
12944 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
12945 "*Scroll up to this many lines, to bring point back on screen.\n\
12946 A value of zero means to scroll the text to center point vertically\n\
12948 scroll_conservatively
= 0;
12950 DEFVAR_INT ("scroll-margin", &scroll_margin
,
12951 "*Number of lines of margin at the top and bottom of a window.\n\
12952 Recenter the window whenever point gets within this many lines\n\
12953 of the top or bottom of the window.");
12957 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
12960 DEFVAR_BOOL ("truncate-partial-width-windows",
12961 &truncate_partial_width_windows
,
12962 "*Non-nil means truncate lines in all windows less than full frame wide.");
12963 truncate_partial_width_windows
= 1;
12965 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
12966 "*Non-nil means use inverse video for the mode line.");
12967 mode_line_inverse_video
= 1;
12969 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
12970 "*Maximum buffer size for which line number should be displayed.\n\
12971 If the buffer is bigger than this, the line number does not appear\n\
12972 in the mode line.");
12973 line_number_display_limit
= 1000000;
12975 DEFVAR_INT ("line-number-display-limit-width", &line_number_display_limit_width
,
12976 "*Maximum line width (in characters) for line number display.\n\
12977 If the average length of the lines near point is bigger than this, then the\n\
12978 line number may be omitted from the mode line.");
12979 line_number_display_limit_width
= 200;
12981 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
12982 "*Non-nil means highlight region even in nonselected windows.");
12983 highlight_nonselected_windows
= 0;
12985 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
12986 "Non-nil if more than one frame is visible on this display.\n\
12987 Minibuffer-only frames don't count, but iconified frames do.\n\
12988 This variable is not guaranteed to be accurate except while processing\n\
12989 `frame-title-format' and `icon-title-format'.");
12991 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
12992 "Template for displaying the title bar of visible frames.\n\
12993 \(Assuming the window manager supports this feature.)\n\
12994 This variable has the same structure as `mode-line-format' (which see),\n\
12995 and is used only on frames for which no explicit name has been set\n\
12996 \(see `modify-frame-parameters').");
12997 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
12998 "Template for displaying the title bar of an iconified frame.\n\
12999 \(Assuming the window manager supports this feature.)\n\
13000 This variable has the same structure as `mode-line-format' (which see),\n\
13001 and is used only on frames for which no explicit name has been set\n\
13002 \(see `modify-frame-parameters').");
13004 = Vframe_title_format
13005 = Fcons (intern ("multiple-frames"),
13006 Fcons (build_string ("%b"),
13007 Fcons (Fcons (build_string (""),
13008 Fcons (intern ("invocation-name"),
13009 Fcons (build_string ("@"),
13010 Fcons (intern ("system-name"),
13014 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13015 "Maximum number of lines to keep in the message log buffer.\n\
13016 If nil, disable message logging. If t, log messages but don't truncate\n\
13017 the buffer when it becomes large.");
13018 XSETFASTINT (Vmessage_log_max
, 50);
13020 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13021 "Functions called before redisplay, if window sizes have changed.\n\
13022 The value should be a list of functions that take one argument.\n\
13023 Just before redisplay, for each frame, if any of its windows have changed\n\
13024 size since the last redisplay, or have been split or deleted,\n\
13025 all the functions in the list are called, with the frame as argument.");
13026 Vwindow_size_change_functions
= Qnil
;
13028 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13029 "List of Functions to call before redisplaying a window with scrolling.\n\
13030 Each function is called with two arguments, the window\n\
13031 and its new display-start position. Note that the value of `window-end'\n\
13032 is not valid when these functions are called.");
13033 Vwindow_scroll_functions
= Qnil
;
13035 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13036 "*Non-nil means automatically resize tool-bars.\n\
13037 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13038 It decreases a tool-bar's height when it would display blank lines\n\
13040 auto_resize_tool_bars_p
= 1;
13042 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13043 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13044 auto_raise_tool_bar_buttons_p
= 1;
13046 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13047 "*Margin around tool-bar buttons in pixels.");
13048 tool_bar_button_margin
= 1;
13050 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13051 "Relief thickness of tool-bar buttons.");
13052 tool_bar_button_relief
= 3;
13054 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13055 "List of functions to call to fontify regions of text.\n\
13056 Each function is called with one argument POS. Functions must\n\
13057 fontify a region starting at POS in the current buffer, and give\n\
13058 fontified regions the property `fontified'.\n\
13059 This variable automatically becomes buffer-local when set.");
13060 Vfontification_functions
= Qnil
;
13061 Fmake_local_variable (Qfontification_functions
);
13063 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13064 &unibyte_display_via_language_environment
,
13065 "*Non-nil means display unibyte text according to language environment.\n\
13066 Specifically this means that unibyte non-ASCII characters\n\
13067 are displayed by converting them to the equivalent multibyte characters\n\
13068 according to the current language environment. As a result, they are\n\
13069 displayed according to the current fontset.");
13070 unibyte_display_via_language_environment
= 0;
13072 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13073 "*Maximum height for resizing mini-windows.\n\
13074 If a float, it specifies a fraction of the mini-window frame's height.\n\
13075 If an integer, it specifies a number of lines.\n\
13076 If nil, don't resize.");
13077 Vmax_mini_window_height
= make_float (0.25);
13079 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13080 &cursor_in_non_selected_windows
,
13081 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13082 Nil means don't display a cursor there.");
13083 cursor_in_non_selected_windows
= 1;
13085 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13086 "*Non-nil means scroll the display automatically to make point visible.");
13087 automatic_hscrolling_p
= 1;
13091 /* Initialize this module when Emacs starts. */
13096 Lisp_Object root_window
;
13097 struct window
*mini_w
;
13099 CHARPOS (this_line_start_pos
) = 0;
13101 mini_w
= XWINDOW (minibuf_window
);
13102 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13104 if (!noninteractive
)
13106 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13109 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13110 set_window_height (root_window
,
13111 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13113 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13114 set_window_height (minibuf_window
, 1, 0);
13116 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13117 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13119 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13120 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13121 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13123 /* The default ellipsis glyphs `...'. */
13124 for (i
= 0; i
< 3; ++i
)
13125 XSETFASTINT (default_invis_vector
[i
], '.');
13128 #ifdef HAVE_WINDOW_SYSTEM
13130 /* Allocate the buffer for frame titles. */
13132 frame_title_buf
= (char *) xmalloc (size
);
13133 frame_title_buf_end
= frame_title_buf
+ size
;
13134 frame_title_ptr
= NULL
;
13136 #endif /* HAVE_WINDOW_SYSTEM */