1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay() +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator
128 (or init_string_iterator for that matter). Calls to
129 get_next_display_element fill the iterator structure with relevant
130 information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define min(a, b) ((a) < (b) ? (a) : (b))
202 #define max(a, b) ((a) > (b) ? (a) : (b))
204 #define INFINITY 10000000
206 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
207 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
208 extern int pending_menu_activation
;
211 extern int interrupt_input
;
212 extern int command_loop_level
;
214 extern int minibuffer_auto_raise
;
216 extern Lisp_Object Qface
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
222 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
223 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
224 Lisp_Object Qredisplay_end_trigger_functions
;
225 Lisp_Object Qinhibit_point_motion_hooks
;
226 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
227 Lisp_Object Qfontified
;
228 Lisp_Object Qgrow_only
;
230 /* Functions called to fontify regions of text. */
232 Lisp_Object Vfontification_functions
;
233 Lisp_Object Qfontification_functions
;
235 /* Non-zero means draw tool bar buttons raised when the mouse moves
238 int auto_raise_tool_bar_buttons_p
;
240 /* Margin around tool bar buttons in pixels. */
242 int tool_bar_button_margin
;
244 /* Thickness of shadow to draw around tool bar buttons. */
246 int tool_bar_button_relief
;
248 /* Non-zero means automatically resize tool-bars so that all tool-bar
249 items are visible, and no blank lines remain. */
251 int auto_resize_tool_bars_p
;
253 /* Non-nil means don't actually do any redisplay. */
255 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
257 /* Names of text properties relevant for redisplay. */
259 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
260 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
262 /* Symbols used in text property values. */
264 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
265 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
267 extern Lisp_Object Qheight
;
269 /* Non-nil means highlight trailing whitespace. */
271 Lisp_Object Vshow_trailing_whitespace
;
273 /* Name of the face used to highlight trailing whitespace. */
275 Lisp_Object Qtrailing_whitespace
;
277 /* The symbol `image' which is the car of the lists used to represent
282 /* Non-zero means print newline to stdout before next mini-buffer
285 int noninteractive_need_newline
;
287 /* Non-zero means print newline to message log before next message. */
289 static int message_log_need_newline
;
292 /* The buffer position of the first character appearing entirely or
293 partially on the line of the selected window which contains the
294 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
295 redisplay optimization in redisplay_internal. */
297 static struct text_pos this_line_start_pos
;
299 /* Number of characters past the end of the line above, including the
300 terminating newline. */
302 static struct text_pos this_line_end_pos
;
304 /* The vertical positions and the height of this line. */
306 static int this_line_vpos
;
307 static int this_line_y
;
308 static int this_line_pixel_height
;
310 /* X position at which this display line starts. Usually zero;
311 negative if first character is partially visible. */
313 static int this_line_start_x
;
315 /* Buffer that this_line_.* variables are referring to. */
317 static struct buffer
*this_line_buffer
;
319 /* Nonzero means truncate lines in all windows less wide than the
322 int truncate_partial_width_windows
;
324 /* A flag to control how to display unibyte 8-bit character. */
326 int unibyte_display_via_language_environment
;
328 /* Nonzero means we have more than one non-mini-buffer-only frame.
329 Not guaranteed to be accurate except while parsing
330 frame-title-format. */
334 Lisp_Object Vglobal_mode_string
;
336 /* Marker for where to display an arrow on top of the buffer text. */
338 Lisp_Object Voverlay_arrow_position
;
340 /* String to display for the arrow. Only used on terminal frames. */
342 Lisp_Object Voverlay_arrow_string
;
344 /* Values of those variables at last redisplay. However, if
345 Voverlay_arrow_position is a marker, last_arrow_position is its
346 numerical position. */
348 static Lisp_Object last_arrow_position
, last_arrow_string
;
350 /* Like mode-line-format, but for the title bar on a visible frame. */
352 Lisp_Object Vframe_title_format
;
354 /* Like mode-line-format, but for the title bar on an iconified frame. */
356 Lisp_Object Vicon_title_format
;
358 /* List of functions to call when a window's size changes. These
359 functions get one arg, a frame on which one or more windows' sizes
362 static Lisp_Object Vwindow_size_change_functions
;
364 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
366 /* Nonzero if overlay arrow has been displayed once in this window. */
368 static int overlay_arrow_seen
;
370 /* Nonzero means highlight the region even in nonselected windows. */
372 int highlight_nonselected_windows
;
374 /* If cursor motion alone moves point off frame, try scrolling this
375 many lines up or down if that will bring it back. */
377 static int scroll_step
;
379 /* Non-0 means scroll just far enough to bring point back on the
380 screen, when appropriate. */
382 static int scroll_conservatively
;
384 /* Recenter the window whenever point gets within this many lines of
385 the top or bottom of the window. This value is translated into a
386 pixel value by multiplying it with CANON_Y_UNIT, which means that
387 there is really a fixed pixel height scroll margin. */
391 /* Number of windows showing the buffer of the selected window (or
392 another buffer with the same base buffer). keyboard.c refers to
397 /* Vector containing glyphs for an ellipsis `...'. */
399 static Lisp_Object default_invis_vector
[3];
401 /* Zero means display the mode-line/header-line/menu-bar in the default face
402 (this slightly odd definition is for compatibility with previous versions
403 of emacs), non-zero means display them using their respective faces.
405 This variable is deprecated. */
407 int mode_line_inverse_video
;
409 /* Prompt to display in front of the mini-buffer contents. */
411 Lisp_Object minibuf_prompt
;
413 /* Width of current mini-buffer prompt. Only set after display_line
414 of the line that contains the prompt. */
416 int minibuf_prompt_width
;
417 int minibuf_prompt_pixel_width
;
419 /* This is the window where the echo area message was displayed. It
420 is always a mini-buffer window, but it may not be the same window
421 currently active as a mini-buffer. */
423 Lisp_Object echo_area_window
;
425 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
426 pushes the current message and the value of
427 message_enable_multibyte on the stack, the function restore_message
428 pops the stack and displays MESSAGE again. */
430 Lisp_Object Vmessage_stack
;
432 /* Nonzero means multibyte characters were enabled when the echo area
433 message was specified. */
435 int message_enable_multibyte
;
437 /* True if we should redraw the mode lines on the next redisplay. */
439 int update_mode_lines
;
441 /* Nonzero if window sizes or contents have changed since last
442 redisplay that finished */
444 int windows_or_buffers_changed
;
446 /* Nonzero after display_mode_line if %l was used and it displayed a
449 int line_number_displayed
;
451 /* Maximum buffer size for which to display line numbers. */
453 Lisp_Object Vline_number_display_limit
;
455 /* line width to consider when repostioning for line number display */
457 static int line_number_display_limit_width
;
459 /* Number of lines to keep in the message log buffer. t means
460 infinite. nil means don't log at all. */
462 Lisp_Object Vmessage_log_max
;
464 /* The name of the *Messages* buffer, a string. */
466 static Lisp_Object Vmessages_buffer_name
;
468 /* Current, index 0, and last displayed echo area message. Either
469 buffers from echo_buffers, or nil to indicate no message. */
471 Lisp_Object echo_area_buffer
[2];
473 /* The buffers referenced from echo_area_buffer. */
475 static Lisp_Object echo_buffer
[2];
477 /* A vector saved used in with_area_buffer to reduce consing. */
479 static Lisp_Object Vwith_echo_area_save_vector
;
481 /* Non-zero means display_echo_area should display the last echo area
482 message again. Set by redisplay_preserve_echo_area. */
484 static int display_last_displayed_message_p
;
486 /* Nonzero if echo area is being used by print; zero if being used by
489 int message_buf_print
;
491 /* Maximum height for resizing mini-windows. Either a float
492 specifying a fraction of the available height, or an integer
493 specifying a number of lines. */
495 Lisp_Object Vmax_mini_window_height
;
497 /* Non-zero means messages should be displayed with truncated
498 lines instead of being continued. */
500 int message_truncate_lines
;
501 Lisp_Object Qmessage_truncate_lines
;
503 /* Non-zero means we want a hollow cursor in windows that are not
504 selected. Zero means there's no cursor in such windows. */
506 int cursor_in_non_selected_windows
;
508 /* A scratch glyph row with contents used for generating truncation
509 glyphs. Also used in direct_output_for_insert. */
511 #define MAX_SCRATCH_GLYPHS 100
512 struct glyph_row scratch_glyph_row
;
513 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
515 /* Ascent and height of the last line processed by move_it_to. */
517 static int last_max_ascent
, last_height
;
519 /* Non-zero if there's a help-echo in the echo area. */
521 int help_echo_showing_p
;
523 /* If >= 0, computed, exact values of mode-line and header-line height
524 to use in the macros CURRENT_MODE_LINE_HEIGHT and
525 CURRENT_HEADER_LINE_HEIGHT. */
527 int current_mode_line_height
, current_header_line_height
;
529 /* The maximum distance to look ahead for text properties. Values
530 that are too small let us call compute_char_face and similar
531 functions too often which is expensive. Values that are too large
532 let us call compute_char_face and alike too often because we
533 might not be interested in text properties that far away. */
535 #define TEXT_PROP_DISTANCE_LIMIT 100
539 /* Non-zero means print traces of redisplay if compiled with
542 int trace_redisplay_p
;
544 #endif /* GLYPH_DEBUG */
546 #ifdef DEBUG_TRACE_MOVE
547 /* Non-zero means trace with TRACE_MOVE to stderr. */
550 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
552 #define TRACE_MOVE(x) (void) 0
555 /* Non-zero means automatically scroll windows horizontally to make
558 int automatic_hscrolling_p
;
560 /* A list of symbols, one for each supported image type. */
562 Lisp_Object Vimage_types
;
564 /* The variable `resize-mini-windows'. If nil, don't resize
565 mini-windows. If t, always resize them to fit the text they
566 display. If `grow-only', let mini-windows grow only until they
569 Lisp_Object Vresize_mini_windows
;
571 /* Value returned from text property handlers (see below). */
576 HANDLED_RECOMPUTE_PROPS
,
577 HANDLED_OVERLAY_STRING_CONSUMED
,
581 /* A description of text properties that redisplay is interested
586 /* The name of the property. */
589 /* A unique index for the property. */
592 /* A handler function called to set up iterator IT from the property
593 at IT's current position. Value is used to steer handle_stop. */
594 enum prop_handled (*handler
) P_ ((struct it
*it
));
597 static enum prop_handled handle_face_prop
P_ ((struct it
*));
598 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
599 static enum prop_handled handle_display_prop
P_ ((struct it
*));
600 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
601 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
602 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
604 /* Properties handled by iterators. */
606 static struct props it_props
[] =
608 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
609 /* Handle `face' before `display' because some sub-properties of
610 `display' need to know the face. */
611 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
612 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
613 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
614 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
618 /* Value is the position described by X. If X is a marker, value is
619 the marker_position of X. Otherwise, value is X. */
621 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
623 /* Enumeration returned by some move_it_.* functions internally. */
627 /* Not used. Undefined value. */
630 /* Move ended at the requested buffer position or ZV. */
631 MOVE_POS_MATCH_OR_ZV
,
633 /* Move ended at the requested X pixel position. */
636 /* Move within a line ended at the end of a line that must be
640 /* Move within a line ended at the end of a line that would
641 be displayed truncated. */
644 /* Move within a line ended at a line end. */
650 /* Function prototypes. */
652 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
653 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
654 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
655 static int invisible_text_between_p
P_ ((struct it
*, int, int));
656 static int next_element_from_ellipsis
P_ ((struct it
*));
657 static void pint2str
P_ ((char *, int, int));
658 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
660 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
661 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
662 static void store_frame_title_char
P_ ((char));
663 static int store_frame_title
P_ ((unsigned char *, int, int));
664 static void x_consider_frame_title
P_ ((Lisp_Object
));
665 static void handle_stop
P_ ((struct it
*));
666 static int tool_bar_lines_needed
P_ ((struct frame
*));
667 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
668 static void ensure_echo_area_buffers
P_ ((void));
669 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
671 struct glyph_row
*));
672 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
673 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
674 static int with_echo_area_buffer
P_ ((struct window
*, int,
675 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
676 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
677 static void clear_garbaged_frames
P_ ((void));
678 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
679 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
680 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
681 static int display_echo_area
P_ ((struct window
*));
682 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
683 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
684 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
685 static int string_char_and_length
P_ ((unsigned char *, int, int *));
686 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
688 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
689 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
690 static void insert_left_trunc_glyphs
P_ ((struct it
*));
691 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
692 static void extend_face_to_end_of_line
P_ ((struct it
*));
693 static int append_space
P_ ((struct it
*, int));
694 static void make_cursor_line_fully_visible
P_ ((struct window
*));
695 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
696 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
697 static int trailing_whitespace_p
P_ ((int));
698 static int message_log_check_duplicate
P_ ((int, int, int, int));
699 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
700 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
701 static void push_it
P_ ((struct it
*));
702 static void pop_it
P_ ((struct it
*));
703 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
704 static void redisplay_internal
P_ ((int));
705 static int echo_area_display
P_ ((int));
706 static void redisplay_windows
P_ ((Lisp_Object
));
707 static void redisplay_window
P_ ((Lisp_Object
, int));
708 static void update_menu_bar
P_ ((struct frame
*, int));
709 static int try_window_reusing_current_matrix
P_ ((struct window
*));
710 static int try_window_id
P_ ((struct window
*));
711 static int display_line
P_ ((struct it
*));
712 static int display_mode_lines
P_ ((struct window
*));
713 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
714 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
715 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
716 static void display_menu_bar
P_ ((struct window
*));
717 static int display_count_lines
P_ ((int, int, int, int, int *));
718 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
719 int, int, struct it
*, int, int, int, int));
720 static void compute_line_metrics
P_ ((struct it
*));
721 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
722 static int get_overlay_strings
P_ ((struct it
*));
723 static void next_overlay_string
P_ ((struct it
*));
724 static void reseat
P_ ((struct it
*, struct text_pos
, int));
725 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
726 static void back_to_previous_visible_line_start
P_ ((struct it
*));
727 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
728 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
729 static int next_element_from_display_vector
P_ ((struct it
*));
730 static int next_element_from_string
P_ ((struct it
*));
731 static int next_element_from_c_string
P_ ((struct it
*));
732 static int next_element_from_buffer
P_ ((struct it
*));
733 static int next_element_from_composition
P_ ((struct it
*));
734 static int next_element_from_image
P_ ((struct it
*));
735 static int next_element_from_stretch
P_ ((struct it
*));
736 static void load_overlay_strings
P_ ((struct it
*));
737 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
738 struct display_pos
*));
739 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
740 Lisp_Object
, int, int, int, int));
741 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
743 void move_it_vertically_backward
P_ ((struct it
*, int));
744 static void init_to_row_start
P_ ((struct it
*, struct window
*,
745 struct glyph_row
*));
746 static void init_to_row_end
P_ ((struct it
*, struct window
*,
747 struct glyph_row
*));
748 static void back_to_previous_line_start
P_ ((struct it
*));
749 static int forward_to_next_line_start
P_ ((struct it
*, int *));
750 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
752 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
753 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
754 static int number_of_chars
P_ ((unsigned char *, int));
755 static void compute_stop_pos
P_ ((struct it
*));
756 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
758 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
759 static int next_overlay_change
P_ ((int));
760 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
761 Lisp_Object
, struct text_pos
*));
762 static int underlying_face_id
P_ ((struct it
*));
764 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
765 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
767 #ifdef HAVE_WINDOW_SYSTEM
769 static void update_tool_bar
P_ ((struct frame
*, int));
770 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
771 static int redisplay_tool_bar
P_ ((struct frame
*));
772 static void display_tool_bar_line
P_ ((struct it
*));
774 #endif /* HAVE_WINDOW_SYSTEM */
777 /***********************************************************************
778 Window display dimensions
779 ***********************************************************************/
781 /* Return the window-relative maximum y + 1 for glyph rows displaying
782 text in window W. This is the height of W minus the height of a
783 mode line, if any. */
786 window_text_bottom_y (w
)
789 struct frame
*f
= XFRAME (w
->frame
);
790 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
792 if (WINDOW_WANTS_MODELINE_P (w
))
793 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
798 /* Return the pixel width of display area AREA of window W. AREA < 0
799 means return the total width of W, not including bitmap areas to
800 the left and right of the window. */
803 window_box_width (w
, area
)
807 struct frame
*f
= XFRAME (w
->frame
);
808 int width
= XFASTINT (w
->width
);
810 if (!w
->pseudo_window_p
)
812 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
814 if (area
== TEXT_AREA
)
816 if (INTEGERP (w
->left_margin_width
))
817 width
-= XFASTINT (w
->left_margin_width
);
818 if (INTEGERP (w
->right_margin_width
))
819 width
-= XFASTINT (w
->right_margin_width
);
821 else if (area
== LEFT_MARGIN_AREA
)
822 width
= (INTEGERP (w
->left_margin_width
)
823 ? XFASTINT (w
->left_margin_width
) : 0);
824 else if (area
== RIGHT_MARGIN_AREA
)
825 width
= (INTEGERP (w
->right_margin_width
)
826 ? XFASTINT (w
->right_margin_width
) : 0);
829 return width
* CANON_X_UNIT (f
);
833 /* Return the pixel height of the display area of window W, not
834 including mode lines of W, if any.. */
837 window_box_height (w
)
840 struct frame
*f
= XFRAME (w
->frame
);
841 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
843 xassert (height
>= 0);
845 if (WINDOW_WANTS_MODELINE_P (w
))
846 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
848 if (WINDOW_WANTS_HEADER_LINE_P (w
))
849 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
855 /* Return the frame-relative coordinate of the left edge of display
856 area AREA of window W. AREA < 0 means return the left edge of the
857 whole window, to the right of any bitmap area at the left side of
861 window_box_left (w
, area
)
865 struct frame
*f
= XFRAME (w
->frame
);
866 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
868 if (!w
->pseudo_window_p
)
870 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
871 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
873 if (area
== TEXT_AREA
)
874 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
875 else if (area
== RIGHT_MARGIN_AREA
)
876 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
877 + window_box_width (w
, TEXT_AREA
));
884 /* Return the frame-relative coordinate of the right edge of display
885 area AREA of window W. AREA < 0 means return the left edge of the
886 whole window, to the left of any bitmap area at the right side of
890 window_box_right (w
, area
)
894 return window_box_left (w
, area
) + window_box_width (w
, area
);
898 /* Get the bounding box of the display area AREA of window W, without
899 mode lines, in frame-relative coordinates. AREA < 0 means the
900 whole window, not including bitmap areas to the left and right of
901 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
902 coordinates of the upper-left corner of the box. Return in
903 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
906 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
909 int *box_x
, *box_y
, *box_width
, *box_height
;
911 struct frame
*f
= XFRAME (w
->frame
);
913 *box_width
= window_box_width (w
, area
);
914 *box_height
= window_box_height (w
);
915 *box_x
= window_box_left (w
, area
);
916 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
917 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
918 if (WINDOW_WANTS_HEADER_LINE_P (w
))
919 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
923 /* Get the bounding box of the display area AREA of window W, without
924 mode lines. AREA < 0 means the whole window, not including bitmap
925 areas to the left and right of the window. Return in *TOP_LEFT_X
926 and TOP_LEFT_Y the frame-relative pixel coordinates of the
927 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
928 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
932 window_box_edges (w
, area
, top_left_x
, top_left_y
,
933 bottom_right_x
, bottom_right_y
)
936 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
938 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
940 *bottom_right_x
+= *top_left_x
;
941 *bottom_right_y
+= *top_left_y
;
946 /***********************************************************************
948 ***********************************************************************/
950 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
951 1 if POS is visible and the line containing POS is fully visible.
952 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
953 and header-lines heights. */
956 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
958 int charpos
, *fully
, exact_mode_line_heights_p
;
963 struct buffer
*old_buffer
= NULL
;
965 if (XBUFFER (w
->buffer
) != current_buffer
)
967 old_buffer
= current_buffer
;
968 set_buffer_internal_1 (XBUFFER (w
->buffer
));
971 *fully
= visible_p
= 0;
972 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
974 /* Compute exact mode line heights, if requested. */
975 if (exact_mode_line_heights_p
)
977 if (WINDOW_WANTS_MODELINE_P (w
))
978 current_mode_line_height
979 = display_mode_line (w
, MODE_LINE_FACE_ID
,
980 current_buffer
->mode_line_format
);
982 if (WINDOW_WANTS_HEADER_LINE_P (w
))
983 current_header_line_height
984 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
985 current_buffer
->header_line_format
);
988 start_display (&it
, w
, top
);
989 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
990 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
992 if (IT_CHARPOS (it
) == charpos
)
994 int line_height
, line_bottom_y
;
995 int line_top_y
= it
.current_y
;
996 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
998 line_height
= it
.max_ascent
+ it
.max_descent
;
999 if (line_height
== 0)
1002 line_height
= last_height
;
1003 else if (charpos
< ZV
)
1005 move_it_by_lines (&it
, 1, 1);
1006 line_height
= (it
.max_ascent
|| it
.max_descent
1007 ? it
.max_ascent
+ it
.max_descent
1012 /* Use the default character height. */
1013 it
.what
= IT_CHARACTER
;
1016 PRODUCE_GLYPHS (&it
);
1017 line_height
= it
.ascent
+ it
.descent
;
1020 line_bottom_y
= line_top_y
+ line_height
;
1022 if (line_top_y
< window_top_y
)
1023 visible_p
= line_bottom_y
> window_top_y
;
1024 else if (line_top_y
< it
.last_visible_y
)
1027 *fully
= line_bottom_y
<= it
.last_visible_y
;
1030 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1032 move_it_by_lines (&it
, 1, 0);
1033 if (charpos
< IT_CHARPOS (it
))
1041 set_buffer_internal_1 (old_buffer
);
1043 current_header_line_height
= current_mode_line_height
= -1;
1048 /* Return the next character from STR which is MAXLEN bytes long.
1049 Return in *LEN the length of the character. This is like
1050 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1051 we find one, we return a `?', but with the length of the invalid
1055 string_char_and_length (str
, maxlen
, len
)
1061 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1062 if (!CHAR_VALID_P (c
, 1))
1063 /* We may not change the length here because other places in Emacs
1064 don't use this function, i.e. they silently accept invalid
1073 /* Given a position POS containing a valid character and byte position
1074 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1076 static struct text_pos
1077 string_pos_nchars_ahead (pos
, string
, nchars
)
1078 struct text_pos pos
;
1082 xassert (STRINGP (string
) && nchars
>= 0);
1084 if (STRING_MULTIBYTE (string
))
1086 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1087 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1092 string_char_and_length (p
, rest
, &len
);
1093 p
+= len
, rest
-= len
;
1094 xassert (rest
>= 0);
1096 BYTEPOS (pos
) += len
;
1100 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1106 /* Value is the text position, i.e. character and byte position,
1107 for character position CHARPOS in STRING. */
1109 static INLINE
struct text_pos
1110 string_pos (charpos
, string
)
1114 struct text_pos pos
;
1115 xassert (STRINGP (string
));
1116 xassert (charpos
>= 0);
1117 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1122 /* Value is a text position, i.e. character and byte position, for
1123 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1124 means recognize multibyte characters. */
1126 static struct text_pos
1127 c_string_pos (charpos
, s
, multibyte_p
)
1132 struct text_pos pos
;
1134 xassert (s
!= NULL
);
1135 xassert (charpos
>= 0);
1139 int rest
= strlen (s
), len
;
1141 SET_TEXT_POS (pos
, 0, 0);
1144 string_char_and_length (s
, rest
, &len
);
1145 s
+= len
, rest
-= len
;
1146 xassert (rest
>= 0);
1148 BYTEPOS (pos
) += len
;
1152 SET_TEXT_POS (pos
, charpos
, charpos
);
1158 /* Value is the number of characters in C string S. MULTIBYTE_P
1159 non-zero means recognize multibyte characters. */
1162 number_of_chars (s
, multibyte_p
)
1170 int rest
= strlen (s
), len
;
1171 unsigned char *p
= (unsigned char *) s
;
1173 for (nchars
= 0; rest
> 0; ++nchars
)
1175 string_char_and_length (p
, rest
, &len
);
1176 rest
-= len
, p
+= len
;
1180 nchars
= strlen (s
);
1186 /* Compute byte position NEWPOS->bytepos corresponding to
1187 NEWPOS->charpos. POS is a known position in string STRING.
1188 NEWPOS->charpos must be >= POS.charpos. */
1191 compute_string_pos (newpos
, pos
, string
)
1192 struct text_pos
*newpos
, pos
;
1195 xassert (STRINGP (string
));
1196 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1198 if (STRING_MULTIBYTE (string
))
1199 *newpos
= string_pos_nchars_ahead (pos
, string
,
1200 CHARPOS (*newpos
) - CHARPOS (pos
));
1202 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1207 /***********************************************************************
1208 Lisp form evaluation
1209 ***********************************************************************/
1211 /* Error handler for safe_eval and safe_call. */
1214 safe_eval_handler (arg
)
1217 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1222 /* Evaluate SEXPR and return the result, or nil if something went
1229 int count
= BINDING_STACK_SIZE ();
1230 struct gcpro gcpro1
;
1234 specbind (Qinhibit_redisplay
, Qt
);
1235 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, safe_eval_handler
);
1237 return unbind_to (count
, val
);
1241 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1242 Return the result, or nil if something went wrong. */
1245 safe_call (nargs
, args
)
1249 int count
= BINDING_STACK_SIZE ();
1251 struct gcpro gcpro1
;
1254 gcpro1
.nvars
= nargs
;
1255 specbind (Qinhibit_redisplay
, Qt
);
1256 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1259 return unbind_to (count
, val
);
1263 /* Call function FN with one argument ARG.
1264 Return the result, or nil if something went wrong. */
1267 safe_call1 (fn
, arg
)
1268 Lisp_Object fn
, arg
;
1270 Lisp_Object args
[2];
1273 return safe_call (2, args
);
1278 /***********************************************************************
1280 ***********************************************************************/
1284 /* Define CHECK_IT to perform sanity checks on iterators.
1285 This is for debugging. It is too slow to do unconditionally. */
1291 if (it
->method
== next_element_from_string
)
1293 xassert (STRINGP (it
->string
));
1294 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1296 else if (it
->method
== next_element_from_buffer
)
1298 /* Check that character and byte positions agree. */
1299 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1303 xassert (it
->current
.dpvec_index
>= 0);
1305 xassert (it
->current
.dpvec_index
< 0);
1308 #define CHECK_IT(IT) check_it ((IT))
1312 #define CHECK_IT(IT) (void) 0
1319 /* Check that the window end of window W is what we expect it
1320 to be---the last row in the current matrix displaying text. */
1323 check_window_end (w
)
1326 if (!MINI_WINDOW_P (w
)
1327 && !NILP (w
->window_end_valid
))
1329 struct glyph_row
*row
;
1330 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1331 XFASTINT (w
->window_end_vpos
)),
1333 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1334 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1338 #define CHECK_WINDOW_END(W) check_window_end ((W))
1340 #else /* not GLYPH_DEBUG */
1342 #define CHECK_WINDOW_END(W) (void) 0
1344 #endif /* not GLYPH_DEBUG */
1348 /***********************************************************************
1349 Iterator initialization
1350 ***********************************************************************/
1352 /* Initialize IT for displaying current_buffer in window W, starting
1353 at character position CHARPOS. CHARPOS < 0 means that no buffer
1354 position is specified which is useful when the iterator is assigned
1355 a position later. BYTEPOS is the byte position corresponding to
1356 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1358 If ROW is not null, calls to produce_glyphs with IT as parameter
1359 will produce glyphs in that row.
1361 BASE_FACE_ID is the id of a base face to use. It must be one of
1362 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1363 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1364 displaying the tool-bar.
1366 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1367 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1368 corresponding mode line glyph row of the desired matrix of W. */
1371 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1374 int charpos
, bytepos
;
1375 struct glyph_row
*row
;
1376 enum face_id base_face_id
;
1378 int highlight_region_p
;
1380 /* Some precondition checks. */
1381 xassert (w
!= NULL
&& it
!= NULL
);
1382 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1384 /* If face attributes have been changed since the last redisplay,
1385 free realized faces now because they depend on face definitions
1386 that might have changed. */
1387 if (face_change_count
)
1389 face_change_count
= 0;
1390 free_all_realized_faces (Qnil
);
1393 /* Use one of the mode line rows of W's desired matrix if
1397 if (base_face_id
== MODE_LINE_FACE_ID
)
1398 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1399 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1400 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1404 bzero (it
, sizeof *it
);
1405 it
->current
.overlay_string_index
= -1;
1406 it
->current
.dpvec_index
= -1;
1407 it
->base_face_id
= base_face_id
;
1409 /* The window in which we iterate over current_buffer: */
1410 XSETWINDOW (it
->window
, w
);
1412 it
->f
= XFRAME (w
->frame
);
1414 /* Extra space between lines (on window systems only). */
1415 if (base_face_id
== DEFAULT_FACE_ID
1416 && FRAME_WINDOW_P (it
->f
))
1418 if (NATNUMP (current_buffer
->extra_line_spacing
))
1419 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1420 else if (it
->f
->extra_line_spacing
> 0)
1421 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1424 /* If realized faces have been removed, e.g. because of face
1425 attribute changes of named faces, recompute them. */
1426 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1427 recompute_basic_faces (it
->f
);
1429 /* Current value of the `space-width', and 'height' properties. */
1430 it
->space_width
= Qnil
;
1431 it
->font_height
= Qnil
;
1433 /* Are control characters displayed as `^C'? */
1434 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1436 /* -1 means everything between a CR and the following line end
1437 is invisible. >0 means lines indented more than this value are
1439 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1440 ? XFASTINT (current_buffer
->selective_display
)
1441 : (!NILP (current_buffer
->selective_display
)
1443 it
->selective_display_ellipsis_p
1444 = !NILP (current_buffer
->selective_display_ellipses
);
1446 /* Display table to use. */
1447 it
->dp
= window_display_table (w
);
1449 /* Are multibyte characters enabled in current_buffer? */
1450 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1452 /* Non-zero if we should highlight the region. */
1454 = (!NILP (Vtransient_mark_mode
)
1455 && !NILP (current_buffer
->mark_active
)
1456 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1458 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1459 start and end of a visible region in window IT->w. Set both to
1460 -1 to indicate no region. */
1461 if (highlight_region_p
1462 /* Maybe highlight only in selected window. */
1463 && (/* Either show region everywhere. */
1464 highlight_nonselected_windows
1465 /* Or show region in the selected window. */
1466 || w
== XWINDOW (selected_window
)
1467 /* Or show the region if we are in the mini-buffer and W is
1468 the window the mini-buffer refers to. */
1469 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1470 && w
== XWINDOW (Vminibuf_scroll_window
))))
1472 int charpos
= marker_position (current_buffer
->mark
);
1473 it
->region_beg_charpos
= min (PT
, charpos
);
1474 it
->region_end_charpos
= max (PT
, charpos
);
1477 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1479 /* Get the position at which the redisplay_end_trigger hook should
1480 be run, if it is to be run at all. */
1481 if (MARKERP (w
->redisplay_end_trigger
)
1482 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1483 it
->redisplay_end_trigger_charpos
1484 = marker_position (w
->redisplay_end_trigger
);
1485 else if (INTEGERP (w
->redisplay_end_trigger
))
1486 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1488 /* Correct bogus values of tab_width. */
1489 it
->tab_width
= XINT (current_buffer
->tab_width
);
1490 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1493 /* Are lines in the display truncated? */
1494 it
->truncate_lines_p
1495 = (base_face_id
!= DEFAULT_FACE_ID
1496 || XINT (it
->w
->hscroll
)
1497 || (truncate_partial_width_windows
1498 && !WINDOW_FULL_WIDTH_P (it
->w
))
1499 || !NILP (current_buffer
->truncate_lines
));
1501 /* Get dimensions of truncation and continuation glyphs. These are
1502 displayed as bitmaps under X, so we don't need them for such
1504 if (!FRAME_WINDOW_P (it
->f
))
1506 if (it
->truncate_lines_p
)
1508 /* We will need the truncation glyph. */
1509 xassert (it
->glyph_row
== NULL
);
1510 produce_special_glyphs (it
, IT_TRUNCATION
);
1511 it
->truncation_pixel_width
= it
->pixel_width
;
1515 /* We will need the continuation glyph. */
1516 xassert (it
->glyph_row
== NULL
);
1517 produce_special_glyphs (it
, IT_CONTINUATION
);
1518 it
->continuation_pixel_width
= it
->pixel_width
;
1521 /* Reset these values to zero becaue the produce_special_glyphs
1522 above has changed them. */
1523 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1524 it
->phys_ascent
= it
->phys_descent
= 0;
1527 /* Set this after getting the dimensions of truncation and
1528 continuation glyphs, so that we don't produce glyphs when calling
1529 produce_special_glyphs, above. */
1530 it
->glyph_row
= row
;
1531 it
->area
= TEXT_AREA
;
1533 /* Get the dimensions of the display area. The display area
1534 consists of the visible window area plus a horizontally scrolled
1535 part to the left of the window. All x-values are relative to the
1536 start of this total display area. */
1537 if (base_face_id
!= DEFAULT_FACE_ID
)
1539 /* Mode lines, menu bar in terminal frames. */
1540 it
->first_visible_x
= 0;
1541 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1546 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1547 it
->last_visible_x
= (it
->first_visible_x
1548 + window_box_width (w
, TEXT_AREA
));
1550 /* If we truncate lines, leave room for the truncator glyph(s) at
1551 the right margin. Otherwise, leave room for the continuation
1552 glyph(s). Truncation and continuation glyphs are not inserted
1553 for window-based redisplay. */
1554 if (!FRAME_WINDOW_P (it
->f
))
1556 if (it
->truncate_lines_p
)
1557 it
->last_visible_x
-= it
->truncation_pixel_width
;
1559 it
->last_visible_x
-= it
->continuation_pixel_width
;
1562 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1563 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1566 /* Leave room for a border glyph. */
1567 if (!FRAME_WINDOW_P (it
->f
)
1568 && !WINDOW_RIGHTMOST_P (it
->w
))
1569 it
->last_visible_x
-= 1;
1571 it
->last_visible_y
= window_text_bottom_y (w
);
1573 /* For mode lines and alike, arrange for the first glyph having a
1574 left box line if the face specifies a box. */
1575 if (base_face_id
!= DEFAULT_FACE_ID
)
1579 it
->face_id
= base_face_id
;
1581 /* If we have a boxed mode line, make the first character appear
1582 with a left box line. */
1583 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1584 if (face
->box
!= FACE_NO_BOX
)
1585 it
->start_of_box_run_p
= 1;
1588 /* If a buffer position was specified, set the iterator there,
1589 getting overlays and face properties from that position. */
1592 it
->end_charpos
= ZV
;
1594 IT_CHARPOS (*it
) = charpos
;
1596 /* Compute byte position if not specified. */
1598 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1600 IT_BYTEPOS (*it
) = bytepos
;
1602 /* Compute faces etc. */
1603 reseat (it
, it
->current
.pos
, 1);
1610 /* Initialize IT for the display of window W with window start POS. */
1613 start_display (it
, w
, pos
)
1616 struct text_pos pos
;
1618 int start_at_line_beg_p
;
1619 struct glyph_row
*row
;
1620 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1623 row
= w
->desired_matrix
->rows
+ first_vpos
;
1624 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1625 first_y
= it
->current_y
;
1627 /* If window start is not at a line start, move back to the line
1628 start. This makes sure that we take continuation lines into
1630 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1631 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1632 if (!start_at_line_beg_p
)
1633 reseat_at_previous_visible_line_start (it
);
1635 /* If window start is not at a line start, skip forward to POS to
1636 get the correct continuation_lines_width and current_x. */
1637 if (!start_at_line_beg_p
)
1639 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1641 /* If lines are continued, this line may end in the middle of a
1642 multi-glyph character (e.g. a control character displayed as
1643 \003, or in the middle of an overlay string). In this case
1644 move_it_to above will not have taken us to the start of
1645 the continuation line but to the end of the continued line. */
1646 if (!it
->truncate_lines_p
)
1648 if (it
->current_x
> 0)
1650 if (it
->current
.dpvec_index
>= 0
1651 || it
->current
.overlay_string_index
>= 0)
1653 set_iterator_to_next (it
, 1);
1654 move_it_in_display_line_to (it
, -1, -1, 0);
1657 it
->continuation_lines_width
+= it
->current_x
;
1660 /* We're starting a new display line, not affected by the
1661 height of the continued line, so clear the appropriate
1662 fields in the iterator structure. */
1663 it
->max_ascent
= it
->max_descent
= 0;
1664 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1667 it
->current_y
= first_y
;
1669 it
->current_x
= it
->hpos
= 0;
1672 #if 0 /* Don't assert the following because start_display is sometimes
1673 called intentionally with a window start that is not at a
1674 line start. Please leave this code in as a comment. */
1676 /* Window start should be on a line start, now. */
1677 xassert (it
->continuation_lines_width
1678 || IT_CHARPOS (it
) == BEGV
1679 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1684 /* Initialize IT for stepping through current_buffer in window W,
1685 starting at position POS that includes overlay string and display
1686 vector/ control character translation position information. */
1689 init_from_display_pos (it
, w
, pos
)
1692 struct display_pos
*pos
;
1694 /* Keep in mind: the call to reseat in init_iterator skips invisible
1695 text, so we might end up at a position different from POS. This
1696 is only a problem when POS is a row start after a newline and an
1697 overlay starts there with an after-string, and the overlay has an
1698 invisible property. Since we don't skip invisible text in
1699 display_line and elsewhere immediately after consuming the
1700 newline before the row start, such a POS will not be in a string,
1701 but the call to init_iterator below will move us to the
1703 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1704 NULL
, DEFAULT_FACE_ID
);
1706 /* If position is within an overlay string, set up IT to
1707 the right overlay string. */
1708 if (pos
->overlay_string_index
>= 0)
1712 /* We already have the first chunk of overlay strings in
1713 IT->overlay_strings. Load more until the one for
1714 pos->overlay_string_index is in IT->overlay_strings. */
1715 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1717 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1718 it
->current
.overlay_string_index
= 0;
1721 load_overlay_strings (it
);
1722 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1726 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1727 relative_index
= (it
->current
.overlay_string_index
1728 % OVERLAY_STRING_CHUNK_SIZE
);
1729 it
->string
= it
->overlay_strings
[relative_index
];
1730 xassert (STRINGP (it
->string
));
1731 it
->current
.string_pos
= pos
->string_pos
;
1732 it
->method
= next_element_from_string
;
1734 else if (it
->current
.overlay_string_index
>= 0)
1736 /* If POS says we're already after an overlay string ending at
1737 POS, make sure to pop the iterator because it will be in
1738 front of that overlay string. When POS is ZV, we've thereby
1739 also ``processed'' overlay strings at ZV. */
1741 it
->current
.overlay_string_index
= -1;
1742 it
->method
= next_element_from_buffer
;
1743 if (CHARPOS (pos
->pos
) == ZV
)
1744 it
->overlay_strings_at_end_processed_p
= 1;
1747 if (CHARPOS (pos
->string_pos
) >= 0)
1749 /* Recorded position is not in an overlay string, but in another
1750 string. This can only be a string from a `display' property.
1751 IT should already be filled with that string. */
1752 it
->current
.string_pos
= pos
->string_pos
;
1753 xassert (STRINGP (it
->string
));
1756 /* Restore position in display vector translations or control
1757 character translations. */
1758 if (pos
->dpvec_index
>= 0)
1760 /* This fills IT->dpvec. */
1761 get_next_display_element (it
);
1762 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1763 it
->current
.dpvec_index
= pos
->dpvec_index
;
1770 /* Initialize IT for stepping through current_buffer in window W
1771 starting at ROW->start. */
1774 init_to_row_start (it
, w
, row
)
1777 struct glyph_row
*row
;
1779 init_from_display_pos (it
, w
, &row
->start
);
1780 it
->continuation_lines_width
= row
->continuation_lines_width
;
1785 /* Initialize IT for stepping through current_buffer in window W
1786 starting in the line following ROW, i.e. starting at ROW->end. */
1789 init_to_row_end (it
, w
, row
)
1792 struct glyph_row
*row
;
1794 init_from_display_pos (it
, w
, &row
->end
);
1796 if (row
->continued_p
)
1797 it
->continuation_lines_width
= (row
->continuation_lines_width
1798 + row
->pixel_width
);
1805 /***********************************************************************
1807 ***********************************************************************/
1809 /* Called when IT reaches IT->stop_charpos. Handle text property and
1810 overlay changes. Set IT->stop_charpos to the next position where
1817 enum prop_handled handled
;
1818 int handle_overlay_change_p
= 1;
1822 it
->current
.dpvec_index
= -1;
1826 handled
= HANDLED_NORMALLY
;
1828 /* Call text property handlers. */
1829 for (p
= it_props
; p
->handler
; ++p
)
1831 handled
= p
->handler (it
);
1833 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1835 else if (handled
== HANDLED_RETURN
)
1837 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1838 handle_overlay_change_p
= 0;
1841 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1843 /* Don't check for overlay strings below when set to deliver
1844 characters from a display vector. */
1845 if (it
->method
== next_element_from_display_vector
)
1846 handle_overlay_change_p
= 0;
1848 /* Handle overlay changes. */
1849 if (handle_overlay_change_p
)
1850 handled
= handle_overlay_change (it
);
1852 /* Determine where to stop next. */
1853 if (handled
== HANDLED_NORMALLY
)
1854 compute_stop_pos (it
);
1857 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1861 /* Compute IT->stop_charpos from text property and overlay change
1862 information for IT's current position. */
1865 compute_stop_pos (it
)
1868 register INTERVAL iv
, next_iv
;
1869 Lisp_Object object
, limit
, position
;
1871 /* If nowhere else, stop at the end. */
1872 it
->stop_charpos
= it
->end_charpos
;
1874 if (STRINGP (it
->string
))
1876 /* Strings are usually short, so don't limit the search for
1878 object
= it
->string
;
1880 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1886 /* If next overlay change is in front of the current stop pos
1887 (which is IT->end_charpos), stop there. Note: value of
1888 next_overlay_change is point-max if no overlay change
1890 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1891 if (charpos
< it
->stop_charpos
)
1892 it
->stop_charpos
= charpos
;
1894 /* If showing the region, we have to stop at the region
1895 start or end because the face might change there. */
1896 if (it
->region_beg_charpos
> 0)
1898 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1899 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1900 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1901 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1904 /* Set up variables for computing the stop position from text
1905 property changes. */
1906 XSETBUFFER (object
, current_buffer
);
1907 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1908 XSETFASTINT (position
, IT_CHARPOS (*it
));
1912 /* Get the interval containing IT's position. Value is a null
1913 interval if there isn't such an interval. */
1914 iv
= validate_interval_range (object
, &position
, &position
, 0);
1915 if (!NULL_INTERVAL_P (iv
))
1917 Lisp_Object values_here
[LAST_PROP_IDX
];
1920 /* Get properties here. */
1921 for (p
= it_props
; p
->handler
; ++p
)
1922 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1924 /* Look for an interval following iv that has different
1926 for (next_iv
= next_interval (iv
);
1927 (!NULL_INTERVAL_P (next_iv
)
1929 || XFASTINT (limit
) > next_iv
->position
));
1930 next_iv
= next_interval (next_iv
))
1932 for (p
= it_props
; p
->handler
; ++p
)
1934 Lisp_Object new_value
;
1936 new_value
= textget (next_iv
->plist
, *p
->name
);
1937 if (!EQ (values_here
[p
->idx
], new_value
))
1945 if (!NULL_INTERVAL_P (next_iv
))
1947 if (INTEGERP (limit
)
1948 && next_iv
->position
>= XFASTINT (limit
))
1949 /* No text property change up to limit. */
1950 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1952 /* Text properties change in next_iv. */
1953 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1957 xassert (STRINGP (it
->string
)
1958 || (it
->stop_charpos
>= BEGV
1959 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1963 /* Return the position of the next overlay change after POS in
1964 current_buffer. Value is point-max if no overlay change
1965 follows. This is like `next-overlay-change' but doesn't use
1969 next_overlay_change (pos
)
1974 Lisp_Object
*overlays
;
1978 /* Get all overlays at the given position. */
1980 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1981 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1982 if (noverlays
> len
)
1985 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1986 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1989 /* If any of these overlays ends before endpos,
1990 use its ending point instead. */
1991 for (i
= 0; i
< noverlays
; ++i
)
1996 oend
= OVERLAY_END (overlays
[i
]);
1997 oendpos
= OVERLAY_POSITION (oend
);
1998 endpos
= min (endpos
, oendpos
);
2006 /***********************************************************************
2008 ***********************************************************************/
2010 /* Handle changes in the `fontified' property of the current buffer by
2011 calling hook functions from Qfontification_functions to fontify
2014 static enum prop_handled
2015 handle_fontified_prop (it
)
2018 Lisp_Object prop
, pos
;
2019 enum prop_handled handled
= HANDLED_NORMALLY
;
2021 /* Get the value of the `fontified' property at IT's current buffer
2022 position. (The `fontified' property doesn't have a special
2023 meaning in strings.) If the value is nil, call functions from
2024 Qfontification_functions. */
2025 if (!STRINGP (it
->string
)
2027 && !NILP (Vfontification_functions
)
2028 && !NILP (Vrun_hooks
)
2029 && (pos
= make_number (IT_CHARPOS (*it
)),
2030 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2033 int count
= BINDING_STACK_SIZE ();
2036 val
= Vfontification_functions
;
2037 specbind (Qfontification_functions
, Qnil
);
2038 specbind (Qafter_change_functions
, Qnil
);
2040 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2041 safe_call1 (val
, pos
);
2044 Lisp_Object globals
, fn
;
2045 struct gcpro gcpro1
, gcpro2
;
2048 GCPRO2 (val
, globals
);
2050 for (; CONSP (val
); val
= XCDR (val
))
2056 /* A value of t indicates this hook has a local
2057 binding; it means to run the global binding too.
2058 In a global value, t should not occur. If it
2059 does, we must ignore it to avoid an endless
2061 for (globals
= Fdefault_value (Qfontification_functions
);
2063 globals
= XCDR (globals
))
2065 fn
= XCAR (globals
);
2067 safe_call1 (fn
, pos
);
2071 safe_call1 (fn
, pos
);
2077 unbind_to (count
, Qnil
);
2079 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2080 something. This avoids an endless loop if they failed to
2081 fontify the text for which reason ever. */
2082 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2083 handled
= HANDLED_RECOMPUTE_PROPS
;
2091 /***********************************************************************
2093 ***********************************************************************/
2095 /* Set up iterator IT from face properties at its current position.
2096 Called from handle_stop. */
2098 static enum prop_handled
2099 handle_face_prop (it
)
2102 int new_face_id
, next_stop
;
2104 if (!STRINGP (it
->string
))
2107 = face_at_buffer_position (it
->w
,
2109 it
->region_beg_charpos
,
2110 it
->region_end_charpos
,
2113 + TEXT_PROP_DISTANCE_LIMIT
),
2116 /* Is this a start of a run of characters with box face?
2117 Caveat: this can be called for a freshly initialized
2118 iterator; face_id is -1 is this case. We know that the new
2119 face will not change until limit, i.e. if the new face has a
2120 box, all characters up to limit will have one. But, as
2121 usual, we don't know whether limit is really the end. */
2122 if (new_face_id
!= it
->face_id
)
2124 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2126 /* If new face has a box but old face has not, this is
2127 the start of a run of characters with box, i.e. it has
2128 a shadow on the left side. The value of face_id of the
2129 iterator will be -1 if this is the initial call that gets
2130 the face. In this case, we have to look in front of IT's
2131 position and see whether there is a face != new_face_id. */
2132 it
->start_of_box_run_p
2133 = (new_face
->box
!= FACE_NO_BOX
2134 && (it
->face_id
>= 0
2135 || IT_CHARPOS (*it
) == BEG
2136 || new_face_id
!= face_before_it_pos (it
)));
2137 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2142 int base_face_id
, bufpos
;
2144 if (it
->current
.overlay_string_index
>= 0)
2145 bufpos
= IT_CHARPOS (*it
);
2149 /* For strings from a buffer, i.e. overlay strings or strings
2150 from a `display' property, use the face at IT's current
2151 buffer position as the base face to merge with, so that
2152 overlay strings appear in the same face as surrounding
2153 text, unless they specify their own faces. */
2154 base_face_id
= underlying_face_id (it
);
2156 new_face_id
= face_at_string_position (it
->w
,
2158 IT_STRING_CHARPOS (*it
),
2160 it
->region_beg_charpos
,
2161 it
->region_end_charpos
,
2165 #if 0 /* This shouldn't be neccessary. Let's check it. */
2166 /* If IT is used to display a mode line we would really like to
2167 use the mode line face instead of the frame's default face. */
2168 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2169 && new_face_id
== DEFAULT_FACE_ID
)
2170 new_face_id
= MODE_LINE_FACE_ID
;
2173 /* Is this a start of a run of characters with box? Caveat:
2174 this can be called for a freshly allocated iterator; face_id
2175 is -1 is this case. We know that the new face will not
2176 change until the next check pos, i.e. if the new face has a
2177 box, all characters up to that position will have a
2178 box. But, as usual, we don't know whether that position
2179 is really the end. */
2180 if (new_face_id
!= it
->face_id
)
2182 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2183 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2185 /* If new face has a box but old face hasn't, this is the
2186 start of a run of characters with box, i.e. it has a
2187 shadow on the left side. */
2188 it
->start_of_box_run_p
2189 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2190 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2194 it
->face_id
= new_face_id
;
2195 return HANDLED_NORMALLY
;
2199 /* Return the ID of the face ``underlying'' IT's current position,
2200 which is in a string. If the iterator is associated with a
2201 buffer, return the face at IT's current buffer position.
2202 Otherwise, use the iterator's base_face_id. */
2205 underlying_face_id (it
)
2208 int face_id
= it
->base_face_id
, i
;
2210 xassert (STRINGP (it
->string
));
2212 for (i
= it
->sp
- 1; i
>= 0; --i
)
2213 if (NILP (it
->stack
[i
].string
))
2214 face_id
= it
->stack
[i
].face_id
;
2220 /* Compute the face one character before or after the current position
2221 of IT. BEFORE_P non-zero means get the face in front of IT's
2222 position. Value is the id of the face. */
2225 face_before_or_after_it_pos (it
, before_p
)
2230 int next_check_charpos
;
2231 struct text_pos pos
;
2233 xassert (it
->s
== NULL
);
2235 if (STRINGP (it
->string
))
2237 int bufpos
, base_face_id
;
2239 /* No face change past the end of the string (for the case
2240 we are padding with spaces). No face change before the
2242 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2243 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2246 /* Set pos to the position before or after IT's current position. */
2248 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2250 /* For composition, we must check the character after the
2252 pos
= (it
->what
== IT_COMPOSITION
2253 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2254 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2256 if (it
->current
.overlay_string_index
>= 0)
2257 bufpos
= IT_CHARPOS (*it
);
2261 base_face_id
= underlying_face_id (it
);
2263 /* Get the face for ASCII, or unibyte. */
2264 face_id
= face_at_string_position (it
->w
,
2268 it
->region_beg_charpos
,
2269 it
->region_end_charpos
,
2270 &next_check_charpos
,
2273 /* Correct the face for charsets different from ASCII. Do it
2274 for the multibyte case only. The face returned above is
2275 suitable for unibyte text if IT->string is unibyte. */
2276 if (STRING_MULTIBYTE (it
->string
))
2278 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2279 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2281 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2283 c
= string_char_and_length (p
, rest
, &len
);
2284 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2289 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2290 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2293 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2294 pos
= it
->current
.pos
;
2297 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2300 if (it
->what
== IT_COMPOSITION
)
2301 /* For composition, we must check the position after the
2303 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2305 INC_TEXT_POS (pos
, it
->multibyte_p
);
2308 /* Determine face for CHARSET_ASCII, or unibyte. */
2309 face_id
= face_at_buffer_position (it
->w
,
2311 it
->region_beg_charpos
,
2312 it
->region_end_charpos
,
2313 &next_check_charpos
,
2316 /* Correct the face for charsets different from ASCII. Do it
2317 for the multibyte case only. The face returned above is
2318 suitable for unibyte text if current_buffer is unibyte. */
2319 if (it
->multibyte_p
)
2321 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2322 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2323 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2332 /***********************************************************************
2334 ***********************************************************************/
2336 /* Set up iterator IT from invisible properties at its current
2337 position. Called from handle_stop. */
2339 static enum prop_handled
2340 handle_invisible_prop (it
)
2343 enum prop_handled handled
= HANDLED_NORMALLY
;
2345 if (STRINGP (it
->string
))
2347 extern Lisp_Object Qinvisible
;
2348 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2350 /* Get the value of the invisible text property at the
2351 current position. Value will be nil if there is no such
2353 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2354 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2357 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2359 handled
= HANDLED_RECOMPUTE_PROPS
;
2361 /* Get the position at which the next change of the
2362 invisible text property can be found in IT->string.
2363 Value will be nil if the property value is the same for
2364 all the rest of IT->string. */
2365 XSETINT (limit
, XSTRING (it
->string
)->size
);
2366 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2369 /* Text at current position is invisible. The next
2370 change in the property is at position end_charpos.
2371 Move IT's current position to that position. */
2372 if (INTEGERP (end_charpos
)
2373 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2375 struct text_pos old
;
2376 old
= it
->current
.string_pos
;
2377 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2378 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2382 /* The rest of the string is invisible. If this is an
2383 overlay string, proceed with the next overlay string
2384 or whatever comes and return a character from there. */
2385 if (it
->current
.overlay_string_index
>= 0)
2387 next_overlay_string (it
);
2388 /* Don't check for overlay strings when we just
2389 finished processing them. */
2390 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2394 struct Lisp_String
*s
= XSTRING (it
->string
);
2395 IT_STRING_CHARPOS (*it
) = s
->size
;
2396 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2403 int visible_p
, newpos
, next_stop
;
2404 Lisp_Object pos
, prop
;
2406 /* First of all, is there invisible text at this position? */
2407 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2408 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2410 /* If we are on invisible text, skip over it. */
2411 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2412 && IT_CHARPOS (*it
) < it
->end_charpos
)
2414 /* Record whether we have to display an ellipsis for the
2416 int display_ellipsis_p
2417 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2419 handled
= HANDLED_RECOMPUTE_PROPS
;
2421 /* Loop skipping over invisible text. The loop is left at
2422 ZV or with IT on the first char being visible again. */
2425 /* Try to skip some invisible text. Return value is the
2426 position reached which can be equal to IT's position
2427 if there is nothing invisible here. This skips both
2428 over invisible text properties and overlays with
2429 invisible property. */
2430 newpos
= skip_invisible (IT_CHARPOS (*it
),
2431 &next_stop
, ZV
, it
->window
);
2433 /* If we skipped nothing at all we weren't at invisible
2434 text in the first place. If everything to the end of
2435 the buffer was skipped, end the loop. */
2436 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2440 /* We skipped some characters but not necessarily
2441 all there are. Check if we ended up on visible
2442 text. Fget_char_property returns the property of
2443 the char before the given position, i.e. if we
2444 get visible_p = 1, this means that the char at
2445 newpos is visible. */
2446 XSETFASTINT (pos
, newpos
);
2447 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2448 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2451 /* If we ended up on invisible text, proceed to
2452 skip starting with next_stop. */
2454 IT_CHARPOS (*it
) = next_stop
;
2458 /* The position newpos is now either ZV or on visible text. */
2459 IT_CHARPOS (*it
) = newpos
;
2460 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2462 /* Maybe return `...' next for the end of the invisible text. */
2463 if (display_ellipsis_p
)
2466 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2468 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2469 it
->dpvec
= v
->contents
;
2470 it
->dpend
= v
->contents
+ v
->size
;
2474 /* Default `...'. */
2475 it
->dpvec
= default_invis_vector
;
2476 it
->dpend
= default_invis_vector
+ 3;
2479 /* The ellipsis display does not replace the display of
2480 the character at the new position. Indicate this by
2481 setting IT->dpvec_char_len to zero. */
2482 it
->dpvec_char_len
= 0;
2484 it
->current
.dpvec_index
= 0;
2485 it
->method
= next_element_from_display_vector
;
2495 /***********************************************************************
2497 ***********************************************************************/
2499 /* Set up iterator IT from `display' property at its current position.
2500 Called from handle_stop. */
2502 static enum prop_handled
2503 handle_display_prop (it
)
2506 Lisp_Object prop
, object
;
2507 struct text_pos
*position
;
2508 int space_or_image_found_p
;
2510 if (STRINGP (it
->string
))
2512 object
= it
->string
;
2513 position
= &it
->current
.string_pos
;
2518 position
= &it
->current
.pos
;
2521 /* Reset those iterator values set from display property values. */
2522 it
->font_height
= Qnil
;
2523 it
->space_width
= Qnil
;
2526 /* We don't support recursive `display' properties, i.e. string
2527 values that have a string `display' property, that have a string
2528 `display' property etc. */
2529 if (!it
->string_from_display_prop_p
)
2530 it
->area
= TEXT_AREA
;
2532 prop
= Fget_char_property (make_number (position
->charpos
),
2535 return HANDLED_NORMALLY
;
2537 space_or_image_found_p
= 0;
2539 && CONSP (XCAR (prop
))
2540 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2542 /* A list of sub-properties. */
2543 while (CONSP (prop
))
2545 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2546 space_or_image_found_p
= 1;
2550 else if (VECTORP (prop
))
2553 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2554 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2556 space_or_image_found_p
= 1;
2560 if (handle_single_display_prop (it
, prop
, object
, position
))
2561 space_or_image_found_p
= 1;
2564 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2568 /* Value is the position of the end of the `display' property starting
2569 at START_POS in OBJECT. */
2571 static struct text_pos
2572 display_prop_end (it
, object
, start_pos
)
2575 struct text_pos start_pos
;
2578 struct text_pos end_pos
;
2580 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2581 Qdisplay
, object
, Qnil
);
2582 CHARPOS (end_pos
) = XFASTINT (end
);
2583 if (STRINGP (object
))
2584 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2586 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2592 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2593 is the object in which the `display' property was found. *POSITION
2594 is the position at which it was found.
2596 If PROP is a `space' or `image' sub-property, set *POSITION to the
2597 end position of the `display' property.
2599 Value is non-zero if a `space' or `image' property value was found. */
2602 handle_single_display_prop (it
, prop
, object
, position
)
2606 struct text_pos
*position
;
2609 int space_or_image_found_p
= 0;
2612 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2613 evaluated. If the result is nil, VALUE is ignored. */
2615 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2624 if (!NILP (form
) && !EQ (form
, Qt
))
2626 struct gcpro gcpro1
;
2627 struct text_pos end_pos
, pt
;
2630 end_pos
= display_prop_end (it
, object
, *position
);
2632 /* Temporarily set point to the end position, and then evaluate
2633 the form. This makes `(eolp)' work as FORM. */
2634 if (BUFFERP (object
))
2637 BYTEPOS (pt
) = PT_BYTE
;
2638 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2641 form
= safe_eval (form
);
2643 if (BUFFERP (object
))
2644 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2652 && EQ (XCAR (prop
), Qheight
)
2653 && CONSP (XCDR (prop
)))
2655 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2658 /* `(height HEIGHT)'. */
2659 it
->font_height
= XCAR (XCDR (prop
));
2660 if (!NILP (it
->font_height
))
2662 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2663 int new_height
= -1;
2665 if (CONSP (it
->font_height
)
2666 && (EQ (XCAR (it
->font_height
), Qplus
)
2667 || EQ (XCAR (it
->font_height
), Qminus
))
2668 && CONSP (XCDR (it
->font_height
))
2669 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2671 /* `(+ N)' or `(- N)' where N is an integer. */
2672 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2673 if (EQ (XCAR (it
->font_height
), Qplus
))
2675 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2677 else if (FUNCTIONP (it
->font_height
))
2679 /* Call function with current height as argument.
2680 Value is the new height. */
2682 height
= safe_call1 (it
->font_height
,
2683 face
->lface
[LFACE_HEIGHT_INDEX
]);
2684 if (NUMBERP (height
))
2685 new_height
= XFLOATINT (height
);
2687 else if (NUMBERP (it
->font_height
))
2689 /* Value is a multiple of the canonical char height. */
2692 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2693 new_height
= (XFLOATINT (it
->font_height
)
2694 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2698 /* Evaluate IT->font_height with `height' bound to the
2699 current specified height to get the new height. */
2701 int count
= BINDING_STACK_SIZE ();
2703 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2704 value
= safe_eval (it
->font_height
);
2705 unbind_to (count
, Qnil
);
2707 if (NUMBERP (value
))
2708 new_height
= XFLOATINT (value
);
2712 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2715 else if (CONSP (prop
)
2716 && EQ (XCAR (prop
), Qspace_width
)
2717 && CONSP (XCDR (prop
)))
2719 /* `(space_width WIDTH)'. */
2720 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2723 value
= XCAR (XCDR (prop
));
2724 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2725 it
->space_width
= value
;
2727 else if (CONSP (prop
)
2728 && EQ (XCAR (prop
), Qraise
)
2729 && CONSP (XCDR (prop
)))
2731 /* `(raise FACTOR)'. */
2732 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2735 #ifdef HAVE_WINDOW_SYSTEM
2736 value
= XCAR (XCDR (prop
));
2737 if (NUMBERP (value
))
2739 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2740 it
->voffset
= - (XFLOATINT (value
)
2741 * (FONT_HEIGHT (face
->font
)));
2743 #endif /* HAVE_WINDOW_SYSTEM */
2745 else if (!it
->string_from_display_prop_p
)
2747 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2748 VALUE) or `((margin nil) VALUE)' or VALUE. */
2749 Lisp_Object location
, value
;
2750 struct text_pos start_pos
;
2753 /* Characters having this form of property are not displayed, so
2754 we have to find the end of the property. */
2755 start_pos
= *position
;
2756 *position
= display_prop_end (it
, object
, start_pos
);
2759 /* Let's stop at the new position and assume that all
2760 text properties change there. */
2761 it
->stop_charpos
= position
->charpos
;
2763 location
= Qunbound
;
2764 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2768 value
= XCDR (prop
);
2770 value
= XCAR (value
);
2773 if (EQ (XCAR (tem
), Qmargin
)
2774 && (tem
= XCDR (tem
),
2775 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2777 || EQ (tem
, Qleft_margin
)
2778 || EQ (tem
, Qright_margin
))))
2782 if (EQ (location
, Qunbound
))
2788 #ifdef HAVE_WINDOW_SYSTEM
2789 if (FRAME_TERMCAP_P (it
->f
))
2790 valid_p
= STRINGP (value
);
2792 valid_p
= (STRINGP (value
)
2793 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2794 || valid_image_p (value
));
2795 #else /* not HAVE_WINDOW_SYSTEM */
2796 valid_p
= STRINGP (value
);
2797 #endif /* not HAVE_WINDOW_SYSTEM */
2799 if ((EQ (location
, Qleft_margin
)
2800 || EQ (location
, Qright_margin
)
2804 space_or_image_found_p
= 1;
2806 /* Save current settings of IT so that we can restore them
2807 when we are finished with the glyph property value. */
2810 if (NILP (location
))
2811 it
->area
= TEXT_AREA
;
2812 else if (EQ (location
, Qleft_margin
))
2813 it
->area
= LEFT_MARGIN_AREA
;
2815 it
->area
= RIGHT_MARGIN_AREA
;
2817 if (STRINGP (value
))
2820 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2821 it
->current
.overlay_string_index
= -1;
2822 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2823 it
->end_charpos
= it
->string_nchars
2824 = XSTRING (it
->string
)->size
;
2825 it
->method
= next_element_from_string
;
2826 it
->stop_charpos
= 0;
2827 it
->string_from_display_prop_p
= 1;
2829 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2831 it
->method
= next_element_from_stretch
;
2833 it
->current
.pos
= it
->position
= start_pos
;
2835 #ifdef HAVE_WINDOW_SYSTEM
2838 it
->what
= IT_IMAGE
;
2839 it
->image_id
= lookup_image (it
->f
, value
);
2840 it
->position
= start_pos
;
2841 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2842 it
->method
= next_element_from_image
;
2844 /* Say that we haven't consumed the characters with
2845 `display' property yet. The call to pop_it in
2846 set_iterator_to_next will clean this up. */
2847 *position
= start_pos
;
2849 #endif /* HAVE_WINDOW_SYSTEM */
2852 /* Invalid property or property not supported. Restore
2853 the position to what it was before. */
2854 *position
= start_pos
;
2857 return space_or_image_found_p
;
2861 /* Check if PROP is a display sub-property value whose text should be
2862 treated as intangible. */
2865 single_display_prop_intangible_p (prop
)
2868 /* Skip over `when FORM'. */
2869 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2880 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
2881 we don't need to treat text as intangible. */
2882 if (EQ (XCAR (prop
), Qmargin
))
2890 || EQ (XCAR (prop
), Qleft_margin
)
2891 || EQ (XCAR (prop
), Qright_margin
))
2895 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
2899 /* Check if PROP is a display property value whose text should be
2900 treated as intangible. */
2903 display_prop_intangible_p (prop
)
2907 && CONSP (XCAR (prop
))
2908 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2910 /* A list of sub-properties. */
2911 while (CONSP (prop
))
2913 if (single_display_prop_intangible_p (XCAR (prop
)))
2918 else if (VECTORP (prop
))
2920 /* A vector of sub-properties. */
2922 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2923 if (single_display_prop_intangible_p (XVECTOR (prop
)->contents
[i
]))
2927 return single_display_prop_intangible_p (prop
);
2933 /***********************************************************************
2934 `composition' property
2935 ***********************************************************************/
2937 /* Set up iterator IT from `composition' property at its current
2938 position. Called from handle_stop. */
2940 static enum prop_handled
2941 handle_composition_prop (it
)
2944 Lisp_Object prop
, string
;
2945 int pos
, pos_byte
, end
;
2946 enum prop_handled handled
= HANDLED_NORMALLY
;
2948 if (STRINGP (it
->string
))
2950 pos
= IT_STRING_CHARPOS (*it
);
2951 pos_byte
= IT_STRING_BYTEPOS (*it
);
2952 string
= it
->string
;
2956 pos
= IT_CHARPOS (*it
);
2957 pos_byte
= IT_BYTEPOS (*it
);
2961 /* If there's a valid composition and point is not inside of the
2962 composition (in the case that the composition is from the current
2963 buffer), draw a glyph composed from the composition components. */
2964 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2965 && COMPOSITION_VALID_P (pos
, end
, prop
)
2966 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2968 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2972 it
->method
= next_element_from_composition
;
2974 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2975 /* For a terminal, draw only the first character of the
2977 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2978 it
->len
= (STRINGP (it
->string
)
2979 ? string_char_to_byte (it
->string
, end
)
2980 : CHAR_TO_BYTE (end
)) - pos_byte
;
2981 it
->stop_charpos
= end
;
2982 handled
= HANDLED_RETURN
;
2991 /***********************************************************************
2993 ***********************************************************************/
2995 /* The following structure is used to record overlay strings for
2996 later sorting in load_overlay_strings. */
2998 struct overlay_entry
3000 Lisp_Object overlay
;
3007 /* Set up iterator IT from overlay strings at its current position.
3008 Called from handle_stop. */
3010 static enum prop_handled
3011 handle_overlay_change (it
)
3014 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
3015 return HANDLED_RECOMPUTE_PROPS
;
3017 return HANDLED_NORMALLY
;
3021 /* Set up the next overlay string for delivery by IT, if there is an
3022 overlay string to deliver. Called by set_iterator_to_next when the
3023 end of the current overlay string is reached. If there are more
3024 overlay strings to display, IT->string and
3025 IT->current.overlay_string_index are set appropriately here.
3026 Otherwise IT->string is set to nil. */
3029 next_overlay_string (it
)
3032 ++it
->current
.overlay_string_index
;
3033 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3035 /* No more overlay strings. Restore IT's settings to what
3036 they were before overlay strings were processed, and
3037 continue to deliver from current_buffer. */
3039 xassert (it
->stop_charpos
>= BEGV
3040 && it
->stop_charpos
<= it
->end_charpos
);
3042 it
->current
.overlay_string_index
= -1;
3043 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3044 it
->n_overlay_strings
= 0;
3045 it
->method
= next_element_from_buffer
;
3047 /* If we're at the end of the buffer, record that we have
3048 processed the overlay strings there already, so that
3049 next_element_from_buffer doesn't try it again. */
3050 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3051 it
->overlay_strings_at_end_processed_p
= 1;
3055 /* There are more overlay strings to process. If
3056 IT->current.overlay_string_index has advanced to a position
3057 where we must load IT->overlay_strings with more strings, do
3059 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3061 if (it
->current
.overlay_string_index
&& i
== 0)
3062 load_overlay_strings (it
);
3064 /* Initialize IT to deliver display elements from the overlay
3066 it
->string
= it
->overlay_strings
[i
];
3067 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3068 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3069 it
->method
= next_element_from_string
;
3070 it
->stop_charpos
= 0;
3077 /* Compare two overlay_entry structures E1 and E2. Used as a
3078 comparison function for qsort in load_overlay_strings. Overlay
3079 strings for the same position are sorted so that
3081 1. All after-strings come in front of before-strings, except
3082 when they come from the same overlay.
3084 2. Within after-strings, strings are sorted so that overlay strings
3085 from overlays with higher priorities come first.
3087 2. Within before-strings, strings are sorted so that overlay
3088 strings from overlays with higher priorities come last.
3090 Value is analogous to strcmp. */
3094 compare_overlay_entries (e1
, e2
)
3097 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3098 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3101 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3103 /* Let after-strings appear in front of before-strings if
3104 they come from different overlays. */
3105 if (EQ (entry1
->overlay
, entry2
->overlay
))
3106 result
= entry1
->after_string_p
? 1 : -1;
3108 result
= entry1
->after_string_p
? -1 : 1;
3110 else if (entry1
->after_string_p
)
3111 /* After-strings sorted in order of decreasing priority. */
3112 result
= entry2
->priority
- entry1
->priority
;
3114 /* Before-strings sorted in order of increasing priority. */
3115 result
= entry1
->priority
- entry2
->priority
;
3121 /* Load the vector IT->overlay_strings with overlay strings from IT's
3122 current buffer position. Set IT->n_overlays to the total number of
3123 overlay strings found.
3125 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3126 a time. On entry into load_overlay_strings,
3127 IT->current.overlay_string_index gives the number of overlay
3128 strings that have already been loaded by previous calls to this
3131 IT->add_overlay_start contains an additional overlay start
3132 position to consider for taking overlay strings from, if non-zero.
3133 This position comes into play when the overlay has an `invisible'
3134 property, and both before and after-strings. When we've skipped to
3135 the end of the overlay, because of its `invisible' property, we
3136 nevertheless want its before-string to appear.
3137 IT->add_overlay_start will contain the overlay start position
3140 Overlay strings are sorted so that after-string strings come in
3141 front of before-string strings. Within before and after-strings,
3142 strings are sorted by overlay priority. See also function
3143 compare_overlay_entries. */
3146 load_overlay_strings (it
)
3149 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3150 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3153 int n
= 0, i
, j
, invis_p
;
3154 struct overlay_entry
*entries
3155 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3156 int charpos
= IT_CHARPOS (*it
);
3158 /* Append the overlay string STRING of overlay OVERLAY to vector
3159 `entries' which has size `size' and currently contains `n'
3160 elements. AFTER_P non-zero means STRING is an after-string of
3162 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3165 Lisp_Object priority; \
3169 int new_size = 2 * size; \
3170 struct overlay_entry *old = entries; \
3172 (struct overlay_entry *) alloca (new_size \
3173 * sizeof *entries); \
3174 bcopy (old, entries, size * sizeof *entries); \
3178 entries[n].string = (STRING); \
3179 entries[n].overlay = (OVERLAY); \
3180 priority = Foverlay_get ((OVERLAY), Qpriority); \
3181 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3182 entries[n].after_string_p = (AFTER_P); \
3187 /* Process overlay before the overlay center. */
3188 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3190 overlay
= XCAR (ov
);
3191 xassert (OVERLAYP (overlay
));
3192 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3193 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3198 /* Skip this overlay if it doesn't start or end at IT's current
3200 if (end
!= charpos
&& start
!= charpos
)
3203 /* Skip this overlay if it doesn't apply to IT->w. */
3204 window
= Foverlay_get (overlay
, Qwindow
);
3205 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3208 /* If the text ``under'' the overlay is invisible, both before-
3209 and after-strings from this overlay are visible; start and
3210 end position are indistinguishable. */
3211 invisible
= Foverlay_get (overlay
, Qinvisible
);
3212 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3214 /* If overlay has a non-empty before-string, record it. */
3215 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3216 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3217 && XSTRING (str
)->size
)
3218 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3220 /* If overlay has a non-empty after-string, record it. */
3221 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3222 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3223 && XSTRING (str
)->size
)
3224 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3227 /* Process overlays after the overlay center. */
3228 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3230 overlay
= XCAR (ov
);
3231 xassert (OVERLAYP (overlay
));
3232 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3233 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3235 if (start
> charpos
)
3238 /* Skip this overlay if it doesn't start or end at IT's current
3240 if (end
!= charpos
&& start
!= charpos
)
3243 /* Skip this overlay if it doesn't apply to IT->w. */
3244 window
= Foverlay_get (overlay
, Qwindow
);
3245 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3248 /* If the text ``under'' the overlay is invisible, it has a zero
3249 dimension, and both before- and after-strings apply. */
3250 invisible
= Foverlay_get (overlay
, Qinvisible
);
3251 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3253 /* If overlay has a non-empty before-string, record it. */
3254 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3255 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3256 && XSTRING (str
)->size
)
3257 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3259 /* If overlay has a non-empty after-string, record it. */
3260 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3261 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3262 && XSTRING (str
)->size
)
3263 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3266 #undef RECORD_OVERLAY_STRING
3270 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3272 /* Record the total number of strings to process. */
3273 it
->n_overlay_strings
= n
;
3275 /* IT->current.overlay_string_index is the number of overlay strings
3276 that have already been consumed by IT. Copy some of the
3277 remaining overlay strings to IT->overlay_strings. */
3279 j
= it
->current
.overlay_string_index
;
3280 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3281 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3287 /* Get the first chunk of overlay strings at IT's current buffer
3288 position. Value is non-zero if at least one overlay string was
3292 get_overlay_strings (it
)
3295 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3296 process. This fills IT->overlay_strings with strings, and sets
3297 IT->n_overlay_strings to the total number of strings to process.
3298 IT->pos.overlay_string_index has to be set temporarily to zero
3299 because load_overlay_strings needs this; it must be set to -1
3300 when no overlay strings are found because a zero value would
3301 indicate a position in the first overlay string. */
3302 it
->current
.overlay_string_index
= 0;
3303 load_overlay_strings (it
);
3305 /* If we found overlay strings, set up IT to deliver display
3306 elements from the first one. Otherwise set up IT to deliver
3307 from current_buffer. */
3308 if (it
->n_overlay_strings
)
3310 /* Make sure we know settings in current_buffer, so that we can
3311 restore meaningful values when we're done with the overlay
3313 compute_stop_pos (it
);
3314 xassert (it
->face_id
>= 0);
3316 /* Save IT's settings. They are restored after all overlay
3317 strings have been processed. */
3318 xassert (it
->sp
== 0);
3321 /* Set up IT to deliver display elements from the first overlay
3323 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3324 it
->stop_charpos
= 0;
3325 it
->string
= it
->overlay_strings
[0];
3326 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3327 xassert (STRINGP (it
->string
));
3328 it
->method
= next_element_from_string
;
3333 it
->current
.overlay_string_index
= -1;
3334 it
->method
= next_element_from_buffer
;
3339 /* Value is non-zero if we found at least one overlay string. */
3340 return STRINGP (it
->string
);
3345 /***********************************************************************
3346 Saving and restoring state
3347 ***********************************************************************/
3349 /* Save current settings of IT on IT->stack. Called, for example,
3350 before setting up IT for an overlay string, to be able to restore
3351 IT's settings to what they were after the overlay string has been
3358 struct iterator_stack_entry
*p
;
3360 xassert (it
->sp
< 2);
3361 p
= it
->stack
+ it
->sp
;
3363 p
->stop_charpos
= it
->stop_charpos
;
3364 xassert (it
->face_id
>= 0);
3365 p
->face_id
= it
->face_id
;
3366 p
->string
= it
->string
;
3367 p
->pos
= it
->current
;
3368 p
->end_charpos
= it
->end_charpos
;
3369 p
->string_nchars
= it
->string_nchars
;
3371 p
->multibyte_p
= it
->multibyte_p
;
3372 p
->space_width
= it
->space_width
;
3373 p
->font_height
= it
->font_height
;
3374 p
->voffset
= it
->voffset
;
3375 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3380 /* Restore IT's settings from IT->stack. Called, for example, when no
3381 more overlay strings must be processed, and we return to delivering
3382 display elements from a buffer, or when the end of a string from a
3383 `display' property is reached and we return to delivering display
3384 elements from an overlay string, or from a buffer. */
3390 struct iterator_stack_entry
*p
;
3392 xassert (it
->sp
> 0);
3394 p
= it
->stack
+ it
->sp
;
3395 it
->stop_charpos
= p
->stop_charpos
;
3396 it
->face_id
= p
->face_id
;
3397 it
->string
= p
->string
;
3398 it
->current
= p
->pos
;
3399 it
->end_charpos
= p
->end_charpos
;
3400 it
->string_nchars
= p
->string_nchars
;
3402 it
->multibyte_p
= p
->multibyte_p
;
3403 it
->space_width
= p
->space_width
;
3404 it
->font_height
= p
->font_height
;
3405 it
->voffset
= p
->voffset
;
3406 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3411 /***********************************************************************
3413 ***********************************************************************/
3415 /* Set IT's current position to the previous line start. */
3418 back_to_previous_line_start (it
)
3421 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3422 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3426 /* Move IT to the next line start.
3428 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3429 we skipped over part of the text (as opposed to moving the iterator
3430 continuously over the text). Otherwise, don't change the value
3433 Newlines may come from buffer text, overlay strings, or strings
3434 displayed via the `display' property. That's the reason we can't
3435 simply use find_next_newline_no_quit.
3437 Note that this function may not skip over invisible text that is so
3438 because of text properties and immediately follows a newline. If
3439 it would, function reseat_at_next_visible_line_start, when called
3440 from set_iterator_to_next, would effectively make invisible
3441 characters following a newline part of the wrong glyph row, which
3442 leads to wrong cursor motion. */
3445 forward_to_next_line_start (it
, skipped_p
)
3449 int old_selective
, newline_found_p
, n
;
3450 const int MAX_NEWLINE_DISTANCE
= 500;
3452 /* If already on a newline, just consume it to avoid unintended
3453 skipping over invisible text below. */
3454 if (it
->what
== IT_CHARACTER
&& it
->c
== '\n')
3456 set_iterator_to_next (it
, 0);
3460 /* Don't handle selective display in the following. It's (a)
3461 unnecessary because it's done by the caller, and (b) leads to an
3462 infinite recursion because next_element_from_ellipsis indirectly
3463 calls this function. */
3464 old_selective
= it
->selective
;
3467 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3468 from buffer text. */
3469 n
= newline_found_p
= 0;
3470 while (n
< MAX_NEWLINE_DISTANCE
3471 && get_next_display_element (it
)
3472 && !newline_found_p
)
3474 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3475 set_iterator_to_next (it
, 0);
3476 if (!STRINGP (it
->string
))
3480 /* If we didn't find a newline near enough, see if we can use a
3482 if (!newline_found_p
&& n
== MAX_NEWLINE_DISTANCE
)
3484 int start
= IT_CHARPOS (*it
);
3485 int limit
= find_next_newline_no_quit (start
, 1);
3488 xassert (!STRINGP (it
->string
));
3490 /* If there isn't any `display' property in sight, and no
3491 overlays, we can just use the position of the newline in
3493 if (it
->stop_charpos
>= limit
3494 || ((pos
= Fnext_single_property_change (make_number (start
),
3496 Qnil
, make_number (limit
)),
3498 && next_overlay_change (start
) == ZV
))
3500 IT_CHARPOS (*it
) = limit
;
3501 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3502 *skipped_p
= newline_found_p
= 1;
3506 while (get_next_display_element (it
)
3507 && !newline_found_p
)
3509 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3510 set_iterator_to_next (it
, 0);
3515 it
->selective
= old_selective
;
3516 return newline_found_p
;
3520 /* Set IT's current position to the previous visible line start. Skip
3521 invisible text that is so either due to text properties or due to
3522 selective display. Caution: this does not change IT->current_x and
3526 back_to_previous_visible_line_start (it
)
3531 /* Go back one newline if not on BEGV already. */
3532 if (IT_CHARPOS (*it
) > BEGV
)
3533 back_to_previous_line_start (it
);
3535 /* Move over lines that are invisible because of selective display
3536 or text properties. */
3537 while (IT_CHARPOS (*it
) > BEGV
3542 /* If selective > 0, then lines indented more than that values
3544 if (it
->selective
> 0
3545 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3552 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3553 Qinvisible
, it
->window
);
3554 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3558 /* Back one more newline if the current one is invisible. */
3560 back_to_previous_line_start (it
);
3563 xassert (IT_CHARPOS (*it
) >= BEGV
);
3564 xassert (IT_CHARPOS (*it
) == BEGV
3565 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3570 /* Reseat iterator IT at the previous visible line start. Skip
3571 invisible text that is so either due to text properties or due to
3572 selective display. At the end, update IT's overlay information,
3573 face information etc. */
3576 reseat_at_previous_visible_line_start (it
)
3579 back_to_previous_visible_line_start (it
);
3580 reseat (it
, it
->current
.pos
, 1);
3585 /* Reseat iterator IT on the next visible line start in the current
3586 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3587 preceding the line start. Skip over invisible text that is so
3588 because of selective display. Compute faces, overlays etc at the
3589 new position. Note that this function does not skip over text that
3590 is invisible because of text properties. */
3593 reseat_at_next_visible_line_start (it
, on_newline_p
)
3597 int newline_found_p
, skipped_p
= 0;
3599 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3601 /* Skip over lines that are invisible because they are indented
3602 more than the value of IT->selective. */
3603 if (it
->selective
> 0)
3604 while (IT_CHARPOS (*it
) < ZV
3605 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3607 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3609 /* Position on the newline if that's what's requested. */
3610 if (on_newline_p
&& newline_found_p
)
3612 if (STRINGP (it
->string
))
3614 if (IT_STRING_CHARPOS (*it
) > 0)
3616 --IT_STRING_CHARPOS (*it
);
3617 --IT_STRING_BYTEPOS (*it
);
3620 else if (IT_CHARPOS (*it
) > BEGV
)
3624 reseat (it
, it
->current
.pos
, 0);
3628 reseat (it
, it
->current
.pos
, 0);
3635 /***********************************************************************
3636 Changing an iterator's position
3637 ***********************************************************************/
3639 /* Change IT's current position to POS in current_buffer. If FORCE_P
3640 is non-zero, always check for text properties at the new position.
3641 Otherwise, text properties are only looked up if POS >=
3642 IT->check_charpos of a property. */
3645 reseat (it
, pos
, force_p
)
3647 struct text_pos pos
;
3650 int original_pos
= IT_CHARPOS (*it
);
3652 reseat_1 (it
, pos
, 0);
3654 /* Determine where to check text properties. Avoid doing it
3655 where possible because text property lookup is very expensive. */
3657 || CHARPOS (pos
) > it
->stop_charpos
3658 || CHARPOS (pos
) < original_pos
)
3665 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3666 IT->stop_pos to POS, also. */
3669 reseat_1 (it
, pos
, set_stop_p
)
3671 struct text_pos pos
;
3674 /* Don't call this function when scanning a C string. */
3675 xassert (it
->s
== NULL
);
3677 /* POS must be a reasonable value. */
3678 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3680 it
->current
.pos
= it
->position
= pos
;
3681 XSETBUFFER (it
->object
, current_buffer
);
3683 it
->current
.dpvec_index
= -1;
3684 it
->current
.overlay_string_index
= -1;
3685 IT_STRING_CHARPOS (*it
) = -1;
3686 IT_STRING_BYTEPOS (*it
) = -1;
3688 it
->method
= next_element_from_buffer
;
3690 it
->face_before_selective_p
= 0;
3693 it
->stop_charpos
= CHARPOS (pos
);
3697 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3698 If S is non-null, it is a C string to iterate over. Otherwise,
3699 STRING gives a Lisp string to iterate over.
3701 If PRECISION > 0, don't return more then PRECISION number of
3702 characters from the string.
3704 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3705 characters have been returned. FIELD_WIDTH < 0 means an infinite
3708 MULTIBYTE = 0 means disable processing of multibyte characters,
3709 MULTIBYTE > 0 means enable it,
3710 MULTIBYTE < 0 means use IT->multibyte_p.
3712 IT must be initialized via a prior call to init_iterator before
3713 calling this function. */
3716 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3721 int precision
, field_width
, multibyte
;
3723 /* No region in strings. */
3724 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3726 /* No text property checks performed by default, but see below. */
3727 it
->stop_charpos
= -1;
3729 /* Set iterator position and end position. */
3730 bzero (&it
->current
, sizeof it
->current
);
3731 it
->current
.overlay_string_index
= -1;
3732 it
->current
.dpvec_index
= -1;
3733 xassert (charpos
>= 0);
3735 /* Use the setting of MULTIBYTE if specified. */
3737 it
->multibyte_p
= multibyte
> 0;
3741 xassert (STRINGP (string
));
3742 it
->string
= string
;
3744 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3745 it
->method
= next_element_from_string
;
3746 it
->current
.string_pos
= string_pos (charpos
, string
);
3753 /* Note that we use IT->current.pos, not it->current.string_pos,
3754 for displaying C strings. */
3755 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3756 if (it
->multibyte_p
)
3758 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3759 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3763 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3764 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3767 it
->method
= next_element_from_c_string
;
3770 /* PRECISION > 0 means don't return more than PRECISION characters
3772 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3773 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3775 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3776 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3777 FIELD_WIDTH < 0 means infinite field width. This is useful for
3778 padding with `-' at the end of a mode line. */
3779 if (field_width
< 0)
3780 field_width
= INFINITY
;
3781 if (field_width
> it
->end_charpos
- charpos
)
3782 it
->end_charpos
= charpos
+ field_width
;
3784 /* Use the standard display table for displaying strings. */
3785 if (DISP_TABLE_P (Vstandard_display_table
))
3786 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3788 it
->stop_charpos
= charpos
;
3794 /***********************************************************************
3796 ***********************************************************************/
3798 /* Load IT's display element fields with information about the next
3799 display element from the current position of IT. Value is zero if
3800 end of buffer (or C string) is reached. */
3803 get_next_display_element (it
)
3806 /* Non-zero means that we found an display element. Zero means that
3807 we hit the end of what we iterate over. Performance note: the
3808 function pointer `method' used here turns out to be faster than
3809 using a sequence of if-statements. */
3810 int success_p
= (*it
->method
) (it
);
3812 if (it
->what
== IT_CHARACTER
)
3814 /* Map via display table or translate control characters.
3815 IT->c, IT->len etc. have been set to the next character by
3816 the function call above. If we have a display table, and it
3817 contains an entry for IT->c, translate it. Don't do this if
3818 IT->c itself comes from a display table, otherwise we could
3819 end up in an infinite recursion. (An alternative could be to
3820 count the recursion depth of this function and signal an
3821 error when a certain maximum depth is reached.) Is it worth
3823 if (success_p
&& it
->dpvec
== NULL
)
3828 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3831 struct Lisp_Vector
*v
= XVECTOR (dv
);
3833 /* Return the first character from the display table
3834 entry, if not empty. If empty, don't display the
3835 current character. */
3838 it
->dpvec_char_len
= it
->len
;
3839 it
->dpvec
= v
->contents
;
3840 it
->dpend
= v
->contents
+ v
->size
;
3841 it
->current
.dpvec_index
= 0;
3842 it
->method
= next_element_from_display_vector
;
3845 success_p
= get_next_display_element (it
);
3848 /* Translate control characters into `\003' or `^C' form.
3849 Control characters coming from a display table entry are
3850 currently not translated because we use IT->dpvec to hold
3851 the translation. This could easily be changed but I
3852 don't believe that it is worth doing.
3854 Non-printable multibyte characters are also translated
3856 else if ((it
->c
< ' '
3857 && (it
->area
!= TEXT_AREA
3858 || (it
->c
!= '\n' && it
->c
!= '\t')))
3861 || !CHAR_PRINTABLE_P (it
->c
))
3863 /* IT->c is a control character which must be displayed
3864 either as '\003' or as `^C' where the '\\' and '^'
3865 can be defined in the display table. Fill
3866 IT->ctl_chars with glyphs for what we have to
3867 display. Then, set IT->dpvec to these glyphs. */
3870 if (it
->c
< 128 && it
->ctl_arrow_p
)
3872 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3874 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3875 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3876 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3878 g
= FAST_MAKE_GLYPH ('^', 0);
3879 XSETINT (it
->ctl_chars
[0], g
);
3881 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3882 XSETINT (it
->ctl_chars
[1], g
);
3884 /* Set up IT->dpvec and return first character from it. */
3885 it
->dpvec_char_len
= it
->len
;
3886 it
->dpvec
= it
->ctl_chars
;
3887 it
->dpend
= it
->dpvec
+ 2;
3888 it
->current
.dpvec_index
= 0;
3889 it
->method
= next_element_from_display_vector
;
3890 get_next_display_element (it
);
3894 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3899 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3901 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3902 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3903 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3905 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3907 if (SINGLE_BYTE_CHAR_P (it
->c
))
3908 str
[0] = it
->c
, len
= 1;
3910 len
= CHAR_STRING (it
->c
, str
);
3912 for (i
= 0; i
< len
; i
++)
3914 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3915 /* Insert three more glyphs into IT->ctl_chars for
3916 the octal display of the character. */
3917 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3918 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3919 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3920 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3921 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3922 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3925 /* Set up IT->dpvec and return the first character
3927 it
->dpvec_char_len
= it
->len
;
3928 it
->dpvec
= it
->ctl_chars
;
3929 it
->dpend
= it
->dpvec
+ len
* 4;
3930 it
->current
.dpvec_index
= 0;
3931 it
->method
= next_element_from_display_vector
;
3932 get_next_display_element (it
);
3937 /* Adjust face id for a multibyte character. There are no
3938 multibyte character in unibyte text. */
3941 && FRAME_WINDOW_P (it
->f
))
3943 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3944 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3948 /* Is this character the last one of a run of characters with
3949 box? If yes, set IT->end_of_box_run_p to 1. */
3956 it
->end_of_box_run_p
3957 = ((face_id
= face_after_it_pos (it
),
3958 face_id
!= it
->face_id
)
3959 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3960 face
->box
== FACE_NO_BOX
));
3963 /* Value is 0 if end of buffer or string reached. */
3968 /* Move IT to the next display element.
3970 RESEAT_P non-zero means if called on a newline in buffer text,
3971 skip to the next visible line start.
3973 Functions get_next_display_element and set_iterator_to_next are
3974 separate because I find this arrangement easier to handle than a
3975 get_next_display_element function that also increments IT's
3976 position. The way it is we can first look at an iterator's current
3977 display element, decide whether it fits on a line, and if it does,
3978 increment the iterator position. The other way around we probably
3979 would either need a flag indicating whether the iterator has to be
3980 incremented the next time, or we would have to implement a
3981 decrement position function which would not be easy to write. */
3984 set_iterator_to_next (it
, reseat_p
)
3988 /* Reset flags indicating start and end of a sequence of characters
3989 with box. Reset them at the start of this function because
3990 moving the iterator to a new position might set them. */
3991 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3993 if (it
->method
== next_element_from_buffer
)
3995 /* The current display element of IT is a character from
3996 current_buffer. Advance in the buffer, and maybe skip over
3997 invisible lines that are so because of selective display. */
3998 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
3999 reseat_at_next_visible_line_start (it
, 0);
4002 xassert (it
->len
!= 0);
4003 IT_BYTEPOS (*it
) += it
->len
;
4004 IT_CHARPOS (*it
) += 1;
4005 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4008 else if (it
->method
== next_element_from_composition
)
4010 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4011 if (STRINGP (it
->string
))
4013 IT_STRING_BYTEPOS (*it
) += it
->len
;
4014 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4015 it
->method
= next_element_from_string
;
4016 goto consider_string_end
;
4020 IT_BYTEPOS (*it
) += it
->len
;
4021 IT_CHARPOS (*it
) += it
->cmp_len
;
4022 it
->method
= next_element_from_buffer
;
4025 else if (it
->method
== next_element_from_c_string
)
4027 /* Current display element of IT is from a C string. */
4028 IT_BYTEPOS (*it
) += it
->len
;
4029 IT_CHARPOS (*it
) += 1;
4031 else if (it
->method
== next_element_from_display_vector
)
4033 /* Current display element of IT is from a display table entry.
4034 Advance in the display table definition. Reset it to null if
4035 end reached, and continue with characters from buffers/
4037 ++it
->current
.dpvec_index
;
4039 /* Restore face of the iterator to what they were before the
4040 display vector entry (these entries may contain faces). */
4041 it
->face_id
= it
->saved_face_id
;
4043 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4046 it
->method
= next_element_from_c_string
;
4047 else if (STRINGP (it
->string
))
4048 it
->method
= next_element_from_string
;
4050 it
->method
= next_element_from_buffer
;
4053 it
->current
.dpvec_index
= -1;
4055 /* Skip over characters which were displayed via IT->dpvec. */
4056 if (it
->dpvec_char_len
< 0)
4057 reseat_at_next_visible_line_start (it
, 1);
4058 else if (it
->dpvec_char_len
> 0)
4060 it
->len
= it
->dpvec_char_len
;
4061 set_iterator_to_next (it
, reseat_p
);
4065 else if (it
->method
== next_element_from_string
)
4067 /* Current display element is a character from a Lisp string. */
4068 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4069 IT_STRING_BYTEPOS (*it
) += it
->len
;
4070 IT_STRING_CHARPOS (*it
) += 1;
4072 consider_string_end
:
4074 if (it
->current
.overlay_string_index
>= 0)
4076 /* IT->string is an overlay string. Advance to the
4077 next, if there is one. */
4078 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4079 next_overlay_string (it
);
4083 /* IT->string is not an overlay string. If we reached
4084 its end, and there is something on IT->stack, proceed
4085 with what is on the stack. This can be either another
4086 string, this time an overlay string, or a buffer. */
4087 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4091 if (!STRINGP (it
->string
))
4092 it
->method
= next_element_from_buffer
;
4096 else if (it
->method
== next_element_from_image
4097 || it
->method
== next_element_from_stretch
)
4099 /* The position etc with which we have to proceed are on
4100 the stack. The position may be at the end of a string,
4101 if the `display' property takes up the whole string. */
4104 if (STRINGP (it
->string
))
4106 it
->method
= next_element_from_string
;
4107 goto consider_string_end
;
4110 it
->method
= next_element_from_buffer
;
4113 /* There are no other methods defined, so this should be a bug. */
4116 xassert (it
->method
!= next_element_from_string
4117 || (STRINGP (it
->string
)
4118 && IT_STRING_CHARPOS (*it
) >= 0));
4122 /* Load IT's display element fields with information about the next
4123 display element which comes from a display table entry or from the
4124 result of translating a control character to one of the forms `^C'
4125 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4128 next_element_from_display_vector (it
)
4132 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4134 /* Remember the current face id in case glyphs specify faces.
4135 IT's face is restored in set_iterator_to_next. */
4136 it
->saved_face_id
= it
->face_id
;
4138 if (INTEGERP (*it
->dpvec
)
4139 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4144 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4145 it
->c
= FAST_GLYPH_CHAR (g
);
4146 it
->len
= CHAR_BYTES (it
->c
);
4148 /* The entry may contain a face id to use. Such a face id is
4149 the id of a Lisp face, not a realized face. A face id of
4150 zero means no face is specified. */
4151 lface_id
= FAST_GLYPH_FACE (g
);
4154 /* The function returns -1 if lface_id is invalid. */
4155 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4157 it
->face_id
= face_id
;
4161 /* Display table entry is invalid. Return a space. */
4162 it
->c
= ' ', it
->len
= 1;
4164 /* Don't change position and object of the iterator here. They are
4165 still the values of the character that had this display table
4166 entry or was translated, and that's what we want. */
4167 it
->what
= IT_CHARACTER
;
4172 /* Load IT with the next display element from Lisp string IT->string.
4173 IT->current.string_pos is the current position within the string.
4174 If IT->current.overlay_string_index >= 0, the Lisp string is an
4178 next_element_from_string (it
)
4181 struct text_pos position
;
4183 xassert (STRINGP (it
->string
));
4184 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4185 position
= it
->current
.string_pos
;
4187 /* Time to check for invisible text? */
4188 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4189 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4193 /* Since a handler may have changed IT->method, we must
4195 return get_next_display_element (it
);
4198 if (it
->current
.overlay_string_index
>= 0)
4200 /* Get the next character from an overlay string. In overlay
4201 strings, There is no field width or padding with spaces to
4203 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4208 else if (STRING_MULTIBYTE (it
->string
))
4210 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4211 - IT_STRING_BYTEPOS (*it
));
4212 unsigned char *s
= (XSTRING (it
->string
)->data
4213 + IT_STRING_BYTEPOS (*it
));
4214 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4218 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4224 /* Get the next character from a Lisp string that is not an
4225 overlay string. Such strings come from the mode line, for
4226 example. We may have to pad with spaces, or truncate the
4227 string. See also next_element_from_c_string. */
4228 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4233 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4235 /* Pad with spaces. */
4236 it
->c
= ' ', it
->len
= 1;
4237 CHARPOS (position
) = BYTEPOS (position
) = -1;
4239 else if (STRING_MULTIBYTE (it
->string
))
4241 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4242 - IT_STRING_BYTEPOS (*it
));
4243 unsigned char *s
= (XSTRING (it
->string
)->data
4244 + IT_STRING_BYTEPOS (*it
));
4245 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4249 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4254 /* Record what we have and where it came from. Note that we store a
4255 buffer position in IT->position although it could arguably be a
4257 it
->what
= IT_CHARACTER
;
4258 it
->object
= it
->string
;
4259 it
->position
= position
;
4264 /* Load IT with next display element from C string IT->s.
4265 IT->string_nchars is the maximum number of characters to return
4266 from the string. IT->end_charpos may be greater than
4267 IT->string_nchars when this function is called, in which case we
4268 may have to return padding spaces. Value is zero if end of string
4269 reached, including padding spaces. */
4272 next_element_from_c_string (it
)
4278 it
->what
= IT_CHARACTER
;
4279 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4282 /* IT's position can be greater IT->string_nchars in case a field
4283 width or precision has been specified when the iterator was
4285 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4287 /* End of the game. */
4291 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4293 /* Pad with spaces. */
4294 it
->c
= ' ', it
->len
= 1;
4295 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4297 else if (it
->multibyte_p
)
4299 /* Implementation note: The calls to strlen apparently aren't a
4300 performance problem because there is no noticeable performance
4301 difference between Emacs running in unibyte or multibyte mode. */
4302 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4303 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4307 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4313 /* Set up IT to return characters from an ellipsis, if appropriate.
4314 The definition of the ellipsis glyphs may come from a display table
4315 entry. This function Fills IT with the first glyph from the
4316 ellipsis if an ellipsis is to be displayed. */
4319 next_element_from_ellipsis (it
)
4322 if (it
->selective_display_ellipsis_p
)
4324 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4326 /* Use the display table definition for `...'. Invalid glyphs
4327 will be handled by the method returning elements from dpvec. */
4328 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4329 it
->dpvec_char_len
= it
->len
;
4330 it
->dpvec
= v
->contents
;
4331 it
->dpend
= v
->contents
+ v
->size
;
4332 it
->current
.dpvec_index
= 0;
4333 it
->method
= next_element_from_display_vector
;
4337 /* Use default `...' which is stored in default_invis_vector. */
4338 it
->dpvec_char_len
= it
->len
;
4339 it
->dpvec
= default_invis_vector
;
4340 it
->dpend
= default_invis_vector
+ 3;
4341 it
->current
.dpvec_index
= 0;
4342 it
->method
= next_element_from_display_vector
;
4347 /* The face at the current position may be different from the
4348 face we find after the invisible text. Remember what it
4349 was in IT->saved_face_id, and signal that it's there by
4350 setting face_before_selective_p. */
4351 it
->saved_face_id
= it
->face_id
;
4352 it
->method
= next_element_from_buffer
;
4353 reseat_at_next_visible_line_start (it
, 1);
4354 it
->face_before_selective_p
= 1;
4357 return get_next_display_element (it
);
4361 /* Deliver an image display element. The iterator IT is already
4362 filled with image information (done in handle_display_prop). Value
4367 next_element_from_image (it
)
4370 it
->what
= IT_IMAGE
;
4375 /* Fill iterator IT with next display element from a stretch glyph
4376 property. IT->object is the value of the text property. Value is
4380 next_element_from_stretch (it
)
4383 it
->what
= IT_STRETCH
;
4388 /* Load IT with the next display element from current_buffer. Value
4389 is zero if end of buffer reached. IT->stop_charpos is the next
4390 position at which to stop and check for text properties or buffer
4394 next_element_from_buffer (it
)
4399 /* Check this assumption, otherwise, we would never enter the
4400 if-statement, below. */
4401 xassert (IT_CHARPOS (*it
) >= BEGV
4402 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4404 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4406 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4408 int overlay_strings_follow_p
;
4410 /* End of the game, except when overlay strings follow that
4411 haven't been returned yet. */
4412 if (it
->overlay_strings_at_end_processed_p
)
4413 overlay_strings_follow_p
= 0;
4416 it
->overlay_strings_at_end_processed_p
= 1;
4417 overlay_strings_follow_p
= get_overlay_strings (it
);
4420 if (overlay_strings_follow_p
)
4421 success_p
= get_next_display_element (it
);
4425 it
->position
= it
->current
.pos
;
4432 return get_next_display_element (it
);
4437 /* No face changes, overlays etc. in sight, so just return a
4438 character from current_buffer. */
4441 /* Maybe run the redisplay end trigger hook. Performance note:
4442 This doesn't seem to cost measurable time. */
4443 if (it
->redisplay_end_trigger_charpos
4445 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4446 run_redisplay_end_trigger_hook (it
);
4448 /* Get the next character, maybe multibyte. */
4449 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4450 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4452 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4453 - IT_BYTEPOS (*it
));
4454 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4457 it
->c
= *p
, it
->len
= 1;
4459 /* Record what we have and where it came from. */
4460 it
->what
= IT_CHARACTER
;;
4461 it
->object
= it
->w
->buffer
;
4462 it
->position
= it
->current
.pos
;
4464 /* Normally we return the character found above, except when we
4465 really want to return an ellipsis for selective display. */
4470 /* A value of selective > 0 means hide lines indented more
4471 than that number of columns. */
4472 if (it
->selective
> 0
4473 && IT_CHARPOS (*it
) + 1 < ZV
4474 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4475 IT_BYTEPOS (*it
) + 1,
4478 success_p
= next_element_from_ellipsis (it
);
4479 it
->dpvec_char_len
= -1;
4482 else if (it
->c
== '\r' && it
->selective
== -1)
4484 /* A value of selective == -1 means that everything from the
4485 CR to the end of the line is invisible, with maybe an
4486 ellipsis displayed for it. */
4487 success_p
= next_element_from_ellipsis (it
);
4488 it
->dpvec_char_len
= -1;
4493 /* Value is zero if end of buffer reached. */
4494 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4499 /* Run the redisplay end trigger hook for IT. */
4502 run_redisplay_end_trigger_hook (it
)
4505 Lisp_Object args
[3];
4507 /* IT->glyph_row should be non-null, i.e. we should be actually
4508 displaying something, or otherwise we should not run the hook. */
4509 xassert (it
->glyph_row
);
4511 /* Set up hook arguments. */
4512 args
[0] = Qredisplay_end_trigger_functions
;
4513 args
[1] = it
->window
;
4514 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4515 it
->redisplay_end_trigger_charpos
= 0;
4517 /* Since we are *trying* to run these functions, don't try to run
4518 them again, even if they get an error. */
4519 it
->w
->redisplay_end_trigger
= Qnil
;
4520 Frun_hook_with_args (3, args
);
4522 /* Notice if it changed the face of the character we are on. */
4523 handle_face_prop (it
);
4527 /* Deliver a composition display element. The iterator IT is already
4528 filled with composition information (done in
4529 handle_composition_prop). Value is always 1. */
4532 next_element_from_composition (it
)
4535 it
->what
= IT_COMPOSITION
;
4536 it
->position
= (STRINGP (it
->string
)
4537 ? it
->current
.string_pos
4544 /***********************************************************************
4545 Moving an iterator without producing glyphs
4546 ***********************************************************************/
4548 /* Move iterator IT to a specified buffer or X position within one
4549 line on the display without producing glyphs.
4551 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4552 whichever is reached first.
4554 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4556 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4557 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4558 TO_X includes the amount by which a window is horizontally
4563 MOVE_POS_MATCH_OR_ZV
4564 - when TO_POS or ZV was reached.
4567 -when TO_X was reached before TO_POS or ZV were reached.
4570 - when we reached the end of the display area and the line must
4574 - when we reached the end of the display area and the line is
4578 - when we stopped at a line end, i.e. a newline or a CR and selective
4581 static enum move_it_result
4582 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4584 int to_charpos
, to_x
, op
;
4586 enum move_it_result result
= MOVE_UNDEFINED
;
4587 struct glyph_row
*saved_glyph_row
;
4589 /* Don't produce glyphs in produce_glyphs. */
4590 saved_glyph_row
= it
->glyph_row
;
4591 it
->glyph_row
= NULL
;
4595 int x
, i
, ascent
= 0, descent
= 0;
4597 /* Stop when ZV or TO_CHARPOS reached. */
4598 if (!get_next_display_element (it
)
4599 || ((op
& MOVE_TO_POS
) != 0
4600 && BUFFERP (it
->object
)
4601 && IT_CHARPOS (*it
) >= to_charpos
))
4603 result
= MOVE_POS_MATCH_OR_ZV
;
4607 /* The call to produce_glyphs will get the metrics of the
4608 display element IT is loaded with. We record in x the
4609 x-position before this display element in case it does not
4613 /* Remember the line height so far in case the next element doesn't
4615 if (!it
->truncate_lines_p
)
4617 ascent
= it
->max_ascent
;
4618 descent
= it
->max_descent
;
4621 PRODUCE_GLYPHS (it
);
4623 if (it
->area
!= TEXT_AREA
)
4625 set_iterator_to_next (it
, 1);
4629 /* The number of glyphs we get back in IT->nglyphs will normally
4630 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4631 character on a terminal frame, or (iii) a line end. For the
4632 second case, IT->nglyphs - 1 padding glyphs will be present
4633 (on X frames, there is only one glyph produced for a
4634 composite character.
4636 The behavior implemented below means, for continuation lines,
4637 that as many spaces of a TAB as fit on the current line are
4638 displayed there. For terminal frames, as many glyphs of a
4639 multi-glyph character are displayed in the current line, too.
4640 This is what the old redisplay code did, and we keep it that
4641 way. Under X, the whole shape of a complex character must
4642 fit on the line or it will be completely displayed in the
4645 Note that both for tabs and padding glyphs, all glyphs have
4649 /* More than one glyph or glyph doesn't fit on line. All
4650 glyphs have the same width. */
4651 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4654 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4656 new_x
= x
+ single_glyph_width
;
4658 /* We want to leave anything reaching TO_X to the caller. */
4659 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4662 result
= MOVE_X_REACHED
;
4665 else if (/* Lines are continued. */
4666 !it
->truncate_lines_p
4667 && (/* And glyph doesn't fit on the line. */
4668 new_x
> it
->last_visible_x
4669 /* Or it fits exactly and we're on a window
4671 || (new_x
== it
->last_visible_x
4672 && FRAME_WINDOW_P (it
->f
))))
4674 if (/* IT->hpos == 0 means the very first glyph
4675 doesn't fit on the line, e.g. a wide image. */
4677 || (new_x
== it
->last_visible_x
4678 && FRAME_WINDOW_P (it
->f
)))
4681 it
->current_x
= new_x
;
4682 if (i
== it
->nglyphs
- 1)
4683 set_iterator_to_next (it
, 1);
4688 it
->max_ascent
= ascent
;
4689 it
->max_descent
= descent
;
4692 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4694 result
= MOVE_LINE_CONTINUED
;
4697 else if (new_x
> it
->first_visible_x
)
4699 /* Glyph is visible. Increment number of glyphs that
4700 would be displayed. */
4705 /* Glyph is completely off the left margin of the display
4706 area. Nothing to do. */
4710 if (result
!= MOVE_UNDEFINED
)
4713 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4715 /* Stop when TO_X specified and reached. This check is
4716 necessary here because of lines consisting of a line end,
4717 only. The line end will not produce any glyphs and we
4718 would never get MOVE_X_REACHED. */
4719 xassert (it
->nglyphs
== 0);
4720 result
= MOVE_X_REACHED
;
4724 /* Is this a line end? If yes, we're done. */
4725 if (ITERATOR_AT_END_OF_LINE_P (it
))
4727 result
= MOVE_NEWLINE_OR_CR
;
4731 /* The current display element has been consumed. Advance
4733 set_iterator_to_next (it
, 1);
4735 /* Stop if lines are truncated and IT's current x-position is
4736 past the right edge of the window now. */
4737 if (it
->truncate_lines_p
4738 && it
->current_x
>= it
->last_visible_x
)
4740 result
= MOVE_LINE_TRUNCATED
;
4745 /* Restore the iterator settings altered at the beginning of this
4747 it
->glyph_row
= saved_glyph_row
;
4752 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4753 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4754 the description of enum move_operation_enum.
4756 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4757 screen line, this function will set IT to the next position >
4761 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4763 int to_charpos
, to_x
, to_y
, to_vpos
;
4766 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4772 if (op
& MOVE_TO_VPOS
)
4774 /* If no TO_CHARPOS and no TO_X specified, stop at the
4775 start of the line TO_VPOS. */
4776 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4778 if (it
->vpos
== to_vpos
)
4784 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4788 /* TO_VPOS >= 0 means stop at TO_X in the line at
4789 TO_VPOS, or at TO_POS, whichever comes first. */
4790 if (it
->vpos
== to_vpos
)
4796 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4798 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4803 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4805 /* We have reached TO_X but not in the line we want. */
4806 skip
= move_it_in_display_line_to (it
, to_charpos
,
4808 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4816 else if (op
& MOVE_TO_Y
)
4818 struct it it_backup
;
4820 /* TO_Y specified means stop at TO_X in the line containing
4821 TO_Y---or at TO_CHARPOS if this is reached first. The
4822 problem is that we can't really tell whether the line
4823 contains TO_Y before we have completely scanned it, and
4824 this may skip past TO_X. What we do is to first scan to
4827 If TO_X is not specified, use a TO_X of zero. The reason
4828 is to make the outcome of this function more predictable.
4829 If we didn't use TO_X == 0, we would stop at the end of
4830 the line which is probably not what a caller would expect
4832 skip
= move_it_in_display_line_to (it
, to_charpos
,
4836 | (op
& MOVE_TO_POS
)));
4838 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4839 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4845 /* If TO_X was reached, we would like to know whether TO_Y
4846 is in the line. This can only be said if we know the
4847 total line height which requires us to scan the rest of
4849 if (skip
== MOVE_X_REACHED
)
4852 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
4853 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4855 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
4858 /* Now, decide whether TO_Y is in this line. */
4859 line_height
= it
->max_ascent
+ it
->max_descent
;
4860 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
4862 if (to_y
>= it
->current_y
4863 && to_y
< it
->current_y
+ line_height
)
4865 if (skip
== MOVE_X_REACHED
)
4866 /* If TO_Y is in this line and TO_X was reached above,
4867 we scanned too far. We have to restore IT's settings
4868 to the ones before skipping. */
4872 else if (skip
== MOVE_X_REACHED
)
4875 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4883 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4887 case MOVE_POS_MATCH_OR_ZV
:
4891 case MOVE_NEWLINE_OR_CR
:
4892 set_iterator_to_next (it
, 1);
4893 it
->continuation_lines_width
= 0;
4896 case MOVE_LINE_TRUNCATED
:
4897 it
->continuation_lines_width
= 0;
4898 reseat_at_next_visible_line_start (it
, 0);
4899 if ((op
& MOVE_TO_POS
) != 0
4900 && IT_CHARPOS (*it
) > to_charpos
)
4907 case MOVE_LINE_CONTINUED
:
4908 it
->continuation_lines_width
+= it
->current_x
;
4915 /* Reset/increment for the next run. */
4916 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4917 it
->current_x
= it
->hpos
= 0;
4918 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4920 last_height
= it
->max_ascent
+ it
->max_descent
;
4921 last_max_ascent
= it
->max_ascent
;
4922 it
->max_ascent
= it
->max_descent
= 0;
4927 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
4931 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4933 If DY > 0, move IT backward at least that many pixels. DY = 0
4934 means move IT backward to the preceding line start or BEGV. This
4935 function may move over more than DY pixels if IT->current_y - DY
4936 ends up in the middle of a line; in this case IT->current_y will be
4937 set to the top of the line moved to. */
4940 move_it_vertically_backward (it
, dy
)
4944 int nlines
, h
, line_height
;
4946 int start_pos
= IT_CHARPOS (*it
);
4950 /* Estimate how many newlines we must move back. */
4951 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4953 /* Set the iterator's position that many lines back. */
4954 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4955 back_to_previous_visible_line_start (it
);
4957 /* Reseat the iterator here. When moving backward, we don't want
4958 reseat to skip forward over invisible text, set up the iterator
4959 to deliver from overlay strings at the new position etc. So,
4960 use reseat_1 here. */
4961 reseat_1 (it
, it
->current
.pos
, 1);
4963 /* We are now surely at a line start. */
4964 it
->current_x
= it
->hpos
= 0;
4966 /* Move forward and see what y-distance we moved. First move to the
4967 start of the next line so that we get its height. We need this
4968 height to be able to tell whether we reached the specified
4971 it2
.max_ascent
= it2
.max_descent
= 0;
4972 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4973 MOVE_TO_POS
| MOVE_TO_VPOS
);
4974 xassert (IT_CHARPOS (*it
) >= BEGV
);
4975 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4977 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4978 xassert (IT_CHARPOS (*it
) >= BEGV
);
4979 h
= it2
.current_y
- it
->current_y
;
4980 nlines
= it2
.vpos
- it
->vpos
;
4982 /* Correct IT's y and vpos position. */
4988 /* DY == 0 means move to the start of the screen line. The
4989 value of nlines is > 0 if continuation lines were involved. */
4991 move_it_by_lines (it
, nlines
, 1);
4992 xassert (IT_CHARPOS (*it
) <= start_pos
);
4996 /* The y-position we try to reach. Note that h has been
4997 subtracted in front of the if-statement. */
4998 int target_y
= it
->current_y
+ h
- dy
;
5000 /* If we did not reach target_y, try to move further backward if
5001 we can. If we moved too far backward, try to move forward. */
5002 if (target_y
< it
->current_y
5003 && IT_CHARPOS (*it
) > BEGV
)
5005 move_it_vertically (it
, target_y
- it
->current_y
);
5006 xassert (IT_CHARPOS (*it
) >= BEGV
);
5008 else if (target_y
>= it
->current_y
+ line_height
5009 && IT_CHARPOS (*it
) < ZV
)
5011 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5012 xassert (IT_CHARPOS (*it
) >= BEGV
);
5018 /* Move IT by a specified amount of pixel lines DY. DY negative means
5019 move backwards. DY = 0 means move to start of screen line. At the
5020 end, IT will be on the start of a screen line. */
5023 move_it_vertically (it
, dy
)
5028 move_it_vertically_backward (it
, -dy
);
5031 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5032 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5033 MOVE_TO_POS
| MOVE_TO_Y
);
5034 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5036 /* If buffer ends in ZV without a newline, move to the start of
5037 the line to satisfy the post-condition. */
5038 if (IT_CHARPOS (*it
) == ZV
5039 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5040 move_it_by_lines (it
, 0, 0);
5045 /* Return non-zero if some text between buffer positions START_CHARPOS
5046 and END_CHARPOS is invisible. IT->window is the window for text
5050 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5052 int start_charpos
, end_charpos
;
5054 Lisp_Object prop
, limit
;
5055 int invisible_found_p
;
5057 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5059 /* Is text at START invisible? */
5060 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5062 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5063 invisible_found_p
= 1;
5066 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5068 make_number (end_charpos
));
5069 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5072 return invisible_found_p
;
5076 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5077 negative means move up. DVPOS == 0 means move to the start of the
5078 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5079 NEED_Y_P is zero, IT->current_y will be left unchanged.
5081 Further optimization ideas: If we would know that IT->f doesn't use
5082 a face with proportional font, we could be faster for
5083 truncate-lines nil. */
5086 move_it_by_lines (it
, dvpos
, need_y_p
)
5088 int dvpos
, need_y_p
;
5090 struct position pos
;
5092 if (!FRAME_WINDOW_P (it
->f
))
5094 struct text_pos textpos
;
5096 /* We can use vmotion on frames without proportional fonts. */
5097 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5098 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5099 reseat (it
, textpos
, 1);
5100 it
->vpos
+= pos
.vpos
;
5101 it
->current_y
+= pos
.vpos
;
5103 else if (dvpos
== 0)
5105 /* DVPOS == 0 means move to the start of the screen line. */
5106 move_it_vertically_backward (it
, 0);
5107 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5111 /* If there are no continuation lines, and if there is no
5112 selective display, try the simple method of moving forward
5113 DVPOS newlines, then see where we are. */
5114 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
5116 int shortage
= 0, charpos
;
5118 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
5119 charpos
= IT_CHARPOS (*it
) + 1;
5121 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
5124 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
5126 struct text_pos pos
;
5127 CHARPOS (pos
) = charpos
;
5128 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
5129 reseat (it
, pos
, 1);
5130 it
->vpos
+= dvpos
- shortage
;
5131 it
->hpos
= it
->current_x
= 0;
5136 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5141 int start_charpos
, i
;
5143 /* If there are no continuation lines, and if there is no
5144 selective display, try the simple method of moving backward
5146 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
5149 int charpos
= IT_CHARPOS (*it
);
5150 int bytepos
= IT_BYTEPOS (*it
);
5152 /* If in the middle of a line, go to its start. */
5153 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
5155 charpos
= find_next_newline_no_quit (charpos
, -1);
5156 bytepos
= CHAR_TO_BYTE (charpos
);
5159 if (charpos
== BEGV
)
5161 struct text_pos pos
;
5162 CHARPOS (pos
) = charpos
;
5163 BYTEPOS (pos
) = bytepos
;
5164 reseat (it
, pos
, 1);
5165 it
->hpos
= it
->current_x
= 0;
5170 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
5171 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
5173 struct text_pos pos
;
5174 CHARPOS (pos
) = charpos
;
5175 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
5176 reseat (it
, pos
, 1);
5177 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
5178 it
->hpos
= it
->current_x
= 0;
5184 /* Go back -DVPOS visible lines and reseat the iterator there. */
5185 start_charpos
= IT_CHARPOS (*it
);
5186 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5187 back_to_previous_visible_line_start (it
);
5188 reseat (it
, it
->current
.pos
, 1);
5189 it
->current_x
= it
->hpos
= 0;
5191 /* Above call may have moved too far if continuation lines
5192 are involved. Scan forward and see if it did. */
5194 it2
.vpos
= it2
.current_y
= 0;
5195 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5196 it
->vpos
-= it2
.vpos
;
5197 it
->current_y
-= it2
.current_y
;
5198 it
->current_x
= it
->hpos
= 0;
5200 /* If we moved too far, move IT some lines forward. */
5201 if (it2
.vpos
> -dvpos
)
5203 int delta
= it2
.vpos
+ dvpos
;
5204 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5211 /***********************************************************************
5213 ***********************************************************************/
5216 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5220 add_to_log (format
, arg1
, arg2
)
5222 Lisp_Object arg1
, arg2
;
5224 Lisp_Object args
[3];
5225 Lisp_Object msg
, fmt
;
5228 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5231 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5233 args
[0] = fmt
= build_string (format
);
5236 msg
= Fformat (3, args
);
5238 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5239 buffer
= (char *) alloca (len
);
5240 strcpy (buffer
, XSTRING (msg
)->data
);
5242 message_dolog (buffer
, len
- 1, 1, 0);
5247 /* Output a newline in the *Messages* buffer if "needs" one. */
5250 message_log_maybe_newline ()
5252 if (message_log_need_newline
)
5253 message_dolog ("", 0, 1, 0);
5257 /* Add a string M of length LEN to the message log, optionally
5258 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5259 nonzero, means interpret the contents of M as multibyte. This
5260 function calls low-level routines in order to bypass text property
5261 hooks, etc. which might not be safe to run. */
5264 message_dolog (m
, len
, nlflag
, multibyte
)
5266 int len
, nlflag
, multibyte
;
5268 if (!NILP (Vmessage_log_max
))
5270 struct buffer
*oldbuf
;
5271 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5272 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5273 int point_at_end
= 0;
5275 Lisp_Object old_deactivate_mark
, tem
;
5276 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5278 old_deactivate_mark
= Vdeactivate_mark
;
5279 oldbuf
= current_buffer
;
5280 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5281 current_buffer
->undo_list
= Qt
;
5283 oldpoint
= Fpoint_marker ();
5284 oldbegv
= Fpoint_min_marker ();
5285 oldzv
= Fpoint_max_marker ();
5286 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5294 BEGV_BYTE
= BEG_BYTE
;
5297 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5299 /* Insert the string--maybe converting multibyte to single byte
5300 or vice versa, so that all the text fits the buffer. */
5302 && NILP (current_buffer
->enable_multibyte_characters
))
5305 unsigned char work
[1];
5307 /* Convert a multibyte string to single-byte
5308 for the *Message* buffer. */
5309 for (i
= 0; i
< len
; i
+= nbytes
)
5311 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
5312 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5314 : multibyte_char_to_unibyte (c
, Qnil
));
5315 insert_1_both (work
, 1, 1, 1, 0, 0);
5318 else if (! multibyte
5319 && ! NILP (current_buffer
->enable_multibyte_characters
))
5322 unsigned char *msg
= (unsigned char *) m
;
5323 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5324 /* Convert a single-byte string to multibyte
5325 for the *Message* buffer. */
5326 for (i
= 0; i
< len
; i
++)
5328 c
= unibyte_char_to_multibyte (msg
[i
]);
5329 nbytes
= CHAR_STRING (c
, str
);
5330 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
5334 insert_1 (m
, len
, 1, 0, 0);
5338 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5339 insert_1 ("\n", 1, 1, 0, 0);
5341 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5343 this_bol_byte
= PT_BYTE
;
5347 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5349 prev_bol_byte
= PT_BYTE
;
5351 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5352 this_bol
, this_bol_byte
);
5355 del_range_both (prev_bol
, prev_bol_byte
,
5356 this_bol
, this_bol_byte
, 0);
5362 /* If you change this format, don't forget to also
5363 change message_log_check_duplicate. */
5364 sprintf (dupstr
, " [%d times]", dup
);
5365 duplen
= strlen (dupstr
);
5366 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5367 insert_1 (dupstr
, duplen
, 1, 0, 1);
5372 if (NATNUMP (Vmessage_log_max
))
5374 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5375 -XFASTINT (Vmessage_log_max
) - 1, 0);
5376 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5379 BEGV
= XMARKER (oldbegv
)->charpos
;
5380 BEGV_BYTE
= marker_byte_position (oldbegv
);
5389 ZV
= XMARKER (oldzv
)->charpos
;
5390 ZV_BYTE
= marker_byte_position (oldzv
);
5394 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5396 /* We can't do Fgoto_char (oldpoint) because it will run some
5398 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5399 XMARKER (oldpoint
)->bytepos
);
5402 free_marker (oldpoint
);
5403 free_marker (oldbegv
);
5404 free_marker (oldzv
);
5406 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5407 set_buffer_internal (oldbuf
);
5409 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5410 message_log_need_newline
= !nlflag
;
5411 Vdeactivate_mark
= old_deactivate_mark
;
5416 /* We are at the end of the buffer after just having inserted a newline.
5417 (Note: We depend on the fact we won't be crossing the gap.)
5418 Check to see if the most recent message looks a lot like the previous one.
5419 Return 0 if different, 1 if the new one should just replace it, or a
5420 value N > 1 if we should also append " [N times]". */
5423 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5424 int prev_bol
, this_bol
;
5425 int prev_bol_byte
, this_bol_byte
;
5428 int len
= Z_BYTE
- 1 - this_bol_byte
;
5430 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5431 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5433 for (i
= 0; i
< len
; i
++)
5435 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5443 if (*p1
++ == ' ' && *p1
++ == '[')
5446 while (*p1
>= '0' && *p1
<= '9')
5447 n
= n
* 10 + *p1
++ - '0';
5448 if (strncmp (p1
, " times]\n", 8) == 0)
5455 /* Display an echo area message M with a specified length of LEN
5456 chars. The string may include null characters. If M is 0, clear
5457 out any existing message, and let the mini-buffer text show through.
5459 The buffer M must continue to exist until after the echo area gets
5460 cleared or some other message gets displayed there. This means do
5461 not pass text that is stored in a Lisp string; do not pass text in
5462 a buffer that was alloca'd. */
5465 message2 (m
, len
, multibyte
)
5470 /* First flush out any partial line written with print. */
5471 message_log_maybe_newline ();
5473 message_dolog (m
, len
, 1, multibyte
);
5474 message2_nolog (m
, len
, multibyte
);
5478 /* The non-logging counterpart of message2. */
5481 message2_nolog (m
, len
, multibyte
)
5485 struct frame
*sf
= SELECTED_FRAME ();
5486 message_enable_multibyte
= multibyte
;
5490 if (noninteractive_need_newline
)
5491 putc ('\n', stderr
);
5492 noninteractive_need_newline
= 0;
5494 fwrite (m
, len
, 1, stderr
);
5495 if (cursor_in_echo_area
== 0)
5496 fprintf (stderr
, "\n");
5499 /* A null message buffer means that the frame hasn't really been
5500 initialized yet. Error messages get reported properly by
5501 cmd_error, so this must be just an informative message; toss it. */
5502 else if (INTERACTIVE
5503 && sf
->glyphs_initialized_p
5504 && FRAME_MESSAGE_BUF (sf
))
5506 Lisp_Object mini_window
;
5509 /* Get the frame containing the mini-buffer
5510 that the selected frame is using. */
5511 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5512 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5514 FRAME_SAMPLE_VISIBILITY (f
);
5515 if (FRAME_VISIBLE_P (sf
)
5516 && ! FRAME_VISIBLE_P (f
))
5517 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5521 set_message (m
, Qnil
, len
, multibyte
);
5522 if (minibuffer_auto_raise
)
5523 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5526 clear_message (1, 1);
5528 do_pending_window_change (0);
5529 echo_area_display (1);
5530 do_pending_window_change (0);
5531 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5532 (*frame_up_to_date_hook
) (f
);
5537 /* Display an echo area message M with a specified length of NBYTES
5538 bytes. The string may include null characters. If M is not a
5539 string, clear out any existing message, and let the mini-buffer
5540 text show through. */
5543 message3 (m
, nbytes
, multibyte
)
5548 struct gcpro gcpro1
;
5552 /* First flush out any partial line written with print. */
5553 message_log_maybe_newline ();
5555 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5556 message3_nolog (m
, nbytes
, multibyte
);
5562 /* The non-logging version of message3. */
5565 message3_nolog (m
, nbytes
, multibyte
)
5567 int nbytes
, multibyte
;
5569 struct frame
*sf
= SELECTED_FRAME ();
5570 message_enable_multibyte
= multibyte
;
5574 if (noninteractive_need_newline
)
5575 putc ('\n', stderr
);
5576 noninteractive_need_newline
= 0;
5578 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5579 if (cursor_in_echo_area
== 0)
5580 fprintf (stderr
, "\n");
5583 /* A null message buffer means that the frame hasn't really been
5584 initialized yet. Error messages get reported properly by
5585 cmd_error, so this must be just an informative message; toss it. */
5586 else if (INTERACTIVE
5587 && sf
->glyphs_initialized_p
5588 && FRAME_MESSAGE_BUF (sf
))
5590 Lisp_Object mini_window
;
5594 /* Get the frame containing the mini-buffer
5595 that the selected frame is using. */
5596 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5597 frame
= XWINDOW (mini_window
)->frame
;
5600 FRAME_SAMPLE_VISIBILITY (f
);
5601 if (FRAME_VISIBLE_P (sf
)
5602 && !FRAME_VISIBLE_P (f
))
5603 Fmake_frame_visible (frame
);
5605 if (STRINGP (m
) && XSTRING (m
)->size
)
5607 set_message (NULL
, m
, nbytes
, multibyte
);
5608 if (minibuffer_auto_raise
)
5609 Fraise_frame (frame
);
5612 clear_message (1, 1);
5614 do_pending_window_change (0);
5615 echo_area_display (1);
5616 do_pending_window_change (0);
5617 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5618 (*frame_up_to_date_hook
) (f
);
5623 /* Display a null-terminated echo area message M. If M is 0, clear
5624 out any existing message, and let the mini-buffer text show through.
5626 The buffer M must continue to exist until after the echo area gets
5627 cleared or some other message gets displayed there. Do not pass
5628 text that is stored in a Lisp string. Do not pass text in a buffer
5629 that was alloca'd. */
5635 message2 (m
, (m
? strlen (m
) : 0), 0);
5639 /* The non-logging counterpart of message1. */
5645 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5648 /* Display a message M which contains a single %s
5649 which gets replaced with STRING. */
5652 message_with_string (m
, string
, log
)
5661 if (noninteractive_need_newline
)
5662 putc ('\n', stderr
);
5663 noninteractive_need_newline
= 0;
5664 fprintf (stderr
, m
, XSTRING (string
)->data
);
5665 if (cursor_in_echo_area
== 0)
5666 fprintf (stderr
, "\n");
5670 else if (INTERACTIVE
)
5672 /* The frame whose minibuffer we're going to display the message on.
5673 It may be larger than the selected frame, so we need
5674 to use its buffer, not the selected frame's buffer. */
5675 Lisp_Object mini_window
;
5676 struct frame
*f
, *sf
= SELECTED_FRAME ();
5678 /* Get the frame containing the minibuffer
5679 that the selected frame is using. */
5680 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5681 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5683 /* A null message buffer means that the frame hasn't really been
5684 initialized yet. Error messages get reported properly by
5685 cmd_error, so this must be just an informative message; toss it. */
5686 if (FRAME_MESSAGE_BUF (f
))
5690 a
[0] = (char *) XSTRING (string
)->data
;
5692 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5693 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5696 message2 (FRAME_MESSAGE_BUF (f
), len
,
5697 STRING_MULTIBYTE (string
));
5699 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5700 STRING_MULTIBYTE (string
));
5702 /* Print should start at the beginning of the message
5703 buffer next time. */
5704 message_buf_print
= 0;
5710 /* Dump an informative message to the minibuf. If M is 0, clear out
5711 any existing message, and let the mini-buffer text show through. */
5715 message (m
, a1
, a2
, a3
)
5717 EMACS_INT a1
, a2
, a3
;
5723 if (noninteractive_need_newline
)
5724 putc ('\n', stderr
);
5725 noninteractive_need_newline
= 0;
5726 fprintf (stderr
, m
, a1
, a2
, a3
);
5727 if (cursor_in_echo_area
== 0)
5728 fprintf (stderr
, "\n");
5732 else if (INTERACTIVE
)
5734 /* The frame whose mini-buffer we're going to display the message
5735 on. It may be larger than the selected frame, so we need to
5736 use its buffer, not the selected frame's buffer. */
5737 Lisp_Object mini_window
;
5738 struct frame
*f
, *sf
= SELECTED_FRAME ();
5740 /* Get the frame containing the mini-buffer
5741 that the selected frame is using. */
5742 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5743 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5745 /* A null message buffer means that the frame hasn't really been
5746 initialized yet. Error messages get reported properly by
5747 cmd_error, so this must be just an informative message; toss
5749 if (FRAME_MESSAGE_BUF (f
))
5760 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5761 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5763 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5764 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5766 #endif /* NO_ARG_ARRAY */
5768 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5773 /* Print should start at the beginning of the message
5774 buffer next time. */
5775 message_buf_print
= 0;
5781 /* The non-logging version of message. */
5784 message_nolog (m
, a1
, a2
, a3
)
5786 EMACS_INT a1
, a2
, a3
;
5788 Lisp_Object old_log_max
;
5789 old_log_max
= Vmessage_log_max
;
5790 Vmessage_log_max
= Qnil
;
5791 message (m
, a1
, a2
, a3
);
5792 Vmessage_log_max
= old_log_max
;
5796 /* Display the current message in the current mini-buffer. This is
5797 only called from error handlers in process.c, and is not time
5803 if (!NILP (echo_area_buffer
[0]))
5806 string
= Fcurrent_message ();
5807 message3 (string
, XSTRING (string
)->size
,
5808 !NILP (current_buffer
->enable_multibyte_characters
));
5813 /* Make sure echo area buffers in echo_buffers[] are life. If they
5814 aren't, make new ones. */
5817 ensure_echo_area_buffers ()
5821 for (i
= 0; i
< 2; ++i
)
5822 if (!BUFFERP (echo_buffer
[i
])
5823 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5826 Lisp_Object old_buffer
;
5829 old_buffer
= echo_buffer
[i
];
5830 sprintf (name
, " *Echo Area %d*", i
);
5831 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5832 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
5834 for (j
= 0; j
< 2; ++j
)
5835 if (EQ (old_buffer
, echo_area_buffer
[j
]))
5836 echo_area_buffer
[j
] = echo_buffer
[i
];
5841 /* Call FN with args A1..A4 with either the current or last displayed
5842 echo_area_buffer as current buffer.
5844 WHICH zero means use the current message buffer
5845 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5846 from echo_buffer[] and clear it.
5848 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5849 suitable buffer from echo_buffer[] and clear it.
5851 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5852 that the current message becomes the last displayed one, make
5853 choose a suitable buffer for echo_area_buffer[0], and clear it.
5855 Value is what FN returns. */
5858 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
5861 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
5867 int this_one
, the_other
, clear_buffer_p
, rc
;
5868 int count
= BINDING_STACK_SIZE ();
5870 /* If buffers aren't life, make new ones. */
5871 ensure_echo_area_buffers ();
5876 this_one
= 0, the_other
= 1;
5878 this_one
= 1, the_other
= 0;
5881 this_one
= 0, the_other
= 1;
5884 /* We need a fresh one in case the current echo buffer equals
5885 the one containing the last displayed echo area message. */
5886 if (!NILP (echo_area_buffer
[this_one
])
5887 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5888 echo_area_buffer
[this_one
] = Qnil
;
5891 /* Choose a suitable buffer from echo_buffer[] is we don't
5893 if (NILP (echo_area_buffer
[this_one
]))
5895 echo_area_buffer
[this_one
]
5896 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5897 ? echo_buffer
[the_other
]
5898 : echo_buffer
[this_one
]);
5902 buffer
= echo_area_buffer
[this_one
];
5904 record_unwind_protect (unwind_with_echo_area_buffer
,
5905 with_echo_area_buffer_unwind_data (w
));
5907 /* Make the echo area buffer current. Note that for display
5908 purposes, it is not necessary that the displayed window's buffer
5909 == current_buffer, except for text property lookup. So, let's
5910 only set that buffer temporarily here without doing a full
5911 Fset_window_buffer. We must also change w->pointm, though,
5912 because otherwise an assertions in unshow_buffer fails, and Emacs
5914 set_buffer_internal_1 (XBUFFER (buffer
));
5918 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5921 current_buffer
->undo_list
= Qt
;
5922 current_buffer
->read_only
= Qnil
;
5924 if (clear_buffer_p
&& Z
> BEG
)
5927 xassert (BEGV
>= BEG
);
5928 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5930 rc
= fn (a1
, a2
, a3
, a4
);
5932 xassert (BEGV
>= BEG
);
5933 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5935 unbind_to (count
, Qnil
);
5940 /* Save state that should be preserved around the call to the function
5941 FN called in with_echo_area_buffer. */
5944 with_echo_area_buffer_unwind_data (w
)
5950 /* Reduce consing by keeping one vector in
5951 Vwith_echo_area_save_vector. */
5952 vector
= Vwith_echo_area_save_vector
;
5953 Vwith_echo_area_save_vector
= Qnil
;
5956 vector
= Fmake_vector (make_number (7), Qnil
);
5958 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5959 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5960 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5964 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5965 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5966 XVECTOR (vector
)->contents
[i
++]
5967 = make_number (XMARKER (w
->pointm
)->charpos
);
5968 XVECTOR (vector
)->contents
[i
++]
5969 = make_number (XMARKER (w
->pointm
)->bytepos
);
5975 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5978 xassert (i
== XVECTOR (vector
)->size
);
5983 /* Restore global state from VECTOR which was created by
5984 with_echo_area_buffer_unwind_data. */
5987 unwind_with_echo_area_buffer (vector
)
5992 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5993 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5994 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5996 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5999 Lisp_Object buffer
, charpos
, bytepos
;
6001 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
6002 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
6003 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
6004 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
6007 set_marker_both (w
->pointm
, buffer
,
6008 XFASTINT (charpos
), XFASTINT (bytepos
));
6011 Vwith_echo_area_save_vector
= vector
;
6016 /* Set up the echo area for use by print functions. MULTIBYTE_P
6017 non-zero means we will print multibyte. */
6020 setup_echo_area_for_printing (multibyte_p
)
6023 ensure_echo_area_buffers ();
6025 if (!message_buf_print
)
6027 /* A message has been output since the last time we printed.
6028 Choose a fresh echo area buffer. */
6029 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6030 echo_area_buffer
[0] = echo_buffer
[1];
6032 echo_area_buffer
[0] = echo_buffer
[0];
6034 /* Switch to that buffer and clear it. */
6035 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6038 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6040 /* Set up the buffer for the multibyteness we need. */
6042 != !NILP (current_buffer
->enable_multibyte_characters
))
6043 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6045 /* Raise the frame containing the echo area. */
6046 if (minibuffer_auto_raise
)
6048 struct frame
*sf
= SELECTED_FRAME ();
6049 Lisp_Object mini_window
;
6050 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6051 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6054 message_log_maybe_newline ();
6055 message_buf_print
= 1;
6059 if (NILP (echo_area_buffer
[0]))
6061 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6062 echo_area_buffer
[0] = echo_buffer
[1];
6064 echo_area_buffer
[0] = echo_buffer
[0];
6067 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6068 /* Someone switched buffers between print requests. */
6069 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6074 /* Display an echo area message in window W. Value is non-zero if W's
6075 height is changed. If display_last_displayed_message_p is
6076 non-zero, display the message that was last displayed, otherwise
6077 display the current message. */
6080 display_echo_area (w
)
6083 int i
, no_message_p
, window_height_changed_p
, count
;
6085 /* Temporarily disable garbage collections while displaying the echo
6086 area. This is done because a GC can print a message itself.
6087 That message would modify the echo area buffer's contents while a
6088 redisplay of the buffer is going on, and seriously confuse
6090 count
= inhibit_garbage_collection ();
6092 /* If there is no message, we must call display_echo_area_1
6093 nevertheless because it resizes the window. But we will have to
6094 reset the echo_area_buffer in question to nil at the end because
6095 with_echo_area_buffer will sets it to an empty buffer. */
6096 i
= display_last_displayed_message_p
? 1 : 0;
6097 no_message_p
= NILP (echo_area_buffer
[i
]);
6099 window_height_changed_p
6100 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6101 display_echo_area_1
,
6102 (EMACS_INT
) w
, Qnil
, 0, 0);
6105 echo_area_buffer
[i
] = Qnil
;
6107 unbind_to (count
, Qnil
);
6108 return window_height_changed_p
;
6112 /* Helper for display_echo_area. Display the current buffer which
6113 contains the current echo area message in window W, a mini-window,
6114 a pointer to which is passed in A1. A2..A4 are currently not used.
6115 Change the height of W so that all of the message is displayed.
6116 Value is non-zero if height of W was changed. */
6119 display_echo_area_1 (a1
, a2
, a3
, a4
)
6124 struct window
*w
= (struct window
*) a1
;
6126 struct text_pos start
;
6127 int window_height_changed_p
= 0;
6129 /* Do this before displaying, so that we have a large enough glyph
6130 matrix for the display. */
6131 window_height_changed_p
= resize_mini_window (w
, 0);
6134 clear_glyph_matrix (w
->desired_matrix
);
6135 XSETWINDOW (window
, w
);
6136 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6137 try_window (window
, start
);
6139 return window_height_changed_p
;
6143 /* Resize the echo area window to exactly the size needed for the
6144 currently displayed message, if there is one. */
6147 resize_echo_area_axactly ()
6149 if (BUFFERP (echo_area_buffer
[0])
6150 && WINDOWP (echo_area_window
))
6152 struct window
*w
= XWINDOW (echo_area_window
);
6155 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6156 (EMACS_INT
) w
, Qnil
, 0, 0);
6159 ++windows_or_buffers_changed
;
6160 ++update_mode_lines
;
6161 redisplay_internal (0);
6167 /* Callback function for with_echo_area_buffer, when used from
6168 resize_echo_area_axactly. A1 contains a pointer to the window to
6169 resize, A2 to A4 are not used. Value is what resize_mini_window
6173 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6178 return resize_mini_window ((struct window
*) a1
, 1);
6182 /* Resize mini-window W to fit the size of its contents. EXACT:P
6183 means size the window exactly to the size needed. Otherwise, it's
6184 only enlarged until W's buffer is empty. Value is non-zero if
6185 the window height has been changed. */
6188 resize_mini_window (w
, exact_p
)
6192 struct frame
*f
= XFRAME (w
->frame
);
6193 int window_height_changed_p
= 0;
6195 xassert (MINI_WINDOW_P (w
));
6197 /* Nil means don't try to resize. */
6198 if (NILP (Vresize_mini_windows
)
6199 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6202 if (!FRAME_MINIBUF_ONLY_P (f
))
6205 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6206 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6207 int height
, max_height
;
6208 int unit
= CANON_Y_UNIT (f
);
6209 struct text_pos start
;
6210 struct buffer
*old_current_buffer
= NULL
;
6212 if (current_buffer
!= XBUFFER (w
->buffer
))
6214 old_current_buffer
= current_buffer
;
6215 set_buffer_internal (XBUFFER (w
->buffer
));
6218 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6220 /* Compute the max. number of lines specified by the user. */
6221 if (FLOATP (Vmax_mini_window_height
))
6222 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6223 else if (INTEGERP (Vmax_mini_window_height
))
6224 max_height
= XINT (Vmax_mini_window_height
);
6226 max_height
= total_height
/ 4;
6228 /* Correct that max. height if it's bogus. */
6229 max_height
= max (1, max_height
);
6230 max_height
= min (total_height
, max_height
);
6232 /* Find out the height of the text in the window. */
6233 if (it
.truncate_lines_p
)
6238 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6239 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6240 height
= it
.current_y
+ last_height
;
6242 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6243 height
-= it
.extra_line_spacing
;
6244 height
= (height
+ unit
- 1) / unit
;
6247 /* Compute a suitable window start. */
6248 if (height
> max_height
)
6250 height
= max_height
;
6251 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6252 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6253 start
= it
.current
.pos
;
6256 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6257 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6259 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6261 /* Let it grow only, until we display an empty message, in which
6262 case the window shrinks again. */
6263 if (height
> XFASTINT (w
->height
))
6265 int old_height
= XFASTINT (w
->height
);
6266 freeze_window_starts (f
, 1);
6267 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6268 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6270 else if (height
< XFASTINT (w
->height
)
6271 && (exact_p
|| BEGV
== ZV
))
6273 int old_height
= XFASTINT (w
->height
);
6274 freeze_window_starts (f
, 0);
6275 shrink_mini_window (w
);
6276 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6281 /* Always resize to exact size needed. */
6282 if (height
> XFASTINT (w
->height
))
6284 int old_height
= XFASTINT (w
->height
);
6285 freeze_window_starts (f
, 1);
6286 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6287 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6289 else if (height
< XFASTINT (w
->height
))
6291 int old_height
= XFASTINT (w
->height
);
6292 freeze_window_starts (f
, 0);
6293 shrink_mini_window (w
);
6297 freeze_window_starts (f
, 1);
6298 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6301 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6305 if (old_current_buffer
)
6306 set_buffer_internal (old_current_buffer
);
6309 return window_height_changed_p
;
6313 /* Value is the current message, a string, or nil if there is no
6321 if (NILP (echo_area_buffer
[0]))
6325 with_echo_area_buffer (0, 0, current_message_1
,
6326 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6328 echo_area_buffer
[0] = Qnil
;
6336 current_message_1 (a1
, a2
, a3
, a4
)
6341 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6344 *msg
= make_buffer_string (BEG
, Z
, 1);
6351 /* Push the current message on Vmessage_stack for later restauration
6352 by restore_message. Value is non-zero if the current message isn't
6353 empty. This is a relatively infrequent operation, so it's not
6354 worth optimizing. */
6360 msg
= current_message ();
6361 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6362 return STRINGP (msg
);
6366 /* Restore message display from the top of Vmessage_stack. */
6373 xassert (CONSP (Vmessage_stack
));
6374 msg
= XCAR (Vmessage_stack
);
6376 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6378 message3_nolog (msg
, 0, 0);
6382 /* Pop the top-most entry off Vmessage_stack. */
6387 xassert (CONSP (Vmessage_stack
));
6388 Vmessage_stack
= XCDR (Vmessage_stack
);
6392 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6393 exits. If the stack is not empty, we have a missing pop_message
6397 check_message_stack ()
6399 if (!NILP (Vmessage_stack
))
6404 /* Truncate to NCHARS what will be displayed in the echo area the next
6405 time we display it---but don't redisplay it now. */
6408 truncate_echo_area (nchars
)
6412 echo_area_buffer
[0] = Qnil
;
6413 /* A null message buffer means that the frame hasn't really been
6414 initialized yet. Error messages get reported properly by
6415 cmd_error, so this must be just an informative message; toss it. */
6416 else if (!noninteractive
6418 && !NILP (echo_area_buffer
[0]))
6420 struct frame
*sf
= SELECTED_FRAME ();
6421 if (FRAME_MESSAGE_BUF (sf
))
6422 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6427 /* Helper function for truncate_echo_area. Truncate the current
6428 message to at most NCHARS characters. */
6431 truncate_message_1 (nchars
, a2
, a3
, a4
)
6436 if (BEG
+ nchars
< Z
)
6437 del_range (BEG
+ nchars
, Z
);
6439 echo_area_buffer
[0] = Qnil
;
6444 /* Set the current message to a substring of S or STRING.
6446 If STRING is a Lisp string, set the message to the first NBYTES
6447 bytes from STRING. NBYTES zero means use the whole string. If
6448 STRING is multibyte, the message will be displayed multibyte.
6450 If S is not null, set the message to the first LEN bytes of S. LEN
6451 zero means use the whole string. MULTIBYTE_P non-zero means S is
6452 multibyte. Display the message multibyte in that case. */
6455 set_message (s
, string
, nbytes
, multibyte_p
)
6460 message_enable_multibyte
6461 = ((s
&& multibyte_p
)
6462 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6464 with_echo_area_buffer (0, -1, set_message_1
,
6465 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6466 message_buf_print
= 0;
6467 help_echo_showing_p
= 0;
6471 /* Helper function for set_message. Arguments have the same meaning
6472 as there, with A1 corresponding to S and A2 corresponding to STRING
6473 This function is called with the echo area buffer being
6477 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6480 EMACS_INT nbytes
, multibyte_p
;
6482 char *s
= (char *) a1
;
6483 Lisp_Object string
= a2
;
6487 /* Change multibyteness of the echo buffer appropriately. */
6488 if (message_enable_multibyte
6489 != !NILP (current_buffer
->enable_multibyte_characters
))
6490 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6492 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6494 /* Insert new message at BEG. */
6495 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6497 if (STRINGP (string
))
6502 nbytes
= XSTRING (string
)->size_byte
;
6503 nchars
= string_byte_to_char (string
, nbytes
);
6505 /* This function takes care of single/multibyte conversion. We
6506 just have to ensure that the echo area buffer has the right
6507 setting of enable_multibyte_characters. */
6508 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6513 nbytes
= strlen (s
);
6515 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6517 /* Convert from multi-byte to single-byte. */
6519 unsigned char work
[1];
6521 /* Convert a multibyte string to single-byte. */
6522 for (i
= 0; i
< nbytes
; i
+= n
)
6524 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6525 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6527 : multibyte_char_to_unibyte (c
, Qnil
));
6528 insert_1_both (work
, 1, 1, 1, 0, 0);
6531 else if (!multibyte_p
6532 && !NILP (current_buffer
->enable_multibyte_characters
))
6534 /* Convert from single-byte to multi-byte. */
6536 unsigned char *msg
= (unsigned char *) s
;
6537 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6539 /* Convert a single-byte string to multibyte. */
6540 for (i
= 0; i
< nbytes
; i
++)
6542 c
= unibyte_char_to_multibyte (msg
[i
]);
6543 n
= CHAR_STRING (c
, str
);
6544 insert_1_both (str
, 1, n
, 1, 0, 0);
6548 insert_1 (s
, nbytes
, 1, 0, 0);
6555 /* Clear messages. CURRENT_P non-zero means clear the current
6556 message. LAST_DISPLAYED_P non-zero means clear the message
6560 clear_message (current_p
, last_displayed_p
)
6561 int current_p
, last_displayed_p
;
6564 echo_area_buffer
[0] = Qnil
;
6566 if (last_displayed_p
)
6567 echo_area_buffer
[1] = Qnil
;
6569 message_buf_print
= 0;
6572 /* Clear garbaged frames.
6574 This function is used where the old redisplay called
6575 redraw_garbaged_frames which in turn called redraw_frame which in
6576 turn called clear_frame. The call to clear_frame was a source of
6577 flickering. I believe a clear_frame is not necessary. It should
6578 suffice in the new redisplay to invalidate all current matrices,
6579 and ensure a complete redisplay of all windows. */
6582 clear_garbaged_frames ()
6586 Lisp_Object tail
, frame
;
6588 FOR_EACH_FRAME (tail
, frame
)
6590 struct frame
*f
= XFRAME (frame
);
6592 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6594 clear_current_matrices (f
);
6600 ++windows_or_buffers_changed
;
6605 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6606 is non-zero update selected_frame. Value is non-zero if the
6607 mini-windows height has been changed. */
6610 echo_area_display (update_frame_p
)
6613 Lisp_Object mini_window
;
6616 int window_height_changed_p
= 0;
6617 struct frame
*sf
= SELECTED_FRAME ();
6619 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6620 w
= XWINDOW (mini_window
);
6621 f
= XFRAME (WINDOW_FRAME (w
));
6623 /* Don't display if frame is invisible or not yet initialized. */
6624 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6627 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6629 #ifdef HAVE_WINDOW_SYSTEM
6630 /* When Emacs starts, selected_frame may be a visible terminal
6631 frame, even if we run under a window system. If we let this
6632 through, a message would be displayed on the terminal. */
6633 if (EQ (selected_frame
, Vterminal_frame
)
6634 && !NILP (Vwindow_system
))
6636 #endif /* HAVE_WINDOW_SYSTEM */
6639 /* Redraw garbaged frames. */
6641 clear_garbaged_frames ();
6643 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6645 echo_area_window
= mini_window
;
6646 window_height_changed_p
= display_echo_area (w
);
6647 w
->must_be_updated_p
= 1;
6649 /* Update the display, unless called from redisplay_internal.
6650 Also don't update the screen during redisplay itself. The
6651 update will happen at the end of redisplay, and an update
6652 here could cause confusion. */
6653 if (update_frame_p
&& !redisplaying_p
)
6657 /* If the display update has been interrupted by pending
6658 input, update mode lines in the frame. Due to the
6659 pending input, it might have been that redisplay hasn't
6660 been called, so that mode lines above the echo area are
6661 garbaged. This looks odd, so we prevent it here. */
6662 if (!display_completed
)
6663 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6665 if (window_height_changed_p
)
6667 /* Must update other windows. */
6668 windows_or_buffers_changed
= 1;
6669 redisplay_internal (0);
6671 else if (FRAME_WINDOW_P (f
) && n
== 0)
6673 /* Window configuration is the same as before.
6674 Can do with a display update of the echo area,
6675 unless we displayed some mode lines. */
6676 update_single_window (w
, 1);
6677 rif
->flush_display (f
);
6680 update_frame (f
, 1, 1);
6682 /* If cursor is in the echo area, make sure that the next
6683 redisplay displays the minibuffer, so that the cursor will
6684 be replaced with what the minibuffer wants. */
6685 if (cursor_in_echo_area
)
6686 ++windows_or_buffers_changed
;
6689 else if (!EQ (mini_window
, selected_window
))
6690 windows_or_buffers_changed
++;
6692 /* Last displayed message is now the current message. */
6693 echo_area_buffer
[1] = echo_area_buffer
[0];
6695 /* Prevent redisplay optimization in redisplay_internal by resetting
6696 this_line_start_pos. This is done because the mini-buffer now
6697 displays the message instead of its buffer text. */
6698 if (EQ (mini_window
, selected_window
))
6699 CHARPOS (this_line_start_pos
) = 0;
6701 return window_height_changed_p
;
6706 /***********************************************************************
6708 ***********************************************************************/
6711 #ifdef HAVE_WINDOW_SYSTEM
6713 /* A buffer for constructing frame titles in it; allocated from the
6714 heap in init_xdisp and resized as needed in store_frame_title_char. */
6716 static char *frame_title_buf
;
6718 /* The buffer's end, and a current output position in it. */
6720 static char *frame_title_buf_end
;
6721 static char *frame_title_ptr
;
6724 /* Store a single character C for the frame title in frame_title_buf.
6725 Re-allocate frame_title_buf if necessary. */
6728 store_frame_title_char (c
)
6731 /* If output position has reached the end of the allocated buffer,
6732 double the buffer's size. */
6733 if (frame_title_ptr
== frame_title_buf_end
)
6735 int len
= frame_title_ptr
- frame_title_buf
;
6736 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6737 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6738 frame_title_buf_end
= frame_title_buf
+ new_size
;
6739 frame_title_ptr
= frame_title_buf
+ len
;
6742 *frame_title_ptr
++ = c
;
6746 /* Store part of a frame title in frame_title_buf, beginning at
6747 frame_title_ptr. STR is the string to store. Do not copy more
6748 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6749 the whole string. Pad with spaces until FIELD_WIDTH number of
6750 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6751 Called from display_mode_element when it is used to build a frame
6755 store_frame_title (str
, field_width
, precision
)
6757 int field_width
, precision
;
6761 /* Copy at most PRECISION chars from STR. */
6762 while ((precision
<= 0 || n
< precision
)
6765 store_frame_title_char (*str
++);
6769 /* Fill up with spaces until FIELD_WIDTH reached. */
6770 while (field_width
> 0
6773 store_frame_title_char (' ');
6781 /* Set the title of FRAME, if it has changed. The title format is
6782 Vicon_title_format if FRAME is iconified, otherwise it is
6783 frame_title_format. */
6786 x_consider_frame_title (frame
)
6789 struct frame
*f
= XFRAME (frame
);
6791 if (FRAME_WINDOW_P (f
)
6792 || FRAME_MINIBUF_ONLY_P (f
)
6793 || f
->explicit_name
)
6795 /* Do we have more than one visible frame on this X display? */
6798 struct buffer
*obuf
;
6802 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6804 struct frame
*tf
= XFRAME (XCAR (tail
));
6807 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6808 && !FRAME_MINIBUF_ONLY_P (tf
)
6809 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6813 /* Set global variable indicating that multiple frames exist. */
6814 multiple_frames
= CONSP (tail
);
6816 /* Switch to the buffer of selected window of the frame. Set up
6817 frame_title_ptr so that display_mode_element will output into it;
6818 then display the title. */
6819 obuf
= current_buffer
;
6820 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6821 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6822 frame_title_ptr
= frame_title_buf
;
6823 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6824 NULL
, DEFAULT_FACE_ID
);
6825 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6826 frame_title_ptr
= NULL
;
6827 set_buffer_internal (obuf
);
6829 /* Set the title only if it's changed. This avoids consing in
6830 the common case where it hasn't. (If it turns out that we've
6831 already wasted too much time by walking through the list with
6832 display_mode_element, then we might need to optimize at a
6833 higher level than this.) */
6834 if (! STRINGP (f
->name
)
6835 || STRING_BYTES (XSTRING (f
->name
)) != len
6836 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6837 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6841 #else /* not HAVE_WINDOW_SYSTEM */
6843 #define frame_title_ptr ((char *)0)
6844 #define store_frame_title(str, mincol, maxcol) 0
6846 #endif /* not HAVE_WINDOW_SYSTEM */
6851 /***********************************************************************
6853 ***********************************************************************/
6856 /* Prepare for redisplay by updating menu-bar item lists when
6857 appropriate. This can call eval. */
6860 prepare_menu_bars ()
6863 struct gcpro gcpro1
, gcpro2
;
6865 Lisp_Object tooltip_frame
;
6867 #ifdef HAVE_X_WINDOWS
6868 tooltip_frame
= tip_frame
;
6870 tooltip_frame
= Qnil
;
6873 /* Update all frame titles based on their buffer names, etc. We do
6874 this before the menu bars so that the buffer-menu will show the
6875 up-to-date frame titles. */
6876 #ifdef HAVE_WINDOW_SYSTEM
6877 if (windows_or_buffers_changed
|| update_mode_lines
)
6879 Lisp_Object tail
, frame
;
6881 FOR_EACH_FRAME (tail
, frame
)
6884 if (!EQ (frame
, tooltip_frame
)
6885 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6886 x_consider_frame_title (frame
);
6889 #endif /* HAVE_WINDOW_SYSTEM */
6891 /* Update the menu bar item lists, if appropriate. This has to be
6892 done before any actual redisplay or generation of display lines. */
6893 all_windows
= (update_mode_lines
6894 || buffer_shared
> 1
6895 || windows_or_buffers_changed
);
6898 Lisp_Object tail
, frame
;
6899 int count
= BINDING_STACK_SIZE ();
6901 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6903 FOR_EACH_FRAME (tail
, frame
)
6907 /* Ignore tooltip frame. */
6908 if (EQ (frame
, tooltip_frame
))
6911 /* If a window on this frame changed size, report that to
6912 the user and clear the size-change flag. */
6913 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6915 Lisp_Object functions
;
6917 /* Clear flag first in case we get an error below. */
6918 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6919 functions
= Vwindow_size_change_functions
;
6920 GCPRO2 (tail
, functions
);
6922 while (CONSP (functions
))
6924 call1 (XCAR (functions
), frame
);
6925 functions
= XCDR (functions
);
6931 update_menu_bar (f
, 0);
6932 #ifdef HAVE_WINDOW_SYSTEM
6933 update_tool_bar (f
, 0);
6938 unbind_to (count
, Qnil
);
6942 struct frame
*sf
= SELECTED_FRAME ();
6943 update_menu_bar (sf
, 1);
6944 #ifdef HAVE_WINDOW_SYSTEM
6945 update_tool_bar (sf
, 1);
6949 /* Motif needs this. See comment in xmenu.c. Turn it off when
6950 pending_menu_activation is not defined. */
6951 #ifdef USE_X_TOOLKIT
6952 pending_menu_activation
= 0;
6957 /* Update the menu bar item list for frame F. This has to be done
6958 before we start to fill in any display lines, because it can call
6961 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6964 update_menu_bar (f
, save_match_data
)
6966 int save_match_data
;
6969 register struct window
*w
;
6971 window
= FRAME_SELECTED_WINDOW (f
);
6972 w
= XWINDOW (window
);
6974 if (update_mode_lines
)
6975 w
->update_mode_line
= Qt
;
6977 if (FRAME_WINDOW_P (f
)
6979 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
6980 FRAME_EXTERNAL_MENU_BAR (f
)
6982 FRAME_MENU_BAR_LINES (f
) > 0
6984 : FRAME_MENU_BAR_LINES (f
) > 0)
6986 /* If the user has switched buffers or windows, we need to
6987 recompute to reflect the new bindings. But we'll
6988 recompute when update_mode_lines is set too; that means
6989 that people can use force-mode-line-update to request
6990 that the menu bar be recomputed. The adverse effect on
6991 the rest of the redisplay algorithm is about the same as
6992 windows_or_buffers_changed anyway. */
6993 if (windows_or_buffers_changed
6994 || !NILP (w
->update_mode_line
)
6995 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6996 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6997 != !NILP (w
->last_had_star
))
6998 || ((!NILP (Vtransient_mark_mode
)
6999 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7000 != !NILP (w
->region_showing
)))
7002 struct buffer
*prev
= current_buffer
;
7003 int count
= BINDING_STACK_SIZE ();
7005 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7006 if (save_match_data
)
7007 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7008 if (NILP (Voverriding_local_map_menu_flag
))
7010 specbind (Qoverriding_terminal_local_map
, Qnil
);
7011 specbind (Qoverriding_local_map
, Qnil
);
7014 /* Run the Lucid hook. */
7015 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
7017 /* If it has changed current-menubar from previous value,
7018 really recompute the menu-bar from the value. */
7019 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7020 call0 (Qrecompute_lucid_menubar
);
7022 safe_run_hooks (Qmenu_bar_update_hook
);
7023 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7025 /* Redisplay the menu bar in case we changed it. */
7026 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
7027 if (FRAME_WINDOW_P (f
)
7028 #if defined (macintosh)
7029 /* All frames on Mac OS share the same menubar. So only the
7030 selected frame should be allowed to set it. */
7031 && f
== SELECTED_FRAME ()
7034 set_frame_menubar (f
, 0, 0);
7036 /* On a terminal screen, the menu bar is an ordinary screen
7037 line, and this makes it get updated. */
7038 w
->update_mode_line
= Qt
;
7039 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7040 /* In the non-toolkit version, the menu bar is an ordinary screen
7041 line, and this makes it get updated. */
7042 w
->update_mode_line
= Qt
;
7043 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
7045 unbind_to (count
, Qnil
);
7046 set_buffer_internal_1 (prev
);
7053 /***********************************************************************
7055 ***********************************************************************/
7057 #ifdef HAVE_WINDOW_SYSTEM
7059 /* Update the tool-bar item list for frame F. This has to be done
7060 before we start to fill in any display lines. Called from
7061 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7062 and restore it here. */
7065 update_tool_bar (f
, save_match_data
)
7067 int save_match_data
;
7069 if (WINDOWP (f
->tool_bar_window
)
7070 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
7075 window
= FRAME_SELECTED_WINDOW (f
);
7076 w
= XWINDOW (window
);
7078 /* If the user has switched buffers or windows, we need to
7079 recompute to reflect the new bindings. But we'll
7080 recompute when update_mode_lines is set too; that means
7081 that people can use force-mode-line-update to request
7082 that the menu bar be recomputed. The adverse effect on
7083 the rest of the redisplay algorithm is about the same as
7084 windows_or_buffers_changed anyway. */
7085 if (windows_or_buffers_changed
7086 || !NILP (w
->update_mode_line
)
7087 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7088 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7089 != !NILP (w
->last_had_star
))
7090 || ((!NILP (Vtransient_mark_mode
)
7091 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7092 != !NILP (w
->region_showing
)))
7094 struct buffer
*prev
= current_buffer
;
7095 int count
= BINDING_STACK_SIZE ();
7097 /* Set current_buffer to the buffer of the selected
7098 window of the frame, so that we get the right local
7100 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7102 /* Save match data, if we must. */
7103 if (save_match_data
)
7104 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7106 /* Make sure that we don't accidentally use bogus keymaps. */
7107 if (NILP (Voverriding_local_map_menu_flag
))
7109 specbind (Qoverriding_terminal_local_map
, Qnil
);
7110 specbind (Qoverriding_local_map
, Qnil
);
7113 /* Build desired tool-bar items from keymaps. */
7115 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7117 /* Redisplay the tool-bar in case we changed it. */
7118 w
->update_mode_line
= Qt
;
7120 unbind_to (count
, Qnil
);
7121 set_buffer_internal_1 (prev
);
7127 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7128 F's desired tool-bar contents. F->tool_bar_items must have
7129 been set up previously by calling prepare_menu_bars. */
7132 build_desired_tool_bar_string (f
)
7135 int i
, size
, size_needed
, string_idx
;
7136 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7137 Lisp_Object image
, plist
, props
;
7139 image
= plist
= props
= Qnil
;
7140 GCPRO3 (image
, plist
, props
);
7142 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7143 Otherwise, make a new string. */
7145 /* The size of the string we might be able to reuse. */
7146 size
= (STRINGP (f
->desired_tool_bar_string
)
7147 ? XSTRING (f
->desired_tool_bar_string
)->size
7150 /* Each image in the string we build is preceded by a space,
7151 and there is a space at the end. */
7152 size_needed
= f
->n_tool_bar_items
+ 1;
7154 /* Reuse f->desired_tool_bar_string, if possible. */
7155 if (size
< size_needed
)
7156 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7160 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7161 Fremove_text_properties (make_number (0), make_number (size
),
7162 props
, f
->desired_tool_bar_string
);
7165 /* Put a `display' property on the string for the images to display,
7166 put a `menu_item' property on tool-bar items with a value that
7167 is the index of the item in F's tool-bar item vector. */
7168 for (i
= 0, string_idx
= 0;
7169 i
< f
->n_tool_bar_items
;
7170 ++i
, string_idx
+= 1)
7172 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7174 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7175 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7176 int margin
, relief
, idx
;
7177 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
7178 extern Lisp_Object Qlaplace
;
7180 /* If image is a vector, choose the image according to the
7182 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7183 if (VECTORP (image
))
7187 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7188 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7191 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7192 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7194 xassert (ASIZE (image
) >= idx
);
7195 image
= AREF (image
, idx
);
7200 /* Ignore invalid image specifications. */
7201 if (!valid_image_p (image
))
7204 /* Display the tool-bar button pressed, or depressed. */
7205 plist
= Fcopy_sequence (XCDR (image
));
7207 /* Compute margin and relief to draw. */
7208 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
7209 margin
= relief
+ max (0, tool_bar_button_margin
);
7211 if (auto_raise_tool_bar_buttons_p
)
7213 /* Add a `:relief' property to the image spec if the item is
7217 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7223 /* If image is selected, display it pressed, i.e. with a
7224 negative relief. If it's not selected, display it with a
7226 plist
= Fplist_put (plist
, QCrelief
,
7228 ? make_number (-relief
)
7229 : make_number (relief
)));
7233 /* Put a margin around the image. */
7235 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
7237 /* If button is not enabled, and we don't have special images
7238 for the disabled state, make the image appear disabled by
7239 applying an appropriate algorithm to it. */
7240 if (!enabled_p
&& idx
< 0)
7241 plist
= Fplist_put (plist
, QCalgorithm
, Qdisabled
);
7243 /* Put a `display' text property on the string for the image to
7244 display. Put a `menu-item' property on the string that gives
7245 the start of this item's properties in the tool-bar items
7247 image
= Fcons (Qimage
, plist
);
7248 props
= list4 (Qdisplay
, image
,
7249 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
7250 Fadd_text_properties (make_number (string_idx
),
7251 make_number (string_idx
+ 1),
7252 props
, f
->desired_tool_bar_string
);
7260 /* Display one line of the tool-bar of frame IT->f. */
7263 display_tool_bar_line (it
)
7266 struct glyph_row
*row
= it
->glyph_row
;
7267 int max_x
= it
->last_visible_x
;
7270 prepare_desired_row (row
);
7271 row
->y
= it
->current_y
;
7273 while (it
->current_x
< max_x
)
7275 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7277 /* Get the next display element. */
7278 if (!get_next_display_element (it
))
7281 /* Produce glyphs. */
7282 x_before
= it
->current_x
;
7283 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7284 PRODUCE_GLYPHS (it
);
7286 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7291 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7293 if (x
+ glyph
->pixel_width
> max_x
)
7295 /* Glyph doesn't fit on line. */
7296 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7302 x
+= glyph
->pixel_width
;
7306 /* Stop at line ends. */
7307 if (ITERATOR_AT_END_OF_LINE_P (it
))
7310 set_iterator_to_next (it
, 1);
7315 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7316 extend_face_to_end_of_line (it
);
7317 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7318 last
->right_box_line_p
= 1;
7319 compute_line_metrics (it
);
7321 /* If line is empty, make it occupy the rest of the tool-bar. */
7322 if (!row
->displays_text_p
)
7324 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7325 row
->ascent
= row
->phys_ascent
= 0;
7328 row
->full_width_p
= 1;
7329 row
->continued_p
= 0;
7330 row
->truncated_on_left_p
= 0;
7331 row
->truncated_on_right_p
= 0;
7333 it
->current_x
= it
->hpos
= 0;
7334 it
->current_y
+= row
->height
;
7340 /* Value is the number of screen lines needed to make all tool-bar
7341 items of frame F visible. */
7344 tool_bar_lines_needed (f
)
7347 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7350 /* Initialize an iterator for iteration over
7351 F->desired_tool_bar_string in the tool-bar window of frame F. */
7352 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7353 it
.first_visible_x
= 0;
7354 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7355 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7357 while (!ITERATOR_AT_END_P (&it
))
7359 it
.glyph_row
= w
->desired_matrix
->rows
;
7360 clear_glyph_row (it
.glyph_row
);
7361 display_tool_bar_line (&it
);
7364 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7368 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7369 height should be changed. */
7372 redisplay_tool_bar (f
)
7377 struct glyph_row
*row
;
7378 int change_height_p
= 0;
7380 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7381 do anything. This means you must start with tool-bar-lines
7382 non-zero to get the auto-sizing effect. Or in other words, you
7383 can turn off tool-bars by specifying tool-bar-lines zero. */
7384 if (!WINDOWP (f
->tool_bar_window
)
7385 || (w
= XWINDOW (f
->tool_bar_window
),
7386 XFASTINT (w
->height
) == 0))
7389 /* Set up an iterator for the tool-bar window. */
7390 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7391 it
.first_visible_x
= 0;
7392 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7395 /* Build a string that represents the contents of the tool-bar. */
7396 build_desired_tool_bar_string (f
);
7397 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7399 /* Display as many lines as needed to display all tool-bar items. */
7400 while (it
.current_y
< it
.last_visible_y
)
7401 display_tool_bar_line (&it
);
7403 /* It doesn't make much sense to try scrolling in the tool-bar
7404 window, so don't do it. */
7405 w
->desired_matrix
->no_scrolling_p
= 1;
7406 w
->must_be_updated_p
= 1;
7408 if (auto_resize_tool_bars_p
)
7412 /* If there are blank lines at the end, except for a partially
7413 visible blank line at the end that is smaller than
7414 CANON_Y_UNIT, change the tool-bar's height. */
7415 row
= it
.glyph_row
- 1;
7416 if (!row
->displays_text_p
7417 && row
->height
>= CANON_Y_UNIT (f
))
7418 change_height_p
= 1;
7420 /* If row displays tool-bar items, but is partially visible,
7421 change the tool-bar's height. */
7422 if (row
->displays_text_p
7423 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7424 change_height_p
= 1;
7426 /* Resize windows as needed by changing the `tool-bar-lines'
7429 && (nlines
= tool_bar_lines_needed (f
),
7430 nlines
!= XFASTINT (w
->height
)))
7432 extern Lisp_Object Qtool_bar_lines
;
7434 int old_height
= XFASTINT (w
->height
);
7436 XSETFRAME (frame
, f
);
7437 clear_glyph_matrix (w
->desired_matrix
);
7438 Fmodify_frame_parameters (frame
,
7439 Fcons (Fcons (Qtool_bar_lines
,
7440 make_number (nlines
)),
7442 if (XFASTINT (w
->height
) != old_height
)
7443 fonts_changed_p
= 1;
7447 return change_height_p
;
7451 /* Get information about the tool-bar item which is displayed in GLYPH
7452 on frame F. Return in *PROP_IDX the index where tool-bar item
7453 properties start in F->tool_bar_items. Value is zero if
7454 GLYPH doesn't display a tool-bar item. */
7457 tool_bar_item_info (f
, glyph
, prop_idx
)
7459 struct glyph
*glyph
;
7465 /* Get the text property `menu-item' at pos. The value of that
7466 property is the start index of this item's properties in
7467 F->tool_bar_items. */
7468 prop
= Fget_text_property (make_number (glyph
->charpos
),
7469 Qmenu_item
, f
->current_tool_bar_string
);
7470 if (INTEGERP (prop
))
7472 *prop_idx
= XINT (prop
);
7481 #endif /* HAVE_WINDOW_SYSTEM */
7485 /************************************************************************
7486 Horizontal scrolling
7487 ************************************************************************/
7489 static int hscroll_window_tree
P_ ((Lisp_Object
));
7490 static int hscroll_windows
P_ ((Lisp_Object
));
7492 /* For all leaf windows in the window tree rooted at WINDOW, set their
7493 hscroll value so that PT is (i) visible in the window, and (ii) so
7494 that it is not within a certain margin at the window's left and
7495 right border. Value is non-zero if any window's hscroll has been
7499 hscroll_window_tree (window
)
7502 int hscrolled_p
= 0;
7504 while (WINDOWP (window
))
7506 struct window
*w
= XWINDOW (window
);
7508 if (WINDOWP (w
->hchild
))
7509 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7510 else if (WINDOWP (w
->vchild
))
7511 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7512 else if (w
->cursor
.vpos
>= 0)
7514 int hscroll_margin
, text_area_x
, text_area_y
;
7515 int text_area_width
, text_area_height
;
7516 struct glyph_row
*current_cursor_row
7517 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7518 struct glyph_row
*desired_cursor_row
7519 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7520 struct glyph_row
*cursor_row
7521 = (desired_cursor_row
->enabled_p
7522 ? desired_cursor_row
7523 : current_cursor_row
);
7525 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7526 &text_area_width
, &text_area_height
);
7528 /* Scroll when cursor is inside this scroll margin. */
7529 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7531 if ((XFASTINT (w
->hscroll
)
7532 && w
->cursor
.x
< hscroll_margin
)
7533 || (cursor_row
->enabled_p
7534 && cursor_row
->truncated_on_right_p
7535 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7539 struct buffer
*saved_current_buffer
;
7542 /* Find point in a display of infinite width. */
7543 saved_current_buffer
= current_buffer
;
7544 current_buffer
= XBUFFER (w
->buffer
);
7546 if (w
== XWINDOW (selected_window
))
7547 pt
= BUF_PT (current_buffer
);
7550 pt
= marker_position (w
->pointm
);
7551 pt
= max (BEGV
, pt
);
7555 /* Move iterator to pt starting at cursor_row->start in
7556 a line with infinite width. */
7557 init_to_row_start (&it
, w
, cursor_row
);
7558 it
.last_visible_x
= INFINITY
;
7559 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7560 current_buffer
= saved_current_buffer
;
7562 /* Center cursor in window. */
7563 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7564 / CANON_X_UNIT (it
.f
));
7566 /* Don't call Fset_window_hscroll if value hasn't
7567 changed because it will prevent redisplay
7569 if (XFASTINT (w
->hscroll
) != hscroll
)
7571 Fset_window_hscroll (window
, make_number (hscroll
));
7580 /* Value is non-zero if hscroll of any leaf window has been changed. */
7585 /* Set hscroll so that cursor is visible and not inside horizontal
7586 scroll margins for all windows in the tree rooted at WINDOW. See
7587 also hscroll_window_tree above. Value is non-zero if any window's
7588 hscroll has been changed. If it has, desired matrices on the frame
7589 of WINDOW are cleared. */
7592 hscroll_windows (window
)
7597 if (automatic_hscrolling_p
)
7599 hscrolled_p
= hscroll_window_tree (window
);
7601 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7610 /************************************************************************
7612 ************************************************************************/
7614 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7615 to a non-zero value. This is sometimes handy to have in a debugger
7620 /* First and last unchanged row for try_window_id. */
7622 int debug_first_unchanged_at_end_vpos
;
7623 int debug_last_unchanged_at_beg_vpos
;
7625 /* Delta vpos and y. */
7627 int debug_dvpos
, debug_dy
;
7629 /* Delta in characters and bytes for try_window_id. */
7631 int debug_delta
, debug_delta_bytes
;
7633 /* Values of window_end_pos and window_end_vpos at the end of
7636 int debug_end_pos
, debug_end_vpos
;
7638 /* Append a string to W->desired_matrix->method. FMT is a printf
7639 format string. A1...A9 are a supplement for a variable-length
7640 argument list. If trace_redisplay_p is non-zero also printf the
7641 resulting string to stderr. */
7644 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7647 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7650 char *method
= w
->desired_matrix
->method
;
7651 int len
= strlen (method
);
7652 int size
= sizeof w
->desired_matrix
->method
;
7653 int remaining
= size
- len
- 1;
7655 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7656 if (len
&& remaining
)
7662 strncpy (method
+ len
, buffer
, remaining
);
7664 if (trace_redisplay_p
)
7665 fprintf (stderr
, "%p (%s): %s\n",
7667 ((BUFFERP (w
->buffer
)
7668 && STRINGP (XBUFFER (w
->buffer
)->name
))
7669 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7674 #endif /* GLYPH_DEBUG */
7677 /* This counter is used to clear the face cache every once in a while
7678 in redisplay_internal. It is incremented for each redisplay.
7679 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7682 #define CLEAR_FACE_CACHE_COUNT 10000
7683 static int clear_face_cache_count
;
7685 /* Record the previous terminal frame we displayed. */
7687 static struct frame
*previous_terminal_frame
;
7689 /* Non-zero while redisplay_internal is in progress. */
7694 /* Value is non-zero if all changes in window W, which displays
7695 current_buffer, are in the text between START and END. START is a
7696 buffer position, END is given as a distance from Z. Used in
7697 redisplay_internal for display optimization. */
7700 text_outside_line_unchanged_p (w
, start
, end
)
7704 int unchanged_p
= 1;
7706 /* If text or overlays have changed, see where. */
7707 if (XFASTINT (w
->last_modified
) < MODIFF
7708 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7710 /* Gap in the line? */
7711 if (GPT
< start
|| Z
- GPT
< end
)
7714 /* Changes start in front of the line, or end after it? */
7716 && (BEG_UNCHANGED
< start
- 1
7717 || END_UNCHANGED
< end
))
7720 /* If selective display, can't optimize if changes start at the
7721 beginning of the line. */
7723 && INTEGERP (current_buffer
->selective_display
)
7724 && XINT (current_buffer
->selective_display
) > 0
7725 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7733 /* Do a frame update, taking possible shortcuts into account. This is
7734 the main external entry point for redisplay.
7736 If the last redisplay displayed an echo area message and that message
7737 is no longer requested, we clear the echo area or bring back the
7738 mini-buffer if that is in use. */
7743 redisplay_internal (0);
7746 /* Return 1 if point moved out of or into a composition. Otherwise
7747 return 0. PREV_BUF and PREV_PT are the last point buffer and
7748 position. BUF and PT are the current point buffer and position. */
7751 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7752 struct buffer
*prev_buf
, *buf
;
7759 XSETBUFFER (buffer
, buf
);
7760 /* Check a composition at the last point if point moved within the
7762 if (prev_buf
== buf
)
7765 /* Point didn't move. */
7768 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7769 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7770 && COMPOSITION_VALID_P (start
, end
, prop
)
7771 && start
< prev_pt
&& end
> prev_pt
)
7772 /* The last point was within the composition. Return 1 iff
7773 point moved out of the composition. */
7774 return (pt
<= start
|| pt
>= end
);
7777 /* Check a composition at the current point. */
7778 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7779 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7780 && COMPOSITION_VALID_P (start
, end
, prop
)
7781 && start
< pt
&& end
> pt
);
7784 /* Reconsider the setting of B->clip_changed which is displayed
7788 reconsider_clip_changes (w
, b
)
7792 if (b
->prevent_redisplay_optimizations_p
)
7793 b
->clip_changed
= 1;
7794 else if (b
->clip_changed
7795 && !NILP (w
->window_end_valid
)
7796 && w
->current_matrix
->buffer
== b
7797 && w
->current_matrix
->zv
== BUF_ZV (b
)
7798 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7799 b
->clip_changed
= 0;
7801 /* If display wasn't paused, and W is not a tool bar window, see if
7802 point has been moved into or out of a composition. In that case,
7803 we set b->clip_changed to 1 to force updating the screen. If
7804 b->clip_changed has already been set to 1, we can skip this
7806 if (!b
->clip_changed
7807 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7811 if (w
== XWINDOW (selected_window
))
7812 pt
= BUF_PT (current_buffer
);
7814 pt
= marker_position (w
->pointm
);
7816 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7817 || pt
!= XINT (w
->last_point
))
7818 && check_point_in_composition (w
->current_matrix
->buffer
,
7819 XINT (w
->last_point
),
7820 XBUFFER (w
->buffer
), pt
))
7821 b
->clip_changed
= 1;
7826 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7827 response to any user action; therefore, we should preserve the echo
7828 area. (Actually, our caller does that job.) Perhaps in the future
7829 avoid recentering windows if it is not necessary; currently that
7830 causes some problems. */
7833 redisplay_internal (preserve_echo_area
)
7834 int preserve_echo_area
;
7836 struct window
*w
= XWINDOW (selected_window
);
7837 struct frame
*f
= XFRAME (w
->frame
);
7839 int must_finish
= 0;
7840 struct text_pos tlbufpos
, tlendpos
;
7841 int number_of_visible_frames
;
7843 struct frame
*sf
= SELECTED_FRAME ();
7845 /* Non-zero means redisplay has to consider all windows on all
7846 frames. Zero means, only selected_window is considered. */
7847 int consider_all_windows_p
;
7849 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7851 /* No redisplay if running in batch mode or frame is not yet fully
7852 initialized, or redisplay is explicitly turned off by setting
7853 Vinhibit_redisplay. */
7855 || !NILP (Vinhibit_redisplay
)
7856 || !f
->glyphs_initialized_p
)
7859 /* The flag redisplay_performed_directly_p is set by
7860 direct_output_for_insert when it already did the whole screen
7861 update necessary. */
7862 if (redisplay_performed_directly_p
)
7864 redisplay_performed_directly_p
= 0;
7865 if (!hscroll_windows (selected_window
))
7869 #ifdef USE_X_TOOLKIT
7870 if (popup_activated ())
7874 /* I don't think this happens but let's be paranoid. */
7878 /* Record a function that resets redisplaying_p to its old value
7879 when we leave this function. */
7880 count
= BINDING_STACK_SIZE ();
7881 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7886 reconsider_clip_changes (w
, current_buffer
);
7888 /* If new fonts have been loaded that make a glyph matrix adjustment
7889 necessary, do it. */
7890 if (fonts_changed_p
)
7892 adjust_glyphs (NULL
);
7893 ++windows_or_buffers_changed
;
7894 fonts_changed_p
= 0;
7897 if (! FRAME_WINDOW_P (sf
)
7898 && previous_terminal_frame
!= sf
)
7900 /* Since frames on an ASCII terminal share the same display
7901 area, displaying a different frame means redisplay the whole
7903 windows_or_buffers_changed
++;
7904 SET_FRAME_GARBAGED (sf
);
7905 XSETFRAME (Vterminal_frame
, sf
);
7907 previous_terminal_frame
= sf
;
7909 /* Set the visible flags for all frames. Do this before checking
7910 for resized or garbaged frames; they want to know if their frames
7911 are visible. See the comment in frame.h for
7912 FRAME_SAMPLE_VISIBILITY. */
7914 Lisp_Object tail
, frame
;
7916 number_of_visible_frames
= 0;
7918 FOR_EACH_FRAME (tail
, frame
)
7920 struct frame
*f
= XFRAME (frame
);
7922 FRAME_SAMPLE_VISIBILITY (f
);
7923 if (FRAME_VISIBLE_P (f
))
7924 ++number_of_visible_frames
;
7925 clear_desired_matrices (f
);
7929 /* Notice any pending interrupt request to change frame size. */
7930 do_pending_window_change (1);
7932 /* Clear frames marked as garbaged. */
7934 clear_garbaged_frames ();
7936 /* Build menubar and tool-bar items. */
7937 prepare_menu_bars ();
7939 if (windows_or_buffers_changed
)
7940 update_mode_lines
++;
7942 /* Detect case that we need to write or remove a star in the mode line. */
7943 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7945 w
->update_mode_line
= Qt
;
7946 if (buffer_shared
> 1)
7947 update_mode_lines
++;
7950 /* If %c is in the mode line, update it if needed. */
7951 if (!NILP (w
->column_number_displayed
)
7952 /* This alternative quickly identifies a common case
7953 where no change is needed. */
7954 && !(PT
== XFASTINT (w
->last_point
)
7955 && XFASTINT (w
->last_modified
) >= MODIFF
7956 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7957 && XFASTINT (w
->column_number_displayed
) != current_column ())
7958 w
->update_mode_line
= Qt
;
7960 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7962 /* The variable buffer_shared is set in redisplay_window and
7963 indicates that we redisplay a buffer in different windows. See
7965 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7967 /* If specs for an arrow have changed, do thorough redisplay
7968 to ensure we remove any arrow that should no longer exist. */
7969 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7970 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7971 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7973 /* Normally the message* functions will have already displayed and
7974 updated the echo area, but the frame may have been trashed, or
7975 the update may have been preempted, so display the echo area
7976 again here. Checking both message buffers captures the case that
7977 the echo area should be cleared. */
7978 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7980 int window_height_changed_p
= echo_area_display (0);
7983 if (fonts_changed_p
)
7985 else if (window_height_changed_p
)
7987 consider_all_windows_p
= 1;
7988 ++update_mode_lines
;
7989 ++windows_or_buffers_changed
;
7991 /* If window configuration was changed, frames may have been
7992 marked garbaged. Clear them or we will experience
7993 surprises wrt scrolling. */
7995 clear_garbaged_frames ();
7998 else if (EQ (selected_window
, minibuf_window
)
7999 && (current_buffer
->clip_changed
8000 || XFASTINT (w
->last_modified
) < MODIFF
8001 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8002 && resize_mini_window (w
, 0))
8004 /* Resized active mini-window to fit the size of what it is
8005 showing if its contents might have changed. */
8007 consider_all_windows_p
= 1;
8008 ++windows_or_buffers_changed
;
8009 ++update_mode_lines
;
8011 /* If window configuration was changed, frames may have been
8012 marked garbaged. Clear them or we will experience
8013 surprises wrt scrolling. */
8015 clear_garbaged_frames ();
8019 /* If showing the region, and mark has changed, we must redisplay
8020 the whole window. The assignment to this_line_start_pos prevents
8021 the optimization directly below this if-statement. */
8022 if (((!NILP (Vtransient_mark_mode
)
8023 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8024 != !NILP (w
->region_showing
))
8025 || (!NILP (w
->region_showing
)
8026 && !EQ (w
->region_showing
,
8027 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
8028 CHARPOS (this_line_start_pos
) = 0;
8030 /* Optimize the case that only the line containing the cursor in the
8031 selected window has changed. Variables starting with this_ are
8032 set in display_line and record information about the line
8033 containing the cursor. */
8034 tlbufpos
= this_line_start_pos
;
8035 tlendpos
= this_line_end_pos
;
8036 if (!consider_all_windows_p
8037 && CHARPOS (tlbufpos
) > 0
8038 && NILP (w
->update_mode_line
)
8039 && !current_buffer
->clip_changed
8040 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
8041 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
8042 /* Make sure recorded data applies to current buffer, etc. */
8043 && this_line_buffer
== current_buffer
8044 && current_buffer
== XBUFFER (w
->buffer
)
8045 && NILP (w
->force_start
)
8046 /* Point must be on the line that we have info recorded about. */
8047 && PT
>= CHARPOS (tlbufpos
)
8048 && PT
<= Z
- CHARPOS (tlendpos
)
8049 /* All text outside that line, including its final newline,
8050 must be unchanged */
8051 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
8052 CHARPOS (tlendpos
)))
8054 if (CHARPOS (tlbufpos
) > BEGV
8055 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
8056 && (CHARPOS (tlbufpos
) == ZV
8057 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
8058 /* Former continuation line has disappeared by becoming empty */
8060 else if (XFASTINT (w
->last_modified
) < MODIFF
8061 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
8062 || MINI_WINDOW_P (w
))
8064 /* We have to handle the case of continuation around a
8065 wide-column character (See the comment in indent.c around
8068 For instance, in the following case:
8070 -------- Insert --------
8071 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
8072 J_I_ ==> J_I_ `^^' are cursors.
8076 As we have to redraw the line above, we should goto cancel. */
8079 int line_height_before
= this_line_pixel_height
;
8081 /* Note that start_display will handle the case that the
8082 line starting at tlbufpos is a continuation lines. */
8083 start_display (&it
, w
, tlbufpos
);
8085 /* Implementation note: It this still necessary? */
8086 if (it
.current_x
!= this_line_start_x
)
8089 TRACE ((stderr
, "trying display optimization 1\n"));
8090 w
->cursor
.vpos
= -1;
8091 overlay_arrow_seen
= 0;
8092 it
.vpos
= this_line_vpos
;
8093 it
.current_y
= this_line_y
;
8094 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8097 /* If line contains point, is not continued,
8098 and ends at same distance from eob as before, we win */
8099 if (w
->cursor
.vpos
>= 0
8100 /* Line is not continued, otherwise this_line_start_pos
8101 would have been set to 0 in display_line. */
8102 && CHARPOS (this_line_start_pos
)
8103 /* Line ends as before. */
8104 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8105 /* Line has same height as before. Otherwise other lines
8106 would have to be shifted up or down. */
8107 && this_line_pixel_height
== line_height_before
)
8109 /* If this is not the window's last line, we must adjust
8110 the charstarts of the lines below. */
8111 if (it
.current_y
< it
.last_visible_y
)
8113 struct glyph_row
*row
8114 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8115 int delta
, delta_bytes
;
8117 if (Z
- CHARPOS (tlendpos
) == ZV
)
8119 /* This line ends at end of (accessible part of)
8120 buffer. There is no newline to count. */
8122 - CHARPOS (tlendpos
)
8123 - MATRIX_ROW_START_CHARPOS (row
));
8124 delta_bytes
= (Z_BYTE
8125 - BYTEPOS (tlendpos
)
8126 - MATRIX_ROW_START_BYTEPOS (row
));
8130 /* This line ends in a newline. Must take
8131 account of the newline and the rest of the
8132 text that follows. */
8134 - CHARPOS (tlendpos
)
8135 - MATRIX_ROW_START_CHARPOS (row
));
8136 delta_bytes
= (Z_BYTE
8137 - BYTEPOS (tlendpos
)
8138 - MATRIX_ROW_START_BYTEPOS (row
));
8141 increment_matrix_positions (w
->current_matrix
,
8143 w
->current_matrix
->nrows
,
8144 delta
, delta_bytes
);
8147 /* If this row displays text now but previously didn't,
8148 or vice versa, w->window_end_vpos may have to be
8150 if ((it
.glyph_row
- 1)->displays_text_p
)
8152 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8153 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8155 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8156 && this_line_vpos
> 0)
8157 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8158 w
->window_end_valid
= Qnil
;
8160 /* Update hint: No need to try to scroll in update_window. */
8161 w
->desired_matrix
->no_scrolling_p
= 1;
8164 *w
->desired_matrix
->method
= 0;
8165 debug_method_add (w
, "optimization 1");
8172 else if (/* Cursor position hasn't changed. */
8173 PT
== XFASTINT (w
->last_point
)
8174 /* Make sure the cursor was last displayed
8175 in this window. Otherwise we have to reposition it. */
8176 && 0 <= w
->cursor
.vpos
8177 && XINT (w
->height
) > w
->cursor
.vpos
)
8181 do_pending_window_change (1);
8183 /* We used to always goto end_of_redisplay here, but this
8184 isn't enough if we have a blinking cursor. */
8185 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8186 goto end_of_redisplay
;
8190 /* If highlighting the region, or if the cursor is in the echo area,
8191 then we can't just move the cursor. */
8192 else if (! (!NILP (Vtransient_mark_mode
)
8193 && !NILP (current_buffer
->mark_active
))
8194 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8195 || highlight_nonselected_windows
)
8196 && NILP (w
->region_showing
)
8197 && NILP (Vshow_trailing_whitespace
)
8198 && !cursor_in_echo_area
)
8201 struct glyph_row
*row
;
8203 /* Skip from tlbufpos to PT and see where it is. Note that
8204 PT may be in invisible text. If so, we will end at the
8205 next visible position. */
8206 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8207 NULL
, DEFAULT_FACE_ID
);
8208 it
.current_x
= this_line_start_x
;
8209 it
.current_y
= this_line_y
;
8210 it
.vpos
= this_line_vpos
;
8212 /* The call to move_it_to stops in front of PT, but
8213 moves over before-strings. */
8214 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8216 if (it
.vpos
== this_line_vpos
8217 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8220 xassert (this_line_vpos
== it
.vpos
);
8221 xassert (this_line_y
== it
.current_y
);
8222 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8230 /* Text changed drastically or point moved off of line. */
8231 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8234 CHARPOS (this_line_start_pos
) = 0;
8235 consider_all_windows_p
|= buffer_shared
> 1;
8236 ++clear_face_cache_count
;
8239 /* Build desired matrices, and update the display. If
8240 consider_all_windows_p is non-zero, do it for all windows on all
8241 frames. Otherwise do it for selected_window, only. */
8243 if (consider_all_windows_p
)
8245 Lisp_Object tail
, frame
;
8247 /* Clear the face cache eventually. */
8248 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8250 clear_face_cache (0);
8251 clear_face_cache_count
= 0;
8254 /* Recompute # windows showing selected buffer. This will be
8255 incremented each time such a window is displayed. */
8258 FOR_EACH_FRAME (tail
, frame
)
8260 struct frame
*f
= XFRAME (frame
);
8262 if (FRAME_WINDOW_P (f
) || f
== sf
)
8264 /* Mark all the scroll bars to be removed; we'll redeem
8265 the ones we want when we redisplay their windows. */
8266 if (condemn_scroll_bars_hook
)
8267 (*condemn_scroll_bars_hook
) (f
);
8269 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8270 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8272 /* Any scroll bars which redisplay_windows should have
8273 nuked should now go away. */
8274 if (judge_scroll_bars_hook
)
8275 (*judge_scroll_bars_hook
) (f
);
8277 /* If fonts changed, display again. */
8278 if (fonts_changed_p
)
8281 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8283 /* See if we have to hscroll. */
8284 if (hscroll_windows (f
->root_window
))
8287 /* Prevent various kinds of signals during display
8288 update. stdio is not robust about handling
8289 signals, which can cause an apparent I/O
8291 if (interrupt_input
)
8295 /* Update the display. */
8296 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8297 pause
|= update_frame (f
, 0, 0);
8301 mark_window_display_accurate (f
->root_window
, 1);
8302 if (frame_up_to_date_hook
)
8303 frame_up_to_date_hook (f
);
8308 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8310 Lisp_Object mini_window
;
8311 struct frame
*mini_frame
;
8313 redisplay_window (selected_window
, 1);
8315 /* Compare desired and current matrices, perform output. */
8318 /* If fonts changed, display again. */
8319 if (fonts_changed_p
)
8322 /* Prevent various kinds of signals during display update.
8323 stdio is not robust about handling signals,
8324 which can cause an apparent I/O error. */
8325 if (interrupt_input
)
8329 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8331 if (hscroll_windows (selected_window
))
8334 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8335 pause
= update_frame (sf
, 0, 0);
8338 /* We may have called echo_area_display at the top of this
8339 function. If the echo area is on another frame, that may
8340 have put text on a frame other than the selected one, so the
8341 above call to update_frame would not have caught it. Catch
8343 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8344 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8346 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8348 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8349 pause
|= update_frame (mini_frame
, 0, 0);
8350 if (!pause
&& hscroll_windows (mini_window
))
8355 /* If display was paused because of pending input, make sure we do a
8356 thorough update the next time. */
8359 /* Prevent the optimization at the beginning of
8360 redisplay_internal that tries a single-line update of the
8361 line containing the cursor in the selected window. */
8362 CHARPOS (this_line_start_pos
) = 0;
8364 /* Let the overlay arrow be updated the next time. */
8365 if (!NILP (last_arrow_position
))
8367 last_arrow_position
= Qt
;
8368 last_arrow_string
= Qt
;
8371 /* If we pause after scrolling, some rows in the current
8372 matrices of some windows are not valid. */
8373 if (!WINDOW_FULL_WIDTH_P (w
)
8374 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8375 update_mode_lines
= 1;
8378 /* Now text on frame agrees with windows, so put info into the
8379 windows for partial redisplay to follow. */
8382 register struct buffer
*b
= XBUFFER (w
->buffer
);
8384 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8385 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8386 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8387 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8389 if (consider_all_windows_p
)
8390 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
8393 XSETFASTINT (w
->last_point
, BUF_PT (b
));
8394 w
->last_cursor
= w
->cursor
;
8395 w
->last_cursor_off_p
= w
->cursor_off_p
;
8397 b
->clip_changed
= 0;
8398 b
->prevent_redisplay_optimizations_p
= 0;
8399 w
->update_mode_line
= Qnil
;
8400 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
8401 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
8403 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8406 /* Record if we are showing a region, so can make sure to
8407 update it fully at next redisplay. */
8408 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
8409 && (EQ (selected_window
,
8410 current_buffer
->last_selected_window
)
8411 || highlight_nonselected_windows
)
8412 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
8413 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
8416 w
->window_end_valid
= w
->buffer
;
8417 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8418 last_arrow_string
= Voverlay_arrow_string
;
8419 if (frame_up_to_date_hook
!= 0)
8420 (*frame_up_to_date_hook
) (sf
);
8422 w
->current_matrix
->buffer
= b
;
8423 w
->current_matrix
->begv
= BUF_BEGV (b
);
8424 w
->current_matrix
->zv
= BUF_ZV (b
);
8427 update_mode_lines
= 0;
8428 windows_or_buffers_changed
= 0;
8431 /* Start SIGIO interrupts coming again. Having them off during the
8432 code above makes it less likely one will discard output, but not
8433 impossible, since there might be stuff in the system buffer here.
8434 But it is much hairier to try to do anything about that. */
8435 if (interrupt_input
)
8439 /* If a frame has become visible which was not before, redisplay
8440 again, so that we display it. Expose events for such a frame
8441 (which it gets when becoming visible) don't call the parts of
8442 redisplay constructing glyphs, so simply exposing a frame won't
8443 display anything in this case. So, we have to display these
8444 frames here explicitly. */
8447 Lisp_Object tail
, frame
;
8450 FOR_EACH_FRAME (tail
, frame
)
8452 int this_is_visible
= 0;
8454 if (XFRAME (frame
)->visible
)
8455 this_is_visible
= 1;
8456 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8457 if (XFRAME (frame
)->visible
)
8458 this_is_visible
= 1;
8460 if (this_is_visible
)
8464 if (new_count
!= number_of_visible_frames
)
8465 windows_or_buffers_changed
++;
8468 /* Change frame size now if a change is pending. */
8469 do_pending_window_change (1);
8471 /* If we just did a pending size change, or have additional
8472 visible frames, redisplay again. */
8473 if (windows_or_buffers_changed
&& !pause
)
8478 unbind_to (count
, Qnil
);
8482 /* Redisplay, but leave alone any recent echo area message unless
8483 another message has been requested in its place.
8485 This is useful in situations where you need to redisplay but no
8486 user action has occurred, making it inappropriate for the message
8487 area to be cleared. See tracking_off and
8488 wait_reading_process_input for examples of these situations. */
8491 redisplay_preserve_echo_area ()
8493 if (!NILP (echo_area_buffer
[1]))
8495 /* We have a previously displayed message, but no current
8496 message. Redisplay the previous message. */
8497 display_last_displayed_message_p
= 1;
8498 redisplay_internal (1);
8499 display_last_displayed_message_p
= 0;
8502 redisplay_internal (1);
8506 /* Function registered with record_unwind_protect in
8507 redisplay_internal. Clears the flag indicating that a redisplay is
8511 unwind_redisplay (old_redisplaying_p
)
8512 Lisp_Object old_redisplaying_p
;
8514 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8519 /* Mark the display of windows in the window tree rooted at WINDOW as
8520 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
8521 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
8522 the next time redisplay_internal is called. */
8525 mark_window_display_accurate (window
, accurate_p
)
8531 for (; !NILP (window
); window
= w
->next
)
8533 w
= XWINDOW (window
);
8535 if (BUFFERP (w
->buffer
))
8537 struct buffer
*b
= XBUFFER (w
->buffer
);
8539 XSETFASTINT (w
->last_modified
,
8540 accurate_p
? BUF_MODIFF (b
) : 0);
8541 XSETFASTINT (w
->last_overlay_modified
,
8542 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8543 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
8546 #if 0 /* I don't think this is necessary because display_line does it.
8548 /* Record if we are showing a region, so can make sure to
8549 update it fully at next redisplay. */
8551 = (!NILP (Vtransient_mark_mode
)
8552 && (w
== XWINDOW (current_buffer
->last_selected_window
)
8553 || highlight_nonselected_windows
)
8554 && (!NILP (b
->mark_active
)
8555 ? Fmarker_position (b
->mark
)
8561 b
->clip_changed
= 0;
8562 b
->prevent_redisplay_optimizations_p
= 0;
8563 w
->current_matrix
->buffer
= b
;
8564 w
->current_matrix
->begv
= BUF_BEGV (b
);
8565 w
->current_matrix
->zv
= BUF_ZV (b
);
8566 w
->last_cursor
= w
->cursor
;
8567 w
->last_cursor_off_p
= w
->cursor_off_p
;
8568 if (w
== XWINDOW (selected_window
))
8569 w
->last_point
= make_number (BUF_PT (b
));
8571 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8575 w
->window_end_valid
= w
->buffer
;
8576 w
->update_mode_line
= Qnil
;
8578 if (!NILP (w
->vchild
))
8579 mark_window_display_accurate (w
->vchild
, accurate_p
);
8580 if (!NILP (w
->hchild
))
8581 mark_window_display_accurate (w
->hchild
, accurate_p
);
8586 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8587 last_arrow_string
= Voverlay_arrow_string
;
8591 /* Force a thorough redisplay the next time by setting
8592 last_arrow_position and last_arrow_string to t, which is
8593 unequal to any useful value of Voverlay_arrow_... */
8594 last_arrow_position
= Qt
;
8595 last_arrow_string
= Qt
;
8600 /* Return value in display table DP (Lisp_Char_Table *) for character
8601 C. Since a display table doesn't have any parent, we don't have to
8602 follow parent. Do not call this function directly but use the
8603 macro DISP_CHAR_VECTOR. */
8606 disp_char_vector (dp
, c
)
8607 struct Lisp_Char_Table
*dp
;
8613 if (SINGLE_BYTE_CHAR_P (c
))
8614 return (dp
->contents
[c
]);
8616 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8619 else if (code
[2] < 32)
8622 /* Here, the possible range of code[0] (== charset ID) is
8623 128..max_charset. Since the top level char table contains data
8624 for multibyte characters after 256th element, we must increment
8625 code[0] by 128 to get a correct index. */
8627 code
[3] = -1; /* anchor */
8629 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8631 val
= dp
->contents
[code
[i
]];
8632 if (!SUB_CHAR_TABLE_P (val
))
8633 return (NILP (val
) ? dp
->defalt
: val
);
8636 /* Here, val is a sub char table. We return the default value of
8638 return (dp
->defalt
);
8643 /***********************************************************************
8645 ***********************************************************************/
8647 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8650 redisplay_windows (window
)
8653 while (!NILP (window
))
8655 struct window
*w
= XWINDOW (window
);
8657 if (!NILP (w
->hchild
))
8658 redisplay_windows (w
->hchild
);
8659 else if (!NILP (w
->vchild
))
8660 redisplay_windows (w
->vchild
);
8662 redisplay_window (window
, 0);
8669 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8670 DELTA is the number of bytes by which positions recorded in ROW
8671 differ from current buffer positions. */
8674 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8676 struct glyph_row
*row
;
8677 struct glyph_matrix
*matrix
;
8678 int delta
, delta_bytes
, dy
, dvpos
;
8680 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8681 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8683 int pt_old
= PT
- delta
;
8685 /* Skip over glyphs not having an object at the start of the row.
8686 These are special glyphs like truncation marks on terminal
8688 if (row
->displays_text_p
)
8690 && INTEGERP (glyph
->object
)
8691 && glyph
->charpos
< 0)
8693 x
+= glyph
->pixel_width
;
8698 && !INTEGERP (glyph
->object
)
8699 && (!BUFFERP (glyph
->object
)
8700 || glyph
->charpos
< pt_old
))
8702 x
+= glyph
->pixel_width
;
8706 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8708 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8709 w
->cursor
.y
= row
->y
+ dy
;
8711 if (w
== XWINDOW (selected_window
))
8713 if (!row
->continued_p
8714 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8717 this_line_buffer
= XBUFFER (w
->buffer
);
8719 CHARPOS (this_line_start_pos
)
8720 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8721 BYTEPOS (this_line_start_pos
)
8722 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8724 CHARPOS (this_line_end_pos
)
8725 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8726 BYTEPOS (this_line_end_pos
)
8727 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8729 this_line_y
= w
->cursor
.y
;
8730 this_line_pixel_height
= row
->height
;
8731 this_line_vpos
= w
->cursor
.vpos
;
8732 this_line_start_x
= row
->x
;
8735 CHARPOS (this_line_start_pos
) = 0;
8740 /* Run window scroll functions, if any, for WINDOW with new window
8741 start STARTP. Sets the window start of WINDOW to that position.
8743 We assume that the window's buffer is really current. */
8745 static INLINE
struct text_pos
8746 run_window_scroll_functions (window
, startp
)
8748 struct text_pos startp
;
8750 struct window
*w
= XWINDOW (window
);
8751 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8753 if (current_buffer
!= XBUFFER (w
->buffer
))
8756 if (!NILP (Vwindow_scroll_functions
))
8758 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8759 make_number (CHARPOS (startp
)));
8760 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8761 /* In case the hook functions switch buffers. */
8762 if (current_buffer
!= XBUFFER (w
->buffer
))
8763 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8770 /* Modify the desired matrix of window W and W->vscroll so that the
8771 line containing the cursor is fully visible. */
8774 make_cursor_line_fully_visible (w
)
8777 struct glyph_matrix
*matrix
;
8778 struct glyph_row
*row
;
8779 int window_height
, header_line_height
;
8781 /* It's not always possible to find the cursor, e.g, when a window
8782 is full of overlay strings. Don't do anything in that case. */
8783 if (w
->cursor
.vpos
< 0)
8786 matrix
= w
->desired_matrix
;
8787 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8789 /* If the cursor row is not partially visible, there's nothing
8791 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8794 /* If the row the cursor is in is taller than the window's height,
8795 it's not clear what to do, so do nothing. */
8796 window_height
= window_box_height (w
);
8797 if (row
->height
>= window_height
)
8800 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
8802 int dy
= row
->height
- row
->visible_height
;
8805 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8807 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
8809 int dy
= - (row
->height
- row
->visible_height
);
8812 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8815 /* When we change the cursor y-position of the selected window,
8816 change this_line_y as well so that the display optimization for
8817 the cursor line of the selected window in redisplay_internal uses
8818 the correct y-position. */
8819 if (w
== XWINDOW (selected_window
))
8820 this_line_y
= w
->cursor
.y
;
8824 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8825 non-zero means only WINDOW is redisplayed in redisplay_internal.
8826 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8827 in redisplay_window to bring a partially visible line into view in
8828 the case that only the cursor has moved.
8832 1 if scrolling succeeded
8834 0 if scrolling didn't find point.
8836 -1 if new fonts have been loaded so that we must interrupt
8837 redisplay, adjust glyph matrices, and try again. */
8840 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8841 scroll_step
, temp_scroll_step
)
8843 int just_this_one_p
;
8844 int scroll_conservatively
, scroll_step
;
8845 int temp_scroll_step
;
8847 struct window
*w
= XWINDOW (window
);
8848 struct frame
*f
= XFRAME (w
->frame
);
8849 struct text_pos scroll_margin_pos
;
8850 struct text_pos pos
;
8851 struct text_pos startp
;
8853 Lisp_Object window_end
;
8854 int this_scroll_margin
;
8858 int amount_to_scroll
= 0;
8859 Lisp_Object aggressive
;
8863 debug_method_add (w
, "try_scrolling");
8866 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8868 /* Compute scroll margin height in pixels. We scroll when point is
8869 within this distance from the top or bottom of the window. */
8870 if (scroll_margin
> 0)
8872 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8873 this_scroll_margin
*= CANON_Y_UNIT (f
);
8876 this_scroll_margin
= 0;
8878 /* Compute how much we should try to scroll maximally to bring point
8880 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
8881 scroll_max
= max (scroll_step
,
8882 max (scroll_conservatively
, temp_scroll_step
));
8883 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8884 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8885 /* We're trying to scroll because of aggressive scrolling
8886 but no scroll_step is set. Choose an arbitrary one. Maybe
8887 there should be a variable for this. */
8891 scroll_max
*= CANON_Y_UNIT (f
);
8893 /* Decide whether we have to scroll down. Start at the window end
8894 and move this_scroll_margin up to find the position of the scroll
8896 window_end
= Fwindow_end (window
, Qt
);
8897 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8898 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8899 if (this_scroll_margin
)
8901 start_display (&it
, w
, scroll_margin_pos
);
8902 move_it_vertically (&it
, - this_scroll_margin
);
8903 scroll_margin_pos
= it
.current
.pos
;
8906 if (PT
>= CHARPOS (scroll_margin_pos
))
8913 /* Point is in the scroll margin at the bottom of the window, or
8914 below. Compute a new window start that makes point visible. */
8916 /* Compute the distance from the scroll margin to PT.
8917 Give up if the distance is greater than scroll_max. */
8918 start_display (&it
, w
, scroll_margin_pos
);
8920 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8921 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8922 #if 0 /* Taking the line's height into account here looks wrong. */
8923 line_height
= (it
.max_ascent
+ it
.max_descent
8924 ? it
.max_ascent
+ it
.max_descent
8926 dy
= it
.current_y
+ line_height
- y0
;
8928 /* With a scroll_margin of 0, scroll_margin_pos is at the window
8929 end, which is one line below the window. The iterator's
8930 current_y will be same as y0 in that case, but we have to
8931 scroll a line to make PT visible. That's the reason why 1 is
8933 dy
= 1 + it
.current_y
- y0
;
8936 if (dy
> scroll_max
)
8939 /* Move the window start down. If scrolling conservatively,
8940 move it just enough down to make point visible. If
8941 scroll_step is set, move it down by scroll_step. */
8942 start_display (&it
, w
, startp
);
8944 if (scroll_conservatively
)
8946 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
8947 else if (scroll_step
|| temp_scroll_step
)
8948 amount_to_scroll
= scroll_max
;
8951 aggressive
= current_buffer
->scroll_down_aggressively
;
8952 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8953 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8954 if (NUMBERP (aggressive
))
8955 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8958 if (amount_to_scroll
<= 0)
8961 move_it_vertically (&it
, amount_to_scroll
);
8962 startp
= it
.current
.pos
;
8966 /* See if point is inside the scroll margin at the top of the
8968 scroll_margin_pos
= startp
;
8969 if (this_scroll_margin
)
8971 start_display (&it
, w
, startp
);
8972 move_it_vertically (&it
, this_scroll_margin
);
8973 scroll_margin_pos
= it
.current
.pos
;
8976 if (PT
< CHARPOS (scroll_margin_pos
))
8978 /* Point is in the scroll margin at the top of the window or
8979 above what is displayed in the window. */
8982 /* Compute the vertical distance from PT to the scroll
8983 margin position. Give up if distance is greater than
8985 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8986 start_display (&it
, w
, pos
);
8988 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8989 it
.last_visible_y
, -1,
8990 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8991 dy
= it
.current_y
- y0
;
8992 if (dy
> scroll_max
)
8995 /* Compute new window start. */
8996 start_display (&it
, w
, startp
);
8998 if (scroll_conservatively
)
9000 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
9001 else if (scroll_step
|| temp_scroll_step
)
9002 amount_to_scroll
= scroll_max
;
9005 aggressive
= current_buffer
->scroll_up_aggressively
;
9006 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
9007 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
9008 if (NUMBERP (aggressive
))
9009 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
9012 if (amount_to_scroll
<= 0)
9015 move_it_vertically (&it
, - amount_to_scroll
);
9016 startp
= it
.current
.pos
;
9020 /* Run window scroll functions. */
9021 startp
= run_window_scroll_functions (window
, startp
);
9023 /* Display the window. Give up if new fonts are loaded, or if point
9025 if (!try_window (window
, startp
))
9027 else if (w
->cursor
.vpos
< 0)
9029 clear_glyph_matrix (w
->desired_matrix
);
9034 /* Maybe forget recorded base line for line number display. */
9035 if (!just_this_one_p
9036 || current_buffer
->clip_changed
9037 || BEG_UNCHANGED
< CHARPOS (startp
))
9038 w
->base_line_number
= Qnil
;
9040 /* If cursor ends up on a partially visible line, shift display
9041 lines up or down. */
9042 make_cursor_line_fully_visible (w
);
9050 /* Compute a suitable window start for window W if display of W starts
9051 on a continuation line. Value is non-zero if a new window start
9054 The new window start will be computed, based on W's width, starting
9055 from the start of the continued line. It is the start of the
9056 screen line with the minimum distance from the old start W->start. */
9059 compute_window_start_on_continuation_line (w
)
9062 struct text_pos pos
, start_pos
;
9063 int window_start_changed_p
= 0;
9065 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
9067 /* If window start is on a continuation line... Window start may be
9068 < BEGV in case there's invisible text at the start of the
9069 buffer (M-x rmail, for example). */
9070 if (CHARPOS (start_pos
) > BEGV
9071 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
9074 struct glyph_row
*row
;
9076 /* Handle the case that the window start is out of range. */
9077 if (CHARPOS (start_pos
) < BEGV
)
9078 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
9079 else if (CHARPOS (start_pos
) > ZV
)
9080 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
9082 /* Find the start of the continued line. This should be fast
9083 because scan_buffer is fast (newline cache). */
9084 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
9085 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
9086 row
, DEFAULT_FACE_ID
);
9087 reseat_at_previous_visible_line_start (&it
);
9089 /* If the line start is "too far" away from the window start,
9090 say it takes too much time to compute a new window start. */
9091 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9092 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9094 int min_distance
, distance
;
9096 /* Move forward by display lines to find the new window
9097 start. If window width was enlarged, the new start can
9098 be expected to be > the old start. If window width was
9099 decreased, the new window start will be < the old start.
9100 So, we're looking for the display line start with the
9101 minimum distance from the old window start. */
9102 pos
= it
.current
.pos
;
9103 min_distance
= INFINITY
;
9104 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9105 distance
< min_distance
)
9107 min_distance
= distance
;
9108 pos
= it
.current
.pos
;
9109 move_it_by_lines (&it
, 1, 0);
9112 /* Set the window start there. */
9113 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9114 window_start_changed_p
= 1;
9118 return window_start_changed_p
;
9122 /* Try cursor movement in case text has not changes in window WINDOW,
9123 with window start STARTP. Value is
9127 0 if this method cannot be used
9129 -1 if we know we have to scroll the display. *SCROLL_STEP is
9130 set to 1, under certain circumstances, if we want to scroll as
9131 if scroll-step were set to 1. See the code. */
9134 try_cursor_movement (window
, startp
, scroll_step
)
9136 struct text_pos startp
;
9139 struct window
*w
= XWINDOW (window
);
9140 struct frame
*f
= XFRAME (w
->frame
);
9143 /* Handle case where text has not changed, only point, and it has
9144 not moved off the frame. */
9145 if (/* Point may be in this window. */
9146 PT
>= CHARPOS (startp
)
9147 /* Selective display hasn't changed. */
9148 && !current_buffer
->clip_changed
9149 /* Function force-mode-line-update is used to force a thorough
9150 redisplay. It sets either windows_or_buffers_changed or
9151 update_mode_lines. So don't take a shortcut here for these
9153 && !update_mode_lines
9154 && !windows_or_buffers_changed
9155 /* Can't use this case if highlighting a region. When a
9156 region exists, cursor movement has to do more than just
9158 && !(!NILP (Vtransient_mark_mode
)
9159 && !NILP (current_buffer
->mark_active
))
9160 && NILP (w
->region_showing
)
9161 && NILP (Vshow_trailing_whitespace
)
9162 /* Right after splitting windows, last_point may be nil. */
9163 && INTEGERP (w
->last_point
)
9164 /* This code is not used for mini-buffer for the sake of the case
9165 of redisplaying to replace an echo area message; since in
9166 that case the mini-buffer contents per se are usually
9167 unchanged. This code is of no real use in the mini-buffer
9168 since the handling of this_line_start_pos, etc., in redisplay
9169 handles the same cases. */
9170 && !EQ (window
, minibuf_window
)
9171 /* When splitting windows or for new windows, it happens that
9172 redisplay is called with a nil window_end_vpos or one being
9173 larger than the window. This should really be fixed in
9174 window.c. I don't have this on my list, now, so we do
9175 approximately the same as the old redisplay code. --gerd. */
9176 && INTEGERP (w
->window_end_vpos
)
9177 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9178 && (FRAME_WINDOW_P (f
)
9179 || !MARKERP (Voverlay_arrow_position
)
9180 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9182 int this_scroll_margin
;
9183 struct glyph_row
*row
;
9186 debug_method_add (w
, "cursor movement");
9189 /* Scroll if point within this distance from the top or bottom
9190 of the window. This is a pixel value. */
9191 this_scroll_margin
= max (0, scroll_margin
);
9192 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9193 this_scroll_margin
*= CANON_Y_UNIT (f
);
9195 /* Start with the row the cursor was displayed during the last
9196 not paused redisplay. Give up if that row is not valid. */
9197 if (w
->last_cursor
.vpos
< 0
9198 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9202 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9203 if (row
->mode_line_p
)
9205 if (!row
->enabled_p
)
9212 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9215 if (PT
> XFASTINT (w
->last_point
))
9217 /* Point has moved forward. */
9218 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9219 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9221 xassert (row
->enabled_p
);
9225 /* The end position of a row equals the start position
9226 of the next row. If PT is there, we would rather
9227 display it in the next line. */
9228 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9229 && MATRIX_ROW_END_CHARPOS (row
) == PT
9230 && !cursor_row_p (w
, row
))
9233 /* If within the scroll margin, scroll. Note that
9234 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9235 the next line would be drawn, and that
9236 this_scroll_margin can be zero. */
9237 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9238 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9239 /* Line is completely visible last line in window
9240 and PT is to be set in the next line. */
9241 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9242 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9243 && !row
->ends_at_zv_p
9244 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9247 else if (PT
< XFASTINT (w
->last_point
))
9249 /* Cursor has to be moved backward. Note that PT >=
9250 CHARPOS (startp) because of the outer
9252 while (!row
->mode_line_p
9253 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9254 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9255 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9256 && (row
->y
> this_scroll_margin
9257 || CHARPOS (startp
) == BEGV
))
9259 xassert (row
->enabled_p
);
9263 /* Consider the following case: Window starts at BEGV,
9264 there is invisible, intangible text at BEGV, so that
9265 display starts at some point START > BEGV. It can
9266 happen that we are called with PT somewhere between
9267 BEGV and START. Try to handle that case. */
9268 if (row
< w
->current_matrix
->rows
9269 || row
->mode_line_p
)
9271 row
= w
->current_matrix
->rows
;
9272 if (row
->mode_line_p
)
9276 /* Due to newlines in overlay strings, we may have to
9277 skip forward over overlay strings. */
9278 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9279 && MATRIX_ROW_END_CHARPOS (row
) == PT
9280 && !cursor_row_p (w
, row
))
9283 /* If within the scroll margin, scroll. */
9284 if (row
->y
< this_scroll_margin
9285 && CHARPOS (startp
) != BEGV
)
9289 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9290 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9292 /* if PT is not in the glyph row, give up. */
9295 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9297 /* If we end up in a partially visible line, let's make it
9298 fully visible, except when it's taller than the window,
9299 in which case we can't do much about it. */
9300 if (row
->height
> window_box_height (w
))
9307 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9308 try_window (window
, startp
);
9309 make_cursor_line_fully_visible (w
);
9317 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9327 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9328 selected_window is redisplayed. */
9331 redisplay_window (window
, just_this_one_p
)
9333 int just_this_one_p
;
9335 struct window
*w
= XWINDOW (window
);
9336 struct frame
*f
= XFRAME (w
->frame
);
9337 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9338 struct buffer
*old
= current_buffer
;
9339 struct text_pos lpoint
, opoint
, startp
;
9340 int update_mode_line
;
9343 /* Record it now because it's overwritten. */
9344 int current_matrix_up_to_date_p
= 0;
9345 int temp_scroll_step
= 0;
9346 int count
= BINDING_STACK_SIZE ();
9349 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9352 /* W must be a leaf window here. */
9353 xassert (!NILP (w
->buffer
));
9355 *w
->desired_matrix
->method
= 0;
9358 specbind (Qinhibit_point_motion_hooks
, Qt
);
9360 reconsider_clip_changes (w
, buffer
);
9362 /* Has the mode line to be updated? */
9363 update_mode_line
= (!NILP (w
->update_mode_line
)
9364 || update_mode_lines
9365 || buffer
->clip_changed
);
9367 if (MINI_WINDOW_P (w
))
9369 if (w
== XWINDOW (echo_area_window
)
9370 && !NILP (echo_area_buffer
[0]))
9372 if (update_mode_line
)
9373 /* We may have to update a tty frame's menu bar or a
9374 tool-bar. Example `M-x C-h C-h C-g'. */
9375 goto finish_menu_bars
;
9377 /* We've already displayed the echo area glyphs in this window. */
9378 goto finish_scroll_bars
;
9380 else if (w
!= XWINDOW (minibuf_window
))
9382 /* W is a mini-buffer window, but it's not the currently
9383 active one, so clear it. */
9384 int yb
= window_text_bottom_y (w
);
9385 struct glyph_row
*row
;
9388 for (y
= 0, row
= w
->desired_matrix
->rows
;
9390 y
+= row
->height
, ++row
)
9391 blank_row (w
, row
, y
);
9392 goto finish_scroll_bars
;
9396 /* Otherwise set up data on this window; select its buffer and point
9398 /* Really select the buffer, for the sake of buffer-local
9400 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9401 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9403 current_matrix_up_to_date_p
9404 = (!NILP (w
->window_end_valid
)
9405 && !current_buffer
->clip_changed
9406 && XFASTINT (w
->last_modified
) >= MODIFF
9407 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9409 /* When windows_or_buffers_changed is non-zero, we can't rely on
9410 the window end being valid, so set it to nil there. */
9411 if (windows_or_buffers_changed
)
9413 /* If window starts on a continuation line, maybe adjust the
9414 window start in case the window's width changed. */
9415 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9416 compute_window_start_on_continuation_line (w
);
9418 w
->window_end_valid
= Qnil
;
9421 /* Some sanity checks. */
9422 CHECK_WINDOW_END (w
);
9423 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9425 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9428 /* If %c is in mode line, update it if needed. */
9429 if (!NILP (w
->column_number_displayed
)
9430 /* This alternative quickly identifies a common case
9431 where no change is needed. */
9432 && !(PT
== XFASTINT (w
->last_point
)
9433 && XFASTINT (w
->last_modified
) >= MODIFF
9434 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9435 && XFASTINT (w
->column_number_displayed
) != current_column ())
9436 update_mode_line
= 1;
9438 /* Count number of windows showing the selected buffer. An indirect
9439 buffer counts as its base buffer. */
9440 if (!just_this_one_p
)
9442 struct buffer
*current_base
, *window_base
;
9443 current_base
= current_buffer
;
9444 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9445 if (current_base
->base_buffer
)
9446 current_base
= current_base
->base_buffer
;
9447 if (window_base
->base_buffer
)
9448 window_base
= window_base
->base_buffer
;
9449 if (current_base
== window_base
)
9453 /* Point refers normally to the selected window. For any other
9454 window, set up appropriate value. */
9455 if (!EQ (window
, selected_window
))
9457 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9458 int new_pt_byte
= marker_byte_position (w
->pointm
);
9462 new_pt_byte
= BEGV_BYTE
;
9463 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9465 else if (new_pt
> (ZV
- 1))
9468 new_pt_byte
= ZV_BYTE
;
9469 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9472 /* We don't use SET_PT so that the point-motion hooks don't run. */
9473 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9476 /* If any of the character widths specified in the display table
9477 have changed, invalidate the width run cache. It's true that
9478 this may be a bit late to catch such changes, but the rest of
9479 redisplay goes (non-fatally) haywire when the display table is
9480 changed, so why should we worry about doing any better? */
9481 if (current_buffer
->width_run_cache
)
9483 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9485 if (! disptab_matches_widthtab (disptab
,
9486 XVECTOR (current_buffer
->width_table
)))
9488 invalidate_region_cache (current_buffer
,
9489 current_buffer
->width_run_cache
,
9491 recompute_width_table (current_buffer
, disptab
);
9495 /* If window-start is screwed up, choose a new one. */
9496 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9499 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9501 /* If someone specified a new starting point but did not insist,
9502 check whether it can be used. */
9503 if (!NILP (w
->optional_new_start
)
9504 && CHARPOS (startp
) >= BEGV
9505 && CHARPOS (startp
) <= ZV
)
9507 w
->optional_new_start
= Qnil
;
9508 start_display (&it
, w
, startp
);
9509 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9510 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9511 if (IT_CHARPOS (it
) == PT
)
9512 w
->force_start
= Qt
;
9515 /* Handle case where place to start displaying has been specified,
9516 unless the specified location is outside the accessible range. */
9517 if (!NILP (w
->force_start
)
9518 || w
->frozen_window_start_p
)
9520 w
->force_start
= Qnil
;
9522 w
->window_end_valid
= Qnil
;
9524 /* Forget any recorded base line for line number display. */
9525 if (!current_matrix_up_to_date_p
9526 || current_buffer
->clip_changed
)
9527 w
->base_line_number
= Qnil
;
9529 /* Redisplay the mode line. Select the buffer properly for that.
9530 Also, run the hook window-scroll-functions
9531 because we have scrolled. */
9532 /* Note, we do this after clearing force_start because
9533 if there's an error, it is better to forget about force_start
9534 than to get into an infinite loop calling the hook functions
9535 and having them get more errors. */
9536 if (!update_mode_line
9537 || ! NILP (Vwindow_scroll_functions
))
9539 update_mode_line
= 1;
9540 w
->update_mode_line
= Qt
;
9541 startp
= run_window_scroll_functions (window
, startp
);
9544 XSETFASTINT (w
->last_modified
, 0);
9545 XSETFASTINT (w
->last_overlay_modified
, 0);
9546 if (CHARPOS (startp
) < BEGV
)
9547 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9548 else if (CHARPOS (startp
) > ZV
)
9549 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9551 /* Redisplay, then check if cursor has been set during the
9552 redisplay. Give up if new fonts were loaded. */
9553 if (!try_window (window
, startp
))
9555 w
->force_start
= Qt
;
9556 clear_glyph_matrix (w
->desired_matrix
);
9557 goto restore_buffers
;
9560 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9562 /* If point does not appear, try to move point so it does
9563 appear. The desired matrix has been built above, so we
9566 struct glyph_row
*row
;
9568 window_height
= window_box_height (w
) / 2;
9569 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9570 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9573 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9574 MATRIX_ROW_START_BYTEPOS (row
));
9576 if (w
!= XWINDOW (selected_window
))
9577 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9578 else if (current_buffer
== old
)
9579 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9581 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9583 /* If we are highlighting the region, then we just changed
9584 the region, so redisplay to show it. */
9585 if (!NILP (Vtransient_mark_mode
)
9586 && !NILP (current_buffer
->mark_active
))
9588 clear_glyph_matrix (w
->desired_matrix
);
9589 if (!try_window (window
, startp
))
9590 goto restore_buffers
;
9594 make_cursor_line_fully_visible (w
);
9596 debug_method_add (w
, "forced window start");
9601 /* Handle case where text has not changed, only point, and it has
9602 not moved off the frame. */
9603 if (current_matrix_up_to_date_p
9604 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9612 /* If current starting point was originally the beginning of a line
9613 but no longer is, find a new starting point. */
9614 else if (!NILP (w
->start_at_line_beg
)
9615 && !(CHARPOS (startp
) <= BEGV
9616 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9619 debug_method_add (w
, "recenter 1");
9624 /* Try scrolling with try_window_id. */
9625 else if (/* Windows and buffers haven't changed. */
9626 !windows_or_buffers_changed
9627 /* Window must be either use window-based redisplay or
9629 && (FRAME_WINDOW_P (f
)
9630 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9631 && !MINI_WINDOW_P (w
)
9632 /* Point is not known NOT to appear in window. */
9633 && PT
>= CHARPOS (startp
)
9634 && XFASTINT (w
->last_modified
)
9635 /* Window is not hscrolled. */
9636 && XFASTINT (w
->hscroll
) == 0
9637 /* Selective display has not changed. */
9638 && !current_buffer
->clip_changed
9639 /* Current matrix is up to date. */
9640 && !NILP (w
->window_end_valid
)
9641 /* Can't use this case if highlighting a region because
9642 a cursor movement will do more than just set the cursor. */
9643 && !(!NILP (Vtransient_mark_mode
)
9644 && !NILP (current_buffer
->mark_active
))
9645 && NILP (w
->region_showing
)
9646 && NILP (Vshow_trailing_whitespace
)
9647 /* Overlay arrow position and string not changed. */
9648 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9649 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9650 /* Value is > 0 if update has been done, it is -1 if we
9651 know that the same window start will not work. It is 0
9652 if unsuccessful for some other reason. */
9653 && (tem
= try_window_id (w
)) != 0)
9656 debug_method_add (w
, "try_window_id %d", tem
);
9659 if (fonts_changed_p
)
9660 goto restore_buffers
;
9664 /* Otherwise try_window_id has returned -1 which means that we
9665 don't want the alternative below this comment to execute. */
9667 else if (CHARPOS (startp
) >= BEGV
9668 && CHARPOS (startp
) <= ZV
9669 && PT
>= CHARPOS (startp
)
9670 && (CHARPOS (startp
) < ZV
9671 /* Avoid starting at end of buffer. */
9672 || CHARPOS (startp
) == BEGV
9673 || (XFASTINT (w
->last_modified
) >= MODIFF
9674 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9677 debug_method_add (w
, "same window start");
9680 /* Try to redisplay starting at same place as before.
9681 If point has not moved off frame, accept the results. */
9682 if (!current_matrix_up_to_date_p
9683 /* Don't use try_window_reusing_current_matrix in this case
9684 because a window scroll function can have changed the
9686 || !NILP (Vwindow_scroll_functions
)
9687 || MINI_WINDOW_P (w
)
9688 || !try_window_reusing_current_matrix (w
))
9690 IF_DEBUG (debug_method_add (w
, "1"));
9691 try_window (window
, startp
);
9694 if (fonts_changed_p
)
9695 goto restore_buffers
;
9697 if (w
->cursor
.vpos
>= 0)
9699 if (!just_this_one_p
9700 || current_buffer
->clip_changed
9701 || BEG_UNCHANGED
< CHARPOS (startp
))
9702 /* Forget any recorded base line for line number display. */
9703 w
->base_line_number
= Qnil
;
9705 make_cursor_line_fully_visible (w
);
9709 clear_glyph_matrix (w
->desired_matrix
);
9714 XSETFASTINT (w
->last_modified
, 0);
9715 XSETFASTINT (w
->last_overlay_modified
, 0);
9717 /* Redisplay the mode line. Select the buffer properly for that. */
9718 if (!update_mode_line
)
9720 update_mode_line
= 1;
9721 w
->update_mode_line
= Qt
;
9724 /* Try to scroll by specified few lines. */
9725 if ((scroll_conservatively
9728 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9729 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9730 && !current_buffer
->clip_changed
9731 && CHARPOS (startp
) >= BEGV
9732 && CHARPOS (startp
) <= ZV
)
9734 /* The function returns -1 if new fonts were loaded, 1 if
9735 successful, 0 if not successful. */
9736 int rc
= try_scrolling (window
, just_this_one_p
,
9737 scroll_conservatively
,
9743 goto restore_buffers
;
9746 /* Finally, just choose place to start which centers point */
9751 debug_method_add (w
, "recenter");
9754 /* w->vscroll = 0; */
9756 /* Forget any previously recorded base line for line number display. */
9757 if (!current_matrix_up_to_date_p
9758 || current_buffer
->clip_changed
)
9759 w
->base_line_number
= Qnil
;
9761 /* Move backward half the height of the window. */
9762 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9763 it
.current_y
= it
.last_visible_y
;
9764 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9765 xassert (IT_CHARPOS (it
) >= BEGV
);
9767 /* The function move_it_vertically_backward may move over more
9768 than the specified y-distance. If it->w is small, e.g. a
9769 mini-buffer window, we may end up in front of the window's
9770 display area. Start displaying at the start of the line
9771 containing PT in this case. */
9772 if (it
.current_y
<= 0)
9774 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9775 move_it_vertically (&it
, 0);
9776 xassert (IT_CHARPOS (it
) <= PT
);
9780 it
.current_x
= it
.hpos
= 0;
9782 /* Set startp here explicitly in case that helps avoid an infinite loop
9783 in case the window-scroll-functions functions get errors. */
9784 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9786 /* Run scroll hooks. */
9787 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9789 /* Redisplay the window. */
9790 if (!current_matrix_up_to_date_p
9791 || windows_or_buffers_changed
9792 /* Don't use try_window_reusing_current_matrix in this case
9793 because it can have changed the buffer. */
9794 || !NILP (Vwindow_scroll_functions
)
9796 || MINI_WINDOW_P (w
)
9797 || !try_window_reusing_current_matrix (w
))
9798 try_window (window
, startp
);
9800 /* If new fonts have been loaded (due to fontsets), give up. We
9801 have to start a new redisplay since we need to re-adjust glyph
9803 if (fonts_changed_p
)
9804 goto restore_buffers
;
9806 /* If cursor did not appear assume that the middle of the window is
9807 in the first line of the window. Do it again with the next line.
9808 (Imagine a window of height 100, displaying two lines of height
9809 60. Moving back 50 from it->last_visible_y will end in the first
9811 if (w
->cursor
.vpos
< 0)
9813 if (!NILP (w
->window_end_valid
)
9814 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9816 clear_glyph_matrix (w
->desired_matrix
);
9817 move_it_by_lines (&it
, 1, 0);
9818 try_window (window
, it
.current
.pos
);
9820 else if (PT
< IT_CHARPOS (it
))
9822 clear_glyph_matrix (w
->desired_matrix
);
9823 move_it_by_lines (&it
, -1, 0);
9824 try_window (window
, it
.current
.pos
);
9828 /* Not much we can do about it. */
9832 /* Consider the following case: Window starts at BEGV, there is
9833 invisible, intangible text at BEGV, so that display starts at
9834 some point START > BEGV. It can happen that we are called with
9835 PT somewhere between BEGV and START. Try to handle that case. */
9836 if (w
->cursor
.vpos
< 0)
9838 struct glyph_row
*row
= w
->current_matrix
->rows
;
9839 if (row
->mode_line_p
)
9841 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9844 make_cursor_line_fully_visible (w
);
9848 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9849 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9850 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9853 /* Display the mode line, if we must. */
9854 if ((update_mode_line
9855 /* If window not full width, must redo its mode line
9856 if (a) the window to its side is being redone and
9857 (b) we do a frame-based redisplay. This is a consequence
9858 of how inverted lines are drawn in frame-based redisplay. */
9859 || (!just_this_one_p
9860 && !FRAME_WINDOW_P (f
)
9861 && !WINDOW_FULL_WIDTH_P (w
))
9862 /* Line number to display. */
9863 || INTEGERP (w
->base_line_pos
)
9864 /* Column number is displayed and different from the one displayed. */
9865 || (!NILP (w
->column_number_displayed
)
9866 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9867 /* This means that the window has a mode line. */
9868 && (WINDOW_WANTS_MODELINE_P (w
)
9869 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9871 Lisp_Object old_selected_frame
;
9873 old_selected_frame
= selected_frame
;
9875 XSETFRAME (selected_frame
, f
);
9876 display_mode_lines (w
);
9877 selected_frame
= old_selected_frame
;
9879 /* If mode line height has changed, arrange for a thorough
9880 immediate redisplay using the correct mode line height. */
9881 if (WINDOW_WANTS_MODELINE_P (w
)
9882 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9884 fonts_changed_p
= 1;
9885 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9886 = DESIRED_MODE_LINE_HEIGHT (w
);
9889 /* If top line height has changed, arrange for a thorough
9890 immediate redisplay using the correct mode line height. */
9891 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9892 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9894 fonts_changed_p
= 1;
9895 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9896 = DESIRED_HEADER_LINE_HEIGHT (w
);
9899 if (fonts_changed_p
)
9900 goto restore_buffers
;
9903 if (!line_number_displayed
9904 && !BUFFERP (w
->base_line_pos
))
9906 w
->base_line_pos
= Qnil
;
9907 w
->base_line_number
= Qnil
;
9912 /* When we reach a frame's selected window, redo the frame's menu bar. */
9913 if (update_mode_line
9914 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9916 int redisplay_menu_p
= 0;
9918 if (FRAME_WINDOW_P (f
))
9920 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
9921 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9923 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9927 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9929 if (redisplay_menu_p
)
9930 display_menu_bar (w
);
9932 #ifdef HAVE_WINDOW_SYSTEM
9933 if (WINDOWP (f
->tool_bar_window
)
9934 && (FRAME_TOOL_BAR_LINES (f
) > 0
9935 || auto_resize_tool_bars_p
))
9936 redisplay_tool_bar (f
);
9942 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9944 int start
, end
, whole
;
9946 /* Calculate the start and end positions for the current window.
9947 At some point, it would be nice to choose between scrollbars
9948 which reflect the whole buffer size, with special markers
9949 indicating narrowing, and scrollbars which reflect only the
9952 Note that mini-buffers sometimes aren't displaying any text. */
9953 if (!MINI_WINDOW_P (w
)
9954 || (w
== XWINDOW (minibuf_window
)
9955 && NILP (echo_area_buffer
[0])))
9958 start
= marker_position (w
->start
) - BEGV
;
9959 /* I don't think this is guaranteed to be right. For the
9960 moment, we'll pretend it is. */
9961 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9965 if (whole
< (end
- start
))
9966 whole
= end
- start
;
9969 start
= end
= whole
= 0;
9971 /* Indicate what this scroll bar ought to be displaying now. */
9972 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9974 /* Note that we actually used the scroll bar attached to this
9975 window, so it shouldn't be deleted at the end of redisplay. */
9976 (*redeem_scroll_bar_hook
) (w
);
9981 /* Restore current_buffer and value of point in it. */
9982 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9983 set_buffer_internal_1 (old
);
9984 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9986 unbind_to (count
, Qnil
);
9990 /* Build the complete desired matrix of WINDOW with a window start
9991 buffer position POS. Value is non-zero if successful. It is zero
9992 if fonts were loaded during redisplay which makes re-adjusting
9993 glyph matrices necessary. */
9996 try_window (window
, pos
)
9998 struct text_pos pos
;
10000 struct window
*w
= XWINDOW (window
);
10002 struct glyph_row
*last_text_row
= NULL
;
10004 /* Make POS the new window start. */
10005 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
10007 /* Mark cursor position as unknown. No overlay arrow seen. */
10008 w
->cursor
.vpos
= -1;
10009 overlay_arrow_seen
= 0;
10011 /* Initialize iterator and info to start at POS. */
10012 start_display (&it
, w
, pos
);
10014 /* Display all lines of W. */
10015 while (it
.current_y
< it
.last_visible_y
)
10017 if (display_line (&it
))
10018 last_text_row
= it
.glyph_row
- 1;
10019 if (fonts_changed_p
)
10023 /* If bottom moved off end of frame, change mode line percentage. */
10024 if (XFASTINT (w
->window_end_pos
) <= 0
10025 && Z
!= IT_CHARPOS (it
))
10026 w
->update_mode_line
= Qt
;
10028 /* Set window_end_pos to the offset of the last character displayed
10029 on the window from the end of current_buffer. Set
10030 window_end_vpos to its row number. */
10033 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
10034 w
->window_end_bytepos
10035 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10036 XSETFASTINT (w
->window_end_pos
,
10037 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10038 XSETFASTINT (w
->window_end_vpos
,
10039 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10040 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
10041 ->displays_text_p
);
10045 w
->window_end_bytepos
= 0;
10046 XSETFASTINT (w
->window_end_pos
, 0);
10047 XSETFASTINT (w
->window_end_vpos
, 0);
10050 /* But that is not valid info until redisplay finishes. */
10051 w
->window_end_valid
= Qnil
;
10057 /************************************************************************
10058 Window redisplay reusing current matrix when buffer has not changed
10059 ************************************************************************/
10061 /* Try redisplay of window W showing an unchanged buffer with a
10062 different window start than the last time it was displayed by
10063 reusing its current matrix. Value is non-zero if successful.
10064 W->start is the new window start. */
10067 try_window_reusing_current_matrix (w
)
10070 struct frame
*f
= XFRAME (w
->frame
);
10071 struct glyph_row
*row
, *bottom_row
;
10074 struct text_pos start
, new_start
;
10075 int nrows_scrolled
, i
;
10076 struct glyph_row
*last_text_row
;
10077 struct glyph_row
*last_reused_text_row
;
10078 struct glyph_row
*start_row
;
10079 int start_vpos
, min_y
, max_y
;
10081 if (/* This function doesn't handle terminal frames. */
10082 !FRAME_WINDOW_P (f
)
10083 /* Don't try to reuse the display if windows have been split
10085 || windows_or_buffers_changed
)
10088 /* Can't do this if region may have changed. */
10089 if ((!NILP (Vtransient_mark_mode
)
10090 && !NILP (current_buffer
->mark_active
))
10091 || !NILP (w
->region_showing
)
10092 || !NILP (Vshow_trailing_whitespace
))
10095 /* If top-line visibility has changed, give up. */
10096 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10097 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10100 /* Give up if old or new display is scrolled vertically. We could
10101 make this function handle this, but right now it doesn't. */
10102 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10103 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10106 /* The variable new_start now holds the new window start. The old
10107 start `start' can be determined from the current matrix. */
10108 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10109 start
= start_row
->start
.pos
;
10110 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10112 /* Clear the desired matrix for the display below. */
10113 clear_glyph_matrix (w
->desired_matrix
);
10115 if (CHARPOS (new_start
) <= CHARPOS (start
))
10119 IF_DEBUG (debug_method_add (w
, "twu1"));
10121 /* Display up to a row that can be reused. The variable
10122 last_text_row is set to the last row displayed that displays
10123 text. Note that it.vpos == 0 if or if not there is a
10124 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10125 start_display (&it
, w
, new_start
);
10126 first_row_y
= it
.current_y
;
10127 w
->cursor
.vpos
= -1;
10128 last_text_row
= last_reused_text_row
= NULL
;
10130 while (it
.current_y
< it
.last_visible_y
10131 && IT_CHARPOS (it
) < CHARPOS (start
)
10132 && !fonts_changed_p
)
10133 if (display_line (&it
))
10134 last_text_row
= it
.glyph_row
- 1;
10136 /* A value of current_y < last_visible_y means that we stopped
10137 at the previous window start, which in turn means that we
10138 have at least one reusable row. */
10139 if (it
.current_y
< it
.last_visible_y
)
10141 /* IT.vpos always starts from 0; it counts text lines. */
10142 nrows_scrolled
= it
.vpos
;
10144 /* Find PT if not already found in the lines displayed. */
10145 if (w
->cursor
.vpos
< 0)
10147 int dy
= it
.current_y
- first_row_y
;
10149 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10150 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10152 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10153 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10155 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10156 dy
, nrows_scrolled
);
10160 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10166 /* Give up if point was not found. This shouldn't
10167 happen often; not more often than with try_window
10169 if (w
->cursor
.vpos
< 0)
10171 clear_glyph_matrix (w
->desired_matrix
);
10176 /* Scroll the display. Do it before the current matrix is
10177 changed. The problem here is that update has not yet
10178 run, i.e. part of the current matrix is not up to date.
10179 scroll_run_hook will clear the cursor, and use the
10180 current matrix to get the height of the row the cursor is
10182 run
.current_y
= first_row_y
;
10183 run
.desired_y
= it
.current_y
;
10184 run
.height
= it
.last_visible_y
- it
.current_y
;
10186 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10189 rif
->update_window_begin_hook (w
);
10190 rif
->clear_mouse_face (w
);
10191 rif
->scroll_run_hook (w
, &run
);
10192 rif
->update_window_end_hook (w
, 0, 0);
10196 /* Shift current matrix down by nrows_scrolled lines. */
10197 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10198 rotate_matrix (w
->current_matrix
,
10200 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10203 /* Disable lines not reused. */
10204 for (i
= 0; i
< it
.vpos
; ++i
)
10205 (start_row
+ i
)->enabled_p
= 0;
10207 /* Re-compute Y positions. */
10208 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10209 max_y
= it
.last_visible_y
;
10210 for (row
= start_row
+ nrows_scrolled
;
10214 row
->y
= it
.current_y
;
10216 if (row
->y
< min_y
)
10217 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10218 else if (row
->y
+ row
->height
> max_y
)
10219 row
->visible_height
10220 = row
->height
- (row
->y
+ row
->height
- max_y
);
10222 row
->visible_height
= row
->height
;
10224 it
.current_y
+= row
->height
;
10226 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10227 last_reused_text_row
= row
;
10228 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10233 /* Update window_end_pos etc.; last_reused_text_row is the last
10234 reused row from the current matrix containing text, if any.
10235 The value of last_text_row is the last displayed line
10236 containing text. */
10237 if (last_reused_text_row
)
10239 w
->window_end_bytepos
10240 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10241 XSETFASTINT (w
->window_end_pos
,
10242 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10243 XSETFASTINT (w
->window_end_vpos
,
10244 MATRIX_ROW_VPOS (last_reused_text_row
,
10245 w
->current_matrix
));
10247 else if (last_text_row
)
10249 w
->window_end_bytepos
10250 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10251 XSETFASTINT (w
->window_end_pos
,
10252 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10253 XSETFASTINT (w
->window_end_vpos
,
10254 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10258 /* This window must be completely empty. */
10259 w
->window_end_bytepos
= 0;
10260 XSETFASTINT (w
->window_end_pos
, 0);
10261 XSETFASTINT (w
->window_end_vpos
, 0);
10263 w
->window_end_valid
= Qnil
;
10265 /* Update hint: don't try scrolling again in update_window. */
10266 w
->desired_matrix
->no_scrolling_p
= 1;
10269 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10273 else if (CHARPOS (new_start
) > CHARPOS (start
))
10275 struct glyph_row
*pt_row
, *row
;
10276 struct glyph_row
*first_reusable_row
;
10277 struct glyph_row
*first_row_to_display
;
10279 int yb
= window_text_bottom_y (w
);
10281 IF_DEBUG (debug_method_add (w
, "twu2"));
10283 /* Find the row starting at new_start, if there is one. Don't
10284 reuse a partially visible line at the end. */
10285 first_reusable_row
= start_row
;
10286 while (first_reusable_row
->enabled_p
10287 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10288 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10289 < CHARPOS (new_start
)))
10290 ++first_reusable_row
;
10292 /* Give up if there is no row to reuse. */
10293 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10294 || !first_reusable_row
->enabled_p
10295 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10296 != CHARPOS (new_start
)))
10299 /* We can reuse fully visible rows beginning with
10300 first_reusable_row to the end of the window. Set
10301 first_row_to_display to the first row that cannot be reused.
10302 Set pt_row to the row containing point, if there is any. */
10303 first_row_to_display
= first_reusable_row
;
10305 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
10307 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10308 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10309 pt_row
= first_row_to_display
;
10311 ++first_row_to_display
;
10314 /* Start displaying at the start of first_row_to_display. */
10315 xassert (first_row_to_display
->y
< yb
);
10316 init_to_row_start (&it
, w
, first_row_to_display
);
10317 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10319 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10321 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10322 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10324 /* Display lines beginning with first_row_to_display in the
10325 desired matrix. Set last_text_row to the last row displayed
10326 that displays text. */
10327 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10328 if (pt_row
== NULL
)
10329 w
->cursor
.vpos
= -1;
10330 last_text_row
= NULL
;
10331 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10332 if (display_line (&it
))
10333 last_text_row
= it
.glyph_row
- 1;
10335 /* Give up If point isn't in a row displayed or reused. */
10336 if (w
->cursor
.vpos
< 0)
10338 clear_glyph_matrix (w
->desired_matrix
);
10342 /* If point is in a reused row, adjust y and vpos of the cursor
10346 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10347 w
->current_matrix
);
10348 w
->cursor
.y
-= first_reusable_row
->y
;
10351 /* Scroll the display. */
10352 run
.current_y
= first_reusable_row
->y
;
10353 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10354 run
.height
= it
.last_visible_y
- run
.current_y
;
10355 dy
= run
.current_y
- run
.desired_y
;
10359 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10361 rif
->update_window_begin_hook (w
);
10362 rif
->clear_mouse_face (w
);
10363 rif
->scroll_run_hook (w
, &run
);
10364 rif
->update_window_end_hook (w
, 0, 0);
10368 /* Adjust Y positions of reused rows. */
10369 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10370 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10371 max_y
= it
.last_visible_y
;
10372 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10375 if (row
->y
< min_y
)
10376 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10377 else if (row
->y
+ row
->height
> max_y
)
10378 row
->visible_height
10379 = row
->height
- (row
->y
+ row
->height
- max_y
);
10381 row
->visible_height
= row
->height
;
10384 /* Disable rows not reused. */
10385 while (row
< bottom_row
)
10387 row
->enabled_p
= 0;
10391 /* Scroll the current matrix. */
10392 xassert (nrows_scrolled
> 0);
10393 rotate_matrix (w
->current_matrix
,
10395 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10398 /* Adjust window end. A null value of last_text_row means that
10399 the window end is in reused rows which in turn means that
10400 only its vpos can have changed. */
10403 w
->window_end_bytepos
10404 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10405 XSETFASTINT (w
->window_end_pos
,
10406 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10407 XSETFASTINT (w
->window_end_vpos
,
10408 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10412 XSETFASTINT (w
->window_end_vpos
,
10413 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10416 w
->window_end_valid
= Qnil
;
10417 w
->desired_matrix
->no_scrolling_p
= 1;
10420 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10430 /************************************************************************
10431 Window redisplay reusing current matrix when buffer has changed
10432 ************************************************************************/
10434 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10435 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10437 static struct glyph_row
*
10438 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10439 struct glyph_row
*));
10442 /* Return the last row in MATRIX displaying text. If row START is
10443 non-null, start searching with that row. IT gives the dimensions
10444 of the display. Value is null if matrix is empty; otherwise it is
10445 a pointer to the row found. */
10447 static struct glyph_row
*
10448 find_last_row_displaying_text (matrix
, it
, start
)
10449 struct glyph_matrix
*matrix
;
10451 struct glyph_row
*start
;
10453 struct glyph_row
*row
, *row_found
;
10455 /* Set row_found to the last row in IT->w's current matrix
10456 displaying text. The loop looks funny but think of partially
10459 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10460 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10462 xassert (row
->enabled_p
);
10464 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10473 /* Return the last row in the current matrix of W that is not affected
10474 by changes at the start of current_buffer that occurred since the
10475 last time W was redisplayed. Value is null if no such row exists.
10477 The global variable beg_unchanged has to contain the number of
10478 bytes unchanged at the start of current_buffer. BEG +
10479 beg_unchanged is the buffer position of the first changed byte in
10480 current_buffer. Characters at positions < BEG + beg_unchanged are
10481 at the same buffer positions as they were when the current matrix
10484 static struct glyph_row
*
10485 find_last_unchanged_at_beg_row (w
)
10488 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10489 struct glyph_row
*row
;
10490 struct glyph_row
*row_found
= NULL
;
10491 int yb
= window_text_bottom_y (w
);
10493 /* Find the last row displaying unchanged text. */
10494 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10495 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10496 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10498 if (/* If row ends before first_changed_pos, it is unchanged,
10499 except in some case. */
10500 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10501 /* When row ends in ZV and we write at ZV it is not
10503 && !row
->ends_at_zv_p
10504 /* When first_changed_pos is the end of a continued line,
10505 row is not unchanged because it may be no longer
10507 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10508 && row
->continued_p
))
10511 /* Stop if last visible row. */
10512 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10522 /* Find the first glyph row in the current matrix of W that is not
10523 affected by changes at the end of current_buffer since the last
10524 time the window was redisplayed. Return in *DELTA the number of
10525 chars by which buffer positions in unchanged text at the end of
10526 current_buffer must be adjusted. Return in *DELTA_BYTES the
10527 corresponding number of bytes. Value is null if no such row
10528 exists, i.e. all rows are affected by changes. */
10530 static struct glyph_row
*
10531 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10533 int *delta
, *delta_bytes
;
10535 struct glyph_row
*row
;
10536 struct glyph_row
*row_found
= NULL
;
10538 *delta
= *delta_bytes
= 0;
10540 /* Display must not have been paused, otherwise the current matrix
10541 is not up to date. */
10542 if (NILP (w
->window_end_valid
))
10545 /* A value of window_end_pos >= END_UNCHANGED means that the window
10546 end is in the range of changed text. If so, there is no
10547 unchanged row at the end of W's current matrix. */
10548 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10551 /* Set row to the last row in W's current matrix displaying text. */
10552 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10554 /* If matrix is entirely empty, no unchanged row exists. */
10555 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10557 /* The value of row is the last glyph row in the matrix having a
10558 meaningful buffer position in it. The end position of row
10559 corresponds to window_end_pos. This allows us to translate
10560 buffer positions in the current matrix to current buffer
10561 positions for characters not in changed text. */
10562 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10563 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10564 int last_unchanged_pos
, last_unchanged_pos_old
;
10565 struct glyph_row
*first_text_row
10566 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10568 *delta
= Z
- Z_old
;
10569 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10571 /* Set last_unchanged_pos to the buffer position of the last
10572 character in the buffer that has not been changed. Z is the
10573 index + 1 of the last byte in current_buffer, i.e. by
10574 subtracting end_unchanged we get the index of the last
10575 unchanged character, and we have to add BEG to get its buffer
10577 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10578 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10580 /* Search backward from ROW for a row displaying a line that
10581 starts at a minimum position >= last_unchanged_pos_old. */
10582 for (; row
> first_text_row
; --row
)
10584 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10587 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10592 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10599 /* Make sure that glyph rows in the current matrix of window W
10600 reference the same glyph memory as corresponding rows in the
10601 frame's frame matrix. This function is called after scrolling W's
10602 current matrix on a terminal frame in try_window_id and
10603 try_window_reusing_current_matrix. */
10606 sync_frame_with_window_matrix_rows (w
)
10609 struct frame
*f
= XFRAME (w
->frame
);
10610 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10612 /* Preconditions: W must be a leaf window and full-width. Its frame
10613 must have a frame matrix. */
10614 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10615 xassert (WINDOW_FULL_WIDTH_P (w
));
10616 xassert (!FRAME_WINDOW_P (f
));
10618 /* If W is a full-width window, glyph pointers in W's current matrix
10619 have, by definition, to be the same as glyph pointers in the
10620 corresponding frame matrix. */
10621 window_row
= w
->current_matrix
->rows
;
10622 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10623 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10624 while (window_row
< window_row_end
)
10628 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10629 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10631 /* Disable frame rows whose corresponding window rows have
10632 been disabled in try_window_id. */
10633 if (!window_row
->enabled_p
)
10634 frame_row
->enabled_p
= 0;
10636 ++window_row
, ++frame_row
;
10641 /* Find the glyph row in window W containing CHARPOS. Consider all
10642 rows between START and END (not inclusive). END null means search
10643 all rows to the end of the display area of W. Value is the row
10644 containing CHARPOS or null. */
10646 static struct glyph_row
*
10647 row_containing_pos (w
, charpos
, start
, end
)
10650 struct glyph_row
*start
, *end
;
10652 struct glyph_row
*row
= start
;
10655 /* If we happen to start on a header-line, skip that. */
10656 if (row
->mode_line_p
)
10659 if ((end
&& row
>= end
) || !row
->enabled_p
)
10662 last_y
= window_text_bottom_y (w
);
10664 while ((end
== NULL
|| row
< end
)
10665 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
10666 /* The end position of a row equals the start
10667 position of the next row. If CHARPOS is there, we
10668 would rather display it in the next line, except
10669 when this line ends in ZV. */
10670 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10671 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10672 || !row
->ends_at_zv_p
)))
10673 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10676 /* Give up if CHARPOS not found. */
10677 if ((end
&& row
>= end
)
10678 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10679 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10686 /* Try to redisplay window W by reusing its existing display. W's
10687 current matrix must be up to date when this function is called,
10688 i.e. window_end_valid must not be nil.
10692 1 if display has been updated
10693 0 if otherwise unsuccessful
10694 -1 if redisplay with same window start is known not to succeed
10696 The following steps are performed:
10698 1. Find the last row in the current matrix of W that is not
10699 affected by changes at the start of current_buffer. If no such row
10702 2. Find the first row in W's current matrix that is not affected by
10703 changes at the end of current_buffer. Maybe there is no such row.
10705 3. Display lines beginning with the row + 1 found in step 1 to the
10706 row found in step 2 or, if step 2 didn't find a row, to the end of
10709 4. If cursor is not known to appear on the window, give up.
10711 5. If display stopped at the row found in step 2, scroll the
10712 display and current matrix as needed.
10714 6. Maybe display some lines at the end of W, if we must. This can
10715 happen under various circumstances, like a partially visible line
10716 becoming fully visible, or because newly displayed lines are displayed
10717 in smaller font sizes.
10719 7. Update W's window end information. */
10721 /* Check that window end is what we expect it to be. */
10727 struct frame
*f
= XFRAME (w
->frame
);
10728 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10729 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10730 struct glyph_row
*last_unchanged_at_beg_row
;
10731 struct glyph_row
*first_unchanged_at_end_row
;
10732 struct glyph_row
*row
;
10733 struct glyph_row
*bottom_row
;
10736 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10737 struct text_pos start_pos
;
10739 int first_unchanged_at_end_vpos
= 0;
10740 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10741 struct text_pos start
;
10743 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10745 /* Check pre-conditions. Window end must be valid, otherwise
10746 the current matrix would not be up to date. */
10747 xassert (!NILP (w
->window_end_valid
));
10748 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10749 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10751 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10752 only if buffer has really changed. The reason is that the gap is
10753 initially at Z for freshly visited files. The code below would
10754 set end_unchanged to 0 in that case. */
10755 if (MODIFF
> SAVE_MODIFF
10756 /* This seems to happen sometimes after saving a buffer. */
10757 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10759 if (GPT
- BEG
< BEG_UNCHANGED
)
10760 BEG_UNCHANGED
= GPT
- BEG
;
10761 if (Z
- GPT
< END_UNCHANGED
)
10762 END_UNCHANGED
= Z
- GPT
;
10765 /* If window starts after a line end, and the last change is in
10766 front of that newline, then changes don't affect the display.
10767 This case happens with stealth-fontification. Note that although
10768 the display is unchanged, glyph positions in the matrix have to
10769 be adjusted, of course. */
10770 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10771 if (CHARPOS (start
) > BEGV
10772 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10773 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10774 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10776 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10777 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10781 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10782 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10784 increment_matrix_positions (w
->current_matrix
,
10785 MATRIX_ROW_VPOS (r0
, current_matrix
),
10786 MATRIX_ROW_VPOS (r1
, current_matrix
),
10787 delta
, delta_bytes
);
10790 #if 0 /* If changes are all in front of the window start, the
10791 distance of the last displayed glyph from Z hasn't
10794 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10795 w
->window_end_bytepos
10796 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10799 row
= row_containing_pos (w
, PT
, r0
, NULL
);
10803 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10807 /* Return quickly if changes are all below what is displayed in the
10808 window, and if PT is in the window. */
10809 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10810 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10812 /* We have to update window end positions because the buffer's
10813 size has changed. */
10815 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10816 w
->window_end_bytepos
10817 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10819 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10820 row
= row_containing_pos (w
, PT
, row
, NULL
);
10821 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10825 /* Check that window start agrees with the start of the first glyph
10826 row in its current matrix. Check this after we know the window
10827 start is not in changed text, otherwise positions would not be
10829 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10830 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10833 /* Compute the position at which we have to start displaying new
10834 lines. Some of the lines at the top of the window might be
10835 reusable because they are not displaying changed text. Find the
10836 last row in W's current matrix not affected by changes at the
10837 start of current_buffer. Value is null if changes start in the
10838 first line of window. */
10839 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
10840 if (last_unchanged_at_beg_row
)
10842 /* Avoid starting to display in the moddle of a character, a TAB
10843 for instance. This is easier than to set up the iterator
10844 exactly, and it's not a frequent case, so the additional
10845 effort wouldn't really pay off. */
10846 while (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
10847 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
10848 --last_unchanged_at_beg_row
;
10850 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
10853 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10854 start_pos
= it
.current
.pos
;
10856 /* Start displaying new lines in the desired matrix at the same
10857 vpos we would use in the current matrix, i.e. below
10858 last_unchanged_at_beg_row. */
10859 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10861 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10862 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10864 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10868 /* There are no reusable lines at the start of the window.
10869 Start displaying in the first line. */
10870 start_display (&it
, w
, start
);
10871 start_pos
= it
.current
.pos
;
10874 /* Find the first row that is not affected by changes at the end of
10875 the buffer. Value will be null if there is no unchanged row, in
10876 which case we must redisplay to the end of the window. delta
10877 will be set to the value by which buffer positions beginning with
10878 first_unchanged_at_end_row have to be adjusted due to text
10880 first_unchanged_at_end_row
10881 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10882 IF_DEBUG (debug_delta
= delta
);
10883 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10885 /* Set stop_pos to the buffer position up to which we will have to
10886 display new lines. If first_unchanged_at_end_row != NULL, this
10887 is the buffer position of the start of the line displayed in that
10888 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10889 that we don't stop at a buffer position. */
10891 if (first_unchanged_at_end_row
)
10893 xassert (last_unchanged_at_beg_row
== NULL
10894 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10896 /* If this is a continuation line, move forward to the next one
10897 that isn't. Changes in lines above affect this line.
10898 Caution: this may move first_unchanged_at_end_row to a row
10899 not displaying text. */
10900 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10901 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10902 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10903 < it
.last_visible_y
))
10904 ++first_unchanged_at_end_row
;
10906 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10907 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10908 >= it
.last_visible_y
))
10909 first_unchanged_at_end_row
= NULL
;
10912 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10914 first_unchanged_at_end_vpos
10915 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10916 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10919 else if (last_unchanged_at_beg_row
== NULL
)
10925 /* Either there is no unchanged row at the end, or the one we have
10926 now displays text. This is a necessary condition for the window
10927 end pos calculation at the end of this function. */
10928 xassert (first_unchanged_at_end_row
== NULL
10929 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10931 debug_last_unchanged_at_beg_vpos
10932 = (last_unchanged_at_beg_row
10933 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10935 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10937 #endif /* GLYPH_DEBUG != 0 */
10940 /* Display new lines. Set last_text_row to the last new line
10941 displayed which has text on it, i.e. might end up as being the
10942 line where the window_end_vpos is. */
10943 w
->cursor
.vpos
= -1;
10944 last_text_row
= NULL
;
10945 overlay_arrow_seen
= 0;
10946 while (it
.current_y
< it
.last_visible_y
10947 && !fonts_changed_p
10948 && (first_unchanged_at_end_row
== NULL
10949 || IT_CHARPOS (it
) < stop_pos
))
10951 if (display_line (&it
))
10952 last_text_row
= it
.glyph_row
- 1;
10955 if (fonts_changed_p
)
10959 /* Compute differences in buffer positions, y-positions etc. for
10960 lines reused at the bottom of the window. Compute what we can
10962 if (first_unchanged_at_end_row
10963 /* No lines reused because we displayed everything up to the
10964 bottom of the window. */
10965 && it
.current_y
< it
.last_visible_y
)
10968 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10970 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10971 run
.current_y
= first_unchanged_at_end_row
->y
;
10972 run
.desired_y
= run
.current_y
+ dy
;
10973 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10977 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10978 first_unchanged_at_end_row
= NULL
;
10980 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10983 /* Find the cursor if not already found. We have to decide whether
10984 PT will appear on this window (it sometimes doesn't, but this is
10985 not a very frequent case.) This decision has to be made before
10986 the current matrix is altered. A value of cursor.vpos < 0 means
10987 that PT is either in one of the lines beginning at
10988 first_unchanged_at_end_row or below the window. Don't care for
10989 lines that might be displayed later at the window end; as
10990 mentioned, this is not a frequent case. */
10991 if (w
->cursor
.vpos
< 0)
10993 /* Cursor in unchanged rows at the top? */
10994 if (PT
< CHARPOS (start_pos
)
10995 && last_unchanged_at_beg_row
)
10997 row
= row_containing_pos (w
, PT
,
10998 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10999 last_unchanged_at_beg_row
+ 1);
11001 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11004 /* Start from first_unchanged_at_end_row looking for PT. */
11005 else if (first_unchanged_at_end_row
)
11007 row
= row_containing_pos (w
, PT
- delta
,
11008 first_unchanged_at_end_row
, NULL
);
11010 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
11011 delta_bytes
, dy
, dvpos
);
11014 /* Give up if cursor was not found. */
11015 if (w
->cursor
.vpos
< 0)
11017 clear_glyph_matrix (w
->desired_matrix
);
11022 /* Don't let the cursor end in the scroll margins. */
11024 int this_scroll_margin
, cursor_height
;
11026 this_scroll_margin
= max (0, scroll_margin
);
11027 this_scroll_margin
= min (this_scroll_margin
,
11028 XFASTINT (w
->height
) / 4);
11029 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
11030 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
11032 if ((w
->cursor
.y
< this_scroll_margin
11033 && CHARPOS (start
) > BEGV
)
11034 /* Don't take scroll margin into account at the bottom because
11035 old redisplay didn't do it either. */
11036 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
11038 w
->cursor
.vpos
= -1;
11039 clear_glyph_matrix (w
->desired_matrix
);
11044 /* Scroll the display. Do it before changing the current matrix so
11045 that xterm.c doesn't get confused about where the cursor glyph is
11047 if (dy
&& run
.height
)
11051 if (FRAME_WINDOW_P (f
))
11053 rif
->update_window_begin_hook (w
);
11054 rif
->clear_mouse_face (w
);
11055 rif
->scroll_run_hook (w
, &run
);
11056 rif
->update_window_end_hook (w
, 0, 0);
11060 /* Terminal frame. In this case, dvpos gives the number of
11061 lines to scroll by; dvpos < 0 means scroll up. */
11062 int first_unchanged_at_end_vpos
11063 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
11064 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
11065 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
11067 /* Perform the operation on the screen. */
11070 /* Scroll last_unchanged_at_beg_row to the end of the
11071 window down dvpos lines. */
11072 set_terminal_window (end
);
11074 /* On dumb terminals delete dvpos lines at the end
11075 before inserting dvpos empty lines. */
11076 if (!scroll_region_ok
)
11077 ins_del_lines (end
- dvpos
, -dvpos
);
11079 /* Insert dvpos empty lines in front of
11080 last_unchanged_at_beg_row. */
11081 ins_del_lines (from
, dvpos
);
11083 else if (dvpos
< 0)
11085 /* Scroll up last_unchanged_at_beg_vpos to the end of
11086 the window to last_unchanged_at_beg_vpos - |dvpos|. */
11087 set_terminal_window (end
);
11089 /* Delete dvpos lines in front of
11090 last_unchanged_at_beg_vpos. ins_del_lines will set
11091 the cursor to the given vpos and emit |dvpos| delete
11093 ins_del_lines (from
+ dvpos
, dvpos
);
11095 /* On a dumb terminal insert dvpos empty lines at the
11097 if (!scroll_region_ok
)
11098 ins_del_lines (end
+ dvpos
, -dvpos
);
11101 set_terminal_window (0);
11107 /* Shift reused rows of the current matrix to the right position.
11108 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11110 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11111 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11114 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11115 bottom_vpos
, dvpos
);
11116 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11119 else if (dvpos
> 0)
11121 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11122 bottom_vpos
, dvpos
);
11123 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11124 first_unchanged_at_end_vpos
+ dvpos
, 0);
11127 /* For frame-based redisplay, make sure that current frame and window
11128 matrix are in sync with respect to glyph memory. */
11129 if (!FRAME_WINDOW_P (f
))
11130 sync_frame_with_window_matrix_rows (w
);
11132 /* Adjust buffer positions in reused rows. */
11134 increment_matrix_positions (current_matrix
,
11135 first_unchanged_at_end_vpos
+ dvpos
,
11136 bottom_vpos
, delta
, delta_bytes
);
11138 /* Adjust Y positions. */
11140 shift_glyph_matrix (w
, current_matrix
,
11141 first_unchanged_at_end_vpos
+ dvpos
,
11144 if (first_unchanged_at_end_row
)
11145 first_unchanged_at_end_row
+= dvpos
;
11147 /* If scrolling up, there may be some lines to display at the end of
11149 last_text_row_at_end
= NULL
;
11152 /* Set last_row to the glyph row in the current matrix where the
11153 window end line is found. It has been moved up or down in
11154 the matrix by dvpos. */
11155 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11156 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11158 /* If last_row is the window end line, it should display text. */
11159 xassert (last_row
->displays_text_p
);
11161 /* If window end line was partially visible before, begin
11162 displaying at that line. Otherwise begin displaying with the
11163 line following it. */
11164 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11166 init_to_row_start (&it
, w
, last_row
);
11167 it
.vpos
= last_vpos
;
11168 it
.current_y
= last_row
->y
;
11172 init_to_row_end (&it
, w
, last_row
);
11173 it
.vpos
= 1 + last_vpos
;
11174 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11178 /* We may start in a continuation line. If so, we have to get
11179 the right continuation_lines_width and current_x. */
11180 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11181 it
.hpos
= it
.current_x
= 0;
11183 /* Display the rest of the lines at the window end. */
11184 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11185 while (it
.current_y
< it
.last_visible_y
11186 && !fonts_changed_p
)
11188 /* Is it always sure that the display agrees with lines in
11189 the current matrix? I don't think so, so we mark rows
11190 displayed invalid in the current matrix by setting their
11191 enabled_p flag to zero. */
11192 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11193 if (display_line (&it
))
11194 last_text_row_at_end
= it
.glyph_row
- 1;
11198 /* Update window_end_pos and window_end_vpos. */
11199 if (first_unchanged_at_end_row
11200 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11201 && !last_text_row_at_end
)
11203 /* Window end line if one of the preserved rows from the current
11204 matrix. Set row to the last row displaying text in current
11205 matrix starting at first_unchanged_at_end_row, after
11207 xassert (first_unchanged_at_end_row
->displays_text_p
);
11208 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11209 first_unchanged_at_end_row
);
11210 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11212 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
11213 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11214 XSETFASTINT (w
->window_end_vpos
,
11215 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11217 else if (last_text_row_at_end
)
11219 XSETFASTINT (w
->window_end_pos
,
11220 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11221 w
->window_end_bytepos
11222 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11223 XSETFASTINT (w
->window_end_vpos
,
11224 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11226 else if (last_text_row
)
11228 /* We have displayed either to the end of the window or at the
11229 end of the window, i.e. the last row with text is to be found
11230 in the desired matrix. */
11231 XSETFASTINT (w
->window_end_pos
,
11232 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11233 w
->window_end_bytepos
11234 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11235 XSETFASTINT (w
->window_end_vpos
,
11236 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11238 else if (first_unchanged_at_end_row
== NULL
11239 && last_text_row
== NULL
11240 && last_text_row_at_end
== NULL
)
11242 /* Displayed to end of window, but no line containing text was
11243 displayed. Lines were deleted at the end of the window. */
11245 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11247 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
11248 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11249 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
11250 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11251 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
11254 w
->window_end_vpos
= make_number (vpos
);
11259 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11260 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11262 /* Record that display has not been completed. */
11263 w
->window_end_valid
= Qnil
;
11264 w
->desired_matrix
->no_scrolling_p
= 1;
11270 /***********************************************************************
11271 More debugging support
11272 ***********************************************************************/
11276 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11277 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11280 /* Dump the contents of glyph matrix MATRIX on stderr. If
11281 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
11284 dump_glyph_matrix (matrix
, with_glyphs_p
)
11285 struct glyph_matrix
*matrix
;
11289 for (i
= 0; i
< matrix
->nrows
; ++i
)
11290 dump_glyph_row (matrix
, i
, with_glyphs_p
);
11294 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11295 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
11298 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
11299 struct glyph_matrix
*matrix
;
11300 int vpos
, with_glyphs_p
;
11302 struct glyph_row
*row
;
11304 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11307 row
= MATRIX_ROW (matrix
, vpos
);
11309 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFes X Y W H V A P\n");
11310 fprintf (stderr
, "=======================================================================\n");
11312 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11313 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11314 row
- matrix
->rows
,
11315 MATRIX_ROW_START_CHARPOS (row
),
11316 MATRIX_ROW_END_CHARPOS (row
),
11317 row
->used
[TEXT_AREA
],
11318 row
->contains_overlapping_glyphs_p
,
11321 row
->truncated_on_left_p
,
11322 row
->truncated_on_right_p
,
11323 row
->overlay_arrow_p
,
11325 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11326 row
->displays_text_p
,
11329 row
->ends_in_middle_of_char_p
,
11330 row
->starts_in_middle_of_char_p
,
11335 row
->visible_height
,
11338 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
11339 row
->end
.overlay_string_index
);
11340 fprintf (stderr
, "%9d %5d\n",
11341 CHARPOS (row
->start
.string_pos
),
11342 CHARPOS (row
->end
.string_pos
));
11343 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11344 row
->end
.dpvec_index
);
11348 struct glyph
*glyph
, *glyph_end
;
11349 int prev_had_glyphs_p
;
11351 glyph
= row
->glyphs
[TEXT_AREA
];
11352 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
11354 /* Glyph for a line end in text. */
11355 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
11358 if (glyph
< glyph_end
)
11360 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11361 prev_had_glyphs_p
= 1;
11364 prev_had_glyphs_p
= 0;
11366 while (glyph
< glyph_end
)
11368 if (glyph
->type
== CHAR_GLYPH
)
11371 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11372 glyph
- row
->glyphs
[TEXT_AREA
],
11375 (BUFFERP (glyph
->object
)
11377 : (STRINGP (glyph
->object
)
11380 glyph
->pixel_width
,
11382 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11386 glyph
->left_box_line_p
,
11387 glyph
->right_box_line_p
);
11389 else if (glyph
->type
== STRETCH_GLYPH
)
11392 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11393 glyph
- row
->glyphs
[TEXT_AREA
],
11396 (BUFFERP (glyph
->object
)
11398 : (STRINGP (glyph
->object
)
11401 glyph
->pixel_width
,
11405 glyph
->left_box_line_p
,
11406 glyph
->right_box_line_p
);
11408 else if (glyph
->type
== IMAGE_GLYPH
)
11411 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11412 glyph
- row
->glyphs
[TEXT_AREA
],
11415 (BUFFERP (glyph
->object
)
11417 : (STRINGP (glyph
->object
)
11420 glyph
->pixel_width
,
11424 glyph
->left_box_line_p
,
11425 glyph
->right_box_line_p
);
11433 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11434 Sdump_glyph_matrix
, 0, 1, "p",
11435 "Dump the current matrix of the selected window to stderr.\n\
11436 Shows contents of glyph row structures. With non-nil optional\n\
11437 parameter WITH-GLYPHS-P, dump glyphs as well.")
11439 Lisp_Object with_glyphs_p
;
11441 struct window
*w
= XWINDOW (selected_window
);
11442 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11444 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11445 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11446 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11447 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11448 fprintf (stderr
, "=============================================\n");
11449 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
11454 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
11455 "Dump glyph row ROW to stderr.")
11459 CHECK_NUMBER (row
, 0);
11460 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
11465 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
11469 struct frame
*sf
= SELECTED_FRAME ();
11470 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
11472 dump_glyph_row (m
, 0, 1);
11477 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11478 Strace_redisplay_toggle
, 0, 0, "",
11479 "Toggle tracing of redisplay.")
11482 trace_redisplay_p
= !trace_redisplay_p
;
11487 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11488 "Print STRING to stderr.")
11490 Lisp_Object string
;
11492 CHECK_STRING (string
, 0);
11493 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11497 #endif /* GLYPH_DEBUG */
11501 /***********************************************************************
11502 Building Desired Matrix Rows
11503 ***********************************************************************/
11505 /* Return a temporary glyph row holding the glyphs of an overlay
11506 arrow. Only used for non-window-redisplay windows. */
11508 static struct glyph_row
*
11509 get_overlay_arrow_glyph_row (w
)
11512 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11513 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11514 struct buffer
*old
= current_buffer
;
11515 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11516 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11517 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11521 int n_glyphs_before
;
11523 set_buffer_temp (buffer
);
11524 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11525 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11526 SET_TEXT_POS (it
.position
, 0, 0);
11528 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11530 while (p
< arrow_end
)
11532 Lisp_Object face
, ilisp
;
11534 /* Get the next character. */
11536 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11538 it
.c
= *p
, it
.len
= 1;
11541 /* Get its face. */
11542 XSETFASTINT (ilisp
, p
- arrow_string
);
11543 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11544 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11546 /* Compute its width, get its glyphs. */
11547 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11548 SET_TEXT_POS (it
.position
, -1, -1);
11549 PRODUCE_GLYPHS (&it
);
11551 /* If this character doesn't fit any more in the line, we have
11552 to remove some glyphs. */
11553 if (it
.current_x
> it
.last_visible_x
)
11555 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11560 set_buffer_temp (old
);
11561 return it
.glyph_row
;
11565 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11566 glyphs are only inserted for terminal frames since we can't really
11567 win with truncation glyphs when partially visible glyphs are
11568 involved. Which glyphs to insert is determined by
11569 produce_special_glyphs. */
11572 insert_left_trunc_glyphs (it
)
11575 struct it truncate_it
;
11576 struct glyph
*from
, *end
, *to
, *toend
;
11578 xassert (!FRAME_WINDOW_P (it
->f
));
11580 /* Get the truncation glyphs. */
11582 truncate_it
.current_x
= 0;
11583 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11584 truncate_it
.glyph_row
= &scratch_glyph_row
;
11585 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11586 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11587 truncate_it
.object
= make_number (0);
11588 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
11590 /* Overwrite glyphs from IT with truncation glyphs. */
11591 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11592 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
11593 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
11594 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
11599 /* There may be padding glyphs left over. Remove them. */
11601 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
11603 while (from
< toend
)
11606 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
11610 /* Compute the pixel height and width of IT->glyph_row.
11612 Most of the time, ascent and height of a display line will be equal
11613 to the max_ascent and max_height values of the display iterator
11614 structure. This is not the case if
11616 1. We hit ZV without displaying anything. In this case, max_ascent
11617 and max_height will be zero.
11619 2. We have some glyphs that don't contribute to the line height.
11620 (The glyph row flag contributes_to_line_height_p is for future
11621 pixmap extensions).
11623 The first case is easily covered by using default values because in
11624 these cases, the line height does not really matter, except that it
11625 must not be zero. */
11628 compute_line_metrics (it
)
11631 struct glyph_row
*row
= it
->glyph_row
;
11634 if (FRAME_WINDOW_P (it
->f
))
11636 int i
, header_line_height
;
11638 /* The line may consist of one space only, that was added to
11639 place the cursor on it. If so, the row's height hasn't been
11641 if (row
->height
== 0)
11643 if (it
->max_ascent
+ it
->max_descent
== 0)
11644 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
11645 row
->ascent
= it
->max_ascent
;
11646 row
->height
= it
->max_ascent
+ it
->max_descent
;
11647 row
->phys_ascent
= it
->max_phys_ascent
;
11648 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11651 /* Compute the width of this line. */
11652 row
->pixel_width
= row
->x
;
11653 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
11654 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11656 xassert (row
->pixel_width
>= 0);
11657 xassert (row
->ascent
>= 0 && row
->height
> 0);
11659 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
11660 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
11662 /* If first line's physical ascent is larger than its logical
11663 ascent, use the physical ascent, and make the row taller.
11664 This makes accented characters fully visible. */
11665 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
11666 && row
->phys_ascent
> row
->ascent
)
11668 row
->height
+= row
->phys_ascent
- row
->ascent
;
11669 row
->ascent
= row
->phys_ascent
;
11672 /* Compute how much of the line is visible. */
11673 row
->visible_height
= row
->height
;
11675 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
11676 if (row
->y
< header_line_height
)
11677 row
->visible_height
-= header_line_height
- row
->y
;
11680 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
11681 if (row
->y
+ row
->height
> max_y
)
11682 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11687 row
->pixel_width
= row
->used
[TEXT_AREA
];
11688 row
->ascent
= row
->phys_ascent
= 0;
11689 row
->height
= row
->phys_height
= row
->visible_height
= 1;
11692 /* Compute a hash code for this row. */
11694 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11695 for (i
= 0; i
< row
->used
[area
]; ++i
)
11696 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
11697 + row
->glyphs
[area
][i
].u
.val
11698 + row
->glyphs
[area
][i
].face_id
11699 + row
->glyphs
[area
][i
].padding_p
11700 + (row
->glyphs
[area
][i
].type
<< 2));
11702 it
->max_ascent
= it
->max_descent
= 0;
11703 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
11707 /* Append one space to the glyph row of iterator IT if doing a
11708 window-based redisplay. DEFAULT_FACE_P non-zero means let the
11709 space have the default face, otherwise let it have the same face as
11710 IT->face_id. Value is non-zero if a space was added.
11712 This function is called to make sure that there is always one glyph
11713 at the end of a glyph row that the cursor can be set on under
11714 window-systems. (If there weren't such a glyph we would not know
11715 how wide and tall a box cursor should be displayed).
11717 At the same time this space let's a nicely handle clearing to the
11718 end of the line if the row ends in italic text. */
11721 append_space (it
, default_face_p
)
11723 int default_face_p
;
11725 if (FRAME_WINDOW_P (it
->f
))
11727 int n
= it
->glyph_row
->used
[TEXT_AREA
];
11729 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
11730 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
11732 /* Save some values that must not be changed.
11733 Must save IT->c and IT->len because otherwise
11734 ITERATOR_AT_END_P wouldn't work anymore after
11735 append_space has been called. */
11736 int saved_what
= it
->what
;
11737 int saved_c
= it
->c
, saved_len
= it
->len
;
11738 int saved_x
= it
->current_x
;
11739 int saved_face_id
= it
->face_id
;
11740 struct text_pos saved_pos
;
11741 Lisp_Object saved_object
;
11744 saved_object
= it
->object
;
11745 saved_pos
= it
->position
;
11747 it
->what
= IT_CHARACTER
;
11748 bzero (&it
->position
, sizeof it
->position
);
11749 it
->object
= make_number (0);
11753 if (default_face_p
)
11754 it
->face_id
= DEFAULT_FACE_ID
;
11755 else if (it
->face_before_selective_p
)
11756 it
->face_id
= it
->saved_face_id
;
11757 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11758 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11760 PRODUCE_GLYPHS (it
);
11762 it
->current_x
= saved_x
;
11763 it
->object
= saved_object
;
11764 it
->position
= saved_pos
;
11765 it
->what
= saved_what
;
11766 it
->face_id
= saved_face_id
;
11767 it
->len
= saved_len
;
11777 /* Extend the face of the last glyph in the text area of IT->glyph_row
11778 to the end of the display line. Called from display_line.
11779 If the glyph row is empty, add a space glyph to it so that we
11780 know the face to draw. Set the glyph row flag fill_line_p. */
11783 extend_face_to_end_of_line (it
)
11787 struct frame
*f
= it
->f
;
11789 /* If line is already filled, do nothing. */
11790 if (it
->current_x
>= it
->last_visible_x
)
11793 /* Face extension extends the background and box of IT->face_id
11794 to the end of the line. If the background equals the background
11795 of the frame, we don't have to do anything. */
11796 if (it
->face_before_selective_p
)
11797 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
11799 face
= FACE_FROM_ID (f
, it
->face_id
);
11801 if (FRAME_WINDOW_P (f
)
11802 && face
->box
== FACE_NO_BOX
11803 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11807 /* Set the glyph row flag indicating that the face of the last glyph
11808 in the text area has to be drawn to the end of the text area. */
11809 it
->glyph_row
->fill_line_p
= 1;
11811 /* If current character of IT is not ASCII, make sure we have the
11812 ASCII face. This will be automatically undone the next time
11813 get_next_display_element returns a multibyte character. Note
11814 that the character will always be single byte in unibyte text. */
11815 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11817 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11820 if (FRAME_WINDOW_P (f
))
11822 /* If the row is empty, add a space with the current face of IT,
11823 so that we know which face to draw. */
11824 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11826 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11827 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11828 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11833 /* Save some values that must not be changed. */
11834 int saved_x
= it
->current_x
;
11835 struct text_pos saved_pos
;
11836 Lisp_Object saved_object
;
11837 int saved_what
= it
->what
;
11838 int saved_face_id
= it
->face_id
;
11840 saved_object
= it
->object
;
11841 saved_pos
= it
->position
;
11843 it
->what
= IT_CHARACTER
;
11844 bzero (&it
->position
, sizeof it
->position
);
11845 it
->object
= make_number (0);
11848 it
->face_id
= face
->id
;
11850 PRODUCE_GLYPHS (it
);
11852 while (it
->current_x
<= it
->last_visible_x
)
11853 PRODUCE_GLYPHS (it
);
11855 /* Don't count these blanks really. It would let us insert a left
11856 truncation glyph below and make us set the cursor on them, maybe. */
11857 it
->current_x
= saved_x
;
11858 it
->object
= saved_object
;
11859 it
->position
= saved_pos
;
11860 it
->what
= saved_what
;
11861 it
->face_id
= saved_face_id
;
11866 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11867 trailing whitespace. */
11870 trailing_whitespace_p (charpos
)
11873 int bytepos
= CHAR_TO_BYTE (charpos
);
11876 while (bytepos
< ZV_BYTE
11877 && (c
= FETCH_CHAR (bytepos
),
11878 c
== ' ' || c
== '\t'))
11881 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11883 if (bytepos
!= PT_BYTE
)
11890 /* Highlight trailing whitespace, if any, in ROW. */
11893 highlight_trailing_whitespace (f
, row
)
11895 struct glyph_row
*row
;
11897 int used
= row
->used
[TEXT_AREA
];
11901 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11902 struct glyph
*glyph
= start
+ used
- 1;
11904 /* Skip over the space glyph inserted to display the
11905 cursor at the end of a line. */
11906 if (glyph
->type
== CHAR_GLYPH
11907 && glyph
->u
.ch
== ' '
11908 && INTEGERP (glyph
->object
))
11911 /* If last glyph is a space or stretch, and it's trailing
11912 whitespace, set the face of all trailing whitespace glyphs in
11913 IT->glyph_row to `trailing-whitespace'. */
11915 && BUFFERP (glyph
->object
)
11916 && (glyph
->type
== STRETCH_GLYPH
11917 || (glyph
->type
== CHAR_GLYPH
11918 && glyph
->u
.ch
== ' '))
11919 && trailing_whitespace_p (glyph
->charpos
))
11921 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11923 while (glyph
>= start
11924 && BUFFERP (glyph
->object
)
11925 && (glyph
->type
== STRETCH_GLYPH
11926 || (glyph
->type
== CHAR_GLYPH
11927 && glyph
->u
.ch
== ' ')))
11928 (glyph
--)->face_id
= face_id
;
11934 /* Value is non-zero if glyph row ROW in window W should be
11935 used to hold the cursor. */
11938 cursor_row_p (w
, row
)
11940 struct glyph_row
*row
;
11942 int cursor_row_p
= 1;
11944 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
11946 /* If the row ends with a newline from a string, we don't want
11947 the cursor there (if the row is continued it doesn't end in a
11949 if (CHARPOS (row
->end
.string_pos
) >= 0
11950 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11951 cursor_row_p
= row
->continued_p
;
11953 /* If the row ends at ZV, display the cursor at the end of that
11954 row instead of at the start of the row below. */
11955 else if (row
->ends_at_zv_p
)
11961 return cursor_row_p
;
11965 /* Construct the glyph row IT->glyph_row in the desired matrix of
11966 IT->w from text at the current position of IT. See dispextern.h
11967 for an overview of struct it. Value is non-zero if
11968 IT->glyph_row displays text, as opposed to a line displaying ZV
11975 struct glyph_row
*row
= it
->glyph_row
;
11977 /* We always start displaying at hpos zero even if hscrolled. */
11978 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11980 /* We must not display in a row that's not a text row. */
11981 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11982 < it
->w
->desired_matrix
->nrows
);
11984 /* Is IT->w showing the region? */
11985 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11987 /* Clear the result glyph row and enable it. */
11988 prepare_desired_row (row
);
11990 row
->y
= it
->current_y
;
11991 row
->start
= it
->current
;
11992 row
->continuation_lines_width
= it
->continuation_lines_width
;
11993 row
->displays_text_p
= 1;
11994 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
11995 it
->starts_in_middle_of_char_p
= 0;
11997 /* Arrange the overlays nicely for our purposes. Usually, we call
11998 display_line on only one line at a time, in which case this
11999 can't really hurt too much, or we call it on lines which appear
12000 one after another in the buffer, in which case all calls to
12001 recenter_overlay_lists but the first will be pretty cheap. */
12002 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
12004 /* Move over display elements that are not visible because we are
12005 hscrolled. This may stop at an x-position < IT->first_visible_x
12006 if the first glyph is partially visible or if we hit a line end. */
12007 if (it
->current_x
< it
->first_visible_x
)
12008 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
12009 MOVE_TO_POS
| MOVE_TO_X
);
12011 /* Get the initial row height. This is either the height of the
12012 text hscrolled, if there is any, or zero. */
12013 row
->ascent
= it
->max_ascent
;
12014 row
->height
= it
->max_ascent
+ it
->max_descent
;
12015 row
->phys_ascent
= it
->max_phys_ascent
;
12016 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12018 /* Loop generating characters. The loop is left with IT on the next
12019 character to display. */
12022 int n_glyphs_before
, hpos_before
, x_before
;
12024 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
12026 /* Retrieve the next thing to display. Value is zero if end of
12028 if (!get_next_display_element (it
))
12030 /* Maybe add a space at the end of this line that is used to
12031 display the cursor there under X. Set the charpos of the
12032 first glyph of blank lines not corresponding to any text
12034 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
12035 || row
->used
[TEXT_AREA
] == 0)
12037 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
12038 row
->displays_text_p
= 0;
12040 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
12041 row
->indicate_empty_line_p
= 1;
12044 it
->continuation_lines_width
= 0;
12045 row
->ends_at_zv_p
= 1;
12049 /* Now, get the metrics of what we want to display. This also
12050 generates glyphs in `row' (which is IT->glyph_row). */
12051 n_glyphs_before
= row
->used
[TEXT_AREA
];
12054 /* Remember the line height so far in case the next element doesn't
12055 fit on the line. */
12056 if (!it
->truncate_lines_p
)
12058 ascent
= it
->max_ascent
;
12059 descent
= it
->max_descent
;
12060 phys_ascent
= it
->max_phys_ascent
;
12061 phys_descent
= it
->max_phys_descent
;
12064 PRODUCE_GLYPHS (it
);
12066 /* If this display element was in marginal areas, continue with
12068 if (it
->area
!= TEXT_AREA
)
12070 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12071 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12072 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12073 row
->phys_height
= max (row
->phys_height
,
12074 it
->max_phys_ascent
+ it
->max_phys_descent
);
12075 set_iterator_to_next (it
, 1);
12079 /* Does the display element fit on the line? If we truncate
12080 lines, we should draw past the right edge of the window. If
12081 we don't truncate, we want to stop so that we can display the
12082 continuation glyph before the right margin. If lines are
12083 continued, there are two possible strategies for characters
12084 resulting in more than 1 glyph (e.g. tabs): Display as many
12085 glyphs as possible in this line and leave the rest for the
12086 continuation line, or display the whole element in the next
12087 line. Original redisplay did the former, so we do it also. */
12088 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12089 hpos_before
= it
->hpos
;
12093 && it
->current_x
< it
->last_visible_x
)
12096 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12097 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12098 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12099 row
->phys_height
= max (row
->phys_height
,
12100 it
->max_phys_ascent
+ it
->max_phys_descent
);
12101 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
12102 row
->x
= x
- it
->first_visible_x
;
12107 struct glyph
*glyph
;
12109 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
12111 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12112 new_x
= x
+ glyph
->pixel_width
;
12114 if (/* Lines are continued. */
12115 !it
->truncate_lines_p
12116 && (/* Glyph doesn't fit on the line. */
12117 new_x
> it
->last_visible_x
12118 /* Or it fits exactly on a window system frame. */
12119 || (new_x
== it
->last_visible_x
12120 && FRAME_WINDOW_P (it
->f
))))
12122 /* End of a continued line. */
12125 || (new_x
== it
->last_visible_x
12126 && FRAME_WINDOW_P (it
->f
)))
12128 /* Current glyph is the only one on the line or
12129 fits exactly on the line. We must continue
12130 the line because we can't draw the cursor
12131 after the glyph. */
12132 row
->continued_p
= 1;
12133 it
->current_x
= new_x
;
12134 it
->continuation_lines_width
+= new_x
;
12136 if (i
== nglyphs
- 1)
12137 set_iterator_to_next (it
, 1);
12139 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12140 && !FRAME_WINDOW_P (it
->f
))
12142 /* A padding glyph that doesn't fit on this line.
12143 This means the whole character doesn't fit
12145 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12147 /* Fill the rest of the row with continuation
12148 glyphs like in 20.x. */
12149 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12150 < row
->glyphs
[1 + TEXT_AREA
])
12151 produce_special_glyphs (it
, IT_CONTINUATION
);
12153 row
->continued_p
= 1;
12154 it
->current_x
= x_before
;
12155 it
->continuation_lines_width
+= x_before
;
12157 /* Restore the height to what it was before the
12158 element not fitting on the line. */
12159 it
->max_ascent
= ascent
;
12160 it
->max_descent
= descent
;
12161 it
->max_phys_ascent
= phys_ascent
;
12162 it
->max_phys_descent
= phys_descent
;
12166 /* Display element draws past the right edge of
12167 the window. Restore positions to values
12168 before the element. The next line starts
12169 with current_x before the glyph that could
12170 not be displayed, so that TAB works right. */
12171 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12173 /* Display continuation glyphs. */
12174 if (!FRAME_WINDOW_P (it
->f
))
12175 produce_special_glyphs (it
, IT_CONTINUATION
);
12176 row
->continued_p
= 1;
12179 it
->continuation_lines_width
+= x
;
12180 if (nglyphs
> 1 && i
> 0)
12182 row
->ends_in_middle_of_char_p
= 1;
12183 it
->starts_in_middle_of_char_p
= 1;
12186 /* Restore the height to what it was before the
12187 element not fitting on the line. */
12188 it
->max_ascent
= ascent
;
12189 it
->max_descent
= descent
;
12190 it
->max_phys_ascent
= phys_ascent
;
12191 it
->max_phys_descent
= phys_descent
;
12196 else if (new_x
> it
->first_visible_x
)
12198 /* Increment number of glyphs actually displayed. */
12201 if (x
< it
->first_visible_x
)
12202 /* Glyph is partially visible, i.e. row starts at
12203 negative X position. */
12204 row
->x
= x
- it
->first_visible_x
;
12208 /* Glyph is completely off the left margin of the
12209 window. This should not happen because of the
12210 move_it_in_display_line at the start of
12216 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12217 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12218 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12219 row
->phys_height
= max (row
->phys_height
,
12220 it
->max_phys_ascent
+ it
->max_phys_descent
);
12222 /* End of this display line if row is continued. */
12223 if (row
->continued_p
)
12227 /* Is this a line end? If yes, we're also done, after making
12228 sure that a non-default face is extended up to the right
12229 margin of the window. */
12230 if (ITERATOR_AT_END_OF_LINE_P (it
))
12232 int used_before
= row
->used
[TEXT_AREA
];
12234 /* Add a space at the end of the line that is used to
12235 display the cursor there. */
12236 append_space (it
, 0);
12238 /* Extend the face to the end of the line. */
12239 extend_face_to_end_of_line (it
);
12241 /* Make sure we have the position. */
12242 if (used_before
== 0)
12243 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12245 /* Consume the line end. This skips over invisible lines. */
12246 set_iterator_to_next (it
, 1);
12247 it
->continuation_lines_width
= 0;
12251 /* Proceed with next display element. Note that this skips
12252 over lines invisible because of selective display. */
12253 set_iterator_to_next (it
, 1);
12255 /* If we truncate lines, we are done when the last displayed
12256 glyphs reach past the right margin of the window. */
12257 if (it
->truncate_lines_p
12258 && (FRAME_WINDOW_P (it
->f
)
12259 ? (it
->current_x
>= it
->last_visible_x
)
12260 : (it
->current_x
> it
->last_visible_x
)))
12262 /* Maybe add truncation glyphs. */
12263 if (!FRAME_WINDOW_P (it
->f
))
12265 --it
->glyph_row
->used
[TEXT_AREA
];
12266 produce_special_glyphs (it
, IT_TRUNCATION
);
12269 row
->truncated_on_right_p
= 1;
12270 it
->continuation_lines_width
= 0;
12271 reseat_at_next_visible_line_start (it
, 0);
12272 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12273 it
->hpos
= hpos_before
;
12274 it
->current_x
= x_before
;
12279 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12280 at the left window margin. */
12281 if (it
->first_visible_x
12282 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12284 if (!FRAME_WINDOW_P (it
->f
))
12285 insert_left_trunc_glyphs (it
);
12286 row
->truncated_on_left_p
= 1;
12289 /* If the start of this line is the overlay arrow-position, then
12290 mark this glyph row as the one containing the overlay arrow.
12291 This is clearly a mess with variable size fonts. It would be
12292 better to let it be displayed like cursors under X. */
12293 if (MARKERP (Voverlay_arrow_position
)
12294 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12295 && (MATRIX_ROW_START_CHARPOS (row
)
12296 == marker_position (Voverlay_arrow_position
))
12297 && STRINGP (Voverlay_arrow_string
)
12298 && ! overlay_arrow_seen
)
12300 /* Overlay arrow in window redisplay is a bitmap. */
12301 if (!FRAME_WINDOW_P (it
->f
))
12303 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12304 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12305 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12306 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12307 struct glyph
*p2
, *end
;
12309 /* Copy the arrow glyphs. */
12310 while (glyph
< arrow_end
)
12313 /* Throw away padding glyphs. */
12315 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12316 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12322 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12326 overlay_arrow_seen
= 1;
12327 row
->overlay_arrow_p
= 1;
12330 /* Compute pixel dimensions of this line. */
12331 compute_line_metrics (it
);
12333 /* Remember the position at which this line ends. */
12334 row
->end
= it
->current
;
12336 /* Maybe set the cursor. */
12337 if (it
->w
->cursor
.vpos
< 0
12338 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12339 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12340 && cursor_row_p (it
->w
, row
))
12341 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12343 /* Highlight trailing whitespace. */
12344 if (!NILP (Vshow_trailing_whitespace
))
12345 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12347 /* Prepare for the next line. This line starts horizontally at (X
12348 HPOS) = (0 0). Vertical positions are incremented. As a
12349 convenience for the caller, IT->glyph_row is set to the next
12351 it
->current_x
= it
->hpos
= 0;
12352 it
->current_y
+= row
->height
;
12355 return row
->displays_text_p
;
12360 /***********************************************************************
12362 ***********************************************************************/
12364 /* Redisplay the menu bar in the frame for window W.
12366 The menu bar of X frames that don't have X toolkit support is
12367 displayed in a special window W->frame->menu_bar_window.
12369 The menu bar of terminal frames is treated specially as far as
12370 glyph matrices are concerned. Menu bar lines are not part of
12371 windows, so the update is done directly on the frame matrix rows
12372 for the menu bar. */
12375 display_menu_bar (w
)
12378 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12383 /* Don't do all this for graphical frames. */
12385 if (!NILP (Vwindow_system
))
12388 #ifdef USE_X_TOOLKIT
12393 if (FRAME_MAC_P (f
))
12397 #ifdef USE_X_TOOLKIT
12398 xassert (!FRAME_WINDOW_P (f
));
12399 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12400 it
.first_visible_x
= 0;
12401 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12402 #else /* not USE_X_TOOLKIT */
12403 if (FRAME_WINDOW_P (f
))
12405 /* Menu bar lines are displayed in the desired matrix of the
12406 dummy window menu_bar_window. */
12407 struct window
*menu_w
;
12408 xassert (WINDOWP (f
->menu_bar_window
));
12409 menu_w
= XWINDOW (f
->menu_bar_window
);
12410 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12412 it
.first_visible_x
= 0;
12413 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12417 /* This is a TTY frame, i.e. character hpos/vpos are used as
12419 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12421 it
.first_visible_x
= 0;
12422 it
.last_visible_x
= FRAME_WIDTH (f
);
12424 #endif /* not USE_X_TOOLKIT */
12426 if (! mode_line_inverse_video
)
12427 /* Force the menu-bar to be displayed in the default face. */
12428 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
12430 /* Clear all rows of the menu bar. */
12431 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12433 struct glyph_row
*row
= it
.glyph_row
+ i
;
12434 clear_glyph_row (row
);
12435 row
->enabled_p
= 1;
12436 row
->full_width_p
= 1;
12439 /* Display all items of the menu bar. */
12440 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12441 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12443 Lisp_Object string
;
12445 /* Stop at nil string. */
12446 string
= XVECTOR (items
)->contents
[i
+ 1];
12450 /* Remember where item was displayed. */
12451 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
12453 /* Display the item, pad with one space. */
12454 if (it
.current_x
< it
.last_visible_x
)
12455 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12456 XSTRING (string
)->size
+ 1, 0, 0, -1);
12459 /* Fill out the line with spaces. */
12460 if (it
.current_x
< it
.last_visible_x
)
12461 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12463 /* Compute the total height of the lines. */
12464 compute_line_metrics (&it
);
12469 /***********************************************************************
12471 ***********************************************************************/
12473 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12474 FORCE is non-zero, redisplay mode lines unconditionally.
12475 Otherwise, redisplay only mode lines that are garbaged. Value is
12476 the number of windows whose mode lines were redisplayed. */
12479 redisplay_mode_lines (window
, force
)
12480 Lisp_Object window
;
12485 while (!NILP (window
))
12487 struct window
*w
= XWINDOW (window
);
12489 if (WINDOWP (w
->hchild
))
12490 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12491 else if (WINDOWP (w
->vchild
))
12492 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12494 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12495 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12497 Lisp_Object old_selected_frame
;
12498 struct text_pos lpoint
;
12499 struct buffer
*old
= current_buffer
;
12501 /* Set the window's buffer for the mode line display. */
12502 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12503 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12505 /* Point refers normally to the selected window. For any
12506 other window, set up appropriate value. */
12507 if (!EQ (window
, selected_window
))
12509 struct text_pos pt
;
12511 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12512 if (CHARPOS (pt
) < BEGV
)
12513 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12514 else if (CHARPOS (pt
) > (ZV
- 1))
12515 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12517 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12520 /* Temporarily set up the selected frame. */
12521 old_selected_frame
= selected_frame
;
12522 selected_frame
= w
->frame
;
12524 /* Display mode lines. */
12525 clear_glyph_matrix (w
->desired_matrix
);
12526 if (display_mode_lines (w
))
12529 w
->must_be_updated_p
= 1;
12532 /* Restore old settings. */
12533 selected_frame
= old_selected_frame
;
12534 set_buffer_internal_1 (old
);
12535 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12545 /* Display the mode and/or top line of window W. Value is the number
12546 of mode lines displayed. */
12549 display_mode_lines (w
)
12554 /* These will be set while the mode line specs are processed. */
12555 line_number_displayed
= 0;
12556 w
->column_number_displayed
= Qnil
;
12558 if (WINDOW_WANTS_MODELINE_P (w
))
12560 display_mode_line (w
, MODE_LINE_FACE_ID
,
12561 current_buffer
->mode_line_format
);
12565 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12567 display_mode_line (w
, HEADER_LINE_FACE_ID
,
12568 current_buffer
->header_line_format
);
12576 /* Display mode or top line of window W. FACE_ID specifies which line
12577 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
12578 FORMAT is the mode line format to display. Value is the pixel
12579 height of the mode line displayed. */
12582 display_mode_line (w
, face_id
, format
)
12584 enum face_id face_id
;
12585 Lisp_Object format
;
12590 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
12591 prepare_desired_row (it
.glyph_row
);
12593 if (! mode_line_inverse_video
)
12594 /* Force the mode-line to be displayed in the default face. */
12595 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
12597 /* Temporarily make frame's keyboard the current kboard so that
12598 kboard-local variables in the mode_line_format will get the right
12600 push_frame_kboard (it
.f
);
12601 display_mode_element (&it
, 0, 0, 0, format
);
12602 pop_frame_kboard ();
12604 /* Fill up with spaces. */
12605 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
12607 compute_line_metrics (&it
);
12608 it
.glyph_row
->full_width_p
= 1;
12609 it
.glyph_row
->mode_line_p
= 1;
12610 it
.glyph_row
->inverse_p
= 0;
12611 it
.glyph_row
->continued_p
= 0;
12612 it
.glyph_row
->truncated_on_left_p
= 0;
12613 it
.glyph_row
->truncated_on_right_p
= 0;
12615 /* Make a 3D mode-line have a shadow at its right end. */
12616 face
= FACE_FROM_ID (it
.f
, face_id
);
12617 extend_face_to_end_of_line (&it
);
12618 if (face
->box
!= FACE_NO_BOX
)
12620 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
12621 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
12622 last
->right_box_line_p
= 1;
12625 return it
.glyph_row
->height
;
12629 /* Contribute ELT to the mode line for window IT->w. How it
12630 translates into text depends on its data type.
12632 IT describes the display environment in which we display, as usual.
12634 DEPTH is the depth in recursion. It is used to prevent
12635 infinite recursion here.
12637 FIELD_WIDTH is the number of characters the display of ELT should
12638 occupy in the mode line, and PRECISION is the maximum number of
12639 characters to display from ELT's representation. See
12640 display_string for details. *
12642 Returns the hpos of the end of the text generated by ELT. */
12645 display_mode_element (it
, depth
, field_width
, precision
, elt
)
12648 int field_width
, precision
;
12651 int n
= 0, field
, prec
;
12659 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
12663 /* A string: output it and check for %-constructs within it. */
12665 unsigned char *this = XSTRING (elt
)->data
;
12666 unsigned char *lisp_string
= this;
12668 while ((precision
<= 0 || n
< precision
)
12670 && (frame_title_ptr
12671 || it
->current_x
< it
->last_visible_x
))
12673 unsigned char *last
= this;
12675 /* Advance to end of string or next format specifier. */
12676 while ((c
= *this++) != '\0' && c
!= '%')
12679 if (this - 1 != last
)
12681 /* Output to end of string or up to '%'. Field width
12682 is length of string. Don't output more than
12683 PRECISION allows us. */
12684 prec
= --this - last
;
12685 if (precision
> 0 && prec
> precision
- n
)
12686 prec
= precision
- n
;
12688 if (frame_title_ptr
)
12689 n
+= store_frame_title (last
, prec
, prec
);
12691 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
12692 it
, 0, prec
, 0, -1);
12694 else /* c == '%' */
12696 unsigned char *percent_position
= this;
12698 /* Get the specified minimum width. Zero means
12701 while ((c
= *this++) >= '0' && c
<= '9')
12702 field
= field
* 10 + c
- '0';
12704 /* Don't pad beyond the total padding allowed. */
12705 if (field_width
- n
> 0 && field
> field_width
- n
)
12706 field
= field_width
- n
;
12708 /* Note that either PRECISION <= 0 or N < PRECISION. */
12709 prec
= precision
- n
;
12712 n
+= display_mode_element (it
, depth
, field
, prec
,
12713 Vglobal_mode_string
);
12716 unsigned char *spec
12717 = decode_mode_spec (it
->w
, c
, field
, prec
);
12719 if (frame_title_ptr
)
12720 n
+= store_frame_title (spec
, field
, prec
);
12724 = it
->glyph_row
->used
[TEXT_AREA
];
12726 = percent_position
- XSTRING (elt
)->data
;
12728 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
12729 field
, prec
, 0, -1);
12731 /* Assign to the glyphs written above the
12732 string where the `%x' came from, position
12736 struct glyph
*glyph
12737 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
12741 for (i
= 0; i
< nwritten
; ++i
)
12743 glyph
[i
].object
= elt
;
12744 glyph
[i
].charpos
= charpos
;
12757 /* A symbol: process the value of the symbol recursively
12758 as if it appeared here directly. Avoid error if symbol void.
12759 Special case: if value of symbol is a string, output the string
12762 register Lisp_Object tem
;
12763 tem
= Fboundp (elt
);
12766 tem
= Fsymbol_value (elt
);
12767 /* If value is a string, output that string literally:
12768 don't check for % within it. */
12771 prec
= XSTRING (tem
)->size
;
12772 if (precision
> 0 && prec
> precision
- n
)
12773 prec
= precision
- n
;
12774 if (frame_title_ptr
)
12775 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
12777 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
12780 else if (!EQ (tem
, elt
))
12782 /* Give up right away for nil or t. */
12792 register Lisp_Object car
, tem
;
12794 /* A cons cell: three distinct cases.
12795 If first element is a string or a cons, process all the elements
12796 and effectively concatenate them.
12797 If first element is a negative number, truncate displaying cdr to
12798 at most that many characters. If positive, pad (with spaces)
12799 to at least that many characters.
12800 If first element is a symbol, process the cadr or caddr recursively
12801 according to whether the symbol's value is non-nil or nil. */
12803 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
12805 /* An element of the form (:eval FORM) means evaluate FORM
12806 and use the result as mode line elements. */
12807 struct gcpro gcpro1
;
12810 spec
= safe_eval (XCAR (XCDR (elt
)));
12812 n
+= display_mode_element (it
, depth
, field_width
- n
,
12813 precision
- n
, spec
);
12816 else if (SYMBOLP (car
))
12818 tem
= Fboundp (car
);
12822 /* elt is now the cdr, and we know it is a cons cell.
12823 Use its car if CAR has a non-nil value. */
12826 tem
= Fsymbol_value (car
);
12833 /* Symbol's value is nil (or symbol is unbound)
12834 Get the cddr of the original list
12835 and if possible find the caddr and use that. */
12839 else if (!CONSP (elt
))
12844 else if (INTEGERP (car
))
12846 register int lim
= XINT (car
);
12850 /* Negative int means reduce maximum width. */
12851 if (precision
<= 0)
12854 precision
= min (precision
, -lim
);
12858 /* Padding specified. Don't let it be more than
12859 current maximum. */
12861 lim
= min (precision
, lim
);
12863 /* If that's more padding than already wanted, queue it.
12864 But don't reduce padding already specified even if
12865 that is beyond the current truncation point. */
12866 field_width
= max (lim
, field_width
);
12870 else if (STRINGP (car
) || CONSP (car
))
12872 register int limit
= 50;
12873 /* Limit is to protect against circular lists. */
12876 && (precision
<= 0 || n
< precision
))
12878 n
+= display_mode_element (it
, depth
, field_width
- n
,
12879 precision
- n
, XCAR (elt
));
12888 if (frame_title_ptr
)
12889 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12891 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12892 precision
- n
, 0, 0);
12896 /* Pad to FIELD_WIDTH. */
12897 if (field_width
> 0 && n
< field_width
)
12899 if (frame_title_ptr
)
12900 n
+= store_frame_title ("", field_width
- n
, 0);
12902 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12910 /* Write a null-terminated, right justified decimal representation of
12911 the positive integer D to BUF using a minimal field width WIDTH. */
12914 pint2str (buf
, width
, d
)
12915 register char *buf
;
12916 register int width
;
12919 register char *p
= buf
;
12927 *p
++ = d
% 10 + '0';
12932 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12943 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12944 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12945 type of CODING_SYSTEM. Return updated pointer into BUF. */
12947 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12950 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12951 Lisp_Object coding_system
;
12952 register char *buf
;
12956 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12957 unsigned char *eol_str
;
12959 /* The EOL conversion we are using. */
12960 Lisp_Object eoltype
;
12962 val
= Fget (coding_system
, Qcoding_system
);
12965 if (!VECTORP (val
)) /* Not yet decided. */
12970 eoltype
= eol_mnemonic_undecided
;
12971 /* Don't mention EOL conversion if it isn't decided. */
12975 Lisp_Object eolvalue
;
12977 eolvalue
= Fget (coding_system
, Qeol_type
);
12980 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12984 /* The EOL conversion that is normal on this system. */
12986 if (NILP (eolvalue
)) /* Not yet decided. */
12987 eoltype
= eol_mnemonic_undecided
;
12988 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12989 eoltype
= eol_mnemonic_undecided
;
12990 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12991 eoltype
= (XFASTINT (eolvalue
) == 0
12992 ? eol_mnemonic_unix
12993 : (XFASTINT (eolvalue
) == 1
12994 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
13000 /* Mention the EOL conversion if it is not the usual one. */
13001 if (STRINGP (eoltype
))
13003 eol_str
= XSTRING (eoltype
)->data
;
13004 eol_str_len
= XSTRING (eoltype
)->size
;
13006 else if (INTEGERP (eoltype
)
13007 && CHAR_VALID_P (XINT (eoltype
), 0))
13009 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
13010 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
13014 eol_str
= invalid_eol_type
;
13015 eol_str_len
= sizeof (invalid_eol_type
) - 1;
13017 bcopy (eol_str
, buf
, eol_str_len
);
13018 buf
+= eol_str_len
;
13024 /* Return a string for the output of a mode line %-spec for window W,
13025 generated by character C. PRECISION >= 0 means don't return a
13026 string longer than that value. FIELD_WIDTH > 0 means pad the
13027 string returned with spaces to that value. */
13029 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
13032 decode_mode_spec (w
, c
, field_width
, precision
)
13035 int field_width
, precision
;
13038 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13039 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
13040 struct buffer
*b
= XBUFFER (w
->buffer
);
13047 if (!NILP (b
->read_only
))
13049 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13054 /* This differs from %* only for a modified read-only buffer. */
13055 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13057 if (!NILP (b
->read_only
))
13062 /* This differs from %* in ignoring read-only-ness. */
13063 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
13075 if (command_loop_level
> 5)
13077 p
= decode_mode_spec_buf
;
13078 for (i
= 0; i
< command_loop_level
; i
++)
13081 return decode_mode_spec_buf
;
13089 if (command_loop_level
> 5)
13091 p
= decode_mode_spec_buf
;
13092 for (i
= 0; i
< command_loop_level
; i
++)
13095 return decode_mode_spec_buf
;
13102 /* Let lots_of_dashes be a string of infinite length. */
13103 if (field_width
<= 0
13104 || field_width
> sizeof (lots_of_dashes
))
13106 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
13107 decode_mode_spec_buf
[i
] = '-';
13108 decode_mode_spec_buf
[i
] = '\0';
13109 return decode_mode_spec_buf
;
13112 return lots_of_dashes
;
13121 int col
= current_column ();
13122 XSETFASTINT (w
->column_number_displayed
, col
);
13123 pint2str (decode_mode_spec_buf
, field_width
, col
);
13124 return decode_mode_spec_buf
;
13128 /* %F displays the frame name. */
13129 if (!NILP (f
->title
))
13130 return (char *) XSTRING (f
->title
)->data
;
13131 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13132 return (char *) XSTRING (f
->name
)->data
;
13141 int startpos
= XMARKER (w
->start
)->charpos
;
13142 int startpos_byte
= marker_byte_position (w
->start
);
13143 int line
, linepos
, linepos_byte
, topline
;
13145 int height
= XFASTINT (w
->height
);
13147 /* If we decided that this buffer isn't suitable for line numbers,
13148 don't forget that too fast. */
13149 if (EQ (w
->base_line_pos
, w
->buffer
))
13151 /* But do forget it, if the window shows a different buffer now. */
13152 else if (BUFFERP (w
->base_line_pos
))
13153 w
->base_line_pos
= Qnil
;
13155 /* If the buffer is very big, don't waste time. */
13156 if (INTEGERP (Vline_number_display_limit
)
13157 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13159 w
->base_line_pos
= Qnil
;
13160 w
->base_line_number
= Qnil
;
13164 if (!NILP (w
->base_line_number
)
13165 && !NILP (w
->base_line_pos
)
13166 && XFASTINT (w
->base_line_pos
) <= startpos
)
13168 line
= XFASTINT (w
->base_line_number
);
13169 linepos
= XFASTINT (w
->base_line_pos
);
13170 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13175 linepos
= BUF_BEGV (b
);
13176 linepos_byte
= BUF_BEGV_BYTE (b
);
13179 /* Count lines from base line to window start position. */
13180 nlines
= display_count_lines (linepos
, linepos_byte
,
13184 topline
= nlines
+ line
;
13186 /* Determine a new base line, if the old one is too close
13187 or too far away, or if we did not have one.
13188 "Too close" means it's plausible a scroll-down would
13189 go back past it. */
13190 if (startpos
== BUF_BEGV (b
))
13192 XSETFASTINT (w
->base_line_number
, topline
);
13193 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
13195 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13196 || linepos
== BUF_BEGV (b
))
13198 int limit
= BUF_BEGV (b
);
13199 int limit_byte
= BUF_BEGV_BYTE (b
);
13201 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13203 if (startpos
- distance
> limit
)
13205 limit
= startpos
- distance
;
13206 limit_byte
= CHAR_TO_BYTE (limit
);
13209 nlines
= display_count_lines (startpos
, startpos_byte
,
13211 - (height
* 2 + 30),
13213 /* If we couldn't find the lines we wanted within
13214 line_number_display_limit_width chars per line,
13215 give up on line numbers for this window. */
13216 if (position
== limit_byte
&& limit
== startpos
- distance
)
13218 w
->base_line_pos
= w
->buffer
;
13219 w
->base_line_number
= Qnil
;
13223 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
13224 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
13227 /* Now count lines from the start pos to point. */
13228 nlines
= display_count_lines (startpos
, startpos_byte
,
13229 PT_BYTE
, PT
, &junk
);
13231 /* Record that we did display the line number. */
13232 line_number_displayed
= 1;
13234 /* Make the string to show. */
13235 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13236 return decode_mode_spec_buf
;
13239 char* p
= decode_mode_spec_buf
;
13240 int pad
= field_width
- 2;
13246 return decode_mode_spec_buf
;
13252 obj
= b
->mode_name
;
13256 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13262 int pos
= marker_position (w
->start
);
13263 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13265 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13267 if (pos
<= BUF_BEGV (b
))
13272 else if (pos
<= BUF_BEGV (b
))
13276 if (total
> 1000000)
13277 /* Do it differently for a large value, to avoid overflow. */
13278 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13280 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13281 /* We can't normally display a 3-digit number,
13282 so get us a 2-digit number that is close. */
13285 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13286 return decode_mode_spec_buf
;
13290 /* Display percentage of size above the bottom of the screen. */
13293 int toppos
= marker_position (w
->start
);
13294 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13295 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13297 if (botpos
>= BUF_ZV (b
))
13299 if (toppos
<= BUF_BEGV (b
))
13306 if (total
> 1000000)
13307 /* Do it differently for a large value, to avoid overflow. */
13308 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13310 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13311 /* We can't normally display a 3-digit number,
13312 so get us a 2-digit number that is close. */
13315 if (toppos
<= BUF_BEGV (b
))
13316 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13318 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13319 return decode_mode_spec_buf
;
13324 /* status of process */
13325 obj
= Fget_buffer_process (w
->buffer
);
13327 return "no process";
13328 #ifdef subprocesses
13329 obj
= Fsymbol_name (Fprocess_status (obj
));
13333 case 't': /* indicate TEXT or BINARY */
13334 #ifdef MODE_LINE_BINARY_TEXT
13335 return MODE_LINE_BINARY_TEXT (b
);
13341 /* coding-system (not including end-of-line format) */
13343 /* coding-system (including end-of-line type) */
13345 int eol_flag
= (c
== 'Z');
13346 char *p
= decode_mode_spec_buf
;
13348 if (! FRAME_WINDOW_P (f
))
13350 /* No need to mention EOL here--the terminal never needs
13351 to do EOL conversion. */
13352 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13353 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13355 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13358 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13359 #ifdef subprocesses
13360 obj
= Fget_buffer_process (Fcurrent_buffer ());
13361 if (PROCESSP (obj
))
13363 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13365 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13368 #endif /* subprocesses */
13371 return decode_mode_spec_buf
;
13376 return (char *) XSTRING (obj
)->data
;
13382 /* Count up to COUNT lines starting from START / START_BYTE.
13383 But don't go beyond LIMIT_BYTE.
13384 Return the number of lines thus found (always nonnegative).
13386 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13389 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13390 int start
, start_byte
, limit_byte
, count
;
13393 register unsigned char *cursor
;
13394 unsigned char *base
;
13396 register int ceiling
;
13397 register unsigned char *ceiling_addr
;
13398 int orig_count
= count
;
13400 /* If we are not in selective display mode,
13401 check only for newlines. */
13402 int selective_display
= (!NILP (current_buffer
->selective_display
)
13403 && !INTEGERP (current_buffer
->selective_display
));
13407 while (start_byte
< limit_byte
)
13409 ceiling
= BUFFER_CEILING_OF (start_byte
);
13410 ceiling
= min (limit_byte
- 1, ceiling
);
13411 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13412 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13415 if (selective_display
)
13416 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13419 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13422 if (cursor
!= ceiling_addr
)
13426 start_byte
+= cursor
- base
+ 1;
13427 *byte_pos_ptr
= start_byte
;
13431 if (++cursor
== ceiling_addr
)
13437 start_byte
+= cursor
- base
;
13442 while (start_byte
> limit_byte
)
13444 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13445 ceiling
= max (limit_byte
, ceiling
);
13446 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13447 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13450 if (selective_display
)
13451 while (--cursor
!= ceiling_addr
13452 && *cursor
!= '\n' && *cursor
!= 015)
13455 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13458 if (cursor
!= ceiling_addr
)
13462 start_byte
+= cursor
- base
+ 1;
13463 *byte_pos_ptr
= start_byte
;
13464 /* When scanning backwards, we should
13465 not count the newline posterior to which we stop. */
13466 return - orig_count
- 1;
13472 /* Here we add 1 to compensate for the last decrement
13473 of CURSOR, which took it past the valid range. */
13474 start_byte
+= cursor
- base
+ 1;
13478 *byte_pos_ptr
= limit_byte
;
13481 return - orig_count
+ count
;
13482 return orig_count
- count
;
13488 /***********************************************************************
13490 ***********************************************************************/
13492 /* Display a NUL-terminated string, starting with index START.
13494 If STRING is non-null, display that C string. Otherwise, the Lisp
13495 string LISP_STRING is displayed.
13497 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13498 FACE_STRING. Display STRING or LISP_STRING with the face at
13499 FACE_STRING_POS in FACE_STRING:
13501 Display the string in the environment given by IT, but use the
13502 standard display table, temporarily.
13504 FIELD_WIDTH is the minimum number of output glyphs to produce.
13505 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13506 with spaces. If STRING has more characters, more than FIELD_WIDTH
13507 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13509 PRECISION is the maximum number of characters to output from
13510 STRING. PRECISION < 0 means don't truncate the string.
13512 This is roughly equivalent to printf format specifiers:
13514 FIELD_WIDTH PRECISION PRINTF
13515 ----------------------------------------
13521 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13522 display them, and < 0 means obey the current buffer's value of
13523 enable_multibyte_characters.
13525 Value is the number of glyphs produced. */
13528 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13529 start
, it
, field_width
, precision
, max_x
, multibyte
)
13530 unsigned char *string
;
13531 Lisp_Object lisp_string
;
13532 Lisp_Object face_string
;
13533 int face_string_pos
;
13536 int field_width
, precision
, max_x
;
13539 int hpos_at_start
= it
->hpos
;
13540 int saved_face_id
= it
->face_id
;
13541 struct glyph_row
*row
= it
->glyph_row
;
13543 /* Initialize the iterator IT for iteration over STRING beginning
13544 with index START. We assume that IT may be modified here (which
13545 means that display_line has to do something when displaying a
13546 mini-buffer prompt, which it does). */
13547 reseat_to_string (it
, string
, lisp_string
, start
,
13548 precision
, field_width
, multibyte
);
13550 /* If displaying STRING, set up the face of the iterator
13551 from LISP_STRING, if that's given. */
13552 if (STRINGP (face_string
))
13558 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13559 0, it
->region_beg_charpos
,
13560 it
->region_end_charpos
,
13561 &endptr
, it
->base_face_id
);
13562 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13563 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13566 /* Set max_x to the maximum allowed X position. Don't let it go
13567 beyond the right edge of the window. */
13569 max_x
= it
->last_visible_x
;
13571 max_x
= min (max_x
, it
->last_visible_x
);
13573 /* Skip over display elements that are not visible. because IT->w is
13575 if (it
->current_x
< it
->first_visible_x
)
13576 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
13577 MOVE_TO_POS
| MOVE_TO_X
);
13579 row
->ascent
= it
->max_ascent
;
13580 row
->height
= it
->max_ascent
+ it
->max_descent
;
13581 row
->phys_ascent
= it
->max_phys_ascent
;
13582 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13584 /* This condition is for the case that we are called with current_x
13585 past last_visible_x. */
13586 while (it
->current_x
< max_x
)
13588 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
13590 /* Get the next display element. */
13591 if (!get_next_display_element (it
))
13594 /* Produce glyphs. */
13595 x_before
= it
->current_x
;
13596 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13597 PRODUCE_GLYPHS (it
);
13599 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
13602 while (i
< nglyphs
)
13604 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13606 if (!it
->truncate_lines_p
13607 && x
+ glyph
->pixel_width
> max_x
)
13609 /* End of continued line or max_x reached. */
13610 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13614 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
13616 /* Glyph is at least partially visible. */
13618 if (x
< it
->first_visible_x
)
13619 it
->glyph_row
->x
= x
- it
->first_visible_x
;
13623 /* Glyph is off the left margin of the display area.
13624 Should not happen. */
13628 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13629 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13630 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13631 row
->phys_height
= max (row
->phys_height
,
13632 it
->max_phys_ascent
+ it
->max_phys_descent
);
13633 x
+= glyph
->pixel_width
;
13637 /* Stop if max_x reached. */
13641 /* Stop at line ends. */
13642 if (ITERATOR_AT_END_OF_LINE_P (it
))
13644 it
->continuation_lines_width
= 0;
13648 set_iterator_to_next (it
, 1);
13650 /* Stop if truncating at the right edge. */
13651 if (it
->truncate_lines_p
13652 && it
->current_x
>= it
->last_visible_x
)
13654 /* Add truncation mark, but don't do it if the line is
13655 truncated at a padding space. */
13656 if (IT_CHARPOS (*it
) < it
->string_nchars
)
13658 if (!FRAME_WINDOW_P (it
->f
))
13659 produce_special_glyphs (it
, IT_TRUNCATION
);
13660 it
->glyph_row
->truncated_on_right_p
= 1;
13666 /* Maybe insert a truncation at the left. */
13667 if (it
->first_visible_x
13668 && IT_CHARPOS (*it
) > 0)
13670 if (!FRAME_WINDOW_P (it
->f
))
13671 insert_left_trunc_glyphs (it
);
13672 it
->glyph_row
->truncated_on_left_p
= 1;
13675 it
->face_id
= saved_face_id
;
13677 /* Value is number of columns displayed. */
13678 return it
->hpos
- hpos_at_start
;
13683 /* This is like a combination of memq and assq. Return 1 if PROPVAL
13684 appears as an element of LIST or as the car of an element of LIST.
13685 If PROPVAL is a list, compare each element against LIST in that
13686 way, and return 1 if any element of PROPVAL is found in LIST.
13687 Otherwise return 0. This function cannot quit. */
13690 invisible_p (propval
, list
)
13691 register Lisp_Object propval
;
13694 register Lisp_Object tail
, proptail
;
13696 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13698 register Lisp_Object tem
;
13700 if (EQ (propval
, tem
))
13702 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13706 if (CONSP (propval
))
13708 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13710 Lisp_Object propelt
;
13711 propelt
= XCAR (proptail
);
13712 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13714 register Lisp_Object tem
;
13716 if (EQ (propelt
, tem
))
13718 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13728 /* Return 1 if PROPVAL appears as the car of an element of LIST and
13729 the cdr of that element is non-nil. If PROPVAL is a list, check
13730 each element of PROPVAL in that way, and the first time some
13731 element is found, return 1 if the cdr of that element is non-nil.
13732 Otherwise return 0. This function cannot quit. */
13735 invisible_ellipsis_p (propval
, list
)
13736 register Lisp_Object propval
;
13739 register Lisp_Object tail
, proptail
;
13741 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13743 register Lisp_Object tem
;
13745 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13746 return ! NILP (XCDR (tem
));
13749 if (CONSP (propval
))
13750 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13752 Lisp_Object propelt
;
13753 propelt
= XCAR (proptail
);
13754 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13756 register Lisp_Object tem
;
13758 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13759 return ! NILP (XCDR (tem
));
13768 /***********************************************************************
13770 ***********************************************************************/
13775 Vwith_echo_area_save_vector
= Qnil
;
13776 staticpro (&Vwith_echo_area_save_vector
);
13778 Vmessage_stack
= Qnil
;
13779 staticpro (&Vmessage_stack
);
13781 Qinhibit_redisplay
= intern ("inhibit-redisplay");
13782 staticpro (&Qinhibit_redisplay
);
13785 defsubr (&Sdump_glyph_matrix
);
13786 defsubr (&Sdump_glyph_row
);
13787 defsubr (&Sdump_tool_bar_row
);
13788 defsubr (&Strace_redisplay_toggle
);
13789 defsubr (&Strace_to_stderr
);
13792 staticpro (&Qmenu_bar_update_hook
);
13793 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
13795 staticpro (&Qoverriding_terminal_local_map
);
13796 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
13798 staticpro (&Qoverriding_local_map
);
13799 Qoverriding_local_map
= intern ("overriding-local-map");
13801 staticpro (&Qwindow_scroll_functions
);
13802 Qwindow_scroll_functions
= intern ("window-scroll-functions");
13804 staticpro (&Qredisplay_end_trigger_functions
);
13805 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
13807 staticpro (&Qinhibit_point_motion_hooks
);
13808 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
13810 QCdata
= intern (":data");
13811 staticpro (&QCdata
);
13812 Qdisplay
= intern ("display");
13813 staticpro (&Qdisplay
);
13814 Qspace_width
= intern ("space-width");
13815 staticpro (&Qspace_width
);
13816 Qraise
= intern ("raise");
13817 staticpro (&Qraise
);
13818 Qspace
= intern ("space");
13819 staticpro (&Qspace
);
13820 Qmargin
= intern ("margin");
13821 staticpro (&Qmargin
);
13822 Qleft_margin
= intern ("left-margin");
13823 staticpro (&Qleft_margin
);
13824 Qright_margin
= intern ("right-margin");
13825 staticpro (&Qright_margin
);
13826 Qalign_to
= intern ("align-to");
13827 staticpro (&Qalign_to
);
13828 QCalign_to
= intern (":align-to");
13829 staticpro (&QCalign_to
);
13830 Qrelative_width
= intern ("relative-width");
13831 staticpro (&Qrelative_width
);
13832 QCrelative_width
= intern (":relative-width");
13833 staticpro (&QCrelative_width
);
13834 QCrelative_height
= intern (":relative-height");
13835 staticpro (&QCrelative_height
);
13836 QCeval
= intern (":eval");
13837 staticpro (&QCeval
);
13838 Qwhen
= intern ("when");
13839 staticpro (&Qwhen
);
13840 QCfile
= intern (":file");
13841 staticpro (&QCfile
);
13842 Qfontified
= intern ("fontified");
13843 staticpro (&Qfontified
);
13844 Qfontification_functions
= intern ("fontification-functions");
13845 staticpro (&Qfontification_functions
);
13846 Qtrailing_whitespace
= intern ("trailing-whitespace");
13847 staticpro (&Qtrailing_whitespace
);
13848 Qimage
= intern ("image");
13849 staticpro (&Qimage
);
13850 Qmessage_truncate_lines
= intern ("message-truncate-lines");
13851 staticpro (&Qmessage_truncate_lines
);
13852 Qgrow_only
= intern ("grow-only");
13853 staticpro (&Qgrow_only
);
13855 last_arrow_position
= Qnil
;
13856 last_arrow_string
= Qnil
;
13857 staticpro (&last_arrow_position
);
13858 staticpro (&last_arrow_string
);
13860 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
13861 staticpro (&echo_buffer
[0]);
13862 staticpro (&echo_buffer
[1]);
13864 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
13865 staticpro (&echo_area_buffer
[0]);
13866 staticpro (&echo_area_buffer
[1]);
13868 Vmessages_buffer_name
= build_string ("*Messages*");
13869 staticpro (&Vmessages_buffer_name
);
13871 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
13872 "Non-nil means highlight trailing whitespace.\n\
13873 The face used for trailing whitespace is `trailing-whitespace'.");
13874 Vshow_trailing_whitespace
= Qnil
;
13876 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
13877 "Non-nil means don't actually do any redisplay.\n\
13878 This is used for internal purposes.");
13879 Vinhibit_redisplay
= Qnil
;
13881 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
13882 "String (or mode line construct) included (normally) in `mode-line-format'.");
13883 Vglobal_mode_string
= Qnil
;
13885 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
13886 "Marker for where to display an arrow on top of the buffer text.\n\
13887 This must be the beginning of a line in order to work.\n\
13888 See also `overlay-arrow-string'.");
13889 Voverlay_arrow_position
= Qnil
;
13891 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
13892 "String to display as an arrow. See also `overlay-arrow-position'.");
13893 Voverlay_arrow_string
= Qnil
;
13895 DEFVAR_INT ("scroll-step", &scroll_step
,
13896 "*The number of lines to try scrolling a window by when point moves out.\n\
13897 If that fails to bring point back on frame, point is centered instead.\n\
13898 If this is zero, point is always centered after it moves off frame.\n\
13899 If you want scrolling to always be a line at a time, you should set\n\
13900 `scroll-conservatively' to a large value rather than set this to 1.");
13902 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13903 "*Scroll up to this many lines, to bring point back on screen.\n\
13904 A value of zero means to scroll the text to center point vertically\n\
13906 scroll_conservatively
= 0;
13908 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13909 "*Number of lines of margin at the top and bottom of a window.\n\
13910 Recenter the window whenever point gets within this many lines\n\
13911 of the top or bottom of the window.");
13915 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13918 DEFVAR_BOOL ("truncate-partial-width-windows",
13919 &truncate_partial_width_windows
,
13920 "*Non-nil means truncate lines in all windows less than full frame wide.");
13921 truncate_partial_width_windows
= 1;
13923 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13924 "nil means display the mode-line/header-line/menu-bar in the default face.\n\
13925 Any other value means to use the appropriate face, `mode-line',\n\
13926 `header-line', or `menu' respectively.\n\
13928 This variable is deprecated; please change the above faces instead.");
13929 mode_line_inverse_video
= 1;
13931 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
13932 "*Maximum buffer size for which line number should be displayed.\n\
13933 If the buffer is bigger than this, the line number does not appear\n\
13934 in the mode line. A value of nil means no limit.");
13935 Vline_number_display_limit
= Qnil
;
13937 DEFVAR_INT ("line-number-display-limit-width",
13938 &line_number_display_limit_width
,
13939 "*Maximum line width (in characters) for line number display.\n\
13940 If the average length of the lines near point is bigger than this, then the\n\
13941 line number may be omitted from the mode line.");
13942 line_number_display_limit_width
= 200;
13944 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13945 "*Non-nil means highlight region even in nonselected windows.");
13946 highlight_nonselected_windows
= 0;
13948 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13949 "Non-nil if more than one frame is visible on this display.\n\
13950 Minibuffer-only frames don't count, but iconified frames do.\n\
13951 This variable is not guaranteed to be accurate except while processing\n\
13952 `frame-title-format' and `icon-title-format'.");
13954 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13955 "Template for displaying the title bar of visible frames.\n\
13956 \(Assuming the window manager supports this feature.)\n\
13957 This variable has the same structure as `mode-line-format' (which see),\n\
13958 and is used only on frames for which no explicit name has been set\n\
13959 \(see `modify-frame-parameters').");
13960 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13961 "Template for displaying the title bar of an iconified frame.\n\
13962 \(Assuming the window manager supports this feature.)\n\
13963 This variable has the same structure as `mode-line-format' (which see),\n\
13964 and is used only on frames for which no explicit name has been set\n\
13965 \(see `modify-frame-parameters').");
13967 = Vframe_title_format
13968 = Fcons (intern ("multiple-frames"),
13969 Fcons (build_string ("%b"),
13970 Fcons (Fcons (build_string (""),
13971 Fcons (intern ("invocation-name"),
13972 Fcons (build_string ("@"),
13973 Fcons (intern ("system-name"),
13977 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13978 "Maximum number of lines to keep in the message log buffer.\n\
13979 If nil, disable message logging. If t, log messages but don't truncate\n\
13980 the buffer when it becomes large.");
13981 XSETFASTINT (Vmessage_log_max
, 50);
13983 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13984 "Functions called before redisplay, if window sizes have changed.\n\
13985 The value should be a list of functions that take one argument.\n\
13986 Just before redisplay, for each frame, if any of its windows have changed\n\
13987 size since the last redisplay, or have been split or deleted,\n\
13988 all the functions in the list are called, with the frame as argument.");
13989 Vwindow_size_change_functions
= Qnil
;
13991 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13992 "List of Functions to call before redisplaying a window with scrolling.\n\
13993 Each function is called with two arguments, the window\n\
13994 and its new display-start position. Note that the value of `window-end'\n\
13995 is not valid when these functions are called.");
13996 Vwindow_scroll_functions
= Qnil
;
13998 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13999 "*Non-nil means automatically resize tool-bars.\n\
14000 This increases a tool-bar's height if not all tool-bar items are visible.\n\
14001 It decreases a tool-bar's height when it would display blank lines\n\
14003 auto_resize_tool_bars_p
= 1;
14005 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
14006 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
14007 auto_raise_tool_bar_buttons_p
= 1;
14009 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
14010 "*Margin around tool-bar buttons in pixels.");
14011 tool_bar_button_margin
= 1;
14013 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
14014 "Relief thickness of tool-bar buttons.");
14015 tool_bar_button_relief
= 3;
14017 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
14018 "List of functions to call to fontify regions of text.\n\
14019 Each function is called with one argument POS. Functions must\n\
14020 fontify a region starting at POS in the current buffer, and give\n\
14021 fontified regions the property `fontified'.\n\
14022 This variable automatically becomes buffer-local when set.");
14023 Vfontification_functions
= Qnil
;
14024 Fmake_variable_buffer_local (Qfontification_functions
);
14026 DEFVAR_BOOL ("unibyte-display-via-language-environment",
14027 &unibyte_display_via_language_environment
,
14028 "*Non-nil means display unibyte text according to language environment.\n\
14029 Specifically this means that unibyte non-ASCII characters\n\
14030 are displayed by converting them to the equivalent multibyte characters\n\
14031 according to the current language environment. As a result, they are\n\
14032 displayed according to the current fontset.");
14033 unibyte_display_via_language_environment
= 0;
14035 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
14036 "*Maximum height for resizing mini-windows.\n\
14037 If a float, it specifies a fraction of the mini-window frame's height.\n\
14038 If an integer, it specifies a number of lines.");
14039 Vmax_mini_window_height
= make_float (0.25);
14041 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
14042 "*How to resize the mini-window.\n\
14043 A value of nil means don't automatically resize mini-windows.\n\
14044 A value of t means resize it to fit the text displayed in it.\n\
14045 A value of `grow-only', the default, means let mini-windows grow\n\
14046 only, until the its display becomes empty, at which point the mini-window\n\
14047 goes back to its normal size.");
14048 Vresize_mini_windows
= Qgrow_only
;
14050 DEFVAR_BOOL ("cursor-in-non-selected-windows",
14051 &cursor_in_non_selected_windows
,
14052 "*Non-nil means display a hollow cursor in non-selected windows.\n\
14053 Nil means don't display a cursor there.");
14054 cursor_in_non_selected_windows
= 1;
14056 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
14057 "*Non-nil means scroll the display automatically to make point visible.");
14058 automatic_hscrolling_p
= 1;
14060 DEFVAR_LISP ("image-types", &Vimage_types
,
14061 "List of supported image types.\n\
14062 Each element of the list is a symbol for a supported image type.");
14063 Vimage_types
= Qnil
;
14065 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
14066 "If non-nil, messages are truncated instead of resizing the echo area.\n\
14067 Bind this around calls to `message' to let it take effect.");
14068 message_truncate_lines
= 0;
14070 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
14071 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
14072 Can be used to update submenus whose contents should vary.");
14073 Vmenu_bar_update_hook
= Qnil
;
14077 /* Initialize this module when Emacs starts. */
14082 Lisp_Object root_window
;
14083 struct window
*mini_w
;
14085 current_header_line_height
= current_mode_line_height
= -1;
14087 CHARPOS (this_line_start_pos
) = 0;
14089 mini_w
= XWINDOW (minibuf_window
);
14090 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
14092 if (!noninteractive
)
14094 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
14097 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
14098 set_window_height (root_window
,
14099 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
14101 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
14102 set_window_height (minibuf_window
, 1, 0);
14104 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
14105 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
14107 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
14108 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
14109 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
14111 /* The default ellipsis glyphs `...'. */
14112 for (i
= 0; i
< 3; ++i
)
14113 XSETFASTINT (default_invis_vector
[i
], '.');
14116 #ifdef HAVE_WINDOW_SYSTEM
14118 /* Allocate the buffer for frame titles. */
14120 frame_title_buf
= (char *) xmalloc (size
);
14121 frame_title_buf_end
= frame_title_buf
+ size
;
14122 frame_title_ptr
= NULL
;
14124 #endif /* HAVE_WINDOW_SYSTEM */
14126 help_echo_showing_p
= 0;