1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001
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. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define min(a, b) ((a) < (b) ? (a) : (b))
202 #define max(a, b) ((a) > (b) ? (a) : (b))
204 #define INFINITY 10000000
206 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
207 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
208 extern int pending_menu_activation
;
211 extern int interrupt_input
;
212 extern int command_loop_level
;
214 extern int minibuffer_auto_raise
;
216 extern Lisp_Object Qface
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
222 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
223 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
224 Lisp_Object Qredisplay_end_trigger_functions
;
225 Lisp_Object Qinhibit_point_motion_hooks
;
226 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
227 Lisp_Object Qfontified
;
228 Lisp_Object Qgrow_only
;
230 /* Functions called to fontify regions of text. */
232 Lisp_Object Vfontification_functions
;
233 Lisp_Object Qfontification_functions
;
235 /* Non-zero means draw tool bar buttons raised when the mouse moves
238 int auto_raise_tool_bar_buttons_p
;
240 /* Margin around tool bar buttons in pixels. */
242 Lisp_Object Vtool_bar_button_margin
;
244 /* Thickness of shadow to draw around tool bar buttons. */
246 int tool_bar_button_relief
;
248 /* Non-zero means automatically resize tool-bars so that all tool-bar
249 items are visible, and no blank lines remain. */
251 int auto_resize_tool_bars_p
;
253 /* Non-nil means don't actually do any redisplay. */
255 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
257 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
259 int inhibit_eval_during_redisplay
, Qinhibit_eval_during_redisplay
;
261 /* Names of text properties relevant for redisplay. */
263 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
264 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
266 /* Symbols used in text property values. */
268 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
269 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
271 extern Lisp_Object Qheight
;
273 /* Non-nil means highlight trailing whitespace. */
275 Lisp_Object Vshow_trailing_whitespace
;
277 /* Name of the face used to highlight trailing whitespace. */
279 Lisp_Object Qtrailing_whitespace
;
281 /* The symbol `image' which is the car of the lists used to represent
286 /* Non-zero means print newline to stdout before next mini-buffer
289 int noninteractive_need_newline
;
291 /* Non-zero means print newline to message log before next message. */
293 static int message_log_need_newline
;
296 /* The buffer position of the first character appearing entirely or
297 partially on the line of the selected window which contains the
298 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
299 redisplay optimization in redisplay_internal. */
301 static struct text_pos this_line_start_pos
;
303 /* Number of characters past the end of the line above, including the
304 terminating newline. */
306 static struct text_pos this_line_end_pos
;
308 /* The vertical positions and the height of this line. */
310 static int this_line_vpos
;
311 static int this_line_y
;
312 static int this_line_pixel_height
;
314 /* X position at which this display line starts. Usually zero;
315 negative if first character is partially visible. */
317 static int this_line_start_x
;
319 /* Buffer that this_line_.* variables are referring to. */
321 static struct buffer
*this_line_buffer
;
323 /* Nonzero means truncate lines in all windows less wide than the
326 int truncate_partial_width_windows
;
328 /* A flag to control how to display unibyte 8-bit character. */
330 int unibyte_display_via_language_environment
;
332 /* Nonzero means we have more than one non-mini-buffer-only frame.
333 Not guaranteed to be accurate except while parsing
334 frame-title-format. */
338 Lisp_Object Vglobal_mode_string
;
340 /* Marker for where to display an arrow on top of the buffer text. */
342 Lisp_Object Voverlay_arrow_position
;
344 /* String to display for the arrow. Only used on terminal frames. */
346 Lisp_Object Voverlay_arrow_string
;
348 /* Values of those variables at last redisplay. However, if
349 Voverlay_arrow_position is a marker, last_arrow_position is its
350 numerical position. */
352 static Lisp_Object last_arrow_position
, last_arrow_string
;
354 /* Like mode-line-format, but for the title bar on a visible frame. */
356 Lisp_Object Vframe_title_format
;
358 /* Like mode-line-format, but for the title bar on an iconified frame. */
360 Lisp_Object Vicon_title_format
;
362 /* List of functions to call when a window's size changes. These
363 functions get one arg, a frame on which one or more windows' sizes
366 static Lisp_Object Vwindow_size_change_functions
;
368 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
370 /* Nonzero if overlay arrow has been displayed once in this window. */
372 static int overlay_arrow_seen
;
374 /* Nonzero means highlight the region even in nonselected windows. */
376 int highlight_nonselected_windows
;
378 /* If cursor motion alone moves point off frame, try scrolling this
379 many lines up or down if that will bring it back. */
381 static int scroll_step
;
383 /* Non-0 means scroll just far enough to bring point back on the
384 screen, when appropriate. */
386 static int scroll_conservatively
;
388 /* Recenter the window whenever point gets within this many lines of
389 the top or bottom of the window. This value is translated into a
390 pixel value by multiplying it with CANON_Y_UNIT, which means that
391 there is really a fixed pixel height scroll margin. */
395 /* Number of windows showing the buffer of the selected window (or
396 another buffer with the same base buffer). keyboard.c refers to
401 /* Vector containing glyphs for an ellipsis `...'. */
403 static Lisp_Object default_invis_vector
[3];
405 /* Zero means display the mode-line/header-line/menu-bar in the default face
406 (this slightly odd definition is for compatibility with previous versions
407 of emacs), non-zero means display them using their respective faces.
409 This variable is deprecated. */
411 int mode_line_inverse_video
;
413 /* Prompt to display in front of the mini-buffer contents. */
415 Lisp_Object minibuf_prompt
;
417 /* Width of current mini-buffer prompt. Only set after display_line
418 of the line that contains the prompt. */
420 int minibuf_prompt_width
;
421 int minibuf_prompt_pixel_width
;
423 /* This is the window where the echo area message was displayed. It
424 is always a mini-buffer window, but it may not be the same window
425 currently active as a mini-buffer. */
427 Lisp_Object echo_area_window
;
429 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
430 pushes the current message and the value of
431 message_enable_multibyte on the stack, the function restore_message
432 pops the stack and displays MESSAGE again. */
434 Lisp_Object Vmessage_stack
;
436 /* Nonzero means multibyte characters were enabled when the echo area
437 message was specified. */
439 int message_enable_multibyte
;
441 /* True if we should redraw the mode lines on the next redisplay. */
443 int update_mode_lines
;
445 /* Nonzero if window sizes or contents have changed since last
446 redisplay that finished */
448 int windows_or_buffers_changed
;
450 /* Nonzero after display_mode_line if %l was used and it displayed a
453 int line_number_displayed
;
455 /* Maximum buffer size for which to display line numbers. */
457 Lisp_Object Vline_number_display_limit
;
459 /* line width to consider when repostioning for line number display */
461 static int line_number_display_limit_width
;
463 /* Number of lines to keep in the message log buffer. t means
464 infinite. nil means don't log at all. */
466 Lisp_Object Vmessage_log_max
;
468 /* The name of the *Messages* buffer, a string. */
470 static Lisp_Object Vmessages_buffer_name
;
472 /* Current, index 0, and last displayed echo area message. Either
473 buffers from echo_buffers, or nil to indicate no message. */
475 Lisp_Object echo_area_buffer
[2];
477 /* The buffers referenced from echo_area_buffer. */
479 static Lisp_Object echo_buffer
[2];
481 /* A vector saved used in with_area_buffer to reduce consing. */
483 static Lisp_Object Vwith_echo_area_save_vector
;
485 /* Non-zero means display_echo_area should display the last echo area
486 message again. Set by redisplay_preserve_echo_area. */
488 static int display_last_displayed_message_p
;
490 /* Nonzero if echo area is being used by print; zero if being used by
493 int message_buf_print
;
495 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
497 Lisp_Object Qinhibit_menubar_update
;
498 int inhibit_menubar_update
;
500 /* Maximum height for resizing mini-windows. Either a float
501 specifying a fraction of the available height, or an integer
502 specifying a number of lines. */
504 Lisp_Object Vmax_mini_window_height
;
506 /* Non-zero means messages should be displayed with truncated
507 lines instead of being continued. */
509 int message_truncate_lines
;
510 Lisp_Object Qmessage_truncate_lines
;
512 /* Non-zero means we want a hollow cursor in windows that are not
513 selected. Zero means there's no cursor in such windows. */
515 int cursor_in_non_selected_windows
;
517 /* A scratch glyph row with contents used for generating truncation
518 glyphs. Also used in direct_output_for_insert. */
520 #define MAX_SCRATCH_GLYPHS 100
521 struct glyph_row scratch_glyph_row
;
522 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
524 /* Ascent and height of the last line processed by move_it_to. */
526 static int last_max_ascent
, last_height
;
528 /* Non-zero if there's a help-echo in the echo area. */
530 int help_echo_showing_p
;
532 /* If >= 0, computed, exact values of mode-line and header-line height
533 to use in the macros CURRENT_MODE_LINE_HEIGHT and
534 CURRENT_HEADER_LINE_HEIGHT. */
536 int current_mode_line_height
, current_header_line_height
;
538 /* The maximum distance to look ahead for text properties. Values
539 that are too small let us call compute_char_face and similar
540 functions too often which is expensive. Values that are too large
541 let us call compute_char_face and alike too often because we
542 might not be interested in text properties that far away. */
544 #define TEXT_PROP_DISTANCE_LIMIT 100
548 /* Non-zero means print traces of redisplay if compiled with
551 int trace_redisplay_p
;
553 #endif /* GLYPH_DEBUG */
555 #ifdef DEBUG_TRACE_MOVE
556 /* Non-zero means trace with TRACE_MOVE to stderr. */
559 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
561 #define TRACE_MOVE(x) (void) 0
564 /* Non-zero means automatically scroll windows horizontally to make
567 int automatic_hscrolling_p
;
569 /* A list of symbols, one for each supported image type. */
571 Lisp_Object Vimage_types
;
573 /* The variable `resize-mini-windows'. If nil, don't resize
574 mini-windows. If t, always resize them to fit the text they
575 display. If `grow-only', let mini-windows grow only until they
578 Lisp_Object Vresize_mini_windows
;
580 /* Value returned from text property handlers (see below). */
585 HANDLED_RECOMPUTE_PROPS
,
586 HANDLED_OVERLAY_STRING_CONSUMED
,
590 /* A description of text properties that redisplay is interested
595 /* The name of the property. */
598 /* A unique index for the property. */
601 /* A handler function called to set up iterator IT from the property
602 at IT's current position. Value is used to steer handle_stop. */
603 enum prop_handled (*handler
) P_ ((struct it
*it
));
606 static enum prop_handled handle_face_prop
P_ ((struct it
*));
607 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
608 static enum prop_handled handle_display_prop
P_ ((struct it
*));
609 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
610 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
611 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
613 /* Properties handled by iterators. */
615 static struct props it_props
[] =
617 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
618 /* Handle `face' before `display' because some sub-properties of
619 `display' need to know the face. */
620 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
621 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
622 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
623 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
627 /* Value is the position described by X. If X is a marker, value is
628 the marker_position of X. Otherwise, value is X. */
630 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
632 /* Enumeration returned by some move_it_.* functions internally. */
636 /* Not used. Undefined value. */
639 /* Move ended at the requested buffer position or ZV. */
640 MOVE_POS_MATCH_OR_ZV
,
642 /* Move ended at the requested X pixel position. */
645 /* Move within a line ended at the end of a line that must be
649 /* Move within a line ended at the end of a line that would
650 be displayed truncated. */
653 /* Move within a line ended at a line end. */
659 /* Function prototypes. */
661 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
662 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
663 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
664 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
665 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
666 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
667 static int invisible_text_between_p
P_ ((struct it
*, int, int));
668 static int next_element_from_ellipsis
P_ ((struct it
*));
669 static void pint2str
P_ ((char *, int, int));
670 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
672 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
673 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
674 static void store_frame_title_char
P_ ((char));
675 static int store_frame_title
P_ ((unsigned char *, int, int));
676 static void x_consider_frame_title
P_ ((Lisp_Object
));
677 static void handle_stop
P_ ((struct it
*));
678 static int tool_bar_lines_needed
P_ ((struct frame
*));
679 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
680 static void ensure_echo_area_buffers
P_ ((void));
681 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
683 struct glyph_row
*));
684 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
685 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
686 static int with_echo_area_buffer
P_ ((struct window
*, int,
687 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
688 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
689 static void clear_garbaged_frames
P_ ((void));
690 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
691 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
692 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
693 static int display_echo_area
P_ ((struct window
*));
694 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
695 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
696 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
697 static int string_char_and_length
P_ ((unsigned char *, int, int *));
698 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
700 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
701 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
702 static void insert_left_trunc_glyphs
P_ ((struct it
*));
703 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
704 static void extend_face_to_end_of_line
P_ ((struct it
*));
705 static int append_space
P_ ((struct it
*, int));
706 static void make_cursor_line_fully_visible
P_ ((struct window
*));
707 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
708 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
709 static int trailing_whitespace_p
P_ ((int));
710 static int message_log_check_duplicate
P_ ((int, int, int, int));
711 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
712 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
713 static void push_it
P_ ((struct it
*));
714 static void pop_it
P_ ((struct it
*));
715 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
716 static void redisplay_internal
P_ ((int));
717 static int echo_area_display
P_ ((int));
718 static void redisplay_windows
P_ ((Lisp_Object
));
719 static void redisplay_window
P_ ((Lisp_Object
, int));
720 static void update_menu_bar
P_ ((struct frame
*, int));
721 static int try_window_reusing_current_matrix
P_ ((struct window
*));
722 static int try_window_id
P_ ((struct window
*));
723 static int display_line
P_ ((struct it
*));
724 static int display_mode_lines
P_ ((struct window
*));
725 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
726 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
727 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
728 static void display_menu_bar
P_ ((struct window
*));
729 static int display_count_lines
P_ ((int, int, int, int, int *));
730 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
731 int, int, struct it
*, int, int, int, int));
732 static void compute_line_metrics
P_ ((struct it
*));
733 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
734 static int get_overlay_strings
P_ ((struct it
*));
735 static void next_overlay_string
P_ ((struct it
*));
736 static void reseat
P_ ((struct it
*, struct text_pos
, int));
737 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
738 static void back_to_previous_visible_line_start
P_ ((struct it
*));
739 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
740 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
741 static int next_element_from_display_vector
P_ ((struct it
*));
742 static int next_element_from_string
P_ ((struct it
*));
743 static int next_element_from_c_string
P_ ((struct it
*));
744 static int next_element_from_buffer
P_ ((struct it
*));
745 static int next_element_from_composition
P_ ((struct it
*));
746 static int next_element_from_image
P_ ((struct it
*));
747 static int next_element_from_stretch
P_ ((struct it
*));
748 static void load_overlay_strings
P_ ((struct it
*));
749 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
750 struct display_pos
*));
751 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
752 Lisp_Object
, int, int, int, int));
753 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
755 void move_it_vertically_backward
P_ ((struct it
*, int));
756 static void init_to_row_start
P_ ((struct it
*, struct window
*,
757 struct glyph_row
*));
758 static void init_to_row_end
P_ ((struct it
*, struct window
*,
759 struct glyph_row
*));
760 static void back_to_previous_line_start
P_ ((struct it
*));
761 static int forward_to_next_line_start
P_ ((struct it
*, int *));
762 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
764 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
765 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
766 static int number_of_chars
P_ ((unsigned char *, int));
767 static void compute_stop_pos
P_ ((struct it
*));
768 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
770 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
771 static int next_overlay_change
P_ ((int));
772 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
773 Lisp_Object
, struct text_pos
*,
775 static int underlying_face_id
P_ ((struct it
*));
776 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
779 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
780 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
782 #ifdef HAVE_WINDOW_SYSTEM
784 static void update_tool_bar
P_ ((struct frame
*, int));
785 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
786 static int redisplay_tool_bar
P_ ((struct frame
*));
787 static void display_tool_bar_line
P_ ((struct it
*));
789 #endif /* HAVE_WINDOW_SYSTEM */
792 /***********************************************************************
793 Window display dimensions
794 ***********************************************************************/
796 /* Return the window-relative maximum y + 1 for glyph rows displaying
797 text in window W. This is the height of W minus the height of a
798 mode line, if any. */
801 window_text_bottom_y (w
)
804 struct frame
*f
= XFRAME (w
->frame
);
805 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
807 if (WINDOW_WANTS_MODELINE_P (w
))
808 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
813 /* Return the pixel width of display area AREA of window W. AREA < 0
814 means return the total width of W, not including bitmap areas to
815 the left and right of the window. */
818 window_box_width (w
, area
)
822 struct frame
*f
= XFRAME (w
->frame
);
823 int width
= XFASTINT (w
->width
);
825 if (!w
->pseudo_window_p
)
827 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
829 if (area
== TEXT_AREA
)
831 if (INTEGERP (w
->left_margin_width
))
832 width
-= XFASTINT (w
->left_margin_width
);
833 if (INTEGERP (w
->right_margin_width
))
834 width
-= XFASTINT (w
->right_margin_width
);
836 else if (area
== LEFT_MARGIN_AREA
)
837 width
= (INTEGERP (w
->left_margin_width
)
838 ? XFASTINT (w
->left_margin_width
) : 0);
839 else if (area
== RIGHT_MARGIN_AREA
)
840 width
= (INTEGERP (w
->right_margin_width
)
841 ? XFASTINT (w
->right_margin_width
) : 0);
844 return width
* CANON_X_UNIT (f
);
848 /* Return the pixel height of the display area of window W, not
849 including mode lines of W, if any.. */
852 window_box_height (w
)
855 struct frame
*f
= XFRAME (w
->frame
);
856 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
858 xassert (height
>= 0);
860 /* Note: the code below that determines the mode-line/header-line
861 height is essentially the same as that contained in the macro
862 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
863 the appropriate glyph row has its `mode_line_p' flag set,
864 and if it doesn't, uses estimate_mode_line_height instead. */
866 if (WINDOW_WANTS_MODELINE_P (w
))
868 struct glyph_row
*ml_row
869 = (w
->current_matrix
&& w
->current_matrix
->rows
870 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
872 if (ml_row
&& ml_row
->mode_line_p
)
873 height
-= ml_row
->height
;
875 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
878 if (WINDOW_WANTS_HEADER_LINE_P (w
))
880 struct glyph_row
*hl_row
881 = (w
->current_matrix
&& w
->current_matrix
->rows
882 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
884 if (hl_row
&& hl_row
->mode_line_p
)
885 height
-= hl_row
->height
;
887 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
894 /* Return the frame-relative coordinate of the left edge of display
895 area AREA of window W. AREA < 0 means return the left edge of the
896 whole window, to the right of any bitmap area at the left side of
900 window_box_left (w
, area
)
904 struct frame
*f
= XFRAME (w
->frame
);
905 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
907 if (!w
->pseudo_window_p
)
909 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
910 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
912 if (area
== TEXT_AREA
)
913 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
914 else if (area
== RIGHT_MARGIN_AREA
)
915 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
916 + window_box_width (w
, TEXT_AREA
));
923 /* Return the frame-relative coordinate of the right edge of display
924 area AREA of window W. AREA < 0 means return the left edge of the
925 whole window, to the left of any bitmap area at the right side of
929 window_box_right (w
, area
)
933 return window_box_left (w
, area
) + window_box_width (w
, area
);
937 /* Get the bounding box of the display area AREA of window W, without
938 mode lines, in frame-relative coordinates. AREA < 0 means the
939 whole window, not including bitmap areas to the left and right of
940 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
941 coordinates of the upper-left corner of the box. Return in
942 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
945 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
948 int *box_x
, *box_y
, *box_width
, *box_height
;
950 struct frame
*f
= XFRAME (w
->frame
);
952 *box_width
= window_box_width (w
, area
);
953 *box_height
= window_box_height (w
);
954 *box_x
= window_box_left (w
, area
);
955 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
956 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
957 if (WINDOW_WANTS_HEADER_LINE_P (w
))
958 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
962 /* Get the bounding box of the display area AREA of window W, without
963 mode lines. AREA < 0 means the whole window, not including bitmap
964 areas to the left and right of the window. Return in *TOP_LEFT_X
965 and TOP_LEFT_Y the frame-relative pixel coordinates of the
966 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
967 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
971 window_box_edges (w
, area
, top_left_x
, top_left_y
,
972 bottom_right_x
, bottom_right_y
)
975 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
977 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
979 *bottom_right_x
+= *top_left_x
;
980 *bottom_right_y
+= *top_left_y
;
985 /***********************************************************************
987 ***********************************************************************/
989 /* Return the bottom y-position of the line the iterator IT is in.
990 This can modify IT's settings. */
996 int line_height
= it
->max_ascent
+ it
->max_descent
;
997 int line_top_y
= it
->current_y
;
999 if (line_height
== 0)
1002 line_height
= last_height
;
1003 else if (IT_CHARPOS (*it
) < ZV
)
1005 move_it_by_lines (it
, 1, 1);
1006 line_height
= (it
->max_ascent
|| it
->max_descent
1007 ? it
->max_ascent
+ it
->max_descent
1012 struct glyph_row
*row
= it
->glyph_row
;
1014 /* Use the default character height. */
1015 it
->glyph_row
= NULL
;
1016 it
->what
= IT_CHARACTER
;
1019 PRODUCE_GLYPHS (it
);
1020 line_height
= it
->ascent
+ it
->descent
;
1021 it
->glyph_row
= row
;
1025 return line_top_y
+ line_height
;
1029 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1030 1 if POS is visible and the line containing POS is fully visible.
1031 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1032 and header-lines heights. */
1035 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1037 int charpos
, *fully
, exact_mode_line_heights_p
;
1040 struct text_pos top
;
1042 struct buffer
*old_buffer
= NULL
;
1044 if (XBUFFER (w
->buffer
) != current_buffer
)
1046 old_buffer
= current_buffer
;
1047 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1050 *fully
= visible_p
= 0;
1051 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1053 /* Compute exact mode line heights, if requested. */
1054 if (exact_mode_line_heights_p
)
1056 if (WINDOW_WANTS_MODELINE_P (w
))
1057 current_mode_line_height
1058 = display_mode_line (w
, MODE_LINE_FACE_ID
,
1059 current_buffer
->mode_line_format
);
1061 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1062 current_header_line_height
1063 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1064 current_buffer
->header_line_format
);
1067 start_display (&it
, w
, top
);
1068 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1069 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1071 /* Note that we may overshoot because of invisible text. */
1072 if (IT_CHARPOS (it
) >= charpos
)
1074 int top_y
= it
.current_y
;
1075 int bottom_y
= line_bottom_y (&it
);
1076 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1078 if (top_y
< window_top_y
)
1079 visible_p
= bottom_y
> window_top_y
;
1080 else if (top_y
< it
.last_visible_y
)
1083 *fully
= bottom_y
<= it
.last_visible_y
;
1086 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1088 move_it_by_lines (&it
, 1, 0);
1089 if (charpos
< IT_CHARPOS (it
))
1097 set_buffer_internal_1 (old_buffer
);
1099 current_header_line_height
= current_mode_line_height
= -1;
1104 /* Return the next character from STR which is MAXLEN bytes long.
1105 Return in *LEN the length of the character. This is like
1106 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1107 we find one, we return a `?', but with the length of the invalid
1111 string_char_and_length (str
, maxlen
, len
)
1117 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1118 if (!CHAR_VALID_P (c
, 1))
1119 /* We may not change the length here because other places in Emacs
1120 don't use this function, i.e. they silently accept invalid
1129 /* Given a position POS containing a valid character and byte position
1130 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1132 static struct text_pos
1133 string_pos_nchars_ahead (pos
, string
, nchars
)
1134 struct text_pos pos
;
1138 xassert (STRINGP (string
) && nchars
>= 0);
1140 if (STRING_MULTIBYTE (string
))
1142 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1143 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1148 string_char_and_length (p
, rest
, &len
);
1149 p
+= len
, rest
-= len
;
1150 xassert (rest
>= 0);
1152 BYTEPOS (pos
) += len
;
1156 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1162 /* Value is the text position, i.e. character and byte position,
1163 for character position CHARPOS in STRING. */
1165 static INLINE
struct text_pos
1166 string_pos (charpos
, string
)
1170 struct text_pos pos
;
1171 xassert (STRINGP (string
));
1172 xassert (charpos
>= 0);
1173 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1178 /* Value is a text position, i.e. character and byte position, for
1179 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1180 means recognize multibyte characters. */
1182 static struct text_pos
1183 c_string_pos (charpos
, s
, multibyte_p
)
1188 struct text_pos pos
;
1190 xassert (s
!= NULL
);
1191 xassert (charpos
>= 0);
1195 int rest
= strlen (s
), len
;
1197 SET_TEXT_POS (pos
, 0, 0);
1200 string_char_and_length (s
, rest
, &len
);
1201 s
+= len
, rest
-= len
;
1202 xassert (rest
>= 0);
1204 BYTEPOS (pos
) += len
;
1208 SET_TEXT_POS (pos
, charpos
, charpos
);
1214 /* Value is the number of characters in C string S. MULTIBYTE_P
1215 non-zero means recognize multibyte characters. */
1218 number_of_chars (s
, multibyte_p
)
1226 int rest
= strlen (s
), len
;
1227 unsigned char *p
= (unsigned char *) s
;
1229 for (nchars
= 0; rest
> 0; ++nchars
)
1231 string_char_and_length (p
, rest
, &len
);
1232 rest
-= len
, p
+= len
;
1236 nchars
= strlen (s
);
1242 /* Compute byte position NEWPOS->bytepos corresponding to
1243 NEWPOS->charpos. POS is a known position in string STRING.
1244 NEWPOS->charpos must be >= POS.charpos. */
1247 compute_string_pos (newpos
, pos
, string
)
1248 struct text_pos
*newpos
, pos
;
1251 xassert (STRINGP (string
));
1252 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1254 if (STRING_MULTIBYTE (string
))
1255 *newpos
= string_pos_nchars_ahead (pos
, string
,
1256 CHARPOS (*newpos
) - CHARPOS (pos
));
1258 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1263 /***********************************************************************
1264 Lisp form evaluation
1265 ***********************************************************************/
1267 /* Error handler for safe_eval and safe_call. */
1270 safe_eval_handler (arg
)
1273 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1278 /* Evaluate SEXPR and return the result, or nil if something went
1287 if (inhibit_eval_during_redisplay
)
1291 int count
= BINDING_STACK_SIZE ();
1292 struct gcpro gcpro1
;
1295 specbind (Qinhibit_redisplay
, Qt
);
1296 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1299 val
= unbind_to (count
, val
);
1306 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1307 Return the result, or nil if something went wrong. */
1310 safe_call (nargs
, args
)
1316 if (inhibit_eval_during_redisplay
)
1320 int count
= BINDING_STACK_SIZE ();
1321 struct gcpro gcpro1
;
1324 gcpro1
.nvars
= nargs
;
1325 specbind (Qinhibit_redisplay
, Qt
);
1326 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1329 val
= unbind_to (count
, val
);
1336 /* Call function FN with one argument ARG.
1337 Return the result, or nil if something went wrong. */
1340 safe_call1 (fn
, arg
)
1341 Lisp_Object fn
, arg
;
1343 Lisp_Object args
[2];
1346 return safe_call (2, args
);
1351 /***********************************************************************
1353 ***********************************************************************/
1357 /* Define CHECK_IT to perform sanity checks on iterators.
1358 This is for debugging. It is too slow to do unconditionally. */
1364 if (it
->method
== next_element_from_string
)
1366 xassert (STRINGP (it
->string
));
1367 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1369 else if (it
->method
== next_element_from_buffer
)
1371 /* Check that character and byte positions agree. */
1372 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1376 xassert (it
->current
.dpvec_index
>= 0);
1378 xassert (it
->current
.dpvec_index
< 0);
1381 #define CHECK_IT(IT) check_it ((IT))
1385 #define CHECK_IT(IT) (void) 0
1392 /* Check that the window end of window W is what we expect it
1393 to be---the last row in the current matrix displaying text. */
1396 check_window_end (w
)
1399 if (!MINI_WINDOW_P (w
)
1400 && !NILP (w
->window_end_valid
))
1402 struct glyph_row
*row
;
1403 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1404 XFASTINT (w
->window_end_vpos
)),
1406 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1407 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1411 #define CHECK_WINDOW_END(W) check_window_end ((W))
1413 #else /* not GLYPH_DEBUG */
1415 #define CHECK_WINDOW_END(W) (void) 0
1417 #endif /* not GLYPH_DEBUG */
1421 /***********************************************************************
1422 Iterator initialization
1423 ***********************************************************************/
1425 /* Initialize IT for displaying current_buffer in window W, starting
1426 at character position CHARPOS. CHARPOS < 0 means that no buffer
1427 position is specified which is useful when the iterator is assigned
1428 a position later. BYTEPOS is the byte position corresponding to
1429 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1431 If ROW is not null, calls to produce_glyphs with IT as parameter
1432 will produce glyphs in that row.
1434 BASE_FACE_ID is the id of a base face to use. It must be one of
1435 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1436 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1437 displaying the tool-bar.
1439 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1440 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1441 corresponding mode line glyph row of the desired matrix of W. */
1444 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1447 int charpos
, bytepos
;
1448 struct glyph_row
*row
;
1449 enum face_id base_face_id
;
1451 int highlight_region_p
;
1453 /* Some precondition checks. */
1454 xassert (w
!= NULL
&& it
!= NULL
);
1455 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1457 /* If face attributes have been changed since the last redisplay,
1458 free realized faces now because they depend on face definitions
1459 that might have changed. */
1460 if (face_change_count
)
1462 face_change_count
= 0;
1463 free_all_realized_faces (Qnil
);
1466 /* Use one of the mode line rows of W's desired matrix if
1470 if (base_face_id
== MODE_LINE_FACE_ID
)
1471 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1472 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1473 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1477 bzero (it
, sizeof *it
);
1478 it
->current
.overlay_string_index
= -1;
1479 it
->current
.dpvec_index
= -1;
1480 it
->base_face_id
= base_face_id
;
1482 /* The window in which we iterate over current_buffer: */
1483 XSETWINDOW (it
->window
, w
);
1485 it
->f
= XFRAME (w
->frame
);
1487 /* Extra space between lines (on window systems only). */
1488 if (base_face_id
== DEFAULT_FACE_ID
1489 && FRAME_WINDOW_P (it
->f
))
1491 if (NATNUMP (current_buffer
->extra_line_spacing
))
1492 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1493 else if (it
->f
->extra_line_spacing
> 0)
1494 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1497 /* If realized faces have been removed, e.g. because of face
1498 attribute changes of named faces, recompute them. When running
1499 in batch mode, the face cache of Vterminal_frame is null. If
1500 we happen to get called, make a dummy face cache. */
1505 FRAME_FACE_CACHE (it
->f
) == NULL
)
1506 init_frame_faces (it
->f
);
1507 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1508 recompute_basic_faces (it
->f
);
1510 /* Current value of the `space-width', and 'height' properties. */
1511 it
->space_width
= Qnil
;
1512 it
->font_height
= Qnil
;
1514 /* Are control characters displayed as `^C'? */
1515 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1517 /* -1 means everything between a CR and the following line end
1518 is invisible. >0 means lines indented more than this value are
1520 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1521 ? XFASTINT (current_buffer
->selective_display
)
1522 : (!NILP (current_buffer
->selective_display
)
1524 it
->selective_display_ellipsis_p
1525 = !NILP (current_buffer
->selective_display_ellipses
);
1527 /* Display table to use. */
1528 it
->dp
= window_display_table (w
);
1530 /* Are multibyte characters enabled in current_buffer? */
1531 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1533 /* Non-zero if we should highlight the region. */
1535 = (!NILP (Vtransient_mark_mode
)
1536 && !NILP (current_buffer
->mark_active
)
1537 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1539 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1540 start and end of a visible region in window IT->w. Set both to
1541 -1 to indicate no region. */
1542 if (highlight_region_p
1543 /* Maybe highlight only in selected window. */
1544 && (/* Either show region everywhere. */
1545 highlight_nonselected_windows
1546 /* Or show region in the selected window. */
1547 || w
== XWINDOW (selected_window
)
1548 /* Or show the region if we are in the mini-buffer and W is
1549 the window the mini-buffer refers to. */
1550 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1551 && WINDOWP (Vminibuf_scroll_window
)
1552 && w
== XWINDOW (Vminibuf_scroll_window
))))
1554 int charpos
= marker_position (current_buffer
->mark
);
1555 it
->region_beg_charpos
= min (PT
, charpos
);
1556 it
->region_end_charpos
= max (PT
, charpos
);
1559 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1561 /* Get the position at which the redisplay_end_trigger hook should
1562 be run, if it is to be run at all. */
1563 if (MARKERP (w
->redisplay_end_trigger
)
1564 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1565 it
->redisplay_end_trigger_charpos
1566 = marker_position (w
->redisplay_end_trigger
);
1567 else if (INTEGERP (w
->redisplay_end_trigger
))
1568 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1570 /* Correct bogus values of tab_width. */
1571 it
->tab_width
= XINT (current_buffer
->tab_width
);
1572 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1575 /* Are lines in the display truncated? */
1576 it
->truncate_lines_p
1577 = (base_face_id
!= DEFAULT_FACE_ID
1578 || XINT (it
->w
->hscroll
)
1579 || (truncate_partial_width_windows
1580 && !WINDOW_FULL_WIDTH_P (it
->w
))
1581 || !NILP (current_buffer
->truncate_lines
));
1583 /* Get dimensions of truncation and continuation glyphs. These are
1584 displayed as bitmaps under X, so we don't need them for such
1586 if (!FRAME_WINDOW_P (it
->f
))
1588 if (it
->truncate_lines_p
)
1590 /* We will need the truncation glyph. */
1591 xassert (it
->glyph_row
== NULL
);
1592 produce_special_glyphs (it
, IT_TRUNCATION
);
1593 it
->truncation_pixel_width
= it
->pixel_width
;
1597 /* We will need the continuation glyph. */
1598 xassert (it
->glyph_row
== NULL
);
1599 produce_special_glyphs (it
, IT_CONTINUATION
);
1600 it
->continuation_pixel_width
= it
->pixel_width
;
1603 /* Reset these values to zero becaue the produce_special_glyphs
1604 above has changed them. */
1605 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1606 it
->phys_ascent
= it
->phys_descent
= 0;
1609 /* Set this after getting the dimensions of truncation and
1610 continuation glyphs, so that we don't produce glyphs when calling
1611 produce_special_glyphs, above. */
1612 it
->glyph_row
= row
;
1613 it
->area
= TEXT_AREA
;
1615 /* Get the dimensions of the display area. The display area
1616 consists of the visible window area plus a horizontally scrolled
1617 part to the left of the window. All x-values are relative to the
1618 start of this total display area. */
1619 if (base_face_id
!= DEFAULT_FACE_ID
)
1621 /* Mode lines, menu bar in terminal frames. */
1622 it
->first_visible_x
= 0;
1623 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1628 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1629 it
->last_visible_x
= (it
->first_visible_x
1630 + window_box_width (w
, TEXT_AREA
));
1632 /* If we truncate lines, leave room for the truncator glyph(s) at
1633 the right margin. Otherwise, leave room for the continuation
1634 glyph(s). Truncation and continuation glyphs are not inserted
1635 for window-based redisplay. */
1636 if (!FRAME_WINDOW_P (it
->f
))
1638 if (it
->truncate_lines_p
)
1639 it
->last_visible_x
-= it
->truncation_pixel_width
;
1641 it
->last_visible_x
-= it
->continuation_pixel_width
;
1644 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1645 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1648 /* Leave room for a border glyph. */
1649 if (!FRAME_WINDOW_P (it
->f
)
1650 && !WINDOW_RIGHTMOST_P (it
->w
))
1651 it
->last_visible_x
-= 1;
1653 it
->last_visible_y
= window_text_bottom_y (w
);
1655 /* For mode lines and alike, arrange for the first glyph having a
1656 left box line if the face specifies a box. */
1657 if (base_face_id
!= DEFAULT_FACE_ID
)
1661 it
->face_id
= base_face_id
;
1663 /* If we have a boxed mode line, make the first character appear
1664 with a left box line. */
1665 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1666 if (face
->box
!= FACE_NO_BOX
)
1667 it
->start_of_box_run_p
= 1;
1670 /* If a buffer position was specified, set the iterator there,
1671 getting overlays and face properties from that position. */
1674 it
->end_charpos
= ZV
;
1676 IT_CHARPOS (*it
) = charpos
;
1678 /* Compute byte position if not specified. */
1680 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1682 IT_BYTEPOS (*it
) = bytepos
;
1684 /* Compute faces etc. */
1685 reseat (it
, it
->current
.pos
, 1);
1692 /* Initialize IT for the display of window W with window start POS. */
1695 start_display (it
, w
, pos
)
1698 struct text_pos pos
;
1700 int start_at_line_beg_p
;
1701 struct glyph_row
*row
;
1702 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1705 row
= w
->desired_matrix
->rows
+ first_vpos
;
1706 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1707 first_y
= it
->current_y
;
1709 /* If window start is not at a line start, move back to the line
1710 start. This makes sure that we take continuation lines into
1712 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1713 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1714 if (!start_at_line_beg_p
)
1715 reseat_at_previous_visible_line_start (it
);
1717 /* If window start is not at a line start, skip forward to POS to
1718 get the correct continuation_lines_width and current_x. */
1719 if (!start_at_line_beg_p
)
1721 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1723 /* If lines are continued, this line may end in the middle of a
1724 multi-glyph character (e.g. a control character displayed as
1725 \003, or in the middle of an overlay string). In this case
1726 move_it_to above will not have taken us to the start of
1727 the continuation line but to the end of the continued line. */
1728 if (!it
->truncate_lines_p
)
1730 if (it
->current_x
> 0)
1732 if (it
->current
.dpvec_index
>= 0
1733 || it
->current
.overlay_string_index
>= 0)
1735 set_iterator_to_next (it
, 1);
1736 move_it_in_display_line_to (it
, -1, -1, 0);
1739 it
->continuation_lines_width
+= it
->current_x
;
1742 /* We're starting a new display line, not affected by the
1743 height of the continued line, so clear the appropriate
1744 fields in the iterator structure. */
1745 it
->max_ascent
= it
->max_descent
= 0;
1746 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1749 it
->current_y
= first_y
;
1751 it
->current_x
= it
->hpos
= 0;
1754 #if 0 /* Don't assert the following because start_display is sometimes
1755 called intentionally with a window start that is not at a
1756 line start. Please leave this code in as a comment. */
1758 /* Window start should be on a line start, now. */
1759 xassert (it
->continuation_lines_width
1760 || IT_CHARPOS (it
) == BEGV
1761 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1766 /* Return 1 if POS is a position in ellipses displayed for invisible
1767 text. W is the window we display, for text property lookup. */
1770 in_ellipses_for_invisible_text_p (pos
, w
)
1771 struct display_pos
*pos
;
1774 Lisp_Object prop
, window
;
1776 int charpos
= CHARPOS (pos
->pos
);
1778 /* If POS specifies a position in a display vector, this might
1779 be for an ellipsis displayed for invisible text. We won't
1780 get the iterator set up for delivering that ellipsis unless
1781 we make sure that it gets aware of the invisible text. */
1782 if (pos
->dpvec_index
>= 0
1783 && pos
->overlay_string_index
< 0
1784 && CHARPOS (pos
->string_pos
) < 0
1786 && (XSETWINDOW (window
, w
),
1787 prop
= Fget_char_property (make_number (charpos
),
1788 Qinvisible
, window
),
1789 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1791 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1793 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
1794 && TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
))
1802 /* Initialize IT for stepping through current_buffer in window W,
1803 starting at position POS that includes overlay string and display
1804 vector/ control character translation position information. */
1807 init_from_display_pos (it
, w
, pos
)
1810 struct display_pos
*pos
;
1812 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1814 /* If POS specifies a position in a display vector, this might
1815 be for an ellipsis displayed for invisible text. We won't
1816 get the iterator set up for delivering that ellipsis unless
1817 we make sure that it gets aware of the invisible text. */
1818 if (in_ellipses_for_invisible_text_p (pos
, w
))
1824 /* Keep in mind: the call to reseat in init_iterator skips invisible
1825 text, so we might end up at a position different from POS. This
1826 is only a problem when POS is a row start after a newline and an
1827 overlay starts there with an after-string, and the overlay has an
1828 invisible property. Since we don't skip invisible text in
1829 display_line and elsewhere immediately after consuming the
1830 newline before the row start, such a POS will not be in a string,
1831 but the call to init_iterator below will move us to the
1833 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1835 /* If position is within an overlay string, set up IT to
1836 the right overlay string. */
1837 if (pos
->overlay_string_index
>= 0)
1841 /* We already have the first chunk of overlay strings in
1842 IT->overlay_strings. Load more until the one for
1843 pos->overlay_string_index is in IT->overlay_strings. */
1844 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1846 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1847 it
->current
.overlay_string_index
= 0;
1850 load_overlay_strings (it
);
1851 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1855 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1856 relative_index
= (it
->current
.overlay_string_index
1857 % OVERLAY_STRING_CHUNK_SIZE
);
1858 it
->string
= it
->overlay_strings
[relative_index
];
1859 xassert (STRINGP (it
->string
));
1860 it
->current
.string_pos
= pos
->string_pos
;
1861 it
->method
= next_element_from_string
;
1863 else if (it
->current
.overlay_string_index
>= 0)
1865 /* If POS says we're already after an overlay string ending at
1866 POS, make sure to pop the iterator because it will be in
1867 front of that overlay string. When POS is ZV, we've thereby
1868 also ``processed'' overlay strings at ZV. */
1871 it
->current
.overlay_string_index
= -1;
1872 it
->method
= next_element_from_buffer
;
1873 if (CHARPOS (pos
->pos
) == ZV
)
1874 it
->overlay_strings_at_end_processed_p
= 1;
1877 if (CHARPOS (pos
->string_pos
) >= 0)
1879 /* Recorded position is not in an overlay string, but in another
1880 string. This can only be a string from a `display' property.
1881 IT should already be filled with that string. */
1882 it
->current
.string_pos
= pos
->string_pos
;
1883 xassert (STRINGP (it
->string
));
1886 /* Restore position in display vector translations, control
1887 character translations or ellipses. */
1888 if (pos
->dpvec_index
>= 0)
1890 if (it
->dpvec
== NULL
)
1891 get_next_display_element (it
);
1892 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1893 it
->current
.dpvec_index
= pos
->dpvec_index
;
1900 /* Initialize IT for stepping through current_buffer in window W
1901 starting at ROW->start. */
1904 init_to_row_start (it
, w
, row
)
1907 struct glyph_row
*row
;
1909 init_from_display_pos (it
, w
, &row
->start
);
1910 it
->continuation_lines_width
= row
->continuation_lines_width
;
1915 /* Initialize IT for stepping through current_buffer in window W
1916 starting in the line following ROW, i.e. starting at ROW->end. */
1919 init_to_row_end (it
, w
, row
)
1922 struct glyph_row
*row
;
1924 init_from_display_pos (it
, w
, &row
->end
);
1926 if (row
->continued_p
)
1927 it
->continuation_lines_width
= (row
->continuation_lines_width
1928 + row
->pixel_width
);
1935 /***********************************************************************
1937 ***********************************************************************/
1939 /* Called when IT reaches IT->stop_charpos. Handle text property and
1940 overlay changes. Set IT->stop_charpos to the next position where
1947 enum prop_handled handled
;
1948 int handle_overlay_change_p
= 1;
1952 it
->current
.dpvec_index
= -1;
1956 handled
= HANDLED_NORMALLY
;
1958 /* Call text property handlers. */
1959 for (p
= it_props
; p
->handler
; ++p
)
1961 handled
= p
->handler (it
);
1963 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1965 else if (handled
== HANDLED_RETURN
)
1967 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1968 handle_overlay_change_p
= 0;
1971 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1973 /* Don't check for overlay strings below when set to deliver
1974 characters from a display vector. */
1975 if (it
->method
== next_element_from_display_vector
)
1976 handle_overlay_change_p
= 0;
1978 /* Handle overlay changes. */
1979 if (handle_overlay_change_p
)
1980 handled
= handle_overlay_change (it
);
1982 /* Determine where to stop next. */
1983 if (handled
== HANDLED_NORMALLY
)
1984 compute_stop_pos (it
);
1987 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1991 /* Compute IT->stop_charpos from text property and overlay change
1992 information for IT's current position. */
1995 compute_stop_pos (it
)
1998 register INTERVAL iv
, next_iv
;
1999 Lisp_Object object
, limit
, position
;
2001 /* If nowhere else, stop at the end. */
2002 it
->stop_charpos
= it
->end_charpos
;
2004 if (STRINGP (it
->string
))
2006 /* Strings are usually short, so don't limit the search for
2008 object
= it
->string
;
2010 position
= make_number (IT_STRING_CHARPOS (*it
));
2016 /* If next overlay change is in front of the current stop pos
2017 (which is IT->end_charpos), stop there. Note: value of
2018 next_overlay_change is point-max if no overlay change
2020 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2021 if (charpos
< it
->stop_charpos
)
2022 it
->stop_charpos
= charpos
;
2024 /* If showing the region, we have to stop at the region
2025 start or end because the face might change there. */
2026 if (it
->region_beg_charpos
> 0)
2028 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2029 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2030 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2031 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2034 /* Set up variables for computing the stop position from text
2035 property changes. */
2036 XSETBUFFER (object
, current_buffer
);
2037 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2038 position
= make_number (IT_CHARPOS (*it
));
2042 /* Get the interval containing IT's position. Value is a null
2043 interval if there isn't such an interval. */
2044 iv
= validate_interval_range (object
, &position
, &position
, 0);
2045 if (!NULL_INTERVAL_P (iv
))
2047 Lisp_Object values_here
[LAST_PROP_IDX
];
2050 /* Get properties here. */
2051 for (p
= it_props
; p
->handler
; ++p
)
2052 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2054 /* Look for an interval following iv that has different
2056 for (next_iv
= next_interval (iv
);
2057 (!NULL_INTERVAL_P (next_iv
)
2059 || XFASTINT (limit
) > next_iv
->position
));
2060 next_iv
= next_interval (next_iv
))
2062 for (p
= it_props
; p
->handler
; ++p
)
2064 Lisp_Object new_value
;
2066 new_value
= textget (next_iv
->plist
, *p
->name
);
2067 if (!EQ (values_here
[p
->idx
], new_value
))
2075 if (!NULL_INTERVAL_P (next_iv
))
2077 if (INTEGERP (limit
)
2078 && next_iv
->position
>= XFASTINT (limit
))
2079 /* No text property change up to limit. */
2080 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2082 /* Text properties change in next_iv. */
2083 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2087 xassert (STRINGP (it
->string
)
2088 || (it
->stop_charpos
>= BEGV
2089 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2093 /* Return the position of the next overlay change after POS in
2094 current_buffer. Value is point-max if no overlay change
2095 follows. This is like `next-overlay-change' but doesn't use
2099 next_overlay_change (pos
)
2104 Lisp_Object
*overlays
;
2108 /* Get all overlays at the given position. */
2110 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2111 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2112 if (noverlays
> len
)
2115 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2116 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2119 /* If any of these overlays ends before endpos,
2120 use its ending point instead. */
2121 for (i
= 0; i
< noverlays
; ++i
)
2126 oend
= OVERLAY_END (overlays
[i
]);
2127 oendpos
= OVERLAY_POSITION (oend
);
2128 endpos
= min (endpos
, oendpos
);
2136 /***********************************************************************
2138 ***********************************************************************/
2140 /* Handle changes in the `fontified' property of the current buffer by
2141 calling hook functions from Qfontification_functions to fontify
2144 static enum prop_handled
2145 handle_fontified_prop (it
)
2148 Lisp_Object prop
, pos
;
2149 enum prop_handled handled
= HANDLED_NORMALLY
;
2151 /* Get the value of the `fontified' property at IT's current buffer
2152 position. (The `fontified' property doesn't have a special
2153 meaning in strings.) If the value is nil, call functions from
2154 Qfontification_functions. */
2155 if (!STRINGP (it
->string
)
2157 && !NILP (Vfontification_functions
)
2158 && !NILP (Vrun_hooks
)
2159 && (pos
= make_number (IT_CHARPOS (*it
)),
2160 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2163 int count
= BINDING_STACK_SIZE ();
2166 val
= Vfontification_functions
;
2167 specbind (Qfontification_functions
, Qnil
);
2168 specbind (Qafter_change_functions
, Qnil
);
2170 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2171 safe_call1 (val
, pos
);
2174 Lisp_Object globals
, fn
;
2175 struct gcpro gcpro1
, gcpro2
;
2178 GCPRO2 (val
, globals
);
2180 for (; CONSP (val
); val
= XCDR (val
))
2186 /* A value of t indicates this hook has a local
2187 binding; it means to run the global binding too.
2188 In a global value, t should not occur. If it
2189 does, we must ignore it to avoid an endless
2191 for (globals
= Fdefault_value (Qfontification_functions
);
2193 globals
= XCDR (globals
))
2195 fn
= XCAR (globals
);
2197 safe_call1 (fn
, pos
);
2201 safe_call1 (fn
, pos
);
2207 unbind_to (count
, Qnil
);
2209 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2210 something. This avoids an endless loop if they failed to
2211 fontify the text for which reason ever. */
2212 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2213 handled
= HANDLED_RECOMPUTE_PROPS
;
2221 /***********************************************************************
2223 ***********************************************************************/
2225 /* Set up iterator IT from face properties at its current position.
2226 Called from handle_stop. */
2228 static enum prop_handled
2229 handle_face_prop (it
)
2232 int new_face_id
, next_stop
;
2234 if (!STRINGP (it
->string
))
2237 = face_at_buffer_position (it
->w
,
2239 it
->region_beg_charpos
,
2240 it
->region_end_charpos
,
2243 + TEXT_PROP_DISTANCE_LIMIT
),
2246 /* Is this a start of a run of characters with box face?
2247 Caveat: this can be called for a freshly initialized
2248 iterator; face_id is -1 is this case. We know that the new
2249 face will not change until limit, i.e. if the new face has a
2250 box, all characters up to limit will have one. But, as
2251 usual, we don't know whether limit is really the end. */
2252 if (new_face_id
!= it
->face_id
)
2254 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2256 /* If new face has a box but old face has not, this is
2257 the start of a run of characters with box, i.e. it has
2258 a shadow on the left side. The value of face_id of the
2259 iterator will be -1 if this is the initial call that gets
2260 the face. In this case, we have to look in front of IT's
2261 position and see whether there is a face != new_face_id. */
2262 it
->start_of_box_run_p
2263 = (new_face
->box
!= FACE_NO_BOX
2264 && (it
->face_id
>= 0
2265 || IT_CHARPOS (*it
) == BEG
2266 || new_face_id
!= face_before_it_pos (it
)));
2267 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2272 int base_face_id
, bufpos
;
2274 if (it
->current
.overlay_string_index
>= 0)
2275 bufpos
= IT_CHARPOS (*it
);
2279 /* For strings from a buffer, i.e. overlay strings or strings
2280 from a `display' property, use the face at IT's current
2281 buffer position as the base face to merge with, so that
2282 overlay strings appear in the same face as surrounding
2283 text, unless they specify their own faces. */
2284 base_face_id
= underlying_face_id (it
);
2286 new_face_id
= face_at_string_position (it
->w
,
2288 IT_STRING_CHARPOS (*it
),
2290 it
->region_beg_charpos
,
2291 it
->region_end_charpos
,
2295 #if 0 /* This shouldn't be neccessary. Let's check it. */
2296 /* If IT is used to display a mode line we would really like to
2297 use the mode line face instead of the frame's default face. */
2298 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2299 && new_face_id
== DEFAULT_FACE_ID
)
2300 new_face_id
= MODE_LINE_FACE_ID
;
2303 /* Is this a start of a run of characters with box? Caveat:
2304 this can be called for a freshly allocated iterator; face_id
2305 is -1 is this case. We know that the new face will not
2306 change until the next check pos, i.e. if the new face has a
2307 box, all characters up to that position will have a
2308 box. But, as usual, we don't know whether that position
2309 is really the end. */
2310 if (new_face_id
!= it
->face_id
)
2312 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2313 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2315 /* If new face has a box but old face hasn't, this is the
2316 start of a run of characters with box, i.e. it has a
2317 shadow on the left side. */
2318 it
->start_of_box_run_p
2319 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2320 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2324 it
->face_id
= new_face_id
;
2325 return HANDLED_NORMALLY
;
2329 /* Return the ID of the face ``underlying'' IT's current position,
2330 which is in a string. If the iterator is associated with a
2331 buffer, return the face at IT's current buffer position.
2332 Otherwise, use the iterator's base_face_id. */
2335 underlying_face_id (it
)
2338 int face_id
= it
->base_face_id
, i
;
2340 xassert (STRINGP (it
->string
));
2342 for (i
= it
->sp
- 1; i
>= 0; --i
)
2343 if (NILP (it
->stack
[i
].string
))
2344 face_id
= it
->stack
[i
].face_id
;
2350 /* Compute the face one character before or after the current position
2351 of IT. BEFORE_P non-zero means get the face in front of IT's
2352 position. Value is the id of the face. */
2355 face_before_or_after_it_pos (it
, before_p
)
2360 int next_check_charpos
;
2361 struct text_pos pos
;
2363 xassert (it
->s
== NULL
);
2365 if (STRINGP (it
->string
))
2367 int bufpos
, base_face_id
;
2369 /* No face change past the end of the string (for the case
2370 we are padding with spaces). No face change before the
2372 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2373 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2376 /* Set pos to the position before or after IT's current position. */
2378 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2380 /* For composition, we must check the character after the
2382 pos
= (it
->what
== IT_COMPOSITION
2383 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2384 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2386 if (it
->current
.overlay_string_index
>= 0)
2387 bufpos
= IT_CHARPOS (*it
);
2391 base_face_id
= underlying_face_id (it
);
2393 /* Get the face for ASCII, or unibyte. */
2394 face_id
= face_at_string_position (it
->w
,
2398 it
->region_beg_charpos
,
2399 it
->region_end_charpos
,
2400 &next_check_charpos
,
2403 /* Correct the face for charsets different from ASCII. Do it
2404 for the multibyte case only. The face returned above is
2405 suitable for unibyte text if IT->string is unibyte. */
2406 if (STRING_MULTIBYTE (it
->string
))
2408 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2409 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2411 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2413 c
= string_char_and_length (p
, rest
, &len
);
2414 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2419 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2420 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2423 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2424 pos
= it
->current
.pos
;
2427 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2430 if (it
->what
== IT_COMPOSITION
)
2431 /* For composition, we must check the position after the
2433 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2435 INC_TEXT_POS (pos
, it
->multibyte_p
);
2438 /* Determine face for CHARSET_ASCII, or unibyte. */
2439 face_id
= face_at_buffer_position (it
->w
,
2441 it
->region_beg_charpos
,
2442 it
->region_end_charpos
,
2443 &next_check_charpos
,
2446 /* Correct the face for charsets different from ASCII. Do it
2447 for the multibyte case only. The face returned above is
2448 suitable for unibyte text if current_buffer is unibyte. */
2449 if (it
->multibyte_p
)
2451 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2452 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2453 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2462 /***********************************************************************
2464 ***********************************************************************/
2466 /* Set up iterator IT from invisible properties at its current
2467 position. Called from handle_stop. */
2469 static enum prop_handled
2470 handle_invisible_prop (it
)
2473 enum prop_handled handled
= HANDLED_NORMALLY
;
2475 if (STRINGP (it
->string
))
2477 extern Lisp_Object Qinvisible
;
2478 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2480 /* Get the value of the invisible text property at the
2481 current position. Value will be nil if there is no such
2483 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2484 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2487 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2489 handled
= HANDLED_RECOMPUTE_PROPS
;
2491 /* Get the position at which the next change of the
2492 invisible text property can be found in IT->string.
2493 Value will be nil if the property value is the same for
2494 all the rest of IT->string. */
2495 XSETINT (limit
, XSTRING (it
->string
)->size
);
2496 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2499 /* Text at current position is invisible. The next
2500 change in the property is at position end_charpos.
2501 Move IT's current position to that position. */
2502 if (INTEGERP (end_charpos
)
2503 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2505 struct text_pos old
;
2506 old
= it
->current
.string_pos
;
2507 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2508 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2512 /* The rest of the string is invisible. If this is an
2513 overlay string, proceed with the next overlay string
2514 or whatever comes and return a character from there. */
2515 if (it
->current
.overlay_string_index
>= 0)
2517 next_overlay_string (it
);
2518 /* Don't check for overlay strings when we just
2519 finished processing them. */
2520 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2524 struct Lisp_String
*s
= XSTRING (it
->string
);
2525 IT_STRING_CHARPOS (*it
) = s
->size
;
2526 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2533 int visible_p
, newpos
, next_stop
;
2534 Lisp_Object pos
, prop
;
2536 /* First of all, is there invisible text at this position? */
2537 pos
= make_number (IT_CHARPOS (*it
));
2538 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2540 /* If we are on invisible text, skip over it. */
2541 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2542 && IT_CHARPOS (*it
) < it
->end_charpos
)
2544 /* Record whether we have to display an ellipsis for the
2546 int display_ellipsis_p
2547 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2549 handled
= HANDLED_RECOMPUTE_PROPS
;
2551 /* Loop skipping over invisible text. The loop is left at
2552 ZV or with IT on the first char being visible again. */
2555 /* Try to skip some invisible text. Return value is the
2556 position reached which can be equal to IT's position
2557 if there is nothing invisible here. This skips both
2558 over invisible text properties and overlays with
2559 invisible property. */
2560 newpos
= skip_invisible (IT_CHARPOS (*it
),
2561 &next_stop
, ZV
, it
->window
);
2563 /* If we skipped nothing at all we weren't at invisible
2564 text in the first place. If everything to the end of
2565 the buffer was skipped, end the loop. */
2566 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2570 /* We skipped some characters but not necessarily
2571 all there are. Check if we ended up on visible
2572 text. Fget_char_property returns the property of
2573 the char before the given position, i.e. if we
2574 get visible_p = 1, this means that the char at
2575 newpos is visible. */
2576 pos
= make_number (newpos
);
2577 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2578 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2581 /* If we ended up on invisible text, proceed to
2582 skip starting with next_stop. */
2584 IT_CHARPOS (*it
) = next_stop
;
2588 /* The position newpos is now either ZV or on visible text. */
2589 IT_CHARPOS (*it
) = newpos
;
2590 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2592 /* Maybe return `...' next for the end of the invisible text. */
2593 if (display_ellipsis_p
)
2596 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2598 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2599 it
->dpvec
= v
->contents
;
2600 it
->dpend
= v
->contents
+ v
->size
;
2604 /* Default `...'. */
2605 it
->dpvec
= default_invis_vector
;
2606 it
->dpend
= default_invis_vector
+ 3;
2609 /* The ellipsis display does not replace the display of
2610 the character at the new position. Indicate this by
2611 setting IT->dpvec_char_len to zero. */
2612 it
->dpvec_char_len
= 0;
2614 it
->current
.dpvec_index
= 0;
2615 it
->method
= next_element_from_display_vector
;
2625 /***********************************************************************
2627 ***********************************************************************/
2629 /* Set up iterator IT from `display' property at its current position.
2630 Called from handle_stop. */
2632 static enum prop_handled
2633 handle_display_prop (it
)
2636 Lisp_Object prop
, object
;
2637 struct text_pos
*position
;
2638 int display_replaced_p
= 0;
2640 if (STRINGP (it
->string
))
2642 object
= it
->string
;
2643 position
= &it
->current
.string_pos
;
2647 object
= it
->w
->buffer
;
2648 position
= &it
->current
.pos
;
2651 /* Reset those iterator values set from display property values. */
2652 it
->font_height
= Qnil
;
2653 it
->space_width
= Qnil
;
2656 /* We don't support recursive `display' properties, i.e. string
2657 values that have a string `display' property, that have a string
2658 `display' property etc. */
2659 if (!it
->string_from_display_prop_p
)
2660 it
->area
= TEXT_AREA
;
2662 prop
= Fget_char_property (make_number (position
->charpos
),
2665 return HANDLED_NORMALLY
;
2668 /* Simple properties. */
2669 && !EQ (XCAR (prop
), Qimage
)
2670 && !EQ (XCAR (prop
), Qspace
)
2671 && !EQ (XCAR (prop
), Qwhen
)
2672 && !EQ (XCAR (prop
), Qspace_width
)
2673 && !EQ (XCAR (prop
), Qheight
)
2674 && !EQ (XCAR (prop
), Qraise
)
2675 /* Marginal area specifications. */
2676 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2677 && !NILP (XCAR (prop
)))
2679 for (; CONSP (prop
); prop
= XCDR (prop
))
2681 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2682 position
, display_replaced_p
))
2683 display_replaced_p
= 1;
2686 else if (VECTORP (prop
))
2689 for (i
= 0; i
< ASIZE (prop
); ++i
)
2690 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2691 position
, display_replaced_p
))
2692 display_replaced_p
= 1;
2696 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2697 display_replaced_p
= 1;
2700 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2704 /* Value is the position of the end of the `display' property starting
2705 at START_POS in OBJECT. */
2707 static struct text_pos
2708 display_prop_end (it
, object
, start_pos
)
2711 struct text_pos start_pos
;
2714 struct text_pos end_pos
;
2716 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2717 Qdisplay
, object
, Qnil
);
2718 CHARPOS (end_pos
) = XFASTINT (end
);
2719 if (STRINGP (object
))
2720 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2722 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2728 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2729 is the object in which the `display' property was found. *POSITION
2730 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2731 means that we previously saw a display sub-property which already
2732 replaced text display with something else, for example an image;
2733 ignore such properties after the first one has been processed.
2735 If PROP is a `space' or `image' sub-property, set *POSITION to the
2736 end position of the `display' property.
2738 Value is non-zero something was found which replaces the display
2739 of buffer or string text. */
2742 handle_single_display_prop (it
, prop
, object
, position
,
2743 display_replaced_before_p
)
2747 struct text_pos
*position
;
2748 int display_replaced_before_p
;
2751 int replaces_text_display_p
= 0;
2754 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2755 evaluated. If the result is nil, VALUE is ignored. */
2757 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2766 if (!NILP (form
) && !EQ (form
, Qt
))
2768 struct gcpro gcpro1
;
2769 struct text_pos end_pos
, pt
;
2772 end_pos
= display_prop_end (it
, object
, *position
);
2774 /* Temporarily set point to the end position, and then evaluate
2775 the form. This makes `(eolp)' work as FORM. */
2776 if (BUFFERP (object
))
2779 BYTEPOS (pt
) = PT_BYTE
;
2780 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2783 form
= safe_eval (form
);
2785 if (BUFFERP (object
))
2786 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2794 && EQ (XCAR (prop
), Qheight
)
2795 && CONSP (XCDR (prop
)))
2797 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2800 /* `(height HEIGHT)'. */
2801 it
->font_height
= XCAR (XCDR (prop
));
2802 if (!NILP (it
->font_height
))
2804 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2805 int new_height
= -1;
2807 if (CONSP (it
->font_height
)
2808 && (EQ (XCAR (it
->font_height
), Qplus
)
2809 || EQ (XCAR (it
->font_height
), Qminus
))
2810 && CONSP (XCDR (it
->font_height
))
2811 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2813 /* `(+ N)' or `(- N)' where N is an integer. */
2814 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2815 if (EQ (XCAR (it
->font_height
), Qplus
))
2817 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2819 else if (FUNCTIONP (it
->font_height
))
2821 /* Call function with current height as argument.
2822 Value is the new height. */
2824 height
= safe_call1 (it
->font_height
,
2825 face
->lface
[LFACE_HEIGHT_INDEX
]);
2826 if (NUMBERP (height
))
2827 new_height
= XFLOATINT (height
);
2829 else if (NUMBERP (it
->font_height
))
2831 /* Value is a multiple of the canonical char height. */
2834 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2835 new_height
= (XFLOATINT (it
->font_height
)
2836 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2840 /* Evaluate IT->font_height with `height' bound to the
2841 current specified height to get the new height. */
2843 int count
= BINDING_STACK_SIZE ();
2845 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2846 value
= safe_eval (it
->font_height
);
2847 unbind_to (count
, Qnil
);
2849 if (NUMBERP (value
))
2850 new_height
= XFLOATINT (value
);
2854 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2857 else if (CONSP (prop
)
2858 && EQ (XCAR (prop
), Qspace_width
)
2859 && CONSP (XCDR (prop
)))
2861 /* `(space_width WIDTH)'. */
2862 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2865 value
= XCAR (XCDR (prop
));
2866 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2867 it
->space_width
= value
;
2869 else if (CONSP (prop
)
2870 && EQ (XCAR (prop
), Qraise
)
2871 && CONSP (XCDR (prop
)))
2873 /* `(raise FACTOR)'. */
2874 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2877 #ifdef HAVE_WINDOW_SYSTEM
2878 value
= XCAR (XCDR (prop
));
2879 if (NUMBERP (value
))
2881 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2882 it
->voffset
= - (XFLOATINT (value
)
2883 * (FONT_HEIGHT (face
->font
)));
2885 #endif /* HAVE_WINDOW_SYSTEM */
2887 else if (!it
->string_from_display_prop_p
)
2889 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2890 VALUE) or `((margin nil) VALUE)' or VALUE. */
2891 Lisp_Object location
, value
;
2892 struct text_pos start_pos
;
2895 /* Characters having this form of property are not displayed, so
2896 we have to find the end of the property. */
2897 start_pos
= *position
;
2898 *position
= display_prop_end (it
, object
, start_pos
);
2901 /* Let's stop at the new position and assume that all
2902 text properties change there. */
2903 it
->stop_charpos
= position
->charpos
;
2905 location
= Qunbound
;
2906 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2910 value
= XCDR (prop
);
2912 value
= XCAR (value
);
2915 if (EQ (XCAR (tem
), Qmargin
)
2916 && (tem
= XCDR (tem
),
2917 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2919 || EQ (tem
, Qleft_margin
)
2920 || EQ (tem
, Qright_margin
))))
2924 if (EQ (location
, Qunbound
))
2930 #ifdef HAVE_WINDOW_SYSTEM
2931 if (FRAME_TERMCAP_P (it
->f
))
2932 valid_p
= STRINGP (value
);
2934 valid_p
= (STRINGP (value
)
2935 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2936 || valid_image_p (value
));
2937 #else /* not HAVE_WINDOW_SYSTEM */
2938 valid_p
= STRINGP (value
);
2939 #endif /* not HAVE_WINDOW_SYSTEM */
2941 if ((EQ (location
, Qleft_margin
)
2942 || EQ (location
, Qright_margin
)
2945 && !display_replaced_before_p
)
2947 replaces_text_display_p
= 1;
2949 /* Save current settings of IT so that we can restore them
2950 when we are finished with the glyph property value. */
2953 if (NILP (location
))
2954 it
->area
= TEXT_AREA
;
2955 else if (EQ (location
, Qleft_margin
))
2956 it
->area
= LEFT_MARGIN_AREA
;
2958 it
->area
= RIGHT_MARGIN_AREA
;
2960 if (STRINGP (value
))
2963 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2964 it
->current
.overlay_string_index
= -1;
2965 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2966 it
->end_charpos
= it
->string_nchars
2967 = XSTRING (it
->string
)->size
;
2968 it
->method
= next_element_from_string
;
2969 it
->stop_charpos
= 0;
2970 it
->string_from_display_prop_p
= 1;
2971 /* Say that we haven't consumed the characters with
2972 `display' property yet. The call to pop_it in
2973 set_iterator_to_next will clean this up. */
2974 *position
= start_pos
;
2976 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2978 it
->method
= next_element_from_stretch
;
2980 it
->current
.pos
= it
->position
= start_pos
;
2982 #ifdef HAVE_WINDOW_SYSTEM
2985 it
->what
= IT_IMAGE
;
2986 it
->image_id
= lookup_image (it
->f
, value
);
2987 it
->position
= start_pos
;
2988 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2989 it
->method
= next_element_from_image
;
2991 /* Say that we haven't consumed the characters with
2992 `display' property yet. The call to pop_it in
2993 set_iterator_to_next will clean this up. */
2994 *position
= start_pos
;
2996 #endif /* HAVE_WINDOW_SYSTEM */
2999 /* Invalid property or property not supported. Restore
3000 the position to what it was before. */
3001 *position
= start_pos
;
3004 return replaces_text_display_p
;
3008 /* Check if PROP is a display sub-property value whose text should be
3009 treated as intangible. */
3012 single_display_prop_intangible_p (prop
)
3015 /* Skip over `when FORM'. */
3016 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3027 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3028 we don't need to treat text as intangible. */
3029 if (EQ (XCAR (prop
), Qmargin
))
3037 || EQ (XCAR (prop
), Qleft_margin
)
3038 || EQ (XCAR (prop
), Qright_margin
))
3042 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3046 /* Check if PROP is a display property value whose text should be
3047 treated as intangible. */
3050 display_prop_intangible_p (prop
)
3054 && CONSP (XCAR (prop
))
3055 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3057 /* A list of sub-properties. */
3058 while (CONSP (prop
))
3060 if (single_display_prop_intangible_p (XCAR (prop
)))
3065 else if (VECTORP (prop
))
3067 /* A vector of sub-properties. */
3069 for (i
= 0; i
< ASIZE (prop
); ++i
)
3070 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3074 return single_display_prop_intangible_p (prop
);
3080 /* Return 1 if PROP is a display sub-property value containing STRING. */
3083 single_display_prop_string_p (prop
, string
)
3084 Lisp_Object prop
, string
;
3086 extern Lisp_Object Qwhen
, Qmargin
;
3088 if (EQ (string
, prop
))
3091 /* Skip over `when FORM'. */
3092 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3101 /* Skip over `margin LOCATION'. */
3102 if (EQ (XCAR (prop
), Qmargin
))
3113 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3117 /* Return 1 if STRING appears in the `display' property PROP. */
3120 display_prop_string_p (prop
, string
)
3121 Lisp_Object prop
, string
;
3123 extern Lisp_Object Qwhen
, Qmargin
;
3126 && CONSP (XCAR (prop
))
3127 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3129 /* A list of sub-properties. */
3130 while (CONSP (prop
))
3132 if (single_display_prop_string_p (XCAR (prop
), string
))
3137 else if (VECTORP (prop
))
3139 /* A vector of sub-properties. */
3141 for (i
= 0; i
< ASIZE (prop
); ++i
)
3142 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3146 return single_display_prop_string_p (prop
, string
);
3152 /* Determine from which buffer position in W's buffer STRING comes
3153 from. AROUND_CHARPOS is an approximate position where it could
3154 be from. Value is the buffer position or 0 if it couldn't be
3157 W's buffer must be current.
3159 This function is necessary because we don't record buffer positions
3160 in glyphs generated from strings (to keep struct glyph small).
3161 This function may only use code that doesn't eval because it is
3162 called asynchronously from note_mouse_highlight. */
3165 string_buffer_position (w
, string
, around_charpos
)
3170 Lisp_Object around
= make_number (around_charpos
);
3171 Lisp_Object limit
, prop
, pos
;
3172 const int MAX_DISTANCE
= 1000;
3175 pos
= make_number (around_charpos
);
3176 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3177 while (!found
&& !EQ (pos
, limit
))
3179 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3180 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3183 pos
= Fnext_single_property_change (pos
, Qdisplay
, Qnil
, limit
);
3188 pos
= make_number (around_charpos
);
3189 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3190 while (!found
&& !EQ (pos
, limit
))
3192 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3193 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3196 pos
= Fprevious_single_property_change (pos
, Qdisplay
, Qnil
,
3201 return found
? XINT (pos
) : 0;
3206 /***********************************************************************
3207 `composition' property
3208 ***********************************************************************/
3210 /* Set up iterator IT from `composition' property at its current
3211 position. Called from handle_stop. */
3213 static enum prop_handled
3214 handle_composition_prop (it
)
3217 Lisp_Object prop
, string
;
3218 int pos
, pos_byte
, end
;
3219 enum prop_handled handled
= HANDLED_NORMALLY
;
3221 if (STRINGP (it
->string
))
3223 pos
= IT_STRING_CHARPOS (*it
);
3224 pos_byte
= IT_STRING_BYTEPOS (*it
);
3225 string
= it
->string
;
3229 pos
= IT_CHARPOS (*it
);
3230 pos_byte
= IT_BYTEPOS (*it
);
3234 /* If there's a valid composition and point is not inside of the
3235 composition (in the case that the composition is from the current
3236 buffer), draw a glyph composed from the composition components. */
3237 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3238 && COMPOSITION_VALID_P (pos
, end
, prop
)
3239 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3241 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3245 it
->method
= next_element_from_composition
;
3247 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3248 /* For a terminal, draw only the first character of the
3250 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3251 it
->len
= (STRINGP (it
->string
)
3252 ? string_char_to_byte (it
->string
, end
)
3253 : CHAR_TO_BYTE (end
)) - pos_byte
;
3254 it
->stop_charpos
= end
;
3255 handled
= HANDLED_RETURN
;
3264 /***********************************************************************
3266 ***********************************************************************/
3268 /* The following structure is used to record overlay strings for
3269 later sorting in load_overlay_strings. */
3271 struct overlay_entry
3273 Lisp_Object overlay
;
3280 /* Set up iterator IT from overlay strings at its current position.
3281 Called from handle_stop. */
3283 static enum prop_handled
3284 handle_overlay_change (it
)
3287 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
3288 return HANDLED_RECOMPUTE_PROPS
;
3290 return HANDLED_NORMALLY
;
3294 /* Set up the next overlay string for delivery by IT, if there is an
3295 overlay string to deliver. Called by set_iterator_to_next when the
3296 end of the current overlay string is reached. If there are more
3297 overlay strings to display, IT->string and
3298 IT->current.overlay_string_index are set appropriately here.
3299 Otherwise IT->string is set to nil. */
3302 next_overlay_string (it
)
3305 ++it
->current
.overlay_string_index
;
3306 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3308 /* No more overlay strings. Restore IT's settings to what
3309 they were before overlay strings were processed, and
3310 continue to deliver from current_buffer. */
3312 xassert (it
->stop_charpos
>= BEGV
3313 && it
->stop_charpos
<= it
->end_charpos
);
3315 it
->current
.overlay_string_index
= -1;
3316 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3317 it
->n_overlay_strings
= 0;
3318 it
->method
= next_element_from_buffer
;
3320 /* If we're at the end of the buffer, record that we have
3321 processed the overlay strings there already, so that
3322 next_element_from_buffer doesn't try it again. */
3323 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3324 it
->overlay_strings_at_end_processed_p
= 1;
3328 /* There are more overlay strings to process. If
3329 IT->current.overlay_string_index has advanced to a position
3330 where we must load IT->overlay_strings with more strings, do
3332 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3334 if (it
->current
.overlay_string_index
&& i
== 0)
3335 load_overlay_strings (it
);
3337 /* Initialize IT to deliver display elements from the overlay
3339 it
->string
= it
->overlay_strings
[i
];
3340 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3341 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3342 it
->method
= next_element_from_string
;
3343 it
->stop_charpos
= 0;
3350 /* Compare two overlay_entry structures E1 and E2. Used as a
3351 comparison function for qsort in load_overlay_strings. Overlay
3352 strings for the same position are sorted so that
3354 1. All after-strings come in front of before-strings, except
3355 when they come from the same overlay.
3357 2. Within after-strings, strings are sorted so that overlay strings
3358 from overlays with higher priorities come first.
3360 2. Within before-strings, strings are sorted so that overlay
3361 strings from overlays with higher priorities come last.
3363 Value is analogous to strcmp. */
3367 compare_overlay_entries (e1
, e2
)
3370 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3371 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3374 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3376 /* Let after-strings appear in front of before-strings if
3377 they come from different overlays. */
3378 if (EQ (entry1
->overlay
, entry2
->overlay
))
3379 result
= entry1
->after_string_p
? 1 : -1;
3381 result
= entry1
->after_string_p
? -1 : 1;
3383 else if (entry1
->after_string_p
)
3384 /* After-strings sorted in order of decreasing priority. */
3385 result
= entry2
->priority
- entry1
->priority
;
3387 /* Before-strings sorted in order of increasing priority. */
3388 result
= entry1
->priority
- entry2
->priority
;
3394 /* Load the vector IT->overlay_strings with overlay strings from IT's
3395 current buffer position. Set IT->n_overlays to the total number of
3396 overlay strings found.
3398 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3399 a time. On entry into load_overlay_strings,
3400 IT->current.overlay_string_index gives the number of overlay
3401 strings that have already been loaded by previous calls to this
3404 IT->add_overlay_start contains an additional overlay start
3405 position to consider for taking overlay strings from, if non-zero.
3406 This position comes into play when the overlay has an `invisible'
3407 property, and both before and after-strings. When we've skipped to
3408 the end of the overlay, because of its `invisible' property, we
3409 nevertheless want its before-string to appear.
3410 IT->add_overlay_start will contain the overlay start position
3413 Overlay strings are sorted so that after-string strings come in
3414 front of before-string strings. Within before and after-strings,
3415 strings are sorted by overlay priority. See also function
3416 compare_overlay_entries. */
3419 load_overlay_strings (it
)
3422 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3423 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3426 int n
= 0, i
, j
, invis_p
;
3427 struct overlay_entry
*entries
3428 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3429 int charpos
= IT_CHARPOS (*it
);
3431 /* Append the overlay string STRING of overlay OVERLAY to vector
3432 `entries' which has size `size' and currently contains `n'
3433 elements. AFTER_P non-zero means STRING is an after-string of
3435 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3438 Lisp_Object priority; \
3442 int new_size = 2 * size; \
3443 struct overlay_entry *old = entries; \
3445 (struct overlay_entry *) alloca (new_size \
3446 * sizeof *entries); \
3447 bcopy (old, entries, size * sizeof *entries); \
3451 entries[n].string = (STRING); \
3452 entries[n].overlay = (OVERLAY); \
3453 priority = Foverlay_get ((OVERLAY), Qpriority); \
3454 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3455 entries[n].after_string_p = (AFTER_P); \
3460 /* Process overlay before the overlay center. */
3461 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3463 overlay
= XCAR (ov
);
3464 xassert (OVERLAYP (overlay
));
3465 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3466 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3471 /* Skip this overlay if it doesn't start or end at IT's current
3473 if (end
!= charpos
&& start
!= charpos
)
3476 /* Skip this overlay if it doesn't apply to IT->w. */
3477 window
= Foverlay_get (overlay
, Qwindow
);
3478 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3481 /* If the text ``under'' the overlay is invisible, both before-
3482 and after-strings from this overlay are visible; start and
3483 end position are indistinguishable. */
3484 invisible
= Foverlay_get (overlay
, Qinvisible
);
3485 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3487 /* If overlay has a non-empty before-string, record it. */
3488 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3489 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3490 && XSTRING (str
)->size
)
3491 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3493 /* If overlay has a non-empty after-string, record it. */
3494 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3495 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3496 && XSTRING (str
)->size
)
3497 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3500 /* Process overlays after the overlay center. */
3501 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3503 overlay
= XCAR (ov
);
3504 xassert (OVERLAYP (overlay
));
3505 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3506 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3508 if (start
> charpos
)
3511 /* Skip this overlay if it doesn't start or end at IT's current
3513 if (end
!= charpos
&& start
!= charpos
)
3516 /* Skip this overlay if it doesn't apply to IT->w. */
3517 window
= Foverlay_get (overlay
, Qwindow
);
3518 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3521 /* If the text ``under'' the overlay is invisible, it has a zero
3522 dimension, and both before- and after-strings apply. */
3523 invisible
= Foverlay_get (overlay
, Qinvisible
);
3524 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3526 /* If overlay has a non-empty before-string, record it. */
3527 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3528 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3529 && XSTRING (str
)->size
)
3530 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3532 /* If overlay has a non-empty after-string, record it. */
3533 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3534 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3535 && XSTRING (str
)->size
)
3536 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3539 #undef RECORD_OVERLAY_STRING
3543 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3545 /* Record the total number of strings to process. */
3546 it
->n_overlay_strings
= n
;
3548 /* IT->current.overlay_string_index is the number of overlay strings
3549 that have already been consumed by IT. Copy some of the
3550 remaining overlay strings to IT->overlay_strings. */
3552 j
= it
->current
.overlay_string_index
;
3553 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3554 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3560 /* Get the first chunk of overlay strings at IT's current buffer
3561 position. Value is non-zero if at least one overlay string was
3565 get_overlay_strings (it
)
3568 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3569 process. This fills IT->overlay_strings with strings, and sets
3570 IT->n_overlay_strings to the total number of strings to process.
3571 IT->pos.overlay_string_index has to be set temporarily to zero
3572 because load_overlay_strings needs this; it must be set to -1
3573 when no overlay strings are found because a zero value would
3574 indicate a position in the first overlay string. */
3575 it
->current
.overlay_string_index
= 0;
3576 load_overlay_strings (it
);
3578 /* If we found overlay strings, set up IT to deliver display
3579 elements from the first one. Otherwise set up IT to deliver
3580 from current_buffer. */
3581 if (it
->n_overlay_strings
)
3583 /* Make sure we know settings in current_buffer, so that we can
3584 restore meaningful values when we're done with the overlay
3586 compute_stop_pos (it
);
3587 xassert (it
->face_id
>= 0);
3589 /* Save IT's settings. They are restored after all overlay
3590 strings have been processed. */
3591 xassert (it
->sp
== 0);
3594 /* Set up IT to deliver display elements from the first overlay
3596 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3597 it
->string
= it
->overlay_strings
[0];
3598 it
->stop_charpos
= 0;
3599 it
->end_charpos
= XSTRING (it
->string
)->size
;
3600 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3601 xassert (STRINGP (it
->string
));
3602 it
->method
= next_element_from_string
;
3607 it
->current
.overlay_string_index
= -1;
3608 it
->method
= next_element_from_buffer
;
3613 /* Value is non-zero if we found at least one overlay string. */
3614 return STRINGP (it
->string
);
3619 /***********************************************************************
3620 Saving and restoring state
3621 ***********************************************************************/
3623 /* Save current settings of IT on IT->stack. Called, for example,
3624 before setting up IT for an overlay string, to be able to restore
3625 IT's settings to what they were after the overlay string has been
3632 struct iterator_stack_entry
*p
;
3634 xassert (it
->sp
< 2);
3635 p
= it
->stack
+ it
->sp
;
3637 p
->stop_charpos
= it
->stop_charpos
;
3638 xassert (it
->face_id
>= 0);
3639 p
->face_id
= it
->face_id
;
3640 p
->string
= it
->string
;
3641 p
->pos
= it
->current
;
3642 p
->end_charpos
= it
->end_charpos
;
3643 p
->string_nchars
= it
->string_nchars
;
3645 p
->multibyte_p
= it
->multibyte_p
;
3646 p
->space_width
= it
->space_width
;
3647 p
->font_height
= it
->font_height
;
3648 p
->voffset
= it
->voffset
;
3649 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3654 /* Restore IT's settings from IT->stack. Called, for example, when no
3655 more overlay strings must be processed, and we return to delivering
3656 display elements from a buffer, or when the end of a string from a
3657 `display' property is reached and we return to delivering display
3658 elements from an overlay string, or from a buffer. */
3664 struct iterator_stack_entry
*p
;
3666 xassert (it
->sp
> 0);
3668 p
= it
->stack
+ it
->sp
;
3669 it
->stop_charpos
= p
->stop_charpos
;
3670 it
->face_id
= p
->face_id
;
3671 it
->string
= p
->string
;
3672 it
->current
= p
->pos
;
3673 it
->end_charpos
= p
->end_charpos
;
3674 it
->string_nchars
= p
->string_nchars
;
3676 it
->multibyte_p
= p
->multibyte_p
;
3677 it
->space_width
= p
->space_width
;
3678 it
->font_height
= p
->font_height
;
3679 it
->voffset
= p
->voffset
;
3680 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3685 /***********************************************************************
3687 ***********************************************************************/
3689 /* Set IT's current position to the previous line start. */
3692 back_to_previous_line_start (it
)
3695 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3696 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3700 /* Move IT to the next line start.
3702 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3703 we skipped over part of the text (as opposed to moving the iterator
3704 continuously over the text). Otherwise, don't change the value
3707 Newlines may come from buffer text, overlay strings, or strings
3708 displayed via the `display' property. That's the reason we can't
3709 simply use find_next_newline_no_quit.
3711 Note that this function may not skip over invisible text that is so
3712 because of text properties and immediately follows a newline. If
3713 it would, function reseat_at_next_visible_line_start, when called
3714 from set_iterator_to_next, would effectively make invisible
3715 characters following a newline part of the wrong glyph row, which
3716 leads to wrong cursor motion. */
3719 forward_to_next_line_start (it
, skipped_p
)
3723 int old_selective
, newline_found_p
, n
;
3724 const int MAX_NEWLINE_DISTANCE
= 500;
3726 /* If already on a newline, just consume it to avoid unintended
3727 skipping over invisible text below. */
3728 if (it
->what
== IT_CHARACTER
3730 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3732 set_iterator_to_next (it
, 0);
3737 /* Don't handle selective display in the following. It's (a)
3738 unnecessary because it's done by the caller, and (b) leads to an
3739 infinite recursion because next_element_from_ellipsis indirectly
3740 calls this function. */
3741 old_selective
= it
->selective
;
3744 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3745 from buffer text. */
3746 for (n
= newline_found_p
= 0;
3747 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3748 n
+= STRINGP (it
->string
) ? 0 : 1)
3750 if (!get_next_display_element (it
))
3752 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3753 set_iterator_to_next (it
, 0);
3756 /* If we didn't find a newline near enough, see if we can use a
3758 if (n
== MAX_NEWLINE_DISTANCE
)
3760 int start
= IT_CHARPOS (*it
);
3761 int limit
= find_next_newline_no_quit (start
, 1);
3764 xassert (!STRINGP (it
->string
));
3766 /* If there isn't any `display' property in sight, and no
3767 overlays, we can just use the position of the newline in
3769 if (it
->stop_charpos
>= limit
3770 || ((pos
= Fnext_single_property_change (make_number (start
),
3772 Qnil
, make_number (limit
)),
3774 && next_overlay_change (start
) == ZV
))
3776 IT_CHARPOS (*it
) = limit
;
3777 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3778 *skipped_p
= newline_found_p
= 1;
3782 while (get_next_display_element (it
)
3783 && !newline_found_p
)
3785 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3786 set_iterator_to_next (it
, 0);
3791 it
->selective
= old_selective
;
3792 return newline_found_p
;
3796 /* Set IT's current position to the previous visible line start. Skip
3797 invisible text that is so either due to text properties or due to
3798 selective display. Caution: this does not change IT->current_x and
3802 back_to_previous_visible_line_start (it
)
3807 /* Go back one newline if not on BEGV already. */
3808 if (IT_CHARPOS (*it
) > BEGV
)
3809 back_to_previous_line_start (it
);
3811 /* Move over lines that are invisible because of selective display
3812 or text properties. */
3813 while (IT_CHARPOS (*it
) > BEGV
3818 /* If selective > 0, then lines indented more than that values
3820 if (it
->selective
> 0
3821 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3828 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3829 Qinvisible
, it
->window
);
3830 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3834 /* Back one more newline if the current one is invisible. */
3836 back_to_previous_line_start (it
);
3839 xassert (IT_CHARPOS (*it
) >= BEGV
);
3840 xassert (IT_CHARPOS (*it
) == BEGV
3841 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3846 /* Reseat iterator IT at the previous visible line start. Skip
3847 invisible text that is so either due to text properties or due to
3848 selective display. At the end, update IT's overlay information,
3849 face information etc. */
3852 reseat_at_previous_visible_line_start (it
)
3855 back_to_previous_visible_line_start (it
);
3856 reseat (it
, it
->current
.pos
, 1);
3861 /* Reseat iterator IT on the next visible line start in the current
3862 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3863 preceding the line start. Skip over invisible text that is so
3864 because of selective display. Compute faces, overlays etc at the
3865 new position. Note that this function does not skip over text that
3866 is invisible because of text properties. */
3869 reseat_at_next_visible_line_start (it
, on_newline_p
)
3873 int newline_found_p
, skipped_p
= 0;
3875 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3877 /* Skip over lines that are invisible because they are indented
3878 more than the value of IT->selective. */
3879 if (it
->selective
> 0)
3880 while (IT_CHARPOS (*it
) < ZV
3881 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3884 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3885 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3888 /* Position on the newline if that's what's requested. */
3889 if (on_newline_p
&& newline_found_p
)
3891 if (STRINGP (it
->string
))
3893 if (IT_STRING_CHARPOS (*it
) > 0)
3895 --IT_STRING_CHARPOS (*it
);
3896 --IT_STRING_BYTEPOS (*it
);
3899 else if (IT_CHARPOS (*it
) > BEGV
)
3903 reseat (it
, it
->current
.pos
, 0);
3907 reseat (it
, it
->current
.pos
, 0);
3914 /***********************************************************************
3915 Changing an iterator's position
3916 ***********************************************************************/
3918 /* Change IT's current position to POS in current_buffer. If FORCE_P
3919 is non-zero, always check for text properties at the new position.
3920 Otherwise, text properties are only looked up if POS >=
3921 IT->check_charpos of a property. */
3924 reseat (it
, pos
, force_p
)
3926 struct text_pos pos
;
3929 int original_pos
= IT_CHARPOS (*it
);
3931 reseat_1 (it
, pos
, 0);
3933 /* Determine where to check text properties. Avoid doing it
3934 where possible because text property lookup is very expensive. */
3936 || CHARPOS (pos
) > it
->stop_charpos
3937 || CHARPOS (pos
) < original_pos
)
3944 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3945 IT->stop_pos to POS, also. */
3948 reseat_1 (it
, pos
, set_stop_p
)
3950 struct text_pos pos
;
3953 /* Don't call this function when scanning a C string. */
3954 xassert (it
->s
== NULL
);
3956 /* POS must be a reasonable value. */
3957 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3959 it
->current
.pos
= it
->position
= pos
;
3960 XSETBUFFER (it
->object
, current_buffer
);
3961 it
->end_charpos
= ZV
;
3963 it
->current
.dpvec_index
= -1;
3964 it
->current
.overlay_string_index
= -1;
3965 IT_STRING_CHARPOS (*it
) = -1;
3966 IT_STRING_BYTEPOS (*it
) = -1;
3968 it
->method
= next_element_from_buffer
;
3970 it
->face_before_selective_p
= 0;
3973 it
->stop_charpos
= CHARPOS (pos
);
3977 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3978 If S is non-null, it is a C string to iterate over. Otherwise,
3979 STRING gives a Lisp string to iterate over.
3981 If PRECISION > 0, don't return more then PRECISION number of
3982 characters from the string.
3984 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3985 characters have been returned. FIELD_WIDTH < 0 means an infinite
3988 MULTIBYTE = 0 means disable processing of multibyte characters,
3989 MULTIBYTE > 0 means enable it,
3990 MULTIBYTE < 0 means use IT->multibyte_p.
3992 IT must be initialized via a prior call to init_iterator before
3993 calling this function. */
3996 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4001 int precision
, field_width
, multibyte
;
4003 /* No region in strings. */
4004 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4006 /* No text property checks performed by default, but see below. */
4007 it
->stop_charpos
= -1;
4009 /* Set iterator position and end position. */
4010 bzero (&it
->current
, sizeof it
->current
);
4011 it
->current
.overlay_string_index
= -1;
4012 it
->current
.dpvec_index
= -1;
4013 xassert (charpos
>= 0);
4015 /* If STRING is specified, use its multibyteness, otherwise use the
4016 setting of MULTIBYTE, if specified. */
4018 it
->multibyte_p
= multibyte
> 0;
4022 xassert (STRINGP (string
));
4023 it
->string
= string
;
4025 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4026 it
->method
= next_element_from_string
;
4027 it
->current
.string_pos
= string_pos (charpos
, string
);
4034 /* Note that we use IT->current.pos, not it->current.string_pos,
4035 for displaying C strings. */
4036 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4037 if (it
->multibyte_p
)
4039 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4040 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4044 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4045 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4048 it
->method
= next_element_from_c_string
;
4051 /* PRECISION > 0 means don't return more than PRECISION characters
4053 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4054 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4056 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4057 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4058 FIELD_WIDTH < 0 means infinite field width. This is useful for
4059 padding with `-' at the end of a mode line. */
4060 if (field_width
< 0)
4061 field_width
= INFINITY
;
4062 if (field_width
> it
->end_charpos
- charpos
)
4063 it
->end_charpos
= charpos
+ field_width
;
4065 /* Use the standard display table for displaying strings. */
4066 if (DISP_TABLE_P (Vstandard_display_table
))
4067 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4069 it
->stop_charpos
= charpos
;
4075 /***********************************************************************
4077 ***********************************************************************/
4079 /* Load IT's display element fields with information about the next
4080 display element from the current position of IT. Value is zero if
4081 end of buffer (or C string) is reached. */
4084 get_next_display_element (it
)
4087 /* Non-zero means that we found an display element. Zero means that
4088 we hit the end of what we iterate over. Performance note: the
4089 function pointer `method' used here turns out to be faster than
4090 using a sequence of if-statements. */
4091 int success_p
= (*it
->method
) (it
);
4093 if (it
->what
== IT_CHARACTER
)
4095 /* Map via display table or translate control characters.
4096 IT->c, IT->len etc. have been set to the next character by
4097 the function call above. If we have a display table, and it
4098 contains an entry for IT->c, translate it. Don't do this if
4099 IT->c itself comes from a display table, otherwise we could
4100 end up in an infinite recursion. (An alternative could be to
4101 count the recursion depth of this function and signal an
4102 error when a certain maximum depth is reached.) Is it worth
4104 if (success_p
&& it
->dpvec
== NULL
)
4109 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4112 struct Lisp_Vector
*v
= XVECTOR (dv
);
4114 /* Return the first character from the display table
4115 entry, if not empty. If empty, don't display the
4116 current character. */
4119 it
->dpvec_char_len
= it
->len
;
4120 it
->dpvec
= v
->contents
;
4121 it
->dpend
= v
->contents
+ v
->size
;
4122 it
->current
.dpvec_index
= 0;
4123 it
->method
= next_element_from_display_vector
;
4124 success_p
= get_next_display_element (it
);
4128 set_iterator_to_next (it
, 0);
4129 success_p
= get_next_display_element (it
);
4133 /* Translate control characters into `\003' or `^C' form.
4134 Control characters coming from a display table entry are
4135 currently not translated because we use IT->dpvec to hold
4136 the translation. This could easily be changed but I
4137 don't believe that it is worth doing.
4139 Non-printable multibyte characters are also translated
4141 else if ((it
->c
< ' '
4142 && (it
->area
!= TEXT_AREA
4143 || (it
->c
!= '\n' && it
->c
!= '\t')))
4146 || !CHAR_PRINTABLE_P (it
->c
))
4148 /* IT->c is a control character which must be displayed
4149 either as '\003' or as `^C' where the '\\' and '^'
4150 can be defined in the display table. Fill
4151 IT->ctl_chars with glyphs for what we have to
4152 display. Then, set IT->dpvec to these glyphs. */
4155 if (it
->c
< 128 && it
->ctl_arrow_p
)
4157 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4159 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4160 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4161 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4163 g
= FAST_MAKE_GLYPH ('^', 0);
4164 XSETINT (it
->ctl_chars
[0], g
);
4166 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4167 XSETINT (it
->ctl_chars
[1], g
);
4169 /* Set up IT->dpvec and return first character from it. */
4170 it
->dpvec_char_len
= it
->len
;
4171 it
->dpvec
= it
->ctl_chars
;
4172 it
->dpend
= it
->dpvec
+ 2;
4173 it
->current
.dpvec_index
= 0;
4174 it
->method
= next_element_from_display_vector
;
4175 get_next_display_element (it
);
4179 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4184 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4186 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4187 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4188 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4190 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4192 if (SINGLE_BYTE_CHAR_P (it
->c
))
4193 str
[0] = it
->c
, len
= 1;
4195 len
= CHAR_STRING (it
->c
, str
);
4197 for (i
= 0; i
< len
; i
++)
4199 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4200 /* Insert three more glyphs into IT->ctl_chars for
4201 the octal display of the character. */
4202 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4203 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4204 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4205 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4206 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4207 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4210 /* Set up IT->dpvec and return the first character
4212 it
->dpvec_char_len
= it
->len
;
4213 it
->dpvec
= it
->ctl_chars
;
4214 it
->dpend
= it
->dpvec
+ len
* 4;
4215 it
->current
.dpvec_index
= 0;
4216 it
->method
= next_element_from_display_vector
;
4217 get_next_display_element (it
);
4222 /* Adjust face id for a multibyte character. There are no
4223 multibyte character in unibyte text. */
4226 && FRAME_WINDOW_P (it
->f
))
4228 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4229 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4233 /* Is this character the last one of a run of characters with
4234 box? If yes, set IT->end_of_box_run_p to 1. */
4241 it
->end_of_box_run_p
4242 = ((face_id
= face_after_it_pos (it
),
4243 face_id
!= it
->face_id
)
4244 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4245 face
->box
== FACE_NO_BOX
));
4248 /* Value is 0 if end of buffer or string reached. */
4253 /* Move IT to the next display element.
4255 RESEAT_P non-zero means if called on a newline in buffer text,
4256 skip to the next visible line start.
4258 Functions get_next_display_element and set_iterator_to_next are
4259 separate because I find this arrangement easier to handle than a
4260 get_next_display_element function that also increments IT's
4261 position. The way it is we can first look at an iterator's current
4262 display element, decide whether it fits on a line, and if it does,
4263 increment the iterator position. The other way around we probably
4264 would either need a flag indicating whether the iterator has to be
4265 incremented the next time, or we would have to implement a
4266 decrement position function which would not be easy to write. */
4269 set_iterator_to_next (it
, reseat_p
)
4273 /* Reset flags indicating start and end of a sequence of characters
4274 with box. Reset them at the start of this function because
4275 moving the iterator to a new position might set them. */
4276 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4278 if (it
->method
== next_element_from_buffer
)
4280 /* The current display element of IT is a character from
4281 current_buffer. Advance in the buffer, and maybe skip over
4282 invisible lines that are so because of selective display. */
4283 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4284 reseat_at_next_visible_line_start (it
, 0);
4287 xassert (it
->len
!= 0);
4288 IT_BYTEPOS (*it
) += it
->len
;
4289 IT_CHARPOS (*it
) += 1;
4290 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4293 else if (it
->method
== next_element_from_composition
)
4295 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4296 if (STRINGP (it
->string
))
4298 IT_STRING_BYTEPOS (*it
) += it
->len
;
4299 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4300 it
->method
= next_element_from_string
;
4301 goto consider_string_end
;
4305 IT_BYTEPOS (*it
) += it
->len
;
4306 IT_CHARPOS (*it
) += it
->cmp_len
;
4307 it
->method
= next_element_from_buffer
;
4310 else if (it
->method
== next_element_from_c_string
)
4312 /* Current display element of IT is from a C string. */
4313 IT_BYTEPOS (*it
) += it
->len
;
4314 IT_CHARPOS (*it
) += 1;
4316 else if (it
->method
== next_element_from_display_vector
)
4318 /* Current display element of IT is from a display table entry.
4319 Advance in the display table definition. Reset it to null if
4320 end reached, and continue with characters from buffers/
4322 ++it
->current
.dpvec_index
;
4324 /* Restore face of the iterator to what they were before the
4325 display vector entry (these entries may contain faces). */
4326 it
->face_id
= it
->saved_face_id
;
4328 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4331 it
->method
= next_element_from_c_string
;
4332 else if (STRINGP (it
->string
))
4333 it
->method
= next_element_from_string
;
4335 it
->method
= next_element_from_buffer
;
4338 it
->current
.dpvec_index
= -1;
4340 /* Skip over characters which were displayed via IT->dpvec. */
4341 if (it
->dpvec_char_len
< 0)
4342 reseat_at_next_visible_line_start (it
, 1);
4343 else if (it
->dpvec_char_len
> 0)
4345 it
->len
= it
->dpvec_char_len
;
4346 set_iterator_to_next (it
, reseat_p
);
4350 else if (it
->method
== next_element_from_string
)
4352 /* Current display element is a character from a Lisp string. */
4353 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4354 IT_STRING_BYTEPOS (*it
) += it
->len
;
4355 IT_STRING_CHARPOS (*it
) += 1;
4357 consider_string_end
:
4359 if (it
->current
.overlay_string_index
>= 0)
4361 /* IT->string is an overlay string. Advance to the
4362 next, if there is one. */
4363 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4364 next_overlay_string (it
);
4368 /* IT->string is not an overlay string. If we reached
4369 its end, and there is something on IT->stack, proceed
4370 with what is on the stack. This can be either another
4371 string, this time an overlay string, or a buffer. */
4372 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4376 if (!STRINGP (it
->string
))
4377 it
->method
= next_element_from_buffer
;
4379 goto consider_string_end
;
4383 else if (it
->method
== next_element_from_image
4384 || it
->method
== next_element_from_stretch
)
4386 /* The position etc with which we have to proceed are on
4387 the stack. The position may be at the end of a string,
4388 if the `display' property takes up the whole string. */
4391 if (STRINGP (it
->string
))
4393 it
->method
= next_element_from_string
;
4394 goto consider_string_end
;
4397 it
->method
= next_element_from_buffer
;
4400 /* There are no other methods defined, so this should be a bug. */
4403 xassert (it
->method
!= next_element_from_string
4404 || (STRINGP (it
->string
)
4405 && IT_STRING_CHARPOS (*it
) >= 0));
4409 /* Load IT's display element fields with information about the next
4410 display element which comes from a display table entry or from the
4411 result of translating a control character to one of the forms `^C'
4412 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4415 next_element_from_display_vector (it
)
4419 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4421 /* Remember the current face id in case glyphs specify faces.
4422 IT's face is restored in set_iterator_to_next. */
4423 it
->saved_face_id
= it
->face_id
;
4425 if (INTEGERP (*it
->dpvec
)
4426 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4431 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4432 it
->c
= FAST_GLYPH_CHAR (g
);
4433 it
->len
= CHAR_BYTES (it
->c
);
4435 /* The entry may contain a face id to use. Such a face id is
4436 the id of a Lisp face, not a realized face. A face id of
4437 zero means no face is specified. */
4438 lface_id
= FAST_GLYPH_FACE (g
);
4441 /* The function returns -1 if lface_id is invalid. */
4442 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4444 it
->face_id
= face_id
;
4448 /* Display table entry is invalid. Return a space. */
4449 it
->c
= ' ', it
->len
= 1;
4451 /* Don't change position and object of the iterator here. They are
4452 still the values of the character that had this display table
4453 entry or was translated, and that's what we want. */
4454 it
->what
= IT_CHARACTER
;
4459 /* Load IT with the next display element from Lisp string IT->string.
4460 IT->current.string_pos is the current position within the string.
4461 If IT->current.overlay_string_index >= 0, the Lisp string is an
4465 next_element_from_string (it
)
4468 struct text_pos position
;
4470 xassert (STRINGP (it
->string
));
4471 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4472 position
= it
->current
.string_pos
;
4474 /* Time to check for invisible text? */
4475 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4476 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4480 /* Since a handler may have changed IT->method, we must
4482 return get_next_display_element (it
);
4485 if (it
->current
.overlay_string_index
>= 0)
4487 /* Get the next character from an overlay string. In overlay
4488 strings, There is no field width or padding with spaces to
4490 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4495 else if (STRING_MULTIBYTE (it
->string
))
4497 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4498 - IT_STRING_BYTEPOS (*it
));
4499 unsigned char *s
= (XSTRING (it
->string
)->data
4500 + IT_STRING_BYTEPOS (*it
));
4501 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4505 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4511 /* Get the next character from a Lisp string that is not an
4512 overlay string. Such strings come from the mode line, for
4513 example. We may have to pad with spaces, or truncate the
4514 string. See also next_element_from_c_string. */
4515 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4520 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4522 /* Pad with spaces. */
4523 it
->c
= ' ', it
->len
= 1;
4524 CHARPOS (position
) = BYTEPOS (position
) = -1;
4526 else if (STRING_MULTIBYTE (it
->string
))
4528 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4529 - IT_STRING_BYTEPOS (*it
));
4530 unsigned char *s
= (XSTRING (it
->string
)->data
4531 + IT_STRING_BYTEPOS (*it
));
4532 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4536 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4541 /* Record what we have and where it came from. Note that we store a
4542 buffer position in IT->position although it could arguably be a
4544 it
->what
= IT_CHARACTER
;
4545 it
->object
= it
->string
;
4546 it
->position
= position
;
4551 /* Load IT with next display element from C string IT->s.
4552 IT->string_nchars is the maximum number of characters to return
4553 from the string. IT->end_charpos may be greater than
4554 IT->string_nchars when this function is called, in which case we
4555 may have to return padding spaces. Value is zero if end of string
4556 reached, including padding spaces. */
4559 next_element_from_c_string (it
)
4565 it
->what
= IT_CHARACTER
;
4566 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4569 /* IT's position can be greater IT->string_nchars in case a field
4570 width or precision has been specified when the iterator was
4572 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4574 /* End of the game. */
4578 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4580 /* Pad with spaces. */
4581 it
->c
= ' ', it
->len
= 1;
4582 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4584 else if (it
->multibyte_p
)
4586 /* Implementation note: The calls to strlen apparently aren't a
4587 performance problem because there is no noticeable performance
4588 difference between Emacs running in unibyte or multibyte mode. */
4589 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4590 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4594 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4600 /* Set up IT to return characters from an ellipsis, if appropriate.
4601 The definition of the ellipsis glyphs may come from a display table
4602 entry. This function Fills IT with the first glyph from the
4603 ellipsis if an ellipsis is to be displayed. */
4606 next_element_from_ellipsis (it
)
4609 if (it
->selective_display_ellipsis_p
)
4611 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4613 /* Use the display table definition for `...'. Invalid glyphs
4614 will be handled by the method returning elements from dpvec. */
4615 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4616 it
->dpvec_char_len
= it
->len
;
4617 it
->dpvec
= v
->contents
;
4618 it
->dpend
= v
->contents
+ v
->size
;
4619 it
->current
.dpvec_index
= 0;
4620 it
->method
= next_element_from_display_vector
;
4624 /* Use default `...' which is stored in default_invis_vector. */
4625 it
->dpvec_char_len
= it
->len
;
4626 it
->dpvec
= default_invis_vector
;
4627 it
->dpend
= default_invis_vector
+ 3;
4628 it
->current
.dpvec_index
= 0;
4629 it
->method
= next_element_from_display_vector
;
4634 /* The face at the current position may be different from the
4635 face we find after the invisible text. Remember what it
4636 was in IT->saved_face_id, and signal that it's there by
4637 setting face_before_selective_p. */
4638 it
->saved_face_id
= it
->face_id
;
4639 it
->method
= next_element_from_buffer
;
4640 reseat_at_next_visible_line_start (it
, 1);
4641 it
->face_before_selective_p
= 1;
4644 return get_next_display_element (it
);
4648 /* Deliver an image display element. The iterator IT is already
4649 filled with image information (done in handle_display_prop). Value
4654 next_element_from_image (it
)
4657 it
->what
= IT_IMAGE
;
4662 /* Fill iterator IT with next display element from a stretch glyph
4663 property. IT->object is the value of the text property. Value is
4667 next_element_from_stretch (it
)
4670 it
->what
= IT_STRETCH
;
4675 /* Load IT with the next display element from current_buffer. Value
4676 is zero if end of buffer reached. IT->stop_charpos is the next
4677 position at which to stop and check for text properties or buffer
4681 next_element_from_buffer (it
)
4686 /* Check this assumption, otherwise, we would never enter the
4687 if-statement, below. */
4688 xassert (IT_CHARPOS (*it
) >= BEGV
4689 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4691 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4693 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4695 int overlay_strings_follow_p
;
4697 /* End of the game, except when overlay strings follow that
4698 haven't been returned yet. */
4699 if (it
->overlay_strings_at_end_processed_p
)
4700 overlay_strings_follow_p
= 0;
4703 it
->overlay_strings_at_end_processed_p
= 1;
4704 overlay_strings_follow_p
= get_overlay_strings (it
);
4707 if (overlay_strings_follow_p
)
4708 success_p
= get_next_display_element (it
);
4712 it
->position
= it
->current
.pos
;
4719 return get_next_display_element (it
);
4724 /* No face changes, overlays etc. in sight, so just return a
4725 character from current_buffer. */
4728 /* Maybe run the redisplay end trigger hook. Performance note:
4729 This doesn't seem to cost measurable time. */
4730 if (it
->redisplay_end_trigger_charpos
4732 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4733 run_redisplay_end_trigger_hook (it
);
4735 /* Get the next character, maybe multibyte. */
4736 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4737 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4739 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4740 - IT_BYTEPOS (*it
));
4741 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4744 it
->c
= *p
, it
->len
= 1;
4746 /* Record what we have and where it came from. */
4747 it
->what
= IT_CHARACTER
;;
4748 it
->object
= it
->w
->buffer
;
4749 it
->position
= it
->current
.pos
;
4751 /* Normally we return the character found above, except when we
4752 really want to return an ellipsis for selective display. */
4757 /* A value of selective > 0 means hide lines indented more
4758 than that number of columns. */
4759 if (it
->selective
> 0
4760 && IT_CHARPOS (*it
) + 1 < ZV
4761 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4762 IT_BYTEPOS (*it
) + 1,
4765 success_p
= next_element_from_ellipsis (it
);
4766 it
->dpvec_char_len
= -1;
4769 else if (it
->c
== '\r' && it
->selective
== -1)
4771 /* A value of selective == -1 means that everything from the
4772 CR to the end of the line is invisible, with maybe an
4773 ellipsis displayed for it. */
4774 success_p
= next_element_from_ellipsis (it
);
4775 it
->dpvec_char_len
= -1;
4780 /* Value is zero if end of buffer reached. */
4781 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4786 /* Run the redisplay end trigger hook for IT. */
4789 run_redisplay_end_trigger_hook (it
)
4792 Lisp_Object args
[3];
4794 /* IT->glyph_row should be non-null, i.e. we should be actually
4795 displaying something, or otherwise we should not run the hook. */
4796 xassert (it
->glyph_row
);
4798 /* Set up hook arguments. */
4799 args
[0] = Qredisplay_end_trigger_functions
;
4800 args
[1] = it
->window
;
4801 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4802 it
->redisplay_end_trigger_charpos
= 0;
4804 /* Since we are *trying* to run these functions, don't try to run
4805 them again, even if they get an error. */
4806 it
->w
->redisplay_end_trigger
= Qnil
;
4807 Frun_hook_with_args (3, args
);
4809 /* Notice if it changed the face of the character we are on. */
4810 handle_face_prop (it
);
4814 /* Deliver a composition display element. The iterator IT is already
4815 filled with composition information (done in
4816 handle_composition_prop). Value is always 1. */
4819 next_element_from_composition (it
)
4822 it
->what
= IT_COMPOSITION
;
4823 it
->position
= (STRINGP (it
->string
)
4824 ? it
->current
.string_pos
4831 /***********************************************************************
4832 Moving an iterator without producing glyphs
4833 ***********************************************************************/
4835 /* Move iterator IT to a specified buffer or X position within one
4836 line on the display without producing glyphs.
4838 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4839 whichever is reached first.
4841 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4843 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4844 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4845 TO_X includes the amount by which a window is horizontally
4850 MOVE_POS_MATCH_OR_ZV
4851 - when TO_POS or ZV was reached.
4854 -when TO_X was reached before TO_POS or ZV were reached.
4857 - when we reached the end of the display area and the line must
4861 - when we reached the end of the display area and the line is
4865 - when we stopped at a line end, i.e. a newline or a CR and selective
4868 static enum move_it_result
4869 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4871 int to_charpos
, to_x
, op
;
4873 enum move_it_result result
= MOVE_UNDEFINED
;
4874 struct glyph_row
*saved_glyph_row
;
4876 /* Don't produce glyphs in produce_glyphs. */
4877 saved_glyph_row
= it
->glyph_row
;
4878 it
->glyph_row
= NULL
;
4882 int x
, i
, ascent
= 0, descent
= 0;
4884 /* Stop when ZV or TO_CHARPOS reached. */
4885 if (!get_next_display_element (it
)
4886 || ((op
& MOVE_TO_POS
) != 0
4887 && BUFFERP (it
->object
)
4888 && IT_CHARPOS (*it
) >= to_charpos
))
4890 result
= MOVE_POS_MATCH_OR_ZV
;
4894 /* The call to produce_glyphs will get the metrics of the
4895 display element IT is loaded with. We record in x the
4896 x-position before this display element in case it does not
4900 /* Remember the line height so far in case the next element doesn't
4902 if (!it
->truncate_lines_p
)
4904 ascent
= it
->max_ascent
;
4905 descent
= it
->max_descent
;
4908 PRODUCE_GLYPHS (it
);
4910 if (it
->area
!= TEXT_AREA
)
4912 set_iterator_to_next (it
, 1);
4916 /* The number of glyphs we get back in IT->nglyphs will normally
4917 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4918 character on a terminal frame, or (iii) a line end. For the
4919 second case, IT->nglyphs - 1 padding glyphs will be present
4920 (on X frames, there is only one glyph produced for a
4921 composite character.
4923 The behavior implemented below means, for continuation lines,
4924 that as many spaces of a TAB as fit on the current line are
4925 displayed there. For terminal frames, as many glyphs of a
4926 multi-glyph character are displayed in the current line, too.
4927 This is what the old redisplay code did, and we keep it that
4928 way. Under X, the whole shape of a complex character must
4929 fit on the line or it will be completely displayed in the
4932 Note that both for tabs and padding glyphs, all glyphs have
4936 /* More than one glyph or glyph doesn't fit on line. All
4937 glyphs have the same width. */
4938 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4941 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4943 new_x
= x
+ single_glyph_width
;
4945 /* We want to leave anything reaching TO_X to the caller. */
4946 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4949 result
= MOVE_X_REACHED
;
4952 else if (/* Lines are continued. */
4953 !it
->truncate_lines_p
4954 && (/* And glyph doesn't fit on the line. */
4955 new_x
> it
->last_visible_x
4956 /* Or it fits exactly and we're on a window
4958 || (new_x
== it
->last_visible_x
4959 && FRAME_WINDOW_P (it
->f
))))
4961 if (/* IT->hpos == 0 means the very first glyph
4962 doesn't fit on the line, e.g. a wide image. */
4964 || (new_x
== it
->last_visible_x
4965 && FRAME_WINDOW_P (it
->f
)))
4968 it
->current_x
= new_x
;
4969 if (i
== it
->nglyphs
- 1)
4970 set_iterator_to_next (it
, 1);
4975 it
->max_ascent
= ascent
;
4976 it
->max_descent
= descent
;
4979 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4981 result
= MOVE_LINE_CONTINUED
;
4984 else if (new_x
> it
->first_visible_x
)
4986 /* Glyph is visible. Increment number of glyphs that
4987 would be displayed. */
4992 /* Glyph is completely off the left margin of the display
4993 area. Nothing to do. */
4997 if (result
!= MOVE_UNDEFINED
)
5000 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5002 /* Stop when TO_X specified and reached. This check is
5003 necessary here because of lines consisting of a line end,
5004 only. The line end will not produce any glyphs and we
5005 would never get MOVE_X_REACHED. */
5006 xassert (it
->nglyphs
== 0);
5007 result
= MOVE_X_REACHED
;
5011 /* Is this a line end? If yes, we're done. */
5012 if (ITERATOR_AT_END_OF_LINE_P (it
))
5014 result
= MOVE_NEWLINE_OR_CR
;
5018 /* The current display element has been consumed. Advance
5020 set_iterator_to_next (it
, 1);
5022 /* Stop if lines are truncated and IT's current x-position is
5023 past the right edge of the window now. */
5024 if (it
->truncate_lines_p
5025 && it
->current_x
>= it
->last_visible_x
)
5027 result
= MOVE_LINE_TRUNCATED
;
5032 /* Restore the iterator settings altered at the beginning of this
5034 it
->glyph_row
= saved_glyph_row
;
5039 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5040 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5041 the description of enum move_operation_enum.
5043 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5044 screen line, this function will set IT to the next position >
5048 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5050 int to_charpos
, to_x
, to_y
, to_vpos
;
5053 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5059 if (op
& MOVE_TO_VPOS
)
5061 /* If no TO_CHARPOS and no TO_X specified, stop at the
5062 start of the line TO_VPOS. */
5063 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5065 if (it
->vpos
== to_vpos
)
5071 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5075 /* TO_VPOS >= 0 means stop at TO_X in the line at
5076 TO_VPOS, or at TO_POS, whichever comes first. */
5077 if (it
->vpos
== to_vpos
)
5083 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5085 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5090 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5092 /* We have reached TO_X but not in the line we want. */
5093 skip
= move_it_in_display_line_to (it
, to_charpos
,
5095 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5103 else if (op
& MOVE_TO_Y
)
5105 struct it it_backup
;
5107 /* TO_Y specified means stop at TO_X in the line containing
5108 TO_Y---or at TO_CHARPOS if this is reached first. The
5109 problem is that we can't really tell whether the line
5110 contains TO_Y before we have completely scanned it, and
5111 this may skip past TO_X. What we do is to first scan to
5114 If TO_X is not specified, use a TO_X of zero. The reason
5115 is to make the outcome of this function more predictable.
5116 If we didn't use TO_X == 0, we would stop at the end of
5117 the line which is probably not what a caller would expect
5119 skip
= move_it_in_display_line_to (it
, to_charpos
,
5123 | (op
& MOVE_TO_POS
)));
5125 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5126 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5132 /* If TO_X was reached, we would like to know whether TO_Y
5133 is in the line. This can only be said if we know the
5134 total line height which requires us to scan the rest of
5136 if (skip
== MOVE_X_REACHED
)
5139 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5140 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5142 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5145 /* Now, decide whether TO_Y is in this line. */
5146 line_height
= it
->max_ascent
+ it
->max_descent
;
5147 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5149 if (to_y
>= it
->current_y
5150 && to_y
< it
->current_y
+ line_height
)
5152 if (skip
== MOVE_X_REACHED
)
5153 /* If TO_Y is in this line and TO_X was reached above,
5154 we scanned too far. We have to restore IT's settings
5155 to the ones before skipping. */
5159 else if (skip
== MOVE_X_REACHED
)
5162 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5170 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5174 case MOVE_POS_MATCH_OR_ZV
:
5178 case MOVE_NEWLINE_OR_CR
:
5179 set_iterator_to_next (it
, 1);
5180 it
->continuation_lines_width
= 0;
5183 case MOVE_LINE_TRUNCATED
:
5184 it
->continuation_lines_width
= 0;
5185 reseat_at_next_visible_line_start (it
, 0);
5186 if ((op
& MOVE_TO_POS
) != 0
5187 && IT_CHARPOS (*it
) > to_charpos
)
5194 case MOVE_LINE_CONTINUED
:
5195 it
->continuation_lines_width
+= it
->current_x
;
5202 /* Reset/increment for the next run. */
5203 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5204 it
->current_x
= it
->hpos
= 0;
5205 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5207 last_height
= it
->max_ascent
+ it
->max_descent
;
5208 last_max_ascent
= it
->max_ascent
;
5209 it
->max_ascent
= it
->max_descent
= 0;
5214 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5218 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5220 If DY > 0, move IT backward at least that many pixels. DY = 0
5221 means move IT backward to the preceding line start or BEGV. This
5222 function may move over more than DY pixels if IT->current_y - DY
5223 ends up in the middle of a line; in this case IT->current_y will be
5224 set to the top of the line moved to. */
5227 move_it_vertically_backward (it
, dy
)
5231 int nlines
, h
, line_height
;
5233 int start_pos
= IT_CHARPOS (*it
);
5237 /* Estimate how many newlines we must move back. */
5238 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5240 /* Set the iterator's position that many lines back. */
5241 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5242 back_to_previous_visible_line_start (it
);
5244 /* Reseat the iterator here. When moving backward, we don't want
5245 reseat to skip forward over invisible text, set up the iterator
5246 to deliver from overlay strings at the new position etc. So,
5247 use reseat_1 here. */
5248 reseat_1 (it
, it
->current
.pos
, 1);
5250 /* We are now surely at a line start. */
5251 it
->current_x
= it
->hpos
= 0;
5253 /* Move forward and see what y-distance we moved. First move to the
5254 start of the next line so that we get its height. We need this
5255 height to be able to tell whether we reached the specified
5258 it2
.max_ascent
= it2
.max_descent
= 0;
5259 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5260 MOVE_TO_POS
| MOVE_TO_VPOS
);
5261 xassert (IT_CHARPOS (*it
) >= BEGV
);
5262 line_height
= it2
.max_ascent
+ it2
.max_descent
;
5264 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5265 xassert (IT_CHARPOS (*it
) >= BEGV
);
5266 h
= it2
.current_y
- it
->current_y
;
5267 nlines
= it2
.vpos
- it
->vpos
;
5269 /* Correct IT's y and vpos position. */
5275 /* DY == 0 means move to the start of the screen line. The
5276 value of nlines is > 0 if continuation lines were involved. */
5278 move_it_by_lines (it
, nlines
, 1);
5279 xassert (IT_CHARPOS (*it
) <= start_pos
);
5283 /* The y-position we try to reach. Note that h has been
5284 subtracted in front of the if-statement. */
5285 int target_y
= it
->current_y
+ h
- dy
;
5287 /* If we did not reach target_y, try to move further backward if
5288 we can. If we moved too far backward, try to move forward. */
5289 if (target_y
< it
->current_y
5290 && IT_CHARPOS (*it
) > BEGV
)
5292 move_it_vertically (it
, target_y
- it
->current_y
);
5293 xassert (IT_CHARPOS (*it
) >= BEGV
);
5295 else if (target_y
>= it
->current_y
+ line_height
5296 && IT_CHARPOS (*it
) < ZV
)
5298 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5299 xassert (IT_CHARPOS (*it
) >= BEGV
);
5305 /* Move IT by a specified amount of pixel lines DY. DY negative means
5306 move backwards. DY = 0 means move to start of screen line. At the
5307 end, IT will be on the start of a screen line. */
5310 move_it_vertically (it
, dy
)
5315 move_it_vertically_backward (it
, -dy
);
5318 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5319 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5320 MOVE_TO_POS
| MOVE_TO_Y
);
5321 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5323 /* If buffer ends in ZV without a newline, move to the start of
5324 the line to satisfy the post-condition. */
5325 if (IT_CHARPOS (*it
) == ZV
5326 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5327 move_it_by_lines (it
, 0, 0);
5332 /* Move iterator IT past the end of the text line it is in. */
5335 move_it_past_eol (it
)
5338 enum move_it_result rc
;
5340 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5341 if (rc
== MOVE_NEWLINE_OR_CR
)
5342 set_iterator_to_next (it
, 0);
5346 #if 0 /* Currently not used. */
5348 /* Return non-zero if some text between buffer positions START_CHARPOS
5349 and END_CHARPOS is invisible. IT->window is the window for text
5353 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5355 int start_charpos
, end_charpos
;
5357 Lisp_Object prop
, limit
;
5358 int invisible_found_p
;
5360 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5362 /* Is text at START invisible? */
5363 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5365 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5366 invisible_found_p
= 1;
5369 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5371 make_number (end_charpos
));
5372 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5375 return invisible_found_p
;
5381 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5382 negative means move up. DVPOS == 0 means move to the start of the
5383 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5384 NEED_Y_P is zero, IT->current_y will be left unchanged.
5386 Further optimization ideas: If we would know that IT->f doesn't use
5387 a face with proportional font, we could be faster for
5388 truncate-lines nil. */
5391 move_it_by_lines (it
, dvpos
, need_y_p
)
5393 int dvpos
, need_y_p
;
5395 struct position pos
;
5397 if (!FRAME_WINDOW_P (it
->f
))
5399 struct text_pos textpos
;
5401 /* We can use vmotion on frames without proportional fonts. */
5402 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5403 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5404 reseat (it
, textpos
, 1);
5405 it
->vpos
+= pos
.vpos
;
5406 it
->current_y
+= pos
.vpos
;
5408 else if (dvpos
== 0)
5410 /* DVPOS == 0 means move to the start of the screen line. */
5411 move_it_vertically_backward (it
, 0);
5412 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5415 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5419 int start_charpos
, i
;
5421 /* Go back -DVPOS visible lines and reseat the iterator there. */
5422 start_charpos
= IT_CHARPOS (*it
);
5423 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5424 back_to_previous_visible_line_start (it
);
5425 reseat (it
, it
->current
.pos
, 1);
5426 it
->current_x
= it
->hpos
= 0;
5428 /* Above call may have moved too far if continuation lines
5429 are involved. Scan forward and see if it did. */
5431 it2
.vpos
= it2
.current_y
= 0;
5432 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5433 it
->vpos
-= it2
.vpos
;
5434 it
->current_y
-= it2
.current_y
;
5435 it
->current_x
= it
->hpos
= 0;
5437 /* If we moved too far, move IT some lines forward. */
5438 if (it2
.vpos
> -dvpos
)
5440 int delta
= it2
.vpos
+ dvpos
;
5441 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5448 /***********************************************************************
5450 ***********************************************************************/
5453 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5457 add_to_log (format
, arg1
, arg2
)
5459 Lisp_Object arg1
, arg2
;
5461 Lisp_Object args
[3];
5462 Lisp_Object msg
, fmt
;
5465 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5468 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5470 args
[0] = fmt
= build_string (format
);
5473 msg
= Fformat (3, args
);
5475 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5476 buffer
= (char *) alloca (len
);
5477 strcpy (buffer
, XSTRING (msg
)->data
);
5479 message_dolog (buffer
, len
- 1, 1, 0);
5484 /* Output a newline in the *Messages* buffer if "needs" one. */
5487 message_log_maybe_newline ()
5489 if (message_log_need_newline
)
5490 message_dolog ("", 0, 1, 0);
5494 /* Add a string M of length NBYTES to the message log, optionally
5495 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5496 nonzero, means interpret the contents of M as multibyte. This
5497 function calls low-level routines in order to bypass text property
5498 hooks, etc. which might not be safe to run. */
5501 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5503 int nbytes
, nlflag
, multibyte
;
5505 if (!NILP (Vmessage_log_max
))
5507 struct buffer
*oldbuf
;
5508 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5509 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5510 int point_at_end
= 0;
5512 Lisp_Object old_deactivate_mark
, tem
;
5513 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5515 old_deactivate_mark
= Vdeactivate_mark
;
5516 oldbuf
= current_buffer
;
5517 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5518 current_buffer
->undo_list
= Qt
;
5520 oldpoint
= Fpoint_marker ();
5521 oldbegv
= Fpoint_min_marker ();
5522 oldzv
= Fpoint_max_marker ();
5523 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5531 BEGV_BYTE
= BEG_BYTE
;
5534 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5536 /* Insert the string--maybe converting multibyte to single byte
5537 or vice versa, so that all the text fits the buffer. */
5539 && NILP (current_buffer
->enable_multibyte_characters
))
5541 int i
, c
, char_bytes
;
5542 unsigned char work
[1];
5544 /* Convert a multibyte string to single-byte
5545 for the *Message* buffer. */
5546 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5548 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5549 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5551 : multibyte_char_to_unibyte (c
, Qnil
));
5552 insert_1_both (work
, 1, 1, 1, 0, 0);
5555 else if (! multibyte
5556 && ! NILP (current_buffer
->enable_multibyte_characters
))
5558 int i
, c
, char_bytes
;
5559 unsigned char *msg
= (unsigned char *) m
;
5560 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5561 /* Convert a single-byte string to multibyte
5562 for the *Message* buffer. */
5563 for (i
= 0; i
< nbytes
; i
++)
5565 c
= unibyte_char_to_multibyte (msg
[i
]);
5566 char_bytes
= CHAR_STRING (c
, str
);
5567 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5571 insert_1 (m
, nbytes
, 1, 0, 0);
5575 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5576 insert_1 ("\n", 1, 1, 0, 0);
5578 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5580 this_bol_byte
= PT_BYTE
;
5584 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5586 prev_bol_byte
= PT_BYTE
;
5588 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5589 this_bol
, this_bol_byte
);
5592 del_range_both (prev_bol
, prev_bol_byte
,
5593 this_bol
, this_bol_byte
, 0);
5599 /* If you change this format, don't forget to also
5600 change message_log_check_duplicate. */
5601 sprintf (dupstr
, " [%d times]", dup
);
5602 duplen
= strlen (dupstr
);
5603 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5604 insert_1 (dupstr
, duplen
, 1, 0, 1);
5609 if (NATNUMP (Vmessage_log_max
))
5611 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5612 -XFASTINT (Vmessage_log_max
) - 1, 0);
5613 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5616 BEGV
= XMARKER (oldbegv
)->charpos
;
5617 BEGV_BYTE
= marker_byte_position (oldbegv
);
5626 ZV
= XMARKER (oldzv
)->charpos
;
5627 ZV_BYTE
= marker_byte_position (oldzv
);
5631 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5633 /* We can't do Fgoto_char (oldpoint) because it will run some
5635 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5636 XMARKER (oldpoint
)->bytepos
);
5639 free_marker (oldpoint
);
5640 free_marker (oldbegv
);
5641 free_marker (oldzv
);
5643 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5644 set_buffer_internal (oldbuf
);
5646 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5647 message_log_need_newline
= !nlflag
;
5648 Vdeactivate_mark
= old_deactivate_mark
;
5653 /* We are at the end of the buffer after just having inserted a newline.
5654 (Note: We depend on the fact we won't be crossing the gap.)
5655 Check to see if the most recent message looks a lot like the previous one.
5656 Return 0 if different, 1 if the new one should just replace it, or a
5657 value N > 1 if we should also append " [N times]". */
5660 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5661 int prev_bol
, this_bol
;
5662 int prev_bol_byte
, this_bol_byte
;
5665 int len
= Z_BYTE
- 1 - this_bol_byte
;
5667 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5668 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5670 for (i
= 0; i
< len
; i
++)
5672 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5680 if (*p1
++ == ' ' && *p1
++ == '[')
5683 while (*p1
>= '0' && *p1
<= '9')
5684 n
= n
* 10 + *p1
++ - '0';
5685 if (strncmp (p1
, " times]\n", 8) == 0)
5692 /* Display an echo area message M with a specified length of NBYTES
5693 bytes. The string may include null characters. If M is 0, clear
5694 out any existing message, and let the mini-buffer text show
5697 The buffer M must continue to exist until after the echo area gets
5698 cleared or some other message gets displayed there. This means do
5699 not pass text that is stored in a Lisp string; do not pass text in
5700 a buffer that was alloca'd. */
5703 message2 (m
, nbytes
, multibyte
)
5708 /* First flush out any partial line written with print. */
5709 message_log_maybe_newline ();
5711 message_dolog (m
, nbytes
, 1, multibyte
);
5712 message2_nolog (m
, nbytes
, multibyte
);
5716 /* The non-logging counterpart of message2. */
5719 message2_nolog (m
, nbytes
, multibyte
)
5723 struct frame
*sf
= SELECTED_FRAME ();
5724 message_enable_multibyte
= multibyte
;
5728 if (noninteractive_need_newline
)
5729 putc ('\n', stderr
);
5730 noninteractive_need_newline
= 0;
5732 fwrite (m
, nbytes
, 1, stderr
);
5733 if (cursor_in_echo_area
== 0)
5734 fprintf (stderr
, "\n");
5737 /* A null message buffer means that the frame hasn't really been
5738 initialized yet. Error messages get reported properly by
5739 cmd_error, so this must be just an informative message; toss it. */
5740 else if (INTERACTIVE
5741 && sf
->glyphs_initialized_p
5742 && FRAME_MESSAGE_BUF (sf
))
5744 Lisp_Object mini_window
;
5747 /* Get the frame containing the mini-buffer
5748 that the selected frame is using. */
5749 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5750 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5752 FRAME_SAMPLE_VISIBILITY (f
);
5753 if (FRAME_VISIBLE_P (sf
)
5754 && ! FRAME_VISIBLE_P (f
))
5755 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5759 set_message (m
, Qnil
, nbytes
, multibyte
);
5760 if (minibuffer_auto_raise
)
5761 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5764 clear_message (1, 1);
5766 do_pending_window_change (0);
5767 echo_area_display (1);
5768 do_pending_window_change (0);
5769 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5770 (*frame_up_to_date_hook
) (f
);
5775 /* Display an echo area message M with a specified length of NBYTES
5776 bytes. The string may include null characters. If M is not a
5777 string, clear out any existing message, and let the mini-buffer
5778 text show through. */
5781 message3 (m
, nbytes
, multibyte
)
5786 struct gcpro gcpro1
;
5790 /* First flush out any partial line written with print. */
5791 message_log_maybe_newline ();
5793 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5794 message3_nolog (m
, nbytes
, multibyte
);
5800 /* The non-logging version of message3. */
5803 message3_nolog (m
, nbytes
, multibyte
)
5805 int nbytes
, multibyte
;
5807 struct frame
*sf
= SELECTED_FRAME ();
5808 message_enable_multibyte
= multibyte
;
5812 if (noninteractive_need_newline
)
5813 putc ('\n', stderr
);
5814 noninteractive_need_newline
= 0;
5816 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5817 if (cursor_in_echo_area
== 0)
5818 fprintf (stderr
, "\n");
5821 /* A null message buffer means that the frame hasn't really been
5822 initialized yet. Error messages get reported properly by
5823 cmd_error, so this must be just an informative message; toss it. */
5824 else if (INTERACTIVE
5825 && sf
->glyphs_initialized_p
5826 && FRAME_MESSAGE_BUF (sf
))
5828 Lisp_Object mini_window
;
5832 /* Get the frame containing the mini-buffer
5833 that the selected frame is using. */
5834 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5835 frame
= XWINDOW (mini_window
)->frame
;
5838 FRAME_SAMPLE_VISIBILITY (f
);
5839 if (FRAME_VISIBLE_P (sf
)
5840 && !FRAME_VISIBLE_P (f
))
5841 Fmake_frame_visible (frame
);
5843 if (STRINGP (m
) && XSTRING (m
)->size
)
5845 set_message (NULL
, m
, nbytes
, multibyte
);
5846 if (minibuffer_auto_raise
)
5847 Fraise_frame (frame
);
5850 clear_message (1, 1);
5852 do_pending_window_change (0);
5853 echo_area_display (1);
5854 do_pending_window_change (0);
5855 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5856 (*frame_up_to_date_hook
) (f
);
5861 /* Display a null-terminated echo area message M. If M is 0, clear
5862 out any existing message, and let the mini-buffer text show through.
5864 The buffer M must continue to exist until after the echo area gets
5865 cleared or some other message gets displayed there. Do not pass
5866 text that is stored in a Lisp string. Do not pass text in a buffer
5867 that was alloca'd. */
5873 message2 (m
, (m
? strlen (m
) : 0), 0);
5877 /* The non-logging counterpart of message1. */
5883 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5886 /* Display a message M which contains a single %s
5887 which gets replaced with STRING. */
5890 message_with_string (m
, string
, log
)
5899 if (noninteractive_need_newline
)
5900 putc ('\n', stderr
);
5901 noninteractive_need_newline
= 0;
5902 fprintf (stderr
, m
, XSTRING (string
)->data
);
5903 if (cursor_in_echo_area
== 0)
5904 fprintf (stderr
, "\n");
5908 else if (INTERACTIVE
)
5910 /* The frame whose minibuffer we're going to display the message on.
5911 It may be larger than the selected frame, so we need
5912 to use its buffer, not the selected frame's buffer. */
5913 Lisp_Object mini_window
;
5914 struct frame
*f
, *sf
= SELECTED_FRAME ();
5916 /* Get the frame containing the minibuffer
5917 that the selected frame is using. */
5918 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5919 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5921 /* A null message buffer means that the frame hasn't really been
5922 initialized yet. Error messages get reported properly by
5923 cmd_error, so this must be just an informative message; toss it. */
5924 if (FRAME_MESSAGE_BUF (f
))
5928 a
[0] = (char *) XSTRING (string
)->data
;
5930 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5931 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5934 message2 (FRAME_MESSAGE_BUF (f
), len
,
5935 STRING_MULTIBYTE (string
));
5937 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5938 STRING_MULTIBYTE (string
));
5940 /* Print should start at the beginning of the message
5941 buffer next time. */
5942 message_buf_print
= 0;
5948 /* Dump an informative message to the minibuf. If M is 0, clear out
5949 any existing message, and let the mini-buffer text show through. */
5953 message (m
, a1
, a2
, a3
)
5955 EMACS_INT a1
, a2
, a3
;
5961 if (noninteractive_need_newline
)
5962 putc ('\n', stderr
);
5963 noninteractive_need_newline
= 0;
5964 fprintf (stderr
, m
, a1
, a2
, a3
);
5965 if (cursor_in_echo_area
== 0)
5966 fprintf (stderr
, "\n");
5970 else if (INTERACTIVE
)
5972 /* The frame whose mini-buffer we're going to display the message
5973 on. It may be larger than the selected frame, so we need to
5974 use its buffer, not the selected frame's buffer. */
5975 Lisp_Object mini_window
;
5976 struct frame
*f
, *sf
= SELECTED_FRAME ();
5978 /* Get the frame containing the mini-buffer
5979 that the selected frame is using. */
5980 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5981 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5983 /* A null message buffer means that the frame hasn't really been
5984 initialized yet. Error messages get reported properly by
5985 cmd_error, so this must be just an informative message; toss
5987 if (FRAME_MESSAGE_BUF (f
))
5998 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5999 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6001 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6002 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6004 #endif /* NO_ARG_ARRAY */
6006 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6011 /* Print should start at the beginning of the message
6012 buffer next time. */
6013 message_buf_print
= 0;
6019 /* The non-logging version of message. */
6022 message_nolog (m
, a1
, a2
, a3
)
6024 EMACS_INT a1
, a2
, a3
;
6026 Lisp_Object old_log_max
;
6027 old_log_max
= Vmessage_log_max
;
6028 Vmessage_log_max
= Qnil
;
6029 message (m
, a1
, a2
, a3
);
6030 Vmessage_log_max
= old_log_max
;
6034 /* Display the current message in the current mini-buffer. This is
6035 only called from error handlers in process.c, and is not time
6041 if (!NILP (echo_area_buffer
[0]))
6044 string
= Fcurrent_message ();
6045 message3 (string
, XSTRING (string
)->size
,
6046 !NILP (current_buffer
->enable_multibyte_characters
));
6051 /* Make sure echo area buffers in echo_buffers[] are life. If they
6052 aren't, make new ones. */
6055 ensure_echo_area_buffers ()
6059 for (i
= 0; i
< 2; ++i
)
6060 if (!BUFFERP (echo_buffer
[i
])
6061 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6064 Lisp_Object old_buffer
;
6067 old_buffer
= echo_buffer
[i
];
6068 sprintf (name
, " *Echo Area %d*", i
);
6069 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6070 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6072 for (j
= 0; j
< 2; ++j
)
6073 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6074 echo_area_buffer
[j
] = echo_buffer
[i
];
6079 /* Call FN with args A1..A4 with either the current or last displayed
6080 echo_area_buffer as current buffer.
6082 WHICH zero means use the current message buffer
6083 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6084 from echo_buffer[] and clear it.
6086 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6087 suitable buffer from echo_buffer[] and clear it.
6089 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6090 that the current message becomes the last displayed one, make
6091 choose a suitable buffer for echo_area_buffer[0], and clear it.
6093 Value is what FN returns. */
6096 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6099 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6105 int this_one
, the_other
, clear_buffer_p
, rc
;
6106 int count
= BINDING_STACK_SIZE ();
6108 /* If buffers aren't life, make new ones. */
6109 ensure_echo_area_buffers ();
6114 this_one
= 0, the_other
= 1;
6116 this_one
= 1, the_other
= 0;
6119 this_one
= 0, the_other
= 1;
6122 /* We need a fresh one in case the current echo buffer equals
6123 the one containing the last displayed echo area message. */
6124 if (!NILP (echo_area_buffer
[this_one
])
6125 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6126 echo_area_buffer
[this_one
] = Qnil
;
6129 /* Choose a suitable buffer from echo_buffer[] is we don't
6131 if (NILP (echo_area_buffer
[this_one
]))
6133 echo_area_buffer
[this_one
]
6134 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6135 ? echo_buffer
[the_other
]
6136 : echo_buffer
[this_one
]);
6140 buffer
= echo_area_buffer
[this_one
];
6142 record_unwind_protect (unwind_with_echo_area_buffer
,
6143 with_echo_area_buffer_unwind_data (w
));
6145 /* Make the echo area buffer current. Note that for display
6146 purposes, it is not necessary that the displayed window's buffer
6147 == current_buffer, except for text property lookup. So, let's
6148 only set that buffer temporarily here without doing a full
6149 Fset_window_buffer. We must also change w->pointm, though,
6150 because otherwise an assertions in unshow_buffer fails, and Emacs
6152 set_buffer_internal_1 (XBUFFER (buffer
));
6156 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6159 current_buffer
->undo_list
= Qt
;
6160 current_buffer
->read_only
= Qnil
;
6161 specbind (Qinhibit_read_only
, Qt
);
6163 if (clear_buffer_p
&& Z
> BEG
)
6166 xassert (BEGV
>= BEG
);
6167 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6169 rc
= fn (a1
, a2
, a3
, a4
);
6171 xassert (BEGV
>= BEG
);
6172 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6174 unbind_to (count
, Qnil
);
6179 /* Save state that should be preserved around the call to the function
6180 FN called in with_echo_area_buffer. */
6183 with_echo_area_buffer_unwind_data (w
)
6189 /* Reduce consing by keeping one vector in
6190 Vwith_echo_area_save_vector. */
6191 vector
= Vwith_echo_area_save_vector
;
6192 Vwith_echo_area_save_vector
= Qnil
;
6195 vector
= Fmake_vector (make_number (7), Qnil
);
6197 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6198 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6199 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6203 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6204 AREF (vector
, i
) = w
->buffer
; ++i
;
6205 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6206 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6211 for (; i
< end
; ++i
)
6212 AREF (vector
, i
) = Qnil
;
6215 xassert (i
== ASIZE (vector
));
6220 /* Restore global state from VECTOR which was created by
6221 with_echo_area_buffer_unwind_data. */
6224 unwind_with_echo_area_buffer (vector
)
6227 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6228 Vdeactivate_mark
= AREF (vector
, 1);
6229 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6231 if (WINDOWP (AREF (vector
, 3)))
6234 Lisp_Object buffer
, charpos
, bytepos
;
6236 w
= XWINDOW (AREF (vector
, 3));
6237 buffer
= AREF (vector
, 4);
6238 charpos
= AREF (vector
, 5);
6239 bytepos
= AREF (vector
, 6);
6242 set_marker_both (w
->pointm
, buffer
,
6243 XFASTINT (charpos
), XFASTINT (bytepos
));
6246 Vwith_echo_area_save_vector
= vector
;
6251 /* Set up the echo area for use by print functions. MULTIBYTE_P
6252 non-zero means we will print multibyte. */
6255 setup_echo_area_for_printing (multibyte_p
)
6258 ensure_echo_area_buffers ();
6260 if (!message_buf_print
)
6262 /* A message has been output since the last time we printed.
6263 Choose a fresh echo area buffer. */
6264 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6265 echo_area_buffer
[0] = echo_buffer
[1];
6267 echo_area_buffer
[0] = echo_buffer
[0];
6269 /* Switch to that buffer and clear it. */
6270 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6271 current_buffer
->truncate_lines
= Qnil
;
6275 int count
= BINDING_STACK_SIZE ();
6276 specbind (Qinhibit_read_only
, Qt
);
6278 unbind_to (count
, Qnil
);
6280 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6282 /* Set up the buffer for the multibyteness we need. */
6284 != !NILP (current_buffer
->enable_multibyte_characters
))
6285 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6287 /* Raise the frame containing the echo area. */
6288 if (minibuffer_auto_raise
)
6290 struct frame
*sf
= SELECTED_FRAME ();
6291 Lisp_Object mini_window
;
6292 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6293 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6296 message_log_maybe_newline ();
6297 message_buf_print
= 1;
6301 if (NILP (echo_area_buffer
[0]))
6303 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6304 echo_area_buffer
[0] = echo_buffer
[1];
6306 echo_area_buffer
[0] = echo_buffer
[0];
6309 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6311 /* Someone switched buffers between print requests. */
6312 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6313 current_buffer
->truncate_lines
= Qnil
;
6319 /* Display an echo area message in window W. Value is non-zero if W's
6320 height is changed. If display_last_displayed_message_p is
6321 non-zero, display the message that was last displayed, otherwise
6322 display the current message. */
6325 display_echo_area (w
)
6328 int i
, no_message_p
, window_height_changed_p
, count
;
6330 /* Temporarily disable garbage collections while displaying the echo
6331 area. This is done because a GC can print a message itself.
6332 That message would modify the echo area buffer's contents while a
6333 redisplay of the buffer is going on, and seriously confuse
6335 count
= inhibit_garbage_collection ();
6337 /* If there is no message, we must call display_echo_area_1
6338 nevertheless because it resizes the window. But we will have to
6339 reset the echo_area_buffer in question to nil at the end because
6340 with_echo_area_buffer will sets it to an empty buffer. */
6341 i
= display_last_displayed_message_p
? 1 : 0;
6342 no_message_p
= NILP (echo_area_buffer
[i
]);
6344 window_height_changed_p
6345 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6346 display_echo_area_1
,
6347 (EMACS_INT
) w
, Qnil
, 0, 0);
6350 echo_area_buffer
[i
] = Qnil
;
6352 unbind_to (count
, Qnil
);
6353 return window_height_changed_p
;
6357 /* Helper for display_echo_area. Display the current buffer which
6358 contains the current echo area message in window W, a mini-window,
6359 a pointer to which is passed in A1. A2..A4 are currently not used.
6360 Change the height of W so that all of the message is displayed.
6361 Value is non-zero if height of W was changed. */
6364 display_echo_area_1 (a1
, a2
, a3
, a4
)
6369 struct window
*w
= (struct window
*) a1
;
6371 struct text_pos start
;
6372 int window_height_changed_p
= 0;
6374 /* Do this before displaying, so that we have a large enough glyph
6375 matrix for the display. */
6376 window_height_changed_p
= resize_mini_window (w
, 0);
6379 clear_glyph_matrix (w
->desired_matrix
);
6380 XSETWINDOW (window
, w
);
6381 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6382 try_window (window
, start
);
6384 return window_height_changed_p
;
6388 /* Resize the echo area window to exactly the size needed for the
6389 currently displayed message, if there is one. */
6392 resize_echo_area_axactly ()
6394 if (BUFFERP (echo_area_buffer
[0])
6395 && WINDOWP (echo_area_window
))
6397 struct window
*w
= XWINDOW (echo_area_window
);
6400 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6401 (EMACS_INT
) w
, Qnil
, 0, 0);
6404 ++windows_or_buffers_changed
;
6405 ++update_mode_lines
;
6406 redisplay_internal (0);
6412 /* Callback function for with_echo_area_buffer, when used from
6413 resize_echo_area_axactly. A1 contains a pointer to the window to
6414 resize, A2 to A4 are not used. Value is what resize_mini_window
6418 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6423 return resize_mini_window ((struct window
*) a1
, 1);
6427 /* Resize mini-window W to fit the size of its contents. EXACT:P
6428 means size the window exactly to the size needed. Otherwise, it's
6429 only enlarged until W's buffer is empty. Value is non-zero if
6430 the window height has been changed. */
6433 resize_mini_window (w
, exact_p
)
6437 struct frame
*f
= XFRAME (w
->frame
);
6438 int window_height_changed_p
= 0;
6440 xassert (MINI_WINDOW_P (w
));
6442 /* Nil means don't try to resize. */
6443 if (NILP (Vresize_mini_windows
)
6444 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6447 if (!FRAME_MINIBUF_ONLY_P (f
))
6450 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6451 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6452 int height
, max_height
;
6453 int unit
= CANON_Y_UNIT (f
);
6454 struct text_pos start
;
6455 struct buffer
*old_current_buffer
= NULL
;
6457 if (current_buffer
!= XBUFFER (w
->buffer
))
6459 old_current_buffer
= current_buffer
;
6460 set_buffer_internal (XBUFFER (w
->buffer
));
6463 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6465 /* Compute the max. number of lines specified by the user. */
6466 if (FLOATP (Vmax_mini_window_height
))
6467 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6468 else if (INTEGERP (Vmax_mini_window_height
))
6469 max_height
= XINT (Vmax_mini_window_height
);
6471 max_height
= total_height
/ 4;
6473 /* Correct that max. height if it's bogus. */
6474 max_height
= max (1, max_height
);
6475 max_height
= min (total_height
, max_height
);
6477 /* Find out the height of the text in the window. */
6478 if (it
.truncate_lines_p
)
6483 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6484 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6485 height
= it
.current_y
+ last_height
;
6487 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6488 height
-= it
.extra_line_spacing
;
6489 height
= (height
+ unit
- 1) / unit
;
6492 /* Compute a suitable window start. */
6493 if (height
> max_height
)
6495 height
= max_height
;
6496 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6497 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6498 start
= it
.current
.pos
;
6501 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6502 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6504 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6506 /* Let it grow only, until we display an empty message, in which
6507 case the window shrinks again. */
6508 if (height
> XFASTINT (w
->height
))
6510 int old_height
= XFASTINT (w
->height
);
6511 freeze_window_starts (f
, 1);
6512 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6513 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6515 else if (height
< XFASTINT (w
->height
)
6516 && (exact_p
|| BEGV
== ZV
))
6518 int old_height
= XFASTINT (w
->height
);
6519 freeze_window_starts (f
, 0);
6520 shrink_mini_window (w
);
6521 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6526 /* Always resize to exact size needed. */
6527 if (height
> XFASTINT (w
->height
))
6529 int old_height
= XFASTINT (w
->height
);
6530 freeze_window_starts (f
, 1);
6531 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6532 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6534 else if (height
< XFASTINT (w
->height
))
6536 int old_height
= XFASTINT (w
->height
);
6537 freeze_window_starts (f
, 0);
6538 shrink_mini_window (w
);
6542 freeze_window_starts (f
, 1);
6543 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6546 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6550 if (old_current_buffer
)
6551 set_buffer_internal (old_current_buffer
);
6554 return window_height_changed_p
;
6558 /* Value is the current message, a string, or nil if there is no
6566 if (NILP (echo_area_buffer
[0]))
6570 with_echo_area_buffer (0, 0, current_message_1
,
6571 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6573 echo_area_buffer
[0] = Qnil
;
6581 current_message_1 (a1
, a2
, a3
, a4
)
6586 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6589 *msg
= make_buffer_string (BEG
, Z
, 1);
6596 /* Push the current message on Vmessage_stack for later restauration
6597 by restore_message. Value is non-zero if the current message isn't
6598 empty. This is a relatively infrequent operation, so it's not
6599 worth optimizing. */
6605 msg
= current_message ();
6606 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6607 return STRINGP (msg
);
6611 /* Handler for record_unwind_protect calling pop_message. */
6614 push_message_unwind (dummy
)
6622 /* Restore message display from the top of Vmessage_stack. */
6629 xassert (CONSP (Vmessage_stack
));
6630 msg
= XCAR (Vmessage_stack
);
6632 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6634 message3_nolog (msg
, 0, 0);
6638 /* Pop the top-most entry off Vmessage_stack. */
6643 xassert (CONSP (Vmessage_stack
));
6644 Vmessage_stack
= XCDR (Vmessage_stack
);
6648 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6649 exits. If the stack is not empty, we have a missing pop_message
6653 check_message_stack ()
6655 if (!NILP (Vmessage_stack
))
6660 /* Truncate to NCHARS what will be displayed in the echo area the next
6661 time we display it---but don't redisplay it now. */
6664 truncate_echo_area (nchars
)
6668 echo_area_buffer
[0] = Qnil
;
6669 /* A null message buffer means that the frame hasn't really been
6670 initialized yet. Error messages get reported properly by
6671 cmd_error, so this must be just an informative message; toss it. */
6672 else if (!noninteractive
6674 && !NILP (echo_area_buffer
[0]))
6676 struct frame
*sf
= SELECTED_FRAME ();
6677 if (FRAME_MESSAGE_BUF (sf
))
6678 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6683 /* Helper function for truncate_echo_area. Truncate the current
6684 message to at most NCHARS characters. */
6687 truncate_message_1 (nchars
, a2
, a3
, a4
)
6692 if (BEG
+ nchars
< Z
)
6693 del_range (BEG
+ nchars
, Z
);
6695 echo_area_buffer
[0] = Qnil
;
6700 /* Set the current message to a substring of S or STRING.
6702 If STRING is a Lisp string, set the message to the first NBYTES
6703 bytes from STRING. NBYTES zero means use the whole string. If
6704 STRING is multibyte, the message will be displayed multibyte.
6706 If S is not null, set the message to the first LEN bytes of S. LEN
6707 zero means use the whole string. MULTIBYTE_P non-zero means S is
6708 multibyte. Display the message multibyte in that case. */
6711 set_message (s
, string
, nbytes
, multibyte_p
)
6716 message_enable_multibyte
6717 = ((s
&& multibyte_p
)
6718 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6720 with_echo_area_buffer (0, -1, set_message_1
,
6721 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6722 message_buf_print
= 0;
6723 help_echo_showing_p
= 0;
6727 /* Helper function for set_message. Arguments have the same meaning
6728 as there, with A1 corresponding to S and A2 corresponding to STRING
6729 This function is called with the echo area buffer being
6733 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6736 EMACS_INT nbytes
, multibyte_p
;
6738 char *s
= (char *) a1
;
6739 Lisp_Object string
= a2
;
6743 /* Change multibyteness of the echo buffer appropriately. */
6744 if (message_enable_multibyte
6745 != !NILP (current_buffer
->enable_multibyte_characters
))
6746 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6748 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6750 /* Insert new message at BEG. */
6751 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6753 if (STRINGP (string
))
6758 nbytes
= XSTRING (string
)->size_byte
;
6759 nchars
= string_byte_to_char (string
, nbytes
);
6761 /* This function takes care of single/multibyte conversion. We
6762 just have to ensure that the echo area buffer has the right
6763 setting of enable_multibyte_characters. */
6764 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6769 nbytes
= strlen (s
);
6771 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6773 /* Convert from multi-byte to single-byte. */
6775 unsigned char work
[1];
6777 /* Convert a multibyte string to single-byte. */
6778 for (i
= 0; i
< nbytes
; i
+= n
)
6780 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6781 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6783 : multibyte_char_to_unibyte (c
, Qnil
));
6784 insert_1_both (work
, 1, 1, 1, 0, 0);
6787 else if (!multibyte_p
6788 && !NILP (current_buffer
->enable_multibyte_characters
))
6790 /* Convert from single-byte to multi-byte. */
6792 unsigned char *msg
= (unsigned char *) s
;
6793 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6795 /* Convert a single-byte string to multibyte. */
6796 for (i
= 0; i
< nbytes
; i
++)
6798 c
= unibyte_char_to_multibyte (msg
[i
]);
6799 n
= CHAR_STRING (c
, str
);
6800 insert_1_both (str
, 1, n
, 1, 0, 0);
6804 insert_1 (s
, nbytes
, 1, 0, 0);
6811 /* Clear messages. CURRENT_P non-zero means clear the current
6812 message. LAST_DISPLAYED_P non-zero means clear the message
6816 clear_message (current_p
, last_displayed_p
)
6817 int current_p
, last_displayed_p
;
6820 echo_area_buffer
[0] = Qnil
;
6822 if (last_displayed_p
)
6823 echo_area_buffer
[1] = Qnil
;
6825 message_buf_print
= 0;
6828 /* Clear garbaged frames.
6830 This function is used where the old redisplay called
6831 redraw_garbaged_frames which in turn called redraw_frame which in
6832 turn called clear_frame. The call to clear_frame was a source of
6833 flickering. I believe a clear_frame is not necessary. It should
6834 suffice in the new redisplay to invalidate all current matrices,
6835 and ensure a complete redisplay of all windows. */
6838 clear_garbaged_frames ()
6842 Lisp_Object tail
, frame
;
6844 FOR_EACH_FRAME (tail
, frame
)
6846 struct frame
*f
= XFRAME (frame
);
6848 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6850 clear_current_matrices (f
);
6856 ++windows_or_buffers_changed
;
6861 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6862 is non-zero update selected_frame. Value is non-zero if the
6863 mini-windows height has been changed. */
6866 echo_area_display (update_frame_p
)
6869 Lisp_Object mini_window
;
6872 int window_height_changed_p
= 0;
6873 struct frame
*sf
= SELECTED_FRAME ();
6875 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6876 w
= XWINDOW (mini_window
);
6877 f
= XFRAME (WINDOW_FRAME (w
));
6879 /* Don't display if frame is invisible or not yet initialized. */
6880 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6883 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6885 #ifdef HAVE_WINDOW_SYSTEM
6886 /* When Emacs starts, selected_frame may be a visible terminal
6887 frame, even if we run under a window system. If we let this
6888 through, a message would be displayed on the terminal. */
6889 if (EQ (selected_frame
, Vterminal_frame
)
6890 && !NILP (Vwindow_system
))
6892 #endif /* HAVE_WINDOW_SYSTEM */
6895 /* Redraw garbaged frames. */
6897 clear_garbaged_frames ();
6899 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6901 echo_area_window
= mini_window
;
6902 window_height_changed_p
= display_echo_area (w
);
6903 w
->must_be_updated_p
= 1;
6905 /* Update the display, unless called from redisplay_internal.
6906 Also don't update the screen during redisplay itself. The
6907 update will happen at the end of redisplay, and an update
6908 here could cause confusion. */
6909 if (update_frame_p
&& !redisplaying_p
)
6913 /* If the display update has been interrupted by pending
6914 input, update mode lines in the frame. Due to the
6915 pending input, it might have been that redisplay hasn't
6916 been called, so that mode lines above the echo area are
6917 garbaged. This looks odd, so we prevent it here. */
6918 if (!display_completed
)
6919 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6921 if (window_height_changed_p
6922 /* Don't do this if Emacs is shutting down. Redisplay
6923 needs to run hooks. */
6924 && !NILP (Vrun_hooks
))
6926 /* Must update other windows. Likewise as in other
6927 cases, don't let this update be interrupted by
6929 int count
= BINDING_STACK_SIZE ();
6930 specbind (Qredisplay_dont_pause
, Qt
);
6931 windows_or_buffers_changed
= 1;
6932 redisplay_internal (0);
6933 unbind_to (count
, Qnil
);
6935 else if (FRAME_WINDOW_P (f
) && n
== 0)
6937 /* Window configuration is the same as before.
6938 Can do with a display update of the echo area,
6939 unless we displayed some mode lines. */
6940 update_single_window (w
, 1);
6941 rif
->flush_display (f
);
6944 update_frame (f
, 1, 1);
6946 /* If cursor is in the echo area, make sure that the next
6947 redisplay displays the minibuffer, so that the cursor will
6948 be replaced with what the minibuffer wants. */
6949 if (cursor_in_echo_area
)
6950 ++windows_or_buffers_changed
;
6953 else if (!EQ (mini_window
, selected_window
))
6954 windows_or_buffers_changed
++;
6956 /* Last displayed message is now the current message. */
6957 echo_area_buffer
[1] = echo_area_buffer
[0];
6959 /* Prevent redisplay optimization in redisplay_internal by resetting
6960 this_line_start_pos. This is done because the mini-buffer now
6961 displays the message instead of its buffer text. */
6962 if (EQ (mini_window
, selected_window
))
6963 CHARPOS (this_line_start_pos
) = 0;
6965 return window_height_changed_p
;
6970 /***********************************************************************
6972 ***********************************************************************/
6975 #ifdef HAVE_WINDOW_SYSTEM
6977 /* A buffer for constructing frame titles in it; allocated from the
6978 heap in init_xdisp and resized as needed in store_frame_title_char. */
6980 static char *frame_title_buf
;
6982 /* The buffer's end, and a current output position in it. */
6984 static char *frame_title_buf_end
;
6985 static char *frame_title_ptr
;
6988 /* Store a single character C for the frame title in frame_title_buf.
6989 Re-allocate frame_title_buf if necessary. */
6992 store_frame_title_char (c
)
6995 /* If output position has reached the end of the allocated buffer,
6996 double the buffer's size. */
6997 if (frame_title_ptr
== frame_title_buf_end
)
6999 int len
= frame_title_ptr
- frame_title_buf
;
7000 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7001 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7002 frame_title_buf_end
= frame_title_buf
+ new_size
;
7003 frame_title_ptr
= frame_title_buf
+ len
;
7006 *frame_title_ptr
++ = c
;
7010 /* Store part of a frame title in frame_title_buf, beginning at
7011 frame_title_ptr. STR is the string to store. Do not copy
7012 characters that yield more columns than PRECISION; PRECISION <= 0
7013 means copy the whole string. Pad with spaces until FIELD_WIDTH
7014 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7015 pad. Called from display_mode_element when it is used to build a
7019 store_frame_title (str
, field_width
, precision
)
7021 int field_width
, precision
;
7024 int dummy
, nbytes
, width
;
7026 /* Copy at most PRECISION chars from STR. */
7027 nbytes
= strlen (str
);
7028 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7030 store_frame_title_char (*str
++);
7032 /* Fill up with spaces until FIELD_WIDTH reached. */
7033 while (field_width
> 0
7036 store_frame_title_char (' ');
7044 /* Set the title of FRAME, if it has changed. The title format is
7045 Vicon_title_format if FRAME is iconified, otherwise it is
7046 frame_title_format. */
7049 x_consider_frame_title (frame
)
7052 struct frame
*f
= XFRAME (frame
);
7054 if (FRAME_WINDOW_P (f
)
7055 || FRAME_MINIBUF_ONLY_P (f
)
7056 || f
->explicit_name
)
7058 /* Do we have more than one visible frame on this X display? */
7061 struct buffer
*obuf
;
7065 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7067 struct frame
*tf
= XFRAME (XCAR (tail
));
7070 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7071 && !FRAME_MINIBUF_ONLY_P (tf
)
7072 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7076 /* Set global variable indicating that multiple frames exist. */
7077 multiple_frames
= CONSP (tail
);
7079 /* Switch to the buffer of selected window of the frame. Set up
7080 frame_title_ptr so that display_mode_element will output into it;
7081 then display the title. */
7082 obuf
= current_buffer
;
7083 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7084 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7085 frame_title_ptr
= frame_title_buf
;
7086 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7087 NULL
, DEFAULT_FACE_ID
);
7088 display_mode_element (&it
, 0, -1, -1, fmt
);
7089 len
= frame_title_ptr
- frame_title_buf
;
7090 frame_title_ptr
= NULL
;
7091 set_buffer_internal (obuf
);
7093 /* Set the title only if it's changed. This avoids consing in
7094 the common case where it hasn't. (If it turns out that we've
7095 already wasted too much time by walking through the list with
7096 display_mode_element, then we might need to optimize at a
7097 higher level than this.) */
7098 if (! STRINGP (f
->name
)
7099 || STRING_BYTES (XSTRING (f
->name
)) != len
7100 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7101 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7105 #else /* not HAVE_WINDOW_SYSTEM */
7107 #define frame_title_ptr ((char *)0)
7108 #define store_frame_title(str, mincol, maxcol) 0
7110 #endif /* not HAVE_WINDOW_SYSTEM */
7115 /***********************************************************************
7117 ***********************************************************************/
7120 /* Prepare for redisplay by updating menu-bar item lists when
7121 appropriate. This can call eval. */
7124 prepare_menu_bars ()
7127 struct gcpro gcpro1
, gcpro2
;
7129 Lisp_Object tooltip_frame
;
7131 #ifdef HAVE_X_WINDOWS
7132 tooltip_frame
= tip_frame
;
7134 tooltip_frame
= Qnil
;
7137 /* Update all frame titles based on their buffer names, etc. We do
7138 this before the menu bars so that the buffer-menu will show the
7139 up-to-date frame titles. */
7140 #ifdef HAVE_WINDOW_SYSTEM
7141 if (windows_or_buffers_changed
|| update_mode_lines
)
7143 Lisp_Object tail
, frame
;
7145 FOR_EACH_FRAME (tail
, frame
)
7148 if (!EQ (frame
, tooltip_frame
)
7149 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7150 x_consider_frame_title (frame
);
7153 #endif /* HAVE_WINDOW_SYSTEM */
7155 /* Update the menu bar item lists, if appropriate. This has to be
7156 done before any actual redisplay or generation of display lines. */
7157 all_windows
= (update_mode_lines
7158 || buffer_shared
> 1
7159 || windows_or_buffers_changed
);
7162 Lisp_Object tail
, frame
;
7163 int count
= BINDING_STACK_SIZE ();
7165 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7167 FOR_EACH_FRAME (tail
, frame
)
7171 /* Ignore tooltip frame. */
7172 if (EQ (frame
, tooltip_frame
))
7175 /* If a window on this frame changed size, report that to
7176 the user and clear the size-change flag. */
7177 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7179 Lisp_Object functions
;
7181 /* Clear flag first in case we get an error below. */
7182 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7183 functions
= Vwindow_size_change_functions
;
7184 GCPRO2 (tail
, functions
);
7186 while (CONSP (functions
))
7188 call1 (XCAR (functions
), frame
);
7189 functions
= XCDR (functions
);
7195 update_menu_bar (f
, 0);
7196 #ifdef HAVE_WINDOW_SYSTEM
7197 update_tool_bar (f
, 0);
7202 unbind_to (count
, Qnil
);
7206 struct frame
*sf
= SELECTED_FRAME ();
7207 update_menu_bar (sf
, 1);
7208 #ifdef HAVE_WINDOW_SYSTEM
7209 update_tool_bar (sf
, 1);
7213 /* Motif needs this. See comment in xmenu.c. Turn it off when
7214 pending_menu_activation is not defined. */
7215 #ifdef USE_X_TOOLKIT
7216 pending_menu_activation
= 0;
7221 /* Update the menu bar item list for frame F. This has to be done
7222 before we start to fill in any display lines, because it can call
7225 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7228 update_menu_bar (f
, save_match_data
)
7230 int save_match_data
;
7233 register struct window
*w
;
7235 /* If called recursively during a menu update, do nothing. This can
7236 happen when, for instance, an activate-menubar-hook causes a
7238 if (inhibit_menubar_update
)
7241 window
= FRAME_SELECTED_WINDOW (f
);
7242 w
= XWINDOW (window
);
7244 if (update_mode_lines
)
7245 w
->update_mode_line
= Qt
;
7247 if (FRAME_WINDOW_P (f
)
7249 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7250 FRAME_EXTERNAL_MENU_BAR (f
)
7252 FRAME_MENU_BAR_LINES (f
) > 0
7254 : FRAME_MENU_BAR_LINES (f
) > 0)
7256 /* If the user has switched buffers or windows, we need to
7257 recompute to reflect the new bindings. But we'll
7258 recompute when update_mode_lines is set too; that means
7259 that people can use force-mode-line-update to request
7260 that the menu bar be recomputed. The adverse effect on
7261 the rest of the redisplay algorithm is about the same as
7262 windows_or_buffers_changed anyway. */
7263 if (windows_or_buffers_changed
7264 || !NILP (w
->update_mode_line
)
7265 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7266 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7267 != !NILP (w
->last_had_star
))
7268 || ((!NILP (Vtransient_mark_mode
)
7269 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7270 != !NILP (w
->region_showing
)))
7272 struct buffer
*prev
= current_buffer
;
7273 int count
= BINDING_STACK_SIZE ();
7275 specbind (Qinhibit_menubar_update
, Qt
);
7277 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7278 if (save_match_data
)
7279 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7280 if (NILP (Voverriding_local_map_menu_flag
))
7282 specbind (Qoverriding_terminal_local_map
, Qnil
);
7283 specbind (Qoverriding_local_map
, Qnil
);
7286 /* Run the Lucid hook. */
7287 safe_run_hooks (Qactivate_menubar_hook
);
7289 /* If it has changed current-menubar from previous value,
7290 really recompute the menu-bar from the value. */
7291 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7292 call0 (Qrecompute_lucid_menubar
);
7294 safe_run_hooks (Qmenu_bar_update_hook
);
7295 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7297 /* Redisplay the menu bar in case we changed it. */
7298 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7299 if (FRAME_WINDOW_P (f
)
7300 #if defined (macintosh)
7301 /* All frames on Mac OS share the same menubar. So only the
7302 selected frame should be allowed to set it. */
7303 && f
== SELECTED_FRAME ()
7306 set_frame_menubar (f
, 0, 0);
7308 /* On a terminal screen, the menu bar is an ordinary screen
7309 line, and this makes it get updated. */
7310 w
->update_mode_line
= Qt
;
7311 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7312 /* In the non-toolkit version, the menu bar is an ordinary screen
7313 line, and this makes it get updated. */
7314 w
->update_mode_line
= Qt
;
7315 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7317 unbind_to (count
, Qnil
);
7318 set_buffer_internal_1 (prev
);
7325 /***********************************************************************
7327 ***********************************************************************/
7329 #ifdef HAVE_WINDOW_SYSTEM
7331 /* Update the tool-bar item list for frame F. This has to be done
7332 before we start to fill in any display lines. Called from
7333 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7334 and restore it here. */
7337 update_tool_bar (f
, save_match_data
)
7339 int save_match_data
;
7341 if (WINDOWP (f
->tool_bar_window
)
7342 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7347 window
= FRAME_SELECTED_WINDOW (f
);
7348 w
= XWINDOW (window
);
7350 /* If the user has switched buffers or windows, we need to
7351 recompute to reflect the new bindings. But we'll
7352 recompute when update_mode_lines is set too; that means
7353 that people can use force-mode-line-update to request
7354 that the menu bar be recomputed. The adverse effect on
7355 the rest of the redisplay algorithm is about the same as
7356 windows_or_buffers_changed anyway. */
7357 if (windows_or_buffers_changed
7358 || !NILP (w
->update_mode_line
)
7359 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7360 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7361 != !NILP (w
->last_had_star
))
7362 || ((!NILP (Vtransient_mark_mode
)
7363 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7364 != !NILP (w
->region_showing
)))
7366 struct buffer
*prev
= current_buffer
;
7367 int count
= BINDING_STACK_SIZE ();
7369 /* Set current_buffer to the buffer of the selected
7370 window of the frame, so that we get the right local
7372 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7374 /* Save match data, if we must. */
7375 if (save_match_data
)
7376 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7378 /* Make sure that we don't accidentally use bogus keymaps. */
7379 if (NILP (Voverriding_local_map_menu_flag
))
7381 specbind (Qoverriding_terminal_local_map
, Qnil
);
7382 specbind (Qoverriding_local_map
, Qnil
);
7385 /* Build desired tool-bar items from keymaps. */
7387 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7389 /* Redisplay the tool-bar in case we changed it. */
7390 w
->update_mode_line
= Qt
;
7392 unbind_to (count
, Qnil
);
7393 set_buffer_internal_1 (prev
);
7399 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7400 F's desired tool-bar contents. F->tool_bar_items must have
7401 been set up previously by calling prepare_menu_bars. */
7404 build_desired_tool_bar_string (f
)
7407 int i
, size
, size_needed
;
7408 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7409 Lisp_Object image
, plist
, props
;
7411 image
= plist
= props
= Qnil
;
7412 GCPRO3 (image
, plist
, props
);
7414 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7415 Otherwise, make a new string. */
7417 /* The size of the string we might be able to reuse. */
7418 size
= (STRINGP (f
->desired_tool_bar_string
)
7419 ? XSTRING (f
->desired_tool_bar_string
)->size
7422 /* We need one space in the string for each image. */
7423 size_needed
= f
->n_tool_bar_items
;
7425 /* Reuse f->desired_tool_bar_string, if possible. */
7426 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7427 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7431 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7432 Fremove_text_properties (make_number (0), make_number (size
),
7433 props
, f
->desired_tool_bar_string
);
7436 /* Put a `display' property on the string for the images to display,
7437 put a `menu_item' property on tool-bar items with a value that
7438 is the index of the item in F's tool-bar item vector. */
7439 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7441 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7443 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7444 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7445 int hmargin
, vmargin
, relief
, idx
, end
;
7446 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7447 extern Lisp_Object Qlaplace
;
7449 /* If image is a vector, choose the image according to the
7451 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7452 if (VECTORP (image
))
7456 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7457 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7460 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7461 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7463 xassert (ASIZE (image
) >= idx
);
7464 image
= AREF (image
, idx
);
7469 /* Ignore invalid image specifications. */
7470 if (!valid_image_p (image
))
7473 /* Display the tool-bar button pressed, or depressed. */
7474 plist
= Fcopy_sequence (XCDR (image
));
7476 /* Compute margin and relief to draw. */
7477 relief
= (tool_bar_button_relief
> 0
7478 ? tool_bar_button_relief
7479 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7480 hmargin
= vmargin
= relief
;
7482 if (INTEGERP (Vtool_bar_button_margin
)
7483 && XINT (Vtool_bar_button_margin
) > 0)
7485 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7486 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7488 else if (CONSP (Vtool_bar_button_margin
))
7490 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7491 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7492 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7494 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7495 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7496 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7499 if (auto_raise_tool_bar_buttons_p
)
7501 /* Add a `:relief' property to the image spec if the item is
7505 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7512 /* If image is selected, display it pressed, i.e. with a
7513 negative relief. If it's not selected, display it with a
7515 plist
= Fplist_put (plist
, QCrelief
,
7517 ? make_number (-relief
)
7518 : make_number (relief
)));
7523 /* Put a margin around the image. */
7524 if (hmargin
|| vmargin
)
7526 if (hmargin
== vmargin
)
7527 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7529 plist
= Fplist_put (plist
, QCmargin
,
7530 Fcons (make_number (hmargin
),
7531 make_number (vmargin
)));
7534 /* If button is not enabled, and we don't have special images
7535 for the disabled state, make the image appear disabled by
7536 applying an appropriate algorithm to it. */
7537 if (!enabled_p
&& idx
< 0)
7538 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7540 /* Put a `display' text property on the string for the image to
7541 display. Put a `menu-item' property on the string that gives
7542 the start of this item's properties in the tool-bar items
7544 image
= Fcons (Qimage
, plist
);
7545 props
= list4 (Qdisplay
, image
,
7546 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7548 /* Let the last image hide all remaining spaces in the tool bar
7549 string. The string can be longer than needed when we reuse a
7551 if (i
+ 1 == f
->n_tool_bar_items
)
7552 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7555 Fadd_text_properties (make_number (i
), make_number (end
),
7556 props
, f
->desired_tool_bar_string
);
7564 /* Display one line of the tool-bar of frame IT->f. */
7567 display_tool_bar_line (it
)
7570 struct glyph_row
*row
= it
->glyph_row
;
7571 int max_x
= it
->last_visible_x
;
7574 prepare_desired_row (row
);
7575 row
->y
= it
->current_y
;
7577 /* Note that this isn't made use of if the face hasn't a box,
7578 so there's no need to check the face here. */
7579 it
->start_of_box_run_p
= 1;
7581 while (it
->current_x
< max_x
)
7583 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7585 /* Get the next display element. */
7586 if (!get_next_display_element (it
))
7589 /* Produce glyphs. */
7590 x_before
= it
->current_x
;
7591 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7592 PRODUCE_GLYPHS (it
);
7594 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7599 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7601 if (x
+ glyph
->pixel_width
> max_x
)
7603 /* Glyph doesn't fit on line. */
7604 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7610 x
+= glyph
->pixel_width
;
7614 /* Stop at line ends. */
7615 if (ITERATOR_AT_END_OF_LINE_P (it
))
7618 set_iterator_to_next (it
, 1);
7623 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7624 extend_face_to_end_of_line (it
);
7625 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7626 last
->right_box_line_p
= 1;
7627 if (last
== row
->glyphs
[TEXT_AREA
])
7628 last
->left_box_line_p
= 1;
7629 compute_line_metrics (it
);
7631 /* If line is empty, make it occupy the rest of the tool-bar. */
7632 if (!row
->displays_text_p
)
7634 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7635 row
->ascent
= row
->phys_ascent
= 0;
7638 row
->full_width_p
= 1;
7639 row
->continued_p
= 0;
7640 row
->truncated_on_left_p
= 0;
7641 row
->truncated_on_right_p
= 0;
7643 it
->current_x
= it
->hpos
= 0;
7644 it
->current_y
+= row
->height
;
7650 /* Value is the number of screen lines needed to make all tool-bar
7651 items of frame F visible. */
7654 tool_bar_lines_needed (f
)
7657 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7660 /* Initialize an iterator for iteration over
7661 F->desired_tool_bar_string in the tool-bar window of frame F. */
7662 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7663 it
.first_visible_x
= 0;
7664 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7665 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7667 while (!ITERATOR_AT_END_P (&it
))
7669 it
.glyph_row
= w
->desired_matrix
->rows
;
7670 clear_glyph_row (it
.glyph_row
);
7671 display_tool_bar_line (&it
);
7674 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7678 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7680 "Return the number of lines occupied by the tool bar of FRAME.")
7689 frame
= selected_frame
;
7691 CHECK_FRAME (frame
, 0);
7694 if (WINDOWP (f
->tool_bar_window
)
7695 || (w
= XWINDOW (f
->tool_bar_window
),
7696 XFASTINT (w
->height
) > 0))
7698 update_tool_bar (f
, 1);
7699 if (f
->n_tool_bar_items
)
7701 build_desired_tool_bar_string (f
);
7702 nlines
= tool_bar_lines_needed (f
);
7706 return make_number (nlines
);
7710 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7711 height should be changed. */
7714 redisplay_tool_bar (f
)
7719 struct glyph_row
*row
;
7720 int change_height_p
= 0;
7722 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7723 do anything. This means you must start with tool-bar-lines
7724 non-zero to get the auto-sizing effect. Or in other words, you
7725 can turn off tool-bars by specifying tool-bar-lines zero. */
7726 if (!WINDOWP (f
->tool_bar_window
)
7727 || (w
= XWINDOW (f
->tool_bar_window
),
7728 XFASTINT (w
->height
) == 0))
7731 /* Set up an iterator for the tool-bar window. */
7732 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7733 it
.first_visible_x
= 0;
7734 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7737 /* Build a string that represents the contents of the tool-bar. */
7738 build_desired_tool_bar_string (f
);
7739 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7741 /* Display as many lines as needed to display all tool-bar items. */
7742 while (it
.current_y
< it
.last_visible_y
)
7743 display_tool_bar_line (&it
);
7745 /* It doesn't make much sense to try scrolling in the tool-bar
7746 window, so don't do it. */
7747 w
->desired_matrix
->no_scrolling_p
= 1;
7748 w
->must_be_updated_p
= 1;
7750 if (auto_resize_tool_bars_p
)
7754 /* If we couldn't display everything, change the tool-bar's
7756 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7757 change_height_p
= 1;
7759 /* If there are blank lines at the end, except for a partially
7760 visible blank line at the end that is smaller than
7761 CANON_Y_UNIT, change the tool-bar's height. */
7762 row
= it
.glyph_row
- 1;
7763 if (!row
->displays_text_p
7764 && row
->height
>= CANON_Y_UNIT (f
))
7765 change_height_p
= 1;
7767 /* If row displays tool-bar items, but is partially visible,
7768 change the tool-bar's height. */
7769 if (row
->displays_text_p
7770 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7771 change_height_p
= 1;
7773 /* Resize windows as needed by changing the `tool-bar-lines'
7776 && (nlines
= tool_bar_lines_needed (f
),
7777 nlines
!= XFASTINT (w
->height
)))
7779 extern Lisp_Object Qtool_bar_lines
;
7781 int old_height
= XFASTINT (w
->height
);
7783 XSETFRAME (frame
, f
);
7784 clear_glyph_matrix (w
->desired_matrix
);
7785 Fmodify_frame_parameters (frame
,
7786 Fcons (Fcons (Qtool_bar_lines
,
7787 make_number (nlines
)),
7789 if (XFASTINT (w
->height
) != old_height
)
7790 fonts_changed_p
= 1;
7794 return change_height_p
;
7798 /* Get information about the tool-bar item which is displayed in GLYPH
7799 on frame F. Return in *PROP_IDX the index where tool-bar item
7800 properties start in F->tool_bar_items. Value is zero if
7801 GLYPH doesn't display a tool-bar item. */
7804 tool_bar_item_info (f
, glyph
, prop_idx
)
7806 struct glyph
*glyph
;
7812 /* Get the text property `menu-item' at pos. The value of that
7813 property is the start index of this item's properties in
7814 F->tool_bar_items. */
7815 prop
= Fget_text_property (make_number (glyph
->charpos
),
7816 Qmenu_item
, f
->current_tool_bar_string
);
7817 if (INTEGERP (prop
))
7819 *prop_idx
= XINT (prop
);
7828 #endif /* HAVE_WINDOW_SYSTEM */
7832 /************************************************************************
7833 Horizontal scrolling
7834 ************************************************************************/
7836 static int hscroll_window_tree
P_ ((Lisp_Object
));
7837 static int hscroll_windows
P_ ((Lisp_Object
));
7839 /* For all leaf windows in the window tree rooted at WINDOW, set their
7840 hscroll value so that PT is (i) visible in the window, and (ii) so
7841 that it is not within a certain margin at the window's left and
7842 right border. Value is non-zero if any window's hscroll has been
7846 hscroll_window_tree (window
)
7849 int hscrolled_p
= 0;
7851 while (WINDOWP (window
))
7853 struct window
*w
= XWINDOW (window
);
7855 if (WINDOWP (w
->hchild
))
7856 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7857 else if (WINDOWP (w
->vchild
))
7858 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7859 else if (w
->cursor
.vpos
>= 0)
7861 int hscroll_margin
, text_area_x
, text_area_y
;
7862 int text_area_width
, text_area_height
;
7863 struct glyph_row
*current_cursor_row
7864 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7865 struct glyph_row
*desired_cursor_row
7866 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7867 struct glyph_row
*cursor_row
7868 = (desired_cursor_row
->enabled_p
7869 ? desired_cursor_row
7870 : current_cursor_row
);
7872 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7873 &text_area_width
, &text_area_height
);
7875 /* Scroll when cursor is inside this scroll margin. */
7876 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7878 if ((XFASTINT (w
->hscroll
)
7879 && w
->cursor
.x
< hscroll_margin
)
7880 || (cursor_row
->enabled_p
7881 && cursor_row
->truncated_on_right_p
7882 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7886 struct buffer
*saved_current_buffer
;
7889 /* Find point in a display of infinite width. */
7890 saved_current_buffer
= current_buffer
;
7891 current_buffer
= XBUFFER (w
->buffer
);
7893 if (w
== XWINDOW (selected_window
))
7894 pt
= BUF_PT (current_buffer
);
7897 pt
= marker_position (w
->pointm
);
7898 pt
= max (BEGV
, pt
);
7902 /* Move iterator to pt starting at cursor_row->start in
7903 a line with infinite width. */
7904 init_to_row_start (&it
, w
, cursor_row
);
7905 it
.last_visible_x
= INFINITY
;
7906 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7907 current_buffer
= saved_current_buffer
;
7909 /* Center cursor in window. */
7910 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7911 / CANON_X_UNIT (it
.f
));
7912 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
7914 /* Don't call Fset_window_hscroll if value hasn't
7915 changed because it will prevent redisplay
7917 if (XFASTINT (w
->hscroll
) != hscroll
)
7919 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
7920 w
->hscroll
= make_number (hscroll
);
7929 /* Value is non-zero if hscroll of any leaf window has been changed. */
7934 /* Set hscroll so that cursor is visible and not inside horizontal
7935 scroll margins for all windows in the tree rooted at WINDOW. See
7936 also hscroll_window_tree above. Value is non-zero if any window's
7937 hscroll has been changed. If it has, desired matrices on the frame
7938 of WINDOW are cleared. */
7941 hscroll_windows (window
)
7946 if (automatic_hscrolling_p
)
7948 hscrolled_p
= hscroll_window_tree (window
);
7950 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7959 /************************************************************************
7961 ************************************************************************/
7963 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7964 to a non-zero value. This is sometimes handy to have in a debugger
7969 /* First and last unchanged row for try_window_id. */
7971 int debug_first_unchanged_at_end_vpos
;
7972 int debug_last_unchanged_at_beg_vpos
;
7974 /* Delta vpos and y. */
7976 int debug_dvpos
, debug_dy
;
7978 /* Delta in characters and bytes for try_window_id. */
7980 int debug_delta
, debug_delta_bytes
;
7982 /* Values of window_end_pos and window_end_vpos at the end of
7985 int debug_end_pos
, debug_end_vpos
;
7987 /* Append a string to W->desired_matrix->method. FMT is a printf
7988 format string. A1...A9 are a supplement for a variable-length
7989 argument list. If trace_redisplay_p is non-zero also printf the
7990 resulting string to stderr. */
7993 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7996 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7999 char *method
= w
->desired_matrix
->method
;
8000 int len
= strlen (method
);
8001 int size
= sizeof w
->desired_matrix
->method
;
8002 int remaining
= size
- len
- 1;
8004 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8005 if (len
&& remaining
)
8011 strncpy (method
+ len
, buffer
, remaining
);
8013 if (trace_redisplay_p
)
8014 fprintf (stderr
, "%p (%s): %s\n",
8016 ((BUFFERP (w
->buffer
)
8017 && STRINGP (XBUFFER (w
->buffer
)->name
))
8018 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8023 #endif /* GLYPH_DEBUG */
8026 /* This counter is used to clear the face cache every once in a while
8027 in redisplay_internal. It is incremented for each redisplay.
8028 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8031 #define CLEAR_FACE_CACHE_COUNT 10000
8032 static int clear_face_cache_count
;
8034 /* Record the previous terminal frame we displayed. */
8036 static struct frame
*previous_terminal_frame
;
8038 /* Non-zero while redisplay_internal is in progress. */
8043 /* Value is non-zero if all changes in window W, which displays
8044 current_buffer, are in the text between START and END. START is a
8045 buffer position, END is given as a distance from Z. Used in
8046 redisplay_internal for display optimization. */
8049 text_outside_line_unchanged_p (w
, start
, end
)
8053 int unchanged_p
= 1;
8055 /* If text or overlays have changed, see where. */
8056 if (XFASTINT (w
->last_modified
) < MODIFF
8057 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8059 /* Gap in the line? */
8060 if (GPT
< start
|| Z
- GPT
< end
)
8063 /* Changes start in front of the line, or end after it? */
8065 && (BEG_UNCHANGED
< start
- 1
8066 || END_UNCHANGED
< end
))
8069 /* If selective display, can't optimize if changes start at the
8070 beginning of the line. */
8072 && INTEGERP (current_buffer
->selective_display
)
8073 && XINT (current_buffer
->selective_display
) > 0
8074 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8082 /* Do a frame update, taking possible shortcuts into account. This is
8083 the main external entry point for redisplay.
8085 If the last redisplay displayed an echo area message and that message
8086 is no longer requested, we clear the echo area or bring back the
8087 mini-buffer if that is in use. */
8092 redisplay_internal (0);
8095 /* Return 1 if point moved out of or into a composition. Otherwise
8096 return 0. PREV_BUF and PREV_PT are the last point buffer and
8097 position. BUF and PT are the current point buffer and position. */
8100 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8101 struct buffer
*prev_buf
, *buf
;
8108 XSETBUFFER (buffer
, buf
);
8109 /* Check a composition at the last point if point moved within the
8111 if (prev_buf
== buf
)
8114 /* Point didn't move. */
8117 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8118 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8119 && COMPOSITION_VALID_P (start
, end
, prop
)
8120 && start
< prev_pt
&& end
> prev_pt
)
8121 /* The last point was within the composition. Return 1 iff
8122 point moved out of the composition. */
8123 return (pt
<= start
|| pt
>= end
);
8126 /* Check a composition at the current point. */
8127 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8128 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8129 && COMPOSITION_VALID_P (start
, end
, prop
)
8130 && start
< pt
&& end
> pt
);
8133 /* Reconsider the setting of B->clip_changed which is displayed
8137 reconsider_clip_changes (w
, b
)
8141 if (b
->prevent_redisplay_optimizations_p
)
8142 b
->clip_changed
= 1;
8143 else if (b
->clip_changed
8144 && !NILP (w
->window_end_valid
)
8145 && w
->current_matrix
->buffer
== b
8146 && w
->current_matrix
->zv
== BUF_ZV (b
)
8147 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8148 b
->clip_changed
= 0;
8150 /* If display wasn't paused, and W is not a tool bar window, see if
8151 point has been moved into or out of a composition. In that case,
8152 we set b->clip_changed to 1 to force updating the screen. If
8153 b->clip_changed has already been set to 1, we can skip this
8155 if (!b
->clip_changed
8156 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8160 if (w
== XWINDOW (selected_window
))
8161 pt
= BUF_PT (current_buffer
);
8163 pt
= marker_position (w
->pointm
);
8165 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8166 || pt
!= XINT (w
->last_point
))
8167 && check_point_in_composition (w
->current_matrix
->buffer
,
8168 XINT (w
->last_point
),
8169 XBUFFER (w
->buffer
), pt
))
8170 b
->clip_changed
= 1;
8175 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8176 response to any user action; therefore, we should preserve the echo
8177 area. (Actually, our caller does that job.) Perhaps in the future
8178 avoid recentering windows if it is not necessary; currently that
8179 causes some problems. */
8182 redisplay_internal (preserve_echo_area
)
8183 int preserve_echo_area
;
8185 struct window
*w
= XWINDOW (selected_window
);
8186 struct frame
*f
= XFRAME (w
->frame
);
8188 int must_finish
= 0;
8189 struct text_pos tlbufpos
, tlendpos
;
8190 int number_of_visible_frames
;
8192 struct frame
*sf
= SELECTED_FRAME ();
8194 /* Non-zero means redisplay has to consider all windows on all
8195 frames. Zero means, only selected_window is considered. */
8196 int consider_all_windows_p
;
8198 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8200 /* No redisplay if running in batch mode or frame is not yet fully
8201 initialized, or redisplay is explicitly turned off by setting
8202 Vinhibit_redisplay. */
8204 || !NILP (Vinhibit_redisplay
)
8205 || !f
->glyphs_initialized_p
)
8208 /* The flag redisplay_performed_directly_p is set by
8209 direct_output_for_insert when it already did the whole screen
8210 update necessary. */
8211 if (redisplay_performed_directly_p
)
8213 redisplay_performed_directly_p
= 0;
8214 if (!hscroll_windows (selected_window
))
8218 #ifdef USE_X_TOOLKIT
8219 if (popup_activated ())
8223 /* I don't think this happens but let's be paranoid. */
8227 /* Record a function that resets redisplaying_p to its old value
8228 when we leave this function. */
8229 count
= BINDING_STACK_SIZE ();
8230 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8235 reconsider_clip_changes (w
, current_buffer
);
8237 /* If new fonts have been loaded that make a glyph matrix adjustment
8238 necessary, do it. */
8239 if (fonts_changed_p
)
8241 adjust_glyphs (NULL
);
8242 ++windows_or_buffers_changed
;
8243 fonts_changed_p
= 0;
8246 /* If face_change_count is non-zero, init_iterator will free all
8247 realized faces, which includes the faces referenced from current
8248 matrices. So, we can't reuse current matrices in this case. */
8249 if (face_change_count
)
8250 ++windows_or_buffers_changed
;
8252 if (! FRAME_WINDOW_P (sf
)
8253 && previous_terminal_frame
!= sf
)
8255 /* Since frames on an ASCII terminal share the same display
8256 area, displaying a different frame means redisplay the whole
8258 windows_or_buffers_changed
++;
8259 SET_FRAME_GARBAGED (sf
);
8260 XSETFRAME (Vterminal_frame
, sf
);
8262 previous_terminal_frame
= sf
;
8264 /* Set the visible flags for all frames. Do this before checking
8265 for resized or garbaged frames; they want to know if their frames
8266 are visible. See the comment in frame.h for
8267 FRAME_SAMPLE_VISIBILITY. */
8269 Lisp_Object tail
, frame
;
8271 number_of_visible_frames
= 0;
8273 FOR_EACH_FRAME (tail
, frame
)
8275 struct frame
*f
= XFRAME (frame
);
8277 FRAME_SAMPLE_VISIBILITY (f
);
8278 if (FRAME_VISIBLE_P (f
))
8279 ++number_of_visible_frames
;
8280 clear_desired_matrices (f
);
8284 /* Notice any pending interrupt request to change frame size. */
8285 do_pending_window_change (1);
8287 /* Clear frames marked as garbaged. */
8289 clear_garbaged_frames ();
8291 /* Build menubar and tool-bar items. */
8292 prepare_menu_bars ();
8294 if (windows_or_buffers_changed
)
8295 update_mode_lines
++;
8297 /* Detect case that we need to write or remove a star in the mode line. */
8298 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8300 w
->update_mode_line
= Qt
;
8301 if (buffer_shared
> 1)
8302 update_mode_lines
++;
8305 /* If %c is in the mode line, update it if needed. */
8306 if (!NILP (w
->column_number_displayed
)
8307 /* This alternative quickly identifies a common case
8308 where no change is needed. */
8309 && !(PT
== XFASTINT (w
->last_point
)
8310 && XFASTINT (w
->last_modified
) >= MODIFF
8311 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8312 && XFASTINT (w
->column_number_displayed
) != current_column ())
8313 w
->update_mode_line
= Qt
;
8315 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8317 /* The variable buffer_shared is set in redisplay_window and
8318 indicates that we redisplay a buffer in different windows. See
8320 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8322 /* If specs for an arrow have changed, do thorough redisplay
8323 to ensure we remove any arrow that should no longer exist. */
8324 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8325 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8326 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8328 /* Normally the message* functions will have already displayed and
8329 updated the echo area, but the frame may have been trashed, or
8330 the update may have been preempted, so display the echo area
8331 again here. Checking both message buffers captures the case that
8332 the echo area should be cleared. */
8333 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
8335 int window_height_changed_p
= echo_area_display (0);
8338 if (fonts_changed_p
)
8340 else if (window_height_changed_p
)
8342 consider_all_windows_p
= 1;
8343 ++update_mode_lines
;
8344 ++windows_or_buffers_changed
;
8346 /* If window configuration was changed, frames may have been
8347 marked garbaged. Clear them or we will experience
8348 surprises wrt scrolling. */
8350 clear_garbaged_frames ();
8353 else if (EQ (selected_window
, minibuf_window
)
8354 && (current_buffer
->clip_changed
8355 || XFASTINT (w
->last_modified
) < MODIFF
8356 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8357 && resize_mini_window (w
, 0))
8359 /* Resized active mini-window to fit the size of what it is
8360 showing if its contents might have changed. */
8362 consider_all_windows_p
= 1;
8363 ++windows_or_buffers_changed
;
8364 ++update_mode_lines
;
8366 /* If window configuration was changed, frames may have been
8367 marked garbaged. Clear them or we will experience
8368 surprises wrt scrolling. */
8370 clear_garbaged_frames ();
8374 /* If showing the region, and mark has changed, we must redisplay
8375 the whole window. The assignment to this_line_start_pos prevents
8376 the optimization directly below this if-statement. */
8377 if (((!NILP (Vtransient_mark_mode
)
8378 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8379 != !NILP (w
->region_showing
))
8380 || (!NILP (w
->region_showing
)
8381 && !EQ (w
->region_showing
,
8382 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8383 CHARPOS (this_line_start_pos
) = 0;
8385 /* Optimize the case that only the line containing the cursor in the
8386 selected window has changed. Variables starting with this_ are
8387 set in display_line and record information about the line
8388 containing the cursor. */
8389 tlbufpos
= this_line_start_pos
;
8390 tlendpos
= this_line_end_pos
;
8391 if (!consider_all_windows_p
8392 && CHARPOS (tlbufpos
) > 0
8393 && NILP (w
->update_mode_line
)
8394 && !current_buffer
->clip_changed
8395 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8396 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8397 /* Make sure recorded data applies to current buffer, etc. */
8398 && this_line_buffer
== current_buffer
8399 && current_buffer
== XBUFFER (w
->buffer
)
8400 && NILP (w
->force_start
)
8401 /* Point must be on the line that we have info recorded about. */
8402 && PT
>= CHARPOS (tlbufpos
)
8403 && PT
<= Z
- CHARPOS (tlendpos
)
8404 /* All text outside that line, including its final newline,
8405 must be unchanged */
8406 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8407 CHARPOS (tlendpos
)))
8409 if (CHARPOS (tlbufpos
) > BEGV
8410 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8411 && (CHARPOS (tlbufpos
) == ZV
8412 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8413 /* Former continuation line has disappeared by becoming empty */
8415 else if (XFASTINT (w
->last_modified
) < MODIFF
8416 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8417 || MINI_WINDOW_P (w
))
8419 /* We have to handle the case of continuation around a
8420 wide-column character (See the comment in indent.c around
8423 For instance, in the following case:
8425 -------- Insert --------
8426 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8427 J_I_ ==> J_I_ `^^' are cursors.
8431 As we have to redraw the line above, we should goto cancel. */
8434 int line_height_before
= this_line_pixel_height
;
8436 /* Note that start_display will handle the case that the
8437 line starting at tlbufpos is a continuation lines. */
8438 start_display (&it
, w
, tlbufpos
);
8440 /* Implementation note: It this still necessary? */
8441 if (it
.current_x
!= this_line_start_x
)
8444 TRACE ((stderr
, "trying display optimization 1\n"));
8445 w
->cursor
.vpos
= -1;
8446 overlay_arrow_seen
= 0;
8447 it
.vpos
= this_line_vpos
;
8448 it
.current_y
= this_line_y
;
8449 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8452 /* If line contains point, is not continued,
8453 and ends at same distance from eob as before, we win */
8454 if (w
->cursor
.vpos
>= 0
8455 /* Line is not continued, otherwise this_line_start_pos
8456 would have been set to 0 in display_line. */
8457 && CHARPOS (this_line_start_pos
)
8458 /* Line ends as before. */
8459 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8460 /* Line has same height as before. Otherwise other lines
8461 would have to be shifted up or down. */
8462 && this_line_pixel_height
== line_height_before
)
8464 /* If this is not the window's last line, we must adjust
8465 the charstarts of the lines below. */
8466 if (it
.current_y
< it
.last_visible_y
)
8468 struct glyph_row
*row
8469 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8470 int delta
, delta_bytes
;
8472 if (Z
- CHARPOS (tlendpos
) == ZV
)
8474 /* This line ends at end of (accessible part of)
8475 buffer. There is no newline to count. */
8477 - CHARPOS (tlendpos
)
8478 - MATRIX_ROW_START_CHARPOS (row
));
8479 delta_bytes
= (Z_BYTE
8480 - BYTEPOS (tlendpos
)
8481 - MATRIX_ROW_START_BYTEPOS (row
));
8485 /* This line ends in a newline. Must take
8486 account of the newline and the rest of the
8487 text that follows. */
8489 - CHARPOS (tlendpos
)
8490 - MATRIX_ROW_START_CHARPOS (row
));
8491 delta_bytes
= (Z_BYTE
8492 - BYTEPOS (tlendpos
)
8493 - MATRIX_ROW_START_BYTEPOS (row
));
8496 increment_matrix_positions (w
->current_matrix
,
8498 w
->current_matrix
->nrows
,
8499 delta
, delta_bytes
);
8502 /* If this row displays text now but previously didn't,
8503 or vice versa, w->window_end_vpos may have to be
8505 if ((it
.glyph_row
- 1)->displays_text_p
)
8507 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8508 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8510 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8511 && this_line_vpos
> 0)
8512 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8513 w
->window_end_valid
= Qnil
;
8515 /* Update hint: No need to try to scroll in update_window. */
8516 w
->desired_matrix
->no_scrolling_p
= 1;
8519 *w
->desired_matrix
->method
= 0;
8520 debug_method_add (w
, "optimization 1");
8527 else if (/* Cursor position hasn't changed. */
8528 PT
== XFASTINT (w
->last_point
)
8529 /* Make sure the cursor was last displayed
8530 in this window. Otherwise we have to reposition it. */
8531 && 0 <= w
->cursor
.vpos
8532 && XINT (w
->height
) > w
->cursor
.vpos
)
8536 do_pending_window_change (1);
8538 /* We used to always goto end_of_redisplay here, but this
8539 isn't enough if we have a blinking cursor. */
8540 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8541 goto end_of_redisplay
;
8545 /* If highlighting the region, or if the cursor is in the echo area,
8546 then we can't just move the cursor. */
8547 else if (! (!NILP (Vtransient_mark_mode
)
8548 && !NILP (current_buffer
->mark_active
))
8549 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8550 || highlight_nonselected_windows
)
8551 && NILP (w
->region_showing
)
8552 && NILP (Vshow_trailing_whitespace
)
8553 && !cursor_in_echo_area
)
8556 struct glyph_row
*row
;
8558 /* Skip from tlbufpos to PT and see where it is. Note that
8559 PT may be in invisible text. If so, we will end at the
8560 next visible position. */
8561 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8562 NULL
, DEFAULT_FACE_ID
);
8563 it
.current_x
= this_line_start_x
;
8564 it
.current_y
= this_line_y
;
8565 it
.vpos
= this_line_vpos
;
8567 /* The call to move_it_to stops in front of PT, but
8568 moves over before-strings. */
8569 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8571 if (it
.vpos
== this_line_vpos
8572 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8575 xassert (this_line_vpos
== it
.vpos
);
8576 xassert (this_line_y
== it
.current_y
);
8577 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8579 *w
->desired_matrix
->method
= 0;
8580 debug_method_add (w
, "optimization 3");
8589 /* Text changed drastically or point moved off of line. */
8590 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8593 CHARPOS (this_line_start_pos
) = 0;
8594 consider_all_windows_p
|= buffer_shared
> 1;
8595 ++clear_face_cache_count
;
8598 /* Build desired matrices, and update the display. If
8599 consider_all_windows_p is non-zero, do it for all windows on all
8600 frames. Otherwise do it for selected_window, only. */
8602 if (consider_all_windows_p
)
8604 Lisp_Object tail
, frame
;
8605 int i
, n
= 0, size
= 50;
8606 struct frame
**updated
8607 = (struct frame
**) alloca (size
* sizeof *updated
);
8609 /* Clear the face cache eventually. */
8610 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8612 clear_face_cache (0);
8613 clear_face_cache_count
= 0;
8616 /* Recompute # windows showing selected buffer. This will be
8617 incremented each time such a window is displayed. */
8620 FOR_EACH_FRAME (tail
, frame
)
8622 struct frame
*f
= XFRAME (frame
);
8624 if (FRAME_WINDOW_P (f
) || f
== sf
)
8626 /* Mark all the scroll bars to be removed; we'll redeem
8627 the ones we want when we redisplay their windows. */
8628 if (condemn_scroll_bars_hook
)
8629 condemn_scroll_bars_hook (f
);
8631 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8632 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8634 /* Any scroll bars which redisplay_windows should have
8635 nuked should now go away. */
8636 if (judge_scroll_bars_hook
)
8637 judge_scroll_bars_hook (f
);
8639 /* If fonts changed, display again. */
8640 if (fonts_changed_p
)
8643 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8645 /* See if we have to hscroll. */
8646 if (hscroll_windows (f
->root_window
))
8649 /* Prevent various kinds of signals during display
8650 update. stdio is not robust about handling
8651 signals, which can cause an apparent I/O
8653 if (interrupt_input
)
8657 /* Update the display. */
8658 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8659 pause
|= update_frame (f
, 0, 0);
8665 int nbytes
= size
* sizeof *updated
;
8666 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8667 bcopy (updated
, p
, nbytes
);
8676 /* Do the mark_window_display_accurate after all windows have
8677 been redisplayed because this call resets flags in buffers
8678 which are needed for proper redisplay. */
8679 for (i
= 0; i
< n
; ++i
)
8681 struct frame
*f
= updated
[i
];
8682 mark_window_display_accurate (f
->root_window
, 1);
8683 if (frame_up_to_date_hook
)
8684 frame_up_to_date_hook (f
);
8687 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8689 Lisp_Object mini_window
;
8690 struct frame
*mini_frame
;
8692 redisplay_window (selected_window
, 1);
8694 /* Compare desired and current matrices, perform output. */
8697 /* If fonts changed, display again. */
8698 if (fonts_changed_p
)
8701 /* Prevent various kinds of signals during display update.
8702 stdio is not robust about handling signals,
8703 which can cause an apparent I/O error. */
8704 if (interrupt_input
)
8708 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8710 if (hscroll_windows (selected_window
))
8713 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8714 pause
= update_frame (sf
, 0, 0);
8717 /* We may have called echo_area_display at the top of this
8718 function. If the echo area is on another frame, that may
8719 have put text on a frame other than the selected one, so the
8720 above call to update_frame would not have caught it. Catch
8722 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8723 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8725 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8727 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8728 pause
|= update_frame (mini_frame
, 0, 0);
8729 if (!pause
&& hscroll_windows (mini_window
))
8734 /* If display was paused because of pending input, make sure we do a
8735 thorough update the next time. */
8738 /* Prevent the optimization at the beginning of
8739 redisplay_internal that tries a single-line update of the
8740 line containing the cursor in the selected window. */
8741 CHARPOS (this_line_start_pos
) = 0;
8743 /* Let the overlay arrow be updated the next time. */
8744 if (!NILP (last_arrow_position
))
8746 last_arrow_position
= Qt
;
8747 last_arrow_string
= Qt
;
8750 /* If we pause after scrolling, some rows in the current
8751 matrices of some windows are not valid. */
8752 if (!WINDOW_FULL_WIDTH_P (w
)
8753 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8754 update_mode_lines
= 1;
8758 if (!consider_all_windows_p
)
8760 /* This has already been done above if
8761 consider_all_windows_p is set. */
8762 mark_window_display_accurate_1 (w
, 1);
8764 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8765 last_arrow_string
= Voverlay_arrow_string
;
8767 if (frame_up_to_date_hook
!= 0)
8768 frame_up_to_date_hook (sf
);
8771 update_mode_lines
= 0;
8772 windows_or_buffers_changed
= 0;
8775 /* Start SIGIO interrupts coming again. Having them off during the
8776 code above makes it less likely one will discard output, but not
8777 impossible, since there might be stuff in the system buffer here.
8778 But it is much hairier to try to do anything about that. */
8779 if (interrupt_input
)
8783 /* If a frame has become visible which was not before, redisplay
8784 again, so that we display it. Expose events for such a frame
8785 (which it gets when becoming visible) don't call the parts of
8786 redisplay constructing glyphs, so simply exposing a frame won't
8787 display anything in this case. So, we have to display these
8788 frames here explicitly. */
8791 Lisp_Object tail
, frame
;
8794 FOR_EACH_FRAME (tail
, frame
)
8796 int this_is_visible
= 0;
8798 if (XFRAME (frame
)->visible
)
8799 this_is_visible
= 1;
8800 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8801 if (XFRAME (frame
)->visible
)
8802 this_is_visible
= 1;
8804 if (this_is_visible
)
8808 if (new_count
!= number_of_visible_frames
)
8809 windows_or_buffers_changed
++;
8812 /* Change frame size now if a change is pending. */
8813 do_pending_window_change (1);
8815 /* If we just did a pending size change, or have additional
8816 visible frames, redisplay again. */
8817 if (windows_or_buffers_changed
&& !pause
)
8822 unbind_to (count
, Qnil
);
8826 /* Redisplay, but leave alone any recent echo area message unless
8827 another message has been requested in its place.
8829 This is useful in situations where you need to redisplay but no
8830 user action has occurred, making it inappropriate for the message
8831 area to be cleared. See tracking_off and
8832 wait_reading_process_input for examples of these situations.
8834 FROM_WHERE is an integer saying from where this function was
8835 called. This is useful for debugging. */
8838 redisplay_preserve_echo_area (from_where
)
8841 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
8843 if (!NILP (echo_area_buffer
[1]))
8845 /* We have a previously displayed message, but no current
8846 message. Redisplay the previous message. */
8847 display_last_displayed_message_p
= 1;
8848 redisplay_internal (1);
8849 display_last_displayed_message_p
= 0;
8852 redisplay_internal (1);
8856 /* Function registered with record_unwind_protect in
8857 redisplay_internal. Clears the flag indicating that a redisplay is
8861 unwind_redisplay (old_redisplaying_p
)
8862 Lisp_Object old_redisplaying_p
;
8864 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8869 /* Mark the display of window W as accurate or inaccurate. If
8870 ACCURATE_P is non-zero mark display of W as accurate. If
8871 ACCURATE_P is zero, arrange for W to be redisplayed the next time
8872 redisplay_internal is called. */
8875 mark_window_display_accurate_1 (w
, accurate_p
)
8879 if (BUFFERP (w
->buffer
))
8881 struct buffer
*b
= XBUFFER (w
->buffer
);
8884 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
8885 w
->last_overlay_modified
8886 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8888 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
8892 b
->clip_changed
= 0;
8893 b
->prevent_redisplay_optimizations_p
= 0;
8895 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8896 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8897 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8898 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8900 w
->current_matrix
->buffer
= b
;
8901 w
->current_matrix
->begv
= BUF_BEGV (b
);
8902 w
->current_matrix
->zv
= BUF_ZV (b
);
8904 w
->last_cursor
= w
->cursor
;
8905 w
->last_cursor_off_p
= w
->cursor_off_p
;
8907 if (w
== XWINDOW (selected_window
))
8908 w
->last_point
= make_number (BUF_PT (b
));
8910 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8916 w
->window_end_valid
= w
->buffer
;
8917 w
->update_mode_line
= Qnil
;
8922 /* Mark the display of windows in the window tree rooted at WINDOW as
8923 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
8924 windows as accurate. If ACCURATE_P is zero, arrange for windows to
8925 be redisplayed the next time redisplay_internal is called. */
8928 mark_window_display_accurate (window
, accurate_p
)
8934 for (; !NILP (window
); window
= w
->next
)
8936 w
= XWINDOW (window
);
8937 mark_window_display_accurate_1 (w
, accurate_p
);
8939 if (!NILP (w
->vchild
))
8940 mark_window_display_accurate (w
->vchild
, accurate_p
);
8941 if (!NILP (w
->hchild
))
8942 mark_window_display_accurate (w
->hchild
, accurate_p
);
8947 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8948 last_arrow_string
= Voverlay_arrow_string
;
8952 /* Force a thorough redisplay the next time by setting
8953 last_arrow_position and last_arrow_string to t, which is
8954 unequal to any useful value of Voverlay_arrow_... */
8955 last_arrow_position
= Qt
;
8956 last_arrow_string
= Qt
;
8961 /* Return value in display table DP (Lisp_Char_Table *) for character
8962 C. Since a display table doesn't have any parent, we don't have to
8963 follow parent. Do not call this function directly but use the
8964 macro DISP_CHAR_VECTOR. */
8967 disp_char_vector (dp
, c
)
8968 struct Lisp_Char_Table
*dp
;
8974 if (SINGLE_BYTE_CHAR_P (c
))
8975 return (dp
->contents
[c
]);
8977 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8980 else if (code
[2] < 32)
8983 /* Here, the possible range of code[0] (== charset ID) is
8984 128..max_charset. Since the top level char table contains data
8985 for multibyte characters after 256th element, we must increment
8986 code[0] by 128 to get a correct index. */
8988 code
[3] = -1; /* anchor */
8990 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8992 val
= dp
->contents
[code
[i
]];
8993 if (!SUB_CHAR_TABLE_P (val
))
8994 return (NILP (val
) ? dp
->defalt
: val
);
8997 /* Here, val is a sub char table. We return the default value of
8999 return (dp
->defalt
);
9004 /***********************************************************************
9006 ***********************************************************************/
9008 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9011 redisplay_windows (window
)
9014 while (!NILP (window
))
9016 struct window
*w
= XWINDOW (window
);
9018 if (!NILP (w
->hchild
))
9019 redisplay_windows (w
->hchild
);
9020 else if (!NILP (w
->vchild
))
9021 redisplay_windows (w
->vchild
);
9023 redisplay_window (window
, 0);
9030 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9031 DELTA is the number of bytes by which positions recorded in ROW
9032 differ from current buffer positions. */
9035 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9037 struct glyph_row
*row
;
9038 struct glyph_matrix
*matrix
;
9039 int delta
, delta_bytes
, dy
, dvpos
;
9041 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9042 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9044 int pt_old
= PT
- delta
;
9046 /* Skip over glyphs not having an object at the start of the row.
9047 These are special glyphs like truncation marks on terminal
9049 if (row
->displays_text_p
)
9051 && INTEGERP (glyph
->object
)
9052 && glyph
->charpos
< 0)
9054 x
+= glyph
->pixel_width
;
9059 && !INTEGERP (glyph
->object
)
9060 && (!BUFFERP (glyph
->object
)
9061 || glyph
->charpos
< pt_old
))
9063 x
+= glyph
->pixel_width
;
9067 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9069 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9070 w
->cursor
.y
= row
->y
+ dy
;
9072 if (w
== XWINDOW (selected_window
))
9074 if (!row
->continued_p
9075 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9078 this_line_buffer
= XBUFFER (w
->buffer
);
9080 CHARPOS (this_line_start_pos
)
9081 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9082 BYTEPOS (this_line_start_pos
)
9083 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9085 CHARPOS (this_line_end_pos
)
9086 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9087 BYTEPOS (this_line_end_pos
)
9088 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9090 this_line_y
= w
->cursor
.y
;
9091 this_line_pixel_height
= row
->height
;
9092 this_line_vpos
= w
->cursor
.vpos
;
9093 this_line_start_x
= row
->x
;
9096 CHARPOS (this_line_start_pos
) = 0;
9101 /* Run window scroll functions, if any, for WINDOW with new window
9102 start STARTP. Sets the window start of WINDOW to that position.
9104 We assume that the window's buffer is really current. */
9106 static INLINE
struct text_pos
9107 run_window_scroll_functions (window
, startp
)
9109 struct text_pos startp
;
9111 struct window
*w
= XWINDOW (window
);
9112 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9114 if (current_buffer
!= XBUFFER (w
->buffer
))
9117 if (!NILP (Vwindow_scroll_functions
))
9119 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9120 make_number (CHARPOS (startp
)));
9121 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9122 /* In case the hook functions switch buffers. */
9123 if (current_buffer
!= XBUFFER (w
->buffer
))
9124 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9131 /* Modify the desired matrix of window W and W->vscroll so that the
9132 line containing the cursor is fully visible. */
9135 make_cursor_line_fully_visible (w
)
9138 struct glyph_matrix
*matrix
;
9139 struct glyph_row
*row
;
9142 /* It's not always possible to find the cursor, e.g, when a window
9143 is full of overlay strings. Don't do anything in that case. */
9144 if (w
->cursor
.vpos
< 0)
9147 matrix
= w
->desired_matrix
;
9148 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9150 /* If the cursor row is not partially visible, there's nothing
9152 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9155 /* If the row the cursor is in is taller than the window's height,
9156 it's not clear what to do, so do nothing. */
9157 window_height
= window_box_height (w
);
9158 if (row
->height
>= window_height
)
9161 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9163 int dy
= row
->height
- row
->visible_height
;
9166 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9168 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9170 int dy
= - (row
->height
- row
->visible_height
);
9173 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9176 /* When we change the cursor y-position of the selected window,
9177 change this_line_y as well so that the display optimization for
9178 the cursor line of the selected window in redisplay_internal uses
9179 the correct y-position. */
9180 if (w
== XWINDOW (selected_window
))
9181 this_line_y
= w
->cursor
.y
;
9185 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9186 non-zero means only WINDOW is redisplayed in redisplay_internal.
9187 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9188 in redisplay_window to bring a partially visible line into view in
9189 the case that only the cursor has moved.
9193 1 if scrolling succeeded
9195 0 if scrolling didn't find point.
9197 -1 if new fonts have been loaded so that we must interrupt
9198 redisplay, adjust glyph matrices, and try again. */
9201 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9202 scroll_step
, temp_scroll_step
)
9204 int just_this_one_p
;
9205 int scroll_conservatively
, scroll_step
;
9206 int temp_scroll_step
;
9208 struct window
*w
= XWINDOW (window
);
9209 struct frame
*f
= XFRAME (w
->frame
);
9210 struct text_pos scroll_margin_pos
;
9211 struct text_pos pos
;
9212 struct text_pos startp
;
9214 Lisp_Object window_end
;
9215 int this_scroll_margin
;
9219 int amount_to_scroll
= 0;
9220 Lisp_Object aggressive
;
9224 debug_method_add (w
, "try_scrolling");
9227 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9229 /* Compute scroll margin height in pixels. We scroll when point is
9230 within this distance from the top or bottom of the window. */
9231 if (scroll_margin
> 0)
9233 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9234 this_scroll_margin
*= CANON_Y_UNIT (f
);
9237 this_scroll_margin
= 0;
9239 /* Compute how much we should try to scroll maximally to bring point
9241 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9242 scroll_max
= max (scroll_step
,
9243 max (scroll_conservatively
, temp_scroll_step
));
9244 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9245 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9246 /* We're trying to scroll because of aggressive scrolling
9247 but no scroll_step is set. Choose an arbitrary one. Maybe
9248 there should be a variable for this. */
9252 scroll_max
*= CANON_Y_UNIT (f
);
9254 /* Decide whether we have to scroll down. Start at the window end
9255 and move this_scroll_margin up to find the position of the scroll
9257 window_end
= Fwindow_end (window
, Qt
);
9258 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9259 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9260 if (this_scroll_margin
)
9262 start_display (&it
, w
, scroll_margin_pos
);
9263 move_it_vertically (&it
, - this_scroll_margin
);
9264 scroll_margin_pos
= it
.current
.pos
;
9267 if (PT
>= CHARPOS (scroll_margin_pos
))
9271 /* Point is in the scroll margin at the bottom of the window, or
9272 below. Compute a new window start that makes point visible. */
9274 /* Compute the distance from the scroll margin to PT.
9275 Give up if the distance is greater than scroll_max. */
9276 start_display (&it
, w
, scroll_margin_pos
);
9278 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9279 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9281 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9282 end, which is one line below the window. The iterator's
9283 current_y will be same as y0 in that case, but we have to
9284 scroll a line to make PT visible. That's the reason why 1 is
9286 dy
= 1 + it
.current_y
- y0
;
9288 if (dy
> scroll_max
)
9291 /* Move the window start down. If scrolling conservatively,
9292 move it just enough down to make point visible. If
9293 scroll_step is set, move it down by scroll_step. */
9294 start_display (&it
, w
, startp
);
9296 if (scroll_conservatively
)
9298 = max (max (dy
, CANON_Y_UNIT (f
)),
9299 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9300 else if (scroll_step
|| temp_scroll_step
)
9301 amount_to_scroll
= scroll_max
;
9304 aggressive
= current_buffer
->scroll_down_aggressively
;
9305 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9306 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9307 if (NUMBERP (aggressive
))
9308 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9311 if (amount_to_scroll
<= 0)
9314 move_it_vertically (&it
, amount_to_scroll
);
9315 startp
= it
.current
.pos
;
9319 /* See if point is inside the scroll margin at the top of the
9321 scroll_margin_pos
= startp
;
9322 if (this_scroll_margin
)
9324 start_display (&it
, w
, startp
);
9325 move_it_vertically (&it
, this_scroll_margin
);
9326 scroll_margin_pos
= it
.current
.pos
;
9329 if (PT
< CHARPOS (scroll_margin_pos
))
9331 /* Point is in the scroll margin at the top of the window or
9332 above what is displayed in the window. */
9335 /* Compute the vertical distance from PT to the scroll
9336 margin position. Give up if distance is greater than
9338 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9339 start_display (&it
, w
, pos
);
9341 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9342 it
.last_visible_y
, -1,
9343 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9344 dy
= it
.current_y
- y0
;
9345 if (dy
> scroll_max
)
9348 /* Compute new window start. */
9349 start_display (&it
, w
, startp
);
9351 if (scroll_conservatively
)
9353 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9354 else if (scroll_step
|| temp_scroll_step
)
9355 amount_to_scroll
= scroll_max
;
9358 aggressive
= current_buffer
->scroll_up_aggressively
;
9359 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9360 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9361 if (NUMBERP (aggressive
))
9362 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9365 if (amount_to_scroll
<= 0)
9368 move_it_vertically (&it
, - amount_to_scroll
);
9369 startp
= it
.current
.pos
;
9373 /* Run window scroll functions. */
9374 startp
= run_window_scroll_functions (window
, startp
);
9376 /* Display the window. Give up if new fonts are loaded, or if point
9378 if (!try_window (window
, startp
))
9380 else if (w
->cursor
.vpos
< 0)
9382 clear_glyph_matrix (w
->desired_matrix
);
9387 /* Maybe forget recorded base line for line number display. */
9388 if (!just_this_one_p
9389 || current_buffer
->clip_changed
9390 || BEG_UNCHANGED
< CHARPOS (startp
))
9391 w
->base_line_number
= Qnil
;
9393 /* If cursor ends up on a partially visible line, shift display
9394 lines up or down. */
9395 make_cursor_line_fully_visible (w
);
9403 /* Compute a suitable window start for window W if display of W starts
9404 on a continuation line. Value is non-zero if a new window start
9407 The new window start will be computed, based on W's width, starting
9408 from the start of the continued line. It is the start of the
9409 screen line with the minimum distance from the old start W->start. */
9412 compute_window_start_on_continuation_line (w
)
9415 struct text_pos pos
, start_pos
;
9416 int window_start_changed_p
= 0;
9418 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9420 /* If window start is on a continuation line... Window start may be
9421 < BEGV in case there's invisible text at the start of the
9422 buffer (M-x rmail, for example). */
9423 if (CHARPOS (start_pos
) > BEGV
9424 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9427 struct glyph_row
*row
;
9429 /* Handle the case that the window start is out of range. */
9430 if (CHARPOS (start_pos
) < BEGV
)
9431 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9432 else if (CHARPOS (start_pos
) > ZV
)
9433 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9435 /* Find the start of the continued line. This should be fast
9436 because scan_buffer is fast (newline cache). */
9437 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9438 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9439 row
, DEFAULT_FACE_ID
);
9440 reseat_at_previous_visible_line_start (&it
);
9442 /* If the line start is "too far" away from the window start,
9443 say it takes too much time to compute a new window start. */
9444 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9445 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9447 int min_distance
, distance
;
9449 /* Move forward by display lines to find the new window
9450 start. If window width was enlarged, the new start can
9451 be expected to be > the old start. If window width was
9452 decreased, the new window start will be < the old start.
9453 So, we're looking for the display line start with the
9454 minimum distance from the old window start. */
9455 pos
= it
.current
.pos
;
9456 min_distance
= INFINITY
;
9457 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9458 distance
< min_distance
)
9460 min_distance
= distance
;
9461 pos
= it
.current
.pos
;
9462 move_it_by_lines (&it
, 1, 0);
9465 /* Set the window start there. */
9466 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9467 window_start_changed_p
= 1;
9471 return window_start_changed_p
;
9475 /* Try cursor movement in case text has not changes in window WINDOW,
9476 with window start STARTP. Value is
9480 0 if this method cannot be used
9482 -1 if we know we have to scroll the display. *SCROLL_STEP is
9483 set to 1, under certain circumstances, if we want to scroll as
9484 if scroll-step were set to 1. See the code. */
9487 try_cursor_movement (window
, startp
, scroll_step
)
9489 struct text_pos startp
;
9492 struct window
*w
= XWINDOW (window
);
9493 struct frame
*f
= XFRAME (w
->frame
);
9496 /* Handle case where text has not changed, only point, and it has
9497 not moved off the frame. */
9498 if (/* Point may be in this window. */
9499 PT
>= CHARPOS (startp
)
9500 /* Selective display hasn't changed. */
9501 && !current_buffer
->clip_changed
9502 /* Function force-mode-line-update is used to force a thorough
9503 redisplay. It sets either windows_or_buffers_changed or
9504 update_mode_lines. So don't take a shortcut here for these
9506 && !update_mode_lines
9507 && !windows_or_buffers_changed
9508 /* Can't use this case if highlighting a region. When a
9509 region exists, cursor movement has to do more than just
9511 && !(!NILP (Vtransient_mark_mode
)
9512 && !NILP (current_buffer
->mark_active
))
9513 && NILP (w
->region_showing
)
9514 && NILP (Vshow_trailing_whitespace
)
9515 /* Right after splitting windows, last_point may be nil. */
9516 && INTEGERP (w
->last_point
)
9517 /* This code is not used for mini-buffer for the sake of the case
9518 of redisplaying to replace an echo area message; since in
9519 that case the mini-buffer contents per se are usually
9520 unchanged. This code is of no real use in the mini-buffer
9521 since the handling of this_line_start_pos, etc., in redisplay
9522 handles the same cases. */
9523 && !EQ (window
, minibuf_window
)
9524 /* When splitting windows or for new windows, it happens that
9525 redisplay is called with a nil window_end_vpos or one being
9526 larger than the window. This should really be fixed in
9527 window.c. I don't have this on my list, now, so we do
9528 approximately the same as the old redisplay code. --gerd. */
9529 && INTEGERP (w
->window_end_vpos
)
9530 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9531 && (FRAME_WINDOW_P (f
)
9532 || !MARKERP (Voverlay_arrow_position
)
9533 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9535 int this_scroll_margin
;
9536 struct glyph_row
*row
;
9539 debug_method_add (w
, "cursor movement");
9542 /* Scroll if point within this distance from the top or bottom
9543 of the window. This is a pixel value. */
9544 this_scroll_margin
= max (0, scroll_margin
);
9545 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9546 this_scroll_margin
*= CANON_Y_UNIT (f
);
9548 /* Start with the row the cursor was displayed during the last
9549 not paused redisplay. Give up if that row is not valid. */
9550 if (w
->last_cursor
.vpos
< 0
9551 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9555 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9556 if (row
->mode_line_p
)
9558 if (!row
->enabled_p
)
9565 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9567 if (PT
> XFASTINT (w
->last_point
))
9569 /* Point has moved forward. */
9570 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9571 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9573 xassert (row
->enabled_p
);
9577 /* The end position of a row equals the start position
9578 of the next row. If PT is there, we would rather
9579 display it in the next line. */
9580 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9581 && MATRIX_ROW_END_CHARPOS (row
) == PT
9582 && !cursor_row_p (w
, row
))
9585 /* If within the scroll margin, scroll. Note that
9586 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9587 the next line would be drawn, and that
9588 this_scroll_margin can be zero. */
9589 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9590 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9591 /* Line is completely visible last line in window
9592 and PT is to be set in the next line. */
9593 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9594 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9595 && !row
->ends_at_zv_p
9596 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9599 else if (PT
< XFASTINT (w
->last_point
))
9601 /* Cursor has to be moved backward. Note that PT >=
9602 CHARPOS (startp) because of the outer
9604 while (!row
->mode_line_p
9605 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9606 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9607 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9608 && (row
->y
> this_scroll_margin
9609 || CHARPOS (startp
) == BEGV
))
9611 xassert (row
->enabled_p
);
9615 /* Consider the following case: Window starts at BEGV,
9616 there is invisible, intangible text at BEGV, so that
9617 display starts at some point START > BEGV. It can
9618 happen that we are called with PT somewhere between
9619 BEGV and START. Try to handle that case. */
9620 if (row
< w
->current_matrix
->rows
9621 || row
->mode_line_p
)
9623 row
= w
->current_matrix
->rows
;
9624 if (row
->mode_line_p
)
9628 /* Due to newlines in overlay strings, we may have to
9629 skip forward over overlay strings. */
9630 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9631 && MATRIX_ROW_END_CHARPOS (row
) == PT
9632 && !cursor_row_p (w
, row
))
9635 /* If within the scroll margin, scroll. */
9636 if (row
->y
< this_scroll_margin
9637 && CHARPOS (startp
) != BEGV
)
9641 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9642 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9644 /* if PT is not in the glyph row, give up. */
9647 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9649 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9650 && !row
->ends_at_zv_p
9651 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9653 else if (row
->height
> window_box_height (w
))
9655 /* If we end up in a partially visible line, let's
9656 make it fully visible, except when it's taller
9657 than the window, in which case we can't do much
9664 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9665 try_window (window
, startp
);
9666 make_cursor_line_fully_visible (w
);
9674 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9684 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9685 selected_window is redisplayed. */
9688 redisplay_window (window
, just_this_one_p
)
9690 int just_this_one_p
;
9692 struct window
*w
= XWINDOW (window
);
9693 struct frame
*f
= XFRAME (w
->frame
);
9694 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9695 struct buffer
*old
= current_buffer
;
9696 struct text_pos lpoint
, opoint
, startp
;
9697 int update_mode_line
;
9700 /* Record it now because it's overwritten. */
9701 int current_matrix_up_to_date_p
= 0;
9702 int temp_scroll_step
= 0;
9703 int count
= BINDING_STACK_SIZE ();
9706 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9709 /* W must be a leaf window here. */
9710 xassert (!NILP (w
->buffer
));
9712 *w
->desired_matrix
->method
= 0;
9715 specbind (Qinhibit_point_motion_hooks
, Qt
);
9717 reconsider_clip_changes (w
, buffer
);
9719 /* Has the mode line to be updated? */
9720 update_mode_line
= (!NILP (w
->update_mode_line
)
9721 || update_mode_lines
9722 || buffer
->clip_changed
);
9724 if (MINI_WINDOW_P (w
))
9726 if (w
== XWINDOW (echo_area_window
)
9727 && !NILP (echo_area_buffer
[0]))
9729 if (update_mode_line
)
9730 /* We may have to update a tty frame's menu bar or a
9731 tool-bar. Example `M-x C-h C-h C-g'. */
9732 goto finish_menu_bars
;
9734 /* We've already displayed the echo area glyphs in this window. */
9735 goto finish_scroll_bars
;
9737 else if (w
!= XWINDOW (minibuf_window
))
9739 /* W is a mini-buffer window, but it's not the currently
9740 active one, so clear it. */
9741 int yb
= window_text_bottom_y (w
);
9742 struct glyph_row
*row
;
9745 for (y
= 0, row
= w
->desired_matrix
->rows
;
9747 y
+= row
->height
, ++row
)
9748 blank_row (w
, row
, y
);
9749 goto finish_scroll_bars
;
9753 /* Otherwise set up data on this window; select its buffer and point
9755 /* Really select the buffer, for the sake of buffer-local
9757 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9758 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9760 current_matrix_up_to_date_p
9761 = (!NILP (w
->window_end_valid
)
9762 && !current_buffer
->clip_changed
9763 && XFASTINT (w
->last_modified
) >= MODIFF
9764 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9766 /* When windows_or_buffers_changed is non-zero, we can't rely on
9767 the window end being valid, so set it to nil there. */
9768 if (windows_or_buffers_changed
)
9770 /* If window starts on a continuation line, maybe adjust the
9771 window start in case the window's width changed. */
9772 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9773 compute_window_start_on_continuation_line (w
);
9775 w
->window_end_valid
= Qnil
;
9778 /* Some sanity checks. */
9779 CHECK_WINDOW_END (w
);
9780 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9782 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9785 /* If %c is in mode line, update it if needed. */
9786 if (!NILP (w
->column_number_displayed
)
9787 /* This alternative quickly identifies a common case
9788 where no change is needed. */
9789 && !(PT
== XFASTINT (w
->last_point
)
9790 && XFASTINT (w
->last_modified
) >= MODIFF
9791 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9792 && XFASTINT (w
->column_number_displayed
) != current_column ())
9793 update_mode_line
= 1;
9795 /* Count number of windows showing the selected buffer. An indirect
9796 buffer counts as its base buffer. */
9797 if (!just_this_one_p
)
9799 struct buffer
*current_base
, *window_base
;
9800 current_base
= current_buffer
;
9801 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9802 if (current_base
->base_buffer
)
9803 current_base
= current_base
->base_buffer
;
9804 if (window_base
->base_buffer
)
9805 window_base
= window_base
->base_buffer
;
9806 if (current_base
== window_base
)
9810 /* Point refers normally to the selected window. For any other
9811 window, set up appropriate value. */
9812 if (!EQ (window
, selected_window
))
9814 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9815 int new_pt_byte
= marker_byte_position (w
->pointm
);
9819 new_pt_byte
= BEGV_BYTE
;
9820 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9822 else if (new_pt
> (ZV
- 1))
9825 new_pt_byte
= ZV_BYTE
;
9826 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9829 /* We don't use SET_PT so that the point-motion hooks don't run. */
9830 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9833 /* If any of the character widths specified in the display table
9834 have changed, invalidate the width run cache. It's true that
9835 this may be a bit late to catch such changes, but the rest of
9836 redisplay goes (non-fatally) haywire when the display table is
9837 changed, so why should we worry about doing any better? */
9838 if (current_buffer
->width_run_cache
)
9840 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9842 if (! disptab_matches_widthtab (disptab
,
9843 XVECTOR (current_buffer
->width_table
)))
9845 invalidate_region_cache (current_buffer
,
9846 current_buffer
->width_run_cache
,
9848 recompute_width_table (current_buffer
, disptab
);
9852 /* If window-start is screwed up, choose a new one. */
9853 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9856 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9858 /* If someone specified a new starting point but did not insist,
9859 check whether it can be used. */
9860 if (!NILP (w
->optional_new_start
)
9861 && CHARPOS (startp
) >= BEGV
9862 && CHARPOS (startp
) <= ZV
)
9864 w
->optional_new_start
= Qnil
;
9865 start_display (&it
, w
, startp
);
9866 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9867 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9868 if (IT_CHARPOS (it
) == PT
)
9869 w
->force_start
= Qt
;
9872 /* Handle case where place to start displaying has been specified,
9873 unless the specified location is outside the accessible range. */
9874 if (!NILP (w
->force_start
)
9875 || w
->frozen_window_start_p
)
9877 w
->force_start
= Qnil
;
9879 w
->window_end_valid
= Qnil
;
9881 /* Forget any recorded base line for line number display. */
9882 if (!current_matrix_up_to_date_p
9883 || current_buffer
->clip_changed
)
9884 w
->base_line_number
= Qnil
;
9886 /* Redisplay the mode line. Select the buffer properly for that.
9887 Also, run the hook window-scroll-functions
9888 because we have scrolled. */
9889 /* Note, we do this after clearing force_start because
9890 if there's an error, it is better to forget about force_start
9891 than to get into an infinite loop calling the hook functions
9892 and having them get more errors. */
9893 if (!update_mode_line
9894 || ! NILP (Vwindow_scroll_functions
))
9896 update_mode_line
= 1;
9897 w
->update_mode_line
= Qt
;
9898 startp
= run_window_scroll_functions (window
, startp
);
9901 w
->last_modified
= make_number (0);
9902 w
->last_overlay_modified
= make_number (0);
9903 if (CHARPOS (startp
) < BEGV
)
9904 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9905 else if (CHARPOS (startp
) > ZV
)
9906 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9908 /* Redisplay, then check if cursor has been set during the
9909 redisplay. Give up if new fonts were loaded. */
9910 if (!try_window (window
, startp
))
9912 w
->force_start
= Qt
;
9913 clear_glyph_matrix (w
->desired_matrix
);
9914 goto finish_scroll_bars
;
9917 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9919 /* If point does not appear, try to move point so it does
9920 appear. The desired matrix has been built above, so we
9923 struct glyph_row
*row
;
9925 window_height
= window_box_height (w
) / 2;
9926 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9927 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9930 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9931 MATRIX_ROW_START_BYTEPOS (row
));
9933 if (w
!= XWINDOW (selected_window
))
9934 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9935 else if (current_buffer
== old
)
9936 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9938 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9940 /* If we are highlighting the region, then we just changed
9941 the region, so redisplay to show it. */
9942 if (!NILP (Vtransient_mark_mode
)
9943 && !NILP (current_buffer
->mark_active
))
9945 clear_glyph_matrix (w
->desired_matrix
);
9946 if (!try_window (window
, startp
))
9947 goto finish_scroll_bars
;
9951 make_cursor_line_fully_visible (w
);
9953 debug_method_add (w
, "forced window start");
9958 /* Handle case where text has not changed, only point, and it has
9959 not moved off the frame. */
9960 if (current_matrix_up_to_date_p
9961 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9969 /* If current starting point was originally the beginning of a line
9970 but no longer is, find a new starting point. */
9971 else if (!NILP (w
->start_at_line_beg
)
9972 && !(CHARPOS (startp
) <= BEGV
9973 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9976 debug_method_add (w
, "recenter 1");
9981 /* Try scrolling with try_window_id. */
9982 else if (/* Windows and buffers haven't changed. */
9983 !windows_or_buffers_changed
9984 /* Window must be either use window-based redisplay or
9986 && (FRAME_WINDOW_P (f
)
9987 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9988 && !MINI_WINDOW_P (w
)
9989 /* Point is not known NOT to appear in window. */
9990 && PT
>= CHARPOS (startp
)
9991 && XFASTINT (w
->last_modified
)
9992 /* Window is not hscrolled. */
9993 && XFASTINT (w
->hscroll
) == 0
9994 /* Selective display has not changed. */
9995 && !current_buffer
->clip_changed
9996 /* Current matrix is up to date. */
9997 && !NILP (w
->window_end_valid
)
9998 /* Can't use this case if highlighting a region because
9999 a cursor movement will do more than just set the cursor. */
10000 && !(!NILP (Vtransient_mark_mode
)
10001 && !NILP (current_buffer
->mark_active
))
10002 && NILP (w
->region_showing
)
10003 && NILP (Vshow_trailing_whitespace
)
10004 /* Overlay arrow position and string not changed. */
10005 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
10006 && EQ (last_arrow_string
, Voverlay_arrow_string
)
10007 /* Value is > 0 if update has been done, it is -1 if we
10008 know that the same window start will not work. It is 0
10009 if unsuccessful for some other reason. */
10010 && (tem
= try_window_id (w
)) != 0)
10013 debug_method_add (w
, "try_window_id %d", tem
);
10016 if (fonts_changed_p
)
10017 goto finish_scroll_bars
;
10021 /* Otherwise try_window_id has returned -1 which means that we
10022 don't want the alternative below this comment to execute. */
10024 else if (CHARPOS (startp
) >= BEGV
10025 && CHARPOS (startp
) <= ZV
10026 && PT
>= CHARPOS (startp
)
10027 && (CHARPOS (startp
) < ZV
10028 /* Avoid starting at end of buffer. */
10029 || CHARPOS (startp
) == BEGV
10030 || (XFASTINT (w
->last_modified
) >= MODIFF
10031 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10034 debug_method_add (w
, "same window start");
10037 /* Try to redisplay starting at same place as before.
10038 If point has not moved off frame, accept the results. */
10039 if (!current_matrix_up_to_date_p
10040 /* Don't use try_window_reusing_current_matrix in this case
10041 because a window scroll function can have changed the
10043 || !NILP (Vwindow_scroll_functions
)
10044 || MINI_WINDOW_P (w
)
10045 || !try_window_reusing_current_matrix (w
))
10047 IF_DEBUG (debug_method_add (w
, "1"));
10048 try_window (window
, startp
);
10051 if (fonts_changed_p
)
10052 goto finish_scroll_bars
;
10054 if (w
->cursor
.vpos
>= 0)
10056 if (!just_this_one_p
10057 || current_buffer
->clip_changed
10058 || BEG_UNCHANGED
< CHARPOS (startp
))
10059 /* Forget any recorded base line for line number display. */
10060 w
->base_line_number
= Qnil
;
10062 make_cursor_line_fully_visible (w
);
10066 clear_glyph_matrix (w
->desired_matrix
);
10071 w
->last_modified
= make_number (0);
10072 w
->last_overlay_modified
= make_number (0);
10074 /* Redisplay the mode line. Select the buffer properly for that. */
10075 if (!update_mode_line
)
10077 update_mode_line
= 1;
10078 w
->update_mode_line
= Qt
;
10081 /* Try to scroll by specified few lines. */
10082 if ((scroll_conservatively
10084 || temp_scroll_step
10085 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10086 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10087 && !current_buffer
->clip_changed
10088 && CHARPOS (startp
) >= BEGV
10089 && CHARPOS (startp
) <= ZV
)
10091 /* The function returns -1 if new fonts were loaded, 1 if
10092 successful, 0 if not successful. */
10093 int rc
= try_scrolling (window
, just_this_one_p
,
10094 scroll_conservatively
,
10100 goto finish_scroll_bars
;
10103 /* Finally, just choose place to start which centers point */
10108 debug_method_add (w
, "recenter");
10111 /* w->vscroll = 0; */
10113 /* Forget any previously recorded base line for line number display. */
10114 if (!current_matrix_up_to_date_p
10115 || current_buffer
->clip_changed
)
10116 w
->base_line_number
= Qnil
;
10118 /* Move backward half the height of the window. */
10119 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10120 it
.current_y
= it
.last_visible_y
;
10121 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
10122 xassert (IT_CHARPOS (it
) >= BEGV
);
10124 /* The function move_it_vertically_backward may move over more
10125 than the specified y-distance. If it->w is small, e.g. a
10126 mini-buffer window, we may end up in front of the window's
10127 display area. Start displaying at the start of the line
10128 containing PT in this case. */
10129 if (it
.current_y
<= 0)
10131 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10132 move_it_vertically (&it
, 0);
10133 xassert (IT_CHARPOS (it
) <= PT
);
10137 it
.current_x
= it
.hpos
= 0;
10139 /* Set startp here explicitly in case that helps avoid an infinite loop
10140 in case the window-scroll-functions functions get errors. */
10141 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10143 /* Run scroll hooks. */
10144 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10146 /* Redisplay the window. */
10147 if (!current_matrix_up_to_date_p
10148 || windows_or_buffers_changed
10149 /* Don't use try_window_reusing_current_matrix in this case
10150 because it can have changed the buffer. */
10151 || !NILP (Vwindow_scroll_functions
)
10152 || !just_this_one_p
10153 || MINI_WINDOW_P (w
)
10154 || !try_window_reusing_current_matrix (w
))
10155 try_window (window
, startp
);
10157 /* If new fonts have been loaded (due to fontsets), give up. We
10158 have to start a new redisplay since we need to re-adjust glyph
10160 if (fonts_changed_p
)
10161 goto finish_scroll_bars
;
10163 /* If cursor did not appear assume that the middle of the window is
10164 in the first line of the window. Do it again with the next line.
10165 (Imagine a window of height 100, displaying two lines of height
10166 60. Moving back 50 from it->last_visible_y will end in the first
10168 if (w
->cursor
.vpos
< 0)
10170 if (!NILP (w
->window_end_valid
)
10171 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10173 clear_glyph_matrix (w
->desired_matrix
);
10174 move_it_by_lines (&it
, 1, 0);
10175 try_window (window
, it
.current
.pos
);
10177 else if (PT
< IT_CHARPOS (it
))
10179 clear_glyph_matrix (w
->desired_matrix
);
10180 move_it_by_lines (&it
, -1, 0);
10181 try_window (window
, it
.current
.pos
);
10185 /* Not much we can do about it. */
10189 /* Consider the following case: Window starts at BEGV, there is
10190 invisible, intangible text at BEGV, so that display starts at
10191 some point START > BEGV. It can happen that we are called with
10192 PT somewhere between BEGV and START. Try to handle that case. */
10193 if (w
->cursor
.vpos
< 0)
10195 struct glyph_row
*row
= w
->current_matrix
->rows
;
10196 if (row
->mode_line_p
)
10198 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10201 make_cursor_line_fully_visible (w
);
10205 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10206 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10207 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10210 /* Display the mode line, if we must. */
10211 if ((update_mode_line
10212 /* If window not full width, must redo its mode line
10213 if (a) the window to its side is being redone and
10214 (b) we do a frame-based redisplay. This is a consequence
10215 of how inverted lines are drawn in frame-based redisplay. */
10216 || (!just_this_one_p
10217 && !FRAME_WINDOW_P (f
)
10218 && !WINDOW_FULL_WIDTH_P (w
))
10219 /* Line number to display. */
10220 || INTEGERP (w
->base_line_pos
)
10221 /* Column number is displayed and different from the one displayed. */
10222 || (!NILP (w
->column_number_displayed
)
10223 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10224 /* This means that the window has a mode line. */
10225 && (WINDOW_WANTS_MODELINE_P (w
)
10226 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10228 Lisp_Object old_selected_frame
;
10230 old_selected_frame
= selected_frame
;
10232 XSETFRAME (selected_frame
, f
);
10233 display_mode_lines (w
);
10234 selected_frame
= old_selected_frame
;
10236 /* If mode line height has changed, arrange for a thorough
10237 immediate redisplay using the correct mode line height. */
10238 if (WINDOW_WANTS_MODELINE_P (w
)
10239 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10241 fonts_changed_p
= 1;
10242 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10243 = DESIRED_MODE_LINE_HEIGHT (w
);
10246 /* If top line height has changed, arrange for a thorough
10247 immediate redisplay using the correct mode line height. */
10248 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10249 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10251 fonts_changed_p
= 1;
10252 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10253 = DESIRED_HEADER_LINE_HEIGHT (w
);
10256 if (fonts_changed_p
)
10257 goto finish_scroll_bars
;
10260 if (!line_number_displayed
10261 && !BUFFERP (w
->base_line_pos
))
10263 w
->base_line_pos
= Qnil
;
10264 w
->base_line_number
= Qnil
;
10269 /* When we reach a frame's selected window, redo the frame's menu bar. */
10270 if (update_mode_line
10271 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10273 int redisplay_menu_p
= 0;
10275 if (FRAME_WINDOW_P (f
))
10277 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10278 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10280 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10284 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10286 if (redisplay_menu_p
)
10287 display_menu_bar (w
);
10289 #ifdef HAVE_WINDOW_SYSTEM
10290 if (WINDOWP (f
->tool_bar_window
)
10291 && (FRAME_TOOL_BAR_LINES (f
) > 0
10292 || auto_resize_tool_bars_p
))
10293 redisplay_tool_bar (f
);
10297 finish_scroll_bars
:
10299 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10301 int start
, end
, whole
;
10303 /* Calculate the start and end positions for the current window.
10304 At some point, it would be nice to choose between scrollbars
10305 which reflect the whole buffer size, with special markers
10306 indicating narrowing, and scrollbars which reflect only the
10309 Note that mini-buffers sometimes aren't displaying any text. */
10310 if (!MINI_WINDOW_P (w
)
10311 || (w
== XWINDOW (minibuf_window
)
10312 && NILP (echo_area_buffer
[0])))
10315 start
= marker_position (w
->start
) - BEGV
;
10316 /* I don't think this is guaranteed to be right. For the
10317 moment, we'll pretend it is. */
10318 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10322 if (whole
< (end
- start
))
10323 whole
= end
- start
;
10326 start
= end
= whole
= 0;
10328 /* Indicate what this scroll bar ought to be displaying now. */
10329 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10331 /* Note that we actually used the scroll bar attached to this
10332 window, so it shouldn't be deleted at the end of redisplay. */
10333 redeem_scroll_bar_hook (w
);
10336 /* Restore current_buffer and value of point in it. */
10337 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10338 set_buffer_internal_1 (old
);
10339 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10341 unbind_to (count
, Qnil
);
10345 /* Build the complete desired matrix of WINDOW with a window start
10346 buffer position POS. Value is non-zero if successful. It is zero
10347 if fonts were loaded during redisplay which makes re-adjusting
10348 glyph matrices necessary. */
10351 try_window (window
, pos
)
10352 Lisp_Object window
;
10353 struct text_pos pos
;
10355 struct window
*w
= XWINDOW (window
);
10357 struct glyph_row
*last_text_row
= NULL
;
10359 /* Make POS the new window start. */
10360 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10362 /* Mark cursor position as unknown. No overlay arrow seen. */
10363 w
->cursor
.vpos
= -1;
10364 overlay_arrow_seen
= 0;
10366 /* Initialize iterator and info to start at POS. */
10367 start_display (&it
, w
, pos
);
10369 /* Display all lines of W. */
10370 while (it
.current_y
< it
.last_visible_y
)
10372 if (display_line (&it
))
10373 last_text_row
= it
.glyph_row
- 1;
10374 if (fonts_changed_p
)
10378 /* If bottom moved off end of frame, change mode line percentage. */
10379 if (XFASTINT (w
->window_end_pos
) <= 0
10380 && Z
!= IT_CHARPOS (it
))
10381 w
->update_mode_line
= Qt
;
10383 /* Set window_end_pos to the offset of the last character displayed
10384 on the window from the end of current_buffer. Set
10385 window_end_vpos to its row number. */
10388 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10389 w
->window_end_bytepos
10390 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10392 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10394 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10395 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10396 ->displays_text_p
);
10400 w
->window_end_bytepos
= 0;
10401 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10404 /* But that is not valid info until redisplay finishes. */
10405 w
->window_end_valid
= Qnil
;
10411 /************************************************************************
10412 Window redisplay reusing current matrix when buffer has not changed
10413 ************************************************************************/
10415 /* Try redisplay of window W showing an unchanged buffer with a
10416 different window start than the last time it was displayed by
10417 reusing its current matrix. Value is non-zero if successful.
10418 W->start is the new window start. */
10421 try_window_reusing_current_matrix (w
)
10424 struct frame
*f
= XFRAME (w
->frame
);
10425 struct glyph_row
*row
, *bottom_row
;
10428 struct text_pos start
, new_start
;
10429 int nrows_scrolled
, i
;
10430 struct glyph_row
*last_text_row
;
10431 struct glyph_row
*last_reused_text_row
;
10432 struct glyph_row
*start_row
;
10433 int start_vpos
, min_y
, max_y
;
10435 if (/* This function doesn't handle terminal frames. */
10436 !FRAME_WINDOW_P (f
)
10437 /* Don't try to reuse the display if windows have been split
10439 || windows_or_buffers_changed
)
10442 /* Can't do this if region may have changed. */
10443 if ((!NILP (Vtransient_mark_mode
)
10444 && !NILP (current_buffer
->mark_active
))
10445 || !NILP (w
->region_showing
)
10446 || !NILP (Vshow_trailing_whitespace
))
10449 /* If top-line visibility has changed, give up. */
10450 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10451 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10454 /* Give up if old or new display is scrolled vertically. We could
10455 make this function handle this, but right now it doesn't. */
10456 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10457 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10460 /* The variable new_start now holds the new window start. The old
10461 start `start' can be determined from the current matrix. */
10462 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10463 start
= start_row
->start
.pos
;
10464 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10466 /* Clear the desired matrix for the display below. */
10467 clear_glyph_matrix (w
->desired_matrix
);
10469 if (CHARPOS (new_start
) <= CHARPOS (start
))
10473 /* Don't use this method if the display starts with an ellipsis
10474 displayed for invisible text. It's not easy to handle that case
10475 below, and it's certainly not worth the effort since this is
10476 not a frequent case. */
10477 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10480 IF_DEBUG (debug_method_add (w
, "twu1"));
10482 /* Display up to a row that can be reused. The variable
10483 last_text_row is set to the last row displayed that displays
10484 text. Note that it.vpos == 0 if or if not there is a
10485 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10486 start_display (&it
, w
, new_start
);
10487 first_row_y
= it
.current_y
;
10488 w
->cursor
.vpos
= -1;
10489 last_text_row
= last_reused_text_row
= NULL
;
10491 while (it
.current_y
< it
.last_visible_y
10492 && IT_CHARPOS (it
) < CHARPOS (start
)
10493 && !fonts_changed_p
)
10494 if (display_line (&it
))
10495 last_text_row
= it
.glyph_row
- 1;
10497 /* A value of current_y < last_visible_y means that we stopped
10498 at the previous window start, which in turn means that we
10499 have at least one reusable row. */
10500 if (it
.current_y
< it
.last_visible_y
)
10502 /* IT.vpos always starts from 0; it counts text lines. */
10503 nrows_scrolled
= it
.vpos
;
10505 /* Find PT if not already found in the lines displayed. */
10506 if (w
->cursor
.vpos
< 0)
10508 int dy
= it
.current_y
- first_row_y
;
10510 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10511 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10513 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10514 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10516 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10517 dy
, nrows_scrolled
);
10521 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10527 /* Give up if point was not found. This shouldn't
10528 happen often; not more often than with try_window
10530 if (w
->cursor
.vpos
< 0)
10532 clear_glyph_matrix (w
->desired_matrix
);
10537 /* Scroll the display. Do it before the current matrix is
10538 changed. The problem here is that update has not yet
10539 run, i.e. part of the current matrix is not up to date.
10540 scroll_run_hook will clear the cursor, and use the
10541 current matrix to get the height of the row the cursor is
10543 run
.current_y
= first_row_y
;
10544 run
.desired_y
= it
.current_y
;
10545 run
.height
= it
.last_visible_y
- it
.current_y
;
10547 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10550 rif
->update_window_begin_hook (w
);
10551 rif
->clear_mouse_face (w
);
10552 rif
->scroll_run_hook (w
, &run
);
10553 rif
->update_window_end_hook (w
, 0, 0);
10557 /* Shift current matrix down by nrows_scrolled lines. */
10558 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10559 rotate_matrix (w
->current_matrix
,
10561 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10564 /* Disable lines that must be updated. */
10565 for (i
= 0; i
< it
.vpos
; ++i
)
10566 (start_row
+ i
)->enabled_p
= 0;
10568 /* Re-compute Y positions. */
10569 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10570 max_y
= it
.last_visible_y
;
10571 for (row
= start_row
+ nrows_scrolled
;
10575 row
->y
= it
.current_y
;
10577 if (row
->y
< min_y
)
10578 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10579 else if (row
->y
+ row
->height
> max_y
)
10580 row
->visible_height
10581 = row
->height
- (row
->y
+ row
->height
- max_y
);
10583 row
->visible_height
= row
->height
;
10585 it
.current_y
+= row
->height
;
10587 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10588 last_reused_text_row
= row
;
10589 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10593 /* Disable lines in the current matrix which are now
10594 below the window. */
10595 for (++row
; row
< bottom_row
; ++row
)
10596 row
->enabled_p
= 0;
10599 /* Update window_end_pos etc.; last_reused_text_row is the last
10600 reused row from the current matrix containing text, if any.
10601 The value of last_text_row is the last displayed line
10602 containing text. */
10603 if (last_reused_text_row
)
10605 w
->window_end_bytepos
10606 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10608 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10610 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10611 w
->current_matrix
));
10613 else if (last_text_row
)
10615 w
->window_end_bytepos
10616 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10618 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10620 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10624 /* This window must be completely empty. */
10625 w
->window_end_bytepos
= 0;
10626 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10628 w
->window_end_valid
= Qnil
;
10630 /* Update hint: don't try scrolling again in update_window. */
10631 w
->desired_matrix
->no_scrolling_p
= 1;
10634 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10638 else if (CHARPOS (new_start
) > CHARPOS (start
))
10640 struct glyph_row
*pt_row
, *row
;
10641 struct glyph_row
*first_reusable_row
;
10642 struct glyph_row
*first_row_to_display
;
10644 int yb
= window_text_bottom_y (w
);
10646 /* Find the row starting at new_start, if there is one. Don't
10647 reuse a partially visible line at the end. */
10648 first_reusable_row
= start_row
;
10649 while (first_reusable_row
->enabled_p
10650 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10651 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10652 < CHARPOS (new_start
)))
10653 ++first_reusable_row
;
10655 /* Give up if there is no row to reuse. */
10656 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10657 || !first_reusable_row
->enabled_p
10658 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10659 != CHARPOS (new_start
)))
10662 /* We can reuse fully visible rows beginning with
10663 first_reusable_row to the end of the window. Set
10664 first_row_to_display to the first row that cannot be reused.
10665 Set pt_row to the row containing point, if there is any. */
10667 for (first_row_to_display
= first_reusable_row
;
10668 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10669 ++first_row_to_display
)
10671 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10672 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10673 pt_row
= first_row_to_display
;
10676 /* Start displaying at the start of first_row_to_display. */
10677 xassert (first_row_to_display
->y
< yb
);
10678 init_to_row_start (&it
, w
, first_row_to_display
);
10680 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10682 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10684 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10685 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10687 /* Display lines beginning with first_row_to_display in the
10688 desired matrix. Set last_text_row to the last row displayed
10689 that displays text. */
10690 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10691 if (pt_row
== NULL
)
10692 w
->cursor
.vpos
= -1;
10693 last_text_row
= NULL
;
10694 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10695 if (display_line (&it
))
10696 last_text_row
= it
.glyph_row
- 1;
10698 /* Give up If point isn't in a row displayed or reused. */
10699 if (w
->cursor
.vpos
< 0)
10701 clear_glyph_matrix (w
->desired_matrix
);
10705 /* If point is in a reused row, adjust y and vpos of the cursor
10709 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10710 w
->current_matrix
);
10711 w
->cursor
.y
-= first_reusable_row
->y
;
10714 /* Scroll the display. */
10715 run
.current_y
= first_reusable_row
->y
;
10716 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10717 run
.height
= it
.last_visible_y
- run
.current_y
;
10718 dy
= run
.current_y
- run
.desired_y
;
10722 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10724 rif
->update_window_begin_hook (w
);
10725 rif
->clear_mouse_face (w
);
10726 rif
->scroll_run_hook (w
, &run
);
10727 rif
->update_window_end_hook (w
, 0, 0);
10731 /* Adjust Y positions of reused rows. */
10732 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10733 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10734 max_y
= it
.last_visible_y
;
10735 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10738 if (row
->y
< min_y
)
10739 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10740 else if (row
->y
+ row
->height
> max_y
)
10741 row
->visible_height
10742 = row
->height
- (row
->y
+ row
->height
- max_y
);
10744 row
->visible_height
= row
->height
;
10747 /* Scroll the current matrix. */
10748 xassert (nrows_scrolled
> 0);
10749 rotate_matrix (w
->current_matrix
,
10751 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10754 /* Disable rows not reused. */
10755 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
10756 row
->enabled_p
= 0;
10758 /* Adjust window end. A null value of last_text_row means that
10759 the window end is in reused rows which in turn means that
10760 only its vpos can have changed. */
10763 w
->window_end_bytepos
10764 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10766 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10768 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10773 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10776 w
->window_end_valid
= Qnil
;
10777 w
->desired_matrix
->no_scrolling_p
= 1;
10780 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10790 /************************************************************************
10791 Window redisplay reusing current matrix when buffer has changed
10792 ************************************************************************/
10794 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10795 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10797 static struct glyph_row
*
10798 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10799 struct glyph_row
*));
10802 /* Return the last row in MATRIX displaying text. If row START is
10803 non-null, start searching with that row. IT gives the dimensions
10804 of the display. Value is null if matrix is empty; otherwise it is
10805 a pointer to the row found. */
10807 static struct glyph_row
*
10808 find_last_row_displaying_text (matrix
, it
, start
)
10809 struct glyph_matrix
*matrix
;
10811 struct glyph_row
*start
;
10813 struct glyph_row
*row
, *row_found
;
10815 /* Set row_found to the last row in IT->w's current matrix
10816 displaying text. The loop looks funny but think of partially
10819 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10820 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10822 xassert (row
->enabled_p
);
10824 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10833 /* Return the last row in the current matrix of W that is not affected
10834 by changes at the start of current_buffer that occurred since the
10835 last time W was redisplayed. Value is null if no such row exists.
10837 The global variable beg_unchanged has to contain the number of
10838 bytes unchanged at the start of current_buffer. BEG +
10839 beg_unchanged is the buffer position of the first changed byte in
10840 current_buffer. Characters at positions < BEG + beg_unchanged are
10841 at the same buffer positions as they were when the current matrix
10844 static struct glyph_row
*
10845 find_last_unchanged_at_beg_row (w
)
10848 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10849 struct glyph_row
*row
;
10850 struct glyph_row
*row_found
= NULL
;
10851 int yb
= window_text_bottom_y (w
);
10853 /* Find the last row displaying unchanged text. */
10854 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10855 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10856 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10858 if (/* If row ends before first_changed_pos, it is unchanged,
10859 except in some case. */
10860 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10861 /* When row ends in ZV and we write at ZV it is not
10863 && !row
->ends_at_zv_p
10864 /* When first_changed_pos is the end of a continued line,
10865 row is not unchanged because it may be no longer
10867 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10868 && row
->continued_p
))
10871 /* Stop if last visible row. */
10872 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10882 /* Find the first glyph row in the current matrix of W that is not
10883 affected by changes at the end of current_buffer since the last
10884 time the window was redisplayed. Return in *DELTA the number of
10885 chars by which buffer positions in unchanged text at the end of
10886 current_buffer must be adjusted. Return in *DELTA_BYTES the
10887 corresponding number of bytes. Value is null if no such row
10888 exists, i.e. all rows are affected by changes. */
10890 static struct glyph_row
*
10891 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10893 int *delta
, *delta_bytes
;
10895 struct glyph_row
*row
;
10896 struct glyph_row
*row_found
= NULL
;
10898 *delta
= *delta_bytes
= 0;
10900 /* Display must not have been paused, otherwise the current matrix
10901 is not up to date. */
10902 if (NILP (w
->window_end_valid
))
10905 /* A value of window_end_pos >= END_UNCHANGED means that the window
10906 end is in the range of changed text. If so, there is no
10907 unchanged row at the end of W's current matrix. */
10908 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10911 /* Set row to the last row in W's current matrix displaying text. */
10912 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10914 /* If matrix is entirely empty, no unchanged row exists. */
10915 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10917 /* The value of row is the last glyph row in the matrix having a
10918 meaningful buffer position in it. The end position of row
10919 corresponds to window_end_pos. This allows us to translate
10920 buffer positions in the current matrix to current buffer
10921 positions for characters not in changed text. */
10922 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10923 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10924 int last_unchanged_pos
, last_unchanged_pos_old
;
10925 struct glyph_row
*first_text_row
10926 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10928 *delta
= Z
- Z_old
;
10929 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10931 /* Set last_unchanged_pos to the buffer position of the last
10932 character in the buffer that has not been changed. Z is the
10933 index + 1 of the last byte in current_buffer, i.e. by
10934 subtracting end_unchanged we get the index of the last
10935 unchanged character, and we have to add BEG to get its buffer
10937 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10938 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10940 /* Search backward from ROW for a row displaying a line that
10941 starts at a minimum position >= last_unchanged_pos_old. */
10942 for (; row
> first_text_row
; --row
)
10944 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10947 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10952 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10959 /* Make sure that glyph rows in the current matrix of window W
10960 reference the same glyph memory as corresponding rows in the
10961 frame's frame matrix. This function is called after scrolling W's
10962 current matrix on a terminal frame in try_window_id and
10963 try_window_reusing_current_matrix. */
10966 sync_frame_with_window_matrix_rows (w
)
10969 struct frame
*f
= XFRAME (w
->frame
);
10970 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10972 /* Preconditions: W must be a leaf window and full-width. Its frame
10973 must have a frame matrix. */
10974 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10975 xassert (WINDOW_FULL_WIDTH_P (w
));
10976 xassert (!FRAME_WINDOW_P (f
));
10978 /* If W is a full-width window, glyph pointers in W's current matrix
10979 have, by definition, to be the same as glyph pointers in the
10980 corresponding frame matrix. */
10981 window_row
= w
->current_matrix
->rows
;
10982 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10983 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10984 while (window_row
< window_row_end
)
10988 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10989 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10991 /* Disable frame rows whose corresponding window rows have
10992 been disabled in try_window_id. */
10993 if (!window_row
->enabled_p
)
10994 frame_row
->enabled_p
= 0;
10996 ++window_row
, ++frame_row
;
11001 /* Find the glyph row in window W containing CHARPOS. Consider all
11002 rows between START and END (not inclusive). END null means search
11003 all rows to the end of the display area of W. Value is the row
11004 containing CHARPOS or null. */
11006 static struct glyph_row
*
11007 row_containing_pos (w
, charpos
, start
, end
)
11010 struct glyph_row
*start
, *end
;
11012 struct glyph_row
*row
= start
;
11015 /* If we happen to start on a header-line, skip that. */
11016 if (row
->mode_line_p
)
11019 if ((end
&& row
>= end
) || !row
->enabled_p
)
11022 last_y
= window_text_bottom_y (w
);
11024 while ((end
== NULL
|| row
< end
)
11025 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11026 /* The end position of a row equals the start
11027 position of the next row. If CHARPOS is there, we
11028 would rather display it in the next line, except
11029 when this line ends in ZV. */
11030 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11031 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11032 || !row
->ends_at_zv_p
)))
11033 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11036 /* Give up if CHARPOS not found. */
11037 if ((end
&& row
>= end
)
11038 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11039 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11046 /* Try to redisplay window W by reusing its existing display. W's
11047 current matrix must be up to date when this function is called,
11048 i.e. window_end_valid must not be nil.
11052 1 if display has been updated
11053 0 if otherwise unsuccessful
11054 -1 if redisplay with same window start is known not to succeed
11056 The following steps are performed:
11058 1. Find the last row in the current matrix of W that is not
11059 affected by changes at the start of current_buffer. If no such row
11062 2. Find the first row in W's current matrix that is not affected by
11063 changes at the end of current_buffer. Maybe there is no such row.
11065 3. Display lines beginning with the row + 1 found in step 1 to the
11066 row found in step 2 or, if step 2 didn't find a row, to the end of
11069 4. If cursor is not known to appear on the window, give up.
11071 5. If display stopped at the row found in step 2, scroll the
11072 display and current matrix as needed.
11074 6. Maybe display some lines at the end of W, if we must. This can
11075 happen under various circumstances, like a partially visible line
11076 becoming fully visible, or because newly displayed lines are displayed
11077 in smaller font sizes.
11079 7. Update W's window end information. */
11081 /* Check that window end is what we expect it to be. */
11087 struct frame
*f
= XFRAME (w
->frame
);
11088 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11089 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11090 struct glyph_row
*last_unchanged_at_beg_row
;
11091 struct glyph_row
*first_unchanged_at_end_row
;
11092 struct glyph_row
*row
;
11093 struct glyph_row
*bottom_row
;
11096 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11097 struct text_pos start_pos
;
11099 int first_unchanged_at_end_vpos
= 0;
11100 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11101 struct text_pos start
;
11103 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11105 /* Check pre-conditions. Window end must be valid, otherwise
11106 the current matrix would not be up to date. */
11107 xassert (!NILP (w
->window_end_valid
));
11108 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
11109 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
11111 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11112 only if buffer has really changed. The reason is that the gap is
11113 initially at Z for freshly visited files. The code below would
11114 set end_unchanged to 0 in that case. */
11115 if (MODIFF
> SAVE_MODIFF
11116 /* This seems to happen sometimes after saving a buffer. */
11117 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11119 if (GPT
- BEG
< BEG_UNCHANGED
)
11120 BEG_UNCHANGED
= GPT
- BEG
;
11121 if (Z
- GPT
< END_UNCHANGED
)
11122 END_UNCHANGED
= Z
- GPT
;
11125 /* If window starts after a line end, and the last change is in
11126 front of that newline, then changes don't affect the display.
11127 This case happens with stealth-fontification. Note that although
11128 the display is unchanged, glyph positions in the matrix have to
11129 be adjusted, of course. */
11130 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11131 if (CHARPOS (start
) > BEGV
11132 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
11133 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
11134 && PT
< MATRIX_ROW_END_CHARPOS (row
))
11136 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11137 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
11141 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11142 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
11144 increment_matrix_positions (w
->current_matrix
,
11145 MATRIX_ROW_VPOS (r0
, current_matrix
),
11146 MATRIX_ROW_VPOS (r1
, current_matrix
),
11147 delta
, delta_bytes
);
11150 #if 0 /* If changes are all in front of the window start, the
11151 distance of the last displayed glyph from Z hasn't
11154 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11155 w
->window_end_bytepos
11156 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11159 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11163 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11167 /* Return quickly if changes are all below what is displayed in the
11168 window, and if PT is in the window. */
11169 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
11170 && PT
< MATRIX_ROW_END_CHARPOS (row
))
11172 /* We have to update window end positions because the buffer's
11173 size has changed. */
11175 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11176 w
->window_end_bytepos
11177 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11179 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11180 row
= row_containing_pos (w
, PT
, row
, NULL
);
11181 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11185 /* Check that window start agrees with the start of the first glyph
11186 row in its current matrix. Check this after we know the window
11187 start is not in changed text, otherwise positions would not be
11189 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11190 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11193 /* Compute the position at which we have to start displaying new
11194 lines. Some of the lines at the top of the window might be
11195 reusable because they are not displaying changed text. Find the
11196 last row in W's current matrix not affected by changes at the
11197 start of current_buffer. Value is null if changes start in the
11198 first line of window. */
11199 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11200 if (last_unchanged_at_beg_row
)
11202 /* Avoid starting to display in the moddle of a character, a TAB
11203 for instance. This is easier than to set up the iterator
11204 exactly, and it's not a frequent case, so the additional
11205 effort wouldn't really pay off. */
11206 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11207 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11208 --last_unchanged_at_beg_row
;
11210 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11213 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
11214 start_pos
= it
.current
.pos
;
11216 /* Start displaying new lines in the desired matrix at the same
11217 vpos we would use in the current matrix, i.e. below
11218 last_unchanged_at_beg_row. */
11219 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11221 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11222 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11224 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11228 /* There are no reusable lines at the start of the window.
11229 Start displaying in the first line. */
11230 start_display (&it
, w
, start
);
11231 start_pos
= it
.current
.pos
;
11234 /* Find the first row that is not affected by changes at the end of
11235 the buffer. Value will be null if there is no unchanged row, in
11236 which case we must redisplay to the end of the window. delta
11237 will be set to the value by which buffer positions beginning with
11238 first_unchanged_at_end_row have to be adjusted due to text
11240 first_unchanged_at_end_row
11241 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11242 IF_DEBUG (debug_delta
= delta
);
11243 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11245 /* Set stop_pos to the buffer position up to which we will have to
11246 display new lines. If first_unchanged_at_end_row != NULL, this
11247 is the buffer position of the start of the line displayed in that
11248 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11249 that we don't stop at a buffer position. */
11251 if (first_unchanged_at_end_row
)
11253 xassert (last_unchanged_at_beg_row
== NULL
11254 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11256 /* If this is a continuation line, move forward to the next one
11257 that isn't. Changes in lines above affect this line.
11258 Caution: this may move first_unchanged_at_end_row to a row
11259 not displaying text. */
11260 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11261 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11262 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11263 < it
.last_visible_y
))
11264 ++first_unchanged_at_end_row
;
11266 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11267 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11268 >= it
.last_visible_y
))
11269 first_unchanged_at_end_row
= NULL
;
11272 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11274 first_unchanged_at_end_vpos
11275 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11276 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11279 else if (last_unchanged_at_beg_row
== NULL
)
11285 /* Either there is no unchanged row at the end, or the one we have
11286 now displays text. This is a necessary condition for the window
11287 end pos calculation at the end of this function. */
11288 xassert (first_unchanged_at_end_row
== NULL
11289 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11291 debug_last_unchanged_at_beg_vpos
11292 = (last_unchanged_at_beg_row
11293 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11295 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11297 #endif /* GLYPH_DEBUG != 0 */
11300 /* Display new lines. Set last_text_row to the last new line
11301 displayed which has text on it, i.e. might end up as being the
11302 line where the window_end_vpos is. */
11303 w
->cursor
.vpos
= -1;
11304 last_text_row
= NULL
;
11305 overlay_arrow_seen
= 0;
11306 while (it
.current_y
< it
.last_visible_y
11307 && !fonts_changed_p
11308 && (first_unchanged_at_end_row
== NULL
11309 || IT_CHARPOS (it
) < stop_pos
))
11311 if (display_line (&it
))
11312 last_text_row
= it
.glyph_row
- 1;
11315 if (fonts_changed_p
)
11319 /* Compute differences in buffer positions, y-positions etc. for
11320 lines reused at the bottom of the window. Compute what we can
11322 if (first_unchanged_at_end_row
11323 /* No lines reused because we displayed everything up to the
11324 bottom of the window. */
11325 && it
.current_y
< it
.last_visible_y
)
11328 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11330 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11331 run
.current_y
= first_unchanged_at_end_row
->y
;
11332 run
.desired_y
= run
.current_y
+ dy
;
11333 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11337 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11338 first_unchanged_at_end_row
= NULL
;
11340 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11343 /* Find the cursor if not already found. We have to decide whether
11344 PT will appear on this window (it sometimes doesn't, but this is
11345 not a very frequent case.) This decision has to be made before
11346 the current matrix is altered. A value of cursor.vpos < 0 means
11347 that PT is either in one of the lines beginning at
11348 first_unchanged_at_end_row or below the window. Don't care for
11349 lines that might be displayed later at the window end; as
11350 mentioned, this is not a frequent case. */
11351 if (w
->cursor
.vpos
< 0)
11353 /* Cursor in unchanged rows at the top? */
11354 if (PT
< CHARPOS (start_pos
)
11355 && last_unchanged_at_beg_row
)
11357 row
= row_containing_pos (w
, PT
,
11358 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11359 last_unchanged_at_beg_row
+ 1);
11361 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11364 /* Start from first_unchanged_at_end_row looking for PT. */
11365 else if (first_unchanged_at_end_row
)
11367 row
= row_containing_pos (w
, PT
- delta
,
11368 first_unchanged_at_end_row
, NULL
);
11370 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11371 delta_bytes
, dy
, dvpos
);
11374 /* Give up if cursor was not found. */
11375 if (w
->cursor
.vpos
< 0)
11377 clear_glyph_matrix (w
->desired_matrix
);
11382 /* Don't let the cursor end in the scroll margins. */
11384 int this_scroll_margin
, cursor_height
;
11386 this_scroll_margin
= max (0, scroll_margin
);
11387 this_scroll_margin
= min (this_scroll_margin
,
11388 XFASTINT (w
->height
) / 4);
11389 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11390 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11392 if ((w
->cursor
.y
< this_scroll_margin
11393 && CHARPOS (start
) > BEGV
)
11394 /* Don't take scroll margin into account at the bottom because
11395 old redisplay didn't do it either. */
11396 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11398 w
->cursor
.vpos
= -1;
11399 clear_glyph_matrix (w
->desired_matrix
);
11404 /* Scroll the display. Do it before changing the current matrix so
11405 that xterm.c doesn't get confused about where the cursor glyph is
11407 if (dy
&& run
.height
)
11411 if (FRAME_WINDOW_P (f
))
11413 rif
->update_window_begin_hook (w
);
11414 rif
->clear_mouse_face (w
);
11415 rif
->scroll_run_hook (w
, &run
);
11416 rif
->update_window_end_hook (w
, 0, 0);
11420 /* Terminal frame. In this case, dvpos gives the number of
11421 lines to scroll by; dvpos < 0 means scroll up. */
11422 int first_unchanged_at_end_vpos
11423 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11424 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11425 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
11427 /* Perform the operation on the screen. */
11430 /* Scroll last_unchanged_at_beg_row to the end of the
11431 window down dvpos lines. */
11432 set_terminal_window (end
);
11434 /* On dumb terminals delete dvpos lines at the end
11435 before inserting dvpos empty lines. */
11436 if (!scroll_region_ok
)
11437 ins_del_lines (end
- dvpos
, -dvpos
);
11439 /* Insert dvpos empty lines in front of
11440 last_unchanged_at_beg_row. */
11441 ins_del_lines (from
, dvpos
);
11443 else if (dvpos
< 0)
11445 /* Scroll up last_unchanged_at_beg_vpos to the end of
11446 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11447 set_terminal_window (end
);
11449 /* Delete dvpos lines in front of
11450 last_unchanged_at_beg_vpos. ins_del_lines will set
11451 the cursor to the given vpos and emit |dvpos| delete
11453 ins_del_lines (from
+ dvpos
, dvpos
);
11455 /* On a dumb terminal insert dvpos empty lines at the
11457 if (!scroll_region_ok
)
11458 ins_del_lines (end
+ dvpos
, -dvpos
);
11461 set_terminal_window (0);
11467 /* Shift reused rows of the current matrix to the right position.
11468 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11470 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11471 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11474 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11475 bottom_vpos
, dvpos
);
11476 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11479 else if (dvpos
> 0)
11481 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11482 bottom_vpos
, dvpos
);
11483 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11484 first_unchanged_at_end_vpos
+ dvpos
, 0);
11487 /* For frame-based redisplay, make sure that current frame and window
11488 matrix are in sync with respect to glyph memory. */
11489 if (!FRAME_WINDOW_P (f
))
11490 sync_frame_with_window_matrix_rows (w
);
11492 /* Adjust buffer positions in reused rows. */
11494 increment_matrix_positions (current_matrix
,
11495 first_unchanged_at_end_vpos
+ dvpos
,
11496 bottom_vpos
, delta
, delta_bytes
);
11498 /* Adjust Y positions. */
11500 shift_glyph_matrix (w
, current_matrix
,
11501 first_unchanged_at_end_vpos
+ dvpos
,
11504 if (first_unchanged_at_end_row
)
11505 first_unchanged_at_end_row
+= dvpos
;
11507 /* If scrolling up, there may be some lines to display at the end of
11509 last_text_row_at_end
= NULL
;
11512 /* Set last_row to the glyph row in the current matrix where the
11513 window end line is found. It has been moved up or down in
11514 the matrix by dvpos. */
11515 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11516 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11518 /* If last_row is the window end line, it should display text. */
11519 xassert (last_row
->displays_text_p
);
11521 /* If window end line was partially visible before, begin
11522 displaying at that line. Otherwise begin displaying with the
11523 line following it. */
11524 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11526 init_to_row_start (&it
, w
, last_row
);
11527 it
.vpos
= last_vpos
;
11528 it
.current_y
= last_row
->y
;
11532 init_to_row_end (&it
, w
, last_row
);
11533 it
.vpos
= 1 + last_vpos
;
11534 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11538 /* We may start in a continuation line. If so, we have to get
11539 the right continuation_lines_width and current_x. */
11540 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11541 it
.hpos
= it
.current_x
= 0;
11543 /* Display the rest of the lines at the window end. */
11544 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11545 while (it
.current_y
< it
.last_visible_y
11546 && !fonts_changed_p
)
11548 /* Is it always sure that the display agrees with lines in
11549 the current matrix? I don't think so, so we mark rows
11550 displayed invalid in the current matrix by setting their
11551 enabled_p flag to zero. */
11552 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11553 if (display_line (&it
))
11554 last_text_row_at_end
= it
.glyph_row
- 1;
11558 /* Update window_end_pos and window_end_vpos. */
11559 if (first_unchanged_at_end_row
11560 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11561 && !last_text_row_at_end
)
11563 /* Window end line if one of the preserved rows from the current
11564 matrix. Set row to the last row displaying text in current
11565 matrix starting at first_unchanged_at_end_row, after
11567 xassert (first_unchanged_at_end_row
->displays_text_p
);
11568 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11569 first_unchanged_at_end_row
);
11570 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11572 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11573 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11575 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11577 else if (last_text_row_at_end
)
11580 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11581 w
->window_end_bytepos
11582 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11584 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11586 else if (last_text_row
)
11588 /* We have displayed either to the end of the window or at the
11589 end of the window, i.e. the last row with text is to be found
11590 in the desired matrix. */
11592 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11593 w
->window_end_bytepos
11594 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11596 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11598 else if (first_unchanged_at_end_row
== NULL
11599 && last_text_row
== NULL
11600 && last_text_row_at_end
== NULL
)
11602 /* Displayed to end of window, but no line containing text was
11603 displayed. Lines were deleted at the end of the window. */
11605 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11607 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
11608 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11609 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
11610 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11611 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
11614 w
->window_end_vpos
= make_number (vpos
);
11619 #if 0 /* This leads to problems, for instance when the cursor is
11620 at ZV, and the cursor line displays no text. */
11621 /* Disable rows below what's displayed in the window. This makes
11622 debugging easier. */
11623 enable_glyph_matrix_rows (current_matrix
,
11624 XFASTINT (w
->window_end_vpos
) + 1,
11628 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11629 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11631 /* Record that display has not been completed. */
11632 w
->window_end_valid
= Qnil
;
11633 w
->desired_matrix
->no_scrolling_p
= 1;
11639 /***********************************************************************
11640 More debugging support
11641 ***********************************************************************/
11645 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11646 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11647 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11650 /* Dump the contents of glyph matrix MATRIX on stderr.
11652 GLYPHS 0 means don't show glyph contents.
11653 GLYPHS 1 means show glyphs in short form
11654 GLYPHS > 1 means show glyphs in long form. */
11657 dump_glyph_matrix (matrix
, glyphs
)
11658 struct glyph_matrix
*matrix
;
11662 for (i
= 0; i
< matrix
->nrows
; ++i
)
11663 dump_glyph_row (matrix
, i
, glyphs
);
11667 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
11668 the glyph row and area where the glyph comes from. */
11671 dump_glyph (row
, glyph
, area
)
11672 struct glyph_row
*row
;
11673 struct glyph
*glyph
;
11676 if (glyph
->type
== CHAR_GLYPH
)
11679 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11680 glyph
- row
->glyphs
[TEXT_AREA
],
11683 (BUFFERP (glyph
->object
)
11685 : (STRINGP (glyph
->object
)
11688 glyph
->pixel_width
,
11690 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11694 glyph
->left_box_line_p
,
11695 glyph
->right_box_line_p
);
11697 else if (glyph
->type
== STRETCH_GLYPH
)
11700 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11701 glyph
- row
->glyphs
[TEXT_AREA
],
11704 (BUFFERP (glyph
->object
)
11706 : (STRINGP (glyph
->object
)
11709 glyph
->pixel_width
,
11713 glyph
->left_box_line_p
,
11714 glyph
->right_box_line_p
);
11716 else if (glyph
->type
== IMAGE_GLYPH
)
11719 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11720 glyph
- row
->glyphs
[TEXT_AREA
],
11723 (BUFFERP (glyph
->object
)
11725 : (STRINGP (glyph
->object
)
11728 glyph
->pixel_width
,
11732 glyph
->left_box_line_p
,
11733 glyph
->right_box_line_p
);
11738 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11739 GLYPHS 0 means don't show glyph contents.
11740 GLYPHS 1 means show glyphs in short form
11741 GLYPHS > 1 means show glyphs in long form. */
11744 dump_glyph_row (matrix
, vpos
, glyphs
)
11745 struct glyph_matrix
*matrix
;
11748 struct glyph_row
*row
;
11750 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11753 row
= MATRIX_ROW (matrix
, vpos
);
11757 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
11758 fprintf (stderr
, "=======================================================================\n");
11760 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11761 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11762 row
- matrix
->rows
,
11763 MATRIX_ROW_START_CHARPOS (row
),
11764 MATRIX_ROW_END_CHARPOS (row
),
11765 row
->used
[TEXT_AREA
],
11766 row
->contains_overlapping_glyphs_p
,
11769 row
->truncated_on_left_p
,
11770 row
->truncated_on_right_p
,
11771 row
->overlay_arrow_p
,
11773 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11774 row
->displays_text_p
,
11777 row
->ends_in_middle_of_char_p
,
11778 row
->starts_in_middle_of_char_p
,
11784 row
->visible_height
,
11787 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
11788 row
->end
.overlay_string_index
);
11789 fprintf (stderr
, "%9d %5d\n",
11790 CHARPOS (row
->start
.string_pos
),
11791 CHARPOS (row
->end
.string_pos
));
11792 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11793 row
->end
.dpvec_index
);
11800 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11802 struct glyph
*glyph
= row
->glyphs
[area
];
11803 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
11805 /* Glyph for a line end in text. */
11806 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
11809 if (glyph
< glyph_end
)
11810 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11812 for (; glyph
< glyph_end
; ++glyph
)
11813 dump_glyph (row
, glyph
, area
);
11816 else if (glyphs
== 1)
11820 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11822 char *s
= (char *) alloca (row
->used
[area
] + 1);
11825 for (i
= 0; i
< row
->used
[area
]; ++i
)
11827 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
11828 if (glyph
->type
== CHAR_GLYPH
11829 && glyph
->u
.ch
< 0x80
11830 && glyph
->u
.ch
>= ' ')
11831 s
[i
] = glyph
->u
.ch
;
11837 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
11843 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11844 Sdump_glyph_matrix
, 0, 1, "p",
11845 "Dump the current matrix of the selected window to stderr.\n\
11846 Shows contents of glyph row structures. With non-nil\n\
11847 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show\n\
11848 glyphs in short form, otherwise show glyphs in long form.")
11850 Lisp_Object glyphs
;
11852 struct window
*w
= XWINDOW (selected_window
);
11853 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11855 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11856 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11857 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11858 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11859 fprintf (stderr
, "=============================================\n");
11860 dump_glyph_matrix (w
->current_matrix
,
11861 NILP (glyphs
) ? 0 : XINT (glyphs
));
11866 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
11867 "Dump glyph row ROW to stderr.\n\
11868 GLYPH 0 means don't dump glyphs.\n\
11869 GLYPH 1 means dump glyphs in short form.\n\
11870 GLYPH > 1 or omitted means dump glyphs in long form.")
11872 Lisp_Object row
, glyphs
;
11874 CHECK_NUMBER (row
, 0);
11875 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
,
11877 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
11882 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
11883 "Dump glyph row ROW of the tool-bar of the current frame to stderr.\n\
11884 GLYPH 0 means don't dump glyphs.\n\
11885 GLYPH 1 means dump glyphs in short form.\n\
11886 GLYPH > 1 or omitted means dump glyphs in long form.")
11888 Lisp_Object row
, glyphs
;
11890 struct frame
*sf
= SELECTED_FRAME ();
11891 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)->current_matrix
);
11892 dump_glyph_row (m
, XINT (row
), INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
11897 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11898 Strace_redisplay_toggle
, 0, 0, "",
11899 "Toggle tracing of redisplay.")
11902 trace_redisplay_p
= !trace_redisplay_p
;
11907 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11908 "Print STRING to stderr.")
11910 Lisp_Object string
;
11912 CHECK_STRING (string
, 0);
11913 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11917 #endif /* GLYPH_DEBUG */
11921 /***********************************************************************
11922 Building Desired Matrix Rows
11923 ***********************************************************************/
11925 /* Return a temporary glyph row holding the glyphs of an overlay
11926 arrow. Only used for non-window-redisplay windows. */
11928 static struct glyph_row
*
11929 get_overlay_arrow_glyph_row (w
)
11932 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11933 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11934 struct buffer
*old
= current_buffer
;
11935 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11936 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11937 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11941 int n_glyphs_before
;
11943 set_buffer_temp (buffer
);
11944 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11945 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11946 SET_TEXT_POS (it
.position
, 0, 0);
11948 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11950 while (p
< arrow_end
)
11952 Lisp_Object face
, ilisp
;
11954 /* Get the next character. */
11956 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11958 it
.c
= *p
, it
.len
= 1;
11961 /* Get its face. */
11962 ilisp
= make_number (p
- arrow_string
);
11963 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11964 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11966 /* Compute its width, get its glyphs. */
11967 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11968 SET_TEXT_POS (it
.position
, -1, -1);
11969 PRODUCE_GLYPHS (&it
);
11971 /* If this character doesn't fit any more in the line, we have
11972 to remove some glyphs. */
11973 if (it
.current_x
> it
.last_visible_x
)
11975 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11980 set_buffer_temp (old
);
11981 return it
.glyph_row
;
11985 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11986 glyphs are only inserted for terminal frames since we can't really
11987 win with truncation glyphs when partially visible glyphs are
11988 involved. Which glyphs to insert is determined by
11989 produce_special_glyphs. */
11992 insert_left_trunc_glyphs (it
)
11995 struct it truncate_it
;
11996 struct glyph
*from
, *end
, *to
, *toend
;
11998 xassert (!FRAME_WINDOW_P (it
->f
));
12000 /* Get the truncation glyphs. */
12002 truncate_it
.current_x
= 0;
12003 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12004 truncate_it
.glyph_row
= &scratch_glyph_row
;
12005 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12006 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12007 truncate_it
.object
= make_number (0);
12008 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12010 /* Overwrite glyphs from IT with truncation glyphs. */
12011 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12012 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12013 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12014 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12019 /* There may be padding glyphs left over. Overwrite them too. */
12020 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12022 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12028 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12032 /* Compute the pixel height and width of IT->glyph_row.
12034 Most of the time, ascent and height of a display line will be equal
12035 to the max_ascent and max_height values of the display iterator
12036 structure. This is not the case if
12038 1. We hit ZV without displaying anything. In this case, max_ascent
12039 and max_height will be zero.
12041 2. We have some glyphs that don't contribute to the line height.
12042 (The glyph row flag contributes_to_line_height_p is for future
12043 pixmap extensions).
12045 The first case is easily covered by using default values because in
12046 these cases, the line height does not really matter, except that it
12047 must not be zero. */
12050 compute_line_metrics (it
)
12053 struct glyph_row
*row
= it
->glyph_row
;
12056 if (FRAME_WINDOW_P (it
->f
))
12058 int i
, header_line_height
;
12060 /* The line may consist of one space only, that was added to
12061 place the cursor on it. If so, the row's height hasn't been
12063 if (row
->height
== 0)
12065 if (it
->max_ascent
+ it
->max_descent
== 0)
12066 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12067 row
->ascent
= it
->max_ascent
;
12068 row
->height
= it
->max_ascent
+ it
->max_descent
;
12069 row
->phys_ascent
= it
->max_phys_ascent
;
12070 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12073 /* Compute the width of this line. */
12074 row
->pixel_width
= row
->x
;
12075 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12076 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12078 xassert (row
->pixel_width
>= 0);
12079 xassert (row
->ascent
>= 0 && row
->height
> 0);
12081 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12082 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12084 /* If first line's physical ascent is larger than its logical
12085 ascent, use the physical ascent, and make the row taller.
12086 This makes accented characters fully visible. */
12087 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12088 && row
->phys_ascent
> row
->ascent
)
12090 row
->height
+= row
->phys_ascent
- row
->ascent
;
12091 row
->ascent
= row
->phys_ascent
;
12094 /* Compute how much of the line is visible. */
12095 row
->visible_height
= row
->height
;
12097 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12098 if (row
->y
< header_line_height
)
12099 row
->visible_height
-= header_line_height
- row
->y
;
12102 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12103 if (row
->y
+ row
->height
> max_y
)
12104 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12109 row
->pixel_width
= row
->used
[TEXT_AREA
];
12110 row
->ascent
= row
->phys_ascent
= 0;
12111 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12114 /* Compute a hash code for this row. */
12116 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12117 for (i
= 0; i
< row
->used
[area
]; ++i
)
12118 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12119 + row
->glyphs
[area
][i
].u
.val
12120 + row
->glyphs
[area
][i
].face_id
12121 + row
->glyphs
[area
][i
].padding_p
12122 + (row
->glyphs
[area
][i
].type
<< 2));
12124 it
->max_ascent
= it
->max_descent
= 0;
12125 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12129 /* Append one space to the glyph row of iterator IT if doing a
12130 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12131 space have the default face, otherwise let it have the same face as
12132 IT->face_id. Value is non-zero if a space was added.
12134 This function is called to make sure that there is always one glyph
12135 at the end of a glyph row that the cursor can be set on under
12136 window-systems. (If there weren't such a glyph we would not know
12137 how wide and tall a box cursor should be displayed).
12139 At the same time this space let's a nicely handle clearing to the
12140 end of the line if the row ends in italic text. */
12143 append_space (it
, default_face_p
)
12145 int default_face_p
;
12147 if (FRAME_WINDOW_P (it
->f
))
12149 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12151 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12152 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12154 /* Save some values that must not be changed.
12155 Must save IT->c and IT->len because otherwise
12156 ITERATOR_AT_END_P wouldn't work anymore after
12157 append_space has been called. */
12158 enum display_element_type saved_what
= it
->what
;
12159 int saved_c
= it
->c
, saved_len
= it
->len
;
12160 int saved_x
= it
->current_x
;
12161 int saved_face_id
= it
->face_id
;
12162 struct text_pos saved_pos
;
12163 Lisp_Object saved_object
;
12166 saved_object
= it
->object
;
12167 saved_pos
= it
->position
;
12169 it
->what
= IT_CHARACTER
;
12170 bzero (&it
->position
, sizeof it
->position
);
12171 it
->object
= make_number (0);
12175 if (default_face_p
)
12176 it
->face_id
= DEFAULT_FACE_ID
;
12177 else if (it
->face_before_selective_p
)
12178 it
->face_id
= it
->saved_face_id
;
12179 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12180 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12182 PRODUCE_GLYPHS (it
);
12184 it
->current_x
= saved_x
;
12185 it
->object
= saved_object
;
12186 it
->position
= saved_pos
;
12187 it
->what
= saved_what
;
12188 it
->face_id
= saved_face_id
;
12189 it
->len
= saved_len
;
12199 /* Extend the face of the last glyph in the text area of IT->glyph_row
12200 to the end of the display line. Called from display_line.
12201 If the glyph row is empty, add a space glyph to it so that we
12202 know the face to draw. Set the glyph row flag fill_line_p. */
12205 extend_face_to_end_of_line (it
)
12209 struct frame
*f
= it
->f
;
12211 /* If line is already filled, do nothing. */
12212 if (it
->current_x
>= it
->last_visible_x
)
12215 /* Face extension extends the background and box of IT->face_id
12216 to the end of the line. If the background equals the background
12217 of the frame, we don't have to do anything. */
12218 if (it
->face_before_selective_p
)
12219 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12221 face
= FACE_FROM_ID (f
, it
->face_id
);
12223 if (FRAME_WINDOW_P (f
)
12224 && face
->box
== FACE_NO_BOX
12225 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12229 /* Set the glyph row flag indicating that the face of the last glyph
12230 in the text area has to be drawn to the end of the text area. */
12231 it
->glyph_row
->fill_line_p
= 1;
12233 /* If current character of IT is not ASCII, make sure we have the
12234 ASCII face. This will be automatically undone the next time
12235 get_next_display_element returns a multibyte character. Note
12236 that the character will always be single byte in unibyte text. */
12237 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12239 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12242 if (FRAME_WINDOW_P (f
))
12244 /* If the row is empty, add a space with the current face of IT,
12245 so that we know which face to draw. */
12246 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12248 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12249 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12250 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12255 /* Save some values that must not be changed. */
12256 int saved_x
= it
->current_x
;
12257 struct text_pos saved_pos
;
12258 Lisp_Object saved_object
;
12259 enum display_element_type saved_what
= it
->what
;
12260 int saved_face_id
= it
->face_id
;
12262 saved_object
= it
->object
;
12263 saved_pos
= it
->position
;
12265 it
->what
= IT_CHARACTER
;
12266 bzero (&it
->position
, sizeof it
->position
);
12267 it
->object
= make_number (0);
12270 it
->face_id
= face
->id
;
12272 PRODUCE_GLYPHS (it
);
12274 while (it
->current_x
<= it
->last_visible_x
)
12275 PRODUCE_GLYPHS (it
);
12277 /* Don't count these blanks really. It would let us insert a left
12278 truncation glyph below and make us set the cursor on them, maybe. */
12279 it
->current_x
= saved_x
;
12280 it
->object
= saved_object
;
12281 it
->position
= saved_pos
;
12282 it
->what
= saved_what
;
12283 it
->face_id
= saved_face_id
;
12288 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12289 trailing whitespace. */
12292 trailing_whitespace_p (charpos
)
12295 int bytepos
= CHAR_TO_BYTE (charpos
);
12298 while (bytepos
< ZV_BYTE
12299 && (c
= FETCH_CHAR (bytepos
),
12300 c
== ' ' || c
== '\t'))
12303 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12305 if (bytepos
!= PT_BYTE
)
12312 /* Highlight trailing whitespace, if any, in ROW. */
12315 highlight_trailing_whitespace (f
, row
)
12317 struct glyph_row
*row
;
12319 int used
= row
->used
[TEXT_AREA
];
12323 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12324 struct glyph
*glyph
= start
+ used
- 1;
12326 /* Skip over glyphs inserted to display the cursor at the
12327 end of a line, for extending the face of the last glyph
12328 to the end of the line on terminals, and for truncation
12329 and continuation glyphs. */
12330 while (glyph
>= start
12331 && glyph
->type
== CHAR_GLYPH
12332 && INTEGERP (glyph
->object
))
12335 /* If last glyph is a space or stretch, and it's trailing
12336 whitespace, set the face of all trailing whitespace glyphs in
12337 IT->glyph_row to `trailing-whitespace'. */
12339 && BUFFERP (glyph
->object
)
12340 && (glyph
->type
== STRETCH_GLYPH
12341 || (glyph
->type
== CHAR_GLYPH
12342 && glyph
->u
.ch
== ' '))
12343 && trailing_whitespace_p (glyph
->charpos
))
12345 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12347 while (glyph
>= start
12348 && BUFFERP (glyph
->object
)
12349 && (glyph
->type
== STRETCH_GLYPH
12350 || (glyph
->type
== CHAR_GLYPH
12351 && glyph
->u
.ch
== ' ')))
12352 (glyph
--)->face_id
= face_id
;
12358 /* Value is non-zero if glyph row ROW in window W should be
12359 used to hold the cursor. */
12362 cursor_row_p (w
, row
)
12364 struct glyph_row
*row
;
12366 int cursor_row_p
= 1;
12368 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12370 /* If the row ends with a newline from a string, we don't want
12371 the cursor there (if the row is continued it doesn't end in a
12373 if (CHARPOS (row
->end
.string_pos
) >= 0
12374 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12375 cursor_row_p
= row
->continued_p
;
12377 /* If the row ends at ZV, display the cursor at the end of that
12378 row instead of at the start of the row below. */
12379 else if (row
->ends_at_zv_p
)
12385 return cursor_row_p
;
12389 /* Construct the glyph row IT->glyph_row in the desired matrix of
12390 IT->w from text at the current position of IT. See dispextern.h
12391 for an overview of struct it. Value is non-zero if
12392 IT->glyph_row displays text, as opposed to a line displaying ZV
12399 struct glyph_row
*row
= it
->glyph_row
;
12401 /* We always start displaying at hpos zero even if hscrolled. */
12402 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12404 /* We must not display in a row that's not a text row. */
12405 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12406 < it
->w
->desired_matrix
->nrows
);
12408 /* Is IT->w showing the region? */
12409 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12411 /* Clear the result glyph row and enable it. */
12412 prepare_desired_row (row
);
12414 row
->y
= it
->current_y
;
12415 row
->start
= it
->current
;
12416 row
->continuation_lines_width
= it
->continuation_lines_width
;
12417 row
->displays_text_p
= 1;
12418 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12419 it
->starts_in_middle_of_char_p
= 0;
12421 /* Arrange the overlays nicely for our purposes. Usually, we call
12422 display_line on only one line at a time, in which case this
12423 can't really hurt too much, or we call it on lines which appear
12424 one after another in the buffer, in which case all calls to
12425 recenter_overlay_lists but the first will be pretty cheap. */
12426 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12428 /* Move over display elements that are not visible because we are
12429 hscrolled. This may stop at an x-position < IT->first_visible_x
12430 if the first glyph is partially visible or if we hit a line end. */
12431 if (it
->current_x
< it
->first_visible_x
)
12432 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12433 MOVE_TO_POS
| MOVE_TO_X
);
12435 /* Get the initial row height. This is either the height of the
12436 text hscrolled, if there is any, or zero. */
12437 row
->ascent
= it
->max_ascent
;
12438 row
->height
= it
->max_ascent
+ it
->max_descent
;
12439 row
->phys_ascent
= it
->max_phys_ascent
;
12440 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12442 /* Loop generating characters. The loop is left with IT on the next
12443 character to display. */
12446 int n_glyphs_before
, hpos_before
, x_before
;
12448 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12450 /* Retrieve the next thing to display. Value is zero if end of
12452 if (!get_next_display_element (it
))
12454 /* Maybe add a space at the end of this line that is used to
12455 display the cursor there under X. Set the charpos of the
12456 first glyph of blank lines not corresponding to any text
12458 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12459 || row
->used
[TEXT_AREA
] == 0)
12461 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12462 row
->displays_text_p
= 0;
12464 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12465 row
->indicate_empty_line_p
= 1;
12468 it
->continuation_lines_width
= 0;
12469 row
->ends_at_zv_p
= 1;
12473 /* Now, get the metrics of what we want to display. This also
12474 generates glyphs in `row' (which is IT->glyph_row). */
12475 n_glyphs_before
= row
->used
[TEXT_AREA
];
12478 /* Remember the line height so far in case the next element doesn't
12479 fit on the line. */
12480 if (!it
->truncate_lines_p
)
12482 ascent
= it
->max_ascent
;
12483 descent
= it
->max_descent
;
12484 phys_ascent
= it
->max_phys_ascent
;
12485 phys_descent
= it
->max_phys_descent
;
12488 PRODUCE_GLYPHS (it
);
12490 /* If this display element was in marginal areas, continue with
12492 if (it
->area
!= TEXT_AREA
)
12494 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12495 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12496 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12497 row
->phys_height
= max (row
->phys_height
,
12498 it
->max_phys_ascent
+ it
->max_phys_descent
);
12499 set_iterator_to_next (it
, 1);
12503 /* Does the display element fit on the line? If we truncate
12504 lines, we should draw past the right edge of the window. If
12505 we don't truncate, we want to stop so that we can display the
12506 continuation glyph before the right margin. If lines are
12507 continued, there are two possible strategies for characters
12508 resulting in more than 1 glyph (e.g. tabs): Display as many
12509 glyphs as possible in this line and leave the rest for the
12510 continuation line, or display the whole element in the next
12511 line. Original redisplay did the former, so we do it also. */
12512 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12513 hpos_before
= it
->hpos
;
12516 if (/* Not a newline. */
12518 /* Glyphs produced fit entirely in the line. */
12519 && it
->current_x
< it
->last_visible_x
)
12521 it
->hpos
+= nglyphs
;
12522 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12523 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12524 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12525 row
->phys_height
= max (row
->phys_height
,
12526 it
->max_phys_ascent
+ it
->max_phys_descent
);
12527 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12528 row
->x
= x
- it
->first_visible_x
;
12533 struct glyph
*glyph
;
12535 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12537 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12538 new_x
= x
+ glyph
->pixel_width
;
12540 if (/* Lines are continued. */
12541 !it
->truncate_lines_p
12542 && (/* Glyph doesn't fit on the line. */
12543 new_x
> it
->last_visible_x
12544 /* Or it fits exactly on a window system frame. */
12545 || (new_x
== it
->last_visible_x
12546 && FRAME_WINDOW_P (it
->f
))))
12548 /* End of a continued line. */
12551 || (new_x
== it
->last_visible_x
12552 && FRAME_WINDOW_P (it
->f
)))
12554 /* Current glyph is the only one on the line or
12555 fits exactly on the line. We must continue
12556 the line because we can't draw the cursor
12557 after the glyph. */
12558 row
->continued_p
= 1;
12559 it
->current_x
= new_x
;
12560 it
->continuation_lines_width
+= new_x
;
12562 if (i
== nglyphs
- 1)
12563 set_iterator_to_next (it
, 1);
12565 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12566 && !FRAME_WINDOW_P (it
->f
))
12568 /* A padding glyph that doesn't fit on this line.
12569 This means the whole character doesn't fit
12571 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12573 /* Fill the rest of the row with continuation
12574 glyphs like in 20.x. */
12575 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12576 < row
->glyphs
[1 + TEXT_AREA
])
12577 produce_special_glyphs (it
, IT_CONTINUATION
);
12579 row
->continued_p
= 1;
12580 it
->current_x
= x_before
;
12581 it
->continuation_lines_width
+= x_before
;
12583 /* Restore the height to what it was before the
12584 element not fitting on the line. */
12585 it
->max_ascent
= ascent
;
12586 it
->max_descent
= descent
;
12587 it
->max_phys_ascent
= phys_ascent
;
12588 it
->max_phys_descent
= phys_descent
;
12592 /* Display element draws past the right edge of
12593 the window. Restore positions to values
12594 before the element. The next line starts
12595 with current_x before the glyph that could
12596 not be displayed, so that TAB works right. */
12597 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12599 /* Display continuation glyphs. */
12600 if (!FRAME_WINDOW_P (it
->f
))
12601 produce_special_glyphs (it
, IT_CONTINUATION
);
12602 row
->continued_p
= 1;
12605 it
->continuation_lines_width
+= x
;
12606 if (nglyphs
> 1 && i
> 0)
12608 row
->ends_in_middle_of_char_p
= 1;
12609 it
->starts_in_middle_of_char_p
= 1;
12612 /* Restore the height to what it was before the
12613 element not fitting on the line. */
12614 it
->max_ascent
= ascent
;
12615 it
->max_descent
= descent
;
12616 it
->max_phys_ascent
= phys_ascent
;
12617 it
->max_phys_descent
= phys_descent
;
12622 else if (new_x
> it
->first_visible_x
)
12624 /* Increment number of glyphs actually displayed. */
12627 if (x
< it
->first_visible_x
)
12628 /* Glyph is partially visible, i.e. row starts at
12629 negative X position. */
12630 row
->x
= x
- it
->first_visible_x
;
12634 /* Glyph is completely off the left margin of the
12635 window. This should not happen because of the
12636 move_it_in_display_line at the start of
12642 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12643 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12644 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12645 row
->phys_height
= max (row
->phys_height
,
12646 it
->max_phys_ascent
+ it
->max_phys_descent
);
12648 /* End of this display line if row is continued. */
12649 if (row
->continued_p
)
12653 /* Is this a line end? If yes, we're also done, after making
12654 sure that a non-default face is extended up to the right
12655 margin of the window. */
12656 if (ITERATOR_AT_END_OF_LINE_P (it
))
12658 int used_before
= row
->used
[TEXT_AREA
];
12660 /* Add a space at the end of the line that is used to
12661 display the cursor there. */
12662 append_space (it
, 0);
12664 /* Extend the face to the end of the line. */
12665 extend_face_to_end_of_line (it
);
12667 /* Make sure we have the position. */
12668 if (used_before
== 0)
12669 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12671 /* Consume the line end. This skips over invisible lines. */
12672 set_iterator_to_next (it
, 1);
12673 it
->continuation_lines_width
= 0;
12677 /* Proceed with next display element. Note that this skips
12678 over lines invisible because of selective display. */
12679 set_iterator_to_next (it
, 1);
12681 /* If we truncate lines, we are done when the last displayed
12682 glyphs reach past the right margin of the window. */
12683 if (it
->truncate_lines_p
12684 && (FRAME_WINDOW_P (it
->f
)
12685 ? (it
->current_x
>= it
->last_visible_x
)
12686 : (it
->current_x
> it
->last_visible_x
)))
12688 /* Maybe add truncation glyphs. */
12689 if (!FRAME_WINDOW_P (it
->f
))
12693 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
12694 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
12697 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
12699 row
->used
[TEXT_AREA
] = i
;
12700 produce_special_glyphs (it
, IT_TRUNCATION
);
12704 row
->truncated_on_right_p
= 1;
12705 it
->continuation_lines_width
= 0;
12706 reseat_at_next_visible_line_start (it
, 0);
12707 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12708 it
->hpos
= hpos_before
;
12709 it
->current_x
= x_before
;
12714 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12715 at the left window margin. */
12716 if (it
->first_visible_x
12717 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12719 if (!FRAME_WINDOW_P (it
->f
))
12720 insert_left_trunc_glyphs (it
);
12721 row
->truncated_on_left_p
= 1;
12724 /* If the start of this line is the overlay arrow-position, then
12725 mark this glyph row as the one containing the overlay arrow.
12726 This is clearly a mess with variable size fonts. It would be
12727 better to let it be displayed like cursors under X. */
12728 if (MARKERP (Voverlay_arrow_position
)
12729 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12730 && (MATRIX_ROW_START_CHARPOS (row
)
12731 == marker_position (Voverlay_arrow_position
))
12732 && STRINGP (Voverlay_arrow_string
)
12733 && ! overlay_arrow_seen
)
12735 /* Overlay arrow in window redisplay is a bitmap. */
12736 if (!FRAME_WINDOW_P (it
->f
))
12738 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12739 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12740 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12741 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12742 struct glyph
*p2
, *end
;
12744 /* Copy the arrow glyphs. */
12745 while (glyph
< arrow_end
)
12748 /* Throw away padding glyphs. */
12750 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12751 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12757 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12761 overlay_arrow_seen
= 1;
12762 row
->overlay_arrow_p
= 1;
12765 /* Compute pixel dimensions of this line. */
12766 compute_line_metrics (it
);
12768 /* Remember the position at which this line ends. */
12769 row
->end
= it
->current
;
12771 /* Maybe set the cursor. */
12772 if (it
->w
->cursor
.vpos
< 0
12773 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12774 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12775 && cursor_row_p (it
->w
, row
))
12776 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12778 /* Highlight trailing whitespace. */
12779 if (!NILP (Vshow_trailing_whitespace
))
12780 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12782 /* Prepare for the next line. This line starts horizontally at (X
12783 HPOS) = (0 0). Vertical positions are incremented. As a
12784 convenience for the caller, IT->glyph_row is set to the next
12786 it
->current_x
= it
->hpos
= 0;
12787 it
->current_y
+= row
->height
;
12790 return row
->displays_text_p
;
12795 /***********************************************************************
12797 ***********************************************************************/
12799 /* Redisplay the menu bar in the frame for window W.
12801 The menu bar of X frames that don't have X toolkit support is
12802 displayed in a special window W->frame->menu_bar_window.
12804 The menu bar of terminal frames is treated specially as far as
12805 glyph matrices are concerned. Menu bar lines are not part of
12806 windows, so the update is done directly on the frame matrix rows
12807 for the menu bar. */
12810 display_menu_bar (w
)
12813 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12818 /* Don't do all this for graphical frames. */
12820 if (!NILP (Vwindow_system
))
12823 #ifdef USE_X_TOOLKIT
12828 if (FRAME_MAC_P (f
))
12832 #ifdef USE_X_TOOLKIT
12833 xassert (!FRAME_WINDOW_P (f
));
12834 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12835 it
.first_visible_x
= 0;
12836 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12837 #else /* not USE_X_TOOLKIT */
12838 if (FRAME_WINDOW_P (f
))
12840 /* Menu bar lines are displayed in the desired matrix of the
12841 dummy window menu_bar_window. */
12842 struct window
*menu_w
;
12843 xassert (WINDOWP (f
->menu_bar_window
));
12844 menu_w
= XWINDOW (f
->menu_bar_window
);
12845 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12847 it
.first_visible_x
= 0;
12848 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12852 /* This is a TTY frame, i.e. character hpos/vpos are used as
12854 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12856 it
.first_visible_x
= 0;
12857 it
.last_visible_x
= FRAME_WIDTH (f
);
12859 #endif /* not USE_X_TOOLKIT */
12861 if (! mode_line_inverse_video
)
12862 /* Force the menu-bar to be displayed in the default face. */
12863 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
12865 /* Clear all rows of the menu bar. */
12866 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12868 struct glyph_row
*row
= it
.glyph_row
+ i
;
12869 clear_glyph_row (row
);
12870 row
->enabled_p
= 1;
12871 row
->full_width_p
= 1;
12874 /* Display all items of the menu bar. */
12875 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12876 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12878 Lisp_Object string
;
12880 /* Stop at nil string. */
12881 string
= AREF (items
, i
+ 1);
12885 /* Remember where item was displayed. */
12886 AREF (items
, i
+ 3) = make_number (it
.hpos
);
12888 /* Display the item, pad with one space. */
12889 if (it
.current_x
< it
.last_visible_x
)
12890 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12891 XSTRING (string
)->size
+ 1, 0, 0, -1);
12894 /* Fill out the line with spaces. */
12895 if (it
.current_x
< it
.last_visible_x
)
12896 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12898 /* Compute the total height of the lines. */
12899 compute_line_metrics (&it
);
12904 /***********************************************************************
12906 ***********************************************************************/
12908 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12909 FORCE is non-zero, redisplay mode lines unconditionally.
12910 Otherwise, redisplay only mode lines that are garbaged. Value is
12911 the number of windows whose mode lines were redisplayed. */
12914 redisplay_mode_lines (window
, force
)
12915 Lisp_Object window
;
12920 while (!NILP (window
))
12922 struct window
*w
= XWINDOW (window
);
12924 if (WINDOWP (w
->hchild
))
12925 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12926 else if (WINDOWP (w
->vchild
))
12927 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12929 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12930 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12932 Lisp_Object old_selected_frame
;
12933 struct text_pos lpoint
;
12934 struct buffer
*old
= current_buffer
;
12936 /* Set the window's buffer for the mode line display. */
12937 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12938 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12940 /* Point refers normally to the selected window. For any
12941 other window, set up appropriate value. */
12942 if (!EQ (window
, selected_window
))
12944 struct text_pos pt
;
12946 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12947 if (CHARPOS (pt
) < BEGV
)
12948 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12949 else if (CHARPOS (pt
) > (ZV
- 1))
12950 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12952 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12955 /* Temporarily set up the selected frame. */
12956 old_selected_frame
= selected_frame
;
12957 selected_frame
= w
->frame
;
12959 /* Display mode lines. */
12960 clear_glyph_matrix (w
->desired_matrix
);
12961 if (display_mode_lines (w
))
12964 w
->must_be_updated_p
= 1;
12967 /* Restore old settings. */
12968 selected_frame
= old_selected_frame
;
12969 set_buffer_internal_1 (old
);
12970 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12980 /* Display the mode and/or top line of window W. Value is the number
12981 of mode lines displayed. */
12984 display_mode_lines (w
)
12989 /* These will be set while the mode line specs are processed. */
12990 line_number_displayed
= 0;
12991 w
->column_number_displayed
= Qnil
;
12993 if (WINDOW_WANTS_MODELINE_P (w
))
12995 display_mode_line (w
, MODE_LINE_FACE_ID
,
12996 current_buffer
->mode_line_format
);
13000 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13002 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13003 current_buffer
->header_line_format
);
13011 /* Display mode or top line of window W. FACE_ID specifies which line
13012 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13013 FORMAT is the mode line format to display. Value is the pixel
13014 height of the mode line displayed. */
13017 display_mode_line (w
, face_id
, format
)
13019 enum face_id face_id
;
13020 Lisp_Object format
;
13025 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13026 prepare_desired_row (it
.glyph_row
);
13028 if (! mode_line_inverse_video
)
13029 /* Force the mode-line to be displayed in the default face. */
13030 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13032 /* Temporarily make frame's keyboard the current kboard so that
13033 kboard-local variables in the mode_line_format will get the right
13035 push_frame_kboard (it
.f
);
13036 display_mode_element (&it
, 0, 0, 0, format
);
13037 pop_frame_kboard ();
13039 /* Fill up with spaces. */
13040 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13042 compute_line_metrics (&it
);
13043 it
.glyph_row
->full_width_p
= 1;
13044 it
.glyph_row
->mode_line_p
= 1;
13045 it
.glyph_row
->inverse_p
= 0;
13046 it
.glyph_row
->continued_p
= 0;
13047 it
.glyph_row
->truncated_on_left_p
= 0;
13048 it
.glyph_row
->truncated_on_right_p
= 0;
13050 /* Make a 3D mode-line have a shadow at its right end. */
13051 face
= FACE_FROM_ID (it
.f
, face_id
);
13052 extend_face_to_end_of_line (&it
);
13053 if (face
->box
!= FACE_NO_BOX
)
13055 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13056 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13057 last
->right_box_line_p
= 1;
13060 return it
.glyph_row
->height
;
13064 /* Contribute ELT to the mode line for window IT->w. How it
13065 translates into text depends on its data type.
13067 IT describes the display environment in which we display, as usual.
13069 DEPTH is the depth in recursion. It is used to prevent
13070 infinite recursion here.
13072 FIELD_WIDTH is the number of characters the display of ELT should
13073 occupy in the mode line, and PRECISION is the maximum number of
13074 characters to display from ELT's representation. See
13075 display_string for details. *
13077 Returns the hpos of the end of the text generated by ELT. */
13080 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13083 int field_width
, precision
;
13086 int n
= 0, field
, prec
;
13094 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13098 /* A string: output it and check for %-constructs within it. */
13100 unsigned char *this = XSTRING (elt
)->data
;
13101 unsigned char *lisp_string
= this;
13103 while ((precision
<= 0 || n
< precision
)
13105 && (frame_title_ptr
13106 || it
->current_x
< it
->last_visible_x
))
13108 unsigned char *last
= this;
13110 /* Advance to end of string or next format specifier. */
13111 while ((c
= *this++) != '\0' && c
!= '%')
13114 if (this - 1 != last
)
13116 /* Output to end of string or up to '%'. Field width
13117 is length of string. Don't output more than
13118 PRECISION allows us. */
13120 prec
= strwidth (last
, this - last
);
13121 if (precision
> 0 && prec
> precision
- n
)
13122 prec
= precision
- n
;
13124 if (frame_title_ptr
)
13125 n
+= store_frame_title (last
, 0, prec
);
13127 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
13128 it
, 0, prec
, 0, -1);
13130 else /* c == '%' */
13132 unsigned char *percent_position
= this;
13134 /* Get the specified minimum width. Zero means
13137 while ((c
= *this++) >= '0' && c
<= '9')
13138 field
= field
* 10 + c
- '0';
13140 /* Don't pad beyond the total padding allowed. */
13141 if (field_width
- n
> 0 && field
> field_width
- n
)
13142 field
= field_width
- n
;
13144 /* Note that either PRECISION <= 0 or N < PRECISION. */
13145 prec
= precision
- n
;
13148 n
+= display_mode_element (it
, depth
, field
, prec
,
13149 Vglobal_mode_string
);
13152 unsigned char *spec
13153 = decode_mode_spec (it
->w
, c
, field
, prec
);
13155 if (frame_title_ptr
)
13156 n
+= store_frame_title (spec
, field
, prec
);
13160 = it
->glyph_row
->used
[TEXT_AREA
];
13162 = percent_position
- XSTRING (elt
)->data
;
13164 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
13165 field
, prec
, 0, -1);
13167 /* Assign to the glyphs written above the
13168 string where the `%x' came from, position
13172 struct glyph
*glyph
13173 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13177 for (i
= 0; i
< nwritten
; ++i
)
13179 glyph
[i
].object
= elt
;
13180 glyph
[i
].charpos
= charpos
;
13193 /* A symbol: process the value of the symbol recursively
13194 as if it appeared here directly. Avoid error if symbol void.
13195 Special case: if value of symbol is a string, output the string
13198 register Lisp_Object tem
;
13199 tem
= Fboundp (elt
);
13202 tem
= Fsymbol_value (elt
);
13203 /* If value is a string, output that string literally:
13204 don't check for % within it. */
13207 prec
= precision
- n
;
13208 if (frame_title_ptr
)
13209 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13211 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13214 else if (!EQ (tem
, elt
))
13216 /* Give up right away for nil or t. */
13226 register Lisp_Object car
, tem
;
13228 /* A cons cell: three distinct cases.
13229 If first element is a string or a cons, process all the elements
13230 and effectively concatenate them.
13231 If first element is a negative number, truncate displaying cdr to
13232 at most that many characters. If positive, pad (with spaces)
13233 to at least that many characters.
13234 If first element is a symbol, process the cadr or caddr recursively
13235 according to whether the symbol's value is non-nil or nil. */
13237 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13239 /* An element of the form (:eval FORM) means evaluate FORM
13240 and use the result as mode line elements. */
13241 struct gcpro gcpro1
;
13244 spec
= safe_eval (XCAR (XCDR (elt
)));
13246 n
+= display_mode_element (it
, depth
, field_width
- n
,
13247 precision
- n
, spec
);
13250 else if (SYMBOLP (car
))
13252 tem
= Fboundp (car
);
13256 /* elt is now the cdr, and we know it is a cons cell.
13257 Use its car if CAR has a non-nil value. */
13260 tem
= Fsymbol_value (car
);
13267 /* Symbol's value is nil (or symbol is unbound)
13268 Get the cddr of the original list
13269 and if possible find the caddr and use that. */
13273 else if (!CONSP (elt
))
13278 else if (INTEGERP (car
))
13280 register int lim
= XINT (car
);
13284 /* Negative int means reduce maximum width. */
13285 if (precision
<= 0)
13288 precision
= min (precision
, -lim
);
13292 /* Padding specified. Don't let it be more than
13293 current maximum. */
13295 lim
= min (precision
, lim
);
13297 /* If that's more padding than already wanted, queue it.
13298 But don't reduce padding already specified even if
13299 that is beyond the current truncation point. */
13300 field_width
= max (lim
, field_width
);
13304 else if (STRINGP (car
) || CONSP (car
))
13306 register int limit
= 50;
13307 /* Limit is to protect against circular lists. */
13310 && (precision
<= 0 || n
< precision
))
13312 n
+= display_mode_element (it
, depth
, field_width
- n
,
13313 precision
- n
, XCAR (elt
));
13322 if (frame_title_ptr
)
13323 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13325 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13326 precision
- n
, 0, 0);
13330 /* Pad to FIELD_WIDTH. */
13331 if (field_width
> 0 && n
< field_width
)
13333 if (frame_title_ptr
)
13334 n
+= store_frame_title ("", field_width
- n
, 0);
13336 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13344 /* Write a null-terminated, right justified decimal representation of
13345 the positive integer D to BUF using a minimal field width WIDTH. */
13348 pint2str (buf
, width
, d
)
13349 register char *buf
;
13350 register int width
;
13353 register char *p
= buf
;
13361 *p
++ = d
% 10 + '0';
13366 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13377 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13378 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13379 type of CODING_SYSTEM. Return updated pointer into BUF. */
13381 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13384 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13385 Lisp_Object coding_system
;
13386 register char *buf
;
13390 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13391 unsigned char *eol_str
;
13393 /* The EOL conversion we are using. */
13394 Lisp_Object eoltype
;
13396 val
= Fget (coding_system
, Qcoding_system
);
13399 if (!VECTORP (val
)) /* Not yet decided. */
13404 eoltype
= eol_mnemonic_undecided
;
13405 /* Don't mention EOL conversion if it isn't decided. */
13409 Lisp_Object eolvalue
;
13411 eolvalue
= Fget (coding_system
, Qeol_type
);
13414 *buf
++ = XFASTINT (AREF (val
, 1));
13418 /* The EOL conversion that is normal on this system. */
13420 if (NILP (eolvalue
)) /* Not yet decided. */
13421 eoltype
= eol_mnemonic_undecided
;
13422 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13423 eoltype
= eol_mnemonic_undecided
;
13424 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13425 eoltype
= (XFASTINT (eolvalue
) == 0
13426 ? eol_mnemonic_unix
13427 : (XFASTINT (eolvalue
) == 1
13428 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13434 /* Mention the EOL conversion if it is not the usual one. */
13435 if (STRINGP (eoltype
))
13437 eol_str
= XSTRING (eoltype
)->data
;
13438 eol_str_len
= XSTRING (eoltype
)->size
;
13440 else if (INTEGERP (eoltype
)
13441 && CHAR_VALID_P (XINT (eoltype
), 0))
13443 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13444 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13448 eol_str
= invalid_eol_type
;
13449 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13451 bcopy (eol_str
, buf
, eol_str_len
);
13452 buf
+= eol_str_len
;
13458 /* Return a string for the output of a mode line %-spec for window W,
13459 generated by character C. PRECISION >= 0 means don't return a
13460 string longer than that value. FIELD_WIDTH > 0 means pad the
13461 string returned with spaces to that value. */
13463 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13466 decode_mode_spec (w
, c
, field_width
, precision
)
13469 int field_width
, precision
;
13472 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13473 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13474 struct buffer
*b
= XBUFFER (w
->buffer
);
13481 if (!NILP (b
->read_only
))
13483 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13488 /* This differs from %* only for a modified read-only buffer. */
13489 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13491 if (!NILP (b
->read_only
))
13496 /* This differs from %* in ignoring read-only-ness. */
13497 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13509 if (command_loop_level
> 5)
13511 p
= decode_mode_spec_buf
;
13512 for (i
= 0; i
< command_loop_level
; i
++)
13515 return decode_mode_spec_buf
;
13523 if (command_loop_level
> 5)
13525 p
= decode_mode_spec_buf
;
13526 for (i
= 0; i
< command_loop_level
; i
++)
13529 return decode_mode_spec_buf
;
13536 /* Let lots_of_dashes be a string of infinite length. */
13537 if (field_width
<= 0
13538 || field_width
> sizeof (lots_of_dashes
))
13540 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13541 decode_mode_spec_buf
[i
] = '-';
13542 decode_mode_spec_buf
[i
] = '\0';
13543 return decode_mode_spec_buf
;
13546 return lots_of_dashes
;
13555 int col
= current_column ();
13556 w
->column_number_displayed
= make_number (col
);
13557 pint2str (decode_mode_spec_buf
, field_width
, col
);
13558 return decode_mode_spec_buf
;
13562 /* %F displays the frame name. */
13563 if (!NILP (f
->title
))
13564 return (char *) XSTRING (f
->title
)->data
;
13565 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13566 return (char *) XSTRING (f
->name
)->data
;
13575 int startpos
= XMARKER (w
->start
)->charpos
;
13576 int startpos_byte
= marker_byte_position (w
->start
);
13577 int line
, linepos
, linepos_byte
, topline
;
13579 int height
= XFASTINT (w
->height
);
13581 /* If we decided that this buffer isn't suitable for line numbers,
13582 don't forget that too fast. */
13583 if (EQ (w
->base_line_pos
, w
->buffer
))
13585 /* But do forget it, if the window shows a different buffer now. */
13586 else if (BUFFERP (w
->base_line_pos
))
13587 w
->base_line_pos
= Qnil
;
13589 /* If the buffer is very big, don't waste time. */
13590 if (INTEGERP (Vline_number_display_limit
)
13591 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13593 w
->base_line_pos
= Qnil
;
13594 w
->base_line_number
= Qnil
;
13598 if (!NILP (w
->base_line_number
)
13599 && !NILP (w
->base_line_pos
)
13600 && XFASTINT (w
->base_line_pos
) <= startpos
)
13602 line
= XFASTINT (w
->base_line_number
);
13603 linepos
= XFASTINT (w
->base_line_pos
);
13604 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13609 linepos
= BUF_BEGV (b
);
13610 linepos_byte
= BUF_BEGV_BYTE (b
);
13613 /* Count lines from base line to window start position. */
13614 nlines
= display_count_lines (linepos
, linepos_byte
,
13618 topline
= nlines
+ line
;
13620 /* Determine a new base line, if the old one is too close
13621 or too far away, or if we did not have one.
13622 "Too close" means it's plausible a scroll-down would
13623 go back past it. */
13624 if (startpos
== BUF_BEGV (b
))
13626 w
->base_line_number
= make_number (topline
);
13627 w
->base_line_pos
= make_number (BUF_BEGV (b
));
13629 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13630 || linepos
== BUF_BEGV (b
))
13632 int limit
= BUF_BEGV (b
);
13633 int limit_byte
= BUF_BEGV_BYTE (b
);
13635 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13637 if (startpos
- distance
> limit
)
13639 limit
= startpos
- distance
;
13640 limit_byte
= CHAR_TO_BYTE (limit
);
13643 nlines
= display_count_lines (startpos
, startpos_byte
,
13645 - (height
* 2 + 30),
13647 /* If we couldn't find the lines we wanted within
13648 line_number_display_limit_width chars per line,
13649 give up on line numbers for this window. */
13650 if (position
== limit_byte
&& limit
== startpos
- distance
)
13652 w
->base_line_pos
= w
->buffer
;
13653 w
->base_line_number
= Qnil
;
13657 w
->base_line_number
= make_number (topline
- nlines
);
13658 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
13661 /* Now count lines from the start pos to point. */
13662 nlines
= display_count_lines (startpos
, startpos_byte
,
13663 PT_BYTE
, PT
, &junk
);
13665 /* Record that we did display the line number. */
13666 line_number_displayed
= 1;
13668 /* Make the string to show. */
13669 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13670 return decode_mode_spec_buf
;
13673 char* p
= decode_mode_spec_buf
;
13674 int pad
= field_width
- 2;
13680 return decode_mode_spec_buf
;
13686 obj
= b
->mode_name
;
13690 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13696 int pos
= marker_position (w
->start
);
13697 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13699 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13701 if (pos
<= BUF_BEGV (b
))
13706 else if (pos
<= BUF_BEGV (b
))
13710 if (total
> 1000000)
13711 /* Do it differently for a large value, to avoid overflow. */
13712 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13714 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13715 /* We can't normally display a 3-digit number,
13716 so get us a 2-digit number that is close. */
13719 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13720 return decode_mode_spec_buf
;
13724 /* Display percentage of size above the bottom of the screen. */
13727 int toppos
= marker_position (w
->start
);
13728 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13729 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13731 if (botpos
>= BUF_ZV (b
))
13733 if (toppos
<= BUF_BEGV (b
))
13740 if (total
> 1000000)
13741 /* Do it differently for a large value, to avoid overflow. */
13742 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13744 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13745 /* We can't normally display a 3-digit number,
13746 so get us a 2-digit number that is close. */
13749 if (toppos
<= BUF_BEGV (b
))
13750 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13752 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13753 return decode_mode_spec_buf
;
13758 /* status of process */
13759 obj
= Fget_buffer_process (w
->buffer
);
13761 return "no process";
13762 #ifdef subprocesses
13763 obj
= Fsymbol_name (Fprocess_status (obj
));
13767 case 't': /* indicate TEXT or BINARY */
13768 #ifdef MODE_LINE_BINARY_TEXT
13769 return MODE_LINE_BINARY_TEXT (b
);
13775 /* coding-system (not including end-of-line format) */
13777 /* coding-system (including end-of-line type) */
13779 int eol_flag
= (c
== 'Z');
13780 char *p
= decode_mode_spec_buf
;
13782 if (! FRAME_WINDOW_P (f
))
13784 /* No need to mention EOL here--the terminal never needs
13785 to do EOL conversion. */
13786 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13787 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13789 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13792 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13793 #ifdef subprocesses
13794 obj
= Fget_buffer_process (Fcurrent_buffer ());
13795 if (PROCESSP (obj
))
13797 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13799 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13802 #endif /* subprocesses */
13805 return decode_mode_spec_buf
;
13810 return (char *) XSTRING (obj
)->data
;
13816 /* Count up to COUNT lines starting from START / START_BYTE.
13817 But don't go beyond LIMIT_BYTE.
13818 Return the number of lines thus found (always nonnegative).
13820 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13823 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13824 int start
, start_byte
, limit_byte
, count
;
13827 register unsigned char *cursor
;
13828 unsigned char *base
;
13830 register int ceiling
;
13831 register unsigned char *ceiling_addr
;
13832 int orig_count
= count
;
13834 /* If we are not in selective display mode,
13835 check only for newlines. */
13836 int selective_display
= (!NILP (current_buffer
->selective_display
)
13837 && !INTEGERP (current_buffer
->selective_display
));
13841 while (start_byte
< limit_byte
)
13843 ceiling
= BUFFER_CEILING_OF (start_byte
);
13844 ceiling
= min (limit_byte
- 1, ceiling
);
13845 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13846 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13849 if (selective_display
)
13850 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13853 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13856 if (cursor
!= ceiling_addr
)
13860 start_byte
+= cursor
- base
+ 1;
13861 *byte_pos_ptr
= start_byte
;
13865 if (++cursor
== ceiling_addr
)
13871 start_byte
+= cursor
- base
;
13876 while (start_byte
> limit_byte
)
13878 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13879 ceiling
= max (limit_byte
, ceiling
);
13880 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13881 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13884 if (selective_display
)
13885 while (--cursor
!= ceiling_addr
13886 && *cursor
!= '\n' && *cursor
!= 015)
13889 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13892 if (cursor
!= ceiling_addr
)
13896 start_byte
+= cursor
- base
+ 1;
13897 *byte_pos_ptr
= start_byte
;
13898 /* When scanning backwards, we should
13899 not count the newline posterior to which we stop. */
13900 return - orig_count
- 1;
13906 /* Here we add 1 to compensate for the last decrement
13907 of CURSOR, which took it past the valid range. */
13908 start_byte
+= cursor
- base
+ 1;
13912 *byte_pos_ptr
= limit_byte
;
13915 return - orig_count
+ count
;
13916 return orig_count
- count
;
13922 /***********************************************************************
13924 ***********************************************************************/
13926 /* Display a NUL-terminated string, starting with index START.
13928 If STRING is non-null, display that C string. Otherwise, the Lisp
13929 string LISP_STRING is displayed.
13931 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13932 FACE_STRING. Display STRING or LISP_STRING with the face at
13933 FACE_STRING_POS in FACE_STRING:
13935 Display the string in the environment given by IT, but use the
13936 standard display table, temporarily.
13938 FIELD_WIDTH is the minimum number of output glyphs to produce.
13939 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13940 with spaces. If STRING has more characters, more than FIELD_WIDTH
13941 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13943 PRECISION is the maximum number of characters to output from
13944 STRING. PRECISION < 0 means don't truncate the string.
13946 This is roughly equivalent to printf format specifiers:
13948 FIELD_WIDTH PRECISION PRINTF
13949 ----------------------------------------
13955 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13956 display them, and < 0 means obey the current buffer's value of
13957 enable_multibyte_characters.
13959 Value is the number of glyphs produced. */
13962 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13963 start
, it
, field_width
, precision
, max_x
, multibyte
)
13964 unsigned char *string
;
13965 Lisp_Object lisp_string
;
13966 Lisp_Object face_string
;
13967 int face_string_pos
;
13970 int field_width
, precision
, max_x
;
13973 int hpos_at_start
= it
->hpos
;
13974 int saved_face_id
= it
->face_id
;
13975 struct glyph_row
*row
= it
->glyph_row
;
13977 /* Initialize the iterator IT for iteration over STRING beginning
13978 with index START. */
13979 reseat_to_string (it
, string
, lisp_string
, start
,
13980 precision
, field_width
, multibyte
);
13982 /* If displaying STRING, set up the face of the iterator
13983 from LISP_STRING, if that's given. */
13984 if (STRINGP (face_string
))
13990 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13991 0, it
->region_beg_charpos
,
13992 it
->region_end_charpos
,
13993 &endptr
, it
->base_face_id
, 0);
13994 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13995 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13998 /* Set max_x to the maximum allowed X position. Don't let it go
13999 beyond the right edge of the window. */
14001 max_x
= it
->last_visible_x
;
14003 max_x
= min (max_x
, it
->last_visible_x
);
14005 /* Skip over display elements that are not visible. because IT->w is
14007 if (it
->current_x
< it
->first_visible_x
)
14008 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14009 MOVE_TO_POS
| MOVE_TO_X
);
14011 row
->ascent
= it
->max_ascent
;
14012 row
->height
= it
->max_ascent
+ it
->max_descent
;
14013 row
->phys_ascent
= it
->max_phys_ascent
;
14014 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14016 /* This condition is for the case that we are called with current_x
14017 past last_visible_x. */
14018 while (it
->current_x
< max_x
)
14020 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14022 /* Get the next display element. */
14023 if (!get_next_display_element (it
))
14026 /* Produce glyphs. */
14027 x_before
= it
->current_x
;
14028 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14029 PRODUCE_GLYPHS (it
);
14031 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14034 while (i
< nglyphs
)
14036 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14038 if (!it
->truncate_lines_p
14039 && x
+ glyph
->pixel_width
> max_x
)
14041 /* End of continued line or max_x reached. */
14042 if (CHAR_GLYPH_PADDING_P (*glyph
))
14044 /* A wide character is unbreakable. */
14045 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14046 it
->current_x
= x_before
;
14050 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14055 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14057 /* Glyph is at least partially visible. */
14059 if (x
< it
->first_visible_x
)
14060 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14064 /* Glyph is off the left margin of the display area.
14065 Should not happen. */
14069 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14070 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14071 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14072 row
->phys_height
= max (row
->phys_height
,
14073 it
->max_phys_ascent
+ it
->max_phys_descent
);
14074 x
+= glyph
->pixel_width
;
14078 /* Stop if max_x reached. */
14082 /* Stop at line ends. */
14083 if (ITERATOR_AT_END_OF_LINE_P (it
))
14085 it
->continuation_lines_width
= 0;
14089 set_iterator_to_next (it
, 1);
14091 /* Stop if truncating at the right edge. */
14092 if (it
->truncate_lines_p
14093 && it
->current_x
>= it
->last_visible_x
)
14095 /* Add truncation mark, but don't do it if the line is
14096 truncated at a padding space. */
14097 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14099 if (!FRAME_WINDOW_P (it
->f
))
14103 if (it
->current_x
> it
->last_visible_x
)
14105 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14106 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14108 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14110 row
->used
[TEXT_AREA
] = i
;
14111 produce_special_glyphs (it
, IT_TRUNCATION
);
14114 produce_special_glyphs (it
, IT_TRUNCATION
);
14116 it
->glyph_row
->truncated_on_right_p
= 1;
14122 /* Maybe insert a truncation at the left. */
14123 if (it
->first_visible_x
14124 && IT_CHARPOS (*it
) > 0)
14126 if (!FRAME_WINDOW_P (it
->f
))
14127 insert_left_trunc_glyphs (it
);
14128 it
->glyph_row
->truncated_on_left_p
= 1;
14131 it
->face_id
= saved_face_id
;
14133 /* Value is number of columns displayed. */
14134 return it
->hpos
- hpos_at_start
;
14139 /* This is like a combination of memq and assq. Return 1 if PROPVAL
14140 appears as an element of LIST or as the car of an element of LIST.
14141 If PROPVAL is a list, compare each element against LIST in that
14142 way, and return 1 if any element of PROPVAL is found in LIST.
14143 Otherwise return 0. This function cannot quit. */
14146 invisible_p (propval
, list
)
14147 register Lisp_Object propval
;
14150 register Lisp_Object tail
, proptail
;
14152 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14154 register Lisp_Object tem
;
14156 if (EQ (propval
, tem
))
14158 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14162 if (CONSP (propval
))
14164 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14166 Lisp_Object propelt
;
14167 propelt
= XCAR (proptail
);
14168 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14170 register Lisp_Object tem
;
14172 if (EQ (propelt
, tem
))
14174 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14184 /* Return 1 if PROPVAL appears as the car of an element of LIST and
14185 the cdr of that element is non-nil. If PROPVAL is a list, check
14186 each element of PROPVAL in that way, and the first time some
14187 element is found, return 1 if the cdr of that element is non-nil.
14188 Otherwise return 0. This function cannot quit. */
14191 invisible_ellipsis_p (propval
, list
)
14192 register Lisp_Object propval
;
14195 register Lisp_Object tail
, proptail
;
14197 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14199 register Lisp_Object tem
;
14201 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14202 return ! NILP (XCDR (tem
));
14205 if (CONSP (propval
))
14206 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14208 Lisp_Object propelt
;
14209 propelt
= XCAR (proptail
);
14210 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14212 register Lisp_Object tem
;
14214 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14215 return ! NILP (XCDR (tem
));
14224 /***********************************************************************
14226 ***********************************************************************/
14231 Vwith_echo_area_save_vector
= Qnil
;
14232 staticpro (&Vwith_echo_area_save_vector
);
14234 Vmessage_stack
= Qnil
;
14235 staticpro (&Vmessage_stack
);
14237 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14238 staticpro (&Qinhibit_redisplay
);
14241 defsubr (&Sdump_glyph_matrix
);
14242 defsubr (&Sdump_glyph_row
);
14243 defsubr (&Sdump_tool_bar_row
);
14244 defsubr (&Strace_redisplay_toggle
);
14245 defsubr (&Strace_to_stderr
);
14247 #ifdef HAVE_WINDOW_SYSTEM
14248 defsubr (&Stool_bar_lines_needed
);
14251 staticpro (&Qmenu_bar_update_hook
);
14252 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14254 staticpro (&Qoverriding_terminal_local_map
);
14255 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14257 staticpro (&Qoverriding_local_map
);
14258 Qoverriding_local_map
= intern ("overriding-local-map");
14260 staticpro (&Qwindow_scroll_functions
);
14261 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14263 staticpro (&Qredisplay_end_trigger_functions
);
14264 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14266 staticpro (&Qinhibit_point_motion_hooks
);
14267 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14269 QCdata
= intern (":data");
14270 staticpro (&QCdata
);
14271 Qdisplay
= intern ("display");
14272 staticpro (&Qdisplay
);
14273 Qspace_width
= intern ("space-width");
14274 staticpro (&Qspace_width
);
14275 Qraise
= intern ("raise");
14276 staticpro (&Qraise
);
14277 Qspace
= intern ("space");
14278 staticpro (&Qspace
);
14279 Qmargin
= intern ("margin");
14280 staticpro (&Qmargin
);
14281 Qleft_margin
= intern ("left-margin");
14282 staticpro (&Qleft_margin
);
14283 Qright_margin
= intern ("right-margin");
14284 staticpro (&Qright_margin
);
14285 Qalign_to
= intern ("align-to");
14286 staticpro (&Qalign_to
);
14287 QCalign_to
= intern (":align-to");
14288 staticpro (&QCalign_to
);
14289 Qrelative_width
= intern ("relative-width");
14290 staticpro (&Qrelative_width
);
14291 QCrelative_width
= intern (":relative-width");
14292 staticpro (&QCrelative_width
);
14293 QCrelative_height
= intern (":relative-height");
14294 staticpro (&QCrelative_height
);
14295 QCeval
= intern (":eval");
14296 staticpro (&QCeval
);
14297 Qwhen
= intern ("when");
14298 staticpro (&Qwhen
);
14299 QCfile
= intern (":file");
14300 staticpro (&QCfile
);
14301 Qfontified
= intern ("fontified");
14302 staticpro (&Qfontified
);
14303 Qfontification_functions
= intern ("fontification-functions");
14304 staticpro (&Qfontification_functions
);
14305 Qtrailing_whitespace
= intern ("trailing-whitespace");
14306 staticpro (&Qtrailing_whitespace
);
14307 Qimage
= intern ("image");
14308 staticpro (&Qimage
);
14309 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14310 staticpro (&Qmessage_truncate_lines
);
14311 Qgrow_only
= intern ("grow-only");
14312 staticpro (&Qgrow_only
);
14313 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14314 staticpro (&Qinhibit_menubar_update
);
14315 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14316 staticpro (&Qinhibit_eval_during_redisplay
);
14318 last_arrow_position
= Qnil
;
14319 last_arrow_string
= Qnil
;
14320 staticpro (&last_arrow_position
);
14321 staticpro (&last_arrow_string
);
14323 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14324 staticpro (&echo_buffer
[0]);
14325 staticpro (&echo_buffer
[1]);
14327 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14328 staticpro (&echo_area_buffer
[0]);
14329 staticpro (&echo_area_buffer
[1]);
14331 Vmessages_buffer_name
= build_string ("*Messages*");
14332 staticpro (&Vmessages_buffer_name
);
14334 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14335 "Non-nil means highlight trailing whitespace.\n\
14336 The face used for trailing whitespace is `trailing-whitespace'.");
14337 Vshow_trailing_whitespace
= Qnil
;
14339 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14340 "Non-nil means don't actually do any redisplay.\n\
14341 This is used for internal purposes.");
14342 Vinhibit_redisplay
= Qnil
;
14344 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14345 "String (or mode line construct) included (normally) in `mode-line-format'.");
14346 Vglobal_mode_string
= Qnil
;
14348 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14349 "Marker for where to display an arrow on top of the buffer text.\n\
14350 This must be the beginning of a line in order to work.\n\
14351 See also `overlay-arrow-string'.");
14352 Voverlay_arrow_position
= Qnil
;
14354 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14355 "String to display as an arrow. See also `overlay-arrow-position'.");
14356 Voverlay_arrow_string
= Qnil
;
14358 DEFVAR_INT ("scroll-step", &scroll_step
,
14359 "*The number of lines to try scrolling a window by when point moves out.\n\
14360 If that fails to bring point back on frame, point is centered instead.\n\
14361 If this is zero, point is always centered after it moves off frame.\n\
14362 If you want scrolling to always be a line at a time, you should set\n\
14363 `scroll-conservatively' to a large value rather than set this to 1.");
14365 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14366 "*Scroll up to this many lines, to bring point back on screen.\n\
14367 A value of zero means to scroll the text to center point vertically\n\
14369 scroll_conservatively
= 0;
14371 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14372 "*Number of lines of margin at the top and bottom of a window.\n\
14373 Recenter the window whenever point gets within this many lines\n\
14374 of the top or bottom of the window.");
14378 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
14381 DEFVAR_BOOL ("truncate-partial-width-windows",
14382 &truncate_partial_width_windows
,
14383 "*Non-nil means truncate lines in all windows less than full frame wide.");
14384 truncate_partial_width_windows
= 1;
14386 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14387 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
14388 Any other value means to use the appropriate face, `mode-line',\n\
14389 `header-line', or `menu' respectively.\n\
14391 This variable is deprecated; please change the above faces instead.");
14392 mode_line_inverse_video
= 1;
14394 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14395 "*Maximum buffer size for which line number should be displayed.\n\
14396 If the buffer is bigger than this, the line number does not appear\n\
14397 in the mode line. A value of nil means no limit.");
14398 Vline_number_display_limit
= Qnil
;
14400 DEFVAR_INT ("line-number-display-limit-width",
14401 &line_number_display_limit_width
,
14402 "*Maximum line width (in characters) for line number display.\n\
14403 If the average length of the lines near point is bigger than this, then the\n\
14404 line number may be omitted from the mode line.");
14405 line_number_display_limit_width
= 200;
14407 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14408 "*Non-nil means highlight region even in nonselected windows.");
14409 highlight_nonselected_windows
= 0;
14411 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14412 "Non-nil if more than one frame is visible on this display.\n\
14413 Minibuffer-only frames don't count, but iconified frames do.\n\
14414 This variable is not guaranteed to be accurate except while processing\n\
14415 `frame-title-format' and `icon-title-format'.");
14417 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14418 "Template for displaying the title bar of visible frames.\n\
14419 \(Assuming the window manager supports this feature.)\n\
14420 This variable has the same structure as `mode-line-format' (which see),\n\
14421 and is used only on frames for which no explicit name has been set\n\
14422 \(see `modify-frame-parameters').");
14423 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14424 "Template for displaying the title bar of an iconified frame.\n\
14425 \(Assuming the window manager supports this feature.)\n\
14426 This variable has the same structure as `mode-line-format' (which see),\n\
14427 and is used only on frames for which no explicit name has been set\n\
14428 \(see `modify-frame-parameters').");
14430 = Vframe_title_format
14431 = Fcons (intern ("multiple-frames"),
14432 Fcons (build_string ("%b"),
14433 Fcons (Fcons (build_string (""),
14434 Fcons (intern ("invocation-name"),
14435 Fcons (build_string ("@"),
14436 Fcons (intern ("system-name"),
14440 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14441 "Maximum number of lines to keep in the message log buffer.\n\
14442 If nil, disable message logging. If t, log messages but don't truncate\n\
14443 the buffer when it becomes large.");
14444 Vmessage_log_max
= make_number (50);
14446 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14447 "Functions called before redisplay, if window sizes have changed.\n\
14448 The value should be a list of functions that take one argument.\n\
14449 Just before redisplay, for each frame, if any of its windows have changed\n\
14450 size since the last redisplay, or have been split or deleted,\n\
14451 all the functions in the list are called, with the frame as argument.");
14452 Vwindow_size_change_functions
= Qnil
;
14454 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14455 "List of Functions to call before redisplaying a window with scrolling.\n\
14456 Each function is called with two arguments, the window\n\
14457 and its new display-start position. Note that the value of `window-end'\n\
14458 is not valid when these functions are called.");
14459 Vwindow_scroll_functions
= Qnil
;
14461 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14462 "*Non-nil means automatically resize tool-bars.\n\
14463 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14464 It decreases a tool-bar's height when it would display blank lines\n\
14466 auto_resize_tool_bars_p
= 1;
14468 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14469 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14470 auto_raise_tool_bar_buttons_p
= 1;
14472 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14473 "*Margin around tool-bar buttons in pixels.\n\
14474 If an integer, use that for both horizontal and vertical margins.\n\
14475 Otherwise, value should be a pair of integers `(HORZ : VERT)' with\n\
14476 HORZ specifying the horizontal margin, and VERT specifying the\n\
14477 vertical margin.");
14478 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14480 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14481 "Relief thickness of tool-bar buttons.");
14482 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14484 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14485 "List of functions to call to fontify regions of text.\n\
14486 Each function is called with one argument POS. Functions must\n\
14487 fontify a region starting at POS in the current buffer, and give\n\
14488 fontified regions the property `fontified'.\n\
14489 This variable automatically becomes buffer-local when set.");
14490 Vfontification_functions
= Qnil
;
14491 Fmake_variable_buffer_local (Qfontification_functions
);
14493 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14494 &unibyte_display_via_language_environment
,
14495 "*Non-nil means display unibyte text according to language environment.\n\
14496 Specifically this means that unibyte non-ASCII characters\n\
14497 are displayed by converting them to the equivalent multibyte characters\n\
14498 according to the current language environment. As a result, they are\n\
14499 displayed according to the current fontset.");
14500 unibyte_display_via_language_environment
= 0;
14502 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14503 "*Maximum height for resizing mini-windows.\n\
14504 If a float, it specifies a fraction of the mini-window frame's height.\n\
14505 If an integer, it specifies a number of lines.");
14506 Vmax_mini_window_height
= make_float (0.25);
14508 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14509 "*How to resize mini-windows.\n\
14510 A value of nil means don't automatically resize mini-windows.\n\
14511 A value of t means resize them to fit the text displayed in them.\n\
14512 A value of `grow-only', the default, means let mini-windows grow\n\
14513 only, until their display becomes empty, at which point the windows\n\
14514 go back to their normal size.");
14515 Vresize_mini_windows
= Qgrow_only
;
14517 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14518 &cursor_in_non_selected_windows
,
14519 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14520 Nil means don't display a cursor there.");
14521 cursor_in_non_selected_windows
= 1;
14523 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14524 "*Non-nil means scroll the display automatically to make point visible.");
14525 automatic_hscrolling_p
= 1;
14527 DEFVAR_LISP ("image-types", &Vimage_types
,
14528 "List of supported image types.\n\
14529 Each element of the list is a symbol for a supported image type.");
14530 Vimage_types
= Qnil
;
14532 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14533 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14534 Bind this around calls to `message' to let it take effect.");
14535 message_truncate_lines
= 0;
14537 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14538 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14539 Can be used to update submenus whose contents should vary.");
14540 Vmenu_bar_update_hook
= Qnil
;
14542 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14543 "Non-nil means don't update menu bars. Internal use only.");
14544 inhibit_menubar_update
= 0;
14546 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
14547 "Non-nil means don't eval Lisp during redisplay.");
14548 inhibit_eval_during_redisplay
= 0;
14552 /* Initialize this module when Emacs starts. */
14557 Lisp_Object root_window
;
14558 struct window
*mini_w
;
14560 current_header_line_height
= current_mode_line_height
= -1;
14562 CHARPOS (this_line_start_pos
) = 0;
14564 mini_w
= XWINDOW (minibuf_window
);
14565 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14567 if (!noninteractive
)
14569 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14572 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
14573 set_window_height (root_window
,
14574 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14576 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
14577 set_window_height (minibuf_window
, 1, 0);
14579 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
14580 mini_w
->width
= make_number (FRAME_WIDTH (f
));
14582 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14583 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14584 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14586 /* The default ellipsis glyphs `...'. */
14587 for (i
= 0; i
< 3; ++i
)
14588 default_invis_vector
[i
] = make_number ('.');
14591 #ifdef HAVE_WINDOW_SYSTEM
14593 /* Allocate the buffer for frame titles. */
14595 frame_title_buf
= (char *) xmalloc (size
);
14596 frame_title_buf_end
= frame_title_buf
+ size
;
14597 frame_title_ptr
= NULL
;
14599 #endif /* HAVE_WINDOW_SYSTEM */
14601 help_echo_showing_p
= 0;