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 /* Nonzero means display mode line highlighted. */
403 int mode_line_inverse_video
;
405 /* Prompt to display in front of the mini-buffer contents. */
407 Lisp_Object minibuf_prompt
;
409 /* Width of current mini-buffer prompt. Only set after display_line
410 of the line that contains the prompt. */
412 int minibuf_prompt_width
;
413 int minibuf_prompt_pixel_width
;
415 /* This is the window where the echo area message was displayed. It
416 is always a mini-buffer window, but it may not be the same window
417 currently active as a mini-buffer. */
419 Lisp_Object echo_area_window
;
421 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
422 pushes the current message and the value of
423 message_enable_multibyte on the stack, the function restore_message
424 pops the stack and displays MESSAGE again. */
426 Lisp_Object Vmessage_stack
;
428 /* Nonzero means multibyte characters were enabled when the echo area
429 message was specified. */
431 int message_enable_multibyte
;
433 /* True if we should redraw the mode lines on the next redisplay. */
435 int update_mode_lines
;
437 /* Nonzero if window sizes or contents have changed since last
438 redisplay that finished */
440 int windows_or_buffers_changed
;
442 /* Nonzero after display_mode_line if %l was used and it displayed a
445 int line_number_displayed
;
447 /* Maximum buffer size for which to display line numbers. */
449 Lisp_Object Vline_number_display_limit
;
451 /* line width to consider when repostioning for line number display */
453 static int line_number_display_limit_width
;
455 /* Number of lines to keep in the message log buffer. t means
456 infinite. nil means don't log at all. */
458 Lisp_Object Vmessage_log_max
;
460 /* The name of the *Messages* buffer, a string. */
462 static Lisp_Object Vmessages_buffer_name
;
464 /* Current, index 0, and last displayed echo area message. Either
465 buffers from echo_buffers, or nil to indicate no message. */
467 Lisp_Object echo_area_buffer
[2];
469 /* The buffers referenced from echo_area_buffer. */
471 static Lisp_Object echo_buffer
[2];
473 /* A vector saved used in with_area_buffer to reduce consing. */
475 static Lisp_Object Vwith_echo_area_save_vector
;
477 /* Non-zero means display_echo_area should display the last echo area
478 message again. Set by redisplay_preserve_echo_area. */
480 static int display_last_displayed_message_p
;
482 /* Nonzero if echo area is being used by print; zero if being used by
485 int message_buf_print
;
487 /* Maximum height for resizing mini-windows. Either a float
488 specifying a fraction of the available height, or an integer
489 specifying a number of lines. */
491 Lisp_Object Vmax_mini_window_height
;
493 /* Non-zero means messages should be displayed with truncated
494 lines instead of being continued. */
496 int message_truncate_lines
;
497 Lisp_Object Qmessage_truncate_lines
;
499 /* Non-zero means we want a hollow cursor in windows that are not
500 selected. Zero means there's no cursor in such windows. */
502 int cursor_in_non_selected_windows
;
504 /* A scratch glyph row with contents used for generating truncation
505 glyphs. Also used in direct_output_for_insert. */
507 #define MAX_SCRATCH_GLYPHS 100
508 struct glyph_row scratch_glyph_row
;
509 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
511 /* Ascent and height of the last line processed by move_it_to. */
513 static int last_max_ascent
, last_height
;
515 /* Non-zero if there's a help-echo in the echo area. */
517 int help_echo_showing_p
;
519 /* If >= 0, computed, exact values of mode-line and header-line height
520 to use in the macros CURRENT_MODE_LINE_HEIGHT and
521 CURRENT_HEADER_LINE_HEIGHT. */
523 int current_mode_line_height
, current_header_line_height
;
525 /* The maximum distance to look ahead for text properties. Values
526 that are too small let us call compute_char_face and similar
527 functions too often which is expensive. Values that are too large
528 let us call compute_char_face and alike too often because we
529 might not be interested in text properties that far away. */
531 #define TEXT_PROP_DISTANCE_LIMIT 100
535 /* Non-zero means print traces of redisplay if compiled with
538 int trace_redisplay_p
;
540 #endif /* GLYPH_DEBUG */
542 #ifdef DEBUG_TRACE_MOVE
543 /* Non-zero means trace with TRACE_MOVE to stderr. */
546 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
548 #define TRACE_MOVE(x) (void) 0
551 /* Non-zero means automatically scroll windows horizontally to make
554 int automatic_hscrolling_p
;
556 /* A list of symbols, one for each supported image type. */
558 Lisp_Object Vimage_types
;
560 /* The variable `resize-mini-windows'. If nil, don't resize
561 mini-windows. If t, always resize them to fit the text they
562 display. If `grow-only', let mini-windows grow only until they
565 Lisp_Object Vresize_mini_windows
;
567 /* Value returned from text property handlers (see below). */
572 HANDLED_RECOMPUTE_PROPS
,
573 HANDLED_OVERLAY_STRING_CONSUMED
,
577 /* A description of text properties that redisplay is interested
582 /* The name of the property. */
585 /* A unique index for the property. */
588 /* A handler function called to set up iterator IT from the property
589 at IT's current position. Value is used to steer handle_stop. */
590 enum prop_handled (*handler
) P_ ((struct it
*it
));
593 static enum prop_handled handle_face_prop
P_ ((struct it
*));
594 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
595 static enum prop_handled handle_display_prop
P_ ((struct it
*));
596 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
597 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
598 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
600 /* Properties handled by iterators. */
602 static struct props it_props
[] =
604 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
605 /* Handle `face' before `display' because some sub-properties of
606 `display' need to know the face. */
607 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
608 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
609 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
610 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
614 /* Value is the position described by X. If X is a marker, value is
615 the marker_position of X. Otherwise, value is X. */
617 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
619 /* Enumeration returned by some move_it_.* functions internally. */
623 /* Not used. Undefined value. */
626 /* Move ended at the requested buffer position or ZV. */
627 MOVE_POS_MATCH_OR_ZV
,
629 /* Move ended at the requested X pixel position. */
632 /* Move within a line ended at the end of a line that must be
636 /* Move within a line ended at the end of a line that would
637 be displayed truncated. */
640 /* Move within a line ended at a line end. */
646 /* Function prototypes. */
648 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
649 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
650 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
651 static int invisible_text_between_p
P_ ((struct it
*, int, int));
652 static int next_element_from_ellipsis
P_ ((struct it
*));
653 static void pint2str
P_ ((char *, int, int));
654 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
656 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
657 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
658 static void store_frame_title_char
P_ ((char));
659 static int store_frame_title
P_ ((unsigned char *, int, int));
660 static void x_consider_frame_title
P_ ((Lisp_Object
));
661 static void handle_stop
P_ ((struct it
*));
662 static int tool_bar_lines_needed
P_ ((struct frame
*));
663 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
664 static void ensure_echo_area_buffers
P_ ((void));
665 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
667 struct glyph_row
*));
668 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
669 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
670 static int with_echo_area_buffer
P_ ((struct window
*, int,
671 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
672 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
673 static void clear_garbaged_frames
P_ ((void));
674 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
675 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
676 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
677 static int display_echo_area
P_ ((struct window
*));
678 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
679 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
680 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
681 static int string_char_and_length
P_ ((unsigned char *, int, int *));
682 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
684 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
685 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
686 static void insert_left_trunc_glyphs
P_ ((struct it
*));
687 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
688 static void extend_face_to_end_of_line
P_ ((struct it
*));
689 static int append_space
P_ ((struct it
*, int));
690 static void make_cursor_line_fully_visible
P_ ((struct window
*));
691 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
692 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
693 static int trailing_whitespace_p
P_ ((int));
694 static int message_log_check_duplicate
P_ ((int, int, int, int));
695 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
696 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
697 static void push_it
P_ ((struct it
*));
698 static void pop_it
P_ ((struct it
*));
699 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
700 static void redisplay_internal
P_ ((int));
701 static int echo_area_display
P_ ((int));
702 static void redisplay_windows
P_ ((Lisp_Object
));
703 static void redisplay_window
P_ ((Lisp_Object
, int));
704 static void update_menu_bar
P_ ((struct frame
*, int));
705 static int try_window_reusing_current_matrix
P_ ((struct window
*));
706 static int try_window_id
P_ ((struct window
*));
707 static int display_line
P_ ((struct it
*));
708 static int display_mode_lines
P_ ((struct window
*));
709 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
710 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
711 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
712 static void display_menu_bar
P_ ((struct window
*));
713 static int display_count_lines
P_ ((int, int, int, int, int *));
714 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
715 int, int, struct it
*, int, int, int, int));
716 static void compute_line_metrics
P_ ((struct it
*));
717 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
718 static int get_overlay_strings
P_ ((struct it
*));
719 static void next_overlay_string
P_ ((struct it
*));
720 static void reseat
P_ ((struct it
*, struct text_pos
, int));
721 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
722 static void back_to_previous_visible_line_start
P_ ((struct it
*));
723 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
724 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
725 static int next_element_from_display_vector
P_ ((struct it
*));
726 static int next_element_from_string
P_ ((struct it
*));
727 static int next_element_from_c_string
P_ ((struct it
*));
728 static int next_element_from_buffer
P_ ((struct it
*));
729 static int next_element_from_composition
P_ ((struct it
*));
730 static int next_element_from_image
P_ ((struct it
*));
731 static int next_element_from_stretch
P_ ((struct it
*));
732 static void load_overlay_strings
P_ ((struct it
*));
733 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
734 struct display_pos
*));
735 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
736 Lisp_Object
, int, int, int, int));
737 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
739 void move_it_vertically_backward
P_ ((struct it
*, int));
740 static void init_to_row_start
P_ ((struct it
*, struct window
*,
741 struct glyph_row
*));
742 static void init_to_row_end
P_ ((struct it
*, struct window
*,
743 struct glyph_row
*));
744 static void back_to_previous_line_start
P_ ((struct it
*));
745 static int forward_to_next_line_start
P_ ((struct it
*, int *));
746 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
748 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
749 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
750 static int number_of_chars
P_ ((unsigned char *, int));
751 static void compute_stop_pos
P_ ((struct it
*));
752 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
754 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
755 static int next_overlay_change
P_ ((int));
756 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
757 Lisp_Object
, struct text_pos
*));
759 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
760 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
762 #ifdef HAVE_WINDOW_SYSTEM
764 static void update_tool_bar
P_ ((struct frame
*, int));
765 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
766 static int redisplay_tool_bar
P_ ((struct frame
*));
767 static void display_tool_bar_line
P_ ((struct it
*));
769 #endif /* HAVE_WINDOW_SYSTEM */
772 /***********************************************************************
773 Window display dimensions
774 ***********************************************************************/
776 /* Return the window-relative maximum y + 1 for glyph rows displaying
777 text in window W. This is the height of W minus the height of a
778 mode line, if any. */
781 window_text_bottom_y (w
)
784 struct frame
*f
= XFRAME (w
->frame
);
785 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
787 if (WINDOW_WANTS_MODELINE_P (w
))
788 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
793 /* Return the pixel width of display area AREA of window W. AREA < 0
794 means return the total width of W, not including bitmap areas to
795 the left and right of the window. */
798 window_box_width (w
, area
)
802 struct frame
*f
= XFRAME (w
->frame
);
803 int width
= XFASTINT (w
->width
);
805 if (!w
->pseudo_window_p
)
807 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
809 if (area
== TEXT_AREA
)
811 if (INTEGERP (w
->left_margin_width
))
812 width
-= XFASTINT (w
->left_margin_width
);
813 if (INTEGERP (w
->right_margin_width
))
814 width
-= XFASTINT (w
->right_margin_width
);
816 else if (area
== LEFT_MARGIN_AREA
)
817 width
= (INTEGERP (w
->left_margin_width
)
818 ? XFASTINT (w
->left_margin_width
) : 0);
819 else if (area
== RIGHT_MARGIN_AREA
)
820 width
= (INTEGERP (w
->right_margin_width
)
821 ? XFASTINT (w
->right_margin_width
) : 0);
824 return width
* CANON_X_UNIT (f
);
828 /* Return the pixel height of the display area of window W, not
829 including mode lines of W, if any.. */
832 window_box_height (w
)
835 struct frame
*f
= XFRAME (w
->frame
);
836 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
838 xassert (height
>= 0);
840 if (WINDOW_WANTS_MODELINE_P (w
))
841 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
843 if (WINDOW_WANTS_HEADER_LINE_P (w
))
844 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
850 /* Return the frame-relative coordinate of the left edge of display
851 area AREA of window W. AREA < 0 means return the left edge of the
852 whole window, to the right of any bitmap area at the left side of
856 window_box_left (w
, area
)
860 struct frame
*f
= XFRAME (w
->frame
);
861 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
863 if (!w
->pseudo_window_p
)
865 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
866 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
868 if (area
== TEXT_AREA
)
869 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
870 else if (area
== RIGHT_MARGIN_AREA
)
871 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
872 + window_box_width (w
, TEXT_AREA
));
879 /* Return the frame-relative coordinate of the right edge of display
880 area AREA of window W. AREA < 0 means return the left edge of the
881 whole window, to the left of any bitmap area at the right side of
885 window_box_right (w
, area
)
889 return window_box_left (w
, area
) + window_box_width (w
, area
);
893 /* Get the bounding box of the display area AREA of window W, without
894 mode lines, in frame-relative coordinates. AREA < 0 means the
895 whole window, not including bitmap areas to the left and right of
896 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
897 coordinates of the upper-left corner of the box. Return in
898 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
901 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
904 int *box_x
, *box_y
, *box_width
, *box_height
;
906 struct frame
*f
= XFRAME (w
->frame
);
908 *box_width
= window_box_width (w
, area
);
909 *box_height
= window_box_height (w
);
910 *box_x
= window_box_left (w
, area
);
911 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
912 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
913 if (WINDOW_WANTS_HEADER_LINE_P (w
))
914 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
918 /* Get the bounding box of the display area AREA of window W, without
919 mode lines. AREA < 0 means the whole window, not including bitmap
920 areas to the left and right of the window. Return in *TOP_LEFT_X
921 and TOP_LEFT_Y the frame-relative pixel coordinates of the
922 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
923 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
927 window_box_edges (w
, area
, top_left_x
, top_left_y
,
928 bottom_right_x
, bottom_right_y
)
931 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
933 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
935 *bottom_right_x
+= *top_left_x
;
936 *bottom_right_y
+= *top_left_y
;
941 /***********************************************************************
943 ***********************************************************************/
945 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
946 1 if POS is visible and the line containing POS is fully visible.
947 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
948 and header-lines heights. */
951 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
953 int charpos
, *fully
, exact_mode_line_heights_p
;
958 struct buffer
*old_buffer
= NULL
;
960 if (XBUFFER (w
->buffer
) != current_buffer
)
962 old_buffer
= current_buffer
;
963 set_buffer_internal_1 (XBUFFER (w
->buffer
));
966 *fully
= visible_p
= 0;
967 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
969 /* Compute exact mode line heights, if requested. */
970 if (exact_mode_line_heights_p
)
972 if (WINDOW_WANTS_MODELINE_P (w
))
973 current_mode_line_height
974 = display_mode_line (w
, MODE_LINE_FACE_ID
,
975 current_buffer
->mode_line_format
);
977 if (WINDOW_WANTS_HEADER_LINE_P (w
))
978 current_header_line_height
979 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
980 current_buffer
->header_line_format
);
983 start_display (&it
, w
, top
);
984 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
985 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
987 if (IT_CHARPOS (it
) == charpos
)
989 int line_height
, line_bottom_y
;
990 int line_top_y
= it
.current_y
;
991 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
993 line_height
= it
.max_ascent
+ it
.max_descent
;
994 if (line_height
== 0)
997 line_height
= last_height
;
998 else if (charpos
< ZV
)
1000 move_it_by_lines (&it
, 1, 1);
1001 line_height
= (it
.max_ascent
|| it
.max_descent
1002 ? it
.max_ascent
+ it
.max_descent
1007 /* Use the default character height. */
1008 it
.what
= IT_CHARACTER
;
1011 PRODUCE_GLYPHS (&it
);
1012 line_height
= it
.ascent
+ it
.descent
;
1015 line_bottom_y
= line_top_y
+ line_height
;
1017 if (line_top_y
< window_top_y
)
1018 visible_p
= line_bottom_y
> window_top_y
;
1019 else if (line_top_y
< it
.last_visible_y
)
1022 *fully
= line_bottom_y
<= it
.last_visible_y
;
1025 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1027 move_it_by_lines (&it
, 1, 0);
1028 if (charpos
< IT_CHARPOS (it
))
1036 set_buffer_internal_1 (old_buffer
);
1038 current_header_line_height
= current_mode_line_height
= -1;
1043 /* Return the next character from STR which is MAXLEN bytes long.
1044 Return in *LEN the length of the character. This is like
1045 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1046 we find one, we return a `?', but with the length of the invalid
1050 string_char_and_length (str
, maxlen
, len
)
1056 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1057 if (!CHAR_VALID_P (c
, 1))
1058 /* We may not change the length here because other places in Emacs
1059 don't use this function, i.e. they silently accept invalid
1068 /* Given a position POS containing a valid character and byte position
1069 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1071 static struct text_pos
1072 string_pos_nchars_ahead (pos
, string
, nchars
)
1073 struct text_pos pos
;
1077 xassert (STRINGP (string
) && nchars
>= 0);
1079 if (STRING_MULTIBYTE (string
))
1081 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
1082 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
1087 string_char_and_length (p
, rest
, &len
);
1088 p
+= len
, rest
-= len
;
1089 xassert (rest
>= 0);
1091 BYTEPOS (pos
) += len
;
1095 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1101 /* Value is the text position, i.e. character and byte position,
1102 for character position CHARPOS in STRING. */
1104 static INLINE
struct text_pos
1105 string_pos (charpos
, string
)
1109 struct text_pos pos
;
1110 xassert (STRINGP (string
));
1111 xassert (charpos
>= 0);
1112 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1117 /* Value is a text position, i.e. character and byte position, for
1118 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1119 means recognize multibyte characters. */
1121 static struct text_pos
1122 c_string_pos (charpos
, s
, multibyte_p
)
1127 struct text_pos pos
;
1129 xassert (s
!= NULL
);
1130 xassert (charpos
>= 0);
1134 int rest
= strlen (s
), len
;
1136 SET_TEXT_POS (pos
, 0, 0);
1139 string_char_and_length (s
, rest
, &len
);
1140 s
+= len
, rest
-= len
;
1141 xassert (rest
>= 0);
1143 BYTEPOS (pos
) += len
;
1147 SET_TEXT_POS (pos
, charpos
, charpos
);
1153 /* Value is the number of characters in C string S. MULTIBYTE_P
1154 non-zero means recognize multibyte characters. */
1157 number_of_chars (s
, multibyte_p
)
1165 int rest
= strlen (s
), len
;
1166 unsigned char *p
= (unsigned char *) s
;
1168 for (nchars
= 0; rest
> 0; ++nchars
)
1170 string_char_and_length (p
, rest
, &len
);
1171 rest
-= len
, p
+= len
;
1175 nchars
= strlen (s
);
1181 /* Compute byte position NEWPOS->bytepos corresponding to
1182 NEWPOS->charpos. POS is a known position in string STRING.
1183 NEWPOS->charpos must be >= POS.charpos. */
1186 compute_string_pos (newpos
, pos
, string
)
1187 struct text_pos
*newpos
, pos
;
1190 xassert (STRINGP (string
));
1191 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1193 if (STRING_MULTIBYTE (string
))
1194 *newpos
= string_pos_nchars_ahead (pos
, string
,
1195 CHARPOS (*newpos
) - CHARPOS (pos
));
1197 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1202 /***********************************************************************
1203 Lisp form evaluation
1204 ***********************************************************************/
1206 /* Error handler for safe_eval and safe_call. */
1209 safe_eval_handler (arg
)
1212 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1217 /* Evaluate SEXPR and return the result, or nil if something went
1224 int count
= specpdl_ptr
- specpdl
;
1225 struct gcpro gcpro1
;
1229 specbind (Qinhibit_redisplay
, Qt
);
1230 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, safe_eval_handler
);
1232 return unbind_to (count
, val
);
1236 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1237 Return the result, or nil if something went wrong. */
1240 safe_call (nargs
, args
)
1244 int count
= specpdl_ptr
- specpdl
;
1246 struct gcpro gcpro1
;
1249 gcpro1
.nvars
= nargs
;
1250 specbind (Qinhibit_redisplay
, Qt
);
1251 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qerror
,
1254 return unbind_to (count
, val
);
1258 /* Call function FN with one argument ARG.
1259 Return the result, or nil if something went wrong. */
1262 safe_call1 (fn
, arg
)
1263 Lisp_Object fn
, arg
;
1265 Lisp_Object args
[2];
1268 return safe_call (2, args
);
1273 /***********************************************************************
1275 ***********************************************************************/
1279 /* Define CHECK_IT to perform sanity checks on iterators.
1280 This is for debugging. It is too slow to do unconditionally. */
1286 if (it
->method
== next_element_from_string
)
1288 xassert (STRINGP (it
->string
));
1289 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1291 else if (it
->method
== next_element_from_buffer
)
1293 /* Check that character and byte positions agree. */
1294 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1298 xassert (it
->current
.dpvec_index
>= 0);
1300 xassert (it
->current
.dpvec_index
< 0);
1303 #define CHECK_IT(IT) check_it ((IT))
1307 #define CHECK_IT(IT) (void) 0
1314 /* Check that the window end of window W is what we expect it
1315 to be---the last row in the current matrix displaying text. */
1318 check_window_end (w
)
1321 if (!MINI_WINDOW_P (w
)
1322 && !NILP (w
->window_end_valid
))
1324 struct glyph_row
*row
;
1325 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1326 XFASTINT (w
->window_end_vpos
)),
1328 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1329 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1333 #define CHECK_WINDOW_END(W) check_window_end ((W))
1335 #else /* not GLYPH_DEBUG */
1337 #define CHECK_WINDOW_END(W) (void) 0
1339 #endif /* not GLYPH_DEBUG */
1343 /***********************************************************************
1344 Iterator initialization
1345 ***********************************************************************/
1347 /* Initialize IT for displaying current_buffer in window W, starting
1348 at character position CHARPOS. CHARPOS < 0 means that no buffer
1349 position is specified which is useful when the iterator is assigned
1350 a position later. BYTEPOS is the byte position corresponding to
1351 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1353 If ROW is not null, calls to produce_glyphs with IT as parameter
1354 will produce glyphs in that row.
1356 BASE_FACE_ID is the id of a base face to use. It must be one of
1357 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1358 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1359 displaying the tool-bar.
1361 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1362 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1363 corresponding mode line glyph row of the desired matrix of W. */
1366 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1369 int charpos
, bytepos
;
1370 struct glyph_row
*row
;
1371 enum face_id base_face_id
;
1373 int highlight_region_p
;
1375 /* Some precondition checks. */
1376 xassert (w
!= NULL
&& it
!= NULL
);
1377 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1379 /* If face attributes have been changed since the last redisplay,
1380 free realized faces now because they depend on face definitions
1381 that might have changed. */
1382 if (face_change_count
)
1384 face_change_count
= 0;
1385 free_all_realized_faces (Qnil
);
1388 /* Use one of the mode line rows of W's desired matrix if
1392 if (base_face_id
== MODE_LINE_FACE_ID
)
1393 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1394 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1395 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1399 bzero (it
, sizeof *it
);
1400 it
->current
.overlay_string_index
= -1;
1401 it
->current
.dpvec_index
= -1;
1402 it
->base_face_id
= base_face_id
;
1404 /* The window in which we iterate over current_buffer: */
1405 XSETWINDOW (it
->window
, w
);
1407 it
->f
= XFRAME (w
->frame
);
1409 /* Extra space between lines (on window systems only). */
1410 if (base_face_id
== DEFAULT_FACE_ID
1411 && FRAME_WINDOW_P (it
->f
))
1413 if (NATNUMP (current_buffer
->extra_line_spacing
))
1414 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1415 else if (it
->f
->extra_line_spacing
> 0)
1416 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1419 /* If realized faces have been removed, e.g. because of face
1420 attribute changes of named faces, recompute them. */
1421 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1422 recompute_basic_faces (it
->f
);
1424 /* Current value of the `space-width', and 'height' properties. */
1425 it
->space_width
= Qnil
;
1426 it
->font_height
= Qnil
;
1428 /* Are control characters displayed as `^C'? */
1429 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1431 /* -1 means everything between a CR and the following line end
1432 is invisible. >0 means lines indented more than this value are
1434 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1435 ? XFASTINT (current_buffer
->selective_display
)
1436 : (!NILP (current_buffer
->selective_display
)
1438 it
->selective_display_ellipsis_p
1439 = !NILP (current_buffer
->selective_display_ellipses
);
1441 /* Display table to use. */
1442 it
->dp
= window_display_table (w
);
1444 /* Are multibyte characters enabled in current_buffer? */
1445 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1447 /* Non-zero if we should highlight the region. */
1449 = (!NILP (Vtransient_mark_mode
)
1450 && !NILP (current_buffer
->mark_active
)
1451 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1453 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1454 start and end of a visible region in window IT->w. Set both to
1455 -1 to indicate no region. */
1456 if (highlight_region_p
1457 /* Maybe highlight only in selected window. */
1458 && (/* Either show region everywhere. */
1459 highlight_nonselected_windows
1460 /* Or show region in the selected window. */
1461 || w
== XWINDOW (selected_window
)
1462 /* Or show the region if we are in the mini-buffer and W is
1463 the window the mini-buffer refers to. */
1464 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1465 && w
== XWINDOW (Vminibuf_scroll_window
))))
1467 int charpos
= marker_position (current_buffer
->mark
);
1468 it
->region_beg_charpos
= min (PT
, charpos
);
1469 it
->region_end_charpos
= max (PT
, charpos
);
1472 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1474 /* Get the position at which the redisplay_end_trigger hook should
1475 be run, if it is to be run at all. */
1476 if (MARKERP (w
->redisplay_end_trigger
)
1477 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1478 it
->redisplay_end_trigger_charpos
1479 = marker_position (w
->redisplay_end_trigger
);
1480 else if (INTEGERP (w
->redisplay_end_trigger
))
1481 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1483 /* Correct bogus values of tab_width. */
1484 it
->tab_width
= XINT (current_buffer
->tab_width
);
1485 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1488 /* Are lines in the display truncated? */
1489 it
->truncate_lines_p
1490 = (base_face_id
!= DEFAULT_FACE_ID
1491 || XINT (it
->w
->hscroll
)
1492 || (truncate_partial_width_windows
1493 && !WINDOW_FULL_WIDTH_P (it
->w
))
1494 || !NILP (current_buffer
->truncate_lines
));
1496 /* Get dimensions of truncation and continuation glyphs. These are
1497 displayed as bitmaps under X, so we don't need them for such
1499 if (!FRAME_WINDOW_P (it
->f
))
1501 if (it
->truncate_lines_p
)
1503 /* We will need the truncation glyph. */
1504 xassert (it
->glyph_row
== NULL
);
1505 produce_special_glyphs (it
, IT_TRUNCATION
);
1506 it
->truncation_pixel_width
= it
->pixel_width
;
1510 /* We will need the continuation glyph. */
1511 xassert (it
->glyph_row
== NULL
);
1512 produce_special_glyphs (it
, IT_CONTINUATION
);
1513 it
->continuation_pixel_width
= it
->pixel_width
;
1516 /* Reset these values to zero becaue the produce_special_glyphs
1517 above has changed them. */
1518 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1519 it
->phys_ascent
= it
->phys_descent
= 0;
1522 /* Set this after getting the dimensions of truncation and
1523 continuation glyphs, so that we don't produce glyphs when calling
1524 produce_special_glyphs, above. */
1525 it
->glyph_row
= row
;
1526 it
->area
= TEXT_AREA
;
1528 /* Get the dimensions of the display area. The display area
1529 consists of the visible window area plus a horizontally scrolled
1530 part to the left of the window. All x-values are relative to the
1531 start of this total display area. */
1532 if (base_face_id
!= DEFAULT_FACE_ID
)
1534 /* Mode lines, menu bar in terminal frames. */
1535 it
->first_visible_x
= 0;
1536 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1541 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1542 it
->last_visible_x
= (it
->first_visible_x
1543 + window_box_width (w
, TEXT_AREA
));
1545 /* If we truncate lines, leave room for the truncator glyph(s) at
1546 the right margin. Otherwise, leave room for the continuation
1547 glyph(s). Truncation and continuation glyphs are not inserted
1548 for window-based redisplay. */
1549 if (!FRAME_WINDOW_P (it
->f
))
1551 if (it
->truncate_lines_p
)
1552 it
->last_visible_x
-= it
->truncation_pixel_width
;
1554 it
->last_visible_x
-= it
->continuation_pixel_width
;
1557 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1558 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1561 /* Leave room for a border glyph. */
1562 if (!FRAME_WINDOW_P (it
->f
)
1563 && !WINDOW_RIGHTMOST_P (it
->w
))
1564 it
->last_visible_x
-= 1;
1566 it
->last_visible_y
= window_text_bottom_y (w
);
1568 /* For mode lines and alike, arrange for the first glyph having a
1569 left box line if the face specifies a box. */
1570 if (base_face_id
!= DEFAULT_FACE_ID
)
1574 it
->face_id
= base_face_id
;
1576 /* If we have a boxed mode line, make the first character appear
1577 with a left box line. */
1578 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1579 if (face
->box
!= FACE_NO_BOX
)
1580 it
->start_of_box_run_p
= 1;
1583 /* If a buffer position was specified, set the iterator there,
1584 getting overlays and face properties from that position. */
1587 it
->end_charpos
= ZV
;
1589 IT_CHARPOS (*it
) = charpos
;
1591 /* Compute byte position if not specified. */
1593 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1595 IT_BYTEPOS (*it
) = bytepos
;
1597 /* Compute faces etc. */
1598 reseat (it
, it
->current
.pos
, 1);
1605 /* Initialize IT for the display of window W with window start POS. */
1608 start_display (it
, w
, pos
)
1611 struct text_pos pos
;
1613 int start_at_line_beg_p
;
1614 struct glyph_row
*row
;
1615 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1618 row
= w
->desired_matrix
->rows
+ first_vpos
;
1619 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1620 first_y
= it
->current_y
;
1622 /* If window start is not at a line start, move back to the line
1623 start. This makes sure that we take continuation lines into
1625 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1626 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1627 if (!start_at_line_beg_p
)
1628 reseat_at_previous_visible_line_start (it
);
1630 /* If window start is not at a line start, skip forward to POS to
1631 get the correct continuation_lines_width and current_x. */
1632 if (!start_at_line_beg_p
)
1634 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1636 /* If lines are continued, this line may end in the middle of a
1637 multi-glyph character (e.g. a control character displayed as
1638 \003, or in the middle of an overlay string). In this case
1639 move_it_to above will not have taken us to the start of
1640 the continuation line but to the end of the continued line. */
1641 if (!it
->truncate_lines_p
)
1643 if (it
->current_x
> 0)
1645 if (it
->current
.dpvec_index
>= 0
1646 || it
->current
.overlay_string_index
>= 0)
1648 set_iterator_to_next (it
, 1);
1649 move_it_in_display_line_to (it
, -1, -1, 0);
1652 it
->continuation_lines_width
+= it
->current_x
;
1655 /* We're starting a new display line, not affected by the
1656 height of the continued line, so clear the appropriate
1657 fields in the iterator structure. */
1658 it
->max_ascent
= it
->max_descent
= 0;
1659 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1662 it
->current_y
= first_y
;
1664 it
->current_x
= it
->hpos
= 0;
1667 #if 0 /* Don't assert the following because start_display is sometimes
1668 called intentionally with a window start that is not at a
1669 line start. Please leave this code in as a comment. */
1671 /* Window start should be on a line start, now. */
1672 xassert (it
->continuation_lines_width
1673 || IT_CHARPOS (it
) == BEGV
1674 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1679 /* Initialize IT for stepping through current_buffer in window W,
1680 starting at position POS that includes overlay string and display
1681 vector/ control character translation position information. */
1684 init_from_display_pos (it
, w
, pos
)
1687 struct display_pos
*pos
;
1689 /* Keep in mind: the call to reseat in init_iterator skips invisible
1690 text, so we might end up at a position different from POS. This
1691 is only a problem when POS is a row start after a newline and an
1692 overlay starts there with an after-string, and the overlay has an
1693 invisible property. Since we don't skip invisible text in
1694 display_line and elsewhere immediately after consuming the
1695 newline before the row start, such a POS will not be in a string,
1696 but the call to init_iterator below will move us to the
1698 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1699 NULL
, DEFAULT_FACE_ID
);
1701 /* If position is within an overlay string, set up IT to
1702 the right overlay string. */
1703 if (pos
->overlay_string_index
>= 0)
1707 /* We already have the first chunk of overlay strings in
1708 IT->overlay_strings. Load more until the one for
1709 pos->overlay_string_index is in IT->overlay_strings. */
1710 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1712 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1713 it
->current
.overlay_string_index
= 0;
1716 load_overlay_strings (it
);
1717 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1721 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1722 relative_index
= (it
->current
.overlay_string_index
1723 % OVERLAY_STRING_CHUNK_SIZE
);
1724 it
->string
= it
->overlay_strings
[relative_index
];
1725 xassert (STRINGP (it
->string
));
1726 it
->current
.string_pos
= pos
->string_pos
;
1727 it
->method
= next_element_from_string
;
1729 else if (CHARPOS (pos
->string_pos
) >= 0)
1731 /* Recorded position is not in an overlay string, but in another
1732 string. This can only be a string from a `display' property.
1733 IT should already be filled with that string. */
1734 it
->current
.string_pos
= pos
->string_pos
;
1735 xassert (STRINGP (it
->string
));
1738 /* Restore position in display vector translations or control
1739 character translations. */
1740 if (pos
->dpvec_index
>= 0)
1742 /* This fills IT->dpvec. */
1743 get_next_display_element (it
);
1744 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1745 it
->current
.dpvec_index
= pos
->dpvec_index
;
1752 /* Initialize IT for stepping through current_buffer in window W
1753 starting at ROW->start. */
1756 init_to_row_start (it
, w
, row
)
1759 struct glyph_row
*row
;
1761 init_from_display_pos (it
, w
, &row
->start
);
1762 it
->continuation_lines_width
= row
->continuation_lines_width
;
1767 /* Initialize IT for stepping through current_buffer in window W
1768 starting in the line following ROW, i.e. starting at ROW->end. */
1771 init_to_row_end (it
, w
, row
)
1774 struct glyph_row
*row
;
1776 init_from_display_pos (it
, w
, &row
->end
);
1778 if (row
->continued_p
)
1779 it
->continuation_lines_width
= (row
->continuation_lines_width
1780 + row
->pixel_width
);
1787 /***********************************************************************
1789 ***********************************************************************/
1791 /* Called when IT reaches IT->stop_charpos. Handle text property and
1792 overlay changes. Set IT->stop_charpos to the next position where
1799 enum prop_handled handled
;
1800 int handle_overlay_change_p
= 1;
1804 it
->current
.dpvec_index
= -1;
1808 handled
= HANDLED_NORMALLY
;
1810 /* Call text property handlers. */
1811 for (p
= it_props
; p
->handler
; ++p
)
1813 handled
= p
->handler (it
);
1815 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1817 else if (handled
== HANDLED_RETURN
)
1819 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1820 handle_overlay_change_p
= 0;
1823 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1825 /* Don't check for overlay strings below when set to deliver
1826 characters from a display vector. */
1827 if (it
->method
== next_element_from_display_vector
)
1828 handle_overlay_change_p
= 0;
1830 /* Handle overlay changes. */
1831 if (handle_overlay_change_p
)
1832 handled
= handle_overlay_change (it
);
1834 /* Determine where to stop next. */
1835 if (handled
== HANDLED_NORMALLY
)
1836 compute_stop_pos (it
);
1839 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1843 /* Compute IT->stop_charpos from text property and overlay change
1844 information for IT's current position. */
1847 compute_stop_pos (it
)
1850 register INTERVAL iv
, next_iv
;
1851 Lisp_Object object
, limit
, position
;
1853 /* If nowhere else, stop at the end. */
1854 it
->stop_charpos
= it
->end_charpos
;
1856 if (STRINGP (it
->string
))
1858 /* Strings are usually short, so don't limit the search for
1860 object
= it
->string
;
1862 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1868 /* If next overlay change is in front of the current stop pos
1869 (which is IT->end_charpos), stop there. Note: value of
1870 next_overlay_change is point-max if no overlay change
1872 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1873 if (charpos
< it
->stop_charpos
)
1874 it
->stop_charpos
= charpos
;
1876 /* If showing the region, we have to stop at the region
1877 start or end because the face might change there. */
1878 if (it
->region_beg_charpos
> 0)
1880 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1881 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1882 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1883 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1886 /* Set up variables for computing the stop position from text
1887 property changes. */
1888 XSETBUFFER (object
, current_buffer
);
1889 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1890 XSETFASTINT (position
, IT_CHARPOS (*it
));
1894 /* Get the interval containing IT's position. Value is a null
1895 interval if there isn't such an interval. */
1896 iv
= validate_interval_range (object
, &position
, &position
, 0);
1897 if (!NULL_INTERVAL_P (iv
))
1899 Lisp_Object values_here
[LAST_PROP_IDX
];
1902 /* Get properties here. */
1903 for (p
= it_props
; p
->handler
; ++p
)
1904 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1906 /* Look for an interval following iv that has different
1908 for (next_iv
= next_interval (iv
);
1909 (!NULL_INTERVAL_P (next_iv
)
1911 || XFASTINT (limit
) > next_iv
->position
));
1912 next_iv
= next_interval (next_iv
))
1914 for (p
= it_props
; p
->handler
; ++p
)
1916 Lisp_Object new_value
;
1918 new_value
= textget (next_iv
->plist
, *p
->name
);
1919 if (!EQ (values_here
[p
->idx
], new_value
))
1927 if (!NULL_INTERVAL_P (next_iv
))
1929 if (INTEGERP (limit
)
1930 && next_iv
->position
>= XFASTINT (limit
))
1931 /* No text property change up to limit. */
1932 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1934 /* Text properties change in next_iv. */
1935 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1939 xassert (STRINGP (it
->string
)
1940 || (it
->stop_charpos
>= BEGV
1941 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1945 /* Return the position of the next overlay change after POS in
1946 current_buffer. Value is point-max if no overlay change
1947 follows. This is like `next-overlay-change' but doesn't use
1951 next_overlay_change (pos
)
1956 Lisp_Object
*overlays
;
1960 /* Get all overlays at the given position. */
1962 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1963 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1964 if (noverlays
> len
)
1967 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1968 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
1971 /* If any of these overlays ends before endpos,
1972 use its ending point instead. */
1973 for (i
= 0; i
< noverlays
; ++i
)
1978 oend
= OVERLAY_END (overlays
[i
]);
1979 oendpos
= OVERLAY_POSITION (oend
);
1980 endpos
= min (endpos
, oendpos
);
1988 /***********************************************************************
1990 ***********************************************************************/
1992 /* Handle changes in the `fontified' property of the current buffer by
1993 calling hook functions from Qfontification_functions to fontify
1996 static enum prop_handled
1997 handle_fontified_prop (it
)
2000 Lisp_Object prop
, pos
;
2001 enum prop_handled handled
= HANDLED_NORMALLY
;
2003 /* Get the value of the `fontified' property at IT's current buffer
2004 position. (The `fontified' property doesn't have a special
2005 meaning in strings.) If the value is nil, call functions from
2006 Qfontification_functions. */
2007 if (!STRINGP (it
->string
)
2009 && !NILP (Vfontification_functions
)
2010 && !NILP (Vrun_hooks
)
2011 && (pos
= make_number (IT_CHARPOS (*it
)),
2012 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2015 int count
= specpdl_ptr
- specpdl
;
2018 val
= Vfontification_functions
;
2019 specbind (Qfontification_functions
, Qnil
);
2020 specbind (Qafter_change_functions
, Qnil
);
2022 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2023 safe_call1 (val
, pos
);
2026 Lisp_Object globals
, fn
;
2027 struct gcpro gcpro1
, gcpro2
;
2030 GCPRO2 (val
, globals
);
2032 for (; CONSP (val
); val
= XCDR (val
))
2038 /* A value of t indicates this hook has a local
2039 binding; it means to run the global binding too.
2040 In a global value, t should not occur. If it
2041 does, we must ignore it to avoid an endless
2043 for (globals
= Fdefault_value (Qfontification_functions
);
2045 globals
= XCDR (globals
))
2047 fn
= XCAR (globals
);
2049 safe_call1 (fn
, pos
);
2053 safe_call1 (fn
, pos
);
2059 unbind_to (count
, Qnil
);
2061 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2062 something. This avoids an endless loop if they failed to
2063 fontify the text for which reason ever. */
2064 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2065 handled
= HANDLED_RECOMPUTE_PROPS
;
2073 /***********************************************************************
2075 ***********************************************************************/
2077 /* Set up iterator IT from face properties at its current position.
2078 Called from handle_stop. */
2080 static enum prop_handled
2081 handle_face_prop (it
)
2084 int new_face_id
, next_stop
;
2086 if (!STRINGP (it
->string
))
2089 = face_at_buffer_position (it
->w
,
2091 it
->region_beg_charpos
,
2092 it
->region_end_charpos
,
2095 + TEXT_PROP_DISTANCE_LIMIT
),
2098 /* Is this a start of a run of characters with box face?
2099 Caveat: this can be called for a freshly initialized
2100 iterator; face_id is -1 is this case. We know that the new
2101 face will not change until limit, i.e. if the new face has a
2102 box, all characters up to limit will have one. But, as
2103 usual, we don't know whether limit is really the end. */
2104 if (new_face_id
!= it
->face_id
)
2106 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2108 /* If new face has a box but old face has not, this is
2109 the start of a run of characters with box, i.e. it has
2110 a shadow on the left side. The value of face_id of the
2111 iterator will be -1 if this is the initial call that gets
2112 the face. In this case, we have to look in front of IT's
2113 position and see whether there is a face != new_face_id. */
2114 it
->start_of_box_run_p
2115 = (new_face
->box
!= FACE_NO_BOX
2116 && (it
->face_id
>= 0
2117 || IT_CHARPOS (*it
) == BEG
2118 || new_face_id
!= face_before_it_pos (it
)));
2119 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2125 = face_at_string_position (it
->w
,
2127 IT_STRING_CHARPOS (*it
),
2128 (it
->current
.overlay_string_index
>= 0
2131 it
->region_beg_charpos
,
2132 it
->region_end_charpos
,
2136 #if 0 /* This shouldn't be neccessary. Let's check it. */
2137 /* If IT is used to display a mode line we would really like to
2138 use the mode line face instead of the frame's default face. */
2139 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2140 && new_face_id
== DEFAULT_FACE_ID
)
2141 new_face_id
= MODE_LINE_FACE_ID
;
2144 /* Is this a start of a run of characters with box? Caveat:
2145 this can be called for a freshly allocated iterator; face_id
2146 is -1 is this case. We know that the new face will not
2147 change until the next check pos, i.e. if the new face has a
2148 box, all characters up to that position will have a
2149 box. But, as usual, we don't know whether that position
2150 is really the end. */
2151 if (new_face_id
!= it
->face_id
)
2153 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2154 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2156 /* If new face has a box but old face hasn't, this is the
2157 start of a run of characters with box, i.e. it has a
2158 shadow on the left side. */
2159 it
->start_of_box_run_p
2160 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2161 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2165 it
->face_id
= new_face_id
;
2166 return HANDLED_NORMALLY
;
2170 /* Compute the face one character before or after the current position
2171 of IT. BEFORE_P non-zero means get the face in front of IT's
2172 position. Value is the id of the face. */
2175 face_before_or_after_it_pos (it
, before_p
)
2180 int next_check_charpos
;
2181 struct text_pos pos
;
2183 xassert (it
->s
== NULL
);
2185 if (STRINGP (it
->string
))
2187 /* No face change past the end of the string (for the case
2188 we are padding with spaces). No face change before the
2190 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
2191 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2194 /* Set pos to the position before or after IT's current position. */
2196 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2198 /* For composition, we must check the character after the
2200 pos
= (it
->what
== IT_COMPOSITION
2201 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2202 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2204 /* Get the face for ASCII, or unibyte. */
2206 = face_at_string_position (it
->w
,
2209 (it
->current
.overlay_string_index
>= 0
2212 it
->region_beg_charpos
,
2213 it
->region_end_charpos
,
2214 &next_check_charpos
,
2217 /* Correct the face for charsets different from ASCII. Do it
2218 for the multibyte case only. The face returned above is
2219 suitable for unibyte text if IT->string is unibyte. */
2220 if (STRING_MULTIBYTE (it
->string
))
2222 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
2223 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
2225 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2227 c
= string_char_and_length (p
, rest
, &len
);
2228 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2233 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2234 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2237 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2238 pos
= it
->current
.pos
;
2241 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2244 if (it
->what
== IT_COMPOSITION
)
2245 /* For composition, we must check the position after the
2247 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2249 INC_TEXT_POS (pos
, it
->multibyte_p
);
2251 /* Determine face for CHARSET_ASCII, or unibyte. */
2252 face_id
= face_at_buffer_position (it
->w
,
2254 it
->region_beg_charpos
,
2255 it
->region_end_charpos
,
2256 &next_check_charpos
,
2259 /* Correct the face for charsets different from ASCII. Do it
2260 for the multibyte case only. The face returned above is
2261 suitable for unibyte text if current_buffer is unibyte. */
2262 if (it
->multibyte_p
)
2264 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
2265 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2266 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2275 /***********************************************************************
2277 ***********************************************************************/
2279 /* Set up iterator IT from invisible properties at its current
2280 position. Called from handle_stop. */
2282 static enum prop_handled
2283 handle_invisible_prop (it
)
2286 enum prop_handled handled
= HANDLED_NORMALLY
;
2288 if (STRINGP (it
->string
))
2290 extern Lisp_Object Qinvisible
;
2291 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2293 /* Get the value of the invisible text property at the
2294 current position. Value will be nil if there is no such
2296 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2297 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2300 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2302 handled
= HANDLED_RECOMPUTE_PROPS
;
2304 /* Get the position at which the next change of the
2305 invisible text property can be found in IT->string.
2306 Value will be nil if the property value is the same for
2307 all the rest of IT->string. */
2308 XSETINT (limit
, XSTRING (it
->string
)->size
);
2309 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2312 /* Text at current position is invisible. The next
2313 change in the property is at position end_charpos.
2314 Move IT's current position to that position. */
2315 if (INTEGERP (end_charpos
)
2316 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2318 struct text_pos old
;
2319 old
= it
->current
.string_pos
;
2320 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2321 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2325 /* The rest of the string is invisible. If this is an
2326 overlay string, proceed with the next overlay string
2327 or whatever comes and return a character from there. */
2328 if (it
->current
.overlay_string_index
>= 0)
2330 next_overlay_string (it
);
2331 /* Don't check for overlay strings when we just
2332 finished processing them. */
2333 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2337 struct Lisp_String
*s
= XSTRING (it
->string
);
2338 IT_STRING_CHARPOS (*it
) = s
->size
;
2339 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2346 int visible_p
, newpos
, next_stop
;
2347 Lisp_Object pos
, prop
;
2349 /* First of all, is there invisible text at this position? */
2350 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2351 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2353 /* If we are on invisible text, skip over it. */
2354 if (TEXT_PROP_MEANS_INVISIBLE (prop
)
2355 && IT_CHARPOS (*it
) < it
->end_charpos
)
2357 /* Record whether we have to display an ellipsis for the
2359 int display_ellipsis_p
2360 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2362 handled
= HANDLED_RECOMPUTE_PROPS
;
2364 /* Loop skipping over invisible text. The loop is left at
2365 ZV or with IT on the first char being visible again. */
2368 /* Try to skip some invisible text. Return value is the
2369 position reached which can be equal to IT's position
2370 if there is nothing invisible here. This skips both
2371 over invisible text properties and overlays with
2372 invisible property. */
2373 newpos
= skip_invisible (IT_CHARPOS (*it
),
2374 &next_stop
, ZV
, it
->window
);
2376 /* If we skipped nothing at all we weren't at invisible
2377 text in the first place. If everything to the end of
2378 the buffer was skipped, end the loop. */
2379 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2383 /* We skipped some characters but not necessarily
2384 all there are. Check if we ended up on visible
2385 text. Fget_char_property returns the property of
2386 the char before the given position, i.e. if we
2387 get visible_p = 1, this means that the char at
2388 newpos is visible. */
2389 XSETFASTINT (pos
, newpos
);
2390 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2391 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2394 /* If we ended up on invisible text, proceed to
2395 skip starting with next_stop. */
2397 IT_CHARPOS (*it
) = next_stop
;
2401 /* The position newpos is now either ZV or on visible text. */
2402 IT_CHARPOS (*it
) = newpos
;
2403 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2405 /* Maybe return `...' next for the end of the invisible text. */
2406 if (display_ellipsis_p
)
2409 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2411 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2412 it
->dpvec
= v
->contents
;
2413 it
->dpend
= v
->contents
+ v
->size
;
2417 /* Default `...'. */
2418 it
->dpvec
= default_invis_vector
;
2419 it
->dpend
= default_invis_vector
+ 3;
2422 /* The ellipsis display does not replace the display of
2423 the character at the new position. Indicate this by
2424 setting IT->dpvec_char_len to zero. */
2425 it
->dpvec_char_len
= 0;
2427 it
->current
.dpvec_index
= 0;
2428 it
->method
= next_element_from_display_vector
;
2438 /***********************************************************************
2440 ***********************************************************************/
2442 /* Set up iterator IT from `display' property at its current position.
2443 Called from handle_stop. */
2445 static enum prop_handled
2446 handle_display_prop (it
)
2449 Lisp_Object prop
, object
;
2450 struct text_pos
*position
;
2451 int space_or_image_found_p
;
2453 if (STRINGP (it
->string
))
2455 object
= it
->string
;
2456 position
= &it
->current
.string_pos
;
2461 position
= &it
->current
.pos
;
2464 /* Reset those iterator values set from display property values. */
2465 it
->font_height
= Qnil
;
2466 it
->space_width
= Qnil
;
2469 /* We don't support recursive `display' properties, i.e. string
2470 values that have a string `display' property, that have a string
2471 `display' property etc. */
2472 if (!it
->string_from_display_prop_p
)
2473 it
->area
= TEXT_AREA
;
2475 prop
= Fget_char_property (make_number (position
->charpos
),
2478 return HANDLED_NORMALLY
;
2480 space_or_image_found_p
= 0;
2482 && CONSP (XCAR (prop
))
2483 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2485 /* A list of sub-properties. */
2486 while (CONSP (prop
))
2488 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2489 space_or_image_found_p
= 1;
2493 else if (VECTORP (prop
))
2496 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2497 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2499 space_or_image_found_p
= 1;
2503 if (handle_single_display_prop (it
, prop
, object
, position
))
2504 space_or_image_found_p
= 1;
2507 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2511 /* Value is the position of the end of the `display' property starting
2512 at START_POS in OBJECT. */
2514 static struct text_pos
2515 display_prop_end (it
, object
, start_pos
)
2518 struct text_pos start_pos
;
2521 struct text_pos end_pos
;
2523 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2524 Qdisplay
, object
, Qnil
);
2525 CHARPOS (end_pos
) = XFASTINT (end
);
2526 if (STRINGP (object
))
2527 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2529 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2535 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2536 is the object in which the `display' property was found. *POSITION
2537 is the position at which it was found.
2539 If PROP is a `space' or `image' sub-property, set *POSITION to the
2540 end position of the `display' property.
2542 Value is non-zero if a `space' or `image' property value was found. */
2545 handle_single_display_prop (it
, prop
, object
, position
)
2549 struct text_pos
*position
;
2552 int space_or_image_found_p
= 0;
2555 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2556 evaluated. If the result is nil, VALUE is ignored. */
2558 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2567 if (!NILP (form
) && !EQ (form
, Qt
))
2569 struct gcpro gcpro1
;
2570 struct text_pos end_pos
, pt
;
2573 end_pos
= display_prop_end (it
, object
, *position
);
2575 /* Temporarily set point to the end position, and then evaluate
2576 the form. This makes `(eolp)' work as FORM. */
2577 if (BUFFERP (object
))
2580 BYTEPOS (pt
) = PT_BYTE
;
2581 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2584 form
= safe_eval (form
);
2586 if (BUFFERP (object
))
2587 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2595 && EQ (XCAR (prop
), Qheight
)
2596 && CONSP (XCDR (prop
)))
2598 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2601 /* `(height HEIGHT)'. */
2602 it
->font_height
= XCAR (XCDR (prop
));
2603 if (!NILP (it
->font_height
))
2605 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2606 int new_height
= -1;
2608 if (CONSP (it
->font_height
)
2609 && (EQ (XCAR (it
->font_height
), Qplus
)
2610 || EQ (XCAR (it
->font_height
), Qminus
))
2611 && CONSP (XCDR (it
->font_height
))
2612 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2614 /* `(+ N)' or `(- N)' where N is an integer. */
2615 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2616 if (EQ (XCAR (it
->font_height
), Qplus
))
2618 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2620 else if (FUNCTIONP (it
->font_height
))
2622 /* Call function with current height as argument.
2623 Value is the new height. */
2625 height
= safe_call1 (it
->font_height
,
2626 face
->lface
[LFACE_HEIGHT_INDEX
]);
2627 if (NUMBERP (height
))
2628 new_height
= XFLOATINT (height
);
2630 else if (NUMBERP (it
->font_height
))
2632 /* Value is a multiple of the canonical char height. */
2635 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2636 new_height
= (XFLOATINT (it
->font_height
)
2637 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2641 /* Evaluate IT->font_height with `height' bound to the
2642 current specified height to get the new height. */
2644 int count
= specpdl_ptr
- specpdl
;
2646 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2647 value
= safe_eval (it
->font_height
);
2648 unbind_to (count
, Qnil
);
2650 if (NUMBERP (value
))
2651 new_height
= XFLOATINT (value
);
2655 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2658 else if (CONSP (prop
)
2659 && EQ (XCAR (prop
), Qspace_width
)
2660 && CONSP (XCDR (prop
)))
2662 /* `(space_width WIDTH)'. */
2663 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2666 value
= XCAR (XCDR (prop
));
2667 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2668 it
->space_width
= value
;
2670 else if (CONSP (prop
)
2671 && EQ (XCAR (prop
), Qraise
)
2672 && CONSP (XCDR (prop
)))
2674 /* `(raise FACTOR)'. */
2675 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2678 #ifdef HAVE_WINDOW_SYSTEM
2679 value
= XCAR (XCDR (prop
));
2680 if (NUMBERP (value
))
2682 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2683 it
->voffset
= - (XFLOATINT (value
)
2684 * (FONT_HEIGHT (face
->font
)));
2686 #endif /* HAVE_WINDOW_SYSTEM */
2688 else if (!it
->string_from_display_prop_p
)
2690 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2691 VALUE) or `((margin nil) VALUE)' or VALUE. */
2692 Lisp_Object location
, value
;
2693 struct text_pos start_pos
;
2696 /* Characters having this form of property are not displayed, so
2697 we have to find the end of the property. */
2698 start_pos
= *position
;
2699 *position
= display_prop_end (it
, object
, start_pos
);
2702 /* Let's stop at the new position and assume that all
2703 text properties change there. */
2704 it
->stop_charpos
= position
->charpos
;
2706 location
= Qunbound
;
2707 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2711 value
= XCDR (prop
);
2713 value
= XCAR (value
);
2716 if (EQ (XCAR (tem
), Qmargin
)
2717 && (tem
= XCDR (tem
),
2718 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2720 || EQ (tem
, Qleft_margin
)
2721 || EQ (tem
, Qright_margin
))))
2725 if (EQ (location
, Qunbound
))
2731 #ifdef HAVE_WINDOW_SYSTEM
2732 if (FRAME_TERMCAP_P (it
->f
))
2733 valid_p
= STRINGP (value
);
2735 valid_p
= (STRINGP (value
)
2736 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2737 || valid_image_p (value
));
2738 #else /* not HAVE_WINDOW_SYSTEM */
2739 valid_p
= STRINGP (value
);
2740 #endif /* not HAVE_WINDOW_SYSTEM */
2742 if ((EQ (location
, Qleft_margin
)
2743 || EQ (location
, Qright_margin
)
2747 space_or_image_found_p
= 1;
2749 /* Save current settings of IT so that we can restore them
2750 when we are finished with the glyph property value. */
2753 if (NILP (location
))
2754 it
->area
= TEXT_AREA
;
2755 else if (EQ (location
, Qleft_margin
))
2756 it
->area
= LEFT_MARGIN_AREA
;
2758 it
->area
= RIGHT_MARGIN_AREA
;
2760 if (STRINGP (value
))
2763 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2764 it
->current
.overlay_string_index
= -1;
2765 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2766 it
->end_charpos
= it
->string_nchars
2767 = XSTRING (it
->string
)->size
;
2768 it
->method
= next_element_from_string
;
2769 it
->stop_charpos
= 0;
2770 it
->string_from_display_prop_p
= 1;
2772 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2774 it
->method
= next_element_from_stretch
;
2776 it
->current
.pos
= it
->position
= start_pos
;
2778 #ifdef HAVE_WINDOW_SYSTEM
2781 it
->what
= IT_IMAGE
;
2782 it
->image_id
= lookup_image (it
->f
, value
);
2783 it
->position
= start_pos
;
2784 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2785 it
->method
= next_element_from_image
;
2787 /* Say that we haven't consumed the characters with
2788 `display' property yet. The call to pop_it in
2789 set_iterator_to_next will clean this up. */
2790 *position
= start_pos
;
2792 #endif /* HAVE_WINDOW_SYSTEM */
2795 /* Invalid property or property not supported. Restore
2796 the position to what it was before. */
2797 *position
= start_pos
;
2800 return space_or_image_found_p
;
2804 /* Check if PROP is a display sub-property value whose text should be
2805 treated as intangible. */
2808 single_display_prop_intangible_p (prop
)
2811 /* Skip over `when FORM'. */
2812 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2823 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
2824 we don't need to treat text as intangible. */
2825 if (EQ (XCAR (prop
), Qmargin
))
2833 || EQ (XCAR (prop
), Qleft_margin
)
2834 || EQ (XCAR (prop
), Qright_margin
))
2838 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
2842 /* Check if PROP is a display property value whose text should be
2843 treated as intangible. */
2846 display_prop_intangible_p (prop
)
2850 && CONSP (XCAR (prop
))
2851 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2853 /* A list of sub-properties. */
2854 while (CONSP (prop
))
2856 if (single_display_prop_intangible_p (XCAR (prop
)))
2861 else if (VECTORP (prop
))
2863 /* A vector of sub-properties. */
2865 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2866 if (single_display_prop_intangible_p (XVECTOR (prop
)->contents
[i
]))
2870 return single_display_prop_intangible_p (prop
);
2876 /***********************************************************************
2877 `composition' property
2878 ***********************************************************************/
2880 /* Set up iterator IT from `composition' property at its current
2881 position. Called from handle_stop. */
2883 static enum prop_handled
2884 handle_composition_prop (it
)
2887 Lisp_Object prop
, string
;
2888 int pos
, pos_byte
, end
;
2889 enum prop_handled handled
= HANDLED_NORMALLY
;
2891 if (STRINGP (it
->string
))
2893 pos
= IT_STRING_CHARPOS (*it
);
2894 pos_byte
= IT_STRING_BYTEPOS (*it
);
2895 string
= it
->string
;
2899 pos
= IT_CHARPOS (*it
);
2900 pos_byte
= IT_BYTEPOS (*it
);
2904 /* If there's a valid composition and point is not inside of the
2905 composition (in the case that the composition is from the current
2906 buffer), draw a glyph composed from the composition components. */
2907 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2908 && COMPOSITION_VALID_P (pos
, end
, prop
)
2909 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2911 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2915 it
->method
= next_element_from_composition
;
2917 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2918 /* For a terminal, draw only the first character of the
2920 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2921 it
->len
= (STRINGP (it
->string
)
2922 ? string_char_to_byte (it
->string
, end
)
2923 : CHAR_TO_BYTE (end
)) - pos_byte
;
2924 it
->stop_charpos
= end
;
2925 handled
= HANDLED_RETURN
;
2934 /***********************************************************************
2936 ***********************************************************************/
2938 /* The following structure is used to record overlay strings for
2939 later sorting in load_overlay_strings. */
2941 struct overlay_entry
2943 Lisp_Object overlay
;
2950 /* Set up iterator IT from overlay strings at its current position.
2951 Called from handle_stop. */
2953 static enum prop_handled
2954 handle_overlay_change (it
)
2957 if (!STRINGP (it
->string
) && get_overlay_strings (it
))
2958 return HANDLED_RECOMPUTE_PROPS
;
2960 return HANDLED_NORMALLY
;
2964 /* Set up the next overlay string for delivery by IT, if there is an
2965 overlay string to deliver. Called by set_iterator_to_next when the
2966 end of the current overlay string is reached. If there are more
2967 overlay strings to display, IT->string and
2968 IT->current.overlay_string_index are set appropriately here.
2969 Otherwise IT->string is set to nil. */
2972 next_overlay_string (it
)
2975 ++it
->current
.overlay_string_index
;
2976 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2978 /* No more overlay strings. Restore IT's settings to what
2979 they were before overlay strings were processed, and
2980 continue to deliver from current_buffer. */
2982 xassert (it
->stop_charpos
>= BEGV
2983 && it
->stop_charpos
<= it
->end_charpos
);
2985 it
->current
.overlay_string_index
= -1;
2986 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2987 it
->n_overlay_strings
= 0;
2988 it
->method
= next_element_from_buffer
;
2990 /* If we're at the end of the buffer, record that we have
2991 processed the overlay strings there already, so that
2992 next_element_from_buffer doesn't try it again. */
2993 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
2994 it
->overlay_strings_at_end_processed_p
= 1;
2998 /* There are more overlay strings to process. If
2999 IT->current.overlay_string_index has advanced to a position
3000 where we must load IT->overlay_strings with more strings, do
3002 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3004 if (it
->current
.overlay_string_index
&& i
== 0)
3005 load_overlay_strings (it
);
3007 /* Initialize IT to deliver display elements from the overlay
3009 it
->string
= it
->overlay_strings
[i
];
3010 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3011 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3012 it
->method
= next_element_from_string
;
3013 it
->stop_charpos
= 0;
3020 /* Compare two overlay_entry structures E1 and E2. Used as a
3021 comparison function for qsort in load_overlay_strings. Overlay
3022 strings for the same position are sorted so that
3024 1. All after-strings come in front of before-strings, except
3025 when they come from the same overlay.
3027 2. Within after-strings, strings are sorted so that overlay strings
3028 from overlays with higher priorities come first.
3030 2. Within before-strings, strings are sorted so that overlay
3031 strings from overlays with higher priorities come last.
3033 Value is analogous to strcmp. */
3037 compare_overlay_entries (e1
, e2
)
3040 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3041 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3044 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3046 /* Let after-strings appear in front of before-strings if
3047 they come from different overlays. */
3048 if (EQ (entry1
->overlay
, entry2
->overlay
))
3049 result
= entry1
->after_string_p
? 1 : -1;
3051 result
= entry1
->after_string_p
? -1 : 1;
3053 else if (entry1
->after_string_p
)
3054 /* After-strings sorted in order of decreasing priority. */
3055 result
= entry2
->priority
- entry1
->priority
;
3057 /* Before-strings sorted in order of increasing priority. */
3058 result
= entry1
->priority
- entry2
->priority
;
3064 /* Load the vector IT->overlay_strings with overlay strings from IT's
3065 current buffer position. Set IT->n_overlays to the total number of
3066 overlay strings found.
3068 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3069 a time. On entry into load_overlay_strings,
3070 IT->current.overlay_string_index gives the number of overlay
3071 strings that have already been loaded by previous calls to this
3074 IT->add_overlay_start contains an additional overlay start
3075 position to consider for taking overlay strings from, if non-zero.
3076 This position comes into play when the overlay has an `invisible'
3077 property, and both before and after-strings. When we've skipped to
3078 the end of the overlay, because of its `invisible' property, we
3079 nevertheless want its before-string to appear.
3080 IT->add_overlay_start will contain the overlay start position
3083 Overlay strings are sorted so that after-string strings come in
3084 front of before-string strings. Within before and after-strings,
3085 strings are sorted by overlay priority. See also function
3086 compare_overlay_entries. */
3089 load_overlay_strings (it
)
3092 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3093 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3096 int n
= 0, i
, j
, invis_p
;
3097 struct overlay_entry
*entries
3098 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3099 int charpos
= IT_CHARPOS (*it
);
3101 /* Append the overlay string STRING of overlay OVERLAY to vector
3102 `entries' which has size `size' and currently contains `n'
3103 elements. AFTER_P non-zero means STRING is an after-string of
3105 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3108 Lisp_Object priority; \
3112 int new_size = 2 * size; \
3113 struct overlay_entry *old = entries; \
3115 (struct overlay_entry *) alloca (new_size \
3116 * sizeof *entries); \
3117 bcopy (old, entries, size * sizeof *entries); \
3121 entries[n].string = (STRING); \
3122 entries[n].overlay = (OVERLAY); \
3123 priority = Foverlay_get ((OVERLAY), Qpriority); \
3124 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3125 entries[n].after_string_p = (AFTER_P); \
3130 /* Process overlay before the overlay center. */
3131 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3133 overlay
= XCAR (ov
);
3134 xassert (OVERLAYP (overlay
));
3135 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3136 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3141 /* Skip this overlay if it doesn't start or end at IT's current
3143 if (end
!= charpos
&& start
!= charpos
)
3146 /* Skip this overlay if it doesn't apply to IT->w. */
3147 window
= Foverlay_get (overlay
, Qwindow
);
3148 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3151 /* If the text ``under'' the overlay is invisible, both before-
3152 and after-strings from this overlay are visible; start and
3153 end position are indistinguishable. */
3154 invisible
= Foverlay_get (overlay
, Qinvisible
);
3155 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3157 /* If overlay has a non-empty before-string, record it. */
3158 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3159 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3160 && XSTRING (str
)->size
)
3161 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3163 /* If overlay has a non-empty after-string, record it. */
3164 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3165 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3166 && XSTRING (str
)->size
)
3167 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3170 /* Process overlays after the overlay center. */
3171 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3173 overlay
= XCAR (ov
);
3174 xassert (OVERLAYP (overlay
));
3175 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3176 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3178 if (start
> charpos
)
3181 /* Skip this overlay if it doesn't start or end at IT's current
3183 if (end
!= charpos
&& start
!= charpos
)
3186 /* Skip this overlay if it doesn't apply to IT->w. */
3187 window
= Foverlay_get (overlay
, Qwindow
);
3188 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3191 /* If the text ``under'' the overlay is invisible, it has a zero
3192 dimension, and both before- and after-strings apply. */
3193 invisible
= Foverlay_get (overlay
, Qinvisible
);
3194 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3196 /* If overlay has a non-empty before-string, record it. */
3197 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3198 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3199 && XSTRING (str
)->size
)
3200 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3202 /* If overlay has a non-empty after-string, record it. */
3203 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3204 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3205 && XSTRING (str
)->size
)
3206 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3209 #undef RECORD_OVERLAY_STRING
3213 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3215 /* Record the total number of strings to process. */
3216 it
->n_overlay_strings
= n
;
3218 /* IT->current.overlay_string_index is the number of overlay strings
3219 that have already been consumed by IT. Copy some of the
3220 remaining overlay strings to IT->overlay_strings. */
3222 j
= it
->current
.overlay_string_index
;
3223 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3224 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3230 /* Get the first chunk of overlay strings at IT's current buffer
3231 position. Value is non-zero if at least one overlay string was
3235 get_overlay_strings (it
)
3238 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3239 process. This fills IT->overlay_strings with strings, and sets
3240 IT->n_overlay_strings to the total number of strings to process.
3241 IT->pos.overlay_string_index has to be set temporarily to zero
3242 because load_overlay_strings needs this; it must be set to -1
3243 when no overlay strings are found because a zero value would
3244 indicate a position in the first overlay string. */
3245 it
->current
.overlay_string_index
= 0;
3246 load_overlay_strings (it
);
3248 /* If we found overlay strings, set up IT to deliver display
3249 elements from the first one. Otherwise set up IT to deliver
3250 from current_buffer. */
3251 if (it
->n_overlay_strings
)
3253 /* Make sure we know settings in current_buffer, so that we can
3254 restore meaningful values when we're done with the overlay
3256 compute_stop_pos (it
);
3257 xassert (it
->face_id
>= 0);
3259 /* Save IT's settings. They are restored after all overlay
3260 strings have been processed. */
3261 xassert (it
->sp
== 0);
3264 /* Set up IT to deliver display elements from the first overlay
3266 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3267 it
->stop_charpos
= 0;
3268 it
->string
= it
->overlay_strings
[0];
3269 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3270 xassert (STRINGP (it
->string
));
3271 it
->method
= next_element_from_string
;
3276 it
->current
.overlay_string_index
= -1;
3277 it
->method
= next_element_from_buffer
;
3282 /* Value is non-zero if we found at least one overlay string. */
3283 return STRINGP (it
->string
);
3288 /***********************************************************************
3289 Saving and restoring state
3290 ***********************************************************************/
3292 /* Save current settings of IT on IT->stack. Called, for example,
3293 before setting up IT for an overlay string, to be able to restore
3294 IT's settings to what they were after the overlay string has been
3301 struct iterator_stack_entry
*p
;
3303 xassert (it
->sp
< 2);
3304 p
= it
->stack
+ it
->sp
;
3306 p
->stop_charpos
= it
->stop_charpos
;
3307 xassert (it
->face_id
>= 0);
3308 p
->face_id
= it
->face_id
;
3309 p
->string
= it
->string
;
3310 p
->pos
= it
->current
;
3311 p
->end_charpos
= it
->end_charpos
;
3312 p
->string_nchars
= it
->string_nchars
;
3314 p
->multibyte_p
= it
->multibyte_p
;
3315 p
->space_width
= it
->space_width
;
3316 p
->font_height
= it
->font_height
;
3317 p
->voffset
= it
->voffset
;
3318 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3323 /* Restore IT's settings from IT->stack. Called, for example, when no
3324 more overlay strings must be processed, and we return to delivering
3325 display elements from a buffer, or when the end of a string from a
3326 `display' property is reached and we return to delivering display
3327 elements from an overlay string, or from a buffer. */
3333 struct iterator_stack_entry
*p
;
3335 xassert (it
->sp
> 0);
3337 p
= it
->stack
+ it
->sp
;
3338 it
->stop_charpos
= p
->stop_charpos
;
3339 it
->face_id
= p
->face_id
;
3340 it
->string
= p
->string
;
3341 it
->current
= p
->pos
;
3342 it
->end_charpos
= p
->end_charpos
;
3343 it
->string_nchars
= p
->string_nchars
;
3345 it
->multibyte_p
= p
->multibyte_p
;
3346 it
->space_width
= p
->space_width
;
3347 it
->font_height
= p
->font_height
;
3348 it
->voffset
= p
->voffset
;
3349 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3354 /***********************************************************************
3356 ***********************************************************************/
3358 /* Set IT's current position to the previous line start. */
3361 back_to_previous_line_start (it
)
3364 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3365 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3369 /* Move IT to the next line start.
3371 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3372 we skipped over part of the text (as opposed to moving the iterator
3373 continuously over the text). Otherwise, don't change the value
3376 Newlines may come from buffer text, overlay strings, or strings
3377 displayed via the `display' property. That's the reason we can't
3378 simply use find_next_newline_no_quit. */
3381 forward_to_next_line_start (it
, skipped_p
)
3385 int old_selective
, newline_found_p
, n
;
3386 const int MAX_NEWLINE_DISTANCE
= 500;
3388 /* Don't handle selective display in the following. It's (a)
3389 unnecessary and (b) leads to an infinite recursion because
3390 next_element_from_ellipsis indirectly calls this function. */
3391 old_selective
= it
->selective
;
3394 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3395 from buffer text. */
3396 n
= newline_found_p
= 0;
3397 while (n
< MAX_NEWLINE_DISTANCE
3398 && get_next_display_element (it
)
3399 && !newline_found_p
)
3401 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3402 set_iterator_to_next (it
, 0);
3403 if (!STRINGP (it
->string
))
3407 /* If we didn't find a newline near enough, see if we can use a
3409 if (!newline_found_p
&& n
== MAX_NEWLINE_DISTANCE
)
3411 int start
= IT_CHARPOS (*it
);
3412 int limit
= find_next_newline_no_quit (start
, 1);
3415 xassert (!STRINGP (it
->string
));
3417 /* If there isn't any `display' property in sight, and no
3418 overlays, we can just use the position of the newline in
3420 if (it
->stop_charpos
>= limit
3421 || ((pos
= Fnext_single_property_change (make_number (start
),
3423 Qnil
, make_number (limit
)),
3425 && next_overlay_change (start
) == ZV
))
3427 IT_CHARPOS (*it
) = limit
;
3428 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3429 *skipped_p
= newline_found_p
= 1;
3433 while (get_next_display_element (it
)
3434 && !newline_found_p
)
3436 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3437 set_iterator_to_next (it
, 0);
3442 it
->selective
= old_selective
;
3443 return newline_found_p
;
3447 /* Set IT's current position to the previous visible line start. Skip
3448 invisible text that is so either due to text properties or due to
3449 selective display. Caution: this does not change IT->current_x and
3453 back_to_previous_visible_line_start (it
)
3458 /* Go back one newline if not on BEGV already. */
3459 if (IT_CHARPOS (*it
) > BEGV
)
3460 back_to_previous_line_start (it
);
3462 /* Move over lines that are invisible because of selective display
3463 or text properties. */
3464 while (IT_CHARPOS (*it
) > BEGV
3469 /* If selective > 0, then lines indented more than that values
3471 if (it
->selective
> 0
3472 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3479 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3480 Qinvisible
, it
->window
);
3481 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3485 /* Back one more newline if the current one is invisible. */
3487 back_to_previous_line_start (it
);
3490 xassert (IT_CHARPOS (*it
) >= BEGV
);
3491 xassert (IT_CHARPOS (*it
) == BEGV
3492 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3497 /* Reseat iterator IT at the previous visible line start. Skip
3498 invisible text that is so either due to text properties or due to
3499 selective display. At the end, update IT's overlay information,
3500 face information etc. */
3503 reseat_at_previous_visible_line_start (it
)
3506 back_to_previous_visible_line_start (it
);
3507 reseat (it
, it
->current
.pos
, 1);
3512 /* Reseat iterator IT on the next visible line start in the current
3513 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3514 preceding the line start. Skip over invisible text that is so
3515 because of selective display. Compute faces, overlays etc at the
3516 new position. Note that this function does not skip over text that
3517 is invisible because of text properties. */
3520 reseat_at_next_visible_line_start (it
, on_newline_p
)
3524 int newline_found_p
, skipped_p
= 0;
3526 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3528 /* Skip over lines that are invisible because they are indented
3529 more than the value of IT->selective. */
3530 if (it
->selective
> 0)
3531 while (IT_CHARPOS (*it
) < ZV
3532 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3534 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
3536 /* Position on the newline if that's what's requested. */
3537 if (on_newline_p
&& newline_found_p
)
3539 if (STRINGP (it
->string
))
3541 if (IT_STRING_CHARPOS (*it
) > 0)
3543 --IT_STRING_CHARPOS (*it
);
3544 --IT_STRING_BYTEPOS (*it
);
3547 else if (IT_CHARPOS (*it
) > BEGV
)
3551 reseat (it
, it
->current
.pos
, 0);
3555 reseat (it
, it
->current
.pos
, 0);
3562 /***********************************************************************
3563 Changing an iterator's position
3564 ***********************************************************************/
3566 /* Change IT's current position to POS in current_buffer. If FORCE_P
3567 is non-zero, always check for text properties at the new position.
3568 Otherwise, text properties are only looked up if POS >=
3569 IT->check_charpos of a property. */
3572 reseat (it
, pos
, force_p
)
3574 struct text_pos pos
;
3577 int original_pos
= IT_CHARPOS (*it
);
3579 reseat_1 (it
, pos
, 0);
3581 /* Determine where to check text properties. Avoid doing it
3582 where possible because text property lookup is very expensive. */
3584 || CHARPOS (pos
) > it
->stop_charpos
3585 || CHARPOS (pos
) < original_pos
)
3592 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3593 IT->stop_pos to POS, also. */
3596 reseat_1 (it
, pos
, set_stop_p
)
3598 struct text_pos pos
;
3601 /* Don't call this function when scanning a C string. */
3602 xassert (it
->s
== NULL
);
3604 /* POS must be a reasonable value. */
3605 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3607 it
->current
.pos
= it
->position
= pos
;
3608 XSETBUFFER (it
->object
, current_buffer
);
3610 it
->current
.dpvec_index
= -1;
3611 it
->current
.overlay_string_index
= -1;
3612 IT_STRING_CHARPOS (*it
) = -1;
3613 IT_STRING_BYTEPOS (*it
) = -1;
3615 it
->method
= next_element_from_buffer
;
3619 it
->stop_charpos
= CHARPOS (pos
);
3623 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3624 If S is non-null, it is a C string to iterate over. Otherwise,
3625 STRING gives a Lisp string to iterate over.
3627 If PRECISION > 0, don't return more then PRECISION number of
3628 characters from the string.
3630 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3631 characters have been returned. FIELD_WIDTH < 0 means an infinite
3634 MULTIBYTE = 0 means disable processing of multibyte characters,
3635 MULTIBYTE > 0 means enable it,
3636 MULTIBYTE < 0 means use IT->multibyte_p.
3638 IT must be initialized via a prior call to init_iterator before
3639 calling this function. */
3642 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3647 int precision
, field_width
, multibyte
;
3649 /* No region in strings. */
3650 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3652 /* No text property checks performed by default, but see below. */
3653 it
->stop_charpos
= -1;
3655 /* Set iterator position and end position. */
3656 bzero (&it
->current
, sizeof it
->current
);
3657 it
->current
.overlay_string_index
= -1;
3658 it
->current
.dpvec_index
= -1;
3659 xassert (charpos
>= 0);
3661 /* Use the setting of MULTIBYTE if specified. */
3663 it
->multibyte_p
= multibyte
> 0;
3667 xassert (STRINGP (string
));
3668 it
->string
= string
;
3670 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3671 it
->method
= next_element_from_string
;
3672 it
->current
.string_pos
= string_pos (charpos
, string
);
3679 /* Note that we use IT->current.pos, not it->current.string_pos,
3680 for displaying C strings. */
3681 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3682 if (it
->multibyte_p
)
3684 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3685 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3689 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3690 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3693 it
->method
= next_element_from_c_string
;
3696 /* PRECISION > 0 means don't return more than PRECISION characters
3698 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3699 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3701 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3702 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3703 FIELD_WIDTH < 0 means infinite field width. This is useful for
3704 padding with `-' at the end of a mode line. */
3705 if (field_width
< 0)
3706 field_width
= INFINITY
;
3707 if (field_width
> it
->end_charpos
- charpos
)
3708 it
->end_charpos
= charpos
+ field_width
;
3710 /* Use the standard display table for displaying strings. */
3711 if (DISP_TABLE_P (Vstandard_display_table
))
3712 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3714 it
->stop_charpos
= charpos
;
3720 /***********************************************************************
3722 ***********************************************************************/
3724 /* Load IT's display element fields with information about the next
3725 display element from the current position of IT. Value is zero if
3726 end of buffer (or C string) is reached. */
3729 get_next_display_element (it
)
3732 /* Non-zero means that we found an display element. Zero means that
3733 we hit the end of what we iterate over. Performance note: the
3734 function pointer `method' used here turns out to be faster than
3735 using a sequence of if-statements. */
3736 int success_p
= (*it
->method
) (it
);
3738 if (it
->what
== IT_CHARACTER
)
3740 /* Map via display table or translate control characters.
3741 IT->c, IT->len etc. have been set to the next character by
3742 the function call above. If we have a display table, and it
3743 contains an entry for IT->c, translate it. Don't do this if
3744 IT->c itself comes from a display table, otherwise we could
3745 end up in an infinite recursion. (An alternative could be to
3746 count the recursion depth of this function and signal an
3747 error when a certain maximum depth is reached.) Is it worth
3749 if (success_p
&& it
->dpvec
== NULL
)
3754 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3757 struct Lisp_Vector
*v
= XVECTOR (dv
);
3759 /* Return the first character from the display table
3760 entry, if not empty. If empty, don't display the
3761 current character. */
3764 it
->dpvec_char_len
= it
->len
;
3765 it
->dpvec
= v
->contents
;
3766 it
->dpend
= v
->contents
+ v
->size
;
3767 it
->current
.dpvec_index
= 0;
3768 it
->method
= next_element_from_display_vector
;
3771 success_p
= get_next_display_element (it
);
3774 /* Translate control characters into `\003' or `^C' form.
3775 Control characters coming from a display table entry are
3776 currently not translated because we use IT->dpvec to hold
3777 the translation. This could easily be changed but I
3778 don't believe that it is worth doing.
3780 Non-printable multibyte characters are also translated
3782 else if ((it
->c
< ' '
3783 && (it
->area
!= TEXT_AREA
3784 || (it
->c
!= '\n' && it
->c
!= '\t')))
3787 || !CHAR_PRINTABLE_P (it
->c
))
3789 /* IT->c is a control character which must be displayed
3790 either as '\003' or as `^C' where the '\\' and '^'
3791 can be defined in the display table. Fill
3792 IT->ctl_chars with glyphs for what we have to
3793 display. Then, set IT->dpvec to these glyphs. */
3796 if (it
->c
< 128 && it
->ctl_arrow_p
)
3798 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3800 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3801 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3802 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3804 g
= FAST_MAKE_GLYPH ('^', 0);
3805 XSETINT (it
->ctl_chars
[0], g
);
3807 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3808 XSETINT (it
->ctl_chars
[1], g
);
3810 /* Set up IT->dpvec and return first character from it. */
3811 it
->dpvec_char_len
= it
->len
;
3812 it
->dpvec
= it
->ctl_chars
;
3813 it
->dpend
= it
->dpvec
+ 2;
3814 it
->current
.dpvec_index
= 0;
3815 it
->method
= next_element_from_display_vector
;
3816 get_next_display_element (it
);
3820 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3825 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3827 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3828 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3829 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3831 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3833 if (SINGLE_BYTE_CHAR_P (it
->c
))
3834 str
[0] = it
->c
, len
= 1;
3836 len
= CHAR_STRING (it
->c
, str
);
3838 for (i
= 0; i
< len
; i
++)
3840 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3841 /* Insert three more glyphs into IT->ctl_chars for
3842 the octal display of the character. */
3843 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3844 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3845 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3846 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3847 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3848 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3851 /* Set up IT->dpvec and return the first character
3853 it
->dpvec_char_len
= it
->len
;
3854 it
->dpvec
= it
->ctl_chars
;
3855 it
->dpend
= it
->dpvec
+ len
* 4;
3856 it
->current
.dpvec_index
= 0;
3857 it
->method
= next_element_from_display_vector
;
3858 get_next_display_element (it
);
3863 /* Adjust face id for a multibyte character. There are no
3864 multibyte character in unibyte text. */
3867 && FRAME_WINDOW_P (it
->f
))
3869 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3870 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3874 /* Is this character the last one of a run of characters with
3875 box? If yes, set IT->end_of_box_run_p to 1. */
3882 it
->end_of_box_run_p
3883 = ((face_id
= face_after_it_pos (it
),
3884 face_id
!= it
->face_id
)
3885 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3886 face
->box
== FACE_NO_BOX
));
3889 /* Value is 0 if end of buffer or string reached. */
3894 /* Move IT to the next display element.
3896 RESEAT_P non-zero means if called on a newline in buffer text,
3897 skip to the next visible line start.
3899 Functions get_next_display_element and set_iterator_to_next are
3900 separate because I find this arrangement easier to handle than a
3901 get_next_display_element function that also increments IT's
3902 position. The way it is we can first look at an iterator's current
3903 display element, decide whether it fits on a line, and if it does,
3904 increment the iterator position. The other way around we probably
3905 would either need a flag indicating whether the iterator has to be
3906 incremented the next time, or we would have to implement a
3907 decrement position function which would not be easy to write. */
3910 set_iterator_to_next (it
, reseat_p
)
3914 /* Reset flags indicating start and end of a sequence of characters
3915 with box. Reset them at the start of this function because
3916 moving the iterator to a new position might set them. */
3917 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3919 if (it
->method
== next_element_from_buffer
)
3921 /* The current display element of IT is a character from
3922 current_buffer. Advance in the buffer, and maybe skip over
3923 invisible lines that are so because of selective display. */
3924 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
3925 reseat_at_next_visible_line_start (it
, 0);
3928 xassert (it
->len
!= 0);
3929 IT_BYTEPOS (*it
) += it
->len
;
3930 IT_CHARPOS (*it
) += 1;
3931 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3934 else if (it
->method
== next_element_from_composition
)
3936 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3937 if (STRINGP (it
->string
))
3939 IT_STRING_BYTEPOS (*it
) += it
->len
;
3940 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3941 it
->method
= next_element_from_string
;
3942 goto consider_string_end
;
3946 IT_BYTEPOS (*it
) += it
->len
;
3947 IT_CHARPOS (*it
) += it
->cmp_len
;
3948 it
->method
= next_element_from_buffer
;
3951 else if (it
->method
== next_element_from_c_string
)
3953 /* Current display element of IT is from a C string. */
3954 IT_BYTEPOS (*it
) += it
->len
;
3955 IT_CHARPOS (*it
) += 1;
3957 else if (it
->method
== next_element_from_display_vector
)
3959 /* Current display element of IT is from a display table entry.
3960 Advance in the display table definition. Reset it to null if
3961 end reached, and continue with characters from buffers/
3963 ++it
->current
.dpvec_index
;
3965 /* Restore face of the iterator to what they were before the
3966 display vector entry (these entries may contain faces). */
3967 it
->face_id
= it
->saved_face_id
;
3969 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3972 it
->method
= next_element_from_c_string
;
3973 else if (STRINGP (it
->string
))
3974 it
->method
= next_element_from_string
;
3976 it
->method
= next_element_from_buffer
;
3979 it
->current
.dpvec_index
= -1;
3981 /* Skip over characters which were displayed via IT->dpvec. */
3982 if (it
->dpvec_char_len
< 0)
3983 reseat_at_next_visible_line_start (it
, 1);
3984 else if (it
->dpvec_char_len
> 0)
3986 it
->len
= it
->dpvec_char_len
;
3987 set_iterator_to_next (it
, reseat_p
);
3991 else if (it
->method
== next_element_from_string
)
3993 /* Current display element is a character from a Lisp string. */
3994 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3995 IT_STRING_BYTEPOS (*it
) += it
->len
;
3996 IT_STRING_CHARPOS (*it
) += 1;
3998 consider_string_end
:
4000 if (it
->current
.overlay_string_index
>= 0)
4002 /* IT->string is an overlay string. Advance to the
4003 next, if there is one. */
4004 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4005 next_overlay_string (it
);
4009 /* IT->string is not an overlay string. If we reached
4010 its end, and there is something on IT->stack, proceed
4011 with what is on the stack. This can be either another
4012 string, this time an overlay string, or a buffer. */
4013 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
4017 if (!STRINGP (it
->string
))
4018 it
->method
= next_element_from_buffer
;
4022 else if (it
->method
== next_element_from_image
4023 || it
->method
== next_element_from_stretch
)
4025 /* The position etc with which we have to proceed are on
4026 the stack. The position may be at the end of a string,
4027 if the `display' property takes up the whole string. */
4030 if (STRINGP (it
->string
))
4032 it
->method
= next_element_from_string
;
4033 goto consider_string_end
;
4036 it
->method
= next_element_from_buffer
;
4039 /* There are no other methods defined, so this should be a bug. */
4042 xassert (it
->method
!= next_element_from_string
4043 || (STRINGP (it
->string
)
4044 && IT_STRING_CHARPOS (*it
) >= 0));
4048 /* Load IT's display element fields with information about the next
4049 display element which comes from a display table entry or from the
4050 result of translating a control character to one of the forms `^C'
4051 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4054 next_element_from_display_vector (it
)
4058 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4060 /* Remember the current face id in case glyphs specify faces.
4061 IT's face is restored in set_iterator_to_next. */
4062 it
->saved_face_id
= it
->face_id
;
4064 if (INTEGERP (*it
->dpvec
)
4065 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4070 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4071 it
->c
= FAST_GLYPH_CHAR (g
);
4072 it
->len
= CHAR_BYTES (it
->c
);
4074 /* The entry may contain a face id to use. Such a face id is
4075 the id of a Lisp face, not a realized face. A face id of
4076 zero means no face is specified. */
4077 lface_id
= FAST_GLYPH_FACE (g
);
4080 /* The function returns -1 if lface_id is invalid. */
4081 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4083 it
->face_id
= face_id
;
4087 /* Display table entry is invalid. Return a space. */
4088 it
->c
= ' ', it
->len
= 1;
4090 /* Don't change position and object of the iterator here. They are
4091 still the values of the character that had this display table
4092 entry or was translated, and that's what we want. */
4093 it
->what
= IT_CHARACTER
;
4098 /* Load IT with the next display element from Lisp string IT->string.
4099 IT->current.string_pos is the current position within the string.
4100 If IT->current.overlay_string_index >= 0, the Lisp string is an
4104 next_element_from_string (it
)
4107 struct text_pos position
;
4109 xassert (STRINGP (it
->string
));
4110 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4111 position
= it
->current
.string_pos
;
4113 /* Time to check for invisible text? */
4114 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4115 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4119 /* Since a handler may have changed IT->method, we must
4121 return get_next_display_element (it
);
4124 if (it
->current
.overlay_string_index
>= 0)
4126 /* Get the next character from an overlay string. In overlay
4127 strings, There is no field width or padding with spaces to
4129 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
4134 else if (STRING_MULTIBYTE (it
->string
))
4136 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
4137 - IT_STRING_BYTEPOS (*it
));
4138 unsigned char *s
= (XSTRING (it
->string
)->data
4139 + IT_STRING_BYTEPOS (*it
));
4140 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4144 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4150 /* Get the next character from a Lisp string that is not an
4151 overlay string. Such strings come from the mode line, for
4152 example. We may have to pad with spaces, or truncate the
4153 string. See also next_element_from_c_string. */
4154 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4159 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4161 /* Pad with spaces. */
4162 it
->c
= ' ', it
->len
= 1;
4163 CHARPOS (position
) = BYTEPOS (position
) = -1;
4165 else if (STRING_MULTIBYTE (it
->string
))
4167 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
4168 - IT_STRING_BYTEPOS (*it
));
4169 unsigned char *s
= (XSTRING (it
->string
)->data
4170 + IT_STRING_BYTEPOS (*it
));
4171 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4175 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
4180 /* Record what we have and where it came from. Note that we store a
4181 buffer position in IT->position although it could arguably be a
4183 it
->what
= IT_CHARACTER
;
4184 it
->object
= it
->string
;
4185 it
->position
= position
;
4190 /* Load IT with next display element from C string IT->s.
4191 IT->string_nchars is the maximum number of characters to return
4192 from the string. IT->end_charpos may be greater than
4193 IT->string_nchars when this function is called, in which case we
4194 may have to return padding spaces. Value is zero if end of string
4195 reached, including padding spaces. */
4198 next_element_from_c_string (it
)
4204 it
->what
= IT_CHARACTER
;
4205 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4208 /* IT's position can be greater IT->string_nchars in case a field
4209 width or precision has been specified when the iterator was
4211 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4213 /* End of the game. */
4217 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4219 /* Pad with spaces. */
4220 it
->c
= ' ', it
->len
= 1;
4221 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4223 else if (it
->multibyte_p
)
4225 /* Implementation note: The calls to strlen apparently aren't a
4226 performance problem because there is no noticeable performance
4227 difference between Emacs running in unibyte or multibyte mode. */
4228 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4229 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4233 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4239 /* Set up IT to return characters from an ellipsis, if appropriate.
4240 The definition of the ellipsis glyphs may come from a display table
4241 entry. This function Fills IT with the first glyph from the
4242 ellipsis if an ellipsis is to be displayed. */
4245 next_element_from_ellipsis (it
)
4248 if (it
->selective_display_ellipsis_p
)
4250 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4252 /* Use the display table definition for `...'. Invalid glyphs
4253 will be handled by the method returning elements from dpvec. */
4254 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4255 it
->dpvec_char_len
= it
->len
;
4256 it
->dpvec
= v
->contents
;
4257 it
->dpend
= v
->contents
+ v
->size
;
4258 it
->current
.dpvec_index
= 0;
4259 it
->method
= next_element_from_display_vector
;
4263 /* Use default `...' which is stored in default_invis_vector. */
4264 it
->dpvec_char_len
= it
->len
;
4265 it
->dpvec
= default_invis_vector
;
4266 it
->dpend
= default_invis_vector
+ 3;
4267 it
->current
.dpvec_index
= 0;
4268 it
->method
= next_element_from_display_vector
;
4273 it
->method
= next_element_from_buffer
;
4274 reseat_at_next_visible_line_start (it
, 1);
4277 return get_next_display_element (it
);
4281 /* Deliver an image display element. The iterator IT is already
4282 filled with image information (done in handle_display_prop). Value
4287 next_element_from_image (it
)
4290 it
->what
= IT_IMAGE
;
4295 /* Fill iterator IT with next display element from a stretch glyph
4296 property. IT->object is the value of the text property. Value is
4300 next_element_from_stretch (it
)
4303 it
->what
= IT_STRETCH
;
4308 /* Load IT with the next display element from current_buffer. Value
4309 is zero if end of buffer reached. IT->stop_charpos is the next
4310 position at which to stop and check for text properties or buffer
4314 next_element_from_buffer (it
)
4319 /* Check this assumption, otherwise, we would never enter the
4320 if-statement, below. */
4321 xassert (IT_CHARPOS (*it
) >= BEGV
4322 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4324 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4326 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4328 int overlay_strings_follow_p
;
4330 /* End of the game, except when overlay strings follow that
4331 haven't been returned yet. */
4332 if (it
->overlay_strings_at_end_processed_p
)
4333 overlay_strings_follow_p
= 0;
4336 it
->overlay_strings_at_end_processed_p
= 1;
4337 overlay_strings_follow_p
= get_overlay_strings (it
);
4340 if (overlay_strings_follow_p
)
4341 success_p
= get_next_display_element (it
);
4345 it
->position
= it
->current
.pos
;
4352 return get_next_display_element (it
);
4357 /* No face changes, overlays etc. in sight, so just return a
4358 character from current_buffer. */
4361 /* Maybe run the redisplay end trigger hook. Performance note:
4362 This doesn't seem to cost measurable time. */
4363 if (it
->redisplay_end_trigger_charpos
4365 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4366 run_redisplay_end_trigger_hook (it
);
4368 /* Get the next character, maybe multibyte. */
4369 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4370 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4372 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4373 - IT_BYTEPOS (*it
));
4374 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4377 it
->c
= *p
, it
->len
= 1;
4379 /* Record what we have and where it came from. */
4380 it
->what
= IT_CHARACTER
;;
4381 it
->object
= it
->w
->buffer
;
4382 it
->position
= it
->current
.pos
;
4384 /* Normally we return the character found above, except when we
4385 really want to return an ellipsis for selective display. */
4390 /* A value of selective > 0 means hide lines indented more
4391 than that number of columns. */
4392 if (it
->selective
> 0
4393 && IT_CHARPOS (*it
) + 1 < ZV
4394 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4395 IT_BYTEPOS (*it
) + 1,
4398 success_p
= next_element_from_ellipsis (it
);
4399 it
->dpvec_char_len
= -1;
4402 else if (it
->c
== '\r' && it
->selective
== -1)
4404 /* A value of selective == -1 means that everything from the
4405 CR to the end of the line is invisible, with maybe an
4406 ellipsis displayed for it. */
4407 success_p
= next_element_from_ellipsis (it
);
4408 it
->dpvec_char_len
= -1;
4413 /* Value is zero if end of buffer reached. */
4414 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4419 /* Run the redisplay end trigger hook for IT. */
4422 run_redisplay_end_trigger_hook (it
)
4425 Lisp_Object args
[3];
4427 /* IT->glyph_row should be non-null, i.e. we should be actually
4428 displaying something, or otherwise we should not run the hook. */
4429 xassert (it
->glyph_row
);
4431 /* Set up hook arguments. */
4432 args
[0] = Qredisplay_end_trigger_functions
;
4433 args
[1] = it
->window
;
4434 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4435 it
->redisplay_end_trigger_charpos
= 0;
4437 /* Since we are *trying* to run these functions, don't try to run
4438 them again, even if they get an error. */
4439 it
->w
->redisplay_end_trigger
= Qnil
;
4440 Frun_hook_with_args (3, args
);
4442 /* Notice if it changed the face of the character we are on. */
4443 handle_face_prop (it
);
4447 /* Deliver a composition display element. The iterator IT is already
4448 filled with composition information (done in
4449 handle_composition_prop). Value is always 1. */
4452 next_element_from_composition (it
)
4455 it
->what
= IT_COMPOSITION
;
4456 it
->position
= (STRINGP (it
->string
)
4457 ? it
->current
.string_pos
4464 /***********************************************************************
4465 Moving an iterator without producing glyphs
4466 ***********************************************************************/
4468 /* Move iterator IT to a specified buffer or X position within one
4469 line on the display without producing glyphs.
4471 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4472 whichever is reached first.
4474 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4476 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4477 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4478 TO_X includes the amount by which a window is horizontally
4483 MOVE_POS_MATCH_OR_ZV
4484 - when TO_POS or ZV was reached.
4487 -when TO_X was reached before TO_POS or ZV were reached.
4490 - when we reached the end of the display area and the line must
4494 - when we reached the end of the display area and the line is
4498 - when we stopped at a line end, i.e. a newline or a CR and selective
4501 static enum move_it_result
4502 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4504 int to_charpos
, to_x
, op
;
4506 enum move_it_result result
= MOVE_UNDEFINED
;
4507 struct glyph_row
*saved_glyph_row
;
4509 /* Don't produce glyphs in produce_glyphs. */
4510 saved_glyph_row
= it
->glyph_row
;
4511 it
->glyph_row
= NULL
;
4515 int x
, i
, ascent
= 0, descent
= 0;
4517 /* Stop when ZV or TO_CHARPOS reached. */
4518 if (!get_next_display_element (it
)
4519 || ((op
& MOVE_TO_POS
) != 0
4520 && BUFFERP (it
->object
)
4521 && IT_CHARPOS (*it
) >= to_charpos
))
4523 result
= MOVE_POS_MATCH_OR_ZV
;
4527 /* The call to produce_glyphs will get the metrics of the
4528 display element IT is loaded with. We record in x the
4529 x-position before this display element in case it does not
4533 /* Remember the line height so far in case the next element doesn't
4535 if (!it
->truncate_lines_p
)
4537 ascent
= it
->max_ascent
;
4538 descent
= it
->max_descent
;
4541 PRODUCE_GLYPHS (it
);
4543 if (it
->area
!= TEXT_AREA
)
4545 set_iterator_to_next (it
, 1);
4549 /* The number of glyphs we get back in IT->nglyphs will normally
4550 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4551 character on a terminal frame, or (iii) a line end. For the
4552 second case, IT->nglyphs - 1 padding glyphs will be present
4553 (on X frames, there is only one glyph produced for a
4554 composite character.
4556 The behavior implemented below means, for continuation lines,
4557 that as many spaces of a TAB as fit on the current line are
4558 displayed there. For terminal frames, as many glyphs of a
4559 multi-glyph character are displayed in the current line, too.
4560 This is what the old redisplay code did, and we keep it that
4561 way. Under X, the whole shape of a complex character must
4562 fit on the line or it will be completely displayed in the
4565 Note that both for tabs and padding glyphs, all glyphs have
4569 /* More than one glyph or glyph doesn't fit on line. All
4570 glyphs have the same width. */
4571 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4574 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4576 new_x
= x
+ single_glyph_width
;
4578 /* We want to leave anything reaching TO_X to the caller. */
4579 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4582 result
= MOVE_X_REACHED
;
4585 else if (/* Lines are continued. */
4586 !it
->truncate_lines_p
4587 && (/* And glyph doesn't fit on the line. */
4588 new_x
> it
->last_visible_x
4589 /* Or it fits exactly and we're on a window
4591 || (new_x
== it
->last_visible_x
4592 && FRAME_WINDOW_P (it
->f
))))
4594 if (/* IT->hpos == 0 means the very first glyph
4595 doesn't fit on the line, e.g. a wide image. */
4597 || (new_x
== it
->last_visible_x
4598 && FRAME_WINDOW_P (it
->f
)))
4601 it
->current_x
= new_x
;
4602 if (i
== it
->nglyphs
- 1)
4603 set_iterator_to_next (it
, 1);
4608 it
->max_ascent
= ascent
;
4609 it
->max_descent
= descent
;
4612 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
4614 result
= MOVE_LINE_CONTINUED
;
4617 else if (new_x
> it
->first_visible_x
)
4619 /* Glyph is visible. Increment number of glyphs that
4620 would be displayed. */
4625 /* Glyph is completely off the left margin of the display
4626 area. Nothing to do. */
4630 if (result
!= MOVE_UNDEFINED
)
4633 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4635 /* Stop when TO_X specified and reached. This check is
4636 necessary here because of lines consisting of a line end,
4637 only. The line end will not produce any glyphs and we
4638 would never get MOVE_X_REACHED. */
4639 xassert (it
->nglyphs
== 0);
4640 result
= MOVE_X_REACHED
;
4644 /* Is this a line end? If yes, we're done. */
4645 if (ITERATOR_AT_END_OF_LINE_P (it
))
4647 result
= MOVE_NEWLINE_OR_CR
;
4651 /* The current display element has been consumed. Advance
4653 set_iterator_to_next (it
, 1);
4655 /* Stop if lines are truncated and IT's current x-position is
4656 past the right edge of the window now. */
4657 if (it
->truncate_lines_p
4658 && it
->current_x
>= it
->last_visible_x
)
4660 result
= MOVE_LINE_TRUNCATED
;
4665 /* Restore the iterator settings altered at the beginning of this
4667 it
->glyph_row
= saved_glyph_row
;
4672 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4673 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4674 the description of enum move_operation_enum.
4676 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4677 screen line, this function will set IT to the next position >
4681 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4683 int to_charpos
, to_x
, to_y
, to_vpos
;
4686 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4692 if (op
& MOVE_TO_VPOS
)
4694 /* If no TO_CHARPOS and no TO_X specified, stop at the
4695 start of the line TO_VPOS. */
4696 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4698 if (it
->vpos
== to_vpos
)
4704 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4708 /* TO_VPOS >= 0 means stop at TO_X in the line at
4709 TO_VPOS, or at TO_POS, whichever comes first. */
4710 if (it
->vpos
== to_vpos
)
4716 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4718 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4723 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4725 /* We have reached TO_X but not in the line we want. */
4726 skip
= move_it_in_display_line_to (it
, to_charpos
,
4728 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4736 else if (op
& MOVE_TO_Y
)
4738 struct it it_backup
;
4740 /* TO_Y specified means stop at TO_X in the line containing
4741 TO_Y---or at TO_CHARPOS if this is reached first. The
4742 problem is that we can't really tell whether the line
4743 contains TO_Y before we have completely scanned it, and
4744 this may skip past TO_X. What we do is to first scan to
4747 If TO_X is not specified, use a TO_X of zero. The reason
4748 is to make the outcome of this function more predictable.
4749 If we didn't use TO_X == 0, we would stop at the end of
4750 the line which is probably not what a caller would expect
4752 skip
= move_it_in_display_line_to (it
, to_charpos
,
4756 | (op
& MOVE_TO_POS
)));
4758 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4759 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4765 /* If TO_X was reached, we would like to know whether TO_Y
4766 is in the line. This can only be said if we know the
4767 total line height which requires us to scan the rest of
4769 if (skip
== MOVE_X_REACHED
)
4772 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
4773 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4775 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
4778 /* Now, decide whether TO_Y is in this line. */
4779 line_height
= it
->max_ascent
+ it
->max_descent
;
4780 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
4782 if (to_y
>= it
->current_y
4783 && to_y
< it
->current_y
+ line_height
)
4785 if (skip
== MOVE_X_REACHED
)
4786 /* If TO_Y is in this line and TO_X was reached above,
4787 we scanned too far. We have to restore IT's settings
4788 to the ones before skipping. */
4792 else if (skip
== MOVE_X_REACHED
)
4795 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4803 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4807 case MOVE_POS_MATCH_OR_ZV
:
4811 case MOVE_NEWLINE_OR_CR
:
4812 set_iterator_to_next (it
, 1);
4813 it
->continuation_lines_width
= 0;
4816 case MOVE_LINE_TRUNCATED
:
4817 it
->continuation_lines_width
= 0;
4818 reseat_at_next_visible_line_start (it
, 0);
4819 if ((op
& MOVE_TO_POS
) != 0
4820 && IT_CHARPOS (*it
) > to_charpos
)
4827 case MOVE_LINE_CONTINUED
:
4828 it
->continuation_lines_width
+= it
->current_x
;
4835 /* Reset/increment for the next run. */
4836 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4837 it
->current_x
= it
->hpos
= 0;
4838 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4840 last_height
= it
->max_ascent
+ it
->max_descent
;
4841 last_max_ascent
= it
->max_ascent
;
4842 it
->max_ascent
= it
->max_descent
= 0;
4847 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
4851 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4853 If DY > 0, move IT backward at least that many pixels. DY = 0
4854 means move IT backward to the preceding line start or BEGV. This
4855 function may move over more than DY pixels if IT->current_y - DY
4856 ends up in the middle of a line; in this case IT->current_y will be
4857 set to the top of the line moved to. */
4860 move_it_vertically_backward (it
, dy
)
4864 int nlines
, h
, line_height
;
4866 int start_pos
= IT_CHARPOS (*it
);
4870 /* Estimate how many newlines we must move back. */
4871 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4873 /* Set the iterator's position that many lines back. */
4874 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4875 back_to_previous_visible_line_start (it
);
4877 /* Reseat the iterator here. When moving backward, we don't want
4878 reseat to skip forward over invisible text, set up the iterator
4879 to deliver from overlay strings at the new position etc. So,
4880 use reseat_1 here. */
4881 reseat_1 (it
, it
->current
.pos
, 1);
4883 /* We are now surely at a line start. */
4884 it
->current_x
= it
->hpos
= 0;
4886 /* Move forward and see what y-distance we moved. First move to the
4887 start of the next line so that we get its height. We need this
4888 height to be able to tell whether we reached the specified
4891 it2
.max_ascent
= it2
.max_descent
= 0;
4892 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4893 MOVE_TO_POS
| MOVE_TO_VPOS
);
4894 xassert (IT_CHARPOS (*it
) >= BEGV
);
4895 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4897 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4898 xassert (IT_CHARPOS (*it
) >= BEGV
);
4899 h
= it2
.current_y
- it
->current_y
;
4900 nlines
= it2
.vpos
- it
->vpos
;
4902 /* Correct IT's y and vpos position. */
4908 /* DY == 0 means move to the start of the screen line. The
4909 value of nlines is > 0 if continuation lines were involved. */
4911 move_it_by_lines (it
, nlines
, 1);
4912 xassert (IT_CHARPOS (*it
) <= start_pos
);
4916 /* The y-position we try to reach. Note that h has been
4917 subtracted in front of the if-statement. */
4918 int target_y
= it
->current_y
+ h
- dy
;
4920 /* If we did not reach target_y, try to move further backward if
4921 we can. If we moved too far backward, try to move forward. */
4922 if (target_y
< it
->current_y
4923 && IT_CHARPOS (*it
) > BEGV
)
4925 move_it_vertically (it
, target_y
- it
->current_y
);
4926 xassert (IT_CHARPOS (*it
) >= BEGV
);
4928 else if (target_y
>= it
->current_y
+ line_height
4929 && IT_CHARPOS (*it
) < ZV
)
4931 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4932 xassert (IT_CHARPOS (*it
) >= BEGV
);
4938 /* Move IT by a specified amount of pixel lines DY. DY negative means
4939 move backwards. DY = 0 means move to start of screen line. At the
4940 end, IT will be on the start of a screen line. */
4943 move_it_vertically (it
, dy
)
4948 move_it_vertically_backward (it
, -dy
);
4951 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
4952 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4953 MOVE_TO_POS
| MOVE_TO_Y
);
4954 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
4956 /* If buffer ends in ZV without a newline, move to the start of
4957 the line to satisfy the post-condition. */
4958 if (IT_CHARPOS (*it
) == ZV
4959 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4960 move_it_by_lines (it
, 0, 0);
4965 /* Return non-zero if some text between buffer positions START_CHARPOS
4966 and END_CHARPOS is invisible. IT->window is the window for text
4970 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4972 int start_charpos
, end_charpos
;
4974 Lisp_Object prop
, limit
;
4975 int invisible_found_p
;
4977 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4979 /* Is text at START invisible? */
4980 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4982 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4983 invisible_found_p
= 1;
4986 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
4988 make_number (end_charpos
));
4989 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4992 return invisible_found_p
;
4996 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4997 negative means move up. DVPOS == 0 means move to the start of the
4998 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4999 NEED_Y_P is zero, IT->current_y will be left unchanged.
5001 Further optimization ideas: If we would know that IT->f doesn't use
5002 a face with proportional font, we could be faster for
5003 truncate-lines nil. */
5006 move_it_by_lines (it
, dvpos
, need_y_p
)
5008 int dvpos
, need_y_p
;
5010 struct position pos
;
5012 if (!FRAME_WINDOW_P (it
->f
))
5014 struct text_pos textpos
;
5016 /* We can use vmotion on frames without proportional fonts. */
5017 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5018 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5019 reseat (it
, textpos
, 1);
5020 it
->vpos
+= pos
.vpos
;
5021 it
->current_y
+= pos
.vpos
;
5023 else if (dvpos
== 0)
5025 /* DVPOS == 0 means move to the start of the screen line. */
5026 move_it_vertically_backward (it
, 0);
5027 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5031 /* If there are no continuation lines, and if there is no
5032 selective display, try the simple method of moving forward
5033 DVPOS newlines, then see where we are. */
5034 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
5036 int shortage
= 0, charpos
;
5038 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
5039 charpos
= IT_CHARPOS (*it
) + 1;
5041 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
5044 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
5046 struct text_pos pos
;
5047 CHARPOS (pos
) = charpos
;
5048 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
5049 reseat (it
, pos
, 1);
5050 it
->vpos
+= dvpos
- shortage
;
5051 it
->hpos
= it
->current_x
= 0;
5056 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5061 int start_charpos
, i
;
5063 /* If there are no continuation lines, and if there is no
5064 selective display, try the simple method of moving backward
5066 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
5069 int charpos
= IT_CHARPOS (*it
);
5070 int bytepos
= IT_BYTEPOS (*it
);
5072 /* If in the middle of a line, go to its start. */
5073 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
5075 charpos
= find_next_newline_no_quit (charpos
, -1);
5076 bytepos
= CHAR_TO_BYTE (charpos
);
5079 if (charpos
== BEGV
)
5081 struct text_pos pos
;
5082 CHARPOS (pos
) = charpos
;
5083 BYTEPOS (pos
) = bytepos
;
5084 reseat (it
, pos
, 1);
5085 it
->hpos
= it
->current_x
= 0;
5090 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
5091 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
5093 struct text_pos pos
;
5094 CHARPOS (pos
) = charpos
;
5095 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
5096 reseat (it
, pos
, 1);
5097 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
5098 it
->hpos
= it
->current_x
= 0;
5104 /* Go back -DVPOS visible lines and reseat the iterator there. */
5105 start_charpos
= IT_CHARPOS (*it
);
5106 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5107 back_to_previous_visible_line_start (it
);
5108 reseat (it
, it
->current
.pos
, 1);
5109 it
->current_x
= it
->hpos
= 0;
5111 /* Above call may have moved too far if continuation lines
5112 are involved. Scan forward and see if it did. */
5114 it2
.vpos
= it2
.current_y
= 0;
5115 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5116 it
->vpos
-= it2
.vpos
;
5117 it
->current_y
-= it2
.current_y
;
5118 it
->current_x
= it
->hpos
= 0;
5120 /* If we moved too far, move IT some lines forward. */
5121 if (it2
.vpos
> -dvpos
)
5123 int delta
= it2
.vpos
+ dvpos
;
5124 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5131 /***********************************************************************
5133 ***********************************************************************/
5136 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5140 add_to_log (format
, arg1
, arg2
)
5142 Lisp_Object arg1
, arg2
;
5144 Lisp_Object args
[3];
5145 Lisp_Object msg
, fmt
;
5148 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5151 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5153 args
[0] = fmt
= build_string (format
);
5156 msg
= Fformat (3, args
);
5158 len
= STRING_BYTES (XSTRING (msg
)) + 1;
5159 buffer
= (char *) alloca (len
);
5160 strcpy (buffer
, XSTRING (msg
)->data
);
5162 message_dolog (buffer
, len
- 1, 1, 0);
5167 /* Output a newline in the *Messages* buffer if "needs" one. */
5170 message_log_maybe_newline ()
5172 if (message_log_need_newline
)
5173 message_dolog ("", 0, 1, 0);
5177 /* Add a string M of length LEN to the message log, optionally
5178 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5179 nonzero, means interpret the contents of M as multibyte. This
5180 function calls low-level routines in order to bypass text property
5181 hooks, etc. which might not be safe to run. */
5184 message_dolog (m
, len
, nlflag
, multibyte
)
5186 int len
, nlflag
, multibyte
;
5188 if (!NILP (Vmessage_log_max
))
5190 struct buffer
*oldbuf
;
5191 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5192 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5193 int point_at_end
= 0;
5195 Lisp_Object old_deactivate_mark
, tem
;
5196 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5198 old_deactivate_mark
= Vdeactivate_mark
;
5199 oldbuf
= current_buffer
;
5200 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5201 current_buffer
->undo_list
= Qt
;
5203 oldpoint
= Fpoint_marker ();
5204 oldbegv
= Fpoint_min_marker ();
5205 oldzv
= Fpoint_max_marker ();
5206 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
5214 BEGV_BYTE
= BEG_BYTE
;
5217 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5219 /* Insert the string--maybe converting multibyte to single byte
5220 or vice versa, so that all the text fits the buffer. */
5222 && NILP (current_buffer
->enable_multibyte_characters
))
5225 unsigned char work
[1];
5227 /* Convert a multibyte string to single-byte
5228 for the *Message* buffer. */
5229 for (i
= 0; i
< len
; i
+= nbytes
)
5231 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
5232 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5234 : multibyte_char_to_unibyte (c
, Qnil
));
5235 insert_1_both (work
, 1, 1, 1, 0, 0);
5238 else if (! multibyte
5239 && ! NILP (current_buffer
->enable_multibyte_characters
))
5242 unsigned char *msg
= (unsigned char *) m
;
5243 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5244 /* Convert a single-byte string to multibyte
5245 for the *Message* buffer. */
5246 for (i
= 0; i
< len
; i
++)
5248 c
= unibyte_char_to_multibyte (msg
[i
]);
5249 nbytes
= CHAR_STRING (c
, str
);
5250 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
5254 insert_1 (m
, len
, 1, 0, 0);
5258 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5259 insert_1 ("\n", 1, 1, 0, 0);
5261 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5263 this_bol_byte
= PT_BYTE
;
5267 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5269 prev_bol_byte
= PT_BYTE
;
5271 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5272 this_bol
, this_bol_byte
);
5275 del_range_both (prev_bol
, prev_bol_byte
,
5276 this_bol
, this_bol_byte
, 0);
5282 /* If you change this format, don't forget to also
5283 change message_log_check_duplicate. */
5284 sprintf (dupstr
, " [%d times]", dup
);
5285 duplen
= strlen (dupstr
);
5286 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5287 insert_1 (dupstr
, duplen
, 1, 0, 1);
5292 if (NATNUMP (Vmessage_log_max
))
5294 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5295 -XFASTINT (Vmessage_log_max
) - 1, 0);
5296 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5299 BEGV
= XMARKER (oldbegv
)->charpos
;
5300 BEGV_BYTE
= marker_byte_position (oldbegv
);
5309 ZV
= XMARKER (oldzv
)->charpos
;
5310 ZV_BYTE
= marker_byte_position (oldzv
);
5314 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5316 /* We can't do Fgoto_char (oldpoint) because it will run some
5318 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5319 XMARKER (oldpoint
)->bytepos
);
5322 free_marker (oldpoint
);
5323 free_marker (oldbegv
);
5324 free_marker (oldzv
);
5326 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5327 set_buffer_internal (oldbuf
);
5329 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5330 message_log_need_newline
= !nlflag
;
5331 Vdeactivate_mark
= old_deactivate_mark
;
5336 /* We are at the end of the buffer after just having inserted a newline.
5337 (Note: We depend on the fact we won't be crossing the gap.)
5338 Check to see if the most recent message looks a lot like the previous one.
5339 Return 0 if different, 1 if the new one should just replace it, or a
5340 value N > 1 if we should also append " [N times]". */
5343 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5344 int prev_bol
, this_bol
;
5345 int prev_bol_byte
, this_bol_byte
;
5348 int len
= Z_BYTE
- 1 - this_bol_byte
;
5350 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5351 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5353 for (i
= 0; i
< len
; i
++)
5355 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
5364 if (*p1
++ == ' ' && *p1
++ == '[')
5367 while (*p1
>= '0' && *p1
<= '9')
5368 n
= n
* 10 + *p1
++ - '0';
5369 if (strncmp (p1
, " times]\n", 8) == 0)
5376 /* Display an echo area message M with a specified length of LEN
5377 chars. The string may include null characters. If M is 0, clear
5378 out any existing message, and let the mini-buffer text show through.
5380 The buffer M must continue to exist until after the echo area gets
5381 cleared or some other message gets displayed there. This means do
5382 not pass text that is stored in a Lisp string; do not pass text in
5383 a buffer that was alloca'd. */
5386 message2 (m
, len
, multibyte
)
5391 /* First flush out any partial line written with print. */
5392 message_log_maybe_newline ();
5394 message_dolog (m
, len
, 1, multibyte
);
5395 message2_nolog (m
, len
, multibyte
);
5399 /* The non-logging counterpart of message2. */
5402 message2_nolog (m
, len
, multibyte
)
5406 struct frame
*sf
= SELECTED_FRAME ();
5407 message_enable_multibyte
= multibyte
;
5411 if (noninteractive_need_newline
)
5412 putc ('\n', stderr
);
5413 noninteractive_need_newline
= 0;
5415 fwrite (m
, len
, 1, stderr
);
5416 if (cursor_in_echo_area
== 0)
5417 fprintf (stderr
, "\n");
5420 /* A null message buffer means that the frame hasn't really been
5421 initialized yet. Error messages get reported properly by
5422 cmd_error, so this must be just an informative message; toss it. */
5423 else if (INTERACTIVE
5424 && sf
->glyphs_initialized_p
5425 && FRAME_MESSAGE_BUF (sf
))
5427 Lisp_Object mini_window
;
5430 /* Get the frame containing the mini-buffer
5431 that the selected frame is using. */
5432 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5433 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5435 FRAME_SAMPLE_VISIBILITY (f
);
5436 if (FRAME_VISIBLE_P (sf
)
5437 && ! FRAME_VISIBLE_P (f
))
5438 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5442 set_message (m
, Qnil
, len
, multibyte
);
5443 if (minibuffer_auto_raise
)
5444 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5447 clear_message (1, 1);
5449 do_pending_window_change (0);
5450 echo_area_display (1);
5451 do_pending_window_change (0);
5452 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5453 (*frame_up_to_date_hook
) (f
);
5458 /* Display an echo area message M with a specified length of NBYTES
5459 bytes. The string may include null characters. If M is not a
5460 string, clear out any existing message, and let the mini-buffer
5461 text show through. */
5464 message3 (m
, nbytes
, multibyte
)
5469 struct gcpro gcpro1
;
5473 /* First flush out any partial line written with print. */
5474 message_log_maybe_newline ();
5476 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
5477 message3_nolog (m
, nbytes
, multibyte
);
5483 /* The non-logging version of message3. */
5486 message3_nolog (m
, nbytes
, multibyte
)
5488 int nbytes
, multibyte
;
5490 struct frame
*sf
= SELECTED_FRAME ();
5491 message_enable_multibyte
= multibyte
;
5495 if (noninteractive_need_newline
)
5496 putc ('\n', stderr
);
5497 noninteractive_need_newline
= 0;
5499 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5500 if (cursor_in_echo_area
== 0)
5501 fprintf (stderr
, "\n");
5504 /* A null message buffer means that the frame hasn't really been
5505 initialized yet. Error messages get reported properly by
5506 cmd_error, so this must be just an informative message; toss it. */
5507 else if (INTERACTIVE
5508 && sf
->glyphs_initialized_p
5509 && FRAME_MESSAGE_BUF (sf
))
5511 Lisp_Object mini_window
;
5515 /* Get the frame containing the mini-buffer
5516 that the selected frame is using. */
5517 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5518 frame
= XWINDOW (mini_window
)->frame
;
5521 FRAME_SAMPLE_VISIBILITY (f
);
5522 if (FRAME_VISIBLE_P (sf
)
5523 && !FRAME_VISIBLE_P (f
))
5524 Fmake_frame_visible (frame
);
5526 if (STRINGP (m
) && XSTRING (m
)->size
)
5528 set_message (NULL
, m
, nbytes
, multibyte
);
5529 if (minibuffer_auto_raise
)
5530 Fraise_frame (frame
);
5533 clear_message (1, 1);
5535 do_pending_window_change (0);
5536 echo_area_display (1);
5537 do_pending_window_change (0);
5538 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5539 (*frame_up_to_date_hook
) (f
);
5544 /* Display a null-terminated echo area message M. If M is 0, clear
5545 out any existing message, and let the mini-buffer text show through.
5547 The buffer M must continue to exist until after the echo area gets
5548 cleared or some other message gets displayed there. Do not pass
5549 text that is stored in a Lisp string. Do not pass text in a buffer
5550 that was alloca'd. */
5556 message2 (m
, (m
? strlen (m
) : 0), 0);
5560 /* The non-logging counterpart of message1. */
5566 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5569 /* Display a message M which contains a single %s
5570 which gets replaced with STRING. */
5573 message_with_string (m
, string
, log
)
5582 if (noninteractive_need_newline
)
5583 putc ('\n', stderr
);
5584 noninteractive_need_newline
= 0;
5585 fprintf (stderr
, m
, XSTRING (string
)->data
);
5586 if (cursor_in_echo_area
== 0)
5587 fprintf (stderr
, "\n");
5591 else if (INTERACTIVE
)
5593 /* The frame whose minibuffer we're going to display the message on.
5594 It may be larger than the selected frame, so we need
5595 to use its buffer, not the selected frame's buffer. */
5596 Lisp_Object mini_window
;
5597 struct frame
*f
, *sf
= SELECTED_FRAME ();
5599 /* Get the frame containing the minibuffer
5600 that the selected frame is using. */
5601 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5602 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5604 /* A null message buffer means that the frame hasn't really been
5605 initialized yet. Error messages get reported properly by
5606 cmd_error, so this must be just an informative message; toss it. */
5607 if (FRAME_MESSAGE_BUF (f
))
5611 a
[0] = (char *) XSTRING (string
)->data
;
5613 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5614 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5617 message2 (FRAME_MESSAGE_BUF (f
), len
,
5618 STRING_MULTIBYTE (string
));
5620 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5621 STRING_MULTIBYTE (string
));
5623 /* Print should start at the beginning of the message
5624 buffer next time. */
5625 message_buf_print
= 0;
5631 /* Dump an informative message to the minibuf. If M is 0, clear out
5632 any existing message, and let the mini-buffer text show through. */
5636 message (m
, a1
, a2
, a3
)
5638 EMACS_INT a1
, a2
, a3
;
5644 if (noninteractive_need_newline
)
5645 putc ('\n', stderr
);
5646 noninteractive_need_newline
= 0;
5647 fprintf (stderr
, m
, a1
, a2
, a3
);
5648 if (cursor_in_echo_area
== 0)
5649 fprintf (stderr
, "\n");
5653 else if (INTERACTIVE
)
5655 /* The frame whose mini-buffer we're going to display the message
5656 on. It may be larger than the selected frame, so we need to
5657 use its buffer, not the selected frame's buffer. */
5658 Lisp_Object mini_window
;
5659 struct frame
*f
, *sf
= SELECTED_FRAME ();
5661 /* Get the frame containing the mini-buffer
5662 that the selected frame is using. */
5663 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5664 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5666 /* A null message buffer means that the frame hasn't really been
5667 initialized yet. Error messages get reported properly by
5668 cmd_error, so this must be just an informative message; toss
5670 if (FRAME_MESSAGE_BUF (f
))
5681 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5682 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5684 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5685 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5687 #endif /* NO_ARG_ARRAY */
5689 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5694 /* Print should start at the beginning of the message
5695 buffer next time. */
5696 message_buf_print
= 0;
5702 /* The non-logging version of message. */
5705 message_nolog (m
, a1
, a2
, a3
)
5707 EMACS_INT a1
, a2
, a3
;
5709 Lisp_Object old_log_max
;
5710 old_log_max
= Vmessage_log_max
;
5711 Vmessage_log_max
= Qnil
;
5712 message (m
, a1
, a2
, a3
);
5713 Vmessage_log_max
= old_log_max
;
5717 /* Display the current message in the current mini-buffer. This is
5718 only called from error handlers in process.c, and is not time
5724 if (!NILP (echo_area_buffer
[0]))
5727 string
= Fcurrent_message ();
5728 message3 (string
, XSTRING (string
)->size
,
5729 !NILP (current_buffer
->enable_multibyte_characters
));
5734 /* Make sure echo area buffers in echo_buffers[] are life. If they
5735 aren't, make new ones. */
5738 ensure_echo_area_buffers ()
5742 for (i
= 0; i
< 2; ++i
)
5743 if (!BUFFERP (echo_buffer
[i
])
5744 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5747 Lisp_Object old_buffer
;
5750 old_buffer
= echo_buffer
[i
];
5751 sprintf (name
, " *Echo Area %d*", i
);
5752 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5753 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
5755 for (j
= 0; j
< 2; ++j
)
5756 if (EQ (old_buffer
, echo_area_buffer
[j
]))
5757 echo_area_buffer
[j
] = echo_buffer
[i
];
5762 /* Call FN with args A1..A4 with either the current or last displayed
5763 echo_area_buffer as current buffer.
5765 WHICH zero means use the current message buffer
5766 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5767 from echo_buffer[] and clear it.
5769 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5770 suitable buffer from echo_buffer[] and clear it.
5772 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5773 that the current message becomes the last displayed one, make
5774 choose a suitable buffer for echo_area_buffer[0], and clear it.
5776 Value is what FN returns. */
5779 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
5782 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
5788 int this_one
, the_other
, clear_buffer_p
, rc
;
5789 int count
= specpdl_ptr
- specpdl
;
5791 /* If buffers aren't life, make new ones. */
5792 ensure_echo_area_buffers ();
5797 this_one
= 0, the_other
= 1;
5799 this_one
= 1, the_other
= 0;
5802 this_one
= 0, the_other
= 1;
5805 /* We need a fresh one in case the current echo buffer equals
5806 the one containing the last displayed echo area message. */
5807 if (!NILP (echo_area_buffer
[this_one
])
5808 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5809 echo_area_buffer
[this_one
] = Qnil
;
5812 /* Choose a suitable buffer from echo_buffer[] is we don't
5814 if (NILP (echo_area_buffer
[this_one
]))
5816 echo_area_buffer
[this_one
]
5817 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5818 ? echo_buffer
[the_other
]
5819 : echo_buffer
[this_one
]);
5823 buffer
= echo_area_buffer
[this_one
];
5825 record_unwind_protect (unwind_with_echo_area_buffer
,
5826 with_echo_area_buffer_unwind_data (w
));
5828 /* Make the echo area buffer current. Note that for display
5829 purposes, it is not necessary that the displayed window's buffer
5830 == current_buffer, except for text property lookup. So, let's
5831 only set that buffer temporarily here without doing a full
5832 Fset_window_buffer. We must also change w->pointm, though,
5833 because otherwise an assertions in unshow_buffer fails, and Emacs
5835 set_buffer_internal_1 (XBUFFER (buffer
));
5839 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5842 current_buffer
->undo_list
= Qt
;
5843 current_buffer
->read_only
= Qnil
;
5845 if (clear_buffer_p
&& Z
> BEG
)
5848 xassert (BEGV
>= BEG
);
5849 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5851 rc
= fn (a1
, a2
, a3
, a4
);
5853 xassert (BEGV
>= BEG
);
5854 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5856 unbind_to (count
, Qnil
);
5861 /* Save state that should be preserved around the call to the function
5862 FN called in with_echo_area_buffer. */
5865 with_echo_area_buffer_unwind_data (w
)
5871 /* Reduce consing by keeping one vector in
5872 Vwith_echo_area_save_vector. */
5873 vector
= Vwith_echo_area_save_vector
;
5874 Vwith_echo_area_save_vector
= Qnil
;
5877 vector
= Fmake_vector (make_number (7), Qnil
);
5879 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5880 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5881 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5885 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5886 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5887 XVECTOR (vector
)->contents
[i
++]
5888 = make_number (XMARKER (w
->pointm
)->charpos
);
5889 XVECTOR (vector
)->contents
[i
++]
5890 = make_number (XMARKER (w
->pointm
)->bytepos
);
5896 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5899 xassert (i
== XVECTOR (vector
)->size
);
5904 /* Restore global state from VECTOR which was created by
5905 with_echo_area_buffer_unwind_data. */
5908 unwind_with_echo_area_buffer (vector
)
5913 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5914 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5915 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5917 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5920 Lisp_Object buffer
, charpos
, bytepos
;
5922 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5923 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5924 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5925 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5928 set_marker_both (w
->pointm
, buffer
,
5929 XFASTINT (charpos
), XFASTINT (bytepos
));
5932 Vwith_echo_area_save_vector
= vector
;
5937 /* Set up the echo area for use by print functions. MULTIBYTE_P
5938 non-zero means we will print multibyte. */
5941 setup_echo_area_for_printing (multibyte_p
)
5944 ensure_echo_area_buffers ();
5946 if (!message_buf_print
)
5948 /* A message has been output since the last time we printed.
5949 Choose a fresh echo area buffer. */
5950 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5951 echo_area_buffer
[0] = echo_buffer
[1];
5953 echo_area_buffer
[0] = echo_buffer
[0];
5955 /* Switch to that buffer and clear it. */
5956 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5959 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5961 /* Set up the buffer for the multibyteness we need. */
5963 != !NILP (current_buffer
->enable_multibyte_characters
))
5964 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5966 /* Raise the frame containing the echo area. */
5967 if (minibuffer_auto_raise
)
5969 struct frame
*sf
= SELECTED_FRAME ();
5970 Lisp_Object mini_window
;
5971 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5972 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5975 message_log_maybe_newline ();
5976 message_buf_print
= 1;
5980 if (NILP (echo_area_buffer
[0]))
5982 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5983 echo_area_buffer
[0] = echo_buffer
[1];
5985 echo_area_buffer
[0] = echo_buffer
[0];
5988 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5989 /* Someone switched buffers between print requests. */
5990 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5995 /* Display an echo area message in window W. Value is non-zero if W's
5996 height is changed. If display_last_displayed_message_p is
5997 non-zero, display the message that was last displayed, otherwise
5998 display the current message. */
6001 display_echo_area (w
)
6004 int i
, no_message_p
, window_height_changed_p
, count
;
6006 /* Temporarily disable garbage collections while displaying the echo
6007 area. This is done because a GC can print a message itself.
6008 That message would modify the echo area buffer's contents while a
6009 redisplay of the buffer is going on, and seriously confuse
6011 count
= inhibit_garbage_collection ();
6013 /* If there is no message, we must call display_echo_area_1
6014 nevertheless because it resizes the window. But we will have to
6015 reset the echo_area_buffer in question to nil at the end because
6016 with_echo_area_buffer will sets it to an empty buffer. */
6017 i
= display_last_displayed_message_p
? 1 : 0;
6018 no_message_p
= NILP (echo_area_buffer
[i
]);
6020 window_height_changed_p
6021 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6022 display_echo_area_1
,
6023 (EMACS_INT
) w
, Qnil
, 0, 0);
6026 echo_area_buffer
[i
] = Qnil
;
6028 unbind_to (count
, Qnil
);
6029 return window_height_changed_p
;
6033 /* Helper for display_echo_area. Display the current buffer which
6034 contains the current echo area message in window W, a mini-window,
6035 a pointer to which is passed in A1. A2..A4 are currently not used.
6036 Change the height of W so that all of the message is displayed.
6037 Value is non-zero if height of W was changed. */
6040 display_echo_area_1 (a1
, a2
, a3
, a4
)
6045 struct window
*w
= (struct window
*) a1
;
6047 struct text_pos start
;
6048 int window_height_changed_p
= 0;
6050 /* Do this before displaying, so that we have a large enough glyph
6051 matrix for the display. */
6052 window_height_changed_p
= resize_mini_window (w
, 0);
6055 clear_glyph_matrix (w
->desired_matrix
);
6056 XSETWINDOW (window
, w
);
6057 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6058 try_window (window
, start
);
6060 return window_height_changed_p
;
6064 /* Resize the echo area window to exactly the size needed for the
6065 currently displayed message, if there is one. */
6068 resize_echo_area_axactly ()
6070 if (BUFFERP (echo_area_buffer
[0])
6071 && WINDOWP (echo_area_window
))
6073 struct window
*w
= XWINDOW (echo_area_window
);
6076 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6077 (EMACS_INT
) w
, Qnil
, 0, 0);
6080 ++windows_or_buffers_changed
;
6081 ++update_mode_lines
;
6082 redisplay_internal (0);
6088 /* Callback function for with_echo_area_buffer, when used from
6089 resize_echo_area_axactly. A1 contains a pointer to the window to
6090 resize, A2 to A4 are not used. Value is what resize_mini_window
6094 resize_mini_window_1 (a1
, a2
, a3
, a4
)
6099 return resize_mini_window ((struct window
*) a1
, 1);
6103 /* Resize mini-window W to fit the size of its contents. EXACT:P
6104 means size the window exactly to the size needed. Otherwise, it's
6105 only enlarged until W's buffer is empty. Value is non-zero if
6106 the window height has been changed. */
6109 resize_mini_window (w
, exact_p
)
6113 struct frame
*f
= XFRAME (w
->frame
);
6114 int window_height_changed_p
= 0;
6116 xassert (MINI_WINDOW_P (w
));
6118 /* Nil means don't try to resize. */
6119 if (NILP (Vresize_mini_windows
)
6120 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6123 if (!FRAME_MINIBUF_ONLY_P (f
))
6126 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6127 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6128 int height
, max_height
;
6129 int unit
= CANON_Y_UNIT (f
);
6130 struct text_pos start
;
6132 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6134 /* Compute the max. number of lines specified by the user. */
6135 if (FLOATP (Vmax_mini_window_height
))
6136 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
6137 else if (INTEGERP (Vmax_mini_window_height
))
6138 max_height
= XINT (Vmax_mini_window_height
);
6140 max_height
= total_height
/ 4;
6142 /* Correct that max. height if it's bogus. */
6143 max_height
= max (1, max_height
);
6144 max_height
= min (total_height
, max_height
);
6146 /* Find out the height of the text in the window. */
6147 if (it
.truncate_lines_p
)
6152 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6153 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6154 height
= it
.current_y
+ last_height
;
6156 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6157 height
-= it
.extra_line_spacing
;
6158 height
= (height
+ unit
- 1) / unit
;
6161 /* Compute a suitable window start. */
6162 if (height
> max_height
)
6164 height
= max_height
;
6165 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6166 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6167 start
= it
.current
.pos
;
6170 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6171 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6173 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6175 /* Let it grow only, until we display an empty message, in which
6176 case the window shrinks again. */
6177 if (height
> XFASTINT (w
->height
))
6179 int old_height
= XFASTINT (w
->height
);
6180 freeze_window_starts (f
, 1);
6181 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6182 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6184 else if (height
< XFASTINT (w
->height
)
6185 && (exact_p
|| BEGV
== ZV
))
6187 int old_height
= XFASTINT (w
->height
);
6188 freeze_window_starts (f
, 0);
6189 shrink_mini_window (w
);
6190 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6195 /* Always resize to exact size needed. */
6196 if (height
> XFASTINT (w
->height
))
6198 int old_height
= XFASTINT (w
->height
);
6199 freeze_window_starts (f
, 1);
6200 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6201 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6203 else if (height
< XFASTINT (w
->height
))
6205 int old_height
= XFASTINT (w
->height
);
6206 freeze_window_starts (f
, 0);
6207 shrink_mini_window (w
);
6211 freeze_window_starts (f
, 1);
6212 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6215 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6220 return window_height_changed_p
;
6224 /* Value is the current message, a string, or nil if there is no
6232 if (NILP (echo_area_buffer
[0]))
6236 with_echo_area_buffer (0, 0, current_message_1
,
6237 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6239 echo_area_buffer
[0] = Qnil
;
6247 current_message_1 (a1
, a2
, a3
, a4
)
6252 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6255 *msg
= make_buffer_string (BEG
, Z
, 1);
6262 /* Push the current message on Vmessage_stack for later restauration
6263 by restore_message. Value is non-zero if the current message isn't
6264 empty. This is a relatively infrequent operation, so it's not
6265 worth optimizing. */
6271 msg
= current_message ();
6272 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6273 return STRINGP (msg
);
6277 /* Restore message display from the top of Vmessage_stack. */
6284 xassert (CONSP (Vmessage_stack
));
6285 msg
= XCAR (Vmessage_stack
);
6287 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
6289 message3_nolog (msg
, 0, 0);
6293 /* Pop the top-most entry off Vmessage_stack. */
6298 xassert (CONSP (Vmessage_stack
));
6299 Vmessage_stack
= XCDR (Vmessage_stack
);
6303 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6304 exits. If the stack is not empty, we have a missing pop_message
6308 check_message_stack ()
6310 if (!NILP (Vmessage_stack
))
6315 /* Truncate to NCHARS what will be displayed in the echo area the next
6316 time we display it---but don't redisplay it now. */
6319 truncate_echo_area (nchars
)
6323 echo_area_buffer
[0] = Qnil
;
6324 /* A null message buffer means that the frame hasn't really been
6325 initialized yet. Error messages get reported properly by
6326 cmd_error, so this must be just an informative message; toss it. */
6327 else if (!noninteractive
6329 && !NILP (echo_area_buffer
[0]))
6331 struct frame
*sf
= SELECTED_FRAME ();
6332 if (FRAME_MESSAGE_BUF (sf
))
6333 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6338 /* Helper function for truncate_echo_area. Truncate the current
6339 message to at most NCHARS characters. */
6342 truncate_message_1 (nchars
, a2
, a3
, a4
)
6347 if (BEG
+ nchars
< Z
)
6348 del_range (BEG
+ nchars
, Z
);
6350 echo_area_buffer
[0] = Qnil
;
6355 /* Set the current message to a substring of S or STRING.
6357 If STRING is a Lisp string, set the message to the first NBYTES
6358 bytes from STRING. NBYTES zero means use the whole string. If
6359 STRING is multibyte, the message will be displayed multibyte.
6361 If S is not null, set the message to the first LEN bytes of S. LEN
6362 zero means use the whole string. MULTIBYTE_P non-zero means S is
6363 multibyte. Display the message multibyte in that case. */
6366 set_message (s
, string
, nbytes
, multibyte_p
)
6371 message_enable_multibyte
6372 = ((s
&& multibyte_p
)
6373 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6375 with_echo_area_buffer (0, -1, set_message_1
,
6376 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6377 message_buf_print
= 0;
6378 help_echo_showing_p
= 0;
6382 /* Helper function for set_message. Arguments have the same meaning
6383 as there, with A1 corresponding to S and A2 corresponding to STRING
6384 This function is called with the echo area buffer being
6388 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
6391 EMACS_INT nbytes
, multibyte_p
;
6393 char *s
= (char *) a1
;
6394 Lisp_Object string
= a2
;
6398 /* Change multibyteness of the echo buffer appropriately. */
6399 if (message_enable_multibyte
6400 != !NILP (current_buffer
->enable_multibyte_characters
))
6401 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
6403 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
6405 /* Insert new message at BEG. */
6406 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6408 if (STRINGP (string
))
6413 nbytes
= XSTRING (string
)->size_byte
;
6414 nchars
= string_byte_to_char (string
, nbytes
);
6416 /* This function takes care of single/multibyte conversion. We
6417 just have to ensure that the echo area buffer has the right
6418 setting of enable_multibyte_characters. */
6419 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
6424 nbytes
= strlen (s
);
6426 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
6428 /* Convert from multi-byte to single-byte. */
6430 unsigned char work
[1];
6432 /* Convert a multibyte string to single-byte. */
6433 for (i
= 0; i
< nbytes
; i
+= n
)
6435 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
6436 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6438 : multibyte_char_to_unibyte (c
, Qnil
));
6439 insert_1_both (work
, 1, 1, 1, 0, 0);
6442 else if (!multibyte_p
6443 && !NILP (current_buffer
->enable_multibyte_characters
))
6445 /* Convert from single-byte to multi-byte. */
6447 unsigned char *msg
= (unsigned char *) s
;
6448 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6450 /* Convert a single-byte string to multibyte. */
6451 for (i
= 0; i
< nbytes
; i
++)
6453 c
= unibyte_char_to_multibyte (msg
[i
]);
6454 n
= CHAR_STRING (c
, str
);
6455 insert_1_both (str
, 1, n
, 1, 0, 0);
6459 insert_1 (s
, nbytes
, 1, 0, 0);
6466 /* Clear messages. CURRENT_P non-zero means clear the current
6467 message. LAST_DISPLAYED_P non-zero means clear the message
6471 clear_message (current_p
, last_displayed_p
)
6472 int current_p
, last_displayed_p
;
6475 echo_area_buffer
[0] = Qnil
;
6477 if (last_displayed_p
)
6478 echo_area_buffer
[1] = Qnil
;
6480 message_buf_print
= 0;
6483 /* Clear garbaged frames.
6485 This function is used where the old redisplay called
6486 redraw_garbaged_frames which in turn called redraw_frame which in
6487 turn called clear_frame. The call to clear_frame was a source of
6488 flickering. I believe a clear_frame is not necessary. It should
6489 suffice in the new redisplay to invalidate all current matrices,
6490 and ensure a complete redisplay of all windows. */
6493 clear_garbaged_frames ()
6497 Lisp_Object tail
, frame
;
6499 FOR_EACH_FRAME (tail
, frame
)
6501 struct frame
*f
= XFRAME (frame
);
6503 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
6505 clear_current_matrices (f
);
6511 ++windows_or_buffers_changed
;
6516 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
6517 is non-zero update selected_frame. Value is non-zero if the
6518 mini-windows height has been changed. */
6521 echo_area_display (update_frame_p
)
6524 Lisp_Object mini_window
;
6527 int window_height_changed_p
= 0;
6528 struct frame
*sf
= SELECTED_FRAME ();
6530 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6531 w
= XWINDOW (mini_window
);
6532 f
= XFRAME (WINDOW_FRAME (w
));
6534 /* Don't display if frame is invisible or not yet initialized. */
6535 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
6538 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
6540 #ifdef HAVE_WINDOW_SYSTEM
6541 /* When Emacs starts, selected_frame may be a visible terminal
6542 frame, even if we run under a window system. If we let this
6543 through, a message would be displayed on the terminal. */
6544 if (EQ (selected_frame
, Vterminal_frame
)
6545 && !NILP (Vwindow_system
))
6547 #endif /* HAVE_WINDOW_SYSTEM */
6550 /* Redraw garbaged frames. */
6552 clear_garbaged_frames ();
6554 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
6556 echo_area_window
= mini_window
;
6557 window_height_changed_p
= display_echo_area (w
);
6558 w
->must_be_updated_p
= 1;
6560 /* Update the display, unless called from redisplay_internal.
6561 Also don't update the screen during redisplay itself. The
6562 update will happen at the end of redisplay, and an update
6563 here could cause confusion. */
6564 if (update_frame_p
&& !redisplaying_p
)
6568 /* If the display update has been interrupted by pending
6569 input, update mode lines in the frame. Due to the
6570 pending input, it might have been that redisplay hasn't
6571 been called, so that mode lines above the echo area are
6572 garbaged. This looks odd, so we prevent it here. */
6573 if (!display_completed
)
6574 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
6576 if (window_height_changed_p
)
6578 /* Must update other windows. */
6579 windows_or_buffers_changed
= 1;
6580 redisplay_internal (0);
6582 else if (FRAME_WINDOW_P (f
) && n
== 0)
6584 /* Window configuration is the same as before.
6585 Can do with a display update of the echo area,
6586 unless we displayed some mode lines. */
6587 update_single_window (w
, 1);
6588 rif
->flush_display (f
);
6591 update_frame (f
, 1, 1);
6594 else if (!EQ (mini_window
, selected_window
))
6595 windows_or_buffers_changed
++;
6597 /* Last displayed message is now the current message. */
6598 echo_area_buffer
[1] = echo_area_buffer
[0];
6600 /* Prevent redisplay optimization in redisplay_internal by resetting
6601 this_line_start_pos. This is done because the mini-buffer now
6602 displays the message instead of its buffer text. */
6603 if (EQ (mini_window
, selected_window
))
6604 CHARPOS (this_line_start_pos
) = 0;
6606 return window_height_changed_p
;
6611 /***********************************************************************
6613 ***********************************************************************/
6616 #ifdef HAVE_WINDOW_SYSTEM
6618 /* A buffer for constructing frame titles in it; allocated from the
6619 heap in init_xdisp and resized as needed in store_frame_title_char. */
6621 static char *frame_title_buf
;
6623 /* The buffer's end, and a current output position in it. */
6625 static char *frame_title_buf_end
;
6626 static char *frame_title_ptr
;
6629 /* Store a single character C for the frame title in frame_title_buf.
6630 Re-allocate frame_title_buf if necessary. */
6633 store_frame_title_char (c
)
6636 /* If output position has reached the end of the allocated buffer,
6637 double the buffer's size. */
6638 if (frame_title_ptr
== frame_title_buf_end
)
6640 int len
= frame_title_ptr
- frame_title_buf
;
6641 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6642 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6643 frame_title_buf_end
= frame_title_buf
+ new_size
;
6644 frame_title_ptr
= frame_title_buf
+ len
;
6647 *frame_title_ptr
++ = c
;
6651 /* Store part of a frame title in frame_title_buf, beginning at
6652 frame_title_ptr. STR is the string to store. Do not copy more
6653 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6654 the whole string. Pad with spaces until FIELD_WIDTH number of
6655 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6656 Called from display_mode_element when it is used to build a frame
6660 store_frame_title (str
, field_width
, precision
)
6662 int field_width
, precision
;
6666 /* Copy at most PRECISION chars from STR. */
6667 while ((precision
<= 0 || n
< precision
)
6670 store_frame_title_char (*str
++);
6674 /* Fill up with spaces until FIELD_WIDTH reached. */
6675 while (field_width
> 0
6678 store_frame_title_char (' ');
6686 /* Set the title of FRAME, if it has changed. The title format is
6687 Vicon_title_format if FRAME is iconified, otherwise it is
6688 frame_title_format. */
6691 x_consider_frame_title (frame
)
6694 struct frame
*f
= XFRAME (frame
);
6696 if (FRAME_WINDOW_P (f
)
6697 || FRAME_MINIBUF_ONLY_P (f
)
6698 || f
->explicit_name
)
6700 /* Do we have more than one visible frame on this X display? */
6703 struct buffer
*obuf
;
6707 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6709 struct frame
*tf
= XFRAME (XCAR (tail
));
6712 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6713 && !FRAME_MINIBUF_ONLY_P (tf
)
6714 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6718 /* Set global variable indicating that multiple frames exist. */
6719 multiple_frames
= CONSP (tail
);
6721 /* Switch to the buffer of selected window of the frame. Set up
6722 frame_title_ptr so that display_mode_element will output into it;
6723 then display the title. */
6724 obuf
= current_buffer
;
6725 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6726 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6727 frame_title_ptr
= frame_title_buf
;
6728 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6729 NULL
, DEFAULT_FACE_ID
);
6730 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6731 frame_title_ptr
= NULL
;
6732 set_buffer_internal (obuf
);
6734 /* Set the title only if it's changed. This avoids consing in
6735 the common case where it hasn't. (If it turns out that we've
6736 already wasted too much time by walking through the list with
6737 display_mode_element, then we might need to optimize at a
6738 higher level than this.) */
6739 if (! STRINGP (f
->name
)
6740 || STRING_BYTES (XSTRING (f
->name
)) != len
6741 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6742 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6746 #else /* not HAVE_WINDOW_SYSTEM */
6748 #define frame_title_ptr ((char *)0)
6749 #define store_frame_title(str, mincol, maxcol) 0
6751 #endif /* not HAVE_WINDOW_SYSTEM */
6756 /***********************************************************************
6758 ***********************************************************************/
6761 /* Prepare for redisplay by updating menu-bar item lists when
6762 appropriate. This can call eval. */
6765 prepare_menu_bars ()
6768 struct gcpro gcpro1
, gcpro2
;
6770 struct frame
*tooltip_frame
;
6772 #ifdef HAVE_X_WINDOWS
6773 tooltip_frame
= tip_frame
;
6775 tooltip_frame
= NULL
;
6778 /* Update all frame titles based on their buffer names, etc. We do
6779 this before the menu bars so that the buffer-menu will show the
6780 up-to-date frame titles. */
6781 #ifdef HAVE_WINDOW_SYSTEM
6782 if (windows_or_buffers_changed
|| update_mode_lines
)
6784 Lisp_Object tail
, frame
;
6786 FOR_EACH_FRAME (tail
, frame
)
6789 if (f
!= tooltip_frame
6790 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6791 x_consider_frame_title (frame
);
6794 #endif /* HAVE_WINDOW_SYSTEM */
6796 /* Update the menu bar item lists, if appropriate. This has to be
6797 done before any actual redisplay or generation of display lines. */
6798 all_windows
= (update_mode_lines
6799 || buffer_shared
> 1
6800 || windows_or_buffers_changed
);
6803 Lisp_Object tail
, frame
;
6804 int count
= specpdl_ptr
- specpdl
;
6806 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6808 FOR_EACH_FRAME (tail
, frame
)
6812 /* Ignore tooltip frame. */
6813 if (f
== tooltip_frame
)
6816 /* If a window on this frame changed size, report that to
6817 the user and clear the size-change flag. */
6818 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6820 Lisp_Object functions
;
6822 /* Clear flag first in case we get an error below. */
6823 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6824 functions
= Vwindow_size_change_functions
;
6825 GCPRO2 (tail
, functions
);
6827 while (CONSP (functions
))
6829 call1 (XCAR (functions
), frame
);
6830 functions
= XCDR (functions
);
6836 update_menu_bar (f
, 0);
6837 #ifdef HAVE_WINDOW_SYSTEM
6838 update_tool_bar (f
, 0);
6843 unbind_to (count
, Qnil
);
6847 struct frame
*sf
= SELECTED_FRAME ();
6848 update_menu_bar (sf
, 1);
6849 #ifdef HAVE_WINDOW_SYSTEM
6850 update_tool_bar (sf
, 1);
6854 /* Motif needs this. See comment in xmenu.c. Turn it off when
6855 pending_menu_activation is not defined. */
6856 #ifdef USE_X_TOOLKIT
6857 pending_menu_activation
= 0;
6862 /* Update the menu bar item list for frame F. This has to be done
6863 before we start to fill in any display lines, because it can call
6866 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6869 update_menu_bar (f
, save_match_data
)
6871 int save_match_data
;
6874 register struct window
*w
;
6876 window
= FRAME_SELECTED_WINDOW (f
);
6877 w
= XWINDOW (window
);
6879 if (update_mode_lines
)
6880 w
->update_mode_line
= Qt
;
6882 if (FRAME_WINDOW_P (f
)
6884 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
6885 FRAME_EXTERNAL_MENU_BAR (f
)
6887 FRAME_MENU_BAR_LINES (f
) > 0
6889 : FRAME_MENU_BAR_LINES (f
) > 0)
6891 /* If the user has switched buffers or windows, we need to
6892 recompute to reflect the new bindings. But we'll
6893 recompute when update_mode_lines is set too; that means
6894 that people can use force-mode-line-update to request
6895 that the menu bar be recomputed. The adverse effect on
6896 the rest of the redisplay algorithm is about the same as
6897 windows_or_buffers_changed anyway. */
6898 if (windows_or_buffers_changed
6899 || !NILP (w
->update_mode_line
)
6900 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6901 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6902 != !NILP (w
->last_had_star
))
6903 || ((!NILP (Vtransient_mark_mode
)
6904 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6905 != !NILP (w
->region_showing
)))
6907 struct buffer
*prev
= current_buffer
;
6908 int count
= specpdl_ptr
- specpdl
;
6910 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6911 if (save_match_data
)
6912 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6913 if (NILP (Voverriding_local_map_menu_flag
))
6915 specbind (Qoverriding_terminal_local_map
, Qnil
);
6916 specbind (Qoverriding_local_map
, Qnil
);
6919 /* Run the Lucid hook. */
6920 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6922 /* If it has changed current-menubar from previous value,
6923 really recompute the menu-bar from the value. */
6924 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6925 call0 (Qrecompute_lucid_menubar
);
6927 safe_run_hooks (Qmenu_bar_update_hook
);
6928 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6930 /* Redisplay the menu bar in case we changed it. */
6931 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
6932 if (FRAME_WINDOW_P (f
)
6933 #if defined (macintosh)
6934 /* All frames on Mac OS share the same menubar. So only the
6935 selected frame should be allowed to set it. */
6936 && f
== SELECTED_FRAME ()
6939 set_frame_menubar (f
, 0, 0);
6941 /* On a terminal screen, the menu bar is an ordinary screen
6942 line, and this makes it get updated. */
6943 w
->update_mode_line
= Qt
;
6944 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6945 /* In the non-toolkit version, the menu bar is an ordinary screen
6946 line, and this makes it get updated. */
6947 w
->update_mode_line
= Qt
;
6948 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6950 unbind_to (count
, Qnil
);
6951 set_buffer_internal_1 (prev
);
6958 /***********************************************************************
6960 ***********************************************************************/
6962 #ifdef HAVE_WINDOW_SYSTEM
6964 /* Update the tool-bar item list for frame F. This has to be done
6965 before we start to fill in any display lines. Called from
6966 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6967 and restore it here. */
6970 update_tool_bar (f
, save_match_data
)
6972 int save_match_data
;
6974 if (WINDOWP (f
->tool_bar_window
)
6975 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6980 window
= FRAME_SELECTED_WINDOW (f
);
6981 w
= XWINDOW (window
);
6983 /* If the user has switched buffers or windows, we need to
6984 recompute to reflect the new bindings. But we'll
6985 recompute when update_mode_lines is set too; that means
6986 that people can use force-mode-line-update to request
6987 that the menu bar be recomputed. The adverse effect on
6988 the rest of the redisplay algorithm is about the same as
6989 windows_or_buffers_changed anyway. */
6990 if (windows_or_buffers_changed
6991 || !NILP (w
->update_mode_line
)
6992 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6993 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6994 != !NILP (w
->last_had_star
))
6995 || ((!NILP (Vtransient_mark_mode
)
6996 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6997 != !NILP (w
->region_showing
)))
6999 struct buffer
*prev
= current_buffer
;
7000 int count
= specpdl_ptr
- specpdl
;
7002 /* Set current_buffer to the buffer of the selected
7003 window of the frame, so that we get the right local
7005 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7007 /* Save match data, if we must. */
7008 if (save_match_data
)
7009 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7011 /* Make sure that we don't accidentally use bogus keymaps. */
7012 if (NILP (Voverriding_local_map_menu_flag
))
7014 specbind (Qoverriding_terminal_local_map
, Qnil
);
7015 specbind (Qoverriding_local_map
, Qnil
);
7018 /* Build desired tool-bar items from keymaps. */
7019 f
->desired_tool_bar_items
7020 = tool_bar_items (f
->desired_tool_bar_items
,
7021 &f
->n_desired_tool_bar_items
);
7023 /* Redisplay the tool-bar in case we changed it. */
7024 w
->update_mode_line
= Qt
;
7026 unbind_to (count
, Qnil
);
7027 set_buffer_internal_1 (prev
);
7033 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7034 F's desired tool-bar contents. F->desired_tool_bar_items must have
7035 been set up previously by calling prepare_menu_bars. */
7038 build_desired_tool_bar_string (f
)
7041 int i
, size
, size_needed
, string_idx
;
7042 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7043 Lisp_Object image
, plist
, props
;
7045 image
= plist
= props
= Qnil
;
7046 GCPRO3 (image
, plist
, props
);
7048 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7049 Otherwise, make a new string. */
7051 /* The size of the string we might be able to reuse. */
7052 size
= (STRINGP (f
->desired_tool_bar_string
)
7053 ? XSTRING (f
->desired_tool_bar_string
)->size
7056 /* Each image in the string we build is preceded by a space,
7057 and there is a space at the end. */
7058 size_needed
= f
->n_desired_tool_bar_items
+ 1;
7060 /* Reuse f->desired_tool_bar_string, if possible. */
7061 if (size
< size_needed
)
7062 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7066 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7067 Fremove_text_properties (make_number (0), make_number (size
),
7068 props
, f
->desired_tool_bar_string
);
7071 /* Put a `display' property on the string for the images to display,
7072 put a `menu_item' property on tool-bar items with a value that
7073 is the index of the item in F's tool-bar item vector. */
7074 for (i
= 0, string_idx
= 0;
7075 i
< f
->n_desired_tool_bar_items
;
7076 ++i
, string_idx
+= 1)
7079 (XVECTOR (f->desired_tool_bar_items) \
7080 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
7082 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7083 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7084 int margin
, relief
, idx
;
7085 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
7086 extern Lisp_Object Qlaplace
;
7088 /* If image is a vector, choose the image according to the
7090 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7091 if (VECTORP (image
))
7095 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7096 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7099 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7100 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7102 xassert (ASIZE (image
) >= idx
);
7103 image
= AREF (image
, idx
);
7108 /* Ignore invalid image specifications. */
7109 if (!valid_image_p (image
))
7112 /* Display the tool-bar button pressed, or depressed. */
7113 plist
= Fcopy_sequence (XCDR (image
));
7115 /* Compute margin and relief to draw. */
7116 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
7117 margin
= relief
+ max (0, tool_bar_button_margin
);
7119 if (auto_raise_tool_bar_buttons_p
)
7121 /* Add a `:relief' property to the image spec if the item is
7125 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7131 /* If image is selected, display it pressed, i.e. with a
7132 negative relief. If it's not selected, display it with a
7134 plist
= Fplist_put (plist
, QCrelief
,
7136 ? make_number (-relief
)
7137 : make_number (relief
)));
7141 /* Put a margin around the image. */
7143 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
7145 /* If button is not enabled, and we don't have special images
7146 for the disabled state, make the image appear disabled by
7147 applying an appropriate algorithm to it. */
7148 if (!enabled_p
&& idx
< 0)
7149 plist
= Fplist_put (plist
, QCalgorithm
, Qdisabled
);
7151 /* Put a `display' text property on the string for the image to
7152 display. Put a `menu-item' property on the string that gives
7153 the start of this item's properties in the tool-bar items
7155 image
= Fcons (Qimage
, plist
);
7156 props
= list4 (Qdisplay
, image
,
7157 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
7158 Fadd_text_properties (make_number (string_idx
),
7159 make_number (string_idx
+ 1),
7160 props
, f
->desired_tool_bar_string
);
7168 /* Display one line of the tool-bar of frame IT->f. */
7171 display_tool_bar_line (it
)
7174 struct glyph_row
*row
= it
->glyph_row
;
7175 int max_x
= it
->last_visible_x
;
7178 prepare_desired_row (row
);
7179 row
->y
= it
->current_y
;
7181 while (it
->current_x
< max_x
)
7183 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7185 /* Get the next display element. */
7186 if (!get_next_display_element (it
))
7189 /* Produce glyphs. */
7190 x_before
= it
->current_x
;
7191 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7192 PRODUCE_GLYPHS (it
);
7194 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7199 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7201 if (x
+ glyph
->pixel_width
> max_x
)
7203 /* Glyph doesn't fit on line. */
7204 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7210 x
+= glyph
->pixel_width
;
7214 /* Stop at line ends. */
7215 if (ITERATOR_AT_END_OF_LINE_P (it
))
7218 set_iterator_to_next (it
, 1);
7223 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7224 extend_face_to_end_of_line (it
);
7225 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7226 last
->right_box_line_p
= 1;
7227 compute_line_metrics (it
);
7229 /* If line is empty, make it occupy the rest of the tool-bar. */
7230 if (!row
->displays_text_p
)
7232 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7233 row
->ascent
= row
->phys_ascent
= 0;
7236 row
->full_width_p
= 1;
7237 row
->continued_p
= 0;
7238 row
->truncated_on_left_p
= 0;
7239 row
->truncated_on_right_p
= 0;
7241 it
->current_x
= it
->hpos
= 0;
7242 it
->current_y
+= row
->height
;
7248 /* Value is the number of screen lines needed to make all tool-bar
7249 items of frame F visible. */
7252 tool_bar_lines_needed (f
)
7255 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7258 /* Initialize an iterator for iteration over
7259 F->desired_tool_bar_string in the tool-bar window of frame F. */
7260 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7261 it
.first_visible_x
= 0;
7262 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7263 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7265 while (!ITERATOR_AT_END_P (&it
))
7267 it
.glyph_row
= w
->desired_matrix
->rows
;
7268 clear_glyph_row (it
.glyph_row
);
7269 display_tool_bar_line (&it
);
7272 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7276 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
7277 height should be changed. */
7280 redisplay_tool_bar (f
)
7285 struct glyph_row
*row
;
7286 int change_height_p
= 0;
7288 /* If frame hasn't a tool-bar window or if it is zero-height, don't
7289 do anything. This means you must start with tool-bar-lines
7290 non-zero to get the auto-sizing effect. Or in other words, you
7291 can turn off tool-bars by specifying tool-bar-lines zero. */
7292 if (!WINDOWP (f
->tool_bar_window
)
7293 || (w
= XWINDOW (f
->tool_bar_window
),
7294 XFASTINT (w
->height
) == 0))
7297 /* Set up an iterator for the tool-bar window. */
7298 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7299 it
.first_visible_x
= 0;
7300 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7303 /* Build a string that represents the contents of the tool-bar. */
7304 build_desired_tool_bar_string (f
);
7305 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7307 /* Display as many lines as needed to display all tool-bar items. */
7308 while (it
.current_y
< it
.last_visible_y
)
7309 display_tool_bar_line (&it
);
7311 /* It doesn't make much sense to try scrolling in the tool-bar
7312 window, so don't do it. */
7313 w
->desired_matrix
->no_scrolling_p
= 1;
7314 w
->must_be_updated_p
= 1;
7316 if (auto_resize_tool_bars_p
)
7320 /* If there are blank lines at the end, except for a partially
7321 visible blank line at the end that is smaller than
7322 CANON_Y_UNIT, change the tool-bar's height. */
7323 row
= it
.glyph_row
- 1;
7324 if (!row
->displays_text_p
7325 && row
->height
>= CANON_Y_UNIT (f
))
7326 change_height_p
= 1;
7328 /* If row displays tool-bar items, but is partially visible,
7329 change the tool-bar's height. */
7330 if (row
->displays_text_p
7331 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
7332 change_height_p
= 1;
7334 /* Resize windows as needed by changing the `tool-bar-lines'
7337 && (nlines
= tool_bar_lines_needed (f
),
7338 nlines
!= XFASTINT (w
->height
)))
7340 extern Lisp_Object Qtool_bar_lines
;
7342 int old_height
= XFASTINT (w
->height
);
7344 XSETFRAME (frame
, f
);
7345 clear_glyph_matrix (w
->desired_matrix
);
7346 Fmodify_frame_parameters (frame
,
7347 Fcons (Fcons (Qtool_bar_lines
,
7348 make_number (nlines
)),
7350 if (XFASTINT (w
->height
) != old_height
)
7351 fonts_changed_p
= 1;
7355 return change_height_p
;
7359 /* Get information about the tool-bar item which is displayed in GLYPH
7360 on frame F. Return in *PROP_IDX the index where tool-bar item
7361 properties start in F->current_tool_bar_items. Value is zero if
7362 GLYPH doesn't display a tool-bar item. */
7365 tool_bar_item_info (f
, glyph
, prop_idx
)
7367 struct glyph
*glyph
;
7373 /* Get the text property `menu-item' at pos. The value of that
7374 property is the start index of this item's properties in
7375 F->current_tool_bar_items. */
7376 prop
= Fget_text_property (make_number (glyph
->charpos
),
7377 Qmenu_item
, f
->current_tool_bar_string
);
7378 if (INTEGERP (prop
))
7380 *prop_idx
= XINT (prop
);
7389 #endif /* HAVE_WINDOW_SYSTEM */
7393 /************************************************************************
7394 Horizontal scrolling
7395 ************************************************************************/
7397 static int hscroll_window_tree
P_ ((Lisp_Object
));
7398 static int hscroll_windows
P_ ((Lisp_Object
));
7400 /* For all leaf windows in the window tree rooted at WINDOW, set their
7401 hscroll value so that PT is (i) visible in the window, and (ii) so
7402 that it is not within a certain margin at the window's left and
7403 right border. Value is non-zero if any window's hscroll has been
7407 hscroll_window_tree (window
)
7410 int hscrolled_p
= 0;
7412 while (WINDOWP (window
))
7414 struct window
*w
= XWINDOW (window
);
7416 if (WINDOWP (w
->hchild
))
7417 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
7418 else if (WINDOWP (w
->vchild
))
7419 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
7420 else if (w
->cursor
.vpos
>= 0)
7422 int hscroll_margin
, text_area_x
, text_area_y
;
7423 int text_area_width
, text_area_height
;
7424 struct glyph_row
*current_cursor_row
7425 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
7426 struct glyph_row
*desired_cursor_row
7427 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
7428 struct glyph_row
*cursor_row
7429 = (desired_cursor_row
->enabled_p
7430 ? desired_cursor_row
7431 : current_cursor_row
);
7433 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
7434 &text_area_width
, &text_area_height
);
7436 /* Scroll when cursor is inside this scroll margin. */
7437 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
7439 if ((XFASTINT (w
->hscroll
)
7440 && w
->cursor
.x
< hscroll_margin
)
7441 || (cursor_row
->enabled_p
7442 && cursor_row
->truncated_on_right_p
7443 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
7447 struct buffer
*saved_current_buffer
;
7450 /* Find point in a display of infinite width. */
7451 saved_current_buffer
= current_buffer
;
7452 current_buffer
= XBUFFER (w
->buffer
);
7454 if (w
== XWINDOW (selected_window
))
7455 pt
= BUF_PT (current_buffer
);
7458 pt
= marker_position (w
->pointm
);
7459 pt
= max (BEGV
, pt
);
7463 /* Move iterator to pt starting at cursor_row->start in
7464 a line with infinite width. */
7465 init_to_row_start (&it
, w
, cursor_row
);
7466 it
.last_visible_x
= INFINITY
;
7467 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
7468 current_buffer
= saved_current_buffer
;
7470 /* Center cursor in window. */
7471 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
7472 / CANON_X_UNIT (it
.f
));
7474 /* Don't call Fset_window_hscroll if value hasn't
7475 changed because it will prevent redisplay
7477 if (XFASTINT (w
->hscroll
) != hscroll
)
7479 Fset_window_hscroll (window
, make_number (hscroll
));
7488 /* Value is non-zero if hscroll of any leaf window has been changed. */
7493 /* Set hscroll so that cursor is visible and not inside horizontal
7494 scroll margins for all windows in the tree rooted at WINDOW. See
7495 also hscroll_window_tree above. Value is non-zero if any window's
7496 hscroll has been changed. If it has, desired matrices on the frame
7497 of WINDOW are cleared. */
7500 hscroll_windows (window
)
7505 if (automatic_hscrolling_p
)
7507 hscrolled_p
= hscroll_window_tree (window
);
7509 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
7518 /************************************************************************
7520 ************************************************************************/
7522 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
7523 to a non-zero value. This is sometimes handy to have in a debugger
7528 /* First and last unchanged row for try_window_id. */
7530 int debug_first_unchanged_at_end_vpos
;
7531 int debug_last_unchanged_at_beg_vpos
;
7533 /* Delta vpos and y. */
7535 int debug_dvpos
, debug_dy
;
7537 /* Delta in characters and bytes for try_window_id. */
7539 int debug_delta
, debug_delta_bytes
;
7541 /* Values of window_end_pos and window_end_vpos at the end of
7544 int debug_end_pos
, debug_end_vpos
;
7546 /* Append a string to W->desired_matrix->method. FMT is a printf
7547 format string. A1...A9 are a supplement for a variable-length
7548 argument list. If trace_redisplay_p is non-zero also printf the
7549 resulting string to stderr. */
7552 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
7555 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
7558 char *method
= w
->desired_matrix
->method
;
7559 int len
= strlen (method
);
7560 int size
= sizeof w
->desired_matrix
->method
;
7561 int remaining
= size
- len
- 1;
7563 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
7564 if (len
&& remaining
)
7570 strncpy (method
+ len
, buffer
, remaining
);
7572 if (trace_redisplay_p
)
7573 fprintf (stderr
, "%p (%s): %s\n",
7575 ((BUFFERP (w
->buffer
)
7576 && STRINGP (XBUFFER (w
->buffer
)->name
))
7577 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
7582 #endif /* GLYPH_DEBUG */
7585 /* This counter is used to clear the face cache every once in a while
7586 in redisplay_internal. It is incremented for each redisplay.
7587 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
7590 #define CLEAR_FACE_CACHE_COUNT 10000
7591 static int clear_face_cache_count
;
7593 /* Record the previous terminal frame we displayed. */
7595 static struct frame
*previous_terminal_frame
;
7597 /* Non-zero while redisplay_internal is in progress. */
7602 /* Value is non-zero if all changes in window W, which displays
7603 current_buffer, are in the text between START and END. START is a
7604 buffer position, END is given as a distance from Z. Used in
7605 redisplay_internal for display optimization. */
7608 text_outside_line_unchanged_p (w
, start
, end
)
7612 int unchanged_p
= 1;
7614 /* If text or overlays have changed, see where. */
7615 if (XFASTINT (w
->last_modified
) < MODIFF
7616 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7618 /* Gap in the line? */
7619 if (GPT
< start
|| Z
- GPT
< end
)
7622 /* Changes start in front of the line, or end after it? */
7624 && (BEG_UNCHANGED
< start
- 1
7625 || END_UNCHANGED
< end
))
7628 /* If selective display, can't optimize if changes start at the
7629 beginning of the line. */
7631 && INTEGERP (current_buffer
->selective_display
)
7632 && XINT (current_buffer
->selective_display
) > 0
7633 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7641 /* Do a frame update, taking possible shortcuts into account. This is
7642 the main external entry point for redisplay.
7644 If the last redisplay displayed an echo area message and that message
7645 is no longer requested, we clear the echo area or bring back the
7646 mini-buffer if that is in use. */
7651 redisplay_internal (0);
7654 /* Return 1 if point moved out of or into a composition. Otherwise
7655 return 0. PREV_BUF and PREV_PT are the last point buffer and
7656 position. BUF and PT are the current point buffer and position. */
7659 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7660 struct buffer
*prev_buf
, *buf
;
7667 XSETBUFFER (buffer
, buf
);
7668 /* Check a composition at the last point if point moved within the
7670 if (prev_buf
== buf
)
7673 /* Point didn't move. */
7676 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7677 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7678 && COMPOSITION_VALID_P (start
, end
, prop
)
7679 && start
< prev_pt
&& end
> prev_pt
)
7680 /* The last point was within the composition. Return 1 iff
7681 point moved out of the composition. */
7682 return (pt
<= start
|| pt
>= end
);
7685 /* Check a composition at the current point. */
7686 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7687 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7688 && COMPOSITION_VALID_P (start
, end
, prop
)
7689 && start
< pt
&& end
> pt
);
7692 /* Reconsider the setting of B->clip_changed which is displayed
7696 reconsider_clip_changes (w
, b
)
7700 if (b
->prevent_redisplay_optimizations_p
)
7701 b
->clip_changed
= 1;
7702 else if (b
->clip_changed
7703 && !NILP (w
->window_end_valid
)
7704 && w
->current_matrix
->buffer
== b
7705 && w
->current_matrix
->zv
== BUF_ZV (b
)
7706 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7707 b
->clip_changed
= 0;
7709 /* If display wasn't paused, and W is not a tool bar window, see if
7710 point has been moved into or out of a composition. In that case,
7711 we set b->clip_changed to 1 to force updating the screen. If
7712 b->clip_changed has already been set to 1, we can skip this
7714 if (!b
->clip_changed
7715 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7719 if (w
== XWINDOW (selected_window
))
7720 pt
= BUF_PT (current_buffer
);
7722 pt
= marker_position (w
->pointm
);
7724 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7725 || pt
!= XINT (w
->last_point
))
7726 && check_point_in_composition (w
->current_matrix
->buffer
,
7727 XINT (w
->last_point
),
7728 XBUFFER (w
->buffer
), pt
))
7729 b
->clip_changed
= 1;
7734 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7735 response to any user action; therefore, we should preserve the echo
7736 area. (Actually, our caller does that job.) Perhaps in the future
7737 avoid recentering windows if it is not necessary; currently that
7738 causes some problems. */
7741 redisplay_internal (preserve_echo_area
)
7742 int preserve_echo_area
;
7744 struct window
*w
= XWINDOW (selected_window
);
7745 struct frame
*f
= XFRAME (w
->frame
);
7747 int must_finish
= 0;
7748 struct text_pos tlbufpos
, tlendpos
;
7749 int number_of_visible_frames
;
7751 struct frame
*sf
= SELECTED_FRAME ();
7753 /* Non-zero means redisplay has to consider all windows on all
7754 frames. Zero means, only selected_window is considered. */
7755 int consider_all_windows_p
;
7757 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7759 /* No redisplay if running in batch mode or frame is not yet fully
7760 initialized, or redisplay is explicitly turned off by setting
7761 Vinhibit_redisplay. */
7763 || !NILP (Vinhibit_redisplay
)
7764 || !f
->glyphs_initialized_p
)
7767 /* The flag redisplay_performed_directly_p is set by
7768 direct_output_for_insert when it already did the whole screen
7769 update necessary. */
7770 if (redisplay_performed_directly_p
)
7772 redisplay_performed_directly_p
= 0;
7773 if (!hscroll_windows (selected_window
))
7777 #ifdef USE_X_TOOLKIT
7778 if (popup_activated ())
7782 /* I don't think this happens but let's be paranoid. */
7786 /* Record a function that resets redisplaying_p to its old value
7787 when we leave this function. */
7788 count
= specpdl_ptr
- specpdl
;
7789 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7794 reconsider_clip_changes (w
, current_buffer
);
7796 /* If new fonts have been loaded that make a glyph matrix adjustment
7797 necessary, do it. */
7798 if (fonts_changed_p
)
7800 adjust_glyphs (NULL
);
7801 ++windows_or_buffers_changed
;
7802 fonts_changed_p
= 0;
7805 if (! FRAME_WINDOW_P (sf
)
7806 && previous_terminal_frame
!= sf
)
7808 /* Since frames on an ASCII terminal share the same display
7809 area, displaying a different frame means redisplay the whole
7811 windows_or_buffers_changed
++;
7812 SET_FRAME_GARBAGED (sf
);
7813 XSETFRAME (Vterminal_frame
, sf
);
7815 previous_terminal_frame
= sf
;
7817 /* Set the visible flags for all frames. Do this before checking
7818 for resized or garbaged frames; they want to know if their frames
7819 are visible. See the comment in frame.h for
7820 FRAME_SAMPLE_VISIBILITY. */
7822 Lisp_Object tail
, frame
;
7824 number_of_visible_frames
= 0;
7826 FOR_EACH_FRAME (tail
, frame
)
7828 struct frame
*f
= XFRAME (frame
);
7830 FRAME_SAMPLE_VISIBILITY (f
);
7831 if (FRAME_VISIBLE_P (f
))
7832 ++number_of_visible_frames
;
7833 clear_desired_matrices (f
);
7837 /* Notice any pending interrupt request to change frame size. */
7838 do_pending_window_change (1);
7840 /* Clear frames marked as garbaged. */
7842 clear_garbaged_frames ();
7844 /* Build menubar and tool-bar items. */
7845 prepare_menu_bars ();
7847 if (windows_or_buffers_changed
)
7848 update_mode_lines
++;
7850 /* Detect case that we need to write or remove a star in the mode line. */
7851 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7853 w
->update_mode_line
= Qt
;
7854 if (buffer_shared
> 1)
7855 update_mode_lines
++;
7858 /* If %c is in the mode line, update it if needed. */
7859 if (!NILP (w
->column_number_displayed
)
7860 /* This alternative quickly identifies a common case
7861 where no change is needed. */
7862 && !(PT
== XFASTINT (w
->last_point
)
7863 && XFASTINT (w
->last_modified
) >= MODIFF
7864 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7865 && XFASTINT (w
->column_number_displayed
) != current_column ())
7866 w
->update_mode_line
= Qt
;
7868 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7870 /* The variable buffer_shared is set in redisplay_window and
7871 indicates that we redisplay a buffer in different windows. See
7873 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7875 /* If specs for an arrow have changed, do thorough redisplay
7876 to ensure we remove any arrow that should no longer exist. */
7877 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7878 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7879 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7881 /* Normally the message* functions will have already displayed and
7882 updated the echo area, but the frame may have been trashed, or
7883 the update may have been preempted, so display the echo area
7884 again here. Checking both message buffers captures the case that
7885 the echo area should be cleared. */
7886 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7888 int window_height_changed_p
= echo_area_display (0);
7891 if (fonts_changed_p
)
7893 else if (window_height_changed_p
)
7895 consider_all_windows_p
= 1;
7896 ++update_mode_lines
;
7897 ++windows_or_buffers_changed
;
7899 /* If window configuration was changed, frames may have been
7900 marked garbaged. Clear them or we will experience
7901 surprises wrt scrolling. */
7903 clear_garbaged_frames ();
7906 else if (EQ (selected_window
, minibuf_window
)
7907 && (current_buffer
->clip_changed
7908 || XFASTINT (w
->last_modified
) < MODIFF
7909 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7910 && resize_mini_window (w
, 0))
7912 /* Resized active mini-window to fit the size of what it is
7913 showing if its contents might have changed. */
7915 consider_all_windows_p
= 1;
7916 ++windows_or_buffers_changed
;
7917 ++update_mode_lines
;
7919 /* If window configuration was changed, frames may have been
7920 marked garbaged. Clear them or we will experience
7921 surprises wrt scrolling. */
7923 clear_garbaged_frames ();
7927 /* If showing the region, and mark has changed, we must redisplay
7928 the whole window. The assignment to this_line_start_pos prevents
7929 the optimization directly below this if-statement. */
7930 if (((!NILP (Vtransient_mark_mode
)
7931 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7932 != !NILP (w
->region_showing
))
7933 || (!NILP (w
->region_showing
)
7934 && !EQ (w
->region_showing
,
7935 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7936 CHARPOS (this_line_start_pos
) = 0;
7938 /* Optimize the case that only the line containing the cursor in the
7939 selected window has changed. Variables starting with this_ are
7940 set in display_line and record information about the line
7941 containing the cursor. */
7942 tlbufpos
= this_line_start_pos
;
7943 tlendpos
= this_line_end_pos
;
7944 if (!consider_all_windows_p
7945 && CHARPOS (tlbufpos
) > 0
7946 && NILP (w
->update_mode_line
)
7947 && !current_buffer
->clip_changed
7948 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7949 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7950 /* Make sure recorded data applies to current buffer, etc. */
7951 && this_line_buffer
== current_buffer
7952 && current_buffer
== XBUFFER (w
->buffer
)
7953 && NILP (w
->force_start
)
7954 /* Point must be on the line that we have info recorded about. */
7955 && PT
>= CHARPOS (tlbufpos
)
7956 && PT
<= Z
- CHARPOS (tlendpos
)
7957 /* All text outside that line, including its final newline,
7958 must be unchanged */
7959 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7960 CHARPOS (tlendpos
)))
7962 if (CHARPOS (tlbufpos
) > BEGV
7963 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7964 && (CHARPOS (tlbufpos
) == ZV
7965 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7966 /* Former continuation line has disappeared by becoming empty */
7968 else if (XFASTINT (w
->last_modified
) < MODIFF
7969 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7970 || MINI_WINDOW_P (w
))
7972 /* We have to handle the case of continuation around a
7973 wide-column character (See the comment in indent.c around
7976 For instance, in the following case:
7978 -------- Insert --------
7979 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7980 J_I_ ==> J_I_ `^^' are cursors.
7984 As we have to redraw the line above, we should goto cancel. */
7987 int line_height_before
= this_line_pixel_height
;
7989 /* Note that start_display will handle the case that the
7990 line starting at tlbufpos is a continuation lines. */
7991 start_display (&it
, w
, tlbufpos
);
7993 /* Implementation note: It this still necessary? */
7994 if (it
.current_x
!= this_line_start_x
)
7997 TRACE ((stderr
, "trying display optimization 1\n"));
7998 w
->cursor
.vpos
= -1;
7999 overlay_arrow_seen
= 0;
8000 it
.vpos
= this_line_vpos
;
8001 it
.current_y
= this_line_y
;
8002 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
8005 /* If line contains point, is not continued,
8006 and ends at same distance from eob as before, we win */
8007 if (w
->cursor
.vpos
>= 0
8008 /* Line is not continued, otherwise this_line_start_pos
8009 would have been set to 0 in display_line. */
8010 && CHARPOS (this_line_start_pos
)
8011 /* Line ends as before. */
8012 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
8013 /* Line has same height as before. Otherwise other lines
8014 would have to be shifted up or down. */
8015 && this_line_pixel_height
== line_height_before
)
8017 /* If this is not the window's last line, we must adjust
8018 the charstarts of the lines below. */
8019 if (it
.current_y
< it
.last_visible_y
)
8021 struct glyph_row
*row
8022 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
8023 int delta
, delta_bytes
;
8025 if (Z
- CHARPOS (tlendpos
) == ZV
)
8027 /* This line ends at end of (accessible part of)
8028 buffer. There is no newline to count. */
8030 - CHARPOS (tlendpos
)
8031 - MATRIX_ROW_START_CHARPOS (row
));
8032 delta_bytes
= (Z_BYTE
8033 - BYTEPOS (tlendpos
)
8034 - MATRIX_ROW_START_BYTEPOS (row
));
8038 /* This line ends in a newline. Must take
8039 account of the newline and the rest of the
8040 text that follows. */
8042 - CHARPOS (tlendpos
)
8043 - MATRIX_ROW_START_CHARPOS (row
));
8044 delta_bytes
= (Z_BYTE
8045 - BYTEPOS (tlendpos
)
8046 - MATRIX_ROW_START_BYTEPOS (row
));
8049 increment_matrix_positions (w
->current_matrix
,
8051 w
->current_matrix
->nrows
,
8052 delta
, delta_bytes
);
8055 /* If this row displays text now but previously didn't,
8056 or vice versa, w->window_end_vpos may have to be
8058 if ((it
.glyph_row
- 1)->displays_text_p
)
8060 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
8061 XSETINT (w
->window_end_vpos
, this_line_vpos
);
8063 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
8064 && this_line_vpos
> 0)
8065 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
8066 w
->window_end_valid
= Qnil
;
8068 /* Update hint: No need to try to scroll in update_window. */
8069 w
->desired_matrix
->no_scrolling_p
= 1;
8072 *w
->desired_matrix
->method
= 0;
8073 debug_method_add (w
, "optimization 1");
8080 else if (/* Cursor position hasn't changed. */
8081 PT
== XFASTINT (w
->last_point
)
8082 /* Make sure the cursor was last displayed
8083 in this window. Otherwise we have to reposition it. */
8084 && 0 <= w
->cursor
.vpos
8085 && XINT (w
->height
) > w
->cursor
.vpos
)
8089 do_pending_window_change (1);
8091 /* We used to always goto end_of_redisplay here, but this
8092 isn't enough if we have a blinking cursor. */
8093 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
8094 goto end_of_redisplay
;
8098 /* If highlighting the region, or if the cursor is in the echo area,
8099 then we can't just move the cursor. */
8100 else if (! (!NILP (Vtransient_mark_mode
)
8101 && !NILP (current_buffer
->mark_active
))
8102 && (EQ (selected_window
, current_buffer
->last_selected_window
)
8103 || highlight_nonselected_windows
)
8104 && NILP (w
->region_showing
)
8105 && NILP (Vshow_trailing_whitespace
)
8106 && !cursor_in_echo_area
)
8109 struct glyph_row
*row
;
8111 /* Skip from tlbufpos to PT and see where it is. Note that
8112 PT may be in invisible text. If so, we will end at the
8113 next visible position. */
8114 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
8115 NULL
, DEFAULT_FACE_ID
);
8116 it
.current_x
= this_line_start_x
;
8117 it
.current_y
= this_line_y
;
8118 it
.vpos
= this_line_vpos
;
8120 /* The call to move_it_to stops in front of PT, but
8121 moves over before-strings. */
8122 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
8124 if (it
.vpos
== this_line_vpos
8125 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
8128 xassert (this_line_vpos
== it
.vpos
);
8129 xassert (this_line_y
== it
.current_y
);
8130 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8138 /* Text changed drastically or point moved off of line. */
8139 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
8142 CHARPOS (this_line_start_pos
) = 0;
8143 consider_all_windows_p
|= buffer_shared
> 1;
8144 ++clear_face_cache_count
;
8147 /* Build desired matrices, and update the display. If
8148 consider_all_windows_p is non-zero, do it for all windows on all
8149 frames. Otherwise do it for selected_window, only. */
8151 if (consider_all_windows_p
)
8153 Lisp_Object tail
, frame
;
8155 /* Clear the face cache eventually. */
8156 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
8158 clear_face_cache (0);
8159 clear_face_cache_count
= 0;
8162 /* Recompute # windows showing selected buffer. This will be
8163 incremented each time such a window is displayed. */
8166 FOR_EACH_FRAME (tail
, frame
)
8168 struct frame
*f
= XFRAME (frame
);
8170 if (FRAME_WINDOW_P (f
) || f
== sf
)
8172 /* Mark all the scroll bars to be removed; we'll redeem
8173 the ones we want when we redisplay their windows. */
8174 if (condemn_scroll_bars_hook
)
8175 (*condemn_scroll_bars_hook
) (f
);
8177 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8178 redisplay_windows (FRAME_ROOT_WINDOW (f
));
8180 /* Any scroll bars which redisplay_windows should have
8181 nuked should now go away. */
8182 if (judge_scroll_bars_hook
)
8183 (*judge_scroll_bars_hook
) (f
);
8185 /* If fonts changed, display again. */
8186 if (fonts_changed_p
)
8189 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
8191 /* See if we have to hscroll. */
8192 if (hscroll_windows (f
->root_window
))
8195 /* Prevent various kinds of signals during display
8196 update. stdio is not robust about handling
8197 signals, which can cause an apparent I/O
8199 if (interrupt_input
)
8203 /* Update the display. */
8204 set_window_update_flags (XWINDOW (f
->root_window
), 1);
8205 pause
|= update_frame (f
, 0, 0);
8209 mark_window_display_accurate (f
->root_window
, 1);
8210 if (frame_up_to_date_hook
)
8211 frame_up_to_date_hook (f
);
8216 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8218 Lisp_Object mini_window
;
8219 struct frame
*mini_frame
;
8221 redisplay_window (selected_window
, 1);
8223 /* Compare desired and current matrices, perform output. */
8226 /* If fonts changed, display again. */
8227 if (fonts_changed_p
)
8230 /* Prevent various kinds of signals during display update.
8231 stdio is not robust about handling signals,
8232 which can cause an apparent I/O error. */
8233 if (interrupt_input
)
8237 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
8239 if (hscroll_windows (selected_window
))
8242 XWINDOW (selected_window
)->must_be_updated_p
= 1;
8243 pause
= update_frame (sf
, 0, 0);
8246 /* We may have called echo_area_display at the top of this
8247 function. If the echo area is on another frame, that may
8248 have put text on a frame other than the selected one, so the
8249 above call to update_frame would not have caught it. Catch
8251 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8252 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8254 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
8256 XWINDOW (mini_window
)->must_be_updated_p
= 1;
8257 pause
|= update_frame (mini_frame
, 0, 0);
8258 if (!pause
&& hscroll_windows (mini_window
))
8263 /* If display was paused because of pending input, make sure we do a
8264 thorough update the next time. */
8267 /* Prevent the optimization at the beginning of
8268 redisplay_internal that tries a single-line update of the
8269 line containing the cursor in the selected window. */
8270 CHARPOS (this_line_start_pos
) = 0;
8272 /* Let the overlay arrow be updated the next time. */
8273 if (!NILP (last_arrow_position
))
8275 last_arrow_position
= Qt
;
8276 last_arrow_string
= Qt
;
8279 /* If we pause after scrolling, some rows in the current
8280 matrices of some windows are not valid. */
8281 if (!WINDOW_FULL_WIDTH_P (w
)
8282 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
8283 update_mode_lines
= 1;
8286 /* Now text on frame agrees with windows, so put info into the
8287 windows for partial redisplay to follow. */
8290 register struct buffer
*b
= XBUFFER (w
->buffer
);
8292 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
8293 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
8294 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
8295 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
8297 if (consider_all_windows_p
)
8298 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
8301 XSETFASTINT (w
->last_point
, BUF_PT (b
));
8302 w
->last_cursor
= w
->cursor
;
8303 w
->last_cursor_off_p
= w
->cursor_off_p
;
8305 b
->clip_changed
= 0;
8306 b
->prevent_redisplay_optimizations_p
= 0;
8307 w
->update_mode_line
= Qnil
;
8308 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
8309 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
8311 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8314 /* Record if we are showing a region, so can make sure to
8315 update it fully at next redisplay. */
8316 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
8317 && (EQ (selected_window
,
8318 current_buffer
->last_selected_window
)
8319 || highlight_nonselected_windows
)
8320 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
8321 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
8324 w
->window_end_valid
= w
->buffer
;
8325 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8326 last_arrow_string
= Voverlay_arrow_string
;
8327 if (frame_up_to_date_hook
!= 0)
8328 (*frame_up_to_date_hook
) (sf
);
8330 w
->current_matrix
->buffer
= b
;
8331 w
->current_matrix
->begv
= BUF_BEGV (b
);
8332 w
->current_matrix
->zv
= BUF_ZV (b
);
8335 update_mode_lines
= 0;
8336 windows_or_buffers_changed
= 0;
8339 /* Start SIGIO interrupts coming again. Having them off during the
8340 code above makes it less likely one will discard output, but not
8341 impossible, since there might be stuff in the system buffer here.
8342 But it is much hairier to try to do anything about that. */
8343 if (interrupt_input
)
8347 /* If a frame has become visible which was not before, redisplay
8348 again, so that we display it. Expose events for such a frame
8349 (which it gets when becoming visible) don't call the parts of
8350 redisplay constructing glyphs, so simply exposing a frame won't
8351 display anything in this case. So, we have to display these
8352 frames here explicitly. */
8355 Lisp_Object tail
, frame
;
8358 FOR_EACH_FRAME (tail
, frame
)
8360 int this_is_visible
= 0;
8362 if (XFRAME (frame
)->visible
)
8363 this_is_visible
= 1;
8364 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
8365 if (XFRAME (frame
)->visible
)
8366 this_is_visible
= 1;
8368 if (this_is_visible
)
8372 if (new_count
!= number_of_visible_frames
)
8373 windows_or_buffers_changed
++;
8376 /* Change frame size now if a change is pending. */
8377 do_pending_window_change (1);
8379 /* If we just did a pending size change, or have additional
8380 visible frames, redisplay again. */
8381 if (windows_or_buffers_changed
&& !pause
)
8386 unbind_to (count
, Qnil
);
8390 /* Redisplay, but leave alone any recent echo area message unless
8391 another message has been requested in its place.
8393 This is useful in situations where you need to redisplay but no
8394 user action has occurred, making it inappropriate for the message
8395 area to be cleared. See tracking_off and
8396 wait_reading_process_input for examples of these situations. */
8399 redisplay_preserve_echo_area ()
8401 if (!NILP (echo_area_buffer
[1]))
8403 /* We have a previously displayed message, but no current
8404 message. Redisplay the previous message. */
8405 display_last_displayed_message_p
= 1;
8406 redisplay_internal (1);
8407 display_last_displayed_message_p
= 0;
8410 redisplay_internal (1);
8414 /* Function registered with record_unwind_protect in
8415 redisplay_internal. Clears the flag indicating that a redisplay is
8419 unwind_redisplay (old_redisplaying_p
)
8420 Lisp_Object old_redisplaying_p
;
8422 redisplaying_p
= XFASTINT (old_redisplaying_p
);
8427 /* Mark the display of windows in the window tree rooted at WINDOW as
8428 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
8429 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
8430 the next time redisplay_internal is called. */
8433 mark_window_display_accurate (window
, accurate_p
)
8439 for (; !NILP (window
); window
= w
->next
)
8441 w
= XWINDOW (window
);
8443 if (BUFFERP (w
->buffer
))
8445 struct buffer
*b
= XBUFFER (w
->buffer
);
8447 XSETFASTINT (w
->last_modified
,
8448 accurate_p
? BUF_MODIFF (b
) : 0);
8449 XSETFASTINT (w
->last_overlay_modified
,
8450 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
8451 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
8454 #if 0 /* I don't think this is necessary because display_line does it.
8456 /* Record if we are showing a region, so can make sure to
8457 update it fully at next redisplay. */
8459 = (!NILP (Vtransient_mark_mode
)
8460 && (w
== XWINDOW (current_buffer
->last_selected_window
)
8461 || highlight_nonselected_windows
)
8462 && (!NILP (b
->mark_active
)
8463 ? Fmarker_position (b
->mark
)
8469 b
->clip_changed
= 0;
8470 b
->prevent_redisplay_optimizations_p
= 0;
8471 w
->current_matrix
->buffer
= b
;
8472 w
->current_matrix
->begv
= BUF_BEGV (b
);
8473 w
->current_matrix
->zv
= BUF_ZV (b
);
8474 w
->last_cursor
= w
->cursor
;
8475 w
->last_cursor_off_p
= w
->cursor_off_p
;
8476 if (w
== XWINDOW (selected_window
))
8477 w
->last_point
= make_number (BUF_PT (b
));
8479 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
8483 w
->window_end_valid
= w
->buffer
;
8484 w
->update_mode_line
= Qnil
;
8486 if (!NILP (w
->vchild
))
8487 mark_window_display_accurate (w
->vchild
, accurate_p
);
8488 if (!NILP (w
->hchild
))
8489 mark_window_display_accurate (w
->hchild
, accurate_p
);
8494 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
8495 last_arrow_string
= Voverlay_arrow_string
;
8499 /* Force a thorough redisplay the next time by setting
8500 last_arrow_position and last_arrow_string to t, which is
8501 unequal to any useful value of Voverlay_arrow_... */
8502 last_arrow_position
= Qt
;
8503 last_arrow_string
= Qt
;
8508 /* Return value in display table DP (Lisp_Char_Table *) for character
8509 C. Since a display table doesn't have any parent, we don't have to
8510 follow parent. Do not call this function directly but use the
8511 macro DISP_CHAR_VECTOR. */
8514 disp_char_vector (dp
, c
)
8515 struct Lisp_Char_Table
*dp
;
8521 if (SINGLE_BYTE_CHAR_P (c
))
8522 return (dp
->contents
[c
]);
8524 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
8527 else if (code
[2] < 32)
8530 /* Here, the possible range of code[0] (== charset ID) is
8531 128..max_charset. Since the top level char table contains data
8532 for multibyte characters after 256th element, we must increment
8533 code[0] by 128 to get a correct index. */
8535 code
[3] = -1; /* anchor */
8537 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
8539 val
= dp
->contents
[code
[i
]];
8540 if (!SUB_CHAR_TABLE_P (val
))
8541 return (NILP (val
) ? dp
->defalt
: val
);
8544 /* Here, val is a sub char table. We return the default value of
8546 return (dp
->defalt
);
8551 /***********************************************************************
8553 ***********************************************************************/
8555 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
8558 redisplay_windows (window
)
8561 while (!NILP (window
))
8563 struct window
*w
= XWINDOW (window
);
8565 if (!NILP (w
->hchild
))
8566 redisplay_windows (w
->hchild
);
8567 else if (!NILP (w
->vchild
))
8568 redisplay_windows (w
->vchild
);
8570 redisplay_window (window
, 0);
8577 /* Set cursor position of W. PT is assumed to be displayed in ROW.
8578 DELTA is the number of bytes by which positions recorded in ROW
8579 differ from current buffer positions. */
8582 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8584 struct glyph_row
*row
;
8585 struct glyph_matrix
*matrix
;
8586 int delta
, delta_bytes
, dy
, dvpos
;
8588 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8589 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8591 int pt_old
= PT
- delta
;
8593 /* Skip over glyphs not having an object at the start of the row.
8594 These are special glyphs like truncation marks on terminal
8596 if (row
->displays_text_p
)
8598 && INTEGERP (glyph
->object
)
8599 && glyph
->charpos
< 0)
8601 x
+= glyph
->pixel_width
;
8606 && !INTEGERP (glyph
->object
)
8607 && (!BUFFERP (glyph
->object
)
8608 || glyph
->charpos
< pt_old
))
8610 x
+= glyph
->pixel_width
;
8614 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8616 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8617 w
->cursor
.y
= row
->y
+ dy
;
8619 if (w
== XWINDOW (selected_window
))
8621 if (!row
->continued_p
8622 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8625 this_line_buffer
= XBUFFER (w
->buffer
);
8627 CHARPOS (this_line_start_pos
)
8628 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8629 BYTEPOS (this_line_start_pos
)
8630 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8632 CHARPOS (this_line_end_pos
)
8633 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8634 BYTEPOS (this_line_end_pos
)
8635 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8637 this_line_y
= w
->cursor
.y
;
8638 this_line_pixel_height
= row
->height
;
8639 this_line_vpos
= w
->cursor
.vpos
;
8640 this_line_start_x
= row
->x
;
8643 CHARPOS (this_line_start_pos
) = 0;
8648 /* Run window scroll functions, if any, for WINDOW with new window
8649 start STARTP. Sets the window start of WINDOW to that position.
8651 We assume that the window's buffer is really current. */
8653 static INLINE
struct text_pos
8654 run_window_scroll_functions (window
, startp
)
8656 struct text_pos startp
;
8658 struct window
*w
= XWINDOW (window
);
8659 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8661 if (current_buffer
!= XBUFFER (w
->buffer
))
8664 if (!NILP (Vwindow_scroll_functions
))
8666 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8667 make_number (CHARPOS (startp
)));
8668 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8669 /* In case the hook functions switch buffers. */
8670 if (current_buffer
!= XBUFFER (w
->buffer
))
8671 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8678 /* Modify the desired matrix of window W and W->vscroll so that the
8679 line containing the cursor is fully visible. */
8682 make_cursor_line_fully_visible (w
)
8685 struct glyph_matrix
*matrix
;
8686 struct glyph_row
*row
;
8687 int window_height
, header_line_height
;
8689 /* It's not always possible to find the cursor, e.g, when a window
8690 is full of overlay strings. Don't do anything in that case. */
8691 if (w
->cursor
.vpos
< 0)
8694 matrix
= w
->desired_matrix
;
8695 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8697 /* If the cursor row is not partially visible, there's nothing
8699 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8702 /* If the row the cursor is in is taller than the window's height,
8703 it's not clear what to do, so do nothing. */
8704 window_height
= window_box_height (w
);
8705 if (row
->height
>= window_height
)
8708 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
8710 int dy
= row
->height
- row
->visible_height
;
8713 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8715 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
8717 int dy
= - (row
->height
- row
->visible_height
);
8720 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8723 /* When we change the cursor y-position of the selected window,
8724 change this_line_y as well so that the display optimization for
8725 the cursor line of the selected window in redisplay_internal uses
8726 the correct y-position. */
8727 if (w
== XWINDOW (selected_window
))
8728 this_line_y
= w
->cursor
.y
;
8732 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8733 non-zero means only WINDOW is redisplayed in redisplay_internal.
8734 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8735 in redisplay_window to bring a partially visible line into view in
8736 the case that only the cursor has moved.
8740 1 if scrolling succeeded
8742 0 if scrolling didn't find point.
8744 -1 if new fonts have been loaded so that we must interrupt
8745 redisplay, adjust glyph matrices, and try again. */
8748 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8749 scroll_step
, temp_scroll_step
)
8751 int just_this_one_p
;
8752 int scroll_conservatively
, scroll_step
;
8753 int temp_scroll_step
;
8755 struct window
*w
= XWINDOW (window
);
8756 struct frame
*f
= XFRAME (w
->frame
);
8757 struct text_pos scroll_margin_pos
;
8758 struct text_pos pos
;
8759 struct text_pos startp
;
8761 Lisp_Object window_end
;
8762 int this_scroll_margin
;
8766 int amount_to_scroll
= 0;
8767 Lisp_Object aggressive
;
8771 debug_method_add (w
, "try_scrolling");
8774 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8776 /* Compute scroll margin height in pixels. We scroll when point is
8777 within this distance from the top or bottom of the window. */
8778 if (scroll_margin
> 0)
8780 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8781 this_scroll_margin
*= CANON_Y_UNIT (f
);
8784 this_scroll_margin
= 0;
8786 /* Compute how much we should try to scroll maximally to bring point
8788 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
8789 scroll_max
= max (scroll_step
,
8790 max (scroll_conservatively
, temp_scroll_step
));
8791 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8792 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8793 /* We're trying to scroll because of aggressive scrolling
8794 but no scroll_step is set. Choose an arbitrary one. Maybe
8795 there should be a variable for this. */
8799 scroll_max
*= CANON_Y_UNIT (f
);
8801 /* Decide whether we have to scroll down. Start at the window end
8802 and move this_scroll_margin up to find the position of the scroll
8804 window_end
= Fwindow_end (window
, Qt
);
8805 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8806 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8807 if (this_scroll_margin
)
8809 start_display (&it
, w
, scroll_margin_pos
);
8810 move_it_vertically (&it
, - this_scroll_margin
);
8811 scroll_margin_pos
= it
.current
.pos
;
8814 if (PT
>= CHARPOS (scroll_margin_pos
))
8821 /* Point is in the scroll margin at the bottom of the window, or
8822 below. Compute a new window start that makes point visible. */
8824 /* Compute the distance from the scroll margin to PT.
8825 Give up if the distance is greater than scroll_max. */
8826 start_display (&it
, w
, scroll_margin_pos
);
8828 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8829 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8830 #if 0 /* Taking the line's height into account here looks wrong. */
8831 line_height
= (it
.max_ascent
+ it
.max_descent
8832 ? it
.max_ascent
+ it
.max_descent
8834 dy
= it
.current_y
+ line_height
- y0
;
8836 /* With a scroll_margin of 0, scroll_margin_pos is at the window
8837 end, which is one line below the window. The iterator's
8838 current_y will be same as y0 in that case, but we have to
8839 scroll a line to make PT visible. That's the reason why 1 is
8841 dy
= 1 + it
.current_y
- y0
;
8844 if (dy
> scroll_max
)
8847 /* Move the window start down. If scrolling conservatively,
8848 move it just enough down to make point visible. If
8849 scroll_step is set, move it down by scroll_step. */
8850 start_display (&it
, w
, startp
);
8852 if (scroll_conservatively
)
8854 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
8855 else if (scroll_step
|| temp_scroll_step
)
8856 amount_to_scroll
= scroll_max
;
8859 aggressive
= current_buffer
->scroll_down_aggressively
;
8860 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8861 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8862 if (NUMBERP (aggressive
))
8863 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8866 if (amount_to_scroll
<= 0)
8869 move_it_vertically (&it
, amount_to_scroll
);
8870 startp
= it
.current
.pos
;
8874 /* See if point is inside the scroll margin at the top of the
8876 scroll_margin_pos
= startp
;
8877 if (this_scroll_margin
)
8879 start_display (&it
, w
, startp
);
8880 move_it_vertically (&it
, this_scroll_margin
);
8881 scroll_margin_pos
= it
.current
.pos
;
8884 if (PT
< CHARPOS (scroll_margin_pos
))
8886 /* Point is in the scroll margin at the top of the window or
8887 above what is displayed in the window. */
8890 /* Compute the vertical distance from PT to the scroll
8891 margin position. Give up if distance is greater than
8893 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8894 start_display (&it
, w
, pos
);
8896 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8897 it
.last_visible_y
, -1,
8898 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8899 dy
= it
.current_y
- y0
;
8900 if (dy
> scroll_max
)
8903 /* Compute new window start. */
8904 start_display (&it
, w
, startp
);
8906 if (scroll_conservatively
)
8908 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
8909 else if (scroll_step
|| temp_scroll_step
)
8910 amount_to_scroll
= scroll_max
;
8913 aggressive
= current_buffer
->scroll_up_aggressively
;
8914 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8915 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8916 if (NUMBERP (aggressive
))
8917 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8920 if (amount_to_scroll
<= 0)
8923 move_it_vertically (&it
, - amount_to_scroll
);
8924 startp
= it
.current
.pos
;
8928 /* Run window scroll functions. */
8929 startp
= run_window_scroll_functions (window
, startp
);
8931 /* Display the window. Give up if new fonts are loaded, or if point
8933 if (!try_window (window
, startp
))
8935 else if (w
->cursor
.vpos
< 0)
8937 clear_glyph_matrix (w
->desired_matrix
);
8942 /* Maybe forget recorded base line for line number display. */
8943 if (!just_this_one_p
8944 || current_buffer
->clip_changed
8945 || BEG_UNCHANGED
< CHARPOS (startp
))
8946 w
->base_line_number
= Qnil
;
8948 /* If cursor ends up on a partially visible line, shift display
8949 lines up or down. */
8950 make_cursor_line_fully_visible (w
);
8958 /* Compute a suitable window start for window W if display of W starts
8959 on a continuation line. Value is non-zero if a new window start
8962 The new window start will be computed, based on W's width, starting
8963 from the start of the continued line. It is the start of the
8964 screen line with the minimum distance from the old start W->start. */
8967 compute_window_start_on_continuation_line (w
)
8970 struct text_pos pos
, start_pos
;
8971 int window_start_changed_p
= 0;
8973 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8975 /* If window start is on a continuation line... Window start may be
8976 < BEGV in case there's invisible text at the start of the
8977 buffer (M-x rmail, for example). */
8978 if (CHARPOS (start_pos
) > BEGV
8979 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8982 struct glyph_row
*row
;
8984 /* Handle the case that the window start is out of range. */
8985 if (CHARPOS (start_pos
) < BEGV
)
8986 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8987 else if (CHARPOS (start_pos
) > ZV
)
8988 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8990 /* Find the start of the continued line. This should be fast
8991 because scan_buffer is fast (newline cache). */
8992 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8993 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8994 row
, DEFAULT_FACE_ID
);
8995 reseat_at_previous_visible_line_start (&it
);
8997 /* If the line start is "too far" away from the window start,
8998 say it takes too much time to compute a new window start. */
8999 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
9000 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
9002 int min_distance
, distance
;
9004 /* Move forward by display lines to find the new window
9005 start. If window width was enlarged, the new start can
9006 be expected to be > the old start. If window width was
9007 decreased, the new window start will be < the old start.
9008 So, we're looking for the display line start with the
9009 minimum distance from the old window start. */
9010 pos
= it
.current
.pos
;
9011 min_distance
= INFINITY
;
9012 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
9013 distance
< min_distance
)
9015 min_distance
= distance
;
9016 pos
= it
.current
.pos
;
9017 move_it_by_lines (&it
, 1, 0);
9020 /* Set the window start there. */
9021 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
9022 window_start_changed_p
= 1;
9026 return window_start_changed_p
;
9030 /* Try cursor movement in case text has not changes in window WINDOW,
9031 with window start STARTP. Value is
9035 0 if this method cannot be used
9037 -1 if we know we have to scroll the display. *SCROLL_STEP is
9038 set to 1, under certain circumstances, if we want to scroll as
9039 if scroll-step were set to 1. See the code. */
9042 try_cursor_movement (window
, startp
, scroll_step
)
9044 struct text_pos startp
;
9047 struct window
*w
= XWINDOW (window
);
9048 struct frame
*f
= XFRAME (w
->frame
);
9051 /* Handle case where text has not changed, only point, and it has
9052 not moved off the frame. */
9053 if (/* Point may be in this window. */
9054 PT
>= CHARPOS (startp
)
9055 /* If we don't check this, we are called to move the cursor in a
9056 horizontally split window with a current matrix that doesn't
9058 && !windows_or_buffers_changed
9059 /* Selective display hasn't changed. */
9060 && !current_buffer
->clip_changed
9061 /* If force-mode-line-update was called, really redisplay;
9062 that's how redisplay is forced after e.g. changing
9063 buffer-invisibility-spec. */
9064 && NILP (w
->update_mode_line
)
9065 /* Can't use this case if highlighting a region. When a
9066 region exists, cursor movement has to do more than just
9068 && !(!NILP (Vtransient_mark_mode
)
9069 && !NILP (current_buffer
->mark_active
))
9070 && NILP (w
->region_showing
)
9071 && NILP (Vshow_trailing_whitespace
)
9072 /* Right after splitting windows, last_point may be nil. */
9073 && INTEGERP (w
->last_point
)
9074 /* This code is not used for mini-buffer for the sake of the case
9075 of redisplaying to replace an echo area message; since in
9076 that case the mini-buffer contents per se are usually
9077 unchanged. This code is of no real use in the mini-buffer
9078 since the handling of this_line_start_pos, etc., in redisplay
9079 handles the same cases. */
9080 && !EQ (window
, minibuf_window
)
9081 /* When splitting windows or for new windows, it happens that
9082 redisplay is called with a nil window_end_vpos or one being
9083 larger than the window. This should really be fixed in
9084 window.c. I don't have this on my list, now, so we do
9085 approximately the same as the old redisplay code. --gerd. */
9086 && INTEGERP (w
->window_end_vpos
)
9087 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
9088 && (FRAME_WINDOW_P (f
)
9089 || !MARKERP (Voverlay_arrow_position
)
9090 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
9092 int this_scroll_margin
;
9093 struct glyph_row
*row
;
9096 debug_method_add (w
, "cursor movement");
9099 /* Scroll if point within this distance from the top or bottom
9100 of the window. This is a pixel value. */
9101 this_scroll_margin
= max (0, scroll_margin
);
9102 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
9103 this_scroll_margin
*= CANON_Y_UNIT (f
);
9105 /* Start with the row the cursor was displayed during the last
9106 not paused redisplay. Give up if that row is not valid. */
9107 if (w
->last_cursor
.vpos
< 0
9108 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
9112 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
9113 if (row
->mode_line_p
)
9115 if (!row
->enabled_p
)
9122 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
9125 if (PT
> XFASTINT (w
->last_point
))
9127 /* Point has moved forward. */
9128 while (MATRIX_ROW_END_CHARPOS (row
) < PT
9129 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9131 xassert (row
->enabled_p
);
9135 /* The end position of a row equals the start position
9136 of the next row. If PT is there, we would rather
9137 display it in the next line. */
9138 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9139 && MATRIX_ROW_END_CHARPOS (row
) == PT
9140 && !cursor_row_p (w
, row
))
9143 /* If within the scroll margin, scroll. Note that
9144 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
9145 the next line would be drawn, and that
9146 this_scroll_margin can be zero. */
9147 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
9148 || PT
> MATRIX_ROW_END_CHARPOS (row
)
9149 /* Line is completely visible last line in window
9150 and PT is to be set in the next line. */
9151 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
9152 && PT
== MATRIX_ROW_END_CHARPOS (row
)
9153 && !row
->ends_at_zv_p
9154 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
9157 else if (PT
< XFASTINT (w
->last_point
))
9159 /* Cursor has to be moved backward. Note that PT >=
9160 CHARPOS (startp) because of the outer
9162 while (!row
->mode_line_p
9163 && (MATRIX_ROW_START_CHARPOS (row
) > PT
9164 || (MATRIX_ROW_START_CHARPOS (row
) == PT
9165 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
9166 && (row
->y
> this_scroll_margin
9167 || CHARPOS (startp
) == BEGV
))
9169 xassert (row
->enabled_p
);
9173 /* Consider the following case: Window starts at BEGV,
9174 there is invisible, intangible text at BEGV, so that
9175 display starts at some point START > BEGV. It can
9176 happen that we are called with PT somewhere between
9177 BEGV and START. Try to handle that case. */
9178 if (row
< w
->current_matrix
->rows
9179 || row
->mode_line_p
)
9181 row
= w
->current_matrix
->rows
;
9182 if (row
->mode_line_p
)
9186 /* Due to newlines in overlay strings, we may have to
9187 skip forward over overlay strings. */
9188 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
9189 && MATRIX_ROW_END_CHARPOS (row
) == PT
9190 && !cursor_row_p (w
, row
))
9193 /* If within the scroll margin, scroll. */
9194 if (row
->y
< this_scroll_margin
9195 && CHARPOS (startp
) != BEGV
)
9199 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
9200 || PT
> MATRIX_ROW_END_CHARPOS (row
))
9202 /* if PT is not in the glyph row, give up. */
9205 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9207 /* If we end up in a partially visible line, let's make it
9208 fully visible, except when it's taller than the window,
9209 in which case we can't do much about it. */
9210 if (row
->height
> window_box_height (w
))
9217 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9218 try_window (window
, startp
);
9219 make_cursor_line_fully_visible (w
);
9227 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9237 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
9238 selected_window is redisplayed. */
9241 redisplay_window (window
, just_this_one_p
)
9243 int just_this_one_p
;
9245 struct window
*w
= XWINDOW (window
);
9246 struct frame
*f
= XFRAME (w
->frame
);
9247 struct buffer
*buffer
= XBUFFER (w
->buffer
);
9248 struct buffer
*old
= current_buffer
;
9249 struct text_pos lpoint
, opoint
, startp
;
9250 int update_mode_line
;
9253 /* Record it now because it's overwritten. */
9254 int current_matrix_up_to_date_p
= 0;
9255 int temp_scroll_step
= 0;
9256 int count
= specpdl_ptr
- specpdl
;
9259 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9262 /* W must be a leaf window here. */
9263 xassert (!NILP (w
->buffer
));
9265 *w
->desired_matrix
->method
= 0;
9268 specbind (Qinhibit_point_motion_hooks
, Qt
);
9270 reconsider_clip_changes (w
, buffer
);
9272 /* Has the mode line to be updated? */
9273 update_mode_line
= (!NILP (w
->update_mode_line
)
9274 || update_mode_lines
9275 || buffer
->clip_changed
);
9277 if (MINI_WINDOW_P (w
))
9279 if (w
== XWINDOW (echo_area_window
)
9280 && !NILP (echo_area_buffer
[0]))
9282 if (update_mode_line
)
9283 /* We may have to update a tty frame's menu bar or a
9284 tool-bar. Example `M-x C-h C-h C-g'. */
9285 goto finish_menu_bars
;
9287 /* We've already displayed the echo area glyphs in this window. */
9288 goto finish_scroll_bars
;
9290 else if (w
!= XWINDOW (minibuf_window
))
9292 /* W is a mini-buffer window, but it's not the currently
9293 active one, so clear it. */
9294 int yb
= window_text_bottom_y (w
);
9295 struct glyph_row
*row
;
9298 for (y
= 0, row
= w
->desired_matrix
->rows
;
9300 y
+= row
->height
, ++row
)
9301 blank_row (w
, row
, y
);
9302 goto finish_scroll_bars
;
9306 /* Otherwise set up data on this window; select its buffer and point
9308 /* Really select the buffer, for the sake of buffer-local
9310 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9311 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
9313 current_matrix_up_to_date_p
9314 = (!NILP (w
->window_end_valid
)
9315 && !current_buffer
->clip_changed
9316 && XFASTINT (w
->last_modified
) >= MODIFF
9317 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
9319 /* When windows_or_buffers_changed is non-zero, we can't rely on
9320 the window end being valid, so set it to nil there. */
9321 if (windows_or_buffers_changed
)
9323 /* If window starts on a continuation line, maybe adjust the
9324 window start in case the window's width changed. */
9325 if (XMARKER (w
->start
)->buffer
== current_buffer
)
9326 compute_window_start_on_continuation_line (w
);
9328 w
->window_end_valid
= Qnil
;
9331 /* Some sanity checks. */
9332 CHECK_WINDOW_END (w
);
9333 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
9335 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
9338 /* If %c is in mode line, update it if needed. */
9339 if (!NILP (w
->column_number_displayed
)
9340 /* This alternative quickly identifies a common case
9341 where no change is needed. */
9342 && !(PT
== XFASTINT (w
->last_point
)
9343 && XFASTINT (w
->last_modified
) >= MODIFF
9344 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9345 && XFASTINT (w
->column_number_displayed
) != current_column ())
9346 update_mode_line
= 1;
9348 /* Count number of windows showing the selected buffer. An indirect
9349 buffer counts as its base buffer. */
9350 if (!just_this_one_p
)
9352 struct buffer
*current_base
, *window_base
;
9353 current_base
= current_buffer
;
9354 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9355 if (current_base
->base_buffer
)
9356 current_base
= current_base
->base_buffer
;
9357 if (window_base
->base_buffer
)
9358 window_base
= window_base
->base_buffer
;
9359 if (current_base
== window_base
)
9363 /* Point refers normally to the selected window. For any other
9364 window, set up appropriate value. */
9365 if (!EQ (window
, selected_window
))
9367 int new_pt
= XMARKER (w
->pointm
)->charpos
;
9368 int new_pt_byte
= marker_byte_position (w
->pointm
);
9372 new_pt_byte
= BEGV_BYTE
;
9373 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
9375 else if (new_pt
> (ZV
- 1))
9378 new_pt_byte
= ZV_BYTE
;
9379 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
9382 /* We don't use SET_PT so that the point-motion hooks don't run. */
9383 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
9386 /* If any of the character widths specified in the display table
9387 have changed, invalidate the width run cache. It's true that
9388 this may be a bit late to catch such changes, but the rest of
9389 redisplay goes (non-fatally) haywire when the display table is
9390 changed, so why should we worry about doing any better? */
9391 if (current_buffer
->width_run_cache
)
9393 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
9395 if (! disptab_matches_widthtab (disptab
,
9396 XVECTOR (current_buffer
->width_table
)))
9398 invalidate_region_cache (current_buffer
,
9399 current_buffer
->width_run_cache
,
9401 recompute_width_table (current_buffer
, disptab
);
9405 /* If window-start is screwed up, choose a new one. */
9406 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
9409 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9411 /* If someone specified a new starting point but did not insist,
9412 check whether it can be used. */
9413 if (!NILP (w
->optional_new_start
)
9414 && CHARPOS (startp
) >= BEGV
9415 && CHARPOS (startp
) <= ZV
)
9417 w
->optional_new_start
= Qnil
;
9418 start_display (&it
, w
, startp
);
9419 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
9420 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9421 if (IT_CHARPOS (it
) == PT
)
9422 w
->force_start
= Qt
;
9425 /* Handle case where place to start displaying has been specified,
9426 unless the specified location is outside the accessible range. */
9427 if (!NILP (w
->force_start
)
9428 || w
->frozen_window_start_p
)
9430 w
->force_start
= Qnil
;
9432 w
->window_end_valid
= Qnil
;
9434 /* Forget any recorded base line for line number display. */
9435 if (!current_matrix_up_to_date_p
9436 || current_buffer
->clip_changed
)
9437 w
->base_line_number
= Qnil
;
9439 /* Redisplay the mode line. Select the buffer properly for that.
9440 Also, run the hook window-scroll-functions
9441 because we have scrolled. */
9442 /* Note, we do this after clearing force_start because
9443 if there's an error, it is better to forget about force_start
9444 than to get into an infinite loop calling the hook functions
9445 and having them get more errors. */
9446 if (!update_mode_line
9447 || ! NILP (Vwindow_scroll_functions
))
9449 update_mode_line
= 1;
9450 w
->update_mode_line
= Qt
;
9451 startp
= run_window_scroll_functions (window
, startp
);
9454 XSETFASTINT (w
->last_modified
, 0);
9455 XSETFASTINT (w
->last_overlay_modified
, 0);
9456 if (CHARPOS (startp
) < BEGV
)
9457 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
9458 else if (CHARPOS (startp
) > ZV
)
9459 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
9461 /* Redisplay, then check if cursor has been set during the
9462 redisplay. Give up if new fonts were loaded. */
9463 if (!try_window (window
, startp
))
9465 w
->force_start
= Qt
;
9466 clear_glyph_matrix (w
->desired_matrix
);
9467 goto restore_buffers
;
9470 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
9472 /* If point does not appear, try to move point so it does
9473 appear. The desired matrix has been built above, so we
9476 struct glyph_row
*row
;
9478 window_height
= window_box_height (w
) / 2;
9479 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
9480 while (MATRIX_ROW_BOTTOM_Y (row
) < window_height
)
9483 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
9484 MATRIX_ROW_START_BYTEPOS (row
));
9486 if (w
!= XWINDOW (selected_window
))
9487 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
9488 else if (current_buffer
== old
)
9489 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
9491 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
9493 /* If we are highlighting the region, then we just changed
9494 the region, so redisplay to show it. */
9495 if (!NILP (Vtransient_mark_mode
)
9496 && !NILP (current_buffer
->mark_active
))
9498 clear_glyph_matrix (w
->desired_matrix
);
9499 if (!try_window (window
, startp
))
9500 goto restore_buffers
;
9504 make_cursor_line_fully_visible (w
);
9506 debug_method_add (w
, "forced window start");
9511 /* Handle case where text has not changed, only point, and it has
9512 not moved off the frame. */
9513 if (current_matrix_up_to_date_p
9514 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
9522 /* If current starting point was originally the beginning of a line
9523 but no longer is, find a new starting point. */
9524 else if (!NILP (w
->start_at_line_beg
)
9525 && !(CHARPOS (startp
) <= BEGV
9526 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
9529 debug_method_add (w
, "recenter 1");
9534 /* Try scrolling with try_window_id. */
9535 else if (/* Windows and buffers haven't changed. */
9536 !windows_or_buffers_changed
9537 /* Window must be either use window-based redisplay or
9539 && (FRAME_WINDOW_P (f
)
9540 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
9541 && !MINI_WINDOW_P (w
)
9542 /* Point is not known NOT to appear in window. */
9543 && PT
>= CHARPOS (startp
)
9544 && XFASTINT (w
->last_modified
)
9545 /* Window is not hscrolled. */
9546 && XFASTINT (w
->hscroll
) == 0
9547 /* Selective display has not changed. */
9548 && !current_buffer
->clip_changed
9549 /* Current matrix is up to date. */
9550 && !NILP (w
->window_end_valid
)
9551 /* Can't use this case if highlighting a region because
9552 a cursor movement will do more than just set the cursor. */
9553 && !(!NILP (Vtransient_mark_mode
)
9554 && !NILP (current_buffer
->mark_active
))
9555 && NILP (w
->region_showing
)
9556 && NILP (Vshow_trailing_whitespace
)
9557 /* Overlay arrow position and string not changed. */
9558 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
9559 && EQ (last_arrow_string
, Voverlay_arrow_string
)
9560 /* Value is > 0 if update has been done, it is -1 if we
9561 know that the same window start will not work. It is 0
9562 if unsuccessful for some other reason. */
9563 && (tem
= try_window_id (w
)) != 0)
9566 debug_method_add (w
, "try_window_id %d", tem
);
9569 if (fonts_changed_p
)
9570 goto restore_buffers
;
9574 /* Otherwise try_window_id has returned -1 which means that we
9575 don't want the alternative below this comment to execute. */
9577 else if (CHARPOS (startp
) >= BEGV
9578 && CHARPOS (startp
) <= ZV
9579 && PT
>= CHARPOS (startp
)
9580 && (CHARPOS (startp
) < ZV
9581 /* Avoid starting at end of buffer. */
9582 || CHARPOS (startp
) == BEGV
9583 || (XFASTINT (w
->last_modified
) >= MODIFF
9584 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
9587 debug_method_add (w
, "same window start");
9590 /* Try to redisplay starting at same place as before.
9591 If point has not moved off frame, accept the results. */
9592 if (!current_matrix_up_to_date_p
9593 /* Don't use try_window_reusing_current_matrix in this case
9594 because a window scroll function can have changed the
9596 || !NILP (Vwindow_scroll_functions
)
9597 || MINI_WINDOW_P (w
)
9598 || !try_window_reusing_current_matrix (w
))
9600 IF_DEBUG (debug_method_add (w
, "1"));
9601 try_window (window
, startp
);
9604 if (fonts_changed_p
)
9605 goto restore_buffers
;
9607 if (w
->cursor
.vpos
>= 0)
9609 if (!just_this_one_p
9610 || current_buffer
->clip_changed
9611 || BEG_UNCHANGED
< CHARPOS (startp
))
9612 /* Forget any recorded base line for line number display. */
9613 w
->base_line_number
= Qnil
;
9615 make_cursor_line_fully_visible (w
);
9619 clear_glyph_matrix (w
->desired_matrix
);
9624 XSETFASTINT (w
->last_modified
, 0);
9625 XSETFASTINT (w
->last_overlay_modified
, 0);
9627 /* Redisplay the mode line. Select the buffer properly for that. */
9628 if (!update_mode_line
)
9630 update_mode_line
= 1;
9631 w
->update_mode_line
= Qt
;
9634 /* Try to scroll by specified few lines. */
9635 if ((scroll_conservatively
9638 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9639 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9640 && !current_buffer
->clip_changed
9641 && CHARPOS (startp
) >= BEGV
9642 && CHARPOS (startp
) <= ZV
)
9644 /* The function returns -1 if new fonts were loaded, 1 if
9645 successful, 0 if not successful. */
9646 int rc
= try_scrolling (window
, just_this_one_p
,
9647 scroll_conservatively
,
9653 goto restore_buffers
;
9656 /* Finally, just choose place to start which centers point */
9661 debug_method_add (w
, "recenter");
9664 /* w->vscroll = 0; */
9666 /* Forget any previously recorded base line for line number display. */
9667 if (!current_matrix_up_to_date_p
9668 || current_buffer
->clip_changed
)
9669 w
->base_line_number
= Qnil
;
9671 /* Move backward half the height of the window. */
9672 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9673 it
.current_y
= it
.last_visible_y
;
9674 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9675 xassert (IT_CHARPOS (it
) >= BEGV
);
9677 /* The function move_it_vertically_backward may move over more
9678 than the specified y-distance. If it->w is small, e.g. a
9679 mini-buffer window, we may end up in front of the window's
9680 display area. Start displaying at the start of the line
9681 containing PT in this case. */
9682 if (it
.current_y
<= 0)
9684 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9685 move_it_vertically (&it
, 0);
9686 xassert (IT_CHARPOS (it
) <= PT
);
9690 it
.current_x
= it
.hpos
= 0;
9692 /* Set startp here explicitly in case that helps avoid an infinite loop
9693 in case the window-scroll-functions functions get errors. */
9694 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9696 /* Run scroll hooks. */
9697 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9699 /* Redisplay the window. */
9700 if (!current_matrix_up_to_date_p
9701 || windows_or_buffers_changed
9702 /* Don't use try_window_reusing_current_matrix in this case
9703 because it can have changed the buffer. */
9704 || !NILP (Vwindow_scroll_functions
)
9706 || MINI_WINDOW_P (w
)
9707 || !try_window_reusing_current_matrix (w
))
9708 try_window (window
, startp
);
9710 /* If new fonts have been loaded (due to fontsets), give up. We
9711 have to start a new redisplay since we need to re-adjust glyph
9713 if (fonts_changed_p
)
9714 goto restore_buffers
;
9716 /* If cursor did not appear assume that the middle of the window is
9717 in the first line of the window. Do it again with the next line.
9718 (Imagine a window of height 100, displaying two lines of height
9719 60. Moving back 50 from it->last_visible_y will end in the first
9721 if (w
->cursor
.vpos
< 0)
9723 if (!NILP (w
->window_end_valid
)
9724 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9726 clear_glyph_matrix (w
->desired_matrix
);
9727 move_it_by_lines (&it
, 1, 0);
9728 try_window (window
, it
.current
.pos
);
9730 else if (PT
< IT_CHARPOS (it
))
9732 clear_glyph_matrix (w
->desired_matrix
);
9733 move_it_by_lines (&it
, -1, 0);
9734 try_window (window
, it
.current
.pos
);
9738 /* Not much we can do about it. */
9742 /* Consider the following case: Window starts at BEGV, there is
9743 invisible, intangible text at BEGV, so that display starts at
9744 some point START > BEGV. It can happen that we are called with
9745 PT somewhere between BEGV and START. Try to handle that case. */
9746 if (w
->cursor
.vpos
< 0)
9748 struct glyph_row
*row
= w
->current_matrix
->rows
;
9749 if (row
->mode_line_p
)
9751 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9754 make_cursor_line_fully_visible (w
);
9758 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9759 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9760 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9763 /* Display the mode line, if we must. */
9764 if ((update_mode_line
9765 /* If window not full width, must redo its mode line
9766 if (a) the window to its side is being redone and
9767 (b) we do a frame-based redisplay. This is a consequence
9768 of how inverted lines are drawn in frame-based redisplay. */
9769 || (!just_this_one_p
9770 && !FRAME_WINDOW_P (f
)
9771 && !WINDOW_FULL_WIDTH_P (w
))
9772 /* Line number to display. */
9773 || INTEGERP (w
->base_line_pos
)
9774 /* Column number is displayed and different from the one displayed. */
9775 || (!NILP (w
->column_number_displayed
)
9776 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9777 /* This means that the window has a mode line. */
9778 && (WINDOW_WANTS_MODELINE_P (w
)
9779 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9781 Lisp_Object old_selected_frame
;
9783 old_selected_frame
= selected_frame
;
9785 XSETFRAME (selected_frame
, f
);
9786 display_mode_lines (w
);
9787 selected_frame
= old_selected_frame
;
9789 /* If mode line height has changed, arrange for a thorough
9790 immediate redisplay using the correct mode line height. */
9791 if (WINDOW_WANTS_MODELINE_P (w
)
9792 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9794 fonts_changed_p
= 1;
9795 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9796 = DESIRED_MODE_LINE_HEIGHT (w
);
9799 /* If top line height has changed, arrange for a thorough
9800 immediate redisplay using the correct mode line height. */
9801 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9802 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9804 fonts_changed_p
= 1;
9805 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9806 = DESIRED_HEADER_LINE_HEIGHT (w
);
9809 if (fonts_changed_p
)
9810 goto restore_buffers
;
9813 if (!line_number_displayed
9814 && !BUFFERP (w
->base_line_pos
))
9816 w
->base_line_pos
= Qnil
;
9817 w
->base_line_number
= Qnil
;
9822 /* When we reach a frame's selected window, redo the frame's menu bar. */
9823 if (update_mode_line
9824 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9826 int redisplay_menu_p
= 0;
9828 if (FRAME_WINDOW_P (f
))
9830 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
9831 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9833 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9837 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9839 if (redisplay_menu_p
)
9840 display_menu_bar (w
);
9842 #ifdef HAVE_WINDOW_SYSTEM
9843 if (WINDOWP (f
->tool_bar_window
)
9844 && (FRAME_TOOL_BAR_LINES (f
) > 0
9845 || auto_resize_tool_bars_p
))
9846 redisplay_tool_bar (f
);
9852 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9854 int start
, end
, whole
;
9856 /* Calculate the start and end positions for the current window.
9857 At some point, it would be nice to choose between scrollbars
9858 which reflect the whole buffer size, with special markers
9859 indicating narrowing, and scrollbars which reflect only the
9862 Note that mini-buffers sometimes aren't displaying any text. */
9863 if (!MINI_WINDOW_P (w
)
9864 || (w
== XWINDOW (minibuf_window
)
9865 && NILP (echo_area_buffer
[0])))
9868 start
= marker_position (w
->start
) - BEGV
;
9869 /* I don't think this is guaranteed to be right. For the
9870 moment, we'll pretend it is. */
9871 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9875 if (whole
< (end
- start
))
9876 whole
= end
- start
;
9879 start
= end
= whole
= 0;
9881 /* Indicate what this scroll bar ought to be displaying now. */
9882 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9884 /* Note that we actually used the scroll bar attached to this
9885 window, so it shouldn't be deleted at the end of redisplay. */
9886 (*redeem_scroll_bar_hook
) (w
);
9891 /* Restore current_buffer and value of point in it. */
9892 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9893 set_buffer_internal_1 (old
);
9894 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9896 unbind_to (count
, Qnil
);
9900 /* Build the complete desired matrix of WINDOW with a window start
9901 buffer position POS. Value is non-zero if successful. It is zero
9902 if fonts were loaded during redisplay which makes re-adjusting
9903 glyph matrices necessary. */
9906 try_window (window
, pos
)
9908 struct text_pos pos
;
9910 struct window
*w
= XWINDOW (window
);
9912 struct glyph_row
*last_text_row
= NULL
;
9914 /* Make POS the new window start. */
9915 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9917 /* Mark cursor position as unknown. No overlay arrow seen. */
9918 w
->cursor
.vpos
= -1;
9919 overlay_arrow_seen
= 0;
9921 /* Initialize iterator and info to start at POS. */
9922 start_display (&it
, w
, pos
);
9924 /* Display all lines of W. */
9925 while (it
.current_y
< it
.last_visible_y
)
9927 if (display_line (&it
))
9928 last_text_row
= it
.glyph_row
- 1;
9929 if (fonts_changed_p
)
9933 /* If bottom moved off end of frame, change mode line percentage. */
9934 if (XFASTINT (w
->window_end_pos
) <= 0
9935 && Z
!= IT_CHARPOS (it
))
9936 w
->update_mode_line
= Qt
;
9938 /* Set window_end_pos to the offset of the last character displayed
9939 on the window from the end of current_buffer. Set
9940 window_end_vpos to its row number. */
9943 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9944 w
->window_end_bytepos
9945 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9946 XSETFASTINT (w
->window_end_pos
,
9947 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9948 XSETFASTINT (w
->window_end_vpos
,
9949 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9950 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9955 w
->window_end_bytepos
= 0;
9956 XSETFASTINT (w
->window_end_pos
, 0);
9957 XSETFASTINT (w
->window_end_vpos
, 0);
9960 /* But that is not valid info until redisplay finishes. */
9961 w
->window_end_valid
= Qnil
;
9967 /************************************************************************
9968 Window redisplay reusing current matrix when buffer has not changed
9969 ************************************************************************/
9971 /* Try redisplay of window W showing an unchanged buffer with a
9972 different window start than the last time it was displayed by
9973 reusing its current matrix. Value is non-zero if successful.
9974 W->start is the new window start. */
9977 try_window_reusing_current_matrix (w
)
9980 struct frame
*f
= XFRAME (w
->frame
);
9981 struct glyph_row
*row
, *bottom_row
;
9984 struct text_pos start
, new_start
;
9985 int nrows_scrolled
, i
;
9986 struct glyph_row
*last_text_row
;
9987 struct glyph_row
*last_reused_text_row
;
9988 struct glyph_row
*start_row
;
9989 int start_vpos
, min_y
, max_y
;
9991 if (/* This function doesn't handle terminal frames. */
9993 /* Don't try to reuse the display if windows have been split
9995 || windows_or_buffers_changed
)
9998 /* Can't do this if region may have changed. */
9999 if ((!NILP (Vtransient_mark_mode
)
10000 && !NILP (current_buffer
->mark_active
))
10001 || !NILP (w
->region_showing
)
10002 || !NILP (Vshow_trailing_whitespace
))
10005 /* If top-line visibility has changed, give up. */
10006 if (WINDOW_WANTS_HEADER_LINE_P (w
)
10007 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
10010 /* Give up if old or new display is scrolled vertically. We could
10011 make this function handle this, but right now it doesn't. */
10012 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10013 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
10016 /* The variable new_start now holds the new window start. The old
10017 start `start' can be determined from the current matrix. */
10018 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
10019 start
= start_row
->start
.pos
;
10020 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
10022 /* Clear the desired matrix for the display below. */
10023 clear_glyph_matrix (w
->desired_matrix
);
10025 if (CHARPOS (new_start
) <= CHARPOS (start
))
10029 IF_DEBUG (debug_method_add (w
, "twu1"));
10031 /* Display up to a row that can be reused. The variable
10032 last_text_row is set to the last row displayed that displays
10033 text. Note that it.vpos == 0 if or if not there is a
10034 header-line; it's not the same as the MATRIX_ROW_VPOS! */
10035 start_display (&it
, w
, new_start
);
10036 first_row_y
= it
.current_y
;
10037 w
->cursor
.vpos
= -1;
10038 last_text_row
= last_reused_text_row
= NULL
;
10040 while (it
.current_y
< it
.last_visible_y
10041 && IT_CHARPOS (it
) < CHARPOS (start
)
10042 && !fonts_changed_p
)
10043 if (display_line (&it
))
10044 last_text_row
= it
.glyph_row
- 1;
10046 /* A value of current_y < last_visible_y means that we stopped
10047 at the previous window start, which in turn means that we
10048 have at least one reusable row. */
10049 if (it
.current_y
< it
.last_visible_y
)
10051 /* IT.vpos always starts from 0; it counts text lines. */
10052 nrows_scrolled
= it
.vpos
;
10054 /* Find PT if not already found in the lines displayed. */
10055 if (w
->cursor
.vpos
< 0)
10057 int dy
= it
.current_y
- first_row_y
;
10059 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10060 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10062 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
10063 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10065 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
10066 dy
, nrows_scrolled
);
10070 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
10076 /* Give up if point was not found. This shouldn't
10077 happen often; not more often than with try_window
10079 if (w
->cursor
.vpos
< 0)
10081 clear_glyph_matrix (w
->desired_matrix
);
10086 /* Scroll the display. Do it before the current matrix is
10087 changed. The problem here is that update has not yet
10088 run, i.e. part of the current matrix is not up to date.
10089 scroll_run_hook will clear the cursor, and use the
10090 current matrix to get the height of the row the cursor is
10092 run
.current_y
= first_row_y
;
10093 run
.desired_y
= it
.current_y
;
10094 run
.height
= it
.last_visible_y
- it
.current_y
;
10096 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
10099 rif
->update_window_begin_hook (w
);
10100 rif
->clear_mouse_face (w
);
10101 rif
->scroll_run_hook (w
, &run
);
10102 rif
->update_window_end_hook (w
, 0, 0);
10106 /* Shift current matrix down by nrows_scrolled lines. */
10107 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10108 rotate_matrix (w
->current_matrix
,
10110 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10113 /* Disable lines not reused. */
10114 for (i
= 0; i
< it
.vpos
; ++i
)
10115 (start_row
+ i
)->enabled_p
= 0;
10117 /* Re-compute Y positions. */
10118 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10119 max_y
= it
.last_visible_y
;
10120 for (row
= start_row
+ nrows_scrolled
;
10124 row
->y
= it
.current_y
;
10126 if (row
->y
< min_y
)
10127 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10128 else if (row
->y
+ row
->height
> max_y
)
10129 row
->visible_height
10130 = row
->height
- (row
->y
+ row
->height
- max_y
);
10132 row
->visible_height
= row
->height
;
10134 it
.current_y
+= row
->height
;
10136 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10137 last_reused_text_row
= row
;
10138 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
10143 /* Update window_end_pos etc.; last_reused_text_row is the last
10144 reused row from the current matrix containing text, if any.
10145 The value of last_text_row is the last displayed line
10146 containing text. */
10147 if (last_reused_text_row
)
10149 w
->window_end_bytepos
10150 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
10151 XSETFASTINT (w
->window_end_pos
,
10152 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
10153 XSETFASTINT (w
->window_end_vpos
,
10154 MATRIX_ROW_VPOS (last_reused_text_row
,
10155 w
->current_matrix
));
10157 else if (last_text_row
)
10159 w
->window_end_bytepos
10160 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10161 XSETFASTINT (w
->window_end_pos
,
10162 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10163 XSETFASTINT (w
->window_end_vpos
,
10164 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10168 /* This window must be completely empty. */
10169 w
->window_end_bytepos
= 0;
10170 XSETFASTINT (w
->window_end_pos
, 0);
10171 XSETFASTINT (w
->window_end_vpos
, 0);
10173 w
->window_end_valid
= Qnil
;
10175 /* Update hint: don't try scrolling again in update_window. */
10176 w
->desired_matrix
->no_scrolling_p
= 1;
10179 debug_method_add (w
, "try_window_reusing_current_matrix 1");
10183 else if (CHARPOS (new_start
) > CHARPOS (start
))
10185 struct glyph_row
*pt_row
, *row
;
10186 struct glyph_row
*first_reusable_row
;
10187 struct glyph_row
*first_row_to_display
;
10189 int yb
= window_text_bottom_y (w
);
10191 IF_DEBUG (debug_method_add (w
, "twu2"));
10193 /* Find the row starting at new_start, if there is one. Don't
10194 reuse a partially visible line at the end. */
10195 first_reusable_row
= start_row
;
10196 while (first_reusable_row
->enabled_p
10197 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
10198 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10199 < CHARPOS (new_start
)))
10200 ++first_reusable_row
;
10202 /* Give up if there is no row to reuse. */
10203 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
10204 || !first_reusable_row
->enabled_p
10205 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
10206 != CHARPOS (new_start
)))
10209 /* We can reuse fully visible rows beginning with
10210 first_reusable_row to the end of the window. Set
10211 first_row_to_display to the first row that cannot be reused.
10212 Set pt_row to the row containing point, if there is any. */
10213 first_row_to_display
= first_reusable_row
;
10215 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
10217 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
10218 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
10219 pt_row
= first_row_to_display
;
10221 ++first_row_to_display
;
10224 /* Start displaying at the start of first_row_to_display. */
10225 xassert (first_row_to_display
->y
< yb
);
10226 init_to_row_start (&it
, w
, first_row_to_display
);
10227 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
10229 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
10231 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
10232 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10234 /* Display lines beginning with first_row_to_display in the
10235 desired matrix. Set last_text_row to the last row displayed
10236 that displays text. */
10237 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
10238 if (pt_row
== NULL
)
10239 w
->cursor
.vpos
= -1;
10240 last_text_row
= NULL
;
10241 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
10242 if (display_line (&it
))
10243 last_text_row
= it
.glyph_row
- 1;
10245 /* Give up If point isn't in a row displayed or reused. */
10246 if (w
->cursor
.vpos
< 0)
10248 clear_glyph_matrix (w
->desired_matrix
);
10252 /* If point is in a reused row, adjust y and vpos of the cursor
10256 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
10257 w
->current_matrix
);
10258 w
->cursor
.y
-= first_reusable_row
->y
;
10261 /* Scroll the display. */
10262 run
.current_y
= first_reusable_row
->y
;
10263 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10264 run
.height
= it
.last_visible_y
- run
.current_y
;
10265 dy
= run
.current_y
- run
.desired_y
;
10269 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10271 rif
->update_window_begin_hook (w
);
10272 rif
->clear_mouse_face (w
);
10273 rif
->scroll_run_hook (w
, &run
);
10274 rif
->update_window_end_hook (w
, 0, 0);
10278 /* Adjust Y positions of reused rows. */
10279 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
10280 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10281 max_y
= it
.last_visible_y
;
10282 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
10285 if (row
->y
< min_y
)
10286 row
->visible_height
= row
->height
- (min_y
- row
->y
);
10287 else if (row
->y
+ row
->height
> max_y
)
10288 row
->visible_height
10289 = row
->height
- (row
->y
+ row
->height
- max_y
);
10291 row
->visible_height
= row
->height
;
10294 /* Disable rows not reused. */
10295 while (row
< bottom_row
)
10297 row
->enabled_p
= 0;
10301 /* Scroll the current matrix. */
10302 xassert (nrows_scrolled
> 0);
10303 rotate_matrix (w
->current_matrix
,
10305 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
10308 /* Adjust window end. A null value of last_text_row means that
10309 the window end is in reused rows which in turn means that
10310 only its vpos can have changed. */
10313 w
->window_end_bytepos
10314 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10315 XSETFASTINT (w
->window_end_pos
,
10316 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10317 XSETFASTINT (w
->window_end_vpos
,
10318 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
10322 XSETFASTINT (w
->window_end_vpos
,
10323 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
10326 w
->window_end_valid
= Qnil
;
10327 w
->desired_matrix
->no_scrolling_p
= 1;
10330 debug_method_add (w
, "try_window_reusing_current_matrix 2");
10340 /************************************************************************
10341 Window redisplay reusing current matrix when buffer has changed
10342 ************************************************************************/
10344 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
10345 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
10347 static struct glyph_row
*
10348 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
10349 struct glyph_row
*));
10352 /* Return the last row in MATRIX displaying text. If row START is
10353 non-null, start searching with that row. IT gives the dimensions
10354 of the display. Value is null if matrix is empty; otherwise it is
10355 a pointer to the row found. */
10357 static struct glyph_row
*
10358 find_last_row_displaying_text (matrix
, it
, start
)
10359 struct glyph_matrix
*matrix
;
10361 struct glyph_row
*start
;
10363 struct glyph_row
*row
, *row_found
;
10365 /* Set row_found to the last row in IT->w's current matrix
10366 displaying text. The loop looks funny but think of partially
10369 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
10370 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10372 xassert (row
->enabled_p
);
10374 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
10383 /* Return the last row in the current matrix of W that is not affected
10384 by changes at the start of current_buffer that occurred since the
10385 last time W was redisplayed. Value is null if no such row exists.
10387 The global variable beg_unchanged has to contain the number of
10388 bytes unchanged at the start of current_buffer. BEG +
10389 beg_unchanged is the buffer position of the first changed byte in
10390 current_buffer. Characters at positions < BEG + beg_unchanged are
10391 at the same buffer positions as they were when the current matrix
10394 static struct glyph_row
*
10395 find_last_unchanged_at_beg_row (w
)
10398 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
10399 struct glyph_row
*row
;
10400 struct glyph_row
*row_found
= NULL
;
10401 int yb
= window_text_bottom_y (w
);
10403 /* Find the last row displaying unchanged text. */
10404 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10405 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
10406 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
10408 if (/* If row ends before first_changed_pos, it is unchanged,
10409 except in some case. */
10410 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
10411 /* When row ends in ZV and we write at ZV it is not
10413 && !row
->ends_at_zv_p
10414 /* When first_changed_pos is the end of a continued line,
10415 row is not unchanged because it may be no longer
10417 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
10418 && row
->continued_p
))
10421 /* Stop if last visible row. */
10422 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
10432 /* Find the first glyph row in the current matrix of W that is not
10433 affected by changes at the end of current_buffer since the last
10434 time the window was redisplayed. Return in *DELTA the number of
10435 chars by which buffer positions in unchanged text at the end of
10436 current_buffer must be adjusted. Return in *DELTA_BYTES the
10437 corresponding number of bytes. Value is null if no such row
10438 exists, i.e. all rows are affected by changes. */
10440 static struct glyph_row
*
10441 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
10443 int *delta
, *delta_bytes
;
10445 struct glyph_row
*row
;
10446 struct glyph_row
*row_found
= NULL
;
10448 *delta
= *delta_bytes
= 0;
10450 /* Display must not have been paused, otherwise the current matrix
10451 is not up to date. */
10452 if (NILP (w
->window_end_valid
))
10455 /* A value of window_end_pos >= END_UNCHANGED means that the window
10456 end is in the range of changed text. If so, there is no
10457 unchanged row at the end of W's current matrix. */
10458 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
10461 /* Set row to the last row in W's current matrix displaying text. */
10462 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10464 /* If matrix is entirely empty, no unchanged row exists. */
10465 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10467 /* The value of row is the last glyph row in the matrix having a
10468 meaningful buffer position in it. The end position of row
10469 corresponds to window_end_pos. This allows us to translate
10470 buffer positions in the current matrix to current buffer
10471 positions for characters not in changed text. */
10472 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
10473 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
10474 int last_unchanged_pos
, last_unchanged_pos_old
;
10475 struct glyph_row
*first_text_row
10476 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10478 *delta
= Z
- Z_old
;
10479 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
10481 /* Set last_unchanged_pos to the buffer position of the last
10482 character in the buffer that has not been changed. Z is the
10483 index + 1 of the last byte in current_buffer, i.e. by
10484 subtracting end_unchanged we get the index of the last
10485 unchanged character, and we have to add BEG to get its buffer
10487 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
10488 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
10490 /* Search backward from ROW for a row displaying a line that
10491 starts at a minimum position >= last_unchanged_pos_old. */
10492 for (; row
> first_text_row
; --row
)
10494 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
10497 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
10502 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
10509 /* Make sure that glyph rows in the current matrix of window W
10510 reference the same glyph memory as corresponding rows in the
10511 frame's frame matrix. This function is called after scrolling W's
10512 current matrix on a terminal frame in try_window_id and
10513 try_window_reusing_current_matrix. */
10516 sync_frame_with_window_matrix_rows (w
)
10519 struct frame
*f
= XFRAME (w
->frame
);
10520 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
10522 /* Preconditions: W must be a leaf window and full-width. Its frame
10523 must have a frame matrix. */
10524 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
10525 xassert (WINDOW_FULL_WIDTH_P (w
));
10526 xassert (!FRAME_WINDOW_P (f
));
10528 /* If W is a full-width window, glyph pointers in W's current matrix
10529 have, by definition, to be the same as glyph pointers in the
10530 corresponding frame matrix. */
10531 window_row
= w
->current_matrix
->rows
;
10532 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
10533 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
10534 while (window_row
< window_row_end
)
10538 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
10539 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
10541 /* Disable frame rows whose corresponding window rows have
10542 been disabled in try_window_id. */
10543 if (!window_row
->enabled_p
)
10544 frame_row
->enabled_p
= 0;
10546 ++window_row
, ++frame_row
;
10551 /* Find the glyph row in window W containing CHARPOS. Consider all
10552 rows between START and END (not inclusive). END null means search
10553 all rows to the end of the display area of W. Value is the row
10554 containing CHARPOS or null. */
10556 static struct glyph_row
*
10557 row_containing_pos (w
, charpos
, start
, end
)
10560 struct glyph_row
*start
, *end
;
10562 struct glyph_row
*row
= start
;
10565 /* If we happen to start on a header-line, skip that. */
10566 if (row
->mode_line_p
)
10569 if ((end
&& row
>= end
) || !row
->enabled_p
)
10572 last_y
= window_text_bottom_y (w
);
10574 while ((end
== NULL
|| row
< end
)
10575 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
10576 /* The end position of a row equals the start
10577 position of the next row. If CHARPOS is there, we
10578 would rather display it in the next line, except
10579 when this line ends in ZV. */
10580 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
10581 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
10582 || !row
->ends_at_zv_p
)))
10583 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10586 /* Give up if CHARPOS not found. */
10587 if ((end
&& row
>= end
)
10588 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
10589 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
10596 /* Try to redisplay window W by reusing its existing display. W's
10597 current matrix must be up to date when this function is called,
10598 i.e. window_end_valid must not be nil.
10602 1 if display has been updated
10603 0 if otherwise unsuccessful
10604 -1 if redisplay with same window start is known not to succeed
10606 The following steps are performed:
10608 1. Find the last row in the current matrix of W that is not
10609 affected by changes at the start of current_buffer. If no such row
10612 2. Find the first row in W's current matrix that is not affected by
10613 changes at the end of current_buffer. Maybe there is no such row.
10615 3. Display lines beginning with the row + 1 found in step 1 to the
10616 row found in step 2 or, if step 2 didn't find a row, to the end of
10619 4. If cursor is not known to appear on the window, give up.
10621 5. If display stopped at the row found in step 2, scroll the
10622 display and current matrix as needed.
10624 6. Maybe display some lines at the end of W, if we must. This can
10625 happen under various circumstances, like a partially visible line
10626 becoming fully visible, or because newly displayed lines are displayed
10627 in smaller font sizes.
10629 7. Update W's window end information. */
10631 /* Check that window end is what we expect it to be. */
10637 struct frame
*f
= XFRAME (w
->frame
);
10638 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
10639 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
10640 struct glyph_row
*last_unchanged_at_beg_row
;
10641 struct glyph_row
*first_unchanged_at_end_row
;
10642 struct glyph_row
*row
;
10643 struct glyph_row
*bottom_row
;
10646 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
10647 struct text_pos start_pos
;
10649 int first_unchanged_at_end_vpos
= 0;
10650 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10651 struct text_pos start
;
10653 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10655 /* Check pre-conditions. Window end must be valid, otherwise
10656 the current matrix would not be up to date. */
10657 xassert (!NILP (w
->window_end_valid
));
10658 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10659 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10661 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10662 only if buffer has really changed. The reason is that the gap is
10663 initially at Z for freshly visited files. The code below would
10664 set end_unchanged to 0 in that case. */
10665 if (MODIFF
> SAVE_MODIFF
10666 /* This seems to happen sometimes after saving a buffer. */
10667 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10669 if (GPT
- BEG
< BEG_UNCHANGED
)
10670 BEG_UNCHANGED
= GPT
- BEG
;
10671 if (Z
- GPT
< END_UNCHANGED
)
10672 END_UNCHANGED
= Z
- GPT
;
10675 /* If window starts after a line end, and the last change is in
10676 front of that newline, then changes don't affect the display.
10677 This case happens with stealth-fontification. Note that although
10678 the display is unchanged, glyph positions in the matrix have to
10679 be adjusted, of course. */
10680 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10681 if (CHARPOS (start
) > BEGV
10682 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10683 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10684 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10686 struct glyph_row
*r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
10687 int delta
= CHARPOS (start
) - MATRIX_ROW_START_CHARPOS (r0
);
10691 struct glyph_row
*r1
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10692 int delta_bytes
= BYTEPOS (start
) - MATRIX_ROW_START_BYTEPOS (r0
);
10694 increment_matrix_positions (w
->current_matrix
,
10695 MATRIX_ROW_VPOS (r0
, current_matrix
),
10696 MATRIX_ROW_VPOS (r1
, current_matrix
),
10697 delta
, delta_bytes
);
10700 #if 0 /* If changes are all in front of the window start, the
10701 distance of the last displayed glyph from Z hasn't
10704 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10705 w
->window_end_bytepos
10706 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10712 /* Return quickly if changes are all below what is displayed in the
10713 window, and if PT is in the window. */
10714 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10715 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10717 /* We have to update window end positions because the buffer's
10718 size has changed. */
10720 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10721 w
->window_end_bytepos
10722 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10724 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10725 row
= row_containing_pos (w
, PT
, row
, NULL
);
10726 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10730 /* Check that window start agrees with the start of the first glyph
10731 row in its current matrix. Check this after we know the window
10732 start is not in changed text, otherwise positions would not be
10734 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10735 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10738 /* Compute the position at which we have to start displaying new
10739 lines. Some of the lines at the top of the window might be
10740 reusable because they are not displaying changed text. Find the
10741 last row in W's current matrix not affected by changes at the
10742 start of current_buffer. Value is null if changes start in the
10743 first line of window. */
10744 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
10745 if (last_unchanged_at_beg_row
)
10747 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10748 start_pos
= it
.current
.pos
;
10750 /* Start displaying new lines in the desired matrix at the same
10751 vpos we would use in the current matrix, i.e. below
10752 last_unchanged_at_beg_row. */
10753 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10755 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10756 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10758 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10762 /* There are no reusable lines at the start of the window.
10763 Start displaying in the first line. */
10764 start_display (&it
, w
, start
);
10765 start_pos
= it
.current
.pos
;
10768 /* Find the first row that is not affected by changes at the end of
10769 the buffer. Value will be null if there is no unchanged row, in
10770 which case we must redisplay to the end of the window. delta
10771 will be set to the value by which buffer positions beginning with
10772 first_unchanged_at_end_row have to be adjusted due to text
10774 first_unchanged_at_end_row
10775 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10776 IF_DEBUG (debug_delta
= delta
);
10777 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10779 /* Set stop_pos to the buffer position up to which we will have to
10780 display new lines. If first_unchanged_at_end_row != NULL, this
10781 is the buffer position of the start of the line displayed in that
10782 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10783 that we don't stop at a buffer position. */
10785 if (first_unchanged_at_end_row
)
10787 xassert (last_unchanged_at_beg_row
== NULL
10788 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10790 /* If this is a continuation line, move forward to the next one
10791 that isn't. Changes in lines above affect this line.
10792 Caution: this may move first_unchanged_at_end_row to a row
10793 not displaying text. */
10794 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10795 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10796 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10797 < it
.last_visible_y
))
10798 ++first_unchanged_at_end_row
;
10800 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10801 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10802 >= it
.last_visible_y
))
10803 first_unchanged_at_end_row
= NULL
;
10806 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10808 first_unchanged_at_end_vpos
10809 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10810 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10813 else if (last_unchanged_at_beg_row
== NULL
)
10819 /* Either there is no unchanged row at the end, or the one we have
10820 now displays text. This is a necessary condition for the window
10821 end pos calculation at the end of this function. */
10822 xassert (first_unchanged_at_end_row
== NULL
10823 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10825 debug_last_unchanged_at_beg_vpos
10826 = (last_unchanged_at_beg_row
10827 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10829 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10831 #endif /* GLYPH_DEBUG != 0 */
10834 /* Display new lines. Set last_text_row to the last new line
10835 displayed which has text on it, i.e. might end up as being the
10836 line where the window_end_vpos is. */
10837 w
->cursor
.vpos
= -1;
10838 last_text_row
= NULL
;
10839 overlay_arrow_seen
= 0;
10840 while (it
.current_y
< it
.last_visible_y
10841 && !fonts_changed_p
10842 && (first_unchanged_at_end_row
== NULL
10843 || IT_CHARPOS (it
) < stop_pos
))
10845 if (display_line (&it
))
10846 last_text_row
= it
.glyph_row
- 1;
10849 if (fonts_changed_p
)
10853 /* Compute differences in buffer positions, y-positions etc. for
10854 lines reused at the bottom of the window. Compute what we can
10856 if (first_unchanged_at_end_row
10857 /* No lines reused because we displayed everything up to the
10858 bottom of the window. */
10859 && it
.current_y
< it
.last_visible_y
)
10862 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10864 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10865 run
.current_y
= first_unchanged_at_end_row
->y
;
10866 run
.desired_y
= run
.current_y
+ dy
;
10867 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10871 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10872 first_unchanged_at_end_row
= NULL
;
10874 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10877 /* Find the cursor if not already found. We have to decide whether
10878 PT will appear on this window (it sometimes doesn't, but this is
10879 not a very frequent case.) This decision has to be made before
10880 the current matrix is altered. A value of cursor.vpos < 0 means
10881 that PT is either in one of the lines beginning at
10882 first_unchanged_at_end_row or below the window. Don't care for
10883 lines that might be displayed later at the window end; as
10884 mentioned, this is not a frequent case. */
10885 if (w
->cursor
.vpos
< 0)
10887 /* Cursor in unchanged rows at the top? */
10888 if (PT
< CHARPOS (start_pos
)
10889 && last_unchanged_at_beg_row
)
10891 row
= row_containing_pos (w
, PT
,
10892 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10893 last_unchanged_at_beg_row
+ 1);
10895 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10898 /* Start from first_unchanged_at_end_row looking for PT. */
10899 else if (first_unchanged_at_end_row
)
10901 row
= row_containing_pos (w
, PT
- delta
,
10902 first_unchanged_at_end_row
, NULL
);
10904 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10905 delta_bytes
, dy
, dvpos
);
10908 /* Give up if cursor was not found. */
10909 if (w
->cursor
.vpos
< 0)
10911 clear_glyph_matrix (w
->desired_matrix
);
10916 /* Don't let the cursor end in the scroll margins. */
10918 int this_scroll_margin
, cursor_height
;
10920 this_scroll_margin
= max (0, scroll_margin
);
10921 this_scroll_margin
= min (this_scroll_margin
,
10922 XFASTINT (w
->height
) / 4);
10923 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10924 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10926 if ((w
->cursor
.y
< this_scroll_margin
10927 && CHARPOS (start
) > BEGV
)
10928 /* Don't take scroll margin into account at the bottom because
10929 old redisplay didn't do it either. */
10930 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10932 w
->cursor
.vpos
= -1;
10933 clear_glyph_matrix (w
->desired_matrix
);
10938 /* Scroll the display. Do it before changing the current matrix so
10939 that xterm.c doesn't get confused about where the cursor glyph is
10941 if (dy
&& run
.height
)
10945 if (FRAME_WINDOW_P (f
))
10947 rif
->update_window_begin_hook (w
);
10948 rif
->clear_mouse_face (w
);
10949 rif
->scroll_run_hook (w
, &run
);
10950 rif
->update_window_end_hook (w
, 0, 0);
10954 /* Terminal frame. In this case, dvpos gives the number of
10955 lines to scroll by; dvpos < 0 means scroll up. */
10956 int first_unchanged_at_end_vpos
10957 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10958 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10959 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10961 /* Perform the operation on the screen. */
10964 /* Scroll last_unchanged_at_beg_row to the end of the
10965 window down dvpos lines. */
10966 set_terminal_window (end
);
10968 /* On dumb terminals delete dvpos lines at the end
10969 before inserting dvpos empty lines. */
10970 if (!scroll_region_ok
)
10971 ins_del_lines (end
- dvpos
, -dvpos
);
10973 /* Insert dvpos empty lines in front of
10974 last_unchanged_at_beg_row. */
10975 ins_del_lines (from
, dvpos
);
10977 else if (dvpos
< 0)
10979 /* Scroll up last_unchanged_at_beg_vpos to the end of
10980 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10981 set_terminal_window (end
);
10983 /* Delete dvpos lines in front of
10984 last_unchanged_at_beg_vpos. ins_del_lines will set
10985 the cursor to the given vpos and emit |dvpos| delete
10987 ins_del_lines (from
+ dvpos
, dvpos
);
10989 /* On a dumb terminal insert dvpos empty lines at the
10991 if (!scroll_region_ok
)
10992 ins_del_lines (end
+ dvpos
, -dvpos
);
10995 set_terminal_window (0);
11001 /* Shift reused rows of the current matrix to the right position.
11002 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
11004 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
11005 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
11008 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
11009 bottom_vpos
, dvpos
);
11010 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
11013 else if (dvpos
> 0)
11015 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
11016 bottom_vpos
, dvpos
);
11017 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
11018 first_unchanged_at_end_vpos
+ dvpos
, 0);
11021 /* For frame-based redisplay, make sure that current frame and window
11022 matrix are in sync with respect to glyph memory. */
11023 if (!FRAME_WINDOW_P (f
))
11024 sync_frame_with_window_matrix_rows (w
);
11026 /* Adjust buffer positions in reused rows. */
11028 increment_matrix_positions (current_matrix
,
11029 first_unchanged_at_end_vpos
+ dvpos
,
11030 bottom_vpos
, delta
, delta_bytes
);
11032 /* Adjust Y positions. */
11034 shift_glyph_matrix (w
, current_matrix
,
11035 first_unchanged_at_end_vpos
+ dvpos
,
11038 if (first_unchanged_at_end_row
)
11039 first_unchanged_at_end_row
+= dvpos
;
11041 /* If scrolling up, there may be some lines to display at the end of
11043 last_text_row_at_end
= NULL
;
11046 /* Set last_row to the glyph row in the current matrix where the
11047 window end line is found. It has been moved up or down in
11048 the matrix by dvpos. */
11049 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
11050 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
11052 /* If last_row is the window end line, it should display text. */
11053 xassert (last_row
->displays_text_p
);
11055 /* If window end line was partially visible before, begin
11056 displaying at that line. Otherwise begin displaying with the
11057 line following it. */
11058 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
11060 init_to_row_start (&it
, w
, last_row
);
11061 it
.vpos
= last_vpos
;
11062 it
.current_y
= last_row
->y
;
11066 init_to_row_end (&it
, w
, last_row
);
11067 it
.vpos
= 1 + last_vpos
;
11068 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
11072 /* We may start in a continuation line. If so, we have to get
11073 the right continuation_lines_width and current_x. */
11074 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
11075 it
.hpos
= it
.current_x
= 0;
11077 /* Display the rest of the lines at the window end. */
11078 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
11079 while (it
.current_y
< it
.last_visible_y
11080 && !fonts_changed_p
)
11082 /* Is it always sure that the display agrees with lines in
11083 the current matrix? I don't think so, so we mark rows
11084 displayed invalid in the current matrix by setting their
11085 enabled_p flag to zero. */
11086 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
11087 if (display_line (&it
))
11088 last_text_row_at_end
= it
.glyph_row
- 1;
11092 /* Update window_end_pos and window_end_vpos. */
11093 if (first_unchanged_at_end_row
11094 && first_unchanged_at_end_row
->y
< it
.last_visible_y
11095 && !last_text_row_at_end
)
11097 /* Window end line if one of the preserved rows from the current
11098 matrix. Set row to the last row displaying text in current
11099 matrix starting at first_unchanged_at_end_row, after
11101 xassert (first_unchanged_at_end_row
->displays_text_p
);
11102 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
11103 first_unchanged_at_end_row
);
11104 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
11106 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
11107 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
11108 XSETFASTINT (w
->window_end_vpos
,
11109 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
11111 else if (last_text_row_at_end
)
11113 XSETFASTINT (w
->window_end_pos
,
11114 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
11115 w
->window_end_bytepos
11116 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
11117 XSETFASTINT (w
->window_end_vpos
,
11118 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
11120 else if (last_text_row
)
11122 /* We have displayed either to the end of the window or at the
11123 end of the window, i.e. the last row with text is to be found
11124 in the desired matrix. */
11125 XSETFASTINT (w
->window_end_pos
,
11126 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11127 w
->window_end_bytepos
11128 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11129 XSETFASTINT (w
->window_end_vpos
,
11130 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
11132 else if (first_unchanged_at_end_row
== NULL
11133 && last_text_row
== NULL
11134 && last_text_row_at_end
== NULL
)
11136 /* Displayed to end of window, but no line containing text was
11137 displayed. Lines were deleted at the end of the window. */
11139 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
11141 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
11142 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11143 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
11144 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
11145 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
11148 w
->window_end_vpos
= make_number (vpos
);
11153 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
11154 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
11156 /* Record that display has not been completed. */
11157 w
->window_end_valid
= Qnil
;
11158 w
->desired_matrix
->no_scrolling_p
= 1;
11164 /***********************************************************************
11165 More debugging support
11166 ***********************************************************************/
11170 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
11171 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
11174 /* Dump the contents of glyph matrix MATRIX on stderr. If
11175 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
11178 dump_glyph_matrix (matrix
, with_glyphs_p
)
11179 struct glyph_matrix
*matrix
;
11183 for (i
= 0; i
< matrix
->nrows
; ++i
)
11184 dump_glyph_row (matrix
, i
, with_glyphs_p
);
11188 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
11189 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
11192 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
11193 struct glyph_matrix
*matrix
;
11194 int vpos
, with_glyphs_p
;
11196 struct glyph_row
*row
;
11198 if (vpos
< 0 || vpos
>= matrix
->nrows
)
11201 row
= MATRIX_ROW (matrix
, vpos
);
11203 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFes X Y W H V A P\n");
11204 fprintf (stderr
, "=======================================================================\n");
11206 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d\
11207 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
11208 row
- matrix
->rows
,
11209 MATRIX_ROW_START_CHARPOS (row
),
11210 MATRIX_ROW_END_CHARPOS (row
),
11211 row
->used
[TEXT_AREA
],
11212 row
->contains_overlapping_glyphs_p
,
11215 row
->truncated_on_left_p
,
11216 row
->truncated_on_right_p
,
11217 row
->overlay_arrow_p
,
11219 MATRIX_ROW_CONTINUATION_LINE_P (row
),
11220 row
->displays_text_p
,
11223 row
->ends_in_middle_of_char_p
,
11224 row
->starts_in_middle_of_char_p
,
11229 row
->visible_height
,
11232 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
11233 row
->end
.overlay_string_index
);
11234 fprintf (stderr
, "%9d %5d\n",
11235 CHARPOS (row
->start
.string_pos
),
11236 CHARPOS (row
->end
.string_pos
));
11237 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
11238 row
->end
.dpvec_index
);
11242 struct glyph
*glyph
, *glyph_end
;
11243 int prev_had_glyphs_p
;
11245 glyph
= row
->glyphs
[TEXT_AREA
];
11246 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
11248 /* Glyph for a line end in text. */
11249 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
11252 if (glyph
< glyph_end
)
11254 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
11255 prev_had_glyphs_p
= 1;
11258 prev_had_glyphs_p
= 0;
11260 while (glyph
< glyph_end
)
11262 if (glyph
->type
== CHAR_GLYPH
)
11265 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11266 glyph
- row
->glyphs
[TEXT_AREA
],
11269 (BUFFERP (glyph
->object
)
11271 : (STRINGP (glyph
->object
)
11274 glyph
->pixel_width
,
11276 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
11280 glyph
->left_box_line_p
,
11281 glyph
->right_box_line_p
);
11283 else if (glyph
->type
== STRETCH_GLYPH
)
11286 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11287 glyph
- row
->glyphs
[TEXT_AREA
],
11290 (BUFFERP (glyph
->object
)
11292 : (STRINGP (glyph
->object
)
11295 glyph
->pixel_width
,
11299 glyph
->left_box_line_p
,
11300 glyph
->right_box_line_p
);
11302 else if (glyph
->type
== IMAGE_GLYPH
)
11305 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
11306 glyph
- row
->glyphs
[TEXT_AREA
],
11309 (BUFFERP (glyph
->object
)
11311 : (STRINGP (glyph
->object
)
11314 glyph
->pixel_width
,
11318 glyph
->left_box_line_p
,
11319 glyph
->right_box_line_p
);
11327 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
11328 Sdump_glyph_matrix
, 0, 1, "p",
11329 "Dump the current matrix of the selected window to stderr.\n\
11330 Shows contents of glyph row structures. With non-nil optional\n\
11331 parameter WITH-GLYPHS-P, dump glyphs as well.")
11333 Lisp_Object with_glyphs_p
;
11335 struct window
*w
= XWINDOW (selected_window
);
11336 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11338 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
11339 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
11340 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
11341 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
11342 fprintf (stderr
, "=============================================\n");
11343 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
11348 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
11349 "Dump glyph row ROW to stderr.")
11353 CHECK_NUMBER (row
, 0);
11354 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
11359 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
11363 struct frame
*sf
= SELECTED_FRAME ();
11364 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
11366 dump_glyph_row (m
, 0, 1);
11371 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
11372 Strace_redisplay_toggle
, 0, 0, "",
11373 "Toggle tracing of redisplay.")
11376 trace_redisplay_p
= !trace_redisplay_p
;
11381 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
11382 "Print STRING to stderr.")
11384 Lisp_Object string
;
11386 CHECK_STRING (string
, 0);
11387 fprintf (stderr
, "%s", XSTRING (string
)->data
);
11391 #endif /* GLYPH_DEBUG */
11395 /***********************************************************************
11396 Building Desired Matrix Rows
11397 ***********************************************************************/
11399 /* Return a temporary glyph row holding the glyphs of an overlay
11400 arrow. Only used for non-window-redisplay windows. */
11402 static struct glyph_row
*
11403 get_overlay_arrow_glyph_row (w
)
11406 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11407 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11408 struct buffer
*old
= current_buffer
;
11409 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
11410 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
11411 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
11415 int n_glyphs_before
;
11417 set_buffer_temp (buffer
);
11418 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
11419 it
.glyph_row
->used
[TEXT_AREA
] = 0;
11420 SET_TEXT_POS (it
.position
, 0, 0);
11422 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
11424 while (p
< arrow_end
)
11426 Lisp_Object face
, ilisp
;
11428 /* Get the next character. */
11430 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
11432 it
.c
= *p
, it
.len
= 1;
11435 /* Get its face. */
11436 XSETFASTINT (ilisp
, p
- arrow_string
);
11437 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
11438 it
.face_id
= compute_char_face (f
, it
.c
, face
);
11440 /* Compute its width, get its glyphs. */
11441 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
11442 SET_TEXT_POS (it
.position
, -1, -1);
11443 PRODUCE_GLYPHS (&it
);
11445 /* If this character doesn't fit any more in the line, we have
11446 to remove some glyphs. */
11447 if (it
.current_x
> it
.last_visible_x
)
11449 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
11454 set_buffer_temp (old
);
11455 return it
.glyph_row
;
11459 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
11460 glyphs are only inserted for terminal frames since we can't really
11461 win with truncation glyphs when partially visible glyphs are
11462 involved. Which glyphs to insert is determined by
11463 produce_special_glyphs. */
11466 insert_left_trunc_glyphs (it
)
11469 struct it truncate_it
;
11470 struct glyph
*from
, *end
, *to
, *toend
;
11472 xassert (!FRAME_WINDOW_P (it
->f
));
11474 /* Get the truncation glyphs. */
11476 truncate_it
.current_x
= 0;
11477 truncate_it
.face_id
= DEFAULT_FACE_ID
;
11478 truncate_it
.glyph_row
= &scratch_glyph_row
;
11479 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
11480 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
11481 truncate_it
.object
= make_number (0);
11482 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
11484 /* Overwrite glyphs from IT with truncation glyphs. */
11485 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
11486 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
11487 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
11488 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
11493 /* There may be padding glyphs left over. Remove them. */
11495 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
11497 while (from
< toend
)
11500 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
11504 /* Compute the pixel height and width of IT->glyph_row.
11506 Most of the time, ascent and height of a display line will be equal
11507 to the max_ascent and max_height values of the display iterator
11508 structure. This is not the case if
11510 1. We hit ZV without displaying anything. In this case, max_ascent
11511 and max_height will be zero.
11513 2. We have some glyphs that don't contribute to the line height.
11514 (The glyph row flag contributes_to_line_height_p is for future
11515 pixmap extensions).
11517 The first case is easily covered by using default values because in
11518 these cases, the line height does not really matter, except that it
11519 must not be zero. */
11522 compute_line_metrics (it
)
11525 struct glyph_row
*row
= it
->glyph_row
;
11528 if (FRAME_WINDOW_P (it
->f
))
11530 int i
, header_line_height
;
11532 /* The line may consist of one space only, that was added to
11533 place the cursor on it. If so, the row's height hasn't been
11535 if (row
->height
== 0)
11537 if (it
->max_ascent
+ it
->max_descent
== 0)
11538 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
11539 row
->ascent
= it
->max_ascent
;
11540 row
->height
= it
->max_ascent
+ it
->max_descent
;
11541 row
->phys_ascent
= it
->max_phys_ascent
;
11542 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11545 /* Compute the width of this line. */
11546 row
->pixel_width
= row
->x
;
11547 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
11548 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11550 xassert (row
->pixel_width
>= 0);
11551 xassert (row
->ascent
>= 0 && row
->height
> 0);
11553 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
11554 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
11556 /* If first line's physical ascent is larger than its logical
11557 ascent, use the physical ascent, and make the row taller.
11558 This makes accented characters fully visible. */
11559 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
11560 && row
->phys_ascent
> row
->ascent
)
11562 row
->height
+= row
->phys_ascent
- row
->ascent
;
11563 row
->ascent
= row
->phys_ascent
;
11566 /* Compute how much of the line is visible. */
11567 row
->visible_height
= row
->height
;
11569 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
11570 if (row
->y
< header_line_height
)
11571 row
->visible_height
-= header_line_height
- row
->y
;
11574 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
11575 if (row
->y
+ row
->height
> max_y
)
11576 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11581 row
->pixel_width
= row
->used
[TEXT_AREA
];
11582 row
->ascent
= row
->phys_ascent
= 0;
11583 row
->height
= row
->phys_height
= row
->visible_height
= 1;
11586 /* Compute a hash code for this row. */
11588 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
11589 for (i
= 0; i
< row
->used
[area
]; ++i
)
11590 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
11591 + row
->glyphs
[area
][i
].u
.val
11592 + row
->glyphs
[area
][i
].face_id
11593 + row
->glyphs
[area
][i
].padding_p
11594 + (row
->glyphs
[area
][i
].type
<< 2));
11596 it
->max_ascent
= it
->max_descent
= 0;
11597 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
11601 /* Append one space to the glyph row of iterator IT if doing a
11602 window-based redisplay. DEFAULT_FACE_P non-zero means let the
11603 space have the default face, otherwise let it have the same face as
11604 IT->face_id. Value is non-zero if a space was added.
11606 This function is called to make sure that there is always one glyph
11607 at the end of a glyph row that the cursor can be set on under
11608 window-systems. (If there weren't such a glyph we would not know
11609 how wide and tall a box cursor should be displayed).
11611 At the same time this space let's a nicely handle clearing to the
11612 end of the line if the row ends in italic text. */
11615 append_space (it
, default_face_p
)
11617 int default_face_p
;
11619 if (FRAME_WINDOW_P (it
->f
))
11621 int n
= it
->glyph_row
->used
[TEXT_AREA
];
11623 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
11624 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
11626 /* Save some values that must not be changed.
11627 Must save IT->c and IT->len because otherwise
11628 ITERATOR_AT_END_P wouldn't work anymore after
11629 append_space has been called. */
11630 int saved_what
= it
->what
;
11631 int saved_c
= it
->c
, saved_len
= it
->len
;
11632 int saved_x
= it
->current_x
;
11633 int saved_face_id
= it
->face_id
;
11634 struct text_pos saved_pos
;
11635 Lisp_Object saved_object
;
11638 saved_object
= it
->object
;
11639 saved_pos
= it
->position
;
11641 it
->what
= IT_CHARACTER
;
11642 bzero (&it
->position
, sizeof it
->position
);
11643 it
->object
= make_number (0);
11647 if (default_face_p
)
11648 it
->face_id
= DEFAULT_FACE_ID
;
11649 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
11650 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
11652 PRODUCE_GLYPHS (it
);
11654 it
->current_x
= saved_x
;
11655 it
->object
= saved_object
;
11656 it
->position
= saved_pos
;
11657 it
->what
= saved_what
;
11658 it
->face_id
= saved_face_id
;
11659 it
->len
= saved_len
;
11669 /* Extend the face of the last glyph in the text area of IT->glyph_row
11670 to the end of the display line. Called from display_line.
11671 If the glyph row is empty, add a space glyph to it so that we
11672 know the face to draw. Set the glyph row flag fill_line_p. */
11675 extend_face_to_end_of_line (it
)
11679 struct frame
*f
= it
->f
;
11681 /* If line is already filled, do nothing. */
11682 if (it
->current_x
>= it
->last_visible_x
)
11685 /* Face extension extends the background and box of IT->face_id
11686 to the end of the line. If the background equals the background
11687 of the frame, we haven't to do anything. */
11688 face
= FACE_FROM_ID (f
, it
->face_id
);
11689 if (FRAME_WINDOW_P (f
)
11690 && face
->box
== FACE_NO_BOX
11691 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
11695 /* Set the glyph row flag indicating that the face of the last glyph
11696 in the text area has to be drawn to the end of the text area. */
11697 it
->glyph_row
->fill_line_p
= 1;
11699 /* If current character of IT is not ASCII, make sure we have the
11700 ASCII face. This will be automatically undone the next time
11701 get_next_display_element returns a multibyte character. Note
11702 that the character will always be single byte in unibyte text. */
11703 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11705 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11708 if (FRAME_WINDOW_P (f
))
11710 /* If the row is empty, add a space with the current face of IT,
11711 so that we know which face to draw. */
11712 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11714 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11715 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11716 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11721 /* Save some values that must not be changed. */
11722 int saved_x
= it
->current_x
;
11723 struct text_pos saved_pos
;
11724 Lisp_Object saved_object
;
11725 int saved_what
= it
->what
;
11727 saved_object
= it
->object
;
11728 saved_pos
= it
->position
;
11730 it
->what
= IT_CHARACTER
;
11731 bzero (&it
->position
, sizeof it
->position
);
11732 it
->object
= make_number (0);
11736 PRODUCE_GLYPHS (it
);
11738 while (it
->current_x
<= it
->last_visible_x
)
11739 PRODUCE_GLYPHS (it
);
11741 /* Don't count these blanks really. It would let us insert a left
11742 truncation glyph below and make us set the cursor on them, maybe. */
11743 it
->current_x
= saved_x
;
11744 it
->object
= saved_object
;
11745 it
->position
= saved_pos
;
11746 it
->what
= saved_what
;
11751 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11752 trailing whitespace. */
11755 trailing_whitespace_p (charpos
)
11758 int bytepos
= CHAR_TO_BYTE (charpos
);
11761 while (bytepos
< ZV_BYTE
11762 && (c
= FETCH_CHAR (bytepos
),
11763 c
== ' ' || c
== '\t'))
11766 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11768 if (bytepos
!= PT_BYTE
)
11775 /* Highlight trailing whitespace, if any, in ROW. */
11778 highlight_trailing_whitespace (f
, row
)
11780 struct glyph_row
*row
;
11782 int used
= row
->used
[TEXT_AREA
];
11786 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11787 struct glyph
*glyph
= start
+ used
- 1;
11789 /* Skip over the space glyph inserted to display the
11790 cursor at the end of a line. */
11791 if (glyph
->type
== CHAR_GLYPH
11792 && glyph
->u
.ch
== ' '
11793 && INTEGERP (glyph
->object
))
11796 /* If last glyph is a space or stretch, and it's trailing
11797 whitespace, set the face of all trailing whitespace glyphs in
11798 IT->glyph_row to `trailing-whitespace'. */
11800 && BUFFERP (glyph
->object
)
11801 && (glyph
->type
== STRETCH_GLYPH
11802 || (glyph
->type
== CHAR_GLYPH
11803 && glyph
->u
.ch
== ' '))
11804 && trailing_whitespace_p (glyph
->charpos
))
11806 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11808 while (glyph
>= start
11809 && BUFFERP (glyph
->object
)
11810 && (glyph
->type
== STRETCH_GLYPH
11811 || (glyph
->type
== CHAR_GLYPH
11812 && glyph
->u
.ch
== ' ')))
11813 (glyph
--)->face_id
= face_id
;
11819 /* Value is non-zero if glyph row ROW in window W should be
11820 used to put the cursor on. */
11823 cursor_row_p (w
, row
)
11825 struct glyph_row
*row
;
11827 int cursor_row_p
= 1;
11829 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
11831 /* If the row ends with a newline from a string, we don't want
11832 the cursor there (if the row is continued it doesn't end in a
11834 if (CHARPOS (row
->end
.string_pos
) >= 0
11835 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11836 cursor_row_p
= row
->continued_p
;
11838 /* If the row ends at ZV, display the cursor at the end of that
11839 row instead of at the start of the row below. */
11840 else if (row
->ends_at_zv_p
)
11846 return cursor_row_p
;
11850 /* Construct the glyph row IT->glyph_row in the desired matrix of
11851 IT->w from text at the current position of IT. See dispextern.h
11852 for an overview of struct it. Value is non-zero if
11853 IT->glyph_row displays text, as opposed to a line displaying ZV
11860 struct glyph_row
*row
= it
->glyph_row
;
11862 /* We always start displaying at hpos zero even if hscrolled. */
11863 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11865 /* We must not display in a row that's not a text row. */
11866 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11867 < it
->w
->desired_matrix
->nrows
);
11869 /* Is IT->w showing the region? */
11870 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11872 /* Clear the result glyph row and enable it. */
11873 prepare_desired_row (row
);
11875 row
->y
= it
->current_y
;
11876 row
->start
= it
->current
;
11877 row
->continuation_lines_width
= it
->continuation_lines_width
;
11878 row
->displays_text_p
= 1;
11879 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
11880 it
->starts_in_middle_of_char_p
= 0;
11882 /* Arrange the overlays nicely for our purposes. Usually, we call
11883 display_line on only one line at a time, in which case this
11884 can't really hurt too much, or we call it on lines which appear
11885 one after another in the buffer, in which case all calls to
11886 recenter_overlay_lists but the first will be pretty cheap. */
11887 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11889 /* Move over display elements that are not visible because we are
11890 hscrolled. This may stop at an x-position < IT->first_visible_x
11891 if the first glyph is partially visible or if we hit a line end. */
11892 if (it
->current_x
< it
->first_visible_x
)
11893 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11894 MOVE_TO_POS
| MOVE_TO_X
);
11896 /* Get the initial row height. This is either the height of the
11897 text hscrolled, if there is any, or zero. */
11898 row
->ascent
= it
->max_ascent
;
11899 row
->height
= it
->max_ascent
+ it
->max_descent
;
11900 row
->phys_ascent
= it
->max_phys_ascent
;
11901 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11903 /* Loop generating characters. The loop is left with IT on the next
11904 character to display. */
11907 int n_glyphs_before
, hpos_before
, x_before
;
11909 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
11911 /* Retrieve the next thing to display. Value is zero if end of
11913 if (!get_next_display_element (it
))
11915 /* Maybe add a space at the end of this line that is used to
11916 display the cursor there under X. Set the charpos of the
11917 first glyph of blank lines not corresponding to any text
11919 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11920 || row
->used
[TEXT_AREA
] == 0)
11922 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11923 row
->displays_text_p
= 0;
11925 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11926 row
->indicate_empty_line_p
= 1;
11929 it
->continuation_lines_width
= 0;
11930 row
->ends_at_zv_p
= 1;
11934 /* Now, get the metrics of what we want to display. This also
11935 generates glyphs in `row' (which is IT->glyph_row). */
11936 n_glyphs_before
= row
->used
[TEXT_AREA
];
11939 /* Remember the line height so far in case the next element doesn't
11940 fit on the line. */
11941 if (!it
->truncate_lines_p
)
11943 ascent
= it
->max_ascent
;
11944 descent
= it
->max_descent
;
11945 phys_ascent
= it
->max_phys_ascent
;
11946 phys_descent
= it
->max_phys_descent
;
11949 PRODUCE_GLYPHS (it
);
11951 /* If this display element was in marginal areas, continue with
11953 if (it
->area
!= TEXT_AREA
)
11955 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11956 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11957 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11958 row
->phys_height
= max (row
->phys_height
,
11959 it
->max_phys_ascent
+ it
->max_phys_descent
);
11960 set_iterator_to_next (it
, 1);
11964 /* Does the display element fit on the line? If we truncate
11965 lines, we should draw past the right edge of the window. If
11966 we don't truncate, we want to stop so that we can display the
11967 continuation glyph before the right margin. If lines are
11968 continued, there are two possible strategies for characters
11969 resulting in more than 1 glyph (e.g. tabs): Display as many
11970 glyphs as possible in this line and leave the rest for the
11971 continuation line, or display the whole element in the next
11972 line. Original redisplay did the former, so we do it also. */
11973 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11974 hpos_before
= it
->hpos
;
11978 && it
->current_x
< it
->last_visible_x
)
11981 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11982 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11983 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11984 row
->phys_height
= max (row
->phys_height
,
11985 it
->max_phys_ascent
+ it
->max_phys_descent
);
11986 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11987 row
->x
= x
- it
->first_visible_x
;
11992 struct glyph
*glyph
;
11994 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11996 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11997 new_x
= x
+ glyph
->pixel_width
;
11999 if (/* Lines are continued. */
12000 !it
->truncate_lines_p
12001 && (/* Glyph doesn't fit on the line. */
12002 new_x
> it
->last_visible_x
12003 /* Or it fits exactly on a window system frame. */
12004 || (new_x
== it
->last_visible_x
12005 && FRAME_WINDOW_P (it
->f
))))
12007 /* End of a continued line. */
12010 || (new_x
== it
->last_visible_x
12011 && FRAME_WINDOW_P (it
->f
)))
12013 /* Current glyph is the only one on the line or
12014 fits exactly on the line. We must continue
12015 the line because we can't draw the cursor
12016 after the glyph. */
12017 row
->continued_p
= 1;
12018 it
->current_x
= new_x
;
12019 it
->continuation_lines_width
+= new_x
;
12021 if (i
== nglyphs
- 1)
12022 set_iterator_to_next (it
, 1);
12024 else if (CHAR_GLYPH_PADDING_P (*glyph
)
12025 && !FRAME_WINDOW_P (it
->f
))
12027 /* A padding glyph that doesn't fit on this line.
12028 This means the whole character doesn't fit
12030 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12032 /* Fill the rest of the row with continuation
12033 glyphs like in 20.x. */
12034 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
12035 < row
->glyphs
[1 + TEXT_AREA
])
12036 produce_special_glyphs (it
, IT_CONTINUATION
);
12038 row
->continued_p
= 1;
12039 it
->current_x
= x_before
;
12040 it
->continuation_lines_width
+= x_before
;
12042 /* Restore the height to what it was before the
12043 element not fitting on the line. */
12044 it
->max_ascent
= ascent
;
12045 it
->max_descent
= descent
;
12046 it
->max_phys_ascent
= phys_ascent
;
12047 it
->max_phys_descent
= phys_descent
;
12051 /* Display element draws past the right edge of
12052 the window. Restore positions to values
12053 before the element. The next line starts
12054 with current_x before the glyph that could
12055 not be displayed, so that TAB works right. */
12056 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12058 /* Display continuation glyphs. */
12059 if (!FRAME_WINDOW_P (it
->f
))
12060 produce_special_glyphs (it
, IT_CONTINUATION
);
12061 row
->continued_p
= 1;
12064 it
->continuation_lines_width
+= x
;
12065 if (nglyphs
> 1 && i
> 0)
12067 row
->ends_in_middle_of_char_p
= 1;
12068 it
->starts_in_middle_of_char_p
= 1;
12071 /* Restore the height to what it was before the
12072 element not fitting on the line. */
12073 it
->max_ascent
= ascent
;
12074 it
->max_descent
= descent
;
12075 it
->max_phys_ascent
= phys_ascent
;
12076 it
->max_phys_descent
= phys_descent
;
12081 else if (new_x
> it
->first_visible_x
)
12083 /* Increment number of glyphs actually displayed. */
12086 if (x
< it
->first_visible_x
)
12087 /* Glyph is partially visible, i.e. row starts at
12088 negative X position. */
12089 row
->x
= x
- it
->first_visible_x
;
12093 /* Glyph is completely off the left margin of the
12094 window. This should not happen because of the
12095 move_it_in_display_line at the start of
12101 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12102 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12103 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12104 row
->phys_height
= max (row
->phys_height
,
12105 it
->max_phys_ascent
+ it
->max_phys_descent
);
12107 /* End of this display line if row is continued. */
12108 if (row
->continued_p
)
12112 /* Is this a line end? If yes, we're also done, after making
12113 sure that a non-default face is extended up to the right
12114 margin of the window. */
12115 if (ITERATOR_AT_END_OF_LINE_P (it
))
12117 int used_before
= row
->used
[TEXT_AREA
];
12119 /* Add a space at the end of the line that is used to
12120 display the cursor there. */
12121 append_space (it
, 0);
12123 /* Extend the face to the end of the line. */
12124 extend_face_to_end_of_line (it
);
12126 /* Make sure we have the position. */
12127 if (used_before
== 0)
12128 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
12130 /* Consume the line end. This skips over invisible lines. */
12131 set_iterator_to_next (it
, 1);
12132 it
->continuation_lines_width
= 0;
12136 /* Proceed with next display element. Note that this skips
12137 over lines invisible because of selective display. */
12138 set_iterator_to_next (it
, 1);
12140 /* If we truncate lines, we are done when the last displayed
12141 glyphs reach past the right margin of the window. */
12142 if (it
->truncate_lines_p
12143 && (FRAME_WINDOW_P (it
->f
)
12144 ? (it
->current_x
>= it
->last_visible_x
)
12145 : (it
->current_x
> it
->last_visible_x
)))
12147 /* Maybe add truncation glyphs. */
12148 if (!FRAME_WINDOW_P (it
->f
))
12150 --it
->glyph_row
->used
[TEXT_AREA
];
12151 produce_special_glyphs (it
, IT_TRUNCATION
);
12154 row
->truncated_on_right_p
= 1;
12155 it
->continuation_lines_width
= 0;
12156 reseat_at_next_visible_line_start (it
, 0);
12157 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
12158 it
->hpos
= hpos_before
;
12159 it
->current_x
= x_before
;
12164 /* If line is not empty and hscrolled, maybe insert truncation glyphs
12165 at the left window margin. */
12166 if (it
->first_visible_x
12167 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
12169 if (!FRAME_WINDOW_P (it
->f
))
12170 insert_left_trunc_glyphs (it
);
12171 row
->truncated_on_left_p
= 1;
12174 /* If the start of this line is the overlay arrow-position, then
12175 mark this glyph row as the one containing the overlay arrow.
12176 This is clearly a mess with variable size fonts. It would be
12177 better to let it be displayed like cursors under X. */
12178 if (MARKERP (Voverlay_arrow_position
)
12179 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
12180 && (MATRIX_ROW_START_CHARPOS (row
)
12181 == marker_position (Voverlay_arrow_position
))
12182 && STRINGP (Voverlay_arrow_string
)
12183 && ! overlay_arrow_seen
)
12185 /* Overlay arrow in window redisplay is a bitmap. */
12186 if (!FRAME_WINDOW_P (it
->f
))
12188 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
12189 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
12190 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
12191 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
12192 struct glyph
*p2
, *end
;
12194 /* Copy the arrow glyphs. */
12195 while (glyph
< arrow_end
)
12198 /* Throw away padding glyphs. */
12200 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
12201 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
12207 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
12211 overlay_arrow_seen
= 1;
12212 row
->overlay_arrow_p
= 1;
12215 /* Compute pixel dimensions of this line. */
12216 compute_line_metrics (it
);
12218 /* Remember the position at which this line ends. */
12219 row
->end
= it
->current
;
12221 /* Maybe set the cursor. */
12222 if (it
->w
->cursor
.vpos
< 0
12223 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
12224 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
12225 && cursor_row_p (it
->w
, row
))
12226 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
12228 /* Highlight trailing whitespace. */
12229 if (!NILP (Vshow_trailing_whitespace
))
12230 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
12232 /* Prepare for the next line. This line starts horizontally at (X
12233 HPOS) = (0 0). Vertical positions are incremented. As a
12234 convenience for the caller, IT->glyph_row is set to the next
12236 it
->current_x
= it
->hpos
= 0;
12237 it
->current_y
+= row
->height
;
12240 return row
->displays_text_p
;
12245 /***********************************************************************
12247 ***********************************************************************/
12249 /* Redisplay the menu bar in the frame for window W.
12251 The menu bar of X frames that don't have X toolkit support is
12252 displayed in a special window W->frame->menu_bar_window.
12254 The menu bar of terminal frames is treated specially as far as
12255 glyph matrices are concerned. Menu bar lines are not part of
12256 windows, so the update is done directly on the frame matrix rows
12257 for the menu bar. */
12260 display_menu_bar (w
)
12263 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12268 /* Don't do all this for graphical frames. */
12270 if (!NILP (Vwindow_system
))
12273 #ifdef USE_X_TOOLKIT
12278 if (FRAME_MAC_P (f
))
12282 #ifdef USE_X_TOOLKIT
12283 xassert (!FRAME_WINDOW_P (f
));
12284 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
12285 it
.first_visible_x
= 0;
12286 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12287 #else /* not USE_X_TOOLKIT */
12288 if (FRAME_WINDOW_P (f
))
12290 /* Menu bar lines are displayed in the desired matrix of the
12291 dummy window menu_bar_window. */
12292 struct window
*menu_w
;
12293 xassert (WINDOWP (f
->menu_bar_window
));
12294 menu_w
= XWINDOW (f
->menu_bar_window
);
12295 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
12297 it
.first_visible_x
= 0;
12298 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
12302 /* This is a TTY frame, i.e. character hpos/vpos are used as
12304 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
12306 it
.first_visible_x
= 0;
12307 it
.last_visible_x
= FRAME_WIDTH (f
);
12309 #endif /* not USE_X_TOOLKIT */
12311 /* Clear all rows of the menu bar. */
12312 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
12314 struct glyph_row
*row
= it
.glyph_row
+ i
;
12315 clear_glyph_row (row
);
12316 row
->enabled_p
= 1;
12317 row
->full_width_p
= 1;
12320 /* Make the first line of the menu bar appear in reverse video. */
12321 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12323 /* Display all items of the menu bar. */
12324 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
12325 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
12327 Lisp_Object string
;
12329 /* Stop at nil string. */
12330 string
= XVECTOR (items
)->contents
[i
+ 1];
12334 /* Remember where item was displayed. */
12335 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
12337 /* Display the item, pad with one space. */
12338 if (it
.current_x
< it
.last_visible_x
)
12339 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
12340 XSTRING (string
)->size
+ 1, 0, 0, -1);
12343 /* Fill out the line with spaces. */
12344 if (it
.current_x
< it
.last_visible_x
)
12345 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
12347 /* Compute the total height of the lines. */
12348 compute_line_metrics (&it
);
12353 /***********************************************************************
12355 ***********************************************************************/
12357 /* Redisplay mode lines in the window tree whose root is WINDOW. If
12358 FORCE is non-zero, redisplay mode lines unconditionally.
12359 Otherwise, redisplay only mode lines that are garbaged. Value is
12360 the number of windows whose mode lines were redisplayed. */
12363 redisplay_mode_lines (window
, force
)
12364 Lisp_Object window
;
12369 while (!NILP (window
))
12371 struct window
*w
= XWINDOW (window
);
12373 if (WINDOWP (w
->hchild
))
12374 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
12375 else if (WINDOWP (w
->vchild
))
12376 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
12378 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
12379 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
12381 Lisp_Object old_selected_frame
;
12382 struct text_pos lpoint
;
12383 struct buffer
*old
= current_buffer
;
12385 /* Set the window's buffer for the mode line display. */
12386 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12387 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12389 /* Point refers normally to the selected window. For any
12390 other window, set up appropriate value. */
12391 if (!EQ (window
, selected_window
))
12393 struct text_pos pt
;
12395 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
12396 if (CHARPOS (pt
) < BEGV
)
12397 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
12398 else if (CHARPOS (pt
) > (ZV
- 1))
12399 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
12401 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
12404 /* Temporarily set up the selected frame. */
12405 old_selected_frame
= selected_frame
;
12406 selected_frame
= w
->frame
;
12408 /* Display mode lines. */
12409 clear_glyph_matrix (w
->desired_matrix
);
12410 if (display_mode_lines (w
))
12413 w
->must_be_updated_p
= 1;
12416 /* Restore old settings. */
12417 selected_frame
= old_selected_frame
;
12418 set_buffer_internal_1 (old
);
12419 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12429 /* Display the mode and/or top line of window W. Value is the number
12430 of mode lines displayed. */
12433 display_mode_lines (w
)
12438 /* These will be set while the mode line specs are processed. */
12439 line_number_displayed
= 0;
12440 w
->column_number_displayed
= Qnil
;
12442 if (WINDOW_WANTS_MODELINE_P (w
))
12444 display_mode_line (w
, MODE_LINE_FACE_ID
,
12445 current_buffer
->mode_line_format
);
12449 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12451 display_mode_line (w
, HEADER_LINE_FACE_ID
,
12452 current_buffer
->header_line_format
);
12460 /* Display mode or top line of window W. FACE_ID specifies which line
12461 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
12462 FORMAT is the mode line format to display. Value is the pixel
12463 height of the mode line displayed. */
12466 display_mode_line (w
, face_id
, format
)
12468 enum face_id face_id
;
12469 Lisp_Object format
;
12474 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
12475 prepare_desired_row (it
.glyph_row
);
12477 /* Temporarily make frame's keyboard the current kboard so that
12478 kboard-local variables in the mode_line_format will get the right
12480 push_frame_kboard (it
.f
);
12481 display_mode_element (&it
, 0, 0, 0, format
);
12482 pop_frame_kboard ();
12484 /* Fill up with spaces. */
12485 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
12487 compute_line_metrics (&it
);
12488 it
.glyph_row
->full_width_p
= 1;
12489 it
.glyph_row
->mode_line_p
= 1;
12490 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
12491 it
.glyph_row
->continued_p
= 0;
12492 it
.glyph_row
->truncated_on_left_p
= 0;
12493 it
.glyph_row
->truncated_on_right_p
= 0;
12495 /* Make a 3D mode-line have a shadow at its right end. */
12496 face
= FACE_FROM_ID (it
.f
, face_id
);
12497 extend_face_to_end_of_line (&it
);
12498 if (face
->box
!= FACE_NO_BOX
)
12500 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
12501 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
12502 last
->right_box_line_p
= 1;
12505 return it
.glyph_row
->height
;
12509 /* Contribute ELT to the mode line for window IT->w. How it
12510 translates into text depends on its data type.
12512 IT describes the display environment in which we display, as usual.
12514 DEPTH is the depth in recursion. It is used to prevent
12515 infinite recursion here.
12517 FIELD_WIDTH is the number of characters the display of ELT should
12518 occupy in the mode line, and PRECISION is the maximum number of
12519 characters to display from ELT's representation. See
12520 display_string for details. *
12522 Returns the hpos of the end of the text generated by ELT. */
12525 display_mode_element (it
, depth
, field_width
, precision
, elt
)
12528 int field_width
, precision
;
12531 int n
= 0, field
, prec
;
12539 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
12543 /* A string: output it and check for %-constructs within it. */
12545 unsigned char *this = XSTRING (elt
)->data
;
12546 unsigned char *lisp_string
= this;
12548 while ((precision
<= 0 || n
< precision
)
12550 && (frame_title_ptr
12551 || it
->current_x
< it
->last_visible_x
))
12553 unsigned char *last
= this;
12555 /* Advance to end of string or next format specifier. */
12556 while ((c
= *this++) != '\0' && c
!= '%')
12559 if (this - 1 != last
)
12561 /* Output to end of string or up to '%'. Field width
12562 is length of string. Don't output more than
12563 PRECISION allows us. */
12564 prec
= --this - last
;
12565 if (precision
> 0 && prec
> precision
- n
)
12566 prec
= precision
- n
;
12568 if (frame_title_ptr
)
12569 n
+= store_frame_title (last
, prec
, prec
);
12571 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
12572 it
, 0, prec
, 0, -1);
12574 else /* c == '%' */
12576 unsigned char *percent_position
= this;
12578 /* Get the specified minimum width. Zero means
12581 while ((c
= *this++) >= '0' && c
<= '9')
12582 field
= field
* 10 + c
- '0';
12584 /* Don't pad beyond the total padding allowed. */
12585 if (field_width
- n
> 0 && field
> field_width
- n
)
12586 field
= field_width
- n
;
12588 /* Note that either PRECISION <= 0 or N < PRECISION. */
12589 prec
= precision
- n
;
12592 n
+= display_mode_element (it
, depth
, field
, prec
,
12593 Vglobal_mode_string
);
12596 unsigned char *spec
12597 = decode_mode_spec (it
->w
, c
, field
, prec
);
12599 if (frame_title_ptr
)
12600 n
+= store_frame_title (spec
, field
, prec
);
12604 = it
->glyph_row
->used
[TEXT_AREA
];
12606 = percent_position
- XSTRING (elt
)->data
;
12608 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
12609 field
, prec
, 0, -1);
12611 /* Assign to the glyphs written above the
12612 string where the `%x' came from, position
12616 struct glyph
*glyph
12617 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
12621 for (i
= 0; i
< nwritten
; ++i
)
12623 glyph
[i
].object
= elt
;
12624 glyph
[i
].charpos
= charpos
;
12637 /* A symbol: process the value of the symbol recursively
12638 as if it appeared here directly. Avoid error if symbol void.
12639 Special case: if value of symbol is a string, output the string
12642 register Lisp_Object tem
;
12643 tem
= Fboundp (elt
);
12646 tem
= Fsymbol_value (elt
);
12647 /* If value is a string, output that string literally:
12648 don't check for % within it. */
12651 prec
= XSTRING (tem
)->size
;
12652 if (precision
> 0 && prec
> precision
- n
)
12653 prec
= precision
- n
;
12654 if (frame_title_ptr
)
12655 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
12657 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
12660 else if (!EQ (tem
, elt
))
12662 /* Give up right away for nil or t. */
12672 register Lisp_Object car
, tem
;
12674 /* A cons cell: three distinct cases.
12675 If first element is a string or a cons, process all the elements
12676 and effectively concatenate them.
12677 If first element is a negative number, truncate displaying cdr to
12678 at most that many characters. If positive, pad (with spaces)
12679 to at least that many characters.
12680 If first element is a symbol, process the cadr or caddr recursively
12681 according to whether the symbol's value is non-nil or nil. */
12683 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
12685 /* An element of the form (:eval FORM) means evaluate FORM
12686 and use the result as mode line elements. */
12687 struct gcpro gcpro1
;
12690 spec
= safe_eval (XCAR (XCDR (elt
)));
12692 n
+= display_mode_element (it
, depth
, field_width
- n
,
12693 precision
- n
, spec
);
12696 else if (SYMBOLP (car
))
12698 tem
= Fboundp (car
);
12702 /* elt is now the cdr, and we know it is a cons cell.
12703 Use its car if CAR has a non-nil value. */
12706 tem
= Fsymbol_value (car
);
12713 /* Symbol's value is nil (or symbol is unbound)
12714 Get the cddr of the original list
12715 and if possible find the caddr and use that. */
12719 else if (!CONSP (elt
))
12724 else if (INTEGERP (car
))
12726 register int lim
= XINT (car
);
12730 /* Negative int means reduce maximum width. */
12731 if (precision
<= 0)
12734 precision
= min (precision
, -lim
);
12738 /* Padding specified. Don't let it be more than
12739 current maximum. */
12741 lim
= min (precision
, lim
);
12743 /* If that's more padding than already wanted, queue it.
12744 But don't reduce padding already specified even if
12745 that is beyond the current truncation point. */
12746 field_width
= max (lim
, field_width
);
12750 else if (STRINGP (car
) || CONSP (car
))
12752 register int limit
= 50;
12753 /* Limit is to protect against circular lists. */
12756 && (precision
<= 0 || n
< precision
))
12758 n
+= display_mode_element (it
, depth
, field_width
- n
,
12759 precision
- n
, XCAR (elt
));
12768 if (frame_title_ptr
)
12769 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
12771 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
12772 precision
- n
, 0, 0);
12776 /* Pad to FIELD_WIDTH. */
12777 if (field_width
> 0 && n
< field_width
)
12779 if (frame_title_ptr
)
12780 n
+= store_frame_title ("", field_width
- n
, 0);
12782 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
12790 /* Write a null-terminated, right justified decimal representation of
12791 the positive integer D to BUF using a minimal field width WIDTH. */
12794 pint2str (buf
, width
, d
)
12795 register char *buf
;
12796 register int width
;
12799 register char *p
= buf
;
12807 *p
++ = d
% 10 + '0';
12812 for (width
-= (int) (p
- buf
); width
> 0; --width
)
12823 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
12824 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
12825 type of CODING_SYSTEM. Return updated pointer into BUF. */
12827 static unsigned char invalid_eol_type
[] = "(*invalid*)";
12830 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
12831 Lisp_Object coding_system
;
12832 register char *buf
;
12836 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
12837 unsigned char *eol_str
;
12839 /* The EOL conversion we are using. */
12840 Lisp_Object eoltype
;
12842 val
= Fget (coding_system
, Qcoding_system
);
12845 if (!VECTORP (val
)) /* Not yet decided. */
12850 eoltype
= eol_mnemonic_undecided
;
12851 /* Don't mention EOL conversion if it isn't decided. */
12855 Lisp_Object eolvalue
;
12857 eolvalue
= Fget (coding_system
, Qeol_type
);
12860 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
12864 /* The EOL conversion that is normal on this system. */
12866 if (NILP (eolvalue
)) /* Not yet decided. */
12867 eoltype
= eol_mnemonic_undecided
;
12868 else if (VECTORP (eolvalue
)) /* Not yet decided. */
12869 eoltype
= eol_mnemonic_undecided
;
12870 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
12871 eoltype
= (XFASTINT (eolvalue
) == 0
12872 ? eol_mnemonic_unix
12873 : (XFASTINT (eolvalue
) == 1
12874 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12880 /* Mention the EOL conversion if it is not the usual one. */
12881 if (STRINGP (eoltype
))
12883 eol_str
= XSTRING (eoltype
)->data
;
12884 eol_str_len
= XSTRING (eoltype
)->size
;
12886 else if (INTEGERP (eoltype
)
12887 && CHAR_VALID_P (XINT (eoltype
), 0))
12889 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12890 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12894 eol_str
= invalid_eol_type
;
12895 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12897 bcopy (eol_str
, buf
, eol_str_len
);
12898 buf
+= eol_str_len
;
12904 /* Return a string for the output of a mode line %-spec for window W,
12905 generated by character C. PRECISION >= 0 means don't return a
12906 string longer than that value. FIELD_WIDTH > 0 means pad the
12907 string returned with spaces to that value. */
12909 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12912 decode_mode_spec (w
, c
, field_width
, precision
)
12915 int field_width
, precision
;
12918 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12919 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12920 struct buffer
*b
= XBUFFER (w
->buffer
);
12927 if (!NILP (b
->read_only
))
12929 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12934 /* This differs from %* only for a modified read-only buffer. */
12935 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12937 if (!NILP (b
->read_only
))
12942 /* This differs from %* in ignoring read-only-ness. */
12943 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12955 if (command_loop_level
> 5)
12957 p
= decode_mode_spec_buf
;
12958 for (i
= 0; i
< command_loop_level
; i
++)
12961 return decode_mode_spec_buf
;
12969 if (command_loop_level
> 5)
12971 p
= decode_mode_spec_buf
;
12972 for (i
= 0; i
< command_loop_level
; i
++)
12975 return decode_mode_spec_buf
;
12982 /* Let lots_of_dashes be a string of infinite length. */
12983 if (field_width
<= 0
12984 || field_width
> sizeof (lots_of_dashes
))
12986 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12987 decode_mode_spec_buf
[i
] = '-';
12988 decode_mode_spec_buf
[i
] = '\0';
12989 return decode_mode_spec_buf
;
12992 return lots_of_dashes
;
13001 int col
= current_column ();
13002 XSETFASTINT (w
->column_number_displayed
, col
);
13003 pint2str (decode_mode_spec_buf
, field_width
, col
);
13004 return decode_mode_spec_buf
;
13008 /* %F displays the frame name. */
13009 if (!NILP (f
->title
))
13010 return (char *) XSTRING (f
->title
)->data
;
13011 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
13012 return (char *) XSTRING (f
->name
)->data
;
13021 int startpos
= XMARKER (w
->start
)->charpos
;
13022 int startpos_byte
= marker_byte_position (w
->start
);
13023 int line
, linepos
, linepos_byte
, topline
;
13025 int height
= XFASTINT (w
->height
);
13027 /* If we decided that this buffer isn't suitable for line numbers,
13028 don't forget that too fast. */
13029 if (EQ (w
->base_line_pos
, w
->buffer
))
13031 /* But do forget it, if the window shows a different buffer now. */
13032 else if (BUFFERP (w
->base_line_pos
))
13033 w
->base_line_pos
= Qnil
;
13035 /* If the buffer is very big, don't waste time. */
13036 if (INTEGERP (Vline_number_display_limit
)
13037 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
13039 w
->base_line_pos
= Qnil
;
13040 w
->base_line_number
= Qnil
;
13044 if (!NILP (w
->base_line_number
)
13045 && !NILP (w
->base_line_pos
)
13046 && XFASTINT (w
->base_line_pos
) <= startpos
)
13048 line
= XFASTINT (w
->base_line_number
);
13049 linepos
= XFASTINT (w
->base_line_pos
);
13050 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
13055 linepos
= BUF_BEGV (b
);
13056 linepos_byte
= BUF_BEGV_BYTE (b
);
13059 /* Count lines from base line to window start position. */
13060 nlines
= display_count_lines (linepos
, linepos_byte
,
13064 topline
= nlines
+ line
;
13066 /* Determine a new base line, if the old one is too close
13067 or too far away, or if we did not have one.
13068 "Too close" means it's plausible a scroll-down would
13069 go back past it. */
13070 if (startpos
== BUF_BEGV (b
))
13072 XSETFASTINT (w
->base_line_number
, topline
);
13073 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
13075 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
13076 || linepos
== BUF_BEGV (b
))
13078 int limit
= BUF_BEGV (b
);
13079 int limit_byte
= BUF_BEGV_BYTE (b
);
13081 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
13083 if (startpos
- distance
> limit
)
13085 limit
= startpos
- distance
;
13086 limit_byte
= CHAR_TO_BYTE (limit
);
13089 nlines
= display_count_lines (startpos
, startpos_byte
,
13091 - (height
* 2 + 30),
13093 /* If we couldn't find the lines we wanted within
13094 line_number_display_limit_width chars per line,
13095 give up on line numbers for this window. */
13096 if (position
== limit_byte
&& limit
== startpos
- distance
)
13098 w
->base_line_pos
= w
->buffer
;
13099 w
->base_line_number
= Qnil
;
13103 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
13104 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
13107 /* Now count lines from the start pos to point. */
13108 nlines
= display_count_lines (startpos
, startpos_byte
,
13109 PT_BYTE
, PT
, &junk
);
13111 /* Record that we did display the line number. */
13112 line_number_displayed
= 1;
13114 /* Make the string to show. */
13115 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
13116 return decode_mode_spec_buf
;
13119 char* p
= decode_mode_spec_buf
;
13120 int pad
= field_width
- 2;
13126 return decode_mode_spec_buf
;
13132 obj
= b
->mode_name
;
13136 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
13142 int pos
= marker_position (w
->start
);
13143 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13145 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
13147 if (pos
<= BUF_BEGV (b
))
13152 else if (pos
<= BUF_BEGV (b
))
13156 if (total
> 1000000)
13157 /* Do it differently for a large value, to avoid overflow. */
13158 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13160 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13161 /* We can't normally display a 3-digit number,
13162 so get us a 2-digit number that is close. */
13165 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13166 return decode_mode_spec_buf
;
13170 /* Display percentage of size above the bottom of the screen. */
13173 int toppos
= marker_position (w
->start
);
13174 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
13175 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
13177 if (botpos
>= BUF_ZV (b
))
13179 if (toppos
<= BUF_BEGV (b
))
13186 if (total
> 1000000)
13187 /* Do it differently for a large value, to avoid overflow. */
13188 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
13190 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
13191 /* We can't normally display a 3-digit number,
13192 so get us a 2-digit number that is close. */
13195 if (toppos
<= BUF_BEGV (b
))
13196 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
13198 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
13199 return decode_mode_spec_buf
;
13204 /* status of process */
13205 obj
= Fget_buffer_process (w
->buffer
);
13207 return "no process";
13208 #ifdef subprocesses
13209 obj
= Fsymbol_name (Fprocess_status (obj
));
13213 case 't': /* indicate TEXT or BINARY */
13214 #ifdef MODE_LINE_BINARY_TEXT
13215 return MODE_LINE_BINARY_TEXT (b
);
13221 /* coding-system (not including end-of-line format) */
13223 /* coding-system (including end-of-line type) */
13225 int eol_flag
= (c
== 'Z');
13226 char *p
= decode_mode_spec_buf
;
13228 if (! FRAME_WINDOW_P (f
))
13230 /* No need to mention EOL here--the terminal never needs
13231 to do EOL conversion. */
13232 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
13233 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
13235 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
13238 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
13239 #ifdef subprocesses
13240 obj
= Fget_buffer_process (Fcurrent_buffer ());
13241 if (PROCESSP (obj
))
13243 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
13245 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
13248 #endif /* subprocesses */
13251 return decode_mode_spec_buf
;
13256 return (char *) XSTRING (obj
)->data
;
13262 /* Count up to COUNT lines starting from START / START_BYTE.
13263 But don't go beyond LIMIT_BYTE.
13264 Return the number of lines thus found (always nonnegative).
13266 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
13269 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
13270 int start
, start_byte
, limit_byte
, count
;
13273 register unsigned char *cursor
;
13274 unsigned char *base
;
13276 register int ceiling
;
13277 register unsigned char *ceiling_addr
;
13278 int orig_count
= count
;
13280 /* If we are not in selective display mode,
13281 check only for newlines. */
13282 int selective_display
= (!NILP (current_buffer
->selective_display
)
13283 && !INTEGERP (current_buffer
->selective_display
));
13287 while (start_byte
< limit_byte
)
13289 ceiling
= BUFFER_CEILING_OF (start_byte
);
13290 ceiling
= min (limit_byte
- 1, ceiling
);
13291 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
13292 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
13295 if (selective_display
)
13296 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
13299 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
13302 if (cursor
!= ceiling_addr
)
13306 start_byte
+= cursor
- base
+ 1;
13307 *byte_pos_ptr
= start_byte
;
13311 if (++cursor
== ceiling_addr
)
13317 start_byte
+= cursor
- base
;
13322 while (start_byte
> limit_byte
)
13324 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
13325 ceiling
= max (limit_byte
, ceiling
);
13326 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
13327 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
13330 if (selective_display
)
13331 while (--cursor
!= ceiling_addr
13332 && *cursor
!= '\n' && *cursor
!= 015)
13335 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
13338 if (cursor
!= ceiling_addr
)
13342 start_byte
+= cursor
- base
+ 1;
13343 *byte_pos_ptr
= start_byte
;
13344 /* When scanning backwards, we should
13345 not count the newline posterior to which we stop. */
13346 return - orig_count
- 1;
13352 /* Here we add 1 to compensate for the last decrement
13353 of CURSOR, which took it past the valid range. */
13354 start_byte
+= cursor
- base
+ 1;
13358 *byte_pos_ptr
= limit_byte
;
13361 return - orig_count
+ count
;
13362 return orig_count
- count
;
13368 /***********************************************************************
13370 ***********************************************************************/
13372 /* Display a NUL-terminated string, starting with index START.
13374 If STRING is non-null, display that C string. Otherwise, the Lisp
13375 string LISP_STRING is displayed.
13377 If FACE_STRING is not nil, FACE_STRING_POS is a position in
13378 FACE_STRING. Display STRING or LISP_STRING with the face at
13379 FACE_STRING_POS in FACE_STRING:
13381 Display the string in the environment given by IT, but use the
13382 standard display table, temporarily.
13384 FIELD_WIDTH is the minimum number of output glyphs to produce.
13385 If STRING has fewer characters than FIELD_WIDTH, pad to the right
13386 with spaces. If STRING has more characters, more than FIELD_WIDTH
13387 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
13389 PRECISION is the maximum number of characters to output from
13390 STRING. PRECISION < 0 means don't truncate the string.
13392 This is roughly equivalent to printf format specifiers:
13394 FIELD_WIDTH PRECISION PRINTF
13395 ----------------------------------------
13401 MULTIBYTE zero means do not display multibyte chars, > 0 means do
13402 display them, and < 0 means obey the current buffer's value of
13403 enable_multibyte_characters.
13405 Value is the number of glyphs produced. */
13408 display_string (string
, lisp_string
, face_string
, face_string_pos
,
13409 start
, it
, field_width
, precision
, max_x
, multibyte
)
13410 unsigned char *string
;
13411 Lisp_Object lisp_string
;
13412 Lisp_Object face_string
;
13413 int face_string_pos
;
13416 int field_width
, precision
, max_x
;
13419 int hpos_at_start
= it
->hpos
;
13420 int saved_face_id
= it
->face_id
;
13421 struct glyph_row
*row
= it
->glyph_row
;
13423 /* Initialize the iterator IT for iteration over STRING beginning
13424 with index START. We assume that IT may be modified here (which
13425 means that display_line has to do something when displaying a
13426 mini-buffer prompt, which it does). */
13427 reseat_to_string (it
, string
, lisp_string
, start
,
13428 precision
, field_width
, multibyte
);
13430 /* If displaying STRING, set up the face of the iterator
13431 from LISP_STRING, if that's given. */
13432 if (STRINGP (face_string
))
13438 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
13439 0, it
->region_beg_charpos
,
13440 it
->region_end_charpos
,
13441 &endptr
, it
->base_face_id
);
13442 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13443 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
13446 /* Set max_x to the maximum allowed X position. Don't let it go
13447 beyond the right edge of the window. */
13449 max_x
= it
->last_visible_x
;
13451 max_x
= min (max_x
, it
->last_visible_x
);
13453 /* Skip over display elements that are not visible. because IT->w is
13455 if (it
->current_x
< it
->first_visible_x
)
13456 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
13457 MOVE_TO_POS
| MOVE_TO_X
);
13459 row
->ascent
= it
->max_ascent
;
13460 row
->height
= it
->max_ascent
+ it
->max_descent
;
13461 row
->phys_ascent
= it
->max_phys_ascent
;
13462 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13464 /* This condition is for the case that we are called with current_x
13465 past last_visible_x. */
13466 while (it
->current_x
< max_x
)
13468 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
13470 /* Get the next display element. */
13471 if (!get_next_display_element (it
))
13474 /* Produce glyphs. */
13475 x_before
= it
->current_x
;
13476 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
13477 PRODUCE_GLYPHS (it
);
13479 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
13482 while (i
< nglyphs
)
13484 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13486 if (!it
->truncate_lines_p
13487 && x
+ glyph
->pixel_width
> max_x
)
13489 /* End of continued line or max_x reached. */
13490 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13494 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
13496 /* Glyph is at least partially visible. */
13498 if (x
< it
->first_visible_x
)
13499 it
->glyph_row
->x
= x
- it
->first_visible_x
;
13503 /* Glyph is off the left margin of the display area.
13504 Should not happen. */
13508 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13509 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13510 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13511 row
->phys_height
= max (row
->phys_height
,
13512 it
->max_phys_ascent
+ it
->max_phys_descent
);
13513 x
+= glyph
->pixel_width
;
13517 /* Stop if max_x reached. */
13521 /* Stop at line ends. */
13522 if (ITERATOR_AT_END_OF_LINE_P (it
))
13524 it
->continuation_lines_width
= 0;
13528 set_iterator_to_next (it
, 1);
13530 /* Stop if truncating at the right edge. */
13531 if (it
->truncate_lines_p
13532 && it
->current_x
>= it
->last_visible_x
)
13534 /* Add truncation mark, but don't do it if the line is
13535 truncated at a padding space. */
13536 if (IT_CHARPOS (*it
) < it
->string_nchars
)
13538 if (!FRAME_WINDOW_P (it
->f
))
13539 produce_special_glyphs (it
, IT_TRUNCATION
);
13540 it
->glyph_row
->truncated_on_right_p
= 1;
13546 /* Maybe insert a truncation at the left. */
13547 if (it
->first_visible_x
13548 && IT_CHARPOS (*it
) > 0)
13550 if (!FRAME_WINDOW_P (it
->f
))
13551 insert_left_trunc_glyphs (it
);
13552 it
->glyph_row
->truncated_on_left_p
= 1;
13555 it
->face_id
= saved_face_id
;
13557 /* Value is number of columns displayed. */
13558 return it
->hpos
- hpos_at_start
;
13563 /* This is like a combination of memq and assq. Return 1 if PROPVAL
13564 appears as an element of LIST or as the car of an element of LIST.
13565 If PROPVAL is a list, compare each element against LIST in that
13566 way, and return 1 if any element of PROPVAL is found in LIST.
13567 Otherwise return 0. This function cannot quit. */
13570 invisible_p (propval
, list
)
13571 register Lisp_Object propval
;
13574 register Lisp_Object tail
, proptail
;
13576 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13578 register Lisp_Object tem
;
13580 if (EQ (propval
, tem
))
13582 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13586 if (CONSP (propval
))
13588 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13590 Lisp_Object propelt
;
13591 propelt
= XCAR (proptail
);
13592 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13594 register Lisp_Object tem
;
13596 if (EQ (propelt
, tem
))
13598 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13608 /* Return 1 if PROPVAL appears as the car of an element of LIST and
13609 the cdr of that element is non-nil. If PROPVAL is a list, check
13610 each element of PROPVAL in that way, and the first time some
13611 element is found, return 1 if the cdr of that element is non-nil.
13612 Otherwise return 0. This function cannot quit. */
13615 invisible_ellipsis_p (propval
, list
)
13616 register Lisp_Object propval
;
13619 register Lisp_Object tail
, proptail
;
13621 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13623 register Lisp_Object tem
;
13625 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
13626 return ! NILP (XCDR (tem
));
13629 if (CONSP (propval
))
13630 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
13632 Lisp_Object propelt
;
13633 propelt
= XCAR (proptail
);
13634 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
13636 register Lisp_Object tem
;
13638 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
13639 return ! NILP (XCDR (tem
));
13648 /***********************************************************************
13650 ***********************************************************************/
13655 Vwith_echo_area_save_vector
= Qnil
;
13656 staticpro (&Vwith_echo_area_save_vector
);
13658 Vmessage_stack
= Qnil
;
13659 staticpro (&Vmessage_stack
);
13661 Qinhibit_redisplay
= intern ("inhibit-redisplay");
13662 staticpro (&Qinhibit_redisplay
);
13665 defsubr (&Sdump_glyph_matrix
);
13666 defsubr (&Sdump_glyph_row
);
13667 defsubr (&Sdump_tool_bar_row
);
13668 defsubr (&Strace_redisplay_toggle
);
13669 defsubr (&Strace_to_stderr
);
13672 staticpro (&Qmenu_bar_update_hook
);
13673 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
13675 staticpro (&Qoverriding_terminal_local_map
);
13676 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
13678 staticpro (&Qoverriding_local_map
);
13679 Qoverriding_local_map
= intern ("overriding-local-map");
13681 staticpro (&Qwindow_scroll_functions
);
13682 Qwindow_scroll_functions
= intern ("window-scroll-functions");
13684 staticpro (&Qredisplay_end_trigger_functions
);
13685 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
13687 staticpro (&Qinhibit_point_motion_hooks
);
13688 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
13690 QCdata
= intern (":data");
13691 staticpro (&QCdata
);
13692 Qdisplay
= intern ("display");
13693 staticpro (&Qdisplay
);
13694 Qspace_width
= intern ("space-width");
13695 staticpro (&Qspace_width
);
13696 Qraise
= intern ("raise");
13697 staticpro (&Qraise
);
13698 Qspace
= intern ("space");
13699 staticpro (&Qspace
);
13700 Qmargin
= intern ("margin");
13701 staticpro (&Qmargin
);
13702 Qleft_margin
= intern ("left-margin");
13703 staticpro (&Qleft_margin
);
13704 Qright_margin
= intern ("right-margin");
13705 staticpro (&Qright_margin
);
13706 Qalign_to
= intern ("align-to");
13707 staticpro (&Qalign_to
);
13708 QCalign_to
= intern (":align-to");
13709 staticpro (&QCalign_to
);
13710 Qrelative_width
= intern ("relative-width");
13711 staticpro (&Qrelative_width
);
13712 QCrelative_width
= intern (":relative-width");
13713 staticpro (&QCrelative_width
);
13714 QCrelative_height
= intern (":relative-height");
13715 staticpro (&QCrelative_height
);
13716 QCeval
= intern (":eval");
13717 staticpro (&QCeval
);
13718 Qwhen
= intern ("when");
13719 staticpro (&Qwhen
);
13720 QCfile
= intern (":file");
13721 staticpro (&QCfile
);
13722 Qfontified
= intern ("fontified");
13723 staticpro (&Qfontified
);
13724 Qfontification_functions
= intern ("fontification-functions");
13725 staticpro (&Qfontification_functions
);
13726 Qtrailing_whitespace
= intern ("trailing-whitespace");
13727 staticpro (&Qtrailing_whitespace
);
13728 Qimage
= intern ("image");
13729 staticpro (&Qimage
);
13730 Qmessage_truncate_lines
= intern ("message-truncate-lines");
13731 staticpro (&Qmessage_truncate_lines
);
13732 Qgrow_only
= intern ("grow-only");
13733 staticpro (&Qgrow_only
);
13735 last_arrow_position
= Qnil
;
13736 last_arrow_string
= Qnil
;
13737 staticpro (&last_arrow_position
);
13738 staticpro (&last_arrow_string
);
13740 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
13741 staticpro (&echo_buffer
[0]);
13742 staticpro (&echo_buffer
[1]);
13744 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
13745 staticpro (&echo_area_buffer
[0]);
13746 staticpro (&echo_area_buffer
[1]);
13748 Vmessages_buffer_name
= build_string ("*Messages*");
13749 staticpro (&Vmessages_buffer_name
);
13751 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
13752 "Non-nil means highlight trailing whitespace.\n\
13753 The face used for trailing whitespace is `trailing-whitespace'.");
13754 Vshow_trailing_whitespace
= Qnil
;
13756 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
13757 "Non-nil means don't actually do any redisplay.\n\
13758 This is used for internal purposes.");
13759 Vinhibit_redisplay
= Qnil
;
13761 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
13762 "String (or mode line construct) included (normally) in `mode-line-format'.");
13763 Vglobal_mode_string
= Qnil
;
13765 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
13766 "Marker for where to display an arrow on top of the buffer text.\n\
13767 This must be the beginning of a line in order to work.\n\
13768 See also `overlay-arrow-string'.");
13769 Voverlay_arrow_position
= Qnil
;
13771 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
13772 "String to display as an arrow. See also `overlay-arrow-position'.");
13773 Voverlay_arrow_string
= Qnil
;
13775 DEFVAR_INT ("scroll-step", &scroll_step
,
13776 "*The number of lines to try scrolling a window by when point moves out.\n\
13777 If that fails to bring point back on frame, point is centered instead.\n\
13778 If this is zero, point is always centered after it moves off frame.\n\
13779 If you want scrolling to always be a line at a time, you should set\n\
13780 `scroll-conservatively' to a large value rather than set this to 1.");
13782 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
13783 "*Scroll up to this many lines, to bring point back on screen.\n\
13784 A value of zero means to scroll the text to center point vertically\n\
13786 scroll_conservatively
= 0;
13788 DEFVAR_INT ("scroll-margin", &scroll_margin
,
13789 "*Number of lines of margin at the top and bottom of a window.\n\
13790 Recenter the window whenever point gets within this many lines\n\
13791 of the top or bottom of the window.");
13795 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
13798 DEFVAR_BOOL ("truncate-partial-width-windows",
13799 &truncate_partial_width_windows
,
13800 "*Non-nil means truncate lines in all windows less than full frame wide.");
13801 truncate_partial_width_windows
= 1;
13803 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
13804 "*Non-nil means use inverse video for the mode line.");
13805 mode_line_inverse_video
= 1;
13807 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
13808 "*Maximum buffer size for which line number should be displayed.\n\
13809 If the buffer is bigger than this, the line number does not appear\n\
13810 in the mode line. A value of nil means no limit.");
13811 Vline_number_display_limit
= Qnil
;
13813 DEFVAR_INT ("line-number-display-limit-width",
13814 &line_number_display_limit_width
,
13815 "*Maximum line width (in characters) for line number display.\n\
13816 If the average length of the lines near point is bigger than this, then the\n\
13817 line number may be omitted from the mode line.");
13818 line_number_display_limit_width
= 200;
13820 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
13821 "*Non-nil means highlight region even in nonselected windows.");
13822 highlight_nonselected_windows
= 0;
13824 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
13825 "Non-nil if more than one frame is visible on this display.\n\
13826 Minibuffer-only frames don't count, but iconified frames do.\n\
13827 This variable is not guaranteed to be accurate except while processing\n\
13828 `frame-title-format' and `icon-title-format'.");
13830 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
13831 "Template for displaying the title bar of visible frames.\n\
13832 \(Assuming the window manager supports this feature.)\n\
13833 This variable has the same structure as `mode-line-format' (which see),\n\
13834 and is used only on frames for which no explicit name has been set\n\
13835 \(see `modify-frame-parameters').");
13836 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
13837 "Template for displaying the title bar of an iconified frame.\n\
13838 \(Assuming the window manager supports this feature.)\n\
13839 This variable has the same structure as `mode-line-format' (which see),\n\
13840 and is used only on frames for which no explicit name has been set\n\
13841 \(see `modify-frame-parameters').");
13843 = Vframe_title_format
13844 = Fcons (intern ("multiple-frames"),
13845 Fcons (build_string ("%b"),
13846 Fcons (Fcons (build_string (""),
13847 Fcons (intern ("invocation-name"),
13848 Fcons (build_string ("@"),
13849 Fcons (intern ("system-name"),
13853 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
13854 "Maximum number of lines to keep in the message log buffer.\n\
13855 If nil, disable message logging. If t, log messages but don't truncate\n\
13856 the buffer when it becomes large.");
13857 XSETFASTINT (Vmessage_log_max
, 50);
13859 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
13860 "Functions called before redisplay, if window sizes have changed.\n\
13861 The value should be a list of functions that take one argument.\n\
13862 Just before redisplay, for each frame, if any of its windows have changed\n\
13863 size since the last redisplay, or have been split or deleted,\n\
13864 all the functions in the list are called, with the frame as argument.");
13865 Vwindow_size_change_functions
= Qnil
;
13867 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
13868 "List of Functions to call before redisplaying a window with scrolling.\n\
13869 Each function is called with two arguments, the window\n\
13870 and its new display-start position. Note that the value of `window-end'\n\
13871 is not valid when these functions are called.");
13872 Vwindow_scroll_functions
= Qnil
;
13874 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
13875 "*Non-nil means automatically resize tool-bars.\n\
13876 This increases a tool-bar's height if not all tool-bar items are visible.\n\
13877 It decreases a tool-bar's height when it would display blank lines\n\
13879 auto_resize_tool_bars_p
= 1;
13881 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
13882 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
13883 auto_raise_tool_bar_buttons_p
= 1;
13885 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
13886 "*Margin around tool-bar buttons in pixels.");
13887 tool_bar_button_margin
= 1;
13889 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
13890 "Relief thickness of tool-bar buttons.");
13891 tool_bar_button_relief
= 3;
13893 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13894 "List of functions to call to fontify regions of text.\n\
13895 Each function is called with one argument POS. Functions must\n\
13896 fontify a region starting at POS in the current buffer, and give\n\
13897 fontified regions the property `fontified'.\n\
13898 This variable automatically becomes buffer-local when set.");
13899 Vfontification_functions
= Qnil
;
13900 Fmake_local_variable (Qfontification_functions
);
13902 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13903 &unibyte_display_via_language_environment
,
13904 "*Non-nil means display unibyte text according to language environment.\n\
13905 Specifically this means that unibyte non-ASCII characters\n\
13906 are displayed by converting them to the equivalent multibyte characters\n\
13907 according to the current language environment. As a result, they are\n\
13908 displayed according to the current fontset.");
13909 unibyte_display_via_language_environment
= 0;
13911 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13912 "*Maximum height for resizing mini-windows.\n\
13913 If a float, it specifies a fraction of the mini-window frame's height.\n\
13914 If an integer, it specifies a number of lines.");
13915 Vmax_mini_window_height
= make_float (0.25);
13917 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
13918 "*How to resize the mini-window.\n\
13919 A value of nil means don't automatically resize mini-windows.\n\
13920 A value of t means resize it to fit the text displayed in it.\n\
13921 A value of `grow-only', the default, means let mini-windows grow\n\
13922 only, until the its display becomes empty, at which point the mini-window\n\
13923 goes back to its normal size.");
13924 Vresize_mini_windows
= Qgrow_only
;
13926 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13927 &cursor_in_non_selected_windows
,
13928 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13929 Nil means don't display a cursor there.");
13930 cursor_in_non_selected_windows
= 1;
13932 DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p
,
13933 "*Non-nil means scroll the display automatically to make point visible.");
13934 automatic_hscrolling_p
= 1;
13936 DEFVAR_LISP ("image-types", &Vimage_types
,
13937 "List of supported image types.\n\
13938 Each element of the list is a symbol for a supported image type.");
13939 Vimage_types
= Qnil
;
13941 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
13942 "If non-nil, messages are truncated instead of resizing the echo area.\n\
13943 Bind this around calls to `message' to let it take effect.");
13944 message_truncate_lines
= 0;
13946 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
13947 "Normal hook run for clicks on menu bar, before displaying a submenu.\n\
13948 Can be used to update submenus whose contents should vary.");
13949 Vmenu_bar_update_hook
= Qnil
;
13953 /* Initialize this module when Emacs starts. */
13958 Lisp_Object root_window
;
13959 struct window
*mini_w
;
13961 current_header_line_height
= current_mode_line_height
= -1;
13963 CHARPOS (this_line_start_pos
) = 0;
13965 mini_w
= XWINDOW (minibuf_window
);
13966 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13968 if (!noninteractive
)
13970 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13973 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13974 set_window_height (root_window
,
13975 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13977 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13978 set_window_height (minibuf_window
, 1, 0);
13980 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13981 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13983 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13984 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13985 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13987 /* The default ellipsis glyphs `...'. */
13988 for (i
= 0; i
< 3; ++i
)
13989 XSETFASTINT (default_invis_vector
[i
], '.');
13992 #ifdef HAVE_WINDOW_SYSTEM
13994 /* Allocate the buffer for frame titles. */
13996 frame_title_buf
= (char *) xmalloc (size
);
13997 frame_title_buf_end
= frame_title_buf
+ size
;
13998 frame_title_ptr
= NULL
;
14000 #endif /* HAVE_WINDOW_SYSTEM */
14002 help_echo_showing_p
= 0;