1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
184 #include "termhooks.h"
185 #include "intervals.h"
188 #include "region-cache.h"
191 #ifdef HAVE_X_WINDOWS
201 #define INFINITY 10000000
203 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
205 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
206 extern int pending_menu_activation
;
209 extern int interrupt_input
;
210 extern int command_loop_level
;
212 extern int minibuffer_auto_raise
;
213 extern Lisp_Object Vminibuffer_list
;
215 extern Lisp_Object Qface
;
216 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
218 extern Lisp_Object Voverriding_local_map
;
219 extern Lisp_Object Voverriding_local_map_menu_flag
;
220 extern Lisp_Object Qmenu_item
;
221 extern Lisp_Object Qwhen
;
223 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
224 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
225 Lisp_Object Qredisplay_end_trigger_functions
;
226 Lisp_Object Qinhibit_point_motion_hooks
;
227 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
228 Lisp_Object Qfontified
;
229 Lisp_Object Qgrow_only
;
230 Lisp_Object Qinhibit_eval_during_redisplay
;
231 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
234 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
236 Lisp_Object Qrisky_local_variable
;
238 /* Holds the list (error). */
239 Lisp_Object list_of_error
;
241 /* Functions called to fontify regions of text. */
243 Lisp_Object Vfontification_functions
;
244 Lisp_Object Qfontification_functions
;
246 /* Non-zero means draw tool bar buttons raised when the mouse moves
249 int auto_raise_tool_bar_buttons_p
;
251 /* Margin around tool bar buttons in pixels. */
253 Lisp_Object Vtool_bar_button_margin
;
255 /* Thickness of shadow to draw around tool bar buttons. */
257 EMACS_INT tool_bar_button_relief
;
259 /* Non-zero means automatically resize tool-bars so that all tool-bar
260 items are visible, and no blank lines remain. */
262 int auto_resize_tool_bars_p
;
264 /* Non-nil means don't actually do any redisplay. */
266 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
268 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
270 int inhibit_eval_during_redisplay
;
272 /* Names of text properties relevant for redisplay. */
274 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
275 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
277 /* Symbols used in text property values. */
279 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
280 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
282 extern Lisp_Object Qheight
;
283 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
285 /* Non-nil means highlight trailing whitespace. */
287 Lisp_Object Vshow_trailing_whitespace
;
289 /* Name of the face used to highlight trailing whitespace. */
291 Lisp_Object Qtrailing_whitespace
;
293 /* The symbol `image' which is the car of the lists used to represent
298 /* Non-zero means print newline to stdout before next mini-buffer
301 int noninteractive_need_newline
;
303 /* Non-zero means print newline to message log before next message. */
305 static int message_log_need_newline
;
307 /* Three markers that message_dolog uses.
308 It could allocate them itself, but that causes trouble
309 in handling memory-full errors. */
310 static Lisp_Object message_dolog_marker1
;
311 static Lisp_Object message_dolog_marker2
;
312 static Lisp_Object message_dolog_marker3
;
314 /* The buffer position of the first character appearing entirely or
315 partially on the line of the selected window which contains the
316 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
317 redisplay optimization in redisplay_internal. */
319 static struct text_pos this_line_start_pos
;
321 /* Number of characters past the end of the line above, including the
322 terminating newline. */
324 static struct text_pos this_line_end_pos
;
326 /* The vertical positions and the height of this line. */
328 static int this_line_vpos
;
329 static int this_line_y
;
330 static int this_line_pixel_height
;
332 /* X position at which this display line starts. Usually zero;
333 negative if first character is partially visible. */
335 static int this_line_start_x
;
337 /* Buffer that this_line_.* variables are referring to. */
339 static struct buffer
*this_line_buffer
;
341 /* Nonzero means truncate lines in all windows less wide than the
344 int truncate_partial_width_windows
;
346 /* A flag to control how to display unibyte 8-bit character. */
348 int unibyte_display_via_language_environment
;
350 /* Nonzero means we have more than one non-mini-buffer-only frame.
351 Not guaranteed to be accurate except while parsing
352 frame-title-format. */
356 Lisp_Object Vglobal_mode_string
;
358 /* Marker for where to display an arrow on top of the buffer text. */
360 Lisp_Object Voverlay_arrow_position
;
362 /* String to display for the arrow. Only used on terminal frames. */
364 Lisp_Object Voverlay_arrow_string
;
366 /* Values of those variables at last redisplay. However, if
367 Voverlay_arrow_position is a marker, last_arrow_position is its
368 numerical position. */
370 static Lisp_Object last_arrow_position
, last_arrow_string
;
372 /* Like mode-line-format, but for the title bar on a visible frame. */
374 Lisp_Object Vframe_title_format
;
376 /* Like mode-line-format, but for the title bar on an iconified frame. */
378 Lisp_Object Vicon_title_format
;
380 /* List of functions to call when a window's size changes. These
381 functions get one arg, a frame on which one or more windows' sizes
384 static Lisp_Object Vwindow_size_change_functions
;
386 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
388 /* Nonzero if overlay arrow has been displayed once in this window. */
390 static int overlay_arrow_seen
;
392 /* Nonzero means highlight the region even in nonselected windows. */
394 int highlight_nonselected_windows
;
396 /* If cursor motion alone moves point off frame, try scrolling this
397 many lines up or down if that will bring it back. */
399 static EMACS_INT scroll_step
;
401 /* Nonzero means scroll just far enough to bring point back on the
402 screen, when appropriate. */
404 static EMACS_INT scroll_conservatively
;
406 /* Recenter the window whenever point gets within this many lines of
407 the top or bottom of the window. This value is translated into a
408 pixel value by multiplying it with CANON_Y_UNIT, which means that
409 there is really a fixed pixel height scroll margin. */
411 EMACS_INT scroll_margin
;
413 /* Number of windows showing the buffer of the selected window (or
414 another buffer with the same base buffer). keyboard.c refers to
419 /* Vector containing glyphs for an ellipsis `...'. */
421 static Lisp_Object default_invis_vector
[3];
423 /* Zero means display the mode-line/header-line/menu-bar in the default face
424 (this slightly odd definition is for compatibility with previous versions
425 of emacs), non-zero means display them using their respective faces.
427 This variable is deprecated. */
429 int mode_line_inverse_video
;
431 /* Prompt to display in front of the mini-buffer contents. */
433 Lisp_Object minibuf_prompt
;
435 /* Width of current mini-buffer prompt. Only set after display_line
436 of the line that contains the prompt. */
438 int minibuf_prompt_width
;
440 /* This is the window where the echo area message was displayed. It
441 is always a mini-buffer window, but it may not be the same window
442 currently active as a mini-buffer. */
444 Lisp_Object echo_area_window
;
446 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
447 pushes the current message and the value of
448 message_enable_multibyte on the stack, the function restore_message
449 pops the stack and displays MESSAGE again. */
451 Lisp_Object Vmessage_stack
;
453 /* Nonzero means multibyte characters were enabled when the echo area
454 message was specified. */
456 int message_enable_multibyte
;
458 /* Nonzero if we should redraw the mode lines on the next redisplay. */
460 int update_mode_lines
;
462 /* Nonzero if window sizes or contents have changed since last
463 redisplay that finished. */
465 int windows_or_buffers_changed
;
467 /* Nonzero means a frame's cursor type has been changed. */
469 int cursor_type_changed
;
471 /* Nonzero after display_mode_line if %l was used and it displayed a
474 int line_number_displayed
;
476 /* Maximum buffer size for which to display line numbers. */
478 Lisp_Object Vline_number_display_limit
;
480 /* Line width to consider when repositioning for line number display. */
482 static EMACS_INT line_number_display_limit_width
;
484 /* Number of lines to keep in the message log buffer. t means
485 infinite. nil means don't log at all. */
487 Lisp_Object Vmessage_log_max
;
489 /* The name of the *Messages* buffer, a string. */
491 static Lisp_Object Vmessages_buffer_name
;
493 /* Current, index 0, and last displayed echo area message. Either
494 buffers from echo_buffers, or nil to indicate no message. */
496 Lisp_Object echo_area_buffer
[2];
498 /* The buffers referenced from echo_area_buffer. */
500 static Lisp_Object echo_buffer
[2];
502 /* A vector saved used in with_area_buffer to reduce consing. */
504 static Lisp_Object Vwith_echo_area_save_vector
;
506 /* Non-zero means display_echo_area should display the last echo area
507 message again. Set by redisplay_preserve_echo_area. */
509 static int display_last_displayed_message_p
;
511 /* Nonzero if echo area is being used by print; zero if being used by
514 int message_buf_print
;
516 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
518 Lisp_Object Qinhibit_menubar_update
;
519 int inhibit_menubar_update
;
521 /* Maximum height for resizing mini-windows. Either a float
522 specifying a fraction of the available height, or an integer
523 specifying a number of lines. */
525 Lisp_Object Vmax_mini_window_height
;
527 /* Non-zero means messages should be displayed with truncated
528 lines instead of being continued. */
530 int message_truncate_lines
;
531 Lisp_Object Qmessage_truncate_lines
;
533 /* Set to 1 in clear_message to make redisplay_internal aware
534 of an emptied echo area. */
536 static int message_cleared_p
;
538 /* Non-zero means we want a hollow cursor in windows that are not
539 selected. Zero means there's no cursor in such windows. */
541 Lisp_Object Vcursor_in_non_selected_windows
;
542 Lisp_Object Qcursor_in_non_selected_windows
;
544 /* How to blink the default frame cursor off. */
545 Lisp_Object Vblink_cursor_alist
;
547 /* A scratch glyph row with contents used for generating truncation
548 glyphs. Also used in direct_output_for_insert. */
550 #define MAX_SCRATCH_GLYPHS 100
551 struct glyph_row scratch_glyph_row
;
552 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
554 /* Ascent and height of the last line processed by move_it_to. */
556 static int last_max_ascent
, last_height
;
558 /* Non-zero if there's a help-echo in the echo area. */
560 int help_echo_showing_p
;
562 /* If >= 0, computed, exact values of mode-line and header-line height
563 to use in the macros CURRENT_MODE_LINE_HEIGHT and
564 CURRENT_HEADER_LINE_HEIGHT. */
566 int current_mode_line_height
, current_header_line_height
;
568 /* The maximum distance to look ahead for text properties. Values
569 that are too small let us call compute_char_face and similar
570 functions too often which is expensive. Values that are too large
571 let us call compute_char_face and alike too often because we
572 might not be interested in text properties that far away. */
574 #define TEXT_PROP_DISTANCE_LIMIT 100
578 /* Variables to turn off display optimizations from Lisp. */
580 int inhibit_try_window_id
, inhibit_try_window_reusing
;
581 int inhibit_try_cursor_movement
;
583 /* Non-zero means print traces of redisplay if compiled with
586 int trace_redisplay_p
;
588 #endif /* GLYPH_DEBUG */
590 #ifdef DEBUG_TRACE_MOVE
591 /* Non-zero means trace with TRACE_MOVE to stderr. */
594 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
596 #define TRACE_MOVE(x) (void) 0
599 /* Non-zero means automatically scroll windows horizontally to make
602 int automatic_hscrolling_p
;
604 /* How close to the margin can point get before the window is scrolled
606 EMACS_INT hscroll_margin
;
608 /* How much to scroll horizontally when point is inside the above margin. */
609 Lisp_Object Vhscroll_step
;
611 /* A list of symbols, one for each supported image type. */
613 Lisp_Object Vimage_types
;
615 /* The variable `resize-mini-windows'. If nil, don't resize
616 mini-windows. If t, always resize them to fit the text they
617 display. If `grow-only', let mini-windows grow only until they
620 Lisp_Object Vresize_mini_windows
;
622 /* Buffer being redisplayed -- for redisplay_window_error. */
624 struct buffer
*displayed_buffer
;
626 /* Value returned from text property handlers (see below). */
631 HANDLED_RECOMPUTE_PROPS
,
632 HANDLED_OVERLAY_STRING_CONSUMED
,
636 /* A description of text properties that redisplay is interested
641 /* The name of the property. */
644 /* A unique index for the property. */
647 /* A handler function called to set up iterator IT from the property
648 at IT's current position. Value is used to steer handle_stop. */
649 enum prop_handled (*handler
) P_ ((struct it
*it
));
652 static enum prop_handled handle_face_prop
P_ ((struct it
*));
653 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
654 static enum prop_handled handle_display_prop
P_ ((struct it
*));
655 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
656 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
657 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
659 /* Properties handled by iterators. */
661 static struct props it_props
[] =
663 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
664 /* Handle `face' before `display' because some sub-properties of
665 `display' need to know the face. */
666 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
667 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
668 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
669 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
673 /* Value is the position described by X. If X is a marker, value is
674 the marker_position of X. Otherwise, value is X. */
676 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
678 /* Enumeration returned by some move_it_.* functions internally. */
682 /* Not used. Undefined value. */
685 /* Move ended at the requested buffer position or ZV. */
686 MOVE_POS_MATCH_OR_ZV
,
688 /* Move ended at the requested X pixel position. */
691 /* Move within a line ended at the end of a line that must be
695 /* Move within a line ended at the end of a line that would
696 be displayed truncated. */
699 /* Move within a line ended at a line end. */
703 /* This counter is used to clear the face cache every once in a while
704 in redisplay_internal. It is incremented for each redisplay.
705 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
708 #define CLEAR_FACE_CACHE_COUNT 500
709 static int clear_face_cache_count
;
711 /* Record the previous terminal frame we displayed. */
713 static struct frame
*previous_terminal_frame
;
715 /* Non-zero while redisplay_internal is in progress. */
719 /* Non-zero means don't free realized faces. Bound while freeing
720 realized faces is dangerous because glyph matrices might still
723 int inhibit_free_realized_faces
;
724 Lisp_Object Qinhibit_free_realized_faces
;
727 /* Function prototypes. */
729 static void setup_for_ellipsis
P_ ((struct it
*));
730 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
731 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
732 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
733 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
734 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
735 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
738 static int invisible_text_between_p
P_ ((struct it
*, int, int));
741 static int next_element_from_ellipsis
P_ ((struct it
*));
742 static void pint2str
P_ ((char *, int, int));
743 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
745 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
746 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
747 static void store_frame_title_char
P_ ((char));
748 static int store_frame_title
P_ ((const unsigned char *, int, int));
749 static void x_consider_frame_title
P_ ((Lisp_Object
));
750 static void handle_stop
P_ ((struct it
*));
751 static int tool_bar_lines_needed
P_ ((struct frame
*));
752 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
753 static void ensure_echo_area_buffers
P_ ((void));
754 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
755 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
756 static int with_echo_area_buffer
P_ ((struct window
*, int,
757 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
758 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
759 static void clear_garbaged_frames
P_ ((void));
760 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
761 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
762 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
763 static int display_echo_area
P_ ((struct window
*));
764 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
765 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
766 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
767 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
768 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
770 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
771 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
772 static void insert_left_trunc_glyphs
P_ ((struct it
*));
773 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
774 static void extend_face_to_end_of_line
P_ ((struct it
*));
775 static int append_space
P_ ((struct it
*, int));
776 static int make_cursor_line_fully_visible
P_ ((struct window
*));
777 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
778 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
779 static int trailing_whitespace_p
P_ ((int));
780 static int message_log_check_duplicate
P_ ((int, int, int, int));
781 static void push_it
P_ ((struct it
*));
782 static void pop_it
P_ ((struct it
*));
783 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
784 static void redisplay_internal
P_ ((int));
785 static int echo_area_display
P_ ((int));
786 static void redisplay_windows
P_ ((Lisp_Object
));
787 static void redisplay_window
P_ ((Lisp_Object
, int));
788 static Lisp_Object
redisplay_window_error ();
789 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
790 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
791 static void update_menu_bar
P_ ((struct frame
*, int));
792 static int try_window_reusing_current_matrix
P_ ((struct window
*));
793 static int try_window_id
P_ ((struct window
*));
794 static int display_line
P_ ((struct it
*));
795 static int display_mode_lines
P_ ((struct window
*));
796 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
797 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
798 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
799 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
800 static void display_menu_bar
P_ ((struct window
*));
801 static int display_count_lines
P_ ((int, int, int, int, int *));
802 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
803 int, int, struct it
*, int, int, int, int));
804 static void compute_line_metrics
P_ ((struct it
*));
805 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
806 static int get_overlay_strings
P_ ((struct it
*, int));
807 static void next_overlay_string
P_ ((struct it
*));
808 static void reseat
P_ ((struct it
*, struct text_pos
, int));
809 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
810 static void back_to_previous_visible_line_start
P_ ((struct it
*));
811 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
812 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
813 static int next_element_from_display_vector
P_ ((struct it
*));
814 static int next_element_from_string
P_ ((struct it
*));
815 static int next_element_from_c_string
P_ ((struct it
*));
816 static int next_element_from_buffer
P_ ((struct it
*));
817 static int next_element_from_composition
P_ ((struct it
*));
818 static int next_element_from_image
P_ ((struct it
*));
819 static int next_element_from_stretch
P_ ((struct it
*));
820 static void load_overlay_strings
P_ ((struct it
*, int));
821 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
822 struct display_pos
*));
823 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
824 Lisp_Object
, int, int, int, int));
825 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
827 void move_it_vertically_backward
P_ ((struct it
*, int));
828 static void init_to_row_start
P_ ((struct it
*, struct window
*,
829 struct glyph_row
*));
830 static int init_to_row_end
P_ ((struct it
*, struct window
*,
831 struct glyph_row
*));
832 static void back_to_previous_line_start
P_ ((struct it
*));
833 static int forward_to_next_line_start
P_ ((struct it
*, int *));
834 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
836 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
837 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
838 static int number_of_chars
P_ ((unsigned char *, int));
839 static void compute_stop_pos
P_ ((struct it
*));
840 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
842 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
843 static int next_overlay_change
P_ ((int));
844 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
845 Lisp_Object
, struct text_pos
*,
847 static int underlying_face_id
P_ ((struct it
*));
848 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
851 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
852 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
854 #ifdef HAVE_WINDOW_SYSTEM
856 static void update_tool_bar
P_ ((struct frame
*, int));
857 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
858 static int redisplay_tool_bar
P_ ((struct frame
*));
859 static void display_tool_bar_line
P_ ((struct it
*));
861 #endif /* HAVE_WINDOW_SYSTEM */
864 /***********************************************************************
865 Window display dimensions
866 ***********************************************************************/
868 /* Return the bottom boundary y-position for text lines in window W.
869 This is the first y position at which a line cannot start.
870 It is relative to the top of the window.
872 This is the height of W minus the height of a mode line, if any. */
875 window_text_bottom_y (w
)
878 struct frame
*f
= XFRAME (w
->frame
);
879 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
881 if (WINDOW_WANTS_MODELINE_P (w
))
882 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
887 /* Return the pixel width of display area AREA of window W. AREA < 0
888 means return the total width of W, not including fringes to
889 the left and right of the window. */
892 window_box_width (w
, area
)
896 struct frame
*f
= XFRAME (w
->frame
);
897 int width
= XFASTINT (w
->width
);
899 if (!w
->pseudo_window_p
)
901 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
903 if (area
== TEXT_AREA
)
905 if (INTEGERP (w
->left_margin_width
))
906 width
-= XFASTINT (w
->left_margin_width
);
907 if (INTEGERP (w
->right_margin_width
))
908 width
-= XFASTINT (w
->right_margin_width
);
910 else if (area
== LEFT_MARGIN_AREA
)
911 width
= (INTEGERP (w
->left_margin_width
)
912 ? XFASTINT (w
->left_margin_width
) : 0);
913 else if (area
== RIGHT_MARGIN_AREA
)
914 width
= (INTEGERP (w
->right_margin_width
)
915 ? XFASTINT (w
->right_margin_width
) : 0);
918 return width
* CANON_X_UNIT (f
);
922 /* Return the pixel height of the display area of window W, not
923 including mode lines of W, if any. */
926 window_box_height (w
)
929 struct frame
*f
= XFRAME (w
->frame
);
930 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
932 xassert (height
>= 0);
934 /* Note: the code below that determines the mode-line/header-line
935 height is essentially the same as that contained in the macro
936 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
937 the appropriate glyph row has its `mode_line_p' flag set,
938 and if it doesn't, uses estimate_mode_line_height instead. */
940 if (WINDOW_WANTS_MODELINE_P (w
))
942 struct glyph_row
*ml_row
943 = (w
->current_matrix
&& w
->current_matrix
->rows
944 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
946 if (ml_row
&& ml_row
->mode_line_p
)
947 height
-= ml_row
->height
;
949 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
952 if (WINDOW_WANTS_HEADER_LINE_P (w
))
954 struct glyph_row
*hl_row
955 = (w
->current_matrix
&& w
->current_matrix
->rows
956 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
958 if (hl_row
&& hl_row
->mode_line_p
)
959 height
-= hl_row
->height
;
961 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
964 /* With a very small font and a mode-line that's taller than
965 default, we might end up with a negative height. */
966 return max (0, height
);
970 /* Return the frame-relative coordinate of the left edge of display
971 area AREA of window W. AREA < 0 means return the left edge of the
972 whole window, to the right of the left fringe of W. */
975 window_box_left (w
, area
)
979 struct frame
*f
= XFRAME (w
->frame
);
980 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
982 if (!w
->pseudo_window_p
)
984 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
985 + FRAME_LEFT_FRINGE_WIDTH (f
));
987 if (area
== TEXT_AREA
)
988 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
989 else if (area
== RIGHT_MARGIN_AREA
)
990 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
991 + window_box_width (w
, TEXT_AREA
));
998 /* Return the frame-relative coordinate of the right edge of display
999 area AREA of window W. AREA < 0 means return the left edge of the
1000 whole window, to the left of the right fringe of W. */
1003 window_box_right (w
, area
)
1007 return window_box_left (w
, area
) + window_box_width (w
, area
);
1011 /* Get the bounding box of the display area AREA of window W, without
1012 mode lines, in frame-relative coordinates. AREA < 0 means the
1013 whole window, not including the left and right fringes of
1014 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1015 coordinates of the upper-left corner of the box. Return in
1016 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1019 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1022 int *box_x
, *box_y
, *box_width
, *box_height
;
1024 struct frame
*f
= XFRAME (w
->frame
);
1026 *box_width
= window_box_width (w
, area
);
1027 *box_height
= window_box_height (w
);
1028 *box_x
= window_box_left (w
, area
);
1029 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
1030 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
1031 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1032 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1036 /* Get the bounding box of the display area AREA of window W, without
1037 mode lines. AREA < 0 means the whole window, not including the
1038 left and right fringe of the window. Return in *TOP_LEFT_X
1039 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1040 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1041 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1045 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1046 bottom_right_x
, bottom_right_y
)
1049 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1051 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1053 *bottom_right_x
+= *top_left_x
;
1054 *bottom_right_y
+= *top_left_y
;
1059 /***********************************************************************
1061 ***********************************************************************/
1063 /* Return the bottom y-position of the line the iterator IT is in.
1064 This can modify IT's settings. */
1070 int line_height
= it
->max_ascent
+ it
->max_descent
;
1071 int line_top_y
= it
->current_y
;
1073 if (line_height
== 0)
1076 line_height
= last_height
;
1077 else if (IT_CHARPOS (*it
) < ZV
)
1079 move_it_by_lines (it
, 1, 1);
1080 line_height
= (it
->max_ascent
|| it
->max_descent
1081 ? it
->max_ascent
+ it
->max_descent
1086 struct glyph_row
*row
= it
->glyph_row
;
1088 /* Use the default character height. */
1089 it
->glyph_row
= NULL
;
1090 it
->what
= IT_CHARACTER
;
1093 PRODUCE_GLYPHS (it
);
1094 line_height
= it
->ascent
+ it
->descent
;
1095 it
->glyph_row
= row
;
1099 return line_top_y
+ line_height
;
1103 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1104 1 if POS is visible and the line containing POS is fully visible.
1105 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1106 and header-lines heights. */
1109 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1111 int charpos
, *fully
, exact_mode_line_heights_p
;
1114 struct text_pos top
;
1116 struct buffer
*old_buffer
= NULL
;
1118 if (XBUFFER (w
->buffer
) != current_buffer
)
1120 old_buffer
= current_buffer
;
1121 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1124 *fully
= visible_p
= 0;
1125 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1127 /* Compute exact mode line heights, if requested. */
1128 if (exact_mode_line_heights_p
)
1130 if (WINDOW_WANTS_MODELINE_P (w
))
1131 current_mode_line_height
1132 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1133 current_buffer
->mode_line_format
);
1135 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1136 current_header_line_height
1137 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1138 current_buffer
->header_line_format
);
1141 start_display (&it
, w
, top
);
1142 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1143 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1145 /* Note that we may overshoot because of invisible text. */
1146 if (IT_CHARPOS (it
) >= charpos
)
1148 int top_y
= it
.current_y
;
1149 int bottom_y
= line_bottom_y (&it
);
1150 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1152 if (top_y
< window_top_y
)
1153 visible_p
= bottom_y
> window_top_y
;
1154 else if (top_y
< it
.last_visible_y
)
1157 *fully
= bottom_y
<= it
.last_visible_y
;
1160 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1162 move_it_by_lines (&it
, 1, 0);
1163 if (charpos
< IT_CHARPOS (it
))
1171 set_buffer_internal_1 (old_buffer
);
1173 current_header_line_height
= current_mode_line_height
= -1;
1178 /* Return the next character from STR which is MAXLEN bytes long.
1179 Return in *LEN the length of the character. This is like
1180 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1181 we find one, we return a `?', but with the length of the invalid
1185 string_char_and_length (str
, maxlen
, len
)
1186 const unsigned char *str
;
1191 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1192 if (!CHAR_VALID_P (c
, 1))
1193 /* We may not change the length here because other places in Emacs
1194 don't use this function, i.e. they silently accept invalid
1203 /* Given a position POS containing a valid character and byte position
1204 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1206 static struct text_pos
1207 string_pos_nchars_ahead (pos
, string
, nchars
)
1208 struct text_pos pos
;
1212 xassert (STRINGP (string
) && nchars
>= 0);
1214 if (STRING_MULTIBYTE (string
))
1216 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1217 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1222 string_char_and_length (p
, rest
, &len
);
1223 p
+= len
, rest
-= len
;
1224 xassert (rest
>= 0);
1226 BYTEPOS (pos
) += len
;
1230 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1236 /* Value is the text position, i.e. character and byte position,
1237 for character position CHARPOS in STRING. */
1239 static INLINE
struct text_pos
1240 string_pos (charpos
, string
)
1244 struct text_pos pos
;
1245 xassert (STRINGP (string
));
1246 xassert (charpos
>= 0);
1247 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1252 /* Value is a text position, i.e. character and byte position, for
1253 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1254 means recognize multibyte characters. */
1256 static struct text_pos
1257 c_string_pos (charpos
, s
, multibyte_p
)
1262 struct text_pos pos
;
1264 xassert (s
!= NULL
);
1265 xassert (charpos
>= 0);
1269 int rest
= strlen (s
), len
;
1271 SET_TEXT_POS (pos
, 0, 0);
1274 string_char_and_length (s
, rest
, &len
);
1275 s
+= len
, rest
-= len
;
1276 xassert (rest
>= 0);
1278 BYTEPOS (pos
) += len
;
1282 SET_TEXT_POS (pos
, charpos
, charpos
);
1288 /* Value is the number of characters in C string S. MULTIBYTE_P
1289 non-zero means recognize multibyte characters. */
1292 number_of_chars (s
, multibyte_p
)
1300 int rest
= strlen (s
), len
;
1301 unsigned char *p
= (unsigned char *) s
;
1303 for (nchars
= 0; rest
> 0; ++nchars
)
1305 string_char_and_length (p
, rest
, &len
);
1306 rest
-= len
, p
+= len
;
1310 nchars
= strlen (s
);
1316 /* Compute byte position NEWPOS->bytepos corresponding to
1317 NEWPOS->charpos. POS is a known position in string STRING.
1318 NEWPOS->charpos must be >= POS.charpos. */
1321 compute_string_pos (newpos
, pos
, string
)
1322 struct text_pos
*newpos
, pos
;
1325 xassert (STRINGP (string
));
1326 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1328 if (STRING_MULTIBYTE (string
))
1329 *newpos
= string_pos_nchars_ahead (pos
, string
,
1330 CHARPOS (*newpos
) - CHARPOS (pos
));
1332 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1337 /***********************************************************************
1338 Lisp form evaluation
1339 ***********************************************************************/
1341 /* Error handler for safe_eval and safe_call. */
1344 safe_eval_handler (arg
)
1347 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1352 /* Evaluate SEXPR and return the result, or nil if something went
1353 wrong. Prevent redisplay during the evaluation. */
1361 if (inhibit_eval_during_redisplay
)
1365 int count
= SPECPDL_INDEX ();
1366 struct gcpro gcpro1
;
1369 specbind (Qinhibit_redisplay
, Qt
);
1370 /* Use Qt to ensure debugger does not run,
1371 so there is no possibility of wanting to redisplay. */
1372 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1375 val
= unbind_to (count
, val
);
1382 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1383 Return the result, or nil if something went wrong. Prevent
1384 redisplay during the evaluation. */
1387 safe_call (nargs
, args
)
1393 if (inhibit_eval_during_redisplay
)
1397 int count
= SPECPDL_INDEX ();
1398 struct gcpro gcpro1
;
1401 gcpro1
.nvars
= nargs
;
1402 specbind (Qinhibit_redisplay
, Qt
);
1403 /* Use Qt to ensure debugger does not run,
1404 so there is no possibility of wanting to redisplay. */
1405 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1408 val
= unbind_to (count
, val
);
1415 /* Call function FN with one argument ARG.
1416 Return the result, or nil if something went wrong. */
1419 safe_call1 (fn
, arg
)
1420 Lisp_Object fn
, arg
;
1422 Lisp_Object args
[2];
1425 return safe_call (2, args
);
1430 /***********************************************************************
1432 ***********************************************************************/
1436 /* Define CHECK_IT to perform sanity checks on iterators.
1437 This is for debugging. It is too slow to do unconditionally. */
1443 if (it
->method
== next_element_from_string
)
1445 xassert (STRINGP (it
->string
));
1446 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1448 else if (it
->method
== next_element_from_buffer
)
1450 /* Check that character and byte positions agree. */
1451 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1455 xassert (it
->current
.dpvec_index
>= 0);
1457 xassert (it
->current
.dpvec_index
< 0);
1460 #define CHECK_IT(IT) check_it ((IT))
1464 #define CHECK_IT(IT) (void) 0
1471 /* Check that the window end of window W is what we expect it
1472 to be---the last row in the current matrix displaying text. */
1475 check_window_end (w
)
1478 if (!MINI_WINDOW_P (w
)
1479 && !NILP (w
->window_end_valid
))
1481 struct glyph_row
*row
;
1482 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1483 XFASTINT (w
->window_end_vpos
)),
1485 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1486 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1490 #define CHECK_WINDOW_END(W) check_window_end ((W))
1492 #else /* not GLYPH_DEBUG */
1494 #define CHECK_WINDOW_END(W) (void) 0
1496 #endif /* not GLYPH_DEBUG */
1500 /***********************************************************************
1501 Iterator initialization
1502 ***********************************************************************/
1504 /* Initialize IT for displaying current_buffer in window W, starting
1505 at character position CHARPOS. CHARPOS < 0 means that no buffer
1506 position is specified which is useful when the iterator is assigned
1507 a position later. BYTEPOS is the byte position corresponding to
1508 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1510 If ROW is not null, calls to produce_glyphs with IT as parameter
1511 will produce glyphs in that row.
1513 BASE_FACE_ID is the id of a base face to use. It must be one of
1514 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1515 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1516 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1518 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1519 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1520 will be initialized to use the corresponding mode line glyph row of
1521 the desired matrix of W. */
1524 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1527 int charpos
, bytepos
;
1528 struct glyph_row
*row
;
1529 enum face_id base_face_id
;
1531 int highlight_region_p
;
1533 /* Some precondition checks. */
1534 xassert (w
!= NULL
&& it
!= NULL
);
1535 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1538 /* If face attributes have been changed since the last redisplay,
1539 free realized faces now because they depend on face definitions
1540 that might have changed. Don't free faces while there might be
1541 desired matrices pending which reference these faces. */
1542 if (face_change_count
&& !inhibit_free_realized_faces
)
1544 face_change_count
= 0;
1545 free_all_realized_faces (Qnil
);
1548 /* Use one of the mode line rows of W's desired matrix if
1552 if (base_face_id
== MODE_LINE_FACE_ID
1553 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1554 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1555 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1556 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1560 bzero (it
, sizeof *it
);
1561 it
->current
.overlay_string_index
= -1;
1562 it
->current
.dpvec_index
= -1;
1563 it
->base_face_id
= base_face_id
;
1565 /* The window in which we iterate over current_buffer: */
1566 XSETWINDOW (it
->window
, w
);
1568 it
->f
= XFRAME (w
->frame
);
1570 /* Extra space between lines (on window systems only). */
1571 if (base_face_id
== DEFAULT_FACE_ID
1572 && FRAME_WINDOW_P (it
->f
))
1574 if (NATNUMP (current_buffer
->extra_line_spacing
))
1575 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1576 else if (it
->f
->extra_line_spacing
> 0)
1577 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1580 /* If realized faces have been removed, e.g. because of face
1581 attribute changes of named faces, recompute them. When running
1582 in batch mode, the face cache of Vterminal_frame is null. If
1583 we happen to get called, make a dummy face cache. */
1588 FRAME_FACE_CACHE (it
->f
) == NULL
)
1589 init_frame_faces (it
->f
);
1590 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1591 recompute_basic_faces (it
->f
);
1593 /* Current value of the `space-width', and 'height' properties. */
1594 it
->space_width
= Qnil
;
1595 it
->font_height
= Qnil
;
1597 /* Are control characters displayed as `^C'? */
1598 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1600 /* -1 means everything between a CR and the following line end
1601 is invisible. >0 means lines indented more than this value are
1603 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1604 ? XFASTINT (current_buffer
->selective_display
)
1605 : (!NILP (current_buffer
->selective_display
)
1607 it
->selective_display_ellipsis_p
1608 = !NILP (current_buffer
->selective_display_ellipses
);
1610 /* Display table to use. */
1611 it
->dp
= window_display_table (w
);
1613 /* Are multibyte characters enabled in current_buffer? */
1614 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1616 /* Non-zero if we should highlight the region. */
1618 = (!NILP (Vtransient_mark_mode
)
1619 && !NILP (current_buffer
->mark_active
)
1620 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1622 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1623 start and end of a visible region in window IT->w. Set both to
1624 -1 to indicate no region. */
1625 if (highlight_region_p
1626 /* Maybe highlight only in selected window. */
1627 && (/* Either show region everywhere. */
1628 highlight_nonselected_windows
1629 /* Or show region in the selected window. */
1630 || w
== XWINDOW (selected_window
)
1631 /* Or show the region if we are in the mini-buffer and W is
1632 the window the mini-buffer refers to. */
1633 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1634 && WINDOWP (minibuf_selected_window
)
1635 && w
== XWINDOW (minibuf_selected_window
))))
1637 int charpos
= marker_position (current_buffer
->mark
);
1638 it
->region_beg_charpos
= min (PT
, charpos
);
1639 it
->region_end_charpos
= max (PT
, charpos
);
1642 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1644 /* Get the position at which the redisplay_end_trigger hook should
1645 be run, if it is to be run at all. */
1646 if (MARKERP (w
->redisplay_end_trigger
)
1647 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1648 it
->redisplay_end_trigger_charpos
1649 = marker_position (w
->redisplay_end_trigger
);
1650 else if (INTEGERP (w
->redisplay_end_trigger
))
1651 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1653 /* Correct bogus values of tab_width. */
1654 it
->tab_width
= XINT (current_buffer
->tab_width
);
1655 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1658 /* Are lines in the display truncated? */
1659 it
->truncate_lines_p
1660 = (base_face_id
!= DEFAULT_FACE_ID
1661 || XINT (it
->w
->hscroll
)
1662 || (truncate_partial_width_windows
1663 && !WINDOW_FULL_WIDTH_P (it
->w
))
1664 || !NILP (current_buffer
->truncate_lines
));
1666 /* Get dimensions of truncation and continuation glyphs. These are
1667 displayed as fringe bitmaps under X, so we don't need them for such
1669 if (!FRAME_WINDOW_P (it
->f
))
1671 if (it
->truncate_lines_p
)
1673 /* We will need the truncation glyph. */
1674 xassert (it
->glyph_row
== NULL
);
1675 produce_special_glyphs (it
, IT_TRUNCATION
);
1676 it
->truncation_pixel_width
= it
->pixel_width
;
1680 /* We will need the continuation glyph. */
1681 xassert (it
->glyph_row
== NULL
);
1682 produce_special_glyphs (it
, IT_CONTINUATION
);
1683 it
->continuation_pixel_width
= it
->pixel_width
;
1686 /* Reset these values to zero because the produce_special_glyphs
1687 above has changed them. */
1688 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1689 it
->phys_ascent
= it
->phys_descent
= 0;
1692 /* Set this after getting the dimensions of truncation and
1693 continuation glyphs, so that we don't produce glyphs when calling
1694 produce_special_glyphs, above. */
1695 it
->glyph_row
= row
;
1696 it
->area
= TEXT_AREA
;
1698 /* Get the dimensions of the display area. The display area
1699 consists of the visible window area plus a horizontally scrolled
1700 part to the left of the window. All x-values are relative to the
1701 start of this total display area. */
1702 if (base_face_id
!= DEFAULT_FACE_ID
)
1704 /* Mode lines, menu bar in terminal frames. */
1705 it
->first_visible_x
= 0;
1706 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1711 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1712 it
->last_visible_x
= (it
->first_visible_x
1713 + window_box_width (w
, TEXT_AREA
));
1715 /* If we truncate lines, leave room for the truncator glyph(s) at
1716 the right margin. Otherwise, leave room for the continuation
1717 glyph(s). Truncation and continuation glyphs are not inserted
1718 for window-based redisplay. */
1719 if (!FRAME_WINDOW_P (it
->f
))
1721 if (it
->truncate_lines_p
)
1722 it
->last_visible_x
-= it
->truncation_pixel_width
;
1724 it
->last_visible_x
-= it
->continuation_pixel_width
;
1727 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1728 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1731 /* Leave room for a border glyph. */
1732 if (!FRAME_WINDOW_P (it
->f
)
1733 && !WINDOW_RIGHTMOST_P (it
->w
))
1734 it
->last_visible_x
-= 1;
1736 it
->last_visible_y
= window_text_bottom_y (w
);
1738 /* For mode lines and alike, arrange for the first glyph having a
1739 left box line if the face specifies a box. */
1740 if (base_face_id
!= DEFAULT_FACE_ID
)
1744 it
->face_id
= base_face_id
;
1746 /* If we have a boxed mode line, make the first character appear
1747 with a left box line. */
1748 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1749 if (face
->box
!= FACE_NO_BOX
)
1750 it
->start_of_box_run_p
= 1;
1753 /* If a buffer position was specified, set the iterator there,
1754 getting overlays and face properties from that position. */
1755 if (charpos
>= BUF_BEG (current_buffer
))
1757 it
->end_charpos
= ZV
;
1759 IT_CHARPOS (*it
) = charpos
;
1761 /* Compute byte position if not specified. */
1762 if (bytepos
< charpos
)
1763 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1765 IT_BYTEPOS (*it
) = bytepos
;
1767 /* Compute faces etc. */
1768 reseat (it
, it
->current
.pos
, 1);
1775 /* Initialize IT for the display of window W with window start POS. */
1778 start_display (it
, w
, pos
)
1781 struct text_pos pos
;
1783 struct glyph_row
*row
;
1784 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1786 row
= w
->desired_matrix
->rows
+ first_vpos
;
1787 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1789 if (!it
->truncate_lines_p
)
1791 int start_at_line_beg_p
;
1792 int first_y
= it
->current_y
;
1794 /* If window start is not at a line start, skip forward to POS to
1795 get the correct continuation lines width. */
1796 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1797 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1798 if (!start_at_line_beg_p
)
1802 reseat_at_previous_visible_line_start (it
);
1803 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1805 new_x
= it
->current_x
+ it
->pixel_width
;
1807 /* If lines are continued, this line may end in the middle
1808 of a multi-glyph character (e.g. a control character
1809 displayed as \003, or in the middle of an overlay
1810 string). In this case move_it_to above will not have
1811 taken us to the start of the continuation line but to the
1812 end of the continued line. */
1813 if (it
->current_x
> 0
1814 && !it
->truncate_lines_p
/* Lines are continued. */
1815 && (/* And glyph doesn't fit on the line. */
1816 new_x
> it
->last_visible_x
1817 /* Or it fits exactly and we're on a window
1819 || (new_x
== it
->last_visible_x
1820 && FRAME_WINDOW_P (it
->f
))))
1822 if (it
->current
.dpvec_index
>= 0
1823 || it
->current
.overlay_string_index
>= 0)
1825 set_iterator_to_next (it
, 1);
1826 move_it_in_display_line_to (it
, -1, -1, 0);
1829 it
->continuation_lines_width
+= it
->current_x
;
1832 /* We're starting a new display line, not affected by the
1833 height of the continued line, so clear the appropriate
1834 fields in the iterator structure. */
1835 it
->max_ascent
= it
->max_descent
= 0;
1836 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
1838 it
->current_y
= first_y
;
1840 it
->current_x
= it
->hpos
= 0;
1844 #if 0 /* Don't assert the following because start_display is sometimes
1845 called intentionally with a window start that is not at a
1846 line start. Please leave this code in as a comment. */
1848 /* Window start should be on a line start, now. */
1849 xassert (it
->continuation_lines_width
1850 || IT_CHARPOS (it
) == BEGV
1851 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1856 /* Return 1 if POS is a position in ellipses displayed for invisible
1857 text. W is the window we display, for text property lookup. */
1860 in_ellipses_for_invisible_text_p (pos
, w
)
1861 struct display_pos
*pos
;
1864 Lisp_Object prop
, window
;
1866 int charpos
= CHARPOS (pos
->pos
);
1868 /* If POS specifies a position in a display vector, this might
1869 be for an ellipsis displayed for invisible text. We won't
1870 get the iterator set up for delivering that ellipsis unless
1871 we make sure that it gets aware of the invisible text. */
1872 if (pos
->dpvec_index
>= 0
1873 && pos
->overlay_string_index
< 0
1874 && CHARPOS (pos
->string_pos
) < 0
1876 && (XSETWINDOW (window
, w
),
1877 prop
= Fget_char_property (make_number (charpos
),
1878 Qinvisible
, window
),
1879 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
1881 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
1883 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
1890 /* Initialize IT for stepping through current_buffer in window W,
1891 starting at position POS that includes overlay string and display
1892 vector/ control character translation position information. Value
1893 is zero if there are overlay strings with newlines at POS. */
1896 init_from_display_pos (it
, w
, pos
)
1899 struct display_pos
*pos
;
1901 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
1902 int i
, overlay_strings_with_newlines
= 0;
1904 /* If POS specifies a position in a display vector, this might
1905 be for an ellipsis displayed for invisible text. We won't
1906 get the iterator set up for delivering that ellipsis unless
1907 we make sure that it gets aware of the invisible text. */
1908 if (in_ellipses_for_invisible_text_p (pos
, w
))
1914 /* Keep in mind: the call to reseat in init_iterator skips invisible
1915 text, so we might end up at a position different from POS. This
1916 is only a problem when POS is a row start after a newline and an
1917 overlay starts there with an after-string, and the overlay has an
1918 invisible property. Since we don't skip invisible text in
1919 display_line and elsewhere immediately after consuming the
1920 newline before the row start, such a POS will not be in a string,
1921 but the call to init_iterator below will move us to the
1923 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
1925 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
1927 const char *s
= SDATA (it
->overlay_strings
[i
]);
1928 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
1930 while (s
< e
&& *s
!= '\n')
1935 overlay_strings_with_newlines
= 1;
1940 /* If position is within an overlay string, set up IT to the right
1942 if (pos
->overlay_string_index
>= 0)
1946 /* If the first overlay string happens to have a `display'
1947 property for an image, the iterator will be set up for that
1948 image, and we have to undo that setup first before we can
1949 correct the overlay string index. */
1950 if (it
->method
== next_element_from_image
)
1953 /* We already have the first chunk of overlay strings in
1954 IT->overlay_strings. Load more until the one for
1955 pos->overlay_string_index is in IT->overlay_strings. */
1956 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1958 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1959 it
->current
.overlay_string_index
= 0;
1962 load_overlay_strings (it
, 0);
1963 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1967 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1968 relative_index
= (it
->current
.overlay_string_index
1969 % OVERLAY_STRING_CHUNK_SIZE
);
1970 it
->string
= it
->overlay_strings
[relative_index
];
1971 xassert (STRINGP (it
->string
));
1972 it
->current
.string_pos
= pos
->string_pos
;
1973 it
->method
= next_element_from_string
;
1976 #if 0 /* This is bogus because POS not having an overlay string
1977 position does not mean it's after the string. Example: A
1978 line starting with a before-string and initialization of IT
1979 to the previous row's end position. */
1980 else if (it
->current
.overlay_string_index
>= 0)
1982 /* If POS says we're already after an overlay string ending at
1983 POS, make sure to pop the iterator because it will be in
1984 front of that overlay string. When POS is ZV, we've thereby
1985 also ``processed'' overlay strings at ZV. */
1988 it
->current
.overlay_string_index
= -1;
1989 it
->method
= next_element_from_buffer
;
1990 if (CHARPOS (pos
->pos
) == ZV
)
1991 it
->overlay_strings_at_end_processed_p
= 1;
1995 if (CHARPOS (pos
->string_pos
) >= 0)
1997 /* Recorded position is not in an overlay string, but in another
1998 string. This can only be a string from a `display' property.
1999 IT should already be filled with that string. */
2000 it
->current
.string_pos
= pos
->string_pos
;
2001 xassert (STRINGP (it
->string
));
2004 /* Restore position in display vector translations, control
2005 character translations or ellipses. */
2006 if (pos
->dpvec_index
>= 0)
2008 if (it
->dpvec
== NULL
)
2009 get_next_display_element (it
);
2010 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2011 it
->current
.dpvec_index
= pos
->dpvec_index
;
2015 return !overlay_strings_with_newlines
;
2019 /* Initialize IT for stepping through current_buffer in window W
2020 starting at ROW->start. */
2023 init_to_row_start (it
, w
, row
)
2026 struct glyph_row
*row
;
2028 init_from_display_pos (it
, w
, &row
->start
);
2029 it
->continuation_lines_width
= row
->continuation_lines_width
;
2034 /* Initialize IT for stepping through current_buffer in window W
2035 starting in the line following ROW, i.e. starting at ROW->end.
2036 Value is zero if there are overlay strings with newlines at ROW's
2040 init_to_row_end (it
, w
, row
)
2043 struct glyph_row
*row
;
2047 if (init_from_display_pos (it
, w
, &row
->end
))
2049 if (row
->continued_p
)
2050 it
->continuation_lines_width
2051 = row
->continuation_lines_width
+ row
->pixel_width
;
2062 /***********************************************************************
2064 ***********************************************************************/
2066 /* Called when IT reaches IT->stop_charpos. Handle text property and
2067 overlay changes. Set IT->stop_charpos to the next position where
2074 enum prop_handled handled
;
2075 int handle_overlay_change_p
= 1;
2079 it
->current
.dpvec_index
= -1;
2083 handled
= HANDLED_NORMALLY
;
2085 /* Call text property handlers. */
2086 for (p
= it_props
; p
->handler
; ++p
)
2088 handled
= p
->handler (it
);
2090 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2092 else if (handled
== HANDLED_RETURN
)
2094 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2095 handle_overlay_change_p
= 0;
2098 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2100 /* Don't check for overlay strings below when set to deliver
2101 characters from a display vector. */
2102 if (it
->method
== next_element_from_display_vector
)
2103 handle_overlay_change_p
= 0;
2105 /* Handle overlay changes. */
2106 if (handle_overlay_change_p
)
2107 handled
= handle_overlay_change (it
);
2109 /* Determine where to stop next. */
2110 if (handled
== HANDLED_NORMALLY
)
2111 compute_stop_pos (it
);
2114 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2118 /* Compute IT->stop_charpos from text property and overlay change
2119 information for IT's current position. */
2122 compute_stop_pos (it
)
2125 register INTERVAL iv
, next_iv
;
2126 Lisp_Object object
, limit
, position
;
2128 /* If nowhere else, stop at the end. */
2129 it
->stop_charpos
= it
->end_charpos
;
2131 if (STRINGP (it
->string
))
2133 /* Strings are usually short, so don't limit the search for
2135 object
= it
->string
;
2137 position
= make_number (IT_STRING_CHARPOS (*it
));
2143 /* If next overlay change is in front of the current stop pos
2144 (which is IT->end_charpos), stop there. Note: value of
2145 next_overlay_change is point-max if no overlay change
2147 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2148 if (charpos
< it
->stop_charpos
)
2149 it
->stop_charpos
= charpos
;
2151 /* If showing the region, we have to stop at the region
2152 start or end because the face might change there. */
2153 if (it
->region_beg_charpos
> 0)
2155 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2156 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2157 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2158 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2161 /* Set up variables for computing the stop position from text
2162 property changes. */
2163 XSETBUFFER (object
, current_buffer
);
2164 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2165 position
= make_number (IT_CHARPOS (*it
));
2169 /* Get the interval containing IT's position. Value is a null
2170 interval if there isn't such an interval. */
2171 iv
= validate_interval_range (object
, &position
, &position
, 0);
2172 if (!NULL_INTERVAL_P (iv
))
2174 Lisp_Object values_here
[LAST_PROP_IDX
];
2177 /* Get properties here. */
2178 for (p
= it_props
; p
->handler
; ++p
)
2179 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2181 /* Look for an interval following iv that has different
2183 for (next_iv
= next_interval (iv
);
2184 (!NULL_INTERVAL_P (next_iv
)
2186 || XFASTINT (limit
) > next_iv
->position
));
2187 next_iv
= next_interval (next_iv
))
2189 for (p
= it_props
; p
->handler
; ++p
)
2191 Lisp_Object new_value
;
2193 new_value
= textget (next_iv
->plist
, *p
->name
);
2194 if (!EQ (values_here
[p
->idx
], new_value
))
2202 if (!NULL_INTERVAL_P (next_iv
))
2204 if (INTEGERP (limit
)
2205 && next_iv
->position
>= XFASTINT (limit
))
2206 /* No text property change up to limit. */
2207 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2209 /* Text properties change in next_iv. */
2210 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2214 xassert (STRINGP (it
->string
)
2215 || (it
->stop_charpos
>= BEGV
2216 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2220 /* Return the position of the next overlay change after POS in
2221 current_buffer. Value is point-max if no overlay change
2222 follows. This is like `next-overlay-change' but doesn't use
2226 next_overlay_change (pos
)
2231 Lisp_Object
*overlays
;
2235 /* Get all overlays at the given position. */
2237 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2238 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2239 if (noverlays
> len
)
2242 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2243 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2246 /* If any of these overlays ends before endpos,
2247 use its ending point instead. */
2248 for (i
= 0; i
< noverlays
; ++i
)
2253 oend
= OVERLAY_END (overlays
[i
]);
2254 oendpos
= OVERLAY_POSITION (oend
);
2255 endpos
= min (endpos
, oendpos
);
2263 /***********************************************************************
2265 ***********************************************************************/
2267 /* Handle changes in the `fontified' property of the current buffer by
2268 calling hook functions from Qfontification_functions to fontify
2271 static enum prop_handled
2272 handle_fontified_prop (it
)
2275 Lisp_Object prop
, pos
;
2276 enum prop_handled handled
= HANDLED_NORMALLY
;
2278 /* Get the value of the `fontified' property at IT's current buffer
2279 position. (The `fontified' property doesn't have a special
2280 meaning in strings.) If the value is nil, call functions from
2281 Qfontification_functions. */
2282 if (!STRINGP (it
->string
)
2284 && !NILP (Vfontification_functions
)
2285 && !NILP (Vrun_hooks
)
2286 && (pos
= make_number (IT_CHARPOS (*it
)),
2287 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2290 int count
= SPECPDL_INDEX ();
2293 val
= Vfontification_functions
;
2294 specbind (Qfontification_functions
, Qnil
);
2296 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2297 safe_call1 (val
, pos
);
2300 Lisp_Object globals
, fn
;
2301 struct gcpro gcpro1
, gcpro2
;
2304 GCPRO2 (val
, globals
);
2306 for (; CONSP (val
); val
= XCDR (val
))
2312 /* A value of t indicates this hook has a local
2313 binding; it means to run the global binding too.
2314 In a global value, t should not occur. If it
2315 does, we must ignore it to avoid an endless
2317 for (globals
= Fdefault_value (Qfontification_functions
);
2319 globals
= XCDR (globals
))
2321 fn
= XCAR (globals
);
2323 safe_call1 (fn
, pos
);
2327 safe_call1 (fn
, pos
);
2333 unbind_to (count
, Qnil
);
2335 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2336 something. This avoids an endless loop if they failed to
2337 fontify the text for which reason ever. */
2338 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2339 handled
= HANDLED_RECOMPUTE_PROPS
;
2347 /***********************************************************************
2349 ***********************************************************************/
2351 /* Set up iterator IT from face properties at its current position.
2352 Called from handle_stop. */
2354 static enum prop_handled
2355 handle_face_prop (it
)
2358 int new_face_id
, next_stop
;
2360 if (!STRINGP (it
->string
))
2363 = face_at_buffer_position (it
->w
,
2365 it
->region_beg_charpos
,
2366 it
->region_end_charpos
,
2369 + TEXT_PROP_DISTANCE_LIMIT
),
2372 /* Is this a start of a run of characters with box face?
2373 Caveat: this can be called for a freshly initialized
2374 iterator; face_id is -1 in this case. We know that the new
2375 face will not change until limit, i.e. if the new face has a
2376 box, all characters up to limit will have one. But, as
2377 usual, we don't know whether limit is really the end. */
2378 if (new_face_id
!= it
->face_id
)
2380 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2382 /* If new face has a box but old face has not, this is
2383 the start of a run of characters with box, i.e. it has
2384 a shadow on the left side. The value of face_id of the
2385 iterator will be -1 if this is the initial call that gets
2386 the face. In this case, we have to look in front of IT's
2387 position and see whether there is a face != new_face_id. */
2388 it
->start_of_box_run_p
2389 = (new_face
->box
!= FACE_NO_BOX
2390 && (it
->face_id
>= 0
2391 || IT_CHARPOS (*it
) == BEG
2392 || new_face_id
!= face_before_it_pos (it
)));
2393 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2398 int base_face_id
, bufpos
;
2400 if (it
->current
.overlay_string_index
>= 0)
2401 bufpos
= IT_CHARPOS (*it
);
2405 /* For strings from a buffer, i.e. overlay strings or strings
2406 from a `display' property, use the face at IT's current
2407 buffer position as the base face to merge with, so that
2408 overlay strings appear in the same face as surrounding
2409 text, unless they specify their own faces. */
2410 base_face_id
= underlying_face_id (it
);
2412 new_face_id
= face_at_string_position (it
->w
,
2414 IT_STRING_CHARPOS (*it
),
2416 it
->region_beg_charpos
,
2417 it
->region_end_charpos
,
2421 #if 0 /* This shouldn't be neccessary. Let's check it. */
2422 /* If IT is used to display a mode line we would really like to
2423 use the mode line face instead of the frame's default face. */
2424 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2425 && new_face_id
== DEFAULT_FACE_ID
)
2426 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2429 /* Is this a start of a run of characters with box? Caveat:
2430 this can be called for a freshly allocated iterator; face_id
2431 is -1 is this case. We know that the new face will not
2432 change until the next check pos, i.e. if the new face has a
2433 box, all characters up to that position will have a
2434 box. But, as usual, we don't know whether that position
2435 is really the end. */
2436 if (new_face_id
!= it
->face_id
)
2438 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2439 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2441 /* If new face has a box but old face hasn't, this is the
2442 start of a run of characters with box, i.e. it has a
2443 shadow on the left side. */
2444 it
->start_of_box_run_p
2445 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2446 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2450 it
->face_id
= new_face_id
;
2451 return HANDLED_NORMALLY
;
2455 /* Return the ID of the face ``underlying'' IT's current position,
2456 which is in a string. If the iterator is associated with a
2457 buffer, return the face at IT's current buffer position.
2458 Otherwise, use the iterator's base_face_id. */
2461 underlying_face_id (it
)
2464 int face_id
= it
->base_face_id
, i
;
2466 xassert (STRINGP (it
->string
));
2468 for (i
= it
->sp
- 1; i
>= 0; --i
)
2469 if (NILP (it
->stack
[i
].string
))
2470 face_id
= it
->stack
[i
].face_id
;
2476 /* Compute the face one character before or after the current position
2477 of IT. BEFORE_P non-zero means get the face in front of IT's
2478 position. Value is the id of the face. */
2481 face_before_or_after_it_pos (it
, before_p
)
2486 int next_check_charpos
;
2487 struct text_pos pos
;
2489 xassert (it
->s
== NULL
);
2491 if (STRINGP (it
->string
))
2493 int bufpos
, base_face_id
;
2495 /* No face change past the end of the string (for the case
2496 we are padding with spaces). No face change before the
2498 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2499 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2502 /* Set pos to the position before or after IT's current position. */
2504 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2506 /* For composition, we must check the character after the
2508 pos
= (it
->what
== IT_COMPOSITION
2509 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2510 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2512 if (it
->current
.overlay_string_index
>= 0)
2513 bufpos
= IT_CHARPOS (*it
);
2517 base_face_id
= underlying_face_id (it
);
2519 /* Get the face for ASCII, or unibyte. */
2520 face_id
= face_at_string_position (it
->w
,
2524 it
->region_beg_charpos
,
2525 it
->region_end_charpos
,
2526 &next_check_charpos
,
2529 /* Correct the face for charsets different from ASCII. Do it
2530 for the multibyte case only. The face returned above is
2531 suitable for unibyte text if IT->string is unibyte. */
2532 if (STRING_MULTIBYTE (it
->string
))
2534 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2535 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2537 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2539 c
= string_char_and_length (p
, rest
, &len
);
2540 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2545 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2546 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2549 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2550 pos
= it
->current
.pos
;
2553 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2556 if (it
->what
== IT_COMPOSITION
)
2557 /* For composition, we must check the position after the
2559 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2561 INC_TEXT_POS (pos
, it
->multibyte_p
);
2564 /* Determine face for CHARSET_ASCII, or unibyte. */
2565 face_id
= face_at_buffer_position (it
->w
,
2567 it
->region_beg_charpos
,
2568 it
->region_end_charpos
,
2569 &next_check_charpos
,
2572 /* Correct the face for charsets different from ASCII. Do it
2573 for the multibyte case only. The face returned above is
2574 suitable for unibyte text if current_buffer is unibyte. */
2575 if (it
->multibyte_p
)
2577 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2578 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2579 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2588 /***********************************************************************
2590 ***********************************************************************/
2592 /* Set up iterator IT from invisible properties at its current
2593 position. Called from handle_stop. */
2595 static enum prop_handled
2596 handle_invisible_prop (it
)
2599 enum prop_handled handled
= HANDLED_NORMALLY
;
2601 if (STRINGP (it
->string
))
2603 extern Lisp_Object Qinvisible
;
2604 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2606 /* Get the value of the invisible text property at the
2607 current position. Value will be nil if there is no such
2609 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2610 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2613 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2615 handled
= HANDLED_RECOMPUTE_PROPS
;
2617 /* Get the position at which the next change of the
2618 invisible text property can be found in IT->string.
2619 Value will be nil if the property value is the same for
2620 all the rest of IT->string. */
2621 XSETINT (limit
, SCHARS (it
->string
));
2622 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2625 /* Text at current position is invisible. The next
2626 change in the property is at position end_charpos.
2627 Move IT's current position to that position. */
2628 if (INTEGERP (end_charpos
)
2629 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2631 struct text_pos old
;
2632 old
= it
->current
.string_pos
;
2633 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2634 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2638 /* The rest of the string is invisible. If this is an
2639 overlay string, proceed with the next overlay string
2640 or whatever comes and return a character from there. */
2641 if (it
->current
.overlay_string_index
>= 0)
2643 next_overlay_string (it
);
2644 /* Don't check for overlay strings when we just
2645 finished processing them. */
2646 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2650 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
2651 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
2658 int invis_p
, newpos
, next_stop
, start_charpos
;
2659 Lisp_Object pos
, prop
, overlay
;
2661 /* First of all, is there invisible text at this position? */
2662 start_charpos
= IT_CHARPOS (*it
);
2663 pos
= make_number (IT_CHARPOS (*it
));
2664 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
2666 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2668 /* If we are on invisible text, skip over it. */
2669 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
2671 /* Record whether we have to display an ellipsis for the
2673 int display_ellipsis_p
= invis_p
== 2;
2675 handled
= HANDLED_RECOMPUTE_PROPS
;
2677 /* Loop skipping over invisible text. The loop is left at
2678 ZV or with IT on the first char being visible again. */
2681 /* Try to skip some invisible text. Return value is the
2682 position reached which can be equal to IT's position
2683 if there is nothing invisible here. This skips both
2684 over invisible text properties and overlays with
2685 invisible property. */
2686 newpos
= skip_invisible (IT_CHARPOS (*it
),
2687 &next_stop
, ZV
, it
->window
);
2689 /* If we skipped nothing at all we weren't at invisible
2690 text in the first place. If everything to the end of
2691 the buffer was skipped, end the loop. */
2692 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2696 /* We skipped some characters but not necessarily
2697 all there are. Check if we ended up on visible
2698 text. Fget_char_property returns the property of
2699 the char before the given position, i.e. if we
2700 get invis_p = 0, this means that the char at
2701 newpos is visible. */
2702 pos
= make_number (newpos
);
2703 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2704 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
2707 /* If we ended up on invisible text, proceed to
2708 skip starting with next_stop. */
2710 IT_CHARPOS (*it
) = next_stop
;
2714 /* The position newpos is now either ZV or on visible text. */
2715 IT_CHARPOS (*it
) = newpos
;
2716 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2718 /* If there are before-strings at the start of invisible
2719 text, and the text is invisible because of a text
2720 property, arrange to show before-strings because 20.x did
2721 it that way. (If the text is invisible because of an
2722 overlay property instead of a text property, this is
2723 already handled in the overlay code.) */
2725 && get_overlay_strings (it
, start_charpos
))
2727 handled
= HANDLED_RECOMPUTE_PROPS
;
2728 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
2730 else if (display_ellipsis_p
)
2731 setup_for_ellipsis (it
);
2739 /* Make iterator IT return `...' next. */
2742 setup_for_ellipsis (it
)
2746 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2748 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2749 it
->dpvec
= v
->contents
;
2750 it
->dpend
= v
->contents
+ v
->size
;
2754 /* Default `...'. */
2755 it
->dpvec
= default_invis_vector
;
2756 it
->dpend
= default_invis_vector
+ 3;
2759 /* The ellipsis display does not replace the display of the
2760 character at the new position. Indicate this by setting
2761 IT->dpvec_char_len to zero. */
2762 it
->dpvec_char_len
= 0;
2764 it
->current
.dpvec_index
= 0;
2765 it
->method
= next_element_from_display_vector
;
2770 /***********************************************************************
2772 ***********************************************************************/
2774 /* Set up iterator IT from `display' property at its current position.
2775 Called from handle_stop. */
2777 static enum prop_handled
2778 handle_display_prop (it
)
2781 Lisp_Object prop
, object
;
2782 struct text_pos
*position
;
2783 int display_replaced_p
= 0;
2785 if (STRINGP (it
->string
))
2787 object
= it
->string
;
2788 position
= &it
->current
.string_pos
;
2792 object
= it
->w
->buffer
;
2793 position
= &it
->current
.pos
;
2796 /* Reset those iterator values set from display property values. */
2797 it
->font_height
= Qnil
;
2798 it
->space_width
= Qnil
;
2801 /* We don't support recursive `display' properties, i.e. string
2802 values that have a string `display' property, that have a string
2803 `display' property etc. */
2804 if (!it
->string_from_display_prop_p
)
2805 it
->area
= TEXT_AREA
;
2807 prop
= Fget_char_property (make_number (position
->charpos
),
2810 return HANDLED_NORMALLY
;
2813 /* Simple properties. */
2814 && !EQ (XCAR (prop
), Qimage
)
2815 && !EQ (XCAR (prop
), Qspace
)
2816 && !EQ (XCAR (prop
), Qwhen
)
2817 && !EQ (XCAR (prop
), Qspace_width
)
2818 && !EQ (XCAR (prop
), Qheight
)
2819 && !EQ (XCAR (prop
), Qraise
)
2820 /* Marginal area specifications. */
2821 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
2822 && !NILP (XCAR (prop
)))
2824 for (; CONSP (prop
); prop
= XCDR (prop
))
2826 if (handle_single_display_prop (it
, XCAR (prop
), object
,
2827 position
, display_replaced_p
))
2828 display_replaced_p
= 1;
2831 else if (VECTORP (prop
))
2834 for (i
= 0; i
< ASIZE (prop
); ++i
)
2835 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
2836 position
, display_replaced_p
))
2837 display_replaced_p
= 1;
2841 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
2842 display_replaced_p
= 1;
2845 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2849 /* Value is the position of the end of the `display' property starting
2850 at START_POS in OBJECT. */
2852 static struct text_pos
2853 display_prop_end (it
, object
, start_pos
)
2856 struct text_pos start_pos
;
2859 struct text_pos end_pos
;
2861 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
2862 Qdisplay
, object
, Qnil
);
2863 CHARPOS (end_pos
) = XFASTINT (end
);
2864 if (STRINGP (object
))
2865 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2867 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2873 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2874 is the object in which the `display' property was found. *POSITION
2875 is the position at which it was found. DISPLAY_REPLACED_P non-zero
2876 means that we previously saw a display sub-property which already
2877 replaced text display with something else, for example an image;
2878 ignore such properties after the first one has been processed.
2880 If PROP is a `space' or `image' sub-property, set *POSITION to the
2881 end position of the `display' property.
2883 Value is non-zero if something was found which replaces the display
2884 of buffer or string text. */
2887 handle_single_display_prop (it
, prop
, object
, position
,
2888 display_replaced_before_p
)
2892 struct text_pos
*position
;
2893 int display_replaced_before_p
;
2896 int replaces_text_display_p
= 0;
2899 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2900 evaluated. If the result is nil, VALUE is ignored. */
2902 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2911 if (!NILP (form
) && !EQ (form
, Qt
))
2913 int count
= SPECPDL_INDEX ();
2914 struct gcpro gcpro1
;
2916 /* Bind `object' to the object having the `display' property, a
2917 buffer or string. Bind `position' to the position in the
2918 object where the property was found, and `buffer-position'
2919 to the current position in the buffer. */
2920 specbind (Qobject
, object
);
2921 specbind (Qposition
, make_number (CHARPOS (*position
)));
2922 specbind (Qbuffer_position
,
2923 make_number (STRINGP (object
)
2924 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
2926 form
= safe_eval (form
);
2928 unbind_to (count
, Qnil
);
2935 && EQ (XCAR (prop
), Qheight
)
2936 && CONSP (XCDR (prop
)))
2938 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2941 /* `(height HEIGHT)'. */
2942 it
->font_height
= XCAR (XCDR (prop
));
2943 if (!NILP (it
->font_height
))
2945 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2946 int new_height
= -1;
2948 if (CONSP (it
->font_height
)
2949 && (EQ (XCAR (it
->font_height
), Qplus
)
2950 || EQ (XCAR (it
->font_height
), Qminus
))
2951 && CONSP (XCDR (it
->font_height
))
2952 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2954 /* `(+ N)' or `(- N)' where N is an integer. */
2955 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2956 if (EQ (XCAR (it
->font_height
), Qplus
))
2958 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2960 else if (FUNCTIONP (it
->font_height
))
2962 /* Call function with current height as argument.
2963 Value is the new height. */
2965 height
= safe_call1 (it
->font_height
,
2966 face
->lface
[LFACE_HEIGHT_INDEX
]);
2967 if (NUMBERP (height
))
2968 new_height
= XFLOATINT (height
);
2970 else if (NUMBERP (it
->font_height
))
2972 /* Value is a multiple of the canonical char height. */
2975 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2976 new_height
= (XFLOATINT (it
->font_height
)
2977 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2981 /* Evaluate IT->font_height with `height' bound to the
2982 current specified height to get the new height. */
2984 int count
= SPECPDL_INDEX ();
2986 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2987 value
= safe_eval (it
->font_height
);
2988 unbind_to (count
, Qnil
);
2990 if (NUMBERP (value
))
2991 new_height
= XFLOATINT (value
);
2995 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2998 else if (CONSP (prop
)
2999 && EQ (XCAR (prop
), Qspace_width
)
3000 && CONSP (XCDR (prop
)))
3002 /* `(space_width WIDTH)'. */
3003 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3006 value
= XCAR (XCDR (prop
));
3007 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3008 it
->space_width
= value
;
3010 else if (CONSP (prop
)
3011 && EQ (XCAR (prop
), Qraise
)
3012 && CONSP (XCDR (prop
)))
3014 /* `(raise FACTOR)'. */
3015 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3018 #ifdef HAVE_WINDOW_SYSTEM
3019 value
= XCAR (XCDR (prop
));
3020 if (NUMBERP (value
))
3022 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3023 it
->voffset
= - (XFLOATINT (value
)
3024 * (FONT_HEIGHT (face
->font
)));
3026 #endif /* HAVE_WINDOW_SYSTEM */
3028 else if (!it
->string_from_display_prop_p
)
3030 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3031 VALUE) or `((margin nil) VALUE)' or VALUE. */
3032 Lisp_Object location
, value
;
3033 struct text_pos start_pos
;
3036 /* Characters having this form of property are not displayed, so
3037 we have to find the end of the property. */
3038 start_pos
= *position
;
3039 *position
= display_prop_end (it
, object
, start_pos
);
3042 /* Let's stop at the new position and assume that all
3043 text properties change there. */
3044 it
->stop_charpos
= position
->charpos
;
3046 location
= Qunbound
;
3047 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3051 value
= XCDR (prop
);
3053 value
= XCAR (value
);
3056 if (EQ (XCAR (tem
), Qmargin
)
3057 && (tem
= XCDR (tem
),
3058 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3060 || EQ (tem
, Qleft_margin
)
3061 || EQ (tem
, Qright_margin
))))
3065 if (EQ (location
, Qunbound
))
3071 #ifdef HAVE_WINDOW_SYSTEM
3072 if (FRAME_TERMCAP_P (it
->f
))
3073 valid_p
= STRINGP (value
);
3075 valid_p
= (STRINGP (value
)
3076 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3077 || valid_image_p (value
));
3078 #else /* not HAVE_WINDOW_SYSTEM */
3079 valid_p
= STRINGP (value
);
3080 #endif /* not HAVE_WINDOW_SYSTEM */
3082 if ((EQ (location
, Qleft_margin
)
3083 || EQ (location
, Qright_margin
)
3086 && !display_replaced_before_p
)
3088 replaces_text_display_p
= 1;
3090 /* Save current settings of IT so that we can restore them
3091 when we are finished with the glyph property value. */
3094 if (NILP (location
))
3095 it
->area
= TEXT_AREA
;
3096 else if (EQ (location
, Qleft_margin
))
3097 it
->area
= LEFT_MARGIN_AREA
;
3099 it
->area
= RIGHT_MARGIN_AREA
;
3101 if (STRINGP (value
))
3104 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3105 it
->current
.overlay_string_index
= -1;
3106 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3107 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3108 it
->method
= next_element_from_string
;
3109 it
->stop_charpos
= 0;
3110 it
->string_from_display_prop_p
= 1;
3111 /* Say that we haven't consumed the characters with
3112 `display' property yet. The call to pop_it in
3113 set_iterator_to_next will clean this up. */
3114 *position
= start_pos
;
3116 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3118 it
->method
= next_element_from_stretch
;
3120 it
->current
.pos
= it
->position
= start_pos
;
3122 #ifdef HAVE_WINDOW_SYSTEM
3125 it
->what
= IT_IMAGE
;
3126 it
->image_id
= lookup_image (it
->f
, value
);
3127 it
->position
= start_pos
;
3128 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3129 it
->method
= next_element_from_image
;
3131 /* Say that we haven't consumed the characters with
3132 `display' property yet. The call to pop_it in
3133 set_iterator_to_next will clean this up. */
3134 *position
= start_pos
;
3136 #endif /* HAVE_WINDOW_SYSTEM */
3139 /* Invalid property or property not supported. Restore
3140 the position to what it was before. */
3141 *position
= start_pos
;
3144 return replaces_text_display_p
;
3148 /* Check if PROP is a display sub-property value whose text should be
3149 treated as intangible. */
3152 single_display_prop_intangible_p (prop
)
3155 /* Skip over `when FORM'. */
3156 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3170 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3171 we don't need to treat text as intangible. */
3172 if (EQ (XCAR (prop
), Qmargin
))
3180 || EQ (XCAR (prop
), Qleft_margin
)
3181 || EQ (XCAR (prop
), Qright_margin
))
3185 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3189 /* Check if PROP is a display property value whose text should be
3190 treated as intangible. */
3193 display_prop_intangible_p (prop
)
3197 && CONSP (XCAR (prop
))
3198 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3200 /* A list of sub-properties. */
3201 while (CONSP (prop
))
3203 if (single_display_prop_intangible_p (XCAR (prop
)))
3208 else if (VECTORP (prop
))
3210 /* A vector of sub-properties. */
3212 for (i
= 0; i
< ASIZE (prop
); ++i
)
3213 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3217 return single_display_prop_intangible_p (prop
);
3223 /* Return 1 if PROP is a display sub-property value containing STRING. */
3226 single_display_prop_string_p (prop
, string
)
3227 Lisp_Object prop
, string
;
3229 if (EQ (string
, prop
))
3232 /* Skip over `when FORM'. */
3233 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3242 /* Skip over `margin LOCATION'. */
3243 if (EQ (XCAR (prop
), Qmargin
))
3254 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3258 /* Return 1 if STRING appears in the `display' property PROP. */
3261 display_prop_string_p (prop
, string
)
3262 Lisp_Object prop
, string
;
3265 && CONSP (XCAR (prop
))
3266 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3268 /* A list of sub-properties. */
3269 while (CONSP (prop
))
3271 if (single_display_prop_string_p (XCAR (prop
), string
))
3276 else if (VECTORP (prop
))
3278 /* A vector of sub-properties. */
3280 for (i
= 0; i
< ASIZE (prop
); ++i
)
3281 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3285 return single_display_prop_string_p (prop
, string
);
3291 /* Determine from which buffer position in W's buffer STRING comes
3292 from. AROUND_CHARPOS is an approximate position where it could
3293 be from. Value is the buffer position or 0 if it couldn't be
3296 W's buffer must be current.
3298 This function is necessary because we don't record buffer positions
3299 in glyphs generated from strings (to keep struct glyph small).
3300 This function may only use code that doesn't eval because it is
3301 called asynchronously from note_mouse_highlight. */
3304 string_buffer_position (w
, string
, around_charpos
)
3309 Lisp_Object limit
, prop
, pos
;
3310 const int MAX_DISTANCE
= 1000;
3313 pos
= make_number (around_charpos
);
3314 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3315 while (!found
&& !EQ (pos
, limit
))
3317 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3318 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3321 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3326 pos
= make_number (around_charpos
);
3327 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3328 while (!found
&& !EQ (pos
, limit
))
3330 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3331 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3334 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3339 return found
? XINT (pos
) : 0;
3344 /***********************************************************************
3345 `composition' property
3346 ***********************************************************************/
3348 /* Set up iterator IT from `composition' property at its current
3349 position. Called from handle_stop. */
3351 static enum prop_handled
3352 handle_composition_prop (it
)
3355 Lisp_Object prop
, string
;
3356 int pos
, pos_byte
, end
;
3357 enum prop_handled handled
= HANDLED_NORMALLY
;
3359 if (STRINGP (it
->string
))
3361 pos
= IT_STRING_CHARPOS (*it
);
3362 pos_byte
= IT_STRING_BYTEPOS (*it
);
3363 string
= it
->string
;
3367 pos
= IT_CHARPOS (*it
);
3368 pos_byte
= IT_BYTEPOS (*it
);
3372 /* If there's a valid composition and point is not inside of the
3373 composition (in the case that the composition is from the current
3374 buffer), draw a glyph composed from the composition components. */
3375 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3376 && COMPOSITION_VALID_P (pos
, end
, prop
)
3377 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3379 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3383 it
->method
= next_element_from_composition
;
3385 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3386 /* For a terminal, draw only the first character of the
3388 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3389 it
->len
= (STRINGP (it
->string
)
3390 ? string_char_to_byte (it
->string
, end
)
3391 : CHAR_TO_BYTE (end
)) - pos_byte
;
3392 it
->stop_charpos
= end
;
3393 handled
= HANDLED_RETURN
;
3402 /***********************************************************************
3404 ***********************************************************************/
3406 /* The following structure is used to record overlay strings for
3407 later sorting in load_overlay_strings. */
3409 struct overlay_entry
3411 Lisp_Object overlay
;
3418 /* Set up iterator IT from overlay strings at its current position.
3419 Called from handle_stop. */
3421 static enum prop_handled
3422 handle_overlay_change (it
)
3425 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3426 return HANDLED_RECOMPUTE_PROPS
;
3428 return HANDLED_NORMALLY
;
3432 /* Set up the next overlay string for delivery by IT, if there is an
3433 overlay string to deliver. Called by set_iterator_to_next when the
3434 end of the current overlay string is reached. If there are more
3435 overlay strings to display, IT->string and
3436 IT->current.overlay_string_index are set appropriately here.
3437 Otherwise IT->string is set to nil. */
3440 next_overlay_string (it
)
3443 ++it
->current
.overlay_string_index
;
3444 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3446 /* No more overlay strings. Restore IT's settings to what
3447 they were before overlay strings were processed, and
3448 continue to deliver from current_buffer. */
3449 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3452 xassert (it
->stop_charpos
>= BEGV
3453 && it
->stop_charpos
<= it
->end_charpos
);
3455 it
->current
.overlay_string_index
= -1;
3456 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3457 it
->n_overlay_strings
= 0;
3458 it
->method
= next_element_from_buffer
;
3460 /* If we're at the end of the buffer, record that we have
3461 processed the overlay strings there already, so that
3462 next_element_from_buffer doesn't try it again. */
3463 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3464 it
->overlay_strings_at_end_processed_p
= 1;
3466 /* If we have to display `...' for invisible text, set
3467 the iterator up for that. */
3468 if (display_ellipsis_p
)
3469 setup_for_ellipsis (it
);
3473 /* There are more overlay strings to process. If
3474 IT->current.overlay_string_index has advanced to a position
3475 where we must load IT->overlay_strings with more strings, do
3477 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3479 if (it
->current
.overlay_string_index
&& i
== 0)
3480 load_overlay_strings (it
, 0);
3482 /* Initialize IT to deliver display elements from the overlay
3484 it
->string
= it
->overlay_strings
[i
];
3485 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3486 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3487 it
->method
= next_element_from_string
;
3488 it
->stop_charpos
= 0;
3495 /* Compare two overlay_entry structures E1 and E2. Used as a
3496 comparison function for qsort in load_overlay_strings. Overlay
3497 strings for the same position are sorted so that
3499 1. All after-strings come in front of before-strings, except
3500 when they come from the same overlay.
3502 2. Within after-strings, strings are sorted so that overlay strings
3503 from overlays with higher priorities come first.
3505 2. Within before-strings, strings are sorted so that overlay
3506 strings from overlays with higher priorities come last.
3508 Value is analogous to strcmp. */
3512 compare_overlay_entries (e1
, e2
)
3515 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3516 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3519 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3521 /* Let after-strings appear in front of before-strings if
3522 they come from different overlays. */
3523 if (EQ (entry1
->overlay
, entry2
->overlay
))
3524 result
= entry1
->after_string_p
? 1 : -1;
3526 result
= entry1
->after_string_p
? -1 : 1;
3528 else if (entry1
->after_string_p
)
3529 /* After-strings sorted in order of decreasing priority. */
3530 result
= entry2
->priority
- entry1
->priority
;
3532 /* Before-strings sorted in order of increasing priority. */
3533 result
= entry1
->priority
- entry2
->priority
;
3539 /* Load the vector IT->overlay_strings with overlay strings from IT's
3540 current buffer position, or from CHARPOS if that is > 0. Set
3541 IT->n_overlays to the total number of overlay strings found.
3543 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3544 a time. On entry into load_overlay_strings,
3545 IT->current.overlay_string_index gives the number of overlay
3546 strings that have already been loaded by previous calls to this
3549 IT->add_overlay_start contains an additional overlay start
3550 position to consider for taking overlay strings from, if non-zero.
3551 This position comes into play when the overlay has an `invisible'
3552 property, and both before and after-strings. When we've skipped to
3553 the end of the overlay, because of its `invisible' property, we
3554 nevertheless want its before-string to appear.
3555 IT->add_overlay_start will contain the overlay start position
3558 Overlay strings are sorted so that after-string strings come in
3559 front of before-string strings. Within before and after-strings,
3560 strings are sorted by overlay priority. See also function
3561 compare_overlay_entries. */
3564 load_overlay_strings (it
, charpos
)
3568 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3569 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3572 int n
= 0, i
, j
, invis_p
;
3573 struct overlay_entry
*entries
3574 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3577 charpos
= IT_CHARPOS (*it
);
3579 /* Append the overlay string STRING of overlay OVERLAY to vector
3580 `entries' which has size `size' and currently contains `n'
3581 elements. AFTER_P non-zero means STRING is an after-string of
3583 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3586 Lisp_Object priority; \
3590 int new_size = 2 * size; \
3591 struct overlay_entry *old = entries; \
3593 (struct overlay_entry *) alloca (new_size \
3594 * sizeof *entries); \
3595 bcopy (old, entries, size * sizeof *entries); \
3599 entries[n].string = (STRING); \
3600 entries[n].overlay = (OVERLAY); \
3601 priority = Foverlay_get ((OVERLAY), Qpriority); \
3602 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3603 entries[n].after_string_p = (AFTER_P); \
3608 /* Process overlay before the overlay center. */
3609 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3611 overlay
= XCAR (ov
);
3612 xassert (OVERLAYP (overlay
));
3613 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3614 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3619 /* Skip this overlay if it doesn't start or end at IT's current
3621 if (end
!= charpos
&& start
!= charpos
)
3624 /* Skip this overlay if it doesn't apply to IT->w. */
3625 window
= Foverlay_get (overlay
, Qwindow
);
3626 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3629 /* If the text ``under'' the overlay is invisible, both before-
3630 and after-strings from this overlay are visible; start and
3631 end position are indistinguishable. */
3632 invisible
= Foverlay_get (overlay
, Qinvisible
);
3633 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3635 /* If overlay has a non-empty before-string, record it. */
3636 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3637 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3639 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3641 /* If overlay has a non-empty after-string, record it. */
3642 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3643 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3645 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3648 /* Process overlays after the overlay center. */
3649 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
3651 overlay
= XCAR (ov
);
3652 xassert (OVERLAYP (overlay
));
3653 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3654 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
3656 if (start
> charpos
)
3659 /* Skip this overlay if it doesn't start or end at IT's current
3661 if (end
!= charpos
&& start
!= charpos
)
3664 /* Skip this overlay if it doesn't apply to IT->w. */
3665 window
= Foverlay_get (overlay
, Qwindow
);
3666 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
3669 /* If the text ``under'' the overlay is invisible, it has a zero
3670 dimension, and both before- and after-strings apply. */
3671 invisible
= Foverlay_get (overlay
, Qinvisible
);
3672 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
3674 /* If overlay has a non-empty before-string, record it. */
3675 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
3676 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
3678 RECORD_OVERLAY_STRING (overlay
, str
, 0);
3680 /* If overlay has a non-empty after-string, record it. */
3681 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
3682 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
3684 RECORD_OVERLAY_STRING (overlay
, str
, 1);
3687 #undef RECORD_OVERLAY_STRING
3691 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
3693 /* Record the total number of strings to process. */
3694 it
->n_overlay_strings
= n
;
3696 /* IT->current.overlay_string_index is the number of overlay strings
3697 that have already been consumed by IT. Copy some of the
3698 remaining overlay strings to IT->overlay_strings. */
3700 j
= it
->current
.overlay_string_index
;
3701 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
3702 it
->overlay_strings
[i
++] = entries
[j
++].string
;
3708 /* Get the first chunk of overlay strings at IT's current buffer
3709 position, or at CHARPOS if that is > 0. Value is non-zero if at
3710 least one overlay string was found. */
3713 get_overlay_strings (it
, charpos
)
3717 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
3718 process. This fills IT->overlay_strings with strings, and sets
3719 IT->n_overlay_strings to the total number of strings to process.
3720 IT->pos.overlay_string_index has to be set temporarily to zero
3721 because load_overlay_strings needs this; it must be set to -1
3722 when no overlay strings are found because a zero value would
3723 indicate a position in the first overlay string. */
3724 it
->current
.overlay_string_index
= 0;
3725 load_overlay_strings (it
, charpos
);
3727 /* If we found overlay strings, set up IT to deliver display
3728 elements from the first one. Otherwise set up IT to deliver
3729 from current_buffer. */
3730 if (it
->n_overlay_strings
)
3732 /* Make sure we know settings in current_buffer, so that we can
3733 restore meaningful values when we're done with the overlay
3735 compute_stop_pos (it
);
3736 xassert (it
->face_id
>= 0);
3738 /* Save IT's settings. They are restored after all overlay
3739 strings have been processed. */
3740 xassert (it
->sp
== 0);
3743 /* Set up IT to deliver display elements from the first overlay
3745 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3746 it
->string
= it
->overlay_strings
[0];
3747 it
->stop_charpos
= 0;
3748 xassert (STRINGP (it
->string
));
3749 it
->end_charpos
= SCHARS (it
->string
);
3750 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3751 it
->method
= next_element_from_string
;
3756 it
->current
.overlay_string_index
= -1;
3757 it
->method
= next_element_from_buffer
;
3762 /* Value is non-zero if we found at least one overlay string. */
3763 return STRINGP (it
->string
);
3768 /***********************************************************************
3769 Saving and restoring state
3770 ***********************************************************************/
3772 /* Save current settings of IT on IT->stack. Called, for example,
3773 before setting up IT for an overlay string, to be able to restore
3774 IT's settings to what they were after the overlay string has been
3781 struct iterator_stack_entry
*p
;
3783 xassert (it
->sp
< 2);
3784 p
= it
->stack
+ it
->sp
;
3786 p
->stop_charpos
= it
->stop_charpos
;
3787 xassert (it
->face_id
>= 0);
3788 p
->face_id
= it
->face_id
;
3789 p
->string
= it
->string
;
3790 p
->pos
= it
->current
;
3791 p
->end_charpos
= it
->end_charpos
;
3792 p
->string_nchars
= it
->string_nchars
;
3794 p
->multibyte_p
= it
->multibyte_p
;
3795 p
->space_width
= it
->space_width
;
3796 p
->font_height
= it
->font_height
;
3797 p
->voffset
= it
->voffset
;
3798 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
3799 p
->display_ellipsis_p
= 0;
3804 /* Restore IT's settings from IT->stack. Called, for example, when no
3805 more overlay strings must be processed, and we return to delivering
3806 display elements from a buffer, or when the end of a string from a
3807 `display' property is reached and we return to delivering display
3808 elements from an overlay string, or from a buffer. */
3814 struct iterator_stack_entry
*p
;
3816 xassert (it
->sp
> 0);
3818 p
= it
->stack
+ it
->sp
;
3819 it
->stop_charpos
= p
->stop_charpos
;
3820 it
->face_id
= p
->face_id
;
3821 it
->string
= p
->string
;
3822 it
->current
= p
->pos
;
3823 it
->end_charpos
= p
->end_charpos
;
3824 it
->string_nchars
= p
->string_nchars
;
3826 it
->multibyte_p
= p
->multibyte_p
;
3827 it
->space_width
= p
->space_width
;
3828 it
->font_height
= p
->font_height
;
3829 it
->voffset
= p
->voffset
;
3830 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
3835 /***********************************************************************
3837 ***********************************************************************/
3839 /* Set IT's current position to the previous line start. */
3842 back_to_previous_line_start (it
)
3845 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
3846 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3850 /* Move IT to the next line start.
3852 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
3853 we skipped over part of the text (as opposed to moving the iterator
3854 continuously over the text). Otherwise, don't change the value
3857 Newlines may come from buffer text, overlay strings, or strings
3858 displayed via the `display' property. That's the reason we can't
3859 simply use find_next_newline_no_quit.
3861 Note that this function may not skip over invisible text that is so
3862 because of text properties and immediately follows a newline. If
3863 it would, function reseat_at_next_visible_line_start, when called
3864 from set_iterator_to_next, would effectively make invisible
3865 characters following a newline part of the wrong glyph row, which
3866 leads to wrong cursor motion. */
3869 forward_to_next_line_start (it
, skipped_p
)
3873 int old_selective
, newline_found_p
, n
;
3874 const int MAX_NEWLINE_DISTANCE
= 500;
3876 /* If already on a newline, just consume it to avoid unintended
3877 skipping over invisible text below. */
3878 if (it
->what
== IT_CHARACTER
3880 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
3882 set_iterator_to_next (it
, 0);
3887 /* Don't handle selective display in the following. It's (a)
3888 unnecessary because it's done by the caller, and (b) leads to an
3889 infinite recursion because next_element_from_ellipsis indirectly
3890 calls this function. */
3891 old_selective
= it
->selective
;
3894 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
3895 from buffer text. */
3896 for (n
= newline_found_p
= 0;
3897 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
3898 n
+= STRINGP (it
->string
) ? 0 : 1)
3900 if (!get_next_display_element (it
))
3902 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
3903 set_iterator_to_next (it
, 0);
3906 /* If we didn't find a newline near enough, see if we can use a
3908 if (!newline_found_p
)
3910 int start
= IT_CHARPOS (*it
);
3911 int limit
= find_next_newline_no_quit (start
, 1);
3914 xassert (!STRINGP (it
->string
));
3916 /* If there isn't any `display' property in sight, and no
3917 overlays, we can just use the position of the newline in
3919 if (it
->stop_charpos
>= limit
3920 || ((pos
= Fnext_single_property_change (make_number (start
),
3922 Qnil
, make_number (limit
)),
3924 && next_overlay_change (start
) == ZV
))
3926 IT_CHARPOS (*it
) = limit
;
3927 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
3928 *skipped_p
= newline_found_p
= 1;
3932 while (get_next_display_element (it
)
3933 && !newline_found_p
)
3935 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
3936 set_iterator_to_next (it
, 0);
3941 it
->selective
= old_selective
;
3942 return newline_found_p
;
3946 /* Set IT's current position to the previous visible line start. Skip
3947 invisible text that is so either due to text properties or due to
3948 selective display. Caution: this does not change IT->current_x and
3952 back_to_previous_visible_line_start (it
)
3957 /* Go back one newline if not on BEGV already. */
3958 if (IT_CHARPOS (*it
) > BEGV
)
3959 back_to_previous_line_start (it
);
3961 /* Move over lines that are invisible because of selective display
3962 or text properties. */
3963 while (IT_CHARPOS (*it
) > BEGV
3968 /* If selective > 0, then lines indented more than that values
3970 if (it
->selective
> 0
3971 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3972 (double) it
->selective
)) /* iftc */
3978 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3979 Qinvisible
, it
->window
);
3980 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3984 /* Back one more newline if the current one is invisible. */
3986 back_to_previous_line_start (it
);
3989 xassert (IT_CHARPOS (*it
) >= BEGV
);
3990 xassert (IT_CHARPOS (*it
) == BEGV
3991 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3996 /* Reseat iterator IT at the previous visible line start. Skip
3997 invisible text that is so either due to text properties or due to
3998 selective display. At the end, update IT's overlay information,
3999 face information etc. */
4002 reseat_at_previous_visible_line_start (it
)
4005 back_to_previous_visible_line_start (it
);
4006 reseat (it
, it
->current
.pos
, 1);
4011 /* Reseat iterator IT on the next visible line start in the current
4012 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4013 preceding the line start. Skip over invisible text that is so
4014 because of selective display. Compute faces, overlays etc at the
4015 new position. Note that this function does not skip over text that
4016 is invisible because of text properties. */
4019 reseat_at_next_visible_line_start (it
, on_newline_p
)
4023 int newline_found_p
, skipped_p
= 0;
4025 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4027 /* Skip over lines that are invisible because they are indented
4028 more than the value of IT->selective. */
4029 if (it
->selective
> 0)
4030 while (IT_CHARPOS (*it
) < ZV
4031 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4032 (double) it
->selective
)) /* iftc */
4034 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4035 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4038 /* Position on the newline if that's what's requested. */
4039 if (on_newline_p
&& newline_found_p
)
4041 if (STRINGP (it
->string
))
4043 if (IT_STRING_CHARPOS (*it
) > 0)
4045 --IT_STRING_CHARPOS (*it
);
4046 --IT_STRING_BYTEPOS (*it
);
4049 else if (IT_CHARPOS (*it
) > BEGV
)
4053 reseat (it
, it
->current
.pos
, 0);
4057 reseat (it
, it
->current
.pos
, 0);
4064 /***********************************************************************
4065 Changing an iterator's position
4066 ***********************************************************************/
4068 /* Change IT's current position to POS in current_buffer. If FORCE_P
4069 is non-zero, always check for text properties at the new position.
4070 Otherwise, text properties are only looked up if POS >=
4071 IT->check_charpos of a property. */
4074 reseat (it
, pos
, force_p
)
4076 struct text_pos pos
;
4079 int original_pos
= IT_CHARPOS (*it
);
4081 reseat_1 (it
, pos
, 0);
4083 /* Determine where to check text properties. Avoid doing it
4084 where possible because text property lookup is very expensive. */
4086 || CHARPOS (pos
) > it
->stop_charpos
4087 || CHARPOS (pos
) < original_pos
)
4094 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4095 IT->stop_pos to POS, also. */
4098 reseat_1 (it
, pos
, set_stop_p
)
4100 struct text_pos pos
;
4103 /* Don't call this function when scanning a C string. */
4104 xassert (it
->s
== NULL
);
4106 /* POS must be a reasonable value. */
4107 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4109 it
->current
.pos
= it
->position
= pos
;
4110 XSETBUFFER (it
->object
, current_buffer
);
4111 it
->end_charpos
= ZV
;
4113 it
->current
.dpvec_index
= -1;
4114 it
->current
.overlay_string_index
= -1;
4115 IT_STRING_CHARPOS (*it
) = -1;
4116 IT_STRING_BYTEPOS (*it
) = -1;
4118 it
->method
= next_element_from_buffer
;
4119 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4121 it
->face_before_selective_p
= 0;
4124 it
->stop_charpos
= CHARPOS (pos
);
4128 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4129 If S is non-null, it is a C string to iterate over. Otherwise,
4130 STRING gives a Lisp string to iterate over.
4132 If PRECISION > 0, don't return more then PRECISION number of
4133 characters from the string.
4135 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4136 characters have been returned. FIELD_WIDTH < 0 means an infinite
4139 MULTIBYTE = 0 means disable processing of multibyte characters,
4140 MULTIBYTE > 0 means enable it,
4141 MULTIBYTE < 0 means use IT->multibyte_p.
4143 IT must be initialized via a prior call to init_iterator before
4144 calling this function. */
4147 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4152 int precision
, field_width
, multibyte
;
4154 /* No region in strings. */
4155 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4157 /* No text property checks performed by default, but see below. */
4158 it
->stop_charpos
= -1;
4160 /* Set iterator position and end position. */
4161 bzero (&it
->current
, sizeof it
->current
);
4162 it
->current
.overlay_string_index
= -1;
4163 it
->current
.dpvec_index
= -1;
4164 xassert (charpos
>= 0);
4166 /* If STRING is specified, use its multibyteness, otherwise use the
4167 setting of MULTIBYTE, if specified. */
4169 it
->multibyte_p
= multibyte
> 0;
4173 xassert (STRINGP (string
));
4174 it
->string
= string
;
4176 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4177 it
->method
= next_element_from_string
;
4178 it
->current
.string_pos
= string_pos (charpos
, string
);
4185 /* Note that we use IT->current.pos, not it->current.string_pos,
4186 for displaying C strings. */
4187 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4188 if (it
->multibyte_p
)
4190 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4191 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4195 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4196 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4199 it
->method
= next_element_from_c_string
;
4202 /* PRECISION > 0 means don't return more than PRECISION characters
4204 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4205 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4207 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4208 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4209 FIELD_WIDTH < 0 means infinite field width. This is useful for
4210 padding with `-' at the end of a mode line. */
4211 if (field_width
< 0)
4212 field_width
= INFINITY
;
4213 if (field_width
> it
->end_charpos
- charpos
)
4214 it
->end_charpos
= charpos
+ field_width
;
4216 /* Use the standard display table for displaying strings. */
4217 if (DISP_TABLE_P (Vstandard_display_table
))
4218 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4220 it
->stop_charpos
= charpos
;
4226 /***********************************************************************
4228 ***********************************************************************/
4230 /* Load IT's display element fields with information about the next
4231 display element from the current position of IT. Value is zero if
4232 end of buffer (or C string) is reached. */
4235 get_next_display_element (it
)
4238 /* Non-zero means that we found a display element. Zero means that
4239 we hit the end of what we iterate over. Performance note: the
4240 function pointer `method' used here turns out to be faster than
4241 using a sequence of if-statements. */
4242 int success_p
= (*it
->method
) (it
);
4244 if (it
->what
== IT_CHARACTER
)
4246 /* Map via display table or translate control characters.
4247 IT->c, IT->len etc. have been set to the next character by
4248 the function call above. If we have a display table, and it
4249 contains an entry for IT->c, translate it. Don't do this if
4250 IT->c itself comes from a display table, otherwise we could
4251 end up in an infinite recursion. (An alternative could be to
4252 count the recursion depth of this function and signal an
4253 error when a certain maximum depth is reached.) Is it worth
4255 if (success_p
&& it
->dpvec
== NULL
)
4260 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4263 struct Lisp_Vector
*v
= XVECTOR (dv
);
4265 /* Return the first character from the display table
4266 entry, if not empty. If empty, don't display the
4267 current character. */
4270 it
->dpvec_char_len
= it
->len
;
4271 it
->dpvec
= v
->contents
;
4272 it
->dpend
= v
->contents
+ v
->size
;
4273 it
->current
.dpvec_index
= 0;
4274 it
->method
= next_element_from_display_vector
;
4275 success_p
= get_next_display_element (it
);
4279 set_iterator_to_next (it
, 0);
4280 success_p
= get_next_display_element (it
);
4284 /* Translate control characters into `\003' or `^C' form.
4285 Control characters coming from a display table entry are
4286 currently not translated because we use IT->dpvec to hold
4287 the translation. This could easily be changed but I
4288 don't believe that it is worth doing.
4290 If it->multibyte_p is nonzero, eight-bit characters and
4291 non-printable multibyte characters are also translated to
4294 If it->multibyte_p is zero, eight-bit characters that
4295 don't have corresponding multibyte char code are also
4296 translated to octal form. */
4297 else if ((it
->c
< ' '
4298 && (it
->area
!= TEXT_AREA
4299 || (it
->c
!= '\n' && it
->c
!= '\t')))
4303 || !CHAR_PRINTABLE_P (it
->c
))
4305 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4307 /* IT->c is a control character which must be displayed
4308 either as '\003' or as `^C' where the '\\' and '^'
4309 can be defined in the display table. Fill
4310 IT->ctl_chars with glyphs for what we have to
4311 display. Then, set IT->dpvec to these glyphs. */
4314 if (it
->c
< 128 && it
->ctl_arrow_p
)
4316 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4318 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4319 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4320 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4322 g
= FAST_MAKE_GLYPH ('^', 0);
4323 XSETINT (it
->ctl_chars
[0], g
);
4325 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4326 XSETINT (it
->ctl_chars
[1], g
);
4328 /* Set up IT->dpvec and return first character from it. */
4329 it
->dpvec_char_len
= it
->len
;
4330 it
->dpvec
= it
->ctl_chars
;
4331 it
->dpend
= it
->dpvec
+ 2;
4332 it
->current
.dpvec_index
= 0;
4333 it
->method
= next_element_from_display_vector
;
4334 get_next_display_element (it
);
4338 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4343 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4345 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4346 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4347 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4349 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4351 if (SINGLE_BYTE_CHAR_P (it
->c
))
4352 str
[0] = it
->c
, len
= 1;
4355 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4358 /* It's an invalid character, which
4359 shouldn't happen actually, but due to
4360 bugs it may happen. Let's print the char
4361 as is, there's not much meaningful we can
4364 str
[1] = it
->c
>> 8;
4365 str
[2] = it
->c
>> 16;
4366 str
[3] = it
->c
>> 24;
4371 for (i
= 0; i
< len
; i
++)
4373 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4374 /* Insert three more glyphs into IT->ctl_chars for
4375 the octal display of the character. */
4376 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4377 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4378 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4379 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4380 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4381 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4384 /* Set up IT->dpvec and return the first character
4386 it
->dpvec_char_len
= it
->len
;
4387 it
->dpvec
= it
->ctl_chars
;
4388 it
->dpend
= it
->dpvec
+ len
* 4;
4389 it
->current
.dpvec_index
= 0;
4390 it
->method
= next_element_from_display_vector
;
4391 get_next_display_element (it
);
4396 /* Adjust face id for a multibyte character. There are no
4397 multibyte character in unibyte text. */
4400 && FRAME_WINDOW_P (it
->f
))
4402 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4403 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4407 /* Is this character the last one of a run of characters with
4408 box? If yes, set IT->end_of_box_run_p to 1. */
4415 it
->end_of_box_run_p
4416 = ((face_id
= face_after_it_pos (it
),
4417 face_id
!= it
->face_id
)
4418 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4419 face
->box
== FACE_NO_BOX
));
4422 /* Value is 0 if end of buffer or string reached. */
4427 /* Move IT to the next display element.
4429 RESEAT_P non-zero means if called on a newline in buffer text,
4430 skip to the next visible line start.
4432 Functions get_next_display_element and set_iterator_to_next are
4433 separate because I find this arrangement easier to handle than a
4434 get_next_display_element function that also increments IT's
4435 position. The way it is we can first look at an iterator's current
4436 display element, decide whether it fits on a line, and if it does,
4437 increment the iterator position. The other way around we probably
4438 would either need a flag indicating whether the iterator has to be
4439 incremented the next time, or we would have to implement a
4440 decrement position function which would not be easy to write. */
4443 set_iterator_to_next (it
, reseat_p
)
4447 /* Reset flags indicating start and end of a sequence of characters
4448 with box. Reset them at the start of this function because
4449 moving the iterator to a new position might set them. */
4450 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4452 if (it
->method
== next_element_from_buffer
)
4454 /* The current display element of IT is a character from
4455 current_buffer. Advance in the buffer, and maybe skip over
4456 invisible lines that are so because of selective display. */
4457 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4458 reseat_at_next_visible_line_start (it
, 0);
4461 xassert (it
->len
!= 0);
4462 IT_BYTEPOS (*it
) += it
->len
;
4463 IT_CHARPOS (*it
) += 1;
4464 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4467 else if (it
->method
== next_element_from_composition
)
4469 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4470 if (STRINGP (it
->string
))
4472 IT_STRING_BYTEPOS (*it
) += it
->len
;
4473 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4474 it
->method
= next_element_from_string
;
4475 goto consider_string_end
;
4479 IT_BYTEPOS (*it
) += it
->len
;
4480 IT_CHARPOS (*it
) += it
->cmp_len
;
4481 it
->method
= next_element_from_buffer
;
4484 else if (it
->method
== next_element_from_c_string
)
4486 /* Current display element of IT is from a C string. */
4487 IT_BYTEPOS (*it
) += it
->len
;
4488 IT_CHARPOS (*it
) += 1;
4490 else if (it
->method
== next_element_from_display_vector
)
4492 /* Current display element of IT is from a display table entry.
4493 Advance in the display table definition. Reset it to null if
4494 end reached, and continue with characters from buffers/
4496 ++it
->current
.dpvec_index
;
4498 /* Restore face of the iterator to what they were before the
4499 display vector entry (these entries may contain faces). */
4500 it
->face_id
= it
->saved_face_id
;
4502 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4505 it
->method
= next_element_from_c_string
;
4506 else if (STRINGP (it
->string
))
4507 it
->method
= next_element_from_string
;
4509 it
->method
= next_element_from_buffer
;
4512 it
->current
.dpvec_index
= -1;
4514 /* Skip over characters which were displayed via IT->dpvec. */
4515 if (it
->dpvec_char_len
< 0)
4516 reseat_at_next_visible_line_start (it
, 1);
4517 else if (it
->dpvec_char_len
> 0)
4519 it
->len
= it
->dpvec_char_len
;
4520 set_iterator_to_next (it
, reseat_p
);
4524 else if (it
->method
== next_element_from_string
)
4526 /* Current display element is a character from a Lisp string. */
4527 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4528 IT_STRING_BYTEPOS (*it
) += it
->len
;
4529 IT_STRING_CHARPOS (*it
) += 1;
4531 consider_string_end
:
4533 if (it
->current
.overlay_string_index
>= 0)
4535 /* IT->string is an overlay string. Advance to the
4536 next, if there is one. */
4537 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4538 next_overlay_string (it
);
4542 /* IT->string is not an overlay string. If we reached
4543 its end, and there is something on IT->stack, proceed
4544 with what is on the stack. This can be either another
4545 string, this time an overlay string, or a buffer. */
4546 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4550 if (!STRINGP (it
->string
))
4551 it
->method
= next_element_from_buffer
;
4553 goto consider_string_end
;
4557 else if (it
->method
== next_element_from_image
4558 || it
->method
== next_element_from_stretch
)
4560 /* The position etc with which we have to proceed are on
4561 the stack. The position may be at the end of a string,
4562 if the `display' property takes up the whole string. */
4565 if (STRINGP (it
->string
))
4567 it
->method
= next_element_from_string
;
4568 goto consider_string_end
;
4571 it
->method
= next_element_from_buffer
;
4574 /* There are no other methods defined, so this should be a bug. */
4577 xassert (it
->method
!= next_element_from_string
4578 || (STRINGP (it
->string
)
4579 && IT_STRING_CHARPOS (*it
) >= 0));
4583 /* Load IT's display element fields with information about the next
4584 display element which comes from a display table entry or from the
4585 result of translating a control character to one of the forms `^C'
4586 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4589 next_element_from_display_vector (it
)
4593 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4595 /* Remember the current face id in case glyphs specify faces.
4596 IT's face is restored in set_iterator_to_next. */
4597 it
->saved_face_id
= it
->face_id
;
4599 if (INTEGERP (*it
->dpvec
)
4600 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4605 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4606 it
->c
= FAST_GLYPH_CHAR (g
);
4607 it
->len
= CHAR_BYTES (it
->c
);
4609 /* The entry may contain a face id to use. Such a face id is
4610 the id of a Lisp face, not a realized face. A face id of
4611 zero means no face is specified. */
4612 lface_id
= FAST_GLYPH_FACE (g
);
4615 /* The function returns -1 if lface_id is invalid. */
4616 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4618 it
->face_id
= face_id
;
4622 /* Display table entry is invalid. Return a space. */
4623 it
->c
= ' ', it
->len
= 1;
4625 /* Don't change position and object of the iterator here. They are
4626 still the values of the character that had this display table
4627 entry or was translated, and that's what we want. */
4628 it
->what
= IT_CHARACTER
;
4633 /* Load IT with the next display element from Lisp string IT->string.
4634 IT->current.string_pos is the current position within the string.
4635 If IT->current.overlay_string_index >= 0, the Lisp string is an
4639 next_element_from_string (it
)
4642 struct text_pos position
;
4644 xassert (STRINGP (it
->string
));
4645 xassert (IT_STRING_CHARPOS (*it
) >= 0);
4646 position
= it
->current
.string_pos
;
4648 /* Time to check for invisible text? */
4649 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
4650 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
4654 /* Since a handler may have changed IT->method, we must
4656 return get_next_display_element (it
);
4659 if (it
->current
.overlay_string_index
>= 0)
4661 /* Get the next character from an overlay string. In overlay
4662 strings, There is no field width or padding with spaces to
4664 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4669 else if (STRING_MULTIBYTE (it
->string
))
4671 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4672 const unsigned char *s
= (SDATA (it
->string
)
4673 + IT_STRING_BYTEPOS (*it
));
4674 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
4678 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4684 /* Get the next character from a Lisp string that is not an
4685 overlay string. Such strings come from the mode line, for
4686 example. We may have to pad with spaces, or truncate the
4687 string. See also next_element_from_c_string. */
4688 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
4693 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
4695 /* Pad with spaces. */
4696 it
->c
= ' ', it
->len
= 1;
4697 CHARPOS (position
) = BYTEPOS (position
) = -1;
4699 else if (STRING_MULTIBYTE (it
->string
))
4701 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
4702 const unsigned char *s
= (SDATA (it
->string
)
4703 + IT_STRING_BYTEPOS (*it
));
4704 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
4708 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
4713 /* Record what we have and where it came from. Note that we store a
4714 buffer position in IT->position although it could arguably be a
4716 it
->what
= IT_CHARACTER
;
4717 it
->object
= it
->string
;
4718 it
->position
= position
;
4723 /* Load IT with next display element from C string IT->s.
4724 IT->string_nchars is the maximum number of characters to return
4725 from the string. IT->end_charpos may be greater than
4726 IT->string_nchars when this function is called, in which case we
4727 may have to return padding spaces. Value is zero if end of string
4728 reached, including padding spaces. */
4731 next_element_from_c_string (it
)
4737 it
->what
= IT_CHARACTER
;
4738 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
4741 /* IT's position can be greater IT->string_nchars in case a field
4742 width or precision has been specified when the iterator was
4744 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4746 /* End of the game. */
4750 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
4752 /* Pad with spaces. */
4753 it
->c
= ' ', it
->len
= 1;
4754 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
4756 else if (it
->multibyte_p
)
4758 /* Implementation note: The calls to strlen apparently aren't a
4759 performance problem because there is no noticeable performance
4760 difference between Emacs running in unibyte or multibyte mode. */
4761 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
4762 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
4766 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
4772 /* Set up IT to return characters from an ellipsis, if appropriate.
4773 The definition of the ellipsis glyphs may come from a display table
4774 entry. This function Fills IT with the first glyph from the
4775 ellipsis if an ellipsis is to be displayed. */
4778 next_element_from_ellipsis (it
)
4781 if (it
->selective_display_ellipsis_p
)
4783 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4785 /* Use the display table definition for `...'. Invalid glyphs
4786 will be handled by the method returning elements from dpvec. */
4787 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4788 it
->dpvec_char_len
= it
->len
;
4789 it
->dpvec
= v
->contents
;
4790 it
->dpend
= v
->contents
+ v
->size
;
4791 it
->current
.dpvec_index
= 0;
4792 it
->method
= next_element_from_display_vector
;
4796 /* Use default `...' which is stored in default_invis_vector. */
4797 it
->dpvec_char_len
= it
->len
;
4798 it
->dpvec
= default_invis_vector
;
4799 it
->dpend
= default_invis_vector
+ 3;
4800 it
->current
.dpvec_index
= 0;
4801 it
->method
= next_element_from_display_vector
;
4806 /* The face at the current position may be different from the
4807 face we find after the invisible text. Remember what it
4808 was in IT->saved_face_id, and signal that it's there by
4809 setting face_before_selective_p. */
4810 it
->saved_face_id
= it
->face_id
;
4811 it
->method
= next_element_from_buffer
;
4812 reseat_at_next_visible_line_start (it
, 1);
4813 it
->face_before_selective_p
= 1;
4816 return get_next_display_element (it
);
4820 /* Deliver an image display element. The iterator IT is already
4821 filled with image information (done in handle_display_prop). Value
4826 next_element_from_image (it
)
4829 it
->what
= IT_IMAGE
;
4834 /* Fill iterator IT with next display element from a stretch glyph
4835 property. IT->object is the value of the text property. Value is
4839 next_element_from_stretch (it
)
4842 it
->what
= IT_STRETCH
;
4847 /* Load IT with the next display element from current_buffer. Value
4848 is zero if end of buffer reached. IT->stop_charpos is the next
4849 position at which to stop and check for text properties or buffer
4853 next_element_from_buffer (it
)
4858 /* Check this assumption, otherwise, we would never enter the
4859 if-statement, below. */
4860 xassert (IT_CHARPOS (*it
) >= BEGV
4861 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
4863 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
4865 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4867 int overlay_strings_follow_p
;
4869 /* End of the game, except when overlay strings follow that
4870 haven't been returned yet. */
4871 if (it
->overlay_strings_at_end_processed_p
)
4872 overlay_strings_follow_p
= 0;
4875 it
->overlay_strings_at_end_processed_p
= 1;
4876 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
4879 if (overlay_strings_follow_p
)
4880 success_p
= get_next_display_element (it
);
4884 it
->position
= it
->current
.pos
;
4891 return get_next_display_element (it
);
4896 /* No face changes, overlays etc. in sight, so just return a
4897 character from current_buffer. */
4900 /* Maybe run the redisplay end trigger hook. Performance note:
4901 This doesn't seem to cost measurable time. */
4902 if (it
->redisplay_end_trigger_charpos
4904 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
4905 run_redisplay_end_trigger_hook (it
);
4907 /* Get the next character, maybe multibyte. */
4908 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
4909 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
4911 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
4912 - IT_BYTEPOS (*it
));
4913 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
4916 it
->c
= *p
, it
->len
= 1;
4918 /* Record what we have and where it came from. */
4919 it
->what
= IT_CHARACTER
;;
4920 it
->object
= it
->w
->buffer
;
4921 it
->position
= it
->current
.pos
;
4923 /* Normally we return the character found above, except when we
4924 really want to return an ellipsis for selective display. */
4929 /* A value of selective > 0 means hide lines indented more
4930 than that number of columns. */
4931 if (it
->selective
> 0
4932 && IT_CHARPOS (*it
) + 1 < ZV
4933 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
4934 IT_BYTEPOS (*it
) + 1,
4935 (double) it
->selective
)) /* iftc */
4937 success_p
= next_element_from_ellipsis (it
);
4938 it
->dpvec_char_len
= -1;
4941 else if (it
->c
== '\r' && it
->selective
== -1)
4943 /* A value of selective == -1 means that everything from the
4944 CR to the end of the line is invisible, with maybe an
4945 ellipsis displayed for it. */
4946 success_p
= next_element_from_ellipsis (it
);
4947 it
->dpvec_char_len
= -1;
4952 /* Value is zero if end of buffer reached. */
4953 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
4958 /* Run the redisplay end trigger hook for IT. */
4961 run_redisplay_end_trigger_hook (it
)
4964 Lisp_Object args
[3];
4966 /* IT->glyph_row should be non-null, i.e. we should be actually
4967 displaying something, or otherwise we should not run the hook. */
4968 xassert (it
->glyph_row
);
4970 /* Set up hook arguments. */
4971 args
[0] = Qredisplay_end_trigger_functions
;
4972 args
[1] = it
->window
;
4973 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
4974 it
->redisplay_end_trigger_charpos
= 0;
4976 /* Since we are *trying* to run these functions, don't try to run
4977 them again, even if they get an error. */
4978 it
->w
->redisplay_end_trigger
= Qnil
;
4979 Frun_hook_with_args (3, args
);
4981 /* Notice if it changed the face of the character we are on. */
4982 handle_face_prop (it
);
4986 /* Deliver a composition display element. The iterator IT is already
4987 filled with composition information (done in
4988 handle_composition_prop). Value is always 1. */
4991 next_element_from_composition (it
)
4994 it
->what
= IT_COMPOSITION
;
4995 it
->position
= (STRINGP (it
->string
)
4996 ? it
->current
.string_pos
5003 /***********************************************************************
5004 Moving an iterator without producing glyphs
5005 ***********************************************************************/
5007 /* Move iterator IT to a specified buffer or X position within one
5008 line on the display without producing glyphs.
5010 OP should be a bit mask including some or all of these bits:
5011 MOVE_TO_X: Stop on reaching x-position TO_X.
5012 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5013 Regardless of OP's value, stop in reaching the end of the display line.
5015 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5016 This means, in particular, that TO_X includes window's horizontal
5019 The return value has several possible values that
5020 say what condition caused the scan to stop:
5022 MOVE_POS_MATCH_OR_ZV
5023 - when TO_POS or ZV was reached.
5026 -when TO_X was reached before TO_POS or ZV were reached.
5029 - when we reached the end of the display area and the line must
5033 - when we reached the end of the display area and the line is
5037 - when we stopped at a line end, i.e. a newline or a CR and selective
5040 static enum move_it_result
5041 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5043 int to_charpos
, to_x
, op
;
5045 enum move_it_result result
= MOVE_UNDEFINED
;
5046 struct glyph_row
*saved_glyph_row
;
5048 /* Don't produce glyphs in produce_glyphs. */
5049 saved_glyph_row
= it
->glyph_row
;
5050 it
->glyph_row
= NULL
;
5054 int x
, i
, ascent
= 0, descent
= 0;
5056 /* Stop when ZV or TO_CHARPOS reached. */
5057 if (!get_next_display_element (it
)
5058 || ((op
& MOVE_TO_POS
) != 0
5059 && BUFFERP (it
->object
)
5060 && IT_CHARPOS (*it
) >= to_charpos
))
5062 result
= MOVE_POS_MATCH_OR_ZV
;
5066 /* The call to produce_glyphs will get the metrics of the
5067 display element IT is loaded with. We record in x the
5068 x-position before this display element in case it does not
5072 /* Remember the line height so far in case the next element doesn't
5074 if (!it
->truncate_lines_p
)
5076 ascent
= it
->max_ascent
;
5077 descent
= it
->max_descent
;
5080 PRODUCE_GLYPHS (it
);
5082 if (it
->area
!= TEXT_AREA
)
5084 set_iterator_to_next (it
, 1);
5088 /* The number of glyphs we get back in IT->nglyphs will normally
5089 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5090 character on a terminal frame, or (iii) a line end. For the
5091 second case, IT->nglyphs - 1 padding glyphs will be present
5092 (on X frames, there is only one glyph produced for a
5093 composite character.
5095 The behavior implemented below means, for continuation lines,
5096 that as many spaces of a TAB as fit on the current line are
5097 displayed there. For terminal frames, as many glyphs of a
5098 multi-glyph character are displayed in the current line, too.
5099 This is what the old redisplay code did, and we keep it that
5100 way. Under X, the whole shape of a complex character must
5101 fit on the line or it will be completely displayed in the
5104 Note that both for tabs and padding glyphs, all glyphs have
5108 /* More than one glyph or glyph doesn't fit on line. All
5109 glyphs have the same width. */
5110 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5113 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5115 new_x
= x
+ single_glyph_width
;
5117 /* We want to leave anything reaching TO_X to the caller. */
5118 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5121 result
= MOVE_X_REACHED
;
5124 else if (/* Lines are continued. */
5125 !it
->truncate_lines_p
5126 && (/* And glyph doesn't fit on the line. */
5127 new_x
> it
->last_visible_x
5128 /* Or it fits exactly and we're on a window
5130 || (new_x
== it
->last_visible_x
5131 && FRAME_WINDOW_P (it
->f
))))
5133 if (/* IT->hpos == 0 means the very first glyph
5134 doesn't fit on the line, e.g. a wide image. */
5136 || (new_x
== it
->last_visible_x
5137 && FRAME_WINDOW_P (it
->f
)))
5140 it
->current_x
= new_x
;
5141 if (i
== it
->nglyphs
- 1)
5142 set_iterator_to_next (it
, 1);
5147 it
->max_ascent
= ascent
;
5148 it
->max_descent
= descent
;
5151 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5153 result
= MOVE_LINE_CONTINUED
;
5156 else if (new_x
> it
->first_visible_x
)
5158 /* Glyph is visible. Increment number of glyphs that
5159 would be displayed. */
5164 /* Glyph is completely off the left margin of the display
5165 area. Nothing to do. */
5169 if (result
!= MOVE_UNDEFINED
)
5172 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5174 /* Stop when TO_X specified and reached. This check is
5175 necessary here because of lines consisting of a line end,
5176 only. The line end will not produce any glyphs and we
5177 would never get MOVE_X_REACHED. */
5178 xassert (it
->nglyphs
== 0);
5179 result
= MOVE_X_REACHED
;
5183 /* Is this a line end? If yes, we're done. */
5184 if (ITERATOR_AT_END_OF_LINE_P (it
))
5186 result
= MOVE_NEWLINE_OR_CR
;
5190 /* The current display element has been consumed. Advance
5192 set_iterator_to_next (it
, 1);
5194 /* Stop if lines are truncated and IT's current x-position is
5195 past the right edge of the window now. */
5196 if (it
->truncate_lines_p
5197 && it
->current_x
>= it
->last_visible_x
)
5199 result
= MOVE_LINE_TRUNCATED
;
5204 /* Restore the iterator settings altered at the beginning of this
5206 it
->glyph_row
= saved_glyph_row
;
5211 /* Move IT forward until it satisfies one or more of the criteria in
5212 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5214 OP is a bit-mask that specifies where to stop, and in particular,
5215 which of those four position arguments makes a difference. See the
5216 description of enum move_operation_enum.
5218 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5219 screen line, this function will set IT to the next position >
5223 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5225 int to_charpos
, to_x
, to_y
, to_vpos
;
5228 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5234 if (op
& MOVE_TO_VPOS
)
5236 /* If no TO_CHARPOS and no TO_X specified, stop at the
5237 start of the line TO_VPOS. */
5238 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5240 if (it
->vpos
== to_vpos
)
5246 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5250 /* TO_VPOS >= 0 means stop at TO_X in the line at
5251 TO_VPOS, or at TO_POS, whichever comes first. */
5252 if (it
->vpos
== to_vpos
)
5258 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5260 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5265 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5267 /* We have reached TO_X but not in the line we want. */
5268 skip
= move_it_in_display_line_to (it
, to_charpos
,
5270 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5278 else if (op
& MOVE_TO_Y
)
5280 struct it it_backup
;
5282 /* TO_Y specified means stop at TO_X in the line containing
5283 TO_Y---or at TO_CHARPOS if this is reached first. The
5284 problem is that we can't really tell whether the line
5285 contains TO_Y before we have completely scanned it, and
5286 this may skip past TO_X. What we do is to first scan to
5289 If TO_X is not specified, use a TO_X of zero. The reason
5290 is to make the outcome of this function more predictable.
5291 If we didn't use TO_X == 0, we would stop at the end of
5292 the line which is probably not what a caller would expect
5294 skip
= move_it_in_display_line_to (it
, to_charpos
,
5298 | (op
& MOVE_TO_POS
)));
5300 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5301 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5307 /* If TO_X was reached, we would like to know whether TO_Y
5308 is in the line. This can only be said if we know the
5309 total line height which requires us to scan the rest of
5311 if (skip
== MOVE_X_REACHED
)
5314 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5315 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5317 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5320 /* Now, decide whether TO_Y is in this line. */
5321 line_height
= it
->max_ascent
+ it
->max_descent
;
5322 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5324 if (to_y
>= it
->current_y
5325 && to_y
< it
->current_y
+ line_height
)
5327 if (skip
== MOVE_X_REACHED
)
5328 /* If TO_Y is in this line and TO_X was reached above,
5329 we scanned too far. We have to restore IT's settings
5330 to the ones before skipping. */
5334 else if (skip
== MOVE_X_REACHED
)
5337 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5345 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5349 case MOVE_POS_MATCH_OR_ZV
:
5353 case MOVE_NEWLINE_OR_CR
:
5354 set_iterator_to_next (it
, 1);
5355 it
->continuation_lines_width
= 0;
5358 case MOVE_LINE_TRUNCATED
:
5359 it
->continuation_lines_width
= 0;
5360 reseat_at_next_visible_line_start (it
, 0);
5361 if ((op
& MOVE_TO_POS
) != 0
5362 && IT_CHARPOS (*it
) > to_charpos
)
5369 case MOVE_LINE_CONTINUED
:
5370 it
->continuation_lines_width
+= it
->current_x
;
5377 /* Reset/increment for the next run. */
5378 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5379 it
->current_x
= it
->hpos
= 0;
5380 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5382 last_height
= it
->max_ascent
+ it
->max_descent
;
5383 last_max_ascent
= it
->max_ascent
;
5384 it
->max_ascent
= it
->max_descent
= 0;
5389 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5393 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5395 If DY > 0, move IT backward at least that many pixels. DY = 0
5396 means move IT backward to the preceding line start or BEGV. This
5397 function may move over more than DY pixels if IT->current_y - DY
5398 ends up in the middle of a line; in this case IT->current_y will be
5399 set to the top of the line moved to. */
5402 move_it_vertically_backward (it
, dy
)
5408 int start_pos
= IT_CHARPOS (*it
);
5412 /* Estimate how many newlines we must move back. */
5413 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5415 /* Set the iterator's position that many lines back. */
5416 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5417 back_to_previous_visible_line_start (it
);
5419 /* Reseat the iterator here. When moving backward, we don't want
5420 reseat to skip forward over invisible text, set up the iterator
5421 to deliver from overlay strings at the new position etc. So,
5422 use reseat_1 here. */
5423 reseat_1 (it
, it
->current
.pos
, 1);
5425 /* We are now surely at a line start. */
5426 it
->current_x
= it
->hpos
= 0;
5427 it
->continuation_lines_width
= 0;
5429 /* Move forward and see what y-distance we moved. First move to the
5430 start of the next line so that we get its height. We need this
5431 height to be able to tell whether we reached the specified
5434 it2
.max_ascent
= it2
.max_descent
= 0;
5435 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5436 MOVE_TO_POS
| MOVE_TO_VPOS
);
5437 xassert (IT_CHARPOS (*it
) >= BEGV
);
5440 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5441 xassert (IT_CHARPOS (*it
) >= BEGV
);
5442 h
= it2
.current_y
- it
->current_y
;
5443 nlines
= it2
.vpos
- it
->vpos
;
5445 /* Correct IT's y and vpos position. */
5451 /* DY == 0 means move to the start of the screen line. The
5452 value of nlines is > 0 if continuation lines were involved. */
5454 move_it_by_lines (it
, nlines
, 1);
5455 xassert (IT_CHARPOS (*it
) <= start_pos
);
5459 /* The y-position we try to reach. Note that h has been
5460 subtracted in front of the if-statement. */
5461 int target_y
= it
->current_y
+ h
- dy
;
5462 int y0
= it3
.current_y
;
5463 int y1
= line_bottom_y (&it3
);
5464 int line_height
= y1
- y0
;
5466 /* If we did not reach target_y, try to move further backward if
5467 we can. If we moved too far backward, try to move forward. */
5468 if (target_y
< it
->current_y
5469 /* This is heuristic. In a window that's 3 lines high, with
5470 a line height of 13 pixels each, recentering with point
5471 on the bottom line will try to move -39/2 = 19 pixels
5472 backward. Try to avoid moving into the first line. */
5473 && it
->current_y
- target_y
> line_height
/ 3 * 2
5474 && IT_CHARPOS (*it
) > BEGV
)
5476 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5477 target_y
- it
->current_y
));
5478 move_it_vertically (it
, target_y
- it
->current_y
);
5479 xassert (IT_CHARPOS (*it
) >= BEGV
);
5481 else if (target_y
>= it
->current_y
+ line_height
5482 && IT_CHARPOS (*it
) < ZV
)
5484 /* Should move forward by at least one line, maybe more.
5486 Note: Calling move_it_by_lines can be expensive on
5487 terminal frames, where compute_motion is used (via
5488 vmotion) to do the job, when there are very long lines
5489 and truncate-lines is nil. That's the reason for
5490 treating terminal frames specially here. */
5492 if (!FRAME_WINDOW_P (it
->f
))
5493 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5498 move_it_by_lines (it
, 1, 1);
5500 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5503 xassert (IT_CHARPOS (*it
) >= BEGV
);
5509 /* Move IT by a specified amount of pixel lines DY. DY negative means
5510 move backwards. DY = 0 means move to start of screen line. At the
5511 end, IT will be on the start of a screen line. */
5514 move_it_vertically (it
, dy
)
5519 move_it_vertically_backward (it
, -dy
);
5522 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5523 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5524 MOVE_TO_POS
| MOVE_TO_Y
);
5525 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5527 /* If buffer ends in ZV without a newline, move to the start of
5528 the line to satisfy the post-condition. */
5529 if (IT_CHARPOS (*it
) == ZV
5530 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5531 move_it_by_lines (it
, 0, 0);
5536 /* Move iterator IT past the end of the text line it is in. */
5539 move_it_past_eol (it
)
5542 enum move_it_result rc
;
5544 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5545 if (rc
== MOVE_NEWLINE_OR_CR
)
5546 set_iterator_to_next (it
, 0);
5550 #if 0 /* Currently not used. */
5552 /* Return non-zero if some text between buffer positions START_CHARPOS
5553 and END_CHARPOS is invisible. IT->window is the window for text
5557 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5559 int start_charpos
, end_charpos
;
5561 Lisp_Object prop
, limit
;
5562 int invisible_found_p
;
5564 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5566 /* Is text at START invisible? */
5567 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5569 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5570 invisible_found_p
= 1;
5573 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5575 make_number (end_charpos
));
5576 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5579 return invisible_found_p
;
5585 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5586 negative means move up. DVPOS == 0 means move to the start of the
5587 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5588 NEED_Y_P is zero, IT->current_y will be left unchanged.
5590 Further optimization ideas: If we would know that IT->f doesn't use
5591 a face with proportional font, we could be faster for
5592 truncate-lines nil. */
5595 move_it_by_lines (it
, dvpos
, need_y_p
)
5597 int dvpos
, need_y_p
;
5599 struct position pos
;
5601 if (!FRAME_WINDOW_P (it
->f
))
5603 struct text_pos textpos
;
5605 /* We can use vmotion on frames without proportional fonts. */
5606 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5607 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5608 reseat (it
, textpos
, 1);
5609 it
->vpos
+= pos
.vpos
;
5610 it
->current_y
+= pos
.vpos
;
5612 else if (dvpos
== 0)
5614 /* DVPOS == 0 means move to the start of the screen line. */
5615 move_it_vertically_backward (it
, 0);
5616 xassert (it
->current_x
== 0 && it
->hpos
== 0);
5619 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
5623 int start_charpos
, i
;
5625 /* Start at the beginning of the screen line containing IT's
5627 move_it_vertically_backward (it
, 0);
5629 /* Go back -DVPOS visible lines and reseat the iterator there. */
5630 start_charpos
= IT_CHARPOS (*it
);
5631 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
5632 back_to_previous_visible_line_start (it
);
5633 reseat (it
, it
->current
.pos
, 1);
5634 it
->current_x
= it
->hpos
= 0;
5636 /* Above call may have moved too far if continuation lines
5637 are involved. Scan forward and see if it did. */
5639 it2
.vpos
= it2
.current_y
= 0;
5640 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
5641 it
->vpos
-= it2
.vpos
;
5642 it
->current_y
-= it2
.current_y
;
5643 it
->current_x
= it
->hpos
= 0;
5645 /* If we moved too far, move IT some lines forward. */
5646 if (it2
.vpos
> -dvpos
)
5648 int delta
= it2
.vpos
+ dvpos
;
5649 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
5654 /* Return 1 if IT points into the middle of a display vector. */
5657 in_display_vector_p (it
)
5660 return (it
->method
== next_element_from_display_vector
5661 && it
->current
.dpvec_index
> 0
5662 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
5666 /***********************************************************************
5668 ***********************************************************************/
5671 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
5675 add_to_log (format
, arg1
, arg2
)
5677 Lisp_Object arg1
, arg2
;
5679 Lisp_Object args
[3];
5680 Lisp_Object msg
, fmt
;
5683 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5685 /* Do nothing if called asynchronously. Inserting text into
5686 a buffer may call after-change-functions and alike and
5687 that would means running Lisp asynchronously. */
5688 if (handling_signal
)
5692 GCPRO4 (fmt
, msg
, arg1
, arg2
);
5694 args
[0] = fmt
= build_string (format
);
5697 msg
= Fformat (3, args
);
5699 len
= SBYTES (msg
) + 1;
5700 buffer
= (char *) alloca (len
);
5701 bcopy (SDATA (msg
), buffer
, len
);
5703 message_dolog (buffer
, len
- 1, 1, 0);
5708 /* Output a newline in the *Messages* buffer if "needs" one. */
5711 message_log_maybe_newline ()
5713 if (message_log_need_newline
)
5714 message_dolog ("", 0, 1, 0);
5718 /* Add a string M of length NBYTES to the message log, optionally
5719 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
5720 nonzero, means interpret the contents of M as multibyte. This
5721 function calls low-level routines in order to bypass text property
5722 hooks, etc. which might not be safe to run. */
5725 message_dolog (m
, nbytes
, nlflag
, multibyte
)
5727 int nbytes
, nlflag
, multibyte
;
5729 if (!NILP (Vmemory_full
))
5732 if (!NILP (Vmessage_log_max
))
5734 struct buffer
*oldbuf
;
5735 Lisp_Object oldpoint
, oldbegv
, oldzv
;
5736 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5737 int point_at_end
= 0;
5739 Lisp_Object old_deactivate_mark
, tem
;
5740 struct gcpro gcpro1
;
5742 old_deactivate_mark
= Vdeactivate_mark
;
5743 oldbuf
= current_buffer
;
5744 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
5745 current_buffer
->undo_list
= Qt
;
5747 oldpoint
= message_dolog_marker1
;
5748 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
5749 oldbegv
= message_dolog_marker2
;
5750 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
5751 oldzv
= message_dolog_marker3
;
5752 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
5753 GCPRO1 (old_deactivate_mark
);
5761 BEGV_BYTE
= BEG_BYTE
;
5764 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5766 /* Insert the string--maybe converting multibyte to single byte
5767 or vice versa, so that all the text fits the buffer. */
5769 && NILP (current_buffer
->enable_multibyte_characters
))
5771 int i
, c
, char_bytes
;
5772 unsigned char work
[1];
5774 /* Convert a multibyte string to single-byte
5775 for the *Message* buffer. */
5776 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
5778 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
5779 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5781 : multibyte_char_to_unibyte (c
, Qnil
));
5782 insert_1_both (work
, 1, 1, 1, 0, 0);
5785 else if (! multibyte
5786 && ! NILP (current_buffer
->enable_multibyte_characters
))
5788 int i
, c
, char_bytes
;
5789 unsigned char *msg
= (unsigned char *) m
;
5790 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5791 /* Convert a single-byte string to multibyte
5792 for the *Message* buffer. */
5793 for (i
= 0; i
< nbytes
; i
++)
5795 c
= unibyte_char_to_multibyte (msg
[i
]);
5796 char_bytes
= CHAR_STRING (c
, str
);
5797 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
5801 insert_1 (m
, nbytes
, 1, 0, 0);
5805 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
5806 insert_1 ("\n", 1, 1, 0, 0);
5808 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5810 this_bol_byte
= PT_BYTE
;
5812 /* See if this line duplicates the previous one.
5813 If so, combine duplicates. */
5816 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
5818 prev_bol_byte
= PT_BYTE
;
5820 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
5821 this_bol
, this_bol_byte
);
5824 del_range_both (prev_bol
, prev_bol_byte
,
5825 this_bol
, this_bol_byte
, 0);
5831 /* If you change this format, don't forget to also
5832 change message_log_check_duplicate. */
5833 sprintf (dupstr
, " [%d times]", dup
);
5834 duplen
= strlen (dupstr
);
5835 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
5836 insert_1 (dupstr
, duplen
, 1, 0, 1);
5841 /* If we have more than the desired maximum number of lines
5842 in the *Messages* buffer now, delete the oldest ones.
5843 This is safe because we don't have undo in this buffer. */
5845 if (NATNUMP (Vmessage_log_max
))
5847 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
5848 -XFASTINT (Vmessage_log_max
) - 1, 0);
5849 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
5852 BEGV
= XMARKER (oldbegv
)->charpos
;
5853 BEGV_BYTE
= marker_byte_position (oldbegv
);
5862 ZV
= XMARKER (oldzv
)->charpos
;
5863 ZV_BYTE
= marker_byte_position (oldzv
);
5867 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
5869 /* We can't do Fgoto_char (oldpoint) because it will run some
5871 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
5872 XMARKER (oldpoint
)->bytepos
);
5875 unchain_marker (oldpoint
);
5876 unchain_marker (oldbegv
);
5877 unchain_marker (oldzv
);
5879 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
5880 set_buffer_internal (oldbuf
);
5882 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5883 message_log_need_newline
= !nlflag
;
5884 Vdeactivate_mark
= old_deactivate_mark
;
5889 /* We are at the end of the buffer after just having inserted a newline.
5890 (Note: We depend on the fact we won't be crossing the gap.)
5891 Check to see if the most recent message looks a lot like the previous one.
5892 Return 0 if different, 1 if the new one should just replace it, or a
5893 value N > 1 if we should also append " [N times]". */
5896 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
5897 int prev_bol
, this_bol
;
5898 int prev_bol_byte
, this_bol_byte
;
5901 int len
= Z_BYTE
- 1 - this_bol_byte
;
5903 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
5904 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
5906 for (i
= 0; i
< len
; i
++)
5908 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
5916 if (*p1
++ == ' ' && *p1
++ == '[')
5919 while (*p1
>= '0' && *p1
<= '9')
5920 n
= n
* 10 + *p1
++ - '0';
5921 if (strncmp (p1
, " times]\n", 8) == 0)
5928 /* Display an echo area message M with a specified length of NBYTES
5929 bytes. The string may include null characters. If M is 0, clear
5930 out any existing message, and let the mini-buffer text show
5933 The buffer M must continue to exist until after the echo area gets
5934 cleared or some other message gets displayed there. This means do
5935 not pass text that is stored in a Lisp string; do not pass text in
5936 a buffer that was alloca'd. */
5939 message2 (m
, nbytes
, multibyte
)
5944 /* First flush out any partial line written with print. */
5945 message_log_maybe_newline ();
5947 message_dolog (m
, nbytes
, 1, multibyte
);
5948 message2_nolog (m
, nbytes
, multibyte
);
5952 /* The non-logging counterpart of message2. */
5955 message2_nolog (m
, nbytes
, multibyte
)
5957 int nbytes
, multibyte
;
5959 struct frame
*sf
= SELECTED_FRAME ();
5960 message_enable_multibyte
= multibyte
;
5964 if (noninteractive_need_newline
)
5965 putc ('\n', stderr
);
5966 noninteractive_need_newline
= 0;
5968 fwrite (m
, nbytes
, 1, stderr
);
5969 if (cursor_in_echo_area
== 0)
5970 fprintf (stderr
, "\n");
5973 /* A null message buffer means that the frame hasn't really been
5974 initialized yet. Error messages get reported properly by
5975 cmd_error, so this must be just an informative message; toss it. */
5976 else if (INTERACTIVE
5977 && sf
->glyphs_initialized_p
5978 && FRAME_MESSAGE_BUF (sf
))
5980 Lisp_Object mini_window
;
5983 /* Get the frame containing the mini-buffer
5984 that the selected frame is using. */
5985 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5986 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5988 FRAME_SAMPLE_VISIBILITY (f
);
5989 if (FRAME_VISIBLE_P (sf
)
5990 && ! FRAME_VISIBLE_P (f
))
5991 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
5995 set_message (m
, Qnil
, nbytes
, multibyte
);
5996 if (minibuffer_auto_raise
)
5997 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6000 clear_message (1, 1);
6002 do_pending_window_change (0);
6003 echo_area_display (1);
6004 do_pending_window_change (0);
6005 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6006 (*frame_up_to_date_hook
) (f
);
6011 /* Display an echo area message M with a specified length of NBYTES
6012 bytes. The string may include null characters. If M is not a
6013 string, clear out any existing message, and let the mini-buffer
6014 text show through. */
6017 message3 (m
, nbytes
, multibyte
)
6022 struct gcpro gcpro1
;
6026 /* First flush out any partial line written with print. */
6027 message_log_maybe_newline ();
6029 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6030 message3_nolog (m
, nbytes
, multibyte
);
6036 /* The non-logging version of message3. */
6039 message3_nolog (m
, nbytes
, multibyte
)
6041 int nbytes
, multibyte
;
6043 struct frame
*sf
= SELECTED_FRAME ();
6044 message_enable_multibyte
= multibyte
;
6048 if (noninteractive_need_newline
)
6049 putc ('\n', stderr
);
6050 noninteractive_need_newline
= 0;
6052 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6053 if (cursor_in_echo_area
== 0)
6054 fprintf (stderr
, "\n");
6057 /* A null message buffer means that the frame hasn't really been
6058 initialized yet. Error messages get reported properly by
6059 cmd_error, so this must be just an informative message; toss it. */
6060 else if (INTERACTIVE
6061 && sf
->glyphs_initialized_p
6062 && FRAME_MESSAGE_BUF (sf
))
6064 Lisp_Object mini_window
;
6068 /* Get the frame containing the mini-buffer
6069 that the selected frame is using. */
6070 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6071 frame
= XWINDOW (mini_window
)->frame
;
6074 FRAME_SAMPLE_VISIBILITY (f
);
6075 if (FRAME_VISIBLE_P (sf
)
6076 && !FRAME_VISIBLE_P (f
))
6077 Fmake_frame_visible (frame
);
6079 if (STRINGP (m
) && SCHARS (m
) > 0)
6081 set_message (NULL
, m
, nbytes
, multibyte
);
6082 if (minibuffer_auto_raise
)
6083 Fraise_frame (frame
);
6086 clear_message (1, 1);
6088 do_pending_window_change (0);
6089 echo_area_display (1);
6090 do_pending_window_change (0);
6091 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6092 (*frame_up_to_date_hook
) (f
);
6097 /* Display a null-terminated echo area message M. If M is 0, clear
6098 out any existing message, and let the mini-buffer text show through.
6100 The buffer M must continue to exist until after the echo area gets
6101 cleared or some other message gets displayed there. Do not pass
6102 text that is stored in a Lisp string. Do not pass text in a buffer
6103 that was alloca'd. */
6109 message2 (m
, (m
? strlen (m
) : 0), 0);
6113 /* The non-logging counterpart of message1. */
6119 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6122 /* Display a message M which contains a single %s
6123 which gets replaced with STRING. */
6126 message_with_string (m
, string
, log
)
6131 CHECK_STRING (string
);
6137 if (noninteractive_need_newline
)
6138 putc ('\n', stderr
);
6139 noninteractive_need_newline
= 0;
6140 fprintf (stderr
, m
, SDATA (string
));
6141 if (cursor_in_echo_area
== 0)
6142 fprintf (stderr
, "\n");
6146 else if (INTERACTIVE
)
6148 /* The frame whose minibuffer we're going to display the message on.
6149 It may be larger than the selected frame, so we need
6150 to use its buffer, not the selected frame's buffer. */
6151 Lisp_Object mini_window
;
6152 struct frame
*f
, *sf
= SELECTED_FRAME ();
6154 /* Get the frame containing the minibuffer
6155 that the selected frame is using. */
6156 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6157 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6159 /* A null message buffer means that the frame hasn't really been
6160 initialized yet. Error messages get reported properly by
6161 cmd_error, so this must be just an informative message; toss it. */
6162 if (FRAME_MESSAGE_BUF (f
))
6164 Lisp_Object args
[2], message
;
6165 struct gcpro gcpro1
, gcpro2
;
6167 args
[0] = build_string (m
);
6168 args
[1] = message
= string
;
6169 GCPRO2 (args
[0], message
);
6172 message
= Fformat (2, args
);
6175 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6177 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6181 /* Print should start at the beginning of the message
6182 buffer next time. */
6183 message_buf_print
= 0;
6189 /* Dump an informative message to the minibuf. If M is 0, clear out
6190 any existing message, and let the mini-buffer text show through. */
6194 message (m
, a1
, a2
, a3
)
6196 EMACS_INT a1
, a2
, a3
;
6202 if (noninteractive_need_newline
)
6203 putc ('\n', stderr
);
6204 noninteractive_need_newline
= 0;
6205 fprintf (stderr
, m
, a1
, a2
, a3
);
6206 if (cursor_in_echo_area
== 0)
6207 fprintf (stderr
, "\n");
6211 else if (INTERACTIVE
)
6213 /* The frame whose mini-buffer we're going to display the message
6214 on. It may be larger than the selected frame, so we need to
6215 use its buffer, not the selected frame's buffer. */
6216 Lisp_Object mini_window
;
6217 struct frame
*f
, *sf
= SELECTED_FRAME ();
6219 /* Get the frame containing the mini-buffer
6220 that the selected frame is using. */
6221 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6222 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6224 /* A null message buffer means that the frame hasn't really been
6225 initialized yet. Error messages get reported properly by
6226 cmd_error, so this must be just an informative message; toss
6228 if (FRAME_MESSAGE_BUF (f
))
6239 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6240 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6242 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6243 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6245 #endif /* NO_ARG_ARRAY */
6247 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6252 /* Print should start at the beginning of the message
6253 buffer next time. */
6254 message_buf_print
= 0;
6260 /* The non-logging version of message. */
6263 message_nolog (m
, a1
, a2
, a3
)
6265 EMACS_INT a1
, a2
, a3
;
6267 Lisp_Object old_log_max
;
6268 old_log_max
= Vmessage_log_max
;
6269 Vmessage_log_max
= Qnil
;
6270 message (m
, a1
, a2
, a3
);
6271 Vmessage_log_max
= old_log_max
;
6275 /* Display the current message in the current mini-buffer. This is
6276 only called from error handlers in process.c, and is not time
6282 if (!NILP (echo_area_buffer
[0]))
6285 string
= Fcurrent_message ();
6286 message3 (string
, SBYTES (string
),
6287 !NILP (current_buffer
->enable_multibyte_characters
));
6292 /* Make sure echo area buffers in `echo_buffers' are live.
6293 If they aren't, make new ones. */
6296 ensure_echo_area_buffers ()
6300 for (i
= 0; i
< 2; ++i
)
6301 if (!BUFFERP (echo_buffer
[i
])
6302 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6305 Lisp_Object old_buffer
;
6308 old_buffer
= echo_buffer
[i
];
6309 sprintf (name
, " *Echo Area %d*", i
);
6310 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6311 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6313 for (j
= 0; j
< 2; ++j
)
6314 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6315 echo_area_buffer
[j
] = echo_buffer
[i
];
6320 /* Call FN with args A1..A4 with either the current or last displayed
6321 echo_area_buffer as current buffer.
6323 WHICH zero means use the current message buffer
6324 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6325 from echo_buffer[] and clear it.
6327 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6328 suitable buffer from echo_buffer[] and clear it.
6330 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6331 that the current message becomes the last displayed one, make
6332 choose a suitable buffer for echo_area_buffer[0], and clear it.
6334 Value is what FN returns. */
6337 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6340 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6346 int this_one
, the_other
, clear_buffer_p
, rc
;
6347 int count
= SPECPDL_INDEX ();
6349 /* If buffers aren't live, make new ones. */
6350 ensure_echo_area_buffers ();
6355 this_one
= 0, the_other
= 1;
6357 this_one
= 1, the_other
= 0;
6360 this_one
= 0, the_other
= 1;
6363 /* We need a fresh one in case the current echo buffer equals
6364 the one containing the last displayed echo area message. */
6365 if (!NILP (echo_area_buffer
[this_one
])
6366 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6367 echo_area_buffer
[this_one
] = Qnil
;
6370 /* Choose a suitable buffer from echo_buffer[] is we don't
6372 if (NILP (echo_area_buffer
[this_one
]))
6374 echo_area_buffer
[this_one
]
6375 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6376 ? echo_buffer
[the_other
]
6377 : echo_buffer
[this_one
]);
6381 buffer
= echo_area_buffer
[this_one
];
6383 /* Don't get confused by reusing the buffer used for echoing
6384 for a different purpose. */
6385 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6388 record_unwind_protect (unwind_with_echo_area_buffer
,
6389 with_echo_area_buffer_unwind_data (w
));
6391 /* Make the echo area buffer current. Note that for display
6392 purposes, it is not necessary that the displayed window's buffer
6393 == current_buffer, except for text property lookup. So, let's
6394 only set that buffer temporarily here without doing a full
6395 Fset_window_buffer. We must also change w->pointm, though,
6396 because otherwise an assertions in unshow_buffer fails, and Emacs
6398 set_buffer_internal_1 (XBUFFER (buffer
));
6402 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6405 current_buffer
->undo_list
= Qt
;
6406 current_buffer
->read_only
= Qnil
;
6407 specbind (Qinhibit_read_only
, Qt
);
6408 specbind (Qinhibit_modification_hooks
, Qt
);
6410 if (clear_buffer_p
&& Z
> BEG
)
6413 xassert (BEGV
>= BEG
);
6414 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6416 rc
= fn (a1
, a2
, a3
, a4
);
6418 xassert (BEGV
>= BEG
);
6419 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6421 unbind_to (count
, Qnil
);
6426 /* Save state that should be preserved around the call to the function
6427 FN called in with_echo_area_buffer. */
6430 with_echo_area_buffer_unwind_data (w
)
6436 /* Reduce consing by keeping one vector in
6437 Vwith_echo_area_save_vector. */
6438 vector
= Vwith_echo_area_save_vector
;
6439 Vwith_echo_area_save_vector
= Qnil
;
6442 vector
= Fmake_vector (make_number (7), Qnil
);
6444 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6445 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6446 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6450 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6451 AREF (vector
, i
) = w
->buffer
; ++i
;
6452 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6453 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6458 for (; i
< end
; ++i
)
6459 AREF (vector
, i
) = Qnil
;
6462 xassert (i
== ASIZE (vector
));
6467 /* Restore global state from VECTOR which was created by
6468 with_echo_area_buffer_unwind_data. */
6471 unwind_with_echo_area_buffer (vector
)
6474 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6475 Vdeactivate_mark
= AREF (vector
, 1);
6476 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6478 if (WINDOWP (AREF (vector
, 3)))
6481 Lisp_Object buffer
, charpos
, bytepos
;
6483 w
= XWINDOW (AREF (vector
, 3));
6484 buffer
= AREF (vector
, 4);
6485 charpos
= AREF (vector
, 5);
6486 bytepos
= AREF (vector
, 6);
6489 set_marker_both (w
->pointm
, buffer
,
6490 XFASTINT (charpos
), XFASTINT (bytepos
));
6493 Vwith_echo_area_save_vector
= vector
;
6498 /* Set up the echo area for use by print functions. MULTIBYTE_P
6499 non-zero means we will print multibyte. */
6502 setup_echo_area_for_printing (multibyte_p
)
6505 /* If we can't find an echo area any more, exit. */
6506 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
6509 ensure_echo_area_buffers ();
6511 if (!message_buf_print
)
6513 /* A message has been output since the last time we printed.
6514 Choose a fresh echo area buffer. */
6515 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6516 echo_area_buffer
[0] = echo_buffer
[1];
6518 echo_area_buffer
[0] = echo_buffer
[0];
6520 /* Switch to that buffer and clear it. */
6521 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6522 current_buffer
->truncate_lines
= Qnil
;
6526 int count
= SPECPDL_INDEX ();
6527 specbind (Qinhibit_read_only
, Qt
);
6528 /* Note that undo recording is always disabled. */
6530 unbind_to (count
, Qnil
);
6532 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6534 /* Set up the buffer for the multibyteness we need. */
6536 != !NILP (current_buffer
->enable_multibyte_characters
))
6537 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6539 /* Raise the frame containing the echo area. */
6540 if (minibuffer_auto_raise
)
6542 struct frame
*sf
= SELECTED_FRAME ();
6543 Lisp_Object mini_window
;
6544 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6545 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6548 message_log_maybe_newline ();
6549 message_buf_print
= 1;
6553 if (NILP (echo_area_buffer
[0]))
6555 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6556 echo_area_buffer
[0] = echo_buffer
[1];
6558 echo_area_buffer
[0] = echo_buffer
[0];
6561 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6563 /* Someone switched buffers between print requests. */
6564 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6565 current_buffer
->truncate_lines
= Qnil
;
6571 /* Display an echo area message in window W. Value is non-zero if W's
6572 height is changed. If display_last_displayed_message_p is
6573 non-zero, display the message that was last displayed, otherwise
6574 display the current message. */
6577 display_echo_area (w
)
6580 int i
, no_message_p
, window_height_changed_p
, count
;
6582 /* Temporarily disable garbage collections while displaying the echo
6583 area. This is done because a GC can print a message itself.
6584 That message would modify the echo area buffer's contents while a
6585 redisplay of the buffer is going on, and seriously confuse
6587 count
= inhibit_garbage_collection ();
6589 /* If there is no message, we must call display_echo_area_1
6590 nevertheless because it resizes the window. But we will have to
6591 reset the echo_area_buffer in question to nil at the end because
6592 with_echo_area_buffer will sets it to an empty buffer. */
6593 i
= display_last_displayed_message_p
? 1 : 0;
6594 no_message_p
= NILP (echo_area_buffer
[i
]);
6596 window_height_changed_p
6597 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6598 display_echo_area_1
,
6599 (EMACS_INT
) w
, Qnil
, 0, 0);
6602 echo_area_buffer
[i
] = Qnil
;
6604 unbind_to (count
, Qnil
);
6605 return window_height_changed_p
;
6609 /* Helper for display_echo_area. Display the current buffer which
6610 contains the current echo area message in window W, a mini-window,
6611 a pointer to which is passed in A1. A2..A4 are currently not used.
6612 Change the height of W so that all of the message is displayed.
6613 Value is non-zero if height of W was changed. */
6616 display_echo_area_1 (a1
, a2
, a3
, a4
)
6621 struct window
*w
= (struct window
*) a1
;
6623 struct text_pos start
;
6624 int window_height_changed_p
= 0;
6626 /* Do this before displaying, so that we have a large enough glyph
6627 matrix for the display. */
6628 window_height_changed_p
= resize_mini_window (w
, 0);
6631 clear_glyph_matrix (w
->desired_matrix
);
6632 XSETWINDOW (window
, w
);
6633 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
6634 try_window (window
, start
);
6636 return window_height_changed_p
;
6640 /* Resize the echo area window to exactly the size needed for the
6641 currently displayed message, if there is one. If a mini-buffer
6642 is active, don't shrink it. */
6645 resize_echo_area_exactly ()
6647 if (BUFFERP (echo_area_buffer
[0])
6648 && WINDOWP (echo_area_window
))
6650 struct window
*w
= XWINDOW (echo_area_window
);
6652 Lisp_Object resize_exactly
;
6654 if (minibuf_level
== 0)
6655 resize_exactly
= Qt
;
6657 resize_exactly
= Qnil
;
6659 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
6660 (EMACS_INT
) w
, resize_exactly
, 0, 0);
6663 ++windows_or_buffers_changed
;
6664 ++update_mode_lines
;
6665 redisplay_internal (0);
6671 /* Callback function for with_echo_area_buffer, when used from
6672 resize_echo_area_exactly. A1 contains a pointer to the window to
6673 resize, EXACTLY non-nil means resize the mini-window exactly to the
6674 size of the text displayed. A3 and A4 are not used. Value is what
6675 resize_mini_window returns. */
6678 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
6680 Lisp_Object exactly
;
6683 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
6687 /* Resize mini-window W to fit the size of its contents. EXACT:P
6688 means size the window exactly to the size needed. Otherwise, it's
6689 only enlarged until W's buffer is empty. Value is non-zero if
6690 the window height has been changed. */
6693 resize_mini_window (w
, exact_p
)
6697 struct frame
*f
= XFRAME (w
->frame
);
6698 int window_height_changed_p
= 0;
6700 xassert (MINI_WINDOW_P (w
));
6702 /* Don't resize windows while redisplaying a window; it would
6703 confuse redisplay functions when the size of the window they are
6704 displaying changes from under them. Such a resizing can happen,
6705 for instance, when which-func prints a long message while
6706 we are running fontification-functions. We're running these
6707 functions with safe_call which binds inhibit-redisplay to t. */
6708 if (!NILP (Vinhibit_redisplay
))
6711 /* Nil means don't try to resize. */
6712 if (NILP (Vresize_mini_windows
)
6713 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
6716 if (!FRAME_MINIBUF_ONLY_P (f
))
6719 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6720 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
6721 int height
, max_height
;
6722 int unit
= CANON_Y_UNIT (f
);
6723 struct text_pos start
;
6724 struct buffer
*old_current_buffer
= NULL
;
6726 if (current_buffer
!= XBUFFER (w
->buffer
))
6728 old_current_buffer
= current_buffer
;
6729 set_buffer_internal (XBUFFER (w
->buffer
));
6732 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
6734 /* Compute the max. number of lines specified by the user. */
6735 if (FLOATP (Vmax_mini_window_height
))
6736 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
6737 else if (INTEGERP (Vmax_mini_window_height
))
6738 max_height
= XINT (Vmax_mini_window_height
);
6740 max_height
= total_height
/ 4;
6742 /* Correct that max. height if it's bogus. */
6743 max_height
= max (1, max_height
);
6744 max_height
= min (total_height
, max_height
);
6746 /* Find out the height of the text in the window. */
6747 if (it
.truncate_lines_p
)
6752 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
6753 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
6754 height
= it
.current_y
+ last_height
;
6756 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
6757 height
-= it
.extra_line_spacing
;
6758 height
= (height
+ unit
- 1) / unit
;
6761 /* Compute a suitable window start. */
6762 if (height
> max_height
)
6764 height
= max_height
;
6765 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
6766 move_it_vertically_backward (&it
, (height
- 1) * unit
);
6767 start
= it
.current
.pos
;
6770 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
6771 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
6773 if (EQ (Vresize_mini_windows
, Qgrow_only
))
6775 /* Let it grow only, until we display an empty message, in which
6776 case the window shrinks again. */
6777 if (height
> XFASTINT (w
->height
))
6779 int old_height
= XFASTINT (w
->height
);
6780 freeze_window_starts (f
, 1);
6781 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6782 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6784 else if (height
< XFASTINT (w
->height
)
6785 && (exact_p
|| BEGV
== ZV
))
6787 int old_height
= XFASTINT (w
->height
);
6788 freeze_window_starts (f
, 0);
6789 shrink_mini_window (w
);
6790 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6795 /* Always resize to exact size needed. */
6796 if (height
> XFASTINT (w
->height
))
6798 int old_height
= XFASTINT (w
->height
);
6799 freeze_window_starts (f
, 1);
6800 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6801 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6803 else if (height
< XFASTINT (w
->height
))
6805 int old_height
= XFASTINT (w
->height
);
6806 freeze_window_starts (f
, 0);
6807 shrink_mini_window (w
);
6811 freeze_window_starts (f
, 1);
6812 grow_mini_window (w
, height
- XFASTINT (w
->height
));
6815 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
6819 if (old_current_buffer
)
6820 set_buffer_internal (old_current_buffer
);
6823 return window_height_changed_p
;
6827 /* Value is the current message, a string, or nil if there is no
6835 if (NILP (echo_area_buffer
[0]))
6839 with_echo_area_buffer (0, 0, current_message_1
,
6840 (EMACS_INT
) &msg
, Qnil
, 0, 0);
6842 echo_area_buffer
[0] = Qnil
;
6850 current_message_1 (a1
, a2
, a3
, a4
)
6855 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
6858 *msg
= make_buffer_string (BEG
, Z
, 1);
6865 /* Push the current message on Vmessage_stack for later restauration
6866 by restore_message. Value is non-zero if the current message isn't
6867 empty. This is a relatively infrequent operation, so it's not
6868 worth optimizing. */
6874 msg
= current_message ();
6875 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
6876 return STRINGP (msg
);
6880 /* Restore message display from the top of Vmessage_stack. */
6887 xassert (CONSP (Vmessage_stack
));
6888 msg
= XCAR (Vmessage_stack
);
6890 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
6892 message3_nolog (msg
, 0, 0);
6896 /* Handler for record_unwind_protect calling pop_message. */
6899 pop_message_unwind (dummy
)
6906 /* Pop the top-most entry off Vmessage_stack. */
6911 xassert (CONSP (Vmessage_stack
));
6912 Vmessage_stack
= XCDR (Vmessage_stack
);
6916 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
6917 exits. If the stack is not empty, we have a missing pop_message
6921 check_message_stack ()
6923 if (!NILP (Vmessage_stack
))
6928 /* Truncate to NCHARS what will be displayed in the echo area the next
6929 time we display it---but don't redisplay it now. */
6932 truncate_echo_area (nchars
)
6936 echo_area_buffer
[0] = Qnil
;
6937 /* A null message buffer means that the frame hasn't really been
6938 initialized yet. Error messages get reported properly by
6939 cmd_error, so this must be just an informative message; toss it. */
6940 else if (!noninteractive
6942 && !NILP (echo_area_buffer
[0]))
6944 struct frame
*sf
= SELECTED_FRAME ();
6945 if (FRAME_MESSAGE_BUF (sf
))
6946 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
6951 /* Helper function for truncate_echo_area. Truncate the current
6952 message to at most NCHARS characters. */
6955 truncate_message_1 (nchars
, a2
, a3
, a4
)
6960 if (BEG
+ nchars
< Z
)
6961 del_range (BEG
+ nchars
, Z
);
6963 echo_area_buffer
[0] = Qnil
;
6968 /* Set the current message to a substring of S or STRING.
6970 If STRING is a Lisp string, set the message to the first NBYTES
6971 bytes from STRING. NBYTES zero means use the whole string. If
6972 STRING is multibyte, the message will be displayed multibyte.
6974 If S is not null, set the message to the first LEN bytes of S. LEN
6975 zero means use the whole string. MULTIBYTE_P non-zero means S is
6976 multibyte. Display the message multibyte in that case. */
6979 set_message (s
, string
, nbytes
, multibyte_p
)
6982 int nbytes
, multibyte_p
;
6984 message_enable_multibyte
6985 = ((s
&& multibyte_p
)
6986 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
6988 with_echo_area_buffer (0, -1, set_message_1
,
6989 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
6990 message_buf_print
= 0;
6991 help_echo_showing_p
= 0;
6995 /* Helper function for set_message. Arguments have the same meaning
6996 as there, with A1 corresponding to S and A2 corresponding to STRING
6997 This function is called with the echo area buffer being
7001 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7004 EMACS_INT nbytes
, multibyte_p
;
7006 const char *s
= (const char *) a1
;
7007 Lisp_Object string
= a2
;
7011 /* Change multibyteness of the echo buffer appropriately. */
7012 if (message_enable_multibyte
7013 != !NILP (current_buffer
->enable_multibyte_characters
))
7014 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7016 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7018 /* Insert new message at BEG. */
7019 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7021 if (STRINGP (string
))
7026 nbytes
= SBYTES (string
);
7027 nchars
= string_byte_to_char (string
, nbytes
);
7029 /* This function takes care of single/multibyte conversion. We
7030 just have to ensure that the echo area buffer has the right
7031 setting of enable_multibyte_characters. */
7032 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7037 nbytes
= strlen (s
);
7039 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7041 /* Convert from multi-byte to single-byte. */
7043 unsigned char work
[1];
7045 /* Convert a multibyte string to single-byte. */
7046 for (i
= 0; i
< nbytes
; i
+= n
)
7048 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7049 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7051 : multibyte_char_to_unibyte (c
, Qnil
));
7052 insert_1_both (work
, 1, 1, 1, 0, 0);
7055 else if (!multibyte_p
7056 && !NILP (current_buffer
->enable_multibyte_characters
))
7058 /* Convert from single-byte to multi-byte. */
7060 const unsigned char *msg
= (const unsigned char *) s
;
7061 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7063 /* Convert a single-byte string to multibyte. */
7064 for (i
= 0; i
< nbytes
; i
++)
7066 c
= unibyte_char_to_multibyte (msg
[i
]);
7067 n
= CHAR_STRING (c
, str
);
7068 insert_1_both (str
, 1, n
, 1, 0, 0);
7072 insert_1 (s
, nbytes
, 1, 0, 0);
7079 /* Clear messages. CURRENT_P non-zero means clear the current
7080 message. LAST_DISPLAYED_P non-zero means clear the message
7084 clear_message (current_p
, last_displayed_p
)
7085 int current_p
, last_displayed_p
;
7089 echo_area_buffer
[0] = Qnil
;
7090 message_cleared_p
= 1;
7093 if (last_displayed_p
)
7094 echo_area_buffer
[1] = Qnil
;
7096 message_buf_print
= 0;
7099 /* Clear garbaged frames.
7101 This function is used where the old redisplay called
7102 redraw_garbaged_frames which in turn called redraw_frame which in
7103 turn called clear_frame. The call to clear_frame was a source of
7104 flickering. I believe a clear_frame is not necessary. It should
7105 suffice in the new redisplay to invalidate all current matrices,
7106 and ensure a complete redisplay of all windows. */
7109 clear_garbaged_frames ()
7113 Lisp_Object tail
, frame
;
7114 int changed_count
= 0;
7116 FOR_EACH_FRAME (tail
, frame
)
7118 struct frame
*f
= XFRAME (frame
);
7120 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7123 Fredraw_frame (frame
);
7124 clear_current_matrices (f
);
7133 ++windows_or_buffers_changed
;
7138 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7139 is non-zero update selected_frame. Value is non-zero if the
7140 mini-windows height has been changed. */
7143 echo_area_display (update_frame_p
)
7146 Lisp_Object mini_window
;
7149 int window_height_changed_p
= 0;
7150 struct frame
*sf
= SELECTED_FRAME ();
7152 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7153 w
= XWINDOW (mini_window
);
7154 f
= XFRAME (WINDOW_FRAME (w
));
7156 /* Don't display if frame is invisible or not yet initialized. */
7157 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7160 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7162 #ifdef HAVE_WINDOW_SYSTEM
7163 /* When Emacs starts, selected_frame may be a visible terminal
7164 frame, even if we run under a window system. If we let this
7165 through, a message would be displayed on the terminal. */
7166 if (EQ (selected_frame
, Vterminal_frame
)
7167 && !NILP (Vwindow_system
))
7169 #endif /* HAVE_WINDOW_SYSTEM */
7172 /* Redraw garbaged frames. */
7174 clear_garbaged_frames ();
7176 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7178 echo_area_window
= mini_window
;
7179 window_height_changed_p
= display_echo_area (w
);
7180 w
->must_be_updated_p
= 1;
7182 /* Update the display, unless called from redisplay_internal.
7183 Also don't update the screen during redisplay itself. The
7184 update will happen at the end of redisplay, and an update
7185 here could cause confusion. */
7186 if (update_frame_p
&& !redisplaying_p
)
7190 /* If the display update has been interrupted by pending
7191 input, update mode lines in the frame. Due to the
7192 pending input, it might have been that redisplay hasn't
7193 been called, so that mode lines above the echo area are
7194 garbaged. This looks odd, so we prevent it here. */
7195 if (!display_completed
)
7196 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7198 if (window_height_changed_p
7199 /* Don't do this if Emacs is shutting down. Redisplay
7200 needs to run hooks. */
7201 && !NILP (Vrun_hooks
))
7203 /* Must update other windows. Likewise as in other
7204 cases, don't let this update be interrupted by
7206 int count
= SPECPDL_INDEX ();
7207 specbind (Qredisplay_dont_pause
, Qt
);
7208 windows_or_buffers_changed
= 1;
7209 redisplay_internal (0);
7210 unbind_to (count
, Qnil
);
7212 else if (FRAME_WINDOW_P (f
) && n
== 0)
7214 /* Window configuration is the same as before.
7215 Can do with a display update of the echo area,
7216 unless we displayed some mode lines. */
7217 update_single_window (w
, 1);
7218 rif
->flush_display (f
);
7221 update_frame (f
, 1, 1);
7223 /* If cursor is in the echo area, make sure that the next
7224 redisplay displays the minibuffer, so that the cursor will
7225 be replaced with what the minibuffer wants. */
7226 if (cursor_in_echo_area
)
7227 ++windows_or_buffers_changed
;
7230 else if (!EQ (mini_window
, selected_window
))
7231 windows_or_buffers_changed
++;
7233 /* Last displayed message is now the current message. */
7234 echo_area_buffer
[1] = echo_area_buffer
[0];
7236 /* Prevent redisplay optimization in redisplay_internal by resetting
7237 this_line_start_pos. This is done because the mini-buffer now
7238 displays the message instead of its buffer text. */
7239 if (EQ (mini_window
, selected_window
))
7240 CHARPOS (this_line_start_pos
) = 0;
7242 return window_height_changed_p
;
7247 /***********************************************************************
7249 ***********************************************************************/
7252 /* The frame title buffering code is also used by Fformat_mode_line.
7253 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7255 /* A buffer for constructing frame titles in it; allocated from the
7256 heap in init_xdisp and resized as needed in store_frame_title_char. */
7258 static char *frame_title_buf
;
7260 /* The buffer's end, and a current output position in it. */
7262 static char *frame_title_buf_end
;
7263 static char *frame_title_ptr
;
7266 /* Store a single character C for the frame title in frame_title_buf.
7267 Re-allocate frame_title_buf if necessary. */
7271 store_frame_title_char (char c
)
7273 store_frame_title_char (c
)
7277 /* If output position has reached the end of the allocated buffer,
7278 double the buffer's size. */
7279 if (frame_title_ptr
== frame_title_buf_end
)
7281 int len
= frame_title_ptr
- frame_title_buf
;
7282 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7283 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7284 frame_title_buf_end
= frame_title_buf
+ new_size
;
7285 frame_title_ptr
= frame_title_buf
+ len
;
7288 *frame_title_ptr
++ = c
;
7292 /* Store part of a frame title in frame_title_buf, beginning at
7293 frame_title_ptr. STR is the string to store. Do not copy
7294 characters that yield more columns than PRECISION; PRECISION <= 0
7295 means copy the whole string. Pad with spaces until FIELD_WIDTH
7296 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7297 pad. Called from display_mode_element when it is used to build a
7301 store_frame_title (str
, field_width
, precision
)
7302 const unsigned char *str
;
7303 int field_width
, precision
;
7308 /* Copy at most PRECISION chars from STR. */
7309 nbytes
= strlen (str
);
7310 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7312 store_frame_title_char (*str
++);
7314 /* Fill up with spaces until FIELD_WIDTH reached. */
7315 while (field_width
> 0
7318 store_frame_title_char (' ');
7325 #ifdef HAVE_WINDOW_SYSTEM
7327 /* Set the title of FRAME, if it has changed. The title format is
7328 Vicon_title_format if FRAME is iconified, otherwise it is
7329 frame_title_format. */
7332 x_consider_frame_title (frame
)
7335 struct frame
*f
= XFRAME (frame
);
7337 if (FRAME_WINDOW_P (f
)
7338 || FRAME_MINIBUF_ONLY_P (f
)
7339 || f
->explicit_name
)
7341 /* Do we have more than one visible frame on this X display? */
7344 struct buffer
*obuf
;
7348 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7350 Lisp_Object other_frame
= XCAR (tail
);
7351 struct frame
*tf
= XFRAME (other_frame
);
7354 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7355 && !FRAME_MINIBUF_ONLY_P (tf
)
7356 && !EQ (other_frame
, tip_frame
)
7357 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7361 /* Set global variable indicating that multiple frames exist. */
7362 multiple_frames
= CONSP (tail
);
7364 /* Switch to the buffer of selected window of the frame. Set up
7365 frame_title_ptr so that display_mode_element will output into it;
7366 then display the title. */
7367 obuf
= current_buffer
;
7368 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7369 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7370 frame_title_ptr
= frame_title_buf
;
7371 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7372 NULL
, DEFAULT_FACE_ID
);
7373 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7374 len
= frame_title_ptr
- frame_title_buf
;
7375 frame_title_ptr
= NULL
;
7376 set_buffer_internal_1 (obuf
);
7378 /* Set the title only if it's changed. This avoids consing in
7379 the common case where it hasn't. (If it turns out that we've
7380 already wasted too much time by walking through the list with
7381 display_mode_element, then we might need to optimize at a
7382 higher level than this.) */
7383 if (! STRINGP (f
->name
)
7384 || SBYTES (f
->name
) != len
7385 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7386 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7390 #endif /* not HAVE_WINDOW_SYSTEM */
7395 /***********************************************************************
7397 ***********************************************************************/
7400 /* Prepare for redisplay by updating menu-bar item lists when
7401 appropriate. This can call eval. */
7404 prepare_menu_bars ()
7407 struct gcpro gcpro1
, gcpro2
;
7409 Lisp_Object tooltip_frame
;
7411 #ifdef HAVE_WINDOW_SYSTEM
7412 tooltip_frame
= tip_frame
;
7414 tooltip_frame
= Qnil
;
7417 /* Update all frame titles based on their buffer names, etc. We do
7418 this before the menu bars so that the buffer-menu will show the
7419 up-to-date frame titles. */
7420 #ifdef HAVE_WINDOW_SYSTEM
7421 if (windows_or_buffers_changed
|| update_mode_lines
)
7423 Lisp_Object tail
, frame
;
7425 FOR_EACH_FRAME (tail
, frame
)
7428 if (!EQ (frame
, tooltip_frame
)
7429 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7430 x_consider_frame_title (frame
);
7433 #endif /* HAVE_WINDOW_SYSTEM */
7435 /* Update the menu bar item lists, if appropriate. This has to be
7436 done before any actual redisplay or generation of display lines. */
7437 all_windows
= (update_mode_lines
7438 || buffer_shared
> 1
7439 || windows_or_buffers_changed
);
7442 Lisp_Object tail
, frame
;
7443 int count
= SPECPDL_INDEX ();
7445 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7447 FOR_EACH_FRAME (tail
, frame
)
7451 /* Ignore tooltip frame. */
7452 if (EQ (frame
, tooltip_frame
))
7455 /* If a window on this frame changed size, report that to
7456 the user and clear the size-change flag. */
7457 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7459 Lisp_Object functions
;
7461 /* Clear flag first in case we get an error below. */
7462 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7463 functions
= Vwindow_size_change_functions
;
7464 GCPRO2 (tail
, functions
);
7466 while (CONSP (functions
))
7468 call1 (XCAR (functions
), frame
);
7469 functions
= XCDR (functions
);
7475 update_menu_bar (f
, 0);
7476 #ifdef HAVE_WINDOW_SYSTEM
7477 update_tool_bar (f
, 0);
7482 unbind_to (count
, Qnil
);
7486 struct frame
*sf
= SELECTED_FRAME ();
7487 update_menu_bar (sf
, 1);
7488 #ifdef HAVE_WINDOW_SYSTEM
7489 update_tool_bar (sf
, 1);
7493 /* Motif needs this. See comment in xmenu.c. Turn it off when
7494 pending_menu_activation is not defined. */
7495 #ifdef USE_X_TOOLKIT
7496 pending_menu_activation
= 0;
7501 /* Update the menu bar item list for frame F. This has to be done
7502 before we start to fill in any display lines, because it can call
7505 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7508 update_menu_bar (f
, save_match_data
)
7510 int save_match_data
;
7513 register struct window
*w
;
7515 /* If called recursively during a menu update, do nothing. This can
7516 happen when, for instance, an activate-menubar-hook causes a
7518 if (inhibit_menubar_update
)
7521 window
= FRAME_SELECTED_WINDOW (f
);
7522 w
= XWINDOW (window
);
7524 #if 0 /* The if statement below this if statement used to include the
7525 condition !NILP (w->update_mode_line), rather than using
7526 update_mode_lines directly, and this if statement may have
7527 been added to make that condition work. Now the if
7528 statement below matches its comment, this isn't needed. */
7529 if (update_mode_lines
)
7530 w
->update_mode_line
= Qt
;
7533 if (FRAME_WINDOW_P (f
)
7535 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7536 || defined (USE_GTK)
7537 FRAME_EXTERNAL_MENU_BAR (f
)
7539 FRAME_MENU_BAR_LINES (f
) > 0
7541 : FRAME_MENU_BAR_LINES (f
) > 0)
7543 /* If the user has switched buffers or windows, we need to
7544 recompute to reflect the new bindings. But we'll
7545 recompute when update_mode_lines is set too; that means
7546 that people can use force-mode-line-update to request
7547 that the menu bar be recomputed. The adverse effect on
7548 the rest of the redisplay algorithm is about the same as
7549 windows_or_buffers_changed anyway. */
7550 if (windows_or_buffers_changed
7551 /* This used to test w->update_mode_line, but we believe
7552 there is no need to recompute the menu in that case. */
7553 || update_mode_lines
7554 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7555 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7556 != !NILP (w
->last_had_star
))
7557 || ((!NILP (Vtransient_mark_mode
)
7558 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7559 != !NILP (w
->region_showing
)))
7561 struct buffer
*prev
= current_buffer
;
7562 int count
= SPECPDL_INDEX ();
7564 specbind (Qinhibit_menubar_update
, Qt
);
7566 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7567 if (save_match_data
)
7568 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7569 if (NILP (Voverriding_local_map_menu_flag
))
7571 specbind (Qoverriding_terminal_local_map
, Qnil
);
7572 specbind (Qoverriding_local_map
, Qnil
);
7575 /* Run the Lucid hook. */
7576 safe_run_hooks (Qactivate_menubar_hook
);
7578 /* If it has changed current-menubar from previous value,
7579 really recompute the menu-bar from the value. */
7580 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7581 call0 (Qrecompute_lucid_menubar
);
7583 safe_run_hooks (Qmenu_bar_update_hook
);
7584 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7586 /* Redisplay the menu bar in case we changed it. */
7587 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7588 || defined (USE_GTK)
7589 if (FRAME_WINDOW_P (f
)
7590 #if defined (MAC_OS)
7591 /* All frames on Mac OS share the same menubar. So only the
7592 selected frame should be allowed to set it. */
7593 && f
== SELECTED_FRAME ()
7596 set_frame_menubar (f
, 0, 0);
7598 /* On a terminal screen, the menu bar is an ordinary screen
7599 line, and this makes it get updated. */
7600 w
->update_mode_line
= Qt
;
7601 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7602 /* In the non-toolkit version, the menu bar is an ordinary screen
7603 line, and this makes it get updated. */
7604 w
->update_mode_line
= Qt
;
7605 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7607 unbind_to (count
, Qnil
);
7608 set_buffer_internal_1 (prev
);
7615 /***********************************************************************
7617 ***********************************************************************/
7619 #ifdef HAVE_WINDOW_SYSTEM
7621 /* Update the tool-bar item list for frame F. This has to be done
7622 before we start to fill in any display lines. Called from
7623 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
7624 and restore it here. */
7627 update_tool_bar (f
, save_match_data
)
7629 int save_match_data
;
7632 int do_update
= FRAME_EXTERNAL_TOOL_BAR(f
);
7634 int do_update
= WINDOWP (f
->tool_bar_window
)
7635 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0;
7643 window
= FRAME_SELECTED_WINDOW (f
);
7644 w
= XWINDOW (window
);
7646 /* If the user has switched buffers or windows, we need to
7647 recompute to reflect the new bindings. But we'll
7648 recompute when update_mode_lines is set too; that means
7649 that people can use force-mode-line-update to request
7650 that the menu bar be recomputed. The adverse effect on
7651 the rest of the redisplay algorithm is about the same as
7652 windows_or_buffers_changed anyway. */
7653 if (windows_or_buffers_changed
7654 || !NILP (w
->update_mode_line
)
7655 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7656 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7657 != !NILP (w
->last_had_star
))
7658 || ((!NILP (Vtransient_mark_mode
)
7659 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7660 != !NILP (w
->region_showing
)))
7662 struct buffer
*prev
= current_buffer
;
7663 int count
= SPECPDL_INDEX ();
7665 /* Set current_buffer to the buffer of the selected
7666 window of the frame, so that we get the right local
7668 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7670 /* Save match data, if we must. */
7671 if (save_match_data
)
7672 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7674 /* Make sure that we don't accidentally use bogus keymaps. */
7675 if (NILP (Voverriding_local_map_menu_flag
))
7677 specbind (Qoverriding_terminal_local_map
, Qnil
);
7678 specbind (Qoverriding_local_map
, Qnil
);
7681 /* Build desired tool-bar items from keymaps. */
7683 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
7685 /* Redisplay the tool-bar in case we changed it. */
7686 w
->update_mode_line
= Qt
;
7688 unbind_to (count
, Qnil
);
7689 set_buffer_internal_1 (prev
);
7695 /* Set F->desired_tool_bar_string to a Lisp string representing frame
7696 F's desired tool-bar contents. F->tool_bar_items must have
7697 been set up previously by calling prepare_menu_bars. */
7700 build_desired_tool_bar_string (f
)
7703 int i
, size
, size_needed
;
7704 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7705 Lisp_Object image
, plist
, props
;
7707 image
= plist
= props
= Qnil
;
7708 GCPRO3 (image
, plist
, props
);
7710 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
7711 Otherwise, make a new string. */
7713 /* The size of the string we might be able to reuse. */
7714 size
= (STRINGP (f
->desired_tool_bar_string
)
7715 ? SCHARS (f
->desired_tool_bar_string
)
7718 /* We need one space in the string for each image. */
7719 size_needed
= f
->n_tool_bar_items
;
7721 /* Reuse f->desired_tool_bar_string, if possible. */
7722 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
7723 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
7727 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
7728 Fremove_text_properties (make_number (0), make_number (size
),
7729 props
, f
->desired_tool_bar_string
);
7732 /* Put a `display' property on the string for the images to display,
7733 put a `menu_item' property on tool-bar items with a value that
7734 is the index of the item in F's tool-bar item vector. */
7735 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
7737 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
7739 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7740 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7741 int hmargin
, vmargin
, relief
, idx
, end
;
7742 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
7744 /* If image is a vector, choose the image according to the
7746 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
7747 if (VECTORP (image
))
7751 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
7752 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
7755 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
7756 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
7758 xassert (ASIZE (image
) >= idx
);
7759 image
= AREF (image
, idx
);
7764 /* Ignore invalid image specifications. */
7765 if (!valid_image_p (image
))
7768 /* Display the tool-bar button pressed, or depressed. */
7769 plist
= Fcopy_sequence (XCDR (image
));
7771 /* Compute margin and relief to draw. */
7772 relief
= (tool_bar_button_relief
>= 0
7773 ? tool_bar_button_relief
7774 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
7775 hmargin
= vmargin
= relief
;
7777 if (INTEGERP (Vtool_bar_button_margin
)
7778 && XINT (Vtool_bar_button_margin
) > 0)
7780 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
7781 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
7783 else if (CONSP (Vtool_bar_button_margin
))
7785 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
7786 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
7787 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
7789 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
7790 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
7791 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
7794 if (auto_raise_tool_bar_buttons_p
)
7796 /* Add a `:relief' property to the image spec if the item is
7800 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
7807 /* If image is selected, display it pressed, i.e. with a
7808 negative relief. If it's not selected, display it with a
7810 plist
= Fplist_put (plist
, QCrelief
,
7812 ? make_number (-relief
)
7813 : make_number (relief
)));
7818 /* Put a margin around the image. */
7819 if (hmargin
|| vmargin
)
7821 if (hmargin
== vmargin
)
7822 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
7824 plist
= Fplist_put (plist
, QCmargin
,
7825 Fcons (make_number (hmargin
),
7826 make_number (vmargin
)));
7829 /* If button is not enabled, and we don't have special images
7830 for the disabled state, make the image appear disabled by
7831 applying an appropriate algorithm to it. */
7832 if (!enabled_p
&& idx
< 0)
7833 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
7835 /* Put a `display' text property on the string for the image to
7836 display. Put a `menu-item' property on the string that gives
7837 the start of this item's properties in the tool-bar items
7839 image
= Fcons (Qimage
, plist
);
7840 props
= list4 (Qdisplay
, image
,
7841 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
7843 /* Let the last image hide all remaining spaces in the tool bar
7844 string. The string can be longer than needed when we reuse a
7846 if (i
+ 1 == f
->n_tool_bar_items
)
7847 end
= SCHARS (f
->desired_tool_bar_string
);
7850 Fadd_text_properties (make_number (i
), make_number (end
),
7851 props
, f
->desired_tool_bar_string
);
7859 /* Display one line of the tool-bar of frame IT->f. */
7862 display_tool_bar_line (it
)
7865 struct glyph_row
*row
= it
->glyph_row
;
7866 int max_x
= it
->last_visible_x
;
7869 prepare_desired_row (row
);
7870 row
->y
= it
->current_y
;
7872 /* Note that this isn't made use of if the face hasn't a box,
7873 so there's no need to check the face here. */
7874 it
->start_of_box_run_p
= 1;
7876 while (it
->current_x
< max_x
)
7878 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
7880 /* Get the next display element. */
7881 if (!get_next_display_element (it
))
7884 /* Produce glyphs. */
7885 x_before
= it
->current_x
;
7886 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
7887 PRODUCE_GLYPHS (it
);
7889 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
7894 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
7896 if (x
+ glyph
->pixel_width
> max_x
)
7898 /* Glyph doesn't fit on line. */
7899 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
7905 x
+= glyph
->pixel_width
;
7909 /* Stop at line ends. */
7910 if (ITERATOR_AT_END_OF_LINE_P (it
))
7913 set_iterator_to_next (it
, 1);
7918 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
7919 extend_face_to_end_of_line (it
);
7920 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
7921 last
->right_box_line_p
= 1;
7922 if (last
== row
->glyphs
[TEXT_AREA
])
7923 last
->left_box_line_p
= 1;
7924 compute_line_metrics (it
);
7926 /* If line is empty, make it occupy the rest of the tool-bar. */
7927 if (!row
->displays_text_p
)
7929 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
7930 row
->ascent
= row
->phys_ascent
= 0;
7933 row
->full_width_p
= 1;
7934 row
->continued_p
= 0;
7935 row
->truncated_on_left_p
= 0;
7936 row
->truncated_on_right_p
= 0;
7938 it
->current_x
= it
->hpos
= 0;
7939 it
->current_y
+= row
->height
;
7945 /* Value is the number of screen lines needed to make all tool-bar
7946 items of frame F visible. */
7949 tool_bar_lines_needed (f
)
7952 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7955 /* Initialize an iterator for iteration over
7956 F->desired_tool_bar_string in the tool-bar window of frame F. */
7957 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
7958 it
.first_visible_x
= 0;
7959 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
7960 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
7962 while (!ITERATOR_AT_END_P (&it
))
7964 it
.glyph_row
= w
->desired_matrix
->rows
;
7965 clear_glyph_row (it
.glyph_row
);
7966 display_tool_bar_line (&it
);
7969 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
7973 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
7975 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
7984 frame
= selected_frame
;
7986 CHECK_FRAME (frame
);
7989 if (WINDOWP (f
->tool_bar_window
)
7990 || (w
= XWINDOW (f
->tool_bar_window
),
7991 XFASTINT (w
->height
) > 0))
7993 update_tool_bar (f
, 1);
7994 if (f
->n_tool_bar_items
)
7996 build_desired_tool_bar_string (f
);
7997 nlines
= tool_bar_lines_needed (f
);
8001 return make_number (nlines
);
8005 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8006 height should be changed. */
8009 redisplay_tool_bar (f
)
8014 struct glyph_row
*row
;
8015 int change_height_p
= 0;
8018 if (FRAME_EXTERNAL_TOOL_BAR(f
))
8019 update_frame_tool_bar (f
);
8023 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8024 do anything. This means you must start with tool-bar-lines
8025 non-zero to get the auto-sizing effect. Or in other words, you
8026 can turn off tool-bars by specifying tool-bar-lines zero. */
8027 if (!WINDOWP (f
->tool_bar_window
)
8028 || (w
= XWINDOW (f
->tool_bar_window
),
8029 XFASTINT (w
->height
) == 0))
8032 /* Set up an iterator for the tool-bar window. */
8033 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8034 it
.first_visible_x
= 0;
8035 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
8038 /* Build a string that represents the contents of the tool-bar. */
8039 build_desired_tool_bar_string (f
);
8040 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8042 /* Display as many lines as needed to display all tool-bar items. */
8043 while (it
.current_y
< it
.last_visible_y
)
8044 display_tool_bar_line (&it
);
8046 /* It doesn't make much sense to try scrolling in the tool-bar
8047 window, so don't do it. */
8048 w
->desired_matrix
->no_scrolling_p
= 1;
8049 w
->must_be_updated_p
= 1;
8051 if (auto_resize_tool_bars_p
)
8055 /* If we couldn't display everything, change the tool-bar's
8057 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8058 change_height_p
= 1;
8060 /* If there are blank lines at the end, except for a partially
8061 visible blank line at the end that is smaller than
8062 CANON_Y_UNIT, change the tool-bar's height. */
8063 row
= it
.glyph_row
- 1;
8064 if (!row
->displays_text_p
8065 && row
->height
>= CANON_Y_UNIT (f
))
8066 change_height_p
= 1;
8068 /* If row displays tool-bar items, but is partially visible,
8069 change the tool-bar's height. */
8070 if (row
->displays_text_p
8071 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8072 change_height_p
= 1;
8074 /* Resize windows as needed by changing the `tool-bar-lines'
8077 && (nlines
= tool_bar_lines_needed (f
),
8078 nlines
!= XFASTINT (w
->height
)))
8080 extern Lisp_Object Qtool_bar_lines
;
8082 int old_height
= XFASTINT (w
->height
);
8084 XSETFRAME (frame
, f
);
8085 clear_glyph_matrix (w
->desired_matrix
);
8086 Fmodify_frame_parameters (frame
,
8087 Fcons (Fcons (Qtool_bar_lines
,
8088 make_number (nlines
)),
8090 if (XFASTINT (w
->height
) != old_height
)
8091 fonts_changed_p
= 1;
8095 return change_height_p
;
8099 /* Get information about the tool-bar item which is displayed in GLYPH
8100 on frame F. Return in *PROP_IDX the index where tool-bar item
8101 properties start in F->tool_bar_items. Value is zero if
8102 GLYPH doesn't display a tool-bar item. */
8105 tool_bar_item_info (f
, glyph
, prop_idx
)
8107 struct glyph
*glyph
;
8114 /* This function can be called asynchronously, which means we must
8115 exclude any possibility that Fget_text_property signals an
8117 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8118 charpos
= max (0, charpos
);
8120 /* Get the text property `menu-item' at pos. The value of that
8121 property is the start index of this item's properties in
8122 F->tool_bar_items. */
8123 prop
= Fget_text_property (make_number (charpos
),
8124 Qmenu_item
, f
->current_tool_bar_string
);
8125 if (INTEGERP (prop
))
8127 *prop_idx
= XINT (prop
);
8136 #endif /* HAVE_WINDOW_SYSTEM */
8140 /***********************************************************************
8142 ***********************************************************************/
8144 #ifdef HAVE_WINDOW_SYSTEM
8146 /* An arrow like this: `<-'. */
8147 static unsigned char left_bits
[] = {
8148 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
8150 /* Right truncation arrow bitmap `->'. */
8151 static unsigned char right_bits
[] = {
8152 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
8154 /* Marker for continued lines. */
8155 static unsigned char continued_bits
[] = {
8156 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
8158 /* Marker for continuation lines. */
8159 static unsigned char continuation_bits
[] = {
8160 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
8162 /* Overlay arrow bitmap. A triangular arrow. */
8163 static unsigned char ov_bits
[] = {
8164 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
8166 /* Bitmap drawn to indicate lines not displaying text if
8167 `indicate-empty-lines' is non-nil. */
8168 static unsigned char zv_bits
[] = {
8169 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8170 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8171 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8172 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8173 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8174 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8175 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8176 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
8178 struct fringe_bitmap fringe_bitmaps
[MAX_FRINGE_BITMAPS
] =
8180 { 0, 0, 0, NULL
/* NO_FRINGE_BITMAP */ },
8181 { 8, sizeof (left_bits
), 0, left_bits
},
8182 { 8, sizeof (right_bits
), 0, right_bits
},
8183 { 8, sizeof (continued_bits
), 0, continued_bits
},
8184 { 8, sizeof (continuation_bits
), 0, continuation_bits
},
8185 { 8, sizeof (ov_bits
), 0, ov_bits
},
8186 { 8, sizeof (zv_bits
), 3, zv_bits
}
8190 /* Draw the bitmap WHICH in one of the left or right fringes of
8191 window W. ROW is the glyph row for which to display the bitmap; it
8192 determines the vertical position at which the bitmap has to be
8196 draw_fringe_bitmap (w
, row
, which
, left_p
)
8198 struct glyph_row
*row
;
8199 enum fringe_bitmap_type which
;
8202 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8203 struct draw_fringe_bitmap_params p
;
8205 /* Convert row to frame coordinates. */
8206 p
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8209 p
.wd
= fringe_bitmaps
[which
].width
;
8211 p
.h
= fringe_bitmaps
[which
].height
;
8212 p
.dh
= (fringe_bitmaps
[which
].period
8213 ? (p
.y
% fringe_bitmaps
[which
].period
)
8216 /* Clip bitmap if too high. */
8217 if (p
.h
> row
->height
)
8220 p
.face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
8221 PREPARE_FACE_FOR_DISPLAY (f
, p
.face
);
8223 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
8228 if (p
.wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
8229 p
.wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
8230 p
.x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
8232 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - p
.wd
) / 2);
8233 if (p
.wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> p
.h
)
8235 /* If W has a vertical border to its left, don't draw over it. */
8236 int border
= ((XFASTINT (w
->left
) > 0
8237 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8239 p
.bx
= (window_box_left (w
, -1)
8240 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
8242 p
.nx
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
8247 if (p
.wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
8248 p
.wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
8249 p
.x
= (window_box_right (w
, -1)
8250 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - p
.wd
) / 2);
8251 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
8253 if (p
.wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> p
.h
)
8255 p
.bx
= window_box_right (w
, -1);
8256 p
.nx
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
8262 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
8264 p
.by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, row
->y
));
8265 p
.ny
= row
->visible_height
;
8268 /* Adjust y to the offset in the row to start drawing the bitmap. */
8269 p
.y
+= (row
->height
- p
.h
) / 2;
8271 rif
->draw_fringe_bitmap (w
, row
, &p
);
8274 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
8275 function with input blocked. */
8278 draw_row_fringe_bitmaps (w
, row
)
8280 struct glyph_row
*row
;
8282 struct frame
*f
= XFRAME (w
->frame
);
8283 enum fringe_bitmap_type bitmap
;
8285 xassert (interrupt_input_blocked
);
8287 /* If row is completely invisible, because of vscrolling, we
8288 don't have to draw anything. */
8289 if (row
->visible_height
<= 0)
8292 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
8294 /* Decide which bitmap to draw in the left fringe. */
8295 if (row
->overlay_arrow_p
)
8296 bitmap
= OVERLAY_ARROW_BITMAP
;
8297 else if (row
->truncated_on_left_p
)
8298 bitmap
= LEFT_TRUNCATION_BITMAP
;
8299 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
8300 bitmap
= CONTINUATION_LINE_BITMAP
;
8301 else if (row
->indicate_empty_line_p
)
8302 bitmap
= ZV_LINE_BITMAP
;
8304 bitmap
= NO_FRINGE_BITMAP
;
8306 draw_fringe_bitmap (w
, row
, bitmap
, 1);
8309 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
8311 /* Decide which bitmap to draw in the right fringe. */
8312 if (row
->truncated_on_right_p
)
8313 bitmap
= RIGHT_TRUNCATION_BITMAP
;
8314 else if (row
->continued_p
)
8315 bitmap
= CONTINUED_LINE_BITMAP
;
8316 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
8317 bitmap
= ZV_LINE_BITMAP
;
8319 bitmap
= NO_FRINGE_BITMAP
;
8321 draw_fringe_bitmap (w
, row
, bitmap
, 0);
8326 /* Compute actual fringe widths */
8329 compute_fringe_widths (f
, redraw
)
8333 int o_left
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
8334 int o_right
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
8335 int o_cols
= FRAME_X_FRINGE_COLS (f
);
8337 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
8338 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
8339 int left_fringe_width
, right_fringe_width
;
8341 if (!NILP (left_fringe
))
8342 left_fringe
= Fcdr (left_fringe
);
8343 if (!NILP (right_fringe
))
8344 right_fringe
= Fcdr (right_fringe
);
8346 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
8347 XINT (left_fringe
));
8348 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
8349 XINT (right_fringe
));
8351 if (left_fringe_width
|| right_fringe_width
)
8353 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
8354 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
8355 int conf_wid
= left_wid
+ right_wid
;
8356 int font_wid
= FONT_WIDTH (FRAME_FONT (f
));
8357 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
8358 int real_wid
= cols
* font_wid
;
8359 if (left_wid
&& right_wid
)
8361 if (left_fringe_width
< 0)
8363 /* Left fringe width is fixed, adjust right fringe if necessary */
8364 FRAME_X_LEFT_FRINGE_WIDTH (f
) = left_wid
;
8365 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = real_wid
- left_wid
;
8367 else if (right_fringe_width
< 0)
8369 /* Right fringe width is fixed, adjust left fringe if necessary */
8370 FRAME_X_LEFT_FRINGE_WIDTH (f
) = real_wid
- right_wid
;
8371 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = right_wid
;
8375 /* Adjust both fringes with an equal amount.
8376 Note that we are doing integer arithmetic here, so don't
8377 lose a pixel if the total width is an odd number. */
8378 int fill
= real_wid
- conf_wid
;
8379 FRAME_X_LEFT_FRINGE_WIDTH (f
) = left_wid
+ fill
/2;
8380 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = right_wid
+ fill
- fill
/2;
8383 else if (left_fringe_width
)
8385 FRAME_X_LEFT_FRINGE_WIDTH (f
) = real_wid
;
8386 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = 0;
8390 FRAME_X_LEFT_FRINGE_WIDTH (f
) = 0;
8391 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = real_wid
;
8393 FRAME_X_FRINGE_COLS (f
) = cols
;
8394 FRAME_X_FRINGE_WIDTH (f
) = real_wid
;
8398 FRAME_X_LEFT_FRINGE_WIDTH (f
) = 0;
8399 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = 0;
8400 FRAME_X_FRINGE_COLS (f
) = 0;
8401 FRAME_X_FRINGE_WIDTH (f
) = 0;
8404 if (redraw
&& FRAME_VISIBLE_P (f
))
8405 if (o_left
!= FRAME_X_LEFT_FRINGE_WIDTH (f
) ||
8406 o_right
!= FRAME_X_RIGHT_FRINGE_WIDTH (f
) ||
8407 o_cols
!= FRAME_X_FRINGE_COLS (f
))
8411 #endif /* HAVE_WINDOW_SYSTEM */
8415 /************************************************************************
8416 Horizontal scrolling
8417 ************************************************************************/
8419 static int hscroll_window_tree
P_ ((Lisp_Object
));
8420 static int hscroll_windows
P_ ((Lisp_Object
));
8422 /* For all leaf windows in the window tree rooted at WINDOW, set their
8423 hscroll value so that PT is (i) visible in the window, and (ii) so
8424 that it is not within a certain margin at the window's left and
8425 right border. Value is non-zero if any window's hscroll has been
8429 hscroll_window_tree (window
)
8432 int hscrolled_p
= 0;
8433 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
8434 int hscroll_step_abs
= 0;
8435 double hscroll_step_rel
= 0;
8437 if (hscroll_relative_p
)
8439 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
8440 if (hscroll_step_rel
< 0)
8442 hscroll_relative_p
= 0;
8443 hscroll_step_abs
= 0;
8446 else if (INTEGERP (Vhscroll_step
))
8448 hscroll_step_abs
= XINT (Vhscroll_step
);
8449 if (hscroll_step_abs
< 0)
8450 hscroll_step_abs
= 0;
8453 hscroll_step_abs
= 0;
8455 while (WINDOWP (window
))
8457 struct window
*w
= XWINDOW (window
);
8459 if (WINDOWP (w
->hchild
))
8460 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
8461 else if (WINDOWP (w
->vchild
))
8462 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
8463 else if (w
->cursor
.vpos
>= 0)
8465 int h_margin
, text_area_x
, text_area_y
;
8466 int text_area_width
, text_area_height
;
8467 struct glyph_row
*current_cursor_row
8468 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
8469 struct glyph_row
*desired_cursor_row
8470 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
8471 struct glyph_row
*cursor_row
8472 = (desired_cursor_row
->enabled_p
8473 ? desired_cursor_row
8474 : current_cursor_row
);
8476 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
8477 &text_area_width
, &text_area_height
);
8479 /* Scroll when cursor is inside this scroll margin. */
8480 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
8482 if ((XFASTINT (w
->hscroll
)
8483 && w
->cursor
.x
<= h_margin
)
8484 || (cursor_row
->enabled_p
8485 && cursor_row
->truncated_on_right_p
8486 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
8490 struct buffer
*saved_current_buffer
;
8494 /* Find point in a display of infinite width. */
8495 saved_current_buffer
= current_buffer
;
8496 current_buffer
= XBUFFER (w
->buffer
);
8498 if (w
== XWINDOW (selected_window
))
8499 pt
= BUF_PT (current_buffer
);
8502 pt
= marker_position (w
->pointm
);
8503 pt
= max (BEGV
, pt
);
8507 /* Move iterator to pt starting at cursor_row->start in
8508 a line with infinite width. */
8509 init_to_row_start (&it
, w
, cursor_row
);
8510 it
.last_visible_x
= INFINITY
;
8511 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
8512 current_buffer
= saved_current_buffer
;
8514 /* Position cursor in window. */
8515 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
8516 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
8517 / CANON_X_UNIT (it
.f
);
8518 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
8520 if (hscroll_relative_p
)
8521 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
8524 wanted_x
= text_area_width
8525 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8528 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8532 if (hscroll_relative_p
)
8533 wanted_x
= text_area_width
* hscroll_step_rel
8536 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
8539 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
8541 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
8543 /* Don't call Fset_window_hscroll if value hasn't
8544 changed because it will prevent redisplay
8546 if (XFASTINT (w
->hscroll
) != hscroll
)
8548 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
8549 w
->hscroll
= make_number (hscroll
);
8558 /* Value is non-zero if hscroll of any leaf window has been changed. */
8563 /* Set hscroll so that cursor is visible and not inside horizontal
8564 scroll margins for all windows in the tree rooted at WINDOW. See
8565 also hscroll_window_tree above. Value is non-zero if any window's
8566 hscroll has been changed. If it has, desired matrices on the frame
8567 of WINDOW are cleared. */
8570 hscroll_windows (window
)
8575 if (automatic_hscrolling_p
)
8577 hscrolled_p
= hscroll_window_tree (window
);
8579 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
8588 /************************************************************************
8590 ************************************************************************/
8592 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
8593 to a non-zero value. This is sometimes handy to have in a debugger
8598 /* First and last unchanged row for try_window_id. */
8600 int debug_first_unchanged_at_end_vpos
;
8601 int debug_last_unchanged_at_beg_vpos
;
8603 /* Delta vpos and y. */
8605 int debug_dvpos
, debug_dy
;
8607 /* Delta in characters and bytes for try_window_id. */
8609 int debug_delta
, debug_delta_bytes
;
8611 /* Values of window_end_pos and window_end_vpos at the end of
8614 EMACS_INT debug_end_pos
, debug_end_vpos
;
8616 /* Append a string to W->desired_matrix->method. FMT is a printf
8617 format string. A1...A9 are a supplement for a variable-length
8618 argument list. If trace_redisplay_p is non-zero also printf the
8619 resulting string to stderr. */
8622 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
8625 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
8628 char *method
= w
->desired_matrix
->method
;
8629 int len
= strlen (method
);
8630 int size
= sizeof w
->desired_matrix
->method
;
8631 int remaining
= size
- len
- 1;
8633 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
8634 if (len
&& remaining
)
8640 strncpy (method
+ len
, buffer
, remaining
);
8642 if (trace_redisplay_p
)
8643 fprintf (stderr
, "%p (%s): %s\n",
8645 ((BUFFERP (w
->buffer
)
8646 && STRINGP (XBUFFER (w
->buffer
)->name
))
8647 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
8652 #endif /* GLYPH_DEBUG */
8655 /* Value is non-zero if all changes in window W, which displays
8656 current_buffer, are in the text between START and END. START is a
8657 buffer position, END is given as a distance from Z. Used in
8658 redisplay_internal for display optimization. */
8661 text_outside_line_unchanged_p (w
, start
, end
)
8665 int unchanged_p
= 1;
8667 /* If text or overlays have changed, see where. */
8668 if (XFASTINT (w
->last_modified
) < MODIFF
8669 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
8671 /* Gap in the line? */
8672 if (GPT
< start
|| Z
- GPT
< end
)
8675 /* Changes start in front of the line, or end after it? */
8677 && (BEG_UNCHANGED
< start
- 1
8678 || END_UNCHANGED
< end
))
8681 /* If selective display, can't optimize if changes start at the
8682 beginning of the line. */
8684 && INTEGERP (current_buffer
->selective_display
)
8685 && XINT (current_buffer
->selective_display
) > 0
8686 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
8689 /* If there are overlays at the start or end of the line, these
8690 may have overlay strings with newlines in them. A change at
8691 START, for instance, may actually concern the display of such
8692 overlay strings as well, and they are displayed on different
8693 lines. So, quickly rule out this case. (For the future, it
8694 might be desirable to implement something more telling than
8695 just BEG/END_UNCHANGED.) */
8698 if (BEG
+ BEG_UNCHANGED
== start
8699 && overlay_touches_p (start
))
8701 if (END_UNCHANGED
== end
8702 && overlay_touches_p (Z
- end
))
8711 /* Do a frame update, taking possible shortcuts into account. This is
8712 the main external entry point for redisplay.
8714 If the last redisplay displayed an echo area message and that message
8715 is no longer requested, we clear the echo area or bring back the
8716 mini-buffer if that is in use. */
8721 redisplay_internal (0);
8725 /* Return 1 if point moved out of or into a composition. Otherwise
8726 return 0. PREV_BUF and PREV_PT are the last point buffer and
8727 position. BUF and PT are the current point buffer and position. */
8730 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
8731 struct buffer
*prev_buf
, *buf
;
8738 XSETBUFFER (buffer
, buf
);
8739 /* Check a composition at the last point if point moved within the
8741 if (prev_buf
== buf
)
8744 /* Point didn't move. */
8747 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
8748 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
8749 && COMPOSITION_VALID_P (start
, end
, prop
)
8750 && start
< prev_pt
&& end
> prev_pt
)
8751 /* The last point was within the composition. Return 1 iff
8752 point moved out of the composition. */
8753 return (pt
<= start
|| pt
>= end
);
8756 /* Check a composition at the current point. */
8757 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
8758 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
8759 && COMPOSITION_VALID_P (start
, end
, prop
)
8760 && start
< pt
&& end
> pt
);
8764 /* Reconsider the setting of B->clip_changed which is displayed
8768 reconsider_clip_changes (w
, b
)
8773 && !NILP (w
->window_end_valid
)
8774 && w
->current_matrix
->buffer
== b
8775 && w
->current_matrix
->zv
== BUF_ZV (b
)
8776 && w
->current_matrix
->begv
== BUF_BEGV (b
))
8777 b
->clip_changed
= 0;
8779 /* If display wasn't paused, and W is not a tool bar window, see if
8780 point has been moved into or out of a composition. In that case,
8781 we set b->clip_changed to 1 to force updating the screen. If
8782 b->clip_changed has already been set to 1, we can skip this
8784 if (!b
->clip_changed
8785 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
8789 if (w
== XWINDOW (selected_window
))
8790 pt
= BUF_PT (current_buffer
);
8792 pt
= marker_position (w
->pointm
);
8794 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
8795 || pt
!= XINT (w
->last_point
))
8796 && check_point_in_composition (w
->current_matrix
->buffer
,
8797 XINT (w
->last_point
),
8798 XBUFFER (w
->buffer
), pt
))
8799 b
->clip_changed
= 1;
8803 #define STOP_POLLING \
8804 do { if (! polling_stopped_here) stop_polling (); \
8805 polling_stopped_here = 1; } while (0)
8807 #define RESUME_POLLING \
8808 do { if (polling_stopped_here) start_polling (); \
8809 polling_stopped_here = 0; } while (0)
8812 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
8813 response to any user action; therefore, we should preserve the echo
8814 area. (Actually, our caller does that job.) Perhaps in the future
8815 avoid recentering windows if it is not necessary; currently that
8816 causes some problems. */
8819 redisplay_internal (preserve_echo_area
)
8820 int preserve_echo_area
;
8822 struct window
*w
= XWINDOW (selected_window
);
8823 struct frame
*f
= XFRAME (w
->frame
);
8825 int must_finish
= 0;
8826 struct text_pos tlbufpos
, tlendpos
;
8827 int number_of_visible_frames
;
8829 struct frame
*sf
= SELECTED_FRAME ();
8830 int polling_stopped_here
= 0;
8832 /* Non-zero means redisplay has to consider all windows on all
8833 frames. Zero means, only selected_window is considered. */
8834 int consider_all_windows_p
;
8836 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
8838 /* No redisplay if running in batch mode or frame is not yet fully
8839 initialized, or redisplay is explicitly turned off by setting
8840 Vinhibit_redisplay. */
8842 || !NILP (Vinhibit_redisplay
)
8843 || !f
->glyphs_initialized_p
)
8846 /* The flag redisplay_performed_directly_p is set by
8847 direct_output_for_insert when it already did the whole screen
8848 update necessary. */
8849 if (redisplay_performed_directly_p
)
8851 redisplay_performed_directly_p
= 0;
8852 if (!hscroll_windows (selected_window
))
8856 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8857 if (popup_activated ())
8861 /* I don't think this happens but let's be paranoid. */
8865 /* Record a function that resets redisplaying_p to its old value
8866 when we leave this function. */
8867 count
= SPECPDL_INDEX ();
8868 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
8870 specbind (Qinhibit_free_realized_faces
, Qnil
);
8874 reconsider_clip_changes (w
, current_buffer
);
8876 /* If new fonts have been loaded that make a glyph matrix adjustment
8877 necessary, do it. */
8878 if (fonts_changed_p
)
8880 adjust_glyphs (NULL
);
8881 ++windows_or_buffers_changed
;
8882 fonts_changed_p
= 0;
8885 /* If face_change_count is non-zero, init_iterator will free all
8886 realized faces, which includes the faces referenced from current
8887 matrices. So, we can't reuse current matrices in this case. */
8888 if (face_change_count
)
8889 ++windows_or_buffers_changed
;
8891 if (! FRAME_WINDOW_P (sf
)
8892 && previous_terminal_frame
!= sf
)
8894 /* Since frames on an ASCII terminal share the same display
8895 area, displaying a different frame means redisplay the whole
8897 windows_or_buffers_changed
++;
8898 SET_FRAME_GARBAGED (sf
);
8899 XSETFRAME (Vterminal_frame
, sf
);
8901 previous_terminal_frame
= sf
;
8903 /* Set the visible flags for all frames. Do this before checking
8904 for resized or garbaged frames; they want to know if their frames
8905 are visible. See the comment in frame.h for
8906 FRAME_SAMPLE_VISIBILITY. */
8908 Lisp_Object tail
, frame
;
8910 number_of_visible_frames
= 0;
8912 FOR_EACH_FRAME (tail
, frame
)
8914 struct frame
*f
= XFRAME (frame
);
8916 FRAME_SAMPLE_VISIBILITY (f
);
8917 if (FRAME_VISIBLE_P (f
))
8918 ++number_of_visible_frames
;
8919 clear_desired_matrices (f
);
8923 /* Notice any pending interrupt request to change frame size. */
8924 do_pending_window_change (1);
8926 /* Clear frames marked as garbaged. */
8928 clear_garbaged_frames ();
8930 /* Build menubar and tool-bar items. */
8931 prepare_menu_bars ();
8933 if (windows_or_buffers_changed
)
8934 update_mode_lines
++;
8936 /* Detect case that we need to write or remove a star in the mode line. */
8937 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
8939 w
->update_mode_line
= Qt
;
8940 if (buffer_shared
> 1)
8941 update_mode_lines
++;
8944 /* If %c is in the mode line, update it if needed. */
8945 if (!NILP (w
->column_number_displayed
)
8946 /* This alternative quickly identifies a common case
8947 where no change is needed. */
8948 && !(PT
== XFASTINT (w
->last_point
)
8949 && XFASTINT (w
->last_modified
) >= MODIFF
8950 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8951 && (XFASTINT (w
->column_number_displayed
)
8952 != (int) current_column ())) /* iftc */
8953 w
->update_mode_line
= Qt
;
8955 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
8957 /* The variable buffer_shared is set in redisplay_window and
8958 indicates that we redisplay a buffer in different windows. See
8960 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
8961 || cursor_type_changed
);
8963 /* If specs for an arrow have changed, do thorough redisplay
8964 to ensure we remove any arrow that should no longer exist. */
8965 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
8966 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
8967 consider_all_windows_p
= windows_or_buffers_changed
= 1;
8969 /* Normally the message* functions will have already displayed and
8970 updated the echo area, but the frame may have been trashed, or
8971 the update may have been preempted, so display the echo area
8972 again here. Checking message_cleared_p captures the case that
8973 the echo area should be cleared. */
8974 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
8975 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
8976 || (message_cleared_p
8977 && minibuf_level
== 0
8978 /* If the mini-window is currently selected, this means the
8979 echo-area doesn't show through. */
8980 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
8982 int window_height_changed_p
= echo_area_display (0);
8985 /* If we don't display the current message, don't clear the
8986 message_cleared_p flag, because, if we did, we wouldn't clear
8987 the echo area in the next redisplay which doesn't preserve
8989 if (!display_last_displayed_message_p
)
8990 message_cleared_p
= 0;
8992 if (fonts_changed_p
)
8994 else if (window_height_changed_p
)
8996 consider_all_windows_p
= 1;
8997 ++update_mode_lines
;
8998 ++windows_or_buffers_changed
;
9000 /* If window configuration was changed, frames may have been
9001 marked garbaged. Clear them or we will experience
9002 surprises wrt scrolling. */
9004 clear_garbaged_frames ();
9007 else if (EQ (selected_window
, minibuf_window
)
9008 && (current_buffer
->clip_changed
9009 || XFASTINT (w
->last_modified
) < MODIFF
9010 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9011 && resize_mini_window (w
, 0))
9013 /* Resized active mini-window to fit the size of what it is
9014 showing if its contents might have changed. */
9016 consider_all_windows_p
= 1;
9017 ++windows_or_buffers_changed
;
9018 ++update_mode_lines
;
9020 /* If window configuration was changed, frames may have been
9021 marked garbaged. Clear them or we will experience
9022 surprises wrt scrolling. */
9024 clear_garbaged_frames ();
9028 /* If showing the region, and mark has changed, we must redisplay
9029 the whole window. The assignment to this_line_start_pos prevents
9030 the optimization directly below this if-statement. */
9031 if (((!NILP (Vtransient_mark_mode
)
9032 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9033 != !NILP (w
->region_showing
))
9034 || (!NILP (w
->region_showing
)
9035 && !EQ (w
->region_showing
,
9036 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9037 CHARPOS (this_line_start_pos
) = 0;
9039 /* Optimize the case that only the line containing the cursor in the
9040 selected window has changed. Variables starting with this_ are
9041 set in display_line and record information about the line
9042 containing the cursor. */
9043 tlbufpos
= this_line_start_pos
;
9044 tlendpos
= this_line_end_pos
;
9045 if (!consider_all_windows_p
9046 && CHARPOS (tlbufpos
) > 0
9047 && NILP (w
->update_mode_line
)
9048 && !current_buffer
->clip_changed
9049 && !current_buffer
->prevent_redisplay_optimizations_p
9050 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9051 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9052 /* Make sure recorded data applies to current buffer, etc. */
9053 && this_line_buffer
== current_buffer
9054 && current_buffer
== XBUFFER (w
->buffer
)
9055 && NILP (w
->force_start
)
9056 && NILP (w
->optional_new_start
)
9057 /* Point must be on the line that we have info recorded about. */
9058 && PT
>= CHARPOS (tlbufpos
)
9059 && PT
<= Z
- CHARPOS (tlendpos
)
9060 /* All text outside that line, including its final newline,
9061 must be unchanged */
9062 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9063 CHARPOS (tlendpos
)))
9065 if (CHARPOS (tlbufpos
) > BEGV
9066 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9067 && (CHARPOS (tlbufpos
) == ZV
9068 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9069 /* Former continuation line has disappeared by becoming empty */
9071 else if (XFASTINT (w
->last_modified
) < MODIFF
9072 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9073 || MINI_WINDOW_P (w
))
9075 /* We have to handle the case of continuation around a
9076 wide-column character (See the comment in indent.c around
9079 For instance, in the following case:
9081 -------- Insert --------
9082 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9083 J_I_ ==> J_I_ `^^' are cursors.
9087 As we have to redraw the line above, we should goto cancel. */
9090 int line_height_before
= this_line_pixel_height
;
9092 /* Note that start_display will handle the case that the
9093 line starting at tlbufpos is a continuation lines. */
9094 start_display (&it
, w
, tlbufpos
);
9096 /* Implementation note: It this still necessary? */
9097 if (it
.current_x
!= this_line_start_x
)
9100 TRACE ((stderr
, "trying display optimization 1\n"));
9101 w
->cursor
.vpos
= -1;
9102 overlay_arrow_seen
= 0;
9103 it
.vpos
= this_line_vpos
;
9104 it
.current_y
= this_line_y
;
9105 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9108 /* If line contains point, is not continued,
9109 and ends at same distance from eob as before, we win */
9110 if (w
->cursor
.vpos
>= 0
9111 /* Line is not continued, otherwise this_line_start_pos
9112 would have been set to 0 in display_line. */
9113 && CHARPOS (this_line_start_pos
)
9114 /* Line ends as before. */
9115 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9116 /* Line has same height as before. Otherwise other lines
9117 would have to be shifted up or down. */
9118 && this_line_pixel_height
== line_height_before
)
9120 /* If this is not the window's last line, we must adjust
9121 the charstarts of the lines below. */
9122 if (it
.current_y
< it
.last_visible_y
)
9124 struct glyph_row
*row
9125 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9126 int delta
, delta_bytes
;
9128 if (Z
- CHARPOS (tlendpos
) == ZV
)
9130 /* This line ends at end of (accessible part of)
9131 buffer. There is no newline to count. */
9133 - CHARPOS (tlendpos
)
9134 - MATRIX_ROW_START_CHARPOS (row
));
9135 delta_bytes
= (Z_BYTE
9136 - BYTEPOS (tlendpos
)
9137 - MATRIX_ROW_START_BYTEPOS (row
));
9141 /* This line ends in a newline. Must take
9142 account of the newline and the rest of the
9143 text that follows. */
9145 - CHARPOS (tlendpos
)
9146 - MATRIX_ROW_START_CHARPOS (row
));
9147 delta_bytes
= (Z_BYTE
9148 - BYTEPOS (tlendpos
)
9149 - MATRIX_ROW_START_BYTEPOS (row
));
9152 increment_matrix_positions (w
->current_matrix
,
9154 w
->current_matrix
->nrows
,
9155 delta
, delta_bytes
);
9158 /* If this row displays text now but previously didn't,
9159 or vice versa, w->window_end_vpos may have to be
9161 if ((it
.glyph_row
- 1)->displays_text_p
)
9163 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
9164 XSETINT (w
->window_end_vpos
, this_line_vpos
);
9166 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
9167 && this_line_vpos
> 0)
9168 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
9169 w
->window_end_valid
= Qnil
;
9171 /* Update hint: No need to try to scroll in update_window. */
9172 w
->desired_matrix
->no_scrolling_p
= 1;
9175 *w
->desired_matrix
->method
= 0;
9176 debug_method_add (w
, "optimization 1");
9183 else if (/* Cursor position hasn't changed. */
9184 PT
== XFASTINT (w
->last_point
)
9185 /* Make sure the cursor was last displayed
9186 in this window. Otherwise we have to reposition it. */
9187 && 0 <= w
->cursor
.vpos
9188 && XINT (w
->height
) > w
->cursor
.vpos
)
9192 do_pending_window_change (1);
9194 /* We used to always goto end_of_redisplay here, but this
9195 isn't enough if we have a blinking cursor. */
9196 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
9197 goto end_of_redisplay
;
9201 /* If highlighting the region, or if the cursor is in the echo area,
9202 then we can't just move the cursor. */
9203 else if (! (!NILP (Vtransient_mark_mode
)
9204 && !NILP (current_buffer
->mark_active
))
9205 && (EQ (selected_window
, current_buffer
->last_selected_window
)
9206 || highlight_nonselected_windows
)
9207 && NILP (w
->region_showing
)
9208 && NILP (Vshow_trailing_whitespace
)
9209 && !cursor_in_echo_area
)
9212 struct glyph_row
*row
;
9214 /* Skip from tlbufpos to PT and see where it is. Note that
9215 PT may be in invisible text. If so, we will end at the
9216 next visible position. */
9217 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
9218 NULL
, DEFAULT_FACE_ID
);
9219 it
.current_x
= this_line_start_x
;
9220 it
.current_y
= this_line_y
;
9221 it
.vpos
= this_line_vpos
;
9223 /* The call to move_it_to stops in front of PT, but
9224 moves over before-strings. */
9225 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
9227 if (it
.vpos
== this_line_vpos
9228 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
9231 xassert (this_line_vpos
== it
.vpos
);
9232 xassert (this_line_y
== it
.current_y
);
9233 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9235 *w
->desired_matrix
->method
= 0;
9236 debug_method_add (w
, "optimization 3");
9245 /* Text changed drastically or point moved off of line. */
9246 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
9249 CHARPOS (this_line_start_pos
) = 0;
9250 consider_all_windows_p
|= buffer_shared
> 1;
9251 ++clear_face_cache_count
;
9254 /* Build desired matrices, and update the display. If
9255 consider_all_windows_p is non-zero, do it for all windows on all
9256 frames. Otherwise do it for selected_window, only. */
9258 if (consider_all_windows_p
)
9260 Lisp_Object tail
, frame
;
9261 int i
, n
= 0, size
= 50;
9262 struct frame
**updated
9263 = (struct frame
**) alloca (size
* sizeof *updated
);
9265 /* Clear the face cache eventually. */
9266 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
9268 clear_face_cache (0);
9269 clear_face_cache_count
= 0;
9272 /* Recompute # windows showing selected buffer. This will be
9273 incremented each time such a window is displayed. */
9276 FOR_EACH_FRAME (tail
, frame
)
9278 struct frame
*f
= XFRAME (frame
);
9280 if (FRAME_WINDOW_P (f
) || f
== sf
)
9282 #ifdef HAVE_WINDOW_SYSTEM
9283 if (clear_face_cache_count
% 50 == 0
9284 && FRAME_WINDOW_P (f
))
9285 clear_image_cache (f
, 0);
9286 #endif /* HAVE_WINDOW_SYSTEM */
9288 /* Mark all the scroll bars to be removed; we'll redeem
9289 the ones we want when we redisplay their windows. */
9290 if (condemn_scroll_bars_hook
)
9291 condemn_scroll_bars_hook (f
);
9293 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9294 redisplay_windows (FRAME_ROOT_WINDOW (f
));
9296 /* Any scroll bars which redisplay_windows should have
9297 nuked should now go away. */
9298 if (judge_scroll_bars_hook
)
9299 judge_scroll_bars_hook (f
);
9301 /* If fonts changed, display again. */
9302 /* ??? rms: I suspect it is a mistake to jump all the way
9303 back to retry here. It should just retry this frame. */
9304 if (fonts_changed_p
)
9307 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9309 /* See if we have to hscroll. */
9310 if (hscroll_windows (f
->root_window
))
9313 /* Prevent various kinds of signals during display
9314 update. stdio is not robust about handling
9315 signals, which can cause an apparent I/O
9317 if (interrupt_input
)
9321 /* Update the display. */
9322 set_window_update_flags (XWINDOW (f
->root_window
), 1);
9323 pause
|= update_frame (f
, 0, 0);
9329 int nbytes
= size
* sizeof *updated
;
9330 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
9331 bcopy (updated
, p
, nbytes
);
9340 /* Do the mark_window_display_accurate after all windows have
9341 been redisplayed because this call resets flags in buffers
9342 which are needed for proper redisplay. */
9343 for (i
= 0; i
< n
; ++i
)
9345 struct frame
*f
= updated
[i
];
9346 mark_window_display_accurate (f
->root_window
, 1);
9347 if (frame_up_to_date_hook
)
9348 frame_up_to_date_hook (f
);
9351 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9353 Lisp_Object mini_window
;
9354 struct frame
*mini_frame
;
9356 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
9357 /* Use list_of_error, not Qerror, so that
9358 we catch only errors and don't run the debugger. */
9359 internal_condition_case_1 (redisplay_window_1
, selected_window
,
9361 redisplay_window_error
);
9363 /* Compare desired and current matrices, perform output. */
9366 /* If fonts changed, display again. */
9367 if (fonts_changed_p
)
9370 /* Prevent various kinds of signals during display update.
9371 stdio is not robust about handling signals,
9372 which can cause an apparent I/O error. */
9373 if (interrupt_input
)
9377 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
9379 if (hscroll_windows (selected_window
))
9382 XWINDOW (selected_window
)->must_be_updated_p
= 1;
9383 pause
= update_frame (sf
, 0, 0);
9386 /* We may have called echo_area_display at the top of this
9387 function. If the echo area is on another frame, that may
9388 have put text on a frame other than the selected one, so the
9389 above call to update_frame would not have caught it. Catch
9391 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9392 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9394 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
9396 XWINDOW (mini_window
)->must_be_updated_p
= 1;
9397 pause
|= update_frame (mini_frame
, 0, 0);
9398 if (!pause
&& hscroll_windows (mini_window
))
9403 /* If display was paused because of pending input, make sure we do a
9404 thorough update the next time. */
9407 /* Prevent the optimization at the beginning of
9408 redisplay_internal that tries a single-line update of the
9409 line containing the cursor in the selected window. */
9410 CHARPOS (this_line_start_pos
) = 0;
9412 /* Let the overlay arrow be updated the next time. */
9413 if (!NILP (last_arrow_position
))
9415 last_arrow_position
= Qt
;
9416 last_arrow_string
= Qt
;
9419 /* If we pause after scrolling, some rows in the current
9420 matrices of some windows are not valid. */
9421 if (!WINDOW_FULL_WIDTH_P (w
)
9422 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
9423 update_mode_lines
= 1;
9427 if (!consider_all_windows_p
)
9429 /* This has already been done above if
9430 consider_all_windows_p is set. */
9431 mark_window_display_accurate_1 (w
, 1);
9433 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9434 last_arrow_string
= Voverlay_arrow_string
;
9436 if (frame_up_to_date_hook
!= 0)
9437 frame_up_to_date_hook (sf
);
9440 update_mode_lines
= 0;
9441 windows_or_buffers_changed
= 0;
9442 cursor_type_changed
= 0;
9445 /* Start SIGIO interrupts coming again. Having them off during the
9446 code above makes it less likely one will discard output, but not
9447 impossible, since there might be stuff in the system buffer here.
9448 But it is much hairier to try to do anything about that. */
9449 if (interrupt_input
)
9453 /* If a frame has become visible which was not before, redisplay
9454 again, so that we display it. Expose events for such a frame
9455 (which it gets when becoming visible) don't call the parts of
9456 redisplay constructing glyphs, so simply exposing a frame won't
9457 display anything in this case. So, we have to display these
9458 frames here explicitly. */
9461 Lisp_Object tail
, frame
;
9464 FOR_EACH_FRAME (tail
, frame
)
9466 int this_is_visible
= 0;
9468 if (XFRAME (frame
)->visible
)
9469 this_is_visible
= 1;
9470 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
9471 if (XFRAME (frame
)->visible
)
9472 this_is_visible
= 1;
9474 if (this_is_visible
)
9478 if (new_count
!= number_of_visible_frames
)
9479 windows_or_buffers_changed
++;
9482 /* Change frame size now if a change is pending. */
9483 do_pending_window_change (1);
9485 /* If we just did a pending size change, or have additional
9486 visible frames, redisplay again. */
9487 if (windows_or_buffers_changed
&& !pause
)
9491 unbind_to (count
, Qnil
);
9496 /* Redisplay, but leave alone any recent echo area message unless
9497 another message has been requested in its place.
9499 This is useful in situations where you need to redisplay but no
9500 user action has occurred, making it inappropriate for the message
9501 area to be cleared. See tracking_off and
9502 wait_reading_process_input for examples of these situations.
9504 FROM_WHERE is an integer saying from where this function was
9505 called. This is useful for debugging. */
9508 redisplay_preserve_echo_area (from_where
)
9511 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
9513 if (!NILP (echo_area_buffer
[1]))
9515 /* We have a previously displayed message, but no current
9516 message. Redisplay the previous message. */
9517 display_last_displayed_message_p
= 1;
9518 redisplay_internal (1);
9519 display_last_displayed_message_p
= 0;
9522 redisplay_internal (1);
9526 /* Function registered with record_unwind_protect in
9527 redisplay_internal. Reset redisplaying_p to the value it had
9528 before redisplay_internal was called, and clear
9529 prevent_freeing_realized_faces_p. */
9532 unwind_redisplay (old_redisplaying_p
)
9533 Lisp_Object old_redisplaying_p
;
9535 redisplaying_p
= XFASTINT (old_redisplaying_p
);
9540 /* Mark the display of window W as accurate or inaccurate. If
9541 ACCURATE_P is non-zero mark display of W as accurate. If
9542 ACCURATE_P is zero, arrange for W to be redisplayed the next time
9543 redisplay_internal is called. */
9546 mark_window_display_accurate_1 (w
, accurate_p
)
9550 if (BUFFERP (w
->buffer
))
9552 struct buffer
*b
= XBUFFER (w
->buffer
);
9555 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
9556 w
->last_overlay_modified
9557 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
9559 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
9563 b
->clip_changed
= 0;
9564 b
->prevent_redisplay_optimizations_p
= 0;
9566 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
9567 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
9568 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
9569 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
9571 w
->current_matrix
->buffer
= b
;
9572 w
->current_matrix
->begv
= BUF_BEGV (b
);
9573 w
->current_matrix
->zv
= BUF_ZV (b
);
9575 w
->last_cursor
= w
->cursor
;
9576 w
->last_cursor_off_p
= w
->cursor_off_p
;
9578 if (w
== XWINDOW (selected_window
))
9579 w
->last_point
= make_number (BUF_PT (b
));
9581 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
9587 w
->window_end_valid
= w
->buffer
;
9588 #if 0 /* This is incorrect with variable-height lines. */
9589 xassert (XINT (w
->window_end_vpos
)
9591 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
9593 w
->update_mode_line
= Qnil
;
9598 /* Mark the display of windows in the window tree rooted at WINDOW as
9599 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
9600 windows as accurate. If ACCURATE_P is zero, arrange for windows to
9601 be redisplayed the next time redisplay_internal is called. */
9604 mark_window_display_accurate (window
, accurate_p
)
9610 for (; !NILP (window
); window
= w
->next
)
9612 w
= XWINDOW (window
);
9613 mark_window_display_accurate_1 (w
, accurate_p
);
9615 if (!NILP (w
->vchild
))
9616 mark_window_display_accurate (w
->vchild
, accurate_p
);
9617 if (!NILP (w
->hchild
))
9618 mark_window_display_accurate (w
->hchild
, accurate_p
);
9623 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
9624 last_arrow_string
= Voverlay_arrow_string
;
9628 /* Force a thorough redisplay the next time by setting
9629 last_arrow_position and last_arrow_string to t, which is
9630 unequal to any useful value of Voverlay_arrow_... */
9631 last_arrow_position
= Qt
;
9632 last_arrow_string
= Qt
;
9637 /* Return value in display table DP (Lisp_Char_Table *) for character
9638 C. Since a display table doesn't have any parent, we don't have to
9639 follow parent. Do not call this function directly but use the
9640 macro DISP_CHAR_VECTOR. */
9643 disp_char_vector (dp
, c
)
9644 struct Lisp_Char_Table
*dp
;
9650 if (SINGLE_BYTE_CHAR_P (c
))
9651 return (dp
->contents
[c
]);
9653 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
9656 else if (code
[2] < 32)
9659 /* Here, the possible range of code[0] (== charset ID) is
9660 128..max_charset. Since the top level char table contains data
9661 for multibyte characters after 256th element, we must increment
9662 code[0] by 128 to get a correct index. */
9664 code
[3] = -1; /* anchor */
9666 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
9668 val
= dp
->contents
[code
[i
]];
9669 if (!SUB_CHAR_TABLE_P (val
))
9670 return (NILP (val
) ? dp
->defalt
: val
);
9673 /* Here, val is a sub char table. We return the default value of
9675 return (dp
->defalt
);
9680 /***********************************************************************
9682 ***********************************************************************/
9684 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
9687 redisplay_windows (window
)
9690 while (!NILP (window
))
9692 struct window
*w
= XWINDOW (window
);
9694 if (!NILP (w
->hchild
))
9695 redisplay_windows (w
->hchild
);
9696 else if (!NILP (w
->vchild
))
9697 redisplay_windows (w
->vchild
);
9700 displayed_buffer
= XBUFFER (w
->buffer
);
9701 /* Use list_of_error, not Qerror, so that
9702 we catch only errors and don't run the debugger. */
9703 internal_condition_case_1 (redisplay_window_0
, window
,
9705 redisplay_window_error
);
9713 redisplay_window_error ()
9715 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
9720 redisplay_window_0 (window
)
9723 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9724 redisplay_window (window
, 0);
9729 redisplay_window_1 (window
)
9732 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
9733 redisplay_window (window
, 1);
9738 /* Increment GLYPH until it reaches END or CONDITION fails while
9739 adding (GLYPH)->pixel_width to X. */
9741 #define SKIP_GLYPHS(glyph, end, x, condition) \
9744 (x) += (glyph)->pixel_width; \
9747 while ((glyph) < (end) && (condition))
9750 /* Set cursor position of W. PT is assumed to be displayed in ROW.
9751 DELTA is the number of bytes by which positions recorded in ROW
9752 differ from current buffer positions. */
9755 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
9757 struct glyph_row
*row
;
9758 struct glyph_matrix
*matrix
;
9759 int delta
, delta_bytes
, dy
, dvpos
;
9761 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
9762 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
9763 /* The first glyph that starts a sequence of glyphs from string. */
9764 struct glyph
*string_start
;
9765 /* The X coordinate of string_start. */
9767 /* The last known character position. */
9768 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
9769 /* The last known character position before string_start. */
9770 int string_before_pos
;
9772 int pt_old
= PT
- delta
;
9774 /* Skip over glyphs not having an object at the start of the row.
9775 These are special glyphs like truncation marks on terminal
9777 if (row
->displays_text_p
)
9779 && INTEGERP (glyph
->object
)
9780 && glyph
->charpos
< 0)
9782 x
+= glyph
->pixel_width
;
9786 string_start
= NULL
;
9788 && !INTEGERP (glyph
->object
)
9789 && (!BUFFERP (glyph
->object
)
9790 || (last_pos
= glyph
->charpos
) < pt_old
))
9792 if (! STRINGP (glyph
->object
))
9794 string_start
= NULL
;
9795 x
+= glyph
->pixel_width
;
9800 string_before_pos
= last_pos
;
9801 string_start
= glyph
;
9803 /* Skip all glyphs from string. */
9804 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
9809 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
9811 /* We may have skipped over point because the previous glyphs
9812 are from string. As there's no easy way to know the
9813 character position of the current glyph, find the correct
9814 glyph on point by scanning from string_start again. */
9819 limit
= make_number (pt_old
+ 1);
9821 glyph
= string_start
;
9823 string
= glyph
->object
;
9824 pos
= string_buffer_position (w
, string
, string_before_pos
);
9825 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
9826 because we always put cursor after overlay strings. */
9827 while (pos
== 0 && glyph
< end
)
9829 string
= glyph
->object
;
9830 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9832 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
9837 pos
= XINT (Fnext_single_char_property_change
9838 (make_number (pos
), Qdisplay
, Qnil
, limit
));
9841 /* Skip glyphs from the same string. */
9842 string
= glyph
->object
;
9843 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9844 /* Skip glyphs from an overlay. */
9846 && ! string_buffer_position (w
, glyph
->object
, pos
))
9848 string
= glyph
->object
;
9849 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
9854 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
9856 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
9857 w
->cursor
.y
= row
->y
+ dy
;
9859 if (w
== XWINDOW (selected_window
))
9861 if (!row
->continued_p
9862 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
9865 this_line_buffer
= XBUFFER (w
->buffer
);
9867 CHARPOS (this_line_start_pos
)
9868 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
9869 BYTEPOS (this_line_start_pos
)
9870 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
9872 CHARPOS (this_line_end_pos
)
9873 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
9874 BYTEPOS (this_line_end_pos
)
9875 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
9877 this_line_y
= w
->cursor
.y
;
9878 this_line_pixel_height
= row
->height
;
9879 this_line_vpos
= w
->cursor
.vpos
;
9880 this_line_start_x
= row
->x
;
9883 CHARPOS (this_line_start_pos
) = 0;
9888 /* Run window scroll functions, if any, for WINDOW with new window
9889 start STARTP. Sets the window start of WINDOW to that position.
9891 We assume that the window's buffer is really current. */
9893 static INLINE
struct text_pos
9894 run_window_scroll_functions (window
, startp
)
9896 struct text_pos startp
;
9898 struct window
*w
= XWINDOW (window
);
9899 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
9901 if (current_buffer
!= XBUFFER (w
->buffer
))
9904 if (!NILP (Vwindow_scroll_functions
))
9906 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
9907 make_number (CHARPOS (startp
)));
9908 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9909 /* In case the hook functions switch buffers. */
9910 if (current_buffer
!= XBUFFER (w
->buffer
))
9911 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9918 /* Make sure the line containing the cursor is fully visible.
9919 A value of 1 means there is nothing to be done.
9920 (Either the line is fully visible, or it cannot be made so,
9922 A value of 0 means the caller should do scrolling
9923 as if point had gone off the screen. */
9926 make_cursor_line_fully_visible (w
)
9929 struct glyph_matrix
*matrix
;
9930 struct glyph_row
*row
;
9933 /* It's not always possible to find the cursor, e.g, when a window
9934 is full of overlay strings. Don't do anything in that case. */
9935 if (w
->cursor
.vpos
< 0)
9938 matrix
= w
->desired_matrix
;
9939 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
9941 /* If the cursor row is not partially visible, there's nothing to do. */
9942 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
9945 /* If the row the cursor is in is taller than the window's height,
9946 it's not clear what to do, so do nothing. */
9947 window_height
= window_box_height (w
);
9948 if (row
->height
>= window_height
)
9954 /* This code used to try to scroll the window just enough to make
9955 the line visible. It returned 0 to say that the caller should
9956 allocate larger glyph matrices. */
9958 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
9960 int dy
= row
->height
- row
->visible_height
;
9963 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9965 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
9967 int dy
= - (row
->height
- row
->visible_height
);
9970 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
9973 /* When we change the cursor y-position of the selected window,
9974 change this_line_y as well so that the display optimization for
9975 the cursor line of the selected window in redisplay_internal uses
9976 the correct y-position. */
9977 if (w
== XWINDOW (selected_window
))
9978 this_line_y
= w
->cursor
.y
;
9980 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
9981 redisplay with larger matrices. */
9982 if (matrix
->nrows
< required_matrix_height (w
))
9984 fonts_changed_p
= 1;
9993 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
9994 non-zero means only WINDOW is redisplayed in redisplay_internal.
9995 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
9996 in redisplay_window to bring a partially visible line into view in
9997 the case that only the cursor has moved.
9999 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10000 last screen line's vertical height extends past the end of the screen.
10004 1 if scrolling succeeded
10006 0 if scrolling didn't find point.
10008 -1 if new fonts have been loaded so that we must interrupt
10009 redisplay, adjust glyph matrices, and try again. */
10015 SCROLLING_NEED_LARGER_MATRICES
10019 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10020 scroll_step
, temp_scroll_step
, last_line_misfit
)
10021 Lisp_Object window
;
10022 int just_this_one_p
;
10023 EMACS_INT scroll_conservatively
, scroll_step
;
10024 int temp_scroll_step
;
10025 int last_line_misfit
;
10027 struct window
*w
= XWINDOW (window
);
10028 struct frame
*f
= XFRAME (w
->frame
);
10029 struct text_pos scroll_margin_pos
;
10030 struct text_pos pos
;
10031 struct text_pos startp
;
10033 Lisp_Object window_end
;
10034 int this_scroll_margin
;
10038 int amount_to_scroll
= 0;
10039 Lisp_Object aggressive
;
10041 int end_scroll_margin
;
10044 debug_method_add (w
, "try_scrolling");
10047 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10049 /* Compute scroll margin height in pixels. We scroll when point is
10050 within this distance from the top or bottom of the window. */
10051 if (scroll_margin
> 0)
10053 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
10054 this_scroll_margin
*= CANON_Y_UNIT (f
);
10057 this_scroll_margin
= 0;
10059 /* Compute how much we should try to scroll maximally to bring point
10061 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10062 scroll_max
= max (scroll_step
,
10063 max (scroll_conservatively
, temp_scroll_step
));
10064 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10065 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10066 /* We're trying to scroll because of aggressive scrolling
10067 but no scroll_step is set. Choose an arbitrary one. Maybe
10068 there should be a variable for this. */
10072 scroll_max
*= CANON_Y_UNIT (f
);
10074 /* Decide whether we have to scroll down. Start at the window end
10075 and move this_scroll_margin up to find the position of the scroll
10077 window_end
= Fwindow_end (window
, Qt
);
10081 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10082 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10084 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
10085 if (end_scroll_margin
)
10087 start_display (&it
, w
, scroll_margin_pos
);
10088 move_it_vertically (&it
, - end_scroll_margin
);
10089 scroll_margin_pos
= it
.current
.pos
;
10092 if (PT
>= CHARPOS (scroll_margin_pos
))
10096 /* Point is in the scroll margin at the bottom of the window, or
10097 below. Compute a new window start that makes point visible. */
10099 /* Compute the distance from the scroll margin to PT.
10100 Give up if the distance is greater than scroll_max. */
10101 start_display (&it
, w
, scroll_margin_pos
);
10103 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10104 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10106 /* To make point visible, we have to move the window start
10107 down so that the line the cursor is in is visible, which
10108 means we have to add in the height of the cursor line. */
10109 dy
= line_bottom_y (&it
) - y0
;
10111 if (dy
> scroll_max
)
10112 return SCROLLING_FAILED
;
10114 /* Move the window start down. If scrolling conservatively,
10115 move it just enough down to make point visible. If
10116 scroll_step is set, move it down by scroll_step. */
10117 start_display (&it
, w
, startp
);
10119 if (scroll_conservatively
)
10120 /* Set AMOUNT_TO_SCROLL to at least one line,
10121 and at most scroll_conservatively lines. */
10123 = min (max (dy
, CANON_Y_UNIT (f
)),
10124 CANON_Y_UNIT (f
) * scroll_conservatively
);
10125 else if (scroll_step
|| temp_scroll_step
)
10126 amount_to_scroll
= scroll_max
;
10129 aggressive
= current_buffer
->scroll_up_aggressively
;
10130 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
10131 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10132 if (NUMBERP (aggressive
))
10133 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10136 if (amount_to_scroll
<= 0)
10137 return SCROLLING_FAILED
;
10139 /* If moving by amount_to_scroll leaves STARTP unchanged,
10140 move it down one screen line. */
10142 move_it_vertically (&it
, amount_to_scroll
);
10143 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
10144 move_it_by_lines (&it
, 1, 1);
10145 startp
= it
.current
.pos
;
10149 /* See if point is inside the scroll margin at the top of the
10151 scroll_margin_pos
= startp
;
10152 if (this_scroll_margin
)
10154 start_display (&it
, w
, startp
);
10155 move_it_vertically (&it
, this_scroll_margin
);
10156 scroll_margin_pos
= it
.current
.pos
;
10159 if (PT
< CHARPOS (scroll_margin_pos
))
10161 /* Point is in the scroll margin at the top of the window or
10162 above what is displayed in the window. */
10165 /* Compute the vertical distance from PT to the scroll
10166 margin position. Give up if distance is greater than
10168 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
10169 start_display (&it
, w
, pos
);
10171 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
10172 it
.last_visible_y
, -1,
10173 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10174 dy
= it
.current_y
- y0
;
10175 if (dy
> scroll_max
)
10176 return SCROLLING_FAILED
;
10178 /* Compute new window start. */
10179 start_display (&it
, w
, startp
);
10181 if (scroll_conservatively
)
10183 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
10184 else if (scroll_step
|| temp_scroll_step
)
10185 amount_to_scroll
= scroll_max
;
10188 aggressive
= current_buffer
->scroll_down_aggressively
;
10189 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
10190 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10191 if (NUMBERP (aggressive
))
10192 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10195 if (amount_to_scroll
<= 0)
10196 return SCROLLING_FAILED
;
10198 move_it_vertically (&it
, - amount_to_scroll
);
10199 startp
= it
.current
.pos
;
10203 /* Run window scroll functions. */
10204 startp
= run_window_scroll_functions (window
, startp
);
10206 /* Display the window. Give up if new fonts are loaded, or if point
10208 if (!try_window (window
, startp
))
10209 rc
= SCROLLING_NEED_LARGER_MATRICES
;
10210 else if (w
->cursor
.vpos
< 0)
10212 clear_glyph_matrix (w
->desired_matrix
);
10213 rc
= SCROLLING_FAILED
;
10217 /* Maybe forget recorded base line for line number display. */
10218 if (!just_this_one_p
10219 || current_buffer
->clip_changed
10220 || BEG_UNCHANGED
< CHARPOS (startp
))
10221 w
->base_line_number
= Qnil
;
10223 /* If cursor ends up on a partially visible line,
10224 treat that as being off the bottom of the screen. */
10225 if (! make_cursor_line_fully_visible (w
))
10227 clear_glyph_matrix (w
->desired_matrix
);
10228 last_line_misfit
= 1;
10231 rc
= SCROLLING_SUCCESS
;
10238 /* Compute a suitable window start for window W if display of W starts
10239 on a continuation line. Value is non-zero if a new window start
10242 The new window start will be computed, based on W's width, starting
10243 from the start of the continued line. It is the start of the
10244 screen line with the minimum distance from the old start W->start. */
10247 compute_window_start_on_continuation_line (w
)
10250 struct text_pos pos
, start_pos
;
10251 int window_start_changed_p
= 0;
10253 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
10255 /* If window start is on a continuation line... Window start may be
10256 < BEGV in case there's invisible text at the start of the
10257 buffer (M-x rmail, for example). */
10258 if (CHARPOS (start_pos
) > BEGV
10259 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
10262 struct glyph_row
*row
;
10264 /* Handle the case that the window start is out of range. */
10265 if (CHARPOS (start_pos
) < BEGV
)
10266 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
10267 else if (CHARPOS (start_pos
) > ZV
)
10268 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
10270 /* Find the start of the continued line. This should be fast
10271 because scan_buffer is fast (newline cache). */
10272 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
10273 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
10274 row
, DEFAULT_FACE_ID
);
10275 reseat_at_previous_visible_line_start (&it
);
10277 /* If the line start is "too far" away from the window start,
10278 say it takes too much time to compute a new window start. */
10279 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
10280 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
10282 int min_distance
, distance
;
10284 /* Move forward by display lines to find the new window
10285 start. If window width was enlarged, the new start can
10286 be expected to be > the old start. If window width was
10287 decreased, the new window start will be < the old start.
10288 So, we're looking for the display line start with the
10289 minimum distance from the old window start. */
10290 pos
= it
.current
.pos
;
10291 min_distance
= INFINITY
;
10292 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
10293 distance
< min_distance
)
10295 min_distance
= distance
;
10296 pos
= it
.current
.pos
;
10297 move_it_by_lines (&it
, 1, 0);
10300 /* Set the window start there. */
10301 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
10302 window_start_changed_p
= 1;
10306 return window_start_changed_p
;
10310 /* Try cursor movement in case text has not changed in window WINDOW,
10311 with window start STARTP. Value is
10313 CURSOR_MOVEMENT_SUCCESS if successful
10315 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
10317 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
10318 display. *SCROLL_STEP is set to 1, under certain circumstances, if
10319 we want to scroll as if scroll-step were set to 1. See the code.
10321 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
10322 which case we have to abort this redisplay, and adjust matrices
10327 CURSOR_MOVEMENT_SUCCESS
,
10328 CURSOR_MOVEMENT_CANNOT_BE_USED
,
10329 CURSOR_MOVEMENT_MUST_SCROLL
,
10330 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
10334 try_cursor_movement (window
, startp
, scroll_step
)
10335 Lisp_Object window
;
10336 struct text_pos startp
;
10339 struct window
*w
= XWINDOW (window
);
10340 struct frame
*f
= XFRAME (w
->frame
);
10341 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
10344 if (inhibit_try_cursor_movement
)
10348 /* Handle case where text has not changed, only point, and it has
10349 not moved off the frame. */
10350 if (/* Point may be in this window. */
10351 PT
>= CHARPOS (startp
)
10352 /* Selective display hasn't changed. */
10353 && !current_buffer
->clip_changed
10354 /* Function force-mode-line-update is used to force a thorough
10355 redisplay. It sets either windows_or_buffers_changed or
10356 update_mode_lines. So don't take a shortcut here for these
10358 && !update_mode_lines
10359 && !windows_or_buffers_changed
10360 && !cursor_type_changed
10361 /* Can't use this case if highlighting a region. When a
10362 region exists, cursor movement has to do more than just
10364 && !(!NILP (Vtransient_mark_mode
)
10365 && !NILP (current_buffer
->mark_active
))
10366 && NILP (w
->region_showing
)
10367 && NILP (Vshow_trailing_whitespace
)
10368 /* Right after splitting windows, last_point may be nil. */
10369 && INTEGERP (w
->last_point
)
10370 /* This code is not used for mini-buffer for the sake of the case
10371 of redisplaying to replace an echo area message; since in
10372 that case the mini-buffer contents per se are usually
10373 unchanged. This code is of no real use in the mini-buffer
10374 since the handling of this_line_start_pos, etc., in redisplay
10375 handles the same cases. */
10376 && !EQ (window
, minibuf_window
)
10377 /* When splitting windows or for new windows, it happens that
10378 redisplay is called with a nil window_end_vpos or one being
10379 larger than the window. This should really be fixed in
10380 window.c. I don't have this on my list, now, so we do
10381 approximately the same as the old redisplay code. --gerd. */
10382 && INTEGERP (w
->window_end_vpos
)
10383 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
10384 && (FRAME_WINDOW_P (f
)
10385 || !MARKERP (Voverlay_arrow_position
)
10386 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
10388 int this_scroll_margin
;
10389 struct glyph_row
*row
= NULL
;
10392 debug_method_add (w
, "cursor movement");
10395 /* Scroll if point within this distance from the top or bottom
10396 of the window. This is a pixel value. */
10397 this_scroll_margin
= max (0, scroll_margin
);
10398 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
10399 this_scroll_margin
*= CANON_Y_UNIT (f
);
10401 /* Start with the row the cursor was displayed during the last
10402 not paused redisplay. Give up if that row is not valid. */
10403 if (w
->last_cursor
.vpos
< 0
10404 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
10405 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10408 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
10409 if (row
->mode_line_p
)
10411 if (!row
->enabled_p
)
10412 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10415 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
10418 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
10420 if (PT
> XFASTINT (w
->last_point
))
10422 /* Point has moved forward. */
10423 while (MATRIX_ROW_END_CHARPOS (row
) < PT
10424 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
10426 xassert (row
->enabled_p
);
10430 /* The end position of a row equals the start position
10431 of the next row. If PT is there, we would rather
10432 display it in the next line. */
10433 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10434 && MATRIX_ROW_END_CHARPOS (row
) == PT
10435 && !cursor_row_p (w
, row
))
10438 /* If within the scroll margin, scroll. Note that
10439 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
10440 the next line would be drawn, and that
10441 this_scroll_margin can be zero. */
10442 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
10443 || PT
> MATRIX_ROW_END_CHARPOS (row
)
10444 /* Line is completely visible last line in window
10445 and PT is to be set in the next line. */
10446 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
10447 && PT
== MATRIX_ROW_END_CHARPOS (row
)
10448 && !row
->ends_at_zv_p
10449 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
10452 else if (PT
< XFASTINT (w
->last_point
))
10454 /* Cursor has to be moved backward. Note that PT >=
10455 CHARPOS (startp) because of the outer
10457 while (!row
->mode_line_p
10458 && (MATRIX_ROW_START_CHARPOS (row
) > PT
10459 || (MATRIX_ROW_START_CHARPOS (row
) == PT
10460 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
10461 && (row
->y
> this_scroll_margin
10462 || CHARPOS (startp
) == BEGV
))
10464 xassert (row
->enabled_p
);
10468 /* Consider the following case: Window starts at BEGV,
10469 there is invisible, intangible text at BEGV, so that
10470 display starts at some point START > BEGV. It can
10471 happen that we are called with PT somewhere between
10472 BEGV and START. Try to handle that case. */
10473 if (row
< w
->current_matrix
->rows
10474 || row
->mode_line_p
)
10476 row
= w
->current_matrix
->rows
;
10477 if (row
->mode_line_p
)
10481 /* Due to newlines in overlay strings, we may have to
10482 skip forward over overlay strings. */
10483 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
10484 && MATRIX_ROW_END_CHARPOS (row
) == PT
10485 && !cursor_row_p (w
, row
))
10488 /* If within the scroll margin, scroll. */
10489 if (row
->y
< this_scroll_margin
10490 && CHARPOS (startp
) != BEGV
)
10494 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
10495 || PT
> MATRIX_ROW_END_CHARPOS (row
))
10497 /* if PT is not in the glyph row, give up. */
10498 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10500 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10502 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
10503 && !row
->ends_at_zv_p
10504 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
10505 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10506 else if (row
->height
> window_box_height (w
))
10508 /* If we end up in a partially visible line, let's
10509 make it fully visible, except when it's taller
10510 than the window, in which case we can't do much
10513 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10517 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10518 if (!make_cursor_line_fully_visible (w
))
10519 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10521 rc
= CURSOR_MOVEMENT_SUCCESS
;
10525 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
10528 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10529 rc
= CURSOR_MOVEMENT_SUCCESS
;
10538 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
10539 selected_window is redisplayed.
10541 We can return without actually redisplaying the window if
10542 fonts_changed_p is nonzero. In that case, redisplay_internal will
10546 redisplay_window (window
, just_this_one_p
)
10547 Lisp_Object window
;
10548 int just_this_one_p
;
10550 struct window
*w
= XWINDOW (window
);
10551 struct frame
*f
= XFRAME (w
->frame
);
10552 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10553 struct buffer
*old
= current_buffer
;
10554 struct text_pos lpoint
, opoint
, startp
;
10555 int update_mode_line
;
10558 /* Record it now because it's overwritten. */
10559 int current_matrix_up_to_date_p
= 0;
10560 /* This is less strict than current_matrix_up_to_date_p.
10561 It indictes that the buffer contents and narrowing are unchanged. */
10562 int buffer_unchanged_p
= 0;
10563 int temp_scroll_step
= 0;
10564 int count
= SPECPDL_INDEX ();
10566 int centering_position
;
10567 int last_line_misfit
= 0;
10569 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10572 /* W must be a leaf window here. */
10573 xassert (!NILP (w
->buffer
));
10575 *w
->desired_matrix
->method
= 0;
10578 specbind (Qinhibit_point_motion_hooks
, Qt
);
10580 reconsider_clip_changes (w
, buffer
);
10582 /* Has the mode line to be updated? */
10583 update_mode_line
= (!NILP (w
->update_mode_line
)
10584 || update_mode_lines
10585 || buffer
->clip_changed
10586 || buffer
->prevent_redisplay_optimizations_p
);
10588 if (MINI_WINDOW_P (w
))
10590 if (w
== XWINDOW (echo_area_window
)
10591 && !NILP (echo_area_buffer
[0]))
10593 if (update_mode_line
)
10594 /* We may have to update a tty frame's menu bar or a
10595 tool-bar. Example `M-x C-h C-h C-g'. */
10596 goto finish_menu_bars
;
10598 /* We've already displayed the echo area glyphs in this window. */
10599 goto finish_scroll_bars
;
10601 else if ((w
!= XWINDOW (minibuf_window
)
10602 || minibuf_level
== 0)
10603 /* Quail displays non-mini buffers in minibuffer window.
10604 In that case, redisplay the window normally. */
10605 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
10607 /* W is a mini-buffer window, but it's not active, so clear
10609 int yb
= window_text_bottom_y (w
);
10610 struct glyph_row
*row
;
10613 for (y
= 0, row
= w
->desired_matrix
->rows
;
10615 y
+= row
->height
, ++row
)
10616 blank_row (w
, row
, y
);
10617 goto finish_scroll_bars
;
10620 clear_glyph_matrix (w
->desired_matrix
);
10623 /* Otherwise set up data on this window; select its buffer and point
10625 /* Really select the buffer, for the sake of buffer-local
10627 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10628 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
10630 current_matrix_up_to_date_p
10631 = (!NILP (w
->window_end_valid
)
10632 && !current_buffer
->clip_changed
10633 && !current_buffer
->prevent_redisplay_optimizations_p
10634 && XFASTINT (w
->last_modified
) >= MODIFF
10635 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10638 = (!NILP (w
->window_end_valid
)
10639 && !current_buffer
->clip_changed
10640 && XFASTINT (w
->last_modified
) >= MODIFF
10641 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
10643 /* When windows_or_buffers_changed is non-zero, we can't rely on
10644 the window end being valid, so set it to nil there. */
10645 if (windows_or_buffers_changed
)
10647 /* If window starts on a continuation line, maybe adjust the
10648 window start in case the window's width changed. */
10649 if (XMARKER (w
->start
)->buffer
== current_buffer
)
10650 compute_window_start_on_continuation_line (w
);
10652 w
->window_end_valid
= Qnil
;
10655 /* Some sanity checks. */
10656 CHECK_WINDOW_END (w
);
10657 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
10659 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
10662 /* If %c is in mode line, update it if needed. */
10663 if (!NILP (w
->column_number_displayed
)
10664 /* This alternative quickly identifies a common case
10665 where no change is needed. */
10666 && !(PT
== XFASTINT (w
->last_point
)
10667 && XFASTINT (w
->last_modified
) >= MODIFF
10668 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10669 && (XFASTINT (w
->column_number_displayed
)
10670 != (int) current_column ())) /* iftc */
10671 update_mode_line
= 1;
10673 /* Count number of windows showing the selected buffer. An indirect
10674 buffer counts as its base buffer. */
10675 if (!just_this_one_p
)
10677 struct buffer
*current_base
, *window_base
;
10678 current_base
= current_buffer
;
10679 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10680 if (current_base
->base_buffer
)
10681 current_base
= current_base
->base_buffer
;
10682 if (window_base
->base_buffer
)
10683 window_base
= window_base
->base_buffer
;
10684 if (current_base
== window_base
)
10688 /* Point refers normally to the selected window. For any other
10689 window, set up appropriate value. */
10690 if (!EQ (window
, selected_window
))
10692 int new_pt
= XMARKER (w
->pointm
)->charpos
;
10693 int new_pt_byte
= marker_byte_position (w
->pointm
);
10697 new_pt_byte
= BEGV_BYTE
;
10698 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
10700 else if (new_pt
> (ZV
- 1))
10703 new_pt_byte
= ZV_BYTE
;
10704 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
10707 /* We don't use SET_PT so that the point-motion hooks don't run. */
10708 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
10711 /* If any of the character widths specified in the display table
10712 have changed, invalidate the width run cache. It's true that
10713 this may be a bit late to catch such changes, but the rest of
10714 redisplay goes (non-fatally) haywire when the display table is
10715 changed, so why should we worry about doing any better? */
10716 if (current_buffer
->width_run_cache
)
10718 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
10720 if (! disptab_matches_widthtab (disptab
,
10721 XVECTOR (current_buffer
->width_table
)))
10723 invalidate_region_cache (current_buffer
,
10724 current_buffer
->width_run_cache
,
10726 recompute_width_table (current_buffer
, disptab
);
10730 /* If window-start is screwed up, choose a new one. */
10731 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
10734 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10736 /* If someone specified a new starting point but did not insist,
10737 check whether it can be used. */
10738 if (!NILP (w
->optional_new_start
)
10739 && CHARPOS (startp
) >= BEGV
10740 && CHARPOS (startp
) <= ZV
)
10742 w
->optional_new_start
= Qnil
;
10743 start_display (&it
, w
, startp
);
10744 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10745 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10746 if (IT_CHARPOS (it
) == PT
)
10747 w
->force_start
= Qt
;
10750 /* Handle case where place to start displaying has been specified,
10751 unless the specified location is outside the accessible range. */
10752 if (!NILP (w
->force_start
)
10753 || w
->frozen_window_start_p
)
10755 /* We set this later on if we have to adjust point. */
10758 w
->force_start
= Qnil
;
10760 w
->window_end_valid
= Qnil
;
10762 /* Forget any recorded base line for line number display. */
10763 if (!buffer_unchanged_p
)
10764 w
->base_line_number
= Qnil
;
10766 /* Redisplay the mode line. Select the buffer properly for that.
10767 Also, run the hook window-scroll-functions
10768 because we have scrolled. */
10769 /* Note, we do this after clearing force_start because
10770 if there's an error, it is better to forget about force_start
10771 than to get into an infinite loop calling the hook functions
10772 and having them get more errors. */
10773 if (!update_mode_line
10774 || ! NILP (Vwindow_scroll_functions
))
10776 update_mode_line
= 1;
10777 w
->update_mode_line
= Qt
;
10778 startp
= run_window_scroll_functions (window
, startp
);
10781 w
->last_modified
= make_number (0);
10782 w
->last_overlay_modified
= make_number (0);
10783 if (CHARPOS (startp
) < BEGV
)
10784 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
10785 else if (CHARPOS (startp
) > ZV
)
10786 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
10788 /* Redisplay, then check if cursor has been set during the
10789 redisplay. Give up if new fonts were loaded. */
10790 if (!try_window (window
, startp
))
10792 w
->force_start
= Qt
;
10793 clear_glyph_matrix (w
->desired_matrix
);
10794 goto need_larger_matrices
;
10797 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
10799 /* If point does not appear, try to move point so it does
10800 appear. The desired matrix has been built above, so we
10801 can use it here. */
10802 new_vpos
= window_box_height (w
) / 2;
10805 if (!make_cursor_line_fully_visible (w
))
10807 /* Point does appear, but on a line partly visible at end of window.
10808 Move it back to a fully-visible line. */
10809 new_vpos
= window_box_height (w
);
10812 /* If we need to move point for either of the above reasons,
10813 now actually do it. */
10816 struct glyph_row
*row
;
10818 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
10819 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
10822 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
10823 MATRIX_ROW_START_BYTEPOS (row
));
10825 if (w
!= XWINDOW (selected_window
))
10826 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
10827 else if (current_buffer
== old
)
10828 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
10830 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
10832 /* If we are highlighting the region, then we just changed
10833 the region, so redisplay to show it. */
10834 if (!NILP (Vtransient_mark_mode
)
10835 && !NILP (current_buffer
->mark_active
))
10837 clear_glyph_matrix (w
->desired_matrix
);
10838 if (!try_window (window
, startp
))
10839 goto need_larger_matrices
;
10844 debug_method_add (w
, "forced window start");
10849 /* Handle case where text has not changed, only point, and it has
10850 not moved off the frame, and we are not retrying after hscroll.
10851 (current_matrix_up_to_date_p is nonzero when retrying.) */
10852 if (current_matrix_up_to_date_p
10853 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
10854 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
10858 case CURSOR_MOVEMENT_SUCCESS
:
10861 #if 0 /* try_cursor_movement never returns this value. */
10862 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
10863 goto need_larger_matrices
;
10866 case CURSOR_MOVEMENT_MUST_SCROLL
:
10867 goto try_to_scroll
;
10873 /* If current starting point was originally the beginning of a line
10874 but no longer is, find a new starting point. */
10875 else if (!NILP (w
->start_at_line_beg
)
10876 && !(CHARPOS (startp
) <= BEGV
10877 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
10880 debug_method_add (w
, "recenter 1");
10885 /* Try scrolling with try_window_id. Value is > 0 if update has
10886 been done, it is -1 if we know that the same window start will
10887 not work. It is 0 if unsuccessful for some other reason. */
10888 else if ((tem
= try_window_id (w
)) != 0)
10891 debug_method_add (w
, "try_window_id %d", tem
);
10894 if (fonts_changed_p
)
10895 goto need_larger_matrices
;
10899 /* Otherwise try_window_id has returned -1 which means that we
10900 don't want the alternative below this comment to execute. */
10902 else if (CHARPOS (startp
) >= BEGV
10903 && CHARPOS (startp
) <= ZV
10904 && PT
>= CHARPOS (startp
)
10905 && (CHARPOS (startp
) < ZV
10906 /* Avoid starting at end of buffer. */
10907 || CHARPOS (startp
) == BEGV
10908 || (XFASTINT (w
->last_modified
) >= MODIFF
10909 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
10912 debug_method_add (w
, "same window start");
10915 /* Try to redisplay starting at same place as before.
10916 If point has not moved off frame, accept the results. */
10917 if (!current_matrix_up_to_date_p
10918 /* Don't use try_window_reusing_current_matrix in this case
10919 because a window scroll function can have changed the
10921 || !NILP (Vwindow_scroll_functions
)
10922 || MINI_WINDOW_P (w
)
10923 || !try_window_reusing_current_matrix (w
))
10925 IF_DEBUG (debug_method_add (w
, "1"));
10926 try_window (window
, startp
);
10929 if (fonts_changed_p
)
10930 goto need_larger_matrices
;
10932 if (w
->cursor
.vpos
>= 0)
10934 if (!just_this_one_p
10935 || current_buffer
->clip_changed
10936 || BEG_UNCHANGED
< CHARPOS (startp
))
10937 /* Forget any recorded base line for line number display. */
10938 w
->base_line_number
= Qnil
;
10940 if (!make_cursor_line_fully_visible (w
))
10942 clear_glyph_matrix (w
->desired_matrix
);
10943 last_line_misfit
= 1;
10945 /* Drop through and scroll. */
10950 clear_glyph_matrix (w
->desired_matrix
);
10955 w
->last_modified
= make_number (0);
10956 w
->last_overlay_modified
= make_number (0);
10958 /* Redisplay the mode line. Select the buffer properly for that. */
10959 if (!update_mode_line
)
10961 update_mode_line
= 1;
10962 w
->update_mode_line
= Qt
;
10965 /* Try to scroll by specified few lines. */
10966 if ((scroll_conservatively
10968 || temp_scroll_step
10969 || NUMBERP (current_buffer
->scroll_up_aggressively
)
10970 || NUMBERP (current_buffer
->scroll_down_aggressively
))
10971 && !current_buffer
->clip_changed
10972 && CHARPOS (startp
) >= BEGV
10973 && CHARPOS (startp
) <= ZV
)
10975 /* The function returns -1 if new fonts were loaded, 1 if
10976 successful, 0 if not successful. */
10977 int rc
= try_scrolling (window
, just_this_one_p
,
10978 scroll_conservatively
,
10980 temp_scroll_step
, last_line_misfit
);
10983 case SCROLLING_SUCCESS
:
10986 case SCROLLING_NEED_LARGER_MATRICES
:
10987 goto need_larger_matrices
;
10989 case SCROLLING_FAILED
:
10997 /* Finally, just choose place to start which centers point */
11000 centering_position
= window_box_height (w
) / 2;
11003 /* Jump here with centering_position already set to 0. */
11006 debug_method_add (w
, "recenter");
11009 /* w->vscroll = 0; */
11011 /* Forget any previously recorded base line for line number display. */
11012 if (!buffer_unchanged_p
)
11013 w
->base_line_number
= Qnil
;
11015 /* Move backward half the height of the window. */
11016 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11017 it
.current_y
= it
.last_visible_y
;
11018 move_it_vertically_backward (&it
, centering_position
);
11019 xassert (IT_CHARPOS (it
) >= BEGV
);
11021 /* The function move_it_vertically_backward may move over more
11022 than the specified y-distance. If it->w is small, e.g. a
11023 mini-buffer window, we may end up in front of the window's
11024 display area. Start displaying at the start of the line
11025 containing PT in this case. */
11026 if (it
.current_y
<= 0)
11028 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11029 move_it_vertically (&it
, 0);
11030 xassert (IT_CHARPOS (it
) <= PT
);
11034 it
.current_x
= it
.hpos
= 0;
11036 /* Set startp here explicitly in case that helps avoid an infinite loop
11037 in case the window-scroll-functions functions get errors. */
11038 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11040 /* Run scroll hooks. */
11041 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11043 /* Redisplay the window. */
11044 if (!current_matrix_up_to_date_p
11045 || windows_or_buffers_changed
11046 || cursor_type_changed
11047 /* Don't use try_window_reusing_current_matrix in this case
11048 because it can have changed the buffer. */
11049 || !NILP (Vwindow_scroll_functions
)
11050 || !just_this_one_p
11051 || MINI_WINDOW_P (w
)
11052 || !try_window_reusing_current_matrix (w
))
11053 try_window (window
, startp
);
11055 /* If new fonts have been loaded (due to fontsets), give up. We
11056 have to start a new redisplay since we need to re-adjust glyph
11058 if (fonts_changed_p
)
11059 goto need_larger_matrices
;
11061 /* If cursor did not appear assume that the middle of the window is
11062 in the first line of the window. Do it again with the next line.
11063 (Imagine a window of height 100, displaying two lines of height
11064 60. Moving back 50 from it->last_visible_y will end in the first
11066 if (w
->cursor
.vpos
< 0)
11068 if (!NILP (w
->window_end_valid
)
11069 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11071 clear_glyph_matrix (w
->desired_matrix
);
11072 move_it_by_lines (&it
, 1, 0);
11073 try_window (window
, it
.current
.pos
);
11075 else if (PT
< IT_CHARPOS (it
))
11077 clear_glyph_matrix (w
->desired_matrix
);
11078 move_it_by_lines (&it
, -1, 0);
11079 try_window (window
, it
.current
.pos
);
11083 /* Not much we can do about it. */
11087 /* Consider the following case: Window starts at BEGV, there is
11088 invisible, intangible text at BEGV, so that display starts at
11089 some point START > BEGV. It can happen that we are called with
11090 PT somewhere between BEGV and START. Try to handle that case. */
11091 if (w
->cursor
.vpos
< 0)
11093 struct glyph_row
*row
= w
->current_matrix
->rows
;
11094 if (row
->mode_line_p
)
11096 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11099 if (!make_cursor_line_fully_visible (w
))
11101 /* If vscroll is enabled, disable it and try again. */
11105 clear_glyph_matrix (w
->desired_matrix
);
11109 /* If centering point failed to make the whole line visible,
11110 put point at the top instead. That has to make the whole line
11111 visible, if it can be done. */
11112 centering_position
= 0;
11118 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11119 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
11120 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
11123 /* Display the mode line, if we must. */
11124 if ((update_mode_line
11125 /* If window not full width, must redo its mode line
11126 if (a) the window to its side is being redone and
11127 (b) we do a frame-based redisplay. This is a consequence
11128 of how inverted lines are drawn in frame-based redisplay. */
11129 || (!just_this_one_p
11130 && !FRAME_WINDOW_P (f
)
11131 && !WINDOW_FULL_WIDTH_P (w
))
11132 /* Line number to display. */
11133 || INTEGERP (w
->base_line_pos
)
11134 /* Column number is displayed and different from the one displayed. */
11135 || (!NILP (w
->column_number_displayed
)
11136 && (XFASTINT (w
->column_number_displayed
)
11137 != (int) current_column ()))) /* iftc */
11138 /* This means that the window has a mode line. */
11139 && (WINDOW_WANTS_MODELINE_P (w
)
11140 || WINDOW_WANTS_HEADER_LINE_P (w
)))
11142 display_mode_lines (w
);
11144 /* If mode line height has changed, arrange for a thorough
11145 immediate redisplay using the correct mode line height. */
11146 if (WINDOW_WANTS_MODELINE_P (w
)
11147 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
11149 fonts_changed_p
= 1;
11150 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
11151 = DESIRED_MODE_LINE_HEIGHT (w
);
11154 /* If top line height has changed, arrange for a thorough
11155 immediate redisplay using the correct mode line height. */
11156 if (WINDOW_WANTS_HEADER_LINE_P (w
)
11157 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
11159 fonts_changed_p
= 1;
11160 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
11161 = DESIRED_HEADER_LINE_HEIGHT (w
);
11164 if (fonts_changed_p
)
11165 goto need_larger_matrices
;
11168 if (!line_number_displayed
11169 && !BUFFERP (w
->base_line_pos
))
11171 w
->base_line_pos
= Qnil
;
11172 w
->base_line_number
= Qnil
;
11177 /* When we reach a frame's selected window, redo the frame's menu bar. */
11178 if (update_mode_line
11179 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
11181 int redisplay_menu_p
= 0;
11182 int redisplay_tool_bar_p
= 0;
11184 if (FRAME_WINDOW_P (f
))
11186 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
11187 || defined (USE_GTK)
11188 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
11190 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
11194 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
11196 if (redisplay_menu_p
)
11197 display_menu_bar (w
);
11199 #ifdef HAVE_WINDOW_SYSTEM
11201 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
11203 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
11204 && (FRAME_TOOL_BAR_LINES (f
) > 0
11205 || auto_resize_tool_bars_p
);
11209 if (redisplay_tool_bar_p
)
11210 redisplay_tool_bar (f
);
11214 /* We go to this label, with fonts_changed_p nonzero,
11215 if it is necessary to try again using larger glyph matrices.
11216 We have to redeem the scroll bar even in this case,
11217 because the loop in redisplay_internal expects that. */
11218 need_larger_matrices
:
11220 finish_scroll_bars
:
11222 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11224 int start
, end
, whole
;
11226 /* Calculate the start and end positions for the current window.
11227 At some point, it would be nice to choose between scrollbars
11228 which reflect the whole buffer size, with special markers
11229 indicating narrowing, and scrollbars which reflect only the
11232 Note that mini-buffers sometimes aren't displaying any text. */
11233 if (!MINI_WINDOW_P (w
)
11234 || (w
== XWINDOW (minibuf_window
)
11235 && NILP (echo_area_buffer
[0])))
11238 start
= marker_position (w
->start
) - BEGV
;
11239 /* I don't think this is guaranteed to be right. For the
11240 moment, we'll pretend it is. */
11241 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
11245 if (whole
< (end
- start
))
11246 whole
= end
- start
;
11249 start
= end
= whole
= 0;
11251 /* Indicate what this scroll bar ought to be displaying now. */
11252 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11254 /* Note that we actually used the scroll bar attached to this
11255 window, so it shouldn't be deleted at the end of redisplay. */
11256 redeem_scroll_bar_hook (w
);
11259 /* Restore current_buffer and value of point in it. */
11260 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
11261 set_buffer_internal_1 (old
);
11262 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
11264 unbind_to (count
, Qnil
);
11268 /* Build the complete desired matrix of WINDOW with a window start
11269 buffer position POS. Value is non-zero if successful. It is zero
11270 if fonts were loaded during redisplay which makes re-adjusting
11271 glyph matrices necessary. */
11274 try_window (window
, pos
)
11275 Lisp_Object window
;
11276 struct text_pos pos
;
11278 struct window
*w
= XWINDOW (window
);
11280 struct glyph_row
*last_text_row
= NULL
;
11282 /* Make POS the new window start. */
11283 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
11285 /* Mark cursor position as unknown. No overlay arrow seen. */
11286 w
->cursor
.vpos
= -1;
11287 overlay_arrow_seen
= 0;
11289 /* Initialize iterator and info to start at POS. */
11290 start_display (&it
, w
, pos
);
11292 /* Display all lines of W. */
11293 while (it
.current_y
< it
.last_visible_y
)
11295 if (display_line (&it
))
11296 last_text_row
= it
.glyph_row
- 1;
11297 if (fonts_changed_p
)
11301 /* If bottom moved off end of frame, change mode line percentage. */
11302 if (XFASTINT (w
->window_end_pos
) <= 0
11303 && Z
!= IT_CHARPOS (it
))
11304 w
->update_mode_line
= Qt
;
11306 /* Set window_end_pos to the offset of the last character displayed
11307 on the window from the end of current_buffer. Set
11308 window_end_vpos to its row number. */
11311 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
11312 w
->window_end_bytepos
11313 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11315 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11317 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11318 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
11319 ->displays_text_p
);
11323 w
->window_end_bytepos
= 0;
11324 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11327 /* But that is not valid info until redisplay finishes. */
11328 w
->window_end_valid
= Qnil
;
11334 /************************************************************************
11335 Window redisplay reusing current matrix when buffer has not changed
11336 ************************************************************************/
11338 /* Try redisplay of window W showing an unchanged buffer with a
11339 different window start than the last time it was displayed by
11340 reusing its current matrix. Value is non-zero if successful.
11341 W->start is the new window start. */
11344 try_window_reusing_current_matrix (w
)
11347 struct frame
*f
= XFRAME (w
->frame
);
11348 struct glyph_row
*row
, *bottom_row
;
11351 struct text_pos start
, new_start
;
11352 int nrows_scrolled
, i
;
11353 struct glyph_row
*last_text_row
;
11354 struct glyph_row
*last_reused_text_row
;
11355 struct glyph_row
*start_row
;
11356 int start_vpos
, min_y
, max_y
;
11359 if (inhibit_try_window_reusing
)
11363 if (/* This function doesn't handle terminal frames. */
11364 !FRAME_WINDOW_P (f
)
11365 /* Don't try to reuse the display if windows have been split
11367 || windows_or_buffers_changed
11368 || cursor_type_changed
)
11371 /* Can't do this if region may have changed. */
11372 if ((!NILP (Vtransient_mark_mode
)
11373 && !NILP (current_buffer
->mark_active
))
11374 || !NILP (w
->region_showing
)
11375 || !NILP (Vshow_trailing_whitespace
))
11378 /* If top-line visibility has changed, give up. */
11379 if (WINDOW_WANTS_HEADER_LINE_P (w
)
11380 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
11383 /* Give up if old or new display is scrolled vertically. We could
11384 make this function handle this, but right now it doesn't. */
11385 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11386 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
11389 /* The variable new_start now holds the new window start. The old
11390 start `start' can be determined from the current matrix. */
11391 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
11392 start
= start_row
->start
.pos
;
11393 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
11395 /* Clear the desired matrix for the display below. */
11396 clear_glyph_matrix (w
->desired_matrix
);
11398 if (CHARPOS (new_start
) <= CHARPOS (start
))
11402 /* Don't use this method if the display starts with an ellipsis
11403 displayed for invisible text. It's not easy to handle that case
11404 below, and it's certainly not worth the effort since this is
11405 not a frequent case. */
11406 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
11409 IF_DEBUG (debug_method_add (w
, "twu1"));
11411 /* Display up to a row that can be reused. The variable
11412 last_text_row is set to the last row displayed that displays
11413 text. Note that it.vpos == 0 if or if not there is a
11414 header-line; it's not the same as the MATRIX_ROW_VPOS! */
11415 start_display (&it
, w
, new_start
);
11416 first_row_y
= it
.current_y
;
11417 w
->cursor
.vpos
= -1;
11418 last_text_row
= last_reused_text_row
= NULL
;
11420 while (it
.current_y
< it
.last_visible_y
11421 && IT_CHARPOS (it
) < CHARPOS (start
)
11422 && !fonts_changed_p
)
11423 if (display_line (&it
))
11424 last_text_row
= it
.glyph_row
- 1;
11426 /* A value of current_y < last_visible_y means that we stopped
11427 at the previous window start, which in turn means that we
11428 have at least one reusable row. */
11429 if (it
.current_y
< it
.last_visible_y
)
11431 /* IT.vpos always starts from 0; it counts text lines. */
11432 nrows_scrolled
= it
.vpos
;
11434 /* Find PT if not already found in the lines displayed. */
11435 if (w
->cursor
.vpos
< 0)
11437 int dy
= it
.current_y
- first_row_y
;
11439 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11440 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
11442 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
11443 dy
, nrows_scrolled
);
11446 clear_glyph_matrix (w
->desired_matrix
);
11451 /* Scroll the display. Do it before the current matrix is
11452 changed. The problem here is that update has not yet
11453 run, i.e. part of the current matrix is not up to date.
11454 scroll_run_hook will clear the cursor, and use the
11455 current matrix to get the height of the row the cursor is
11457 run
.current_y
= first_row_y
;
11458 run
.desired_y
= it
.current_y
;
11459 run
.height
= it
.last_visible_y
- it
.current_y
;
11461 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
11464 rif
->update_window_begin_hook (w
);
11465 rif
->clear_mouse_face (w
);
11466 rif
->scroll_run_hook (w
, &run
);
11467 rif
->update_window_end_hook (w
, 0, 0);
11471 /* Shift current matrix down by nrows_scrolled lines. */
11472 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11473 rotate_matrix (w
->current_matrix
,
11475 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11478 /* Disable lines that must be updated. */
11479 for (i
= 0; i
< it
.vpos
; ++i
)
11480 (start_row
+ i
)->enabled_p
= 0;
11482 /* Re-compute Y positions. */
11483 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11484 max_y
= it
.last_visible_y
;
11485 for (row
= start_row
+ nrows_scrolled
;
11489 row
->y
= it
.current_y
;
11490 row
->visible_height
= row
->height
;
11492 if (row
->y
< min_y
)
11493 row
->visible_height
-= min_y
- row
->y
;
11494 if (row
->y
+ row
->height
> max_y
)
11495 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11497 it
.current_y
+= row
->height
;
11499 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11500 last_reused_text_row
= row
;
11501 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
11505 /* Disable lines in the current matrix which are now
11506 below the window. */
11507 for (++row
; row
< bottom_row
; ++row
)
11508 row
->enabled_p
= 0;
11511 /* Update window_end_pos etc.; last_reused_text_row is the last
11512 reused row from the current matrix containing text, if any.
11513 The value of last_text_row is the last displayed line
11514 containing text. */
11515 if (last_reused_text_row
)
11517 w
->window_end_bytepos
11518 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
11520 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
11522 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
11523 w
->current_matrix
));
11525 else if (last_text_row
)
11527 w
->window_end_bytepos
11528 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11530 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11532 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11536 /* This window must be completely empty. */
11537 w
->window_end_bytepos
= 0;
11538 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
11540 w
->window_end_valid
= Qnil
;
11542 /* Update hint: don't try scrolling again in update_window. */
11543 w
->desired_matrix
->no_scrolling_p
= 1;
11546 debug_method_add (w
, "try_window_reusing_current_matrix 1");
11550 else if (CHARPOS (new_start
) > CHARPOS (start
))
11552 struct glyph_row
*pt_row
, *row
;
11553 struct glyph_row
*first_reusable_row
;
11554 struct glyph_row
*first_row_to_display
;
11556 int yb
= window_text_bottom_y (w
);
11558 /* Find the row starting at new_start, if there is one. Don't
11559 reuse a partially visible line at the end. */
11560 first_reusable_row
= start_row
;
11561 while (first_reusable_row
->enabled_p
11562 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
11563 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11564 < CHARPOS (new_start
)))
11565 ++first_reusable_row
;
11567 /* Give up if there is no row to reuse. */
11568 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
11569 || !first_reusable_row
->enabled_p
11570 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
11571 != CHARPOS (new_start
)))
11574 /* We can reuse fully visible rows beginning with
11575 first_reusable_row to the end of the window. Set
11576 first_row_to_display to the first row that cannot be reused.
11577 Set pt_row to the row containing point, if there is any. */
11579 for (first_row_to_display
= first_reusable_row
;
11580 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
11581 ++first_row_to_display
)
11583 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
11584 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
11585 pt_row
= first_row_to_display
;
11588 /* Start displaying at the start of first_row_to_display. */
11589 xassert (first_row_to_display
->y
< yb
);
11590 init_to_row_start (&it
, w
, first_row_to_display
);
11592 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
11594 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
11596 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
11597 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
11599 /* Display lines beginning with first_row_to_display in the
11600 desired matrix. Set last_text_row to the last row displayed
11601 that displays text. */
11602 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
11603 if (pt_row
== NULL
)
11604 w
->cursor
.vpos
= -1;
11605 last_text_row
= NULL
;
11606 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
11607 if (display_line (&it
))
11608 last_text_row
= it
.glyph_row
- 1;
11610 /* Give up If point isn't in a row displayed or reused. */
11611 if (w
->cursor
.vpos
< 0)
11613 clear_glyph_matrix (w
->desired_matrix
);
11617 /* If point is in a reused row, adjust y and vpos of the cursor
11621 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
11622 w
->current_matrix
);
11623 w
->cursor
.y
-= first_reusable_row
->y
;
11626 /* Scroll the display. */
11627 run
.current_y
= first_reusable_row
->y
;
11628 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11629 run
.height
= it
.last_visible_y
- run
.current_y
;
11630 dy
= run
.current_y
- run
.desired_y
;
11634 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11636 rif
->update_window_begin_hook (w
);
11637 rif
->clear_mouse_face (w
);
11638 rif
->scroll_run_hook (w
, &run
);
11639 rif
->update_window_end_hook (w
, 0, 0);
11643 /* Adjust Y positions of reused rows. */
11644 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
11645 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11646 max_y
= it
.last_visible_y
;
11647 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
11650 row
->visible_height
= row
->height
;
11651 if (row
->y
< min_y
)
11652 row
->visible_height
-= min_y
- row
->y
;
11653 if (row
->y
+ row
->height
> max_y
)
11654 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
11657 /* Scroll the current matrix. */
11658 xassert (nrows_scrolled
> 0);
11659 rotate_matrix (w
->current_matrix
,
11661 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
11664 /* Disable rows not reused. */
11665 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
11666 row
->enabled_p
= 0;
11668 /* Adjust window end. A null value of last_text_row means that
11669 the window end is in reused rows which in turn means that
11670 only its vpos can have changed. */
11673 w
->window_end_bytepos
11674 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
11676 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
11678 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
11683 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
11686 w
->window_end_valid
= Qnil
;
11687 w
->desired_matrix
->no_scrolling_p
= 1;
11690 debug_method_add (w
, "try_window_reusing_current_matrix 2");
11700 /************************************************************************
11701 Window redisplay reusing current matrix when buffer has changed
11702 ************************************************************************/
11704 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
11705 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
11707 static struct glyph_row
*
11708 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
11709 struct glyph_row
*));
11712 /* Return the last row in MATRIX displaying text. If row START is
11713 non-null, start searching with that row. IT gives the dimensions
11714 of the display. Value is null if matrix is empty; otherwise it is
11715 a pointer to the row found. */
11717 static struct glyph_row
*
11718 find_last_row_displaying_text (matrix
, it
, start
)
11719 struct glyph_matrix
*matrix
;
11721 struct glyph_row
*start
;
11723 struct glyph_row
*row
, *row_found
;
11725 /* Set row_found to the last row in IT->w's current matrix
11726 displaying text. The loop looks funny but think of partially
11729 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
11730 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11732 xassert (row
->enabled_p
);
11734 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
11743 /* Return the last row in the current matrix of W that is not affected
11744 by changes at the start of current_buffer that occurred since W's
11745 current matrix was built. Value is null if no such row exists.
11747 BEG_UNCHANGED us the number of characters unchanged at the start of
11748 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
11749 first changed character in current_buffer. Characters at positions <
11750 BEG + BEG_UNCHANGED are at the same buffer positions as they were
11751 when the current matrix was built. */
11753 static struct glyph_row
*
11754 find_last_unchanged_at_beg_row (w
)
11757 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
11758 struct glyph_row
*row
;
11759 struct glyph_row
*row_found
= NULL
;
11760 int yb
= window_text_bottom_y (w
);
11762 /* Find the last row displaying unchanged text. */
11763 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11764 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11765 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
11767 if (/* If row ends before first_changed_pos, it is unchanged,
11768 except in some case. */
11769 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
11770 /* When row ends in ZV and we write at ZV it is not
11772 && !row
->ends_at_zv_p
11773 /* When first_changed_pos is the end of a continued line,
11774 row is not unchanged because it may be no longer
11776 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
11777 && row
->continued_p
))
11780 /* Stop if last visible row. */
11781 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
11791 /* Find the first glyph row in the current matrix of W that is not
11792 affected by changes at the end of current_buffer since the
11793 time W's current matrix was built.
11795 Return in *DELTA the number of chars by which buffer positions in
11796 unchanged text at the end of current_buffer must be adjusted.
11798 Return in *DELTA_BYTES the corresponding number of bytes.
11800 Value is null if no such row exists, i.e. all rows are affected by
11803 static struct glyph_row
*
11804 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
11806 int *delta
, *delta_bytes
;
11808 struct glyph_row
*row
;
11809 struct glyph_row
*row_found
= NULL
;
11811 *delta
= *delta_bytes
= 0;
11813 /* Display must not have been paused, otherwise the current matrix
11814 is not up to date. */
11815 if (NILP (w
->window_end_valid
))
11818 /* A value of window_end_pos >= END_UNCHANGED means that the window
11819 end is in the range of changed text. If so, there is no
11820 unchanged row at the end of W's current matrix. */
11821 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
11824 /* Set row to the last row in W's current matrix displaying text. */
11825 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
11827 /* If matrix is entirely empty, no unchanged row exists. */
11828 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11830 /* The value of row is the last glyph row in the matrix having a
11831 meaningful buffer position in it. The end position of row
11832 corresponds to window_end_pos. This allows us to translate
11833 buffer positions in the current matrix to current buffer
11834 positions for characters not in changed text. */
11835 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
11836 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
11837 int last_unchanged_pos
, last_unchanged_pos_old
;
11838 struct glyph_row
*first_text_row
11839 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
11841 *delta
= Z
- Z_old
;
11842 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
11844 /* Set last_unchanged_pos to the buffer position of the last
11845 character in the buffer that has not been changed. Z is the
11846 index + 1 of the last character in current_buffer, i.e. by
11847 subtracting END_UNCHANGED we get the index of the last
11848 unchanged character, and we have to add BEG to get its buffer
11850 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
11851 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
11853 /* Search backward from ROW for a row displaying a line that
11854 starts at a minimum position >= last_unchanged_pos_old. */
11855 for (; row
> first_text_row
; --row
)
11857 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11860 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
11865 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
11872 /* Make sure that glyph rows in the current matrix of window W
11873 reference the same glyph memory as corresponding rows in the
11874 frame's frame matrix. This function is called after scrolling W's
11875 current matrix on a terminal frame in try_window_id and
11876 try_window_reusing_current_matrix. */
11879 sync_frame_with_window_matrix_rows (w
)
11882 struct frame
*f
= XFRAME (w
->frame
);
11883 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
11885 /* Preconditions: W must be a leaf window and full-width. Its frame
11886 must have a frame matrix. */
11887 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
11888 xassert (WINDOW_FULL_WIDTH_P (w
));
11889 xassert (!FRAME_WINDOW_P (f
));
11891 /* If W is a full-width window, glyph pointers in W's current matrix
11892 have, by definition, to be the same as glyph pointers in the
11893 corresponding frame matrix. Note that frame matrices have no
11894 marginal areas (see build_frame_matrix). */
11895 window_row
= w
->current_matrix
->rows
;
11896 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
11897 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
11898 while (window_row
< window_row_end
)
11900 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
11901 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
11903 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
11904 frame_row
->glyphs
[TEXT_AREA
] = start
;
11905 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
11906 frame_row
->glyphs
[LAST_AREA
] = end
;
11908 /* Disable frame rows whose corresponding window rows have
11909 been disabled in try_window_id. */
11910 if (!window_row
->enabled_p
)
11911 frame_row
->enabled_p
= 0;
11913 ++window_row
, ++frame_row
;
11918 /* Find the glyph row in window W containing CHARPOS. Consider all
11919 rows between START and END (not inclusive). END null means search
11920 all rows to the end of the display area of W. Value is the row
11921 containing CHARPOS or null. */
11924 row_containing_pos (w
, charpos
, start
, end
, dy
)
11927 struct glyph_row
*start
, *end
;
11930 struct glyph_row
*row
= start
;
11933 /* If we happen to start on a header-line, skip that. */
11934 if (row
->mode_line_p
)
11937 if ((end
&& row
>= end
) || !row
->enabled_p
)
11940 last_y
= window_text_bottom_y (w
) - dy
;
11944 /* Give up if we have gone too far. */
11945 if (end
&& row
>= end
)
11947 /* This formerly returned if they were equal.
11948 I think that both quantities are of a "last plus one" type;
11949 if so, when they are equal, the row is within the screen. -- rms. */
11950 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
11953 /* If it is in this row, return this row. */
11954 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
11955 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
11956 /* The end position of a row equals the start
11957 position of the next row. If CHARPOS is there, we
11958 would rather display it in the next line, except
11959 when this line ends in ZV. */
11960 && !row
->ends_at_zv_p
11961 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11962 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
11969 /* Try to redisplay window W by reusing its existing display. W's
11970 current matrix must be up to date when this function is called,
11971 i.e. window_end_valid must not be nil.
11975 1 if display has been updated
11976 0 if otherwise unsuccessful
11977 -1 if redisplay with same window start is known not to succeed
11979 The following steps are performed:
11981 1. Find the last row in the current matrix of W that is not
11982 affected by changes at the start of current_buffer. If no such row
11985 2. Find the first row in W's current matrix that is not affected by
11986 changes at the end of current_buffer. Maybe there is no such row.
11988 3. Display lines beginning with the row + 1 found in step 1 to the
11989 row found in step 2 or, if step 2 didn't find a row, to the end of
11992 4. If cursor is not known to appear on the window, give up.
11994 5. If display stopped at the row found in step 2, scroll the
11995 display and current matrix as needed.
11997 6. Maybe display some lines at the end of W, if we must. This can
11998 happen under various circumstances, like a partially visible line
11999 becoming fully visible, or because newly displayed lines are displayed
12000 in smaller font sizes.
12002 7. Update W's window end information. */
12008 struct frame
*f
= XFRAME (w
->frame
);
12009 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12010 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12011 struct glyph_row
*last_unchanged_at_beg_row
;
12012 struct glyph_row
*first_unchanged_at_end_row
;
12013 struct glyph_row
*row
;
12014 struct glyph_row
*bottom_row
;
12017 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12018 struct text_pos start_pos
;
12020 int first_unchanged_at_end_vpos
= 0;
12021 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12022 struct text_pos start
;
12023 int first_changed_charpos
, last_changed_charpos
;
12026 if (inhibit_try_window_id
)
12030 /* This is handy for debugging. */
12032 #define GIVE_UP(X) \
12034 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12038 #define GIVE_UP(X) return 0
12041 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12043 /* Don't use this for mini-windows because these can show
12044 messages and mini-buffers, and we don't handle that here. */
12045 if (MINI_WINDOW_P (w
))
12048 /* This flag is used to prevent redisplay optimizations. */
12049 if (windows_or_buffers_changed
|| cursor_type_changed
)
12052 /* Verify that narrowing has not changed.
12053 Also verify that we were not told to prevent redisplay optimizations.
12054 It would be nice to further
12055 reduce the number of cases where this prevents try_window_id. */
12056 if (current_buffer
->clip_changed
12057 || current_buffer
->prevent_redisplay_optimizations_p
)
12060 /* Window must either use window-based redisplay or be full width. */
12061 if (!FRAME_WINDOW_P (f
)
12062 && (!line_ins_del_ok
12063 || !WINDOW_FULL_WIDTH_P (w
)))
12066 /* Give up if point is not known NOT to appear in W. */
12067 if (PT
< CHARPOS (start
))
12070 /* Another way to prevent redisplay optimizations. */
12071 if (XFASTINT (w
->last_modified
) == 0)
12074 /* Verify that window is not hscrolled. */
12075 if (XFASTINT (w
->hscroll
) != 0)
12078 /* Verify that display wasn't paused. */
12079 if (NILP (w
->window_end_valid
))
12082 /* Can't use this if highlighting a region because a cursor movement
12083 will do more than just set the cursor. */
12084 if (!NILP (Vtransient_mark_mode
)
12085 && !NILP (current_buffer
->mark_active
))
12088 /* Likewise if highlighting trailing whitespace. */
12089 if (!NILP (Vshow_trailing_whitespace
))
12092 /* Likewise if showing a region. */
12093 if (!NILP (w
->region_showing
))
12096 /* Can use this if overlay arrow position and or string have changed. */
12097 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
12098 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
12102 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
12103 only if buffer has really changed. The reason is that the gap is
12104 initially at Z for freshly visited files. The code below would
12105 set end_unchanged to 0 in that case. */
12106 if (MODIFF
> SAVE_MODIFF
12107 /* This seems to happen sometimes after saving a buffer. */
12108 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12110 if (GPT
- BEG
< BEG_UNCHANGED
)
12111 BEG_UNCHANGED
= GPT
- BEG
;
12112 if (Z
- GPT
< END_UNCHANGED
)
12113 END_UNCHANGED
= Z
- GPT
;
12116 /* The position of the first and last character that has been changed. */
12117 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
12118 last_changed_charpos
= Z
- END_UNCHANGED
;
12120 /* If window starts after a line end, and the last change is in
12121 front of that newline, then changes don't affect the display.
12122 This case happens with stealth-fontification. Note that although
12123 the display is unchanged, glyph positions in the matrix have to
12124 be adjusted, of course. */
12125 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12126 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12127 && ((last_changed_charpos
< CHARPOS (start
)
12128 && CHARPOS (start
) == BEGV
)
12129 || (last_changed_charpos
< CHARPOS (start
) - 1
12130 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
12132 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
12133 struct glyph_row
*r0
;
12135 /* Compute how many chars/bytes have been added to or removed
12136 from the buffer. */
12137 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12138 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12140 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12142 /* Give up if PT is not in the window. Note that it already has
12143 been checked at the start of try_window_id that PT is not in
12144 front of the window start. */
12145 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
12148 /* If window start is unchanged, we can reuse the whole matrix
12149 as is, after adjusting glyph positions. No need to compute
12150 the window end again, since its offset from Z hasn't changed. */
12151 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12152 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
12153 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
12155 /* Adjust positions in the glyph matrix. */
12156 if (delta
|| delta_bytes
)
12158 struct glyph_row
*r1
12159 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12160 increment_matrix_positions (w
->current_matrix
,
12161 MATRIX_ROW_VPOS (r0
, current_matrix
),
12162 MATRIX_ROW_VPOS (r1
, current_matrix
),
12163 delta
, delta_bytes
);
12166 /* Set the cursor. */
12167 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
12169 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
12176 /* Handle the case that changes are all below what is displayed in
12177 the window, and that PT is in the window. This shortcut cannot
12178 be taken if ZV is visible in the window, and text has been added
12179 there that is visible in the window. */
12180 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
12181 /* ZV is not visible in the window, or there are no
12182 changes at ZV, actually. */
12183 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
12184 || first_changed_charpos
== last_changed_charpos
))
12186 struct glyph_row
*r0
;
12188 /* Give up if PT is not in the window. Note that it already has
12189 been checked at the start of try_window_id that PT is not in
12190 front of the window start. */
12191 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
12194 /* If window start is unchanged, we can reuse the whole matrix
12195 as is, without changing glyph positions since no text has
12196 been added/removed in front of the window end. */
12197 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12198 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
12200 /* We have to compute the window end anew since text
12201 can have been added/removed after it. */
12203 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12204 w
->window_end_bytepos
12205 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12207 /* Set the cursor. */
12208 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
12210 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
12217 /* Give up if window start is in the changed area.
12219 The condition used to read
12221 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
12223 but why that was tested escapes me at the moment. */
12224 if (CHARPOS (start
) >= first_changed_charpos
12225 && CHARPOS (start
) <= last_changed_charpos
)
12228 /* Check that window start agrees with the start of the first glyph
12229 row in its current matrix. Check this after we know the window
12230 start is not in changed text, otherwise positions would not be
12232 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12233 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
12236 /* Give up if the window ends in strings. Overlay strings
12237 at the end are difficult to handle, so don't try. */
12238 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
12239 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
12242 /* Compute the position at which we have to start displaying new
12243 lines. Some of the lines at the top of the window might be
12244 reusable because they are not displaying changed text. Find the
12245 last row in W's current matrix not affected by changes at the
12246 start of current_buffer. Value is null if changes start in the
12247 first line of window. */
12248 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
12249 if (last_unchanged_at_beg_row
)
12251 /* Avoid starting to display in the moddle of a character, a TAB
12252 for instance. This is easier than to set up the iterator
12253 exactly, and it's not a frequent case, so the additional
12254 effort wouldn't really pay off. */
12255 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
12256 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
12257 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
12258 --last_unchanged_at_beg_row
;
12260 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
12263 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
12265 start_pos
= it
.current
.pos
;
12267 /* Start displaying new lines in the desired matrix at the same
12268 vpos we would use in the current matrix, i.e. below
12269 last_unchanged_at_beg_row. */
12270 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
12272 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12273 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
12275 xassert (it
.hpos
== 0 && it
.current_x
== 0);
12279 /* There are no reusable lines at the start of the window.
12280 Start displaying in the first line. */
12281 start_display (&it
, w
, start
);
12282 start_pos
= it
.current
.pos
;
12285 /* Find the first row that is not affected by changes at the end of
12286 the buffer. Value will be null if there is no unchanged row, in
12287 which case we must redisplay to the end of the window. delta
12288 will be set to the value by which buffer positions beginning with
12289 first_unchanged_at_end_row have to be adjusted due to text
12291 first_unchanged_at_end_row
12292 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
12293 IF_DEBUG (debug_delta
= delta
);
12294 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
12296 /* Set stop_pos to the buffer position up to which we will have to
12297 display new lines. If first_unchanged_at_end_row != NULL, this
12298 is the buffer position of the start of the line displayed in that
12299 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
12300 that we don't stop at a buffer position. */
12302 if (first_unchanged_at_end_row
)
12304 xassert (last_unchanged_at_beg_row
== NULL
12305 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
12307 /* If this is a continuation line, move forward to the next one
12308 that isn't. Changes in lines above affect this line.
12309 Caution: this may move first_unchanged_at_end_row to a row
12310 not displaying text. */
12311 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
12312 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
12313 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
12314 < it
.last_visible_y
))
12315 ++first_unchanged_at_end_row
;
12317 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
12318 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
12319 >= it
.last_visible_y
))
12320 first_unchanged_at_end_row
= NULL
;
12323 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
12325 first_unchanged_at_end_vpos
12326 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
12327 xassert (stop_pos
>= Z
- END_UNCHANGED
);
12330 else if (last_unchanged_at_beg_row
== NULL
)
12336 /* Either there is no unchanged row at the end, or the one we have
12337 now displays text. This is a necessary condition for the window
12338 end pos calculation at the end of this function. */
12339 xassert (first_unchanged_at_end_row
== NULL
12340 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
12342 debug_last_unchanged_at_beg_vpos
12343 = (last_unchanged_at_beg_row
12344 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
12346 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
12348 #endif /* GLYPH_DEBUG != 0 */
12351 /* Display new lines. Set last_text_row to the last new line
12352 displayed which has text on it, i.e. might end up as being the
12353 line where the window_end_vpos is. */
12354 w
->cursor
.vpos
= -1;
12355 last_text_row
= NULL
;
12356 overlay_arrow_seen
= 0;
12357 while (it
.current_y
< it
.last_visible_y
12358 && !fonts_changed_p
12359 && (first_unchanged_at_end_row
== NULL
12360 || IT_CHARPOS (it
) < stop_pos
))
12362 if (display_line (&it
))
12363 last_text_row
= it
.glyph_row
- 1;
12366 if (fonts_changed_p
)
12370 /* Compute differences in buffer positions, y-positions etc. for
12371 lines reused at the bottom of the window. Compute what we can
12373 if (first_unchanged_at_end_row
12374 /* No lines reused because we displayed everything up to the
12375 bottom of the window. */
12376 && it
.current_y
< it
.last_visible_y
)
12379 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
12381 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
12382 run
.current_y
= first_unchanged_at_end_row
->y
;
12383 run
.desired_y
= run
.current_y
+ dy
;
12384 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
12388 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
12389 first_unchanged_at_end_row
= NULL
;
12391 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
12394 /* Find the cursor if not already found. We have to decide whether
12395 PT will appear on this window (it sometimes doesn't, but this is
12396 not a very frequent case.) This decision has to be made before
12397 the current matrix is altered. A value of cursor.vpos < 0 means
12398 that PT is either in one of the lines beginning at
12399 first_unchanged_at_end_row or below the window. Don't care for
12400 lines that might be displayed later at the window end; as
12401 mentioned, this is not a frequent case. */
12402 if (w
->cursor
.vpos
< 0)
12404 /* Cursor in unchanged rows at the top? */
12405 if (PT
< CHARPOS (start_pos
)
12406 && last_unchanged_at_beg_row
)
12408 row
= row_containing_pos (w
, PT
,
12409 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
12410 last_unchanged_at_beg_row
+ 1, 0);
12412 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12415 /* Start from first_unchanged_at_end_row looking for PT. */
12416 else if (first_unchanged_at_end_row
)
12418 row
= row_containing_pos (w
, PT
- delta
,
12419 first_unchanged_at_end_row
, NULL
, 0);
12421 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
12422 delta_bytes
, dy
, dvpos
);
12425 /* Give up if cursor was not found. */
12426 if (w
->cursor
.vpos
< 0)
12428 clear_glyph_matrix (w
->desired_matrix
);
12433 /* Don't let the cursor end in the scroll margins. */
12435 int this_scroll_margin
, cursor_height
;
12437 this_scroll_margin
= max (0, scroll_margin
);
12438 this_scroll_margin
= min (this_scroll_margin
,
12439 XFASTINT (w
->height
) / 4);
12440 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
12441 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12443 if ((w
->cursor
.y
< this_scroll_margin
12444 && CHARPOS (start
) > BEGV
)
12445 /* Don't take scroll margin into account at the bottom because
12446 old redisplay didn't do it either. */
12447 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
12449 w
->cursor
.vpos
= -1;
12450 clear_glyph_matrix (w
->desired_matrix
);
12455 /* Scroll the display. Do it before changing the current matrix so
12456 that xterm.c doesn't get confused about where the cursor glyph is
12458 if (dy
&& run
.height
)
12462 if (FRAME_WINDOW_P (f
))
12464 rif
->update_window_begin_hook (w
);
12465 rif
->clear_mouse_face (w
);
12466 rif
->scroll_run_hook (w
, &run
);
12467 rif
->update_window_end_hook (w
, 0, 0);
12471 /* Terminal frame. In this case, dvpos gives the number of
12472 lines to scroll by; dvpos < 0 means scroll up. */
12473 int first_unchanged_at_end_vpos
12474 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
12475 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
12476 int end
= (XFASTINT (w
->top
)
12477 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
12478 + window_internal_height (w
));
12480 /* Perform the operation on the screen. */
12483 /* Scroll last_unchanged_at_beg_row to the end of the
12484 window down dvpos lines. */
12485 set_terminal_window (end
);
12487 /* On dumb terminals delete dvpos lines at the end
12488 before inserting dvpos empty lines. */
12489 if (!scroll_region_ok
)
12490 ins_del_lines (end
- dvpos
, -dvpos
);
12492 /* Insert dvpos empty lines in front of
12493 last_unchanged_at_beg_row. */
12494 ins_del_lines (from
, dvpos
);
12496 else if (dvpos
< 0)
12498 /* Scroll up last_unchanged_at_beg_vpos to the end of
12499 the window to last_unchanged_at_beg_vpos - |dvpos|. */
12500 set_terminal_window (end
);
12502 /* Delete dvpos lines in front of
12503 last_unchanged_at_beg_vpos. ins_del_lines will set
12504 the cursor to the given vpos and emit |dvpos| delete
12506 ins_del_lines (from
+ dvpos
, dvpos
);
12508 /* On a dumb terminal insert dvpos empty lines at the
12510 if (!scroll_region_ok
)
12511 ins_del_lines (end
+ dvpos
, -dvpos
);
12514 set_terminal_window (0);
12520 /* Shift reused rows of the current matrix to the right position.
12521 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
12523 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12524 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
12527 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
12528 bottom_vpos
, dvpos
);
12529 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
12532 else if (dvpos
> 0)
12534 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
12535 bottom_vpos
, dvpos
);
12536 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
12537 first_unchanged_at_end_vpos
+ dvpos
, 0);
12540 /* For frame-based redisplay, make sure that current frame and window
12541 matrix are in sync with respect to glyph memory. */
12542 if (!FRAME_WINDOW_P (f
))
12543 sync_frame_with_window_matrix_rows (w
);
12545 /* Adjust buffer positions in reused rows. */
12547 increment_matrix_positions (current_matrix
,
12548 first_unchanged_at_end_vpos
+ dvpos
,
12549 bottom_vpos
, delta
, delta_bytes
);
12551 /* Adjust Y positions. */
12553 shift_glyph_matrix (w
, current_matrix
,
12554 first_unchanged_at_end_vpos
+ dvpos
,
12557 if (first_unchanged_at_end_row
)
12558 first_unchanged_at_end_row
+= dvpos
;
12560 /* If scrolling up, there may be some lines to display at the end of
12562 last_text_row_at_end
= NULL
;
12565 /* Scrolling up can leave for example a partially visible line
12566 at the end of the window to be redisplayed. */
12567 /* Set last_row to the glyph row in the current matrix where the
12568 window end line is found. It has been moved up or down in
12569 the matrix by dvpos. */
12570 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
12571 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
12573 /* If last_row is the window end line, it should display text. */
12574 xassert (last_row
->displays_text_p
);
12576 /* If window end line was partially visible before, begin
12577 displaying at that line. Otherwise begin displaying with the
12578 line following it. */
12579 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
12581 init_to_row_start (&it
, w
, last_row
);
12582 it
.vpos
= last_vpos
;
12583 it
.current_y
= last_row
->y
;
12587 init_to_row_end (&it
, w
, last_row
);
12588 it
.vpos
= 1 + last_vpos
;
12589 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
12593 /* We may start in a continuation line. If so, we have to
12594 get the right continuation_lines_width and current_x. */
12595 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
12596 it
.hpos
= it
.current_x
= 0;
12598 /* Display the rest of the lines at the window end. */
12599 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12600 while (it
.current_y
< it
.last_visible_y
12601 && !fonts_changed_p
)
12603 /* Is it always sure that the display agrees with lines in
12604 the current matrix? I don't think so, so we mark rows
12605 displayed invalid in the current matrix by setting their
12606 enabled_p flag to zero. */
12607 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
12608 if (display_line (&it
))
12609 last_text_row_at_end
= it
.glyph_row
- 1;
12613 /* Update window_end_pos and window_end_vpos. */
12614 if (first_unchanged_at_end_row
12615 && first_unchanged_at_end_row
->y
< it
.last_visible_y
12616 && !last_text_row_at_end
)
12618 /* Window end line if one of the preserved rows from the current
12619 matrix. Set row to the last row displaying text in current
12620 matrix starting at first_unchanged_at_end_row, after
12622 xassert (first_unchanged_at_end_row
->displays_text_p
);
12623 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
12624 first_unchanged_at_end_row
);
12625 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
12627 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12628 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12630 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
12631 xassert (w
->window_end_bytepos
>= 0);
12632 IF_DEBUG (debug_method_add (w
, "A"));
12634 else if (last_text_row_at_end
)
12637 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
12638 w
->window_end_bytepos
12639 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
12641 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
12642 xassert (w
->window_end_bytepos
>= 0);
12643 IF_DEBUG (debug_method_add (w
, "B"));
12645 else if (last_text_row
)
12647 /* We have displayed either to the end of the window or at the
12648 end of the window, i.e. the last row with text is to be found
12649 in the desired matrix. */
12651 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12652 w
->window_end_bytepos
12653 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12655 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
12656 xassert (w
->window_end_bytepos
>= 0);
12658 else if (first_unchanged_at_end_row
== NULL
12659 && last_text_row
== NULL
12660 && last_text_row_at_end
== NULL
)
12662 /* Displayed to end of window, but no line containing text was
12663 displayed. Lines were deleted at the end of the window. */
12664 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
12665 int vpos
= XFASTINT (w
->window_end_vpos
);
12666 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
12667 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
12670 row
== NULL
&& vpos
>= first_vpos
;
12671 --vpos
, --current_row
, --desired_row
)
12673 if (desired_row
->enabled_p
)
12675 if (desired_row
->displays_text_p
)
12678 else if (current_row
->displays_text_p
)
12682 xassert (row
!= NULL
);
12683 w
->window_end_vpos
= make_number (vpos
+ 1);
12684 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12685 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12686 xassert (w
->window_end_bytepos
>= 0);
12687 IF_DEBUG (debug_method_add (w
, "C"));
12692 #if 0 /* This leads to problems, for instance when the cursor is
12693 at ZV, and the cursor line displays no text. */
12694 /* Disable rows below what's displayed in the window. This makes
12695 debugging easier. */
12696 enable_glyph_matrix_rows (current_matrix
,
12697 XFASTINT (w
->window_end_vpos
) + 1,
12701 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
12702 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
12704 /* Record that display has not been completed. */
12705 w
->window_end_valid
= Qnil
;
12706 w
->desired_matrix
->no_scrolling_p
= 1;
12714 /***********************************************************************
12715 More debugging support
12716 ***********************************************************************/
12720 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
12721 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
12722 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
12725 /* Dump the contents of glyph matrix MATRIX on stderr.
12727 GLYPHS 0 means don't show glyph contents.
12728 GLYPHS 1 means show glyphs in short form
12729 GLYPHS > 1 means show glyphs in long form. */
12732 dump_glyph_matrix (matrix
, glyphs
)
12733 struct glyph_matrix
*matrix
;
12737 for (i
= 0; i
< matrix
->nrows
; ++i
)
12738 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
12742 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
12743 the glyph row and area where the glyph comes from. */
12746 dump_glyph (row
, glyph
, area
)
12747 struct glyph_row
*row
;
12748 struct glyph
*glyph
;
12751 if (glyph
->type
== CHAR_GLYPH
)
12754 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12755 glyph
- row
->glyphs
[TEXT_AREA
],
12758 (BUFFERP (glyph
->object
)
12760 : (STRINGP (glyph
->object
)
12763 glyph
->pixel_width
,
12765 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
12769 glyph
->left_box_line_p
,
12770 glyph
->right_box_line_p
);
12772 else if (glyph
->type
== STRETCH_GLYPH
)
12775 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12776 glyph
- row
->glyphs
[TEXT_AREA
],
12779 (BUFFERP (glyph
->object
)
12781 : (STRINGP (glyph
->object
)
12784 glyph
->pixel_width
,
12788 glyph
->left_box_line_p
,
12789 glyph
->right_box_line_p
);
12791 else if (glyph
->type
== IMAGE_GLYPH
)
12794 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
12795 glyph
- row
->glyphs
[TEXT_AREA
],
12798 (BUFFERP (glyph
->object
)
12800 : (STRINGP (glyph
->object
)
12803 glyph
->pixel_width
,
12807 glyph
->left_box_line_p
,
12808 glyph
->right_box_line_p
);
12813 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
12814 GLYPHS 0 means don't show glyph contents.
12815 GLYPHS 1 means show glyphs in short form
12816 GLYPHS > 1 means show glyphs in long form. */
12819 dump_glyph_row (row
, vpos
, glyphs
)
12820 struct glyph_row
*row
;
12825 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
12826 fprintf (stderr
, "=======================================================================\n");
12828 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
12829 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
12831 MATRIX_ROW_START_CHARPOS (row
),
12832 MATRIX_ROW_END_CHARPOS (row
),
12833 row
->used
[TEXT_AREA
],
12834 row
->contains_overlapping_glyphs_p
,
12836 row
->truncated_on_left_p
,
12837 row
->truncated_on_right_p
,
12838 row
->overlay_arrow_p
,
12840 MATRIX_ROW_CONTINUATION_LINE_P (row
),
12841 row
->displays_text_p
,
12844 row
->ends_in_middle_of_char_p
,
12845 row
->starts_in_middle_of_char_p
,
12851 row
->visible_height
,
12854 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
12855 row
->end
.overlay_string_index
,
12856 row
->continuation_lines_width
);
12857 fprintf (stderr
, "%9d %5d\n",
12858 CHARPOS (row
->start
.string_pos
),
12859 CHARPOS (row
->end
.string_pos
));
12860 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
12861 row
->end
.dpvec_index
);
12868 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12870 struct glyph
*glyph
= row
->glyphs
[area
];
12871 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
12873 /* Glyph for a line end in text. */
12874 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
12877 if (glyph
< glyph_end
)
12878 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
12880 for (; glyph
< glyph_end
; ++glyph
)
12881 dump_glyph (row
, glyph
, area
);
12884 else if (glyphs
== 1)
12888 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
12890 char *s
= (char *) alloca (row
->used
[area
] + 1);
12893 for (i
= 0; i
< row
->used
[area
]; ++i
)
12895 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
12896 if (glyph
->type
== CHAR_GLYPH
12897 && glyph
->u
.ch
< 0x80
12898 && glyph
->u
.ch
>= ' ')
12899 s
[i
] = glyph
->u
.ch
;
12905 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
12911 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
12912 Sdump_glyph_matrix
, 0, 1, "p",
12913 doc
: /* Dump the current matrix of the selected window to stderr.
12914 Shows contents of glyph row structures. With non-nil
12915 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
12916 glyphs in short form, otherwise show glyphs in long form. */)
12918 Lisp_Object glyphs
;
12920 struct window
*w
= XWINDOW (selected_window
);
12921 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12923 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
12924 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
12925 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
12926 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
12927 fprintf (stderr
, "=============================================\n");
12928 dump_glyph_matrix (w
->current_matrix
,
12929 NILP (glyphs
) ? 0 : XINT (glyphs
));
12934 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
12935 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
12938 struct frame
*f
= XFRAME (selected_frame
);
12939 dump_glyph_matrix (f
->current_matrix
, 1);
12944 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
12945 doc
: /* Dump glyph row ROW to stderr.
12946 GLYPH 0 means don't dump glyphs.
12947 GLYPH 1 means dump glyphs in short form.
12948 GLYPH > 1 or omitted means dump glyphs in long form. */)
12950 Lisp_Object row
, glyphs
;
12952 struct glyph_matrix
*matrix
;
12955 CHECK_NUMBER (row
);
12956 matrix
= XWINDOW (selected_window
)->current_matrix
;
12958 if (vpos
>= 0 && vpos
< matrix
->nrows
)
12959 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
12961 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12966 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
12967 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
12968 GLYPH 0 means don't dump glyphs.
12969 GLYPH 1 means dump glyphs in short form.
12970 GLYPH > 1 or omitted means dump glyphs in long form. */)
12972 Lisp_Object row
, glyphs
;
12974 struct frame
*sf
= SELECTED_FRAME ();
12975 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
12978 CHECK_NUMBER (row
);
12980 if (vpos
>= 0 && vpos
< m
->nrows
)
12981 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
12982 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
12987 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
12988 doc
: /* Toggle tracing of redisplay.
12989 With ARG, turn tracing on if and only if ARG is positive. */)
12994 trace_redisplay_p
= !trace_redisplay_p
;
12997 arg
= Fprefix_numeric_value (arg
);
12998 trace_redisplay_p
= XINT (arg
) > 0;
13005 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13006 doc
: /* Like `format', but print result to stderr.
13007 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13012 Lisp_Object s
= Fformat (nargs
, args
);
13013 fprintf (stderr
, "%s", SDATA (s
));
13017 #endif /* GLYPH_DEBUG */
13021 /***********************************************************************
13022 Building Desired Matrix Rows
13023 ***********************************************************************/
13025 /* Return a temporary glyph row holding the glyphs of an overlay
13026 arrow. Only used for non-window-redisplay windows. */
13028 static struct glyph_row
*
13029 get_overlay_arrow_glyph_row (w
)
13032 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13033 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13034 struct buffer
*old
= current_buffer
;
13035 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
13036 int arrow_len
= SCHARS (Voverlay_arrow_string
);
13037 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13038 const unsigned char *p
;
13041 int n_glyphs_before
;
13043 set_buffer_temp (buffer
);
13044 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13045 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13046 SET_TEXT_POS (it
.position
, 0, 0);
13048 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13050 while (p
< arrow_end
)
13052 Lisp_Object face
, ilisp
;
13054 /* Get the next character. */
13056 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13058 it
.c
= *p
, it
.len
= 1;
13061 /* Get its face. */
13062 ilisp
= make_number (p
- arrow_string
);
13063 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
13064 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13066 /* Compute its width, get its glyphs. */
13067 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13068 SET_TEXT_POS (it
.position
, -1, -1);
13069 PRODUCE_GLYPHS (&it
);
13071 /* If this character doesn't fit any more in the line, we have
13072 to remove some glyphs. */
13073 if (it
.current_x
> it
.last_visible_x
)
13075 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13080 set_buffer_temp (old
);
13081 return it
.glyph_row
;
13085 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
13086 glyphs are only inserted for terminal frames since we can't really
13087 win with truncation glyphs when partially visible glyphs are
13088 involved. Which glyphs to insert is determined by
13089 produce_special_glyphs. */
13092 insert_left_trunc_glyphs (it
)
13095 struct it truncate_it
;
13096 struct glyph
*from
, *end
, *to
, *toend
;
13098 xassert (!FRAME_WINDOW_P (it
->f
));
13100 /* Get the truncation glyphs. */
13102 truncate_it
.current_x
= 0;
13103 truncate_it
.face_id
= DEFAULT_FACE_ID
;
13104 truncate_it
.glyph_row
= &scratch_glyph_row
;
13105 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
13106 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
13107 truncate_it
.object
= make_number (0);
13108 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
13110 /* Overwrite glyphs from IT with truncation glyphs. */
13111 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13112 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
13113 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
13114 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
13119 /* There may be padding glyphs left over. Overwrite them too. */
13120 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
13122 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13128 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
13132 /* Compute the pixel height and width of IT->glyph_row.
13134 Most of the time, ascent and height of a display line will be equal
13135 to the max_ascent and max_height values of the display iterator
13136 structure. This is not the case if
13138 1. We hit ZV without displaying anything. In this case, max_ascent
13139 and max_height will be zero.
13141 2. We have some glyphs that don't contribute to the line height.
13142 (The glyph row flag contributes_to_line_height_p is for future
13143 pixmap extensions).
13145 The first case is easily covered by using default values because in
13146 these cases, the line height does not really matter, except that it
13147 must not be zero. */
13150 compute_line_metrics (it
)
13153 struct glyph_row
*row
= it
->glyph_row
;
13156 if (FRAME_WINDOW_P (it
->f
))
13158 int i
, min_y
, max_y
;
13160 /* The line may consist of one space only, that was added to
13161 place the cursor on it. If so, the row's height hasn't been
13163 if (row
->height
== 0)
13165 if (it
->max_ascent
+ it
->max_descent
== 0)
13166 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
13167 row
->ascent
= it
->max_ascent
;
13168 row
->height
= it
->max_ascent
+ it
->max_descent
;
13169 row
->phys_ascent
= it
->max_phys_ascent
;
13170 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13173 /* Compute the width of this line. */
13174 row
->pixel_width
= row
->x
;
13175 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
13176 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
13178 xassert (row
->pixel_width
>= 0);
13179 xassert (row
->ascent
>= 0 && row
->height
> 0);
13181 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
13182 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
13184 /* If first line's physical ascent is larger than its logical
13185 ascent, use the physical ascent, and make the row taller.
13186 This makes accented characters fully visible. */
13187 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
13188 && row
->phys_ascent
> row
->ascent
)
13190 row
->height
+= row
->phys_ascent
- row
->ascent
;
13191 row
->ascent
= row
->phys_ascent
;
13194 /* Compute how much of the line is visible. */
13195 row
->visible_height
= row
->height
;
13197 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
13198 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
13200 if (row
->y
< min_y
)
13201 row
->visible_height
-= min_y
- row
->y
;
13202 if (row
->y
+ row
->height
> max_y
)
13203 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13207 row
->pixel_width
= row
->used
[TEXT_AREA
];
13208 if (row
->continued_p
)
13209 row
->pixel_width
-= it
->continuation_pixel_width
;
13210 else if (row
->truncated_on_right_p
)
13211 row
->pixel_width
-= it
->truncation_pixel_width
;
13212 row
->ascent
= row
->phys_ascent
= 0;
13213 row
->height
= row
->phys_height
= row
->visible_height
= 1;
13216 /* Compute a hash code for this row. */
13218 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13219 for (i
= 0; i
< row
->used
[area
]; ++i
)
13220 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
13221 + row
->glyphs
[area
][i
].u
.val
13222 + row
->glyphs
[area
][i
].face_id
13223 + row
->glyphs
[area
][i
].padding_p
13224 + (row
->glyphs
[area
][i
].type
<< 2));
13226 it
->max_ascent
= it
->max_descent
= 0;
13227 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
13231 /* Append one space to the glyph row of iterator IT if doing a
13232 window-based redisplay. DEFAULT_FACE_P non-zero means let the
13233 space have the default face, otherwise let it have the same face as
13234 IT->face_id. Value is non-zero if a space was added.
13236 This function is called to make sure that there is always one glyph
13237 at the end of a glyph row that the cursor can be set on under
13238 window-systems. (If there weren't such a glyph we would not know
13239 how wide and tall a box cursor should be displayed).
13241 At the same time this space let's a nicely handle clearing to the
13242 end of the line if the row ends in italic text. */
13245 append_space (it
, default_face_p
)
13247 int default_face_p
;
13249 if (FRAME_WINDOW_P (it
->f
))
13251 int n
= it
->glyph_row
->used
[TEXT_AREA
];
13253 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
13254 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
13256 /* Save some values that must not be changed.
13257 Must save IT->c and IT->len because otherwise
13258 ITERATOR_AT_END_P wouldn't work anymore after
13259 append_space has been called. */
13260 enum display_element_type saved_what
= it
->what
;
13261 int saved_c
= it
->c
, saved_len
= it
->len
;
13262 int saved_x
= it
->current_x
;
13263 int saved_face_id
= it
->face_id
;
13264 struct text_pos saved_pos
;
13265 Lisp_Object saved_object
;
13268 saved_object
= it
->object
;
13269 saved_pos
= it
->position
;
13271 it
->what
= IT_CHARACTER
;
13272 bzero (&it
->position
, sizeof it
->position
);
13273 it
->object
= make_number (0);
13277 if (default_face_p
)
13278 it
->face_id
= DEFAULT_FACE_ID
;
13279 else if (it
->face_before_selective_p
)
13280 it
->face_id
= it
->saved_face_id
;
13281 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13282 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
13284 PRODUCE_GLYPHS (it
);
13286 it
->current_x
= saved_x
;
13287 it
->object
= saved_object
;
13288 it
->position
= saved_pos
;
13289 it
->what
= saved_what
;
13290 it
->face_id
= saved_face_id
;
13291 it
->len
= saved_len
;
13301 /* Extend the face of the last glyph in the text area of IT->glyph_row
13302 to the end of the display line. Called from display_line.
13303 If the glyph row is empty, add a space glyph to it so that we
13304 know the face to draw. Set the glyph row flag fill_line_p. */
13307 extend_face_to_end_of_line (it
)
13311 struct frame
*f
= it
->f
;
13313 /* If line is already filled, do nothing. */
13314 if (it
->current_x
>= it
->last_visible_x
)
13317 /* Face extension extends the background and box of IT->face_id
13318 to the end of the line. If the background equals the background
13319 of the frame, we don't have to do anything. */
13320 if (it
->face_before_selective_p
)
13321 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
13323 face
= FACE_FROM_ID (f
, it
->face_id
);
13325 if (FRAME_WINDOW_P (f
)
13326 && face
->box
== FACE_NO_BOX
13327 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
13331 /* Set the glyph row flag indicating that the face of the last glyph
13332 in the text area has to be drawn to the end of the text area. */
13333 it
->glyph_row
->fill_line_p
= 1;
13335 /* If current character of IT is not ASCII, make sure we have the
13336 ASCII face. This will be automatically undone the next time
13337 get_next_display_element returns a multibyte character. Note
13338 that the character will always be single byte in unibyte text. */
13339 if (!SINGLE_BYTE_CHAR_P (it
->c
))
13341 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
13344 if (FRAME_WINDOW_P (f
))
13346 /* If the row is empty, add a space with the current face of IT,
13347 so that we know which face to draw. */
13348 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
13350 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
13351 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
13352 it
->glyph_row
->used
[TEXT_AREA
] = 1;
13357 /* Save some values that must not be changed. */
13358 int saved_x
= it
->current_x
;
13359 struct text_pos saved_pos
;
13360 Lisp_Object saved_object
;
13361 enum display_element_type saved_what
= it
->what
;
13362 int saved_face_id
= it
->face_id
;
13364 saved_object
= it
->object
;
13365 saved_pos
= it
->position
;
13367 it
->what
= IT_CHARACTER
;
13368 bzero (&it
->position
, sizeof it
->position
);
13369 it
->object
= make_number (0);
13372 it
->face_id
= face
->id
;
13374 PRODUCE_GLYPHS (it
);
13376 while (it
->current_x
<= it
->last_visible_x
)
13377 PRODUCE_GLYPHS (it
);
13379 /* Don't count these blanks really. It would let us insert a left
13380 truncation glyph below and make us set the cursor on them, maybe. */
13381 it
->current_x
= saved_x
;
13382 it
->object
= saved_object
;
13383 it
->position
= saved_pos
;
13384 it
->what
= saved_what
;
13385 it
->face_id
= saved_face_id
;
13390 /* Value is non-zero if text starting at CHARPOS in current_buffer is
13391 trailing whitespace. */
13394 trailing_whitespace_p (charpos
)
13397 int bytepos
= CHAR_TO_BYTE (charpos
);
13400 while (bytepos
< ZV_BYTE
13401 && (c
= FETCH_CHAR (bytepos
),
13402 c
== ' ' || c
== '\t'))
13405 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
13407 if (bytepos
!= PT_BYTE
)
13414 /* Highlight trailing whitespace, if any, in ROW. */
13417 highlight_trailing_whitespace (f
, row
)
13419 struct glyph_row
*row
;
13421 int used
= row
->used
[TEXT_AREA
];
13425 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
13426 struct glyph
*glyph
= start
+ used
- 1;
13428 /* Skip over glyphs inserted to display the cursor at the
13429 end of a line, for extending the face of the last glyph
13430 to the end of the line on terminals, and for truncation
13431 and continuation glyphs. */
13432 while (glyph
>= start
13433 && glyph
->type
== CHAR_GLYPH
13434 && INTEGERP (glyph
->object
))
13437 /* If last glyph is a space or stretch, and it's trailing
13438 whitespace, set the face of all trailing whitespace glyphs in
13439 IT->glyph_row to `trailing-whitespace'. */
13441 && BUFFERP (glyph
->object
)
13442 && (glyph
->type
== STRETCH_GLYPH
13443 || (glyph
->type
== CHAR_GLYPH
13444 && glyph
->u
.ch
== ' '))
13445 && trailing_whitespace_p (glyph
->charpos
))
13447 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
13449 while (glyph
>= start
13450 && BUFFERP (glyph
->object
)
13451 && (glyph
->type
== STRETCH_GLYPH
13452 || (glyph
->type
== CHAR_GLYPH
13453 && glyph
->u
.ch
== ' ')))
13454 (glyph
--)->face_id
= face_id
;
13460 /* Value is non-zero if glyph row ROW in window W should be
13461 used to hold the cursor. */
13464 cursor_row_p (w
, row
)
13466 struct glyph_row
*row
;
13468 int cursor_row_p
= 1;
13470 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
13472 /* If the row ends with a newline from a string, we don't want
13473 the cursor there (if the row is continued it doesn't end in a
13475 if (CHARPOS (row
->end
.string_pos
) >= 0
13476 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13477 cursor_row_p
= row
->continued_p
;
13479 /* If the row ends at ZV, display the cursor at the end of that
13480 row instead of at the start of the row below. */
13481 else if (row
->ends_at_zv_p
)
13487 return cursor_row_p
;
13491 /* Construct the glyph row IT->glyph_row in the desired matrix of
13492 IT->w from text at the current position of IT. See dispextern.h
13493 for an overview of struct it. Value is non-zero if
13494 IT->glyph_row displays text, as opposed to a line displaying ZV
13501 struct glyph_row
*row
= it
->glyph_row
;
13503 /* We always start displaying at hpos zero even if hscrolled. */
13504 xassert (it
->hpos
== 0 && it
->current_x
== 0);
13506 /* We must not display in a row that's not a text row. */
13507 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
13508 < it
->w
->desired_matrix
->nrows
);
13510 /* Is IT->w showing the region? */
13511 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
13513 /* Clear the result glyph row and enable it. */
13514 prepare_desired_row (row
);
13516 row
->y
= it
->current_y
;
13517 row
->start
= it
->current
;
13518 row
->continuation_lines_width
= it
->continuation_lines_width
;
13519 row
->displays_text_p
= 1;
13520 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
13521 it
->starts_in_middle_of_char_p
= 0;
13523 /* Arrange the overlays nicely for our purposes. Usually, we call
13524 display_line on only one line at a time, in which case this
13525 can't really hurt too much, or we call it on lines which appear
13526 one after another in the buffer, in which case all calls to
13527 recenter_overlay_lists but the first will be pretty cheap. */
13528 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
13530 /* Move over display elements that are not visible because we are
13531 hscrolled. This may stop at an x-position < IT->first_visible_x
13532 if the first glyph is partially visible or if we hit a line end. */
13533 if (it
->current_x
< it
->first_visible_x
)
13534 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
13535 MOVE_TO_POS
| MOVE_TO_X
);
13537 /* Get the initial row height. This is either the height of the
13538 text hscrolled, if there is any, or zero. */
13539 row
->ascent
= it
->max_ascent
;
13540 row
->height
= it
->max_ascent
+ it
->max_descent
;
13541 row
->phys_ascent
= it
->max_phys_ascent
;
13542 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13544 /* Loop generating characters. The loop is left with IT on the next
13545 character to display. */
13548 int n_glyphs_before
, hpos_before
, x_before
;
13550 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
13552 /* Retrieve the next thing to display. Value is zero if end of
13554 if (!get_next_display_element (it
))
13556 /* Maybe add a space at the end of this line that is used to
13557 display the cursor there under X. Set the charpos of the
13558 first glyph of blank lines not corresponding to any text
13560 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
13561 || row
->used
[TEXT_AREA
] == 0)
13563 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
13564 row
->displays_text_p
= 0;
13566 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
13567 && (!MINI_WINDOW_P (it
->w
)
13568 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
13569 row
->indicate_empty_line_p
= 1;
13572 it
->continuation_lines_width
= 0;
13573 row
->ends_at_zv_p
= 1;
13577 /* Now, get the metrics of what we want to display. This also
13578 generates glyphs in `row' (which is IT->glyph_row). */
13579 n_glyphs_before
= row
->used
[TEXT_AREA
];
13582 /* Remember the line height so far in case the next element doesn't
13583 fit on the line. */
13584 if (!it
->truncate_lines_p
)
13586 ascent
= it
->max_ascent
;
13587 descent
= it
->max_descent
;
13588 phys_ascent
= it
->max_phys_ascent
;
13589 phys_descent
= it
->max_phys_descent
;
13592 PRODUCE_GLYPHS (it
);
13594 /* If this display element was in marginal areas, continue with
13596 if (it
->area
!= TEXT_AREA
)
13598 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13599 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13600 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13601 row
->phys_height
= max (row
->phys_height
,
13602 it
->max_phys_ascent
+ it
->max_phys_descent
);
13603 set_iterator_to_next (it
, 1);
13607 /* Does the display element fit on the line? If we truncate
13608 lines, we should draw past the right edge of the window. If
13609 we don't truncate, we want to stop so that we can display the
13610 continuation glyph before the right margin. If lines are
13611 continued, there are two possible strategies for characters
13612 resulting in more than 1 glyph (e.g. tabs): Display as many
13613 glyphs as possible in this line and leave the rest for the
13614 continuation line, or display the whole element in the next
13615 line. Original redisplay did the former, so we do it also. */
13616 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
13617 hpos_before
= it
->hpos
;
13620 if (/* Not a newline. */
13622 /* Glyphs produced fit entirely in the line. */
13623 && it
->current_x
< it
->last_visible_x
)
13625 it
->hpos
+= nglyphs
;
13626 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13627 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13628 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13629 row
->phys_height
= max (row
->phys_height
,
13630 it
->max_phys_ascent
+ it
->max_phys_descent
);
13631 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
13632 row
->x
= x
- it
->first_visible_x
;
13637 struct glyph
*glyph
;
13639 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
13641 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
13642 new_x
= x
+ glyph
->pixel_width
;
13644 if (/* Lines are continued. */
13645 !it
->truncate_lines_p
13646 && (/* Glyph doesn't fit on the line. */
13647 new_x
> it
->last_visible_x
13648 /* Or it fits exactly on a window system frame. */
13649 || (new_x
== it
->last_visible_x
13650 && FRAME_WINDOW_P (it
->f
))))
13652 /* End of a continued line. */
13655 || (new_x
== it
->last_visible_x
13656 && FRAME_WINDOW_P (it
->f
)))
13658 /* Current glyph is the only one on the line or
13659 fits exactly on the line. We must continue
13660 the line because we can't draw the cursor
13661 after the glyph. */
13662 row
->continued_p
= 1;
13663 it
->current_x
= new_x
;
13664 it
->continuation_lines_width
+= new_x
;
13666 if (i
== nglyphs
- 1)
13667 set_iterator_to_next (it
, 1);
13669 else if (CHAR_GLYPH_PADDING_P (*glyph
)
13670 && !FRAME_WINDOW_P (it
->f
))
13672 /* A padding glyph that doesn't fit on this line.
13673 This means the whole character doesn't fit
13675 row
->used
[TEXT_AREA
] = n_glyphs_before
;
13677 /* Fill the rest of the row with continuation
13678 glyphs like in 20.x. */
13679 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
13680 < row
->glyphs
[1 + TEXT_AREA
])
13681 produce_special_glyphs (it
, IT_CONTINUATION
);
13683 row
->continued_p
= 1;
13684 it
->current_x
= x_before
;
13685 it
->continuation_lines_width
+= x_before
;
13687 /* Restore the height to what it was before the
13688 element not fitting on the line. */
13689 it
->max_ascent
= ascent
;
13690 it
->max_descent
= descent
;
13691 it
->max_phys_ascent
= phys_ascent
;
13692 it
->max_phys_descent
= phys_descent
;
13694 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
13696 /* A TAB that extends past the right edge of the
13697 window. This produces a single glyph on
13698 window system frames. We leave the glyph in
13699 this row and let it fill the row, but don't
13700 consume the TAB. */
13701 it
->continuation_lines_width
+= it
->last_visible_x
;
13702 row
->ends_in_middle_of_char_p
= 1;
13703 row
->continued_p
= 1;
13704 glyph
->pixel_width
= it
->last_visible_x
- x
;
13705 it
->starts_in_middle_of_char_p
= 1;
13709 /* Something other than a TAB that draws past
13710 the right edge of the window. Restore
13711 positions to values before the element. */
13712 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
13714 /* Display continuation glyphs. */
13715 if (!FRAME_WINDOW_P (it
->f
))
13716 produce_special_glyphs (it
, IT_CONTINUATION
);
13717 row
->continued_p
= 1;
13719 it
->continuation_lines_width
+= x
;
13721 if (nglyphs
> 1 && i
> 0)
13723 row
->ends_in_middle_of_char_p
= 1;
13724 it
->starts_in_middle_of_char_p
= 1;
13727 /* Restore the height to what it was before the
13728 element not fitting on the line. */
13729 it
->max_ascent
= ascent
;
13730 it
->max_descent
= descent
;
13731 it
->max_phys_ascent
= phys_ascent
;
13732 it
->max_phys_descent
= phys_descent
;
13737 else if (new_x
> it
->first_visible_x
)
13739 /* Increment number of glyphs actually displayed. */
13742 if (x
< it
->first_visible_x
)
13743 /* Glyph is partially visible, i.e. row starts at
13744 negative X position. */
13745 row
->x
= x
- it
->first_visible_x
;
13749 /* Glyph is completely off the left margin of the
13750 window. This should not happen because of the
13751 move_it_in_display_line at the start of this
13752 function, unless the text display area of the
13753 window is empty. */
13754 xassert (it
->first_visible_x
<= it
->last_visible_x
);
13758 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
13759 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
13760 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
13761 row
->phys_height
= max (row
->phys_height
,
13762 it
->max_phys_ascent
+ it
->max_phys_descent
);
13764 /* End of this display line if row is continued. */
13765 if (row
->continued_p
)
13769 /* Is this a line end? If yes, we're also done, after making
13770 sure that a non-default face is extended up to the right
13771 margin of the window. */
13772 if (ITERATOR_AT_END_OF_LINE_P (it
))
13774 int used_before
= row
->used
[TEXT_AREA
];
13776 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
13778 /* Add a space at the end of the line that is used to
13779 display the cursor there. */
13780 append_space (it
, 0);
13782 /* Extend the face to the end of the line. */
13783 extend_face_to_end_of_line (it
);
13785 /* Make sure we have the position. */
13786 if (used_before
== 0)
13787 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
13789 /* Consume the line end. This skips over invisible lines. */
13790 set_iterator_to_next (it
, 1);
13791 it
->continuation_lines_width
= 0;
13795 /* Proceed with next display element. Note that this skips
13796 over lines invisible because of selective display. */
13797 set_iterator_to_next (it
, 1);
13799 /* If we truncate lines, we are done when the last displayed
13800 glyphs reach past the right margin of the window. */
13801 if (it
->truncate_lines_p
13802 && (FRAME_WINDOW_P (it
->f
)
13803 ? (it
->current_x
>= it
->last_visible_x
)
13804 : (it
->current_x
> it
->last_visible_x
)))
13806 /* Maybe add truncation glyphs. */
13807 if (!FRAME_WINDOW_P (it
->f
))
13811 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
13812 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
13815 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
13817 row
->used
[TEXT_AREA
] = i
;
13818 produce_special_glyphs (it
, IT_TRUNCATION
);
13822 row
->truncated_on_right_p
= 1;
13823 it
->continuation_lines_width
= 0;
13824 reseat_at_next_visible_line_start (it
, 0);
13825 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
13826 it
->hpos
= hpos_before
;
13827 it
->current_x
= x_before
;
13832 /* If line is not empty and hscrolled, maybe insert truncation glyphs
13833 at the left window margin. */
13834 if (it
->first_visible_x
13835 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
13837 if (!FRAME_WINDOW_P (it
->f
))
13838 insert_left_trunc_glyphs (it
);
13839 row
->truncated_on_left_p
= 1;
13842 /* If the start of this line is the overlay arrow-position, then
13843 mark this glyph row as the one containing the overlay arrow.
13844 This is clearly a mess with variable size fonts. It would be
13845 better to let it be displayed like cursors under X. */
13846 if (MARKERP (Voverlay_arrow_position
)
13847 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
13848 && (MATRIX_ROW_START_CHARPOS (row
)
13849 == marker_position (Voverlay_arrow_position
))
13850 && STRINGP (Voverlay_arrow_string
)
13851 && ! overlay_arrow_seen
)
13853 /* Overlay arrow in window redisplay is a fringe bitmap. */
13854 if (!FRAME_WINDOW_P (it
->f
))
13856 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
13857 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
13858 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
13859 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
13860 struct glyph
*p2
, *end
;
13862 /* Copy the arrow glyphs. */
13863 while (glyph
< arrow_end
)
13866 /* Throw away padding glyphs. */
13868 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
13869 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
13875 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
13879 overlay_arrow_seen
= 1;
13880 row
->overlay_arrow_p
= 1;
13883 /* Compute pixel dimensions of this line. */
13884 compute_line_metrics (it
);
13886 /* Remember the position at which this line ends. */
13887 row
->end
= it
->current
;
13889 /* Maybe set the cursor. */
13890 if (it
->w
->cursor
.vpos
< 0
13891 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
13892 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13893 && cursor_row_p (it
->w
, row
))
13894 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
13896 /* Highlight trailing whitespace. */
13897 if (!NILP (Vshow_trailing_whitespace
))
13898 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
13900 /* Prepare for the next line. This line starts horizontally at (X
13901 HPOS) = (0 0). Vertical positions are incremented. As a
13902 convenience for the caller, IT->glyph_row is set to the next
13904 it
->current_x
= it
->hpos
= 0;
13905 it
->current_y
+= row
->height
;
13908 return row
->displays_text_p
;
13913 /***********************************************************************
13915 ***********************************************************************/
13917 /* Redisplay the menu bar in the frame for window W.
13919 The menu bar of X frames that don't have X toolkit support is
13920 displayed in a special window W->frame->menu_bar_window.
13922 The menu bar of terminal frames is treated specially as far as
13923 glyph matrices are concerned. Menu bar lines are not part of
13924 windows, so the update is done directly on the frame matrix rows
13925 for the menu bar. */
13928 display_menu_bar (w
)
13931 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13936 /* Don't do all this for graphical frames. */
13938 if (!NILP (Vwindow_system
))
13941 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
13946 if (FRAME_MAC_P (f
))
13950 #ifdef USE_X_TOOLKIT
13951 xassert (!FRAME_WINDOW_P (f
));
13952 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
13953 it
.first_visible_x
= 0;
13954 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13955 #else /* not USE_X_TOOLKIT */
13956 if (FRAME_WINDOW_P (f
))
13958 /* Menu bar lines are displayed in the desired matrix of the
13959 dummy window menu_bar_window. */
13960 struct window
*menu_w
;
13961 xassert (WINDOWP (f
->menu_bar_window
));
13962 menu_w
= XWINDOW (f
->menu_bar_window
);
13963 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
13965 it
.first_visible_x
= 0;
13966 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
13970 /* This is a TTY frame, i.e. character hpos/vpos are used as
13972 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
13974 it
.first_visible_x
= 0;
13975 it
.last_visible_x
= FRAME_WIDTH (f
);
13977 #endif /* not USE_X_TOOLKIT */
13979 if (! mode_line_inverse_video
)
13980 /* Force the menu-bar to be displayed in the default face. */
13981 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
13983 /* Clear all rows of the menu bar. */
13984 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
13986 struct glyph_row
*row
= it
.glyph_row
+ i
;
13987 clear_glyph_row (row
);
13988 row
->enabled_p
= 1;
13989 row
->full_width_p
= 1;
13992 /* Display all items of the menu bar. */
13993 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
13994 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
13996 Lisp_Object string
;
13998 /* Stop at nil string. */
13999 string
= AREF (items
, i
+ 1);
14003 /* Remember where item was displayed. */
14004 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14006 /* Display the item, pad with one space. */
14007 if (it
.current_x
< it
.last_visible_x
)
14008 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14009 SCHARS (string
) + 1, 0, 0, -1);
14012 /* Fill out the line with spaces. */
14013 if (it
.current_x
< it
.last_visible_x
)
14014 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
14016 /* Compute the total height of the lines. */
14017 compute_line_metrics (&it
);
14022 /***********************************************************************
14024 ***********************************************************************/
14026 /* Redisplay mode lines in the window tree whose root is WINDOW. If
14027 FORCE is non-zero, redisplay mode lines unconditionally.
14028 Otherwise, redisplay only mode lines that are garbaged. Value is
14029 the number of windows whose mode lines were redisplayed. */
14032 redisplay_mode_lines (window
, force
)
14033 Lisp_Object window
;
14038 while (!NILP (window
))
14040 struct window
*w
= XWINDOW (window
);
14042 if (WINDOWP (w
->hchild
))
14043 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
14044 else if (WINDOWP (w
->vchild
))
14045 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
14047 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
14048 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
14050 struct text_pos lpoint
;
14051 struct buffer
*old
= current_buffer
;
14053 /* Set the window's buffer for the mode line display. */
14054 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14055 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14057 /* Point refers normally to the selected window. For any
14058 other window, set up appropriate value. */
14059 if (!EQ (window
, selected_window
))
14061 struct text_pos pt
;
14063 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
14064 if (CHARPOS (pt
) < BEGV
)
14065 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14066 else if (CHARPOS (pt
) > (ZV
- 1))
14067 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
14069 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
14072 /* Display mode lines. */
14073 clear_glyph_matrix (w
->desired_matrix
);
14074 if (display_mode_lines (w
))
14077 w
->must_be_updated_p
= 1;
14080 /* Restore old settings. */
14081 set_buffer_internal_1 (old
);
14082 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14092 /* Display the mode and/or top line of window W. Value is the number
14093 of mode lines displayed. */
14096 display_mode_lines (w
)
14099 Lisp_Object old_selected_window
, old_selected_frame
;
14102 old_selected_frame
= selected_frame
;
14103 selected_frame
= w
->frame
;
14104 old_selected_window
= selected_window
;
14105 XSETWINDOW (selected_window
, w
);
14107 /* These will be set while the mode line specs are processed. */
14108 line_number_displayed
= 0;
14109 w
->column_number_displayed
= Qnil
;
14111 if (WINDOW_WANTS_MODELINE_P (w
))
14113 struct window
*sel_w
= XWINDOW (old_selected_window
);
14115 /* Select mode line face based on the real selected window. */
14116 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
14117 current_buffer
->mode_line_format
);
14121 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14123 display_mode_line (w
, HEADER_LINE_FACE_ID
,
14124 current_buffer
->header_line_format
);
14128 selected_frame
= old_selected_frame
;
14129 selected_window
= old_selected_window
;
14134 /* Display mode or top line of window W. FACE_ID specifies which line
14135 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
14136 FORMAT is the mode line format to display. Value is the pixel
14137 height of the mode line displayed. */
14140 display_mode_line (w
, face_id
, format
)
14142 enum face_id face_id
;
14143 Lisp_Object format
;
14148 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14149 prepare_desired_row (it
.glyph_row
);
14151 if (! mode_line_inverse_video
)
14152 /* Force the mode-line to be displayed in the default face. */
14153 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14155 /* Temporarily make frame's keyboard the current kboard so that
14156 kboard-local variables in the mode_line_format will get the right
14158 push_frame_kboard (it
.f
);
14159 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14160 pop_frame_kboard ();
14162 /* Fill up with spaces. */
14163 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
14165 compute_line_metrics (&it
);
14166 it
.glyph_row
->full_width_p
= 1;
14167 it
.glyph_row
->mode_line_p
= 1;
14168 it
.glyph_row
->continued_p
= 0;
14169 it
.glyph_row
->truncated_on_left_p
= 0;
14170 it
.glyph_row
->truncated_on_right_p
= 0;
14172 /* Make a 3D mode-line have a shadow at its right end. */
14173 face
= FACE_FROM_ID (it
.f
, face_id
);
14174 extend_face_to_end_of_line (&it
);
14175 if (face
->box
!= FACE_NO_BOX
)
14177 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
14178 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
14179 last
->right_box_line_p
= 1;
14182 return it
.glyph_row
->height
;
14185 /* Alist that caches the results of :propertize.
14186 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
14187 Lisp_Object mode_line_proptrans_alist
;
14189 /* List of strings making up the mode-line. */
14190 Lisp_Object mode_line_string_list
;
14192 /* Base face property when building propertized mode line string. */
14193 static Lisp_Object mode_line_string_face
;
14194 static Lisp_Object mode_line_string_face_prop
;
14197 /* Contribute ELT to the mode line for window IT->w. How it
14198 translates into text depends on its data type.
14200 IT describes the display environment in which we display, as usual.
14202 DEPTH is the depth in recursion. It is used to prevent
14203 infinite recursion here.
14205 FIELD_WIDTH is the number of characters the display of ELT should
14206 occupy in the mode line, and PRECISION is the maximum number of
14207 characters to display from ELT's representation. See
14208 display_string for details.
14210 Returns the hpos of the end of the text generated by ELT.
14212 PROPS is a property list to add to any string we encounter.
14214 If RISKY is nonzero, remove (disregard) any properties in any string
14215 we encounter, and ignore :eval and :propertize.
14217 If the global variable `frame_title_ptr' is non-NULL, then the output
14218 is passed to `store_frame_title' instead of `display_string'. */
14221 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
14224 int field_width
, precision
;
14225 Lisp_Object elt
, props
;
14228 int n
= 0, field
, prec
;
14237 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
14241 /* A string: output it and check for %-constructs within it. */
14243 const unsigned char *this, *lisp_string
;
14245 if (!NILP (props
) || risky
)
14247 Lisp_Object oprops
, aelt
;
14248 oprops
= Ftext_properties_at (make_number (0), elt
);
14250 if (NILP (Fequal (props
, oprops
)) || risky
)
14252 /* If the starting string has properties,
14253 merge the specified ones onto the existing ones. */
14254 if (! NILP (oprops
) && !risky
)
14258 oprops
= Fcopy_sequence (oprops
);
14260 while (CONSP (tem
))
14262 oprops
= Fplist_put (oprops
, XCAR (tem
),
14263 XCAR (XCDR (tem
)));
14264 tem
= XCDR (XCDR (tem
));
14269 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
14270 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
14272 mode_line_proptrans_alist
14273 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
14280 elt
= Fcopy_sequence (elt
);
14281 Fset_text_properties (make_number (0), Flength (elt
),
14283 /* Add this item to mode_line_proptrans_alist. */
14284 mode_line_proptrans_alist
14285 = Fcons (Fcons (elt
, props
),
14286 mode_line_proptrans_alist
);
14287 /* Truncate mode_line_proptrans_alist
14288 to at most 50 elements. */
14289 tem
= Fnthcdr (make_number (50),
14290 mode_line_proptrans_alist
);
14292 XSETCDR (tem
, Qnil
);
14297 this = SDATA (elt
);
14298 lisp_string
= this;
14302 prec
= precision
- n
;
14303 if (frame_title_ptr
)
14304 n
+= store_frame_title (SDATA (elt
), -1, prec
);
14305 else if (!NILP (mode_line_string_list
))
14306 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
14308 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
14309 0, prec
, 0, STRING_MULTIBYTE (elt
));
14314 while ((precision
<= 0 || n
< precision
)
14316 && (frame_title_ptr
14317 || !NILP (mode_line_string_list
)
14318 || it
->current_x
< it
->last_visible_x
))
14320 const unsigned char *last
= this;
14322 /* Advance to end of string or next format specifier. */
14323 while ((c
= *this++) != '\0' && c
!= '%')
14326 if (this - 1 != last
)
14328 /* Output to end of string or up to '%'. Field width
14329 is length of string. Don't output more than
14330 PRECISION allows us. */
14333 prec
= chars_in_text (last
, this - last
);
14334 if (precision
> 0 && prec
> precision
- n
)
14335 prec
= precision
- n
;
14337 if (frame_title_ptr
)
14338 n
+= store_frame_title (last
, 0, prec
);
14339 else if (!NILP (mode_line_string_list
))
14341 int bytepos
= last
- lisp_string
;
14342 int charpos
= string_byte_to_char (elt
, bytepos
);
14343 n
+= store_mode_line_string (NULL
,
14344 Fsubstring (elt
, make_number (charpos
),
14345 make_number (charpos
+ prec
)),
14350 int bytepos
= last
- lisp_string
;
14351 int charpos
= string_byte_to_char (elt
, bytepos
);
14352 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
14354 STRING_MULTIBYTE (elt
));
14357 else /* c == '%' */
14359 const unsigned char *percent_position
= this;
14361 /* Get the specified minimum width. Zero means
14364 while ((c
= *this++) >= '0' && c
<= '9')
14365 field
= field
* 10 + c
- '0';
14367 /* Don't pad beyond the total padding allowed. */
14368 if (field_width
- n
> 0 && field
> field_width
- n
)
14369 field
= field_width
- n
;
14371 /* Note that either PRECISION <= 0 or N < PRECISION. */
14372 prec
= precision
- n
;
14375 n
+= display_mode_element (it
, depth
, field
, prec
,
14376 Vglobal_mode_string
, props
,
14381 int bytepos
, charpos
;
14382 unsigned char *spec
;
14384 bytepos
= percent_position
- lisp_string
;
14385 charpos
= (STRING_MULTIBYTE (elt
)
14386 ? string_byte_to_char (elt
, bytepos
)
14390 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
14392 if (frame_title_ptr
)
14393 n
+= store_frame_title (spec
, field
, prec
);
14394 else if (!NILP (mode_line_string_list
))
14396 int len
= strlen (spec
);
14397 Lisp_Object tem
= make_string (spec
, len
);
14398 props
= Ftext_properties_at (make_number (charpos
), elt
);
14399 /* Should only keep face property in props */
14400 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
14404 int nglyphs_before
, nwritten
;
14406 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
14407 nwritten
= display_string (spec
, Qnil
, elt
,
14412 /* Assign to the glyphs written above the
14413 string where the `%x' came from, position
14417 struct glyph
*glyph
14418 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
14422 for (i
= 0; i
< nwritten
; ++i
)
14424 glyph
[i
].object
= elt
;
14425 glyph
[i
].charpos
= charpos
;
14440 /* A symbol: process the value of the symbol recursively
14441 as if it appeared here directly. Avoid error if symbol void.
14442 Special case: if value of symbol is a string, output the string
14445 register Lisp_Object tem
;
14447 /* If the variable is not marked as risky to set
14448 then its contents are risky to use. */
14449 if (NILP (Fget (elt
, Qrisky_local_variable
)))
14452 tem
= Fboundp (elt
);
14455 tem
= Fsymbol_value (elt
);
14456 /* If value is a string, output that string literally:
14457 don't check for % within it. */
14461 if (!EQ (tem
, elt
))
14463 /* Give up right away for nil or t. */
14473 register Lisp_Object car
, tem
;
14475 /* A cons cell: five distinct cases.
14476 If first element is :eval or :propertize, do something special.
14477 If first element is a string or a cons, process all the elements
14478 and effectively concatenate them.
14479 If first element is a negative number, truncate displaying cdr to
14480 at most that many characters. If positive, pad (with spaces)
14481 to at least that many characters.
14482 If first element is a symbol, process the cadr or caddr recursively
14483 according to whether the symbol's value is non-nil or nil. */
14485 if (EQ (car
, QCeval
))
14487 /* An element of the form (:eval FORM) means evaluate FORM
14488 and use the result as mode line elements. */
14493 if (CONSP (XCDR (elt
)))
14496 spec
= safe_eval (XCAR (XCDR (elt
)));
14497 n
+= display_mode_element (it
, depth
, field_width
- n
,
14498 precision
- n
, spec
, props
,
14502 else if (EQ (car
, QCpropertize
))
14504 /* An element of the form (:propertize ELT PROPS...)
14505 means display ELT but applying properties PROPS. */
14510 if (CONSP (XCDR (elt
)))
14511 n
+= display_mode_element (it
, depth
, field_width
- n
,
14512 precision
- n
, XCAR (XCDR (elt
)),
14513 XCDR (XCDR (elt
)), risky
);
14515 else if (SYMBOLP (car
))
14517 tem
= Fboundp (car
);
14521 /* elt is now the cdr, and we know it is a cons cell.
14522 Use its car if CAR has a non-nil value. */
14525 tem
= Fsymbol_value (car
);
14532 /* Symbol's value is nil (or symbol is unbound)
14533 Get the cddr of the original list
14534 and if possible find the caddr and use that. */
14538 else if (!CONSP (elt
))
14543 else if (INTEGERP (car
))
14545 register int lim
= XINT (car
);
14549 /* Negative int means reduce maximum width. */
14550 if (precision
<= 0)
14553 precision
= min (precision
, -lim
);
14557 /* Padding specified. Don't let it be more than
14558 current maximum. */
14560 lim
= min (precision
, lim
);
14562 /* If that's more padding than already wanted, queue it.
14563 But don't reduce padding already specified even if
14564 that is beyond the current truncation point. */
14565 field_width
= max (lim
, field_width
);
14569 else if (STRINGP (car
) || CONSP (car
))
14571 register int limit
= 50;
14572 /* Limit is to protect against circular lists. */
14575 && (precision
<= 0 || n
< precision
))
14577 n
+= display_mode_element (it
, depth
, field_width
- n
,
14578 precision
- n
, XCAR (elt
),
14588 if (frame_title_ptr
)
14589 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
14590 else if (!NILP (mode_line_string_list
))
14591 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
14593 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
14594 precision
- n
, 0, 0);
14598 /* Pad to FIELD_WIDTH. */
14599 if (field_width
> 0 && n
< field_width
)
14601 if (frame_title_ptr
)
14602 n
+= store_frame_title ("", field_width
- n
, 0);
14603 else if (!NILP (mode_line_string_list
))
14604 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
14606 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
14613 /* Store a mode-line string element in mode_line_string_list.
14615 If STRING is non-null, display that C string. Otherwise, the Lisp
14616 string LISP_STRING is displayed.
14618 FIELD_WIDTH is the minimum number of output glyphs to produce.
14619 If STRING has fewer characters than FIELD_WIDTH, pad to the right
14620 with spaces. FIELD_WIDTH <= 0 means don't pad.
14622 PRECISION is the maximum number of characters to output from
14623 STRING. PRECISION <= 0 means don't truncate the string.
14625 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
14626 properties to the string.
14628 PROPS are the properties to add to the string.
14629 The mode_line_string_face face property is always added to the string.
14632 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
14634 Lisp_Object lisp_string
;
14643 if (string
!= NULL
)
14645 len
= strlen (string
);
14646 if (precision
> 0 && len
> precision
)
14648 lisp_string
= make_string (string
, len
);
14650 props
= mode_line_string_face_prop
;
14651 else if (!NILP (mode_line_string_face
))
14653 Lisp_Object face
= Fplist_get (props
, Qface
);
14654 props
= Fcopy_sequence (props
);
14656 face
= mode_line_string_face
;
14658 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14659 props
= Fplist_put (props
, Qface
, face
);
14661 Fadd_text_properties (make_number (0), make_number (len
),
14662 props
, lisp_string
);
14666 len
= XFASTINT (Flength (lisp_string
));
14667 if (precision
> 0 && len
> precision
)
14670 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
14673 if (!NILP (mode_line_string_face
))
14677 props
= Ftext_properties_at (make_number (0), lisp_string
);
14678 face
= Fplist_get (props
, Qface
);
14680 face
= mode_line_string_face
;
14682 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
14683 props
= Fcons (Qface
, Fcons (face
, Qnil
));
14685 lisp_string
= Fcopy_sequence (lisp_string
);
14688 Fadd_text_properties (make_number (0), make_number (len
),
14689 props
, lisp_string
);
14694 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14698 if (field_width
> len
)
14700 field_width
-= len
;
14701 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
14703 Fadd_text_properties (make_number (0), make_number (field_width
),
14704 props
, lisp_string
);
14705 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
14713 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
14715 doc
: /* Return the mode-line of selected window as a string.
14716 First optional arg FORMAT specifies a different format string (see
14717 `mode-line-format' for details) to use. If FORMAT is t, return
14718 the buffer's header-line. Second optional arg WINDOW specifies a
14719 different window to use as the context for the formatting.
14720 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
14721 (format
, window
, no_props
)
14722 Lisp_Object format
, window
, no_props
;
14727 struct buffer
*old_buffer
= NULL
;
14728 enum face_id face_id
= DEFAULT_FACE_ID
;
14731 window
= selected_window
;
14732 CHECK_WINDOW (window
);
14733 w
= XWINDOW (window
);
14734 CHECK_BUFFER (w
->buffer
);
14736 if (XBUFFER (w
->buffer
) != current_buffer
)
14738 old_buffer
= current_buffer
;
14739 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14742 if (NILP (format
) || EQ (format
, Qt
))
14744 face_id
= NILP (format
)
14745 ? CURRENT_MODE_LINE_FACE_ID (w
) :
14746 HEADER_LINE_FACE_ID
;
14747 format
= NILP (format
)
14748 ? current_buffer
->mode_line_format
14749 : current_buffer
->header_line_format
;
14752 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14754 if (NILP (no_props
))
14756 mode_line_string_face
=
14757 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
14758 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
14759 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
14761 mode_line_string_face_prop
=
14762 NILP (mode_line_string_face
) ? Qnil
:
14763 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
14765 /* We need a dummy last element in mode_line_string_list to
14766 indicate we are building the propertized mode-line string.
14767 Using mode_line_string_face_prop here GC protects it. */
14768 mode_line_string_list
=
14769 Fcons (mode_line_string_face_prop
, Qnil
);
14770 frame_title_ptr
= NULL
;
14774 mode_line_string_face_prop
= Qnil
;
14775 mode_line_string_list
= Qnil
;
14776 frame_title_ptr
= frame_title_buf
;
14779 push_frame_kboard (it
.f
);
14780 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14781 pop_frame_kboard ();
14784 set_buffer_internal_1 (old_buffer
);
14786 if (NILP (no_props
))
14789 mode_line_string_list
= Fnreverse (mode_line_string_list
);
14790 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
14791 make_string ("", 0));
14792 mode_line_string_face_prop
= Qnil
;
14793 mode_line_string_list
= Qnil
;
14797 len
= frame_title_ptr
- frame_title_buf
;
14798 if (len
> 0 && frame_title_ptr
[-1] == '-')
14800 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
14801 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
14803 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
14804 if (len
> frame_title_ptr
- frame_title_buf
)
14805 len
= frame_title_ptr
- frame_title_buf
;
14808 frame_title_ptr
= NULL
;
14809 return make_string (frame_title_buf
, len
);
14812 /* Write a null-terminated, right justified decimal representation of
14813 the positive integer D to BUF using a minimal field width WIDTH. */
14816 pint2str (buf
, width
, d
)
14817 register char *buf
;
14818 register int width
;
14821 register char *p
= buf
;
14829 *p
++ = d
% 10 + '0';
14834 for (width
-= (int) (p
- buf
); width
> 0; --width
)
14845 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
14846 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
14847 type of CODING_SYSTEM. Return updated pointer into BUF. */
14849 static unsigned char invalid_eol_type
[] = "(*invalid*)";
14852 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
14853 Lisp_Object coding_system
;
14854 register char *buf
;
14858 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
14859 const unsigned char *eol_str
;
14861 /* The EOL conversion we are using. */
14862 Lisp_Object eoltype
;
14864 val
= Fget (coding_system
, Qcoding_system
);
14867 if (!VECTORP (val
)) /* Not yet decided. */
14872 eoltype
= eol_mnemonic_undecided
;
14873 /* Don't mention EOL conversion if it isn't decided. */
14877 Lisp_Object eolvalue
;
14879 eolvalue
= Fget (coding_system
, Qeol_type
);
14882 *buf
++ = XFASTINT (AREF (val
, 1));
14886 /* The EOL conversion that is normal on this system. */
14888 if (NILP (eolvalue
)) /* Not yet decided. */
14889 eoltype
= eol_mnemonic_undecided
;
14890 else if (VECTORP (eolvalue
)) /* Not yet decided. */
14891 eoltype
= eol_mnemonic_undecided
;
14892 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
14893 eoltype
= (XFASTINT (eolvalue
) == 0
14894 ? eol_mnemonic_unix
14895 : (XFASTINT (eolvalue
) == 1
14896 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
14902 /* Mention the EOL conversion if it is not the usual one. */
14903 if (STRINGP (eoltype
))
14905 eol_str
= SDATA (eoltype
);
14906 eol_str_len
= SBYTES (eoltype
);
14908 else if (INTEGERP (eoltype
)
14909 && CHAR_VALID_P (XINT (eoltype
), 0))
14911 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
14912 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
14917 eol_str
= invalid_eol_type
;
14918 eol_str_len
= sizeof (invalid_eol_type
) - 1;
14920 bcopy (eol_str
, buf
, eol_str_len
);
14921 buf
+= eol_str_len
;
14927 /* Return a string for the output of a mode line %-spec for window W,
14928 generated by character C. PRECISION >= 0 means don't return a
14929 string longer than that value. FIELD_WIDTH > 0 means pad the
14930 string returned with spaces to that value. Return 1 in *MULTIBYTE
14931 if the result is multibyte text. */
14933 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
14936 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
14939 int field_width
, precision
;
14943 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14944 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
14945 struct buffer
*b
= XBUFFER (w
->buffer
);
14953 if (!NILP (b
->read_only
))
14955 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14960 /* This differs from %* only for a modified read-only buffer. */
14961 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14963 if (!NILP (b
->read_only
))
14968 /* This differs from %* in ignoring read-only-ness. */
14969 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
14981 if (command_loop_level
> 5)
14983 p
= decode_mode_spec_buf
;
14984 for (i
= 0; i
< command_loop_level
; i
++)
14987 return decode_mode_spec_buf
;
14995 if (command_loop_level
> 5)
14997 p
= decode_mode_spec_buf
;
14998 for (i
= 0; i
< command_loop_level
; i
++)
15001 return decode_mode_spec_buf
;
15008 /* Let lots_of_dashes be a string of infinite length. */
15009 if (!NILP (mode_line_string_list
))
15011 if (field_width
<= 0
15012 || field_width
> sizeof (lots_of_dashes
))
15014 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
15015 decode_mode_spec_buf
[i
] = '-';
15016 decode_mode_spec_buf
[i
] = '\0';
15017 return decode_mode_spec_buf
;
15020 return lots_of_dashes
;
15029 int col
= (int) current_column (); /* iftc */
15030 w
->column_number_displayed
= make_number (col
);
15031 pint2str (decode_mode_spec_buf
, field_width
, col
);
15032 return decode_mode_spec_buf
;
15036 /* %F displays the frame name. */
15037 if (!NILP (f
->title
))
15038 return (char *) SDATA (f
->title
);
15039 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
15040 return (char *) SDATA (f
->name
);
15049 int startpos
= XMARKER (w
->start
)->charpos
;
15050 int startpos_byte
= marker_byte_position (w
->start
);
15051 int line
, linepos
, linepos_byte
, topline
;
15053 int height
= XFASTINT (w
->height
);
15055 /* If we decided that this buffer isn't suitable for line numbers,
15056 don't forget that too fast. */
15057 if (EQ (w
->base_line_pos
, w
->buffer
))
15059 /* But do forget it, if the window shows a different buffer now. */
15060 else if (BUFFERP (w
->base_line_pos
))
15061 w
->base_line_pos
= Qnil
;
15063 /* If the buffer is very big, don't waste time. */
15064 if (INTEGERP (Vline_number_display_limit
)
15065 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
15067 w
->base_line_pos
= Qnil
;
15068 w
->base_line_number
= Qnil
;
15072 if (!NILP (w
->base_line_number
)
15073 && !NILP (w
->base_line_pos
)
15074 && XFASTINT (w
->base_line_pos
) <= startpos
)
15076 line
= XFASTINT (w
->base_line_number
);
15077 linepos
= XFASTINT (w
->base_line_pos
);
15078 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
15083 linepos
= BUF_BEGV (b
);
15084 linepos_byte
= BUF_BEGV_BYTE (b
);
15087 /* Count lines from base line to window start position. */
15088 nlines
= display_count_lines (linepos
, linepos_byte
,
15092 topline
= nlines
+ line
;
15094 /* Determine a new base line, if the old one is too close
15095 or too far away, or if we did not have one.
15096 "Too close" means it's plausible a scroll-down would
15097 go back past it. */
15098 if (startpos
== BUF_BEGV (b
))
15100 w
->base_line_number
= make_number (topline
);
15101 w
->base_line_pos
= make_number (BUF_BEGV (b
));
15103 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
15104 || linepos
== BUF_BEGV (b
))
15106 int limit
= BUF_BEGV (b
);
15107 int limit_byte
= BUF_BEGV_BYTE (b
);
15109 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
15111 if (startpos
- distance
> limit
)
15113 limit
= startpos
- distance
;
15114 limit_byte
= CHAR_TO_BYTE (limit
);
15117 nlines
= display_count_lines (startpos
, startpos_byte
,
15119 - (height
* 2 + 30),
15121 /* If we couldn't find the lines we wanted within
15122 line_number_display_limit_width chars per line,
15123 give up on line numbers for this window. */
15124 if (position
== limit_byte
&& limit
== startpos
- distance
)
15126 w
->base_line_pos
= w
->buffer
;
15127 w
->base_line_number
= Qnil
;
15131 w
->base_line_number
= make_number (topline
- nlines
);
15132 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
15135 /* Now count lines from the start pos to point. */
15136 nlines
= display_count_lines (startpos
, startpos_byte
,
15137 PT_BYTE
, PT
, &junk
);
15139 /* Record that we did display the line number. */
15140 line_number_displayed
= 1;
15142 /* Make the string to show. */
15143 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
15144 return decode_mode_spec_buf
;
15147 char* p
= decode_mode_spec_buf
;
15148 int pad
= field_width
- 2;
15154 return decode_mode_spec_buf
;
15160 obj
= b
->mode_name
;
15164 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
15170 int pos
= marker_position (w
->start
);
15171 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
15173 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
15175 if (pos
<= BUF_BEGV (b
))
15180 else if (pos
<= BUF_BEGV (b
))
15184 if (total
> 1000000)
15185 /* Do it differently for a large value, to avoid overflow. */
15186 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
15188 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
15189 /* We can't normally display a 3-digit number,
15190 so get us a 2-digit number that is close. */
15193 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
15194 return decode_mode_spec_buf
;
15198 /* Display percentage of size above the bottom of the screen. */
15201 int toppos
= marker_position (w
->start
);
15202 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
15203 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
15205 if (botpos
>= BUF_ZV (b
))
15207 if (toppos
<= BUF_BEGV (b
))
15214 if (total
> 1000000)
15215 /* Do it differently for a large value, to avoid overflow. */
15216 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
15218 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
15219 /* We can't normally display a 3-digit number,
15220 so get us a 2-digit number that is close. */
15223 if (toppos
<= BUF_BEGV (b
))
15224 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
15226 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
15227 return decode_mode_spec_buf
;
15232 /* status of process */
15233 obj
= Fget_buffer_process (w
->buffer
);
15235 return "no process";
15236 #ifdef subprocesses
15237 obj
= Fsymbol_name (Fprocess_status (obj
));
15241 case 't': /* indicate TEXT or BINARY */
15242 #ifdef MODE_LINE_BINARY_TEXT
15243 return MODE_LINE_BINARY_TEXT (b
);
15249 /* coding-system (not including end-of-line format) */
15251 /* coding-system (including end-of-line type) */
15253 int eol_flag
= (c
== 'Z');
15254 char *p
= decode_mode_spec_buf
;
15256 if (! FRAME_WINDOW_P (f
))
15258 /* No need to mention EOL here--the terminal never needs
15259 to do EOL conversion. */
15260 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
15261 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
15263 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
15266 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
15267 #ifdef subprocesses
15268 obj
= Fget_buffer_process (Fcurrent_buffer ());
15269 if (PROCESSP (obj
))
15271 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
15273 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
15276 #endif /* subprocesses */
15279 return decode_mode_spec_buf
;
15285 *multibyte
= STRING_MULTIBYTE (obj
);
15286 return (char *) SDATA (obj
);
15293 /* Count up to COUNT lines starting from START / START_BYTE.
15294 But don't go beyond LIMIT_BYTE.
15295 Return the number of lines thus found (always nonnegative).
15297 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
15300 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
15301 int start
, start_byte
, limit_byte
, count
;
15304 register unsigned char *cursor
;
15305 unsigned char *base
;
15307 register int ceiling
;
15308 register unsigned char *ceiling_addr
;
15309 int orig_count
= count
;
15311 /* If we are not in selective display mode,
15312 check only for newlines. */
15313 int selective_display
= (!NILP (current_buffer
->selective_display
)
15314 && !INTEGERP (current_buffer
->selective_display
));
15318 while (start_byte
< limit_byte
)
15320 ceiling
= BUFFER_CEILING_OF (start_byte
);
15321 ceiling
= min (limit_byte
- 1, ceiling
);
15322 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
15323 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
15326 if (selective_display
)
15327 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
15330 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
15333 if (cursor
!= ceiling_addr
)
15337 start_byte
+= cursor
- base
+ 1;
15338 *byte_pos_ptr
= start_byte
;
15342 if (++cursor
== ceiling_addr
)
15348 start_byte
+= cursor
- base
;
15353 while (start_byte
> limit_byte
)
15355 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
15356 ceiling
= max (limit_byte
, ceiling
);
15357 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
15358 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
15361 if (selective_display
)
15362 while (--cursor
!= ceiling_addr
15363 && *cursor
!= '\n' && *cursor
!= 015)
15366 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
15369 if (cursor
!= ceiling_addr
)
15373 start_byte
+= cursor
- base
+ 1;
15374 *byte_pos_ptr
= start_byte
;
15375 /* When scanning backwards, we should
15376 not count the newline posterior to which we stop. */
15377 return - orig_count
- 1;
15383 /* Here we add 1 to compensate for the last decrement
15384 of CURSOR, which took it past the valid range. */
15385 start_byte
+= cursor
- base
+ 1;
15389 *byte_pos_ptr
= limit_byte
;
15392 return - orig_count
+ count
;
15393 return orig_count
- count
;
15399 /***********************************************************************
15401 ***********************************************************************/
15403 /* Display a NUL-terminated string, starting with index START.
15405 If STRING is non-null, display that C string. Otherwise, the Lisp
15406 string LISP_STRING is displayed.
15408 If FACE_STRING is not nil, FACE_STRING_POS is a position in
15409 FACE_STRING. Display STRING or LISP_STRING with the face at
15410 FACE_STRING_POS in FACE_STRING:
15412 Display the string in the environment given by IT, but use the
15413 standard display table, temporarily.
15415 FIELD_WIDTH is the minimum number of output glyphs to produce.
15416 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15417 with spaces. If STRING has more characters, more than FIELD_WIDTH
15418 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
15420 PRECISION is the maximum number of characters to output from
15421 STRING. PRECISION < 0 means don't truncate the string.
15423 This is roughly equivalent to printf format specifiers:
15425 FIELD_WIDTH PRECISION PRINTF
15426 ----------------------------------------
15432 MULTIBYTE zero means do not display multibyte chars, > 0 means do
15433 display them, and < 0 means obey the current buffer's value of
15434 enable_multibyte_characters.
15436 Value is the number of glyphs produced. */
15439 display_string (string
, lisp_string
, face_string
, face_string_pos
,
15440 start
, it
, field_width
, precision
, max_x
, multibyte
)
15441 unsigned char *string
;
15442 Lisp_Object lisp_string
;
15443 Lisp_Object face_string
;
15444 int face_string_pos
;
15447 int field_width
, precision
, max_x
;
15450 int hpos_at_start
= it
->hpos
;
15451 int saved_face_id
= it
->face_id
;
15452 struct glyph_row
*row
= it
->glyph_row
;
15454 /* Initialize the iterator IT for iteration over STRING beginning
15455 with index START. */
15456 reseat_to_string (it
, string
, lisp_string
, start
,
15457 precision
, field_width
, multibyte
);
15459 /* If displaying STRING, set up the face of the iterator
15460 from LISP_STRING, if that's given. */
15461 if (STRINGP (face_string
))
15467 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
15468 0, it
->region_beg_charpos
,
15469 it
->region_end_charpos
,
15470 &endptr
, it
->base_face_id
, 0);
15471 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15472 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
15475 /* Set max_x to the maximum allowed X position. Don't let it go
15476 beyond the right edge of the window. */
15478 max_x
= it
->last_visible_x
;
15480 max_x
= min (max_x
, it
->last_visible_x
);
15482 /* Skip over display elements that are not visible. because IT->w is
15484 if (it
->current_x
< it
->first_visible_x
)
15485 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
15486 MOVE_TO_POS
| MOVE_TO_X
);
15488 row
->ascent
= it
->max_ascent
;
15489 row
->height
= it
->max_ascent
+ it
->max_descent
;
15490 row
->phys_ascent
= it
->max_phys_ascent
;
15491 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15493 /* This condition is for the case that we are called with current_x
15494 past last_visible_x. */
15495 while (it
->current_x
< max_x
)
15497 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
15499 /* Get the next display element. */
15500 if (!get_next_display_element (it
))
15503 /* Produce glyphs. */
15504 x_before
= it
->current_x
;
15505 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15506 PRODUCE_GLYPHS (it
);
15508 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
15511 while (i
< nglyphs
)
15513 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15515 if (!it
->truncate_lines_p
15516 && x
+ glyph
->pixel_width
> max_x
)
15518 /* End of continued line or max_x reached. */
15519 if (CHAR_GLYPH_PADDING_P (*glyph
))
15521 /* A wide character is unbreakable. */
15522 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15523 it
->current_x
= x_before
;
15527 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15532 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
15534 /* Glyph is at least partially visible. */
15536 if (x
< it
->first_visible_x
)
15537 it
->glyph_row
->x
= x
- it
->first_visible_x
;
15541 /* Glyph is off the left margin of the display area.
15542 Should not happen. */
15546 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15547 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15548 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15549 row
->phys_height
= max (row
->phys_height
,
15550 it
->max_phys_ascent
+ it
->max_phys_descent
);
15551 x
+= glyph
->pixel_width
;
15555 /* Stop if max_x reached. */
15559 /* Stop at line ends. */
15560 if (ITERATOR_AT_END_OF_LINE_P (it
))
15562 it
->continuation_lines_width
= 0;
15566 set_iterator_to_next (it
, 1);
15568 /* Stop if truncating at the right edge. */
15569 if (it
->truncate_lines_p
15570 && it
->current_x
>= it
->last_visible_x
)
15572 /* Add truncation mark, but don't do it if the line is
15573 truncated at a padding space. */
15574 if (IT_CHARPOS (*it
) < it
->string_nchars
)
15576 if (!FRAME_WINDOW_P (it
->f
))
15580 if (it
->current_x
> it
->last_visible_x
)
15582 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15583 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15585 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15587 row
->used
[TEXT_AREA
] = i
;
15588 produce_special_glyphs (it
, IT_TRUNCATION
);
15591 produce_special_glyphs (it
, IT_TRUNCATION
);
15593 it
->glyph_row
->truncated_on_right_p
= 1;
15599 /* Maybe insert a truncation at the left. */
15600 if (it
->first_visible_x
15601 && IT_CHARPOS (*it
) > 0)
15603 if (!FRAME_WINDOW_P (it
->f
))
15604 insert_left_trunc_glyphs (it
);
15605 it
->glyph_row
->truncated_on_left_p
= 1;
15608 it
->face_id
= saved_face_id
;
15610 /* Value is number of columns displayed. */
15611 return it
->hpos
- hpos_at_start
;
15616 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
15617 appears as an element of LIST or as the car of an element of LIST.
15618 If PROPVAL is a list, compare each element against LIST in that
15619 way, and return 1/2 if any element of PROPVAL is found in LIST.
15620 Otherwise return 0. This function cannot quit.
15621 The return value is 2 if the text is invisible but with an ellipsis
15622 and 1 if it's invisible and without an ellipsis. */
15625 invisible_p (propval
, list
)
15626 register Lisp_Object propval
;
15629 register Lisp_Object tail
, proptail
;
15631 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15633 register Lisp_Object tem
;
15635 if (EQ (propval
, tem
))
15637 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
15638 return NILP (XCDR (tem
)) ? 1 : 2;
15641 if (CONSP (propval
))
15643 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
15645 Lisp_Object propelt
;
15646 propelt
= XCAR (proptail
);
15647 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
15649 register Lisp_Object tem
;
15651 if (EQ (propelt
, tem
))
15653 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
15654 return NILP (XCDR (tem
)) ? 1 : 2;
15663 /***********************************************************************
15665 ***********************************************************************/
15670 dump_glyph_string (s
)
15671 struct glyph_string
*s
;
15673 fprintf (stderr
, "glyph string\n");
15674 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
15675 s
->x
, s
->y
, s
->width
, s
->height
);
15676 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
15677 fprintf (stderr
, " hl = %d\n", s
->hl
);
15678 fprintf (stderr
, " left overhang = %d, right = %d\n",
15679 s
->left_overhang
, s
->right_overhang
);
15680 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
15681 fprintf (stderr
, " extends to end of line = %d\n",
15682 s
->extends_to_end_of_line_p
);
15683 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
15684 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
15687 #endif /* GLYPH_DEBUG */
15689 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
15690 of XChar2b structures for S; it can't be allocated in
15691 init_glyph_string because it must be allocated via `alloca'. W
15692 is the window on which S is drawn. ROW and AREA are the glyph row
15693 and area within the row from which S is constructed. START is the
15694 index of the first glyph structure covered by S. HL is a
15695 face-override for drawing S. */
15698 #define OPTIONAL_HDC(hdc) hdc,
15699 #define DECLARE_HDC(hdc) HDC hdc;
15700 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
15701 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
15704 #ifndef OPTIONAL_HDC
15705 #define OPTIONAL_HDC(hdc)
15706 #define DECLARE_HDC(hdc)
15707 #define ALLOCATE_HDC(hdc, f)
15708 #define RELEASE_HDC(hdc, f)
15712 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
15713 struct glyph_string
*s
;
15717 struct glyph_row
*row
;
15718 enum glyph_row_area area
;
15720 enum draw_glyphs_face hl
;
15722 bzero (s
, sizeof *s
);
15724 s
->f
= XFRAME (w
->frame
);
15728 s
->display
= FRAME_X_DISPLAY (s
->f
);
15729 s
->window
= FRAME_X_WINDOW (s
->f
);
15730 s
->char2b
= char2b
;
15734 s
->first_glyph
= row
->glyphs
[area
] + start
;
15735 s
->height
= row
->height
;
15736 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
15738 /* Display the internal border below the tool-bar window. */
15739 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
15740 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
15742 s
->ybase
= s
->y
+ row
->ascent
;
15746 /* Append the list of glyph strings with head H and tail T to the list
15747 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
15750 append_glyph_string_lists (head
, tail
, h
, t
)
15751 struct glyph_string
**head
, **tail
;
15752 struct glyph_string
*h
, *t
;
15766 /* Prepend the list of glyph strings with head H and tail T to the
15767 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
15771 prepend_glyph_string_lists (head
, tail
, h
, t
)
15772 struct glyph_string
**head
, **tail
;
15773 struct glyph_string
*h
, *t
;
15787 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
15788 Set *HEAD and *TAIL to the resulting list. */
15791 append_glyph_string (head
, tail
, s
)
15792 struct glyph_string
**head
, **tail
;
15793 struct glyph_string
*s
;
15795 s
->next
= s
->prev
= NULL
;
15796 append_glyph_string_lists (head
, tail
, s
, s
);
15800 /* Get face and two-byte form of character glyph GLYPH on frame F.
15801 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
15802 a pointer to a realized face that is ready for display. */
15804 static INLINE
struct face
*
15805 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
15807 struct glyph
*glyph
;
15813 xassert (glyph
->type
== CHAR_GLYPH
);
15814 face
= FACE_FROM_ID (f
, glyph
->face_id
);
15819 if (!glyph
->multibyte_p
)
15821 /* Unibyte case. We don't have to encode, but we have to make
15822 sure to use a face suitable for unibyte. */
15823 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
15825 else if (glyph
->u
.ch
< 128
15826 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
15828 /* Case of ASCII in a face known to fit ASCII. */
15829 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
15833 int c1
, c2
, charset
;
15835 /* Split characters into bytes. If c2 is -1 afterwards, C is
15836 really a one-byte character so that byte1 is zero. */
15837 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
15839 STORE_XCHAR2B (char2b
, c1
, c2
);
15841 STORE_XCHAR2B (char2b
, 0, c1
);
15843 /* Maybe encode the character in *CHAR2B. */
15844 if (charset
!= CHARSET_ASCII
)
15846 struct font_info
*font_info
15847 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
15850 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
15854 /* Make sure X resources of the face are allocated. */
15855 xassert (face
!= NULL
);
15856 PREPARE_FACE_FOR_DISPLAY (f
, face
);
15861 /* Fill glyph string S with composition components specified by S->cmp.
15863 FACES is an array of faces for all components of this composition.
15864 S->gidx is the index of the first component for S.
15865 OVERLAPS_P non-zero means S should draw the foreground only, and
15866 use its physical height for clipping.
15868 Value is the index of a component not in S. */
15871 fill_composite_glyph_string (s
, faces
, overlaps_p
)
15872 struct glyph_string
*s
;
15873 struct face
**faces
;
15880 s
->for_overlaps_p
= overlaps_p
;
15882 s
->face
= faces
[s
->gidx
];
15883 s
->font
= s
->face
->font
;
15884 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
15886 /* For all glyphs of this composition, starting at the offset
15887 S->gidx, until we reach the end of the definition or encounter a
15888 glyph that requires the different face, add it to S. */
15890 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
15893 /* All glyph strings for the same composition has the same width,
15894 i.e. the width set for the first component of the composition. */
15896 s
->width
= s
->first_glyph
->pixel_width
;
15898 /* If the specified font could not be loaded, use the frame's
15899 default font, but record the fact that we couldn't load it in
15900 the glyph string so that we can draw rectangles for the
15901 characters of the glyph string. */
15902 if (s
->font
== NULL
)
15904 s
->font_not_found_p
= 1;
15905 s
->font
= FRAME_FONT (s
->f
);
15908 /* Adjust base line for subscript/superscript text. */
15909 s
->ybase
+= s
->first_glyph
->voffset
;
15911 xassert (s
->face
&& s
->face
->gc
);
15913 /* This glyph string must always be drawn with 16-bit functions. */
15916 return s
->gidx
+ s
->nchars
;
15920 /* Fill glyph string S from a sequence of character glyphs.
15922 FACE_ID is the face id of the string. START is the index of the
15923 first glyph to consider, END is the index of the last + 1.
15924 OVERLAPS_P non-zero means S should draw the foreground only, and
15925 use its physical height for clipping.
15927 Value is the index of the first glyph not in S. */
15930 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
15931 struct glyph_string
*s
;
15933 int start
, end
, overlaps_p
;
15935 struct glyph
*glyph
, *last
;
15937 int glyph_not_available_p
;
15939 xassert (s
->f
== XFRAME (s
->w
->frame
));
15940 xassert (s
->nchars
== 0);
15941 xassert (start
>= 0 && end
> start
);
15943 s
->for_overlaps_p
= overlaps_p
,
15944 glyph
= s
->row
->glyphs
[s
->area
] + start
;
15945 last
= s
->row
->glyphs
[s
->area
] + end
;
15946 voffset
= glyph
->voffset
;
15948 glyph_not_available_p
= glyph
->glyph_not_available_p
;
15950 while (glyph
< last
15951 && glyph
->type
== CHAR_GLYPH
15952 && glyph
->voffset
== voffset
15953 /* Same face id implies same font, nowadays. */
15954 && glyph
->face_id
== face_id
15955 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
15959 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
15960 s
->char2b
+ s
->nchars
,
15962 s
->two_byte_p
= two_byte_p
;
15964 xassert (s
->nchars
<= end
- start
);
15965 s
->width
+= glyph
->pixel_width
;
15969 s
->font
= s
->face
->font
;
15970 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
15972 /* If the specified font could not be loaded, use the frame's font,
15973 but record the fact that we couldn't load it in
15974 S->font_not_found_p so that we can draw rectangles for the
15975 characters of the glyph string. */
15976 if (s
->font
== NULL
|| glyph_not_available_p
)
15978 s
->font_not_found_p
= 1;
15979 s
->font
= FRAME_FONT (s
->f
);
15982 /* Adjust base line for subscript/superscript text. */
15983 s
->ybase
+= voffset
;
15985 xassert (s
->face
&& s
->face
->gc
);
15986 return glyph
- s
->row
->glyphs
[s
->area
];
15990 /* Fill glyph string S from image glyph S->first_glyph. */
15993 fill_image_glyph_string (s
)
15994 struct glyph_string
*s
;
15996 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
15997 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
15999 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
16000 s
->font
= s
->face
->font
;
16001 s
->width
= s
->first_glyph
->pixel_width
;
16003 /* Adjust base line for subscript/superscript text. */
16004 s
->ybase
+= s
->first_glyph
->voffset
;
16008 /* Fill glyph string S from a sequence of stretch glyphs.
16010 ROW is the glyph row in which the glyphs are found, AREA is the
16011 area within the row. START is the index of the first glyph to
16012 consider, END is the index of the last + 1.
16014 Value is the index of the first glyph not in S. */
16017 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
16018 struct glyph_string
*s
;
16019 struct glyph_row
*row
;
16020 enum glyph_row_area area
;
16023 struct glyph
*glyph
, *last
;
16024 int voffset
, face_id
;
16026 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
16028 glyph
= s
->row
->glyphs
[s
->area
] + start
;
16029 last
= s
->row
->glyphs
[s
->area
] + end
;
16030 face_id
= glyph
->face_id
;
16031 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
16032 s
->font
= s
->face
->font
;
16033 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16034 s
->width
= glyph
->pixel_width
;
16035 voffset
= glyph
->voffset
;
16039 && glyph
->type
== STRETCH_GLYPH
16040 && glyph
->voffset
== voffset
16041 && glyph
->face_id
== face_id
);
16043 s
->width
+= glyph
->pixel_width
;
16045 /* Adjust base line for subscript/superscript text. */
16046 s
->ybase
+= voffset
;
16048 /* The case that face->gc == 0 is handled when drawing the glyph
16049 string by calling PREPARE_FACE_FOR_DISPLAY. */
16051 return glyph
- s
->row
->glyphs
[s
->area
];
16056 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
16057 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
16058 assumed to be zero. */
16061 x_get_glyph_overhangs (glyph
, f
, left
, right
)
16062 struct glyph
*glyph
;
16066 *left
= *right
= 0;
16068 if (glyph
->type
== CHAR_GLYPH
)
16072 struct font_info
*font_info
;
16076 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
16078 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16079 if (font
/* ++KFS: Should this be font_info ? */
16080 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
16082 if (pcm
->rbearing
> pcm
->width
)
16083 *right
= pcm
->rbearing
- pcm
->width
;
16084 if (pcm
->lbearing
< 0)
16085 *left
= -pcm
->lbearing
;
16091 /* Return the index of the first glyph preceding glyph string S that
16092 is overwritten by S because of S's left overhang. Value is -1
16093 if no glyphs are overwritten. */
16096 left_overwritten (s
)
16097 struct glyph_string
*s
;
16101 if (s
->left_overhang
)
16104 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16105 int first
= s
->first_glyph
- glyphs
;
16107 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
16108 x
-= glyphs
[i
].pixel_width
;
16119 /* Return the index of the first glyph preceding glyph string S that
16120 is overwriting S because of its right overhang. Value is -1 if no
16121 glyph in front of S overwrites S. */
16124 left_overwriting (s
)
16125 struct glyph_string
*s
;
16128 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16129 int first
= s
->first_glyph
- glyphs
;
16133 for (i
= first
- 1; i
>= 0; --i
)
16136 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
16139 x
-= glyphs
[i
].pixel_width
;
16146 /* Return the index of the last glyph following glyph string S that is
16147 not overwritten by S because of S's right overhang. Value is -1 if
16148 no such glyph is found. */
16151 right_overwritten (s
)
16152 struct glyph_string
*s
;
16156 if (s
->right_overhang
)
16159 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16160 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
16161 int end
= s
->row
->used
[s
->area
];
16163 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
16164 x
+= glyphs
[i
].pixel_width
;
16173 /* Return the index of the last glyph following glyph string S that
16174 overwrites S because of its left overhang. Value is negative
16175 if no such glyph is found. */
16178 right_overwriting (s
)
16179 struct glyph_string
*s
;
16182 int end
= s
->row
->used
[s
->area
];
16183 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16184 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
16188 for (i
= first
; i
< end
; ++i
)
16191 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
16194 x
+= glyphs
[i
].pixel_width
;
16201 /* Get face and two-byte form of character C in face FACE_ID on frame
16202 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
16203 means we want to display multibyte text. DISPLAY_P non-zero means
16204 make sure that X resources for the face returned are allocated.
16205 Value is a pointer to a realized face that is ready for display if
16206 DISPLAY_P is non-zero. */
16208 static INLINE
struct face
*
16209 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
16213 int multibyte_p
, display_p
;
16215 struct face
*face
= FACE_FROM_ID (f
, face_id
);
16219 /* Unibyte case. We don't have to encode, but we have to make
16220 sure to use a face suitable for unibyte. */
16221 STORE_XCHAR2B (char2b
, 0, c
);
16222 face_id
= FACE_FOR_CHAR (f
, face
, c
);
16223 face
= FACE_FROM_ID (f
, face_id
);
16225 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
16227 /* Case of ASCII in a face known to fit ASCII. */
16228 STORE_XCHAR2B (char2b
, 0, c
);
16232 int c1
, c2
, charset
;
16234 /* Split characters into bytes. If c2 is -1 afterwards, C is
16235 really a one-byte character so that byte1 is zero. */
16236 SPLIT_CHAR (c
, charset
, c1
, c2
);
16238 STORE_XCHAR2B (char2b
, c1
, c2
);
16240 STORE_XCHAR2B (char2b
, 0, c1
);
16242 /* Maybe encode the character in *CHAR2B. */
16243 if (face
->font
!= NULL
)
16245 struct font_info
*font_info
16246 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16248 rif
->encode_char (c
, char2b
, font_info
, 0);
16252 /* Make sure X resources of the face are allocated. */
16253 #ifdef HAVE_X_WINDOWS
16257 xassert (face
!= NULL
);
16258 PREPARE_FACE_FOR_DISPLAY (f
, face
);
16265 /* Set background width of glyph string S. START is the index of the
16266 first glyph following S. LAST_X is the right-most x-position + 1
16267 in the drawing area. */
16270 set_glyph_string_background_width (s
, start
, last_x
)
16271 struct glyph_string
*s
;
16275 /* If the face of this glyph string has to be drawn to the end of
16276 the drawing area, set S->extends_to_end_of_line_p. */
16277 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
16279 if (start
== s
->row
->used
[s
->area
]
16280 && s
->area
== TEXT_AREA
16281 && ((s
->hl
== DRAW_NORMAL_TEXT
16282 && (s
->row
->fill_line_p
16283 || s
->face
->background
!= default_face
->background
16284 || s
->face
->stipple
!= default_face
->stipple
16285 || s
->row
->mouse_face_p
))
16286 || s
->hl
== DRAW_MOUSE_FACE
16287 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
16288 && s
->row
->fill_line_p
)))
16289 s
->extends_to_end_of_line_p
= 1;
16291 /* If S extends its face to the end of the line, set its
16292 background_width to the distance to the right edge of the drawing
16294 if (s
->extends_to_end_of_line_p
)
16295 s
->background_width
= last_x
- s
->x
+ 1;
16297 s
->background_width
= s
->width
;
16301 /* Compute overhangs and x-positions for glyph string S and its
16302 predecessors, or successors. X is the starting x-position for S.
16303 BACKWARD_P non-zero means process predecessors. */
16306 compute_overhangs_and_x (s
, x
, backward_p
)
16307 struct glyph_string
*s
;
16315 if (rif
->compute_glyph_string_overhangs
)
16316 rif
->compute_glyph_string_overhangs (s
);
16326 if (rif
->compute_glyph_string_overhangs
)
16327 rif
->compute_glyph_string_overhangs (s
);
16337 /* The following macros are only called from x_draw_glyphs below.
16338 They reference the following parameters of that function directly:
16339 `w', `row', `area', and `overlap_p'
16340 as well as the following local variables:
16341 `s', `f', and `hdc' (in W32) */
16344 /* On W32, silently add local `hdc' variable to argument list of
16345 init_glyph_string. */
16346 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
16347 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
16349 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
16350 init_glyph_string (s, char2b, w, row, area, start, hl)
16353 /* Add a glyph string for a stretch glyph to the list of strings
16354 between HEAD and TAIL. START is the index of the stretch glyph in
16355 row area AREA of glyph row ROW. END is the index of the last glyph
16356 in that glyph row area. X is the current output position assigned
16357 to the new glyph string constructed. HL overrides that face of the
16358 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
16359 is the right-most x-position of the drawing area. */
16361 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
16362 and below -- keep them on one line. */
16363 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
16366 s = (struct glyph_string *) alloca (sizeof *s); \
16367 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
16368 START = fill_stretch_glyph_string (s, row, area, START, END); \
16369 append_glyph_string (&HEAD, &TAIL, s); \
16375 /* Add a glyph string for an image glyph to the list of strings
16376 between HEAD and TAIL. START is the index of the image glyph in
16377 row area AREA of glyph row ROW. END is the index of the last glyph
16378 in that glyph row area. X is the current output position assigned
16379 to the new glyph string constructed. HL overrides that face of the
16380 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
16381 is the right-most x-position of the drawing area. */
16383 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
16386 s = (struct glyph_string *) alloca (sizeof *s); \
16387 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
16388 fill_image_glyph_string (s); \
16389 append_glyph_string (&HEAD, &TAIL, s); \
16396 /* Add a glyph string for a sequence of character glyphs to the list
16397 of strings between HEAD and TAIL. START is the index of the first
16398 glyph in row area AREA of glyph row ROW that is part of the new
16399 glyph string. END is the index of the last glyph in that glyph row
16400 area. X is the current output position assigned to the new glyph
16401 string constructed. HL overrides that face of the glyph; e.g. it
16402 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
16403 right-most x-position of the drawing area. */
16405 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
16411 c = (row)->glyphs[area][START].u.ch; \
16412 face_id = (row)->glyphs[area][START].face_id; \
16414 s = (struct glyph_string *) alloca (sizeof *s); \
16415 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
16416 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
16417 append_glyph_string (&HEAD, &TAIL, s); \
16419 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
16424 /* Add a glyph string for a composite sequence to the list of strings
16425 between HEAD and TAIL. START is the index of the first glyph in
16426 row area AREA of glyph row ROW that is part of the new glyph
16427 string. END is the index of the last glyph in that glyph row area.
16428 X is the current output position assigned to the new glyph string
16429 constructed. HL overrides that face of the glyph; e.g. it is
16430 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
16431 x-position of the drawing area. */
16433 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
16435 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
16436 int face_id = (row)->glyphs[area][START].face_id; \
16437 struct face *base_face = FACE_FROM_ID (f, face_id); \
16438 struct composition *cmp = composition_table[cmp_id]; \
16439 int glyph_len = cmp->glyph_len; \
16441 struct face **faces; \
16442 struct glyph_string *first_s = NULL; \
16445 base_face = base_face->ascii_face; \
16446 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
16447 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
16448 /* At first, fill in `char2b' and `faces'. */ \
16449 for (n = 0; n < glyph_len; n++) \
16451 int c = COMPOSITION_GLYPH (cmp, n); \
16452 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
16453 faces[n] = FACE_FROM_ID (f, this_face_id); \
16454 get_char_face_and_encoding (f, c, this_face_id, \
16455 char2b + n, 1, 1); \
16458 /* Make glyph_strings for each glyph sequence that is drawable by \
16459 the same face, and append them to HEAD/TAIL. */ \
16460 for (n = 0; n < cmp->glyph_len;) \
16462 s = (struct glyph_string *) alloca (sizeof *s); \
16463 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
16464 append_glyph_string (&(HEAD), &(TAIL), s); \
16472 n = fill_composite_glyph_string (s, faces, overlaps_p); \
16480 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
16481 of AREA of glyph row ROW on window W between indices START and END.
16482 HL overrides the face for drawing glyph strings, e.g. it is
16483 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
16484 x-positions of the drawing area.
16486 This is an ugly monster macro construct because we must use alloca
16487 to allocate glyph strings (because x_draw_glyphs can be called
16488 asynchronously). */
16490 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
16493 HEAD = TAIL = NULL; \
16494 while (START < END) \
16496 struct glyph *first_glyph = (row)->glyphs[area] + START; \
16497 switch (first_glyph->type) \
16500 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
16504 case COMPOSITE_GLYPH: \
16505 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
16509 case STRETCH_GLYPH: \
16510 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
16514 case IMAGE_GLYPH: \
16515 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
16523 set_glyph_string_background_width (s, START, LAST_X); \
16530 /* Draw glyphs between START and END in AREA of ROW on window W,
16531 starting at x-position X. X is relative to AREA in W. HL is a
16532 face-override with the following meaning:
16534 DRAW_NORMAL_TEXT draw normally
16535 DRAW_CURSOR draw in cursor face
16536 DRAW_MOUSE_FACE draw in mouse face.
16537 DRAW_INVERSE_VIDEO draw in mode line face
16538 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
16539 DRAW_IMAGE_RAISED draw an image with a raised relief around it
16541 If OVERLAPS_P is non-zero, draw only the foreground of characters
16542 and clip to the physical height of ROW.
16544 Value is the x-position reached, relative to AREA of W. */
16547 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
16550 struct glyph_row
*row
;
16551 enum glyph_row_area area
;
16553 enum draw_glyphs_face hl
;
16556 struct glyph_string
*head
, *tail
;
16557 struct glyph_string
*s
;
16558 int last_x
, area_width
;
16561 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16564 ALLOCATE_HDC (hdc
, f
);
16566 /* Let's rather be paranoid than getting a SEGV. */
16567 end
= min (end
, row
->used
[area
]);
16568 start
= max (0, start
);
16569 start
= min (end
, start
);
16571 /* Translate X to frame coordinates. Set last_x to the right
16572 end of the drawing area. */
16573 if (row
->full_width_p
)
16575 /* X is relative to the left edge of W, without scroll bars
16577 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
16579 x
+= window_left_x
;
16580 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
16581 last_x
= window_left_x
+ area_width
;
16583 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
16585 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
16586 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
16592 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
16593 /* ++KFS: W32 and MAC versions had -= in next line (bug??) */
16594 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
16598 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
16599 area_width
= window_box_width (w
, area
);
16600 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
16603 /* Build a doubly-linked list of glyph_string structures between
16604 head and tail from what we have to draw. Note that the macro
16605 BUILD_GLYPH_STRINGS will modify its start parameter. That's
16606 the reason we use a separate variable `i'. */
16608 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
16610 x_reached
= tail
->x
+ tail
->background_width
;
16614 /* If there are any glyphs with lbearing < 0 or rbearing > width in
16615 the row, redraw some glyphs in front or following the glyph
16616 strings built above. */
16617 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
16620 struct glyph_string
*h
, *t
;
16622 /* Compute overhangs for all glyph strings. */
16623 if (rif
->compute_glyph_string_overhangs
)
16624 for (s
= head
; s
; s
= s
->next
)
16625 rif
->compute_glyph_string_overhangs (s
);
16627 /* Prepend glyph strings for glyphs in front of the first glyph
16628 string that are overwritten because of the first glyph
16629 string's left overhang. The background of all strings
16630 prepended must be drawn because the first glyph string
16632 i
= left_overwritten (head
);
16636 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
16637 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
16639 compute_overhangs_and_x (t
, head
->x
, 1);
16640 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
16643 /* Prepend glyph strings for glyphs in front of the first glyph
16644 string that overwrite that glyph string because of their
16645 right overhang. For these strings, only the foreground must
16646 be drawn, because it draws over the glyph string at `head'.
16647 The background must not be drawn because this would overwrite
16648 right overhangs of preceding glyphs for which no glyph
16650 i
= left_overwriting (head
);
16653 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
16654 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
16655 for (s
= h
; s
; s
= s
->next
)
16656 s
->background_filled_p
= 1;
16657 compute_overhangs_and_x (t
, head
->x
, 1);
16658 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
16661 /* Append glyphs strings for glyphs following the last glyph
16662 string tail that are overwritten by tail. The background of
16663 these strings has to be drawn because tail's foreground draws
16665 i
= right_overwritten (tail
);
16668 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
16669 DRAW_NORMAL_TEXT
, x
, last_x
);
16670 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
16671 append_glyph_string_lists (&head
, &tail
, h
, t
);
16674 /* Append glyph strings for glyphs following the last glyph
16675 string tail that overwrite tail. The foreground of such
16676 glyphs has to be drawn because it writes into the background
16677 of tail. The background must not be drawn because it could
16678 paint over the foreground of following glyphs. */
16679 i
= right_overwriting (tail
);
16682 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
16683 DRAW_NORMAL_TEXT
, x
, last_x
);
16684 for (s
= h
; s
; s
= s
->next
)
16685 s
->background_filled_p
= 1;
16686 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
16687 append_glyph_string_lists (&head
, &tail
, h
, t
);
16691 /* Draw all strings. */
16692 for (s
= head
; s
; s
= s
->next
)
16693 rif
->draw_glyph_string (s
);
16695 if (area
== TEXT_AREA
16696 && !row
->full_width_p
16697 /* When drawing overlapping rows, only the glyph strings'
16698 foreground is drawn, which doesn't erase a cursor
16702 int x0
= head
? head
->x
: x
;
16703 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
16705 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
16706 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
16708 /* ++KFS: W32 and MAC versions had following test here:
16709 if (!row->full_width_p && XFASTINT (w->left_margin_width) != 0)
16712 if (XFASTINT (w
->left_margin_width
) != 0)
16714 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
16715 x0
-= left_area_width
;
16716 x1
-= left_area_width
;
16719 notice_overwritten_cursor (w
, area
, x0
, x1
,
16720 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
16723 /* Value is the x-position up to which drawn, relative to AREA of W.
16724 This doesn't include parts drawn because of overhangs. */
16725 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
16726 if (!row
->full_width_p
)
16728 /* ++KFS: W32 and MAC versions only had this test here:
16729 if (area > LEFT_MARGIN_AREA)
16732 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
16733 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
16734 if (area
> TEXT_AREA
)
16735 x_reached
-= window_box_width (w
, TEXT_AREA
);
16738 RELEASE_HDC (hdc
, f
);
16744 /* Store one glyph for IT->char_to_display in IT->glyph_row.
16745 Called from x_produce_glyphs when IT->glyph_row is non-null. */
16751 struct glyph
*glyph
;
16752 enum glyph_row_area area
= it
->area
;
16754 xassert (it
->glyph_row
);
16755 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
16757 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
16758 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
16760 glyph
->charpos
= CHARPOS (it
->position
);
16761 glyph
->object
= it
->object
;
16762 glyph
->pixel_width
= it
->pixel_width
;
16763 glyph
->voffset
= it
->voffset
;
16764 glyph
->type
= CHAR_GLYPH
;
16765 glyph
->multibyte_p
= it
->multibyte_p
;
16766 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
16767 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
16768 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
16769 || it
->phys_descent
> it
->descent
);
16770 glyph
->padding_p
= 0;
16771 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
16772 glyph
->face_id
= it
->face_id
;
16773 glyph
->u
.ch
= it
->char_to_display
;
16774 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
16775 ++it
->glyph_row
->used
[area
];
16779 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
16780 Called from x_produce_glyphs when IT->glyph_row is non-null. */
16783 append_composite_glyph (it
)
16786 struct glyph
*glyph
;
16787 enum glyph_row_area area
= it
->area
;
16789 xassert (it
->glyph_row
);
16791 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
16792 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
16794 glyph
->charpos
= CHARPOS (it
->position
);
16795 glyph
->object
= it
->object
;
16796 glyph
->pixel_width
= it
->pixel_width
;
16797 glyph
->voffset
= it
->voffset
;
16798 glyph
->type
= COMPOSITE_GLYPH
;
16799 glyph
->multibyte_p
= it
->multibyte_p
;
16800 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
16801 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
16802 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
16803 || it
->phys_descent
> it
->descent
);
16804 glyph
->padding_p
= 0;
16805 glyph
->glyph_not_available_p
= 0;
16806 glyph
->face_id
= it
->face_id
;
16807 glyph
->u
.cmp_id
= it
->cmp_id
;
16808 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
16809 ++it
->glyph_row
->used
[area
];
16814 /* Change IT->ascent and IT->height according to the setting of
16818 take_vertical_position_into_account (it
)
16823 if (it
->voffset
< 0)
16824 /* Increase the ascent so that we can display the text higher
16826 it
->ascent
+= abs (it
->voffset
);
16828 /* Increase the descent so that we can display the text lower
16830 it
->descent
+= it
->voffset
;
16835 /* Produce glyphs/get display metrics for the image IT is loaded with.
16836 See the description of struct display_iterator in dispextern.h for
16837 an overview of struct display_iterator. */
16840 produce_image_glyph (it
)
16846 xassert (it
->what
== IT_IMAGE
);
16848 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16849 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
16852 /* Make sure X resources of the face and image are loaded. */
16853 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
16854 prepare_image_for_display (it
->f
, img
);
16856 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
16857 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
16858 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
16862 if (face
->box
!= FACE_NO_BOX
)
16864 if (face
->box_line_width
> 0)
16866 it
->ascent
+= face
->box_line_width
;
16867 it
->descent
+= face
->box_line_width
;
16870 if (it
->start_of_box_run_p
)
16871 it
->pixel_width
+= abs (face
->box_line_width
);
16872 if (it
->end_of_box_run_p
)
16873 it
->pixel_width
+= abs (face
->box_line_width
);
16876 take_vertical_position_into_account (it
);
16880 struct glyph
*glyph
;
16881 enum glyph_row_area area
= it
->area
;
16883 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
16884 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
16886 glyph
->charpos
= CHARPOS (it
->position
);
16887 glyph
->object
= it
->object
;
16888 glyph
->pixel_width
= it
->pixel_width
;
16889 glyph
->voffset
= it
->voffset
;
16890 glyph
->type
= IMAGE_GLYPH
;
16891 glyph
->multibyte_p
= it
->multibyte_p
;
16892 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
16893 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
16894 glyph
->overlaps_vertically_p
= 0;
16895 glyph
->padding_p
= 0;
16896 glyph
->glyph_not_available_p
= 0;
16897 glyph
->face_id
= it
->face_id
;
16898 glyph
->u
.img_id
= img
->id
;
16899 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
16900 ++it
->glyph_row
->used
[area
];
16906 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
16907 of the glyph, WIDTH and HEIGHT are the width and height of the
16908 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
16909 ascent of the glyph (0 <= ASCENT <= 1). */
16912 append_stretch_glyph (it
, object
, width
, height
, ascent
)
16914 Lisp_Object object
;
16918 struct glyph
*glyph
;
16919 enum glyph_row_area area
= it
->area
;
16921 xassert (ascent
>= 0 && ascent
<= 1);
16923 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
16924 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
16926 glyph
->charpos
= CHARPOS (it
->position
);
16927 glyph
->object
= object
;
16928 glyph
->pixel_width
= width
;
16929 glyph
->voffset
= it
->voffset
;
16930 glyph
->type
= STRETCH_GLYPH
;
16931 glyph
->multibyte_p
= it
->multibyte_p
;
16932 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
16933 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
16934 glyph
->overlaps_vertically_p
= 0;
16935 glyph
->padding_p
= 0;
16936 glyph
->glyph_not_available_p
= 0;
16937 glyph
->face_id
= it
->face_id
;
16938 glyph
->u
.stretch
.ascent
= height
* ascent
;
16939 glyph
->u
.stretch
.height
= height
;
16940 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
16941 ++it
->glyph_row
->used
[area
];
16946 /* Produce a stretch glyph for iterator IT. IT->object is the value
16947 of the glyph property displayed. The value must be a list
16948 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
16951 1. `:width WIDTH' specifies that the space should be WIDTH *
16952 canonical char width wide. WIDTH may be an integer or floating
16955 2. `:relative-width FACTOR' specifies that the width of the stretch
16956 should be computed from the width of the first character having the
16957 `glyph' property, and should be FACTOR times that width.
16959 3. `:align-to HPOS' specifies that the space should be wide enough
16960 to reach HPOS, a value in canonical character units.
16962 Exactly one of the above pairs must be present.
16964 4. `:height HEIGHT' specifies that the height of the stretch produced
16965 should be HEIGHT, measured in canonical character units.
16967 5. `:relative-height FACTOR' specifies that the height of the
16968 stretch should be FACTOR times the height of the characters having
16969 the glyph property.
16971 Either none or exactly one of 4 or 5 must be present.
16973 6. `:ascent ASCENT' specifies that ASCENT percent of the height
16974 of the stretch should be used for the ascent of the stretch.
16975 ASCENT must be in the range 0 <= ASCENT <= 100. */
16977 #define NUMVAL(X) \
16978 ((INTEGERP (X) || FLOATP (X)) \
16984 produce_stretch_glyph (it
)
16987 /* (space :width WIDTH :height HEIGHT. */
16988 Lisp_Object prop
, plist
;
16989 int width
= 0, height
= 0;
16991 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16992 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
16994 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
16996 /* List should start with `space'. */
16997 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
16998 plist
= XCDR (it
->object
);
17000 /* Compute the width of the stretch. */
17001 if (prop
= Fplist_get (plist
, QCwidth
),
17003 /* Absolute width `:width WIDTH' specified and valid. */
17004 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
17005 else if (prop
= Fplist_get (plist
, QCrelative_width
),
17008 /* Relative width `:relative-width FACTOR' specified and valid.
17009 Compute the width of the characters having the `glyph'
17012 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
17015 if (it
->multibyte_p
)
17017 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
17018 - IT_BYTEPOS (*it
));
17019 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
17022 it2
.c
= *p
, it2
.len
= 1;
17024 it2
.glyph_row
= NULL
;
17025 it2
.what
= IT_CHARACTER
;
17026 x_produce_glyphs (&it2
);
17027 width
= NUMVAL (prop
) * it2
.pixel_width
;
17029 else if (prop
= Fplist_get (plist
, QCalign_to
),
17031 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
17033 /* Nothing specified -> width defaults to canonical char width. */
17034 width
= CANON_X_UNIT (it
->f
);
17036 /* Compute height. */
17037 if (prop
= Fplist_get (plist
, QCheight
),
17039 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
17040 else if (prop
= Fplist_get (plist
, QCrelative_height
),
17042 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
17044 height
= FONT_HEIGHT (font
);
17046 /* Compute percentage of height used for ascent. If
17047 `:ascent ASCENT' is present and valid, use that. Otherwise,
17048 derive the ascent from the font in use. */
17049 if (prop
= Fplist_get (plist
, QCascent
),
17050 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
17051 ascent
= NUMVAL (prop
) / 100.0;
17053 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
17062 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
17063 if (!STRINGP (object
))
17064 object
= it
->w
->buffer
;
17065 append_stretch_glyph (it
, object
, width
, height
, ascent
);
17068 it
->pixel_width
= width
;
17069 it
->ascent
= it
->phys_ascent
= height
* ascent
;
17070 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
17073 if (face
->box
!= FACE_NO_BOX
)
17075 if (face
->box_line_width
> 0)
17077 it
->ascent
+= face
->box_line_width
;
17078 it
->descent
+= face
->box_line_width
;
17081 if (it
->start_of_box_run_p
)
17082 it
->pixel_width
+= abs (face
->box_line_width
);
17083 if (it
->end_of_box_run_p
)
17084 it
->pixel_width
+= abs (face
->box_line_width
);
17087 take_vertical_position_into_account (it
);
17091 Produce glyphs/get display metrics for the display element IT is
17092 loaded with. See the description of struct display_iterator in
17093 dispextern.h for an overview of struct display_iterator. */
17096 x_produce_glyphs (it
)
17099 it
->glyph_not_available_p
= 0;
17101 if (it
->what
== IT_CHARACTER
)
17105 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17107 int font_not_found_p
;
17108 struct font_info
*font_info
;
17109 int boff
; /* baseline offset */
17110 /* We may change it->multibyte_p upon unibyte<->multibyte
17111 conversion. So, save the current value now and restore it
17114 Note: It seems that we don't have to record multibyte_p in
17115 struct glyph because the character code itself tells if or
17116 not the character is multibyte. Thus, in the future, we must
17117 consider eliminating the field `multibyte_p' in the struct
17119 int saved_multibyte_p
= it
->multibyte_p
;
17121 /* Maybe translate single-byte characters to multibyte, or the
17123 it
->char_to_display
= it
->c
;
17124 if (!ASCII_BYTE_P (it
->c
))
17126 if (unibyte_display_via_language_environment
17127 && SINGLE_BYTE_CHAR_P (it
->c
)
17129 || !NILP (Vnonascii_translation_table
)))
17131 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
17132 it
->multibyte_p
= 1;
17133 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
17134 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17136 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
17137 && !it
->multibyte_p
)
17139 it
->multibyte_p
= 1;
17140 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
17141 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17145 /* Get font to use. Encode IT->char_to_display. */
17146 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
17147 &char2b
, it
->multibyte_p
, 0);
17150 /* When no suitable font found, use the default font. */
17151 font_not_found_p
= font
== NULL
;
17152 if (font_not_found_p
)
17154 font
= FRAME_FONT (it
->f
);
17155 boff
= FRAME_BASELINE_OFFSET (it
->f
);
17160 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
17161 boff
= font_info
->baseline_offset
;
17162 if (font_info
->vertical_centering
)
17163 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
17166 if (it
->char_to_display
>= ' '
17167 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
17169 /* Either unibyte or ASCII. */
17174 pcm
= rif
->per_char_metric (font
, &char2b
,
17175 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
17176 it
->ascent
= FONT_BASE (font
) + boff
;
17177 it
->descent
= FONT_DESCENT (font
) - boff
;
17181 it
->phys_ascent
= pcm
->ascent
+ boff
;
17182 it
->phys_descent
= pcm
->descent
- boff
;
17183 it
->pixel_width
= pcm
->width
;
17187 it
->glyph_not_available_p
= 1;
17188 it
->phys_ascent
= FONT_BASE (font
) + boff
;
17189 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17190 it
->pixel_width
= FONT_WIDTH (font
);
17193 /* If this is a space inside a region of text with
17194 `space-width' property, change its width. */
17195 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
17197 it
->pixel_width
*= XFLOATINT (it
->space_width
);
17199 /* If face has a box, add the box thickness to the character
17200 height. If character has a box line to the left and/or
17201 right, add the box line width to the character's width. */
17202 if (face
->box
!= FACE_NO_BOX
)
17204 int thick
= face
->box_line_width
;
17208 it
->ascent
+= thick
;
17209 it
->descent
+= thick
;
17214 if (it
->start_of_box_run_p
)
17215 it
->pixel_width
+= thick
;
17216 if (it
->end_of_box_run_p
)
17217 it
->pixel_width
+= thick
;
17220 /* If face has an overline, add the height of the overline
17221 (1 pixel) and a 1 pixel margin to the character height. */
17222 if (face
->overline_p
)
17225 take_vertical_position_into_account (it
);
17227 /* If we have to actually produce glyphs, do it. */
17232 /* Translate a space with a `space-width' property
17233 into a stretch glyph. */
17234 double ascent
= (double) FONT_BASE (font
)
17235 / FONT_HEIGHT (font
);
17236 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
17237 it
->ascent
+ it
->descent
, ascent
);
17242 /* If characters with lbearing or rbearing are displayed
17243 in this line, record that fact in a flag of the
17244 glyph row. This is used to optimize X output code. */
17245 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
17246 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
17249 else if (it
->char_to_display
== '\n')
17251 /* A newline has no width but we need the height of the line. */
17252 it
->pixel_width
= 0;
17254 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
17255 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17257 if (face
->box
!= FACE_NO_BOX
17258 && face
->box_line_width
> 0)
17260 it
->ascent
+= face
->box_line_width
;
17261 it
->descent
+= face
->box_line_width
;
17264 else if (it
->char_to_display
== '\t')
17266 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
17267 int x
= it
->current_x
+ it
->continuation_lines_width
;
17268 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
17270 /* If the distance from the current position to the next tab
17271 stop is less than a canonical character width, use the
17272 tab stop after that. */
17273 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
17274 next_tab_x
+= tab_width
;
17276 it
->pixel_width
= next_tab_x
- x
;
17278 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
17279 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17283 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
17284 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
17285 it
->ascent
+ it
->descent
, ascent
);
17290 /* A multi-byte character. Assume that the display width of the
17291 character is the width of the character multiplied by the
17292 width of the font. */
17294 /* If we found a font, this font should give us the right
17295 metrics. If we didn't find a font, use the frame's
17296 default font and calculate the width of the character
17297 from the charset width; this is what old redisplay code
17300 pcm
= rif
->per_char_metric (font
, &char2b
,
17301 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
17303 if (font_not_found_p
|| !pcm
)
17305 int charset
= CHAR_CHARSET (it
->char_to_display
);
17307 it
->glyph_not_available_p
= 1;
17308 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
17309 * CHARSET_WIDTH (charset
));
17310 it
->phys_ascent
= FONT_BASE (font
) + boff
;
17311 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17315 it
->pixel_width
= pcm
->width
;
17316 it
->phys_ascent
= pcm
->ascent
+ boff
;
17317 it
->phys_descent
= pcm
->descent
- boff
;
17319 && (pcm
->lbearing
< 0
17320 || pcm
->rbearing
> pcm
->width
))
17321 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
17324 it
->ascent
= FONT_BASE (font
) + boff
;
17325 it
->descent
= FONT_DESCENT (font
) - boff
;
17326 if (face
->box
!= FACE_NO_BOX
)
17328 int thick
= face
->box_line_width
;
17332 it
->ascent
+= thick
;
17333 it
->descent
+= thick
;
17338 if (it
->start_of_box_run_p
)
17339 it
->pixel_width
+= thick
;
17340 if (it
->end_of_box_run_p
)
17341 it
->pixel_width
+= thick
;
17344 /* If face has an overline, add the height of the overline
17345 (1 pixel) and a 1 pixel margin to the character height. */
17346 if (face
->overline_p
)
17349 take_vertical_position_into_account (it
);
17354 it
->multibyte_p
= saved_multibyte_p
;
17356 else if (it
->what
== IT_COMPOSITION
)
17358 /* Note: A composition is represented as one glyph in the
17359 glyph matrix. There are no padding glyphs. */
17362 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17364 int font_not_found_p
;
17365 struct font_info
*font_info
;
17366 int boff
; /* baseline offset */
17367 struct composition
*cmp
= composition_table
[it
->cmp_id
];
17369 /* Maybe translate single-byte characters to multibyte. */
17370 it
->char_to_display
= it
->c
;
17371 if (unibyte_display_via_language_environment
17372 && SINGLE_BYTE_CHAR_P (it
->c
)
17375 && !NILP (Vnonascii_translation_table
))))
17377 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
17380 /* Get face and font to use. Encode IT->char_to_display. */
17381 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
17382 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17383 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
17384 &char2b
, it
->multibyte_p
, 0);
17387 /* When no suitable font found, use the default font. */
17388 font_not_found_p
= font
== NULL
;
17389 if (font_not_found_p
)
17391 font
= FRAME_FONT (it
->f
);
17392 boff
= FRAME_BASELINE_OFFSET (it
->f
);
17397 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
17398 boff
= font_info
->baseline_offset
;
17399 if (font_info
->vertical_centering
)
17400 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
17403 /* There are no padding glyphs, so there is only one glyph to
17404 produce for the composition. Important is that pixel_width,
17405 ascent and descent are the values of what is drawn by
17406 draw_glyphs (i.e. the values of the overall glyphs composed). */
17409 /* If we have not yet calculated pixel size data of glyphs of
17410 the composition for the current face font, calculate them
17411 now. Theoretically, we have to check all fonts for the
17412 glyphs, but that requires much time and memory space. So,
17413 here we check only the font of the first glyph. This leads
17414 to incorrect display very rarely, and C-l (recenter) can
17415 correct the display anyway. */
17416 if (cmp
->font
!= (void *) font
)
17418 /* Ascent and descent of the font of the first character of
17419 this composition (adjusted by baseline offset). Ascent
17420 and descent of overall glyphs should not be less than
17421 them respectively. */
17422 int font_ascent
= FONT_BASE (font
) + boff
;
17423 int font_descent
= FONT_DESCENT (font
) - boff
;
17424 /* Bounding box of the overall glyphs. */
17425 int leftmost
, rightmost
, lowest
, highest
;
17426 int i
, width
, ascent
, descent
;
17428 cmp
->font
= (void *) font
;
17430 /* Initialize the bounding box. */
17432 && (pcm
= rif
->per_char_metric (font
, &char2b
,
17433 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
17435 width
= pcm
->width
;
17436 ascent
= pcm
->ascent
;
17437 descent
= pcm
->descent
;
17441 width
= FONT_WIDTH (font
);
17442 ascent
= FONT_BASE (font
);
17443 descent
= FONT_DESCENT (font
);
17447 lowest
= - descent
+ boff
;
17448 highest
= ascent
+ boff
;
17452 && font_info
->default_ascent
17453 && CHAR_TABLE_P (Vuse_default_ascent
)
17454 && !NILP (Faref (Vuse_default_ascent
,
17455 make_number (it
->char_to_display
))))
17456 highest
= font_info
->default_ascent
+ boff
;
17458 /* Draw the first glyph at the normal position. It may be
17459 shifted to right later if some other glyphs are drawn at
17461 cmp
->offsets
[0] = 0;
17462 cmp
->offsets
[1] = boff
;
17464 /* Set cmp->offsets for the remaining glyphs. */
17465 for (i
= 1; i
< cmp
->glyph_len
; i
++)
17467 int left
, right
, btm
, top
;
17468 int ch
= COMPOSITION_GLYPH (cmp
, i
);
17469 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
17471 face
= FACE_FROM_ID (it
->f
, face_id
);
17472 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
17473 &char2b
, it
->multibyte_p
, 0);
17477 font
= FRAME_FONT (it
->f
);
17478 boff
= FRAME_BASELINE_OFFSET (it
->f
);
17484 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
17485 boff
= font_info
->baseline_offset
;
17486 if (font_info
->vertical_centering
)
17487 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
17491 && (pcm
= rif
->per_char_metric (font
, &char2b
,
17492 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
17494 width
= pcm
->width
;
17495 ascent
= pcm
->ascent
;
17496 descent
= pcm
->descent
;
17500 width
= FONT_WIDTH (font
);
17505 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
17507 /* Relative composition with or without
17508 alternate chars. */
17509 left
= (leftmost
+ rightmost
- width
) / 2;
17510 btm
= - descent
+ boff
;
17511 if (font_info
&& font_info
->relative_compose
17512 && (! CHAR_TABLE_P (Vignore_relative_composition
)
17513 || NILP (Faref (Vignore_relative_composition
,
17514 make_number (ch
)))))
17517 if (- descent
>= font_info
->relative_compose
)
17518 /* One extra pixel between two glyphs. */
17520 else if (ascent
<= 0)
17521 /* One extra pixel between two glyphs. */
17522 btm
= lowest
- 1 - ascent
- descent
;
17527 /* A composition rule is specified by an integer
17528 value that encodes global and new reference
17529 points (GREF and NREF). GREF and NREF are
17530 specified by numbers as below:
17532 0---1---2 -- ascent
17536 9--10--11 -- center
17538 ---3---4---5--- baseline
17540 6---7---8 -- descent
17542 int rule
= COMPOSITION_RULE (cmp
, i
);
17543 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
17545 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
17546 grefx
= gref
% 3, nrefx
= nref
% 3;
17547 grefy
= gref
/ 3, nrefy
= nref
/ 3;
17550 + grefx
* (rightmost
- leftmost
) / 2
17551 - nrefx
* width
/ 2);
17552 btm
= ((grefy
== 0 ? highest
17554 : grefy
== 2 ? lowest
17555 : (highest
+ lowest
) / 2)
17556 - (nrefy
== 0 ? ascent
+ descent
17557 : nrefy
== 1 ? descent
- boff
17559 : (ascent
+ descent
) / 2));
17562 cmp
->offsets
[i
* 2] = left
;
17563 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
17565 /* Update the bounding box of the overall glyphs. */
17566 right
= left
+ width
;
17567 top
= btm
+ descent
+ ascent
;
17568 if (left
< leftmost
)
17570 if (right
> rightmost
)
17578 /* If there are glyphs whose x-offsets are negative,
17579 shift all glyphs to the right and make all x-offsets
17583 for (i
= 0; i
< cmp
->glyph_len
; i
++)
17584 cmp
->offsets
[i
* 2] -= leftmost
;
17585 rightmost
-= leftmost
;
17588 cmp
->pixel_width
= rightmost
;
17589 cmp
->ascent
= highest
;
17590 cmp
->descent
= - lowest
;
17591 if (cmp
->ascent
< font_ascent
)
17592 cmp
->ascent
= font_ascent
;
17593 if (cmp
->descent
< font_descent
)
17594 cmp
->descent
= font_descent
;
17597 it
->pixel_width
= cmp
->pixel_width
;
17598 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
17599 it
->descent
= it
->phys_descent
= cmp
->descent
;
17601 if (face
->box
!= FACE_NO_BOX
)
17603 int thick
= face
->box_line_width
;
17607 it
->ascent
+= thick
;
17608 it
->descent
+= thick
;
17613 if (it
->start_of_box_run_p
)
17614 it
->pixel_width
+= thick
;
17615 if (it
->end_of_box_run_p
)
17616 it
->pixel_width
+= thick
;
17619 /* If face has an overline, add the height of the overline
17620 (1 pixel) and a 1 pixel margin to the character height. */
17621 if (face
->overline_p
)
17624 take_vertical_position_into_account (it
);
17627 append_composite_glyph (it
);
17629 else if (it
->what
== IT_IMAGE
)
17630 produce_image_glyph (it
);
17631 else if (it
->what
== IT_STRETCH
)
17632 produce_stretch_glyph (it
);
17634 /* Accumulate dimensions. Note: can't assume that it->descent > 0
17635 because this isn't true for images with `:ascent 100'. */
17636 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
17637 if (it
->area
== TEXT_AREA
)
17638 it
->current_x
+= it
->pixel_width
;
17640 it
->descent
+= it
->extra_line_spacing
;
17642 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
17643 it
->max_descent
= max (it
->max_descent
, it
->descent
);
17644 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
17645 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
17653 /***********************************************************************
17655 ***********************************************************************/
17657 /* Value is the internal representation of the specified cursor type
17658 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
17659 of the bar cursor. */
17661 enum text_cursor_kinds
17662 get_specified_cursor_type (arg
, width
)
17666 enum text_cursor_kinds type
;
17671 if (EQ (arg
, Qbox
))
17672 return FILLED_BOX_CURSOR
;
17674 if (EQ (arg
, Qhollow
))
17675 return HOLLOW_BOX_CURSOR
;
17677 if (EQ (arg
, Qbar
))
17684 && EQ (XCAR (arg
), Qbar
)
17685 && INTEGERP (XCDR (arg
))
17686 && XINT (XCDR (arg
)) >= 0)
17688 *width
= XINT (XCDR (arg
));
17692 if (EQ (arg
, Qhbar
))
17695 return HBAR_CURSOR
;
17699 && EQ (XCAR (arg
), Qhbar
)
17700 && INTEGERP (XCDR (arg
))
17701 && XINT (XCDR (arg
)) >= 0)
17703 *width
= XINT (XCDR (arg
));
17704 return HBAR_CURSOR
;
17707 /* Treat anything unknown as "hollow box cursor".
17708 It was bad to signal an error; people have trouble fixing
17709 .Xdefaults with Emacs, when it has something bad in it. */
17710 type
= HOLLOW_BOX_CURSOR
;
17715 /* Set the default cursor types for specified frame. */
17717 set_frame_cursor_types (f
, arg
)
17724 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
17725 FRAME_CURSOR_WIDTH (f
) = width
;
17727 /* By default, set up the blink-off state depending on the on-state. */
17729 tem
= Fassoc (arg
, Vblink_cursor_alist
);
17732 FRAME_BLINK_OFF_CURSOR (f
)
17733 = get_specified_cursor_type (XCDR (tem
), &width
);
17734 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
17737 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
17741 /* Return the cursor we want to be displayed in window W. Return
17742 width of bar/hbar cursor through WIDTH arg. Return with
17743 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
17744 (i.e. if the `system caret' should track this cursor).
17746 In a mini-buffer window, we want the cursor only to appear if we
17747 are reading input from this window. For the selected window, we
17748 want the cursor type given by the frame parameter or buffer local
17749 setting of cursor-type. If explicitly marked off, draw no cursor.
17750 In all other cases, we want a hollow box cursor. */
17752 enum text_cursor_kinds
17753 get_window_cursor_type (w
, width
, active_cursor
)
17756 int *active_cursor
;
17758 struct frame
*f
= XFRAME (w
->frame
);
17759 struct buffer
*b
= XBUFFER (w
->buffer
);
17760 int cursor_type
= DEFAULT_CURSOR
;
17761 Lisp_Object alt_cursor
;
17762 int non_selected
= 0;
17764 *active_cursor
= 1;
17767 if (cursor_in_echo_area
17768 && FRAME_HAS_MINIBUF_P (f
)
17769 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
17771 if (w
== XWINDOW (echo_area_window
))
17773 *width
= FRAME_CURSOR_WIDTH (f
);
17774 return FRAME_DESIRED_CURSOR (f
);
17777 *active_cursor
= 0;
17781 /* Nonselected window or nonselected frame. */
17782 else if (w
!= XWINDOW (f
->selected_window
)
17783 #ifdef HAVE_WINDOW_SYSTEM
17784 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
17788 *active_cursor
= 0;
17790 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
17796 /* Never display a cursor in a window in which cursor-type is nil. */
17797 if (NILP (b
->cursor_type
))
17800 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
17803 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
17804 return get_specified_cursor_type (alt_cursor
, width
);
17807 /* Get the normal cursor type for this window. */
17808 if (EQ (b
->cursor_type
, Qt
))
17810 cursor_type
= FRAME_DESIRED_CURSOR (f
);
17811 *width
= FRAME_CURSOR_WIDTH (f
);
17814 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
17816 /* Use normal cursor if not blinked off. */
17817 if (!w
->cursor_off_p
)
17818 return cursor_type
;
17820 /* Cursor is blinked off, so determine how to "toggle" it. */
17822 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
17823 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
17824 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
17826 /* Then see if frame has specified a specific blink off cursor type. */
17827 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
17829 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
17830 return FRAME_BLINK_OFF_CURSOR (f
);
17833 /* Finally perform built-in cursor blinking:
17834 filled box <-> hollow box
17835 wide [h]bar <-> narrow [h]bar
17836 narrow [h]bar <-> no cursor
17837 other type <-> no cursor */
17839 if (cursor_type
== FILLED_BOX_CURSOR
)
17840 return HOLLOW_BOX_CURSOR
;
17842 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
17845 return cursor_type
;
17852 /* Notice when the text cursor of window W has been completely
17853 overwritten by a drawing operation that outputs glyphs in AREA
17854 starting at X0 and ending at X1 in the line starting at Y0 and
17855 ending at Y1. X coordinates are area-relative. X1 < 0 means all
17856 the rest of the line after X0 has been written. Y coordinates
17857 are window-relative. */
17860 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
17862 enum glyph_row_area area
;
17863 int x0
, y0
, x1
, y1
;
17866 /* ++KFS: Why is there a special version of this for the mac ? */
17867 if (area
== TEXT_AREA
17868 && w
->phys_cursor_on_p
17869 && y0
<= w
->phys_cursor
.y
17870 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
17871 && x0
<= w
->phys_cursor
.x
17872 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
17873 w
->phys_cursor_on_p
= 0;
17875 if (area
== TEXT_AREA
&& w
->phys_cursor_on_p
)
17877 int cx0
= w
->phys_cursor
.x
;
17878 int cx1
= cx0
+ w
->phys_cursor_width
;
17879 int cy0
= w
->phys_cursor
.y
;
17880 int cy1
= cy0
+ w
->phys_cursor_height
;
17882 if (x0
<= cx0
&& (x1
< 0 || x1
>= cx1
))
17884 /* The cursor image will be completely removed from the
17885 screen if the output area intersects the cursor area in
17886 y-direction. When we draw in [y0 y1[, and some part of
17887 the cursor is at y < y0, that part must have been drawn
17888 before. When scrolling, the cursor is erased before
17889 actually scrolling, so we don't come here. When not
17890 scrolling, the rows above the old cursor row must have
17891 changed, and in this case these rows must have written
17892 over the cursor image.
17894 Likewise if part of the cursor is below y1, with the
17895 exception of the cursor being in the first blank row at
17896 the buffer and window end because update_text_area
17897 doesn't draw that row. (Except when it does, but
17898 that's handled in update_text_area.) */
17900 if (((y0
>= cy0
&& y0
< cy1
) || (y1
> cy0
&& y1
< cy1
))
17901 && w
->current_matrix
->rows
[w
->phys_cursor
.vpos
].displays_text_p
)
17902 w
->phys_cursor_on_p
= 0;
17909 /***********************************************************************
17911 ***********************************************************************/
17916 Vwith_echo_area_save_vector
= Qnil
;
17917 staticpro (&Vwith_echo_area_save_vector
);
17919 Vmessage_stack
= Qnil
;
17920 staticpro (&Vmessage_stack
);
17922 Qinhibit_redisplay
= intern ("inhibit-redisplay");
17923 staticpro (&Qinhibit_redisplay
);
17925 message_dolog_marker1
= Fmake_marker ();
17926 staticpro (&message_dolog_marker1
);
17927 message_dolog_marker2
= Fmake_marker ();
17928 staticpro (&message_dolog_marker2
);
17929 message_dolog_marker3
= Fmake_marker ();
17930 staticpro (&message_dolog_marker3
);
17933 defsubr (&Sdump_frame_glyph_matrix
);
17934 defsubr (&Sdump_glyph_matrix
);
17935 defsubr (&Sdump_glyph_row
);
17936 defsubr (&Sdump_tool_bar_row
);
17937 defsubr (&Strace_redisplay
);
17938 defsubr (&Strace_to_stderr
);
17940 #ifdef HAVE_WINDOW_SYSTEM
17941 defsubr (&Stool_bar_lines_needed
);
17943 defsubr (&Sformat_mode_line
);
17945 staticpro (&Qmenu_bar_update_hook
);
17946 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
17948 staticpro (&Qoverriding_terminal_local_map
);
17949 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
17951 staticpro (&Qoverriding_local_map
);
17952 Qoverriding_local_map
= intern ("overriding-local-map");
17954 staticpro (&Qwindow_scroll_functions
);
17955 Qwindow_scroll_functions
= intern ("window-scroll-functions");
17957 staticpro (&Qredisplay_end_trigger_functions
);
17958 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
17960 staticpro (&Qinhibit_point_motion_hooks
);
17961 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
17963 QCdata
= intern (":data");
17964 staticpro (&QCdata
);
17965 Qdisplay
= intern ("display");
17966 staticpro (&Qdisplay
);
17967 Qspace_width
= intern ("space-width");
17968 staticpro (&Qspace_width
);
17969 Qraise
= intern ("raise");
17970 staticpro (&Qraise
);
17971 Qspace
= intern ("space");
17972 staticpro (&Qspace
);
17973 Qmargin
= intern ("margin");
17974 staticpro (&Qmargin
);
17975 Qleft_margin
= intern ("left-margin");
17976 staticpro (&Qleft_margin
);
17977 Qright_margin
= intern ("right-margin");
17978 staticpro (&Qright_margin
);
17979 Qalign_to
= intern ("align-to");
17980 staticpro (&Qalign_to
);
17981 QCalign_to
= intern (":align-to");
17982 staticpro (&QCalign_to
);
17983 Qrelative_width
= intern ("relative-width");
17984 staticpro (&Qrelative_width
);
17985 QCrelative_width
= intern (":relative-width");
17986 staticpro (&QCrelative_width
);
17987 QCrelative_height
= intern (":relative-height");
17988 staticpro (&QCrelative_height
);
17989 QCeval
= intern (":eval");
17990 staticpro (&QCeval
);
17991 QCpropertize
= intern (":propertize");
17992 staticpro (&QCpropertize
);
17993 QCfile
= intern (":file");
17994 staticpro (&QCfile
);
17995 Qfontified
= intern ("fontified");
17996 staticpro (&Qfontified
);
17997 Qfontification_functions
= intern ("fontification-functions");
17998 staticpro (&Qfontification_functions
);
17999 Qtrailing_whitespace
= intern ("trailing-whitespace");
18000 staticpro (&Qtrailing_whitespace
);
18001 Qimage
= intern ("image");
18002 staticpro (&Qimage
);
18003 Qmessage_truncate_lines
= intern ("message-truncate-lines");
18004 staticpro (&Qmessage_truncate_lines
);
18005 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
18006 staticpro (&Qcursor_in_non_selected_windows
);
18007 Qgrow_only
= intern ("grow-only");
18008 staticpro (&Qgrow_only
);
18009 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
18010 staticpro (&Qinhibit_menubar_update
);
18011 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
18012 staticpro (&Qinhibit_eval_during_redisplay
);
18013 Qposition
= intern ("position");
18014 staticpro (&Qposition
);
18015 Qbuffer_position
= intern ("buffer-position");
18016 staticpro (&Qbuffer_position
);
18017 Qobject
= intern ("object");
18018 staticpro (&Qobject
);
18019 Qbar
= intern ("bar");
18021 Qhbar
= intern ("hbar");
18022 staticpro (&Qhbar
);
18023 Qbox
= intern ("box");
18025 Qhollow
= intern ("hollow");
18026 staticpro (&Qhollow
);
18027 Qrisky_local_variable
= intern ("risky-local-variable");
18028 staticpro (&Qrisky_local_variable
);
18029 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
18030 staticpro (&Qinhibit_free_realized_faces
);
18032 list_of_error
= Fcons (intern ("error"), Qnil
);
18033 staticpro (&list_of_error
);
18035 last_arrow_position
= Qnil
;
18036 last_arrow_string
= Qnil
;
18037 staticpro (&last_arrow_position
);
18038 staticpro (&last_arrow_string
);
18040 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
18041 staticpro (&echo_buffer
[0]);
18042 staticpro (&echo_buffer
[1]);
18044 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
18045 staticpro (&echo_area_buffer
[0]);
18046 staticpro (&echo_area_buffer
[1]);
18048 Vmessages_buffer_name
= build_string ("*Messages*");
18049 staticpro (&Vmessages_buffer_name
);
18051 mode_line_proptrans_alist
= Qnil
;
18052 staticpro (&mode_line_proptrans_alist
);
18054 mode_line_string_list
= Qnil
;
18055 staticpro (&mode_line_string_list
);
18057 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
18058 doc
: /* Non-nil means highlight trailing whitespace.
18059 The face used for trailing whitespace is `trailing-whitespace'. */);
18060 Vshow_trailing_whitespace
= Qnil
;
18062 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
18063 doc
: /* Non-nil means don't actually do any redisplay.
18064 This is used for internal purposes. */);
18065 Vinhibit_redisplay
= Qnil
;
18067 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
18068 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
18069 Vglobal_mode_string
= Qnil
;
18071 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
18072 doc
: /* Marker for where to display an arrow on top of the buffer text.
18073 This must be the beginning of a line in order to work.
18074 See also `overlay-arrow-string'. */);
18075 Voverlay_arrow_position
= Qnil
;
18077 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
18078 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
18079 Voverlay_arrow_string
= Qnil
;
18081 DEFVAR_INT ("scroll-step", &scroll_step
,
18082 doc
: /* *The number of lines to try scrolling a window by when point moves out.
18083 If that fails to bring point back on frame, point is centered instead.
18084 If this is zero, point is always centered after it moves off frame.
18085 If you want scrolling to always be a line at a time, you should set
18086 `scroll-conservatively' to a large value rather than set this to 1. */);
18088 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
18089 doc
: /* *Scroll up to this many lines, to bring point back on screen.
18090 A value of zero means to scroll the text to center point vertically
18091 in the window. */);
18092 scroll_conservatively
= 0;
18094 DEFVAR_INT ("scroll-margin", &scroll_margin
,
18095 doc
: /* *Number of lines of margin at the top and bottom of a window.
18096 Recenter the window whenever point gets within this many lines
18097 of the top or bottom of the window. */);
18101 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
18104 DEFVAR_BOOL ("truncate-partial-width-windows",
18105 &truncate_partial_width_windows
,
18106 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
18107 truncate_partial_width_windows
= 1;
18109 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
18110 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
18111 Any other value means to use the appropriate face, `mode-line',
18112 `header-line', or `menu' respectively. */);
18113 mode_line_inverse_video
= 1;
18115 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
18116 doc
: /* *Maximum buffer size for which line number should be displayed.
18117 If the buffer is bigger than this, the line number does not appear
18118 in the mode line. A value of nil means no limit. */);
18119 Vline_number_display_limit
= Qnil
;
18121 DEFVAR_INT ("line-number-display-limit-width",
18122 &line_number_display_limit_width
,
18123 doc
: /* *Maximum line width (in characters) for line number display.
18124 If the average length of the lines near point is bigger than this, then the
18125 line number may be omitted from the mode line. */);
18126 line_number_display_limit_width
= 200;
18128 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
18129 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
18130 highlight_nonselected_windows
= 0;
18132 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
18133 doc
: /* Non-nil if more than one frame is visible on this display.
18134 Minibuffer-only frames don't count, but iconified frames do.
18135 This variable is not guaranteed to be accurate except while processing
18136 `frame-title-format' and `icon-title-format'. */);
18138 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
18139 doc
: /* Template for displaying the title bar of visible frames.
18140 \(Assuming the window manager supports this feature.)
18141 This variable has the same structure as `mode-line-format' (which see),
18142 and is used only on frames for which no explicit name has been set
18143 \(see `modify-frame-parameters'). */);
18144 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
18145 doc
: /* Template for displaying the title bar of an iconified frame.
18146 \(Assuming the window manager supports this feature.)
18147 This variable has the same structure as `mode-line-format' (which see),
18148 and is used only on frames for which no explicit name has been set
18149 \(see `modify-frame-parameters'). */);
18151 = Vframe_title_format
18152 = Fcons (intern ("multiple-frames"),
18153 Fcons (build_string ("%b"),
18154 Fcons (Fcons (empty_string
,
18155 Fcons (intern ("invocation-name"),
18156 Fcons (build_string ("@"),
18157 Fcons (intern ("system-name"),
18161 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
18162 doc
: /* Maximum number of lines to keep in the message log buffer.
18163 If nil, disable message logging. If t, log messages but don't truncate
18164 the buffer when it becomes large. */);
18165 Vmessage_log_max
= make_number (50);
18167 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
18168 doc
: /* Functions called before redisplay, if window sizes have changed.
18169 The value should be a list of functions that take one argument.
18170 Just before redisplay, for each frame, if any of its windows have changed
18171 size since the last redisplay, or have been split or deleted,
18172 all the functions in the list are called, with the frame as argument. */);
18173 Vwindow_size_change_functions
= Qnil
;
18175 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
18176 doc
: /* List of Functions to call before redisplaying a window with scrolling.
18177 Each function is called with two arguments, the window
18178 and its new display-start position. Note that the value of `window-end'
18179 is not valid when these functions are called. */);
18180 Vwindow_scroll_functions
= Qnil
;
18182 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
18183 doc
: /* *Non-nil means automatically resize tool-bars.
18184 This increases a tool-bar's height if not all tool-bar items are visible.
18185 It decreases a tool-bar's height when it would display blank lines
18187 auto_resize_tool_bars_p
= 1;
18189 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
18190 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
18191 auto_raise_tool_bar_buttons_p
= 1;
18193 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
18194 doc
: /* *Margin around tool-bar buttons in pixels.
18195 If an integer, use that for both horizontal and vertical margins.
18196 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
18197 HORZ specifying the horizontal margin, and VERT specifying the
18198 vertical margin. */);
18199 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
18201 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
18202 doc
: /* *Relief thickness of tool-bar buttons. */);
18203 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
18205 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
18206 doc
: /* List of functions to call to fontify regions of text.
18207 Each function is called with one argument POS. Functions must
18208 fontify a region starting at POS in the current buffer, and give
18209 fontified regions the property `fontified'. */);
18210 Vfontification_functions
= Qnil
;
18211 Fmake_variable_buffer_local (Qfontification_functions
);
18213 DEFVAR_BOOL ("unibyte-display-via-language-environment",
18214 &unibyte_display_via_language_environment
,
18215 doc
: /* *Non-nil means display unibyte text according to language environment.
18216 Specifically this means that unibyte non-ASCII characters
18217 are displayed by converting them to the equivalent multibyte characters
18218 according to the current language environment. As a result, they are
18219 displayed according to the current fontset. */);
18220 unibyte_display_via_language_environment
= 0;
18222 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
18223 doc
: /* *Maximum height for resizing mini-windows.
18224 If a float, it specifies a fraction of the mini-window frame's height.
18225 If an integer, it specifies a number of lines. */);
18226 Vmax_mini_window_height
= make_float (0.25);
18228 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
18229 doc
: /* *How to resize mini-windows.
18230 A value of nil means don't automatically resize mini-windows.
18231 A value of t means resize them to fit the text displayed in them.
18232 A value of `grow-only', the default, means let mini-windows grow
18233 only, until their display becomes empty, at which point the windows
18234 go back to their normal size. */);
18235 Vresize_mini_windows
= Qgrow_only
;
18237 DEFVAR_LISP ("cursor-in-non-selected-windows",
18238 &Vcursor_in_non_selected_windows
,
18239 doc
: /* *Cursor type to display in non-selected windows.
18240 t means to use hollow box cursor. See `cursor-type' for other values. */);
18241 Vcursor_in_non_selected_windows
= Qt
;
18243 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
18244 doc
: /* Alist specifying how to blink the cursor off.
18245 Each element has the form (ON-STATE . OFF-STATE). Whenever the
18246 `cursor-type' frame-parameter or variable equals ON-STATE,
18247 comparing using `equal', Emacs uses OFF-STATE to specify
18248 how to blink it off. */);
18249 Vblink_cursor_alist
= Qnil
;
18251 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
18252 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
18253 automatic_hscrolling_p
= 1;
18255 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
18256 doc
: /* *How many columns away from the window edge point is allowed to get
18257 before automatic hscrolling will horizontally scroll the window. */);
18258 hscroll_margin
= 5;
18260 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
18261 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
18262 When point is less than `automatic-hscroll-margin' columns from the window
18263 edge, automatic hscrolling will scroll the window by the amount of columns
18264 determined by this variable. If its value is a positive integer, scroll that
18265 many columns. If it's a positive floating-point number, it specifies the
18266 fraction of the window's width to scroll. If it's nil or zero, point will be
18267 centered horizontally after the scroll. Any other value, including negative
18268 numbers, are treated as if the value were zero.
18270 Automatic hscrolling always moves point outside the scroll margin, so if
18271 point was more than scroll step columns inside the margin, the window will
18272 scroll more than the value given by the scroll step.
18274 Note that the lower bound for automatic hscrolling specified by `scroll-left'
18275 and `scroll-right' overrides this variable's effect. */);
18276 Vhscroll_step
= make_number (0);
18278 DEFVAR_LISP ("image-types", &Vimage_types
,
18279 doc
: /* List of supported image types.
18280 Each element of the list is a symbol for a supported image type. */);
18281 Vimage_types
= Qnil
;
18283 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
18284 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
18285 Bind this around calls to `message' to let it take effect. */);
18286 message_truncate_lines
= 0;
18288 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
18289 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
18290 Can be used to update submenus whose contents should vary. */);
18291 Vmenu_bar_update_hook
= Qnil
;
18293 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
18294 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
18295 inhibit_menubar_update
= 0;
18297 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
18298 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
18299 inhibit_eval_during_redisplay
= 0;
18301 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
18302 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
18303 inhibit_free_realized_faces
= 0;
18306 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
18307 doc
: /* Inhibit try_window_id display optimization. */);
18308 inhibit_try_window_id
= 0;
18310 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
18311 doc
: /* Inhibit try_window_reusing display optimization. */);
18312 inhibit_try_window_reusing
= 0;
18314 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
18315 doc
: /* Inhibit try_cursor_movement display optimization. */);
18316 inhibit_try_cursor_movement
= 0;
18317 #endif /* GLYPH_DEBUG */
18321 /* Initialize this module when Emacs starts. */
18326 Lisp_Object root_window
;
18327 struct window
*mini_w
;
18329 current_header_line_height
= current_mode_line_height
= -1;
18331 CHARPOS (this_line_start_pos
) = 0;
18333 mini_w
= XWINDOW (minibuf_window
);
18334 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
18336 if (!noninteractive
)
18338 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
18341 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
18342 set_window_height (root_window
,
18343 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
18345 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
18346 set_window_height (minibuf_window
, 1, 0);
18348 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
18349 mini_w
->width
= make_number (FRAME_WIDTH (f
));
18351 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
18352 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
18353 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
18355 /* The default ellipsis glyphs `...'. */
18356 for (i
= 0; i
< 3; ++i
)
18357 default_invis_vector
[i
] = make_number ('.');
18361 /* Allocate the buffer for frame titles.
18362 Also used for `format-mode-line'. */
18364 frame_title_buf
= (char *) xmalloc (size
);
18365 frame_title_buf_end
= frame_title_buf
+ size
;
18366 frame_title_ptr
= NULL
;
18369 help_echo_showing_p
= 0;