1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 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"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
203 #ifndef FRAME_X_OUTPUT
204 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
207 #define INFINITY 10000000
209 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
211 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
212 extern int pending_menu_activation
;
215 extern int interrupt_input
;
216 extern int command_loop_level
;
218 extern Lisp_Object do_mouse_tracking
;
220 extern int minibuffer_auto_raise
;
221 extern Lisp_Object Vminibuffer_list
;
223 extern Lisp_Object Qface
;
224 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
226 extern Lisp_Object Voverriding_local_map
;
227 extern Lisp_Object Voverriding_local_map_menu_flag
;
228 extern Lisp_Object Qmenu_item
;
229 extern Lisp_Object Qwhen
;
230 extern Lisp_Object Qhelp_echo
;
232 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
233 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
234 Lisp_Object Qredisplay_end_trigger_functions
;
235 Lisp_Object Qinhibit_point_motion_hooks
;
236 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
237 Lisp_Object Qfontified
;
238 Lisp_Object Qgrow_only
;
239 Lisp_Object Qinhibit_eval_during_redisplay
;
240 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
243 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Non-zero means to reposition window if cursor line is only partially visible. */
269 int make_cursor_line_fully_visible_p
;
271 /* Margin around tool bar buttons in pixels. */
273 Lisp_Object Vtool_bar_button_margin
;
275 /* Thickness of shadow to draw around tool bar buttons. */
277 EMACS_INT tool_bar_button_relief
;
279 /* Non-zero means automatically resize tool-bars so that all tool-bar
280 items are visible, and no blank lines remain. */
282 int auto_resize_tool_bars_p
;
284 /* Non-zero means draw block and hollow cursor as wide as the glyph
285 under it. For example, if a block cursor is over a tab, it will be
286 drawn as wide as that tab on the display. */
288 int x_stretch_cursor_p
;
290 /* Non-nil means don't actually do any redisplay. */
292 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
294 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
296 int inhibit_eval_during_redisplay
;
298 /* Names of text properties relevant for redisplay. */
300 Lisp_Object Qdisplay
;
301 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
303 /* Symbols used in text property values. */
305 Lisp_Object Vdisplay_pixels_per_inch
;
306 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
307 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
310 Lisp_Object Qmargin
, Qpointer
;
311 Lisp_Object Qline_height
;
312 extern Lisp_Object Qheight
;
313 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
314 extern Lisp_Object Qscroll_bar
;
315 extern Lisp_Object Qcursor
;
317 /* Non-nil means highlight trailing whitespace. */
319 Lisp_Object Vshow_trailing_whitespace
;
321 /* Non-nil means escape non-break space and hyphens. */
323 Lisp_Object Vshow_nonbreak_escape
;
325 #ifdef HAVE_WINDOW_SYSTEM
326 extern Lisp_Object Voverflow_newline_into_fringe
;
328 /* Test if overflow newline into fringe. Called with iterator IT
329 at or past right window margin, and with IT->current_x set. */
331 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
332 (!NILP (Voverflow_newline_into_fringe) \
333 && FRAME_WINDOW_P (it->f) \
334 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
335 && it->current_x == it->last_visible_x)
337 #endif /* HAVE_WINDOW_SYSTEM */
339 /* Non-nil means show the text cursor in void text areas
340 i.e. in blank areas after eol and eob. This used to be
341 the default in 21.3. */
343 Lisp_Object Vvoid_text_area_pointer
;
345 /* Name of the face used to highlight trailing whitespace. */
347 Lisp_Object Qtrailing_whitespace
;
349 /* Name and number of the face used to highlight escape glyphs. */
351 Lisp_Object Qescape_glyph
;
353 /* The symbol `image' which is the car of the lists used to represent
358 /* The image map types. */
359 Lisp_Object QCmap
, QCpointer
;
360 Lisp_Object Qrect
, Qcircle
, Qpoly
;
362 /* Non-zero means print newline to stdout before next mini-buffer
365 int noninteractive_need_newline
;
367 /* Non-zero means print newline to message log before next message. */
369 static int message_log_need_newline
;
371 /* Three markers that message_dolog uses.
372 It could allocate them itself, but that causes trouble
373 in handling memory-full errors. */
374 static Lisp_Object message_dolog_marker1
;
375 static Lisp_Object message_dolog_marker2
;
376 static Lisp_Object message_dolog_marker3
;
378 /* The buffer position of the first character appearing entirely or
379 partially on the line of the selected window which contains the
380 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
381 redisplay optimization in redisplay_internal. */
383 static struct text_pos this_line_start_pos
;
385 /* Number of characters past the end of the line above, including the
386 terminating newline. */
388 static struct text_pos this_line_end_pos
;
390 /* The vertical positions and the height of this line. */
392 static int this_line_vpos
;
393 static int this_line_y
;
394 static int this_line_pixel_height
;
396 /* X position at which this display line starts. Usually zero;
397 negative if first character is partially visible. */
399 static int this_line_start_x
;
401 /* Buffer that this_line_.* variables are referring to. */
403 static struct buffer
*this_line_buffer
;
405 /* Nonzero means truncate lines in all windows less wide than the
408 int truncate_partial_width_windows
;
410 /* A flag to control how to display unibyte 8-bit character. */
412 int unibyte_display_via_language_environment
;
414 /* Nonzero means we have more than one non-mini-buffer-only frame.
415 Not guaranteed to be accurate except while parsing
416 frame-title-format. */
420 Lisp_Object Vglobal_mode_string
;
423 /* List of variables (symbols) which hold markers for overlay arrows.
424 The symbols on this list are examined during redisplay to determine
425 where to display overlay arrows. */
427 Lisp_Object Voverlay_arrow_variable_list
;
429 /* Marker for where to display an arrow on top of the buffer text. */
431 Lisp_Object Voverlay_arrow_position
;
433 /* String to display for the arrow. Only used on terminal frames. */
435 Lisp_Object Voverlay_arrow_string
;
437 /* Values of those variables at last redisplay are stored as
438 properties on `overlay-arrow-position' symbol. However, if
439 Voverlay_arrow_position is a marker, last-arrow-position is its
440 numerical position. */
442 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
444 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
445 properties on a symbol in overlay-arrow-variable-list. */
447 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
449 /* Like mode-line-format, but for the title bar on a visible frame. */
451 Lisp_Object Vframe_title_format
;
453 /* Like mode-line-format, but for the title bar on an iconified frame. */
455 Lisp_Object Vicon_title_format
;
457 /* List of functions to call when a window's size changes. These
458 functions get one arg, a frame on which one or more windows' sizes
461 static Lisp_Object Vwindow_size_change_functions
;
463 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
465 /* Nonzero if overlay arrow has been displayed once in this window. */
467 static int overlay_arrow_seen
;
469 /* Nonzero means highlight the region even in nonselected windows. */
471 int highlight_nonselected_windows
;
473 /* If cursor motion alone moves point off frame, try scrolling this
474 many lines up or down if that will bring it back. */
476 static EMACS_INT scroll_step
;
478 /* Nonzero means scroll just far enough to bring point back on the
479 screen, when appropriate. */
481 static EMACS_INT scroll_conservatively
;
483 /* Recenter the window whenever point gets within this many lines of
484 the top or bottom of the window. This value is translated into a
485 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
486 that there is really a fixed pixel height scroll margin. */
488 EMACS_INT scroll_margin
;
490 /* Number of windows showing the buffer of the selected window (or
491 another buffer with the same base buffer). keyboard.c refers to
496 /* Vector containing glyphs for an ellipsis `...'. */
498 static Lisp_Object default_invis_vector
[3];
500 /* Zero means display the mode-line/header-line/menu-bar in the default face
501 (this slightly odd definition is for compatibility with previous versions
502 of emacs), non-zero means display them using their respective faces.
504 This variable is deprecated. */
506 int mode_line_inverse_video
;
508 /* Prompt to display in front of the mini-buffer contents. */
510 Lisp_Object minibuf_prompt
;
512 /* Width of current mini-buffer prompt. Only set after display_line
513 of the line that contains the prompt. */
515 int minibuf_prompt_width
;
517 /* This is the window where the echo area message was displayed. It
518 is always a mini-buffer window, but it may not be the same window
519 currently active as a mini-buffer. */
521 Lisp_Object echo_area_window
;
523 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
524 pushes the current message and the value of
525 message_enable_multibyte on the stack, the function restore_message
526 pops the stack and displays MESSAGE again. */
528 Lisp_Object Vmessage_stack
;
530 /* Nonzero means multibyte characters were enabled when the echo area
531 message was specified. */
533 int message_enable_multibyte
;
535 /* Nonzero if we should redraw the mode lines on the next redisplay. */
537 int update_mode_lines
;
539 /* Nonzero if window sizes or contents have changed since last
540 redisplay that finished. */
542 int windows_or_buffers_changed
;
544 /* Nonzero means a frame's cursor type has been changed. */
546 int cursor_type_changed
;
548 /* Nonzero after display_mode_line if %l was used and it displayed a
551 int line_number_displayed
;
553 /* Maximum buffer size for which to display line numbers. */
555 Lisp_Object Vline_number_display_limit
;
557 /* Line width to consider when repositioning for line number display. */
559 static EMACS_INT line_number_display_limit_width
;
561 /* Number of lines to keep in the message log buffer. t means
562 infinite. nil means don't log at all. */
564 Lisp_Object Vmessage_log_max
;
566 /* The name of the *Messages* buffer, a string. */
568 static Lisp_Object Vmessages_buffer_name
;
570 /* Current, index 0, and last displayed echo area message. Either
571 buffers from echo_buffers, or nil to indicate no message. */
573 Lisp_Object echo_area_buffer
[2];
575 /* The buffers referenced from echo_area_buffer. */
577 static Lisp_Object echo_buffer
[2];
579 /* A vector saved used in with_area_buffer to reduce consing. */
581 static Lisp_Object Vwith_echo_area_save_vector
;
583 /* Non-zero means display_echo_area should display the last echo area
584 message again. Set by redisplay_preserve_echo_area. */
586 static int display_last_displayed_message_p
;
588 /* Nonzero if echo area is being used by print; zero if being used by
591 int message_buf_print
;
593 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
595 Lisp_Object Qinhibit_menubar_update
;
596 int inhibit_menubar_update
;
598 /* Maximum height for resizing mini-windows. Either a float
599 specifying a fraction of the available height, or an integer
600 specifying a number of lines. */
602 Lisp_Object Vmax_mini_window_height
;
604 /* Non-zero means messages should be displayed with truncated
605 lines instead of being continued. */
607 int message_truncate_lines
;
608 Lisp_Object Qmessage_truncate_lines
;
610 /* Set to 1 in clear_message to make redisplay_internal aware
611 of an emptied echo area. */
613 static int message_cleared_p
;
615 /* Non-zero means we want a hollow cursor in windows that are not
616 selected. Zero means there's no cursor in such windows. */
618 Lisp_Object Vcursor_in_non_selected_windows
;
619 Lisp_Object Qcursor_in_non_selected_windows
;
621 /* How to blink the default frame cursor off. */
622 Lisp_Object Vblink_cursor_alist
;
624 /* A scratch glyph row with contents used for generating truncation
625 glyphs. Also used in direct_output_for_insert. */
627 #define MAX_SCRATCH_GLYPHS 100
628 struct glyph_row scratch_glyph_row
;
629 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
631 /* Ascent and height of the last line processed by move_it_to. */
633 static int last_max_ascent
, last_height
;
635 /* Non-zero if there's a help-echo in the echo area. */
637 int help_echo_showing_p
;
639 /* If >= 0, computed, exact values of mode-line and header-line height
640 to use in the macros CURRENT_MODE_LINE_HEIGHT and
641 CURRENT_HEADER_LINE_HEIGHT. */
643 int current_mode_line_height
, current_header_line_height
;
645 /* The maximum distance to look ahead for text properties. Values
646 that are too small let us call compute_char_face and similar
647 functions too often which is expensive. Values that are too large
648 let us call compute_char_face and alike too often because we
649 might not be interested in text properties that far away. */
651 #define TEXT_PROP_DISTANCE_LIMIT 100
655 /* Variables to turn off display optimizations from Lisp. */
657 int inhibit_try_window_id
, inhibit_try_window_reusing
;
658 int inhibit_try_cursor_movement
;
660 /* Non-zero means print traces of redisplay if compiled with
663 int trace_redisplay_p
;
665 #endif /* GLYPH_DEBUG */
667 #ifdef DEBUG_TRACE_MOVE
668 /* Non-zero means trace with TRACE_MOVE to stderr. */
671 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
673 #define TRACE_MOVE(x) (void) 0
676 /* Non-zero means automatically scroll windows horizontally to make
679 int automatic_hscrolling_p
;
681 /* How close to the margin can point get before the window is scrolled
683 EMACS_INT hscroll_margin
;
685 /* How much to scroll horizontally when point is inside the above margin. */
686 Lisp_Object Vhscroll_step
;
688 /* The variable `resize-mini-windows'. If nil, don't resize
689 mini-windows. If t, always resize them to fit the text they
690 display. If `grow-only', let mini-windows grow only until they
693 Lisp_Object Vresize_mini_windows
;
695 /* Buffer being redisplayed -- for redisplay_window_error. */
697 struct buffer
*displayed_buffer
;
699 /* Value returned from text property handlers (see below). */
704 HANDLED_RECOMPUTE_PROPS
,
705 HANDLED_OVERLAY_STRING_CONSUMED
,
709 /* A description of text properties that redisplay is interested
714 /* The name of the property. */
717 /* A unique index for the property. */
720 /* A handler function called to set up iterator IT from the property
721 at IT's current position. Value is used to steer handle_stop. */
722 enum prop_handled (*handler
) P_ ((struct it
*it
));
725 static enum prop_handled handle_face_prop
P_ ((struct it
*));
726 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
727 static enum prop_handled handle_display_prop
P_ ((struct it
*));
728 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
729 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
730 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
732 /* Properties handled by iterators. */
734 static struct props it_props
[] =
736 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
737 /* Handle `face' before `display' because some sub-properties of
738 `display' need to know the face. */
739 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
740 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
741 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
742 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
746 /* Value is the position described by X. If X is a marker, value is
747 the marker_position of X. Otherwise, value is X. */
749 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
751 /* Enumeration returned by some move_it_.* functions internally. */
755 /* Not used. Undefined value. */
758 /* Move ended at the requested buffer position or ZV. */
759 MOVE_POS_MATCH_OR_ZV
,
761 /* Move ended at the requested X pixel position. */
764 /* Move within a line ended at the end of a line that must be
768 /* Move within a line ended at the end of a line that would
769 be displayed truncated. */
772 /* Move within a line ended at a line end. */
776 /* This counter is used to clear the face cache every once in a while
777 in redisplay_internal. It is incremented for each redisplay.
778 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
781 #define CLEAR_FACE_CACHE_COUNT 500
782 static int clear_face_cache_count
;
784 /* Record the previous terminal frame we displayed. */
786 static struct frame
*previous_terminal_frame
;
788 /* Non-zero while redisplay_internal is in progress. */
792 /* Non-zero means don't free realized faces. Bound while freeing
793 realized faces is dangerous because glyph matrices might still
796 int inhibit_free_realized_faces
;
797 Lisp_Object Qinhibit_free_realized_faces
;
799 /* If a string, XTread_socket generates an event to display that string.
800 (The display is done in read_char.) */
802 Lisp_Object help_echo_string
;
803 Lisp_Object help_echo_window
;
804 Lisp_Object help_echo_object
;
807 /* Temporary variable for XTread_socket. */
809 Lisp_Object previous_help_echo_string
;
811 /* Null glyph slice */
813 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
816 /* Function prototypes. */
818 static void setup_for_ellipsis
P_ ((struct it
*, int));
819 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
820 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
821 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
822 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
823 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
824 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
827 static int invisible_text_between_p
P_ ((struct it
*, int, int));
830 static int next_element_from_ellipsis
P_ ((struct it
*));
831 static void pint2str
P_ ((char *, int, int));
832 static void pint2hrstr
P_ ((char *, int, int));
833 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
835 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
836 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
837 static void store_frame_title_char
P_ ((char));
838 static int store_frame_title
P_ ((const unsigned char *, int, int));
839 static void x_consider_frame_title
P_ ((Lisp_Object
));
840 static void handle_stop
P_ ((struct it
*));
841 static int tool_bar_lines_needed
P_ ((struct frame
*));
842 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
843 static void ensure_echo_area_buffers
P_ ((void));
844 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
845 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
846 static int with_echo_area_buffer
P_ ((struct window
*, int,
847 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
848 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
849 static void clear_garbaged_frames
P_ ((void));
850 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
851 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
852 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
853 static int display_echo_area
P_ ((struct window
*));
854 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
855 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
856 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
857 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
858 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
860 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
861 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
862 static void insert_left_trunc_glyphs
P_ ((struct it
*));
863 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
865 static void extend_face_to_end_of_line
P_ ((struct it
*));
866 static int append_space_for_newline
P_ ((struct it
*, int));
867 static int make_cursor_line_fully_visible
P_ ((struct window
*, int));
868 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
869 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
870 static int trailing_whitespace_p
P_ ((int));
871 static int message_log_check_duplicate
P_ ((int, int, int, int));
872 static void push_it
P_ ((struct it
*));
873 static void pop_it
P_ ((struct it
*));
874 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
875 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
876 static void redisplay_internal
P_ ((int));
877 static int echo_area_display
P_ ((int));
878 static void redisplay_windows
P_ ((Lisp_Object
));
879 static void redisplay_window
P_ ((Lisp_Object
, int));
880 static Lisp_Object
redisplay_window_error ();
881 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
882 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
883 static void update_menu_bar
P_ ((struct frame
*, int));
884 static int try_window_reusing_current_matrix
P_ ((struct window
*));
885 static int try_window_id
P_ ((struct window
*));
886 static int display_line
P_ ((struct it
*));
887 static int display_mode_lines
P_ ((struct window
*));
888 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
889 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
890 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
891 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
892 static void display_menu_bar
P_ ((struct window
*));
893 static int display_count_lines
P_ ((int, int, int, int, int *));
894 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
895 int, int, struct it
*, int, int, int, int));
896 static void compute_line_metrics
P_ ((struct it
*));
897 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
898 static int get_overlay_strings
P_ ((struct it
*, int));
899 static void next_overlay_string
P_ ((struct it
*));
900 static void reseat
P_ ((struct it
*, struct text_pos
, int));
901 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
902 static void back_to_previous_visible_line_start
P_ ((struct it
*));
903 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
904 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
905 static int next_element_from_display_vector
P_ ((struct it
*));
906 static int next_element_from_string
P_ ((struct it
*));
907 static int next_element_from_c_string
P_ ((struct it
*));
908 static int next_element_from_buffer
P_ ((struct it
*));
909 static int next_element_from_composition
P_ ((struct it
*));
910 static int next_element_from_image
P_ ((struct it
*));
911 static int next_element_from_stretch
P_ ((struct it
*));
912 static void load_overlay_strings
P_ ((struct it
*, int));
913 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
914 struct display_pos
*));
915 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
916 Lisp_Object
, int, int, int, int));
917 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
919 void move_it_vertically_backward
P_ ((struct it
*, int));
920 static void init_to_row_start
P_ ((struct it
*, struct window
*,
921 struct glyph_row
*));
922 static int init_to_row_end
P_ ((struct it
*, struct window
*,
923 struct glyph_row
*));
924 static void back_to_previous_line_start
P_ ((struct it
*));
925 static int forward_to_next_line_start
P_ ((struct it
*, int *));
926 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
928 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
929 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
930 static int number_of_chars
P_ ((unsigned char *, int));
931 static void compute_stop_pos
P_ ((struct it
*));
932 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
934 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
935 static int next_overlay_change
P_ ((int));
936 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
937 Lisp_Object
, struct text_pos
*,
939 static int underlying_face_id
P_ ((struct it
*));
940 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
943 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
944 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
946 #ifdef HAVE_WINDOW_SYSTEM
948 static void update_tool_bar
P_ ((struct frame
*, int));
949 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
950 static int redisplay_tool_bar
P_ ((struct frame
*));
951 static void display_tool_bar_line
P_ ((struct it
*));
952 static void notice_overwritten_cursor
P_ ((struct window
*,
954 int, int, int, int));
958 #endif /* HAVE_WINDOW_SYSTEM */
961 /***********************************************************************
962 Window display dimensions
963 ***********************************************************************/
965 /* Return the bottom boundary y-position for text lines in window W.
966 This is the first y position at which a line cannot start.
967 It is relative to the top of the window.
969 This is the height of W minus the height of a mode line, if any. */
972 window_text_bottom_y (w
)
975 int height
= WINDOW_TOTAL_HEIGHT (w
);
977 if (WINDOW_WANTS_MODELINE_P (w
))
978 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
982 /* Return the pixel width of display area AREA of window W. AREA < 0
983 means return the total width of W, not including fringes to
984 the left and right of the window. */
987 window_box_width (w
, area
)
991 int cols
= XFASTINT (w
->total_cols
);
994 if (!w
->pseudo_window_p
)
996 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
998 if (area
== TEXT_AREA
)
1000 if (INTEGERP (w
->left_margin_cols
))
1001 cols
-= XFASTINT (w
->left_margin_cols
);
1002 if (INTEGERP (w
->right_margin_cols
))
1003 cols
-= XFASTINT (w
->right_margin_cols
);
1004 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1006 else if (area
== LEFT_MARGIN_AREA
)
1008 cols
= (INTEGERP (w
->left_margin_cols
)
1009 ? XFASTINT (w
->left_margin_cols
) : 0);
1012 else if (area
== RIGHT_MARGIN_AREA
)
1014 cols
= (INTEGERP (w
->right_margin_cols
)
1015 ? XFASTINT (w
->right_margin_cols
) : 0);
1020 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1024 /* Return the pixel height of the display area of window W, not
1025 including mode lines of W, if any. */
1028 window_box_height (w
)
1031 struct frame
*f
= XFRAME (w
->frame
);
1032 int height
= WINDOW_TOTAL_HEIGHT (w
);
1034 xassert (height
>= 0);
1036 /* Note: the code below that determines the mode-line/header-line
1037 height is essentially the same as that contained in the macro
1038 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1039 the appropriate glyph row has its `mode_line_p' flag set,
1040 and if it doesn't, uses estimate_mode_line_height instead. */
1042 if (WINDOW_WANTS_MODELINE_P (w
))
1044 struct glyph_row
*ml_row
1045 = (w
->current_matrix
&& w
->current_matrix
->rows
1046 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1048 if (ml_row
&& ml_row
->mode_line_p
)
1049 height
-= ml_row
->height
;
1051 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1054 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1056 struct glyph_row
*hl_row
1057 = (w
->current_matrix
&& w
->current_matrix
->rows
1058 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1060 if (hl_row
&& hl_row
->mode_line_p
)
1061 height
-= hl_row
->height
;
1063 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1066 /* With a very small font and a mode-line that's taller than
1067 default, we might end up with a negative height. */
1068 return max (0, height
);
1071 /* Return the window-relative coordinate of the left edge of display
1072 area AREA of window W. AREA < 0 means return the left edge of the
1073 whole window, to the right of the left fringe of W. */
1076 window_box_left_offset (w
, area
)
1082 if (w
->pseudo_window_p
)
1085 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1087 if (area
== TEXT_AREA
)
1088 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1089 + window_box_width (w
, LEFT_MARGIN_AREA
));
1090 else if (area
== RIGHT_MARGIN_AREA
)
1091 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1092 + window_box_width (w
, LEFT_MARGIN_AREA
)
1093 + window_box_width (w
, TEXT_AREA
)
1094 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1096 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1097 else if (area
== LEFT_MARGIN_AREA
1098 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1099 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1105 /* Return the window-relative coordinate of the right edge of display
1106 area AREA of window W. AREA < 0 means return the left edge of the
1107 whole window, to the left of the right fringe of W. */
1110 window_box_right_offset (w
, area
)
1114 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1117 /* Return the frame-relative coordinate of the left edge of display
1118 area AREA of window W. AREA < 0 means return the left edge of the
1119 whole window, to the right of the left fringe of W. */
1122 window_box_left (w
, area
)
1126 struct frame
*f
= XFRAME (w
->frame
);
1129 if (w
->pseudo_window_p
)
1130 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1132 x
= (WINDOW_LEFT_EDGE_X (w
)
1133 + window_box_left_offset (w
, area
));
1139 /* Return the frame-relative coordinate of the right edge of display
1140 area AREA of window W. AREA < 0 means return the left edge of the
1141 whole window, to the left of the right fringe of W. */
1144 window_box_right (w
, area
)
1148 return window_box_left (w
, area
) + window_box_width (w
, area
);
1151 /* Get the bounding box of the display area AREA of window W, without
1152 mode lines, in frame-relative coordinates. AREA < 0 means the
1153 whole window, not including the left and right fringes of
1154 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1155 coordinates of the upper-left corner of the box. Return in
1156 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1159 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1162 int *box_x
, *box_y
, *box_width
, *box_height
;
1165 *box_width
= window_box_width (w
, area
);
1167 *box_height
= window_box_height (w
);
1169 *box_x
= window_box_left (w
, area
);
1172 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1173 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1174 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1179 /* Get the bounding box of the display area AREA of window W, without
1180 mode lines. AREA < 0 means the whole window, not including the
1181 left and right fringe of the window. Return in *TOP_LEFT_X
1182 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1183 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1184 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1188 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1189 bottom_right_x
, bottom_right_y
)
1192 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1194 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1196 *bottom_right_x
+= *top_left_x
;
1197 *bottom_right_y
+= *top_left_y
;
1202 /***********************************************************************
1204 ***********************************************************************/
1206 /* Return the bottom y-position of the line the iterator IT is in.
1207 This can modify IT's settings. */
1213 int line_height
= it
->max_ascent
+ it
->max_descent
;
1214 int line_top_y
= it
->current_y
;
1216 if (line_height
== 0)
1219 line_height
= last_height
;
1220 else if (IT_CHARPOS (*it
) < ZV
)
1222 move_it_by_lines (it
, 1, 1);
1223 line_height
= (it
->max_ascent
|| it
->max_descent
1224 ? it
->max_ascent
+ it
->max_descent
1229 struct glyph_row
*row
= it
->glyph_row
;
1231 /* Use the default character height. */
1232 it
->glyph_row
= NULL
;
1233 it
->what
= IT_CHARACTER
;
1236 PRODUCE_GLYPHS (it
);
1237 line_height
= it
->ascent
+ it
->descent
;
1238 it
->glyph_row
= row
;
1242 return line_top_y
+ line_height
;
1246 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1247 1 if POS is visible and the line containing POS is fully visible.
1248 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1249 and header-lines heights. */
1252 pos_visible_p (w
, charpos
, fully
, x
, y
, exact_mode_line_heights_p
)
1254 int charpos
, *fully
, *x
, *y
, exact_mode_line_heights_p
;
1257 struct text_pos top
;
1259 struct buffer
*old_buffer
= NULL
;
1261 if (XBUFFER (w
->buffer
) != current_buffer
)
1263 old_buffer
= current_buffer
;
1264 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1267 *fully
= visible_p
= 0;
1268 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1270 /* Compute exact mode line heights, if requested. */
1271 if (exact_mode_line_heights_p
)
1273 if (WINDOW_WANTS_MODELINE_P (w
))
1274 current_mode_line_height
1275 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1276 current_buffer
->mode_line_format
);
1278 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1279 current_header_line_height
1280 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1281 current_buffer
->header_line_format
);
1284 start_display (&it
, w
, top
);
1285 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1286 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1288 /* Note that we may overshoot because of invisible text. */
1289 if (IT_CHARPOS (it
) >= charpos
)
1291 int top_y
= it
.current_y
;
1292 int bottom_y
= line_bottom_y (&it
);
1293 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1295 if (top_y
< window_top_y
)
1296 visible_p
= bottom_y
> window_top_y
;
1297 else if (top_y
< it
.last_visible_y
)
1300 *fully
= bottom_y
<= it
.last_visible_y
;
1305 *y
= max (top_y
+ it
.max_ascent
- it
.ascent
, window_top_y
);
1308 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1313 move_it_by_lines (&it
, 1, 0);
1314 if (charpos
< IT_CHARPOS (it
))
1319 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1321 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1327 set_buffer_internal_1 (old_buffer
);
1329 current_header_line_height
= current_mode_line_height
= -1;
1335 /* Return the next character from STR which is MAXLEN bytes long.
1336 Return in *LEN the length of the character. This is like
1337 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1338 we find one, we return a `?', but with the length of the invalid
1342 string_char_and_length (str
, maxlen
, len
)
1343 const unsigned char *str
;
1348 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1349 if (!CHAR_VALID_P (c
, 1))
1350 /* We may not change the length here because other places in Emacs
1351 don't use this function, i.e. they silently accept invalid
1360 /* Given a position POS containing a valid character and byte position
1361 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1363 static struct text_pos
1364 string_pos_nchars_ahead (pos
, string
, nchars
)
1365 struct text_pos pos
;
1369 xassert (STRINGP (string
) && nchars
>= 0);
1371 if (STRING_MULTIBYTE (string
))
1373 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1374 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1379 string_char_and_length (p
, rest
, &len
);
1380 p
+= len
, rest
-= len
;
1381 xassert (rest
>= 0);
1383 BYTEPOS (pos
) += len
;
1387 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1393 /* Value is the text position, i.e. character and byte position,
1394 for character position CHARPOS in STRING. */
1396 static INLINE
struct text_pos
1397 string_pos (charpos
, string
)
1401 struct text_pos pos
;
1402 xassert (STRINGP (string
));
1403 xassert (charpos
>= 0);
1404 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1409 /* Value is a text position, i.e. character and byte position, for
1410 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1411 means recognize multibyte characters. */
1413 static struct text_pos
1414 c_string_pos (charpos
, s
, multibyte_p
)
1419 struct text_pos pos
;
1421 xassert (s
!= NULL
);
1422 xassert (charpos
>= 0);
1426 int rest
= strlen (s
), len
;
1428 SET_TEXT_POS (pos
, 0, 0);
1431 string_char_and_length (s
, rest
, &len
);
1432 s
+= len
, rest
-= len
;
1433 xassert (rest
>= 0);
1435 BYTEPOS (pos
) += len
;
1439 SET_TEXT_POS (pos
, charpos
, charpos
);
1445 /* Value is the number of characters in C string S. MULTIBYTE_P
1446 non-zero means recognize multibyte characters. */
1449 number_of_chars (s
, multibyte_p
)
1457 int rest
= strlen (s
), len
;
1458 unsigned char *p
= (unsigned char *) s
;
1460 for (nchars
= 0; rest
> 0; ++nchars
)
1462 string_char_and_length (p
, rest
, &len
);
1463 rest
-= len
, p
+= len
;
1467 nchars
= strlen (s
);
1473 /* Compute byte position NEWPOS->bytepos corresponding to
1474 NEWPOS->charpos. POS is a known position in string STRING.
1475 NEWPOS->charpos must be >= POS.charpos. */
1478 compute_string_pos (newpos
, pos
, string
)
1479 struct text_pos
*newpos
, pos
;
1482 xassert (STRINGP (string
));
1483 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1485 if (STRING_MULTIBYTE (string
))
1486 *newpos
= string_pos_nchars_ahead (pos
, string
,
1487 CHARPOS (*newpos
) - CHARPOS (pos
));
1489 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1493 Return an estimation of the pixel height of mode or top lines on
1494 frame F. FACE_ID specifies what line's height to estimate. */
1497 estimate_mode_line_height (f
, face_id
)
1499 enum face_id face_id
;
1501 #ifdef HAVE_WINDOW_SYSTEM
1502 if (FRAME_WINDOW_P (f
))
1504 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1506 /* This function is called so early when Emacs starts that the face
1507 cache and mode line face are not yet initialized. */
1508 if (FRAME_FACE_CACHE (f
))
1510 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1514 height
= FONT_HEIGHT (face
->font
);
1515 if (face
->box_line_width
> 0)
1516 height
+= 2 * face
->box_line_width
;
1527 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1528 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1529 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1530 not force the value into range. */
1533 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1535 register int pix_x
, pix_y
;
1537 NativeRectangle
*bounds
;
1541 #ifdef HAVE_WINDOW_SYSTEM
1542 if (FRAME_WINDOW_P (f
))
1544 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1545 even for negative values. */
1547 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1549 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1551 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1552 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1555 STORE_NATIVE_RECT (*bounds
,
1556 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1557 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1558 FRAME_COLUMN_WIDTH (f
) - 1,
1559 FRAME_LINE_HEIGHT (f
) - 1);
1565 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1566 pix_x
= FRAME_TOTAL_COLS (f
);
1570 else if (pix_y
> FRAME_LINES (f
))
1571 pix_y
= FRAME_LINES (f
);
1581 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1582 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1583 can't tell the positions because W's display is not up to date,
1587 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1590 int *frame_x
, *frame_y
;
1592 #ifdef HAVE_WINDOW_SYSTEM
1593 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1597 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1598 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1600 if (display_completed
)
1602 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1603 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1604 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1610 hpos
+= glyph
->pixel_width
;
1614 /* If first glyph is partially visible, its first visible position is still 0. */
1626 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1627 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1638 #ifdef HAVE_WINDOW_SYSTEM
1640 /* Find the glyph under window-relative coordinates X/Y in window W.
1641 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1642 strings. Return in *HPOS and *VPOS the row and column number of
1643 the glyph found. Return in *AREA the glyph area containing X.
1644 Value is a pointer to the glyph found or null if X/Y is not on
1645 text, or we can't tell because W's current matrix is not up to
1648 static struct glyph
*
1649 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1652 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1654 struct glyph
*glyph
, *end
;
1655 struct glyph_row
*row
= NULL
;
1658 /* Find row containing Y. Give up if some row is not enabled. */
1659 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1661 row
= MATRIX_ROW (w
->current_matrix
, i
);
1662 if (!row
->enabled_p
)
1664 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1671 /* Give up if Y is not in the window. */
1672 if (i
== w
->current_matrix
->nrows
)
1675 /* Get the glyph area containing X. */
1676 if (w
->pseudo_window_p
)
1683 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1685 *area
= LEFT_MARGIN_AREA
;
1686 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1688 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1691 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1695 *area
= RIGHT_MARGIN_AREA
;
1696 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1700 /* Find glyph containing X. */
1701 glyph
= row
->glyphs
[*area
];
1702 end
= glyph
+ row
->used
[*area
];
1704 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1706 x
-= glyph
->pixel_width
;
1716 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1719 *hpos
= glyph
- row
->glyphs
[*area
];
1725 Convert frame-relative x/y to coordinates relative to window W.
1726 Takes pseudo-windows into account. */
1729 frame_to_window_pixel_xy (w
, x
, y
)
1733 if (w
->pseudo_window_p
)
1735 /* A pseudo-window is always full-width, and starts at the
1736 left edge of the frame, plus a frame border. */
1737 struct frame
*f
= XFRAME (w
->frame
);
1738 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1739 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1743 *x
-= WINDOW_LEFT_EDGE_X (w
);
1744 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1749 Return in *R the clipping rectangle for glyph string S. */
1752 get_glyph_string_clip_rect (s
, nr
)
1753 struct glyph_string
*s
;
1754 NativeRectangle
*nr
;
1758 if (s
->row
->full_width_p
)
1760 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1761 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1762 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1764 /* Unless displaying a mode or menu bar line, which are always
1765 fully visible, clip to the visible part of the row. */
1766 if (s
->w
->pseudo_window_p
)
1767 r
.height
= s
->row
->visible_height
;
1769 r
.height
= s
->height
;
1773 /* This is a text line that may be partially visible. */
1774 r
.x
= window_box_left (s
->w
, s
->area
);
1775 r
.width
= window_box_width (s
->w
, s
->area
);
1776 r
.height
= s
->row
->visible_height
;
1779 /* If S draws overlapping rows, it's sufficient to use the top and
1780 bottom of the window for clipping because this glyph string
1781 intentionally draws over other lines. */
1782 if (s
->for_overlaps_p
)
1784 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1785 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1789 /* Don't use S->y for clipping because it doesn't take partially
1790 visible lines into account. For example, it can be negative for
1791 partially visible lines at the top of a window. */
1792 if (!s
->row
->full_width_p
1793 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1794 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1796 r
.y
= max (0, s
->row
->y
);
1798 /* If drawing a tool-bar window, draw it over the internal border
1799 at the top of the window. */
1800 if (WINDOWP (s
->f
->tool_bar_window
)
1801 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1802 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1805 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1807 /* If drawing the cursor, don't let glyph draw outside its
1808 advertised boundaries. Cleartype does this under some circumstances. */
1809 if (s
->hl
== DRAW_CURSOR
)
1811 struct glyph
*glyph
= s
->first_glyph
;
1816 r
.width
-= s
->x
- r
.x
;
1819 r
.width
= min (r
.width
, glyph
->pixel_width
);
1821 /* Don't draw cursor glyph taller than our actual glyph. */
1822 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1823 if (height
< r
.height
)
1825 int max_y
= r
.y
+ r
.height
;
1826 r
.y
= min (max_y
, s
->ybase
+ glyph
->descent
- height
);
1827 r
.height
= min (max_y
- r
.y
, height
);
1831 #ifdef CONVERT_FROM_XRECT
1832 CONVERT_FROM_XRECT (r
, *nr
);
1838 #endif /* HAVE_WINDOW_SYSTEM */
1841 /***********************************************************************
1842 Lisp form evaluation
1843 ***********************************************************************/
1845 /* Error handler for safe_eval and safe_call. */
1848 safe_eval_handler (arg
)
1851 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1856 /* Evaluate SEXPR and return the result, or nil if something went
1857 wrong. Prevent redisplay during the evaluation. */
1865 if (inhibit_eval_during_redisplay
)
1869 int count
= SPECPDL_INDEX ();
1870 struct gcpro gcpro1
;
1873 specbind (Qinhibit_redisplay
, Qt
);
1874 /* Use Qt to ensure debugger does not run,
1875 so there is no possibility of wanting to redisplay. */
1876 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1879 val
= unbind_to (count
, val
);
1886 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1887 Return the result, or nil if something went wrong. Prevent
1888 redisplay during the evaluation. */
1891 safe_call (nargs
, args
)
1897 if (inhibit_eval_during_redisplay
)
1901 int count
= SPECPDL_INDEX ();
1902 struct gcpro gcpro1
;
1905 gcpro1
.nvars
= nargs
;
1906 specbind (Qinhibit_redisplay
, Qt
);
1907 /* Use Qt to ensure debugger does not run,
1908 so there is no possibility of wanting to redisplay. */
1909 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1912 val
= unbind_to (count
, val
);
1919 /* Call function FN with one argument ARG.
1920 Return the result, or nil if something went wrong. */
1923 safe_call1 (fn
, arg
)
1924 Lisp_Object fn
, arg
;
1926 Lisp_Object args
[2];
1929 return safe_call (2, args
);
1934 /***********************************************************************
1936 ***********************************************************************/
1940 /* Define CHECK_IT to perform sanity checks on iterators.
1941 This is for debugging. It is too slow to do unconditionally. */
1947 if (it
->method
== next_element_from_string
)
1949 xassert (STRINGP (it
->string
));
1950 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1954 xassert (IT_STRING_CHARPOS (*it
) < 0);
1955 if (it
->method
== next_element_from_buffer
)
1957 /* Check that character and byte positions agree. */
1958 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1963 xassert (it
->current
.dpvec_index
>= 0);
1965 xassert (it
->current
.dpvec_index
< 0);
1968 #define CHECK_IT(IT) check_it ((IT))
1972 #define CHECK_IT(IT) (void) 0
1979 /* Check that the window end of window W is what we expect it
1980 to be---the last row in the current matrix displaying text. */
1983 check_window_end (w
)
1986 if (!MINI_WINDOW_P (w
)
1987 && !NILP (w
->window_end_valid
))
1989 struct glyph_row
*row
;
1990 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1991 XFASTINT (w
->window_end_vpos
)),
1993 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1994 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1998 #define CHECK_WINDOW_END(W) check_window_end ((W))
2000 #else /* not GLYPH_DEBUG */
2002 #define CHECK_WINDOW_END(W) (void) 0
2004 #endif /* not GLYPH_DEBUG */
2008 /***********************************************************************
2009 Iterator initialization
2010 ***********************************************************************/
2012 /* Initialize IT for displaying current_buffer in window W, starting
2013 at character position CHARPOS. CHARPOS < 0 means that no buffer
2014 position is specified which is useful when the iterator is assigned
2015 a position later. BYTEPOS is the byte position corresponding to
2016 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2018 If ROW is not null, calls to produce_glyphs with IT as parameter
2019 will produce glyphs in that row.
2021 BASE_FACE_ID is the id of a base face to use. It must be one of
2022 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2023 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2024 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2026 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2027 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2028 will be initialized to use the corresponding mode line glyph row of
2029 the desired matrix of W. */
2032 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2035 int charpos
, bytepos
;
2036 struct glyph_row
*row
;
2037 enum face_id base_face_id
;
2039 int highlight_region_p
;
2041 /* Some precondition checks. */
2042 xassert (w
!= NULL
&& it
!= NULL
);
2043 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2046 /* If face attributes have been changed since the last redisplay,
2047 free realized faces now because they depend on face definitions
2048 that might have changed. Don't free faces while there might be
2049 desired matrices pending which reference these faces. */
2050 if (face_change_count
&& !inhibit_free_realized_faces
)
2052 face_change_count
= 0;
2053 free_all_realized_faces (Qnil
);
2056 /* Use one of the mode line rows of W's desired matrix if
2060 if (base_face_id
== MODE_LINE_FACE_ID
2061 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2062 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2063 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2064 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2068 bzero (it
, sizeof *it
);
2069 it
->current
.overlay_string_index
= -1;
2070 it
->current
.dpvec_index
= -1;
2071 it
->base_face_id
= base_face_id
;
2073 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2075 /* The window in which we iterate over current_buffer: */
2076 XSETWINDOW (it
->window
, w
);
2078 it
->f
= XFRAME (w
->frame
);
2080 /* Extra space between lines (on window systems only). */
2081 if (base_face_id
== DEFAULT_FACE_ID
2082 && FRAME_WINDOW_P (it
->f
))
2084 if (NATNUMP (current_buffer
->extra_line_spacing
))
2085 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2086 else if (FLOATP (current_buffer
->extra_line_spacing
))
2087 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2088 * FRAME_LINE_HEIGHT (it
->f
));
2089 else if (it
->f
->extra_line_spacing
> 0)
2090 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2091 it
->max_extra_line_spacing
= 0;
2094 /* If realized faces have been removed, e.g. because of face
2095 attribute changes of named faces, recompute them. When running
2096 in batch mode, the face cache of Vterminal_frame is null. If
2097 we happen to get called, make a dummy face cache. */
2098 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2099 init_frame_faces (it
->f
);
2100 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2101 recompute_basic_faces (it
->f
);
2103 /* Current value of the `slice', `space-width', and 'height' properties. */
2104 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2105 it
->space_width
= Qnil
;
2106 it
->font_height
= Qnil
;
2107 it
->override_ascent
= -1;
2109 /* Are control characters displayed as `^C'? */
2110 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2112 /* -1 means everything between a CR and the following line end
2113 is invisible. >0 means lines indented more than this value are
2115 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2116 ? XFASTINT (current_buffer
->selective_display
)
2117 : (!NILP (current_buffer
->selective_display
)
2119 it
->selective_display_ellipsis_p
2120 = !NILP (current_buffer
->selective_display_ellipses
);
2122 /* Display table to use. */
2123 it
->dp
= window_display_table (w
);
2125 /* Are multibyte characters enabled in current_buffer? */
2126 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2128 /* Non-zero if we should highlight the region. */
2130 = (!NILP (Vtransient_mark_mode
)
2131 && !NILP (current_buffer
->mark_active
)
2132 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2134 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2135 start and end of a visible region in window IT->w. Set both to
2136 -1 to indicate no region. */
2137 if (highlight_region_p
2138 /* Maybe highlight only in selected window. */
2139 && (/* Either show region everywhere. */
2140 highlight_nonselected_windows
2141 /* Or show region in the selected window. */
2142 || w
== XWINDOW (selected_window
)
2143 /* Or show the region if we are in the mini-buffer and W is
2144 the window the mini-buffer refers to. */
2145 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2146 && WINDOWP (minibuf_selected_window
)
2147 && w
== XWINDOW (minibuf_selected_window
))))
2149 int charpos
= marker_position (current_buffer
->mark
);
2150 it
->region_beg_charpos
= min (PT
, charpos
);
2151 it
->region_end_charpos
= max (PT
, charpos
);
2154 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2156 /* Get the position at which the redisplay_end_trigger hook should
2157 be run, if it is to be run at all. */
2158 if (MARKERP (w
->redisplay_end_trigger
)
2159 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2160 it
->redisplay_end_trigger_charpos
2161 = marker_position (w
->redisplay_end_trigger
);
2162 else if (INTEGERP (w
->redisplay_end_trigger
))
2163 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2165 /* Correct bogus values of tab_width. */
2166 it
->tab_width
= XINT (current_buffer
->tab_width
);
2167 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2170 /* Are lines in the display truncated? */
2171 it
->truncate_lines_p
2172 = (base_face_id
!= DEFAULT_FACE_ID
2173 || XINT (it
->w
->hscroll
)
2174 || (truncate_partial_width_windows
2175 && !WINDOW_FULL_WIDTH_P (it
->w
))
2176 || !NILP (current_buffer
->truncate_lines
));
2178 /* Get dimensions of truncation and continuation glyphs. These are
2179 displayed as fringe bitmaps under X, so we don't need them for such
2181 if (!FRAME_WINDOW_P (it
->f
))
2183 if (it
->truncate_lines_p
)
2185 /* We will need the truncation glyph. */
2186 xassert (it
->glyph_row
== NULL
);
2187 produce_special_glyphs (it
, IT_TRUNCATION
);
2188 it
->truncation_pixel_width
= it
->pixel_width
;
2192 /* We will need the continuation glyph. */
2193 xassert (it
->glyph_row
== NULL
);
2194 produce_special_glyphs (it
, IT_CONTINUATION
);
2195 it
->continuation_pixel_width
= it
->pixel_width
;
2198 /* Reset these values to zero because the produce_special_glyphs
2199 above has changed them. */
2200 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2201 it
->phys_ascent
= it
->phys_descent
= 0;
2204 /* Set this after getting the dimensions of truncation and
2205 continuation glyphs, so that we don't produce glyphs when calling
2206 produce_special_glyphs, above. */
2207 it
->glyph_row
= row
;
2208 it
->area
= TEXT_AREA
;
2210 /* Get the dimensions of the display area. The display area
2211 consists of the visible window area plus a horizontally scrolled
2212 part to the left of the window. All x-values are relative to the
2213 start of this total display area. */
2214 if (base_face_id
!= DEFAULT_FACE_ID
)
2216 /* Mode lines, menu bar in terminal frames. */
2217 it
->first_visible_x
= 0;
2218 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2223 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2224 it
->last_visible_x
= (it
->first_visible_x
2225 + window_box_width (w
, TEXT_AREA
));
2227 /* If we truncate lines, leave room for the truncator glyph(s) at
2228 the right margin. Otherwise, leave room for the continuation
2229 glyph(s). Truncation and continuation glyphs are not inserted
2230 for window-based redisplay. */
2231 if (!FRAME_WINDOW_P (it
->f
))
2233 if (it
->truncate_lines_p
)
2234 it
->last_visible_x
-= it
->truncation_pixel_width
;
2236 it
->last_visible_x
-= it
->continuation_pixel_width
;
2239 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2240 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2243 /* Leave room for a border glyph. */
2244 if (!FRAME_WINDOW_P (it
->f
)
2245 && !WINDOW_RIGHTMOST_P (it
->w
))
2246 it
->last_visible_x
-= 1;
2248 it
->last_visible_y
= window_text_bottom_y (w
);
2250 /* For mode lines and alike, arrange for the first glyph having a
2251 left box line if the face specifies a box. */
2252 if (base_face_id
!= DEFAULT_FACE_ID
)
2256 it
->face_id
= base_face_id
;
2258 /* If we have a boxed mode line, make the first character appear
2259 with a left box line. */
2260 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2261 if (face
->box
!= FACE_NO_BOX
)
2262 it
->start_of_box_run_p
= 1;
2265 /* If a buffer position was specified, set the iterator there,
2266 getting overlays and face properties from that position. */
2267 if (charpos
>= BUF_BEG (current_buffer
))
2269 it
->end_charpos
= ZV
;
2271 IT_CHARPOS (*it
) = charpos
;
2273 /* Compute byte position if not specified. */
2274 if (bytepos
< charpos
)
2275 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2277 IT_BYTEPOS (*it
) = bytepos
;
2279 it
->start
= it
->current
;
2281 /* Compute faces etc. */
2282 reseat (it
, it
->current
.pos
, 1);
2289 /* Initialize IT for the display of window W with window start POS. */
2292 start_display (it
, w
, pos
)
2295 struct text_pos pos
;
2297 struct glyph_row
*row
;
2298 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2300 row
= w
->desired_matrix
->rows
+ first_vpos
;
2301 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2302 it
->first_vpos
= first_vpos
;
2304 if (!it
->truncate_lines_p
)
2306 int start_at_line_beg_p
;
2307 int first_y
= it
->current_y
;
2309 /* If window start is not at a line start, skip forward to POS to
2310 get the correct continuation lines width. */
2311 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2312 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2313 if (!start_at_line_beg_p
)
2317 reseat_at_previous_visible_line_start (it
);
2318 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2320 new_x
= it
->current_x
+ it
->pixel_width
;
2322 /* If lines are continued, this line may end in the middle
2323 of a multi-glyph character (e.g. a control character
2324 displayed as \003, or in the middle of an overlay
2325 string). In this case move_it_to above will not have
2326 taken us to the start of the continuation line but to the
2327 end of the continued line. */
2328 if (it
->current_x
> 0
2329 && !it
->truncate_lines_p
/* Lines are continued. */
2330 && (/* And glyph doesn't fit on the line. */
2331 new_x
> it
->last_visible_x
2332 /* Or it fits exactly and we're on a window
2334 || (new_x
== it
->last_visible_x
2335 && FRAME_WINDOW_P (it
->f
))))
2337 if (it
->current
.dpvec_index
>= 0
2338 || it
->current
.overlay_string_index
>= 0)
2340 set_iterator_to_next (it
, 1);
2341 move_it_in_display_line_to (it
, -1, -1, 0);
2344 it
->continuation_lines_width
+= it
->current_x
;
2347 /* We're starting a new display line, not affected by the
2348 height of the continued line, so clear the appropriate
2349 fields in the iterator structure. */
2350 it
->max_ascent
= it
->max_descent
= 0;
2351 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2353 it
->current_y
= first_y
;
2355 it
->current_x
= it
->hpos
= 0;
2359 #if 0 /* Don't assert the following because start_display is sometimes
2360 called intentionally with a window start that is not at a
2361 line start. Please leave this code in as a comment. */
2363 /* Window start should be on a line start, now. */
2364 xassert (it
->continuation_lines_width
2365 || IT_CHARPOS (it
) == BEGV
2366 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2371 /* Return 1 if POS is a position in ellipses displayed for invisible
2372 text. W is the window we display, for text property lookup. */
2375 in_ellipses_for_invisible_text_p (pos
, w
)
2376 struct display_pos
*pos
;
2379 Lisp_Object prop
, window
;
2381 int charpos
= CHARPOS (pos
->pos
);
2383 /* If POS specifies a position in a display vector, this might
2384 be for an ellipsis displayed for invisible text. We won't
2385 get the iterator set up for delivering that ellipsis unless
2386 we make sure that it gets aware of the invisible text. */
2387 if (pos
->dpvec_index
>= 0
2388 && pos
->overlay_string_index
< 0
2389 && CHARPOS (pos
->string_pos
) < 0
2391 && (XSETWINDOW (window
, w
),
2392 prop
= Fget_char_property (make_number (charpos
),
2393 Qinvisible
, window
),
2394 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2396 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2398 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2405 /* Initialize IT for stepping through current_buffer in window W,
2406 starting at position POS that includes overlay string and display
2407 vector/ control character translation position information. Value
2408 is zero if there are overlay strings with newlines at POS. */
2411 init_from_display_pos (it
, w
, pos
)
2414 struct display_pos
*pos
;
2416 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2417 int i
, overlay_strings_with_newlines
= 0;
2419 /* If POS specifies a position in a display vector, this might
2420 be for an ellipsis displayed for invisible text. We won't
2421 get the iterator set up for delivering that ellipsis unless
2422 we make sure that it gets aware of the invisible text. */
2423 if (in_ellipses_for_invisible_text_p (pos
, w
))
2429 /* Keep in mind: the call to reseat in init_iterator skips invisible
2430 text, so we might end up at a position different from POS. This
2431 is only a problem when POS is a row start after a newline and an
2432 overlay starts there with an after-string, and the overlay has an
2433 invisible property. Since we don't skip invisible text in
2434 display_line and elsewhere immediately after consuming the
2435 newline before the row start, such a POS will not be in a string,
2436 but the call to init_iterator below will move us to the
2438 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2440 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2442 const char *s
= SDATA (it
->overlay_strings
[i
]);
2443 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2445 while (s
< e
&& *s
!= '\n')
2450 overlay_strings_with_newlines
= 1;
2455 /* If position is within an overlay string, set up IT to the right
2457 if (pos
->overlay_string_index
>= 0)
2461 /* If the first overlay string happens to have a `display'
2462 property for an image, the iterator will be set up for that
2463 image, and we have to undo that setup first before we can
2464 correct the overlay string index. */
2465 if (it
->method
== next_element_from_image
)
2468 /* We already have the first chunk of overlay strings in
2469 IT->overlay_strings. Load more until the one for
2470 pos->overlay_string_index is in IT->overlay_strings. */
2471 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2473 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2474 it
->current
.overlay_string_index
= 0;
2477 load_overlay_strings (it
, 0);
2478 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2482 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2483 relative_index
= (it
->current
.overlay_string_index
2484 % OVERLAY_STRING_CHUNK_SIZE
);
2485 it
->string
= it
->overlay_strings
[relative_index
];
2486 xassert (STRINGP (it
->string
));
2487 it
->current
.string_pos
= pos
->string_pos
;
2488 it
->method
= next_element_from_string
;
2491 #if 0 /* This is bogus because POS not having an overlay string
2492 position does not mean it's after the string. Example: A
2493 line starting with a before-string and initialization of IT
2494 to the previous row's end position. */
2495 else if (it
->current
.overlay_string_index
>= 0)
2497 /* If POS says we're already after an overlay string ending at
2498 POS, make sure to pop the iterator because it will be in
2499 front of that overlay string. When POS is ZV, we've thereby
2500 also ``processed'' overlay strings at ZV. */
2503 it
->current
.overlay_string_index
= -1;
2504 it
->method
= next_element_from_buffer
;
2505 if (CHARPOS (pos
->pos
) == ZV
)
2506 it
->overlay_strings_at_end_processed_p
= 1;
2510 if (CHARPOS (pos
->string_pos
) >= 0)
2512 /* Recorded position is not in an overlay string, but in another
2513 string. This can only be a string from a `display' property.
2514 IT should already be filled with that string. */
2515 it
->current
.string_pos
= pos
->string_pos
;
2516 xassert (STRINGP (it
->string
));
2519 /* Restore position in display vector translations, control
2520 character translations or ellipses. */
2521 if (pos
->dpvec_index
>= 0)
2523 if (it
->dpvec
== NULL
)
2524 get_next_display_element (it
);
2525 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2526 it
->current
.dpvec_index
= pos
->dpvec_index
;
2530 return !overlay_strings_with_newlines
;
2534 /* Initialize IT for stepping through current_buffer in window W
2535 starting at ROW->start. */
2538 init_to_row_start (it
, w
, row
)
2541 struct glyph_row
*row
;
2543 init_from_display_pos (it
, w
, &row
->start
);
2544 it
->start
= row
->start
;
2545 it
->continuation_lines_width
= row
->continuation_lines_width
;
2550 /* Initialize IT for stepping through current_buffer in window W
2551 starting in the line following ROW, i.e. starting at ROW->end.
2552 Value is zero if there are overlay strings with newlines at ROW's
2556 init_to_row_end (it
, w
, row
)
2559 struct glyph_row
*row
;
2563 if (init_from_display_pos (it
, w
, &row
->end
))
2565 if (row
->continued_p
)
2566 it
->continuation_lines_width
2567 = row
->continuation_lines_width
+ row
->pixel_width
;
2578 /***********************************************************************
2580 ***********************************************************************/
2582 /* Called when IT reaches IT->stop_charpos. Handle text property and
2583 overlay changes. Set IT->stop_charpos to the next position where
2590 enum prop_handled handled
;
2591 int handle_overlay_change_p
= 1;
2595 it
->current
.dpvec_index
= -1;
2599 handled
= HANDLED_NORMALLY
;
2601 /* Call text property handlers. */
2602 for (p
= it_props
; p
->handler
; ++p
)
2604 handled
= p
->handler (it
);
2606 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2608 else if (handled
== HANDLED_RETURN
)
2610 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2611 handle_overlay_change_p
= 0;
2614 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2616 /* Don't check for overlay strings below when set to deliver
2617 characters from a display vector. */
2618 if (it
->method
== next_element_from_display_vector
)
2619 handle_overlay_change_p
= 0;
2621 /* Handle overlay changes. */
2622 if (handle_overlay_change_p
)
2623 handled
= handle_overlay_change (it
);
2625 /* Determine where to stop next. */
2626 if (handled
== HANDLED_NORMALLY
)
2627 compute_stop_pos (it
);
2630 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2634 /* Compute IT->stop_charpos from text property and overlay change
2635 information for IT's current position. */
2638 compute_stop_pos (it
)
2641 register INTERVAL iv
, next_iv
;
2642 Lisp_Object object
, limit
, position
;
2644 /* If nowhere else, stop at the end. */
2645 it
->stop_charpos
= it
->end_charpos
;
2647 if (STRINGP (it
->string
))
2649 /* Strings are usually short, so don't limit the search for
2651 object
= it
->string
;
2653 position
= make_number (IT_STRING_CHARPOS (*it
));
2659 /* If next overlay change is in front of the current stop pos
2660 (which is IT->end_charpos), stop there. Note: value of
2661 next_overlay_change is point-max if no overlay change
2663 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2664 if (charpos
< it
->stop_charpos
)
2665 it
->stop_charpos
= charpos
;
2667 /* If showing the region, we have to stop at the region
2668 start or end because the face might change there. */
2669 if (it
->region_beg_charpos
> 0)
2671 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2672 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2673 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2674 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2677 /* Set up variables for computing the stop position from text
2678 property changes. */
2679 XSETBUFFER (object
, current_buffer
);
2680 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2681 position
= make_number (IT_CHARPOS (*it
));
2685 /* Get the interval containing IT's position. Value is a null
2686 interval if there isn't such an interval. */
2687 iv
= validate_interval_range (object
, &position
, &position
, 0);
2688 if (!NULL_INTERVAL_P (iv
))
2690 Lisp_Object values_here
[LAST_PROP_IDX
];
2693 /* Get properties here. */
2694 for (p
= it_props
; p
->handler
; ++p
)
2695 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2697 /* Look for an interval following iv that has different
2699 for (next_iv
= next_interval (iv
);
2700 (!NULL_INTERVAL_P (next_iv
)
2702 || XFASTINT (limit
) > next_iv
->position
));
2703 next_iv
= next_interval (next_iv
))
2705 for (p
= it_props
; p
->handler
; ++p
)
2707 Lisp_Object new_value
;
2709 new_value
= textget (next_iv
->plist
, *p
->name
);
2710 if (!EQ (values_here
[p
->idx
], new_value
))
2718 if (!NULL_INTERVAL_P (next_iv
))
2720 if (INTEGERP (limit
)
2721 && next_iv
->position
>= XFASTINT (limit
))
2722 /* No text property change up to limit. */
2723 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2725 /* Text properties change in next_iv. */
2726 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2730 xassert (STRINGP (it
->string
)
2731 || (it
->stop_charpos
>= BEGV
2732 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2736 /* Return the position of the next overlay change after POS in
2737 current_buffer. Value is point-max if no overlay change
2738 follows. This is like `next-overlay-change' but doesn't use
2742 next_overlay_change (pos
)
2747 Lisp_Object
*overlays
;
2750 /* Get all overlays at the given position. */
2751 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2753 /* If any of these overlays ends before endpos,
2754 use its ending point instead. */
2755 for (i
= 0; i
< noverlays
; ++i
)
2760 oend
= OVERLAY_END (overlays
[i
]);
2761 oendpos
= OVERLAY_POSITION (oend
);
2762 endpos
= min (endpos
, oendpos
);
2770 /***********************************************************************
2772 ***********************************************************************/
2774 /* Handle changes in the `fontified' property of the current buffer by
2775 calling hook functions from Qfontification_functions to fontify
2778 static enum prop_handled
2779 handle_fontified_prop (it
)
2782 Lisp_Object prop
, pos
;
2783 enum prop_handled handled
= HANDLED_NORMALLY
;
2785 /* Get the value of the `fontified' property at IT's current buffer
2786 position. (The `fontified' property doesn't have a special
2787 meaning in strings.) If the value is nil, call functions from
2788 Qfontification_functions. */
2789 if (!STRINGP (it
->string
)
2791 && !NILP (Vfontification_functions
)
2792 && !NILP (Vrun_hooks
)
2793 && (pos
= make_number (IT_CHARPOS (*it
)),
2794 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2797 int count
= SPECPDL_INDEX ();
2800 val
= Vfontification_functions
;
2801 specbind (Qfontification_functions
, Qnil
);
2803 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2804 safe_call1 (val
, pos
);
2807 Lisp_Object globals
, fn
;
2808 struct gcpro gcpro1
, gcpro2
;
2811 GCPRO2 (val
, globals
);
2813 for (; CONSP (val
); val
= XCDR (val
))
2819 /* A value of t indicates this hook has a local
2820 binding; it means to run the global binding too.
2821 In a global value, t should not occur. If it
2822 does, we must ignore it to avoid an endless
2824 for (globals
= Fdefault_value (Qfontification_functions
);
2826 globals
= XCDR (globals
))
2828 fn
= XCAR (globals
);
2830 safe_call1 (fn
, pos
);
2834 safe_call1 (fn
, pos
);
2840 unbind_to (count
, Qnil
);
2842 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2843 something. This avoids an endless loop if they failed to
2844 fontify the text for which reason ever. */
2845 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2846 handled
= HANDLED_RECOMPUTE_PROPS
;
2854 /***********************************************************************
2856 ***********************************************************************/
2858 /* Set up iterator IT from face properties at its current position.
2859 Called from handle_stop. */
2861 static enum prop_handled
2862 handle_face_prop (it
)
2865 int new_face_id
, next_stop
;
2867 if (!STRINGP (it
->string
))
2870 = face_at_buffer_position (it
->w
,
2872 it
->region_beg_charpos
,
2873 it
->region_end_charpos
,
2876 + TEXT_PROP_DISTANCE_LIMIT
),
2879 /* Is this a start of a run of characters with box face?
2880 Caveat: this can be called for a freshly initialized
2881 iterator; face_id is -1 in this case. We know that the new
2882 face will not change until limit, i.e. if the new face has a
2883 box, all characters up to limit will have one. But, as
2884 usual, we don't know whether limit is really the end. */
2885 if (new_face_id
!= it
->face_id
)
2887 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2889 /* If new face has a box but old face has not, this is
2890 the start of a run of characters with box, i.e. it has
2891 a shadow on the left side. The value of face_id of the
2892 iterator will be -1 if this is the initial call that gets
2893 the face. In this case, we have to look in front of IT's
2894 position and see whether there is a face != new_face_id. */
2895 it
->start_of_box_run_p
2896 = (new_face
->box
!= FACE_NO_BOX
2897 && (it
->face_id
>= 0
2898 || IT_CHARPOS (*it
) == BEG
2899 || new_face_id
!= face_before_it_pos (it
)));
2900 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2905 int base_face_id
, bufpos
;
2907 if (it
->current
.overlay_string_index
>= 0)
2908 bufpos
= IT_CHARPOS (*it
);
2912 /* For strings from a buffer, i.e. overlay strings or strings
2913 from a `display' property, use the face at IT's current
2914 buffer position as the base face to merge with, so that
2915 overlay strings appear in the same face as surrounding
2916 text, unless they specify their own faces. */
2917 base_face_id
= underlying_face_id (it
);
2919 new_face_id
= face_at_string_position (it
->w
,
2921 IT_STRING_CHARPOS (*it
),
2923 it
->region_beg_charpos
,
2924 it
->region_end_charpos
,
2928 #if 0 /* This shouldn't be neccessary. Let's check it. */
2929 /* If IT is used to display a mode line we would really like to
2930 use the mode line face instead of the frame's default face. */
2931 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2932 && new_face_id
== DEFAULT_FACE_ID
)
2933 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2936 /* Is this a start of a run of characters with box? Caveat:
2937 this can be called for a freshly allocated iterator; face_id
2938 is -1 is this case. We know that the new face will not
2939 change until the next check pos, i.e. if the new face has a
2940 box, all characters up to that position will have a
2941 box. But, as usual, we don't know whether that position
2942 is really the end. */
2943 if (new_face_id
!= it
->face_id
)
2945 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2946 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2948 /* If new face has a box but old face hasn't, this is the
2949 start of a run of characters with box, i.e. it has a
2950 shadow on the left side. */
2951 it
->start_of_box_run_p
2952 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2953 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2957 it
->face_id
= new_face_id
;
2958 return HANDLED_NORMALLY
;
2962 /* Return the ID of the face ``underlying'' IT's current position,
2963 which is in a string. If the iterator is associated with a
2964 buffer, return the face at IT's current buffer position.
2965 Otherwise, use the iterator's base_face_id. */
2968 underlying_face_id (it
)
2971 int face_id
= it
->base_face_id
, i
;
2973 xassert (STRINGP (it
->string
));
2975 for (i
= it
->sp
- 1; i
>= 0; --i
)
2976 if (NILP (it
->stack
[i
].string
))
2977 face_id
= it
->stack
[i
].face_id
;
2983 /* Compute the face one character before or after the current position
2984 of IT. BEFORE_P non-zero means get the face in front of IT's
2985 position. Value is the id of the face. */
2988 face_before_or_after_it_pos (it
, before_p
)
2993 int next_check_charpos
;
2994 struct text_pos pos
;
2996 xassert (it
->s
== NULL
);
2998 if (STRINGP (it
->string
))
3000 int bufpos
, base_face_id
;
3002 /* No face change past the end of the string (for the case
3003 we are padding with spaces). No face change before the
3005 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3006 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3009 /* Set pos to the position before or after IT's current position. */
3011 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3013 /* For composition, we must check the character after the
3015 pos
= (it
->what
== IT_COMPOSITION
3016 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3017 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3019 if (it
->current
.overlay_string_index
>= 0)
3020 bufpos
= IT_CHARPOS (*it
);
3024 base_face_id
= underlying_face_id (it
);
3026 /* Get the face for ASCII, or unibyte. */
3027 face_id
= face_at_string_position (it
->w
,
3031 it
->region_beg_charpos
,
3032 it
->region_end_charpos
,
3033 &next_check_charpos
,
3036 /* Correct the face for charsets different from ASCII. Do it
3037 for the multibyte case only. The face returned above is
3038 suitable for unibyte text if IT->string is unibyte. */
3039 if (STRING_MULTIBYTE (it
->string
))
3041 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3042 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3044 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3046 c
= string_char_and_length (p
, rest
, &len
);
3047 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3052 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3053 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3056 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3057 pos
= it
->current
.pos
;
3060 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3063 if (it
->what
== IT_COMPOSITION
)
3064 /* For composition, we must check the position after the
3066 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3068 INC_TEXT_POS (pos
, it
->multibyte_p
);
3071 /* Determine face for CHARSET_ASCII, or unibyte. */
3072 face_id
= face_at_buffer_position (it
->w
,
3074 it
->region_beg_charpos
,
3075 it
->region_end_charpos
,
3076 &next_check_charpos
,
3079 /* Correct the face for charsets different from ASCII. Do it
3080 for the multibyte case only. The face returned above is
3081 suitable for unibyte text if current_buffer is unibyte. */
3082 if (it
->multibyte_p
)
3084 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3085 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3086 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3095 /***********************************************************************
3097 ***********************************************************************/
3099 /* Set up iterator IT from invisible properties at its current
3100 position. Called from handle_stop. */
3102 static enum prop_handled
3103 handle_invisible_prop (it
)
3106 enum prop_handled handled
= HANDLED_NORMALLY
;
3108 if (STRINGP (it
->string
))
3110 extern Lisp_Object Qinvisible
;
3111 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3113 /* Get the value of the invisible text property at the
3114 current position. Value will be nil if there is no such
3116 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3117 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3120 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3122 handled
= HANDLED_RECOMPUTE_PROPS
;
3124 /* Get the position at which the next change of the
3125 invisible text property can be found in IT->string.
3126 Value will be nil if the property value is the same for
3127 all the rest of IT->string. */
3128 XSETINT (limit
, SCHARS (it
->string
));
3129 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3132 /* Text at current position is invisible. The next
3133 change in the property is at position end_charpos.
3134 Move IT's current position to that position. */
3135 if (INTEGERP (end_charpos
)
3136 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3138 struct text_pos old
;
3139 old
= it
->current
.string_pos
;
3140 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3141 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3145 /* The rest of the string is invisible. If this is an
3146 overlay string, proceed with the next overlay string
3147 or whatever comes and return a character from there. */
3148 if (it
->current
.overlay_string_index
>= 0)
3150 next_overlay_string (it
);
3151 /* Don't check for overlay strings when we just
3152 finished processing them. */
3153 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3157 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3158 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3165 int invis_p
, newpos
, next_stop
, start_charpos
;
3166 Lisp_Object pos
, prop
, overlay
;
3168 /* First of all, is there invisible text at this position? */
3169 start_charpos
= IT_CHARPOS (*it
);
3170 pos
= make_number (IT_CHARPOS (*it
));
3171 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3173 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3175 /* If we are on invisible text, skip over it. */
3176 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3178 /* Record whether we have to display an ellipsis for the
3180 int display_ellipsis_p
= invis_p
== 2;
3182 handled
= HANDLED_RECOMPUTE_PROPS
;
3184 /* Loop skipping over invisible text. The loop is left at
3185 ZV or with IT on the first char being visible again. */
3188 /* Try to skip some invisible text. Return value is the
3189 position reached which can be equal to IT's position
3190 if there is nothing invisible here. This skips both
3191 over invisible text properties and overlays with
3192 invisible property. */
3193 newpos
= skip_invisible (IT_CHARPOS (*it
),
3194 &next_stop
, ZV
, it
->window
);
3196 /* If we skipped nothing at all we weren't at invisible
3197 text in the first place. If everything to the end of
3198 the buffer was skipped, end the loop. */
3199 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3203 /* We skipped some characters but not necessarily
3204 all there are. Check if we ended up on visible
3205 text. Fget_char_property returns the property of
3206 the char before the given position, i.e. if we
3207 get invis_p = 0, this means that the char at
3208 newpos is visible. */
3209 pos
= make_number (newpos
);
3210 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3211 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3214 /* If we ended up on invisible text, proceed to
3215 skip starting with next_stop. */
3217 IT_CHARPOS (*it
) = next_stop
;
3221 /* The position newpos is now either ZV or on visible text. */
3222 IT_CHARPOS (*it
) = newpos
;
3223 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3225 /* If there are before-strings at the start of invisible
3226 text, and the text is invisible because of a text
3227 property, arrange to show before-strings because 20.x did
3228 it that way. (If the text is invisible because of an
3229 overlay property instead of a text property, this is
3230 already handled in the overlay code.) */
3232 && get_overlay_strings (it
, start_charpos
))
3234 handled
= HANDLED_RECOMPUTE_PROPS
;
3235 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3237 else if (display_ellipsis_p
)
3238 setup_for_ellipsis (it
, 0);
3246 /* Make iterator IT return `...' next.
3247 Replaces LEN characters from buffer. */
3250 setup_for_ellipsis (it
, len
)
3254 /* Use the display table definition for `...'. Invalid glyphs
3255 will be handled by the method returning elements from dpvec. */
3256 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3258 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3259 it
->dpvec
= v
->contents
;
3260 it
->dpend
= v
->contents
+ v
->size
;
3264 /* Default `...'. */
3265 it
->dpvec
= default_invis_vector
;
3266 it
->dpend
= default_invis_vector
+ 3;
3269 it
->dpvec_char_len
= len
;
3270 it
->current
.dpvec_index
= 0;
3271 it
->dpvec_face_id
= -1;
3273 /* Remember the current face id in case glyphs specify faces.
3274 IT's face is restored in set_iterator_to_next. */
3275 it
->saved_face_id
= it
->face_id
;
3276 it
->method
= next_element_from_display_vector
;
3282 /***********************************************************************
3284 ***********************************************************************/
3286 /* Set up iterator IT from `display' property at its current position.
3287 Called from handle_stop.
3288 We return HANDLED_RETURN if some part of the display property
3289 overrides the display of the buffer text itself.
3290 Otherwise we return HANDLED_NORMALLY. */
3292 static enum prop_handled
3293 handle_display_prop (it
)
3296 Lisp_Object prop
, object
;
3297 struct text_pos
*position
;
3298 /* Nonzero if some property replaces the display of the text itself. */
3299 int display_replaced_p
= 0;
3301 if (STRINGP (it
->string
))
3303 object
= it
->string
;
3304 position
= &it
->current
.string_pos
;
3308 object
= it
->w
->buffer
;
3309 position
= &it
->current
.pos
;
3312 /* Reset those iterator values set from display property values. */
3313 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3314 it
->space_width
= Qnil
;
3315 it
->font_height
= Qnil
;
3318 /* We don't support recursive `display' properties, i.e. string
3319 values that have a string `display' property, that have a string
3320 `display' property etc. */
3321 if (!it
->string_from_display_prop_p
)
3322 it
->area
= TEXT_AREA
;
3324 prop
= Fget_char_property (make_number (position
->charpos
),
3327 return HANDLED_NORMALLY
;
3330 /* Simple properties. */
3331 && !EQ (XCAR (prop
), Qimage
)
3332 && !EQ (XCAR (prop
), Qspace
)
3333 && !EQ (XCAR (prop
), Qwhen
)
3334 && !EQ (XCAR (prop
), Qslice
)
3335 && !EQ (XCAR (prop
), Qspace_width
)
3336 && !EQ (XCAR (prop
), Qheight
)
3337 && !EQ (XCAR (prop
), Qraise
)
3338 /* Marginal area specifications. */
3339 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3340 && !EQ (XCAR (prop
), Qleft_fringe
)
3341 && !EQ (XCAR (prop
), Qright_fringe
)
3342 && !NILP (XCAR (prop
)))
3344 for (; CONSP (prop
); prop
= XCDR (prop
))
3346 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3347 position
, display_replaced_p
))
3348 display_replaced_p
= 1;
3351 else if (VECTORP (prop
))
3354 for (i
= 0; i
< ASIZE (prop
); ++i
)
3355 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3356 position
, display_replaced_p
))
3357 display_replaced_p
= 1;
3361 if (handle_single_display_spec (it
, prop
, object
, position
, 0))
3362 display_replaced_p
= 1;
3365 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3369 /* Value is the position of the end of the `display' property starting
3370 at START_POS in OBJECT. */
3372 static struct text_pos
3373 display_prop_end (it
, object
, start_pos
)
3376 struct text_pos start_pos
;
3379 struct text_pos end_pos
;
3381 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3382 Qdisplay
, object
, Qnil
);
3383 CHARPOS (end_pos
) = XFASTINT (end
);
3384 if (STRINGP (object
))
3385 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3387 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3393 /* Set up IT from a single `display' specification PROP. OBJECT
3394 is the object in which the `display' property was found. *POSITION
3395 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3396 means that we previously saw a display specification which already
3397 replaced text display with something else, for example an image;
3398 we ignore such properties after the first one has been processed.
3400 If PROP is a `space' or `image' specification, and in some other
3401 cases too, set *POSITION to the position where the `display'
3404 Value is non-zero if something was found which replaces the display
3405 of buffer or string text. */
3408 handle_single_display_spec (it
, spec
, object
, position
,
3409 display_replaced_before_p
)
3413 struct text_pos
*position
;
3414 int display_replaced_before_p
;
3417 Lisp_Object location
, value
;
3418 struct text_pos start_pos
;
3421 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3422 If the result is non-nil, use VALUE instead of SPEC. */
3424 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3433 if (!NILP (form
) && !EQ (form
, Qt
))
3435 int count
= SPECPDL_INDEX ();
3436 struct gcpro gcpro1
;
3438 /* Bind `object' to the object having the `display' property, a
3439 buffer or string. Bind `position' to the position in the
3440 object where the property was found, and `buffer-position'
3441 to the current position in the buffer. */
3442 specbind (Qobject
, object
);
3443 specbind (Qposition
, make_number (CHARPOS (*position
)));
3444 specbind (Qbuffer_position
,
3445 make_number (STRINGP (object
)
3446 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3448 form
= safe_eval (form
);
3450 unbind_to (count
, Qnil
);
3456 /* Handle `(height HEIGHT)' specifications. */
3458 && EQ (XCAR (spec
), Qheight
)
3459 && CONSP (XCDR (spec
)))
3461 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3464 it
->font_height
= XCAR (XCDR (spec
));
3465 if (!NILP (it
->font_height
))
3467 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3468 int new_height
= -1;
3470 if (CONSP (it
->font_height
)
3471 && (EQ (XCAR (it
->font_height
), Qplus
)
3472 || EQ (XCAR (it
->font_height
), Qminus
))
3473 && CONSP (XCDR (it
->font_height
))
3474 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3476 /* `(+ N)' or `(- N)' where N is an integer. */
3477 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3478 if (EQ (XCAR (it
->font_height
), Qplus
))
3480 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3482 else if (FUNCTIONP (it
->font_height
))
3484 /* Call function with current height as argument.
3485 Value is the new height. */
3487 height
= safe_call1 (it
->font_height
,
3488 face
->lface
[LFACE_HEIGHT_INDEX
]);
3489 if (NUMBERP (height
))
3490 new_height
= XFLOATINT (height
);
3492 else if (NUMBERP (it
->font_height
))
3494 /* Value is a multiple of the canonical char height. */
3497 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3498 new_height
= (XFLOATINT (it
->font_height
)
3499 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3503 /* Evaluate IT->font_height with `height' bound to the
3504 current specified height to get the new height. */
3505 int count
= SPECPDL_INDEX ();
3507 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3508 value
= safe_eval (it
->font_height
);
3509 unbind_to (count
, Qnil
);
3511 if (NUMBERP (value
))
3512 new_height
= XFLOATINT (value
);
3516 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3522 /* Handle `(space_width WIDTH)'. */
3524 && EQ (XCAR (spec
), Qspace_width
)
3525 && CONSP (XCDR (spec
)))
3527 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3530 value
= XCAR (XCDR (spec
));
3531 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3532 it
->space_width
= value
;
3537 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3539 && EQ (XCAR (spec
), Qslice
))
3543 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3546 if (tem
= XCDR (spec
), CONSP (tem
))
3548 it
->slice
.x
= XCAR (tem
);
3549 if (tem
= XCDR (tem
), CONSP (tem
))
3551 it
->slice
.y
= XCAR (tem
);
3552 if (tem
= XCDR (tem
), CONSP (tem
))
3554 it
->slice
.width
= XCAR (tem
);
3555 if (tem
= XCDR (tem
), CONSP (tem
))
3556 it
->slice
.height
= XCAR (tem
);
3564 /* Handle `(raise FACTOR)'. */
3566 && EQ (XCAR (spec
), Qraise
)
3567 && CONSP (XCDR (spec
)))
3569 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3572 #ifdef HAVE_WINDOW_SYSTEM
3573 value
= XCAR (XCDR (spec
));
3574 if (NUMBERP (value
))
3576 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3577 it
->voffset
= - (XFLOATINT (value
)
3578 * (FONT_HEIGHT (face
->font
)));
3580 #endif /* HAVE_WINDOW_SYSTEM */
3585 /* Don't handle the other kinds of display specifications
3586 inside a string that we got from a `display' property. */
3587 if (it
->string_from_display_prop_p
)
3590 /* Characters having this form of property are not displayed, so
3591 we have to find the end of the property. */
3592 start_pos
= *position
;
3593 *position
= display_prop_end (it
, object
, start_pos
);
3596 /* Stop the scan at that end position--we assume that all
3597 text properties change there. */
3598 it
->stop_charpos
= position
->charpos
;
3600 /* Handle `(left-fringe BITMAP [FACE])'
3601 and `(right-fringe BITMAP [FACE])'. */
3603 && (EQ (XCAR (spec
), Qleft_fringe
)
3604 || EQ (XCAR (spec
), Qright_fringe
))
3605 && CONSP (XCDR (spec
)))
3607 int face_id
= DEFAULT_FACE_ID
;
3610 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3611 /* If we return here, POSITION has been advanced
3612 across the text with this property. */
3615 #ifdef HAVE_WINDOW_SYSTEM
3616 value
= XCAR (XCDR (spec
));
3617 if (!SYMBOLP (value
)
3618 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3619 /* If we return here, POSITION has been advanced
3620 across the text with this property. */
3623 if (CONSP (XCDR (XCDR (spec
))))
3625 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3626 int face_id2
= lookup_named_face (it
->f
, face_name
, 'A', 0);
3631 /* Save current settings of IT so that we can restore them
3632 when we are finished with the glyph property value. */
3636 it
->area
= TEXT_AREA
;
3637 it
->what
= IT_IMAGE
;
3638 it
->image_id
= -1; /* no image */
3639 it
->position
= start_pos
;
3640 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3641 it
->method
= next_element_from_image
;
3642 it
->face_id
= face_id
;
3644 /* Say that we haven't consumed the characters with
3645 `display' property yet. The call to pop_it in
3646 set_iterator_to_next will clean this up. */
3647 *position
= start_pos
;
3649 if (EQ (XCAR (spec
), Qleft_fringe
))
3651 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3652 it
->left_user_fringe_face_id
= face_id
;
3656 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3657 it
->right_user_fringe_face_id
= face_id
;
3659 #endif /* HAVE_WINDOW_SYSTEM */
3663 /* Prepare to handle `((margin left-margin) ...)',
3664 `((margin right-margin) ...)' and `((margin nil) ...)'
3665 prefixes for display specifications. */
3666 location
= Qunbound
;
3667 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3671 value
= XCDR (spec
);
3673 value
= XCAR (value
);
3676 if (EQ (XCAR (tem
), Qmargin
)
3677 && (tem
= XCDR (tem
),
3678 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3680 || EQ (tem
, Qleft_margin
)
3681 || EQ (tem
, Qright_margin
))))
3685 if (EQ (location
, Qunbound
))
3691 /* After this point, VALUE is the property after any
3692 margin prefix has been stripped. It must be a string,
3693 an image specification, or `(space ...)'.
3695 LOCATION specifies where to display: `left-margin',
3696 `right-margin' or nil. */
3698 valid_p
= (STRINGP (value
)
3699 #ifdef HAVE_WINDOW_SYSTEM
3700 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3701 #endif /* not HAVE_WINDOW_SYSTEM */
3702 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3704 if (valid_p
&& !display_replaced_before_p
)
3706 /* Save current settings of IT so that we can restore them
3707 when we are finished with the glyph property value. */
3710 if (NILP (location
))
3711 it
->area
= TEXT_AREA
;
3712 else if (EQ (location
, Qleft_margin
))
3713 it
->area
= LEFT_MARGIN_AREA
;
3715 it
->area
= RIGHT_MARGIN_AREA
;
3717 if (STRINGP (value
))
3720 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3721 it
->current
.overlay_string_index
= -1;
3722 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3723 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3724 it
->method
= next_element_from_string
;
3725 it
->stop_charpos
= 0;
3726 it
->string_from_display_prop_p
= 1;
3727 /* Say that we haven't consumed the characters with
3728 `display' property yet. The call to pop_it in
3729 set_iterator_to_next will clean this up. */
3730 *position
= start_pos
;
3732 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3734 it
->method
= next_element_from_stretch
;
3736 it
->current
.pos
= it
->position
= start_pos
;
3738 #ifdef HAVE_WINDOW_SYSTEM
3741 it
->what
= IT_IMAGE
;
3742 it
->image_id
= lookup_image (it
->f
, value
);
3743 it
->position
= start_pos
;
3744 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3745 it
->method
= next_element_from_image
;
3747 /* Say that we haven't consumed the characters with
3748 `display' property yet. The call to pop_it in
3749 set_iterator_to_next will clean this up. */
3750 *position
= start_pos
;
3752 #endif /* HAVE_WINDOW_SYSTEM */
3757 /* Invalid property or property not supported. Restore
3758 POSITION to what it was before. */
3759 *position
= start_pos
;
3764 /* Check if SPEC is a display specification value whose text should be
3765 treated as intangible. */
3768 single_display_spec_intangible_p (prop
)
3771 /* Skip over `when FORM'. */
3772 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3786 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3787 we don't need to treat text as intangible. */
3788 if (EQ (XCAR (prop
), Qmargin
))
3796 || EQ (XCAR (prop
), Qleft_margin
)
3797 || EQ (XCAR (prop
), Qright_margin
))
3801 return (CONSP (prop
)
3802 && (EQ (XCAR (prop
), Qimage
)
3803 || EQ (XCAR (prop
), Qspace
)));
3807 /* Check if PROP is a display property value whose text should be
3808 treated as intangible. */
3811 display_prop_intangible_p (prop
)
3815 && CONSP (XCAR (prop
))
3816 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3818 /* A list of sub-properties. */
3819 while (CONSP (prop
))
3821 if (single_display_spec_intangible_p (XCAR (prop
)))
3826 else if (VECTORP (prop
))
3828 /* A vector of sub-properties. */
3830 for (i
= 0; i
< ASIZE (prop
); ++i
)
3831 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3835 return single_display_spec_intangible_p (prop
);
3841 /* Return 1 if PROP is a display sub-property value containing STRING. */
3844 single_display_spec_string_p (prop
, string
)
3845 Lisp_Object prop
, string
;
3847 if (EQ (string
, prop
))
3850 /* Skip over `when FORM'. */
3851 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3860 /* Skip over `margin LOCATION'. */
3861 if (EQ (XCAR (prop
), Qmargin
))
3872 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3876 /* Return 1 if STRING appears in the `display' property PROP. */
3879 display_prop_string_p (prop
, string
)
3880 Lisp_Object prop
, string
;
3883 && CONSP (XCAR (prop
))
3884 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3886 /* A list of sub-properties. */
3887 while (CONSP (prop
))
3889 if (single_display_spec_string_p (XCAR (prop
), string
))
3894 else if (VECTORP (prop
))
3896 /* A vector of sub-properties. */
3898 for (i
= 0; i
< ASIZE (prop
); ++i
)
3899 if (single_display_spec_string_p (AREF (prop
, i
), string
))
3903 return single_display_spec_string_p (prop
, string
);
3909 /* Determine from which buffer position in W's buffer STRING comes
3910 from. AROUND_CHARPOS is an approximate position where it could
3911 be from. Value is the buffer position or 0 if it couldn't be
3914 W's buffer must be current.
3916 This function is necessary because we don't record buffer positions
3917 in glyphs generated from strings (to keep struct glyph small).
3918 This function may only use code that doesn't eval because it is
3919 called asynchronously from note_mouse_highlight. */
3922 string_buffer_position (w
, string
, around_charpos
)
3927 Lisp_Object limit
, prop
, pos
;
3928 const int MAX_DISTANCE
= 1000;
3931 pos
= make_number (around_charpos
);
3932 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3933 while (!found
&& !EQ (pos
, limit
))
3935 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3936 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3939 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3944 pos
= make_number (around_charpos
);
3945 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3946 while (!found
&& !EQ (pos
, limit
))
3948 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3949 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3952 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3957 return found
? XINT (pos
) : 0;
3962 /***********************************************************************
3963 `composition' property
3964 ***********************************************************************/
3966 /* Set up iterator IT from `composition' property at its current
3967 position. Called from handle_stop. */
3969 static enum prop_handled
3970 handle_composition_prop (it
)
3973 Lisp_Object prop
, string
;
3974 int pos
, pos_byte
, end
;
3975 enum prop_handled handled
= HANDLED_NORMALLY
;
3977 if (STRINGP (it
->string
))
3979 pos
= IT_STRING_CHARPOS (*it
);
3980 pos_byte
= IT_STRING_BYTEPOS (*it
);
3981 string
= it
->string
;
3985 pos
= IT_CHARPOS (*it
);
3986 pos_byte
= IT_BYTEPOS (*it
);
3990 /* If there's a valid composition and point is not inside of the
3991 composition (in the case that the composition is from the current
3992 buffer), draw a glyph composed from the composition components. */
3993 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3994 && COMPOSITION_VALID_P (pos
, end
, prop
)
3995 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3997 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4001 it
->method
= next_element_from_composition
;
4003 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4004 /* For a terminal, draw only the first character of the
4006 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4007 it
->len
= (STRINGP (it
->string
)
4008 ? string_char_to_byte (it
->string
, end
)
4009 : CHAR_TO_BYTE (end
)) - pos_byte
;
4010 it
->stop_charpos
= end
;
4011 handled
= HANDLED_RETURN
;
4020 /***********************************************************************
4022 ***********************************************************************/
4024 /* The following structure is used to record overlay strings for
4025 later sorting in load_overlay_strings. */
4027 struct overlay_entry
4029 Lisp_Object overlay
;
4036 /* Set up iterator IT from overlay strings at its current position.
4037 Called from handle_stop. */
4039 static enum prop_handled
4040 handle_overlay_change (it
)
4043 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4044 return HANDLED_RECOMPUTE_PROPS
;
4046 return HANDLED_NORMALLY
;
4050 /* Set up the next overlay string for delivery by IT, if there is an
4051 overlay string to deliver. Called by set_iterator_to_next when the
4052 end of the current overlay string is reached. If there are more
4053 overlay strings to display, IT->string and
4054 IT->current.overlay_string_index are set appropriately here.
4055 Otherwise IT->string is set to nil. */
4058 next_overlay_string (it
)
4061 ++it
->current
.overlay_string_index
;
4062 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4064 /* No more overlay strings. Restore IT's settings to what
4065 they were before overlay strings were processed, and
4066 continue to deliver from current_buffer. */
4067 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4070 xassert (it
->stop_charpos
>= BEGV
4071 && it
->stop_charpos
<= it
->end_charpos
);
4073 it
->current
.overlay_string_index
= -1;
4074 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4075 it
->n_overlay_strings
= 0;
4076 it
->method
= next_element_from_buffer
;
4078 /* If we're at the end of the buffer, record that we have
4079 processed the overlay strings there already, so that
4080 next_element_from_buffer doesn't try it again. */
4081 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4082 it
->overlay_strings_at_end_processed_p
= 1;
4084 /* If we have to display `...' for invisible text, set
4085 the iterator up for that. */
4086 if (display_ellipsis_p
)
4087 setup_for_ellipsis (it
, 0);
4091 /* There are more overlay strings to process. If
4092 IT->current.overlay_string_index has advanced to a position
4093 where we must load IT->overlay_strings with more strings, do
4095 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4097 if (it
->current
.overlay_string_index
&& i
== 0)
4098 load_overlay_strings (it
, 0);
4100 /* Initialize IT to deliver display elements from the overlay
4102 it
->string
= it
->overlay_strings
[i
];
4103 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4104 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4105 it
->method
= next_element_from_string
;
4106 it
->stop_charpos
= 0;
4113 /* Compare two overlay_entry structures E1 and E2. Used as a
4114 comparison function for qsort in load_overlay_strings. Overlay
4115 strings for the same position are sorted so that
4117 1. All after-strings come in front of before-strings, except
4118 when they come from the same overlay.
4120 2. Within after-strings, strings are sorted so that overlay strings
4121 from overlays with higher priorities come first.
4123 2. Within before-strings, strings are sorted so that overlay
4124 strings from overlays with higher priorities come last.
4126 Value is analogous to strcmp. */
4130 compare_overlay_entries (e1
, e2
)
4133 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4134 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4137 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4139 /* Let after-strings appear in front of before-strings if
4140 they come from different overlays. */
4141 if (EQ (entry1
->overlay
, entry2
->overlay
))
4142 result
= entry1
->after_string_p
? 1 : -1;
4144 result
= entry1
->after_string_p
? -1 : 1;
4146 else if (entry1
->after_string_p
)
4147 /* After-strings sorted in order of decreasing priority. */
4148 result
= entry2
->priority
- entry1
->priority
;
4150 /* Before-strings sorted in order of increasing priority. */
4151 result
= entry1
->priority
- entry2
->priority
;
4157 /* Load the vector IT->overlay_strings with overlay strings from IT's
4158 current buffer position, or from CHARPOS if that is > 0. Set
4159 IT->n_overlays to the total number of overlay strings found.
4161 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4162 a time. On entry into load_overlay_strings,
4163 IT->current.overlay_string_index gives the number of overlay
4164 strings that have already been loaded by previous calls to this
4167 IT->add_overlay_start contains an additional overlay start
4168 position to consider for taking overlay strings from, if non-zero.
4169 This position comes into play when the overlay has an `invisible'
4170 property, and both before and after-strings. When we've skipped to
4171 the end of the overlay, because of its `invisible' property, we
4172 nevertheless want its before-string to appear.
4173 IT->add_overlay_start will contain the overlay start position
4176 Overlay strings are sorted so that after-string strings come in
4177 front of before-string strings. Within before and after-strings,
4178 strings are sorted by overlay priority. See also function
4179 compare_overlay_entries. */
4182 load_overlay_strings (it
, charpos
)
4186 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4187 Lisp_Object overlay
, window
, str
, invisible
;
4188 struct Lisp_Overlay
*ov
;
4191 int n
= 0, i
, j
, invis_p
;
4192 struct overlay_entry
*entries
4193 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4196 charpos
= IT_CHARPOS (*it
);
4198 /* Append the overlay string STRING of overlay OVERLAY to vector
4199 `entries' which has size `size' and currently contains `n'
4200 elements. AFTER_P non-zero means STRING is an after-string of
4202 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4205 Lisp_Object priority; \
4209 int new_size = 2 * size; \
4210 struct overlay_entry *old = entries; \
4212 (struct overlay_entry *) alloca (new_size \
4213 * sizeof *entries); \
4214 bcopy (old, entries, size * sizeof *entries); \
4218 entries[n].string = (STRING); \
4219 entries[n].overlay = (OVERLAY); \
4220 priority = Foverlay_get ((OVERLAY), Qpriority); \
4221 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4222 entries[n].after_string_p = (AFTER_P); \
4227 /* Process overlay before the overlay center. */
4228 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4230 XSETMISC (overlay
, ov
);
4231 xassert (OVERLAYP (overlay
));
4232 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4233 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4238 /* Skip this overlay if it doesn't start or end at IT's current
4240 if (end
!= charpos
&& start
!= charpos
)
4243 /* Skip this overlay if it doesn't apply to IT->w. */
4244 window
= Foverlay_get (overlay
, Qwindow
);
4245 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4248 /* If the text ``under'' the overlay is invisible, both before-
4249 and after-strings from this overlay are visible; start and
4250 end position are indistinguishable. */
4251 invisible
= Foverlay_get (overlay
, Qinvisible
);
4252 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4254 /* If overlay has a non-empty before-string, record it. */
4255 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4256 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4258 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4260 /* If overlay has a non-empty after-string, record it. */
4261 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4262 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4264 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4267 /* Process overlays after the overlay center. */
4268 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4270 XSETMISC (overlay
, ov
);
4271 xassert (OVERLAYP (overlay
));
4272 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4273 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4275 if (start
> charpos
)
4278 /* Skip this overlay if it doesn't start or end at IT's current
4280 if (end
!= charpos
&& start
!= charpos
)
4283 /* Skip this overlay if it doesn't apply to IT->w. */
4284 window
= Foverlay_get (overlay
, Qwindow
);
4285 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4288 /* If the text ``under'' the overlay is invisible, it has a zero
4289 dimension, and both before- and after-strings apply. */
4290 invisible
= Foverlay_get (overlay
, Qinvisible
);
4291 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4293 /* If overlay has a non-empty before-string, record it. */
4294 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4295 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4297 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4299 /* If overlay has a non-empty after-string, record it. */
4300 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4301 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4303 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4306 #undef RECORD_OVERLAY_STRING
4310 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4312 /* Record the total number of strings to process. */
4313 it
->n_overlay_strings
= n
;
4315 /* IT->current.overlay_string_index is the number of overlay strings
4316 that have already been consumed by IT. Copy some of the
4317 remaining overlay strings to IT->overlay_strings. */
4319 j
= it
->current
.overlay_string_index
;
4320 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4321 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4327 /* Get the first chunk of overlay strings at IT's current buffer
4328 position, or at CHARPOS if that is > 0. Value is non-zero if at
4329 least one overlay string was found. */
4332 get_overlay_strings (it
, charpos
)
4336 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4337 process. This fills IT->overlay_strings with strings, and sets
4338 IT->n_overlay_strings to the total number of strings to process.
4339 IT->pos.overlay_string_index has to be set temporarily to zero
4340 because load_overlay_strings needs this; it must be set to -1
4341 when no overlay strings are found because a zero value would
4342 indicate a position in the first overlay string. */
4343 it
->current
.overlay_string_index
= 0;
4344 load_overlay_strings (it
, charpos
);
4346 /* If we found overlay strings, set up IT to deliver display
4347 elements from the first one. Otherwise set up IT to deliver
4348 from current_buffer. */
4349 if (it
->n_overlay_strings
)
4351 /* Make sure we know settings in current_buffer, so that we can
4352 restore meaningful values when we're done with the overlay
4354 compute_stop_pos (it
);
4355 xassert (it
->face_id
>= 0);
4357 /* Save IT's settings. They are restored after all overlay
4358 strings have been processed. */
4359 xassert (it
->sp
== 0);
4362 /* Set up IT to deliver display elements from the first overlay
4364 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4365 it
->string
= it
->overlay_strings
[0];
4366 it
->stop_charpos
= 0;
4367 xassert (STRINGP (it
->string
));
4368 it
->end_charpos
= SCHARS (it
->string
);
4369 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4370 it
->method
= next_element_from_string
;
4375 it
->current
.overlay_string_index
= -1;
4376 it
->method
= next_element_from_buffer
;
4381 /* Value is non-zero if we found at least one overlay string. */
4382 return STRINGP (it
->string
);
4387 /***********************************************************************
4388 Saving and restoring state
4389 ***********************************************************************/
4391 /* Save current settings of IT on IT->stack. Called, for example,
4392 before setting up IT for an overlay string, to be able to restore
4393 IT's settings to what they were after the overlay string has been
4400 struct iterator_stack_entry
*p
;
4402 xassert (it
->sp
< 2);
4403 p
= it
->stack
+ it
->sp
;
4405 p
->stop_charpos
= it
->stop_charpos
;
4406 xassert (it
->face_id
>= 0);
4407 p
->face_id
= it
->face_id
;
4408 p
->string
= it
->string
;
4409 p
->pos
= it
->current
;
4410 p
->end_charpos
= it
->end_charpos
;
4411 p
->string_nchars
= it
->string_nchars
;
4413 p
->multibyte_p
= it
->multibyte_p
;
4414 p
->slice
= it
->slice
;
4415 p
->space_width
= it
->space_width
;
4416 p
->font_height
= it
->font_height
;
4417 p
->voffset
= it
->voffset
;
4418 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4419 p
->display_ellipsis_p
= 0;
4424 /* Restore IT's settings from IT->stack. Called, for example, when no
4425 more overlay strings must be processed, and we return to delivering
4426 display elements from a buffer, or when the end of a string from a
4427 `display' property is reached and we return to delivering display
4428 elements from an overlay string, or from a buffer. */
4434 struct iterator_stack_entry
*p
;
4436 xassert (it
->sp
> 0);
4438 p
= it
->stack
+ it
->sp
;
4439 it
->stop_charpos
= p
->stop_charpos
;
4440 it
->face_id
= p
->face_id
;
4441 it
->string
= p
->string
;
4442 it
->current
= p
->pos
;
4443 it
->end_charpos
= p
->end_charpos
;
4444 it
->string_nchars
= p
->string_nchars
;
4446 it
->multibyte_p
= p
->multibyte_p
;
4447 it
->slice
= p
->slice
;
4448 it
->space_width
= p
->space_width
;
4449 it
->font_height
= p
->font_height
;
4450 it
->voffset
= p
->voffset
;
4451 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4456 /***********************************************************************
4458 ***********************************************************************/
4460 /* Set IT's current position to the previous line start. */
4463 back_to_previous_line_start (it
)
4466 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4467 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4471 /* Move IT to the next line start.
4473 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4474 we skipped over part of the text (as opposed to moving the iterator
4475 continuously over the text). Otherwise, don't change the value
4478 Newlines may come from buffer text, overlay strings, or strings
4479 displayed via the `display' property. That's the reason we can't
4480 simply use find_next_newline_no_quit.
4482 Note that this function may not skip over invisible text that is so
4483 because of text properties and immediately follows a newline. If
4484 it would, function reseat_at_next_visible_line_start, when called
4485 from set_iterator_to_next, would effectively make invisible
4486 characters following a newline part of the wrong glyph row, which
4487 leads to wrong cursor motion. */
4490 forward_to_next_line_start (it
, skipped_p
)
4494 int old_selective
, newline_found_p
, n
;
4495 const int MAX_NEWLINE_DISTANCE
= 500;
4497 /* If already on a newline, just consume it to avoid unintended
4498 skipping over invisible text below. */
4499 if (it
->what
== IT_CHARACTER
4501 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4503 set_iterator_to_next (it
, 0);
4508 /* Don't handle selective display in the following. It's (a)
4509 unnecessary because it's done by the caller, and (b) leads to an
4510 infinite recursion because next_element_from_ellipsis indirectly
4511 calls this function. */
4512 old_selective
= it
->selective
;
4515 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4516 from buffer text. */
4517 for (n
= newline_found_p
= 0;
4518 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4519 n
+= STRINGP (it
->string
) ? 0 : 1)
4521 if (!get_next_display_element (it
))
4523 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4524 set_iterator_to_next (it
, 0);
4527 /* If we didn't find a newline near enough, see if we can use a
4529 if (!newline_found_p
)
4531 int start
= IT_CHARPOS (*it
);
4532 int limit
= find_next_newline_no_quit (start
, 1);
4535 xassert (!STRINGP (it
->string
));
4537 /* If there isn't any `display' property in sight, and no
4538 overlays, we can just use the position of the newline in
4540 if (it
->stop_charpos
>= limit
4541 || ((pos
= Fnext_single_property_change (make_number (start
),
4543 Qnil
, make_number (limit
)),
4545 && next_overlay_change (start
) == ZV
))
4547 IT_CHARPOS (*it
) = limit
;
4548 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4549 *skipped_p
= newline_found_p
= 1;
4553 while (get_next_display_element (it
)
4554 && !newline_found_p
)
4556 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4557 set_iterator_to_next (it
, 0);
4562 it
->selective
= old_selective
;
4563 return newline_found_p
;
4567 /* Set IT's current position to the previous visible line start. Skip
4568 invisible text that is so either due to text properties or due to
4569 selective display. Caution: this does not change IT->current_x and
4573 back_to_previous_visible_line_start (it
)
4578 /* Go back one newline if not on BEGV already. */
4579 if (IT_CHARPOS (*it
) > BEGV
)
4580 back_to_previous_line_start (it
);
4582 /* Move over lines that are invisible because of selective display
4583 or text properties. */
4584 while (IT_CHARPOS (*it
) > BEGV
4589 /* If selective > 0, then lines indented more than that values
4591 if (it
->selective
> 0
4592 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4593 (double) it
->selective
)) /* iftc */
4599 /* Check the newline before point for invisibility. */
4600 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4601 Qinvisible
, it
->window
);
4602 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4607 /* Commenting this out fixes the bug described in
4608 http://www.math.ku.dk/~larsh/emacs/emacs-loops-on-large-images/test-case.txt. */
4611 struct it it2
= *it
;
4613 if (handle_display_prop (&it2
) == HANDLED_RETURN
)
4618 /* Back one more newline if the current one is invisible. */
4620 back_to_previous_line_start (it
);
4623 xassert (IT_CHARPOS (*it
) >= BEGV
);
4624 xassert (IT_CHARPOS (*it
) == BEGV
4625 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4630 /* Reseat iterator IT at the previous visible line start. Skip
4631 invisible text that is so either due to text properties or due to
4632 selective display. At the end, update IT's overlay information,
4633 face information etc. */
4636 reseat_at_previous_visible_line_start (it
)
4639 back_to_previous_visible_line_start (it
);
4640 reseat (it
, it
->current
.pos
, 1);
4645 /* Reseat iterator IT on the next visible line start in the current
4646 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4647 preceding the line start. Skip over invisible text that is so
4648 because of selective display. Compute faces, overlays etc at the
4649 new position. Note that this function does not skip over text that
4650 is invisible because of text properties. */
4653 reseat_at_next_visible_line_start (it
, on_newline_p
)
4657 int newline_found_p
, skipped_p
= 0;
4659 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4661 /* Skip over lines that are invisible because they are indented
4662 more than the value of IT->selective. */
4663 if (it
->selective
> 0)
4664 while (IT_CHARPOS (*it
) < ZV
4665 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4666 (double) it
->selective
)) /* iftc */
4668 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4669 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4672 /* Position on the newline if that's what's requested. */
4673 if (on_newline_p
&& newline_found_p
)
4675 if (STRINGP (it
->string
))
4677 if (IT_STRING_CHARPOS (*it
) > 0)
4679 --IT_STRING_CHARPOS (*it
);
4680 --IT_STRING_BYTEPOS (*it
);
4683 else if (IT_CHARPOS (*it
) > BEGV
)
4687 reseat (it
, it
->current
.pos
, 0);
4691 reseat (it
, it
->current
.pos
, 0);
4698 /***********************************************************************
4699 Changing an iterator's position
4700 ***********************************************************************/
4702 /* Change IT's current position to POS in current_buffer. If FORCE_P
4703 is non-zero, always check for text properties at the new position.
4704 Otherwise, text properties are only looked up if POS >=
4705 IT->check_charpos of a property. */
4708 reseat (it
, pos
, force_p
)
4710 struct text_pos pos
;
4713 int original_pos
= IT_CHARPOS (*it
);
4715 reseat_1 (it
, pos
, 0);
4717 /* Determine where to check text properties. Avoid doing it
4718 where possible because text property lookup is very expensive. */
4720 || CHARPOS (pos
) > it
->stop_charpos
4721 || CHARPOS (pos
) < original_pos
)
4728 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4729 IT->stop_pos to POS, also. */
4732 reseat_1 (it
, pos
, set_stop_p
)
4734 struct text_pos pos
;
4737 /* Don't call this function when scanning a C string. */
4738 xassert (it
->s
== NULL
);
4740 /* POS must be a reasonable value. */
4741 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4743 it
->current
.pos
= it
->position
= pos
;
4744 XSETBUFFER (it
->object
, current_buffer
);
4745 it
->end_charpos
= ZV
;
4747 it
->current
.dpvec_index
= -1;
4748 it
->current
.overlay_string_index
= -1;
4749 IT_STRING_CHARPOS (*it
) = -1;
4750 IT_STRING_BYTEPOS (*it
) = -1;
4752 it
->method
= next_element_from_buffer
;
4753 /* RMS: I added this to fix a bug in move_it_vertically_backward
4754 where it->area continued to relate to the starting point
4755 for the backward motion. Bug report from
4756 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4757 However, I am not sure whether reseat still does the right thing
4758 in general after this change. */
4759 it
->area
= TEXT_AREA
;
4760 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4762 it
->face_before_selective_p
= 0;
4765 it
->stop_charpos
= CHARPOS (pos
);
4769 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4770 If S is non-null, it is a C string to iterate over. Otherwise,
4771 STRING gives a Lisp string to iterate over.
4773 If PRECISION > 0, don't return more then PRECISION number of
4774 characters from the string.
4776 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4777 characters have been returned. FIELD_WIDTH < 0 means an infinite
4780 MULTIBYTE = 0 means disable processing of multibyte characters,
4781 MULTIBYTE > 0 means enable it,
4782 MULTIBYTE < 0 means use IT->multibyte_p.
4784 IT must be initialized via a prior call to init_iterator before
4785 calling this function. */
4788 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4793 int precision
, field_width
, multibyte
;
4795 /* No region in strings. */
4796 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4798 /* No text property checks performed by default, but see below. */
4799 it
->stop_charpos
= -1;
4801 /* Set iterator position and end position. */
4802 bzero (&it
->current
, sizeof it
->current
);
4803 it
->current
.overlay_string_index
= -1;
4804 it
->current
.dpvec_index
= -1;
4805 xassert (charpos
>= 0);
4807 /* If STRING is specified, use its multibyteness, otherwise use the
4808 setting of MULTIBYTE, if specified. */
4810 it
->multibyte_p
= multibyte
> 0;
4814 xassert (STRINGP (string
));
4815 it
->string
= string
;
4817 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4818 it
->method
= next_element_from_string
;
4819 it
->current
.string_pos
= string_pos (charpos
, string
);
4826 /* Note that we use IT->current.pos, not it->current.string_pos,
4827 for displaying C strings. */
4828 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4829 if (it
->multibyte_p
)
4831 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4832 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4836 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4837 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4840 it
->method
= next_element_from_c_string
;
4843 /* PRECISION > 0 means don't return more than PRECISION characters
4845 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4846 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4848 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4849 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4850 FIELD_WIDTH < 0 means infinite field width. This is useful for
4851 padding with `-' at the end of a mode line. */
4852 if (field_width
< 0)
4853 field_width
= INFINITY
;
4854 if (field_width
> it
->end_charpos
- charpos
)
4855 it
->end_charpos
= charpos
+ field_width
;
4857 /* Use the standard display table for displaying strings. */
4858 if (DISP_TABLE_P (Vstandard_display_table
))
4859 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4861 it
->stop_charpos
= charpos
;
4867 /***********************************************************************
4869 ***********************************************************************/
4871 /* Load IT's display element fields with information about the next
4872 display element from the current position of IT. Value is zero if
4873 end of buffer (or C string) is reached. */
4876 get_next_display_element (it
)
4879 /* Non-zero means that we found a display element. Zero means that
4880 we hit the end of what we iterate over. Performance note: the
4881 function pointer `method' used here turns out to be faster than
4882 using a sequence of if-statements. */
4886 success_p
= (*it
->method
) (it
);
4888 if (it
->what
== IT_CHARACTER
)
4890 /* Map via display table or translate control characters.
4891 IT->c, IT->len etc. have been set to the next character by
4892 the function call above. If we have a display table, and it
4893 contains an entry for IT->c, translate it. Don't do this if
4894 IT->c itself comes from a display table, otherwise we could
4895 end up in an infinite recursion. (An alternative could be to
4896 count the recursion depth of this function and signal an
4897 error when a certain maximum depth is reached.) Is it worth
4899 if (success_p
&& it
->dpvec
== NULL
)
4904 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4907 struct Lisp_Vector
*v
= XVECTOR (dv
);
4909 /* Return the first character from the display table
4910 entry, if not empty. If empty, don't display the
4911 current character. */
4914 it
->dpvec_char_len
= it
->len
;
4915 it
->dpvec
= v
->contents
;
4916 it
->dpend
= v
->contents
+ v
->size
;
4917 it
->current
.dpvec_index
= 0;
4918 it
->dpvec_face_id
= -1;
4919 it
->saved_face_id
= it
->face_id
;
4920 it
->method
= next_element_from_display_vector
;
4925 set_iterator_to_next (it
, 0);
4930 /* Translate control characters into `\003' or `^C' form.
4931 Control characters coming from a display table entry are
4932 currently not translated because we use IT->dpvec to hold
4933 the translation. This could easily be changed but I
4934 don't believe that it is worth doing.
4936 If it->multibyte_p is nonzero, eight-bit characters and
4937 non-printable multibyte characters are also translated to
4940 If it->multibyte_p is zero, eight-bit characters that
4941 don't have corresponding multibyte char code are also
4942 translated to octal form. */
4943 else if ((it
->c
< ' '
4944 && (it
->area
!= TEXT_AREA
4945 /* In mode line, treat \n like other crl chars. */
4947 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
4948 || (it
->c
!= '\n' && it
->c
!= '\t')))
4952 || !CHAR_PRINTABLE_P (it
->c
)
4953 || (!NILP (Vshow_nonbreak_escape
)
4954 && (it
->c
== 0x8ad || it
->c
== 0x8a0)))
4956 && (!unibyte_display_via_language_environment
4957 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
4959 /* IT->c is a control character which must be displayed
4960 either as '\003' or as `^C' where the '\\' and '^'
4961 can be defined in the display table. Fill
4962 IT->ctl_chars with glyphs for what we have to
4963 display. Then, set IT->dpvec to these glyphs. */
4966 int face_id
, lface_id
;
4969 if (it
->c
< 128 && it
->ctl_arrow_p
)
4971 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4973 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4974 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4976 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4977 lface_id
= FAST_GLYPH_FACE (g
);
4980 g
= FAST_GLYPH_CHAR (g
);
4981 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
4987 /* Merge the escape-glyph face into the current face. */
4988 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
4993 XSETINT (it
->ctl_chars
[0], g
);
4995 XSETINT (it
->ctl_chars
[1], g
);
4997 goto display_control
;
5001 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5002 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5004 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5005 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5008 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5009 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5015 /* Merge the escape-glyph face into the current face. */
5016 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5018 escape_glyph
= '\\';
5021 if (it
->c
== 0x8a0 || it
->c
== 0x8ad)
5023 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5024 g
= it
->c
== 0x8ad ? '-' : ' ';
5025 XSETINT (it
->ctl_chars
[1], g
);
5027 goto display_control
;
5031 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5035 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5036 if (SINGLE_BYTE_CHAR_P (it
->c
))
5037 str
[0] = it
->c
, len
= 1;
5040 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5043 /* It's an invalid character, which shouldn't
5044 happen actually, but due to bugs it may
5045 happen. Let's print the char as is, there's
5046 not much meaningful we can do with it. */
5048 str
[1] = it
->c
>> 8;
5049 str
[2] = it
->c
>> 16;
5050 str
[3] = it
->c
>> 24;
5055 for (i
= 0; i
< len
; i
++)
5057 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5058 /* Insert three more glyphs into IT->ctl_chars for
5059 the octal display of the character. */
5060 g
= ((str
[i
] >> 6) & 7) + '0';
5061 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5062 g
= ((str
[i
] >> 3) & 7) + '0';
5063 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5064 g
= (str
[i
] & 7) + '0';
5065 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5071 /* Set up IT->dpvec and return first character from it. */
5072 it
->dpvec_char_len
= it
->len
;
5073 it
->dpvec
= it
->ctl_chars
;
5074 it
->dpend
= it
->dpvec
+ ctl_len
;
5075 it
->current
.dpvec_index
= 0;
5076 it
->dpvec_face_id
= face_id
;
5077 it
->saved_face_id
= it
->face_id
;
5078 it
->method
= next_element_from_display_vector
;
5084 /* Adjust face id for a multibyte character. There are no
5085 multibyte character in unibyte text. */
5088 && FRAME_WINDOW_P (it
->f
))
5090 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5091 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5095 /* Is this character the last one of a run of characters with
5096 box? If yes, set IT->end_of_box_run_p to 1. */
5103 it
->end_of_box_run_p
5104 = ((face_id
= face_after_it_pos (it
),
5105 face_id
!= it
->face_id
)
5106 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5107 face
->box
== FACE_NO_BOX
));
5110 /* Value is 0 if end of buffer or string reached. */
5115 /* Move IT to the next display element.
5117 RESEAT_P non-zero means if called on a newline in buffer text,
5118 skip to the next visible line start.
5120 Functions get_next_display_element and set_iterator_to_next are
5121 separate because I find this arrangement easier to handle than a
5122 get_next_display_element function that also increments IT's
5123 position. The way it is we can first look at an iterator's current
5124 display element, decide whether it fits on a line, and if it does,
5125 increment the iterator position. The other way around we probably
5126 would either need a flag indicating whether the iterator has to be
5127 incremented the next time, or we would have to implement a
5128 decrement position function which would not be easy to write. */
5131 set_iterator_to_next (it
, reseat_p
)
5135 /* Reset flags indicating start and end of a sequence of characters
5136 with box. Reset them at the start of this function because
5137 moving the iterator to a new position might set them. */
5138 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5140 if (it
->method
== next_element_from_buffer
)
5142 /* The current display element of IT is a character from
5143 current_buffer. Advance in the buffer, and maybe skip over
5144 invisible lines that are so because of selective display. */
5145 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5146 reseat_at_next_visible_line_start (it
, 0);
5149 xassert (it
->len
!= 0);
5150 IT_BYTEPOS (*it
) += it
->len
;
5151 IT_CHARPOS (*it
) += 1;
5152 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5155 else if (it
->method
== next_element_from_composition
)
5157 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5158 if (STRINGP (it
->string
))
5160 IT_STRING_BYTEPOS (*it
) += it
->len
;
5161 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5162 it
->method
= next_element_from_string
;
5163 goto consider_string_end
;
5167 IT_BYTEPOS (*it
) += it
->len
;
5168 IT_CHARPOS (*it
) += it
->cmp_len
;
5169 it
->method
= next_element_from_buffer
;
5172 else if (it
->method
== next_element_from_c_string
)
5174 /* Current display element of IT is from a C string. */
5175 IT_BYTEPOS (*it
) += it
->len
;
5176 IT_CHARPOS (*it
) += 1;
5178 else if (it
->method
== next_element_from_display_vector
)
5180 /* Current display element of IT is from a display table entry.
5181 Advance in the display table definition. Reset it to null if
5182 end reached, and continue with characters from buffers/
5184 ++it
->current
.dpvec_index
;
5186 /* Restore face of the iterator to what they were before the
5187 display vector entry (these entries may contain faces). */
5188 it
->face_id
= it
->saved_face_id
;
5190 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5193 it
->method
= next_element_from_c_string
;
5194 else if (STRINGP (it
->string
))
5195 it
->method
= next_element_from_string
;
5197 it
->method
= next_element_from_buffer
;
5200 it
->current
.dpvec_index
= -1;
5202 /* Skip over characters which were displayed via IT->dpvec. */
5203 if (it
->dpvec_char_len
< 0)
5204 reseat_at_next_visible_line_start (it
, 1);
5205 else if (it
->dpvec_char_len
> 0)
5207 it
->len
= it
->dpvec_char_len
;
5208 set_iterator_to_next (it
, reseat_p
);
5211 /* Recheck faces after display vector */
5212 it
->stop_charpos
= IT_CHARPOS (*it
);
5215 else if (it
->method
== next_element_from_string
)
5217 /* Current display element is a character from a Lisp string. */
5218 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5219 IT_STRING_BYTEPOS (*it
) += it
->len
;
5220 IT_STRING_CHARPOS (*it
) += 1;
5222 consider_string_end
:
5224 if (it
->current
.overlay_string_index
>= 0)
5226 /* IT->string is an overlay string. Advance to the
5227 next, if there is one. */
5228 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5229 next_overlay_string (it
);
5233 /* IT->string is not an overlay string. If we reached
5234 its end, and there is something on IT->stack, proceed
5235 with what is on the stack. This can be either another
5236 string, this time an overlay string, or a buffer. */
5237 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5241 if (!STRINGP (it
->string
))
5242 it
->method
= next_element_from_buffer
;
5244 goto consider_string_end
;
5248 else if (it
->method
== next_element_from_image
5249 || it
->method
== next_element_from_stretch
)
5251 /* The position etc with which we have to proceed are on
5252 the stack. The position may be at the end of a string,
5253 if the `display' property takes up the whole string. */
5256 if (STRINGP (it
->string
))
5258 it
->method
= next_element_from_string
;
5259 goto consider_string_end
;
5262 it
->method
= next_element_from_buffer
;
5265 /* There are no other methods defined, so this should be a bug. */
5268 xassert (it
->method
!= next_element_from_string
5269 || (STRINGP (it
->string
)
5270 && IT_STRING_CHARPOS (*it
) >= 0));
5273 /* Load IT's display element fields with information about the next
5274 display element which comes from a display table entry or from the
5275 result of translating a control character to one of the forms `^C'
5278 IT->dpvec holds the glyphs to return as characters.
5279 IT->saved_face_id holds the face id before the display vector--
5280 it is restored into IT->face_idin set_iterator_to_next. */
5283 next_element_from_display_vector (it
)
5287 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5289 if (INTEGERP (*it
->dpvec
)
5290 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5294 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5295 it
->c
= FAST_GLYPH_CHAR (g
);
5296 it
->len
= CHAR_BYTES (it
->c
);
5298 /* The entry may contain a face id to use. Such a face id is
5299 the id of a Lisp face, not a realized face. A face id of
5300 zero means no face is specified. */
5301 if (it
->dpvec_face_id
>= 0)
5302 it
->face_id
= it
->dpvec_face_id
;
5305 int lface_id
= FAST_GLYPH_FACE (g
);
5307 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5312 /* Display table entry is invalid. Return a space. */
5313 it
->c
= ' ', it
->len
= 1;
5315 /* Don't change position and object of the iterator here. They are
5316 still the values of the character that had this display table
5317 entry or was translated, and that's what we want. */
5318 it
->what
= IT_CHARACTER
;
5323 /* Load IT with the next display element from Lisp string IT->string.
5324 IT->current.string_pos is the current position within the string.
5325 If IT->current.overlay_string_index >= 0, the Lisp string is an
5329 next_element_from_string (it
)
5332 struct text_pos position
;
5334 xassert (STRINGP (it
->string
));
5335 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5336 position
= it
->current
.string_pos
;
5338 /* Time to check for invisible text? */
5339 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5340 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5344 /* Since a handler may have changed IT->method, we must
5346 return get_next_display_element (it
);
5349 if (it
->current
.overlay_string_index
>= 0)
5351 /* Get the next character from an overlay string. In overlay
5352 strings, There is no field width or padding with spaces to
5354 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5359 else if (STRING_MULTIBYTE (it
->string
))
5361 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5362 const unsigned char *s
= (SDATA (it
->string
)
5363 + IT_STRING_BYTEPOS (*it
));
5364 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5368 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5374 /* Get the next character from a Lisp string that is not an
5375 overlay string. Such strings come from the mode line, for
5376 example. We may have to pad with spaces, or truncate the
5377 string. See also next_element_from_c_string. */
5378 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5383 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5385 /* Pad with spaces. */
5386 it
->c
= ' ', it
->len
= 1;
5387 CHARPOS (position
) = BYTEPOS (position
) = -1;
5389 else if (STRING_MULTIBYTE (it
->string
))
5391 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5392 const unsigned char *s
= (SDATA (it
->string
)
5393 + IT_STRING_BYTEPOS (*it
));
5394 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5398 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5403 /* Record what we have and where it came from. Note that we store a
5404 buffer position in IT->position although it could arguably be a
5406 it
->what
= IT_CHARACTER
;
5407 it
->object
= it
->string
;
5408 it
->position
= position
;
5413 /* Load IT with next display element from C string IT->s.
5414 IT->string_nchars is the maximum number of characters to return
5415 from the string. IT->end_charpos may be greater than
5416 IT->string_nchars when this function is called, in which case we
5417 may have to return padding spaces. Value is zero if end of string
5418 reached, including padding spaces. */
5421 next_element_from_c_string (it
)
5427 it
->what
= IT_CHARACTER
;
5428 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5431 /* IT's position can be greater IT->string_nchars in case a field
5432 width or precision has been specified when the iterator was
5434 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5436 /* End of the game. */
5440 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5442 /* Pad with spaces. */
5443 it
->c
= ' ', it
->len
= 1;
5444 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5446 else if (it
->multibyte_p
)
5448 /* Implementation note: The calls to strlen apparently aren't a
5449 performance problem because there is no noticeable performance
5450 difference between Emacs running in unibyte or multibyte mode. */
5451 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5452 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5456 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5462 /* Set up IT to return characters from an ellipsis, if appropriate.
5463 The definition of the ellipsis glyphs may come from a display table
5464 entry. This function Fills IT with the first glyph from the
5465 ellipsis if an ellipsis is to be displayed. */
5468 next_element_from_ellipsis (it
)
5471 if (it
->selective_display_ellipsis_p
)
5472 setup_for_ellipsis (it
, it
->len
);
5475 /* The face at the current position may be different from the
5476 face we find after the invisible text. Remember what it
5477 was in IT->saved_face_id, and signal that it's there by
5478 setting face_before_selective_p. */
5479 it
->saved_face_id
= it
->face_id
;
5480 it
->method
= next_element_from_buffer
;
5481 reseat_at_next_visible_line_start (it
, 1);
5482 it
->face_before_selective_p
= 1;
5485 return get_next_display_element (it
);
5489 /* Deliver an image display element. The iterator IT is already
5490 filled with image information (done in handle_display_prop). Value
5495 next_element_from_image (it
)
5498 it
->what
= IT_IMAGE
;
5503 /* Fill iterator IT with next display element from a stretch glyph
5504 property. IT->object is the value of the text property. Value is
5508 next_element_from_stretch (it
)
5511 it
->what
= IT_STRETCH
;
5516 /* Load IT with the next display element from current_buffer. Value
5517 is zero if end of buffer reached. IT->stop_charpos is the next
5518 position at which to stop and check for text properties or buffer
5522 next_element_from_buffer (it
)
5527 /* Check this assumption, otherwise, we would never enter the
5528 if-statement, below. */
5529 xassert (IT_CHARPOS (*it
) >= BEGV
5530 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5532 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5534 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5536 int overlay_strings_follow_p
;
5538 /* End of the game, except when overlay strings follow that
5539 haven't been returned yet. */
5540 if (it
->overlay_strings_at_end_processed_p
)
5541 overlay_strings_follow_p
= 0;
5544 it
->overlay_strings_at_end_processed_p
= 1;
5545 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5548 if (overlay_strings_follow_p
)
5549 success_p
= get_next_display_element (it
);
5553 it
->position
= it
->current
.pos
;
5560 return get_next_display_element (it
);
5565 /* No face changes, overlays etc. in sight, so just return a
5566 character from current_buffer. */
5569 /* Maybe run the redisplay end trigger hook. Performance note:
5570 This doesn't seem to cost measurable time. */
5571 if (it
->redisplay_end_trigger_charpos
5573 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5574 run_redisplay_end_trigger_hook (it
);
5576 /* Get the next character, maybe multibyte. */
5577 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5578 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5580 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5581 - IT_BYTEPOS (*it
));
5582 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5585 it
->c
= *p
, it
->len
= 1;
5587 /* Record what we have and where it came from. */
5588 it
->what
= IT_CHARACTER
;;
5589 it
->object
= it
->w
->buffer
;
5590 it
->position
= it
->current
.pos
;
5592 /* Normally we return the character found above, except when we
5593 really want to return an ellipsis for selective display. */
5598 /* A value of selective > 0 means hide lines indented more
5599 than that number of columns. */
5600 if (it
->selective
> 0
5601 && IT_CHARPOS (*it
) + 1 < ZV
5602 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5603 IT_BYTEPOS (*it
) + 1,
5604 (double) it
->selective
)) /* iftc */
5606 success_p
= next_element_from_ellipsis (it
);
5607 it
->dpvec_char_len
= -1;
5610 else if (it
->c
== '\r' && it
->selective
== -1)
5612 /* A value of selective == -1 means that everything from the
5613 CR to the end of the line is invisible, with maybe an
5614 ellipsis displayed for it. */
5615 success_p
= next_element_from_ellipsis (it
);
5616 it
->dpvec_char_len
= -1;
5621 /* Value is zero if end of buffer reached. */
5622 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5627 /* Run the redisplay end trigger hook for IT. */
5630 run_redisplay_end_trigger_hook (it
)
5633 Lisp_Object args
[3];
5635 /* IT->glyph_row should be non-null, i.e. we should be actually
5636 displaying something, or otherwise we should not run the hook. */
5637 xassert (it
->glyph_row
);
5639 /* Set up hook arguments. */
5640 args
[0] = Qredisplay_end_trigger_functions
;
5641 args
[1] = it
->window
;
5642 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5643 it
->redisplay_end_trigger_charpos
= 0;
5645 /* Since we are *trying* to run these functions, don't try to run
5646 them again, even if they get an error. */
5647 it
->w
->redisplay_end_trigger
= Qnil
;
5648 Frun_hook_with_args (3, args
);
5650 /* Notice if it changed the face of the character we are on. */
5651 handle_face_prop (it
);
5655 /* Deliver a composition display element. The iterator IT is already
5656 filled with composition information (done in
5657 handle_composition_prop). Value is always 1. */
5660 next_element_from_composition (it
)
5663 it
->what
= IT_COMPOSITION
;
5664 it
->position
= (STRINGP (it
->string
)
5665 ? it
->current
.string_pos
5672 /***********************************************************************
5673 Moving an iterator without producing glyphs
5674 ***********************************************************************/
5676 /* Move iterator IT to a specified buffer or X position within one
5677 line on the display without producing glyphs.
5679 OP should be a bit mask including some or all of these bits:
5680 MOVE_TO_X: Stop on reaching x-position TO_X.
5681 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5682 Regardless of OP's value, stop in reaching the end of the display line.
5684 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5685 This means, in particular, that TO_X includes window's horizontal
5688 The return value has several possible values that
5689 say what condition caused the scan to stop:
5691 MOVE_POS_MATCH_OR_ZV
5692 - when TO_POS or ZV was reached.
5695 -when TO_X was reached before TO_POS or ZV were reached.
5698 - when we reached the end of the display area and the line must
5702 - when we reached the end of the display area and the line is
5706 - when we stopped at a line end, i.e. a newline or a CR and selective
5709 static enum move_it_result
5710 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5712 int to_charpos
, to_x
, op
;
5714 enum move_it_result result
= MOVE_UNDEFINED
;
5715 struct glyph_row
*saved_glyph_row
;
5717 /* Don't produce glyphs in produce_glyphs. */
5718 saved_glyph_row
= it
->glyph_row
;
5719 it
->glyph_row
= NULL
;
5721 #define BUFFER_POS_REACHED_P() \
5722 ((op & MOVE_TO_POS) != 0 \
5723 && BUFFERP (it->object) \
5724 && IT_CHARPOS (*it) >= to_charpos \
5725 && it->method == next_element_from_buffer)
5729 int x
, i
, ascent
= 0, descent
= 0;
5731 /* Stop when ZV reached.
5732 We used to stop here when TO_CHARPOS reached as well, but that is
5733 too soon if this glyph does not fit on this line. So we handle it
5734 explicitly below. */
5735 if (!get_next_display_element (it
)
5736 || (it
->truncate_lines_p
5737 && BUFFER_POS_REACHED_P ()))
5739 result
= MOVE_POS_MATCH_OR_ZV
;
5743 /* The call to produce_glyphs will get the metrics of the
5744 display element IT is loaded with. We record in x the
5745 x-position before this display element in case it does not
5749 /* Remember the line height so far in case the next element doesn't
5751 if (!it
->truncate_lines_p
)
5753 ascent
= it
->max_ascent
;
5754 descent
= it
->max_descent
;
5757 PRODUCE_GLYPHS (it
);
5759 if (it
->area
!= TEXT_AREA
)
5761 set_iterator_to_next (it
, 1);
5765 /* The number of glyphs we get back in IT->nglyphs will normally
5766 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5767 character on a terminal frame, or (iii) a line end. For the
5768 second case, IT->nglyphs - 1 padding glyphs will be present
5769 (on X frames, there is only one glyph produced for a
5770 composite character.
5772 The behavior implemented below means, for continuation lines,
5773 that as many spaces of a TAB as fit on the current line are
5774 displayed there. For terminal frames, as many glyphs of a
5775 multi-glyph character are displayed in the current line, too.
5776 This is what the old redisplay code did, and we keep it that
5777 way. Under X, the whole shape of a complex character must
5778 fit on the line or it will be completely displayed in the
5781 Note that both for tabs and padding glyphs, all glyphs have
5785 /* More than one glyph or glyph doesn't fit on line. All
5786 glyphs have the same width. */
5787 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5790 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5792 new_x
= x
+ single_glyph_width
;
5794 /* We want to leave anything reaching TO_X to the caller. */
5795 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5797 if (BUFFER_POS_REACHED_P ())
5798 goto buffer_pos_reached
;
5800 result
= MOVE_X_REACHED
;
5803 else if (/* Lines are continued. */
5804 !it
->truncate_lines_p
5805 && (/* And glyph doesn't fit on the line. */
5806 new_x
> it
->last_visible_x
5807 /* Or it fits exactly and we're on a window
5809 || (new_x
== it
->last_visible_x
5810 && FRAME_WINDOW_P (it
->f
))))
5812 if (/* IT->hpos == 0 means the very first glyph
5813 doesn't fit on the line, e.g. a wide image. */
5815 || (new_x
== it
->last_visible_x
5816 && FRAME_WINDOW_P (it
->f
)))
5819 it
->current_x
= new_x
;
5820 if (i
== it
->nglyphs
- 1)
5822 set_iterator_to_next (it
, 1);
5823 #ifdef HAVE_WINDOW_SYSTEM
5824 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5826 if (!get_next_display_element (it
))
5828 result
= MOVE_POS_MATCH_OR_ZV
;
5831 if (BUFFER_POS_REACHED_P ())
5833 if (ITERATOR_AT_END_OF_LINE_P (it
))
5834 result
= MOVE_POS_MATCH_OR_ZV
;
5836 result
= MOVE_LINE_CONTINUED
;
5839 if (ITERATOR_AT_END_OF_LINE_P (it
))
5841 result
= MOVE_NEWLINE_OR_CR
;
5845 #endif /* HAVE_WINDOW_SYSTEM */
5851 it
->max_ascent
= ascent
;
5852 it
->max_descent
= descent
;
5855 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5857 result
= MOVE_LINE_CONTINUED
;
5860 else if (BUFFER_POS_REACHED_P ())
5861 goto buffer_pos_reached
;
5862 else if (new_x
> it
->first_visible_x
)
5864 /* Glyph is visible. Increment number of glyphs that
5865 would be displayed. */
5870 /* Glyph is completely off the left margin of the display
5871 area. Nothing to do. */
5875 if (result
!= MOVE_UNDEFINED
)
5878 else if (BUFFER_POS_REACHED_P ())
5882 it
->max_ascent
= ascent
;
5883 it
->max_descent
= descent
;
5884 result
= MOVE_POS_MATCH_OR_ZV
;
5887 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5889 /* Stop when TO_X specified and reached. This check is
5890 necessary here because of lines consisting of a line end,
5891 only. The line end will not produce any glyphs and we
5892 would never get MOVE_X_REACHED. */
5893 xassert (it
->nglyphs
== 0);
5894 result
= MOVE_X_REACHED
;
5898 /* Is this a line end? If yes, we're done. */
5899 if (ITERATOR_AT_END_OF_LINE_P (it
))
5901 result
= MOVE_NEWLINE_OR_CR
;
5905 /* The current display element has been consumed. Advance
5907 set_iterator_to_next (it
, 1);
5909 /* Stop if lines are truncated and IT's current x-position is
5910 past the right edge of the window now. */
5911 if (it
->truncate_lines_p
5912 && it
->current_x
>= it
->last_visible_x
)
5914 #ifdef HAVE_WINDOW_SYSTEM
5915 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5917 if (!get_next_display_element (it
)
5918 || BUFFER_POS_REACHED_P ())
5920 result
= MOVE_POS_MATCH_OR_ZV
;
5923 if (ITERATOR_AT_END_OF_LINE_P (it
))
5925 result
= MOVE_NEWLINE_OR_CR
;
5929 #endif /* HAVE_WINDOW_SYSTEM */
5930 result
= MOVE_LINE_TRUNCATED
;
5935 #undef BUFFER_POS_REACHED_P
5937 /* Restore the iterator settings altered at the beginning of this
5939 it
->glyph_row
= saved_glyph_row
;
5944 /* Move IT forward until it satisfies one or more of the criteria in
5945 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5947 OP is a bit-mask that specifies where to stop, and in particular,
5948 which of those four position arguments makes a difference. See the
5949 description of enum move_operation_enum.
5951 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5952 screen line, this function will set IT to the next position >
5956 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5958 int to_charpos
, to_x
, to_y
, to_vpos
;
5961 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5967 if (op
& MOVE_TO_VPOS
)
5969 /* If no TO_CHARPOS and no TO_X specified, stop at the
5970 start of the line TO_VPOS. */
5971 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5973 if (it
->vpos
== to_vpos
)
5979 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5983 /* TO_VPOS >= 0 means stop at TO_X in the line at
5984 TO_VPOS, or at TO_POS, whichever comes first. */
5985 if (it
->vpos
== to_vpos
)
5991 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5993 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5998 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6000 /* We have reached TO_X but not in the line we want. */
6001 skip
= move_it_in_display_line_to (it
, to_charpos
,
6003 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6011 else if (op
& MOVE_TO_Y
)
6013 struct it it_backup
;
6015 /* TO_Y specified means stop at TO_X in the line containing
6016 TO_Y---or at TO_CHARPOS if this is reached first. The
6017 problem is that we can't really tell whether the line
6018 contains TO_Y before we have completely scanned it, and
6019 this may skip past TO_X. What we do is to first scan to
6022 If TO_X is not specified, use a TO_X of zero. The reason
6023 is to make the outcome of this function more predictable.
6024 If we didn't use TO_X == 0, we would stop at the end of
6025 the line which is probably not what a caller would expect
6027 skip
= move_it_in_display_line_to (it
, to_charpos
,
6031 | (op
& MOVE_TO_POS
)));
6033 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6034 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6040 /* If TO_X was reached, we would like to know whether TO_Y
6041 is in the line. This can only be said if we know the
6042 total line height which requires us to scan the rest of
6044 if (skip
== MOVE_X_REACHED
)
6047 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6048 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6050 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6053 /* Now, decide whether TO_Y is in this line. */
6054 line_height
= it
->max_ascent
+ it
->max_descent
;
6055 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6057 if (to_y
>= it
->current_y
6058 && to_y
< it
->current_y
+ line_height
)
6060 if (skip
== MOVE_X_REACHED
)
6061 /* If TO_Y is in this line and TO_X was reached above,
6062 we scanned too far. We have to restore IT's settings
6063 to the ones before skipping. */
6067 else if (skip
== MOVE_X_REACHED
)
6070 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6078 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6082 case MOVE_POS_MATCH_OR_ZV
:
6086 case MOVE_NEWLINE_OR_CR
:
6087 set_iterator_to_next (it
, 1);
6088 it
->continuation_lines_width
= 0;
6091 case MOVE_LINE_TRUNCATED
:
6092 it
->continuation_lines_width
= 0;
6093 reseat_at_next_visible_line_start (it
, 0);
6094 if ((op
& MOVE_TO_POS
) != 0
6095 && IT_CHARPOS (*it
) > to_charpos
)
6102 case MOVE_LINE_CONTINUED
:
6103 it
->continuation_lines_width
+= it
->current_x
;
6110 /* Reset/increment for the next run. */
6111 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6112 it
->current_x
= it
->hpos
= 0;
6113 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6115 last_height
= it
->max_ascent
+ it
->max_descent
;
6116 last_max_ascent
= it
->max_ascent
;
6117 it
->max_ascent
= it
->max_descent
= 0;
6122 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6126 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6128 If DY > 0, move IT backward at least that many pixels. DY = 0
6129 means move IT backward to the preceding line start or BEGV. This
6130 function may move over more than DY pixels if IT->current_y - DY
6131 ends up in the middle of a line; in this case IT->current_y will be
6132 set to the top of the line moved to. */
6135 move_it_vertically_backward (it
, dy
)
6146 start_pos
= IT_CHARPOS (*it
);
6148 /* Estimate how many newlines we must move back. */
6149 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6151 /* Set the iterator's position that many lines back. */
6152 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6153 back_to_previous_visible_line_start (it
);
6155 /* Reseat the iterator here. When moving backward, we don't want
6156 reseat to skip forward over invisible text, set up the iterator
6157 to deliver from overlay strings at the new position etc. So,
6158 use reseat_1 here. */
6159 reseat_1 (it
, it
->current
.pos
, 1);
6161 /* We are now surely at a line start. */
6162 it
->current_x
= it
->hpos
= 0;
6163 it
->continuation_lines_width
= 0;
6165 /* Move forward and see what y-distance we moved. First move to the
6166 start of the next line so that we get its height. We need this
6167 height to be able to tell whether we reached the specified
6170 it2
.max_ascent
= it2
.max_descent
= 0;
6171 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6172 MOVE_TO_POS
| MOVE_TO_VPOS
);
6173 xassert (IT_CHARPOS (*it
) >= BEGV
);
6176 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6177 xassert (IT_CHARPOS (*it
) >= BEGV
);
6178 /* H is the actual vertical distance from the position in *IT
6179 and the starting position. */
6180 h
= it2
.current_y
- it
->current_y
;
6181 /* NLINES is the distance in number of lines. */
6182 nlines
= it2
.vpos
- it
->vpos
;
6184 /* Correct IT's y and vpos position
6185 so that they are relative to the starting point. */
6191 /* DY == 0 means move to the start of the screen line. The
6192 value of nlines is > 0 if continuation lines were involved. */
6194 move_it_by_lines (it
, nlines
, 1);
6195 xassert (IT_CHARPOS (*it
) <= start_pos
);
6199 /* The y-position we try to reach, relative to *IT.
6200 Note that H has been subtracted in front of the if-statement. */
6201 int target_y
= it
->current_y
+ h
- dy
;
6202 int y0
= it3
.current_y
;
6203 int y1
= line_bottom_y (&it3
);
6204 int line_height
= y1
- y0
;
6206 /* If we did not reach target_y, try to move further backward if
6207 we can. If we moved too far backward, try to move forward. */
6208 if (target_y
< it
->current_y
6209 /* This is heuristic. In a window that's 3 lines high, with
6210 a line height of 13 pixels each, recentering with point
6211 on the bottom line will try to move -39/2 = 19 pixels
6212 backward. Try to avoid moving into the first line. */
6213 && it
->current_y
- target_y
> line_height
* 2 / 3
6214 && IT_CHARPOS (*it
) > BEGV
)
6216 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6217 target_y
- it
->current_y
));
6218 dy
= it
->current_y
- target_y
;
6219 goto move_further_back
;
6221 else if (target_y
>= it
->current_y
+ line_height
6222 && IT_CHARPOS (*it
) < ZV
)
6224 /* Should move forward by at least one line, maybe more.
6226 Note: Calling move_it_by_lines can be expensive on
6227 terminal frames, where compute_motion is used (via
6228 vmotion) to do the job, when there are very long lines
6229 and truncate-lines is nil. That's the reason for
6230 treating terminal frames specially here. */
6232 if (!FRAME_WINDOW_P (it
->f
))
6233 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6238 move_it_by_lines (it
, 1, 1);
6240 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6243 xassert (IT_CHARPOS (*it
) >= BEGV
);
6249 /* Move IT by a specified amount of pixel lines DY. DY negative means
6250 move backwards. DY = 0 means move to start of screen line. At the
6251 end, IT will be on the start of a screen line. */
6254 move_it_vertically (it
, dy
)
6259 move_it_vertically_backward (it
, -dy
);
6262 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6263 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6264 MOVE_TO_POS
| MOVE_TO_Y
);
6265 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6267 /* If buffer ends in ZV without a newline, move to the start of
6268 the line to satisfy the post-condition. */
6269 if (IT_CHARPOS (*it
) == ZV
6270 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6271 move_it_by_lines (it
, 0, 0);
6276 /* Move iterator IT past the end of the text line it is in. */
6279 move_it_past_eol (it
)
6282 enum move_it_result rc
;
6284 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6285 if (rc
== MOVE_NEWLINE_OR_CR
)
6286 set_iterator_to_next (it
, 0);
6290 #if 0 /* Currently not used. */
6292 /* Return non-zero if some text between buffer positions START_CHARPOS
6293 and END_CHARPOS is invisible. IT->window is the window for text
6297 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6299 int start_charpos
, end_charpos
;
6301 Lisp_Object prop
, limit
;
6302 int invisible_found_p
;
6304 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6306 /* Is text at START invisible? */
6307 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6309 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6310 invisible_found_p
= 1;
6313 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6315 make_number (end_charpos
));
6316 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6319 return invisible_found_p
;
6325 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6326 negative means move up. DVPOS == 0 means move to the start of the
6327 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6328 NEED_Y_P is zero, IT->current_y will be left unchanged.
6330 Further optimization ideas: If we would know that IT->f doesn't use
6331 a face with proportional font, we could be faster for
6332 truncate-lines nil. */
6335 move_it_by_lines (it
, dvpos
, need_y_p
)
6337 int dvpos
, need_y_p
;
6339 struct position pos
;
6341 if (!FRAME_WINDOW_P (it
->f
))
6343 struct text_pos textpos
;
6345 /* We can use vmotion on frames without proportional fonts. */
6346 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6347 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6348 reseat (it
, textpos
, 1);
6349 it
->vpos
+= pos
.vpos
;
6350 it
->current_y
+= pos
.vpos
;
6352 else if (dvpos
== 0)
6354 /* DVPOS == 0 means move to the start of the screen line. */
6355 move_it_vertically_backward (it
, 0);
6356 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6357 /* Let next call to line_bottom_y calculate real line height */
6361 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6365 int start_charpos
, i
;
6367 /* Start at the beginning of the screen line containing IT's
6369 move_it_vertically_backward (it
, 0);
6371 /* Go back -DVPOS visible lines and reseat the iterator there. */
6372 start_charpos
= IT_CHARPOS (*it
);
6373 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6374 back_to_previous_visible_line_start (it
);
6375 reseat (it
, it
->current
.pos
, 1);
6376 it
->current_x
= it
->hpos
= 0;
6378 /* Above call may have moved too far if continuation lines
6379 are involved. Scan forward and see if it did. */
6381 it2
.vpos
= it2
.current_y
= 0;
6382 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6383 it
->vpos
-= it2
.vpos
;
6384 it
->current_y
-= it2
.current_y
;
6385 it
->current_x
= it
->hpos
= 0;
6387 /* If we moved too far, move IT some lines forward. */
6388 if (it2
.vpos
> -dvpos
)
6390 int delta
= it2
.vpos
+ dvpos
;
6391 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6396 /* Return 1 if IT points into the middle of a display vector. */
6399 in_display_vector_p (it
)
6402 return (it
->method
== next_element_from_display_vector
6403 && it
->current
.dpvec_index
> 0
6404 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6408 /***********************************************************************
6410 ***********************************************************************/
6413 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6417 add_to_log (format
, arg1
, arg2
)
6419 Lisp_Object arg1
, arg2
;
6421 Lisp_Object args
[3];
6422 Lisp_Object msg
, fmt
;
6425 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6428 /* Do nothing if called asynchronously. Inserting text into
6429 a buffer may call after-change-functions and alike and
6430 that would means running Lisp asynchronously. */
6431 if (handling_signal
)
6435 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6437 args
[0] = fmt
= build_string (format
);
6440 msg
= Fformat (3, args
);
6442 len
= SBYTES (msg
) + 1;
6443 SAFE_ALLOCA (buffer
, char *, len
);
6444 bcopy (SDATA (msg
), buffer
, len
);
6446 message_dolog (buffer
, len
- 1, 1, 0);
6453 /* Output a newline in the *Messages* buffer if "needs" one. */
6456 message_log_maybe_newline ()
6458 if (message_log_need_newline
)
6459 message_dolog ("", 0, 1, 0);
6463 /* Add a string M of length NBYTES to the message log, optionally
6464 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6465 nonzero, means interpret the contents of M as multibyte. This
6466 function calls low-level routines in order to bypass text property
6467 hooks, etc. which might not be safe to run. */
6470 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6472 int nbytes
, nlflag
, multibyte
;
6474 if (!NILP (Vmemory_full
))
6477 if (!NILP (Vmessage_log_max
))
6479 struct buffer
*oldbuf
;
6480 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6481 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6482 int point_at_end
= 0;
6484 Lisp_Object old_deactivate_mark
, tem
;
6485 struct gcpro gcpro1
;
6487 old_deactivate_mark
= Vdeactivate_mark
;
6488 oldbuf
= current_buffer
;
6489 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6490 current_buffer
->undo_list
= Qt
;
6492 oldpoint
= message_dolog_marker1
;
6493 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6494 oldbegv
= message_dolog_marker2
;
6495 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6496 oldzv
= message_dolog_marker3
;
6497 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6498 GCPRO1 (old_deactivate_mark
);
6506 BEGV_BYTE
= BEG_BYTE
;
6509 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6511 /* Insert the string--maybe converting multibyte to single byte
6512 or vice versa, so that all the text fits the buffer. */
6514 && NILP (current_buffer
->enable_multibyte_characters
))
6516 int i
, c
, char_bytes
;
6517 unsigned char work
[1];
6519 /* Convert a multibyte string to single-byte
6520 for the *Message* buffer. */
6521 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6523 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6524 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6526 : multibyte_char_to_unibyte (c
, Qnil
));
6527 insert_1_both (work
, 1, 1, 1, 0, 0);
6530 else if (! multibyte
6531 && ! NILP (current_buffer
->enable_multibyte_characters
))
6533 int i
, c
, char_bytes
;
6534 unsigned char *msg
= (unsigned char *) m
;
6535 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6536 /* Convert a single-byte string to multibyte
6537 for the *Message* buffer. */
6538 for (i
= 0; i
< nbytes
; i
++)
6540 c
= unibyte_char_to_multibyte (msg
[i
]);
6541 char_bytes
= CHAR_STRING (c
, str
);
6542 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6546 insert_1 (m
, nbytes
, 1, 0, 0);
6550 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6551 insert_1 ("\n", 1, 1, 0, 0);
6553 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6555 this_bol_byte
= PT_BYTE
;
6557 /* See if this line duplicates the previous one.
6558 If so, combine duplicates. */
6561 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6563 prev_bol_byte
= PT_BYTE
;
6565 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6566 this_bol
, this_bol_byte
);
6569 del_range_both (prev_bol
, prev_bol_byte
,
6570 this_bol
, this_bol_byte
, 0);
6576 /* If you change this format, don't forget to also
6577 change message_log_check_duplicate. */
6578 sprintf (dupstr
, " [%d times]", dup
);
6579 duplen
= strlen (dupstr
);
6580 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6581 insert_1 (dupstr
, duplen
, 1, 0, 1);
6586 /* If we have more than the desired maximum number of lines
6587 in the *Messages* buffer now, delete the oldest ones.
6588 This is safe because we don't have undo in this buffer. */
6590 if (NATNUMP (Vmessage_log_max
))
6592 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6593 -XFASTINT (Vmessage_log_max
) - 1, 0);
6594 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6597 BEGV
= XMARKER (oldbegv
)->charpos
;
6598 BEGV_BYTE
= marker_byte_position (oldbegv
);
6607 ZV
= XMARKER (oldzv
)->charpos
;
6608 ZV_BYTE
= marker_byte_position (oldzv
);
6612 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6614 /* We can't do Fgoto_char (oldpoint) because it will run some
6616 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6617 XMARKER (oldpoint
)->bytepos
);
6620 unchain_marker (XMARKER (oldpoint
));
6621 unchain_marker (XMARKER (oldbegv
));
6622 unchain_marker (XMARKER (oldzv
));
6624 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6625 set_buffer_internal (oldbuf
);
6627 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6628 message_log_need_newline
= !nlflag
;
6629 Vdeactivate_mark
= old_deactivate_mark
;
6634 /* We are at the end of the buffer after just having inserted a newline.
6635 (Note: We depend on the fact we won't be crossing the gap.)
6636 Check to see if the most recent message looks a lot like the previous one.
6637 Return 0 if different, 1 if the new one should just replace it, or a
6638 value N > 1 if we should also append " [N times]". */
6641 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6642 int prev_bol
, this_bol
;
6643 int prev_bol_byte
, this_bol_byte
;
6646 int len
= Z_BYTE
- 1 - this_bol_byte
;
6648 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6649 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6651 for (i
= 0; i
< len
; i
++)
6653 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6661 if (*p1
++ == ' ' && *p1
++ == '[')
6664 while (*p1
>= '0' && *p1
<= '9')
6665 n
= n
* 10 + *p1
++ - '0';
6666 if (strncmp (p1
, " times]\n", 8) == 0)
6673 /* Display an echo area message M with a specified length of NBYTES
6674 bytes. The string may include null characters. If M is 0, clear
6675 out any existing message, and let the mini-buffer text show
6678 The buffer M must continue to exist until after the echo area gets
6679 cleared or some other message gets displayed there. This means do
6680 not pass text that is stored in a Lisp string; do not pass text in
6681 a buffer that was alloca'd. */
6684 message2 (m
, nbytes
, multibyte
)
6689 /* First flush out any partial line written with print. */
6690 message_log_maybe_newline ();
6692 message_dolog (m
, nbytes
, 1, multibyte
);
6693 message2_nolog (m
, nbytes
, multibyte
);
6697 /* The non-logging counterpart of message2. */
6700 message2_nolog (m
, nbytes
, multibyte
)
6702 int nbytes
, multibyte
;
6704 struct frame
*sf
= SELECTED_FRAME ();
6705 message_enable_multibyte
= multibyte
;
6709 if (noninteractive_need_newline
)
6710 putc ('\n', stderr
);
6711 noninteractive_need_newline
= 0;
6713 fwrite (m
, nbytes
, 1, stderr
);
6714 if (cursor_in_echo_area
== 0)
6715 fprintf (stderr
, "\n");
6718 /* A null message buffer means that the frame hasn't really been
6719 initialized yet. Error messages get reported properly by
6720 cmd_error, so this must be just an informative message; toss it. */
6721 else if (INTERACTIVE
6722 && sf
->glyphs_initialized_p
6723 && FRAME_MESSAGE_BUF (sf
))
6725 Lisp_Object mini_window
;
6728 /* Get the frame containing the mini-buffer
6729 that the selected frame is using. */
6730 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6731 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6733 FRAME_SAMPLE_VISIBILITY (f
);
6734 if (FRAME_VISIBLE_P (sf
)
6735 && ! FRAME_VISIBLE_P (f
))
6736 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6740 set_message (m
, Qnil
, nbytes
, multibyte
);
6741 if (minibuffer_auto_raise
)
6742 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6745 clear_message (1, 1);
6747 do_pending_window_change (0);
6748 echo_area_display (1);
6749 do_pending_window_change (0);
6750 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6751 (*frame_up_to_date_hook
) (f
);
6756 /* Display an echo area message M with a specified length of NBYTES
6757 bytes. The string may include null characters. If M is not a
6758 string, clear out any existing message, and let the mini-buffer
6759 text show through. */
6762 message3 (m
, nbytes
, multibyte
)
6767 struct gcpro gcpro1
;
6770 clear_message (1,1);
6772 /* First flush out any partial line written with print. */
6773 message_log_maybe_newline ();
6775 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6776 message3_nolog (m
, nbytes
, multibyte
);
6782 /* The non-logging version of message3. */
6785 message3_nolog (m
, nbytes
, multibyte
)
6787 int nbytes
, multibyte
;
6789 struct frame
*sf
= SELECTED_FRAME ();
6790 message_enable_multibyte
= multibyte
;
6794 if (noninteractive_need_newline
)
6795 putc ('\n', stderr
);
6796 noninteractive_need_newline
= 0;
6798 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6799 if (cursor_in_echo_area
== 0)
6800 fprintf (stderr
, "\n");
6803 /* A null message buffer means that the frame hasn't really been
6804 initialized yet. Error messages get reported properly by
6805 cmd_error, so this must be just an informative message; toss it. */
6806 else if (INTERACTIVE
6807 && sf
->glyphs_initialized_p
6808 && FRAME_MESSAGE_BUF (sf
))
6810 Lisp_Object mini_window
;
6814 /* Get the frame containing the mini-buffer
6815 that the selected frame is using. */
6816 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6817 frame
= XWINDOW (mini_window
)->frame
;
6820 FRAME_SAMPLE_VISIBILITY (f
);
6821 if (FRAME_VISIBLE_P (sf
)
6822 && !FRAME_VISIBLE_P (f
))
6823 Fmake_frame_visible (frame
);
6825 if (STRINGP (m
) && SCHARS (m
) > 0)
6827 set_message (NULL
, m
, nbytes
, multibyte
);
6828 if (minibuffer_auto_raise
)
6829 Fraise_frame (frame
);
6832 clear_message (1, 1);
6834 do_pending_window_change (0);
6835 echo_area_display (1);
6836 do_pending_window_change (0);
6837 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6838 (*frame_up_to_date_hook
) (f
);
6843 /* Display a null-terminated echo area message M. If M is 0, clear
6844 out any existing message, and let the mini-buffer text show through.
6846 The buffer M must continue to exist until after the echo area gets
6847 cleared or some other message gets displayed there. Do not pass
6848 text that is stored in a Lisp string. Do not pass text in a buffer
6849 that was alloca'd. */
6855 message2 (m
, (m
? strlen (m
) : 0), 0);
6859 /* The non-logging counterpart of message1. */
6865 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6868 /* Display a message M which contains a single %s
6869 which gets replaced with STRING. */
6872 message_with_string (m
, string
, log
)
6877 CHECK_STRING (string
);
6883 if (noninteractive_need_newline
)
6884 putc ('\n', stderr
);
6885 noninteractive_need_newline
= 0;
6886 fprintf (stderr
, m
, SDATA (string
));
6887 if (cursor_in_echo_area
== 0)
6888 fprintf (stderr
, "\n");
6892 else if (INTERACTIVE
)
6894 /* The frame whose minibuffer we're going to display the message on.
6895 It may be larger than the selected frame, so we need
6896 to use its buffer, not the selected frame's buffer. */
6897 Lisp_Object mini_window
;
6898 struct frame
*f
, *sf
= SELECTED_FRAME ();
6900 /* Get the frame containing the minibuffer
6901 that the selected frame is using. */
6902 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6903 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6905 /* A null message buffer means that the frame hasn't really been
6906 initialized yet. Error messages get reported properly by
6907 cmd_error, so this must be just an informative message; toss it. */
6908 if (FRAME_MESSAGE_BUF (f
))
6910 Lisp_Object args
[2], message
;
6911 struct gcpro gcpro1
, gcpro2
;
6913 args
[0] = build_string (m
);
6914 args
[1] = message
= string
;
6915 GCPRO2 (args
[0], message
);
6918 message
= Fformat (2, args
);
6921 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6923 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6927 /* Print should start at the beginning of the message
6928 buffer next time. */
6929 message_buf_print
= 0;
6935 /* Dump an informative message to the minibuf. If M is 0, clear out
6936 any existing message, and let the mini-buffer text show through. */
6940 message (m
, a1
, a2
, a3
)
6942 EMACS_INT a1
, a2
, a3
;
6948 if (noninteractive_need_newline
)
6949 putc ('\n', stderr
);
6950 noninteractive_need_newline
= 0;
6951 fprintf (stderr
, m
, a1
, a2
, a3
);
6952 if (cursor_in_echo_area
== 0)
6953 fprintf (stderr
, "\n");
6957 else if (INTERACTIVE
)
6959 /* The frame whose mini-buffer we're going to display the message
6960 on. It may be larger than the selected frame, so we need to
6961 use its buffer, not the selected frame's buffer. */
6962 Lisp_Object mini_window
;
6963 struct frame
*f
, *sf
= SELECTED_FRAME ();
6965 /* Get the frame containing the mini-buffer
6966 that the selected frame is using. */
6967 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6968 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6970 /* A null message buffer means that the frame hasn't really been
6971 initialized yet. Error messages get reported properly by
6972 cmd_error, so this must be just an informative message; toss
6974 if (FRAME_MESSAGE_BUF (f
))
6985 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6986 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6988 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6989 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6991 #endif /* NO_ARG_ARRAY */
6993 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6998 /* Print should start at the beginning of the message
6999 buffer next time. */
7000 message_buf_print
= 0;
7006 /* The non-logging version of message. */
7009 message_nolog (m
, a1
, a2
, a3
)
7011 EMACS_INT a1
, a2
, a3
;
7013 Lisp_Object old_log_max
;
7014 old_log_max
= Vmessage_log_max
;
7015 Vmessage_log_max
= Qnil
;
7016 message (m
, a1
, a2
, a3
);
7017 Vmessage_log_max
= old_log_max
;
7021 /* Display the current message in the current mini-buffer. This is
7022 only called from error handlers in process.c, and is not time
7028 if (!NILP (echo_area_buffer
[0]))
7031 string
= Fcurrent_message ();
7032 message3 (string
, SBYTES (string
),
7033 !NILP (current_buffer
->enable_multibyte_characters
));
7038 /* Make sure echo area buffers in `echo_buffers' are live.
7039 If they aren't, make new ones. */
7042 ensure_echo_area_buffers ()
7046 for (i
= 0; i
< 2; ++i
)
7047 if (!BUFFERP (echo_buffer
[i
])
7048 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7051 Lisp_Object old_buffer
;
7054 old_buffer
= echo_buffer
[i
];
7055 sprintf (name
, " *Echo Area %d*", i
);
7056 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7057 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7059 for (j
= 0; j
< 2; ++j
)
7060 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7061 echo_area_buffer
[j
] = echo_buffer
[i
];
7066 /* Call FN with args A1..A4 with either the current or last displayed
7067 echo_area_buffer as current buffer.
7069 WHICH zero means use the current message buffer
7070 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7071 from echo_buffer[] and clear it.
7073 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7074 suitable buffer from echo_buffer[] and clear it.
7076 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7077 that the current message becomes the last displayed one, make
7078 choose a suitable buffer for echo_area_buffer[0], and clear it.
7080 Value is what FN returns. */
7083 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7086 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7092 int this_one
, the_other
, clear_buffer_p
, rc
;
7093 int count
= SPECPDL_INDEX ();
7095 /* If buffers aren't live, make new ones. */
7096 ensure_echo_area_buffers ();
7101 this_one
= 0, the_other
= 1;
7103 this_one
= 1, the_other
= 0;
7106 this_one
= 0, the_other
= 1;
7109 /* We need a fresh one in case the current echo buffer equals
7110 the one containing the last displayed echo area message. */
7111 if (!NILP (echo_area_buffer
[this_one
])
7112 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7113 echo_area_buffer
[this_one
] = Qnil
;
7116 /* Choose a suitable buffer from echo_buffer[] is we don't
7118 if (NILP (echo_area_buffer
[this_one
]))
7120 echo_area_buffer
[this_one
]
7121 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7122 ? echo_buffer
[the_other
]
7123 : echo_buffer
[this_one
]);
7127 buffer
= echo_area_buffer
[this_one
];
7129 /* Don't get confused by reusing the buffer used for echoing
7130 for a different purpose. */
7131 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7134 record_unwind_protect (unwind_with_echo_area_buffer
,
7135 with_echo_area_buffer_unwind_data (w
));
7137 /* Make the echo area buffer current. Note that for display
7138 purposes, it is not necessary that the displayed window's buffer
7139 == current_buffer, except for text property lookup. So, let's
7140 only set that buffer temporarily here without doing a full
7141 Fset_window_buffer. We must also change w->pointm, though,
7142 because otherwise an assertions in unshow_buffer fails, and Emacs
7144 set_buffer_internal_1 (XBUFFER (buffer
));
7148 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7151 current_buffer
->undo_list
= Qt
;
7152 current_buffer
->read_only
= Qnil
;
7153 specbind (Qinhibit_read_only
, Qt
);
7154 specbind (Qinhibit_modification_hooks
, Qt
);
7156 if (clear_buffer_p
&& Z
> BEG
)
7159 xassert (BEGV
>= BEG
);
7160 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7162 rc
= fn (a1
, a2
, a3
, a4
);
7164 xassert (BEGV
>= BEG
);
7165 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7167 unbind_to (count
, Qnil
);
7172 /* Save state that should be preserved around the call to the function
7173 FN called in with_echo_area_buffer. */
7176 with_echo_area_buffer_unwind_data (w
)
7182 /* Reduce consing by keeping one vector in
7183 Vwith_echo_area_save_vector. */
7184 vector
= Vwith_echo_area_save_vector
;
7185 Vwith_echo_area_save_vector
= Qnil
;
7188 vector
= Fmake_vector (make_number (7), Qnil
);
7190 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7191 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7192 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7196 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7197 AREF (vector
, i
) = w
->buffer
; ++i
;
7198 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7199 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7204 for (; i
< end
; ++i
)
7205 AREF (vector
, i
) = Qnil
;
7208 xassert (i
== ASIZE (vector
));
7213 /* Restore global state from VECTOR which was created by
7214 with_echo_area_buffer_unwind_data. */
7217 unwind_with_echo_area_buffer (vector
)
7220 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7221 Vdeactivate_mark
= AREF (vector
, 1);
7222 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7224 if (WINDOWP (AREF (vector
, 3)))
7227 Lisp_Object buffer
, charpos
, bytepos
;
7229 w
= XWINDOW (AREF (vector
, 3));
7230 buffer
= AREF (vector
, 4);
7231 charpos
= AREF (vector
, 5);
7232 bytepos
= AREF (vector
, 6);
7235 set_marker_both (w
->pointm
, buffer
,
7236 XFASTINT (charpos
), XFASTINT (bytepos
));
7239 Vwith_echo_area_save_vector
= vector
;
7244 /* Set up the echo area for use by print functions. MULTIBYTE_P
7245 non-zero means we will print multibyte. */
7248 setup_echo_area_for_printing (multibyte_p
)
7251 /* If we can't find an echo area any more, exit. */
7252 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7255 ensure_echo_area_buffers ();
7257 if (!message_buf_print
)
7259 /* A message has been output since the last time we printed.
7260 Choose a fresh echo area buffer. */
7261 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7262 echo_area_buffer
[0] = echo_buffer
[1];
7264 echo_area_buffer
[0] = echo_buffer
[0];
7266 /* Switch to that buffer and clear it. */
7267 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7268 current_buffer
->truncate_lines
= Qnil
;
7272 int count
= SPECPDL_INDEX ();
7273 specbind (Qinhibit_read_only
, Qt
);
7274 /* Note that undo recording is always disabled. */
7276 unbind_to (count
, Qnil
);
7278 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7280 /* Set up the buffer for the multibyteness we need. */
7282 != !NILP (current_buffer
->enable_multibyte_characters
))
7283 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7285 /* Raise the frame containing the echo area. */
7286 if (minibuffer_auto_raise
)
7288 struct frame
*sf
= SELECTED_FRAME ();
7289 Lisp_Object mini_window
;
7290 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7291 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7294 message_log_maybe_newline ();
7295 message_buf_print
= 1;
7299 if (NILP (echo_area_buffer
[0]))
7301 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7302 echo_area_buffer
[0] = echo_buffer
[1];
7304 echo_area_buffer
[0] = echo_buffer
[0];
7307 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7309 /* Someone switched buffers between print requests. */
7310 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7311 current_buffer
->truncate_lines
= Qnil
;
7317 /* Display an echo area message in window W. Value is non-zero if W's
7318 height is changed. If display_last_displayed_message_p is
7319 non-zero, display the message that was last displayed, otherwise
7320 display the current message. */
7323 display_echo_area (w
)
7326 int i
, no_message_p
, window_height_changed_p
, count
;
7328 /* Temporarily disable garbage collections while displaying the echo
7329 area. This is done because a GC can print a message itself.
7330 That message would modify the echo area buffer's contents while a
7331 redisplay of the buffer is going on, and seriously confuse
7333 count
= inhibit_garbage_collection ();
7335 /* If there is no message, we must call display_echo_area_1
7336 nevertheless because it resizes the window. But we will have to
7337 reset the echo_area_buffer in question to nil at the end because
7338 with_echo_area_buffer will sets it to an empty buffer. */
7339 i
= display_last_displayed_message_p
? 1 : 0;
7340 no_message_p
= NILP (echo_area_buffer
[i
]);
7342 window_height_changed_p
7343 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7344 display_echo_area_1
,
7345 (EMACS_INT
) w
, Qnil
, 0, 0);
7348 echo_area_buffer
[i
] = Qnil
;
7350 unbind_to (count
, Qnil
);
7351 return window_height_changed_p
;
7355 /* Helper for display_echo_area. Display the current buffer which
7356 contains the current echo area message in window W, a mini-window,
7357 a pointer to which is passed in A1. A2..A4 are currently not used.
7358 Change the height of W so that all of the message is displayed.
7359 Value is non-zero if height of W was changed. */
7362 display_echo_area_1 (a1
, a2
, a3
, a4
)
7367 struct window
*w
= (struct window
*) a1
;
7369 struct text_pos start
;
7370 int window_height_changed_p
= 0;
7372 /* Do this before displaying, so that we have a large enough glyph
7373 matrix for the display. */
7374 window_height_changed_p
= resize_mini_window (w
, 0);
7377 clear_glyph_matrix (w
->desired_matrix
);
7378 XSETWINDOW (window
, w
);
7379 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7380 try_window (window
, start
);
7382 return window_height_changed_p
;
7386 /* Resize the echo area window to exactly the size needed for the
7387 currently displayed message, if there is one. If a mini-buffer
7388 is active, don't shrink it. */
7391 resize_echo_area_exactly ()
7393 if (BUFFERP (echo_area_buffer
[0])
7394 && WINDOWP (echo_area_window
))
7396 struct window
*w
= XWINDOW (echo_area_window
);
7398 Lisp_Object resize_exactly
;
7400 if (minibuf_level
== 0)
7401 resize_exactly
= Qt
;
7403 resize_exactly
= Qnil
;
7405 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7406 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7409 ++windows_or_buffers_changed
;
7410 ++update_mode_lines
;
7411 redisplay_internal (0);
7417 /* Callback function for with_echo_area_buffer, when used from
7418 resize_echo_area_exactly. A1 contains a pointer to the window to
7419 resize, EXACTLY non-nil means resize the mini-window exactly to the
7420 size of the text displayed. A3 and A4 are not used. Value is what
7421 resize_mini_window returns. */
7424 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7426 Lisp_Object exactly
;
7429 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7433 /* Resize mini-window W to fit the size of its contents. EXACT:P
7434 means size the window exactly to the size needed. Otherwise, it's
7435 only enlarged until W's buffer is empty. Value is non-zero if
7436 the window height has been changed. */
7439 resize_mini_window (w
, exact_p
)
7443 struct frame
*f
= XFRAME (w
->frame
);
7444 int window_height_changed_p
= 0;
7446 xassert (MINI_WINDOW_P (w
));
7448 /* Don't resize windows while redisplaying a window; it would
7449 confuse redisplay functions when the size of the window they are
7450 displaying changes from under them. Such a resizing can happen,
7451 for instance, when which-func prints a long message while
7452 we are running fontification-functions. We're running these
7453 functions with safe_call which binds inhibit-redisplay to t. */
7454 if (!NILP (Vinhibit_redisplay
))
7457 /* Nil means don't try to resize. */
7458 if (NILP (Vresize_mini_windows
)
7459 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7462 if (!FRAME_MINIBUF_ONLY_P (f
))
7465 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7466 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7467 int height
, max_height
;
7468 int unit
= FRAME_LINE_HEIGHT (f
);
7469 struct text_pos start
;
7470 struct buffer
*old_current_buffer
= NULL
;
7472 if (current_buffer
!= XBUFFER (w
->buffer
))
7474 old_current_buffer
= current_buffer
;
7475 set_buffer_internal (XBUFFER (w
->buffer
));
7478 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7480 /* Compute the max. number of lines specified by the user. */
7481 if (FLOATP (Vmax_mini_window_height
))
7482 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7483 else if (INTEGERP (Vmax_mini_window_height
))
7484 max_height
= XINT (Vmax_mini_window_height
);
7486 max_height
= total_height
/ 4;
7488 /* Correct that max. height if it's bogus. */
7489 max_height
= max (1, max_height
);
7490 max_height
= min (total_height
, max_height
);
7492 /* Find out the height of the text in the window. */
7493 if (it
.truncate_lines_p
)
7498 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7499 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7500 height
= it
.current_y
+ last_height
;
7502 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7503 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7504 height
= (height
+ unit
- 1) / unit
;
7507 /* Compute a suitable window start. */
7508 if (height
> max_height
)
7510 height
= max_height
;
7511 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7512 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7513 start
= it
.current
.pos
;
7516 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7517 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7519 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7521 /* Let it grow only, until we display an empty message, in which
7522 case the window shrinks again. */
7523 if (height
> WINDOW_TOTAL_LINES (w
))
7525 int old_height
= WINDOW_TOTAL_LINES (w
);
7526 freeze_window_starts (f
, 1);
7527 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7528 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7530 else if (height
< WINDOW_TOTAL_LINES (w
)
7531 && (exact_p
|| BEGV
== ZV
))
7533 int old_height
= WINDOW_TOTAL_LINES (w
);
7534 freeze_window_starts (f
, 0);
7535 shrink_mini_window (w
);
7536 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7541 /* Always resize to exact size needed. */
7542 if (height
> WINDOW_TOTAL_LINES (w
))
7544 int old_height
= WINDOW_TOTAL_LINES (w
);
7545 freeze_window_starts (f
, 1);
7546 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7547 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7549 else if (height
< WINDOW_TOTAL_LINES (w
))
7551 int old_height
= WINDOW_TOTAL_LINES (w
);
7552 freeze_window_starts (f
, 0);
7553 shrink_mini_window (w
);
7557 freeze_window_starts (f
, 1);
7558 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7561 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7565 if (old_current_buffer
)
7566 set_buffer_internal (old_current_buffer
);
7569 return window_height_changed_p
;
7573 /* Value is the current message, a string, or nil if there is no
7581 if (NILP (echo_area_buffer
[0]))
7585 with_echo_area_buffer (0, 0, current_message_1
,
7586 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7588 echo_area_buffer
[0] = Qnil
;
7596 current_message_1 (a1
, a2
, a3
, a4
)
7601 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7604 *msg
= make_buffer_string (BEG
, Z
, 1);
7611 /* Push the current message on Vmessage_stack for later restauration
7612 by restore_message. Value is non-zero if the current message isn't
7613 empty. This is a relatively infrequent operation, so it's not
7614 worth optimizing. */
7620 msg
= current_message ();
7621 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7622 return STRINGP (msg
);
7626 /* Restore message display from the top of Vmessage_stack. */
7633 xassert (CONSP (Vmessage_stack
));
7634 msg
= XCAR (Vmessage_stack
);
7636 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7638 message3_nolog (msg
, 0, 0);
7642 /* Handler for record_unwind_protect calling pop_message. */
7645 pop_message_unwind (dummy
)
7652 /* Pop the top-most entry off Vmessage_stack. */
7657 xassert (CONSP (Vmessage_stack
));
7658 Vmessage_stack
= XCDR (Vmessage_stack
);
7662 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7663 exits. If the stack is not empty, we have a missing pop_message
7667 check_message_stack ()
7669 if (!NILP (Vmessage_stack
))
7674 /* Truncate to NCHARS what will be displayed in the echo area the next
7675 time we display it---but don't redisplay it now. */
7678 truncate_echo_area (nchars
)
7682 echo_area_buffer
[0] = Qnil
;
7683 /* A null message buffer means that the frame hasn't really been
7684 initialized yet. Error messages get reported properly by
7685 cmd_error, so this must be just an informative message; toss it. */
7686 else if (!noninteractive
7688 && !NILP (echo_area_buffer
[0]))
7690 struct frame
*sf
= SELECTED_FRAME ();
7691 if (FRAME_MESSAGE_BUF (sf
))
7692 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7697 /* Helper function for truncate_echo_area. Truncate the current
7698 message to at most NCHARS characters. */
7701 truncate_message_1 (nchars
, a2
, a3
, a4
)
7706 if (BEG
+ nchars
< Z
)
7707 del_range (BEG
+ nchars
, Z
);
7709 echo_area_buffer
[0] = Qnil
;
7714 /* Set the current message to a substring of S or STRING.
7716 If STRING is a Lisp string, set the message to the first NBYTES
7717 bytes from STRING. NBYTES zero means use the whole string. If
7718 STRING is multibyte, the message will be displayed multibyte.
7720 If S is not null, set the message to the first LEN bytes of S. LEN
7721 zero means use the whole string. MULTIBYTE_P non-zero means S is
7722 multibyte. Display the message multibyte in that case. */
7725 set_message (s
, string
, nbytes
, multibyte_p
)
7728 int nbytes
, multibyte_p
;
7730 message_enable_multibyte
7731 = ((s
&& multibyte_p
)
7732 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7734 with_echo_area_buffer (0, -1, set_message_1
,
7735 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7736 message_buf_print
= 0;
7737 help_echo_showing_p
= 0;
7741 /* Helper function for set_message. Arguments have the same meaning
7742 as there, with A1 corresponding to S and A2 corresponding to STRING
7743 This function is called with the echo area buffer being
7747 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7750 EMACS_INT nbytes
, multibyte_p
;
7752 const char *s
= (const char *) a1
;
7753 Lisp_Object string
= a2
;
7757 /* Change multibyteness of the echo buffer appropriately. */
7758 if (message_enable_multibyte
7759 != !NILP (current_buffer
->enable_multibyte_characters
))
7760 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7762 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7764 /* Insert new message at BEG. */
7765 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7767 if (STRINGP (string
))
7772 nbytes
= SBYTES (string
);
7773 nchars
= string_byte_to_char (string
, nbytes
);
7775 /* This function takes care of single/multibyte conversion. We
7776 just have to ensure that the echo area buffer has the right
7777 setting of enable_multibyte_characters. */
7778 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7783 nbytes
= strlen (s
);
7785 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7787 /* Convert from multi-byte to single-byte. */
7789 unsigned char work
[1];
7791 /* Convert a multibyte string to single-byte. */
7792 for (i
= 0; i
< nbytes
; i
+= n
)
7794 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7795 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7797 : multibyte_char_to_unibyte (c
, Qnil
));
7798 insert_1_both (work
, 1, 1, 1, 0, 0);
7801 else if (!multibyte_p
7802 && !NILP (current_buffer
->enable_multibyte_characters
))
7804 /* Convert from single-byte to multi-byte. */
7806 const unsigned char *msg
= (const unsigned char *) s
;
7807 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7809 /* Convert a single-byte string to multibyte. */
7810 for (i
= 0; i
< nbytes
; i
++)
7812 c
= unibyte_char_to_multibyte (msg
[i
]);
7813 n
= CHAR_STRING (c
, str
);
7814 insert_1_both (str
, 1, n
, 1, 0, 0);
7818 insert_1 (s
, nbytes
, 1, 0, 0);
7825 /* Clear messages. CURRENT_P non-zero means clear the current
7826 message. LAST_DISPLAYED_P non-zero means clear the message
7830 clear_message (current_p
, last_displayed_p
)
7831 int current_p
, last_displayed_p
;
7835 echo_area_buffer
[0] = Qnil
;
7836 message_cleared_p
= 1;
7839 if (last_displayed_p
)
7840 echo_area_buffer
[1] = Qnil
;
7842 message_buf_print
= 0;
7845 /* Clear garbaged frames.
7847 This function is used where the old redisplay called
7848 redraw_garbaged_frames which in turn called redraw_frame which in
7849 turn called clear_frame. The call to clear_frame was a source of
7850 flickering. I believe a clear_frame is not necessary. It should
7851 suffice in the new redisplay to invalidate all current matrices,
7852 and ensure a complete redisplay of all windows. */
7855 clear_garbaged_frames ()
7859 Lisp_Object tail
, frame
;
7860 int changed_count
= 0;
7862 FOR_EACH_FRAME (tail
, frame
)
7864 struct frame
*f
= XFRAME (frame
);
7866 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7870 Fredraw_frame (frame
);
7871 f
->force_flush_display_p
= 1;
7873 clear_current_matrices (f
);
7882 ++windows_or_buffers_changed
;
7887 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7888 is non-zero update selected_frame. Value is non-zero if the
7889 mini-windows height has been changed. */
7892 echo_area_display (update_frame_p
)
7895 Lisp_Object mini_window
;
7898 int window_height_changed_p
= 0;
7899 struct frame
*sf
= SELECTED_FRAME ();
7901 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7902 w
= XWINDOW (mini_window
);
7903 f
= XFRAME (WINDOW_FRAME (w
));
7905 /* Don't display if frame is invisible or not yet initialized. */
7906 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7909 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7911 #ifdef HAVE_WINDOW_SYSTEM
7912 /* When Emacs starts, selected_frame may be a visible terminal
7913 frame, even if we run under a window system. If we let this
7914 through, a message would be displayed on the terminal. */
7915 if (EQ (selected_frame
, Vterminal_frame
)
7916 && !NILP (Vwindow_system
))
7918 #endif /* HAVE_WINDOW_SYSTEM */
7921 /* Redraw garbaged frames. */
7923 clear_garbaged_frames ();
7925 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7927 echo_area_window
= mini_window
;
7928 window_height_changed_p
= display_echo_area (w
);
7929 w
->must_be_updated_p
= 1;
7931 /* Update the display, unless called from redisplay_internal.
7932 Also don't update the screen during redisplay itself. The
7933 update will happen at the end of redisplay, and an update
7934 here could cause confusion. */
7935 if (update_frame_p
&& !redisplaying_p
)
7939 /* If the display update has been interrupted by pending
7940 input, update mode lines in the frame. Due to the
7941 pending input, it might have been that redisplay hasn't
7942 been called, so that mode lines above the echo area are
7943 garbaged. This looks odd, so we prevent it here. */
7944 if (!display_completed
)
7945 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7947 if (window_height_changed_p
7948 /* Don't do this if Emacs is shutting down. Redisplay
7949 needs to run hooks. */
7950 && !NILP (Vrun_hooks
))
7952 /* Must update other windows. Likewise as in other
7953 cases, don't let this update be interrupted by
7955 int count
= SPECPDL_INDEX ();
7956 specbind (Qredisplay_dont_pause
, Qt
);
7957 windows_or_buffers_changed
= 1;
7958 redisplay_internal (0);
7959 unbind_to (count
, Qnil
);
7961 else if (FRAME_WINDOW_P (f
) && n
== 0)
7963 /* Window configuration is the same as before.
7964 Can do with a display update of the echo area,
7965 unless we displayed some mode lines. */
7966 update_single_window (w
, 1);
7967 rif
->flush_display (f
);
7970 update_frame (f
, 1, 1);
7972 /* If cursor is in the echo area, make sure that the next
7973 redisplay displays the minibuffer, so that the cursor will
7974 be replaced with what the minibuffer wants. */
7975 if (cursor_in_echo_area
)
7976 ++windows_or_buffers_changed
;
7979 else if (!EQ (mini_window
, selected_window
))
7980 windows_or_buffers_changed
++;
7982 /* Last displayed message is now the current message. */
7983 echo_area_buffer
[1] = echo_area_buffer
[0];
7985 /* Prevent redisplay optimization in redisplay_internal by resetting
7986 this_line_start_pos. This is done because the mini-buffer now
7987 displays the message instead of its buffer text. */
7988 if (EQ (mini_window
, selected_window
))
7989 CHARPOS (this_line_start_pos
) = 0;
7991 return window_height_changed_p
;
7996 /***********************************************************************
7998 ***********************************************************************/
8001 /* The frame title buffering code is also used by Fformat_mode_line.
8002 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
8004 /* A buffer for constructing frame titles in it; allocated from the
8005 heap in init_xdisp and resized as needed in store_frame_title_char. */
8007 static char *frame_title_buf
;
8009 /* The buffer's end, and a current output position in it. */
8011 static char *frame_title_buf_end
;
8012 static char *frame_title_ptr
;
8015 /* Store a single character C for the frame title in frame_title_buf.
8016 Re-allocate frame_title_buf if necessary. */
8020 store_frame_title_char (char c
)
8022 store_frame_title_char (c
)
8026 /* If output position has reached the end of the allocated buffer,
8027 double the buffer's size. */
8028 if (frame_title_ptr
== frame_title_buf_end
)
8030 int len
= frame_title_ptr
- frame_title_buf
;
8031 int new_size
= 2 * len
* sizeof *frame_title_buf
;
8032 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
8033 frame_title_buf_end
= frame_title_buf
+ new_size
;
8034 frame_title_ptr
= frame_title_buf
+ len
;
8037 *frame_title_ptr
++ = c
;
8041 /* Store part of a frame title in frame_title_buf, beginning at
8042 frame_title_ptr. STR is the string to store. Do not copy
8043 characters that yield more columns than PRECISION; PRECISION <= 0
8044 means copy the whole string. Pad with spaces until FIELD_WIDTH
8045 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8046 pad. Called from display_mode_element when it is used to build a
8050 store_frame_title (str
, field_width
, precision
)
8051 const unsigned char *str
;
8052 int field_width
, precision
;
8057 /* Copy at most PRECISION chars from STR. */
8058 nbytes
= strlen (str
);
8059 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8061 store_frame_title_char (*str
++);
8063 /* Fill up with spaces until FIELD_WIDTH reached. */
8064 while (field_width
> 0
8067 store_frame_title_char (' ');
8074 #ifdef HAVE_WINDOW_SYSTEM
8076 /* Set the title of FRAME, if it has changed. The title format is
8077 Vicon_title_format if FRAME is iconified, otherwise it is
8078 frame_title_format. */
8081 x_consider_frame_title (frame
)
8084 struct frame
*f
= XFRAME (frame
);
8086 if (FRAME_WINDOW_P (f
)
8087 || FRAME_MINIBUF_ONLY_P (f
)
8088 || f
->explicit_name
)
8090 /* Do we have more than one visible frame on this X display? */
8093 struct buffer
*obuf
;
8097 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8099 Lisp_Object other_frame
= XCAR (tail
);
8100 struct frame
*tf
= XFRAME (other_frame
);
8103 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8104 && !FRAME_MINIBUF_ONLY_P (tf
)
8105 && !EQ (other_frame
, tip_frame
)
8106 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8110 /* Set global variable indicating that multiple frames exist. */
8111 multiple_frames
= CONSP (tail
);
8113 /* Switch to the buffer of selected window of the frame. Set up
8114 frame_title_ptr so that display_mode_element will output into it;
8115 then display the title. */
8116 obuf
= current_buffer
;
8117 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8118 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8119 frame_title_ptr
= frame_title_buf
;
8120 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8121 NULL
, DEFAULT_FACE_ID
);
8122 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8123 len
= frame_title_ptr
- frame_title_buf
;
8124 frame_title_ptr
= NULL
;
8125 set_buffer_internal_1 (obuf
);
8127 /* Set the title only if it's changed. This avoids consing in
8128 the common case where it hasn't. (If it turns out that we've
8129 already wasted too much time by walking through the list with
8130 display_mode_element, then we might need to optimize at a
8131 higher level than this.) */
8132 if (! STRINGP (f
->name
)
8133 || SBYTES (f
->name
) != len
8134 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8135 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8139 #endif /* not HAVE_WINDOW_SYSTEM */
8144 /***********************************************************************
8146 ***********************************************************************/
8149 /* Prepare for redisplay by updating menu-bar item lists when
8150 appropriate. This can call eval. */
8153 prepare_menu_bars ()
8156 struct gcpro gcpro1
, gcpro2
;
8158 Lisp_Object tooltip_frame
;
8160 #ifdef HAVE_WINDOW_SYSTEM
8161 tooltip_frame
= tip_frame
;
8163 tooltip_frame
= Qnil
;
8166 /* Update all frame titles based on their buffer names, etc. We do
8167 this before the menu bars so that the buffer-menu will show the
8168 up-to-date frame titles. */
8169 #ifdef HAVE_WINDOW_SYSTEM
8170 if (windows_or_buffers_changed
|| update_mode_lines
)
8172 Lisp_Object tail
, frame
;
8174 FOR_EACH_FRAME (tail
, frame
)
8177 if (!EQ (frame
, tooltip_frame
)
8178 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8179 x_consider_frame_title (frame
);
8182 #endif /* HAVE_WINDOW_SYSTEM */
8184 /* Update the menu bar item lists, if appropriate. This has to be
8185 done before any actual redisplay or generation of display lines. */
8186 all_windows
= (update_mode_lines
8187 || buffer_shared
> 1
8188 || windows_or_buffers_changed
);
8191 Lisp_Object tail
, frame
;
8192 int count
= SPECPDL_INDEX ();
8194 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8196 FOR_EACH_FRAME (tail
, frame
)
8200 /* Ignore tooltip frame. */
8201 if (EQ (frame
, tooltip_frame
))
8204 /* If a window on this frame changed size, report that to
8205 the user and clear the size-change flag. */
8206 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8208 Lisp_Object functions
;
8210 /* Clear flag first in case we get an error below. */
8211 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8212 functions
= Vwindow_size_change_functions
;
8213 GCPRO2 (tail
, functions
);
8215 while (CONSP (functions
))
8217 call1 (XCAR (functions
), frame
);
8218 functions
= XCDR (functions
);
8224 update_menu_bar (f
, 0);
8225 #ifdef HAVE_WINDOW_SYSTEM
8226 update_tool_bar (f
, 0);
8231 unbind_to (count
, Qnil
);
8235 struct frame
*sf
= SELECTED_FRAME ();
8236 update_menu_bar (sf
, 1);
8237 #ifdef HAVE_WINDOW_SYSTEM
8238 update_tool_bar (sf
, 1);
8242 /* Motif needs this. See comment in xmenu.c. Turn it off when
8243 pending_menu_activation is not defined. */
8244 #ifdef USE_X_TOOLKIT
8245 pending_menu_activation
= 0;
8250 /* Update the menu bar item list for frame F. This has to be done
8251 before we start to fill in any display lines, because it can call
8254 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8257 update_menu_bar (f
, save_match_data
)
8259 int save_match_data
;
8262 register struct window
*w
;
8264 /* If called recursively during a menu update, do nothing. This can
8265 happen when, for instance, an activate-menubar-hook causes a
8267 if (inhibit_menubar_update
)
8270 window
= FRAME_SELECTED_WINDOW (f
);
8271 w
= XWINDOW (window
);
8273 #if 0 /* The if statement below this if statement used to include the
8274 condition !NILP (w->update_mode_line), rather than using
8275 update_mode_lines directly, and this if statement may have
8276 been added to make that condition work. Now the if
8277 statement below matches its comment, this isn't needed. */
8278 if (update_mode_lines
)
8279 w
->update_mode_line
= Qt
;
8282 if (FRAME_WINDOW_P (f
)
8284 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8285 || defined (USE_GTK)
8286 FRAME_EXTERNAL_MENU_BAR (f
)
8288 FRAME_MENU_BAR_LINES (f
) > 0
8290 : FRAME_MENU_BAR_LINES (f
) > 0)
8292 /* If the user has switched buffers or windows, we need to
8293 recompute to reflect the new bindings. But we'll
8294 recompute when update_mode_lines is set too; that means
8295 that people can use force-mode-line-update to request
8296 that the menu bar be recomputed. The adverse effect on
8297 the rest of the redisplay algorithm is about the same as
8298 windows_or_buffers_changed anyway. */
8299 if (windows_or_buffers_changed
8300 /* This used to test w->update_mode_line, but we believe
8301 there is no need to recompute the menu in that case. */
8302 || update_mode_lines
8303 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8304 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8305 != !NILP (w
->last_had_star
))
8306 || ((!NILP (Vtransient_mark_mode
)
8307 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8308 != !NILP (w
->region_showing
)))
8310 struct buffer
*prev
= current_buffer
;
8311 int count
= SPECPDL_INDEX ();
8313 specbind (Qinhibit_menubar_update
, Qt
);
8315 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8316 if (save_match_data
)
8317 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8318 if (NILP (Voverriding_local_map_menu_flag
))
8320 specbind (Qoverriding_terminal_local_map
, Qnil
);
8321 specbind (Qoverriding_local_map
, Qnil
);
8324 /* Run the Lucid hook. */
8325 safe_run_hooks (Qactivate_menubar_hook
);
8327 /* If it has changed current-menubar from previous value,
8328 really recompute the menu-bar from the value. */
8329 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8330 call0 (Qrecompute_lucid_menubar
);
8332 safe_run_hooks (Qmenu_bar_update_hook
);
8333 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8335 /* Redisplay the menu bar in case we changed it. */
8336 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8337 || defined (USE_GTK)
8338 if (FRAME_WINDOW_P (f
)
8339 #if defined (MAC_OS)
8340 /* All frames on Mac OS share the same menubar. So only the
8341 selected frame should be allowed to set it. */
8342 && f
== SELECTED_FRAME ()
8345 set_frame_menubar (f
, 0, 0);
8347 /* On a terminal screen, the menu bar is an ordinary screen
8348 line, and this makes it get updated. */
8349 w
->update_mode_line
= Qt
;
8350 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8351 /* In the non-toolkit version, the menu bar is an ordinary screen
8352 line, and this makes it get updated. */
8353 w
->update_mode_line
= Qt
;
8354 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8356 unbind_to (count
, Qnil
);
8357 set_buffer_internal_1 (prev
);
8364 /***********************************************************************
8366 ***********************************************************************/
8368 #ifdef HAVE_WINDOW_SYSTEM
8371 Nominal cursor position -- where to draw output.
8372 HPOS and VPOS are window relative glyph matrix coordinates.
8373 X and Y are window relative pixel coordinates. */
8375 struct cursor_pos output_cursor
;
8379 Set the global variable output_cursor to CURSOR. All cursor
8380 positions are relative to updated_window. */
8383 set_output_cursor (cursor
)
8384 struct cursor_pos
*cursor
;
8386 output_cursor
.hpos
= cursor
->hpos
;
8387 output_cursor
.vpos
= cursor
->vpos
;
8388 output_cursor
.x
= cursor
->x
;
8389 output_cursor
.y
= cursor
->y
;
8394 Set a nominal cursor position.
8396 HPOS and VPOS are column/row positions in a window glyph matrix. X
8397 and Y are window text area relative pixel positions.
8399 If this is done during an update, updated_window will contain the
8400 window that is being updated and the position is the future output
8401 cursor position for that window. If updated_window is null, use
8402 selected_window and display the cursor at the given position. */
8405 x_cursor_to (vpos
, hpos
, y
, x
)
8406 int vpos
, hpos
, y
, x
;
8410 /* If updated_window is not set, work on selected_window. */
8414 w
= XWINDOW (selected_window
);
8416 /* Set the output cursor. */
8417 output_cursor
.hpos
= hpos
;
8418 output_cursor
.vpos
= vpos
;
8419 output_cursor
.x
= x
;
8420 output_cursor
.y
= y
;
8422 /* If not called as part of an update, really display the cursor.
8423 This will also set the cursor position of W. */
8424 if (updated_window
== NULL
)
8427 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8428 if (rif
->flush_display_optional
)
8429 rif
->flush_display_optional (SELECTED_FRAME ());
8434 #endif /* HAVE_WINDOW_SYSTEM */
8437 /***********************************************************************
8439 ***********************************************************************/
8441 #ifdef HAVE_WINDOW_SYSTEM
8443 /* Where the mouse was last time we reported a mouse event. */
8445 FRAME_PTR last_mouse_frame
;
8447 /* Tool-bar item index of the item on which a mouse button was pressed
8450 int last_tool_bar_item
;
8453 /* Update the tool-bar item list for frame F. This has to be done
8454 before we start to fill in any display lines. Called from
8455 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8456 and restore it here. */
8459 update_tool_bar (f
, save_match_data
)
8461 int save_match_data
;
8464 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8466 int do_update
= WINDOWP (f
->tool_bar_window
)
8467 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8475 window
= FRAME_SELECTED_WINDOW (f
);
8476 w
= XWINDOW (window
);
8478 /* If the user has switched buffers or windows, we need to
8479 recompute to reflect the new bindings. But we'll
8480 recompute when update_mode_lines is set too; that means
8481 that people can use force-mode-line-update to request
8482 that the menu bar be recomputed. The adverse effect on
8483 the rest of the redisplay algorithm is about the same as
8484 windows_or_buffers_changed anyway. */
8485 if (windows_or_buffers_changed
8486 || !NILP (w
->update_mode_line
)
8487 || update_mode_lines
8488 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8489 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8490 != !NILP (w
->last_had_star
))
8491 || ((!NILP (Vtransient_mark_mode
)
8492 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8493 != !NILP (w
->region_showing
)))
8495 struct buffer
*prev
= current_buffer
;
8496 int count
= SPECPDL_INDEX ();
8497 Lisp_Object new_tool_bar
;
8499 struct gcpro gcpro1
;
8501 /* Set current_buffer to the buffer of the selected
8502 window of the frame, so that we get the right local
8504 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8506 /* Save match data, if we must. */
8507 if (save_match_data
)
8508 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8510 /* Make sure that we don't accidentally use bogus keymaps. */
8511 if (NILP (Voverriding_local_map_menu_flag
))
8513 specbind (Qoverriding_terminal_local_map
, Qnil
);
8514 specbind (Qoverriding_local_map
, Qnil
);
8517 GCPRO1 (new_tool_bar
);
8519 /* Build desired tool-bar items from keymaps. */
8520 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8523 /* Redisplay the tool-bar if we changed it. */
8524 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8526 /* Redisplay that happens asynchronously due to an expose event
8527 may access f->tool_bar_items. Make sure we update both
8528 variables within BLOCK_INPUT so no such event interrupts. */
8530 f
->tool_bar_items
= new_tool_bar
;
8531 f
->n_tool_bar_items
= new_n_tool_bar
;
8532 w
->update_mode_line
= Qt
;
8538 unbind_to (count
, Qnil
);
8539 set_buffer_internal_1 (prev
);
8545 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8546 F's desired tool-bar contents. F->tool_bar_items must have
8547 been set up previously by calling prepare_menu_bars. */
8550 build_desired_tool_bar_string (f
)
8553 int i
, size
, size_needed
;
8554 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8555 Lisp_Object image
, plist
, props
;
8557 image
= plist
= props
= Qnil
;
8558 GCPRO3 (image
, plist
, props
);
8560 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8561 Otherwise, make a new string. */
8563 /* The size of the string we might be able to reuse. */
8564 size
= (STRINGP (f
->desired_tool_bar_string
)
8565 ? SCHARS (f
->desired_tool_bar_string
)
8568 /* We need one space in the string for each image. */
8569 size_needed
= f
->n_tool_bar_items
;
8571 /* Reuse f->desired_tool_bar_string, if possible. */
8572 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8573 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8577 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8578 Fremove_text_properties (make_number (0), make_number (size
),
8579 props
, f
->desired_tool_bar_string
);
8582 /* Put a `display' property on the string for the images to display,
8583 put a `menu_item' property on tool-bar items with a value that
8584 is the index of the item in F's tool-bar item vector. */
8585 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8587 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8589 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8590 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8591 int hmargin
, vmargin
, relief
, idx
, end
;
8592 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8594 /* If image is a vector, choose the image according to the
8596 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8597 if (VECTORP (image
))
8601 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8602 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8605 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8606 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8608 xassert (ASIZE (image
) >= idx
);
8609 image
= AREF (image
, idx
);
8614 /* Ignore invalid image specifications. */
8615 if (!valid_image_p (image
))
8618 /* Display the tool-bar button pressed, or depressed. */
8619 plist
= Fcopy_sequence (XCDR (image
));
8621 /* Compute margin and relief to draw. */
8622 relief
= (tool_bar_button_relief
>= 0
8623 ? tool_bar_button_relief
8624 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8625 hmargin
= vmargin
= relief
;
8627 if (INTEGERP (Vtool_bar_button_margin
)
8628 && XINT (Vtool_bar_button_margin
) > 0)
8630 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8631 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8633 else if (CONSP (Vtool_bar_button_margin
))
8635 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8636 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8637 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8639 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8640 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8641 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8644 if (auto_raise_tool_bar_buttons_p
)
8646 /* Add a `:relief' property to the image spec if the item is
8650 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8657 /* If image is selected, display it pressed, i.e. with a
8658 negative relief. If it's not selected, display it with a
8660 plist
= Fplist_put (plist
, QCrelief
,
8662 ? make_number (-relief
)
8663 : make_number (relief
)));
8668 /* Put a margin around the image. */
8669 if (hmargin
|| vmargin
)
8671 if (hmargin
== vmargin
)
8672 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8674 plist
= Fplist_put (plist
, QCmargin
,
8675 Fcons (make_number (hmargin
),
8676 make_number (vmargin
)));
8679 /* If button is not enabled, and we don't have special images
8680 for the disabled state, make the image appear disabled by
8681 applying an appropriate algorithm to it. */
8682 if (!enabled_p
&& idx
< 0)
8683 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8685 /* Put a `display' text property on the string for the image to
8686 display. Put a `menu-item' property on the string that gives
8687 the start of this item's properties in the tool-bar items
8689 image
= Fcons (Qimage
, plist
);
8690 props
= list4 (Qdisplay
, image
,
8691 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8693 /* Let the last image hide all remaining spaces in the tool bar
8694 string. The string can be longer than needed when we reuse a
8696 if (i
+ 1 == f
->n_tool_bar_items
)
8697 end
= SCHARS (f
->desired_tool_bar_string
);
8700 Fadd_text_properties (make_number (i
), make_number (end
),
8701 props
, f
->desired_tool_bar_string
);
8709 /* Display one line of the tool-bar of frame IT->f. */
8712 display_tool_bar_line (it
)
8715 struct glyph_row
*row
= it
->glyph_row
;
8716 int max_x
= it
->last_visible_x
;
8719 prepare_desired_row (row
);
8720 row
->y
= it
->current_y
;
8722 /* Note that this isn't made use of if the face hasn't a box,
8723 so there's no need to check the face here. */
8724 it
->start_of_box_run_p
= 1;
8726 while (it
->current_x
< max_x
)
8728 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8730 /* Get the next display element. */
8731 if (!get_next_display_element (it
))
8734 /* Produce glyphs. */
8735 x_before
= it
->current_x
;
8736 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8737 PRODUCE_GLYPHS (it
);
8739 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8744 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8746 if (x
+ glyph
->pixel_width
> max_x
)
8748 /* Glyph doesn't fit on line. */
8749 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8755 x
+= glyph
->pixel_width
;
8759 /* Stop at line ends. */
8760 if (ITERATOR_AT_END_OF_LINE_P (it
))
8763 set_iterator_to_next (it
, 1);
8768 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8769 extend_face_to_end_of_line (it
);
8770 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8771 last
->right_box_line_p
= 1;
8772 if (last
== row
->glyphs
[TEXT_AREA
])
8773 last
->left_box_line_p
= 1;
8774 compute_line_metrics (it
);
8776 /* If line is empty, make it occupy the rest of the tool-bar. */
8777 if (!row
->displays_text_p
)
8779 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8780 row
->ascent
= row
->phys_ascent
= 0;
8781 row
->extra_line_spacing
= 0;
8784 row
->full_width_p
= 1;
8785 row
->continued_p
= 0;
8786 row
->truncated_on_left_p
= 0;
8787 row
->truncated_on_right_p
= 0;
8789 it
->current_x
= it
->hpos
= 0;
8790 it
->current_y
+= row
->height
;
8796 /* Value is the number of screen lines needed to make all tool-bar
8797 items of frame F visible. */
8800 tool_bar_lines_needed (f
)
8803 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8806 /* Initialize an iterator for iteration over
8807 F->desired_tool_bar_string in the tool-bar window of frame F. */
8808 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8809 it
.first_visible_x
= 0;
8810 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8811 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8813 while (!ITERATOR_AT_END_P (&it
))
8815 it
.glyph_row
= w
->desired_matrix
->rows
;
8816 clear_glyph_row (it
.glyph_row
);
8817 display_tool_bar_line (&it
);
8820 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8824 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8826 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8835 frame
= selected_frame
;
8837 CHECK_FRAME (frame
);
8840 if (WINDOWP (f
->tool_bar_window
)
8841 || (w
= XWINDOW (f
->tool_bar_window
),
8842 WINDOW_TOTAL_LINES (w
) > 0))
8844 update_tool_bar (f
, 1);
8845 if (f
->n_tool_bar_items
)
8847 build_desired_tool_bar_string (f
);
8848 nlines
= tool_bar_lines_needed (f
);
8852 return make_number (nlines
);
8856 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8857 height should be changed. */
8860 redisplay_tool_bar (f
)
8865 struct glyph_row
*row
;
8866 int change_height_p
= 0;
8869 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8870 update_frame_tool_bar (f
);
8874 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8875 do anything. This means you must start with tool-bar-lines
8876 non-zero to get the auto-sizing effect. Or in other words, you
8877 can turn off tool-bars by specifying tool-bar-lines zero. */
8878 if (!WINDOWP (f
->tool_bar_window
)
8879 || (w
= XWINDOW (f
->tool_bar_window
),
8880 WINDOW_TOTAL_LINES (w
) == 0))
8883 /* Set up an iterator for the tool-bar window. */
8884 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8885 it
.first_visible_x
= 0;
8886 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8889 /* Build a string that represents the contents of the tool-bar. */
8890 build_desired_tool_bar_string (f
);
8891 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8893 /* Display as many lines as needed to display all tool-bar items. */
8894 while (it
.current_y
< it
.last_visible_y
)
8895 display_tool_bar_line (&it
);
8897 /* It doesn't make much sense to try scrolling in the tool-bar
8898 window, so don't do it. */
8899 w
->desired_matrix
->no_scrolling_p
= 1;
8900 w
->must_be_updated_p
= 1;
8902 if (auto_resize_tool_bars_p
)
8906 /* If we couldn't display everything, change the tool-bar's
8908 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8909 change_height_p
= 1;
8911 /* If there are blank lines at the end, except for a partially
8912 visible blank line at the end that is smaller than
8913 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8914 row
= it
.glyph_row
- 1;
8915 if (!row
->displays_text_p
8916 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8917 change_height_p
= 1;
8919 /* If row displays tool-bar items, but is partially visible,
8920 change the tool-bar's height. */
8921 if (row
->displays_text_p
8922 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8923 change_height_p
= 1;
8925 /* Resize windows as needed by changing the `tool-bar-lines'
8928 && (nlines
= tool_bar_lines_needed (f
),
8929 nlines
!= WINDOW_TOTAL_LINES (w
)))
8931 extern Lisp_Object Qtool_bar_lines
;
8933 int old_height
= WINDOW_TOTAL_LINES (w
);
8935 XSETFRAME (frame
, f
);
8936 clear_glyph_matrix (w
->desired_matrix
);
8937 Fmodify_frame_parameters (frame
,
8938 Fcons (Fcons (Qtool_bar_lines
,
8939 make_number (nlines
)),
8941 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8942 fonts_changed_p
= 1;
8946 return change_height_p
;
8950 /* Get information about the tool-bar item which is displayed in GLYPH
8951 on frame F. Return in *PROP_IDX the index where tool-bar item
8952 properties start in F->tool_bar_items. Value is zero if
8953 GLYPH doesn't display a tool-bar item. */
8956 tool_bar_item_info (f
, glyph
, prop_idx
)
8958 struct glyph
*glyph
;
8965 /* This function can be called asynchronously, which means we must
8966 exclude any possibility that Fget_text_property signals an
8968 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8969 charpos
= max (0, charpos
);
8971 /* Get the text property `menu-item' at pos. The value of that
8972 property is the start index of this item's properties in
8973 F->tool_bar_items. */
8974 prop
= Fget_text_property (make_number (charpos
),
8975 Qmenu_item
, f
->current_tool_bar_string
);
8976 if (INTEGERP (prop
))
8978 *prop_idx
= XINT (prop
);
8988 /* Get information about the tool-bar item at position X/Y on frame F.
8989 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8990 the current matrix of the tool-bar window of F, or NULL if not
8991 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8992 item in F->tool_bar_items. Value is
8994 -1 if X/Y is not on a tool-bar item
8995 0 if X/Y is on the same item that was highlighted before.
8999 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9002 struct glyph
**glyph
;
9003 int *hpos
, *vpos
, *prop_idx
;
9005 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9006 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9009 /* Find the glyph under X/Y. */
9010 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9014 /* Get the start of this tool-bar item's properties in
9015 f->tool_bar_items. */
9016 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9019 /* Is mouse on the highlighted item? */
9020 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9021 && *vpos
>= dpyinfo
->mouse_face_beg_row
9022 && *vpos
<= dpyinfo
->mouse_face_end_row
9023 && (*vpos
> dpyinfo
->mouse_face_beg_row
9024 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9025 && (*vpos
< dpyinfo
->mouse_face_end_row
9026 || *hpos
< dpyinfo
->mouse_face_end_col
9027 || dpyinfo
->mouse_face_past_end
))
9035 Handle mouse button event on the tool-bar of frame F, at
9036 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9037 0 for button release. MODIFIERS is event modifiers for button
9041 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9044 unsigned int modifiers
;
9046 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9047 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9048 int hpos
, vpos
, prop_idx
;
9049 struct glyph
*glyph
;
9050 Lisp_Object enabled_p
;
9052 /* If not on the highlighted tool-bar item, return. */
9053 frame_to_window_pixel_xy (w
, &x
, &y
);
9054 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9057 /* If item is disabled, do nothing. */
9058 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9059 if (NILP (enabled_p
))
9064 /* Show item in pressed state. */
9065 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9066 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9067 last_tool_bar_item
= prop_idx
;
9071 Lisp_Object key
, frame
;
9072 struct input_event event
;
9075 /* Show item in released state. */
9076 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9077 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9079 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9081 XSETFRAME (frame
, f
);
9082 event
.kind
= TOOL_BAR_EVENT
;
9083 event
.frame_or_window
= frame
;
9085 kbd_buffer_store_event (&event
);
9087 event
.kind
= TOOL_BAR_EVENT
;
9088 event
.frame_or_window
= frame
;
9090 event
.modifiers
= modifiers
;
9091 kbd_buffer_store_event (&event
);
9092 last_tool_bar_item
= -1;
9097 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9098 tool-bar window-relative coordinates X/Y. Called from
9099 note_mouse_highlight. */
9102 note_tool_bar_highlight (f
, x
, y
)
9106 Lisp_Object window
= f
->tool_bar_window
;
9107 struct window
*w
= XWINDOW (window
);
9108 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9110 struct glyph
*glyph
;
9111 struct glyph_row
*row
;
9113 Lisp_Object enabled_p
;
9115 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9116 int mouse_down_p
, rc
;
9118 /* Function note_mouse_highlight is called with negative x(y
9119 values when mouse moves outside of the frame. */
9120 if (x
<= 0 || y
<= 0)
9122 clear_mouse_face (dpyinfo
);
9126 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9129 /* Not on tool-bar item. */
9130 clear_mouse_face (dpyinfo
);
9134 /* On same tool-bar item as before. */
9137 clear_mouse_face (dpyinfo
);
9139 /* Mouse is down, but on different tool-bar item? */
9140 mouse_down_p
= (dpyinfo
->grabbed
9141 && f
== last_mouse_frame
9142 && FRAME_LIVE_P (f
));
9144 && last_tool_bar_item
!= prop_idx
)
9147 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9148 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9150 /* If tool-bar item is not enabled, don't highlight it. */
9151 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9152 if (!NILP (enabled_p
))
9154 /* Compute the x-position of the glyph. In front and past the
9155 image is a space. We include this in the highlighted area. */
9156 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9157 for (i
= x
= 0; i
< hpos
; ++i
)
9158 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9160 /* Record this as the current active region. */
9161 dpyinfo
->mouse_face_beg_col
= hpos
;
9162 dpyinfo
->mouse_face_beg_row
= vpos
;
9163 dpyinfo
->mouse_face_beg_x
= x
;
9164 dpyinfo
->mouse_face_beg_y
= row
->y
;
9165 dpyinfo
->mouse_face_past_end
= 0;
9167 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9168 dpyinfo
->mouse_face_end_row
= vpos
;
9169 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9170 dpyinfo
->mouse_face_end_y
= row
->y
;
9171 dpyinfo
->mouse_face_window
= window
;
9172 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9174 /* Display it as active. */
9175 show_mouse_face (dpyinfo
, draw
);
9176 dpyinfo
->mouse_face_image_state
= draw
;
9181 /* Set help_echo_string to a help string to display for this tool-bar item.
9182 XTread_socket does the rest. */
9183 help_echo_object
= help_echo_window
= Qnil
;
9185 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9186 if (NILP (help_echo_string
))
9187 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9190 #endif /* HAVE_WINDOW_SYSTEM */
9194 /************************************************************************
9195 Horizontal scrolling
9196 ************************************************************************/
9198 static int hscroll_window_tree
P_ ((Lisp_Object
));
9199 static int hscroll_windows
P_ ((Lisp_Object
));
9201 /* For all leaf windows in the window tree rooted at WINDOW, set their
9202 hscroll value so that PT is (i) visible in the window, and (ii) so
9203 that it is not within a certain margin at the window's left and
9204 right border. Value is non-zero if any window's hscroll has been
9208 hscroll_window_tree (window
)
9211 int hscrolled_p
= 0;
9212 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9213 int hscroll_step_abs
= 0;
9214 double hscroll_step_rel
= 0;
9216 if (hscroll_relative_p
)
9218 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9219 if (hscroll_step_rel
< 0)
9221 hscroll_relative_p
= 0;
9222 hscroll_step_abs
= 0;
9225 else if (INTEGERP (Vhscroll_step
))
9227 hscroll_step_abs
= XINT (Vhscroll_step
);
9228 if (hscroll_step_abs
< 0)
9229 hscroll_step_abs
= 0;
9232 hscroll_step_abs
= 0;
9234 while (WINDOWP (window
))
9236 struct window
*w
= XWINDOW (window
);
9238 if (WINDOWP (w
->hchild
))
9239 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9240 else if (WINDOWP (w
->vchild
))
9241 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9242 else if (w
->cursor
.vpos
>= 0)
9245 int text_area_width
;
9246 struct glyph_row
*current_cursor_row
9247 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9248 struct glyph_row
*desired_cursor_row
9249 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9250 struct glyph_row
*cursor_row
9251 = (desired_cursor_row
->enabled_p
9252 ? desired_cursor_row
9253 : current_cursor_row
);
9255 text_area_width
= window_box_width (w
, TEXT_AREA
);
9257 /* Scroll when cursor is inside this scroll margin. */
9258 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9260 if ((XFASTINT (w
->hscroll
)
9261 && w
->cursor
.x
<= h_margin
)
9262 || (cursor_row
->enabled_p
9263 && cursor_row
->truncated_on_right_p
9264 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9268 struct buffer
*saved_current_buffer
;
9272 /* Find point in a display of infinite width. */
9273 saved_current_buffer
= current_buffer
;
9274 current_buffer
= XBUFFER (w
->buffer
);
9276 if (w
== XWINDOW (selected_window
))
9277 pt
= BUF_PT (current_buffer
);
9280 pt
= marker_position (w
->pointm
);
9281 pt
= max (BEGV
, pt
);
9285 /* Move iterator to pt starting at cursor_row->start in
9286 a line with infinite width. */
9287 init_to_row_start (&it
, w
, cursor_row
);
9288 it
.last_visible_x
= INFINITY
;
9289 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9290 current_buffer
= saved_current_buffer
;
9292 /* Position cursor in window. */
9293 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9294 hscroll
= max (0, (it
.current_x
9295 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9296 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9297 : (text_area_width
/ 2))))
9298 / FRAME_COLUMN_WIDTH (it
.f
);
9299 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9301 if (hscroll_relative_p
)
9302 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9305 wanted_x
= text_area_width
9306 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9309 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9313 if (hscroll_relative_p
)
9314 wanted_x
= text_area_width
* hscroll_step_rel
9317 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9320 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9322 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9324 /* Don't call Fset_window_hscroll if value hasn't
9325 changed because it will prevent redisplay
9327 if (XFASTINT (w
->hscroll
) != hscroll
)
9329 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9330 w
->hscroll
= make_number (hscroll
);
9339 /* Value is non-zero if hscroll of any leaf window has been changed. */
9344 /* Set hscroll so that cursor is visible and not inside horizontal
9345 scroll margins for all windows in the tree rooted at WINDOW. See
9346 also hscroll_window_tree above. Value is non-zero if any window's
9347 hscroll has been changed. If it has, desired matrices on the frame
9348 of WINDOW are cleared. */
9351 hscroll_windows (window
)
9356 if (automatic_hscrolling_p
)
9358 hscrolled_p
= hscroll_window_tree (window
);
9360 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9369 /************************************************************************
9371 ************************************************************************/
9373 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9374 to a non-zero value. This is sometimes handy to have in a debugger
9379 /* First and last unchanged row for try_window_id. */
9381 int debug_first_unchanged_at_end_vpos
;
9382 int debug_last_unchanged_at_beg_vpos
;
9384 /* Delta vpos and y. */
9386 int debug_dvpos
, debug_dy
;
9388 /* Delta in characters and bytes for try_window_id. */
9390 int debug_delta
, debug_delta_bytes
;
9392 /* Values of window_end_pos and window_end_vpos at the end of
9395 EMACS_INT debug_end_pos
, debug_end_vpos
;
9397 /* Append a string to W->desired_matrix->method. FMT is a printf
9398 format string. A1...A9 are a supplement for a variable-length
9399 argument list. If trace_redisplay_p is non-zero also printf the
9400 resulting string to stderr. */
9403 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9406 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9409 char *method
= w
->desired_matrix
->method
;
9410 int len
= strlen (method
);
9411 int size
= sizeof w
->desired_matrix
->method
;
9412 int remaining
= size
- len
- 1;
9414 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9415 if (len
&& remaining
)
9421 strncpy (method
+ len
, buffer
, remaining
);
9423 if (trace_redisplay_p
)
9424 fprintf (stderr
, "%p (%s): %s\n",
9426 ((BUFFERP (w
->buffer
)
9427 && STRINGP (XBUFFER (w
->buffer
)->name
))
9428 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9433 #endif /* GLYPH_DEBUG */
9436 /* Value is non-zero if all changes in window W, which displays
9437 current_buffer, are in the text between START and END. START is a
9438 buffer position, END is given as a distance from Z. Used in
9439 redisplay_internal for display optimization. */
9442 text_outside_line_unchanged_p (w
, start
, end
)
9446 int unchanged_p
= 1;
9448 /* If text or overlays have changed, see where. */
9449 if (XFASTINT (w
->last_modified
) < MODIFF
9450 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9452 /* Gap in the line? */
9453 if (GPT
< start
|| Z
- GPT
< end
)
9456 /* Changes start in front of the line, or end after it? */
9458 && (BEG_UNCHANGED
< start
- 1
9459 || END_UNCHANGED
< end
))
9462 /* If selective display, can't optimize if changes start at the
9463 beginning of the line. */
9465 && INTEGERP (current_buffer
->selective_display
)
9466 && XINT (current_buffer
->selective_display
) > 0
9467 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9470 /* If there are overlays at the start or end of the line, these
9471 may have overlay strings with newlines in them. A change at
9472 START, for instance, may actually concern the display of such
9473 overlay strings as well, and they are displayed on different
9474 lines. So, quickly rule out this case. (For the future, it
9475 might be desirable to implement something more telling than
9476 just BEG/END_UNCHANGED.) */
9479 if (BEG
+ BEG_UNCHANGED
== start
9480 && overlay_touches_p (start
))
9482 if (END_UNCHANGED
== end
9483 && overlay_touches_p (Z
- end
))
9492 /* Do a frame update, taking possible shortcuts into account. This is
9493 the main external entry point for redisplay.
9495 If the last redisplay displayed an echo area message and that message
9496 is no longer requested, we clear the echo area or bring back the
9497 mini-buffer if that is in use. */
9502 redisplay_internal (0);
9507 overlay_arrow_string_or_property (var
, pbitmap
)
9511 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9517 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9518 *pbitmap
= XINT (bitmap
);
9523 return Voverlay_arrow_string
;
9526 /* Return 1 if there are any overlay-arrows in current_buffer. */
9528 overlay_arrow_in_current_buffer_p ()
9532 for (vlist
= Voverlay_arrow_variable_list
;
9534 vlist
= XCDR (vlist
))
9536 Lisp_Object var
= XCAR (vlist
);
9541 val
= find_symbol_value (var
);
9543 && current_buffer
== XMARKER (val
)->buffer
)
9550 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9554 overlay_arrows_changed_p ()
9558 for (vlist
= Voverlay_arrow_variable_list
;
9560 vlist
= XCDR (vlist
))
9562 Lisp_Object var
= XCAR (vlist
);
9563 Lisp_Object val
, pstr
;
9567 val
= find_symbol_value (var
);
9570 if (! EQ (COERCE_MARKER (val
),
9571 Fget (var
, Qlast_arrow_position
))
9572 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9573 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9579 /* Mark overlay arrows to be updated on next redisplay. */
9582 update_overlay_arrows (up_to_date
)
9587 for (vlist
= Voverlay_arrow_variable_list
;
9589 vlist
= XCDR (vlist
))
9591 Lisp_Object var
= XCAR (vlist
);
9598 Lisp_Object val
= find_symbol_value (var
);
9599 Fput (var
, Qlast_arrow_position
,
9600 COERCE_MARKER (val
));
9601 Fput (var
, Qlast_arrow_string
,
9602 overlay_arrow_string_or_property (var
, 0));
9604 else if (up_to_date
< 0
9605 || !NILP (Fget (var
, Qlast_arrow_position
)))
9607 Fput (var
, Qlast_arrow_position
, Qt
);
9608 Fput (var
, Qlast_arrow_string
, Qt
);
9614 /* Return overlay arrow string to display at row.
9615 Return t if display as bitmap in left fringe.
9616 Return nil if no overlay arrow. */
9619 overlay_arrow_at_row (it
, row
, pbitmap
)
9621 struct glyph_row
*row
;
9626 for (vlist
= Voverlay_arrow_variable_list
;
9628 vlist
= XCDR (vlist
))
9630 Lisp_Object var
= XCAR (vlist
);
9636 val
= find_symbol_value (var
);
9639 && current_buffer
== XMARKER (val
)->buffer
9640 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9642 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9643 if (FRAME_WINDOW_P (it
->f
)
9644 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9656 /* Return 1 if point moved out of or into a composition. Otherwise
9657 return 0. PREV_BUF and PREV_PT are the last point buffer and
9658 position. BUF and PT are the current point buffer and position. */
9661 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9662 struct buffer
*prev_buf
, *buf
;
9669 XSETBUFFER (buffer
, buf
);
9670 /* Check a composition at the last point if point moved within the
9672 if (prev_buf
== buf
)
9675 /* Point didn't move. */
9678 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9679 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9680 && COMPOSITION_VALID_P (start
, end
, prop
)
9681 && start
< prev_pt
&& end
> prev_pt
)
9682 /* The last point was within the composition. Return 1 iff
9683 point moved out of the composition. */
9684 return (pt
<= start
|| pt
>= end
);
9687 /* Check a composition at the current point. */
9688 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9689 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9690 && COMPOSITION_VALID_P (start
, end
, prop
)
9691 && start
< pt
&& end
> pt
);
9695 /* Reconsider the setting of B->clip_changed which is displayed
9699 reconsider_clip_changes (w
, b
)
9704 && !NILP (w
->window_end_valid
)
9705 && w
->current_matrix
->buffer
== b
9706 && w
->current_matrix
->zv
== BUF_ZV (b
)
9707 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9708 b
->clip_changed
= 0;
9710 /* If display wasn't paused, and W is not a tool bar window, see if
9711 point has been moved into or out of a composition. In that case,
9712 we set b->clip_changed to 1 to force updating the screen. If
9713 b->clip_changed has already been set to 1, we can skip this
9715 if (!b
->clip_changed
9716 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9720 if (w
== XWINDOW (selected_window
))
9721 pt
= BUF_PT (current_buffer
);
9723 pt
= marker_position (w
->pointm
);
9725 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9726 || pt
!= XINT (w
->last_point
))
9727 && check_point_in_composition (w
->current_matrix
->buffer
,
9728 XINT (w
->last_point
),
9729 XBUFFER (w
->buffer
), pt
))
9730 b
->clip_changed
= 1;
9735 /* Select FRAME to forward the values of frame-local variables into C
9736 variables so that the redisplay routines can access those values
9740 select_frame_for_redisplay (frame
)
9743 Lisp_Object tail
, sym
, val
;
9744 Lisp_Object old
= selected_frame
;
9746 selected_frame
= frame
;
9748 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9749 if (CONSP (XCAR (tail
))
9750 && (sym
= XCAR (XCAR (tail
)),
9752 && (sym
= indirect_variable (sym
),
9753 val
= SYMBOL_VALUE (sym
),
9754 (BUFFER_LOCAL_VALUEP (val
)
9755 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9756 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9757 Fsymbol_value (sym
);
9759 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9760 if (CONSP (XCAR (tail
))
9761 && (sym
= XCAR (XCAR (tail
)),
9763 && (sym
= indirect_variable (sym
),
9764 val
= SYMBOL_VALUE (sym
),
9765 (BUFFER_LOCAL_VALUEP (val
)
9766 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9767 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9768 Fsymbol_value (sym
);
9772 #define STOP_POLLING \
9773 do { if (! polling_stopped_here) stop_polling (); \
9774 polling_stopped_here = 1; } while (0)
9776 #define RESUME_POLLING \
9777 do { if (polling_stopped_here) start_polling (); \
9778 polling_stopped_here = 0; } while (0)
9781 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9782 response to any user action; therefore, we should preserve the echo
9783 area. (Actually, our caller does that job.) Perhaps in the future
9784 avoid recentering windows if it is not necessary; currently that
9785 causes some problems. */
9788 redisplay_internal (preserve_echo_area
)
9789 int preserve_echo_area
;
9791 struct window
*w
= XWINDOW (selected_window
);
9792 struct frame
*f
= XFRAME (w
->frame
);
9794 int must_finish
= 0;
9795 struct text_pos tlbufpos
, tlendpos
;
9796 int number_of_visible_frames
;
9798 struct frame
*sf
= SELECTED_FRAME ();
9799 int polling_stopped_here
= 0;
9801 /* Non-zero means redisplay has to consider all windows on all
9802 frames. Zero means, only selected_window is considered. */
9803 int consider_all_windows_p
;
9805 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9807 /* No redisplay if running in batch mode or frame is not yet fully
9808 initialized, or redisplay is explicitly turned off by setting
9809 Vinhibit_redisplay. */
9811 || !NILP (Vinhibit_redisplay
)
9812 || !f
->glyphs_initialized_p
)
9815 /* The flag redisplay_performed_directly_p is set by
9816 direct_output_for_insert when it already did the whole screen
9817 update necessary. */
9818 if (redisplay_performed_directly_p
)
9820 redisplay_performed_directly_p
= 0;
9821 if (!hscroll_windows (selected_window
))
9825 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9826 if (popup_activated ())
9830 /* I don't think this happens but let's be paranoid. */
9834 /* Record a function that resets redisplaying_p to its old value
9835 when we leave this function. */
9836 count
= SPECPDL_INDEX ();
9837 record_unwind_protect (unwind_redisplay
,
9838 Fcons (make_number (redisplaying_p
), selected_frame
));
9840 specbind (Qinhibit_free_realized_faces
, Qnil
);
9844 reconsider_clip_changes (w
, current_buffer
);
9846 /* If new fonts have been loaded that make a glyph matrix adjustment
9847 necessary, do it. */
9848 if (fonts_changed_p
)
9850 adjust_glyphs (NULL
);
9851 ++windows_or_buffers_changed
;
9852 fonts_changed_p
= 0;
9855 /* If face_change_count is non-zero, init_iterator will free all
9856 realized faces, which includes the faces referenced from current
9857 matrices. So, we can't reuse current matrices in this case. */
9858 if (face_change_count
)
9859 ++windows_or_buffers_changed
;
9861 if (! FRAME_WINDOW_P (sf
)
9862 && previous_terminal_frame
!= sf
)
9864 /* Since frames on an ASCII terminal share the same display
9865 area, displaying a different frame means redisplay the whole
9867 windows_or_buffers_changed
++;
9868 SET_FRAME_GARBAGED (sf
);
9869 XSETFRAME (Vterminal_frame
, sf
);
9871 previous_terminal_frame
= sf
;
9873 /* Set the visible flags for all frames. Do this before checking
9874 for resized or garbaged frames; they want to know if their frames
9875 are visible. See the comment in frame.h for
9876 FRAME_SAMPLE_VISIBILITY. */
9878 Lisp_Object tail
, frame
;
9880 number_of_visible_frames
= 0;
9882 FOR_EACH_FRAME (tail
, frame
)
9884 struct frame
*f
= XFRAME (frame
);
9886 FRAME_SAMPLE_VISIBILITY (f
);
9887 if (FRAME_VISIBLE_P (f
))
9888 ++number_of_visible_frames
;
9889 clear_desired_matrices (f
);
9893 /* Notice any pending interrupt request to change frame size. */
9894 do_pending_window_change (1);
9896 /* Clear frames marked as garbaged. */
9898 clear_garbaged_frames ();
9900 /* Build menubar and tool-bar items. */
9901 prepare_menu_bars ();
9903 if (windows_or_buffers_changed
)
9904 update_mode_lines
++;
9906 /* Detect case that we need to write or remove a star in the mode line. */
9907 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9909 w
->update_mode_line
= Qt
;
9910 if (buffer_shared
> 1)
9911 update_mode_lines
++;
9914 /* If %c is in the mode line, update it if needed. */
9915 if (!NILP (w
->column_number_displayed
)
9916 /* This alternative quickly identifies a common case
9917 where no change is needed. */
9918 && !(PT
== XFASTINT (w
->last_point
)
9919 && XFASTINT (w
->last_modified
) >= MODIFF
9920 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9921 && (XFASTINT (w
->column_number_displayed
)
9922 != (int) current_column ())) /* iftc */
9923 w
->update_mode_line
= Qt
;
9925 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9927 /* The variable buffer_shared is set in redisplay_window and
9928 indicates that we redisplay a buffer in different windows. See
9930 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9931 || cursor_type_changed
);
9933 /* If specs for an arrow have changed, do thorough redisplay
9934 to ensure we remove any arrow that should no longer exist. */
9935 if (overlay_arrows_changed_p ())
9936 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9938 /* Normally the message* functions will have already displayed and
9939 updated the echo area, but the frame may have been trashed, or
9940 the update may have been preempted, so display the echo area
9941 again here. Checking message_cleared_p captures the case that
9942 the echo area should be cleared. */
9943 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9944 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9945 || (message_cleared_p
9946 && minibuf_level
== 0
9947 /* If the mini-window is currently selected, this means the
9948 echo-area doesn't show through. */
9949 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9951 int window_height_changed_p
= echo_area_display (0);
9954 /* If we don't display the current message, don't clear the
9955 message_cleared_p flag, because, if we did, we wouldn't clear
9956 the echo area in the next redisplay which doesn't preserve
9958 if (!display_last_displayed_message_p
)
9959 message_cleared_p
= 0;
9961 if (fonts_changed_p
)
9963 else if (window_height_changed_p
)
9965 consider_all_windows_p
= 1;
9966 ++update_mode_lines
;
9967 ++windows_or_buffers_changed
;
9969 /* If window configuration was changed, frames may have been
9970 marked garbaged. Clear them or we will experience
9971 surprises wrt scrolling. */
9973 clear_garbaged_frames ();
9976 else if (EQ (selected_window
, minibuf_window
)
9977 && (current_buffer
->clip_changed
9978 || XFASTINT (w
->last_modified
) < MODIFF
9979 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9980 && resize_mini_window (w
, 0))
9982 /* Resized active mini-window to fit the size of what it is
9983 showing if its contents might have changed. */
9985 consider_all_windows_p
= 1;
9986 ++windows_or_buffers_changed
;
9987 ++update_mode_lines
;
9989 /* If window configuration was changed, frames may have been
9990 marked garbaged. Clear them or we will experience
9991 surprises wrt scrolling. */
9993 clear_garbaged_frames ();
9997 /* If showing the region, and mark has changed, we must redisplay
9998 the whole window. The assignment to this_line_start_pos prevents
9999 the optimization directly below this if-statement. */
10000 if (((!NILP (Vtransient_mark_mode
)
10001 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10002 != !NILP (w
->region_showing
))
10003 || (!NILP (w
->region_showing
)
10004 && !EQ (w
->region_showing
,
10005 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10006 CHARPOS (this_line_start_pos
) = 0;
10008 /* Optimize the case that only the line containing the cursor in the
10009 selected window has changed. Variables starting with this_ are
10010 set in display_line and record information about the line
10011 containing the cursor. */
10012 tlbufpos
= this_line_start_pos
;
10013 tlendpos
= this_line_end_pos
;
10014 if (!consider_all_windows_p
10015 && CHARPOS (tlbufpos
) > 0
10016 && NILP (w
->update_mode_line
)
10017 && !current_buffer
->clip_changed
10018 && !current_buffer
->prevent_redisplay_optimizations_p
10019 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10020 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10021 /* Make sure recorded data applies to current buffer, etc. */
10022 && this_line_buffer
== current_buffer
10023 && current_buffer
== XBUFFER (w
->buffer
)
10024 && NILP (w
->force_start
)
10025 && NILP (w
->optional_new_start
)
10026 /* Point must be on the line that we have info recorded about. */
10027 && PT
>= CHARPOS (tlbufpos
)
10028 && PT
<= Z
- CHARPOS (tlendpos
)
10029 /* All text outside that line, including its final newline,
10030 must be unchanged */
10031 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10032 CHARPOS (tlendpos
)))
10034 if (CHARPOS (tlbufpos
) > BEGV
10035 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10036 && (CHARPOS (tlbufpos
) == ZV
10037 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10038 /* Former continuation line has disappeared by becoming empty */
10040 else if (XFASTINT (w
->last_modified
) < MODIFF
10041 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10042 || MINI_WINDOW_P (w
))
10044 /* We have to handle the case of continuation around a
10045 wide-column character (See the comment in indent.c around
10048 For instance, in the following case:
10050 -------- Insert --------
10051 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10052 J_I_ ==> J_I_ `^^' are cursors.
10056 As we have to redraw the line above, we should goto cancel. */
10059 int line_height_before
= this_line_pixel_height
;
10061 /* Note that start_display will handle the case that the
10062 line starting at tlbufpos is a continuation lines. */
10063 start_display (&it
, w
, tlbufpos
);
10065 /* Implementation note: It this still necessary? */
10066 if (it
.current_x
!= this_line_start_x
)
10069 TRACE ((stderr
, "trying display optimization 1\n"));
10070 w
->cursor
.vpos
= -1;
10071 overlay_arrow_seen
= 0;
10072 it
.vpos
= this_line_vpos
;
10073 it
.current_y
= this_line_y
;
10074 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10075 display_line (&it
);
10077 /* If line contains point, is not continued,
10078 and ends at same distance from eob as before, we win */
10079 if (w
->cursor
.vpos
>= 0
10080 /* Line is not continued, otherwise this_line_start_pos
10081 would have been set to 0 in display_line. */
10082 && CHARPOS (this_line_start_pos
)
10083 /* Line ends as before. */
10084 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10085 /* Line has same height as before. Otherwise other lines
10086 would have to be shifted up or down. */
10087 && this_line_pixel_height
== line_height_before
)
10089 /* If this is not the window's last line, we must adjust
10090 the charstarts of the lines below. */
10091 if (it
.current_y
< it
.last_visible_y
)
10093 struct glyph_row
*row
10094 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10095 int delta
, delta_bytes
;
10097 if (Z
- CHARPOS (tlendpos
) == ZV
)
10099 /* This line ends at end of (accessible part of)
10100 buffer. There is no newline to count. */
10102 - CHARPOS (tlendpos
)
10103 - MATRIX_ROW_START_CHARPOS (row
));
10104 delta_bytes
= (Z_BYTE
10105 - BYTEPOS (tlendpos
)
10106 - MATRIX_ROW_START_BYTEPOS (row
));
10110 /* This line ends in a newline. Must take
10111 account of the newline and the rest of the
10112 text that follows. */
10114 - CHARPOS (tlendpos
)
10115 - MATRIX_ROW_START_CHARPOS (row
));
10116 delta_bytes
= (Z_BYTE
10117 - BYTEPOS (tlendpos
)
10118 - MATRIX_ROW_START_BYTEPOS (row
));
10121 increment_matrix_positions (w
->current_matrix
,
10122 this_line_vpos
+ 1,
10123 w
->current_matrix
->nrows
,
10124 delta
, delta_bytes
);
10127 /* If this row displays text now but previously didn't,
10128 or vice versa, w->window_end_vpos may have to be
10130 if ((it
.glyph_row
- 1)->displays_text_p
)
10132 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10133 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10135 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10136 && this_line_vpos
> 0)
10137 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10138 w
->window_end_valid
= Qnil
;
10140 /* Update hint: No need to try to scroll in update_window. */
10141 w
->desired_matrix
->no_scrolling_p
= 1;
10144 *w
->desired_matrix
->method
= 0;
10145 debug_method_add (w
, "optimization 1");
10147 #ifdef HAVE_WINDOW_SYSTEM
10148 update_window_fringes (w
, 0);
10155 else if (/* Cursor position hasn't changed. */
10156 PT
== XFASTINT (w
->last_point
)
10157 /* Make sure the cursor was last displayed
10158 in this window. Otherwise we have to reposition it. */
10159 && 0 <= w
->cursor
.vpos
10160 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10164 do_pending_window_change (1);
10166 /* We used to always goto end_of_redisplay here, but this
10167 isn't enough if we have a blinking cursor. */
10168 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10169 goto end_of_redisplay
;
10173 /* If highlighting the region, or if the cursor is in the echo area,
10174 then we can't just move the cursor. */
10175 else if (! (!NILP (Vtransient_mark_mode
)
10176 && !NILP (current_buffer
->mark_active
))
10177 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10178 || highlight_nonselected_windows
)
10179 && NILP (w
->region_showing
)
10180 && NILP (Vshow_trailing_whitespace
)
10181 && !cursor_in_echo_area
)
10184 struct glyph_row
*row
;
10186 /* Skip from tlbufpos to PT and see where it is. Note that
10187 PT may be in invisible text. If so, we will end at the
10188 next visible position. */
10189 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10190 NULL
, DEFAULT_FACE_ID
);
10191 it
.current_x
= this_line_start_x
;
10192 it
.current_y
= this_line_y
;
10193 it
.vpos
= this_line_vpos
;
10195 /* The call to move_it_to stops in front of PT, but
10196 moves over before-strings. */
10197 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10199 if (it
.vpos
== this_line_vpos
10200 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10203 xassert (this_line_vpos
== it
.vpos
);
10204 xassert (this_line_y
== it
.current_y
);
10205 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10207 *w
->desired_matrix
->method
= 0;
10208 debug_method_add (w
, "optimization 3");
10217 /* Text changed drastically or point moved off of line. */
10218 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10221 CHARPOS (this_line_start_pos
) = 0;
10222 consider_all_windows_p
|= buffer_shared
> 1;
10223 ++clear_face_cache_count
;
10226 /* Build desired matrices, and update the display. If
10227 consider_all_windows_p is non-zero, do it for all windows on all
10228 frames. Otherwise do it for selected_window, only. */
10230 if (consider_all_windows_p
)
10232 Lisp_Object tail
, frame
;
10233 int i
, n
= 0, size
= 50;
10234 struct frame
**updated
10235 = (struct frame
**) alloca (size
* sizeof *updated
);
10237 /* Clear the face cache eventually. */
10238 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10240 clear_face_cache (0);
10241 clear_face_cache_count
= 0;
10244 /* Recompute # windows showing selected buffer. This will be
10245 incremented each time such a window is displayed. */
10248 FOR_EACH_FRAME (tail
, frame
)
10250 struct frame
*f
= XFRAME (frame
);
10252 if (FRAME_WINDOW_P (f
) || f
== sf
)
10254 if (! EQ (frame
, selected_frame
))
10255 /* Select the frame, for the sake of frame-local
10257 select_frame_for_redisplay (frame
);
10259 #ifdef HAVE_WINDOW_SYSTEM
10260 if (clear_face_cache_count
% 50 == 0
10261 && FRAME_WINDOW_P (f
))
10262 clear_image_cache (f
, 0);
10263 #endif /* HAVE_WINDOW_SYSTEM */
10265 /* Mark all the scroll bars to be removed; we'll redeem
10266 the ones we want when we redisplay their windows. */
10267 if (condemn_scroll_bars_hook
)
10268 condemn_scroll_bars_hook (f
);
10270 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10271 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10273 /* Any scroll bars which redisplay_windows should have
10274 nuked should now go away. */
10275 if (judge_scroll_bars_hook
)
10276 judge_scroll_bars_hook (f
);
10278 /* If fonts changed, display again. */
10279 /* ??? rms: I suspect it is a mistake to jump all the way
10280 back to retry here. It should just retry this frame. */
10281 if (fonts_changed_p
)
10284 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10286 /* See if we have to hscroll. */
10287 if (hscroll_windows (f
->root_window
))
10290 /* Prevent various kinds of signals during display
10291 update. stdio is not robust about handling
10292 signals, which can cause an apparent I/O
10294 if (interrupt_input
)
10295 unrequest_sigio ();
10298 /* Update the display. */
10299 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10300 pause
|= update_frame (f
, 0, 0);
10301 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10308 int nbytes
= size
* sizeof *updated
;
10309 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10310 bcopy (updated
, p
, nbytes
);
10321 /* Do the mark_window_display_accurate after all windows have
10322 been redisplayed because this call resets flags in buffers
10323 which are needed for proper redisplay. */
10324 for (i
= 0; i
< n
; ++i
)
10326 struct frame
*f
= updated
[i
];
10327 mark_window_display_accurate (f
->root_window
, 1);
10328 if (frame_up_to_date_hook
)
10329 frame_up_to_date_hook (f
);
10333 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10335 Lisp_Object mini_window
;
10336 struct frame
*mini_frame
;
10338 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10339 /* Use list_of_error, not Qerror, so that
10340 we catch only errors and don't run the debugger. */
10341 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10343 redisplay_window_error
);
10345 /* Compare desired and current matrices, perform output. */
10348 /* If fonts changed, display again. */
10349 if (fonts_changed_p
)
10352 /* Prevent various kinds of signals during display update.
10353 stdio is not robust about handling signals,
10354 which can cause an apparent I/O error. */
10355 if (interrupt_input
)
10356 unrequest_sigio ();
10359 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10361 if (hscroll_windows (selected_window
))
10364 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10365 pause
= update_frame (sf
, 0, 0);
10368 /* We may have called echo_area_display at the top of this
10369 function. If the echo area is on another frame, that may
10370 have put text on a frame other than the selected one, so the
10371 above call to update_frame would not have caught it. Catch
10373 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10374 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10376 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10378 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10379 pause
|= update_frame (mini_frame
, 0, 0);
10380 if (!pause
&& hscroll_windows (mini_window
))
10385 /* If display was paused because of pending input, make sure we do a
10386 thorough update the next time. */
10389 /* Prevent the optimization at the beginning of
10390 redisplay_internal that tries a single-line update of the
10391 line containing the cursor in the selected window. */
10392 CHARPOS (this_line_start_pos
) = 0;
10394 /* Let the overlay arrow be updated the next time. */
10395 update_overlay_arrows (0);
10397 /* If we pause after scrolling, some rows in the current
10398 matrices of some windows are not valid. */
10399 if (!WINDOW_FULL_WIDTH_P (w
)
10400 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10401 update_mode_lines
= 1;
10405 if (!consider_all_windows_p
)
10407 /* This has already been done above if
10408 consider_all_windows_p is set. */
10409 mark_window_display_accurate_1 (w
, 1);
10411 /* Say overlay arrows are up to date. */
10412 update_overlay_arrows (1);
10414 if (frame_up_to_date_hook
!= 0)
10415 frame_up_to_date_hook (sf
);
10418 update_mode_lines
= 0;
10419 windows_or_buffers_changed
= 0;
10420 cursor_type_changed
= 0;
10423 /* Start SIGIO interrupts coming again. Having them off during the
10424 code above makes it less likely one will discard output, but not
10425 impossible, since there might be stuff in the system buffer here.
10426 But it is much hairier to try to do anything about that. */
10427 if (interrupt_input
)
10431 /* If a frame has become visible which was not before, redisplay
10432 again, so that we display it. Expose events for such a frame
10433 (which it gets when becoming visible) don't call the parts of
10434 redisplay constructing glyphs, so simply exposing a frame won't
10435 display anything in this case. So, we have to display these
10436 frames here explicitly. */
10439 Lisp_Object tail
, frame
;
10442 FOR_EACH_FRAME (tail
, frame
)
10444 int this_is_visible
= 0;
10446 if (XFRAME (frame
)->visible
)
10447 this_is_visible
= 1;
10448 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10449 if (XFRAME (frame
)->visible
)
10450 this_is_visible
= 1;
10452 if (this_is_visible
)
10456 if (new_count
!= number_of_visible_frames
)
10457 windows_or_buffers_changed
++;
10460 /* Change frame size now if a change is pending. */
10461 do_pending_window_change (1);
10463 /* If we just did a pending size change, or have additional
10464 visible frames, redisplay again. */
10465 if (windows_or_buffers_changed
&& !pause
)
10469 unbind_to (count
, Qnil
);
10474 /* Redisplay, but leave alone any recent echo area message unless
10475 another message has been requested in its place.
10477 This is useful in situations where you need to redisplay but no
10478 user action has occurred, making it inappropriate for the message
10479 area to be cleared. See tracking_off and
10480 wait_reading_process_output for examples of these situations.
10482 FROM_WHERE is an integer saying from where this function was
10483 called. This is useful for debugging. */
10486 redisplay_preserve_echo_area (from_where
)
10489 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10491 if (!NILP (echo_area_buffer
[1]))
10493 /* We have a previously displayed message, but no current
10494 message. Redisplay the previous message. */
10495 display_last_displayed_message_p
= 1;
10496 redisplay_internal (1);
10497 display_last_displayed_message_p
= 0;
10500 redisplay_internal (1);
10502 if (rif
!= NULL
&& rif
->flush_display_optional
)
10503 rif
->flush_display_optional (NULL
);
10507 /* Function registered with record_unwind_protect in
10508 redisplay_internal. Reset redisplaying_p to the value it had
10509 before redisplay_internal was called, and clear
10510 prevent_freeing_realized_faces_p. It also selects the previously
10514 unwind_redisplay (val
)
10517 Lisp_Object old_redisplaying_p
, old_frame
;
10519 old_redisplaying_p
= XCAR (val
);
10520 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10521 old_frame
= XCDR (val
);
10522 if (! EQ (old_frame
, selected_frame
))
10523 select_frame_for_redisplay (old_frame
);
10528 /* Mark the display of window W as accurate or inaccurate. If
10529 ACCURATE_P is non-zero mark display of W as accurate. If
10530 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10531 redisplay_internal is called. */
10534 mark_window_display_accurate_1 (w
, accurate_p
)
10538 if (BUFFERP (w
->buffer
))
10540 struct buffer
*b
= XBUFFER (w
->buffer
);
10543 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10544 w
->last_overlay_modified
10545 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10547 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10551 b
->clip_changed
= 0;
10552 b
->prevent_redisplay_optimizations_p
= 0;
10554 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10555 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10556 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10557 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10559 w
->current_matrix
->buffer
= b
;
10560 w
->current_matrix
->begv
= BUF_BEGV (b
);
10561 w
->current_matrix
->zv
= BUF_ZV (b
);
10563 w
->last_cursor
= w
->cursor
;
10564 w
->last_cursor_off_p
= w
->cursor_off_p
;
10566 if (w
== XWINDOW (selected_window
))
10567 w
->last_point
= make_number (BUF_PT (b
));
10569 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10575 w
->window_end_valid
= w
->buffer
;
10576 #if 0 /* This is incorrect with variable-height lines. */
10577 xassert (XINT (w
->window_end_vpos
)
10578 < (WINDOW_TOTAL_LINES (w
)
10579 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10581 w
->update_mode_line
= Qnil
;
10586 /* Mark the display of windows in the window tree rooted at WINDOW as
10587 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10588 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10589 be redisplayed the next time redisplay_internal is called. */
10592 mark_window_display_accurate (window
, accurate_p
)
10593 Lisp_Object window
;
10598 for (; !NILP (window
); window
= w
->next
)
10600 w
= XWINDOW (window
);
10601 mark_window_display_accurate_1 (w
, accurate_p
);
10603 if (!NILP (w
->vchild
))
10604 mark_window_display_accurate (w
->vchild
, accurate_p
);
10605 if (!NILP (w
->hchild
))
10606 mark_window_display_accurate (w
->hchild
, accurate_p
);
10611 update_overlay_arrows (1);
10615 /* Force a thorough redisplay the next time by setting
10616 last_arrow_position and last_arrow_string to t, which is
10617 unequal to any useful value of Voverlay_arrow_... */
10618 update_overlay_arrows (-1);
10623 /* Return value in display table DP (Lisp_Char_Table *) for character
10624 C. Since a display table doesn't have any parent, we don't have to
10625 follow parent. Do not call this function directly but use the
10626 macro DISP_CHAR_VECTOR. */
10629 disp_char_vector (dp
, c
)
10630 struct Lisp_Char_Table
*dp
;
10636 if (SINGLE_BYTE_CHAR_P (c
))
10637 return (dp
->contents
[c
]);
10639 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10642 else if (code
[2] < 32)
10645 /* Here, the possible range of code[0] (== charset ID) is
10646 128..max_charset. Since the top level char table contains data
10647 for multibyte characters after 256th element, we must increment
10648 code[0] by 128 to get a correct index. */
10650 code
[3] = -1; /* anchor */
10652 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10654 val
= dp
->contents
[code
[i
]];
10655 if (!SUB_CHAR_TABLE_P (val
))
10656 return (NILP (val
) ? dp
->defalt
: val
);
10659 /* Here, val is a sub char table. We return the default value of
10661 return (dp
->defalt
);
10666 /***********************************************************************
10668 ***********************************************************************/
10670 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10673 redisplay_windows (window
)
10674 Lisp_Object window
;
10676 while (!NILP (window
))
10678 struct window
*w
= XWINDOW (window
);
10680 if (!NILP (w
->hchild
))
10681 redisplay_windows (w
->hchild
);
10682 else if (!NILP (w
->vchild
))
10683 redisplay_windows (w
->vchild
);
10686 displayed_buffer
= XBUFFER (w
->buffer
);
10687 /* Use list_of_error, not Qerror, so that
10688 we catch only errors and don't run the debugger. */
10689 internal_condition_case_1 (redisplay_window_0
, window
,
10691 redisplay_window_error
);
10699 redisplay_window_error ()
10701 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10706 redisplay_window_0 (window
)
10707 Lisp_Object window
;
10709 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10710 redisplay_window (window
, 0);
10715 redisplay_window_1 (window
)
10716 Lisp_Object window
;
10718 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10719 redisplay_window (window
, 1);
10724 /* Increment GLYPH until it reaches END or CONDITION fails while
10725 adding (GLYPH)->pixel_width to X. */
10727 #define SKIP_GLYPHS(glyph, end, x, condition) \
10730 (x) += (glyph)->pixel_width; \
10733 while ((glyph) < (end) && (condition))
10736 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10737 DELTA is the number of bytes by which positions recorded in ROW
10738 differ from current buffer positions. */
10741 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10743 struct glyph_row
*row
;
10744 struct glyph_matrix
*matrix
;
10745 int delta
, delta_bytes
, dy
, dvpos
;
10747 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10748 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10749 struct glyph
*cursor
= NULL
;
10750 /* The first glyph that starts a sequence of glyphs from string. */
10751 struct glyph
*string_start
;
10752 /* The X coordinate of string_start. */
10753 int string_start_x
;
10754 /* The last known character position. */
10755 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10756 /* The last known character position before string_start. */
10757 int string_before_pos
;
10760 int cursor_from_overlay_pos
= 0;
10761 int pt_old
= PT
- delta
;
10763 /* Skip over glyphs not having an object at the start of the row.
10764 These are special glyphs like truncation marks on terminal
10766 if (row
->displays_text_p
)
10768 && INTEGERP (glyph
->object
)
10769 && glyph
->charpos
< 0)
10771 x
+= glyph
->pixel_width
;
10775 string_start
= NULL
;
10777 && !INTEGERP (glyph
->object
)
10778 && (!BUFFERP (glyph
->object
)
10779 || (last_pos
= glyph
->charpos
) < pt_old
))
10781 if (! STRINGP (glyph
->object
))
10783 string_start
= NULL
;
10784 x
+= glyph
->pixel_width
;
10786 if (cursor_from_overlay_pos
10787 && last_pos
> cursor_from_overlay_pos
)
10789 cursor_from_overlay_pos
= 0;
10795 string_before_pos
= last_pos
;
10796 string_start
= glyph
;
10797 string_start_x
= x
;
10798 /* Skip all glyphs from string. */
10802 if ((cursor
== NULL
|| glyph
> cursor
)
10803 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
10804 Qcursor
, (glyph
)->object
))
10805 && (pos
= string_buffer_position (w
, glyph
->object
,
10806 string_before_pos
),
10807 (pos
== 0 /* From overlay */
10808 || pos
== pt_old
)))
10810 /* Estimate overlay buffer position from the buffer
10811 positions of the glyphs before and after the overlay.
10812 Add 1 to last_pos so that if point corresponds to the
10813 glyph right after the overlay, we still use a 'cursor'
10814 property found in that overlay. */
10815 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
10819 x
+= glyph
->pixel_width
;
10822 while (glyph
< end
&& STRINGP (glyph
->object
));
10826 if (cursor
!= NULL
)
10831 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
10833 /* Scan back over the ellipsis glyphs, decrementing positions. */
10834 while (glyph
> row
->glyphs
[TEXT_AREA
]
10835 && (glyph
- 1)->charpos
== last_pos
)
10836 glyph
--, x
-= glyph
->pixel_width
;
10837 /* That loop always goes one position too far,
10838 including the glyph before the ellipsis.
10839 So scan forward over that one. */
10840 x
+= glyph
->pixel_width
;
10843 else if (string_start
10844 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10846 /* We may have skipped over point because the previous glyphs
10847 are from string. As there's no easy way to know the
10848 character position of the current glyph, find the correct
10849 glyph on point by scanning from string_start again. */
10851 Lisp_Object string
;
10854 limit
= make_number (pt_old
+ 1);
10856 glyph
= string_start
;
10857 x
= string_start_x
;
10858 string
= glyph
->object
;
10859 pos
= string_buffer_position (w
, string
, string_before_pos
);
10860 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10861 because we always put cursor after overlay strings. */
10862 while (pos
== 0 && glyph
< end
)
10864 string
= glyph
->object
;
10865 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10867 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10870 while (glyph
< end
)
10872 pos
= XINT (Fnext_single_char_property_change
10873 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10876 /* Skip glyphs from the same string. */
10877 string
= glyph
->object
;
10878 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10879 /* Skip glyphs from an overlay. */
10881 && ! string_buffer_position (w
, glyph
->object
, pos
))
10883 string
= glyph
->object
;
10884 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10889 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10891 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10892 w
->cursor
.y
= row
->y
+ dy
;
10894 if (w
== XWINDOW (selected_window
))
10896 if (!row
->continued_p
10897 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10900 this_line_buffer
= XBUFFER (w
->buffer
);
10902 CHARPOS (this_line_start_pos
)
10903 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10904 BYTEPOS (this_line_start_pos
)
10905 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10907 CHARPOS (this_line_end_pos
)
10908 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10909 BYTEPOS (this_line_end_pos
)
10910 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10912 this_line_y
= w
->cursor
.y
;
10913 this_line_pixel_height
= row
->height
;
10914 this_line_vpos
= w
->cursor
.vpos
;
10915 this_line_start_x
= row
->x
;
10918 CHARPOS (this_line_start_pos
) = 0;
10923 /* Run window scroll functions, if any, for WINDOW with new window
10924 start STARTP. Sets the window start of WINDOW to that position.
10926 We assume that the window's buffer is really current. */
10928 static INLINE
struct text_pos
10929 run_window_scroll_functions (window
, startp
)
10930 Lisp_Object window
;
10931 struct text_pos startp
;
10933 struct window
*w
= XWINDOW (window
);
10934 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10936 if (current_buffer
!= XBUFFER (w
->buffer
))
10939 if (!NILP (Vwindow_scroll_functions
))
10941 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10942 make_number (CHARPOS (startp
)));
10943 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10944 /* In case the hook functions switch buffers. */
10945 if (current_buffer
!= XBUFFER (w
->buffer
))
10946 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10953 /* Make sure the line containing the cursor is fully visible.
10954 A value of 1 means there is nothing to be done.
10955 (Either the line is fully visible, or it cannot be made so,
10956 or we cannot tell.)
10958 If FORCE_P is non-zero, return 0 even if partial visible cursor row
10959 is higher than window.
10961 A value of 0 means the caller should do scrolling
10962 as if point had gone off the screen. */
10965 make_cursor_line_fully_visible (w
, force_p
)
10969 struct glyph_matrix
*matrix
;
10970 struct glyph_row
*row
;
10973 if (!make_cursor_line_fully_visible_p
)
10976 /* It's not always possible to find the cursor, e.g, when a window
10977 is full of overlay strings. Don't do anything in that case. */
10978 if (w
->cursor
.vpos
< 0)
10981 matrix
= w
->desired_matrix
;
10982 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10984 /* If the cursor row is not partially visible, there's nothing to do. */
10985 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
10988 /* If the row the cursor is in is taller than the window's height,
10989 it's not clear what to do, so do nothing. */
10990 window_height
= window_box_height (w
);
10991 if (row
->height
>= window_height
)
10993 if (!force_p
|| w
->vscroll
)
10999 /* This code used to try to scroll the window just enough to make
11000 the line visible. It returned 0 to say that the caller should
11001 allocate larger glyph matrices. */
11003 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11005 int dy
= row
->height
- row
->visible_height
;
11008 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11010 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11012 int dy
= - (row
->height
- row
->visible_height
);
11015 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11018 /* When we change the cursor y-position of the selected window,
11019 change this_line_y as well so that the display optimization for
11020 the cursor line of the selected window in redisplay_internal uses
11021 the correct y-position. */
11022 if (w
== XWINDOW (selected_window
))
11023 this_line_y
= w
->cursor
.y
;
11025 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11026 redisplay with larger matrices. */
11027 if (matrix
->nrows
< required_matrix_height (w
))
11029 fonts_changed_p
= 1;
11038 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11039 non-zero means only WINDOW is redisplayed in redisplay_internal.
11040 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11041 in redisplay_window to bring a partially visible line into view in
11042 the case that only the cursor has moved.
11044 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11045 last screen line's vertical height extends past the end of the screen.
11049 1 if scrolling succeeded
11051 0 if scrolling didn't find point.
11053 -1 if new fonts have been loaded so that we must interrupt
11054 redisplay, adjust glyph matrices, and try again. */
11060 SCROLLING_NEED_LARGER_MATRICES
11064 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11065 scroll_step
, temp_scroll_step
, last_line_misfit
)
11066 Lisp_Object window
;
11067 int just_this_one_p
;
11068 EMACS_INT scroll_conservatively
, scroll_step
;
11069 int temp_scroll_step
;
11070 int last_line_misfit
;
11072 struct window
*w
= XWINDOW (window
);
11073 struct frame
*f
= XFRAME (w
->frame
);
11074 struct text_pos scroll_margin_pos
;
11075 struct text_pos pos
;
11076 struct text_pos startp
;
11078 Lisp_Object window_end
;
11079 int this_scroll_margin
;
11083 int amount_to_scroll
= 0;
11084 Lisp_Object aggressive
;
11086 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11089 debug_method_add (w
, "try_scrolling");
11092 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11094 /* Compute scroll margin height in pixels. We scroll when point is
11095 within this distance from the top or bottom of the window. */
11096 if (scroll_margin
> 0)
11098 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11099 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11102 this_scroll_margin
= 0;
11104 /* Force scroll_conservatively to have a reasonable value so it doesn't
11105 cause an overflow while computing how much to scroll. */
11106 if (scroll_conservatively
)
11107 scroll_conservatively
= min (scroll_conservatively
,
11108 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11110 /* Compute how much we should try to scroll maximally to bring point
11112 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11113 scroll_max
= max (scroll_step
,
11114 max (scroll_conservatively
, temp_scroll_step
));
11115 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11116 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11117 /* We're trying to scroll because of aggressive scrolling
11118 but no scroll_step is set. Choose an arbitrary one. Maybe
11119 there should be a variable for this. */
11123 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11125 /* Decide whether we have to scroll down. Start at the window end
11126 and move this_scroll_margin up to find the position of the scroll
11128 window_end
= Fwindow_end (window
, Qt
);
11132 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11133 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11135 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11137 start_display (&it
, w
, scroll_margin_pos
);
11138 if (this_scroll_margin
)
11139 move_it_vertically_backward (&it
, this_scroll_margin
);
11140 if (extra_scroll_margin_lines
)
11141 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11142 scroll_margin_pos
= it
.current
.pos
;
11145 if (PT
>= CHARPOS (scroll_margin_pos
))
11149 /* Point is in the scroll margin at the bottom of the window, or
11150 below. Compute a new window start that makes point visible. */
11152 /* Compute the distance from the scroll margin to PT.
11153 Give up if the distance is greater than scroll_max. */
11154 start_display (&it
, w
, scroll_margin_pos
);
11156 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11157 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11159 /* To make point visible, we have to move the window start
11160 down so that the line the cursor is in is visible, which
11161 means we have to add in the height of the cursor line. */
11162 dy
= line_bottom_y (&it
) - y0
;
11164 if (dy
> scroll_max
)
11165 return SCROLLING_FAILED
;
11167 /* Move the window start down. If scrolling conservatively,
11168 move it just enough down to make point visible. If
11169 scroll_step is set, move it down by scroll_step. */
11170 start_display (&it
, w
, startp
);
11172 if (scroll_conservatively
)
11173 /* Set AMOUNT_TO_SCROLL to at least one line,
11174 and at most scroll_conservatively lines. */
11176 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11177 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11178 else if (scroll_step
|| temp_scroll_step
)
11179 amount_to_scroll
= scroll_max
;
11182 aggressive
= current_buffer
->scroll_up_aggressively
;
11183 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11184 if (NUMBERP (aggressive
))
11186 double float_amount
= XFLOATINT (aggressive
) * height
;
11187 amount_to_scroll
= float_amount
;
11188 if (amount_to_scroll
== 0 && float_amount
> 0)
11189 amount_to_scroll
= 1;
11193 if (amount_to_scroll
<= 0)
11194 return SCROLLING_FAILED
;
11196 /* If moving by amount_to_scroll leaves STARTP unchanged,
11197 move it down one screen line. */
11199 move_it_vertically (&it
, amount_to_scroll
);
11200 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11201 move_it_by_lines (&it
, 1, 1);
11202 startp
= it
.current
.pos
;
11206 /* See if point is inside the scroll margin at the top of the
11208 scroll_margin_pos
= startp
;
11209 if (this_scroll_margin
)
11211 start_display (&it
, w
, startp
);
11212 move_it_vertically (&it
, this_scroll_margin
);
11213 scroll_margin_pos
= it
.current
.pos
;
11216 if (PT
< CHARPOS (scroll_margin_pos
))
11218 /* Point is in the scroll margin at the top of the window or
11219 above what is displayed in the window. */
11222 /* Compute the vertical distance from PT to the scroll
11223 margin position. Give up if distance is greater than
11225 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11226 start_display (&it
, w
, pos
);
11228 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11229 it
.last_visible_y
, -1,
11230 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11231 dy
= it
.current_y
- y0
;
11232 if (dy
> scroll_max
)
11233 return SCROLLING_FAILED
;
11235 /* Compute new window start. */
11236 start_display (&it
, w
, startp
);
11238 if (scroll_conservatively
)
11240 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11241 else if (scroll_step
|| temp_scroll_step
)
11242 amount_to_scroll
= scroll_max
;
11245 aggressive
= current_buffer
->scroll_down_aggressively
;
11246 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11247 if (NUMBERP (aggressive
))
11249 double float_amount
= XFLOATINT (aggressive
) * height
;
11250 amount_to_scroll
= float_amount
;
11251 if (amount_to_scroll
== 0 && float_amount
> 0)
11252 amount_to_scroll
= 1;
11256 if (amount_to_scroll
<= 0)
11257 return SCROLLING_FAILED
;
11259 move_it_vertically_backward (&it
, amount_to_scroll
);
11260 startp
= it
.current
.pos
;
11264 /* Run window scroll functions. */
11265 startp
= run_window_scroll_functions (window
, startp
);
11267 /* Display the window. Give up if new fonts are loaded, or if point
11269 if (!try_window (window
, startp
))
11270 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11271 else if (w
->cursor
.vpos
< 0)
11273 clear_glyph_matrix (w
->desired_matrix
);
11274 rc
= SCROLLING_FAILED
;
11278 /* Maybe forget recorded base line for line number display. */
11279 if (!just_this_one_p
11280 || current_buffer
->clip_changed
11281 || BEG_UNCHANGED
< CHARPOS (startp
))
11282 w
->base_line_number
= Qnil
;
11284 /* If cursor ends up on a partially visible line,
11285 treat that as being off the bottom of the screen. */
11286 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11288 clear_glyph_matrix (w
->desired_matrix
);
11289 ++extra_scroll_margin_lines
;
11292 rc
= SCROLLING_SUCCESS
;
11299 /* Compute a suitable window start for window W if display of W starts
11300 on a continuation line. Value is non-zero if a new window start
11303 The new window start will be computed, based on W's width, starting
11304 from the start of the continued line. It is the start of the
11305 screen line with the minimum distance from the old start W->start. */
11308 compute_window_start_on_continuation_line (w
)
11311 struct text_pos pos
, start_pos
;
11312 int window_start_changed_p
= 0;
11314 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11316 /* If window start is on a continuation line... Window start may be
11317 < BEGV in case there's invisible text at the start of the
11318 buffer (M-x rmail, for example). */
11319 if (CHARPOS (start_pos
) > BEGV
11320 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11323 struct glyph_row
*row
;
11325 /* Handle the case that the window start is out of range. */
11326 if (CHARPOS (start_pos
) < BEGV
)
11327 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11328 else if (CHARPOS (start_pos
) > ZV
)
11329 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11331 /* Find the start of the continued line. This should be fast
11332 because scan_buffer is fast (newline cache). */
11333 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11334 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11335 row
, DEFAULT_FACE_ID
);
11336 reseat_at_previous_visible_line_start (&it
);
11338 /* If the line start is "too far" away from the window start,
11339 say it takes too much time to compute a new window start. */
11340 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11341 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11343 int min_distance
, distance
;
11345 /* Move forward by display lines to find the new window
11346 start. If window width was enlarged, the new start can
11347 be expected to be > the old start. If window width was
11348 decreased, the new window start will be < the old start.
11349 So, we're looking for the display line start with the
11350 minimum distance from the old window start. */
11351 pos
= it
.current
.pos
;
11352 min_distance
= INFINITY
;
11353 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11354 distance
< min_distance
)
11356 min_distance
= distance
;
11357 pos
= it
.current
.pos
;
11358 move_it_by_lines (&it
, 1, 0);
11361 /* Set the window start there. */
11362 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11363 window_start_changed_p
= 1;
11367 return window_start_changed_p
;
11371 /* Try cursor movement in case text has not changed in window WINDOW,
11372 with window start STARTP. Value is
11374 CURSOR_MOVEMENT_SUCCESS if successful
11376 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11378 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11379 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11380 we want to scroll as if scroll-step were set to 1. See the code.
11382 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11383 which case we have to abort this redisplay, and adjust matrices
11388 CURSOR_MOVEMENT_SUCCESS
,
11389 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11390 CURSOR_MOVEMENT_MUST_SCROLL
,
11391 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11395 try_cursor_movement (window
, startp
, scroll_step
)
11396 Lisp_Object window
;
11397 struct text_pos startp
;
11400 struct window
*w
= XWINDOW (window
);
11401 struct frame
*f
= XFRAME (w
->frame
);
11402 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11405 if (inhibit_try_cursor_movement
)
11409 /* Handle case where text has not changed, only point, and it has
11410 not moved off the frame. */
11411 if (/* Point may be in this window. */
11412 PT
>= CHARPOS (startp
)
11413 /* Selective display hasn't changed. */
11414 && !current_buffer
->clip_changed
11415 /* Function force-mode-line-update is used to force a thorough
11416 redisplay. It sets either windows_or_buffers_changed or
11417 update_mode_lines. So don't take a shortcut here for these
11419 && !update_mode_lines
11420 && !windows_or_buffers_changed
11421 && !cursor_type_changed
11422 /* Can't use this case if highlighting a region. When a
11423 region exists, cursor movement has to do more than just
11425 && !(!NILP (Vtransient_mark_mode
)
11426 && !NILP (current_buffer
->mark_active
))
11427 && NILP (w
->region_showing
)
11428 && NILP (Vshow_trailing_whitespace
)
11429 /* Right after splitting windows, last_point may be nil. */
11430 && INTEGERP (w
->last_point
)
11431 /* This code is not used for mini-buffer for the sake of the case
11432 of redisplaying to replace an echo area message; since in
11433 that case the mini-buffer contents per se are usually
11434 unchanged. This code is of no real use in the mini-buffer
11435 since the handling of this_line_start_pos, etc., in redisplay
11436 handles the same cases. */
11437 && !EQ (window
, minibuf_window
)
11438 /* When splitting windows or for new windows, it happens that
11439 redisplay is called with a nil window_end_vpos or one being
11440 larger than the window. This should really be fixed in
11441 window.c. I don't have this on my list, now, so we do
11442 approximately the same as the old redisplay code. --gerd. */
11443 && INTEGERP (w
->window_end_vpos
)
11444 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11445 && (FRAME_WINDOW_P (f
)
11446 || !overlay_arrow_in_current_buffer_p ()))
11448 int this_scroll_margin
, top_scroll_margin
;
11449 struct glyph_row
*row
= NULL
;
11452 debug_method_add (w
, "cursor movement");
11455 /* Scroll if point within this distance from the top or bottom
11456 of the window. This is a pixel value. */
11457 this_scroll_margin
= max (0, scroll_margin
);
11458 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11459 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11461 top_scroll_margin
= this_scroll_margin
;
11462 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11463 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11465 /* Start with the row the cursor was displayed during the last
11466 not paused redisplay. Give up if that row is not valid. */
11467 if (w
->last_cursor
.vpos
< 0
11468 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11469 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11472 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11473 if (row
->mode_line_p
)
11475 if (!row
->enabled_p
)
11476 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11479 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11482 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11484 if (PT
> XFASTINT (w
->last_point
))
11486 /* Point has moved forward. */
11487 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11488 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11490 xassert (row
->enabled_p
);
11494 /* The end position of a row equals the start position
11495 of the next row. If PT is there, we would rather
11496 display it in the next line. */
11497 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11498 && MATRIX_ROW_END_CHARPOS (row
) == PT
11499 && !cursor_row_p (w
, row
))
11502 /* If within the scroll margin, scroll. Note that
11503 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11504 the next line would be drawn, and that
11505 this_scroll_margin can be zero. */
11506 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11507 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11508 /* Line is completely visible last line in window
11509 and PT is to be set in the next line. */
11510 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11511 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11512 && !row
->ends_at_zv_p
11513 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11516 else if (PT
< XFASTINT (w
->last_point
))
11518 /* Cursor has to be moved backward. Note that PT >=
11519 CHARPOS (startp) because of the outer if-statement. */
11520 while (!row
->mode_line_p
11521 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11522 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11523 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11524 && (row
->y
> top_scroll_margin
11525 || CHARPOS (startp
) == BEGV
))
11527 xassert (row
->enabled_p
);
11531 /* Consider the following case: Window starts at BEGV,
11532 there is invisible, intangible text at BEGV, so that
11533 display starts at some point START > BEGV. It can
11534 happen that we are called with PT somewhere between
11535 BEGV and START. Try to handle that case. */
11536 if (row
< w
->current_matrix
->rows
11537 || row
->mode_line_p
)
11539 row
= w
->current_matrix
->rows
;
11540 if (row
->mode_line_p
)
11544 /* Due to newlines in overlay strings, we may have to
11545 skip forward over overlay strings. */
11546 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11547 && MATRIX_ROW_END_CHARPOS (row
) == PT
11548 && !cursor_row_p (w
, row
))
11551 /* If within the scroll margin, scroll. */
11552 if (row
->y
< top_scroll_margin
11553 && CHARPOS (startp
) != BEGV
)
11557 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11558 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11560 /* if PT is not in the glyph row, give up. */
11561 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11563 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11564 && make_cursor_line_fully_visible_p
)
11566 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11567 && !row
->ends_at_zv_p
11568 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11569 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11570 else if (row
->height
> window_box_height (w
))
11572 /* If we end up in a partially visible line, let's
11573 make it fully visible, except when it's taller
11574 than the window, in which case we can't do much
11577 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11581 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11582 if (!make_cursor_line_fully_visible (w
, 0))
11583 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11585 rc
= CURSOR_MOVEMENT_SUCCESS
;
11589 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11592 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11593 rc
= CURSOR_MOVEMENT_SUCCESS
;
11602 set_vertical_scroll_bar (w
)
11605 int start
, end
, whole
;
11607 /* Calculate the start and end positions for the current window.
11608 At some point, it would be nice to choose between scrollbars
11609 which reflect the whole buffer size, with special markers
11610 indicating narrowing, and scrollbars which reflect only the
11613 Note that mini-buffers sometimes aren't displaying any text. */
11614 if (!MINI_WINDOW_P (w
)
11615 || (w
== XWINDOW (minibuf_window
)
11616 && NILP (echo_area_buffer
[0])))
11618 struct buffer
*buf
= XBUFFER (w
->buffer
);
11619 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11620 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11621 /* I don't think this is guaranteed to be right. For the
11622 moment, we'll pretend it is. */
11623 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11627 if (whole
< (end
- start
))
11628 whole
= end
- start
;
11631 start
= end
= whole
= 0;
11633 /* Indicate what this scroll bar ought to be displaying now. */
11634 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11638 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11639 selected_window is redisplayed.
11641 We can return without actually redisplaying the window if
11642 fonts_changed_p is nonzero. In that case, redisplay_internal will
11646 redisplay_window (window
, just_this_one_p
)
11647 Lisp_Object window
;
11648 int just_this_one_p
;
11650 struct window
*w
= XWINDOW (window
);
11651 struct frame
*f
= XFRAME (w
->frame
);
11652 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11653 struct buffer
*old
= current_buffer
;
11654 struct text_pos lpoint
, opoint
, startp
;
11655 int update_mode_line
;
11658 /* Record it now because it's overwritten. */
11659 int current_matrix_up_to_date_p
= 0;
11660 int used_current_matrix_p
= 0;
11661 /* This is less strict than current_matrix_up_to_date_p.
11662 It indictes that the buffer contents and narrowing are unchanged. */
11663 int buffer_unchanged_p
= 0;
11664 int temp_scroll_step
= 0;
11665 int count
= SPECPDL_INDEX ();
11667 int centering_position
;
11668 int last_line_misfit
= 0;
11670 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11673 /* W must be a leaf window here. */
11674 xassert (!NILP (w
->buffer
));
11676 *w
->desired_matrix
->method
= 0;
11679 specbind (Qinhibit_point_motion_hooks
, Qt
);
11681 reconsider_clip_changes (w
, buffer
);
11683 /* Has the mode line to be updated? */
11684 update_mode_line
= (!NILP (w
->update_mode_line
)
11685 || update_mode_lines
11686 || buffer
->clip_changed
11687 || buffer
->prevent_redisplay_optimizations_p
);
11689 if (MINI_WINDOW_P (w
))
11691 if (w
== XWINDOW (echo_area_window
)
11692 && !NILP (echo_area_buffer
[0]))
11694 if (update_mode_line
)
11695 /* We may have to update a tty frame's menu bar or a
11696 tool-bar. Example `M-x C-h C-h C-g'. */
11697 goto finish_menu_bars
;
11699 /* We've already displayed the echo area glyphs in this window. */
11700 goto finish_scroll_bars
;
11702 else if ((w
!= XWINDOW (minibuf_window
)
11703 || minibuf_level
== 0)
11704 /* When buffer is nonempty, redisplay window normally. */
11705 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11706 /* Quail displays non-mini buffers in minibuffer window.
11707 In that case, redisplay the window normally. */
11708 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11710 /* W is a mini-buffer window, but it's not active, so clear
11712 int yb
= window_text_bottom_y (w
);
11713 struct glyph_row
*row
;
11716 for (y
= 0, row
= w
->desired_matrix
->rows
;
11718 y
+= row
->height
, ++row
)
11719 blank_row (w
, row
, y
);
11720 goto finish_scroll_bars
;
11723 clear_glyph_matrix (w
->desired_matrix
);
11726 /* Otherwise set up data on this window; select its buffer and point
11728 /* Really select the buffer, for the sake of buffer-local
11730 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11731 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11733 current_matrix_up_to_date_p
11734 = (!NILP (w
->window_end_valid
)
11735 && !current_buffer
->clip_changed
11736 && !current_buffer
->prevent_redisplay_optimizations_p
11737 && XFASTINT (w
->last_modified
) >= MODIFF
11738 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11741 = (!NILP (w
->window_end_valid
)
11742 && !current_buffer
->clip_changed
11743 && XFASTINT (w
->last_modified
) >= MODIFF
11744 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11746 /* When windows_or_buffers_changed is non-zero, we can't rely on
11747 the window end being valid, so set it to nil there. */
11748 if (windows_or_buffers_changed
)
11750 /* If window starts on a continuation line, maybe adjust the
11751 window start in case the window's width changed. */
11752 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11753 compute_window_start_on_continuation_line (w
);
11755 w
->window_end_valid
= Qnil
;
11758 /* Some sanity checks. */
11759 CHECK_WINDOW_END (w
);
11760 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11762 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11765 /* If %c is in mode line, update it if needed. */
11766 if (!NILP (w
->column_number_displayed
)
11767 /* This alternative quickly identifies a common case
11768 where no change is needed. */
11769 && !(PT
== XFASTINT (w
->last_point
)
11770 && XFASTINT (w
->last_modified
) >= MODIFF
11771 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11772 && (XFASTINT (w
->column_number_displayed
)
11773 != (int) current_column ())) /* iftc */
11774 update_mode_line
= 1;
11776 /* Count number of windows showing the selected buffer. An indirect
11777 buffer counts as its base buffer. */
11778 if (!just_this_one_p
)
11780 struct buffer
*current_base
, *window_base
;
11781 current_base
= current_buffer
;
11782 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11783 if (current_base
->base_buffer
)
11784 current_base
= current_base
->base_buffer
;
11785 if (window_base
->base_buffer
)
11786 window_base
= window_base
->base_buffer
;
11787 if (current_base
== window_base
)
11791 /* Point refers normally to the selected window. For any other
11792 window, set up appropriate value. */
11793 if (!EQ (window
, selected_window
))
11795 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11796 int new_pt_byte
= marker_byte_position (w
->pointm
);
11800 new_pt_byte
= BEGV_BYTE
;
11801 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11803 else if (new_pt
> (ZV
- 1))
11806 new_pt_byte
= ZV_BYTE
;
11807 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11810 /* We don't use SET_PT so that the point-motion hooks don't run. */
11811 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11814 /* If any of the character widths specified in the display table
11815 have changed, invalidate the width run cache. It's true that
11816 this may be a bit late to catch such changes, but the rest of
11817 redisplay goes (non-fatally) haywire when the display table is
11818 changed, so why should we worry about doing any better? */
11819 if (current_buffer
->width_run_cache
)
11821 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11823 if (! disptab_matches_widthtab (disptab
,
11824 XVECTOR (current_buffer
->width_table
)))
11826 invalidate_region_cache (current_buffer
,
11827 current_buffer
->width_run_cache
,
11829 recompute_width_table (current_buffer
, disptab
);
11833 /* If window-start is screwed up, choose a new one. */
11834 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11837 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11839 /* If someone specified a new starting point but did not insist,
11840 check whether it can be used. */
11841 if (!NILP (w
->optional_new_start
)
11842 && CHARPOS (startp
) >= BEGV
11843 && CHARPOS (startp
) <= ZV
)
11845 w
->optional_new_start
= Qnil
;
11846 start_display (&it
, w
, startp
);
11847 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11848 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11849 if (IT_CHARPOS (it
) == PT
)
11850 w
->force_start
= Qt
;
11851 /* IT may overshoot PT if text at PT is invisible. */
11852 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11853 w
->force_start
= Qt
;
11858 /* Handle case where place to start displaying has been specified,
11859 unless the specified location is outside the accessible range. */
11860 if (!NILP (w
->force_start
)
11861 || w
->frozen_window_start_p
)
11863 /* We set this later on if we have to adjust point. */
11866 w
->force_start
= Qnil
;
11868 w
->window_end_valid
= Qnil
;
11870 /* Forget any recorded base line for line number display. */
11871 if (!buffer_unchanged_p
)
11872 w
->base_line_number
= Qnil
;
11874 /* Redisplay the mode line. Select the buffer properly for that.
11875 Also, run the hook window-scroll-functions
11876 because we have scrolled. */
11877 /* Note, we do this after clearing force_start because
11878 if there's an error, it is better to forget about force_start
11879 than to get into an infinite loop calling the hook functions
11880 and having them get more errors. */
11881 if (!update_mode_line
11882 || ! NILP (Vwindow_scroll_functions
))
11884 update_mode_line
= 1;
11885 w
->update_mode_line
= Qt
;
11886 startp
= run_window_scroll_functions (window
, startp
);
11889 w
->last_modified
= make_number (0);
11890 w
->last_overlay_modified
= make_number (0);
11891 if (CHARPOS (startp
) < BEGV
)
11892 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11893 else if (CHARPOS (startp
) > ZV
)
11894 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11896 /* Redisplay, then check if cursor has been set during the
11897 redisplay. Give up if new fonts were loaded. */
11898 if (!try_window (window
, startp
))
11900 w
->force_start
= Qt
;
11901 clear_glyph_matrix (w
->desired_matrix
);
11902 goto need_larger_matrices
;
11905 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11907 /* If point does not appear, try to move point so it does
11908 appear. The desired matrix has been built above, so we
11909 can use it here. */
11910 new_vpos
= window_box_height (w
) / 2;
11913 if (!make_cursor_line_fully_visible (w
, 0))
11915 /* Point does appear, but on a line partly visible at end of window.
11916 Move it back to a fully-visible line. */
11917 new_vpos
= window_box_height (w
);
11920 /* If we need to move point for either of the above reasons,
11921 now actually do it. */
11924 struct glyph_row
*row
;
11926 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11927 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11930 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11931 MATRIX_ROW_START_BYTEPOS (row
));
11933 if (w
!= XWINDOW (selected_window
))
11934 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11935 else if (current_buffer
== old
)
11936 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11938 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11940 /* If we are highlighting the region, then we just changed
11941 the region, so redisplay to show it. */
11942 if (!NILP (Vtransient_mark_mode
)
11943 && !NILP (current_buffer
->mark_active
))
11945 clear_glyph_matrix (w
->desired_matrix
);
11946 if (!try_window (window
, startp
))
11947 goto need_larger_matrices
;
11952 debug_method_add (w
, "forced window start");
11957 /* Handle case where text has not changed, only point, and it has
11958 not moved off the frame, and we are not retrying after hscroll.
11959 (current_matrix_up_to_date_p is nonzero when retrying.) */
11960 if (current_matrix_up_to_date_p
11961 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11962 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11966 case CURSOR_MOVEMENT_SUCCESS
:
11967 used_current_matrix_p
= 1;
11970 #if 0 /* try_cursor_movement never returns this value. */
11971 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11972 goto need_larger_matrices
;
11975 case CURSOR_MOVEMENT_MUST_SCROLL
:
11976 goto try_to_scroll
;
11982 /* If current starting point was originally the beginning of a line
11983 but no longer is, find a new starting point. */
11984 else if (!NILP (w
->start_at_line_beg
)
11985 && !(CHARPOS (startp
) <= BEGV
11986 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11989 debug_method_add (w
, "recenter 1");
11994 /* Try scrolling with try_window_id. Value is > 0 if update has
11995 been done, it is -1 if we know that the same window start will
11996 not work. It is 0 if unsuccessful for some other reason. */
11997 else if ((tem
= try_window_id (w
)) != 0)
12000 debug_method_add (w
, "try_window_id %d", tem
);
12003 if (fonts_changed_p
)
12004 goto need_larger_matrices
;
12008 /* Otherwise try_window_id has returned -1 which means that we
12009 don't want the alternative below this comment to execute. */
12011 else if (CHARPOS (startp
) >= BEGV
12012 && CHARPOS (startp
) <= ZV
12013 && PT
>= CHARPOS (startp
)
12014 && (CHARPOS (startp
) < ZV
12015 /* Avoid starting at end of buffer. */
12016 || CHARPOS (startp
) == BEGV
12017 || (XFASTINT (w
->last_modified
) >= MODIFF
12018 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12021 debug_method_add (w
, "same window start");
12024 /* Try to redisplay starting at same place as before.
12025 If point has not moved off frame, accept the results. */
12026 if (!current_matrix_up_to_date_p
12027 /* Don't use try_window_reusing_current_matrix in this case
12028 because a window scroll function can have changed the
12030 || !NILP (Vwindow_scroll_functions
)
12031 || MINI_WINDOW_P (w
)
12032 || !(used_current_matrix_p
12033 = try_window_reusing_current_matrix (w
)))
12035 IF_DEBUG (debug_method_add (w
, "1"));
12036 try_window (window
, startp
);
12039 if (fonts_changed_p
)
12040 goto need_larger_matrices
;
12042 if (w
->cursor
.vpos
>= 0)
12044 if (!just_this_one_p
12045 || current_buffer
->clip_changed
12046 || BEG_UNCHANGED
< CHARPOS (startp
))
12047 /* Forget any recorded base line for line number display. */
12048 w
->base_line_number
= Qnil
;
12050 if (!make_cursor_line_fully_visible (w
, 1))
12052 clear_glyph_matrix (w
->desired_matrix
);
12053 last_line_misfit
= 1;
12055 /* Drop through and scroll. */
12060 clear_glyph_matrix (w
->desired_matrix
);
12065 w
->last_modified
= make_number (0);
12066 w
->last_overlay_modified
= make_number (0);
12068 /* Redisplay the mode line. Select the buffer properly for that. */
12069 if (!update_mode_line
)
12071 update_mode_line
= 1;
12072 w
->update_mode_line
= Qt
;
12075 /* Try to scroll by specified few lines. */
12076 if ((scroll_conservatively
12078 || temp_scroll_step
12079 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12080 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12081 && !current_buffer
->clip_changed
12082 && CHARPOS (startp
) >= BEGV
12083 && CHARPOS (startp
) <= ZV
)
12085 /* The function returns -1 if new fonts were loaded, 1 if
12086 successful, 0 if not successful. */
12087 int rc
= try_scrolling (window
, just_this_one_p
,
12088 scroll_conservatively
,
12090 temp_scroll_step
, last_line_misfit
);
12093 case SCROLLING_SUCCESS
:
12096 case SCROLLING_NEED_LARGER_MATRICES
:
12097 goto need_larger_matrices
;
12099 case SCROLLING_FAILED
:
12107 /* Finally, just choose place to start which centers point */
12110 centering_position
= window_box_height (w
) / 2;
12113 /* Jump here with centering_position already set to 0. */
12116 debug_method_add (w
, "recenter");
12119 /* w->vscroll = 0; */
12121 /* Forget any previously recorded base line for line number display. */
12122 if (!buffer_unchanged_p
)
12123 w
->base_line_number
= Qnil
;
12125 /* Move backward half the height of the window. */
12126 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12127 it
.current_y
= it
.last_visible_y
;
12128 move_it_vertically_backward (&it
, centering_position
);
12129 xassert (IT_CHARPOS (it
) >= BEGV
);
12131 /* The function move_it_vertically_backward may move over more
12132 than the specified y-distance. If it->w is small, e.g. a
12133 mini-buffer window, we may end up in front of the window's
12134 display area. Start displaying at the start of the line
12135 containing PT in this case. */
12136 if (it
.current_y
<= 0)
12138 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12139 move_it_vertically_backward (&it
, 0);
12140 xassert (IT_CHARPOS (it
) <= PT
);
12144 it
.current_x
= it
.hpos
= 0;
12146 /* Set startp here explicitly in case that helps avoid an infinite loop
12147 in case the window-scroll-functions functions get errors. */
12148 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12150 /* Run scroll hooks. */
12151 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12153 /* Redisplay the window. */
12154 if (!current_matrix_up_to_date_p
12155 || windows_or_buffers_changed
12156 || cursor_type_changed
12157 /* Don't use try_window_reusing_current_matrix in this case
12158 because it can have changed the buffer. */
12159 || !NILP (Vwindow_scroll_functions
)
12160 || !just_this_one_p
12161 || MINI_WINDOW_P (w
)
12162 || !(used_current_matrix_p
12163 = try_window_reusing_current_matrix (w
)))
12164 try_window (window
, startp
);
12166 /* If new fonts have been loaded (due to fontsets), give up. We
12167 have to start a new redisplay since we need to re-adjust glyph
12169 if (fonts_changed_p
)
12170 goto need_larger_matrices
;
12172 /* If cursor did not appear assume that the middle of the window is
12173 in the first line of the window. Do it again with the next line.
12174 (Imagine a window of height 100, displaying two lines of height
12175 60. Moving back 50 from it->last_visible_y will end in the first
12177 if (w
->cursor
.vpos
< 0)
12179 if (!NILP (w
->window_end_valid
)
12180 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12182 clear_glyph_matrix (w
->desired_matrix
);
12183 move_it_by_lines (&it
, 1, 0);
12184 try_window (window
, it
.current
.pos
);
12186 else if (PT
< IT_CHARPOS (it
))
12188 clear_glyph_matrix (w
->desired_matrix
);
12189 move_it_by_lines (&it
, -1, 0);
12190 try_window (window
, it
.current
.pos
);
12194 /* Not much we can do about it. */
12198 /* Consider the following case: Window starts at BEGV, there is
12199 invisible, intangible text at BEGV, so that display starts at
12200 some point START > BEGV. It can happen that we are called with
12201 PT somewhere between BEGV and START. Try to handle that case. */
12202 if (w
->cursor
.vpos
< 0)
12204 struct glyph_row
*row
= w
->current_matrix
->rows
;
12205 if (row
->mode_line_p
)
12207 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12210 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12212 /* If vscroll is enabled, disable it and try again. */
12216 clear_glyph_matrix (w
->desired_matrix
);
12220 /* If centering point failed to make the whole line visible,
12221 put point at the top instead. That has to make the whole line
12222 visible, if it can be done. */
12223 clear_glyph_matrix (w
->desired_matrix
);
12224 centering_position
= 0;
12230 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12231 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12232 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12235 /* Display the mode line, if we must. */
12236 if ((update_mode_line
12237 /* If window not full width, must redo its mode line
12238 if (a) the window to its side is being redone and
12239 (b) we do a frame-based redisplay. This is a consequence
12240 of how inverted lines are drawn in frame-based redisplay. */
12241 || (!just_this_one_p
12242 && !FRAME_WINDOW_P (f
)
12243 && !WINDOW_FULL_WIDTH_P (w
))
12244 /* Line number to display. */
12245 || INTEGERP (w
->base_line_pos
)
12246 /* Column number is displayed and different from the one displayed. */
12247 || (!NILP (w
->column_number_displayed
)
12248 && (XFASTINT (w
->column_number_displayed
)
12249 != (int) current_column ()))) /* iftc */
12250 /* This means that the window has a mode line. */
12251 && (WINDOW_WANTS_MODELINE_P (w
)
12252 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12254 display_mode_lines (w
);
12256 /* If mode line height has changed, arrange for a thorough
12257 immediate redisplay using the correct mode line height. */
12258 if (WINDOW_WANTS_MODELINE_P (w
)
12259 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12261 fonts_changed_p
= 1;
12262 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12263 = DESIRED_MODE_LINE_HEIGHT (w
);
12266 /* If top line height has changed, arrange for a thorough
12267 immediate redisplay using the correct mode line height. */
12268 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12269 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12271 fonts_changed_p
= 1;
12272 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12273 = DESIRED_HEADER_LINE_HEIGHT (w
);
12276 if (fonts_changed_p
)
12277 goto need_larger_matrices
;
12280 if (!line_number_displayed
12281 && !BUFFERP (w
->base_line_pos
))
12283 w
->base_line_pos
= Qnil
;
12284 w
->base_line_number
= Qnil
;
12289 /* When we reach a frame's selected window, redo the frame's menu bar. */
12290 if (update_mode_line
12291 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12293 int redisplay_menu_p
= 0;
12294 int redisplay_tool_bar_p
= 0;
12296 if (FRAME_WINDOW_P (f
))
12298 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12299 || defined (USE_GTK)
12300 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12302 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12306 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12308 if (redisplay_menu_p
)
12309 display_menu_bar (w
);
12311 #ifdef HAVE_WINDOW_SYSTEM
12313 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12315 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12316 && (FRAME_TOOL_BAR_LINES (f
) > 0
12317 || auto_resize_tool_bars_p
);
12321 if (redisplay_tool_bar_p
)
12322 redisplay_tool_bar (f
);
12326 #ifdef HAVE_WINDOW_SYSTEM
12327 if (FRAME_WINDOW_P (f
)
12328 && update_window_fringes (w
, 0)
12329 && !just_this_one_p
12330 && (used_current_matrix_p
|| overlay_arrow_seen
)
12331 && !w
->pseudo_window_p
)
12335 if (draw_window_fringes (w
, 1))
12336 x_draw_vertical_border (w
);
12340 #endif /* HAVE_WINDOW_SYSTEM */
12342 /* We go to this label, with fonts_changed_p nonzero,
12343 if it is necessary to try again using larger glyph matrices.
12344 We have to redeem the scroll bar even in this case,
12345 because the loop in redisplay_internal expects that. */
12346 need_larger_matrices
:
12348 finish_scroll_bars
:
12350 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12352 /* Set the thumb's position and size. */
12353 set_vertical_scroll_bar (w
);
12355 /* Note that we actually used the scroll bar attached to this
12356 window, so it shouldn't be deleted at the end of redisplay. */
12357 redeem_scroll_bar_hook (w
);
12360 /* Restore current_buffer and value of point in it. */
12361 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12362 set_buffer_internal_1 (old
);
12363 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12365 unbind_to (count
, Qnil
);
12369 /* Build the complete desired matrix of WINDOW with a window start
12370 buffer position POS. Value is non-zero if successful. It is zero
12371 if fonts were loaded during redisplay which makes re-adjusting
12372 glyph matrices necessary. */
12375 try_window (window
, pos
)
12376 Lisp_Object window
;
12377 struct text_pos pos
;
12379 struct window
*w
= XWINDOW (window
);
12381 struct glyph_row
*last_text_row
= NULL
;
12383 /* Make POS the new window start. */
12384 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12386 /* Mark cursor position as unknown. No overlay arrow seen. */
12387 w
->cursor
.vpos
= -1;
12388 overlay_arrow_seen
= 0;
12390 /* Initialize iterator and info to start at POS. */
12391 start_display (&it
, w
, pos
);
12393 /* Display all lines of W. */
12394 while (it
.current_y
< it
.last_visible_y
)
12396 if (display_line (&it
))
12397 last_text_row
= it
.glyph_row
- 1;
12398 if (fonts_changed_p
)
12402 /* If bottom moved off end of frame, change mode line percentage. */
12403 if (XFASTINT (w
->window_end_pos
) <= 0
12404 && Z
!= IT_CHARPOS (it
))
12405 w
->update_mode_line
= Qt
;
12407 /* Set window_end_pos to the offset of the last character displayed
12408 on the window from the end of current_buffer. Set
12409 window_end_vpos to its row number. */
12412 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12413 w
->window_end_bytepos
12414 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12416 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12418 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12419 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12420 ->displays_text_p
);
12424 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12425 w
->window_end_pos
= make_number (Z
- ZV
);
12426 w
->window_end_vpos
= make_number (0);
12429 /* But that is not valid info until redisplay finishes. */
12430 w
->window_end_valid
= Qnil
;
12436 /************************************************************************
12437 Window redisplay reusing current matrix when buffer has not changed
12438 ************************************************************************/
12440 /* Try redisplay of window W showing an unchanged buffer with a
12441 different window start than the last time it was displayed by
12442 reusing its current matrix. Value is non-zero if successful.
12443 W->start is the new window start. */
12446 try_window_reusing_current_matrix (w
)
12449 struct frame
*f
= XFRAME (w
->frame
);
12450 struct glyph_row
*row
, *bottom_row
;
12453 struct text_pos start
, new_start
;
12454 int nrows_scrolled
, i
;
12455 struct glyph_row
*last_text_row
;
12456 struct glyph_row
*last_reused_text_row
;
12457 struct glyph_row
*start_row
;
12458 int start_vpos
, min_y
, max_y
;
12461 if (inhibit_try_window_reusing
)
12465 if (/* This function doesn't handle terminal frames. */
12466 !FRAME_WINDOW_P (f
)
12467 /* Don't try to reuse the display if windows have been split
12469 || windows_or_buffers_changed
12470 || cursor_type_changed
)
12473 /* Can't do this if region may have changed. */
12474 if ((!NILP (Vtransient_mark_mode
)
12475 && !NILP (current_buffer
->mark_active
))
12476 || !NILP (w
->region_showing
)
12477 || !NILP (Vshow_trailing_whitespace
))
12480 /* If top-line visibility has changed, give up. */
12481 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12482 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12485 /* Give up if old or new display is scrolled vertically. We could
12486 make this function handle this, but right now it doesn't. */
12487 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12488 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12491 /* The variable new_start now holds the new window start. The old
12492 start `start' can be determined from the current matrix. */
12493 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12494 start
= start_row
->start
.pos
;
12495 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12497 /* Clear the desired matrix for the display below. */
12498 clear_glyph_matrix (w
->desired_matrix
);
12500 if (CHARPOS (new_start
) <= CHARPOS (start
))
12504 /* Don't use this method if the display starts with an ellipsis
12505 displayed for invisible text. It's not easy to handle that case
12506 below, and it's certainly not worth the effort since this is
12507 not a frequent case. */
12508 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12511 IF_DEBUG (debug_method_add (w
, "twu1"));
12513 /* Display up to a row that can be reused. The variable
12514 last_text_row is set to the last row displayed that displays
12515 text. Note that it.vpos == 0 if or if not there is a
12516 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12517 start_display (&it
, w
, new_start
);
12518 first_row_y
= it
.current_y
;
12519 w
->cursor
.vpos
= -1;
12520 last_text_row
= last_reused_text_row
= NULL
;
12522 while (it
.current_y
< it
.last_visible_y
12523 && !fonts_changed_p
)
12525 /* If we have reached into the characters in the START row,
12526 that means the line boundaries have changed. So we
12527 can't start copying with the row START. Maybe it will
12528 work to start copying with the following row. */
12529 while (IT_CHARPOS (it
) > CHARPOS (start
))
12531 /* Advance to the next row as the "start". */
12533 start
= start_row
->start
.pos
;
12534 /* If there are no more rows to try, or just one, give up. */
12535 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12536 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12537 || CHARPOS (start
) == ZV
)
12539 clear_glyph_matrix (w
->desired_matrix
);
12543 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12545 /* If we have reached alignment,
12546 we can copy the rest of the rows. */
12547 if (IT_CHARPOS (it
) == CHARPOS (start
))
12550 if (display_line (&it
))
12551 last_text_row
= it
.glyph_row
- 1;
12554 /* A value of current_y < last_visible_y means that we stopped
12555 at the previous window start, which in turn means that we
12556 have at least one reusable row. */
12557 if (it
.current_y
< it
.last_visible_y
)
12559 /* IT.vpos always starts from 0; it counts text lines. */
12560 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12562 /* Find PT if not already found in the lines displayed. */
12563 if (w
->cursor
.vpos
< 0)
12565 int dy
= it
.current_y
- start_row
->y
;
12567 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12568 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12570 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12571 dy
, nrows_scrolled
);
12574 clear_glyph_matrix (w
->desired_matrix
);
12579 /* Scroll the display. Do it before the current matrix is
12580 changed. The problem here is that update has not yet
12581 run, i.e. part of the current matrix is not up to date.
12582 scroll_run_hook will clear the cursor, and use the
12583 current matrix to get the height of the row the cursor is
12585 run
.current_y
= start_row
->y
;
12586 run
.desired_y
= it
.current_y
;
12587 run
.height
= it
.last_visible_y
- it
.current_y
;
12589 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12592 rif
->update_window_begin_hook (w
);
12593 rif
->clear_window_mouse_face (w
);
12594 rif
->scroll_run_hook (w
, &run
);
12595 rif
->update_window_end_hook (w
, 0, 0);
12599 /* Shift current matrix down by nrows_scrolled lines. */
12600 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12601 rotate_matrix (w
->current_matrix
,
12603 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12606 /* Disable lines that must be updated. */
12607 for (i
= 0; i
< it
.vpos
; ++i
)
12608 (start_row
+ i
)->enabled_p
= 0;
12610 /* Re-compute Y positions. */
12611 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12612 max_y
= it
.last_visible_y
;
12613 for (row
= start_row
+ nrows_scrolled
;
12617 row
->y
= it
.current_y
;
12618 row
->visible_height
= row
->height
;
12620 if (row
->y
< min_y
)
12621 row
->visible_height
-= min_y
- row
->y
;
12622 if (row
->y
+ row
->height
> max_y
)
12623 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12624 row
->redraw_fringe_bitmaps_p
= 1;
12626 it
.current_y
+= row
->height
;
12628 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12629 last_reused_text_row
= row
;
12630 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12634 /* Disable lines in the current matrix which are now
12635 below the window. */
12636 for (++row
; row
< bottom_row
; ++row
)
12637 row
->enabled_p
= 0;
12640 /* Update window_end_pos etc.; last_reused_text_row is the last
12641 reused row from the current matrix containing text, if any.
12642 The value of last_text_row is the last displayed line
12643 containing text. */
12644 if (last_reused_text_row
)
12646 w
->window_end_bytepos
12647 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12649 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12651 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12652 w
->current_matrix
));
12654 else if (last_text_row
)
12656 w
->window_end_bytepos
12657 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12659 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12661 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12665 /* This window must be completely empty. */
12666 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12667 w
->window_end_pos
= make_number (Z
- ZV
);
12668 w
->window_end_vpos
= make_number (0);
12670 w
->window_end_valid
= Qnil
;
12672 /* Update hint: don't try scrolling again in update_window. */
12673 w
->desired_matrix
->no_scrolling_p
= 1;
12676 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12680 else if (CHARPOS (new_start
) > CHARPOS (start
))
12682 struct glyph_row
*pt_row
, *row
;
12683 struct glyph_row
*first_reusable_row
;
12684 struct glyph_row
*first_row_to_display
;
12686 int yb
= window_text_bottom_y (w
);
12688 /* Find the row starting at new_start, if there is one. Don't
12689 reuse a partially visible line at the end. */
12690 first_reusable_row
= start_row
;
12691 while (first_reusable_row
->enabled_p
12692 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12693 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12694 < CHARPOS (new_start
)))
12695 ++first_reusable_row
;
12697 /* Give up if there is no row to reuse. */
12698 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12699 || !first_reusable_row
->enabled_p
12700 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12701 != CHARPOS (new_start
)))
12704 /* We can reuse fully visible rows beginning with
12705 first_reusable_row to the end of the window. Set
12706 first_row_to_display to the first row that cannot be reused.
12707 Set pt_row to the row containing point, if there is any. */
12709 for (first_row_to_display
= first_reusable_row
;
12710 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12711 ++first_row_to_display
)
12713 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12714 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12715 pt_row
= first_row_to_display
;
12718 /* Start displaying at the start of first_row_to_display. */
12719 xassert (first_row_to_display
->y
< yb
);
12720 init_to_row_start (&it
, w
, first_row_to_display
);
12722 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12724 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12726 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12727 + WINDOW_HEADER_LINE_HEIGHT (w
));
12729 /* Display lines beginning with first_row_to_display in the
12730 desired matrix. Set last_text_row to the last row displayed
12731 that displays text. */
12732 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12733 if (pt_row
== NULL
)
12734 w
->cursor
.vpos
= -1;
12735 last_text_row
= NULL
;
12736 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12737 if (display_line (&it
))
12738 last_text_row
= it
.glyph_row
- 1;
12740 /* Give up If point isn't in a row displayed or reused. */
12741 if (w
->cursor
.vpos
< 0)
12743 clear_glyph_matrix (w
->desired_matrix
);
12747 /* If point is in a reused row, adjust y and vpos of the cursor
12751 w
->cursor
.vpos
-= nrows_scrolled
;
12752 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
12755 /* Scroll the display. */
12756 run
.current_y
= first_reusable_row
->y
;
12757 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12758 run
.height
= it
.last_visible_y
- run
.current_y
;
12759 dy
= run
.current_y
- run
.desired_y
;
12764 rif
->update_window_begin_hook (w
);
12765 rif
->clear_window_mouse_face (w
);
12766 rif
->scroll_run_hook (w
, &run
);
12767 rif
->update_window_end_hook (w
, 0, 0);
12771 /* Adjust Y positions of reused rows. */
12772 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12773 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12774 max_y
= it
.last_visible_y
;
12775 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12778 row
->visible_height
= row
->height
;
12779 if (row
->y
< min_y
)
12780 row
->visible_height
-= min_y
- row
->y
;
12781 if (row
->y
+ row
->height
> max_y
)
12782 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12783 row
->redraw_fringe_bitmaps_p
= 1;
12786 /* Scroll the current matrix. */
12787 xassert (nrows_scrolled
> 0);
12788 rotate_matrix (w
->current_matrix
,
12790 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12793 /* Disable rows not reused. */
12794 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12795 row
->enabled_p
= 0;
12797 /* Point may have moved to a different line, so we cannot assume that
12798 the previous cursor position is valid; locate the correct row. */
12801 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12802 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
12806 w
->cursor
.y
= row
->y
;
12808 if (row
< bottom_row
)
12810 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
12811 while (glyph
->charpos
< PT
)
12814 w
->cursor
.x
+= glyph
->pixel_width
;
12820 /* Adjust window end. A null value of last_text_row means that
12821 the window end is in reused rows which in turn means that
12822 only its vpos can have changed. */
12825 w
->window_end_bytepos
12826 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12828 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12830 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12835 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12838 w
->window_end_valid
= Qnil
;
12839 w
->desired_matrix
->no_scrolling_p
= 1;
12842 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12852 /************************************************************************
12853 Window redisplay reusing current matrix when buffer has changed
12854 ************************************************************************/
12856 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12857 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12859 static struct glyph_row
*
12860 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12861 struct glyph_row
*));
12864 /* Return the last row in MATRIX displaying text. If row START is
12865 non-null, start searching with that row. IT gives the dimensions
12866 of the display. Value is null if matrix is empty; otherwise it is
12867 a pointer to the row found. */
12869 static struct glyph_row
*
12870 find_last_row_displaying_text (matrix
, it
, start
)
12871 struct glyph_matrix
*matrix
;
12873 struct glyph_row
*start
;
12875 struct glyph_row
*row
, *row_found
;
12877 /* Set row_found to the last row in IT->w's current matrix
12878 displaying text. The loop looks funny but think of partially
12881 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12882 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12884 xassert (row
->enabled_p
);
12886 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12895 /* Return the last row in the current matrix of W that is not affected
12896 by changes at the start of current_buffer that occurred since W's
12897 current matrix was built. Value is null if no such row exists.
12899 BEG_UNCHANGED us the number of characters unchanged at the start of
12900 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12901 first changed character in current_buffer. Characters at positions <
12902 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12903 when the current matrix was built. */
12905 static struct glyph_row
*
12906 find_last_unchanged_at_beg_row (w
)
12909 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12910 struct glyph_row
*row
;
12911 struct glyph_row
*row_found
= NULL
;
12912 int yb
= window_text_bottom_y (w
);
12914 /* Find the last row displaying unchanged text. */
12915 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12916 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12917 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12919 if (/* If row ends before first_changed_pos, it is unchanged,
12920 except in some case. */
12921 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12922 /* When row ends in ZV and we write at ZV it is not
12924 && !row
->ends_at_zv_p
12925 /* When first_changed_pos is the end of a continued line,
12926 row is not unchanged because it may be no longer
12928 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12929 && (row
->continued_p
12930 || row
->exact_window_width_line_p
)))
12933 /* Stop if last visible row. */
12934 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12944 /* Find the first glyph row in the current matrix of W that is not
12945 affected by changes at the end of current_buffer since the
12946 time W's current matrix was built.
12948 Return in *DELTA the number of chars by which buffer positions in
12949 unchanged text at the end of current_buffer must be adjusted.
12951 Return in *DELTA_BYTES the corresponding number of bytes.
12953 Value is null if no such row exists, i.e. all rows are affected by
12956 static struct glyph_row
*
12957 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12959 int *delta
, *delta_bytes
;
12961 struct glyph_row
*row
;
12962 struct glyph_row
*row_found
= NULL
;
12964 *delta
= *delta_bytes
= 0;
12966 /* Display must not have been paused, otherwise the current matrix
12967 is not up to date. */
12968 if (NILP (w
->window_end_valid
))
12971 /* A value of window_end_pos >= END_UNCHANGED means that the window
12972 end is in the range of changed text. If so, there is no
12973 unchanged row at the end of W's current matrix. */
12974 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12977 /* Set row to the last row in W's current matrix displaying text. */
12978 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12980 /* If matrix is entirely empty, no unchanged row exists. */
12981 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12983 /* The value of row is the last glyph row in the matrix having a
12984 meaningful buffer position in it. The end position of row
12985 corresponds to window_end_pos. This allows us to translate
12986 buffer positions in the current matrix to current buffer
12987 positions for characters not in changed text. */
12988 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12989 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12990 int last_unchanged_pos
, last_unchanged_pos_old
;
12991 struct glyph_row
*first_text_row
12992 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12994 *delta
= Z
- Z_old
;
12995 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12997 /* Set last_unchanged_pos to the buffer position of the last
12998 character in the buffer that has not been changed. Z is the
12999 index + 1 of the last character in current_buffer, i.e. by
13000 subtracting END_UNCHANGED we get the index of the last
13001 unchanged character, and we have to add BEG to get its buffer
13003 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13004 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13006 /* Search backward from ROW for a row displaying a line that
13007 starts at a minimum position >= last_unchanged_pos_old. */
13008 for (; row
> first_text_row
; --row
)
13010 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13013 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13018 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13025 /* Make sure that glyph rows in the current matrix of window W
13026 reference the same glyph memory as corresponding rows in the
13027 frame's frame matrix. This function is called after scrolling W's
13028 current matrix on a terminal frame in try_window_id and
13029 try_window_reusing_current_matrix. */
13032 sync_frame_with_window_matrix_rows (w
)
13035 struct frame
*f
= XFRAME (w
->frame
);
13036 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13038 /* Preconditions: W must be a leaf window and full-width. Its frame
13039 must have a frame matrix. */
13040 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13041 xassert (WINDOW_FULL_WIDTH_P (w
));
13042 xassert (!FRAME_WINDOW_P (f
));
13044 /* If W is a full-width window, glyph pointers in W's current matrix
13045 have, by definition, to be the same as glyph pointers in the
13046 corresponding frame matrix. Note that frame matrices have no
13047 marginal areas (see build_frame_matrix). */
13048 window_row
= w
->current_matrix
->rows
;
13049 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13050 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13051 while (window_row
< window_row_end
)
13053 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13054 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13056 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13057 frame_row
->glyphs
[TEXT_AREA
] = start
;
13058 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13059 frame_row
->glyphs
[LAST_AREA
] = end
;
13061 /* Disable frame rows whose corresponding window rows have
13062 been disabled in try_window_id. */
13063 if (!window_row
->enabled_p
)
13064 frame_row
->enabled_p
= 0;
13066 ++window_row
, ++frame_row
;
13071 /* Find the glyph row in window W containing CHARPOS. Consider all
13072 rows between START and END (not inclusive). END null means search
13073 all rows to the end of the display area of W. Value is the row
13074 containing CHARPOS or null. */
13077 row_containing_pos (w
, charpos
, start
, end
, dy
)
13080 struct glyph_row
*start
, *end
;
13083 struct glyph_row
*row
= start
;
13086 /* If we happen to start on a header-line, skip that. */
13087 if (row
->mode_line_p
)
13090 if ((end
&& row
>= end
) || !row
->enabled_p
)
13093 last_y
= window_text_bottom_y (w
) - dy
;
13097 /* Give up if we have gone too far. */
13098 if (end
&& row
>= end
)
13100 /* This formerly returned if they were equal.
13101 I think that both quantities are of a "last plus one" type;
13102 if so, when they are equal, the row is within the screen. -- rms. */
13103 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13106 /* If it is in this row, return this row. */
13107 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13108 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13109 /* The end position of a row equals the start
13110 position of the next row. If CHARPOS is there, we
13111 would rather display it in the next line, except
13112 when this line ends in ZV. */
13113 && !row
->ends_at_zv_p
13114 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13115 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13122 /* Try to redisplay window W by reusing its existing display. W's
13123 current matrix must be up to date when this function is called,
13124 i.e. window_end_valid must not be nil.
13128 1 if display has been updated
13129 0 if otherwise unsuccessful
13130 -1 if redisplay with same window start is known not to succeed
13132 The following steps are performed:
13134 1. Find the last row in the current matrix of W that is not
13135 affected by changes at the start of current_buffer. If no such row
13138 2. Find the first row in W's current matrix that is not affected by
13139 changes at the end of current_buffer. Maybe there is no such row.
13141 3. Display lines beginning with the row + 1 found in step 1 to the
13142 row found in step 2 or, if step 2 didn't find a row, to the end of
13145 4. If cursor is not known to appear on the window, give up.
13147 5. If display stopped at the row found in step 2, scroll the
13148 display and current matrix as needed.
13150 6. Maybe display some lines at the end of W, if we must. This can
13151 happen under various circumstances, like a partially visible line
13152 becoming fully visible, or because newly displayed lines are displayed
13153 in smaller font sizes.
13155 7. Update W's window end information. */
13161 struct frame
*f
= XFRAME (w
->frame
);
13162 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13163 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13164 struct glyph_row
*last_unchanged_at_beg_row
;
13165 struct glyph_row
*first_unchanged_at_end_row
;
13166 struct glyph_row
*row
;
13167 struct glyph_row
*bottom_row
;
13170 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13171 struct text_pos start_pos
;
13173 int first_unchanged_at_end_vpos
= 0;
13174 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13175 struct text_pos start
;
13176 int first_changed_charpos
, last_changed_charpos
;
13179 if (inhibit_try_window_id
)
13183 /* This is handy for debugging. */
13185 #define GIVE_UP(X) \
13187 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13191 #define GIVE_UP(X) return 0
13194 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13196 /* Don't use this for mini-windows because these can show
13197 messages and mini-buffers, and we don't handle that here. */
13198 if (MINI_WINDOW_P (w
))
13201 /* This flag is used to prevent redisplay optimizations. */
13202 if (windows_or_buffers_changed
|| cursor_type_changed
)
13205 /* Verify that narrowing has not changed.
13206 Also verify that we were not told to prevent redisplay optimizations.
13207 It would be nice to further
13208 reduce the number of cases where this prevents try_window_id. */
13209 if (current_buffer
->clip_changed
13210 || current_buffer
->prevent_redisplay_optimizations_p
)
13213 /* Window must either use window-based redisplay or be full width. */
13214 if (!FRAME_WINDOW_P (f
)
13215 && (!line_ins_del_ok
13216 || !WINDOW_FULL_WIDTH_P (w
)))
13219 /* Give up if point is not known NOT to appear in W. */
13220 if (PT
< CHARPOS (start
))
13223 /* Another way to prevent redisplay optimizations. */
13224 if (XFASTINT (w
->last_modified
) == 0)
13227 /* Verify that window is not hscrolled. */
13228 if (XFASTINT (w
->hscroll
) != 0)
13231 /* Verify that display wasn't paused. */
13232 if (NILP (w
->window_end_valid
))
13235 /* Can't use this if highlighting a region because a cursor movement
13236 will do more than just set the cursor. */
13237 if (!NILP (Vtransient_mark_mode
)
13238 && !NILP (current_buffer
->mark_active
))
13241 /* Likewise if highlighting trailing whitespace. */
13242 if (!NILP (Vshow_trailing_whitespace
))
13245 /* Likewise if showing a region. */
13246 if (!NILP (w
->region_showing
))
13249 /* Can use this if overlay arrow position and or string have changed. */
13250 if (overlay_arrows_changed_p ())
13254 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13255 only if buffer has really changed. The reason is that the gap is
13256 initially at Z for freshly visited files. The code below would
13257 set end_unchanged to 0 in that case. */
13258 if (MODIFF
> SAVE_MODIFF
13259 /* This seems to happen sometimes after saving a buffer. */
13260 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13262 if (GPT
- BEG
< BEG_UNCHANGED
)
13263 BEG_UNCHANGED
= GPT
- BEG
;
13264 if (Z
- GPT
< END_UNCHANGED
)
13265 END_UNCHANGED
= Z
- GPT
;
13268 /* The position of the first and last character that has been changed. */
13269 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13270 last_changed_charpos
= Z
- END_UNCHANGED
;
13272 /* If window starts after a line end, and the last change is in
13273 front of that newline, then changes don't affect the display.
13274 This case happens with stealth-fontification. Note that although
13275 the display is unchanged, glyph positions in the matrix have to
13276 be adjusted, of course. */
13277 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13278 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13279 && ((last_changed_charpos
< CHARPOS (start
)
13280 && CHARPOS (start
) == BEGV
)
13281 || (last_changed_charpos
< CHARPOS (start
) - 1
13282 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13284 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13285 struct glyph_row
*r0
;
13287 /* Compute how many chars/bytes have been added to or removed
13288 from the buffer. */
13289 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13290 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13292 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13294 /* Give up if PT is not in the window. Note that it already has
13295 been checked at the start of try_window_id that PT is not in
13296 front of the window start. */
13297 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13300 /* If window start is unchanged, we can reuse the whole matrix
13301 as is, after adjusting glyph positions. No need to compute
13302 the window end again, since its offset from Z hasn't changed. */
13303 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13304 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13305 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13306 /* PT must not be in a partially visible line. */
13307 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13308 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13310 /* Adjust positions in the glyph matrix. */
13311 if (delta
|| delta_bytes
)
13313 struct glyph_row
*r1
13314 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13315 increment_matrix_positions (w
->current_matrix
,
13316 MATRIX_ROW_VPOS (r0
, current_matrix
),
13317 MATRIX_ROW_VPOS (r1
, current_matrix
),
13318 delta
, delta_bytes
);
13321 /* Set the cursor. */
13322 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13324 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13331 /* Handle the case that changes are all below what is displayed in
13332 the window, and that PT is in the window. This shortcut cannot
13333 be taken if ZV is visible in the window, and text has been added
13334 there that is visible in the window. */
13335 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13336 /* ZV is not visible in the window, or there are no
13337 changes at ZV, actually. */
13338 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13339 || first_changed_charpos
== last_changed_charpos
))
13341 struct glyph_row
*r0
;
13343 /* Give up if PT is not in the window. Note that it already has
13344 been checked at the start of try_window_id that PT is not in
13345 front of the window start. */
13346 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13349 /* If window start is unchanged, we can reuse the whole matrix
13350 as is, without changing glyph positions since no text has
13351 been added/removed in front of the window end. */
13352 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13353 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13354 /* PT must not be in a partially visible line. */
13355 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13356 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13358 /* We have to compute the window end anew since text
13359 can have been added/removed after it. */
13361 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13362 w
->window_end_bytepos
13363 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13365 /* Set the cursor. */
13366 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13368 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13375 /* Give up if window start is in the changed area.
13377 The condition used to read
13379 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13381 but why that was tested escapes me at the moment. */
13382 if (CHARPOS (start
) >= first_changed_charpos
13383 && CHARPOS (start
) <= last_changed_charpos
)
13386 /* Check that window start agrees with the start of the first glyph
13387 row in its current matrix. Check this after we know the window
13388 start is not in changed text, otherwise positions would not be
13390 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13391 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13394 /* Give up if the window ends in strings. Overlay strings
13395 at the end are difficult to handle, so don't try. */
13396 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13397 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13400 /* Compute the position at which we have to start displaying new
13401 lines. Some of the lines at the top of the window might be
13402 reusable because they are not displaying changed text. Find the
13403 last row in W's current matrix not affected by changes at the
13404 start of current_buffer. Value is null if changes start in the
13405 first line of window. */
13406 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13407 if (last_unchanged_at_beg_row
)
13409 /* Avoid starting to display in the moddle of a character, a TAB
13410 for instance. This is easier than to set up the iterator
13411 exactly, and it's not a frequent case, so the additional
13412 effort wouldn't really pay off. */
13413 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13414 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13415 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13416 --last_unchanged_at_beg_row
;
13418 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13421 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13423 start_pos
= it
.current
.pos
;
13425 /* Start displaying new lines in the desired matrix at the same
13426 vpos we would use in the current matrix, i.e. below
13427 last_unchanged_at_beg_row. */
13428 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13430 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13431 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13433 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13437 /* There are no reusable lines at the start of the window.
13438 Start displaying in the first text line. */
13439 start_display (&it
, w
, start
);
13440 it
.vpos
= it
.first_vpos
;
13441 start_pos
= it
.current
.pos
;
13444 /* Find the first row that is not affected by changes at the end of
13445 the buffer. Value will be null if there is no unchanged row, in
13446 which case we must redisplay to the end of the window. delta
13447 will be set to the value by which buffer positions beginning with
13448 first_unchanged_at_end_row have to be adjusted due to text
13450 first_unchanged_at_end_row
13451 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13452 IF_DEBUG (debug_delta
= delta
);
13453 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13455 /* Set stop_pos to the buffer position up to which we will have to
13456 display new lines. If first_unchanged_at_end_row != NULL, this
13457 is the buffer position of the start of the line displayed in that
13458 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13459 that we don't stop at a buffer position. */
13461 if (first_unchanged_at_end_row
)
13463 xassert (last_unchanged_at_beg_row
== NULL
13464 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13466 /* If this is a continuation line, move forward to the next one
13467 that isn't. Changes in lines above affect this line.
13468 Caution: this may move first_unchanged_at_end_row to a row
13469 not displaying text. */
13470 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13471 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13472 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13473 < it
.last_visible_y
))
13474 ++first_unchanged_at_end_row
;
13476 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13477 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13478 >= it
.last_visible_y
))
13479 first_unchanged_at_end_row
= NULL
;
13482 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13484 first_unchanged_at_end_vpos
13485 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13486 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13489 else if (last_unchanged_at_beg_row
== NULL
)
13495 /* Either there is no unchanged row at the end, or the one we have
13496 now displays text. This is a necessary condition for the window
13497 end pos calculation at the end of this function. */
13498 xassert (first_unchanged_at_end_row
== NULL
13499 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13501 debug_last_unchanged_at_beg_vpos
13502 = (last_unchanged_at_beg_row
13503 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13505 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13507 #endif /* GLYPH_DEBUG != 0 */
13510 /* Display new lines. Set last_text_row to the last new line
13511 displayed which has text on it, i.e. might end up as being the
13512 line where the window_end_vpos is. */
13513 w
->cursor
.vpos
= -1;
13514 last_text_row
= NULL
;
13515 overlay_arrow_seen
= 0;
13516 while (it
.current_y
< it
.last_visible_y
13517 && !fonts_changed_p
13518 && (first_unchanged_at_end_row
== NULL
13519 || IT_CHARPOS (it
) < stop_pos
))
13521 if (display_line (&it
))
13522 last_text_row
= it
.glyph_row
- 1;
13525 if (fonts_changed_p
)
13529 /* Compute differences in buffer positions, y-positions etc. for
13530 lines reused at the bottom of the window. Compute what we can
13532 if (first_unchanged_at_end_row
13533 /* No lines reused because we displayed everything up to the
13534 bottom of the window. */
13535 && it
.current_y
< it
.last_visible_y
)
13538 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13540 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13541 run
.current_y
= first_unchanged_at_end_row
->y
;
13542 run
.desired_y
= run
.current_y
+ dy
;
13543 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13547 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13548 first_unchanged_at_end_row
= NULL
;
13550 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13553 /* Find the cursor if not already found. We have to decide whether
13554 PT will appear on this window (it sometimes doesn't, but this is
13555 not a very frequent case.) This decision has to be made before
13556 the current matrix is altered. A value of cursor.vpos < 0 means
13557 that PT is either in one of the lines beginning at
13558 first_unchanged_at_end_row or below the window. Don't care for
13559 lines that might be displayed later at the window end; as
13560 mentioned, this is not a frequent case. */
13561 if (w
->cursor
.vpos
< 0)
13563 /* Cursor in unchanged rows at the top? */
13564 if (PT
< CHARPOS (start_pos
)
13565 && last_unchanged_at_beg_row
)
13567 row
= row_containing_pos (w
, PT
,
13568 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13569 last_unchanged_at_beg_row
+ 1, 0);
13571 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13574 /* Start from first_unchanged_at_end_row looking for PT. */
13575 else if (first_unchanged_at_end_row
)
13577 row
= row_containing_pos (w
, PT
- delta
,
13578 first_unchanged_at_end_row
, NULL
, 0);
13580 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13581 delta_bytes
, dy
, dvpos
);
13584 /* Give up if cursor was not found. */
13585 if (w
->cursor
.vpos
< 0)
13587 clear_glyph_matrix (w
->desired_matrix
);
13592 /* Don't let the cursor end in the scroll margins. */
13594 int this_scroll_margin
, cursor_height
;
13596 this_scroll_margin
= max (0, scroll_margin
);
13597 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13598 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13599 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13601 if ((w
->cursor
.y
< this_scroll_margin
13602 && CHARPOS (start
) > BEGV
)
13603 /* Old redisplay didn't take scroll margin into account at the bottom,
13604 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13605 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13606 ? cursor_height
+ this_scroll_margin
13607 : 1)) > it
.last_visible_y
)
13609 w
->cursor
.vpos
= -1;
13610 clear_glyph_matrix (w
->desired_matrix
);
13615 /* Scroll the display. Do it before changing the current matrix so
13616 that xterm.c doesn't get confused about where the cursor glyph is
13618 if (dy
&& run
.height
)
13622 if (FRAME_WINDOW_P (f
))
13624 rif
->update_window_begin_hook (w
);
13625 rif
->clear_window_mouse_face (w
);
13626 rif
->scroll_run_hook (w
, &run
);
13627 rif
->update_window_end_hook (w
, 0, 0);
13631 /* Terminal frame. In this case, dvpos gives the number of
13632 lines to scroll by; dvpos < 0 means scroll up. */
13633 int first_unchanged_at_end_vpos
13634 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13635 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13636 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13637 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13638 + window_internal_height (w
));
13640 /* Perform the operation on the screen. */
13643 /* Scroll last_unchanged_at_beg_row to the end of the
13644 window down dvpos lines. */
13645 set_terminal_window (end
);
13647 /* On dumb terminals delete dvpos lines at the end
13648 before inserting dvpos empty lines. */
13649 if (!scroll_region_ok
)
13650 ins_del_lines (end
- dvpos
, -dvpos
);
13652 /* Insert dvpos empty lines in front of
13653 last_unchanged_at_beg_row. */
13654 ins_del_lines (from
, dvpos
);
13656 else if (dvpos
< 0)
13658 /* Scroll up last_unchanged_at_beg_vpos to the end of
13659 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13660 set_terminal_window (end
);
13662 /* Delete dvpos lines in front of
13663 last_unchanged_at_beg_vpos. ins_del_lines will set
13664 the cursor to the given vpos and emit |dvpos| delete
13666 ins_del_lines (from
+ dvpos
, dvpos
);
13668 /* On a dumb terminal insert dvpos empty lines at the
13670 if (!scroll_region_ok
)
13671 ins_del_lines (end
+ dvpos
, -dvpos
);
13674 set_terminal_window (0);
13680 /* Shift reused rows of the current matrix to the right position.
13681 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13683 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13684 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13687 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13688 bottom_vpos
, dvpos
);
13689 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13692 else if (dvpos
> 0)
13694 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13695 bottom_vpos
, dvpos
);
13696 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13697 first_unchanged_at_end_vpos
+ dvpos
, 0);
13700 /* For frame-based redisplay, make sure that current frame and window
13701 matrix are in sync with respect to glyph memory. */
13702 if (!FRAME_WINDOW_P (f
))
13703 sync_frame_with_window_matrix_rows (w
);
13705 /* Adjust buffer positions in reused rows. */
13707 increment_matrix_positions (current_matrix
,
13708 first_unchanged_at_end_vpos
+ dvpos
,
13709 bottom_vpos
, delta
, delta_bytes
);
13711 /* Adjust Y positions. */
13713 shift_glyph_matrix (w
, current_matrix
,
13714 first_unchanged_at_end_vpos
+ dvpos
,
13717 if (first_unchanged_at_end_row
)
13718 first_unchanged_at_end_row
+= dvpos
;
13720 /* If scrolling up, there may be some lines to display at the end of
13722 last_text_row_at_end
= NULL
;
13725 /* Scrolling up can leave for example a partially visible line
13726 at the end of the window to be redisplayed. */
13727 /* Set last_row to the glyph row in the current matrix where the
13728 window end line is found. It has been moved up or down in
13729 the matrix by dvpos. */
13730 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13731 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13733 /* If last_row is the window end line, it should display text. */
13734 xassert (last_row
->displays_text_p
);
13736 /* If window end line was partially visible before, begin
13737 displaying at that line. Otherwise begin displaying with the
13738 line following it. */
13739 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13741 init_to_row_start (&it
, w
, last_row
);
13742 it
.vpos
= last_vpos
;
13743 it
.current_y
= last_row
->y
;
13747 init_to_row_end (&it
, w
, last_row
);
13748 it
.vpos
= 1 + last_vpos
;
13749 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13753 /* We may start in a continuation line. If so, we have to
13754 get the right continuation_lines_width and current_x. */
13755 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13756 it
.hpos
= it
.current_x
= 0;
13758 /* Display the rest of the lines at the window end. */
13759 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13760 while (it
.current_y
< it
.last_visible_y
13761 && !fonts_changed_p
)
13763 /* Is it always sure that the display agrees with lines in
13764 the current matrix? I don't think so, so we mark rows
13765 displayed invalid in the current matrix by setting their
13766 enabled_p flag to zero. */
13767 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13768 if (display_line (&it
))
13769 last_text_row_at_end
= it
.glyph_row
- 1;
13773 /* Update window_end_pos and window_end_vpos. */
13774 if (first_unchanged_at_end_row
13775 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13776 && !last_text_row_at_end
)
13778 /* Window end line if one of the preserved rows from the current
13779 matrix. Set row to the last row displaying text in current
13780 matrix starting at first_unchanged_at_end_row, after
13782 xassert (first_unchanged_at_end_row
->displays_text_p
);
13783 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13784 first_unchanged_at_end_row
);
13785 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13787 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13788 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13790 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13791 xassert (w
->window_end_bytepos
>= 0);
13792 IF_DEBUG (debug_method_add (w
, "A"));
13794 else if (last_text_row_at_end
)
13797 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13798 w
->window_end_bytepos
13799 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13801 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13802 xassert (w
->window_end_bytepos
>= 0);
13803 IF_DEBUG (debug_method_add (w
, "B"));
13805 else if (last_text_row
)
13807 /* We have displayed either to the end of the window or at the
13808 end of the window, i.e. the last row with text is to be found
13809 in the desired matrix. */
13811 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13812 w
->window_end_bytepos
13813 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13815 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13816 xassert (w
->window_end_bytepos
>= 0);
13818 else if (first_unchanged_at_end_row
== NULL
13819 && last_text_row
== NULL
13820 && last_text_row_at_end
== NULL
)
13822 /* Displayed to end of window, but no line containing text was
13823 displayed. Lines were deleted at the end of the window. */
13824 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13825 int vpos
= XFASTINT (w
->window_end_vpos
);
13826 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13827 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13830 row
== NULL
&& vpos
>= first_vpos
;
13831 --vpos
, --current_row
, --desired_row
)
13833 if (desired_row
->enabled_p
)
13835 if (desired_row
->displays_text_p
)
13838 else if (current_row
->displays_text_p
)
13842 xassert (row
!= NULL
);
13843 w
->window_end_vpos
= make_number (vpos
+ 1);
13844 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13845 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13846 xassert (w
->window_end_bytepos
>= 0);
13847 IF_DEBUG (debug_method_add (w
, "C"));
13852 #if 0 /* This leads to problems, for instance when the cursor is
13853 at ZV, and the cursor line displays no text. */
13854 /* Disable rows below what's displayed in the window. This makes
13855 debugging easier. */
13856 enable_glyph_matrix_rows (current_matrix
,
13857 XFASTINT (w
->window_end_vpos
) + 1,
13861 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13862 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13864 /* Record that display has not been completed. */
13865 w
->window_end_valid
= Qnil
;
13866 w
->desired_matrix
->no_scrolling_p
= 1;
13874 /***********************************************************************
13875 More debugging support
13876 ***********************************************************************/
13880 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13881 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13882 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13885 /* Dump the contents of glyph matrix MATRIX on stderr.
13887 GLYPHS 0 means don't show glyph contents.
13888 GLYPHS 1 means show glyphs in short form
13889 GLYPHS > 1 means show glyphs in long form. */
13892 dump_glyph_matrix (matrix
, glyphs
)
13893 struct glyph_matrix
*matrix
;
13897 for (i
= 0; i
< matrix
->nrows
; ++i
)
13898 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13902 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13903 the glyph row and area where the glyph comes from. */
13906 dump_glyph (row
, glyph
, area
)
13907 struct glyph_row
*row
;
13908 struct glyph
*glyph
;
13911 if (glyph
->type
== CHAR_GLYPH
)
13914 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13915 glyph
- row
->glyphs
[TEXT_AREA
],
13918 (BUFFERP (glyph
->object
)
13920 : (STRINGP (glyph
->object
)
13923 glyph
->pixel_width
,
13925 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13929 glyph
->left_box_line_p
,
13930 glyph
->right_box_line_p
);
13932 else if (glyph
->type
== STRETCH_GLYPH
)
13935 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13936 glyph
- row
->glyphs
[TEXT_AREA
],
13939 (BUFFERP (glyph
->object
)
13941 : (STRINGP (glyph
->object
)
13944 glyph
->pixel_width
,
13948 glyph
->left_box_line_p
,
13949 glyph
->right_box_line_p
);
13951 else if (glyph
->type
== IMAGE_GLYPH
)
13954 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13955 glyph
- row
->glyphs
[TEXT_AREA
],
13958 (BUFFERP (glyph
->object
)
13960 : (STRINGP (glyph
->object
)
13963 glyph
->pixel_width
,
13967 glyph
->left_box_line_p
,
13968 glyph
->right_box_line_p
);
13973 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13974 GLYPHS 0 means don't show glyph contents.
13975 GLYPHS 1 means show glyphs in short form
13976 GLYPHS > 1 means show glyphs in long form. */
13979 dump_glyph_row (row
, vpos
, glyphs
)
13980 struct glyph_row
*row
;
13985 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13986 fprintf (stderr
, "=======================================================================\n");
13988 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13989 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13991 MATRIX_ROW_START_CHARPOS (row
),
13992 MATRIX_ROW_END_CHARPOS (row
),
13993 row
->used
[TEXT_AREA
],
13994 row
->contains_overlapping_glyphs_p
,
13996 row
->truncated_on_left_p
,
13997 row
->truncated_on_right_p
,
13998 row
->overlay_arrow_p
,
14000 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14001 row
->displays_text_p
,
14004 row
->ends_in_middle_of_char_p
,
14005 row
->starts_in_middle_of_char_p
,
14011 row
->visible_height
,
14014 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14015 row
->end
.overlay_string_index
,
14016 row
->continuation_lines_width
);
14017 fprintf (stderr
, "%9d %5d\n",
14018 CHARPOS (row
->start
.string_pos
),
14019 CHARPOS (row
->end
.string_pos
));
14020 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14021 row
->end
.dpvec_index
);
14028 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14030 struct glyph
*glyph
= row
->glyphs
[area
];
14031 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14033 /* Glyph for a line end in text. */
14034 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14037 if (glyph
< glyph_end
)
14038 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14040 for (; glyph
< glyph_end
; ++glyph
)
14041 dump_glyph (row
, glyph
, area
);
14044 else if (glyphs
== 1)
14048 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14050 char *s
= (char *) alloca (row
->used
[area
] + 1);
14053 for (i
= 0; i
< row
->used
[area
]; ++i
)
14055 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14056 if (glyph
->type
== CHAR_GLYPH
14057 && glyph
->u
.ch
< 0x80
14058 && glyph
->u
.ch
>= ' ')
14059 s
[i
] = glyph
->u
.ch
;
14065 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14071 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14072 Sdump_glyph_matrix
, 0, 1, "p",
14073 doc
: /* Dump the current matrix of the selected window to stderr.
14074 Shows contents of glyph row structures. With non-nil
14075 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14076 glyphs in short form, otherwise show glyphs in long form. */)
14078 Lisp_Object glyphs
;
14080 struct window
*w
= XWINDOW (selected_window
);
14081 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14083 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14084 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14085 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14086 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14087 fprintf (stderr
, "=============================================\n");
14088 dump_glyph_matrix (w
->current_matrix
,
14089 NILP (glyphs
) ? 0 : XINT (glyphs
));
14094 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14095 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14098 struct frame
*f
= XFRAME (selected_frame
);
14099 dump_glyph_matrix (f
->current_matrix
, 1);
14104 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14105 doc
: /* Dump glyph row ROW to stderr.
14106 GLYPH 0 means don't dump glyphs.
14107 GLYPH 1 means dump glyphs in short form.
14108 GLYPH > 1 or omitted means dump glyphs in long form. */)
14110 Lisp_Object row
, glyphs
;
14112 struct glyph_matrix
*matrix
;
14115 CHECK_NUMBER (row
);
14116 matrix
= XWINDOW (selected_window
)->current_matrix
;
14118 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14119 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14121 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14126 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14127 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14128 GLYPH 0 means don't dump glyphs.
14129 GLYPH 1 means dump glyphs in short form.
14130 GLYPH > 1 or omitted means dump glyphs in long form. */)
14132 Lisp_Object row
, glyphs
;
14134 struct frame
*sf
= SELECTED_FRAME ();
14135 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14138 CHECK_NUMBER (row
);
14140 if (vpos
>= 0 && vpos
< m
->nrows
)
14141 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14142 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14147 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14148 doc
: /* Toggle tracing of redisplay.
14149 With ARG, turn tracing on if and only if ARG is positive. */)
14154 trace_redisplay_p
= !trace_redisplay_p
;
14157 arg
= Fprefix_numeric_value (arg
);
14158 trace_redisplay_p
= XINT (arg
) > 0;
14165 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14166 doc
: /* Like `format', but print result to stderr.
14167 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14172 Lisp_Object s
= Fformat (nargs
, args
);
14173 fprintf (stderr
, "%s", SDATA (s
));
14177 #endif /* GLYPH_DEBUG */
14181 /***********************************************************************
14182 Building Desired Matrix Rows
14183 ***********************************************************************/
14185 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14186 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14188 static struct glyph_row
*
14189 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14191 Lisp_Object overlay_arrow_string
;
14193 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14194 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14195 struct buffer
*old
= current_buffer
;
14196 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14197 int arrow_len
= SCHARS (overlay_arrow_string
);
14198 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14199 const unsigned char *p
;
14202 int n_glyphs_before
;
14204 set_buffer_temp (buffer
);
14205 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14206 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14207 SET_TEXT_POS (it
.position
, 0, 0);
14209 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14211 while (p
< arrow_end
)
14213 Lisp_Object face
, ilisp
;
14215 /* Get the next character. */
14217 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14219 it
.c
= *p
, it
.len
= 1;
14222 /* Get its face. */
14223 ilisp
= make_number (p
- arrow_string
);
14224 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14225 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14227 /* Compute its width, get its glyphs. */
14228 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14229 SET_TEXT_POS (it
.position
, -1, -1);
14230 PRODUCE_GLYPHS (&it
);
14232 /* If this character doesn't fit any more in the line, we have
14233 to remove some glyphs. */
14234 if (it
.current_x
> it
.last_visible_x
)
14236 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14241 set_buffer_temp (old
);
14242 return it
.glyph_row
;
14246 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14247 glyphs are only inserted for terminal frames since we can't really
14248 win with truncation glyphs when partially visible glyphs are
14249 involved. Which glyphs to insert is determined by
14250 produce_special_glyphs. */
14253 insert_left_trunc_glyphs (it
)
14256 struct it truncate_it
;
14257 struct glyph
*from
, *end
, *to
, *toend
;
14259 xassert (!FRAME_WINDOW_P (it
->f
));
14261 /* Get the truncation glyphs. */
14263 truncate_it
.current_x
= 0;
14264 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14265 truncate_it
.glyph_row
= &scratch_glyph_row
;
14266 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14267 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14268 truncate_it
.object
= make_number (0);
14269 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14271 /* Overwrite glyphs from IT with truncation glyphs. */
14272 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14273 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14274 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14275 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14280 /* There may be padding glyphs left over. Overwrite them too. */
14281 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14283 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14289 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14293 /* Compute the pixel height and width of IT->glyph_row.
14295 Most of the time, ascent and height of a display line will be equal
14296 to the max_ascent and max_height values of the display iterator
14297 structure. This is not the case if
14299 1. We hit ZV without displaying anything. In this case, max_ascent
14300 and max_height will be zero.
14302 2. We have some glyphs that don't contribute to the line height.
14303 (The glyph row flag contributes_to_line_height_p is for future
14304 pixmap extensions).
14306 The first case is easily covered by using default values because in
14307 these cases, the line height does not really matter, except that it
14308 must not be zero. */
14311 compute_line_metrics (it
)
14314 struct glyph_row
*row
= it
->glyph_row
;
14317 if (FRAME_WINDOW_P (it
->f
))
14319 int i
, min_y
, max_y
;
14321 /* The line may consist of one space only, that was added to
14322 place the cursor on it. If so, the row's height hasn't been
14324 if (row
->height
== 0)
14326 if (it
->max_ascent
+ it
->max_descent
== 0)
14327 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14328 row
->ascent
= it
->max_ascent
;
14329 row
->height
= it
->max_ascent
+ it
->max_descent
;
14330 row
->phys_ascent
= it
->max_phys_ascent
;
14331 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14332 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14335 /* Compute the width of this line. */
14336 row
->pixel_width
= row
->x
;
14337 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14338 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14340 xassert (row
->pixel_width
>= 0);
14341 xassert (row
->ascent
>= 0 && row
->height
> 0);
14343 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14344 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14346 /* If first line's physical ascent is larger than its logical
14347 ascent, use the physical ascent, and make the row taller.
14348 This makes accented characters fully visible. */
14349 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14350 && row
->phys_ascent
> row
->ascent
)
14352 row
->height
+= row
->phys_ascent
- row
->ascent
;
14353 row
->ascent
= row
->phys_ascent
;
14356 /* Compute how much of the line is visible. */
14357 row
->visible_height
= row
->height
;
14359 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14360 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14362 if (row
->y
< min_y
)
14363 row
->visible_height
-= min_y
- row
->y
;
14364 if (row
->y
+ row
->height
> max_y
)
14365 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14369 row
->pixel_width
= row
->used
[TEXT_AREA
];
14370 if (row
->continued_p
)
14371 row
->pixel_width
-= it
->continuation_pixel_width
;
14372 else if (row
->truncated_on_right_p
)
14373 row
->pixel_width
-= it
->truncation_pixel_width
;
14374 row
->ascent
= row
->phys_ascent
= 0;
14375 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14376 row
->extra_line_spacing
= 0;
14379 /* Compute a hash code for this row. */
14381 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14382 for (i
= 0; i
< row
->used
[area
]; ++i
)
14383 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14384 + row
->glyphs
[area
][i
].u
.val
14385 + row
->glyphs
[area
][i
].face_id
14386 + row
->glyphs
[area
][i
].padding_p
14387 + (row
->glyphs
[area
][i
].type
<< 2));
14389 it
->max_ascent
= it
->max_descent
= 0;
14390 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14394 /* Append one space to the glyph row of iterator IT if doing a
14395 window-based redisplay. The space has the same face as
14396 IT->face_id. Value is non-zero if a space was added.
14398 This function is called to make sure that there is always one glyph
14399 at the end of a glyph row that the cursor can be set on under
14400 window-systems. (If there weren't such a glyph we would not know
14401 how wide and tall a box cursor should be displayed).
14403 At the same time this space let's a nicely handle clearing to the
14404 end of the line if the row ends in italic text. */
14407 append_space_for_newline (it
, default_face_p
)
14409 int default_face_p
;
14411 if (FRAME_WINDOW_P (it
->f
))
14413 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14415 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14416 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14418 /* Save some values that must not be changed.
14419 Must save IT->c and IT->len because otherwise
14420 ITERATOR_AT_END_P wouldn't work anymore after
14421 append_space_for_newline has been called. */
14422 enum display_element_type saved_what
= it
->what
;
14423 int saved_c
= it
->c
, saved_len
= it
->len
;
14424 int saved_x
= it
->current_x
;
14425 int saved_face_id
= it
->face_id
;
14426 struct text_pos saved_pos
;
14427 Lisp_Object saved_object
;
14430 saved_object
= it
->object
;
14431 saved_pos
= it
->position
;
14433 it
->what
= IT_CHARACTER
;
14434 bzero (&it
->position
, sizeof it
->position
);
14435 it
->object
= make_number (0);
14439 if (default_face_p
)
14440 it
->face_id
= DEFAULT_FACE_ID
;
14441 else if (it
->face_before_selective_p
)
14442 it
->face_id
= it
->saved_face_id
;
14443 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14444 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14446 PRODUCE_GLYPHS (it
);
14448 it
->override_ascent
= -1;
14449 it
->constrain_row_ascent_descent_p
= 0;
14450 it
->current_x
= saved_x
;
14451 it
->object
= saved_object
;
14452 it
->position
= saved_pos
;
14453 it
->what
= saved_what
;
14454 it
->face_id
= saved_face_id
;
14455 it
->len
= saved_len
;
14465 /* Extend the face of the last glyph in the text area of IT->glyph_row
14466 to the end of the display line. Called from display_line.
14467 If the glyph row is empty, add a space glyph to it so that we
14468 know the face to draw. Set the glyph row flag fill_line_p. */
14471 extend_face_to_end_of_line (it
)
14475 struct frame
*f
= it
->f
;
14477 /* If line is already filled, do nothing. */
14478 if (it
->current_x
>= it
->last_visible_x
)
14481 /* Face extension extends the background and box of IT->face_id
14482 to the end of the line. If the background equals the background
14483 of the frame, we don't have to do anything. */
14484 if (it
->face_before_selective_p
)
14485 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14487 face
= FACE_FROM_ID (f
, it
->face_id
);
14489 if (FRAME_WINDOW_P (f
)
14490 && face
->box
== FACE_NO_BOX
14491 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14495 /* Set the glyph row flag indicating that the face of the last glyph
14496 in the text area has to be drawn to the end of the text area. */
14497 it
->glyph_row
->fill_line_p
= 1;
14499 /* If current character of IT is not ASCII, make sure we have the
14500 ASCII face. This will be automatically undone the next time
14501 get_next_display_element returns a multibyte character. Note
14502 that the character will always be single byte in unibyte text. */
14503 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14505 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14508 if (FRAME_WINDOW_P (f
))
14510 /* If the row is empty, add a space with the current face of IT,
14511 so that we know which face to draw. */
14512 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14514 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14515 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14516 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14521 /* Save some values that must not be changed. */
14522 int saved_x
= it
->current_x
;
14523 struct text_pos saved_pos
;
14524 Lisp_Object saved_object
;
14525 enum display_element_type saved_what
= it
->what
;
14526 int saved_face_id
= it
->face_id
;
14528 saved_object
= it
->object
;
14529 saved_pos
= it
->position
;
14531 it
->what
= IT_CHARACTER
;
14532 bzero (&it
->position
, sizeof it
->position
);
14533 it
->object
= make_number (0);
14536 it
->face_id
= face
->id
;
14538 PRODUCE_GLYPHS (it
);
14540 while (it
->current_x
<= it
->last_visible_x
)
14541 PRODUCE_GLYPHS (it
);
14543 /* Don't count these blanks really. It would let us insert a left
14544 truncation glyph below and make us set the cursor on them, maybe. */
14545 it
->current_x
= saved_x
;
14546 it
->object
= saved_object
;
14547 it
->position
= saved_pos
;
14548 it
->what
= saved_what
;
14549 it
->face_id
= saved_face_id
;
14554 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14555 trailing whitespace. */
14558 trailing_whitespace_p (charpos
)
14561 int bytepos
= CHAR_TO_BYTE (charpos
);
14564 while (bytepos
< ZV_BYTE
14565 && (c
= FETCH_CHAR (bytepos
),
14566 c
== ' ' || c
== '\t'))
14569 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14571 if (bytepos
!= PT_BYTE
)
14578 /* Highlight trailing whitespace, if any, in ROW. */
14581 highlight_trailing_whitespace (f
, row
)
14583 struct glyph_row
*row
;
14585 int used
= row
->used
[TEXT_AREA
];
14589 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14590 struct glyph
*glyph
= start
+ used
- 1;
14592 /* Skip over glyphs inserted to display the cursor at the
14593 end of a line, for extending the face of the last glyph
14594 to the end of the line on terminals, and for truncation
14595 and continuation glyphs. */
14596 while (glyph
>= start
14597 && glyph
->type
== CHAR_GLYPH
14598 && INTEGERP (glyph
->object
))
14601 /* If last glyph is a space or stretch, and it's trailing
14602 whitespace, set the face of all trailing whitespace glyphs in
14603 IT->glyph_row to `trailing-whitespace'. */
14605 && BUFFERP (glyph
->object
)
14606 && (glyph
->type
== STRETCH_GLYPH
14607 || (glyph
->type
== CHAR_GLYPH
14608 && glyph
->u
.ch
== ' '))
14609 && trailing_whitespace_p (glyph
->charpos
))
14611 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14615 while (glyph
>= start
14616 && BUFFERP (glyph
->object
)
14617 && (glyph
->type
== STRETCH_GLYPH
14618 || (glyph
->type
== CHAR_GLYPH
14619 && glyph
->u
.ch
== ' ')))
14620 (glyph
--)->face_id
= face_id
;
14626 /* Value is non-zero if glyph row ROW in window W should be
14627 used to hold the cursor. */
14630 cursor_row_p (w
, row
)
14632 struct glyph_row
*row
;
14634 int cursor_row_p
= 1;
14636 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14638 /* If the row ends with a newline from a string, we don't want
14639 the cursor there (if the row is continued it doesn't end in a
14641 if (CHARPOS (row
->end
.string_pos
) >= 0)
14642 cursor_row_p
= row
->continued_p
;
14643 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14645 /* If the row ends in middle of a real character,
14646 and the line is continued, we want the cursor here.
14647 That's because MATRIX_ROW_END_CHARPOS would equal
14648 PT if PT is before the character. */
14649 if (!row
->ends_in_ellipsis_p
)
14650 cursor_row_p
= row
->continued_p
;
14652 /* If the row ends in an ellipsis, then
14653 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
14654 We want that position to be displayed after the ellipsis. */
14657 /* If the row ends at ZV, display the cursor at the end of that
14658 row instead of at the start of the row below. */
14659 else if (row
->ends_at_zv_p
)
14665 return cursor_row_p
;
14669 /* Construct the glyph row IT->glyph_row in the desired matrix of
14670 IT->w from text at the current position of IT. See dispextern.h
14671 for an overview of struct it. Value is non-zero if
14672 IT->glyph_row displays text, as opposed to a line displaying ZV
14679 struct glyph_row
*row
= it
->glyph_row
;
14680 int overlay_arrow_bitmap
;
14681 Lisp_Object overlay_arrow_string
;
14683 /* We always start displaying at hpos zero even if hscrolled. */
14684 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14686 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14687 >= it
->w
->desired_matrix
->nrows
)
14689 it
->w
->nrows_scale_factor
++;
14690 fonts_changed_p
= 1;
14694 /* Is IT->w showing the region? */
14695 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14697 /* Clear the result glyph row and enable it. */
14698 prepare_desired_row (row
);
14700 row
->y
= it
->current_y
;
14701 row
->start
= it
->start
;
14702 row
->continuation_lines_width
= it
->continuation_lines_width
;
14703 row
->displays_text_p
= 1;
14704 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14705 it
->starts_in_middle_of_char_p
= 0;
14707 /* Arrange the overlays nicely for our purposes. Usually, we call
14708 display_line on only one line at a time, in which case this
14709 can't really hurt too much, or we call it on lines which appear
14710 one after another in the buffer, in which case all calls to
14711 recenter_overlay_lists but the first will be pretty cheap. */
14712 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14714 /* Move over display elements that are not visible because we are
14715 hscrolled. This may stop at an x-position < IT->first_visible_x
14716 if the first glyph is partially visible or if we hit a line end. */
14717 if (it
->current_x
< it
->first_visible_x
)
14719 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14720 MOVE_TO_POS
| MOVE_TO_X
);
14723 /* Get the initial row height. This is either the height of the
14724 text hscrolled, if there is any, or zero. */
14725 row
->ascent
= it
->max_ascent
;
14726 row
->height
= it
->max_ascent
+ it
->max_descent
;
14727 row
->phys_ascent
= it
->max_phys_ascent
;
14728 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14729 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14731 /* Loop generating characters. The loop is left with IT on the next
14732 character to display. */
14735 int n_glyphs_before
, hpos_before
, x_before
;
14737 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14739 /* Retrieve the next thing to display. Value is zero if end of
14741 if (!get_next_display_element (it
))
14743 /* Maybe add a space at the end of this line that is used to
14744 display the cursor there under X. Set the charpos of the
14745 first glyph of blank lines not corresponding to any text
14747 #ifdef HAVE_WINDOW_SYSTEM
14748 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14749 row
->exact_window_width_line_p
= 1;
14751 #endif /* HAVE_WINDOW_SYSTEM */
14752 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14753 || row
->used
[TEXT_AREA
] == 0)
14755 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14756 row
->displays_text_p
= 0;
14758 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14759 && (!MINI_WINDOW_P (it
->w
)
14760 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14761 row
->indicate_empty_line_p
= 1;
14764 it
->continuation_lines_width
= 0;
14765 row
->ends_at_zv_p
= 1;
14769 /* Now, get the metrics of what we want to display. This also
14770 generates glyphs in `row' (which is IT->glyph_row). */
14771 n_glyphs_before
= row
->used
[TEXT_AREA
];
14774 /* Remember the line height so far in case the next element doesn't
14775 fit on the line. */
14776 if (!it
->truncate_lines_p
)
14778 ascent
= it
->max_ascent
;
14779 descent
= it
->max_descent
;
14780 phys_ascent
= it
->max_phys_ascent
;
14781 phys_descent
= it
->max_phys_descent
;
14784 PRODUCE_GLYPHS (it
);
14786 /* If this display element was in marginal areas, continue with
14788 if (it
->area
!= TEXT_AREA
)
14790 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14791 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14792 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14793 row
->phys_height
= max (row
->phys_height
,
14794 it
->max_phys_ascent
+ it
->max_phys_descent
);
14795 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14796 it
->max_extra_line_spacing
);
14797 set_iterator_to_next (it
, 1);
14801 /* Does the display element fit on the line? If we truncate
14802 lines, we should draw past the right edge of the window. If
14803 we don't truncate, we want to stop so that we can display the
14804 continuation glyph before the right margin. If lines are
14805 continued, there are two possible strategies for characters
14806 resulting in more than 1 glyph (e.g. tabs): Display as many
14807 glyphs as possible in this line and leave the rest for the
14808 continuation line, or display the whole element in the next
14809 line. Original redisplay did the former, so we do it also. */
14810 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14811 hpos_before
= it
->hpos
;
14814 if (/* Not a newline. */
14816 /* Glyphs produced fit entirely in the line. */
14817 && it
->current_x
< it
->last_visible_x
)
14819 it
->hpos
+= nglyphs
;
14820 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14821 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14822 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14823 row
->phys_height
= max (row
->phys_height
,
14824 it
->max_phys_ascent
+ it
->max_phys_descent
);
14825 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14826 it
->max_extra_line_spacing
);
14827 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14828 row
->x
= x
- it
->first_visible_x
;
14833 struct glyph
*glyph
;
14835 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14837 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14838 new_x
= x
+ glyph
->pixel_width
;
14840 if (/* Lines are continued. */
14841 !it
->truncate_lines_p
14842 && (/* Glyph doesn't fit on the line. */
14843 new_x
> it
->last_visible_x
14844 /* Or it fits exactly on a window system frame. */
14845 || (new_x
== it
->last_visible_x
14846 && FRAME_WINDOW_P (it
->f
))))
14848 /* End of a continued line. */
14851 || (new_x
== it
->last_visible_x
14852 && FRAME_WINDOW_P (it
->f
)))
14854 /* Current glyph is the only one on the line or
14855 fits exactly on the line. We must continue
14856 the line because we can't draw the cursor
14857 after the glyph. */
14858 row
->continued_p
= 1;
14859 it
->current_x
= new_x
;
14860 it
->continuation_lines_width
+= new_x
;
14862 if (i
== nglyphs
- 1)
14864 set_iterator_to_next (it
, 1);
14865 #ifdef HAVE_WINDOW_SYSTEM
14866 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14868 if (!get_next_display_element (it
))
14870 row
->exact_window_width_line_p
= 1;
14871 it
->continuation_lines_width
= 0;
14872 row
->continued_p
= 0;
14873 row
->ends_at_zv_p
= 1;
14875 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14877 row
->continued_p
= 0;
14878 row
->exact_window_width_line_p
= 1;
14881 #endif /* HAVE_WINDOW_SYSTEM */
14884 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14885 && !FRAME_WINDOW_P (it
->f
))
14887 /* A padding glyph that doesn't fit on this line.
14888 This means the whole character doesn't fit
14890 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14892 /* Fill the rest of the row with continuation
14893 glyphs like in 20.x. */
14894 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14895 < row
->glyphs
[1 + TEXT_AREA
])
14896 produce_special_glyphs (it
, IT_CONTINUATION
);
14898 row
->continued_p
= 1;
14899 it
->current_x
= x_before
;
14900 it
->continuation_lines_width
+= x_before
;
14902 /* Restore the height to what it was before the
14903 element not fitting on the line. */
14904 it
->max_ascent
= ascent
;
14905 it
->max_descent
= descent
;
14906 it
->max_phys_ascent
= phys_ascent
;
14907 it
->max_phys_descent
= phys_descent
;
14909 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14911 /* A TAB that extends past the right edge of the
14912 window. This produces a single glyph on
14913 window system frames. We leave the glyph in
14914 this row and let it fill the row, but don't
14915 consume the TAB. */
14916 it
->continuation_lines_width
+= it
->last_visible_x
;
14917 row
->ends_in_middle_of_char_p
= 1;
14918 row
->continued_p
= 1;
14919 glyph
->pixel_width
= it
->last_visible_x
- x
;
14920 it
->starts_in_middle_of_char_p
= 1;
14924 /* Something other than a TAB that draws past
14925 the right edge of the window. Restore
14926 positions to values before the element. */
14927 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14929 /* Display continuation glyphs. */
14930 if (!FRAME_WINDOW_P (it
->f
))
14931 produce_special_glyphs (it
, IT_CONTINUATION
);
14932 row
->continued_p
= 1;
14934 it
->continuation_lines_width
+= x
;
14936 if (nglyphs
> 1 && i
> 0)
14938 row
->ends_in_middle_of_char_p
= 1;
14939 it
->starts_in_middle_of_char_p
= 1;
14942 /* Restore the height to what it was before the
14943 element not fitting on the line. */
14944 it
->max_ascent
= ascent
;
14945 it
->max_descent
= descent
;
14946 it
->max_phys_ascent
= phys_ascent
;
14947 it
->max_phys_descent
= phys_descent
;
14952 else if (new_x
> it
->first_visible_x
)
14954 /* Increment number of glyphs actually displayed. */
14957 if (x
< it
->first_visible_x
)
14958 /* Glyph is partially visible, i.e. row starts at
14959 negative X position. */
14960 row
->x
= x
- it
->first_visible_x
;
14964 /* Glyph is completely off the left margin of the
14965 window. This should not happen because of the
14966 move_it_in_display_line at the start of this
14967 function, unless the text display area of the
14968 window is empty. */
14969 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14973 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14974 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14975 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14976 row
->phys_height
= max (row
->phys_height
,
14977 it
->max_phys_ascent
+ it
->max_phys_descent
);
14978 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14979 it
->max_extra_line_spacing
);
14981 /* End of this display line if row is continued. */
14982 if (row
->continued_p
|| row
->ends_at_zv_p
)
14987 /* Is this a line end? If yes, we're also done, after making
14988 sure that a non-default face is extended up to the right
14989 margin of the window. */
14990 if (ITERATOR_AT_END_OF_LINE_P (it
))
14992 int used_before
= row
->used
[TEXT_AREA
];
14994 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14996 #ifdef HAVE_WINDOW_SYSTEM
14997 /* Add a space at the end of the line that is used to
14998 display the cursor there. */
14999 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15000 append_space_for_newline (it
, 0);
15001 #endif /* HAVE_WINDOW_SYSTEM */
15003 /* Extend the face to the end of the line. */
15004 extend_face_to_end_of_line (it
);
15006 /* Make sure we have the position. */
15007 if (used_before
== 0)
15008 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15010 /* Consume the line end. This skips over invisible lines. */
15011 set_iterator_to_next (it
, 1);
15012 it
->continuation_lines_width
= 0;
15016 /* Proceed with next display element. Note that this skips
15017 over lines invisible because of selective display. */
15018 set_iterator_to_next (it
, 1);
15020 /* If we truncate lines, we are done when the last displayed
15021 glyphs reach past the right margin of the window. */
15022 if (it
->truncate_lines_p
15023 && (FRAME_WINDOW_P (it
->f
)
15024 ? (it
->current_x
>= it
->last_visible_x
)
15025 : (it
->current_x
> it
->last_visible_x
)))
15027 /* Maybe add truncation glyphs. */
15028 if (!FRAME_WINDOW_P (it
->f
))
15032 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15033 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15036 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15038 row
->used
[TEXT_AREA
] = i
;
15039 produce_special_glyphs (it
, IT_TRUNCATION
);
15042 #ifdef HAVE_WINDOW_SYSTEM
15045 /* Don't truncate if we can overflow newline into fringe. */
15046 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15048 if (!get_next_display_element (it
))
15050 it
->continuation_lines_width
= 0;
15051 row
->ends_at_zv_p
= 1;
15052 row
->exact_window_width_line_p
= 1;
15055 if (ITERATOR_AT_END_OF_LINE_P (it
))
15057 row
->exact_window_width_line_p
= 1;
15058 goto at_end_of_line
;
15062 #endif /* HAVE_WINDOW_SYSTEM */
15064 row
->truncated_on_right_p
= 1;
15065 it
->continuation_lines_width
= 0;
15066 reseat_at_next_visible_line_start (it
, 0);
15067 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15068 it
->hpos
= hpos_before
;
15069 it
->current_x
= x_before
;
15074 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15075 at the left window margin. */
15076 if (it
->first_visible_x
15077 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15079 if (!FRAME_WINDOW_P (it
->f
))
15080 insert_left_trunc_glyphs (it
);
15081 row
->truncated_on_left_p
= 1;
15084 /* If the start of this line is the overlay arrow-position, then
15085 mark this glyph row as the one containing the overlay arrow.
15086 This is clearly a mess with variable size fonts. It would be
15087 better to let it be displayed like cursors under X. */
15088 if (! overlay_arrow_seen
15089 && (overlay_arrow_string
15090 = overlay_arrow_at_row (it
, row
, &overlay_arrow_bitmap
),
15091 !NILP (overlay_arrow_string
)))
15093 /* Overlay arrow in window redisplay is a fringe bitmap. */
15094 if (STRINGP (overlay_arrow_string
))
15096 struct glyph_row
*arrow_row
15097 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15098 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15099 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15100 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15101 struct glyph
*p2
, *end
;
15103 /* Copy the arrow glyphs. */
15104 while (glyph
< arrow_end
)
15107 /* Throw away padding glyphs. */
15109 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15110 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15116 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15121 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
15122 row
->overlay_arrow_p
= 1;
15124 overlay_arrow_seen
= 1;
15127 /* Compute pixel dimensions of this line. */
15128 compute_line_metrics (it
);
15130 /* Remember the position at which this line ends. */
15131 row
->end
= it
->current
;
15133 /* Record whether this row ends inside an ellipsis. */
15134 row
->ends_in_ellipsis_p
15135 = (it
->method
== next_element_from_display_vector
15136 && it
->ellipsis_p
);
15138 /* Save fringe bitmaps in this row. */
15139 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15140 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15141 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15142 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15144 it
->left_user_fringe_bitmap
= 0;
15145 it
->left_user_fringe_face_id
= 0;
15146 it
->right_user_fringe_bitmap
= 0;
15147 it
->right_user_fringe_face_id
= 0;
15149 /* Maybe set the cursor. */
15150 if (it
->w
->cursor
.vpos
< 0
15151 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15152 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15153 && cursor_row_p (it
->w
, row
))
15154 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15156 /* Highlight trailing whitespace. */
15157 if (!NILP (Vshow_trailing_whitespace
))
15158 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15160 /* Prepare for the next line. This line starts horizontally at (X
15161 HPOS) = (0 0). Vertical positions are incremented. As a
15162 convenience for the caller, IT->glyph_row is set to the next
15164 it
->current_x
= it
->hpos
= 0;
15165 it
->current_y
+= row
->height
;
15168 it
->start
= it
->current
;
15169 return row
->displays_text_p
;
15174 /***********************************************************************
15176 ***********************************************************************/
15178 /* Redisplay the menu bar in the frame for window W.
15180 The menu bar of X frames that don't have X toolkit support is
15181 displayed in a special window W->frame->menu_bar_window.
15183 The menu bar of terminal frames is treated specially as far as
15184 glyph matrices are concerned. Menu bar lines are not part of
15185 windows, so the update is done directly on the frame matrix rows
15186 for the menu bar. */
15189 display_menu_bar (w
)
15192 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15197 /* Don't do all this for graphical frames. */
15199 if (!NILP (Vwindow_system
))
15202 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15207 if (FRAME_MAC_P (f
))
15211 #ifdef USE_X_TOOLKIT
15212 xassert (!FRAME_WINDOW_P (f
));
15213 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15214 it
.first_visible_x
= 0;
15215 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15216 #else /* not USE_X_TOOLKIT */
15217 if (FRAME_WINDOW_P (f
))
15219 /* Menu bar lines are displayed in the desired matrix of the
15220 dummy window menu_bar_window. */
15221 struct window
*menu_w
;
15222 xassert (WINDOWP (f
->menu_bar_window
));
15223 menu_w
= XWINDOW (f
->menu_bar_window
);
15224 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15226 it
.first_visible_x
= 0;
15227 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15231 /* This is a TTY frame, i.e. character hpos/vpos are used as
15233 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15235 it
.first_visible_x
= 0;
15236 it
.last_visible_x
= FRAME_COLS (f
);
15238 #endif /* not USE_X_TOOLKIT */
15240 if (! mode_line_inverse_video
)
15241 /* Force the menu-bar to be displayed in the default face. */
15242 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15244 /* Clear all rows of the menu bar. */
15245 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15247 struct glyph_row
*row
= it
.glyph_row
+ i
;
15248 clear_glyph_row (row
);
15249 row
->enabled_p
= 1;
15250 row
->full_width_p
= 1;
15253 /* Display all items of the menu bar. */
15254 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15255 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15257 Lisp_Object string
;
15259 /* Stop at nil string. */
15260 string
= AREF (items
, i
+ 1);
15264 /* Remember where item was displayed. */
15265 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15267 /* Display the item, pad with one space. */
15268 if (it
.current_x
< it
.last_visible_x
)
15269 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15270 SCHARS (string
) + 1, 0, 0, -1);
15273 /* Fill out the line with spaces. */
15274 if (it
.current_x
< it
.last_visible_x
)
15275 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15277 /* Compute the total height of the lines. */
15278 compute_line_metrics (&it
);
15283 /***********************************************************************
15285 ***********************************************************************/
15287 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15288 FORCE is non-zero, redisplay mode lines unconditionally.
15289 Otherwise, redisplay only mode lines that are garbaged. Value is
15290 the number of windows whose mode lines were redisplayed. */
15293 redisplay_mode_lines (window
, force
)
15294 Lisp_Object window
;
15299 while (!NILP (window
))
15301 struct window
*w
= XWINDOW (window
);
15303 if (WINDOWP (w
->hchild
))
15304 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15305 else if (WINDOWP (w
->vchild
))
15306 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15308 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15309 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15311 struct text_pos lpoint
;
15312 struct buffer
*old
= current_buffer
;
15314 /* Set the window's buffer for the mode line display. */
15315 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15316 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15318 /* Point refers normally to the selected window. For any
15319 other window, set up appropriate value. */
15320 if (!EQ (window
, selected_window
))
15322 struct text_pos pt
;
15324 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15325 if (CHARPOS (pt
) < BEGV
)
15326 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15327 else if (CHARPOS (pt
) > (ZV
- 1))
15328 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15330 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15333 /* Display mode lines. */
15334 clear_glyph_matrix (w
->desired_matrix
);
15335 if (display_mode_lines (w
))
15338 w
->must_be_updated_p
= 1;
15341 /* Restore old settings. */
15342 set_buffer_internal_1 (old
);
15343 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15353 /* Display the mode and/or top line of window W. Value is the number
15354 of mode lines displayed. */
15357 display_mode_lines (w
)
15360 Lisp_Object old_selected_window
, old_selected_frame
;
15363 old_selected_frame
= selected_frame
;
15364 selected_frame
= w
->frame
;
15365 old_selected_window
= selected_window
;
15366 XSETWINDOW (selected_window
, w
);
15368 /* These will be set while the mode line specs are processed. */
15369 line_number_displayed
= 0;
15370 w
->column_number_displayed
= Qnil
;
15372 if (WINDOW_WANTS_MODELINE_P (w
))
15374 struct window
*sel_w
= XWINDOW (old_selected_window
);
15376 /* Select mode line face based on the real selected window. */
15377 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15378 current_buffer
->mode_line_format
);
15382 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15384 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15385 current_buffer
->header_line_format
);
15389 selected_frame
= old_selected_frame
;
15390 selected_window
= old_selected_window
;
15395 /* Display mode or top line of window W. FACE_ID specifies which line
15396 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15397 FORMAT is the mode line format to display. Value is the pixel
15398 height of the mode line displayed. */
15401 display_mode_line (w
, face_id
, format
)
15403 enum face_id face_id
;
15404 Lisp_Object format
;
15409 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15410 prepare_desired_row (it
.glyph_row
);
15412 it
.glyph_row
->mode_line_p
= 1;
15414 if (! mode_line_inverse_video
)
15415 /* Force the mode-line to be displayed in the default face. */
15416 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15418 /* Temporarily make frame's keyboard the current kboard so that
15419 kboard-local variables in the mode_line_format will get the right
15421 push_frame_kboard (it
.f
);
15422 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15423 pop_frame_kboard ();
15425 /* Fill up with spaces. */
15426 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15428 compute_line_metrics (&it
);
15429 it
.glyph_row
->full_width_p
= 1;
15430 it
.glyph_row
->continued_p
= 0;
15431 it
.glyph_row
->truncated_on_left_p
= 0;
15432 it
.glyph_row
->truncated_on_right_p
= 0;
15434 /* Make a 3D mode-line have a shadow at its right end. */
15435 face
= FACE_FROM_ID (it
.f
, face_id
);
15436 extend_face_to_end_of_line (&it
);
15437 if (face
->box
!= FACE_NO_BOX
)
15439 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15440 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15441 last
->right_box_line_p
= 1;
15444 return it
.glyph_row
->height
;
15447 /* Alist that caches the results of :propertize.
15448 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15449 Lisp_Object mode_line_proptrans_alist
;
15451 /* List of strings making up the mode-line. */
15452 Lisp_Object mode_line_string_list
;
15454 /* Base face property when building propertized mode line string. */
15455 static Lisp_Object mode_line_string_face
;
15456 static Lisp_Object mode_line_string_face_prop
;
15459 /* Contribute ELT to the mode line for window IT->w. How it
15460 translates into text depends on its data type.
15462 IT describes the display environment in which we display, as usual.
15464 DEPTH is the depth in recursion. It is used to prevent
15465 infinite recursion here.
15467 FIELD_WIDTH is the number of characters the display of ELT should
15468 occupy in the mode line, and PRECISION is the maximum number of
15469 characters to display from ELT's representation. See
15470 display_string for details.
15472 Returns the hpos of the end of the text generated by ELT.
15474 PROPS is a property list to add to any string we encounter.
15476 If RISKY is nonzero, remove (disregard) any properties in any string
15477 we encounter, and ignore :eval and :propertize.
15479 If the global variable `frame_title_ptr' is non-NULL, then the output
15480 is passed to `store_frame_title' instead of `display_string'. */
15483 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15486 int field_width
, precision
;
15487 Lisp_Object elt
, props
;
15490 int n
= 0, field
, prec
;
15495 elt
= build_string ("*too-deep*");
15499 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15503 /* A string: output it and check for %-constructs within it. */
15505 const unsigned char *this, *lisp_string
;
15507 if (!NILP (props
) || risky
)
15509 Lisp_Object oprops
, aelt
;
15510 oprops
= Ftext_properties_at (make_number (0), elt
);
15512 /* If the starting string's properties are not what
15513 we want, translate the string. Also, if the string
15514 is risky, do that anyway. */
15516 if (NILP (Fequal (props
, oprops
)) || risky
)
15518 /* If the starting string has properties,
15519 merge the specified ones onto the existing ones. */
15520 if (! NILP (oprops
) && !risky
)
15524 oprops
= Fcopy_sequence (oprops
);
15526 while (CONSP (tem
))
15528 oprops
= Fplist_put (oprops
, XCAR (tem
),
15529 XCAR (XCDR (tem
)));
15530 tem
= XCDR (XCDR (tem
));
15535 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15536 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15538 mode_line_proptrans_alist
15539 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15546 elt
= Fcopy_sequence (elt
);
15547 Fset_text_properties (make_number (0), Flength (elt
),
15549 /* Add this item to mode_line_proptrans_alist. */
15550 mode_line_proptrans_alist
15551 = Fcons (Fcons (elt
, props
),
15552 mode_line_proptrans_alist
);
15553 /* Truncate mode_line_proptrans_alist
15554 to at most 50 elements. */
15555 tem
= Fnthcdr (make_number (50),
15556 mode_line_proptrans_alist
);
15558 XSETCDR (tem
, Qnil
);
15563 this = SDATA (elt
);
15564 lisp_string
= this;
15568 prec
= precision
- n
;
15569 if (frame_title_ptr
)
15570 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15571 else if (!NILP (mode_line_string_list
))
15572 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15574 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15575 0, prec
, 0, STRING_MULTIBYTE (elt
));
15580 while ((precision
<= 0 || n
< precision
)
15582 && (frame_title_ptr
15583 || !NILP (mode_line_string_list
)
15584 || it
->current_x
< it
->last_visible_x
))
15586 const unsigned char *last
= this;
15588 /* Advance to end of string or next format specifier. */
15589 while ((c
= *this++) != '\0' && c
!= '%')
15592 if (this - 1 != last
)
15594 int nchars
, nbytes
;
15596 /* Output to end of string or up to '%'. Field width
15597 is length of string. Don't output more than
15598 PRECISION allows us. */
15601 prec
= c_string_width (last
, this - last
, precision
- n
,
15604 if (frame_title_ptr
)
15605 n
+= store_frame_title (last
, 0, prec
);
15606 else if (!NILP (mode_line_string_list
))
15608 int bytepos
= last
- lisp_string
;
15609 int charpos
= string_byte_to_char (elt
, bytepos
);
15610 int endpos
= (precision
<= 0
15611 ? string_byte_to_char (elt
,
15612 this - lisp_string
)
15613 : charpos
+ nchars
);
15615 n
+= store_mode_line_string (NULL
,
15616 Fsubstring (elt
, make_number (charpos
),
15617 make_number (endpos
)),
15622 int bytepos
= last
- lisp_string
;
15623 int charpos
= string_byte_to_char (elt
, bytepos
);
15624 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15626 STRING_MULTIBYTE (elt
));
15629 else /* c == '%' */
15631 const unsigned char *percent_position
= this;
15633 /* Get the specified minimum width. Zero means
15636 while ((c
= *this++) >= '0' && c
<= '9')
15637 field
= field
* 10 + c
- '0';
15639 /* Don't pad beyond the total padding allowed. */
15640 if (field_width
- n
> 0 && field
> field_width
- n
)
15641 field
= field_width
- n
;
15643 /* Note that either PRECISION <= 0 or N < PRECISION. */
15644 prec
= precision
- n
;
15647 n
+= display_mode_element (it
, depth
, field
, prec
,
15648 Vglobal_mode_string
, props
,
15653 int bytepos
, charpos
;
15654 unsigned char *spec
;
15656 bytepos
= percent_position
- lisp_string
;
15657 charpos
= (STRING_MULTIBYTE (elt
)
15658 ? string_byte_to_char (elt
, bytepos
)
15662 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15664 if (frame_title_ptr
)
15665 n
+= store_frame_title (spec
, field
, prec
);
15666 else if (!NILP (mode_line_string_list
))
15668 int len
= strlen (spec
);
15669 Lisp_Object tem
= make_string (spec
, len
);
15670 props
= Ftext_properties_at (make_number (charpos
), elt
);
15671 /* Should only keep face property in props */
15672 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15676 int nglyphs_before
, nwritten
;
15678 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15679 nwritten
= display_string (spec
, Qnil
, elt
,
15684 /* Assign to the glyphs written above the
15685 string where the `%x' came from, position
15689 struct glyph
*glyph
15690 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15694 for (i
= 0; i
< nwritten
; ++i
)
15696 glyph
[i
].object
= elt
;
15697 glyph
[i
].charpos
= charpos
;
15712 /* A symbol: process the value of the symbol recursively
15713 as if it appeared here directly. Avoid error if symbol void.
15714 Special case: if value of symbol is a string, output the string
15717 register Lisp_Object tem
;
15719 /* If the variable is not marked as risky to set
15720 then its contents are risky to use. */
15721 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15724 tem
= Fboundp (elt
);
15727 tem
= Fsymbol_value (elt
);
15728 /* If value is a string, output that string literally:
15729 don't check for % within it. */
15733 if (!EQ (tem
, elt
))
15735 /* Give up right away for nil or t. */
15745 register Lisp_Object car
, tem
;
15747 /* A cons cell: five distinct cases.
15748 If first element is :eval or :propertize, do something special.
15749 If first element is a string or a cons, process all the elements
15750 and effectively concatenate them.
15751 If first element is a negative number, truncate displaying cdr to
15752 at most that many characters. If positive, pad (with spaces)
15753 to at least that many characters.
15754 If first element is a symbol, process the cadr or caddr recursively
15755 according to whether the symbol's value is non-nil or nil. */
15757 if (EQ (car
, QCeval
))
15759 /* An element of the form (:eval FORM) means evaluate FORM
15760 and use the result as mode line elements. */
15765 if (CONSP (XCDR (elt
)))
15768 spec
= safe_eval (XCAR (XCDR (elt
)));
15769 n
+= display_mode_element (it
, depth
, field_width
- n
,
15770 precision
- n
, spec
, props
,
15774 else if (EQ (car
, QCpropertize
))
15776 /* An element of the form (:propertize ELT PROPS...)
15777 means display ELT but applying properties PROPS. */
15782 if (CONSP (XCDR (elt
)))
15783 n
+= display_mode_element (it
, depth
, field_width
- n
,
15784 precision
- n
, XCAR (XCDR (elt
)),
15785 XCDR (XCDR (elt
)), risky
);
15787 else if (SYMBOLP (car
))
15789 tem
= Fboundp (car
);
15793 /* elt is now the cdr, and we know it is a cons cell.
15794 Use its car if CAR has a non-nil value. */
15797 tem
= Fsymbol_value (car
);
15804 /* Symbol's value is nil (or symbol is unbound)
15805 Get the cddr of the original list
15806 and if possible find the caddr and use that. */
15810 else if (!CONSP (elt
))
15815 else if (INTEGERP (car
))
15817 register int lim
= XINT (car
);
15821 /* Negative int means reduce maximum width. */
15822 if (precision
<= 0)
15825 precision
= min (precision
, -lim
);
15829 /* Padding specified. Don't let it be more than
15830 current maximum. */
15832 lim
= min (precision
, lim
);
15834 /* If that's more padding than already wanted, queue it.
15835 But don't reduce padding already specified even if
15836 that is beyond the current truncation point. */
15837 field_width
= max (lim
, field_width
);
15841 else if (STRINGP (car
) || CONSP (car
))
15843 register int limit
= 50;
15844 /* Limit is to protect against circular lists. */
15847 && (precision
<= 0 || n
< precision
))
15849 n
+= display_mode_element (it
, depth
, field_width
- n
,
15850 precision
- n
, XCAR (elt
),
15860 elt
= build_string ("*invalid*");
15864 /* Pad to FIELD_WIDTH. */
15865 if (field_width
> 0 && n
< field_width
)
15867 if (frame_title_ptr
)
15868 n
+= store_frame_title ("", field_width
- n
, 0);
15869 else if (!NILP (mode_line_string_list
))
15870 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15872 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15879 /* Store a mode-line string element in mode_line_string_list.
15881 If STRING is non-null, display that C string. Otherwise, the Lisp
15882 string LISP_STRING is displayed.
15884 FIELD_WIDTH is the minimum number of output glyphs to produce.
15885 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15886 with spaces. FIELD_WIDTH <= 0 means don't pad.
15888 PRECISION is the maximum number of characters to output from
15889 STRING. PRECISION <= 0 means don't truncate the string.
15891 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15892 properties to the string.
15894 PROPS are the properties to add to the string.
15895 The mode_line_string_face face property is always added to the string.
15899 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15901 Lisp_Object lisp_string
;
15910 if (string
!= NULL
)
15912 len
= strlen (string
);
15913 if (precision
> 0 && len
> precision
)
15915 lisp_string
= make_string (string
, len
);
15917 props
= mode_line_string_face_prop
;
15918 else if (!NILP (mode_line_string_face
))
15920 Lisp_Object face
= Fsafe_plist_get (props
, Qface
);
15921 props
= Fcopy_sequence (props
);
15923 face
= mode_line_string_face
;
15925 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15926 props
= Fplist_put (props
, Qface
, face
);
15928 Fadd_text_properties (make_number (0), make_number (len
),
15929 props
, lisp_string
);
15933 len
= XFASTINT (Flength (lisp_string
));
15934 if (precision
> 0 && len
> precision
)
15937 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15940 if (!NILP (mode_line_string_face
))
15944 props
= Ftext_properties_at (make_number (0), lisp_string
);
15945 face
= Fsafe_plist_get (props
, Qface
);
15947 face
= mode_line_string_face
;
15949 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15950 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15952 lisp_string
= Fcopy_sequence (lisp_string
);
15955 Fadd_text_properties (make_number (0), make_number (len
),
15956 props
, lisp_string
);
15961 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15965 if (field_width
> len
)
15967 field_width
-= len
;
15968 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15970 Fadd_text_properties (make_number (0), make_number (field_width
),
15971 props
, lisp_string
);
15972 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15980 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15982 doc
: /* Format a string out of a mode line format specification.
15983 First arg FORMAT specifies the mode line format (see `mode-line-format'
15984 for details) to use.
15986 Optional second arg FACE specifies the face property to put
15987 on all characters for which no face is specified.
15988 t means whatever face the window's mode line currently uses
15989 \(either `mode-line' or `mode-line-inactive', depending).
15990 nil means the default is no face property.
15991 If FACE is an integer, the value string has no text properties.
15993 Optional third and fourth args WINDOW and BUFFER specify the window
15994 and buffer to use as the context for the formatting (defaults
15995 are the selected window and the window's buffer). */)
15996 (format
, face
, window
, buffer
)
15997 Lisp_Object format
, face
, window
, buffer
;
16002 struct buffer
*old_buffer
= NULL
;
16004 int no_props
= INTEGERP (face
);
16007 window
= selected_window
;
16008 CHECK_WINDOW (window
);
16009 w
= XWINDOW (window
);
16012 buffer
= w
->buffer
;
16013 CHECK_BUFFER (buffer
);
16016 return build_string ("");
16024 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16025 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16029 face_id
= DEFAULT_FACE_ID
;
16031 if (XBUFFER (buffer
) != current_buffer
)
16033 old_buffer
= current_buffer
;
16034 set_buffer_internal_1 (XBUFFER (buffer
));
16037 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16041 mode_line_string_face
= face
;
16042 mode_line_string_face_prop
16043 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16045 /* We need a dummy last element in mode_line_string_list to
16046 indicate we are building the propertized mode-line string.
16047 Using mode_line_string_face_prop here GC protects it. */
16048 mode_line_string_list
16049 = Fcons (mode_line_string_face_prop
, Qnil
);
16050 frame_title_ptr
= NULL
;
16054 mode_line_string_face_prop
= Qnil
;
16055 mode_line_string_list
= Qnil
;
16056 frame_title_ptr
= frame_title_buf
;
16059 push_frame_kboard (it
.f
);
16060 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16061 pop_frame_kboard ();
16064 set_buffer_internal_1 (old_buffer
);
16069 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16070 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
16071 make_string ("", 0));
16072 mode_line_string_face_prop
= Qnil
;
16073 mode_line_string_list
= Qnil
;
16077 len
= frame_title_ptr
- frame_title_buf
;
16078 if (len
> 0 && frame_title_ptr
[-1] == '-')
16080 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
16081 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
16083 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
16084 if (len
> frame_title_ptr
- frame_title_buf
)
16085 len
= frame_title_ptr
- frame_title_buf
;
16088 frame_title_ptr
= NULL
;
16089 return make_string (frame_title_buf
, len
);
16092 /* Write a null-terminated, right justified decimal representation of
16093 the positive integer D to BUF using a minimal field width WIDTH. */
16096 pint2str (buf
, width
, d
)
16097 register char *buf
;
16098 register int width
;
16101 register char *p
= buf
;
16109 *p
++ = d
% 10 + '0';
16114 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16125 /* Write a null-terminated, right justified decimal and "human
16126 readable" representation of the nonnegative integer D to BUF using
16127 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16129 static const char power_letter
[] =
16143 pint2hrstr (buf
, width
, d
)
16148 /* We aim to represent the nonnegative integer D as
16149 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16152 /* -1 means: do not use TENTHS. */
16156 /* Length of QUOTIENT.TENTHS as a string. */
16162 if (1000 <= quotient
)
16164 /* Scale to the appropriate EXPONENT. */
16167 remainder
= quotient
% 1000;
16171 while (1000 <= quotient
);
16173 /* Round to nearest and decide whether to use TENTHS or not. */
16176 tenths
= remainder
/ 100;
16177 if (50 <= remainder
% 100)
16184 if (quotient
== 10)
16192 if (500 <= remainder
)
16194 if (quotient
< 999)
16205 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16206 if (tenths
== -1 && quotient
<= 99)
16213 p
= psuffix
= buf
+ max (width
, length
);
16215 /* Print EXPONENT. */
16217 *psuffix
++ = power_letter
[exponent
];
16220 /* Print TENTHS. */
16223 *--p
= '0' + tenths
;
16227 /* Print QUOTIENT. */
16230 int digit
= quotient
% 10;
16231 *--p
= '0' + digit
;
16233 while ((quotient
/= 10) != 0);
16235 /* Print leading spaces. */
16240 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16241 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16242 type of CODING_SYSTEM. Return updated pointer into BUF. */
16244 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16247 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16248 Lisp_Object coding_system
;
16249 register char *buf
;
16253 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16254 const unsigned char *eol_str
;
16256 /* The EOL conversion we are using. */
16257 Lisp_Object eoltype
;
16259 val
= Fget (coding_system
, Qcoding_system
);
16262 if (!VECTORP (val
)) /* Not yet decided. */
16267 eoltype
= eol_mnemonic_undecided
;
16268 /* Don't mention EOL conversion if it isn't decided. */
16272 Lisp_Object eolvalue
;
16274 eolvalue
= Fget (coding_system
, Qeol_type
);
16277 *buf
++ = XFASTINT (AREF (val
, 1));
16281 /* The EOL conversion that is normal on this system. */
16283 if (NILP (eolvalue
)) /* Not yet decided. */
16284 eoltype
= eol_mnemonic_undecided
;
16285 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16286 eoltype
= eol_mnemonic_undecided
;
16287 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16288 eoltype
= (XFASTINT (eolvalue
) == 0
16289 ? eol_mnemonic_unix
16290 : (XFASTINT (eolvalue
) == 1
16291 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16297 /* Mention the EOL conversion if it is not the usual one. */
16298 if (STRINGP (eoltype
))
16300 eol_str
= SDATA (eoltype
);
16301 eol_str_len
= SBYTES (eoltype
);
16303 else if (INTEGERP (eoltype
)
16304 && CHAR_VALID_P (XINT (eoltype
), 0))
16306 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16307 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16312 eol_str
= invalid_eol_type
;
16313 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16315 bcopy (eol_str
, buf
, eol_str_len
);
16316 buf
+= eol_str_len
;
16322 /* Return a string for the output of a mode line %-spec for window W,
16323 generated by character C. PRECISION >= 0 means don't return a
16324 string longer than that value. FIELD_WIDTH > 0 means pad the
16325 string returned with spaces to that value. Return 1 in *MULTIBYTE
16326 if the result is multibyte text.
16328 Note we operate on the current buffer for most purposes,
16329 the exception being w->base_line_pos. */
16331 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16334 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16337 int field_width
, precision
;
16341 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16342 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16343 struct buffer
*b
= current_buffer
;
16351 if (!NILP (b
->read_only
))
16353 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16358 /* This differs from %* only for a modified read-only buffer. */
16359 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16361 if (!NILP (b
->read_only
))
16366 /* This differs from %* in ignoring read-only-ness. */
16367 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16379 if (command_loop_level
> 5)
16381 p
= decode_mode_spec_buf
;
16382 for (i
= 0; i
< command_loop_level
; i
++)
16385 return decode_mode_spec_buf
;
16393 if (command_loop_level
> 5)
16395 p
= decode_mode_spec_buf
;
16396 for (i
= 0; i
< command_loop_level
; i
++)
16399 return decode_mode_spec_buf
;
16406 /* Let lots_of_dashes be a string of infinite length. */
16407 if (!NILP (mode_line_string_list
))
16409 if (field_width
<= 0
16410 || field_width
> sizeof (lots_of_dashes
))
16412 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16413 decode_mode_spec_buf
[i
] = '-';
16414 decode_mode_spec_buf
[i
] = '\0';
16415 return decode_mode_spec_buf
;
16418 return lots_of_dashes
;
16427 int col
= (int) current_column (); /* iftc */
16428 w
->column_number_displayed
= make_number (col
);
16429 pint2str (decode_mode_spec_buf
, field_width
, col
);
16430 return decode_mode_spec_buf
;
16434 /* %F displays the frame name. */
16435 if (!NILP (f
->title
))
16436 return (char *) SDATA (f
->title
);
16437 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16438 return (char *) SDATA (f
->name
);
16447 int size
= ZV
- BEGV
;
16448 pint2str (decode_mode_spec_buf
, field_width
, size
);
16449 return decode_mode_spec_buf
;
16454 int size
= ZV
- BEGV
;
16455 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16456 return decode_mode_spec_buf
;
16461 int startpos
= XMARKER (w
->start
)->charpos
;
16462 int startpos_byte
= marker_byte_position (w
->start
);
16463 int line
, linepos
, linepos_byte
, topline
;
16465 int height
= WINDOW_TOTAL_LINES (w
);
16467 /* If we decided that this buffer isn't suitable for line numbers,
16468 don't forget that too fast. */
16469 if (EQ (w
->base_line_pos
, w
->buffer
))
16471 /* But do forget it, if the window shows a different buffer now. */
16472 else if (BUFFERP (w
->base_line_pos
))
16473 w
->base_line_pos
= Qnil
;
16475 /* If the buffer is very big, don't waste time. */
16476 if (INTEGERP (Vline_number_display_limit
)
16477 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16479 w
->base_line_pos
= Qnil
;
16480 w
->base_line_number
= Qnil
;
16484 if (!NILP (w
->base_line_number
)
16485 && !NILP (w
->base_line_pos
)
16486 && XFASTINT (w
->base_line_pos
) <= startpos
)
16488 line
= XFASTINT (w
->base_line_number
);
16489 linepos
= XFASTINT (w
->base_line_pos
);
16490 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16495 linepos
= BUF_BEGV (b
);
16496 linepos_byte
= BUF_BEGV_BYTE (b
);
16499 /* Count lines from base line to window start position. */
16500 nlines
= display_count_lines (linepos
, linepos_byte
,
16504 topline
= nlines
+ line
;
16506 /* Determine a new base line, if the old one is too close
16507 or too far away, or if we did not have one.
16508 "Too close" means it's plausible a scroll-down would
16509 go back past it. */
16510 if (startpos
== BUF_BEGV (b
))
16512 w
->base_line_number
= make_number (topline
);
16513 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16515 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16516 || linepos
== BUF_BEGV (b
))
16518 int limit
= BUF_BEGV (b
);
16519 int limit_byte
= BUF_BEGV_BYTE (b
);
16521 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16523 if (startpos
- distance
> limit
)
16525 limit
= startpos
- distance
;
16526 limit_byte
= CHAR_TO_BYTE (limit
);
16529 nlines
= display_count_lines (startpos
, startpos_byte
,
16531 - (height
* 2 + 30),
16533 /* If we couldn't find the lines we wanted within
16534 line_number_display_limit_width chars per line,
16535 give up on line numbers for this window. */
16536 if (position
== limit_byte
&& limit
== startpos
- distance
)
16538 w
->base_line_pos
= w
->buffer
;
16539 w
->base_line_number
= Qnil
;
16543 w
->base_line_number
= make_number (topline
- nlines
);
16544 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16547 /* Now count lines from the start pos to point. */
16548 nlines
= display_count_lines (startpos
, startpos_byte
,
16549 PT_BYTE
, PT
, &junk
);
16551 /* Record that we did display the line number. */
16552 line_number_displayed
= 1;
16554 /* Make the string to show. */
16555 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16556 return decode_mode_spec_buf
;
16559 char* p
= decode_mode_spec_buf
;
16560 int pad
= field_width
- 2;
16566 return decode_mode_spec_buf
;
16572 obj
= b
->mode_name
;
16576 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16582 int pos
= marker_position (w
->start
);
16583 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16585 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16587 if (pos
<= BUF_BEGV (b
))
16592 else if (pos
<= BUF_BEGV (b
))
16596 if (total
> 1000000)
16597 /* Do it differently for a large value, to avoid overflow. */
16598 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16600 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16601 /* We can't normally display a 3-digit number,
16602 so get us a 2-digit number that is close. */
16605 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16606 return decode_mode_spec_buf
;
16610 /* Display percentage of size above the bottom of the screen. */
16613 int toppos
= marker_position (w
->start
);
16614 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16615 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16617 if (botpos
>= BUF_ZV (b
))
16619 if (toppos
<= BUF_BEGV (b
))
16626 if (total
> 1000000)
16627 /* Do it differently for a large value, to avoid overflow. */
16628 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16630 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16631 /* We can't normally display a 3-digit number,
16632 so get us a 2-digit number that is close. */
16635 if (toppos
<= BUF_BEGV (b
))
16636 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16638 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16639 return decode_mode_spec_buf
;
16644 /* status of process */
16645 obj
= Fget_buffer_process (Fcurrent_buffer ());
16647 return "no process";
16648 #ifdef subprocesses
16649 obj
= Fsymbol_name (Fprocess_status (obj
));
16653 case 't': /* indicate TEXT or BINARY */
16654 #ifdef MODE_LINE_BINARY_TEXT
16655 return MODE_LINE_BINARY_TEXT (b
);
16661 /* coding-system (not including end-of-line format) */
16663 /* coding-system (including end-of-line type) */
16665 int eol_flag
= (c
== 'Z');
16666 char *p
= decode_mode_spec_buf
;
16668 if (! FRAME_WINDOW_P (f
))
16670 /* No need to mention EOL here--the terminal never needs
16671 to do EOL conversion. */
16672 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16673 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16675 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16678 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16679 #ifdef subprocesses
16680 obj
= Fget_buffer_process (Fcurrent_buffer ());
16681 if (PROCESSP (obj
))
16683 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16685 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16688 #endif /* subprocesses */
16691 return decode_mode_spec_buf
;
16697 *multibyte
= STRING_MULTIBYTE (obj
);
16698 return (char *) SDATA (obj
);
16705 /* Count up to COUNT lines starting from START / START_BYTE.
16706 But don't go beyond LIMIT_BYTE.
16707 Return the number of lines thus found (always nonnegative).
16709 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16712 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16713 int start
, start_byte
, limit_byte
, count
;
16716 register unsigned char *cursor
;
16717 unsigned char *base
;
16719 register int ceiling
;
16720 register unsigned char *ceiling_addr
;
16721 int orig_count
= count
;
16723 /* If we are not in selective display mode,
16724 check only for newlines. */
16725 int selective_display
= (!NILP (current_buffer
->selective_display
)
16726 && !INTEGERP (current_buffer
->selective_display
));
16730 while (start_byte
< limit_byte
)
16732 ceiling
= BUFFER_CEILING_OF (start_byte
);
16733 ceiling
= min (limit_byte
- 1, ceiling
);
16734 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16735 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16738 if (selective_display
)
16739 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16742 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16745 if (cursor
!= ceiling_addr
)
16749 start_byte
+= cursor
- base
+ 1;
16750 *byte_pos_ptr
= start_byte
;
16754 if (++cursor
== ceiling_addr
)
16760 start_byte
+= cursor
- base
;
16765 while (start_byte
> limit_byte
)
16767 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16768 ceiling
= max (limit_byte
, ceiling
);
16769 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16770 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16773 if (selective_display
)
16774 while (--cursor
!= ceiling_addr
16775 && *cursor
!= '\n' && *cursor
!= 015)
16778 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16781 if (cursor
!= ceiling_addr
)
16785 start_byte
+= cursor
- base
+ 1;
16786 *byte_pos_ptr
= start_byte
;
16787 /* When scanning backwards, we should
16788 not count the newline posterior to which we stop. */
16789 return - orig_count
- 1;
16795 /* Here we add 1 to compensate for the last decrement
16796 of CURSOR, which took it past the valid range. */
16797 start_byte
+= cursor
- base
+ 1;
16801 *byte_pos_ptr
= limit_byte
;
16804 return - orig_count
+ count
;
16805 return orig_count
- count
;
16811 /***********************************************************************
16813 ***********************************************************************/
16815 /* Display a NUL-terminated string, starting with index START.
16817 If STRING is non-null, display that C string. Otherwise, the Lisp
16818 string LISP_STRING is displayed.
16820 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16821 FACE_STRING. Display STRING or LISP_STRING with the face at
16822 FACE_STRING_POS in FACE_STRING:
16824 Display the string in the environment given by IT, but use the
16825 standard display table, temporarily.
16827 FIELD_WIDTH is the minimum number of output glyphs to produce.
16828 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16829 with spaces. If STRING has more characters, more than FIELD_WIDTH
16830 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16832 PRECISION is the maximum number of characters to output from
16833 STRING. PRECISION < 0 means don't truncate the string.
16835 This is roughly equivalent to printf format specifiers:
16837 FIELD_WIDTH PRECISION PRINTF
16838 ----------------------------------------
16844 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16845 display them, and < 0 means obey the current buffer's value of
16846 enable_multibyte_characters.
16848 Value is the number of glyphs produced. */
16851 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16852 start
, it
, field_width
, precision
, max_x
, multibyte
)
16853 unsigned char *string
;
16854 Lisp_Object lisp_string
;
16855 Lisp_Object face_string
;
16856 int face_string_pos
;
16859 int field_width
, precision
, max_x
;
16862 int hpos_at_start
= it
->hpos
;
16863 int saved_face_id
= it
->face_id
;
16864 struct glyph_row
*row
= it
->glyph_row
;
16866 /* Initialize the iterator IT for iteration over STRING beginning
16867 with index START. */
16868 reseat_to_string (it
, string
, lisp_string
, start
,
16869 precision
, field_width
, multibyte
);
16871 /* If displaying STRING, set up the face of the iterator
16872 from LISP_STRING, if that's given. */
16873 if (STRINGP (face_string
))
16879 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16880 0, it
->region_beg_charpos
,
16881 it
->region_end_charpos
,
16882 &endptr
, it
->base_face_id
, 0);
16883 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16884 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16887 /* Set max_x to the maximum allowed X position. Don't let it go
16888 beyond the right edge of the window. */
16890 max_x
= it
->last_visible_x
;
16892 max_x
= min (max_x
, it
->last_visible_x
);
16894 /* Skip over display elements that are not visible. because IT->w is
16896 if (it
->current_x
< it
->first_visible_x
)
16897 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16898 MOVE_TO_POS
| MOVE_TO_X
);
16900 row
->ascent
= it
->max_ascent
;
16901 row
->height
= it
->max_ascent
+ it
->max_descent
;
16902 row
->phys_ascent
= it
->max_phys_ascent
;
16903 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16904 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16906 /* This condition is for the case that we are called with current_x
16907 past last_visible_x. */
16908 while (it
->current_x
< max_x
)
16910 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16912 /* Get the next display element. */
16913 if (!get_next_display_element (it
))
16916 /* Produce glyphs. */
16917 x_before
= it
->current_x
;
16918 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16919 PRODUCE_GLYPHS (it
);
16921 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16924 while (i
< nglyphs
)
16926 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16928 if (!it
->truncate_lines_p
16929 && x
+ glyph
->pixel_width
> max_x
)
16931 /* End of continued line or max_x reached. */
16932 if (CHAR_GLYPH_PADDING_P (*glyph
))
16934 /* A wide character is unbreakable. */
16935 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16936 it
->current_x
= x_before
;
16940 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16945 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16947 /* Glyph is at least partially visible. */
16949 if (x
< it
->first_visible_x
)
16950 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16954 /* Glyph is off the left margin of the display area.
16955 Should not happen. */
16959 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16960 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16961 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16962 row
->phys_height
= max (row
->phys_height
,
16963 it
->max_phys_ascent
+ it
->max_phys_descent
);
16964 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16965 it
->max_extra_line_spacing
);
16966 x
+= glyph
->pixel_width
;
16970 /* Stop if max_x reached. */
16974 /* Stop at line ends. */
16975 if (ITERATOR_AT_END_OF_LINE_P (it
))
16977 it
->continuation_lines_width
= 0;
16981 set_iterator_to_next (it
, 1);
16983 /* Stop if truncating at the right edge. */
16984 if (it
->truncate_lines_p
16985 && it
->current_x
>= it
->last_visible_x
)
16987 /* Add truncation mark, but don't do it if the line is
16988 truncated at a padding space. */
16989 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16991 if (!FRAME_WINDOW_P (it
->f
))
16995 if (it
->current_x
> it
->last_visible_x
)
16997 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16998 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17000 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17002 row
->used
[TEXT_AREA
] = i
;
17003 produce_special_glyphs (it
, IT_TRUNCATION
);
17006 produce_special_glyphs (it
, IT_TRUNCATION
);
17008 it
->glyph_row
->truncated_on_right_p
= 1;
17014 /* Maybe insert a truncation at the left. */
17015 if (it
->first_visible_x
17016 && IT_CHARPOS (*it
) > 0)
17018 if (!FRAME_WINDOW_P (it
->f
))
17019 insert_left_trunc_glyphs (it
);
17020 it
->glyph_row
->truncated_on_left_p
= 1;
17023 it
->face_id
= saved_face_id
;
17025 /* Value is number of columns displayed. */
17026 return it
->hpos
- hpos_at_start
;
17031 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17032 appears as an element of LIST or as the car of an element of LIST.
17033 If PROPVAL is a list, compare each element against LIST in that
17034 way, and return 1/2 if any element of PROPVAL is found in LIST.
17035 Otherwise return 0. This function cannot quit.
17036 The return value is 2 if the text is invisible but with an ellipsis
17037 and 1 if it's invisible and without an ellipsis. */
17040 invisible_p (propval
, list
)
17041 register Lisp_Object propval
;
17044 register Lisp_Object tail
, proptail
;
17046 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17048 register Lisp_Object tem
;
17050 if (EQ (propval
, tem
))
17052 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17053 return NILP (XCDR (tem
)) ? 1 : 2;
17056 if (CONSP (propval
))
17058 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17060 Lisp_Object propelt
;
17061 propelt
= XCAR (proptail
);
17062 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17064 register Lisp_Object tem
;
17066 if (EQ (propelt
, tem
))
17068 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17069 return NILP (XCDR (tem
)) ? 1 : 2;
17077 /* Calculate a width or height in pixels from a specification using
17078 the following elements:
17081 NUM - a (fractional) multiple of the default font width/height
17082 (NUM) - specifies exactly NUM pixels
17083 UNIT - a fixed number of pixels, see below.
17084 ELEMENT - size of a display element in pixels, see below.
17085 (NUM . SPEC) - equals NUM * SPEC
17086 (+ SPEC SPEC ...) - add pixel values
17087 (- SPEC SPEC ...) - subtract pixel values
17088 (- SPEC) - negate pixel value
17091 INT or FLOAT - a number constant
17092 SYMBOL - use symbol's (buffer local) variable binding.
17095 in - pixels per inch *)
17096 mm - pixels per 1/1000 meter *)
17097 cm - pixels per 1/100 meter *)
17098 width - width of current font in pixels.
17099 height - height of current font in pixels.
17101 *) using the ratio(s) defined in display-pixels-per-inch.
17105 left-fringe - left fringe width in pixels
17106 right-fringe - right fringe width in pixels
17108 left-margin - left margin width in pixels
17109 right-margin - right margin width in pixels
17111 scroll-bar - scroll-bar area width in pixels
17115 Pixels corresponding to 5 inches:
17118 Total width of non-text areas on left side of window (if scroll-bar is on left):
17119 '(space :width (+ left-fringe left-margin scroll-bar))
17121 Align to first text column (in header line):
17122 '(space :align-to 0)
17124 Align to middle of text area minus half the width of variable `my-image'
17125 containing a loaded image:
17126 '(space :align-to (0.5 . (- text my-image)))
17128 Width of left margin minus width of 1 character in the default font:
17129 '(space :width (- left-margin 1))
17131 Width of left margin minus width of 2 characters in the current font:
17132 '(space :width (- left-margin (2 . width)))
17134 Center 1 character over left-margin (in header line):
17135 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17137 Different ways to express width of left fringe plus left margin minus one pixel:
17138 '(space :width (- (+ left-fringe left-margin) (1)))
17139 '(space :width (+ left-fringe left-margin (- (1))))
17140 '(space :width (+ left-fringe left-margin (-1)))
17144 #define NUMVAL(X) \
17145 ((INTEGERP (X) || FLOATP (X)) \
17150 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17155 int width_p
, *align_to
;
17159 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17160 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17163 return OK_PIXELS (0);
17165 if (SYMBOLP (prop
))
17167 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17169 char *unit
= SDATA (SYMBOL_NAME (prop
));
17171 if (unit
[0] == 'i' && unit
[1] == 'n')
17173 else if (unit
[0] == 'm' && unit
[1] == 'm')
17175 else if (unit
[0] == 'c' && unit
[1] == 'm')
17182 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17183 || (CONSP (Vdisplay_pixels_per_inch
)
17185 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17186 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17188 return OK_PIXELS (ppi
/ pixels
);
17194 #ifdef HAVE_WINDOW_SYSTEM
17195 if (EQ (prop
, Qheight
))
17196 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17197 if (EQ (prop
, Qwidth
))
17198 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17200 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17201 return OK_PIXELS (1);
17204 if (EQ (prop
, Qtext
))
17205 return OK_PIXELS (width_p
17206 ? window_box_width (it
->w
, TEXT_AREA
)
17207 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17209 if (align_to
&& *align_to
< 0)
17212 if (EQ (prop
, Qleft
))
17213 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17214 if (EQ (prop
, Qright
))
17215 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17216 if (EQ (prop
, Qcenter
))
17217 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17218 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17219 if (EQ (prop
, Qleft_fringe
))
17220 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17221 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17222 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17223 if (EQ (prop
, Qright_fringe
))
17224 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17225 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17226 : window_box_right_offset (it
->w
, TEXT_AREA
));
17227 if (EQ (prop
, Qleft_margin
))
17228 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17229 if (EQ (prop
, Qright_margin
))
17230 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17231 if (EQ (prop
, Qscroll_bar
))
17232 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17234 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17235 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17236 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17241 if (EQ (prop
, Qleft_fringe
))
17242 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17243 if (EQ (prop
, Qright_fringe
))
17244 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17245 if (EQ (prop
, Qleft_margin
))
17246 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17247 if (EQ (prop
, Qright_margin
))
17248 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17249 if (EQ (prop
, Qscroll_bar
))
17250 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17253 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17256 if (INTEGERP (prop
) || FLOATP (prop
))
17258 int base_unit
= (width_p
17259 ? FRAME_COLUMN_WIDTH (it
->f
)
17260 : FRAME_LINE_HEIGHT (it
->f
));
17261 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17266 Lisp_Object car
= XCAR (prop
);
17267 Lisp_Object cdr
= XCDR (prop
);
17271 #ifdef HAVE_WINDOW_SYSTEM
17272 if (valid_image_p (prop
))
17274 int id
= lookup_image (it
->f
, prop
);
17275 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17277 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17280 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17286 while (CONSP (cdr
))
17288 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17289 font
, width_p
, align_to
))
17292 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17297 if (EQ (car
, Qminus
))
17299 return OK_PIXELS (pixels
);
17302 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17305 if (INTEGERP (car
) || FLOATP (car
))
17308 pixels
= XFLOATINT (car
);
17310 return OK_PIXELS (pixels
);
17311 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17312 font
, width_p
, align_to
))
17313 return OK_PIXELS (pixels
* fact
);
17324 /***********************************************************************
17326 ***********************************************************************/
17328 #ifdef HAVE_WINDOW_SYSTEM
17333 dump_glyph_string (s
)
17334 struct glyph_string
*s
;
17336 fprintf (stderr
, "glyph string\n");
17337 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17338 s
->x
, s
->y
, s
->width
, s
->height
);
17339 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17340 fprintf (stderr
, " hl = %d\n", s
->hl
);
17341 fprintf (stderr
, " left overhang = %d, right = %d\n",
17342 s
->left_overhang
, s
->right_overhang
);
17343 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17344 fprintf (stderr
, " extends to end of line = %d\n",
17345 s
->extends_to_end_of_line_p
);
17346 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17347 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17350 #endif /* GLYPH_DEBUG */
17352 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17353 of XChar2b structures for S; it can't be allocated in
17354 init_glyph_string because it must be allocated via `alloca'. W
17355 is the window on which S is drawn. ROW and AREA are the glyph row
17356 and area within the row from which S is constructed. START is the
17357 index of the first glyph structure covered by S. HL is a
17358 face-override for drawing S. */
17361 #define OPTIONAL_HDC(hdc) hdc,
17362 #define DECLARE_HDC(hdc) HDC hdc;
17363 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17364 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17367 #ifndef OPTIONAL_HDC
17368 #define OPTIONAL_HDC(hdc)
17369 #define DECLARE_HDC(hdc)
17370 #define ALLOCATE_HDC(hdc, f)
17371 #define RELEASE_HDC(hdc, f)
17375 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17376 struct glyph_string
*s
;
17380 struct glyph_row
*row
;
17381 enum glyph_row_area area
;
17383 enum draw_glyphs_face hl
;
17385 bzero (s
, sizeof *s
);
17387 s
->f
= XFRAME (w
->frame
);
17391 s
->display
= FRAME_X_DISPLAY (s
->f
);
17392 s
->window
= FRAME_X_WINDOW (s
->f
);
17393 s
->char2b
= char2b
;
17397 s
->first_glyph
= row
->glyphs
[area
] + start
;
17398 s
->height
= row
->height
;
17399 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17401 /* Display the internal border below the tool-bar window. */
17402 if (WINDOWP (s
->f
->tool_bar_window
)
17403 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17404 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17406 s
->ybase
= s
->y
+ row
->ascent
;
17410 /* Append the list of glyph strings with head H and tail T to the list
17411 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17414 append_glyph_string_lists (head
, tail
, h
, t
)
17415 struct glyph_string
**head
, **tail
;
17416 struct glyph_string
*h
, *t
;
17430 /* Prepend the list of glyph strings with head H and tail T to the
17431 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17435 prepend_glyph_string_lists (head
, tail
, h
, t
)
17436 struct glyph_string
**head
, **tail
;
17437 struct glyph_string
*h
, *t
;
17451 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17452 Set *HEAD and *TAIL to the resulting list. */
17455 append_glyph_string (head
, tail
, s
)
17456 struct glyph_string
**head
, **tail
;
17457 struct glyph_string
*s
;
17459 s
->next
= s
->prev
= NULL
;
17460 append_glyph_string_lists (head
, tail
, s
, s
);
17464 /* Get face and two-byte form of character glyph GLYPH on frame F.
17465 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17466 a pointer to a realized face that is ready for display. */
17468 static INLINE
struct face
*
17469 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17471 struct glyph
*glyph
;
17477 xassert (glyph
->type
== CHAR_GLYPH
);
17478 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17483 if (!glyph
->multibyte_p
)
17485 /* Unibyte case. We don't have to encode, but we have to make
17486 sure to use a face suitable for unibyte. */
17487 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17489 else if (glyph
->u
.ch
< 128
17490 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17492 /* Case of ASCII in a face known to fit ASCII. */
17493 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17497 int c1
, c2
, charset
;
17499 /* Split characters into bytes. If c2 is -1 afterwards, C is
17500 really a one-byte character so that byte1 is zero. */
17501 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17503 STORE_XCHAR2B (char2b
, c1
, c2
);
17505 STORE_XCHAR2B (char2b
, 0, c1
);
17507 /* Maybe encode the character in *CHAR2B. */
17508 if (charset
!= CHARSET_ASCII
)
17510 struct font_info
*font_info
17511 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17514 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17518 /* Make sure X resources of the face are allocated. */
17519 xassert (face
!= NULL
);
17520 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17525 /* Fill glyph string S with composition components specified by S->cmp.
17527 FACES is an array of faces for all components of this composition.
17528 S->gidx is the index of the first component for S.
17529 OVERLAPS_P non-zero means S should draw the foreground only, and
17530 use its physical height for clipping.
17532 Value is the index of a component not in S. */
17535 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17536 struct glyph_string
*s
;
17537 struct face
**faces
;
17544 s
->for_overlaps_p
= overlaps_p
;
17546 s
->face
= faces
[s
->gidx
];
17547 s
->font
= s
->face
->font
;
17548 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17550 /* For all glyphs of this composition, starting at the offset
17551 S->gidx, until we reach the end of the definition or encounter a
17552 glyph that requires the different face, add it to S. */
17554 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17557 /* All glyph strings for the same composition has the same width,
17558 i.e. the width set for the first component of the composition. */
17560 s
->width
= s
->first_glyph
->pixel_width
;
17562 /* If the specified font could not be loaded, use the frame's
17563 default font, but record the fact that we couldn't load it in
17564 the glyph string so that we can draw rectangles for the
17565 characters of the glyph string. */
17566 if (s
->font
== NULL
)
17568 s
->font_not_found_p
= 1;
17569 s
->font
= FRAME_FONT (s
->f
);
17572 /* Adjust base line for subscript/superscript text. */
17573 s
->ybase
+= s
->first_glyph
->voffset
;
17575 xassert (s
->face
&& s
->face
->gc
);
17577 /* This glyph string must always be drawn with 16-bit functions. */
17580 return s
->gidx
+ s
->nchars
;
17584 /* Fill glyph string S from a sequence of character glyphs.
17586 FACE_ID is the face id of the string. START is the index of the
17587 first glyph to consider, END is the index of the last + 1.
17588 OVERLAPS_P non-zero means S should draw the foreground only, and
17589 use its physical height for clipping.
17591 Value is the index of the first glyph not in S. */
17594 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17595 struct glyph_string
*s
;
17597 int start
, end
, overlaps_p
;
17599 struct glyph
*glyph
, *last
;
17601 int glyph_not_available_p
;
17603 xassert (s
->f
== XFRAME (s
->w
->frame
));
17604 xassert (s
->nchars
== 0);
17605 xassert (start
>= 0 && end
> start
);
17607 s
->for_overlaps_p
= overlaps_p
,
17608 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17609 last
= s
->row
->glyphs
[s
->area
] + end
;
17610 voffset
= glyph
->voffset
;
17612 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17614 while (glyph
< last
17615 && glyph
->type
== CHAR_GLYPH
17616 && glyph
->voffset
== voffset
17617 /* Same face id implies same font, nowadays. */
17618 && glyph
->face_id
== face_id
17619 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17623 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17624 s
->char2b
+ s
->nchars
,
17626 s
->two_byte_p
= two_byte_p
;
17628 xassert (s
->nchars
<= end
- start
);
17629 s
->width
+= glyph
->pixel_width
;
17633 s
->font
= s
->face
->font
;
17634 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17636 /* If the specified font could not be loaded, use the frame's font,
17637 but record the fact that we couldn't load it in
17638 S->font_not_found_p so that we can draw rectangles for the
17639 characters of the glyph string. */
17640 if (s
->font
== NULL
|| glyph_not_available_p
)
17642 s
->font_not_found_p
= 1;
17643 s
->font
= FRAME_FONT (s
->f
);
17646 /* Adjust base line for subscript/superscript text. */
17647 s
->ybase
+= voffset
;
17649 xassert (s
->face
&& s
->face
->gc
);
17650 return glyph
- s
->row
->glyphs
[s
->area
];
17654 /* Fill glyph string S from image glyph S->first_glyph. */
17657 fill_image_glyph_string (s
)
17658 struct glyph_string
*s
;
17660 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17661 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17663 s
->slice
= s
->first_glyph
->slice
;
17664 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17665 s
->font
= s
->face
->font
;
17666 s
->width
= s
->first_glyph
->pixel_width
;
17668 /* Adjust base line for subscript/superscript text. */
17669 s
->ybase
+= s
->first_glyph
->voffset
;
17673 /* Fill glyph string S from a sequence of stretch glyphs.
17675 ROW is the glyph row in which the glyphs are found, AREA is the
17676 area within the row. START is the index of the first glyph to
17677 consider, END is the index of the last + 1.
17679 Value is the index of the first glyph not in S. */
17682 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17683 struct glyph_string
*s
;
17684 struct glyph_row
*row
;
17685 enum glyph_row_area area
;
17688 struct glyph
*glyph
, *last
;
17689 int voffset
, face_id
;
17691 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17693 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17694 last
= s
->row
->glyphs
[s
->area
] + end
;
17695 face_id
= glyph
->face_id
;
17696 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17697 s
->font
= s
->face
->font
;
17698 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17699 s
->width
= glyph
->pixel_width
;
17700 voffset
= glyph
->voffset
;
17704 && glyph
->type
== STRETCH_GLYPH
17705 && glyph
->voffset
== voffset
17706 && glyph
->face_id
== face_id
);
17708 s
->width
+= glyph
->pixel_width
;
17710 /* Adjust base line for subscript/superscript text. */
17711 s
->ybase
+= voffset
;
17713 /* The case that face->gc == 0 is handled when drawing the glyph
17714 string by calling PREPARE_FACE_FOR_DISPLAY. */
17716 return glyph
- s
->row
->glyphs
[s
->area
];
17721 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17722 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17723 assumed to be zero. */
17726 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17727 struct glyph
*glyph
;
17731 *left
= *right
= 0;
17733 if (glyph
->type
== CHAR_GLYPH
)
17737 struct font_info
*font_info
;
17741 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17743 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17744 if (font
/* ++KFS: Should this be font_info ? */
17745 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17747 if (pcm
->rbearing
> pcm
->width
)
17748 *right
= pcm
->rbearing
- pcm
->width
;
17749 if (pcm
->lbearing
< 0)
17750 *left
= -pcm
->lbearing
;
17756 /* Return the index of the first glyph preceding glyph string S that
17757 is overwritten by S because of S's left overhang. Value is -1
17758 if no glyphs are overwritten. */
17761 left_overwritten (s
)
17762 struct glyph_string
*s
;
17766 if (s
->left_overhang
)
17769 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17770 int first
= s
->first_glyph
- glyphs
;
17772 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17773 x
-= glyphs
[i
].pixel_width
;
17784 /* Return the index of the first glyph preceding glyph string S that
17785 is overwriting S because of its right overhang. Value is -1 if no
17786 glyph in front of S overwrites S. */
17789 left_overwriting (s
)
17790 struct glyph_string
*s
;
17793 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17794 int first
= s
->first_glyph
- glyphs
;
17798 for (i
= first
- 1; i
>= 0; --i
)
17801 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17804 x
-= glyphs
[i
].pixel_width
;
17811 /* Return the index of the last glyph following glyph string S that is
17812 not overwritten by S because of S's right overhang. Value is -1 if
17813 no such glyph is found. */
17816 right_overwritten (s
)
17817 struct glyph_string
*s
;
17821 if (s
->right_overhang
)
17824 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17825 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17826 int end
= s
->row
->used
[s
->area
];
17828 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17829 x
+= glyphs
[i
].pixel_width
;
17838 /* Return the index of the last glyph following glyph string S that
17839 overwrites S because of its left overhang. Value is negative
17840 if no such glyph is found. */
17843 right_overwriting (s
)
17844 struct glyph_string
*s
;
17847 int end
= s
->row
->used
[s
->area
];
17848 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17849 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17853 for (i
= first
; i
< end
; ++i
)
17856 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17859 x
+= glyphs
[i
].pixel_width
;
17866 /* Get face and two-byte form of character C in face FACE_ID on frame
17867 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17868 means we want to display multibyte text. DISPLAY_P non-zero means
17869 make sure that X resources for the face returned are allocated.
17870 Value is a pointer to a realized face that is ready for display if
17871 DISPLAY_P is non-zero. */
17873 static INLINE
struct face
*
17874 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17878 int multibyte_p
, display_p
;
17880 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17884 /* Unibyte case. We don't have to encode, but we have to make
17885 sure to use a face suitable for unibyte. */
17886 STORE_XCHAR2B (char2b
, 0, c
);
17887 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17888 face
= FACE_FROM_ID (f
, face_id
);
17890 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17892 /* Case of ASCII in a face known to fit ASCII. */
17893 STORE_XCHAR2B (char2b
, 0, c
);
17897 int c1
, c2
, charset
;
17899 /* Split characters into bytes. If c2 is -1 afterwards, C is
17900 really a one-byte character so that byte1 is zero. */
17901 SPLIT_CHAR (c
, charset
, c1
, c2
);
17903 STORE_XCHAR2B (char2b
, c1
, c2
);
17905 STORE_XCHAR2B (char2b
, 0, c1
);
17907 /* Maybe encode the character in *CHAR2B. */
17908 if (face
->font
!= NULL
)
17910 struct font_info
*font_info
17911 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17913 rif
->encode_char (c
, char2b
, font_info
, 0);
17917 /* Make sure X resources of the face are allocated. */
17918 #ifdef HAVE_X_WINDOWS
17922 xassert (face
!= NULL
);
17923 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17930 /* Set background width of glyph string S. START is the index of the
17931 first glyph following S. LAST_X is the right-most x-position + 1
17932 in the drawing area. */
17935 set_glyph_string_background_width (s
, start
, last_x
)
17936 struct glyph_string
*s
;
17940 /* If the face of this glyph string has to be drawn to the end of
17941 the drawing area, set S->extends_to_end_of_line_p. */
17942 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17944 if (start
== s
->row
->used
[s
->area
]
17945 && s
->area
== TEXT_AREA
17946 && ((s
->hl
== DRAW_NORMAL_TEXT
17947 && (s
->row
->fill_line_p
17948 || s
->face
->background
!= default_face
->background
17949 || s
->face
->stipple
!= default_face
->stipple
17950 || s
->row
->mouse_face_p
))
17951 || s
->hl
== DRAW_MOUSE_FACE
17952 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17953 && s
->row
->fill_line_p
)))
17954 s
->extends_to_end_of_line_p
= 1;
17956 /* If S extends its face to the end of the line, set its
17957 background_width to the distance to the right edge of the drawing
17959 if (s
->extends_to_end_of_line_p
)
17960 s
->background_width
= last_x
- s
->x
+ 1;
17962 s
->background_width
= s
->width
;
17966 /* Compute overhangs and x-positions for glyph string S and its
17967 predecessors, or successors. X is the starting x-position for S.
17968 BACKWARD_P non-zero means process predecessors. */
17971 compute_overhangs_and_x (s
, x
, backward_p
)
17972 struct glyph_string
*s
;
17980 if (rif
->compute_glyph_string_overhangs
)
17981 rif
->compute_glyph_string_overhangs (s
);
17991 if (rif
->compute_glyph_string_overhangs
)
17992 rif
->compute_glyph_string_overhangs (s
);
18002 /* The following macros are only called from draw_glyphs below.
18003 They reference the following parameters of that function directly:
18004 `w', `row', `area', and `overlap_p'
18005 as well as the following local variables:
18006 `s', `f', and `hdc' (in W32) */
18009 /* On W32, silently add local `hdc' variable to argument list of
18010 init_glyph_string. */
18011 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18012 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18014 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18015 init_glyph_string (s, char2b, w, row, area, start, hl)
18018 /* Add a glyph string for a stretch glyph to the list of strings
18019 between HEAD and TAIL. START is the index of the stretch glyph in
18020 row area AREA of glyph row ROW. END is the index of the last glyph
18021 in that glyph row area. X is the current output position assigned
18022 to the new glyph string constructed. HL overrides that face of the
18023 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18024 is the right-most x-position of the drawing area. */
18026 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18027 and below -- keep them on one line. */
18028 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18031 s = (struct glyph_string *) alloca (sizeof *s); \
18032 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18033 START = fill_stretch_glyph_string (s, row, area, START, END); \
18034 append_glyph_string (&HEAD, &TAIL, s); \
18040 /* Add a glyph string for an image glyph to the list of strings
18041 between HEAD and TAIL. START is the index of the image glyph in
18042 row area AREA of glyph row ROW. END is the index of the last glyph
18043 in that glyph row area. X is the current output position assigned
18044 to the new glyph string constructed. HL overrides that face of the
18045 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18046 is the right-most x-position of the drawing area. */
18048 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18051 s = (struct glyph_string *) alloca (sizeof *s); \
18052 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18053 fill_image_glyph_string (s); \
18054 append_glyph_string (&HEAD, &TAIL, s); \
18061 /* Add a glyph string for a sequence of character glyphs to the list
18062 of strings between HEAD and TAIL. START is the index of the first
18063 glyph in row area AREA of glyph row ROW that is part of the new
18064 glyph string. END is the index of the last glyph in that glyph row
18065 area. X is the current output position assigned to the new glyph
18066 string constructed. HL overrides that face of the glyph; e.g. it
18067 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18068 right-most x-position of the drawing area. */
18070 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18076 c = (row)->glyphs[area][START].u.ch; \
18077 face_id = (row)->glyphs[area][START].face_id; \
18079 s = (struct glyph_string *) alloca (sizeof *s); \
18080 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18081 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18082 append_glyph_string (&HEAD, &TAIL, s); \
18084 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18089 /* Add a glyph string for a composite sequence to the list of strings
18090 between HEAD and TAIL. START is the index of the first glyph in
18091 row area AREA of glyph row ROW that is part of the new glyph
18092 string. END is the index of the last glyph in that glyph row area.
18093 X is the current output position assigned to the new glyph string
18094 constructed. HL overrides that face of the glyph; e.g. it is
18095 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18096 x-position of the drawing area. */
18098 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18100 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18101 int face_id = (row)->glyphs[area][START].face_id; \
18102 struct face *base_face = FACE_FROM_ID (f, face_id); \
18103 struct composition *cmp = composition_table[cmp_id]; \
18104 int glyph_len = cmp->glyph_len; \
18106 struct face **faces; \
18107 struct glyph_string *first_s = NULL; \
18110 base_face = base_face->ascii_face; \
18111 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18112 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18113 /* At first, fill in `char2b' and `faces'. */ \
18114 for (n = 0; n < glyph_len; n++) \
18116 int c = COMPOSITION_GLYPH (cmp, n); \
18117 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18118 faces[n] = FACE_FROM_ID (f, this_face_id); \
18119 get_char_face_and_encoding (f, c, this_face_id, \
18120 char2b + n, 1, 1); \
18123 /* Make glyph_strings for each glyph sequence that is drawable by \
18124 the same face, and append them to HEAD/TAIL. */ \
18125 for (n = 0; n < cmp->glyph_len;) \
18127 s = (struct glyph_string *) alloca (sizeof *s); \
18128 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18129 append_glyph_string (&(HEAD), &(TAIL), s); \
18137 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18145 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18146 of AREA of glyph row ROW on window W between indices START and END.
18147 HL overrides the face for drawing glyph strings, e.g. it is
18148 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18149 x-positions of the drawing area.
18151 This is an ugly monster macro construct because we must use alloca
18152 to allocate glyph strings (because draw_glyphs can be called
18153 asynchronously). */
18155 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18158 HEAD = TAIL = NULL; \
18159 while (START < END) \
18161 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18162 switch (first_glyph->type) \
18165 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18169 case COMPOSITE_GLYPH: \
18170 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18174 case STRETCH_GLYPH: \
18175 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18179 case IMAGE_GLYPH: \
18180 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18188 set_glyph_string_background_width (s, START, LAST_X); \
18195 /* Draw glyphs between START and END in AREA of ROW on window W,
18196 starting at x-position X. X is relative to AREA in W. HL is a
18197 face-override with the following meaning:
18199 DRAW_NORMAL_TEXT draw normally
18200 DRAW_CURSOR draw in cursor face
18201 DRAW_MOUSE_FACE draw in mouse face.
18202 DRAW_INVERSE_VIDEO draw in mode line face
18203 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18204 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18206 If OVERLAPS_P is non-zero, draw only the foreground of characters
18207 and clip to the physical height of ROW.
18209 Value is the x-position reached, relative to AREA of W. */
18212 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18215 struct glyph_row
*row
;
18216 enum glyph_row_area area
;
18218 enum draw_glyphs_face hl
;
18221 struct glyph_string
*head
, *tail
;
18222 struct glyph_string
*s
;
18223 int last_x
, area_width
;
18226 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18229 ALLOCATE_HDC (hdc
, f
);
18231 /* Let's rather be paranoid than getting a SEGV. */
18232 end
= min (end
, row
->used
[area
]);
18233 start
= max (0, start
);
18234 start
= min (end
, start
);
18236 /* Translate X to frame coordinates. Set last_x to the right
18237 end of the drawing area. */
18238 if (row
->full_width_p
)
18240 /* X is relative to the left edge of W, without scroll bars
18242 x
+= WINDOW_LEFT_EDGE_X (w
);
18243 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18247 int area_left
= window_box_left (w
, area
);
18249 area_width
= window_box_width (w
, area
);
18250 last_x
= area_left
+ area_width
;
18253 /* Build a doubly-linked list of glyph_string structures between
18254 head and tail from what we have to draw. Note that the macro
18255 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18256 the reason we use a separate variable `i'. */
18258 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18260 x_reached
= tail
->x
+ tail
->background_width
;
18264 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18265 the row, redraw some glyphs in front or following the glyph
18266 strings built above. */
18267 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18270 struct glyph_string
*h
, *t
;
18272 /* Compute overhangs for all glyph strings. */
18273 if (rif
->compute_glyph_string_overhangs
)
18274 for (s
= head
; s
; s
= s
->next
)
18275 rif
->compute_glyph_string_overhangs (s
);
18277 /* Prepend glyph strings for glyphs in front of the first glyph
18278 string that are overwritten because of the first glyph
18279 string's left overhang. The background of all strings
18280 prepended must be drawn because the first glyph string
18282 i
= left_overwritten (head
);
18286 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18287 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18289 compute_overhangs_and_x (t
, head
->x
, 1);
18290 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18293 /* Prepend glyph strings for glyphs in front of the first glyph
18294 string that overwrite that glyph string because of their
18295 right overhang. For these strings, only the foreground must
18296 be drawn, because it draws over the glyph string at `head'.
18297 The background must not be drawn because this would overwrite
18298 right overhangs of preceding glyphs for which no glyph
18300 i
= left_overwriting (head
);
18303 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18304 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18305 for (s
= h
; s
; s
= s
->next
)
18306 s
->background_filled_p
= 1;
18307 compute_overhangs_and_x (t
, head
->x
, 1);
18308 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18311 /* Append glyphs strings for glyphs following the last glyph
18312 string tail that are overwritten by tail. The background of
18313 these strings has to be drawn because tail's foreground draws
18315 i
= right_overwritten (tail
);
18318 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18319 DRAW_NORMAL_TEXT
, x
, last_x
);
18320 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18321 append_glyph_string_lists (&head
, &tail
, h
, t
);
18324 /* Append glyph strings for glyphs following the last glyph
18325 string tail that overwrite tail. The foreground of such
18326 glyphs has to be drawn because it writes into the background
18327 of tail. The background must not be drawn because it could
18328 paint over the foreground of following glyphs. */
18329 i
= right_overwriting (tail
);
18332 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18333 DRAW_NORMAL_TEXT
, x
, last_x
);
18334 for (s
= h
; s
; s
= s
->next
)
18335 s
->background_filled_p
= 1;
18336 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18337 append_glyph_string_lists (&head
, &tail
, h
, t
);
18341 /* Draw all strings. */
18342 for (s
= head
; s
; s
= s
->next
)
18343 rif
->draw_glyph_string (s
);
18345 if (area
== TEXT_AREA
18346 && !row
->full_width_p
18347 /* When drawing overlapping rows, only the glyph strings'
18348 foreground is drawn, which doesn't erase a cursor
18352 int x0
= head
? head
->x
: x
;
18353 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18355 int text_left
= window_box_left (w
, TEXT_AREA
);
18359 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18360 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18363 /* Value is the x-position up to which drawn, relative to AREA of W.
18364 This doesn't include parts drawn because of overhangs. */
18365 if (row
->full_width_p
)
18366 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18368 x_reached
-= window_box_left (w
, area
);
18370 RELEASE_HDC (hdc
, f
);
18375 /* Expand row matrix if too narrow. Don't expand if area
18378 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18380 if (!fonts_changed_p \
18381 && (it->glyph_row->glyphs[area] \
18382 < it->glyph_row->glyphs[area + 1])) \
18384 it->w->ncols_scale_factor++; \
18385 fonts_changed_p = 1; \
18389 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18390 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18396 struct glyph
*glyph
;
18397 enum glyph_row_area area
= it
->area
;
18399 xassert (it
->glyph_row
);
18400 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18402 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18403 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18405 glyph
->charpos
= CHARPOS (it
->position
);
18406 glyph
->object
= it
->object
;
18407 glyph
->pixel_width
= it
->pixel_width
;
18408 glyph
->ascent
= it
->ascent
;
18409 glyph
->descent
= it
->descent
;
18410 glyph
->voffset
= it
->voffset
;
18411 glyph
->type
= CHAR_GLYPH
;
18412 glyph
->multibyte_p
= it
->multibyte_p
;
18413 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18414 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18415 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18416 || it
->phys_descent
> it
->descent
);
18417 glyph
->padding_p
= 0;
18418 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18419 glyph
->face_id
= it
->face_id
;
18420 glyph
->u
.ch
= it
->char_to_display
;
18421 glyph
->slice
= null_glyph_slice
;
18422 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18423 ++it
->glyph_row
->used
[area
];
18426 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18429 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18430 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18433 append_composite_glyph (it
)
18436 struct glyph
*glyph
;
18437 enum glyph_row_area area
= it
->area
;
18439 xassert (it
->glyph_row
);
18441 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18442 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18444 glyph
->charpos
= CHARPOS (it
->position
);
18445 glyph
->object
= it
->object
;
18446 glyph
->pixel_width
= it
->pixel_width
;
18447 glyph
->ascent
= it
->ascent
;
18448 glyph
->descent
= it
->descent
;
18449 glyph
->voffset
= it
->voffset
;
18450 glyph
->type
= COMPOSITE_GLYPH
;
18451 glyph
->multibyte_p
= it
->multibyte_p
;
18452 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18453 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18454 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18455 || it
->phys_descent
> it
->descent
);
18456 glyph
->padding_p
= 0;
18457 glyph
->glyph_not_available_p
= 0;
18458 glyph
->face_id
= it
->face_id
;
18459 glyph
->u
.cmp_id
= it
->cmp_id
;
18460 glyph
->slice
= null_glyph_slice
;
18461 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18462 ++it
->glyph_row
->used
[area
];
18465 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18469 /* Change IT->ascent and IT->height according to the setting of
18473 take_vertical_position_into_account (it
)
18478 if (it
->voffset
< 0)
18479 /* Increase the ascent so that we can display the text higher
18481 it
->ascent
-= it
->voffset
;
18483 /* Increase the descent so that we can display the text lower
18485 it
->descent
+= it
->voffset
;
18490 /* Produce glyphs/get display metrics for the image IT is loaded with.
18491 See the description of struct display_iterator in dispextern.h for
18492 an overview of struct display_iterator. */
18495 produce_image_glyph (it
)
18501 struct glyph_slice slice
;
18503 xassert (it
->what
== IT_IMAGE
);
18505 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18507 /* Make sure X resources of the face is loaded. */
18508 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18510 if (it
->image_id
< 0)
18512 /* Fringe bitmap. */
18513 it
->ascent
= it
->phys_ascent
= 0;
18514 it
->descent
= it
->phys_descent
= 0;
18515 it
->pixel_width
= 0;
18520 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18522 /* Make sure X resources of the image is loaded. */
18523 prepare_image_for_display (it
->f
, img
);
18525 slice
.x
= slice
.y
= 0;
18526 slice
.width
= img
->width
;
18527 slice
.height
= img
->height
;
18529 if (INTEGERP (it
->slice
.x
))
18530 slice
.x
= XINT (it
->slice
.x
);
18531 else if (FLOATP (it
->slice
.x
))
18532 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18534 if (INTEGERP (it
->slice
.y
))
18535 slice
.y
= XINT (it
->slice
.y
);
18536 else if (FLOATP (it
->slice
.y
))
18537 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18539 if (INTEGERP (it
->slice
.width
))
18540 slice
.width
= XINT (it
->slice
.width
);
18541 else if (FLOATP (it
->slice
.width
))
18542 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18544 if (INTEGERP (it
->slice
.height
))
18545 slice
.height
= XINT (it
->slice
.height
);
18546 else if (FLOATP (it
->slice
.height
))
18547 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18549 if (slice
.x
>= img
->width
)
18550 slice
.x
= img
->width
;
18551 if (slice
.y
>= img
->height
)
18552 slice
.y
= img
->height
;
18553 if (slice
.x
+ slice
.width
>= img
->width
)
18554 slice
.width
= img
->width
- slice
.x
;
18555 if (slice
.y
+ slice
.height
> img
->height
)
18556 slice
.height
= img
->height
- slice
.y
;
18558 if (slice
.width
== 0 || slice
.height
== 0)
18561 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18563 it
->descent
= slice
.height
- glyph_ascent
;
18565 it
->descent
+= img
->vmargin
;
18566 if (slice
.y
+ slice
.height
== img
->height
)
18567 it
->descent
+= img
->vmargin
;
18568 it
->phys_descent
= it
->descent
;
18570 it
->pixel_width
= slice
.width
;
18572 it
->pixel_width
+= img
->hmargin
;
18573 if (slice
.x
+ slice
.width
== img
->width
)
18574 it
->pixel_width
+= img
->hmargin
;
18576 /* It's quite possible for images to have an ascent greater than
18577 their height, so don't get confused in that case. */
18578 if (it
->descent
< 0)
18581 #if 0 /* this breaks image tiling */
18582 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18583 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18584 if (face_ascent
> it
->ascent
)
18585 it
->ascent
= it
->phys_ascent
= face_ascent
;
18590 if (face
->box
!= FACE_NO_BOX
)
18592 if (face
->box_line_width
> 0)
18595 it
->ascent
+= face
->box_line_width
;
18596 if (slice
.y
+ slice
.height
== img
->height
)
18597 it
->descent
+= face
->box_line_width
;
18600 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18601 it
->pixel_width
+= abs (face
->box_line_width
);
18602 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18603 it
->pixel_width
+= abs (face
->box_line_width
);
18606 take_vertical_position_into_account (it
);
18610 struct glyph
*glyph
;
18611 enum glyph_row_area area
= it
->area
;
18613 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18614 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18616 glyph
->charpos
= CHARPOS (it
->position
);
18617 glyph
->object
= it
->object
;
18618 glyph
->pixel_width
= it
->pixel_width
;
18619 glyph
->ascent
= glyph_ascent
;
18620 glyph
->descent
= it
->descent
;
18621 glyph
->voffset
= it
->voffset
;
18622 glyph
->type
= IMAGE_GLYPH
;
18623 glyph
->multibyte_p
= it
->multibyte_p
;
18624 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18625 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18626 glyph
->overlaps_vertically_p
= 0;
18627 glyph
->padding_p
= 0;
18628 glyph
->glyph_not_available_p
= 0;
18629 glyph
->face_id
= it
->face_id
;
18630 glyph
->u
.img_id
= img
->id
;
18631 glyph
->slice
= slice
;
18632 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18633 ++it
->glyph_row
->used
[area
];
18636 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18641 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18642 of the glyph, WIDTH and HEIGHT are the width and height of the
18643 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18646 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18648 Lisp_Object object
;
18652 struct glyph
*glyph
;
18653 enum glyph_row_area area
= it
->area
;
18655 xassert (ascent
>= 0 && ascent
<= height
);
18657 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18658 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18660 glyph
->charpos
= CHARPOS (it
->position
);
18661 glyph
->object
= object
;
18662 glyph
->pixel_width
= width
;
18663 glyph
->ascent
= ascent
;
18664 glyph
->descent
= height
- ascent
;
18665 glyph
->voffset
= it
->voffset
;
18666 glyph
->type
= STRETCH_GLYPH
;
18667 glyph
->multibyte_p
= it
->multibyte_p
;
18668 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18669 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18670 glyph
->overlaps_vertically_p
= 0;
18671 glyph
->padding_p
= 0;
18672 glyph
->glyph_not_available_p
= 0;
18673 glyph
->face_id
= it
->face_id
;
18674 glyph
->u
.stretch
.ascent
= ascent
;
18675 glyph
->u
.stretch
.height
= height
;
18676 glyph
->slice
= null_glyph_slice
;
18677 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18678 ++it
->glyph_row
->used
[area
];
18681 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18685 /* Produce a stretch glyph for iterator IT. IT->object is the value
18686 of the glyph property displayed. The value must be a list
18687 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18690 1. `:width WIDTH' specifies that the space should be WIDTH *
18691 canonical char width wide. WIDTH may be an integer or floating
18694 2. `:relative-width FACTOR' specifies that the width of the stretch
18695 should be computed from the width of the first character having the
18696 `glyph' property, and should be FACTOR times that width.
18698 3. `:align-to HPOS' specifies that the space should be wide enough
18699 to reach HPOS, a value in canonical character units.
18701 Exactly one of the above pairs must be present.
18703 4. `:height HEIGHT' specifies that the height of the stretch produced
18704 should be HEIGHT, measured in canonical character units.
18706 5. `:relative-height FACTOR' specifies that the height of the
18707 stretch should be FACTOR times the height of the characters having
18708 the glyph property.
18710 Either none or exactly one of 4 or 5 must be present.
18712 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18713 of the stretch should be used for the ascent of the stretch.
18714 ASCENT must be in the range 0 <= ASCENT <= 100. */
18717 produce_stretch_glyph (it
)
18720 /* (space :width WIDTH :height HEIGHT ...) */
18721 Lisp_Object prop
, plist
;
18722 int width
= 0, height
= 0, align_to
= -1;
18723 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18726 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18727 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18729 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18731 /* List should start with `space'. */
18732 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18733 plist
= XCDR (it
->object
);
18735 /* Compute the width of the stretch. */
18736 if ((prop
= Fsafe_plist_get (plist
, QCwidth
), !NILP (prop
))
18737 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18739 /* Absolute width `:width WIDTH' specified and valid. */
18740 zero_width_ok_p
= 1;
18743 else if (prop
= Fsafe_plist_get (plist
, QCrelative_width
),
18746 /* Relative width `:relative-width FACTOR' specified and valid.
18747 Compute the width of the characters having the `glyph'
18750 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18753 if (it
->multibyte_p
)
18755 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18756 - IT_BYTEPOS (*it
));
18757 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18760 it2
.c
= *p
, it2
.len
= 1;
18762 it2
.glyph_row
= NULL
;
18763 it2
.what
= IT_CHARACTER
;
18764 x_produce_glyphs (&it2
);
18765 width
= NUMVAL (prop
) * it2
.pixel_width
;
18767 else if ((prop
= Fsafe_plist_get (plist
, QCalign_to
), !NILP (prop
))
18768 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18770 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18771 align_to
= (align_to
< 0
18773 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18774 else if (align_to
< 0)
18775 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18776 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18777 zero_width_ok_p
= 1;
18780 /* Nothing specified -> width defaults to canonical char width. */
18781 width
= FRAME_COLUMN_WIDTH (it
->f
);
18783 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18786 /* Compute height. */
18787 if ((prop
= Fsafe_plist_get (plist
, QCheight
), !NILP (prop
))
18788 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18791 zero_height_ok_p
= 1;
18793 else if (prop
= Fsafe_plist_get (plist
, QCrelative_height
),
18795 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18797 height
= FONT_HEIGHT (font
);
18799 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18802 /* Compute percentage of height used for ascent. If
18803 `:ascent ASCENT' is present and valid, use that. Otherwise,
18804 derive the ascent from the font in use. */
18805 if (prop
= Fsafe_plist_get (plist
, QCascent
),
18806 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18807 ascent
= height
* NUMVAL (prop
) / 100.0;
18808 else if (!NILP (prop
)
18809 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18810 ascent
= min (max (0, (int)tem
), height
);
18812 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18814 if (width
> 0 && height
> 0 && it
->glyph_row
)
18816 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18817 if (!STRINGP (object
))
18818 object
= it
->w
->buffer
;
18819 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18822 it
->pixel_width
= width
;
18823 it
->ascent
= it
->phys_ascent
= ascent
;
18824 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18825 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18827 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18829 if (face
->box_line_width
> 0)
18831 it
->ascent
+= face
->box_line_width
;
18832 it
->descent
+= face
->box_line_width
;
18835 if (it
->start_of_box_run_p
)
18836 it
->pixel_width
+= abs (face
->box_line_width
);
18837 if (it
->end_of_box_run_p
)
18838 it
->pixel_width
+= abs (face
->box_line_width
);
18841 take_vertical_position_into_account (it
);
18844 /* Get line-height and line-spacing property at point.
18845 If line-height has format (HEIGHT TOTAL), return TOTAL
18846 in TOTAL_HEIGHT. */
18849 get_line_height_property (it
, prop
)
18853 Lisp_Object position
, val
;
18855 if (STRINGP (it
->object
))
18856 position
= make_number (IT_STRING_CHARPOS (*it
));
18857 else if (BUFFERP (it
->object
))
18858 position
= make_number (IT_CHARPOS (*it
));
18862 return Fget_char_property (position
, prop
, it
->object
);
18865 /* Calculate line-height and line-spacing properties.
18866 An integer value specifies explicit pixel value.
18867 A float value specifies relative value to current face height.
18868 A cons (float . face-name) specifies relative value to
18869 height of specified face font.
18871 Returns height in pixels, or nil. */
18875 calc_line_height_property (it
, val
, font
, boff
, override
)
18879 int boff
, override
;
18881 Lisp_Object face_name
= Qnil
;
18882 int ascent
, descent
, height
;
18884 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
18889 face_name
= XCAR (val
);
18891 if (!NUMBERP (val
))
18892 val
= make_number (1);
18893 if (NILP (face_name
))
18895 height
= it
->ascent
+ it
->descent
;
18900 if (NILP (face_name
))
18902 font
= FRAME_FONT (it
->f
);
18903 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18905 else if (EQ (face_name
, Qt
))
18913 struct font_info
*font_info
;
18915 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
18917 return make_number (-1);
18919 face
= FACE_FROM_ID (it
->f
, face_id
);
18922 return make_number (-1);
18924 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18925 boff
= font_info
->baseline_offset
;
18926 if (font_info
->vertical_centering
)
18927 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18930 ascent
= FONT_BASE (font
) + boff
;
18931 descent
= FONT_DESCENT (font
) - boff
;
18935 it
->override_ascent
= ascent
;
18936 it
->override_descent
= descent
;
18937 it
->override_boff
= boff
;
18940 height
= ascent
+ descent
;
18944 height
= (int)(XFLOAT_DATA (val
) * height
);
18945 else if (INTEGERP (val
))
18946 height
*= XINT (val
);
18948 return make_number (height
);
18953 Produce glyphs/get display metrics for the display element IT is
18954 loaded with. See the description of struct display_iterator in
18955 dispextern.h for an overview of struct display_iterator. */
18958 x_produce_glyphs (it
)
18961 int extra_line_spacing
= it
->extra_line_spacing
;
18963 it
->glyph_not_available_p
= 0;
18965 if (it
->what
== IT_CHARACTER
)
18969 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18971 int font_not_found_p
;
18972 struct font_info
*font_info
;
18973 int boff
; /* baseline offset */
18974 /* We may change it->multibyte_p upon unibyte<->multibyte
18975 conversion. So, save the current value now and restore it
18978 Note: It seems that we don't have to record multibyte_p in
18979 struct glyph because the character code itself tells if or
18980 not the character is multibyte. Thus, in the future, we must
18981 consider eliminating the field `multibyte_p' in the struct
18983 int saved_multibyte_p
= it
->multibyte_p
;
18985 /* Maybe translate single-byte characters to multibyte, or the
18987 it
->char_to_display
= it
->c
;
18988 if (!ASCII_BYTE_P (it
->c
))
18990 if (unibyte_display_via_language_environment
18991 && SINGLE_BYTE_CHAR_P (it
->c
)
18993 || !NILP (Vnonascii_translation_table
)))
18995 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18996 it
->multibyte_p
= 1;
18997 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18998 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19000 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19001 && !it
->multibyte_p
)
19003 it
->multibyte_p
= 1;
19004 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19005 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19009 /* Get font to use. Encode IT->char_to_display. */
19010 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19011 &char2b
, it
->multibyte_p
, 0);
19014 /* When no suitable font found, use the default font. */
19015 font_not_found_p
= font
== NULL
;
19016 if (font_not_found_p
)
19018 font
= FRAME_FONT (it
->f
);
19019 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19024 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19025 boff
= font_info
->baseline_offset
;
19026 if (font_info
->vertical_centering
)
19027 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19030 if (it
->char_to_display
>= ' '
19031 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19033 /* Either unibyte or ASCII. */
19038 pcm
= rif
->per_char_metric (font
, &char2b
,
19039 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19041 if (it
->override_ascent
>= 0)
19043 it
->ascent
= it
->override_ascent
;
19044 it
->descent
= it
->override_descent
;
19045 boff
= it
->override_boff
;
19049 it
->ascent
= FONT_BASE (font
) + boff
;
19050 it
->descent
= FONT_DESCENT (font
) - boff
;
19055 it
->phys_ascent
= pcm
->ascent
+ boff
;
19056 it
->phys_descent
= pcm
->descent
- boff
;
19057 it
->pixel_width
= pcm
->width
;
19061 it
->glyph_not_available_p
= 1;
19062 it
->phys_ascent
= it
->ascent
;
19063 it
->phys_descent
= it
->descent
;
19064 it
->pixel_width
= FONT_WIDTH (font
);
19067 if (it
->constrain_row_ascent_descent_p
)
19069 if (it
->descent
> it
->max_descent
)
19071 it
->ascent
+= it
->descent
- it
->max_descent
;
19072 it
->descent
= it
->max_descent
;
19074 if (it
->ascent
> it
->max_ascent
)
19076 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19077 it
->ascent
= it
->max_ascent
;
19079 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19080 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19081 extra_line_spacing
= 0;
19084 /* If this is a space inside a region of text with
19085 `space-width' property, change its width. */
19086 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19088 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19090 /* If face has a box, add the box thickness to the character
19091 height. If character has a box line to the left and/or
19092 right, add the box line width to the character's width. */
19093 if (face
->box
!= FACE_NO_BOX
)
19095 int thick
= face
->box_line_width
;
19099 it
->ascent
+= thick
;
19100 it
->descent
+= thick
;
19105 if (it
->start_of_box_run_p
)
19106 it
->pixel_width
+= thick
;
19107 if (it
->end_of_box_run_p
)
19108 it
->pixel_width
+= thick
;
19111 /* If face has an overline, add the height of the overline
19112 (1 pixel) and a 1 pixel margin to the character height. */
19113 if (face
->overline_p
)
19116 if (it
->constrain_row_ascent_descent_p
)
19118 if (it
->ascent
> it
->max_ascent
)
19119 it
->ascent
= it
->max_ascent
;
19120 if (it
->descent
> it
->max_descent
)
19121 it
->descent
= it
->max_descent
;
19124 take_vertical_position_into_account (it
);
19126 /* If we have to actually produce glyphs, do it. */
19131 /* Translate a space with a `space-width' property
19132 into a stretch glyph. */
19133 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19134 / FONT_HEIGHT (font
));
19135 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19136 it
->ascent
+ it
->descent
, ascent
);
19141 /* If characters with lbearing or rbearing are displayed
19142 in this line, record that fact in a flag of the
19143 glyph row. This is used to optimize X output code. */
19144 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19145 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19148 else if (it
->char_to_display
== '\n')
19150 /* A newline has no width but we need the height of the line.
19151 But if previous part of the line set a height, don't
19152 increase that height */
19154 Lisp_Object height
;
19155 Lisp_Object total_height
= Qnil
;
19157 it
->override_ascent
= -1;
19158 it
->pixel_width
= 0;
19161 height
= get_line_height_property(it
, Qline_height
);
19162 /* Split (line-height total-height) list */
19164 && CONSP (XCDR (height
))
19165 && NILP (XCDR (XCDR (height
))))
19167 total_height
= XCAR (XCDR (height
));
19168 height
= XCAR (height
);
19170 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19172 if (it
->override_ascent
>= 0)
19174 it
->ascent
= it
->override_ascent
;
19175 it
->descent
= it
->override_descent
;
19176 boff
= it
->override_boff
;
19180 it
->ascent
= FONT_BASE (font
) + boff
;
19181 it
->descent
= FONT_DESCENT (font
) - boff
;
19184 if (EQ (height
, Qt
))
19186 if (it
->descent
> it
->max_descent
)
19188 it
->ascent
+= it
->descent
- it
->max_descent
;
19189 it
->descent
= it
->max_descent
;
19191 if (it
->ascent
> it
->max_ascent
)
19193 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19194 it
->ascent
= it
->max_ascent
;
19196 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19197 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19198 it
->constrain_row_ascent_descent_p
= 1;
19199 extra_line_spacing
= 0;
19203 Lisp_Object spacing
;
19206 it
->phys_ascent
= it
->ascent
;
19207 it
->phys_descent
= it
->descent
;
19209 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19210 && face
->box
!= FACE_NO_BOX
19211 && face
->box_line_width
> 0)
19213 it
->ascent
+= face
->box_line_width
;
19214 it
->descent
+= face
->box_line_width
;
19217 && XINT (height
) > it
->ascent
+ it
->descent
)
19218 it
->ascent
= XINT (height
) - it
->descent
;
19220 if (!NILP (total_height
))
19221 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19224 spacing
= get_line_height_property(it
, Qline_spacing
);
19225 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19227 if (INTEGERP (spacing
))
19229 extra_line_spacing
= XINT (spacing
);
19230 if (!NILP (total_height
))
19231 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19235 else if (it
->char_to_display
== '\t')
19237 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19238 int x
= it
->current_x
+ it
->continuation_lines_width
;
19239 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19241 /* If the distance from the current position to the next tab
19242 stop is less than a space character width, use the
19243 tab stop after that. */
19244 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19245 next_tab_x
+= tab_width
;
19247 it
->pixel_width
= next_tab_x
- x
;
19249 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19250 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19254 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19255 it
->ascent
+ it
->descent
, it
->ascent
);
19260 /* A multi-byte character. Assume that the display width of the
19261 character is the width of the character multiplied by the
19262 width of the font. */
19264 /* If we found a font, this font should give us the right
19265 metrics. If we didn't find a font, use the frame's
19266 default font and calculate the width of the character
19267 from the charset width; this is what old redisplay code
19270 pcm
= rif
->per_char_metric (font
, &char2b
,
19271 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19273 if (font_not_found_p
|| !pcm
)
19275 int charset
= CHAR_CHARSET (it
->char_to_display
);
19277 it
->glyph_not_available_p
= 1;
19278 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19279 * CHARSET_WIDTH (charset
));
19280 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19281 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19285 it
->pixel_width
= pcm
->width
;
19286 it
->phys_ascent
= pcm
->ascent
+ boff
;
19287 it
->phys_descent
= pcm
->descent
- boff
;
19289 && (pcm
->lbearing
< 0
19290 || pcm
->rbearing
> pcm
->width
))
19291 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19294 it
->ascent
= FONT_BASE (font
) + boff
;
19295 it
->descent
= FONT_DESCENT (font
) - boff
;
19296 if (face
->box
!= FACE_NO_BOX
)
19298 int thick
= face
->box_line_width
;
19302 it
->ascent
+= thick
;
19303 it
->descent
+= thick
;
19308 if (it
->start_of_box_run_p
)
19309 it
->pixel_width
+= thick
;
19310 if (it
->end_of_box_run_p
)
19311 it
->pixel_width
+= thick
;
19314 /* If face has an overline, add the height of the overline
19315 (1 pixel) and a 1 pixel margin to the character height. */
19316 if (face
->overline_p
)
19319 take_vertical_position_into_account (it
);
19324 it
->multibyte_p
= saved_multibyte_p
;
19326 else if (it
->what
== IT_COMPOSITION
)
19328 /* Note: A composition is represented as one glyph in the
19329 glyph matrix. There are no padding glyphs. */
19332 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19334 int font_not_found_p
;
19335 struct font_info
*font_info
;
19336 int boff
; /* baseline offset */
19337 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19339 /* Maybe translate single-byte characters to multibyte. */
19340 it
->char_to_display
= it
->c
;
19341 if (unibyte_display_via_language_environment
19342 && SINGLE_BYTE_CHAR_P (it
->c
)
19345 && !NILP (Vnonascii_translation_table
))))
19347 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19350 /* Get face and font to use. Encode IT->char_to_display. */
19351 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19352 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19353 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19354 &char2b
, it
->multibyte_p
, 0);
19357 /* When no suitable font found, use the default font. */
19358 font_not_found_p
= font
== NULL
;
19359 if (font_not_found_p
)
19361 font
= FRAME_FONT (it
->f
);
19362 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19367 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19368 boff
= font_info
->baseline_offset
;
19369 if (font_info
->vertical_centering
)
19370 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19373 /* There are no padding glyphs, so there is only one glyph to
19374 produce for the composition. Important is that pixel_width,
19375 ascent and descent are the values of what is drawn by
19376 draw_glyphs (i.e. the values of the overall glyphs composed). */
19379 /* If we have not yet calculated pixel size data of glyphs of
19380 the composition for the current face font, calculate them
19381 now. Theoretically, we have to check all fonts for the
19382 glyphs, but that requires much time and memory space. So,
19383 here we check only the font of the first glyph. This leads
19384 to incorrect display very rarely, and C-l (recenter) can
19385 correct the display anyway. */
19386 if (cmp
->font
!= (void *) font
)
19388 /* Ascent and descent of the font of the first character of
19389 this composition (adjusted by baseline offset). Ascent
19390 and descent of overall glyphs should not be less than
19391 them respectively. */
19392 int font_ascent
= FONT_BASE (font
) + boff
;
19393 int font_descent
= FONT_DESCENT (font
) - boff
;
19394 /* Bounding box of the overall glyphs. */
19395 int leftmost
, rightmost
, lowest
, highest
;
19396 int i
, width
, ascent
, descent
;
19398 cmp
->font
= (void *) font
;
19400 /* Initialize the bounding box. */
19402 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19403 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19405 width
= pcm
->width
;
19406 ascent
= pcm
->ascent
;
19407 descent
= pcm
->descent
;
19411 width
= FONT_WIDTH (font
);
19412 ascent
= FONT_BASE (font
);
19413 descent
= FONT_DESCENT (font
);
19417 lowest
= - descent
+ boff
;
19418 highest
= ascent
+ boff
;
19422 && font_info
->default_ascent
19423 && CHAR_TABLE_P (Vuse_default_ascent
)
19424 && !NILP (Faref (Vuse_default_ascent
,
19425 make_number (it
->char_to_display
))))
19426 highest
= font_info
->default_ascent
+ boff
;
19428 /* Draw the first glyph at the normal position. It may be
19429 shifted to right later if some other glyphs are drawn at
19431 cmp
->offsets
[0] = 0;
19432 cmp
->offsets
[1] = boff
;
19434 /* Set cmp->offsets for the remaining glyphs. */
19435 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19437 int left
, right
, btm
, top
;
19438 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19439 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19441 face
= FACE_FROM_ID (it
->f
, face_id
);
19442 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19443 &char2b
, it
->multibyte_p
, 0);
19447 font
= FRAME_FONT (it
->f
);
19448 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19454 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19455 boff
= font_info
->baseline_offset
;
19456 if (font_info
->vertical_centering
)
19457 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19461 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19462 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19464 width
= pcm
->width
;
19465 ascent
= pcm
->ascent
;
19466 descent
= pcm
->descent
;
19470 width
= FONT_WIDTH (font
);
19475 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19477 /* Relative composition with or without
19478 alternate chars. */
19479 left
= (leftmost
+ rightmost
- width
) / 2;
19480 btm
= - descent
+ boff
;
19481 if (font_info
&& font_info
->relative_compose
19482 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19483 || NILP (Faref (Vignore_relative_composition
,
19484 make_number (ch
)))))
19487 if (- descent
>= font_info
->relative_compose
)
19488 /* One extra pixel between two glyphs. */
19490 else if (ascent
<= 0)
19491 /* One extra pixel between two glyphs. */
19492 btm
= lowest
- 1 - ascent
- descent
;
19497 /* A composition rule is specified by an integer
19498 value that encodes global and new reference
19499 points (GREF and NREF). GREF and NREF are
19500 specified by numbers as below:
19502 0---1---2 -- ascent
19506 9--10--11 -- center
19508 ---3---4---5--- baseline
19510 6---7---8 -- descent
19512 int rule
= COMPOSITION_RULE (cmp
, i
);
19513 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19515 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19516 grefx
= gref
% 3, nrefx
= nref
% 3;
19517 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19520 + grefx
* (rightmost
- leftmost
) / 2
19521 - nrefx
* width
/ 2);
19522 btm
= ((grefy
== 0 ? highest
19524 : grefy
== 2 ? lowest
19525 : (highest
+ lowest
) / 2)
19526 - (nrefy
== 0 ? ascent
+ descent
19527 : nrefy
== 1 ? descent
- boff
19529 : (ascent
+ descent
) / 2));
19532 cmp
->offsets
[i
* 2] = left
;
19533 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19535 /* Update the bounding box of the overall glyphs. */
19536 right
= left
+ width
;
19537 top
= btm
+ descent
+ ascent
;
19538 if (left
< leftmost
)
19540 if (right
> rightmost
)
19548 /* If there are glyphs whose x-offsets are negative,
19549 shift all glyphs to the right and make all x-offsets
19553 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19554 cmp
->offsets
[i
* 2] -= leftmost
;
19555 rightmost
-= leftmost
;
19558 cmp
->pixel_width
= rightmost
;
19559 cmp
->ascent
= highest
;
19560 cmp
->descent
= - lowest
;
19561 if (cmp
->ascent
< font_ascent
)
19562 cmp
->ascent
= font_ascent
;
19563 if (cmp
->descent
< font_descent
)
19564 cmp
->descent
= font_descent
;
19567 it
->pixel_width
= cmp
->pixel_width
;
19568 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19569 it
->descent
= it
->phys_descent
= cmp
->descent
;
19571 if (face
->box
!= FACE_NO_BOX
)
19573 int thick
= face
->box_line_width
;
19577 it
->ascent
+= thick
;
19578 it
->descent
+= thick
;
19583 if (it
->start_of_box_run_p
)
19584 it
->pixel_width
+= thick
;
19585 if (it
->end_of_box_run_p
)
19586 it
->pixel_width
+= thick
;
19589 /* If face has an overline, add the height of the overline
19590 (1 pixel) and a 1 pixel margin to the character height. */
19591 if (face
->overline_p
)
19594 take_vertical_position_into_account (it
);
19597 append_composite_glyph (it
);
19599 else if (it
->what
== IT_IMAGE
)
19600 produce_image_glyph (it
);
19601 else if (it
->what
== IT_STRETCH
)
19602 produce_stretch_glyph (it
);
19604 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19605 because this isn't true for images with `:ascent 100'. */
19606 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19607 if (it
->area
== TEXT_AREA
)
19608 it
->current_x
+= it
->pixel_width
;
19610 if (extra_line_spacing
> 0)
19612 it
->descent
+= extra_line_spacing
;
19613 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19614 it
->max_extra_line_spacing
= extra_line_spacing
;
19617 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19618 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19619 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19620 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19624 Output LEN glyphs starting at START at the nominal cursor position.
19625 Advance the nominal cursor over the text. The global variable
19626 updated_window contains the window being updated, updated_row is
19627 the glyph row being updated, and updated_area is the area of that
19628 row being updated. */
19631 x_write_glyphs (start
, len
)
19632 struct glyph
*start
;
19637 xassert (updated_window
&& updated_row
);
19640 /* Write glyphs. */
19642 hpos
= start
- updated_row
->glyphs
[updated_area
];
19643 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19644 updated_row
, updated_area
,
19646 DRAW_NORMAL_TEXT
, 0);
19648 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19649 if (updated_area
== TEXT_AREA
19650 && updated_window
->phys_cursor_on_p
19651 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19652 && updated_window
->phys_cursor
.hpos
>= hpos
19653 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19654 updated_window
->phys_cursor_on_p
= 0;
19658 /* Advance the output cursor. */
19659 output_cursor
.hpos
+= len
;
19660 output_cursor
.x
= x
;
19665 Insert LEN glyphs from START at the nominal cursor position. */
19668 x_insert_glyphs (start
, len
)
19669 struct glyph
*start
;
19674 int line_height
, shift_by_width
, shifted_region_width
;
19675 struct glyph_row
*row
;
19676 struct glyph
*glyph
;
19677 int frame_x
, frame_y
, hpos
;
19679 xassert (updated_window
&& updated_row
);
19681 w
= updated_window
;
19682 f
= XFRAME (WINDOW_FRAME (w
));
19684 /* Get the height of the line we are in. */
19686 line_height
= row
->height
;
19688 /* Get the width of the glyphs to insert. */
19689 shift_by_width
= 0;
19690 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19691 shift_by_width
+= glyph
->pixel_width
;
19693 /* Get the width of the region to shift right. */
19694 shifted_region_width
= (window_box_width (w
, updated_area
)
19699 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19700 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19702 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19703 line_height
, shift_by_width
);
19705 /* Write the glyphs. */
19706 hpos
= start
- row
->glyphs
[updated_area
];
19707 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19709 DRAW_NORMAL_TEXT
, 0);
19711 /* Advance the output cursor. */
19712 output_cursor
.hpos
+= len
;
19713 output_cursor
.x
+= shift_by_width
;
19719 Erase the current text line from the nominal cursor position
19720 (inclusive) to pixel column TO_X (exclusive). The idea is that
19721 everything from TO_X onward is already erased.
19723 TO_X is a pixel position relative to updated_area of
19724 updated_window. TO_X == -1 means clear to the end of this area. */
19727 x_clear_end_of_line (to_x
)
19731 struct window
*w
= updated_window
;
19732 int max_x
, min_y
, max_y
;
19733 int from_x
, from_y
, to_y
;
19735 xassert (updated_window
&& updated_row
);
19736 f
= XFRAME (w
->frame
);
19738 if (updated_row
->full_width_p
)
19739 max_x
= WINDOW_TOTAL_WIDTH (w
);
19741 max_x
= window_box_width (w
, updated_area
);
19742 max_y
= window_text_bottom_y (w
);
19744 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19745 of window. For TO_X > 0, truncate to end of drawing area. */
19751 to_x
= min (to_x
, max_x
);
19753 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19755 /* Notice if the cursor will be cleared by this operation. */
19756 if (!updated_row
->full_width_p
)
19757 notice_overwritten_cursor (w
, updated_area
,
19758 output_cursor
.x
, -1,
19760 MATRIX_ROW_BOTTOM_Y (updated_row
));
19762 from_x
= output_cursor
.x
;
19764 /* Translate to frame coordinates. */
19765 if (updated_row
->full_width_p
)
19767 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19768 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19772 int area_left
= window_box_left (w
, updated_area
);
19773 from_x
+= area_left
;
19777 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19778 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19779 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19781 /* Prevent inadvertently clearing to end of the X window. */
19782 if (to_x
> from_x
&& to_y
> from_y
)
19785 rif
->clear_frame_area (f
, from_x
, from_y
,
19786 to_x
- from_x
, to_y
- from_y
);
19791 #endif /* HAVE_WINDOW_SYSTEM */
19795 /***********************************************************************
19797 ***********************************************************************/
19799 /* Value is the internal representation of the specified cursor type
19800 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19801 of the bar cursor. */
19803 static enum text_cursor_kinds
19804 get_specified_cursor_type (arg
, width
)
19808 enum text_cursor_kinds type
;
19813 if (EQ (arg
, Qbox
))
19814 return FILLED_BOX_CURSOR
;
19816 if (EQ (arg
, Qhollow
))
19817 return HOLLOW_BOX_CURSOR
;
19819 if (EQ (arg
, Qbar
))
19826 && EQ (XCAR (arg
), Qbar
)
19827 && INTEGERP (XCDR (arg
))
19828 && XINT (XCDR (arg
)) >= 0)
19830 *width
= XINT (XCDR (arg
));
19834 if (EQ (arg
, Qhbar
))
19837 return HBAR_CURSOR
;
19841 && EQ (XCAR (arg
), Qhbar
)
19842 && INTEGERP (XCDR (arg
))
19843 && XINT (XCDR (arg
)) >= 0)
19845 *width
= XINT (XCDR (arg
));
19846 return HBAR_CURSOR
;
19849 /* Treat anything unknown as "hollow box cursor".
19850 It was bad to signal an error; people have trouble fixing
19851 .Xdefaults with Emacs, when it has something bad in it. */
19852 type
= HOLLOW_BOX_CURSOR
;
19857 /* Set the default cursor types for specified frame. */
19859 set_frame_cursor_types (f
, arg
)
19866 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19867 FRAME_CURSOR_WIDTH (f
) = width
;
19869 /* By default, set up the blink-off state depending on the on-state. */
19871 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19874 FRAME_BLINK_OFF_CURSOR (f
)
19875 = get_specified_cursor_type (XCDR (tem
), &width
);
19876 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19879 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19883 /* Return the cursor we want to be displayed in window W. Return
19884 width of bar/hbar cursor through WIDTH arg. Return with
19885 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19886 (i.e. if the `system caret' should track this cursor).
19888 In a mini-buffer window, we want the cursor only to appear if we
19889 are reading input from this window. For the selected window, we
19890 want the cursor type given by the frame parameter or buffer local
19891 setting of cursor-type. If explicitly marked off, draw no cursor.
19892 In all other cases, we want a hollow box cursor. */
19894 static enum text_cursor_kinds
19895 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19897 struct glyph
*glyph
;
19899 int *active_cursor
;
19901 struct frame
*f
= XFRAME (w
->frame
);
19902 struct buffer
*b
= XBUFFER (w
->buffer
);
19903 int cursor_type
= DEFAULT_CURSOR
;
19904 Lisp_Object alt_cursor
;
19905 int non_selected
= 0;
19907 *active_cursor
= 1;
19910 if (cursor_in_echo_area
19911 && FRAME_HAS_MINIBUF_P (f
)
19912 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19914 if (w
== XWINDOW (echo_area_window
))
19916 *width
= FRAME_CURSOR_WIDTH (f
);
19917 return FRAME_DESIRED_CURSOR (f
);
19920 *active_cursor
= 0;
19924 /* Nonselected window or nonselected frame. */
19925 else if (w
!= XWINDOW (f
->selected_window
)
19926 #ifdef HAVE_WINDOW_SYSTEM
19927 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19931 *active_cursor
= 0;
19933 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19939 /* Never display a cursor in a window in which cursor-type is nil. */
19940 if (NILP (b
->cursor_type
))
19943 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19946 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19947 return get_specified_cursor_type (alt_cursor
, width
);
19950 /* Get the normal cursor type for this window. */
19951 if (EQ (b
->cursor_type
, Qt
))
19953 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19954 *width
= FRAME_CURSOR_WIDTH (f
);
19957 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19959 /* Use normal cursor if not blinked off. */
19960 if (!w
->cursor_off_p
)
19962 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19963 if (cursor_type
== FILLED_BOX_CURSOR
)
19964 cursor_type
= HOLLOW_BOX_CURSOR
;
19966 return cursor_type
;
19969 /* Cursor is blinked off, so determine how to "toggle" it. */
19971 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19972 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19973 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19975 /* Then see if frame has specified a specific blink off cursor type. */
19976 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19978 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19979 return FRAME_BLINK_OFF_CURSOR (f
);
19983 /* Some people liked having a permanently visible blinking cursor,
19984 while others had very strong opinions against it. So it was
19985 decided to remove it. KFS 2003-09-03 */
19987 /* Finally perform built-in cursor blinking:
19988 filled box <-> hollow box
19989 wide [h]bar <-> narrow [h]bar
19990 narrow [h]bar <-> no cursor
19991 other type <-> no cursor */
19993 if (cursor_type
== FILLED_BOX_CURSOR
)
19994 return HOLLOW_BOX_CURSOR
;
19996 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19999 return cursor_type
;
20007 #ifdef HAVE_WINDOW_SYSTEM
20009 /* Notice when the text cursor of window W has been completely
20010 overwritten by a drawing operation that outputs glyphs in AREA
20011 starting at X0 and ending at X1 in the line starting at Y0 and
20012 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20013 the rest of the line after X0 has been written. Y coordinates
20014 are window-relative. */
20017 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20019 enum glyph_row_area area
;
20020 int x0
, y0
, x1
, y1
;
20022 int cx0
, cx1
, cy0
, cy1
;
20023 struct glyph_row
*row
;
20025 if (!w
->phys_cursor_on_p
)
20027 if (area
!= TEXT_AREA
)
20030 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
20031 if (!row
->displays_text_p
)
20034 if (row
->cursor_in_fringe_p
)
20036 row
->cursor_in_fringe_p
= 0;
20037 draw_fringe_bitmap (w
, row
, 0);
20038 w
->phys_cursor_on_p
= 0;
20042 cx0
= w
->phys_cursor
.x
;
20043 cx1
= cx0
+ w
->phys_cursor_width
;
20044 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20047 /* The cursor image will be completely removed from the
20048 screen if the output area intersects the cursor area in
20049 y-direction. When we draw in [y0 y1[, and some part of
20050 the cursor is at y < y0, that part must have been drawn
20051 before. When scrolling, the cursor is erased before
20052 actually scrolling, so we don't come here. When not
20053 scrolling, the rows above the old cursor row must have
20054 changed, and in this case these rows must have written
20055 over the cursor image.
20057 Likewise if part of the cursor is below y1, with the
20058 exception of the cursor being in the first blank row at
20059 the buffer and window end because update_text_area
20060 doesn't draw that row. (Except when it does, but
20061 that's handled in update_text_area.) */
20063 cy0
= w
->phys_cursor
.y
;
20064 cy1
= cy0
+ w
->phys_cursor_height
;
20065 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20068 w
->phys_cursor_on_p
= 0;
20071 #endif /* HAVE_WINDOW_SYSTEM */
20074 /************************************************************************
20076 ************************************************************************/
20078 #ifdef HAVE_WINDOW_SYSTEM
20081 Fix the display of area AREA of overlapping row ROW in window W. */
20084 x_fix_overlapping_area (w
, row
, area
)
20086 struct glyph_row
*row
;
20087 enum glyph_row_area area
;
20094 for (i
= 0; i
< row
->used
[area
];)
20096 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20098 int start
= i
, start_x
= x
;
20102 x
+= row
->glyphs
[area
][i
].pixel_width
;
20105 while (i
< row
->used
[area
]
20106 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20108 draw_glyphs (w
, start_x
, row
, area
,
20110 DRAW_NORMAL_TEXT
, 1);
20114 x
+= row
->glyphs
[area
][i
].pixel_width
;
20124 Draw the cursor glyph of window W in glyph row ROW. See the
20125 comment of draw_glyphs for the meaning of HL. */
20128 draw_phys_cursor_glyph (w
, row
, hl
)
20130 struct glyph_row
*row
;
20131 enum draw_glyphs_face hl
;
20133 /* If cursor hpos is out of bounds, don't draw garbage. This can
20134 happen in mini-buffer windows when switching between echo area
20135 glyphs and mini-buffer. */
20136 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20138 int on_p
= w
->phys_cursor_on_p
;
20140 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20141 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20143 w
->phys_cursor_on_p
= on_p
;
20145 if (hl
== DRAW_CURSOR
)
20146 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20147 /* When we erase the cursor, and ROW is overlapped by other
20148 rows, make sure that these overlapping parts of other rows
20150 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20152 if (row
> w
->current_matrix
->rows
20153 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20154 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20156 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20157 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20158 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20165 Erase the image of a cursor of window W from the screen. */
20168 erase_phys_cursor (w
)
20171 struct frame
*f
= XFRAME (w
->frame
);
20172 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20173 int hpos
= w
->phys_cursor
.hpos
;
20174 int vpos
= w
->phys_cursor
.vpos
;
20175 int mouse_face_here_p
= 0;
20176 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20177 struct glyph_row
*cursor_row
;
20178 struct glyph
*cursor_glyph
;
20179 enum draw_glyphs_face hl
;
20181 /* No cursor displayed or row invalidated => nothing to do on the
20183 if (w
->phys_cursor_type
== NO_CURSOR
)
20184 goto mark_cursor_off
;
20186 /* VPOS >= active_glyphs->nrows means that window has been resized.
20187 Don't bother to erase the cursor. */
20188 if (vpos
>= active_glyphs
->nrows
)
20189 goto mark_cursor_off
;
20191 /* If row containing cursor is marked invalid, there is nothing we
20193 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20194 if (!cursor_row
->enabled_p
)
20195 goto mark_cursor_off
;
20197 /* If line spacing is > 0, old cursor may only be partially visible in
20198 window after split-window. So adjust visible height. */
20199 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20200 window_text_bottom_y (w
) - cursor_row
->y
);
20202 /* If row is completely invisible, don't attempt to delete a cursor which
20203 isn't there. This can happen if cursor is at top of a window, and
20204 we switch to a buffer with a header line in that window. */
20205 if (cursor_row
->visible_height
<= 0)
20206 goto mark_cursor_off
;
20208 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20209 if (cursor_row
->cursor_in_fringe_p
)
20211 cursor_row
->cursor_in_fringe_p
= 0;
20212 draw_fringe_bitmap (w
, cursor_row
, 0);
20213 goto mark_cursor_off
;
20216 /* This can happen when the new row is shorter than the old one.
20217 In this case, either draw_glyphs or clear_end_of_line
20218 should have cleared the cursor. Note that we wouldn't be
20219 able to erase the cursor in this case because we don't have a
20220 cursor glyph at hand. */
20221 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20222 goto mark_cursor_off
;
20224 /* If the cursor is in the mouse face area, redisplay that when
20225 we clear the cursor. */
20226 if (! NILP (dpyinfo
->mouse_face_window
)
20227 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20228 && (vpos
> dpyinfo
->mouse_face_beg_row
20229 || (vpos
== dpyinfo
->mouse_face_beg_row
20230 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20231 && (vpos
< dpyinfo
->mouse_face_end_row
20232 || (vpos
== dpyinfo
->mouse_face_end_row
20233 && hpos
< dpyinfo
->mouse_face_end_col
))
20234 /* Don't redraw the cursor's spot in mouse face if it is at the
20235 end of a line (on a newline). The cursor appears there, but
20236 mouse highlighting does not. */
20237 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20238 mouse_face_here_p
= 1;
20240 /* Maybe clear the display under the cursor. */
20241 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20244 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20247 cursor_glyph
= get_phys_cursor_glyph (w
);
20248 if (cursor_glyph
== NULL
)
20249 goto mark_cursor_off
;
20251 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20252 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20253 width
= min (cursor_glyph
->pixel_width
,
20254 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20256 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20259 /* Erase the cursor by redrawing the character underneath it. */
20260 if (mouse_face_here_p
)
20261 hl
= DRAW_MOUSE_FACE
;
20263 hl
= DRAW_NORMAL_TEXT
;
20264 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20267 w
->phys_cursor_on_p
= 0;
20268 w
->phys_cursor_type
= NO_CURSOR
;
20273 Display or clear cursor of window W. If ON is zero, clear the
20274 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20275 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20278 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20280 int on
, hpos
, vpos
, x
, y
;
20282 struct frame
*f
= XFRAME (w
->frame
);
20283 int new_cursor_type
;
20284 int new_cursor_width
;
20286 struct glyph_row
*glyph_row
;
20287 struct glyph
*glyph
;
20289 /* This is pointless on invisible frames, and dangerous on garbaged
20290 windows and frames; in the latter case, the frame or window may
20291 be in the midst of changing its size, and x and y may be off the
20293 if (! FRAME_VISIBLE_P (f
)
20294 || FRAME_GARBAGED_P (f
)
20295 || vpos
>= w
->current_matrix
->nrows
20296 || hpos
>= w
->current_matrix
->matrix_w
)
20299 /* If cursor is off and we want it off, return quickly. */
20300 if (!on
&& !w
->phys_cursor_on_p
)
20303 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20304 /* If cursor row is not enabled, we don't really know where to
20305 display the cursor. */
20306 if (!glyph_row
->enabled_p
)
20308 w
->phys_cursor_on_p
= 0;
20313 if (!glyph_row
->exact_window_width_line_p
20314 || hpos
< glyph_row
->used
[TEXT_AREA
])
20315 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20317 xassert (interrupt_input_blocked
);
20319 /* Set new_cursor_type to the cursor we want to be displayed. */
20320 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20321 &new_cursor_width
, &active_cursor
);
20323 /* If cursor is currently being shown and we don't want it to be or
20324 it is in the wrong place, or the cursor type is not what we want,
20326 if (w
->phys_cursor_on_p
20328 || w
->phys_cursor
.x
!= x
20329 || w
->phys_cursor
.y
!= y
20330 || new_cursor_type
!= w
->phys_cursor_type
20331 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20332 && new_cursor_width
!= w
->phys_cursor_width
)))
20333 erase_phys_cursor (w
);
20335 /* Don't check phys_cursor_on_p here because that flag is only set
20336 to zero in some cases where we know that the cursor has been
20337 completely erased, to avoid the extra work of erasing the cursor
20338 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20339 still not be visible, or it has only been partly erased. */
20342 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20343 w
->phys_cursor_height
= glyph_row
->height
;
20345 /* Set phys_cursor_.* before x_draw_.* is called because some
20346 of them may need the information. */
20347 w
->phys_cursor
.x
= x
;
20348 w
->phys_cursor
.y
= glyph_row
->y
;
20349 w
->phys_cursor
.hpos
= hpos
;
20350 w
->phys_cursor
.vpos
= vpos
;
20353 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20354 new_cursor_type
, new_cursor_width
,
20355 on
, active_cursor
);
20359 /* Switch the display of W's cursor on or off, according to the value
20363 update_window_cursor (w
, on
)
20367 /* Don't update cursor in windows whose frame is in the process
20368 of being deleted. */
20369 if (w
->current_matrix
)
20372 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20373 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20379 /* Call update_window_cursor with parameter ON_P on all leaf windows
20380 in the window tree rooted at W. */
20383 update_cursor_in_window_tree (w
, on_p
)
20389 if (!NILP (w
->hchild
))
20390 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20391 else if (!NILP (w
->vchild
))
20392 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20394 update_window_cursor (w
, on_p
);
20396 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20402 Display the cursor on window W, or clear it, according to ON_P.
20403 Don't change the cursor's position. */
20406 x_update_cursor (f
, on_p
)
20410 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20415 Clear the cursor of window W to background color, and mark the
20416 cursor as not shown. This is used when the text where the cursor
20417 is is about to be rewritten. */
20423 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20424 update_window_cursor (w
, 0);
20429 Display the active region described by mouse_face_* according to DRAW. */
20432 show_mouse_face (dpyinfo
, draw
)
20433 Display_Info
*dpyinfo
;
20434 enum draw_glyphs_face draw
;
20436 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20437 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20439 if (/* If window is in the process of being destroyed, don't bother
20441 w
->current_matrix
!= NULL
20442 /* Don't update mouse highlight if hidden */
20443 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20444 /* Recognize when we are called to operate on rows that don't exist
20445 anymore. This can happen when a window is split. */
20446 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20448 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20449 struct glyph_row
*row
, *first
, *last
;
20451 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20452 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20454 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20456 int start_hpos
, end_hpos
, start_x
;
20458 /* For all but the first row, the highlight starts at column 0. */
20461 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20462 start_x
= dpyinfo
->mouse_face_beg_x
;
20471 end_hpos
= dpyinfo
->mouse_face_end_col
;
20473 end_hpos
= row
->used
[TEXT_AREA
];
20475 if (end_hpos
> start_hpos
)
20477 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20478 start_hpos
, end_hpos
,
20482 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20486 /* When we've written over the cursor, arrange for it to
20487 be displayed again. */
20488 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20491 display_and_set_cursor (w
, 1,
20492 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20493 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20498 /* Change the mouse cursor. */
20499 if (draw
== DRAW_NORMAL_TEXT
)
20500 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20501 else if (draw
== DRAW_MOUSE_FACE
)
20502 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20504 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20508 Clear out the mouse-highlighted active region.
20509 Redraw it un-highlighted first. Value is non-zero if mouse
20510 face was actually drawn unhighlighted. */
20513 clear_mouse_face (dpyinfo
)
20514 Display_Info
*dpyinfo
;
20518 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20520 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20524 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20525 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20526 dpyinfo
->mouse_face_window
= Qnil
;
20527 dpyinfo
->mouse_face_overlay
= Qnil
;
20533 Non-zero if physical cursor of window W is within mouse face. */
20536 cursor_in_mouse_face_p (w
)
20539 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20540 int in_mouse_face
= 0;
20542 if (WINDOWP (dpyinfo
->mouse_face_window
)
20543 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20545 int hpos
= w
->phys_cursor
.hpos
;
20546 int vpos
= w
->phys_cursor
.vpos
;
20548 if (vpos
>= dpyinfo
->mouse_face_beg_row
20549 && vpos
<= dpyinfo
->mouse_face_end_row
20550 && (vpos
> dpyinfo
->mouse_face_beg_row
20551 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20552 && (vpos
< dpyinfo
->mouse_face_end_row
20553 || hpos
< dpyinfo
->mouse_face_end_col
20554 || dpyinfo
->mouse_face_past_end
))
20558 return in_mouse_face
;
20564 /* Find the glyph matrix position of buffer position CHARPOS in window
20565 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20566 current glyphs must be up to date. If CHARPOS is above window
20567 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20568 of last line in W. In the row containing CHARPOS, stop before glyphs
20569 having STOP as object. */
20571 #if 1 /* This is a version of fast_find_position that's more correct
20572 in the presence of hscrolling, for example. I didn't install
20573 it right away because the problem fixed is minor, it failed
20574 in 20.x as well, and I think it's too risky to install
20575 so near the release of 21.1. 2001-09-25 gerd. */
20578 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20581 int *hpos
, *vpos
, *x
, *y
;
20584 struct glyph_row
*row
, *first
;
20585 struct glyph
*glyph
, *end
;
20588 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20589 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20594 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20598 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20601 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20607 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20609 glyph
= row
->glyphs
[TEXT_AREA
];
20610 end
= glyph
+ row
->used
[TEXT_AREA
];
20612 /* Skip over glyphs not having an object at the start of the row.
20613 These are special glyphs like truncation marks on terminal
20615 if (row
->displays_text_p
)
20617 && INTEGERP (glyph
->object
)
20618 && !EQ (stop
, glyph
->object
)
20619 && glyph
->charpos
< 0)
20621 *x
+= glyph
->pixel_width
;
20626 && !INTEGERP (glyph
->object
)
20627 && !EQ (stop
, glyph
->object
)
20628 && (!BUFFERP (glyph
->object
)
20629 || glyph
->charpos
< charpos
))
20631 *x
+= glyph
->pixel_width
;
20635 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20642 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20645 int *hpos
, *vpos
, *x
, *y
;
20650 int maybe_next_line_p
= 0;
20651 int line_start_position
;
20652 int yb
= window_text_bottom_y (w
);
20653 struct glyph_row
*row
, *best_row
;
20654 int row_vpos
, best_row_vpos
;
20657 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20658 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20660 while (row
->y
< yb
)
20662 if (row
->used
[TEXT_AREA
])
20663 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20665 line_start_position
= 0;
20667 if (line_start_position
> pos
)
20669 /* If the position sought is the end of the buffer,
20670 don't include the blank lines at the bottom of the window. */
20671 else if (line_start_position
== pos
20672 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20674 maybe_next_line_p
= 1;
20677 else if (line_start_position
> 0)
20680 best_row_vpos
= row_vpos
;
20683 if (row
->y
+ row
->height
>= yb
)
20690 /* Find the right column within BEST_ROW. */
20692 current_x
= best_row
->x
;
20693 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20695 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20696 int charpos
= glyph
->charpos
;
20698 if (BUFFERP (glyph
->object
))
20700 if (charpos
== pos
)
20703 *vpos
= best_row_vpos
;
20708 else if (charpos
> pos
)
20711 else if (EQ (glyph
->object
, stop
))
20716 current_x
+= glyph
->pixel_width
;
20719 /* If we're looking for the end of the buffer,
20720 and we didn't find it in the line we scanned,
20721 use the start of the following line. */
20722 if (maybe_next_line_p
)
20727 current_x
= best_row
->x
;
20730 *vpos
= best_row_vpos
;
20731 *hpos
= lastcol
+ 1;
20740 /* Find the position of the glyph for position POS in OBJECT in
20741 window W's current matrix, and return in *X, *Y the pixel
20742 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20744 RIGHT_P non-zero means return the position of the right edge of the
20745 glyph, RIGHT_P zero means return the left edge position.
20747 If no glyph for POS exists in the matrix, return the position of
20748 the glyph with the next smaller position that is in the matrix, if
20749 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20750 exists in the matrix, return the position of the glyph with the
20751 next larger position in OBJECT.
20753 Value is non-zero if a glyph was found. */
20756 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20759 Lisp_Object object
;
20760 int *hpos
, *vpos
, *x
, *y
;
20763 int yb
= window_text_bottom_y (w
);
20764 struct glyph_row
*r
;
20765 struct glyph
*best_glyph
= NULL
;
20766 struct glyph_row
*best_row
= NULL
;
20769 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20770 r
->enabled_p
&& r
->y
< yb
;
20773 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20774 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20777 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20778 if (EQ (g
->object
, object
))
20780 if (g
->charpos
== pos
)
20787 else if (best_glyph
== NULL
20788 || ((abs (g
->charpos
- pos
)
20789 < abs (best_glyph
->charpos
- pos
))
20792 : g
->charpos
> pos
)))
20806 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20810 *x
+= best_glyph
->pixel_width
;
20815 *vpos
= best_row
- w
->current_matrix
->rows
;
20818 return best_glyph
!= NULL
;
20822 /* See if position X, Y is within a hot-spot of an image. */
20825 on_hot_spot_p (hot_spot
, x
, y
)
20826 Lisp_Object hot_spot
;
20829 if (!CONSP (hot_spot
))
20832 if (EQ (XCAR (hot_spot
), Qrect
))
20834 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20835 Lisp_Object rect
= XCDR (hot_spot
);
20839 if (!CONSP (XCAR (rect
)))
20841 if (!CONSP (XCDR (rect
)))
20843 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20845 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20847 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20849 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20853 else if (EQ (XCAR (hot_spot
), Qcircle
))
20855 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20856 Lisp_Object circ
= XCDR (hot_spot
);
20857 Lisp_Object lr
, lx0
, ly0
;
20859 && CONSP (XCAR (circ
))
20860 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20861 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20862 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20864 double r
= XFLOATINT (lr
);
20865 double dx
= XINT (lx0
) - x
;
20866 double dy
= XINT (ly0
) - y
;
20867 return (dx
* dx
+ dy
* dy
<= r
* r
);
20870 else if (EQ (XCAR (hot_spot
), Qpoly
))
20872 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20873 if (VECTORP (XCDR (hot_spot
)))
20875 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20876 Lisp_Object
*poly
= v
->contents
;
20880 Lisp_Object lx
, ly
;
20883 /* Need an even number of coordinates, and at least 3 edges. */
20884 if (n
< 6 || n
& 1)
20887 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20888 If count is odd, we are inside polygon. Pixels on edges
20889 may or may not be included depending on actual geometry of the
20891 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20892 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20894 x0
= XINT (lx
), y0
= XINT (ly
);
20895 for (i
= 0; i
< n
; i
+= 2)
20897 int x1
= x0
, y1
= y0
;
20898 if ((lx
= poly
[i
], !INTEGERP (lx
))
20899 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20901 x0
= XINT (lx
), y0
= XINT (ly
);
20903 /* Does this segment cross the X line? */
20911 if (y
> y0
&& y
> y1
)
20913 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20919 /* If we don't understand the format, pretend we're not in the hot-spot. */
20924 find_hot_spot (map
, x
, y
)
20928 while (CONSP (map
))
20930 if (CONSP (XCAR (map
))
20931 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20939 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20941 doc
: /* Lookup in image map MAP coordinates X and Y.
20942 An image map is an alist where each element has the format (AREA ID PLIST).
20943 An AREA is specified as either a rectangle, a circle, or a polygon:
20944 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20945 pixel coordinates of the upper left and bottom right corners.
20946 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20947 and the radius of the circle; r may be a float or integer.
20948 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20949 vector describes one corner in the polygon.
20950 Returns the alist element for the first matching AREA in MAP. */)
20961 return find_hot_spot (map
, XINT (x
), XINT (y
));
20965 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20967 define_frame_cursor1 (f
, cursor
, pointer
)
20970 Lisp_Object pointer
;
20972 /* Do not change cursor shape while dragging mouse. */
20973 if (!NILP (do_mouse_tracking
))
20976 if (!NILP (pointer
))
20978 if (EQ (pointer
, Qarrow
))
20979 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20980 else if (EQ (pointer
, Qhand
))
20981 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20982 else if (EQ (pointer
, Qtext
))
20983 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20984 else if (EQ (pointer
, intern ("hdrag")))
20985 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20986 #ifdef HAVE_X_WINDOWS
20987 else if (EQ (pointer
, intern ("vdrag")))
20988 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20990 else if (EQ (pointer
, intern ("hourglass")))
20991 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20992 else if (EQ (pointer
, Qmodeline
))
20993 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20995 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20998 if (cursor
!= No_Cursor
)
20999 rif
->define_frame_cursor (f
, cursor
);
21002 /* Take proper action when mouse has moved to the mode or header line
21003 or marginal area AREA of window W, x-position X and y-position Y.
21004 X is relative to the start of the text display area of W, so the
21005 width of bitmap areas and scroll bars must be subtracted to get a
21006 position relative to the start of the mode line. */
21009 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
21012 enum window_part area
;
21014 struct frame
*f
= XFRAME (w
->frame
);
21015 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21016 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21017 Lisp_Object pointer
= Qnil
;
21018 int charpos
, dx
, dy
, width
, height
;
21019 Lisp_Object string
, object
= Qnil
;
21020 Lisp_Object pos
, help
;
21022 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21023 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21024 &object
, &dx
, &dy
, &width
, &height
);
21027 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21028 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21029 &object
, &dx
, &dy
, &width
, &height
);
21034 if (IMAGEP (object
))
21036 Lisp_Object image_map
, hotspot
;
21037 if ((image_map
= Fsafe_plist_get (XCDR (object
), QCmap
),
21039 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21041 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21043 Lisp_Object area_id
, plist
;
21045 area_id
= XCAR (hotspot
);
21046 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21047 If so, we could look for mouse-enter, mouse-leave
21048 properties in PLIST (and do something...). */
21049 hotspot
= XCDR (hotspot
);
21050 if (CONSP (hotspot
)
21051 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21053 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21054 if (NILP (pointer
))
21056 help
= Fsafe_plist_get (plist
, Qhelp_echo
);
21059 help_echo_string
= help
;
21060 /* Is this correct? ++kfs */
21061 XSETWINDOW (help_echo_window
, w
);
21062 help_echo_object
= w
->buffer
;
21063 help_echo_pos
= charpos
;
21066 if (NILP (pointer
))
21067 pointer
= Fsafe_plist_get (XCDR (object
), QCpointer
);
21071 if (STRINGP (string
))
21073 pos
= make_number (charpos
);
21074 /* If we're on a string with `help-echo' text property, arrange
21075 for the help to be displayed. This is done by setting the
21076 global variable help_echo_string to the help string. */
21079 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21082 help_echo_string
= help
;
21083 XSETWINDOW (help_echo_window
, w
);
21084 help_echo_object
= string
;
21085 help_echo_pos
= charpos
;
21089 if (NILP (pointer
))
21090 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21092 /* Change the mouse pointer according to what is under X/Y. */
21093 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21096 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21097 if (!KEYMAPP (map
))
21098 map
= Fget_text_property (pos
, Qkeymap
, string
);
21099 if (!KEYMAPP (map
))
21100 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21104 define_frame_cursor1 (f
, cursor
, pointer
);
21109 Take proper action when the mouse has moved to position X, Y on
21110 frame F as regards highlighting characters that have mouse-face
21111 properties. Also de-highlighting chars where the mouse was before.
21112 X and Y can be negative or out of range. */
21115 note_mouse_highlight (f
, x
, y
)
21119 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21120 enum window_part part
;
21121 Lisp_Object window
;
21123 Cursor cursor
= No_Cursor
;
21124 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21127 /* When a menu is active, don't highlight because this looks odd. */
21128 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21129 if (popup_activated ())
21133 if (NILP (Vmouse_highlight
)
21134 || !f
->glyphs_initialized_p
)
21137 dpyinfo
->mouse_face_mouse_x
= x
;
21138 dpyinfo
->mouse_face_mouse_y
= y
;
21139 dpyinfo
->mouse_face_mouse_frame
= f
;
21141 if (dpyinfo
->mouse_face_defer
)
21144 if (gc_in_progress
)
21146 dpyinfo
->mouse_face_deferred_gc
= 1;
21150 /* Which window is that in? */
21151 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21153 /* If we were displaying active text in another window, clear that.
21154 Also clear if we move out of text area in same window. */
21155 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21156 || (part
!= ON_TEXT
&& !NILP (dpyinfo
->mouse_face_window
)))
21157 clear_mouse_face (dpyinfo
);
21159 /* Not on a window -> return. */
21160 if (!WINDOWP (window
))
21163 /* Reset help_echo_string. It will get recomputed below. */
21164 help_echo_string
= Qnil
;
21166 /* Convert to window-relative pixel coordinates. */
21167 w
= XWINDOW (window
);
21168 frame_to_window_pixel_xy (w
, &x
, &y
);
21170 /* Handle tool-bar window differently since it doesn't display a
21172 if (EQ (window
, f
->tool_bar_window
))
21174 note_tool_bar_highlight (f
, x
, y
);
21178 /* Mouse is on the mode, header line or margin? */
21179 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21180 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21182 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
21186 if (part
== ON_VERTICAL_BORDER
)
21187 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21188 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21189 || part
== ON_SCROLL_BAR
)
21190 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21192 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21194 /* Are we in a window whose display is up to date?
21195 And verify the buffer's text has not changed. */
21196 b
= XBUFFER (w
->buffer
);
21197 if (part
== ON_TEXT
21198 && EQ (w
->window_end_valid
, w
->buffer
)
21199 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21200 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21202 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21203 struct glyph
*glyph
;
21204 Lisp_Object object
;
21205 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21206 Lisp_Object
*overlay_vec
= NULL
;
21208 struct buffer
*obuf
;
21209 int obegv
, ozv
, same_region
;
21211 /* Find the glyph under X/Y. */
21212 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21214 /* Look for :pointer property on image. */
21215 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21217 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21218 if (img
!= NULL
&& IMAGEP (img
->spec
))
21220 Lisp_Object image_map
, hotspot
;
21221 if ((image_map
= Fsafe_plist_get (XCDR (img
->spec
), QCmap
),
21223 && (hotspot
= find_hot_spot (image_map
,
21224 glyph
->slice
.x
+ dx
,
21225 glyph
->slice
.y
+ dy
),
21227 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21229 Lisp_Object area_id
, plist
;
21231 area_id
= XCAR (hotspot
);
21232 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21233 If so, we could look for mouse-enter, mouse-leave
21234 properties in PLIST (and do something...). */
21235 hotspot
= XCDR (hotspot
);
21236 if (CONSP (hotspot
)
21237 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21239 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21240 if (NILP (pointer
))
21242 help_echo_string
= Fsafe_plist_get (plist
, Qhelp_echo
);
21243 if (!NILP (help_echo_string
))
21245 help_echo_window
= window
;
21246 help_echo_object
= glyph
->object
;
21247 help_echo_pos
= glyph
->charpos
;
21251 if (NILP (pointer
))
21252 pointer
= Fsafe_plist_get (XCDR (img
->spec
), QCpointer
);
21256 /* Clear mouse face if X/Y not over text. */
21258 || area
!= TEXT_AREA
21259 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21261 if (clear_mouse_face (dpyinfo
))
21262 cursor
= No_Cursor
;
21263 if (NILP (pointer
))
21265 if (area
!= TEXT_AREA
)
21266 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21268 pointer
= Vvoid_text_area_pointer
;
21273 pos
= glyph
->charpos
;
21274 object
= glyph
->object
;
21275 if (!STRINGP (object
) && !BUFFERP (object
))
21278 /* If we get an out-of-range value, return now; avoid an error. */
21279 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21282 /* Make the window's buffer temporarily current for
21283 overlays_at and compute_char_face. */
21284 obuf
= current_buffer
;
21285 current_buffer
= b
;
21291 /* Is this char mouse-active or does it have help-echo? */
21292 position
= make_number (pos
);
21294 if (BUFFERP (object
))
21296 /* Put all the overlays we want in a vector in overlay_vec. */
21297 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21298 /* Sort overlays into increasing priority order. */
21299 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21304 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21305 && vpos
>= dpyinfo
->mouse_face_beg_row
21306 && vpos
<= dpyinfo
->mouse_face_end_row
21307 && (vpos
> dpyinfo
->mouse_face_beg_row
21308 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21309 && (vpos
< dpyinfo
->mouse_face_end_row
21310 || hpos
< dpyinfo
->mouse_face_end_col
21311 || dpyinfo
->mouse_face_past_end
));
21314 cursor
= No_Cursor
;
21316 /* Check mouse-face highlighting. */
21318 /* If there exists an overlay with mouse-face overlapping
21319 the one we are currently highlighting, we have to
21320 check if we enter the overlapping overlay, and then
21321 highlight only that. */
21322 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21323 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21325 /* Find the highest priority overlay that has a mouse-face
21328 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21330 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21331 if (!NILP (mouse_face
))
21332 overlay
= overlay_vec
[i
];
21335 /* If we're actually highlighting the same overlay as
21336 before, there's no need to do that again. */
21337 if (!NILP (overlay
)
21338 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21339 goto check_help_echo
;
21341 dpyinfo
->mouse_face_overlay
= overlay
;
21343 /* Clear the display of the old active region, if any. */
21344 if (clear_mouse_face (dpyinfo
))
21345 cursor
= No_Cursor
;
21347 /* If no overlay applies, get a text property. */
21348 if (NILP (overlay
))
21349 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21351 /* Handle the overlay case. */
21352 if (!NILP (overlay
))
21354 /* Find the range of text around this char that
21355 should be active. */
21356 Lisp_Object before
, after
;
21359 before
= Foverlay_start (overlay
);
21360 after
= Foverlay_end (overlay
);
21361 /* Record this as the current active region. */
21362 fast_find_position (w
, XFASTINT (before
),
21363 &dpyinfo
->mouse_face_beg_col
,
21364 &dpyinfo
->mouse_face_beg_row
,
21365 &dpyinfo
->mouse_face_beg_x
,
21366 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21368 dpyinfo
->mouse_face_past_end
21369 = !fast_find_position (w
, XFASTINT (after
),
21370 &dpyinfo
->mouse_face_end_col
,
21371 &dpyinfo
->mouse_face_end_row
,
21372 &dpyinfo
->mouse_face_end_x
,
21373 &dpyinfo
->mouse_face_end_y
, Qnil
);
21374 dpyinfo
->mouse_face_window
= window
;
21376 dpyinfo
->mouse_face_face_id
21377 = face_at_buffer_position (w
, pos
, 0, 0,
21379 !dpyinfo
->mouse_face_hidden
);
21381 /* Display it as active. */
21382 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21383 cursor
= No_Cursor
;
21385 /* Handle the text property case. */
21386 else if (!NILP (mouse_face
) && BUFFERP (object
))
21388 /* Find the range of text around this char that
21389 should be active. */
21390 Lisp_Object before
, after
, beginning
, end
;
21393 beginning
= Fmarker_position (w
->start
);
21394 end
= make_number (BUF_Z (XBUFFER (object
))
21395 - XFASTINT (w
->window_end_pos
));
21397 = Fprevious_single_property_change (make_number (pos
+ 1),
21399 object
, beginning
);
21401 = Fnext_single_property_change (position
, Qmouse_face
,
21404 /* Record this as the current active region. */
21405 fast_find_position (w
, XFASTINT (before
),
21406 &dpyinfo
->mouse_face_beg_col
,
21407 &dpyinfo
->mouse_face_beg_row
,
21408 &dpyinfo
->mouse_face_beg_x
,
21409 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21410 dpyinfo
->mouse_face_past_end
21411 = !fast_find_position (w
, XFASTINT (after
),
21412 &dpyinfo
->mouse_face_end_col
,
21413 &dpyinfo
->mouse_face_end_row
,
21414 &dpyinfo
->mouse_face_end_x
,
21415 &dpyinfo
->mouse_face_end_y
, Qnil
);
21416 dpyinfo
->mouse_face_window
= window
;
21418 if (BUFFERP (object
))
21419 dpyinfo
->mouse_face_face_id
21420 = face_at_buffer_position (w
, pos
, 0, 0,
21422 !dpyinfo
->mouse_face_hidden
);
21424 /* Display it as active. */
21425 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21426 cursor
= No_Cursor
;
21428 else if (!NILP (mouse_face
) && STRINGP (object
))
21433 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21436 e
= Fnext_single_property_change (position
, Qmouse_face
,
21439 b
= make_number (0);
21441 e
= make_number (SCHARS (object
) - 1);
21442 fast_find_string_pos (w
, XINT (b
), object
,
21443 &dpyinfo
->mouse_face_beg_col
,
21444 &dpyinfo
->mouse_face_beg_row
,
21445 &dpyinfo
->mouse_face_beg_x
,
21446 &dpyinfo
->mouse_face_beg_y
, 0);
21447 fast_find_string_pos (w
, XINT (e
), object
,
21448 &dpyinfo
->mouse_face_end_col
,
21449 &dpyinfo
->mouse_face_end_row
,
21450 &dpyinfo
->mouse_face_end_x
,
21451 &dpyinfo
->mouse_face_end_y
, 1);
21452 dpyinfo
->mouse_face_past_end
= 0;
21453 dpyinfo
->mouse_face_window
= window
;
21454 dpyinfo
->mouse_face_face_id
21455 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21456 glyph
->face_id
, 1);
21457 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21458 cursor
= No_Cursor
;
21460 else if (STRINGP (object
) && NILP (mouse_face
))
21462 /* A string which doesn't have mouse-face, but
21463 the text ``under'' it might have. */
21464 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21465 int start
= MATRIX_ROW_START_CHARPOS (r
);
21467 pos
= string_buffer_position (w
, object
, start
);
21469 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21473 if (!NILP (mouse_face
) && !NILP (overlay
))
21475 Lisp_Object before
= Foverlay_start (overlay
);
21476 Lisp_Object after
= Foverlay_end (overlay
);
21479 /* Note that we might not be able to find position
21480 BEFORE in the glyph matrix if the overlay is
21481 entirely covered by a `display' property. In
21482 this case, we overshoot. So let's stop in
21483 the glyph matrix before glyphs for OBJECT. */
21484 fast_find_position (w
, XFASTINT (before
),
21485 &dpyinfo
->mouse_face_beg_col
,
21486 &dpyinfo
->mouse_face_beg_row
,
21487 &dpyinfo
->mouse_face_beg_x
,
21488 &dpyinfo
->mouse_face_beg_y
,
21491 dpyinfo
->mouse_face_past_end
21492 = !fast_find_position (w
, XFASTINT (after
),
21493 &dpyinfo
->mouse_face_end_col
,
21494 &dpyinfo
->mouse_face_end_row
,
21495 &dpyinfo
->mouse_face_end_x
,
21496 &dpyinfo
->mouse_face_end_y
,
21498 dpyinfo
->mouse_face_window
= window
;
21499 dpyinfo
->mouse_face_face_id
21500 = face_at_buffer_position (w
, pos
, 0, 0,
21502 !dpyinfo
->mouse_face_hidden
);
21504 /* Display it as active. */
21505 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21506 cursor
= No_Cursor
;
21513 /* Look for a `help-echo' property. */
21514 if (NILP (help_echo_string
)) {
21515 Lisp_Object help
, overlay
;
21517 /* Check overlays first. */
21518 help
= overlay
= Qnil
;
21519 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21521 overlay
= overlay_vec
[i
];
21522 help
= Foverlay_get (overlay
, Qhelp_echo
);
21527 help_echo_string
= help
;
21528 help_echo_window
= window
;
21529 help_echo_object
= overlay
;
21530 help_echo_pos
= pos
;
21534 Lisp_Object object
= glyph
->object
;
21535 int charpos
= glyph
->charpos
;
21537 /* Try text properties. */
21538 if (STRINGP (object
)
21540 && charpos
< SCHARS (object
))
21542 help
= Fget_text_property (make_number (charpos
),
21543 Qhelp_echo
, object
);
21546 /* If the string itself doesn't specify a help-echo,
21547 see if the buffer text ``under'' it does. */
21548 struct glyph_row
*r
21549 = MATRIX_ROW (w
->current_matrix
, vpos
);
21550 int start
= MATRIX_ROW_START_CHARPOS (r
);
21551 int pos
= string_buffer_position (w
, object
, start
);
21554 help
= Fget_char_property (make_number (pos
),
21555 Qhelp_echo
, w
->buffer
);
21559 object
= w
->buffer
;
21564 else if (BUFFERP (object
)
21567 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21572 help_echo_string
= help
;
21573 help_echo_window
= window
;
21574 help_echo_object
= object
;
21575 help_echo_pos
= charpos
;
21580 /* Look for a `pointer' property. */
21581 if (NILP (pointer
))
21583 /* Check overlays first. */
21584 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21585 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21587 if (NILP (pointer
))
21589 Lisp_Object object
= glyph
->object
;
21590 int charpos
= glyph
->charpos
;
21592 /* Try text properties. */
21593 if (STRINGP (object
)
21595 && charpos
< SCHARS (object
))
21597 pointer
= Fget_text_property (make_number (charpos
),
21599 if (NILP (pointer
))
21601 /* If the string itself doesn't specify a pointer,
21602 see if the buffer text ``under'' it does. */
21603 struct glyph_row
*r
21604 = MATRIX_ROW (w
->current_matrix
, vpos
);
21605 int start
= MATRIX_ROW_START_CHARPOS (r
);
21606 int pos
= string_buffer_position (w
, object
, start
);
21608 pointer
= Fget_char_property (make_number (pos
),
21609 Qpointer
, w
->buffer
);
21612 else if (BUFFERP (object
)
21615 pointer
= Fget_text_property (make_number (charpos
),
21622 current_buffer
= obuf
;
21627 define_frame_cursor1 (f
, cursor
, pointer
);
21632 Clear any mouse-face on window W. This function is part of the
21633 redisplay interface, and is called from try_window_id and similar
21634 functions to ensure the mouse-highlight is off. */
21637 x_clear_window_mouse_face (w
)
21640 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21641 Lisp_Object window
;
21644 XSETWINDOW (window
, w
);
21645 if (EQ (window
, dpyinfo
->mouse_face_window
))
21646 clear_mouse_face (dpyinfo
);
21652 Just discard the mouse face information for frame F, if any.
21653 This is used when the size of F is changed. */
21656 cancel_mouse_face (f
)
21659 Lisp_Object window
;
21660 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21662 window
= dpyinfo
->mouse_face_window
;
21663 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21665 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21666 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21667 dpyinfo
->mouse_face_window
= Qnil
;
21672 #endif /* HAVE_WINDOW_SYSTEM */
21675 /***********************************************************************
21677 ***********************************************************************/
21679 #ifdef HAVE_WINDOW_SYSTEM
21681 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21682 which intersects rectangle R. R is in window-relative coordinates. */
21685 expose_area (w
, row
, r
, area
)
21687 struct glyph_row
*row
;
21689 enum glyph_row_area area
;
21691 struct glyph
*first
= row
->glyphs
[area
];
21692 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21693 struct glyph
*last
;
21694 int first_x
, start_x
, x
;
21696 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21697 /* If row extends face to end of line write the whole line. */
21698 draw_glyphs (w
, 0, row
, area
,
21699 0, row
->used
[area
],
21700 DRAW_NORMAL_TEXT
, 0);
21703 /* Set START_X to the window-relative start position for drawing glyphs of
21704 AREA. The first glyph of the text area can be partially visible.
21705 The first glyphs of other areas cannot. */
21706 start_x
= window_box_left_offset (w
, area
);
21708 if (area
== TEXT_AREA
)
21711 /* Find the first glyph that must be redrawn. */
21713 && x
+ first
->pixel_width
< r
->x
)
21715 x
+= first
->pixel_width
;
21719 /* Find the last one. */
21723 && x
< r
->x
+ r
->width
)
21725 x
+= last
->pixel_width
;
21731 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21732 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21733 DRAW_NORMAL_TEXT
, 0);
21738 /* Redraw the parts of the glyph row ROW on window W intersecting
21739 rectangle R. R is in window-relative coordinates. Value is
21740 non-zero if mouse-face was overwritten. */
21743 expose_line (w
, row
, r
)
21745 struct glyph_row
*row
;
21748 xassert (row
->enabled_p
);
21750 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21751 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21752 0, row
->used
[TEXT_AREA
],
21753 DRAW_NORMAL_TEXT
, 0);
21756 if (row
->used
[LEFT_MARGIN_AREA
])
21757 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21758 if (row
->used
[TEXT_AREA
])
21759 expose_area (w
, row
, r
, TEXT_AREA
);
21760 if (row
->used
[RIGHT_MARGIN_AREA
])
21761 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21762 draw_row_fringe_bitmaps (w
, row
);
21765 return row
->mouse_face_p
;
21769 /* Redraw those parts of glyphs rows during expose event handling that
21770 overlap other rows. Redrawing of an exposed line writes over parts
21771 of lines overlapping that exposed line; this function fixes that.
21773 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21774 row in W's current matrix that is exposed and overlaps other rows.
21775 LAST_OVERLAPPING_ROW is the last such row. */
21778 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21780 struct glyph_row
*first_overlapping_row
;
21781 struct glyph_row
*last_overlapping_row
;
21783 struct glyph_row
*row
;
21785 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21786 if (row
->overlapping_p
)
21788 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21790 if (row
->used
[LEFT_MARGIN_AREA
])
21791 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21793 if (row
->used
[TEXT_AREA
])
21794 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21796 if (row
->used
[RIGHT_MARGIN_AREA
])
21797 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21802 /* Return non-zero if W's cursor intersects rectangle R. */
21805 phys_cursor_in_rect_p (w
, r
)
21809 XRectangle cr
, result
;
21810 struct glyph
*cursor_glyph
;
21812 cursor_glyph
= get_phys_cursor_glyph (w
);
21815 /* r is relative to W's box, but w->phys_cursor.x is relative
21816 to left edge of W's TEXT area. Adjust it. */
21817 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21818 cr
.y
= w
->phys_cursor
.y
;
21819 cr
.width
= cursor_glyph
->pixel_width
;
21820 cr
.height
= w
->phys_cursor_height
;
21821 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21822 I assume the effect is the same -- and this is portable. */
21823 return x_intersect_rectangles (&cr
, r
, &result
);
21831 Draw a vertical window border to the right of window W if W doesn't
21832 have vertical scroll bars. */
21835 x_draw_vertical_border (w
)
21838 /* We could do better, if we knew what type of scroll-bar the adjacent
21839 windows (on either side) have... But we don't :-(
21840 However, I think this works ok. ++KFS 2003-04-25 */
21842 /* Redraw borders between horizontally adjacent windows. Don't
21843 do it for frames with vertical scroll bars because either the
21844 right scroll bar of a window, or the left scroll bar of its
21845 neighbor will suffice as a border. */
21846 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
21849 if (!WINDOW_RIGHTMOST_P (w
)
21850 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21852 int x0
, x1
, y0
, y1
;
21854 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21857 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
21859 else if (!WINDOW_LEFTMOST_P (w
)
21860 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21862 int x0
, x1
, y0
, y1
;
21864 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21867 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
21872 /* Redraw the part of window W intersection rectangle FR. Pixel
21873 coordinates in FR are frame-relative. Call this function with
21874 input blocked. Value is non-zero if the exposure overwrites
21878 expose_window (w
, fr
)
21882 struct frame
*f
= XFRAME (w
->frame
);
21884 int mouse_face_overwritten_p
= 0;
21886 /* If window is not yet fully initialized, do nothing. This can
21887 happen when toolkit scroll bars are used and a window is split.
21888 Reconfiguring the scroll bar will generate an expose for a newly
21890 if (w
->current_matrix
== NULL
)
21893 /* When we're currently updating the window, display and current
21894 matrix usually don't agree. Arrange for a thorough display
21896 if (w
== updated_window
)
21898 SET_FRAME_GARBAGED (f
);
21902 /* Frame-relative pixel rectangle of W. */
21903 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21904 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21905 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21906 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21908 if (x_intersect_rectangles (fr
, &wr
, &r
))
21910 int yb
= window_text_bottom_y (w
);
21911 struct glyph_row
*row
;
21912 int cursor_cleared_p
;
21913 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21915 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21916 r
.x
, r
.y
, r
.width
, r
.height
));
21918 /* Convert to window coordinates. */
21919 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21920 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21922 /* Turn off the cursor. */
21923 if (!w
->pseudo_window_p
21924 && phys_cursor_in_rect_p (w
, &r
))
21926 x_clear_cursor (w
);
21927 cursor_cleared_p
= 1;
21930 cursor_cleared_p
= 0;
21932 /* Update lines intersecting rectangle R. */
21933 first_overlapping_row
= last_overlapping_row
= NULL
;
21934 for (row
= w
->current_matrix
->rows
;
21939 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21941 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21942 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21943 || (r
.y
>= y0
&& r
.y
< y1
)
21944 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21946 if (row
->overlapping_p
)
21948 if (first_overlapping_row
== NULL
)
21949 first_overlapping_row
= row
;
21950 last_overlapping_row
= row
;
21953 if (expose_line (w
, row
, &r
))
21954 mouse_face_overwritten_p
= 1;
21961 /* Display the mode line if there is one. */
21962 if (WINDOW_WANTS_MODELINE_P (w
)
21963 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21965 && row
->y
< r
.y
+ r
.height
)
21967 if (expose_line (w
, row
, &r
))
21968 mouse_face_overwritten_p
= 1;
21971 if (!w
->pseudo_window_p
)
21973 /* Fix the display of overlapping rows. */
21974 if (first_overlapping_row
)
21975 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21977 /* Draw border between windows. */
21978 x_draw_vertical_border (w
);
21980 /* Turn the cursor on again. */
21981 if (cursor_cleared_p
)
21982 update_window_cursor (w
, 1);
21986 return mouse_face_overwritten_p
;
21991 /* Redraw (parts) of all windows in the window tree rooted at W that
21992 intersect R. R contains frame pixel coordinates. Value is
21993 non-zero if the exposure overwrites mouse-face. */
21996 expose_window_tree (w
, r
)
22000 struct frame
*f
= XFRAME (w
->frame
);
22001 int mouse_face_overwritten_p
= 0;
22003 while (w
&& !FRAME_GARBAGED_P (f
))
22005 if (!NILP (w
->hchild
))
22006 mouse_face_overwritten_p
22007 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22008 else if (!NILP (w
->vchild
))
22009 mouse_face_overwritten_p
22010 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22012 mouse_face_overwritten_p
|= expose_window (w
, r
);
22014 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22017 return mouse_face_overwritten_p
;
22022 Redisplay an exposed area of frame F. X and Y are the upper-left
22023 corner of the exposed rectangle. W and H are width and height of
22024 the exposed area. All are pixel values. W or H zero means redraw
22025 the entire frame. */
22028 expose_frame (f
, x
, y
, w
, h
)
22033 int mouse_face_overwritten_p
= 0;
22035 TRACE ((stderr
, "expose_frame "));
22037 /* No need to redraw if frame will be redrawn soon. */
22038 if (FRAME_GARBAGED_P (f
))
22040 TRACE ((stderr
, " garbaged\n"));
22044 /* If basic faces haven't been realized yet, there is no point in
22045 trying to redraw anything. This can happen when we get an expose
22046 event while Emacs is starting, e.g. by moving another window. */
22047 if (FRAME_FACE_CACHE (f
) == NULL
22048 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22050 TRACE ((stderr
, " no faces\n"));
22054 if (w
== 0 || h
== 0)
22057 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22058 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22068 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22069 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22071 if (WINDOWP (f
->tool_bar_window
))
22072 mouse_face_overwritten_p
22073 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22075 #ifdef HAVE_X_WINDOWS
22077 #ifndef USE_X_TOOLKIT
22078 if (WINDOWP (f
->menu_bar_window
))
22079 mouse_face_overwritten_p
22080 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22081 #endif /* not USE_X_TOOLKIT */
22085 /* Some window managers support a focus-follows-mouse style with
22086 delayed raising of frames. Imagine a partially obscured frame,
22087 and moving the mouse into partially obscured mouse-face on that
22088 frame. The visible part of the mouse-face will be highlighted,
22089 then the WM raises the obscured frame. With at least one WM, KDE
22090 2.1, Emacs is not getting any event for the raising of the frame
22091 (even tried with SubstructureRedirectMask), only Expose events.
22092 These expose events will draw text normally, i.e. not
22093 highlighted. Which means we must redo the highlight here.
22094 Subsume it under ``we love X''. --gerd 2001-08-15 */
22095 /* Included in Windows version because Windows most likely does not
22096 do the right thing if any third party tool offers
22097 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22098 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22100 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22101 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22103 int x
= dpyinfo
->mouse_face_mouse_x
;
22104 int y
= dpyinfo
->mouse_face_mouse_y
;
22105 clear_mouse_face (dpyinfo
);
22106 note_mouse_highlight (f
, x
, y
);
22113 Determine the intersection of two rectangles R1 and R2. Return
22114 the intersection in *RESULT. Value is non-zero if RESULT is not
22118 x_intersect_rectangles (r1
, r2
, result
)
22119 XRectangle
*r1
, *r2
, *result
;
22121 XRectangle
*left
, *right
;
22122 XRectangle
*upper
, *lower
;
22123 int intersection_p
= 0;
22125 /* Rearrange so that R1 is the left-most rectangle. */
22127 left
= r1
, right
= r2
;
22129 left
= r2
, right
= r1
;
22131 /* X0 of the intersection is right.x0, if this is inside R1,
22132 otherwise there is no intersection. */
22133 if (right
->x
<= left
->x
+ left
->width
)
22135 result
->x
= right
->x
;
22137 /* The right end of the intersection is the minimum of the
22138 the right ends of left and right. */
22139 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22142 /* Same game for Y. */
22144 upper
= r1
, lower
= r2
;
22146 upper
= r2
, lower
= r1
;
22148 /* The upper end of the intersection is lower.y0, if this is inside
22149 of upper. Otherwise, there is no intersection. */
22150 if (lower
->y
<= upper
->y
+ upper
->height
)
22152 result
->y
= lower
->y
;
22154 /* The lower end of the intersection is the minimum of the lower
22155 ends of upper and lower. */
22156 result
->height
= (min (lower
->y
+ lower
->height
,
22157 upper
->y
+ upper
->height
)
22159 intersection_p
= 1;
22163 return intersection_p
;
22166 #endif /* HAVE_WINDOW_SYSTEM */
22169 /***********************************************************************
22171 ***********************************************************************/
22176 Vwith_echo_area_save_vector
= Qnil
;
22177 staticpro (&Vwith_echo_area_save_vector
);
22179 Vmessage_stack
= Qnil
;
22180 staticpro (&Vmessage_stack
);
22182 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22183 staticpro (&Qinhibit_redisplay
);
22185 message_dolog_marker1
= Fmake_marker ();
22186 staticpro (&message_dolog_marker1
);
22187 message_dolog_marker2
= Fmake_marker ();
22188 staticpro (&message_dolog_marker2
);
22189 message_dolog_marker3
= Fmake_marker ();
22190 staticpro (&message_dolog_marker3
);
22193 defsubr (&Sdump_frame_glyph_matrix
);
22194 defsubr (&Sdump_glyph_matrix
);
22195 defsubr (&Sdump_glyph_row
);
22196 defsubr (&Sdump_tool_bar_row
);
22197 defsubr (&Strace_redisplay
);
22198 defsubr (&Strace_to_stderr
);
22200 #ifdef HAVE_WINDOW_SYSTEM
22201 defsubr (&Stool_bar_lines_needed
);
22202 defsubr (&Slookup_image_map
);
22204 defsubr (&Sformat_mode_line
);
22206 staticpro (&Qmenu_bar_update_hook
);
22207 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22209 staticpro (&Qoverriding_terminal_local_map
);
22210 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22212 staticpro (&Qoverriding_local_map
);
22213 Qoverriding_local_map
= intern ("overriding-local-map");
22215 staticpro (&Qwindow_scroll_functions
);
22216 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22218 staticpro (&Qredisplay_end_trigger_functions
);
22219 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22221 staticpro (&Qinhibit_point_motion_hooks
);
22222 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22224 QCdata
= intern (":data");
22225 staticpro (&QCdata
);
22226 Qdisplay
= intern ("display");
22227 staticpro (&Qdisplay
);
22228 Qspace_width
= intern ("space-width");
22229 staticpro (&Qspace_width
);
22230 Qraise
= intern ("raise");
22231 staticpro (&Qraise
);
22232 Qslice
= intern ("slice");
22233 staticpro (&Qslice
);
22234 Qspace
= intern ("space");
22235 staticpro (&Qspace
);
22236 Qmargin
= intern ("margin");
22237 staticpro (&Qmargin
);
22238 Qpointer
= intern ("pointer");
22239 staticpro (&Qpointer
);
22240 Qleft_margin
= intern ("left-margin");
22241 staticpro (&Qleft_margin
);
22242 Qright_margin
= intern ("right-margin");
22243 staticpro (&Qright_margin
);
22244 Qcenter
= intern ("center");
22245 staticpro (&Qcenter
);
22246 Qline_height
= intern ("line-height");
22247 staticpro (&Qline_height
);
22248 QCalign_to
= intern (":align-to");
22249 staticpro (&QCalign_to
);
22250 QCrelative_width
= intern (":relative-width");
22251 staticpro (&QCrelative_width
);
22252 QCrelative_height
= intern (":relative-height");
22253 staticpro (&QCrelative_height
);
22254 QCeval
= intern (":eval");
22255 staticpro (&QCeval
);
22256 QCpropertize
= intern (":propertize");
22257 staticpro (&QCpropertize
);
22258 QCfile
= intern (":file");
22259 staticpro (&QCfile
);
22260 Qfontified
= intern ("fontified");
22261 staticpro (&Qfontified
);
22262 Qfontification_functions
= intern ("fontification-functions");
22263 staticpro (&Qfontification_functions
);
22264 Qtrailing_whitespace
= intern ("trailing-whitespace");
22265 staticpro (&Qtrailing_whitespace
);
22266 Qescape_glyph
= intern ("escape-glyph");
22267 staticpro (&Qescape_glyph
);
22268 Qimage
= intern ("image");
22269 staticpro (&Qimage
);
22270 QCmap
= intern (":map");
22271 staticpro (&QCmap
);
22272 QCpointer
= intern (":pointer");
22273 staticpro (&QCpointer
);
22274 Qrect
= intern ("rect");
22275 staticpro (&Qrect
);
22276 Qcircle
= intern ("circle");
22277 staticpro (&Qcircle
);
22278 Qpoly
= intern ("poly");
22279 staticpro (&Qpoly
);
22280 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22281 staticpro (&Qmessage_truncate_lines
);
22282 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
22283 staticpro (&Qcursor_in_non_selected_windows
);
22284 Qgrow_only
= intern ("grow-only");
22285 staticpro (&Qgrow_only
);
22286 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22287 staticpro (&Qinhibit_menubar_update
);
22288 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22289 staticpro (&Qinhibit_eval_during_redisplay
);
22290 Qposition
= intern ("position");
22291 staticpro (&Qposition
);
22292 Qbuffer_position
= intern ("buffer-position");
22293 staticpro (&Qbuffer_position
);
22294 Qobject
= intern ("object");
22295 staticpro (&Qobject
);
22296 Qbar
= intern ("bar");
22298 Qhbar
= intern ("hbar");
22299 staticpro (&Qhbar
);
22300 Qbox
= intern ("box");
22302 Qhollow
= intern ("hollow");
22303 staticpro (&Qhollow
);
22304 Qhand
= intern ("hand");
22305 staticpro (&Qhand
);
22306 Qarrow
= intern ("arrow");
22307 staticpro (&Qarrow
);
22308 Qtext
= intern ("text");
22309 staticpro (&Qtext
);
22310 Qrisky_local_variable
= intern ("risky-local-variable");
22311 staticpro (&Qrisky_local_variable
);
22312 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22313 staticpro (&Qinhibit_free_realized_faces
);
22315 list_of_error
= Fcons (Fcons (intern ("error"),
22316 Fcons (intern ("void-variable"), Qnil
)),
22318 staticpro (&list_of_error
);
22320 Qlast_arrow_position
= intern ("last-arrow-position");
22321 staticpro (&Qlast_arrow_position
);
22322 Qlast_arrow_string
= intern ("last-arrow-string");
22323 staticpro (&Qlast_arrow_string
);
22325 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22326 staticpro (&Qoverlay_arrow_string
);
22327 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22328 staticpro (&Qoverlay_arrow_bitmap
);
22330 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22331 staticpro (&echo_buffer
[0]);
22332 staticpro (&echo_buffer
[1]);
22334 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22335 staticpro (&echo_area_buffer
[0]);
22336 staticpro (&echo_area_buffer
[1]);
22338 Vmessages_buffer_name
= build_string ("*Messages*");
22339 staticpro (&Vmessages_buffer_name
);
22341 mode_line_proptrans_alist
= Qnil
;
22342 staticpro (&mode_line_proptrans_alist
);
22344 mode_line_string_list
= Qnil
;
22345 staticpro (&mode_line_string_list
);
22347 help_echo_string
= Qnil
;
22348 staticpro (&help_echo_string
);
22349 help_echo_object
= Qnil
;
22350 staticpro (&help_echo_object
);
22351 help_echo_window
= Qnil
;
22352 staticpro (&help_echo_window
);
22353 previous_help_echo_string
= Qnil
;
22354 staticpro (&previous_help_echo_string
);
22355 help_echo_pos
= -1;
22357 #ifdef HAVE_WINDOW_SYSTEM
22358 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22359 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22360 For example, if a block cursor is over a tab, it will be drawn as
22361 wide as that tab on the display. */);
22362 x_stretch_cursor_p
= 0;
22365 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22366 doc
: /* *Non-nil means highlight trailing whitespace.
22367 The face used for trailing whitespace is `trailing-whitespace'. */);
22368 Vshow_trailing_whitespace
= Qnil
;
22370 DEFVAR_LISP ("show-nonbreak-escape", &Vshow_nonbreak_escape
,
22371 doc
: /* *Non-nil means display escape character before non-break space and hyphen. */);
22372 Vshow_nonbreak_escape
= Qt
;
22374 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22375 doc
: /* *The pointer shape to show in void text areas.
22376 Nil means to show the text pointer. Other options are `arrow', `text',
22377 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22378 Vvoid_text_area_pointer
= Qarrow
;
22380 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22381 doc
: /* Non-nil means don't actually do any redisplay.
22382 This is used for internal purposes. */);
22383 Vinhibit_redisplay
= Qnil
;
22385 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22386 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22387 Vglobal_mode_string
= Qnil
;
22389 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22390 doc
: /* Marker for where to display an arrow on top of the buffer text.
22391 This must be the beginning of a line in order to work.
22392 See also `overlay-arrow-string'. */);
22393 Voverlay_arrow_position
= Qnil
;
22395 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22396 doc
: /* String to display as an arrow in non-window frames.
22397 See also `overlay-arrow-position'. */);
22398 Voverlay_arrow_string
= Qnil
;
22400 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22401 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22402 The symbols on this list are examined during redisplay to determine
22403 where to display overlay arrows. */);
22404 Voverlay_arrow_variable_list
22405 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22407 DEFVAR_INT ("scroll-step", &scroll_step
,
22408 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22409 If that fails to bring point back on frame, point is centered instead.
22410 If this is zero, point is always centered after it moves off frame.
22411 If you want scrolling to always be a line at a time, you should set
22412 `scroll-conservatively' to a large value rather than set this to 1. */);
22414 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22415 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22416 A value of zero means to scroll the text to center point vertically
22417 in the window. */);
22418 scroll_conservatively
= 0;
22420 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22421 doc
: /* *Number of lines of margin at the top and bottom of a window.
22422 Recenter the window whenever point gets within this many lines
22423 of the top or bottom of the window. */);
22426 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22427 doc
: /* Pixels per inch on current display.
22428 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22429 Vdisplay_pixels_per_inch
= make_float (72.0);
22432 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22435 DEFVAR_BOOL ("truncate-partial-width-windows",
22436 &truncate_partial_width_windows
,
22437 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22438 truncate_partial_width_windows
= 1;
22440 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22441 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22442 Any other value means to use the appropriate face, `mode-line',
22443 `header-line', or `menu' respectively. */);
22444 mode_line_inverse_video
= 1;
22446 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22447 doc
: /* *Maximum buffer size for which line number should be displayed.
22448 If the buffer is bigger than this, the line number does not appear
22449 in the mode line. A value of nil means no limit. */);
22450 Vline_number_display_limit
= Qnil
;
22452 DEFVAR_INT ("line-number-display-limit-width",
22453 &line_number_display_limit_width
,
22454 doc
: /* *Maximum line width (in characters) for line number display.
22455 If the average length of the lines near point is bigger than this, then the
22456 line number may be omitted from the mode line. */);
22457 line_number_display_limit_width
= 200;
22459 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22460 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22461 highlight_nonselected_windows
= 0;
22463 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22464 doc
: /* Non-nil if more than one frame is visible on this display.
22465 Minibuffer-only frames don't count, but iconified frames do.
22466 This variable is not guaranteed to be accurate except while processing
22467 `frame-title-format' and `icon-title-format'. */);
22469 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22470 doc
: /* Template for displaying the title bar of visible frames.
22471 \(Assuming the window manager supports this feature.)
22472 This variable has the same structure as `mode-line-format' (which see),
22473 and is used only on frames for which no explicit name has been set
22474 \(see `modify-frame-parameters'). */);
22476 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22477 doc
: /* Template for displaying the title bar of an iconified frame.
22478 \(Assuming the window manager supports this feature.)
22479 This variable has the same structure as `mode-line-format' (which see),
22480 and is used only on frames for which no explicit name has been set
22481 \(see `modify-frame-parameters'). */);
22483 = Vframe_title_format
22484 = Fcons (intern ("multiple-frames"),
22485 Fcons (build_string ("%b"),
22486 Fcons (Fcons (empty_string
,
22487 Fcons (intern ("invocation-name"),
22488 Fcons (build_string ("@"),
22489 Fcons (intern ("system-name"),
22493 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22494 doc
: /* Maximum number of lines to keep in the message log buffer.
22495 If nil, disable message logging. If t, log messages but don't truncate
22496 the buffer when it becomes large. */);
22497 Vmessage_log_max
= make_number (50);
22499 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22500 doc
: /* Functions called before redisplay, if window sizes have changed.
22501 The value should be a list of functions that take one argument.
22502 Just before redisplay, for each frame, if any of its windows have changed
22503 size since the last redisplay, or have been split or deleted,
22504 all the functions in the list are called, with the frame as argument. */);
22505 Vwindow_size_change_functions
= Qnil
;
22507 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22508 doc
: /* List of functions to call before redisplaying a window with scrolling.
22509 Each function is called with two arguments, the window
22510 and its new display-start position. Note that the value of `window-end'
22511 is not valid when these functions are called. */);
22512 Vwindow_scroll_functions
= Qnil
;
22514 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22515 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22516 mouse_autoselect_window
= 0;
22518 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22519 doc
: /* *Non-nil means automatically resize tool-bars.
22520 This increases a tool-bar's height if not all tool-bar items are visible.
22521 It decreases a tool-bar's height when it would display blank lines
22523 auto_resize_tool_bars_p
= 1;
22525 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22526 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22527 auto_raise_tool_bar_buttons_p
= 1;
22529 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
22530 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
22531 make_cursor_line_fully_visible_p
= 1;
22533 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22534 doc
: /* *Margin around tool-bar buttons in pixels.
22535 If an integer, use that for both horizontal and vertical margins.
22536 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22537 HORZ specifying the horizontal margin, and VERT specifying the
22538 vertical margin. */);
22539 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22541 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22542 doc
: /* *Relief thickness of tool-bar buttons. */);
22543 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22545 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22546 doc
: /* List of functions to call to fontify regions of text.
22547 Each function is called with one argument POS. Functions must
22548 fontify a region starting at POS in the current buffer, and give
22549 fontified regions the property `fontified'. */);
22550 Vfontification_functions
= Qnil
;
22551 Fmake_variable_buffer_local (Qfontification_functions
);
22553 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22554 &unibyte_display_via_language_environment
,
22555 doc
: /* *Non-nil means display unibyte text according to language environment.
22556 Specifically this means that unibyte non-ASCII characters
22557 are displayed by converting them to the equivalent multibyte characters
22558 according to the current language environment. As a result, they are
22559 displayed according to the current fontset. */);
22560 unibyte_display_via_language_environment
= 0;
22562 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22563 doc
: /* *Maximum height for resizing mini-windows.
22564 If a float, it specifies a fraction of the mini-window frame's height.
22565 If an integer, it specifies a number of lines. */);
22566 Vmax_mini_window_height
= make_float (0.25);
22568 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22569 doc
: /* *How to resize mini-windows.
22570 A value of nil means don't automatically resize mini-windows.
22571 A value of t means resize them to fit the text displayed in them.
22572 A value of `grow-only', the default, means let mini-windows grow
22573 only, until their display becomes empty, at which point the windows
22574 go back to their normal size. */);
22575 Vresize_mini_windows
= Qgrow_only
;
22577 DEFVAR_LISP ("cursor-in-non-selected-windows",
22578 &Vcursor_in_non_selected_windows
,
22579 doc
: /* *Cursor type to display in non-selected windows.
22580 t means to use hollow box cursor. See `cursor-type' for other values. */);
22581 Vcursor_in_non_selected_windows
= Qt
;
22583 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22584 doc
: /* Alist specifying how to blink the cursor off.
22585 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22586 `cursor-type' frame-parameter or variable equals ON-STATE,
22587 comparing using `equal', Emacs uses OFF-STATE to specify
22588 how to blink it off. */);
22589 Vblink_cursor_alist
= Qnil
;
22591 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22592 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22593 automatic_hscrolling_p
= 1;
22595 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22596 doc
: /* *How many columns away from the window edge point is allowed to get
22597 before automatic hscrolling will horizontally scroll the window. */);
22598 hscroll_margin
= 5;
22600 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22601 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22602 When point is less than `automatic-hscroll-margin' columns from the window
22603 edge, automatic hscrolling will scroll the window by the amount of columns
22604 determined by this variable. If its value is a positive integer, scroll that
22605 many columns. If it's a positive floating-point number, it specifies the
22606 fraction of the window's width to scroll. If it's nil or zero, point will be
22607 centered horizontally after the scroll. Any other value, including negative
22608 numbers, are treated as if the value were zero.
22610 Automatic hscrolling always moves point outside the scroll margin, so if
22611 point was more than scroll step columns inside the margin, the window will
22612 scroll more than the value given by the scroll step.
22614 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22615 and `scroll-right' overrides this variable's effect. */);
22616 Vhscroll_step
= make_number (0);
22618 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22619 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22620 Bind this around calls to `message' to let it take effect. */);
22621 message_truncate_lines
= 0;
22623 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22624 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22625 Can be used to update submenus whose contents should vary. */);
22626 Vmenu_bar_update_hook
= Qnil
;
22628 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22629 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22630 inhibit_menubar_update
= 0;
22632 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22633 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22634 inhibit_eval_during_redisplay
= 0;
22636 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22637 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22638 inhibit_free_realized_faces
= 0;
22641 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22642 doc
: /* Inhibit try_window_id display optimization. */);
22643 inhibit_try_window_id
= 0;
22645 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22646 doc
: /* Inhibit try_window_reusing display optimization. */);
22647 inhibit_try_window_reusing
= 0;
22649 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22650 doc
: /* Inhibit try_cursor_movement display optimization. */);
22651 inhibit_try_cursor_movement
= 0;
22652 #endif /* GLYPH_DEBUG */
22656 /* Initialize this module when Emacs starts. */
22661 Lisp_Object root_window
;
22662 struct window
*mini_w
;
22664 current_header_line_height
= current_mode_line_height
= -1;
22666 CHARPOS (this_line_start_pos
) = 0;
22668 mini_w
= XWINDOW (minibuf_window
);
22669 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22671 if (!noninteractive
)
22673 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22676 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22677 set_window_height (root_window
,
22678 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22680 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22681 set_window_height (minibuf_window
, 1, 0);
22683 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22684 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22686 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22687 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22688 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22690 /* The default ellipsis glyphs `...'. */
22691 for (i
= 0; i
< 3; ++i
)
22692 default_invis_vector
[i
] = make_number ('.');
22696 /* Allocate the buffer for frame titles.
22697 Also used for `format-mode-line'. */
22699 frame_title_buf
= (char *) xmalloc (size
);
22700 frame_title_buf_end
= frame_title_buf
+ size
;
22701 frame_title_ptr
= NULL
;
22704 help_echo_showing_p
= 0;
22708 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22709 (do not change this comment) */