1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001, 2002
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 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 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 displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 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 INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
204 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
205 extern int pending_menu_activation
;
208 extern int interrupt_input
;
209 extern int command_loop_level
;
211 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Qface
;
215 extern Lisp_Object Voverriding_local_map
;
216 extern Lisp_Object Voverriding_local_map_menu_flag
;
217 extern Lisp_Object Qmenu_item
;
219 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
220 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
221 Lisp_Object Qredisplay_end_trigger_functions
;
222 Lisp_Object Qinhibit_point_motion_hooks
;
223 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
, QCpropertize
;
224 Lisp_Object Qfontified
;
225 Lisp_Object Qgrow_only
;
226 Lisp_Object Qinhibit_eval_during_redisplay
;
227 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
229 /* Functions called to fontify regions of text. */
231 Lisp_Object Vfontification_functions
;
232 Lisp_Object Qfontification_functions
;
234 /* Non-zero means draw tool bar buttons raised when the mouse moves
237 int auto_raise_tool_bar_buttons_p
;
239 /* Margin around tool bar buttons in pixels. */
241 Lisp_Object Vtool_bar_button_margin
;
243 /* Thickness of shadow to draw around tool bar buttons. */
245 EMACS_INT tool_bar_button_relief
;
247 /* Non-zero means automatically resize tool-bars so that all tool-bar
248 items are visible, and no blank lines remain. */
250 int auto_resize_tool_bars_p
;
252 /* Non-nil means don't actually do any redisplay. */
254 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
256 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
258 int inhibit_eval_during_redisplay
;
260 /* Names of text properties relevant for redisplay. */
262 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
263 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
265 /* Symbols used in text property values. */
267 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
268 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
270 extern Lisp_Object Qheight
;
272 /* Non-nil means highlight trailing whitespace. */
274 Lisp_Object Vshow_trailing_whitespace
;
276 /* Name of the face used to highlight trailing whitespace. */
278 Lisp_Object Qtrailing_whitespace
;
280 /* The symbol `image' which is the car of the lists used to represent
285 /* Non-zero means print newline to stdout before next mini-buffer
288 int noninteractive_need_newline
;
290 /* Non-zero means print newline to message log before next message. */
292 static int message_log_need_newline
;
294 /* Three markers that message_dolog uses.
295 It could allocate them itself, but that causes trouble
296 in handling memory-full errors. */
297 static Lisp_Object message_dolog_marker1
;
298 static Lisp_Object message_dolog_marker2
;
299 static Lisp_Object message_dolog_marker3
;
301 /* The buffer position of the first character appearing entirely or
302 partially on the line of the selected window which contains the
303 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
304 redisplay optimization in redisplay_internal. */
306 static struct text_pos this_line_start_pos
;
308 /* Number of characters past the end of the line above, including the
309 terminating newline. */
311 static struct text_pos this_line_end_pos
;
313 /* The vertical positions and the height of this line. */
315 static int this_line_vpos
;
316 static int this_line_y
;
317 static int this_line_pixel_height
;
319 /* X position at which this display line starts. Usually zero;
320 negative if first character is partially visible. */
322 static int this_line_start_x
;
324 /* Buffer that this_line_.* variables are referring to. */
326 static struct buffer
*this_line_buffer
;
328 /* Nonzero means truncate lines in all windows less wide than the
331 int truncate_partial_width_windows
;
333 /* A flag to control how to display unibyte 8-bit character. */
335 int unibyte_display_via_language_environment
;
337 /* Nonzero means we have more than one non-mini-buffer-only frame.
338 Not guaranteed to be accurate except while parsing
339 frame-title-format. */
343 Lisp_Object Vglobal_mode_string
;
345 /* Marker for where to display an arrow on top of the buffer text. */
347 Lisp_Object Voverlay_arrow_position
;
349 /* String to display for the arrow. Only used on terminal frames. */
351 Lisp_Object Voverlay_arrow_string
;
353 /* Values of those variables at last redisplay. However, if
354 Voverlay_arrow_position is a marker, last_arrow_position is its
355 numerical position. */
357 static Lisp_Object last_arrow_position
, last_arrow_string
;
359 /* Like mode-line-format, but for the title bar on a visible frame. */
361 Lisp_Object Vframe_title_format
;
363 /* Like mode-line-format, but for the title bar on an iconified frame. */
365 Lisp_Object Vicon_title_format
;
367 /* List of functions to call when a window's size changes. These
368 functions get one arg, a frame on which one or more windows' sizes
371 static Lisp_Object Vwindow_size_change_functions
;
373 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
375 /* Nonzero if overlay arrow has been displayed once in this window. */
377 static int overlay_arrow_seen
;
379 /* Nonzero means highlight the region even in nonselected windows. */
381 int highlight_nonselected_windows
;
383 /* If cursor motion alone moves point off frame, try scrolling this
384 many lines up or down if that will bring it back. */
386 static EMACS_INT scroll_step
;
388 /* Nonzero means scroll just far enough to bring point back on the
389 screen, when appropriate. */
391 static EMACS_INT scroll_conservatively
;
393 /* Recenter the window whenever point gets within this many lines of
394 the top or bottom of the window. This value is translated into a
395 pixel value by multiplying it with CANON_Y_UNIT, which means that
396 there is really a fixed pixel height scroll margin. */
398 EMACS_INT scroll_margin
;
400 /* Number of windows showing the buffer of the selected window (or
401 another buffer with the same base buffer). keyboard.c refers to
406 /* Vector containing glyphs for an ellipsis `...'. */
408 static Lisp_Object default_invis_vector
[3];
410 /* Zero means display the mode-line/header-line/menu-bar in the default face
411 (this slightly odd definition is for compatibility with previous versions
412 of emacs), non-zero means display them using their respective faces.
414 This variable is deprecated. */
416 int mode_line_inverse_video
;
418 /* Prompt to display in front of the mini-buffer contents. */
420 Lisp_Object minibuf_prompt
;
422 /* Width of current mini-buffer prompt. Only set after display_line
423 of the line that contains the prompt. */
425 int minibuf_prompt_width
;
426 int minibuf_prompt_pixel_width
;
428 /* This is the window where the echo area message was displayed. It
429 is always a mini-buffer window, but it may not be the same window
430 currently active as a mini-buffer. */
432 Lisp_Object echo_area_window
;
434 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
435 pushes the current message and the value of
436 message_enable_multibyte on the stack, the function restore_message
437 pops the stack and displays MESSAGE again. */
439 Lisp_Object Vmessage_stack
;
441 /* Nonzero means multibyte characters were enabled when the echo area
442 message was specified. */
444 int message_enable_multibyte
;
446 /* Nonzero if we should redraw the mode lines on the next redisplay. */
448 int update_mode_lines
;
450 /* Nonzero if window sizes or contents have changed since last
451 redisplay that finished. */
453 int windows_or_buffers_changed
;
455 /* Nonzero after display_mode_line if %l was used and it displayed a
458 int line_number_displayed
;
460 /* Maximum buffer size for which to display line numbers. */
462 Lisp_Object Vline_number_display_limit
;
464 /* Line width to consider when repositioning for line number display. */
466 static EMACS_INT line_number_display_limit_width
;
468 /* Number of lines to keep in the message log buffer. t means
469 infinite. nil means don't log at all. */
471 Lisp_Object Vmessage_log_max
;
473 /* The name of the *Messages* buffer, a string. */
475 static Lisp_Object Vmessages_buffer_name
;
477 /* Current, index 0, and last displayed echo area message. Either
478 buffers from echo_buffers, or nil to indicate no message. */
480 Lisp_Object echo_area_buffer
[2];
482 /* The buffers referenced from echo_area_buffer. */
484 static Lisp_Object echo_buffer
[2];
486 /* A vector saved used in with_area_buffer to reduce consing. */
488 static Lisp_Object Vwith_echo_area_save_vector
;
490 /* Non-zero means display_echo_area should display the last echo area
491 message again. Set by redisplay_preserve_echo_area. */
493 static int display_last_displayed_message_p
;
495 /* Nonzero if echo area is being used by print; zero if being used by
498 int message_buf_print
;
500 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
502 Lisp_Object Qinhibit_menubar_update
;
503 int inhibit_menubar_update
;
505 /* Maximum height for resizing mini-windows. Either a float
506 specifying a fraction of the available height, or an integer
507 specifying a number of lines. */
509 Lisp_Object Vmax_mini_window_height
;
511 /* Non-zero means messages should be displayed with truncated
512 lines instead of being continued. */
514 int message_truncate_lines
;
515 Lisp_Object Qmessage_truncate_lines
;
517 /* Set to 1 in clear_message to make redisplay_internal aware
518 of an emptied echo area. */
520 static int message_cleared_p
;
522 /* Non-zero means we want a hollow cursor in windows that are not
523 selected. Zero means there's no cursor in such windows. */
525 int cursor_in_non_selected_windows
;
526 Lisp_Object Qcursor_in_non_selected_windows
;
528 /* A scratch glyph row with contents used for generating truncation
529 glyphs. Also used in direct_output_for_insert. */
531 #define MAX_SCRATCH_GLYPHS 100
532 struct glyph_row scratch_glyph_row
;
533 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
535 /* Ascent and height of the last line processed by move_it_to. */
537 static int last_max_ascent
, last_height
;
539 /* Non-zero if there's a help-echo in the echo area. */
541 int help_echo_showing_p
;
543 /* If >= 0, computed, exact values of mode-line and header-line height
544 to use in the macros CURRENT_MODE_LINE_HEIGHT and
545 CURRENT_HEADER_LINE_HEIGHT. */
547 int current_mode_line_height
, current_header_line_height
;
549 /* The maximum distance to look ahead for text properties. Values
550 that are too small let us call compute_char_face and similar
551 functions too often which is expensive. Values that are too large
552 let us call compute_char_face and alike too often because we
553 might not be interested in text properties that far away. */
555 #define TEXT_PROP_DISTANCE_LIMIT 100
559 /* Variables to turn off display optimizations from Lisp. */
561 int inhibit_try_window_id
, inhibit_try_window_reusing
;
562 int inhibit_try_cursor_movement
;
564 /* Non-zero means print traces of redisplay if compiled with
567 int trace_redisplay_p
;
569 #endif /* GLYPH_DEBUG */
571 #ifdef DEBUG_TRACE_MOVE
572 /* Non-zero means trace with TRACE_MOVE to stderr. */
575 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
577 #define TRACE_MOVE(x) (void) 0
580 /* Non-zero means automatically scroll windows horizontally to make
583 int automatic_hscrolling_p
;
585 /* How close to the margin can point get before the window is scrolled
587 EMACS_INT hscroll_margin
;
589 /* How much to scroll horizontally when point is inside the above margin. */
590 Lisp_Object Vhscroll_step
;
592 /* A list of symbols, one for each supported image type. */
594 Lisp_Object Vimage_types
;
596 /* The variable `resize-mini-windows'. If nil, don't resize
597 mini-windows. If t, always resize them to fit the text they
598 display. If `grow-only', let mini-windows grow only until they
601 Lisp_Object Vresize_mini_windows
;
603 /* Buffer being redisplayed -- for redisplay_window_error. */
605 struct buffer
*displayed_buffer
;
607 /* Value returned from text property handlers (see below). */
612 HANDLED_RECOMPUTE_PROPS
,
613 HANDLED_OVERLAY_STRING_CONSUMED
,
617 /* A description of text properties that redisplay is interested
622 /* The name of the property. */
625 /* A unique index for the property. */
628 /* A handler function called to set up iterator IT from the property
629 at IT's current position. Value is used to steer handle_stop. */
630 enum prop_handled (*handler
) P_ ((struct it
*it
));
633 static enum prop_handled handle_face_prop
P_ ((struct it
*));
634 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
635 static enum prop_handled handle_display_prop
P_ ((struct it
*));
636 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
637 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
638 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
640 /* Properties handled by iterators. */
642 static struct props it_props
[] =
644 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
645 /* Handle `face' before `display' because some sub-properties of
646 `display' need to know the face. */
647 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
648 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
649 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
650 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
654 /* Value is the position described by X. If X is a marker, value is
655 the marker_position of X. Otherwise, value is X. */
657 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
659 /* Enumeration returned by some move_it_.* functions internally. */
663 /* Not used. Undefined value. */
666 /* Move ended at the requested buffer position or ZV. */
667 MOVE_POS_MATCH_OR_ZV
,
669 /* Move ended at the requested X pixel position. */
672 /* Move within a line ended at the end of a line that must be
676 /* Move within a line ended at the end of a line that would
677 be displayed truncated. */
680 /* Move within a line ended at a line end. */
686 /* Function prototypes. */
688 static void setup_for_ellipsis
P_ ((struct it
*));
689 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
690 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
691 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
692 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
693 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
694 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
697 static int invisible_text_between_p
P_ ((struct it
*, int, int));
700 static int next_element_from_ellipsis
P_ ((struct it
*));
701 static void pint2str
P_ ((char *, int, int));
702 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
704 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
705 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
706 static void store_frame_title_char
P_ ((char));
707 static int store_frame_title
P_ ((unsigned char *, int, int));
708 static void x_consider_frame_title
P_ ((Lisp_Object
));
709 static void handle_stop
P_ ((struct it
*));
710 static int tool_bar_lines_needed
P_ ((struct frame
*));
711 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
712 static void ensure_echo_area_buffers
P_ ((void));
713 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
714 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
715 static int with_echo_area_buffer
P_ ((struct window
*, int,
716 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
717 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
718 static void clear_garbaged_frames
P_ ((void));
719 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
720 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
721 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
722 static int display_echo_area
P_ ((struct window
*));
723 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
724 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
725 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
726 static int string_char_and_length
P_ ((unsigned char *, int, int *));
727 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
729 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
730 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
731 static void insert_left_trunc_glyphs
P_ ((struct it
*));
732 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
733 static void extend_face_to_end_of_line
P_ ((struct it
*));
734 static int append_space
P_ ((struct it
*, int));
735 static int make_cursor_line_fully_visible
P_ ((struct window
*));
736 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int));
737 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
738 static int trailing_whitespace_p
P_ ((int));
739 static int message_log_check_duplicate
P_ ((int, int, int, int));
740 static void push_it
P_ ((struct it
*));
741 static void pop_it
P_ ((struct it
*));
742 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
743 static void redisplay_internal
P_ ((int));
744 static int echo_area_display
P_ ((int));
745 static void redisplay_windows
P_ ((Lisp_Object
));
746 static void redisplay_window
P_ ((Lisp_Object
, int));
747 static Lisp_Object
redisplay_window_error ();
748 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
749 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
750 static void update_menu_bar
P_ ((struct frame
*, int));
751 static int try_window_reusing_current_matrix
P_ ((struct window
*));
752 static int try_window_id
P_ ((struct window
*));
753 static int display_line
P_ ((struct it
*));
754 static int display_mode_lines
P_ ((struct window
*));
755 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
756 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
));
757 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
758 static void display_menu_bar
P_ ((struct window
*));
759 static int display_count_lines
P_ ((int, int, int, int, int *));
760 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
761 int, int, struct it
*, int, int, int, int));
762 static void compute_line_metrics
P_ ((struct it
*));
763 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
764 static int get_overlay_strings
P_ ((struct it
*, int));
765 static void next_overlay_string
P_ ((struct it
*));
766 static void reseat
P_ ((struct it
*, struct text_pos
, int));
767 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
768 static void back_to_previous_visible_line_start
P_ ((struct it
*));
769 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
770 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
771 static int next_element_from_display_vector
P_ ((struct it
*));
772 static int next_element_from_string
P_ ((struct it
*));
773 static int next_element_from_c_string
P_ ((struct it
*));
774 static int next_element_from_buffer
P_ ((struct it
*));
775 static int next_element_from_composition
P_ ((struct it
*));
776 static int next_element_from_image
P_ ((struct it
*));
777 static int next_element_from_stretch
P_ ((struct it
*));
778 static void load_overlay_strings
P_ ((struct it
*, int));
779 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
780 struct display_pos
*));
781 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
782 Lisp_Object
, int, int, int, int));
783 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
785 void move_it_vertically_backward
P_ ((struct it
*, int));
786 static void init_to_row_start
P_ ((struct it
*, struct window
*,
787 struct glyph_row
*));
788 static int init_to_row_end
P_ ((struct it
*, struct window
*,
789 struct glyph_row
*));
790 static void back_to_previous_line_start
P_ ((struct it
*));
791 static int forward_to_next_line_start
P_ ((struct it
*, int *));
792 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
794 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
795 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
796 static int number_of_chars
P_ ((unsigned char *, int));
797 static void compute_stop_pos
P_ ((struct it
*));
798 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
800 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
801 static int next_overlay_change
P_ ((int));
802 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
803 Lisp_Object
, struct text_pos
*,
805 static int underlying_face_id
P_ ((struct it
*));
806 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
809 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
810 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
812 #ifdef HAVE_WINDOW_SYSTEM
814 static void update_tool_bar
P_ ((struct frame
*, int));
815 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
816 static int redisplay_tool_bar
P_ ((struct frame
*));
817 static void display_tool_bar_line
P_ ((struct it
*));
819 #endif /* HAVE_WINDOW_SYSTEM */
822 /***********************************************************************
823 Window display dimensions
824 ***********************************************************************/
826 /* Return the window-relative maximum y + 1 for glyph rows displaying
827 text in window W. This is the height of W minus the height of a
828 mode line, if any. */
831 window_text_bottom_y (w
)
834 struct frame
*f
= XFRAME (w
->frame
);
835 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
837 if (WINDOW_WANTS_MODELINE_P (w
))
838 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
843 /* Return the pixel width of display area AREA of window W. AREA < 0
844 means return the total width of W, not including fringes to
845 the left and right of the window. */
848 window_box_width (w
, area
)
852 struct frame
*f
= XFRAME (w
->frame
);
853 int width
= XFASTINT (w
->width
);
855 if (!w
->pseudo_window_p
)
857 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
859 if (area
== TEXT_AREA
)
861 if (INTEGERP (w
->left_margin_width
))
862 width
-= XFASTINT (w
->left_margin_width
);
863 if (INTEGERP (w
->right_margin_width
))
864 width
-= XFASTINT (w
->right_margin_width
);
866 else if (area
== LEFT_MARGIN_AREA
)
867 width
= (INTEGERP (w
->left_margin_width
)
868 ? XFASTINT (w
->left_margin_width
) : 0);
869 else if (area
== RIGHT_MARGIN_AREA
)
870 width
= (INTEGERP (w
->right_margin_width
)
871 ? XFASTINT (w
->right_margin_width
) : 0);
874 return width
* CANON_X_UNIT (f
);
878 /* Return the pixel height of the display area of window W, not
879 including mode lines of W, if any. */
882 window_box_height (w
)
885 struct frame
*f
= XFRAME (w
->frame
);
886 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
888 xassert (height
>= 0);
890 /* Note: the code below that determines the mode-line/header-line
891 height is essentially the same as that contained in the macro
892 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
893 the appropriate glyph row has its `mode_line_p' flag set,
894 and if it doesn't, uses estimate_mode_line_height instead. */
896 if (WINDOW_WANTS_MODELINE_P (w
))
898 struct glyph_row
*ml_row
899 = (w
->current_matrix
&& w
->current_matrix
->rows
900 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
902 if (ml_row
&& ml_row
->mode_line_p
)
903 height
-= ml_row
->height
;
905 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
908 if (WINDOW_WANTS_HEADER_LINE_P (w
))
910 struct glyph_row
*hl_row
911 = (w
->current_matrix
&& w
->current_matrix
->rows
912 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
914 if (hl_row
&& hl_row
->mode_line_p
)
915 height
-= hl_row
->height
;
917 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
920 /* With a very small font and a mode-line that's taller than
921 default, we might end up with a negative height. */
922 return max (0, height
);
926 /* Return the frame-relative coordinate of the left edge of display
927 area AREA of window W. AREA < 0 means return the left edge of the
928 whole window, to the right of the left fringe of W. */
931 window_box_left (w
, area
)
935 struct frame
*f
= XFRAME (w
->frame
);
936 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
938 if (!w
->pseudo_window_p
)
940 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
941 + FRAME_LEFT_FRINGE_WIDTH (f
));
943 if (area
== TEXT_AREA
)
944 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
945 else if (area
== RIGHT_MARGIN_AREA
)
946 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
947 + window_box_width (w
, TEXT_AREA
));
954 /* Return the frame-relative coordinate of the right edge of display
955 area AREA of window W. AREA < 0 means return the left edge of the
956 whole window, to the left of the right fringe of W. */
959 window_box_right (w
, area
)
963 return window_box_left (w
, area
) + window_box_width (w
, area
);
967 /* Get the bounding box of the display area AREA of window W, without
968 mode lines, in frame-relative coordinates. AREA < 0 means the
969 whole window, not including the left and right fringes of
970 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
971 coordinates of the upper-left corner of the box. Return in
972 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
975 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
978 int *box_x
, *box_y
, *box_width
, *box_height
;
980 struct frame
*f
= XFRAME (w
->frame
);
982 *box_width
= window_box_width (w
, area
);
983 *box_height
= window_box_height (w
);
984 *box_x
= window_box_left (w
, area
);
985 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
986 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
987 if (WINDOW_WANTS_HEADER_LINE_P (w
))
988 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
992 /* Get the bounding box of the display area AREA of window W, without
993 mode lines. AREA < 0 means the whole window, not including the
994 left and right fringe of the window. Return in *TOP_LEFT_X
995 and TOP_LEFT_Y the frame-relative pixel coordinates of the
996 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
997 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1001 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1002 bottom_right_x
, bottom_right_y
)
1005 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1007 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1009 *bottom_right_x
+= *top_left_x
;
1010 *bottom_right_y
+= *top_left_y
;
1015 /***********************************************************************
1017 ***********************************************************************/
1019 /* Return the bottom y-position of the line the iterator IT is in.
1020 This can modify IT's settings. */
1026 int line_height
= it
->max_ascent
+ it
->max_descent
;
1027 int line_top_y
= it
->current_y
;
1029 if (line_height
== 0)
1032 line_height
= last_height
;
1033 else if (IT_CHARPOS (*it
) < ZV
)
1035 move_it_by_lines (it
, 1, 1);
1036 line_height
= (it
->max_ascent
|| it
->max_descent
1037 ? it
->max_ascent
+ it
->max_descent
1042 struct glyph_row
*row
= it
->glyph_row
;
1044 /* Use the default character height. */
1045 it
->glyph_row
= NULL
;
1046 it
->what
= IT_CHARACTER
;
1049 PRODUCE_GLYPHS (it
);
1050 line_height
= it
->ascent
+ it
->descent
;
1051 it
->glyph_row
= row
;
1055 return line_top_y
+ line_height
;
1059 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1060 1 if POS is visible and the line containing POS is fully visible.
1061 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1062 and header-lines heights. */
1065 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1067 int charpos
, *fully
, exact_mode_line_heights_p
;
1070 struct text_pos top
;
1072 struct buffer
*old_buffer
= NULL
;
1074 if (XBUFFER (w
->buffer
) != current_buffer
)
1076 old_buffer
= current_buffer
;
1077 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1080 *fully
= visible_p
= 0;
1081 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1083 /* Compute exact mode line heights, if requested. */
1084 if (exact_mode_line_heights_p
)
1086 if (WINDOW_WANTS_MODELINE_P (w
))
1087 current_mode_line_height
1088 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1089 current_buffer
->mode_line_format
);
1091 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1092 current_header_line_height
1093 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1094 current_buffer
->header_line_format
);
1097 start_display (&it
, w
, top
);
1098 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1099 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1101 /* Note that we may overshoot because of invisible text. */
1102 if (IT_CHARPOS (it
) >= charpos
)
1104 int top_y
= it
.current_y
;
1105 int bottom_y
= line_bottom_y (&it
);
1106 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1108 if (top_y
< window_top_y
)
1109 visible_p
= bottom_y
> window_top_y
;
1110 else if (top_y
< it
.last_visible_y
)
1113 *fully
= bottom_y
<= it
.last_visible_y
;
1116 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1118 move_it_by_lines (&it
, 1, 0);
1119 if (charpos
< IT_CHARPOS (it
))
1127 set_buffer_internal_1 (old_buffer
);
1129 current_header_line_height
= current_mode_line_height
= -1;
1134 /* Return the next character from STR which is MAXLEN bytes long.
1135 Return in *LEN the length of the character. This is like
1136 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1137 we find one, we return a `?', but with the length of the invalid
1141 string_char_and_length (str
, maxlen
, len
)
1147 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1148 if (!CHAR_VALID_P (c
, 1))
1149 /* We may not change the length here because other places in Emacs
1150 don't use this function, i.e. they silently accept invalid
1159 /* Given a position POS containing a valid character and byte position
1160 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1162 static struct text_pos
1163 string_pos_nchars_ahead (pos
, string
, nchars
)
1164 struct text_pos pos
;
1168 xassert (STRINGP (string
) && nchars
>= 0);
1170 if (STRING_MULTIBYTE (string
))
1172 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1173 unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1178 string_char_and_length (p
, rest
, &len
);
1179 p
+= len
, rest
-= len
;
1180 xassert (rest
>= 0);
1182 BYTEPOS (pos
) += len
;
1186 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1192 /* Value is the text position, i.e. character and byte position,
1193 for character position CHARPOS in STRING. */
1195 static INLINE
struct text_pos
1196 string_pos (charpos
, string
)
1200 struct text_pos pos
;
1201 xassert (STRINGP (string
));
1202 xassert (charpos
>= 0);
1203 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1208 /* Value is a text position, i.e. character and byte position, for
1209 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1210 means recognize multibyte characters. */
1212 static struct text_pos
1213 c_string_pos (charpos
, s
, multibyte_p
)
1218 struct text_pos pos
;
1220 xassert (s
!= NULL
);
1221 xassert (charpos
>= 0);
1225 int rest
= strlen (s
), len
;
1227 SET_TEXT_POS (pos
, 0, 0);
1230 string_char_and_length (s
, rest
, &len
);
1231 s
+= len
, rest
-= len
;
1232 xassert (rest
>= 0);
1234 BYTEPOS (pos
) += len
;
1238 SET_TEXT_POS (pos
, charpos
, charpos
);
1244 /* Value is the number of characters in C string S. MULTIBYTE_P
1245 non-zero means recognize multibyte characters. */
1248 number_of_chars (s
, multibyte_p
)
1256 int rest
= strlen (s
), len
;
1257 unsigned char *p
= (unsigned char *) s
;
1259 for (nchars
= 0; rest
> 0; ++nchars
)
1261 string_char_and_length (p
, rest
, &len
);
1262 rest
-= len
, p
+= len
;
1266 nchars
= strlen (s
);
1272 /* Compute byte position NEWPOS->bytepos corresponding to
1273 NEWPOS->charpos. POS is a known position in string STRING.
1274 NEWPOS->charpos must be >= POS.charpos. */
1277 compute_string_pos (newpos
, pos
, string
)
1278 struct text_pos
*newpos
, pos
;
1281 xassert (STRINGP (string
));
1282 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1284 if (STRING_MULTIBYTE (string
))
1285 *newpos
= string_pos_nchars_ahead (pos
, string
,
1286 CHARPOS (*newpos
) - CHARPOS (pos
));
1288 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1293 /***********************************************************************
1294 Lisp form evaluation
1295 ***********************************************************************/
1297 /* Error handler for safe_eval and safe_call. */
1300 safe_eval_handler (arg
)
1303 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1308 /* Evaluate SEXPR and return the result, or nil if something went
1309 wrong. Prevent redisplay during the evaluation. */
1317 if (inhibit_eval_during_redisplay
)
1321 int count
= BINDING_STACK_SIZE ();
1322 struct gcpro gcpro1
;
1325 specbind (Qinhibit_redisplay
, Qt
);
1326 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
1329 val
= unbind_to (count
, val
);
1336 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1337 Return the result, or nil if something went wrong. Prevent
1338 redisplay during the evaluation. */
1341 safe_call (nargs
, args
)
1347 if (inhibit_eval_during_redisplay
)
1351 int count
= BINDING_STACK_SIZE ();
1352 struct gcpro gcpro1
;
1355 gcpro1
.nvars
= nargs
;
1356 specbind (Qinhibit_redisplay
, Qt
);
1357 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1360 val
= unbind_to (count
, val
);
1367 /* Call function FN with one argument ARG.
1368 Return the result, or nil if something went wrong. */
1371 safe_call1 (fn
, arg
)
1372 Lisp_Object fn
, arg
;
1374 Lisp_Object args
[2];
1377 return safe_call (2, args
);
1382 /***********************************************************************
1384 ***********************************************************************/
1388 /* Define CHECK_IT to perform sanity checks on iterators.
1389 This is for debugging. It is too slow to do unconditionally. */
1395 if (it
->method
== next_element_from_string
)
1397 xassert (STRINGP (it
->string
));
1398 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1400 else if (it
->method
== next_element_from_buffer
)
1402 /* Check that character and byte positions agree. */
1403 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1407 xassert (it
->current
.dpvec_index
>= 0);
1409 xassert (it
->current
.dpvec_index
< 0);
1412 #define CHECK_IT(IT) check_it ((IT))
1416 #define CHECK_IT(IT) (void) 0
1423 /* Check that the window end of window W is what we expect it
1424 to be---the last row in the current matrix displaying text. */
1427 check_window_end (w
)
1430 if (!MINI_WINDOW_P (w
)
1431 && !NILP (w
->window_end_valid
))
1433 struct glyph_row
*row
;
1434 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1435 XFASTINT (w
->window_end_vpos
)),
1437 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1438 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1442 #define CHECK_WINDOW_END(W) check_window_end ((W))
1444 #else /* not GLYPH_DEBUG */
1446 #define CHECK_WINDOW_END(W) (void) 0
1448 #endif /* not GLYPH_DEBUG */
1452 /***********************************************************************
1453 Iterator initialization
1454 ***********************************************************************/
1456 /* Initialize IT for displaying current_buffer in window W, starting
1457 at character position CHARPOS. CHARPOS < 0 means that no buffer
1458 position is specified which is useful when the iterator is assigned
1459 a position later. BYTEPOS is the byte position corresponding to
1460 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1462 If ROW is not null, calls to produce_glyphs with IT as parameter
1463 will produce glyphs in that row.
1465 BASE_FACE_ID is the id of a base face to use. It must be one of
1466 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1467 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1468 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1470 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1471 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1472 will be initialized to use the corresponding mode line glyph row of
1473 the desired matrix of W. */
1476 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1479 int charpos
, bytepos
;
1480 struct glyph_row
*row
;
1481 enum face_id base_face_id
;
1483 int highlight_region_p
;
1485 /* Some precondition checks. */
1486 xassert (w
!= NULL
&& it
!= NULL
);
1487 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1490 /* If face attributes have been changed since the last redisplay,
1491 free realized faces now because they depend on face definitions
1492 that might have changed. */
1493 if (face_change_count
)
1495 face_change_count
= 0;
1496 free_all_realized_faces (Qnil
);
1499 /* Use one of the mode line rows of W's desired matrix if
1503 if (base_face_id
== MODE_LINE_FACE_ID
1504 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1505 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1506 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1507 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1511 bzero (it
, sizeof *it
);
1512 it
->current
.overlay_string_index
= -1;
1513 it
->current
.dpvec_index
= -1;
1514 it
->base_face_id
= base_face_id
;
1516 /* The window in which we iterate over current_buffer: */
1517 XSETWINDOW (it
->window
, w
);
1519 it
->f
= XFRAME (w
->frame
);
1521 /* Extra space between lines (on window systems only). */
1522 if (base_face_id
== DEFAULT_FACE_ID
1523 && FRAME_WINDOW_P (it
->f
))
1525 if (NATNUMP (current_buffer
->extra_line_spacing
))
1526 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1527 else if (it
->f
->extra_line_spacing
> 0)
1528 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1531 /* If realized faces have been removed, e.g. because of face
1532 attribute changes of named faces, recompute them. When running
1533 in batch mode, the face cache of Vterminal_frame is null. If
1534 we happen to get called, make a dummy face cache. */
1539 FRAME_FACE_CACHE (it
->f
) == NULL
)
1540 init_frame_faces (it
->f
);
1541 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1542 recompute_basic_faces (it
->f
);
1544 /* Current value of the `space-width', and 'height' properties. */
1545 it
->space_width
= Qnil
;
1546 it
->font_height
= Qnil
;
1548 /* Are control characters displayed as `^C'? */
1549 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1551 /* -1 means everything between a CR and the following line end
1552 is invisible. >0 means lines indented more than this value are
1554 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1555 ? XFASTINT (current_buffer
->selective_display
)
1556 : (!NILP (current_buffer
->selective_display
)
1558 it
->selective_display_ellipsis_p
1559 = !NILP (current_buffer
->selective_display_ellipses
);
1561 /* Display table to use. */
1562 it
->dp
= window_display_table (w
);
1564 /* Are multibyte characters enabled in current_buffer? */
1565 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1567 /* Non-zero if we should highlight the region. */
1569 = (!NILP (Vtransient_mark_mode
)
1570 && !NILP (current_buffer
->mark_active
)
1571 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1573 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1574 start and end of a visible region in window IT->w. Set both to
1575 -1 to indicate no region. */
1576 if (highlight_region_p
1577 /* Maybe highlight only in selected window. */
1578 && (/* Either show region everywhere. */
1579 highlight_nonselected_windows
1580 /* Or show region in the selected window. */
1581 || w
== XWINDOW (selected_window
)
1582 /* Or show the region if we are in the mini-buffer and W is
1583 the window the mini-buffer refers to. */
1584 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1585 && WINDOWP (minibuf_selected_window
)
1586 && w
== XWINDOW (minibuf_selected_window
))))
1588 int charpos
= marker_position (current_buffer
->mark
);
1589 it
->region_beg_charpos
= min (PT
, charpos
);
1590 it
->region_end_charpos
= max (PT
, charpos
);
1593 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1595 /* Get the position at which the redisplay_end_trigger hook should
1596 be run, if it is to be run at all. */
1597 if (MARKERP (w
->redisplay_end_trigger
)
1598 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1599 it
->redisplay_end_trigger_charpos
1600 = marker_position (w
->redisplay_end_trigger
);
1601 else if (INTEGERP (w
->redisplay_end_trigger
))
1602 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1604 /* Correct bogus values of tab_width. */
1605 it
->tab_width
= XINT (current_buffer
->tab_width
);
1606 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1609 /* Are lines in the display truncated? */
1610 it
->truncate_lines_p
1611 = (base_face_id
!= DEFAULT_FACE_ID
1612 || XINT (it
->w
->hscroll
)
1613 || (truncate_partial_width_windows
1614 && !WINDOW_FULL_WIDTH_P (it
->w
))
1615 || !NILP (current_buffer
->truncate_lines
));
1617 /* Get dimensions of truncation and continuation glyphs. These are
1618 displayed as fringe bitmaps under X, so we don't need them for such
1620 if (!FRAME_WINDOW_P (it
->f
))
1622 if (it
->truncate_lines_p
)
1624 /* We will need the truncation glyph. */
1625 xassert (it
->glyph_row
== NULL
);
1626 produce_special_glyphs (it
, IT_TRUNCATION
);
1627 it
->truncation_pixel_width
= it
->pixel_width
;
1631 /* We will need the continuation glyph. */
1632 xassert (it
->glyph_row
== NULL
);
1633 produce_special_glyphs (it
, IT_CONTINUATION
);
1634 it
->continuation_pixel_width
= it
->pixel_width
;
1637 /* Reset these values to zero because the produce_special_glyphs
1638 above has changed them. */
1639 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1640 it
->phys_ascent
= it
->phys_descent
= 0;
1643 /* Set this after getting the dimensions of truncation and
1644 continuation glyphs, so that we don't produce glyphs when calling
1645 produce_special_glyphs, above. */
1646 it
->glyph_row
= row
;
1647 it
->area
= TEXT_AREA
;
1649 /* Get the dimensions of the display area. The display area
1650 consists of the visible window area plus a horizontally scrolled
1651 part to the left of the window. All x-values are relative to the
1652 start of this total display area. */
1653 if (base_face_id
!= DEFAULT_FACE_ID
)
1655 /* Mode lines, menu bar in terminal frames. */
1656 it
->first_visible_x
= 0;
1657 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1662 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1663 it
->last_visible_x
= (it
->first_visible_x
1664 + window_box_width (w
, TEXT_AREA
));
1666 /* If we truncate lines, leave room for the truncator glyph(s) at
1667 the right margin. Otherwise, leave room for the continuation
1668 glyph(s). Truncation and continuation glyphs are not inserted
1669 for window-based redisplay. */
1670 if (!FRAME_WINDOW_P (it
->f
))
1672 if (it
->truncate_lines_p
)
1673 it
->last_visible_x
-= it
->truncation_pixel_width
;
1675 it
->last_visible_x
-= it
->continuation_pixel_width
;
1678 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1679 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1682 /* Leave room for a border glyph. */
1683 if (!FRAME_WINDOW_P (it
->f
)
1684 && !WINDOW_RIGHTMOST_P (it
->w
))
1685 it
->last_visible_x
-= 1;
1687 it
->last_visible_y
= window_text_bottom_y (w
);
1689 /* For mode lines and alike, arrange for the first glyph having a
1690 left box line if the face specifies a box. */
1691 if (base_face_id
!= DEFAULT_FACE_ID
)
1695 it
->face_id
= base_face_id
;
1697 /* If we have a boxed mode line, make the first character appear
1698 with a left box line. */
1699 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1700 if (face
->box
!= FACE_NO_BOX
)
1701 it
->start_of_box_run_p
= 1;
1704 /* If a buffer position was specified, set the iterator there,
1705 getting overlays and face properties from that position. */
1706 if (charpos
>= BUF_BEG (current_buffer
))
1708 it
->end_charpos
= ZV
;
1710 IT_CHARPOS (*it
) = charpos
;
1712 /* Compute byte position if not specified. */
1713 if (bytepos
< charpos
)
1714 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1716 IT_BYTEPOS (*it
) = bytepos
;
1718 /* Compute faces etc. */
1719 reseat (it
, it
->current
.pos
, 1);
1726 /* Initialize IT for the display of window W with window start POS. */
1729 start_display (it
, w
, pos
)
1732 struct text_pos pos
;
1734 struct glyph_row
*row
;
1735 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1737 row
= w
->desired_matrix
->rows
+ first_vpos
;
1738 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1740 if (!it
->truncate_lines_p
)
1742 int start_at_line_beg_p
;
1743 int first_y
= it
->current_y
;
1745 /* If window start is not at a line start, skip forward to POS to
1746 get the correct continuation lines width. */
1747 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1748 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1749 if (!start_at_line_beg_p
)
1751 reseat_at_previous_visible_line_start (it
);
1752 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1754 /* If lines are continued, this line may end in the middle
1755 of a multi-glyph character (e.g. a control character
1756 displayed as \003, or in the middle of an overlay
1757 string). In this case move_it_to above will not have
1758 taken us to the start of the continuation line but to the
1759 end of the continued line. */
1760 if (it
->current_x
> 0)
1762 if (it
->current
.dpvec_index
>= 0
1763 || it
->current
.overlay_string_index
>= 0)
1765 set_iterator_to_next (it
, 1);
1766 move_it_in_display_line_to (it
, -1, -1, 0);
1769 it
->continuation_lines_width
+= it
->current_x
;
1772 /* We're starting a new display line, not affected by the
1773 height of the continued line, so clear the appropriate
1774 fields in the iterator structure. */
1775 it
->max_ascent
= it
->max_descent
= 0;
1776 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1778 it
->current_y
= first_y
;
1780 it
->current_x
= it
->hpos
= 0;
1784 #if 0 /* Don't assert the following because start_display is sometimes
1785 called intentionally with a window start that is not at a
1786 line start. Please leave this code in as a comment. */
1788 /* Window start should be on a line start, now. */
1789 xassert (it
->continuation_lines_width
1790 || IT_CHARPOS (it
) == BEGV
1791 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1796 /* Return 1 if POS is a position in ellipses displayed for invisible
1797 text. W is the window we display, for text property lookup. */
1800 in_ellipses_for_invisible_text_p (pos
, w
)
1801 struct display_pos
*pos
;
1804 Lisp_Object prop
, window
;
1806 int charpos
= CHARPOS (pos
->pos
);
1808 /* If POS specifies a position in a display vector, this might
1809 be for an ellipsis displayed for invisible text. We won't
1810 get the iterator set up for delivering that ellipsis unless
1811 we make sure that it gets aware of the invisible text. */
1812 if (pos
->dpvec_index
>= 0
1813 && pos
->overlay_string_index
< 0
1814 && CHARPOS (pos
->string_pos
) < 0
1816 && (XSETWINDOW (window
, w
),
1817 prop
= Fget_char_property (make_number (charpos
),
1818 Qinvisible
, window
),
1819 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1821 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1823 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1830 /* Initialize IT for stepping through current_buffer in window W,
1831 starting at position POS that includes overlay string and display
1832 vector/ control character translation position information. Value
1833 is zero if there are overlay strings with newlines at POS. */
1836 init_from_display_pos (it
, w
, pos
)
1839 struct display_pos
*pos
;
1841 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1842 int i
, overlay_strings_with_newlines
= 0;
1844 /* If POS specifies a position in a display vector, this might
1845 be for an ellipsis displayed for invisible text. We won't
1846 get the iterator set up for delivering that ellipsis unless
1847 we make sure that it gets aware of the invisible text. */
1848 if (in_ellipses_for_invisible_text_p (pos
, w
))
1854 /* Keep in mind: the call to reseat in init_iterator skips invisible
1855 text, so we might end up at a position different from POS. This
1856 is only a problem when POS is a row start after a newline and an
1857 overlay starts there with an after-string, and the overlay has an
1858 invisible property. Since we don't skip invisible text in
1859 display_line and elsewhere immediately after consuming the
1860 newline before the row start, such a POS will not be in a string,
1861 but the call to init_iterator below will move us to the
1863 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1865 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1867 char *s
= SDATA (it
->overlay_strings
[i
]);
1868 char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1870 while (s
< e
&& *s
!= '\n')
1875 overlay_strings_with_newlines
= 1;
1880 /* If position is within an overlay string, set up IT to the right
1882 if (pos
->overlay_string_index
>= 0)
1886 /* If the first overlay string happens to have a `display'
1887 property for an image, the iterator will be set up for that
1888 image, and we have to undo that setup first before we can
1889 correct the overlay string index. */
1890 if (it
->method
== next_element_from_image
)
1893 /* We already have the first chunk of overlay strings in
1894 IT->overlay_strings. Load more until the one for
1895 pos->overlay_string_index is in IT->overlay_strings. */
1896 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1898 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1899 it
->current
.overlay_string_index
= 0;
1902 load_overlay_strings (it
, 0);
1903 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1907 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1908 relative_index
= (it
->current
.overlay_string_index
1909 % OVERLAY_STRING_CHUNK_SIZE
);
1910 it
->string
= it
->overlay_strings
[relative_index
];
1911 xassert (STRINGP (it
->string
));
1912 it
->current
.string_pos
= pos
->string_pos
;
1913 it
->method
= next_element_from_string
;
1916 #if 0 /* This is bogus because POS not having an overlay string
1917 position does not mean it's after the string. Example: A
1918 line starting with a before-string and initialization of IT
1919 to the previous row's end position. */
1920 else if (it
->current
.overlay_string_index
>= 0)
1922 /* If POS says we're already after an overlay string ending at
1923 POS, make sure to pop the iterator because it will be in
1924 front of that overlay string. When POS is ZV, we've thereby
1925 also ``processed'' overlay strings at ZV. */
1928 it
->current
.overlay_string_index
= -1;
1929 it
->method
= next_element_from_buffer
;
1930 if (CHARPOS (pos
->pos
) == ZV
)
1931 it
->overlay_strings_at_end_processed_p
= 1;
1935 if (CHARPOS (pos
->string_pos
) >= 0)
1937 /* Recorded position is not in an overlay string, but in another
1938 string. This can only be a string from a `display' property.
1939 IT should already be filled with that string. */
1940 it
->current
.string_pos
= pos
->string_pos
;
1941 xassert (STRINGP (it
->string
));
1944 /* Restore position in display vector translations, control
1945 character translations or ellipses. */
1946 if (pos
->dpvec_index
>= 0)
1948 if (it
->dpvec
== NULL
)
1949 get_next_display_element (it
);
1950 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1951 it
->current
.dpvec_index
= pos
->dpvec_index
;
1955 return !overlay_strings_with_newlines
;
1959 /* Initialize IT for stepping through current_buffer in window W
1960 starting at ROW->start. */
1963 init_to_row_start (it
, w
, row
)
1966 struct glyph_row
*row
;
1968 init_from_display_pos (it
, w
, &row
->start
);
1969 it
->continuation_lines_width
= row
->continuation_lines_width
;
1974 /* Initialize IT for stepping through current_buffer in window W
1975 starting in the line following ROW, i.e. starting at ROW->end.
1976 Value is zero if there are overlay strings with newlines at ROW's
1980 init_to_row_end (it
, w
, row
)
1983 struct glyph_row
*row
;
1987 if (init_from_display_pos (it
, w
, &row
->end
))
1989 if (row
->continued_p
)
1990 it
->continuation_lines_width
1991 = row
->continuation_lines_width
+ row
->pixel_width
;
2002 /***********************************************************************
2004 ***********************************************************************/
2006 /* Called when IT reaches IT->stop_charpos. Handle text property and
2007 overlay changes. Set IT->stop_charpos to the next position where
2014 enum prop_handled handled
;
2015 int handle_overlay_change_p
= 1;
2019 it
->current
.dpvec_index
= -1;
2023 handled
= HANDLED_NORMALLY
;
2025 /* Call text property handlers. */
2026 for (p
= it_props
; p
->handler
; ++p
)
2028 handled
= p
->handler (it
);
2030 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2032 else if (handled
== HANDLED_RETURN
)
2034 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2035 handle_overlay_change_p
= 0;
2038 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2040 /* Don't check for overlay strings below when set to deliver
2041 characters from a display vector. */
2042 if (it
->method
== next_element_from_display_vector
)
2043 handle_overlay_change_p
= 0;
2045 /* Handle overlay changes. */
2046 if (handle_overlay_change_p
)
2047 handled
= handle_overlay_change (it
);
2049 /* Determine where to stop next. */
2050 if (handled
== HANDLED_NORMALLY
)
2051 compute_stop_pos (it
);
2054 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2058 /* Compute IT->stop_charpos from text property and overlay change
2059 information for IT's current position. */
2062 compute_stop_pos (it
)
2065 register INTERVAL iv
, next_iv
;
2066 Lisp_Object object
, limit
, position
;
2068 /* If nowhere else, stop at the end. */
2069 it
->stop_charpos
= it
->end_charpos
;
2071 if (STRINGP (it
->string
))
2073 /* Strings are usually short, so don't limit the search for
2075 object
= it
->string
;
2077 position
= make_number (IT_STRING_CHARPOS (*it
));
2083 /* If next overlay change is in front of the current stop pos
2084 (which is IT->end_charpos), stop there. Note: value of
2085 next_overlay_change is point-max if no overlay change
2087 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2088 if (charpos
< it
->stop_charpos
)
2089 it
->stop_charpos
= charpos
;
2091 /* If showing the region, we have to stop at the region
2092 start or end because the face might change there. */
2093 if (it
->region_beg_charpos
> 0)
2095 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2096 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2097 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2098 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2101 /* Set up variables for computing the stop position from text
2102 property changes. */
2103 XSETBUFFER (object
, current_buffer
);
2104 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2105 position
= make_number (IT_CHARPOS (*it
));
2109 /* Get the interval containing IT's position. Value is a null
2110 interval if there isn't such an interval. */
2111 iv
= validate_interval_range (object
, &position
, &position
, 0);
2112 if (!NULL_INTERVAL_P (iv
))
2114 Lisp_Object values_here
[LAST_PROP_IDX
];
2117 /* Get properties here. */
2118 for (p
= it_props
; p
->handler
; ++p
)
2119 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2121 /* Look for an interval following iv that has different
2123 for (next_iv
= next_interval (iv
);
2124 (!NULL_INTERVAL_P (next_iv
)
2126 || XFASTINT (limit
) > next_iv
->position
));
2127 next_iv
= next_interval (next_iv
))
2129 for (p
= it_props
; p
->handler
; ++p
)
2131 Lisp_Object new_value
;
2133 new_value
= textget (next_iv
->plist
, *p
->name
);
2134 if (!EQ (values_here
[p
->idx
], new_value
))
2142 if (!NULL_INTERVAL_P (next_iv
))
2144 if (INTEGERP (limit
)
2145 && next_iv
->position
>= XFASTINT (limit
))
2146 /* No text property change up to limit. */
2147 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2149 /* Text properties change in next_iv. */
2150 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2154 xassert (STRINGP (it
->string
)
2155 || (it
->stop_charpos
>= BEGV
2156 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2160 /* Return the position of the next overlay change after POS in
2161 current_buffer. Value is point-max if no overlay change
2162 follows. This is like `next-overlay-change' but doesn't use
2166 next_overlay_change (pos
)
2171 Lisp_Object
*overlays
;
2175 /* Get all overlays at the given position. */
2177 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2178 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2179 if (noverlays
> len
)
2182 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2183 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2186 /* If any of these overlays ends before endpos,
2187 use its ending point instead. */
2188 for (i
= 0; i
< noverlays
; ++i
)
2193 oend
= OVERLAY_END (overlays
[i
]);
2194 oendpos
= OVERLAY_POSITION (oend
);
2195 endpos
= min (endpos
, oendpos
);
2203 /***********************************************************************
2205 ***********************************************************************/
2207 /* Handle changes in the `fontified' property of the current buffer by
2208 calling hook functions from Qfontification_functions to fontify
2211 static enum prop_handled
2212 handle_fontified_prop (it
)
2215 Lisp_Object prop
, pos
;
2216 enum prop_handled handled
= HANDLED_NORMALLY
;
2218 /* Get the value of the `fontified' property at IT's current buffer
2219 position. (The `fontified' property doesn't have a special
2220 meaning in strings.) If the value is nil, call functions from
2221 Qfontification_functions. */
2222 if (!STRINGP (it
->string
)
2224 && !NILP (Vfontification_functions
)
2225 && !NILP (Vrun_hooks
)
2226 && (pos
= make_number (IT_CHARPOS (*it
)),
2227 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2230 int count
= BINDING_STACK_SIZE ();
2233 val
= Vfontification_functions
;
2234 specbind (Qfontification_functions
, Qnil
);
2236 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2237 safe_call1 (val
, pos
);
2240 Lisp_Object globals
, fn
;
2241 struct gcpro gcpro1
, gcpro2
;
2244 GCPRO2 (val
, globals
);
2246 for (; CONSP (val
); val
= XCDR (val
))
2252 /* A value of t indicates this hook has a local
2253 binding; it means to run the global binding too.
2254 In a global value, t should not occur. If it
2255 does, we must ignore it to avoid an endless
2257 for (globals
= Fdefault_value (Qfontification_functions
);
2259 globals
= XCDR (globals
))
2261 fn
= XCAR (globals
);
2263 safe_call1 (fn
, pos
);
2267 safe_call1 (fn
, pos
);
2273 unbind_to (count
, Qnil
);
2275 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2276 something. This avoids an endless loop if they failed to
2277 fontify the text for which reason ever. */
2278 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2279 handled
= HANDLED_RECOMPUTE_PROPS
;
2287 /***********************************************************************
2289 ***********************************************************************/
2291 /* Set up iterator IT from face properties at its current position.
2292 Called from handle_stop. */
2294 static enum prop_handled
2295 handle_face_prop (it
)
2298 int new_face_id
, next_stop
;
2300 if (!STRINGP (it
->string
))
2303 = face_at_buffer_position (it
->w
,
2305 it
->region_beg_charpos
,
2306 it
->region_end_charpos
,
2309 + TEXT_PROP_DISTANCE_LIMIT
),
2312 /* Is this a start of a run of characters with box face?
2313 Caveat: this can be called for a freshly initialized
2314 iterator; face_id is -1 in this case. We know that the new
2315 face will not change until limit, i.e. if the new face has a
2316 box, all characters up to limit will have one. But, as
2317 usual, we don't know whether limit is really the end. */
2318 if (new_face_id
!= it
->face_id
)
2320 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2322 /* If new face has a box but old face has not, this is
2323 the start of a run of characters with box, i.e. it has
2324 a shadow on the left side. The value of face_id of the
2325 iterator will be -1 if this is the initial call that gets
2326 the face. In this case, we have to look in front of IT's
2327 position and see whether there is a face != new_face_id. */
2328 it
->start_of_box_run_p
2329 = (new_face
->box
!= FACE_NO_BOX
2330 && (it
->face_id
>= 0
2331 || IT_CHARPOS (*it
) == BEG
2332 || new_face_id
!= face_before_it_pos (it
)));
2333 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2338 int base_face_id
, bufpos
;
2340 if (it
->current
.overlay_string_index
>= 0)
2341 bufpos
= IT_CHARPOS (*it
);
2345 /* For strings from a buffer, i.e. overlay strings or strings
2346 from a `display' property, use the face at IT's current
2347 buffer position as the base face to merge with, so that
2348 overlay strings appear in the same face as surrounding
2349 text, unless they specify their own faces. */
2350 base_face_id
= underlying_face_id (it
);
2352 new_face_id
= face_at_string_position (it
->w
,
2354 IT_STRING_CHARPOS (*it
),
2356 it
->region_beg_charpos
,
2357 it
->region_end_charpos
,
2361 #if 0 /* This shouldn't be neccessary. Let's check it. */
2362 /* If IT is used to display a mode line we would really like to
2363 use the mode line face instead of the frame's default face. */
2364 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2365 && new_face_id
== DEFAULT_FACE_ID
)
2366 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2369 /* Is this a start of a run of characters with box? Caveat:
2370 this can be called for a freshly allocated iterator; face_id
2371 is -1 is this case. We know that the new face will not
2372 change until the next check pos, i.e. if the new face has a
2373 box, all characters up to that position will have a
2374 box. But, as usual, we don't know whether that position
2375 is really the end. */
2376 if (new_face_id
!= it
->face_id
)
2378 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2379 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2381 /* If new face has a box but old face hasn't, this is the
2382 start of a run of characters with box, i.e. it has a
2383 shadow on the left side. */
2384 it
->start_of_box_run_p
2385 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2386 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2390 it
->face_id
= new_face_id
;
2391 return HANDLED_NORMALLY
;
2395 /* Return the ID of the face ``underlying'' IT's current position,
2396 which is in a string. If the iterator is associated with a
2397 buffer, return the face at IT's current buffer position.
2398 Otherwise, use the iterator's base_face_id. */
2401 underlying_face_id (it
)
2404 int face_id
= it
->base_face_id
, i
;
2406 xassert (STRINGP (it
->string
));
2408 for (i
= it
->sp
- 1; i
>= 0; --i
)
2409 if (NILP (it
->stack
[i
].string
))
2410 face_id
= it
->stack
[i
].face_id
;
2416 /* Compute the face one character before or after the current position
2417 of IT. BEFORE_P non-zero means get the face in front of IT's
2418 position. Value is the id of the face. */
2421 face_before_or_after_it_pos (it
, before_p
)
2426 int next_check_charpos
;
2427 struct text_pos pos
;
2429 xassert (it
->s
== NULL
);
2431 if (STRINGP (it
->string
))
2433 int bufpos
, base_face_id
;
2435 /* No face change past the end of the string (for the case
2436 we are padding with spaces). No face change before the
2438 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2439 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2442 /* Set pos to the position before or after IT's current position. */
2444 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2446 /* For composition, we must check the character after the
2448 pos
= (it
->what
== IT_COMPOSITION
2449 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2450 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2452 if (it
->current
.overlay_string_index
>= 0)
2453 bufpos
= IT_CHARPOS (*it
);
2457 base_face_id
= underlying_face_id (it
);
2459 /* Get the face for ASCII, or unibyte. */
2460 face_id
= face_at_string_position (it
->w
,
2464 it
->region_beg_charpos
,
2465 it
->region_end_charpos
,
2466 &next_check_charpos
,
2469 /* Correct the face for charsets different from ASCII. Do it
2470 for the multibyte case only. The face returned above is
2471 suitable for unibyte text if IT->string is unibyte. */
2472 if (STRING_MULTIBYTE (it
->string
))
2474 unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2475 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2477 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2479 c
= string_char_and_length (p
, rest
, &len
);
2480 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2485 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2486 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2489 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2490 pos
= it
->current
.pos
;
2493 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2496 if (it
->what
== IT_COMPOSITION
)
2497 /* For composition, we must check the position after the
2499 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2501 INC_TEXT_POS (pos
, it
->multibyte_p
);
2504 /* Determine face for CHARSET_ASCII, or unibyte. */
2505 face_id
= face_at_buffer_position (it
->w
,
2507 it
->region_beg_charpos
,
2508 it
->region_end_charpos
,
2509 &next_check_charpos
,
2512 /* Correct the face for charsets different from ASCII. Do it
2513 for the multibyte case only. The face returned above is
2514 suitable for unibyte text if current_buffer is unibyte. */
2515 if (it
->multibyte_p
)
2517 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2518 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2519 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2528 /***********************************************************************
2530 ***********************************************************************/
2532 /* Set up iterator IT from invisible properties at its current
2533 position. Called from handle_stop. */
2535 static enum prop_handled
2536 handle_invisible_prop (it
)
2539 enum prop_handled handled
= HANDLED_NORMALLY
;
2541 if (STRINGP (it
->string
))
2543 extern Lisp_Object Qinvisible
;
2544 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2546 /* Get the value of the invisible text property at the
2547 current position. Value will be nil if there is no such
2549 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2550 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2553 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2555 handled
= HANDLED_RECOMPUTE_PROPS
;
2557 /* Get the position at which the next change of the
2558 invisible text property can be found in IT->string.
2559 Value will be nil if the property value is the same for
2560 all the rest of IT->string. */
2561 XSETINT (limit
, SCHARS (it
->string
));
2562 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2565 /* Text at current position is invisible. The next
2566 change in the property is at position end_charpos.
2567 Move IT's current position to that position. */
2568 if (INTEGERP (end_charpos
)
2569 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2571 struct text_pos old
;
2572 old
= it
->current
.string_pos
;
2573 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2574 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2578 /* The rest of the string is invisible. If this is an
2579 overlay string, proceed with the next overlay string
2580 or whatever comes and return a character from there. */
2581 if (it
->current
.overlay_string_index
>= 0)
2583 next_overlay_string (it
);
2584 /* Don't check for overlay strings when we just
2585 finished processing them. */
2586 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2590 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2591 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2598 int invis_p
, newpos
, next_stop
, start_charpos
;
2599 Lisp_Object pos
, prop
, overlay
;
2601 /* First of all, is there invisible text at this position? */
2602 start_charpos
= IT_CHARPOS (*it
);
2603 pos
= make_number (IT_CHARPOS (*it
));
2604 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2606 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2608 /* If we are on invisible text, skip over it. */
2609 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2611 /* Record whether we have to display an ellipsis for the
2613 int display_ellipsis_p
= invis_p
== 2;
2615 handled
= HANDLED_RECOMPUTE_PROPS
;
2617 /* Loop skipping over invisible text. The loop is left at
2618 ZV or with IT on the first char being visible again. */
2621 /* Try to skip some invisible text. Return value is the
2622 position reached which can be equal to IT's position
2623 if there is nothing invisible here. This skips both
2624 over invisible text properties and overlays with
2625 invisible property. */
2626 newpos
= skip_invisible (IT_CHARPOS (*it
),
2627 &next_stop
, ZV
, it
->window
);
2629 /* If we skipped nothing at all we weren't at invisible
2630 text in the first place. If everything to the end of
2631 the buffer was skipped, end the loop. */
2632 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2636 /* We skipped some characters but not necessarily
2637 all there are. Check if we ended up on visible
2638 text. Fget_char_property returns the property of
2639 the char before the given position, i.e. if we
2640 get invis_p = 0, this means that the char at
2641 newpos is visible. */
2642 pos
= make_number (newpos
);
2643 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2644 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2647 /* If we ended up on invisible text, proceed to
2648 skip starting with next_stop. */
2650 IT_CHARPOS (*it
) = next_stop
;
2654 /* The position newpos is now either ZV or on visible text. */
2655 IT_CHARPOS (*it
) = newpos
;
2656 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2658 /* If there are before-strings at the start of invisible
2659 text, and the text is invisible because of a text
2660 property, arrange to show before-strings because 20.x did
2661 it that way. (If the text is invisible because of an
2662 overlay property instead of a text property, this is
2663 already handled in the overlay code.) */
2665 && get_overlay_strings (it
, start_charpos
))
2667 handled
= HANDLED_RECOMPUTE_PROPS
;
2668 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2670 else if (display_ellipsis_p
)
2671 setup_for_ellipsis (it
);
2679 /* Make iterator IT return `...' next. */
2682 setup_for_ellipsis (it
)
2686 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2688 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2689 it
->dpvec
= v
->contents
;
2690 it
->dpend
= v
->contents
+ v
->size
;
2694 /* Default `...'. */
2695 it
->dpvec
= default_invis_vector
;
2696 it
->dpend
= default_invis_vector
+ 3;
2699 /* The ellipsis display does not replace the display of the
2700 character at the new position. Indicate this by setting
2701 IT->dpvec_char_len to zero. */
2702 it
->dpvec_char_len
= 0;
2704 it
->current
.dpvec_index
= 0;
2705 it
->method
= next_element_from_display_vector
;
2710 /***********************************************************************
2712 ***********************************************************************/
2714 /* Set up iterator IT from `display' property at its current position.
2715 Called from handle_stop. */
2717 static enum prop_handled
2718 handle_display_prop (it
)
2721 Lisp_Object prop
, object
;
2722 struct text_pos
*position
;
2723 int display_replaced_p
= 0;
2725 if (STRINGP (it
->string
))
2727 object
= it
->string
;
2728 position
= &it
->current
.string_pos
;
2732 object
= it
->w
->buffer
;
2733 position
= &it
->current
.pos
;
2736 /* Reset those iterator values set from display property values. */
2737 it
->font_height
= Qnil
;
2738 it
->space_width
= Qnil
;
2741 /* We don't support recursive `display' properties, i.e. string
2742 values that have a string `display' property, that have a string
2743 `display' property etc. */
2744 if (!it
->string_from_display_prop_p
)
2745 it
->area
= TEXT_AREA
;
2747 prop
= Fget_char_property (make_number (position
->charpos
),
2750 return HANDLED_NORMALLY
;
2753 /* Simple properties. */
2754 && !EQ (XCAR (prop
), Qimage
)
2755 && !EQ (XCAR (prop
), Qspace
)
2756 && !EQ (XCAR (prop
), Qwhen
)
2757 && !EQ (XCAR (prop
), Qspace_width
)
2758 && !EQ (XCAR (prop
), Qheight
)
2759 && !EQ (XCAR (prop
), Qraise
)
2760 /* Marginal area specifications. */
2761 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2762 && !NILP (XCAR (prop
)))
2764 for (; CONSP (prop
); prop
= XCDR (prop
))
2766 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2767 position
, display_replaced_p
))
2768 display_replaced_p
= 1;
2771 else if (VECTORP (prop
))
2774 for (i
= 0; i
< ASIZE (prop
); ++i
)
2775 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2776 position
, display_replaced_p
))
2777 display_replaced_p
= 1;
2781 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2782 display_replaced_p
= 1;
2785 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2789 /* Value is the position of the end of the `display' property starting
2790 at START_POS in OBJECT. */
2792 static struct text_pos
2793 display_prop_end (it
, object
, start_pos
)
2796 struct text_pos start_pos
;
2799 struct text_pos end_pos
;
2801 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2802 Qdisplay
, object
, Qnil
);
2803 CHARPOS (end_pos
) = XFASTINT (end
);
2804 if (STRINGP (object
))
2805 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2807 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2813 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2814 is the object in which the `display' property was found. *POSITION
2815 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2816 means that we previously saw a display sub-property which already
2817 replaced text display with something else, for example an image;
2818 ignore such properties after the first one has been processed.
2820 If PROP is a `space' or `image' sub-property, set *POSITION to the
2821 end position of the `display' property.
2823 Value is non-zero if something was found which replaces the display
2824 of buffer or string text. */
2827 handle_single_display_prop (it
, prop
, object
, position
,
2828 display_replaced_before_p
)
2832 struct text_pos
*position
;
2833 int display_replaced_before_p
;
2836 int replaces_text_display_p
= 0;
2839 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2840 evaluated. If the result is nil, VALUE is ignored. */
2842 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2851 if (!NILP (form
) && !EQ (form
, Qt
))
2853 int count
= BINDING_STACK_SIZE ();
2854 struct gcpro gcpro1
;
2856 /* Bind `object' to the object having the `display' property, a
2857 buffer or string. Bind `position' to the position in the
2858 object where the property was found, and `buffer-position'
2859 to the current position in the buffer. */
2860 specbind (Qobject
, object
);
2861 specbind (Qposition
, make_number (CHARPOS (*position
)));
2862 specbind (Qbuffer_position
,
2863 make_number (STRINGP (object
)
2864 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2866 form
= safe_eval (form
);
2868 unbind_to (count
, Qnil
);
2875 && EQ (XCAR (prop
), Qheight
)
2876 && CONSP (XCDR (prop
)))
2878 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2881 /* `(height HEIGHT)'. */
2882 it
->font_height
= XCAR (XCDR (prop
));
2883 if (!NILP (it
->font_height
))
2885 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2886 int new_height
= -1;
2888 if (CONSP (it
->font_height
)
2889 && (EQ (XCAR (it
->font_height
), Qplus
)
2890 || EQ (XCAR (it
->font_height
), Qminus
))
2891 && CONSP (XCDR (it
->font_height
))
2892 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2894 /* `(+ N)' or `(- N)' where N is an integer. */
2895 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2896 if (EQ (XCAR (it
->font_height
), Qplus
))
2898 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2900 else if (FUNCTIONP (it
->font_height
))
2902 /* Call function with current height as argument.
2903 Value is the new height. */
2905 height
= safe_call1 (it
->font_height
,
2906 face
->lface
[LFACE_HEIGHT_INDEX
]);
2907 if (NUMBERP (height
))
2908 new_height
= XFLOATINT (height
);
2910 else if (NUMBERP (it
->font_height
))
2912 /* Value is a multiple of the canonical char height. */
2915 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2916 new_height
= (XFLOATINT (it
->font_height
)
2917 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2921 /* Evaluate IT->font_height with `height' bound to the
2922 current specified height to get the new height. */
2924 int count
= BINDING_STACK_SIZE ();
2926 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2927 value
= safe_eval (it
->font_height
);
2928 unbind_to (count
, Qnil
);
2930 if (NUMBERP (value
))
2931 new_height
= XFLOATINT (value
);
2935 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2938 else if (CONSP (prop
)
2939 && EQ (XCAR (prop
), Qspace_width
)
2940 && CONSP (XCDR (prop
)))
2942 /* `(space_width WIDTH)'. */
2943 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2946 value
= XCAR (XCDR (prop
));
2947 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2948 it
->space_width
= value
;
2950 else if (CONSP (prop
)
2951 && EQ (XCAR (prop
), Qraise
)
2952 && CONSP (XCDR (prop
)))
2954 /* `(raise FACTOR)'. */
2955 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2958 #ifdef HAVE_WINDOW_SYSTEM
2959 value
= XCAR (XCDR (prop
));
2960 if (NUMBERP (value
))
2962 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2963 it
->voffset
= - (XFLOATINT (value
)
2964 * (FONT_HEIGHT (face
->font
)));
2966 #endif /* HAVE_WINDOW_SYSTEM */
2968 else if (!it
->string_from_display_prop_p
)
2970 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2971 VALUE) or `((margin nil) VALUE)' or VALUE. */
2972 Lisp_Object location
, value
;
2973 struct text_pos start_pos
;
2976 /* Characters having this form of property are not displayed, so
2977 we have to find the end of the property. */
2978 start_pos
= *position
;
2979 *position
= display_prop_end (it
, object
, start_pos
);
2982 /* Let's stop at the new position and assume that all
2983 text properties change there. */
2984 it
->stop_charpos
= position
->charpos
;
2986 location
= Qunbound
;
2987 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2991 value
= XCDR (prop
);
2993 value
= XCAR (value
);
2996 if (EQ (XCAR (tem
), Qmargin
)
2997 && (tem
= XCDR (tem
),
2998 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3000 || EQ (tem
, Qleft_margin
)
3001 || EQ (tem
, Qright_margin
))))
3005 if (EQ (location
, Qunbound
))
3011 #ifdef HAVE_WINDOW_SYSTEM
3012 if (FRAME_TERMCAP_P (it
->f
))
3013 valid_p
= STRINGP (value
);
3015 valid_p
= (STRINGP (value
)
3016 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3017 || valid_image_p (value
));
3018 #else /* not HAVE_WINDOW_SYSTEM */
3019 valid_p
= STRINGP (value
);
3020 #endif /* not HAVE_WINDOW_SYSTEM */
3022 if ((EQ (location
, Qleft_margin
)
3023 || EQ (location
, Qright_margin
)
3026 && !display_replaced_before_p
)
3028 replaces_text_display_p
= 1;
3030 /* Save current settings of IT so that we can restore them
3031 when we are finished with the glyph property value. */
3034 if (NILP (location
))
3035 it
->area
= TEXT_AREA
;
3036 else if (EQ (location
, Qleft_margin
))
3037 it
->area
= LEFT_MARGIN_AREA
;
3039 it
->area
= RIGHT_MARGIN_AREA
;
3041 if (STRINGP (value
))
3044 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3045 it
->current
.overlay_string_index
= -1;
3046 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3047 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3048 it
->method
= next_element_from_string
;
3049 it
->stop_charpos
= 0;
3050 it
->string_from_display_prop_p
= 1;
3051 /* Say that we haven't consumed the characters with
3052 `display' property yet. The call to pop_it in
3053 set_iterator_to_next will clean this up. */
3054 *position
= start_pos
;
3056 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3058 it
->method
= next_element_from_stretch
;
3060 it
->current
.pos
= it
->position
= start_pos
;
3062 #ifdef HAVE_WINDOW_SYSTEM
3065 it
->what
= IT_IMAGE
;
3066 it
->image_id
= lookup_image (it
->f
, value
);
3067 it
->position
= start_pos
;
3068 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3069 it
->method
= next_element_from_image
;
3071 /* Say that we haven't consumed the characters with
3072 `display' property yet. The call to pop_it in
3073 set_iterator_to_next will clean this up. */
3074 *position
= start_pos
;
3076 #endif /* HAVE_WINDOW_SYSTEM */
3079 /* Invalid property or property not supported. Restore
3080 the position to what it was before. */
3081 *position
= start_pos
;
3084 return replaces_text_display_p
;
3088 /* Check if PROP is a display sub-property value whose text should be
3089 treated as intangible. */
3092 single_display_prop_intangible_p (prop
)
3095 /* Skip over `when FORM'. */
3096 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3107 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3108 we don't need to treat text as intangible. */
3109 if (EQ (XCAR (prop
), Qmargin
))
3117 || EQ (XCAR (prop
), Qleft_margin
)
3118 || EQ (XCAR (prop
), Qright_margin
))
3122 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3126 /* Check if PROP is a display property value whose text should be
3127 treated as intangible. */
3130 display_prop_intangible_p (prop
)
3134 && CONSP (XCAR (prop
))
3135 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3137 /* A list of sub-properties. */
3138 while (CONSP (prop
))
3140 if (single_display_prop_intangible_p (XCAR (prop
)))
3145 else if (VECTORP (prop
))
3147 /* A vector of sub-properties. */
3149 for (i
= 0; i
< ASIZE (prop
); ++i
)
3150 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3154 return single_display_prop_intangible_p (prop
);
3160 /* Return 1 if PROP is a display sub-property value containing STRING. */
3163 single_display_prop_string_p (prop
, string
)
3164 Lisp_Object prop
, string
;
3166 if (EQ (string
, prop
))
3169 /* Skip over `when FORM'. */
3170 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3179 /* Skip over `margin LOCATION'. */
3180 if (EQ (XCAR (prop
), Qmargin
))
3191 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3195 /* Return 1 if STRING appears in the `display' property PROP. */
3198 display_prop_string_p (prop
, string
)
3199 Lisp_Object prop
, string
;
3202 && CONSP (XCAR (prop
))
3203 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3205 /* A list of sub-properties. */
3206 while (CONSP (prop
))
3208 if (single_display_prop_string_p (XCAR (prop
), string
))
3213 else if (VECTORP (prop
))
3215 /* A vector of sub-properties. */
3217 for (i
= 0; i
< ASIZE (prop
); ++i
)
3218 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3222 return single_display_prop_string_p (prop
, string
);
3228 /* Determine from which buffer position in W's buffer STRING comes
3229 from. AROUND_CHARPOS is an approximate position where it could
3230 be from. Value is the buffer position or 0 if it couldn't be
3233 W's buffer must be current.
3235 This function is necessary because we don't record buffer positions
3236 in glyphs generated from strings (to keep struct glyph small).
3237 This function may only use code that doesn't eval because it is
3238 called asynchronously from note_mouse_highlight. */
3241 string_buffer_position (w
, string
, around_charpos
)
3246 Lisp_Object limit
, prop
, pos
;
3247 const int MAX_DISTANCE
= 1000;
3250 pos
= make_number (around_charpos
);
3251 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3252 while (!found
&& !EQ (pos
, limit
))
3254 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3255 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3258 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3263 pos
= make_number (around_charpos
);
3264 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3265 while (!found
&& !EQ (pos
, limit
))
3267 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3268 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3271 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3276 return found
? XINT (pos
) : 0;
3281 /***********************************************************************
3282 `composition' property
3283 ***********************************************************************/
3285 /* Set up iterator IT from `composition' property at its current
3286 position. Called from handle_stop. */
3288 static enum prop_handled
3289 handle_composition_prop (it
)
3292 Lisp_Object prop
, string
;
3293 int pos
, pos_byte
, end
;
3294 enum prop_handled handled
= HANDLED_NORMALLY
;
3296 if (STRINGP (it
->string
))
3298 pos
= IT_STRING_CHARPOS (*it
);
3299 pos_byte
= IT_STRING_BYTEPOS (*it
);
3300 string
= it
->string
;
3304 pos
= IT_CHARPOS (*it
);
3305 pos_byte
= IT_BYTEPOS (*it
);
3309 /* If there's a valid composition and point is not inside of the
3310 composition (in the case that the composition is from the current
3311 buffer), draw a glyph composed from the composition components. */
3312 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3313 && COMPOSITION_VALID_P (pos
, end
, prop
)
3314 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3316 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3320 it
->method
= next_element_from_composition
;
3322 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3323 /* For a terminal, draw only the first character of the
3325 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3326 it
->len
= (STRINGP (it
->string
)
3327 ? string_char_to_byte (it
->string
, end
)
3328 : CHAR_TO_BYTE (end
)) - pos_byte
;
3329 it
->stop_charpos
= end
;
3330 handled
= HANDLED_RETURN
;
3339 /***********************************************************************
3341 ***********************************************************************/
3343 /* The following structure is used to record overlay strings for
3344 later sorting in load_overlay_strings. */
3346 struct overlay_entry
3348 Lisp_Object overlay
;
3355 /* Set up iterator IT from overlay strings at its current position.
3356 Called from handle_stop. */
3358 static enum prop_handled
3359 handle_overlay_change (it
)
3362 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3363 return HANDLED_RECOMPUTE_PROPS
;
3365 return HANDLED_NORMALLY
;
3369 /* Set up the next overlay string for delivery by IT, if there is an
3370 overlay string to deliver. Called by set_iterator_to_next when the
3371 end of the current overlay string is reached. If there are more
3372 overlay strings to display, IT->string and
3373 IT->current.overlay_string_index are set appropriately here.
3374 Otherwise IT->string is set to nil. */
3377 next_overlay_string (it
)
3380 ++it
->current
.overlay_string_index
;
3381 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3383 /* No more overlay strings. Restore IT's settings to what
3384 they were before overlay strings were processed, and
3385 continue to deliver from current_buffer. */
3386 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3389 xassert (it
->stop_charpos
>= BEGV
3390 && it
->stop_charpos
<= it
->end_charpos
);
3392 it
->current
.overlay_string_index
= -1;
3393 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3394 it
->n_overlay_strings
= 0;
3395 it
->method
= next_element_from_buffer
;
3397 /* If we're at the end of the buffer, record that we have
3398 processed the overlay strings there already, so that
3399 next_element_from_buffer doesn't try it again. */
3400 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3401 it
->overlay_strings_at_end_processed_p
= 1;
3403 /* If we have to display `...' for invisible text, set
3404 the iterator up for that. */
3405 if (display_ellipsis_p
)
3406 setup_for_ellipsis (it
);
3410 /* There are more overlay strings to process. If
3411 IT->current.overlay_string_index has advanced to a position
3412 where we must load IT->overlay_strings with more strings, do
3414 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3416 if (it
->current
.overlay_string_index
&& i
== 0)
3417 load_overlay_strings (it
, 0);
3419 /* Initialize IT to deliver display elements from the overlay
3421 it
->string
= it
->overlay_strings
[i
];
3422 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3423 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3424 it
->method
= next_element_from_string
;
3425 it
->stop_charpos
= 0;
3432 /* Compare two overlay_entry structures E1 and E2. Used as a
3433 comparison function for qsort in load_overlay_strings. Overlay
3434 strings for the same position are sorted so that
3436 1. All after-strings come in front of before-strings, except
3437 when they come from the same overlay.
3439 2. Within after-strings, strings are sorted so that overlay strings
3440 from overlays with higher priorities come first.
3442 2. Within before-strings, strings are sorted so that overlay
3443 strings from overlays with higher priorities come last.
3445 Value is analogous to strcmp. */
3449 compare_overlay_entries (e1
, e2
)
3452 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3453 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3456 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3458 /* Let after-strings appear in front of before-strings if
3459 they come from different overlays. */
3460 if (EQ (entry1
->overlay
, entry2
->overlay
))
3461 result
= entry1
->after_string_p
? 1 : -1;
3463 result
= entry1
->after_string_p
? -1 : 1;
3465 else if (entry1
->after_string_p
)
3466 /* After-strings sorted in order of decreasing priority. */
3467 result
= entry2
->priority
- entry1
->priority
;
3469 /* Before-strings sorted in order of increasing priority. */
3470 result
= entry1
->priority
- entry2
->priority
;
3476 /* Load the vector IT->overlay_strings with overlay strings from IT's
3477 current buffer position, or from CHARPOS if that is > 0. Set
3478 IT->n_overlays to the total number of overlay strings found.
3480 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3481 a time. On entry into load_overlay_strings,
3482 IT->current.overlay_string_index gives the number of overlay
3483 strings that have already been loaded by previous calls to this
3486 IT->add_overlay_start contains an additional overlay start
3487 position to consider for taking overlay strings from, if non-zero.
3488 This position comes into play when the overlay has an `invisible'
3489 property, and both before and after-strings. When we've skipped to
3490 the end of the overlay, because of its `invisible' property, we
3491 nevertheless want its before-string to appear.
3492 IT->add_overlay_start will contain the overlay start position
3495 Overlay strings are sorted so that after-string strings come in
3496 front of before-string strings. Within before and after-strings,
3497 strings are sorted by overlay priority. See also function
3498 compare_overlay_entries. */
3501 load_overlay_strings (it
, charpos
)
3505 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3506 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3509 int n
= 0, i
, j
, invis_p
;
3510 struct overlay_entry
*entries
3511 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3514 charpos
= IT_CHARPOS (*it
);
3516 /* Append the overlay string STRING of overlay OVERLAY to vector
3517 `entries' which has size `size' and currently contains `n'
3518 elements. AFTER_P non-zero means STRING is an after-string of
3520 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3523 Lisp_Object priority; \
3527 int new_size = 2 * size; \
3528 struct overlay_entry *old = entries; \
3530 (struct overlay_entry *) alloca (new_size \
3531 * sizeof *entries); \
3532 bcopy (old, entries, size * sizeof *entries); \
3536 entries[n].string = (STRING); \
3537 entries[n].overlay = (OVERLAY); \
3538 priority = Foverlay_get ((OVERLAY), Qpriority); \
3539 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3540 entries[n].after_string_p = (AFTER_P); \
3545 /* Process overlay before the overlay center. */
3546 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3548 overlay
= XCAR (ov
);
3549 xassert (OVERLAYP (overlay
));
3550 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3551 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3556 /* Skip this overlay if it doesn't start or end at IT's current
3558 if (end
!= charpos
&& start
!= charpos
)
3561 /* Skip this overlay if it doesn't apply to IT->w. */
3562 window
= Foverlay_get (overlay
, Qwindow
);
3563 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3566 /* If the text ``under'' the overlay is invisible, both before-
3567 and after-strings from this overlay are visible; start and
3568 end position are indistinguishable. */
3569 invisible
= Foverlay_get (overlay
, Qinvisible
);
3570 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3572 /* If overlay has a non-empty before-string, record it. */
3573 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3574 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3576 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3578 /* If overlay has a non-empty after-string, record it. */
3579 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3580 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3582 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3585 /* Process overlays after the overlay center. */
3586 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3588 overlay
= XCAR (ov
);
3589 xassert (OVERLAYP (overlay
));
3590 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3591 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3593 if (start
> charpos
)
3596 /* Skip this overlay if it doesn't start or end at IT's current
3598 if (end
!= charpos
&& start
!= charpos
)
3601 /* Skip this overlay if it doesn't apply to IT->w. */
3602 window
= Foverlay_get (overlay
, Qwindow
);
3603 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3606 /* If the text ``under'' the overlay is invisible, it has a zero
3607 dimension, and both before- and after-strings apply. */
3608 invisible
= Foverlay_get (overlay
, Qinvisible
);
3609 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3611 /* If overlay has a non-empty before-string, record it. */
3612 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3613 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3615 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3617 /* If overlay has a non-empty after-string, record it. */
3618 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3619 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3621 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3624 #undef RECORD_OVERLAY_STRING
3628 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3630 /* Record the total number of strings to process. */
3631 it
->n_overlay_strings
= n
;
3633 /* IT->current.overlay_string_index is the number of overlay strings
3634 that have already been consumed by IT. Copy some of the
3635 remaining overlay strings to IT->overlay_strings. */
3637 j
= it
->current
.overlay_string_index
;
3638 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3639 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3645 /* Get the first chunk of overlay strings at IT's current buffer
3646 position, or at CHARPOS if that is > 0. Value is non-zero if at
3647 least one overlay string was found. */
3650 get_overlay_strings (it
, charpos
)
3654 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3655 process. This fills IT->overlay_strings with strings, and sets
3656 IT->n_overlay_strings to the total number of strings to process.
3657 IT->pos.overlay_string_index has to be set temporarily to zero
3658 because load_overlay_strings needs this; it must be set to -1
3659 when no overlay strings are found because a zero value would
3660 indicate a position in the first overlay string. */
3661 it
->current
.overlay_string_index
= 0;
3662 load_overlay_strings (it
, charpos
);
3664 /* If we found overlay strings, set up IT to deliver display
3665 elements from the first one. Otherwise set up IT to deliver
3666 from current_buffer. */
3667 if (it
->n_overlay_strings
)
3669 /* Make sure we know settings in current_buffer, so that we can
3670 restore meaningful values when we're done with the overlay
3672 compute_stop_pos (it
);
3673 xassert (it
->face_id
>= 0);
3675 /* Save IT's settings. They are restored after all overlay
3676 strings have been processed. */
3677 xassert (it
->sp
== 0);
3680 /* Set up IT to deliver display elements from the first overlay
3682 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3683 it
->string
= it
->overlay_strings
[0];
3684 it
->stop_charpos
= 0;
3685 xassert (STRINGP (it
->string
));
3686 it
->end_charpos
= SCHARS (it
->string
);
3687 it
->multibyte_p
= SMBP (it
->string
);
3688 it
->method
= next_element_from_string
;
3693 it
->current
.overlay_string_index
= -1;
3694 it
->method
= next_element_from_buffer
;
3699 /* Value is non-zero if we found at least one overlay string. */
3700 return STRINGP (it
->string
);
3705 /***********************************************************************
3706 Saving and restoring state
3707 ***********************************************************************/
3709 /* Save current settings of IT on IT->stack. Called, for example,
3710 before setting up IT for an overlay string, to be able to restore
3711 IT's settings to what they were after the overlay string has been
3718 struct iterator_stack_entry
*p
;
3720 xassert (it
->sp
< 2);
3721 p
= it
->stack
+ it
->sp
;
3723 p
->stop_charpos
= it
->stop_charpos
;
3724 xassert (it
->face_id
>= 0);
3725 p
->face_id
= it
->face_id
;
3726 p
->string
= it
->string
;
3727 p
->pos
= it
->current
;
3728 p
->end_charpos
= it
->end_charpos
;
3729 p
->string_nchars
= it
->string_nchars
;
3731 p
->multibyte_p
= it
->multibyte_p
;
3732 p
->space_width
= it
->space_width
;
3733 p
->font_height
= it
->font_height
;
3734 p
->voffset
= it
->voffset
;
3735 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3736 p
->display_ellipsis_p
= 0;
3741 /* Restore IT's settings from IT->stack. Called, for example, when no
3742 more overlay strings must be processed, and we return to delivering
3743 display elements from a buffer, or when the end of a string from a
3744 `display' property is reached and we return to delivering display
3745 elements from an overlay string, or from a buffer. */
3751 struct iterator_stack_entry
*p
;
3753 xassert (it
->sp
> 0);
3755 p
= it
->stack
+ it
->sp
;
3756 it
->stop_charpos
= p
->stop_charpos
;
3757 it
->face_id
= p
->face_id
;
3758 it
->string
= p
->string
;
3759 it
->current
= p
->pos
;
3760 it
->end_charpos
= p
->end_charpos
;
3761 it
->string_nchars
= p
->string_nchars
;
3763 it
->multibyte_p
= p
->multibyte_p
;
3764 it
->space_width
= p
->space_width
;
3765 it
->font_height
= p
->font_height
;
3766 it
->voffset
= p
->voffset
;
3767 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3772 /***********************************************************************
3774 ***********************************************************************/
3776 /* Set IT's current position to the previous line start. */
3779 back_to_previous_line_start (it
)
3782 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3783 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3787 /* Move IT to the next line start.
3789 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3790 we skipped over part of the text (as opposed to moving the iterator
3791 continuously over the text). Otherwise, don't change the value
3794 Newlines may come from buffer text, overlay strings, or strings
3795 displayed via the `display' property. That's the reason we can't
3796 simply use find_next_newline_no_quit.
3798 Note that this function may not skip over invisible text that is so
3799 because of text properties and immediately follows a newline. If
3800 it would, function reseat_at_next_visible_line_start, when called
3801 from set_iterator_to_next, would effectively make invisible
3802 characters following a newline part of the wrong glyph row, which
3803 leads to wrong cursor motion. */
3806 forward_to_next_line_start (it
, skipped_p
)
3810 int old_selective
, newline_found_p
, n
;
3811 const int MAX_NEWLINE_DISTANCE
= 500;
3813 /* If already on a newline, just consume it to avoid unintended
3814 skipping over invisible text below. */
3815 if (it
->what
== IT_CHARACTER
3817 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3819 set_iterator_to_next (it
, 0);
3824 /* Don't handle selective display in the following. It's (a)
3825 unnecessary because it's done by the caller, and (b) leads to an
3826 infinite recursion because next_element_from_ellipsis indirectly
3827 calls this function. */
3828 old_selective
= it
->selective
;
3831 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3832 from buffer text. */
3833 for (n
= newline_found_p
= 0;
3834 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3835 n
+= STRINGP (it
->string
) ? 0 : 1)
3837 if (!get_next_display_element (it
))
3839 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3840 set_iterator_to_next (it
, 0);
3843 /* If we didn't find a newline near enough, see if we can use a
3845 if (n
== MAX_NEWLINE_DISTANCE
)
3847 int start
= IT_CHARPOS (*it
);
3848 int limit
= find_next_newline_no_quit (start
, 1);
3851 xassert (!STRINGP (it
->string
));
3853 /* If there isn't any `display' property in sight, and no
3854 overlays, we can just use the position of the newline in
3856 if (it
->stop_charpos
>= limit
3857 || ((pos
= Fnext_single_property_change (make_number (start
),
3859 Qnil
, make_number (limit
)),
3861 && next_overlay_change (start
) == ZV
))
3863 IT_CHARPOS (*it
) = limit
;
3864 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3865 *skipped_p
= newline_found_p
= 1;
3869 while (get_next_display_element (it
)
3870 && !newline_found_p
)
3872 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3873 set_iterator_to_next (it
, 0);
3878 it
->selective
= old_selective
;
3879 return newline_found_p
;
3883 /* Set IT's current position to the previous visible line start. Skip
3884 invisible text that is so either due to text properties or due to
3885 selective display. Caution: this does not change IT->current_x and
3889 back_to_previous_visible_line_start (it
)
3894 /* Go back one newline if not on BEGV already. */
3895 if (IT_CHARPOS (*it
) > BEGV
)
3896 back_to_previous_line_start (it
);
3898 /* Move over lines that are invisible because of selective display
3899 or text properties. */
3900 while (IT_CHARPOS (*it
) > BEGV
3905 /* If selective > 0, then lines indented more than that values
3907 if (it
->selective
> 0
3908 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3915 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3916 Qinvisible
, it
->window
);
3917 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3921 /* Back one more newline if the current one is invisible. */
3923 back_to_previous_line_start (it
);
3926 xassert (IT_CHARPOS (*it
) >= BEGV
);
3927 xassert (IT_CHARPOS (*it
) == BEGV
3928 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3933 /* Reseat iterator IT at the previous visible line start. Skip
3934 invisible text that is so either due to text properties or due to
3935 selective display. At the end, update IT's overlay information,
3936 face information etc. */
3939 reseat_at_previous_visible_line_start (it
)
3942 back_to_previous_visible_line_start (it
);
3943 reseat (it
, it
->current
.pos
, 1);
3948 /* Reseat iterator IT on the next visible line start in the current
3949 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3950 preceding the line start. Skip over invisible text that is so
3951 because of selective display. Compute faces, overlays etc at the
3952 new position. Note that this function does not skip over text that
3953 is invisible because of text properties. */
3956 reseat_at_next_visible_line_start (it
, on_newline_p
)
3960 int newline_found_p
, skipped_p
= 0;
3962 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3964 /* Skip over lines that are invisible because they are indented
3965 more than the value of IT->selective. */
3966 if (it
->selective
> 0)
3967 while (IT_CHARPOS (*it
) < ZV
3968 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3971 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3972 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3975 /* Position on the newline if that's what's requested. */
3976 if (on_newline_p
&& newline_found_p
)
3978 if (STRINGP (it
->string
))
3980 if (IT_STRING_CHARPOS (*it
) > 0)
3982 --IT_STRING_CHARPOS (*it
);
3983 --IT_STRING_BYTEPOS (*it
);
3986 else if (IT_CHARPOS (*it
) > BEGV
)
3990 reseat (it
, it
->current
.pos
, 0);
3994 reseat (it
, it
->current
.pos
, 0);
4001 /***********************************************************************
4002 Changing an iterator's position
4003 ***********************************************************************/
4005 /* Change IT's current position to POS in current_buffer. If FORCE_P
4006 is non-zero, always check for text properties at the new position.
4007 Otherwise, text properties are only looked up if POS >=
4008 IT->check_charpos of a property. */
4011 reseat (it
, pos
, force_p
)
4013 struct text_pos pos
;
4016 int original_pos
= IT_CHARPOS (*it
);
4018 reseat_1 (it
, pos
, 0);
4020 /* Determine where to check text properties. Avoid doing it
4021 where possible because text property lookup is very expensive. */
4023 || CHARPOS (pos
) > it
->stop_charpos
4024 || CHARPOS (pos
) < original_pos
)
4031 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4032 IT->stop_pos to POS, also. */
4035 reseat_1 (it
, pos
, set_stop_p
)
4037 struct text_pos pos
;
4040 /* Don't call this function when scanning a C string. */
4041 xassert (it
->s
== NULL
);
4043 /* POS must be a reasonable value. */
4044 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4046 it
->current
.pos
= it
->position
= pos
;
4047 XSETBUFFER (it
->object
, current_buffer
);
4048 it
->end_charpos
= ZV
;
4050 it
->current
.dpvec_index
= -1;
4051 it
->current
.overlay_string_index
= -1;
4052 IT_STRING_CHARPOS (*it
) = -1;
4053 IT_STRING_BYTEPOS (*it
) = -1;
4055 it
->method
= next_element_from_buffer
;
4056 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4058 it
->face_before_selective_p
= 0;
4061 it
->stop_charpos
= CHARPOS (pos
);
4065 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4066 If S is non-null, it is a C string to iterate over. Otherwise,
4067 STRING gives a Lisp string to iterate over.
4069 If PRECISION > 0, don't return more then PRECISION number of
4070 characters from the string.
4072 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4073 characters have been returned. FIELD_WIDTH < 0 means an infinite
4076 MULTIBYTE = 0 means disable processing of multibyte characters,
4077 MULTIBYTE > 0 means enable it,
4078 MULTIBYTE < 0 means use IT->multibyte_p.
4080 IT must be initialized via a prior call to init_iterator before
4081 calling this function. */
4084 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4089 int precision
, field_width
, multibyte
;
4091 /* No region in strings. */
4092 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4094 /* No text property checks performed by default, but see below. */
4095 it
->stop_charpos
= -1;
4097 /* Set iterator position and end position. */
4098 bzero (&it
->current
, sizeof it
->current
);
4099 it
->current
.overlay_string_index
= -1;
4100 it
->current
.dpvec_index
= -1;
4101 xassert (charpos
>= 0);
4103 /* If STRING is specified, use its multibyteness, otherwise use the
4104 setting of MULTIBYTE, if specified. */
4106 it
->multibyte_p
= multibyte
> 0;
4110 xassert (STRINGP (string
));
4111 it
->string
= string
;
4113 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4114 it
->method
= next_element_from_string
;
4115 it
->current
.string_pos
= string_pos (charpos
, string
);
4122 /* Note that we use IT->current.pos, not it->current.string_pos,
4123 for displaying C strings. */
4124 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4125 if (it
->multibyte_p
)
4127 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4128 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4132 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4133 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4136 it
->method
= next_element_from_c_string
;
4139 /* PRECISION > 0 means don't return more than PRECISION characters
4141 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4142 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4144 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4145 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4146 FIELD_WIDTH < 0 means infinite field width. This is useful for
4147 padding with `-' at the end of a mode line. */
4148 if (field_width
< 0)
4149 field_width
= INFINITY
;
4150 if (field_width
> it
->end_charpos
- charpos
)
4151 it
->end_charpos
= charpos
+ field_width
;
4153 /* Use the standard display table for displaying strings. */
4154 if (DISP_TABLE_P (Vstandard_display_table
))
4155 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4157 it
->stop_charpos
= charpos
;
4163 /***********************************************************************
4165 ***********************************************************************/
4167 /* Load IT's display element fields with information about the next
4168 display element from the current position of IT. Value is zero if
4169 end of buffer (or C string) is reached. */
4172 get_next_display_element (it
)
4175 /* Non-zero means that we found an display element. Zero means that
4176 we hit the end of what we iterate over. Performance note: the
4177 function pointer `method' used here turns out to be faster than
4178 using a sequence of if-statements. */
4179 int success_p
= (*it
->method
) (it
);
4181 if (it
->what
== IT_CHARACTER
)
4183 /* Map via display table or translate control characters.
4184 IT->c, IT->len etc. have been set to the next character by
4185 the function call above. If we have a display table, and it
4186 contains an entry for IT->c, translate it. Don't do this if
4187 IT->c itself comes from a display table, otherwise we could
4188 end up in an infinite recursion. (An alternative could be to
4189 count the recursion depth of this function and signal an
4190 error when a certain maximum depth is reached.) Is it worth
4192 if (success_p
&& it
->dpvec
== NULL
)
4197 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4200 struct Lisp_Vector
*v
= XVECTOR (dv
);
4202 /* Return the first character from the display table
4203 entry, if not empty. If empty, don't display the
4204 current character. */
4207 it
->dpvec_char_len
= it
->len
;
4208 it
->dpvec
= v
->contents
;
4209 it
->dpend
= v
->contents
+ v
->size
;
4210 it
->current
.dpvec_index
= 0;
4211 it
->method
= next_element_from_display_vector
;
4212 success_p
= get_next_display_element (it
);
4216 set_iterator_to_next (it
, 0);
4217 success_p
= get_next_display_element (it
);
4221 /* Translate control characters into `\003' or `^C' form.
4222 Control characters coming from a display table entry are
4223 currently not translated because we use IT->dpvec to hold
4224 the translation. This could easily be changed but I
4225 don't believe that it is worth doing.
4227 Non-printable multibyte characters are also translated
4229 else if ((it
->c
< ' '
4230 && (it
->area
!= TEXT_AREA
4231 || (it
->c
!= '\n' && it
->c
!= '\t')))
4234 || !CHAR_PRINTABLE_P (it
->c
))
4236 /* IT->c is a control character which must be displayed
4237 either as '\003' or as `^C' where the '\\' and '^'
4238 can be defined in the display table. Fill
4239 IT->ctl_chars with glyphs for what we have to
4240 display. Then, set IT->dpvec to these glyphs. */
4243 if (it
->c
< 128 && it
->ctl_arrow_p
)
4245 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4247 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4248 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4249 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4251 g
= FAST_MAKE_GLYPH ('^', 0);
4252 XSETINT (it
->ctl_chars
[0], g
);
4254 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4255 XSETINT (it
->ctl_chars
[1], g
);
4257 /* Set up IT->dpvec and return first character from it. */
4258 it
->dpvec_char_len
= it
->len
;
4259 it
->dpvec
= it
->ctl_chars
;
4260 it
->dpend
= it
->dpvec
+ 2;
4261 it
->current
.dpvec_index
= 0;
4262 it
->method
= next_element_from_display_vector
;
4263 get_next_display_element (it
);
4267 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4272 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4274 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4275 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4276 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4278 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4280 if (SINGLE_BYTE_CHAR_P (it
->c
))
4281 str
[0] = it
->c
, len
= 1;
4284 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4287 /* It's an invalid character, which
4288 shouldn't happen actually, but due to
4289 bugs it may happen. Let's print the char
4290 as is, there's not much meaningful we can
4293 str
[1] = it
->c
>> 8;
4294 str
[2] = it
->c
>> 16;
4295 str
[3] = it
->c
>> 24;
4300 for (i
= 0; i
< len
; i
++)
4302 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4303 /* Insert three more glyphs into IT->ctl_chars for
4304 the octal display of the character. */
4305 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4306 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4307 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4308 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4309 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4310 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4313 /* Set up IT->dpvec and return the first character
4315 it
->dpvec_char_len
= it
->len
;
4316 it
->dpvec
= it
->ctl_chars
;
4317 it
->dpend
= it
->dpvec
+ len
* 4;
4318 it
->current
.dpvec_index
= 0;
4319 it
->method
= next_element_from_display_vector
;
4320 get_next_display_element (it
);
4325 /* Adjust face id for a multibyte character. There are no
4326 multibyte character in unibyte text. */
4329 && FRAME_WINDOW_P (it
->f
))
4331 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4332 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4336 /* Is this character the last one of a run of characters with
4337 box? If yes, set IT->end_of_box_run_p to 1. */
4344 it
->end_of_box_run_p
4345 = ((face_id
= face_after_it_pos (it
),
4346 face_id
!= it
->face_id
)
4347 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4348 face
->box
== FACE_NO_BOX
));
4351 /* Value is 0 if end of buffer or string reached. */
4356 /* Move IT to the next display element.
4358 RESEAT_P non-zero means if called on a newline in buffer text,
4359 skip to the next visible line start.
4361 Functions get_next_display_element and set_iterator_to_next are
4362 separate because I find this arrangement easier to handle than a
4363 get_next_display_element function that also increments IT's
4364 position. The way it is we can first look at an iterator's current
4365 display element, decide whether it fits on a line, and if it does,
4366 increment the iterator position. The other way around we probably
4367 would either need a flag indicating whether the iterator has to be
4368 incremented the next time, or we would have to implement a
4369 decrement position function which would not be easy to write. */
4372 set_iterator_to_next (it
, reseat_p
)
4376 /* Reset flags indicating start and end of a sequence of characters
4377 with box. Reset them at the start of this function because
4378 moving the iterator to a new position might set them. */
4379 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4381 if (it
->method
== next_element_from_buffer
)
4383 /* The current display element of IT is a character from
4384 current_buffer. Advance in the buffer, and maybe skip over
4385 invisible lines that are so because of selective display. */
4386 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4387 reseat_at_next_visible_line_start (it
, 0);
4390 xassert (it
->len
!= 0);
4391 IT_BYTEPOS (*it
) += it
->len
;
4392 IT_CHARPOS (*it
) += 1;
4393 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4396 else if (it
->method
== next_element_from_composition
)
4398 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4399 if (STRINGP (it
->string
))
4401 IT_STRING_BYTEPOS (*it
) += it
->len
;
4402 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4403 it
->method
= next_element_from_string
;
4404 goto consider_string_end
;
4408 IT_BYTEPOS (*it
) += it
->len
;
4409 IT_CHARPOS (*it
) += it
->cmp_len
;
4410 it
->method
= next_element_from_buffer
;
4413 else if (it
->method
== next_element_from_c_string
)
4415 /* Current display element of IT is from a C string. */
4416 IT_BYTEPOS (*it
) += it
->len
;
4417 IT_CHARPOS (*it
) += 1;
4419 else if (it
->method
== next_element_from_display_vector
)
4421 /* Current display element of IT is from a display table entry.
4422 Advance in the display table definition. Reset it to null if
4423 end reached, and continue with characters from buffers/
4425 ++it
->current
.dpvec_index
;
4427 /* Restore face of the iterator to what they were before the
4428 display vector entry (these entries may contain faces). */
4429 it
->face_id
= it
->saved_face_id
;
4431 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4434 it
->method
= next_element_from_c_string
;
4435 else if (STRINGP (it
->string
))
4436 it
->method
= next_element_from_string
;
4438 it
->method
= next_element_from_buffer
;
4441 it
->current
.dpvec_index
= -1;
4443 /* Skip over characters which were displayed via IT->dpvec. */
4444 if (it
->dpvec_char_len
< 0)
4445 reseat_at_next_visible_line_start (it
, 1);
4446 else if (it
->dpvec_char_len
> 0)
4448 it
->len
= it
->dpvec_char_len
;
4449 set_iterator_to_next (it
, reseat_p
);
4453 else if (it
->method
== next_element_from_string
)
4455 /* Current display element is a character from a Lisp string. */
4456 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4457 IT_STRING_BYTEPOS (*it
) += it
->len
;
4458 IT_STRING_CHARPOS (*it
) += 1;
4460 consider_string_end
:
4462 if (it
->current
.overlay_string_index
>= 0)
4464 /* IT->string is an overlay string. Advance to the
4465 next, if there is one. */
4466 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4467 next_overlay_string (it
);
4471 /* IT->string is not an overlay string. If we reached
4472 its end, and there is something on IT->stack, proceed
4473 with what is on the stack. This can be either another
4474 string, this time an overlay string, or a buffer. */
4475 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4479 if (!STRINGP (it
->string
))
4480 it
->method
= next_element_from_buffer
;
4482 goto consider_string_end
;
4486 else if (it
->method
== next_element_from_image
4487 || it
->method
== next_element_from_stretch
)
4489 /* The position etc with which we have to proceed are on
4490 the stack. The position may be at the end of a string,
4491 if the `display' property takes up the whole string. */
4494 if (STRINGP (it
->string
))
4496 it
->method
= next_element_from_string
;
4497 goto consider_string_end
;
4500 it
->method
= next_element_from_buffer
;
4503 /* There are no other methods defined, so this should be a bug. */
4506 xassert (it
->method
!= next_element_from_string
4507 || (STRINGP (it
->string
)
4508 && IT_STRING_CHARPOS (*it
) >= 0));
4512 /* Load IT's display element fields with information about the next
4513 display element which comes from a display table entry or from the
4514 result of translating a control character to one of the forms `^C'
4515 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4518 next_element_from_display_vector (it
)
4522 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4524 /* Remember the current face id in case glyphs specify faces.
4525 IT's face is restored in set_iterator_to_next. */
4526 it
->saved_face_id
= it
->face_id
;
4528 if (INTEGERP (*it
->dpvec
)
4529 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4534 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4535 it
->c
= FAST_GLYPH_CHAR (g
);
4536 it
->len
= CHAR_BYTES (it
->c
);
4538 /* The entry may contain a face id to use. Such a face id is
4539 the id of a Lisp face, not a realized face. A face id of
4540 zero means no face is specified. */
4541 lface_id
= FAST_GLYPH_FACE (g
);
4544 /* The function returns -1 if lface_id is invalid. */
4545 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4547 it
->face_id
= face_id
;
4551 /* Display table entry is invalid. Return a space. */
4552 it
->c
= ' ', it
->len
= 1;
4554 /* Don't change position and object of the iterator here. They are
4555 still the values of the character that had this display table
4556 entry or was translated, and that's what we want. */
4557 it
->what
= IT_CHARACTER
;
4562 /* Load IT with the next display element from Lisp string IT->string.
4563 IT->current.string_pos is the current position within the string.
4564 If IT->current.overlay_string_index >= 0, the Lisp string is an
4568 next_element_from_string (it
)
4571 struct text_pos position
;
4573 xassert (STRINGP (it
->string
));
4574 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4575 position
= it
->current
.string_pos
;
4577 /* Time to check for invisible text? */
4578 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4579 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4583 /* Since a handler may have changed IT->method, we must
4585 return get_next_display_element (it
);
4588 if (it
->current
.overlay_string_index
>= 0)
4590 /* Get the next character from an overlay string. In overlay
4591 strings, There is no field width or padding with spaces to
4593 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4598 else if (STRING_MULTIBYTE (it
->string
))
4600 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4601 unsigned char *s
= SDATA (it
->string
) + IT_STRING_BYTEPOS (*it
);
4602 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4606 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4612 /* Get the next character from a Lisp string that is not an
4613 overlay string. Such strings come from the mode line, for
4614 example. We may have to pad with spaces, or truncate the
4615 string. See also next_element_from_c_string. */
4616 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4621 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4623 /* Pad with spaces. */
4624 it
->c
= ' ', it
->len
= 1;
4625 CHARPOS (position
) = BYTEPOS (position
) = -1;
4627 else if (STRING_MULTIBYTE (it
->string
))
4629 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4630 unsigned char *s
= SDATA (it
->string
) + IT_STRING_BYTEPOS (*it
);
4631 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4635 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4640 /* Record what we have and where it came from. Note that we store a
4641 buffer position in IT->position although it could arguably be a
4643 it
->what
= IT_CHARACTER
;
4644 it
->object
= it
->string
;
4645 it
->position
= position
;
4650 /* Load IT with next display element from C string IT->s.
4651 IT->string_nchars is the maximum number of characters to return
4652 from the string. IT->end_charpos may be greater than
4653 IT->string_nchars when this function is called, in which case we
4654 may have to return padding spaces. Value is zero if end of string
4655 reached, including padding spaces. */
4658 next_element_from_c_string (it
)
4664 it
->what
= IT_CHARACTER
;
4665 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4668 /* IT's position can be greater IT->string_nchars in case a field
4669 width or precision has been specified when the iterator was
4671 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4673 /* End of the game. */
4677 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4679 /* Pad with spaces. */
4680 it
->c
= ' ', it
->len
= 1;
4681 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4683 else if (it
->multibyte_p
)
4685 /* Implementation note: The calls to strlen apparently aren't a
4686 performance problem because there is no noticeable performance
4687 difference between Emacs running in unibyte or multibyte mode. */
4688 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4689 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4693 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4699 /* Set up IT to return characters from an ellipsis, if appropriate.
4700 The definition of the ellipsis glyphs may come from a display table
4701 entry. This function Fills IT with the first glyph from the
4702 ellipsis if an ellipsis is to be displayed. */
4705 next_element_from_ellipsis (it
)
4708 if (it
->selective_display_ellipsis_p
)
4710 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4712 /* Use the display table definition for `...'. Invalid glyphs
4713 will be handled by the method returning elements from dpvec. */
4714 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4715 it
->dpvec_char_len
= it
->len
;
4716 it
->dpvec
= v
->contents
;
4717 it
->dpend
= v
->contents
+ v
->size
;
4718 it
->current
.dpvec_index
= 0;
4719 it
->method
= next_element_from_display_vector
;
4723 /* Use default `...' which is stored in default_invis_vector. */
4724 it
->dpvec_char_len
= it
->len
;
4725 it
->dpvec
= default_invis_vector
;
4726 it
->dpend
= default_invis_vector
+ 3;
4727 it
->current
.dpvec_index
= 0;
4728 it
->method
= next_element_from_display_vector
;
4733 /* The face at the current position may be different from the
4734 face we find after the invisible text. Remember what it
4735 was in IT->saved_face_id, and signal that it's there by
4736 setting face_before_selective_p. */
4737 it
->saved_face_id
= it
->face_id
;
4738 it
->method
= next_element_from_buffer
;
4739 reseat_at_next_visible_line_start (it
, 1);
4740 it
->face_before_selective_p
= 1;
4743 return get_next_display_element (it
);
4747 /* Deliver an image display element. The iterator IT is already
4748 filled with image information (done in handle_display_prop). Value
4753 next_element_from_image (it
)
4756 it
->what
= IT_IMAGE
;
4761 /* Fill iterator IT with next display element from a stretch glyph
4762 property. IT->object is the value of the text property. Value is
4766 next_element_from_stretch (it
)
4769 it
->what
= IT_STRETCH
;
4774 /* Load IT with the next display element from current_buffer. Value
4775 is zero if end of buffer reached. IT->stop_charpos is the next
4776 position at which to stop and check for text properties or buffer
4780 next_element_from_buffer (it
)
4785 /* Check this assumption, otherwise, we would never enter the
4786 if-statement, below. */
4787 xassert (IT_CHARPOS (*it
) >= BEGV
4788 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4790 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4792 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4794 int overlay_strings_follow_p
;
4796 /* End of the game, except when overlay strings follow that
4797 haven't been returned yet. */
4798 if (it
->overlay_strings_at_end_processed_p
)
4799 overlay_strings_follow_p
= 0;
4802 it
->overlay_strings_at_end_processed_p
= 1;
4803 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4806 if (overlay_strings_follow_p
)
4807 success_p
= get_next_display_element (it
);
4811 it
->position
= it
->current
.pos
;
4818 return get_next_display_element (it
);
4823 /* No face changes, overlays etc. in sight, so just return a
4824 character from current_buffer. */
4827 /* Maybe run the redisplay end trigger hook. Performance note:
4828 This doesn't seem to cost measurable time. */
4829 if (it
->redisplay_end_trigger_charpos
4831 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4832 run_redisplay_end_trigger_hook (it
);
4834 /* Get the next character, maybe multibyte. */
4835 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4836 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4838 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4839 - IT_BYTEPOS (*it
));
4840 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4843 it
->c
= *p
, it
->len
= 1;
4845 /* Record what we have and where it came from. */
4846 it
->what
= IT_CHARACTER
;;
4847 it
->object
= it
->w
->buffer
;
4848 it
->position
= it
->current
.pos
;
4850 /* Normally we return the character found above, except when we
4851 really want to return an ellipsis for selective display. */
4856 /* A value of selective > 0 means hide lines indented more
4857 than that number of columns. */
4858 if (it
->selective
> 0
4859 && IT_CHARPOS (*it
) + 1 < ZV
4860 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4861 IT_BYTEPOS (*it
) + 1,
4864 success_p
= next_element_from_ellipsis (it
);
4865 it
->dpvec_char_len
= -1;
4868 else if (it
->c
== '\r' && it
->selective
== -1)
4870 /* A value of selective == -1 means that everything from the
4871 CR to the end of the line is invisible, with maybe an
4872 ellipsis displayed for it. */
4873 success_p
= next_element_from_ellipsis (it
);
4874 it
->dpvec_char_len
= -1;
4879 /* Value is zero if end of buffer reached. */
4880 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4885 /* Run the redisplay end trigger hook for IT. */
4888 run_redisplay_end_trigger_hook (it
)
4891 Lisp_Object args
[3];
4893 /* IT->glyph_row should be non-null, i.e. we should be actually
4894 displaying something, or otherwise we should not run the hook. */
4895 xassert (it
->glyph_row
);
4897 /* Set up hook arguments. */
4898 args
[0] = Qredisplay_end_trigger_functions
;
4899 args
[1] = it
->window
;
4900 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4901 it
->redisplay_end_trigger_charpos
= 0;
4903 /* Since we are *trying* to run these functions, don't try to run
4904 them again, even if they get an error. */
4905 it
->w
->redisplay_end_trigger
= Qnil
;
4906 Frun_hook_with_args (3, args
);
4908 /* Notice if it changed the face of the character we are on. */
4909 handle_face_prop (it
);
4913 /* Deliver a composition display element. The iterator IT is already
4914 filled with composition information (done in
4915 handle_composition_prop). Value is always 1. */
4918 next_element_from_composition (it
)
4921 it
->what
= IT_COMPOSITION
;
4922 it
->position
= (STRINGP (it
->string
)
4923 ? it
->current
.string_pos
4930 /***********************************************************************
4931 Moving an iterator without producing glyphs
4932 ***********************************************************************/
4934 /* Move iterator IT to a specified buffer or X position within one
4935 line on the display without producing glyphs.
4937 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4938 whichever is reached first.
4940 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4942 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4943 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4944 TO_X includes the amount by which a window is horizontally
4949 MOVE_POS_MATCH_OR_ZV
4950 - when TO_POS or ZV was reached.
4953 -when TO_X was reached before TO_POS or ZV were reached.
4956 - when we reached the end of the display area and the line must
4960 - when we reached the end of the display area and the line is
4964 - when we stopped at a line end, i.e. a newline or a CR and selective
4967 static enum move_it_result
4968 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4970 int to_charpos
, to_x
, op
;
4972 enum move_it_result result
= MOVE_UNDEFINED
;
4973 struct glyph_row
*saved_glyph_row
;
4975 /* Don't produce glyphs in produce_glyphs. */
4976 saved_glyph_row
= it
->glyph_row
;
4977 it
->glyph_row
= NULL
;
4981 int x
, i
, ascent
= 0, descent
= 0;
4983 /* Stop when ZV or TO_CHARPOS reached. */
4984 if (!get_next_display_element (it
)
4985 || ((op
& MOVE_TO_POS
) != 0
4986 && BUFFERP (it
->object
)
4987 && IT_CHARPOS (*it
) >= to_charpos
))
4989 result
= MOVE_POS_MATCH_OR_ZV
;
4993 /* The call to produce_glyphs will get the metrics of the
4994 display element IT is loaded with. We record in x the
4995 x-position before this display element in case it does not
4999 /* Remember the line height so far in case the next element doesn't
5001 if (!it
->truncate_lines_p
)
5003 ascent
= it
->max_ascent
;
5004 descent
= it
->max_descent
;
5007 PRODUCE_GLYPHS (it
);
5009 if (it
->area
!= TEXT_AREA
)
5011 set_iterator_to_next (it
, 1);
5015 /* The number of glyphs we get back in IT->nglyphs will normally
5016 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5017 character on a terminal frame, or (iii) a line end. For the
5018 second case, IT->nglyphs - 1 padding glyphs will be present
5019 (on X frames, there is only one glyph produced for a
5020 composite character.
5022 The behavior implemented below means, for continuation lines,
5023 that as many spaces of a TAB as fit on the current line are
5024 displayed there. For terminal frames, as many glyphs of a
5025 multi-glyph character are displayed in the current line, too.
5026 This is what the old redisplay code did, and we keep it that
5027 way. Under X, the whole shape of a complex character must
5028 fit on the line or it will be completely displayed in the
5031 Note that both for tabs and padding glyphs, all glyphs have
5035 /* More than one glyph or glyph doesn't fit on line. All
5036 glyphs have the same width. */
5037 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5040 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5042 new_x
= x
+ single_glyph_width
;
5044 /* We want to leave anything reaching TO_X to the caller. */
5045 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5048 result
= MOVE_X_REACHED
;
5051 else if (/* Lines are continued. */
5052 !it
->truncate_lines_p
5053 && (/* And glyph doesn't fit on the line. */
5054 new_x
> it
->last_visible_x
5055 /* Or it fits exactly and we're on a window
5057 || (new_x
== it
->last_visible_x
5058 && FRAME_WINDOW_P (it
->f
))))
5060 if (/* IT->hpos == 0 means the very first glyph
5061 doesn't fit on the line, e.g. a wide image. */
5063 || (new_x
== it
->last_visible_x
5064 && FRAME_WINDOW_P (it
->f
)))
5067 it
->current_x
= new_x
;
5068 if (i
== it
->nglyphs
- 1)
5069 set_iterator_to_next (it
, 1);
5074 it
->max_ascent
= ascent
;
5075 it
->max_descent
= descent
;
5078 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5080 result
= MOVE_LINE_CONTINUED
;
5083 else if (new_x
> it
->first_visible_x
)
5085 /* Glyph is visible. Increment number of glyphs that
5086 would be displayed. */
5091 /* Glyph is completely off the left margin of the display
5092 area. Nothing to do. */
5096 if (result
!= MOVE_UNDEFINED
)
5099 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5101 /* Stop when TO_X specified and reached. This check is
5102 necessary here because of lines consisting of a line end,
5103 only. The line end will not produce any glyphs and we
5104 would never get MOVE_X_REACHED. */
5105 xassert (it
->nglyphs
== 0);
5106 result
= MOVE_X_REACHED
;
5110 /* Is this a line end? If yes, we're done. */
5111 if (ITERATOR_AT_END_OF_LINE_P (it
))
5113 result
= MOVE_NEWLINE_OR_CR
;
5117 /* The current display element has been consumed. Advance
5119 set_iterator_to_next (it
, 1);
5121 /* Stop if lines are truncated and IT's current x-position is
5122 past the right edge of the window now. */
5123 if (it
->truncate_lines_p
5124 && it
->current_x
>= it
->last_visible_x
)
5126 result
= MOVE_LINE_TRUNCATED
;
5131 /* Restore the iterator settings altered at the beginning of this
5133 it
->glyph_row
= saved_glyph_row
;
5138 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5139 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5140 the description of enum move_operation_enum.
5142 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5143 screen line, this function will set IT to the next position >
5147 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5149 int to_charpos
, to_x
, to_y
, to_vpos
;
5152 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5158 if (op
& MOVE_TO_VPOS
)
5160 /* If no TO_CHARPOS and no TO_X specified, stop at the
5161 start of the line TO_VPOS. */
5162 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5164 if (it
->vpos
== to_vpos
)
5170 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5174 /* TO_VPOS >= 0 means stop at TO_X in the line at
5175 TO_VPOS, or at TO_POS, whichever comes first. */
5176 if (it
->vpos
== to_vpos
)
5182 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5184 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5189 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5191 /* We have reached TO_X but not in the line we want. */
5192 skip
= move_it_in_display_line_to (it
, to_charpos
,
5194 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5202 else if (op
& MOVE_TO_Y
)
5204 struct it it_backup
;
5206 /* TO_Y specified means stop at TO_X in the line containing
5207 TO_Y---or at TO_CHARPOS if this is reached first. The
5208 problem is that we can't really tell whether the line
5209 contains TO_Y before we have completely scanned it, and
5210 this may skip past TO_X. What we do is to first scan to
5213 If TO_X is not specified, use a TO_X of zero. The reason
5214 is to make the outcome of this function more predictable.
5215 If we didn't use TO_X == 0, we would stop at the end of
5216 the line which is probably not what a caller would expect
5218 skip
= move_it_in_display_line_to (it
, to_charpos
,
5222 | (op
& MOVE_TO_POS
)));
5224 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5225 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5231 /* If TO_X was reached, we would like to know whether TO_Y
5232 is in the line. This can only be said if we know the
5233 total line height which requires us to scan the rest of
5235 if (skip
== MOVE_X_REACHED
)
5238 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5239 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5241 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5244 /* Now, decide whether TO_Y is in this line. */
5245 line_height
= it
->max_ascent
+ it
->max_descent
;
5246 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5248 if (to_y
>= it
->current_y
5249 && to_y
< it
->current_y
+ line_height
)
5251 if (skip
== MOVE_X_REACHED
)
5252 /* If TO_Y is in this line and TO_X was reached above,
5253 we scanned too far. We have to restore IT's settings
5254 to the ones before skipping. */
5258 else if (skip
== MOVE_X_REACHED
)
5261 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5269 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5273 case MOVE_POS_MATCH_OR_ZV
:
5277 case MOVE_NEWLINE_OR_CR
:
5278 set_iterator_to_next (it
, 1);
5279 it
->continuation_lines_width
= 0;
5282 case MOVE_LINE_TRUNCATED
:
5283 it
->continuation_lines_width
= 0;
5284 reseat_at_next_visible_line_start (it
, 0);
5285 if ((op
& MOVE_TO_POS
) != 0
5286 && IT_CHARPOS (*it
) > to_charpos
)
5293 case MOVE_LINE_CONTINUED
:
5294 it
->continuation_lines_width
+= it
->current_x
;
5301 /* Reset/increment for the next run. */
5302 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5303 it
->current_x
= it
->hpos
= 0;
5304 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5306 last_height
= it
->max_ascent
+ it
->max_descent
;
5307 last_max_ascent
= it
->max_ascent
;
5308 it
->max_ascent
= it
->max_descent
= 0;
5313 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5317 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5319 If DY > 0, move IT backward at least that many pixels. DY = 0
5320 means move IT backward to the preceding line start or BEGV. This
5321 function may move over more than DY pixels if IT->current_y - DY
5322 ends up in the middle of a line; in this case IT->current_y will be
5323 set to the top of the line moved to. */
5326 move_it_vertically_backward (it
, dy
)
5332 int start_pos
= IT_CHARPOS (*it
);
5336 /* Estimate how many newlines we must move back. */
5337 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5339 /* Set the iterator's position that many lines back. */
5340 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5341 back_to_previous_visible_line_start (it
);
5343 /* Reseat the iterator here. When moving backward, we don't want
5344 reseat to skip forward over invisible text, set up the iterator
5345 to deliver from overlay strings at the new position etc. So,
5346 use reseat_1 here. */
5347 reseat_1 (it
, it
->current
.pos
, 1);
5349 /* We are now surely at a line start. */
5350 it
->current_x
= it
->hpos
= 0;
5352 /* Move forward and see what y-distance we moved. First move to the
5353 start of the next line so that we get its height. We need this
5354 height to be able to tell whether we reached the specified
5357 it2
.max_ascent
= it2
.max_descent
= 0;
5358 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5359 MOVE_TO_POS
| MOVE_TO_VPOS
);
5360 xassert (IT_CHARPOS (*it
) >= BEGV
);
5363 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5364 xassert (IT_CHARPOS (*it
) >= BEGV
);
5365 h
= it2
.current_y
- it
->current_y
;
5366 nlines
= it2
.vpos
- it
->vpos
;
5368 /* Correct IT's y and vpos position. */
5374 /* DY == 0 means move to the start of the screen line. The
5375 value of nlines is > 0 if continuation lines were involved. */
5377 move_it_by_lines (it
, nlines
, 1);
5378 xassert (IT_CHARPOS (*it
) <= start_pos
);
5382 /* The y-position we try to reach. Note that h has been
5383 subtracted in front of the if-statement. */
5384 int target_y
= it
->current_y
+ h
- dy
;
5385 int y0
= it3
.current_y
;
5386 int y1
= line_bottom_y (&it3
);
5387 int line_height
= y1
- y0
;
5389 /* If we did not reach target_y, try to move further backward if
5390 we can. If we moved too far backward, try to move forward. */
5391 if (target_y
< it
->current_y
5392 /* This is heuristic. In a window that's 3 lines high, with
5393 a line height of 13 pixels each, recentering with point
5394 on the bottom line will try to move -39/2 = 19 pixels
5395 backward. Try to avoid moving into the first line. */
5396 && it
->current_y
- target_y
> line_height
/ 3 * 2
5397 && IT_CHARPOS (*it
) > BEGV
)
5399 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5400 target_y
- it
->current_y
));
5401 move_it_vertically (it
, target_y
- it
->current_y
);
5402 xassert (IT_CHARPOS (*it
) >= BEGV
);
5404 else if (target_y
>= it
->current_y
+ line_height
5405 && IT_CHARPOS (*it
) < ZV
)
5407 /* Should move forward by at least one line, maybe more. */
5410 move_it_by_lines (it
, 1, 1);
5412 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5414 xassert (IT_CHARPOS (*it
) >= BEGV
);
5420 /* Move IT by a specified amount of pixel lines DY. DY negative means
5421 move backwards. DY = 0 means move to start of screen line. At the
5422 end, IT will be on the start of a screen line. */
5425 move_it_vertically (it
, dy
)
5430 move_it_vertically_backward (it
, -dy
);
5433 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5434 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5435 MOVE_TO_POS
| MOVE_TO_Y
);
5436 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5438 /* If buffer ends in ZV without a newline, move to the start of
5439 the line to satisfy the post-condition. */
5440 if (IT_CHARPOS (*it
) == ZV
5441 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5442 move_it_by_lines (it
, 0, 0);
5447 /* Move iterator IT past the end of the text line it is in. */
5450 move_it_past_eol (it
)
5453 enum move_it_result rc
;
5455 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5456 if (rc
== MOVE_NEWLINE_OR_CR
)
5457 set_iterator_to_next (it
, 0);
5461 #if 0 /* Currently not used. */
5463 /* Return non-zero if some text between buffer positions START_CHARPOS
5464 and END_CHARPOS is invisible. IT->window is the window for text
5468 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5470 int start_charpos
, end_charpos
;
5472 Lisp_Object prop
, limit
;
5473 int invisible_found_p
;
5475 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5477 /* Is text at START invisible? */
5478 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5480 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5481 invisible_found_p
= 1;
5484 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5486 make_number (end_charpos
));
5487 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5490 return invisible_found_p
;
5496 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5497 negative means move up. DVPOS == 0 means move to the start of the
5498 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5499 NEED_Y_P is zero, IT->current_y will be left unchanged.
5501 Further optimization ideas: If we would know that IT->f doesn't use
5502 a face with proportional font, we could be faster for
5503 truncate-lines nil. */
5506 move_it_by_lines (it
, dvpos
, need_y_p
)
5508 int dvpos
, need_y_p
;
5510 struct position pos
;
5512 if (!FRAME_WINDOW_P (it
->f
))
5514 struct text_pos textpos
;
5516 /* We can use vmotion on frames without proportional fonts. */
5517 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5518 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5519 reseat (it
, textpos
, 1);
5520 it
->vpos
+= pos
.vpos
;
5521 it
->current_y
+= pos
.vpos
;
5523 else if (dvpos
== 0)
5525 /* DVPOS == 0 means move to the start of the screen line. */
5526 move_it_vertically_backward (it
, 0);
5527 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5530 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5534 int start_charpos
, i
;
5536 /* Start at the beginning of the screen line containing IT's
5538 move_it_vertically_backward (it
, 0);
5540 /* Go back -DVPOS visible lines and reseat the iterator there. */
5541 start_charpos
= IT_CHARPOS (*it
);
5542 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5543 back_to_previous_visible_line_start (it
);
5544 reseat (it
, it
->current
.pos
, 1);
5545 it
->current_x
= it
->hpos
= 0;
5547 /* Above call may have moved too far if continuation lines
5548 are involved. Scan forward and see if it did. */
5550 it2
.vpos
= it2
.current_y
= 0;
5551 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5552 it
->vpos
-= it2
.vpos
;
5553 it
->current_y
-= it2
.current_y
;
5554 it
->current_x
= it
->hpos
= 0;
5556 /* If we moved too far, move IT some lines forward. */
5557 if (it2
.vpos
> -dvpos
)
5559 int delta
= it2
.vpos
+ dvpos
;
5560 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5567 /***********************************************************************
5569 ***********************************************************************/
5572 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5576 add_to_log (format
, arg1
, arg2
)
5578 Lisp_Object arg1
, arg2
;
5580 Lisp_Object args
[3];
5581 Lisp_Object msg
, fmt
;
5584 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5586 /* Do nothing if called asynchronously. Inserting text into
5587 a buffer may call after-change-functions and alike and
5588 that would means running Lisp asynchronously. */
5589 if (handling_signal
)
5593 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5595 args
[0] = fmt
= build_string (format
);
5598 msg
= Fformat (3, args
);
5600 len
= SBYTES (msg
) + 1;
5601 buffer
= (char *) alloca (len
);
5602 bcopy (SDATA (msg
), buffer
, len
);
5604 message_dolog (buffer
, len
- 1, 1, 0);
5609 /* Output a newline in the *Messages* buffer if "needs" one. */
5612 message_log_maybe_newline ()
5614 if (message_log_need_newline
)
5615 message_dolog ("", 0, 1, 0);
5619 /* Add a string M of length NBYTES to the message log, optionally
5620 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5621 nonzero, means interpret the contents of M as multibyte. This
5622 function calls low-level routines in order to bypass text property
5623 hooks, etc. which might not be safe to run. */
5626 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5628 int nbytes
, nlflag
, multibyte
;
5630 if (!NILP (Vmessage_log_max
))
5632 struct buffer
*oldbuf
;
5633 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5634 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5635 int point_at_end
= 0;
5637 Lisp_Object old_deactivate_mark
, tem
;
5638 struct gcpro gcpro1
;
5640 old_deactivate_mark
= Vdeactivate_mark
;
5641 oldbuf
= current_buffer
;
5642 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5643 current_buffer
->undo_list
= Qt
;
5645 oldpoint
= message_dolog_marker1
;
5646 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5647 oldbegv
= message_dolog_marker2
;
5648 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5649 oldzv
= message_dolog_marker3
;
5650 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5651 GCPRO1 (old_deactivate_mark
);
5659 BEGV_BYTE
= BEG_BYTE
;
5662 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5664 /* Insert the string--maybe converting multibyte to single byte
5665 or vice versa, so that all the text fits the buffer. */
5667 && NILP (current_buffer
->enable_multibyte_characters
))
5669 int i
, c
, char_bytes
;
5670 unsigned char work
[1];
5672 /* Convert a multibyte string to single-byte
5673 for the *Message* buffer. */
5674 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5676 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5677 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5679 : multibyte_char_to_unibyte (c
, Qnil
));
5680 insert_1_both (work
, 1, 1, 1, 0, 0);
5683 else if (! multibyte
5684 && ! NILP (current_buffer
->enable_multibyte_characters
))
5686 int i
, c
, char_bytes
;
5687 unsigned char *msg
= (unsigned char *) m
;
5688 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5689 /* Convert a single-byte string to multibyte
5690 for the *Message* buffer. */
5691 for (i
= 0; i
< nbytes
; i
++)
5693 c
= unibyte_char_to_multibyte (msg
[i
]);
5694 char_bytes
= CHAR_STRING (c
, str
);
5695 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5699 insert_1 (m
, nbytes
, 1, 0, 0);
5703 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5704 insert_1 ("\n", 1, 1, 0, 0);
5706 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5708 this_bol_byte
= PT_BYTE
;
5710 /* See if this line duplicates the previous one.
5711 If so, combine duplicates. */
5714 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5716 prev_bol_byte
= PT_BYTE
;
5718 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5719 this_bol
, this_bol_byte
);
5722 del_range_both (prev_bol
, prev_bol_byte
,
5723 this_bol
, this_bol_byte
, 0);
5729 /* If you change this format, don't forget to also
5730 change message_log_check_duplicate. */
5731 sprintf (dupstr
, " [%d times]", dup
);
5732 duplen
= strlen (dupstr
);
5733 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5734 insert_1 (dupstr
, duplen
, 1, 0, 1);
5739 /* If we have more than the desired maximum number of lines
5740 in the *Messages* buffer now, delete the oldest ones.
5741 This is safe because we don't have undo in this buffer. */
5743 if (NATNUMP (Vmessage_log_max
))
5745 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5746 -XFASTINT (Vmessage_log_max
) - 1, 0);
5747 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5750 BEGV
= XMARKER (oldbegv
)->charpos
;
5751 BEGV_BYTE
= marker_byte_position (oldbegv
);
5760 ZV
= XMARKER (oldzv
)->charpos
;
5761 ZV_BYTE
= marker_byte_position (oldzv
);
5765 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5767 /* We can't do Fgoto_char (oldpoint) because it will run some
5769 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5770 XMARKER (oldpoint
)->bytepos
);
5773 unchain_marker (oldpoint
);
5774 unchain_marker (oldbegv
);
5775 unchain_marker (oldzv
);
5777 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5778 set_buffer_internal (oldbuf
);
5780 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5781 message_log_need_newline
= !nlflag
;
5782 Vdeactivate_mark
= old_deactivate_mark
;
5787 /* We are at the end of the buffer after just having inserted a newline.
5788 (Note: We depend on the fact we won't be crossing the gap.)
5789 Check to see if the most recent message looks a lot like the previous one.
5790 Return 0 if different, 1 if the new one should just replace it, or a
5791 value N > 1 if we should also append " [N times]". */
5794 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5795 int prev_bol
, this_bol
;
5796 int prev_bol_byte
, this_bol_byte
;
5799 int len
= Z_BYTE
- 1 - this_bol_byte
;
5801 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5802 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5804 for (i
= 0; i
< len
; i
++)
5806 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5814 if (*p1
++ == ' ' && *p1
++ == '[')
5817 while (*p1
>= '0' && *p1
<= '9')
5818 n
= n
* 10 + *p1
++ - '0';
5819 if (strncmp (p1
, " times]\n", 8) == 0)
5826 /* Display an echo area message M with a specified length of NBYTES
5827 bytes. The string may include null characters. If M is 0, clear
5828 out any existing message, and let the mini-buffer text show
5831 The buffer M must continue to exist until after the echo area gets
5832 cleared or some other message gets displayed there. This means do
5833 not pass text that is stored in a Lisp string; do not pass text in
5834 a buffer that was alloca'd. */
5837 message2 (m
, nbytes
, multibyte
)
5842 /* First flush out any partial line written with print. */
5843 message_log_maybe_newline ();
5845 message_dolog (m
, nbytes
, 1, multibyte
);
5846 message2_nolog (m
, nbytes
, multibyte
);
5850 /* The non-logging counterpart of message2. */
5853 message2_nolog (m
, nbytes
, multibyte
)
5857 struct frame
*sf
= SELECTED_FRAME ();
5858 message_enable_multibyte
= multibyte
;
5862 if (noninteractive_need_newline
)
5863 putc ('\n', stderr
);
5864 noninteractive_need_newline
= 0;
5866 fwrite (m
, nbytes
, 1, stderr
);
5867 if (cursor_in_echo_area
== 0)
5868 fprintf (stderr
, "\n");
5871 /* A null message buffer means that the frame hasn't really been
5872 initialized yet. Error messages get reported properly by
5873 cmd_error, so this must be just an informative message; toss it. */
5874 else if (INTERACTIVE
5875 && sf
->glyphs_initialized_p
5876 && FRAME_MESSAGE_BUF (sf
))
5878 Lisp_Object mini_window
;
5881 /* Get the frame containing the mini-buffer
5882 that the selected frame is using. */
5883 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5884 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5886 FRAME_SAMPLE_VISIBILITY (f
);
5887 if (FRAME_VISIBLE_P (sf
)
5888 && ! FRAME_VISIBLE_P (f
))
5889 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5893 set_message (m
, Qnil
, nbytes
, multibyte
);
5894 if (minibuffer_auto_raise
)
5895 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5898 clear_message (1, 1);
5900 do_pending_window_change (0);
5901 echo_area_display (1);
5902 do_pending_window_change (0);
5903 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5904 (*frame_up_to_date_hook
) (f
);
5909 /* Display an echo area message M with a specified length of NBYTES
5910 bytes. The string may include null characters. If M is not a
5911 string, clear out any existing message, and let the mini-buffer
5912 text show through. */
5915 message3 (m
, nbytes
, multibyte
)
5920 struct gcpro gcpro1
;
5924 /* First flush out any partial line written with print. */
5925 message_log_maybe_newline ();
5927 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
5928 message3_nolog (m
, nbytes
, multibyte
);
5934 /* The non-logging version of message3. */
5937 message3_nolog (m
, nbytes
, multibyte
)
5939 int nbytes
, multibyte
;
5941 struct frame
*sf
= SELECTED_FRAME ();
5942 message_enable_multibyte
= multibyte
;
5946 if (noninteractive_need_newline
)
5947 putc ('\n', stderr
);
5948 noninteractive_need_newline
= 0;
5950 fwrite (SDATA (m
), nbytes
, 1, stderr
);
5951 if (cursor_in_echo_area
== 0)
5952 fprintf (stderr
, "\n");
5955 /* A null message buffer means that the frame hasn't really been
5956 initialized yet. Error messages get reported properly by
5957 cmd_error, so this must be just an informative message; toss it. */
5958 else if (INTERACTIVE
5959 && sf
->glyphs_initialized_p
5960 && FRAME_MESSAGE_BUF (sf
))
5962 Lisp_Object mini_window
;
5966 /* Get the frame containing the mini-buffer
5967 that the selected frame is using. */
5968 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5969 frame
= XWINDOW (mini_window
)->frame
;
5972 FRAME_SAMPLE_VISIBILITY (f
);
5973 if (FRAME_VISIBLE_P (sf
)
5974 && !FRAME_VISIBLE_P (f
))
5975 Fmake_frame_visible (frame
);
5977 if (STRINGP (m
) && SCHARS (m
) > 0)
5979 set_message (NULL
, m
, nbytes
, multibyte
);
5980 if (minibuffer_auto_raise
)
5981 Fraise_frame (frame
);
5984 clear_message (1, 1);
5986 do_pending_window_change (0);
5987 echo_area_display (1);
5988 do_pending_window_change (0);
5989 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5990 (*frame_up_to_date_hook
) (f
);
5995 /* Display a null-terminated echo area message M. If M is 0, clear
5996 out any existing message, and let the mini-buffer text show through.
5998 The buffer M must continue to exist until after the echo area gets
5999 cleared or some other message gets displayed there. Do not pass
6000 text that is stored in a Lisp string. Do not pass text in a buffer
6001 that was alloca'd. */
6007 message2 (m
, (m
? strlen (m
) : 0), 0);
6011 /* The non-logging counterpart of message1. */
6017 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6020 /* Display a message M which contains a single %s
6021 which gets replaced with STRING. */
6024 message_with_string (m
, string
, log
)
6033 if (noninteractive_need_newline
)
6034 putc ('\n', stderr
);
6035 noninteractive_need_newline
= 0;
6036 fprintf (stderr
, m
, SDATA (string
));
6037 if (cursor_in_echo_area
== 0)
6038 fprintf (stderr
, "\n");
6042 else if (INTERACTIVE
)
6044 /* The frame whose minibuffer we're going to display the message on.
6045 It may be larger than the selected frame, so we need
6046 to use its buffer, not the selected frame's buffer. */
6047 Lisp_Object mini_window
;
6048 struct frame
*f
, *sf
= SELECTED_FRAME ();
6050 /* Get the frame containing the minibuffer
6051 that the selected frame is using. */
6052 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6053 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6055 /* A null message buffer means that the frame hasn't really been
6056 initialized yet. Error messages get reported properly by
6057 cmd_error, so this must be just an informative message; toss it. */
6058 if (FRAME_MESSAGE_BUF (f
))
6060 Lisp_Object args
[2], message
;
6061 struct gcpro gcpro1
, gcpro2
;
6063 args
[0] = build_string (m
);
6064 args
[1] = message
= string
;
6065 GCPRO2 (args
, message
);
6068 message
= Fformat (2, args
);
6071 message3 (message
, SBYTES (message
), SMBP (message
));
6073 message3_nolog (message
, SBYTES (message
), SMBP (message
));
6077 /* Print should start at the beginning of the message
6078 buffer next time. */
6079 message_buf_print
= 0;
6085 /* Dump an informative message to the minibuf. If M is 0, clear out
6086 any existing message, and let the mini-buffer text show through. */
6090 message (m
, a1
, a2
, a3
)
6092 EMACS_INT a1
, a2
, a3
;
6098 if (noninteractive_need_newline
)
6099 putc ('\n', stderr
);
6100 noninteractive_need_newline
= 0;
6101 fprintf (stderr
, m
, a1
, a2
, a3
);
6102 if (cursor_in_echo_area
== 0)
6103 fprintf (stderr
, "\n");
6107 else if (INTERACTIVE
)
6109 /* The frame whose mini-buffer we're going to display the message
6110 on. It may be larger than the selected frame, so we need to
6111 use its buffer, not the selected frame's buffer. */
6112 Lisp_Object mini_window
;
6113 struct frame
*f
, *sf
= SELECTED_FRAME ();
6115 /* Get the frame containing the mini-buffer
6116 that the selected frame is using. */
6117 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6118 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6120 /* A null message buffer means that the frame hasn't really been
6121 initialized yet. Error messages get reported properly by
6122 cmd_error, so this must be just an informative message; toss
6124 if (FRAME_MESSAGE_BUF (f
))
6135 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6136 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6138 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6139 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6141 #endif /* NO_ARG_ARRAY */
6143 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6148 /* Print should start at the beginning of the message
6149 buffer next time. */
6150 message_buf_print
= 0;
6156 /* The non-logging version of message. */
6159 message_nolog (m
, a1
, a2
, a3
)
6161 EMACS_INT a1
, a2
, a3
;
6163 Lisp_Object old_log_max
;
6164 old_log_max
= Vmessage_log_max
;
6165 Vmessage_log_max
= Qnil
;
6166 message (m
, a1
, a2
, a3
);
6167 Vmessage_log_max
= old_log_max
;
6171 /* Display the current message in the current mini-buffer. This is
6172 only called from error handlers in process.c, and is not time
6178 if (!NILP (echo_area_buffer
[0]))
6181 string
= Fcurrent_message ();
6182 message3 (string
, SBYTES (string
),
6183 !NILP (current_buffer
->enable_multibyte_characters
));
6188 /* Make sure echo area buffers in echo_buffers[] are life. If they
6189 aren't, make new ones. */
6192 ensure_echo_area_buffers ()
6196 for (i
= 0; i
< 2; ++i
)
6197 if (!BUFFERP (echo_buffer
[i
])
6198 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6201 Lisp_Object old_buffer
;
6204 old_buffer
= echo_buffer
[i
];
6205 sprintf (name
, " *Echo Area %d*", i
);
6206 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6207 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6209 for (j
= 0; j
< 2; ++j
)
6210 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6211 echo_area_buffer
[j
] = echo_buffer
[i
];
6216 /* Call FN with args A1..A4 with either the current or last displayed
6217 echo_area_buffer as current buffer.
6219 WHICH zero means use the current message buffer
6220 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6221 from echo_buffer[] and clear it.
6223 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6224 suitable buffer from echo_buffer[] and clear it.
6226 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6227 that the current message becomes the last displayed one, make
6228 choose a suitable buffer for echo_area_buffer[0], and clear it.
6230 Value is what FN returns. */
6233 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6236 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6242 int this_one
, the_other
, clear_buffer_p
, rc
;
6243 int count
= BINDING_STACK_SIZE ();
6245 /* If buffers aren't life, make new ones. */
6246 ensure_echo_area_buffers ();
6251 this_one
= 0, the_other
= 1;
6253 this_one
= 1, the_other
= 0;
6256 this_one
= 0, the_other
= 1;
6259 /* We need a fresh one in case the current echo buffer equals
6260 the one containing the last displayed echo area message. */
6261 if (!NILP (echo_area_buffer
[this_one
])
6262 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6263 echo_area_buffer
[this_one
] = Qnil
;
6266 /* Choose a suitable buffer from echo_buffer[] is we don't
6268 if (NILP (echo_area_buffer
[this_one
]))
6270 echo_area_buffer
[this_one
]
6271 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6272 ? echo_buffer
[the_other
]
6273 : echo_buffer
[this_one
]);
6277 buffer
= echo_area_buffer
[this_one
];
6279 /* Don't get confused by reusing the buffer used for echoing
6280 for a different purpose. */
6281 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6284 record_unwind_protect (unwind_with_echo_area_buffer
,
6285 with_echo_area_buffer_unwind_data (w
));
6287 /* Make the echo area buffer current. Note that for display
6288 purposes, it is not necessary that the displayed window's buffer
6289 == current_buffer, except for text property lookup. So, let's
6290 only set that buffer temporarily here without doing a full
6291 Fset_window_buffer. We must also change w->pointm, though,
6292 because otherwise an assertions in unshow_buffer fails, and Emacs
6294 set_buffer_internal_1 (XBUFFER (buffer
));
6298 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6301 current_buffer
->undo_list
= Qt
;
6302 current_buffer
->read_only
= Qnil
;
6303 specbind (Qinhibit_read_only
, Qt
);
6304 specbind (Qinhibit_modification_hooks
, Qt
);
6306 if (clear_buffer_p
&& Z
> BEG
)
6309 xassert (BEGV
>= BEG
);
6310 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6312 rc
= fn (a1
, a2
, a3
, a4
);
6314 xassert (BEGV
>= BEG
);
6315 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6317 unbind_to (count
, Qnil
);
6322 /* Save state that should be preserved around the call to the function
6323 FN called in with_echo_area_buffer. */
6326 with_echo_area_buffer_unwind_data (w
)
6332 /* Reduce consing by keeping one vector in
6333 Vwith_echo_area_save_vector. */
6334 vector
= Vwith_echo_area_save_vector
;
6335 Vwith_echo_area_save_vector
= Qnil
;
6338 vector
= Fmake_vector (make_number (7), Qnil
);
6340 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6341 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6342 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6346 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6347 AREF (vector
, i
) = w
->buffer
; ++i
;
6348 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6349 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6354 for (; i
< end
; ++i
)
6355 AREF (vector
, i
) = Qnil
;
6358 xassert (i
== ASIZE (vector
));
6363 /* Restore global state from VECTOR which was created by
6364 with_echo_area_buffer_unwind_data. */
6367 unwind_with_echo_area_buffer (vector
)
6370 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6371 Vdeactivate_mark
= AREF (vector
, 1);
6372 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6374 if (WINDOWP (AREF (vector
, 3)))
6377 Lisp_Object buffer
, charpos
, bytepos
;
6379 w
= XWINDOW (AREF (vector
, 3));
6380 buffer
= AREF (vector
, 4);
6381 charpos
= AREF (vector
, 5);
6382 bytepos
= AREF (vector
, 6);
6385 set_marker_both (w
->pointm
, buffer
,
6386 XFASTINT (charpos
), XFASTINT (bytepos
));
6389 Vwith_echo_area_save_vector
= vector
;
6394 /* Set up the echo area for use by print functions. MULTIBYTE_P
6395 non-zero means we will print multibyte. */
6398 setup_echo_area_for_printing (multibyte_p
)
6401 ensure_echo_area_buffers ();
6403 if (!message_buf_print
)
6405 /* A message has been output since the last time we printed.
6406 Choose a fresh echo area buffer. */
6407 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6408 echo_area_buffer
[0] = echo_buffer
[1];
6410 echo_area_buffer
[0] = echo_buffer
[0];
6412 /* Switch to that buffer and clear it. */
6413 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6414 current_buffer
->truncate_lines
= Qnil
;
6418 int count
= BINDING_STACK_SIZE ();
6419 specbind (Qinhibit_read_only
, Qt
);
6421 unbind_to (count
, Qnil
);
6423 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6425 /* Set up the buffer for the multibyteness we need. */
6427 != !NILP (current_buffer
->enable_multibyte_characters
))
6428 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6430 /* Raise the frame containing the echo area. */
6431 if (minibuffer_auto_raise
)
6433 struct frame
*sf
= SELECTED_FRAME ();
6434 Lisp_Object mini_window
;
6435 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6436 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6439 message_log_maybe_newline ();
6440 message_buf_print
= 1;
6444 if (NILP (echo_area_buffer
[0]))
6446 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6447 echo_area_buffer
[0] = echo_buffer
[1];
6449 echo_area_buffer
[0] = echo_buffer
[0];
6452 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6454 /* Someone switched buffers between print requests. */
6455 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6456 current_buffer
->truncate_lines
= Qnil
;
6462 /* Display an echo area message in window W. Value is non-zero if W's
6463 height is changed. If display_last_displayed_message_p is
6464 non-zero, display the message that was last displayed, otherwise
6465 display the current message. */
6468 display_echo_area (w
)
6471 int i
, no_message_p
, window_height_changed_p
, count
;
6473 /* Temporarily disable garbage collections while displaying the echo
6474 area. This is done because a GC can print a message itself.
6475 That message would modify the echo area buffer's contents while a
6476 redisplay of the buffer is going on, and seriously confuse
6478 count
= inhibit_garbage_collection ();
6480 /* If there is no message, we must call display_echo_area_1
6481 nevertheless because it resizes the window. But we will have to
6482 reset the echo_area_buffer in question to nil at the end because
6483 with_echo_area_buffer will sets it to an empty buffer. */
6484 i
= display_last_displayed_message_p
? 1 : 0;
6485 no_message_p
= NILP (echo_area_buffer
[i
]);
6487 window_height_changed_p
6488 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6489 display_echo_area_1
,
6490 (EMACS_INT
) w
, Qnil
, 0, 0);
6493 echo_area_buffer
[i
] = Qnil
;
6495 unbind_to (count
, Qnil
);
6496 return window_height_changed_p
;
6500 /* Helper for display_echo_area. Display the current buffer which
6501 contains the current echo area message in window W, a mini-window,
6502 a pointer to which is passed in A1. A2..A4 are currently not used.
6503 Change the height of W so that all of the message is displayed.
6504 Value is non-zero if height of W was changed. */
6507 display_echo_area_1 (a1
, a2
, a3
, a4
)
6512 struct window
*w
= (struct window
*) a1
;
6514 struct text_pos start
;
6515 int window_height_changed_p
= 0;
6517 /* Do this before displaying, so that we have a large enough glyph
6518 matrix for the display. */
6519 window_height_changed_p
= resize_mini_window (w
, 0);
6522 clear_glyph_matrix (w
->desired_matrix
);
6523 XSETWINDOW (window
, w
);
6524 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6525 try_window (window
, start
);
6527 return window_height_changed_p
;
6531 /* Resize the echo area window to exactly the size needed for the
6532 currently displayed message, if there is one. If a mini-buffer
6533 is active, don't shrink it. */
6536 resize_echo_area_exactly ()
6538 if (BUFFERP (echo_area_buffer
[0])
6539 && WINDOWP (echo_area_window
))
6541 struct window
*w
= XWINDOW (echo_area_window
);
6543 Lisp_Object resize_exactly
;
6545 if (minibuf_level
== 0)
6546 resize_exactly
= Qt
;
6548 resize_exactly
= Qnil
;
6550 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6551 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6554 ++windows_or_buffers_changed
;
6555 ++update_mode_lines
;
6556 redisplay_internal (0);
6562 /* Callback function for with_echo_area_buffer, when used from
6563 resize_echo_area_exactly. A1 contains a pointer to the window to
6564 resize, EXACTLY non-nil means resize the mini-window exactly to the
6565 size of the text displayed. A3 and A4 are not used. Value is what
6566 resize_mini_window returns. */
6569 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6571 Lisp_Object exactly
;
6574 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6578 /* Resize mini-window W to fit the size of its contents. EXACT:P
6579 means size the window exactly to the size needed. Otherwise, it's
6580 only enlarged until W's buffer is empty. Value is non-zero if
6581 the window height has been changed. */
6584 resize_mini_window (w
, exact_p
)
6588 struct frame
*f
= XFRAME (w
->frame
);
6589 int window_height_changed_p
= 0;
6591 xassert (MINI_WINDOW_P (w
));
6593 /* Don't resize windows while redisplaying a window; it would
6594 confuse redisplay functions when the size of the window they are
6595 displaying changes from under them. Such a resizing can happen,
6596 for instance, when which-func prints a long message while
6597 we are running fontification-functions. We're running these
6598 functions with safe_call which binds inhibit-redisplay to t. */
6599 if (!NILP (Vinhibit_redisplay
))
6602 /* Nil means don't try to resize. */
6603 if (NILP (Vresize_mini_windows
)
6604 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6607 if (!FRAME_MINIBUF_ONLY_P (f
))
6610 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6611 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6612 int height
, max_height
;
6613 int unit
= CANON_Y_UNIT (f
);
6614 struct text_pos start
;
6615 struct buffer
*old_current_buffer
= NULL
;
6617 if (current_buffer
!= XBUFFER (w
->buffer
))
6619 old_current_buffer
= current_buffer
;
6620 set_buffer_internal (XBUFFER (w
->buffer
));
6623 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6625 /* Compute the max. number of lines specified by the user. */
6626 if (FLOATP (Vmax_mini_window_height
))
6627 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6628 else if (INTEGERP (Vmax_mini_window_height
))
6629 max_height
= XINT (Vmax_mini_window_height
);
6631 max_height
= total_height
/ 4;
6633 /* Correct that max. height if it's bogus. */
6634 max_height
= max (1, max_height
);
6635 max_height
= min (total_height
, max_height
);
6637 /* Find out the height of the text in the window. */
6638 if (it
.truncate_lines_p
)
6643 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6644 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6645 height
= it
.current_y
+ last_height
;
6647 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6648 height
-= it
.extra_line_spacing
;
6649 height
= (height
+ unit
- 1) / unit
;
6652 /* Compute a suitable window start. */
6653 if (height
> max_height
)
6655 height
= max_height
;
6656 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6657 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6658 start
= it
.current
.pos
;
6661 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6662 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6664 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6666 /* Let it grow only, until we display an empty message, in which
6667 case the window shrinks again. */
6668 if (height
> XFASTINT (w
->height
))
6670 int old_height
= XFASTINT (w
->height
);
6671 freeze_window_starts (f
, 1);
6672 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6673 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6675 else if (height
< XFASTINT (w
->height
)
6676 && (exact_p
|| BEGV
== ZV
))
6678 int old_height
= XFASTINT (w
->height
);
6679 freeze_window_starts (f
, 0);
6680 shrink_mini_window (w
);
6681 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6686 /* Always resize to exact size needed. */
6687 if (height
> XFASTINT (w
->height
))
6689 int old_height
= XFASTINT (w
->height
);
6690 freeze_window_starts (f
, 1);
6691 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6692 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6694 else if (height
< XFASTINT (w
->height
))
6696 int old_height
= XFASTINT (w
->height
);
6697 freeze_window_starts (f
, 0);
6698 shrink_mini_window (w
);
6702 freeze_window_starts (f
, 1);
6703 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6706 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6710 if (old_current_buffer
)
6711 set_buffer_internal (old_current_buffer
);
6714 return window_height_changed_p
;
6718 /* Value is the current message, a string, or nil if there is no
6726 if (NILP (echo_area_buffer
[0]))
6730 with_echo_area_buffer (0, 0, current_message_1
,
6731 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6733 echo_area_buffer
[0] = Qnil
;
6741 current_message_1 (a1
, a2
, a3
, a4
)
6746 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6749 *msg
= make_buffer_string (BEG
, Z
, 1);
6756 /* Push the current message on Vmessage_stack for later restauration
6757 by restore_message. Value is non-zero if the current message isn't
6758 empty. This is a relatively infrequent operation, so it's not
6759 worth optimizing. */
6765 msg
= current_message ();
6766 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6767 return STRINGP (msg
);
6771 /* Handler for record_unwind_protect calling pop_message. */
6774 push_message_unwind (dummy
)
6782 /* Restore message display from the top of Vmessage_stack. */
6789 xassert (CONSP (Vmessage_stack
));
6790 msg
= XCAR (Vmessage_stack
);
6792 message3_nolog (msg
, SBYTES (msg
), SMBP (msg
));
6794 message3_nolog (msg
, 0, 0);
6798 /* Pop the top-most entry off Vmessage_stack. */
6803 xassert (CONSP (Vmessage_stack
));
6804 Vmessage_stack
= XCDR (Vmessage_stack
);
6808 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6809 exits. If the stack is not empty, we have a missing pop_message
6813 check_message_stack ()
6815 if (!NILP (Vmessage_stack
))
6820 /* Truncate to NCHARS what will be displayed in the echo area the next
6821 time we display it---but don't redisplay it now. */
6824 truncate_echo_area (nchars
)
6828 echo_area_buffer
[0] = Qnil
;
6829 /* A null message buffer means that the frame hasn't really been
6830 initialized yet. Error messages get reported properly by
6831 cmd_error, so this must be just an informative message; toss it. */
6832 else if (!noninteractive
6834 && !NILP (echo_area_buffer
[0]))
6836 struct frame
*sf
= SELECTED_FRAME ();
6837 if (FRAME_MESSAGE_BUF (sf
))
6838 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6843 /* Helper function for truncate_echo_area. Truncate the current
6844 message to at most NCHARS characters. */
6847 truncate_message_1 (nchars
, a2
, a3
, a4
)
6852 if (BEG
+ nchars
< Z
)
6853 del_range (BEG
+ nchars
, Z
);
6855 echo_area_buffer
[0] = Qnil
;
6860 /* Set the current message to a substring of S or STRING.
6862 If STRING is a Lisp string, set the message to the first NBYTES
6863 bytes from STRING. NBYTES zero means use the whole string. If
6864 STRING is multibyte, the message will be displayed multibyte.
6866 If S is not null, set the message to the first LEN bytes of S. LEN
6867 zero means use the whole string. MULTIBYTE_P non-zero means S is
6868 multibyte. Display the message multibyte in that case. */
6871 set_message (s
, string
, nbytes
, multibyte_p
)
6876 message_enable_multibyte
6877 = ((s
&& multibyte_p
)
6878 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6880 with_echo_area_buffer (0, -1, set_message_1
,
6881 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6882 message_buf_print
= 0;
6883 help_echo_showing_p
= 0;
6887 /* Helper function for set_message. Arguments have the same meaning
6888 as there, with A1 corresponding to S and A2 corresponding to STRING
6889 This function is called with the echo area buffer being
6893 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6896 EMACS_INT nbytes
, multibyte_p
;
6898 char *s
= (char *) a1
;
6899 Lisp_Object string
= a2
;
6903 /* Change multibyteness of the echo buffer appropriately. */
6904 if (message_enable_multibyte
6905 != !NILP (current_buffer
->enable_multibyte_characters
))
6906 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6908 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6910 /* Insert new message at BEG. */
6911 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6913 if (STRINGP (string
))
6918 nbytes
= SBYTES (string
);
6919 nchars
= string_byte_to_char (string
, nbytes
);
6921 /* This function takes care of single/multibyte conversion. We
6922 just have to ensure that the echo area buffer has the right
6923 setting of enable_multibyte_characters. */
6924 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6929 nbytes
= strlen (s
);
6931 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6933 /* Convert from multi-byte to single-byte. */
6935 unsigned char work
[1];
6937 /* Convert a multibyte string to single-byte. */
6938 for (i
= 0; i
< nbytes
; i
+= n
)
6940 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6941 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6943 : multibyte_char_to_unibyte (c
, Qnil
));
6944 insert_1_both (work
, 1, 1, 1, 0, 0);
6947 else if (!multibyte_p
6948 && !NILP (current_buffer
->enable_multibyte_characters
))
6950 /* Convert from single-byte to multi-byte. */
6952 unsigned char *msg
= (unsigned char *) s
;
6953 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6955 /* Convert a single-byte string to multibyte. */
6956 for (i
= 0; i
< nbytes
; i
++)
6958 c
= unibyte_char_to_multibyte (msg
[i
]);
6959 n
= CHAR_STRING (c
, str
);
6960 insert_1_both (str
, 1, n
, 1, 0, 0);
6964 insert_1 (s
, nbytes
, 1, 0, 0);
6971 /* Clear messages. CURRENT_P non-zero means clear the current
6972 message. LAST_DISPLAYED_P non-zero means clear the message
6976 clear_message (current_p
, last_displayed_p
)
6977 int current_p
, last_displayed_p
;
6981 echo_area_buffer
[0] = Qnil
;
6982 message_cleared_p
= 1;
6985 if (last_displayed_p
)
6986 echo_area_buffer
[1] = Qnil
;
6988 message_buf_print
= 0;
6991 /* Clear garbaged frames.
6993 This function is used where the old redisplay called
6994 redraw_garbaged_frames which in turn called redraw_frame which in
6995 turn called clear_frame. The call to clear_frame was a source of
6996 flickering. I believe a clear_frame is not necessary. It should
6997 suffice in the new redisplay to invalidate all current matrices,
6998 and ensure a complete redisplay of all windows. */
7001 clear_garbaged_frames ()
7005 Lisp_Object tail
, frame
;
7007 FOR_EACH_FRAME (tail
, frame
)
7009 struct frame
*f
= XFRAME (frame
);
7011 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7014 Fredraw_frame (frame
);
7015 clear_current_matrices (f
);
7022 ++windows_or_buffers_changed
;
7027 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7028 is non-zero update selected_frame. Value is non-zero if the
7029 mini-windows height has been changed. */
7032 echo_area_display (update_frame_p
)
7035 Lisp_Object mini_window
;
7038 int window_height_changed_p
= 0;
7039 struct frame
*sf
= SELECTED_FRAME ();
7041 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7042 w
= XWINDOW (mini_window
);
7043 f
= XFRAME (WINDOW_FRAME (w
));
7045 /* Don't display if frame is invisible or not yet initialized. */
7046 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7049 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7051 #ifdef HAVE_WINDOW_SYSTEM
7052 /* When Emacs starts, selected_frame may be a visible terminal
7053 frame, even if we run under a window system. If we let this
7054 through, a message would be displayed on the terminal. */
7055 if (EQ (selected_frame
, Vterminal_frame
)
7056 && !NILP (Vwindow_system
))
7058 #endif /* HAVE_WINDOW_SYSTEM */
7061 /* Redraw garbaged frames. */
7063 clear_garbaged_frames ();
7065 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7067 echo_area_window
= mini_window
;
7068 window_height_changed_p
= display_echo_area (w
);
7069 w
->must_be_updated_p
= 1;
7071 /* Update the display, unless called from redisplay_internal.
7072 Also don't update the screen during redisplay itself. The
7073 update will happen at the end of redisplay, and an update
7074 here could cause confusion. */
7075 if (update_frame_p
&& !redisplaying_p
)
7079 /* If the display update has been interrupted by pending
7080 input, update mode lines in the frame. Due to the
7081 pending input, it might have been that redisplay hasn't
7082 been called, so that mode lines above the echo area are
7083 garbaged. This looks odd, so we prevent it here. */
7084 if (!display_completed
)
7085 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7087 if (window_height_changed_p
7088 /* Don't do this if Emacs is shutting down. Redisplay
7089 needs to run hooks. */
7090 && !NILP (Vrun_hooks
))
7092 /* Must update other windows. Likewise as in other
7093 cases, don't let this update be interrupted by
7095 int count
= BINDING_STACK_SIZE ();
7096 specbind (Qredisplay_dont_pause
, Qt
);
7097 windows_or_buffers_changed
= 1;
7098 redisplay_internal (0);
7099 unbind_to (count
, Qnil
);
7101 else if (FRAME_WINDOW_P (f
) && n
== 0)
7103 /* Window configuration is the same as before.
7104 Can do with a display update of the echo area,
7105 unless we displayed some mode lines. */
7106 update_single_window (w
, 1);
7107 rif
->flush_display (f
);
7110 update_frame (f
, 1, 1);
7112 /* If cursor is in the echo area, make sure that the next
7113 redisplay displays the minibuffer, so that the cursor will
7114 be replaced with what the minibuffer wants. */
7115 if (cursor_in_echo_area
)
7116 ++windows_or_buffers_changed
;
7119 else if (!EQ (mini_window
, selected_window
))
7120 windows_or_buffers_changed
++;
7122 /* Last displayed message is now the current message. */
7123 echo_area_buffer
[1] = echo_area_buffer
[0];
7125 /* Prevent redisplay optimization in redisplay_internal by resetting
7126 this_line_start_pos. This is done because the mini-buffer now
7127 displays the message instead of its buffer text. */
7128 if (EQ (mini_window
, selected_window
))
7129 CHARPOS (this_line_start_pos
) = 0;
7131 return window_height_changed_p
;
7136 /***********************************************************************
7138 ***********************************************************************/
7141 #ifdef HAVE_WINDOW_SYSTEM
7143 /* A buffer for constructing frame titles in it; allocated from the
7144 heap in init_xdisp and resized as needed in store_frame_title_char. */
7146 static char *frame_title_buf
;
7148 /* The buffer's end, and a current output position in it. */
7150 static char *frame_title_buf_end
;
7151 static char *frame_title_ptr
;
7154 /* Store a single character C for the frame title in frame_title_buf.
7155 Re-allocate frame_title_buf if necessary. */
7158 store_frame_title_char (c
)
7161 /* If output position has reached the end of the allocated buffer,
7162 double the buffer's size. */
7163 if (frame_title_ptr
== frame_title_buf_end
)
7165 int len
= frame_title_ptr
- frame_title_buf
;
7166 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7167 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7168 frame_title_buf_end
= frame_title_buf
+ new_size
;
7169 frame_title_ptr
= frame_title_buf
+ len
;
7172 *frame_title_ptr
++ = c
;
7176 /* Store part of a frame title in frame_title_buf, beginning at
7177 frame_title_ptr. STR is the string to store. Do not copy
7178 characters that yield more columns than PRECISION; PRECISION <= 0
7179 means copy the whole string. Pad with spaces until FIELD_WIDTH
7180 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7181 pad. Called from display_mode_element when it is used to build a
7185 store_frame_title (str
, field_width
, precision
)
7187 int field_width
, precision
;
7192 /* Copy at most PRECISION chars from STR. */
7193 nbytes
= strlen (str
);
7194 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7196 store_frame_title_char (*str
++);
7198 /* Fill up with spaces until FIELD_WIDTH reached. */
7199 while (field_width
> 0
7202 store_frame_title_char (' ');
7210 /* Set the title of FRAME, if it has changed. The title format is
7211 Vicon_title_format if FRAME is iconified, otherwise it is
7212 frame_title_format. */
7215 x_consider_frame_title (frame
)
7218 struct frame
*f
= XFRAME (frame
);
7220 if (FRAME_WINDOW_P (f
)
7221 || FRAME_MINIBUF_ONLY_P (f
)
7222 || f
->explicit_name
)
7224 /* Do we have more than one visible frame on this X display? */
7227 struct buffer
*obuf
;
7231 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7233 Lisp_Object other_frame
= XCAR (tail
);
7234 struct frame
*tf
= XFRAME (other_frame
);
7237 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7238 && !FRAME_MINIBUF_ONLY_P (tf
)
7239 && !EQ (other_frame
, tip_frame
)
7240 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7244 /* Set global variable indicating that multiple frames exist. */
7245 multiple_frames
= CONSP (tail
);
7247 /* Switch to the buffer of selected window of the frame. Set up
7248 frame_title_ptr so that display_mode_element will output into it;
7249 then display the title. */
7250 obuf
= current_buffer
;
7251 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7252 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7253 frame_title_ptr
= frame_title_buf
;
7254 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7255 NULL
, DEFAULT_FACE_ID
);
7256 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
);
7257 len
= frame_title_ptr
- frame_title_buf
;
7258 frame_title_ptr
= NULL
;
7259 set_buffer_internal_1 (obuf
);
7261 /* Set the title only if it's changed. This avoids consing in
7262 the common case where it hasn't. (If it turns out that we've
7263 already wasted too much time by walking through the list with
7264 display_mode_element, then we might need to optimize at a
7265 higher level than this.) */
7266 if (! STRINGP (f
->name
)
7267 || SBYTES (f
->name
) != len
7268 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7269 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7273 #else /* not HAVE_WINDOW_SYSTEM */
7275 #define frame_title_ptr ((char *)0)
7276 #define store_frame_title(str, mincol, maxcol) 0
7278 #endif /* not HAVE_WINDOW_SYSTEM */
7283 /***********************************************************************
7285 ***********************************************************************/
7288 /* Prepare for redisplay by updating menu-bar item lists when
7289 appropriate. This can call eval. */
7292 prepare_menu_bars ()
7295 struct gcpro gcpro1
, gcpro2
;
7297 Lisp_Object tooltip_frame
;
7299 #ifdef HAVE_WINDOW_SYSTEM
7300 tooltip_frame
= tip_frame
;
7302 tooltip_frame
= Qnil
;
7305 /* Update all frame titles based on their buffer names, etc. We do
7306 this before the menu bars so that the buffer-menu will show the
7307 up-to-date frame titles. */
7308 #ifdef HAVE_WINDOW_SYSTEM
7309 if (windows_or_buffers_changed
|| update_mode_lines
)
7311 Lisp_Object tail
, frame
;
7313 FOR_EACH_FRAME (tail
, frame
)
7316 if (!EQ (frame
, tooltip_frame
)
7317 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7318 x_consider_frame_title (frame
);
7321 #endif /* HAVE_WINDOW_SYSTEM */
7323 /* Update the menu bar item lists, if appropriate. This has to be
7324 done before any actual redisplay or generation of display lines. */
7325 all_windows
= (update_mode_lines
7326 || buffer_shared
> 1
7327 || windows_or_buffers_changed
);
7330 Lisp_Object tail
, frame
;
7331 int count
= BINDING_STACK_SIZE ();
7333 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7335 FOR_EACH_FRAME (tail
, frame
)
7339 /* Ignore tooltip frame. */
7340 if (EQ (frame
, tooltip_frame
))
7343 /* If a window on this frame changed size, report that to
7344 the user and clear the size-change flag. */
7345 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7347 Lisp_Object functions
;
7349 /* Clear flag first in case we get an error below. */
7350 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7351 functions
= Vwindow_size_change_functions
;
7352 GCPRO2 (tail
, functions
);
7354 while (CONSP (functions
))
7356 call1 (XCAR (functions
), frame
);
7357 functions
= XCDR (functions
);
7363 update_menu_bar (f
, 0);
7364 #ifdef HAVE_WINDOW_SYSTEM
7365 update_tool_bar (f
, 0);
7370 unbind_to (count
, Qnil
);
7374 struct frame
*sf
= SELECTED_FRAME ();
7375 update_menu_bar (sf
, 1);
7376 #ifdef HAVE_WINDOW_SYSTEM
7377 update_tool_bar (sf
, 1);
7381 /* Motif needs this. See comment in xmenu.c. Turn it off when
7382 pending_menu_activation is not defined. */
7383 #ifdef USE_X_TOOLKIT
7384 pending_menu_activation
= 0;
7389 /* Update the menu bar item list for frame F. This has to be done
7390 before we start to fill in any display lines, because it can call
7393 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7396 update_menu_bar (f
, save_match_data
)
7398 int save_match_data
;
7401 register struct window
*w
;
7403 /* If called recursively during a menu update, do nothing. This can
7404 happen when, for instance, an activate-menubar-hook causes a
7406 if (inhibit_menubar_update
)
7409 window
= FRAME_SELECTED_WINDOW (f
);
7410 w
= XWINDOW (window
);
7412 if (update_mode_lines
)
7413 w
->update_mode_line
= Qt
;
7415 if (FRAME_WINDOW_P (f
)
7417 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7418 FRAME_EXTERNAL_MENU_BAR (f
)
7420 FRAME_MENU_BAR_LINES (f
) > 0
7422 : FRAME_MENU_BAR_LINES (f
) > 0)
7424 /* If the user has switched buffers or windows, we need to
7425 recompute to reflect the new bindings. But we'll
7426 recompute when update_mode_lines is set too; that means
7427 that people can use force-mode-line-update to request
7428 that the menu bar be recomputed. The adverse effect on
7429 the rest of the redisplay algorithm is about the same as
7430 windows_or_buffers_changed anyway. */
7431 if (windows_or_buffers_changed
7432 || !NILP (w
->update_mode_line
)
7433 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7434 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7435 != !NILP (w
->last_had_star
))
7436 || ((!NILP (Vtransient_mark_mode
)
7437 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7438 != !NILP (w
->region_showing
)))
7440 struct buffer
*prev
= current_buffer
;
7441 int count
= BINDING_STACK_SIZE ();
7443 specbind (Qinhibit_menubar_update
, Qt
);
7445 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7446 if (save_match_data
)
7447 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7448 if (NILP (Voverriding_local_map_menu_flag
))
7450 specbind (Qoverriding_terminal_local_map
, Qnil
);
7451 specbind (Qoverriding_local_map
, Qnil
);
7454 /* Run the Lucid hook. */
7455 safe_run_hooks (Qactivate_menubar_hook
);
7457 /* If it has changed current-menubar from previous value,
7458 really recompute the menu-bar from the value. */
7459 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7460 call0 (Qrecompute_lucid_menubar
);
7462 safe_run_hooks (Qmenu_bar_update_hook
);
7463 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7465 /* Redisplay the menu bar in case we changed it. */
7466 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7467 if (FRAME_WINDOW_P (f
)
7468 #if defined (macintosh)
7469 /* All frames on Mac OS share the same menubar. So only the
7470 selected frame should be allowed to set it. */
7471 && f
== SELECTED_FRAME ()
7474 set_frame_menubar (f
, 0, 0);
7476 /* On a terminal screen, the menu bar is an ordinary screen
7477 line, and this makes it get updated. */
7478 w
->update_mode_line
= Qt
;
7479 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7480 /* In the non-toolkit version, the menu bar is an ordinary screen
7481 line, and this makes it get updated. */
7482 w
->update_mode_line
= Qt
;
7483 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7485 unbind_to (count
, Qnil
);
7486 set_buffer_internal_1 (prev
);
7493 /***********************************************************************
7495 ***********************************************************************/
7497 #ifdef HAVE_WINDOW_SYSTEM
7499 /* Update the tool-bar item list for frame F. This has to be done
7500 before we start to fill in any display lines. Called from
7501 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7502 and restore it here. */
7505 update_tool_bar (f
, save_match_data
)
7507 int save_match_data
;
7509 if (WINDOWP (f
->tool_bar_window
)
7510 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7515 window
= FRAME_SELECTED_WINDOW (f
);
7516 w
= XWINDOW (window
);
7518 /* If the user has switched buffers or windows, we need to
7519 recompute to reflect the new bindings. But we'll
7520 recompute when update_mode_lines is set too; that means
7521 that people can use force-mode-line-update to request
7522 that the menu bar be recomputed. The adverse effect on
7523 the rest of the redisplay algorithm is about the same as
7524 windows_or_buffers_changed anyway. */
7525 if (windows_or_buffers_changed
7526 || !NILP (w
->update_mode_line
)
7527 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7528 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7529 != !NILP (w
->last_had_star
))
7530 || ((!NILP (Vtransient_mark_mode
)
7531 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7532 != !NILP (w
->region_showing
)))
7534 struct buffer
*prev
= current_buffer
;
7535 int count
= BINDING_STACK_SIZE ();
7537 /* Set current_buffer to the buffer of the selected
7538 window of the frame, so that we get the right local
7540 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7542 /* Save match data, if we must. */
7543 if (save_match_data
)
7544 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7546 /* Make sure that we don't accidentally use bogus keymaps. */
7547 if (NILP (Voverriding_local_map_menu_flag
))
7549 specbind (Qoverriding_terminal_local_map
, Qnil
);
7550 specbind (Qoverriding_local_map
, Qnil
);
7553 /* Build desired tool-bar items from keymaps. */
7555 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7557 /* Redisplay the tool-bar in case we changed it. */
7558 w
->update_mode_line
= Qt
;
7560 unbind_to (count
, Qnil
);
7561 set_buffer_internal_1 (prev
);
7567 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7568 F's desired tool-bar contents. F->tool_bar_items must have
7569 been set up previously by calling prepare_menu_bars. */
7572 build_desired_tool_bar_string (f
)
7575 int i
, size
, size_needed
;
7576 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7577 Lisp_Object image
, plist
, props
;
7579 image
= plist
= props
= Qnil
;
7580 GCPRO3 (image
, plist
, props
);
7582 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7583 Otherwise, make a new string. */
7585 /* The size of the string we might be able to reuse. */
7586 size
= (STRINGP (f
->desired_tool_bar_string
)
7587 ? SCHARS (f
->desired_tool_bar_string
)
7590 /* We need one space in the string for each image. */
7591 size_needed
= f
->n_tool_bar_items
;
7593 /* Reuse f->desired_tool_bar_string, if possible. */
7594 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7595 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7599 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7600 Fremove_text_properties (make_number (0), make_number (size
),
7601 props
, f
->desired_tool_bar_string
);
7604 /* Put a `display' property on the string for the images to display,
7605 put a `menu_item' property on tool-bar items with a value that
7606 is the index of the item in F's tool-bar item vector. */
7607 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7609 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7611 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7612 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7613 int hmargin
, vmargin
, relief
, idx
, end
;
7614 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7616 /* If image is a vector, choose the image according to the
7618 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7619 if (VECTORP (image
))
7623 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7624 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7627 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7628 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7630 xassert (ASIZE (image
) >= idx
);
7631 image
= AREF (image
, idx
);
7636 /* Ignore invalid image specifications. */
7637 if (!valid_image_p (image
))
7640 /* Display the tool-bar button pressed, or depressed. */
7641 plist
= Fcopy_sequence (XCDR (image
));
7643 /* Compute margin and relief to draw. */
7644 relief
= (tool_bar_button_relief
>= 0
7645 ? tool_bar_button_relief
7646 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7647 hmargin
= vmargin
= relief
;
7649 if (INTEGERP (Vtool_bar_button_margin
)
7650 && XINT (Vtool_bar_button_margin
) > 0)
7652 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7653 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7655 else if (CONSP (Vtool_bar_button_margin
))
7657 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7658 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7659 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7661 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7662 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7663 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7666 if (auto_raise_tool_bar_buttons_p
)
7668 /* Add a `:relief' property to the image spec if the item is
7672 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7679 /* If image is selected, display it pressed, i.e. with a
7680 negative relief. If it's not selected, display it with a
7682 plist
= Fplist_put (plist
, QCrelief
,
7684 ? make_number (-relief
)
7685 : make_number (relief
)));
7690 /* Put a margin around the image. */
7691 if (hmargin
|| vmargin
)
7693 if (hmargin
== vmargin
)
7694 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7696 plist
= Fplist_put (plist
, QCmargin
,
7697 Fcons (make_number (hmargin
),
7698 make_number (vmargin
)));
7701 /* If button is not enabled, and we don't have special images
7702 for the disabled state, make the image appear disabled by
7703 applying an appropriate algorithm to it. */
7704 if (!enabled_p
&& idx
< 0)
7705 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7707 /* Put a `display' text property on the string for the image to
7708 display. Put a `menu-item' property on the string that gives
7709 the start of this item's properties in the tool-bar items
7711 image
= Fcons (Qimage
, plist
);
7712 props
= list4 (Qdisplay
, image
,
7713 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7715 /* Let the last image hide all remaining spaces in the tool bar
7716 string. The string can be longer than needed when we reuse a
7718 if (i
+ 1 == f
->n_tool_bar_items
)
7719 end
= SCHARS (f
->desired_tool_bar_string
);
7722 Fadd_text_properties (make_number (i
), make_number (end
),
7723 props
, f
->desired_tool_bar_string
);
7731 /* Display one line of the tool-bar of frame IT->f. */
7734 display_tool_bar_line (it
)
7737 struct glyph_row
*row
= it
->glyph_row
;
7738 int max_x
= it
->last_visible_x
;
7741 prepare_desired_row (row
);
7742 row
->y
= it
->current_y
;
7744 /* Note that this isn't made use of if the face hasn't a box,
7745 so there's no need to check the face here. */
7746 it
->start_of_box_run_p
= 1;
7748 while (it
->current_x
< max_x
)
7750 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7752 /* Get the next display element. */
7753 if (!get_next_display_element (it
))
7756 /* Produce glyphs. */
7757 x_before
= it
->current_x
;
7758 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7759 PRODUCE_GLYPHS (it
);
7761 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7766 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7768 if (x
+ glyph
->pixel_width
> max_x
)
7770 /* Glyph doesn't fit on line. */
7771 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7777 x
+= glyph
->pixel_width
;
7781 /* Stop at line ends. */
7782 if (ITERATOR_AT_END_OF_LINE_P (it
))
7785 set_iterator_to_next (it
, 1);
7790 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7791 extend_face_to_end_of_line (it
);
7792 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7793 last
->right_box_line_p
= 1;
7794 if (last
== row
->glyphs
[TEXT_AREA
])
7795 last
->left_box_line_p
= 1;
7796 compute_line_metrics (it
);
7798 /* If line is empty, make it occupy the rest of the tool-bar. */
7799 if (!row
->displays_text_p
)
7801 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7802 row
->ascent
= row
->phys_ascent
= 0;
7805 row
->full_width_p
= 1;
7806 row
->continued_p
= 0;
7807 row
->truncated_on_left_p
= 0;
7808 row
->truncated_on_right_p
= 0;
7810 it
->current_x
= it
->hpos
= 0;
7811 it
->current_y
+= row
->height
;
7817 /* Value is the number of screen lines needed to make all tool-bar
7818 items of frame F visible. */
7821 tool_bar_lines_needed (f
)
7824 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7827 /* Initialize an iterator for iteration over
7828 F->desired_tool_bar_string in the tool-bar window of frame F. */
7829 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7830 it
.first_visible_x
= 0;
7831 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7832 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7834 while (!ITERATOR_AT_END_P (&it
))
7836 it
.glyph_row
= w
->desired_matrix
->rows
;
7837 clear_glyph_row (it
.glyph_row
);
7838 display_tool_bar_line (&it
);
7841 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7845 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7847 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7856 frame
= selected_frame
;
7858 CHECK_FRAME (frame
);
7861 if (WINDOWP (f
->tool_bar_window
)
7862 || (w
= XWINDOW (f
->tool_bar_window
),
7863 XFASTINT (w
->height
) > 0))
7865 update_tool_bar (f
, 1);
7866 if (f
->n_tool_bar_items
)
7868 build_desired_tool_bar_string (f
);
7869 nlines
= tool_bar_lines_needed (f
);
7873 return make_number (nlines
);
7877 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7878 height should be changed. */
7881 redisplay_tool_bar (f
)
7886 struct glyph_row
*row
;
7887 int change_height_p
= 0;
7889 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7890 do anything. This means you must start with tool-bar-lines
7891 non-zero to get the auto-sizing effect. Or in other words, you
7892 can turn off tool-bars by specifying tool-bar-lines zero. */
7893 if (!WINDOWP (f
->tool_bar_window
)
7894 || (w
= XWINDOW (f
->tool_bar_window
),
7895 XFASTINT (w
->height
) == 0))
7898 /* Set up an iterator for the tool-bar window. */
7899 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7900 it
.first_visible_x
= 0;
7901 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7904 /* Build a string that represents the contents of the tool-bar. */
7905 build_desired_tool_bar_string (f
);
7906 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7908 /* Display as many lines as needed to display all tool-bar items. */
7909 while (it
.current_y
< it
.last_visible_y
)
7910 display_tool_bar_line (&it
);
7912 /* It doesn't make much sense to try scrolling in the tool-bar
7913 window, so don't do it. */
7914 w
->desired_matrix
->no_scrolling_p
= 1;
7915 w
->must_be_updated_p
= 1;
7917 if (auto_resize_tool_bars_p
)
7921 /* If we couldn't display everything, change the tool-bar's
7923 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7924 change_height_p
= 1;
7926 /* If there are blank lines at the end, except for a partially
7927 visible blank line at the end that is smaller than
7928 CANON_Y_UNIT, change the tool-bar's height. */
7929 row
= it
.glyph_row
- 1;
7930 if (!row
->displays_text_p
7931 && row
->height
>= CANON_Y_UNIT (f
))
7932 change_height_p
= 1;
7934 /* If row displays tool-bar items, but is partially visible,
7935 change the tool-bar's height. */
7936 if (row
->displays_text_p
7937 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7938 change_height_p
= 1;
7940 /* Resize windows as needed by changing the `tool-bar-lines'
7943 && (nlines
= tool_bar_lines_needed (f
),
7944 nlines
!= XFASTINT (w
->height
)))
7946 extern Lisp_Object Qtool_bar_lines
;
7948 int old_height
= XFASTINT (w
->height
);
7950 XSETFRAME (frame
, f
);
7951 clear_glyph_matrix (w
->desired_matrix
);
7952 Fmodify_frame_parameters (frame
,
7953 Fcons (Fcons (Qtool_bar_lines
,
7954 make_number (nlines
)),
7956 if (XFASTINT (w
->height
) != old_height
)
7957 fonts_changed_p
= 1;
7961 return change_height_p
;
7965 /* Get information about the tool-bar item which is displayed in GLYPH
7966 on frame F. Return in *PROP_IDX the index where tool-bar item
7967 properties start in F->tool_bar_items. Value is zero if
7968 GLYPH doesn't display a tool-bar item. */
7971 tool_bar_item_info (f
, glyph
, prop_idx
)
7973 struct glyph
*glyph
;
7980 /* This function can be called asynchronously, which means we must
7981 exclude any possibility that Fget_text_property signals an
7983 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
7984 charpos
= max (0, charpos
);
7986 /* Get the text property `menu-item' at pos. The value of that
7987 property is the start index of this item's properties in
7988 F->tool_bar_items. */
7989 prop
= Fget_text_property (make_number (charpos
),
7990 Qmenu_item
, f
->current_tool_bar_string
);
7991 if (INTEGERP (prop
))
7993 *prop_idx
= XINT (prop
);
8002 #endif /* HAVE_WINDOW_SYSTEM */
8006 /************************************************************************
8007 Horizontal scrolling
8008 ************************************************************************/
8010 static int hscroll_window_tree
P_ ((Lisp_Object
));
8011 static int hscroll_windows
P_ ((Lisp_Object
));
8013 /* For all leaf windows in the window tree rooted at WINDOW, set their
8014 hscroll value so that PT is (i) visible in the window, and (ii) so
8015 that it is not within a certain margin at the window's left and
8016 right border. Value is non-zero if any window's hscroll has been
8020 hscroll_window_tree (window
)
8023 int hscrolled_p
= 0;
8024 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8025 int hscroll_step_abs
= 0;
8026 double hscroll_step_rel
= 0;
8028 if (hscroll_relative_p
)
8030 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8031 if (hscroll_step_rel
< 0)
8033 hscroll_relative_p
= 0;
8034 hscroll_step_abs
= 0;
8037 else if (INTEGERP (Vhscroll_step
))
8039 hscroll_step_abs
= XINT (Vhscroll_step
);
8040 if (hscroll_step_abs
< 0)
8041 hscroll_step_abs
= 0;
8044 hscroll_step_abs
= 0;
8046 while (WINDOWP (window
))
8048 struct window
*w
= XWINDOW (window
);
8050 if (WINDOWP (w
->hchild
))
8051 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8052 else if (WINDOWP (w
->vchild
))
8053 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8054 else if (w
->cursor
.vpos
>= 0)
8056 int h_margin
, text_area_x
, text_area_y
;
8057 int text_area_width
, text_area_height
;
8058 struct glyph_row
*current_cursor_row
8059 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8060 struct glyph_row
*desired_cursor_row
8061 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8062 struct glyph_row
*cursor_row
8063 = (desired_cursor_row
->enabled_p
8064 ? desired_cursor_row
8065 : current_cursor_row
);
8067 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8068 &text_area_width
, &text_area_height
);
8070 /* Scroll when cursor is inside this scroll margin. */
8071 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8073 if ((XFASTINT (w
->hscroll
)
8074 && w
->cursor
.x
<= h_margin
)
8075 || (cursor_row
->enabled_p
8076 && cursor_row
->truncated_on_right_p
8077 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8081 struct buffer
*saved_current_buffer
;
8085 /* Find point in a display of infinite width. */
8086 saved_current_buffer
= current_buffer
;
8087 current_buffer
= XBUFFER (w
->buffer
);
8089 if (w
== XWINDOW (selected_window
))
8090 pt
= BUF_PT (current_buffer
);
8093 pt
= marker_position (w
->pointm
);
8094 pt
= max (BEGV
, pt
);
8098 /* Move iterator to pt starting at cursor_row->start in
8099 a line with infinite width. */
8100 init_to_row_start (&it
, w
, cursor_row
);
8101 it
.last_visible_x
= INFINITY
;
8102 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8103 current_buffer
= saved_current_buffer
;
8105 /* Position cursor in window. */
8106 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8107 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8108 / CANON_X_UNIT (it
.f
);
8109 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8111 if (hscroll_relative_p
)
8112 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8115 wanted_x
= text_area_width
8116 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8119 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8123 if (hscroll_relative_p
)
8124 wanted_x
= text_area_width
* hscroll_step_rel
8127 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8130 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8132 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8134 /* Don't call Fset_window_hscroll if value hasn't
8135 changed because it will prevent redisplay
8137 if (XFASTINT (w
->hscroll
) != hscroll
)
8139 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8140 w
->hscroll
= make_number (hscroll
);
8149 /* Value is non-zero if hscroll of any leaf window has been changed. */
8154 /* Set hscroll so that cursor is visible and not inside horizontal
8155 scroll margins for all windows in the tree rooted at WINDOW. See
8156 also hscroll_window_tree above. Value is non-zero if any window's
8157 hscroll has been changed. If it has, desired matrices on the frame
8158 of WINDOW are cleared. */
8161 hscroll_windows (window
)
8166 if (automatic_hscrolling_p
)
8168 hscrolled_p
= hscroll_window_tree (window
);
8170 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8179 /************************************************************************
8181 ************************************************************************/
8183 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8184 to a non-zero value. This is sometimes handy to have in a debugger
8189 /* First and last unchanged row for try_window_id. */
8191 int debug_first_unchanged_at_end_vpos
;
8192 int debug_last_unchanged_at_beg_vpos
;
8194 /* Delta vpos and y. */
8196 int debug_dvpos
, debug_dy
;
8198 /* Delta in characters and bytes for try_window_id. */
8200 int debug_delta
, debug_delta_bytes
;
8202 /* Values of window_end_pos and window_end_vpos at the end of
8205 EMACS_INT debug_end_pos
, debug_end_vpos
;
8207 /* Append a string to W->desired_matrix->method. FMT is a printf
8208 format string. A1...A9 are a supplement for a variable-length
8209 argument list. If trace_redisplay_p is non-zero also printf the
8210 resulting string to stderr. */
8213 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8216 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8219 char *method
= w
->desired_matrix
->method
;
8220 int len
= strlen (method
);
8221 int size
= sizeof w
->desired_matrix
->method
;
8222 int remaining
= size
- len
- 1;
8224 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8225 if (len
&& remaining
)
8231 strncpy (method
+ len
, buffer
, remaining
);
8233 if (trace_redisplay_p
)
8234 fprintf (stderr
, "%p (%s): %s\n",
8236 ((BUFFERP (w
->buffer
)
8237 && STRINGP (XBUFFER (w
->buffer
)->name
))
8238 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8243 #endif /* GLYPH_DEBUG */
8246 /* This counter is used to clear the face cache every once in a while
8247 in redisplay_internal. It is incremented for each redisplay.
8248 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8251 #define CLEAR_FACE_CACHE_COUNT 500
8252 static int clear_face_cache_count
;
8254 /* Record the previous terminal frame we displayed. */
8256 static struct frame
*previous_terminal_frame
;
8258 /* Non-zero while redisplay_internal is in progress. */
8263 /* Value is non-zero if all changes in window W, which displays
8264 current_buffer, are in the text between START and END. START is a
8265 buffer position, END is given as a distance from Z. Used in
8266 redisplay_internal for display optimization. */
8269 text_outside_line_unchanged_p (w
, start
, end
)
8273 int unchanged_p
= 1;
8275 /* If text or overlays have changed, see where. */
8276 if (XFASTINT (w
->last_modified
) < MODIFF
8277 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8279 /* Gap in the line? */
8280 if (GPT
< start
|| Z
- GPT
< end
)
8283 /* Changes start in front of the line, or end after it? */
8285 && (BEG_UNCHANGED
< start
- 1
8286 || END_UNCHANGED
< end
))
8289 /* If selective display, can't optimize if changes start at the
8290 beginning of the line. */
8292 && INTEGERP (current_buffer
->selective_display
)
8293 && XINT (current_buffer
->selective_display
) > 0
8294 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8297 /* If there are overlays at the start or end of the line, these
8298 may have overlay strings with newlines in them. A change at
8299 START, for instance, may actually concern the display of such
8300 overlay strings as well, and they are displayed on different
8301 lines. So, quickly rule out this case. (For the future, it
8302 might be desirable to implement something more telling than
8303 just BEG/END_UNCHANGED.) */
8306 if (BEG
+ BEG_UNCHANGED
== start
8307 && overlay_touches_p (start
))
8309 if (END_UNCHANGED
== end
8310 && overlay_touches_p (Z
- end
))
8319 /* Do a frame update, taking possible shortcuts into account. This is
8320 the main external entry point for redisplay.
8322 If the last redisplay displayed an echo area message and that message
8323 is no longer requested, we clear the echo area or bring back the
8324 mini-buffer if that is in use. */
8329 redisplay_internal (0);
8333 /* Return 1 if point moved out of or into a composition. Otherwise
8334 return 0. PREV_BUF and PREV_PT are the last point buffer and
8335 position. BUF and PT are the current point buffer and position. */
8338 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8339 struct buffer
*prev_buf
, *buf
;
8346 XSETBUFFER (buffer
, buf
);
8347 /* Check a composition at the last point if point moved within the
8349 if (prev_buf
== buf
)
8352 /* Point didn't move. */
8355 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8356 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8357 && COMPOSITION_VALID_P (start
, end
, prop
)
8358 && start
< prev_pt
&& end
> prev_pt
)
8359 /* The last point was within the composition. Return 1 iff
8360 point moved out of the composition. */
8361 return (pt
<= start
|| pt
>= end
);
8364 /* Check a composition at the current point. */
8365 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8366 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8367 && COMPOSITION_VALID_P (start
, end
, prop
)
8368 && start
< pt
&& end
> pt
);
8372 /* Reconsider the setting of B->clip_changed which is displayed
8376 reconsider_clip_changes (w
, b
)
8380 if (b
->prevent_redisplay_optimizations_p
)
8381 b
->clip_changed
= 1;
8382 else if (b
->clip_changed
8383 && !NILP (w
->window_end_valid
)
8384 && w
->current_matrix
->buffer
== b
8385 && w
->current_matrix
->zv
== BUF_ZV (b
)
8386 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8387 b
->clip_changed
= 0;
8389 /* If display wasn't paused, and W is not a tool bar window, see if
8390 point has been moved into or out of a composition. In that case,
8391 we set b->clip_changed to 1 to force updating the screen. If
8392 b->clip_changed has already been set to 1, we can skip this
8394 if (!b
->clip_changed
8395 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8399 if (w
== XWINDOW (selected_window
))
8400 pt
= BUF_PT (current_buffer
);
8402 pt
= marker_position (w
->pointm
);
8404 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8405 || pt
!= XINT (w
->last_point
))
8406 && check_point_in_composition (w
->current_matrix
->buffer
,
8407 XINT (w
->last_point
),
8408 XBUFFER (w
->buffer
), pt
))
8409 b
->clip_changed
= 1;
8414 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8415 response to any user action; therefore, we should preserve the echo
8416 area. (Actually, our caller does that job.) Perhaps in the future
8417 avoid recentering windows if it is not necessary; currently that
8418 causes some problems. */
8421 redisplay_internal (preserve_echo_area
)
8422 int preserve_echo_area
;
8424 struct window
*w
= XWINDOW (selected_window
);
8425 struct frame
*f
= XFRAME (w
->frame
);
8427 int must_finish
= 0;
8428 struct text_pos tlbufpos
, tlendpos
;
8429 int number_of_visible_frames
;
8431 struct frame
*sf
= SELECTED_FRAME ();
8433 /* Non-zero means redisplay has to consider all windows on all
8434 frames. Zero means, only selected_window is considered. */
8435 int consider_all_windows_p
;
8437 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8439 /* No redisplay if running in batch mode or frame is not yet fully
8440 initialized, or redisplay is explicitly turned off by setting
8441 Vinhibit_redisplay. */
8443 || !NILP (Vinhibit_redisplay
)
8444 || !f
->glyphs_initialized_p
)
8447 /* The flag redisplay_performed_directly_p is set by
8448 direct_output_for_insert when it already did the whole screen
8449 update necessary. */
8450 if (redisplay_performed_directly_p
)
8452 redisplay_performed_directly_p
= 0;
8453 if (!hscroll_windows (selected_window
))
8457 #ifdef USE_X_TOOLKIT
8458 if (popup_activated ())
8462 /* I don't think this happens but let's be paranoid. */
8466 /* Record a function that resets redisplaying_p to its old value
8467 when we leave this function. */
8468 count
= BINDING_STACK_SIZE ();
8469 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8474 reconsider_clip_changes (w
, current_buffer
);
8476 /* If new fonts have been loaded that make a glyph matrix adjustment
8477 necessary, do it. */
8478 if (fonts_changed_p
)
8480 adjust_glyphs (NULL
);
8481 ++windows_or_buffers_changed
;
8482 fonts_changed_p
= 0;
8485 /* If face_change_count is non-zero, init_iterator will free all
8486 realized faces, which includes the faces referenced from current
8487 matrices. So, we can't reuse current matrices in this case. */
8488 if (face_change_count
)
8489 ++windows_or_buffers_changed
;
8491 if (! FRAME_WINDOW_P (sf
)
8492 && previous_terminal_frame
!= sf
)
8494 /* Since frames on an ASCII terminal share the same display
8495 area, displaying a different frame means redisplay the whole
8497 windows_or_buffers_changed
++;
8498 SET_FRAME_GARBAGED (sf
);
8499 XSETFRAME (Vterminal_frame
, sf
);
8501 previous_terminal_frame
= sf
;
8503 /* Set the visible flags for all frames. Do this before checking
8504 for resized or garbaged frames; they want to know if their frames
8505 are visible. See the comment in frame.h for
8506 FRAME_SAMPLE_VISIBILITY. */
8508 Lisp_Object tail
, frame
;
8510 number_of_visible_frames
= 0;
8512 FOR_EACH_FRAME (tail
, frame
)
8514 struct frame
*f
= XFRAME (frame
);
8516 FRAME_SAMPLE_VISIBILITY (f
);
8517 if (FRAME_VISIBLE_P (f
))
8518 ++number_of_visible_frames
;
8519 clear_desired_matrices (f
);
8523 /* Notice any pending interrupt request to change frame size. */
8524 do_pending_window_change (1);
8526 /* Clear frames marked as garbaged. */
8528 clear_garbaged_frames ();
8530 /* Build menubar and tool-bar items. */
8531 prepare_menu_bars ();
8533 if (windows_or_buffers_changed
)
8534 update_mode_lines
++;
8536 /* Detect case that we need to write or remove a star in the mode line. */
8537 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8539 w
->update_mode_line
= Qt
;
8540 if (buffer_shared
> 1)
8541 update_mode_lines
++;
8544 /* If %c is in the mode line, update it if needed. */
8545 if (!NILP (w
->column_number_displayed
)
8546 /* This alternative quickly identifies a common case
8547 where no change is needed. */
8548 && !(PT
== XFASTINT (w
->last_point
)
8549 && XFASTINT (w
->last_modified
) >= MODIFF
8550 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8551 && XFASTINT (w
->column_number_displayed
) != current_column ())
8552 w
->update_mode_line
= Qt
;
8554 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8556 /* The variable buffer_shared is set in redisplay_window and
8557 indicates that we redisplay a buffer in different windows. See
8559 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8561 /* If specs for an arrow have changed, do thorough redisplay
8562 to ensure we remove any arrow that should no longer exist. */
8563 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8564 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8565 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8567 /* Normally the message* functions will have already displayed and
8568 updated the echo area, but the frame may have been trashed, or
8569 the update may have been preempted, so display the echo area
8570 again here. Checking message_cleared_p captures the case that
8571 the echo area should be cleared. */
8572 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8573 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8574 || (message_cleared_p
8575 && minibuf_level
== 0
8576 /* If the mini-window is currently selected, this means the
8577 echo-area doesn't show through. */
8578 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8580 int window_height_changed_p
= echo_area_display (0);
8583 /* If we don't display the current message, don't clear the
8584 message_cleared_p flag, because, if we did, we wouldn't clear
8585 the echo area in the next redisplay which doesn't preserve
8587 if (!display_last_displayed_message_p
)
8588 message_cleared_p
= 0;
8590 if (fonts_changed_p
)
8592 else if (window_height_changed_p
)
8594 consider_all_windows_p
= 1;
8595 ++update_mode_lines
;
8596 ++windows_or_buffers_changed
;
8598 /* If window configuration was changed, frames may have been
8599 marked garbaged. Clear them or we will experience
8600 surprises wrt scrolling. */
8602 clear_garbaged_frames ();
8605 else if (EQ (selected_window
, minibuf_window
)
8606 && (current_buffer
->clip_changed
8607 || XFASTINT (w
->last_modified
) < MODIFF
8608 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8609 && resize_mini_window (w
, 0))
8611 /* Resized active mini-window to fit the size of what it is
8612 showing if its contents might have changed. */
8614 consider_all_windows_p
= 1;
8615 ++windows_or_buffers_changed
;
8616 ++update_mode_lines
;
8618 /* If window configuration was changed, frames may have been
8619 marked garbaged. Clear them or we will experience
8620 surprises wrt scrolling. */
8622 clear_garbaged_frames ();
8626 /* If showing the region, and mark has changed, we must redisplay
8627 the whole window. The assignment to this_line_start_pos prevents
8628 the optimization directly below this if-statement. */
8629 if (((!NILP (Vtransient_mark_mode
)
8630 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8631 != !NILP (w
->region_showing
))
8632 || (!NILP (w
->region_showing
)
8633 && !EQ (w
->region_showing
,
8634 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8635 CHARPOS (this_line_start_pos
) = 0;
8637 /* Optimize the case that only the line containing the cursor in the
8638 selected window has changed. Variables starting with this_ are
8639 set in display_line and record information about the line
8640 containing the cursor. */
8641 tlbufpos
= this_line_start_pos
;
8642 tlendpos
= this_line_end_pos
;
8643 if (!consider_all_windows_p
8644 && CHARPOS (tlbufpos
) > 0
8645 && NILP (w
->update_mode_line
)
8646 && !current_buffer
->clip_changed
8647 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8648 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8649 /* Make sure recorded data applies to current buffer, etc. */
8650 && this_line_buffer
== current_buffer
8651 && current_buffer
== XBUFFER (w
->buffer
)
8652 && NILP (w
->force_start
)
8653 /* Point must be on the line that we have info recorded about. */
8654 && PT
>= CHARPOS (tlbufpos
)
8655 && PT
<= Z
- CHARPOS (tlendpos
)
8656 /* All text outside that line, including its final newline,
8657 must be unchanged */
8658 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8659 CHARPOS (tlendpos
)))
8661 if (CHARPOS (tlbufpos
) > BEGV
8662 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8663 && (CHARPOS (tlbufpos
) == ZV
8664 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8665 /* Former continuation line has disappeared by becoming empty */
8667 else if (XFASTINT (w
->last_modified
) < MODIFF
8668 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8669 || MINI_WINDOW_P (w
))
8671 /* We have to handle the case of continuation around a
8672 wide-column character (See the comment in indent.c around
8675 For instance, in the following case:
8677 -------- Insert --------
8678 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8679 J_I_ ==> J_I_ `^^' are cursors.
8683 As we have to redraw the line above, we should goto cancel. */
8686 int line_height_before
= this_line_pixel_height
;
8688 /* Note that start_display will handle the case that the
8689 line starting at tlbufpos is a continuation lines. */
8690 start_display (&it
, w
, tlbufpos
);
8692 /* Implementation note: It this still necessary? */
8693 if (it
.current_x
!= this_line_start_x
)
8696 TRACE ((stderr
, "trying display optimization 1\n"));
8697 w
->cursor
.vpos
= -1;
8698 overlay_arrow_seen
= 0;
8699 it
.vpos
= this_line_vpos
;
8700 it
.current_y
= this_line_y
;
8701 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8704 /* If line contains point, is not continued,
8705 and ends at same distance from eob as before, we win */
8706 if (w
->cursor
.vpos
>= 0
8707 /* Line is not continued, otherwise this_line_start_pos
8708 would have been set to 0 in display_line. */
8709 && CHARPOS (this_line_start_pos
)
8710 /* Line ends as before. */
8711 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8712 /* Line has same height as before. Otherwise other lines
8713 would have to be shifted up or down. */
8714 && this_line_pixel_height
== line_height_before
)
8716 /* If this is not the window's last line, we must adjust
8717 the charstarts of the lines below. */
8718 if (it
.current_y
< it
.last_visible_y
)
8720 struct glyph_row
*row
8721 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8722 int delta
, delta_bytes
;
8724 if (Z
- CHARPOS (tlendpos
) == ZV
)
8726 /* This line ends at end of (accessible part of)
8727 buffer. There is no newline to count. */
8729 - CHARPOS (tlendpos
)
8730 - MATRIX_ROW_START_CHARPOS (row
));
8731 delta_bytes
= (Z_BYTE
8732 - BYTEPOS (tlendpos
)
8733 - MATRIX_ROW_START_BYTEPOS (row
));
8737 /* This line ends in a newline. Must take
8738 account of the newline and the rest of the
8739 text that follows. */
8741 - CHARPOS (tlendpos
)
8742 - MATRIX_ROW_START_CHARPOS (row
));
8743 delta_bytes
= (Z_BYTE
8744 - BYTEPOS (tlendpos
)
8745 - MATRIX_ROW_START_BYTEPOS (row
));
8748 increment_matrix_positions (w
->current_matrix
,
8750 w
->current_matrix
->nrows
,
8751 delta
, delta_bytes
);
8754 /* If this row displays text now but previously didn't,
8755 or vice versa, w->window_end_vpos may have to be
8757 if ((it
.glyph_row
- 1)->displays_text_p
)
8759 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8760 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8762 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8763 && this_line_vpos
> 0)
8764 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8765 w
->window_end_valid
= Qnil
;
8767 /* Update hint: No need to try to scroll in update_window. */
8768 w
->desired_matrix
->no_scrolling_p
= 1;
8771 *w
->desired_matrix
->method
= 0;
8772 debug_method_add (w
, "optimization 1");
8779 else if (/* Cursor position hasn't changed. */
8780 PT
== XFASTINT (w
->last_point
)
8781 /* Make sure the cursor was last displayed
8782 in this window. Otherwise we have to reposition it. */
8783 && 0 <= w
->cursor
.vpos
8784 && XINT (w
->height
) > w
->cursor
.vpos
)
8788 do_pending_window_change (1);
8790 /* We used to always goto end_of_redisplay here, but this
8791 isn't enough if we have a blinking cursor. */
8792 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8793 goto end_of_redisplay
;
8797 /* If highlighting the region, or if the cursor is in the echo area,
8798 then we can't just move the cursor. */
8799 else if (! (!NILP (Vtransient_mark_mode
)
8800 && !NILP (current_buffer
->mark_active
))
8801 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8802 || highlight_nonselected_windows
)
8803 && NILP (w
->region_showing
)
8804 && NILP (Vshow_trailing_whitespace
)
8805 && !cursor_in_echo_area
)
8808 struct glyph_row
*row
;
8810 /* Skip from tlbufpos to PT and see where it is. Note that
8811 PT may be in invisible text. If so, we will end at the
8812 next visible position. */
8813 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8814 NULL
, DEFAULT_FACE_ID
);
8815 it
.current_x
= this_line_start_x
;
8816 it
.current_y
= this_line_y
;
8817 it
.vpos
= this_line_vpos
;
8819 /* The call to move_it_to stops in front of PT, but
8820 moves over before-strings. */
8821 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8823 if (it
.vpos
== this_line_vpos
8824 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8827 xassert (this_line_vpos
== it
.vpos
);
8828 xassert (this_line_y
== it
.current_y
);
8829 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8831 *w
->desired_matrix
->method
= 0;
8832 debug_method_add (w
, "optimization 3");
8841 /* Text changed drastically or point moved off of line. */
8842 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8845 CHARPOS (this_line_start_pos
) = 0;
8846 consider_all_windows_p
|= buffer_shared
> 1;
8847 ++clear_face_cache_count
;
8850 /* Build desired matrices, and update the display. If
8851 consider_all_windows_p is non-zero, do it for all windows on all
8852 frames. Otherwise do it for selected_window, only. */
8854 if (consider_all_windows_p
)
8856 Lisp_Object tail
, frame
;
8857 int i
, n
= 0, size
= 50;
8858 struct frame
**updated
8859 = (struct frame
**) alloca (size
* sizeof *updated
);
8861 /* Clear the face cache eventually. */
8862 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8864 clear_face_cache (0);
8865 clear_face_cache_count
= 0;
8868 /* Recompute # windows showing selected buffer. This will be
8869 incremented each time such a window is displayed. */
8872 FOR_EACH_FRAME (tail
, frame
)
8874 struct frame
*f
= XFRAME (frame
);
8876 if (FRAME_WINDOW_P (f
) || f
== sf
)
8878 #ifdef HAVE_WINDOW_SYSTEM
8879 if (clear_face_cache_count
% 50 == 0
8880 && FRAME_WINDOW_P (f
))
8881 clear_image_cache (f
, 0);
8882 #endif /* HAVE_WINDOW_SYSTEM */
8884 /* Mark all the scroll bars to be removed; we'll redeem
8885 the ones we want when we redisplay their windows. */
8886 if (condemn_scroll_bars_hook
)
8887 condemn_scroll_bars_hook (f
);
8889 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8890 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8892 /* Any scroll bars which redisplay_windows should have
8893 nuked should now go away. */
8894 if (judge_scroll_bars_hook
)
8895 judge_scroll_bars_hook (f
);
8897 /* If fonts changed, display again. */
8898 if (fonts_changed_p
)
8901 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8903 /* See if we have to hscroll. */
8904 if (hscroll_windows (f
->root_window
))
8907 /* Prevent various kinds of signals during display
8908 update. stdio is not robust about handling
8909 signals, which can cause an apparent I/O
8911 if (interrupt_input
)
8915 /* Update the display. */
8916 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8917 pause
|= update_frame (f
, 0, 0);
8923 int nbytes
= size
* sizeof *updated
;
8924 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8925 bcopy (updated
, p
, nbytes
);
8934 /* Do the mark_window_display_accurate after all windows have
8935 been redisplayed because this call resets flags in buffers
8936 which are needed for proper redisplay. */
8937 for (i
= 0; i
< n
; ++i
)
8939 struct frame
*f
= updated
[i
];
8940 mark_window_display_accurate (f
->root_window
, 1);
8941 if (frame_up_to_date_hook
)
8942 frame_up_to_date_hook (f
);
8945 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8947 Lisp_Object mini_window
;
8948 struct frame
*mini_frame
;
8950 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8951 internal_condition_case_1 (redisplay_window_1
, selected_window
, Qerror
,
8952 redisplay_window_error
);
8954 /* Compare desired and current matrices, perform output. */
8957 /* If fonts changed, display again. */
8958 if (fonts_changed_p
)
8961 /* Prevent various kinds of signals during display update.
8962 stdio is not robust about handling signals,
8963 which can cause an apparent I/O error. */
8964 if (interrupt_input
)
8968 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8970 if (hscroll_windows (selected_window
))
8973 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8974 pause
= update_frame (sf
, 0, 0);
8977 /* We may have called echo_area_display at the top of this
8978 function. If the echo area is on another frame, that may
8979 have put text on a frame other than the selected one, so the
8980 above call to update_frame would not have caught it. Catch
8982 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8983 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8985 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8987 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8988 pause
|= update_frame (mini_frame
, 0, 0);
8989 if (!pause
&& hscroll_windows (mini_window
))
8994 /* If display was paused because of pending input, make sure we do a
8995 thorough update the next time. */
8998 /* Prevent the optimization at the beginning of
8999 redisplay_internal that tries a single-line update of the
9000 line containing the cursor in the selected window. */
9001 CHARPOS (this_line_start_pos
) = 0;
9003 /* Let the overlay arrow be updated the next time. */
9004 if (!NILP (last_arrow_position
))
9006 last_arrow_position
= Qt
;
9007 last_arrow_string
= Qt
;
9010 /* If we pause after scrolling, some rows in the current
9011 matrices of some windows are not valid. */
9012 if (!WINDOW_FULL_WIDTH_P (w
)
9013 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9014 update_mode_lines
= 1;
9018 if (!consider_all_windows_p
)
9020 /* This has already been done above if
9021 consider_all_windows_p is set. */
9022 mark_window_display_accurate_1 (w
, 1);
9024 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9025 last_arrow_string
= Voverlay_arrow_string
;
9027 if (frame_up_to_date_hook
!= 0)
9028 frame_up_to_date_hook (sf
);
9031 update_mode_lines
= 0;
9032 windows_or_buffers_changed
= 0;
9035 /* Start SIGIO interrupts coming again. Having them off during the
9036 code above makes it less likely one will discard output, but not
9037 impossible, since there might be stuff in the system buffer here.
9038 But it is much hairier to try to do anything about that. */
9039 if (interrupt_input
)
9043 /* If a frame has become visible which was not before, redisplay
9044 again, so that we display it. Expose events for such a frame
9045 (which it gets when becoming visible) don't call the parts of
9046 redisplay constructing glyphs, so simply exposing a frame won't
9047 display anything in this case. So, we have to display these
9048 frames here explicitly. */
9051 Lisp_Object tail
, frame
;
9054 FOR_EACH_FRAME (tail
, frame
)
9056 int this_is_visible
= 0;
9058 if (XFRAME (frame
)->visible
)
9059 this_is_visible
= 1;
9060 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9061 if (XFRAME (frame
)->visible
)
9062 this_is_visible
= 1;
9064 if (this_is_visible
)
9068 if (new_count
!= number_of_visible_frames
)
9069 windows_or_buffers_changed
++;
9072 /* Change frame size now if a change is pending. */
9073 do_pending_window_change (1);
9075 /* If we just did a pending size change, or have additional
9076 visible frames, redisplay again. */
9077 if (windows_or_buffers_changed
&& !pause
)
9082 unbind_to (count
, Qnil
);
9086 /* Redisplay, but leave alone any recent echo area message unless
9087 another message has been requested in its place.
9089 This is useful in situations where you need to redisplay but no
9090 user action has occurred, making it inappropriate for the message
9091 area to be cleared. See tracking_off and
9092 wait_reading_process_input for examples of these situations.
9094 FROM_WHERE is an integer saying from where this function was
9095 called. This is useful for debugging. */
9098 redisplay_preserve_echo_area (from_where
)
9101 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9103 if (!NILP (echo_area_buffer
[1]))
9105 /* We have a previously displayed message, but no current
9106 message. Redisplay the previous message. */
9107 display_last_displayed_message_p
= 1;
9108 redisplay_internal (1);
9109 display_last_displayed_message_p
= 0;
9112 redisplay_internal (1);
9116 /* Function registered with record_unwind_protect in
9117 redisplay_internal. Clears the flag indicating that a redisplay is
9121 unwind_redisplay (old_redisplaying_p
)
9122 Lisp_Object old_redisplaying_p
;
9124 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9129 /* Mark the display of window W as accurate or inaccurate. If
9130 ACCURATE_P is non-zero mark display of W as accurate. If
9131 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9132 redisplay_internal is called. */
9135 mark_window_display_accurate_1 (w
, accurate_p
)
9139 if (BUFFERP (w
->buffer
))
9141 struct buffer
*b
= XBUFFER (w
->buffer
);
9144 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9145 w
->last_overlay_modified
9146 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9148 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9152 b
->clip_changed
= 0;
9153 b
->prevent_redisplay_optimizations_p
= 0;
9155 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9156 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9157 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9158 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9160 w
->current_matrix
->buffer
= b
;
9161 w
->current_matrix
->begv
= BUF_BEGV (b
);
9162 w
->current_matrix
->zv
= BUF_ZV (b
);
9164 w
->last_cursor
= w
->cursor
;
9165 w
->last_cursor_off_p
= w
->cursor_off_p
;
9167 if (w
== XWINDOW (selected_window
))
9168 w
->last_point
= make_number (BUF_PT (b
));
9170 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9176 w
->window_end_valid
= w
->buffer
;
9177 #if 0 /* This is incorrect with variable-height lines. */
9178 xassert (XINT (w
->window_end_vpos
)
9180 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9182 w
->update_mode_line
= Qnil
;
9187 /* Mark the display of windows in the window tree rooted at WINDOW as
9188 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9189 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9190 be redisplayed the next time redisplay_internal is called. */
9193 mark_window_display_accurate (window
, accurate_p
)
9199 for (; !NILP (window
); window
= w
->next
)
9201 w
= XWINDOW (window
);
9202 mark_window_display_accurate_1 (w
, accurate_p
);
9204 if (!NILP (w
->vchild
))
9205 mark_window_display_accurate (w
->vchild
, accurate_p
);
9206 if (!NILP (w
->hchild
))
9207 mark_window_display_accurate (w
->hchild
, accurate_p
);
9212 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9213 last_arrow_string
= Voverlay_arrow_string
;
9217 /* Force a thorough redisplay the next time by setting
9218 last_arrow_position and last_arrow_string to t, which is
9219 unequal to any useful value of Voverlay_arrow_... */
9220 last_arrow_position
= Qt
;
9221 last_arrow_string
= Qt
;
9226 /* Return value in display table DP (Lisp_Char_Table *) for character
9227 C. Since a display table doesn't have any parent, we don't have to
9228 follow parent. Do not call this function directly but use the
9229 macro DISP_CHAR_VECTOR. */
9232 disp_char_vector (dp
, c
)
9233 struct Lisp_Char_Table
*dp
;
9239 if (SINGLE_BYTE_CHAR_P (c
))
9240 return (dp
->contents
[c
]);
9242 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9245 else if (code
[2] < 32)
9248 /* Here, the possible range of code[0] (== charset ID) is
9249 128..max_charset. Since the top level char table contains data
9250 for multibyte characters after 256th element, we must increment
9251 code[0] by 128 to get a correct index. */
9253 code
[3] = -1; /* anchor */
9255 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9257 val
= dp
->contents
[code
[i
]];
9258 if (!SUB_CHAR_TABLE_P (val
))
9259 return (NILP (val
) ? dp
->defalt
: val
);
9262 /* Here, val is a sub char table. We return the default value of
9264 return (dp
->defalt
);
9269 /***********************************************************************
9271 ***********************************************************************/
9273 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9276 redisplay_windows (window
)
9279 while (!NILP (window
))
9281 struct window
*w
= XWINDOW (window
);
9283 if (!NILP (w
->hchild
))
9284 redisplay_windows (w
->hchild
);
9285 else if (!NILP (w
->vchild
))
9286 redisplay_windows (w
->vchild
);
9289 displayed_buffer
= XBUFFER (w
->buffer
);
9290 internal_condition_case_1 (redisplay_window_0
, window
, Qerror
,
9291 redisplay_window_error
);
9299 redisplay_window_error ()
9301 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9306 redisplay_window_0 (window
)
9309 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9310 redisplay_window (window
, 0);
9315 redisplay_window_1 (window
)
9318 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9319 redisplay_window (window
, 1);
9323 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9324 DELTA is the number of bytes by which positions recorded in ROW
9325 differ from current buffer positions. */
9328 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9330 struct glyph_row
*row
;
9331 struct glyph_matrix
*matrix
;
9332 int delta
, delta_bytes
, dy
, dvpos
;
9334 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9335 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9337 int pt_old
= PT
- delta
;
9339 /* Skip over glyphs not having an object at the start of the row.
9340 These are special glyphs like truncation marks on terminal
9342 if (row
->displays_text_p
)
9344 && INTEGERP (glyph
->object
)
9345 && glyph
->charpos
< 0)
9347 x
+= glyph
->pixel_width
;
9352 && !INTEGERP (glyph
->object
)
9353 && (!BUFFERP (glyph
->object
)
9354 || glyph
->charpos
< pt_old
))
9356 x
+= glyph
->pixel_width
;
9360 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9362 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9363 w
->cursor
.y
= row
->y
+ dy
;
9365 if (w
== XWINDOW (selected_window
))
9367 if (!row
->continued_p
9368 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9371 this_line_buffer
= XBUFFER (w
->buffer
);
9373 CHARPOS (this_line_start_pos
)
9374 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9375 BYTEPOS (this_line_start_pos
)
9376 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9378 CHARPOS (this_line_end_pos
)
9379 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9380 BYTEPOS (this_line_end_pos
)
9381 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9383 this_line_y
= w
->cursor
.y
;
9384 this_line_pixel_height
= row
->height
;
9385 this_line_vpos
= w
->cursor
.vpos
;
9386 this_line_start_x
= row
->x
;
9389 CHARPOS (this_line_start_pos
) = 0;
9394 /* Run window scroll functions, if any, for WINDOW with new window
9395 start STARTP. Sets the window start of WINDOW to that position.
9397 We assume that the window's buffer is really current. */
9399 static INLINE
struct text_pos
9400 run_window_scroll_functions (window
, startp
)
9402 struct text_pos startp
;
9404 struct window
*w
= XWINDOW (window
);
9405 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9407 if (current_buffer
!= XBUFFER (w
->buffer
))
9410 if (!NILP (Vwindow_scroll_functions
))
9412 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9413 make_number (CHARPOS (startp
)));
9414 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9415 /* In case the hook functions switch buffers. */
9416 if (current_buffer
!= XBUFFER (w
->buffer
))
9417 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9424 /* Modify the desired matrix of window W and W->vscroll so that the
9425 line containing the cursor is fully visible. If this requires
9426 larger matrices than are allocated, set fonts_changed_p and return
9430 make_cursor_line_fully_visible (w
)
9433 struct glyph_matrix
*matrix
;
9434 struct glyph_row
*row
;
9437 /* It's not always possible to find the cursor, e.g, when a window
9438 is full of overlay strings. Don't do anything in that case. */
9439 if (w
->cursor
.vpos
< 0)
9442 matrix
= w
->desired_matrix
;
9443 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9445 /* If the cursor row is not partially visible, there's nothing
9447 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9450 /* If the row the cursor is in is taller than the window's height,
9451 it's not clear what to do, so do nothing. */
9452 window_height
= window_box_height (w
);
9453 if (row
->height
>= window_height
)
9456 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9458 int dy
= row
->height
- row
->visible_height
;
9461 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9463 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9465 int dy
= - (row
->height
- row
->visible_height
);
9468 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9471 /* When we change the cursor y-position of the selected window,
9472 change this_line_y as well so that the display optimization for
9473 the cursor line of the selected window in redisplay_internal uses
9474 the correct y-position. */
9475 if (w
== XWINDOW (selected_window
))
9476 this_line_y
= w
->cursor
.y
;
9478 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9479 redisplay with larger matrices. */
9480 if (matrix
->nrows
< required_matrix_height (w
))
9482 fonts_changed_p
= 1;
9490 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9491 non-zero means only WINDOW is redisplayed in redisplay_internal.
9492 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9493 in redisplay_window to bring a partially visible line into view in
9494 the case that only the cursor has moved.
9498 1 if scrolling succeeded
9500 0 if scrolling didn't find point.
9502 -1 if new fonts have been loaded so that we must interrupt
9503 redisplay, adjust glyph matrices, and try again. */
9509 SCROLLING_NEED_LARGER_MATRICES
9513 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9514 scroll_step
, temp_scroll_step
)
9516 int just_this_one_p
;
9517 EMACS_INT scroll_conservatively
, scroll_step
;
9518 int temp_scroll_step
;
9520 struct window
*w
= XWINDOW (window
);
9521 struct frame
*f
= XFRAME (w
->frame
);
9522 struct text_pos scroll_margin_pos
;
9523 struct text_pos pos
;
9524 struct text_pos startp
;
9526 Lisp_Object window_end
;
9527 int this_scroll_margin
;
9531 int amount_to_scroll
= 0;
9532 Lisp_Object aggressive
;
9536 debug_method_add (w
, "try_scrolling");
9539 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9541 /* Compute scroll margin height in pixels. We scroll when point is
9542 within this distance from the top or bottom of the window. */
9543 if (scroll_margin
> 0)
9545 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9546 this_scroll_margin
*= CANON_Y_UNIT (f
);
9549 this_scroll_margin
= 0;
9551 /* Compute how much we should try to scroll maximally to bring point
9553 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9554 scroll_max
= max (scroll_step
,
9555 max (scroll_conservatively
, temp_scroll_step
));
9556 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9557 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9558 /* We're trying to scroll because of aggressive scrolling
9559 but no scroll_step is set. Choose an arbitrary one. Maybe
9560 there should be a variable for this. */
9564 scroll_max
*= CANON_Y_UNIT (f
);
9566 /* Decide whether we have to scroll down. Start at the window end
9567 and move this_scroll_margin up to find the position of the scroll
9569 window_end
= Fwindow_end (window
, Qt
);
9570 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9571 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9572 if (this_scroll_margin
)
9574 start_display (&it
, w
, scroll_margin_pos
);
9575 move_it_vertically (&it
, - this_scroll_margin
);
9576 scroll_margin_pos
= it
.current
.pos
;
9579 if (PT
>= CHARPOS (scroll_margin_pos
))
9583 /* Point is in the scroll margin at the bottom of the window, or
9584 below. Compute a new window start that makes point visible. */
9586 /* Compute the distance from the scroll margin to PT.
9587 Give up if the distance is greater than scroll_max. */
9588 start_display (&it
, w
, scroll_margin_pos
);
9590 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9591 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9593 /* To make point visible, we have to move the window start
9594 down so that the line the cursor is in is visible, which
9595 means we have to add in the height of the cursor line. */
9596 dy
= line_bottom_y (&it
) - y0
;
9598 if (dy
> scroll_max
)
9599 return SCROLLING_FAILED
;
9601 /* Move the window start down. If scrolling conservatively,
9602 move it just enough down to make point visible. If
9603 scroll_step is set, move it down by scroll_step. */
9604 start_display (&it
, w
, startp
);
9606 if (scroll_conservatively
)
9608 = max (max (dy
, CANON_Y_UNIT (f
)),
9609 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9610 else if (scroll_step
|| temp_scroll_step
)
9611 amount_to_scroll
= scroll_max
;
9614 aggressive
= current_buffer
->scroll_up_aggressively
;
9615 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9616 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9617 if (NUMBERP (aggressive
))
9618 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9621 if (amount_to_scroll
<= 0)
9622 return SCROLLING_FAILED
;
9624 move_it_vertically (&it
, amount_to_scroll
);
9625 startp
= it
.current
.pos
;
9629 /* See if point is inside the scroll margin at the top of the
9631 scroll_margin_pos
= startp
;
9632 if (this_scroll_margin
)
9634 start_display (&it
, w
, startp
);
9635 move_it_vertically (&it
, this_scroll_margin
);
9636 scroll_margin_pos
= it
.current
.pos
;
9639 if (PT
< CHARPOS (scroll_margin_pos
))
9641 /* Point is in the scroll margin at the top of the window or
9642 above what is displayed in the window. */
9645 /* Compute the vertical distance from PT to the scroll
9646 margin position. Give up if distance is greater than
9648 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9649 start_display (&it
, w
, pos
);
9651 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9652 it
.last_visible_y
, -1,
9653 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9654 dy
= it
.current_y
- y0
;
9655 if (dy
> scroll_max
)
9656 return SCROLLING_FAILED
;
9658 /* Compute new window start. */
9659 start_display (&it
, w
, startp
);
9661 if (scroll_conservatively
)
9663 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9664 else if (scroll_step
|| temp_scroll_step
)
9665 amount_to_scroll
= scroll_max
;
9668 aggressive
= current_buffer
->scroll_down_aggressively
;
9669 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9670 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9671 if (NUMBERP (aggressive
))
9672 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9675 if (amount_to_scroll
<= 0)
9676 return SCROLLING_FAILED
;
9678 move_it_vertically (&it
, - amount_to_scroll
);
9679 startp
= it
.current
.pos
;
9683 /* Run window scroll functions. */
9684 startp
= run_window_scroll_functions (window
, startp
);
9686 /* Display the window. Give up if new fonts are loaded, or if point
9688 if (!try_window (window
, startp
))
9689 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9690 else if (w
->cursor
.vpos
< 0)
9692 clear_glyph_matrix (w
->desired_matrix
);
9693 rc
= SCROLLING_FAILED
;
9697 /* Maybe forget recorded base line for line number display. */
9698 if (!just_this_one_p
9699 || current_buffer
->clip_changed
9700 || BEG_UNCHANGED
< CHARPOS (startp
))
9701 w
->base_line_number
= Qnil
;
9703 /* If cursor ends up on a partially visible line, shift display
9704 lines up or down. If that fails because we need larger
9705 matrices, give up. */
9706 if (!make_cursor_line_fully_visible (w
))
9707 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9709 rc
= SCROLLING_SUCCESS
;
9716 /* Compute a suitable window start for window W if display of W starts
9717 on a continuation line. Value is non-zero if a new window start
9720 The new window start will be computed, based on W's width, starting
9721 from the start of the continued line. It is the start of the
9722 screen line with the minimum distance from the old start W->start. */
9725 compute_window_start_on_continuation_line (w
)
9728 struct text_pos pos
, start_pos
;
9729 int window_start_changed_p
= 0;
9731 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9733 /* If window start is on a continuation line... Window start may be
9734 < BEGV in case there's invisible text at the start of the
9735 buffer (M-x rmail, for example). */
9736 if (CHARPOS (start_pos
) > BEGV
9737 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9740 struct glyph_row
*row
;
9742 /* Handle the case that the window start is out of range. */
9743 if (CHARPOS (start_pos
) < BEGV
)
9744 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9745 else if (CHARPOS (start_pos
) > ZV
)
9746 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9748 /* Find the start of the continued line. This should be fast
9749 because scan_buffer is fast (newline cache). */
9750 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9751 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9752 row
, DEFAULT_FACE_ID
);
9753 reseat_at_previous_visible_line_start (&it
);
9755 /* If the line start is "too far" away from the window start,
9756 say it takes too much time to compute a new window start. */
9757 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9758 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9760 int min_distance
, distance
;
9762 /* Move forward by display lines to find the new window
9763 start. If window width was enlarged, the new start can
9764 be expected to be > the old start. If window width was
9765 decreased, the new window start will be < the old start.
9766 So, we're looking for the display line start with the
9767 minimum distance from the old window start. */
9768 pos
= it
.current
.pos
;
9769 min_distance
= INFINITY
;
9770 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9771 distance
< min_distance
)
9773 min_distance
= distance
;
9774 pos
= it
.current
.pos
;
9775 move_it_by_lines (&it
, 1, 0);
9778 /* Set the window start there. */
9779 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9780 window_start_changed_p
= 1;
9784 return window_start_changed_p
;
9788 /* Try cursor movement in case text has not changes in window WINDOW,
9789 with window start STARTP. Value is
9791 CURSOR_MOVEMENT_SUCCESS if successful
9793 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9795 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9796 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9797 we want to scroll as if scroll-step were set to 1. See the code.
9799 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9800 which case we have to abort this redisplay, and adjust matrices
9805 CURSOR_MOVEMENT_SUCCESS
,
9806 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9807 CURSOR_MOVEMENT_MUST_SCROLL
,
9808 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9812 try_cursor_movement (window
, startp
, scroll_step
)
9814 struct text_pos startp
;
9817 struct window
*w
= XWINDOW (window
);
9818 struct frame
*f
= XFRAME (w
->frame
);
9819 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9822 if (inhibit_try_cursor_movement
)
9826 /* Handle case where text has not changed, only point, and it has
9827 not moved off the frame. */
9828 if (/* Point may be in this window. */
9829 PT
>= CHARPOS (startp
)
9830 /* Selective display hasn't changed. */
9831 && !current_buffer
->clip_changed
9832 /* Function force-mode-line-update is used to force a thorough
9833 redisplay. It sets either windows_or_buffers_changed or
9834 update_mode_lines. So don't take a shortcut here for these
9836 && !update_mode_lines
9837 && !windows_or_buffers_changed
9838 /* Can't use this case if highlighting a region. When a
9839 region exists, cursor movement has to do more than just
9841 && !(!NILP (Vtransient_mark_mode
)
9842 && !NILP (current_buffer
->mark_active
))
9843 && NILP (w
->region_showing
)
9844 && NILP (Vshow_trailing_whitespace
)
9845 /* Right after splitting windows, last_point may be nil. */
9846 && INTEGERP (w
->last_point
)
9847 /* This code is not used for mini-buffer for the sake of the case
9848 of redisplaying to replace an echo area message; since in
9849 that case the mini-buffer contents per se are usually
9850 unchanged. This code is of no real use in the mini-buffer
9851 since the handling of this_line_start_pos, etc., in redisplay
9852 handles the same cases. */
9853 && !EQ (window
, minibuf_window
)
9854 /* When splitting windows or for new windows, it happens that
9855 redisplay is called with a nil window_end_vpos or one being
9856 larger than the window. This should really be fixed in
9857 window.c. I don't have this on my list, now, so we do
9858 approximately the same as the old redisplay code. --gerd. */
9859 && INTEGERP (w
->window_end_vpos
)
9860 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9861 && (FRAME_WINDOW_P (f
)
9862 || !MARKERP (Voverlay_arrow_position
)
9863 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9865 int this_scroll_margin
;
9866 struct glyph_row
*row
= NULL
;
9869 debug_method_add (w
, "cursor movement");
9872 /* Scroll if point within this distance from the top or bottom
9873 of the window. This is a pixel value. */
9874 this_scroll_margin
= max (0, scroll_margin
);
9875 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9876 this_scroll_margin
*= CANON_Y_UNIT (f
);
9878 /* Start with the row the cursor was displayed during the last
9879 not paused redisplay. Give up if that row is not valid. */
9880 if (w
->last_cursor
.vpos
< 0
9881 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9882 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9885 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9886 if (row
->mode_line_p
)
9888 if (!row
->enabled_p
)
9889 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9892 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9895 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9897 if (PT
> XFASTINT (w
->last_point
))
9899 /* Point has moved forward. */
9900 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9901 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9903 xassert (row
->enabled_p
);
9907 /* The end position of a row equals the start position
9908 of the next row. If PT is there, we would rather
9909 display it in the next line. */
9910 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9911 && MATRIX_ROW_END_CHARPOS (row
) == PT
9912 && !cursor_row_p (w
, row
))
9915 /* If within the scroll margin, scroll. Note that
9916 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9917 the next line would be drawn, and that
9918 this_scroll_margin can be zero. */
9919 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9920 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9921 /* Line is completely visible last line in window
9922 and PT is to be set in the next line. */
9923 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9924 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9925 && !row
->ends_at_zv_p
9926 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9929 else if (PT
< XFASTINT (w
->last_point
))
9931 /* Cursor has to be moved backward. Note that PT >=
9932 CHARPOS (startp) because of the outer
9934 while (!row
->mode_line_p
9935 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9936 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9937 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9938 && (row
->y
> this_scroll_margin
9939 || CHARPOS (startp
) == BEGV
))
9941 xassert (row
->enabled_p
);
9945 /* Consider the following case: Window starts at BEGV,
9946 there is invisible, intangible text at BEGV, so that
9947 display starts at some point START > BEGV. It can
9948 happen that we are called with PT somewhere between
9949 BEGV and START. Try to handle that case. */
9950 if (row
< w
->current_matrix
->rows
9951 || row
->mode_line_p
)
9953 row
= w
->current_matrix
->rows
;
9954 if (row
->mode_line_p
)
9958 /* Due to newlines in overlay strings, we may have to
9959 skip forward over overlay strings. */
9960 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9961 && MATRIX_ROW_END_CHARPOS (row
) == PT
9962 && !cursor_row_p (w
, row
))
9965 /* If within the scroll margin, scroll. */
9966 if (row
->y
< this_scroll_margin
9967 && CHARPOS (startp
) != BEGV
)
9971 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9972 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9974 /* if PT is not in the glyph row, give up. */
9975 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9977 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9979 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9980 && !row
->ends_at_zv_p
9981 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9982 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9983 else if (row
->height
> window_box_height (w
))
9985 /* If we end up in a partially visible line, let's
9986 make it fully visible, except when it's taller
9987 than the window, in which case we can't do much
9990 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9994 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9995 try_window (window
, startp
);
9996 if (!make_cursor_line_fully_visible (w
))
9997 rc
= CURSOR_MOVEMENT_NEED_LARGER_MATRICES
;
9999 rc
= CURSOR_MOVEMENT_SUCCESS
;
10003 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10006 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10007 rc
= CURSOR_MOVEMENT_SUCCESS
;
10016 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10017 selected_window is redisplayed. */
10020 redisplay_window (window
, just_this_one_p
)
10021 Lisp_Object window
;
10022 int just_this_one_p
;
10024 struct window
*w
= XWINDOW (window
);
10025 struct frame
*f
= XFRAME (w
->frame
);
10026 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10027 struct buffer
*old
= current_buffer
;
10028 struct text_pos lpoint
, opoint
, startp
;
10029 int update_mode_line
;
10032 /* Record it now because it's overwritten. */
10033 int current_matrix_up_to_date_p
= 0;
10034 int temp_scroll_step
= 0;
10035 int count
= BINDING_STACK_SIZE ();
10038 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10041 /* W must be a leaf window here. */
10042 xassert (!NILP (w
->buffer
));
10044 *w
->desired_matrix
->method
= 0;
10047 specbind (Qinhibit_point_motion_hooks
, Qt
);
10049 reconsider_clip_changes (w
, buffer
);
10051 /* Has the mode line to be updated? */
10052 update_mode_line
= (!NILP (w
->update_mode_line
)
10053 || update_mode_lines
10054 || buffer
->clip_changed
);
10056 if (MINI_WINDOW_P (w
))
10058 if (w
== XWINDOW (echo_area_window
)
10059 && !NILP (echo_area_buffer
[0]))
10061 if (update_mode_line
)
10062 /* We may have to update a tty frame's menu bar or a
10063 tool-bar. Example `M-x C-h C-h C-g'. */
10064 goto finish_menu_bars
;
10066 /* We've already displayed the echo area glyphs in this window. */
10067 goto finish_scroll_bars
;
10069 else if (w
!= XWINDOW (minibuf_window
))
10071 /* W is a mini-buffer window, but it's not the currently
10072 active one, so clear it. */
10073 int yb
= window_text_bottom_y (w
);
10074 struct glyph_row
*row
;
10077 for (y
= 0, row
= w
->desired_matrix
->rows
;
10079 y
+= row
->height
, ++row
)
10080 blank_row (w
, row
, y
);
10081 goto finish_scroll_bars
;
10084 clear_glyph_matrix (w
->desired_matrix
);
10087 /* Otherwise set up data on this window; select its buffer and point
10089 /* Really select the buffer, for the sake of buffer-local
10091 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10092 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10094 current_matrix_up_to_date_p
10095 = (!NILP (w
->window_end_valid
)
10096 && !current_buffer
->clip_changed
10097 && XFASTINT (w
->last_modified
) >= MODIFF
10098 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10100 /* When windows_or_buffers_changed is non-zero, we can't rely on
10101 the window end being valid, so set it to nil there. */
10102 if (windows_or_buffers_changed
)
10104 /* If window starts on a continuation line, maybe adjust the
10105 window start in case the window's width changed. */
10106 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10107 compute_window_start_on_continuation_line (w
);
10109 w
->window_end_valid
= Qnil
;
10112 /* Some sanity checks. */
10113 CHECK_WINDOW_END (w
);
10114 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10116 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10119 /* If %c is in mode line, update it if needed. */
10120 if (!NILP (w
->column_number_displayed
)
10121 /* This alternative quickly identifies a common case
10122 where no change is needed. */
10123 && !(PT
== XFASTINT (w
->last_point
)
10124 && XFASTINT (w
->last_modified
) >= MODIFF
10125 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10126 && XFASTINT (w
->column_number_displayed
) != current_column ())
10127 update_mode_line
= 1;
10129 /* Count number of windows showing the selected buffer. An indirect
10130 buffer counts as its base buffer. */
10131 if (!just_this_one_p
)
10133 struct buffer
*current_base
, *window_base
;
10134 current_base
= current_buffer
;
10135 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10136 if (current_base
->base_buffer
)
10137 current_base
= current_base
->base_buffer
;
10138 if (window_base
->base_buffer
)
10139 window_base
= window_base
->base_buffer
;
10140 if (current_base
== window_base
)
10144 /* Point refers normally to the selected window. For any other
10145 window, set up appropriate value. */
10146 if (!EQ (window
, selected_window
))
10148 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10149 int new_pt_byte
= marker_byte_position (w
->pointm
);
10153 new_pt_byte
= BEGV_BYTE
;
10154 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10156 else if (new_pt
> (ZV
- 1))
10159 new_pt_byte
= ZV_BYTE
;
10160 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10163 /* We don't use SET_PT so that the point-motion hooks don't run. */
10164 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10167 /* If any of the character widths specified in the display table
10168 have changed, invalidate the width run cache. It's true that
10169 this may be a bit late to catch such changes, but the rest of
10170 redisplay goes (non-fatally) haywire when the display table is
10171 changed, so why should we worry about doing any better? */
10172 if (current_buffer
->width_run_cache
)
10174 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10176 if (! disptab_matches_widthtab (disptab
,
10177 XVECTOR (current_buffer
->width_table
)))
10179 invalidate_region_cache (current_buffer
,
10180 current_buffer
->width_run_cache
,
10182 recompute_width_table (current_buffer
, disptab
);
10186 /* If window-start is screwed up, choose a new one. */
10187 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10190 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10192 /* If someone specified a new starting point but did not insist,
10193 check whether it can be used. */
10194 if (!NILP (w
->optional_new_start
)
10195 && CHARPOS (startp
) >= BEGV
10196 && CHARPOS (startp
) <= ZV
)
10198 w
->optional_new_start
= Qnil
;
10199 start_display (&it
, w
, startp
);
10200 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10201 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10202 if (IT_CHARPOS (it
) == PT
)
10203 w
->force_start
= Qt
;
10206 /* Handle case where place to start displaying has been specified,
10207 unless the specified location is outside the accessible range. */
10208 if (!NILP (w
->force_start
)
10209 || w
->frozen_window_start_p
)
10211 w
->force_start
= Qnil
;
10213 w
->window_end_valid
= Qnil
;
10215 /* Forget any recorded base line for line number display. */
10216 if (!current_matrix_up_to_date_p
10217 || current_buffer
->clip_changed
)
10218 w
->base_line_number
= Qnil
;
10220 /* Redisplay the mode line. Select the buffer properly for that.
10221 Also, run the hook window-scroll-functions
10222 because we have scrolled. */
10223 /* Note, we do this after clearing force_start because
10224 if there's an error, it is better to forget about force_start
10225 than to get into an infinite loop calling the hook functions
10226 and having them get more errors. */
10227 if (!update_mode_line
10228 || ! NILP (Vwindow_scroll_functions
))
10230 update_mode_line
= 1;
10231 w
->update_mode_line
= Qt
;
10232 startp
= run_window_scroll_functions (window
, startp
);
10235 w
->last_modified
= make_number (0);
10236 w
->last_overlay_modified
= make_number (0);
10237 if (CHARPOS (startp
) < BEGV
)
10238 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10239 else if (CHARPOS (startp
) > ZV
)
10240 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10242 /* Redisplay, then check if cursor has been set during the
10243 redisplay. Give up if new fonts were loaded. */
10244 if (!try_window (window
, startp
))
10246 w
->force_start
= Qt
;
10247 clear_glyph_matrix (w
->desired_matrix
);
10248 goto finish_scroll_bars
;
10251 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10253 /* If point does not appear, try to move point so it does
10254 appear. The desired matrix has been built above, so we
10255 can use it here. */
10257 struct glyph_row
*row
;
10259 window_height
= window_box_height (w
) / 2;
10260 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10261 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10264 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10265 MATRIX_ROW_START_BYTEPOS (row
));
10267 if (w
!= XWINDOW (selected_window
))
10268 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10269 else if (current_buffer
== old
)
10270 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10272 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10274 /* If we are highlighting the region, then we just changed
10275 the region, so redisplay to show it. */
10276 if (!NILP (Vtransient_mark_mode
)
10277 && !NILP (current_buffer
->mark_active
))
10279 clear_glyph_matrix (w
->desired_matrix
);
10280 if (!try_window (window
, startp
))
10281 goto need_larger_matrices
;
10285 if (!make_cursor_line_fully_visible (w
))
10286 goto need_larger_matrices
;
10288 debug_method_add (w
, "forced window start");
10293 /* Handle case where text has not changed, only point, and it has
10294 not moved off the frame. */
10295 if (current_matrix_up_to_date_p
10296 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10297 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10301 case CURSOR_MOVEMENT_SUCCESS
:
10304 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10305 goto need_larger_matrices
;
10307 case CURSOR_MOVEMENT_MUST_SCROLL
:
10308 goto try_to_scroll
;
10314 /* If current starting point was originally the beginning of a line
10315 but no longer is, find a new starting point. */
10316 else if (!NILP (w
->start_at_line_beg
)
10317 && !(CHARPOS (startp
) <= BEGV
10318 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10321 debug_method_add (w
, "recenter 1");
10326 /* Try scrolling with try_window_id. Value is > 0 if update has
10327 been done, it is -1 if we know that the same window start will
10328 not work. It is 0 if unsuccessful for some other reason. */
10329 else if ((tem
= try_window_id (w
)) != 0)
10332 debug_method_add (w
, "try_window_id %d", tem
);
10335 if (fonts_changed_p
)
10336 goto need_larger_matrices
;
10340 /* Otherwise try_window_id has returned -1 which means that we
10341 don't want the alternative below this comment to execute. */
10343 else if (CHARPOS (startp
) >= BEGV
10344 && CHARPOS (startp
) <= ZV
10345 && PT
>= CHARPOS (startp
)
10346 && (CHARPOS (startp
) < ZV
10347 /* Avoid starting at end of buffer. */
10348 || CHARPOS (startp
) == BEGV
10349 || (XFASTINT (w
->last_modified
) >= MODIFF
10350 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10353 debug_method_add (w
, "same window start");
10356 /* Try to redisplay starting at same place as before.
10357 If point has not moved off frame, accept the results. */
10358 if (!current_matrix_up_to_date_p
10359 /* Don't use try_window_reusing_current_matrix in this case
10360 because a window scroll function can have changed the
10362 || !NILP (Vwindow_scroll_functions
)
10363 || MINI_WINDOW_P (w
)
10364 || !try_window_reusing_current_matrix (w
))
10366 IF_DEBUG (debug_method_add (w
, "1"));
10367 try_window (window
, startp
);
10370 if (fonts_changed_p
)
10371 goto need_larger_matrices
;
10373 if (w
->cursor
.vpos
>= 0)
10375 if (!just_this_one_p
10376 || current_buffer
->clip_changed
10377 || BEG_UNCHANGED
< CHARPOS (startp
))
10378 /* Forget any recorded base line for line number display. */
10379 w
->base_line_number
= Qnil
;
10381 if (!make_cursor_line_fully_visible (w
))
10382 goto need_larger_matrices
;
10386 clear_glyph_matrix (w
->desired_matrix
);
10391 w
->last_modified
= make_number (0);
10392 w
->last_overlay_modified
= make_number (0);
10394 /* Redisplay the mode line. Select the buffer properly for that. */
10395 if (!update_mode_line
)
10397 update_mode_line
= 1;
10398 w
->update_mode_line
= Qt
;
10401 /* Try to scroll by specified few lines. */
10402 if ((scroll_conservatively
10404 || temp_scroll_step
10405 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10406 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10407 && !current_buffer
->clip_changed
10408 && CHARPOS (startp
) >= BEGV
10409 && CHARPOS (startp
) <= ZV
)
10411 /* The function returns -1 if new fonts were loaded, 1 if
10412 successful, 0 if not successful. */
10413 int rc
= try_scrolling (window
, just_this_one_p
,
10414 scroll_conservatively
,
10419 case SCROLLING_SUCCESS
:
10422 case SCROLLING_NEED_LARGER_MATRICES
:
10423 goto need_larger_matrices
;
10425 case SCROLLING_FAILED
:
10433 /* Finally, just choose place to start which centers point */
10438 debug_method_add (w
, "recenter");
10441 /* w->vscroll = 0; */
10443 /* Forget any previously recorded base line for line number display. */
10444 if (!current_matrix_up_to_date_p
10445 || current_buffer
->clip_changed
)
10446 w
->base_line_number
= Qnil
;
10448 /* Move backward half the height of the window. */
10449 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10450 it
.current_y
= it
.last_visible_y
;
10451 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10452 xassert (IT_CHARPOS (it
) >= BEGV
);
10454 /* The function move_it_vertically_backward may move over more
10455 than the specified y-distance. If it->w is small, e.g. a
10456 mini-buffer window, we may end up in front of the window's
10457 display area. Start displaying at the start of the line
10458 containing PT in this case. */
10459 if (it
.current_y
<= 0)
10461 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10462 move_it_vertically (&it
, 0);
10463 xassert (IT_CHARPOS (it
) <= PT
);
10467 it
.current_x
= it
.hpos
= 0;
10469 /* Set startp here explicitly in case that helps avoid an infinite loop
10470 in case the window-scroll-functions functions get errors. */
10471 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10473 /* Run scroll hooks. */
10474 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10476 /* Redisplay the window. */
10477 if (!current_matrix_up_to_date_p
10478 || windows_or_buffers_changed
10479 /* Don't use try_window_reusing_current_matrix in this case
10480 because it can have changed the buffer. */
10481 || !NILP (Vwindow_scroll_functions
)
10482 || !just_this_one_p
10483 || MINI_WINDOW_P (w
)
10484 || !try_window_reusing_current_matrix (w
))
10485 try_window (window
, startp
);
10487 /* If new fonts have been loaded (due to fontsets), give up. We
10488 have to start a new redisplay since we need to re-adjust glyph
10490 if (fonts_changed_p
)
10491 goto need_larger_matrices
;
10493 /* If cursor did not appear assume that the middle of the window is
10494 in the first line of the window. Do it again with the next line.
10495 (Imagine a window of height 100, displaying two lines of height
10496 60. Moving back 50 from it->last_visible_y will end in the first
10498 if (w
->cursor
.vpos
< 0)
10500 if (!NILP (w
->window_end_valid
)
10501 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10503 clear_glyph_matrix (w
->desired_matrix
);
10504 move_it_by_lines (&it
, 1, 0);
10505 try_window (window
, it
.current
.pos
);
10507 else if (PT
< IT_CHARPOS (it
))
10509 clear_glyph_matrix (w
->desired_matrix
);
10510 move_it_by_lines (&it
, -1, 0);
10511 try_window (window
, it
.current
.pos
);
10515 /* Not much we can do about it. */
10519 /* Consider the following case: Window starts at BEGV, there is
10520 invisible, intangible text at BEGV, so that display starts at
10521 some point START > BEGV. It can happen that we are called with
10522 PT somewhere between BEGV and START. Try to handle that case. */
10523 if (w
->cursor
.vpos
< 0)
10525 struct glyph_row
*row
= w
->current_matrix
->rows
;
10526 if (row
->mode_line_p
)
10528 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10531 if (!make_cursor_line_fully_visible (w
))
10532 goto need_larger_matrices
;
10536 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10537 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10538 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10541 /* Display the mode line, if we must. */
10542 if ((update_mode_line
10543 /* If window not full width, must redo its mode line
10544 if (a) the window to its side is being redone and
10545 (b) we do a frame-based redisplay. This is a consequence
10546 of how inverted lines are drawn in frame-based redisplay. */
10547 || (!just_this_one_p
10548 && !FRAME_WINDOW_P (f
)
10549 && !WINDOW_FULL_WIDTH_P (w
))
10550 /* Line number to display. */
10551 || INTEGERP (w
->base_line_pos
)
10552 /* Column number is displayed and different from the one displayed. */
10553 || (!NILP (w
->column_number_displayed
)
10554 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10555 /* This means that the window has a mode line. */
10556 && (WINDOW_WANTS_MODELINE_P (w
)
10557 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10559 display_mode_lines (w
);
10561 /* If mode line height has changed, arrange for a thorough
10562 immediate redisplay using the correct mode line height. */
10563 if (WINDOW_WANTS_MODELINE_P (w
)
10564 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10566 fonts_changed_p
= 1;
10567 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10568 = DESIRED_MODE_LINE_HEIGHT (w
);
10571 /* If top line height has changed, arrange for a thorough
10572 immediate redisplay using the correct mode line height. */
10573 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10574 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10576 fonts_changed_p
= 1;
10577 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10578 = DESIRED_HEADER_LINE_HEIGHT (w
);
10581 if (fonts_changed_p
)
10582 goto need_larger_matrices
;
10585 if (!line_number_displayed
10586 && !BUFFERP (w
->base_line_pos
))
10588 w
->base_line_pos
= Qnil
;
10589 w
->base_line_number
= Qnil
;
10594 /* When we reach a frame's selected window, redo the frame's menu bar. */
10595 if (update_mode_line
10596 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10598 int redisplay_menu_p
= 0;
10600 if (FRAME_WINDOW_P (f
))
10602 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10603 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10605 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10609 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10611 if (redisplay_menu_p
)
10612 display_menu_bar (w
);
10614 #ifdef HAVE_WINDOW_SYSTEM
10615 if (WINDOWP (f
->tool_bar_window
)
10616 && (FRAME_TOOL_BAR_LINES (f
) > 0
10617 || auto_resize_tool_bars_p
))
10618 redisplay_tool_bar (f
);
10622 need_larger_matrices
:
10624 finish_scroll_bars
:
10626 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10628 int start
, end
, whole
;
10630 /* Calculate the start and end positions for the current window.
10631 At some point, it would be nice to choose between scrollbars
10632 which reflect the whole buffer size, with special markers
10633 indicating narrowing, and scrollbars which reflect only the
10636 Note that mini-buffers sometimes aren't displaying any text. */
10637 if (!MINI_WINDOW_P (w
)
10638 || (w
== XWINDOW (minibuf_window
)
10639 && NILP (echo_area_buffer
[0])))
10642 start
= marker_position (w
->start
) - BEGV
;
10643 /* I don't think this is guaranteed to be right. For the
10644 moment, we'll pretend it is. */
10645 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10649 if (whole
< (end
- start
))
10650 whole
= end
- start
;
10653 start
= end
= whole
= 0;
10655 /* Indicate what this scroll bar ought to be displaying now. */
10656 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10658 /* Note that we actually used the scroll bar attached to this
10659 window, so it shouldn't be deleted at the end of redisplay. */
10660 redeem_scroll_bar_hook (w
);
10663 /* Restore current_buffer and value of point in it. */
10664 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10665 set_buffer_internal_1 (old
);
10666 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10668 unbind_to (count
, Qnil
);
10672 /* Build the complete desired matrix of WINDOW with a window start
10673 buffer position POS. Value is non-zero if successful. It is zero
10674 if fonts were loaded during redisplay which makes re-adjusting
10675 glyph matrices necessary. */
10678 try_window (window
, pos
)
10679 Lisp_Object window
;
10680 struct text_pos pos
;
10682 struct window
*w
= XWINDOW (window
);
10684 struct glyph_row
*last_text_row
= NULL
;
10686 /* Make POS the new window start. */
10687 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10689 /* Mark cursor position as unknown. No overlay arrow seen. */
10690 w
->cursor
.vpos
= -1;
10691 overlay_arrow_seen
= 0;
10693 /* Initialize iterator and info to start at POS. */
10694 start_display (&it
, w
, pos
);
10696 /* Display all lines of W. */
10697 while (it
.current_y
< it
.last_visible_y
)
10699 if (display_line (&it
))
10700 last_text_row
= it
.glyph_row
- 1;
10701 if (fonts_changed_p
)
10705 /* If bottom moved off end of frame, change mode line percentage. */
10706 if (XFASTINT (w
->window_end_pos
) <= 0
10707 && Z
!= IT_CHARPOS (it
))
10708 w
->update_mode_line
= Qt
;
10710 /* Set window_end_pos to the offset of the last character displayed
10711 on the window from the end of current_buffer. Set
10712 window_end_vpos to its row number. */
10715 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10716 w
->window_end_bytepos
10717 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10719 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10721 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10722 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10723 ->displays_text_p
);
10727 w
->window_end_bytepos
= 0;
10728 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10731 /* But that is not valid info until redisplay finishes. */
10732 w
->window_end_valid
= Qnil
;
10738 /************************************************************************
10739 Window redisplay reusing current matrix when buffer has not changed
10740 ************************************************************************/
10742 /* Try redisplay of window W showing an unchanged buffer with a
10743 different window start than the last time it was displayed by
10744 reusing its current matrix. Value is non-zero if successful.
10745 W->start is the new window start. */
10748 try_window_reusing_current_matrix (w
)
10751 struct frame
*f
= XFRAME (w
->frame
);
10752 struct glyph_row
*row
, *bottom_row
;
10755 struct text_pos start
, new_start
;
10756 int nrows_scrolled
, i
;
10757 struct glyph_row
*last_text_row
;
10758 struct glyph_row
*last_reused_text_row
;
10759 struct glyph_row
*start_row
;
10760 int start_vpos
, min_y
, max_y
;
10763 if (inhibit_try_window_reusing
)
10767 if (/* This function doesn't handle terminal frames. */
10768 !FRAME_WINDOW_P (f
)
10769 /* Don't try to reuse the display if windows have been split
10771 || windows_or_buffers_changed
)
10774 /* Can't do this if region may have changed. */
10775 if ((!NILP (Vtransient_mark_mode
)
10776 && !NILP (current_buffer
->mark_active
))
10777 || !NILP (w
->region_showing
)
10778 || !NILP (Vshow_trailing_whitespace
))
10781 /* If top-line visibility has changed, give up. */
10782 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10783 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10786 /* Give up if old or new display is scrolled vertically. We could
10787 make this function handle this, but right now it doesn't. */
10788 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10789 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10792 /* The variable new_start now holds the new window start. The old
10793 start `start' can be determined from the current matrix. */
10794 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10795 start
= start_row
->start
.pos
;
10796 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10798 /* Clear the desired matrix for the display below. */
10799 clear_glyph_matrix (w
->desired_matrix
);
10801 if (CHARPOS (new_start
) <= CHARPOS (start
))
10805 /* Don't use this method if the display starts with an ellipsis
10806 displayed for invisible text. It's not easy to handle that case
10807 below, and it's certainly not worth the effort since this is
10808 not a frequent case. */
10809 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10812 IF_DEBUG (debug_method_add (w
, "twu1"));
10814 /* Display up to a row that can be reused. The variable
10815 last_text_row is set to the last row displayed that displays
10816 text. Note that it.vpos == 0 if or if not there is a
10817 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10818 start_display (&it
, w
, new_start
);
10819 first_row_y
= it
.current_y
;
10820 w
->cursor
.vpos
= -1;
10821 last_text_row
= last_reused_text_row
= NULL
;
10823 while (it
.current_y
< it
.last_visible_y
10824 && IT_CHARPOS (it
) < CHARPOS (start
)
10825 && !fonts_changed_p
)
10826 if (display_line (&it
))
10827 last_text_row
= it
.glyph_row
- 1;
10829 /* A value of current_y < last_visible_y means that we stopped
10830 at the previous window start, which in turn means that we
10831 have at least one reusable row. */
10832 if (it
.current_y
< it
.last_visible_y
)
10834 /* IT.vpos always starts from 0; it counts text lines. */
10835 nrows_scrolled
= it
.vpos
;
10837 /* Find PT if not already found in the lines displayed. */
10838 if (w
->cursor
.vpos
< 0)
10840 int dy
= it
.current_y
- first_row_y
;
10842 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10843 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10845 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10846 dy
, nrows_scrolled
);
10849 clear_glyph_matrix (w
->desired_matrix
);
10854 /* Scroll the display. Do it before the current matrix is
10855 changed. The problem here is that update has not yet
10856 run, i.e. part of the current matrix is not up to date.
10857 scroll_run_hook will clear the cursor, and use the
10858 current matrix to get the height of the row the cursor is
10860 run
.current_y
= first_row_y
;
10861 run
.desired_y
= it
.current_y
;
10862 run
.height
= it
.last_visible_y
- it
.current_y
;
10864 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10867 rif
->update_window_begin_hook (w
);
10868 rif
->clear_mouse_face (w
);
10869 rif
->scroll_run_hook (w
, &run
);
10870 rif
->update_window_end_hook (w
, 0, 0);
10874 /* Shift current matrix down by nrows_scrolled lines. */
10875 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10876 rotate_matrix (w
->current_matrix
,
10878 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10881 /* Disable lines that must be updated. */
10882 for (i
= 0; i
< it
.vpos
; ++i
)
10883 (start_row
+ i
)->enabled_p
= 0;
10885 /* Re-compute Y positions. */
10886 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10887 max_y
= it
.last_visible_y
;
10888 for (row
= start_row
+ nrows_scrolled
;
10892 row
->y
= it
.current_y
;
10893 row
->visible_height
= row
->height
;
10895 if (row
->y
< min_y
)
10896 row
->visible_height
-= min_y
- row
->y
;
10897 if (row
->y
+ row
->height
> max_y
)
10898 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10900 it
.current_y
+= row
->height
;
10902 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10903 last_reused_text_row
= row
;
10904 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10908 /* Disable lines in the current matrix which are now
10909 below the window. */
10910 for (++row
; row
< bottom_row
; ++row
)
10911 row
->enabled_p
= 0;
10914 /* Update window_end_pos etc.; last_reused_text_row is the last
10915 reused row from the current matrix containing text, if any.
10916 The value of last_text_row is the last displayed line
10917 containing text. */
10918 if (last_reused_text_row
)
10920 w
->window_end_bytepos
10921 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10923 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10925 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10926 w
->current_matrix
));
10928 else if (last_text_row
)
10930 w
->window_end_bytepos
10931 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10933 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10935 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10939 /* This window must be completely empty. */
10940 w
->window_end_bytepos
= 0;
10941 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10943 w
->window_end_valid
= Qnil
;
10945 /* Update hint: don't try scrolling again in update_window. */
10946 w
->desired_matrix
->no_scrolling_p
= 1;
10949 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10953 else if (CHARPOS (new_start
) > CHARPOS (start
))
10955 struct glyph_row
*pt_row
, *row
;
10956 struct glyph_row
*first_reusable_row
;
10957 struct glyph_row
*first_row_to_display
;
10959 int yb
= window_text_bottom_y (w
);
10961 /* Find the row starting at new_start, if there is one. Don't
10962 reuse a partially visible line at the end. */
10963 first_reusable_row
= start_row
;
10964 while (first_reusable_row
->enabled_p
10965 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10966 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10967 < CHARPOS (new_start
)))
10968 ++first_reusable_row
;
10970 /* Give up if there is no row to reuse. */
10971 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10972 || !first_reusable_row
->enabled_p
10973 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10974 != CHARPOS (new_start
)))
10977 /* We can reuse fully visible rows beginning with
10978 first_reusable_row to the end of the window. Set
10979 first_row_to_display to the first row that cannot be reused.
10980 Set pt_row to the row containing point, if there is any. */
10982 for (first_row_to_display
= first_reusable_row
;
10983 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10984 ++first_row_to_display
)
10986 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10987 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10988 pt_row
= first_row_to_display
;
10991 /* Start displaying at the start of first_row_to_display. */
10992 xassert (first_row_to_display
->y
< yb
);
10993 init_to_row_start (&it
, w
, first_row_to_display
);
10995 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10997 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10999 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11000 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11002 /* Display lines beginning with first_row_to_display in the
11003 desired matrix. Set last_text_row to the last row displayed
11004 that displays text. */
11005 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11006 if (pt_row
== NULL
)
11007 w
->cursor
.vpos
= -1;
11008 last_text_row
= NULL
;
11009 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11010 if (display_line (&it
))
11011 last_text_row
= it
.glyph_row
- 1;
11013 /* Give up If point isn't in a row displayed or reused. */
11014 if (w
->cursor
.vpos
< 0)
11016 clear_glyph_matrix (w
->desired_matrix
);
11020 /* If point is in a reused row, adjust y and vpos of the cursor
11024 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11025 w
->current_matrix
);
11026 w
->cursor
.y
-= first_reusable_row
->y
;
11029 /* Scroll the display. */
11030 run
.current_y
= first_reusable_row
->y
;
11031 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11032 run
.height
= it
.last_visible_y
- run
.current_y
;
11033 dy
= run
.current_y
- run
.desired_y
;
11037 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11039 rif
->update_window_begin_hook (w
);
11040 rif
->clear_mouse_face (w
);
11041 rif
->scroll_run_hook (w
, &run
);
11042 rif
->update_window_end_hook (w
, 0, 0);
11046 /* Adjust Y positions of reused rows. */
11047 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11048 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11049 max_y
= it
.last_visible_y
;
11050 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11053 row
->visible_height
= row
->height
;
11054 if (row
->y
< min_y
)
11055 row
->visible_height
-= min_y
- row
->y
;
11056 if (row
->y
+ row
->height
> max_y
)
11057 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11060 /* Scroll the current matrix. */
11061 xassert (nrows_scrolled
> 0);
11062 rotate_matrix (w
->current_matrix
,
11064 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11067 /* Disable rows not reused. */
11068 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11069 row
->enabled_p
= 0;
11071 /* Adjust window end. A null value of last_text_row means that
11072 the window end is in reused rows which in turn means that
11073 only its vpos can have changed. */
11076 w
->window_end_bytepos
11077 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11079 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11081 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11086 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11089 w
->window_end_valid
= Qnil
;
11090 w
->desired_matrix
->no_scrolling_p
= 1;
11093 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11103 /************************************************************************
11104 Window redisplay reusing current matrix when buffer has changed
11105 ************************************************************************/
11107 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11108 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11110 static struct glyph_row
*
11111 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11112 struct glyph_row
*));
11115 /* Return the last row in MATRIX displaying text. If row START is
11116 non-null, start searching with that row. IT gives the dimensions
11117 of the display. Value is null if matrix is empty; otherwise it is
11118 a pointer to the row found. */
11120 static struct glyph_row
*
11121 find_last_row_displaying_text (matrix
, it
, start
)
11122 struct glyph_matrix
*matrix
;
11124 struct glyph_row
*start
;
11126 struct glyph_row
*row
, *row_found
;
11128 /* Set row_found to the last row in IT->w's current matrix
11129 displaying text. The loop looks funny but think of partially
11132 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11133 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11135 xassert (row
->enabled_p
);
11137 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11146 /* Return the last row in the current matrix of W that is not affected
11147 by changes at the start of current_buffer that occurred since W's
11148 current matrix was built. Value is null if no such row exists.
11150 BEG_UNCHANGED us the number of characters unchanged at the start of
11151 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11152 first changed character in current_buffer. Characters at positions <
11153 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11154 when the current matrix was built. */
11156 static struct glyph_row
*
11157 find_last_unchanged_at_beg_row (w
)
11160 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11161 struct glyph_row
*row
;
11162 struct glyph_row
*row_found
= NULL
;
11163 int yb
= window_text_bottom_y (w
);
11165 /* Find the last row displaying unchanged text. */
11166 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11167 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11168 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11170 if (/* If row ends before first_changed_pos, it is unchanged,
11171 except in some case. */
11172 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11173 /* When row ends in ZV and we write at ZV it is not
11175 && !row
->ends_at_zv_p
11176 /* When first_changed_pos is the end of a continued line,
11177 row is not unchanged because it may be no longer
11179 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11180 && row
->continued_p
))
11183 /* Stop if last visible row. */
11184 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11194 /* Find the first glyph row in the current matrix of W that is not
11195 affected by changes at the end of current_buffer since the
11196 time W's current matrix was built.
11198 Return in *DELTA the number of chars by which buffer positions in
11199 unchanged text at the end of current_buffer must be adjusted.
11201 Return in *DELTA_BYTES the corresponding number of bytes.
11203 Value is null if no such row exists, i.e. all rows are affected by
11206 static struct glyph_row
*
11207 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11209 int *delta
, *delta_bytes
;
11211 struct glyph_row
*row
;
11212 struct glyph_row
*row_found
= NULL
;
11214 *delta
= *delta_bytes
= 0;
11216 /* Display must not have been paused, otherwise the current matrix
11217 is not up to date. */
11218 if (NILP (w
->window_end_valid
))
11221 /* A value of window_end_pos >= END_UNCHANGED means that the window
11222 end is in the range of changed text. If so, there is no
11223 unchanged row at the end of W's current matrix. */
11224 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11227 /* Set row to the last row in W's current matrix displaying text. */
11228 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11230 /* If matrix is entirely empty, no unchanged row exists. */
11231 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11233 /* The value of row is the last glyph row in the matrix having a
11234 meaningful buffer position in it. The end position of row
11235 corresponds to window_end_pos. This allows us to translate
11236 buffer positions in the current matrix to current buffer
11237 positions for characters not in changed text. */
11238 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11239 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11240 int last_unchanged_pos
, last_unchanged_pos_old
;
11241 struct glyph_row
*first_text_row
11242 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11244 *delta
= Z
- Z_old
;
11245 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11247 /* Set last_unchanged_pos to the buffer position of the last
11248 character in the buffer that has not been changed. Z is the
11249 index + 1 of the last character in current_buffer, i.e. by
11250 subtracting END_UNCHANGED we get the index of the last
11251 unchanged character, and we have to add BEG to get its buffer
11253 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11254 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11256 /* Search backward from ROW for a row displaying a line that
11257 starts at a minimum position >= last_unchanged_pos_old. */
11258 for (; row
> first_text_row
; --row
)
11260 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11263 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11268 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11275 /* Make sure that glyph rows in the current matrix of window W
11276 reference the same glyph memory as corresponding rows in the
11277 frame's frame matrix. This function is called after scrolling W's
11278 current matrix on a terminal frame in try_window_id and
11279 try_window_reusing_current_matrix. */
11282 sync_frame_with_window_matrix_rows (w
)
11285 struct frame
*f
= XFRAME (w
->frame
);
11286 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11288 /* Preconditions: W must be a leaf window and full-width. Its frame
11289 must have a frame matrix. */
11290 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11291 xassert (WINDOW_FULL_WIDTH_P (w
));
11292 xassert (!FRAME_WINDOW_P (f
));
11294 /* If W is a full-width window, glyph pointers in W's current matrix
11295 have, by definition, to be the same as glyph pointers in the
11296 corresponding frame matrix. */
11297 window_row
= w
->current_matrix
->rows
;
11298 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11299 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11300 while (window_row
< window_row_end
)
11304 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11305 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11307 /* Disable frame rows whose corresponding window rows have
11308 been disabled in try_window_id. */
11309 if (!window_row
->enabled_p
)
11310 frame_row
->enabled_p
= 0;
11312 ++window_row
, ++frame_row
;
11317 /* Find the glyph row in window W containing CHARPOS. Consider all
11318 rows between START and END (not inclusive). END null means search
11319 all rows to the end of the display area of W. Value is the row
11320 containing CHARPOS or null. */
11323 row_containing_pos (w
, charpos
, start
, end
, dy
)
11326 struct glyph_row
*start
, *end
;
11329 struct glyph_row
*row
= start
;
11332 /* If we happen to start on a header-line, skip that. */
11333 if (row
->mode_line_p
)
11336 if ((end
&& row
>= end
) || !row
->enabled_p
)
11339 last_y
= window_text_bottom_y (w
) - dy
;
11341 while ((end
== NULL
|| row
< end
)
11342 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11343 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11344 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11345 /* The end position of a row equals the start
11346 position of the next row. If CHARPOS is there, we
11347 would rather display it in the next line, except
11348 when this line ends in ZV. */
11349 && !row
->ends_at_zv_p
11350 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11353 /* Give up if CHARPOS not found. */
11354 if ((end
&& row
>= end
)
11355 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11356 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11363 /* Try to redisplay window W by reusing its existing display. W's
11364 current matrix must be up to date when this function is called,
11365 i.e. window_end_valid must not be nil.
11369 1 if display has been updated
11370 0 if otherwise unsuccessful
11371 -1 if redisplay with same window start is known not to succeed
11373 The following steps are performed:
11375 1. Find the last row in the current matrix of W that is not
11376 affected by changes at the start of current_buffer. If no such row
11379 2. Find the first row in W's current matrix that is not affected by
11380 changes at the end of current_buffer. Maybe there is no such row.
11382 3. Display lines beginning with the row + 1 found in step 1 to the
11383 row found in step 2 or, if step 2 didn't find a row, to the end of
11386 4. If cursor is not known to appear on the window, give up.
11388 5. If display stopped at the row found in step 2, scroll the
11389 display and current matrix as needed.
11391 6. Maybe display some lines at the end of W, if we must. This can
11392 happen under various circumstances, like a partially visible line
11393 becoming fully visible, or because newly displayed lines are displayed
11394 in smaller font sizes.
11396 7. Update W's window end information. */
11402 struct frame
*f
= XFRAME (w
->frame
);
11403 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11404 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11405 struct glyph_row
*last_unchanged_at_beg_row
;
11406 struct glyph_row
*first_unchanged_at_end_row
;
11407 struct glyph_row
*row
;
11408 struct glyph_row
*bottom_row
;
11411 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11412 struct text_pos start_pos
;
11414 int first_unchanged_at_end_vpos
= 0;
11415 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11416 struct text_pos start
;
11417 int first_changed_charpos
, last_changed_charpos
;
11420 if (inhibit_try_window_id
)
11424 /* This is handy for debugging. */
11426 #define GIVE_UP(X) \
11428 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11432 #define GIVE_UP(X) return 0
11435 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11437 /* Don't use this for mini-windows because these can show
11438 messages and mini-buffers, and we don't handle that here. */
11439 if (MINI_WINDOW_P (w
))
11442 /* This flag is used to prevent redisplay optimizations. */
11443 if (windows_or_buffers_changed
)
11446 /* Verify that narrowing has not changed. This flag is also set to prevent
11447 redisplay optimizations. It would be nice to further
11448 reduce the number of cases where this prevents try_window_id. */
11449 if (current_buffer
->clip_changed
)
11452 /* Window must either use window-based redisplay or be full width. */
11453 if (!FRAME_WINDOW_P (f
)
11454 && (!line_ins_del_ok
11455 || !WINDOW_FULL_WIDTH_P (w
)))
11458 /* Give up if point is not known NOT to appear in W. */
11459 if (PT
< CHARPOS (start
))
11462 /* Another way to prevent redisplay optimizations. */
11463 if (XFASTINT (w
->last_modified
) == 0)
11466 /* Verify that window is not hscrolled. */
11467 if (XFASTINT (w
->hscroll
) != 0)
11470 /* Verify that display wasn't paused. */
11471 if (NILP (w
->window_end_valid
))
11474 /* Can't use this if highlighting a region because a cursor movement
11475 will do more than just set the cursor. */
11476 if (!NILP (Vtransient_mark_mode
)
11477 && !NILP (current_buffer
->mark_active
))
11480 /* Likewise if highlighting trailing whitespace. */
11481 if (!NILP (Vshow_trailing_whitespace
))
11484 /* Likewise if showing a region. */
11485 if (!NILP (w
->region_showing
))
11488 /* Can use this if overlay arrow position and or string have changed. */
11489 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11490 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11494 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11495 only if buffer has really changed. The reason is that the gap is
11496 initially at Z for freshly visited files. The code below would
11497 set end_unchanged to 0 in that case. */
11498 if (MODIFF
> SAVE_MODIFF
11499 /* This seems to happen sometimes after saving a buffer. */
11500 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11502 if (GPT
- BEG
< BEG_UNCHANGED
)
11503 BEG_UNCHANGED
= GPT
- BEG
;
11504 if (Z
- GPT
< END_UNCHANGED
)
11505 END_UNCHANGED
= Z
- GPT
;
11508 /* The position of the first and last character that has been changed. */
11509 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11510 last_changed_charpos
= Z
- END_UNCHANGED
;
11512 /* If window starts after a line end, and the last change is in
11513 front of that newline, then changes don't affect the display.
11514 This case happens with stealth-fontification. Note that although
11515 the display is unchanged, glyph positions in the matrix have to
11516 be adjusted, of course. */
11517 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11518 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11519 && ((last_changed_charpos
< CHARPOS (start
)
11520 && CHARPOS (start
) == BEGV
)
11521 || (last_changed_charpos
< CHARPOS (start
) - 1
11522 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11524 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11525 struct glyph_row
*r0
;
11527 /* Compute how many chars/bytes have been added to or removed
11528 from the buffer. */
11529 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11530 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11532 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11534 /* Give up if PT is not in the window. Note that it already has
11535 been checked at the start of try_window_id that PT is not in
11536 front of the window start. */
11537 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11540 /* If window start is unchanged, we can reuse the whole matrix
11541 as is, after adjusting glyph positions. No need to compute
11542 the window end again, since its offset from Z hasn't changed. */
11543 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11544 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11545 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11547 /* Adjust positions in the glyph matrix. */
11548 if (delta
|| delta_bytes
)
11550 struct glyph_row
*r1
11551 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11552 increment_matrix_positions (w
->current_matrix
,
11553 MATRIX_ROW_VPOS (r0
, current_matrix
),
11554 MATRIX_ROW_VPOS (r1
, current_matrix
),
11555 delta
, delta_bytes
);
11558 /* Set the cursor. */
11559 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11560 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11565 /* Handle the case that changes are all below what is displayed in
11566 the window, and that PT is in the window. This shortcut cannot
11567 be taken if ZV is visible in the window, and text has been added
11568 there that is visible in the window. */
11569 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11570 /* ZV is not visible in the window, or there are no
11571 changes at ZV, actually. */
11572 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11573 || first_changed_charpos
== last_changed_charpos
))
11575 struct glyph_row
*r0
;
11577 /* Give up if PT is not in the window. Note that it already has
11578 been checked at the start of try_window_id that PT is not in
11579 front of the window start. */
11580 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11583 /* If window start is unchanged, we can reuse the whole matrix
11584 as is, without changing glyph positions since no text has
11585 been added/removed in front of the window end. */
11586 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11587 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11589 /* We have to compute the window end anew since text
11590 can have been added/removed after it. */
11592 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11593 w
->window_end_bytepos
11594 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11596 /* Set the cursor. */
11597 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11598 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11603 /* Give up if window start is in the changed area.
11605 The condition used to read
11607 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11609 but why that was tested escapes me at the moment. */
11610 if (CHARPOS (start
) >= first_changed_charpos
11611 && CHARPOS (start
) <= last_changed_charpos
)
11614 /* Check that window start agrees with the start of the first glyph
11615 row in its current matrix. Check this after we know the window
11616 start is not in changed text, otherwise positions would not be
11618 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11619 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11622 /* Give up if the window ends in strings. Overlay strings
11623 at the end are difficult to handle, so don't try. */
11624 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11625 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11628 /* Compute the position at which we have to start displaying new
11629 lines. Some of the lines at the top of the window might be
11630 reusable because they are not displaying changed text. Find the
11631 last row in W's current matrix not affected by changes at the
11632 start of current_buffer. Value is null if changes start in the
11633 first line of window. */
11634 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11635 if (last_unchanged_at_beg_row
)
11637 /* Avoid starting to display in the moddle of a character, a TAB
11638 for instance. This is easier than to set up the iterator
11639 exactly, and it's not a frequent case, so the additional
11640 effort wouldn't really pay off. */
11641 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11642 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11643 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11644 --last_unchanged_at_beg_row
;
11646 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11649 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11651 start_pos
= it
.current
.pos
;
11653 /* Start displaying new lines in the desired matrix at the same
11654 vpos we would use in the current matrix, i.e. below
11655 last_unchanged_at_beg_row. */
11656 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11658 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11659 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11661 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11665 /* There are no reusable lines at the start of the window.
11666 Start displaying in the first line. */
11667 start_display (&it
, w
, start
);
11668 start_pos
= it
.current
.pos
;
11671 /* Find the first row that is not affected by changes at the end of
11672 the buffer. Value will be null if there is no unchanged row, in
11673 which case we must redisplay to the end of the window. delta
11674 will be set to the value by which buffer positions beginning with
11675 first_unchanged_at_end_row have to be adjusted due to text
11677 first_unchanged_at_end_row
11678 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11679 IF_DEBUG (debug_delta
= delta
);
11680 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11682 /* Set stop_pos to the buffer position up to which we will have to
11683 display new lines. If first_unchanged_at_end_row != NULL, this
11684 is the buffer position of the start of the line displayed in that
11685 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11686 that we don't stop at a buffer position. */
11688 if (first_unchanged_at_end_row
)
11690 xassert (last_unchanged_at_beg_row
== NULL
11691 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11693 /* If this is a continuation line, move forward to the next one
11694 that isn't. Changes in lines above affect this line.
11695 Caution: this may move first_unchanged_at_end_row to a row
11696 not displaying text. */
11697 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11698 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11699 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11700 < it
.last_visible_y
))
11701 ++first_unchanged_at_end_row
;
11703 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11704 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11705 >= it
.last_visible_y
))
11706 first_unchanged_at_end_row
= NULL
;
11709 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11711 first_unchanged_at_end_vpos
11712 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11713 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11716 else if (last_unchanged_at_beg_row
== NULL
)
11722 /* Either there is no unchanged row at the end, or the one we have
11723 now displays text. This is a necessary condition for the window
11724 end pos calculation at the end of this function. */
11725 xassert (first_unchanged_at_end_row
== NULL
11726 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11728 debug_last_unchanged_at_beg_vpos
11729 = (last_unchanged_at_beg_row
11730 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11732 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11734 #endif /* GLYPH_DEBUG != 0 */
11737 /* Display new lines. Set last_text_row to the last new line
11738 displayed which has text on it, i.e. might end up as being the
11739 line where the window_end_vpos is. */
11740 w
->cursor
.vpos
= -1;
11741 last_text_row
= NULL
;
11742 overlay_arrow_seen
= 0;
11743 while (it
.current_y
< it
.last_visible_y
11744 && !fonts_changed_p
11745 && (first_unchanged_at_end_row
== NULL
11746 || IT_CHARPOS (it
) < stop_pos
))
11748 if (display_line (&it
))
11749 last_text_row
= it
.glyph_row
- 1;
11752 if (fonts_changed_p
)
11756 /* Compute differences in buffer positions, y-positions etc. for
11757 lines reused at the bottom of the window. Compute what we can
11759 if (first_unchanged_at_end_row
11760 /* No lines reused because we displayed everything up to the
11761 bottom of the window. */
11762 && it
.current_y
< it
.last_visible_y
)
11765 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11767 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11768 run
.current_y
= first_unchanged_at_end_row
->y
;
11769 run
.desired_y
= run
.current_y
+ dy
;
11770 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11774 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11775 first_unchanged_at_end_row
= NULL
;
11777 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11780 /* Find the cursor if not already found. We have to decide whether
11781 PT will appear on this window (it sometimes doesn't, but this is
11782 not a very frequent case.) This decision has to be made before
11783 the current matrix is altered. A value of cursor.vpos < 0 means
11784 that PT is either in one of the lines beginning at
11785 first_unchanged_at_end_row or below the window. Don't care for
11786 lines that might be displayed later at the window end; as
11787 mentioned, this is not a frequent case. */
11788 if (w
->cursor
.vpos
< 0)
11790 /* Cursor in unchanged rows at the top? */
11791 if (PT
< CHARPOS (start_pos
)
11792 && last_unchanged_at_beg_row
)
11794 row
= row_containing_pos (w
, PT
,
11795 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11796 last_unchanged_at_beg_row
+ 1, 0);
11798 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11801 /* Start from first_unchanged_at_end_row looking for PT. */
11802 else if (first_unchanged_at_end_row
)
11804 row
= row_containing_pos (w
, PT
- delta
,
11805 first_unchanged_at_end_row
, NULL
, 0);
11807 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11808 delta_bytes
, dy
, dvpos
);
11811 /* Give up if cursor was not found. */
11812 if (w
->cursor
.vpos
< 0)
11814 clear_glyph_matrix (w
->desired_matrix
);
11819 /* Don't let the cursor end in the scroll margins. */
11821 int this_scroll_margin
, cursor_height
;
11823 this_scroll_margin
= max (0, scroll_margin
);
11824 this_scroll_margin
= min (this_scroll_margin
,
11825 XFASTINT (w
->height
) / 4);
11826 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11827 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11829 if ((w
->cursor
.y
< this_scroll_margin
11830 && CHARPOS (start
) > BEGV
)
11831 /* Don't take scroll margin into account at the bottom because
11832 old redisplay didn't do it either. */
11833 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11835 w
->cursor
.vpos
= -1;
11836 clear_glyph_matrix (w
->desired_matrix
);
11841 /* Scroll the display. Do it before changing the current matrix so
11842 that xterm.c doesn't get confused about where the cursor glyph is
11844 if (dy
&& run
.height
)
11848 if (FRAME_WINDOW_P (f
))
11850 rif
->update_window_begin_hook (w
);
11851 rif
->clear_mouse_face (w
);
11852 rif
->scroll_run_hook (w
, &run
);
11853 rif
->update_window_end_hook (w
, 0, 0);
11857 /* Terminal frame. In this case, dvpos gives the number of
11858 lines to scroll by; dvpos < 0 means scroll up. */
11859 int first_unchanged_at_end_vpos
11860 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11861 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11862 int end
= (XFASTINT (w
->top
)
11863 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11864 + window_internal_height (w
));
11866 /* Perform the operation on the screen. */
11869 /* Scroll last_unchanged_at_beg_row to the end of the
11870 window down dvpos lines. */
11871 set_terminal_window (end
);
11873 /* On dumb terminals delete dvpos lines at the end
11874 before inserting dvpos empty lines. */
11875 if (!scroll_region_ok
)
11876 ins_del_lines (end
- dvpos
, -dvpos
);
11878 /* Insert dvpos empty lines in front of
11879 last_unchanged_at_beg_row. */
11880 ins_del_lines (from
, dvpos
);
11882 else if (dvpos
< 0)
11884 /* Scroll up last_unchanged_at_beg_vpos to the end of
11885 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11886 set_terminal_window (end
);
11888 /* Delete dvpos lines in front of
11889 last_unchanged_at_beg_vpos. ins_del_lines will set
11890 the cursor to the given vpos and emit |dvpos| delete
11892 ins_del_lines (from
+ dvpos
, dvpos
);
11894 /* On a dumb terminal insert dvpos empty lines at the
11896 if (!scroll_region_ok
)
11897 ins_del_lines (end
+ dvpos
, -dvpos
);
11900 set_terminal_window (0);
11906 /* Shift reused rows of the current matrix to the right position.
11907 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11909 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11910 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11913 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11914 bottom_vpos
, dvpos
);
11915 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11918 else if (dvpos
> 0)
11920 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11921 bottom_vpos
, dvpos
);
11922 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11923 first_unchanged_at_end_vpos
+ dvpos
, 0);
11926 /* For frame-based redisplay, make sure that current frame and window
11927 matrix are in sync with respect to glyph memory. */
11928 if (!FRAME_WINDOW_P (f
))
11929 sync_frame_with_window_matrix_rows (w
);
11931 /* Adjust buffer positions in reused rows. */
11933 increment_matrix_positions (current_matrix
,
11934 first_unchanged_at_end_vpos
+ dvpos
,
11935 bottom_vpos
, delta
, delta_bytes
);
11937 /* Adjust Y positions. */
11939 shift_glyph_matrix (w
, current_matrix
,
11940 first_unchanged_at_end_vpos
+ dvpos
,
11943 if (first_unchanged_at_end_row
)
11944 first_unchanged_at_end_row
+= dvpos
;
11946 /* If scrolling up, there may be some lines to display at the end of
11948 last_text_row_at_end
= NULL
;
11951 /* Scrolling up can leave for example a partially visible line
11952 at the end of the window to be redisplayed. */
11953 /* Set last_row to the glyph row in the current matrix where the
11954 window end line is found. It has been moved up or down in
11955 the matrix by dvpos. */
11956 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11957 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11959 /* If last_row is the window end line, it should display text. */
11960 xassert (last_row
->displays_text_p
);
11962 /* If window end line was partially visible before, begin
11963 displaying at that line. Otherwise begin displaying with the
11964 line following it. */
11965 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11967 init_to_row_start (&it
, w
, last_row
);
11968 it
.vpos
= last_vpos
;
11969 it
.current_y
= last_row
->y
;
11973 init_to_row_end (&it
, w
, last_row
);
11974 it
.vpos
= 1 + last_vpos
;
11975 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11979 /* We may start in a continuation line. If so, we have to
11980 get the right continuation_lines_width and current_x. */
11981 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11982 it
.hpos
= it
.current_x
= 0;
11984 /* Display the rest of the lines at the window end. */
11985 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11986 while (it
.current_y
< it
.last_visible_y
11987 && !fonts_changed_p
)
11989 /* Is it always sure that the display agrees with lines in
11990 the current matrix? I don't think so, so we mark rows
11991 displayed invalid in the current matrix by setting their
11992 enabled_p flag to zero. */
11993 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11994 if (display_line (&it
))
11995 last_text_row_at_end
= it
.glyph_row
- 1;
11999 /* Update window_end_pos and window_end_vpos. */
12000 if (first_unchanged_at_end_row
12001 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12002 && !last_text_row_at_end
)
12004 /* Window end line if one of the preserved rows from the current
12005 matrix. Set row to the last row displaying text in current
12006 matrix starting at first_unchanged_at_end_row, after
12008 xassert (first_unchanged_at_end_row
->displays_text_p
);
12009 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12010 first_unchanged_at_end_row
);
12011 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12013 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12014 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12016 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12017 xassert (w
->window_end_bytepos
>= 0);
12018 IF_DEBUG (debug_method_add (w
, "A"));
12020 else if (last_text_row_at_end
)
12023 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12024 w
->window_end_bytepos
12025 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12027 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12028 xassert (w
->window_end_bytepos
>= 0);
12029 IF_DEBUG (debug_method_add (w
, "B"));
12031 else if (last_text_row
)
12033 /* We have displayed either to the end of the window or at the
12034 end of the window, i.e. the last row with text is to be found
12035 in the desired matrix. */
12037 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12038 w
->window_end_bytepos
12039 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12041 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12042 xassert (w
->window_end_bytepos
>= 0);
12044 else if (first_unchanged_at_end_row
== NULL
12045 && last_text_row
== NULL
12046 && last_text_row_at_end
== NULL
)
12048 /* Displayed to end of window, but no line containing text was
12049 displayed. Lines were deleted at the end of the window. */
12050 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12051 int vpos
= XFASTINT (w
->window_end_vpos
);
12052 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12053 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12056 row
== NULL
&& vpos
>= first_vpos
;
12057 --vpos
, --current_row
, --desired_row
)
12059 if (desired_row
->enabled_p
)
12061 if (desired_row
->displays_text_p
)
12064 else if (current_row
->displays_text_p
)
12068 xassert (row
!= NULL
);
12069 w
->window_end_vpos
= make_number (vpos
+ 1);
12070 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12071 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12072 xassert (w
->window_end_bytepos
>= 0);
12073 IF_DEBUG (debug_method_add (w
, "C"));
12078 #if 0 /* This leads to problems, for instance when the cursor is
12079 at ZV, and the cursor line displays no text. */
12080 /* Disable rows below what's displayed in the window. This makes
12081 debugging easier. */
12082 enable_glyph_matrix_rows (current_matrix
,
12083 XFASTINT (w
->window_end_vpos
) + 1,
12087 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12088 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12090 /* Record that display has not been completed. */
12091 w
->window_end_valid
= Qnil
;
12092 w
->desired_matrix
->no_scrolling_p
= 1;
12100 /***********************************************************************
12101 More debugging support
12102 ***********************************************************************/
12106 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12107 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12108 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12111 /* Dump the contents of glyph matrix MATRIX on stderr.
12113 GLYPHS 0 means don't show glyph contents.
12114 GLYPHS 1 means show glyphs in short form
12115 GLYPHS > 1 means show glyphs in long form. */
12118 dump_glyph_matrix (matrix
, glyphs
)
12119 struct glyph_matrix
*matrix
;
12123 for (i
= 0; i
< matrix
->nrows
; ++i
)
12124 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12128 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12129 the glyph row and area where the glyph comes from. */
12132 dump_glyph (row
, glyph
, area
)
12133 struct glyph_row
*row
;
12134 struct glyph
*glyph
;
12137 if (glyph
->type
== CHAR_GLYPH
)
12140 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12141 glyph
- row
->glyphs
[TEXT_AREA
],
12144 (BUFFERP (glyph
->object
)
12146 : (STRINGP (glyph
->object
)
12149 glyph
->pixel_width
,
12151 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12155 glyph
->left_box_line_p
,
12156 glyph
->right_box_line_p
);
12158 else if (glyph
->type
== STRETCH_GLYPH
)
12161 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12162 glyph
- row
->glyphs
[TEXT_AREA
],
12165 (BUFFERP (glyph
->object
)
12167 : (STRINGP (glyph
->object
)
12170 glyph
->pixel_width
,
12174 glyph
->left_box_line_p
,
12175 glyph
->right_box_line_p
);
12177 else if (glyph
->type
== IMAGE_GLYPH
)
12180 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12181 glyph
- row
->glyphs
[TEXT_AREA
],
12184 (BUFFERP (glyph
->object
)
12186 : (STRINGP (glyph
->object
)
12189 glyph
->pixel_width
,
12193 glyph
->left_box_line_p
,
12194 glyph
->right_box_line_p
);
12199 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12200 GLYPHS 0 means don't show glyph contents.
12201 GLYPHS 1 means show glyphs in short form
12202 GLYPHS > 1 means show glyphs in long form. */
12205 dump_glyph_row (row
, vpos
, glyphs
)
12206 struct glyph_row
*row
;
12211 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12212 fprintf (stderr
, "=======================================================================\n");
12214 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12215 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12217 MATRIX_ROW_START_CHARPOS (row
),
12218 MATRIX_ROW_END_CHARPOS (row
),
12219 row
->used
[TEXT_AREA
],
12220 row
->contains_overlapping_glyphs_p
,
12222 row
->truncated_on_left_p
,
12223 row
->truncated_on_right_p
,
12224 row
->overlay_arrow_p
,
12226 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12227 row
->displays_text_p
,
12230 row
->ends_in_middle_of_char_p
,
12231 row
->starts_in_middle_of_char_p
,
12237 row
->visible_height
,
12240 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12241 row
->end
.overlay_string_index
,
12242 row
->continuation_lines_width
);
12243 fprintf (stderr
, "%9d %5d\n",
12244 CHARPOS (row
->start
.string_pos
),
12245 CHARPOS (row
->end
.string_pos
));
12246 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12247 row
->end
.dpvec_index
);
12254 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12256 struct glyph
*glyph
= row
->glyphs
[area
];
12257 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12259 /* Glyph for a line end in text. */
12260 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12263 if (glyph
< glyph_end
)
12264 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12266 for (; glyph
< glyph_end
; ++glyph
)
12267 dump_glyph (row
, glyph
, area
);
12270 else if (glyphs
== 1)
12274 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12276 char *s
= (char *) alloca (row
->used
[area
] + 1);
12279 for (i
= 0; i
< row
->used
[area
]; ++i
)
12281 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12282 if (glyph
->type
== CHAR_GLYPH
12283 && glyph
->u
.ch
< 0x80
12284 && glyph
->u
.ch
>= ' ')
12285 s
[i
] = glyph
->u
.ch
;
12291 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12297 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12298 Sdump_glyph_matrix
, 0, 1, "p",
12299 doc
: /* Dump the current matrix of the selected window to stderr.
12300 Shows contents of glyph row structures. With non-nil
12301 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12302 glyphs in short form, otherwise show glyphs in long form. */)
12304 Lisp_Object glyphs
;
12306 struct window
*w
= XWINDOW (selected_window
);
12307 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12309 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12310 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12311 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12312 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12313 fprintf (stderr
, "=============================================\n");
12314 dump_glyph_matrix (w
->current_matrix
,
12315 NILP (glyphs
) ? 0 : XINT (glyphs
));
12320 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12321 doc
: /* Dump glyph row ROW to stderr.
12322 GLYPH 0 means don't dump glyphs.
12323 GLYPH 1 means dump glyphs in short form.
12324 GLYPH > 1 or omitted means dump glyphs in long form. */)
12326 Lisp_Object row
, glyphs
;
12328 struct glyph_matrix
*matrix
;
12331 CHECK_NUMBER (row
);
12332 matrix
= XWINDOW (selected_window
)->current_matrix
;
12334 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12335 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12337 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12342 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12343 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12344 GLYPH 0 means don't dump glyphs.
12345 GLYPH 1 means dump glyphs in short form.
12346 GLYPH > 1 or omitted means dump glyphs in long form. */)
12348 Lisp_Object row
, glyphs
;
12350 struct frame
*sf
= SELECTED_FRAME ();
12351 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12354 CHECK_NUMBER (row
);
12356 if (vpos
>= 0 && vpos
< m
->nrows
)
12357 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12358 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12363 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12364 doc
: /* Toggle tracing of redisplay.
12365 With ARG, turn tracing on if and only if ARG is positive. */)
12370 trace_redisplay_p
= !trace_redisplay_p
;
12373 arg
= Fprefix_numeric_value (arg
);
12374 trace_redisplay_p
= XINT (arg
) > 0;
12381 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12382 doc
: /* Like `format', but print result to stderr. */)
12387 Lisp_Object s
= Fformat (nargs
, args
);
12388 fprintf (stderr
, "%s", SDATA (s
));
12392 #endif /* GLYPH_DEBUG */
12396 /***********************************************************************
12397 Building Desired Matrix Rows
12398 ***********************************************************************/
12400 /* Return a temporary glyph row holding the glyphs of an overlay
12401 arrow. Only used for non-window-redisplay windows. */
12403 static struct glyph_row
*
12404 get_overlay_arrow_glyph_row (w
)
12407 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12408 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12409 struct buffer
*old
= current_buffer
;
12410 unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
12411 int arrow_len
= SCHARS (Voverlay_arrow_string
);
12412 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12416 int n_glyphs_before
;
12418 set_buffer_temp (buffer
);
12419 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12420 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12421 SET_TEXT_POS (it
.position
, 0, 0);
12423 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12425 while (p
< arrow_end
)
12427 Lisp_Object face
, ilisp
;
12429 /* Get the next character. */
12431 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12433 it
.c
= *p
, it
.len
= 1;
12436 /* Get its face. */
12437 ilisp
= make_number (p
- arrow_string
);
12438 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12439 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12441 /* Compute its width, get its glyphs. */
12442 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12443 SET_TEXT_POS (it
.position
, -1, -1);
12444 PRODUCE_GLYPHS (&it
);
12446 /* If this character doesn't fit any more in the line, we have
12447 to remove some glyphs. */
12448 if (it
.current_x
> it
.last_visible_x
)
12450 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12455 set_buffer_temp (old
);
12456 return it
.glyph_row
;
12460 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12461 glyphs are only inserted for terminal frames since we can't really
12462 win with truncation glyphs when partially visible glyphs are
12463 involved. Which glyphs to insert is determined by
12464 produce_special_glyphs. */
12467 insert_left_trunc_glyphs (it
)
12470 struct it truncate_it
;
12471 struct glyph
*from
, *end
, *to
, *toend
;
12473 xassert (!FRAME_WINDOW_P (it
->f
));
12475 /* Get the truncation glyphs. */
12477 truncate_it
.current_x
= 0;
12478 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12479 truncate_it
.glyph_row
= &scratch_glyph_row
;
12480 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12481 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12482 truncate_it
.object
= make_number (0);
12483 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12485 /* Overwrite glyphs from IT with truncation glyphs. */
12486 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12487 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12488 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12489 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12494 /* There may be padding glyphs left over. Overwrite them too. */
12495 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12497 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12503 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12507 /* Compute the pixel height and width of IT->glyph_row.
12509 Most of the time, ascent and height of a display line will be equal
12510 to the max_ascent and max_height values of the display iterator
12511 structure. This is not the case if
12513 1. We hit ZV without displaying anything. In this case, max_ascent
12514 and max_height will be zero.
12516 2. We have some glyphs that don't contribute to the line height.
12517 (The glyph row flag contributes_to_line_height_p is for future
12518 pixmap extensions).
12520 The first case is easily covered by using default values because in
12521 these cases, the line height does not really matter, except that it
12522 must not be zero. */
12525 compute_line_metrics (it
)
12528 struct glyph_row
*row
= it
->glyph_row
;
12531 if (FRAME_WINDOW_P (it
->f
))
12533 int i
, min_y
, max_y
;
12535 /* The line may consist of one space only, that was added to
12536 place the cursor on it. If so, the row's height hasn't been
12538 if (row
->height
== 0)
12540 if (it
->max_ascent
+ it
->max_descent
== 0)
12541 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12542 row
->ascent
= it
->max_ascent
;
12543 row
->height
= it
->max_ascent
+ it
->max_descent
;
12544 row
->phys_ascent
= it
->max_phys_ascent
;
12545 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12548 /* Compute the width of this line. */
12549 row
->pixel_width
= row
->x
;
12550 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12551 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12553 xassert (row
->pixel_width
>= 0);
12554 xassert (row
->ascent
>= 0 && row
->height
> 0);
12556 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12557 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12559 /* If first line's physical ascent is larger than its logical
12560 ascent, use the physical ascent, and make the row taller.
12561 This makes accented characters fully visible. */
12562 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12563 && row
->phys_ascent
> row
->ascent
)
12565 row
->height
+= row
->phys_ascent
- row
->ascent
;
12566 row
->ascent
= row
->phys_ascent
;
12569 /* Compute how much of the line is visible. */
12570 row
->visible_height
= row
->height
;
12572 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12573 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12575 if (row
->y
< min_y
)
12576 row
->visible_height
-= min_y
- row
->y
;
12577 if (row
->y
+ row
->height
> max_y
)
12578 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12582 row
->pixel_width
= row
->used
[TEXT_AREA
];
12583 if (row
->continued_p
)
12584 row
->pixel_width
-= it
->continuation_pixel_width
;
12585 else if (row
->truncated_on_right_p
)
12586 row
->pixel_width
-= it
->truncation_pixel_width
;
12587 row
->ascent
= row
->phys_ascent
= 0;
12588 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12591 /* Compute a hash code for this row. */
12593 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12594 for (i
= 0; i
< row
->used
[area
]; ++i
)
12595 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12596 + row
->glyphs
[area
][i
].u
.val
12597 + row
->glyphs
[area
][i
].face_id
12598 + row
->glyphs
[area
][i
].padding_p
12599 + (row
->glyphs
[area
][i
].type
<< 2));
12601 it
->max_ascent
= it
->max_descent
= 0;
12602 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12606 /* Append one space to the glyph row of iterator IT if doing a
12607 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12608 space have the default face, otherwise let it have the same face as
12609 IT->face_id. Value is non-zero if a space was added.
12611 This function is called to make sure that there is always one glyph
12612 at the end of a glyph row that the cursor can be set on under
12613 window-systems. (If there weren't such a glyph we would not know
12614 how wide and tall a box cursor should be displayed).
12616 At the same time this space let's a nicely handle clearing to the
12617 end of the line if the row ends in italic text. */
12620 append_space (it
, default_face_p
)
12622 int default_face_p
;
12624 if (FRAME_WINDOW_P (it
->f
))
12626 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12628 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12629 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12631 /* Save some values that must not be changed.
12632 Must save IT->c and IT->len because otherwise
12633 ITERATOR_AT_END_P wouldn't work anymore after
12634 append_space has been called. */
12635 enum display_element_type saved_what
= it
->what
;
12636 int saved_c
= it
->c
, saved_len
= it
->len
;
12637 int saved_x
= it
->current_x
;
12638 int saved_face_id
= it
->face_id
;
12639 struct text_pos saved_pos
;
12640 Lisp_Object saved_object
;
12643 saved_object
= it
->object
;
12644 saved_pos
= it
->position
;
12646 it
->what
= IT_CHARACTER
;
12647 bzero (&it
->position
, sizeof it
->position
);
12648 it
->object
= make_number (0);
12652 if (default_face_p
)
12653 it
->face_id
= DEFAULT_FACE_ID
;
12654 else if (it
->face_before_selective_p
)
12655 it
->face_id
= it
->saved_face_id
;
12656 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12657 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12659 PRODUCE_GLYPHS (it
);
12661 it
->current_x
= saved_x
;
12662 it
->object
= saved_object
;
12663 it
->position
= saved_pos
;
12664 it
->what
= saved_what
;
12665 it
->face_id
= saved_face_id
;
12666 it
->len
= saved_len
;
12676 /* Extend the face of the last glyph in the text area of IT->glyph_row
12677 to the end of the display line. Called from display_line.
12678 If the glyph row is empty, add a space glyph to it so that we
12679 know the face to draw. Set the glyph row flag fill_line_p. */
12682 extend_face_to_end_of_line (it
)
12686 struct frame
*f
= it
->f
;
12688 /* If line is already filled, do nothing. */
12689 if (it
->current_x
>= it
->last_visible_x
)
12692 /* Face extension extends the background and box of IT->face_id
12693 to the end of the line. If the background equals the background
12694 of the frame, we don't have to do anything. */
12695 if (it
->face_before_selective_p
)
12696 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12698 face
= FACE_FROM_ID (f
, it
->face_id
);
12700 if (FRAME_WINDOW_P (f
)
12701 && face
->box
== FACE_NO_BOX
12702 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12706 /* Set the glyph row flag indicating that the face of the last glyph
12707 in the text area has to be drawn to the end of the text area. */
12708 it
->glyph_row
->fill_line_p
= 1;
12710 /* If current character of IT is not ASCII, make sure we have the
12711 ASCII face. This will be automatically undone the next time
12712 get_next_display_element returns a multibyte character. Note
12713 that the character will always be single byte in unibyte text. */
12714 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12716 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12719 if (FRAME_WINDOW_P (f
))
12721 /* If the row is empty, add a space with the current face of IT,
12722 so that we know which face to draw. */
12723 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12725 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12726 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12727 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12732 /* Save some values that must not be changed. */
12733 int saved_x
= it
->current_x
;
12734 struct text_pos saved_pos
;
12735 Lisp_Object saved_object
;
12736 enum display_element_type saved_what
= it
->what
;
12737 int saved_face_id
= it
->face_id
;
12739 saved_object
= it
->object
;
12740 saved_pos
= it
->position
;
12742 it
->what
= IT_CHARACTER
;
12743 bzero (&it
->position
, sizeof it
->position
);
12744 it
->object
= make_number (0);
12747 it
->face_id
= face
->id
;
12749 PRODUCE_GLYPHS (it
);
12751 while (it
->current_x
<= it
->last_visible_x
)
12752 PRODUCE_GLYPHS (it
);
12754 /* Don't count these blanks really. It would let us insert a left
12755 truncation glyph below and make us set the cursor on them, maybe. */
12756 it
->current_x
= saved_x
;
12757 it
->object
= saved_object
;
12758 it
->position
= saved_pos
;
12759 it
->what
= saved_what
;
12760 it
->face_id
= saved_face_id
;
12765 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12766 trailing whitespace. */
12769 trailing_whitespace_p (charpos
)
12772 int bytepos
= CHAR_TO_BYTE (charpos
);
12775 while (bytepos
< ZV_BYTE
12776 && (c
= FETCH_CHAR (bytepos
),
12777 c
== ' ' || c
== '\t'))
12780 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12782 if (bytepos
!= PT_BYTE
)
12789 /* Highlight trailing whitespace, if any, in ROW. */
12792 highlight_trailing_whitespace (f
, row
)
12794 struct glyph_row
*row
;
12796 int used
= row
->used
[TEXT_AREA
];
12800 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12801 struct glyph
*glyph
= start
+ used
- 1;
12803 /* Skip over glyphs inserted to display the cursor at the
12804 end of a line, for extending the face of the last glyph
12805 to the end of the line on terminals, and for truncation
12806 and continuation glyphs. */
12807 while (glyph
>= start
12808 && glyph
->type
== CHAR_GLYPH
12809 && INTEGERP (glyph
->object
))
12812 /* If last glyph is a space or stretch, and it's trailing
12813 whitespace, set the face of all trailing whitespace glyphs in
12814 IT->glyph_row to `trailing-whitespace'. */
12816 && BUFFERP (glyph
->object
)
12817 && (glyph
->type
== STRETCH_GLYPH
12818 || (glyph
->type
== CHAR_GLYPH
12819 && glyph
->u
.ch
== ' '))
12820 && trailing_whitespace_p (glyph
->charpos
))
12822 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12824 while (glyph
>= start
12825 && BUFFERP (glyph
->object
)
12826 && (glyph
->type
== STRETCH_GLYPH
12827 || (glyph
->type
== CHAR_GLYPH
12828 && glyph
->u
.ch
== ' ')))
12829 (glyph
--)->face_id
= face_id
;
12835 /* Value is non-zero if glyph row ROW in window W should be
12836 used to hold the cursor. */
12839 cursor_row_p (w
, row
)
12841 struct glyph_row
*row
;
12843 int cursor_row_p
= 1;
12845 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12847 /* If the row ends with a newline from a string, we don't want
12848 the cursor there (if the row is continued it doesn't end in a
12850 if (CHARPOS (row
->end
.string_pos
) >= 0
12851 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12852 cursor_row_p
= row
->continued_p
;
12854 /* If the row ends at ZV, display the cursor at the end of that
12855 row instead of at the start of the row below. */
12856 else if (row
->ends_at_zv_p
)
12862 return cursor_row_p
;
12866 /* Construct the glyph row IT->glyph_row in the desired matrix of
12867 IT->w from text at the current position of IT. See dispextern.h
12868 for an overview of struct it. Value is non-zero if
12869 IT->glyph_row displays text, as opposed to a line displaying ZV
12876 struct glyph_row
*row
= it
->glyph_row
;
12878 /* We always start displaying at hpos zero even if hscrolled. */
12879 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12881 /* We must not display in a row that's not a text row. */
12882 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12883 < it
->w
->desired_matrix
->nrows
);
12885 /* Is IT->w showing the region? */
12886 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12888 /* Clear the result glyph row and enable it. */
12889 prepare_desired_row (row
);
12891 row
->y
= it
->current_y
;
12892 row
->start
= it
->current
;
12893 row
->continuation_lines_width
= it
->continuation_lines_width
;
12894 row
->displays_text_p
= 1;
12895 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12896 it
->starts_in_middle_of_char_p
= 0;
12898 /* Arrange the overlays nicely for our purposes. Usually, we call
12899 display_line on only one line at a time, in which case this
12900 can't really hurt too much, or we call it on lines which appear
12901 one after another in the buffer, in which case all calls to
12902 recenter_overlay_lists but the first will be pretty cheap. */
12903 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12905 /* Move over display elements that are not visible because we are
12906 hscrolled. This may stop at an x-position < IT->first_visible_x
12907 if the first glyph is partially visible or if we hit a line end. */
12908 if (it
->current_x
< it
->first_visible_x
)
12909 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12910 MOVE_TO_POS
| MOVE_TO_X
);
12912 /* Get the initial row height. This is either the height of the
12913 text hscrolled, if there is any, or zero. */
12914 row
->ascent
= it
->max_ascent
;
12915 row
->height
= it
->max_ascent
+ it
->max_descent
;
12916 row
->phys_ascent
= it
->max_phys_ascent
;
12917 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12919 /* Loop generating characters. The loop is left with IT on the next
12920 character to display. */
12923 int n_glyphs_before
, hpos_before
, x_before
;
12925 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12927 /* Retrieve the next thing to display. Value is zero if end of
12929 if (!get_next_display_element (it
))
12931 /* Maybe add a space at the end of this line that is used to
12932 display the cursor there under X. Set the charpos of the
12933 first glyph of blank lines not corresponding to any text
12935 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12936 || row
->used
[TEXT_AREA
] == 0)
12938 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12939 row
->displays_text_p
= 0;
12941 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
12942 && (!MINI_WINDOW_P (it
->w
)
12943 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
12944 row
->indicate_empty_line_p
= 1;
12947 it
->continuation_lines_width
= 0;
12948 row
->ends_at_zv_p
= 1;
12952 /* Now, get the metrics of what we want to display. This also
12953 generates glyphs in `row' (which is IT->glyph_row). */
12954 n_glyphs_before
= row
->used
[TEXT_AREA
];
12957 /* Remember the line height so far in case the next element doesn't
12958 fit on the line. */
12959 if (!it
->truncate_lines_p
)
12961 ascent
= it
->max_ascent
;
12962 descent
= it
->max_descent
;
12963 phys_ascent
= it
->max_phys_ascent
;
12964 phys_descent
= it
->max_phys_descent
;
12967 PRODUCE_GLYPHS (it
);
12969 /* If this display element was in marginal areas, continue with
12971 if (it
->area
!= TEXT_AREA
)
12973 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12974 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12975 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12976 row
->phys_height
= max (row
->phys_height
,
12977 it
->max_phys_ascent
+ it
->max_phys_descent
);
12978 set_iterator_to_next (it
, 1);
12982 /* Does the display element fit on the line? If we truncate
12983 lines, we should draw past the right edge of the window. If
12984 we don't truncate, we want to stop so that we can display the
12985 continuation glyph before the right margin. If lines are
12986 continued, there are two possible strategies for characters
12987 resulting in more than 1 glyph (e.g. tabs): Display as many
12988 glyphs as possible in this line and leave the rest for the
12989 continuation line, or display the whole element in the next
12990 line. Original redisplay did the former, so we do it also. */
12991 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12992 hpos_before
= it
->hpos
;
12995 if (/* Not a newline. */
12997 /* Glyphs produced fit entirely in the line. */
12998 && it
->current_x
< it
->last_visible_x
)
13000 it
->hpos
+= nglyphs
;
13001 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13002 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13003 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13004 row
->phys_height
= max (row
->phys_height
,
13005 it
->max_phys_ascent
+ it
->max_phys_descent
);
13006 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13007 row
->x
= x
- it
->first_visible_x
;
13012 struct glyph
*glyph
;
13014 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13016 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13017 new_x
= x
+ glyph
->pixel_width
;
13019 if (/* Lines are continued. */
13020 !it
->truncate_lines_p
13021 && (/* Glyph doesn't fit on the line. */
13022 new_x
> it
->last_visible_x
13023 /* Or it fits exactly on a window system frame. */
13024 || (new_x
== it
->last_visible_x
13025 && FRAME_WINDOW_P (it
->f
))))
13027 /* End of a continued line. */
13030 || (new_x
== it
->last_visible_x
13031 && FRAME_WINDOW_P (it
->f
)))
13033 /* Current glyph is the only one on the line or
13034 fits exactly on the line. We must continue
13035 the line because we can't draw the cursor
13036 after the glyph. */
13037 row
->continued_p
= 1;
13038 it
->current_x
= new_x
;
13039 it
->continuation_lines_width
+= new_x
;
13041 if (i
== nglyphs
- 1)
13042 set_iterator_to_next (it
, 1);
13044 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13045 && !FRAME_WINDOW_P (it
->f
))
13047 /* A padding glyph that doesn't fit on this line.
13048 This means the whole character doesn't fit
13050 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13052 /* Fill the rest of the row with continuation
13053 glyphs like in 20.x. */
13054 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13055 < row
->glyphs
[1 + TEXT_AREA
])
13056 produce_special_glyphs (it
, IT_CONTINUATION
);
13058 row
->continued_p
= 1;
13059 it
->current_x
= x_before
;
13060 it
->continuation_lines_width
+= x_before
;
13062 /* Restore the height to what it was before the
13063 element not fitting on the line. */
13064 it
->max_ascent
= ascent
;
13065 it
->max_descent
= descent
;
13066 it
->max_phys_ascent
= phys_ascent
;
13067 it
->max_phys_descent
= phys_descent
;
13069 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13071 /* A TAB that extends past the right edge of the
13072 window. This produces a single glyph on
13073 window system frames. We leave the glyph in
13074 this row and let it fill the row, but don't
13075 consume the TAB. */
13076 it
->continuation_lines_width
+= it
->last_visible_x
;
13077 row
->ends_in_middle_of_char_p
= 1;
13078 row
->continued_p
= 1;
13079 glyph
->pixel_width
= it
->last_visible_x
- x
;
13080 it
->starts_in_middle_of_char_p
= 1;
13084 /* Something other than a TAB that draws past
13085 the right edge of the window. Restore
13086 positions to values before the element. */
13087 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13089 /* Display continuation glyphs. */
13090 if (!FRAME_WINDOW_P (it
->f
))
13091 produce_special_glyphs (it
, IT_CONTINUATION
);
13092 row
->continued_p
= 1;
13094 it
->continuation_lines_width
+= x
;
13096 if (nglyphs
> 1 && i
> 0)
13098 row
->ends_in_middle_of_char_p
= 1;
13099 it
->starts_in_middle_of_char_p
= 1;
13102 /* Restore the height to what it was before the
13103 element not fitting on the line. */
13104 it
->max_ascent
= ascent
;
13105 it
->max_descent
= descent
;
13106 it
->max_phys_ascent
= phys_ascent
;
13107 it
->max_phys_descent
= phys_descent
;
13112 else if (new_x
> it
->first_visible_x
)
13114 /* Increment number of glyphs actually displayed. */
13117 if (x
< it
->first_visible_x
)
13118 /* Glyph is partially visible, i.e. row starts at
13119 negative X position. */
13120 row
->x
= x
- it
->first_visible_x
;
13124 /* Glyph is completely off the left margin of the
13125 window. This should not happen because of the
13126 move_it_in_display_line at the start of
13132 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13133 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13134 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13135 row
->phys_height
= max (row
->phys_height
,
13136 it
->max_phys_ascent
+ it
->max_phys_descent
);
13138 /* End of this display line if row is continued. */
13139 if (row
->continued_p
)
13143 /* Is this a line end? If yes, we're also done, after making
13144 sure that a non-default face is extended up to the right
13145 margin of the window. */
13146 if (ITERATOR_AT_END_OF_LINE_P (it
))
13148 int used_before
= row
->used
[TEXT_AREA
];
13150 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13152 /* Add a space at the end of the line that is used to
13153 display the cursor there. */
13154 append_space (it
, 0);
13156 /* Extend the face to the end of the line. */
13157 extend_face_to_end_of_line (it
);
13159 /* Make sure we have the position. */
13160 if (used_before
== 0)
13161 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13163 /* Consume the line end. This skips over invisible lines. */
13164 set_iterator_to_next (it
, 1);
13165 it
->continuation_lines_width
= 0;
13169 /* Proceed with next display element. Note that this skips
13170 over lines invisible because of selective display. */
13171 set_iterator_to_next (it
, 1);
13173 /* If we truncate lines, we are done when the last displayed
13174 glyphs reach past the right margin of the window. */
13175 if (it
->truncate_lines_p
13176 && (FRAME_WINDOW_P (it
->f
)
13177 ? (it
->current_x
>= it
->last_visible_x
)
13178 : (it
->current_x
> it
->last_visible_x
)))
13180 /* Maybe add truncation glyphs. */
13181 if (!FRAME_WINDOW_P (it
->f
))
13185 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13186 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13189 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13191 row
->used
[TEXT_AREA
] = i
;
13192 produce_special_glyphs (it
, IT_TRUNCATION
);
13196 row
->truncated_on_right_p
= 1;
13197 it
->continuation_lines_width
= 0;
13198 reseat_at_next_visible_line_start (it
, 0);
13199 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13200 it
->hpos
= hpos_before
;
13201 it
->current_x
= x_before
;
13206 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13207 at the left window margin. */
13208 if (it
->first_visible_x
13209 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13211 if (!FRAME_WINDOW_P (it
->f
))
13212 insert_left_trunc_glyphs (it
);
13213 row
->truncated_on_left_p
= 1;
13216 /* If the start of this line is the overlay arrow-position, then
13217 mark this glyph row as the one containing the overlay arrow.
13218 This is clearly a mess with variable size fonts. It would be
13219 better to let it be displayed like cursors under X. */
13220 if (MARKERP (Voverlay_arrow_position
)
13221 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13222 && (MATRIX_ROW_START_CHARPOS (row
)
13223 == marker_position (Voverlay_arrow_position
))
13224 && STRINGP (Voverlay_arrow_string
)
13225 && ! overlay_arrow_seen
)
13227 /* Overlay arrow in window redisplay is a fringe bitmap. */
13228 if (!FRAME_WINDOW_P (it
->f
))
13230 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13231 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13232 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13233 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13234 struct glyph
*p2
, *end
;
13236 /* Copy the arrow glyphs. */
13237 while (glyph
< arrow_end
)
13240 /* Throw away padding glyphs. */
13242 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13243 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13249 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13253 overlay_arrow_seen
= 1;
13254 row
->overlay_arrow_p
= 1;
13257 /* Compute pixel dimensions of this line. */
13258 compute_line_metrics (it
);
13260 /* Remember the position at which this line ends. */
13261 row
->end
= it
->current
;
13263 /* Maybe set the cursor. */
13264 if (it
->w
->cursor
.vpos
< 0
13265 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13266 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13267 && cursor_row_p (it
->w
, row
))
13268 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13270 /* Highlight trailing whitespace. */
13271 if (!NILP (Vshow_trailing_whitespace
))
13272 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13274 /* Prepare for the next line. This line starts horizontally at (X
13275 HPOS) = (0 0). Vertical positions are incremented. As a
13276 convenience for the caller, IT->glyph_row is set to the next
13278 it
->current_x
= it
->hpos
= 0;
13279 it
->current_y
+= row
->height
;
13282 return row
->displays_text_p
;
13287 /***********************************************************************
13289 ***********************************************************************/
13291 /* Redisplay the menu bar in the frame for window W.
13293 The menu bar of X frames that don't have X toolkit support is
13294 displayed in a special window W->frame->menu_bar_window.
13296 The menu bar of terminal frames is treated specially as far as
13297 glyph matrices are concerned. Menu bar lines are not part of
13298 windows, so the update is done directly on the frame matrix rows
13299 for the menu bar. */
13302 display_menu_bar (w
)
13305 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13310 /* Don't do all this for graphical frames. */
13312 if (!NILP (Vwindow_system
))
13315 #ifdef USE_X_TOOLKIT
13320 if (FRAME_MAC_P (f
))
13324 #ifdef USE_X_TOOLKIT
13325 xassert (!FRAME_WINDOW_P (f
));
13326 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13327 it
.first_visible_x
= 0;
13328 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13329 #else /* not USE_X_TOOLKIT */
13330 if (FRAME_WINDOW_P (f
))
13332 /* Menu bar lines are displayed in the desired matrix of the
13333 dummy window menu_bar_window. */
13334 struct window
*menu_w
;
13335 xassert (WINDOWP (f
->menu_bar_window
));
13336 menu_w
= XWINDOW (f
->menu_bar_window
);
13337 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13339 it
.first_visible_x
= 0;
13340 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13344 /* This is a TTY frame, i.e. character hpos/vpos are used as
13346 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13348 it
.first_visible_x
= 0;
13349 it
.last_visible_x
= FRAME_WIDTH (f
);
13351 #endif /* not USE_X_TOOLKIT */
13353 if (! mode_line_inverse_video
)
13354 /* Force the menu-bar to be displayed in the default face. */
13355 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13357 /* Clear all rows of the menu bar. */
13358 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13360 struct glyph_row
*row
= it
.glyph_row
+ i
;
13361 clear_glyph_row (row
);
13362 row
->enabled_p
= 1;
13363 row
->full_width_p
= 1;
13366 /* Display all items of the menu bar. */
13367 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13368 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13370 Lisp_Object string
;
13372 /* Stop at nil string. */
13373 string
= AREF (items
, i
+ 1);
13377 /* Remember where item was displayed. */
13378 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13380 /* Display the item, pad with one space. */
13381 if (it
.current_x
< it
.last_visible_x
)
13382 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13383 SCHARS (string
) + 1, 0, 0, -1);
13386 /* Fill out the line with spaces. */
13387 if (it
.current_x
< it
.last_visible_x
)
13388 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13390 /* Compute the total height of the lines. */
13391 compute_line_metrics (&it
);
13396 /***********************************************************************
13398 ***********************************************************************/
13400 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13401 FORCE is non-zero, redisplay mode lines unconditionally.
13402 Otherwise, redisplay only mode lines that are garbaged. Value is
13403 the number of windows whose mode lines were redisplayed. */
13406 redisplay_mode_lines (window
, force
)
13407 Lisp_Object window
;
13412 while (!NILP (window
))
13414 struct window
*w
= XWINDOW (window
);
13416 if (WINDOWP (w
->hchild
))
13417 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13418 else if (WINDOWP (w
->vchild
))
13419 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13421 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13422 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13424 struct text_pos lpoint
;
13425 struct buffer
*old
= current_buffer
;
13427 /* Set the window's buffer for the mode line display. */
13428 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13429 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13431 /* Point refers normally to the selected window. For any
13432 other window, set up appropriate value. */
13433 if (!EQ (window
, selected_window
))
13435 struct text_pos pt
;
13437 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13438 if (CHARPOS (pt
) < BEGV
)
13439 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13440 else if (CHARPOS (pt
) > (ZV
- 1))
13441 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13443 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13446 /* Display mode lines. */
13447 clear_glyph_matrix (w
->desired_matrix
);
13448 if (display_mode_lines (w
))
13451 w
->must_be_updated_p
= 1;
13454 /* Restore old settings. */
13455 set_buffer_internal_1 (old
);
13456 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13466 /* Display the mode and/or top line of window W. Value is the number
13467 of mode lines displayed. */
13470 display_mode_lines (w
)
13473 Lisp_Object old_selected_window
, old_selected_frame
;
13476 old_selected_frame
= selected_frame
;
13477 selected_frame
= w
->frame
;
13478 old_selected_window
= selected_window
;
13479 XSETWINDOW (selected_window
, w
);
13481 /* These will be set while the mode line specs are processed. */
13482 line_number_displayed
= 0;
13483 w
->column_number_displayed
= Qnil
;
13485 if (WINDOW_WANTS_MODELINE_P (w
))
13487 struct window
*sel_w
= XWINDOW (old_selected_window
);
13489 /* Select mode line face based on the real selected window. */
13490 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13491 current_buffer
->mode_line_format
);
13495 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13497 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13498 current_buffer
->header_line_format
);
13502 selected_frame
= old_selected_frame
;
13503 selected_window
= old_selected_window
;
13508 /* Display mode or top line of window W. FACE_ID specifies which line
13509 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13510 FORMAT is the mode line format to display. Value is the pixel
13511 height of the mode line displayed. */
13514 display_mode_line (w
, face_id
, format
)
13516 enum face_id face_id
;
13517 Lisp_Object format
;
13522 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13523 prepare_desired_row (it
.glyph_row
);
13525 if (! mode_line_inverse_video
)
13526 /* Force the mode-line to be displayed in the default face. */
13527 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13529 /* Temporarily make frame's keyboard the current kboard so that
13530 kboard-local variables in the mode_line_format will get the right
13532 push_frame_kboard (it
.f
);
13533 display_mode_element (&it
, 0, 0, 0, format
, Qnil
);
13534 pop_frame_kboard ();
13536 /* Fill up with spaces. */
13537 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13539 compute_line_metrics (&it
);
13540 it
.glyph_row
->full_width_p
= 1;
13541 it
.glyph_row
->mode_line_p
= 1;
13542 it
.glyph_row
->continued_p
= 0;
13543 it
.glyph_row
->truncated_on_left_p
= 0;
13544 it
.glyph_row
->truncated_on_right_p
= 0;
13546 /* Make a 3D mode-line have a shadow at its right end. */
13547 face
= FACE_FROM_ID (it
.f
, face_id
);
13548 extend_face_to_end_of_line (&it
);
13549 if (face
->box
!= FACE_NO_BOX
)
13551 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13552 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13553 last
->right_box_line_p
= 1;
13556 return it
.glyph_row
->height
;
13559 /* Alist that caches the results of :propertize.
13560 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13561 Lisp_Object mode_line_proptrans_alist
;
13563 /* Contribute ELT to the mode line for window IT->w. How it
13564 translates into text depends on its data type.
13566 IT describes the display environment in which we display, as usual.
13568 DEPTH is the depth in recursion. It is used to prevent
13569 infinite recursion here.
13571 FIELD_WIDTH is the number of characters the display of ELT should
13572 occupy in the mode line, and PRECISION is the maximum number of
13573 characters to display from ELT's representation. See
13574 display_string for details.
13576 Returns the hpos of the end of the text generated by ELT. */
13579 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
)
13582 int field_width
, precision
;
13583 Lisp_Object elt
, props
;
13585 int n
= 0, field
, prec
;
13594 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13598 /* A string: output it and check for %-constructs within it. */
13600 unsigned char *this, *lisp_string
;
13604 Lisp_Object oprops
, aelt
;
13605 oprops
= Ftext_properties_at (make_number (0), elt
);
13606 if (NILP (Fequal (props
, oprops
)))
13608 /* If the starting string has properties,
13609 merge the specified ones onto the existing ones. */
13610 if (! NILP (oprops
))
13614 oprops
= Fcopy_sequence (oprops
);
13616 while (CONSP (tem
))
13618 oprops
= Fplist_put (oprops
, XCAR (tem
),
13619 XCAR (XCDR (tem
)));
13620 tem
= XCDR (XCDR (tem
));
13625 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13626 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13630 elt
= Fcopy_sequence (elt
);
13631 Fset_text_properties (0, Flength (elt
), props
, elt
);
13632 mode_line_proptrans_alist
13633 = Fcons (Fcons (elt
, props
),
13634 mode_line_proptrans_alist
);
13639 this = SDATA (elt
);
13640 lisp_string
= this;
13644 prec
= precision
- n
;
13645 if (frame_title_ptr
)
13646 n
+= store_frame_title (SDATA (elt
), -1, prec
);
13648 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
13649 0, prec
, 0, STRING_MULTIBYTE (elt
));
13654 while ((precision
<= 0 || n
< precision
)
13656 && (frame_title_ptr
13657 || it
->current_x
< it
->last_visible_x
))
13659 unsigned char *last
= this;
13661 /* Advance to end of string or next format specifier. */
13662 while ((c
= *this++) != '\0' && c
!= '%')
13665 if (this - 1 != last
)
13667 /* Output to end of string or up to '%'. Field width
13668 is length of string. Don't output more than
13669 PRECISION allows us. */
13672 prec
= chars_in_text (last
, this - last
);
13673 if (precision
> 0 && prec
> precision
- n
)
13674 prec
= precision
- n
;
13676 if (frame_title_ptr
)
13677 n
+= store_frame_title (last
, 0, prec
);
13680 int bytepos
= last
- lisp_string
;
13681 int charpos
= string_byte_to_char (elt
, bytepos
);
13682 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13684 STRING_MULTIBYTE (elt
));
13687 else /* c == '%' */
13689 unsigned char *percent_position
= this;
13691 /* Get the specified minimum width. Zero means
13694 while ((c
= *this++) >= '0' && c
<= '9')
13695 field
= field
* 10 + c
- '0';
13697 /* Don't pad beyond the total padding allowed. */
13698 if (field_width
- n
> 0 && field
> field_width
- n
)
13699 field
= field_width
- n
;
13701 /* Note that either PRECISION <= 0 or N < PRECISION. */
13702 prec
= precision
- n
;
13705 n
+= display_mode_element (it
, depth
, field
, prec
,
13706 Vglobal_mode_string
, props
);
13710 int bytepos
, charpos
;
13711 unsigned char *spec
;
13713 bytepos
= percent_position
- lisp_string
;
13714 charpos
= (STRING_MULTIBYTE (elt
)
13715 ? string_byte_to_char (elt
, bytepos
)
13719 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13721 if (frame_title_ptr
)
13722 n
+= store_frame_title (spec
, field
, prec
);
13725 int nglyphs_before
, nwritten
;
13727 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13728 nwritten
= display_string (spec
, Qnil
, elt
,
13733 /* Assign to the glyphs written above the
13734 string where the `%x' came from, position
13738 struct glyph
*glyph
13739 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13743 for (i
= 0; i
< nwritten
; ++i
)
13745 glyph
[i
].object
= elt
;
13746 glyph
[i
].charpos
= charpos
;
13761 /* A symbol: process the value of the symbol recursively
13762 as if it appeared here directly. Avoid error if symbol void.
13763 Special case: if value of symbol is a string, output the string
13766 register Lisp_Object tem
;
13767 tem
= Fboundp (elt
);
13770 tem
= Fsymbol_value (elt
);
13771 /* If value is a string, output that string literally:
13772 don't check for % within it. */
13776 if (!EQ (tem
, elt
))
13778 /* Give up right away for nil or t. */
13788 register Lisp_Object car
, tem
;
13790 /* A cons cell: five distinct cases.
13791 If first element is :eval or :propertize, do something special.
13792 If first element is a string or a cons, process all the elements
13793 and effectively concatenate them.
13794 If first element is a negative number, truncate displaying cdr to
13795 at most that many characters. If positive, pad (with spaces)
13796 to at least that many characters.
13797 If first element is a symbol, process the cadr or caddr recursively
13798 according to whether the symbol's value is non-nil or nil. */
13800 if (EQ (car
, QCeval
))
13802 /* An element of the form (:eval FORM) means evaluate FORM
13803 and use the result as mode line elements. */
13805 if (CONSP (XCDR (elt
)))
13808 spec
= safe_eval (XCAR (XCDR (elt
)));
13809 n
+= display_mode_element (it
, depth
, field_width
- n
,
13810 precision
- n
, spec
, props
);
13813 else if (EQ (car
, QCpropertize
))
13815 if (CONSP (XCDR (elt
)))
13817 /* An element of the form (:propertize ELT PROPS...)
13818 means display ELT but applying properties PROPS. */
13819 n
+= display_mode_element (it
, depth
, field_width
- n
,
13820 precision
- n
, XCAR (XCDR (elt
)),
13821 XCDR (XCDR (elt
)));
13824 else if (SYMBOLP (car
))
13826 tem
= Fboundp (car
);
13830 /* elt is now the cdr, and we know it is a cons cell.
13831 Use its car if CAR has a non-nil value. */
13834 tem
= Fsymbol_value (car
);
13841 /* Symbol's value is nil (or symbol is unbound)
13842 Get the cddr of the original list
13843 and if possible find the caddr and use that. */
13847 else if (!CONSP (elt
))
13852 else if (INTEGERP (car
))
13854 register int lim
= XINT (car
);
13858 /* Negative int means reduce maximum width. */
13859 if (precision
<= 0)
13862 precision
= min (precision
, -lim
);
13866 /* Padding specified. Don't let it be more than
13867 current maximum. */
13869 lim
= min (precision
, lim
);
13871 /* If that's more padding than already wanted, queue it.
13872 But don't reduce padding already specified even if
13873 that is beyond the current truncation point. */
13874 field_width
= max (lim
, field_width
);
13878 else if (STRINGP (car
) || CONSP (car
))
13880 register int limit
= 50;
13881 /* Limit is to protect against circular lists. */
13884 && (precision
<= 0 || n
< precision
))
13886 n
+= display_mode_element (it
, depth
, field_width
- n
,
13887 precision
- n
, XCAR (elt
), props
);
13896 if (frame_title_ptr
)
13897 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13899 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13900 precision
- n
, 0, 0);
13904 /* Pad to FIELD_WIDTH. */
13905 if (field_width
> 0 && n
< field_width
)
13907 if (frame_title_ptr
)
13908 n
+= store_frame_title ("", field_width
- n
, 0);
13910 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13918 /* Write a null-terminated, right justified decimal representation of
13919 the positive integer D to BUF using a minimal field width WIDTH. */
13922 pint2str (buf
, width
, d
)
13923 register char *buf
;
13924 register int width
;
13927 register char *p
= buf
;
13935 *p
++ = d
% 10 + '0';
13940 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13951 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13952 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13953 type of CODING_SYSTEM. Return updated pointer into BUF. */
13955 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13958 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13959 Lisp_Object coding_system
;
13960 register char *buf
;
13964 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13965 unsigned char *eol_str
;
13967 /* The EOL conversion we are using. */
13968 Lisp_Object eoltype
;
13970 val
= Fget (coding_system
, Qcoding_system
);
13973 if (!VECTORP (val
)) /* Not yet decided. */
13978 eoltype
= eol_mnemonic_undecided
;
13979 /* Don't mention EOL conversion if it isn't decided. */
13983 Lisp_Object eolvalue
;
13985 eolvalue
= Fget (coding_system
, Qeol_type
);
13988 *buf
++ = XFASTINT (AREF (val
, 1));
13992 /* The EOL conversion that is normal on this system. */
13994 if (NILP (eolvalue
)) /* Not yet decided. */
13995 eoltype
= eol_mnemonic_undecided
;
13996 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13997 eoltype
= eol_mnemonic_undecided
;
13998 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13999 eoltype
= (XFASTINT (eolvalue
) == 0
14000 ? eol_mnemonic_unix
14001 : (XFASTINT (eolvalue
) == 1
14002 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14008 /* Mention the EOL conversion if it is not the usual one. */
14009 if (STRINGP (eoltype
))
14011 eol_str
= SDATA (eoltype
);
14012 eol_str_len
= SBYTES (eoltype
);
14014 else if (INTEGERP (eoltype
)
14015 && CHAR_VALID_P (XINT (eoltype
), 0))
14017 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14018 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
14022 eol_str
= invalid_eol_type
;
14023 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14025 bcopy (eol_str
, buf
, eol_str_len
);
14026 buf
+= eol_str_len
;
14032 /* Return a string for the output of a mode line %-spec for window W,
14033 generated by character C. PRECISION >= 0 means don't return a
14034 string longer than that value. FIELD_WIDTH > 0 means pad the
14035 string returned with spaces to that value. Return 1 in *MULTIBYTE
14036 if the result is multibyte text. */
14038 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14041 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14044 int field_width
, precision
;
14048 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14049 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14050 struct buffer
*b
= XBUFFER (w
->buffer
);
14058 if (!NILP (b
->read_only
))
14060 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14065 /* This differs from %* only for a modified read-only buffer. */
14066 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14068 if (!NILP (b
->read_only
))
14073 /* This differs from %* in ignoring read-only-ness. */
14074 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14086 if (command_loop_level
> 5)
14088 p
= decode_mode_spec_buf
;
14089 for (i
= 0; i
< command_loop_level
; i
++)
14092 return decode_mode_spec_buf
;
14100 if (command_loop_level
> 5)
14102 p
= decode_mode_spec_buf
;
14103 for (i
= 0; i
< command_loop_level
; i
++)
14106 return decode_mode_spec_buf
;
14113 /* Let lots_of_dashes be a string of infinite length. */
14114 if (field_width
<= 0
14115 || field_width
> sizeof (lots_of_dashes
))
14117 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14118 decode_mode_spec_buf
[i
] = '-';
14119 decode_mode_spec_buf
[i
] = '\0';
14120 return decode_mode_spec_buf
;
14123 return lots_of_dashes
;
14132 int col
= current_column ();
14133 w
->column_number_displayed
= make_number (col
);
14134 pint2str (decode_mode_spec_buf
, field_width
, col
);
14135 return decode_mode_spec_buf
;
14139 /* %F displays the frame name. */
14140 if (!NILP (f
->title
))
14141 return (char *) SDATA (f
->title
);
14142 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14143 return (char *) SDATA (f
->name
);
14152 int startpos
= XMARKER (w
->start
)->charpos
;
14153 int startpos_byte
= marker_byte_position (w
->start
);
14154 int line
, linepos
, linepos_byte
, topline
;
14156 int height
= XFASTINT (w
->height
);
14158 /* If we decided that this buffer isn't suitable for line numbers,
14159 don't forget that too fast. */
14160 if (EQ (w
->base_line_pos
, w
->buffer
))
14162 /* But do forget it, if the window shows a different buffer now. */
14163 else if (BUFFERP (w
->base_line_pos
))
14164 w
->base_line_pos
= Qnil
;
14166 /* If the buffer is very big, don't waste time. */
14167 if (INTEGERP (Vline_number_display_limit
)
14168 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14170 w
->base_line_pos
= Qnil
;
14171 w
->base_line_number
= Qnil
;
14175 if (!NILP (w
->base_line_number
)
14176 && !NILP (w
->base_line_pos
)
14177 && XFASTINT (w
->base_line_pos
) <= startpos
)
14179 line
= XFASTINT (w
->base_line_number
);
14180 linepos
= XFASTINT (w
->base_line_pos
);
14181 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14186 linepos
= BUF_BEGV (b
);
14187 linepos_byte
= BUF_BEGV_BYTE (b
);
14190 /* Count lines from base line to window start position. */
14191 nlines
= display_count_lines (linepos
, linepos_byte
,
14195 topline
= nlines
+ line
;
14197 /* Determine a new base line, if the old one is too close
14198 or too far away, or if we did not have one.
14199 "Too close" means it's plausible a scroll-down would
14200 go back past it. */
14201 if (startpos
== BUF_BEGV (b
))
14203 w
->base_line_number
= make_number (topline
);
14204 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14206 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14207 || linepos
== BUF_BEGV (b
))
14209 int limit
= BUF_BEGV (b
);
14210 int limit_byte
= BUF_BEGV_BYTE (b
);
14212 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14214 if (startpos
- distance
> limit
)
14216 limit
= startpos
- distance
;
14217 limit_byte
= CHAR_TO_BYTE (limit
);
14220 nlines
= display_count_lines (startpos
, startpos_byte
,
14222 - (height
* 2 + 30),
14224 /* If we couldn't find the lines we wanted within
14225 line_number_display_limit_width chars per line,
14226 give up on line numbers for this window. */
14227 if (position
== limit_byte
&& limit
== startpos
- distance
)
14229 w
->base_line_pos
= w
->buffer
;
14230 w
->base_line_number
= Qnil
;
14234 w
->base_line_number
= make_number (topline
- nlines
);
14235 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14238 /* Now count lines from the start pos to point. */
14239 nlines
= display_count_lines (startpos
, startpos_byte
,
14240 PT_BYTE
, PT
, &junk
);
14242 /* Record that we did display the line number. */
14243 line_number_displayed
= 1;
14245 /* Make the string to show. */
14246 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14247 return decode_mode_spec_buf
;
14250 char* p
= decode_mode_spec_buf
;
14251 int pad
= field_width
- 2;
14257 return decode_mode_spec_buf
;
14263 obj
= b
->mode_name
;
14267 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14273 int pos
= marker_position (w
->start
);
14274 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14276 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14278 if (pos
<= BUF_BEGV (b
))
14283 else if (pos
<= BUF_BEGV (b
))
14287 if (total
> 1000000)
14288 /* Do it differently for a large value, to avoid overflow. */
14289 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14291 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14292 /* We can't normally display a 3-digit number,
14293 so get us a 2-digit number that is close. */
14296 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14297 return decode_mode_spec_buf
;
14301 /* Display percentage of size above the bottom of the screen. */
14304 int toppos
= marker_position (w
->start
);
14305 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14306 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14308 if (botpos
>= BUF_ZV (b
))
14310 if (toppos
<= BUF_BEGV (b
))
14317 if (total
> 1000000)
14318 /* Do it differently for a large value, to avoid overflow. */
14319 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14321 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14322 /* We can't normally display a 3-digit number,
14323 so get us a 2-digit number that is close. */
14326 if (toppos
<= BUF_BEGV (b
))
14327 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14329 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14330 return decode_mode_spec_buf
;
14335 /* status of process */
14336 obj
= Fget_buffer_process (w
->buffer
);
14338 return "no process";
14339 #ifdef subprocesses
14340 obj
= Fsymbol_name (Fprocess_status (obj
));
14344 case 't': /* indicate TEXT or BINARY */
14345 #ifdef MODE_LINE_BINARY_TEXT
14346 return MODE_LINE_BINARY_TEXT (b
);
14352 /* coding-system (not including end-of-line format) */
14354 /* coding-system (including end-of-line type) */
14356 int eol_flag
= (c
== 'Z');
14357 char *p
= decode_mode_spec_buf
;
14359 if (! FRAME_WINDOW_P (f
))
14361 /* No need to mention EOL here--the terminal never needs
14362 to do EOL conversion. */
14363 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14364 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14366 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14369 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14370 #ifdef subprocesses
14371 obj
= Fget_buffer_process (Fcurrent_buffer ());
14372 if (PROCESSP (obj
))
14374 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14376 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14379 #endif /* subprocesses */
14382 return decode_mode_spec_buf
;
14388 *multibyte
= STRING_MULTIBYTE (obj
);
14389 return (char *) SDATA (obj
);
14396 /* Count up to COUNT lines starting from START / START_BYTE.
14397 But don't go beyond LIMIT_BYTE.
14398 Return the number of lines thus found (always nonnegative).
14400 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14403 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14404 int start
, start_byte
, limit_byte
, count
;
14407 register unsigned char *cursor
;
14408 unsigned char *base
;
14410 register int ceiling
;
14411 register unsigned char *ceiling_addr
;
14412 int orig_count
= count
;
14414 /* If we are not in selective display mode,
14415 check only for newlines. */
14416 int selective_display
= (!NILP (current_buffer
->selective_display
)
14417 && !INTEGERP (current_buffer
->selective_display
));
14421 while (start_byte
< limit_byte
)
14423 ceiling
= BUFFER_CEILING_OF (start_byte
);
14424 ceiling
= min (limit_byte
- 1, ceiling
);
14425 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14426 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14429 if (selective_display
)
14430 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14433 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14436 if (cursor
!= ceiling_addr
)
14440 start_byte
+= cursor
- base
+ 1;
14441 *byte_pos_ptr
= start_byte
;
14445 if (++cursor
== ceiling_addr
)
14451 start_byte
+= cursor
- base
;
14456 while (start_byte
> limit_byte
)
14458 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14459 ceiling
= max (limit_byte
, ceiling
);
14460 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14461 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14464 if (selective_display
)
14465 while (--cursor
!= ceiling_addr
14466 && *cursor
!= '\n' && *cursor
!= 015)
14469 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14472 if (cursor
!= ceiling_addr
)
14476 start_byte
+= cursor
- base
+ 1;
14477 *byte_pos_ptr
= start_byte
;
14478 /* When scanning backwards, we should
14479 not count the newline posterior to which we stop. */
14480 return - orig_count
- 1;
14486 /* Here we add 1 to compensate for the last decrement
14487 of CURSOR, which took it past the valid range. */
14488 start_byte
+= cursor
- base
+ 1;
14492 *byte_pos_ptr
= limit_byte
;
14495 return - orig_count
+ count
;
14496 return orig_count
- count
;
14502 /***********************************************************************
14504 ***********************************************************************/
14506 /* Display a NUL-terminated string, starting with index START.
14508 If STRING is non-null, display that C string. Otherwise, the Lisp
14509 string LISP_STRING is displayed.
14511 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14512 FACE_STRING. Display STRING or LISP_STRING with the face at
14513 FACE_STRING_POS in FACE_STRING:
14515 Display the string in the environment given by IT, but use the
14516 standard display table, temporarily.
14518 FIELD_WIDTH is the minimum number of output glyphs to produce.
14519 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14520 with spaces. If STRING has more characters, more than FIELD_WIDTH
14521 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14523 PRECISION is the maximum number of characters to output from
14524 STRING. PRECISION < 0 means don't truncate the string.
14526 This is roughly equivalent to printf format specifiers:
14528 FIELD_WIDTH PRECISION PRINTF
14529 ----------------------------------------
14535 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14536 display them, and < 0 means obey the current buffer's value of
14537 enable_multibyte_characters.
14539 Value is the number of glyphs produced. */
14542 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14543 start
, it
, field_width
, precision
, max_x
, multibyte
)
14544 unsigned char *string
;
14545 Lisp_Object lisp_string
;
14546 Lisp_Object face_string
;
14547 int face_string_pos
;
14550 int field_width
, precision
, max_x
;
14553 int hpos_at_start
= it
->hpos
;
14554 int saved_face_id
= it
->face_id
;
14555 struct glyph_row
*row
= it
->glyph_row
;
14557 /* Initialize the iterator IT for iteration over STRING beginning
14558 with index START. */
14559 reseat_to_string (it
, string
, lisp_string
, start
,
14560 precision
, field_width
, multibyte
);
14562 /* If displaying STRING, set up the face of the iterator
14563 from LISP_STRING, if that's given. */
14564 if (STRINGP (face_string
))
14570 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14571 0, it
->region_beg_charpos
,
14572 it
->region_end_charpos
,
14573 &endptr
, it
->base_face_id
, 0);
14574 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14575 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14578 /* Set max_x to the maximum allowed X position. Don't let it go
14579 beyond the right edge of the window. */
14581 max_x
= it
->last_visible_x
;
14583 max_x
= min (max_x
, it
->last_visible_x
);
14585 /* Skip over display elements that are not visible. because IT->w is
14587 if (it
->current_x
< it
->first_visible_x
)
14588 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14589 MOVE_TO_POS
| MOVE_TO_X
);
14591 row
->ascent
= it
->max_ascent
;
14592 row
->height
= it
->max_ascent
+ it
->max_descent
;
14593 row
->phys_ascent
= it
->max_phys_ascent
;
14594 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14596 /* This condition is for the case that we are called with current_x
14597 past last_visible_x. */
14598 while (it
->current_x
< max_x
)
14600 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14602 /* Get the next display element. */
14603 if (!get_next_display_element (it
))
14606 /* Produce glyphs. */
14607 x_before
= it
->current_x
;
14608 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14609 PRODUCE_GLYPHS (it
);
14611 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14614 while (i
< nglyphs
)
14616 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14618 if (!it
->truncate_lines_p
14619 && x
+ glyph
->pixel_width
> max_x
)
14621 /* End of continued line or max_x reached. */
14622 if (CHAR_GLYPH_PADDING_P (*glyph
))
14624 /* A wide character is unbreakable. */
14625 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14626 it
->current_x
= x_before
;
14630 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14635 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14637 /* Glyph is at least partially visible. */
14639 if (x
< it
->first_visible_x
)
14640 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14644 /* Glyph is off the left margin of the display area.
14645 Should not happen. */
14649 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14650 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14651 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14652 row
->phys_height
= max (row
->phys_height
,
14653 it
->max_phys_ascent
+ it
->max_phys_descent
);
14654 x
+= glyph
->pixel_width
;
14658 /* Stop if max_x reached. */
14662 /* Stop at line ends. */
14663 if (ITERATOR_AT_END_OF_LINE_P (it
))
14665 it
->continuation_lines_width
= 0;
14669 set_iterator_to_next (it
, 1);
14671 /* Stop if truncating at the right edge. */
14672 if (it
->truncate_lines_p
14673 && it
->current_x
>= it
->last_visible_x
)
14675 /* Add truncation mark, but don't do it if the line is
14676 truncated at a padding space. */
14677 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14679 if (!FRAME_WINDOW_P (it
->f
))
14683 if (it
->current_x
> it
->last_visible_x
)
14685 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14686 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14688 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14690 row
->used
[TEXT_AREA
] = i
;
14691 produce_special_glyphs (it
, IT_TRUNCATION
);
14694 produce_special_glyphs (it
, IT_TRUNCATION
);
14696 it
->glyph_row
->truncated_on_right_p
= 1;
14702 /* Maybe insert a truncation at the left. */
14703 if (it
->first_visible_x
14704 && IT_CHARPOS (*it
) > 0)
14706 if (!FRAME_WINDOW_P (it
->f
))
14707 insert_left_trunc_glyphs (it
);
14708 it
->glyph_row
->truncated_on_left_p
= 1;
14711 it
->face_id
= saved_face_id
;
14713 /* Value is number of columns displayed. */
14714 return it
->hpos
- hpos_at_start
;
14719 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
14720 appears as an element of LIST or as the car of an element of LIST.
14721 If PROPVAL is a list, compare each element against LIST in that
14722 way, and return 1/2 if any element of PROPVAL is found in LIST.
14723 Otherwise return 0. This function cannot quit.
14724 The return value is 2 if the text is invisible but with an ellipsis
14725 and 1 if it's invisible and without an ellipsis. */
14728 invisible_p (propval
, list
)
14729 register Lisp_Object propval
;
14732 register Lisp_Object tail
, proptail
;
14734 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14736 register Lisp_Object tem
;
14738 if (EQ (propval
, tem
))
14740 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14741 return NILP (XCDR (tem
)) ? 1 : 2;
14744 if (CONSP (propval
))
14746 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14748 Lisp_Object propelt
;
14749 propelt
= XCAR (proptail
);
14750 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14752 register Lisp_Object tem
;
14754 if (EQ (propelt
, tem
))
14756 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14757 return NILP (XCDR (tem
)) ? 1 : 2;
14766 /***********************************************************************
14768 ***********************************************************************/
14773 Vwith_echo_area_save_vector
= Qnil
;
14774 staticpro (&Vwith_echo_area_save_vector
);
14776 Vmessage_stack
= Qnil
;
14777 staticpro (&Vmessage_stack
);
14779 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14780 staticpro (&Qinhibit_redisplay
);
14782 message_dolog_marker1
= Fmake_marker ();
14783 staticpro (&message_dolog_marker1
);
14784 message_dolog_marker2
= Fmake_marker ();
14785 staticpro (&message_dolog_marker2
);
14786 message_dolog_marker3
= Fmake_marker ();
14787 staticpro (&message_dolog_marker3
);
14790 defsubr (&Sdump_glyph_matrix
);
14791 defsubr (&Sdump_glyph_row
);
14792 defsubr (&Sdump_tool_bar_row
);
14793 defsubr (&Strace_redisplay
);
14794 defsubr (&Strace_to_stderr
);
14796 #ifdef HAVE_WINDOW_SYSTEM
14797 defsubr (&Stool_bar_lines_needed
);
14800 staticpro (&Qmenu_bar_update_hook
);
14801 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14803 staticpro (&Qoverriding_terminal_local_map
);
14804 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14806 staticpro (&Qoverriding_local_map
);
14807 Qoverriding_local_map
= intern ("overriding-local-map");
14809 staticpro (&Qwindow_scroll_functions
);
14810 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14812 staticpro (&Qredisplay_end_trigger_functions
);
14813 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14815 staticpro (&Qinhibit_point_motion_hooks
);
14816 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14818 QCdata
= intern (":data");
14819 staticpro (&QCdata
);
14820 Qdisplay
= intern ("display");
14821 staticpro (&Qdisplay
);
14822 Qspace_width
= intern ("space-width");
14823 staticpro (&Qspace_width
);
14824 Qraise
= intern ("raise");
14825 staticpro (&Qraise
);
14826 Qspace
= intern ("space");
14827 staticpro (&Qspace
);
14828 Qmargin
= intern ("margin");
14829 staticpro (&Qmargin
);
14830 Qleft_margin
= intern ("left-margin");
14831 staticpro (&Qleft_margin
);
14832 Qright_margin
= intern ("right-margin");
14833 staticpro (&Qright_margin
);
14834 Qalign_to
= intern ("align-to");
14835 staticpro (&Qalign_to
);
14836 QCalign_to
= intern (":align-to");
14837 staticpro (&QCalign_to
);
14838 Qrelative_width
= intern ("relative-width");
14839 staticpro (&Qrelative_width
);
14840 QCrelative_width
= intern (":relative-width");
14841 staticpro (&QCrelative_width
);
14842 QCrelative_height
= intern (":relative-height");
14843 staticpro (&QCrelative_height
);
14844 QCeval
= intern (":eval");
14845 staticpro (&QCeval
);
14846 QCpropertize
= intern (":propertize");
14847 staticpro (&QCpropertize
);
14848 Qwhen
= intern ("when");
14849 staticpro (&Qwhen
);
14850 QCfile
= intern (":file");
14851 staticpro (&QCfile
);
14852 Qfontified
= intern ("fontified");
14853 staticpro (&Qfontified
);
14854 Qfontification_functions
= intern ("fontification-functions");
14855 staticpro (&Qfontification_functions
);
14856 Qtrailing_whitespace
= intern ("trailing-whitespace");
14857 staticpro (&Qtrailing_whitespace
);
14858 Qimage
= intern ("image");
14859 staticpro (&Qimage
);
14860 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14861 staticpro (&Qmessage_truncate_lines
);
14862 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
14863 staticpro (&Qcursor_in_non_selected_windows
);
14864 Qgrow_only
= intern ("grow-only");
14865 staticpro (&Qgrow_only
);
14866 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14867 staticpro (&Qinhibit_menubar_update
);
14868 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14869 staticpro (&Qinhibit_eval_during_redisplay
);
14870 Qposition
= intern ("position");
14871 staticpro (&Qposition
);
14872 Qbuffer_position
= intern ("buffer-position");
14873 staticpro (&Qbuffer_position
);
14874 Qobject
= intern ("object");
14875 staticpro (&Qobject
);
14877 last_arrow_position
= Qnil
;
14878 last_arrow_string
= Qnil
;
14879 staticpro (&last_arrow_position
);
14880 staticpro (&last_arrow_string
);
14882 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14883 staticpro (&echo_buffer
[0]);
14884 staticpro (&echo_buffer
[1]);
14886 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14887 staticpro (&echo_area_buffer
[0]);
14888 staticpro (&echo_area_buffer
[1]);
14890 Vmessages_buffer_name
= build_string ("*Messages*");
14891 staticpro (&Vmessages_buffer_name
);
14893 mode_line_proptrans_alist
= Qnil
;
14894 staticpro (&mode_line_proptrans_alist
);
14896 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14897 doc
: /* Non-nil means highlight trailing whitespace.
14898 The face used for trailing whitespace is `trailing-whitespace'. */);
14899 Vshow_trailing_whitespace
= Qnil
;
14901 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14902 doc
: /* Non-nil means don't actually do any redisplay.
14903 This is used for internal purposes. */);
14904 Vinhibit_redisplay
= Qnil
;
14906 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14907 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
14908 Vglobal_mode_string
= Qnil
;
14910 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14911 doc
: /* Marker for where to display an arrow on top of the buffer text.
14912 This must be the beginning of a line in order to work.
14913 See also `overlay-arrow-string'. */);
14914 Voverlay_arrow_position
= Qnil
;
14916 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14917 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
14918 Voverlay_arrow_string
= Qnil
;
14920 DEFVAR_INT ("scroll-step", &scroll_step
,
14921 doc
: /* *The number of lines to try scrolling a window by when point moves out.
14922 If that fails to bring point back on frame, point is centered instead.
14923 If this is zero, point is always centered after it moves off frame.
14924 If you want scrolling to always be a line at a time, you should set
14925 `scroll-conservatively' to a large value rather than set this to 1. */);
14927 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14928 doc
: /* *Scroll up to this many lines, to bring point back on screen.
14929 A value of zero means to scroll the text to center point vertically
14930 in the window. */);
14931 scroll_conservatively
= 0;
14933 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14934 doc
: /* *Number of lines of margin at the top and bottom of a window.
14935 Recenter the window whenever point gets within this many lines
14936 of the top or bottom of the window. */);
14940 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
14943 DEFVAR_BOOL ("truncate-partial-width-windows",
14944 &truncate_partial_width_windows
,
14945 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
14946 truncate_partial_width_windows
= 1;
14948 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14949 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
14950 Any other value means to use the appropriate face, `mode-line',
14951 `header-line', or `menu' respectively.
14953 This variable is deprecated; please change the above faces instead. */);
14954 mode_line_inverse_video
= 1;
14956 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14957 doc
: /* *Maximum buffer size for which line number should be displayed.
14958 If the buffer is bigger than this, the line number does not appear
14959 in the mode line. A value of nil means no limit. */);
14960 Vline_number_display_limit
= Qnil
;
14962 DEFVAR_INT ("line-number-display-limit-width",
14963 &line_number_display_limit_width
,
14964 doc
: /* *Maximum line width (in characters) for line number display.
14965 If the average length of the lines near point is bigger than this, then the
14966 line number may be omitted from the mode line. */);
14967 line_number_display_limit_width
= 200;
14969 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14970 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
14971 highlight_nonselected_windows
= 0;
14973 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14974 doc
: /* Non-nil if more than one frame is visible on this display.
14975 Minibuffer-only frames don't count, but iconified frames do.
14976 This variable is not guaranteed to be accurate except while processing
14977 `frame-title-format' and `icon-title-format'. */);
14979 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14980 doc
: /* Template for displaying the title bar of visible frames.
14981 \(Assuming the window manager supports this feature.)
14982 This variable has the same structure as `mode-line-format' (which see),
14983 and is used only on frames for which no explicit name has been set
14984 \(see `modify-frame-parameters'). */);
14985 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14986 doc
: /* Template for displaying the title bar of an iconified frame.
14987 \(Assuming the window manager supports this feature.)
14988 This variable has the same structure as `mode-line-format' (which see),
14989 and is used only on frames for which no explicit name has been set
14990 \(see `modify-frame-parameters'). */);
14992 = Vframe_title_format
14993 = Fcons (intern ("multiple-frames"),
14994 Fcons (build_string ("%b"),
14995 Fcons (Fcons (empty_string
,
14996 Fcons (intern ("invocation-name"),
14997 Fcons (build_string ("@"),
14998 Fcons (intern ("system-name"),
15002 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
15003 doc
: /* Maximum number of lines to keep in the message log buffer.
15004 If nil, disable message logging. If t, log messages but don't truncate
15005 the buffer when it becomes large. */);
15006 Vmessage_log_max
= make_number (50);
15008 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
15009 doc
: /* Functions called before redisplay, if window sizes have changed.
15010 The value should be a list of functions that take one argument.
15011 Just before redisplay, for each frame, if any of its windows have changed
15012 size since the last redisplay, or have been split or deleted,
15013 all the functions in the list are called, with the frame as argument. */);
15014 Vwindow_size_change_functions
= Qnil
;
15016 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
15017 doc
: /* List of Functions to call before redisplaying a window with scrolling.
15018 Each function is called with two arguments, the window
15019 and its new display-start position. Note that the value of `window-end'
15020 is not valid when these functions are called. */);
15021 Vwindow_scroll_functions
= Qnil
;
15023 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15024 doc
: /* *Non-nil means automatically resize tool-bars.
15025 This increases a tool-bar's height if not all tool-bar items are visible.
15026 It decreases a tool-bar's height when it would display blank lines
15028 auto_resize_tool_bars_p
= 1;
15030 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15031 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15032 auto_raise_tool_bar_buttons_p
= 1;
15034 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15035 doc
: /* *Margin around tool-bar buttons in pixels.
15036 If an integer, use that for both horizontal and vertical margins.
15037 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15038 HORZ specifying the horizontal margin, and VERT specifying the
15039 vertical margin. */);
15040 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15042 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15043 doc
: /* *Relief thickness of tool-bar buttons. */);
15044 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15046 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15047 doc
: /* List of functions to call to fontify regions of text.
15048 Each function is called with one argument POS. Functions must
15049 fontify a region starting at POS in the current buffer, and give
15050 fontified regions the property `fontified'. */);
15051 Vfontification_functions
= Qnil
;
15052 Fmake_variable_buffer_local (Qfontification_functions
);
15054 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15055 &unibyte_display_via_language_environment
,
15056 doc
: /* *Non-nil means display unibyte text according to language environment.
15057 Specifically this means that unibyte non-ASCII characters
15058 are displayed by converting them to the equivalent multibyte characters
15059 according to the current language environment. As a result, they are
15060 displayed according to the current fontset. */);
15061 unibyte_display_via_language_environment
= 0;
15063 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15064 doc
: /* *Maximum height for resizing mini-windows.
15065 If a float, it specifies a fraction of the mini-window frame's height.
15066 If an integer, it specifies a number of lines. */);
15067 Vmax_mini_window_height
= make_float (0.25);
15069 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15070 doc
: /* *How to resize mini-windows.
15071 A value of nil means don't automatically resize mini-windows.
15072 A value of t means resize them to fit the text displayed in them.
15073 A value of `grow-only', the default, means let mini-windows grow
15074 only, until their display becomes empty, at which point the windows
15075 go back to their normal size. */);
15076 Vresize_mini_windows
= Qgrow_only
;
15078 DEFVAR_BOOL ("cursor-in-non-selected-windows",
15079 &cursor_in_non_selected_windows
,
15080 doc
: /* *Non-nil means display a hollow cursor in non-selected windows.
15081 nil means don't display a cursor there. */);
15082 cursor_in_non_selected_windows
= 1;
15084 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
15085 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15086 automatic_hscrolling_p
= 1;
15088 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
15089 doc
: /* *How many columns away from the window edge point is allowed to get
15090 before automatic hscrolling will horizontally scroll the window. */);
15091 hscroll_margin
= 5;
15093 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
15094 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15095 When point is less than `automatic-hscroll-margin' columns from the window
15096 edge, automatic hscrolling will scroll the window by the amount of columns
15097 determined by this variable. If its value is a positive integer, scroll that
15098 many columns. If it's a positive floating-point number, it specifies the
15099 fraction of the window's width to scroll. If it's nil or zero, point will be
15100 centered horizontally after the scroll. Any other value, including negative
15101 numbers, are treated as if the value were zero.
15103 Automatic hscrolling always moves point outside the scroll margin, so if
15104 point was more than scroll step columns inside the margin, the window will
15105 scroll more than the value given by the scroll step.
15107 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15108 and `scroll-right' overrides this variable's effect. */);
15109 Vhscroll_step
= make_number (0);
15111 DEFVAR_LISP ("image-types", &Vimage_types
,
15112 doc
: /* List of supported image types.
15113 Each element of the list is a symbol for a supported image type. */);
15114 Vimage_types
= Qnil
;
15116 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15117 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15118 Bind this around calls to `message' to let it take effect. */);
15119 message_truncate_lines
= 0;
15121 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15122 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15123 Can be used to update submenus whose contents should vary. */);
15124 Vmenu_bar_update_hook
= Qnil
;
15126 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15127 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15128 inhibit_menubar_update
= 0;
15130 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15131 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15132 inhibit_eval_during_redisplay
= 0;
15135 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15136 doc
: /* Inhibit try_window_id display optimization. */);
15137 inhibit_try_window_id
= 0;
15139 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15140 doc
: /* Inhibit try_window_reusing display optimization. */);
15141 inhibit_try_window_reusing
= 0;
15143 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15144 doc
: /* Inhibit try_cursor_movement display optimization. */);
15145 inhibit_try_cursor_movement
= 0;
15146 #endif /* GLYPH_DEBUG */
15150 /* Initialize this module when Emacs starts. */
15155 Lisp_Object root_window
;
15156 struct window
*mini_w
;
15158 current_header_line_height
= current_mode_line_height
= -1;
15160 CHARPOS (this_line_start_pos
) = 0;
15162 mini_w
= XWINDOW (minibuf_window
);
15163 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15165 if (!noninteractive
)
15167 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15170 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15171 set_window_height (root_window
,
15172 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15174 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15175 set_window_height (minibuf_window
, 1, 0);
15177 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15178 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15180 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15181 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15182 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15184 /* The default ellipsis glyphs `...'. */
15185 for (i
= 0; i
< 3; ++i
)
15186 default_invis_vector
[i
] = make_number ('.');
15189 #ifdef HAVE_WINDOW_SYSTEM
15191 /* Allocate the buffer for frame titles. */
15193 frame_title_buf
= (char *) xmalloc (size
);
15194 frame_title_buf_end
= frame_title_buf
+ size
;
15195 frame_title_ptr
= NULL
;
15197 #endif /* HAVE_WINDOW_SYSTEM */
15199 help_echo_showing_p
= 0;