1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the 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 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 int scroll_step
;
388 /* Nonzero means scroll just far enough to bring point back on the
389 screen, when appropriate. */
391 static 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. */
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 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 int automatic_hscroll_margin
;
589 /* How much to scroll horizontally when point is inside the above margin. */
590 Lisp_Object Vautomatic_hscroll_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, int, 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
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1173 unsigned char *p
= XSTRING (string
)->data
+ 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 (Vminibuf_selected_window
)
1586 && w
== XWINDOW (Vminibuf_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
= XSTRING (it
->overlay_strings
[i
])->data
;
1868 char *e
= s
+ STRING_BYTES (XSTRING (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
) >= XSTRING (it
->string
)->size
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
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2475 int rest
= STRING_BYTES (XSTRING (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
, XSTRING (it
->string
)->size
);
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 struct Lisp_String
*s
= XSTRING (it
->string
);
2591 IT_STRING_CHARPOS (*it
) = s
->size
;
2592 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2599 int invis_p
, newpos
, next_stop
, start_charpos
;
2600 Lisp_Object pos
, prop
, overlay
;
2602 /* First of all, is there invisible text at this position? */
2603 start_charpos
= IT_CHARPOS (*it
);
2604 pos
= make_number (IT_CHARPOS (*it
));
2605 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2607 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2609 /* If we are on invisible text, skip over it. */
2610 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2612 /* Record whether we have to display an ellipsis for the
2614 int display_ellipsis_p
= invis_p
== 2;
2616 handled
= HANDLED_RECOMPUTE_PROPS
;
2618 /* Loop skipping over invisible text. The loop is left at
2619 ZV or with IT on the first char being visible again. */
2622 /* Try to skip some invisible text. Return value is the
2623 position reached which can be equal to IT's position
2624 if there is nothing invisible here. This skips both
2625 over invisible text properties and overlays with
2626 invisible property. */
2627 newpos
= skip_invisible (IT_CHARPOS (*it
),
2628 &next_stop
, ZV
, it
->window
);
2630 /* If we skipped nothing at all we weren't at invisible
2631 text in the first place. If everything to the end of
2632 the buffer was skipped, end the loop. */
2633 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2637 /* We skipped some characters but not necessarily
2638 all there are. Check if we ended up on visible
2639 text. Fget_char_property returns the property of
2640 the char before the given position, i.e. if we
2641 get invis_p = 0, this means that the char at
2642 newpos is visible. */
2643 pos
= make_number (newpos
);
2644 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2645 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2648 /* If we ended up on invisible text, proceed to
2649 skip starting with next_stop. */
2651 IT_CHARPOS (*it
) = next_stop
;
2655 /* The position newpos is now either ZV or on visible text. */
2656 IT_CHARPOS (*it
) = newpos
;
2657 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2659 /* If there are before-strings at the start of invisible
2660 text, and the text is invisible because of a text
2661 property, arrange to show before-strings because 20.x did
2662 it that way. (If the text is invisible because of an
2663 overlay property instead of a text property, this is
2664 already handled in the overlay code.) */
2666 && get_overlay_strings (it
, start_charpos
))
2668 handled
= HANDLED_RECOMPUTE_PROPS
;
2669 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2671 else if (display_ellipsis_p
)
2672 setup_for_ellipsis (it
);
2680 /* Make iterator IT return `...' next. */
2683 setup_for_ellipsis (it
)
2687 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2689 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2690 it
->dpvec
= v
->contents
;
2691 it
->dpend
= v
->contents
+ v
->size
;
2695 /* Default `...'. */
2696 it
->dpvec
= default_invis_vector
;
2697 it
->dpend
= default_invis_vector
+ 3;
2700 /* The ellipsis display does not replace the display of the
2701 character at the new position. Indicate this by setting
2702 IT->dpvec_char_len to zero. */
2703 it
->dpvec_char_len
= 0;
2705 it
->current
.dpvec_index
= 0;
2706 it
->method
= next_element_from_display_vector
;
2711 /***********************************************************************
2713 ***********************************************************************/
2715 /* Set up iterator IT from `display' property at its current position.
2716 Called from handle_stop. */
2718 static enum prop_handled
2719 handle_display_prop (it
)
2722 Lisp_Object prop
, object
;
2723 struct text_pos
*position
;
2724 int display_replaced_p
= 0;
2726 if (STRINGP (it
->string
))
2728 object
= it
->string
;
2729 position
= &it
->current
.string_pos
;
2733 object
= it
->w
->buffer
;
2734 position
= &it
->current
.pos
;
2737 /* Reset those iterator values set from display property values. */
2738 it
->font_height
= Qnil
;
2739 it
->space_width
= Qnil
;
2742 /* We don't support recursive `display' properties, i.e. string
2743 values that have a string `display' property, that have a string
2744 `display' property etc. */
2745 if (!it
->string_from_display_prop_p
)
2746 it
->area
= TEXT_AREA
;
2748 prop
= Fget_char_property (make_number (position
->charpos
),
2751 return HANDLED_NORMALLY
;
2754 /* Simple properties. */
2755 && !EQ (XCAR (prop
), Qimage
)
2756 && !EQ (XCAR (prop
), Qspace
)
2757 && !EQ (XCAR (prop
), Qwhen
)
2758 && !EQ (XCAR (prop
), Qspace_width
)
2759 && !EQ (XCAR (prop
), Qheight
)
2760 && !EQ (XCAR (prop
), Qraise
)
2761 /* Marginal area specifications. */
2762 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2763 && !NILP (XCAR (prop
)))
2765 for (; CONSP (prop
); prop
= XCDR (prop
))
2767 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2768 position
, display_replaced_p
))
2769 display_replaced_p
= 1;
2772 else if (VECTORP (prop
))
2775 for (i
= 0; i
< ASIZE (prop
); ++i
)
2776 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2777 position
, display_replaced_p
))
2778 display_replaced_p
= 1;
2782 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2783 display_replaced_p
= 1;
2786 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2790 /* Value is the position of the end of the `display' property starting
2791 at START_POS in OBJECT. */
2793 static struct text_pos
2794 display_prop_end (it
, object
, start_pos
)
2797 struct text_pos start_pos
;
2800 struct text_pos end_pos
;
2802 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2803 Qdisplay
, object
, Qnil
);
2804 CHARPOS (end_pos
) = XFASTINT (end
);
2805 if (STRINGP (object
))
2806 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2808 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2814 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2815 is the object in which the `display' property was found. *POSITION
2816 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2817 means that we previously saw a display sub-property which already
2818 replaced text display with something else, for example an image;
2819 ignore such properties after the first one has been processed.
2821 If PROP is a `space' or `image' sub-property, set *POSITION to the
2822 end position of the `display' property.
2824 Value is non-zero if something was found which replaces the display
2825 of buffer or string text. */
2828 handle_single_display_prop (it
, prop
, object
, position
,
2829 display_replaced_before_p
)
2833 struct text_pos
*position
;
2834 int display_replaced_before_p
;
2837 int replaces_text_display_p
= 0;
2840 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2841 evaluated. If the result is nil, VALUE is ignored. */
2843 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2852 if (!NILP (form
) && !EQ (form
, Qt
))
2854 int count
= BINDING_STACK_SIZE ();
2855 struct gcpro gcpro1
;
2857 /* Bind `object' to the object having the `display' property, a
2858 buffer or string. Bind `position' to the position in the
2859 object where the property was found, and `buffer-position'
2860 to the current position in the buffer. */
2861 specbind (Qobject
, object
);
2862 specbind (Qposition
, make_number (CHARPOS (*position
)));
2863 specbind (Qbuffer_position
,
2864 make_number (STRINGP (object
)
2865 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2867 form
= safe_eval (form
);
2869 unbind_to (count
, Qnil
);
2876 && EQ (XCAR (prop
), Qheight
)
2877 && CONSP (XCDR (prop
)))
2879 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2882 /* `(height HEIGHT)'. */
2883 it
->font_height
= XCAR (XCDR (prop
));
2884 if (!NILP (it
->font_height
))
2886 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2887 int new_height
= -1;
2889 if (CONSP (it
->font_height
)
2890 && (EQ (XCAR (it
->font_height
), Qplus
)
2891 || EQ (XCAR (it
->font_height
), Qminus
))
2892 && CONSP (XCDR (it
->font_height
))
2893 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2895 /* `(+ N)' or `(- N)' where N is an integer. */
2896 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2897 if (EQ (XCAR (it
->font_height
), Qplus
))
2899 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2901 else if (FUNCTIONP (it
->font_height
))
2903 /* Call function with current height as argument.
2904 Value is the new height. */
2906 height
= safe_call1 (it
->font_height
,
2907 face
->lface
[LFACE_HEIGHT_INDEX
]);
2908 if (NUMBERP (height
))
2909 new_height
= XFLOATINT (height
);
2911 else if (NUMBERP (it
->font_height
))
2913 /* Value is a multiple of the canonical char height. */
2916 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2917 new_height
= (XFLOATINT (it
->font_height
)
2918 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2922 /* Evaluate IT->font_height with `height' bound to the
2923 current specified height to get the new height. */
2925 int count
= BINDING_STACK_SIZE ();
2927 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2928 value
= safe_eval (it
->font_height
);
2929 unbind_to (count
, Qnil
);
2931 if (NUMBERP (value
))
2932 new_height
= XFLOATINT (value
);
2936 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2939 else if (CONSP (prop
)
2940 && EQ (XCAR (prop
), Qspace_width
)
2941 && CONSP (XCDR (prop
)))
2943 /* `(space_width WIDTH)'. */
2944 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2947 value
= XCAR (XCDR (prop
));
2948 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2949 it
->space_width
= value
;
2951 else if (CONSP (prop
)
2952 && EQ (XCAR (prop
), Qraise
)
2953 && CONSP (XCDR (prop
)))
2955 /* `(raise FACTOR)'. */
2956 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2959 #ifdef HAVE_WINDOW_SYSTEM
2960 value
= XCAR (XCDR (prop
));
2961 if (NUMBERP (value
))
2963 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2964 it
->voffset
= - (XFLOATINT (value
)
2965 * (FONT_HEIGHT (face
->font
)));
2967 #endif /* HAVE_WINDOW_SYSTEM */
2969 else if (!it
->string_from_display_prop_p
)
2971 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2972 VALUE) or `((margin nil) VALUE)' or VALUE. */
2973 Lisp_Object location
, value
;
2974 struct text_pos start_pos
;
2977 /* Characters having this form of property are not displayed, so
2978 we have to find the end of the property. */
2979 start_pos
= *position
;
2980 *position
= display_prop_end (it
, object
, start_pos
);
2983 /* Let's stop at the new position and assume that all
2984 text properties change there. */
2985 it
->stop_charpos
= position
->charpos
;
2987 location
= Qunbound
;
2988 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2992 value
= XCDR (prop
);
2994 value
= XCAR (value
);
2997 if (EQ (XCAR (tem
), Qmargin
)
2998 && (tem
= XCDR (tem
),
2999 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3001 || EQ (tem
, Qleft_margin
)
3002 || EQ (tem
, Qright_margin
))))
3006 if (EQ (location
, Qunbound
))
3012 #ifdef HAVE_WINDOW_SYSTEM
3013 if (FRAME_TERMCAP_P (it
->f
))
3014 valid_p
= STRINGP (value
);
3016 valid_p
= (STRINGP (value
)
3017 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3018 || valid_image_p (value
));
3019 #else /* not HAVE_WINDOW_SYSTEM */
3020 valid_p
= STRINGP (value
);
3021 #endif /* not HAVE_WINDOW_SYSTEM */
3023 if ((EQ (location
, Qleft_margin
)
3024 || EQ (location
, Qright_margin
)
3027 && !display_replaced_before_p
)
3029 replaces_text_display_p
= 1;
3031 /* Save current settings of IT so that we can restore them
3032 when we are finished with the glyph property value. */
3035 if (NILP (location
))
3036 it
->area
= TEXT_AREA
;
3037 else if (EQ (location
, Qleft_margin
))
3038 it
->area
= LEFT_MARGIN_AREA
;
3040 it
->area
= RIGHT_MARGIN_AREA
;
3042 if (STRINGP (value
))
3045 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3046 it
->current
.overlay_string_index
= -1;
3047 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3048 it
->end_charpos
= it
->string_nchars
3049 = XSTRING (it
->string
)->size
;
3050 it
->method
= next_element_from_string
;
3051 it
->stop_charpos
= 0;
3052 it
->string_from_display_prop_p
= 1;
3053 /* Say that we haven't consumed the characters with
3054 `display' property yet. The call to pop_it in
3055 set_iterator_to_next will clean this up. */
3056 *position
= start_pos
;
3058 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3060 it
->method
= next_element_from_stretch
;
3062 it
->current
.pos
= it
->position
= start_pos
;
3064 #ifdef HAVE_WINDOW_SYSTEM
3067 it
->what
= IT_IMAGE
;
3068 it
->image_id
= lookup_image (it
->f
, value
);
3069 it
->position
= start_pos
;
3070 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3071 it
->method
= next_element_from_image
;
3073 /* Say that we haven't consumed the characters with
3074 `display' property yet. The call to pop_it in
3075 set_iterator_to_next will clean this up. */
3076 *position
= start_pos
;
3078 #endif /* HAVE_WINDOW_SYSTEM */
3081 /* Invalid property or property not supported. Restore
3082 the position to what it was before. */
3083 *position
= start_pos
;
3086 return replaces_text_display_p
;
3090 /* Check if PROP is a display sub-property value whose text should be
3091 treated as intangible. */
3094 single_display_prop_intangible_p (prop
)
3097 /* Skip over `when FORM'. */
3098 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3109 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3110 we don't need to treat text as intangible. */
3111 if (EQ (XCAR (prop
), Qmargin
))
3119 || EQ (XCAR (prop
), Qleft_margin
)
3120 || EQ (XCAR (prop
), Qright_margin
))
3124 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3128 /* Check if PROP is a display property value whose text should be
3129 treated as intangible. */
3132 display_prop_intangible_p (prop
)
3136 && CONSP (XCAR (prop
))
3137 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3139 /* A list of sub-properties. */
3140 while (CONSP (prop
))
3142 if (single_display_prop_intangible_p (XCAR (prop
)))
3147 else if (VECTORP (prop
))
3149 /* A vector of sub-properties. */
3151 for (i
= 0; i
< ASIZE (prop
); ++i
)
3152 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3156 return single_display_prop_intangible_p (prop
);
3162 /* Return 1 if PROP is a display sub-property value containing STRING. */
3165 single_display_prop_string_p (prop
, string
)
3166 Lisp_Object prop
, string
;
3168 if (EQ (string
, prop
))
3171 /* Skip over `when FORM'. */
3172 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3181 /* Skip over `margin LOCATION'. */
3182 if (EQ (XCAR (prop
), Qmargin
))
3193 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3197 /* Return 1 if STRING appears in the `display' property PROP. */
3200 display_prop_string_p (prop
, string
)
3201 Lisp_Object prop
, string
;
3204 && CONSP (XCAR (prop
))
3205 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3207 /* A list of sub-properties. */
3208 while (CONSP (prop
))
3210 if (single_display_prop_string_p (XCAR (prop
), string
))
3215 else if (VECTORP (prop
))
3217 /* A vector of sub-properties. */
3219 for (i
= 0; i
< ASIZE (prop
); ++i
)
3220 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3224 return single_display_prop_string_p (prop
, string
);
3230 /* Determine from which buffer position in W's buffer STRING comes
3231 from. AROUND_CHARPOS is an approximate position where it could
3232 be from. Value is the buffer position or 0 if it couldn't be
3235 W's buffer must be current.
3237 This function is necessary because we don't record buffer positions
3238 in glyphs generated from strings (to keep struct glyph small).
3239 This function may only use code that doesn't eval because it is
3240 called asynchronously from note_mouse_highlight. */
3243 string_buffer_position (w
, string
, around_charpos
)
3248 Lisp_Object limit
, prop
, pos
;
3249 const int MAX_DISTANCE
= 1000;
3252 pos
= make_number (around_charpos
);
3253 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3254 while (!found
&& !EQ (pos
, limit
))
3256 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3257 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3260 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3265 pos
= make_number (around_charpos
);
3266 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3267 while (!found
&& !EQ (pos
, limit
))
3269 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3270 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3273 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3278 return found
? XINT (pos
) : 0;
3283 /***********************************************************************
3284 `composition' property
3285 ***********************************************************************/
3287 /* Set up iterator IT from `composition' property at its current
3288 position. Called from handle_stop. */
3290 static enum prop_handled
3291 handle_composition_prop (it
)
3294 Lisp_Object prop
, string
;
3295 int pos
, pos_byte
, end
;
3296 enum prop_handled handled
= HANDLED_NORMALLY
;
3298 if (STRINGP (it
->string
))
3300 pos
= IT_STRING_CHARPOS (*it
);
3301 pos_byte
= IT_STRING_BYTEPOS (*it
);
3302 string
= it
->string
;
3306 pos
= IT_CHARPOS (*it
);
3307 pos_byte
= IT_BYTEPOS (*it
);
3311 /* If there's a valid composition and point is not inside of the
3312 composition (in the case that the composition is from the current
3313 buffer), draw a glyph composed from the composition components. */
3314 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3315 && COMPOSITION_VALID_P (pos
, end
, prop
)
3316 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3318 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3322 it
->method
= next_element_from_composition
;
3324 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3325 /* For a terminal, draw only the first character of the
3327 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3328 it
->len
= (STRINGP (it
->string
)
3329 ? string_char_to_byte (it
->string
, end
)
3330 : CHAR_TO_BYTE (end
)) - pos_byte
;
3331 it
->stop_charpos
= end
;
3332 handled
= HANDLED_RETURN
;
3341 /***********************************************************************
3343 ***********************************************************************/
3345 /* The following structure is used to record overlay strings for
3346 later sorting in load_overlay_strings. */
3348 struct overlay_entry
3350 Lisp_Object overlay
;
3357 /* Set up iterator IT from overlay strings at its current position.
3358 Called from handle_stop. */
3360 static enum prop_handled
3361 handle_overlay_change (it
)
3364 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3365 return HANDLED_RECOMPUTE_PROPS
;
3367 return HANDLED_NORMALLY
;
3371 /* Set up the next overlay string for delivery by IT, if there is an
3372 overlay string to deliver. Called by set_iterator_to_next when the
3373 end of the current overlay string is reached. If there are more
3374 overlay strings to display, IT->string and
3375 IT->current.overlay_string_index are set appropriately here.
3376 Otherwise IT->string is set to nil. */
3379 next_overlay_string (it
)
3382 ++it
->current
.overlay_string_index
;
3383 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3385 /* No more overlay strings. Restore IT's settings to what
3386 they were before overlay strings were processed, and
3387 continue to deliver from current_buffer. */
3388 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3391 xassert (it
->stop_charpos
>= BEGV
3392 && it
->stop_charpos
<= it
->end_charpos
);
3394 it
->current
.overlay_string_index
= -1;
3395 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3396 it
->n_overlay_strings
= 0;
3397 it
->method
= next_element_from_buffer
;
3399 /* If we're at the end of the buffer, record that we have
3400 processed the overlay strings there already, so that
3401 next_element_from_buffer doesn't try it again. */
3402 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3403 it
->overlay_strings_at_end_processed_p
= 1;
3405 /* If we have to display `...' for invisible text, set
3406 the iterator up for that. */
3407 if (display_ellipsis_p
)
3408 setup_for_ellipsis (it
);
3412 /* There are more overlay strings to process. If
3413 IT->current.overlay_string_index has advanced to a position
3414 where we must load IT->overlay_strings with more strings, do
3416 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3418 if (it
->current
.overlay_string_index
&& i
== 0)
3419 load_overlay_strings (it
, 0);
3421 /* Initialize IT to deliver display elements from the overlay
3423 it
->string
= it
->overlay_strings
[i
];
3424 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3425 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3426 it
->method
= next_element_from_string
;
3427 it
->stop_charpos
= 0;
3434 /* Compare two overlay_entry structures E1 and E2. Used as a
3435 comparison function for qsort in load_overlay_strings. Overlay
3436 strings for the same position are sorted so that
3438 1. All after-strings come in front of before-strings, except
3439 when they come from the same overlay.
3441 2. Within after-strings, strings are sorted so that overlay strings
3442 from overlays with higher priorities come first.
3444 2. Within before-strings, strings are sorted so that overlay
3445 strings from overlays with higher priorities come last.
3447 Value is analogous to strcmp. */
3451 compare_overlay_entries (e1
, e2
)
3454 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3455 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3458 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3460 /* Let after-strings appear in front of before-strings if
3461 they come from different overlays. */
3462 if (EQ (entry1
->overlay
, entry2
->overlay
))
3463 result
= entry1
->after_string_p
? 1 : -1;
3465 result
= entry1
->after_string_p
? -1 : 1;
3467 else if (entry1
->after_string_p
)
3468 /* After-strings sorted in order of decreasing priority. */
3469 result
= entry2
->priority
- entry1
->priority
;
3471 /* Before-strings sorted in order of increasing priority. */
3472 result
= entry1
->priority
- entry2
->priority
;
3478 /* Load the vector IT->overlay_strings with overlay strings from IT's
3479 current buffer position, or from CHARPOS if that is > 0. Set
3480 IT->n_overlays to the total number of overlay strings found.
3482 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3483 a time. On entry into load_overlay_strings,
3484 IT->current.overlay_string_index gives the number of overlay
3485 strings that have already been loaded by previous calls to this
3488 IT->add_overlay_start contains an additional overlay start
3489 position to consider for taking overlay strings from, if non-zero.
3490 This position comes into play when the overlay has an `invisible'
3491 property, and both before and after-strings. When we've skipped to
3492 the end of the overlay, because of its `invisible' property, we
3493 nevertheless want its before-string to appear.
3494 IT->add_overlay_start will contain the overlay start position
3497 Overlay strings are sorted so that after-string strings come in
3498 front of before-string strings. Within before and after-strings,
3499 strings are sorted by overlay priority. See also function
3500 compare_overlay_entries. */
3503 load_overlay_strings (it
, charpos
)
3507 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3508 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3511 int n
= 0, i
, j
, invis_p
;
3512 struct overlay_entry
*entries
3513 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3516 charpos
= IT_CHARPOS (*it
);
3518 /* Append the overlay string STRING of overlay OVERLAY to vector
3519 `entries' which has size `size' and currently contains `n'
3520 elements. AFTER_P non-zero means STRING is an after-string of
3522 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3525 Lisp_Object priority; \
3529 int new_size = 2 * size; \
3530 struct overlay_entry *old = entries; \
3532 (struct overlay_entry *) alloca (new_size \
3533 * sizeof *entries); \
3534 bcopy (old, entries, size * sizeof *entries); \
3538 entries[n].string = (STRING); \
3539 entries[n].overlay = (OVERLAY); \
3540 priority = Foverlay_get ((OVERLAY), Qpriority); \
3541 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3542 entries[n].after_string_p = (AFTER_P); \
3547 /* Process overlay before the overlay center. */
3548 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3550 overlay
= XCAR (ov
);
3551 xassert (OVERLAYP (overlay
));
3552 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3553 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3558 /* Skip this overlay if it doesn't start or end at IT's current
3560 if (end
!= charpos
&& start
!= charpos
)
3563 /* Skip this overlay if it doesn't apply to IT->w. */
3564 window
= Foverlay_get (overlay
, Qwindow
);
3565 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3568 /* If the text ``under'' the overlay is invisible, both before-
3569 and after-strings from this overlay are visible; start and
3570 end position are indistinguishable. */
3571 invisible
= Foverlay_get (overlay
, Qinvisible
);
3572 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3574 /* If overlay has a non-empty before-string, record it. */
3575 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3576 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3577 && XSTRING (str
)->size
)
3578 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3580 /* If overlay has a non-empty after-string, record it. */
3581 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3582 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3583 && XSTRING (str
)->size
)
3584 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3587 /* Process overlays after the overlay center. */
3588 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3590 overlay
= XCAR (ov
);
3591 xassert (OVERLAYP (overlay
));
3592 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3593 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3595 if (start
> charpos
)
3598 /* Skip this overlay if it doesn't start or end at IT's current
3600 if (end
!= charpos
&& start
!= charpos
)
3603 /* Skip this overlay if it doesn't apply to IT->w. */
3604 window
= Foverlay_get (overlay
, Qwindow
);
3605 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3608 /* If the text ``under'' the overlay is invisible, it has a zero
3609 dimension, and both before- and after-strings apply. */
3610 invisible
= Foverlay_get (overlay
, Qinvisible
);
3611 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3613 /* If overlay has a non-empty before-string, record it. */
3614 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3615 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3616 && XSTRING (str
)->size
)
3617 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3619 /* If overlay has a non-empty after-string, record it. */
3620 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3621 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3622 && XSTRING (str
)->size
)
3623 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3626 #undef RECORD_OVERLAY_STRING
3630 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3632 /* Record the total number of strings to process. */
3633 it
->n_overlay_strings
= n
;
3635 /* IT->current.overlay_string_index is the number of overlay strings
3636 that have already been consumed by IT. Copy some of the
3637 remaining overlay strings to IT->overlay_strings. */
3639 j
= it
->current
.overlay_string_index
;
3640 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3641 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3647 /* Get the first chunk of overlay strings at IT's current buffer
3648 position, or at CHARPOS if that is > 0. Value is non-zero if at
3649 least one overlay string was found. */
3652 get_overlay_strings (it
, charpos
)
3656 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3657 process. This fills IT->overlay_strings with strings, and sets
3658 IT->n_overlay_strings to the total number of strings to process.
3659 IT->pos.overlay_string_index has to be set temporarily to zero
3660 because load_overlay_strings needs this; it must be set to -1
3661 when no overlay strings are found because a zero value would
3662 indicate a position in the first overlay string. */
3663 it
->current
.overlay_string_index
= 0;
3664 load_overlay_strings (it
, charpos
);
3666 /* If we found overlay strings, set up IT to deliver display
3667 elements from the first one. Otherwise set up IT to deliver
3668 from current_buffer. */
3669 if (it
->n_overlay_strings
)
3671 /* Make sure we know settings in current_buffer, so that we can
3672 restore meaningful values when we're done with the overlay
3674 compute_stop_pos (it
);
3675 xassert (it
->face_id
>= 0);
3677 /* Save IT's settings. They are restored after all overlay
3678 strings have been processed. */
3679 xassert (it
->sp
== 0);
3682 /* Set up IT to deliver display elements from the first overlay
3684 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3685 it
->string
= it
->overlay_strings
[0];
3686 it
->stop_charpos
= 0;
3687 it
->end_charpos
= XSTRING (it
->string
)->size
;
3688 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3689 xassert (STRINGP (it
->string
));
3690 it
->method
= next_element_from_string
;
3695 it
->current
.overlay_string_index
= -1;
3696 it
->method
= next_element_from_buffer
;
3701 /* Value is non-zero if we found at least one overlay string. */
3702 return STRINGP (it
->string
);
3707 /***********************************************************************
3708 Saving and restoring state
3709 ***********************************************************************/
3711 /* Save current settings of IT on IT->stack. Called, for example,
3712 before setting up IT for an overlay string, to be able to restore
3713 IT's settings to what they were after the overlay string has been
3720 struct iterator_stack_entry
*p
;
3722 xassert (it
->sp
< 2);
3723 p
= it
->stack
+ it
->sp
;
3725 p
->stop_charpos
= it
->stop_charpos
;
3726 xassert (it
->face_id
>= 0);
3727 p
->face_id
= it
->face_id
;
3728 p
->string
= it
->string
;
3729 p
->pos
= it
->current
;
3730 p
->end_charpos
= it
->end_charpos
;
3731 p
->string_nchars
= it
->string_nchars
;
3733 p
->multibyte_p
= it
->multibyte_p
;
3734 p
->space_width
= it
->space_width
;
3735 p
->font_height
= it
->font_height
;
3736 p
->voffset
= it
->voffset
;
3737 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3738 p
->display_ellipsis_p
= 0;
3743 /* Restore IT's settings from IT->stack. Called, for example, when no
3744 more overlay strings must be processed, and we return to delivering
3745 display elements from a buffer, or when the end of a string from a
3746 `display' property is reached and we return to delivering display
3747 elements from an overlay string, or from a buffer. */
3753 struct iterator_stack_entry
*p
;
3755 xassert (it
->sp
> 0);
3757 p
= it
->stack
+ it
->sp
;
3758 it
->stop_charpos
= p
->stop_charpos
;
3759 it
->face_id
= p
->face_id
;
3760 it
->string
= p
->string
;
3761 it
->current
= p
->pos
;
3762 it
->end_charpos
= p
->end_charpos
;
3763 it
->string_nchars
= p
->string_nchars
;
3765 it
->multibyte_p
= p
->multibyte_p
;
3766 it
->space_width
= p
->space_width
;
3767 it
->font_height
= p
->font_height
;
3768 it
->voffset
= p
->voffset
;
3769 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3774 /***********************************************************************
3776 ***********************************************************************/
3778 /* Set IT's current position to the previous line start. */
3781 back_to_previous_line_start (it
)
3784 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3785 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3789 /* Move IT to the next line start.
3791 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3792 we skipped over part of the text (as opposed to moving the iterator
3793 continuously over the text). Otherwise, don't change the value
3796 Newlines may come from buffer text, overlay strings, or strings
3797 displayed via the `display' property. That's the reason we can't
3798 simply use find_next_newline_no_quit.
3800 Note that this function may not skip over invisible text that is so
3801 because of text properties and immediately follows a newline. If
3802 it would, function reseat_at_next_visible_line_start, when called
3803 from set_iterator_to_next, would effectively make invisible
3804 characters following a newline part of the wrong glyph row, which
3805 leads to wrong cursor motion. */
3808 forward_to_next_line_start (it
, skipped_p
)
3812 int old_selective
, newline_found_p
, n
;
3813 const int MAX_NEWLINE_DISTANCE
= 500;
3815 /* If already on a newline, just consume it to avoid unintended
3816 skipping over invisible text below. */
3817 if (it
->what
== IT_CHARACTER
3819 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3821 set_iterator_to_next (it
, 0);
3826 /* Don't handle selective display in the following. It's (a)
3827 unnecessary because it's done by the caller, and (b) leads to an
3828 infinite recursion because next_element_from_ellipsis indirectly
3829 calls this function. */
3830 old_selective
= it
->selective
;
3833 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3834 from buffer text. */
3835 for (n
= newline_found_p
= 0;
3836 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3837 n
+= STRINGP (it
->string
) ? 0 : 1)
3839 if (!get_next_display_element (it
))
3841 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3842 set_iterator_to_next (it
, 0);
3845 /* If we didn't find a newline near enough, see if we can use a
3847 if (n
== MAX_NEWLINE_DISTANCE
)
3849 int start
= IT_CHARPOS (*it
);
3850 int limit
= find_next_newline_no_quit (start
, 1);
3853 xassert (!STRINGP (it
->string
));
3855 /* If there isn't any `display' property in sight, and no
3856 overlays, we can just use the position of the newline in
3858 if (it
->stop_charpos
>= limit
3859 || ((pos
= Fnext_single_property_change (make_number (start
),
3861 Qnil
, make_number (limit
)),
3863 && next_overlay_change (start
) == ZV
))
3865 IT_CHARPOS (*it
) = limit
;
3866 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3867 *skipped_p
= newline_found_p
= 1;
3871 while (get_next_display_element (it
)
3872 && !newline_found_p
)
3874 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3875 set_iterator_to_next (it
, 0);
3880 it
->selective
= old_selective
;
3881 return newline_found_p
;
3885 /* Set IT's current position to the previous visible line start. Skip
3886 invisible text that is so either due to text properties or due to
3887 selective display. Caution: this does not change IT->current_x and
3891 back_to_previous_visible_line_start (it
)
3896 /* Go back one newline if not on BEGV already. */
3897 if (IT_CHARPOS (*it
) > BEGV
)
3898 back_to_previous_line_start (it
);
3900 /* Move over lines that are invisible because of selective display
3901 or text properties. */
3902 while (IT_CHARPOS (*it
) > BEGV
3907 /* If selective > 0, then lines indented more than that values
3909 if (it
->selective
> 0
3910 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3917 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3918 Qinvisible
, it
->window
);
3919 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3923 /* Back one more newline if the current one is invisible. */
3925 back_to_previous_line_start (it
);
3928 xassert (IT_CHARPOS (*it
) >= BEGV
);
3929 xassert (IT_CHARPOS (*it
) == BEGV
3930 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3935 /* Reseat iterator IT at the previous visible line start. Skip
3936 invisible text that is so either due to text properties or due to
3937 selective display. At the end, update IT's overlay information,
3938 face information etc. */
3941 reseat_at_previous_visible_line_start (it
)
3944 back_to_previous_visible_line_start (it
);
3945 reseat (it
, it
->current
.pos
, 1);
3950 /* Reseat iterator IT on the next visible line start in the current
3951 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3952 preceding the line start. Skip over invisible text that is so
3953 because of selective display. Compute faces, overlays etc at the
3954 new position. Note that this function does not skip over text that
3955 is invisible because of text properties. */
3958 reseat_at_next_visible_line_start (it
, on_newline_p
)
3962 int newline_found_p
, skipped_p
= 0;
3964 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3966 /* Skip over lines that are invisible because they are indented
3967 more than the value of IT->selective. */
3968 if (it
->selective
> 0)
3969 while (IT_CHARPOS (*it
) < ZV
3970 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3973 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3974 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3977 /* Position on the newline if that's what's requested. */
3978 if (on_newline_p
&& newline_found_p
)
3980 if (STRINGP (it
->string
))
3982 if (IT_STRING_CHARPOS (*it
) > 0)
3984 --IT_STRING_CHARPOS (*it
);
3985 --IT_STRING_BYTEPOS (*it
);
3988 else if (IT_CHARPOS (*it
) > BEGV
)
3992 reseat (it
, it
->current
.pos
, 0);
3996 reseat (it
, it
->current
.pos
, 0);
4003 /***********************************************************************
4004 Changing an iterator's position
4005 ***********************************************************************/
4007 /* Change IT's current position to POS in current_buffer. If FORCE_P
4008 is non-zero, always check for text properties at the new position.
4009 Otherwise, text properties are only looked up if POS >=
4010 IT->check_charpos of a property. */
4013 reseat (it
, pos
, force_p
)
4015 struct text_pos pos
;
4018 int original_pos
= IT_CHARPOS (*it
);
4020 reseat_1 (it
, pos
, 0);
4022 /* Determine where to check text properties. Avoid doing it
4023 where possible because text property lookup is very expensive. */
4025 || CHARPOS (pos
) > it
->stop_charpos
4026 || CHARPOS (pos
) < original_pos
)
4033 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4034 IT->stop_pos to POS, also. */
4037 reseat_1 (it
, pos
, set_stop_p
)
4039 struct text_pos pos
;
4042 /* Don't call this function when scanning a C string. */
4043 xassert (it
->s
== NULL
);
4045 /* POS must be a reasonable value. */
4046 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4048 it
->current
.pos
= it
->position
= pos
;
4049 XSETBUFFER (it
->object
, current_buffer
);
4050 it
->end_charpos
= ZV
;
4052 it
->current
.dpvec_index
= -1;
4053 it
->current
.overlay_string_index
= -1;
4054 IT_STRING_CHARPOS (*it
) = -1;
4055 IT_STRING_BYTEPOS (*it
) = -1;
4057 it
->method
= next_element_from_buffer
;
4058 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4060 it
->face_before_selective_p
= 0;
4063 it
->stop_charpos
= CHARPOS (pos
);
4067 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4068 If S is non-null, it is a C string to iterate over. Otherwise,
4069 STRING gives a Lisp string to iterate over.
4071 If PRECISION > 0, don't return more then PRECISION number of
4072 characters from the string.
4074 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4075 characters have been returned. FIELD_WIDTH < 0 means an infinite
4078 MULTIBYTE = 0 means disable processing of multibyte characters,
4079 MULTIBYTE > 0 means enable it,
4080 MULTIBYTE < 0 means use IT->multibyte_p.
4082 IT must be initialized via a prior call to init_iterator before
4083 calling this function. */
4086 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4091 int precision
, field_width
, multibyte
;
4093 /* No region in strings. */
4094 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4096 /* No text property checks performed by default, but see below. */
4097 it
->stop_charpos
= -1;
4099 /* Set iterator position and end position. */
4100 bzero (&it
->current
, sizeof it
->current
);
4101 it
->current
.overlay_string_index
= -1;
4102 it
->current
.dpvec_index
= -1;
4103 xassert (charpos
>= 0);
4105 /* If STRING is specified, use its multibyteness, otherwise use the
4106 setting of MULTIBYTE, if specified. */
4108 it
->multibyte_p
= multibyte
> 0;
4112 xassert (STRINGP (string
));
4113 it
->string
= string
;
4115 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
4116 it
->method
= next_element_from_string
;
4117 it
->current
.string_pos
= string_pos (charpos
, string
);
4124 /* Note that we use IT->current.pos, not it->current.string_pos,
4125 for displaying C strings. */
4126 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4127 if (it
->multibyte_p
)
4129 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4130 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4134 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4135 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4138 it
->method
= next_element_from_c_string
;
4141 /* PRECISION > 0 means don't return more than PRECISION characters
4143 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4144 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4146 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4147 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4148 FIELD_WIDTH < 0 means infinite field width. This is useful for
4149 padding with `-' at the end of a mode line. */
4150 if (field_width
< 0)
4151 field_width
= INFINITY
;
4152 if (field_width
> it
->end_charpos
- charpos
)
4153 it
->end_charpos
= charpos
+ field_width
;
4155 /* Use the standard display table for displaying strings. */
4156 if (DISP_TABLE_P (Vstandard_display_table
))
4157 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4159 it
->stop_charpos
= charpos
;
4165 /***********************************************************************
4167 ***********************************************************************/
4169 /* Load IT's display element fields with information about the next
4170 display element from the current position of IT. Value is zero if
4171 end of buffer (or C string) is reached. */
4174 get_next_display_element (it
)
4177 /* Non-zero means that we found an display element. Zero means that
4178 we hit the end of what we iterate over. Performance note: the
4179 function pointer `method' used here turns out to be faster than
4180 using a sequence of if-statements. */
4181 int success_p
= (*it
->method
) (it
);
4183 if (it
->what
== IT_CHARACTER
)
4185 /* Map via display table or translate control characters.
4186 IT->c, IT->len etc. have been set to the next character by
4187 the function call above. If we have a display table, and it
4188 contains an entry for IT->c, translate it. Don't do this if
4189 IT->c itself comes from a display table, otherwise we could
4190 end up in an infinite recursion. (An alternative could be to
4191 count the recursion depth of this function and signal an
4192 error when a certain maximum depth is reached.) Is it worth
4194 if (success_p
&& it
->dpvec
== NULL
)
4199 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4202 struct Lisp_Vector
*v
= XVECTOR (dv
);
4204 /* Return the first character from the display table
4205 entry, if not empty. If empty, don't display the
4206 current character. */
4209 it
->dpvec_char_len
= it
->len
;
4210 it
->dpvec
= v
->contents
;
4211 it
->dpend
= v
->contents
+ v
->size
;
4212 it
->current
.dpvec_index
= 0;
4213 it
->method
= next_element_from_display_vector
;
4214 success_p
= get_next_display_element (it
);
4218 set_iterator_to_next (it
, 0);
4219 success_p
= get_next_display_element (it
);
4223 /* Translate control characters into `\003' or `^C' form.
4224 Control characters coming from a display table entry are
4225 currently not translated because we use IT->dpvec to hold
4226 the translation. This could easily be changed but I
4227 don't believe that it is worth doing.
4229 Non-printable multibyte characters are also translated
4231 else if ((it
->c
< ' '
4232 && (it
->area
!= TEXT_AREA
4233 || (it
->c
!= '\n' && it
->c
!= '\t')))
4236 || !CHAR_PRINTABLE_P (it
->c
))
4238 /* IT->c is a control character which must be displayed
4239 either as '\003' or as `^C' where the '\\' and '^'
4240 can be defined in the display table. Fill
4241 IT->ctl_chars with glyphs for what we have to
4242 display. Then, set IT->dpvec to these glyphs. */
4245 if (it
->c
< 128 && it
->ctl_arrow_p
)
4247 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4249 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4250 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4251 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4253 g
= FAST_MAKE_GLYPH ('^', 0);
4254 XSETINT (it
->ctl_chars
[0], g
);
4256 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4257 XSETINT (it
->ctl_chars
[1], g
);
4259 /* Set up IT->dpvec and return first character from it. */
4260 it
->dpvec_char_len
= it
->len
;
4261 it
->dpvec
= it
->ctl_chars
;
4262 it
->dpend
= it
->dpvec
+ 2;
4263 it
->current
.dpvec_index
= 0;
4264 it
->method
= next_element_from_display_vector
;
4265 get_next_display_element (it
);
4269 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4274 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4276 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4277 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4278 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4280 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4282 if (SINGLE_BYTE_CHAR_P (it
->c
))
4283 str
[0] = it
->c
, len
= 1;
4286 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4289 /* It's an invalid character, which
4290 shouldn't happen actually, but due to
4291 bugs it may happen. Let's print the char
4292 as is, there's not much meaningful we can
4295 str
[1] = it
->c
>> 8;
4296 str
[2] = it
->c
>> 16;
4297 str
[3] = it
->c
>> 24;
4302 for (i
= 0; i
< len
; i
++)
4304 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4305 /* Insert three more glyphs into IT->ctl_chars for
4306 the octal display of the character. */
4307 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4308 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4309 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4310 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4311 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4312 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4315 /* Set up IT->dpvec and return the first character
4317 it
->dpvec_char_len
= it
->len
;
4318 it
->dpvec
= it
->ctl_chars
;
4319 it
->dpend
= it
->dpvec
+ len
* 4;
4320 it
->current
.dpvec_index
= 0;
4321 it
->method
= next_element_from_display_vector
;
4322 get_next_display_element (it
);
4327 /* Adjust face id for a multibyte character. There are no
4328 multibyte character in unibyte text. */
4331 && FRAME_WINDOW_P (it
->f
))
4333 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4334 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4338 /* Is this character the last one of a run of characters with
4339 box? If yes, set IT->end_of_box_run_p to 1. */
4346 it
->end_of_box_run_p
4347 = ((face_id
= face_after_it_pos (it
),
4348 face_id
!= it
->face_id
)
4349 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4350 face
->box
== FACE_NO_BOX
));
4353 /* Value is 0 if end of buffer or string reached. */
4358 /* Move IT to the next display element.
4360 RESEAT_P non-zero means if called on a newline in buffer text,
4361 skip to the next visible line start.
4363 Functions get_next_display_element and set_iterator_to_next are
4364 separate because I find this arrangement easier to handle than a
4365 get_next_display_element function that also increments IT's
4366 position. The way it is we can first look at an iterator's current
4367 display element, decide whether it fits on a line, and if it does,
4368 increment the iterator position. The other way around we probably
4369 would either need a flag indicating whether the iterator has to be
4370 incremented the next time, or we would have to implement a
4371 decrement position function which would not be easy to write. */
4374 set_iterator_to_next (it
, reseat_p
)
4378 /* Reset flags indicating start and end of a sequence of characters
4379 with box. Reset them at the start of this function because
4380 moving the iterator to a new position might set them. */
4381 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4383 if (it
->method
== next_element_from_buffer
)
4385 /* The current display element of IT is a character from
4386 current_buffer. Advance in the buffer, and maybe skip over
4387 invisible lines that are so because of selective display. */
4388 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4389 reseat_at_next_visible_line_start (it
, 0);
4392 xassert (it
->len
!= 0);
4393 IT_BYTEPOS (*it
) += it
->len
;
4394 IT_CHARPOS (*it
) += 1;
4395 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4398 else if (it
->method
== next_element_from_composition
)
4400 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4401 if (STRINGP (it
->string
))
4403 IT_STRING_BYTEPOS (*it
) += it
->len
;
4404 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4405 it
->method
= next_element_from_string
;
4406 goto consider_string_end
;
4410 IT_BYTEPOS (*it
) += it
->len
;
4411 IT_CHARPOS (*it
) += it
->cmp_len
;
4412 it
->method
= next_element_from_buffer
;
4415 else if (it
->method
== next_element_from_c_string
)
4417 /* Current display element of IT is from a C string. */
4418 IT_BYTEPOS (*it
) += it
->len
;
4419 IT_CHARPOS (*it
) += 1;
4421 else if (it
->method
== next_element_from_display_vector
)
4423 /* Current display element of IT is from a display table entry.
4424 Advance in the display table definition. Reset it to null if
4425 end reached, and continue with characters from buffers/
4427 ++it
->current
.dpvec_index
;
4429 /* Restore face of the iterator to what they were before the
4430 display vector entry (these entries may contain faces). */
4431 it
->face_id
= it
->saved_face_id
;
4433 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4436 it
->method
= next_element_from_c_string
;
4437 else if (STRINGP (it
->string
))
4438 it
->method
= next_element_from_string
;
4440 it
->method
= next_element_from_buffer
;
4443 it
->current
.dpvec_index
= -1;
4445 /* Skip over characters which were displayed via IT->dpvec. */
4446 if (it
->dpvec_char_len
< 0)
4447 reseat_at_next_visible_line_start (it
, 1);
4448 else if (it
->dpvec_char_len
> 0)
4450 it
->len
= it
->dpvec_char_len
;
4451 set_iterator_to_next (it
, reseat_p
);
4455 else if (it
->method
== next_element_from_string
)
4457 /* Current display element is a character from a Lisp string. */
4458 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4459 IT_STRING_BYTEPOS (*it
) += it
->len
;
4460 IT_STRING_CHARPOS (*it
) += 1;
4462 consider_string_end
:
4464 if (it
->current
.overlay_string_index
>= 0)
4466 /* IT->string is an overlay string. Advance to the
4467 next, if there is one. */
4468 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4469 next_overlay_string (it
);
4473 /* IT->string is not an overlay string. If we reached
4474 its end, and there is something on IT->stack, proceed
4475 with what is on the stack. This can be either another
4476 string, this time an overlay string, or a buffer. */
4477 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4481 if (!STRINGP (it
->string
))
4482 it
->method
= next_element_from_buffer
;
4484 goto consider_string_end
;
4488 else if (it
->method
== next_element_from_image
4489 || it
->method
== next_element_from_stretch
)
4491 /* The position etc with which we have to proceed are on
4492 the stack. The position may be at the end of a string,
4493 if the `display' property takes up the whole string. */
4496 if (STRINGP (it
->string
))
4498 it
->method
= next_element_from_string
;
4499 goto consider_string_end
;
4502 it
->method
= next_element_from_buffer
;
4505 /* There are no other methods defined, so this should be a bug. */
4508 xassert (it
->method
!= next_element_from_string
4509 || (STRINGP (it
->string
)
4510 && IT_STRING_CHARPOS (*it
) >= 0));
4514 /* Load IT's display element fields with information about the next
4515 display element which comes from a display table entry or from the
4516 result of translating a control character to one of the forms `^C'
4517 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4520 next_element_from_display_vector (it
)
4524 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4526 /* Remember the current face id in case glyphs specify faces.
4527 IT's face is restored in set_iterator_to_next. */
4528 it
->saved_face_id
= it
->face_id
;
4530 if (INTEGERP (*it
->dpvec
)
4531 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4536 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4537 it
->c
= FAST_GLYPH_CHAR (g
);
4538 it
->len
= CHAR_BYTES (it
->c
);
4540 /* The entry may contain a face id to use. Such a face id is
4541 the id of a Lisp face, not a realized face. A face id of
4542 zero means no face is specified. */
4543 lface_id
= FAST_GLYPH_FACE (g
);
4546 /* The function returns -1 if lface_id is invalid. */
4547 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4549 it
->face_id
= face_id
;
4553 /* Display table entry is invalid. Return a space. */
4554 it
->c
= ' ', it
->len
= 1;
4556 /* Don't change position and object of the iterator here. They are
4557 still the values of the character that had this display table
4558 entry or was translated, and that's what we want. */
4559 it
->what
= IT_CHARACTER
;
4564 /* Load IT with the next display element from Lisp string IT->string.
4565 IT->current.string_pos is the current position within the string.
4566 If IT->current.overlay_string_index >= 0, the Lisp string is an
4570 next_element_from_string (it
)
4573 struct text_pos position
;
4575 xassert (STRINGP (it
->string
));
4576 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4577 position
= it
->current
.string_pos
;
4579 /* Time to check for invisible text? */
4580 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4581 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4585 /* Since a handler may have changed IT->method, we must
4587 return get_next_display_element (it
);
4590 if (it
->current
.overlay_string_index
>= 0)
4592 /* Get the next character from an overlay string. In overlay
4593 strings, There is no field width or padding with spaces to
4595 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4600 else if (STRING_MULTIBYTE (it
->string
))
4602 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4603 - IT_STRING_BYTEPOS (*it
));
4604 unsigned char *s
= (XSTRING (it
->string
)->data
4605 + IT_STRING_BYTEPOS (*it
));
4606 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4610 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4616 /* Get the next character from a Lisp string that is not an
4617 overlay string. Such strings come from the mode line, for
4618 example. We may have to pad with spaces, or truncate the
4619 string. See also next_element_from_c_string. */
4620 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4625 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4627 /* Pad with spaces. */
4628 it
->c
= ' ', it
->len
= 1;
4629 CHARPOS (position
) = BYTEPOS (position
) = -1;
4631 else if (STRING_MULTIBYTE (it
->string
))
4633 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4634 - IT_STRING_BYTEPOS (*it
));
4635 unsigned char *s
= (XSTRING (it
->string
)->data
4636 + IT_STRING_BYTEPOS (*it
));
4637 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4641 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4646 /* Record what we have and where it came from. Note that we store a
4647 buffer position in IT->position although it could arguably be a
4649 it
->what
= IT_CHARACTER
;
4650 it
->object
= it
->string
;
4651 it
->position
= position
;
4656 /* Load IT with next display element from C string IT->s.
4657 IT->string_nchars is the maximum number of characters to return
4658 from the string. IT->end_charpos may be greater than
4659 IT->string_nchars when this function is called, in which case we
4660 may have to return padding spaces. Value is zero if end of string
4661 reached, including padding spaces. */
4664 next_element_from_c_string (it
)
4670 it
->what
= IT_CHARACTER
;
4671 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4674 /* IT's position can be greater IT->string_nchars in case a field
4675 width or precision has been specified when the iterator was
4677 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4679 /* End of the game. */
4683 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4685 /* Pad with spaces. */
4686 it
->c
= ' ', it
->len
= 1;
4687 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4689 else if (it
->multibyte_p
)
4691 /* Implementation note: The calls to strlen apparently aren't a
4692 performance problem because there is no noticeable performance
4693 difference between Emacs running in unibyte or multibyte mode. */
4694 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4695 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4699 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4705 /* Set up IT to return characters from an ellipsis, if appropriate.
4706 The definition of the ellipsis glyphs may come from a display table
4707 entry. This function Fills IT with the first glyph from the
4708 ellipsis if an ellipsis is to be displayed. */
4711 next_element_from_ellipsis (it
)
4714 if (it
->selective_display_ellipsis_p
)
4716 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4718 /* Use the display table definition for `...'. Invalid glyphs
4719 will be handled by the method returning elements from dpvec. */
4720 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4721 it
->dpvec_char_len
= it
->len
;
4722 it
->dpvec
= v
->contents
;
4723 it
->dpend
= v
->contents
+ v
->size
;
4724 it
->current
.dpvec_index
= 0;
4725 it
->method
= next_element_from_display_vector
;
4729 /* Use default `...' which is stored in default_invis_vector. */
4730 it
->dpvec_char_len
= it
->len
;
4731 it
->dpvec
= default_invis_vector
;
4732 it
->dpend
= default_invis_vector
+ 3;
4733 it
->current
.dpvec_index
= 0;
4734 it
->method
= next_element_from_display_vector
;
4739 /* The face at the current position may be different from the
4740 face we find after the invisible text. Remember what it
4741 was in IT->saved_face_id, and signal that it's there by
4742 setting face_before_selective_p. */
4743 it
->saved_face_id
= it
->face_id
;
4744 it
->method
= next_element_from_buffer
;
4745 reseat_at_next_visible_line_start (it
, 1);
4746 it
->face_before_selective_p
= 1;
4749 return get_next_display_element (it
);
4753 /* Deliver an image display element. The iterator IT is already
4754 filled with image information (done in handle_display_prop). Value
4759 next_element_from_image (it
)
4762 it
->what
= IT_IMAGE
;
4767 /* Fill iterator IT with next display element from a stretch glyph
4768 property. IT->object is the value of the text property. Value is
4772 next_element_from_stretch (it
)
4775 it
->what
= IT_STRETCH
;
4780 /* Load IT with the next display element from current_buffer. Value
4781 is zero if end of buffer reached. IT->stop_charpos is the next
4782 position at which to stop and check for text properties or buffer
4786 next_element_from_buffer (it
)
4791 /* Check this assumption, otherwise, we would never enter the
4792 if-statement, below. */
4793 xassert (IT_CHARPOS (*it
) >= BEGV
4794 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4796 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4798 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4800 int overlay_strings_follow_p
;
4802 /* End of the game, except when overlay strings follow that
4803 haven't been returned yet. */
4804 if (it
->overlay_strings_at_end_processed_p
)
4805 overlay_strings_follow_p
= 0;
4808 it
->overlay_strings_at_end_processed_p
= 1;
4809 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4812 if (overlay_strings_follow_p
)
4813 success_p
= get_next_display_element (it
);
4817 it
->position
= it
->current
.pos
;
4824 return get_next_display_element (it
);
4829 /* No face changes, overlays etc. in sight, so just return a
4830 character from current_buffer. */
4833 /* Maybe run the redisplay end trigger hook. Performance note:
4834 This doesn't seem to cost measurable time. */
4835 if (it
->redisplay_end_trigger_charpos
4837 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4838 run_redisplay_end_trigger_hook (it
);
4840 /* Get the next character, maybe multibyte. */
4841 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4842 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4844 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4845 - IT_BYTEPOS (*it
));
4846 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4849 it
->c
= *p
, it
->len
= 1;
4851 /* Record what we have and where it came from. */
4852 it
->what
= IT_CHARACTER
;;
4853 it
->object
= it
->w
->buffer
;
4854 it
->position
= it
->current
.pos
;
4856 /* Normally we return the character found above, except when we
4857 really want to return an ellipsis for selective display. */
4862 /* A value of selective > 0 means hide lines indented more
4863 than that number of columns. */
4864 if (it
->selective
> 0
4865 && IT_CHARPOS (*it
) + 1 < ZV
4866 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4867 IT_BYTEPOS (*it
) + 1,
4870 success_p
= next_element_from_ellipsis (it
);
4871 it
->dpvec_char_len
= -1;
4874 else if (it
->c
== '\r' && it
->selective
== -1)
4876 /* A value of selective == -1 means that everything from the
4877 CR to the end of the line is invisible, with maybe an
4878 ellipsis displayed for it. */
4879 success_p
= next_element_from_ellipsis (it
);
4880 it
->dpvec_char_len
= -1;
4885 /* Value is zero if end of buffer reached. */
4886 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4891 /* Run the redisplay end trigger hook for IT. */
4894 run_redisplay_end_trigger_hook (it
)
4897 Lisp_Object args
[3];
4899 /* IT->glyph_row should be non-null, i.e. we should be actually
4900 displaying something, or otherwise we should not run the hook. */
4901 xassert (it
->glyph_row
);
4903 /* Set up hook arguments. */
4904 args
[0] = Qredisplay_end_trigger_functions
;
4905 args
[1] = it
->window
;
4906 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4907 it
->redisplay_end_trigger_charpos
= 0;
4909 /* Since we are *trying* to run these functions, don't try to run
4910 them again, even if they get an error. */
4911 it
->w
->redisplay_end_trigger
= Qnil
;
4912 Frun_hook_with_args (3, args
);
4914 /* Notice if it changed the face of the character we are on. */
4915 handle_face_prop (it
);
4919 /* Deliver a composition display element. The iterator IT is already
4920 filled with composition information (done in
4921 handle_composition_prop). Value is always 1. */
4924 next_element_from_composition (it
)
4927 it
->what
= IT_COMPOSITION
;
4928 it
->position
= (STRINGP (it
->string
)
4929 ? it
->current
.string_pos
4936 /***********************************************************************
4937 Moving an iterator without producing glyphs
4938 ***********************************************************************/
4940 /* Move iterator IT to a specified buffer or X position within one
4941 line on the display without producing glyphs.
4943 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4944 whichever is reached first.
4946 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4948 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4949 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4950 TO_X includes the amount by which a window is horizontally
4955 MOVE_POS_MATCH_OR_ZV
4956 - when TO_POS or ZV was reached.
4959 -when TO_X was reached before TO_POS or ZV were reached.
4962 - when we reached the end of the display area and the line must
4966 - when we reached the end of the display area and the line is
4970 - when we stopped at a line end, i.e. a newline or a CR and selective
4973 static enum move_it_result
4974 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4976 int to_charpos
, to_x
, op
;
4978 enum move_it_result result
= MOVE_UNDEFINED
;
4979 struct glyph_row
*saved_glyph_row
;
4981 /* Don't produce glyphs in produce_glyphs. */
4982 saved_glyph_row
= it
->glyph_row
;
4983 it
->glyph_row
= NULL
;
4987 int x
, i
, ascent
= 0, descent
= 0;
4989 /* Stop when ZV or TO_CHARPOS reached. */
4990 if (!get_next_display_element (it
)
4991 || ((op
& MOVE_TO_POS
) != 0
4992 && BUFFERP (it
->object
)
4993 && IT_CHARPOS (*it
) >= to_charpos
))
4995 result
= MOVE_POS_MATCH_OR_ZV
;
4999 /* The call to produce_glyphs will get the metrics of the
5000 display element IT is loaded with. We record in x the
5001 x-position before this display element in case it does not
5005 /* Remember the line height so far in case the next element doesn't
5007 if (!it
->truncate_lines_p
)
5009 ascent
= it
->max_ascent
;
5010 descent
= it
->max_descent
;
5013 PRODUCE_GLYPHS (it
);
5015 if (it
->area
!= TEXT_AREA
)
5017 set_iterator_to_next (it
, 1);
5021 /* The number of glyphs we get back in IT->nglyphs will normally
5022 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5023 character on a terminal frame, or (iii) a line end. For the
5024 second case, IT->nglyphs - 1 padding glyphs will be present
5025 (on X frames, there is only one glyph produced for a
5026 composite character.
5028 The behavior implemented below means, for continuation lines,
5029 that as many spaces of a TAB as fit on the current line are
5030 displayed there. For terminal frames, as many glyphs of a
5031 multi-glyph character are displayed in the current line, too.
5032 This is what the old redisplay code did, and we keep it that
5033 way. Under X, the whole shape of a complex character must
5034 fit on the line or it will be completely displayed in the
5037 Note that both for tabs and padding glyphs, all glyphs have
5041 /* More than one glyph or glyph doesn't fit on line. All
5042 glyphs have the same width. */
5043 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5046 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5048 new_x
= x
+ single_glyph_width
;
5050 /* We want to leave anything reaching TO_X to the caller. */
5051 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5054 result
= MOVE_X_REACHED
;
5057 else if (/* Lines are continued. */
5058 !it
->truncate_lines_p
5059 && (/* And glyph doesn't fit on the line. */
5060 new_x
> it
->last_visible_x
5061 /* Or it fits exactly and we're on a window
5063 || (new_x
== it
->last_visible_x
5064 && FRAME_WINDOW_P (it
->f
))))
5066 if (/* IT->hpos == 0 means the very first glyph
5067 doesn't fit on the line, e.g. a wide image. */
5069 || (new_x
== it
->last_visible_x
5070 && FRAME_WINDOW_P (it
->f
)))
5073 it
->current_x
= new_x
;
5074 if (i
== it
->nglyphs
- 1)
5075 set_iterator_to_next (it
, 1);
5080 it
->max_ascent
= ascent
;
5081 it
->max_descent
= descent
;
5084 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5086 result
= MOVE_LINE_CONTINUED
;
5089 else if (new_x
> it
->first_visible_x
)
5091 /* Glyph is visible. Increment number of glyphs that
5092 would be displayed. */
5097 /* Glyph is completely off the left margin of the display
5098 area. Nothing to do. */
5102 if (result
!= MOVE_UNDEFINED
)
5105 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5107 /* Stop when TO_X specified and reached. This check is
5108 necessary here because of lines consisting of a line end,
5109 only. The line end will not produce any glyphs and we
5110 would never get MOVE_X_REACHED. */
5111 xassert (it
->nglyphs
== 0);
5112 result
= MOVE_X_REACHED
;
5116 /* Is this a line end? If yes, we're done. */
5117 if (ITERATOR_AT_END_OF_LINE_P (it
))
5119 result
= MOVE_NEWLINE_OR_CR
;
5123 /* The current display element has been consumed. Advance
5125 set_iterator_to_next (it
, 1);
5127 /* Stop if lines are truncated and IT's current x-position is
5128 past the right edge of the window now. */
5129 if (it
->truncate_lines_p
5130 && it
->current_x
>= it
->last_visible_x
)
5132 result
= MOVE_LINE_TRUNCATED
;
5137 /* Restore the iterator settings altered at the beginning of this
5139 it
->glyph_row
= saved_glyph_row
;
5144 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
5145 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
5146 the description of enum move_operation_enum.
5148 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5149 screen line, this function will set IT to the next position >
5153 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5155 int to_charpos
, to_x
, to_y
, to_vpos
;
5158 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5164 if (op
& MOVE_TO_VPOS
)
5166 /* If no TO_CHARPOS and no TO_X specified, stop at the
5167 start of the line TO_VPOS. */
5168 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5170 if (it
->vpos
== to_vpos
)
5176 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5180 /* TO_VPOS >= 0 means stop at TO_X in the line at
5181 TO_VPOS, or at TO_POS, whichever comes first. */
5182 if (it
->vpos
== to_vpos
)
5188 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5190 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5195 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5197 /* We have reached TO_X but not in the line we want. */
5198 skip
= move_it_in_display_line_to (it
, to_charpos
,
5200 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5208 else if (op
& MOVE_TO_Y
)
5210 struct it it_backup
;
5212 /* TO_Y specified means stop at TO_X in the line containing
5213 TO_Y---or at TO_CHARPOS if this is reached first. The
5214 problem is that we can't really tell whether the line
5215 contains TO_Y before we have completely scanned it, and
5216 this may skip past TO_X. What we do is to first scan to
5219 If TO_X is not specified, use a TO_X of zero. The reason
5220 is to make the outcome of this function more predictable.
5221 If we didn't use TO_X == 0, we would stop at the end of
5222 the line which is probably not what a caller would expect
5224 skip
= move_it_in_display_line_to (it
, to_charpos
,
5228 | (op
& MOVE_TO_POS
)));
5230 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5231 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5237 /* If TO_X was reached, we would like to know whether TO_Y
5238 is in the line. This can only be said if we know the
5239 total line height which requires us to scan the rest of
5241 if (skip
== MOVE_X_REACHED
)
5244 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5245 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5247 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5250 /* Now, decide whether TO_Y is in this line. */
5251 line_height
= it
->max_ascent
+ it
->max_descent
;
5252 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5254 if (to_y
>= it
->current_y
5255 && to_y
< it
->current_y
+ line_height
)
5257 if (skip
== MOVE_X_REACHED
)
5258 /* If TO_Y is in this line and TO_X was reached above,
5259 we scanned too far. We have to restore IT's settings
5260 to the ones before skipping. */
5264 else if (skip
== MOVE_X_REACHED
)
5267 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5275 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5279 case MOVE_POS_MATCH_OR_ZV
:
5283 case MOVE_NEWLINE_OR_CR
:
5284 set_iterator_to_next (it
, 1);
5285 it
->continuation_lines_width
= 0;
5288 case MOVE_LINE_TRUNCATED
:
5289 it
->continuation_lines_width
= 0;
5290 reseat_at_next_visible_line_start (it
, 0);
5291 if ((op
& MOVE_TO_POS
) != 0
5292 && IT_CHARPOS (*it
) > to_charpos
)
5299 case MOVE_LINE_CONTINUED
:
5300 it
->continuation_lines_width
+= it
->current_x
;
5307 /* Reset/increment for the next run. */
5308 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5309 it
->current_x
= it
->hpos
= 0;
5310 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5312 last_height
= it
->max_ascent
+ it
->max_descent
;
5313 last_max_ascent
= it
->max_ascent
;
5314 it
->max_ascent
= it
->max_descent
= 0;
5319 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5323 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5325 If DY > 0, move IT backward at least that many pixels. DY = 0
5326 means move IT backward to the preceding line start or BEGV. This
5327 function may move over more than DY pixels if IT->current_y - DY
5328 ends up in the middle of a line; in this case IT->current_y will be
5329 set to the top of the line moved to. */
5332 move_it_vertically_backward (it
, dy
)
5338 int start_pos
= IT_CHARPOS (*it
);
5342 /* Estimate how many newlines we must move back. */
5343 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5345 /* Set the iterator's position that many lines back. */
5346 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5347 back_to_previous_visible_line_start (it
);
5349 /* Reseat the iterator here. When moving backward, we don't want
5350 reseat to skip forward over invisible text, set up the iterator
5351 to deliver from overlay strings at the new position etc. So,
5352 use reseat_1 here. */
5353 reseat_1 (it
, it
->current
.pos
, 1);
5355 /* We are now surely at a line start. */
5356 it
->current_x
= it
->hpos
= 0;
5358 /* Move forward and see what y-distance we moved. First move to the
5359 start of the next line so that we get its height. We need this
5360 height to be able to tell whether we reached the specified
5363 it2
.max_ascent
= it2
.max_descent
= 0;
5364 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5365 MOVE_TO_POS
| MOVE_TO_VPOS
);
5366 xassert (IT_CHARPOS (*it
) >= BEGV
);
5369 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5370 xassert (IT_CHARPOS (*it
) >= BEGV
);
5371 h
= it2
.current_y
- it
->current_y
;
5372 nlines
= it2
.vpos
- it
->vpos
;
5374 /* Correct IT's y and vpos position. */
5380 /* DY == 0 means move to the start of the screen line. The
5381 value of nlines is > 0 if continuation lines were involved. */
5383 move_it_by_lines (it
, nlines
, 1);
5384 xassert (IT_CHARPOS (*it
) <= start_pos
);
5388 /* The y-position we try to reach. Note that h has been
5389 subtracted in front of the if-statement. */
5390 int target_y
= it
->current_y
+ h
- dy
;
5391 int y0
= it3
.current_y
;
5392 int y1
= line_bottom_y (&it3
);
5393 int line_height
= y1
- y0
;
5395 /* If we did not reach target_y, try to move further backward if
5396 we can. If we moved too far backward, try to move forward. */
5397 if (target_y
< it
->current_y
5398 /* This is heuristic. In a window that's 3 lines high, with
5399 a line height of 13 pixels each, recentering with point
5400 on the bottom line will try to move -39/2 = 19 pixels
5401 backward. Try to avoid moving into the first line. */
5402 && it
->current_y
- target_y
> line_height
/ 3 * 2
5403 && IT_CHARPOS (*it
) > BEGV
)
5405 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5406 target_y
- it
->current_y
));
5407 move_it_vertically (it
, target_y
- it
->current_y
);
5408 xassert (IT_CHARPOS (*it
) >= BEGV
);
5410 else if (target_y
>= it
->current_y
+ line_height
5411 && IT_CHARPOS (*it
) < ZV
)
5413 /* Should move forward by at least one line, maybe more. */
5416 move_it_by_lines (it
, 1, 1);
5418 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5420 xassert (IT_CHARPOS (*it
) >= BEGV
);
5426 /* Move IT by a specified amount of pixel lines DY. DY negative means
5427 move backwards. DY = 0 means move to start of screen line. At the
5428 end, IT will be on the start of a screen line. */
5431 move_it_vertically (it
, dy
)
5436 move_it_vertically_backward (it
, -dy
);
5439 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5440 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5441 MOVE_TO_POS
| MOVE_TO_Y
);
5442 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5444 /* If buffer ends in ZV without a newline, move to the start of
5445 the line to satisfy the post-condition. */
5446 if (IT_CHARPOS (*it
) == ZV
5447 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5448 move_it_by_lines (it
, 0, 0);
5453 /* Move iterator IT past the end of the text line it is in. */
5456 move_it_past_eol (it
)
5459 enum move_it_result rc
;
5461 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5462 if (rc
== MOVE_NEWLINE_OR_CR
)
5463 set_iterator_to_next (it
, 0);
5467 #if 0 /* Currently not used. */
5469 /* Return non-zero if some text between buffer positions START_CHARPOS
5470 and END_CHARPOS is invisible. IT->window is the window for text
5474 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5476 int start_charpos
, end_charpos
;
5478 Lisp_Object prop
, limit
;
5479 int invisible_found_p
;
5481 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5483 /* Is text at START invisible? */
5484 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5486 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5487 invisible_found_p
= 1;
5490 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5492 make_number (end_charpos
));
5493 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5496 return invisible_found_p
;
5502 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5503 negative means move up. DVPOS == 0 means move to the start of the
5504 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5505 NEED_Y_P is zero, IT->current_y will be left unchanged.
5507 Further optimization ideas: If we would know that IT->f doesn't use
5508 a face with proportional font, we could be faster for
5509 truncate-lines nil. */
5512 move_it_by_lines (it
, dvpos
, need_y_p
)
5514 int dvpos
, need_y_p
;
5516 struct position pos
;
5518 if (!FRAME_WINDOW_P (it
->f
))
5520 struct text_pos textpos
;
5522 /* We can use vmotion on frames without proportional fonts. */
5523 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5524 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5525 reseat (it
, textpos
, 1);
5526 it
->vpos
+= pos
.vpos
;
5527 it
->current_y
+= pos
.vpos
;
5529 else if (dvpos
== 0)
5531 /* DVPOS == 0 means move to the start of the screen line. */
5532 move_it_vertically_backward (it
, 0);
5533 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5536 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5540 int start_charpos
, i
;
5542 /* Start at the beginning of the screen line containing IT's
5544 move_it_vertically_backward (it
, 0);
5546 /* Go back -DVPOS visible lines and reseat the iterator there. */
5547 start_charpos
= IT_CHARPOS (*it
);
5548 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5549 back_to_previous_visible_line_start (it
);
5550 reseat (it
, it
->current
.pos
, 1);
5551 it
->current_x
= it
->hpos
= 0;
5553 /* Above call may have moved too far if continuation lines
5554 are involved. Scan forward and see if it did. */
5556 it2
.vpos
= it2
.current_y
= 0;
5557 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5558 it
->vpos
-= it2
.vpos
;
5559 it
->current_y
-= it2
.current_y
;
5560 it
->current_x
= it
->hpos
= 0;
5562 /* If we moved too far, move IT some lines forward. */
5563 if (it2
.vpos
> -dvpos
)
5565 int delta
= it2
.vpos
+ dvpos
;
5566 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5573 /***********************************************************************
5575 ***********************************************************************/
5578 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5582 add_to_log (format
, arg1
, arg2
)
5584 Lisp_Object arg1
, arg2
;
5586 Lisp_Object args
[3];
5587 Lisp_Object msg
, fmt
;
5590 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5592 /* Do nothing if called asynchronously. Inserting text into
5593 a buffer may call after-change-functions and alike and
5594 that would means running Lisp asynchronously. */
5595 if (handling_signal
)
5599 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5601 args
[0] = fmt
= build_string (format
);
5604 msg
= Fformat (3, args
);
5606 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5607 buffer
= (char *) alloca (len
);
5608 bcopy (XSTRING (msg
)->data
, buffer
, len
);
5610 message_dolog (buffer
, len
- 1, 1, 0);
5615 /* Output a newline in the *Messages* buffer if "needs" one. */
5618 message_log_maybe_newline ()
5620 if (message_log_need_newline
)
5621 message_dolog ("", 0, 1, 0);
5625 /* Add a string M of length NBYTES to the message log, optionally
5626 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5627 nonzero, means interpret the contents of M as multibyte. This
5628 function calls low-level routines in order to bypass text property
5629 hooks, etc. which might not be safe to run. */
5632 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5634 int nbytes
, nlflag
, multibyte
;
5636 if (!NILP (Vmessage_log_max
))
5638 struct buffer
*oldbuf
;
5639 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5640 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5641 int point_at_end
= 0;
5643 Lisp_Object old_deactivate_mark
, tem
;
5644 struct gcpro gcpro1
;
5646 old_deactivate_mark
= Vdeactivate_mark
;
5647 oldbuf
= current_buffer
;
5648 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5649 current_buffer
->undo_list
= Qt
;
5651 oldpoint
= message_dolog_marker1
;
5652 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5653 oldbegv
= message_dolog_marker2
;
5654 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5655 oldzv
= message_dolog_marker3
;
5656 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5657 GCPRO1 (old_deactivate_mark
);
5665 BEGV_BYTE
= BEG_BYTE
;
5668 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5670 /* Insert the string--maybe converting multibyte to single byte
5671 or vice versa, so that all the text fits the buffer. */
5673 && NILP (current_buffer
->enable_multibyte_characters
))
5675 int i
, c
, char_bytes
;
5676 unsigned char work
[1];
5678 /* Convert a multibyte string to single-byte
5679 for the *Message* buffer. */
5680 for (i
= 0; i
< nbytes
; i
+= nbytes
)
5682 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5683 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5685 : multibyte_char_to_unibyte (c
, Qnil
));
5686 insert_1_both (work
, 1, 1, 1, 0, 0);
5689 else if (! multibyte
5690 && ! NILP (current_buffer
->enable_multibyte_characters
))
5692 int i
, c
, char_bytes
;
5693 unsigned char *msg
= (unsigned char *) m
;
5694 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5695 /* Convert a single-byte string to multibyte
5696 for the *Message* buffer. */
5697 for (i
= 0; i
< nbytes
; i
++)
5699 c
= unibyte_char_to_multibyte (msg
[i
]);
5700 char_bytes
= CHAR_STRING (c
, str
);
5701 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5705 insert_1 (m
, nbytes
, 1, 0, 0);
5709 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5710 insert_1 ("\n", 1, 1, 0, 0);
5712 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5714 this_bol_byte
= PT_BYTE
;
5716 /* See if this line duplicates the previous one.
5717 If so, combine duplicates. */
5720 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5722 prev_bol_byte
= PT_BYTE
;
5724 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5725 this_bol
, this_bol_byte
);
5728 del_range_both (prev_bol
, prev_bol_byte
,
5729 this_bol
, this_bol_byte
, 0);
5735 /* If you change this format, don't forget to also
5736 change message_log_check_duplicate. */
5737 sprintf (dupstr
, " [%d times]", dup
);
5738 duplen
= strlen (dupstr
);
5739 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5740 insert_1 (dupstr
, duplen
, 1, 0, 1);
5745 /* If we have more than the desired maximum number of lines
5746 in the *Messages* buffer now, delete the oldest ones.
5747 This is safe because we don't have undo in this buffer. */
5749 if (NATNUMP (Vmessage_log_max
))
5751 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5752 -XFASTINT (Vmessage_log_max
) - 1, 0);
5753 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5756 BEGV
= XMARKER (oldbegv
)->charpos
;
5757 BEGV_BYTE
= marker_byte_position (oldbegv
);
5766 ZV
= XMARKER (oldzv
)->charpos
;
5767 ZV_BYTE
= marker_byte_position (oldzv
);
5771 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5773 /* We can't do Fgoto_char (oldpoint) because it will run some
5775 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5776 XMARKER (oldpoint
)->bytepos
);
5779 unchain_marker (oldpoint
);
5780 unchain_marker (oldbegv
);
5781 unchain_marker (oldzv
);
5783 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5784 set_buffer_internal (oldbuf
);
5786 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5787 message_log_need_newline
= !nlflag
;
5788 Vdeactivate_mark
= old_deactivate_mark
;
5793 /* We are at the end of the buffer after just having inserted a newline.
5794 (Note: We depend on the fact we won't be crossing the gap.)
5795 Check to see if the most recent message looks a lot like the previous one.
5796 Return 0 if different, 1 if the new one should just replace it, or a
5797 value N > 1 if we should also append " [N times]". */
5800 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5801 int prev_bol
, this_bol
;
5802 int prev_bol_byte
, this_bol_byte
;
5805 int len
= Z_BYTE
- 1 - this_bol_byte
;
5807 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5808 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5810 for (i
= 0; i
< len
; i
++)
5812 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5820 if (*p1
++ == ' ' && *p1
++ == '[')
5823 while (*p1
>= '0' && *p1
<= '9')
5824 n
= n
* 10 + *p1
++ - '0';
5825 if (strncmp (p1
, " times]\n", 8) == 0)
5832 /* Display an echo area message M with a specified length of NBYTES
5833 bytes. The string may include null characters. If M is 0, clear
5834 out any existing message, and let the mini-buffer text show
5837 The buffer M must continue to exist until after the echo area gets
5838 cleared or some other message gets displayed there. This means do
5839 not pass text that is stored in a Lisp string; do not pass text in
5840 a buffer that was alloca'd. */
5843 message2 (m
, nbytes
, multibyte
)
5848 /* First flush out any partial line written with print. */
5849 message_log_maybe_newline ();
5851 message_dolog (m
, nbytes
, 1, multibyte
);
5852 message2_nolog (m
, nbytes
, multibyte
);
5856 /* The non-logging counterpart of message2. */
5859 message2_nolog (m
, nbytes
, multibyte
)
5863 struct frame
*sf
= SELECTED_FRAME ();
5864 message_enable_multibyte
= multibyte
;
5868 if (noninteractive_need_newline
)
5869 putc ('\n', stderr
);
5870 noninteractive_need_newline
= 0;
5872 fwrite (m
, nbytes
, 1, stderr
);
5873 if (cursor_in_echo_area
== 0)
5874 fprintf (stderr
, "\n");
5877 /* A null message buffer means that the frame hasn't really been
5878 initialized yet. Error messages get reported properly by
5879 cmd_error, so this must be just an informative message; toss it. */
5880 else if (INTERACTIVE
5881 && sf
->glyphs_initialized_p
5882 && FRAME_MESSAGE_BUF (sf
))
5884 Lisp_Object mini_window
;
5887 /* Get the frame containing the mini-buffer
5888 that the selected frame is using. */
5889 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5890 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5892 FRAME_SAMPLE_VISIBILITY (f
);
5893 if (FRAME_VISIBLE_P (sf
)
5894 && ! FRAME_VISIBLE_P (f
))
5895 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5899 set_message (m
, Qnil
, nbytes
, multibyte
);
5900 if (minibuffer_auto_raise
)
5901 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5904 clear_message (1, 1);
5906 do_pending_window_change (0);
5907 echo_area_display (1);
5908 do_pending_window_change (0);
5909 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5910 (*frame_up_to_date_hook
) (f
);
5915 /* Display an echo area message M with a specified length of NBYTES
5916 bytes. The string may include null characters. If M is not a
5917 string, clear out any existing message, and let the mini-buffer
5918 text show through. */
5921 message3 (m
, nbytes
, multibyte
)
5926 struct gcpro gcpro1
;
5930 /* First flush out any partial line written with print. */
5931 message_log_maybe_newline ();
5933 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5934 message3_nolog (m
, nbytes
, multibyte
);
5940 /* The non-logging version of message3. */
5943 message3_nolog (m
, nbytes
, multibyte
)
5945 int nbytes
, multibyte
;
5947 struct frame
*sf
= SELECTED_FRAME ();
5948 message_enable_multibyte
= multibyte
;
5952 if (noninteractive_need_newline
)
5953 putc ('\n', stderr
);
5954 noninteractive_need_newline
= 0;
5956 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5957 if (cursor_in_echo_area
== 0)
5958 fprintf (stderr
, "\n");
5961 /* A null message buffer means that the frame hasn't really been
5962 initialized yet. Error messages get reported properly by
5963 cmd_error, so this must be just an informative message; toss it. */
5964 else if (INTERACTIVE
5965 && sf
->glyphs_initialized_p
5966 && FRAME_MESSAGE_BUF (sf
))
5968 Lisp_Object mini_window
;
5972 /* Get the frame containing the mini-buffer
5973 that the selected frame is using. */
5974 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5975 frame
= XWINDOW (mini_window
)->frame
;
5978 FRAME_SAMPLE_VISIBILITY (f
);
5979 if (FRAME_VISIBLE_P (sf
)
5980 && !FRAME_VISIBLE_P (f
))
5981 Fmake_frame_visible (frame
);
5983 if (STRINGP (m
) && XSTRING (m
)->size
)
5985 set_message (NULL
, m
, nbytes
, multibyte
);
5986 if (minibuffer_auto_raise
)
5987 Fraise_frame (frame
);
5990 clear_message (1, 1);
5992 do_pending_window_change (0);
5993 echo_area_display (1);
5994 do_pending_window_change (0);
5995 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5996 (*frame_up_to_date_hook
) (f
);
6001 /* Display a null-terminated echo area message M. If M is 0, clear
6002 out any existing message, and let the mini-buffer text show through.
6004 The buffer M must continue to exist until after the echo area gets
6005 cleared or some other message gets displayed there. Do not pass
6006 text that is stored in a Lisp string. Do not pass text in a buffer
6007 that was alloca'd. */
6013 message2 (m
, (m
? strlen (m
) : 0), 0);
6017 /* The non-logging counterpart of message1. */
6023 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6026 /* Display a message M which contains a single %s
6027 which gets replaced with STRING. */
6030 message_with_string (m
, string
, log
)
6039 if (noninteractive_need_newline
)
6040 putc ('\n', stderr
);
6041 noninteractive_need_newline
= 0;
6042 fprintf (stderr
, m
, XSTRING (string
)->data
);
6043 if (cursor_in_echo_area
== 0)
6044 fprintf (stderr
, "\n");
6048 else if (INTERACTIVE
)
6050 /* The frame whose minibuffer we're going to display the message on.
6051 It may be larger than the selected frame, so we need
6052 to use its buffer, not the selected frame's buffer. */
6053 Lisp_Object mini_window
;
6054 struct frame
*f
, *sf
= SELECTED_FRAME ();
6056 /* Get the frame containing the minibuffer
6057 that the selected frame is using. */
6058 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6059 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6061 /* A null message buffer means that the frame hasn't really been
6062 initialized yet. Error messages get reported properly by
6063 cmd_error, so this must be just an informative message; toss it. */
6064 if (FRAME_MESSAGE_BUF (f
))
6068 a
[0] = (char *) XSTRING (string
)->data
;
6070 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6071 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6074 message2 (FRAME_MESSAGE_BUF (f
), len
,
6075 STRING_MULTIBYTE (string
));
6077 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
6078 STRING_MULTIBYTE (string
));
6080 /* Print should start at the beginning of the message
6081 buffer next time. */
6082 message_buf_print
= 0;
6088 /* Dump an informative message to the minibuf. If M is 0, clear out
6089 any existing message, and let the mini-buffer text show through. */
6093 message (m
, a1
, a2
, a3
)
6095 EMACS_INT a1
, a2
, a3
;
6101 if (noninteractive_need_newline
)
6102 putc ('\n', stderr
);
6103 noninteractive_need_newline
= 0;
6104 fprintf (stderr
, m
, a1
, a2
, a3
);
6105 if (cursor_in_echo_area
== 0)
6106 fprintf (stderr
, "\n");
6110 else if (INTERACTIVE
)
6112 /* The frame whose mini-buffer we're going to display the message
6113 on. It may be larger than the selected frame, so we need to
6114 use its buffer, not the selected frame's buffer. */
6115 Lisp_Object mini_window
;
6116 struct frame
*f
, *sf
= SELECTED_FRAME ();
6118 /* Get the frame containing the mini-buffer
6119 that the selected frame is using. */
6120 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6121 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6123 /* A null message buffer means that the frame hasn't really been
6124 initialized yet. Error messages get reported properly by
6125 cmd_error, so this must be just an informative message; toss
6127 if (FRAME_MESSAGE_BUF (f
))
6138 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6139 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6141 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6142 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6144 #endif /* NO_ARG_ARRAY */
6146 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6151 /* Print should start at the beginning of the message
6152 buffer next time. */
6153 message_buf_print
= 0;
6159 /* The non-logging version of message. */
6162 message_nolog (m
, a1
, a2
, a3
)
6164 EMACS_INT a1
, a2
, a3
;
6166 Lisp_Object old_log_max
;
6167 old_log_max
= Vmessage_log_max
;
6168 Vmessage_log_max
= Qnil
;
6169 message (m
, a1
, a2
, a3
);
6170 Vmessage_log_max
= old_log_max
;
6174 /* Display the current message in the current mini-buffer. This is
6175 only called from error handlers in process.c, and is not time
6181 if (!NILP (echo_area_buffer
[0]))
6184 string
= Fcurrent_message ();
6185 message3 (string
, XSTRING (string
)->size
,
6186 !NILP (current_buffer
->enable_multibyte_characters
));
6191 /* Make sure echo area buffers in echo_buffers[] are life. If they
6192 aren't, make new ones. */
6195 ensure_echo_area_buffers ()
6199 for (i
= 0; i
< 2; ++i
)
6200 if (!BUFFERP (echo_buffer
[i
])
6201 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6204 Lisp_Object old_buffer
;
6207 old_buffer
= echo_buffer
[i
];
6208 sprintf (name
, " *Echo Area %d*", i
);
6209 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6210 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6212 for (j
= 0; j
< 2; ++j
)
6213 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6214 echo_area_buffer
[j
] = echo_buffer
[i
];
6219 /* Call FN with args A1..A4 with either the current or last displayed
6220 echo_area_buffer as current buffer.
6222 WHICH zero means use the current message buffer
6223 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6224 from echo_buffer[] and clear it.
6226 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6227 suitable buffer from echo_buffer[] and clear it.
6229 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6230 that the current message becomes the last displayed one, make
6231 choose a suitable buffer for echo_area_buffer[0], and clear it.
6233 Value is what FN returns. */
6236 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6239 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6245 int this_one
, the_other
, clear_buffer_p
, rc
;
6246 int count
= BINDING_STACK_SIZE ();
6248 /* If buffers aren't life, make new ones. */
6249 ensure_echo_area_buffers ();
6254 this_one
= 0, the_other
= 1;
6256 this_one
= 1, the_other
= 0;
6259 this_one
= 0, the_other
= 1;
6262 /* We need a fresh one in case the current echo buffer equals
6263 the one containing the last displayed echo area message. */
6264 if (!NILP (echo_area_buffer
[this_one
])
6265 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6266 echo_area_buffer
[this_one
] = Qnil
;
6269 /* Choose a suitable buffer from echo_buffer[] is we don't
6271 if (NILP (echo_area_buffer
[this_one
]))
6273 echo_area_buffer
[this_one
]
6274 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6275 ? echo_buffer
[the_other
]
6276 : echo_buffer
[this_one
]);
6280 buffer
= echo_area_buffer
[this_one
];
6282 /* Don't get confused by reusing the buffer used for echoing
6283 for a different purpose. */
6284 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6287 record_unwind_protect (unwind_with_echo_area_buffer
,
6288 with_echo_area_buffer_unwind_data (w
));
6290 /* Make the echo area buffer current. Note that for display
6291 purposes, it is not necessary that the displayed window's buffer
6292 == current_buffer, except for text property lookup. So, let's
6293 only set that buffer temporarily here without doing a full
6294 Fset_window_buffer. We must also change w->pointm, though,
6295 because otherwise an assertions in unshow_buffer fails, and Emacs
6297 set_buffer_internal_1 (XBUFFER (buffer
));
6301 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6304 current_buffer
->undo_list
= Qt
;
6305 current_buffer
->read_only
= Qnil
;
6306 specbind (Qinhibit_read_only
, Qt
);
6307 specbind (Qinhibit_modification_hooks
, Qt
);
6309 if (clear_buffer_p
&& Z
> BEG
)
6312 xassert (BEGV
>= BEG
);
6313 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6315 rc
= fn (a1
, a2
, a3
, a4
);
6317 xassert (BEGV
>= BEG
);
6318 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6320 unbind_to (count
, Qnil
);
6325 /* Save state that should be preserved around the call to the function
6326 FN called in with_echo_area_buffer. */
6329 with_echo_area_buffer_unwind_data (w
)
6335 /* Reduce consing by keeping one vector in
6336 Vwith_echo_area_save_vector. */
6337 vector
= Vwith_echo_area_save_vector
;
6338 Vwith_echo_area_save_vector
= Qnil
;
6341 vector
= Fmake_vector (make_number (7), Qnil
);
6343 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6344 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6345 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6349 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6350 AREF (vector
, i
) = w
->buffer
; ++i
;
6351 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6352 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6357 for (; i
< end
; ++i
)
6358 AREF (vector
, i
) = Qnil
;
6361 xassert (i
== ASIZE (vector
));
6366 /* Restore global state from VECTOR which was created by
6367 with_echo_area_buffer_unwind_data. */
6370 unwind_with_echo_area_buffer (vector
)
6373 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6374 Vdeactivate_mark
= AREF (vector
, 1);
6375 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6377 if (WINDOWP (AREF (vector
, 3)))
6380 Lisp_Object buffer
, charpos
, bytepos
;
6382 w
= XWINDOW (AREF (vector
, 3));
6383 buffer
= AREF (vector
, 4);
6384 charpos
= AREF (vector
, 5);
6385 bytepos
= AREF (vector
, 6);
6388 set_marker_both (w
->pointm
, buffer
,
6389 XFASTINT (charpos
), XFASTINT (bytepos
));
6392 Vwith_echo_area_save_vector
= vector
;
6397 /* Set up the echo area for use by print functions. MULTIBYTE_P
6398 non-zero means we will print multibyte. */
6401 setup_echo_area_for_printing (multibyte_p
)
6404 ensure_echo_area_buffers ();
6406 if (!message_buf_print
)
6408 /* A message has been output since the last time we printed.
6409 Choose a fresh echo area buffer. */
6410 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6411 echo_area_buffer
[0] = echo_buffer
[1];
6413 echo_area_buffer
[0] = echo_buffer
[0];
6415 /* Switch to that buffer and clear it. */
6416 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6417 current_buffer
->truncate_lines
= Qnil
;
6421 int count
= BINDING_STACK_SIZE ();
6422 specbind (Qinhibit_read_only
, Qt
);
6424 unbind_to (count
, Qnil
);
6426 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6428 /* Set up the buffer for the multibyteness we need. */
6430 != !NILP (current_buffer
->enable_multibyte_characters
))
6431 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6433 /* Raise the frame containing the echo area. */
6434 if (minibuffer_auto_raise
)
6436 struct frame
*sf
= SELECTED_FRAME ();
6437 Lisp_Object mini_window
;
6438 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6439 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6442 message_log_maybe_newline ();
6443 message_buf_print
= 1;
6447 if (NILP (echo_area_buffer
[0]))
6449 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6450 echo_area_buffer
[0] = echo_buffer
[1];
6452 echo_area_buffer
[0] = echo_buffer
[0];
6455 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6457 /* Someone switched buffers between print requests. */
6458 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6459 current_buffer
->truncate_lines
= Qnil
;
6465 /* Display an echo area message in window W. Value is non-zero if W's
6466 height is changed. If display_last_displayed_message_p is
6467 non-zero, display the message that was last displayed, otherwise
6468 display the current message. */
6471 display_echo_area (w
)
6474 int i
, no_message_p
, window_height_changed_p
, count
;
6476 /* Temporarily disable garbage collections while displaying the echo
6477 area. This is done because a GC can print a message itself.
6478 That message would modify the echo area buffer's contents while a
6479 redisplay of the buffer is going on, and seriously confuse
6481 count
= inhibit_garbage_collection ();
6483 /* If there is no message, we must call display_echo_area_1
6484 nevertheless because it resizes the window. But we will have to
6485 reset the echo_area_buffer in question to nil at the end because
6486 with_echo_area_buffer will sets it to an empty buffer. */
6487 i
= display_last_displayed_message_p
? 1 : 0;
6488 no_message_p
= NILP (echo_area_buffer
[i
]);
6490 window_height_changed_p
6491 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6492 display_echo_area_1
,
6493 (EMACS_INT
) w
, Qnil
, 0, 0);
6496 echo_area_buffer
[i
] = Qnil
;
6498 unbind_to (count
, Qnil
);
6499 return window_height_changed_p
;
6503 /* Helper for display_echo_area. Display the current buffer which
6504 contains the current echo area message in window W, a mini-window,
6505 a pointer to which is passed in A1. A2..A4 are currently not used.
6506 Change the height of W so that all of the message is displayed.
6507 Value is non-zero if height of W was changed. */
6510 display_echo_area_1 (a1
, a2
, a3
, a4
)
6515 struct window
*w
= (struct window
*) a1
;
6517 struct text_pos start
;
6518 int window_height_changed_p
= 0;
6520 /* Do this before displaying, so that we have a large enough glyph
6521 matrix for the display. */
6522 window_height_changed_p
= resize_mini_window (w
, 0);
6525 clear_glyph_matrix (w
->desired_matrix
);
6526 XSETWINDOW (window
, w
);
6527 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6528 try_window (window
, start
);
6530 return window_height_changed_p
;
6534 /* Resize the echo area window to exactly the size needed for the
6535 currently displayed message, if there is one. If a mini-buffer
6536 is active, don't shrink it. */
6539 resize_echo_area_exactly ()
6541 if (BUFFERP (echo_area_buffer
[0])
6542 && WINDOWP (echo_area_window
))
6544 struct window
*w
= XWINDOW (echo_area_window
);
6546 Lisp_Object resize_exactly
;
6548 if (minibuf_level
== 0)
6549 resize_exactly
= Qt
;
6551 resize_exactly
= Qnil
;
6553 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6554 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6557 ++windows_or_buffers_changed
;
6558 ++update_mode_lines
;
6559 redisplay_internal (0);
6565 /* Callback function for with_echo_area_buffer, when used from
6566 resize_echo_area_exactly. A1 contains a pointer to the window to
6567 resize, EXACTLY non-nil means resize the mini-window exactly to the
6568 size of the text displayed. A3 and A4 are not used. Value is what
6569 resize_mini_window returns. */
6572 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6574 Lisp_Object exactly
;
6577 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6581 /* Resize mini-window W to fit the size of its contents. EXACT:P
6582 means size the window exactly to the size needed. Otherwise, it's
6583 only enlarged until W's buffer is empty. Value is non-zero if
6584 the window height has been changed. */
6587 resize_mini_window (w
, exact_p
)
6591 struct frame
*f
= XFRAME (w
->frame
);
6592 int window_height_changed_p
= 0;
6594 xassert (MINI_WINDOW_P (w
));
6596 /* Don't resize windows while redisplaying a window; it would
6597 confuse redisplay functions when the size of the window they are
6598 displaying changes from under them. Such a resizing can happen,
6599 for instance, when which-func prints a long message while
6600 we are running fontification-functions. We're running these
6601 functions with safe_call which binds inhibit-redisplay to t. */
6602 if (!NILP (Vinhibit_redisplay
))
6605 /* Nil means don't try to resize. */
6606 if (NILP (Vresize_mini_windows
)
6607 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6610 if (!FRAME_MINIBUF_ONLY_P (f
))
6613 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6614 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6615 int height
, max_height
;
6616 int unit
= CANON_Y_UNIT (f
);
6617 struct text_pos start
;
6618 struct buffer
*old_current_buffer
= NULL
;
6620 if (current_buffer
!= XBUFFER (w
->buffer
))
6622 old_current_buffer
= current_buffer
;
6623 set_buffer_internal (XBUFFER (w
->buffer
));
6626 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6628 /* Compute the max. number of lines specified by the user. */
6629 if (FLOATP (Vmax_mini_window_height
))
6630 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6631 else if (INTEGERP (Vmax_mini_window_height
))
6632 max_height
= XINT (Vmax_mini_window_height
);
6634 max_height
= total_height
/ 4;
6636 /* Correct that max. height if it's bogus. */
6637 max_height
= max (1, max_height
);
6638 max_height
= min (total_height
, max_height
);
6640 /* Find out the height of the text in the window. */
6641 if (it
.truncate_lines_p
)
6646 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6647 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6648 height
= it
.current_y
+ last_height
;
6650 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6651 height
-= it
.extra_line_spacing
;
6652 height
= (height
+ unit
- 1) / unit
;
6655 /* Compute a suitable window start. */
6656 if (height
> max_height
)
6658 height
= max_height
;
6659 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6660 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6661 start
= it
.current
.pos
;
6664 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6665 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6667 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6669 /* Let it grow only, until we display an empty message, in which
6670 case the window shrinks again. */
6671 if (height
> XFASTINT (w
->height
))
6673 int old_height
= XFASTINT (w
->height
);
6674 freeze_window_starts (f
, 1);
6675 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6676 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6678 else if (height
< XFASTINT (w
->height
)
6679 && (exact_p
|| BEGV
== ZV
))
6681 int old_height
= XFASTINT (w
->height
);
6682 freeze_window_starts (f
, 0);
6683 shrink_mini_window (w
);
6684 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6689 /* Always resize to exact size needed. */
6690 if (height
> XFASTINT (w
->height
))
6692 int old_height
= XFASTINT (w
->height
);
6693 freeze_window_starts (f
, 1);
6694 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6695 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6697 else if (height
< XFASTINT (w
->height
))
6699 int old_height
= XFASTINT (w
->height
);
6700 freeze_window_starts (f
, 0);
6701 shrink_mini_window (w
);
6705 freeze_window_starts (f
, 1);
6706 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6709 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6713 if (old_current_buffer
)
6714 set_buffer_internal (old_current_buffer
);
6717 return window_height_changed_p
;
6721 /* Value is the current message, a string, or nil if there is no
6729 if (NILP (echo_area_buffer
[0]))
6733 with_echo_area_buffer (0, 0, current_message_1
,
6734 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6736 echo_area_buffer
[0] = Qnil
;
6744 current_message_1 (a1
, a2
, a3
, a4
)
6749 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6752 *msg
= make_buffer_string (BEG
, Z
, 1);
6759 /* Push the current message on Vmessage_stack for later restauration
6760 by restore_message. Value is non-zero if the current message isn't
6761 empty. This is a relatively infrequent operation, so it's not
6762 worth optimizing. */
6768 msg
= current_message ();
6769 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6770 return STRINGP (msg
);
6774 /* Handler for record_unwind_protect calling pop_message. */
6777 push_message_unwind (dummy
)
6785 /* Restore message display from the top of Vmessage_stack. */
6792 xassert (CONSP (Vmessage_stack
));
6793 msg
= XCAR (Vmessage_stack
);
6795 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6797 message3_nolog (msg
, 0, 0);
6801 /* Pop the top-most entry off Vmessage_stack. */
6806 xassert (CONSP (Vmessage_stack
));
6807 Vmessage_stack
= XCDR (Vmessage_stack
);
6811 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6812 exits. If the stack is not empty, we have a missing pop_message
6816 check_message_stack ()
6818 if (!NILP (Vmessage_stack
))
6823 /* Truncate to NCHARS what will be displayed in the echo area the next
6824 time we display it---but don't redisplay it now. */
6827 truncate_echo_area (nchars
)
6831 echo_area_buffer
[0] = Qnil
;
6832 /* A null message buffer means that the frame hasn't really been
6833 initialized yet. Error messages get reported properly by
6834 cmd_error, so this must be just an informative message; toss it. */
6835 else if (!noninteractive
6837 && !NILP (echo_area_buffer
[0]))
6839 struct frame
*sf
= SELECTED_FRAME ();
6840 if (FRAME_MESSAGE_BUF (sf
))
6841 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6846 /* Helper function for truncate_echo_area. Truncate the current
6847 message to at most NCHARS characters. */
6850 truncate_message_1 (nchars
, a2
, a3
, a4
)
6855 if (BEG
+ nchars
< Z
)
6856 del_range (BEG
+ nchars
, Z
);
6858 echo_area_buffer
[0] = Qnil
;
6863 /* Set the current message to a substring of S or STRING.
6865 If STRING is a Lisp string, set the message to the first NBYTES
6866 bytes from STRING. NBYTES zero means use the whole string. If
6867 STRING is multibyte, the message will be displayed multibyte.
6869 If S is not null, set the message to the first LEN bytes of S. LEN
6870 zero means use the whole string. MULTIBYTE_P non-zero means S is
6871 multibyte. Display the message multibyte in that case. */
6874 set_message (s
, string
, nbytes
, multibyte_p
)
6879 message_enable_multibyte
6880 = ((s
&& multibyte_p
)
6881 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6883 with_echo_area_buffer (0, -1, set_message_1
,
6884 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6885 message_buf_print
= 0;
6886 help_echo_showing_p
= 0;
6890 /* Helper function for set_message. Arguments have the same meaning
6891 as there, with A1 corresponding to S and A2 corresponding to STRING
6892 This function is called with the echo area buffer being
6896 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6899 EMACS_INT nbytes
, multibyte_p
;
6901 char *s
= (char *) a1
;
6902 Lisp_Object string
= a2
;
6906 /* Change multibyteness of the echo buffer appropriately. */
6907 if (message_enable_multibyte
6908 != !NILP (current_buffer
->enable_multibyte_characters
))
6909 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6911 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6913 /* Insert new message at BEG. */
6914 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6916 if (STRINGP (string
))
6921 nbytes
= XSTRING (string
)->size_byte
;
6922 nchars
= string_byte_to_char (string
, nbytes
);
6924 /* This function takes care of single/multibyte conversion. We
6925 just have to ensure that the echo area buffer has the right
6926 setting of enable_multibyte_characters. */
6927 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6932 nbytes
= strlen (s
);
6934 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6936 /* Convert from multi-byte to single-byte. */
6938 unsigned char work
[1];
6940 /* Convert a multibyte string to single-byte. */
6941 for (i
= 0; i
< nbytes
; i
+= n
)
6943 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6944 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6946 : multibyte_char_to_unibyte (c
, Qnil
));
6947 insert_1_both (work
, 1, 1, 1, 0, 0);
6950 else if (!multibyte_p
6951 && !NILP (current_buffer
->enable_multibyte_characters
))
6953 /* Convert from single-byte to multi-byte. */
6955 unsigned char *msg
= (unsigned char *) s
;
6956 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6958 /* Convert a single-byte string to multibyte. */
6959 for (i
= 0; i
< nbytes
; i
++)
6961 c
= unibyte_char_to_multibyte (msg
[i
]);
6962 n
= CHAR_STRING (c
, str
);
6963 insert_1_both (str
, 1, n
, 1, 0, 0);
6967 insert_1 (s
, nbytes
, 1, 0, 0);
6974 /* Clear messages. CURRENT_P non-zero means clear the current
6975 message. LAST_DISPLAYED_P non-zero means clear the message
6979 clear_message (current_p
, last_displayed_p
)
6980 int current_p
, last_displayed_p
;
6984 echo_area_buffer
[0] = Qnil
;
6985 message_cleared_p
= 1;
6988 if (last_displayed_p
)
6989 echo_area_buffer
[1] = Qnil
;
6991 message_buf_print
= 0;
6994 /* Clear garbaged frames.
6996 This function is used where the old redisplay called
6997 redraw_garbaged_frames which in turn called redraw_frame which in
6998 turn called clear_frame. The call to clear_frame was a source of
6999 flickering. I believe a clear_frame is not necessary. It should
7000 suffice in the new redisplay to invalidate all current matrices,
7001 and ensure a complete redisplay of all windows. */
7004 clear_garbaged_frames ()
7008 Lisp_Object tail
, frame
;
7010 FOR_EACH_FRAME (tail
, frame
)
7012 struct frame
*f
= XFRAME (frame
);
7014 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7017 Fredraw_frame (frame
);
7018 clear_current_matrices (f
);
7025 ++windows_or_buffers_changed
;
7030 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7031 is non-zero update selected_frame. Value is non-zero if the
7032 mini-windows height has been changed. */
7035 echo_area_display (update_frame_p
)
7038 Lisp_Object mini_window
;
7041 int window_height_changed_p
= 0;
7042 struct frame
*sf
= SELECTED_FRAME ();
7044 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7045 w
= XWINDOW (mini_window
);
7046 f
= XFRAME (WINDOW_FRAME (w
));
7048 /* Don't display if frame is invisible or not yet initialized. */
7049 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7052 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7054 #ifdef HAVE_WINDOW_SYSTEM
7055 /* When Emacs starts, selected_frame may be a visible terminal
7056 frame, even if we run under a window system. If we let this
7057 through, a message would be displayed on the terminal. */
7058 if (EQ (selected_frame
, Vterminal_frame
)
7059 && !NILP (Vwindow_system
))
7061 #endif /* HAVE_WINDOW_SYSTEM */
7064 /* Redraw garbaged frames. */
7066 clear_garbaged_frames ();
7068 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7070 echo_area_window
= mini_window
;
7071 window_height_changed_p
= display_echo_area (w
);
7072 w
->must_be_updated_p
= 1;
7074 /* Update the display, unless called from redisplay_internal.
7075 Also don't update the screen during redisplay itself. The
7076 update will happen at the end of redisplay, and an update
7077 here could cause confusion. */
7078 if (update_frame_p
&& !redisplaying_p
)
7082 /* If the display update has been interrupted by pending
7083 input, update mode lines in the frame. Due to the
7084 pending input, it might have been that redisplay hasn't
7085 been called, so that mode lines above the echo area are
7086 garbaged. This looks odd, so we prevent it here. */
7087 if (!display_completed
)
7088 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7090 if (window_height_changed_p
7091 /* Don't do this if Emacs is shutting down. Redisplay
7092 needs to run hooks. */
7093 && !NILP (Vrun_hooks
))
7095 /* Must update other windows. Likewise as in other
7096 cases, don't let this update be interrupted by
7098 int count
= BINDING_STACK_SIZE ();
7099 specbind (Qredisplay_dont_pause
, Qt
);
7100 windows_or_buffers_changed
= 1;
7101 redisplay_internal (0);
7102 unbind_to (count
, Qnil
);
7104 else if (FRAME_WINDOW_P (f
) && n
== 0)
7106 /* Window configuration is the same as before.
7107 Can do with a display update of the echo area,
7108 unless we displayed some mode lines. */
7109 update_single_window (w
, 1);
7110 rif
->flush_display (f
);
7113 update_frame (f
, 1, 1);
7115 /* If cursor is in the echo area, make sure that the next
7116 redisplay displays the minibuffer, so that the cursor will
7117 be replaced with what the minibuffer wants. */
7118 if (cursor_in_echo_area
)
7119 ++windows_or_buffers_changed
;
7122 else if (!EQ (mini_window
, selected_window
))
7123 windows_or_buffers_changed
++;
7125 /* Last displayed message is now the current message. */
7126 echo_area_buffer
[1] = echo_area_buffer
[0];
7128 /* Prevent redisplay optimization in redisplay_internal by resetting
7129 this_line_start_pos. This is done because the mini-buffer now
7130 displays the message instead of its buffer text. */
7131 if (EQ (mini_window
, selected_window
))
7132 CHARPOS (this_line_start_pos
) = 0;
7134 return window_height_changed_p
;
7139 /***********************************************************************
7141 ***********************************************************************/
7144 #ifdef HAVE_WINDOW_SYSTEM
7146 /* A buffer for constructing frame titles in it; allocated from the
7147 heap in init_xdisp and resized as needed in store_frame_title_char. */
7149 static char *frame_title_buf
;
7151 /* The buffer's end, and a current output position in it. */
7153 static char *frame_title_buf_end
;
7154 static char *frame_title_ptr
;
7157 /* Store a single character C for the frame title in frame_title_buf.
7158 Re-allocate frame_title_buf if necessary. */
7161 store_frame_title_char (c
)
7164 /* If output position has reached the end of the allocated buffer,
7165 double the buffer's size. */
7166 if (frame_title_ptr
== frame_title_buf_end
)
7168 int len
= frame_title_ptr
- frame_title_buf
;
7169 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7170 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7171 frame_title_buf_end
= frame_title_buf
+ new_size
;
7172 frame_title_ptr
= frame_title_buf
+ len
;
7175 *frame_title_ptr
++ = c
;
7179 /* Store part of a frame title in frame_title_buf, beginning at
7180 frame_title_ptr. STR is the string to store. Do not copy
7181 characters that yield more columns than PRECISION; PRECISION <= 0
7182 means copy the whole string. Pad with spaces until FIELD_WIDTH
7183 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7184 pad. Called from display_mode_element when it is used to build a
7188 store_frame_title (str
, field_width
, precision
)
7190 int field_width
, precision
;
7195 /* Copy at most PRECISION chars from STR. */
7196 nbytes
= strlen (str
);
7197 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7199 store_frame_title_char (*str
++);
7201 /* Fill up with spaces until FIELD_WIDTH reached. */
7202 while (field_width
> 0
7205 store_frame_title_char (' ');
7213 /* Set the title of FRAME, if it has changed. The title format is
7214 Vicon_title_format if FRAME is iconified, otherwise it is
7215 frame_title_format. */
7218 x_consider_frame_title (frame
)
7221 struct frame
*f
= XFRAME (frame
);
7223 if (FRAME_WINDOW_P (f
)
7224 || FRAME_MINIBUF_ONLY_P (f
)
7225 || f
->explicit_name
)
7227 /* Do we have more than one visible frame on this X display? */
7230 struct buffer
*obuf
;
7234 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7236 Lisp_Object other_frame
= XCAR (tail
);
7237 struct frame
*tf
= XFRAME (other_frame
);
7240 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7241 && !FRAME_MINIBUF_ONLY_P (tf
)
7242 && !EQ (other_frame
, tip_frame
)
7243 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7247 /* Set global variable indicating that multiple frames exist. */
7248 multiple_frames
= CONSP (tail
);
7250 /* Switch to the buffer of selected window of the frame. Set up
7251 frame_title_ptr so that display_mode_element will output into it;
7252 then display the title. */
7253 obuf
= current_buffer
;
7254 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7255 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7256 frame_title_ptr
= frame_title_buf
;
7257 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7258 NULL
, DEFAULT_FACE_ID
);
7259 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
);
7260 len
= frame_title_ptr
- frame_title_buf
;
7261 frame_title_ptr
= NULL
;
7262 set_buffer_internal_1 (obuf
);
7264 /* Set the title only if it's changed. This avoids consing in
7265 the common case where it hasn't. (If it turns out that we've
7266 already wasted too much time by walking through the list with
7267 display_mode_element, then we might need to optimize at a
7268 higher level than this.) */
7269 if (! STRINGP (f
->name
)
7270 || STRING_BYTES (XSTRING (f
->name
)) != len
7271 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
7272 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7276 #else /* not HAVE_WINDOW_SYSTEM */
7278 #define frame_title_ptr ((char *)0)
7279 #define store_frame_title(str, mincol, maxcol) 0
7281 #endif /* not HAVE_WINDOW_SYSTEM */
7286 /***********************************************************************
7288 ***********************************************************************/
7291 /* Prepare for redisplay by updating menu-bar item lists when
7292 appropriate. This can call eval. */
7295 prepare_menu_bars ()
7298 struct gcpro gcpro1
, gcpro2
;
7300 Lisp_Object tooltip_frame
;
7302 #ifdef HAVE_WINDOW_SYSTEM
7303 tooltip_frame
= tip_frame
;
7305 tooltip_frame
= Qnil
;
7308 /* Update all frame titles based on their buffer names, etc. We do
7309 this before the menu bars so that the buffer-menu will show the
7310 up-to-date frame titles. */
7311 #ifdef HAVE_WINDOW_SYSTEM
7312 if (windows_or_buffers_changed
|| update_mode_lines
)
7314 Lisp_Object tail
, frame
;
7316 FOR_EACH_FRAME (tail
, frame
)
7319 if (!EQ (frame
, tooltip_frame
)
7320 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7321 x_consider_frame_title (frame
);
7324 #endif /* HAVE_WINDOW_SYSTEM */
7326 /* Update the menu bar item lists, if appropriate. This has to be
7327 done before any actual redisplay or generation of display lines. */
7328 all_windows
= (update_mode_lines
7329 || buffer_shared
> 1
7330 || windows_or_buffers_changed
);
7333 Lisp_Object tail
, frame
;
7334 int count
= BINDING_STACK_SIZE ();
7336 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7338 FOR_EACH_FRAME (tail
, frame
)
7342 /* Ignore tooltip frame. */
7343 if (EQ (frame
, tooltip_frame
))
7346 /* If a window on this frame changed size, report that to
7347 the user and clear the size-change flag. */
7348 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7350 Lisp_Object functions
;
7352 /* Clear flag first in case we get an error below. */
7353 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7354 functions
= Vwindow_size_change_functions
;
7355 GCPRO2 (tail
, functions
);
7357 while (CONSP (functions
))
7359 call1 (XCAR (functions
), frame
);
7360 functions
= XCDR (functions
);
7366 update_menu_bar (f
, 0);
7367 #ifdef HAVE_WINDOW_SYSTEM
7368 update_tool_bar (f
, 0);
7373 unbind_to (count
, Qnil
);
7377 struct frame
*sf
= SELECTED_FRAME ();
7378 update_menu_bar (sf
, 1);
7379 #ifdef HAVE_WINDOW_SYSTEM
7380 update_tool_bar (sf
, 1);
7384 /* Motif needs this. See comment in xmenu.c. Turn it off when
7385 pending_menu_activation is not defined. */
7386 #ifdef USE_X_TOOLKIT
7387 pending_menu_activation
= 0;
7392 /* Update the menu bar item list for frame F. This has to be done
7393 before we start to fill in any display lines, because it can call
7396 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7399 update_menu_bar (f
, save_match_data
)
7401 int save_match_data
;
7404 register struct window
*w
;
7406 /* If called recursively during a menu update, do nothing. This can
7407 happen when, for instance, an activate-menubar-hook causes a
7409 if (inhibit_menubar_update
)
7412 window
= FRAME_SELECTED_WINDOW (f
);
7413 w
= XWINDOW (window
);
7415 if (update_mode_lines
)
7416 w
->update_mode_line
= Qt
;
7418 if (FRAME_WINDOW_P (f
)
7420 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7421 FRAME_EXTERNAL_MENU_BAR (f
)
7423 FRAME_MENU_BAR_LINES (f
) > 0
7425 : FRAME_MENU_BAR_LINES (f
) > 0)
7427 /* If the user has switched buffers or windows, we need to
7428 recompute to reflect the new bindings. But we'll
7429 recompute when update_mode_lines is set too; that means
7430 that people can use force-mode-line-update to request
7431 that the menu bar be recomputed. The adverse effect on
7432 the rest of the redisplay algorithm is about the same as
7433 windows_or_buffers_changed anyway. */
7434 if (windows_or_buffers_changed
7435 || !NILP (w
->update_mode_line
)
7436 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7437 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7438 != !NILP (w
->last_had_star
))
7439 || ((!NILP (Vtransient_mark_mode
)
7440 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7441 != !NILP (w
->region_showing
)))
7443 struct buffer
*prev
= current_buffer
;
7444 int count
= BINDING_STACK_SIZE ();
7446 specbind (Qinhibit_menubar_update
, Qt
);
7448 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7449 if (save_match_data
)
7450 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7451 if (NILP (Voverriding_local_map_menu_flag
))
7453 specbind (Qoverriding_terminal_local_map
, Qnil
);
7454 specbind (Qoverriding_local_map
, Qnil
);
7457 /* Run the Lucid hook. */
7458 safe_run_hooks (Qactivate_menubar_hook
);
7460 /* If it has changed current-menubar from previous value,
7461 really recompute the menu-bar from the value. */
7462 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7463 call0 (Qrecompute_lucid_menubar
);
7465 safe_run_hooks (Qmenu_bar_update_hook
);
7466 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7468 /* Redisplay the menu bar in case we changed it. */
7469 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7470 if (FRAME_WINDOW_P (f
)
7471 #if defined (macintosh)
7472 /* All frames on Mac OS share the same menubar. So only the
7473 selected frame should be allowed to set it. */
7474 && f
== SELECTED_FRAME ()
7477 set_frame_menubar (f
, 0, 0);
7479 /* On a terminal screen, the menu bar is an ordinary screen
7480 line, and this makes it get updated. */
7481 w
->update_mode_line
= Qt
;
7482 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7483 /* In the non-toolkit version, the menu bar is an ordinary screen
7484 line, and this makes it get updated. */
7485 w
->update_mode_line
= Qt
;
7486 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7488 unbind_to (count
, Qnil
);
7489 set_buffer_internal_1 (prev
);
7496 /***********************************************************************
7498 ***********************************************************************/
7500 #ifdef HAVE_WINDOW_SYSTEM
7502 /* Update the tool-bar item list for frame F. This has to be done
7503 before we start to fill in any display lines. Called from
7504 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7505 and restore it here. */
7508 update_tool_bar (f
, save_match_data
)
7510 int save_match_data
;
7512 if (WINDOWP (f
->tool_bar_window
)
7513 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7518 window
= FRAME_SELECTED_WINDOW (f
);
7519 w
= XWINDOW (window
);
7521 /* If the user has switched buffers or windows, we need to
7522 recompute to reflect the new bindings. But we'll
7523 recompute when update_mode_lines is set too; that means
7524 that people can use force-mode-line-update to request
7525 that the menu bar be recomputed. The adverse effect on
7526 the rest of the redisplay algorithm is about the same as
7527 windows_or_buffers_changed anyway. */
7528 if (windows_or_buffers_changed
7529 || !NILP (w
->update_mode_line
)
7530 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7531 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7532 != !NILP (w
->last_had_star
))
7533 || ((!NILP (Vtransient_mark_mode
)
7534 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7535 != !NILP (w
->region_showing
)))
7537 struct buffer
*prev
= current_buffer
;
7538 int count
= BINDING_STACK_SIZE ();
7540 /* Set current_buffer to the buffer of the selected
7541 window of the frame, so that we get the right local
7543 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7545 /* Save match data, if we must. */
7546 if (save_match_data
)
7547 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7549 /* Make sure that we don't accidentally use bogus keymaps. */
7550 if (NILP (Voverriding_local_map_menu_flag
))
7552 specbind (Qoverriding_terminal_local_map
, Qnil
);
7553 specbind (Qoverriding_local_map
, Qnil
);
7556 /* Build desired tool-bar items from keymaps. */
7558 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7560 /* Redisplay the tool-bar in case we changed it. */
7561 w
->update_mode_line
= Qt
;
7563 unbind_to (count
, Qnil
);
7564 set_buffer_internal_1 (prev
);
7570 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7571 F's desired tool-bar contents. F->tool_bar_items must have
7572 been set up previously by calling prepare_menu_bars. */
7575 build_desired_tool_bar_string (f
)
7578 int i
, size
, size_needed
;
7579 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7580 Lisp_Object image
, plist
, props
;
7582 image
= plist
= props
= Qnil
;
7583 GCPRO3 (image
, plist
, props
);
7585 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7586 Otherwise, make a new string. */
7588 /* The size of the string we might be able to reuse. */
7589 size
= (STRINGP (f
->desired_tool_bar_string
)
7590 ? XSTRING (f
->desired_tool_bar_string
)->size
7593 /* We need one space in the string for each image. */
7594 size_needed
= f
->n_tool_bar_items
;
7596 /* Reuse f->desired_tool_bar_string, if possible. */
7597 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7598 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7602 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7603 Fremove_text_properties (make_number (0), make_number (size
),
7604 props
, f
->desired_tool_bar_string
);
7607 /* Put a `display' property on the string for the images to display,
7608 put a `menu_item' property on tool-bar items with a value that
7609 is the index of the item in F's tool-bar item vector. */
7610 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7612 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7614 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7615 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7616 int hmargin
, vmargin
, relief
, idx
, end
;
7617 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7619 /* If image is a vector, choose the image according to the
7621 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7622 if (VECTORP (image
))
7626 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7627 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7630 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7631 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7633 xassert (ASIZE (image
) >= idx
);
7634 image
= AREF (image
, idx
);
7639 /* Ignore invalid image specifications. */
7640 if (!valid_image_p (image
))
7643 /* Display the tool-bar button pressed, or depressed. */
7644 plist
= Fcopy_sequence (XCDR (image
));
7646 /* Compute margin and relief to draw. */
7647 relief
= (tool_bar_button_relief
>= 0
7648 ? tool_bar_button_relief
7649 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7650 hmargin
= vmargin
= relief
;
7652 if (INTEGERP (Vtool_bar_button_margin
)
7653 && XINT (Vtool_bar_button_margin
) > 0)
7655 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7656 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7658 else if (CONSP (Vtool_bar_button_margin
))
7660 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7661 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7662 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7664 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7665 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7666 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7669 if (auto_raise_tool_bar_buttons_p
)
7671 /* Add a `:relief' property to the image spec if the item is
7675 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7682 /* If image is selected, display it pressed, i.e. with a
7683 negative relief. If it's not selected, display it with a
7685 plist
= Fplist_put (plist
, QCrelief
,
7687 ? make_number (-relief
)
7688 : make_number (relief
)));
7693 /* Put a margin around the image. */
7694 if (hmargin
|| vmargin
)
7696 if (hmargin
== vmargin
)
7697 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7699 plist
= Fplist_put (plist
, QCmargin
,
7700 Fcons (make_number (hmargin
),
7701 make_number (vmargin
)));
7704 /* If button is not enabled, and we don't have special images
7705 for the disabled state, make the image appear disabled by
7706 applying an appropriate algorithm to it. */
7707 if (!enabled_p
&& idx
< 0)
7708 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7710 /* Put a `display' text property on the string for the image to
7711 display. Put a `menu-item' property on the string that gives
7712 the start of this item's properties in the tool-bar items
7714 image
= Fcons (Qimage
, plist
);
7715 props
= list4 (Qdisplay
, image
,
7716 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7718 /* Let the last image hide all remaining spaces in the tool bar
7719 string. The string can be longer than needed when we reuse a
7721 if (i
+ 1 == f
->n_tool_bar_items
)
7722 end
= XSTRING (f
->desired_tool_bar_string
)->size
;
7725 Fadd_text_properties (make_number (i
), make_number (end
),
7726 props
, f
->desired_tool_bar_string
);
7734 /* Display one line of the tool-bar of frame IT->f. */
7737 display_tool_bar_line (it
)
7740 struct glyph_row
*row
= it
->glyph_row
;
7741 int max_x
= it
->last_visible_x
;
7744 prepare_desired_row (row
);
7745 row
->y
= it
->current_y
;
7747 /* Note that this isn't made use of if the face hasn't a box,
7748 so there's no need to check the face here. */
7749 it
->start_of_box_run_p
= 1;
7751 while (it
->current_x
< max_x
)
7753 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7755 /* Get the next display element. */
7756 if (!get_next_display_element (it
))
7759 /* Produce glyphs. */
7760 x_before
= it
->current_x
;
7761 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7762 PRODUCE_GLYPHS (it
);
7764 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7769 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7771 if (x
+ glyph
->pixel_width
> max_x
)
7773 /* Glyph doesn't fit on line. */
7774 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7780 x
+= glyph
->pixel_width
;
7784 /* Stop at line ends. */
7785 if (ITERATOR_AT_END_OF_LINE_P (it
))
7788 set_iterator_to_next (it
, 1);
7793 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7794 extend_face_to_end_of_line (it
);
7795 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7796 last
->right_box_line_p
= 1;
7797 if (last
== row
->glyphs
[TEXT_AREA
])
7798 last
->left_box_line_p
= 1;
7799 compute_line_metrics (it
);
7801 /* If line is empty, make it occupy the rest of the tool-bar. */
7802 if (!row
->displays_text_p
)
7804 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7805 row
->ascent
= row
->phys_ascent
= 0;
7808 row
->full_width_p
= 1;
7809 row
->continued_p
= 0;
7810 row
->truncated_on_left_p
= 0;
7811 row
->truncated_on_right_p
= 0;
7813 it
->current_x
= it
->hpos
= 0;
7814 it
->current_y
+= row
->height
;
7820 /* Value is the number of screen lines needed to make all tool-bar
7821 items of frame F visible. */
7824 tool_bar_lines_needed (f
)
7827 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7830 /* Initialize an iterator for iteration over
7831 F->desired_tool_bar_string in the tool-bar window of frame F. */
7832 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7833 it
.first_visible_x
= 0;
7834 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7835 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7837 while (!ITERATOR_AT_END_P (&it
))
7839 it
.glyph_row
= w
->desired_matrix
->rows
;
7840 clear_glyph_row (it
.glyph_row
);
7841 display_tool_bar_line (&it
);
7844 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7848 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7850 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7859 frame
= selected_frame
;
7861 CHECK_FRAME (frame
);
7864 if (WINDOWP (f
->tool_bar_window
)
7865 || (w
= XWINDOW (f
->tool_bar_window
),
7866 XFASTINT (w
->height
) > 0))
7868 update_tool_bar (f
, 1);
7869 if (f
->n_tool_bar_items
)
7871 build_desired_tool_bar_string (f
);
7872 nlines
= tool_bar_lines_needed (f
);
7876 return make_number (nlines
);
7880 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7881 height should be changed. */
7884 redisplay_tool_bar (f
)
7889 struct glyph_row
*row
;
7890 int change_height_p
= 0;
7892 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7893 do anything. This means you must start with tool-bar-lines
7894 non-zero to get the auto-sizing effect. Or in other words, you
7895 can turn off tool-bars by specifying tool-bar-lines zero. */
7896 if (!WINDOWP (f
->tool_bar_window
)
7897 || (w
= XWINDOW (f
->tool_bar_window
),
7898 XFASTINT (w
->height
) == 0))
7901 /* Set up an iterator for the tool-bar window. */
7902 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7903 it
.first_visible_x
= 0;
7904 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7907 /* Build a string that represents the contents of the tool-bar. */
7908 build_desired_tool_bar_string (f
);
7909 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7911 /* Display as many lines as needed to display all tool-bar items. */
7912 while (it
.current_y
< it
.last_visible_y
)
7913 display_tool_bar_line (&it
);
7915 /* It doesn't make much sense to try scrolling in the tool-bar
7916 window, so don't do it. */
7917 w
->desired_matrix
->no_scrolling_p
= 1;
7918 w
->must_be_updated_p
= 1;
7920 if (auto_resize_tool_bars_p
)
7924 /* If we couldn't display everything, change the tool-bar's
7926 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
7927 change_height_p
= 1;
7929 /* If there are blank lines at the end, except for a partially
7930 visible blank line at the end that is smaller than
7931 CANON_Y_UNIT, change the tool-bar's height. */
7932 row
= it
.glyph_row
- 1;
7933 if (!row
->displays_text_p
7934 && row
->height
>= CANON_Y_UNIT (f
))
7935 change_height_p
= 1;
7937 /* If row displays tool-bar items, but is partially visible,
7938 change the tool-bar's height. */
7939 if (row
->displays_text_p
7940 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7941 change_height_p
= 1;
7943 /* Resize windows as needed by changing the `tool-bar-lines'
7946 && (nlines
= tool_bar_lines_needed (f
),
7947 nlines
!= XFASTINT (w
->height
)))
7949 extern Lisp_Object Qtool_bar_lines
;
7951 int old_height
= XFASTINT (w
->height
);
7953 XSETFRAME (frame
, f
);
7954 clear_glyph_matrix (w
->desired_matrix
);
7955 Fmodify_frame_parameters (frame
,
7956 Fcons (Fcons (Qtool_bar_lines
,
7957 make_number (nlines
)),
7959 if (XFASTINT (w
->height
) != old_height
)
7960 fonts_changed_p
= 1;
7964 return change_height_p
;
7968 /* Get information about the tool-bar item which is displayed in GLYPH
7969 on frame F. Return in *PROP_IDX the index where tool-bar item
7970 properties start in F->tool_bar_items. Value is zero if
7971 GLYPH doesn't display a tool-bar item. */
7974 tool_bar_item_info (f
, glyph
, prop_idx
)
7976 struct glyph
*glyph
;
7983 /* This function can be called asynchronously, which means we must
7984 exclude any possibility that Fget_text_property signals an
7986 charpos
= min (XSTRING (f
->current_tool_bar_string
)->size
, glyph
->charpos
);
7987 charpos
= max (0, charpos
);
7989 /* Get the text property `menu-item' at pos. The value of that
7990 property is the start index of this item's properties in
7991 F->tool_bar_items. */
7992 prop
= Fget_text_property (make_number (charpos
),
7993 Qmenu_item
, f
->current_tool_bar_string
);
7994 if (INTEGERP (prop
))
7996 *prop_idx
= XINT (prop
);
8005 #endif /* HAVE_WINDOW_SYSTEM */
8009 /************************************************************************
8010 Horizontal scrolling
8011 ************************************************************************/
8013 static int hscroll_window_tree
P_ ((Lisp_Object
));
8014 static int hscroll_windows
P_ ((Lisp_Object
));
8016 /* For all leaf windows in the window tree rooted at WINDOW, set their
8017 hscroll value so that PT is (i) visible in the window, and (ii) so
8018 that it is not within a certain margin at the window's left and
8019 right border. Value is non-zero if any window's hscroll has been
8023 hscroll_window_tree (window
)
8026 int hscrolled_p
= 0;
8027 int hscroll_relative_p
= FLOATP (Vautomatic_hscroll_step
);
8028 int hscroll_step_abs
= 0;
8029 double hscroll_step_rel
= 0;
8031 if (hscroll_relative_p
)
8033 hscroll_step_rel
= XFLOAT_DATA (Vautomatic_hscroll_step
);
8034 if (hscroll_step_rel
< 0)
8036 hscroll_relative_p
= 0;
8037 hscroll_step_abs
= 0;
8040 else if (INTEGERP (Vautomatic_hscroll_step
))
8042 hscroll_step_abs
= XINT (Vautomatic_hscroll_step
);
8043 if (hscroll_step_abs
< 0)
8044 hscroll_step_abs
= 0;
8047 hscroll_step_abs
= 0;
8049 while (WINDOWP (window
))
8051 struct window
*w
= XWINDOW (window
);
8053 if (WINDOWP (w
->hchild
))
8054 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8055 else if (WINDOWP (w
->vchild
))
8056 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8057 else if (w
->cursor
.vpos
>= 0)
8059 int hscroll_margin
, text_area_x
, text_area_y
;
8060 int text_area_width
, text_area_height
;
8061 struct glyph_row
*current_cursor_row
8062 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8063 struct glyph_row
*desired_cursor_row
8064 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8065 struct glyph_row
*cursor_row
8066 = (desired_cursor_row
->enabled_p
8067 ? desired_cursor_row
8068 : current_cursor_row
);
8070 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8071 &text_area_width
, &text_area_height
);
8073 /* Scroll when cursor is inside this scroll margin. */
8075 = automatic_hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8077 if ((XFASTINT (w
->hscroll
)
8078 && w
->cursor
.x
<= hscroll_margin
)
8079 || (cursor_row
->enabled_p
8080 && cursor_row
->truncated_on_right_p
8081 && (w
->cursor
.x
>= text_area_width
- hscroll_margin
)))
8085 struct buffer
*saved_current_buffer
;
8089 /* Find point in a display of infinite width. */
8090 saved_current_buffer
= current_buffer
;
8091 current_buffer
= XBUFFER (w
->buffer
);
8093 if (w
== XWINDOW (selected_window
))
8094 pt
= BUF_PT (current_buffer
);
8097 pt
= marker_position (w
->pointm
);
8098 pt
= max (BEGV
, pt
);
8102 /* Move iterator to pt starting at cursor_row->start in
8103 a line with infinite width. */
8104 init_to_row_start (&it
, w
, cursor_row
);
8105 it
.last_visible_x
= INFINITY
;
8106 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8107 current_buffer
= saved_current_buffer
;
8109 /* Position cursor in window. */
8110 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8111 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8112 / CANON_X_UNIT (it
.f
);
8113 else if (w
->cursor
.x
>= text_area_width
- hscroll_margin
)
8115 if (hscroll_relative_p
)
8116 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8119 wanted_x
= text_area_width
8120 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8123 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8127 if (hscroll_relative_p
)
8128 wanted_x
= text_area_width
* hscroll_step_rel
8131 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8134 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8136 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8138 /* Don't call Fset_window_hscroll if value hasn't
8139 changed because it will prevent redisplay
8141 if (XFASTINT (w
->hscroll
) != hscroll
)
8143 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8144 w
->hscroll
= make_number (hscroll
);
8153 /* Value is non-zero if hscroll of any leaf window has been changed. */
8158 /* Set hscroll so that cursor is visible and not inside horizontal
8159 scroll margins for all windows in the tree rooted at WINDOW. See
8160 also hscroll_window_tree above. Value is non-zero if any window's
8161 hscroll has been changed. If it has, desired matrices on the frame
8162 of WINDOW are cleared. */
8165 hscroll_windows (window
)
8170 if (automatic_hscrolling_p
)
8172 hscrolled_p
= hscroll_window_tree (window
);
8174 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8183 /************************************************************************
8185 ************************************************************************/
8187 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8188 to a non-zero value. This is sometimes handy to have in a debugger
8193 /* First and last unchanged row for try_window_id. */
8195 int debug_first_unchanged_at_end_vpos
;
8196 int debug_last_unchanged_at_beg_vpos
;
8198 /* Delta vpos and y. */
8200 int debug_dvpos
, debug_dy
;
8202 /* Delta in characters and bytes for try_window_id. */
8204 int debug_delta
, debug_delta_bytes
;
8206 /* Values of window_end_pos and window_end_vpos at the end of
8209 int debug_end_pos
, debug_end_vpos
;
8211 /* Append a string to W->desired_matrix->method. FMT is a printf
8212 format string. A1...A9 are a supplement for a variable-length
8213 argument list. If trace_redisplay_p is non-zero also printf the
8214 resulting string to stderr. */
8217 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8220 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8223 char *method
= w
->desired_matrix
->method
;
8224 int len
= strlen (method
);
8225 int size
= sizeof w
->desired_matrix
->method
;
8226 int remaining
= size
- len
- 1;
8228 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8229 if (len
&& remaining
)
8235 strncpy (method
+ len
, buffer
, remaining
);
8237 if (trace_redisplay_p
)
8238 fprintf (stderr
, "%p (%s): %s\n",
8240 ((BUFFERP (w
->buffer
)
8241 && STRINGP (XBUFFER (w
->buffer
)->name
))
8242 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
8247 #endif /* GLYPH_DEBUG */
8250 /* This counter is used to clear the face cache every once in a while
8251 in redisplay_internal. It is incremented for each redisplay.
8252 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
8255 #define CLEAR_FACE_CACHE_COUNT 500
8256 static int clear_face_cache_count
;
8258 /* Record the previous terminal frame we displayed. */
8260 static struct frame
*previous_terminal_frame
;
8262 /* Non-zero while redisplay_internal is in progress. */
8267 /* Value is non-zero if all changes in window W, which displays
8268 current_buffer, are in the text between START and END. START is a
8269 buffer position, END is given as a distance from Z. Used in
8270 redisplay_internal for display optimization. */
8273 text_outside_line_unchanged_p (w
, start
, end
)
8277 int unchanged_p
= 1;
8279 /* If text or overlays have changed, see where. */
8280 if (XFASTINT (w
->last_modified
) < MODIFF
8281 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8283 /* Gap in the line? */
8284 if (GPT
< start
|| Z
- GPT
< end
)
8287 /* Changes start in front of the line, or end after it? */
8289 && (BEG_UNCHANGED
< start
- 1
8290 || END_UNCHANGED
< end
))
8293 /* If selective display, can't optimize if changes start at the
8294 beginning of the line. */
8296 && INTEGERP (current_buffer
->selective_display
)
8297 && XINT (current_buffer
->selective_display
) > 0
8298 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8301 /* If there are overlays at the start or end of the line, these
8302 may have overlay strings with newlines in them. A change at
8303 START, for instance, may actually concern the display of such
8304 overlay strings as well, and they are displayed on different
8305 lines. So, quickly rule out this case. (For the future, it
8306 might be desirable to implement something more telling than
8307 just BEG/END_UNCHANGED.) */
8310 if (BEG
+ BEG_UNCHANGED
== start
8311 && overlay_touches_p (start
))
8313 if (END_UNCHANGED
== end
8314 && overlay_touches_p (Z
- end
))
8323 /* Do a frame update, taking possible shortcuts into account. This is
8324 the main external entry point for redisplay.
8326 If the last redisplay displayed an echo area message and that message
8327 is no longer requested, we clear the echo area or bring back the
8328 mini-buffer if that is in use. */
8333 redisplay_internal (0);
8337 /* Return 1 if point moved out of or into a composition. Otherwise
8338 return 0. PREV_BUF and PREV_PT are the last point buffer and
8339 position. BUF and PT are the current point buffer and position. */
8342 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8343 struct buffer
*prev_buf
, *buf
;
8350 XSETBUFFER (buffer
, buf
);
8351 /* Check a composition at the last point if point moved within the
8353 if (prev_buf
== buf
)
8356 /* Point didn't move. */
8359 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8360 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8361 && COMPOSITION_VALID_P (start
, end
, prop
)
8362 && start
< prev_pt
&& end
> prev_pt
)
8363 /* The last point was within the composition. Return 1 iff
8364 point moved out of the composition. */
8365 return (pt
<= start
|| pt
>= end
);
8368 /* Check a composition at the current point. */
8369 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8370 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8371 && COMPOSITION_VALID_P (start
, end
, prop
)
8372 && start
< pt
&& end
> pt
);
8376 /* Reconsider the setting of B->clip_changed which is displayed
8380 reconsider_clip_changes (w
, b
)
8384 if (b
->prevent_redisplay_optimizations_p
)
8385 b
->clip_changed
= 1;
8386 else if (b
->clip_changed
8387 && !NILP (w
->window_end_valid
)
8388 && w
->current_matrix
->buffer
== b
8389 && w
->current_matrix
->zv
== BUF_ZV (b
)
8390 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8391 b
->clip_changed
= 0;
8393 /* If display wasn't paused, and W is not a tool bar window, see if
8394 point has been moved into or out of a composition. In that case,
8395 we set b->clip_changed to 1 to force updating the screen. If
8396 b->clip_changed has already been set to 1, we can skip this
8398 if (!b
->clip_changed
8399 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8403 if (w
== XWINDOW (selected_window
))
8404 pt
= BUF_PT (current_buffer
);
8406 pt
= marker_position (w
->pointm
);
8408 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8409 || pt
!= XINT (w
->last_point
))
8410 && check_point_in_composition (w
->current_matrix
->buffer
,
8411 XINT (w
->last_point
),
8412 XBUFFER (w
->buffer
), pt
))
8413 b
->clip_changed
= 1;
8418 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8419 response to any user action; therefore, we should preserve the echo
8420 area. (Actually, our caller does that job.) Perhaps in the future
8421 avoid recentering windows if it is not necessary; currently that
8422 causes some problems. */
8425 redisplay_internal (preserve_echo_area
)
8426 int preserve_echo_area
;
8428 struct window
*w
= XWINDOW (selected_window
);
8429 struct frame
*f
= XFRAME (w
->frame
);
8431 int must_finish
= 0;
8432 struct text_pos tlbufpos
, tlendpos
;
8433 int number_of_visible_frames
;
8435 struct frame
*sf
= SELECTED_FRAME ();
8437 /* Non-zero means redisplay has to consider all windows on all
8438 frames. Zero means, only selected_window is considered. */
8439 int consider_all_windows_p
;
8441 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8443 /* No redisplay if running in batch mode or frame is not yet fully
8444 initialized, or redisplay is explicitly turned off by setting
8445 Vinhibit_redisplay. */
8447 || !NILP (Vinhibit_redisplay
)
8448 || !f
->glyphs_initialized_p
)
8451 /* The flag redisplay_performed_directly_p is set by
8452 direct_output_for_insert when it already did the whole screen
8453 update necessary. */
8454 if (redisplay_performed_directly_p
)
8456 redisplay_performed_directly_p
= 0;
8457 if (!hscroll_windows (selected_window
))
8461 #ifdef USE_X_TOOLKIT
8462 if (popup_activated ())
8466 /* I don't think this happens but let's be paranoid. */
8470 /* Record a function that resets redisplaying_p to its old value
8471 when we leave this function. */
8472 count
= BINDING_STACK_SIZE ();
8473 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8478 reconsider_clip_changes (w
, current_buffer
);
8480 /* If new fonts have been loaded that make a glyph matrix adjustment
8481 necessary, do it. */
8482 if (fonts_changed_p
)
8484 adjust_glyphs (NULL
);
8485 ++windows_or_buffers_changed
;
8486 fonts_changed_p
= 0;
8489 /* If face_change_count is non-zero, init_iterator will free all
8490 realized faces, which includes the faces referenced from current
8491 matrices. So, we can't reuse current matrices in this case. */
8492 if (face_change_count
)
8493 ++windows_or_buffers_changed
;
8495 if (! FRAME_WINDOW_P (sf
)
8496 && previous_terminal_frame
!= sf
)
8498 /* Since frames on an ASCII terminal share the same display
8499 area, displaying a different frame means redisplay the whole
8501 windows_or_buffers_changed
++;
8502 SET_FRAME_GARBAGED (sf
);
8503 XSETFRAME (Vterminal_frame
, sf
);
8505 previous_terminal_frame
= sf
;
8507 /* Set the visible flags for all frames. Do this before checking
8508 for resized or garbaged frames; they want to know if their frames
8509 are visible. See the comment in frame.h for
8510 FRAME_SAMPLE_VISIBILITY. */
8512 Lisp_Object tail
, frame
;
8514 number_of_visible_frames
= 0;
8516 FOR_EACH_FRAME (tail
, frame
)
8518 struct frame
*f
= XFRAME (frame
);
8520 FRAME_SAMPLE_VISIBILITY (f
);
8521 if (FRAME_VISIBLE_P (f
))
8522 ++number_of_visible_frames
;
8523 clear_desired_matrices (f
);
8527 /* Notice any pending interrupt request to change frame size. */
8528 do_pending_window_change (1);
8530 /* Clear frames marked as garbaged. */
8532 clear_garbaged_frames ();
8534 /* Build menubar and tool-bar items. */
8535 prepare_menu_bars ();
8537 if (windows_or_buffers_changed
)
8538 update_mode_lines
++;
8540 /* Detect case that we need to write or remove a star in the mode line. */
8541 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8543 w
->update_mode_line
= Qt
;
8544 if (buffer_shared
> 1)
8545 update_mode_lines
++;
8548 /* If %c is in the mode line, update it if needed. */
8549 if (!NILP (w
->column_number_displayed
)
8550 /* This alternative quickly identifies a common case
8551 where no change is needed. */
8552 && !(PT
== XFASTINT (w
->last_point
)
8553 && XFASTINT (w
->last_modified
) >= MODIFF
8554 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8555 && XFASTINT (w
->column_number_displayed
) != current_column ())
8556 w
->update_mode_line
= Qt
;
8558 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8560 /* The variable buffer_shared is set in redisplay_window and
8561 indicates that we redisplay a buffer in different windows. See
8563 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
8565 /* If specs for an arrow have changed, do thorough redisplay
8566 to ensure we remove any arrow that should no longer exist. */
8567 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8568 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8569 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8571 /* Normally the message* functions will have already displayed and
8572 updated the echo area, but the frame may have been trashed, or
8573 the update may have been preempted, so display the echo area
8574 again here. Checking message_cleared_p captures the case that
8575 the echo area should be cleared. */
8576 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8577 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8578 || (message_cleared_p
8579 && minibuf_level
== 0
8580 /* If the mini-window is currently selected, this means the
8581 echo-area doesn't show through. */
8582 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8584 int window_height_changed_p
= echo_area_display (0);
8587 /* If we don't display the current message, don't clear the
8588 message_cleared_p flag, because, if we did, we wouldn't clear
8589 the echo area in the next redisplay which doesn't preserve
8591 if (!display_last_displayed_message_p
)
8592 message_cleared_p
= 0;
8594 if (fonts_changed_p
)
8596 else if (window_height_changed_p
)
8598 consider_all_windows_p
= 1;
8599 ++update_mode_lines
;
8600 ++windows_or_buffers_changed
;
8602 /* If window configuration was changed, frames may have been
8603 marked garbaged. Clear them or we will experience
8604 surprises wrt scrolling. */
8606 clear_garbaged_frames ();
8609 else if (EQ (selected_window
, minibuf_window
)
8610 && (current_buffer
->clip_changed
8611 || XFASTINT (w
->last_modified
) < MODIFF
8612 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8613 && resize_mini_window (w
, 0))
8615 /* Resized active mini-window to fit the size of what it is
8616 showing if its contents might have changed. */
8618 consider_all_windows_p
= 1;
8619 ++windows_or_buffers_changed
;
8620 ++update_mode_lines
;
8622 /* If window configuration was changed, frames may have been
8623 marked garbaged. Clear them or we will experience
8624 surprises wrt scrolling. */
8626 clear_garbaged_frames ();
8630 /* If showing the region, and mark has changed, we must redisplay
8631 the whole window. The assignment to this_line_start_pos prevents
8632 the optimization directly below this if-statement. */
8633 if (((!NILP (Vtransient_mark_mode
)
8634 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8635 != !NILP (w
->region_showing
))
8636 || (!NILP (w
->region_showing
)
8637 && !EQ (w
->region_showing
,
8638 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8639 CHARPOS (this_line_start_pos
) = 0;
8641 /* Optimize the case that only the line containing the cursor in the
8642 selected window has changed. Variables starting with this_ are
8643 set in display_line and record information about the line
8644 containing the cursor. */
8645 tlbufpos
= this_line_start_pos
;
8646 tlendpos
= this_line_end_pos
;
8647 if (!consider_all_windows_p
8648 && CHARPOS (tlbufpos
) > 0
8649 && NILP (w
->update_mode_line
)
8650 && !current_buffer
->clip_changed
8651 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8652 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8653 /* Make sure recorded data applies to current buffer, etc. */
8654 && this_line_buffer
== current_buffer
8655 && current_buffer
== XBUFFER (w
->buffer
)
8656 && NILP (w
->force_start
)
8657 /* Point must be on the line that we have info recorded about. */
8658 && PT
>= CHARPOS (tlbufpos
)
8659 && PT
<= Z
- CHARPOS (tlendpos
)
8660 /* All text outside that line, including its final newline,
8661 must be unchanged */
8662 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8663 CHARPOS (tlendpos
)))
8665 if (CHARPOS (tlbufpos
) > BEGV
8666 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8667 && (CHARPOS (tlbufpos
) == ZV
8668 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8669 /* Former continuation line has disappeared by becoming empty */
8671 else if (XFASTINT (w
->last_modified
) < MODIFF
8672 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8673 || MINI_WINDOW_P (w
))
8675 /* We have to handle the case of continuation around a
8676 wide-column character (See the comment in indent.c around
8679 For instance, in the following case:
8681 -------- Insert --------
8682 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8683 J_I_ ==> J_I_ `^^' are cursors.
8687 As we have to redraw the line above, we should goto cancel. */
8690 int line_height_before
= this_line_pixel_height
;
8692 /* Note that start_display will handle the case that the
8693 line starting at tlbufpos is a continuation lines. */
8694 start_display (&it
, w
, tlbufpos
);
8696 /* Implementation note: It this still necessary? */
8697 if (it
.current_x
!= this_line_start_x
)
8700 TRACE ((stderr
, "trying display optimization 1\n"));
8701 w
->cursor
.vpos
= -1;
8702 overlay_arrow_seen
= 0;
8703 it
.vpos
= this_line_vpos
;
8704 it
.current_y
= this_line_y
;
8705 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8708 /* If line contains point, is not continued,
8709 and ends at same distance from eob as before, we win */
8710 if (w
->cursor
.vpos
>= 0
8711 /* Line is not continued, otherwise this_line_start_pos
8712 would have been set to 0 in display_line. */
8713 && CHARPOS (this_line_start_pos
)
8714 /* Line ends as before. */
8715 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8716 /* Line has same height as before. Otherwise other lines
8717 would have to be shifted up or down. */
8718 && this_line_pixel_height
== line_height_before
)
8720 /* If this is not the window's last line, we must adjust
8721 the charstarts of the lines below. */
8722 if (it
.current_y
< it
.last_visible_y
)
8724 struct glyph_row
*row
8725 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8726 int delta
, delta_bytes
;
8728 if (Z
- CHARPOS (tlendpos
) == ZV
)
8730 /* This line ends at end of (accessible part of)
8731 buffer. There is no newline to count. */
8733 - CHARPOS (tlendpos
)
8734 - MATRIX_ROW_START_CHARPOS (row
));
8735 delta_bytes
= (Z_BYTE
8736 - BYTEPOS (tlendpos
)
8737 - MATRIX_ROW_START_BYTEPOS (row
));
8741 /* This line ends in a newline. Must take
8742 account of the newline and the rest of the
8743 text that follows. */
8745 - CHARPOS (tlendpos
)
8746 - MATRIX_ROW_START_CHARPOS (row
));
8747 delta_bytes
= (Z_BYTE
8748 - BYTEPOS (tlendpos
)
8749 - MATRIX_ROW_START_BYTEPOS (row
));
8752 increment_matrix_positions (w
->current_matrix
,
8754 w
->current_matrix
->nrows
,
8755 delta
, delta_bytes
);
8758 /* If this row displays text now but previously didn't,
8759 or vice versa, w->window_end_vpos may have to be
8761 if ((it
.glyph_row
- 1)->displays_text_p
)
8763 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8764 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8766 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8767 && this_line_vpos
> 0)
8768 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8769 w
->window_end_valid
= Qnil
;
8771 /* Update hint: No need to try to scroll in update_window. */
8772 w
->desired_matrix
->no_scrolling_p
= 1;
8775 *w
->desired_matrix
->method
= 0;
8776 debug_method_add (w
, "optimization 1");
8783 else if (/* Cursor position hasn't changed. */
8784 PT
== XFASTINT (w
->last_point
)
8785 /* Make sure the cursor was last displayed
8786 in this window. Otherwise we have to reposition it. */
8787 && 0 <= w
->cursor
.vpos
8788 && XINT (w
->height
) > w
->cursor
.vpos
)
8792 do_pending_window_change (1);
8794 /* We used to always goto end_of_redisplay here, but this
8795 isn't enough if we have a blinking cursor. */
8796 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8797 goto end_of_redisplay
;
8801 /* If highlighting the region, or if the cursor is in the echo area,
8802 then we can't just move the cursor. */
8803 else if (! (!NILP (Vtransient_mark_mode
)
8804 && !NILP (current_buffer
->mark_active
))
8805 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8806 || highlight_nonselected_windows
)
8807 && NILP (w
->region_showing
)
8808 && NILP (Vshow_trailing_whitespace
)
8809 && !cursor_in_echo_area
)
8812 struct glyph_row
*row
;
8814 /* Skip from tlbufpos to PT and see where it is. Note that
8815 PT may be in invisible text. If so, we will end at the
8816 next visible position. */
8817 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8818 NULL
, DEFAULT_FACE_ID
);
8819 it
.current_x
= this_line_start_x
;
8820 it
.current_y
= this_line_y
;
8821 it
.vpos
= this_line_vpos
;
8823 /* The call to move_it_to stops in front of PT, but
8824 moves over before-strings. */
8825 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8827 if (it
.vpos
== this_line_vpos
8828 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8831 xassert (this_line_vpos
== it
.vpos
);
8832 xassert (this_line_y
== it
.current_y
);
8833 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8835 *w
->desired_matrix
->method
= 0;
8836 debug_method_add (w
, "optimization 3");
8845 /* Text changed drastically or point moved off of line. */
8846 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8849 CHARPOS (this_line_start_pos
) = 0;
8850 consider_all_windows_p
|= buffer_shared
> 1;
8851 ++clear_face_cache_count
;
8854 /* Build desired matrices, and update the display. If
8855 consider_all_windows_p is non-zero, do it for all windows on all
8856 frames. Otherwise do it for selected_window, only. */
8858 if (consider_all_windows_p
)
8860 Lisp_Object tail
, frame
;
8861 int i
, n
= 0, size
= 50;
8862 struct frame
**updated
8863 = (struct frame
**) alloca (size
* sizeof *updated
);
8865 /* Clear the face cache eventually. */
8866 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8868 clear_face_cache (0);
8869 clear_face_cache_count
= 0;
8872 /* Recompute # windows showing selected buffer. This will be
8873 incremented each time such a window is displayed. */
8876 FOR_EACH_FRAME (tail
, frame
)
8878 struct frame
*f
= XFRAME (frame
);
8880 if (FRAME_WINDOW_P (f
) || f
== sf
)
8882 if (clear_face_cache_count
% 50 == 0
8883 && FRAME_WINDOW_P (f
))
8884 clear_image_cache (f
, 0);
8886 /* Mark all the scroll bars to be removed; we'll redeem
8887 the ones we want when we redisplay their windows. */
8888 if (condemn_scroll_bars_hook
)
8889 condemn_scroll_bars_hook (f
);
8891 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8892 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8894 /* Any scroll bars which redisplay_windows should have
8895 nuked should now go away. */
8896 if (judge_scroll_bars_hook
)
8897 judge_scroll_bars_hook (f
);
8899 /* If fonts changed, display again. */
8900 if (fonts_changed_p
)
8903 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8905 /* See if we have to hscroll. */
8906 if (hscroll_windows (f
->root_window
))
8909 /* Prevent various kinds of signals during display
8910 update. stdio is not robust about handling
8911 signals, which can cause an apparent I/O
8913 if (interrupt_input
)
8917 /* Update the display. */
8918 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8919 pause
|= update_frame (f
, 0, 0);
8925 int nbytes
= size
* sizeof *updated
;
8926 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
8927 bcopy (updated
, p
, nbytes
);
8936 /* Do the mark_window_display_accurate after all windows have
8937 been redisplayed because this call resets flags in buffers
8938 which are needed for proper redisplay. */
8939 for (i
= 0; i
< n
; ++i
)
8941 struct frame
*f
= updated
[i
];
8942 mark_window_display_accurate (f
->root_window
, 1);
8943 if (frame_up_to_date_hook
)
8944 frame_up_to_date_hook (f
);
8947 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8949 Lisp_Object mini_window
;
8950 struct frame
*mini_frame
;
8952 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8953 internal_condition_case_1 (redisplay_window_1
, selected_window
, Qerror
,
8954 redisplay_window_error
);
8956 /* Compare desired and current matrices, perform output. */
8959 /* If fonts changed, display again. */
8960 if (fonts_changed_p
)
8963 /* Prevent various kinds of signals during display update.
8964 stdio is not robust about handling signals,
8965 which can cause an apparent I/O error. */
8966 if (interrupt_input
)
8970 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8972 if (hscroll_windows (selected_window
))
8975 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8976 pause
= update_frame (sf
, 0, 0);
8979 /* We may have called echo_area_display at the top of this
8980 function. If the echo area is on another frame, that may
8981 have put text on a frame other than the selected one, so the
8982 above call to update_frame would not have caught it. Catch
8984 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8985 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8987 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8989 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8990 pause
|= update_frame (mini_frame
, 0, 0);
8991 if (!pause
&& hscroll_windows (mini_window
))
8996 /* If display was paused because of pending input, make sure we do a
8997 thorough update the next time. */
9000 /* Prevent the optimization at the beginning of
9001 redisplay_internal that tries a single-line update of the
9002 line containing the cursor in the selected window. */
9003 CHARPOS (this_line_start_pos
) = 0;
9005 /* Let the overlay arrow be updated the next time. */
9006 if (!NILP (last_arrow_position
))
9008 last_arrow_position
= Qt
;
9009 last_arrow_string
= Qt
;
9012 /* If we pause after scrolling, some rows in the current
9013 matrices of some windows are not valid. */
9014 if (!WINDOW_FULL_WIDTH_P (w
)
9015 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9016 update_mode_lines
= 1;
9020 if (!consider_all_windows_p
)
9022 /* This has already been done above if
9023 consider_all_windows_p is set. */
9024 mark_window_display_accurate_1 (w
, 1);
9026 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9027 last_arrow_string
= Voverlay_arrow_string
;
9029 if (frame_up_to_date_hook
!= 0)
9030 frame_up_to_date_hook (sf
);
9033 update_mode_lines
= 0;
9034 windows_or_buffers_changed
= 0;
9037 /* Start SIGIO interrupts coming again. Having them off during the
9038 code above makes it less likely one will discard output, but not
9039 impossible, since there might be stuff in the system buffer here.
9040 But it is much hairier to try to do anything about that. */
9041 if (interrupt_input
)
9045 /* If a frame has become visible which was not before, redisplay
9046 again, so that we display it. Expose events for such a frame
9047 (which it gets when becoming visible) don't call the parts of
9048 redisplay constructing glyphs, so simply exposing a frame won't
9049 display anything in this case. So, we have to display these
9050 frames here explicitly. */
9053 Lisp_Object tail
, frame
;
9056 FOR_EACH_FRAME (tail
, frame
)
9058 int this_is_visible
= 0;
9060 if (XFRAME (frame
)->visible
)
9061 this_is_visible
= 1;
9062 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9063 if (XFRAME (frame
)->visible
)
9064 this_is_visible
= 1;
9066 if (this_is_visible
)
9070 if (new_count
!= number_of_visible_frames
)
9071 windows_or_buffers_changed
++;
9074 /* Change frame size now if a change is pending. */
9075 do_pending_window_change (1);
9077 /* If we just did a pending size change, or have additional
9078 visible frames, redisplay again. */
9079 if (windows_or_buffers_changed
&& !pause
)
9084 unbind_to (count
, Qnil
);
9088 /* Redisplay, but leave alone any recent echo area message unless
9089 another message has been requested in its place.
9091 This is useful in situations where you need to redisplay but no
9092 user action has occurred, making it inappropriate for the message
9093 area to be cleared. See tracking_off and
9094 wait_reading_process_input for examples of these situations.
9096 FROM_WHERE is an integer saying from where this function was
9097 called. This is useful for debugging. */
9100 redisplay_preserve_echo_area (from_where
)
9103 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9105 if (!NILP (echo_area_buffer
[1]))
9107 /* We have a previously displayed message, but no current
9108 message. Redisplay the previous message. */
9109 display_last_displayed_message_p
= 1;
9110 redisplay_internal (1);
9111 display_last_displayed_message_p
= 0;
9114 redisplay_internal (1);
9118 /* Function registered with record_unwind_protect in
9119 redisplay_internal. Clears the flag indicating that a redisplay is
9123 unwind_redisplay (old_redisplaying_p
)
9124 Lisp_Object old_redisplaying_p
;
9126 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9131 /* Mark the display of window W as accurate or inaccurate. If
9132 ACCURATE_P is non-zero mark display of W as accurate. If
9133 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9134 redisplay_internal is called. */
9137 mark_window_display_accurate_1 (w
, accurate_p
)
9141 if (BUFFERP (w
->buffer
))
9143 struct buffer
*b
= XBUFFER (w
->buffer
);
9146 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9147 w
->last_overlay_modified
9148 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9150 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9154 b
->clip_changed
= 0;
9155 b
->prevent_redisplay_optimizations_p
= 0;
9157 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9158 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9159 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9160 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9162 w
->current_matrix
->buffer
= b
;
9163 w
->current_matrix
->begv
= BUF_BEGV (b
);
9164 w
->current_matrix
->zv
= BUF_ZV (b
);
9166 w
->last_cursor
= w
->cursor
;
9167 w
->last_cursor_off_p
= w
->cursor_off_p
;
9169 if (w
== XWINDOW (selected_window
))
9170 w
->last_point
= make_number (BUF_PT (b
));
9172 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9178 w
->window_end_valid
= w
->buffer
;
9179 #if 0 /* This is incorrect with variable-height lines. */
9180 xassert (XINT (w
->window_end_vpos
)
9182 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9184 w
->update_mode_line
= Qnil
;
9189 /* Mark the display of windows in the window tree rooted at WINDOW as
9190 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9191 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9192 be redisplayed the next time redisplay_internal is called. */
9195 mark_window_display_accurate (window
, accurate_p
)
9201 for (; !NILP (window
); window
= w
->next
)
9203 w
= XWINDOW (window
);
9204 mark_window_display_accurate_1 (w
, accurate_p
);
9206 if (!NILP (w
->vchild
))
9207 mark_window_display_accurate (w
->vchild
, accurate_p
);
9208 if (!NILP (w
->hchild
))
9209 mark_window_display_accurate (w
->hchild
, accurate_p
);
9214 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9215 last_arrow_string
= Voverlay_arrow_string
;
9219 /* Force a thorough redisplay the next time by setting
9220 last_arrow_position and last_arrow_string to t, which is
9221 unequal to any useful value of Voverlay_arrow_... */
9222 last_arrow_position
= Qt
;
9223 last_arrow_string
= Qt
;
9228 /* Return value in display table DP (Lisp_Char_Table *) for character
9229 C. Since a display table doesn't have any parent, we don't have to
9230 follow parent. Do not call this function directly but use the
9231 macro DISP_CHAR_VECTOR. */
9234 disp_char_vector (dp
, c
)
9235 struct Lisp_Char_Table
*dp
;
9241 if (SINGLE_BYTE_CHAR_P (c
))
9242 return (dp
->contents
[c
]);
9244 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9247 else if (code
[2] < 32)
9250 /* Here, the possible range of code[0] (== charset ID) is
9251 128..max_charset. Since the top level char table contains data
9252 for multibyte characters after 256th element, we must increment
9253 code[0] by 128 to get a correct index. */
9255 code
[3] = -1; /* anchor */
9257 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9259 val
= dp
->contents
[code
[i
]];
9260 if (!SUB_CHAR_TABLE_P (val
))
9261 return (NILP (val
) ? dp
->defalt
: val
);
9264 /* Here, val is a sub char table. We return the default value of
9266 return (dp
->defalt
);
9271 /***********************************************************************
9273 ***********************************************************************/
9275 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9278 redisplay_windows (window
)
9281 while (!NILP (window
))
9283 struct window
*w
= XWINDOW (window
);
9285 if (!NILP (w
->hchild
))
9286 redisplay_windows (w
->hchild
);
9287 else if (!NILP (w
->vchild
))
9288 redisplay_windows (w
->vchild
);
9291 displayed_buffer
= XBUFFER (w
->buffer
);
9292 internal_condition_case_1 (redisplay_window_0
, window
, Qerror
,
9293 redisplay_window_error
);
9301 redisplay_window_error ()
9303 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9308 redisplay_window_0 (window
)
9311 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9312 redisplay_window (window
, 0);
9317 redisplay_window_1 (window
)
9320 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9321 redisplay_window (window
, 1);
9325 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9326 DELTA is the number of bytes by which positions recorded in ROW
9327 differ from current buffer positions. */
9330 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9332 struct glyph_row
*row
;
9333 struct glyph_matrix
*matrix
;
9334 int delta
, delta_bytes
, dy
, dvpos
;
9336 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9337 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9339 int pt_old
= PT
- delta
;
9341 /* Skip over glyphs not having an object at the start of the row.
9342 These are special glyphs like truncation marks on terminal
9344 if (row
->displays_text_p
)
9346 && INTEGERP (glyph
->object
)
9347 && glyph
->charpos
< 0)
9349 x
+= glyph
->pixel_width
;
9354 && !INTEGERP (glyph
->object
)
9355 && (!BUFFERP (glyph
->object
)
9356 || glyph
->charpos
< pt_old
))
9358 x
+= glyph
->pixel_width
;
9362 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9364 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9365 w
->cursor
.y
= row
->y
+ dy
;
9367 if (w
== XWINDOW (selected_window
))
9369 if (!row
->continued_p
9370 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9373 this_line_buffer
= XBUFFER (w
->buffer
);
9375 CHARPOS (this_line_start_pos
)
9376 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9377 BYTEPOS (this_line_start_pos
)
9378 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9380 CHARPOS (this_line_end_pos
)
9381 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9382 BYTEPOS (this_line_end_pos
)
9383 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9385 this_line_y
= w
->cursor
.y
;
9386 this_line_pixel_height
= row
->height
;
9387 this_line_vpos
= w
->cursor
.vpos
;
9388 this_line_start_x
= row
->x
;
9391 CHARPOS (this_line_start_pos
) = 0;
9396 /* Run window scroll functions, if any, for WINDOW with new window
9397 start STARTP. Sets the window start of WINDOW to that position.
9399 We assume that the window's buffer is really current. */
9401 static INLINE
struct text_pos
9402 run_window_scroll_functions (window
, startp
)
9404 struct text_pos startp
;
9406 struct window
*w
= XWINDOW (window
);
9407 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9409 if (current_buffer
!= XBUFFER (w
->buffer
))
9412 if (!NILP (Vwindow_scroll_functions
))
9414 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9415 make_number (CHARPOS (startp
)));
9416 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9417 /* In case the hook functions switch buffers. */
9418 if (current_buffer
!= XBUFFER (w
->buffer
))
9419 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9426 /* Modify the desired matrix of window W and W->vscroll so that the
9427 line containing the cursor is fully visible. If this requires
9428 larger matrices than are allocated, set fonts_changed_p and return
9432 make_cursor_line_fully_visible (w
)
9435 struct glyph_matrix
*matrix
;
9436 struct glyph_row
*row
;
9439 /* It's not always possible to find the cursor, e.g, when a window
9440 is full of overlay strings. Don't do anything in that case. */
9441 if (w
->cursor
.vpos
< 0)
9444 matrix
= w
->desired_matrix
;
9445 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9447 /* If the cursor row is not partially visible, there's nothing
9449 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9452 /* If the row the cursor is in is taller than the window's height,
9453 it's not clear what to do, so do nothing. */
9454 window_height
= window_box_height (w
);
9455 if (row
->height
>= window_height
)
9458 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9460 int dy
= row
->height
- row
->visible_height
;
9463 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9465 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9467 int dy
= - (row
->height
- row
->visible_height
);
9470 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9473 /* When we change the cursor y-position of the selected window,
9474 change this_line_y as well so that the display optimization for
9475 the cursor line of the selected window in redisplay_internal uses
9476 the correct y-position. */
9477 if (w
== XWINDOW (selected_window
))
9478 this_line_y
= w
->cursor
.y
;
9480 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9481 redisplay with larger matrices. */
9482 if (matrix
->nrows
< required_matrix_height (w
))
9484 fonts_changed_p
= 1;
9492 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9493 non-zero means only WINDOW is redisplayed in redisplay_internal.
9494 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9495 in redisplay_window to bring a partially visible line into view in
9496 the case that only the cursor has moved.
9500 1 if scrolling succeeded
9502 0 if scrolling didn't find point.
9504 -1 if new fonts have been loaded so that we must interrupt
9505 redisplay, adjust glyph matrices, and try again. */
9511 SCROLLING_NEED_LARGER_MATRICES
9515 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
9516 scroll_step
, temp_scroll_step
)
9518 int just_this_one_p
;
9519 int scroll_conservatively
, scroll_step
;
9520 int temp_scroll_step
;
9522 struct window
*w
= XWINDOW (window
);
9523 struct frame
*f
= XFRAME (w
->frame
);
9524 struct text_pos scroll_margin_pos
;
9525 struct text_pos pos
;
9526 struct text_pos startp
;
9528 Lisp_Object window_end
;
9529 int this_scroll_margin
;
9533 int amount_to_scroll
= 0;
9534 Lisp_Object aggressive
;
9538 debug_method_add (w
, "try_scrolling");
9541 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9543 /* Compute scroll margin height in pixels. We scroll when point is
9544 within this distance from the top or bottom of the window. */
9545 if (scroll_margin
> 0)
9547 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
9548 this_scroll_margin
*= CANON_Y_UNIT (f
);
9551 this_scroll_margin
= 0;
9553 /* Compute how much we should try to scroll maximally to bring point
9555 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
9556 scroll_max
= max (scroll_step
,
9557 max (scroll_conservatively
, temp_scroll_step
));
9558 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
9559 || NUMBERP (current_buffer
->scroll_up_aggressively
))
9560 /* We're trying to scroll because of aggressive scrolling
9561 but no scroll_step is set. Choose an arbitrary one. Maybe
9562 there should be a variable for this. */
9566 scroll_max
*= CANON_Y_UNIT (f
);
9568 /* Decide whether we have to scroll down. Start at the window end
9569 and move this_scroll_margin up to find the position of the scroll
9571 window_end
= Fwindow_end (window
, Qt
);
9572 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
9573 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
9574 if (this_scroll_margin
)
9576 start_display (&it
, w
, scroll_margin_pos
);
9577 move_it_vertically (&it
, - this_scroll_margin
);
9578 scroll_margin_pos
= it
.current
.pos
;
9581 if (PT
>= CHARPOS (scroll_margin_pos
))
9585 /* Point is in the scroll margin at the bottom of the window, or
9586 below. Compute a new window start that makes point visible. */
9588 /* Compute the distance from the scroll margin to PT.
9589 Give up if the distance is greater than scroll_max. */
9590 start_display (&it
, w
, scroll_margin_pos
);
9592 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9593 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9595 /* To make point visible, we have to move the window start
9596 down so that the line the cursor is in is visible, which
9597 means we have to add in the height of the cursor line. */
9598 dy
= line_bottom_y (&it
) - y0
;
9600 if (dy
> scroll_max
)
9601 return SCROLLING_FAILED
;
9603 /* Move the window start down. If scrolling conservatively,
9604 move it just enough down to make point visible. If
9605 scroll_step is set, move it down by scroll_step. */
9606 start_display (&it
, w
, startp
);
9608 if (scroll_conservatively
)
9610 = max (max (dy
, CANON_Y_UNIT (f
)),
9611 CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9612 else if (scroll_step
|| temp_scroll_step
)
9613 amount_to_scroll
= scroll_max
;
9616 aggressive
= current_buffer
->scroll_up_aggressively
;
9617 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9618 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9619 if (NUMBERP (aggressive
))
9620 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9623 if (amount_to_scroll
<= 0)
9624 return SCROLLING_FAILED
;
9626 move_it_vertically (&it
, amount_to_scroll
);
9627 startp
= it
.current
.pos
;
9631 /* See if point is inside the scroll margin at the top of the
9633 scroll_margin_pos
= startp
;
9634 if (this_scroll_margin
)
9636 start_display (&it
, w
, startp
);
9637 move_it_vertically (&it
, this_scroll_margin
);
9638 scroll_margin_pos
= it
.current
.pos
;
9641 if (PT
< CHARPOS (scroll_margin_pos
))
9643 /* Point is in the scroll margin at the top of the window or
9644 above what is displayed in the window. */
9647 /* Compute the vertical distance from PT to the scroll
9648 margin position. Give up if distance is greater than
9650 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
9651 start_display (&it
, w
, pos
);
9653 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
9654 it
.last_visible_y
, -1,
9655 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9656 dy
= it
.current_y
- y0
;
9657 if (dy
> scroll_max
)
9658 return SCROLLING_FAILED
;
9660 /* Compute new window start. */
9661 start_display (&it
, w
, startp
);
9663 if (scroll_conservatively
)
9665 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9666 else if (scroll_step
|| temp_scroll_step
)
9667 amount_to_scroll
= scroll_max
;
9670 aggressive
= current_buffer
->scroll_down_aggressively
;
9671 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9672 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9673 if (NUMBERP (aggressive
))
9674 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9677 if (amount_to_scroll
<= 0)
9678 return SCROLLING_FAILED
;
9680 move_it_vertically (&it
, - amount_to_scroll
);
9681 startp
= it
.current
.pos
;
9685 /* Run window scroll functions. */
9686 startp
= run_window_scroll_functions (window
, startp
);
9688 /* Display the window. Give up if new fonts are loaded, or if point
9690 if (!try_window (window
, startp
))
9691 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9692 else if (w
->cursor
.vpos
< 0)
9694 clear_glyph_matrix (w
->desired_matrix
);
9695 rc
= SCROLLING_FAILED
;
9699 /* Maybe forget recorded base line for line number display. */
9700 if (!just_this_one_p
9701 || current_buffer
->clip_changed
9702 || BEG_UNCHANGED
< CHARPOS (startp
))
9703 w
->base_line_number
= Qnil
;
9705 /* If cursor ends up on a partially visible line, shift display
9706 lines up or down. If that fails because we need larger
9707 matrices, give up. */
9708 if (!make_cursor_line_fully_visible (w
))
9709 rc
= SCROLLING_NEED_LARGER_MATRICES
;
9711 rc
= SCROLLING_SUCCESS
;
9718 /* Compute a suitable window start for window W if display of W starts
9719 on a continuation line. Value is non-zero if a new window start
9722 The new window start will be computed, based on W's width, starting
9723 from the start of the continued line. It is the start of the
9724 screen line with the minimum distance from the old start W->start. */
9727 compute_window_start_on_continuation_line (w
)
9730 struct text_pos pos
, start_pos
;
9731 int window_start_changed_p
= 0;
9733 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9735 /* If window start is on a continuation line... Window start may be
9736 < BEGV in case there's invisible text at the start of the
9737 buffer (M-x rmail, for example). */
9738 if (CHARPOS (start_pos
) > BEGV
9739 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9742 struct glyph_row
*row
;
9744 /* Handle the case that the window start is out of range. */
9745 if (CHARPOS (start_pos
) < BEGV
)
9746 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9747 else if (CHARPOS (start_pos
) > ZV
)
9748 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9750 /* Find the start of the continued line. This should be fast
9751 because scan_buffer is fast (newline cache). */
9752 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9753 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9754 row
, DEFAULT_FACE_ID
);
9755 reseat_at_previous_visible_line_start (&it
);
9757 /* If the line start is "too far" away from the window start,
9758 say it takes too much time to compute a new window start. */
9759 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9760 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9762 int min_distance
, distance
;
9764 /* Move forward by display lines to find the new window
9765 start. If window width was enlarged, the new start can
9766 be expected to be > the old start. If window width was
9767 decreased, the new window start will be < the old start.
9768 So, we're looking for the display line start with the
9769 minimum distance from the old window start. */
9770 pos
= it
.current
.pos
;
9771 min_distance
= INFINITY
;
9772 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9773 distance
< min_distance
)
9775 min_distance
= distance
;
9776 pos
= it
.current
.pos
;
9777 move_it_by_lines (&it
, 1, 0);
9780 /* Set the window start there. */
9781 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9782 window_start_changed_p
= 1;
9786 return window_start_changed_p
;
9790 /* Try cursor movement in case text has not changes in window WINDOW,
9791 with window start STARTP. Value is
9793 CURSOR_MOVEMENT_SUCCESS if successful
9795 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
9797 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
9798 display. *SCROLL_STEP is set to 1, under certain circumstances, if
9799 we want to scroll as if scroll-step were set to 1. See the code.
9801 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
9802 which case we have to abort this redisplay, and adjust matrices
9807 CURSOR_MOVEMENT_SUCCESS
,
9808 CURSOR_MOVEMENT_CANNOT_BE_USED
,
9809 CURSOR_MOVEMENT_MUST_SCROLL
,
9810 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
9814 try_cursor_movement (window
, startp
, scroll_step
)
9816 struct text_pos startp
;
9819 struct window
*w
= XWINDOW (window
);
9820 struct frame
*f
= XFRAME (w
->frame
);
9821 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
9824 if (inhibit_try_cursor_movement
)
9828 /* Handle case where text has not changed, only point, and it has
9829 not moved off the frame. */
9830 if (/* Point may be in this window. */
9831 PT
>= CHARPOS (startp
)
9832 /* Selective display hasn't changed. */
9833 && !current_buffer
->clip_changed
9834 /* Function force-mode-line-update is used to force a thorough
9835 redisplay. It sets either windows_or_buffers_changed or
9836 update_mode_lines. So don't take a shortcut here for these
9838 && !update_mode_lines
9839 && !windows_or_buffers_changed
9840 /* Can't use this case if highlighting a region. When a
9841 region exists, cursor movement has to do more than just
9843 && !(!NILP (Vtransient_mark_mode
)
9844 && !NILP (current_buffer
->mark_active
))
9845 && NILP (w
->region_showing
)
9846 && NILP (Vshow_trailing_whitespace
)
9847 /* Right after splitting windows, last_point may be nil. */
9848 && INTEGERP (w
->last_point
)
9849 /* This code is not used for mini-buffer for the sake of the case
9850 of redisplaying to replace an echo area message; since in
9851 that case the mini-buffer contents per se are usually
9852 unchanged. This code is of no real use in the mini-buffer
9853 since the handling of this_line_start_pos, etc., in redisplay
9854 handles the same cases. */
9855 && !EQ (window
, minibuf_window
)
9856 /* When splitting windows or for new windows, it happens that
9857 redisplay is called with a nil window_end_vpos or one being
9858 larger than the window. This should really be fixed in
9859 window.c. I don't have this on my list, now, so we do
9860 approximately the same as the old redisplay code. --gerd. */
9861 && INTEGERP (w
->window_end_vpos
)
9862 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9863 && (FRAME_WINDOW_P (f
)
9864 || !MARKERP (Voverlay_arrow_position
)
9865 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9867 int this_scroll_margin
;
9868 struct glyph_row
*row
= NULL
;
9871 debug_method_add (w
, "cursor movement");
9874 /* Scroll if point within this distance from the top or bottom
9875 of the window. This is a pixel value. */
9876 this_scroll_margin
= max (0, scroll_margin
);
9877 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9878 this_scroll_margin
*= CANON_Y_UNIT (f
);
9880 /* Start with the row the cursor was displayed during the last
9881 not paused redisplay. Give up if that row is not valid. */
9882 if (w
->last_cursor
.vpos
< 0
9883 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9884 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9887 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9888 if (row
->mode_line_p
)
9890 if (!row
->enabled_p
)
9891 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9894 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
9897 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9899 if (PT
> XFASTINT (w
->last_point
))
9901 /* Point has moved forward. */
9902 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9903 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9905 xassert (row
->enabled_p
);
9909 /* The end position of a row equals the start position
9910 of the next row. If PT is there, we would rather
9911 display it in the next line. */
9912 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9913 && MATRIX_ROW_END_CHARPOS (row
) == PT
9914 && !cursor_row_p (w
, row
))
9917 /* If within the scroll margin, scroll. Note that
9918 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9919 the next line would be drawn, and that
9920 this_scroll_margin can be zero. */
9921 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9922 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9923 /* Line is completely visible last line in window
9924 and PT is to be set in the next line. */
9925 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9926 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9927 && !row
->ends_at_zv_p
9928 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9931 else if (PT
< XFASTINT (w
->last_point
))
9933 /* Cursor has to be moved backward. Note that PT >=
9934 CHARPOS (startp) because of the outer
9936 while (!row
->mode_line_p
9937 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9938 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9939 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9940 && (row
->y
> this_scroll_margin
9941 || CHARPOS (startp
) == BEGV
))
9943 xassert (row
->enabled_p
);
9947 /* Consider the following case: Window starts at BEGV,
9948 there is invisible, intangible text at BEGV, so that
9949 display starts at some point START > BEGV. It can
9950 happen that we are called with PT somewhere between
9951 BEGV and START. Try to handle that case. */
9952 if (row
< w
->current_matrix
->rows
9953 || row
->mode_line_p
)
9955 row
= w
->current_matrix
->rows
;
9956 if (row
->mode_line_p
)
9960 /* Due to newlines in overlay strings, we may have to
9961 skip forward over overlay strings. */
9962 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9963 && MATRIX_ROW_END_CHARPOS (row
) == PT
9964 && !cursor_row_p (w
, row
))
9967 /* If within the scroll margin, scroll. */
9968 if (row
->y
< this_scroll_margin
9969 && CHARPOS (startp
) != BEGV
)
9973 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9974 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9976 /* if PT is not in the glyph row, give up. */
9977 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9979 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9981 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
9982 && !row
->ends_at_zv_p
9983 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
9984 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9985 else if (row
->height
> window_box_height (w
))
9987 /* If we end up in a partially visible line, let's
9988 make it fully visible, except when it's taller
9989 than the window, in which case we can't do much
9992 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
9996 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9997 try_window (window
, startp
);
9998 if (!make_cursor_line_fully_visible (w
))
9999 rc
= CURSOR_MOVEMENT_NEED_LARGER_MATRICES
;
10001 rc
= CURSOR_MOVEMENT_SUCCESS
;
10005 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10008 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10009 rc
= CURSOR_MOVEMENT_SUCCESS
;
10018 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10019 selected_window is redisplayed. */
10022 redisplay_window (window
, just_this_one_p
)
10023 Lisp_Object window
;
10024 int just_this_one_p
;
10026 struct window
*w
= XWINDOW (window
);
10027 struct frame
*f
= XFRAME (w
->frame
);
10028 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10029 struct buffer
*old
= current_buffer
;
10030 struct text_pos lpoint
, opoint
, startp
;
10031 int update_mode_line
;
10034 /* Record it now because it's overwritten. */
10035 int current_matrix_up_to_date_p
= 0;
10036 int temp_scroll_step
= 0;
10037 int count
= BINDING_STACK_SIZE ();
10040 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10043 /* W must be a leaf window here. */
10044 xassert (!NILP (w
->buffer
));
10046 *w
->desired_matrix
->method
= 0;
10049 specbind (Qinhibit_point_motion_hooks
, Qt
);
10051 reconsider_clip_changes (w
, buffer
);
10053 /* Has the mode line to be updated? */
10054 update_mode_line
= (!NILP (w
->update_mode_line
)
10055 || update_mode_lines
10056 || buffer
->clip_changed
);
10058 if (MINI_WINDOW_P (w
))
10060 if (w
== XWINDOW (echo_area_window
)
10061 && !NILP (echo_area_buffer
[0]))
10063 if (update_mode_line
)
10064 /* We may have to update a tty frame's menu bar or a
10065 tool-bar. Example `M-x C-h C-h C-g'. */
10066 goto finish_menu_bars
;
10068 /* We've already displayed the echo area glyphs in this window. */
10069 goto finish_scroll_bars
;
10071 else if (w
!= XWINDOW (minibuf_window
))
10073 /* W is a mini-buffer window, but it's not the currently
10074 active one, so clear it. */
10075 int yb
= window_text_bottom_y (w
);
10076 struct glyph_row
*row
;
10079 for (y
= 0, row
= w
->desired_matrix
->rows
;
10081 y
+= row
->height
, ++row
)
10082 blank_row (w
, row
, y
);
10083 goto finish_scroll_bars
;
10086 clear_glyph_matrix (w
->desired_matrix
);
10089 /* Otherwise set up data on this window; select its buffer and point
10091 /* Really select the buffer, for the sake of buffer-local
10093 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10094 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10096 current_matrix_up_to_date_p
10097 = (!NILP (w
->window_end_valid
)
10098 && !current_buffer
->clip_changed
10099 && XFASTINT (w
->last_modified
) >= MODIFF
10100 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10102 /* When windows_or_buffers_changed is non-zero, we can't rely on
10103 the window end being valid, so set it to nil there. */
10104 if (windows_or_buffers_changed
)
10106 /* If window starts on a continuation line, maybe adjust the
10107 window start in case the window's width changed. */
10108 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10109 compute_window_start_on_continuation_line (w
);
10111 w
->window_end_valid
= Qnil
;
10114 /* Some sanity checks. */
10115 CHECK_WINDOW_END (w
);
10116 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10118 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10121 /* If %c is in mode line, update it if needed. */
10122 if (!NILP (w
->column_number_displayed
)
10123 /* This alternative quickly identifies a common case
10124 where no change is needed. */
10125 && !(PT
== XFASTINT (w
->last_point
)
10126 && XFASTINT (w
->last_modified
) >= MODIFF
10127 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10128 && XFASTINT (w
->column_number_displayed
) != current_column ())
10129 update_mode_line
= 1;
10131 /* Count number of windows showing the selected buffer. An indirect
10132 buffer counts as its base buffer. */
10133 if (!just_this_one_p
)
10135 struct buffer
*current_base
, *window_base
;
10136 current_base
= current_buffer
;
10137 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10138 if (current_base
->base_buffer
)
10139 current_base
= current_base
->base_buffer
;
10140 if (window_base
->base_buffer
)
10141 window_base
= window_base
->base_buffer
;
10142 if (current_base
== window_base
)
10146 /* Point refers normally to the selected window. For any other
10147 window, set up appropriate value. */
10148 if (!EQ (window
, selected_window
))
10150 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10151 int new_pt_byte
= marker_byte_position (w
->pointm
);
10155 new_pt_byte
= BEGV_BYTE
;
10156 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10158 else if (new_pt
> (ZV
- 1))
10161 new_pt_byte
= ZV_BYTE
;
10162 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10165 /* We don't use SET_PT so that the point-motion hooks don't run. */
10166 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10169 /* If any of the character widths specified in the display table
10170 have changed, invalidate the width run cache. It's true that
10171 this may be a bit late to catch such changes, but the rest of
10172 redisplay goes (non-fatally) haywire when the display table is
10173 changed, so why should we worry about doing any better? */
10174 if (current_buffer
->width_run_cache
)
10176 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10178 if (! disptab_matches_widthtab (disptab
,
10179 XVECTOR (current_buffer
->width_table
)))
10181 invalidate_region_cache (current_buffer
,
10182 current_buffer
->width_run_cache
,
10184 recompute_width_table (current_buffer
, disptab
);
10188 /* If window-start is screwed up, choose a new one. */
10189 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10192 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10194 /* If someone specified a new starting point but did not insist,
10195 check whether it can be used. */
10196 if (!NILP (w
->optional_new_start
)
10197 && CHARPOS (startp
) >= BEGV
10198 && CHARPOS (startp
) <= ZV
)
10200 w
->optional_new_start
= Qnil
;
10201 start_display (&it
, w
, startp
);
10202 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10203 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10204 if (IT_CHARPOS (it
) == PT
)
10205 w
->force_start
= Qt
;
10208 /* Handle case where place to start displaying has been specified,
10209 unless the specified location is outside the accessible range. */
10210 if (!NILP (w
->force_start
)
10211 || w
->frozen_window_start_p
)
10213 w
->force_start
= Qnil
;
10215 w
->window_end_valid
= Qnil
;
10217 /* Forget any recorded base line for line number display. */
10218 if (!current_matrix_up_to_date_p
10219 || current_buffer
->clip_changed
)
10220 w
->base_line_number
= Qnil
;
10222 /* Redisplay the mode line. Select the buffer properly for that.
10223 Also, run the hook window-scroll-functions
10224 because we have scrolled. */
10225 /* Note, we do this after clearing force_start because
10226 if there's an error, it is better to forget about force_start
10227 than to get into an infinite loop calling the hook functions
10228 and having them get more errors. */
10229 if (!update_mode_line
10230 || ! NILP (Vwindow_scroll_functions
))
10232 update_mode_line
= 1;
10233 w
->update_mode_line
= Qt
;
10234 startp
= run_window_scroll_functions (window
, startp
);
10237 w
->last_modified
= make_number (0);
10238 w
->last_overlay_modified
= make_number (0);
10239 if (CHARPOS (startp
) < BEGV
)
10240 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10241 else if (CHARPOS (startp
) > ZV
)
10242 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10244 /* Redisplay, then check if cursor has been set during the
10245 redisplay. Give up if new fonts were loaded. */
10246 if (!try_window (window
, startp
))
10248 w
->force_start
= Qt
;
10249 clear_glyph_matrix (w
->desired_matrix
);
10250 goto finish_scroll_bars
;
10253 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10255 /* If point does not appear, try to move point so it does
10256 appear. The desired matrix has been built above, so we
10257 can use it here. */
10259 struct glyph_row
*row
;
10261 window_height
= window_box_height (w
) / 2;
10262 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10263 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
10266 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10267 MATRIX_ROW_START_BYTEPOS (row
));
10269 if (w
!= XWINDOW (selected_window
))
10270 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10271 else if (current_buffer
== old
)
10272 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10274 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10276 /* If we are highlighting the region, then we just changed
10277 the region, so redisplay to show it. */
10278 if (!NILP (Vtransient_mark_mode
)
10279 && !NILP (current_buffer
->mark_active
))
10281 clear_glyph_matrix (w
->desired_matrix
);
10282 if (!try_window (window
, startp
))
10283 goto need_larger_matrices
;
10287 if (!make_cursor_line_fully_visible (w
))
10288 goto need_larger_matrices
;
10290 debug_method_add (w
, "forced window start");
10295 /* Handle case where text has not changed, only point, and it has
10296 not moved off the frame. */
10297 if (current_matrix_up_to_date_p
10298 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10299 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10303 case CURSOR_MOVEMENT_SUCCESS
:
10306 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10307 goto need_larger_matrices
;
10309 case CURSOR_MOVEMENT_MUST_SCROLL
:
10310 goto try_to_scroll
;
10316 /* If current starting point was originally the beginning of a line
10317 but no longer is, find a new starting point. */
10318 else if (!NILP (w
->start_at_line_beg
)
10319 && !(CHARPOS (startp
) <= BEGV
10320 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10323 debug_method_add (w
, "recenter 1");
10328 /* Try scrolling with try_window_id. Value is > 0 if update has
10329 been done, it is -1 if we know that the same window start will
10330 not work. It is 0 if unsuccessful for some other reason. */
10331 else if ((tem
= try_window_id (w
)) != 0)
10334 debug_method_add (w
, "try_window_id %d", tem
);
10337 if (fonts_changed_p
)
10338 goto need_larger_matrices
;
10342 /* Otherwise try_window_id has returned -1 which means that we
10343 don't want the alternative below this comment to execute. */
10345 else if (CHARPOS (startp
) >= BEGV
10346 && CHARPOS (startp
) <= ZV
10347 && PT
>= CHARPOS (startp
)
10348 && (CHARPOS (startp
) < ZV
10349 /* Avoid starting at end of buffer. */
10350 || CHARPOS (startp
) == BEGV
10351 || (XFASTINT (w
->last_modified
) >= MODIFF
10352 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10355 debug_method_add (w
, "same window start");
10358 /* Try to redisplay starting at same place as before.
10359 If point has not moved off frame, accept the results. */
10360 if (!current_matrix_up_to_date_p
10361 /* Don't use try_window_reusing_current_matrix in this case
10362 because a window scroll function can have changed the
10364 || !NILP (Vwindow_scroll_functions
)
10365 || MINI_WINDOW_P (w
)
10366 || !try_window_reusing_current_matrix (w
))
10368 IF_DEBUG (debug_method_add (w
, "1"));
10369 try_window (window
, startp
);
10372 if (fonts_changed_p
)
10373 goto need_larger_matrices
;
10375 if (w
->cursor
.vpos
>= 0)
10377 if (!just_this_one_p
10378 || current_buffer
->clip_changed
10379 || BEG_UNCHANGED
< CHARPOS (startp
))
10380 /* Forget any recorded base line for line number display. */
10381 w
->base_line_number
= Qnil
;
10383 if (!make_cursor_line_fully_visible (w
))
10384 goto need_larger_matrices
;
10388 clear_glyph_matrix (w
->desired_matrix
);
10393 w
->last_modified
= make_number (0);
10394 w
->last_overlay_modified
= make_number (0);
10396 /* Redisplay the mode line. Select the buffer properly for that. */
10397 if (!update_mode_line
)
10399 update_mode_line
= 1;
10400 w
->update_mode_line
= Qt
;
10403 /* Try to scroll by specified few lines. */
10404 if ((scroll_conservatively
10406 || temp_scroll_step
10407 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10408 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10409 && !current_buffer
->clip_changed
10410 && CHARPOS (startp
) >= BEGV
10411 && CHARPOS (startp
) <= ZV
)
10413 /* The function returns -1 if new fonts were loaded, 1 if
10414 successful, 0 if not successful. */
10415 int rc
= try_scrolling (window
, just_this_one_p
,
10416 scroll_conservatively
,
10421 case SCROLLING_SUCCESS
:
10424 case SCROLLING_NEED_LARGER_MATRICES
:
10425 goto need_larger_matrices
;
10427 case SCROLLING_FAILED
:
10435 /* Finally, just choose place to start which centers point */
10440 debug_method_add (w
, "recenter");
10443 /* w->vscroll = 0; */
10445 /* Forget any previously recorded base line for line number display. */
10446 if (!current_matrix_up_to_date_p
10447 || current_buffer
->clip_changed
)
10448 w
->base_line_number
= Qnil
;
10450 /* Move backward half the height of the window. */
10451 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10452 it
.current_y
= it
.last_visible_y
;
10453 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
10454 xassert (IT_CHARPOS (it
) >= BEGV
);
10456 /* The function move_it_vertically_backward may move over more
10457 than the specified y-distance. If it->w is small, e.g. a
10458 mini-buffer window, we may end up in front of the window's
10459 display area. Start displaying at the start of the line
10460 containing PT in this case. */
10461 if (it
.current_y
<= 0)
10463 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
10464 move_it_vertically (&it
, 0);
10465 xassert (IT_CHARPOS (it
) <= PT
);
10469 it
.current_x
= it
.hpos
= 0;
10471 /* Set startp here explicitly in case that helps avoid an infinite loop
10472 in case the window-scroll-functions functions get errors. */
10473 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
10475 /* Run scroll hooks. */
10476 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
10478 /* Redisplay the window. */
10479 if (!current_matrix_up_to_date_p
10480 || windows_or_buffers_changed
10481 /* Don't use try_window_reusing_current_matrix in this case
10482 because it can have changed the buffer. */
10483 || !NILP (Vwindow_scroll_functions
)
10484 || !just_this_one_p
10485 || MINI_WINDOW_P (w
)
10486 || !try_window_reusing_current_matrix (w
))
10487 try_window (window
, startp
);
10489 /* If new fonts have been loaded (due to fontsets), give up. We
10490 have to start a new redisplay since we need to re-adjust glyph
10492 if (fonts_changed_p
)
10493 goto need_larger_matrices
;
10495 /* If cursor did not appear assume that the middle of the window is
10496 in the first line of the window. Do it again with the next line.
10497 (Imagine a window of height 100, displaying two lines of height
10498 60. Moving back 50 from it->last_visible_y will end in the first
10500 if (w
->cursor
.vpos
< 0)
10502 if (!NILP (w
->window_end_valid
)
10503 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
10505 clear_glyph_matrix (w
->desired_matrix
);
10506 move_it_by_lines (&it
, 1, 0);
10507 try_window (window
, it
.current
.pos
);
10509 else if (PT
< IT_CHARPOS (it
))
10511 clear_glyph_matrix (w
->desired_matrix
);
10512 move_it_by_lines (&it
, -1, 0);
10513 try_window (window
, it
.current
.pos
);
10517 /* Not much we can do about it. */
10521 /* Consider the following case: Window starts at BEGV, there is
10522 invisible, intangible text at BEGV, so that display starts at
10523 some point START > BEGV. It can happen that we are called with
10524 PT somewhere between BEGV and START. Try to handle that case. */
10525 if (w
->cursor
.vpos
< 0)
10527 struct glyph_row
*row
= w
->current_matrix
->rows
;
10528 if (row
->mode_line_p
)
10530 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10533 if (!make_cursor_line_fully_visible (w
))
10534 goto need_larger_matrices
;
10538 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10539 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
10540 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
10543 /* Display the mode line, if we must. */
10544 if ((update_mode_line
10545 /* If window not full width, must redo its mode line
10546 if (a) the window to its side is being redone and
10547 (b) we do a frame-based redisplay. This is a consequence
10548 of how inverted lines are drawn in frame-based redisplay. */
10549 || (!just_this_one_p
10550 && !FRAME_WINDOW_P (f
)
10551 && !WINDOW_FULL_WIDTH_P (w
))
10552 /* Line number to display. */
10553 || INTEGERP (w
->base_line_pos
)
10554 /* Column number is displayed and different from the one displayed. */
10555 || (!NILP (w
->column_number_displayed
)
10556 && XFASTINT (w
->column_number_displayed
) != current_column ()))
10557 /* This means that the window has a mode line. */
10558 && (WINDOW_WANTS_MODELINE_P (w
)
10559 || WINDOW_WANTS_HEADER_LINE_P (w
)))
10561 display_mode_lines (w
);
10563 /* If mode line height has changed, arrange for a thorough
10564 immediate redisplay using the correct mode line height. */
10565 if (WINDOW_WANTS_MODELINE_P (w
)
10566 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
10568 fonts_changed_p
= 1;
10569 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
10570 = DESIRED_MODE_LINE_HEIGHT (w
);
10573 /* If top line height has changed, arrange for a thorough
10574 immediate redisplay using the correct mode line height. */
10575 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10576 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
10578 fonts_changed_p
= 1;
10579 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
10580 = DESIRED_HEADER_LINE_HEIGHT (w
);
10583 if (fonts_changed_p
)
10584 goto need_larger_matrices
;
10587 if (!line_number_displayed
10588 && !BUFFERP (w
->base_line_pos
))
10590 w
->base_line_pos
= Qnil
;
10591 w
->base_line_number
= Qnil
;
10596 /* When we reach a frame's selected window, redo the frame's menu bar. */
10597 if (update_mode_line
10598 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
10600 int redisplay_menu_p
= 0;
10602 if (FRAME_WINDOW_P (f
))
10604 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
10605 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
10607 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10611 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
10613 if (redisplay_menu_p
)
10614 display_menu_bar (w
);
10616 #ifdef HAVE_WINDOW_SYSTEM
10617 if (WINDOWP (f
->tool_bar_window
)
10618 && (FRAME_TOOL_BAR_LINES (f
) > 0
10619 || auto_resize_tool_bars_p
))
10620 redisplay_tool_bar (f
);
10624 need_larger_matrices
:
10626 finish_scroll_bars
:
10628 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10630 int start
, end
, whole
;
10632 /* Calculate the start and end positions for the current window.
10633 At some point, it would be nice to choose between scrollbars
10634 which reflect the whole buffer size, with special markers
10635 indicating narrowing, and scrollbars which reflect only the
10638 Note that mini-buffers sometimes aren't displaying any text. */
10639 if (!MINI_WINDOW_P (w
)
10640 || (w
== XWINDOW (minibuf_window
)
10641 && NILP (echo_area_buffer
[0])))
10644 start
= marker_position (w
->start
) - BEGV
;
10645 /* I don't think this is guaranteed to be right. For the
10646 moment, we'll pretend it is. */
10647 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
10651 if (whole
< (end
- start
))
10652 whole
= end
- start
;
10655 start
= end
= whole
= 0;
10657 /* Indicate what this scroll bar ought to be displaying now. */
10658 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
10660 /* Note that we actually used the scroll bar attached to this
10661 window, so it shouldn't be deleted at the end of redisplay. */
10662 redeem_scroll_bar_hook (w
);
10665 /* Restore current_buffer and value of point in it. */
10666 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
10667 set_buffer_internal_1 (old
);
10668 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
10670 unbind_to (count
, Qnil
);
10674 /* Build the complete desired matrix of WINDOW with a window start
10675 buffer position POS. Value is non-zero if successful. It is zero
10676 if fonts were loaded during redisplay which makes re-adjusting
10677 glyph matrices necessary. */
10680 try_window (window
, pos
)
10681 Lisp_Object window
;
10682 struct text_pos pos
;
10684 struct window
*w
= XWINDOW (window
);
10686 struct glyph_row
*last_text_row
= NULL
;
10688 /* Make POS the new window start. */
10689 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10691 /* Mark cursor position as unknown. No overlay arrow seen. */
10692 w
->cursor
.vpos
= -1;
10693 overlay_arrow_seen
= 0;
10695 /* Initialize iterator and info to start at POS. */
10696 start_display (&it
, w
, pos
);
10698 /* Display all lines of W. */
10699 while (it
.current_y
< it
.last_visible_y
)
10701 if (display_line (&it
))
10702 last_text_row
= it
.glyph_row
- 1;
10703 if (fonts_changed_p
)
10707 /* If bottom moved off end of frame, change mode line percentage. */
10708 if (XFASTINT (w
->window_end_pos
) <= 0
10709 && Z
!= IT_CHARPOS (it
))
10710 w
->update_mode_line
= Qt
;
10712 /* Set window_end_pos to the offset of the last character displayed
10713 on the window from the end of current_buffer. Set
10714 window_end_vpos to its row number. */
10717 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10718 w
->window_end_bytepos
10719 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10721 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10723 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10724 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10725 ->displays_text_p
);
10729 w
->window_end_bytepos
= 0;
10730 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10733 /* But that is not valid info until redisplay finishes. */
10734 w
->window_end_valid
= Qnil
;
10740 /************************************************************************
10741 Window redisplay reusing current matrix when buffer has not changed
10742 ************************************************************************/
10744 /* Try redisplay of window W showing an unchanged buffer with a
10745 different window start than the last time it was displayed by
10746 reusing its current matrix. Value is non-zero if successful.
10747 W->start is the new window start. */
10750 try_window_reusing_current_matrix (w
)
10753 struct frame
*f
= XFRAME (w
->frame
);
10754 struct glyph_row
*row
, *bottom_row
;
10757 struct text_pos start
, new_start
;
10758 int nrows_scrolled
, i
;
10759 struct glyph_row
*last_text_row
;
10760 struct glyph_row
*last_reused_text_row
;
10761 struct glyph_row
*start_row
;
10762 int start_vpos
, min_y
, max_y
;
10765 if (inhibit_try_window_reusing
)
10769 if (/* This function doesn't handle terminal frames. */
10770 !FRAME_WINDOW_P (f
)
10771 /* Don't try to reuse the display if windows have been split
10773 || windows_or_buffers_changed
)
10776 /* Can't do this if region may have changed. */
10777 if ((!NILP (Vtransient_mark_mode
)
10778 && !NILP (current_buffer
->mark_active
))
10779 || !NILP (w
->region_showing
)
10780 || !NILP (Vshow_trailing_whitespace
))
10783 /* If top-line visibility has changed, give up. */
10784 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10785 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10788 /* Give up if old or new display is scrolled vertically. We could
10789 make this function handle this, but right now it doesn't. */
10790 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10791 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10794 /* The variable new_start now holds the new window start. The old
10795 start `start' can be determined from the current matrix. */
10796 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10797 start
= start_row
->start
.pos
;
10798 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10800 /* Clear the desired matrix for the display below. */
10801 clear_glyph_matrix (w
->desired_matrix
);
10803 if (CHARPOS (new_start
) <= CHARPOS (start
))
10807 /* Don't use this method if the display starts with an ellipsis
10808 displayed for invisible text. It's not easy to handle that case
10809 below, and it's certainly not worth the effort since this is
10810 not a frequent case. */
10811 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
10814 IF_DEBUG (debug_method_add (w
, "twu1"));
10816 /* Display up to a row that can be reused. The variable
10817 last_text_row is set to the last row displayed that displays
10818 text. Note that it.vpos == 0 if or if not there is a
10819 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10820 start_display (&it
, w
, new_start
);
10821 first_row_y
= it
.current_y
;
10822 w
->cursor
.vpos
= -1;
10823 last_text_row
= last_reused_text_row
= NULL
;
10825 while (it
.current_y
< it
.last_visible_y
10826 && IT_CHARPOS (it
) < CHARPOS (start
)
10827 && !fonts_changed_p
)
10828 if (display_line (&it
))
10829 last_text_row
= it
.glyph_row
- 1;
10831 /* A value of current_y < last_visible_y means that we stopped
10832 at the previous window start, which in turn means that we
10833 have at least one reusable row. */
10834 if (it
.current_y
< it
.last_visible_y
)
10836 /* IT.vpos always starts from 0; it counts text lines. */
10837 nrows_scrolled
= it
.vpos
;
10839 /* Find PT if not already found in the lines displayed. */
10840 if (w
->cursor
.vpos
< 0)
10842 int dy
= it
.current_y
- first_row_y
;
10844 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10845 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
10847 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10848 dy
, nrows_scrolled
);
10851 clear_glyph_matrix (w
->desired_matrix
);
10856 /* Scroll the display. Do it before the current matrix is
10857 changed. The problem here is that update has not yet
10858 run, i.e. part of the current matrix is not up to date.
10859 scroll_run_hook will clear the cursor, and use the
10860 current matrix to get the height of the row the cursor is
10862 run
.current_y
= first_row_y
;
10863 run
.desired_y
= it
.current_y
;
10864 run
.height
= it
.last_visible_y
- it
.current_y
;
10866 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10869 rif
->update_window_begin_hook (w
);
10870 rif
->clear_mouse_face (w
);
10871 rif
->scroll_run_hook (w
, &run
);
10872 rif
->update_window_end_hook (w
, 0, 0);
10876 /* Shift current matrix down by nrows_scrolled lines. */
10877 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10878 rotate_matrix (w
->current_matrix
,
10880 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10883 /* Disable lines that must be updated. */
10884 for (i
= 0; i
< it
.vpos
; ++i
)
10885 (start_row
+ i
)->enabled_p
= 0;
10887 /* Re-compute Y positions. */
10888 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10889 max_y
= it
.last_visible_y
;
10890 for (row
= start_row
+ nrows_scrolled
;
10894 row
->y
= it
.current_y
;
10895 row
->visible_height
= row
->height
;
10897 if (row
->y
< min_y
)
10898 row
->visible_height
-= min_y
- row
->y
;
10899 if (row
->y
+ row
->height
> max_y
)
10900 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10902 it
.current_y
+= row
->height
;
10904 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10905 last_reused_text_row
= row
;
10906 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10910 /* Disable lines in the current matrix which are now
10911 below the window. */
10912 for (++row
; row
< bottom_row
; ++row
)
10913 row
->enabled_p
= 0;
10916 /* Update window_end_pos etc.; last_reused_text_row is the last
10917 reused row from the current matrix containing text, if any.
10918 The value of last_text_row is the last displayed line
10919 containing text. */
10920 if (last_reused_text_row
)
10922 w
->window_end_bytepos
10923 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10925 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10927 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
10928 w
->current_matrix
));
10930 else if (last_text_row
)
10932 w
->window_end_bytepos
10933 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10935 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10937 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10941 /* This window must be completely empty. */
10942 w
->window_end_bytepos
= 0;
10943 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
10945 w
->window_end_valid
= Qnil
;
10947 /* Update hint: don't try scrolling again in update_window. */
10948 w
->desired_matrix
->no_scrolling_p
= 1;
10951 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10955 else if (CHARPOS (new_start
) > CHARPOS (start
))
10957 struct glyph_row
*pt_row
, *row
;
10958 struct glyph_row
*first_reusable_row
;
10959 struct glyph_row
*first_row_to_display
;
10961 int yb
= window_text_bottom_y (w
);
10963 /* Find the row starting at new_start, if there is one. Don't
10964 reuse a partially visible line at the end. */
10965 first_reusable_row
= start_row
;
10966 while (first_reusable_row
->enabled_p
10967 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10968 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10969 < CHARPOS (new_start
)))
10970 ++first_reusable_row
;
10972 /* Give up if there is no row to reuse. */
10973 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10974 || !first_reusable_row
->enabled_p
10975 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10976 != CHARPOS (new_start
)))
10979 /* We can reuse fully visible rows beginning with
10980 first_reusable_row to the end of the window. Set
10981 first_row_to_display to the first row that cannot be reused.
10982 Set pt_row to the row containing point, if there is any. */
10984 for (first_row_to_display
= first_reusable_row
;
10985 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
10986 ++first_row_to_display
)
10988 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10989 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10990 pt_row
= first_row_to_display
;
10993 /* Start displaying at the start of first_row_to_display. */
10994 xassert (first_row_to_display
->y
< yb
);
10995 init_to_row_start (&it
, w
, first_row_to_display
);
10997 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10999 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11001 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11002 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11004 /* Display lines beginning with first_row_to_display in the
11005 desired matrix. Set last_text_row to the last row displayed
11006 that displays text. */
11007 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11008 if (pt_row
== NULL
)
11009 w
->cursor
.vpos
= -1;
11010 last_text_row
= NULL
;
11011 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11012 if (display_line (&it
))
11013 last_text_row
= it
.glyph_row
- 1;
11015 /* Give up If point isn't in a row displayed or reused. */
11016 if (w
->cursor
.vpos
< 0)
11018 clear_glyph_matrix (w
->desired_matrix
);
11022 /* If point is in a reused row, adjust y and vpos of the cursor
11026 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11027 w
->current_matrix
);
11028 w
->cursor
.y
-= first_reusable_row
->y
;
11031 /* Scroll the display. */
11032 run
.current_y
= first_reusable_row
->y
;
11033 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11034 run
.height
= it
.last_visible_y
- run
.current_y
;
11035 dy
= run
.current_y
- run
.desired_y
;
11039 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11041 rif
->update_window_begin_hook (w
);
11042 rif
->clear_mouse_face (w
);
11043 rif
->scroll_run_hook (w
, &run
);
11044 rif
->update_window_end_hook (w
, 0, 0);
11048 /* Adjust Y positions of reused rows. */
11049 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11050 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11051 max_y
= it
.last_visible_y
;
11052 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11055 row
->visible_height
= row
->height
;
11056 if (row
->y
< min_y
)
11057 row
->visible_height
-= min_y
- row
->y
;
11058 if (row
->y
+ row
->height
> max_y
)
11059 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11062 /* Scroll the current matrix. */
11063 xassert (nrows_scrolled
> 0);
11064 rotate_matrix (w
->current_matrix
,
11066 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11069 /* Disable rows not reused. */
11070 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11071 row
->enabled_p
= 0;
11073 /* Adjust window end. A null value of last_text_row means that
11074 the window end is in reused rows which in turn means that
11075 only its vpos can have changed. */
11078 w
->window_end_bytepos
11079 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11081 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11083 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11088 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11091 w
->window_end_valid
= Qnil
;
11092 w
->desired_matrix
->no_scrolling_p
= 1;
11095 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11105 /************************************************************************
11106 Window redisplay reusing current matrix when buffer has changed
11107 ************************************************************************/
11109 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11110 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11112 static struct glyph_row
*
11113 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11114 struct glyph_row
*));
11117 /* Return the last row in MATRIX displaying text. If row START is
11118 non-null, start searching with that row. IT gives the dimensions
11119 of the display. Value is null if matrix is empty; otherwise it is
11120 a pointer to the row found. */
11122 static struct glyph_row
*
11123 find_last_row_displaying_text (matrix
, it
, start
)
11124 struct glyph_matrix
*matrix
;
11126 struct glyph_row
*start
;
11128 struct glyph_row
*row
, *row_found
;
11130 /* Set row_found to the last row in IT->w's current matrix
11131 displaying text. The loop looks funny but think of partially
11134 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11135 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11137 xassert (row
->enabled_p
);
11139 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11148 /* Return the last row in the current matrix of W that is not affected
11149 by changes at the start of current_buffer that occurred since W's
11150 current matrix was built. Value is null if no such row exists.
11152 BEG_UNCHANGED us the number of characters unchanged at the start of
11153 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11154 first changed character in current_buffer. Characters at positions <
11155 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11156 when the current matrix was built. */
11158 static struct glyph_row
*
11159 find_last_unchanged_at_beg_row (w
)
11162 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11163 struct glyph_row
*row
;
11164 struct glyph_row
*row_found
= NULL
;
11165 int yb
= window_text_bottom_y (w
);
11167 /* Find the last row displaying unchanged text. */
11168 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11169 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11170 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11172 if (/* If row ends before first_changed_pos, it is unchanged,
11173 except in some case. */
11174 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11175 /* When row ends in ZV and we write at ZV it is not
11177 && !row
->ends_at_zv_p
11178 /* When first_changed_pos is the end of a continued line,
11179 row is not unchanged because it may be no longer
11181 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11182 && row
->continued_p
))
11185 /* Stop if last visible row. */
11186 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11196 /* Find the first glyph row in the current matrix of W that is not
11197 affected by changes at the end of current_buffer since the
11198 time W's current matrix was built.
11200 Return in *DELTA the number of chars by which buffer positions in
11201 unchanged text at the end of current_buffer must be adjusted.
11203 Return in *DELTA_BYTES the corresponding number of bytes.
11205 Value is null if no such row exists, i.e. all rows are affected by
11208 static struct glyph_row
*
11209 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11211 int *delta
, *delta_bytes
;
11213 struct glyph_row
*row
;
11214 struct glyph_row
*row_found
= NULL
;
11216 *delta
= *delta_bytes
= 0;
11218 /* Display must not have been paused, otherwise the current matrix
11219 is not up to date. */
11220 if (NILP (w
->window_end_valid
))
11223 /* A value of window_end_pos >= END_UNCHANGED means that the window
11224 end is in the range of changed text. If so, there is no
11225 unchanged row at the end of W's current matrix. */
11226 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11229 /* Set row to the last row in W's current matrix displaying text. */
11230 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11232 /* If matrix is entirely empty, no unchanged row exists. */
11233 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11235 /* The value of row is the last glyph row in the matrix having a
11236 meaningful buffer position in it. The end position of row
11237 corresponds to window_end_pos. This allows us to translate
11238 buffer positions in the current matrix to current buffer
11239 positions for characters not in changed text. */
11240 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11241 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11242 int last_unchanged_pos
, last_unchanged_pos_old
;
11243 struct glyph_row
*first_text_row
11244 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11246 *delta
= Z
- Z_old
;
11247 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11249 /* Set last_unchanged_pos to the buffer position of the last
11250 character in the buffer that has not been changed. Z is the
11251 index + 1 of the last character in current_buffer, i.e. by
11252 subtracting END_UNCHANGED we get the index of the last
11253 unchanged character, and we have to add BEG to get its buffer
11255 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11256 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11258 /* Search backward from ROW for a row displaying a line that
11259 starts at a minimum position >= last_unchanged_pos_old. */
11260 for (; row
> first_text_row
; --row
)
11262 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11265 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11270 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11277 /* Make sure that glyph rows in the current matrix of window W
11278 reference the same glyph memory as corresponding rows in the
11279 frame's frame matrix. This function is called after scrolling W's
11280 current matrix on a terminal frame in try_window_id and
11281 try_window_reusing_current_matrix. */
11284 sync_frame_with_window_matrix_rows (w
)
11287 struct frame
*f
= XFRAME (w
->frame
);
11288 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11290 /* Preconditions: W must be a leaf window and full-width. Its frame
11291 must have a frame matrix. */
11292 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11293 xassert (WINDOW_FULL_WIDTH_P (w
));
11294 xassert (!FRAME_WINDOW_P (f
));
11296 /* If W is a full-width window, glyph pointers in W's current matrix
11297 have, by definition, to be the same as glyph pointers in the
11298 corresponding frame matrix. */
11299 window_row
= w
->current_matrix
->rows
;
11300 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11301 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11302 while (window_row
< window_row_end
)
11306 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
11307 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
11309 /* Disable frame rows whose corresponding window rows have
11310 been disabled in try_window_id. */
11311 if (!window_row
->enabled_p
)
11312 frame_row
->enabled_p
= 0;
11314 ++window_row
, ++frame_row
;
11319 /* Find the glyph row in window W containing CHARPOS. Consider all
11320 rows between START and END (not inclusive). END null means search
11321 all rows to the end of the display area of W. Value is the row
11322 containing CHARPOS or null. */
11325 row_containing_pos (w
, charpos
, start
, end
, dy
)
11328 struct glyph_row
*start
, *end
;
11331 struct glyph_row
*row
= start
;
11334 /* If we happen to start on a header-line, skip that. */
11335 if (row
->mode_line_p
)
11338 if ((end
&& row
>= end
) || !row
->enabled_p
)
11341 last_y
= window_text_bottom_y (w
) - dy
;
11343 while ((end
== NULL
|| row
< end
)
11344 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
11345 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
11346 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11347 /* The end position of a row equals the start
11348 position of the next row. If CHARPOS is there, we
11349 would rather display it in the next line, except
11350 when this line ends in ZV. */
11351 && !row
->ends_at_zv_p
11352 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))
11355 /* Give up if CHARPOS not found. */
11356 if ((end
&& row
>= end
)
11357 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
11358 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
11365 /* Try to redisplay window W by reusing its existing display. W's
11366 current matrix must be up to date when this function is called,
11367 i.e. window_end_valid must not be nil.
11371 1 if display has been updated
11372 0 if otherwise unsuccessful
11373 -1 if redisplay with same window start is known not to succeed
11375 The following steps are performed:
11377 1. Find the last row in the current matrix of W that is not
11378 affected by changes at the start of current_buffer. If no such row
11381 2. Find the first row in W's current matrix that is not affected by
11382 changes at the end of current_buffer. Maybe there is no such row.
11384 3. Display lines beginning with the row + 1 found in step 1 to the
11385 row found in step 2 or, if step 2 didn't find a row, to the end of
11388 4. If cursor is not known to appear on the window, give up.
11390 5. If display stopped at the row found in step 2, scroll the
11391 display and current matrix as needed.
11393 6. Maybe display some lines at the end of W, if we must. This can
11394 happen under various circumstances, like a partially visible line
11395 becoming fully visible, or because newly displayed lines are displayed
11396 in smaller font sizes.
11398 7. Update W's window end information. */
11404 struct frame
*f
= XFRAME (w
->frame
);
11405 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
11406 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
11407 struct glyph_row
*last_unchanged_at_beg_row
;
11408 struct glyph_row
*first_unchanged_at_end_row
;
11409 struct glyph_row
*row
;
11410 struct glyph_row
*bottom_row
;
11413 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
11414 struct text_pos start_pos
;
11416 int first_unchanged_at_end_vpos
= 0;
11417 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
11418 struct text_pos start
;
11419 int first_changed_charpos
, last_changed_charpos
;
11422 if (inhibit_try_window_id
)
11426 /* This is handy for debugging. */
11428 #define GIVE_UP(X) \
11430 fprintf (stderr, "try_window_id give up %d\n", (X)); \
11434 #define GIVE_UP(X) return 0
11437 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
11439 /* Don't use this for mini-windows because these can show
11440 messages and mini-buffers, and we don't handle that here. */
11441 if (MINI_WINDOW_P (w
))
11444 /* This flag is used to prevent redisplay optimizations. */
11445 if (windows_or_buffers_changed
)
11448 /* Verify that narrowing has not changed. This flag is also set to prevent
11449 redisplay optimizations. It would be nice to further
11450 reduce the number of cases where this prevents try_window_id. */
11451 if (current_buffer
->clip_changed
)
11454 /* Window must either use window-based redisplay or be full width. */
11455 if (!FRAME_WINDOW_P (f
)
11456 && (!line_ins_del_ok
11457 || !WINDOW_FULL_WIDTH_P (w
)))
11460 /* Give up if point is not known NOT to appear in W. */
11461 if (PT
< CHARPOS (start
))
11464 /* Another way to prevent redisplay optimizations. */
11465 if (XFASTINT (w
->last_modified
) == 0)
11468 /* Verify that window is not hscrolled. */
11469 if (XFASTINT (w
->hscroll
) != 0)
11472 /* Verify that display wasn't paused. */
11473 if (NILP (w
->window_end_valid
))
11476 /* Can't use this if highlighting a region because a cursor movement
11477 will do more than just set the cursor. */
11478 if (!NILP (Vtransient_mark_mode
)
11479 && !NILP (current_buffer
->mark_active
))
11482 /* Likewise if highlighting trailing whitespace. */
11483 if (!NILP (Vshow_trailing_whitespace
))
11486 /* Likewise if showing a region. */
11487 if (!NILP (w
->region_showing
))
11490 /* Can use this if overlay arrow position and or string have changed. */
11491 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
11492 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
11496 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
11497 only if buffer has really changed. The reason is that the gap is
11498 initially at Z for freshly visited files. The code below would
11499 set end_unchanged to 0 in that case. */
11500 if (MODIFF
> SAVE_MODIFF
11501 /* This seems to happen sometimes after saving a buffer. */
11502 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
11504 if (GPT
- BEG
< BEG_UNCHANGED
)
11505 BEG_UNCHANGED
= GPT
- BEG
;
11506 if (Z
- GPT
< END_UNCHANGED
)
11507 END_UNCHANGED
= Z
- GPT
;
11510 /* The position of the first and last character that has been changed. */
11511 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
11512 last_changed_charpos
= Z
- END_UNCHANGED
;
11514 /* If window starts after a line end, and the last change is in
11515 front of that newline, then changes don't affect the display.
11516 This case happens with stealth-fontification. Note that although
11517 the display is unchanged, glyph positions in the matrix have to
11518 be adjusted, of course. */
11519 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11520 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11521 && ((last_changed_charpos
< CHARPOS (start
)
11522 && CHARPOS (start
) == BEGV
)
11523 || (last_changed_charpos
< CHARPOS (start
) - 1
11524 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
11526 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
11527 struct glyph_row
*r0
;
11529 /* Compute how many chars/bytes have been added to or removed
11530 from the buffer. */
11531 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11532 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11534 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11536 /* Give up if PT is not in the window. Note that it already has
11537 been checked at the start of try_window_id that PT is not in
11538 front of the window start. */
11539 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
11542 /* If window start is unchanged, we can reuse the whole matrix
11543 as is, after adjusting glyph positions. No need to compute
11544 the window end again, since its offset from Z hasn't changed. */
11545 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11546 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
11547 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
11549 /* Adjust positions in the glyph matrix. */
11550 if (delta
|| delta_bytes
)
11552 struct glyph_row
*r1
11553 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11554 increment_matrix_positions (w
->current_matrix
,
11555 MATRIX_ROW_VPOS (r0
, current_matrix
),
11556 MATRIX_ROW_VPOS (r1
, current_matrix
),
11557 delta
, delta_bytes
);
11560 /* Set the cursor. */
11561 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11562 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11567 /* Handle the case that changes are all below what is displayed in
11568 the window, and that PT is in the window. This shortcut cannot
11569 be taken if ZV is visible in the window, and text has been added
11570 there that is visible in the window. */
11571 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
11572 /* ZV is not visible in the window, or there are no
11573 changes at ZV, actually. */
11574 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
11575 || first_changed_charpos
== last_changed_charpos
))
11577 struct glyph_row
*r0
;
11579 /* Give up if PT is not in the window. Note that it already has
11580 been checked at the start of try_window_id that PT is not in
11581 front of the window start. */
11582 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
11585 /* If window start is unchanged, we can reuse the whole matrix
11586 as is, without changing glyph positions since no text has
11587 been added/removed in front of the window end. */
11588 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11589 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
11591 /* We have to compute the window end anew since text
11592 can have been added/removed after it. */
11594 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
11595 w
->window_end_bytepos
11596 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11598 /* Set the cursor. */
11599 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
11600 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
11605 /* Give up if window start is in the changed area.
11607 The condition used to read
11609 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
11611 but why that was tested escapes me at the moment. */
11612 if (CHARPOS (start
) >= first_changed_charpos
11613 && CHARPOS (start
) <= last_changed_charpos
)
11616 /* Check that window start agrees with the start of the first glyph
11617 row in its current matrix. Check this after we know the window
11618 start is not in changed text, otherwise positions would not be
11620 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
11621 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
11624 /* Give up if the window ends in strings. Overlay strings
11625 at the end are difficult to handle, so don't try. */
11626 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
11627 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
11630 /* Compute the position at which we have to start displaying new
11631 lines. Some of the lines at the top of the window might be
11632 reusable because they are not displaying changed text. Find the
11633 last row in W's current matrix not affected by changes at the
11634 start of current_buffer. Value is null if changes start in the
11635 first line of window. */
11636 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
11637 if (last_unchanged_at_beg_row
)
11639 /* Avoid starting to display in the moddle of a character, a TAB
11640 for instance. This is easier than to set up the iterator
11641 exactly, and it's not a frequent case, so the additional
11642 effort wouldn't really pay off. */
11643 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
11644 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
11645 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
11646 --last_unchanged_at_beg_row
;
11648 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
11651 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
11653 start_pos
= it
.current
.pos
;
11655 /* Start displaying new lines in the desired matrix at the same
11656 vpos we would use in the current matrix, i.e. below
11657 last_unchanged_at_beg_row. */
11658 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
11660 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11661 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
11663 xassert (it
.hpos
== 0 && it
.current_x
== 0);
11667 /* There are no reusable lines at the start of the window.
11668 Start displaying in the first line. */
11669 start_display (&it
, w
, start
);
11670 start_pos
= it
.current
.pos
;
11673 /* Find the first row that is not affected by changes at the end of
11674 the buffer. Value will be null if there is no unchanged row, in
11675 which case we must redisplay to the end of the window. delta
11676 will be set to the value by which buffer positions beginning with
11677 first_unchanged_at_end_row have to be adjusted due to text
11679 first_unchanged_at_end_row
11680 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
11681 IF_DEBUG (debug_delta
= delta
);
11682 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
11684 /* Set stop_pos to the buffer position up to which we will have to
11685 display new lines. If first_unchanged_at_end_row != NULL, this
11686 is the buffer position of the start of the line displayed in that
11687 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
11688 that we don't stop at a buffer position. */
11690 if (first_unchanged_at_end_row
)
11692 xassert (last_unchanged_at_beg_row
== NULL
11693 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
11695 /* If this is a continuation line, move forward to the next one
11696 that isn't. Changes in lines above affect this line.
11697 Caution: this may move first_unchanged_at_end_row to a row
11698 not displaying text. */
11699 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
11700 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11701 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11702 < it
.last_visible_y
))
11703 ++first_unchanged_at_end_row
;
11705 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
11706 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
11707 >= it
.last_visible_y
))
11708 first_unchanged_at_end_row
= NULL
;
11711 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
11713 first_unchanged_at_end_vpos
11714 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
11715 xassert (stop_pos
>= Z
- END_UNCHANGED
);
11718 else if (last_unchanged_at_beg_row
== NULL
)
11724 /* Either there is no unchanged row at the end, or the one we have
11725 now displays text. This is a necessary condition for the window
11726 end pos calculation at the end of this function. */
11727 xassert (first_unchanged_at_end_row
== NULL
11728 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
11730 debug_last_unchanged_at_beg_vpos
11731 = (last_unchanged_at_beg_row
11732 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
11734 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
11736 #endif /* GLYPH_DEBUG != 0 */
11739 /* Display new lines. Set last_text_row to the last new line
11740 displayed which has text on it, i.e. might end up as being the
11741 line where the window_end_vpos is. */
11742 w
->cursor
.vpos
= -1;
11743 last_text_row
= NULL
;
11744 overlay_arrow_seen
= 0;
11745 while (it
.current_y
< it
.last_visible_y
11746 && !fonts_changed_p
11747 && (first_unchanged_at_end_row
== NULL
11748 || IT_CHARPOS (it
) < stop_pos
))
11750 if (display_line (&it
))
11751 last_text_row
= it
.glyph_row
- 1;
11754 if (fonts_changed_p
)
11758 /* Compute differences in buffer positions, y-positions etc. for
11759 lines reused at the bottom of the window. Compute what we can
11761 if (first_unchanged_at_end_row
11762 /* No lines reused because we displayed everything up to the
11763 bottom of the window. */
11764 && it
.current_y
< it
.last_visible_y
)
11767 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
11769 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
11770 run
.current_y
= first_unchanged_at_end_row
->y
;
11771 run
.desired_y
= run
.current_y
+ dy
;
11772 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
11776 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
11777 first_unchanged_at_end_row
= NULL
;
11779 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
11782 /* Find the cursor if not already found. We have to decide whether
11783 PT will appear on this window (it sometimes doesn't, but this is
11784 not a very frequent case.) This decision has to be made before
11785 the current matrix is altered. A value of cursor.vpos < 0 means
11786 that PT is either in one of the lines beginning at
11787 first_unchanged_at_end_row or below the window. Don't care for
11788 lines that might be displayed later at the window end; as
11789 mentioned, this is not a frequent case. */
11790 if (w
->cursor
.vpos
< 0)
11792 /* Cursor in unchanged rows at the top? */
11793 if (PT
< CHARPOS (start_pos
)
11794 && last_unchanged_at_beg_row
)
11796 row
= row_containing_pos (w
, PT
,
11797 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
11798 last_unchanged_at_beg_row
+ 1, 0);
11800 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11803 /* Start from first_unchanged_at_end_row looking for PT. */
11804 else if (first_unchanged_at_end_row
)
11806 row
= row_containing_pos (w
, PT
- delta
,
11807 first_unchanged_at_end_row
, NULL
, 0);
11809 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11810 delta_bytes
, dy
, dvpos
);
11813 /* Give up if cursor was not found. */
11814 if (w
->cursor
.vpos
< 0)
11816 clear_glyph_matrix (w
->desired_matrix
);
11821 /* Don't let the cursor end in the scroll margins. */
11823 int this_scroll_margin
, cursor_height
;
11825 this_scroll_margin
= max (0, scroll_margin
);
11826 this_scroll_margin
= min (this_scroll_margin
,
11827 XFASTINT (w
->height
) / 4);
11828 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11829 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11831 if ((w
->cursor
.y
< this_scroll_margin
11832 && CHARPOS (start
) > BEGV
)
11833 /* Don't take scroll margin into account at the bottom because
11834 old redisplay didn't do it either. */
11835 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11837 w
->cursor
.vpos
= -1;
11838 clear_glyph_matrix (w
->desired_matrix
);
11843 /* Scroll the display. Do it before changing the current matrix so
11844 that xterm.c doesn't get confused about where the cursor glyph is
11846 if (dy
&& run
.height
)
11850 if (FRAME_WINDOW_P (f
))
11852 rif
->update_window_begin_hook (w
);
11853 rif
->clear_mouse_face (w
);
11854 rif
->scroll_run_hook (w
, &run
);
11855 rif
->update_window_end_hook (w
, 0, 0);
11859 /* Terminal frame. In this case, dvpos gives the number of
11860 lines to scroll by; dvpos < 0 means scroll up. */
11861 int first_unchanged_at_end_vpos
11862 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11863 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11864 int end
= (XFASTINT (w
->top
)
11865 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
11866 + window_internal_height (w
));
11868 /* Perform the operation on the screen. */
11871 /* Scroll last_unchanged_at_beg_row to the end of the
11872 window down dvpos lines. */
11873 set_terminal_window (end
);
11875 /* On dumb terminals delete dvpos lines at the end
11876 before inserting dvpos empty lines. */
11877 if (!scroll_region_ok
)
11878 ins_del_lines (end
- dvpos
, -dvpos
);
11880 /* Insert dvpos empty lines in front of
11881 last_unchanged_at_beg_row. */
11882 ins_del_lines (from
, dvpos
);
11884 else if (dvpos
< 0)
11886 /* Scroll up last_unchanged_at_beg_vpos to the end of
11887 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11888 set_terminal_window (end
);
11890 /* Delete dvpos lines in front of
11891 last_unchanged_at_beg_vpos. ins_del_lines will set
11892 the cursor to the given vpos and emit |dvpos| delete
11894 ins_del_lines (from
+ dvpos
, dvpos
);
11896 /* On a dumb terminal insert dvpos empty lines at the
11898 if (!scroll_region_ok
)
11899 ins_del_lines (end
+ dvpos
, -dvpos
);
11902 set_terminal_window (0);
11908 /* Shift reused rows of the current matrix to the right position.
11909 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11911 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11912 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11915 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11916 bottom_vpos
, dvpos
);
11917 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11920 else if (dvpos
> 0)
11922 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11923 bottom_vpos
, dvpos
);
11924 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11925 first_unchanged_at_end_vpos
+ dvpos
, 0);
11928 /* For frame-based redisplay, make sure that current frame and window
11929 matrix are in sync with respect to glyph memory. */
11930 if (!FRAME_WINDOW_P (f
))
11931 sync_frame_with_window_matrix_rows (w
);
11933 /* Adjust buffer positions in reused rows. */
11935 increment_matrix_positions (current_matrix
,
11936 first_unchanged_at_end_vpos
+ dvpos
,
11937 bottom_vpos
, delta
, delta_bytes
);
11939 /* Adjust Y positions. */
11941 shift_glyph_matrix (w
, current_matrix
,
11942 first_unchanged_at_end_vpos
+ dvpos
,
11945 if (first_unchanged_at_end_row
)
11946 first_unchanged_at_end_row
+= dvpos
;
11948 /* If scrolling up, there may be some lines to display at the end of
11950 last_text_row_at_end
= NULL
;
11953 /* Scrolling up can leave for example a partially visible line
11954 at the end of the window to be redisplayed. */
11955 /* Set last_row to the glyph row in the current matrix where the
11956 window end line is found. It has been moved up or down in
11957 the matrix by dvpos. */
11958 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11959 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11961 /* If last_row is the window end line, it should display text. */
11962 xassert (last_row
->displays_text_p
);
11964 /* If window end line was partially visible before, begin
11965 displaying at that line. Otherwise begin displaying with the
11966 line following it. */
11967 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11969 init_to_row_start (&it
, w
, last_row
);
11970 it
.vpos
= last_vpos
;
11971 it
.current_y
= last_row
->y
;
11975 init_to_row_end (&it
, w
, last_row
);
11976 it
.vpos
= 1 + last_vpos
;
11977 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11981 /* We may start in a continuation line. If so, we have to
11982 get the right continuation_lines_width and current_x. */
11983 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11984 it
.hpos
= it
.current_x
= 0;
11986 /* Display the rest of the lines at the window end. */
11987 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11988 while (it
.current_y
< it
.last_visible_y
11989 && !fonts_changed_p
)
11991 /* Is it always sure that the display agrees with lines in
11992 the current matrix? I don't think so, so we mark rows
11993 displayed invalid in the current matrix by setting their
11994 enabled_p flag to zero. */
11995 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11996 if (display_line (&it
))
11997 last_text_row_at_end
= it
.glyph_row
- 1;
12001 /* Update window_end_pos and window_end_vpos. */
12002 if (first_unchanged_at_end_row
12003 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12004 && !last_text_row_at_end
)
12006 /* Window end line if one of the preserved rows from the current
12007 matrix. Set row to the last row displaying text in current
12008 matrix starting at first_unchanged_at_end_row, after
12010 xassert (first_unchanged_at_end_row
->displays_text_p
);
12011 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12012 first_unchanged_at_end_row
);
12013 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12015 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12016 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12018 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12019 xassert (w
->window_end_bytepos
>= 0);
12020 IF_DEBUG (debug_method_add (w
, "A"));
12022 else if (last_text_row_at_end
)
12025 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12026 w
->window_end_bytepos
12027 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12029 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12030 xassert (w
->window_end_bytepos
>= 0);
12031 IF_DEBUG (debug_method_add (w
, "B"));
12033 else if (last_text_row
)
12035 /* We have displayed either to the end of the window or at the
12036 end of the window, i.e. the last row with text is to be found
12037 in the desired matrix. */
12039 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12040 w
->window_end_bytepos
12041 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12043 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12044 xassert (w
->window_end_bytepos
>= 0);
12046 else if (first_unchanged_at_end_row
== NULL
12047 && last_text_row
== NULL
12048 && last_text_row_at_end
== NULL
)
12050 /* Displayed to end of window, but no line containing text was
12051 displayed. Lines were deleted at the end of the window. */
12052 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12053 int vpos
= XFASTINT (w
->window_end_vpos
);
12054 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12055 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12058 row
== NULL
&& vpos
>= first_vpos
;
12059 --vpos
, --current_row
, --desired_row
)
12061 if (desired_row
->enabled_p
)
12063 if (desired_row
->displays_text_p
)
12066 else if (current_row
->displays_text_p
)
12070 xassert (row
!= NULL
);
12071 w
->window_end_vpos
= make_number (vpos
+ 1);
12072 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12073 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12074 xassert (w
->window_end_bytepos
>= 0);
12075 IF_DEBUG (debug_method_add (w
, "C"));
12080 #if 0 /* This leads to problems, for instance when the cursor is
12081 at ZV, and the cursor line displays no text. */
12082 /* Disable rows below what's displayed in the window. This makes
12083 debugging easier. */
12084 enable_glyph_matrix_rows (current_matrix
,
12085 XFASTINT (w
->window_end_vpos
) + 1,
12089 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12090 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12092 /* Record that display has not been completed. */
12093 w
->window_end_valid
= Qnil
;
12094 w
->desired_matrix
->no_scrolling_p
= 1;
12102 /***********************************************************************
12103 More debugging support
12104 ***********************************************************************/
12108 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12109 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12110 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12113 /* Dump the contents of glyph matrix MATRIX on stderr.
12115 GLYPHS 0 means don't show glyph contents.
12116 GLYPHS 1 means show glyphs in short form
12117 GLYPHS > 1 means show glyphs in long form. */
12120 dump_glyph_matrix (matrix
, glyphs
)
12121 struct glyph_matrix
*matrix
;
12125 for (i
= 0; i
< matrix
->nrows
; ++i
)
12126 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12130 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12131 the glyph row and area where the glyph comes from. */
12134 dump_glyph (row
, glyph
, area
)
12135 struct glyph_row
*row
;
12136 struct glyph
*glyph
;
12139 if (glyph
->type
== CHAR_GLYPH
)
12142 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12143 glyph
- row
->glyphs
[TEXT_AREA
],
12146 (BUFFERP (glyph
->object
)
12148 : (STRINGP (glyph
->object
)
12151 glyph
->pixel_width
,
12153 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12157 glyph
->left_box_line_p
,
12158 glyph
->right_box_line_p
);
12160 else if (glyph
->type
== STRETCH_GLYPH
)
12163 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12164 glyph
- row
->glyphs
[TEXT_AREA
],
12167 (BUFFERP (glyph
->object
)
12169 : (STRINGP (glyph
->object
)
12172 glyph
->pixel_width
,
12176 glyph
->left_box_line_p
,
12177 glyph
->right_box_line_p
);
12179 else if (glyph
->type
== IMAGE_GLYPH
)
12182 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12183 glyph
- row
->glyphs
[TEXT_AREA
],
12186 (BUFFERP (glyph
->object
)
12188 : (STRINGP (glyph
->object
)
12191 glyph
->pixel_width
,
12195 glyph
->left_box_line_p
,
12196 glyph
->right_box_line_p
);
12201 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12202 GLYPHS 0 means don't show glyph contents.
12203 GLYPHS 1 means show glyphs in short form
12204 GLYPHS > 1 means show glyphs in long form. */
12207 dump_glyph_row (row
, vpos
, glyphs
)
12208 struct glyph_row
*row
;
12213 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12214 fprintf (stderr
, "=======================================================================\n");
12216 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12217 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12219 MATRIX_ROW_START_CHARPOS (row
),
12220 MATRIX_ROW_END_CHARPOS (row
),
12221 row
->used
[TEXT_AREA
],
12222 row
->contains_overlapping_glyphs_p
,
12224 row
->truncated_on_left_p
,
12225 row
->truncated_on_right_p
,
12226 row
->overlay_arrow_p
,
12228 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12229 row
->displays_text_p
,
12232 row
->ends_in_middle_of_char_p
,
12233 row
->starts_in_middle_of_char_p
,
12239 row
->visible_height
,
12242 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12243 row
->end
.overlay_string_index
,
12244 row
->continuation_lines_width
);
12245 fprintf (stderr
, "%9d %5d\n",
12246 CHARPOS (row
->start
.string_pos
),
12247 CHARPOS (row
->end
.string_pos
));
12248 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12249 row
->end
.dpvec_index
);
12256 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12258 struct glyph
*glyph
= row
->glyphs
[area
];
12259 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12261 /* Glyph for a line end in text. */
12262 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12265 if (glyph
< glyph_end
)
12266 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12268 for (; glyph
< glyph_end
; ++glyph
)
12269 dump_glyph (row
, glyph
, area
);
12272 else if (glyphs
== 1)
12276 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12278 char *s
= (char *) alloca (row
->used
[area
] + 1);
12281 for (i
= 0; i
< row
->used
[area
]; ++i
)
12283 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12284 if (glyph
->type
== CHAR_GLYPH
12285 && glyph
->u
.ch
< 0x80
12286 && glyph
->u
.ch
>= ' ')
12287 s
[i
] = glyph
->u
.ch
;
12293 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12299 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12300 Sdump_glyph_matrix
, 0, 1, "p",
12301 doc
: /* Dump the current matrix of the selected window to stderr.
12302 Shows contents of glyph row structures. With non-nil
12303 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12304 glyphs in short form, otherwise show glyphs in long form. */)
12306 Lisp_Object glyphs
;
12308 struct window
*w
= XWINDOW (selected_window
);
12309 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12311 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12312 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12313 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12314 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12315 fprintf (stderr
, "=============================================\n");
12316 dump_glyph_matrix (w
->current_matrix
,
12317 NILP (glyphs
) ? 0 : XINT (glyphs
));
12322 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12323 doc
: /* Dump glyph row ROW to stderr.
12324 GLYPH 0 means don't dump glyphs.
12325 GLYPH 1 means dump glyphs in short form.
12326 GLYPH > 1 or omitted means dump glyphs in long form. */)
12328 Lisp_Object row
, glyphs
;
12330 struct glyph_matrix
*matrix
;
12333 CHECK_NUMBER (row
);
12334 matrix
= XWINDOW (selected_window
)->current_matrix
;
12336 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12337 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12339 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12344 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12345 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12346 GLYPH 0 means don't dump glyphs.
12347 GLYPH 1 means dump glyphs in short form.
12348 GLYPH > 1 or omitted means dump glyphs in long form. */)
12350 Lisp_Object row
, glyphs
;
12352 struct frame
*sf
= SELECTED_FRAME ();
12353 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12356 CHECK_NUMBER (row
);
12358 if (vpos
>= 0 && vpos
< m
->nrows
)
12359 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12360 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12365 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12366 doc
: /* Toggle tracing of redisplay.
12367 With ARG, turn tracing on if and only if ARG is positive. */)
12372 trace_redisplay_p
= !trace_redisplay_p
;
12375 arg
= Fprefix_numeric_value (arg
);
12376 trace_redisplay_p
= XINT (arg
) > 0;
12383 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
12384 doc
: /* Like `format', but print result to stderr. */)
12389 Lisp_Object s
= Fformat (nargs
, args
);
12390 fprintf (stderr
, "%s", XSTRING (s
)->data
);
12394 #endif /* GLYPH_DEBUG */
12398 /***********************************************************************
12399 Building Desired Matrix Rows
12400 ***********************************************************************/
12402 /* Return a temporary glyph row holding the glyphs of an overlay
12403 arrow. Only used for non-window-redisplay windows. */
12405 static struct glyph_row
*
12406 get_overlay_arrow_glyph_row (w
)
12409 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12410 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12411 struct buffer
*old
= current_buffer
;
12412 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
12413 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
12414 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
12418 int n_glyphs_before
;
12420 set_buffer_temp (buffer
);
12421 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
12422 it
.glyph_row
->used
[TEXT_AREA
] = 0;
12423 SET_TEXT_POS (it
.position
, 0, 0);
12425 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
12427 while (p
< arrow_end
)
12429 Lisp_Object face
, ilisp
;
12431 /* Get the next character. */
12433 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
12435 it
.c
= *p
, it
.len
= 1;
12438 /* Get its face. */
12439 ilisp
= make_number (p
- arrow_string
);
12440 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
12441 it
.face_id
= compute_char_face (f
, it
.c
, face
);
12443 /* Compute its width, get its glyphs. */
12444 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
12445 SET_TEXT_POS (it
.position
, -1, -1);
12446 PRODUCE_GLYPHS (&it
);
12448 /* If this character doesn't fit any more in the line, we have
12449 to remove some glyphs. */
12450 if (it
.current_x
> it
.last_visible_x
)
12452 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
12457 set_buffer_temp (old
);
12458 return it
.glyph_row
;
12462 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
12463 glyphs are only inserted for terminal frames since we can't really
12464 win with truncation glyphs when partially visible glyphs are
12465 involved. Which glyphs to insert is determined by
12466 produce_special_glyphs. */
12469 insert_left_trunc_glyphs (it
)
12472 struct it truncate_it
;
12473 struct glyph
*from
, *end
, *to
, *toend
;
12475 xassert (!FRAME_WINDOW_P (it
->f
));
12477 /* Get the truncation glyphs. */
12479 truncate_it
.current_x
= 0;
12480 truncate_it
.face_id
= DEFAULT_FACE_ID
;
12481 truncate_it
.glyph_row
= &scratch_glyph_row
;
12482 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
12483 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
12484 truncate_it
.object
= make_number (0);
12485 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
12487 /* Overwrite glyphs from IT with truncation glyphs. */
12488 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12489 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
12490 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
12491 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
12496 /* There may be padding glyphs left over. Overwrite them too. */
12497 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
12499 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
12505 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
12509 /* Compute the pixel height and width of IT->glyph_row.
12511 Most of the time, ascent and height of a display line will be equal
12512 to the max_ascent and max_height values of the display iterator
12513 structure. This is not the case if
12515 1. We hit ZV without displaying anything. In this case, max_ascent
12516 and max_height will be zero.
12518 2. We have some glyphs that don't contribute to the line height.
12519 (The glyph row flag contributes_to_line_height_p is for future
12520 pixmap extensions).
12522 The first case is easily covered by using default values because in
12523 these cases, the line height does not really matter, except that it
12524 must not be zero. */
12527 compute_line_metrics (it
)
12530 struct glyph_row
*row
= it
->glyph_row
;
12533 if (FRAME_WINDOW_P (it
->f
))
12535 int i
, min_y
, max_y
;
12537 /* The line may consist of one space only, that was added to
12538 place the cursor on it. If so, the row's height hasn't been
12540 if (row
->height
== 0)
12542 if (it
->max_ascent
+ it
->max_descent
== 0)
12543 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
12544 row
->ascent
= it
->max_ascent
;
12545 row
->height
= it
->max_ascent
+ it
->max_descent
;
12546 row
->phys_ascent
= it
->max_phys_ascent
;
12547 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12550 /* Compute the width of this line. */
12551 row
->pixel_width
= row
->x
;
12552 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
12553 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12555 xassert (row
->pixel_width
>= 0);
12556 xassert (row
->ascent
>= 0 && row
->height
> 0);
12558 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
12559 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
12561 /* If first line's physical ascent is larger than its logical
12562 ascent, use the physical ascent, and make the row taller.
12563 This makes accented characters fully visible. */
12564 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
12565 && row
->phys_ascent
> row
->ascent
)
12567 row
->height
+= row
->phys_ascent
- row
->ascent
;
12568 row
->ascent
= row
->phys_ascent
;
12571 /* Compute how much of the line is visible. */
12572 row
->visible_height
= row
->height
;
12574 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
12575 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
12577 if (row
->y
< min_y
)
12578 row
->visible_height
-= min_y
- row
->y
;
12579 if (row
->y
+ row
->height
> max_y
)
12580 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12584 row
->pixel_width
= row
->used
[TEXT_AREA
];
12585 if (row
->continued_p
)
12586 row
->pixel_width
-= it
->continuation_pixel_width
;
12587 else if (row
->truncated_on_right_p
)
12588 row
->pixel_width
-= it
->truncation_pixel_width
;
12589 row
->ascent
= row
->phys_ascent
= 0;
12590 row
->height
= row
->phys_height
= row
->visible_height
= 1;
12593 /* Compute a hash code for this row. */
12595 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12596 for (i
= 0; i
< row
->used
[area
]; ++i
)
12597 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
12598 + row
->glyphs
[area
][i
].u
.val
12599 + row
->glyphs
[area
][i
].face_id
12600 + row
->glyphs
[area
][i
].padding_p
12601 + (row
->glyphs
[area
][i
].type
<< 2));
12603 it
->max_ascent
= it
->max_descent
= 0;
12604 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
12608 /* Append one space to the glyph row of iterator IT if doing a
12609 window-based redisplay. DEFAULT_FACE_P non-zero means let the
12610 space have the default face, otherwise let it have the same face as
12611 IT->face_id. Value is non-zero if a space was added.
12613 This function is called to make sure that there is always one glyph
12614 at the end of a glyph row that the cursor can be set on under
12615 window-systems. (If there weren't such a glyph we would not know
12616 how wide and tall a box cursor should be displayed).
12618 At the same time this space let's a nicely handle clearing to the
12619 end of the line if the row ends in italic text. */
12622 append_space (it
, default_face_p
)
12624 int default_face_p
;
12626 if (FRAME_WINDOW_P (it
->f
))
12628 int n
= it
->glyph_row
->used
[TEXT_AREA
];
12630 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
12631 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
12633 /* Save some values that must not be changed.
12634 Must save IT->c and IT->len because otherwise
12635 ITERATOR_AT_END_P wouldn't work anymore after
12636 append_space has been called. */
12637 enum display_element_type saved_what
= it
->what
;
12638 int saved_c
= it
->c
, saved_len
= it
->len
;
12639 int saved_x
= it
->current_x
;
12640 int saved_face_id
= it
->face_id
;
12641 struct text_pos saved_pos
;
12642 Lisp_Object saved_object
;
12645 saved_object
= it
->object
;
12646 saved_pos
= it
->position
;
12648 it
->what
= IT_CHARACTER
;
12649 bzero (&it
->position
, sizeof it
->position
);
12650 it
->object
= make_number (0);
12654 if (default_face_p
)
12655 it
->face_id
= DEFAULT_FACE_ID
;
12656 else if (it
->face_before_selective_p
)
12657 it
->face_id
= it
->saved_face_id
;
12658 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12659 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
12661 PRODUCE_GLYPHS (it
);
12663 it
->current_x
= saved_x
;
12664 it
->object
= saved_object
;
12665 it
->position
= saved_pos
;
12666 it
->what
= saved_what
;
12667 it
->face_id
= saved_face_id
;
12668 it
->len
= saved_len
;
12678 /* Extend the face of the last glyph in the text area of IT->glyph_row
12679 to the end of the display line. Called from display_line.
12680 If the glyph row is empty, add a space glyph to it so that we
12681 know the face to draw. Set the glyph row flag fill_line_p. */
12684 extend_face_to_end_of_line (it
)
12688 struct frame
*f
= it
->f
;
12690 /* If line is already filled, do nothing. */
12691 if (it
->current_x
>= it
->last_visible_x
)
12694 /* Face extension extends the background and box of IT->face_id
12695 to the end of the line. If the background equals the background
12696 of the frame, we don't have to do anything. */
12697 if (it
->face_before_selective_p
)
12698 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
12700 face
= FACE_FROM_ID (f
, it
->face_id
);
12702 if (FRAME_WINDOW_P (f
)
12703 && face
->box
== FACE_NO_BOX
12704 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
12708 /* Set the glyph row flag indicating that the face of the last glyph
12709 in the text area has to be drawn to the end of the text area. */
12710 it
->glyph_row
->fill_line_p
= 1;
12712 /* If current character of IT is not ASCII, make sure we have the
12713 ASCII face. This will be automatically undone the next time
12714 get_next_display_element returns a multibyte character. Note
12715 that the character will always be single byte in unibyte text. */
12716 if (!SINGLE_BYTE_CHAR_P (it
->c
))
12718 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
12721 if (FRAME_WINDOW_P (f
))
12723 /* If the row is empty, add a space with the current face of IT,
12724 so that we know which face to draw. */
12725 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
12727 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
12728 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
12729 it
->glyph_row
->used
[TEXT_AREA
] = 1;
12734 /* Save some values that must not be changed. */
12735 int saved_x
= it
->current_x
;
12736 struct text_pos saved_pos
;
12737 Lisp_Object saved_object
;
12738 enum display_element_type saved_what
= it
->what
;
12739 int saved_face_id
= it
->face_id
;
12741 saved_object
= it
->object
;
12742 saved_pos
= it
->position
;
12744 it
->what
= IT_CHARACTER
;
12745 bzero (&it
->position
, sizeof it
->position
);
12746 it
->object
= make_number (0);
12749 it
->face_id
= face
->id
;
12751 PRODUCE_GLYPHS (it
);
12753 while (it
->current_x
<= it
->last_visible_x
)
12754 PRODUCE_GLYPHS (it
);
12756 /* Don't count these blanks really. It would let us insert a left
12757 truncation glyph below and make us set the cursor on them, maybe. */
12758 it
->current_x
= saved_x
;
12759 it
->object
= saved_object
;
12760 it
->position
= saved_pos
;
12761 it
->what
= saved_what
;
12762 it
->face_id
= saved_face_id
;
12767 /* Value is non-zero if text starting at CHARPOS in current_buffer is
12768 trailing whitespace. */
12771 trailing_whitespace_p (charpos
)
12774 int bytepos
= CHAR_TO_BYTE (charpos
);
12777 while (bytepos
< ZV_BYTE
12778 && (c
= FETCH_CHAR (bytepos
),
12779 c
== ' ' || c
== '\t'))
12782 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
12784 if (bytepos
!= PT_BYTE
)
12791 /* Highlight trailing whitespace, if any, in ROW. */
12794 highlight_trailing_whitespace (f
, row
)
12796 struct glyph_row
*row
;
12798 int used
= row
->used
[TEXT_AREA
];
12802 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
12803 struct glyph
*glyph
= start
+ used
- 1;
12805 /* Skip over glyphs inserted to display the cursor at the
12806 end of a line, for extending the face of the last glyph
12807 to the end of the line on terminals, and for truncation
12808 and continuation glyphs. */
12809 while (glyph
>= start
12810 && glyph
->type
== CHAR_GLYPH
12811 && INTEGERP (glyph
->object
))
12814 /* If last glyph is a space or stretch, and it's trailing
12815 whitespace, set the face of all trailing whitespace glyphs in
12816 IT->glyph_row to `trailing-whitespace'. */
12818 && BUFFERP (glyph
->object
)
12819 && (glyph
->type
== STRETCH_GLYPH
12820 || (glyph
->type
== CHAR_GLYPH
12821 && glyph
->u
.ch
== ' '))
12822 && trailing_whitespace_p (glyph
->charpos
))
12824 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
12826 while (glyph
>= start
12827 && BUFFERP (glyph
->object
)
12828 && (glyph
->type
== STRETCH_GLYPH
12829 || (glyph
->type
== CHAR_GLYPH
12830 && glyph
->u
.ch
== ' ')))
12831 (glyph
--)->face_id
= face_id
;
12837 /* Value is non-zero if glyph row ROW in window W should be
12838 used to hold the cursor. */
12841 cursor_row_p (w
, row
)
12843 struct glyph_row
*row
;
12845 int cursor_row_p
= 1;
12847 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
12849 /* If the row ends with a newline from a string, we don't want
12850 the cursor there (if the row is continued it doesn't end in a
12852 if (CHARPOS (row
->end
.string_pos
) >= 0
12853 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12854 cursor_row_p
= row
->continued_p
;
12856 /* If the row ends at ZV, display the cursor at the end of that
12857 row instead of at the start of the row below. */
12858 else if (row
->ends_at_zv_p
)
12864 return cursor_row_p
;
12868 /* Construct the glyph row IT->glyph_row in the desired matrix of
12869 IT->w from text at the current position of IT. See dispextern.h
12870 for an overview of struct it. Value is non-zero if
12871 IT->glyph_row displays text, as opposed to a line displaying ZV
12878 struct glyph_row
*row
= it
->glyph_row
;
12880 /* We always start displaying at hpos zero even if hscrolled. */
12881 xassert (it
->hpos
== 0 && it
->current_x
== 0);
12883 /* We must not display in a row that's not a text row. */
12884 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
12885 < it
->w
->desired_matrix
->nrows
);
12887 /* Is IT->w showing the region? */
12888 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
12890 /* Clear the result glyph row and enable it. */
12891 prepare_desired_row (row
);
12893 row
->y
= it
->current_y
;
12894 row
->start
= it
->current
;
12895 row
->continuation_lines_width
= it
->continuation_lines_width
;
12896 row
->displays_text_p
= 1;
12897 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
12898 it
->starts_in_middle_of_char_p
= 0;
12900 /* Arrange the overlays nicely for our purposes. Usually, we call
12901 display_line on only one line at a time, in which case this
12902 can't really hurt too much, or we call it on lines which appear
12903 one after another in the buffer, in which case all calls to
12904 recenter_overlay_lists but the first will be pretty cheap. */
12905 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12907 /* Move over display elements that are not visible because we are
12908 hscrolled. This may stop at an x-position < IT->first_visible_x
12909 if the first glyph is partially visible or if we hit a line end. */
12910 if (it
->current_x
< it
->first_visible_x
)
12911 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12912 MOVE_TO_POS
| MOVE_TO_X
);
12914 /* Get the initial row height. This is either the height of the
12915 text hscrolled, if there is any, or zero. */
12916 row
->ascent
= it
->max_ascent
;
12917 row
->height
= it
->max_ascent
+ it
->max_descent
;
12918 row
->phys_ascent
= it
->max_phys_ascent
;
12919 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12921 /* Loop generating characters. The loop is left with IT on the next
12922 character to display. */
12925 int n_glyphs_before
, hpos_before
, x_before
;
12927 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12929 /* Retrieve the next thing to display. Value is zero if end of
12931 if (!get_next_display_element (it
))
12933 /* Maybe add a space at the end of this line that is used to
12934 display the cursor there under X. Set the charpos of the
12935 first glyph of blank lines not corresponding to any text
12937 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12938 || row
->used
[TEXT_AREA
] == 0)
12940 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12941 row
->displays_text_p
= 0;
12943 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
12944 && (!MINI_WINDOW_P (it
->w
)
12945 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
12946 row
->indicate_empty_line_p
= 1;
12949 it
->continuation_lines_width
= 0;
12950 row
->ends_at_zv_p
= 1;
12954 /* Now, get the metrics of what we want to display. This also
12955 generates glyphs in `row' (which is IT->glyph_row). */
12956 n_glyphs_before
= row
->used
[TEXT_AREA
];
12959 /* Remember the line height so far in case the next element doesn't
12960 fit on the line. */
12961 if (!it
->truncate_lines_p
)
12963 ascent
= it
->max_ascent
;
12964 descent
= it
->max_descent
;
12965 phys_ascent
= it
->max_phys_ascent
;
12966 phys_descent
= it
->max_phys_descent
;
12969 PRODUCE_GLYPHS (it
);
12971 /* If this display element was in marginal areas, continue with
12973 if (it
->area
!= TEXT_AREA
)
12975 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12976 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12977 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12978 row
->phys_height
= max (row
->phys_height
,
12979 it
->max_phys_ascent
+ it
->max_phys_descent
);
12980 set_iterator_to_next (it
, 1);
12984 /* Does the display element fit on the line? If we truncate
12985 lines, we should draw past the right edge of the window. If
12986 we don't truncate, we want to stop so that we can display the
12987 continuation glyph before the right margin. If lines are
12988 continued, there are two possible strategies for characters
12989 resulting in more than 1 glyph (e.g. tabs): Display as many
12990 glyphs as possible in this line and leave the rest for the
12991 continuation line, or display the whole element in the next
12992 line. Original redisplay did the former, so we do it also. */
12993 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12994 hpos_before
= it
->hpos
;
12997 if (/* Not a newline. */
12999 /* Glyphs produced fit entirely in the line. */
13000 && it
->current_x
< it
->last_visible_x
)
13002 it
->hpos
+= nglyphs
;
13003 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13004 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13005 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13006 row
->phys_height
= max (row
->phys_height
,
13007 it
->max_phys_ascent
+ it
->max_phys_descent
);
13008 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13009 row
->x
= x
- it
->first_visible_x
;
13014 struct glyph
*glyph
;
13016 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13018 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13019 new_x
= x
+ glyph
->pixel_width
;
13021 if (/* Lines are continued. */
13022 !it
->truncate_lines_p
13023 && (/* Glyph doesn't fit on the line. */
13024 new_x
> it
->last_visible_x
13025 /* Or it fits exactly on a window system frame. */
13026 || (new_x
== it
->last_visible_x
13027 && FRAME_WINDOW_P (it
->f
))))
13029 /* End of a continued line. */
13032 || (new_x
== it
->last_visible_x
13033 && FRAME_WINDOW_P (it
->f
)))
13035 /* Current glyph is the only one on the line or
13036 fits exactly on the line. We must continue
13037 the line because we can't draw the cursor
13038 after the glyph. */
13039 row
->continued_p
= 1;
13040 it
->current_x
= new_x
;
13041 it
->continuation_lines_width
+= new_x
;
13043 if (i
== nglyphs
- 1)
13044 set_iterator_to_next (it
, 1);
13046 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13047 && !FRAME_WINDOW_P (it
->f
))
13049 /* A padding glyph that doesn't fit on this line.
13050 This means the whole character doesn't fit
13052 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13054 /* Fill the rest of the row with continuation
13055 glyphs like in 20.x. */
13056 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13057 < row
->glyphs
[1 + TEXT_AREA
])
13058 produce_special_glyphs (it
, IT_CONTINUATION
);
13060 row
->continued_p
= 1;
13061 it
->current_x
= x_before
;
13062 it
->continuation_lines_width
+= x_before
;
13064 /* Restore the height to what it was before the
13065 element not fitting on the line. */
13066 it
->max_ascent
= ascent
;
13067 it
->max_descent
= descent
;
13068 it
->max_phys_ascent
= phys_ascent
;
13069 it
->max_phys_descent
= phys_descent
;
13071 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13073 /* A TAB that extends past the right edge of the
13074 window. This produces a single glyph on
13075 window system frames. We leave the glyph in
13076 this row and let it fill the row, but don't
13077 consume the TAB. */
13078 it
->continuation_lines_width
+= it
->last_visible_x
;
13079 row
->ends_in_middle_of_char_p
= 1;
13080 row
->continued_p
= 1;
13081 glyph
->pixel_width
= it
->last_visible_x
- x
;
13082 it
->starts_in_middle_of_char_p
= 1;
13086 /* Something other than a TAB that draws past
13087 the right edge of the window. Restore
13088 positions to values before the element. */
13089 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13091 /* Display continuation glyphs. */
13092 if (!FRAME_WINDOW_P (it
->f
))
13093 produce_special_glyphs (it
, IT_CONTINUATION
);
13094 row
->continued_p
= 1;
13096 it
->continuation_lines_width
+= x
;
13098 if (nglyphs
> 1 && i
> 0)
13100 row
->ends_in_middle_of_char_p
= 1;
13101 it
->starts_in_middle_of_char_p
= 1;
13104 /* Restore the height to what it was before the
13105 element not fitting on the line. */
13106 it
->max_ascent
= ascent
;
13107 it
->max_descent
= descent
;
13108 it
->max_phys_ascent
= phys_ascent
;
13109 it
->max_phys_descent
= phys_descent
;
13114 else if (new_x
> it
->first_visible_x
)
13116 /* Increment number of glyphs actually displayed. */
13119 if (x
< it
->first_visible_x
)
13120 /* Glyph is partially visible, i.e. row starts at
13121 negative X position. */
13122 row
->x
= x
- it
->first_visible_x
;
13126 /* Glyph is completely off the left margin of the
13127 window. This should not happen because of the
13128 move_it_in_display_line at the start of
13134 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13135 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13136 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13137 row
->phys_height
= max (row
->phys_height
,
13138 it
->max_phys_ascent
+ it
->max_phys_descent
);
13140 /* End of this display line if row is continued. */
13141 if (row
->continued_p
)
13145 /* Is this a line end? If yes, we're also done, after making
13146 sure that a non-default face is extended up to the right
13147 margin of the window. */
13148 if (ITERATOR_AT_END_OF_LINE_P (it
))
13150 int used_before
= row
->used
[TEXT_AREA
];
13152 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13154 /* Add a space at the end of the line that is used to
13155 display the cursor there. */
13156 append_space (it
, 0);
13158 /* Extend the face to the end of the line. */
13159 extend_face_to_end_of_line (it
);
13161 /* Make sure we have the position. */
13162 if (used_before
== 0)
13163 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13165 /* Consume the line end. This skips over invisible lines. */
13166 set_iterator_to_next (it
, 1);
13167 it
->continuation_lines_width
= 0;
13171 /* Proceed with next display element. Note that this skips
13172 over lines invisible because of selective display. */
13173 set_iterator_to_next (it
, 1);
13175 /* If we truncate lines, we are done when the last displayed
13176 glyphs reach past the right margin of the window. */
13177 if (it
->truncate_lines_p
13178 && (FRAME_WINDOW_P (it
->f
)
13179 ? (it
->current_x
>= it
->last_visible_x
)
13180 : (it
->current_x
> it
->last_visible_x
)))
13182 /* Maybe add truncation glyphs. */
13183 if (!FRAME_WINDOW_P (it
->f
))
13187 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13188 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13191 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13193 row
->used
[TEXT_AREA
] = i
;
13194 produce_special_glyphs (it
, IT_TRUNCATION
);
13198 row
->truncated_on_right_p
= 1;
13199 it
->continuation_lines_width
= 0;
13200 reseat_at_next_visible_line_start (it
, 0);
13201 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13202 it
->hpos
= hpos_before
;
13203 it
->current_x
= x_before
;
13208 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13209 at the left window margin. */
13210 if (it
->first_visible_x
13211 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13213 if (!FRAME_WINDOW_P (it
->f
))
13214 insert_left_trunc_glyphs (it
);
13215 row
->truncated_on_left_p
= 1;
13218 /* If the start of this line is the overlay arrow-position, then
13219 mark this glyph row as the one containing the overlay arrow.
13220 This is clearly a mess with variable size fonts. It would be
13221 better to let it be displayed like cursors under X. */
13222 if (MARKERP (Voverlay_arrow_position
)
13223 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13224 && (MATRIX_ROW_START_CHARPOS (row
)
13225 == marker_position (Voverlay_arrow_position
))
13226 && STRINGP (Voverlay_arrow_string
)
13227 && ! overlay_arrow_seen
)
13229 /* Overlay arrow in window redisplay is a fringe bitmap. */
13230 if (!FRAME_WINDOW_P (it
->f
))
13232 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13233 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13234 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13235 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13236 struct glyph
*p2
, *end
;
13238 /* Copy the arrow glyphs. */
13239 while (glyph
< arrow_end
)
13242 /* Throw away padding glyphs. */
13244 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13245 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13251 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13255 overlay_arrow_seen
= 1;
13256 row
->overlay_arrow_p
= 1;
13259 /* Compute pixel dimensions of this line. */
13260 compute_line_metrics (it
);
13262 /* Remember the position at which this line ends. */
13263 row
->end
= it
->current
;
13265 /* Maybe set the cursor. */
13266 if (it
->w
->cursor
.vpos
< 0
13267 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13268 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13269 && cursor_row_p (it
->w
, row
))
13270 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13272 /* Highlight trailing whitespace. */
13273 if (!NILP (Vshow_trailing_whitespace
))
13274 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13276 /* Prepare for the next line. This line starts horizontally at (X
13277 HPOS) = (0 0). Vertical positions are incremented. As a
13278 convenience for the caller, IT->glyph_row is set to the next
13280 it
->current_x
= it
->hpos
= 0;
13281 it
->current_y
+= row
->height
;
13284 return row
->displays_text_p
;
13289 /***********************************************************************
13291 ***********************************************************************/
13293 /* Redisplay the menu bar in the frame for window W.
13295 The menu bar of X frames that don't have X toolkit support is
13296 displayed in a special window W->frame->menu_bar_window.
13298 The menu bar of terminal frames is treated specially as far as
13299 glyph matrices are concerned. Menu bar lines are not part of
13300 windows, so the update is done directly on the frame matrix rows
13301 for the menu bar. */
13304 display_menu_bar (w
)
13307 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13312 /* Don't do all this for graphical frames. */
13314 if (!NILP (Vwindow_system
))
13317 #ifdef USE_X_TOOLKIT
13322 if (FRAME_MAC_P (f
))
13326 #ifdef USE_X_TOOLKIT
13327 xassert (!FRAME_WINDOW_P (f
));
13328 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13329 it
.first_visible_x
= 0;
13330 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13331 #else /* not USE_X_TOOLKIT */
13332 if (FRAME_WINDOW_P (f
))
13334 /* Menu bar lines are displayed in the desired matrix of the
13335 dummy window menu_bar_window. */
13336 struct window
*menu_w
;
13337 xassert (WINDOWP (f
->menu_bar_window
));
13338 menu_w
= XWINDOW (f
->menu_bar_window
);
13339 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13341 it
.first_visible_x
= 0;
13342 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13346 /* This is a TTY frame, i.e. character hpos/vpos are used as
13348 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13350 it
.first_visible_x
= 0;
13351 it
.last_visible_x
= FRAME_WIDTH (f
);
13353 #endif /* not USE_X_TOOLKIT */
13355 if (! mode_line_inverse_video
)
13356 /* Force the menu-bar to be displayed in the default face. */
13357 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13359 /* Clear all rows of the menu bar. */
13360 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13362 struct glyph_row
*row
= it
.glyph_row
+ i
;
13363 clear_glyph_row (row
);
13364 row
->enabled_p
= 1;
13365 row
->full_width_p
= 1;
13368 /* Display all items of the menu bar. */
13369 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13370 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13372 Lisp_Object string
;
13374 /* Stop at nil string. */
13375 string
= AREF (items
, i
+ 1);
13379 /* Remember where item was displayed. */
13380 AREF (items
, i
+ 3) = make_number (it
.hpos
);
13382 /* Display the item, pad with one space. */
13383 if (it
.current_x
< it
.last_visible_x
)
13384 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
13385 XSTRING (string
)->size
+ 1, 0, 0, -1);
13388 /* Fill out the line with spaces. */
13389 if (it
.current_x
< it
.last_visible_x
)
13390 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
13392 /* Compute the total height of the lines. */
13393 compute_line_metrics (&it
);
13398 /***********************************************************************
13400 ***********************************************************************/
13402 /* Redisplay mode lines in the window tree whose root is WINDOW. If
13403 FORCE is non-zero, redisplay mode lines unconditionally.
13404 Otherwise, redisplay only mode lines that are garbaged. Value is
13405 the number of windows whose mode lines were redisplayed. */
13408 redisplay_mode_lines (window
, force
)
13409 Lisp_Object window
;
13414 while (!NILP (window
))
13416 struct window
*w
= XWINDOW (window
);
13418 if (WINDOWP (w
->hchild
))
13419 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
13420 else if (WINDOWP (w
->vchild
))
13421 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
13423 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
13424 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
13426 struct text_pos lpoint
;
13427 struct buffer
*old
= current_buffer
;
13429 /* Set the window's buffer for the mode line display. */
13430 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13431 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13433 /* Point refers normally to the selected window. For any
13434 other window, set up appropriate value. */
13435 if (!EQ (window
, selected_window
))
13437 struct text_pos pt
;
13439 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
13440 if (CHARPOS (pt
) < BEGV
)
13441 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13442 else if (CHARPOS (pt
) > (ZV
- 1))
13443 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
13445 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
13448 /* Display mode lines. */
13449 clear_glyph_matrix (w
->desired_matrix
);
13450 if (display_mode_lines (w
))
13453 w
->must_be_updated_p
= 1;
13456 /* Restore old settings. */
13457 set_buffer_internal_1 (old
);
13458 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13468 /* Display the mode and/or top line of window W. Value is the number
13469 of mode lines displayed. */
13472 display_mode_lines (w
)
13475 Lisp_Object old_selected_window
, old_selected_frame
;
13478 old_selected_frame
= selected_frame
;
13479 selected_frame
= w
->frame
;
13480 old_selected_window
= selected_window
;
13481 XSETWINDOW (selected_window
, w
);
13483 /* These will be set while the mode line specs are processed. */
13484 line_number_displayed
= 0;
13485 w
->column_number_displayed
= Qnil
;
13487 if (WINDOW_WANTS_MODELINE_P (w
))
13489 struct window
*sel_w
= XWINDOW (old_selected_window
);
13491 /* Select mode line face based on the real selected window. */
13492 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
13493 current_buffer
->mode_line_format
);
13497 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13499 display_mode_line (w
, HEADER_LINE_FACE_ID
,
13500 current_buffer
->header_line_format
);
13504 selected_frame
= old_selected_frame
;
13505 selected_window
= old_selected_window
;
13510 /* Display mode or top line of window W. FACE_ID specifies which line
13511 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
13512 FORMAT is the mode line format to display. Value is the pixel
13513 height of the mode line displayed. */
13516 display_mode_line (w
, face_id
, format
)
13518 enum face_id face_id
;
13519 Lisp_Object format
;
13524 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
13525 prepare_desired_row (it
.glyph_row
);
13527 if (! mode_line_inverse_video
)
13528 /* Force the mode-line to be displayed in the default face. */
13529 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13531 /* Temporarily make frame's keyboard the current kboard so that
13532 kboard-local variables in the mode_line_format will get the right
13534 push_frame_kboard (it
.f
);
13535 display_mode_element (&it
, 0, 0, 0, format
, Qnil
);
13536 pop_frame_kboard ();
13538 /* Fill up with spaces. */
13539 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
13541 compute_line_metrics (&it
);
13542 it
.glyph_row
->full_width_p
= 1;
13543 it
.glyph_row
->mode_line_p
= 1;
13544 it
.glyph_row
->continued_p
= 0;
13545 it
.glyph_row
->truncated_on_left_p
= 0;
13546 it
.glyph_row
->truncated_on_right_p
= 0;
13548 /* Make a 3D mode-line have a shadow at its right end. */
13549 face
= FACE_FROM_ID (it
.f
, face_id
);
13550 extend_face_to_end_of_line (&it
);
13551 if (face
->box
!= FACE_NO_BOX
)
13553 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
13554 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
13555 last
->right_box_line_p
= 1;
13558 return it
.glyph_row
->height
;
13561 /* Alist that caches the results of :propertize.
13562 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
13563 Lisp_Object mode_line_proptrans_alist
;
13565 /* Contribute ELT to the mode line for window IT->w. How it
13566 translates into text depends on its data type.
13568 IT describes the display environment in which we display, as usual.
13570 DEPTH is the depth in recursion. It is used to prevent
13571 infinite recursion here.
13573 FIELD_WIDTH is the number of characters the display of ELT should
13574 occupy in the mode line, and PRECISION is the maximum number of
13575 characters to display from ELT's representation. See
13576 display_string for details.
13578 Returns the hpos of the end of the text generated by ELT. */
13581 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
)
13584 int field_width
, precision
;
13585 Lisp_Object elt
, props
;
13587 int n
= 0, field
, prec
;
13596 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
13600 /* A string: output it and check for %-constructs within it. */
13602 unsigned char *this = XSTRING (elt
)->data
;
13603 unsigned char *lisp_string
= this;
13607 Lisp_Object oprops
, aelt
;
13608 oprops
= Ftext_properties_at (make_number (0), elt
);
13609 if (NILP (Fequal (props
, oprops
)))
13611 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
13612 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
13616 elt
= Fcopy_sequence (elt
);
13617 Fset_text_properties (0, Flength (elt
), props
, elt
);
13618 mode_line_proptrans_alist
13619 = Fcons (Fcons (elt
, props
),
13620 mode_line_proptrans_alist
);
13627 prec
= precision
- n
;
13628 if (frame_title_ptr
)
13629 n
+= store_frame_title (XSTRING (elt
)->data
, -1, prec
);
13631 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
13632 0, prec
, 0, STRING_MULTIBYTE (elt
));
13637 while ((precision
<= 0 || n
< precision
)
13639 && (frame_title_ptr
13640 || it
->current_x
< it
->last_visible_x
))
13642 unsigned char *last
= this;
13644 /* Advance to end of string or next format specifier. */
13645 while ((c
= *this++) != '\0' && c
!= '%')
13648 if (this - 1 != last
)
13650 /* Output to end of string or up to '%'. Field width
13651 is length of string. Don't output more than
13652 PRECISION allows us. */
13655 prec
= chars_in_text (last
, this - last
);
13656 if (precision
> 0 && prec
> precision
- n
)
13657 prec
= precision
- n
;
13659 if (frame_title_ptr
)
13660 n
+= store_frame_title (last
, 0, prec
);
13663 int bytepos
= last
- lisp_string
;
13664 int charpos
= string_byte_to_char (elt
, bytepos
);
13665 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
13667 STRING_MULTIBYTE (elt
));
13670 else /* c == '%' */
13672 unsigned char *percent_position
= this;
13674 /* Get the specified minimum width. Zero means
13677 while ((c
= *this++) >= '0' && c
<= '9')
13678 field
= field
* 10 + c
- '0';
13680 /* Don't pad beyond the total padding allowed. */
13681 if (field_width
- n
> 0 && field
> field_width
- n
)
13682 field
= field_width
- n
;
13684 /* Note that either PRECISION <= 0 or N < PRECISION. */
13685 prec
= precision
- n
;
13688 n
+= display_mode_element (it
, depth
, field
, prec
,
13689 Vglobal_mode_string
, props
);
13693 unsigned char *spec
13694 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
13696 if (frame_title_ptr
)
13697 n
+= store_frame_title (spec
, field
, prec
);
13700 int nglyphs_before
, bytepos
, charpos
, nwritten
;
13702 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13703 bytepos
= percent_position
- XSTRING (elt
)->data
;
13704 charpos
= (STRING_MULTIBYTE (elt
)
13705 ? string_byte_to_char (elt
, bytepos
)
13707 nwritten
= display_string (spec
, Qnil
, elt
,
13712 /* Assign to the glyphs written above the
13713 string where the `%x' came from, position
13717 struct glyph
*glyph
13718 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
13722 for (i
= 0; i
< nwritten
; ++i
)
13724 glyph
[i
].object
= elt
;
13725 glyph
[i
].charpos
= charpos
;
13740 /* A symbol: process the value of the symbol recursively
13741 as if it appeared here directly. Avoid error if symbol void.
13742 Special case: if value of symbol is a string, output the string
13745 register Lisp_Object tem
;
13746 tem
= Fboundp (elt
);
13749 tem
= Fsymbol_value (elt
);
13750 /* If value is a string, output that string literally:
13751 don't check for % within it. */
13755 if (!EQ (tem
, elt
))
13757 /* Give up right away for nil or t. */
13767 register Lisp_Object car
, tem
;
13769 /* A cons cell: five distinct cases.
13770 If first element is :eval or :propertize, do something special.
13771 If first element is a string or a cons, process all the elements
13772 and effectively concatenate them.
13773 If first element is a negative number, truncate displaying cdr to
13774 at most that many characters. If positive, pad (with spaces)
13775 to at least that many characters.
13776 If first element is a symbol, process the cadr or caddr recursively
13777 according to whether the symbol's value is non-nil or nil. */
13779 if (EQ (car
, QCeval
))
13781 /* An element of the form (:eval FORM) means evaluate FORM
13782 and use the result as mode line elements. */
13784 if (CONSP (XCDR (elt
)))
13787 spec
= safe_eval (XCAR (XCDR (elt
)));
13788 n
+= display_mode_element (it
, depth
, field_width
- n
,
13789 precision
- n
, spec
, props
);
13792 else if (EQ (car
, QCpropertize
))
13794 if (CONSP (XCDR (elt
)))
13796 /* An element of the form (:propertize ELT PROPS...)
13797 means display ELT but applying properties PROPS. */
13798 n
+= display_mode_element (it
, depth
, field_width
- n
,
13799 precision
- n
, XCAR (XCDR (elt
)),
13800 XCDR (XCDR (elt
)));
13803 else if (SYMBOLP (car
))
13805 tem
= Fboundp (car
);
13809 /* elt is now the cdr, and we know it is a cons cell.
13810 Use its car if CAR has a non-nil value. */
13813 tem
= Fsymbol_value (car
);
13820 /* Symbol's value is nil (or symbol is unbound)
13821 Get the cddr of the original list
13822 and if possible find the caddr and use that. */
13826 else if (!CONSP (elt
))
13831 else if (INTEGERP (car
))
13833 register int lim
= XINT (car
);
13837 /* Negative int means reduce maximum width. */
13838 if (precision
<= 0)
13841 precision
= min (precision
, -lim
);
13845 /* Padding specified. Don't let it be more than
13846 current maximum. */
13848 lim
= min (precision
, lim
);
13850 /* If that's more padding than already wanted, queue it.
13851 But don't reduce padding already specified even if
13852 that is beyond the current truncation point. */
13853 field_width
= max (lim
, field_width
);
13857 else if (STRINGP (car
) || CONSP (car
))
13859 register int limit
= 50;
13860 /* Limit is to protect against circular lists. */
13863 && (precision
<= 0 || n
< precision
))
13865 n
+= display_mode_element (it
, depth
, field_width
- n
,
13866 precision
- n
, XCAR (elt
), props
);
13875 if (frame_title_ptr
)
13876 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
13878 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
13879 precision
- n
, 0, 0);
13883 /* Pad to FIELD_WIDTH. */
13884 if (field_width
> 0 && n
< field_width
)
13886 if (frame_title_ptr
)
13887 n
+= store_frame_title ("", field_width
- n
, 0);
13889 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
13897 /* Write a null-terminated, right justified decimal representation of
13898 the positive integer D to BUF using a minimal field width WIDTH. */
13901 pint2str (buf
, width
, d
)
13902 register char *buf
;
13903 register int width
;
13906 register char *p
= buf
;
13914 *p
++ = d
% 10 + '0';
13919 for (width
-= (int) (p
- buf
); width
> 0; --width
)
13930 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
13931 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
13932 type of CODING_SYSTEM. Return updated pointer into BUF. */
13934 static unsigned char invalid_eol_type
[] = "(*invalid*)";
13937 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
13938 Lisp_Object coding_system
;
13939 register char *buf
;
13943 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
13944 unsigned char *eol_str
;
13946 /* The EOL conversion we are using. */
13947 Lisp_Object eoltype
;
13949 val
= Fget (coding_system
, Qcoding_system
);
13952 if (!VECTORP (val
)) /* Not yet decided. */
13957 eoltype
= eol_mnemonic_undecided
;
13958 /* Don't mention EOL conversion if it isn't decided. */
13962 Lisp_Object eolvalue
;
13964 eolvalue
= Fget (coding_system
, Qeol_type
);
13967 *buf
++ = XFASTINT (AREF (val
, 1));
13971 /* The EOL conversion that is normal on this system. */
13973 if (NILP (eolvalue
)) /* Not yet decided. */
13974 eoltype
= eol_mnemonic_undecided
;
13975 else if (VECTORP (eolvalue
)) /* Not yet decided. */
13976 eoltype
= eol_mnemonic_undecided
;
13977 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
13978 eoltype
= (XFASTINT (eolvalue
) == 0
13979 ? eol_mnemonic_unix
13980 : (XFASTINT (eolvalue
) == 1
13981 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13987 /* Mention the EOL conversion if it is not the usual one. */
13988 if (STRINGP (eoltype
))
13990 eol_str
= XSTRING (eoltype
)->data
;
13991 eol_str_len
= XSTRING (eoltype
)->size
;
13993 else if (INTEGERP (eoltype
)
13994 && CHAR_VALID_P (XINT (eoltype
), 0))
13996 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13997 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
14001 eol_str
= invalid_eol_type
;
14002 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14004 bcopy (eol_str
, buf
, eol_str_len
);
14005 buf
+= eol_str_len
;
14011 /* Return a string for the output of a mode line %-spec for window W,
14012 generated by character C. PRECISION >= 0 means don't return a
14013 string longer than that value. FIELD_WIDTH > 0 means pad the
14014 string returned with spaces to that value. Return 1 in *MULTIBYTE
14015 if the result is multibyte text. */
14017 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14020 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14023 int field_width
, precision
;
14027 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14028 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14029 struct buffer
*b
= XBUFFER (w
->buffer
);
14037 if (!NILP (b
->read_only
))
14039 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14044 /* This differs from %* only for a modified read-only buffer. */
14045 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14047 if (!NILP (b
->read_only
))
14052 /* This differs from %* in ignoring read-only-ness. */
14053 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14065 if (command_loop_level
> 5)
14067 p
= decode_mode_spec_buf
;
14068 for (i
= 0; i
< command_loop_level
; i
++)
14071 return decode_mode_spec_buf
;
14079 if (command_loop_level
> 5)
14081 p
= decode_mode_spec_buf
;
14082 for (i
= 0; i
< command_loop_level
; i
++)
14085 return decode_mode_spec_buf
;
14092 /* Let lots_of_dashes be a string of infinite length. */
14093 if (field_width
<= 0
14094 || field_width
> sizeof (lots_of_dashes
))
14096 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
14097 decode_mode_spec_buf
[i
] = '-';
14098 decode_mode_spec_buf
[i
] = '\0';
14099 return decode_mode_spec_buf
;
14102 return lots_of_dashes
;
14111 int col
= current_column ();
14112 w
->column_number_displayed
= make_number (col
);
14113 pint2str (decode_mode_spec_buf
, field_width
, col
);
14114 return decode_mode_spec_buf
;
14118 /* %F displays the frame name. */
14119 if (!NILP (f
->title
))
14120 return (char *) XSTRING (f
->title
)->data
;
14121 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
14122 return (char *) XSTRING (f
->name
)->data
;
14131 int startpos
= XMARKER (w
->start
)->charpos
;
14132 int startpos_byte
= marker_byte_position (w
->start
);
14133 int line
, linepos
, linepos_byte
, topline
;
14135 int height
= XFASTINT (w
->height
);
14137 /* If we decided that this buffer isn't suitable for line numbers,
14138 don't forget that too fast. */
14139 if (EQ (w
->base_line_pos
, w
->buffer
))
14141 /* But do forget it, if the window shows a different buffer now. */
14142 else if (BUFFERP (w
->base_line_pos
))
14143 w
->base_line_pos
= Qnil
;
14145 /* If the buffer is very big, don't waste time. */
14146 if (INTEGERP (Vline_number_display_limit
)
14147 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
14149 w
->base_line_pos
= Qnil
;
14150 w
->base_line_number
= Qnil
;
14154 if (!NILP (w
->base_line_number
)
14155 && !NILP (w
->base_line_pos
)
14156 && XFASTINT (w
->base_line_pos
) <= startpos
)
14158 line
= XFASTINT (w
->base_line_number
);
14159 linepos
= XFASTINT (w
->base_line_pos
);
14160 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
14165 linepos
= BUF_BEGV (b
);
14166 linepos_byte
= BUF_BEGV_BYTE (b
);
14169 /* Count lines from base line to window start position. */
14170 nlines
= display_count_lines (linepos
, linepos_byte
,
14174 topline
= nlines
+ line
;
14176 /* Determine a new base line, if the old one is too close
14177 or too far away, or if we did not have one.
14178 "Too close" means it's plausible a scroll-down would
14179 go back past it. */
14180 if (startpos
== BUF_BEGV (b
))
14182 w
->base_line_number
= make_number (topline
);
14183 w
->base_line_pos
= make_number (BUF_BEGV (b
));
14185 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
14186 || linepos
== BUF_BEGV (b
))
14188 int limit
= BUF_BEGV (b
);
14189 int limit_byte
= BUF_BEGV_BYTE (b
);
14191 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
14193 if (startpos
- distance
> limit
)
14195 limit
= startpos
- distance
;
14196 limit_byte
= CHAR_TO_BYTE (limit
);
14199 nlines
= display_count_lines (startpos
, startpos_byte
,
14201 - (height
* 2 + 30),
14203 /* If we couldn't find the lines we wanted within
14204 line_number_display_limit_width chars per line,
14205 give up on line numbers for this window. */
14206 if (position
== limit_byte
&& limit
== startpos
- distance
)
14208 w
->base_line_pos
= w
->buffer
;
14209 w
->base_line_number
= Qnil
;
14213 w
->base_line_number
= make_number (topline
- nlines
);
14214 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
14217 /* Now count lines from the start pos to point. */
14218 nlines
= display_count_lines (startpos
, startpos_byte
,
14219 PT_BYTE
, PT
, &junk
);
14221 /* Record that we did display the line number. */
14222 line_number_displayed
= 1;
14224 /* Make the string to show. */
14225 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
14226 return decode_mode_spec_buf
;
14229 char* p
= decode_mode_spec_buf
;
14230 int pad
= field_width
- 2;
14236 return decode_mode_spec_buf
;
14242 obj
= b
->mode_name
;
14246 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
14252 int pos
= marker_position (w
->start
);
14253 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14255 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
14257 if (pos
<= BUF_BEGV (b
))
14262 else if (pos
<= BUF_BEGV (b
))
14266 if (total
> 1000000)
14267 /* Do it differently for a large value, to avoid overflow. */
14268 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14270 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14271 /* We can't normally display a 3-digit number,
14272 so get us a 2-digit number that is close. */
14275 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14276 return decode_mode_spec_buf
;
14280 /* Display percentage of size above the bottom of the screen. */
14283 int toppos
= marker_position (w
->start
);
14284 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
14285 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
14287 if (botpos
>= BUF_ZV (b
))
14289 if (toppos
<= BUF_BEGV (b
))
14296 if (total
> 1000000)
14297 /* Do it differently for a large value, to avoid overflow. */
14298 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
14300 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
14301 /* We can't normally display a 3-digit number,
14302 so get us a 2-digit number that is close. */
14305 if (toppos
<= BUF_BEGV (b
))
14306 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
14308 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
14309 return decode_mode_spec_buf
;
14314 /* status of process */
14315 obj
= Fget_buffer_process (w
->buffer
);
14317 return "no process";
14318 #ifdef subprocesses
14319 obj
= Fsymbol_name (Fprocess_status (obj
));
14323 case 't': /* indicate TEXT or BINARY */
14324 #ifdef MODE_LINE_BINARY_TEXT
14325 return MODE_LINE_BINARY_TEXT (b
);
14331 /* coding-system (not including end-of-line format) */
14333 /* coding-system (including end-of-line type) */
14335 int eol_flag
= (c
== 'Z');
14336 char *p
= decode_mode_spec_buf
;
14338 if (! FRAME_WINDOW_P (f
))
14340 /* No need to mention EOL here--the terminal never needs
14341 to do EOL conversion. */
14342 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
14343 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
14345 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
14348 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
14349 #ifdef subprocesses
14350 obj
= Fget_buffer_process (Fcurrent_buffer ());
14351 if (PROCESSP (obj
))
14353 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
14355 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
14358 #endif /* subprocesses */
14361 return decode_mode_spec_buf
;
14367 *multibyte
= STRING_MULTIBYTE (obj
);
14368 return (char *) XSTRING (obj
)->data
;
14375 /* Count up to COUNT lines starting from START / START_BYTE.
14376 But don't go beyond LIMIT_BYTE.
14377 Return the number of lines thus found (always nonnegative).
14379 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
14382 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
14383 int start
, start_byte
, limit_byte
, count
;
14386 register unsigned char *cursor
;
14387 unsigned char *base
;
14389 register int ceiling
;
14390 register unsigned char *ceiling_addr
;
14391 int orig_count
= count
;
14393 /* If we are not in selective display mode,
14394 check only for newlines. */
14395 int selective_display
= (!NILP (current_buffer
->selective_display
)
14396 && !INTEGERP (current_buffer
->selective_display
));
14400 while (start_byte
< limit_byte
)
14402 ceiling
= BUFFER_CEILING_OF (start_byte
);
14403 ceiling
= min (limit_byte
- 1, ceiling
);
14404 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
14405 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
14408 if (selective_display
)
14409 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
14412 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
14415 if (cursor
!= ceiling_addr
)
14419 start_byte
+= cursor
- base
+ 1;
14420 *byte_pos_ptr
= start_byte
;
14424 if (++cursor
== ceiling_addr
)
14430 start_byte
+= cursor
- base
;
14435 while (start_byte
> limit_byte
)
14437 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
14438 ceiling
= max (limit_byte
, ceiling
);
14439 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
14440 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
14443 if (selective_display
)
14444 while (--cursor
!= ceiling_addr
14445 && *cursor
!= '\n' && *cursor
!= 015)
14448 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
14451 if (cursor
!= ceiling_addr
)
14455 start_byte
+= cursor
- base
+ 1;
14456 *byte_pos_ptr
= start_byte
;
14457 /* When scanning backwards, we should
14458 not count the newline posterior to which we stop. */
14459 return - orig_count
- 1;
14465 /* Here we add 1 to compensate for the last decrement
14466 of CURSOR, which took it past the valid range. */
14467 start_byte
+= cursor
- base
+ 1;
14471 *byte_pos_ptr
= limit_byte
;
14474 return - orig_count
+ count
;
14475 return orig_count
- count
;
14481 /***********************************************************************
14483 ***********************************************************************/
14485 /* Display a NUL-terminated string, starting with index START.
14487 If STRING is non-null, display that C string. Otherwise, the Lisp
14488 string LISP_STRING is displayed.
14490 If FACE_STRING is not nil, FACE_STRING_POS is a position in
14491 FACE_STRING. Display STRING or LISP_STRING with the face at
14492 FACE_STRING_POS in FACE_STRING:
14494 Display the string in the environment given by IT, but use the
14495 standard display table, temporarily.
14497 FIELD_WIDTH is the minimum number of output glyphs to produce.
14498 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14499 with spaces. If STRING has more characters, more than FIELD_WIDTH
14500 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
14502 PRECISION is the maximum number of characters to output from
14503 STRING. PRECISION < 0 means don't truncate the string.
14505 This is roughly equivalent to printf format specifiers:
14507 FIELD_WIDTH PRECISION PRINTF
14508 ----------------------------------------
14514 MULTIBYTE zero means do not display multibyte chars, > 0 means do
14515 display them, and < 0 means obey the current buffer's value of
14516 enable_multibyte_characters.
14518 Value is the number of glyphs produced. */
14521 display_string (string
, lisp_string
, face_string
, face_string_pos
,
14522 start
, it
, field_width
, precision
, max_x
, multibyte
)
14523 unsigned char *string
;
14524 Lisp_Object lisp_string
;
14525 Lisp_Object face_string
;
14526 int face_string_pos
;
14529 int field_width
, precision
, max_x
;
14532 int hpos_at_start
= it
->hpos
;
14533 int saved_face_id
= it
->face_id
;
14534 struct glyph_row
*row
= it
->glyph_row
;
14536 /* Initialize the iterator IT for iteration over STRING beginning
14537 with index START. */
14538 reseat_to_string (it
, string
, lisp_string
, start
,
14539 precision
, field_width
, multibyte
);
14541 /* If displaying STRING, set up the face of the iterator
14542 from LISP_STRING, if that's given. */
14543 if (STRINGP (face_string
))
14549 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
14550 0, it
->region_beg_charpos
,
14551 it
->region_end_charpos
,
14552 &endptr
, it
->base_face_id
, 0);
14553 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14554 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
14557 /* Set max_x to the maximum allowed X position. Don't let it go
14558 beyond the right edge of the window. */
14560 max_x
= it
->last_visible_x
;
14562 max_x
= min (max_x
, it
->last_visible_x
);
14564 /* Skip over display elements that are not visible. because IT->w is
14566 if (it
->current_x
< it
->first_visible_x
)
14567 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
14568 MOVE_TO_POS
| MOVE_TO_X
);
14570 row
->ascent
= it
->max_ascent
;
14571 row
->height
= it
->max_ascent
+ it
->max_descent
;
14572 row
->phys_ascent
= it
->max_phys_ascent
;
14573 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14575 /* This condition is for the case that we are called with current_x
14576 past last_visible_x. */
14577 while (it
->current_x
< max_x
)
14579 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
14581 /* Get the next display element. */
14582 if (!get_next_display_element (it
))
14585 /* Produce glyphs. */
14586 x_before
= it
->current_x
;
14587 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14588 PRODUCE_GLYPHS (it
);
14590 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
14593 while (i
< nglyphs
)
14595 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14597 if (!it
->truncate_lines_p
14598 && x
+ glyph
->pixel_width
> max_x
)
14600 /* End of continued line or max_x reached. */
14601 if (CHAR_GLYPH_PADDING_P (*glyph
))
14603 /* A wide character is unbreakable. */
14604 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14605 it
->current_x
= x_before
;
14609 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14614 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
14616 /* Glyph is at least partially visible. */
14618 if (x
< it
->first_visible_x
)
14619 it
->glyph_row
->x
= x
- it
->first_visible_x
;
14623 /* Glyph is off the left margin of the display area.
14624 Should not happen. */
14628 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14629 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14630 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14631 row
->phys_height
= max (row
->phys_height
,
14632 it
->max_phys_ascent
+ it
->max_phys_descent
);
14633 x
+= glyph
->pixel_width
;
14637 /* Stop if max_x reached. */
14641 /* Stop at line ends. */
14642 if (ITERATOR_AT_END_OF_LINE_P (it
))
14644 it
->continuation_lines_width
= 0;
14648 set_iterator_to_next (it
, 1);
14650 /* Stop if truncating at the right edge. */
14651 if (it
->truncate_lines_p
14652 && it
->current_x
>= it
->last_visible_x
)
14654 /* Add truncation mark, but don't do it if the line is
14655 truncated at a padding space. */
14656 if (IT_CHARPOS (*it
) < it
->string_nchars
)
14658 if (!FRAME_WINDOW_P (it
->f
))
14662 if (it
->current_x
> it
->last_visible_x
)
14664 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14665 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14667 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14669 row
->used
[TEXT_AREA
] = i
;
14670 produce_special_glyphs (it
, IT_TRUNCATION
);
14673 produce_special_glyphs (it
, IT_TRUNCATION
);
14675 it
->glyph_row
->truncated_on_right_p
= 1;
14681 /* Maybe insert a truncation at the left. */
14682 if (it
->first_visible_x
14683 && IT_CHARPOS (*it
) > 0)
14685 if (!FRAME_WINDOW_P (it
->f
))
14686 insert_left_trunc_glyphs (it
);
14687 it
->glyph_row
->truncated_on_left_p
= 1;
14690 it
->face_id
= saved_face_id
;
14692 /* Value is number of columns displayed. */
14693 return it
->hpos
- hpos_at_start
;
14698 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
14699 appears as an element of LIST or as the car of an element of LIST.
14700 If PROPVAL is a list, compare each element against LIST in that
14701 way, and return 1/2 if any element of PROPVAL is found in LIST.
14702 Otherwise return 0. This function cannot quit.
14703 The return value is 2 if the text is invisible but with an ellipsis
14704 and 1 if it's invisible and without an ellipsis. */
14707 invisible_p (propval
, list
)
14708 register Lisp_Object propval
;
14711 register Lisp_Object tail
, proptail
;
14713 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14715 register Lisp_Object tem
;
14717 if (EQ (propval
, tem
))
14719 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
14720 return NILP (XCDR (tem
)) ? 1 : 2;
14723 if (CONSP (propval
))
14725 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
14727 Lisp_Object propelt
;
14728 propelt
= XCAR (proptail
);
14729 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
14731 register Lisp_Object tem
;
14733 if (EQ (propelt
, tem
))
14735 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
14736 return NILP (XCDR (tem
)) ? 1 : 2;
14745 /***********************************************************************
14747 ***********************************************************************/
14752 Vwith_echo_area_save_vector
= Qnil
;
14753 staticpro (&Vwith_echo_area_save_vector
);
14755 Vmessage_stack
= Qnil
;
14756 staticpro (&Vmessage_stack
);
14758 Qinhibit_redisplay
= intern ("inhibit-redisplay");
14759 staticpro (&Qinhibit_redisplay
);
14761 message_dolog_marker1
= Fmake_marker ();
14762 staticpro (&message_dolog_marker1
);
14763 message_dolog_marker2
= Fmake_marker ();
14764 staticpro (&message_dolog_marker2
);
14765 message_dolog_marker3
= Fmake_marker ();
14766 staticpro (&message_dolog_marker3
);
14769 defsubr (&Sdump_glyph_matrix
);
14770 defsubr (&Sdump_glyph_row
);
14771 defsubr (&Sdump_tool_bar_row
);
14772 defsubr (&Strace_redisplay
);
14773 defsubr (&Strace_to_stderr
);
14775 #ifdef HAVE_WINDOW_SYSTEM
14776 defsubr (&Stool_bar_lines_needed
);
14779 staticpro (&Qmenu_bar_update_hook
);
14780 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
14782 staticpro (&Qoverriding_terminal_local_map
);
14783 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
14785 staticpro (&Qoverriding_local_map
);
14786 Qoverriding_local_map
= intern ("overriding-local-map");
14788 staticpro (&Qwindow_scroll_functions
);
14789 Qwindow_scroll_functions
= intern ("window-scroll-functions");
14791 staticpro (&Qredisplay_end_trigger_functions
);
14792 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
14794 staticpro (&Qinhibit_point_motion_hooks
);
14795 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
14797 QCdata
= intern (":data");
14798 staticpro (&QCdata
);
14799 Qdisplay
= intern ("display");
14800 staticpro (&Qdisplay
);
14801 Qspace_width
= intern ("space-width");
14802 staticpro (&Qspace_width
);
14803 Qraise
= intern ("raise");
14804 staticpro (&Qraise
);
14805 Qspace
= intern ("space");
14806 staticpro (&Qspace
);
14807 Qmargin
= intern ("margin");
14808 staticpro (&Qmargin
);
14809 Qleft_margin
= intern ("left-margin");
14810 staticpro (&Qleft_margin
);
14811 Qright_margin
= intern ("right-margin");
14812 staticpro (&Qright_margin
);
14813 Qalign_to
= intern ("align-to");
14814 staticpro (&Qalign_to
);
14815 QCalign_to
= intern (":align-to");
14816 staticpro (&QCalign_to
);
14817 Qrelative_width
= intern ("relative-width");
14818 staticpro (&Qrelative_width
);
14819 QCrelative_width
= intern (":relative-width");
14820 staticpro (&QCrelative_width
);
14821 QCrelative_height
= intern (":relative-height");
14822 staticpro (&QCrelative_height
);
14823 QCeval
= intern (":eval");
14824 staticpro (&QCeval
);
14825 QCpropertize
= intern (":propertize");
14826 staticpro (&QCpropertize
);
14827 Qwhen
= intern ("when");
14828 staticpro (&Qwhen
);
14829 QCfile
= intern (":file");
14830 staticpro (&QCfile
);
14831 Qfontified
= intern ("fontified");
14832 staticpro (&Qfontified
);
14833 Qfontification_functions
= intern ("fontification-functions");
14834 staticpro (&Qfontification_functions
);
14835 Qtrailing_whitespace
= intern ("trailing-whitespace");
14836 staticpro (&Qtrailing_whitespace
);
14837 Qimage
= intern ("image");
14838 staticpro (&Qimage
);
14839 Qmessage_truncate_lines
= intern ("message-truncate-lines");
14840 staticpro (&Qmessage_truncate_lines
);
14841 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
14842 staticpro (&Qcursor_in_non_selected_windows
);
14843 Qgrow_only
= intern ("grow-only");
14844 staticpro (&Qgrow_only
);
14845 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
14846 staticpro (&Qinhibit_menubar_update
);
14847 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
14848 staticpro (&Qinhibit_eval_during_redisplay
);
14849 Qposition
= intern ("position");
14850 staticpro (&Qposition
);
14851 Qbuffer_position
= intern ("buffer-position");
14852 staticpro (&Qbuffer_position
);
14853 Qobject
= intern ("object");
14854 staticpro (&Qobject
);
14856 last_arrow_position
= Qnil
;
14857 last_arrow_string
= Qnil
;
14858 staticpro (&last_arrow_position
);
14859 staticpro (&last_arrow_string
);
14861 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
14862 staticpro (&echo_buffer
[0]);
14863 staticpro (&echo_buffer
[1]);
14865 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
14866 staticpro (&echo_area_buffer
[0]);
14867 staticpro (&echo_area_buffer
[1]);
14869 Vmessages_buffer_name
= build_string ("*Messages*");
14870 staticpro (&Vmessages_buffer_name
);
14872 mode_line_proptrans_alist
= Qnil
;
14873 staticpro (&mode_line_proptrans_alist
);
14875 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
14876 doc
: /* Non-nil means highlight trailing whitespace.
14877 The face used for trailing whitespace is `trailing-whitespace'. */);
14878 Vshow_trailing_whitespace
= Qnil
;
14880 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
14881 doc
: /* Non-nil means don't actually do any redisplay.
14882 This is used for internal purposes. */);
14883 Vinhibit_redisplay
= Qnil
;
14885 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
14886 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
14887 Vglobal_mode_string
= Qnil
;
14889 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
14890 doc
: /* Marker for where to display an arrow on top of the buffer text.
14891 This must be the beginning of a line in order to work.
14892 See also `overlay-arrow-string'. */);
14893 Voverlay_arrow_position
= Qnil
;
14895 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
14896 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
14897 Voverlay_arrow_string
= Qnil
;
14899 DEFVAR_INT ("scroll-step", &scroll_step
,
14900 doc
: /* *The number of lines to try scrolling a window by when point moves out.
14901 If that fails to bring point back on frame, point is centered instead.
14902 If this is zero, point is always centered after it moves off frame.
14903 If you want scrolling to always be a line at a time, you should set
14904 `scroll-conservatively' to a large value rather than set this to 1. */);
14906 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
14907 doc
: /* *Scroll up to this many lines, to bring point back on screen.
14908 A value of zero means to scroll the text to center point vertically
14909 in the window. */);
14910 scroll_conservatively
= 0;
14912 DEFVAR_INT ("scroll-margin", &scroll_margin
,
14913 doc
: /* *Number of lines of margin at the top and bottom of a window.
14914 Recenter the window whenever point gets within this many lines
14915 of the top or bottom of the window. */);
14919 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
14922 DEFVAR_BOOL ("truncate-partial-width-windows",
14923 &truncate_partial_width_windows
,
14924 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
14925 truncate_partial_width_windows
= 1;
14927 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
14928 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
14929 Any other value means to use the appropriate face, `mode-line',
14930 `header-line', or `menu' respectively.
14932 This variable is deprecated; please change the above faces instead. */);
14933 mode_line_inverse_video
= 1;
14935 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
14936 doc
: /* *Maximum buffer size for which line number should be displayed.
14937 If the buffer is bigger than this, the line number does not appear
14938 in the mode line. A value of nil means no limit. */);
14939 Vline_number_display_limit
= Qnil
;
14941 DEFVAR_INT ("line-number-display-limit-width",
14942 &line_number_display_limit_width
,
14943 doc
: /* *Maximum line width (in characters) for line number display.
14944 If the average length of the lines near point is bigger than this, then the
14945 line number may be omitted from the mode line. */);
14946 line_number_display_limit_width
= 200;
14948 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
14949 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
14950 highlight_nonselected_windows
= 0;
14952 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
14953 doc
: /* Non-nil if more than one frame is visible on this display.
14954 Minibuffer-only frames don't count, but iconified frames do.
14955 This variable is not guaranteed to be accurate except while processing
14956 `frame-title-format' and `icon-title-format'. */);
14958 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
14959 doc
: /* Template for displaying the title bar of visible frames.
14960 \(Assuming the window manager supports this feature.)
14961 This variable has the same structure as `mode-line-format' (which see),
14962 and is used only on frames for which no explicit name has been set
14963 \(see `modify-frame-parameters'). */);
14964 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
14965 doc
: /* Template for displaying the title bar of an iconified frame.
14966 \(Assuming the window manager supports this feature.)
14967 This variable has the same structure as `mode-line-format' (which see),
14968 and is used only on frames for which no explicit name has been set
14969 \(see `modify-frame-parameters'). */);
14971 = Vframe_title_format
14972 = Fcons (intern ("multiple-frames"),
14973 Fcons (build_string ("%b"),
14974 Fcons (Fcons (empty_string
,
14975 Fcons (intern ("invocation-name"),
14976 Fcons (build_string ("@"),
14977 Fcons (intern ("system-name"),
14981 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
14982 doc
: /* Maximum number of lines to keep in the message log buffer.
14983 If nil, disable message logging. If t, log messages but don't truncate
14984 the buffer when it becomes large. */);
14985 Vmessage_log_max
= make_number (50);
14987 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
14988 doc
: /* Functions called before redisplay, if window sizes have changed.
14989 The value should be a list of functions that take one argument.
14990 Just before redisplay, for each frame, if any of its windows have changed
14991 size since the last redisplay, or have been split or deleted,
14992 all the functions in the list are called, with the frame as argument. */);
14993 Vwindow_size_change_functions
= Qnil
;
14995 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
14996 doc
: /* List of Functions to call before redisplaying a window with scrolling.
14997 Each function is called with two arguments, the window
14998 and its new display-start position. Note that the value of `window-end'
14999 is not valid when these functions are called. */);
15000 Vwindow_scroll_functions
= Qnil
;
15002 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
15003 doc
: /* *Non-nil means automatically resize tool-bars.
15004 This increases a tool-bar's height if not all tool-bar items are visible.
15005 It decreases a tool-bar's height when it would display blank lines
15007 auto_resize_tool_bars_p
= 1;
15009 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
15010 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
15011 auto_raise_tool_bar_buttons_p
= 1;
15013 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
15014 doc
: /* *Margin around tool-bar buttons in pixels.
15015 If an integer, use that for both horizontal and vertical margins.
15016 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
15017 HORZ specifying the horizontal margin, and VERT specifying the
15018 vertical margin. */);
15019 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
15021 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
15022 doc
: /* *Relief thickness of tool-bar buttons. */);
15023 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
15025 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
15026 doc
: /* List of functions to call to fontify regions of text.
15027 Each function is called with one argument POS. Functions must
15028 fontify a region starting at POS in the current buffer, and give
15029 fontified regions the property `fontified'. */);
15030 Vfontification_functions
= Qnil
;
15031 Fmake_variable_buffer_local (Qfontification_functions
);
15033 DEFVAR_BOOL ("unibyte-display-via-language-environment",
15034 &unibyte_display_via_language_environment
,
15035 doc
: /* *Non-nil means display unibyte text according to language environment.
15036 Specifically this means that unibyte non-ASCII characters
15037 are displayed by converting them to the equivalent multibyte characters
15038 according to the current language environment. As a result, they are
15039 displayed according to the current fontset. */);
15040 unibyte_display_via_language_environment
= 0;
15042 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
15043 doc
: /* *Maximum height for resizing mini-windows.
15044 If a float, it specifies a fraction of the mini-window frame's height.
15045 If an integer, it specifies a number of lines. */);
15046 Vmax_mini_window_height
= make_float (0.25);
15048 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
15049 doc
: /* *How to resize mini-windows.
15050 A value of nil means don't automatically resize mini-windows.
15051 A value of t means resize them to fit the text displayed in them.
15052 A value of `grow-only', the default, means let mini-windows grow
15053 only, until their display becomes empty, at which point the windows
15054 go back to their normal size. */);
15055 Vresize_mini_windows
= Qgrow_only
;
15057 DEFVAR_BOOL ("cursor-in-non-selected-windows",
15058 &cursor_in_non_selected_windows
,
15059 doc
: /* *Non-nil means display a hollow cursor in non-selected windows.
15060 nil means don't display a cursor there. */);
15061 cursor_in_non_selected_windows
= 1;
15063 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
15064 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
15065 automatic_hscrolling_p
= 1;
15067 DEFVAR_INT ("automatic-hscroll-margin", &automatic_hscroll_margin
,
15068 doc
: /* *How many columns away from the window edge point is allowed to get
15069 before automatic hscrolling will horizontally scroll the window. */);
15070 automatic_hscroll_margin
= 5;
15072 DEFVAR_LISP ("automatic-hscroll-step", &Vautomatic_hscroll_step
,
15073 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
15074 When point is less than `automatic-hscroll-margin' columns from the window
15075 edge, automatic hscrolling will scroll the window by the amount of columns
15076 determined by this variable. If its value is a positive integer, scroll that
15077 many columns. If it's a positive floating-point number, it specifies the
15078 fraction of the window's width to scroll. If it's nil or zero, point will be
15079 centered horizontally after the scroll. Any other value, including negative
15080 numbers, are treated as if the value were zero.
15082 Automatic hscrolling always moves point outside the scroll margin, so if
15083 point was more than scroll step columns inside the margin, the window will
15084 scroll more than the value given by the scroll step.
15086 Note that the lower bound for automatic hscrolling specified by `scroll-left'
15087 and `scroll-right' overrides this variable's effect. */);
15088 Vautomatic_hscroll_step
= make_number (0);
15090 DEFVAR_LISP ("image-types", &Vimage_types
,
15091 doc
: /* List of supported image types.
15092 Each element of the list is a symbol for a supported image type. */);
15093 Vimage_types
= Qnil
;
15095 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
15096 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
15097 Bind this around calls to `message' to let it take effect. */);
15098 message_truncate_lines
= 0;
15100 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
15101 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
15102 Can be used to update submenus whose contents should vary. */);
15103 Vmenu_bar_update_hook
= Qnil
;
15105 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
15106 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
15107 inhibit_menubar_update
= 0;
15109 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
15110 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
15111 inhibit_eval_during_redisplay
= 0;
15114 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
15115 doc
: /* Inhibit try_window_id display optimization. */);
15116 inhibit_try_window_id
= 0;
15118 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
15119 doc
: /* Inhibit try_window_reusing display optimization. */);
15120 inhibit_try_window_reusing
= 0;
15122 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
15123 doc
: /* Inhibit try_cursor_movement display optimization. */);
15124 inhibit_try_cursor_movement
= 0;
15125 #endif /* GLYPH_DEBUG */
15129 /* Initialize this module when Emacs starts. */
15134 Lisp_Object root_window
;
15135 struct window
*mini_w
;
15137 current_header_line_height
= current_mode_line_height
= -1;
15139 CHARPOS (this_line_start_pos
) = 0;
15141 mini_w
= XWINDOW (minibuf_window
);
15142 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
15144 if (!noninteractive
)
15146 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
15149 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
15150 set_window_height (root_window
,
15151 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
15153 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
15154 set_window_height (minibuf_window
, 1, 0);
15156 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
15157 mini_w
->width
= make_number (FRAME_WIDTH (f
));
15159 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
15160 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
15161 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
15163 /* The default ellipsis glyphs `...'. */
15164 for (i
= 0; i
< 3; ++i
)
15165 default_invis_vector
[i
] = make_number ('.');
15168 #ifdef HAVE_WINDOW_SYSTEM
15170 /* Allocate the buffer for frame titles. */
15172 frame_title_buf
= (char *) xmalloc (size
);
15173 frame_title_buf_end
= frame_title_buf
+ size
;
15174 frame_title_ptr
= NULL
;
15176 #endif /* HAVE_WINDOW_SYSTEM */
15178 help_echo_showing_p
= 0;