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 /* Names of text properties relevant for redisplay. */
259 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
260 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
262 /* Symbols used in text property values. */
264 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
265 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
267 extern Lisp_Object Qheight
;
269 /* Non-nil means highlight trailing whitespace. */
271 Lisp_Object Vshow_trailing_whitespace
;
273 /* Name of the face used to highlight trailing whitespace. */
275 Lisp_Object Qtrailing_whitespace
;
277 /* The symbol `image' which is the car of the lists used to represent
282 /* Non-zero means print newline to stdout before next mini-buffer
285 int noninteractive_need_newline
;
287 /* Non-zero means print newline to message log before next message. */
289 static int message_log_need_newline
;
292 /* The buffer position of the first character appearing entirely or
293 partially on the line of the selected window which contains the
294 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
295 redisplay optimization in redisplay_internal. */
297 static struct text_pos this_line_start_pos
;
299 /* Number of characters past the end of the line above, including the
300 terminating newline. */
302 static struct text_pos this_line_end_pos
;
304 /* The vertical positions and the height of this line. */
306 static int this_line_vpos
;
307 static int this_line_y
;
308 static int this_line_pixel_height
;
310 /* X position at which this display line starts. Usually zero;
311 negative if first character is partially visible. */
313 static int this_line_start_x
;
315 /* Buffer that this_line_.* variables are referring to. */
317 static struct buffer
*this_line_buffer
;
319 /* Nonzero means truncate lines in all windows less wide than the
322 int truncate_partial_width_windows
;
324 /* A flag to control how to display unibyte 8-bit character. */
326 int unibyte_display_via_language_environment
;
328 /* Nonzero means we have more than one non-mini-buffer-only frame.
329 Not guaranteed to be accurate except while parsing
330 frame-title-format. */
334 Lisp_Object Vglobal_mode_string
;
336 /* Marker for where to display an arrow on top of the buffer text. */
338 Lisp_Object Voverlay_arrow_position
;
340 /* String to display for the arrow. Only used on terminal frames. */
342 Lisp_Object Voverlay_arrow_string
;
344 /* Values of those variables at last redisplay. However, if
345 Voverlay_arrow_position is a marker, last_arrow_position is its
346 numerical position. */
348 static Lisp_Object last_arrow_position
, last_arrow_string
;
350 /* Like mode-line-format, but for the title bar on a visible frame. */
352 Lisp_Object Vframe_title_format
;
354 /* Like mode-line-format, but for the title bar on an iconified frame. */
356 Lisp_Object Vicon_title_format
;
358 /* List of functions to call when a window's size changes. These
359 functions get one arg, a frame on which one or more windows' sizes
362 static Lisp_Object Vwindow_size_change_functions
;
364 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
366 /* Nonzero if overlay arrow has been displayed once in this window. */
368 static int overlay_arrow_seen
;
370 /* Nonzero means highlight the region even in nonselected windows. */
372 int highlight_nonselected_windows
;
374 /* If cursor motion alone moves point off frame, try scrolling this
375 many lines up or down if that will bring it back. */
377 static int scroll_step
;
379 /* Non-0 means scroll just far enough to bring point back on the
380 screen, when appropriate. */
382 static int scroll_conservatively
;
384 /* Recenter the window whenever point gets within this many lines of
385 the top or bottom of the window. This value is translated into a
386 pixel value by multiplying it with CANON_Y_UNIT, which means that
387 there is really a fixed pixel height scroll margin. */
391 /* Number of windows showing the buffer of the selected window (or
392 another buffer with the same base buffer). keyboard.c refers to
397 /* Vector containing glyphs for an ellipsis `...'. */
399 static Lisp_Object default_invis_vector
[3];
401 /* Zero means display the mode-line/header-line/menu-bar in the default face
402 (this slightly odd definition is for compatibility with previous versions
403 of emacs), non-zero means display them using their respective faces.
405 This variable is deprecated. */
407 int mode_line_inverse_video
;
409 /* Prompt to display in front of the mini-buffer contents. */
411 Lisp_Object minibuf_prompt
;
413 /* Width of current mini-buffer prompt. Only set after display_line
414 of the line that contains the prompt. */
416 int minibuf_prompt_width
;
417 int minibuf_prompt_pixel_width
;
419 /* This is the window where the echo area message was displayed. It
420 is always a mini-buffer window, but it may not be the same window
421 currently active as a mini-buffer. */
423 Lisp_Object echo_area_window
;
425 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
426 pushes the current message and the value of
427 message_enable_multibyte on the stack, the function restore_message
428 pops the stack and displays MESSAGE again. */
430 Lisp_Object Vmessage_stack
;
432 /* Nonzero means multibyte characters were enabled when the echo area
433 message was specified. */
435 int message_enable_multibyte
;
437 /* True if we should redraw the mode lines on the next redisplay. */
439 int update_mode_lines
;
441 /* Nonzero if window sizes or contents have changed since last
442 redisplay that finished */
444 int windows_or_buffers_changed
;
446 /* Nonzero after display_mode_line if %l was used and it displayed a
449 int line_number_displayed
;
451 /* Maximum buffer size for which to display line numbers. */
453 Lisp_Object Vline_number_display_limit
;
455 /* line width to consider when repostioning for line number display */
457 static int line_number_display_limit_width
;
459 /* Number of lines to keep in the message log buffer. t means
460 infinite. nil means don't log at all. */
462 Lisp_Object Vmessage_log_max
;
464 /* The name of the *Messages* buffer, a string. */
466 static Lisp_Object Vmessages_buffer_name
;
468 /* Current, index 0, and last displayed echo area message. Either
469 buffers from echo_buffers, or nil to indicate no message. */
471 Lisp_Object echo_area_buffer
[2];
473 /* The buffers referenced from echo_area_buffer. */
475 static Lisp_Object echo_buffer
[2];
477 /* A vector saved used in with_area_buffer to reduce consing. */
479 static Lisp_Object Vwith_echo_area_save_vector
;
481 /* Non-zero means display_echo_area should display the last echo area
482 message again. Set by redisplay_preserve_echo_area. */
484 static int display_last_displayed_message_p
;
486 /* Nonzero if echo area is being used by print; zero if being used by
489 int message_buf_print
;
491 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
493 Lisp_Object Qinhibit_menubar_update
;
494 int inhibit_menubar_update
;
496 /* Maximum height for resizing mini-windows. Either a float
497 specifying a fraction of the available height, or an integer
498 specifying a number of lines. */
500 Lisp_Object Vmax_mini_window_height
;
502 /* Non-zero means messages should be displayed with truncated
503 lines instead of being continued. */
505 int message_truncate_lines
;
506 Lisp_Object Qmessage_truncate_lines
;
508 /* Non-zero means we want a hollow cursor in windows that are not
509 selected. Zero means there's no cursor in such windows. */
511 int cursor_in_non_selected_windows
;
513 /* A scratch glyph row with contents used for generating truncation
514 glyphs. Also used in direct_output_for_insert. */
516 #define MAX_SCRATCH_GLYPHS 100
517 struct glyph_row scratch_glyph_row
;
518 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
520 /* Ascent and height of the last line processed by move_it_to. */
522 static int last_max_ascent
, last_height
;
524 /* Non-zero if there's a help-echo in the echo area. */
526 int help_echo_showing_p
;
528 /* If >= 0, computed, exact values of mode-line and header-line height
529 to use in the macros CURRENT_MODE_LINE_HEIGHT and
530 CURRENT_HEADER_LINE_HEIGHT. */
532 int current_mode_line_height
, current_header_line_height
;
534 /* The maximum distance to look ahead for text properties. Values
535 that are too small let us call compute_char_face and similar
536 functions too often which is expensive. Values that are too large
537 let us call compute_char_face and alike too often because we
538 might not be interested in text properties that far away. */
540 #define TEXT_PROP_DISTANCE_LIMIT 100
544 /* Non-zero means print traces of redisplay if compiled with
547 int trace_redisplay_p
;
549 #endif /* GLYPH_DEBUG */
551 #ifdef DEBUG_TRACE_MOVE
552 /* Non-zero means trace with TRACE_MOVE to stderr. */
555 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
557 #define TRACE_MOVE(x) (void) 0
560 /* Non-zero means automatically scroll windows horizontally to make
563 int automatic_hscrolling_p
;
565 /* A list of symbols, one for each supported image type. */
567 Lisp_Object Vimage_types
;
569 /* The variable `resize-mini-windows'. If nil, don't resize
570 mini-windows. If t, always resize them to fit the text they
571 display. If `grow-only', let mini-windows grow only until they
574 Lisp_Object Vresize_mini_windows
;
576 /* Value returned from text property handlers (see below). */
581 HANDLED_RECOMPUTE_PROPS
,
582 HANDLED_OVERLAY_STRING_CONSUMED
,
586 /* A description of text properties that redisplay is interested
591 /* The name of the property. */
594 /* A unique index for the property. */
597 /* A handler function called to set up iterator IT from the property
598 at IT's current position. Value is used to steer handle_stop. */
599 enum prop_handled (*handler
) P_ ((struct it
*it
));
602 static enum prop_handled handle_face_prop
P_ ((struct it
*));
603 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
604 static enum prop_handled handle_display_prop
P_ ((struct it
*));
605 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
606 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
607 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
609 /* Properties handled by iterators. */
611 static struct props it_props
[] =
613 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
614 /* Handle `face' before `display' because some sub-properties of
615 `display' need to know the face. */
616 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
617 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
618 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
619 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
623 /* Value is the position described by X. If X is a marker, value is
624 the marker_position of X. Otherwise, value is X. */
626 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
628 /* Enumeration returned by some move_it_.* functions internally. */
632 /* Not used. Undefined value. */
635 /* Move ended at the requested buffer position or ZV. */
636 MOVE_POS_MATCH_OR_ZV
,
638 /* Move ended at the requested X pixel position. */
641 /* Move within a line ended at the end of a line that must be
645 /* Move within a line ended at the end of a line that would
646 be displayed truncated. */
649 /* Move within a line ended at a line end. */
655 /* Function prototypes. */
657 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
658 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
659 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
660 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
661 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
662 static int invisible_text_between_p
P_ ((struct it
*, int, int));
663 static int next_element_from_ellipsis
P_ ((struct it
*));
664 static void pint2str
P_ ((char *, int, int));
665 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
667 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
668 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
669 static void store_frame_title_char
P_ ((char));
670 static int store_frame_title
P_ ((unsigned char *, int, int));
671 static void x_consider_frame_title
P_ ((Lisp_Object
));
672 static void handle_stop
P_ ((struct it
*));
673 static int tool_bar_lines_needed
P_ ((struct frame
*));
674 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
675 static void ensure_echo_area_buffers
P_ ((void));
676 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
678 struct glyph_row
*));
679 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
680 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
681 static int with_echo_area_buffer
P_ ((struct window
*, int,
682 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
683 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
684 static void clear_garbaged_frames
P_ ((void));
685 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
686 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
687 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
688 static int display_echo_area
P_ ((struct window
*));
689 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
690 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
691 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
692 static int string_char_and_length
P_ ((unsigned char *, int, int *));
693 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
695 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
696 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
697 static void insert_left_trunc_glyphs
P_ ((struct it
*));
698 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
699 static void extend_face_to_end_of_line
P_ ((struct it
*));
700 static int append_space
P_ ((struct it
*, int));
701 static void make_cursor_line_fully_visible
P_ ((struct window
*));
702 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
703 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
704 static int trailing_whitespace_p
P_ ((int));
705 static int message_log_check_duplicate
P_ ((int, int, int, int));
706 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
707 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
708 static void push_it
P_ ((struct it
*));
709 static void pop_it
P_ ((struct it
*));
710 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
711 static void redisplay_internal
P_ ((int));
712 static int echo_area_display
P_ ((int));
713 static void redisplay_windows
P_ ((Lisp_Object
));
714 static void redisplay_window
P_ ((Lisp_Object
, int));
715 static void update_menu_bar
P_ ((struct frame
*, int));
716 static int try_window_reusing_current_matrix
P_ ((struct window
*));
717 static int try_window_id
P_ ((struct window
*));
718 static int display_line
P_ ((struct it
*));
719 static int display_mode_lines
P_ ((struct window
*));
720 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
721 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
722 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
723 static void display_menu_bar
P_ ((struct window
*));
724 static int display_count_lines
P_ ((int, int, int, int, int *));
725 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
726 int, int, struct it
*, int, int, int, int));
727 static void compute_line_metrics
P_ ((struct it
*));
728 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
729 static int get_overlay_strings
P_ ((struct it
*));
730 static void next_overlay_string
P_ ((struct it
*));
731 static void reseat
P_ ((struct it
*, struct text_pos
, int));
732 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
733 static void back_to_previous_visible_line_start
P_ ((struct it
*));
734 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
735 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
736 static int next_element_from_display_vector
P_ ((struct it
*));
737 static int next_element_from_string
P_ ((struct it
*));
738 static int next_element_from_c_string
P_ ((struct it
*));
739 static int next_element_from_buffer
P_ ((struct it
*));
740 static int next_element_from_composition
P_ ((struct it
*));
741 static int next_element_from_image
P_ ((struct it
*));
742 static int next_element_from_stretch
P_ ((struct it
*));
743 static void load_overlay_strings
P_ ((struct it
*));
744 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
745 struct display_pos
*));
746 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
747 Lisp_Object
, int, int, int, int));
748 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
750 void move_it_vertically_backward
P_ ((struct it
*, int));
751 static void init_to_row_start
P_ ((struct it
*, struct window
*,
752 struct glyph_row
*));
753 static void init_to_row_end
P_ ((struct it
*, struct window
*,
754 struct glyph_row
*));
755 static void back_to_previous_line_start
P_ ((struct it
*));
756 static int forward_to_next_line_start
P_ ((struct it
*, int *));
757 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
759 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
760 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
761 static int number_of_chars
P_ ((unsigned char *, int));
762 static void compute_stop_pos
P_ ((struct it
*));
763 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
765 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
766 static int next_overlay_change
P_ ((int));
767 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
768 Lisp_Object
, struct text_pos
*,
770 static int underlying_face_id
P_ ((struct it
*));
772 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
773 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
775 #ifdef HAVE_WINDOW_SYSTEM
777 static void update_tool_bar
P_ ((struct frame
*, int));
778 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
779 static int redisplay_tool_bar
P_ ((struct frame
*));
780 static void display_tool_bar_line
P_ ((struct it
*));
782 #endif /* HAVE_WINDOW_SYSTEM */
785 /***********************************************************************
786 Window display dimensions
787 ***********************************************************************/
789 /* Return the window-relative maximum y + 1 for glyph rows displaying
790 text in window W. This is the height of W minus the height of a
791 mode line, if any. */
794 window_text_bottom_y (w
)
797 struct frame
*f
= XFRAME (w
->frame
);
798 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
800 if (WINDOW_WANTS_MODELINE_P (w
))
801 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
806 /* Return the pixel width of display area AREA of window W. AREA < 0
807 means return the total width of W, not including bitmap areas to
808 the left and right of the window. */
811 window_box_width (w
, area
)
815 struct frame
*f
= XFRAME (w
->frame
);
816 int width
= XFASTINT (w
->width
);
818 if (!w
->pseudo_window_p
)
820 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
822 if (area
== TEXT_AREA
)
824 if (INTEGERP (w
->left_margin_width
))
825 width
-= XFASTINT (w
->left_margin_width
);
826 if (INTEGERP (w
->right_margin_width
))
827 width
-= XFASTINT (w
->right_margin_width
);
829 else if (area
== LEFT_MARGIN_AREA
)
830 width
= (INTEGERP (w
->left_margin_width
)
831 ? XFASTINT (w
->left_margin_width
) : 0);
832 else if (area
== RIGHT_MARGIN_AREA
)
833 width
= (INTEGERP (w
->right_margin_width
)
834 ? XFASTINT (w
->right_margin_width
) : 0);
837 return width
* CANON_X_UNIT (f
);
841 /* Return the pixel height of the display area of window W, not
842 including mode lines of W, if any.. */
845 window_box_height (w
)
848 struct frame
*f
= XFRAME (w
->frame
);
849 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
851 xassert (height
>= 0);
853 /* Note: the code below that determines the mode-line/header-line
854 height is essentially the same as that contained in the macro
855 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
856 the appropriate glyph row has its `mode_line_p' flag set,
857 and if it doesn't, uses estimate_mode_line_height instead. */
859 if (WINDOW_WANTS_MODELINE_P (w
))
861 struct glyph_row
*ml_row
862 = (w
->current_matrix
&& w
->current_matrix
->rows
863 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
865 if (ml_row
&& ml_row
->mode_line_p
)
866 height
-= ml_row
->height
;
868 height
-= estimate_mode_line_height (f
, MODE_LINE_FACE_ID
);
871 if (WINDOW_WANTS_HEADER_LINE_P (w
))
873 struct glyph_row
*hl_row
874 = (w
->current_matrix
&& w
->current_matrix
->rows
875 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
877 if (hl_row
&& hl_row
->mode_line_p
)
878 height
-= hl_row
->height
;
880 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
887 /* Return the frame-relative coordinate of the left edge of display
888 area AREA of window W. AREA < 0 means return the left edge of the
889 whole window, to the right of any bitmap area at the left side of
893 window_box_left (w
, area
)
897 struct frame
*f
= XFRAME (w
->frame
);
898 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
900 if (!w
->pseudo_window_p
)
902 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
903 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
905 if (area
== TEXT_AREA
)
906 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
907 else if (area
== RIGHT_MARGIN_AREA
)
908 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
909 + window_box_width (w
, TEXT_AREA
));
916 /* Return the frame-relative coordinate of the right edge of display
917 area AREA of window W. AREA < 0 means return the left edge of the
918 whole window, to the left of any bitmap area at the right side of
922 window_box_right (w
, area
)
926 return window_box_left (w
, area
) + window_box_width (w
, area
);
930 /* Get the bounding box of the display area AREA of window W, without
931 mode lines, in frame-relative coordinates. AREA < 0 means the
932 whole window, not including bitmap areas to the left and right of
933 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
934 coordinates of the upper-left corner of the box. Return in
935 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
938 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
941 int *box_x
, *box_y
, *box_width
, *box_height
;
943 struct frame
*f
= XFRAME (w
->frame
);
945 *box_width
= window_box_width (w
, area
);
946 *box_height
= window_box_height (w
);
947 *box_x
= window_box_left (w
, area
);
948 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
949 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
950 if (WINDOW_WANTS_HEADER_LINE_P (w
))
951 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
955 /* Get the bounding box of the display area AREA of window W, without
956 mode lines. AREA < 0 means the whole window, not including bitmap
957 areas to the left and right of the window. Return in *TOP_LEFT_X
958 and TOP_LEFT_Y the frame-relative pixel coordinates of the
959 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
960 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
964 window_box_edges (w
, area
, top_left_x
, top_left_y
,
965 bottom_right_x
, bottom_right_y
)
968 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
970 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
972 *bottom_right_x
+= *top_left_x
;
973 *bottom_right_y
+= *top_left_y
;
978 /***********************************************************************
980 ***********************************************************************/
982 /* Return the bottom y-position of the line the iterator IT is in.
983 This can modify IT's settings. */
989 int line_height
= it
->max_ascent
+ it
->max_descent
;
990 int line_top_y
= it
->current_y
;
992 if (line_height
== 0)
995 line_height
= last_height
;
996 else if (IT_CHARPOS (*it
) < ZV
)
998 move_it_by_lines (it
, 1, 1);
999 line_height
= (it
->max_ascent
|| it
->max_descent
1000 ? it
->max_ascent
+ it
->max_descent
1005 struct glyph_row
*row
= it
->glyph_row
;
1007 /* Use the default character height. */
1008 it
->glyph_row
= NULL
;
1009 it
->what
= IT_CHARACTER
;
1012 PRODUCE_GLYPHS (it
);
1013 line_height
= it
->ascent
+ it
->descent
;
1014 it
->glyph_row
= row
;
1018 return line_top_y
+ line_height
;
1022 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1023 1 if POS is visible and the line containing POS is fully visible.
1024 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1025 and header-lines heights. */
1028 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1030 int charpos
, *fully
, exact_mode_line_heights_p
;
1033 struct text_pos top
;
1035 struct buffer
*old_buffer
= NULL
;
1037 if (XBUFFER (w
->buffer
) != current_buffer
)
1039 old_buffer
= current_buffer
;
1040 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1043 *fully
= visible_p
= 0;
1044 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1046 /* Compute exact mode line heights, if requested. */
1047 if (exact_mode_line_heights_p
)
1049 if (WINDOW_WANTS_MODELINE_P (w
))
1050 current_mode_line_height
1051 = display_mode_line (w
, MODE_LINE_FACE_ID
,
1052 current_buffer
->mode_line_format
);
1054 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1055 current_header_line_height
1056 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1057 current_buffer
->header_line_format
);
1060 start_display (&it
, w
, top
);
1061 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1062 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1064 /* Note that we may overshoot because of invisible text. */
1065 if (IT_CHARPOS (it
) >= charpos
)
1067 int top_y
= it
.current_y
;
1068 int bottom_y
= line_bottom_y (&it
);
1069 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1071 if (top_y
< window_top_y
)
1072 visible_p
= bottom_y
> window_top_y
;
1073 else if (top_y
< it
.last_visible_y
)
1076 *fully
= bottom_y
<= it
.last_visible_y
;
1079 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1081 move_it_by_lines (&it
, 1, 0);
1082 if (charpos
< IT_CHARPOS (it
))
1090 set_buffer_internal_1 (old_buffer
);
1092 current_header_line_height
= current_mode_line_height
= -1;
1097 /* Return the next character from STR which is MAXLEN bytes long.
1098 Return in *LEN the length of the character. This is like
1099 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1100 we find one, we return a `?', but with the length of the invalid
1104 string_char_and_length (str
, maxlen
, len
)
1110 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1111 if (!CHAR_VALID_P (c
, 1))
1112 /* We may not change the length here because other places in Emacs
1113 don't use this function, i.e. they silently accept invalid
1122 /* Given a position POS containing a valid character and byte position
1123 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1125 static struct text_pos
1126 string_pos_nchars_ahead (pos
, string
, nchars
)
1127 struct text_pos pos
;
1131 xassert (STRINGP (string
) && nchars
>= 0);
1133 if (STRING_MULTIBYTE (string
))
1135 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1136 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1141 string_char_and_length (p
, rest
, &len
);
1142 p
+= len
, rest
-= len
;
1143 xassert (rest
>= 0);
1145 BYTEPOS (pos
) += len
;
1149 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1155 /* Value is the text position, i.e. character and byte position,
1156 for character position CHARPOS in STRING. */
1158 static INLINE
struct text_pos
1159 string_pos (charpos
, string
)
1163 struct text_pos pos
;
1164 xassert (STRINGP (string
));
1165 xassert (charpos
>= 0);
1166 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1171 /* Value is a text position, i.e. character and byte position, for
1172 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1173 means recognize multibyte characters. */
1175 static struct text_pos
1176 c_string_pos (charpos
, s
, multibyte_p
)
1181 struct text_pos pos
;
1183 xassert (s
!= NULL
);
1184 xassert (charpos
>= 0);
1188 int rest
= strlen (s
), len
;
1190 SET_TEXT_POS (pos
, 0, 0);
1193 string_char_and_length (s
, rest
, &len
);
1194 s
+= len
, rest
-= len
;
1195 xassert (rest
>= 0);
1197 BYTEPOS (pos
) += len
;
1201 SET_TEXT_POS (pos
, charpos
, charpos
);
1207 /* Value is the number of characters in C string S. MULTIBYTE_P
1208 non-zero means recognize multibyte characters. */
1211 number_of_chars (s
, multibyte_p
)
1219 int rest
= strlen (s
), len
;
1220 unsigned char *p
= (unsigned char *) s
;
1222 for (nchars
= 0; rest
> 0; ++nchars
)
1224 string_char_and_length (p
, rest
, &len
);
1225 rest
-= len
, p
+= len
;
1229 nchars
= strlen (s
);
1235 /* Compute byte position NEWPOS->bytepos corresponding to
1236 NEWPOS->charpos. POS is a known position in string STRING.
1237 NEWPOS->charpos must be >= POS.charpos. */
1240 compute_string_pos (newpos
, pos
, string
)
1241 struct text_pos
*newpos
, pos
;
1244 xassert (STRINGP (string
));
1245 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1247 if (STRING_MULTIBYTE (string
))
1248 *newpos
= string_pos_nchars_ahead (pos
, string
,
1249 CHARPOS (*newpos
) - CHARPOS (pos
));
1251 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1256 /***********************************************************************
1257 Lisp form evaluation
1258 ***********************************************************************/
1260 /* Error handler for safe_eval and safe_call. */
1263 safe_eval_handler (arg
)
1266 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1271 /* Evaluate SEXPR and return the result, or nil if something went
1278 int count
= BINDING_STACK_SIZE ();
1279 struct gcpro gcpro1
;
1283 specbind (Qinhibit_redisplay
, Qt
);
1284 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, safe_eval_handler
);
1286 return unbind_to (count
, val
);
1290 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1291 Return the result, or nil if something went wrong. */
1294 safe_call (nargs
, args
)
1298 int count
= BINDING_STACK_SIZE ();
1300 struct gcpro gcpro1
;
1303 gcpro1
.nvars
= nargs
;
1304 specbind (Qinhibit_redisplay
, Qt
);
1305 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1308 return unbind_to (count
, val
);
1312 /* Call function FN with one argument ARG.
1313 Return the result, or nil if something went wrong. */
1316 safe_call1 (fn
, arg
)
1317 Lisp_Object fn
, arg
;
1319 Lisp_Object args
[2];
1322 return safe_call (2, args
);
1327 /***********************************************************************
1329 ***********************************************************************/
1333 /* Define CHECK_IT to perform sanity checks on iterators.
1334 This is for debugging. It is too slow to do unconditionally. */
1340 if (it
->method
== next_element_from_string
)
1342 xassert (STRINGP (it
->string
));
1343 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1345 else if (it
->method
== next_element_from_buffer
)
1347 /* Check that character and byte positions agree. */
1348 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1352 xassert (it
->current
.dpvec_index
>= 0);
1354 xassert (it
->current
.dpvec_index
< 0);
1357 #define CHECK_IT(IT) check_it ((IT))
1361 #define CHECK_IT(IT) (void) 0
1368 /* Check that the window end of window W is what we expect it
1369 to be---the last row in the current matrix displaying text. */
1372 check_window_end (w
)
1375 if (!MINI_WINDOW_P (w
)
1376 && !NILP (w
->window_end_valid
))
1378 struct glyph_row
*row
;
1379 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1380 XFASTINT (w
->window_end_vpos
)),
1382 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1383 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1387 #define CHECK_WINDOW_END(W) check_window_end ((W))
1389 #else /* not GLYPH_DEBUG */
1391 #define CHECK_WINDOW_END(W) (void) 0
1393 #endif /* not GLYPH_DEBUG */
1397 /***********************************************************************
1398 Iterator initialization
1399 ***********************************************************************/
1401 /* Initialize IT for displaying current_buffer in window W, starting
1402 at character position CHARPOS. CHARPOS < 0 means that no buffer
1403 position is specified which is useful when the iterator is assigned
1404 a position later. BYTEPOS is the byte position corresponding to
1405 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1407 If ROW is not null, calls to produce_glyphs with IT as parameter
1408 will produce glyphs in that row.
1410 BASE_FACE_ID is the id of a base face to use. It must be one of
1411 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1412 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1413 displaying the tool-bar.
1415 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1416 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1417 corresponding mode line glyph row of the desired matrix of W. */
1420 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1423 int charpos
, bytepos
;
1424 struct glyph_row
*row
;
1425 enum face_id base_face_id
;
1427 int highlight_region_p
;
1429 /* Some precondition checks. */
1430 xassert (w
!= NULL
&& it
!= NULL
);
1431 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1433 /* If face attributes have been changed since the last redisplay,
1434 free realized faces now because they depend on face definitions
1435 that might have changed. */
1436 if (face_change_count
)
1438 face_change_count
= 0;
1439 free_all_realized_faces (Qnil
);
1442 /* Use one of the mode line rows of W's desired matrix if
1446 if (base_face_id
== MODE_LINE_FACE_ID
)
1447 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1448 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1449 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1453 bzero (it
, sizeof *it
);
1454 it
->current
.overlay_string_index
= -1;
1455 it
->current
.dpvec_index
= -1;
1456 it
->base_face_id
= base_face_id
;
1458 /* The window in which we iterate over current_buffer: */
1459 XSETWINDOW (it
->window
, w
);
1461 it
->f
= XFRAME (w
->frame
);
1463 /* Extra space between lines (on window systems only). */
1464 if (base_face_id
== DEFAULT_FACE_ID
1465 && FRAME_WINDOW_P (it
->f
))
1467 if (NATNUMP (current_buffer
->extra_line_spacing
))
1468 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1469 else if (it
->f
->extra_line_spacing
> 0)
1470 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1473 /* If realized faces have been removed, e.g. because of face
1474 attribute changes of named faces, recompute them. When running
1475 in batch mode, the face cache of Vterminal_frame is null. If
1476 we happen to get called, make a dummy face cache. */
1481 FRAME_FACE_CACHE (it
->f
) == NULL
)
1482 init_frame_faces (it
->f
);
1483 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1484 recompute_basic_faces (it
->f
);
1486 /* Current value of the `space-width', and 'height' properties. */
1487 it
->space_width
= Qnil
;
1488 it
->font_height
= Qnil
;
1490 /* Are control characters displayed as `^C'? */
1491 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1493 /* -1 means everything between a CR and the following line end
1494 is invisible. >0 means lines indented more than this value are
1496 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1497 ? XFASTINT (current_buffer
->selective_display
)
1498 : (!NILP (current_buffer
->selective_display
)
1500 it
->selective_display_ellipsis_p
1501 = !NILP (current_buffer
->selective_display_ellipses
);
1503 /* Display table to use. */
1504 it
->dp
= window_display_table (w
);
1506 /* Are multibyte characters enabled in current_buffer? */
1507 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1509 /* Non-zero if we should highlight the region. */
1511 = (!NILP (Vtransient_mark_mode
)
1512 && !NILP (current_buffer
->mark_active
)
1513 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1515 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1516 start and end of a visible region in window IT->w. Set both to
1517 -1 to indicate no region. */
1518 if (highlight_region_p
1519 /* Maybe highlight only in selected window. */
1520 && (/* Either show region everywhere. */
1521 highlight_nonselected_windows
1522 /* Or show region in the selected window. */
1523 || w
== XWINDOW (selected_window
)
1524 /* Or show the region if we are in the mini-buffer and W is
1525 the window the mini-buffer refers to. */
1526 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1527 && w
== XWINDOW (Vminibuf_scroll_window
))))
1529 int charpos
= marker_position (current_buffer
->mark
);
1530 it
->region_beg_charpos
= min (PT
, charpos
);
1531 it
->region_end_charpos
= max (PT
, charpos
);
1534 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1536 /* Get the position at which the redisplay_end_trigger hook should
1537 be run, if it is to be run at all. */
1538 if (MARKERP (w
->redisplay_end_trigger
)
1539 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1540 it
->redisplay_end_trigger_charpos
1541 = marker_position (w
->redisplay_end_trigger
);
1542 else if (INTEGERP (w
->redisplay_end_trigger
))
1543 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1545 /* Correct bogus values of tab_width. */
1546 it
->tab_width
= XINT (current_buffer
->tab_width
);
1547 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1550 /* Are lines in the display truncated? */
1551 it
->truncate_lines_p
1552 = (base_face_id
!= DEFAULT_FACE_ID
1553 || XINT (it
->w
->hscroll
)
1554 || (truncate_partial_width_windows
1555 && !WINDOW_FULL_WIDTH_P (it
->w
))
1556 || !NILP (current_buffer
->truncate_lines
));
1558 /* Get dimensions of truncation and continuation glyphs. These are
1559 displayed as bitmaps under X, so we don't need them for such
1561 if (!FRAME_WINDOW_P (it
->f
))
1563 if (it
->truncate_lines_p
)
1565 /* We will need the truncation glyph. */
1566 xassert (it
->glyph_row
== NULL
);
1567 produce_special_glyphs (it
, IT_TRUNCATION
);
1568 it
->truncation_pixel_width
= it
->pixel_width
;
1572 /* We will need the continuation glyph. */
1573 xassert (it
->glyph_row
== NULL
);
1574 produce_special_glyphs (it
, IT_CONTINUATION
);
1575 it
->continuation_pixel_width
= it
->pixel_width
;
1578 /* Reset these values to zero becaue the produce_special_glyphs
1579 above has changed them. */
1580 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1581 it
->phys_ascent
= it
->phys_descent
= 0;
1584 /* Set this after getting the dimensions of truncation and
1585 continuation glyphs, so that we don't produce glyphs when calling
1586 produce_special_glyphs, above. */
1587 it
->glyph_row
= row
;
1588 it
->area
= TEXT_AREA
;
1590 /* Get the dimensions of the display area. The display area
1591 consists of the visible window area plus a horizontally scrolled
1592 part to the left of the window. All x-values are relative to the
1593 start of this total display area. */
1594 if (base_face_id
!= DEFAULT_FACE_ID
)
1596 /* Mode lines, menu bar in terminal frames. */
1597 it
->first_visible_x
= 0;
1598 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1603 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1604 it
->last_visible_x
= (it
->first_visible_x
1605 + window_box_width (w
, TEXT_AREA
));
1607 /* If we truncate lines, leave room for the truncator glyph(s) at
1608 the right margin. Otherwise, leave room for the continuation
1609 glyph(s). Truncation and continuation glyphs are not inserted
1610 for window-based redisplay. */
1611 if (!FRAME_WINDOW_P (it
->f
))
1613 if (it
->truncate_lines_p
)
1614 it
->last_visible_x
-= it
->truncation_pixel_width
;
1616 it
->last_visible_x
-= it
->continuation_pixel_width
;
1619 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1620 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1623 /* Leave room for a border glyph. */
1624 if (!FRAME_WINDOW_P (it
->f
)
1625 && !WINDOW_RIGHTMOST_P (it
->w
))
1626 it
->last_visible_x
-= 1;
1628 it
->last_visible_y
= window_text_bottom_y (w
);
1630 /* For mode lines and alike, arrange for the first glyph having a
1631 left box line if the face specifies a box. */
1632 if (base_face_id
!= DEFAULT_FACE_ID
)
1636 it
->face_id
= base_face_id
;
1638 /* If we have a boxed mode line, make the first character appear
1639 with a left box line. */
1640 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1641 if (face
->box
!= FACE_NO_BOX
)
1642 it
->start_of_box_run_p
= 1;
1645 /* If a buffer position was specified, set the iterator there,
1646 getting overlays and face properties from that position. */
1649 it
->end_charpos
= ZV
;
1651 IT_CHARPOS (*it
) = charpos
;
1653 /* Compute byte position if not specified. */
1655 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1657 IT_BYTEPOS (*it
) = bytepos
;
1659 /* Compute faces etc. */
1660 reseat (it
, it
->current
.pos
, 1);
1667 /* Initialize IT for the display of window W with window start POS. */
1670 start_display (it
, w
, pos
)
1673 struct text_pos pos
;
1675 int start_at_line_beg_p
;
1676 struct glyph_row
*row
;
1677 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1680 row
= w
->desired_matrix
->rows
+ first_vpos
;
1681 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1682 first_y
= it
->current_y
;
1684 /* If window start is not at a line start, move back to the line
1685 start. This makes sure that we take continuation lines into
1687 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1688 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1689 if (!start_at_line_beg_p
)
1690 reseat_at_previous_visible_line_start (it
);
1692 /* If window start is not at a line start, skip forward to POS to
1693 get the correct continuation_lines_width and current_x. */
1694 if (!start_at_line_beg_p
)
1696 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1698 /* If lines are continued, this line may end in the middle of a
1699 multi-glyph character (e.g. a control character displayed as
1700 \003, or in the middle of an overlay string). In this case
1701 move_it_to above will not have taken us to the start of
1702 the continuation line but to the end of the continued line. */
1703 if (!it
->truncate_lines_p
)
1705 if (it
->current_x
> 0)
1707 if (it
->current
.dpvec_index
>= 0
1708 || it
->current
.overlay_string_index
>= 0)
1710 set_iterator_to_next (it
, 1);
1711 move_it_in_display_line_to (it
, -1, -1, 0);
1714 it
->continuation_lines_width
+= it
->current_x
;
1717 /* We're starting a new display line, not affected by the
1718 height of the continued line, so clear the appropriate
1719 fields in the iterator structure. */
1720 it
->max_ascent
= it
->max_descent
= 0;
1721 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1724 it
->current_y
= first_y
;
1726 it
->current_x
= it
->hpos
= 0;
1729 #if 0 /* Don't assert the following because start_display is sometimes
1730 called intentionally with a window start that is not at a
1731 line start. Please leave this code in as a comment. */
1733 /* Window start should be on a line start, now. */
1734 xassert (it
->continuation_lines_width
1735 || IT_CHARPOS (it
) == BEGV
1736 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1741 /* Initialize IT for stepping through current_buffer in window W,
1742 starting at position POS that includes overlay string and display
1743 vector/ control character translation position information. */
1746 init_from_display_pos (it
, w
, pos
)
1749 struct display_pos
*pos
;
1751 /* Keep in mind: the call to reseat in init_iterator skips invisible
1752 text, so we might end up at a position different from POS. This
1753 is only a problem when POS is a row start after a newline and an
1754 overlay starts there with an after-string, and the overlay has an
1755 invisible property. Since we don't skip invisible text in
1756 display_line and elsewhere immediately after consuming the
1757 newline before the row start, such a POS will not be in a string,
1758 but the call to init_iterator below will move us to the
1760 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1761 NULL
, DEFAULT_FACE_ID
);
1763 /* If position is within an overlay string, set up IT to
1764 the right overlay string. */
1765 if (pos
->overlay_string_index
>= 0)
1769 /* We already have the first chunk of overlay strings in
1770 IT->overlay_strings. Load more until the one for
1771 pos->overlay_string_index is in IT->overlay_strings. */
1772 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1774 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1775 it
->current
.overlay_string_index
= 0;
1778 load_overlay_strings (it
);
1779 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1783 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1784 relative_index
= (it
->current
.overlay_string_index
1785 % OVERLAY_STRING_CHUNK_SIZE
);
1786 it
->string
= it
->overlay_strings
[relative_index
];
1787 xassert (STRINGP (it
->string
));
1788 it
->current
.string_pos
= pos
->string_pos
;
1789 it
->method
= next_element_from_string
;
1791 else if (it
->current
.overlay_string_index
>= 0)
1793 /* If POS says we're already after an overlay string ending at
1794 POS, make sure to pop the iterator because it will be in
1795 front of that overlay string. When POS is ZV, we've thereby
1796 also ``processed'' overlay strings at ZV. */
1799 it
->current
.overlay_string_index
= -1;
1800 it
->method
= next_element_from_buffer
;
1801 if (CHARPOS (pos
->pos
) == ZV
)
1802 it
->overlay_strings_at_end_processed_p
= 1;
1805 if (CHARPOS (pos
->string_pos
) >= 0)
1807 /* Recorded position is not in an overlay string, but in another
1808 string. This can only be a string from a `display' property.
1809 IT should already be filled with that string. */
1810 it
->current
.string_pos
= pos
->string_pos
;
1811 xassert (STRINGP (it
->string
));
1814 /* Restore position in display vector translations or control
1815 character translations. */
1816 if (pos
->dpvec_index
>= 0)
1818 /* This fills IT->dpvec. */
1819 get_next_display_element (it
);
1820 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1821 it
->current
.dpvec_index
= pos
->dpvec_index
;
1828 /* Initialize IT for stepping through current_buffer in window W
1829 starting at ROW->start. */
1832 init_to_row_start (it
, w
, row
)
1835 struct glyph_row
*row
;
1837 init_from_display_pos (it
, w
, &row
->start
);
1838 it
->continuation_lines_width
= row
->continuation_lines_width
;
1843 /* Initialize IT for stepping through current_buffer in window W
1844 starting in the line following ROW, i.e. starting at ROW->end. */
1847 init_to_row_end (it
, w
, row
)
1850 struct glyph_row
*row
;
1852 init_from_display_pos (it
, w
, &row
->end
);
1854 if (row
->continued_p
)
1855 it
->continuation_lines_width
= (row
->continuation_lines_width
1856 + row
->pixel_width
);
1863 /***********************************************************************
1865 ***********************************************************************/
1867 /* Called when IT reaches IT->stop_charpos. Handle text property and
1868 overlay changes. Set IT->stop_charpos to the next position where
1875 enum prop_handled handled
;
1876 int handle_overlay_change_p
= 1;
1880 it
->current
.dpvec_index
= -1;
1884 handled
= HANDLED_NORMALLY
;
1886 /* Call text property handlers. */
1887 for (p
= it_props
; p
->handler
; ++p
)
1889 handled
= p
->handler (it
);
1891 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1893 else if (handled
== HANDLED_RETURN
)
1895 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1896 handle_overlay_change_p
= 0;
1899 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1901 /* Don't check for overlay strings below when set to deliver
1902 characters from a display vector. */
1903 if (it
->method
== next_element_from_display_vector
)
1904 handle_overlay_change_p
= 0;
1906 /* Handle overlay changes. */
1907 if (handle_overlay_change_p
)
1908 handled
= handle_overlay_change (it
);
1910 /* Determine where to stop next. */
1911 if (handled
== HANDLED_NORMALLY
)
1912 compute_stop_pos (it
);
1915 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1919 /* Compute IT->stop_charpos from text property and overlay change
1920 information for IT's current position. */
1923 compute_stop_pos (it
)
1926 register INTERVAL iv
, next_iv
;
1927 Lisp_Object object
, limit
, position
;
1929 /* If nowhere else, stop at the end. */
1930 it
->stop_charpos
= it
->end_charpos
;
1932 if (STRINGP (it
->string
))
1934 /* Strings are usually short, so don't limit the search for
1936 object
= it
->string
;
1938 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1944 /* If next overlay change is in front of the current stop pos
1945 (which is IT->end_charpos), stop there. Note: value of
1946 next_overlay_change is point-max if no overlay change
1948 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1949 if (charpos
< it
->stop_charpos
)
1950 it
->stop_charpos
= charpos
;
1952 /* If showing the region, we have to stop at the region
1953 start or end because the face might change there. */
1954 if (it
->region_beg_charpos
> 0)
1956 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1957 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1958 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1959 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1962 /* Set up variables for computing the stop position from text
1963 property changes. */
1964 XSETBUFFER (object
, current_buffer
);
1965 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1966 XSETFASTINT (position
, IT_CHARPOS (*it
));
1970 /* Get the interval containing IT's position. Value is a null
1971 interval if there isn't such an interval. */
1972 iv
= validate_interval_range (object
, &position
, &position
, 0);
1973 if (!NULL_INTERVAL_P (iv
))
1975 Lisp_Object values_here
[LAST_PROP_IDX
];
1978 /* Get properties here. */
1979 for (p
= it_props
; p
->handler
; ++p
)
1980 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1982 /* Look for an interval following iv that has different
1984 for (next_iv
= next_interval (iv
);
1985 (!NULL_INTERVAL_P (next_iv
)
1987 || XFASTINT (limit
) > next_iv
->position
));
1988 next_iv
= next_interval (next_iv
))
1990 for (p
= it_props
; p
->handler
; ++p
)
1992 Lisp_Object new_value
;
1994 new_value
= textget (next_iv
->plist
, *p
->name
);
1995 if (!EQ (values_here
[p
->idx
], new_value
))
2003 if (!NULL_INTERVAL_P (next_iv
))
2005 if (INTEGERP (limit
)
2006 && next_iv
->position
>= XFASTINT (limit
))
2007 /* No text property change up to limit. */
2008 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2010 /* Text properties change in next_iv. */
2011 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2015 xassert (STRINGP (it
->string
)
2016 || (it
->stop_charpos
>= BEGV
2017 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2021 /* Return the position of the next overlay change after POS in
2022 current_buffer. Value is point-max if no overlay change
2023 follows. This is like `next-overlay-change' but doesn't use
2027 next_overlay_change (pos
)
2032 Lisp_Object
*overlays
;
2036 /* Get all overlays at the given position. */
2038 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2039 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2040 if (noverlays
> len
)
2043 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2044 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2047 /* If any of these overlays ends before endpos,
2048 use its ending point instead. */
2049 for (i
= 0; i
< noverlays
; ++i
)
2054 oend
= OVERLAY_END (overlays
[i
]);
2055 oendpos
= OVERLAY_POSITION (oend
);
2056 endpos
= min (endpos
, oendpos
);
2064 /***********************************************************************
2066 ***********************************************************************/
2068 /* Handle changes in the `fontified' property of the current buffer by
2069 calling hook functions from Qfontification_functions to fontify
2072 static enum prop_handled
2073 handle_fontified_prop (it
)
2076 Lisp_Object prop
, pos
;
2077 enum prop_handled handled
= HANDLED_NORMALLY
;
2079 /* Get the value of the `fontified' property at IT's current buffer
2080 position. (The `fontified' property doesn't have a special
2081 meaning in strings.) If the value is nil, call functions from
2082 Qfontification_functions. */
2083 if (!STRINGP (it
->string
)
2085 && !NILP (Vfontification_functions
)
2086 && !NILP (Vrun_hooks
)
2087 && (pos
= make_number (IT_CHARPOS (*it
)),
2088 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2091 int count
= BINDING_STACK_SIZE ();
2094 val
= Vfontification_functions
;
2095 specbind (Qfontification_functions
, Qnil
);
2096 specbind (Qafter_change_functions
, Qnil
);
2098 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2099 safe_call1 (val
, pos
);
2102 Lisp_Object globals
, fn
;
2103 struct gcpro gcpro1
, gcpro2
;
2106 GCPRO2 (val
, globals
);
2108 for (; CONSP (val
); val
= XCDR (val
))
2114 /* A value of t indicates this hook has a local
2115 binding; it means to run the global binding too.
2116 In a global value, t should not occur. If it
2117 does, we must ignore it to avoid an endless
2119 for (globals
= Fdefault_value (Qfontification_functions
);
2121 globals
= XCDR (globals
))
2123 fn
= XCAR (globals
);
2125 safe_call1 (fn
, pos
);
2129 safe_call1 (fn
, pos
);
2135 unbind_to (count
, Qnil
);
2137 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2138 something. This avoids an endless loop if they failed to
2139 fontify the text for which reason ever. */
2140 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2141 handled
= HANDLED_RECOMPUTE_PROPS
;
2149 /***********************************************************************
2151 ***********************************************************************/
2153 /* Set up iterator IT from face properties at its current position.
2154 Called from handle_stop. */
2156 static enum prop_handled
2157 handle_face_prop (it
)
2160 int new_face_id
, next_stop
;
2162 if (!STRINGP (it
->string
))
2165 = face_at_buffer_position (it
->w
,
2167 it
->region_beg_charpos
,
2168 it
->region_end_charpos
,
2171 + TEXT_PROP_DISTANCE_LIMIT
),
2174 /* Is this a start of a run of characters with box face?
2175 Caveat: this can be called for a freshly initialized
2176 iterator; face_id is -1 is this case. We know that the new
2177 face will not change until limit, i.e. if the new face has a
2178 box, all characters up to limit will have one. But, as
2179 usual, we don't know whether limit is really the end. */
2180 if (new_face_id
!= it
->face_id
)
2182 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2184 /* If new face has a box but old face has not, this is
2185 the start of a run of characters with box, i.e. it has
2186 a shadow on the left side. The value of face_id of the
2187 iterator will be -1 if this is the initial call that gets
2188 the face. In this case, we have to look in front of IT's
2189 position and see whether there is a face != new_face_id. */
2190 it
->start_of_box_run_p
2191 = (new_face
->box
!= FACE_NO_BOX
2192 && (it
->face_id
>= 0
2193 || IT_CHARPOS (*it
) == BEG
2194 || new_face_id
!= face_before_it_pos (it
)));
2195 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2200 int base_face_id
, bufpos
;
2202 if (it
->current
.overlay_string_index
>= 0)
2203 bufpos
= IT_CHARPOS (*it
);
2207 /* For strings from a buffer, i.e. overlay strings or strings
2208 from a `display' property, use the face at IT's current
2209 buffer position as the base face to merge with, so that
2210 overlay strings appear in the same face as surrounding
2211 text, unless they specify their own faces. */
2212 base_face_id
= underlying_face_id (it
);
2214 new_face_id
= face_at_string_position (it
->w
,
2216 IT_STRING_CHARPOS (*it
),
2218 it
->region_beg_charpos
,
2219 it
->region_end_charpos
,
2223 #if 0 /* This shouldn't be neccessary. Let's check it. */
2224 /* If IT is used to display a mode line we would really like to
2225 use the mode line face instead of the frame's default face. */
2226 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2227 && new_face_id
== DEFAULT_FACE_ID
)
2228 new_face_id
= MODE_LINE_FACE_ID
;
2231 /* Is this a start of a run of characters with box? Caveat:
2232 this can be called for a freshly allocated iterator; face_id
2233 is -1 is this case. We know that the new face will not
2234 change until the next check pos, i.e. if the new face has a
2235 box, all characters up to that position will have a
2236 box. But, as usual, we don't know whether that position
2237 is really the end. */
2238 if (new_face_id
!= it
->face_id
)
2240 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2241 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2243 /* If new face has a box but old face hasn't, this is the
2244 start of a run of characters with box, i.e. it has a
2245 shadow on the left side. */
2246 it
->start_of_box_run_p
2247 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2248 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2252 it
->face_id
= new_face_id
;
2253 return HANDLED_NORMALLY
;
2257 /* Return the ID of the face ``underlying'' IT's current position,
2258 which is in a string. If the iterator is associated with a
2259 buffer, return the face at IT's current buffer position.
2260 Otherwise, use the iterator's base_face_id. */
2263 underlying_face_id (it
)
2266 int face_id
= it
->base_face_id
, i
;
2268 xassert (STRINGP (it
->string
));
2270 for (i
= it
->sp
- 1; i
>= 0; --i
)
2271 if (NILP (it
->stack
[i
].string
))
2272 face_id
= it
->stack
[i
].face_id
;
2278 /* Compute the face one character before or after the current position
2279 of IT. BEFORE_P non-zero means get the face in front of IT's
2280 position. Value is the id of the face. */
2283 face_before_or_after_it_pos (it
, before_p
)
2288 int next_check_charpos
;
2289 struct text_pos pos
;
2291 xassert (it
->s
== NULL
);
2293 if (STRINGP (it
->string
))
2295 int bufpos
, base_face_id
;
2297 /* No face change past the end of the string (for the case
2298 we are padding with spaces). No face change before the
2300 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2301 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2304 /* Set pos to the position before or after IT's current position. */
2306 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2308 /* For composition, we must check the character after the
2310 pos
= (it
->what
== IT_COMPOSITION
2311 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2312 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2314 if (it
->current
.overlay_string_index
>= 0)
2315 bufpos
= IT_CHARPOS (*it
);
2319 base_face_id
= underlying_face_id (it
);
2321 /* Get the face for ASCII, or unibyte. */
2322 face_id
= face_at_string_position (it
->w
,
2326 it
->region_beg_charpos
,
2327 it
->region_end_charpos
,
2328 &next_check_charpos
,
2331 /* Correct the face for charsets different from ASCII. Do it
2332 for the multibyte case only. The face returned above is
2333 suitable for unibyte text if IT->string is unibyte. */
2334 if (STRING_MULTIBYTE (it
->string
))
2336 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2337 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2339 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2341 c
= string_char_and_length (p
, rest
, &len
);
2342 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2347 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2348 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2351 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2352 pos
= it
->current
.pos
;
2355 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2358 if (it
->what
== IT_COMPOSITION
)
2359 /* For composition, we must check the position after the
2361 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2363 INC_TEXT_POS (pos
, it
->multibyte_p
);
2366 /* Determine face for CHARSET_ASCII, or unibyte. */
2367 face_id
= face_at_buffer_position (it
->w
,
2369 it
->region_beg_charpos
,
2370 it
->region_end_charpos
,
2371 &next_check_charpos
,
2374 /* Correct the face for charsets different from ASCII. Do it
2375 for the multibyte case only. The face returned above is
2376 suitable for unibyte text if current_buffer is unibyte. */
2377 if (it
->multibyte_p
)
2379 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2380 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2381 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2390 /***********************************************************************
2392 ***********************************************************************/
2394 /* Set up iterator IT from invisible properties at its current
2395 position. Called from handle_stop. */
2397 static enum prop_handled
2398 handle_invisible_prop (it
)
2401 enum prop_handled handled
= HANDLED_NORMALLY
;
2403 if (STRINGP (it
->string
))
2405 extern Lisp_Object Qinvisible
;
2406 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2408 /* Get the value of the invisible text property at the
2409 current position. Value will be nil if there is no such
2411 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2412 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2415 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2417 handled
= HANDLED_RECOMPUTE_PROPS
;
2419 /* Get the position at which the next change of the
2420 invisible text property can be found in IT->string.
2421 Value will be nil if the property value is the same for
2422 all the rest of IT->string. */
2423 XSETINT (limit
, XSTRING (it
->string
)->size
);
2424 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2427 /* Text at current position is invisible. The next
2428 change in the property is at position end_charpos.
2429 Move IT's current position to that position. */
2430 if (INTEGERP (end_charpos
)
2431 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2433 struct text_pos old
;
2434 old
= it
->current
.string_pos
;
2435 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2436 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2440 /* The rest of the string is invisible. If this is an
2441 overlay string, proceed with the next overlay string
2442 or whatever comes and return a character from there. */
2443 if (it
->current
.overlay_string_index
>= 0)
2445 next_overlay_string (it
);
2446 /* Don't check for overlay strings when we just
2447 finished processing them. */
2448 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2452 struct Lisp_String
*s
= XSTRING (it
->string
);
2453 IT_STRING_CHARPOS (*it
) = s
->size
;
2454 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2461 int visible_p
, newpos
, next_stop
;
2462 Lisp_Object pos
, prop
;
2464 /* First of all, is there invisible text at this position? */
2465 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2466 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2468 /* If we are on invisible text, skip over it. */
2469 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2470 && IT_CHARPOS (*it
) < it
->end_charpos
)
2472 /* Record whether we have to display an ellipsis for the
2474 int display_ellipsis_p
2475 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2477 handled
= HANDLED_RECOMPUTE_PROPS
;
2479 /* Loop skipping over invisible text. The loop is left at
2480 ZV or with IT on the first char being visible again. */
2483 /* Try to skip some invisible text. Return value is the
2484 position reached which can be equal to IT's position
2485 if there is nothing invisible here. This skips both
2486 over invisible text properties and overlays with
2487 invisible property. */
2488 newpos
= skip_invisible (IT_CHARPOS (*it
),
2489 &next_stop
, ZV
, it
->window
);
2491 /* If we skipped nothing at all we weren't at invisible
2492 text in the first place. If everything to the end of
2493 the buffer was skipped, end the loop. */
2494 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2498 /* We skipped some characters but not necessarily
2499 all there are. Check if we ended up on visible
2500 text. Fget_char_property returns the property of
2501 the char before the given position, i.e. if we
2502 get visible_p = 1, this means that the char at
2503 newpos is visible. */
2504 XSETFASTINT (pos
, newpos
);
2505 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2506 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2509 /* If we ended up on invisible text, proceed to
2510 skip starting with next_stop. */
2512 IT_CHARPOS (*it
) = next_stop
;
2516 /* The position newpos is now either ZV or on visible text. */
2517 IT_CHARPOS (*it
) = newpos
;
2518 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2520 /* Maybe return `...' next for the end of the invisible text. */
2521 if (display_ellipsis_p
)
2524 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2526 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2527 it
->dpvec
= v
->contents
;
2528 it
->dpend
= v
->contents
+ v
->size
;
2532 /* Default `...'. */
2533 it
->dpvec
= default_invis_vector
;
2534 it
->dpend
= default_invis_vector
+ 3;
2537 /* The ellipsis display does not replace the display of
2538 the character at the new position. Indicate this by
2539 setting IT->dpvec_char_len to zero. */
2540 it
->dpvec_char_len
= 0;
2542 it
->current
.dpvec_index
= 0;
2543 it
->method
= next_element_from_display_vector
;
2553 /***********************************************************************
2555 ***********************************************************************/
2557 /* Set up iterator IT from `display' property at its current position.
2558 Called from handle_stop. */
2560 static enum prop_handled
2561 handle_display_prop (it
)
2564 Lisp_Object prop
, object
;
2565 struct text_pos
*position
;
2566 int display_replaced_p
= 0;
2568 if (STRINGP (it
->string
))
2570 object
= it
->string
;
2571 position
= &it
->current
.string_pos
;
2575 object
= it
->w
->buffer
;
2576 position
= &it
->current
.pos
;
2579 /* Reset those iterator values set from display property values. */
2580 it
->font_height
= Qnil
;
2581 it
->space_width
= Qnil
;
2584 /* We don't support recursive `display' properties, i.e. string
2585 values that have a string `display' property, that have a string
2586 `display' property etc. */
2587 if (!it
->string_from_display_prop_p
)
2588 it
->area
= TEXT_AREA
;
2590 prop
= Fget_char_property (make_number (position
->charpos
),
2593 return HANDLED_NORMALLY
;
2596 && CONSP (XCAR (prop
))
2597 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2599 /* A list of sub-properties. */
2600 for (; CONSP (prop
); prop
= XCDR (prop
))
2602 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2603 position
, display_replaced_p
))
2604 display_replaced_p
= 1;
2607 else if (VECTORP (prop
))
2610 for (i
= 0; i
< ASIZE (prop
); ++i
)
2611 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2612 position
, display_replaced_p
))
2613 display_replaced_p
= 1;
2617 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2618 display_replaced_p
= 1;
2621 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2625 /* Value is the position of the end of the `display' property starting
2626 at START_POS in OBJECT. */
2628 static struct text_pos
2629 display_prop_end (it
, object
, start_pos
)
2632 struct text_pos start_pos
;
2635 struct text_pos end_pos
;
2637 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2638 Qdisplay
, object
, Qnil
);
2639 CHARPOS (end_pos
) = XFASTINT (end
);
2640 if (STRINGP (object
))
2641 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2643 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2649 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2650 is the object in which the `display' property was found. *POSITION
2651 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2652 means that we previously saw a display sub-property which already
2653 replaced text display with something else, for example an image;
2654 ignore such properties after the first one has been processed.
2656 If PROP is a `space' or `image' sub-property, set *POSITION to the
2657 end position of the `display' property.
2659 Value is non-zero something was found which replaces the display
2660 of buffer or string text. */
2663 handle_single_display_prop (it
, prop
, object
, position
,
2664 display_replaced_before_p
)
2668 struct text_pos
*position
;
2669 int display_replaced_before_p
;
2672 int replaces_text_display_p
= 0;
2675 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2676 evaluated. If the result is nil, VALUE is ignored. */
2678 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2687 if (!NILP (form
) && !EQ (form
, Qt
))
2689 struct gcpro gcpro1
;
2690 struct text_pos end_pos
, pt
;
2693 end_pos
= display_prop_end (it
, object
, *position
);
2695 /* Temporarily set point to the end position, and then evaluate
2696 the form. This makes `(eolp)' work as FORM. */
2697 if (BUFFERP (object
))
2700 BYTEPOS (pt
) = PT_BYTE
;
2701 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2704 form
= safe_eval (form
);
2706 if (BUFFERP (object
))
2707 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2715 && EQ (XCAR (prop
), Qheight
)
2716 && CONSP (XCDR (prop
)))
2718 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2721 /* `(height HEIGHT)'. */
2722 it
->font_height
= XCAR (XCDR (prop
));
2723 if (!NILP (it
->font_height
))
2725 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2726 int new_height
= -1;
2728 if (CONSP (it
->font_height
)
2729 && (EQ (XCAR (it
->font_height
), Qplus
)
2730 || EQ (XCAR (it
->font_height
), Qminus
))
2731 && CONSP (XCDR (it
->font_height
))
2732 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2734 /* `(+ N)' or `(- N)' where N is an integer. */
2735 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2736 if (EQ (XCAR (it
->font_height
), Qplus
))
2738 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2740 else if (FUNCTIONP (it
->font_height
))
2742 /* Call function with current height as argument.
2743 Value is the new height. */
2745 height
= safe_call1 (it
->font_height
,
2746 face
->lface
[LFACE_HEIGHT_INDEX
]);
2747 if (NUMBERP (height
))
2748 new_height
= XFLOATINT (height
);
2750 else if (NUMBERP (it
->font_height
))
2752 /* Value is a multiple of the canonical char height. */
2755 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2756 new_height
= (XFLOATINT (it
->font_height
)
2757 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2761 /* Evaluate IT->font_height with `height' bound to the
2762 current specified height to get the new height. */
2764 int count
= BINDING_STACK_SIZE ();
2766 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2767 value
= safe_eval (it
->font_height
);
2768 unbind_to (count
, Qnil
);
2770 if (NUMBERP (value
))
2771 new_height
= XFLOATINT (value
);
2775 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2778 else if (CONSP (prop
)
2779 && EQ (XCAR (prop
), Qspace_width
)
2780 && CONSP (XCDR (prop
)))
2782 /* `(space_width WIDTH)'. */
2783 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2786 value
= XCAR (XCDR (prop
));
2787 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2788 it
->space_width
= value
;
2790 else if (CONSP (prop
)
2791 && EQ (XCAR (prop
), Qraise
)
2792 && CONSP (XCDR (prop
)))
2794 /* `(raise FACTOR)'. */
2795 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2798 #ifdef HAVE_WINDOW_SYSTEM
2799 value
= XCAR (XCDR (prop
));
2800 if (NUMBERP (value
))
2802 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2803 it
->voffset
= - (XFLOATINT (value
)
2804 * (FONT_HEIGHT (face
->font
)));
2806 #endif /* HAVE_WINDOW_SYSTEM */
2808 else if (!it
->string_from_display_prop_p
)
2810 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2811 VALUE) or `((margin nil) VALUE)' or VALUE. */
2812 Lisp_Object location
, value
;
2813 struct text_pos start_pos
;
2816 /* Characters having this form of property are not displayed, so
2817 we have to find the end of the property. */
2818 start_pos
= *position
;
2819 *position
= display_prop_end (it
, object
, start_pos
);
2822 /* Let's stop at the new position and assume that all
2823 text properties change there. */
2824 it
->stop_charpos
= position
->charpos
;
2826 location
= Qunbound
;
2827 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2831 value
= XCDR (prop
);
2833 value
= XCAR (value
);
2836 if (EQ (XCAR (tem
), Qmargin
)
2837 && (tem
= XCDR (tem
),
2838 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2840 || EQ (tem
, Qleft_margin
)
2841 || EQ (tem
, Qright_margin
))))
2845 if (EQ (location
, Qunbound
))
2851 #ifdef HAVE_WINDOW_SYSTEM
2852 if (FRAME_TERMCAP_P (it
->f
))
2853 valid_p
= STRINGP (value
);
2855 valid_p
= (STRINGP (value
)
2856 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2857 || valid_image_p (value
));
2858 #else /* not HAVE_WINDOW_SYSTEM */
2859 valid_p
= STRINGP (value
);
2860 #endif /* not HAVE_WINDOW_SYSTEM */
2862 if ((EQ (location
, Qleft_margin
)
2863 || EQ (location
, Qright_margin
)
2866 && !display_replaced_before_p
)
2868 replaces_text_display_p
= 1;
2870 /* Save current settings of IT so that we can restore them
2871 when we are finished with the glyph property value. */
2874 if (NILP (location
))
2875 it
->area
= TEXT_AREA
;
2876 else if (EQ (location
, Qleft_margin
))
2877 it
->area
= LEFT_MARGIN_AREA
;
2879 it
->area
= RIGHT_MARGIN_AREA
;
2881 if (STRINGP (value
))
2884 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2885 it
->current
.overlay_string_index
= -1;
2886 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2887 it
->end_charpos
= it
->string_nchars
2888 = XSTRING (it
->string
)->size
;
2889 it
->method
= next_element_from_string
;
2890 it
->stop_charpos
= 0;
2891 it
->string_from_display_prop_p
= 1;
2892 /* Say that we haven't consumed the characters with
2893 `display' property yet. The call to pop_it in
2894 set_iterator_to_next will clean this up. */
2895 *position
= start_pos
;
2897 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2899 it
->method
= next_element_from_stretch
;
2901 it
->current
.pos
= it
->position
= start_pos
;
2903 #ifdef HAVE_WINDOW_SYSTEM
2906 it
->what
= IT_IMAGE
;
2907 it
->image_id
= lookup_image (it
->f
, value
);
2908 it
->position
= start_pos
;
2909 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2910 it
->method
= next_element_from_image
;
2912 /* Say that we haven't consumed the characters with
2913 `display' property yet. The call to pop_it in
2914 set_iterator_to_next will clean this up. */
2915 *position
= start_pos
;
2917 #endif /* HAVE_WINDOW_SYSTEM */
2920 /* Invalid property or property not supported. Restore
2921 the position to what it was before. */
2922 *position
= start_pos
;
2925 return replaces_text_display_p
;
2929 /* Check if PROP is a display sub-property value whose text should be
2930 treated as intangible. */
2933 single_display_prop_intangible_p (prop
)
2936 /* Skip over `when FORM'. */
2937 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2948 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
2949 we don't need to treat text as intangible. */
2950 if (EQ (XCAR (prop
), Qmargin
))
2958 || EQ (XCAR (prop
), Qleft_margin
)
2959 || EQ (XCAR (prop
), Qright_margin
))
2963 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
2967 /* Check if PROP is a display property value whose text should be
2968 treated as intangible. */
2971 display_prop_intangible_p (prop
)
2975 && CONSP (XCAR (prop
))
2976 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2978 /* A list of sub-properties. */
2979 while (CONSP (prop
))
2981 if (single_display_prop_intangible_p (XCAR (prop
)))
2986 else if (VECTORP (prop
))
2988 /* A vector of sub-properties. */
2990 for (i
= 0; i
< ASIZE (prop
); ++i
)
2991 if (single_display_prop_intangible_p (AREF (prop
, i
)))
2995 return single_display_prop_intangible_p (prop
);
3001 /* Return 1 if PROP is a display sub-property value containing STRING. */
3004 single_display_prop_string_p (prop
, string
)
3005 Lisp_Object prop
, string
;
3007 extern Lisp_Object Qwhen
, Qmargin
;
3009 if (EQ (string
, prop
))
3012 /* Skip over `when FORM'. */
3013 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3022 /* Skip over `margin LOCATION'. */
3023 if (EQ (XCAR (prop
), Qmargin
))
3034 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3038 /* Return 1 if STRING appears in the `display' property PROP. */
3041 display_prop_string_p (prop
, string
)
3042 Lisp_Object prop
, string
;
3044 extern Lisp_Object Qwhen
, Qmargin
;
3047 && CONSP (XCAR (prop
))
3048 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3050 /* A list of sub-properties. */
3051 while (CONSP (prop
))
3053 if (single_display_prop_string_p (XCAR (prop
), string
))
3058 else if (VECTORP (prop
))
3060 /* A vector of sub-properties. */
3062 for (i
= 0; i
< ASIZE (prop
); ++i
)
3063 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3067 return single_display_prop_string_p (prop
, string
);
3073 /* Determine from which buffer position in W's buffer STRING comes
3074 from. AROUND_CHARPOS is an approximate position where it could
3075 be from. Value is the buffer position or 0 if it couldn't be
3078 W's buffer must be current.
3080 This function is necessary because we don't record buffer positions
3081 in glyphs generated from strings (to keep struct glyph small).
3082 This function may only use code that doesn't eval because it is
3083 called asynchronously from note_mouse_highlight. */
3086 string_buffer_position (w
, string
, around_charpos
)
3091 Lisp_Object around
= make_number (around_charpos
);
3092 Lisp_Object limit
, prop
, pos
;
3093 const int MAX_DISTANCE
= 1000;
3096 pos
= around_charpos
;
3097 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3098 while (!found
&& !EQ (pos
, limit
))
3100 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3101 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3104 pos
= Fnext_single_property_change (pos
, Qdisplay
, Qnil
, limit
);
3109 pos
= around_charpos
;
3110 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3111 while (!found
&& !EQ (pos
, limit
))
3113 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3114 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3117 pos
= Fprevious_single_property_change (pos
, Qdisplay
, Qnil
,
3122 return found
? XINT (pos
) : 0;
3127 /***********************************************************************
3128 `composition' property
3129 ***********************************************************************/
3131 /* Set up iterator IT from `composition' property at its current
3132 position. Called from handle_stop. */
3134 static enum prop_handled
3135 handle_composition_prop (it
)
3138 Lisp_Object prop
, string
;
3139 int pos
, pos_byte
, end
;
3140 enum prop_handled handled
= HANDLED_NORMALLY
;
3142 if (STRINGP (it
->string
))
3144 pos
= IT_STRING_CHARPOS (*it
);
3145 pos_byte
= IT_STRING_BYTEPOS (*it
);
3146 string
= it
->string
;
3150 pos
= IT_CHARPOS (*it
);
3151 pos_byte
= IT_BYTEPOS (*it
);
3155 /* If there's a valid composition and point is not inside of the
3156 composition (in the case that the composition is from the current
3157 buffer), draw a glyph composed from the composition components. */
3158 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3159 && COMPOSITION_VALID_P (pos
, end
, prop
)
3160 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3162 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3166 it
->method
= next_element_from_composition
;
3168 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3169 /* For a terminal, draw only the first character of the
3171 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3172 it
->len
= (STRINGP (it
->string
)
3173 ? string_char_to_byte (it
->string
, end
)
3174 : CHAR_TO_BYTE (end
)) - pos_byte
;
3175 it
->stop_charpos
= end
;
3176 handled
= HANDLED_RETURN
;
3185 /***********************************************************************
3187 ***********************************************************************/
3189 /* The following structure is used to record overlay strings for
3190 later sorting in load_overlay_strings. */
3192 struct overlay_entry
3194 Lisp_Object overlay
;
3201 /* Set up iterator IT from overlay strings at its current position.
3202 Called from handle_stop. */
3204 static enum prop_handled
3205 handle_overlay_change (it
)
3208 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
3209 return HANDLED_RECOMPUTE_PROPS
;
3211 return HANDLED_NORMALLY
;
3215 /* Set up the next overlay string for delivery by IT, if there is an
3216 overlay string to deliver. Called by set_iterator_to_next when the
3217 end of the current overlay string is reached. If there are more
3218 overlay strings to display, IT->string and
3219 IT->current.overlay_string_index are set appropriately here.
3220 Otherwise IT->string is set to nil. */
3223 next_overlay_string (it
)
3226 ++it
->current
.overlay_string_index
;
3227 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3229 /* No more overlay strings. Restore IT's settings to what
3230 they were before overlay strings were processed, and
3231 continue to deliver from current_buffer. */
3233 xassert (it
->stop_charpos
>= BEGV
3234 && it
->stop_charpos
<= it
->end_charpos
);
3236 it
->current
.overlay_string_index
= -1;
3237 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3238 it
->n_overlay_strings
= 0;
3239 it
->method
= next_element_from_buffer
;
3241 /* If we're at the end of the buffer, record that we have
3242 processed the overlay strings there already, so that
3243 next_element_from_buffer doesn't try it again. */
3244 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3245 it
->overlay_strings_at_end_processed_p
= 1;
3249 /* There are more overlay strings to process. If
3250 IT->current.overlay_string_index has advanced to a position
3251 where we must load IT->overlay_strings with more strings, do
3253 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3255 if (it
->current
.overlay_string_index
&& i
== 0)
3256 load_overlay_strings (it
);
3258 /* Initialize IT to deliver display elements from the overlay
3260 it
->string
= it
->overlay_strings
[i
];
3261 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3262 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3263 it
->method
= next_element_from_string
;
3264 it
->stop_charpos
= 0;
3271 /* Compare two overlay_entry structures E1 and E2. Used as a
3272 comparison function for qsort in load_overlay_strings. Overlay
3273 strings for the same position are sorted so that
3275 1. All after-strings come in front of before-strings, except
3276 when they come from the same overlay.
3278 2. Within after-strings, strings are sorted so that overlay strings
3279 from overlays with higher priorities come first.
3281 2. Within before-strings, strings are sorted so that overlay
3282 strings from overlays with higher priorities come last.
3284 Value is analogous to strcmp. */
3288 compare_overlay_entries (e1
, e2
)
3291 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3292 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3295 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3297 /* Let after-strings appear in front of before-strings if
3298 they come from different overlays. */
3299 if (EQ (entry1
->overlay
, entry2
->overlay
))
3300 result
= entry1
->after_string_p
? 1 : -1;
3302 result
= entry1
->after_string_p
? -1 : 1;
3304 else if (entry1
->after_string_p
)
3305 /* After-strings sorted in order of decreasing priority. */
3306 result
= entry2
->priority
- entry1
->priority
;
3308 /* Before-strings sorted in order of increasing priority. */
3309 result
= entry1
->priority
- entry2
->priority
;
3315 /* Load the vector IT->overlay_strings with overlay strings from IT's
3316 current buffer position. Set IT->n_overlays to the total number of
3317 overlay strings found.
3319 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3320 a time. On entry into load_overlay_strings,
3321 IT->current.overlay_string_index gives the number of overlay
3322 strings that have already been loaded by previous calls to this
3325 IT->add_overlay_start contains an additional overlay start
3326 position to consider for taking overlay strings from, if non-zero.
3327 This position comes into play when the overlay has an `invisible'
3328 property, and both before and after-strings. When we've skipped to
3329 the end of the overlay, because of its `invisible' property, we
3330 nevertheless want its before-string to appear.
3331 IT->add_overlay_start will contain the overlay start position
3334 Overlay strings are sorted so that after-string strings come in
3335 front of before-string strings. Within before and after-strings,
3336 strings are sorted by overlay priority. See also function
3337 compare_overlay_entries. */
3340 load_overlay_strings (it
)
3343 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3344 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3347 int n
= 0, i
, j
, invis_p
;
3348 struct overlay_entry
*entries
3349 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3350 int charpos
= IT_CHARPOS (*it
);
3352 /* Append the overlay string STRING of overlay OVERLAY to vector
3353 `entries' which has size `size' and currently contains `n'
3354 elements. AFTER_P non-zero means STRING is an after-string of
3356 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3359 Lisp_Object priority; \
3363 int new_size = 2 * size; \
3364 struct overlay_entry *old = entries; \
3366 (struct overlay_entry *) alloca (new_size \
3367 * sizeof *entries); \
3368 bcopy (old, entries, size * sizeof *entries); \
3372 entries[n].string = (STRING); \
3373 entries[n].overlay = (OVERLAY); \
3374 priority = Foverlay_get ((OVERLAY), Qpriority); \
3375 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3376 entries[n].after_string_p = (AFTER_P); \
3381 /* Process overlay before the overlay center. */
3382 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3384 overlay
= XCAR (ov
);
3385 xassert (OVERLAYP (overlay
));
3386 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3387 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3392 /* Skip this overlay if it doesn't start or end at IT's current
3394 if (end
!= charpos
&& start
!= charpos
)
3397 /* Skip this overlay if it doesn't apply to IT->w. */
3398 window
= Foverlay_get (overlay
, Qwindow
);
3399 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3402 /* If the text ``under'' the overlay is invisible, both before-
3403 and after-strings from this overlay are visible; start and
3404 end position are indistinguishable. */
3405 invisible
= Foverlay_get (overlay
, Qinvisible
);
3406 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3408 /* If overlay has a non-empty before-string, record it. */
3409 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3410 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3411 && XSTRING (str
)->size
)
3412 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3414 /* If overlay has a non-empty after-string, record it. */
3415 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3416 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3417 && XSTRING (str
)->size
)
3418 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3421 /* Process overlays after the overlay center. */
3422 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3424 overlay
= XCAR (ov
);
3425 xassert (OVERLAYP (overlay
));
3426 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3427 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3429 if (start
> charpos
)
3432 /* Skip this overlay if it doesn't start or end at IT's current
3434 if (end
!= charpos
&& start
!= charpos
)
3437 /* Skip this overlay if it doesn't apply to IT->w. */
3438 window
= Foverlay_get (overlay
, Qwindow
);
3439 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3442 /* If the text ``under'' the overlay is invisible, it has a zero
3443 dimension, and both before- and after-strings apply. */
3444 invisible
= Foverlay_get (overlay
, Qinvisible
);
3445 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3447 /* If overlay has a non-empty before-string, record it. */
3448 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3449 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3450 && XSTRING (str
)->size
)
3451 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3453 /* If overlay has a non-empty after-string, record it. */
3454 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3455 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3456 && XSTRING (str
)->size
)
3457 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3460 #undef RECORD_OVERLAY_STRING
3464 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3466 /* Record the total number of strings to process. */
3467 it
->n_overlay_strings
= n
;
3469 /* IT->current.overlay_string_index is the number of overlay strings
3470 that have already been consumed by IT. Copy some of the
3471 remaining overlay strings to IT->overlay_strings. */
3473 j
= it
->current
.overlay_string_index
;
3474 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3475 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3481 /* Get the first chunk of overlay strings at IT's current buffer
3482 position. Value is non-zero if at least one overlay string was
3486 get_overlay_strings (it
)
3489 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3490 process. This fills IT->overlay_strings with strings, and sets
3491 IT->n_overlay_strings to the total number of strings to process.
3492 IT->pos.overlay_string_index has to be set temporarily to zero
3493 because load_overlay_strings needs this; it must be set to -1
3494 when no overlay strings are found because a zero value would
3495 indicate a position in the first overlay string. */
3496 it
->current
.overlay_string_index
= 0;
3497 load_overlay_strings (it
);
3499 /* If we found overlay strings, set up IT to deliver display
3500 elements from the first one. Otherwise set up IT to deliver
3501 from current_buffer. */
3502 if (it
->n_overlay_strings
)
3504 /* Make sure we know settings in current_buffer, so that we can
3505 restore meaningful values when we're done with the overlay
3507 compute_stop_pos (it
);
3508 xassert (it
->face_id
>= 0);
3510 /* Save IT's settings. They are restored after all overlay
3511 strings have been processed. */
3512 xassert (it
->sp
== 0);
3515 /* Set up IT to deliver display elements from the first overlay
3517 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3518 it
->stop_charpos
= 0;
3519 it
->string
= it
->overlay_strings
[0];
3520 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3521 xassert (STRINGP (it
->string
));
3522 it
->method
= next_element_from_string
;
3527 it
->current
.overlay_string_index
= -1;
3528 it
->method
= next_element_from_buffer
;
3533 /* Value is non-zero if we found at least one overlay string. */
3534 return STRINGP (it
->string
);
3539 /***********************************************************************
3540 Saving and restoring state
3541 ***********************************************************************/
3543 /* Save current settings of IT on IT->stack. Called, for example,
3544 before setting up IT for an overlay string, to be able to restore
3545 IT's settings to what they were after the overlay string has been
3552 struct iterator_stack_entry
*p
;
3554 xassert (it
->sp
< 2);
3555 p
= it
->stack
+ it
->sp
;
3557 p
->stop_charpos
= it
->stop_charpos
;
3558 xassert (it
->face_id
>= 0);
3559 p
->face_id
= it
->face_id
;
3560 p
->string
= it
->string
;
3561 p
->pos
= it
->current
;
3562 p
->end_charpos
= it
->end_charpos
;
3563 p
->string_nchars
= it
->string_nchars
;
3565 p
->multibyte_p
= it
->multibyte_p
;
3566 p
->space_width
= it
->space_width
;
3567 p
->font_height
= it
->font_height
;
3568 p
->voffset
= it
->voffset
;
3569 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3574 /* Restore IT's settings from IT->stack. Called, for example, when no
3575 more overlay strings must be processed, and we return to delivering
3576 display elements from a buffer, or when the end of a string from a
3577 `display' property is reached and we return to delivering display
3578 elements from an overlay string, or from a buffer. */
3584 struct iterator_stack_entry
*p
;
3586 xassert (it
->sp
> 0);
3588 p
= it
->stack
+ it
->sp
;
3589 it
->stop_charpos
= p
->stop_charpos
;
3590 it
->face_id
= p
->face_id
;
3591 it
->string
= p
->string
;
3592 it
->current
= p
->pos
;
3593 it
->end_charpos
= p
->end_charpos
;
3594 it
->string_nchars
= p
->string_nchars
;
3596 it
->multibyte_p
= p
->multibyte_p
;
3597 it
->space_width
= p
->space_width
;
3598 it
->font_height
= p
->font_height
;
3599 it
->voffset
= p
->voffset
;
3600 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3605 /***********************************************************************
3607 ***********************************************************************/
3609 /* Set IT's current position to the previous line start. */
3612 back_to_previous_line_start (it
)
3615 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3616 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3620 /* Move IT to the next line start.
3622 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3623 we skipped over part of the text (as opposed to moving the iterator
3624 continuously over the text). Otherwise, don't change the value
3627 Newlines may come from buffer text, overlay strings, or strings
3628 displayed via the `display' property. That's the reason we can't
3629 simply use find_next_newline_no_quit.
3631 Note that this function may not skip over invisible text that is so
3632 because of text properties and immediately follows a newline. If
3633 it would, function reseat_at_next_visible_line_start, when called
3634 from set_iterator_to_next, would effectively make invisible
3635 characters following a newline part of the wrong glyph row, which
3636 leads to wrong cursor motion. */
3639 forward_to_next_line_start (it
, skipped_p
)
3643 int old_selective
, newline_found_p
, n
;
3644 const int MAX_NEWLINE_DISTANCE
= 500;
3646 /* If already on a newline, just consume it to avoid unintended
3647 skipping over invisible text below. */
3648 if (it
->what
== IT_CHARACTER
3650 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3652 set_iterator_to_next (it
, 0);
3657 /* Don't handle selective display in the following. It's (a)
3658 unnecessary because it's done by the caller, and (b) leads to an
3659 infinite recursion because next_element_from_ellipsis indirectly
3660 calls this function. */
3661 old_selective
= it
->selective
;
3664 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3665 from buffer text. */
3666 for (n
= newline_found_p
= 0;
3667 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3668 n
+= STRINGP (it
->string
) ? 0 : 1)
3670 if (!get_next_display_element (it
))
3672 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3673 set_iterator_to_next (it
, 0);
3676 /* If we didn't find a newline near enough, see if we can use a
3678 if (n
== MAX_NEWLINE_DISTANCE
)
3680 int start
= IT_CHARPOS (*it
);
3681 int limit
= find_next_newline_no_quit (start
, 1);
3684 xassert (!STRINGP (it
->string
));
3686 /* If there isn't any `display' property in sight, and no
3687 overlays, we can just use the position of the newline in
3689 if (it
->stop_charpos
>= limit
3690 || ((pos
= Fnext_single_property_change (make_number (start
),
3692 Qnil
, make_number (limit
)),
3694 && next_overlay_change (start
) == ZV
))
3696 IT_CHARPOS (*it
) = limit
;
3697 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3698 *skipped_p
= newline_found_p
= 1;
3702 while (get_next_display_element (it
)
3703 && !newline_found_p
)
3705 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3706 set_iterator_to_next (it
, 0);
3711 it
->selective
= old_selective
;
3712 return newline_found_p
;
3716 /* Set IT's current position to the previous visible line start. Skip
3717 invisible text that is so either due to text properties or due to
3718 selective display. Caution: this does not change IT->current_x and
3722 back_to_previous_visible_line_start (it
)
3727 /* Go back one newline if not on BEGV already. */
3728 if (IT_CHARPOS (*it
) > BEGV
)
3729 back_to_previous_line_start (it
);
3731 /* Move over lines that are invisible because of selective display
3732 or text properties. */
3733 while (IT_CHARPOS (*it
) > BEGV
3738 /* If selective > 0, then lines indented more than that values
3740 if (it
->selective
> 0
3741 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3748 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3749 Qinvisible
, it
->window
);
3750 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3754 /* Back one more newline if the current one is invisible. */
3756 back_to_previous_line_start (it
);
3759 xassert (IT_CHARPOS (*it
) >= BEGV
);
3760 xassert (IT_CHARPOS (*it
) == BEGV
3761 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3766 /* Reseat iterator IT at the previous visible line start. Skip
3767 invisible text that is so either due to text properties or due to
3768 selective display. At the end, update IT's overlay information,
3769 face information etc. */
3772 reseat_at_previous_visible_line_start (it
)
3775 back_to_previous_visible_line_start (it
);
3776 reseat (it
, it
->current
.pos
, 1);
3781 /* Reseat iterator IT on the next visible line start in the current
3782 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3783 preceding the line start. Skip over invisible text that is so
3784 because of selective display. Compute faces, overlays etc at the
3785 new position. Note that this function does not skip over text that
3786 is invisible because of text properties. */
3789 reseat_at_next_visible_line_start (it
, on_newline_p
)
3793 int newline_found_p
, skipped_p
= 0;
3795 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3797 /* Skip over lines that are invisible because they are indented
3798 more than the value of IT->selective. */
3799 if (it
->selective
> 0)
3800 while (IT_CHARPOS (*it
) < ZV
3801 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3804 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3805 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3808 /* Position on the newline if that's what's requested. */
3809 if (on_newline_p
&& newline_found_p
)
3811 if (STRINGP (it
->string
))
3813 if (IT_STRING_CHARPOS (*it
) > 0)
3815 --IT_STRING_CHARPOS (*it
);
3816 --IT_STRING_BYTEPOS (*it
);
3819 else if (IT_CHARPOS (*it
) > BEGV
)
3823 reseat (it
, it
->current
.pos
, 0);
3827 reseat (it
, it
->current
.pos
, 0);
3834 /***********************************************************************
3835 Changing an iterator's position
3836 ***********************************************************************/
3838 /* Change IT's current position to POS in current_buffer. If FORCE_P
3839 is non-zero, always check for text properties at the new position.
3840 Otherwise, text properties are only looked up if POS >=
3841 IT->check_charpos of a property. */
3844 reseat (it
, pos
, force_p
)
3846 struct text_pos pos
;
3849 int original_pos
= IT_CHARPOS (*it
);
3851 reseat_1 (it
, pos
, 0);
3853 /* Determine where to check text properties. Avoid doing it
3854 where possible because text property lookup is very expensive. */
3856 || CHARPOS (pos
) > it
->stop_charpos
3857 || CHARPOS (pos
) < original_pos
)
3864 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3865 IT->stop_pos to POS, also. */
3868 reseat_1 (it
, pos
, set_stop_p
)
3870 struct text_pos pos
;
3873 /* Don't call this function when scanning a C string. */
3874 xassert (it
->s
== NULL
);
3876 /* POS must be a reasonable value. */
3877 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3879 it
->current
.pos
= it
->position
= pos
;
3880 XSETBUFFER (it
->object
, current_buffer
);
3881 it
->end_charpos
= ZV
;
3883 it
->current
.dpvec_index
= -1;
3884 it
->current
.overlay_string_index
= -1;
3885 IT_STRING_CHARPOS (*it
) = -1;
3886 IT_STRING_BYTEPOS (*it
) = -1;
3888 it
->method
= next_element_from_buffer
;
3890 it
->face_before_selective_p
= 0;
3893 it
->stop_charpos
= CHARPOS (pos
);
3897 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3898 If S is non-null, it is a C string to iterate over. Otherwise,
3899 STRING gives a Lisp string to iterate over.
3901 If PRECISION > 0, don't return more then PRECISION number of
3902 characters from the string.
3904 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3905 characters have been returned. FIELD_WIDTH < 0 means an infinite
3908 MULTIBYTE = 0 means disable processing of multibyte characters,
3909 MULTIBYTE > 0 means enable it,
3910 MULTIBYTE < 0 means use IT->multibyte_p.
3912 IT must be initialized via a prior call to init_iterator before
3913 calling this function. */
3916 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3921 int precision
, field_width
, multibyte
;
3923 /* No region in strings. */
3924 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3926 /* No text property checks performed by default, but see below. */
3927 it
->stop_charpos
= -1;
3929 /* Set iterator position and end position. */
3930 bzero (&it
->current
, sizeof it
->current
);
3931 it
->current
.overlay_string_index
= -1;
3932 it
->current
.dpvec_index
= -1;
3933 xassert (charpos
>= 0);
3935 /* Use the setting of MULTIBYTE if specified. */
3937 it
->multibyte_p
= multibyte
> 0;
3941 xassert (STRINGP (string
));
3942 it
->string
= string
;
3944 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3945 it
->method
= next_element_from_string
;
3946 it
->current
.string_pos
= string_pos (charpos
, string
);
3953 /* Note that we use IT->current.pos, not it->current.string_pos,
3954 for displaying C strings. */
3955 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3956 if (it
->multibyte_p
)
3958 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3959 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3963 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3964 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3967 it
->method
= next_element_from_c_string
;
3970 /* PRECISION > 0 means don't return more than PRECISION characters
3972 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3973 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3975 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3976 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3977 FIELD_WIDTH < 0 means infinite field width. This is useful for
3978 padding with `-' at the end of a mode line. */
3979 if (field_width
< 0)
3980 field_width
= INFINITY
;
3981 if (field_width
> it
->end_charpos
- charpos
)
3982 it
->end_charpos
= charpos
+ field_width
;
3984 /* Use the standard display table for displaying strings. */
3985 if (DISP_TABLE_P (Vstandard_display_table
))
3986 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3988 it
->stop_charpos
= charpos
;
3994 /***********************************************************************
3996 ***********************************************************************/
3998 /* Load IT's display element fields with information about the next
3999 display element from the current position of IT. Value is zero if
4000 end of buffer (or C string) is reached. */
4003 get_next_display_element (it
)
4006 /* Non-zero means that we found an display element. Zero means that
4007 we hit the end of what we iterate over. Performance note: the
4008 function pointer `method' used here turns out to be faster than
4009 using a sequence of if-statements. */
4010 int success_p
= (*it
->method
) (it
);
4012 if (it
->what
== IT_CHARACTER
)
4014 /* Map via display table or translate control characters.
4015 IT->c, IT->len etc. have been set to the next character by
4016 the function call above. If we have a display table, and it
4017 contains an entry for IT->c, translate it. Don't do this if
4018 IT->c itself comes from a display table, otherwise we could
4019 end up in an infinite recursion. (An alternative could be to
4020 count the recursion depth of this function and signal an
4021 error when a certain maximum depth is reached.) Is it worth
4023 if (success_p
&& it
->dpvec
== NULL
)
4028 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4031 struct Lisp_Vector
*v
= XVECTOR (dv
);
4033 /* Return the first character from the display table
4034 entry, if not empty. If empty, don't display the
4035 current character. */
4038 it
->dpvec_char_len
= it
->len
;
4039 it
->dpvec
= v
->contents
;
4040 it
->dpend
= v
->contents
+ v
->size
;
4041 it
->current
.dpvec_index
= 0;
4042 it
->method
= next_element_from_display_vector
;
4043 success_p
= get_next_display_element (it
);
4047 set_iterator_to_next (it
, 0);
4048 success_p
= get_next_display_element (it
);
4052 /* Translate control characters into `\003' or `^C' form.
4053 Control characters coming from a display table entry are
4054 currently not translated because we use IT->dpvec to hold
4055 the translation. This could easily be changed but I
4056 don't believe that it is worth doing.
4058 Non-printable multibyte characters are also translated
4060 else if ((it
->c
< ' '
4061 && (it
->area
!= TEXT_AREA
4062 || (it
->c
!= '\n' && it
->c
!= '\t')))
4065 || !CHAR_PRINTABLE_P (it
->c
))
4067 /* IT->c is a control character which must be displayed
4068 either as '\003' or as `^C' where the '\\' and '^'
4069 can be defined in the display table. Fill
4070 IT->ctl_chars with glyphs for what we have to
4071 display. Then, set IT->dpvec to these glyphs. */
4074 if (it
->c
< 128 && it
->ctl_arrow_p
)
4076 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4078 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4079 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4080 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4082 g
= FAST_MAKE_GLYPH ('^', 0);
4083 XSETINT (it
->ctl_chars
[0], g
);
4085 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4086 XSETINT (it
->ctl_chars
[1], g
);
4088 /* Set up IT->dpvec and return first character from it. */
4089 it
->dpvec_char_len
= it
->len
;
4090 it
->dpvec
= it
->ctl_chars
;
4091 it
->dpend
= it
->dpvec
+ 2;
4092 it
->current
.dpvec_index
= 0;
4093 it
->method
= next_element_from_display_vector
;
4094 get_next_display_element (it
);
4098 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4103 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4105 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4106 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4107 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4109 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4111 if (SINGLE_BYTE_CHAR_P (it
->c
))
4112 str
[0] = it
->c
, len
= 1;
4114 len
= CHAR_STRING (it
->c
, str
);
4116 for (i
= 0; i
< len
; i
++)
4118 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4119 /* Insert three more glyphs into IT->ctl_chars for
4120 the octal display of the character. */
4121 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4122 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4123 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4124 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4125 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4126 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4129 /* Set up IT->dpvec and return the first character
4131 it
->dpvec_char_len
= it
->len
;
4132 it
->dpvec
= it
->ctl_chars
;
4133 it
->dpend
= it
->dpvec
+ len
* 4;
4134 it
->current
.dpvec_index
= 0;
4135 it
->method
= next_element_from_display_vector
;
4136 get_next_display_element (it
);
4141 /* Adjust face id for a multibyte character. There are no
4142 multibyte character in unibyte text. */
4145 && FRAME_WINDOW_P (it
->f
))
4147 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4148 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4152 /* Is this character the last one of a run of characters with
4153 box? If yes, set IT->end_of_box_run_p to 1. */
4160 it
->end_of_box_run_p
4161 = ((face_id
= face_after_it_pos (it
),
4162 face_id
!= it
->face_id
)
4163 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4164 face
->box
== FACE_NO_BOX
));
4167 /* Value is 0 if end of buffer or string reached. */
4172 /* Move IT to the next display element.
4174 RESEAT_P non-zero means if called on a newline in buffer text,
4175 skip to the next visible line start.
4177 Functions get_next_display_element and set_iterator_to_next are
4178 separate because I find this arrangement easier to handle than a
4179 get_next_display_element function that also increments IT's
4180 position. The way it is we can first look at an iterator's current
4181 display element, decide whether it fits on a line, and if it does,
4182 increment the iterator position. The other way around we probably
4183 would either need a flag indicating whether the iterator has to be
4184 incremented the next time, or we would have to implement a
4185 decrement position function which would not be easy to write. */
4188 set_iterator_to_next (it
, reseat_p
)
4192 /* Reset flags indicating start and end of a sequence of characters
4193 with box. Reset them at the start of this function because
4194 moving the iterator to a new position might set them. */
4195 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4197 if (it
->method
== next_element_from_buffer
)
4199 /* The current display element of IT is a character from
4200 current_buffer. Advance in the buffer, and maybe skip over
4201 invisible lines that are so because of selective display. */
4202 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4203 reseat_at_next_visible_line_start (it
, 0);
4206 xassert (it
->len
!= 0);
4207 IT_BYTEPOS (*it
) += it
->len
;
4208 IT_CHARPOS (*it
) += 1;
4209 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4212 else if (it
->method
== next_element_from_composition
)
4214 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4215 if (STRINGP (it
->string
))
4217 IT_STRING_BYTEPOS (*it
) += it
->len
;
4218 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4219 it
->method
= next_element_from_string
;
4220 goto consider_string_end
;
4224 IT_BYTEPOS (*it
) += it
->len
;
4225 IT_CHARPOS (*it
) += it
->cmp_len
;
4226 it
->method
= next_element_from_buffer
;
4229 else if (it
->method
== next_element_from_c_string
)
4231 /* Current display element of IT is from a C string. */
4232 IT_BYTEPOS (*it
) += it
->len
;
4233 IT_CHARPOS (*it
) += 1;
4235 else if (it
->method
== next_element_from_display_vector
)
4237 /* Current display element of IT is from a display table entry.
4238 Advance in the display table definition. Reset it to null if
4239 end reached, and continue with characters from buffers/
4241 ++it
->current
.dpvec_index
;
4243 /* Restore face of the iterator to what they were before the
4244 display vector entry (these entries may contain faces). */
4245 it
->face_id
= it
->saved_face_id
;
4247 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4250 it
->method
= next_element_from_c_string
;
4251 else if (STRINGP (it
->string
))
4252 it
->method
= next_element_from_string
;
4254 it
->method
= next_element_from_buffer
;
4257 it
->current
.dpvec_index
= -1;
4259 /* Skip over characters which were displayed via IT->dpvec. */
4260 if (it
->dpvec_char_len
< 0)
4261 reseat_at_next_visible_line_start (it
, 1);
4262 else if (it
->dpvec_char_len
> 0)
4264 it
->len
= it
->dpvec_char_len
;
4265 set_iterator_to_next (it
, reseat_p
);
4269 else if (it
->method
== next_element_from_string
)
4271 /* Current display element is a character from a Lisp string. */
4272 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4273 IT_STRING_BYTEPOS (*it
) += it
->len
;
4274 IT_STRING_CHARPOS (*it
) += 1;
4276 consider_string_end
:
4278 if (it
->current
.overlay_string_index
>= 0)
4280 /* IT->string is an overlay string. Advance to the
4281 next, if there is one. */
4282 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4283 next_overlay_string (it
);
4287 /* IT->string is not an overlay string. If we reached
4288 its end, and there is something on IT->stack, proceed
4289 with what is on the stack. This can be either another
4290 string, this time an overlay string, or a buffer. */
4291 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4295 if (!STRINGP (it
->string
))
4296 it
->method
= next_element_from_buffer
;
4300 else if (it
->method
== next_element_from_image
4301 || it
->method
== next_element_from_stretch
)
4303 /* The position etc with which we have to proceed are on
4304 the stack. The position may be at the end of a string,
4305 if the `display' property takes up the whole string. */
4308 if (STRINGP (it
->string
))
4310 it
->method
= next_element_from_string
;
4311 goto consider_string_end
;
4314 it
->method
= next_element_from_buffer
;
4317 /* There are no other methods defined, so this should be a bug. */
4320 xassert (it
->method
!= next_element_from_string
4321 || (STRINGP (it
->string
)
4322 && IT_STRING_CHARPOS (*it
) >= 0));
4326 /* Load IT's display element fields with information about the next
4327 display element which comes from a display table entry or from the
4328 result of translating a control character to one of the forms `^C'
4329 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4332 next_element_from_display_vector (it
)
4336 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4338 /* Remember the current face id in case glyphs specify faces.
4339 IT's face is restored in set_iterator_to_next. */
4340 it
->saved_face_id
= it
->face_id
;
4342 if (INTEGERP (*it
->dpvec
)
4343 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4348 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4349 it
->c
= FAST_GLYPH_CHAR (g
);
4350 it
->len
= CHAR_BYTES (it
->c
);
4352 /* The entry may contain a face id to use. Such a face id is
4353 the id of a Lisp face, not a realized face. A face id of
4354 zero means no face is specified. */
4355 lface_id
= FAST_GLYPH_FACE (g
);
4358 /* The function returns -1 if lface_id is invalid. */
4359 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4361 it
->face_id
= face_id
;
4365 /* Display table entry is invalid. Return a space. */
4366 it
->c
= ' ', it
->len
= 1;
4368 /* Don't change position and object of the iterator here. They are
4369 still the values of the character that had this display table
4370 entry or was translated, and that's what we want. */
4371 it
->what
= IT_CHARACTER
;
4376 /* Load IT with the next display element from Lisp string IT->string.
4377 IT->current.string_pos is the current position within the string.
4378 If IT->current.overlay_string_index >= 0, the Lisp string is an
4382 next_element_from_string (it
)
4385 struct text_pos position
;
4387 xassert (STRINGP (it
->string
));
4388 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4389 position
= it
->current
.string_pos
;
4391 /* Time to check for invisible text? */
4392 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4393 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4397 /* Since a handler may have changed IT->method, we must
4399 return get_next_display_element (it
);
4402 if (it
->current
.overlay_string_index
>= 0)
4404 /* Get the next character from an overlay string. In overlay
4405 strings, There is no field width or padding with spaces to
4407 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4412 else if (STRING_MULTIBYTE (it
->string
))
4414 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4415 - IT_STRING_BYTEPOS (*it
));
4416 unsigned char *s
= (XSTRING (it
->string
)->data
4417 + IT_STRING_BYTEPOS (*it
));
4418 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4422 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4428 /* Get the next character from a Lisp string that is not an
4429 overlay string. Such strings come from the mode line, for
4430 example. We may have to pad with spaces, or truncate the
4431 string. See also next_element_from_c_string. */
4432 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4437 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4439 /* Pad with spaces. */
4440 it
->c
= ' ', it
->len
= 1;
4441 CHARPOS (position
) = BYTEPOS (position
) = -1;
4443 else if (STRING_MULTIBYTE (it
->string
))
4445 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4446 - IT_STRING_BYTEPOS (*it
));
4447 unsigned char *s
= (XSTRING (it
->string
)->data
4448 + IT_STRING_BYTEPOS (*it
));
4449 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4453 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4458 /* Record what we have and where it came from. Note that we store a
4459 buffer position in IT->position although it could arguably be a
4461 it
->what
= IT_CHARACTER
;
4462 it
->object
= it
->string
;
4463 it
->position
= position
;
4468 /* Load IT with next display element from C string IT->s.
4469 IT->string_nchars is the maximum number of characters to return
4470 from the string. IT->end_charpos may be greater than
4471 IT->string_nchars when this function is called, in which case we
4472 may have to return padding spaces. Value is zero if end of string
4473 reached, including padding spaces. */
4476 next_element_from_c_string (it
)
4482 it
->what
= IT_CHARACTER
;
4483 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4486 /* IT's position can be greater IT->string_nchars in case a field
4487 width or precision has been specified when the iterator was
4489 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4491 /* End of the game. */
4495 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4497 /* Pad with spaces. */
4498 it
->c
= ' ', it
->len
= 1;
4499 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4501 else if (it
->multibyte_p
)
4503 /* Implementation note: The calls to strlen apparently aren't a
4504 performance problem because there is no noticeable performance
4505 difference between Emacs running in unibyte or multibyte mode. */
4506 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4507 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4511 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4517 /* Set up IT to return characters from an ellipsis, if appropriate.
4518 The definition of the ellipsis glyphs may come from a display table
4519 entry. This function Fills IT with the first glyph from the
4520 ellipsis if an ellipsis is to be displayed. */
4523 next_element_from_ellipsis (it
)
4526 if (it
->selective_display_ellipsis_p
)
4528 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4530 /* Use the display table definition for `...'. Invalid glyphs
4531 will be handled by the method returning elements from dpvec. */
4532 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4533 it
->dpvec_char_len
= it
->len
;
4534 it
->dpvec
= v
->contents
;
4535 it
->dpend
= v
->contents
+ v
->size
;
4536 it
->current
.dpvec_index
= 0;
4537 it
->method
= next_element_from_display_vector
;
4541 /* Use default `...' which is stored in default_invis_vector. */
4542 it
->dpvec_char_len
= it
->len
;
4543 it
->dpvec
= default_invis_vector
;
4544 it
->dpend
= default_invis_vector
+ 3;
4545 it
->current
.dpvec_index
= 0;
4546 it
->method
= next_element_from_display_vector
;
4551 /* The face at the current position may be different from the
4552 face we find after the invisible text. Remember what it
4553 was in IT->saved_face_id, and signal that it's there by
4554 setting face_before_selective_p. */
4555 it
->saved_face_id
= it
->face_id
;
4556 it
->method
= next_element_from_buffer
;
4557 reseat_at_next_visible_line_start (it
, 1);
4558 it
->face_before_selective_p
= 1;
4561 return get_next_display_element (it
);
4565 /* Deliver an image display element. The iterator IT is already
4566 filled with image information (done in handle_display_prop). Value
4571 next_element_from_image (it
)
4574 it
->what
= IT_IMAGE
;
4579 /* Fill iterator IT with next display element from a stretch glyph
4580 property. IT->object is the value of the text property. Value is
4584 next_element_from_stretch (it
)
4587 it
->what
= IT_STRETCH
;
4592 /* Load IT with the next display element from current_buffer. Value
4593 is zero if end of buffer reached. IT->stop_charpos is the next
4594 position at which to stop and check for text properties or buffer
4598 next_element_from_buffer (it
)
4603 /* Check this assumption, otherwise, we would never enter the
4604 if-statement, below. */
4605 xassert (IT_CHARPOS (*it
) >= BEGV
4606 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4608 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4610 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4612 int overlay_strings_follow_p
;
4614 /* End of the game, except when overlay strings follow that
4615 haven't been returned yet. */
4616 if (it
->overlay_strings_at_end_processed_p
)
4617 overlay_strings_follow_p
= 0;
4620 it
->overlay_strings_at_end_processed_p
= 1;
4621 overlay_strings_follow_p
= get_overlay_strings (it
);
4624 if (overlay_strings_follow_p
)
4625 success_p
= get_next_display_element (it
);
4629 it
->position
= it
->current
.pos
;
4636 return get_next_display_element (it
);
4641 /* No face changes, overlays etc. in sight, so just return a
4642 character from current_buffer. */
4645 /* Maybe run the redisplay end trigger hook. Performance note:
4646 This doesn't seem to cost measurable time. */
4647 if (it
->redisplay_end_trigger_charpos
4649 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4650 run_redisplay_end_trigger_hook (it
);
4652 /* Get the next character, maybe multibyte. */
4653 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4654 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4656 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4657 - IT_BYTEPOS (*it
));
4658 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4661 it
->c
= *p
, it
->len
= 1;
4663 /* Record what we have and where it came from. */
4664 it
->what
= IT_CHARACTER
;;
4665 it
->object
= it
->w
->buffer
;
4666 it
->position
= it
->current
.pos
;
4668 /* Normally we return the character found above, except when we
4669 really want to return an ellipsis for selective display. */
4674 /* A value of selective > 0 means hide lines indented more
4675 than that number of columns. */
4676 if (it
->selective
> 0
4677 && IT_CHARPOS (*it
) + 1 < ZV
4678 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4679 IT_BYTEPOS (*it
) + 1,
4682 success_p
= next_element_from_ellipsis (it
);
4683 it
->dpvec_char_len
= -1;
4686 else if (it
->c
== '\r' && it
->selective
== -1)
4688 /* A value of selective == -1 means that everything from the
4689 CR to the end of the line is invisible, with maybe an
4690 ellipsis displayed for it. */
4691 success_p
= next_element_from_ellipsis (it
);
4692 it
->dpvec_char_len
= -1;
4697 /* Value is zero if end of buffer reached. */
4698 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4703 /* Run the redisplay end trigger hook for IT. */
4706 run_redisplay_end_trigger_hook (it
)
4709 Lisp_Object args
[3];
4711 /* IT->glyph_row should be non-null, i.e. we should be actually
4712 displaying something, or otherwise we should not run the hook. */
4713 xassert (it
->glyph_row
);
4715 /* Set up hook arguments. */
4716 args
[0] = Qredisplay_end_trigger_functions
;
4717 args
[1] = it
->window
;
4718 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4719 it
->redisplay_end_trigger_charpos
= 0;
4721 /* Since we are *trying* to run these functions, don't try to run
4722 them again, even if they get an error. */
4723 it
->w
->redisplay_end_trigger
= Qnil
;
4724 Frun_hook_with_args (3, args
);
4726 /* Notice if it changed the face of the character we are on. */
4727 handle_face_prop (it
);
4731 /* Deliver a composition display element. The iterator IT is already
4732 filled with composition information (done in
4733 handle_composition_prop). Value is always 1. */
4736 next_element_from_composition (it
)
4739 it
->what
= IT_COMPOSITION
;
4740 it
->position
= (STRINGP (it
->string
)
4741 ? it
->current
.string_pos
4748 /***********************************************************************
4749 Moving an iterator without producing glyphs
4750 ***********************************************************************/
4752 /* Move iterator IT to a specified buffer or X position within one
4753 line on the display without producing glyphs.
4755 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4756 whichever is reached first.
4758 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4760 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4761 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4762 TO_X includes the amount by which a window is horizontally
4767 MOVE_POS_MATCH_OR_ZV
4768 - when TO_POS or ZV was reached.
4771 -when TO_X was reached before TO_POS or ZV were reached.
4774 - when we reached the end of the display area and the line must
4778 - when we reached the end of the display area and the line is
4782 - when we stopped at a line end, i.e. a newline or a CR and selective
4785 static enum move_it_result
4786 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4788 int to_charpos
, to_x
, op
;
4790 enum move_it_result result
= MOVE_UNDEFINED
;
4791 struct glyph_row
*saved_glyph_row
;
4793 /* Don't produce glyphs in produce_glyphs. */
4794 saved_glyph_row
= it
->glyph_row
;
4795 it
->glyph_row
= NULL
;
4799 int x
, i
, ascent
= 0, descent
= 0;
4801 /* Stop when ZV or TO_CHARPOS reached. */
4802 if (!get_next_display_element (it
)
4803 || ((op
& MOVE_TO_POS
) != 0
4804 && BUFFERP (it
->object
)
4805 && IT_CHARPOS (*it
) >= to_charpos
))
4807 result
= MOVE_POS_MATCH_OR_ZV
;
4811 /* The call to produce_glyphs will get the metrics of the
4812 display element IT is loaded with. We record in x the
4813 x-position before this display element in case it does not
4817 /* Remember the line height so far in case the next element doesn't
4819 if (!it
->truncate_lines_p
)
4821 ascent
= it
->max_ascent
;
4822 descent
= it
->max_descent
;
4825 PRODUCE_GLYPHS (it
);
4827 if (it
->area
!= TEXT_AREA
)
4829 set_iterator_to_next (it
, 1);
4833 /* The number of glyphs we get back in IT->nglyphs will normally
4834 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4835 character on a terminal frame, or (iii) a line end. For the
4836 second case, IT->nglyphs - 1 padding glyphs will be present
4837 (on X frames, there is only one glyph produced for a
4838 composite character.
4840 The behavior implemented below means, for continuation lines,
4841 that as many spaces of a TAB as fit on the current line are
4842 displayed there. For terminal frames, as many glyphs of a
4843 multi-glyph character are displayed in the current line, too.
4844 This is what the old redisplay code did, and we keep it that
4845 way. Under X, the whole shape of a complex character must
4846 fit on the line or it will be completely displayed in the
4849 Note that both for tabs and padding glyphs, all glyphs have
4853 /* More than one glyph or glyph doesn't fit on line. All
4854 glyphs have the same width. */
4855 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4858 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4860 new_x
= x
+ single_glyph_width
;
4862 /* We want to leave anything reaching TO_X to the caller. */
4863 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4866 result
= MOVE_X_REACHED
;
4869 else if (/* Lines are continued. */
4870 !it
->truncate_lines_p
4871 && (/* And glyph doesn't fit on the line. */
4872 new_x
> it
->last_visible_x
4873 /* Or it fits exactly and we're on a window
4875 || (new_x
== it
->last_visible_x
4876 && FRAME_WINDOW_P (it
->f
))))
4878 if (/* IT->hpos == 0 means the very first glyph
4879 doesn't fit on the line, e.g. a wide image. */
4881 || (new_x
== it
->last_visible_x
4882 && FRAME_WINDOW_P (it
->f
)))
4885 it
->current_x
= new_x
;
4886 if (i
== it
->nglyphs
- 1)
4887 set_iterator_to_next (it
, 1);
4892 it
->max_ascent
= ascent
;
4893 it
->max_descent
= descent
;
4896 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4898 result
= MOVE_LINE_CONTINUED
;
4901 else if (new_x
> it
->first_visible_x
)
4903 /* Glyph is visible. Increment number of glyphs that
4904 would be displayed. */
4909 /* Glyph is completely off the left margin of the display
4910 area. Nothing to do. */
4914 if (result
!= MOVE_UNDEFINED
)
4917 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4919 /* Stop when TO_X specified and reached. This check is
4920 necessary here because of lines consisting of a line end,
4921 only. The line end will not produce any glyphs and we
4922 would never get MOVE_X_REACHED. */
4923 xassert (it
->nglyphs
== 0);
4924 result
= MOVE_X_REACHED
;
4928 /* Is this a line end? If yes, we're done. */
4929 if (ITERATOR_AT_END_OF_LINE_P (it
))
4931 result
= MOVE_NEWLINE_OR_CR
;
4935 /* The current display element has been consumed. Advance
4937 set_iterator_to_next (it
, 1);
4939 /* Stop if lines are truncated and IT's current x-position is
4940 past the right edge of the window now. */
4941 if (it
->truncate_lines_p
4942 && it
->current_x
>= it
->last_visible_x
)
4944 result
= MOVE_LINE_TRUNCATED
;
4949 /* Restore the iterator settings altered at the beginning of this
4951 it
->glyph_row
= saved_glyph_row
;
4956 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4957 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4958 the description of enum move_operation_enum.
4960 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4961 screen line, this function will set IT to the next position >
4965 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4967 int to_charpos
, to_x
, to_y
, to_vpos
;
4970 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4976 if (op
& MOVE_TO_VPOS
)
4978 /* If no TO_CHARPOS and no TO_X specified, stop at the
4979 start of the line TO_VPOS. */
4980 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4982 if (it
->vpos
== to_vpos
)
4988 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4992 /* TO_VPOS >= 0 means stop at TO_X in the line at
4993 TO_VPOS, or at TO_POS, whichever comes first. */
4994 if (it
->vpos
== to_vpos
)
5000 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5002 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5007 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5009 /* We have reached TO_X but not in the line we want. */
5010 skip
= move_it_in_display_line_to (it
, to_charpos
,
5012 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5020 else if (op
& MOVE_TO_Y
)
5022 struct it it_backup
;
5024 /* TO_Y specified means stop at TO_X in the line containing
5025 TO_Y---or at TO_CHARPOS if this is reached first. The
5026 problem is that we can't really tell whether the line
5027 contains TO_Y before we have completely scanned it, and
5028 this may skip past TO_X. What we do is to first scan to
5031 If TO_X is not specified, use a TO_X of zero. The reason
5032 is to make the outcome of this function more predictable.
5033 If we didn't use TO_X == 0, we would stop at the end of
5034 the line which is probably not what a caller would expect
5036 skip
= move_it_in_display_line_to (it
, to_charpos
,
5040 | (op
& MOVE_TO_POS
)));
5042 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5043 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5049 /* If TO_X was reached, we would like to know whether TO_Y
5050 is in the line. This can only be said if we know the
5051 total line height which requires us to scan the rest of
5053 if (skip
== MOVE_X_REACHED
)
5056 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5057 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5059 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5062 /* Now, decide whether TO_Y is in this line. */
5063 line_height
= it
->max_ascent
+ it
->max_descent
;
5064 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5066 if (to_y
>= it
->current_y
5067 && to_y
< it
->current_y
+ line_height
)
5069 if (skip
== MOVE_X_REACHED
)
5070 /* If TO_Y is in this line and TO_X was reached above,
5071 we scanned too far. We have to restore IT's settings
5072 to the ones before skipping. */
5076 else if (skip
== MOVE_X_REACHED
)
5079 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5087 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5091 case MOVE_POS_MATCH_OR_ZV
:
5095 case MOVE_NEWLINE_OR_CR
:
5096 set_iterator_to_next (it
, 1);
5097 it
->continuation_lines_width
= 0;
5100 case MOVE_LINE_TRUNCATED
:
5101 it
->continuation_lines_width
= 0;
5102 reseat_at_next_visible_line_start (it
, 0);
5103 if ((op
& MOVE_TO_POS
) != 0
5104 && IT_CHARPOS (*it
) > to_charpos
)
5111 case MOVE_LINE_CONTINUED
:
5112 it
->continuation_lines_width
+= it
->current_x
;
5119 /* Reset/increment for the next run. */
5120 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5121 it
->current_x
= it
->hpos
= 0;
5122 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5124 last_height
= it
->max_ascent
+ it
->max_descent
;
5125 last_max_ascent
= it
->max_ascent
;
5126 it
->max_ascent
= it
->max_descent
= 0;
5131 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5135 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5137 If DY > 0, move IT backward at least that many pixels. DY = 0
5138 means move IT backward to the preceding line start or BEGV. This
5139 function may move over more than DY pixels if IT->current_y - DY
5140 ends up in the middle of a line; in this case IT->current_y will be
5141 set to the top of the line moved to. */
5144 move_it_vertically_backward (it
, dy
)
5148 int nlines
, h
, line_height
;
5150 int start_pos
= IT_CHARPOS (*it
);
5154 /* Estimate how many newlines we must move back. */
5155 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5157 /* Set the iterator's position that many lines back. */
5158 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5159 back_to_previous_visible_line_start (it
);
5161 /* Reseat the iterator here. When moving backward, we don't want
5162 reseat to skip forward over invisible text, set up the iterator
5163 to deliver from overlay strings at the new position etc. So,
5164 use reseat_1 here. */
5165 reseat_1 (it
, it
->current
.pos
, 1);
5167 /* We are now surely at a line start. */
5168 it
->current_x
= it
->hpos
= 0;
5170 /* Move forward and see what y-distance we moved. First move to the
5171 start of the next line so that we get its height. We need this
5172 height to be able to tell whether we reached the specified
5175 it2
.max_ascent
= it2
.max_descent
= 0;
5176 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5177 MOVE_TO_POS
| MOVE_TO_VPOS
);
5178 xassert (IT_CHARPOS (*it
) >= BEGV
);
5179 line_height
= it2
.max_ascent
+ it2
.max_descent
;
5181 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5182 xassert (IT_CHARPOS (*it
) >= BEGV
);
5183 h
= it2
.current_y
- it
->current_y
;
5184 nlines
= it2
.vpos
- it
->vpos
;
5186 /* Correct IT's y and vpos position. */
5192 /* DY == 0 means move to the start of the screen line. The
5193 value of nlines is > 0 if continuation lines were involved. */
5195 move_it_by_lines (it
, nlines
, 1);
5196 xassert (IT_CHARPOS (*it
) <= start_pos
);
5200 /* The y-position we try to reach. Note that h has been
5201 subtracted in front of the if-statement. */
5202 int target_y
= it
->current_y
+ h
- dy
;
5204 /* If we did not reach target_y, try to move further backward if
5205 we can. If we moved too far backward, try to move forward. */
5206 if (target_y
< it
->current_y
5207 && IT_CHARPOS (*it
) > BEGV
)
5209 move_it_vertically (it
, target_y
- it
->current_y
);
5210 xassert (IT_CHARPOS (*it
) >= BEGV
);
5212 else if (target_y
>= it
->current_y
+ line_height
5213 && IT_CHARPOS (*it
) < ZV
)
5215 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5216 xassert (IT_CHARPOS (*it
) >= BEGV
);
5222 /* Move IT by a specified amount of pixel lines DY. DY negative means
5223 move backwards. DY = 0 means move to start of screen line. At the
5224 end, IT will be on the start of a screen line. */
5227 move_it_vertically (it
, dy
)
5232 move_it_vertically_backward (it
, -dy
);
5235 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5236 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5237 MOVE_TO_POS
| MOVE_TO_Y
);
5238 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5240 /* If buffer ends in ZV without a newline, move to the start of
5241 the line to satisfy the post-condition. */
5242 if (IT_CHARPOS (*it
) == ZV
5243 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5244 move_it_by_lines (it
, 0, 0);
5249 /* Move iterator IT past the end of the text line it is in. */
5252 move_it_past_eol (it
)
5255 enum move_it_result rc
;
5257 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5258 if (rc
== MOVE_NEWLINE_OR_CR
)
5259 set_iterator_to_next (it
, 0);
5263 #if 0 /* Currently not used. */
5265 /* Return non-zero if some text between buffer positions START_CHARPOS
5266 and END_CHARPOS is invisible. IT->window is the window for text
5270 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5272 int start_charpos
, end_charpos
;
5274 Lisp_Object prop
, limit
;
5275 int invisible_found_p
;
5277 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5279 /* Is text at START invisible? */
5280 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5282 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5283 invisible_found_p
= 1;
5286 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5288 make_number (end_charpos
));
5289 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5292 return invisible_found_p
;
5298 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5299 negative means move up. DVPOS == 0 means move to the start of the
5300 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5301 NEED_Y_P is zero, IT->current_y will be left unchanged.
5303 Further optimization ideas: If we would know that IT->f doesn't use
5304 a face with proportional font, we could be faster for
5305 truncate-lines nil. */
5308 move_it_by_lines (it
, dvpos
, need_y_p
)
5310 int dvpos
, need_y_p
;
5312 struct position pos
;
5314 if (!FRAME_WINDOW_P (it
->f
))
5316 struct text_pos textpos
;
5318 /* We can use vmotion on frames without proportional fonts. */
5319 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5320 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5321 reseat (it
, textpos
, 1);
5322 it
->vpos
+= pos
.vpos
;
5323 it
->current_y
+= pos
.vpos
;
5325 else if (dvpos
== 0)
5327 /* DVPOS == 0 means move to the start of the screen line. */
5328 move_it_vertically_backward (it
, 0);
5329 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5332 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5336 int start_charpos
, i
;
5338 /* Go back -DVPOS visible lines and reseat the iterator there. */
5339 start_charpos
= IT_CHARPOS (*it
);
5340 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5341 back_to_previous_visible_line_start (it
);
5342 reseat (it
, it
->current
.pos
, 1);
5343 it
->current_x
= it
->hpos
= 0;
5345 /* Above call may have moved too far if continuation lines
5346 are involved. Scan forward and see if it did. */
5348 it2
.vpos
= it2
.current_y
= 0;
5349 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5350 it
->vpos
-= it2
.vpos
;
5351 it
->current_y
-= it2
.current_y
;
5352 it
->current_x
= it
->hpos
= 0;
5354 /* If we moved too far, move IT some lines forward. */
5355 if (it2
.vpos
> -dvpos
)
5357 int delta
= it2
.vpos
+ dvpos
;
5358 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5365 /***********************************************************************
5367 ***********************************************************************/
5370 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5374 add_to_log (format
, arg1
, arg2
)
5376 Lisp_Object arg1
, arg2
;
5378 Lisp_Object args
[3];
5379 Lisp_Object msg
, fmt
;
5382 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5385 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5387 args
[0] = fmt
= build_string (format
);
5390 msg
= Fformat (3, args
);
5392 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5393 buffer
= (char *) alloca (len
);
5394 strcpy (buffer
, XSTRING (msg
)->data
);
5396 message_dolog (buffer
, len
- 1, 1, 0);
5401 /* Output a newline in the *Messages* buffer if "needs" one. */
5404 message_log_maybe_newline ()
5406 if (message_log_need_newline
)
5407 message_dolog ("", 0, 1, 0);
5411 /* Add a string M of length NBYTES to the message log, optionally
5412 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5413 nonzero, means interpret the contents of M as multibyte. This
5414 function calls low-level routines in order to bypass text property
5415 hooks, etc. which might not be safe to run. */
5418 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5420 int nbytes
, nlflag
, multibyte
;
5422 if (!NILP (Vmessage_log_max
))
5424 struct buffer
*oldbuf
;
5425 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5426 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5427 int point_at_end
= 0;
5429 Lisp_Object old_deactivate_mark
, tem
;
5430 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5432 old_deactivate_mark
= Vdeactivate_mark
;
5433 oldbuf
= current_buffer
;
5434 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5435 current_buffer
->undo_list
= Qt
;
5437 oldpoint
= Fpoint_marker ();
5438 oldbegv
= Fpoint_min_marker ();
5439 oldzv
= Fpoint_max_marker ();
5440 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5448 BEGV_BYTE
= BEG_BYTE
;
5451 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5453 /* Insert the string--maybe converting multibyte to single byte
5454 or vice versa, so that all the text fits the buffer. */
5456 && NILP (current_buffer
->enable_multibyte_characters
))
5458 int i
, c
, char_bytes
;
5459 unsigned char work
[1];
5461 /* Convert a multibyte string to single-byte
5462 for the *Message* buffer. */
5463 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5465 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5466 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5468 : multibyte_char_to_unibyte (c
, Qnil
));
5469 insert_1_both (work
, 1, 1, 1, 0, 0);
5472 else if (! multibyte
5473 && ! NILP (current_buffer
->enable_multibyte_characters
))
5475 int i
, c
, char_bytes
;
5476 unsigned char *msg
= (unsigned char *) m
;
5477 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5478 /* Convert a single-byte string to multibyte
5479 for the *Message* buffer. */
5480 for (i
= 0; i
< nbytes
; i
++)
5482 c
= unibyte_char_to_multibyte (msg
[i
]);
5483 char_bytes
= CHAR_STRING (c
, str
);
5484 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5488 insert_1 (m
, nbytes
, 1, 0, 0);
5492 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5493 insert_1 ("\n", 1, 1, 0, 0);
5495 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5497 this_bol_byte
= PT_BYTE
;
5501 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5503 prev_bol_byte
= PT_BYTE
;
5505 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5506 this_bol
, this_bol_byte
);
5509 del_range_both (prev_bol
, prev_bol_byte
,
5510 this_bol
, this_bol_byte
, 0);
5516 /* If you change this format, don't forget to also
5517 change message_log_check_duplicate. */
5518 sprintf (dupstr
, " [%d times]", dup
);
5519 duplen
= strlen (dupstr
);
5520 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5521 insert_1 (dupstr
, duplen
, 1, 0, 1);
5526 if (NATNUMP (Vmessage_log_max
))
5528 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5529 -XFASTINT (Vmessage_log_max
) - 1, 0);
5530 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5533 BEGV
= XMARKER (oldbegv
)->charpos
;
5534 BEGV_BYTE
= marker_byte_position (oldbegv
);
5543 ZV
= XMARKER (oldzv
)->charpos
;
5544 ZV_BYTE
= marker_byte_position (oldzv
);
5548 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5550 /* We can't do Fgoto_char (oldpoint) because it will run some
5552 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5553 XMARKER (oldpoint
)->bytepos
);
5556 free_marker (oldpoint
);
5557 free_marker (oldbegv
);
5558 free_marker (oldzv
);
5560 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5561 set_buffer_internal (oldbuf
);
5563 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5564 message_log_need_newline
= !nlflag
;
5565 Vdeactivate_mark
= old_deactivate_mark
;
5570 /* We are at the end of the buffer after just having inserted a newline.
5571 (Note: We depend on the fact we won't be crossing the gap.)
5572 Check to see if the most recent message looks a lot like the previous one.
5573 Return 0 if different, 1 if the new one should just replace it, or a
5574 value N > 1 if we should also append " [N times]". */
5577 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5578 int prev_bol
, this_bol
;
5579 int prev_bol_byte
, this_bol_byte
;
5582 int len
= Z_BYTE
- 1 - this_bol_byte
;
5584 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5585 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5587 for (i
= 0; i
< len
; i
++)
5589 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5597 if (*p1
++ == ' ' && *p1
++ == '[')
5600 while (*p1
>= '0' && *p1
<= '9')
5601 n
= n
* 10 + *p1
++ - '0';
5602 if (strncmp (p1
, " times]\n", 8) == 0)
5609 /* Display an echo area message M with a specified length of NBYTES
5610 bytes. The string may include null characters. If M is 0, clear
5611 out any existing message, and let the mini-buffer text show
5614 The buffer M must continue to exist until after the echo area gets
5615 cleared or some other message gets displayed there. This means do
5616 not pass text that is stored in a Lisp string; do not pass text in
5617 a buffer that was alloca'd. */
5620 message2 (m
, nbytes
, multibyte
)
5625 /* First flush out any partial line written with print. */
5626 message_log_maybe_newline ();
5628 message_dolog (m
, nbytes
, 1, multibyte
);
5629 message2_nolog (m
, nbytes
, multibyte
);
5633 /* The non-logging counterpart of message2. */
5636 message2_nolog (m
, nbytes
, multibyte
)
5640 struct frame
*sf
= SELECTED_FRAME ();
5641 message_enable_multibyte
= multibyte
;
5645 if (noninteractive_need_newline
)
5646 putc ('\n', stderr
);
5647 noninteractive_need_newline
= 0;
5649 fwrite (m
, nbytes
, 1, stderr
);
5650 if (cursor_in_echo_area
== 0)
5651 fprintf (stderr
, "\n");
5654 /* A null message buffer means that the frame hasn't really been
5655 initialized yet. Error messages get reported properly by
5656 cmd_error, so this must be just an informative message; toss it. */
5657 else if (INTERACTIVE
5658 && sf
->glyphs_initialized_p
5659 && FRAME_MESSAGE_BUF (sf
))
5661 Lisp_Object mini_window
;
5664 /* Get the frame containing the mini-buffer
5665 that the selected frame is using. */
5666 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5667 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5669 FRAME_SAMPLE_VISIBILITY (f
);
5670 if (FRAME_VISIBLE_P (sf
)
5671 && ! FRAME_VISIBLE_P (f
))
5672 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5676 set_message (m
, Qnil
, nbytes
, multibyte
);
5677 if (minibuffer_auto_raise
)
5678 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5681 clear_message (1, 1);
5683 do_pending_window_change (0);
5684 echo_area_display (1);
5685 do_pending_window_change (0);
5686 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5687 (*frame_up_to_date_hook
) (f
);
5692 /* Display an echo area message M with a specified length of NBYTES
5693 bytes. The string may include null characters. If M is not a
5694 string, clear out any existing message, and let the mini-buffer
5695 text show through. */
5698 message3 (m
, nbytes
, multibyte
)
5703 struct gcpro gcpro1
;
5707 /* First flush out any partial line written with print. */
5708 message_log_maybe_newline ();
5710 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5711 message3_nolog (m
, nbytes
, multibyte
);
5717 /* The non-logging version of message3. */
5720 message3_nolog (m
, nbytes
, multibyte
)
5722 int nbytes
, multibyte
;
5724 struct frame
*sf
= SELECTED_FRAME ();
5725 message_enable_multibyte
= multibyte
;
5729 if (noninteractive_need_newline
)
5730 putc ('\n', stderr
);
5731 noninteractive_need_newline
= 0;
5733 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5734 if (cursor_in_echo_area
== 0)
5735 fprintf (stderr
, "\n");
5738 /* A null message buffer means that the frame hasn't really been
5739 initialized yet. Error messages get reported properly by
5740 cmd_error, so this must be just an informative message; toss it. */
5741 else if (INTERACTIVE
5742 && sf
->glyphs_initialized_p
5743 && FRAME_MESSAGE_BUF (sf
))
5745 Lisp_Object mini_window
;
5749 /* Get the frame containing the mini-buffer
5750 that the selected frame is using. */
5751 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5752 frame
= XWINDOW (mini_window
)->frame
;
5755 FRAME_SAMPLE_VISIBILITY (f
);
5756 if (FRAME_VISIBLE_P (sf
)
5757 && !FRAME_VISIBLE_P (f
))
5758 Fmake_frame_visible (frame
);
5760 if (STRINGP (m
) && XSTRING (m
)->size
)
5762 set_message (NULL
, m
, nbytes
, multibyte
);
5763 if (minibuffer_auto_raise
)
5764 Fraise_frame (frame
);
5767 clear_message (1, 1);
5769 do_pending_window_change (0);
5770 echo_area_display (1);
5771 do_pending_window_change (0);
5772 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5773 (*frame_up_to_date_hook
) (f
);
5778 /* Display a null-terminated echo area message M. If M is 0, clear
5779 out any existing message, and let the mini-buffer text show through.
5781 The buffer M must continue to exist until after the echo area gets
5782 cleared or some other message gets displayed there. Do not pass
5783 text that is stored in a Lisp string. Do not pass text in a buffer
5784 that was alloca'd. */
5790 message2 (m
, (m
? strlen (m
) : 0), 0);
5794 /* The non-logging counterpart of message1. */
5800 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5803 /* Display a message M which contains a single %s
5804 which gets replaced with STRING. */
5807 message_with_string (m
, string
, log
)
5816 if (noninteractive_need_newline
)
5817 putc ('\n', stderr
);
5818 noninteractive_need_newline
= 0;
5819 fprintf (stderr
, m
, XSTRING (string
)->data
);
5820 if (cursor_in_echo_area
== 0)
5821 fprintf (stderr
, "\n");
5825 else if (INTERACTIVE
)
5827 /* The frame whose minibuffer we're going to display the message on.
5828 It may be larger than the selected frame, so we need
5829 to use its buffer, not the selected frame's buffer. */
5830 Lisp_Object mini_window
;
5831 struct frame
*f
, *sf
= SELECTED_FRAME ();
5833 /* Get the frame containing the minibuffer
5834 that the selected frame is using. */
5835 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5836 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5838 /* A null message buffer means that the frame hasn't really been
5839 initialized yet. Error messages get reported properly by
5840 cmd_error, so this must be just an informative message; toss it. */
5841 if (FRAME_MESSAGE_BUF (f
))
5845 a
[0] = (char *) XSTRING (string
)->data
;
5847 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5848 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5851 message2 (FRAME_MESSAGE_BUF (f
), len
,
5852 STRING_MULTIBYTE (string
));
5854 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5855 STRING_MULTIBYTE (string
));
5857 /* Print should start at the beginning of the message
5858 buffer next time. */
5859 message_buf_print
= 0;
5865 /* Dump an informative message to the minibuf. If M is 0, clear out
5866 any existing message, and let the mini-buffer text show through. */
5870 message (m
, a1
, a2
, a3
)
5872 EMACS_INT a1
, a2
, a3
;
5878 if (noninteractive_need_newline
)
5879 putc ('\n', stderr
);
5880 noninteractive_need_newline
= 0;
5881 fprintf (stderr
, m
, a1
, a2
, a3
);
5882 if (cursor_in_echo_area
== 0)
5883 fprintf (stderr
, "\n");
5887 else if (INTERACTIVE
)
5889 /* The frame whose mini-buffer we're going to display the message
5890 on. It may be larger than the selected frame, so we need to
5891 use its buffer, not the selected frame's buffer. */
5892 Lisp_Object mini_window
;
5893 struct frame
*f
, *sf
= SELECTED_FRAME ();
5895 /* Get the frame containing the mini-buffer
5896 that the selected frame is using. */
5897 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5898 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5900 /* A null message buffer means that the frame hasn't really been
5901 initialized yet. Error messages get reported properly by
5902 cmd_error, so this must be just an informative message; toss
5904 if (FRAME_MESSAGE_BUF (f
))
5915 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5916 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5918 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5919 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5921 #endif /* NO_ARG_ARRAY */
5923 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5928 /* Print should start at the beginning of the message
5929 buffer next time. */
5930 message_buf_print
= 0;
5936 /* The non-logging version of message. */
5939 message_nolog (m
, a1
, a2
, a3
)
5941 EMACS_INT a1
, a2
, a3
;
5943 Lisp_Object old_log_max
;
5944 old_log_max
= Vmessage_log_max
;
5945 Vmessage_log_max
= Qnil
;
5946 message (m
, a1
, a2
, a3
);
5947 Vmessage_log_max
= old_log_max
;
5951 /* Display the current message in the current mini-buffer. This is
5952 only called from error handlers in process.c, and is not time
5958 if (!NILP (echo_area_buffer
[0]))
5961 string
= Fcurrent_message ();
5962 message3 (string
, XSTRING (string
)->size
,
5963 !NILP (current_buffer
->enable_multibyte_characters
));
5968 /* Make sure echo area buffers in echo_buffers[] are life. If they
5969 aren't, make new ones. */
5972 ensure_echo_area_buffers ()
5976 for (i
= 0; i
< 2; ++i
)
5977 if (!BUFFERP (echo_buffer
[i
])
5978 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5981 Lisp_Object old_buffer
;
5984 old_buffer
= echo_buffer
[i
];
5985 sprintf (name
, " *Echo Area %d*", i
);
5986 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5987 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
5989 for (j
= 0; j
< 2; ++j
)
5990 if (EQ (old_buffer
, echo_area_buffer
[j
]))
5991 echo_area_buffer
[j
] = echo_buffer
[i
];
5996 /* Call FN with args A1..A4 with either the current or last displayed
5997 echo_area_buffer as current buffer.
5999 WHICH zero means use the current message buffer
6000 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6001 from echo_buffer[] and clear it.
6003 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6004 suitable buffer from echo_buffer[] and clear it.
6006 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6007 that the current message becomes the last displayed one, make
6008 choose a suitable buffer for echo_area_buffer[0], and clear it.
6010 Value is what FN returns. */
6013 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6016 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6022 int this_one
, the_other
, clear_buffer_p
, rc
;
6023 int count
= BINDING_STACK_SIZE ();
6025 /* If buffers aren't life, make new ones. */
6026 ensure_echo_area_buffers ();
6031 this_one
= 0, the_other
= 1;
6033 this_one
= 1, the_other
= 0;
6036 this_one
= 0, the_other
= 1;
6039 /* We need a fresh one in case the current echo buffer equals
6040 the one containing the last displayed echo area message. */
6041 if (!NILP (echo_area_buffer
[this_one
])
6042 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6043 echo_area_buffer
[this_one
] = Qnil
;
6046 /* Choose a suitable buffer from echo_buffer[] is we don't
6048 if (NILP (echo_area_buffer
[this_one
]))
6050 echo_area_buffer
[this_one
]
6051 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6052 ? echo_buffer
[the_other
]
6053 : echo_buffer
[this_one
]);
6057 buffer
= echo_area_buffer
[this_one
];
6059 record_unwind_protect (unwind_with_echo_area_buffer
,
6060 with_echo_area_buffer_unwind_data (w
));
6062 /* Make the echo area buffer current. Note that for display
6063 purposes, it is not necessary that the displayed window's buffer
6064 == current_buffer, except for text property lookup. So, let's
6065 only set that buffer temporarily here without doing a full
6066 Fset_window_buffer. We must also change w->pointm, though,
6067 because otherwise an assertions in unshow_buffer fails, and Emacs
6069 set_buffer_internal_1 (XBUFFER (buffer
));
6073 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6076 current_buffer
->undo_list
= Qt
;
6077 current_buffer
->read_only
= Qnil
;
6078 specbind (Qinhibit_read_only
, Qt
);
6080 if (clear_buffer_p
&& Z
> BEG
)
6083 xassert (BEGV
>= BEG
);
6084 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6086 rc
= fn (a1
, a2
, a3
, a4
);
6088 xassert (BEGV
>= BEG
);
6089 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6091 unbind_to (count
, Qnil
);
6096 /* Save state that should be preserved around the call to the function
6097 FN called in with_echo_area_buffer. */
6100 with_echo_area_buffer_unwind_data (w
)
6106 /* Reduce consing by keeping one vector in
6107 Vwith_echo_area_save_vector. */
6108 vector
= Vwith_echo_area_save_vector
;
6109 Vwith_echo_area_save_vector
= Qnil
;
6112 vector
= Fmake_vector (make_number (7), Qnil
);
6114 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6115 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6116 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6120 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6121 AREF (vector
, i
) = w
->buffer
; ++i
;
6122 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6123 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6128 for (; i
< end
; ++i
)
6129 AREF (vector
, i
) = Qnil
;
6132 xassert (i
== ASIZE (vector
));
6137 /* Restore global state from VECTOR which was created by
6138 with_echo_area_buffer_unwind_data. */
6141 unwind_with_echo_area_buffer (vector
)
6144 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6145 Vdeactivate_mark
= AREF (vector
, 1);
6146 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6148 if (WINDOWP (AREF (vector
, 3)))
6151 Lisp_Object buffer
, charpos
, bytepos
;
6153 w
= XWINDOW (AREF (vector
, 3));
6154 buffer
= AREF (vector
, 4);
6155 charpos
= AREF (vector
, 5);
6156 bytepos
= AREF (vector
, 6);
6159 set_marker_both (w
->pointm
, buffer
,
6160 XFASTINT (charpos
), XFASTINT (bytepos
));
6163 Vwith_echo_area_save_vector
= vector
;
6168 /* Set up the echo area for use by print functions. MULTIBYTE_P
6169 non-zero means we will print multibyte. */
6172 setup_echo_area_for_printing (multibyte_p
)
6175 ensure_echo_area_buffers ();
6177 if (!message_buf_print
)
6179 /* A message has been output since the last time we printed.
6180 Choose a fresh echo area buffer. */
6181 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6182 echo_area_buffer
[0] = echo_buffer
[1];
6184 echo_area_buffer
[0] = echo_buffer
[0];
6186 /* Switch to that buffer and clear it. */
6187 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6188 current_buffer
->truncate_lines
= Qnil
;
6192 int count
= BINDING_STACK_SIZE ();
6193 specbind (Qinhibit_read_only
, Qt
);
6195 unbind_to (count
, Qnil
);
6197 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6199 /* Set up the buffer for the multibyteness we need. */
6201 != !NILP (current_buffer
->enable_multibyte_characters
))
6202 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6204 /* Raise the frame containing the echo area. */
6205 if (minibuffer_auto_raise
)
6207 struct frame
*sf
= SELECTED_FRAME ();
6208 Lisp_Object mini_window
;
6209 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6210 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6213 message_log_maybe_newline ();
6214 message_buf_print
= 1;
6218 if (NILP (echo_area_buffer
[0]))
6220 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6221 echo_area_buffer
[0] = echo_buffer
[1];
6223 echo_area_buffer
[0] = echo_buffer
[0];
6226 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6228 /* Someone switched buffers between print requests. */
6229 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6230 current_buffer
->truncate_lines
= Qnil
;
6236 /* Display an echo area message in window W. Value is non-zero if W's
6237 height is changed. If display_last_displayed_message_p is
6238 non-zero, display the message that was last displayed, otherwise
6239 display the current message. */
6242 display_echo_area (w
)
6245 int i
, no_message_p
, window_height_changed_p
, count
;
6247 /* Temporarily disable garbage collections while displaying the echo
6248 area. This is done because a GC can print a message itself.
6249 That message would modify the echo area buffer's contents while a
6250 redisplay of the buffer is going on, and seriously confuse
6252 count
= inhibit_garbage_collection ();
6254 /* If there is no message, we must call display_echo_area_1
6255 nevertheless because it resizes the window. But we will have to
6256 reset the echo_area_buffer in question to nil at the end because
6257 with_echo_area_buffer will sets it to an empty buffer. */
6258 i
= display_last_displayed_message_p
? 1 : 0;
6259 no_message_p
= NILP (echo_area_buffer
[i
]);
6261 window_height_changed_p
6262 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6263 display_echo_area_1
,
6264 (EMACS_INT
) w
, Qnil
, 0, 0);
6267 echo_area_buffer
[i
] = Qnil
;
6269 unbind_to (count
, Qnil
);
6270 return window_height_changed_p
;
6274 /* Helper for display_echo_area. Display the current buffer which
6275 contains the current echo area message in window W, a mini-window,
6276 a pointer to which is passed in A1. A2..A4 are currently not used.
6277 Change the height of W so that all of the message is displayed.
6278 Value is non-zero if height of W was changed. */
6281 display_echo_area_1 (a1
, a2
, a3
, a4
)
6286 struct window
*w
= (struct window
*) a1
;
6288 struct text_pos start
;
6289 int window_height_changed_p
= 0;
6291 /* Do this before displaying, so that we have a large enough glyph
6292 matrix for the display. */
6293 window_height_changed_p
= resize_mini_window (w
, 0);
6296 clear_glyph_matrix (w
->desired_matrix
);
6297 XSETWINDOW (window
, w
);
6298 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6299 try_window (window
, start
);
6301 return window_height_changed_p
;
6305 /* Resize the echo area window to exactly the size needed for the
6306 currently displayed message, if there is one. */
6309 resize_echo_area_axactly ()
6311 if (BUFFERP (echo_area_buffer
[0])
6312 && WINDOWP (echo_area_window
))
6314 struct window
*w
= XWINDOW (echo_area_window
);
6317 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6318 (EMACS_INT
) w
, Qnil
, 0, 0);
6321 ++windows_or_buffers_changed
;
6322 ++update_mode_lines
;
6323 redisplay_internal (0);
6329 /* Callback function for with_echo_area_buffer, when used from
6330 resize_echo_area_axactly. A1 contains a pointer to the window to
6331 resize, A2 to A4 are not used. Value is what resize_mini_window
6335 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6340 return resize_mini_window ((struct window
*) a1
, 1);
6344 /* Resize mini-window W to fit the size of its contents. EXACT:P
6345 means size the window exactly to the size needed. Otherwise, it's
6346 only enlarged until W's buffer is empty. Value is non-zero if
6347 the window height has been changed. */
6350 resize_mini_window (w
, exact_p
)
6354 struct frame
*f
= XFRAME (w
->frame
);
6355 int window_height_changed_p
= 0;
6357 xassert (MINI_WINDOW_P (w
));
6359 /* Nil means don't try to resize. */
6360 if (NILP (Vresize_mini_windows
)
6361 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6364 if (!FRAME_MINIBUF_ONLY_P (f
))
6367 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6368 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6369 int height
, max_height
;
6370 int unit
= CANON_Y_UNIT (f
);
6371 struct text_pos start
;
6372 struct buffer
*old_current_buffer
= NULL
;
6374 if (current_buffer
!= XBUFFER (w
->buffer
))
6376 old_current_buffer
= current_buffer
;
6377 set_buffer_internal (XBUFFER (w
->buffer
));
6380 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6382 /* Compute the max. number of lines specified by the user. */
6383 if (FLOATP (Vmax_mini_window_height
))
6384 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6385 else if (INTEGERP (Vmax_mini_window_height
))
6386 max_height
= XINT (Vmax_mini_window_height
);
6388 max_height
= total_height
/ 4;
6390 /* Correct that max. height if it's bogus. */
6391 max_height
= max (1, max_height
);
6392 max_height
= min (total_height
, max_height
);
6394 /* Find out the height of the text in the window. */
6395 if (it
.truncate_lines_p
)
6400 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6401 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6402 height
= it
.current_y
+ last_height
;
6404 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6405 height
-= it
.extra_line_spacing
;
6406 height
= (height
+ unit
- 1) / unit
;
6409 /* Compute a suitable window start. */
6410 if (height
> max_height
)
6412 height
= max_height
;
6413 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6414 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6415 start
= it
.current
.pos
;
6418 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6419 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6421 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6423 /* Let it grow only, until we display an empty message, in which
6424 case the window shrinks again. */
6425 if (height
> XFASTINT (w
->height
))
6427 int old_height
= XFASTINT (w
->height
);
6428 freeze_window_starts (f
, 1);
6429 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6430 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6432 else if (height
< XFASTINT (w
->height
)
6433 && (exact_p
|| BEGV
== ZV
))
6435 int old_height
= XFASTINT (w
->height
);
6436 freeze_window_starts (f
, 0);
6437 shrink_mini_window (w
);
6438 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6443 /* Always resize to exact size needed. */
6444 if (height
> XFASTINT (w
->height
))
6446 int old_height
= XFASTINT (w
->height
);
6447 freeze_window_starts (f
, 1);
6448 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6449 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6451 else if (height
< XFASTINT (w
->height
))
6453 int old_height
= XFASTINT (w
->height
);
6454 freeze_window_starts (f
, 0);
6455 shrink_mini_window (w
);
6459 freeze_window_starts (f
, 1);
6460 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6463 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6467 if (old_current_buffer
)
6468 set_buffer_internal (old_current_buffer
);
6471 return window_height_changed_p
;
6475 /* Value is the current message, a string, or nil if there is no
6483 if (NILP (echo_area_buffer
[0]))
6487 with_echo_area_buffer (0, 0, current_message_1
,
6488 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6490 echo_area_buffer
[0] = Qnil
;
6498 current_message_1 (a1
, a2
, a3
, a4
)
6503 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6506 *msg
= make_buffer_string (BEG
, Z
, 1);
6513 /* Push the current message on Vmessage_stack for later restauration
6514 by restore_message. Value is non-zero if the current message isn't
6515 empty. This is a relatively infrequent operation, so it's not
6516 worth optimizing. */
6522 msg
= current_message ();
6523 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6524 return STRINGP (msg
);
6528 /* Handler for record_unwind_protect calling pop_message. */
6531 push_message_unwind (dummy
)
6539 /* Restore message display from the top of Vmessage_stack. */
6546 xassert (CONSP (Vmessage_stack
));
6547 msg
= XCAR (Vmessage_stack
);
6549 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6551 message3_nolog (msg
, 0, 0);
6555 /* Pop the top-most entry off Vmessage_stack. */
6560 xassert (CONSP (Vmessage_stack
));
6561 Vmessage_stack
= XCDR (Vmessage_stack
);
6565 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6566 exits. If the stack is not empty, we have a missing pop_message
6570 check_message_stack ()
6572 if (!NILP (Vmessage_stack
))
6577 /* Truncate to NCHARS what will be displayed in the echo area the next
6578 time we display it---but don't redisplay it now. */
6581 truncate_echo_area (nchars
)
6585 echo_area_buffer
[0] = Qnil
;
6586 /* A null message buffer means that the frame hasn't really been
6587 initialized yet. Error messages get reported properly by
6588 cmd_error, so this must be just an informative message; toss it. */
6589 else if (!noninteractive
6591 && !NILP (echo_area_buffer
[0]))
6593 struct frame
*sf
= SELECTED_FRAME ();
6594 if (FRAME_MESSAGE_BUF (sf
))
6595 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6600 /* Helper function for truncate_echo_area. Truncate the current
6601 message to at most NCHARS characters. */
6604 truncate_message_1 (nchars
, a2
, a3
, a4
)
6609 if (BEG
+ nchars
< Z
)
6610 del_range (BEG
+ nchars
, Z
);
6612 echo_area_buffer
[0] = Qnil
;
6617 /* Set the current message to a substring of S or STRING.
6619 If STRING is a Lisp string, set the message to the first NBYTES
6620 bytes from STRING. NBYTES zero means use the whole string. If
6621 STRING is multibyte, the message will be displayed multibyte.
6623 If S is not null, set the message to the first LEN bytes of S. LEN
6624 zero means use the whole string. MULTIBYTE_P non-zero means S is
6625 multibyte. Display the message multibyte in that case. */
6628 set_message (s
, string
, nbytes
, multibyte_p
)
6633 message_enable_multibyte
6634 = ((s
&& multibyte_p
)
6635 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6637 with_echo_area_buffer (0, -1, set_message_1
,
6638 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6639 message_buf_print
= 0;
6640 help_echo_showing_p
= 0;
6644 /* Helper function for set_message. Arguments have the same meaning
6645 as there, with A1 corresponding to S and A2 corresponding to STRING
6646 This function is called with the echo area buffer being
6650 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6653 EMACS_INT nbytes
, multibyte_p
;
6655 char *s
= (char *) a1
;
6656 Lisp_Object string
= a2
;
6660 /* Change multibyteness of the echo buffer appropriately. */
6661 if (message_enable_multibyte
6662 != !NILP (current_buffer
->enable_multibyte_characters
))
6663 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6665 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6667 /* Insert new message at BEG. */
6668 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6670 if (STRINGP (string
))
6675 nbytes
= XSTRING (string
)->size_byte
;
6676 nchars
= string_byte_to_char (string
, nbytes
);
6678 /* This function takes care of single/multibyte conversion. We
6679 just have to ensure that the echo area buffer has the right
6680 setting of enable_multibyte_characters. */
6681 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6686 nbytes
= strlen (s
);
6688 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6690 /* Convert from multi-byte to single-byte. */
6692 unsigned char work
[1];
6694 /* Convert a multibyte string to single-byte. */
6695 for (i
= 0; i
< nbytes
; i
+= n
)
6697 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6698 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6700 : multibyte_char_to_unibyte (c
, Qnil
));
6701 insert_1_both (work
, 1, 1, 1, 0, 0);
6704 else if (!multibyte_p
6705 && !NILP (current_buffer
->enable_multibyte_characters
))
6707 /* Convert from single-byte to multi-byte. */
6709 unsigned char *msg
= (unsigned char *) s
;
6710 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6712 /* Convert a single-byte string to multibyte. */
6713 for (i
= 0; i
< nbytes
; i
++)
6715 c
= unibyte_char_to_multibyte (msg
[i
]);
6716 n
= CHAR_STRING (c
, str
);
6717 insert_1_both (str
, 1, n
, 1, 0, 0);
6721 insert_1 (s
, nbytes
, 1, 0, 0);
6728 /* Clear messages. CURRENT_P non-zero means clear the current
6729 message. LAST_DISPLAYED_P non-zero means clear the message
6733 clear_message (current_p
, last_displayed_p
)
6734 int current_p
, last_displayed_p
;
6737 echo_area_buffer
[0] = Qnil
;
6739 if (last_displayed_p
)
6740 echo_area_buffer
[1] = Qnil
;
6742 message_buf_print
= 0;
6745 /* Clear garbaged frames.
6747 This function is used where the old redisplay called
6748 redraw_garbaged_frames which in turn called redraw_frame which in
6749 turn called clear_frame. The call to clear_frame was a source of
6750 flickering. I believe a clear_frame is not necessary. It should
6751 suffice in the new redisplay to invalidate all current matrices,
6752 and ensure a complete redisplay of all windows. */
6755 clear_garbaged_frames ()
6759 Lisp_Object tail
, frame
;
6761 FOR_EACH_FRAME (tail
, frame
)
6763 struct frame
*f
= XFRAME (frame
);
6765 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6767 clear_current_matrices (f
);
6773 ++windows_or_buffers_changed
;
6778 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6779 is non-zero update selected_frame. Value is non-zero if the
6780 mini-windows height has been changed. */
6783 echo_area_display (update_frame_p
)
6786 Lisp_Object mini_window
;
6789 int window_height_changed_p
= 0;
6790 struct frame
*sf
= SELECTED_FRAME ();
6792 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6793 w
= XWINDOW (mini_window
);
6794 f
= XFRAME (WINDOW_FRAME (w
));
6796 /* Don't display if frame is invisible or not yet initialized. */
6797 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6800 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6802 #ifdef HAVE_WINDOW_SYSTEM
6803 /* When Emacs starts, selected_frame may be a visible terminal
6804 frame, even if we run under a window system. If we let this
6805 through, a message would be displayed on the terminal. */
6806 if (EQ (selected_frame
, Vterminal_frame
)
6807 && !NILP (Vwindow_system
))
6809 #endif /* HAVE_WINDOW_SYSTEM */
6812 /* Redraw garbaged frames. */
6814 clear_garbaged_frames ();
6816 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6818 echo_area_window
= mini_window
;
6819 window_height_changed_p
= display_echo_area (w
);
6820 w
->must_be_updated_p
= 1;
6822 /* Update the display, unless called from redisplay_internal.
6823 Also don't update the screen during redisplay itself. The
6824 update will happen at the end of redisplay, and an update
6825 here could cause confusion. */
6826 if (update_frame_p
&& !redisplaying_p
)
6830 /* If the display update has been interrupted by pending
6831 input, update mode lines in the frame. Due to the
6832 pending input, it might have been that redisplay hasn't
6833 been called, so that mode lines above the echo area are
6834 garbaged. This looks odd, so we prevent it here. */
6835 if (!display_completed
)
6836 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6838 if (window_height_changed_p
6839 /* Don't do this if Emacs is shutting down. Redisplay
6840 needs to run hooks. */
6841 && !NILP (Vrun_hooks
))
6843 /* Must update other windows. Likewise as in other
6844 cases, don't let this update be interrupted by
6846 int count
= BINDING_STACK_SIZE ();
6847 specbind (Qredisplay_dont_pause
, Qt
);
6848 windows_or_buffers_changed
= 1;
6849 redisplay_internal (0);
6850 unbind_to (count
, Qnil
);
6852 else if (FRAME_WINDOW_P (f
) && n
== 0)
6854 /* Window configuration is the same as before.
6855 Can do with a display update of the echo area,
6856 unless we displayed some mode lines. */
6857 update_single_window (w
, 1);
6858 rif
->flush_display (f
);
6861 update_frame (f
, 1, 1);
6863 /* If cursor is in the echo area, make sure that the next
6864 redisplay displays the minibuffer, so that the cursor will
6865 be replaced with what the minibuffer wants. */
6866 if (cursor_in_echo_area
)
6867 ++windows_or_buffers_changed
;
6870 else if (!EQ (mini_window
, selected_window
))
6871 windows_or_buffers_changed
++;
6873 /* Last displayed message is now the current message. */
6874 echo_area_buffer
[1] = echo_area_buffer
[0];
6876 /* Prevent redisplay optimization in redisplay_internal by resetting
6877 this_line_start_pos. This is done because the mini-buffer now
6878 displays the message instead of its buffer text. */
6879 if (EQ (mini_window
, selected_window
))
6880 CHARPOS (this_line_start_pos
) = 0;
6882 return window_height_changed_p
;
6887 /***********************************************************************
6889 ***********************************************************************/
6892 #ifdef HAVE_WINDOW_SYSTEM
6894 /* A buffer for constructing frame titles in it; allocated from the
6895 heap in init_xdisp and resized as needed in store_frame_title_char. */
6897 static char *frame_title_buf
;
6899 /* The buffer's end, and a current output position in it. */
6901 static char *frame_title_buf_end
;
6902 static char *frame_title_ptr
;
6905 /* Store a single character C for the frame title in frame_title_buf.
6906 Re-allocate frame_title_buf if necessary. */
6909 store_frame_title_char (c
)
6912 /* If output position has reached the end of the allocated buffer,
6913 double the buffer's size. */
6914 if (frame_title_ptr
== frame_title_buf_end
)
6916 int len
= frame_title_ptr
- frame_title_buf
;
6917 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6918 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6919 frame_title_buf_end
= frame_title_buf
+ new_size
;
6920 frame_title_ptr
= frame_title_buf
+ len
;
6923 *frame_title_ptr
++ = c
;
6927 /* Store part of a frame title in frame_title_buf, beginning at
6928 frame_title_ptr. STR is the string to store. Do not copy
6929 characters that yield more columns than PRECISION; PRECISION <= 0
6930 means copy the whole string. Pad with spaces until FIELD_WIDTH
6931 number of characters have been copied; FIELD_WIDTH <= 0 means don't
6932 pad. Called from display_mode_element when it is used to build a
6936 store_frame_title (str
, field_width
, precision
)
6938 int field_width
, precision
;
6941 int dummy
, nbytes
, width
;
6943 /* Copy at most PRECISION chars from STR. */
6944 nbytes
= strlen (str
);
6945 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
6947 store_frame_title_char (*str
++);
6949 /* Fill up with spaces until FIELD_WIDTH reached. */
6950 while (field_width
> 0
6953 store_frame_title_char (' ');
6961 /* Set the title of FRAME, if it has changed. The title format is
6962 Vicon_title_format if FRAME is iconified, otherwise it is
6963 frame_title_format. */
6966 x_consider_frame_title (frame
)
6969 struct frame
*f
= XFRAME (frame
);
6971 if (FRAME_WINDOW_P (f
)
6972 || FRAME_MINIBUF_ONLY_P (f
)
6973 || f
->explicit_name
)
6975 /* Do we have more than one visible frame on this X display? */
6978 struct buffer
*obuf
;
6982 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6984 struct frame
*tf
= XFRAME (XCAR (tail
));
6987 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6988 && !FRAME_MINIBUF_ONLY_P (tf
)
6989 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6993 /* Set global variable indicating that multiple frames exist. */
6994 multiple_frames
= CONSP (tail
);
6996 /* Switch to the buffer of selected window of the frame. Set up
6997 frame_title_ptr so that display_mode_element will output into it;
6998 then display the title. */
6999 obuf
= current_buffer
;
7000 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
7001 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7002 frame_title_ptr
= frame_title_buf
;
7003 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7004 NULL
, DEFAULT_FACE_ID
);
7005 display_mode_element (&it
, 0, -1, -1, fmt
);
7006 len
= frame_title_ptr
- frame_title_buf
;
7007 frame_title_ptr
= NULL
;
7008 set_buffer_internal (obuf
);
7010 /* Set the title only if it's changed. This avoids consing in
7011 the common case where it hasn't. (If it turns out that we've
7012 already wasted too much time by walking through the list with
7013 display_mode_element, then we might need to optimize at a
7014 higher level than this.) */
7015 if (! STRINGP (f
->name
)
7016 || STRING_BYTES (XSTRING (f
->name
)) != len
7017 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7018 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7022 #else /* not HAVE_WINDOW_SYSTEM */
7024 #define frame_title_ptr ((char *)0)
7025 #define store_frame_title(str, mincol, maxcol) 0
7027 #endif /* not HAVE_WINDOW_SYSTEM */
7032 /***********************************************************************
7034 ***********************************************************************/
7037 /* Prepare for redisplay by updating menu-bar item lists when
7038 appropriate. This can call eval. */
7041 prepare_menu_bars ()
7044 struct gcpro gcpro1
, gcpro2
;
7046 Lisp_Object tooltip_frame
;
7048 #ifdef HAVE_X_WINDOWS
7049 tooltip_frame
= tip_frame
;
7051 tooltip_frame
= Qnil
;
7054 /* Update all frame titles based on their buffer names, etc. We do
7055 this before the menu bars so that the buffer-menu will show the
7056 up-to-date frame titles. */
7057 #ifdef HAVE_WINDOW_SYSTEM
7058 if (windows_or_buffers_changed
|| update_mode_lines
)
7060 Lisp_Object tail
, frame
;
7062 FOR_EACH_FRAME (tail
, frame
)
7065 if (!EQ (frame
, tooltip_frame
)
7066 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7067 x_consider_frame_title (frame
);
7070 #endif /* HAVE_WINDOW_SYSTEM */
7072 /* Update the menu bar item lists, if appropriate. This has to be
7073 done before any actual redisplay or generation of display lines. */
7074 all_windows
= (update_mode_lines
7075 || buffer_shared
> 1
7076 || windows_or_buffers_changed
);
7079 Lisp_Object tail
, frame
;
7080 int count
= BINDING_STACK_SIZE ();
7082 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7084 FOR_EACH_FRAME (tail
, frame
)
7088 /* Ignore tooltip frame. */
7089 if (EQ (frame
, tooltip_frame
))
7092 /* If a window on this frame changed size, report that to
7093 the user and clear the size-change flag. */
7094 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7096 Lisp_Object functions
;
7098 /* Clear flag first in case we get an error below. */
7099 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7100 functions
= Vwindow_size_change_functions
;
7101 GCPRO2 (tail
, functions
);
7103 while (CONSP (functions
))
7105 call1 (XCAR (functions
), frame
);
7106 functions
= XCDR (functions
);
7112 update_menu_bar (f
, 0);
7113 #ifdef HAVE_WINDOW_SYSTEM
7114 update_tool_bar (f
, 0);
7119 unbind_to (count
, Qnil
);
7123 struct frame
*sf
= SELECTED_FRAME ();
7124 update_menu_bar (sf
, 1);
7125 #ifdef HAVE_WINDOW_SYSTEM
7126 update_tool_bar (sf
, 1);
7130 /* Motif needs this. See comment in xmenu.c. Turn it off when
7131 pending_menu_activation is not defined. */
7132 #ifdef USE_X_TOOLKIT
7133 pending_menu_activation
= 0;
7138 /* Update the menu bar item list for frame F. This has to be done
7139 before we start to fill in any display lines, because it can call
7142 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7145 update_menu_bar (f
, save_match_data
)
7147 int save_match_data
;
7150 register struct window
*w
;
7152 /* If called recursively during a menu update, do nothing. This can
7153 happen when, for instance, an activate-menubar-hook causes a
7155 if (inhibit_menubar_update
)
7158 window
= FRAME_SELECTED_WINDOW (f
);
7159 w
= XWINDOW (window
);
7161 if (update_mode_lines
)
7162 w
->update_mode_line
= Qt
;
7164 if (FRAME_WINDOW_P (f
)
7166 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7167 FRAME_EXTERNAL_MENU_BAR (f
)
7169 FRAME_MENU_BAR_LINES (f
) > 0
7171 : FRAME_MENU_BAR_LINES (f
) > 0)
7173 /* If the user has switched buffers or windows, we need to
7174 recompute to reflect the new bindings. But we'll
7175 recompute when update_mode_lines is set too; that means
7176 that people can use force-mode-line-update to request
7177 that the menu bar be recomputed. The adverse effect on
7178 the rest of the redisplay algorithm is about the same as
7179 windows_or_buffers_changed anyway. */
7180 if (windows_or_buffers_changed
7181 || !NILP (w
->update_mode_line
)
7182 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7183 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7184 != !NILP (w
->last_had_star
))
7185 || ((!NILP (Vtransient_mark_mode
)
7186 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7187 != !NILP (w
->region_showing
)))
7189 struct buffer
*prev
= current_buffer
;
7190 int count
= BINDING_STACK_SIZE ();
7192 specbind (Qinhibit_menubar_update
, Qt
);
7194 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7195 if (save_match_data
)
7196 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7197 if (NILP (Voverriding_local_map_menu_flag
))
7199 specbind (Qoverriding_terminal_local_map
, Qnil
);
7200 specbind (Qoverriding_local_map
, Qnil
);
7203 /* Run the Lucid hook. */
7204 safe_run_hooks (Qactivate_menubar_hook
);
7206 /* If it has changed current-menubar from previous value,
7207 really recompute the menu-bar from the value. */
7208 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7209 call0 (Qrecompute_lucid_menubar
);
7211 safe_run_hooks (Qmenu_bar_update_hook
);
7212 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7214 /* Redisplay the menu bar in case we changed it. */
7215 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7216 if (FRAME_WINDOW_P (f
)
7217 #if defined (macintosh)
7218 /* All frames on Mac OS share the same menubar. So only the
7219 selected frame should be allowed to set it. */
7220 && f
== SELECTED_FRAME ()
7223 set_frame_menubar (f
, 0, 0);
7225 /* On a terminal screen, the menu bar is an ordinary screen
7226 line, and this makes it get updated. */
7227 w
->update_mode_line
= Qt
;
7228 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7229 /* In the non-toolkit version, the menu bar is an ordinary screen
7230 line, and this makes it get updated. */
7231 w
->update_mode_line
= Qt
;
7232 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7234 unbind_to (count
, Qnil
);
7235 set_buffer_internal_1 (prev
);
7242 /***********************************************************************
7244 ***********************************************************************/
7246 #ifdef HAVE_WINDOW_SYSTEM
7248 /* Update the tool-bar item list for frame F. This has to be done
7249 before we start to fill in any display lines. Called from
7250 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7251 and restore it here. */
7254 update_tool_bar (f
, save_match_data
)
7256 int save_match_data
;
7258 if (WINDOWP (f
->tool_bar_window
)
7259 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7264 window
= FRAME_SELECTED_WINDOW (f
);
7265 w
= XWINDOW (window
);
7267 /* If the user has switched buffers or windows, we need to
7268 recompute to reflect the new bindings. But we'll
7269 recompute when update_mode_lines is set too; that means
7270 that people can use force-mode-line-update to request
7271 that the menu bar be recomputed. The adverse effect on
7272 the rest of the redisplay algorithm is about the same as
7273 windows_or_buffers_changed anyway. */
7274 if (windows_or_buffers_changed
7275 || !NILP (w
->update_mode_line
)
7276 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7277 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7278 != !NILP (w
->last_had_star
))
7279 || ((!NILP (Vtransient_mark_mode
)
7280 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7281 != !NILP (w
->region_showing
)))
7283 struct buffer
*prev
= current_buffer
;
7284 int count
= BINDING_STACK_SIZE ();
7286 /* Set current_buffer to the buffer of the selected
7287 window of the frame, so that we get the right local
7289 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7291 /* Save match data, if we must. */
7292 if (save_match_data
)
7293 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7295 /* Make sure that we don't accidentally use bogus keymaps. */
7296 if (NILP (Voverriding_local_map_menu_flag
))
7298 specbind (Qoverriding_terminal_local_map
, Qnil
);
7299 specbind (Qoverriding_local_map
, Qnil
);
7302 /* Build desired tool-bar items from keymaps. */
7304 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7306 /* Redisplay the tool-bar in case we changed it. */
7307 w
->update_mode_line
= Qt
;
7309 unbind_to (count
, Qnil
);
7310 set_buffer_internal_1 (prev
);
7316 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7317 F's desired tool-bar contents. F->tool_bar_items must have
7318 been set up previously by calling prepare_menu_bars. */
7321 build_desired_tool_bar_string (f
)
7324 int i
, size
, size_needed
;
7325 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7326 Lisp_Object image
, plist
, props
;
7328 image
= plist
= props
= Qnil
;
7329 GCPRO3 (image
, plist
, props
);
7331 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7332 Otherwise, make a new string. */
7334 /* The size of the string we might be able to reuse. */
7335 size
= (STRINGP (f
->desired_tool_bar_string
)
7336 ? XSTRING (f
->desired_tool_bar_string
)->size
7339 /* We need one space in the string for each image. */
7340 size_needed
= f
->n_tool_bar_items
;
7342 /* Reuse f->desired_tool_bar_string, if possible. */
7343 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7344 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7348 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7349 Fremove_text_properties (make_number (0), make_number (size
),
7350 props
, f
->desired_tool_bar_string
);
7353 /* Put a `display' property on the string for the images to display,
7354 put a `menu_item' property on tool-bar items with a value that
7355 is the index of the item in F's tool-bar item vector. */
7356 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7358 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7360 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7361 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7362 int hmargin
, vmargin
, relief
, idx
, end
;
7363 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7364 extern Lisp_Object Qlaplace
;
7366 /* If image is a vector, choose the image according to the
7368 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7369 if (VECTORP (image
))
7373 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7374 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7377 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7378 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7380 xassert (ASIZE (image
) >= idx
);
7381 image
= AREF (image
, idx
);
7386 /* Ignore invalid image specifications. */
7387 if (!valid_image_p (image
))
7390 /* Display the tool-bar button pressed, or depressed. */
7391 plist
= Fcopy_sequence (XCDR (image
));
7393 /* Compute margin and relief to draw. */
7394 relief
= (tool_bar_button_relief
> 0
7395 ? tool_bar_button_relief
7396 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7397 hmargin
= vmargin
= relief
;
7399 if (INTEGERP (Vtool_bar_button_margin
)
7400 && XINT (Vtool_bar_button_margin
) > 0)
7402 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7403 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7405 else if (CONSP (Vtool_bar_button_margin
))
7407 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7408 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7409 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7411 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7412 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7413 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7416 if (auto_raise_tool_bar_buttons_p
)
7418 /* Add a `:relief' property to the image spec if the item is
7422 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7429 /* If image is selected, display it pressed, i.e. with a
7430 negative relief. If it's not selected, display it with a
7432 plist
= Fplist_put (plist
, QCrelief
,
7434 ? make_number (-relief
)
7435 : make_number (relief
)));
7440 /* Put a margin around the image. */
7441 if (hmargin
|| vmargin
)
7443 if (hmargin
== vmargin
)
7444 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7446 plist
= Fplist_put (plist
, QCmargin
,
7447 Fcons (make_number (hmargin
),
7448 make_number (vmargin
)));
7451 /* If button is not enabled, and we don't have special images
7452 for the disabled state, make the image appear disabled by
7453 applying an appropriate algorithm to it. */
7454 if (!enabled_p
&& idx
< 0)
7455 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7457 /* Put a `display' text property on the string for the image to
7458 display. Put a `menu-item' property on the string that gives
7459 the start of this item's properties in the tool-bar items
7461 image
= Fcons (Qimage
, plist
);
7462 props
= list4 (Qdisplay
, image
,
7463 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7465 /* Let the last image hide all remaining spaces in the tool bar
7466 string. The string can be longer than needed when we reuse a
7468 if (i
+ 1 == f
->n_tool_bar_items
)
7469 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7472 Fadd_text_properties (make_number (i
), make_number (end
),
7473 props
, f
->desired_tool_bar_string
);
7481 /* Display one line of the tool-bar of frame IT->f. */
7484 display_tool_bar_line (it
)
7487 struct glyph_row
*row
= it
->glyph_row
;
7488 int max_x
= it
->last_visible_x
;
7491 prepare_desired_row (row
);
7492 row
->y
= it
->current_y
;
7494 /* Note that this isn't made use of if the face hasn't a box,
7495 so there's no need to check the face here. */
7496 it
->start_of_box_run_p
= 1;
7498 while (it
->current_x
< max_x
)
7500 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7502 /* Get the next display element. */
7503 if (!get_next_display_element (it
))
7506 /* Produce glyphs. */
7507 x_before
= it
->current_x
;
7508 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7509 PRODUCE_GLYPHS (it
);
7511 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7516 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7518 if (x
+ glyph
->pixel_width
> max_x
)
7520 /* Glyph doesn't fit on line. */
7521 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7527 x
+= glyph
->pixel_width
;
7531 /* Stop at line ends. */
7532 if (ITERATOR_AT_END_OF_LINE_P (it
))
7535 set_iterator_to_next (it
, 1);
7540 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7541 extend_face_to_end_of_line (it
);
7542 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7543 last
->right_box_line_p
= 1;
7544 if (last
== row
->glyphs
[TEXT_AREA
])
7545 last
->left_box_line_p
= 1;
7546 compute_line_metrics (it
);
7548 /* If line is empty, make it occupy the rest of the tool-bar. */
7549 if (!row
->displays_text_p
)
7551 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7552 row
->ascent
= row
->phys_ascent
= 0;
7555 row
->full_width_p
= 1;
7556 row
->continued_p
= 0;
7557 row
->truncated_on_left_p
= 0;
7558 row
->truncated_on_right_p
= 0;
7560 it
->current_x
= it
->hpos
= 0;
7561 it
->current_y
+= row
->height
;
7567 /* Value is the number of screen lines needed to make all tool-bar
7568 items of frame F visible. */
7571 tool_bar_lines_needed (f
)
7574 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7577 /* Initialize an iterator for iteration over
7578 F->desired_tool_bar_string in the tool-bar window of frame F. */
7579 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7580 it
.first_visible_x
= 0;
7581 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7582 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7584 while (!ITERATOR_AT_END_P (&it
))
7586 it
.glyph_row
= w
->desired_matrix
->rows
;
7587 clear_glyph_row (it
.glyph_row
);
7588 display_tool_bar_line (&it
);
7591 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7595 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7597 "Return the number of lines occupied by the tool bar of FRAME.")
7606 frame
= selected_frame
;
7608 CHECK_FRAME (frame
, 0);
7611 if (WINDOWP (f
->tool_bar_window
)
7612 || (w
= XWINDOW (f
->tool_bar_window
),
7613 XFASTINT (w
->height
) > 0))
7615 update_tool_bar (f
, 1);
7616 if (f
->n_tool_bar_items
)
7618 build_desired_tool_bar_string (f
);
7619 nlines
= tool_bar_lines_needed (f
);
7623 return make_number (nlines
);
7627 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7628 height should be changed. */
7631 redisplay_tool_bar (f
)
7636 struct glyph_row
*row
;
7637 int change_height_p
= 0;
7639 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7640 do anything. This means you must start with tool-bar-lines
7641 non-zero to get the auto-sizing effect. Or in other words, you
7642 can turn off tool-bars by specifying tool-bar-lines zero. */
7643 if (!WINDOWP (f
->tool_bar_window
)
7644 || (w
= XWINDOW (f
->tool_bar_window
),
7645 XFASTINT (w
->height
) == 0))
7648 /* Set up an iterator for the tool-bar window. */
7649 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7650 it
.first_visible_x
= 0;
7651 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7654 /* Build a string that represents the contents of the tool-bar. */
7655 build_desired_tool_bar_string (f
);
7656 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7658 /* Display as many lines as needed to display all tool-bar items. */
7659 while (it
.current_y
< it
.last_visible_y
)
7660 display_tool_bar_line (&it
);
7662 /* It doesn't make much sense to try scrolling in the tool-bar
7663 window, so don't do it. */
7664 w
->desired_matrix
->no_scrolling_p
= 1;
7665 w
->must_be_updated_p
= 1;
7667 if (auto_resize_tool_bars_p
)
7671 /* If we couldn't display everything, change the tool-bar's
7673 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7674 change_height_p
= 1;
7676 /* If there are blank lines at the end, except for a partially
7677 visible blank line at the end that is smaller than
7678 CANON_Y_UNIT, change the tool-bar's height. */
7679 row
= it
.glyph_row
- 1;
7680 if (!row
->displays_text_p
7681 && row
->height
>= CANON_Y_UNIT (f
))
7682 change_height_p
= 1;
7684 /* If row displays tool-bar items, but is partially visible,
7685 change the tool-bar's height. */
7686 if (row
->displays_text_p
7687 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7688 change_height_p
= 1;
7690 /* Resize windows as needed by changing the `tool-bar-lines'
7693 && (nlines
= tool_bar_lines_needed (f
),
7694 nlines
!= XFASTINT (w
->height
)))
7696 extern Lisp_Object Qtool_bar_lines
;
7698 int old_height
= XFASTINT (w
->height
);
7700 XSETFRAME (frame
, f
);
7701 clear_glyph_matrix (w
->desired_matrix
);
7702 Fmodify_frame_parameters (frame
,
7703 Fcons (Fcons (Qtool_bar_lines
,
7704 make_number (nlines
)),
7706 if (XFASTINT (w
->height
) != old_height
)
7707 fonts_changed_p
= 1;
7711 return change_height_p
;
7715 /* Get information about the tool-bar item which is displayed in GLYPH
7716 on frame F. Return in *PROP_IDX the index where tool-bar item
7717 properties start in F->tool_bar_items. Value is zero if
7718 GLYPH doesn't display a tool-bar item. */
7721 tool_bar_item_info (f
, glyph
, prop_idx
)
7723 struct glyph
*glyph
;
7729 /* Get the text property `menu-item' at pos. The value of that
7730 property is the start index of this item's properties in
7731 F->tool_bar_items. */
7732 prop
= Fget_text_property (make_number (glyph
->charpos
),
7733 Qmenu_item
, f
->current_tool_bar_string
);
7734 if (INTEGERP (prop
))
7736 *prop_idx
= XINT (prop
);
7745 #endif /* HAVE_WINDOW_SYSTEM */
7749 /************************************************************************
7750 Horizontal scrolling
7751 ************************************************************************/
7753 static int hscroll_window_tree
P_ ((Lisp_Object
));
7754 static int hscroll_windows
P_ ((Lisp_Object
));
7756 /* For all leaf windows in the window tree rooted at WINDOW, set their
7757 hscroll value so that PT is (i) visible in the window, and (ii) so
7758 that it is not within a certain margin at the window's left and
7759 right border. Value is non-zero if any window's hscroll has been
7763 hscroll_window_tree (window
)
7766 int hscrolled_p
= 0;
7768 while (WINDOWP (window
))
7770 struct window
*w
= XWINDOW (window
);
7772 if (WINDOWP (w
->hchild
))
7773 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7774 else if (WINDOWP (w
->vchild
))
7775 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7776 else if (w
->cursor
.vpos
>= 0)
7778 int hscroll_margin
, text_area_x
, text_area_y
;
7779 int text_area_width
, text_area_height
;
7780 struct glyph_row
*current_cursor_row
7781 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7782 struct glyph_row
*desired_cursor_row
7783 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7784 struct glyph_row
*cursor_row
7785 = (desired_cursor_row
->enabled_p
7786 ? desired_cursor_row
7787 : current_cursor_row
);
7789 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7790 &text_area_width
, &text_area_height
);
7792 /* Scroll when cursor is inside this scroll margin. */
7793 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7795 if ((XFASTINT (w
->hscroll
)
7796 && w
->cursor
.x
< hscroll_margin
)
7797 || (cursor_row
->enabled_p
7798 && cursor_row
->truncated_on_right_p
7799 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7803 struct buffer
*saved_current_buffer
;
7806 /* Find point in a display of infinite width. */
7807 saved_current_buffer
= current_buffer
;
7808 current_buffer
= XBUFFER (w
->buffer
);
7810 if (w
== XWINDOW (selected_window
))
7811 pt
= BUF_PT (current_buffer
);
7814 pt
= marker_position (w
->pointm
);
7815 pt
= max (BEGV
, pt
);
7819 /* Move iterator to pt starting at cursor_row->start in
7820 a line with infinite width. */
7821 init_to_row_start (&it
, w
, cursor_row
);
7822 it
.last_visible_x
= INFINITY
;
7823 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7824 current_buffer
= saved_current_buffer
;
7826 /* Center cursor in window. */
7827 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7828 / CANON_X_UNIT (it
.f
));
7829 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
7831 /* Don't call Fset_window_hscroll if value hasn't
7832 changed because it will prevent redisplay
7834 if (XFASTINT (w
->hscroll
) != hscroll
)
7836 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
7837 w
->hscroll
= make_number (hscroll
);
7846 /* Value is non-zero if hscroll of any leaf window has been changed. */
7851 /* Set hscroll so that cursor is visible and not inside horizontal
7852 scroll margins for all windows in the tree rooted at WINDOW. See
7853 also hscroll_window_tree above. Value is non-zero if any window's
7854 hscroll has been changed. If it has, desired matrices on the frame
7855 of WINDOW are cleared. */
7858 hscroll_windows (window
)
7863 if (automatic_hscrolling_p
)
7865 hscrolled_p
= hscroll_window_tree (window
);
7867 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7876 /************************************************************************
7878 ************************************************************************/
7880 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7881 to a non-zero value. This is sometimes handy to have in a debugger
7886 /* First and last unchanged row for try_window_id. */
7888 int debug_first_unchanged_at_end_vpos
;
7889 int debug_last_unchanged_at_beg_vpos
;
7891 /* Delta vpos and y. */
7893 int debug_dvpos
, debug_dy
;
7895 /* Delta in characters and bytes for try_window_id. */
7897 int debug_delta
, debug_delta_bytes
;
7899 /* Values of window_end_pos and window_end_vpos at the end of
7902 int debug_end_pos
, debug_end_vpos
;
7904 /* Append a string to W->desired_matrix->method. FMT is a printf
7905 format string. A1...A9 are a supplement for a variable-length
7906 argument list. If trace_redisplay_p is non-zero also printf the
7907 resulting string to stderr. */
7910 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7913 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7916 char *method
= w
->desired_matrix
->method
;
7917 int len
= strlen (method
);
7918 int size
= sizeof w
->desired_matrix
->method
;
7919 int remaining
= size
- len
- 1;
7921 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7922 if (len
&& remaining
)
7928 strncpy (method
+ len
, buffer
, remaining
);
7930 if (trace_redisplay_p
)
7931 fprintf (stderr
, "%p (%s): %s\n",
7933 ((BUFFERP (w
->buffer
)
7934 && STRINGP (XBUFFER (w
->buffer
)->name
))
7935 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7940 #endif /* GLYPH_DEBUG */
7943 /* This counter is used to clear the face cache every once in a while
7944 in redisplay_internal. It is incremented for each redisplay.
7945 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7948 #define CLEAR_FACE_CACHE_COUNT 10000
7949 static int clear_face_cache_count
;
7951 /* Record the previous terminal frame we displayed. */
7953 static struct frame
*previous_terminal_frame
;
7955 /* Non-zero while redisplay_internal is in progress. */
7960 /* Value is non-zero if all changes in window W, which displays
7961 current_buffer, are in the text between START and END. START is a
7962 buffer position, END is given as a distance from Z. Used in
7963 redisplay_internal for display optimization. */
7966 text_outside_line_unchanged_p (w
, start
, end
)
7970 int unchanged_p
= 1;
7972 /* If text or overlays have changed, see where. */
7973 if (XFASTINT (w
->last_modified
) < MODIFF
7974 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7976 /* Gap in the line? */
7977 if (GPT
< start
|| Z
- GPT
< end
)
7980 /* Changes start in front of the line, or end after it? */
7982 && (BEG_UNCHANGED
< start
- 1
7983 || END_UNCHANGED
< end
))
7986 /* If selective display, can't optimize if changes start at the
7987 beginning of the line. */
7989 && INTEGERP (current_buffer
->selective_display
)
7990 && XINT (current_buffer
->selective_display
) > 0
7991 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7999 /* Do a frame update, taking possible shortcuts into account. This is
8000 the main external entry point for redisplay.
8002 If the last redisplay displayed an echo area message and that message
8003 is no longer requested, we clear the echo area or bring back the
8004 mini-buffer if that is in use. */
8009 redisplay_internal (0);
8012 /* Return 1 if point moved out of or into a composition. Otherwise
8013 return 0. PREV_BUF and PREV_PT are the last point buffer and
8014 position. BUF and PT are the current point buffer and position. */
8017 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8018 struct buffer
*prev_buf
, *buf
;
8025 XSETBUFFER (buffer
, buf
);
8026 /* Check a composition at the last point if point moved within the
8028 if (prev_buf
== buf
)
8031 /* Point didn't move. */
8034 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8035 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8036 && COMPOSITION_VALID_P (start
, end
, prop
)
8037 && start
< prev_pt
&& end
> prev_pt
)
8038 /* The last point was within the composition. Return 1 iff
8039 point moved out of the composition. */
8040 return (pt
<= start
|| pt
>= end
);
8043 /* Check a composition at the current point. */
8044 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8045 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8046 && COMPOSITION_VALID_P (start
, end
, prop
)
8047 && start
< pt
&& end
> pt
);
8050 /* Reconsider the setting of B->clip_changed which is displayed
8054 reconsider_clip_changes (w
, b
)
8058 if (b
->prevent_redisplay_optimizations_p
)
8059 b
->clip_changed
= 1;
8060 else if (b
->clip_changed
8061 && !NILP (w
->window_end_valid
)
8062 && w
->current_matrix
->buffer
== b
8063 && w
->current_matrix
->zv
== BUF_ZV (b
)
8064 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8065 b
->clip_changed
= 0;
8067 /* If display wasn't paused, and W is not a tool bar window, see if
8068 point has been moved into or out of a composition. In that case,
8069 we set b->clip_changed to 1 to force updating the screen. If
8070 b->clip_changed has already been set to 1, we can skip this
8072 if (!b
->clip_changed
8073 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8077 if (w
== XWINDOW (selected_window
))
8078 pt
= BUF_PT (current_buffer
);
8080 pt
= marker_position (w
->pointm
);
8082 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8083 || pt
!= XINT (w
->last_point
))
8084 && check_point_in_composition (w
->current_matrix
->buffer
,
8085 XINT (w
->last_point
),
8086 XBUFFER (w
->buffer
), pt
))
8087 b
->clip_changed
= 1;
8092 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8093 response to any user action; therefore, we should preserve the echo
8094 area. (Actually, our caller does that job.) Perhaps in the future
8095 avoid recentering windows if it is not necessary; currently that
8096 causes some problems. */
8099 redisplay_internal (preserve_echo_area
)
8100 int preserve_echo_area
;
8102 struct window
*w
= XWINDOW (selected_window
);
8103 struct frame
*f
= XFRAME (w
->frame
);
8105 int must_finish
= 0;
8106 struct text_pos tlbufpos
, tlendpos
;
8107 int number_of_visible_frames
;
8109 struct frame
*sf
= SELECTED_FRAME ();
8111 /* Non-zero means redisplay has to consider all windows on all
8112 frames. Zero means, only selected_window is considered. */
8113 int consider_all_windows_p
;
8115 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8117 /* No redisplay if running in batch mode or frame is not yet fully
8118 initialized, or redisplay is explicitly turned off by setting
8119 Vinhibit_redisplay. */
8121 || !NILP (Vinhibit_redisplay
)
8122 || !f
->glyphs_initialized_p
)
8125 /* The flag redisplay_performed_directly_p is set by
8126 direct_output_for_insert when it already did the whole screen
8127 update necessary. */
8128 if (redisplay_performed_directly_p
)
8130 redisplay_performed_directly_p
= 0;
8131 if (!hscroll_windows (selected_window
))
8135 #ifdef USE_X_TOOLKIT
8136 if (popup_activated ())
8140 /* I don't think this happens but let's be paranoid. */
8144 /* Record a function that resets redisplaying_p to its old value
8145 when we leave this function. */
8146 count
= BINDING_STACK_SIZE ();
8147 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8152 reconsider_clip_changes (w
, current_buffer
);
8154 /* If new fonts have been loaded that make a glyph matrix adjustment
8155 necessary, do it. */
8156 if (fonts_changed_p
)
8158 adjust_glyphs (NULL
);
8159 ++windows_or_buffers_changed
;
8160 fonts_changed_p
= 0;
8163 /* If face_change_count is non-zero, init_iterator will free all
8164 realized faces, which includes the faces referenced from current
8165 matrices. So, we can't reuse current matrices in this case. */
8166 if (face_change_count
)
8167 ++windows_or_buffers_changed
;
8169 if (! FRAME_WINDOW_P (sf
)
8170 && previous_terminal_frame
!= sf
)
8172 /* Since frames on an ASCII terminal share the same display
8173 area, displaying a different frame means redisplay the whole
8175 windows_or_buffers_changed
++;
8176 SET_FRAME_GARBAGED (sf
);
8177 XSETFRAME (Vterminal_frame
, sf
);
8179 previous_terminal_frame
= sf
;
8181 /* Set the visible flags for all frames. Do this before checking
8182 for resized or garbaged frames; they want to know if their frames
8183 are visible. See the comment in frame.h for
8184 FRAME_SAMPLE_VISIBILITY. */
8186 Lisp_Object tail
, frame
;
8188 number_of_visible_frames
= 0;
8190 FOR_EACH_FRAME (tail
, frame
)
8192 struct frame
*f
= XFRAME (frame
);
8194 FRAME_SAMPLE_VISIBILITY (f
);
8195 if (FRAME_VISIBLE_P (f
))
8196 ++number_of_visible_frames
;
8197 clear_desired_matrices (f
);
8201 /* Notice any pending interrupt request to change frame size. */
8202 do_pending_window_change (1);
8204 /* Clear frames marked as garbaged. */
8206 clear_garbaged_frames ();
8208 /* Build menubar and tool-bar items. */
8209 prepare_menu_bars ();
8211 if (windows_or_buffers_changed
)
8212 update_mode_lines
++;
8214 /* Detect case that we need to write or remove a star in the mode line. */
8215 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8217 w
->update_mode_line
= Qt
;
8218 if (buffer_shared
> 1)
8219 update_mode_lines
++;
8222 /* If %c is in the mode line, update it if needed. */
8223 if (!NILP (w
->column_number_displayed
)
8224 /* This alternative quickly identifies a common case
8225 where no change is needed. */
8226 && !(PT
== XFASTINT (w
->last_point
)
8227 && XFASTINT (w
->last_modified
) >= MODIFF
8228 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8229 && XFASTINT (w
->column_number_displayed
) != current_column ())
8230 w
->update_mode_line
= Qt
;
8232 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8234 /* The variable buffer_shared is set in redisplay_window and
8235 indicates that we redisplay a buffer in different windows. See
8237 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8239 /* If specs for an arrow have changed, do thorough redisplay
8240 to ensure we remove any arrow that should no longer exist. */
8241 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8242 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8243 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8245 /* Normally the message* functions will have already displayed and
8246 updated the echo area, but the frame may have been trashed, or
8247 the update may have been preempted, so display the echo area
8248 again here. Checking both message buffers captures the case that
8249 the echo area should be cleared. */
8250 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
8252 int window_height_changed_p
= echo_area_display (0);
8255 if (fonts_changed_p
)
8257 else if (window_height_changed_p
)
8259 consider_all_windows_p
= 1;
8260 ++update_mode_lines
;
8261 ++windows_or_buffers_changed
;
8263 /* If window configuration was changed, frames may have been
8264 marked garbaged. Clear them or we will experience
8265 surprises wrt scrolling. */
8267 clear_garbaged_frames ();
8270 else if (EQ (selected_window
, minibuf_window
)
8271 && (current_buffer
->clip_changed
8272 || XFASTINT (w
->last_modified
) < MODIFF
8273 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8274 && resize_mini_window (w
, 0))
8276 /* Resized active mini-window to fit the size of what it is
8277 showing if its contents might have changed. */
8279 consider_all_windows_p
= 1;
8280 ++windows_or_buffers_changed
;
8281 ++update_mode_lines
;
8283 /* If window configuration was changed, frames may have been
8284 marked garbaged. Clear them or we will experience
8285 surprises wrt scrolling. */
8287 clear_garbaged_frames ();
8291 /* If showing the region, and mark has changed, we must redisplay
8292 the whole window. The assignment to this_line_start_pos prevents
8293 the optimization directly below this if-statement. */
8294 if (((!NILP (Vtransient_mark_mode
)
8295 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8296 != !NILP (w
->region_showing
))
8297 || (!NILP (w
->region_showing
)
8298 && !EQ (w
->region_showing
,
8299 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8300 CHARPOS (this_line_start_pos
) = 0;
8302 /* Optimize the case that only the line containing the cursor in the
8303 selected window has changed. Variables starting with this_ are
8304 set in display_line and record information about the line
8305 containing the cursor. */
8306 tlbufpos
= this_line_start_pos
;
8307 tlendpos
= this_line_end_pos
;
8308 if (!consider_all_windows_p
8309 && CHARPOS (tlbufpos
) > 0
8310 && NILP (w
->update_mode_line
)
8311 && !current_buffer
->clip_changed
8312 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8313 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8314 /* Make sure recorded data applies to current buffer, etc. */
8315 && this_line_buffer
== current_buffer
8316 && current_buffer
== XBUFFER (w
->buffer
)
8317 && NILP (w
->force_start
)
8318 /* Point must be on the line that we have info recorded about. */
8319 && PT
>= CHARPOS (tlbufpos
)
8320 && PT
<= Z
- CHARPOS (tlendpos
)
8321 /* All text outside that line, including its final newline,
8322 must be unchanged */
8323 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8324 CHARPOS (tlendpos
)))
8326 if (CHARPOS (tlbufpos
) > BEGV
8327 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8328 && (CHARPOS (tlbufpos
) == ZV
8329 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8330 /* Former continuation line has disappeared by becoming empty */
8332 else if (XFASTINT (w
->last_modified
) < MODIFF
8333 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8334 || MINI_WINDOW_P (w
))
8336 /* We have to handle the case of continuation around a
8337 wide-column character (See the comment in indent.c around
8340 For instance, in the following case:
8342 -------- Insert --------
8343 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8344 J_I_ ==> J_I_ `^^' are cursors.
8348 As we have to redraw the line above, we should goto cancel. */
8351 int line_height_before
= this_line_pixel_height
;
8353 /* Note that start_display will handle the case that the
8354 line starting at tlbufpos is a continuation lines. */
8355 start_display (&it
, w
, tlbufpos
);
8357 /* Implementation note: It this still necessary? */
8358 if (it
.current_x
!= this_line_start_x
)
8361 TRACE ((stderr
, "trying display optimization 1\n"));
8362 w
->cursor
.vpos
= -1;
8363 overlay_arrow_seen
= 0;
8364 it
.vpos
= this_line_vpos
;
8365 it
.current_y
= this_line_y
;
8366 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8369 /* If line contains point, is not continued,
8370 and ends at same distance from eob as before, we win */
8371 if (w
->cursor
.vpos
>= 0
8372 /* Line is not continued, otherwise this_line_start_pos
8373 would have been set to 0 in display_line. */
8374 && CHARPOS (this_line_start_pos
)
8375 /* Line ends as before. */
8376 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8377 /* Line has same height as before. Otherwise other lines
8378 would have to be shifted up or down. */
8379 && this_line_pixel_height
== line_height_before
)
8381 /* If this is not the window's last line, we must adjust
8382 the charstarts of the lines below. */
8383 if (it
.current_y
< it
.last_visible_y
)
8385 struct glyph_row
*row
8386 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8387 int delta
, delta_bytes
;
8389 if (Z
- CHARPOS (tlendpos
) == ZV
)
8391 /* This line ends at end of (accessible part of)
8392 buffer. There is no newline to count. */
8394 - CHARPOS (tlendpos
)
8395 - MATRIX_ROW_START_CHARPOS (row
));
8396 delta_bytes
= (Z_BYTE
8397 - BYTEPOS (tlendpos
)
8398 - MATRIX_ROW_START_BYTEPOS (row
));
8402 /* This line ends in a newline. Must take
8403 account of the newline and the rest of the
8404 text that follows. */
8406 - CHARPOS (tlendpos
)
8407 - MATRIX_ROW_START_CHARPOS (row
));
8408 delta_bytes
= (Z_BYTE
8409 - BYTEPOS (tlendpos
)
8410 - MATRIX_ROW_START_BYTEPOS (row
));
8413 increment_matrix_positions (w
->current_matrix
,
8415 w
->current_matrix
->nrows
,
8416 delta
, delta_bytes
);
8419 /* If this row displays text now but previously didn't,
8420 or vice versa, w->window_end_vpos may have to be
8422 if ((it
.glyph_row
- 1)->displays_text_p
)
8424 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8425 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8427 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8428 && this_line_vpos
> 0)
8429 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8430 w
->window_end_valid
= Qnil
;
8432 /* Update hint: No need to try to scroll in update_window. */
8433 w
->desired_matrix
->no_scrolling_p
= 1;
8436 *w
->desired_matrix
->method
= 0;
8437 debug_method_add (w
, "optimization 1");
8444 else if (/* Cursor position hasn't changed. */
8445 PT
== XFASTINT (w
->last_point
)
8446 /* Make sure the cursor was last displayed
8447 in this window. Otherwise we have to reposition it. */
8448 && 0 <= w
->cursor
.vpos
8449 && XINT (w
->height
) > w
->cursor
.vpos
)
8453 do_pending_window_change (1);
8455 /* We used to always goto end_of_redisplay here, but this
8456 isn't enough if we have a blinking cursor. */
8457 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8458 goto end_of_redisplay
;
8462 /* If highlighting the region, or if the cursor is in the echo area,
8463 then we can't just move the cursor. */
8464 else if (! (!NILP (Vtransient_mark_mode
)
8465 && !NILP (current_buffer
->mark_active
))
8466 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8467 || highlight_nonselected_windows
)
8468 && NILP (w
->region_showing
)
8469 && NILP (Vshow_trailing_whitespace
)
8470 && !cursor_in_echo_area
)
8473 struct glyph_row
*row
;
8475 /* Skip from tlbufpos to PT and see where it is. Note that
8476 PT may be in invisible text. If so, we will end at the
8477 next visible position. */
8478 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8479 NULL
, DEFAULT_FACE_ID
);
8480 it
.current_x
= this_line_start_x
;
8481 it
.current_y
= this_line_y
;
8482 it
.vpos
= this_line_vpos
;
8484 /* The call to move_it_to stops in front of PT, but
8485 moves over before-strings. */
8486 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8488 if (it
.vpos
== this_line_vpos
8489 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8492 xassert (this_line_vpos
== it
.vpos
);
8493 xassert (this_line_y
== it
.current_y
);
8494 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8502 /* Text changed drastically or point moved off of line. */
8503 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8506 CHARPOS (this_line_start_pos
) = 0;
8507 consider_all_windows_p
|= buffer_shared
> 1;
8508 ++clear_face_cache_count
;
8511 /* Build desired matrices, and update the display. If
8512 consider_all_windows_p is non-zero, do it for all windows on all
8513 frames. Otherwise do it for selected_window, only. */
8515 if (consider_all_windows_p
)
8517 Lisp_Object tail
, frame
;
8518 int i
, n
= 0, size
= 50;
8519 struct frame
**updated
8520 = (struct frame
**) alloca (size
* sizeof *updated
);
8522 /* Clear the face cache eventually. */
8523 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8525 clear_face_cache (0);
8526 clear_face_cache_count
= 0;
8529 /* Recompute # windows showing selected buffer. This will be
8530 incremented each time such a window is displayed. */
8533 FOR_EACH_FRAME (tail
, frame
)
8535 struct frame
*f
= XFRAME (frame
);
8537 if (FRAME_WINDOW_P (f
) || f
== sf
)
8539 /* Mark all the scroll bars to be removed; we'll redeem
8540 the ones we want when we redisplay their windows. */
8541 if (condemn_scroll_bars_hook
)
8542 condemn_scroll_bars_hook (f
);
8544 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8545 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8547 /* Any scroll bars which redisplay_windows should have
8548 nuked should now go away. */
8549 if (judge_scroll_bars_hook
)
8550 judge_scroll_bars_hook (f
);
8552 /* If fonts changed, display again. */
8553 if (fonts_changed_p
)
8556 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8558 /* See if we have to hscroll. */
8559 if (hscroll_windows (f
->root_window
))
8562 /* Prevent various kinds of signals during display
8563 update. stdio is not robust about handling
8564 signals, which can cause an apparent I/O
8566 if (interrupt_input
)
8570 /* Update the display. */
8571 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8572 pause
|= update_frame (f
, 0, 0);
8578 int nbytes
= size
* sizeof *updated
;
8579 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8580 bcopy (updated
, p
, nbytes
);
8589 /* Do the mark_window_display_accurate after all windows have
8590 been redisplayed because this call resets flags in buffers
8591 which are needed for proper redisplay. */
8592 for (i
= 0; i
< n
; ++i
)
8594 struct frame
*f
= updated
[i
];
8595 mark_window_display_accurate (f
->root_window
, 1);
8596 if (frame_up_to_date_hook
)
8597 frame_up_to_date_hook (f
);
8600 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8602 Lisp_Object mini_window
;
8603 struct frame
*mini_frame
;
8605 redisplay_window (selected_window
, 1);
8607 /* Compare desired and current matrices, perform output. */
8610 /* If fonts changed, display again. */
8611 if (fonts_changed_p
)
8614 /* Prevent various kinds of signals during display update.
8615 stdio is not robust about handling signals,
8616 which can cause an apparent I/O error. */
8617 if (interrupt_input
)
8621 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8623 if (hscroll_windows (selected_window
))
8626 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8627 pause
= update_frame (sf
, 0, 0);
8630 /* We may have called echo_area_display at the top of this
8631 function. If the echo area is on another frame, that may
8632 have put text on a frame other than the selected one, so the
8633 above call to update_frame would not have caught it. Catch
8635 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8636 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8638 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8640 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8641 pause
|= update_frame (mini_frame
, 0, 0);
8642 if (!pause
&& hscroll_windows (mini_window
))
8647 /* If display was paused because of pending input, make sure we do a
8648 thorough update the next time. */
8651 /* Prevent the optimization at the beginning of
8652 redisplay_internal that tries a single-line update of the
8653 line containing the cursor in the selected window. */
8654 CHARPOS (this_line_start_pos
) = 0;
8656 /* Let the overlay arrow be updated the next time. */
8657 if (!NILP (last_arrow_position
))
8659 last_arrow_position
= Qt
;
8660 last_arrow_string
= Qt
;
8663 /* If we pause after scrolling, some rows in the current
8664 matrices of some windows are not valid. */
8665 if (!WINDOW_FULL_WIDTH_P (w
)
8666 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8667 update_mode_lines
= 1;
8670 /* Now text on frame agrees with windows, so put info into the
8671 windows for partial redisplay to follow. */
8674 register struct buffer
*b
= XBUFFER (w
->buffer
);
8676 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8677 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8678 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8679 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8681 if (consider_all_windows_p
)
8682 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
8685 XSETFASTINT (w
->last_point
, BUF_PT (b
));
8686 w
->last_cursor
= w
->cursor
;
8687 w
->last_cursor_off_p
= w
->cursor_off_p
;
8689 b
->clip_changed
= 0;
8690 b
->prevent_redisplay_optimizations_p
= 0;
8691 w
->update_mode_line
= Qnil
;
8692 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
8693 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
8695 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8698 /* Record if we are showing a region, so can make sure to
8699 update it fully at next redisplay. */
8700 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
8701 && (EQ (selected_window
,
8702 current_buffer
->last_selected_window
)
8703 || highlight_nonselected_windows
)
8704 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
8705 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
8708 w
->window_end_valid
= w
->buffer
;
8709 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8710 last_arrow_string
= Voverlay_arrow_string
;
8711 if (frame_up_to_date_hook
!= 0)
8712 (*frame_up_to_date_hook
) (sf
);
8714 w
->current_matrix
->buffer
= b
;
8715 w
->current_matrix
->begv
= BUF_BEGV (b
);
8716 w
->current_matrix
->zv
= BUF_ZV (b
);
8719 update_mode_lines
= 0;
8720 windows_or_buffers_changed
= 0;
8723 /* Start SIGIO interrupts coming again. Having them off during the
8724 code above makes it less likely one will discard output, but not
8725 impossible, since there might be stuff in the system buffer here.
8726 But it is much hairier to try to do anything about that. */
8727 if (interrupt_input
)
8731 /* If a frame has become visible which was not before, redisplay
8732 again, so that we display it. Expose events for such a frame
8733 (which it gets when becoming visible) don't call the parts of
8734 redisplay constructing glyphs, so simply exposing a frame won't
8735 display anything in this case. So, we have to display these
8736 frames here explicitly. */
8739 Lisp_Object tail
, frame
;
8742 FOR_EACH_FRAME (tail
, frame
)
8744 int this_is_visible
= 0;
8746 if (XFRAME (frame
)->visible
)
8747 this_is_visible
= 1;
8748 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8749 if (XFRAME (frame
)->visible
)
8750 this_is_visible
= 1;
8752 if (this_is_visible
)
8756 if (new_count
!= number_of_visible_frames
)
8757 windows_or_buffers_changed
++;
8760 /* Change frame size now if a change is pending. */
8761 do_pending_window_change (1);
8763 /* If we just did a pending size change, or have additional
8764 visible frames, redisplay again. */
8765 if (windows_or_buffers_changed
&& !pause
)
8770 unbind_to (count
, Qnil
);
8774 /* Redisplay, but leave alone any recent echo area message unless
8775 another message has been requested in its place.
8777 This is useful in situations where you need to redisplay but no
8778 user action has occurred, making it inappropriate for the message
8779 area to be cleared. See tracking_off and
8780 wait_reading_process_input for examples of these situations.
8782 FROM_WHERE is an integer saying from where this function was
8783 called. This is useful for debugging. */
8786 redisplay_preserve_echo_area (from_where
)
8789 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
8791 if (!NILP (echo_area_buffer
[1]))
8793 /* We have a previously displayed message, but no current
8794 message. Redisplay the previous message. */
8795 display_last_displayed_message_p
= 1;
8796 redisplay_internal (1);
8797 display_last_displayed_message_p
= 0;
8800 redisplay_internal (1);
8804 /* Function registered with record_unwind_protect in
8805 redisplay_internal. Clears the flag indicating that a redisplay is
8809 unwind_redisplay (old_redisplaying_p
)
8810 Lisp_Object old_redisplaying_p
;
8812 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8817 /* Mark the display of windows in the window tree rooted at WINDOW as
8818 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
8819 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
8820 the next time redisplay_internal is called. */
8823 mark_window_display_accurate (window
, accurate_p
)
8829 for (; !NILP (window
); window
= w
->next
)
8831 w
= XWINDOW (window
);
8833 if (BUFFERP (w
->buffer
))
8835 struct buffer
*b
= XBUFFER (w
->buffer
);
8837 XSETFASTINT (w
->last_modified
,
8838 accurate_p
? BUF_MODIFF (b
) : 0);
8839 XSETFASTINT (w
->last_overlay_modified
,
8840 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8841 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
8844 #if 0 /* I don't think this is necessary because display_line does it.
8846 /* Record if we are showing a region, so can make sure to
8847 update it fully at next redisplay. */
8849 = (!NILP (Vtransient_mark_mode
)
8850 && (w
== XWINDOW (current_buffer
->last_selected_window
)
8851 || highlight_nonselected_windows
)
8852 && (!NILP (b
->mark_active
)
8853 ? Fmarker_position (b
->mark
)
8859 b
->clip_changed
= 0;
8860 b
->prevent_redisplay_optimizations_p
= 0;
8861 w
->current_matrix
->buffer
= b
;
8862 w
->current_matrix
->begv
= BUF_BEGV (b
);
8863 w
->current_matrix
->zv
= BUF_ZV (b
);
8864 w
->last_cursor
= w
->cursor
;
8865 w
->last_cursor_off_p
= w
->cursor_off_p
;
8866 if (w
== XWINDOW (selected_window
))
8867 w
->last_point
= make_number (BUF_PT (b
));
8869 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8873 w
->window_end_valid
= w
->buffer
;
8874 w
->update_mode_line
= Qnil
;
8876 if (!NILP (w
->vchild
))
8877 mark_window_display_accurate (w
->vchild
, accurate_p
);
8878 if (!NILP (w
->hchild
))
8879 mark_window_display_accurate (w
->hchild
, accurate_p
);
8884 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8885 last_arrow_string
= Voverlay_arrow_string
;
8889 /* Force a thorough redisplay the next time by setting
8890 last_arrow_position and last_arrow_string to t, which is
8891 unequal to any useful value of Voverlay_arrow_... */
8892 last_arrow_position
= Qt
;
8893 last_arrow_string
= Qt
;
8898 /* Return value in display table DP (Lisp_Char_Table *) for character
8899 C. Since a display table doesn't have any parent, we don't have to
8900 follow parent. Do not call this function directly but use the
8901 macro DISP_CHAR_VECTOR. */
8904 disp_char_vector (dp
, c
)
8905 struct Lisp_Char_Table
*dp
;
8911 if (SINGLE_BYTE_CHAR_P (c
))
8912 return (dp
->contents
[c
]);
8914 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8917 else if (code
[2] < 32)
8920 /* Here, the possible range of code[0] (== charset ID) is
8921 128..max_charset. Since the top level char table contains data
8922 for multibyte characters after 256th element, we must increment
8923 code[0] by 128 to get a correct index. */
8925 code
[3] = -1; /* anchor */
8927 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8929 val
= dp
->contents
[code
[i
]];
8930 if (!SUB_CHAR_TABLE_P (val
))
8931 return (NILP (val
) ? dp
->defalt
: val
);
8934 /* Here, val is a sub char table. We return the default value of
8936 return (dp
->defalt
);
8941 /***********************************************************************
8943 ***********************************************************************/
8945 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8948 redisplay_windows (window
)
8951 while (!NILP (window
))
8953 struct window
*w
= XWINDOW (window
);
8955 if (!NILP (w
->hchild
))
8956 redisplay_windows (w
->hchild
);
8957 else if (!NILP (w
->vchild
))
8958 redisplay_windows (w
->vchild
);
8960 redisplay_window (window
, 0);
8967 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8968 DELTA is the number of bytes by which positions recorded in ROW
8969 differ from current buffer positions. */
8972 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8974 struct glyph_row
*row
;
8975 struct glyph_matrix
*matrix
;
8976 int delta
, delta_bytes
, dy
, dvpos
;
8978 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8979 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8981 int pt_old
= PT
- delta
;
8983 /* Skip over glyphs not having an object at the start of the row.
8984 These are special glyphs like truncation marks on terminal
8986 if (row
->displays_text_p
)
8988 && INTEGERP (glyph
->object
)
8989 && glyph
->charpos
< 0)
8991 x
+= glyph
->pixel_width
;
8996 && !INTEGERP (glyph
->object
)
8997 && (!BUFFERP (glyph
->object
)
8998 || glyph
->charpos
< pt_old
))
9000 x
+= glyph
->pixel_width
;
9004 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9006 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9007 w
->cursor
.y
= row
->y
+ dy
;
9009 if (w
== XWINDOW (selected_window
))
9011 if (!row
->continued_p
9012 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9015 this_line_buffer
= XBUFFER (w
->buffer
);
9017 CHARPOS (this_line_start_pos
)
9018 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9019 BYTEPOS (this_line_start_pos
)
9020 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9022 CHARPOS (this_line_end_pos
)
9023 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9024 BYTEPOS (this_line_end_pos
)
9025 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9027 this_line_y
= w
->cursor
.y
;
9028 this_line_pixel_height
= row
->height
;
9029 this_line_vpos
= w
->cursor
.vpos
;
9030 this_line_start_x
= row
->x
;
9033 CHARPOS (this_line_start_pos
) = 0;
9038 /* Run window scroll functions, if any, for WINDOW with new window
9039 start STARTP. Sets the window start of WINDOW to that position.
9041 We assume that the window's buffer is really current. */
9043 static INLINE
struct text_pos
9044 run_window_scroll_functions (window
, startp
)
9046 struct text_pos startp
;
9048 struct window
*w
= XWINDOW (window
);
9049 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9051 if (current_buffer
!= XBUFFER (w
->buffer
))
9054 if (!NILP (Vwindow_scroll_functions
))
9056 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9057 make_number (CHARPOS (startp
)));
9058 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9059 /* In case the hook functions switch buffers. */
9060 if (current_buffer
!= XBUFFER (w
->buffer
))
9061 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9068 /* Modify the desired matrix of window W and W->vscroll so that the
9069 line containing the cursor is fully visible. */
9072 make_cursor_line_fully_visible (w
)
9075 struct glyph_matrix
*matrix
;
9076 struct glyph_row
*row
;
9079 /* It's not always possible to find the cursor, e.g, when a window
9080 is full of overlay strings. Don't do anything in that case. */
9081 if (w
->cursor
.vpos
< 0)
9084 matrix
= w
->desired_matrix
;
9085 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9087 /* If the cursor row is not partially visible, there's nothing
9089 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9092 /* If the row the cursor is in is taller than the window's height,
9093 it's not clear what to do, so do nothing. */
9094 window_height
= window_box_height (w
);
9095 if (row
->height
>= window_height
)
9098 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9100 int dy
= row
->height
- row
->visible_height
;
9103 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9105 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9107 int dy
= - (row
->height
- row
->visible_height
);
9110 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9113 /* When we change the cursor y-position of the selected window,
9114 change this_line_y as well so that the display optimization for
9115 the cursor line of the selected window in redisplay_internal uses
9116 the correct y-position. */
9117 if (w
== XWINDOW (selected_window
))
9118 this_line_y
= w
->cursor
.y
;
9122 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9123 non-zero means only WINDOW is redisplayed in redisplay_internal.
9124 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9125 in redisplay_window to bring a partially visible line into view in
9126 the case that only the cursor has moved.
9130 1 if scrolling succeeded
9132 0 if scrolling didn't find point.
9134 -1 if new fonts have been loaded so that we must interrupt
9135 redisplay, adjust glyph matrices, and try again. */
9138 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9139 scroll_step
, temp_scroll_step
)
9141 int just_this_one_p
;
9142 int scroll_conservatively
, scroll_step
;
9143 int temp_scroll_step
;
9145 struct window
*w
= XWINDOW (window
);
9146 struct frame
*f
= XFRAME (w
->frame
);
9147 struct text_pos scroll_margin_pos
;
9148 struct text_pos pos
;
9149 struct text_pos startp
;
9151 Lisp_Object window_end
;
9152 int this_scroll_margin
;
9156 int amount_to_scroll
= 0;
9157 Lisp_Object aggressive
;
9161 debug_method_add (w
, "try_scrolling");
9164 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9166 /* Compute scroll margin height in pixels. We scroll when point is
9167 within this distance from the top or bottom of the window. */
9168 if (scroll_margin
> 0)
9170 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9171 this_scroll_margin
*= CANON_Y_UNIT (f
);
9174 this_scroll_margin
= 0;
9176 /* Compute how much we should try to scroll maximally to bring point
9178 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9179 scroll_max
= max (scroll_step
,
9180 max (scroll_conservatively
, temp_scroll_step
));
9181 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9182 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9183 /* We're trying to scroll because of aggressive scrolling
9184 but no scroll_step is set. Choose an arbitrary one. Maybe
9185 there should be a variable for this. */
9189 scroll_max
*= CANON_Y_UNIT (f
);
9191 /* Decide whether we have to scroll down. Start at the window end
9192 and move this_scroll_margin up to find the position of the scroll
9194 window_end
= Fwindow_end (window
, Qt
);
9195 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9196 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9197 if (this_scroll_margin
)
9199 start_display (&it
, w
, scroll_margin_pos
);
9200 move_it_vertically (&it
, - this_scroll_margin
);
9201 scroll_margin_pos
= it
.current
.pos
;
9204 if (PT
>= CHARPOS (scroll_margin_pos
))
9208 /* Point is in the scroll margin at the bottom of the window, or
9209 below. Compute a new window start that makes point visible. */
9211 /* Compute the distance from the scroll margin to PT.
9212 Give up if the distance is greater than scroll_max. */
9213 start_display (&it
, w
, scroll_margin_pos
);
9215 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9216 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9218 /* With a scroll_margin of 0, scroll_margin_pos is at the window
9219 end, which is one line below the window. The iterator's
9220 current_y will be same as y0 in that case, but we have to
9221 scroll a line to make PT visible. That's the reason why 1 is
9223 dy
= 1 + it
.current_y
- y0
;
9225 if (dy
> scroll_max
)
9228 /* Move the window start down. If scrolling conservatively,
9229 move it just enough down to make point visible. If
9230 scroll_step is set, move it down by scroll_step. */
9231 start_display (&it
, w
, startp
);
9233 if (scroll_conservatively
)
9235 = max (max (dy
, CANON_Y_UNIT (f
)),
9236 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9237 else if (scroll_step
|| temp_scroll_step
)
9238 amount_to_scroll
= scroll_max
;
9241 aggressive
= current_buffer
->scroll_down_aggressively
;
9242 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9243 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9244 if (NUMBERP (aggressive
))
9245 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9248 if (amount_to_scroll
<= 0)
9251 move_it_vertically (&it
, amount_to_scroll
);
9252 startp
= it
.current
.pos
;
9256 /* See if point is inside the scroll margin at the top of the
9258 scroll_margin_pos
= startp
;
9259 if (this_scroll_margin
)
9261 start_display (&it
, w
, startp
);
9262 move_it_vertically (&it
, this_scroll_margin
);
9263 scroll_margin_pos
= it
.current
.pos
;
9266 if (PT
< CHARPOS (scroll_margin_pos
))
9268 /* Point is in the scroll margin at the top of the window or
9269 above what is displayed in the window. */
9272 /* Compute the vertical distance from PT to the scroll
9273 margin position. Give up if distance is greater than
9275 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9276 start_display (&it
, w
, pos
);
9278 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9279 it
.last_visible_y
, -1,
9280 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9281 dy
= it
.current_y
- y0
;
9282 if (dy
> scroll_max
)
9285 /* Compute new window start. */
9286 start_display (&it
, w
, startp
);
9288 if (scroll_conservatively
)
9290 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9291 else if (scroll_step
|| temp_scroll_step
)
9292 amount_to_scroll
= scroll_max
;
9295 aggressive
= current_buffer
->scroll_up_aggressively
;
9296 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9297 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9298 if (NUMBERP (aggressive
))
9299 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9302 if (amount_to_scroll
<= 0)
9305 move_it_vertically (&it
, - amount_to_scroll
);
9306 startp
= it
.current
.pos
;
9310 /* Run window scroll functions. */
9311 startp
= run_window_scroll_functions (window
, startp
);
9313 /* Display the window. Give up if new fonts are loaded, or if point
9315 if (!try_window (window
, startp
))
9317 else if (w
->cursor
.vpos
< 0)
9319 clear_glyph_matrix (w
->desired_matrix
);
9324 /* Maybe forget recorded base line for line number display. */
9325 if (!just_this_one_p
9326 || current_buffer
->clip_changed
9327 || BEG_UNCHANGED
< CHARPOS (startp
))
9328 w
->base_line_number
= Qnil
;
9330 /* If cursor ends up on a partially visible line, shift display
9331 lines up or down. */
9332 make_cursor_line_fully_visible (w
);
9340 /* Compute a suitable window start for window W if display of W starts
9341 on a continuation line. Value is non-zero if a new window start
9344 The new window start will be computed, based on W's width, starting
9345 from the start of the continued line. It is the start of the
9346 screen line with the minimum distance from the old start W->start. */
9349 compute_window_start_on_continuation_line (w
)
9352 struct text_pos pos
, start_pos
;
9353 int window_start_changed_p
= 0;
9355 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9357 /* If window start is on a continuation line... Window start may be
9358 < BEGV in case there's invisible text at the start of the
9359 buffer (M-x rmail, for example). */
9360 if (CHARPOS (start_pos
) > BEGV
9361 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9364 struct glyph_row
*row
;
9366 /* Handle the case that the window start is out of range. */
9367 if (CHARPOS (start_pos
) < BEGV
)
9368 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9369 else if (CHARPOS (start_pos
) > ZV
)
9370 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9372 /* Find the start of the continued line. This should be fast
9373 because scan_buffer is fast (newline cache). */
9374 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9375 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9376 row
, DEFAULT_FACE_ID
);
9377 reseat_at_previous_visible_line_start (&it
);
9379 /* If the line start is "too far" away from the window start,
9380 say it takes too much time to compute a new window start. */
9381 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9382 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9384 int min_distance
, distance
;
9386 /* Move forward by display lines to find the new window
9387 start. If window width was enlarged, the new start can
9388 be expected to be > the old start. If window width was
9389 decreased, the new window start will be < the old start.
9390 So, we're looking for the display line start with the
9391 minimum distance from the old window start. */
9392 pos
= it
.current
.pos
;
9393 min_distance
= INFINITY
;
9394 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9395 distance
< min_distance
)
9397 min_distance
= distance
;
9398 pos
= it
.current
.pos
;
9399 move_it_by_lines (&it
, 1, 0);
9402 /* Set the window start there. */
9403 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9404 window_start_changed_p
= 1;
9408 return window_start_changed_p
;
9412 /* Try cursor movement in case text has not changes in window WINDOW,
9413 with window start STARTP. Value is
9417 0 if this method cannot be used
9419 -1 if we know we have to scroll the display. *SCROLL_STEP is
9420 set to 1, under certain circumstances, if we want to scroll as
9421 if scroll-step were set to 1. See the code. */
9424 try_cursor_movement (window
, startp
, scroll_step
)
9426 struct text_pos startp
;
9429 struct window
*w
= XWINDOW (window
);
9430 struct frame
*f
= XFRAME (w
->frame
);
9433 /* Handle case where text has not changed, only point, and it has
9434 not moved off the frame. */
9435 if (/* Point may be in this window. */
9436 PT
>= CHARPOS (startp
)
9437 /* Selective display hasn't changed. */
9438 && !current_buffer
->clip_changed
9439 /* Function force-mode-line-update is used to force a thorough
9440 redisplay. It sets either windows_or_buffers_changed or
9441 update_mode_lines. So don't take a shortcut here for these
9443 && !update_mode_lines
9444 && !windows_or_buffers_changed
9445 /* Can't use this case if highlighting a region. When a
9446 region exists, cursor movement has to do more than just
9448 && !(!NILP (Vtransient_mark_mode
)
9449 && !NILP (current_buffer
->mark_active
))
9450 && NILP (w
->region_showing
)
9451 && NILP (Vshow_trailing_whitespace
)
9452 /* Right after splitting windows, last_point may be nil. */
9453 && INTEGERP (w
->last_point
)
9454 /* This code is not used for mini-buffer for the sake of the case
9455 of redisplaying to replace an echo area message; since in
9456 that case the mini-buffer contents per se are usually
9457 unchanged. This code is of no real use in the mini-buffer
9458 since the handling of this_line_start_pos, etc., in redisplay
9459 handles the same cases. */
9460 && !EQ (window
, minibuf_window
)
9461 /* When splitting windows or for new windows, it happens that
9462 redisplay is called with a nil window_end_vpos or one being
9463 larger than the window. This should really be fixed in
9464 window.c. I don't have this on my list, now, so we do
9465 approximately the same as the old redisplay code. --gerd. */
9466 && INTEGERP (w
->window_end_vpos
)
9467 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9468 && (FRAME_WINDOW_P (f
)
9469 || !MARKERP (Voverlay_arrow_position
)
9470 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9472 int this_scroll_margin
;
9473 struct glyph_row
*row
;
9476 debug_method_add (w
, "cursor movement");
9479 /* Scroll if point within this distance from the top or bottom
9480 of the window. This is a pixel value. */
9481 this_scroll_margin
= max (0, scroll_margin
);
9482 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9483 this_scroll_margin
*= CANON_Y_UNIT (f
);
9485 /* Start with the row the cursor was displayed during the last
9486 not paused redisplay. Give up if that row is not valid. */
9487 if (w
->last_cursor
.vpos
< 0
9488 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9492 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9493 if (row
->mode_line_p
)
9495 if (!row
->enabled_p
)
9502 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9504 if (PT
> XFASTINT (w
->last_point
))
9506 /* Point has moved forward. */
9507 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9508 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9510 xassert (row
->enabled_p
);
9514 /* The end position of a row equals the start position
9515 of the next row. If PT is there, we would rather
9516 display it in the next line. */
9517 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9518 && MATRIX_ROW_END_CHARPOS (row
) == PT
9519 && !cursor_row_p (w
, row
))
9522 /* If within the scroll margin, scroll. Note that
9523 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9524 the next line would be drawn, and that
9525 this_scroll_margin can be zero. */
9526 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9527 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9528 /* Line is completely visible last line in window
9529 and PT is to be set in the next line. */
9530 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9531 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9532 && !row
->ends_at_zv_p
9533 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9536 else if (PT
< XFASTINT (w
->last_point
))
9538 /* Cursor has to be moved backward. Note that PT >=
9539 CHARPOS (startp) because of the outer
9541 while (!row
->mode_line_p
9542 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9543 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9544 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9545 && (row
->y
> this_scroll_margin
9546 || CHARPOS (startp
) == BEGV
))
9548 xassert (row
->enabled_p
);
9552 /* Consider the following case: Window starts at BEGV,
9553 there is invisible, intangible text at BEGV, so that
9554 display starts at some point START > BEGV. It can
9555 happen that we are called with PT somewhere between
9556 BEGV and START. Try to handle that case. */
9557 if (row
< w
->current_matrix
->rows
9558 || row
->mode_line_p
)
9560 row
= w
->current_matrix
->rows
;
9561 if (row
->mode_line_p
)
9565 /* Due to newlines in overlay strings, we may have to
9566 skip forward over overlay strings. */
9567 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9568 && MATRIX_ROW_END_CHARPOS (row
) == PT
9569 && !cursor_row_p (w
, row
))
9572 /* If within the scroll margin, scroll. */
9573 if (row
->y
< this_scroll_margin
9574 && CHARPOS (startp
) != BEGV
)
9578 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9579 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9581 /* if PT is not in the glyph row, give up. */
9584 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9586 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9587 && !row
->ends_at_zv_p
9588 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9590 else if (row
->height
> window_box_height (w
))
9592 /* If we end up in a partially visible line, let's
9593 make it fully visible, except when it's taller
9594 than the window, in which case we can't do much
9601 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9602 try_window (window
, startp
);
9603 make_cursor_line_fully_visible (w
);
9611 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9621 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9622 selected_window is redisplayed. */
9625 redisplay_window (window
, just_this_one_p
)
9627 int just_this_one_p
;
9629 struct window
*w
= XWINDOW (window
);
9630 struct frame
*f
= XFRAME (w
->frame
);
9631 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9632 struct buffer
*old
= current_buffer
;
9633 struct text_pos lpoint
, opoint
, startp
;
9634 int update_mode_line
;
9637 /* Record it now because it's overwritten. */
9638 int current_matrix_up_to_date_p
= 0;
9639 int temp_scroll_step
= 0;
9640 int count
= BINDING_STACK_SIZE ();
9643 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9646 /* W must be a leaf window here. */
9647 xassert (!NILP (w
->buffer
));
9649 *w
->desired_matrix
->method
= 0;
9652 specbind (Qinhibit_point_motion_hooks
, Qt
);
9654 reconsider_clip_changes (w
, buffer
);
9656 /* Has the mode line to be updated? */
9657 update_mode_line
= (!NILP (w
->update_mode_line
)
9658 || update_mode_lines
9659 || buffer
->clip_changed
);
9661 if (MINI_WINDOW_P (w
))
9663 if (w
== XWINDOW (echo_area_window
)
9664 && !NILP (echo_area_buffer
[0]))
9666 if (update_mode_line
)
9667 /* We may have to update a tty frame's menu bar or a
9668 tool-bar. Example `M-x C-h C-h C-g'. */
9669 goto finish_menu_bars
;
9671 /* We've already displayed the echo area glyphs in this window. */
9672 goto finish_scroll_bars
;
9674 else if (w
!= XWINDOW (minibuf_window
))
9676 /* W is a mini-buffer window, but it's not the currently
9677 active one, so clear it. */
9678 int yb
= window_text_bottom_y (w
);
9679 struct glyph_row
*row
;
9682 for (y
= 0, row
= w
->desired_matrix
->rows
;
9684 y
+= row
->height
, ++row
)
9685 blank_row (w
, row
, y
);
9686 goto finish_scroll_bars
;
9690 /* Otherwise set up data on this window; select its buffer and point
9692 /* Really select the buffer, for the sake of buffer-local
9694 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9695 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9697 current_matrix_up_to_date_p
9698 = (!NILP (w
->window_end_valid
)
9699 && !current_buffer
->clip_changed
9700 && XFASTINT (w
->last_modified
) >= MODIFF
9701 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9703 /* When windows_or_buffers_changed is non-zero, we can't rely on
9704 the window end being valid, so set it to nil there. */
9705 if (windows_or_buffers_changed
)
9707 /* If window starts on a continuation line, maybe adjust the
9708 window start in case the window's width changed. */
9709 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9710 compute_window_start_on_continuation_line (w
);
9712 w
->window_end_valid
= Qnil
;
9715 /* Some sanity checks. */
9716 CHECK_WINDOW_END (w
);
9717 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9719 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9722 /* If %c is in mode line, update it if needed. */
9723 if (!NILP (w
->column_number_displayed
)
9724 /* This alternative quickly identifies a common case
9725 where no change is needed. */
9726 && !(PT
== XFASTINT (w
->last_point
)
9727 && XFASTINT (w
->last_modified
) >= MODIFF
9728 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9729 && XFASTINT (w
->column_number_displayed
) != current_column ())
9730 update_mode_line
= 1;
9732 /* Count number of windows showing the selected buffer. An indirect
9733 buffer counts as its base buffer. */
9734 if (!just_this_one_p
)
9736 struct buffer
*current_base
, *window_base
;
9737 current_base
= current_buffer
;
9738 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9739 if (current_base
->base_buffer
)
9740 current_base
= current_base
->base_buffer
;
9741 if (window_base
->base_buffer
)
9742 window_base
= window_base
->base_buffer
;
9743 if (current_base
== window_base
)
9747 /* Point refers normally to the selected window. For any other
9748 window, set up appropriate value. */
9749 if (!EQ (window
, selected_window
))
9751 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9752 int new_pt_byte
= marker_byte_position (w
->pointm
);
9756 new_pt_byte
= BEGV_BYTE
;
9757 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9759 else if (new_pt
> (ZV
- 1))
9762 new_pt_byte
= ZV_BYTE
;
9763 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9766 /* We don't use SET_PT so that the point-motion hooks don't run. */
9767 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9770 /* If any of the character widths specified in the display table
9771 have changed, invalidate the width run cache. It's true that
9772 this may be a bit late to catch such changes, but the rest of
9773 redisplay goes (non-fatally) haywire when the display table is
9774 changed, so why should we worry about doing any better? */
9775 if (current_buffer
->width_run_cache
)
9777 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9779 if (! disptab_matches_widthtab (disptab
,
9780 XVECTOR (current_buffer
->width_table
)))
9782 invalidate_region_cache (current_buffer
,
9783 current_buffer
->width_run_cache
,
9785 recompute_width_table (current_buffer
, disptab
);
9789 /* If window-start is screwed up, choose a new one. */
9790 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9793 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9795 /* If someone specified a new starting point but did not insist,
9796 check whether it can be used. */
9797 if (!NILP (w
->optional_new_start
)
9798 && CHARPOS (startp
) >= BEGV
9799 && CHARPOS (startp
) <= ZV
)
9801 w
->optional_new_start
= Qnil
;
9802 start_display (&it
, w
, startp
);
9803 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9804 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9805 if (IT_CHARPOS (it
) == PT
)
9806 w
->force_start
= Qt
;
9809 /* Handle case where place to start displaying has been specified,
9810 unless the specified location is outside the accessible range. */
9811 if (!NILP (w
->force_start
)
9812 || w
->frozen_window_start_p
)
9814 w
->force_start
= Qnil
;
9816 w
->window_end_valid
= Qnil
;
9818 /* Forget any recorded base line for line number display. */
9819 if (!current_matrix_up_to_date_p
9820 || current_buffer
->clip_changed
)
9821 w
->base_line_number
= Qnil
;
9823 /* Redisplay the mode line. Select the buffer properly for that.
9824 Also, run the hook window-scroll-functions
9825 because we have scrolled. */
9826 /* Note, we do this after clearing force_start because
9827 if there's an error, it is better to forget about force_start
9828 than to get into an infinite loop calling the hook functions
9829 and having them get more errors. */
9830 if (!update_mode_line
9831 || ! NILP (Vwindow_scroll_functions
))
9833 update_mode_line
= 1;
9834 w
->update_mode_line
= Qt
;
9835 startp
= run_window_scroll_functions (window
, startp
);
9838 XSETFASTINT (w
->last_modified
, 0);
9839 XSETFASTINT (w
->last_overlay_modified
, 0);
9840 if (CHARPOS (startp
) < BEGV
)
9841 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9842 else if (CHARPOS (startp
) > ZV
)
9843 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9845 /* Redisplay, then check if cursor has been set during the
9846 redisplay. Give up if new fonts were loaded. */
9847 if (!try_window (window
, startp
))
9849 w
->force_start
= Qt
;
9850 clear_glyph_matrix (w
->desired_matrix
);
9851 goto finish_scroll_bars
;
9854 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9856 /* If point does not appear, try to move point so it does
9857 appear. The desired matrix has been built above, so we
9860 struct glyph_row
*row
;
9862 window_height
= window_box_height (w
) / 2;
9863 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9864 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9867 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9868 MATRIX_ROW_START_BYTEPOS (row
));
9870 if (w
!= XWINDOW (selected_window
))
9871 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9872 else if (current_buffer
== old
)
9873 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9875 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9877 /* If we are highlighting the region, then we just changed
9878 the region, so redisplay to show it. */
9879 if (!NILP (Vtransient_mark_mode
)
9880 && !NILP (current_buffer
->mark_active
))
9882 clear_glyph_matrix (w
->desired_matrix
);
9883 if (!try_window (window
, startp
))
9884 goto finish_scroll_bars
;
9888 make_cursor_line_fully_visible (w
);
9890 debug_method_add (w
, "forced window start");
9895 /* Handle case where text has not changed, only point, and it has
9896 not moved off the frame. */
9897 if (current_matrix_up_to_date_p
9898 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9906 /* If current starting point was originally the beginning of a line
9907 but no longer is, find a new starting point. */
9908 else if (!NILP (w
->start_at_line_beg
)
9909 && !(CHARPOS (startp
) <= BEGV
9910 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9913 debug_method_add (w
, "recenter 1");
9918 /* Try scrolling with try_window_id. */
9919 else if (/* Windows and buffers haven't changed. */
9920 !windows_or_buffers_changed
9921 /* Window must be either use window-based redisplay or
9923 && (FRAME_WINDOW_P (f
)
9924 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9925 && !MINI_WINDOW_P (w
)
9926 /* Point is not known NOT to appear in window. */
9927 && PT
>= CHARPOS (startp
)
9928 && XFASTINT (w
->last_modified
)
9929 /* Window is not hscrolled. */
9930 && XFASTINT (w
->hscroll
) == 0
9931 /* Selective display has not changed. */
9932 && !current_buffer
->clip_changed
9933 /* Current matrix is up to date. */
9934 && !NILP (w
->window_end_valid
)
9935 /* Can't use this case if highlighting a region because
9936 a cursor movement will do more than just set the cursor. */
9937 && !(!NILP (Vtransient_mark_mode
)
9938 && !NILP (current_buffer
->mark_active
))
9939 && NILP (w
->region_showing
)
9940 && NILP (Vshow_trailing_whitespace
)
9941 /* Overlay arrow position and string not changed. */
9942 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9943 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9944 /* Value is > 0 if update has been done, it is -1 if we
9945 know that the same window start will not work. It is 0
9946 if unsuccessful for some other reason. */
9947 && (tem
= try_window_id (w
)) != 0)
9950 debug_method_add (w
, "try_window_id %d", tem
);
9953 if (fonts_changed_p
)
9954 goto finish_scroll_bars
;
9958 /* Otherwise try_window_id has returned -1 which means that we
9959 don't want the alternative below this comment to execute. */
9961 else if (CHARPOS (startp
) >= BEGV
9962 && CHARPOS (startp
) <= ZV
9963 && PT
>= CHARPOS (startp
)
9964 && (CHARPOS (startp
) < ZV
9965 /* Avoid starting at end of buffer. */
9966 || CHARPOS (startp
) == BEGV
9967 || (XFASTINT (w
->last_modified
) >= MODIFF
9968 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9971 debug_method_add (w
, "same window start");
9974 /* Try to redisplay starting at same place as before.
9975 If point has not moved off frame, accept the results. */
9976 if (!current_matrix_up_to_date_p
9977 /* Don't use try_window_reusing_current_matrix in this case
9978 because a window scroll function can have changed the
9980 || !NILP (Vwindow_scroll_functions
)
9981 || MINI_WINDOW_P (w
)
9982 || !try_window_reusing_current_matrix (w
))
9984 IF_DEBUG (debug_method_add (w
, "1"));
9985 try_window (window
, startp
);
9988 if (fonts_changed_p
)
9989 goto finish_scroll_bars
;
9991 if (w
->cursor
.vpos
>= 0)
9993 if (!just_this_one_p
9994 || current_buffer
->clip_changed
9995 || BEG_UNCHANGED
< CHARPOS (startp
))
9996 /* Forget any recorded base line for line number display. */
9997 w
->base_line_number
= Qnil
;
9999 make_cursor_line_fully_visible (w
);
10003 clear_glyph_matrix (w
->desired_matrix
);
10008 XSETFASTINT (w
->last_modified
, 0);
10009 XSETFASTINT (w
->last_overlay_modified
, 0);
10011 /* Redisplay the mode line. Select the buffer properly for that. */
10012 if (!update_mode_line
)
10014 update_mode_line
= 1;
10015 w
->update_mode_line
= Qt
;
10018 /* Try to scroll by specified few lines. */
10019 if ((scroll_conservatively
10021 || temp_scroll_step
10022 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10023 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10024 && !current_buffer
->clip_changed
10025 && CHARPOS (startp
) >= BEGV
10026 && CHARPOS (startp
) <= ZV
)
10028 /* The function returns -1 if new fonts were loaded, 1 if
10029 successful, 0 if not successful. */
10030 int rc
= try_scrolling (window
, just_this_one_p
,
10031 scroll_conservatively
,
10037 goto finish_scroll_bars
;
10040 /* Finally, just choose place to start which centers point */
10045 debug_method_add (w
, "recenter");
10048 /* w->vscroll = 0; */
10050 /* Forget any previously recorded base line for line number display. */
10051 if (!current_matrix_up_to_date_p
10052 || current_buffer
->clip_changed
)
10053 w
->base_line_number
= Qnil
;
10055 /* Move backward half the height of the window. */
10056 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10057 it
.current_y
= it
.last_visible_y
;
10058 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
10059 xassert (IT_CHARPOS (it
) >= BEGV
);
10061 /* The function move_it_vertically_backward may move over more
10062 than the specified y-distance. If it->w is small, e.g. a
10063 mini-buffer window, we may end up in front of the window's
10064 display area. Start displaying at the start of the line
10065 containing PT in this case. */
10066 if (it
.current_y
<= 0)
10068 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10069 move_it_vertically (&it
, 0);
10070 xassert (IT_CHARPOS (it
) <= PT
);
10074 it
.current_x
= it
.hpos
= 0;
10076 /* Set startp here explicitly in case that helps avoid an infinite loop
10077 in case the window-scroll-functions functions get errors. */
10078 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10080 /* Run scroll hooks. */
10081 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10083 /* Redisplay the window. */
10084 if (!current_matrix_up_to_date_p
10085 || windows_or_buffers_changed
10086 /* Don't use try_window_reusing_current_matrix in this case
10087 because it can have changed the buffer. */
10088 || !NILP (Vwindow_scroll_functions
)
10089 || !just_this_one_p
10090 || MINI_WINDOW_P (w
)
10091 || !try_window_reusing_current_matrix (w
))
10092 try_window (window
, startp
);
10094 /* If new fonts have been loaded (due to fontsets), give up. We
10095 have to start a new redisplay since we need to re-adjust glyph
10097 if (fonts_changed_p
)
10098 goto finish_scroll_bars
;
10100 /* If cursor did not appear assume that the middle of the window is
10101 in the first line of the window. Do it again with the next line.
10102 (Imagine a window of height 100, displaying two lines of height
10103 60. Moving back 50 from it->last_visible_y will end in the first
10105 if (w
->cursor
.vpos
< 0)
10107 if (!NILP (w
->window_end_valid
)
10108 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10110 clear_glyph_matrix (w
->desired_matrix
);
10111 move_it_by_lines (&it
, 1, 0);
10112 try_window (window
, it
.current
.pos
);
10114 else if (PT
< IT_CHARPOS (it
))
10116 clear_glyph_matrix (w
->desired_matrix
);
10117 move_it_by_lines (&it
, -1, 0);
10118 try_window (window
, it
.current
.pos
);
10122 /* Not much we can do about it. */
10126 /* Consider the following case: Window starts at BEGV, there is
10127 invisible, intangible text at BEGV, so that display starts at
10128 some point START > BEGV. It can happen that we are called with
10129 PT somewhere between BEGV and START. Try to handle that case. */
10130 if (w
->cursor
.vpos
< 0)
10132 struct glyph_row
*row
= w
->current_matrix
->rows
;
10133 if (row
->mode_line_p
)
10135 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10138 make_cursor_line_fully_visible (w
);
10142 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10143 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10144 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10147 /* Display the mode line, if we must. */
10148 if ((update_mode_line
10149 /* If window not full width, must redo its mode line
10150 if (a) the window to its side is being redone and
10151 (b) we do a frame-based redisplay. This is a consequence
10152 of how inverted lines are drawn in frame-based redisplay. */
10153 || (!just_this_one_p
10154 && !FRAME_WINDOW_P (f
)
10155 && !WINDOW_FULL_WIDTH_P (w
))
10156 /* Line number to display. */
10157 || INTEGERP (w
->base_line_pos
)
10158 /* Column number is displayed and different from the one displayed. */
10159 || (!NILP (w
->column_number_displayed
)
10160 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10161 /* This means that the window has a mode line. */
10162 && (WINDOW_WANTS_MODELINE_P (w
)
10163 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10165 Lisp_Object old_selected_frame
;
10167 old_selected_frame
= selected_frame
;
10169 XSETFRAME (selected_frame
, f
);
10170 display_mode_lines (w
);
10171 selected_frame
= old_selected_frame
;
10173 /* If mode line height has changed, arrange for a thorough
10174 immediate redisplay using the correct mode line height. */
10175 if (WINDOW_WANTS_MODELINE_P (w
)
10176 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10178 fonts_changed_p
= 1;
10179 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10180 = DESIRED_MODE_LINE_HEIGHT (w
);
10183 /* If top line height has changed, arrange for a thorough
10184 immediate redisplay using the correct mode line height. */
10185 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10186 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10188 fonts_changed_p
= 1;
10189 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10190 = DESIRED_HEADER_LINE_HEIGHT (w
);
10193 if (fonts_changed_p
)
10194 goto finish_scroll_bars
;
10197 if (!line_number_displayed
10198 && !BUFFERP (w
->base_line_pos
))
10200 w
->base_line_pos
= Qnil
;
10201 w
->base_line_number
= Qnil
;
10206 /* When we reach a frame's selected window, redo the frame's menu bar. */
10207 if (update_mode_line
10208 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10210 int redisplay_menu_p
= 0;
10212 if (FRAME_WINDOW_P (f
))
10214 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10215 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10217 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10221 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10223 if (redisplay_menu_p
)
10224 display_menu_bar (w
);
10226 #ifdef HAVE_WINDOW_SYSTEM
10227 if (WINDOWP (f
->tool_bar_window
)
10228 && (FRAME_TOOL_BAR_LINES (f
) > 0
10229 || auto_resize_tool_bars_p
))
10230 redisplay_tool_bar (f
);
10234 finish_scroll_bars
:
10236 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10238 int start
, end
, whole
;
10240 /* Calculate the start and end positions for the current window.
10241 At some point, it would be nice to choose between scrollbars
10242 which reflect the whole buffer size, with special markers
10243 indicating narrowing, and scrollbars which reflect only the
10246 Note that mini-buffers sometimes aren't displaying any text. */
10247 if (!MINI_WINDOW_P (w
)
10248 || (w
== XWINDOW (minibuf_window
)
10249 && NILP (echo_area_buffer
[0])))
10252 start
= marker_position (w
->start
) - BEGV
;
10253 /* I don't think this is guaranteed to be right. For the
10254 moment, we'll pretend it is. */
10255 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10259 if (whole
< (end
- start
))
10260 whole
= end
- start
;
10263 start
= end
= whole
= 0;
10265 /* Indicate what this scroll bar ought to be displaying now. */
10266 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10268 /* Note that we actually used the scroll bar attached to this
10269 window, so it shouldn't be deleted at the end of redisplay. */
10270 redeem_scroll_bar_hook (w
);
10273 /* Restore current_buffer and value of point in it. */
10274 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10275 set_buffer_internal_1 (old
);
10276 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10278 unbind_to (count
, Qnil
);
10282 /* Build the complete desired matrix of WINDOW with a window start
10283 buffer position POS. Value is non-zero if successful. It is zero
10284 if fonts were loaded during redisplay which makes re-adjusting
10285 glyph matrices necessary. */
10288 try_window (window
, pos
)
10289 Lisp_Object window
;
10290 struct text_pos pos
;
10292 struct window
*w
= XWINDOW (window
);
10294 struct glyph_row
*last_text_row
= NULL
;
10296 /* Make POS the new window start. */
10297 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10299 /* Mark cursor position as unknown. No overlay arrow seen. */
10300 w
->cursor
.vpos
= -1;
10301 overlay_arrow_seen
= 0;
10303 /* Initialize iterator and info to start at POS. */
10304 start_display (&it
, w
, pos
);
10306 /* Display all lines of W. */
10307 while (it
.current_y
< it
.last_visible_y
)
10309 if (display_line (&it
))
10310 last_text_row
= it
.glyph_row
- 1;
10311 if (fonts_changed_p
)
10315 /* If bottom moved off end of frame, change mode line percentage. */
10316 if (XFASTINT (w
->window_end_pos
) <= 0
10317 && Z
!= IT_CHARPOS (it
))
10318 w
->update_mode_line
= Qt
;
10320 /* Set window_end_pos to the offset of the last character displayed
10321 on the window from the end of current_buffer. Set
10322 window_end_vpos to its row number. */
10325 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10326 w
->window_end_bytepos
10327 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10328 XSETFASTINT (w
->window_end_pos
,
10329 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10330 XSETFASTINT (w
->window_end_vpos
,
10331 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10332 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10333 ->displays_text_p
);
10337 w
->window_end_bytepos
= 0;
10338 XSETFASTINT (w
->window_end_pos
, 0);
10339 XSETFASTINT (w
->window_end_vpos
, 0);
10342 /* But that is not valid info until redisplay finishes. */
10343 w
->window_end_valid
= Qnil
;
10349 /************************************************************************
10350 Window redisplay reusing current matrix when buffer has not changed
10351 ************************************************************************/
10353 /* Try redisplay of window W showing an unchanged buffer with a
10354 different window start than the last time it was displayed by
10355 reusing its current matrix. Value is non-zero if successful.
10356 W->start is the new window start. */
10359 try_window_reusing_current_matrix (w
)
10362 struct frame
*f
= XFRAME (w
->frame
);
10363 struct glyph_row
*row
, *bottom_row
;
10366 struct text_pos start
, new_start
;
10367 int nrows_scrolled
, i
;
10368 struct glyph_row
*last_text_row
;
10369 struct glyph_row
*last_reused_text_row
;
10370 struct glyph_row
*start_row
;
10371 int start_vpos
, min_y
, max_y
;
10373 if (/* This function doesn't handle terminal frames. */
10374 !FRAME_WINDOW_P (f
)
10375 /* Don't try to reuse the display if windows have been split
10377 || windows_or_buffers_changed
)
10380 /* Can't do this if region may have changed. */
10381 if ((!NILP (Vtransient_mark_mode
)
10382 && !NILP (current_buffer
->mark_active
))
10383 || !NILP (w
->region_showing
)
10384 || !NILP (Vshow_trailing_whitespace
))
10387 /* If top-line visibility has changed, give up. */
10388 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10389 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10392 /* Give up if old or new display is scrolled vertically. We could
10393 make this function handle this, but right now it doesn't. */
10394 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10395 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10398 /* The variable new_start now holds the new window start. The old
10399 start `start' can be determined from the current matrix. */
10400 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10401 start
= start_row
->start
.pos
;
10402 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10404 /* Clear the desired matrix for the display below. */
10405 clear_glyph_matrix (w
->desired_matrix
);
10407 if (CHARPOS (new_start
) <= CHARPOS (start
))
10411 IF_DEBUG (debug_method_add (w
, "twu1"));
10413 /* Display up to a row that can be reused. The variable
10414 last_text_row is set to the last row displayed that displays
10415 text. Note that it.vpos == 0 if or if not there is a
10416 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10417 start_display (&it
, w
, new_start
);
10418 first_row_y
= it
.current_y
;
10419 w
->cursor
.vpos
= -1;
10420 last_text_row
= last_reused_text_row
= NULL
;
10422 while (it
.current_y
< it
.last_visible_y
10423 && IT_CHARPOS (it
) < CHARPOS (start
)
10424 && !fonts_changed_p
)
10425 if (display_line (&it
))
10426 last_text_row
= it
.glyph_row
- 1;
10428 /* A value of current_y < last_visible_y means that we stopped
10429 at the previous window start, which in turn means that we
10430 have at least one reusable row. */
10431 if (it
.current_y
< it
.last_visible_y
)
10433 /* IT.vpos always starts from 0; it counts text lines. */
10434 nrows_scrolled
= it
.vpos
;
10436 /* Find PT if not already found in the lines displayed. */
10437 if (w
->cursor
.vpos
< 0)
10439 int dy
= it
.current_y
- first_row_y
;
10441 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10442 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10444 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10445 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10447 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10448 dy
, nrows_scrolled
);
10452 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10458 /* Give up if point was not found. This shouldn't
10459 happen often; not more often than with try_window
10461 if (w
->cursor
.vpos
< 0)
10463 clear_glyph_matrix (w
->desired_matrix
);
10468 /* Scroll the display. Do it before the current matrix is
10469 changed. The problem here is that update has not yet
10470 run, i.e. part of the current matrix is not up to date.
10471 scroll_run_hook will clear the cursor, and use the
10472 current matrix to get the height of the row the cursor is
10474 run
.current_y
= first_row_y
;
10475 run
.desired_y
= it
.current_y
;
10476 run
.height
= it
.last_visible_y
- it
.current_y
;
10478 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10481 rif
->update_window_begin_hook (w
);
10482 rif
->clear_mouse_face (w
);
10483 rif
->scroll_run_hook (w
, &run
);
10484 rif
->update_window_end_hook (w
, 0, 0);
10488 /* Shift current matrix down by nrows_scrolled lines. */
10489 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10490 rotate_matrix (w
->current_matrix
,
10492 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10495 /* Disable lines that must be updated. */
10496 for (i
= 0; i
< it
.vpos
; ++i
)
10497 (start_row
+ i
)->enabled_p
= 0;
10499 /* Re-compute Y positions. */
10500 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10501 max_y
= it
.last_visible_y
;
10502 for (row
= start_row
+ nrows_scrolled
;
10506 row
->y
= it
.current_y
;
10508 if (row
->y
< min_y
)
10509 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10510 else if (row
->y
+ row
->height
> max_y
)
10511 row
->visible_height
10512 = row
->height
- (row
->y
+ row
->height
- max_y
);
10514 row
->visible_height
= row
->height
;
10516 it
.current_y
+= row
->height
;
10518 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10519 last_reused_text_row
= row
;
10520 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10524 /* Disable lines in the current matrix which are now
10525 below the window. */
10526 for (++row
; row
< bottom_row
; ++row
)
10527 row
->enabled_p
= 0;
10530 /* Update window_end_pos etc.; last_reused_text_row is the last
10531 reused row from the current matrix containing text, if any.
10532 The value of last_text_row is the last displayed line
10533 containing text. */
10534 if (last_reused_text_row
)
10536 w
->window_end_bytepos
10537 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10538 XSETFASTINT (w
->window_end_pos
,
10539 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10540 XSETFASTINT (w
->window_end_vpos
,
10541 MATRIX_ROW_VPOS (last_reused_text_row
,
10542 w
->current_matrix
));
10544 else if (last_text_row
)
10546 w
->window_end_bytepos
10547 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10548 XSETFASTINT (w
->window_end_pos
,
10549 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10550 XSETFASTINT (w
->window_end_vpos
,
10551 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10555 /* This window must be completely empty. */
10556 w
->window_end_bytepos
= 0;
10557 XSETFASTINT (w
->window_end_pos
, 0);
10558 XSETFASTINT (w
->window_end_vpos
, 0);
10560 w
->window_end_valid
= Qnil
;
10562 /* Update hint: don't try scrolling again in update_window. */
10563 w
->desired_matrix
->no_scrolling_p
= 1;
10566 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10570 else if (CHARPOS (new_start
) > CHARPOS (start
))
10572 struct glyph_row
*pt_row
, *row
;
10573 struct glyph_row
*first_reusable_row
;
10574 struct glyph_row
*first_row_to_display
;
10576 int yb
= window_text_bottom_y (w
);
10578 IF_DEBUG (debug_method_add (w
, "twu2"));
10580 /* Find the row starting at new_start, if there is one. Don't
10581 reuse a partially visible line at the end. */
10582 first_reusable_row
= start_row
;
10583 while (first_reusable_row
->enabled_p
10584 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10585 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10586 < CHARPOS (new_start
)))
10587 ++first_reusable_row
;
10589 /* Give up if there is no row to reuse. */
10590 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10591 || !first_reusable_row
->enabled_p
10592 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10593 != CHARPOS (new_start
)))
10596 /* We can reuse fully visible rows beginning with
10597 first_reusable_row to the end of the window. Set
10598 first_row_to_display to the first row that cannot be reused.
10599 Set pt_row to the row containing point, if there is any. */
10600 first_row_to_display
= first_reusable_row
;
10602 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
10604 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10605 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10606 pt_row
= first_row_to_display
;
10608 ++first_row_to_display
;
10611 /* Start displaying at the start of first_row_to_display. */
10612 xassert (first_row_to_display
->y
< yb
);
10613 init_to_row_start (&it
, w
, first_row_to_display
);
10614 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10616 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10618 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10619 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10621 /* Display lines beginning with first_row_to_display in the
10622 desired matrix. Set last_text_row to the last row displayed
10623 that displays text. */
10624 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10625 if (pt_row
== NULL
)
10626 w
->cursor
.vpos
= -1;
10627 last_text_row
= NULL
;
10628 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10629 if (display_line (&it
))
10630 last_text_row
= it
.glyph_row
- 1;
10632 /* Give up If point isn't in a row displayed or reused. */
10633 if (w
->cursor
.vpos
< 0)
10635 clear_glyph_matrix (w
->desired_matrix
);
10639 /* If point is in a reused row, adjust y and vpos of the cursor
10643 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10644 w
->current_matrix
);
10645 w
->cursor
.y
-= first_reusable_row
->y
;
10648 /* Scroll the display. */
10649 run
.current_y
= first_reusable_row
->y
;
10650 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10651 run
.height
= it
.last_visible_y
- run
.current_y
;
10652 dy
= run
.current_y
- run
.desired_y
;
10656 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10658 rif
->update_window_begin_hook (w
);
10659 rif
->clear_mouse_face (w
);
10660 rif
->scroll_run_hook (w
, &run
);
10661 rif
->update_window_end_hook (w
, 0, 0);
10665 /* Adjust Y positions of reused rows. */
10666 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10667 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10668 max_y
= it
.last_visible_y
;
10669 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10672 if (row
->y
< min_y
)
10673 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10674 else if (row
->y
+ row
->height
> max_y
)
10675 row
->visible_height
10676 = row
->height
- (row
->y
+ row
->height
- max_y
);
10678 row
->visible_height
= row
->height
;
10681 /* Disable rows not reused. */
10682 while (row
< bottom_row
)
10684 row
->enabled_p
= 0;
10688 /* Scroll the current matrix. */
10689 xassert (nrows_scrolled
> 0);
10690 rotate_matrix (w
->current_matrix
,
10692 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10695 /* Adjust window end. A null value of last_text_row means that
10696 the window end is in reused rows which in turn means that
10697 only its vpos can have changed. */
10700 w
->window_end_bytepos
10701 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10702 XSETFASTINT (w
->window_end_pos
,
10703 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10704 XSETFASTINT (w
->window_end_vpos
,
10705 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10709 XSETFASTINT (w
->window_end_vpos
,
10710 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10713 w
->window_end_valid
= Qnil
;
10714 w
->desired_matrix
->no_scrolling_p
= 1;
10717 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10727 /************************************************************************
10728 Window redisplay reusing current matrix when buffer has changed
10729 ************************************************************************/
10731 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10732 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10734 static struct glyph_row
*
10735 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10736 struct glyph_row
*));
10739 /* Return the last row in MATRIX displaying text. If row START is
10740 non-null, start searching with that row. IT gives the dimensions
10741 of the display. Value is null if matrix is empty; otherwise it is
10742 a pointer to the row found. */
10744 static struct glyph_row
*
10745 find_last_row_displaying_text (matrix
, it
, start
)
10746 struct glyph_matrix
*matrix
;
10748 struct glyph_row
*start
;
10750 struct glyph_row
*row
, *row_found
;
10752 /* Set row_found to the last row in IT->w's current matrix
10753 displaying text. The loop looks funny but think of partially
10756 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10757 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10759 xassert (row
->enabled_p
);
10761 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10770 /* Return the last row in the current matrix of W that is not affected
10771 by changes at the start of current_buffer that occurred since the
10772 last time W was redisplayed. Value is null if no such row exists.
10774 The global variable beg_unchanged has to contain the number of
10775 bytes unchanged at the start of current_buffer. BEG +
10776 beg_unchanged is the buffer position of the first changed byte in
10777 current_buffer. Characters at positions < BEG + beg_unchanged are
10778 at the same buffer positions as they were when the current matrix
10781 static struct glyph_row
*
10782 find_last_unchanged_at_beg_row (w
)
10785 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10786 struct glyph_row
*row
;
10787 struct glyph_row
*row_found
= NULL
;
10788 int yb
= window_text_bottom_y (w
);
10790 /* Find the last row displaying unchanged text. */
10791 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10792 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10793 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10795 if (/* If row ends before first_changed_pos, it is unchanged,
10796 except in some case. */
10797 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10798 /* When row ends in ZV and we write at ZV it is not
10800 && !row
->ends_at_zv_p
10801 /* When first_changed_pos is the end of a continued line,
10802 row is not unchanged because it may be no longer
10804 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10805 && row
->continued_p
))
10808 /* Stop if last visible row. */
10809 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10819 /* Find the first glyph row in the current matrix of W that is not
10820 affected by changes at the end of current_buffer since the last
10821 time the window was redisplayed. Return in *DELTA the number of
10822 chars by which buffer positions in unchanged text at the end of
10823 current_buffer must be adjusted. Return in *DELTA_BYTES the
10824 corresponding number of bytes. Value is null if no such row
10825 exists, i.e. all rows are affected by changes. */
10827 static struct glyph_row
*
10828 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10830 int *delta
, *delta_bytes
;
10832 struct glyph_row
*row
;
10833 struct glyph_row
*row_found
= NULL
;
10835 *delta
= *delta_bytes
= 0;
10837 /* Display must not have been paused, otherwise the current matrix
10838 is not up to date. */
10839 if (NILP (w
->window_end_valid
))
10842 /* A value of window_end_pos >= END_UNCHANGED means that the window
10843 end is in the range of changed text. If so, there is no
10844 unchanged row at the end of W's current matrix. */
10845 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10848 /* Set row to the last row in W's current matrix displaying text. */
10849 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10851 /* If matrix is entirely empty, no unchanged row exists. */
10852 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10854 /* The value of row is the last glyph row in the matrix having a
10855 meaningful buffer position in it. The end position of row
10856 corresponds to window_end_pos. This allows us to translate
10857 buffer positions in the current matrix to current buffer
10858 positions for characters not in changed text. */
10859 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10860 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10861 int last_unchanged_pos
, last_unchanged_pos_old
;
10862 struct glyph_row
*first_text_row
10863 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10865 *delta
= Z
- Z_old
;
10866 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10868 /* Set last_unchanged_pos to the buffer position of the last
10869 character in the buffer that has not been changed. Z is the
10870 index + 1 of the last byte in current_buffer, i.e. by
10871 subtracting end_unchanged we get the index of the last
10872 unchanged character, and we have to add BEG to get its buffer
10874 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10875 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10877 /* Search backward from ROW for a row displaying a line that
10878 starts at a minimum position >= last_unchanged_pos_old. */
10879 for (; row
> first_text_row
; --row
)
10881 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10884 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10889 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10896 /* Make sure that glyph rows in the current matrix of window W
10897 reference the same glyph memory as corresponding rows in the
10898 frame's frame matrix. This function is called after scrolling W's
10899 current matrix on a terminal frame in try_window_id and
10900 try_window_reusing_current_matrix. */
10903 sync_frame_with_window_matrix_rows (w
)
10906 struct frame
*f
= XFRAME (w
->frame
);
10907 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10909 /* Preconditions: W must be a leaf window and full-width. Its frame
10910 must have a frame matrix. */
10911 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10912 xassert (WINDOW_FULL_WIDTH_P (w
));
10913 xassert (!FRAME_WINDOW_P (f
));
10915 /* If W is a full-width window, glyph pointers in W's current matrix
10916 have, by definition, to be the same as glyph pointers in the
10917 corresponding frame matrix. */
10918 window_row
= w
->current_matrix
->rows
;
10919 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10920 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10921 while (window_row
< window_row_end
)
10925 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10926 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10928 /* Disable frame rows whose corresponding window rows have
10929 been disabled in try_window_id. */
10930 if (!window_row
->enabled_p
)
10931 frame_row
->enabled_p
= 0;
10933 ++window_row
, ++frame_row
;
10938 /* Find the glyph row in window W containing CHARPOS. Consider all
10939 rows between START and END (not inclusive). END null means search
10940 all rows to the end of the display area of W. Value is the row
10941 containing CHARPOS or null. */
10943 static struct glyph_row
*
10944 row_containing_pos (w
, charpos
, start
, end
)
10947 struct glyph_row
*start
, *end
;
10949 struct glyph_row
*row
= start
;
10952 /* If we happen to start on a header-line, skip that. */
10953 if (row
->mode_line_p
)
10956 if ((end
&& row
>= end
) || !row
->enabled_p
)
10959 last_y
= window_text_bottom_y (w
);
10961 while ((end
== NULL
|| row
< end
)
10962 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
10963 /* The end position of a row equals the start
10964 position of the next row. If CHARPOS is there, we
10965 would rather display it in the next line, except
10966 when this line ends in ZV. */
10967 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10968 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10969 || !row
->ends_at_zv_p
)))
10970 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10973 /* Give up if CHARPOS not found. */
10974 if ((end
&& row
>= end
)
10975 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10976 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10983 /* Try to redisplay window W by reusing its existing display. W's
10984 current matrix must be up to date when this function is called,
10985 i.e. window_end_valid must not be nil.
10989 1 if display has been updated
10990 0 if otherwise unsuccessful
10991 -1 if redisplay with same window start is known not to succeed
10993 The following steps are performed:
10995 1. Find the last row in the current matrix of W that is not
10996 affected by changes at the start of current_buffer. If no such row
10999 2. Find the first row in W's current matrix that is not affected by
11000 changes at the end of current_buffer. Maybe there is no such row.
11002 3. Display lines beginning with the row + 1 found in step 1 to the
11003 row found in step 2 or, if step 2 didn't find a row, to the end of
11006 4. If cursor is not known to appear on the window, give up.
11008 5. If display stopped at the row found in step 2, scroll the
11009 display and current matrix as needed.
11011 6. Maybe display some lines at the end of W, if we must. This can
11012 happen under various circumstances, like a partially visible line
11013 becoming fully visible, or because newly displayed lines are displayed
11014 in smaller font sizes.
11016 7. Update W's window end information. */
11018 /* Check that window end is what we expect it to be. */
11024 struct frame
*f
= XFRAME (w
->frame
);
11025 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11026 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11027 struct glyph_row
*last_unchanged_at_beg_row
;
11028 struct glyph_row
*first_unchanged_at_end_row
;
11029 struct glyph_row
*row
;
11030 struct glyph_row
*bottom_row
;
11033 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11034 struct text_pos start_pos
;
11036 int first_unchanged_at_end_vpos
= 0;
11037 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11038 struct text_pos start
;
11040 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11042 /* Check pre-conditions. Window end must be valid, otherwise
11043 the current matrix would not be up to date. */
11044 xassert (!NILP (w
->window_end_valid
));
11045 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
11046 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
11048 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11049 only if buffer has really changed. The reason is that the gap is
11050 initially at Z for freshly visited files. The code below would
11051 set end_unchanged to 0 in that case. */
11052 if (MODIFF
> SAVE_MODIFF
11053 /* This seems to happen sometimes after saving a buffer. */
11054 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11056 if (GPT
- BEG
< BEG_UNCHANGED
)
11057 BEG_UNCHANGED
= GPT
- BEG
;
11058 if (Z
- GPT
< END_UNCHANGED
)
11059 END_UNCHANGED
= Z
- GPT
;
11062 /* If window starts after a line end, and the last change is in
11063 front of that newline, then changes don't affect the display.
11064 This case happens with stealth-fontification. Note that although
11065 the display is unchanged, glyph positions in the matrix have to
11066 be adjusted, of course. */
11067 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11068 if (CHARPOS (start
) > BEGV
11069 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
11070 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
11071 && PT
< MATRIX_ROW_END_CHARPOS (row
))
11073 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11074 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
11078 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11079 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
11081 increment_matrix_positions (w
->current_matrix
,
11082 MATRIX_ROW_VPOS (r0
, current_matrix
),
11083 MATRIX_ROW_VPOS (r1
, current_matrix
),
11084 delta
, delta_bytes
);
11087 #if 0 /* If changes are all in front of the window start, the
11088 distance of the last displayed glyph from Z hasn't
11091 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11092 w
->window_end_bytepos
11093 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11096 row
= row_containing_pos (w
, PT
, r0
, NULL
);
11100 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11104 /* Return quickly if changes are all below what is displayed in the
11105 window, and if PT is in the window. */
11106 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
11107 && PT
< MATRIX_ROW_END_CHARPOS (row
))
11109 /* We have to update window end positions because the buffer's
11110 size has changed. */
11112 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11113 w
->window_end_bytepos
11114 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11116 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11117 row
= row_containing_pos (w
, PT
, row
, NULL
);
11118 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11122 /* Check that window start agrees with the start of the first glyph
11123 row in its current matrix. Check this after we know the window
11124 start is not in changed text, otherwise positions would not be
11126 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11127 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11130 /* Compute the position at which we have to start displaying new
11131 lines. Some of the lines at the top of the window might be
11132 reusable because they are not displaying changed text. Find the
11133 last row in W's current matrix not affected by changes at the
11134 start of current_buffer. Value is null if changes start in the
11135 first line of window. */
11136 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11137 if (last_unchanged_at_beg_row
)
11139 /* Avoid starting to display in the moddle of a character, a TAB
11140 for instance. This is easier than to set up the iterator
11141 exactly, and it's not a frequent case, so the additional
11142 effort wouldn't really pay off. */
11143 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11144 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11145 --last_unchanged_at_beg_row
;
11147 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11150 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
11151 start_pos
= it
.current
.pos
;
11153 /* Start displaying new lines in the desired matrix at the same
11154 vpos we would use in the current matrix, i.e. below
11155 last_unchanged_at_beg_row. */
11156 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11158 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11159 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11161 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11165 /* There are no reusable lines at the start of the window.
11166 Start displaying in the first line. */
11167 start_display (&it
, w
, start
);
11168 start_pos
= it
.current
.pos
;
11171 /* Find the first row that is not affected by changes at the end of
11172 the buffer. Value will be null if there is no unchanged row, in
11173 which case we must redisplay to the end of the window. delta
11174 will be set to the value by which buffer positions beginning with
11175 first_unchanged_at_end_row have to be adjusted due to text
11177 first_unchanged_at_end_row
11178 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11179 IF_DEBUG (debug_delta
= delta
);
11180 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11182 /* Set stop_pos to the buffer position up to which we will have to
11183 display new lines. If first_unchanged_at_end_row != NULL, this
11184 is the buffer position of the start of the line displayed in that
11185 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11186 that we don't stop at a buffer position. */
11188 if (first_unchanged_at_end_row
)
11190 xassert (last_unchanged_at_beg_row
== NULL
11191 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11193 /* If this is a continuation line, move forward to the next one
11194 that isn't. Changes in lines above affect this line.
11195 Caution: this may move first_unchanged_at_end_row to a row
11196 not displaying text. */
11197 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11198 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11199 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11200 < it
.last_visible_y
))
11201 ++first_unchanged_at_end_row
;
11203 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11204 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11205 >= it
.last_visible_y
))
11206 first_unchanged_at_end_row
= NULL
;
11209 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11211 first_unchanged_at_end_vpos
11212 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11213 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11216 else if (last_unchanged_at_beg_row
== NULL
)
11222 /* Either there is no unchanged row at the end, or the one we have
11223 now displays text. This is a necessary condition for the window
11224 end pos calculation at the end of this function. */
11225 xassert (first_unchanged_at_end_row
== NULL
11226 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11228 debug_last_unchanged_at_beg_vpos
11229 = (last_unchanged_at_beg_row
11230 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11232 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11234 #endif /* GLYPH_DEBUG != 0 */
11237 /* Display new lines. Set last_text_row to the last new line
11238 displayed which has text on it, i.e. might end up as being the
11239 line where the window_end_vpos is. */
11240 w
->cursor
.vpos
= -1;
11241 last_text_row
= NULL
;
11242 overlay_arrow_seen
= 0;
11243 while (it
.current_y
< it
.last_visible_y
11244 && !fonts_changed_p
11245 && (first_unchanged_at_end_row
== NULL
11246 || IT_CHARPOS (it
) < stop_pos
))
11248 if (display_line (&it
))
11249 last_text_row
= it
.glyph_row
- 1;
11252 if (fonts_changed_p
)
11256 /* Compute differences in buffer positions, y-positions etc. for
11257 lines reused at the bottom of the window. Compute what we can
11259 if (first_unchanged_at_end_row
11260 /* No lines reused because we displayed everything up to the
11261 bottom of the window. */
11262 && it
.current_y
< it
.last_visible_y
)
11265 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11267 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11268 run
.current_y
= first_unchanged_at_end_row
->y
;
11269 run
.desired_y
= run
.current_y
+ dy
;
11270 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11274 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11275 first_unchanged_at_end_row
= NULL
;
11277 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11280 /* Find the cursor if not already found. We have to decide whether
11281 PT will appear on this window (it sometimes doesn't, but this is
11282 not a very frequent case.) This decision has to be made before
11283 the current matrix is altered. A value of cursor.vpos < 0 means
11284 that PT is either in one of the lines beginning at
11285 first_unchanged_at_end_row or below the window. Don't care for
11286 lines that might be displayed later at the window end; as
11287 mentioned, this is not a frequent case. */
11288 if (w
->cursor
.vpos
< 0)
11290 /* Cursor in unchanged rows at the top? */
11291 if (PT
< CHARPOS (start_pos
)
11292 && last_unchanged_at_beg_row
)
11294 row
= row_containing_pos (w
, PT
,
11295 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11296 last_unchanged_at_beg_row
+ 1);
11298 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11301 /* Start from first_unchanged_at_end_row looking for PT. */
11302 else if (first_unchanged_at_end_row
)
11304 row
= row_containing_pos (w
, PT
- delta
,
11305 first_unchanged_at_end_row
, NULL
);
11307 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11308 delta_bytes
, dy
, dvpos
);
11311 /* Give up if cursor was not found. */
11312 if (w
->cursor
.vpos
< 0)
11314 clear_glyph_matrix (w
->desired_matrix
);
11319 /* Don't let the cursor end in the scroll margins. */
11321 int this_scroll_margin
, cursor_height
;
11323 this_scroll_margin
= max (0, scroll_margin
);
11324 this_scroll_margin
= min (this_scroll_margin
,
11325 XFASTINT (w
->height
) / 4);
11326 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11327 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11329 if ((w
->cursor
.y
< this_scroll_margin
11330 && CHARPOS (start
) > BEGV
)
11331 /* Don't take scroll margin into account at the bottom because
11332 old redisplay didn't do it either. */
11333 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11335 w
->cursor
.vpos
= -1;
11336 clear_glyph_matrix (w
->desired_matrix
);
11341 /* Scroll the display. Do it before changing the current matrix so
11342 that xterm.c doesn't get confused about where the cursor glyph is
11344 if (dy
&& run
.height
)
11348 if (FRAME_WINDOW_P (f
))
11350 rif
->update_window_begin_hook (w
);
11351 rif
->clear_mouse_face (w
);
11352 rif
->scroll_run_hook (w
, &run
);
11353 rif
->update_window_end_hook (w
, 0, 0);
11357 /* Terminal frame. In this case, dvpos gives the number of
11358 lines to scroll by; dvpos < 0 means scroll up. */
11359 int first_unchanged_at_end_vpos
11360 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11361 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11362 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
11364 /* Perform the operation on the screen. */
11367 /* Scroll last_unchanged_at_beg_row to the end of the
11368 window down dvpos lines. */
11369 set_terminal_window (end
);
11371 /* On dumb terminals delete dvpos lines at the end
11372 before inserting dvpos empty lines. */
11373 if (!scroll_region_ok
)
11374 ins_del_lines (end
- dvpos
, -dvpos
);
11376 /* Insert dvpos empty lines in front of
11377 last_unchanged_at_beg_row. */
11378 ins_del_lines (from
, dvpos
);
11380 else if (dvpos
< 0)
11382 /* Scroll up last_unchanged_at_beg_vpos to the end of
11383 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11384 set_terminal_window (end
);
11386 /* Delete dvpos lines in front of
11387 last_unchanged_at_beg_vpos. ins_del_lines will set
11388 the cursor to the given vpos and emit |dvpos| delete
11390 ins_del_lines (from
+ dvpos
, dvpos
);
11392 /* On a dumb terminal insert dvpos empty lines at the
11394 if (!scroll_region_ok
)
11395 ins_del_lines (end
+ dvpos
, -dvpos
);
11398 set_terminal_window (0);
11404 /* Shift reused rows of the current matrix to the right position.
11405 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11407 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11408 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11411 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11412 bottom_vpos
, dvpos
);
11413 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11416 else if (dvpos
> 0)
11418 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11419 bottom_vpos
, dvpos
);
11420 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11421 first_unchanged_at_end_vpos
+ dvpos
, 0);
11424 /* For frame-based redisplay, make sure that current frame and window
11425 matrix are in sync with respect to glyph memory. */
11426 if (!FRAME_WINDOW_P (f
))
11427 sync_frame_with_window_matrix_rows (w
);
11429 /* Adjust buffer positions in reused rows. */
11431 increment_matrix_positions (current_matrix
,
11432 first_unchanged_at_end_vpos
+ dvpos
,
11433 bottom_vpos
, delta
, delta_bytes
);
11435 /* Adjust Y positions. */
11437 shift_glyph_matrix (w
, current_matrix
,
11438 first_unchanged_at_end_vpos
+ dvpos
,
11441 if (first_unchanged_at_end_row
)
11442 first_unchanged_at_end_row
+= dvpos
;
11444 /* If scrolling up, there may be some lines to display at the end of
11446 last_text_row_at_end
= NULL
;
11449 /* Set last_row to the glyph row in the current matrix where the
11450 window end line is found. It has been moved up or down in
11451 the matrix by dvpos. */
11452 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11453 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11455 /* If last_row is the window end line, it should display text. */
11456 xassert (last_row
->displays_text_p
);
11458 /* If window end line was partially visible before, begin
11459 displaying at that line. Otherwise begin displaying with the
11460 line following it. */
11461 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11463 init_to_row_start (&it
, w
, last_row
);
11464 it
.vpos
= last_vpos
;
11465 it
.current_y
= last_row
->y
;
11469 init_to_row_end (&it
, w
, last_row
);
11470 it
.vpos
= 1 + last_vpos
;
11471 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11475 /* We may start in a continuation line. If so, we have to get
11476 the right continuation_lines_width and current_x. */
11477 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11478 it
.hpos
= it
.current_x
= 0;
11480 /* Display the rest of the lines at the window end. */
11481 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11482 while (it
.current_y
< it
.last_visible_y
11483 && !fonts_changed_p
)
11485 /* Is it always sure that the display agrees with lines in
11486 the current matrix? I don't think so, so we mark rows
11487 displayed invalid in the current matrix by setting their
11488 enabled_p flag to zero. */
11489 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11490 if (display_line (&it
))
11491 last_text_row_at_end
= it
.glyph_row
- 1;
11495 /* Update window_end_pos and window_end_vpos. */
11496 if (first_unchanged_at_end_row
11497 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11498 && !last_text_row_at_end
)
11500 /* Window end line if one of the preserved rows from the current
11501 matrix. Set row to the last row displaying text in current
11502 matrix starting at first_unchanged_at_end_row, after
11504 xassert (first_unchanged_at_end_row
->displays_text_p
);
11505 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11506 first_unchanged_at_end_row
);
11507 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11509 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
11510 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11511 XSETFASTINT (w
->window_end_vpos
,
11512 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11514 else if (last_text_row_at_end
)
11516 XSETFASTINT (w
->window_end_pos
,
11517 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11518 w
->window_end_bytepos
11519 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11520 XSETFASTINT (w
->window_end_vpos
,
11521 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11523 else if (last_text_row
)
11525 /* We have displayed either to the end of the window or at the
11526 end of the window, i.e. the last row with text is to be found
11527 in the desired matrix. */
11528 XSETFASTINT (w
->window_end_pos
,
11529 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11530 w
->window_end_bytepos
11531 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11532 XSETFASTINT (w
->window_end_vpos
,
11533 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11535 else if (first_unchanged_at_end_row
== NULL
11536 && last_text_row
== NULL
11537 && last_text_row_at_end
== NULL
)
11539 /* Displayed to end of window, but no line containing text was
11540 displayed. Lines were deleted at the end of the window. */
11542 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11544 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
11545 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11546 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
11547 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11548 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
11551 w
->window_end_vpos
= make_number (vpos
);
11556 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11557 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11559 /* Record that display has not been completed. */
11560 w
->window_end_valid
= Qnil
;
11561 w
->desired_matrix
->no_scrolling_p
= 1;
11567 /***********************************************************************
11568 More debugging support
11569 ***********************************************************************/
11573 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11574 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11575 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
11578 /* Dump the contents of glyph matrix MATRIX on stderr.
11580 GLYPHS 0 means don't show glyph contents.
11581 GLYPHS 1 means show glyphs in short form
11582 GLYPHS > 1 means show glyphs in long form. */
11585 dump_glyph_matrix (matrix
, glyphs
)
11586 struct glyph_matrix
*matrix
;
11590 for (i
= 0; i
< matrix
->nrows
; ++i
)
11591 dump_glyph_row (matrix
, i
, glyphs
);
11595 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
11596 the glyph row and area where the glyph comes from. */
11599 dump_glyph (row
, glyph
, area
)
11600 struct glyph_row
*row
;
11601 struct glyph
*glyph
;
11604 if (glyph
->type
== CHAR_GLYPH
)
11607 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11608 glyph
- row
->glyphs
[TEXT_AREA
],
11611 (BUFFERP (glyph
->object
)
11613 : (STRINGP (glyph
->object
)
11616 glyph
->pixel_width
,
11618 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11622 glyph
->left_box_line_p
,
11623 glyph
->right_box_line_p
);
11625 else if (glyph
->type
== STRETCH_GLYPH
)
11628 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11629 glyph
- row
->glyphs
[TEXT_AREA
],
11632 (BUFFERP (glyph
->object
)
11634 : (STRINGP (glyph
->object
)
11637 glyph
->pixel_width
,
11641 glyph
->left_box_line_p
,
11642 glyph
->right_box_line_p
);
11644 else if (glyph
->type
== IMAGE_GLYPH
)
11647 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11648 glyph
- row
->glyphs
[TEXT_AREA
],
11651 (BUFFERP (glyph
->object
)
11653 : (STRINGP (glyph
->object
)
11656 glyph
->pixel_width
,
11660 glyph
->left_box_line_p
,
11661 glyph
->right_box_line_p
);
11666 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11667 GLYPHS 0 means don't show glyph contents.
11668 GLYPHS 1 means show glyphs in short form
11669 GLYPHS > 1 means show glyphs in long form. */
11672 dump_glyph_row (matrix
, vpos
, glyphs
)
11673 struct glyph_matrix
*matrix
;
11676 struct glyph_row
*row
;
11678 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11681 row
= MATRIX_ROW (matrix
, vpos
);
11685 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
11686 fprintf (stderr
, "=======================================================================\n");
11688 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11689 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11690 row
- matrix
->rows
,
11691 MATRIX_ROW_START_CHARPOS (row
),
11692 MATRIX_ROW_END_CHARPOS (row
),
11693 row
->used
[TEXT_AREA
],
11694 row
->contains_overlapping_glyphs_p
,
11697 row
->truncated_on_left_p
,
11698 row
->truncated_on_right_p
,
11699 row
->overlay_arrow_p
,
11701 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11702 row
->displays_text_p
,
11705 row
->ends_in_middle_of_char_p
,
11706 row
->starts_in_middle_of_char_p
,
11712 row
->visible_height
,
11715 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
11716 row
->end
.overlay_string_index
);
11717 fprintf (stderr
, "%9d %5d\n",
11718 CHARPOS (row
->start
.string_pos
),
11719 CHARPOS (row
->end
.string_pos
));
11720 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11721 row
->end
.dpvec_index
);
11728 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11730 struct glyph
*glyph
, *glyph_end
;
11731 glyph
= row
->glyphs
[area
];
11732 glyph_end
= glyph
+ row
->used
[area
];
11734 /* Glyph for a line end in text. */
11735 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
11738 if (glyph
< glyph_end
)
11739 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11741 for (; glyph
< glyph_end
; ++glyph
)
11742 dump_glyph (row
, glyph
, area
);
11745 else if (glyphs
== 1)
11749 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11751 char *s
= (char *) alloca (row
->used
[area
] + 1);
11754 for (i
= 0; i
< row
->used
[area
]; ++i
)
11756 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
11757 if (glyph
->type
== CHAR_GLYPH
11758 && glyph
->u
.ch
< 0x80
11759 && glyph
->u
.ch
>= ' ')
11760 s
[i
] = glyph
->u
.ch
;
11766 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
11772 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11773 Sdump_glyph_matrix
, 0, 1, "p",
11774 "Dump the current matrix of the selected window to stderr.\n\
11775 Shows contents of glyph row structures. With non-nil\n\
11776 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show\n\
11777 glyphs in short form, otherwise show glyphs in long form.")
11779 Lisp_Object glyphs
;
11781 struct window
*w
= XWINDOW (selected_window
);
11782 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11784 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11785 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11786 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11787 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11788 fprintf (stderr
, "=============================================\n");
11789 dump_glyph_matrix (w
->current_matrix
,
11790 NILP (glyphs
) ? 0 : XINT (glyphs
));
11795 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
11796 "Dump glyph row ROW to stderr.\n\
11797 GLYPH 0 means don't dump glyphs.\n\
11798 GLYPH 1 means dump glyphs in short form.\n\
11799 GLYPH > 1 or omitted means dump glyphs in long form.")
11801 Lisp_Object row
, glyphs
;
11803 CHECK_NUMBER (row
, 0);
11804 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
,
11806 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
11811 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
11812 "Dump glyph row ROW of the tool-bar of the current frame to stderr.\n\
11813 GLYPH 0 means don't dump glyphs.\n\
11814 GLYPH 1 means dump glyphs in short form.\n\
11815 GLYPH > 1 or omitted means dump glyphs in long form.")
11817 Lisp_Object row
, glyphs
;
11819 struct frame
*sf
= SELECTED_FRAME ();
11820 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)->current_matrix
);
11821 dump_glyph_row (m
, XINT (row
), INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
11826 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11827 Strace_redisplay_toggle
, 0, 0, "",
11828 "Toggle tracing of redisplay.")
11831 trace_redisplay_p
= !trace_redisplay_p
;
11836 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11837 "Print STRING to stderr.")
11839 Lisp_Object string
;
11841 CHECK_STRING (string
, 0);
11842 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11846 #endif /* GLYPH_DEBUG */
11850 /***********************************************************************
11851 Building Desired Matrix Rows
11852 ***********************************************************************/
11854 /* Return a temporary glyph row holding the glyphs of an overlay
11855 arrow. Only used for non-window-redisplay windows. */
11857 static struct glyph_row
*
11858 get_overlay_arrow_glyph_row (w
)
11861 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11862 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11863 struct buffer
*old
= current_buffer
;
11864 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11865 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11866 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11870 int n_glyphs_before
;
11872 set_buffer_temp (buffer
);
11873 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11874 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11875 SET_TEXT_POS (it
.position
, 0, 0);
11877 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11879 while (p
< arrow_end
)
11881 Lisp_Object face
, ilisp
;
11883 /* Get the next character. */
11885 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11887 it
.c
= *p
, it
.len
= 1;
11890 /* Get its face. */
11891 XSETFASTINT (ilisp
, p
- arrow_string
);
11892 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11893 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11895 /* Compute its width, get its glyphs. */
11896 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11897 SET_TEXT_POS (it
.position
, -1, -1);
11898 PRODUCE_GLYPHS (&it
);
11900 /* If this character doesn't fit any more in the line, we have
11901 to remove some glyphs. */
11902 if (it
.current_x
> it
.last_visible_x
)
11904 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11909 set_buffer_temp (old
);
11910 return it
.glyph_row
;
11914 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11915 glyphs are only inserted for terminal frames since we can't really
11916 win with truncation glyphs when partially visible glyphs are
11917 involved. Which glyphs to insert is determined by
11918 produce_special_glyphs. */
11921 insert_left_trunc_glyphs (it
)
11924 struct it truncate_it
;
11925 struct glyph
*from
, *end
, *to
, *toend
;
11927 xassert (!FRAME_WINDOW_P (it
->f
));
11929 /* Get the truncation glyphs. */
11931 truncate_it
.current_x
= 0;
11932 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11933 truncate_it
.glyph_row
= &scratch_glyph_row
;
11934 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11935 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11936 truncate_it
.object
= make_number (0);
11937 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
11939 /* Overwrite glyphs from IT with truncation glyphs. */
11940 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11941 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
11942 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
11943 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
11948 /* There may be padding glyphs left over. Overwrite them too. */
11949 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
11951 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11957 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
11961 /* Compute the pixel height and width of IT->glyph_row.
11963 Most of the time, ascent and height of a display line will be equal
11964 to the max_ascent and max_height values of the display iterator
11965 structure. This is not the case if
11967 1. We hit ZV without displaying anything. In this case, max_ascent
11968 and max_height will be zero.
11970 2. We have some glyphs that don't contribute to the line height.
11971 (The glyph row flag contributes_to_line_height_p is for future
11972 pixmap extensions).
11974 The first case is easily covered by using default values because in
11975 these cases, the line height does not really matter, except that it
11976 must not be zero. */
11979 compute_line_metrics (it
)
11982 struct glyph_row
*row
= it
->glyph_row
;
11985 if (FRAME_WINDOW_P (it
->f
))
11987 int i
, header_line_height
;
11989 /* The line may consist of one space only, that was added to
11990 place the cursor on it. If so, the row's height hasn't been
11992 if (row
->height
== 0)
11994 if (it
->max_ascent
+ it
->max_descent
== 0)
11995 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
11996 row
->ascent
= it
->max_ascent
;
11997 row
->height
= it
->max_ascent
+ it
->max_descent
;
11998 row
->phys_ascent
= it
->max_phys_ascent
;
11999 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12002 /* Compute the width of this line. */
12003 row
->pixel_width
= row
->x
;
12004 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12005 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12007 xassert (row
->pixel_width
>= 0);
12008 xassert (row
->ascent
>= 0 && row
->height
> 0);
12010 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12011 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12013 /* If first line's physical ascent is larger than its logical
12014 ascent, use the physical ascent, and make the row taller.
12015 This makes accented characters fully visible. */
12016 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12017 && row
->phys_ascent
> row
->ascent
)
12019 row
->height
+= row
->phys_ascent
- row
->ascent
;
12020 row
->ascent
= row
->phys_ascent
;
12023 /* Compute how much of the line is visible. */
12024 row
->visible_height
= row
->height
;
12026 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12027 if (row
->y
< header_line_height
)
12028 row
->visible_height
-= header_line_height
- row
->y
;
12031 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12032 if (row
->y
+ row
->height
> max_y
)
12033 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12038 row
->pixel_width
= row
->used
[TEXT_AREA
];
12039 row
->ascent
= row
->phys_ascent
= 0;
12040 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12043 /* Compute a hash code for this row. */
12045 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12046 for (i
= 0; i
< row
->used
[area
]; ++i
)
12047 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12048 + row
->glyphs
[area
][i
].u
.val
12049 + row
->glyphs
[area
][i
].face_id
12050 + row
->glyphs
[area
][i
].padding_p
12051 + (row
->glyphs
[area
][i
].type
<< 2));
12053 it
->max_ascent
= it
->max_descent
= 0;
12054 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12058 /* Append one space to the glyph row of iterator IT if doing a
12059 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12060 space have the default face, otherwise let it have the same face as
12061 IT->face_id. Value is non-zero if a space was added.
12063 This function is called to make sure that there is always one glyph
12064 at the end of a glyph row that the cursor can be set on under
12065 window-systems. (If there weren't such a glyph we would not know
12066 how wide and tall a box cursor should be displayed).
12068 At the same time this space let's a nicely handle clearing to the
12069 end of the line if the row ends in italic text. */
12072 append_space (it
, default_face_p
)
12074 int default_face_p
;
12076 if (FRAME_WINDOW_P (it
->f
))
12078 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12080 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12081 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12083 /* Save some values that must not be changed.
12084 Must save IT->c and IT->len because otherwise
12085 ITERATOR_AT_END_P wouldn't work anymore after
12086 append_space has been called. */
12087 enum display_element_type saved_what
= it
->what
;
12088 int saved_c
= it
->c
, saved_len
= it
->len
;
12089 int saved_x
= it
->current_x
;
12090 int saved_face_id
= it
->face_id
;
12091 struct text_pos saved_pos
;
12092 Lisp_Object saved_object
;
12095 saved_object
= it
->object
;
12096 saved_pos
= it
->position
;
12098 it
->what
= IT_CHARACTER
;
12099 bzero (&it
->position
, sizeof it
->position
);
12100 it
->object
= make_number (0);
12104 if (default_face_p
)
12105 it
->face_id
= DEFAULT_FACE_ID
;
12106 else if (it
->face_before_selective_p
)
12107 it
->face_id
= it
->saved_face_id
;
12108 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12109 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12111 PRODUCE_GLYPHS (it
);
12113 it
->current_x
= saved_x
;
12114 it
->object
= saved_object
;
12115 it
->position
= saved_pos
;
12116 it
->what
= saved_what
;
12117 it
->face_id
= saved_face_id
;
12118 it
->len
= saved_len
;
12128 /* Extend the face of the last glyph in the text area of IT->glyph_row
12129 to the end of the display line. Called from display_line.
12130 If the glyph row is empty, add a space glyph to it so that we
12131 know the face to draw. Set the glyph row flag fill_line_p. */
12134 extend_face_to_end_of_line (it
)
12138 struct frame
*f
= it
->f
;
12140 /* If line is already filled, do nothing. */
12141 if (it
->current_x
>= it
->last_visible_x
)
12144 /* Face extension extends the background and box of IT->face_id
12145 to the end of the line. If the background equals the background
12146 of the frame, we don't have to do anything. */
12147 if (it
->face_before_selective_p
)
12148 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12150 face
= FACE_FROM_ID (f
, it
->face_id
);
12152 if (FRAME_WINDOW_P (f
)
12153 && face
->box
== FACE_NO_BOX
12154 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12158 /* Set the glyph row flag indicating that the face of the last glyph
12159 in the text area has to be drawn to the end of the text area. */
12160 it
->glyph_row
->fill_line_p
= 1;
12162 /* If current character of IT is not ASCII, make sure we have the
12163 ASCII face. This will be automatically undone the next time
12164 get_next_display_element returns a multibyte character. Note
12165 that the character will always be single byte in unibyte text. */
12166 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12168 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12171 if (FRAME_WINDOW_P (f
))
12173 /* If the row is empty, add a space with the current face of IT,
12174 so that we know which face to draw. */
12175 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12177 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12178 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12179 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12184 /* Save some values that must not be changed. */
12185 int saved_x
= it
->current_x
;
12186 struct text_pos saved_pos
;
12187 Lisp_Object saved_object
;
12188 enum display_element_type saved_what
= it
->what
;
12189 int saved_face_id
= it
->face_id
;
12191 saved_object
= it
->object
;
12192 saved_pos
= it
->position
;
12194 it
->what
= IT_CHARACTER
;
12195 bzero (&it
->position
, sizeof it
->position
);
12196 it
->object
= make_number (0);
12199 it
->face_id
= face
->id
;
12201 PRODUCE_GLYPHS (it
);
12203 while (it
->current_x
<= it
->last_visible_x
)
12204 PRODUCE_GLYPHS (it
);
12206 /* Don't count these blanks really. It would let us insert a left
12207 truncation glyph below and make us set the cursor on them, maybe. */
12208 it
->current_x
= saved_x
;
12209 it
->object
= saved_object
;
12210 it
->position
= saved_pos
;
12211 it
->what
= saved_what
;
12212 it
->face_id
= saved_face_id
;
12217 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12218 trailing whitespace. */
12221 trailing_whitespace_p (charpos
)
12224 int bytepos
= CHAR_TO_BYTE (charpos
);
12227 while (bytepos
< ZV_BYTE
12228 && (c
= FETCH_CHAR (bytepos
),
12229 c
== ' ' || c
== '\t'))
12232 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12234 if (bytepos
!= PT_BYTE
)
12241 /* Highlight trailing whitespace, if any, in ROW. */
12244 highlight_trailing_whitespace (f
, row
)
12246 struct glyph_row
*row
;
12248 int used
= row
->used
[TEXT_AREA
];
12252 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12253 struct glyph
*glyph
= start
+ used
- 1;
12255 /* Skip over space glyphs inserted to display the cursor at the
12256 end of a line, and for extending the face of the last glyph
12257 to the end of the line on terminals. */
12258 while (glyph
>= start
12259 && glyph
->type
== CHAR_GLYPH
12260 && glyph
->u
.ch
== ' '
12261 && INTEGERP (glyph
->object
))
12264 /* If last glyph is a space or stretch, and it's trailing
12265 whitespace, set the face of all trailing whitespace glyphs in
12266 IT->glyph_row to `trailing-whitespace'. */
12268 && BUFFERP (glyph
->object
)
12269 && (glyph
->type
== STRETCH_GLYPH
12270 || (glyph
->type
== CHAR_GLYPH
12271 && glyph
->u
.ch
== ' '))
12272 && trailing_whitespace_p (glyph
->charpos
))
12274 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12276 while (glyph
>= start
12277 && BUFFERP (glyph
->object
)
12278 && (glyph
->type
== STRETCH_GLYPH
12279 || (glyph
->type
== CHAR_GLYPH
12280 && glyph
->u
.ch
== ' ')))
12281 (glyph
--)->face_id
= face_id
;
12287 /* Value is non-zero if glyph row ROW in window W should be
12288 used to hold the cursor. */
12291 cursor_row_p (w
, row
)
12293 struct glyph_row
*row
;
12295 int cursor_row_p
= 1;
12297 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12299 /* If the row ends with a newline from a string, we don't want
12300 the cursor there (if the row is continued it doesn't end in a
12302 if (CHARPOS (row
->end
.string_pos
) >= 0
12303 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12304 cursor_row_p
= row
->continued_p
;
12306 /* If the row ends at ZV, display the cursor at the end of that
12307 row instead of at the start of the row below. */
12308 else if (row
->ends_at_zv_p
)
12314 return cursor_row_p
;
12318 /* Construct the glyph row IT->glyph_row in the desired matrix of
12319 IT->w from text at the current position of IT. See dispextern.h
12320 for an overview of struct it. Value is non-zero if
12321 IT->glyph_row displays text, as opposed to a line displaying ZV
12328 struct glyph_row
*row
= it
->glyph_row
;
12330 /* We always start displaying at hpos zero even if hscrolled. */
12331 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12333 /* We must not display in a row that's not a text row. */
12334 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12335 < it
->w
->desired_matrix
->nrows
);
12337 /* Is IT->w showing the region? */
12338 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12340 /* Clear the result glyph row and enable it. */
12341 prepare_desired_row (row
);
12343 row
->y
= it
->current_y
;
12344 row
->start
= it
->current
;
12345 row
->continuation_lines_width
= it
->continuation_lines_width
;
12346 row
->displays_text_p
= 1;
12347 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12348 it
->starts_in_middle_of_char_p
= 0;
12350 /* Arrange the overlays nicely for our purposes. Usually, we call
12351 display_line on only one line at a time, in which case this
12352 can't really hurt too much, or we call it on lines which appear
12353 one after another in the buffer, in which case all calls to
12354 recenter_overlay_lists but the first will be pretty cheap. */
12355 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12357 /* Move over display elements that are not visible because we are
12358 hscrolled. This may stop at an x-position < IT->first_visible_x
12359 if the first glyph is partially visible or if we hit a line end. */
12360 if (it
->current_x
< it
->first_visible_x
)
12361 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12362 MOVE_TO_POS
| MOVE_TO_X
);
12364 /* Get the initial row height. This is either the height of the
12365 text hscrolled, if there is any, or zero. */
12366 row
->ascent
= it
->max_ascent
;
12367 row
->height
= it
->max_ascent
+ it
->max_descent
;
12368 row
->phys_ascent
= it
->max_phys_ascent
;
12369 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12371 /* Loop generating characters. The loop is left with IT on the next
12372 character to display. */
12375 int n_glyphs_before
, hpos_before
, x_before
;
12377 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12379 /* Retrieve the next thing to display. Value is zero if end of
12381 if (!get_next_display_element (it
))
12383 /* Maybe add a space at the end of this line that is used to
12384 display the cursor there under X. Set the charpos of the
12385 first glyph of blank lines not corresponding to any text
12387 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12388 || row
->used
[TEXT_AREA
] == 0)
12390 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12391 row
->displays_text_p
= 0;
12393 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12394 row
->indicate_empty_line_p
= 1;
12397 it
->continuation_lines_width
= 0;
12398 row
->ends_at_zv_p
= 1;
12402 /* Now, get the metrics of what we want to display. This also
12403 generates glyphs in `row' (which is IT->glyph_row). */
12404 n_glyphs_before
= row
->used
[TEXT_AREA
];
12407 /* Remember the line height so far in case the next element doesn't
12408 fit on the line. */
12409 if (!it
->truncate_lines_p
)
12411 ascent
= it
->max_ascent
;
12412 descent
= it
->max_descent
;
12413 phys_ascent
= it
->max_phys_ascent
;
12414 phys_descent
= it
->max_phys_descent
;
12417 PRODUCE_GLYPHS (it
);
12419 /* If this display element was in marginal areas, continue with
12421 if (it
->area
!= TEXT_AREA
)
12423 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12424 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12425 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12426 row
->phys_height
= max (row
->phys_height
,
12427 it
->max_phys_ascent
+ it
->max_phys_descent
);
12428 set_iterator_to_next (it
, 1);
12432 /* Does the display element fit on the line? If we truncate
12433 lines, we should draw past the right edge of the window. If
12434 we don't truncate, we want to stop so that we can display the
12435 continuation glyph before the right margin. If lines are
12436 continued, there are two possible strategies for characters
12437 resulting in more than 1 glyph (e.g. tabs): Display as many
12438 glyphs as possible in this line and leave the rest for the
12439 continuation line, or display the whole element in the next
12440 line. Original redisplay did the former, so we do it also. */
12441 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12442 hpos_before
= it
->hpos
;
12445 if (/* Not a newline. */
12447 /* Glyphs produced fit entirely in the line. */
12448 && it
->current_x
< it
->last_visible_x
)
12450 it
->hpos
+= nglyphs
;
12451 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12452 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12453 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12454 row
->phys_height
= max (row
->phys_height
,
12455 it
->max_phys_ascent
+ it
->max_phys_descent
);
12456 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12457 row
->x
= x
- it
->first_visible_x
;
12462 struct glyph
*glyph
;
12464 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12466 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12467 new_x
= x
+ glyph
->pixel_width
;
12469 if (/* Lines are continued. */
12470 !it
->truncate_lines_p
12471 && (/* Glyph doesn't fit on the line. */
12472 new_x
> it
->last_visible_x
12473 /* Or it fits exactly on a window system frame. */
12474 || (new_x
== it
->last_visible_x
12475 && FRAME_WINDOW_P (it
->f
))))
12477 /* End of a continued line. */
12480 || (new_x
== it
->last_visible_x
12481 && FRAME_WINDOW_P (it
->f
)))
12483 /* Current glyph is the only one on the line or
12484 fits exactly on the line. We must continue
12485 the line because we can't draw the cursor
12486 after the glyph. */
12487 row
->continued_p
= 1;
12488 it
->current_x
= new_x
;
12489 it
->continuation_lines_width
+= new_x
;
12491 if (i
== nglyphs
- 1)
12492 set_iterator_to_next (it
, 1);
12494 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12495 && !FRAME_WINDOW_P (it
->f
))
12497 /* A padding glyph that doesn't fit on this line.
12498 This means the whole character doesn't fit
12500 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12502 /* Fill the rest of the row with continuation
12503 glyphs like in 20.x. */
12504 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12505 < row
->glyphs
[1 + TEXT_AREA
])
12506 produce_special_glyphs (it
, IT_CONTINUATION
);
12508 row
->continued_p
= 1;
12509 it
->current_x
= x_before
;
12510 it
->continuation_lines_width
+= x_before
;
12512 /* Restore the height to what it was before the
12513 element not fitting on the line. */
12514 it
->max_ascent
= ascent
;
12515 it
->max_descent
= descent
;
12516 it
->max_phys_ascent
= phys_ascent
;
12517 it
->max_phys_descent
= phys_descent
;
12521 /* Display element draws past the right edge of
12522 the window. Restore positions to values
12523 before the element. The next line starts
12524 with current_x before the glyph that could
12525 not be displayed, so that TAB works right. */
12526 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12528 /* Display continuation glyphs. */
12529 if (!FRAME_WINDOW_P (it
->f
))
12530 produce_special_glyphs (it
, IT_CONTINUATION
);
12531 row
->continued_p
= 1;
12534 it
->continuation_lines_width
+= x
;
12535 if (nglyphs
> 1 && i
> 0)
12537 row
->ends_in_middle_of_char_p
= 1;
12538 it
->starts_in_middle_of_char_p
= 1;
12541 /* Restore the height to what it was before the
12542 element not fitting on the line. */
12543 it
->max_ascent
= ascent
;
12544 it
->max_descent
= descent
;
12545 it
->max_phys_ascent
= phys_ascent
;
12546 it
->max_phys_descent
= phys_descent
;
12551 else if (new_x
> it
->first_visible_x
)
12553 /* Increment number of glyphs actually displayed. */
12556 if (x
< it
->first_visible_x
)
12557 /* Glyph is partially visible, i.e. row starts at
12558 negative X position. */
12559 row
->x
= x
- it
->first_visible_x
;
12563 /* Glyph is completely off the left margin of the
12564 window. This should not happen because of the
12565 move_it_in_display_line at the start of
12571 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12572 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12573 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12574 row
->phys_height
= max (row
->phys_height
,
12575 it
->max_phys_ascent
+ it
->max_phys_descent
);
12577 /* End of this display line if row is continued. */
12578 if (row
->continued_p
)
12582 /* Is this a line end? If yes, we're also done, after making
12583 sure that a non-default face is extended up to the right
12584 margin of the window. */
12585 if (ITERATOR_AT_END_OF_LINE_P (it
))
12587 int used_before
= row
->used
[TEXT_AREA
];
12589 /* Add a space at the end of the line that is used to
12590 display the cursor there. */
12591 append_space (it
, 0);
12593 /* Extend the face to the end of the line. */
12594 extend_face_to_end_of_line (it
);
12596 /* Make sure we have the position. */
12597 if (used_before
== 0)
12598 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12600 /* Consume the line end. This skips over invisible lines. */
12601 set_iterator_to_next (it
, 1);
12602 it
->continuation_lines_width
= 0;
12606 /* Proceed with next display element. Note that this skips
12607 over lines invisible because of selective display. */
12608 set_iterator_to_next (it
, 1);
12610 /* If we truncate lines, we are done when the last displayed
12611 glyphs reach past the right margin of the window. */
12612 if (it
->truncate_lines_p
12613 && (FRAME_WINDOW_P (it
->f
)
12614 ? (it
->current_x
>= it
->last_visible_x
)
12615 : (it
->current_x
> it
->last_visible_x
)))
12617 /* Maybe add truncation glyphs. */
12618 if (!FRAME_WINDOW_P (it
->f
))
12622 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
12623 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
12626 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
12628 row
->used
[TEXT_AREA
] = i
;
12629 produce_special_glyphs (it
, IT_TRUNCATION
);
12633 row
->truncated_on_right_p
= 1;
12634 it
->continuation_lines_width
= 0;
12635 reseat_at_next_visible_line_start (it
, 0);
12636 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12637 it
->hpos
= hpos_before
;
12638 it
->current_x
= x_before
;
12643 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12644 at the left window margin. */
12645 if (it
->first_visible_x
12646 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12648 if (!FRAME_WINDOW_P (it
->f
))
12649 insert_left_trunc_glyphs (it
);
12650 row
->truncated_on_left_p
= 1;
12653 /* If the start of this line is the overlay arrow-position, then
12654 mark this glyph row as the one containing the overlay arrow.
12655 This is clearly a mess with variable size fonts. It would be
12656 better to let it be displayed like cursors under X. */
12657 if (MARKERP (Voverlay_arrow_position
)
12658 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12659 && (MATRIX_ROW_START_CHARPOS (row
)
12660 == marker_position (Voverlay_arrow_position
))
12661 && STRINGP (Voverlay_arrow_string
)
12662 && ! overlay_arrow_seen
)
12664 /* Overlay arrow in window redisplay is a bitmap. */
12665 if (!FRAME_WINDOW_P (it
->f
))
12667 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12668 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12669 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12670 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12671 struct glyph
*p2
, *end
;
12673 /* Copy the arrow glyphs. */
12674 while (glyph
< arrow_end
)
12677 /* Throw away padding glyphs. */
12679 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12680 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12686 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12690 overlay_arrow_seen
= 1;
12691 row
->overlay_arrow_p
= 1;
12694 /* Compute pixel dimensions of this line. */
12695 compute_line_metrics (it
);
12697 /* Remember the position at which this line ends. */
12698 row
->end
= it
->current
;
12700 /* Maybe set the cursor. */
12701 if (it
->w
->cursor
.vpos
< 0
12702 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12703 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12704 && cursor_row_p (it
->w
, row
))
12705 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12707 /* Highlight trailing whitespace. */
12708 if (!NILP (Vshow_trailing_whitespace
))
12709 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12711 /* Prepare for the next line. This line starts horizontally at (X
12712 HPOS) = (0 0). Vertical positions are incremented. As a
12713 convenience for the caller, IT->glyph_row is set to the next
12715 it
->current_x
= it
->hpos
= 0;
12716 it
->current_y
+= row
->height
;
12719 return row
->displays_text_p
;
12724 /***********************************************************************
12726 ***********************************************************************/
12728 /* Redisplay the menu bar in the frame for window W.
12730 The menu bar of X frames that don't have X toolkit support is
12731 displayed in a special window W->frame->menu_bar_window.
12733 The menu bar of terminal frames is treated specially as far as
12734 glyph matrices are concerned. Menu bar lines are not part of
12735 windows, so the update is done directly on the frame matrix rows
12736 for the menu bar. */
12739 display_menu_bar (w
)
12742 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12747 /* Don't do all this for graphical frames. */
12749 if (!NILP (Vwindow_system
))
12752 #ifdef USE_X_TOOLKIT
12757 if (FRAME_MAC_P (f
))
12761 #ifdef USE_X_TOOLKIT
12762 xassert (!FRAME_WINDOW_P (f
));
12763 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12764 it
.first_visible_x
= 0;
12765 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12766 #else /* not USE_X_TOOLKIT */
12767 if (FRAME_WINDOW_P (f
))
12769 /* Menu bar lines are displayed in the desired matrix of the
12770 dummy window menu_bar_window. */
12771 struct window
*menu_w
;
12772 xassert (WINDOWP (f
->menu_bar_window
));
12773 menu_w
= XWINDOW (f
->menu_bar_window
);
12774 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12776 it
.first_visible_x
= 0;
12777 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12781 /* This is a TTY frame, i.e. character hpos/vpos are used as
12783 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12785 it
.first_visible_x
= 0;
12786 it
.last_visible_x
= FRAME_WIDTH (f
);
12788 #endif /* not USE_X_TOOLKIT */
12790 if (! mode_line_inverse_video
)
12791 /* Force the menu-bar to be displayed in the default face. */
12792 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
12794 /* Clear all rows of the menu bar. */
12795 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12797 struct glyph_row
*row
= it
.glyph_row
+ i
;
12798 clear_glyph_row (row
);
12799 row
->enabled_p
= 1;
12800 row
->full_width_p
= 1;
12803 /* Display all items of the menu bar. */
12804 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12805 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12807 Lisp_Object string
;
12809 /* Stop at nil string. */
12810 string
= AREF (items
, i
+ 1);
12814 /* Remember where item was displayed. */
12815 AREF (items
, i
+ 3) = make_number (it
.hpos
);
12817 /* Display the item, pad with one space. */
12818 if (it
.current_x
< it
.last_visible_x
)
12819 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12820 XSTRING (string
)->size
+ 1, 0, 0, -1);
12823 /* Fill out the line with spaces. */
12824 if (it
.current_x
< it
.last_visible_x
)
12825 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12827 /* Compute the total height of the lines. */
12828 compute_line_metrics (&it
);
12833 /***********************************************************************
12835 ***********************************************************************/
12837 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12838 FORCE is non-zero, redisplay mode lines unconditionally.
12839 Otherwise, redisplay only mode lines that are garbaged. Value is
12840 the number of windows whose mode lines were redisplayed. */
12843 redisplay_mode_lines (window
, force
)
12844 Lisp_Object window
;
12849 while (!NILP (window
))
12851 struct window
*w
= XWINDOW (window
);
12853 if (WINDOWP (w
->hchild
))
12854 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12855 else if (WINDOWP (w
->vchild
))
12856 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12858 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12859 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12861 Lisp_Object old_selected_frame
;
12862 struct text_pos lpoint
;
12863 struct buffer
*old
= current_buffer
;
12865 /* Set the window's buffer for the mode line display. */
12866 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12867 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12869 /* Point refers normally to the selected window. For any
12870 other window, set up appropriate value. */
12871 if (!EQ (window
, selected_window
))
12873 struct text_pos pt
;
12875 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12876 if (CHARPOS (pt
) < BEGV
)
12877 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12878 else if (CHARPOS (pt
) > (ZV
- 1))
12879 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12881 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12884 /* Temporarily set up the selected frame. */
12885 old_selected_frame
= selected_frame
;
12886 selected_frame
= w
->frame
;
12888 /* Display mode lines. */
12889 clear_glyph_matrix (w
->desired_matrix
);
12890 if (display_mode_lines (w
))
12893 w
->must_be_updated_p
= 1;
12896 /* Restore old settings. */
12897 selected_frame
= old_selected_frame
;
12898 set_buffer_internal_1 (old
);
12899 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12909 /* Display the mode and/or top line of window W. Value is the number
12910 of mode lines displayed. */
12913 display_mode_lines (w
)
12918 /* These will be set while the mode line specs are processed. */
12919 line_number_displayed
= 0;
12920 w
->column_number_displayed
= Qnil
;
12922 if (WINDOW_WANTS_MODELINE_P (w
))
12924 display_mode_line (w
, MODE_LINE_FACE_ID
,
12925 current_buffer
->mode_line_format
);
12929 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12931 display_mode_line (w
, HEADER_LINE_FACE_ID
,
12932 current_buffer
->header_line_format
);
12940 /* Display mode or top line of window W. FACE_ID specifies which line
12941 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
12942 FORMAT is the mode line format to display. Value is the pixel
12943 height of the mode line displayed. */
12946 display_mode_line (w
, face_id
, format
)
12948 enum face_id face_id
;
12949 Lisp_Object format
;
12954 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
12955 prepare_desired_row (it
.glyph_row
);
12957 if (! mode_line_inverse_video
)
12958 /* Force the mode-line to be displayed in the default face. */
12959 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
12961 /* Temporarily make frame's keyboard the current kboard so that
12962 kboard-local variables in the mode_line_format will get the right
12964 push_frame_kboard (it
.f
);
12965 display_mode_element (&it
, 0, 0, 0, format
);
12966 pop_frame_kboard ();
12968 /* Fill up with spaces. */
12969 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
12971 compute_line_metrics (&it
);
12972 it
.glyph_row
->full_width_p
= 1;
12973 it
.glyph_row
->mode_line_p
= 1;
12974 it
.glyph_row
->inverse_p
= 0;
12975 it
.glyph_row
->continued_p
= 0;
12976 it
.glyph_row
->truncated_on_left_p
= 0;
12977 it
.glyph_row
->truncated_on_right_p
= 0;
12979 /* Make a 3D mode-line have a shadow at its right end. */
12980 face
= FACE_FROM_ID (it
.f
, face_id
);
12981 extend_face_to_end_of_line (&it
);
12982 if (face
->box
!= FACE_NO_BOX
)
12984 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
12985 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
12986 last
->right_box_line_p
= 1;
12989 return it
.glyph_row
->height
;
12993 /* Contribute ELT to the mode line for window IT->w. How it
12994 translates into text depends on its data type.
12996 IT describes the display environment in which we display, as usual.
12998 DEPTH is the depth in recursion. It is used to prevent
12999 infinite recursion here.
13001 FIELD_WIDTH is the number of characters the display of ELT should
13002 occupy in the mode line, and PRECISION is the maximum number of
13003 characters to display from ELT's representation. See
13004 display_string for details. *
13006 Returns the hpos of the end of the text generated by ELT. */
13009 display_mode_element (it
, depth
, field_width
, precision
, elt
)
13012 int field_width
, precision
;
13015 int n
= 0, field
, prec
;
13023 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13027 /* A string: output it and check for %-constructs within it. */
13029 unsigned char *this = XSTRING (elt
)->data
;
13030 unsigned char *lisp_string
= this;
13032 while ((precision
<= 0 || n
< precision
)
13034 && (frame_title_ptr
13035 || it
->current_x
< it
->last_visible_x
))
13037 unsigned char *last
= this;
13039 /* Advance to end of string or next format specifier. */
13040 while ((c
= *this++) != '\0' && c
!= '%')
13043 if (this - 1 != last
)
13045 /* Output to end of string or up to '%'. Field width
13046 is length of string. Don't output more than
13047 PRECISION allows us. */
13049 prec
= strwidth (last
, this - last
);
13050 if (precision
> 0 && prec
> precision
- n
)
13051 prec
= precision
- n
;
13053 if (frame_title_ptr
)
13054 n
+= store_frame_title (last
, 0, prec
);
13056 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
13057 it
, 0, prec
, 0, -1);
13059 else /* c == '%' */
13061 unsigned char *percent_position
= this;
13063 /* Get the specified minimum width. Zero means
13066 while ((c
= *this++) >= '0' && c
<= '9')
13067 field
= field
* 10 + c
- '0';
13069 /* Don't pad beyond the total padding allowed. */
13070 if (field_width
- n
> 0 && field
> field_width
- n
)
13071 field
= field_width
- n
;
13073 /* Note that either PRECISION <= 0 or N < PRECISION. */
13074 prec
= precision
- n
;
13077 n
+= display_mode_element (it
, depth
, field
, prec
,
13078 Vglobal_mode_string
);
13081 unsigned char *spec
13082 = decode_mode_spec (it
->w
, c
, field
, prec
);
13084 if (frame_title_ptr
)
13085 n
+= store_frame_title (spec
, field
, prec
);
13089 = it
->glyph_row
->used
[TEXT_AREA
];
13091 = percent_position
- XSTRING (elt
)->data
;
13093 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
13094 field
, prec
, 0, -1);
13096 /* Assign to the glyphs written above the
13097 string where the `%x' came from, position
13101 struct glyph
*glyph
13102 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13106 for (i
= 0; i
< nwritten
; ++i
)
13108 glyph
[i
].object
= elt
;
13109 glyph
[i
].charpos
= charpos
;
13122 /* A symbol: process the value of the symbol recursively
13123 as if it appeared here directly. Avoid error if symbol void.
13124 Special case: if value of symbol is a string, output the string
13127 register Lisp_Object tem
;
13128 tem
= Fboundp (elt
);
13131 tem
= Fsymbol_value (elt
);
13132 /* If value is a string, output that string literally:
13133 don't check for % within it. */
13136 prec
= precision
- n
;
13137 if (frame_title_ptr
)
13138 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
13140 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
13143 else if (!EQ (tem
, elt
))
13145 /* Give up right away for nil or t. */
13155 register Lisp_Object car
, tem
;
13157 /* A cons cell: three distinct cases.
13158 If first element is a string or a cons, process all the elements
13159 and effectively concatenate them.
13160 If first element is a negative number, truncate displaying cdr to
13161 at most that many characters. If positive, pad (with spaces)
13162 to at least that many characters.
13163 If first element is a symbol, process the cadr or caddr recursively
13164 according to whether the symbol's value is non-nil or nil. */
13166 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
13168 /* An element of the form (:eval FORM) means evaluate FORM
13169 and use the result as mode line elements. */
13170 struct gcpro gcpro1
;
13173 spec
= safe_eval (XCAR (XCDR (elt
)));
13175 n
+= display_mode_element (it
, depth
, field_width
- n
,
13176 precision
- n
, spec
);
13179 else if (SYMBOLP (car
))
13181 tem
= Fboundp (car
);
13185 /* elt is now the cdr, and we know it is a cons cell.
13186 Use its car if CAR has a non-nil value. */
13189 tem
= Fsymbol_value (car
);
13196 /* Symbol's value is nil (or symbol is unbound)
13197 Get the cddr of the original list
13198 and if possible find the caddr and use that. */
13202 else if (!CONSP (elt
))
13207 else if (INTEGERP (car
))
13209 register int lim
= XINT (car
);
13213 /* Negative int means reduce maximum width. */
13214 if (precision
<= 0)
13217 precision
= min (precision
, -lim
);
13221 /* Padding specified. Don't let it be more than
13222 current maximum. */
13224 lim
= min (precision
, lim
);
13226 /* If that's more padding than already wanted, queue it.
13227 But don't reduce padding already specified even if
13228 that is beyond the current truncation point. */
13229 field_width
= max (lim
, field_width
);
13233 else if (STRINGP (car
) || CONSP (car
))
13235 register int limit
= 50;
13236 /* Limit is to protect against circular lists. */
13239 && (precision
<= 0 || n
< precision
))
13241 n
+= display_mode_element (it
, depth
, field_width
- n
,
13242 precision
- n
, XCAR (elt
));
13251 if (frame_title_ptr
)
13252 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13254 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13255 precision
- n
, 0, 0);
13259 /* Pad to FIELD_WIDTH. */
13260 if (field_width
> 0 && n
< field_width
)
13262 if (frame_title_ptr
)
13263 n
+= store_frame_title ("", field_width
- n
, 0);
13265 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13273 /* Write a null-terminated, right justified decimal representation of
13274 the positive integer D to BUF using a minimal field width WIDTH. */
13277 pint2str (buf
, width
, d
)
13278 register char *buf
;
13279 register int width
;
13282 register char *p
= buf
;
13290 *p
++ = d
% 10 + '0';
13295 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13306 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13307 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13308 type of CODING_SYSTEM. Return updated pointer into BUF. */
13310 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13313 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13314 Lisp_Object coding_system
;
13315 register char *buf
;
13319 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13320 unsigned char *eol_str
;
13322 /* The EOL conversion we are using. */
13323 Lisp_Object eoltype
;
13325 val
= Fget (coding_system
, Qcoding_system
);
13328 if (!VECTORP (val
)) /* Not yet decided. */
13333 eoltype
= eol_mnemonic_undecided
;
13334 /* Don't mention EOL conversion if it isn't decided. */
13338 Lisp_Object eolvalue
;
13340 eolvalue
= Fget (coding_system
, Qeol_type
);
13343 *buf
++ = XFASTINT (AREF (val
, 1));
13347 /* The EOL conversion that is normal on this system. */
13349 if (NILP (eolvalue
)) /* Not yet decided. */
13350 eoltype
= eol_mnemonic_undecided
;
13351 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13352 eoltype
= eol_mnemonic_undecided
;
13353 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13354 eoltype
= (XFASTINT (eolvalue
) == 0
13355 ? eol_mnemonic_unix
13356 : (XFASTINT (eolvalue
) == 1
13357 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13363 /* Mention the EOL conversion if it is not the usual one. */
13364 if (STRINGP (eoltype
))
13366 eol_str
= XSTRING (eoltype
)->data
;
13367 eol_str_len
= XSTRING (eoltype
)->size
;
13369 else if (INTEGERP (eoltype
)
13370 && CHAR_VALID_P (XINT (eoltype
), 0))
13372 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13373 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13377 eol_str
= invalid_eol_type
;
13378 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13380 bcopy (eol_str
, buf
, eol_str_len
);
13381 buf
+= eol_str_len
;
13387 /* Return a string for the output of a mode line %-spec for window W,
13388 generated by character C. PRECISION >= 0 means don't return a
13389 string longer than that value. FIELD_WIDTH > 0 means pad the
13390 string returned with spaces to that value. */
13392 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13395 decode_mode_spec (w
, c
, field_width
, precision
)
13398 int field_width
, precision
;
13401 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13402 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13403 struct buffer
*b
= XBUFFER (w
->buffer
);
13410 if (!NILP (b
->read_only
))
13412 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13417 /* This differs from %* only for a modified read-only buffer. */
13418 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13420 if (!NILP (b
->read_only
))
13425 /* This differs from %* in ignoring read-only-ness. */
13426 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13438 if (command_loop_level
> 5)
13440 p
= decode_mode_spec_buf
;
13441 for (i
= 0; i
< command_loop_level
; i
++)
13444 return decode_mode_spec_buf
;
13452 if (command_loop_level
> 5)
13454 p
= decode_mode_spec_buf
;
13455 for (i
= 0; i
< command_loop_level
; i
++)
13458 return decode_mode_spec_buf
;
13465 /* Let lots_of_dashes be a string of infinite length. */
13466 if (field_width
<= 0
13467 || field_width
> sizeof (lots_of_dashes
))
13469 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13470 decode_mode_spec_buf
[i
] = '-';
13471 decode_mode_spec_buf
[i
] = '\0';
13472 return decode_mode_spec_buf
;
13475 return lots_of_dashes
;
13484 int col
= current_column ();
13485 XSETFASTINT (w
->column_number_displayed
, col
);
13486 pint2str (decode_mode_spec_buf
, field_width
, col
);
13487 return decode_mode_spec_buf
;
13491 /* %F displays the frame name. */
13492 if (!NILP (f
->title
))
13493 return (char *) XSTRING (f
->title
)->data
;
13494 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13495 return (char *) XSTRING (f
->name
)->data
;
13504 int startpos
= XMARKER (w
->start
)->charpos
;
13505 int startpos_byte
= marker_byte_position (w
->start
);
13506 int line
, linepos
, linepos_byte
, topline
;
13508 int height
= XFASTINT (w
->height
);
13510 /* If we decided that this buffer isn't suitable for line numbers,
13511 don't forget that too fast. */
13512 if (EQ (w
->base_line_pos
, w
->buffer
))
13514 /* But do forget it, if the window shows a different buffer now. */
13515 else if (BUFFERP (w
->base_line_pos
))
13516 w
->base_line_pos
= Qnil
;
13518 /* If the buffer is very big, don't waste time. */
13519 if (INTEGERP (Vline_number_display_limit
)
13520 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13522 w
->base_line_pos
= Qnil
;
13523 w
->base_line_number
= Qnil
;
13527 if (!NILP (w
->base_line_number
)
13528 && !NILP (w
->base_line_pos
)
13529 && XFASTINT (w
->base_line_pos
) <= startpos
)
13531 line
= XFASTINT (w
->base_line_number
);
13532 linepos
= XFASTINT (w
->base_line_pos
);
13533 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13538 linepos
= BUF_BEGV (b
);
13539 linepos_byte
= BUF_BEGV_BYTE (b
);
13542 /* Count lines from base line to window start position. */
13543 nlines
= display_count_lines (linepos
, linepos_byte
,
13547 topline
= nlines
+ line
;
13549 /* Determine a new base line, if the old one is too close
13550 or too far away, or if we did not have one.
13551 "Too close" means it's plausible a scroll-down would
13552 go back past it. */
13553 if (startpos
== BUF_BEGV (b
))
13555 XSETFASTINT (w
->base_line_number
, topline
);
13556 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
13558 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13559 || linepos
== BUF_BEGV (b
))
13561 int limit
= BUF_BEGV (b
);
13562 int limit_byte
= BUF_BEGV_BYTE (b
);
13564 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13566 if (startpos
- distance
> limit
)
13568 limit
= startpos
- distance
;
13569 limit_byte
= CHAR_TO_BYTE (limit
);
13572 nlines
= display_count_lines (startpos
, startpos_byte
,
13574 - (height
* 2 + 30),
13576 /* If we couldn't find the lines we wanted within
13577 line_number_display_limit_width chars per line,
13578 give up on line numbers for this window. */
13579 if (position
== limit_byte
&& limit
== startpos
- distance
)
13581 w
->base_line_pos
= w
->buffer
;
13582 w
->base_line_number
= Qnil
;
13586 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
13587 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
13590 /* Now count lines from the start pos to point. */
13591 nlines
= display_count_lines (startpos
, startpos_byte
,
13592 PT_BYTE
, PT
, &junk
);
13594 /* Record that we did display the line number. */
13595 line_number_displayed
= 1;
13597 /* Make the string to show. */
13598 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13599 return decode_mode_spec_buf
;
13602 char* p
= decode_mode_spec_buf
;
13603 int pad
= field_width
- 2;
13609 return decode_mode_spec_buf
;
13615 obj
= b
->mode_name
;
13619 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13625 int pos
= marker_position (w
->start
);
13626 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13628 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13630 if (pos
<= BUF_BEGV (b
))
13635 else if (pos
<= BUF_BEGV (b
))
13639 if (total
> 1000000)
13640 /* Do it differently for a large value, to avoid overflow. */
13641 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13643 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13644 /* We can't normally display a 3-digit number,
13645 so get us a 2-digit number that is close. */
13648 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13649 return decode_mode_spec_buf
;
13653 /* Display percentage of size above the bottom of the screen. */
13656 int toppos
= marker_position (w
->start
);
13657 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13658 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13660 if (botpos
>= BUF_ZV (b
))
13662 if (toppos
<= BUF_BEGV (b
))
13669 if (total
> 1000000)
13670 /* Do it differently for a large value, to avoid overflow. */
13671 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13673 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13674 /* We can't normally display a 3-digit number,
13675 so get us a 2-digit number that is close. */
13678 if (toppos
<= BUF_BEGV (b
))
13679 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13681 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13682 return decode_mode_spec_buf
;
13687 /* status of process */
13688 obj
= Fget_buffer_process (w
->buffer
);
13690 return "no process";
13691 #ifdef subprocesses
13692 obj
= Fsymbol_name (Fprocess_status (obj
));
13696 case 't': /* indicate TEXT or BINARY */
13697 #ifdef MODE_LINE_BINARY_TEXT
13698 return MODE_LINE_BINARY_TEXT (b
);
13704 /* coding-system (not including end-of-line format) */
13706 /* coding-system (including end-of-line type) */
13708 int eol_flag
= (c
== 'Z');
13709 char *p
= decode_mode_spec_buf
;
13711 if (! FRAME_WINDOW_P (f
))
13713 /* No need to mention EOL here--the terminal never needs
13714 to do EOL conversion. */
13715 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13716 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13718 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13721 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13722 #ifdef subprocesses
13723 obj
= Fget_buffer_process (Fcurrent_buffer ());
13724 if (PROCESSP (obj
))
13726 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13728 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13731 #endif /* subprocesses */
13734 return decode_mode_spec_buf
;
13739 return (char *) XSTRING (obj
)->data
;
13745 /* Count up to COUNT lines starting from START / START_BYTE.
13746 But don't go beyond LIMIT_BYTE.
13747 Return the number of lines thus found (always nonnegative).
13749 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13752 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13753 int start
, start_byte
, limit_byte
, count
;
13756 register unsigned char *cursor
;
13757 unsigned char *base
;
13759 register int ceiling
;
13760 register unsigned char *ceiling_addr
;
13761 int orig_count
= count
;
13763 /* If we are not in selective display mode,
13764 check only for newlines. */
13765 int selective_display
= (!NILP (current_buffer
->selective_display
)
13766 && !INTEGERP (current_buffer
->selective_display
));
13770 while (start_byte
< limit_byte
)
13772 ceiling
= BUFFER_CEILING_OF (start_byte
);
13773 ceiling
= min (limit_byte
- 1, ceiling
);
13774 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13775 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13778 if (selective_display
)
13779 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13782 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13785 if (cursor
!= ceiling_addr
)
13789 start_byte
+= cursor
- base
+ 1;
13790 *byte_pos_ptr
= start_byte
;
13794 if (++cursor
== ceiling_addr
)
13800 start_byte
+= cursor
- base
;
13805 while (start_byte
> limit_byte
)
13807 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13808 ceiling
= max (limit_byte
, ceiling
);
13809 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13810 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13813 if (selective_display
)
13814 while (--cursor
!= ceiling_addr
13815 && *cursor
!= '\n' && *cursor
!= 015)
13818 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13821 if (cursor
!= ceiling_addr
)
13825 start_byte
+= cursor
- base
+ 1;
13826 *byte_pos_ptr
= start_byte
;
13827 /* When scanning backwards, we should
13828 not count the newline posterior to which we stop. */
13829 return - orig_count
- 1;
13835 /* Here we add 1 to compensate for the last decrement
13836 of CURSOR, which took it past the valid range. */
13837 start_byte
+= cursor
- base
+ 1;
13841 *byte_pos_ptr
= limit_byte
;
13844 return - orig_count
+ count
;
13845 return orig_count
- count
;
13851 /***********************************************************************
13853 ***********************************************************************/
13855 /* Display a NUL-terminated string, starting with index START.
13857 If STRING is non-null, display that C string. Otherwise, the Lisp
13858 string LISP_STRING is displayed.
13860 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13861 FACE_STRING. Display STRING or LISP_STRING with the face at
13862 FACE_STRING_POS in FACE_STRING:
13864 Display the string in the environment given by IT, but use the
13865 standard display table, temporarily.
13867 FIELD_WIDTH is the minimum number of output glyphs to produce.
13868 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13869 with spaces. If STRING has more characters, more than FIELD_WIDTH
13870 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13872 PRECISION is the maximum number of characters to output from
13873 STRING. PRECISION < 0 means don't truncate the string.
13875 This is roughly equivalent to printf format specifiers:
13877 FIELD_WIDTH PRECISION PRINTF
13878 ----------------------------------------
13884 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13885 display them, and < 0 means obey the current buffer's value of
13886 enable_multibyte_characters.
13888 Value is the number of glyphs produced. */
13891 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13892 start
, it
, field_width
, precision
, max_x
, multibyte
)
13893 unsigned char *string
;
13894 Lisp_Object lisp_string
;
13895 Lisp_Object face_string
;
13896 int face_string_pos
;
13899 int field_width
, precision
, max_x
;
13902 int hpos_at_start
= it
->hpos
;
13903 int saved_face_id
= it
->face_id
;
13904 struct glyph_row
*row
= it
->glyph_row
;
13906 /* Initialize the iterator IT for iteration over STRING beginning
13907 with index START. We assume that IT may be modified here (which
13908 means that display_line has to do something when displaying a
13909 mini-buffer prompt, which it does). */
13910 reseat_to_string (it
, string
, lisp_string
, start
,
13911 precision
, field_width
, multibyte
);
13913 /* If displaying STRING, set up the face of the iterator
13914 from LISP_STRING, if that's given. */
13915 if (STRINGP (face_string
))
13921 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13922 0, it
->region_beg_charpos
,
13923 it
->region_end_charpos
,
13924 &endptr
, it
->base_face_id
, 0);
13925 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13926 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13929 /* Set max_x to the maximum allowed X position. Don't let it go
13930 beyond the right edge of the window. */
13932 max_x
= it
->last_visible_x
;
13934 max_x
= min (max_x
, it
->last_visible_x
);
13936 /* Skip over display elements that are not visible. because IT->w is
13938 if (it
->current_x
< it
->first_visible_x
)
13939 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
13940 MOVE_TO_POS
| MOVE_TO_X
);
13942 row
->ascent
= it
->max_ascent
;
13943 row
->height
= it
->max_ascent
+ it
->max_descent
;
13944 row
->phys_ascent
= it
->max_phys_ascent
;
13945 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13947 /* This condition is for the case that we are called with current_x
13948 past last_visible_x. */
13949 while (it
->current_x
< max_x
)
13951 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
13953 /* Get the next display element. */
13954 if (!get_next_display_element (it
))
13957 /* Produce glyphs. */
13958 x_before
= it
->current_x
;
13959 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13960 PRODUCE_GLYPHS (it
);
13962 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
13965 while (i
< nglyphs
)
13967 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13969 if (!it
->truncate_lines_p
13970 && x
+ glyph
->pixel_width
> max_x
)
13972 /* End of continued line or max_x reached. */
13973 if (CHAR_GLYPH_PADDING_P (*glyph
))
13975 /* A wide character is unbreakable. */
13976 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13977 it
->current_x
= x_before
;
13981 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13986 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
13988 /* Glyph is at least partially visible. */
13990 if (x
< it
->first_visible_x
)
13991 it
->glyph_row
->x
= x
- it
->first_visible_x
;
13995 /* Glyph is off the left margin of the display area.
13996 Should not happen. */
14000 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14001 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14002 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14003 row
->phys_height
= max (row
->phys_height
,
14004 it
->max_phys_ascent
+ it
->max_phys_descent
);
14005 x
+= glyph
->pixel_width
;
14009 /* Stop if max_x reached. */
14013 /* Stop at line ends. */
14014 if (ITERATOR_AT_END_OF_LINE_P (it
))
14016 it
->continuation_lines_width
= 0;
14020 set_iterator_to_next (it
, 1);
14022 /* Stop if truncating at the right edge. */
14023 if (it
->truncate_lines_p
14024 && it
->current_x
>= it
->last_visible_x
)
14026 /* Add truncation mark, but don't do it if the line is
14027 truncated at a padding space. */
14028 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14030 if (!FRAME_WINDOW_P (it
->f
))
14034 if (it
->current_x
> it
->last_visible_x
)
14036 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14037 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14039 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14041 row
->used
[TEXT_AREA
] = i
;
14042 produce_special_glyphs (it
, IT_TRUNCATION
);
14045 produce_special_glyphs (it
, IT_TRUNCATION
);
14047 it
->glyph_row
->truncated_on_right_p
= 1;
14053 /* Maybe insert a truncation at the left. */
14054 if (it
->first_visible_x
14055 && IT_CHARPOS (*it
) > 0)
14057 if (!FRAME_WINDOW_P (it
->f
))
14058 insert_left_trunc_glyphs (it
);
14059 it
->glyph_row
->truncated_on_left_p
= 1;
14062 it
->face_id
= saved_face_id
;
14064 /* Value is number of columns displayed. */
14065 return it
->hpos
- hpos_at_start
;
14070 /* This is like a combination of memq and assq. Return 1 if PROPVAL
14071 appears as an element of LIST or as the car of an element of LIST.
14072 If PROPVAL is a list, compare each element against LIST in that
14073 way, and return 1 if any element of PROPVAL is found in LIST.
14074 Otherwise return 0. This function cannot quit. */
14077 invisible_p (propval
, list
)
14078 register Lisp_Object propval
;
14081 register Lisp_Object tail
, proptail
;
14083 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14085 register Lisp_Object tem
;
14087 if (EQ (propval
, tem
))
14089 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14093 if (CONSP (propval
))
14095 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14097 Lisp_Object propelt
;
14098 propelt
= XCAR (proptail
);
14099 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14101 register Lisp_Object tem
;
14103 if (EQ (propelt
, tem
))
14105 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14115 /* Return 1 if PROPVAL appears as the car of an element of LIST and
14116 the cdr of that element is non-nil. If PROPVAL is a list, check
14117 each element of PROPVAL in that way, and the first time some
14118 element is found, return 1 if the cdr of that element is non-nil.
14119 Otherwise return 0. This function cannot quit. */
14122 invisible_ellipsis_p (propval
, list
)
14123 register Lisp_Object propval
;
14126 register Lisp_Object tail
, proptail
;
14128 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14130 register Lisp_Object tem
;
14132 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14133 return ! NILP (XCDR (tem
));
14136 if (CONSP (propval
))
14137 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14139 Lisp_Object propelt
;
14140 propelt
= XCAR (proptail
);
14141 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14143 register Lisp_Object tem
;
14145 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14146 return ! NILP (XCDR (tem
));
14155 /***********************************************************************
14157 ***********************************************************************/
14162 Vwith_echo_area_save_vector
= Qnil
;
14163 staticpro (&Vwith_echo_area_save_vector
);
14165 Vmessage_stack
= Qnil
;
14166 staticpro (&Vmessage_stack
);
14168 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14169 staticpro (&Qinhibit_redisplay
);
14172 defsubr (&Sdump_glyph_matrix
);
14173 defsubr (&Sdump_glyph_row
);
14174 defsubr (&Sdump_tool_bar_row
);
14175 defsubr (&Strace_redisplay_toggle
);
14176 defsubr (&Strace_to_stderr
);
14178 #ifdef HAVE_WINDOW_SYSTEM
14179 defsubr (&Stool_bar_lines_needed
);
14182 staticpro (&Qmenu_bar_update_hook
);
14183 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14185 staticpro (&Qoverriding_terminal_local_map
);
14186 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14188 staticpro (&Qoverriding_local_map
);
14189 Qoverriding_local_map
= intern ("overriding-local-map");
14191 staticpro (&Qwindow_scroll_functions
);
14192 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14194 staticpro (&Qredisplay_end_trigger_functions
);
14195 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14197 staticpro (&Qinhibit_point_motion_hooks
);
14198 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14200 QCdata
= intern (":data");
14201 staticpro (&QCdata
);
14202 Qdisplay
= intern ("display");
14203 staticpro (&Qdisplay
);
14204 Qspace_width
= intern ("space-width");
14205 staticpro (&Qspace_width
);
14206 Qraise
= intern ("raise");
14207 staticpro (&Qraise
);
14208 Qspace
= intern ("space");
14209 staticpro (&Qspace
);
14210 Qmargin
= intern ("margin");
14211 staticpro (&Qmargin
);
14212 Qleft_margin
= intern ("left-margin");
14213 staticpro (&Qleft_margin
);
14214 Qright_margin
= intern ("right-margin");
14215 staticpro (&Qright_margin
);
14216 Qalign_to
= intern ("align-to");
14217 staticpro (&Qalign_to
);
14218 QCalign_to
= intern (":align-to");
14219 staticpro (&QCalign_to
);
14220 Qrelative_width
= intern ("relative-width");
14221 staticpro (&Qrelative_width
);
14222 QCrelative_width
= intern (":relative-width");
14223 staticpro (&QCrelative_width
);
14224 QCrelative_height
= intern (":relative-height");
14225 staticpro (&QCrelative_height
);
14226 QCeval
= intern (":eval");
14227 staticpro (&QCeval
);
14228 Qwhen
= intern ("when");
14229 staticpro (&Qwhen
);
14230 QCfile
= intern (":file");
14231 staticpro (&QCfile
);
14232 Qfontified
= intern ("fontified");
14233 staticpro (&Qfontified
);
14234 Qfontification_functions
= intern ("fontification-functions");
14235 staticpro (&Qfontification_functions
);
14236 Qtrailing_whitespace
= intern ("trailing-whitespace");
14237 staticpro (&Qtrailing_whitespace
);
14238 Qimage
= intern ("image");
14239 staticpro (&Qimage
);
14240 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14241 staticpro (&Qmessage_truncate_lines
);
14242 Qgrow_only
= intern ("grow-only");
14243 staticpro (&Qgrow_only
);
14244 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14245 staticpro (&Qinhibit_menubar_update
);
14247 last_arrow_position
= Qnil
;
14248 last_arrow_string
= Qnil
;
14249 staticpro (&last_arrow_position
);
14250 staticpro (&last_arrow_string
);
14252 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14253 staticpro (&echo_buffer
[0]);
14254 staticpro (&echo_buffer
[1]);
14256 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14257 staticpro (&echo_area_buffer
[0]);
14258 staticpro (&echo_area_buffer
[1]);
14260 Vmessages_buffer_name
= build_string ("*Messages*");
14261 staticpro (&Vmessages_buffer_name
);
14263 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14264 "Non-nil means highlight trailing whitespace.\n\
14265 The face used for trailing whitespace is `trailing-whitespace'.");
14266 Vshow_trailing_whitespace
= Qnil
;
14268 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14269 "Non-nil means don't actually do any redisplay.\n\
14270 This is used for internal purposes.");
14271 Vinhibit_redisplay
= Qnil
;
14273 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14274 "String (or mode line construct) included (normally) in `mode-line-format'.");
14275 Vglobal_mode_string
= Qnil
;
14277 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14278 "Marker for where to display an arrow on top of the buffer text.\n\
14279 This must be the beginning of a line in order to work.\n\
14280 See also `overlay-arrow-string'.");
14281 Voverlay_arrow_position
= Qnil
;
14283 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14284 "String to display as an arrow. See also `overlay-arrow-position'.");
14285 Voverlay_arrow_string
= Qnil
;
14287 DEFVAR_INT ("scroll-step", &scroll_step
,
14288 "*The number of lines to try scrolling a window by when point moves out.\n\
14289 If that fails to bring point back on frame, point is centered instead.\n\
14290 If this is zero, point is always centered after it moves off frame.\n\
14291 If you want scrolling to always be a line at a time, you should set\n\
14292 `scroll-conservatively' to a large value rather than set this to 1.");
14294 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14295 "*Scroll up to this many lines, to bring point back on screen.\n\
14296 A value of zero means to scroll the text to center point vertically\n\
14298 scroll_conservatively
= 0;
14300 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14301 "*Number of lines of margin at the top and bottom of a window.\n\
14302 Recenter the window whenever point gets within this many lines\n\
14303 of the top or bottom of the window.");
14307 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
14310 DEFVAR_BOOL ("truncate-partial-width-windows",
14311 &truncate_partial_width_windows
,
14312 "*Non-nil means truncate lines in all windows less than full frame wide.");
14313 truncate_partial_width_windows
= 1;
14315 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14316 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
14317 Any other value means to use the appropriate face, `mode-line',\n\
14318 `header-line', or `menu' respectively.\n\
14320 This variable is deprecated; please change the above faces instead.");
14321 mode_line_inverse_video
= 1;
14323 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14324 "*Maximum buffer size for which line number should be displayed.\n\
14325 If the buffer is bigger than this, the line number does not appear\n\
14326 in the mode line. A value of nil means no limit.");
14327 Vline_number_display_limit
= Qnil
;
14329 DEFVAR_INT ("line-number-display-limit-width",
14330 &line_number_display_limit_width
,
14331 "*Maximum line width (in characters) for line number display.\n\
14332 If the average length of the lines near point is bigger than this, then the\n\
14333 line number may be omitted from the mode line.");
14334 line_number_display_limit_width
= 200;
14336 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14337 "*Non-nil means highlight region even in nonselected windows.");
14338 highlight_nonselected_windows
= 0;
14340 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14341 "Non-nil if more than one frame is visible on this display.\n\
14342 Minibuffer-only frames don't count, but iconified frames do.\n\
14343 This variable is not guaranteed to be accurate except while processing\n\
14344 `frame-title-format' and `icon-title-format'.");
14346 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14347 "Template for displaying the title bar of visible frames.\n\
14348 \(Assuming the window manager supports this feature.)\n\
14349 This variable has the same structure as `mode-line-format' (which see),\n\
14350 and is used only on frames for which no explicit name has been set\n\
14351 \(see `modify-frame-parameters').");
14352 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14353 "Template for displaying the title bar of an iconified frame.\n\
14354 \(Assuming the window manager supports this feature.)\n\
14355 This variable has the same structure as `mode-line-format' (which see),\n\
14356 and is used only on frames for which no explicit name has been set\n\
14357 \(see `modify-frame-parameters').");
14359 = Vframe_title_format
14360 = Fcons (intern ("multiple-frames"),
14361 Fcons (build_string ("%b"),
14362 Fcons (Fcons (build_string (""),
14363 Fcons (intern ("invocation-name"),
14364 Fcons (build_string ("@"),
14365 Fcons (intern ("system-name"),
14369 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14370 "Maximum number of lines to keep in the message log buffer.\n\
14371 If nil, disable message logging. If t, log messages but don't truncate\n\
14372 the buffer when it becomes large.");
14373 XSETFASTINT (Vmessage_log_max
, 50);
14375 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14376 "Functions called before redisplay, if window sizes have changed.\n\
14377 The value should be a list of functions that take one argument.\n\
14378 Just before redisplay, for each frame, if any of its windows have changed\n\
14379 size since the last redisplay, or have been split or deleted,\n\
14380 all the functions in the list are called, with the frame as argument.");
14381 Vwindow_size_change_functions
= Qnil
;
14383 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14384 "List of Functions to call before redisplaying a window with scrolling.\n\
14385 Each function is called with two arguments, the window\n\
14386 and its new display-start position. Note that the value of `window-end'\n\
14387 is not valid when these functions are called.");
14388 Vwindow_scroll_functions
= Qnil
;
14390 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
14391 "*Non-nil means automatically resize tool-bars.\n\
14392 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14393 It decreases a tool-bar's height when it would display blank lines\n\
14395 auto_resize_tool_bars_p
= 1;
14397 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14398 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14399 auto_raise_tool_bar_buttons_p
= 1;
14401 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
14402 "*Margin around tool-bar buttons in pixels.\n\
14403 If an integer, use that for both horizontal and vertical margins.\n\
14404 Otherwise, value should be a pair of integers `(HORZ : VERT)' with\n\
14405 HORZ specifying the horizontal margin, and VERT specifying the\n\
14406 vertical margin.");
14407 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
14409 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14410 "Relief thickness of tool-bar buttons.");
14411 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
14413 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14414 "List of functions to call to fontify regions of text.\n\
14415 Each function is called with one argument POS. Functions must\n\
14416 fontify a region starting at POS in the current buffer, and give\n\
14417 fontified regions the property `fontified'.\n\
14418 This variable automatically becomes buffer-local when set.");
14419 Vfontification_functions
= Qnil
;
14420 Fmake_variable_buffer_local (Qfontification_functions
);
14422 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14423 &unibyte_display_via_language_environment
,
14424 "*Non-nil means display unibyte text according to language environment.\n\
14425 Specifically this means that unibyte non-ASCII characters\n\
14426 are displayed by converting them to the equivalent multibyte characters\n\
14427 according to the current language environment. As a result, they are\n\
14428 displayed according to the current fontset.");
14429 unibyte_display_via_language_environment
= 0;
14431 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14432 "*Maximum height for resizing mini-windows.\n\
14433 If a float, it specifies a fraction of the mini-window frame's height.\n\
14434 If an integer, it specifies a number of lines.");
14435 Vmax_mini_window_height
= make_float (0.25);
14437 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14438 "*How to resize mini-windows.\n\
14439 A value of nil means don't automatically resize mini-windows.\n\
14440 A value of t means resize them to fit the text displayed in them.\n\
14441 A value of `grow-only', the default, means let mini-windows grow\n\
14442 only, until their display becomes empty, at which point the windows\n\
14443 go back to their normal size.");
14444 Vresize_mini_windows
= Qgrow_only
;
14446 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14447 &cursor_in_non_selected_windows
,
14448 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14449 Nil means don't display a cursor there.");
14450 cursor_in_non_selected_windows
= 1;
14452 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14453 "*Non-nil means scroll the display automatically to make point visible.");
14454 automatic_hscrolling_p
= 1;
14456 DEFVAR_LISP ("image-types", &Vimage_types
,
14457 "List of supported image types.\n\
14458 Each element of the list is a symbol for a supported image type.");
14459 Vimage_types
= Qnil
;
14461 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14462 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14463 Bind this around calls to `message' to let it take effect.");
14464 message_truncate_lines
= 0;
14466 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14467 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14468 Can be used to update submenus whose contents should vary.");
14469 Vmenu_bar_update_hook
= Qnil
;
14471 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
14472 "Non-nil means don't update menu bars. Internal use only.");
14473 inhibit_menubar_update
= 0;
14477 /* Initialize this module when Emacs starts. */
14482 Lisp_Object root_window
;
14483 struct window
*mini_w
;
14485 current_header_line_height
= current_mode_line_height
= -1;
14487 CHARPOS (this_line_start_pos
) = 0;
14489 mini_w
= XWINDOW (minibuf_window
);
14490 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14492 if (!noninteractive
)
14494 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14497 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
14498 set_window_height (root_window
,
14499 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14501 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
14502 set_window_height (minibuf_window
, 1, 0);
14504 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
14505 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
14507 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14508 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14509 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14511 /* The default ellipsis glyphs `...'. */
14512 for (i
= 0; i
< 3; ++i
)
14513 XSETFASTINT (default_invis_vector
[i
], '.');
14516 #ifdef HAVE_WINDOW_SYSTEM
14518 /* Allocate the buffer for frame titles. */
14520 frame_title_buf
= (char *) xmalloc (size
);
14521 frame_title_buf_end
= frame_title_buf
+ size
;
14522 frame_title_ptr
= NULL
;
14524 #endif /* HAVE_WINDOW_SYSTEM */
14526 help_echo_showing_p
= 0;