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.
1247 If visible, set *X and *Y to pixel coordinates of top left corner.
1248 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1249 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1250 and header-lines heights. */
1253 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1255 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1258 struct text_pos top
;
1260 struct buffer
*old_buffer
= NULL
;
1265 if (XBUFFER (w
->buffer
) != current_buffer
)
1267 old_buffer
= current_buffer
;
1268 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1271 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1273 /* Compute exact mode line heights, if requested. */
1274 if (exact_mode_line_heights_p
)
1276 if (WINDOW_WANTS_MODELINE_P (w
))
1277 current_mode_line_height
1278 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1279 current_buffer
->mode_line_format
);
1281 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1282 current_header_line_height
1283 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1284 current_buffer
->header_line_format
);
1287 start_display (&it
, w
, top
);
1288 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1289 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1291 /* Note that we may overshoot because of invisible text. */
1292 if (IT_CHARPOS (it
) >= charpos
)
1294 int top_y
= it
.current_y
;
1295 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1296 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1298 if (top_y
< window_top_y
)
1299 visible_p
= bottom_y
> window_top_y
;
1300 else if (top_y
< it
.last_visible_y
)
1305 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1308 *rtop
= max (0, window_top_y
- top_y
);
1309 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1313 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1318 move_it_by_lines (&it
, 1, 0);
1319 if (charpos
< IT_CHARPOS (it
))
1324 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1326 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1330 *rbot
= max (0, (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
) - it
.last_visible_y
);
1337 set_buffer_internal_1 (old_buffer
);
1339 current_header_line_height
= current_mode_line_height
= -1;
1345 /* Return the next character from STR which is MAXLEN bytes long.
1346 Return in *LEN the length of the character. This is like
1347 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1348 we find one, we return a `?', but with the length of the invalid
1352 string_char_and_length (str
, maxlen
, len
)
1353 const unsigned char *str
;
1358 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1359 if (!CHAR_VALID_P (c
, 1))
1360 /* We may not change the length here because other places in Emacs
1361 don't use this function, i.e. they silently accept invalid
1370 /* Given a position POS containing a valid character and byte position
1371 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1373 static struct text_pos
1374 string_pos_nchars_ahead (pos
, string
, nchars
)
1375 struct text_pos pos
;
1379 xassert (STRINGP (string
) && nchars
>= 0);
1381 if (STRING_MULTIBYTE (string
))
1383 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1384 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1389 string_char_and_length (p
, rest
, &len
);
1390 p
+= len
, rest
-= len
;
1391 xassert (rest
>= 0);
1393 BYTEPOS (pos
) += len
;
1397 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1403 /* Value is the text position, i.e. character and byte position,
1404 for character position CHARPOS in STRING. */
1406 static INLINE
struct text_pos
1407 string_pos (charpos
, string
)
1411 struct text_pos pos
;
1412 xassert (STRINGP (string
));
1413 xassert (charpos
>= 0);
1414 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1419 /* Value is a text position, i.e. character and byte position, for
1420 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1421 means recognize multibyte characters. */
1423 static struct text_pos
1424 c_string_pos (charpos
, s
, multibyte_p
)
1429 struct text_pos pos
;
1431 xassert (s
!= NULL
);
1432 xassert (charpos
>= 0);
1436 int rest
= strlen (s
), len
;
1438 SET_TEXT_POS (pos
, 0, 0);
1441 string_char_and_length (s
, rest
, &len
);
1442 s
+= len
, rest
-= len
;
1443 xassert (rest
>= 0);
1445 BYTEPOS (pos
) += len
;
1449 SET_TEXT_POS (pos
, charpos
, charpos
);
1455 /* Value is the number of characters in C string S. MULTIBYTE_P
1456 non-zero means recognize multibyte characters. */
1459 number_of_chars (s
, multibyte_p
)
1467 int rest
= strlen (s
), len
;
1468 unsigned char *p
= (unsigned char *) s
;
1470 for (nchars
= 0; rest
> 0; ++nchars
)
1472 string_char_and_length (p
, rest
, &len
);
1473 rest
-= len
, p
+= len
;
1477 nchars
= strlen (s
);
1483 /* Compute byte position NEWPOS->bytepos corresponding to
1484 NEWPOS->charpos. POS is a known position in string STRING.
1485 NEWPOS->charpos must be >= POS.charpos. */
1488 compute_string_pos (newpos
, pos
, string
)
1489 struct text_pos
*newpos
, pos
;
1492 xassert (STRINGP (string
));
1493 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1495 if (STRING_MULTIBYTE (string
))
1496 *newpos
= string_pos_nchars_ahead (pos
, string
,
1497 CHARPOS (*newpos
) - CHARPOS (pos
));
1499 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1503 Return an estimation of the pixel height of mode or top lines on
1504 frame F. FACE_ID specifies what line's height to estimate. */
1507 estimate_mode_line_height (f
, face_id
)
1509 enum face_id face_id
;
1511 #ifdef HAVE_WINDOW_SYSTEM
1512 if (FRAME_WINDOW_P (f
))
1514 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1516 /* This function is called so early when Emacs starts that the face
1517 cache and mode line face are not yet initialized. */
1518 if (FRAME_FACE_CACHE (f
))
1520 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1524 height
= FONT_HEIGHT (face
->font
);
1525 if (face
->box_line_width
> 0)
1526 height
+= 2 * face
->box_line_width
;
1537 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1538 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1539 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1540 not force the value into range. */
1543 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1545 register int pix_x
, pix_y
;
1547 NativeRectangle
*bounds
;
1551 #ifdef HAVE_WINDOW_SYSTEM
1552 if (FRAME_WINDOW_P (f
))
1554 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1555 even for negative values. */
1557 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1559 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1561 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1562 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1565 STORE_NATIVE_RECT (*bounds
,
1566 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1567 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1568 FRAME_COLUMN_WIDTH (f
) - 1,
1569 FRAME_LINE_HEIGHT (f
) - 1);
1575 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1576 pix_x
= FRAME_TOTAL_COLS (f
);
1580 else if (pix_y
> FRAME_LINES (f
))
1581 pix_y
= FRAME_LINES (f
);
1591 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1592 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1593 can't tell the positions because W's display is not up to date,
1597 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1600 int *frame_x
, *frame_y
;
1602 #ifdef HAVE_WINDOW_SYSTEM
1603 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1607 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1608 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1610 if (display_completed
)
1612 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1613 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1614 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1620 hpos
+= glyph
->pixel_width
;
1624 /* If first glyph is partially visible, its first visible position is still 0. */
1636 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1637 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1648 #ifdef HAVE_WINDOW_SYSTEM
1650 /* Find the glyph under window-relative coordinates X/Y in window W.
1651 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1652 strings. Return in *HPOS and *VPOS the row and column number of
1653 the glyph found. Return in *AREA the glyph area containing X.
1654 Value is a pointer to the glyph found or null if X/Y is not on
1655 text, or we can't tell because W's current matrix is not up to
1658 static struct glyph
*
1659 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1662 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1664 struct glyph
*glyph
, *end
;
1665 struct glyph_row
*row
= NULL
;
1668 /* Find row containing Y. Give up if some row is not enabled. */
1669 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1671 row
= MATRIX_ROW (w
->current_matrix
, i
);
1672 if (!row
->enabled_p
)
1674 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1681 /* Give up if Y is not in the window. */
1682 if (i
== w
->current_matrix
->nrows
)
1685 /* Get the glyph area containing X. */
1686 if (w
->pseudo_window_p
)
1693 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1695 *area
= LEFT_MARGIN_AREA
;
1696 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1698 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1701 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1705 *area
= RIGHT_MARGIN_AREA
;
1706 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1710 /* Find glyph containing X. */
1711 glyph
= row
->glyphs
[*area
];
1712 end
= glyph
+ row
->used
[*area
];
1714 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1716 x
-= glyph
->pixel_width
;
1726 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1729 *hpos
= glyph
- row
->glyphs
[*area
];
1735 Convert frame-relative x/y to coordinates relative to window W.
1736 Takes pseudo-windows into account. */
1739 frame_to_window_pixel_xy (w
, x
, y
)
1743 if (w
->pseudo_window_p
)
1745 /* A pseudo-window is always full-width, and starts at the
1746 left edge of the frame, plus a frame border. */
1747 struct frame
*f
= XFRAME (w
->frame
);
1748 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1749 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1753 *x
-= WINDOW_LEFT_EDGE_X (w
);
1754 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1759 Return in *R the clipping rectangle for glyph string S. */
1762 get_glyph_string_clip_rect (s
, nr
)
1763 struct glyph_string
*s
;
1764 NativeRectangle
*nr
;
1768 if (s
->row
->full_width_p
)
1770 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1771 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1772 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1774 /* Unless displaying a mode or menu bar line, which are always
1775 fully visible, clip to the visible part of the row. */
1776 if (s
->w
->pseudo_window_p
)
1777 r
.height
= s
->row
->visible_height
;
1779 r
.height
= s
->height
;
1783 /* This is a text line that may be partially visible. */
1784 r
.x
= window_box_left (s
->w
, s
->area
);
1785 r
.width
= window_box_width (s
->w
, s
->area
);
1786 r
.height
= s
->row
->visible_height
;
1790 if (r
.x
< s
->clip_head
->x
)
1792 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1793 r
.width
-= s
->clip_head
->x
- r
.x
;
1796 r
.x
= s
->clip_head
->x
;
1799 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1801 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1802 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1807 /* If S draws overlapping rows, it's sufficient to use the top and
1808 bottom of the window for clipping because this glyph string
1809 intentionally draws over other lines. */
1810 if (s
->for_overlaps_p
)
1812 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1813 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1817 /* Don't use S->y for clipping because it doesn't take partially
1818 visible lines into account. For example, it can be negative for
1819 partially visible lines at the top of a window. */
1820 if (!s
->row
->full_width_p
1821 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1822 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1824 r
.y
= max (0, s
->row
->y
);
1826 /* If drawing a tool-bar window, draw it over the internal border
1827 at the top of the window. */
1828 if (WINDOWP (s
->f
->tool_bar_window
)
1829 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1830 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1833 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1835 /* If drawing the cursor, don't let glyph draw outside its
1836 advertised boundaries. Cleartype does this under some circumstances. */
1837 if (s
->hl
== DRAW_CURSOR
)
1839 struct glyph
*glyph
= s
->first_glyph
;
1844 r
.width
-= s
->x
- r
.x
;
1847 r
.width
= min (r
.width
, glyph
->pixel_width
);
1849 /* If r.y is below window bottom, ensure that we still see a cursor. */
1850 height
= min (glyph
->ascent
+ glyph
->descent
,
1851 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1852 max_y
= window_text_bottom_y (s
->w
) - height
;
1853 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1854 if (s
->ybase
- glyph
->ascent
> max_y
)
1861 /* Don't draw cursor glyph taller than our actual glyph. */
1862 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1863 if (height
< r
.height
)
1865 max_y
= r
.y
+ r
.height
;
1866 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1867 r
.height
= min (max_y
- r
.y
, height
);
1872 #ifdef CONVERT_FROM_XRECT
1873 CONVERT_FROM_XRECT (r
, *nr
);
1881 Return the position and height of the phys cursor in window W.
1882 Set w->phys_cursor_width to width of phys cursor.
1886 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1888 struct glyph_row
*row
;
1889 struct glyph
*glyph
;
1892 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1893 int x
, y
, wd
, h
, h0
, y0
;
1895 /* Compute the width of the rectangle to draw. If on a stretch
1896 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1897 rectangle as wide as the glyph, but use a canonical character
1899 wd
= glyph
->pixel_width
- 1;
1903 if (glyph
->type
== STRETCH_GLYPH
1904 && !x_stretch_cursor_p
)
1905 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1906 w
->phys_cursor_width
= wd
;
1908 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1910 /* If y is below window bottom, ensure that we still see a cursor. */
1911 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1913 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1914 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1916 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1919 h
= max (h
- (y0
- y
) + 1, h0
);
1924 y0
= window_text_bottom_y (w
) - h0
;
1933 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1937 #endif /* HAVE_WINDOW_SYSTEM */
1940 /***********************************************************************
1941 Lisp form evaluation
1942 ***********************************************************************/
1944 /* Error handler for safe_eval and safe_call. */
1947 safe_eval_handler (arg
)
1950 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1955 /* Evaluate SEXPR and return the result, or nil if something went
1956 wrong. Prevent redisplay during the evaluation. */
1964 if (inhibit_eval_during_redisplay
)
1968 int count
= SPECPDL_INDEX ();
1969 struct gcpro gcpro1
;
1972 specbind (Qinhibit_redisplay
, Qt
);
1973 /* Use Qt to ensure debugger does not run,
1974 so there is no possibility of wanting to redisplay. */
1975 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1978 val
= unbind_to (count
, val
);
1985 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1986 Return the result, or nil if something went wrong. Prevent
1987 redisplay during the evaluation. */
1990 safe_call (nargs
, args
)
1996 if (inhibit_eval_during_redisplay
)
2000 int count
= SPECPDL_INDEX ();
2001 struct gcpro gcpro1
;
2004 gcpro1
.nvars
= nargs
;
2005 specbind (Qinhibit_redisplay
, Qt
);
2006 /* Use Qt to ensure debugger does not run,
2007 so there is no possibility of wanting to redisplay. */
2008 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2011 val
= unbind_to (count
, val
);
2018 /* Call function FN with one argument ARG.
2019 Return the result, or nil if something went wrong. */
2022 safe_call1 (fn
, arg
)
2023 Lisp_Object fn
, arg
;
2025 Lisp_Object args
[2];
2028 return safe_call (2, args
);
2033 /***********************************************************************
2035 ***********************************************************************/
2039 /* Define CHECK_IT to perform sanity checks on iterators.
2040 This is for debugging. It is too slow to do unconditionally. */
2046 if (it
->method
== next_element_from_string
)
2048 xassert (STRINGP (it
->string
));
2049 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2053 xassert (IT_STRING_CHARPOS (*it
) < 0);
2054 if (it
->method
== next_element_from_buffer
)
2056 /* Check that character and byte positions agree. */
2057 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2062 xassert (it
->current
.dpvec_index
>= 0);
2064 xassert (it
->current
.dpvec_index
< 0);
2067 #define CHECK_IT(IT) check_it ((IT))
2071 #define CHECK_IT(IT) (void) 0
2078 /* Check that the window end of window W is what we expect it
2079 to be---the last row in the current matrix displaying text. */
2082 check_window_end (w
)
2085 if (!MINI_WINDOW_P (w
)
2086 && !NILP (w
->window_end_valid
))
2088 struct glyph_row
*row
;
2089 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2090 XFASTINT (w
->window_end_vpos
)),
2092 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2093 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2097 #define CHECK_WINDOW_END(W) check_window_end ((W))
2099 #else /* not GLYPH_DEBUG */
2101 #define CHECK_WINDOW_END(W) (void) 0
2103 #endif /* not GLYPH_DEBUG */
2107 /***********************************************************************
2108 Iterator initialization
2109 ***********************************************************************/
2111 /* Initialize IT for displaying current_buffer in window W, starting
2112 at character position CHARPOS. CHARPOS < 0 means that no buffer
2113 position is specified which is useful when the iterator is assigned
2114 a position later. BYTEPOS is the byte position corresponding to
2115 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2117 If ROW is not null, calls to produce_glyphs with IT as parameter
2118 will produce glyphs in that row.
2120 BASE_FACE_ID is the id of a base face to use. It must be one of
2121 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2122 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2123 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2125 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2126 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2127 will be initialized to use the corresponding mode line glyph row of
2128 the desired matrix of W. */
2131 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2134 int charpos
, bytepos
;
2135 struct glyph_row
*row
;
2136 enum face_id base_face_id
;
2138 int highlight_region_p
;
2140 /* Some precondition checks. */
2141 xassert (w
!= NULL
&& it
!= NULL
);
2142 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2145 /* If face attributes have been changed since the last redisplay,
2146 free realized faces now because they depend on face definitions
2147 that might have changed. Don't free faces while there might be
2148 desired matrices pending which reference these faces. */
2149 if (face_change_count
&& !inhibit_free_realized_faces
)
2151 face_change_count
= 0;
2152 free_all_realized_faces (Qnil
);
2155 /* Use one of the mode line rows of W's desired matrix if
2159 if (base_face_id
== MODE_LINE_FACE_ID
2160 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2161 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2162 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2163 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2167 bzero (it
, sizeof *it
);
2168 it
->current
.overlay_string_index
= -1;
2169 it
->current
.dpvec_index
= -1;
2170 it
->base_face_id
= base_face_id
;
2172 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2174 /* The window in which we iterate over current_buffer: */
2175 XSETWINDOW (it
->window
, w
);
2177 it
->f
= XFRAME (w
->frame
);
2179 /* Extra space between lines (on window systems only). */
2180 if (base_face_id
== DEFAULT_FACE_ID
2181 && FRAME_WINDOW_P (it
->f
))
2183 if (NATNUMP (current_buffer
->extra_line_spacing
))
2184 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2185 else if (FLOATP (current_buffer
->extra_line_spacing
))
2186 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2187 * FRAME_LINE_HEIGHT (it
->f
));
2188 else if (it
->f
->extra_line_spacing
> 0)
2189 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2190 it
->max_extra_line_spacing
= 0;
2193 /* If realized faces have been removed, e.g. because of face
2194 attribute changes of named faces, recompute them. When running
2195 in batch mode, the face cache of Vterminal_frame is null. If
2196 we happen to get called, make a dummy face cache. */
2197 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2198 init_frame_faces (it
->f
);
2199 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2200 recompute_basic_faces (it
->f
);
2202 /* Current value of the `slice', `space-width', and 'height' properties. */
2203 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2204 it
->space_width
= Qnil
;
2205 it
->font_height
= Qnil
;
2206 it
->override_ascent
= -1;
2208 /* Are control characters displayed as `^C'? */
2209 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2211 /* -1 means everything between a CR and the following line end
2212 is invisible. >0 means lines indented more than this value are
2214 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2215 ? XFASTINT (current_buffer
->selective_display
)
2216 : (!NILP (current_buffer
->selective_display
)
2218 it
->selective_display_ellipsis_p
2219 = !NILP (current_buffer
->selective_display_ellipses
);
2221 /* Display table to use. */
2222 it
->dp
= window_display_table (w
);
2224 /* Are multibyte characters enabled in current_buffer? */
2225 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2227 /* Non-zero if we should highlight the region. */
2229 = (!NILP (Vtransient_mark_mode
)
2230 && !NILP (current_buffer
->mark_active
)
2231 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2233 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2234 start and end of a visible region in window IT->w. Set both to
2235 -1 to indicate no region. */
2236 if (highlight_region_p
2237 /* Maybe highlight only in selected window. */
2238 && (/* Either show region everywhere. */
2239 highlight_nonselected_windows
2240 /* Or show region in the selected window. */
2241 || w
== XWINDOW (selected_window
)
2242 /* Or show the region if we are in the mini-buffer and W is
2243 the window the mini-buffer refers to. */
2244 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2245 && WINDOWP (minibuf_selected_window
)
2246 && w
== XWINDOW (minibuf_selected_window
))))
2248 int charpos
= marker_position (current_buffer
->mark
);
2249 it
->region_beg_charpos
= min (PT
, charpos
);
2250 it
->region_end_charpos
= max (PT
, charpos
);
2253 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2255 /* Get the position at which the redisplay_end_trigger hook should
2256 be run, if it is to be run at all. */
2257 if (MARKERP (w
->redisplay_end_trigger
)
2258 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2259 it
->redisplay_end_trigger_charpos
2260 = marker_position (w
->redisplay_end_trigger
);
2261 else if (INTEGERP (w
->redisplay_end_trigger
))
2262 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2264 /* Correct bogus values of tab_width. */
2265 it
->tab_width
= XINT (current_buffer
->tab_width
);
2266 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2269 /* Are lines in the display truncated? */
2270 it
->truncate_lines_p
2271 = (base_face_id
!= DEFAULT_FACE_ID
2272 || XINT (it
->w
->hscroll
)
2273 || (truncate_partial_width_windows
2274 && !WINDOW_FULL_WIDTH_P (it
->w
))
2275 || !NILP (current_buffer
->truncate_lines
));
2277 /* Get dimensions of truncation and continuation glyphs. These are
2278 displayed as fringe bitmaps under X, so we don't need them for such
2280 if (!FRAME_WINDOW_P (it
->f
))
2282 if (it
->truncate_lines_p
)
2284 /* We will need the truncation glyph. */
2285 xassert (it
->glyph_row
== NULL
);
2286 produce_special_glyphs (it
, IT_TRUNCATION
);
2287 it
->truncation_pixel_width
= it
->pixel_width
;
2291 /* We will need the continuation glyph. */
2292 xassert (it
->glyph_row
== NULL
);
2293 produce_special_glyphs (it
, IT_CONTINUATION
);
2294 it
->continuation_pixel_width
= it
->pixel_width
;
2297 /* Reset these values to zero because the produce_special_glyphs
2298 above has changed them. */
2299 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2300 it
->phys_ascent
= it
->phys_descent
= 0;
2303 /* Set this after getting the dimensions of truncation and
2304 continuation glyphs, so that we don't produce glyphs when calling
2305 produce_special_glyphs, above. */
2306 it
->glyph_row
= row
;
2307 it
->area
= TEXT_AREA
;
2309 /* Get the dimensions of the display area. The display area
2310 consists of the visible window area plus a horizontally scrolled
2311 part to the left of the window. All x-values are relative to the
2312 start of this total display area. */
2313 if (base_face_id
!= DEFAULT_FACE_ID
)
2315 /* Mode lines, menu bar in terminal frames. */
2316 it
->first_visible_x
= 0;
2317 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2322 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2323 it
->last_visible_x
= (it
->first_visible_x
2324 + window_box_width (w
, TEXT_AREA
));
2326 /* If we truncate lines, leave room for the truncator glyph(s) at
2327 the right margin. Otherwise, leave room for the continuation
2328 glyph(s). Truncation and continuation glyphs are not inserted
2329 for window-based redisplay. */
2330 if (!FRAME_WINDOW_P (it
->f
))
2332 if (it
->truncate_lines_p
)
2333 it
->last_visible_x
-= it
->truncation_pixel_width
;
2335 it
->last_visible_x
-= it
->continuation_pixel_width
;
2338 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2339 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2342 /* Leave room for a border glyph. */
2343 if (!FRAME_WINDOW_P (it
->f
)
2344 && !WINDOW_RIGHTMOST_P (it
->w
))
2345 it
->last_visible_x
-= 1;
2347 it
->last_visible_y
= window_text_bottom_y (w
);
2349 /* For mode lines and alike, arrange for the first glyph having a
2350 left box line if the face specifies a box. */
2351 if (base_face_id
!= DEFAULT_FACE_ID
)
2355 it
->face_id
= base_face_id
;
2357 /* If we have a boxed mode line, make the first character appear
2358 with a left box line. */
2359 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2360 if (face
->box
!= FACE_NO_BOX
)
2361 it
->start_of_box_run_p
= 1;
2364 /* If a buffer position was specified, set the iterator there,
2365 getting overlays and face properties from that position. */
2366 if (charpos
>= BUF_BEG (current_buffer
))
2368 it
->end_charpos
= ZV
;
2370 IT_CHARPOS (*it
) = charpos
;
2372 /* Compute byte position if not specified. */
2373 if (bytepos
< charpos
)
2374 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2376 IT_BYTEPOS (*it
) = bytepos
;
2378 it
->start
= it
->current
;
2380 /* Compute faces etc. */
2381 reseat (it
, it
->current
.pos
, 1);
2388 /* Initialize IT for the display of window W with window start POS. */
2391 start_display (it
, w
, pos
)
2394 struct text_pos pos
;
2396 struct glyph_row
*row
;
2397 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2399 row
= w
->desired_matrix
->rows
+ first_vpos
;
2400 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2401 it
->first_vpos
= first_vpos
;
2403 if (!it
->truncate_lines_p
)
2405 int start_at_line_beg_p
;
2406 int first_y
= it
->current_y
;
2408 /* If window start is not at a line start, skip forward to POS to
2409 get the correct continuation lines width. */
2410 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2411 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2412 if (!start_at_line_beg_p
)
2416 reseat_at_previous_visible_line_start (it
);
2417 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2419 new_x
= it
->current_x
+ it
->pixel_width
;
2421 /* If lines are continued, this line may end in the middle
2422 of a multi-glyph character (e.g. a control character
2423 displayed as \003, or in the middle of an overlay
2424 string). In this case move_it_to above will not have
2425 taken us to the start of the continuation line but to the
2426 end of the continued line. */
2427 if (it
->current_x
> 0
2428 && !it
->truncate_lines_p
/* Lines are continued. */
2429 && (/* And glyph doesn't fit on the line. */
2430 new_x
> it
->last_visible_x
2431 /* Or it fits exactly and we're on a window
2433 || (new_x
== it
->last_visible_x
2434 && FRAME_WINDOW_P (it
->f
))))
2436 if (it
->current
.dpvec_index
>= 0
2437 || it
->current
.overlay_string_index
>= 0)
2439 set_iterator_to_next (it
, 1);
2440 move_it_in_display_line_to (it
, -1, -1, 0);
2443 it
->continuation_lines_width
+= it
->current_x
;
2446 /* We're starting a new display line, not affected by the
2447 height of the continued line, so clear the appropriate
2448 fields in the iterator structure. */
2449 it
->max_ascent
= it
->max_descent
= 0;
2450 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2452 it
->current_y
= first_y
;
2454 it
->current_x
= it
->hpos
= 0;
2458 #if 0 /* Don't assert the following because start_display is sometimes
2459 called intentionally with a window start that is not at a
2460 line start. Please leave this code in as a comment. */
2462 /* Window start should be on a line start, now. */
2463 xassert (it
->continuation_lines_width
2464 || IT_CHARPOS (it
) == BEGV
2465 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2470 /* Return 1 if POS is a position in ellipses displayed for invisible
2471 text. W is the window we display, for text property lookup. */
2474 in_ellipses_for_invisible_text_p (pos
, w
)
2475 struct display_pos
*pos
;
2478 Lisp_Object prop
, window
;
2480 int charpos
= CHARPOS (pos
->pos
);
2482 /* If POS specifies a position in a display vector, this might
2483 be for an ellipsis displayed for invisible text. We won't
2484 get the iterator set up for delivering that ellipsis unless
2485 we make sure that it gets aware of the invisible text. */
2486 if (pos
->dpvec_index
>= 0
2487 && pos
->overlay_string_index
< 0
2488 && CHARPOS (pos
->string_pos
) < 0
2490 && (XSETWINDOW (window
, w
),
2491 prop
= Fget_char_property (make_number (charpos
),
2492 Qinvisible
, window
),
2493 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2495 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2497 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2504 /* Initialize IT for stepping through current_buffer in window W,
2505 starting at position POS that includes overlay string and display
2506 vector/ control character translation position information. Value
2507 is zero if there are overlay strings with newlines at POS. */
2510 init_from_display_pos (it
, w
, pos
)
2513 struct display_pos
*pos
;
2515 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2516 int i
, overlay_strings_with_newlines
= 0;
2518 /* If POS specifies a position in a display vector, this might
2519 be for an ellipsis displayed for invisible text. We won't
2520 get the iterator set up for delivering that ellipsis unless
2521 we make sure that it gets aware of the invisible text. */
2522 if (in_ellipses_for_invisible_text_p (pos
, w
))
2528 /* Keep in mind: the call to reseat in init_iterator skips invisible
2529 text, so we might end up at a position different from POS. This
2530 is only a problem when POS is a row start after a newline and an
2531 overlay starts there with an after-string, and the overlay has an
2532 invisible property. Since we don't skip invisible text in
2533 display_line and elsewhere immediately after consuming the
2534 newline before the row start, such a POS will not be in a string,
2535 but the call to init_iterator below will move us to the
2537 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2539 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2541 const char *s
= SDATA (it
->overlay_strings
[i
]);
2542 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2544 while (s
< e
&& *s
!= '\n')
2549 overlay_strings_with_newlines
= 1;
2554 /* If position is within an overlay string, set up IT to the right
2556 if (pos
->overlay_string_index
>= 0)
2560 /* If the first overlay string happens to have a `display'
2561 property for an image, the iterator will be set up for that
2562 image, and we have to undo that setup first before we can
2563 correct the overlay string index. */
2564 if (it
->method
== next_element_from_image
)
2567 /* We already have the first chunk of overlay strings in
2568 IT->overlay_strings. Load more until the one for
2569 pos->overlay_string_index is in IT->overlay_strings. */
2570 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2572 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2573 it
->current
.overlay_string_index
= 0;
2576 load_overlay_strings (it
, 0);
2577 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2581 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2582 relative_index
= (it
->current
.overlay_string_index
2583 % OVERLAY_STRING_CHUNK_SIZE
);
2584 it
->string
= it
->overlay_strings
[relative_index
];
2585 xassert (STRINGP (it
->string
));
2586 it
->current
.string_pos
= pos
->string_pos
;
2587 it
->method
= next_element_from_string
;
2590 #if 0 /* This is bogus because POS not having an overlay string
2591 position does not mean it's after the string. Example: A
2592 line starting with a before-string and initialization of IT
2593 to the previous row's end position. */
2594 else if (it
->current
.overlay_string_index
>= 0)
2596 /* If POS says we're already after an overlay string ending at
2597 POS, make sure to pop the iterator because it will be in
2598 front of that overlay string. When POS is ZV, we've thereby
2599 also ``processed'' overlay strings at ZV. */
2602 it
->current
.overlay_string_index
= -1;
2603 it
->method
= next_element_from_buffer
;
2604 if (CHARPOS (pos
->pos
) == ZV
)
2605 it
->overlay_strings_at_end_processed_p
= 1;
2609 if (CHARPOS (pos
->string_pos
) >= 0)
2611 /* Recorded position is not in an overlay string, but in another
2612 string. This can only be a string from a `display' property.
2613 IT should already be filled with that string. */
2614 it
->current
.string_pos
= pos
->string_pos
;
2615 xassert (STRINGP (it
->string
));
2618 /* Restore position in display vector translations, control
2619 character translations or ellipses. */
2620 if (pos
->dpvec_index
>= 0)
2622 if (it
->dpvec
== NULL
)
2623 get_next_display_element (it
);
2624 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2625 it
->current
.dpvec_index
= pos
->dpvec_index
;
2629 return !overlay_strings_with_newlines
;
2633 /* Initialize IT for stepping through current_buffer in window W
2634 starting at ROW->start. */
2637 init_to_row_start (it
, w
, row
)
2640 struct glyph_row
*row
;
2642 init_from_display_pos (it
, w
, &row
->start
);
2643 it
->start
= row
->start
;
2644 it
->continuation_lines_width
= row
->continuation_lines_width
;
2649 /* Initialize IT for stepping through current_buffer in window W
2650 starting in the line following ROW, i.e. starting at ROW->end.
2651 Value is zero if there are overlay strings with newlines at ROW's
2655 init_to_row_end (it
, w
, row
)
2658 struct glyph_row
*row
;
2662 if (init_from_display_pos (it
, w
, &row
->end
))
2664 if (row
->continued_p
)
2665 it
->continuation_lines_width
2666 = row
->continuation_lines_width
+ row
->pixel_width
;
2677 /***********************************************************************
2679 ***********************************************************************/
2681 /* Called when IT reaches IT->stop_charpos. Handle text property and
2682 overlay changes. Set IT->stop_charpos to the next position where
2689 enum prop_handled handled
;
2690 int handle_overlay_change_p
= 1;
2694 it
->current
.dpvec_index
= -1;
2698 handled
= HANDLED_NORMALLY
;
2700 /* Call text property handlers. */
2701 for (p
= it_props
; p
->handler
; ++p
)
2703 handled
= p
->handler (it
);
2705 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2707 else if (handled
== HANDLED_RETURN
)
2709 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2710 handle_overlay_change_p
= 0;
2713 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2715 /* Don't check for overlay strings below when set to deliver
2716 characters from a display vector. */
2717 if (it
->method
== next_element_from_display_vector
)
2718 handle_overlay_change_p
= 0;
2720 /* Handle overlay changes. */
2721 if (handle_overlay_change_p
)
2722 handled
= handle_overlay_change (it
);
2724 /* Determine where to stop next. */
2725 if (handled
== HANDLED_NORMALLY
)
2726 compute_stop_pos (it
);
2729 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2733 /* Compute IT->stop_charpos from text property and overlay change
2734 information for IT's current position. */
2737 compute_stop_pos (it
)
2740 register INTERVAL iv
, next_iv
;
2741 Lisp_Object object
, limit
, position
;
2743 /* If nowhere else, stop at the end. */
2744 it
->stop_charpos
= it
->end_charpos
;
2746 if (STRINGP (it
->string
))
2748 /* Strings are usually short, so don't limit the search for
2750 object
= it
->string
;
2752 position
= make_number (IT_STRING_CHARPOS (*it
));
2758 /* If next overlay change is in front of the current stop pos
2759 (which is IT->end_charpos), stop there. Note: value of
2760 next_overlay_change is point-max if no overlay change
2762 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2763 if (charpos
< it
->stop_charpos
)
2764 it
->stop_charpos
= charpos
;
2766 /* If showing the region, we have to stop at the region
2767 start or end because the face might change there. */
2768 if (it
->region_beg_charpos
> 0)
2770 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2771 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2772 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2773 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2776 /* Set up variables for computing the stop position from text
2777 property changes. */
2778 XSETBUFFER (object
, current_buffer
);
2779 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2780 position
= make_number (IT_CHARPOS (*it
));
2784 /* Get the interval containing IT's position. Value is a null
2785 interval if there isn't such an interval. */
2786 iv
= validate_interval_range (object
, &position
, &position
, 0);
2787 if (!NULL_INTERVAL_P (iv
))
2789 Lisp_Object values_here
[LAST_PROP_IDX
];
2792 /* Get properties here. */
2793 for (p
= it_props
; p
->handler
; ++p
)
2794 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2796 /* Look for an interval following iv that has different
2798 for (next_iv
= next_interval (iv
);
2799 (!NULL_INTERVAL_P (next_iv
)
2801 || XFASTINT (limit
) > next_iv
->position
));
2802 next_iv
= next_interval (next_iv
))
2804 for (p
= it_props
; p
->handler
; ++p
)
2806 Lisp_Object new_value
;
2808 new_value
= textget (next_iv
->plist
, *p
->name
);
2809 if (!EQ (values_here
[p
->idx
], new_value
))
2817 if (!NULL_INTERVAL_P (next_iv
))
2819 if (INTEGERP (limit
)
2820 && next_iv
->position
>= XFASTINT (limit
))
2821 /* No text property change up to limit. */
2822 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2824 /* Text properties change in next_iv. */
2825 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2829 xassert (STRINGP (it
->string
)
2830 || (it
->stop_charpos
>= BEGV
2831 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2835 /* Return the position of the next overlay change after POS in
2836 current_buffer. Value is point-max if no overlay change
2837 follows. This is like `next-overlay-change' but doesn't use
2841 next_overlay_change (pos
)
2846 Lisp_Object
*overlays
;
2849 /* Get all overlays at the given position. */
2850 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2852 /* If any of these overlays ends before endpos,
2853 use its ending point instead. */
2854 for (i
= 0; i
< noverlays
; ++i
)
2859 oend
= OVERLAY_END (overlays
[i
]);
2860 oendpos
= OVERLAY_POSITION (oend
);
2861 endpos
= min (endpos
, oendpos
);
2869 /***********************************************************************
2871 ***********************************************************************/
2873 /* Handle changes in the `fontified' property of the current buffer by
2874 calling hook functions from Qfontification_functions to fontify
2877 static enum prop_handled
2878 handle_fontified_prop (it
)
2881 Lisp_Object prop
, pos
;
2882 enum prop_handled handled
= HANDLED_NORMALLY
;
2884 /* Get the value of the `fontified' property at IT's current buffer
2885 position. (The `fontified' property doesn't have a special
2886 meaning in strings.) If the value is nil, call functions from
2887 Qfontification_functions. */
2888 if (!STRINGP (it
->string
)
2890 && !NILP (Vfontification_functions
)
2891 && !NILP (Vrun_hooks
)
2892 && (pos
= make_number (IT_CHARPOS (*it
)),
2893 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2896 int count
= SPECPDL_INDEX ();
2899 val
= Vfontification_functions
;
2900 specbind (Qfontification_functions
, Qnil
);
2902 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2903 safe_call1 (val
, pos
);
2906 Lisp_Object globals
, fn
;
2907 struct gcpro gcpro1
, gcpro2
;
2910 GCPRO2 (val
, globals
);
2912 for (; CONSP (val
); val
= XCDR (val
))
2918 /* A value of t indicates this hook has a local
2919 binding; it means to run the global binding too.
2920 In a global value, t should not occur. If it
2921 does, we must ignore it to avoid an endless
2923 for (globals
= Fdefault_value (Qfontification_functions
);
2925 globals
= XCDR (globals
))
2927 fn
= XCAR (globals
);
2929 safe_call1 (fn
, pos
);
2933 safe_call1 (fn
, pos
);
2939 unbind_to (count
, Qnil
);
2941 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2942 something. This avoids an endless loop if they failed to
2943 fontify the text for which reason ever. */
2944 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2945 handled
= HANDLED_RECOMPUTE_PROPS
;
2953 /***********************************************************************
2955 ***********************************************************************/
2957 /* Set up iterator IT from face properties at its current position.
2958 Called from handle_stop. */
2960 static enum prop_handled
2961 handle_face_prop (it
)
2964 int new_face_id
, next_stop
;
2966 if (!STRINGP (it
->string
))
2969 = face_at_buffer_position (it
->w
,
2971 it
->region_beg_charpos
,
2972 it
->region_end_charpos
,
2975 + TEXT_PROP_DISTANCE_LIMIT
),
2978 /* Is this a start of a run of characters with box face?
2979 Caveat: this can be called for a freshly initialized
2980 iterator; face_id is -1 in this case. We know that the new
2981 face will not change until limit, i.e. if the new face has a
2982 box, all characters up to limit will have one. But, as
2983 usual, we don't know whether limit is really the end. */
2984 if (new_face_id
!= it
->face_id
)
2986 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2988 /* If new face has a box but old face has not, this is
2989 the start of a run of characters with box, i.e. it has
2990 a shadow on the left side. The value of face_id of the
2991 iterator will be -1 if this is the initial call that gets
2992 the face. In this case, we have to look in front of IT's
2993 position and see whether there is a face != new_face_id. */
2994 it
->start_of_box_run_p
2995 = (new_face
->box
!= FACE_NO_BOX
2996 && (it
->face_id
>= 0
2997 || IT_CHARPOS (*it
) == BEG
2998 || new_face_id
!= face_before_it_pos (it
)));
2999 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3004 int base_face_id
, bufpos
;
3006 if (it
->current
.overlay_string_index
>= 0)
3007 bufpos
= IT_CHARPOS (*it
);
3011 /* For strings from a buffer, i.e. overlay strings or strings
3012 from a `display' property, use the face at IT's current
3013 buffer position as the base face to merge with, so that
3014 overlay strings appear in the same face as surrounding
3015 text, unless they specify their own faces. */
3016 base_face_id
= underlying_face_id (it
);
3018 new_face_id
= face_at_string_position (it
->w
,
3020 IT_STRING_CHARPOS (*it
),
3022 it
->region_beg_charpos
,
3023 it
->region_end_charpos
,
3027 #if 0 /* This shouldn't be neccessary. Let's check it. */
3028 /* If IT is used to display a mode line we would really like to
3029 use the mode line face instead of the frame's default face. */
3030 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3031 && new_face_id
== DEFAULT_FACE_ID
)
3032 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3035 /* Is this a start of a run of characters with box? Caveat:
3036 this can be called for a freshly allocated iterator; face_id
3037 is -1 is this case. We know that the new face will not
3038 change until the next check pos, i.e. if the new face has a
3039 box, all characters up to that position will have a
3040 box. But, as usual, we don't know whether that position
3041 is really the end. */
3042 if (new_face_id
!= it
->face_id
)
3044 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3045 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3047 /* If new face has a box but old face hasn't, this is the
3048 start of a run of characters with box, i.e. it has a
3049 shadow on the left side. */
3050 it
->start_of_box_run_p
3051 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3052 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3056 it
->face_id
= new_face_id
;
3057 return HANDLED_NORMALLY
;
3061 /* Return the ID of the face ``underlying'' IT's current position,
3062 which is in a string. If the iterator is associated with a
3063 buffer, return the face at IT's current buffer position.
3064 Otherwise, use the iterator's base_face_id. */
3067 underlying_face_id (it
)
3070 int face_id
= it
->base_face_id
, i
;
3072 xassert (STRINGP (it
->string
));
3074 for (i
= it
->sp
- 1; i
>= 0; --i
)
3075 if (NILP (it
->stack
[i
].string
))
3076 face_id
= it
->stack
[i
].face_id
;
3082 /* Compute the face one character before or after the current position
3083 of IT. BEFORE_P non-zero means get the face in front of IT's
3084 position. Value is the id of the face. */
3087 face_before_or_after_it_pos (it
, before_p
)
3092 int next_check_charpos
;
3093 struct text_pos pos
;
3095 xassert (it
->s
== NULL
);
3097 if (STRINGP (it
->string
))
3099 int bufpos
, base_face_id
;
3101 /* No face change past the end of the string (for the case
3102 we are padding with spaces). No face change before the
3104 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3105 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3108 /* Set pos to the position before or after IT's current position. */
3110 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3112 /* For composition, we must check the character after the
3114 pos
= (it
->what
== IT_COMPOSITION
3115 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3116 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3118 if (it
->current
.overlay_string_index
>= 0)
3119 bufpos
= IT_CHARPOS (*it
);
3123 base_face_id
= underlying_face_id (it
);
3125 /* Get the face for ASCII, or unibyte. */
3126 face_id
= face_at_string_position (it
->w
,
3130 it
->region_beg_charpos
,
3131 it
->region_end_charpos
,
3132 &next_check_charpos
,
3135 /* Correct the face for charsets different from ASCII. Do it
3136 for the multibyte case only. The face returned above is
3137 suitable for unibyte text if IT->string is unibyte. */
3138 if (STRING_MULTIBYTE (it
->string
))
3140 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3141 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3143 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3145 c
= string_char_and_length (p
, rest
, &len
);
3146 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3151 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3152 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3155 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3156 pos
= it
->current
.pos
;
3159 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3162 if (it
->what
== IT_COMPOSITION
)
3163 /* For composition, we must check the position after the
3165 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3167 INC_TEXT_POS (pos
, it
->multibyte_p
);
3170 /* Determine face for CHARSET_ASCII, or unibyte. */
3171 face_id
= face_at_buffer_position (it
->w
,
3173 it
->region_beg_charpos
,
3174 it
->region_end_charpos
,
3175 &next_check_charpos
,
3178 /* Correct the face for charsets different from ASCII. Do it
3179 for the multibyte case only. The face returned above is
3180 suitable for unibyte text if current_buffer is unibyte. */
3181 if (it
->multibyte_p
)
3183 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3184 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3185 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3194 /***********************************************************************
3196 ***********************************************************************/
3198 /* Set up iterator IT from invisible properties at its current
3199 position. Called from handle_stop. */
3201 static enum prop_handled
3202 handle_invisible_prop (it
)
3205 enum prop_handled handled
= HANDLED_NORMALLY
;
3207 if (STRINGP (it
->string
))
3209 extern Lisp_Object Qinvisible
;
3210 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3212 /* Get the value of the invisible text property at the
3213 current position. Value will be nil if there is no such
3215 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3216 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3219 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3221 handled
= HANDLED_RECOMPUTE_PROPS
;
3223 /* Get the position at which the next change of the
3224 invisible text property can be found in IT->string.
3225 Value will be nil if the property value is the same for
3226 all the rest of IT->string. */
3227 XSETINT (limit
, SCHARS (it
->string
));
3228 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3231 /* Text at current position is invisible. The next
3232 change in the property is at position end_charpos.
3233 Move IT's current position to that position. */
3234 if (INTEGERP (end_charpos
)
3235 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3237 struct text_pos old
;
3238 old
= it
->current
.string_pos
;
3239 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3240 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3244 /* The rest of the string is invisible. If this is an
3245 overlay string, proceed with the next overlay string
3246 or whatever comes and return a character from there. */
3247 if (it
->current
.overlay_string_index
>= 0)
3249 next_overlay_string (it
);
3250 /* Don't check for overlay strings when we just
3251 finished processing them. */
3252 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3256 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3257 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3264 int invis_p
, newpos
, next_stop
, start_charpos
;
3265 Lisp_Object pos
, prop
, overlay
;
3267 /* First of all, is there invisible text at this position? */
3268 start_charpos
= IT_CHARPOS (*it
);
3269 pos
= make_number (IT_CHARPOS (*it
));
3270 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3272 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3274 /* If we are on invisible text, skip over it. */
3275 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3277 /* Record whether we have to display an ellipsis for the
3279 int display_ellipsis_p
= invis_p
== 2;
3281 handled
= HANDLED_RECOMPUTE_PROPS
;
3283 /* Loop skipping over invisible text. The loop is left at
3284 ZV or with IT on the first char being visible again. */
3287 /* Try to skip some invisible text. Return value is the
3288 position reached which can be equal to IT's position
3289 if there is nothing invisible here. This skips both
3290 over invisible text properties and overlays with
3291 invisible property. */
3292 newpos
= skip_invisible (IT_CHARPOS (*it
),
3293 &next_stop
, ZV
, it
->window
);
3295 /* If we skipped nothing at all we weren't at invisible
3296 text in the first place. If everything to the end of
3297 the buffer was skipped, end the loop. */
3298 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3302 /* We skipped some characters but not necessarily
3303 all there are. Check if we ended up on visible
3304 text. Fget_char_property returns the property of
3305 the char before the given position, i.e. if we
3306 get invis_p = 0, this means that the char at
3307 newpos is visible. */
3308 pos
= make_number (newpos
);
3309 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3310 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3313 /* If we ended up on invisible text, proceed to
3314 skip starting with next_stop. */
3316 IT_CHARPOS (*it
) = next_stop
;
3320 /* The position newpos is now either ZV or on visible text. */
3321 IT_CHARPOS (*it
) = newpos
;
3322 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3324 /* If there are before-strings at the start of invisible
3325 text, and the text is invisible because of a text
3326 property, arrange to show before-strings because 20.x did
3327 it that way. (If the text is invisible because of an
3328 overlay property instead of a text property, this is
3329 already handled in the overlay code.) */
3331 && get_overlay_strings (it
, start_charpos
))
3333 handled
= HANDLED_RECOMPUTE_PROPS
;
3334 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3336 else if (display_ellipsis_p
)
3337 setup_for_ellipsis (it
, 0);
3345 /* Make iterator IT return `...' next.
3346 Replaces LEN characters from buffer. */
3349 setup_for_ellipsis (it
, len
)
3353 /* Use the display table definition for `...'. Invalid glyphs
3354 will be handled by the method returning elements from dpvec. */
3355 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3357 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3358 it
->dpvec
= v
->contents
;
3359 it
->dpend
= v
->contents
+ v
->size
;
3363 /* Default `...'. */
3364 it
->dpvec
= default_invis_vector
;
3365 it
->dpend
= default_invis_vector
+ 3;
3368 it
->dpvec_char_len
= len
;
3369 it
->current
.dpvec_index
= 0;
3370 it
->dpvec_face_id
= -1;
3372 /* Remember the current face id in case glyphs specify faces.
3373 IT's face is restored in set_iterator_to_next. */
3374 it
->saved_face_id
= it
->face_id
;
3375 it
->method
= next_element_from_display_vector
;
3381 /***********************************************************************
3383 ***********************************************************************/
3385 /* Set up iterator IT from `display' property at its current position.
3386 Called from handle_stop.
3387 We return HANDLED_RETURN if some part of the display property
3388 overrides the display of the buffer text itself.
3389 Otherwise we return HANDLED_NORMALLY. */
3391 static enum prop_handled
3392 handle_display_prop (it
)
3395 Lisp_Object prop
, object
;
3396 struct text_pos
*position
;
3397 /* Nonzero if some property replaces the display of the text itself. */
3398 int display_replaced_p
= 0;
3400 if (STRINGP (it
->string
))
3402 object
= it
->string
;
3403 position
= &it
->current
.string_pos
;
3407 object
= it
->w
->buffer
;
3408 position
= &it
->current
.pos
;
3411 /* Reset those iterator values set from display property values. */
3412 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3413 it
->space_width
= Qnil
;
3414 it
->font_height
= Qnil
;
3417 /* We don't support recursive `display' properties, i.e. string
3418 values that have a string `display' property, that have a string
3419 `display' property etc. */
3420 if (!it
->string_from_display_prop_p
)
3421 it
->area
= TEXT_AREA
;
3423 prop
= Fget_char_property (make_number (position
->charpos
),
3426 return HANDLED_NORMALLY
;
3429 /* Simple properties. */
3430 && !EQ (XCAR (prop
), Qimage
)
3431 && !EQ (XCAR (prop
), Qspace
)
3432 && !EQ (XCAR (prop
), Qwhen
)
3433 && !EQ (XCAR (prop
), Qslice
)
3434 && !EQ (XCAR (prop
), Qspace_width
)
3435 && !EQ (XCAR (prop
), Qheight
)
3436 && !EQ (XCAR (prop
), Qraise
)
3437 /* Marginal area specifications. */
3438 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3439 && !EQ (XCAR (prop
), Qleft_fringe
)
3440 && !EQ (XCAR (prop
), Qright_fringe
)
3441 && !NILP (XCAR (prop
)))
3443 for (; CONSP (prop
); prop
= XCDR (prop
))
3445 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3446 position
, display_replaced_p
))
3447 display_replaced_p
= 1;
3450 else if (VECTORP (prop
))
3453 for (i
= 0; i
< ASIZE (prop
); ++i
)
3454 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3455 position
, display_replaced_p
))
3456 display_replaced_p
= 1;
3460 if (handle_single_display_spec (it
, prop
, object
, position
, 0))
3461 display_replaced_p
= 1;
3464 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3468 /* Value is the position of the end of the `display' property starting
3469 at START_POS in OBJECT. */
3471 static struct text_pos
3472 display_prop_end (it
, object
, start_pos
)
3475 struct text_pos start_pos
;
3478 struct text_pos end_pos
;
3480 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3481 Qdisplay
, object
, Qnil
);
3482 CHARPOS (end_pos
) = XFASTINT (end
);
3483 if (STRINGP (object
))
3484 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3486 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3492 /* Set up IT from a single `display' specification PROP. OBJECT
3493 is the object in which the `display' property was found. *POSITION
3494 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3495 means that we previously saw a display specification which already
3496 replaced text display with something else, for example an image;
3497 we ignore such properties after the first one has been processed.
3499 If PROP is a `space' or `image' specification, and in some other
3500 cases too, set *POSITION to the position where the `display'
3503 Value is non-zero if something was found which replaces the display
3504 of buffer or string text. */
3507 handle_single_display_spec (it
, spec
, object
, position
,
3508 display_replaced_before_p
)
3512 struct text_pos
*position
;
3513 int display_replaced_before_p
;
3516 Lisp_Object location
, value
;
3517 struct text_pos start_pos
;
3520 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3521 If the result is non-nil, use VALUE instead of SPEC. */
3523 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3532 if (!NILP (form
) && !EQ (form
, Qt
))
3534 int count
= SPECPDL_INDEX ();
3535 struct gcpro gcpro1
;
3537 /* Bind `object' to the object having the `display' property, a
3538 buffer or string. Bind `position' to the position in the
3539 object where the property was found, and `buffer-position'
3540 to the current position in the buffer. */
3541 specbind (Qobject
, object
);
3542 specbind (Qposition
, make_number (CHARPOS (*position
)));
3543 specbind (Qbuffer_position
,
3544 make_number (STRINGP (object
)
3545 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3547 form
= safe_eval (form
);
3549 unbind_to (count
, Qnil
);
3555 /* Handle `(height HEIGHT)' specifications. */
3557 && EQ (XCAR (spec
), Qheight
)
3558 && CONSP (XCDR (spec
)))
3560 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3563 it
->font_height
= XCAR (XCDR (spec
));
3564 if (!NILP (it
->font_height
))
3566 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3567 int new_height
= -1;
3569 if (CONSP (it
->font_height
)
3570 && (EQ (XCAR (it
->font_height
), Qplus
)
3571 || EQ (XCAR (it
->font_height
), Qminus
))
3572 && CONSP (XCDR (it
->font_height
))
3573 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3575 /* `(+ N)' or `(- N)' where N is an integer. */
3576 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3577 if (EQ (XCAR (it
->font_height
), Qplus
))
3579 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3581 else if (FUNCTIONP (it
->font_height
))
3583 /* Call function with current height as argument.
3584 Value is the new height. */
3586 height
= safe_call1 (it
->font_height
,
3587 face
->lface
[LFACE_HEIGHT_INDEX
]);
3588 if (NUMBERP (height
))
3589 new_height
= XFLOATINT (height
);
3591 else if (NUMBERP (it
->font_height
))
3593 /* Value is a multiple of the canonical char height. */
3596 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3597 new_height
= (XFLOATINT (it
->font_height
)
3598 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3602 /* Evaluate IT->font_height with `height' bound to the
3603 current specified height to get the new height. */
3604 int count
= SPECPDL_INDEX ();
3606 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3607 value
= safe_eval (it
->font_height
);
3608 unbind_to (count
, Qnil
);
3610 if (NUMBERP (value
))
3611 new_height
= XFLOATINT (value
);
3615 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3621 /* Handle `(space_width WIDTH)'. */
3623 && EQ (XCAR (spec
), Qspace_width
)
3624 && CONSP (XCDR (spec
)))
3626 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3629 value
= XCAR (XCDR (spec
));
3630 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3631 it
->space_width
= value
;
3636 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3638 && EQ (XCAR (spec
), Qslice
))
3642 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3645 if (tem
= XCDR (spec
), CONSP (tem
))
3647 it
->slice
.x
= XCAR (tem
);
3648 if (tem
= XCDR (tem
), CONSP (tem
))
3650 it
->slice
.y
= XCAR (tem
);
3651 if (tem
= XCDR (tem
), CONSP (tem
))
3653 it
->slice
.width
= XCAR (tem
);
3654 if (tem
= XCDR (tem
), CONSP (tem
))
3655 it
->slice
.height
= XCAR (tem
);
3663 /* Handle `(raise FACTOR)'. */
3665 && EQ (XCAR (spec
), Qraise
)
3666 && CONSP (XCDR (spec
)))
3668 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3671 #ifdef HAVE_WINDOW_SYSTEM
3672 value
= XCAR (XCDR (spec
));
3673 if (NUMBERP (value
))
3675 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3676 it
->voffset
= - (XFLOATINT (value
)
3677 * (FONT_HEIGHT (face
->font
)));
3679 #endif /* HAVE_WINDOW_SYSTEM */
3684 /* Don't handle the other kinds of display specifications
3685 inside a string that we got from a `display' property. */
3686 if (it
->string_from_display_prop_p
)
3689 /* Characters having this form of property are not displayed, so
3690 we have to find the end of the property. */
3691 start_pos
= *position
;
3692 *position
= display_prop_end (it
, object
, start_pos
);
3695 /* Stop the scan at that end position--we assume that all
3696 text properties change there. */
3697 it
->stop_charpos
= position
->charpos
;
3699 /* Handle `(left-fringe BITMAP [FACE])'
3700 and `(right-fringe BITMAP [FACE])'. */
3702 && (EQ (XCAR (spec
), Qleft_fringe
)
3703 || EQ (XCAR (spec
), Qright_fringe
))
3704 && CONSP (XCDR (spec
)))
3706 int face_id
= DEFAULT_FACE_ID
;
3709 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3710 /* If we return here, POSITION has been advanced
3711 across the text with this property. */
3714 #ifdef HAVE_WINDOW_SYSTEM
3715 value
= XCAR (XCDR (spec
));
3716 if (!SYMBOLP (value
)
3717 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3718 /* If we return here, POSITION has been advanced
3719 across the text with this property. */
3722 if (CONSP (XCDR (XCDR (spec
))))
3724 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3725 int face_id2
= lookup_named_face (it
->f
, face_name
, 'A', 0);
3730 /* Save current settings of IT so that we can restore them
3731 when we are finished with the glyph property value. */
3735 it
->area
= TEXT_AREA
;
3736 it
->what
= IT_IMAGE
;
3737 it
->image_id
= -1; /* no image */
3738 it
->position
= start_pos
;
3739 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3740 it
->method
= next_element_from_image
;
3741 it
->face_id
= face_id
;
3743 /* Say that we haven't consumed the characters with
3744 `display' property yet. The call to pop_it in
3745 set_iterator_to_next will clean this up. */
3746 *position
= start_pos
;
3748 if (EQ (XCAR (spec
), Qleft_fringe
))
3750 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3751 it
->left_user_fringe_face_id
= face_id
;
3755 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3756 it
->right_user_fringe_face_id
= face_id
;
3758 #endif /* HAVE_WINDOW_SYSTEM */
3762 /* Prepare to handle `((margin left-margin) ...)',
3763 `((margin right-margin) ...)' and `((margin nil) ...)'
3764 prefixes for display specifications. */
3765 location
= Qunbound
;
3766 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3770 value
= XCDR (spec
);
3772 value
= XCAR (value
);
3775 if (EQ (XCAR (tem
), Qmargin
)
3776 && (tem
= XCDR (tem
),
3777 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3779 || EQ (tem
, Qleft_margin
)
3780 || EQ (tem
, Qright_margin
))))
3784 if (EQ (location
, Qunbound
))
3790 /* After this point, VALUE is the property after any
3791 margin prefix has been stripped. It must be a string,
3792 an image specification, or `(space ...)'.
3794 LOCATION specifies where to display: `left-margin',
3795 `right-margin' or nil. */
3797 valid_p
= (STRINGP (value
)
3798 #ifdef HAVE_WINDOW_SYSTEM
3799 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3800 #endif /* not HAVE_WINDOW_SYSTEM */
3801 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3803 if (valid_p
&& !display_replaced_before_p
)
3805 /* Save current settings of IT so that we can restore them
3806 when we are finished with the glyph property value. */
3809 if (NILP (location
))
3810 it
->area
= TEXT_AREA
;
3811 else if (EQ (location
, Qleft_margin
))
3812 it
->area
= LEFT_MARGIN_AREA
;
3814 it
->area
= RIGHT_MARGIN_AREA
;
3816 if (STRINGP (value
))
3819 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3820 it
->current
.overlay_string_index
= -1;
3821 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3822 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3823 it
->method
= next_element_from_string
;
3824 it
->stop_charpos
= 0;
3825 it
->string_from_display_prop_p
= 1;
3826 /* Say that we haven't consumed the characters with
3827 `display' property yet. The call to pop_it in
3828 set_iterator_to_next will clean this up. */
3829 *position
= start_pos
;
3831 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3833 it
->method
= next_element_from_stretch
;
3835 it
->current
.pos
= it
->position
= start_pos
;
3837 #ifdef HAVE_WINDOW_SYSTEM
3840 it
->what
= IT_IMAGE
;
3841 it
->image_id
= lookup_image (it
->f
, value
);
3842 it
->position
= start_pos
;
3843 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3844 it
->method
= next_element_from_image
;
3846 /* Say that we haven't consumed the characters with
3847 `display' property yet. The call to pop_it in
3848 set_iterator_to_next will clean this up. */
3849 *position
= start_pos
;
3851 #endif /* HAVE_WINDOW_SYSTEM */
3856 /* Invalid property or property not supported. Restore
3857 POSITION to what it was before. */
3858 *position
= start_pos
;
3863 /* Check if SPEC is a display specification value whose text should be
3864 treated as intangible. */
3867 single_display_spec_intangible_p (prop
)
3870 /* Skip over `when FORM'. */
3871 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3885 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3886 we don't need to treat text as intangible. */
3887 if (EQ (XCAR (prop
), Qmargin
))
3895 || EQ (XCAR (prop
), Qleft_margin
)
3896 || EQ (XCAR (prop
), Qright_margin
))
3900 return (CONSP (prop
)
3901 && (EQ (XCAR (prop
), Qimage
)
3902 || EQ (XCAR (prop
), Qspace
)));
3906 /* Check if PROP is a display property value whose text should be
3907 treated as intangible. */
3910 display_prop_intangible_p (prop
)
3914 && CONSP (XCAR (prop
))
3915 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3917 /* A list of sub-properties. */
3918 while (CONSP (prop
))
3920 if (single_display_spec_intangible_p (XCAR (prop
)))
3925 else if (VECTORP (prop
))
3927 /* A vector of sub-properties. */
3929 for (i
= 0; i
< ASIZE (prop
); ++i
)
3930 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3934 return single_display_spec_intangible_p (prop
);
3940 /* Return 1 if PROP is a display sub-property value containing STRING. */
3943 single_display_spec_string_p (prop
, string
)
3944 Lisp_Object prop
, string
;
3946 if (EQ (string
, prop
))
3949 /* Skip over `when FORM'. */
3950 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3959 /* Skip over `margin LOCATION'. */
3960 if (EQ (XCAR (prop
), Qmargin
))
3971 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3975 /* Return 1 if STRING appears in the `display' property PROP. */
3978 display_prop_string_p (prop
, string
)
3979 Lisp_Object prop
, string
;
3982 && CONSP (XCAR (prop
))
3983 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3985 /* A list of sub-properties. */
3986 while (CONSP (prop
))
3988 if (single_display_spec_string_p (XCAR (prop
), string
))
3993 else if (VECTORP (prop
))
3995 /* A vector of sub-properties. */
3997 for (i
= 0; i
< ASIZE (prop
); ++i
)
3998 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4002 return single_display_spec_string_p (prop
, string
);
4008 /* Determine from which buffer position in W's buffer STRING comes
4009 from. AROUND_CHARPOS is an approximate position where it could
4010 be from. Value is the buffer position or 0 if it couldn't be
4013 W's buffer must be current.
4015 This function is necessary because we don't record buffer positions
4016 in glyphs generated from strings (to keep struct glyph small).
4017 This function may only use code that doesn't eval because it is
4018 called asynchronously from note_mouse_highlight. */
4021 string_buffer_position (w
, string
, around_charpos
)
4026 Lisp_Object limit
, prop
, pos
;
4027 const int MAX_DISTANCE
= 1000;
4030 pos
= make_number (around_charpos
);
4031 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4032 while (!found
&& !EQ (pos
, limit
))
4034 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4035 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4038 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4043 pos
= make_number (around_charpos
);
4044 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4045 while (!found
&& !EQ (pos
, limit
))
4047 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4048 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4051 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4056 return found
? XINT (pos
) : 0;
4061 /***********************************************************************
4062 `composition' property
4063 ***********************************************************************/
4065 /* Set up iterator IT from `composition' property at its current
4066 position. Called from handle_stop. */
4068 static enum prop_handled
4069 handle_composition_prop (it
)
4072 Lisp_Object prop
, string
;
4073 int pos
, pos_byte
, end
;
4074 enum prop_handled handled
= HANDLED_NORMALLY
;
4076 if (STRINGP (it
->string
))
4078 pos
= IT_STRING_CHARPOS (*it
);
4079 pos_byte
= IT_STRING_BYTEPOS (*it
);
4080 string
= it
->string
;
4084 pos
= IT_CHARPOS (*it
);
4085 pos_byte
= IT_BYTEPOS (*it
);
4089 /* If there's a valid composition and point is not inside of the
4090 composition (in the case that the composition is from the current
4091 buffer), draw a glyph composed from the composition components. */
4092 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4093 && COMPOSITION_VALID_P (pos
, end
, prop
)
4094 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4096 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4100 it
->method
= next_element_from_composition
;
4102 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4103 /* For a terminal, draw only the first character of the
4105 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4106 it
->len
= (STRINGP (it
->string
)
4107 ? string_char_to_byte (it
->string
, end
)
4108 : CHAR_TO_BYTE (end
)) - pos_byte
;
4109 it
->stop_charpos
= end
;
4110 handled
= HANDLED_RETURN
;
4119 /***********************************************************************
4121 ***********************************************************************/
4123 /* The following structure is used to record overlay strings for
4124 later sorting in load_overlay_strings. */
4126 struct overlay_entry
4128 Lisp_Object overlay
;
4135 /* Set up iterator IT from overlay strings at its current position.
4136 Called from handle_stop. */
4138 static enum prop_handled
4139 handle_overlay_change (it
)
4142 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4143 return HANDLED_RECOMPUTE_PROPS
;
4145 return HANDLED_NORMALLY
;
4149 /* Set up the next overlay string for delivery by IT, if there is an
4150 overlay string to deliver. Called by set_iterator_to_next when the
4151 end of the current overlay string is reached. If there are more
4152 overlay strings to display, IT->string and
4153 IT->current.overlay_string_index are set appropriately here.
4154 Otherwise IT->string is set to nil. */
4157 next_overlay_string (it
)
4160 ++it
->current
.overlay_string_index
;
4161 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4163 /* No more overlay strings. Restore IT's settings to what
4164 they were before overlay strings were processed, and
4165 continue to deliver from current_buffer. */
4166 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4169 xassert (it
->stop_charpos
>= BEGV
4170 && it
->stop_charpos
<= it
->end_charpos
);
4172 it
->current
.overlay_string_index
= -1;
4173 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4174 it
->n_overlay_strings
= 0;
4175 it
->method
= next_element_from_buffer
;
4177 /* If we're at the end of the buffer, record that we have
4178 processed the overlay strings there already, so that
4179 next_element_from_buffer doesn't try it again. */
4180 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4181 it
->overlay_strings_at_end_processed_p
= 1;
4183 /* If we have to display `...' for invisible text, set
4184 the iterator up for that. */
4185 if (display_ellipsis_p
)
4186 setup_for_ellipsis (it
, 0);
4190 /* There are more overlay strings to process. If
4191 IT->current.overlay_string_index has advanced to a position
4192 where we must load IT->overlay_strings with more strings, do
4194 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4196 if (it
->current
.overlay_string_index
&& i
== 0)
4197 load_overlay_strings (it
, 0);
4199 /* Initialize IT to deliver display elements from the overlay
4201 it
->string
= it
->overlay_strings
[i
];
4202 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4203 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4204 it
->method
= next_element_from_string
;
4205 it
->stop_charpos
= 0;
4212 /* Compare two overlay_entry structures E1 and E2. Used as a
4213 comparison function for qsort in load_overlay_strings. Overlay
4214 strings for the same position are sorted so that
4216 1. All after-strings come in front of before-strings, except
4217 when they come from the same overlay.
4219 2. Within after-strings, strings are sorted so that overlay strings
4220 from overlays with higher priorities come first.
4222 2. Within before-strings, strings are sorted so that overlay
4223 strings from overlays with higher priorities come last.
4225 Value is analogous to strcmp. */
4229 compare_overlay_entries (e1
, e2
)
4232 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4233 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4236 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4238 /* Let after-strings appear in front of before-strings if
4239 they come from different overlays. */
4240 if (EQ (entry1
->overlay
, entry2
->overlay
))
4241 result
= entry1
->after_string_p
? 1 : -1;
4243 result
= entry1
->after_string_p
? -1 : 1;
4245 else if (entry1
->after_string_p
)
4246 /* After-strings sorted in order of decreasing priority. */
4247 result
= entry2
->priority
- entry1
->priority
;
4249 /* Before-strings sorted in order of increasing priority. */
4250 result
= entry1
->priority
- entry2
->priority
;
4256 /* Load the vector IT->overlay_strings with overlay strings from IT's
4257 current buffer position, or from CHARPOS if that is > 0. Set
4258 IT->n_overlays to the total number of overlay strings found.
4260 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4261 a time. On entry into load_overlay_strings,
4262 IT->current.overlay_string_index gives the number of overlay
4263 strings that have already been loaded by previous calls to this
4266 IT->add_overlay_start contains an additional overlay start
4267 position to consider for taking overlay strings from, if non-zero.
4268 This position comes into play when the overlay has an `invisible'
4269 property, and both before and after-strings. When we've skipped to
4270 the end of the overlay, because of its `invisible' property, we
4271 nevertheless want its before-string to appear.
4272 IT->add_overlay_start will contain the overlay start position
4275 Overlay strings are sorted so that after-string strings come in
4276 front of before-string strings. Within before and after-strings,
4277 strings are sorted by overlay priority. See also function
4278 compare_overlay_entries. */
4281 load_overlay_strings (it
, charpos
)
4285 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4286 Lisp_Object overlay
, window
, str
, invisible
;
4287 struct Lisp_Overlay
*ov
;
4290 int n
= 0, i
, j
, invis_p
;
4291 struct overlay_entry
*entries
4292 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4295 charpos
= IT_CHARPOS (*it
);
4297 /* Append the overlay string STRING of overlay OVERLAY to vector
4298 `entries' which has size `size' and currently contains `n'
4299 elements. AFTER_P non-zero means STRING is an after-string of
4301 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4304 Lisp_Object priority; \
4308 int new_size = 2 * size; \
4309 struct overlay_entry *old = entries; \
4311 (struct overlay_entry *) alloca (new_size \
4312 * sizeof *entries); \
4313 bcopy (old, entries, size * sizeof *entries); \
4317 entries[n].string = (STRING); \
4318 entries[n].overlay = (OVERLAY); \
4319 priority = Foverlay_get ((OVERLAY), Qpriority); \
4320 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4321 entries[n].after_string_p = (AFTER_P); \
4326 /* Process overlay before the overlay center. */
4327 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4329 XSETMISC (overlay
, ov
);
4330 xassert (OVERLAYP (overlay
));
4331 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4332 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4337 /* Skip this overlay if it doesn't start or end at IT's current
4339 if (end
!= charpos
&& start
!= charpos
)
4342 /* Skip this overlay if it doesn't apply to IT->w. */
4343 window
= Foverlay_get (overlay
, Qwindow
);
4344 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4347 /* If the text ``under'' the overlay is invisible, both before-
4348 and after-strings from this overlay are visible; start and
4349 end position are indistinguishable. */
4350 invisible
= Foverlay_get (overlay
, Qinvisible
);
4351 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4353 /* If overlay has a non-empty before-string, record it. */
4354 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4355 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4357 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4359 /* If overlay has a non-empty after-string, record it. */
4360 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4361 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4363 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4366 /* Process overlays after the overlay center. */
4367 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4369 XSETMISC (overlay
, ov
);
4370 xassert (OVERLAYP (overlay
));
4371 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4372 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4374 if (start
> charpos
)
4377 /* Skip this overlay if it doesn't start or end at IT's current
4379 if (end
!= charpos
&& start
!= charpos
)
4382 /* Skip this overlay if it doesn't apply to IT->w. */
4383 window
= Foverlay_get (overlay
, Qwindow
);
4384 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4387 /* If the text ``under'' the overlay is invisible, it has a zero
4388 dimension, and both before- and after-strings apply. */
4389 invisible
= Foverlay_get (overlay
, Qinvisible
);
4390 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4392 /* If overlay has a non-empty before-string, record it. */
4393 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4394 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4396 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4398 /* If overlay has a non-empty after-string, record it. */
4399 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4400 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4402 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4405 #undef RECORD_OVERLAY_STRING
4409 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4411 /* Record the total number of strings to process. */
4412 it
->n_overlay_strings
= n
;
4414 /* IT->current.overlay_string_index is the number of overlay strings
4415 that have already been consumed by IT. Copy some of the
4416 remaining overlay strings to IT->overlay_strings. */
4418 j
= it
->current
.overlay_string_index
;
4419 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4420 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4426 /* Get the first chunk of overlay strings at IT's current buffer
4427 position, or at CHARPOS if that is > 0. Value is non-zero if at
4428 least one overlay string was found. */
4431 get_overlay_strings (it
, charpos
)
4435 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4436 process. This fills IT->overlay_strings with strings, and sets
4437 IT->n_overlay_strings to the total number of strings to process.
4438 IT->pos.overlay_string_index has to be set temporarily to zero
4439 because load_overlay_strings needs this; it must be set to -1
4440 when no overlay strings are found because a zero value would
4441 indicate a position in the first overlay string. */
4442 it
->current
.overlay_string_index
= 0;
4443 load_overlay_strings (it
, charpos
);
4445 /* If we found overlay strings, set up IT to deliver display
4446 elements from the first one. Otherwise set up IT to deliver
4447 from current_buffer. */
4448 if (it
->n_overlay_strings
)
4450 /* Make sure we know settings in current_buffer, so that we can
4451 restore meaningful values when we're done with the overlay
4453 compute_stop_pos (it
);
4454 xassert (it
->face_id
>= 0);
4456 /* Save IT's settings. They are restored after all overlay
4457 strings have been processed. */
4458 xassert (it
->sp
== 0);
4461 /* Set up IT to deliver display elements from the first overlay
4463 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4464 it
->string
= it
->overlay_strings
[0];
4465 it
->stop_charpos
= 0;
4466 xassert (STRINGP (it
->string
));
4467 it
->end_charpos
= SCHARS (it
->string
);
4468 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4469 it
->method
= next_element_from_string
;
4474 it
->current
.overlay_string_index
= -1;
4475 it
->method
= next_element_from_buffer
;
4480 /* Value is non-zero if we found at least one overlay string. */
4481 return STRINGP (it
->string
);
4486 /***********************************************************************
4487 Saving and restoring state
4488 ***********************************************************************/
4490 /* Save current settings of IT on IT->stack. Called, for example,
4491 before setting up IT for an overlay string, to be able to restore
4492 IT's settings to what they were after the overlay string has been
4499 struct iterator_stack_entry
*p
;
4501 xassert (it
->sp
< 2);
4502 p
= it
->stack
+ it
->sp
;
4504 p
->stop_charpos
= it
->stop_charpos
;
4505 xassert (it
->face_id
>= 0);
4506 p
->face_id
= it
->face_id
;
4507 p
->string
= it
->string
;
4508 p
->pos
= it
->current
;
4509 p
->end_charpos
= it
->end_charpos
;
4510 p
->string_nchars
= it
->string_nchars
;
4512 p
->multibyte_p
= it
->multibyte_p
;
4513 p
->slice
= it
->slice
;
4514 p
->space_width
= it
->space_width
;
4515 p
->font_height
= it
->font_height
;
4516 p
->voffset
= it
->voffset
;
4517 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4518 p
->display_ellipsis_p
= 0;
4523 /* Restore IT's settings from IT->stack. Called, for example, when no
4524 more overlay strings must be processed, and we return to delivering
4525 display elements from a buffer, or when the end of a string from a
4526 `display' property is reached and we return to delivering display
4527 elements from an overlay string, or from a buffer. */
4533 struct iterator_stack_entry
*p
;
4535 xassert (it
->sp
> 0);
4537 p
= it
->stack
+ it
->sp
;
4538 it
->stop_charpos
= p
->stop_charpos
;
4539 it
->face_id
= p
->face_id
;
4540 it
->string
= p
->string
;
4541 it
->current
= p
->pos
;
4542 it
->end_charpos
= p
->end_charpos
;
4543 it
->string_nchars
= p
->string_nchars
;
4545 it
->multibyte_p
= p
->multibyte_p
;
4546 it
->slice
= p
->slice
;
4547 it
->space_width
= p
->space_width
;
4548 it
->font_height
= p
->font_height
;
4549 it
->voffset
= p
->voffset
;
4550 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4555 /***********************************************************************
4557 ***********************************************************************/
4559 /* Set IT's current position to the previous line start. */
4562 back_to_previous_line_start (it
)
4565 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4566 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4570 /* Move IT to the next line start.
4572 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4573 we skipped over part of the text (as opposed to moving the iterator
4574 continuously over the text). Otherwise, don't change the value
4577 Newlines may come from buffer text, overlay strings, or strings
4578 displayed via the `display' property. That's the reason we can't
4579 simply use find_next_newline_no_quit.
4581 Note that this function may not skip over invisible text that is so
4582 because of text properties and immediately follows a newline. If
4583 it would, function reseat_at_next_visible_line_start, when called
4584 from set_iterator_to_next, would effectively make invisible
4585 characters following a newline part of the wrong glyph row, which
4586 leads to wrong cursor motion. */
4589 forward_to_next_line_start (it
, skipped_p
)
4593 int old_selective
, newline_found_p
, n
;
4594 const int MAX_NEWLINE_DISTANCE
= 500;
4596 /* If already on a newline, just consume it to avoid unintended
4597 skipping over invisible text below. */
4598 if (it
->what
== IT_CHARACTER
4600 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4602 set_iterator_to_next (it
, 0);
4607 /* Don't handle selective display in the following. It's (a)
4608 unnecessary because it's done by the caller, and (b) leads to an
4609 infinite recursion because next_element_from_ellipsis indirectly
4610 calls this function. */
4611 old_selective
= it
->selective
;
4614 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4615 from buffer text. */
4616 for (n
= newline_found_p
= 0;
4617 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4618 n
+= STRINGP (it
->string
) ? 0 : 1)
4620 if (!get_next_display_element (it
))
4622 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4623 set_iterator_to_next (it
, 0);
4626 /* If we didn't find a newline near enough, see if we can use a
4628 if (!newline_found_p
)
4630 int start
= IT_CHARPOS (*it
);
4631 int limit
= find_next_newline_no_quit (start
, 1);
4634 xassert (!STRINGP (it
->string
));
4636 /* If there isn't any `display' property in sight, and no
4637 overlays, we can just use the position of the newline in
4639 if (it
->stop_charpos
>= limit
4640 || ((pos
= Fnext_single_property_change (make_number (start
),
4642 Qnil
, make_number (limit
)),
4644 && next_overlay_change (start
) == ZV
))
4646 IT_CHARPOS (*it
) = limit
;
4647 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4648 *skipped_p
= newline_found_p
= 1;
4652 while (get_next_display_element (it
)
4653 && !newline_found_p
)
4655 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4656 set_iterator_to_next (it
, 0);
4661 it
->selective
= old_selective
;
4662 return newline_found_p
;
4666 /* Set IT's current position to the previous visible line start. Skip
4667 invisible text that is so either due to text properties or due to
4668 selective display. Caution: this does not change IT->current_x and
4672 back_to_previous_visible_line_start (it
)
4675 while (IT_CHARPOS (*it
) > BEGV
)
4677 back_to_previous_line_start (it
);
4678 if (IT_CHARPOS (*it
) <= BEGV
)
4681 /* If selective > 0, then lines indented more than that values
4683 if (it
->selective
> 0
4684 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4685 (double) it
->selective
)) /* iftc */
4688 /* Check the newline before point for invisibility. */
4691 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4692 Qinvisible
, it
->window
);
4693 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4697 /* If newline has a display property that replaces the newline with something
4698 else (image or text), find start of overlay or interval and continue search
4701 struct it it2
= *it
;
4702 int pos
= IT_CHARPOS (*it
);
4704 Lisp_Object val
, overlay
;
4707 if (handle_display_prop (&it2
) == HANDLED_RETURN
4708 && !NILP (val
= get_char_property_and_overlay
4709 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4710 && (OVERLAYP (overlay
)
4711 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4712 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4716 IT_CHARPOS (*it
) = beg
;
4717 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4724 xassert (IT_CHARPOS (*it
) >= BEGV
);
4725 xassert (IT_CHARPOS (*it
) == BEGV
4726 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4731 /* Reseat iterator IT at the previous visible line start. Skip
4732 invisible text that is so either due to text properties or due to
4733 selective display. At the end, update IT's overlay information,
4734 face information etc. */
4737 reseat_at_previous_visible_line_start (it
)
4740 back_to_previous_visible_line_start (it
);
4741 reseat (it
, it
->current
.pos
, 1);
4746 /* Reseat iterator IT on the next visible line start in the current
4747 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4748 preceding the line start. Skip over invisible text that is so
4749 because of selective display. Compute faces, overlays etc at the
4750 new position. Note that this function does not skip over text that
4751 is invisible because of text properties. */
4754 reseat_at_next_visible_line_start (it
, on_newline_p
)
4758 int newline_found_p
, skipped_p
= 0;
4760 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4762 /* Skip over lines that are invisible because they are indented
4763 more than the value of IT->selective. */
4764 if (it
->selective
> 0)
4765 while (IT_CHARPOS (*it
) < ZV
4766 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4767 (double) it
->selective
)) /* iftc */
4769 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4770 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4773 /* Position on the newline if that's what's requested. */
4774 if (on_newline_p
&& newline_found_p
)
4776 if (STRINGP (it
->string
))
4778 if (IT_STRING_CHARPOS (*it
) > 0)
4780 --IT_STRING_CHARPOS (*it
);
4781 --IT_STRING_BYTEPOS (*it
);
4784 else if (IT_CHARPOS (*it
) > BEGV
)
4788 reseat (it
, it
->current
.pos
, 0);
4792 reseat (it
, it
->current
.pos
, 0);
4799 /***********************************************************************
4800 Changing an iterator's position
4801 ***********************************************************************/
4803 /* Change IT's current position to POS in current_buffer. If FORCE_P
4804 is non-zero, always check for text properties at the new position.
4805 Otherwise, text properties are only looked up if POS >=
4806 IT->check_charpos of a property. */
4809 reseat (it
, pos
, force_p
)
4811 struct text_pos pos
;
4814 int original_pos
= IT_CHARPOS (*it
);
4816 reseat_1 (it
, pos
, 0);
4818 /* Determine where to check text properties. Avoid doing it
4819 where possible because text property lookup is very expensive. */
4821 || CHARPOS (pos
) > it
->stop_charpos
4822 || CHARPOS (pos
) < original_pos
)
4829 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4830 IT->stop_pos to POS, also. */
4833 reseat_1 (it
, pos
, set_stop_p
)
4835 struct text_pos pos
;
4838 /* Don't call this function when scanning a C string. */
4839 xassert (it
->s
== NULL
);
4841 /* POS must be a reasonable value. */
4842 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4844 it
->current
.pos
= it
->position
= pos
;
4845 XSETBUFFER (it
->object
, current_buffer
);
4846 it
->end_charpos
= ZV
;
4848 it
->current
.dpvec_index
= -1;
4849 it
->current
.overlay_string_index
= -1;
4850 IT_STRING_CHARPOS (*it
) = -1;
4851 IT_STRING_BYTEPOS (*it
) = -1;
4853 it
->method
= next_element_from_buffer
;
4854 /* RMS: I added this to fix a bug in move_it_vertically_backward
4855 where it->area continued to relate to the starting point
4856 for the backward motion. Bug report from
4857 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4858 However, I am not sure whether reseat still does the right thing
4859 in general after this change. */
4860 it
->area
= TEXT_AREA
;
4861 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4863 it
->face_before_selective_p
= 0;
4866 it
->stop_charpos
= CHARPOS (pos
);
4870 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4871 If S is non-null, it is a C string to iterate over. Otherwise,
4872 STRING gives a Lisp string to iterate over.
4874 If PRECISION > 0, don't return more then PRECISION number of
4875 characters from the string.
4877 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4878 characters have been returned. FIELD_WIDTH < 0 means an infinite
4881 MULTIBYTE = 0 means disable processing of multibyte characters,
4882 MULTIBYTE > 0 means enable it,
4883 MULTIBYTE < 0 means use IT->multibyte_p.
4885 IT must be initialized via a prior call to init_iterator before
4886 calling this function. */
4889 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4894 int precision
, field_width
, multibyte
;
4896 /* No region in strings. */
4897 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4899 /* No text property checks performed by default, but see below. */
4900 it
->stop_charpos
= -1;
4902 /* Set iterator position and end position. */
4903 bzero (&it
->current
, sizeof it
->current
);
4904 it
->current
.overlay_string_index
= -1;
4905 it
->current
.dpvec_index
= -1;
4906 xassert (charpos
>= 0);
4908 /* If STRING is specified, use its multibyteness, otherwise use the
4909 setting of MULTIBYTE, if specified. */
4911 it
->multibyte_p
= multibyte
> 0;
4915 xassert (STRINGP (string
));
4916 it
->string
= string
;
4918 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4919 it
->method
= next_element_from_string
;
4920 it
->current
.string_pos
= string_pos (charpos
, string
);
4927 /* Note that we use IT->current.pos, not it->current.string_pos,
4928 for displaying C strings. */
4929 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4930 if (it
->multibyte_p
)
4932 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4933 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4937 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4938 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4941 it
->method
= next_element_from_c_string
;
4944 /* PRECISION > 0 means don't return more than PRECISION characters
4946 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4947 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4949 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4950 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4951 FIELD_WIDTH < 0 means infinite field width. This is useful for
4952 padding with `-' at the end of a mode line. */
4953 if (field_width
< 0)
4954 field_width
= INFINITY
;
4955 if (field_width
> it
->end_charpos
- charpos
)
4956 it
->end_charpos
= charpos
+ field_width
;
4958 /* Use the standard display table for displaying strings. */
4959 if (DISP_TABLE_P (Vstandard_display_table
))
4960 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4962 it
->stop_charpos
= charpos
;
4968 /***********************************************************************
4970 ***********************************************************************/
4972 /* Load IT's display element fields with information about the next
4973 display element from the current position of IT. Value is zero if
4974 end of buffer (or C string) is reached. */
4977 get_next_display_element (it
)
4980 /* Non-zero means that we found a display element. Zero means that
4981 we hit the end of what we iterate over. Performance note: the
4982 function pointer `method' used here turns out to be faster than
4983 using a sequence of if-statements. */
4987 success_p
= (*it
->method
) (it
);
4989 if (it
->what
== IT_CHARACTER
)
4991 /* Map via display table or translate control characters.
4992 IT->c, IT->len etc. have been set to the next character by
4993 the function call above. If we have a display table, and it
4994 contains an entry for IT->c, translate it. Don't do this if
4995 IT->c itself comes from a display table, otherwise we could
4996 end up in an infinite recursion. (An alternative could be to
4997 count the recursion depth of this function and signal an
4998 error when a certain maximum depth is reached.) Is it worth
5000 if (success_p
&& it
->dpvec
== NULL
)
5005 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5008 struct Lisp_Vector
*v
= XVECTOR (dv
);
5010 /* Return the first character from the display table
5011 entry, if not empty. If empty, don't display the
5012 current character. */
5015 it
->dpvec_char_len
= it
->len
;
5016 it
->dpvec
= v
->contents
;
5017 it
->dpend
= v
->contents
+ v
->size
;
5018 it
->current
.dpvec_index
= 0;
5019 it
->dpvec_face_id
= -1;
5020 it
->saved_face_id
= it
->face_id
;
5021 it
->method
= next_element_from_display_vector
;
5026 set_iterator_to_next (it
, 0);
5031 /* Translate control characters into `\003' or `^C' form.
5032 Control characters coming from a display table entry are
5033 currently not translated because we use IT->dpvec to hold
5034 the translation. This could easily be changed but I
5035 don't believe that it is worth doing.
5037 If it->multibyte_p is nonzero, eight-bit characters and
5038 non-printable multibyte characters are also translated to
5041 If it->multibyte_p is zero, eight-bit characters that
5042 don't have corresponding multibyte char code are also
5043 translated to octal form. */
5044 else if ((it
->c
< ' '
5045 && (it
->area
!= TEXT_AREA
5046 /* In mode line, treat \n like other crl chars. */
5048 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5049 || (it
->c
!= '\n' && it
->c
!= '\t')))
5053 || !CHAR_PRINTABLE_P (it
->c
)
5054 || (!NILP (Vshow_nonbreak_escape
)
5055 && (it
->c
== 0x8ad || it
->c
== 0x8a0)))
5057 && (!unibyte_display_via_language_environment
5058 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5060 /* IT->c is a control character which must be displayed
5061 either as '\003' or as `^C' where the '\\' and '^'
5062 can be defined in the display table. Fill
5063 IT->ctl_chars with glyphs for what we have to
5064 display. Then, set IT->dpvec to these glyphs. */
5067 int face_id
, lface_id
;
5070 if (it
->c
< 128 && it
->ctl_arrow_p
)
5072 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5074 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5075 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5077 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5078 lface_id
= FAST_GLYPH_FACE (g
);
5081 g
= FAST_GLYPH_CHAR (g
);
5082 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5088 /* Merge the escape-glyph face into the current face. */
5089 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5094 XSETINT (it
->ctl_chars
[0], g
);
5096 XSETINT (it
->ctl_chars
[1], g
);
5098 goto display_control
;
5102 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5103 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5105 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5106 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5109 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5110 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5116 /* Merge the escape-glyph face into the current face. */
5117 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5119 escape_glyph
= '\\';
5122 if (it
->c
== 0x8a0 || it
->c
== 0x8ad)
5124 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5125 g
= it
->c
== 0x8ad ? '-' : ' ';
5126 XSETINT (it
->ctl_chars
[1], g
);
5128 goto display_control
;
5132 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5136 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5137 if (SINGLE_BYTE_CHAR_P (it
->c
))
5138 str
[0] = it
->c
, len
= 1;
5141 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5144 /* It's an invalid character, which shouldn't
5145 happen actually, but due to bugs it may
5146 happen. Let's print the char as is, there's
5147 not much meaningful we can do with it. */
5149 str
[1] = it
->c
>> 8;
5150 str
[2] = it
->c
>> 16;
5151 str
[3] = it
->c
>> 24;
5156 for (i
= 0; i
< len
; i
++)
5158 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5159 /* Insert three more glyphs into IT->ctl_chars for
5160 the octal display of the character. */
5161 g
= ((str
[i
] >> 6) & 7) + '0';
5162 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5163 g
= ((str
[i
] >> 3) & 7) + '0';
5164 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5165 g
= (str
[i
] & 7) + '0';
5166 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5172 /* Set up IT->dpvec and return first character from it. */
5173 it
->dpvec_char_len
= it
->len
;
5174 it
->dpvec
= it
->ctl_chars
;
5175 it
->dpend
= it
->dpvec
+ ctl_len
;
5176 it
->current
.dpvec_index
= 0;
5177 it
->dpvec_face_id
= face_id
;
5178 it
->saved_face_id
= it
->face_id
;
5179 it
->method
= next_element_from_display_vector
;
5185 /* Adjust face id for a multibyte character. There are no
5186 multibyte character in unibyte text. */
5189 && FRAME_WINDOW_P (it
->f
))
5191 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5192 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5196 /* Is this character the last one of a run of characters with
5197 box? If yes, set IT->end_of_box_run_p to 1. */
5204 it
->end_of_box_run_p
5205 = ((face_id
= face_after_it_pos (it
),
5206 face_id
!= it
->face_id
)
5207 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5208 face
->box
== FACE_NO_BOX
));
5211 /* Value is 0 if end of buffer or string reached. */
5216 /* Move IT to the next display element.
5218 RESEAT_P non-zero means if called on a newline in buffer text,
5219 skip to the next visible line start.
5221 Functions get_next_display_element and set_iterator_to_next are
5222 separate because I find this arrangement easier to handle than a
5223 get_next_display_element function that also increments IT's
5224 position. The way it is we can first look at an iterator's current
5225 display element, decide whether it fits on a line, and if it does,
5226 increment the iterator position. The other way around we probably
5227 would either need a flag indicating whether the iterator has to be
5228 incremented the next time, or we would have to implement a
5229 decrement position function which would not be easy to write. */
5232 set_iterator_to_next (it
, reseat_p
)
5236 /* Reset flags indicating start and end of a sequence of characters
5237 with box. Reset them at the start of this function because
5238 moving the iterator to a new position might set them. */
5239 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5241 if (it
->method
== next_element_from_buffer
)
5243 /* The current display element of IT is a character from
5244 current_buffer. Advance in the buffer, and maybe skip over
5245 invisible lines that are so because of selective display. */
5246 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5247 reseat_at_next_visible_line_start (it
, 0);
5250 xassert (it
->len
!= 0);
5251 IT_BYTEPOS (*it
) += it
->len
;
5252 IT_CHARPOS (*it
) += 1;
5253 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5256 else if (it
->method
== next_element_from_composition
)
5258 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5259 if (STRINGP (it
->string
))
5261 IT_STRING_BYTEPOS (*it
) += it
->len
;
5262 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5263 it
->method
= next_element_from_string
;
5264 goto consider_string_end
;
5268 IT_BYTEPOS (*it
) += it
->len
;
5269 IT_CHARPOS (*it
) += it
->cmp_len
;
5270 it
->method
= next_element_from_buffer
;
5273 else if (it
->method
== next_element_from_c_string
)
5275 /* Current display element of IT is from a C string. */
5276 IT_BYTEPOS (*it
) += it
->len
;
5277 IT_CHARPOS (*it
) += 1;
5279 else if (it
->method
== next_element_from_display_vector
)
5281 /* Current display element of IT is from a display table entry.
5282 Advance in the display table definition. Reset it to null if
5283 end reached, and continue with characters from buffers/
5285 ++it
->current
.dpvec_index
;
5287 /* Restore face of the iterator to what they were before the
5288 display vector entry (these entries may contain faces). */
5289 it
->face_id
= it
->saved_face_id
;
5291 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5294 it
->method
= next_element_from_c_string
;
5295 else if (STRINGP (it
->string
))
5296 it
->method
= next_element_from_string
;
5298 it
->method
= next_element_from_buffer
;
5301 it
->current
.dpvec_index
= -1;
5303 /* Skip over characters which were displayed via IT->dpvec. */
5304 if (it
->dpvec_char_len
< 0)
5305 reseat_at_next_visible_line_start (it
, 1);
5306 else if (it
->dpvec_char_len
> 0)
5308 it
->len
= it
->dpvec_char_len
;
5309 set_iterator_to_next (it
, reseat_p
);
5312 /* Recheck faces after display vector */
5313 it
->stop_charpos
= IT_CHARPOS (*it
);
5316 else if (it
->method
== next_element_from_string
)
5318 /* Current display element is a character from a Lisp string. */
5319 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5320 IT_STRING_BYTEPOS (*it
) += it
->len
;
5321 IT_STRING_CHARPOS (*it
) += 1;
5323 consider_string_end
:
5325 if (it
->current
.overlay_string_index
>= 0)
5327 /* IT->string is an overlay string. Advance to the
5328 next, if there is one. */
5329 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5330 next_overlay_string (it
);
5334 /* IT->string is not an overlay string. If we reached
5335 its end, and there is something on IT->stack, proceed
5336 with what is on the stack. This can be either another
5337 string, this time an overlay string, or a buffer. */
5338 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5342 if (!STRINGP (it
->string
))
5343 it
->method
= next_element_from_buffer
;
5345 goto consider_string_end
;
5349 else if (it
->method
== next_element_from_image
5350 || it
->method
== next_element_from_stretch
)
5352 /* The position etc with which we have to proceed are on
5353 the stack. The position may be at the end of a string,
5354 if the `display' property takes up the whole string. */
5357 if (STRINGP (it
->string
))
5359 it
->method
= next_element_from_string
;
5360 goto consider_string_end
;
5363 it
->method
= next_element_from_buffer
;
5366 /* There are no other methods defined, so this should be a bug. */
5369 xassert (it
->method
!= next_element_from_string
5370 || (STRINGP (it
->string
)
5371 && IT_STRING_CHARPOS (*it
) >= 0));
5374 /* Load IT's display element fields with information about the next
5375 display element which comes from a display table entry or from the
5376 result of translating a control character to one of the forms `^C'
5379 IT->dpvec holds the glyphs to return as characters.
5380 IT->saved_face_id holds the face id before the display vector--
5381 it is restored into IT->face_idin set_iterator_to_next. */
5384 next_element_from_display_vector (it
)
5388 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5390 if (INTEGERP (*it
->dpvec
)
5391 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5395 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5396 it
->c
= FAST_GLYPH_CHAR (g
);
5397 it
->len
= CHAR_BYTES (it
->c
);
5399 /* The entry may contain a face id to use. Such a face id is
5400 the id of a Lisp face, not a realized face. A face id of
5401 zero means no face is specified. */
5402 if (it
->dpvec_face_id
>= 0)
5403 it
->face_id
= it
->dpvec_face_id
;
5406 int lface_id
= FAST_GLYPH_FACE (g
);
5408 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5413 /* Display table entry is invalid. Return a space. */
5414 it
->c
= ' ', it
->len
= 1;
5416 /* Don't change position and object of the iterator here. They are
5417 still the values of the character that had this display table
5418 entry or was translated, and that's what we want. */
5419 it
->what
= IT_CHARACTER
;
5424 /* Load IT with the next display element from Lisp string IT->string.
5425 IT->current.string_pos is the current position within the string.
5426 If IT->current.overlay_string_index >= 0, the Lisp string is an
5430 next_element_from_string (it
)
5433 struct text_pos position
;
5435 xassert (STRINGP (it
->string
));
5436 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5437 position
= it
->current
.string_pos
;
5439 /* Time to check for invisible text? */
5440 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5441 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5445 /* Since a handler may have changed IT->method, we must
5447 return get_next_display_element (it
);
5450 if (it
->current
.overlay_string_index
>= 0)
5452 /* Get the next character from an overlay string. In overlay
5453 strings, There is no field width or padding with spaces to
5455 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5460 else if (STRING_MULTIBYTE (it
->string
))
5462 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5463 const unsigned char *s
= (SDATA (it
->string
)
5464 + IT_STRING_BYTEPOS (*it
));
5465 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5469 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5475 /* Get the next character from a Lisp string that is not an
5476 overlay string. Such strings come from the mode line, for
5477 example. We may have to pad with spaces, or truncate the
5478 string. See also next_element_from_c_string. */
5479 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5484 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5486 /* Pad with spaces. */
5487 it
->c
= ' ', it
->len
= 1;
5488 CHARPOS (position
) = BYTEPOS (position
) = -1;
5490 else if (STRING_MULTIBYTE (it
->string
))
5492 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5493 const unsigned char *s
= (SDATA (it
->string
)
5494 + IT_STRING_BYTEPOS (*it
));
5495 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5499 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5504 /* Record what we have and where it came from. Note that we store a
5505 buffer position in IT->position although it could arguably be a
5507 it
->what
= IT_CHARACTER
;
5508 it
->object
= it
->string
;
5509 it
->position
= position
;
5514 /* Load IT with next display element from C string IT->s.
5515 IT->string_nchars is the maximum number of characters to return
5516 from the string. IT->end_charpos may be greater than
5517 IT->string_nchars when this function is called, in which case we
5518 may have to return padding spaces. Value is zero if end of string
5519 reached, including padding spaces. */
5522 next_element_from_c_string (it
)
5528 it
->what
= IT_CHARACTER
;
5529 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5532 /* IT's position can be greater IT->string_nchars in case a field
5533 width or precision has been specified when the iterator was
5535 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5537 /* End of the game. */
5541 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5543 /* Pad with spaces. */
5544 it
->c
= ' ', it
->len
= 1;
5545 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5547 else if (it
->multibyte_p
)
5549 /* Implementation note: The calls to strlen apparently aren't a
5550 performance problem because there is no noticeable performance
5551 difference between Emacs running in unibyte or multibyte mode. */
5552 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5553 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5557 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5563 /* Set up IT to return characters from an ellipsis, if appropriate.
5564 The definition of the ellipsis glyphs may come from a display table
5565 entry. This function Fills IT with the first glyph from the
5566 ellipsis if an ellipsis is to be displayed. */
5569 next_element_from_ellipsis (it
)
5572 if (it
->selective_display_ellipsis_p
)
5573 setup_for_ellipsis (it
, it
->len
);
5576 /* The face at the current position may be different from the
5577 face we find after the invisible text. Remember what it
5578 was in IT->saved_face_id, and signal that it's there by
5579 setting face_before_selective_p. */
5580 it
->saved_face_id
= it
->face_id
;
5581 it
->method
= next_element_from_buffer
;
5582 reseat_at_next_visible_line_start (it
, 1);
5583 it
->face_before_selective_p
= 1;
5586 return get_next_display_element (it
);
5590 /* Deliver an image display element. The iterator IT is already
5591 filled with image information (done in handle_display_prop). Value
5596 next_element_from_image (it
)
5599 it
->what
= IT_IMAGE
;
5604 /* Fill iterator IT with next display element from a stretch glyph
5605 property. IT->object is the value of the text property. Value is
5609 next_element_from_stretch (it
)
5612 it
->what
= IT_STRETCH
;
5617 /* Load IT with the next display element from current_buffer. Value
5618 is zero if end of buffer reached. IT->stop_charpos is the next
5619 position at which to stop and check for text properties or buffer
5623 next_element_from_buffer (it
)
5628 /* Check this assumption, otherwise, we would never enter the
5629 if-statement, below. */
5630 xassert (IT_CHARPOS (*it
) >= BEGV
5631 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5633 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5635 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5637 int overlay_strings_follow_p
;
5639 /* End of the game, except when overlay strings follow that
5640 haven't been returned yet. */
5641 if (it
->overlay_strings_at_end_processed_p
)
5642 overlay_strings_follow_p
= 0;
5645 it
->overlay_strings_at_end_processed_p
= 1;
5646 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5649 if (overlay_strings_follow_p
)
5650 success_p
= get_next_display_element (it
);
5654 it
->position
= it
->current
.pos
;
5661 return get_next_display_element (it
);
5666 /* No face changes, overlays etc. in sight, so just return a
5667 character from current_buffer. */
5670 /* Maybe run the redisplay end trigger hook. Performance note:
5671 This doesn't seem to cost measurable time. */
5672 if (it
->redisplay_end_trigger_charpos
5674 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5675 run_redisplay_end_trigger_hook (it
);
5677 /* Get the next character, maybe multibyte. */
5678 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5679 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5681 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5682 - IT_BYTEPOS (*it
));
5683 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5686 it
->c
= *p
, it
->len
= 1;
5688 /* Record what we have and where it came from. */
5689 it
->what
= IT_CHARACTER
;;
5690 it
->object
= it
->w
->buffer
;
5691 it
->position
= it
->current
.pos
;
5693 /* Normally we return the character found above, except when we
5694 really want to return an ellipsis for selective display. */
5699 /* A value of selective > 0 means hide lines indented more
5700 than that number of columns. */
5701 if (it
->selective
> 0
5702 && IT_CHARPOS (*it
) + 1 < ZV
5703 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5704 IT_BYTEPOS (*it
) + 1,
5705 (double) it
->selective
)) /* iftc */
5707 success_p
= next_element_from_ellipsis (it
);
5708 it
->dpvec_char_len
= -1;
5711 else if (it
->c
== '\r' && it
->selective
== -1)
5713 /* A value of selective == -1 means that everything from the
5714 CR to the end of the line is invisible, with maybe an
5715 ellipsis displayed for it. */
5716 success_p
= next_element_from_ellipsis (it
);
5717 it
->dpvec_char_len
= -1;
5722 /* Value is zero if end of buffer reached. */
5723 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5728 /* Run the redisplay end trigger hook for IT. */
5731 run_redisplay_end_trigger_hook (it
)
5734 Lisp_Object args
[3];
5736 /* IT->glyph_row should be non-null, i.e. we should be actually
5737 displaying something, or otherwise we should not run the hook. */
5738 xassert (it
->glyph_row
);
5740 /* Set up hook arguments. */
5741 args
[0] = Qredisplay_end_trigger_functions
;
5742 args
[1] = it
->window
;
5743 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5744 it
->redisplay_end_trigger_charpos
= 0;
5746 /* Since we are *trying* to run these functions, don't try to run
5747 them again, even if they get an error. */
5748 it
->w
->redisplay_end_trigger
= Qnil
;
5749 Frun_hook_with_args (3, args
);
5751 /* Notice if it changed the face of the character we are on. */
5752 handle_face_prop (it
);
5756 /* Deliver a composition display element. The iterator IT is already
5757 filled with composition information (done in
5758 handle_composition_prop). Value is always 1. */
5761 next_element_from_composition (it
)
5764 it
->what
= IT_COMPOSITION
;
5765 it
->position
= (STRINGP (it
->string
)
5766 ? it
->current
.string_pos
5773 /***********************************************************************
5774 Moving an iterator without producing glyphs
5775 ***********************************************************************/
5777 /* Move iterator IT to a specified buffer or X position within one
5778 line on the display without producing glyphs.
5780 OP should be a bit mask including some or all of these bits:
5781 MOVE_TO_X: Stop on reaching x-position TO_X.
5782 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5783 Regardless of OP's value, stop in reaching the end of the display line.
5785 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5786 This means, in particular, that TO_X includes window's horizontal
5789 The return value has several possible values that
5790 say what condition caused the scan to stop:
5792 MOVE_POS_MATCH_OR_ZV
5793 - when TO_POS or ZV was reached.
5796 -when TO_X was reached before TO_POS or ZV were reached.
5799 - when we reached the end of the display area and the line must
5803 - when we reached the end of the display area and the line is
5807 - when we stopped at a line end, i.e. a newline or a CR and selective
5810 static enum move_it_result
5811 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5813 int to_charpos
, to_x
, op
;
5815 enum move_it_result result
= MOVE_UNDEFINED
;
5816 struct glyph_row
*saved_glyph_row
;
5818 /* Don't produce glyphs in produce_glyphs. */
5819 saved_glyph_row
= it
->glyph_row
;
5820 it
->glyph_row
= NULL
;
5822 #define BUFFER_POS_REACHED_P() \
5823 ((op & MOVE_TO_POS) != 0 \
5824 && BUFFERP (it->object) \
5825 && IT_CHARPOS (*it) >= to_charpos \
5826 && it->method == next_element_from_buffer)
5830 int x
, i
, ascent
= 0, descent
= 0;
5832 /* Stop when ZV reached.
5833 We used to stop here when TO_CHARPOS reached as well, but that is
5834 too soon if this glyph does not fit on this line. So we handle it
5835 explicitly below. */
5836 if (!get_next_display_element (it
)
5837 || (it
->truncate_lines_p
5838 && BUFFER_POS_REACHED_P ()))
5840 result
= MOVE_POS_MATCH_OR_ZV
;
5844 /* The call to produce_glyphs will get the metrics of the
5845 display element IT is loaded with. We record in x the
5846 x-position before this display element in case it does not
5850 /* Remember the line height so far in case the next element doesn't
5852 if (!it
->truncate_lines_p
)
5854 ascent
= it
->max_ascent
;
5855 descent
= it
->max_descent
;
5858 PRODUCE_GLYPHS (it
);
5860 if (it
->area
!= TEXT_AREA
)
5862 set_iterator_to_next (it
, 1);
5866 /* The number of glyphs we get back in IT->nglyphs will normally
5867 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5868 character on a terminal frame, or (iii) a line end. For the
5869 second case, IT->nglyphs - 1 padding glyphs will be present
5870 (on X frames, there is only one glyph produced for a
5871 composite character.
5873 The behavior implemented below means, for continuation lines,
5874 that as many spaces of a TAB as fit on the current line are
5875 displayed there. For terminal frames, as many glyphs of a
5876 multi-glyph character are displayed in the current line, too.
5877 This is what the old redisplay code did, and we keep it that
5878 way. Under X, the whole shape of a complex character must
5879 fit on the line or it will be completely displayed in the
5882 Note that both for tabs and padding glyphs, all glyphs have
5886 /* More than one glyph or glyph doesn't fit on line. All
5887 glyphs have the same width. */
5888 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5891 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5893 new_x
= x
+ single_glyph_width
;
5895 /* We want to leave anything reaching TO_X to the caller. */
5896 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5898 if (BUFFER_POS_REACHED_P ())
5899 goto buffer_pos_reached
;
5901 result
= MOVE_X_REACHED
;
5904 else if (/* Lines are continued. */
5905 !it
->truncate_lines_p
5906 && (/* And glyph doesn't fit on the line. */
5907 new_x
> it
->last_visible_x
5908 /* Or it fits exactly and we're on a window
5910 || (new_x
== it
->last_visible_x
5911 && FRAME_WINDOW_P (it
->f
))))
5913 if (/* IT->hpos == 0 means the very first glyph
5914 doesn't fit on the line, e.g. a wide image. */
5916 || (new_x
== it
->last_visible_x
5917 && FRAME_WINDOW_P (it
->f
)))
5920 it
->current_x
= new_x
;
5921 if (i
== it
->nglyphs
- 1)
5923 set_iterator_to_next (it
, 1);
5924 #ifdef HAVE_WINDOW_SYSTEM
5925 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5927 if (!get_next_display_element (it
))
5929 result
= MOVE_POS_MATCH_OR_ZV
;
5932 if (BUFFER_POS_REACHED_P ())
5934 if (ITERATOR_AT_END_OF_LINE_P (it
))
5935 result
= MOVE_POS_MATCH_OR_ZV
;
5937 result
= MOVE_LINE_CONTINUED
;
5940 if (ITERATOR_AT_END_OF_LINE_P (it
))
5942 result
= MOVE_NEWLINE_OR_CR
;
5946 #endif /* HAVE_WINDOW_SYSTEM */
5952 it
->max_ascent
= ascent
;
5953 it
->max_descent
= descent
;
5956 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5958 result
= MOVE_LINE_CONTINUED
;
5961 else if (BUFFER_POS_REACHED_P ())
5962 goto buffer_pos_reached
;
5963 else if (new_x
> it
->first_visible_x
)
5965 /* Glyph is visible. Increment number of glyphs that
5966 would be displayed. */
5971 /* Glyph is completely off the left margin of the display
5972 area. Nothing to do. */
5976 if (result
!= MOVE_UNDEFINED
)
5979 else if (BUFFER_POS_REACHED_P ())
5983 it
->max_ascent
= ascent
;
5984 it
->max_descent
= descent
;
5985 result
= MOVE_POS_MATCH_OR_ZV
;
5988 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5990 /* Stop when TO_X specified and reached. This check is
5991 necessary here because of lines consisting of a line end,
5992 only. The line end will not produce any glyphs and we
5993 would never get MOVE_X_REACHED. */
5994 xassert (it
->nglyphs
== 0);
5995 result
= MOVE_X_REACHED
;
5999 /* Is this a line end? If yes, we're done. */
6000 if (ITERATOR_AT_END_OF_LINE_P (it
))
6002 result
= MOVE_NEWLINE_OR_CR
;
6006 /* The current display element has been consumed. Advance
6008 set_iterator_to_next (it
, 1);
6010 /* Stop if lines are truncated and IT's current x-position is
6011 past the right edge of the window now. */
6012 if (it
->truncate_lines_p
6013 && it
->current_x
>= it
->last_visible_x
)
6015 #ifdef HAVE_WINDOW_SYSTEM
6016 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6018 if (!get_next_display_element (it
)
6019 || BUFFER_POS_REACHED_P ())
6021 result
= MOVE_POS_MATCH_OR_ZV
;
6024 if (ITERATOR_AT_END_OF_LINE_P (it
))
6026 result
= MOVE_NEWLINE_OR_CR
;
6030 #endif /* HAVE_WINDOW_SYSTEM */
6031 result
= MOVE_LINE_TRUNCATED
;
6036 #undef BUFFER_POS_REACHED_P
6038 /* Restore the iterator settings altered at the beginning of this
6040 it
->glyph_row
= saved_glyph_row
;
6045 /* Move IT forward until it satisfies one or more of the criteria in
6046 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6048 OP is a bit-mask that specifies where to stop, and in particular,
6049 which of those four position arguments makes a difference. See the
6050 description of enum move_operation_enum.
6052 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6053 screen line, this function will set IT to the next position >
6057 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6059 int to_charpos
, to_x
, to_y
, to_vpos
;
6062 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6068 if (op
& MOVE_TO_VPOS
)
6070 /* If no TO_CHARPOS and no TO_X specified, stop at the
6071 start of the line TO_VPOS. */
6072 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6074 if (it
->vpos
== to_vpos
)
6080 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6084 /* TO_VPOS >= 0 means stop at TO_X in the line at
6085 TO_VPOS, or at TO_POS, whichever comes first. */
6086 if (it
->vpos
== to_vpos
)
6092 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6094 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6099 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6101 /* We have reached TO_X but not in the line we want. */
6102 skip
= move_it_in_display_line_to (it
, to_charpos
,
6104 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6112 else if (op
& MOVE_TO_Y
)
6114 struct it it_backup
;
6116 /* TO_Y specified means stop at TO_X in the line containing
6117 TO_Y---or at TO_CHARPOS if this is reached first. The
6118 problem is that we can't really tell whether the line
6119 contains TO_Y before we have completely scanned it, and
6120 this may skip past TO_X. What we do is to first scan to
6123 If TO_X is not specified, use a TO_X of zero. The reason
6124 is to make the outcome of this function more predictable.
6125 If we didn't use TO_X == 0, we would stop at the end of
6126 the line which is probably not what a caller would expect
6128 skip
= move_it_in_display_line_to (it
, to_charpos
,
6132 | (op
& MOVE_TO_POS
)));
6134 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6135 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6141 /* If TO_X was reached, we would like to know whether TO_Y
6142 is in the line. This can only be said if we know the
6143 total line height which requires us to scan the rest of
6145 if (skip
== MOVE_X_REACHED
)
6148 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6149 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6151 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6154 /* Now, decide whether TO_Y is in this line. */
6155 line_height
= it
->max_ascent
+ it
->max_descent
;
6156 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6158 if (to_y
>= it
->current_y
6159 && to_y
< it
->current_y
+ line_height
)
6161 if (skip
== MOVE_X_REACHED
)
6162 /* If TO_Y is in this line and TO_X was reached above,
6163 we scanned too far. We have to restore IT's settings
6164 to the ones before skipping. */
6168 else if (skip
== MOVE_X_REACHED
)
6171 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6179 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6183 case MOVE_POS_MATCH_OR_ZV
:
6187 case MOVE_NEWLINE_OR_CR
:
6188 set_iterator_to_next (it
, 1);
6189 it
->continuation_lines_width
= 0;
6192 case MOVE_LINE_TRUNCATED
:
6193 it
->continuation_lines_width
= 0;
6194 reseat_at_next_visible_line_start (it
, 0);
6195 if ((op
& MOVE_TO_POS
) != 0
6196 && IT_CHARPOS (*it
) > to_charpos
)
6203 case MOVE_LINE_CONTINUED
:
6204 it
->continuation_lines_width
+= it
->current_x
;
6211 /* Reset/increment for the next run. */
6212 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6213 it
->current_x
= it
->hpos
= 0;
6214 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6216 last_height
= it
->max_ascent
+ it
->max_descent
;
6217 last_max_ascent
= it
->max_ascent
;
6218 it
->max_ascent
= it
->max_descent
= 0;
6223 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6227 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6229 If DY > 0, move IT backward at least that many pixels. DY = 0
6230 means move IT backward to the preceding line start or BEGV. This
6231 function may move over more than DY pixels if IT->current_y - DY
6232 ends up in the middle of a line; in this case IT->current_y will be
6233 set to the top of the line moved to. */
6236 move_it_vertically_backward (it
, dy
)
6247 start_pos
= IT_CHARPOS (*it
);
6249 /* Estimate how many newlines we must move back. */
6250 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6252 /* Set the iterator's position that many lines back. */
6253 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6254 back_to_previous_visible_line_start (it
);
6256 /* Reseat the iterator here. When moving backward, we don't want
6257 reseat to skip forward over invisible text, set up the iterator
6258 to deliver from overlay strings at the new position etc. So,
6259 use reseat_1 here. */
6260 reseat_1 (it
, it
->current
.pos
, 1);
6262 /* We are now surely at a line start. */
6263 it
->current_x
= it
->hpos
= 0;
6264 it
->continuation_lines_width
= 0;
6266 /* Move forward and see what y-distance we moved. First move to the
6267 start of the next line so that we get its height. We need this
6268 height to be able to tell whether we reached the specified
6271 it2
.max_ascent
= it2
.max_descent
= 0;
6272 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6273 MOVE_TO_POS
| MOVE_TO_VPOS
);
6274 xassert (IT_CHARPOS (*it
) >= BEGV
);
6277 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6278 xassert (IT_CHARPOS (*it
) >= BEGV
);
6279 /* H is the actual vertical distance from the position in *IT
6280 and the starting position. */
6281 h
= it2
.current_y
- it
->current_y
;
6282 /* NLINES is the distance in number of lines. */
6283 nlines
= it2
.vpos
- it
->vpos
;
6285 /* Correct IT's y and vpos position
6286 so that they are relative to the starting point. */
6292 /* DY == 0 means move to the start of the screen line. The
6293 value of nlines is > 0 if continuation lines were involved. */
6295 move_it_by_lines (it
, nlines
, 1);
6296 xassert (IT_CHARPOS (*it
) <= start_pos
);
6300 /* The y-position we try to reach, relative to *IT.
6301 Note that H has been subtracted in front of the if-statement. */
6302 int target_y
= it
->current_y
+ h
- dy
;
6303 int y0
= it3
.current_y
;
6304 int y1
= line_bottom_y (&it3
);
6305 int line_height
= y1
- y0
;
6307 /* If we did not reach target_y, try to move further backward if
6308 we can. If we moved too far backward, try to move forward. */
6309 if (target_y
< it
->current_y
6310 /* This is heuristic. In a window that's 3 lines high, with
6311 a line height of 13 pixels each, recentering with point
6312 on the bottom line will try to move -39/2 = 19 pixels
6313 backward. Try to avoid moving into the first line. */
6314 && it
->current_y
- target_y
> line_height
* 2 / 3
6315 && IT_CHARPOS (*it
) > BEGV
)
6317 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6318 target_y
- it
->current_y
));
6319 dy
= it
->current_y
- target_y
;
6320 goto move_further_back
;
6322 else if (target_y
>= it
->current_y
+ line_height
6323 && IT_CHARPOS (*it
) < ZV
)
6325 /* Should move forward by at least one line, maybe more.
6327 Note: Calling move_it_by_lines can be expensive on
6328 terminal frames, where compute_motion is used (via
6329 vmotion) to do the job, when there are very long lines
6330 and truncate-lines is nil. That's the reason for
6331 treating terminal frames specially here. */
6333 if (!FRAME_WINDOW_P (it
->f
))
6334 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6339 move_it_by_lines (it
, 1, 1);
6341 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6344 xassert (IT_CHARPOS (*it
) >= BEGV
);
6350 /* Move IT by a specified amount of pixel lines DY. DY negative means
6351 move backwards. DY = 0 means move to start of screen line. At the
6352 end, IT will be on the start of a screen line. */
6355 move_it_vertically (it
, dy
)
6360 move_it_vertically_backward (it
, -dy
);
6363 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6364 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6365 MOVE_TO_POS
| MOVE_TO_Y
);
6366 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6368 /* If buffer ends in ZV without a newline, move to the start of
6369 the line to satisfy the post-condition. */
6370 if (IT_CHARPOS (*it
) == ZV
6371 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6372 move_it_by_lines (it
, 0, 0);
6377 /* Move iterator IT past the end of the text line it is in. */
6380 move_it_past_eol (it
)
6383 enum move_it_result rc
;
6385 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6386 if (rc
== MOVE_NEWLINE_OR_CR
)
6387 set_iterator_to_next (it
, 0);
6391 #if 0 /* Currently not used. */
6393 /* Return non-zero if some text between buffer positions START_CHARPOS
6394 and END_CHARPOS is invisible. IT->window is the window for text
6398 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6400 int start_charpos
, end_charpos
;
6402 Lisp_Object prop
, limit
;
6403 int invisible_found_p
;
6405 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6407 /* Is text at START invisible? */
6408 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6410 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6411 invisible_found_p
= 1;
6414 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6416 make_number (end_charpos
));
6417 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6420 return invisible_found_p
;
6426 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6427 negative means move up. DVPOS == 0 means move to the start of the
6428 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6429 NEED_Y_P is zero, IT->current_y will be left unchanged.
6431 Further optimization ideas: If we would know that IT->f doesn't use
6432 a face with proportional font, we could be faster for
6433 truncate-lines nil. */
6436 move_it_by_lines (it
, dvpos
, need_y_p
)
6438 int dvpos
, need_y_p
;
6440 struct position pos
;
6442 if (!FRAME_WINDOW_P (it
->f
))
6444 struct text_pos textpos
;
6446 /* We can use vmotion on frames without proportional fonts. */
6447 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6448 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6449 reseat (it
, textpos
, 1);
6450 it
->vpos
+= pos
.vpos
;
6451 it
->current_y
+= pos
.vpos
;
6453 else if (dvpos
== 0)
6455 /* DVPOS == 0 means move to the start of the screen line. */
6456 move_it_vertically_backward (it
, 0);
6457 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6458 /* Let next call to line_bottom_y calculate real line height */
6462 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6466 int start_charpos
, i
;
6468 /* Start at the beginning of the screen line containing IT's
6470 move_it_vertically_backward (it
, 0);
6472 /* Go back -DVPOS visible lines and reseat the iterator there. */
6473 start_charpos
= IT_CHARPOS (*it
);
6474 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6475 back_to_previous_visible_line_start (it
);
6476 reseat (it
, it
->current
.pos
, 1);
6477 it
->current_x
= it
->hpos
= 0;
6479 /* Above call may have moved too far if continuation lines
6480 are involved. Scan forward and see if it did. */
6482 it2
.vpos
= it2
.current_y
= 0;
6483 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6484 it
->vpos
-= it2
.vpos
;
6485 it
->current_y
-= it2
.current_y
;
6486 it
->current_x
= it
->hpos
= 0;
6488 /* If we moved too far back, move IT some lines forward. */
6489 if (it2
.vpos
> -dvpos
)
6491 int delta
= it2
.vpos
+ dvpos
;
6493 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6494 /* Move back again if we got too far ahead. */
6495 if (IT_CHARPOS (*it
) >= start_charpos
)
6501 /* Return 1 if IT points into the middle of a display vector. */
6504 in_display_vector_p (it
)
6507 return (it
->method
== next_element_from_display_vector
6508 && it
->current
.dpvec_index
> 0
6509 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6513 /***********************************************************************
6515 ***********************************************************************/
6518 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6522 add_to_log (format
, arg1
, arg2
)
6524 Lisp_Object arg1
, arg2
;
6526 Lisp_Object args
[3];
6527 Lisp_Object msg
, fmt
;
6530 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6533 /* Do nothing if called asynchronously. Inserting text into
6534 a buffer may call after-change-functions and alike and
6535 that would means running Lisp asynchronously. */
6536 if (handling_signal
)
6540 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6542 args
[0] = fmt
= build_string (format
);
6545 msg
= Fformat (3, args
);
6547 len
= SBYTES (msg
) + 1;
6548 SAFE_ALLOCA (buffer
, char *, len
);
6549 bcopy (SDATA (msg
), buffer
, len
);
6551 message_dolog (buffer
, len
- 1, 1, 0);
6558 /* Output a newline in the *Messages* buffer if "needs" one. */
6561 message_log_maybe_newline ()
6563 if (message_log_need_newline
)
6564 message_dolog ("", 0, 1, 0);
6568 /* Add a string M of length NBYTES to the message log, optionally
6569 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6570 nonzero, means interpret the contents of M as multibyte. This
6571 function calls low-level routines in order to bypass text property
6572 hooks, etc. which might not be safe to run. */
6575 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6577 int nbytes
, nlflag
, multibyte
;
6579 if (!NILP (Vmemory_full
))
6582 if (!NILP (Vmessage_log_max
))
6584 struct buffer
*oldbuf
;
6585 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6586 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6587 int point_at_end
= 0;
6589 Lisp_Object old_deactivate_mark
, tem
;
6590 struct gcpro gcpro1
;
6592 old_deactivate_mark
= Vdeactivate_mark
;
6593 oldbuf
= current_buffer
;
6594 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6595 current_buffer
->undo_list
= Qt
;
6597 oldpoint
= message_dolog_marker1
;
6598 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6599 oldbegv
= message_dolog_marker2
;
6600 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6601 oldzv
= message_dolog_marker3
;
6602 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6603 GCPRO1 (old_deactivate_mark
);
6611 BEGV_BYTE
= BEG_BYTE
;
6614 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6616 /* Insert the string--maybe converting multibyte to single byte
6617 or vice versa, so that all the text fits the buffer. */
6619 && NILP (current_buffer
->enable_multibyte_characters
))
6621 int i
, c
, char_bytes
;
6622 unsigned char work
[1];
6624 /* Convert a multibyte string to single-byte
6625 for the *Message* buffer. */
6626 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6628 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6629 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6631 : multibyte_char_to_unibyte (c
, Qnil
));
6632 insert_1_both (work
, 1, 1, 1, 0, 0);
6635 else if (! multibyte
6636 && ! NILP (current_buffer
->enable_multibyte_characters
))
6638 int i
, c
, char_bytes
;
6639 unsigned char *msg
= (unsigned char *) m
;
6640 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6641 /* Convert a single-byte string to multibyte
6642 for the *Message* buffer. */
6643 for (i
= 0; i
< nbytes
; i
++)
6645 c
= unibyte_char_to_multibyte (msg
[i
]);
6646 char_bytes
= CHAR_STRING (c
, str
);
6647 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6651 insert_1 (m
, nbytes
, 1, 0, 0);
6655 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6656 insert_1 ("\n", 1, 1, 0, 0);
6658 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6660 this_bol_byte
= PT_BYTE
;
6662 /* See if this line duplicates the previous one.
6663 If so, combine duplicates. */
6666 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6668 prev_bol_byte
= PT_BYTE
;
6670 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6671 this_bol
, this_bol_byte
);
6674 del_range_both (prev_bol
, prev_bol_byte
,
6675 this_bol
, this_bol_byte
, 0);
6681 /* If you change this format, don't forget to also
6682 change message_log_check_duplicate. */
6683 sprintf (dupstr
, " [%d times]", dup
);
6684 duplen
= strlen (dupstr
);
6685 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6686 insert_1 (dupstr
, duplen
, 1, 0, 1);
6691 /* If we have more than the desired maximum number of lines
6692 in the *Messages* buffer now, delete the oldest ones.
6693 This is safe because we don't have undo in this buffer. */
6695 if (NATNUMP (Vmessage_log_max
))
6697 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6698 -XFASTINT (Vmessage_log_max
) - 1, 0);
6699 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6702 BEGV
= XMARKER (oldbegv
)->charpos
;
6703 BEGV_BYTE
= marker_byte_position (oldbegv
);
6712 ZV
= XMARKER (oldzv
)->charpos
;
6713 ZV_BYTE
= marker_byte_position (oldzv
);
6717 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6719 /* We can't do Fgoto_char (oldpoint) because it will run some
6721 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6722 XMARKER (oldpoint
)->bytepos
);
6725 unchain_marker (XMARKER (oldpoint
));
6726 unchain_marker (XMARKER (oldbegv
));
6727 unchain_marker (XMARKER (oldzv
));
6729 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6730 set_buffer_internal (oldbuf
);
6732 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6733 message_log_need_newline
= !nlflag
;
6734 Vdeactivate_mark
= old_deactivate_mark
;
6739 /* We are at the end of the buffer after just having inserted a newline.
6740 (Note: We depend on the fact we won't be crossing the gap.)
6741 Check to see if the most recent message looks a lot like the previous one.
6742 Return 0 if different, 1 if the new one should just replace it, or a
6743 value N > 1 if we should also append " [N times]". */
6746 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6747 int prev_bol
, this_bol
;
6748 int prev_bol_byte
, this_bol_byte
;
6751 int len
= Z_BYTE
- 1 - this_bol_byte
;
6753 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6754 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6756 for (i
= 0; i
< len
; i
++)
6758 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6766 if (*p1
++ == ' ' && *p1
++ == '[')
6769 while (*p1
>= '0' && *p1
<= '9')
6770 n
= n
* 10 + *p1
++ - '0';
6771 if (strncmp (p1
, " times]\n", 8) == 0)
6778 /* Display an echo area message M with a specified length of NBYTES
6779 bytes. The string may include null characters. If M is 0, clear
6780 out any existing message, and let the mini-buffer text show
6783 The buffer M must continue to exist until after the echo area gets
6784 cleared or some other message gets displayed there. This means do
6785 not pass text that is stored in a Lisp string; do not pass text in
6786 a buffer that was alloca'd. */
6789 message2 (m
, nbytes
, multibyte
)
6794 /* First flush out any partial line written with print. */
6795 message_log_maybe_newline ();
6797 message_dolog (m
, nbytes
, 1, multibyte
);
6798 message2_nolog (m
, nbytes
, multibyte
);
6802 /* The non-logging counterpart of message2. */
6805 message2_nolog (m
, nbytes
, multibyte
)
6807 int nbytes
, multibyte
;
6809 struct frame
*sf
= SELECTED_FRAME ();
6810 message_enable_multibyte
= multibyte
;
6814 if (noninteractive_need_newline
)
6815 putc ('\n', stderr
);
6816 noninteractive_need_newline
= 0;
6818 fwrite (m
, nbytes
, 1, stderr
);
6819 if (cursor_in_echo_area
== 0)
6820 fprintf (stderr
, "\n");
6823 /* A null message buffer means that the frame hasn't really been
6824 initialized yet. Error messages get reported properly by
6825 cmd_error, so this must be just an informative message; toss it. */
6826 else if (INTERACTIVE
6827 && sf
->glyphs_initialized_p
6828 && FRAME_MESSAGE_BUF (sf
))
6830 Lisp_Object mini_window
;
6833 /* Get the frame containing the mini-buffer
6834 that the selected frame is using. */
6835 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6836 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6838 FRAME_SAMPLE_VISIBILITY (f
);
6839 if (FRAME_VISIBLE_P (sf
)
6840 && ! FRAME_VISIBLE_P (f
))
6841 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6845 set_message (m
, Qnil
, nbytes
, multibyte
);
6846 if (minibuffer_auto_raise
)
6847 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6850 clear_message (1, 1);
6852 do_pending_window_change (0);
6853 echo_area_display (1);
6854 do_pending_window_change (0);
6855 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6856 (*frame_up_to_date_hook
) (f
);
6861 /* Display an echo area message M with a specified length of NBYTES
6862 bytes. The string may include null characters. If M is not a
6863 string, clear out any existing message, and let the mini-buffer
6864 text show through. */
6867 message3 (m
, nbytes
, multibyte
)
6872 struct gcpro gcpro1
;
6875 clear_message (1,1);
6877 /* First flush out any partial line written with print. */
6878 message_log_maybe_newline ();
6880 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6881 message3_nolog (m
, nbytes
, multibyte
);
6887 /* The non-logging version of message3. */
6890 message3_nolog (m
, nbytes
, multibyte
)
6892 int nbytes
, multibyte
;
6894 struct frame
*sf
= SELECTED_FRAME ();
6895 message_enable_multibyte
= multibyte
;
6899 if (noninteractive_need_newline
)
6900 putc ('\n', stderr
);
6901 noninteractive_need_newline
= 0;
6903 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6904 if (cursor_in_echo_area
== 0)
6905 fprintf (stderr
, "\n");
6908 /* A null message buffer means that the frame hasn't really been
6909 initialized yet. Error messages get reported properly by
6910 cmd_error, so this must be just an informative message; toss it. */
6911 else if (INTERACTIVE
6912 && sf
->glyphs_initialized_p
6913 && FRAME_MESSAGE_BUF (sf
))
6915 Lisp_Object mini_window
;
6919 /* Get the frame containing the mini-buffer
6920 that the selected frame is using. */
6921 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6922 frame
= XWINDOW (mini_window
)->frame
;
6925 FRAME_SAMPLE_VISIBILITY (f
);
6926 if (FRAME_VISIBLE_P (sf
)
6927 && !FRAME_VISIBLE_P (f
))
6928 Fmake_frame_visible (frame
);
6930 if (STRINGP (m
) && SCHARS (m
) > 0)
6932 set_message (NULL
, m
, nbytes
, multibyte
);
6933 if (minibuffer_auto_raise
)
6934 Fraise_frame (frame
);
6937 clear_message (1, 1);
6939 do_pending_window_change (0);
6940 echo_area_display (1);
6941 do_pending_window_change (0);
6942 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6943 (*frame_up_to_date_hook
) (f
);
6948 /* Display a null-terminated echo area message M. If M is 0, clear
6949 out any existing message, and let the mini-buffer text show through.
6951 The buffer M must continue to exist until after the echo area gets
6952 cleared or some other message gets displayed there. Do not pass
6953 text that is stored in a Lisp string. Do not pass text in a buffer
6954 that was alloca'd. */
6960 message2 (m
, (m
? strlen (m
) : 0), 0);
6964 /* The non-logging counterpart of message1. */
6970 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6973 /* Display a message M which contains a single %s
6974 which gets replaced with STRING. */
6977 message_with_string (m
, string
, log
)
6982 CHECK_STRING (string
);
6988 if (noninteractive_need_newline
)
6989 putc ('\n', stderr
);
6990 noninteractive_need_newline
= 0;
6991 fprintf (stderr
, m
, SDATA (string
));
6992 if (cursor_in_echo_area
== 0)
6993 fprintf (stderr
, "\n");
6997 else if (INTERACTIVE
)
6999 /* The frame whose minibuffer we're going to display the message on.
7000 It may be larger than the selected frame, so we need
7001 to use its buffer, not the selected frame's buffer. */
7002 Lisp_Object mini_window
;
7003 struct frame
*f
, *sf
= SELECTED_FRAME ();
7005 /* Get the frame containing the minibuffer
7006 that the selected frame is using. */
7007 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7008 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7010 /* A null message buffer means that the frame hasn't really been
7011 initialized yet. Error messages get reported properly by
7012 cmd_error, so this must be just an informative message; toss it. */
7013 if (FRAME_MESSAGE_BUF (f
))
7015 Lisp_Object args
[2], message
;
7016 struct gcpro gcpro1
, gcpro2
;
7018 args
[0] = build_string (m
);
7019 args
[1] = message
= string
;
7020 GCPRO2 (args
[0], message
);
7023 message
= Fformat (2, args
);
7026 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7028 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7032 /* Print should start at the beginning of the message
7033 buffer next time. */
7034 message_buf_print
= 0;
7040 /* Dump an informative message to the minibuf. If M is 0, clear out
7041 any existing message, and let the mini-buffer text show through. */
7045 message (m
, a1
, a2
, a3
)
7047 EMACS_INT a1
, a2
, a3
;
7053 if (noninteractive_need_newline
)
7054 putc ('\n', stderr
);
7055 noninteractive_need_newline
= 0;
7056 fprintf (stderr
, m
, a1
, a2
, a3
);
7057 if (cursor_in_echo_area
== 0)
7058 fprintf (stderr
, "\n");
7062 else if (INTERACTIVE
)
7064 /* The frame whose mini-buffer we're going to display the message
7065 on. It may be larger than the selected frame, so we need to
7066 use its buffer, not the selected frame's buffer. */
7067 Lisp_Object mini_window
;
7068 struct frame
*f
, *sf
= SELECTED_FRAME ();
7070 /* Get the frame containing the mini-buffer
7071 that the selected frame is using. */
7072 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7073 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7075 /* A null message buffer means that the frame hasn't really been
7076 initialized yet. Error messages get reported properly by
7077 cmd_error, so this must be just an informative message; toss
7079 if (FRAME_MESSAGE_BUF (f
))
7090 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7091 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7093 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7094 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7096 #endif /* NO_ARG_ARRAY */
7098 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7103 /* Print should start at the beginning of the message
7104 buffer next time. */
7105 message_buf_print
= 0;
7111 /* The non-logging version of message. */
7114 message_nolog (m
, a1
, a2
, a3
)
7116 EMACS_INT a1
, a2
, a3
;
7118 Lisp_Object old_log_max
;
7119 old_log_max
= Vmessage_log_max
;
7120 Vmessage_log_max
= Qnil
;
7121 message (m
, a1
, a2
, a3
);
7122 Vmessage_log_max
= old_log_max
;
7126 /* Display the current message in the current mini-buffer. This is
7127 only called from error handlers in process.c, and is not time
7133 if (!NILP (echo_area_buffer
[0]))
7136 string
= Fcurrent_message ();
7137 message3 (string
, SBYTES (string
),
7138 !NILP (current_buffer
->enable_multibyte_characters
));
7143 /* Make sure echo area buffers in `echo_buffers' are live.
7144 If they aren't, make new ones. */
7147 ensure_echo_area_buffers ()
7151 for (i
= 0; i
< 2; ++i
)
7152 if (!BUFFERP (echo_buffer
[i
])
7153 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7156 Lisp_Object old_buffer
;
7159 old_buffer
= echo_buffer
[i
];
7160 sprintf (name
, " *Echo Area %d*", i
);
7161 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7162 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7164 for (j
= 0; j
< 2; ++j
)
7165 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7166 echo_area_buffer
[j
] = echo_buffer
[i
];
7171 /* Call FN with args A1..A4 with either the current or last displayed
7172 echo_area_buffer as current buffer.
7174 WHICH zero means use the current message buffer
7175 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7176 from echo_buffer[] and clear it.
7178 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7179 suitable buffer from echo_buffer[] and clear it.
7181 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7182 that the current message becomes the last displayed one, make
7183 choose a suitable buffer for echo_area_buffer[0], and clear it.
7185 Value is what FN returns. */
7188 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7191 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7197 int this_one
, the_other
, clear_buffer_p
, rc
;
7198 int count
= SPECPDL_INDEX ();
7200 /* If buffers aren't live, make new ones. */
7201 ensure_echo_area_buffers ();
7206 this_one
= 0, the_other
= 1;
7208 this_one
= 1, the_other
= 0;
7211 this_one
= 0, the_other
= 1;
7214 /* We need a fresh one in case the current echo buffer equals
7215 the one containing the last displayed echo area message. */
7216 if (!NILP (echo_area_buffer
[this_one
])
7217 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7218 echo_area_buffer
[this_one
] = Qnil
;
7221 /* Choose a suitable buffer from echo_buffer[] is we don't
7223 if (NILP (echo_area_buffer
[this_one
]))
7225 echo_area_buffer
[this_one
]
7226 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7227 ? echo_buffer
[the_other
]
7228 : echo_buffer
[this_one
]);
7232 buffer
= echo_area_buffer
[this_one
];
7234 /* Don't get confused by reusing the buffer used for echoing
7235 for a different purpose. */
7236 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7239 record_unwind_protect (unwind_with_echo_area_buffer
,
7240 with_echo_area_buffer_unwind_data (w
));
7242 /* Make the echo area buffer current. Note that for display
7243 purposes, it is not necessary that the displayed window's buffer
7244 == current_buffer, except for text property lookup. So, let's
7245 only set that buffer temporarily here without doing a full
7246 Fset_window_buffer. We must also change w->pointm, though,
7247 because otherwise an assertions in unshow_buffer fails, and Emacs
7249 set_buffer_internal_1 (XBUFFER (buffer
));
7253 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7256 current_buffer
->undo_list
= Qt
;
7257 current_buffer
->read_only
= Qnil
;
7258 specbind (Qinhibit_read_only
, Qt
);
7259 specbind (Qinhibit_modification_hooks
, Qt
);
7261 if (clear_buffer_p
&& Z
> BEG
)
7264 xassert (BEGV
>= BEG
);
7265 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7267 rc
= fn (a1
, a2
, a3
, a4
);
7269 xassert (BEGV
>= BEG
);
7270 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7272 unbind_to (count
, Qnil
);
7277 /* Save state that should be preserved around the call to the function
7278 FN called in with_echo_area_buffer. */
7281 with_echo_area_buffer_unwind_data (w
)
7287 /* Reduce consing by keeping one vector in
7288 Vwith_echo_area_save_vector. */
7289 vector
= Vwith_echo_area_save_vector
;
7290 Vwith_echo_area_save_vector
= Qnil
;
7293 vector
= Fmake_vector (make_number (7), Qnil
);
7295 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7296 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7297 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7301 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7302 AREF (vector
, i
) = w
->buffer
; ++i
;
7303 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7304 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7309 for (; i
< end
; ++i
)
7310 AREF (vector
, i
) = Qnil
;
7313 xassert (i
== ASIZE (vector
));
7318 /* Restore global state from VECTOR which was created by
7319 with_echo_area_buffer_unwind_data. */
7322 unwind_with_echo_area_buffer (vector
)
7325 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7326 Vdeactivate_mark
= AREF (vector
, 1);
7327 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7329 if (WINDOWP (AREF (vector
, 3)))
7332 Lisp_Object buffer
, charpos
, bytepos
;
7334 w
= XWINDOW (AREF (vector
, 3));
7335 buffer
= AREF (vector
, 4);
7336 charpos
= AREF (vector
, 5);
7337 bytepos
= AREF (vector
, 6);
7340 set_marker_both (w
->pointm
, buffer
,
7341 XFASTINT (charpos
), XFASTINT (bytepos
));
7344 Vwith_echo_area_save_vector
= vector
;
7349 /* Set up the echo area for use by print functions. MULTIBYTE_P
7350 non-zero means we will print multibyte. */
7353 setup_echo_area_for_printing (multibyte_p
)
7356 /* If we can't find an echo area any more, exit. */
7357 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7360 ensure_echo_area_buffers ();
7362 if (!message_buf_print
)
7364 /* A message has been output since the last time we printed.
7365 Choose a fresh echo area buffer. */
7366 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7367 echo_area_buffer
[0] = echo_buffer
[1];
7369 echo_area_buffer
[0] = echo_buffer
[0];
7371 /* Switch to that buffer and clear it. */
7372 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7373 current_buffer
->truncate_lines
= Qnil
;
7377 int count
= SPECPDL_INDEX ();
7378 specbind (Qinhibit_read_only
, Qt
);
7379 /* Note that undo recording is always disabled. */
7381 unbind_to (count
, Qnil
);
7383 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7385 /* Set up the buffer for the multibyteness we need. */
7387 != !NILP (current_buffer
->enable_multibyte_characters
))
7388 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7390 /* Raise the frame containing the echo area. */
7391 if (minibuffer_auto_raise
)
7393 struct frame
*sf
= SELECTED_FRAME ();
7394 Lisp_Object mini_window
;
7395 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7396 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7399 message_log_maybe_newline ();
7400 message_buf_print
= 1;
7404 if (NILP (echo_area_buffer
[0]))
7406 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7407 echo_area_buffer
[0] = echo_buffer
[1];
7409 echo_area_buffer
[0] = echo_buffer
[0];
7412 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7414 /* Someone switched buffers between print requests. */
7415 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7416 current_buffer
->truncate_lines
= Qnil
;
7422 /* Display an echo area message in window W. Value is non-zero if W's
7423 height is changed. If display_last_displayed_message_p is
7424 non-zero, display the message that was last displayed, otherwise
7425 display the current message. */
7428 display_echo_area (w
)
7431 int i
, no_message_p
, window_height_changed_p
, count
;
7433 /* Temporarily disable garbage collections while displaying the echo
7434 area. This is done because a GC can print a message itself.
7435 That message would modify the echo area buffer's contents while a
7436 redisplay of the buffer is going on, and seriously confuse
7438 count
= inhibit_garbage_collection ();
7440 /* If there is no message, we must call display_echo_area_1
7441 nevertheless because it resizes the window. But we will have to
7442 reset the echo_area_buffer in question to nil at the end because
7443 with_echo_area_buffer will sets it to an empty buffer. */
7444 i
= display_last_displayed_message_p
? 1 : 0;
7445 no_message_p
= NILP (echo_area_buffer
[i
]);
7447 window_height_changed_p
7448 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7449 display_echo_area_1
,
7450 (EMACS_INT
) w
, Qnil
, 0, 0);
7453 echo_area_buffer
[i
] = Qnil
;
7455 unbind_to (count
, Qnil
);
7456 return window_height_changed_p
;
7460 /* Helper for display_echo_area. Display the current buffer which
7461 contains the current echo area message in window W, a mini-window,
7462 a pointer to which is passed in A1. A2..A4 are currently not used.
7463 Change the height of W so that all of the message is displayed.
7464 Value is non-zero if height of W was changed. */
7467 display_echo_area_1 (a1
, a2
, a3
, a4
)
7472 struct window
*w
= (struct window
*) a1
;
7474 struct text_pos start
;
7475 int window_height_changed_p
= 0;
7477 /* Do this before displaying, so that we have a large enough glyph
7478 matrix for the display. */
7479 window_height_changed_p
= resize_mini_window (w
, 0);
7482 clear_glyph_matrix (w
->desired_matrix
);
7483 XSETWINDOW (window
, w
);
7484 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7485 try_window (window
, start
);
7487 return window_height_changed_p
;
7491 /* Resize the echo area window to exactly the size needed for the
7492 currently displayed message, if there is one. If a mini-buffer
7493 is active, don't shrink it. */
7496 resize_echo_area_exactly ()
7498 if (BUFFERP (echo_area_buffer
[0])
7499 && WINDOWP (echo_area_window
))
7501 struct window
*w
= XWINDOW (echo_area_window
);
7503 Lisp_Object resize_exactly
;
7505 if (minibuf_level
== 0)
7506 resize_exactly
= Qt
;
7508 resize_exactly
= Qnil
;
7510 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7511 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7514 ++windows_or_buffers_changed
;
7515 ++update_mode_lines
;
7516 redisplay_internal (0);
7522 /* Callback function for with_echo_area_buffer, when used from
7523 resize_echo_area_exactly. A1 contains a pointer to the window to
7524 resize, EXACTLY non-nil means resize the mini-window exactly to the
7525 size of the text displayed. A3 and A4 are not used. Value is what
7526 resize_mini_window returns. */
7529 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7531 Lisp_Object exactly
;
7534 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7538 /* Resize mini-window W to fit the size of its contents. EXACT:P
7539 means size the window exactly to the size needed. Otherwise, it's
7540 only enlarged until W's buffer is empty. Value is non-zero if
7541 the window height has been changed. */
7544 resize_mini_window (w
, exact_p
)
7548 struct frame
*f
= XFRAME (w
->frame
);
7549 int window_height_changed_p
= 0;
7551 xassert (MINI_WINDOW_P (w
));
7553 /* Don't resize windows while redisplaying a window; it would
7554 confuse redisplay functions when the size of the window they are
7555 displaying changes from under them. Such a resizing can happen,
7556 for instance, when which-func prints a long message while
7557 we are running fontification-functions. We're running these
7558 functions with safe_call which binds inhibit-redisplay to t. */
7559 if (!NILP (Vinhibit_redisplay
))
7562 /* Nil means don't try to resize. */
7563 if (NILP (Vresize_mini_windows
)
7564 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7567 if (!FRAME_MINIBUF_ONLY_P (f
))
7570 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7571 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7572 int height
, max_height
;
7573 int unit
= FRAME_LINE_HEIGHT (f
);
7574 struct text_pos start
;
7575 struct buffer
*old_current_buffer
= NULL
;
7577 if (current_buffer
!= XBUFFER (w
->buffer
))
7579 old_current_buffer
= current_buffer
;
7580 set_buffer_internal (XBUFFER (w
->buffer
));
7583 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7585 /* Compute the max. number of lines specified by the user. */
7586 if (FLOATP (Vmax_mini_window_height
))
7587 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7588 else if (INTEGERP (Vmax_mini_window_height
))
7589 max_height
= XINT (Vmax_mini_window_height
);
7591 max_height
= total_height
/ 4;
7593 /* Correct that max. height if it's bogus. */
7594 max_height
= max (1, max_height
);
7595 max_height
= min (total_height
, max_height
);
7597 /* Find out the height of the text in the window. */
7598 if (it
.truncate_lines_p
)
7603 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7604 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7605 height
= it
.current_y
+ last_height
;
7607 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7608 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7609 height
= (height
+ unit
- 1) / unit
;
7612 /* Compute a suitable window start. */
7613 if (height
> max_height
)
7615 height
= max_height
;
7616 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7617 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7618 start
= it
.current
.pos
;
7621 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7622 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7624 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7626 /* Let it grow only, until we display an empty message, in which
7627 case the window shrinks again. */
7628 if (height
> WINDOW_TOTAL_LINES (w
))
7630 int old_height
= WINDOW_TOTAL_LINES (w
);
7631 freeze_window_starts (f
, 1);
7632 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7633 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7635 else if (height
< WINDOW_TOTAL_LINES (w
)
7636 && (exact_p
|| BEGV
== ZV
))
7638 int old_height
= WINDOW_TOTAL_LINES (w
);
7639 freeze_window_starts (f
, 0);
7640 shrink_mini_window (w
);
7641 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7646 /* Always resize to exact size needed. */
7647 if (height
> WINDOW_TOTAL_LINES (w
))
7649 int old_height
= WINDOW_TOTAL_LINES (w
);
7650 freeze_window_starts (f
, 1);
7651 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7652 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7654 else if (height
< WINDOW_TOTAL_LINES (w
))
7656 int old_height
= WINDOW_TOTAL_LINES (w
);
7657 freeze_window_starts (f
, 0);
7658 shrink_mini_window (w
);
7662 freeze_window_starts (f
, 1);
7663 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7666 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7670 if (old_current_buffer
)
7671 set_buffer_internal (old_current_buffer
);
7674 return window_height_changed_p
;
7678 /* Value is the current message, a string, or nil if there is no
7686 if (NILP (echo_area_buffer
[0]))
7690 with_echo_area_buffer (0, 0, current_message_1
,
7691 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7693 echo_area_buffer
[0] = Qnil
;
7701 current_message_1 (a1
, a2
, a3
, a4
)
7706 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7709 *msg
= make_buffer_string (BEG
, Z
, 1);
7716 /* Push the current message on Vmessage_stack for later restauration
7717 by restore_message. Value is non-zero if the current message isn't
7718 empty. This is a relatively infrequent operation, so it's not
7719 worth optimizing. */
7725 msg
= current_message ();
7726 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7727 return STRINGP (msg
);
7731 /* Restore message display from the top of Vmessage_stack. */
7738 xassert (CONSP (Vmessage_stack
));
7739 msg
= XCAR (Vmessage_stack
);
7741 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7743 message3_nolog (msg
, 0, 0);
7747 /* Handler for record_unwind_protect calling pop_message. */
7750 pop_message_unwind (dummy
)
7757 /* Pop the top-most entry off Vmessage_stack. */
7762 xassert (CONSP (Vmessage_stack
));
7763 Vmessage_stack
= XCDR (Vmessage_stack
);
7767 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7768 exits. If the stack is not empty, we have a missing pop_message
7772 check_message_stack ()
7774 if (!NILP (Vmessage_stack
))
7779 /* Truncate to NCHARS what will be displayed in the echo area the next
7780 time we display it---but don't redisplay it now. */
7783 truncate_echo_area (nchars
)
7787 echo_area_buffer
[0] = Qnil
;
7788 /* A null message buffer means that the frame hasn't really been
7789 initialized yet. Error messages get reported properly by
7790 cmd_error, so this must be just an informative message; toss it. */
7791 else if (!noninteractive
7793 && !NILP (echo_area_buffer
[0]))
7795 struct frame
*sf
= SELECTED_FRAME ();
7796 if (FRAME_MESSAGE_BUF (sf
))
7797 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7802 /* Helper function for truncate_echo_area. Truncate the current
7803 message to at most NCHARS characters. */
7806 truncate_message_1 (nchars
, a2
, a3
, a4
)
7811 if (BEG
+ nchars
< Z
)
7812 del_range (BEG
+ nchars
, Z
);
7814 echo_area_buffer
[0] = Qnil
;
7819 /* Set the current message to a substring of S or STRING.
7821 If STRING is a Lisp string, set the message to the first NBYTES
7822 bytes from STRING. NBYTES zero means use the whole string. If
7823 STRING is multibyte, the message will be displayed multibyte.
7825 If S is not null, set the message to the first LEN bytes of S. LEN
7826 zero means use the whole string. MULTIBYTE_P non-zero means S is
7827 multibyte. Display the message multibyte in that case. */
7830 set_message (s
, string
, nbytes
, multibyte_p
)
7833 int nbytes
, multibyte_p
;
7835 message_enable_multibyte
7836 = ((s
&& multibyte_p
)
7837 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7839 with_echo_area_buffer (0, -1, set_message_1
,
7840 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7841 message_buf_print
= 0;
7842 help_echo_showing_p
= 0;
7846 /* Helper function for set_message. Arguments have the same meaning
7847 as there, with A1 corresponding to S and A2 corresponding to STRING
7848 This function is called with the echo area buffer being
7852 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7855 EMACS_INT nbytes
, multibyte_p
;
7857 const char *s
= (const char *) a1
;
7858 Lisp_Object string
= a2
;
7862 /* Change multibyteness of the echo buffer appropriately. */
7863 if (message_enable_multibyte
7864 != !NILP (current_buffer
->enable_multibyte_characters
))
7865 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7867 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7869 /* Insert new message at BEG. */
7870 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7872 if (STRINGP (string
))
7877 nbytes
= SBYTES (string
);
7878 nchars
= string_byte_to_char (string
, nbytes
);
7880 /* This function takes care of single/multibyte conversion. We
7881 just have to ensure that the echo area buffer has the right
7882 setting of enable_multibyte_characters. */
7883 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7888 nbytes
= strlen (s
);
7890 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7892 /* Convert from multi-byte to single-byte. */
7894 unsigned char work
[1];
7896 /* Convert a multibyte string to single-byte. */
7897 for (i
= 0; i
< nbytes
; i
+= n
)
7899 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7900 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7902 : multibyte_char_to_unibyte (c
, Qnil
));
7903 insert_1_both (work
, 1, 1, 1, 0, 0);
7906 else if (!multibyte_p
7907 && !NILP (current_buffer
->enable_multibyte_characters
))
7909 /* Convert from single-byte to multi-byte. */
7911 const unsigned char *msg
= (const unsigned char *) s
;
7912 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7914 /* Convert a single-byte string to multibyte. */
7915 for (i
= 0; i
< nbytes
; i
++)
7917 c
= unibyte_char_to_multibyte (msg
[i
]);
7918 n
= CHAR_STRING (c
, str
);
7919 insert_1_both (str
, 1, n
, 1, 0, 0);
7923 insert_1 (s
, nbytes
, 1, 0, 0);
7930 /* Clear messages. CURRENT_P non-zero means clear the current
7931 message. LAST_DISPLAYED_P non-zero means clear the message
7935 clear_message (current_p
, last_displayed_p
)
7936 int current_p
, last_displayed_p
;
7940 echo_area_buffer
[0] = Qnil
;
7941 message_cleared_p
= 1;
7944 if (last_displayed_p
)
7945 echo_area_buffer
[1] = Qnil
;
7947 message_buf_print
= 0;
7950 /* Clear garbaged frames.
7952 This function is used where the old redisplay called
7953 redraw_garbaged_frames which in turn called redraw_frame which in
7954 turn called clear_frame. The call to clear_frame was a source of
7955 flickering. I believe a clear_frame is not necessary. It should
7956 suffice in the new redisplay to invalidate all current matrices,
7957 and ensure a complete redisplay of all windows. */
7960 clear_garbaged_frames ()
7964 Lisp_Object tail
, frame
;
7965 int changed_count
= 0;
7967 FOR_EACH_FRAME (tail
, frame
)
7969 struct frame
*f
= XFRAME (frame
);
7971 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7975 Fredraw_frame (frame
);
7976 f
->force_flush_display_p
= 1;
7978 clear_current_matrices (f
);
7987 ++windows_or_buffers_changed
;
7992 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7993 is non-zero update selected_frame. Value is non-zero if the
7994 mini-windows height has been changed. */
7997 echo_area_display (update_frame_p
)
8000 Lisp_Object mini_window
;
8003 int window_height_changed_p
= 0;
8004 struct frame
*sf
= SELECTED_FRAME ();
8006 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8007 w
= XWINDOW (mini_window
);
8008 f
= XFRAME (WINDOW_FRAME (w
));
8010 /* Don't display if frame is invisible or not yet initialized. */
8011 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8014 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8016 #ifdef HAVE_WINDOW_SYSTEM
8017 /* When Emacs starts, selected_frame may be a visible terminal
8018 frame, even if we run under a window system. If we let this
8019 through, a message would be displayed on the terminal. */
8020 if (EQ (selected_frame
, Vterminal_frame
)
8021 && !NILP (Vwindow_system
))
8023 #endif /* HAVE_WINDOW_SYSTEM */
8026 /* Redraw garbaged frames. */
8028 clear_garbaged_frames ();
8030 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8032 echo_area_window
= mini_window
;
8033 window_height_changed_p
= display_echo_area (w
);
8034 w
->must_be_updated_p
= 1;
8036 /* Update the display, unless called from redisplay_internal.
8037 Also don't update the screen during redisplay itself. The
8038 update will happen at the end of redisplay, and an update
8039 here could cause confusion. */
8040 if (update_frame_p
&& !redisplaying_p
)
8044 /* If the display update has been interrupted by pending
8045 input, update mode lines in the frame. Due to the
8046 pending input, it might have been that redisplay hasn't
8047 been called, so that mode lines above the echo area are
8048 garbaged. This looks odd, so we prevent it here. */
8049 if (!display_completed
)
8050 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8052 if (window_height_changed_p
8053 /* Don't do this if Emacs is shutting down. Redisplay
8054 needs to run hooks. */
8055 && !NILP (Vrun_hooks
))
8057 /* Must update other windows. Likewise as in other
8058 cases, don't let this update be interrupted by
8060 int count
= SPECPDL_INDEX ();
8061 specbind (Qredisplay_dont_pause
, Qt
);
8062 windows_or_buffers_changed
= 1;
8063 redisplay_internal (0);
8064 unbind_to (count
, Qnil
);
8066 else if (FRAME_WINDOW_P (f
) && n
== 0)
8068 /* Window configuration is the same as before.
8069 Can do with a display update of the echo area,
8070 unless we displayed some mode lines. */
8071 update_single_window (w
, 1);
8072 rif
->flush_display (f
);
8075 update_frame (f
, 1, 1);
8077 /* If cursor is in the echo area, make sure that the next
8078 redisplay displays the minibuffer, so that the cursor will
8079 be replaced with what the minibuffer wants. */
8080 if (cursor_in_echo_area
)
8081 ++windows_or_buffers_changed
;
8084 else if (!EQ (mini_window
, selected_window
))
8085 windows_or_buffers_changed
++;
8087 /* Last displayed message is now the current message. */
8088 echo_area_buffer
[1] = echo_area_buffer
[0];
8089 /* Inform read_char that we're not echoing. */
8090 echo_message_buffer
= Qnil
;
8092 /* Prevent redisplay optimization in redisplay_internal by resetting
8093 this_line_start_pos. This is done because the mini-buffer now
8094 displays the message instead of its buffer text. */
8095 if (EQ (mini_window
, selected_window
))
8096 CHARPOS (this_line_start_pos
) = 0;
8098 return window_height_changed_p
;
8103 /***********************************************************************
8105 ***********************************************************************/
8108 /* The frame title buffering code is also used by Fformat_mode_line.
8109 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
8111 /* A buffer for constructing frame titles in it; allocated from the
8112 heap in init_xdisp and resized as needed in store_frame_title_char. */
8114 static char *frame_title_buf
;
8116 /* The buffer's end, and a current output position in it. */
8118 static char *frame_title_buf_end
;
8119 static char *frame_title_ptr
;
8122 /* Store a single character C for the frame title in frame_title_buf.
8123 Re-allocate frame_title_buf if necessary. */
8127 store_frame_title_char (char c
)
8129 store_frame_title_char (c
)
8133 /* If output position has reached the end of the allocated buffer,
8134 double the buffer's size. */
8135 if (frame_title_ptr
== frame_title_buf_end
)
8137 int len
= frame_title_ptr
- frame_title_buf
;
8138 int new_size
= 2 * len
* sizeof *frame_title_buf
;
8139 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
8140 frame_title_buf_end
= frame_title_buf
+ new_size
;
8141 frame_title_ptr
= frame_title_buf
+ len
;
8144 *frame_title_ptr
++ = c
;
8148 /* Store part of a frame title in frame_title_buf, beginning at
8149 frame_title_ptr. STR is the string to store. Do not copy
8150 characters that yield more columns than PRECISION; PRECISION <= 0
8151 means copy the whole string. Pad with spaces until FIELD_WIDTH
8152 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8153 pad. Called from display_mode_element when it is used to build a
8157 store_frame_title (str
, field_width
, precision
)
8158 const unsigned char *str
;
8159 int field_width
, precision
;
8164 /* Copy at most PRECISION chars from STR. */
8165 nbytes
= strlen (str
);
8166 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8168 store_frame_title_char (*str
++);
8170 /* Fill up with spaces until FIELD_WIDTH reached. */
8171 while (field_width
> 0
8174 store_frame_title_char (' ');
8181 #ifdef HAVE_WINDOW_SYSTEM
8183 /* Set the title of FRAME, if it has changed. The title format is
8184 Vicon_title_format if FRAME is iconified, otherwise it is
8185 frame_title_format. */
8188 x_consider_frame_title (frame
)
8191 struct frame
*f
= XFRAME (frame
);
8193 if (FRAME_WINDOW_P (f
)
8194 || FRAME_MINIBUF_ONLY_P (f
)
8195 || f
->explicit_name
)
8197 /* Do we have more than one visible frame on this X display? */
8200 struct buffer
*obuf
;
8204 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8206 Lisp_Object other_frame
= XCAR (tail
);
8207 struct frame
*tf
= XFRAME (other_frame
);
8210 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8211 && !FRAME_MINIBUF_ONLY_P (tf
)
8212 && !EQ (other_frame
, tip_frame
)
8213 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8217 /* Set global variable indicating that multiple frames exist. */
8218 multiple_frames
= CONSP (tail
);
8220 /* Switch to the buffer of selected window of the frame. Set up
8221 frame_title_ptr so that display_mode_element will output into it;
8222 then display the title. */
8223 obuf
= current_buffer
;
8224 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8225 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8226 frame_title_ptr
= frame_title_buf
;
8227 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8228 NULL
, DEFAULT_FACE_ID
);
8229 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8230 len
= frame_title_ptr
- frame_title_buf
;
8231 frame_title_ptr
= NULL
;
8232 set_buffer_internal_1 (obuf
);
8234 /* Set the title only if it's changed. This avoids consing in
8235 the common case where it hasn't. (If it turns out that we've
8236 already wasted too much time by walking through the list with
8237 display_mode_element, then we might need to optimize at a
8238 higher level than this.) */
8239 if (! STRINGP (f
->name
)
8240 || SBYTES (f
->name
) != len
8241 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8242 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8246 #endif /* not HAVE_WINDOW_SYSTEM */
8251 /***********************************************************************
8253 ***********************************************************************/
8256 /* Prepare for redisplay by updating menu-bar item lists when
8257 appropriate. This can call eval. */
8260 prepare_menu_bars ()
8263 struct gcpro gcpro1
, gcpro2
;
8265 Lisp_Object tooltip_frame
;
8267 #ifdef HAVE_WINDOW_SYSTEM
8268 tooltip_frame
= tip_frame
;
8270 tooltip_frame
= Qnil
;
8273 /* Update all frame titles based on their buffer names, etc. We do
8274 this before the menu bars so that the buffer-menu will show the
8275 up-to-date frame titles. */
8276 #ifdef HAVE_WINDOW_SYSTEM
8277 if (windows_or_buffers_changed
|| update_mode_lines
)
8279 Lisp_Object tail
, frame
;
8281 FOR_EACH_FRAME (tail
, frame
)
8284 if (!EQ (frame
, tooltip_frame
)
8285 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8286 x_consider_frame_title (frame
);
8289 #endif /* HAVE_WINDOW_SYSTEM */
8291 /* Update the menu bar item lists, if appropriate. This has to be
8292 done before any actual redisplay or generation of display lines. */
8293 all_windows
= (update_mode_lines
8294 || buffer_shared
> 1
8295 || windows_or_buffers_changed
);
8298 Lisp_Object tail
, frame
;
8299 int count
= SPECPDL_INDEX ();
8301 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8303 FOR_EACH_FRAME (tail
, frame
)
8307 /* Ignore tooltip frame. */
8308 if (EQ (frame
, tooltip_frame
))
8311 /* If a window on this frame changed size, report that to
8312 the user and clear the size-change flag. */
8313 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8315 Lisp_Object functions
;
8317 /* Clear flag first in case we get an error below. */
8318 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8319 functions
= Vwindow_size_change_functions
;
8320 GCPRO2 (tail
, functions
);
8322 while (CONSP (functions
))
8324 call1 (XCAR (functions
), frame
);
8325 functions
= XCDR (functions
);
8331 update_menu_bar (f
, 0);
8332 #ifdef HAVE_WINDOW_SYSTEM
8333 update_tool_bar (f
, 0);
8338 unbind_to (count
, Qnil
);
8342 struct frame
*sf
= SELECTED_FRAME ();
8343 update_menu_bar (sf
, 1);
8344 #ifdef HAVE_WINDOW_SYSTEM
8345 update_tool_bar (sf
, 1);
8349 /* Motif needs this. See comment in xmenu.c. Turn it off when
8350 pending_menu_activation is not defined. */
8351 #ifdef USE_X_TOOLKIT
8352 pending_menu_activation
= 0;
8357 /* Update the menu bar item list for frame F. This has to be done
8358 before we start to fill in any display lines, because it can call
8361 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8364 update_menu_bar (f
, save_match_data
)
8366 int save_match_data
;
8369 register struct window
*w
;
8371 /* If called recursively during a menu update, do nothing. This can
8372 happen when, for instance, an activate-menubar-hook causes a
8374 if (inhibit_menubar_update
)
8377 window
= FRAME_SELECTED_WINDOW (f
);
8378 w
= XWINDOW (window
);
8380 #if 0 /* The if statement below this if statement used to include the
8381 condition !NILP (w->update_mode_line), rather than using
8382 update_mode_lines directly, and this if statement may have
8383 been added to make that condition work. Now the if
8384 statement below matches its comment, this isn't needed. */
8385 if (update_mode_lines
)
8386 w
->update_mode_line
= Qt
;
8389 if (FRAME_WINDOW_P (f
)
8391 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8392 || defined (USE_GTK)
8393 FRAME_EXTERNAL_MENU_BAR (f
)
8395 FRAME_MENU_BAR_LINES (f
) > 0
8397 : FRAME_MENU_BAR_LINES (f
) > 0)
8399 /* If the user has switched buffers or windows, we need to
8400 recompute to reflect the new bindings. But we'll
8401 recompute when update_mode_lines is set too; that means
8402 that people can use force-mode-line-update to request
8403 that the menu bar be recomputed. The adverse effect on
8404 the rest of the redisplay algorithm is about the same as
8405 windows_or_buffers_changed anyway. */
8406 if (windows_or_buffers_changed
8407 /* This used to test w->update_mode_line, but we believe
8408 there is no need to recompute the menu in that case. */
8409 || update_mode_lines
8410 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8411 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8412 != !NILP (w
->last_had_star
))
8413 || ((!NILP (Vtransient_mark_mode
)
8414 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8415 != !NILP (w
->region_showing
)))
8417 struct buffer
*prev
= current_buffer
;
8418 int count
= SPECPDL_INDEX ();
8420 specbind (Qinhibit_menubar_update
, Qt
);
8422 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8423 if (save_match_data
)
8424 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8425 if (NILP (Voverriding_local_map_menu_flag
))
8427 specbind (Qoverriding_terminal_local_map
, Qnil
);
8428 specbind (Qoverriding_local_map
, Qnil
);
8431 /* Run the Lucid hook. */
8432 safe_run_hooks (Qactivate_menubar_hook
);
8434 /* If it has changed current-menubar from previous value,
8435 really recompute the menu-bar from the value. */
8436 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8437 call0 (Qrecompute_lucid_menubar
);
8439 safe_run_hooks (Qmenu_bar_update_hook
);
8440 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8442 /* Redisplay the menu bar in case we changed it. */
8443 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8444 || defined (USE_GTK)
8445 if (FRAME_WINDOW_P (f
)
8446 #if defined (MAC_OS)
8447 /* All frames on Mac OS share the same menubar. So only the
8448 selected frame should be allowed to set it. */
8449 && f
== SELECTED_FRAME ()
8452 set_frame_menubar (f
, 0, 0);
8454 /* On a terminal screen, the menu bar is an ordinary screen
8455 line, and this makes it get updated. */
8456 w
->update_mode_line
= Qt
;
8457 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8458 /* In the non-toolkit version, the menu bar is an ordinary screen
8459 line, and this makes it get updated. */
8460 w
->update_mode_line
= Qt
;
8461 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8463 unbind_to (count
, Qnil
);
8464 set_buffer_internal_1 (prev
);
8471 /***********************************************************************
8473 ***********************************************************************/
8475 #ifdef HAVE_WINDOW_SYSTEM
8478 Nominal cursor position -- where to draw output.
8479 HPOS and VPOS are window relative glyph matrix coordinates.
8480 X and Y are window relative pixel coordinates. */
8482 struct cursor_pos output_cursor
;
8486 Set the global variable output_cursor to CURSOR. All cursor
8487 positions are relative to updated_window. */
8490 set_output_cursor (cursor
)
8491 struct cursor_pos
*cursor
;
8493 output_cursor
.hpos
= cursor
->hpos
;
8494 output_cursor
.vpos
= cursor
->vpos
;
8495 output_cursor
.x
= cursor
->x
;
8496 output_cursor
.y
= cursor
->y
;
8501 Set a nominal cursor position.
8503 HPOS and VPOS are column/row positions in a window glyph matrix. X
8504 and Y are window text area relative pixel positions.
8506 If this is done during an update, updated_window will contain the
8507 window that is being updated and the position is the future output
8508 cursor position for that window. If updated_window is null, use
8509 selected_window and display the cursor at the given position. */
8512 x_cursor_to (vpos
, hpos
, y
, x
)
8513 int vpos
, hpos
, y
, x
;
8517 /* If updated_window is not set, work on selected_window. */
8521 w
= XWINDOW (selected_window
);
8523 /* Set the output cursor. */
8524 output_cursor
.hpos
= hpos
;
8525 output_cursor
.vpos
= vpos
;
8526 output_cursor
.x
= x
;
8527 output_cursor
.y
= y
;
8529 /* If not called as part of an update, really display the cursor.
8530 This will also set the cursor position of W. */
8531 if (updated_window
== NULL
)
8534 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8535 if (rif
->flush_display_optional
)
8536 rif
->flush_display_optional (SELECTED_FRAME ());
8541 #endif /* HAVE_WINDOW_SYSTEM */
8544 /***********************************************************************
8546 ***********************************************************************/
8548 #ifdef HAVE_WINDOW_SYSTEM
8550 /* Where the mouse was last time we reported a mouse event. */
8552 FRAME_PTR last_mouse_frame
;
8554 /* Tool-bar item index of the item on which a mouse button was pressed
8557 int last_tool_bar_item
;
8560 /* Update the tool-bar item list for frame F. This has to be done
8561 before we start to fill in any display lines. Called from
8562 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8563 and restore it here. */
8566 update_tool_bar (f
, save_match_data
)
8568 int save_match_data
;
8571 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8573 int do_update
= WINDOWP (f
->tool_bar_window
)
8574 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8582 window
= FRAME_SELECTED_WINDOW (f
);
8583 w
= XWINDOW (window
);
8585 /* If the user has switched buffers or windows, we need to
8586 recompute to reflect the new bindings. But we'll
8587 recompute when update_mode_lines is set too; that means
8588 that people can use force-mode-line-update to request
8589 that the menu bar be recomputed. The adverse effect on
8590 the rest of the redisplay algorithm is about the same as
8591 windows_or_buffers_changed anyway. */
8592 if (windows_or_buffers_changed
8593 || !NILP (w
->update_mode_line
)
8594 || update_mode_lines
8595 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8596 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8597 != !NILP (w
->last_had_star
))
8598 || ((!NILP (Vtransient_mark_mode
)
8599 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8600 != !NILP (w
->region_showing
)))
8602 struct buffer
*prev
= current_buffer
;
8603 int count
= SPECPDL_INDEX ();
8604 Lisp_Object new_tool_bar
;
8606 struct gcpro gcpro1
;
8608 /* Set current_buffer to the buffer of the selected
8609 window of the frame, so that we get the right local
8611 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8613 /* Save match data, if we must. */
8614 if (save_match_data
)
8615 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8617 /* Make sure that we don't accidentally use bogus keymaps. */
8618 if (NILP (Voverriding_local_map_menu_flag
))
8620 specbind (Qoverriding_terminal_local_map
, Qnil
);
8621 specbind (Qoverriding_local_map
, Qnil
);
8624 GCPRO1 (new_tool_bar
);
8626 /* Build desired tool-bar items from keymaps. */
8627 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8630 /* Redisplay the tool-bar if we changed it. */
8631 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8633 /* Redisplay that happens asynchronously due to an expose event
8634 may access f->tool_bar_items. Make sure we update both
8635 variables within BLOCK_INPUT so no such event interrupts. */
8637 f
->tool_bar_items
= new_tool_bar
;
8638 f
->n_tool_bar_items
= new_n_tool_bar
;
8639 w
->update_mode_line
= Qt
;
8645 unbind_to (count
, Qnil
);
8646 set_buffer_internal_1 (prev
);
8652 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8653 F's desired tool-bar contents. F->tool_bar_items must have
8654 been set up previously by calling prepare_menu_bars. */
8657 build_desired_tool_bar_string (f
)
8660 int i
, size
, size_needed
;
8661 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8662 Lisp_Object image
, plist
, props
;
8664 image
= plist
= props
= Qnil
;
8665 GCPRO3 (image
, plist
, props
);
8667 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8668 Otherwise, make a new string. */
8670 /* The size of the string we might be able to reuse. */
8671 size
= (STRINGP (f
->desired_tool_bar_string
)
8672 ? SCHARS (f
->desired_tool_bar_string
)
8675 /* We need one space in the string for each image. */
8676 size_needed
= f
->n_tool_bar_items
;
8678 /* Reuse f->desired_tool_bar_string, if possible. */
8679 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8680 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8684 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8685 Fremove_text_properties (make_number (0), make_number (size
),
8686 props
, f
->desired_tool_bar_string
);
8689 /* Put a `display' property on the string for the images to display,
8690 put a `menu_item' property on tool-bar items with a value that
8691 is the index of the item in F's tool-bar item vector. */
8692 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8694 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8696 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8697 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8698 int hmargin
, vmargin
, relief
, idx
, end
;
8699 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8701 /* If image is a vector, choose the image according to the
8703 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8704 if (VECTORP (image
))
8708 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8709 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8712 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8713 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8715 xassert (ASIZE (image
) >= idx
);
8716 image
= AREF (image
, idx
);
8721 /* Ignore invalid image specifications. */
8722 if (!valid_image_p (image
))
8725 /* Display the tool-bar button pressed, or depressed. */
8726 plist
= Fcopy_sequence (XCDR (image
));
8728 /* Compute margin and relief to draw. */
8729 relief
= (tool_bar_button_relief
>= 0
8730 ? tool_bar_button_relief
8731 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8732 hmargin
= vmargin
= relief
;
8734 if (INTEGERP (Vtool_bar_button_margin
)
8735 && XINT (Vtool_bar_button_margin
) > 0)
8737 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8738 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8740 else if (CONSP (Vtool_bar_button_margin
))
8742 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8743 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8744 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8746 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8747 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8748 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8751 if (auto_raise_tool_bar_buttons_p
)
8753 /* Add a `:relief' property to the image spec if the item is
8757 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8764 /* If image is selected, display it pressed, i.e. with a
8765 negative relief. If it's not selected, display it with a
8767 plist
= Fplist_put (plist
, QCrelief
,
8769 ? make_number (-relief
)
8770 : make_number (relief
)));
8775 /* Put a margin around the image. */
8776 if (hmargin
|| vmargin
)
8778 if (hmargin
== vmargin
)
8779 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8781 plist
= Fplist_put (plist
, QCmargin
,
8782 Fcons (make_number (hmargin
),
8783 make_number (vmargin
)));
8786 /* If button is not enabled, and we don't have special images
8787 for the disabled state, make the image appear disabled by
8788 applying an appropriate algorithm to it. */
8789 if (!enabled_p
&& idx
< 0)
8790 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8792 /* Put a `display' text property on the string for the image to
8793 display. Put a `menu-item' property on the string that gives
8794 the start of this item's properties in the tool-bar items
8796 image
= Fcons (Qimage
, plist
);
8797 props
= list4 (Qdisplay
, image
,
8798 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8800 /* Let the last image hide all remaining spaces in the tool bar
8801 string. The string can be longer than needed when we reuse a
8803 if (i
+ 1 == f
->n_tool_bar_items
)
8804 end
= SCHARS (f
->desired_tool_bar_string
);
8807 Fadd_text_properties (make_number (i
), make_number (end
),
8808 props
, f
->desired_tool_bar_string
);
8816 /* Display one line of the tool-bar of frame IT->f. */
8819 display_tool_bar_line (it
)
8822 struct glyph_row
*row
= it
->glyph_row
;
8823 int max_x
= it
->last_visible_x
;
8826 prepare_desired_row (row
);
8827 row
->y
= it
->current_y
;
8829 /* Note that this isn't made use of if the face hasn't a box,
8830 so there's no need to check the face here. */
8831 it
->start_of_box_run_p
= 1;
8833 while (it
->current_x
< max_x
)
8835 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8837 /* Get the next display element. */
8838 if (!get_next_display_element (it
))
8841 /* Produce glyphs. */
8842 x_before
= it
->current_x
;
8843 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8844 PRODUCE_GLYPHS (it
);
8846 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8851 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8853 if (x
+ glyph
->pixel_width
> max_x
)
8855 /* Glyph doesn't fit on line. */
8856 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8862 x
+= glyph
->pixel_width
;
8866 /* Stop at line ends. */
8867 if (ITERATOR_AT_END_OF_LINE_P (it
))
8870 set_iterator_to_next (it
, 1);
8875 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8876 extend_face_to_end_of_line (it
);
8877 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8878 last
->right_box_line_p
= 1;
8879 if (last
== row
->glyphs
[TEXT_AREA
])
8880 last
->left_box_line_p
= 1;
8881 compute_line_metrics (it
);
8883 /* If line is empty, make it occupy the rest of the tool-bar. */
8884 if (!row
->displays_text_p
)
8886 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8887 row
->ascent
= row
->phys_ascent
= 0;
8888 row
->extra_line_spacing
= 0;
8891 row
->full_width_p
= 1;
8892 row
->continued_p
= 0;
8893 row
->truncated_on_left_p
= 0;
8894 row
->truncated_on_right_p
= 0;
8896 it
->current_x
= it
->hpos
= 0;
8897 it
->current_y
+= row
->height
;
8903 /* Value is the number of screen lines needed to make all tool-bar
8904 items of frame F visible. */
8907 tool_bar_lines_needed (f
)
8910 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8913 /* Initialize an iterator for iteration over
8914 F->desired_tool_bar_string in the tool-bar window of frame F. */
8915 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8916 it
.first_visible_x
= 0;
8917 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8918 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8920 while (!ITERATOR_AT_END_P (&it
))
8922 it
.glyph_row
= w
->desired_matrix
->rows
;
8923 clear_glyph_row (it
.glyph_row
);
8924 display_tool_bar_line (&it
);
8927 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8931 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8933 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8942 frame
= selected_frame
;
8944 CHECK_FRAME (frame
);
8947 if (WINDOWP (f
->tool_bar_window
)
8948 || (w
= XWINDOW (f
->tool_bar_window
),
8949 WINDOW_TOTAL_LINES (w
) > 0))
8951 update_tool_bar (f
, 1);
8952 if (f
->n_tool_bar_items
)
8954 build_desired_tool_bar_string (f
);
8955 nlines
= tool_bar_lines_needed (f
);
8959 return make_number (nlines
);
8963 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8964 height should be changed. */
8967 redisplay_tool_bar (f
)
8972 struct glyph_row
*row
;
8973 int change_height_p
= 0;
8976 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8977 update_frame_tool_bar (f
);
8981 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8982 do anything. This means you must start with tool-bar-lines
8983 non-zero to get the auto-sizing effect. Or in other words, you
8984 can turn off tool-bars by specifying tool-bar-lines zero. */
8985 if (!WINDOWP (f
->tool_bar_window
)
8986 || (w
= XWINDOW (f
->tool_bar_window
),
8987 WINDOW_TOTAL_LINES (w
) == 0))
8990 /* Set up an iterator for the tool-bar window. */
8991 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8992 it
.first_visible_x
= 0;
8993 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8996 /* Build a string that represents the contents of the tool-bar. */
8997 build_desired_tool_bar_string (f
);
8998 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9000 /* Display as many lines as needed to display all tool-bar items. */
9001 while (it
.current_y
< it
.last_visible_y
)
9002 display_tool_bar_line (&it
);
9004 /* It doesn't make much sense to try scrolling in the tool-bar
9005 window, so don't do it. */
9006 w
->desired_matrix
->no_scrolling_p
= 1;
9007 w
->must_be_updated_p
= 1;
9009 if (auto_resize_tool_bars_p
)
9013 /* If we couldn't display everything, change the tool-bar's
9015 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9016 change_height_p
= 1;
9018 /* If there are blank lines at the end, except for a partially
9019 visible blank line at the end that is smaller than
9020 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9021 row
= it
.glyph_row
- 1;
9022 if (!row
->displays_text_p
9023 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9024 change_height_p
= 1;
9026 /* If row displays tool-bar items, but is partially visible,
9027 change the tool-bar's height. */
9028 if (row
->displays_text_p
9029 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9030 change_height_p
= 1;
9032 /* Resize windows as needed by changing the `tool-bar-lines'
9035 && (nlines
= tool_bar_lines_needed (f
),
9036 nlines
!= WINDOW_TOTAL_LINES (w
)))
9038 extern Lisp_Object Qtool_bar_lines
;
9040 int old_height
= WINDOW_TOTAL_LINES (w
);
9042 XSETFRAME (frame
, f
);
9043 clear_glyph_matrix (w
->desired_matrix
);
9044 Fmodify_frame_parameters (frame
,
9045 Fcons (Fcons (Qtool_bar_lines
,
9046 make_number (nlines
)),
9048 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9049 fonts_changed_p
= 1;
9053 return change_height_p
;
9057 /* Get information about the tool-bar item which is displayed in GLYPH
9058 on frame F. Return in *PROP_IDX the index where tool-bar item
9059 properties start in F->tool_bar_items. Value is zero if
9060 GLYPH doesn't display a tool-bar item. */
9063 tool_bar_item_info (f
, glyph
, prop_idx
)
9065 struct glyph
*glyph
;
9072 /* This function can be called asynchronously, which means we must
9073 exclude any possibility that Fget_text_property signals an
9075 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9076 charpos
= max (0, charpos
);
9078 /* Get the text property `menu-item' at pos. The value of that
9079 property is the start index of this item's properties in
9080 F->tool_bar_items. */
9081 prop
= Fget_text_property (make_number (charpos
),
9082 Qmenu_item
, f
->current_tool_bar_string
);
9083 if (INTEGERP (prop
))
9085 *prop_idx
= XINT (prop
);
9095 /* Get information about the tool-bar item at position X/Y on frame F.
9096 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9097 the current matrix of the tool-bar window of F, or NULL if not
9098 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9099 item in F->tool_bar_items. Value is
9101 -1 if X/Y is not on a tool-bar item
9102 0 if X/Y is on the same item that was highlighted before.
9106 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9109 struct glyph
**glyph
;
9110 int *hpos
, *vpos
, *prop_idx
;
9112 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9113 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9116 /* Find the glyph under X/Y. */
9117 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9121 /* Get the start of this tool-bar item's properties in
9122 f->tool_bar_items. */
9123 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9126 /* Is mouse on the highlighted item? */
9127 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9128 && *vpos
>= dpyinfo
->mouse_face_beg_row
9129 && *vpos
<= dpyinfo
->mouse_face_end_row
9130 && (*vpos
> dpyinfo
->mouse_face_beg_row
9131 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9132 && (*vpos
< dpyinfo
->mouse_face_end_row
9133 || *hpos
< dpyinfo
->mouse_face_end_col
9134 || dpyinfo
->mouse_face_past_end
))
9142 Handle mouse button event on the tool-bar of frame F, at
9143 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9144 0 for button release. MODIFIERS is event modifiers for button
9148 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9151 unsigned int modifiers
;
9153 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9154 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9155 int hpos
, vpos
, prop_idx
;
9156 struct glyph
*glyph
;
9157 Lisp_Object enabled_p
;
9159 /* If not on the highlighted tool-bar item, return. */
9160 frame_to_window_pixel_xy (w
, &x
, &y
);
9161 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9164 /* If item is disabled, do nothing. */
9165 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9166 if (NILP (enabled_p
))
9171 /* Show item in pressed state. */
9172 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9173 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9174 last_tool_bar_item
= prop_idx
;
9178 Lisp_Object key
, frame
;
9179 struct input_event event
;
9182 /* Show item in released state. */
9183 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9184 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9186 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9188 XSETFRAME (frame
, f
);
9189 event
.kind
= TOOL_BAR_EVENT
;
9190 event
.frame_or_window
= frame
;
9192 kbd_buffer_store_event (&event
);
9194 event
.kind
= TOOL_BAR_EVENT
;
9195 event
.frame_or_window
= frame
;
9197 event
.modifiers
= modifiers
;
9198 kbd_buffer_store_event (&event
);
9199 last_tool_bar_item
= -1;
9204 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9205 tool-bar window-relative coordinates X/Y. Called from
9206 note_mouse_highlight. */
9209 note_tool_bar_highlight (f
, x
, y
)
9213 Lisp_Object window
= f
->tool_bar_window
;
9214 struct window
*w
= XWINDOW (window
);
9215 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9217 struct glyph
*glyph
;
9218 struct glyph_row
*row
;
9220 Lisp_Object enabled_p
;
9222 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9223 int mouse_down_p
, rc
;
9225 /* Function note_mouse_highlight is called with negative x(y
9226 values when mouse moves outside of the frame. */
9227 if (x
<= 0 || y
<= 0)
9229 clear_mouse_face (dpyinfo
);
9233 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9236 /* Not on tool-bar item. */
9237 clear_mouse_face (dpyinfo
);
9241 /* On same tool-bar item as before. */
9244 clear_mouse_face (dpyinfo
);
9246 /* Mouse is down, but on different tool-bar item? */
9247 mouse_down_p
= (dpyinfo
->grabbed
9248 && f
== last_mouse_frame
9249 && FRAME_LIVE_P (f
));
9251 && last_tool_bar_item
!= prop_idx
)
9254 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9255 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9257 /* If tool-bar item is not enabled, don't highlight it. */
9258 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9259 if (!NILP (enabled_p
))
9261 /* Compute the x-position of the glyph. In front and past the
9262 image is a space. We include this in the highlighted area. */
9263 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9264 for (i
= x
= 0; i
< hpos
; ++i
)
9265 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9267 /* Record this as the current active region. */
9268 dpyinfo
->mouse_face_beg_col
= hpos
;
9269 dpyinfo
->mouse_face_beg_row
= vpos
;
9270 dpyinfo
->mouse_face_beg_x
= x
;
9271 dpyinfo
->mouse_face_beg_y
= row
->y
;
9272 dpyinfo
->mouse_face_past_end
= 0;
9274 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9275 dpyinfo
->mouse_face_end_row
= vpos
;
9276 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9277 dpyinfo
->mouse_face_end_y
= row
->y
;
9278 dpyinfo
->mouse_face_window
= window
;
9279 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9281 /* Display it as active. */
9282 show_mouse_face (dpyinfo
, draw
);
9283 dpyinfo
->mouse_face_image_state
= draw
;
9288 /* Set help_echo_string to a help string to display for this tool-bar item.
9289 XTread_socket does the rest. */
9290 help_echo_object
= help_echo_window
= Qnil
;
9292 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9293 if (NILP (help_echo_string
))
9294 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9297 #endif /* HAVE_WINDOW_SYSTEM */
9301 /************************************************************************
9302 Horizontal scrolling
9303 ************************************************************************/
9305 static int hscroll_window_tree
P_ ((Lisp_Object
));
9306 static int hscroll_windows
P_ ((Lisp_Object
));
9308 /* For all leaf windows in the window tree rooted at WINDOW, set their
9309 hscroll value so that PT is (i) visible in the window, and (ii) so
9310 that it is not within a certain margin at the window's left and
9311 right border. Value is non-zero if any window's hscroll has been
9315 hscroll_window_tree (window
)
9318 int hscrolled_p
= 0;
9319 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9320 int hscroll_step_abs
= 0;
9321 double hscroll_step_rel
= 0;
9323 if (hscroll_relative_p
)
9325 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9326 if (hscroll_step_rel
< 0)
9328 hscroll_relative_p
= 0;
9329 hscroll_step_abs
= 0;
9332 else if (INTEGERP (Vhscroll_step
))
9334 hscroll_step_abs
= XINT (Vhscroll_step
);
9335 if (hscroll_step_abs
< 0)
9336 hscroll_step_abs
= 0;
9339 hscroll_step_abs
= 0;
9341 while (WINDOWP (window
))
9343 struct window
*w
= XWINDOW (window
);
9345 if (WINDOWP (w
->hchild
))
9346 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9347 else if (WINDOWP (w
->vchild
))
9348 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9349 else if (w
->cursor
.vpos
>= 0)
9352 int text_area_width
;
9353 struct glyph_row
*current_cursor_row
9354 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9355 struct glyph_row
*desired_cursor_row
9356 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9357 struct glyph_row
*cursor_row
9358 = (desired_cursor_row
->enabled_p
9359 ? desired_cursor_row
9360 : current_cursor_row
);
9362 text_area_width
= window_box_width (w
, TEXT_AREA
);
9364 /* Scroll when cursor is inside this scroll margin. */
9365 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9367 if ((XFASTINT (w
->hscroll
)
9368 && w
->cursor
.x
<= h_margin
)
9369 || (cursor_row
->enabled_p
9370 && cursor_row
->truncated_on_right_p
9371 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9375 struct buffer
*saved_current_buffer
;
9379 /* Find point in a display of infinite width. */
9380 saved_current_buffer
= current_buffer
;
9381 current_buffer
= XBUFFER (w
->buffer
);
9383 if (w
== XWINDOW (selected_window
))
9384 pt
= BUF_PT (current_buffer
);
9387 pt
= marker_position (w
->pointm
);
9388 pt
= max (BEGV
, pt
);
9392 /* Move iterator to pt starting at cursor_row->start in
9393 a line with infinite width. */
9394 init_to_row_start (&it
, w
, cursor_row
);
9395 it
.last_visible_x
= INFINITY
;
9396 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9397 current_buffer
= saved_current_buffer
;
9399 /* Position cursor in window. */
9400 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9401 hscroll
= max (0, (it
.current_x
9402 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9403 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9404 : (text_area_width
/ 2))))
9405 / FRAME_COLUMN_WIDTH (it
.f
);
9406 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9408 if (hscroll_relative_p
)
9409 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9412 wanted_x
= text_area_width
9413 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9416 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9420 if (hscroll_relative_p
)
9421 wanted_x
= text_area_width
* hscroll_step_rel
9424 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9427 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9429 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9431 /* Don't call Fset_window_hscroll if value hasn't
9432 changed because it will prevent redisplay
9434 if (XFASTINT (w
->hscroll
) != hscroll
)
9436 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9437 w
->hscroll
= make_number (hscroll
);
9446 /* Value is non-zero if hscroll of any leaf window has been changed. */
9451 /* Set hscroll so that cursor is visible and not inside horizontal
9452 scroll margins for all windows in the tree rooted at WINDOW. See
9453 also hscroll_window_tree above. Value is non-zero if any window's
9454 hscroll has been changed. If it has, desired matrices on the frame
9455 of WINDOW are cleared. */
9458 hscroll_windows (window
)
9463 if (automatic_hscrolling_p
)
9465 hscrolled_p
= hscroll_window_tree (window
);
9467 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9476 /************************************************************************
9478 ************************************************************************/
9480 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9481 to a non-zero value. This is sometimes handy to have in a debugger
9486 /* First and last unchanged row for try_window_id. */
9488 int debug_first_unchanged_at_end_vpos
;
9489 int debug_last_unchanged_at_beg_vpos
;
9491 /* Delta vpos and y. */
9493 int debug_dvpos
, debug_dy
;
9495 /* Delta in characters and bytes for try_window_id. */
9497 int debug_delta
, debug_delta_bytes
;
9499 /* Values of window_end_pos and window_end_vpos at the end of
9502 EMACS_INT debug_end_pos
, debug_end_vpos
;
9504 /* Append a string to W->desired_matrix->method. FMT is a printf
9505 format string. A1...A9 are a supplement for a variable-length
9506 argument list. If trace_redisplay_p is non-zero also printf the
9507 resulting string to stderr. */
9510 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9513 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9516 char *method
= w
->desired_matrix
->method
;
9517 int len
= strlen (method
);
9518 int size
= sizeof w
->desired_matrix
->method
;
9519 int remaining
= size
- len
- 1;
9521 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9522 if (len
&& remaining
)
9528 strncpy (method
+ len
, buffer
, remaining
);
9530 if (trace_redisplay_p
)
9531 fprintf (stderr
, "%p (%s): %s\n",
9533 ((BUFFERP (w
->buffer
)
9534 && STRINGP (XBUFFER (w
->buffer
)->name
))
9535 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9540 #endif /* GLYPH_DEBUG */
9543 /* Value is non-zero if all changes in window W, which displays
9544 current_buffer, are in the text between START and END. START is a
9545 buffer position, END is given as a distance from Z. Used in
9546 redisplay_internal for display optimization. */
9549 text_outside_line_unchanged_p (w
, start
, end
)
9553 int unchanged_p
= 1;
9555 /* If text or overlays have changed, see where. */
9556 if (XFASTINT (w
->last_modified
) < MODIFF
9557 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9559 /* Gap in the line? */
9560 if (GPT
< start
|| Z
- GPT
< end
)
9563 /* Changes start in front of the line, or end after it? */
9565 && (BEG_UNCHANGED
< start
- 1
9566 || END_UNCHANGED
< end
))
9569 /* If selective display, can't optimize if changes start at the
9570 beginning of the line. */
9572 && INTEGERP (current_buffer
->selective_display
)
9573 && XINT (current_buffer
->selective_display
) > 0
9574 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9577 /* If there are overlays at the start or end of the line, these
9578 may have overlay strings with newlines in them. A change at
9579 START, for instance, may actually concern the display of such
9580 overlay strings as well, and they are displayed on different
9581 lines. So, quickly rule out this case. (For the future, it
9582 might be desirable to implement something more telling than
9583 just BEG/END_UNCHANGED.) */
9586 if (BEG
+ BEG_UNCHANGED
== start
9587 && overlay_touches_p (start
))
9589 if (END_UNCHANGED
== end
9590 && overlay_touches_p (Z
- end
))
9599 /* Do a frame update, taking possible shortcuts into account. This is
9600 the main external entry point for redisplay.
9602 If the last redisplay displayed an echo area message and that message
9603 is no longer requested, we clear the echo area or bring back the
9604 mini-buffer if that is in use. */
9609 redisplay_internal (0);
9614 overlay_arrow_string_or_property (var
, pbitmap
)
9618 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9624 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9625 *pbitmap
= XINT (bitmap
);
9630 return Voverlay_arrow_string
;
9633 /* Return 1 if there are any overlay-arrows in current_buffer. */
9635 overlay_arrow_in_current_buffer_p ()
9639 for (vlist
= Voverlay_arrow_variable_list
;
9641 vlist
= XCDR (vlist
))
9643 Lisp_Object var
= XCAR (vlist
);
9648 val
= find_symbol_value (var
);
9650 && current_buffer
== XMARKER (val
)->buffer
)
9657 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9661 overlay_arrows_changed_p ()
9665 for (vlist
= Voverlay_arrow_variable_list
;
9667 vlist
= XCDR (vlist
))
9669 Lisp_Object var
= XCAR (vlist
);
9670 Lisp_Object val
, pstr
;
9674 val
= find_symbol_value (var
);
9677 if (! EQ (COERCE_MARKER (val
),
9678 Fget (var
, Qlast_arrow_position
))
9679 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9680 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9686 /* Mark overlay arrows to be updated on next redisplay. */
9689 update_overlay_arrows (up_to_date
)
9694 for (vlist
= Voverlay_arrow_variable_list
;
9696 vlist
= XCDR (vlist
))
9698 Lisp_Object var
= XCAR (vlist
);
9705 Lisp_Object val
= find_symbol_value (var
);
9706 Fput (var
, Qlast_arrow_position
,
9707 COERCE_MARKER (val
));
9708 Fput (var
, Qlast_arrow_string
,
9709 overlay_arrow_string_or_property (var
, 0));
9711 else if (up_to_date
< 0
9712 || !NILP (Fget (var
, Qlast_arrow_position
)))
9714 Fput (var
, Qlast_arrow_position
, Qt
);
9715 Fput (var
, Qlast_arrow_string
, Qt
);
9721 /* Return overlay arrow string to display at row.
9722 Return t if display as bitmap in left fringe.
9723 Return nil if no overlay arrow. */
9726 overlay_arrow_at_row (it
, row
, pbitmap
)
9728 struct glyph_row
*row
;
9733 for (vlist
= Voverlay_arrow_variable_list
;
9735 vlist
= XCDR (vlist
))
9737 Lisp_Object var
= XCAR (vlist
);
9743 val
= find_symbol_value (var
);
9746 && current_buffer
== XMARKER (val
)->buffer
9747 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9749 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9750 if (FRAME_WINDOW_P (it
->f
)
9751 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9763 /* Return 1 if point moved out of or into a composition. Otherwise
9764 return 0. PREV_BUF and PREV_PT are the last point buffer and
9765 position. BUF and PT are the current point buffer and position. */
9768 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9769 struct buffer
*prev_buf
, *buf
;
9776 XSETBUFFER (buffer
, buf
);
9777 /* Check a composition at the last point if point moved within the
9779 if (prev_buf
== buf
)
9782 /* Point didn't move. */
9785 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9786 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9787 && COMPOSITION_VALID_P (start
, end
, prop
)
9788 && start
< prev_pt
&& end
> prev_pt
)
9789 /* The last point was within the composition. Return 1 iff
9790 point moved out of the composition. */
9791 return (pt
<= start
|| pt
>= end
);
9794 /* Check a composition at the current point. */
9795 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9796 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9797 && COMPOSITION_VALID_P (start
, end
, prop
)
9798 && start
< pt
&& end
> pt
);
9802 /* Reconsider the setting of B->clip_changed which is displayed
9806 reconsider_clip_changes (w
, b
)
9811 && !NILP (w
->window_end_valid
)
9812 && w
->current_matrix
->buffer
== b
9813 && w
->current_matrix
->zv
== BUF_ZV (b
)
9814 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9815 b
->clip_changed
= 0;
9817 /* If display wasn't paused, and W is not a tool bar window, see if
9818 point has been moved into or out of a composition. In that case,
9819 we set b->clip_changed to 1 to force updating the screen. If
9820 b->clip_changed has already been set to 1, we can skip this
9822 if (!b
->clip_changed
9823 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9827 if (w
== XWINDOW (selected_window
))
9828 pt
= BUF_PT (current_buffer
);
9830 pt
= marker_position (w
->pointm
);
9832 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9833 || pt
!= XINT (w
->last_point
))
9834 && check_point_in_composition (w
->current_matrix
->buffer
,
9835 XINT (w
->last_point
),
9836 XBUFFER (w
->buffer
), pt
))
9837 b
->clip_changed
= 1;
9842 /* Select FRAME to forward the values of frame-local variables into C
9843 variables so that the redisplay routines can access those values
9847 select_frame_for_redisplay (frame
)
9850 Lisp_Object tail
, sym
, val
;
9851 Lisp_Object old
= selected_frame
;
9853 selected_frame
= frame
;
9855 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9856 if (CONSP (XCAR (tail
))
9857 && (sym
= XCAR (XCAR (tail
)),
9859 && (sym
= indirect_variable (sym
),
9860 val
= SYMBOL_VALUE (sym
),
9861 (BUFFER_LOCAL_VALUEP (val
)
9862 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9863 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9864 Fsymbol_value (sym
);
9866 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9867 if (CONSP (XCAR (tail
))
9868 && (sym
= XCAR (XCAR (tail
)),
9870 && (sym
= indirect_variable (sym
),
9871 val
= SYMBOL_VALUE (sym
),
9872 (BUFFER_LOCAL_VALUEP (val
)
9873 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9874 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9875 Fsymbol_value (sym
);
9879 #define STOP_POLLING \
9880 do { if (! polling_stopped_here) stop_polling (); \
9881 polling_stopped_here = 1; } while (0)
9883 #define RESUME_POLLING \
9884 do { if (polling_stopped_here) start_polling (); \
9885 polling_stopped_here = 0; } while (0)
9888 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9889 response to any user action; therefore, we should preserve the echo
9890 area. (Actually, our caller does that job.) Perhaps in the future
9891 avoid recentering windows if it is not necessary; currently that
9892 causes some problems. */
9895 redisplay_internal (preserve_echo_area
)
9896 int preserve_echo_area
;
9898 struct window
*w
= XWINDOW (selected_window
);
9899 struct frame
*f
= XFRAME (w
->frame
);
9901 int must_finish
= 0;
9902 struct text_pos tlbufpos
, tlendpos
;
9903 int number_of_visible_frames
;
9905 struct frame
*sf
= SELECTED_FRAME ();
9906 int polling_stopped_here
= 0;
9908 /* Non-zero means redisplay has to consider all windows on all
9909 frames. Zero means, only selected_window is considered. */
9910 int consider_all_windows_p
;
9912 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9914 /* No redisplay if running in batch mode or frame is not yet fully
9915 initialized, or redisplay is explicitly turned off by setting
9916 Vinhibit_redisplay. */
9918 || !NILP (Vinhibit_redisplay
)
9919 || !f
->glyphs_initialized_p
)
9922 /* The flag redisplay_performed_directly_p is set by
9923 direct_output_for_insert when it already did the whole screen
9924 update necessary. */
9925 if (redisplay_performed_directly_p
)
9927 redisplay_performed_directly_p
= 0;
9928 if (!hscroll_windows (selected_window
))
9932 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9933 if (popup_activated ())
9937 /* I don't think this happens but let's be paranoid. */
9941 /* Record a function that resets redisplaying_p to its old value
9942 when we leave this function. */
9943 count
= SPECPDL_INDEX ();
9944 record_unwind_protect (unwind_redisplay
,
9945 Fcons (make_number (redisplaying_p
), selected_frame
));
9947 specbind (Qinhibit_free_realized_faces
, Qnil
);
9951 reconsider_clip_changes (w
, current_buffer
);
9953 /* If new fonts have been loaded that make a glyph matrix adjustment
9954 necessary, do it. */
9955 if (fonts_changed_p
)
9957 adjust_glyphs (NULL
);
9958 ++windows_or_buffers_changed
;
9959 fonts_changed_p
= 0;
9962 /* If face_change_count is non-zero, init_iterator will free all
9963 realized faces, which includes the faces referenced from current
9964 matrices. So, we can't reuse current matrices in this case. */
9965 if (face_change_count
)
9966 ++windows_or_buffers_changed
;
9968 if (! FRAME_WINDOW_P (sf
)
9969 && previous_terminal_frame
!= sf
)
9971 /* Since frames on an ASCII terminal share the same display
9972 area, displaying a different frame means redisplay the whole
9974 windows_or_buffers_changed
++;
9975 SET_FRAME_GARBAGED (sf
);
9976 XSETFRAME (Vterminal_frame
, sf
);
9978 previous_terminal_frame
= sf
;
9980 /* Set the visible flags for all frames. Do this before checking
9981 for resized or garbaged frames; they want to know if their frames
9982 are visible. See the comment in frame.h for
9983 FRAME_SAMPLE_VISIBILITY. */
9985 Lisp_Object tail
, frame
;
9987 number_of_visible_frames
= 0;
9989 FOR_EACH_FRAME (tail
, frame
)
9991 struct frame
*f
= XFRAME (frame
);
9993 FRAME_SAMPLE_VISIBILITY (f
);
9994 if (FRAME_VISIBLE_P (f
))
9995 ++number_of_visible_frames
;
9996 clear_desired_matrices (f
);
10000 /* Notice any pending interrupt request to change frame size. */
10001 do_pending_window_change (1);
10003 /* Clear frames marked as garbaged. */
10004 if (frame_garbaged
)
10005 clear_garbaged_frames ();
10007 /* Build menubar and tool-bar items. */
10008 prepare_menu_bars ();
10010 if (windows_or_buffers_changed
)
10011 update_mode_lines
++;
10013 /* Detect case that we need to write or remove a star in the mode line. */
10014 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10016 w
->update_mode_line
= Qt
;
10017 if (buffer_shared
> 1)
10018 update_mode_lines
++;
10021 /* If %c is in the mode line, update it if needed. */
10022 if (!NILP (w
->column_number_displayed
)
10023 /* This alternative quickly identifies a common case
10024 where no change is needed. */
10025 && !(PT
== XFASTINT (w
->last_point
)
10026 && XFASTINT (w
->last_modified
) >= MODIFF
10027 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10028 && (XFASTINT (w
->column_number_displayed
)
10029 != (int) current_column ())) /* iftc */
10030 w
->update_mode_line
= Qt
;
10032 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10034 /* The variable buffer_shared is set in redisplay_window and
10035 indicates that we redisplay a buffer in different windows. See
10037 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10038 || cursor_type_changed
);
10040 /* If specs for an arrow have changed, do thorough redisplay
10041 to ensure we remove any arrow that should no longer exist. */
10042 if (overlay_arrows_changed_p ())
10043 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10045 /* Normally the message* functions will have already displayed and
10046 updated the echo area, but the frame may have been trashed, or
10047 the update may have been preempted, so display the echo area
10048 again here. Checking message_cleared_p captures the case that
10049 the echo area should be cleared. */
10050 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10051 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10052 || (message_cleared_p
10053 && minibuf_level
== 0
10054 /* If the mini-window is currently selected, this means the
10055 echo-area doesn't show through. */
10056 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10058 int window_height_changed_p
= echo_area_display (0);
10061 /* If we don't display the current message, don't clear the
10062 message_cleared_p flag, because, if we did, we wouldn't clear
10063 the echo area in the next redisplay which doesn't preserve
10065 if (!display_last_displayed_message_p
)
10066 message_cleared_p
= 0;
10068 if (fonts_changed_p
)
10070 else if (window_height_changed_p
)
10072 consider_all_windows_p
= 1;
10073 ++update_mode_lines
;
10074 ++windows_or_buffers_changed
;
10076 /* If window configuration was changed, frames may have been
10077 marked garbaged. Clear them or we will experience
10078 surprises wrt scrolling. */
10079 if (frame_garbaged
)
10080 clear_garbaged_frames ();
10083 else if (EQ (selected_window
, minibuf_window
)
10084 && (current_buffer
->clip_changed
10085 || XFASTINT (w
->last_modified
) < MODIFF
10086 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10087 && resize_mini_window (w
, 0))
10089 /* Resized active mini-window to fit the size of what it is
10090 showing if its contents might have changed. */
10092 consider_all_windows_p
= 1;
10093 ++windows_or_buffers_changed
;
10094 ++update_mode_lines
;
10096 /* If window configuration was changed, frames may have been
10097 marked garbaged. Clear them or we will experience
10098 surprises wrt scrolling. */
10099 if (frame_garbaged
)
10100 clear_garbaged_frames ();
10104 /* If showing the region, and mark has changed, we must redisplay
10105 the whole window. The assignment to this_line_start_pos prevents
10106 the optimization directly below this if-statement. */
10107 if (((!NILP (Vtransient_mark_mode
)
10108 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10109 != !NILP (w
->region_showing
))
10110 || (!NILP (w
->region_showing
)
10111 && !EQ (w
->region_showing
,
10112 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10113 CHARPOS (this_line_start_pos
) = 0;
10115 /* Optimize the case that only the line containing the cursor in the
10116 selected window has changed. Variables starting with this_ are
10117 set in display_line and record information about the line
10118 containing the cursor. */
10119 tlbufpos
= this_line_start_pos
;
10120 tlendpos
= this_line_end_pos
;
10121 if (!consider_all_windows_p
10122 && CHARPOS (tlbufpos
) > 0
10123 && NILP (w
->update_mode_line
)
10124 && !current_buffer
->clip_changed
10125 && !current_buffer
->prevent_redisplay_optimizations_p
10126 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10127 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10128 /* Make sure recorded data applies to current buffer, etc. */
10129 && this_line_buffer
== current_buffer
10130 && current_buffer
== XBUFFER (w
->buffer
)
10131 && NILP (w
->force_start
)
10132 && NILP (w
->optional_new_start
)
10133 /* Point must be on the line that we have info recorded about. */
10134 && PT
>= CHARPOS (tlbufpos
)
10135 && PT
<= Z
- CHARPOS (tlendpos
)
10136 /* All text outside that line, including its final newline,
10137 must be unchanged */
10138 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10139 CHARPOS (tlendpos
)))
10141 if (CHARPOS (tlbufpos
) > BEGV
10142 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10143 && (CHARPOS (tlbufpos
) == ZV
10144 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10145 /* Former continuation line has disappeared by becoming empty */
10147 else if (XFASTINT (w
->last_modified
) < MODIFF
10148 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10149 || MINI_WINDOW_P (w
))
10151 /* We have to handle the case of continuation around a
10152 wide-column character (See the comment in indent.c around
10155 For instance, in the following case:
10157 -------- Insert --------
10158 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10159 J_I_ ==> J_I_ `^^' are cursors.
10163 As we have to redraw the line above, we should goto cancel. */
10166 int line_height_before
= this_line_pixel_height
;
10168 /* Note that start_display will handle the case that the
10169 line starting at tlbufpos is a continuation lines. */
10170 start_display (&it
, w
, tlbufpos
);
10172 /* Implementation note: It this still necessary? */
10173 if (it
.current_x
!= this_line_start_x
)
10176 TRACE ((stderr
, "trying display optimization 1\n"));
10177 w
->cursor
.vpos
= -1;
10178 overlay_arrow_seen
= 0;
10179 it
.vpos
= this_line_vpos
;
10180 it
.current_y
= this_line_y
;
10181 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10182 display_line (&it
);
10184 /* If line contains point, is not continued,
10185 and ends at same distance from eob as before, we win */
10186 if (w
->cursor
.vpos
>= 0
10187 /* Line is not continued, otherwise this_line_start_pos
10188 would have been set to 0 in display_line. */
10189 && CHARPOS (this_line_start_pos
)
10190 /* Line ends as before. */
10191 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10192 /* Line has same height as before. Otherwise other lines
10193 would have to be shifted up or down. */
10194 && this_line_pixel_height
== line_height_before
)
10196 /* If this is not the window's last line, we must adjust
10197 the charstarts of the lines below. */
10198 if (it
.current_y
< it
.last_visible_y
)
10200 struct glyph_row
*row
10201 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10202 int delta
, delta_bytes
;
10204 if (Z
- CHARPOS (tlendpos
) == ZV
)
10206 /* This line ends at end of (accessible part of)
10207 buffer. There is no newline to count. */
10209 - CHARPOS (tlendpos
)
10210 - MATRIX_ROW_START_CHARPOS (row
));
10211 delta_bytes
= (Z_BYTE
10212 - BYTEPOS (tlendpos
)
10213 - MATRIX_ROW_START_BYTEPOS (row
));
10217 /* This line ends in a newline. Must take
10218 account of the newline and the rest of the
10219 text that follows. */
10221 - CHARPOS (tlendpos
)
10222 - MATRIX_ROW_START_CHARPOS (row
));
10223 delta_bytes
= (Z_BYTE
10224 - BYTEPOS (tlendpos
)
10225 - MATRIX_ROW_START_BYTEPOS (row
));
10228 increment_matrix_positions (w
->current_matrix
,
10229 this_line_vpos
+ 1,
10230 w
->current_matrix
->nrows
,
10231 delta
, delta_bytes
);
10234 /* If this row displays text now but previously didn't,
10235 or vice versa, w->window_end_vpos may have to be
10237 if ((it
.glyph_row
- 1)->displays_text_p
)
10239 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10240 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10242 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10243 && this_line_vpos
> 0)
10244 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10245 w
->window_end_valid
= Qnil
;
10247 /* Update hint: No need to try to scroll in update_window. */
10248 w
->desired_matrix
->no_scrolling_p
= 1;
10251 *w
->desired_matrix
->method
= 0;
10252 debug_method_add (w
, "optimization 1");
10254 #ifdef HAVE_WINDOW_SYSTEM
10255 update_window_fringes (w
, 0);
10262 else if (/* Cursor position hasn't changed. */
10263 PT
== XFASTINT (w
->last_point
)
10264 /* Make sure the cursor was last displayed
10265 in this window. Otherwise we have to reposition it. */
10266 && 0 <= w
->cursor
.vpos
10267 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10271 do_pending_window_change (1);
10273 /* We used to always goto end_of_redisplay here, but this
10274 isn't enough if we have a blinking cursor. */
10275 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10276 goto end_of_redisplay
;
10280 /* If highlighting the region, or if the cursor is in the echo area,
10281 then we can't just move the cursor. */
10282 else if (! (!NILP (Vtransient_mark_mode
)
10283 && !NILP (current_buffer
->mark_active
))
10284 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10285 || highlight_nonselected_windows
)
10286 && NILP (w
->region_showing
)
10287 && NILP (Vshow_trailing_whitespace
)
10288 && !cursor_in_echo_area
)
10291 struct glyph_row
*row
;
10293 /* Skip from tlbufpos to PT and see where it is. Note that
10294 PT may be in invisible text. If so, we will end at the
10295 next visible position. */
10296 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10297 NULL
, DEFAULT_FACE_ID
);
10298 it
.current_x
= this_line_start_x
;
10299 it
.current_y
= this_line_y
;
10300 it
.vpos
= this_line_vpos
;
10302 /* The call to move_it_to stops in front of PT, but
10303 moves over before-strings. */
10304 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10306 if (it
.vpos
== this_line_vpos
10307 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10310 xassert (this_line_vpos
== it
.vpos
);
10311 xassert (this_line_y
== it
.current_y
);
10312 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10314 *w
->desired_matrix
->method
= 0;
10315 debug_method_add (w
, "optimization 3");
10324 /* Text changed drastically or point moved off of line. */
10325 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10328 CHARPOS (this_line_start_pos
) = 0;
10329 consider_all_windows_p
|= buffer_shared
> 1;
10330 ++clear_face_cache_count
;
10333 /* Build desired matrices, and update the display. If
10334 consider_all_windows_p is non-zero, do it for all windows on all
10335 frames. Otherwise do it for selected_window, only. */
10337 if (consider_all_windows_p
)
10339 Lisp_Object tail
, frame
;
10340 int i
, n
= 0, size
= 50;
10341 struct frame
**updated
10342 = (struct frame
**) alloca (size
* sizeof *updated
);
10344 /* Clear the face cache eventually. */
10345 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10347 clear_face_cache (0);
10348 clear_face_cache_count
= 0;
10351 /* Recompute # windows showing selected buffer. This will be
10352 incremented each time such a window is displayed. */
10355 FOR_EACH_FRAME (tail
, frame
)
10357 struct frame
*f
= XFRAME (frame
);
10359 if (FRAME_WINDOW_P (f
) || f
== sf
)
10361 if (! EQ (frame
, selected_frame
))
10362 /* Select the frame, for the sake of frame-local
10364 select_frame_for_redisplay (frame
);
10366 #ifdef HAVE_WINDOW_SYSTEM
10367 if (clear_face_cache_count
% 50 == 0
10368 && FRAME_WINDOW_P (f
))
10369 clear_image_cache (f
, 0);
10370 #endif /* HAVE_WINDOW_SYSTEM */
10372 /* Mark all the scroll bars to be removed; we'll redeem
10373 the ones we want when we redisplay their windows. */
10374 if (condemn_scroll_bars_hook
)
10375 condemn_scroll_bars_hook (f
);
10377 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10378 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10380 /* Any scroll bars which redisplay_windows should have
10381 nuked should now go away. */
10382 if (judge_scroll_bars_hook
)
10383 judge_scroll_bars_hook (f
);
10385 /* If fonts changed, display again. */
10386 /* ??? rms: I suspect it is a mistake to jump all the way
10387 back to retry here. It should just retry this frame. */
10388 if (fonts_changed_p
)
10391 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10393 /* See if we have to hscroll. */
10394 if (hscroll_windows (f
->root_window
))
10397 /* Prevent various kinds of signals during display
10398 update. stdio is not robust about handling
10399 signals, which can cause an apparent I/O
10401 if (interrupt_input
)
10402 unrequest_sigio ();
10405 /* Update the display. */
10406 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10407 pause
|= update_frame (f
, 0, 0);
10408 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10415 int nbytes
= size
* sizeof *updated
;
10416 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10417 bcopy (updated
, p
, nbytes
);
10428 /* Do the mark_window_display_accurate after all windows have
10429 been redisplayed because this call resets flags in buffers
10430 which are needed for proper redisplay. */
10431 for (i
= 0; i
< n
; ++i
)
10433 struct frame
*f
= updated
[i
];
10434 mark_window_display_accurate (f
->root_window
, 1);
10435 if (frame_up_to_date_hook
)
10436 frame_up_to_date_hook (f
);
10440 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10442 Lisp_Object mini_window
;
10443 struct frame
*mini_frame
;
10445 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10446 /* Use list_of_error, not Qerror, so that
10447 we catch only errors and don't run the debugger. */
10448 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10450 redisplay_window_error
);
10452 /* Compare desired and current matrices, perform output. */
10455 /* If fonts changed, display again. */
10456 if (fonts_changed_p
)
10459 /* Prevent various kinds of signals during display update.
10460 stdio is not robust about handling signals,
10461 which can cause an apparent I/O error. */
10462 if (interrupt_input
)
10463 unrequest_sigio ();
10466 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10468 if (hscroll_windows (selected_window
))
10471 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10472 pause
= update_frame (sf
, 0, 0);
10475 /* We may have called echo_area_display at the top of this
10476 function. If the echo area is on another frame, that may
10477 have put text on a frame other than the selected one, so the
10478 above call to update_frame would not have caught it. Catch
10480 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10481 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10483 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10485 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10486 pause
|= update_frame (mini_frame
, 0, 0);
10487 if (!pause
&& hscroll_windows (mini_window
))
10492 /* If display was paused because of pending input, make sure we do a
10493 thorough update the next time. */
10496 /* Prevent the optimization at the beginning of
10497 redisplay_internal that tries a single-line update of the
10498 line containing the cursor in the selected window. */
10499 CHARPOS (this_line_start_pos
) = 0;
10501 /* Let the overlay arrow be updated the next time. */
10502 update_overlay_arrows (0);
10504 /* If we pause after scrolling, some rows in the current
10505 matrices of some windows are not valid. */
10506 if (!WINDOW_FULL_WIDTH_P (w
)
10507 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10508 update_mode_lines
= 1;
10512 if (!consider_all_windows_p
)
10514 /* This has already been done above if
10515 consider_all_windows_p is set. */
10516 mark_window_display_accurate_1 (w
, 1);
10518 /* Say overlay arrows are up to date. */
10519 update_overlay_arrows (1);
10521 if (frame_up_to_date_hook
!= 0)
10522 frame_up_to_date_hook (sf
);
10525 update_mode_lines
= 0;
10526 windows_or_buffers_changed
= 0;
10527 cursor_type_changed
= 0;
10530 /* Start SIGIO interrupts coming again. Having them off during the
10531 code above makes it less likely one will discard output, but not
10532 impossible, since there might be stuff in the system buffer here.
10533 But it is much hairier to try to do anything about that. */
10534 if (interrupt_input
)
10538 /* If a frame has become visible which was not before, redisplay
10539 again, so that we display it. Expose events for such a frame
10540 (which it gets when becoming visible) don't call the parts of
10541 redisplay constructing glyphs, so simply exposing a frame won't
10542 display anything in this case. So, we have to display these
10543 frames here explicitly. */
10546 Lisp_Object tail
, frame
;
10549 FOR_EACH_FRAME (tail
, frame
)
10551 int this_is_visible
= 0;
10553 if (XFRAME (frame
)->visible
)
10554 this_is_visible
= 1;
10555 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10556 if (XFRAME (frame
)->visible
)
10557 this_is_visible
= 1;
10559 if (this_is_visible
)
10563 if (new_count
!= number_of_visible_frames
)
10564 windows_or_buffers_changed
++;
10567 /* Change frame size now if a change is pending. */
10568 do_pending_window_change (1);
10570 /* If we just did a pending size change, or have additional
10571 visible frames, redisplay again. */
10572 if (windows_or_buffers_changed
&& !pause
)
10576 unbind_to (count
, Qnil
);
10581 /* Redisplay, but leave alone any recent echo area message unless
10582 another message has been requested in its place.
10584 This is useful in situations where you need to redisplay but no
10585 user action has occurred, making it inappropriate for the message
10586 area to be cleared. See tracking_off and
10587 wait_reading_process_output for examples of these situations.
10589 FROM_WHERE is an integer saying from where this function was
10590 called. This is useful for debugging. */
10593 redisplay_preserve_echo_area (from_where
)
10596 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10598 if (!NILP (echo_area_buffer
[1]))
10600 /* We have a previously displayed message, but no current
10601 message. Redisplay the previous message. */
10602 display_last_displayed_message_p
= 1;
10603 redisplay_internal (1);
10604 display_last_displayed_message_p
= 0;
10607 redisplay_internal (1);
10609 if (rif
!= NULL
&& rif
->flush_display_optional
)
10610 rif
->flush_display_optional (NULL
);
10614 /* Function registered with record_unwind_protect in
10615 redisplay_internal. Reset redisplaying_p to the value it had
10616 before redisplay_internal was called, and clear
10617 prevent_freeing_realized_faces_p. It also selects the previously
10621 unwind_redisplay (val
)
10624 Lisp_Object old_redisplaying_p
, old_frame
;
10626 old_redisplaying_p
= XCAR (val
);
10627 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10628 old_frame
= XCDR (val
);
10629 if (! EQ (old_frame
, selected_frame
))
10630 select_frame_for_redisplay (old_frame
);
10635 /* Mark the display of window W as accurate or inaccurate. If
10636 ACCURATE_P is non-zero mark display of W as accurate. If
10637 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10638 redisplay_internal is called. */
10641 mark_window_display_accurate_1 (w
, accurate_p
)
10645 if (BUFFERP (w
->buffer
))
10647 struct buffer
*b
= XBUFFER (w
->buffer
);
10650 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10651 w
->last_overlay_modified
10652 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10654 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10658 b
->clip_changed
= 0;
10659 b
->prevent_redisplay_optimizations_p
= 0;
10661 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10662 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10663 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10664 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10666 w
->current_matrix
->buffer
= b
;
10667 w
->current_matrix
->begv
= BUF_BEGV (b
);
10668 w
->current_matrix
->zv
= BUF_ZV (b
);
10670 w
->last_cursor
= w
->cursor
;
10671 w
->last_cursor_off_p
= w
->cursor_off_p
;
10673 if (w
== XWINDOW (selected_window
))
10674 w
->last_point
= make_number (BUF_PT (b
));
10676 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10682 w
->window_end_valid
= w
->buffer
;
10683 #if 0 /* This is incorrect with variable-height lines. */
10684 xassert (XINT (w
->window_end_vpos
)
10685 < (WINDOW_TOTAL_LINES (w
)
10686 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10688 w
->update_mode_line
= Qnil
;
10693 /* Mark the display of windows in the window tree rooted at WINDOW as
10694 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10695 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10696 be redisplayed the next time redisplay_internal is called. */
10699 mark_window_display_accurate (window
, accurate_p
)
10700 Lisp_Object window
;
10705 for (; !NILP (window
); window
= w
->next
)
10707 w
= XWINDOW (window
);
10708 mark_window_display_accurate_1 (w
, accurate_p
);
10710 if (!NILP (w
->vchild
))
10711 mark_window_display_accurate (w
->vchild
, accurate_p
);
10712 if (!NILP (w
->hchild
))
10713 mark_window_display_accurate (w
->hchild
, accurate_p
);
10718 update_overlay_arrows (1);
10722 /* Force a thorough redisplay the next time by setting
10723 last_arrow_position and last_arrow_string to t, which is
10724 unequal to any useful value of Voverlay_arrow_... */
10725 update_overlay_arrows (-1);
10730 /* Return value in display table DP (Lisp_Char_Table *) for character
10731 C. Since a display table doesn't have any parent, we don't have to
10732 follow parent. Do not call this function directly but use the
10733 macro DISP_CHAR_VECTOR. */
10736 disp_char_vector (dp
, c
)
10737 struct Lisp_Char_Table
*dp
;
10743 if (SINGLE_BYTE_CHAR_P (c
))
10744 return (dp
->contents
[c
]);
10746 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10749 else if (code
[2] < 32)
10752 /* Here, the possible range of code[0] (== charset ID) is
10753 128..max_charset. Since the top level char table contains data
10754 for multibyte characters after 256th element, we must increment
10755 code[0] by 128 to get a correct index. */
10757 code
[3] = -1; /* anchor */
10759 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10761 val
= dp
->contents
[code
[i
]];
10762 if (!SUB_CHAR_TABLE_P (val
))
10763 return (NILP (val
) ? dp
->defalt
: val
);
10766 /* Here, val is a sub char table. We return the default value of
10768 return (dp
->defalt
);
10773 /***********************************************************************
10775 ***********************************************************************/
10777 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10780 redisplay_windows (window
)
10781 Lisp_Object window
;
10783 while (!NILP (window
))
10785 struct window
*w
= XWINDOW (window
);
10787 if (!NILP (w
->hchild
))
10788 redisplay_windows (w
->hchild
);
10789 else if (!NILP (w
->vchild
))
10790 redisplay_windows (w
->vchild
);
10793 displayed_buffer
= XBUFFER (w
->buffer
);
10794 /* Use list_of_error, not Qerror, so that
10795 we catch only errors and don't run the debugger. */
10796 internal_condition_case_1 (redisplay_window_0
, window
,
10798 redisplay_window_error
);
10806 redisplay_window_error ()
10808 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10813 redisplay_window_0 (window
)
10814 Lisp_Object window
;
10816 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10817 redisplay_window (window
, 0);
10822 redisplay_window_1 (window
)
10823 Lisp_Object window
;
10825 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10826 redisplay_window (window
, 1);
10831 /* Increment GLYPH until it reaches END or CONDITION fails while
10832 adding (GLYPH)->pixel_width to X. */
10834 #define SKIP_GLYPHS(glyph, end, x, condition) \
10837 (x) += (glyph)->pixel_width; \
10840 while ((glyph) < (end) && (condition))
10843 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10844 DELTA is the number of bytes by which positions recorded in ROW
10845 differ from current buffer positions. */
10848 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10850 struct glyph_row
*row
;
10851 struct glyph_matrix
*matrix
;
10852 int delta
, delta_bytes
, dy
, dvpos
;
10854 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10855 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10856 struct glyph
*cursor
= NULL
;
10857 /* The first glyph that starts a sequence of glyphs from string. */
10858 struct glyph
*string_start
;
10859 /* The X coordinate of string_start. */
10860 int string_start_x
;
10861 /* The last known character position. */
10862 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10863 /* The last known character position before string_start. */
10864 int string_before_pos
;
10867 int cursor_from_overlay_pos
= 0;
10868 int pt_old
= PT
- delta
;
10870 /* Skip over glyphs not having an object at the start of the row.
10871 These are special glyphs like truncation marks on terminal
10873 if (row
->displays_text_p
)
10875 && INTEGERP (glyph
->object
)
10876 && glyph
->charpos
< 0)
10878 x
+= glyph
->pixel_width
;
10882 string_start
= NULL
;
10884 && !INTEGERP (glyph
->object
)
10885 && (!BUFFERP (glyph
->object
)
10886 || (last_pos
= glyph
->charpos
) < pt_old
))
10888 if (! STRINGP (glyph
->object
))
10890 string_start
= NULL
;
10891 x
+= glyph
->pixel_width
;
10893 if (cursor_from_overlay_pos
10894 && last_pos
> cursor_from_overlay_pos
)
10896 cursor_from_overlay_pos
= 0;
10902 string_before_pos
= last_pos
;
10903 string_start
= glyph
;
10904 string_start_x
= x
;
10905 /* Skip all glyphs from string. */
10909 if ((cursor
== NULL
|| glyph
> cursor
)
10910 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
10911 Qcursor
, (glyph
)->object
))
10912 && (pos
= string_buffer_position (w
, glyph
->object
,
10913 string_before_pos
),
10914 (pos
== 0 /* From overlay */
10915 || pos
== pt_old
)))
10917 /* Estimate overlay buffer position from the buffer
10918 positions of the glyphs before and after the overlay.
10919 Add 1 to last_pos so that if point corresponds to the
10920 glyph right after the overlay, we still use a 'cursor'
10921 property found in that overlay. */
10922 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
10926 x
+= glyph
->pixel_width
;
10929 while (glyph
< end
&& STRINGP (glyph
->object
));
10933 if (cursor
!= NULL
)
10938 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
10940 /* Scan back over the ellipsis glyphs, decrementing positions. */
10941 while (glyph
> row
->glyphs
[TEXT_AREA
]
10942 && (glyph
- 1)->charpos
== last_pos
)
10943 glyph
--, x
-= glyph
->pixel_width
;
10944 /* That loop always goes one position too far,
10945 including the glyph before the ellipsis.
10946 So scan forward over that one. */
10947 x
+= glyph
->pixel_width
;
10950 else if (string_start
10951 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10953 /* We may have skipped over point because the previous glyphs
10954 are from string. As there's no easy way to know the
10955 character position of the current glyph, find the correct
10956 glyph on point by scanning from string_start again. */
10958 Lisp_Object string
;
10961 limit
= make_number (pt_old
+ 1);
10963 glyph
= string_start
;
10964 x
= string_start_x
;
10965 string
= glyph
->object
;
10966 pos
= string_buffer_position (w
, string
, string_before_pos
);
10967 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10968 because we always put cursor after overlay strings. */
10969 while (pos
== 0 && glyph
< end
)
10971 string
= glyph
->object
;
10972 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10974 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10977 while (glyph
< end
)
10979 pos
= XINT (Fnext_single_char_property_change
10980 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10983 /* Skip glyphs from the same string. */
10984 string
= glyph
->object
;
10985 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10986 /* Skip glyphs from an overlay. */
10988 && ! string_buffer_position (w
, glyph
->object
, pos
))
10990 string
= glyph
->object
;
10991 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10996 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10998 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10999 w
->cursor
.y
= row
->y
+ dy
;
11001 if (w
== XWINDOW (selected_window
))
11003 if (!row
->continued_p
11004 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11007 this_line_buffer
= XBUFFER (w
->buffer
);
11009 CHARPOS (this_line_start_pos
)
11010 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11011 BYTEPOS (this_line_start_pos
)
11012 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11014 CHARPOS (this_line_end_pos
)
11015 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11016 BYTEPOS (this_line_end_pos
)
11017 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11019 this_line_y
= w
->cursor
.y
;
11020 this_line_pixel_height
= row
->height
;
11021 this_line_vpos
= w
->cursor
.vpos
;
11022 this_line_start_x
= row
->x
;
11025 CHARPOS (this_line_start_pos
) = 0;
11030 /* Run window scroll functions, if any, for WINDOW with new window
11031 start STARTP. Sets the window start of WINDOW to that position.
11033 We assume that the window's buffer is really current. */
11035 static INLINE
struct text_pos
11036 run_window_scroll_functions (window
, startp
)
11037 Lisp_Object window
;
11038 struct text_pos startp
;
11040 struct window
*w
= XWINDOW (window
);
11041 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11043 if (current_buffer
!= XBUFFER (w
->buffer
))
11046 if (!NILP (Vwindow_scroll_functions
))
11048 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11049 make_number (CHARPOS (startp
)));
11050 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11051 /* In case the hook functions switch buffers. */
11052 if (current_buffer
!= XBUFFER (w
->buffer
))
11053 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11060 /* Make sure the line containing the cursor is fully visible.
11061 A value of 1 means there is nothing to be done.
11062 (Either the line is fully visible, or it cannot be made so,
11063 or we cannot tell.)
11065 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11066 is higher than window.
11068 A value of 0 means the caller should do scrolling
11069 as if point had gone off the screen. */
11072 make_cursor_line_fully_visible (w
, force_p
)
11076 struct glyph_matrix
*matrix
;
11077 struct glyph_row
*row
;
11080 if (!make_cursor_line_fully_visible_p
)
11083 /* It's not always possible to find the cursor, e.g, when a window
11084 is full of overlay strings. Don't do anything in that case. */
11085 if (w
->cursor
.vpos
< 0)
11088 matrix
= w
->desired_matrix
;
11089 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11091 /* If the cursor row is not partially visible, there's nothing to do. */
11092 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11095 /* If the row the cursor is in is taller than the window's height,
11096 it's not clear what to do, so do nothing. */
11097 window_height
= window_box_height (w
);
11098 if (row
->height
>= window_height
)
11100 if (!force_p
|| w
->vscroll
)
11106 /* This code used to try to scroll the window just enough to make
11107 the line visible. It returned 0 to say that the caller should
11108 allocate larger glyph matrices. */
11110 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11112 int dy
= row
->height
- row
->visible_height
;
11115 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11117 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11119 int dy
= - (row
->height
- row
->visible_height
);
11122 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11125 /* When we change the cursor y-position of the selected window,
11126 change this_line_y as well so that the display optimization for
11127 the cursor line of the selected window in redisplay_internal uses
11128 the correct y-position. */
11129 if (w
== XWINDOW (selected_window
))
11130 this_line_y
= w
->cursor
.y
;
11132 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11133 redisplay with larger matrices. */
11134 if (matrix
->nrows
< required_matrix_height (w
))
11136 fonts_changed_p
= 1;
11145 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11146 non-zero means only WINDOW is redisplayed in redisplay_internal.
11147 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11148 in redisplay_window to bring a partially visible line into view in
11149 the case that only the cursor has moved.
11151 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11152 last screen line's vertical height extends past the end of the screen.
11156 1 if scrolling succeeded
11158 0 if scrolling didn't find point.
11160 -1 if new fonts have been loaded so that we must interrupt
11161 redisplay, adjust glyph matrices, and try again. */
11167 SCROLLING_NEED_LARGER_MATRICES
11171 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11172 scroll_step
, temp_scroll_step
, last_line_misfit
)
11173 Lisp_Object window
;
11174 int just_this_one_p
;
11175 EMACS_INT scroll_conservatively
, scroll_step
;
11176 int temp_scroll_step
;
11177 int last_line_misfit
;
11179 struct window
*w
= XWINDOW (window
);
11180 struct frame
*f
= XFRAME (w
->frame
);
11181 struct text_pos scroll_margin_pos
;
11182 struct text_pos pos
;
11183 struct text_pos startp
;
11185 Lisp_Object window_end
;
11186 int this_scroll_margin
;
11190 int amount_to_scroll
= 0;
11191 Lisp_Object aggressive
;
11193 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11196 debug_method_add (w
, "try_scrolling");
11199 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11201 /* Compute scroll margin height in pixels. We scroll when point is
11202 within this distance from the top or bottom of the window. */
11203 if (scroll_margin
> 0)
11205 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11206 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11209 this_scroll_margin
= 0;
11211 /* Force scroll_conservatively to have a reasonable value so it doesn't
11212 cause an overflow while computing how much to scroll. */
11213 if (scroll_conservatively
)
11214 scroll_conservatively
= min (scroll_conservatively
,
11215 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11217 /* Compute how much we should try to scroll maximally to bring point
11219 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11220 scroll_max
= max (scroll_step
,
11221 max (scroll_conservatively
, temp_scroll_step
));
11222 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11223 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11224 /* We're trying to scroll because of aggressive scrolling
11225 but no scroll_step is set. Choose an arbitrary one. Maybe
11226 there should be a variable for this. */
11230 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11232 /* Decide whether we have to scroll down. Start at the window end
11233 and move this_scroll_margin up to find the position of the scroll
11235 window_end
= Fwindow_end (window
, Qt
);
11239 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11240 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11242 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11244 start_display (&it
, w
, scroll_margin_pos
);
11245 if (this_scroll_margin
)
11246 move_it_vertically_backward (&it
, this_scroll_margin
);
11247 if (extra_scroll_margin_lines
)
11248 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11249 scroll_margin_pos
= it
.current
.pos
;
11252 if (PT
>= CHARPOS (scroll_margin_pos
))
11256 /* Point is in the scroll margin at the bottom of the window, or
11257 below. Compute a new window start that makes point visible. */
11259 /* Compute the distance from the scroll margin to PT.
11260 Give up if the distance is greater than scroll_max. */
11261 start_display (&it
, w
, scroll_margin_pos
);
11263 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11264 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11266 /* To make point visible, we have to move the window start
11267 down so that the line the cursor is in is visible, which
11268 means we have to add in the height of the cursor line. */
11269 dy
= line_bottom_y (&it
) - y0
;
11271 if (dy
> scroll_max
)
11272 return SCROLLING_FAILED
;
11274 /* Move the window start down. If scrolling conservatively,
11275 move it just enough down to make point visible. If
11276 scroll_step is set, move it down by scroll_step. */
11277 start_display (&it
, w
, startp
);
11279 if (scroll_conservatively
)
11280 /* Set AMOUNT_TO_SCROLL to at least one line,
11281 and at most scroll_conservatively lines. */
11283 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11284 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11285 else if (scroll_step
|| temp_scroll_step
)
11286 amount_to_scroll
= scroll_max
;
11289 aggressive
= current_buffer
->scroll_up_aggressively
;
11290 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11291 if (NUMBERP (aggressive
))
11293 double float_amount
= XFLOATINT (aggressive
) * height
;
11294 amount_to_scroll
= float_amount
;
11295 if (amount_to_scroll
== 0 && float_amount
> 0)
11296 amount_to_scroll
= 1;
11300 if (amount_to_scroll
<= 0)
11301 return SCROLLING_FAILED
;
11303 /* If moving by amount_to_scroll leaves STARTP unchanged,
11304 move it down one screen line. */
11306 move_it_vertically (&it
, amount_to_scroll
);
11307 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11308 move_it_by_lines (&it
, 1, 1);
11309 startp
= it
.current
.pos
;
11313 /* See if point is inside the scroll margin at the top of the
11315 scroll_margin_pos
= startp
;
11316 if (this_scroll_margin
)
11318 start_display (&it
, w
, startp
);
11319 move_it_vertically (&it
, this_scroll_margin
);
11320 scroll_margin_pos
= it
.current
.pos
;
11323 if (PT
< CHARPOS (scroll_margin_pos
))
11325 /* Point is in the scroll margin at the top of the window or
11326 above what is displayed in the window. */
11329 /* Compute the vertical distance from PT to the scroll
11330 margin position. Give up if distance is greater than
11332 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11333 start_display (&it
, w
, pos
);
11335 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11336 it
.last_visible_y
, -1,
11337 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11338 dy
= it
.current_y
- y0
;
11339 if (dy
> scroll_max
)
11340 return SCROLLING_FAILED
;
11342 /* Compute new window start. */
11343 start_display (&it
, w
, startp
);
11345 if (scroll_conservatively
)
11347 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11348 else if (scroll_step
|| temp_scroll_step
)
11349 amount_to_scroll
= scroll_max
;
11352 aggressive
= current_buffer
->scroll_down_aggressively
;
11353 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11354 if (NUMBERP (aggressive
))
11356 double float_amount
= XFLOATINT (aggressive
) * height
;
11357 amount_to_scroll
= float_amount
;
11358 if (amount_to_scroll
== 0 && float_amount
> 0)
11359 amount_to_scroll
= 1;
11363 if (amount_to_scroll
<= 0)
11364 return SCROLLING_FAILED
;
11366 move_it_vertically_backward (&it
, amount_to_scroll
);
11367 startp
= it
.current
.pos
;
11371 /* Run window scroll functions. */
11372 startp
= run_window_scroll_functions (window
, startp
);
11374 /* Display the window. Give up if new fonts are loaded, or if point
11376 if (!try_window (window
, startp
))
11377 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11378 else if (w
->cursor
.vpos
< 0)
11380 clear_glyph_matrix (w
->desired_matrix
);
11381 rc
= SCROLLING_FAILED
;
11385 /* Maybe forget recorded base line for line number display. */
11386 if (!just_this_one_p
11387 || current_buffer
->clip_changed
11388 || BEG_UNCHANGED
< CHARPOS (startp
))
11389 w
->base_line_number
= Qnil
;
11391 /* If cursor ends up on a partially visible line,
11392 treat that as being off the bottom of the screen. */
11393 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11395 clear_glyph_matrix (w
->desired_matrix
);
11396 ++extra_scroll_margin_lines
;
11399 rc
= SCROLLING_SUCCESS
;
11406 /* Compute a suitable window start for window W if display of W starts
11407 on a continuation line. Value is non-zero if a new window start
11410 The new window start will be computed, based on W's width, starting
11411 from the start of the continued line. It is the start of the
11412 screen line with the minimum distance from the old start W->start. */
11415 compute_window_start_on_continuation_line (w
)
11418 struct text_pos pos
, start_pos
;
11419 int window_start_changed_p
= 0;
11421 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11423 /* If window start is on a continuation line... Window start may be
11424 < BEGV in case there's invisible text at the start of the
11425 buffer (M-x rmail, for example). */
11426 if (CHARPOS (start_pos
) > BEGV
11427 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11430 struct glyph_row
*row
;
11432 /* Handle the case that the window start is out of range. */
11433 if (CHARPOS (start_pos
) < BEGV
)
11434 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11435 else if (CHARPOS (start_pos
) > ZV
)
11436 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11438 /* Find the start of the continued line. This should be fast
11439 because scan_buffer is fast (newline cache). */
11440 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11441 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11442 row
, DEFAULT_FACE_ID
);
11443 reseat_at_previous_visible_line_start (&it
);
11445 /* If the line start is "too far" away from the window start,
11446 say it takes too much time to compute a new window start. */
11447 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11448 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11450 int min_distance
, distance
;
11452 /* Move forward by display lines to find the new window
11453 start. If window width was enlarged, the new start can
11454 be expected to be > the old start. If window width was
11455 decreased, the new window start will be < the old start.
11456 So, we're looking for the display line start with the
11457 minimum distance from the old window start. */
11458 pos
= it
.current
.pos
;
11459 min_distance
= INFINITY
;
11460 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11461 distance
< min_distance
)
11463 min_distance
= distance
;
11464 pos
= it
.current
.pos
;
11465 move_it_by_lines (&it
, 1, 0);
11468 /* Set the window start there. */
11469 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11470 window_start_changed_p
= 1;
11474 return window_start_changed_p
;
11478 /* Try cursor movement in case text has not changed in window WINDOW,
11479 with window start STARTP. Value is
11481 CURSOR_MOVEMENT_SUCCESS if successful
11483 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11485 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11486 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11487 we want to scroll as if scroll-step were set to 1. See the code.
11489 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11490 which case we have to abort this redisplay, and adjust matrices
11495 CURSOR_MOVEMENT_SUCCESS
,
11496 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11497 CURSOR_MOVEMENT_MUST_SCROLL
,
11498 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11502 try_cursor_movement (window
, startp
, scroll_step
)
11503 Lisp_Object window
;
11504 struct text_pos startp
;
11507 struct window
*w
= XWINDOW (window
);
11508 struct frame
*f
= XFRAME (w
->frame
);
11509 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11512 if (inhibit_try_cursor_movement
)
11516 /* Handle case where text has not changed, only point, and it has
11517 not moved off the frame. */
11518 if (/* Point may be in this window. */
11519 PT
>= CHARPOS (startp
)
11520 /* Selective display hasn't changed. */
11521 && !current_buffer
->clip_changed
11522 /* Function force-mode-line-update is used to force a thorough
11523 redisplay. It sets either windows_or_buffers_changed or
11524 update_mode_lines. So don't take a shortcut here for these
11526 && !update_mode_lines
11527 && !windows_or_buffers_changed
11528 && !cursor_type_changed
11529 /* Can't use this case if highlighting a region. When a
11530 region exists, cursor movement has to do more than just
11532 && !(!NILP (Vtransient_mark_mode
)
11533 && !NILP (current_buffer
->mark_active
))
11534 && NILP (w
->region_showing
)
11535 && NILP (Vshow_trailing_whitespace
)
11536 /* Right after splitting windows, last_point may be nil. */
11537 && INTEGERP (w
->last_point
)
11538 /* This code is not used for mini-buffer for the sake of the case
11539 of redisplaying to replace an echo area message; since in
11540 that case the mini-buffer contents per se are usually
11541 unchanged. This code is of no real use in the mini-buffer
11542 since the handling of this_line_start_pos, etc., in redisplay
11543 handles the same cases. */
11544 && !EQ (window
, minibuf_window
)
11545 /* When splitting windows or for new windows, it happens that
11546 redisplay is called with a nil window_end_vpos or one being
11547 larger than the window. This should really be fixed in
11548 window.c. I don't have this on my list, now, so we do
11549 approximately the same as the old redisplay code. --gerd. */
11550 && INTEGERP (w
->window_end_vpos
)
11551 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11552 && (FRAME_WINDOW_P (f
)
11553 || !overlay_arrow_in_current_buffer_p ()))
11555 int this_scroll_margin
, top_scroll_margin
;
11556 struct glyph_row
*row
= NULL
;
11559 debug_method_add (w
, "cursor movement");
11562 /* Scroll if point within this distance from the top or bottom
11563 of the window. This is a pixel value. */
11564 this_scroll_margin
= max (0, scroll_margin
);
11565 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11566 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11568 top_scroll_margin
= this_scroll_margin
;
11569 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11570 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11572 /* Start with the row the cursor was displayed during the last
11573 not paused redisplay. Give up if that row is not valid. */
11574 if (w
->last_cursor
.vpos
< 0
11575 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11576 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11579 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11580 if (row
->mode_line_p
)
11582 if (!row
->enabled_p
)
11583 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11586 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11589 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11591 if (PT
> XFASTINT (w
->last_point
))
11593 /* Point has moved forward. */
11594 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11595 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11597 xassert (row
->enabled_p
);
11601 /* The end position of a row equals the start position
11602 of the next row. If PT is there, we would rather
11603 display it in the next line. */
11604 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11605 && MATRIX_ROW_END_CHARPOS (row
) == PT
11606 && !cursor_row_p (w
, row
))
11609 /* If within the scroll margin, scroll. Note that
11610 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11611 the next line would be drawn, and that
11612 this_scroll_margin can be zero. */
11613 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11614 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11615 /* Line is completely visible last line in window
11616 and PT is to be set in the next line. */
11617 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11618 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11619 && !row
->ends_at_zv_p
11620 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11623 else if (PT
< XFASTINT (w
->last_point
))
11625 /* Cursor has to be moved backward. Note that PT >=
11626 CHARPOS (startp) because of the outer if-statement. */
11627 while (!row
->mode_line_p
11628 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11629 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11630 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11631 && (row
->y
> top_scroll_margin
11632 || CHARPOS (startp
) == BEGV
))
11634 xassert (row
->enabled_p
);
11638 /* Consider the following case: Window starts at BEGV,
11639 there is invisible, intangible text at BEGV, so that
11640 display starts at some point START > BEGV. It can
11641 happen that we are called with PT somewhere between
11642 BEGV and START. Try to handle that case. */
11643 if (row
< w
->current_matrix
->rows
11644 || row
->mode_line_p
)
11646 row
= w
->current_matrix
->rows
;
11647 if (row
->mode_line_p
)
11651 /* Due to newlines in overlay strings, we may have to
11652 skip forward over overlay strings. */
11653 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11654 && MATRIX_ROW_END_CHARPOS (row
) == PT
11655 && !cursor_row_p (w
, row
))
11658 /* If within the scroll margin, scroll. */
11659 if (row
->y
< top_scroll_margin
11660 && CHARPOS (startp
) != BEGV
)
11664 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11665 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11667 /* if PT is not in the glyph row, give up. */
11668 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11670 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11671 && make_cursor_line_fully_visible_p
)
11673 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11674 && !row
->ends_at_zv_p
11675 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11676 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11677 else if (row
->height
> window_box_height (w
))
11679 /* If we end up in a partially visible line, let's
11680 make it fully visible, except when it's taller
11681 than the window, in which case we can't do much
11684 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11688 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11689 if (!make_cursor_line_fully_visible (w
, 0))
11690 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11692 rc
= CURSOR_MOVEMENT_SUCCESS
;
11696 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11699 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11700 rc
= CURSOR_MOVEMENT_SUCCESS
;
11709 set_vertical_scroll_bar (w
)
11712 int start
, end
, whole
;
11714 /* Calculate the start and end positions for the current window.
11715 At some point, it would be nice to choose between scrollbars
11716 which reflect the whole buffer size, with special markers
11717 indicating narrowing, and scrollbars which reflect only the
11720 Note that mini-buffers sometimes aren't displaying any text. */
11721 if (!MINI_WINDOW_P (w
)
11722 || (w
== XWINDOW (minibuf_window
)
11723 && NILP (echo_area_buffer
[0])))
11725 struct buffer
*buf
= XBUFFER (w
->buffer
);
11726 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11727 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11728 /* I don't think this is guaranteed to be right. For the
11729 moment, we'll pretend it is. */
11730 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11734 if (whole
< (end
- start
))
11735 whole
= end
- start
;
11738 start
= end
= whole
= 0;
11740 /* Indicate what this scroll bar ought to be displaying now. */
11741 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11745 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11746 selected_window is redisplayed.
11748 We can return without actually redisplaying the window if
11749 fonts_changed_p is nonzero. In that case, redisplay_internal will
11753 redisplay_window (window
, just_this_one_p
)
11754 Lisp_Object window
;
11755 int just_this_one_p
;
11757 struct window
*w
= XWINDOW (window
);
11758 struct frame
*f
= XFRAME (w
->frame
);
11759 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11760 struct buffer
*old
= current_buffer
;
11761 struct text_pos lpoint
, opoint
, startp
;
11762 int update_mode_line
;
11765 /* Record it now because it's overwritten. */
11766 int current_matrix_up_to_date_p
= 0;
11767 int used_current_matrix_p
= 0;
11768 /* This is less strict than current_matrix_up_to_date_p.
11769 It indictes that the buffer contents and narrowing are unchanged. */
11770 int buffer_unchanged_p
= 0;
11771 int temp_scroll_step
= 0;
11772 int count
= SPECPDL_INDEX ();
11774 int centering_position
;
11775 int last_line_misfit
= 0;
11777 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11780 /* W must be a leaf window here. */
11781 xassert (!NILP (w
->buffer
));
11783 *w
->desired_matrix
->method
= 0;
11786 specbind (Qinhibit_point_motion_hooks
, Qt
);
11788 reconsider_clip_changes (w
, buffer
);
11790 /* Has the mode line to be updated? */
11791 update_mode_line
= (!NILP (w
->update_mode_line
)
11792 || update_mode_lines
11793 || buffer
->clip_changed
11794 || buffer
->prevent_redisplay_optimizations_p
);
11796 if (MINI_WINDOW_P (w
))
11798 if (w
== XWINDOW (echo_area_window
)
11799 && !NILP (echo_area_buffer
[0]))
11801 if (update_mode_line
)
11802 /* We may have to update a tty frame's menu bar or a
11803 tool-bar. Example `M-x C-h C-h C-g'. */
11804 goto finish_menu_bars
;
11806 /* We've already displayed the echo area glyphs in this window. */
11807 goto finish_scroll_bars
;
11809 else if ((w
!= XWINDOW (minibuf_window
)
11810 || minibuf_level
== 0)
11811 /* When buffer is nonempty, redisplay window normally. */
11812 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11813 /* Quail displays non-mini buffers in minibuffer window.
11814 In that case, redisplay the window normally. */
11815 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11817 /* W is a mini-buffer window, but it's not active, so clear
11819 int yb
= window_text_bottom_y (w
);
11820 struct glyph_row
*row
;
11823 for (y
= 0, row
= w
->desired_matrix
->rows
;
11825 y
+= row
->height
, ++row
)
11826 blank_row (w
, row
, y
);
11827 goto finish_scroll_bars
;
11830 clear_glyph_matrix (w
->desired_matrix
);
11833 /* Otherwise set up data on this window; select its buffer and point
11835 /* Really select the buffer, for the sake of buffer-local
11837 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11838 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11840 current_matrix_up_to_date_p
11841 = (!NILP (w
->window_end_valid
)
11842 && !current_buffer
->clip_changed
11843 && !current_buffer
->prevent_redisplay_optimizations_p
11844 && XFASTINT (w
->last_modified
) >= MODIFF
11845 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11848 = (!NILP (w
->window_end_valid
)
11849 && !current_buffer
->clip_changed
11850 && XFASTINT (w
->last_modified
) >= MODIFF
11851 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11853 /* When windows_or_buffers_changed is non-zero, we can't rely on
11854 the window end being valid, so set it to nil there. */
11855 if (windows_or_buffers_changed
)
11857 /* If window starts on a continuation line, maybe adjust the
11858 window start in case the window's width changed. */
11859 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11860 compute_window_start_on_continuation_line (w
);
11862 w
->window_end_valid
= Qnil
;
11865 /* Some sanity checks. */
11866 CHECK_WINDOW_END (w
);
11867 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11869 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11872 /* If %c is in mode line, update it if needed. */
11873 if (!NILP (w
->column_number_displayed
)
11874 /* This alternative quickly identifies a common case
11875 where no change is needed. */
11876 && !(PT
== XFASTINT (w
->last_point
)
11877 && XFASTINT (w
->last_modified
) >= MODIFF
11878 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11879 && (XFASTINT (w
->column_number_displayed
)
11880 != (int) current_column ())) /* iftc */
11881 update_mode_line
= 1;
11883 /* Count number of windows showing the selected buffer. An indirect
11884 buffer counts as its base buffer. */
11885 if (!just_this_one_p
)
11887 struct buffer
*current_base
, *window_base
;
11888 current_base
= current_buffer
;
11889 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11890 if (current_base
->base_buffer
)
11891 current_base
= current_base
->base_buffer
;
11892 if (window_base
->base_buffer
)
11893 window_base
= window_base
->base_buffer
;
11894 if (current_base
== window_base
)
11898 /* Point refers normally to the selected window. For any other
11899 window, set up appropriate value. */
11900 if (!EQ (window
, selected_window
))
11902 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11903 int new_pt_byte
= marker_byte_position (w
->pointm
);
11907 new_pt_byte
= BEGV_BYTE
;
11908 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11910 else if (new_pt
> (ZV
- 1))
11913 new_pt_byte
= ZV_BYTE
;
11914 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11917 /* We don't use SET_PT so that the point-motion hooks don't run. */
11918 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11921 /* If any of the character widths specified in the display table
11922 have changed, invalidate the width run cache. It's true that
11923 this may be a bit late to catch such changes, but the rest of
11924 redisplay goes (non-fatally) haywire when the display table is
11925 changed, so why should we worry about doing any better? */
11926 if (current_buffer
->width_run_cache
)
11928 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11930 if (! disptab_matches_widthtab (disptab
,
11931 XVECTOR (current_buffer
->width_table
)))
11933 invalidate_region_cache (current_buffer
,
11934 current_buffer
->width_run_cache
,
11936 recompute_width_table (current_buffer
, disptab
);
11940 /* If window-start is screwed up, choose a new one. */
11941 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11944 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11946 /* If someone specified a new starting point but did not insist,
11947 check whether it can be used. */
11948 if (!NILP (w
->optional_new_start
)
11949 && CHARPOS (startp
) >= BEGV
11950 && CHARPOS (startp
) <= ZV
)
11952 w
->optional_new_start
= Qnil
;
11953 start_display (&it
, w
, startp
);
11954 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11955 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11956 if (IT_CHARPOS (it
) == PT
)
11957 w
->force_start
= Qt
;
11958 /* IT may overshoot PT if text at PT is invisible. */
11959 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11960 w
->force_start
= Qt
;
11965 /* Handle case where place to start displaying has been specified,
11966 unless the specified location is outside the accessible range. */
11967 if (!NILP (w
->force_start
)
11968 || w
->frozen_window_start_p
)
11970 /* We set this later on if we have to adjust point. */
11973 w
->force_start
= Qnil
;
11975 w
->window_end_valid
= Qnil
;
11977 /* Forget any recorded base line for line number display. */
11978 if (!buffer_unchanged_p
)
11979 w
->base_line_number
= Qnil
;
11981 /* Redisplay the mode line. Select the buffer properly for that.
11982 Also, run the hook window-scroll-functions
11983 because we have scrolled. */
11984 /* Note, we do this after clearing force_start because
11985 if there's an error, it is better to forget about force_start
11986 than to get into an infinite loop calling the hook functions
11987 and having them get more errors. */
11988 if (!update_mode_line
11989 || ! NILP (Vwindow_scroll_functions
))
11991 update_mode_line
= 1;
11992 w
->update_mode_line
= Qt
;
11993 startp
= run_window_scroll_functions (window
, startp
);
11996 w
->last_modified
= make_number (0);
11997 w
->last_overlay_modified
= make_number (0);
11998 if (CHARPOS (startp
) < BEGV
)
11999 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12000 else if (CHARPOS (startp
) > ZV
)
12001 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12003 /* Redisplay, then check if cursor has been set during the
12004 redisplay. Give up if new fonts were loaded. */
12005 if (!try_window (window
, startp
))
12007 w
->force_start
= Qt
;
12008 clear_glyph_matrix (w
->desired_matrix
);
12009 goto need_larger_matrices
;
12012 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12014 /* If point does not appear, try to move point so it does
12015 appear. The desired matrix has been built above, so we
12016 can use it here. */
12017 new_vpos
= window_box_height (w
) / 2;
12020 if (!make_cursor_line_fully_visible (w
, 0))
12022 /* Point does appear, but on a line partly visible at end of window.
12023 Move it back to a fully-visible line. */
12024 new_vpos
= window_box_height (w
);
12027 /* If we need to move point for either of the above reasons,
12028 now actually do it. */
12031 struct glyph_row
*row
;
12033 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12034 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12037 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12038 MATRIX_ROW_START_BYTEPOS (row
));
12040 if (w
!= XWINDOW (selected_window
))
12041 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12042 else if (current_buffer
== old
)
12043 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12045 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12047 /* If we are highlighting the region, then we just changed
12048 the region, so redisplay to show it. */
12049 if (!NILP (Vtransient_mark_mode
)
12050 && !NILP (current_buffer
->mark_active
))
12052 clear_glyph_matrix (w
->desired_matrix
);
12053 if (!try_window (window
, startp
))
12054 goto need_larger_matrices
;
12059 debug_method_add (w
, "forced window start");
12064 /* Handle case where text has not changed, only point, and it has
12065 not moved off the frame, and we are not retrying after hscroll.
12066 (current_matrix_up_to_date_p is nonzero when retrying.) */
12067 if (current_matrix_up_to_date_p
12068 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12069 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12073 case CURSOR_MOVEMENT_SUCCESS
:
12074 used_current_matrix_p
= 1;
12077 #if 0 /* try_cursor_movement never returns this value. */
12078 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12079 goto need_larger_matrices
;
12082 case CURSOR_MOVEMENT_MUST_SCROLL
:
12083 goto try_to_scroll
;
12089 /* If current starting point was originally the beginning of a line
12090 but no longer is, find a new starting point. */
12091 else if (!NILP (w
->start_at_line_beg
)
12092 && !(CHARPOS (startp
) <= BEGV
12093 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12096 debug_method_add (w
, "recenter 1");
12101 /* Try scrolling with try_window_id. Value is > 0 if update has
12102 been done, it is -1 if we know that the same window start will
12103 not work. It is 0 if unsuccessful for some other reason. */
12104 else if ((tem
= try_window_id (w
)) != 0)
12107 debug_method_add (w
, "try_window_id %d", tem
);
12110 if (fonts_changed_p
)
12111 goto need_larger_matrices
;
12115 /* Otherwise try_window_id has returned -1 which means that we
12116 don't want the alternative below this comment to execute. */
12118 else if (CHARPOS (startp
) >= BEGV
12119 && CHARPOS (startp
) <= ZV
12120 && PT
>= CHARPOS (startp
)
12121 && (CHARPOS (startp
) < ZV
12122 /* Avoid starting at end of buffer. */
12123 || CHARPOS (startp
) == BEGV
12124 || (XFASTINT (w
->last_modified
) >= MODIFF
12125 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12128 debug_method_add (w
, "same window start");
12131 /* Try to redisplay starting at same place as before.
12132 If point has not moved off frame, accept the results. */
12133 if (!current_matrix_up_to_date_p
12134 /* Don't use try_window_reusing_current_matrix in this case
12135 because a window scroll function can have changed the
12137 || !NILP (Vwindow_scroll_functions
)
12138 || MINI_WINDOW_P (w
)
12139 || !(used_current_matrix_p
12140 = try_window_reusing_current_matrix (w
)))
12142 IF_DEBUG (debug_method_add (w
, "1"));
12143 try_window (window
, startp
);
12146 if (fonts_changed_p
)
12147 goto need_larger_matrices
;
12149 if (w
->cursor
.vpos
>= 0)
12151 if (!just_this_one_p
12152 || current_buffer
->clip_changed
12153 || BEG_UNCHANGED
< CHARPOS (startp
))
12154 /* Forget any recorded base line for line number display. */
12155 w
->base_line_number
= Qnil
;
12157 if (!make_cursor_line_fully_visible (w
, 1))
12159 clear_glyph_matrix (w
->desired_matrix
);
12160 last_line_misfit
= 1;
12162 /* Drop through and scroll. */
12167 clear_glyph_matrix (w
->desired_matrix
);
12172 w
->last_modified
= make_number (0);
12173 w
->last_overlay_modified
= make_number (0);
12175 /* Redisplay the mode line. Select the buffer properly for that. */
12176 if (!update_mode_line
)
12178 update_mode_line
= 1;
12179 w
->update_mode_line
= Qt
;
12182 /* Try to scroll by specified few lines. */
12183 if ((scroll_conservatively
12185 || temp_scroll_step
12186 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12187 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12188 && !current_buffer
->clip_changed
12189 && CHARPOS (startp
) >= BEGV
12190 && CHARPOS (startp
) <= ZV
)
12192 /* The function returns -1 if new fonts were loaded, 1 if
12193 successful, 0 if not successful. */
12194 int rc
= try_scrolling (window
, just_this_one_p
,
12195 scroll_conservatively
,
12197 temp_scroll_step
, last_line_misfit
);
12200 case SCROLLING_SUCCESS
:
12203 case SCROLLING_NEED_LARGER_MATRICES
:
12204 goto need_larger_matrices
;
12206 case SCROLLING_FAILED
:
12214 /* Finally, just choose place to start which centers point */
12217 centering_position
= window_box_height (w
) / 2;
12220 /* Jump here with centering_position already set to 0. */
12223 debug_method_add (w
, "recenter");
12226 /* w->vscroll = 0; */
12228 /* Forget any previously recorded base line for line number display. */
12229 if (!buffer_unchanged_p
)
12230 w
->base_line_number
= Qnil
;
12232 /* Move backward half the height of the window. */
12233 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12234 it
.current_y
= it
.last_visible_y
;
12235 move_it_vertically_backward (&it
, centering_position
);
12236 xassert (IT_CHARPOS (it
) >= BEGV
);
12238 /* The function move_it_vertically_backward may move over more
12239 than the specified y-distance. If it->w is small, e.g. a
12240 mini-buffer window, we may end up in front of the window's
12241 display area. Start displaying at the start of the line
12242 containing PT in this case. */
12243 if (it
.current_y
<= 0)
12245 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12246 move_it_vertically_backward (&it
, 0);
12247 xassert (IT_CHARPOS (it
) <= PT
);
12251 it
.current_x
= it
.hpos
= 0;
12253 /* Set startp here explicitly in case that helps avoid an infinite loop
12254 in case the window-scroll-functions functions get errors. */
12255 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12257 /* Run scroll hooks. */
12258 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12260 /* Redisplay the window. */
12261 if (!current_matrix_up_to_date_p
12262 || windows_or_buffers_changed
12263 || cursor_type_changed
12264 /* Don't use try_window_reusing_current_matrix in this case
12265 because it can have changed the buffer. */
12266 || !NILP (Vwindow_scroll_functions
)
12267 || !just_this_one_p
12268 || MINI_WINDOW_P (w
)
12269 || !(used_current_matrix_p
12270 = try_window_reusing_current_matrix (w
)))
12271 try_window (window
, startp
);
12273 /* If new fonts have been loaded (due to fontsets), give up. We
12274 have to start a new redisplay since we need to re-adjust glyph
12276 if (fonts_changed_p
)
12277 goto need_larger_matrices
;
12279 /* If cursor did not appear assume that the middle of the window is
12280 in the first line of the window. Do it again with the next line.
12281 (Imagine a window of height 100, displaying two lines of height
12282 60. Moving back 50 from it->last_visible_y will end in the first
12284 if (w
->cursor
.vpos
< 0)
12286 if (!NILP (w
->window_end_valid
)
12287 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12289 clear_glyph_matrix (w
->desired_matrix
);
12290 move_it_by_lines (&it
, 1, 0);
12291 try_window (window
, it
.current
.pos
);
12293 else if (PT
< IT_CHARPOS (it
))
12295 clear_glyph_matrix (w
->desired_matrix
);
12296 move_it_by_lines (&it
, -1, 0);
12297 try_window (window
, it
.current
.pos
);
12301 /* Not much we can do about it. */
12305 /* Consider the following case: Window starts at BEGV, there is
12306 invisible, intangible text at BEGV, so that display starts at
12307 some point START > BEGV. It can happen that we are called with
12308 PT somewhere between BEGV and START. Try to handle that case. */
12309 if (w
->cursor
.vpos
< 0)
12311 struct glyph_row
*row
= w
->current_matrix
->rows
;
12312 if (row
->mode_line_p
)
12314 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12317 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12319 /* If vscroll is enabled, disable it and try again. */
12323 clear_glyph_matrix (w
->desired_matrix
);
12327 /* If centering point failed to make the whole line visible,
12328 put point at the top instead. That has to make the whole line
12329 visible, if it can be done. */
12330 if (centering_position
== 0)
12332 clear_glyph_matrix (w
->desired_matrix
);
12333 centering_position
= 0;
12339 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12340 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12341 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12344 /* Display the mode line, if we must. */
12345 if ((update_mode_line
12346 /* If window not full width, must redo its mode line
12347 if (a) the window to its side is being redone and
12348 (b) we do a frame-based redisplay. This is a consequence
12349 of how inverted lines are drawn in frame-based redisplay. */
12350 || (!just_this_one_p
12351 && !FRAME_WINDOW_P (f
)
12352 && !WINDOW_FULL_WIDTH_P (w
))
12353 /* Line number to display. */
12354 || INTEGERP (w
->base_line_pos
)
12355 /* Column number is displayed and different from the one displayed. */
12356 || (!NILP (w
->column_number_displayed
)
12357 && (XFASTINT (w
->column_number_displayed
)
12358 != (int) current_column ()))) /* iftc */
12359 /* This means that the window has a mode line. */
12360 && (WINDOW_WANTS_MODELINE_P (w
)
12361 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12363 display_mode_lines (w
);
12365 /* If mode line height has changed, arrange for a thorough
12366 immediate redisplay using the correct mode line height. */
12367 if (WINDOW_WANTS_MODELINE_P (w
)
12368 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12370 fonts_changed_p
= 1;
12371 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12372 = DESIRED_MODE_LINE_HEIGHT (w
);
12375 /* If top line height has changed, arrange for a thorough
12376 immediate redisplay using the correct mode line height. */
12377 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12378 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12380 fonts_changed_p
= 1;
12381 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12382 = DESIRED_HEADER_LINE_HEIGHT (w
);
12385 if (fonts_changed_p
)
12386 goto need_larger_matrices
;
12389 if (!line_number_displayed
12390 && !BUFFERP (w
->base_line_pos
))
12392 w
->base_line_pos
= Qnil
;
12393 w
->base_line_number
= Qnil
;
12398 /* When we reach a frame's selected window, redo the frame's menu bar. */
12399 if (update_mode_line
12400 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12402 int redisplay_menu_p
= 0;
12403 int redisplay_tool_bar_p
= 0;
12405 if (FRAME_WINDOW_P (f
))
12407 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12408 || defined (USE_GTK)
12409 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12411 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12415 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12417 if (redisplay_menu_p
)
12418 display_menu_bar (w
);
12420 #ifdef HAVE_WINDOW_SYSTEM
12422 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12424 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12425 && (FRAME_TOOL_BAR_LINES (f
) > 0
12426 || auto_resize_tool_bars_p
);
12430 if (redisplay_tool_bar_p
)
12431 redisplay_tool_bar (f
);
12435 #ifdef HAVE_WINDOW_SYSTEM
12436 if (FRAME_WINDOW_P (f
)
12437 && update_window_fringes (w
, 0)
12438 && !just_this_one_p
12439 && (used_current_matrix_p
|| overlay_arrow_seen
)
12440 && !w
->pseudo_window_p
)
12444 if (draw_window_fringes (w
, 1))
12445 x_draw_vertical_border (w
);
12449 #endif /* HAVE_WINDOW_SYSTEM */
12451 /* We go to this label, with fonts_changed_p nonzero,
12452 if it is necessary to try again using larger glyph matrices.
12453 We have to redeem the scroll bar even in this case,
12454 because the loop in redisplay_internal expects that. */
12455 need_larger_matrices
:
12457 finish_scroll_bars
:
12459 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12461 /* Set the thumb's position and size. */
12462 set_vertical_scroll_bar (w
);
12464 /* Note that we actually used the scroll bar attached to this
12465 window, so it shouldn't be deleted at the end of redisplay. */
12466 redeem_scroll_bar_hook (w
);
12469 /* Restore current_buffer and value of point in it. */
12470 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12471 set_buffer_internal_1 (old
);
12472 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12474 unbind_to (count
, Qnil
);
12478 /* Build the complete desired matrix of WINDOW with a window start
12479 buffer position POS. Value is non-zero if successful. It is zero
12480 if fonts were loaded during redisplay which makes re-adjusting
12481 glyph matrices necessary. */
12484 try_window (window
, pos
)
12485 Lisp_Object window
;
12486 struct text_pos pos
;
12488 struct window
*w
= XWINDOW (window
);
12490 struct glyph_row
*last_text_row
= NULL
;
12492 /* Make POS the new window start. */
12493 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12495 /* Mark cursor position as unknown. No overlay arrow seen. */
12496 w
->cursor
.vpos
= -1;
12497 overlay_arrow_seen
= 0;
12499 /* Initialize iterator and info to start at POS. */
12500 start_display (&it
, w
, pos
);
12502 /* Display all lines of W. */
12503 while (it
.current_y
< it
.last_visible_y
)
12505 if (display_line (&it
))
12506 last_text_row
= it
.glyph_row
- 1;
12507 if (fonts_changed_p
)
12511 /* If bottom moved off end of frame, change mode line percentage. */
12512 if (XFASTINT (w
->window_end_pos
) <= 0
12513 && Z
!= IT_CHARPOS (it
))
12514 w
->update_mode_line
= Qt
;
12516 /* Set window_end_pos to the offset of the last character displayed
12517 on the window from the end of current_buffer. Set
12518 window_end_vpos to its row number. */
12521 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12522 w
->window_end_bytepos
12523 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12525 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12527 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12528 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12529 ->displays_text_p
);
12533 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12534 w
->window_end_pos
= make_number (Z
- ZV
);
12535 w
->window_end_vpos
= make_number (0);
12538 /* But that is not valid info until redisplay finishes. */
12539 w
->window_end_valid
= Qnil
;
12545 /************************************************************************
12546 Window redisplay reusing current matrix when buffer has not changed
12547 ************************************************************************/
12549 /* Try redisplay of window W showing an unchanged buffer with a
12550 different window start than the last time it was displayed by
12551 reusing its current matrix. Value is non-zero if successful.
12552 W->start is the new window start. */
12555 try_window_reusing_current_matrix (w
)
12558 struct frame
*f
= XFRAME (w
->frame
);
12559 struct glyph_row
*row
, *bottom_row
;
12562 struct text_pos start
, new_start
;
12563 int nrows_scrolled
, i
;
12564 struct glyph_row
*last_text_row
;
12565 struct glyph_row
*last_reused_text_row
;
12566 struct glyph_row
*start_row
;
12567 int start_vpos
, min_y
, max_y
;
12570 if (inhibit_try_window_reusing
)
12574 if (/* This function doesn't handle terminal frames. */
12575 !FRAME_WINDOW_P (f
)
12576 /* Don't try to reuse the display if windows have been split
12578 || windows_or_buffers_changed
12579 || cursor_type_changed
)
12582 /* Can't do this if region may have changed. */
12583 if ((!NILP (Vtransient_mark_mode
)
12584 && !NILP (current_buffer
->mark_active
))
12585 || !NILP (w
->region_showing
)
12586 || !NILP (Vshow_trailing_whitespace
))
12589 /* If top-line visibility has changed, give up. */
12590 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12591 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12594 /* Give up if old or new display is scrolled vertically. We could
12595 make this function handle this, but right now it doesn't. */
12596 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12597 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12600 /* The variable new_start now holds the new window start. The old
12601 start `start' can be determined from the current matrix. */
12602 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12603 start
= start_row
->start
.pos
;
12604 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12606 /* Clear the desired matrix for the display below. */
12607 clear_glyph_matrix (w
->desired_matrix
);
12609 if (CHARPOS (new_start
) <= CHARPOS (start
))
12613 /* Don't use this method if the display starts with an ellipsis
12614 displayed for invisible text. It's not easy to handle that case
12615 below, and it's certainly not worth the effort since this is
12616 not a frequent case. */
12617 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12620 IF_DEBUG (debug_method_add (w
, "twu1"));
12622 /* Display up to a row that can be reused. The variable
12623 last_text_row is set to the last row displayed that displays
12624 text. Note that it.vpos == 0 if or if not there is a
12625 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12626 start_display (&it
, w
, new_start
);
12627 first_row_y
= it
.current_y
;
12628 w
->cursor
.vpos
= -1;
12629 last_text_row
= last_reused_text_row
= NULL
;
12631 while (it
.current_y
< it
.last_visible_y
12632 && !fonts_changed_p
)
12634 /* If we have reached into the characters in the START row,
12635 that means the line boundaries have changed. So we
12636 can't start copying with the row START. Maybe it will
12637 work to start copying with the following row. */
12638 while (IT_CHARPOS (it
) > CHARPOS (start
))
12640 /* Advance to the next row as the "start". */
12642 start
= start_row
->start
.pos
;
12643 /* If there are no more rows to try, or just one, give up. */
12644 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12645 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12646 || CHARPOS (start
) == ZV
)
12648 clear_glyph_matrix (w
->desired_matrix
);
12652 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12654 /* If we have reached alignment,
12655 we can copy the rest of the rows. */
12656 if (IT_CHARPOS (it
) == CHARPOS (start
))
12659 if (display_line (&it
))
12660 last_text_row
= it
.glyph_row
- 1;
12663 /* A value of current_y < last_visible_y means that we stopped
12664 at the previous window start, which in turn means that we
12665 have at least one reusable row. */
12666 if (it
.current_y
< it
.last_visible_y
)
12668 /* IT.vpos always starts from 0; it counts text lines. */
12669 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12671 /* Find PT if not already found in the lines displayed. */
12672 if (w
->cursor
.vpos
< 0)
12674 int dy
= it
.current_y
- start_row
->y
;
12676 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12677 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12679 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12680 dy
, nrows_scrolled
);
12683 clear_glyph_matrix (w
->desired_matrix
);
12688 /* Scroll the display. Do it before the current matrix is
12689 changed. The problem here is that update has not yet
12690 run, i.e. part of the current matrix is not up to date.
12691 scroll_run_hook will clear the cursor, and use the
12692 current matrix to get the height of the row the cursor is
12694 run
.current_y
= start_row
->y
;
12695 run
.desired_y
= it
.current_y
;
12696 run
.height
= it
.last_visible_y
- it
.current_y
;
12698 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12701 rif
->update_window_begin_hook (w
);
12702 rif
->clear_window_mouse_face (w
);
12703 rif
->scroll_run_hook (w
, &run
);
12704 rif
->update_window_end_hook (w
, 0, 0);
12708 /* Shift current matrix down by nrows_scrolled lines. */
12709 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12710 rotate_matrix (w
->current_matrix
,
12712 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12715 /* Disable lines that must be updated. */
12716 for (i
= 0; i
< it
.vpos
; ++i
)
12717 (start_row
+ i
)->enabled_p
= 0;
12719 /* Re-compute Y positions. */
12720 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12721 max_y
= it
.last_visible_y
;
12722 for (row
= start_row
+ nrows_scrolled
;
12726 row
->y
= it
.current_y
;
12727 row
->visible_height
= row
->height
;
12729 if (row
->y
< min_y
)
12730 row
->visible_height
-= min_y
- row
->y
;
12731 if (row
->y
+ row
->height
> max_y
)
12732 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12733 row
->redraw_fringe_bitmaps_p
= 1;
12735 it
.current_y
+= row
->height
;
12737 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12738 last_reused_text_row
= row
;
12739 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12743 /* Disable lines in the current matrix which are now
12744 below the window. */
12745 for (++row
; row
< bottom_row
; ++row
)
12746 row
->enabled_p
= 0;
12749 /* Update window_end_pos etc.; last_reused_text_row is the last
12750 reused row from the current matrix containing text, if any.
12751 The value of last_text_row is the last displayed line
12752 containing text. */
12753 if (last_reused_text_row
)
12755 w
->window_end_bytepos
12756 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12758 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12760 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12761 w
->current_matrix
));
12763 else if (last_text_row
)
12765 w
->window_end_bytepos
12766 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12768 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12770 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12774 /* This window must be completely empty. */
12775 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12776 w
->window_end_pos
= make_number (Z
- ZV
);
12777 w
->window_end_vpos
= make_number (0);
12779 w
->window_end_valid
= Qnil
;
12781 /* Update hint: don't try scrolling again in update_window. */
12782 w
->desired_matrix
->no_scrolling_p
= 1;
12785 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12789 else if (CHARPOS (new_start
) > CHARPOS (start
))
12791 struct glyph_row
*pt_row
, *row
;
12792 struct glyph_row
*first_reusable_row
;
12793 struct glyph_row
*first_row_to_display
;
12795 int yb
= window_text_bottom_y (w
);
12797 /* Find the row starting at new_start, if there is one. Don't
12798 reuse a partially visible line at the end. */
12799 first_reusable_row
= start_row
;
12800 while (first_reusable_row
->enabled_p
12801 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12802 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12803 < CHARPOS (new_start
)))
12804 ++first_reusable_row
;
12806 /* Give up if there is no row to reuse. */
12807 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12808 || !first_reusable_row
->enabled_p
12809 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12810 != CHARPOS (new_start
)))
12813 /* We can reuse fully visible rows beginning with
12814 first_reusable_row to the end of the window. Set
12815 first_row_to_display to the first row that cannot be reused.
12816 Set pt_row to the row containing point, if there is any. */
12818 for (first_row_to_display
= first_reusable_row
;
12819 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12820 ++first_row_to_display
)
12822 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12823 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12824 pt_row
= first_row_to_display
;
12827 /* Start displaying at the start of first_row_to_display. */
12828 xassert (first_row_to_display
->y
< yb
);
12829 init_to_row_start (&it
, w
, first_row_to_display
);
12831 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12833 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12835 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12836 + WINDOW_HEADER_LINE_HEIGHT (w
));
12838 /* Display lines beginning with first_row_to_display in the
12839 desired matrix. Set last_text_row to the last row displayed
12840 that displays text. */
12841 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12842 if (pt_row
== NULL
)
12843 w
->cursor
.vpos
= -1;
12844 last_text_row
= NULL
;
12845 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12846 if (display_line (&it
))
12847 last_text_row
= it
.glyph_row
- 1;
12849 /* Give up If point isn't in a row displayed or reused. */
12850 if (w
->cursor
.vpos
< 0)
12852 clear_glyph_matrix (w
->desired_matrix
);
12856 /* If point is in a reused row, adjust y and vpos of the cursor
12860 w
->cursor
.vpos
-= nrows_scrolled
;
12861 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
12864 /* Scroll the display. */
12865 run
.current_y
= first_reusable_row
->y
;
12866 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12867 run
.height
= it
.last_visible_y
- run
.current_y
;
12868 dy
= run
.current_y
- run
.desired_y
;
12873 rif
->update_window_begin_hook (w
);
12874 rif
->clear_window_mouse_face (w
);
12875 rif
->scroll_run_hook (w
, &run
);
12876 rif
->update_window_end_hook (w
, 0, 0);
12880 /* Adjust Y positions of reused rows. */
12881 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12882 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12883 max_y
= it
.last_visible_y
;
12884 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12887 row
->visible_height
= row
->height
;
12888 if (row
->y
< min_y
)
12889 row
->visible_height
-= min_y
- row
->y
;
12890 if (row
->y
+ row
->height
> max_y
)
12891 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12892 row
->redraw_fringe_bitmaps_p
= 1;
12895 /* Scroll the current matrix. */
12896 xassert (nrows_scrolled
> 0);
12897 rotate_matrix (w
->current_matrix
,
12899 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12902 /* Disable rows not reused. */
12903 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12904 row
->enabled_p
= 0;
12906 /* Point may have moved to a different line, so we cannot assume that
12907 the previous cursor position is valid; locate the correct row. */
12910 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12911 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
12915 w
->cursor
.y
= row
->y
;
12917 if (row
< bottom_row
)
12919 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
12920 while (glyph
->charpos
< PT
)
12923 w
->cursor
.x
+= glyph
->pixel_width
;
12929 /* Adjust window end. A null value of last_text_row means that
12930 the window end is in reused rows which in turn means that
12931 only its vpos can have changed. */
12934 w
->window_end_bytepos
12935 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12937 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12939 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12944 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12947 w
->window_end_valid
= Qnil
;
12948 w
->desired_matrix
->no_scrolling_p
= 1;
12951 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12961 /************************************************************************
12962 Window redisplay reusing current matrix when buffer has changed
12963 ************************************************************************/
12965 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12966 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12968 static struct glyph_row
*
12969 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12970 struct glyph_row
*));
12973 /* Return the last row in MATRIX displaying text. If row START is
12974 non-null, start searching with that row. IT gives the dimensions
12975 of the display. Value is null if matrix is empty; otherwise it is
12976 a pointer to the row found. */
12978 static struct glyph_row
*
12979 find_last_row_displaying_text (matrix
, it
, start
)
12980 struct glyph_matrix
*matrix
;
12982 struct glyph_row
*start
;
12984 struct glyph_row
*row
, *row_found
;
12986 /* Set row_found to the last row in IT->w's current matrix
12987 displaying text. The loop looks funny but think of partially
12990 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12991 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12993 xassert (row
->enabled_p
);
12995 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13004 /* Return the last row in the current matrix of W that is not affected
13005 by changes at the start of current_buffer that occurred since W's
13006 current matrix was built. Value is null if no such row exists.
13008 BEG_UNCHANGED us the number of characters unchanged at the start of
13009 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13010 first changed character in current_buffer. Characters at positions <
13011 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13012 when the current matrix was built. */
13014 static struct glyph_row
*
13015 find_last_unchanged_at_beg_row (w
)
13018 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13019 struct glyph_row
*row
;
13020 struct glyph_row
*row_found
= NULL
;
13021 int yb
= window_text_bottom_y (w
);
13023 /* Find the last row displaying unchanged text. */
13024 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13025 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13026 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13028 if (/* If row ends before first_changed_pos, it is unchanged,
13029 except in some case. */
13030 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13031 /* When row ends in ZV and we write at ZV it is not
13033 && !row
->ends_at_zv_p
13034 /* When first_changed_pos is the end of a continued line,
13035 row is not unchanged because it may be no longer
13037 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13038 && (row
->continued_p
13039 || row
->exact_window_width_line_p
)))
13042 /* Stop if last visible row. */
13043 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13053 /* Find the first glyph row in the current matrix of W that is not
13054 affected by changes at the end of current_buffer since the
13055 time W's current matrix was built.
13057 Return in *DELTA the number of chars by which buffer positions in
13058 unchanged text at the end of current_buffer must be adjusted.
13060 Return in *DELTA_BYTES the corresponding number of bytes.
13062 Value is null if no such row exists, i.e. all rows are affected by
13065 static struct glyph_row
*
13066 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13068 int *delta
, *delta_bytes
;
13070 struct glyph_row
*row
;
13071 struct glyph_row
*row_found
= NULL
;
13073 *delta
= *delta_bytes
= 0;
13075 /* Display must not have been paused, otherwise the current matrix
13076 is not up to date. */
13077 if (NILP (w
->window_end_valid
))
13080 /* A value of window_end_pos >= END_UNCHANGED means that the window
13081 end is in the range of changed text. If so, there is no
13082 unchanged row at the end of W's current matrix. */
13083 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13086 /* Set row to the last row in W's current matrix displaying text. */
13087 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13089 /* If matrix is entirely empty, no unchanged row exists. */
13090 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13092 /* The value of row is the last glyph row in the matrix having a
13093 meaningful buffer position in it. The end position of row
13094 corresponds to window_end_pos. This allows us to translate
13095 buffer positions in the current matrix to current buffer
13096 positions for characters not in changed text. */
13097 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13098 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13099 int last_unchanged_pos
, last_unchanged_pos_old
;
13100 struct glyph_row
*first_text_row
13101 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13103 *delta
= Z
- Z_old
;
13104 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13106 /* Set last_unchanged_pos to the buffer position of the last
13107 character in the buffer that has not been changed. Z is the
13108 index + 1 of the last character in current_buffer, i.e. by
13109 subtracting END_UNCHANGED we get the index of the last
13110 unchanged character, and we have to add BEG to get its buffer
13112 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13113 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13115 /* Search backward from ROW for a row displaying a line that
13116 starts at a minimum position >= last_unchanged_pos_old. */
13117 for (; row
> first_text_row
; --row
)
13119 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13122 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13127 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13134 /* Make sure that glyph rows in the current matrix of window W
13135 reference the same glyph memory as corresponding rows in the
13136 frame's frame matrix. This function is called after scrolling W's
13137 current matrix on a terminal frame in try_window_id and
13138 try_window_reusing_current_matrix. */
13141 sync_frame_with_window_matrix_rows (w
)
13144 struct frame
*f
= XFRAME (w
->frame
);
13145 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13147 /* Preconditions: W must be a leaf window and full-width. Its frame
13148 must have a frame matrix. */
13149 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13150 xassert (WINDOW_FULL_WIDTH_P (w
));
13151 xassert (!FRAME_WINDOW_P (f
));
13153 /* If W is a full-width window, glyph pointers in W's current matrix
13154 have, by definition, to be the same as glyph pointers in the
13155 corresponding frame matrix. Note that frame matrices have no
13156 marginal areas (see build_frame_matrix). */
13157 window_row
= w
->current_matrix
->rows
;
13158 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13159 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13160 while (window_row
< window_row_end
)
13162 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13163 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13165 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13166 frame_row
->glyphs
[TEXT_AREA
] = start
;
13167 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13168 frame_row
->glyphs
[LAST_AREA
] = end
;
13170 /* Disable frame rows whose corresponding window rows have
13171 been disabled in try_window_id. */
13172 if (!window_row
->enabled_p
)
13173 frame_row
->enabled_p
= 0;
13175 ++window_row
, ++frame_row
;
13180 /* Find the glyph row in window W containing CHARPOS. Consider all
13181 rows between START and END (not inclusive). END null means search
13182 all rows to the end of the display area of W. Value is the row
13183 containing CHARPOS or null. */
13186 row_containing_pos (w
, charpos
, start
, end
, dy
)
13189 struct glyph_row
*start
, *end
;
13192 struct glyph_row
*row
= start
;
13195 /* If we happen to start on a header-line, skip that. */
13196 if (row
->mode_line_p
)
13199 if ((end
&& row
>= end
) || !row
->enabled_p
)
13202 last_y
= window_text_bottom_y (w
) - dy
;
13206 /* Give up if we have gone too far. */
13207 if (end
&& row
>= end
)
13209 /* This formerly returned if they were equal.
13210 I think that both quantities are of a "last plus one" type;
13211 if so, when they are equal, the row is within the screen. -- rms. */
13212 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13215 /* If it is in this row, return this row. */
13216 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13217 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13218 /* The end position of a row equals the start
13219 position of the next row. If CHARPOS is there, we
13220 would rather display it in the next line, except
13221 when this line ends in ZV. */
13222 && !row
->ends_at_zv_p
13223 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13224 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13231 /* Try to redisplay window W by reusing its existing display. W's
13232 current matrix must be up to date when this function is called,
13233 i.e. window_end_valid must not be nil.
13237 1 if display has been updated
13238 0 if otherwise unsuccessful
13239 -1 if redisplay with same window start is known not to succeed
13241 The following steps are performed:
13243 1. Find the last row in the current matrix of W that is not
13244 affected by changes at the start of current_buffer. If no such row
13247 2. Find the first row in W's current matrix that is not affected by
13248 changes at the end of current_buffer. Maybe there is no such row.
13250 3. Display lines beginning with the row + 1 found in step 1 to the
13251 row found in step 2 or, if step 2 didn't find a row, to the end of
13254 4. If cursor is not known to appear on the window, give up.
13256 5. If display stopped at the row found in step 2, scroll the
13257 display and current matrix as needed.
13259 6. Maybe display some lines at the end of W, if we must. This can
13260 happen under various circumstances, like a partially visible line
13261 becoming fully visible, or because newly displayed lines are displayed
13262 in smaller font sizes.
13264 7. Update W's window end information. */
13270 struct frame
*f
= XFRAME (w
->frame
);
13271 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13272 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13273 struct glyph_row
*last_unchanged_at_beg_row
;
13274 struct glyph_row
*first_unchanged_at_end_row
;
13275 struct glyph_row
*row
;
13276 struct glyph_row
*bottom_row
;
13279 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13280 struct text_pos start_pos
;
13282 int first_unchanged_at_end_vpos
= 0;
13283 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13284 struct text_pos start
;
13285 int first_changed_charpos
, last_changed_charpos
;
13288 if (inhibit_try_window_id
)
13292 /* This is handy for debugging. */
13294 #define GIVE_UP(X) \
13296 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13300 #define GIVE_UP(X) return 0
13303 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13305 /* Don't use this for mini-windows because these can show
13306 messages and mini-buffers, and we don't handle that here. */
13307 if (MINI_WINDOW_P (w
))
13310 /* This flag is used to prevent redisplay optimizations. */
13311 if (windows_or_buffers_changed
|| cursor_type_changed
)
13314 /* Verify that narrowing has not changed.
13315 Also verify that we were not told to prevent redisplay optimizations.
13316 It would be nice to further
13317 reduce the number of cases where this prevents try_window_id. */
13318 if (current_buffer
->clip_changed
13319 || current_buffer
->prevent_redisplay_optimizations_p
)
13322 /* Window must either use window-based redisplay or be full width. */
13323 if (!FRAME_WINDOW_P (f
)
13324 && (!line_ins_del_ok
13325 || !WINDOW_FULL_WIDTH_P (w
)))
13328 /* Give up if point is not known NOT to appear in W. */
13329 if (PT
< CHARPOS (start
))
13332 /* Another way to prevent redisplay optimizations. */
13333 if (XFASTINT (w
->last_modified
) == 0)
13336 /* Verify that window is not hscrolled. */
13337 if (XFASTINT (w
->hscroll
) != 0)
13340 /* Verify that display wasn't paused. */
13341 if (NILP (w
->window_end_valid
))
13344 /* Can't use this if highlighting a region because a cursor movement
13345 will do more than just set the cursor. */
13346 if (!NILP (Vtransient_mark_mode
)
13347 && !NILP (current_buffer
->mark_active
))
13350 /* Likewise if highlighting trailing whitespace. */
13351 if (!NILP (Vshow_trailing_whitespace
))
13354 /* Likewise if showing a region. */
13355 if (!NILP (w
->region_showing
))
13358 /* Can use this if overlay arrow position and or string have changed. */
13359 if (overlay_arrows_changed_p ())
13363 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13364 only if buffer has really changed. The reason is that the gap is
13365 initially at Z for freshly visited files. The code below would
13366 set end_unchanged to 0 in that case. */
13367 if (MODIFF
> SAVE_MODIFF
13368 /* This seems to happen sometimes after saving a buffer. */
13369 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13371 if (GPT
- BEG
< BEG_UNCHANGED
)
13372 BEG_UNCHANGED
= GPT
- BEG
;
13373 if (Z
- GPT
< END_UNCHANGED
)
13374 END_UNCHANGED
= Z
- GPT
;
13377 /* The position of the first and last character that has been changed. */
13378 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13379 last_changed_charpos
= Z
- END_UNCHANGED
;
13381 /* If window starts after a line end, and the last change is in
13382 front of that newline, then changes don't affect the display.
13383 This case happens with stealth-fontification. Note that although
13384 the display is unchanged, glyph positions in the matrix have to
13385 be adjusted, of course. */
13386 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13387 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13388 && ((last_changed_charpos
< CHARPOS (start
)
13389 && CHARPOS (start
) == BEGV
)
13390 || (last_changed_charpos
< CHARPOS (start
) - 1
13391 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13393 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13394 struct glyph_row
*r0
;
13396 /* Compute how many chars/bytes have been added to or removed
13397 from the buffer. */
13398 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13399 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13401 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13403 /* Give up if PT is not in the window. Note that it already has
13404 been checked at the start of try_window_id that PT is not in
13405 front of the window start. */
13406 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13409 /* If window start is unchanged, we can reuse the whole matrix
13410 as is, after adjusting glyph positions. No need to compute
13411 the window end again, since its offset from Z hasn't changed. */
13412 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13413 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13414 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13415 /* PT must not be in a partially visible line. */
13416 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13417 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13419 /* Adjust positions in the glyph matrix. */
13420 if (delta
|| delta_bytes
)
13422 struct glyph_row
*r1
13423 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13424 increment_matrix_positions (w
->current_matrix
,
13425 MATRIX_ROW_VPOS (r0
, current_matrix
),
13426 MATRIX_ROW_VPOS (r1
, current_matrix
),
13427 delta
, delta_bytes
);
13430 /* Set the cursor. */
13431 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13433 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13440 /* Handle the case that changes are all below what is displayed in
13441 the window, and that PT is in the window. This shortcut cannot
13442 be taken if ZV is visible in the window, and text has been added
13443 there that is visible in the window. */
13444 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13445 /* ZV is not visible in the window, or there are no
13446 changes at ZV, actually. */
13447 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13448 || first_changed_charpos
== last_changed_charpos
))
13450 struct glyph_row
*r0
;
13452 /* Give up if PT is not in the window. Note that it already has
13453 been checked at the start of try_window_id that PT is not in
13454 front of the window start. */
13455 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13458 /* If window start is unchanged, we can reuse the whole matrix
13459 as is, without changing glyph positions since no text has
13460 been added/removed in front of the window end. */
13461 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13462 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13463 /* PT must not be in a partially visible line. */
13464 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13465 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13467 /* We have to compute the window end anew since text
13468 can have been added/removed after it. */
13470 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13471 w
->window_end_bytepos
13472 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13474 /* Set the cursor. */
13475 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13477 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13484 /* Give up if window start is in the changed area.
13486 The condition used to read
13488 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13490 but why that was tested escapes me at the moment. */
13491 if (CHARPOS (start
) >= first_changed_charpos
13492 && CHARPOS (start
) <= last_changed_charpos
)
13495 /* Check that window start agrees with the start of the first glyph
13496 row in its current matrix. Check this after we know the window
13497 start is not in changed text, otherwise positions would not be
13499 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13500 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13503 /* Give up if the window ends in strings. Overlay strings
13504 at the end are difficult to handle, so don't try. */
13505 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13506 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13509 /* Compute the position at which we have to start displaying new
13510 lines. Some of the lines at the top of the window might be
13511 reusable because they are not displaying changed text. Find the
13512 last row in W's current matrix not affected by changes at the
13513 start of current_buffer. Value is null if changes start in the
13514 first line of window. */
13515 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13516 if (last_unchanged_at_beg_row
)
13518 /* Avoid starting to display in the moddle of a character, a TAB
13519 for instance. This is easier than to set up the iterator
13520 exactly, and it's not a frequent case, so the additional
13521 effort wouldn't really pay off. */
13522 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13523 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13524 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13525 --last_unchanged_at_beg_row
;
13527 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13530 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13532 start_pos
= it
.current
.pos
;
13534 /* Start displaying new lines in the desired matrix at the same
13535 vpos we would use in the current matrix, i.e. below
13536 last_unchanged_at_beg_row. */
13537 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13539 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13540 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13542 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13546 /* There are no reusable lines at the start of the window.
13547 Start displaying in the first text line. */
13548 start_display (&it
, w
, start
);
13549 it
.vpos
= it
.first_vpos
;
13550 start_pos
= it
.current
.pos
;
13553 /* Find the first row that is not affected by changes at the end of
13554 the buffer. Value will be null if there is no unchanged row, in
13555 which case we must redisplay to the end of the window. delta
13556 will be set to the value by which buffer positions beginning with
13557 first_unchanged_at_end_row have to be adjusted due to text
13559 first_unchanged_at_end_row
13560 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13561 IF_DEBUG (debug_delta
= delta
);
13562 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13564 /* Set stop_pos to the buffer position up to which we will have to
13565 display new lines. If first_unchanged_at_end_row != NULL, this
13566 is the buffer position of the start of the line displayed in that
13567 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13568 that we don't stop at a buffer position. */
13570 if (first_unchanged_at_end_row
)
13572 xassert (last_unchanged_at_beg_row
== NULL
13573 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13575 /* If this is a continuation line, move forward to the next one
13576 that isn't. Changes in lines above affect this line.
13577 Caution: this may move first_unchanged_at_end_row to a row
13578 not displaying text. */
13579 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13580 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13581 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13582 < it
.last_visible_y
))
13583 ++first_unchanged_at_end_row
;
13585 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13586 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13587 >= it
.last_visible_y
))
13588 first_unchanged_at_end_row
= NULL
;
13591 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13593 first_unchanged_at_end_vpos
13594 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13595 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13598 else if (last_unchanged_at_beg_row
== NULL
)
13604 /* Either there is no unchanged row at the end, or the one we have
13605 now displays text. This is a necessary condition for the window
13606 end pos calculation at the end of this function. */
13607 xassert (first_unchanged_at_end_row
== NULL
13608 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13610 debug_last_unchanged_at_beg_vpos
13611 = (last_unchanged_at_beg_row
13612 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13614 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13616 #endif /* GLYPH_DEBUG != 0 */
13619 /* Display new lines. Set last_text_row to the last new line
13620 displayed which has text on it, i.e. might end up as being the
13621 line where the window_end_vpos is. */
13622 w
->cursor
.vpos
= -1;
13623 last_text_row
= NULL
;
13624 overlay_arrow_seen
= 0;
13625 while (it
.current_y
< it
.last_visible_y
13626 && !fonts_changed_p
13627 && (first_unchanged_at_end_row
== NULL
13628 || IT_CHARPOS (it
) < stop_pos
))
13630 if (display_line (&it
))
13631 last_text_row
= it
.glyph_row
- 1;
13634 if (fonts_changed_p
)
13638 /* Compute differences in buffer positions, y-positions etc. for
13639 lines reused at the bottom of the window. Compute what we can
13641 if (first_unchanged_at_end_row
13642 /* No lines reused because we displayed everything up to the
13643 bottom of the window. */
13644 && it
.current_y
< it
.last_visible_y
)
13647 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13649 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13650 run
.current_y
= first_unchanged_at_end_row
->y
;
13651 run
.desired_y
= run
.current_y
+ dy
;
13652 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13656 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13657 first_unchanged_at_end_row
= NULL
;
13659 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13662 /* Find the cursor if not already found. We have to decide whether
13663 PT will appear on this window (it sometimes doesn't, but this is
13664 not a very frequent case.) This decision has to be made before
13665 the current matrix is altered. A value of cursor.vpos < 0 means
13666 that PT is either in one of the lines beginning at
13667 first_unchanged_at_end_row or below the window. Don't care for
13668 lines that might be displayed later at the window end; as
13669 mentioned, this is not a frequent case. */
13670 if (w
->cursor
.vpos
< 0)
13672 /* Cursor in unchanged rows at the top? */
13673 if (PT
< CHARPOS (start_pos
)
13674 && last_unchanged_at_beg_row
)
13676 row
= row_containing_pos (w
, PT
,
13677 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13678 last_unchanged_at_beg_row
+ 1, 0);
13680 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13683 /* Start from first_unchanged_at_end_row looking for PT. */
13684 else if (first_unchanged_at_end_row
)
13686 row
= row_containing_pos (w
, PT
- delta
,
13687 first_unchanged_at_end_row
, NULL
, 0);
13689 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13690 delta_bytes
, dy
, dvpos
);
13693 /* Give up if cursor was not found. */
13694 if (w
->cursor
.vpos
< 0)
13696 clear_glyph_matrix (w
->desired_matrix
);
13701 /* Don't let the cursor end in the scroll margins. */
13703 int this_scroll_margin
, cursor_height
;
13705 this_scroll_margin
= max (0, scroll_margin
);
13706 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13707 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13708 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13710 if ((w
->cursor
.y
< this_scroll_margin
13711 && CHARPOS (start
) > BEGV
)
13712 /* Old redisplay didn't take scroll margin into account at the bottom,
13713 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13714 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13715 ? cursor_height
+ this_scroll_margin
13716 : 1)) > it
.last_visible_y
)
13718 w
->cursor
.vpos
= -1;
13719 clear_glyph_matrix (w
->desired_matrix
);
13724 /* Scroll the display. Do it before changing the current matrix so
13725 that xterm.c doesn't get confused about where the cursor glyph is
13727 if (dy
&& run
.height
)
13731 if (FRAME_WINDOW_P (f
))
13733 rif
->update_window_begin_hook (w
);
13734 rif
->clear_window_mouse_face (w
);
13735 rif
->scroll_run_hook (w
, &run
);
13736 rif
->update_window_end_hook (w
, 0, 0);
13740 /* Terminal frame. In this case, dvpos gives the number of
13741 lines to scroll by; dvpos < 0 means scroll up. */
13742 int first_unchanged_at_end_vpos
13743 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13744 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13745 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13746 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13747 + window_internal_height (w
));
13749 /* Perform the operation on the screen. */
13752 /* Scroll last_unchanged_at_beg_row to the end of the
13753 window down dvpos lines. */
13754 set_terminal_window (end
);
13756 /* On dumb terminals delete dvpos lines at the end
13757 before inserting dvpos empty lines. */
13758 if (!scroll_region_ok
)
13759 ins_del_lines (end
- dvpos
, -dvpos
);
13761 /* Insert dvpos empty lines in front of
13762 last_unchanged_at_beg_row. */
13763 ins_del_lines (from
, dvpos
);
13765 else if (dvpos
< 0)
13767 /* Scroll up last_unchanged_at_beg_vpos to the end of
13768 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13769 set_terminal_window (end
);
13771 /* Delete dvpos lines in front of
13772 last_unchanged_at_beg_vpos. ins_del_lines will set
13773 the cursor to the given vpos and emit |dvpos| delete
13775 ins_del_lines (from
+ dvpos
, dvpos
);
13777 /* On a dumb terminal insert dvpos empty lines at the
13779 if (!scroll_region_ok
)
13780 ins_del_lines (end
+ dvpos
, -dvpos
);
13783 set_terminal_window (0);
13789 /* Shift reused rows of the current matrix to the right position.
13790 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13792 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13793 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13796 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13797 bottom_vpos
, dvpos
);
13798 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13801 else if (dvpos
> 0)
13803 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13804 bottom_vpos
, dvpos
);
13805 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13806 first_unchanged_at_end_vpos
+ dvpos
, 0);
13809 /* For frame-based redisplay, make sure that current frame and window
13810 matrix are in sync with respect to glyph memory. */
13811 if (!FRAME_WINDOW_P (f
))
13812 sync_frame_with_window_matrix_rows (w
);
13814 /* Adjust buffer positions in reused rows. */
13816 increment_matrix_positions (current_matrix
,
13817 first_unchanged_at_end_vpos
+ dvpos
,
13818 bottom_vpos
, delta
, delta_bytes
);
13820 /* Adjust Y positions. */
13822 shift_glyph_matrix (w
, current_matrix
,
13823 first_unchanged_at_end_vpos
+ dvpos
,
13826 if (first_unchanged_at_end_row
)
13827 first_unchanged_at_end_row
+= dvpos
;
13829 /* If scrolling up, there may be some lines to display at the end of
13831 last_text_row_at_end
= NULL
;
13834 /* Scrolling up can leave for example a partially visible line
13835 at the end of the window to be redisplayed. */
13836 /* Set last_row to the glyph row in the current matrix where the
13837 window end line is found. It has been moved up or down in
13838 the matrix by dvpos. */
13839 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13840 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13842 /* If last_row is the window end line, it should display text. */
13843 xassert (last_row
->displays_text_p
);
13845 /* If window end line was partially visible before, begin
13846 displaying at that line. Otherwise begin displaying with the
13847 line following it. */
13848 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13850 init_to_row_start (&it
, w
, last_row
);
13851 it
.vpos
= last_vpos
;
13852 it
.current_y
= last_row
->y
;
13856 init_to_row_end (&it
, w
, last_row
);
13857 it
.vpos
= 1 + last_vpos
;
13858 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13862 /* We may start in a continuation line. If so, we have to
13863 get the right continuation_lines_width and current_x. */
13864 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13865 it
.hpos
= it
.current_x
= 0;
13867 /* Display the rest of the lines at the window end. */
13868 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13869 while (it
.current_y
< it
.last_visible_y
13870 && !fonts_changed_p
)
13872 /* Is it always sure that the display agrees with lines in
13873 the current matrix? I don't think so, so we mark rows
13874 displayed invalid in the current matrix by setting their
13875 enabled_p flag to zero. */
13876 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13877 if (display_line (&it
))
13878 last_text_row_at_end
= it
.glyph_row
- 1;
13882 /* Update window_end_pos and window_end_vpos. */
13883 if (first_unchanged_at_end_row
13884 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13885 && !last_text_row_at_end
)
13887 /* Window end line if one of the preserved rows from the current
13888 matrix. Set row to the last row displaying text in current
13889 matrix starting at first_unchanged_at_end_row, after
13891 xassert (first_unchanged_at_end_row
->displays_text_p
);
13892 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13893 first_unchanged_at_end_row
);
13894 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13896 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13897 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13899 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13900 xassert (w
->window_end_bytepos
>= 0);
13901 IF_DEBUG (debug_method_add (w
, "A"));
13903 else if (last_text_row_at_end
)
13906 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13907 w
->window_end_bytepos
13908 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13910 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13911 xassert (w
->window_end_bytepos
>= 0);
13912 IF_DEBUG (debug_method_add (w
, "B"));
13914 else if (last_text_row
)
13916 /* We have displayed either to the end of the window or at the
13917 end of the window, i.e. the last row with text is to be found
13918 in the desired matrix. */
13920 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13921 w
->window_end_bytepos
13922 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13924 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13925 xassert (w
->window_end_bytepos
>= 0);
13927 else if (first_unchanged_at_end_row
== NULL
13928 && last_text_row
== NULL
13929 && last_text_row_at_end
== NULL
)
13931 /* Displayed to end of window, but no line containing text was
13932 displayed. Lines were deleted at the end of the window. */
13933 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13934 int vpos
= XFASTINT (w
->window_end_vpos
);
13935 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13936 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13939 row
== NULL
&& vpos
>= first_vpos
;
13940 --vpos
, --current_row
, --desired_row
)
13942 if (desired_row
->enabled_p
)
13944 if (desired_row
->displays_text_p
)
13947 else if (current_row
->displays_text_p
)
13951 xassert (row
!= NULL
);
13952 w
->window_end_vpos
= make_number (vpos
+ 1);
13953 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13954 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13955 xassert (w
->window_end_bytepos
>= 0);
13956 IF_DEBUG (debug_method_add (w
, "C"));
13961 #if 0 /* This leads to problems, for instance when the cursor is
13962 at ZV, and the cursor line displays no text. */
13963 /* Disable rows below what's displayed in the window. This makes
13964 debugging easier. */
13965 enable_glyph_matrix_rows (current_matrix
,
13966 XFASTINT (w
->window_end_vpos
) + 1,
13970 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13971 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13973 /* Record that display has not been completed. */
13974 w
->window_end_valid
= Qnil
;
13975 w
->desired_matrix
->no_scrolling_p
= 1;
13983 /***********************************************************************
13984 More debugging support
13985 ***********************************************************************/
13989 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13990 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13991 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13994 /* Dump the contents of glyph matrix MATRIX on stderr.
13996 GLYPHS 0 means don't show glyph contents.
13997 GLYPHS 1 means show glyphs in short form
13998 GLYPHS > 1 means show glyphs in long form. */
14001 dump_glyph_matrix (matrix
, glyphs
)
14002 struct glyph_matrix
*matrix
;
14006 for (i
= 0; i
< matrix
->nrows
; ++i
)
14007 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14011 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14012 the glyph row and area where the glyph comes from. */
14015 dump_glyph (row
, glyph
, area
)
14016 struct glyph_row
*row
;
14017 struct glyph
*glyph
;
14020 if (glyph
->type
== CHAR_GLYPH
)
14023 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14024 glyph
- row
->glyphs
[TEXT_AREA
],
14027 (BUFFERP (glyph
->object
)
14029 : (STRINGP (glyph
->object
)
14032 glyph
->pixel_width
,
14034 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14038 glyph
->left_box_line_p
,
14039 glyph
->right_box_line_p
);
14041 else if (glyph
->type
== STRETCH_GLYPH
)
14044 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14045 glyph
- row
->glyphs
[TEXT_AREA
],
14048 (BUFFERP (glyph
->object
)
14050 : (STRINGP (glyph
->object
)
14053 glyph
->pixel_width
,
14057 glyph
->left_box_line_p
,
14058 glyph
->right_box_line_p
);
14060 else if (glyph
->type
== IMAGE_GLYPH
)
14063 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14064 glyph
- row
->glyphs
[TEXT_AREA
],
14067 (BUFFERP (glyph
->object
)
14069 : (STRINGP (glyph
->object
)
14072 glyph
->pixel_width
,
14076 glyph
->left_box_line_p
,
14077 glyph
->right_box_line_p
);
14082 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14083 GLYPHS 0 means don't show glyph contents.
14084 GLYPHS 1 means show glyphs in short form
14085 GLYPHS > 1 means show glyphs in long form. */
14088 dump_glyph_row (row
, vpos
, glyphs
)
14089 struct glyph_row
*row
;
14094 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
14095 fprintf (stderr
, "=======================================================================\n");
14097 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
14098 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14100 MATRIX_ROW_START_CHARPOS (row
),
14101 MATRIX_ROW_END_CHARPOS (row
),
14102 row
->used
[TEXT_AREA
],
14103 row
->contains_overlapping_glyphs_p
,
14105 row
->truncated_on_left_p
,
14106 row
->truncated_on_right_p
,
14107 row
->overlay_arrow_p
,
14109 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14110 row
->displays_text_p
,
14113 row
->ends_in_middle_of_char_p
,
14114 row
->starts_in_middle_of_char_p
,
14120 row
->visible_height
,
14123 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14124 row
->end
.overlay_string_index
,
14125 row
->continuation_lines_width
);
14126 fprintf (stderr
, "%9d %5d\n",
14127 CHARPOS (row
->start
.string_pos
),
14128 CHARPOS (row
->end
.string_pos
));
14129 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14130 row
->end
.dpvec_index
);
14137 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14139 struct glyph
*glyph
= row
->glyphs
[area
];
14140 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14142 /* Glyph for a line end in text. */
14143 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14146 if (glyph
< glyph_end
)
14147 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14149 for (; glyph
< glyph_end
; ++glyph
)
14150 dump_glyph (row
, glyph
, area
);
14153 else if (glyphs
== 1)
14157 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14159 char *s
= (char *) alloca (row
->used
[area
] + 1);
14162 for (i
= 0; i
< row
->used
[area
]; ++i
)
14164 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14165 if (glyph
->type
== CHAR_GLYPH
14166 && glyph
->u
.ch
< 0x80
14167 && glyph
->u
.ch
>= ' ')
14168 s
[i
] = glyph
->u
.ch
;
14174 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14180 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14181 Sdump_glyph_matrix
, 0, 1, "p",
14182 doc
: /* Dump the current matrix of the selected window to stderr.
14183 Shows contents of glyph row structures. With non-nil
14184 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14185 glyphs in short form, otherwise show glyphs in long form. */)
14187 Lisp_Object glyphs
;
14189 struct window
*w
= XWINDOW (selected_window
);
14190 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14192 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14193 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14194 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14195 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14196 fprintf (stderr
, "=============================================\n");
14197 dump_glyph_matrix (w
->current_matrix
,
14198 NILP (glyphs
) ? 0 : XINT (glyphs
));
14203 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14204 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14207 struct frame
*f
= XFRAME (selected_frame
);
14208 dump_glyph_matrix (f
->current_matrix
, 1);
14213 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14214 doc
: /* Dump glyph row ROW to stderr.
14215 GLYPH 0 means don't dump glyphs.
14216 GLYPH 1 means dump glyphs in short form.
14217 GLYPH > 1 or omitted means dump glyphs in long form. */)
14219 Lisp_Object row
, glyphs
;
14221 struct glyph_matrix
*matrix
;
14224 CHECK_NUMBER (row
);
14225 matrix
= XWINDOW (selected_window
)->current_matrix
;
14227 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14228 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14230 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14235 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14236 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14237 GLYPH 0 means don't dump glyphs.
14238 GLYPH 1 means dump glyphs in short form.
14239 GLYPH > 1 or omitted means dump glyphs in long form. */)
14241 Lisp_Object row
, glyphs
;
14243 struct frame
*sf
= SELECTED_FRAME ();
14244 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14247 CHECK_NUMBER (row
);
14249 if (vpos
>= 0 && vpos
< m
->nrows
)
14250 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14251 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14256 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14257 doc
: /* Toggle tracing of redisplay.
14258 With ARG, turn tracing on if and only if ARG is positive. */)
14263 trace_redisplay_p
= !trace_redisplay_p
;
14266 arg
= Fprefix_numeric_value (arg
);
14267 trace_redisplay_p
= XINT (arg
) > 0;
14274 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14275 doc
: /* Like `format', but print result to stderr.
14276 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14281 Lisp_Object s
= Fformat (nargs
, args
);
14282 fprintf (stderr
, "%s", SDATA (s
));
14286 #endif /* GLYPH_DEBUG */
14290 /***********************************************************************
14291 Building Desired Matrix Rows
14292 ***********************************************************************/
14294 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14295 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14297 static struct glyph_row
*
14298 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14300 Lisp_Object overlay_arrow_string
;
14302 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14303 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14304 struct buffer
*old
= current_buffer
;
14305 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14306 int arrow_len
= SCHARS (overlay_arrow_string
);
14307 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14308 const unsigned char *p
;
14311 int n_glyphs_before
;
14313 set_buffer_temp (buffer
);
14314 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14315 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14316 SET_TEXT_POS (it
.position
, 0, 0);
14318 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14320 while (p
< arrow_end
)
14322 Lisp_Object face
, ilisp
;
14324 /* Get the next character. */
14326 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14328 it
.c
= *p
, it
.len
= 1;
14331 /* Get its face. */
14332 ilisp
= make_number (p
- arrow_string
);
14333 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14334 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14336 /* Compute its width, get its glyphs. */
14337 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14338 SET_TEXT_POS (it
.position
, -1, -1);
14339 PRODUCE_GLYPHS (&it
);
14341 /* If this character doesn't fit any more in the line, we have
14342 to remove some glyphs. */
14343 if (it
.current_x
> it
.last_visible_x
)
14345 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14350 set_buffer_temp (old
);
14351 return it
.glyph_row
;
14355 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14356 glyphs are only inserted for terminal frames since we can't really
14357 win with truncation glyphs when partially visible glyphs are
14358 involved. Which glyphs to insert is determined by
14359 produce_special_glyphs. */
14362 insert_left_trunc_glyphs (it
)
14365 struct it truncate_it
;
14366 struct glyph
*from
, *end
, *to
, *toend
;
14368 xassert (!FRAME_WINDOW_P (it
->f
));
14370 /* Get the truncation glyphs. */
14372 truncate_it
.current_x
= 0;
14373 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14374 truncate_it
.glyph_row
= &scratch_glyph_row
;
14375 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14376 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14377 truncate_it
.object
= make_number (0);
14378 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14380 /* Overwrite glyphs from IT with truncation glyphs. */
14381 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14382 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14383 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14384 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14389 /* There may be padding glyphs left over. Overwrite them too. */
14390 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14392 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14398 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14402 /* Compute the pixel height and width of IT->glyph_row.
14404 Most of the time, ascent and height of a display line will be equal
14405 to the max_ascent and max_height values of the display iterator
14406 structure. This is not the case if
14408 1. We hit ZV without displaying anything. In this case, max_ascent
14409 and max_height will be zero.
14411 2. We have some glyphs that don't contribute to the line height.
14412 (The glyph row flag contributes_to_line_height_p is for future
14413 pixmap extensions).
14415 The first case is easily covered by using default values because in
14416 these cases, the line height does not really matter, except that it
14417 must not be zero. */
14420 compute_line_metrics (it
)
14423 struct glyph_row
*row
= it
->glyph_row
;
14426 if (FRAME_WINDOW_P (it
->f
))
14428 int i
, min_y
, max_y
;
14430 /* The line may consist of one space only, that was added to
14431 place the cursor on it. If so, the row's height hasn't been
14433 if (row
->height
== 0)
14435 if (it
->max_ascent
+ it
->max_descent
== 0)
14436 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14437 row
->ascent
= it
->max_ascent
;
14438 row
->height
= it
->max_ascent
+ it
->max_descent
;
14439 row
->phys_ascent
= it
->max_phys_ascent
;
14440 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14441 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14444 /* Compute the width of this line. */
14445 row
->pixel_width
= row
->x
;
14446 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14447 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14449 xassert (row
->pixel_width
>= 0);
14450 xassert (row
->ascent
>= 0 && row
->height
> 0);
14452 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14453 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14455 /* If first line's physical ascent is larger than its logical
14456 ascent, use the physical ascent, and make the row taller.
14457 This makes accented characters fully visible. */
14458 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14459 && row
->phys_ascent
> row
->ascent
)
14461 row
->height
+= row
->phys_ascent
- row
->ascent
;
14462 row
->ascent
= row
->phys_ascent
;
14465 /* Compute how much of the line is visible. */
14466 row
->visible_height
= row
->height
;
14468 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14469 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14471 if (row
->y
< min_y
)
14472 row
->visible_height
-= min_y
- row
->y
;
14473 if (row
->y
+ row
->height
> max_y
)
14474 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14478 row
->pixel_width
= row
->used
[TEXT_AREA
];
14479 if (row
->continued_p
)
14480 row
->pixel_width
-= it
->continuation_pixel_width
;
14481 else if (row
->truncated_on_right_p
)
14482 row
->pixel_width
-= it
->truncation_pixel_width
;
14483 row
->ascent
= row
->phys_ascent
= 0;
14484 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14485 row
->extra_line_spacing
= 0;
14488 /* Compute a hash code for this row. */
14490 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14491 for (i
= 0; i
< row
->used
[area
]; ++i
)
14492 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14493 + row
->glyphs
[area
][i
].u
.val
14494 + row
->glyphs
[area
][i
].face_id
14495 + row
->glyphs
[area
][i
].padding_p
14496 + (row
->glyphs
[area
][i
].type
<< 2));
14498 it
->max_ascent
= it
->max_descent
= 0;
14499 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14503 /* Append one space to the glyph row of iterator IT if doing a
14504 window-based redisplay. The space has the same face as
14505 IT->face_id. Value is non-zero if a space was added.
14507 This function is called to make sure that there is always one glyph
14508 at the end of a glyph row that the cursor can be set on under
14509 window-systems. (If there weren't such a glyph we would not know
14510 how wide and tall a box cursor should be displayed).
14512 At the same time this space let's a nicely handle clearing to the
14513 end of the line if the row ends in italic text. */
14516 append_space_for_newline (it
, default_face_p
)
14518 int default_face_p
;
14520 if (FRAME_WINDOW_P (it
->f
))
14522 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14524 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14525 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14527 /* Save some values that must not be changed.
14528 Must save IT->c and IT->len because otherwise
14529 ITERATOR_AT_END_P wouldn't work anymore after
14530 append_space_for_newline has been called. */
14531 enum display_element_type saved_what
= it
->what
;
14532 int saved_c
= it
->c
, saved_len
= it
->len
;
14533 int saved_x
= it
->current_x
;
14534 int saved_face_id
= it
->face_id
;
14535 struct text_pos saved_pos
;
14536 Lisp_Object saved_object
;
14539 saved_object
= it
->object
;
14540 saved_pos
= it
->position
;
14542 it
->what
= IT_CHARACTER
;
14543 bzero (&it
->position
, sizeof it
->position
);
14544 it
->object
= make_number (0);
14548 if (default_face_p
)
14549 it
->face_id
= DEFAULT_FACE_ID
;
14550 else if (it
->face_before_selective_p
)
14551 it
->face_id
= it
->saved_face_id
;
14552 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14553 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14555 PRODUCE_GLYPHS (it
);
14557 it
->override_ascent
= -1;
14558 it
->constrain_row_ascent_descent_p
= 0;
14559 it
->current_x
= saved_x
;
14560 it
->object
= saved_object
;
14561 it
->position
= saved_pos
;
14562 it
->what
= saved_what
;
14563 it
->face_id
= saved_face_id
;
14564 it
->len
= saved_len
;
14574 /* Extend the face of the last glyph in the text area of IT->glyph_row
14575 to the end of the display line. Called from display_line.
14576 If the glyph row is empty, add a space glyph to it so that we
14577 know the face to draw. Set the glyph row flag fill_line_p. */
14580 extend_face_to_end_of_line (it
)
14584 struct frame
*f
= it
->f
;
14586 /* If line is already filled, do nothing. */
14587 if (it
->current_x
>= it
->last_visible_x
)
14590 /* Face extension extends the background and box of IT->face_id
14591 to the end of the line. If the background equals the background
14592 of the frame, we don't have to do anything. */
14593 if (it
->face_before_selective_p
)
14594 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14596 face
= FACE_FROM_ID (f
, it
->face_id
);
14598 if (FRAME_WINDOW_P (f
)
14599 && face
->box
== FACE_NO_BOX
14600 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14604 /* Set the glyph row flag indicating that the face of the last glyph
14605 in the text area has to be drawn to the end of the text area. */
14606 it
->glyph_row
->fill_line_p
= 1;
14608 /* If current character of IT is not ASCII, make sure we have the
14609 ASCII face. This will be automatically undone the next time
14610 get_next_display_element returns a multibyte character. Note
14611 that the character will always be single byte in unibyte text. */
14612 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14614 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14617 if (FRAME_WINDOW_P (f
))
14619 /* If the row is empty, add a space with the current face of IT,
14620 so that we know which face to draw. */
14621 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14623 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14624 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14625 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14630 /* Save some values that must not be changed. */
14631 int saved_x
= it
->current_x
;
14632 struct text_pos saved_pos
;
14633 Lisp_Object saved_object
;
14634 enum display_element_type saved_what
= it
->what
;
14635 int saved_face_id
= it
->face_id
;
14637 saved_object
= it
->object
;
14638 saved_pos
= it
->position
;
14640 it
->what
= IT_CHARACTER
;
14641 bzero (&it
->position
, sizeof it
->position
);
14642 it
->object
= make_number (0);
14645 it
->face_id
= face
->id
;
14647 PRODUCE_GLYPHS (it
);
14649 while (it
->current_x
<= it
->last_visible_x
)
14650 PRODUCE_GLYPHS (it
);
14652 /* Don't count these blanks really. It would let us insert a left
14653 truncation glyph below and make us set the cursor on them, maybe. */
14654 it
->current_x
= saved_x
;
14655 it
->object
= saved_object
;
14656 it
->position
= saved_pos
;
14657 it
->what
= saved_what
;
14658 it
->face_id
= saved_face_id
;
14663 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14664 trailing whitespace. */
14667 trailing_whitespace_p (charpos
)
14670 int bytepos
= CHAR_TO_BYTE (charpos
);
14673 while (bytepos
< ZV_BYTE
14674 && (c
= FETCH_CHAR (bytepos
),
14675 c
== ' ' || c
== '\t'))
14678 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14680 if (bytepos
!= PT_BYTE
)
14687 /* Highlight trailing whitespace, if any, in ROW. */
14690 highlight_trailing_whitespace (f
, row
)
14692 struct glyph_row
*row
;
14694 int used
= row
->used
[TEXT_AREA
];
14698 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14699 struct glyph
*glyph
= start
+ used
- 1;
14701 /* Skip over glyphs inserted to display the cursor at the
14702 end of a line, for extending the face of the last glyph
14703 to the end of the line on terminals, and for truncation
14704 and continuation glyphs. */
14705 while (glyph
>= start
14706 && glyph
->type
== CHAR_GLYPH
14707 && INTEGERP (glyph
->object
))
14710 /* If last glyph is a space or stretch, and it's trailing
14711 whitespace, set the face of all trailing whitespace glyphs in
14712 IT->glyph_row to `trailing-whitespace'. */
14714 && BUFFERP (glyph
->object
)
14715 && (glyph
->type
== STRETCH_GLYPH
14716 || (glyph
->type
== CHAR_GLYPH
14717 && glyph
->u
.ch
== ' '))
14718 && trailing_whitespace_p (glyph
->charpos
))
14720 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14724 while (glyph
>= start
14725 && BUFFERP (glyph
->object
)
14726 && (glyph
->type
== STRETCH_GLYPH
14727 || (glyph
->type
== CHAR_GLYPH
14728 && glyph
->u
.ch
== ' ')))
14729 (glyph
--)->face_id
= face_id
;
14735 /* Value is non-zero if glyph row ROW in window W should be
14736 used to hold the cursor. */
14739 cursor_row_p (w
, row
)
14741 struct glyph_row
*row
;
14743 int cursor_row_p
= 1;
14745 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14747 /* If the row ends with a newline from a string, we don't want
14748 the cursor there (if the row is continued it doesn't end in a
14750 if (CHARPOS (row
->end
.string_pos
) >= 0)
14751 cursor_row_p
= row
->continued_p
;
14752 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14754 /* If the row ends in middle of a real character,
14755 and the line is continued, we want the cursor here.
14756 That's because MATRIX_ROW_END_CHARPOS would equal
14757 PT if PT is before the character. */
14758 if (!row
->ends_in_ellipsis_p
)
14759 cursor_row_p
= row
->continued_p
;
14761 /* If the row ends in an ellipsis, then
14762 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
14763 We want that position to be displayed after the ellipsis. */
14766 /* If the row ends at ZV, display the cursor at the end of that
14767 row instead of at the start of the row below. */
14768 else if (row
->ends_at_zv_p
)
14774 return cursor_row_p
;
14778 /* Construct the glyph row IT->glyph_row in the desired matrix of
14779 IT->w from text at the current position of IT. See dispextern.h
14780 for an overview of struct it. Value is non-zero if
14781 IT->glyph_row displays text, as opposed to a line displaying ZV
14788 struct glyph_row
*row
= it
->glyph_row
;
14789 int overlay_arrow_bitmap
;
14790 Lisp_Object overlay_arrow_string
;
14792 /* We always start displaying at hpos zero even if hscrolled. */
14793 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14795 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14796 >= it
->w
->desired_matrix
->nrows
)
14798 it
->w
->nrows_scale_factor
++;
14799 fonts_changed_p
= 1;
14803 /* Is IT->w showing the region? */
14804 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14806 /* Clear the result glyph row and enable it. */
14807 prepare_desired_row (row
);
14809 row
->y
= it
->current_y
;
14810 row
->start
= it
->start
;
14811 row
->continuation_lines_width
= it
->continuation_lines_width
;
14812 row
->displays_text_p
= 1;
14813 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14814 it
->starts_in_middle_of_char_p
= 0;
14816 /* Arrange the overlays nicely for our purposes. Usually, we call
14817 display_line on only one line at a time, in which case this
14818 can't really hurt too much, or we call it on lines which appear
14819 one after another in the buffer, in which case all calls to
14820 recenter_overlay_lists but the first will be pretty cheap. */
14821 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14823 /* Move over display elements that are not visible because we are
14824 hscrolled. This may stop at an x-position < IT->first_visible_x
14825 if the first glyph is partially visible or if we hit a line end. */
14826 if (it
->current_x
< it
->first_visible_x
)
14828 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14829 MOVE_TO_POS
| MOVE_TO_X
);
14832 /* Get the initial row height. This is either the height of the
14833 text hscrolled, if there is any, or zero. */
14834 row
->ascent
= it
->max_ascent
;
14835 row
->height
= it
->max_ascent
+ it
->max_descent
;
14836 row
->phys_ascent
= it
->max_phys_ascent
;
14837 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14838 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14840 /* Loop generating characters. The loop is left with IT on the next
14841 character to display. */
14844 int n_glyphs_before
, hpos_before
, x_before
;
14846 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14848 /* Retrieve the next thing to display. Value is zero if end of
14850 if (!get_next_display_element (it
))
14852 /* Maybe add a space at the end of this line that is used to
14853 display the cursor there under X. Set the charpos of the
14854 first glyph of blank lines not corresponding to any text
14856 #ifdef HAVE_WINDOW_SYSTEM
14857 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14858 row
->exact_window_width_line_p
= 1;
14860 #endif /* HAVE_WINDOW_SYSTEM */
14861 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14862 || row
->used
[TEXT_AREA
] == 0)
14864 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14865 row
->displays_text_p
= 0;
14867 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14868 && (!MINI_WINDOW_P (it
->w
)
14869 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14870 row
->indicate_empty_line_p
= 1;
14873 it
->continuation_lines_width
= 0;
14874 row
->ends_at_zv_p
= 1;
14878 /* Now, get the metrics of what we want to display. This also
14879 generates glyphs in `row' (which is IT->glyph_row). */
14880 n_glyphs_before
= row
->used
[TEXT_AREA
];
14883 /* Remember the line height so far in case the next element doesn't
14884 fit on the line. */
14885 if (!it
->truncate_lines_p
)
14887 ascent
= it
->max_ascent
;
14888 descent
= it
->max_descent
;
14889 phys_ascent
= it
->max_phys_ascent
;
14890 phys_descent
= it
->max_phys_descent
;
14893 PRODUCE_GLYPHS (it
);
14895 /* If this display element was in marginal areas, continue with
14897 if (it
->area
!= TEXT_AREA
)
14899 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14900 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14901 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14902 row
->phys_height
= max (row
->phys_height
,
14903 it
->max_phys_ascent
+ it
->max_phys_descent
);
14904 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14905 it
->max_extra_line_spacing
);
14906 set_iterator_to_next (it
, 1);
14910 /* Does the display element fit on the line? If we truncate
14911 lines, we should draw past the right edge of the window. If
14912 we don't truncate, we want to stop so that we can display the
14913 continuation glyph before the right margin. If lines are
14914 continued, there are two possible strategies for characters
14915 resulting in more than 1 glyph (e.g. tabs): Display as many
14916 glyphs as possible in this line and leave the rest for the
14917 continuation line, or display the whole element in the next
14918 line. Original redisplay did the former, so we do it also. */
14919 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14920 hpos_before
= it
->hpos
;
14923 if (/* Not a newline. */
14925 /* Glyphs produced fit entirely in the line. */
14926 && it
->current_x
< it
->last_visible_x
)
14928 it
->hpos
+= nglyphs
;
14929 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14930 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14931 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14932 row
->phys_height
= max (row
->phys_height
,
14933 it
->max_phys_ascent
+ it
->max_phys_descent
);
14934 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14935 it
->max_extra_line_spacing
);
14936 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14937 row
->x
= x
- it
->first_visible_x
;
14942 struct glyph
*glyph
;
14944 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14946 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14947 new_x
= x
+ glyph
->pixel_width
;
14949 if (/* Lines are continued. */
14950 !it
->truncate_lines_p
14951 && (/* Glyph doesn't fit on the line. */
14952 new_x
> it
->last_visible_x
14953 /* Or it fits exactly on a window system frame. */
14954 || (new_x
== it
->last_visible_x
14955 && FRAME_WINDOW_P (it
->f
))))
14957 /* End of a continued line. */
14960 || (new_x
== it
->last_visible_x
14961 && FRAME_WINDOW_P (it
->f
)))
14963 /* Current glyph is the only one on the line or
14964 fits exactly on the line. We must continue
14965 the line because we can't draw the cursor
14966 after the glyph. */
14967 row
->continued_p
= 1;
14968 it
->current_x
= new_x
;
14969 it
->continuation_lines_width
+= new_x
;
14971 if (i
== nglyphs
- 1)
14973 set_iterator_to_next (it
, 1);
14974 #ifdef HAVE_WINDOW_SYSTEM
14975 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14977 if (!get_next_display_element (it
))
14979 row
->exact_window_width_line_p
= 1;
14980 it
->continuation_lines_width
= 0;
14981 row
->continued_p
= 0;
14982 row
->ends_at_zv_p
= 1;
14984 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14986 row
->continued_p
= 0;
14987 row
->exact_window_width_line_p
= 1;
14990 #endif /* HAVE_WINDOW_SYSTEM */
14993 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14994 && !FRAME_WINDOW_P (it
->f
))
14996 /* A padding glyph that doesn't fit on this line.
14997 This means the whole character doesn't fit
14999 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15001 /* Fill the rest of the row with continuation
15002 glyphs like in 20.x. */
15003 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15004 < row
->glyphs
[1 + TEXT_AREA
])
15005 produce_special_glyphs (it
, IT_CONTINUATION
);
15007 row
->continued_p
= 1;
15008 it
->current_x
= x_before
;
15009 it
->continuation_lines_width
+= x_before
;
15011 /* Restore the height to what it was before the
15012 element not fitting on the line. */
15013 it
->max_ascent
= ascent
;
15014 it
->max_descent
= descent
;
15015 it
->max_phys_ascent
= phys_ascent
;
15016 it
->max_phys_descent
= phys_descent
;
15018 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15020 /* A TAB that extends past the right edge of the
15021 window. This produces a single glyph on
15022 window system frames. We leave the glyph in
15023 this row and let it fill the row, but don't
15024 consume the TAB. */
15025 it
->continuation_lines_width
+= it
->last_visible_x
;
15026 row
->ends_in_middle_of_char_p
= 1;
15027 row
->continued_p
= 1;
15028 glyph
->pixel_width
= it
->last_visible_x
- x
;
15029 it
->starts_in_middle_of_char_p
= 1;
15033 /* Something other than a TAB that draws past
15034 the right edge of the window. Restore
15035 positions to values before the element. */
15036 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15038 /* Display continuation glyphs. */
15039 if (!FRAME_WINDOW_P (it
->f
))
15040 produce_special_glyphs (it
, IT_CONTINUATION
);
15041 row
->continued_p
= 1;
15043 it
->continuation_lines_width
+= x
;
15045 if (nglyphs
> 1 && i
> 0)
15047 row
->ends_in_middle_of_char_p
= 1;
15048 it
->starts_in_middle_of_char_p
= 1;
15051 /* Restore the height to what it was before the
15052 element not fitting on the line. */
15053 it
->max_ascent
= ascent
;
15054 it
->max_descent
= descent
;
15055 it
->max_phys_ascent
= phys_ascent
;
15056 it
->max_phys_descent
= phys_descent
;
15061 else if (new_x
> it
->first_visible_x
)
15063 /* Increment number of glyphs actually displayed. */
15066 if (x
< it
->first_visible_x
)
15067 /* Glyph is partially visible, i.e. row starts at
15068 negative X position. */
15069 row
->x
= x
- it
->first_visible_x
;
15073 /* Glyph is completely off the left margin of the
15074 window. This should not happen because of the
15075 move_it_in_display_line at the start of this
15076 function, unless the text display area of the
15077 window is empty. */
15078 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15082 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15083 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15084 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15085 row
->phys_height
= max (row
->phys_height
,
15086 it
->max_phys_ascent
+ it
->max_phys_descent
);
15087 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15088 it
->max_extra_line_spacing
);
15090 /* End of this display line if row is continued. */
15091 if (row
->continued_p
|| row
->ends_at_zv_p
)
15096 /* Is this a line end? If yes, we're also done, after making
15097 sure that a non-default face is extended up to the right
15098 margin of the window. */
15099 if (ITERATOR_AT_END_OF_LINE_P (it
))
15101 int used_before
= row
->used
[TEXT_AREA
];
15103 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15105 #ifdef HAVE_WINDOW_SYSTEM
15106 /* Add a space at the end of the line that is used to
15107 display the cursor there. */
15108 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15109 append_space_for_newline (it
, 0);
15110 #endif /* HAVE_WINDOW_SYSTEM */
15112 /* Extend the face to the end of the line. */
15113 extend_face_to_end_of_line (it
);
15115 /* Make sure we have the position. */
15116 if (used_before
== 0)
15117 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15119 /* Consume the line end. This skips over invisible lines. */
15120 set_iterator_to_next (it
, 1);
15121 it
->continuation_lines_width
= 0;
15125 /* Proceed with next display element. Note that this skips
15126 over lines invisible because of selective display. */
15127 set_iterator_to_next (it
, 1);
15129 /* If we truncate lines, we are done when the last displayed
15130 glyphs reach past the right margin of the window. */
15131 if (it
->truncate_lines_p
15132 && (FRAME_WINDOW_P (it
->f
)
15133 ? (it
->current_x
>= it
->last_visible_x
)
15134 : (it
->current_x
> it
->last_visible_x
)))
15136 /* Maybe add truncation glyphs. */
15137 if (!FRAME_WINDOW_P (it
->f
))
15141 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15142 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15145 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15147 row
->used
[TEXT_AREA
] = i
;
15148 produce_special_glyphs (it
, IT_TRUNCATION
);
15151 #ifdef HAVE_WINDOW_SYSTEM
15154 /* Don't truncate if we can overflow newline into fringe. */
15155 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15157 if (!get_next_display_element (it
))
15159 it
->continuation_lines_width
= 0;
15160 row
->ends_at_zv_p
= 1;
15161 row
->exact_window_width_line_p
= 1;
15164 if (ITERATOR_AT_END_OF_LINE_P (it
))
15166 row
->exact_window_width_line_p
= 1;
15167 goto at_end_of_line
;
15171 #endif /* HAVE_WINDOW_SYSTEM */
15173 row
->truncated_on_right_p
= 1;
15174 it
->continuation_lines_width
= 0;
15175 reseat_at_next_visible_line_start (it
, 0);
15176 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15177 it
->hpos
= hpos_before
;
15178 it
->current_x
= x_before
;
15183 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15184 at the left window margin. */
15185 if (it
->first_visible_x
15186 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15188 if (!FRAME_WINDOW_P (it
->f
))
15189 insert_left_trunc_glyphs (it
);
15190 row
->truncated_on_left_p
= 1;
15193 /* If the start of this line is the overlay arrow-position, then
15194 mark this glyph row as the one containing the overlay arrow.
15195 This is clearly a mess with variable size fonts. It would be
15196 better to let it be displayed like cursors under X. */
15197 if (! overlay_arrow_seen
15198 && (overlay_arrow_string
15199 = overlay_arrow_at_row (it
, row
, &overlay_arrow_bitmap
),
15200 !NILP (overlay_arrow_string
)))
15202 /* Overlay arrow in window redisplay is a fringe bitmap. */
15203 if (STRINGP (overlay_arrow_string
))
15205 struct glyph_row
*arrow_row
15206 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15207 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15208 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15209 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15210 struct glyph
*p2
, *end
;
15212 /* Copy the arrow glyphs. */
15213 while (glyph
< arrow_end
)
15216 /* Throw away padding glyphs. */
15218 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15219 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15225 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15230 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
15231 row
->overlay_arrow_p
= 1;
15233 overlay_arrow_seen
= 1;
15236 /* Compute pixel dimensions of this line. */
15237 compute_line_metrics (it
);
15239 /* Remember the position at which this line ends. */
15240 row
->end
= it
->current
;
15242 /* Record whether this row ends inside an ellipsis. */
15243 row
->ends_in_ellipsis_p
15244 = (it
->method
== next_element_from_display_vector
15245 && it
->ellipsis_p
);
15247 /* Save fringe bitmaps in this row. */
15248 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15249 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15250 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15251 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15253 it
->left_user_fringe_bitmap
= 0;
15254 it
->left_user_fringe_face_id
= 0;
15255 it
->right_user_fringe_bitmap
= 0;
15256 it
->right_user_fringe_face_id
= 0;
15258 /* Maybe set the cursor. */
15259 if (it
->w
->cursor
.vpos
< 0
15260 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15261 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15262 && cursor_row_p (it
->w
, row
))
15263 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15265 /* Highlight trailing whitespace. */
15266 if (!NILP (Vshow_trailing_whitespace
))
15267 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15269 /* Prepare for the next line. This line starts horizontally at (X
15270 HPOS) = (0 0). Vertical positions are incremented. As a
15271 convenience for the caller, IT->glyph_row is set to the next
15273 it
->current_x
= it
->hpos
= 0;
15274 it
->current_y
+= row
->height
;
15277 it
->start
= it
->current
;
15278 return row
->displays_text_p
;
15283 /***********************************************************************
15285 ***********************************************************************/
15287 /* Redisplay the menu bar in the frame for window W.
15289 The menu bar of X frames that don't have X toolkit support is
15290 displayed in a special window W->frame->menu_bar_window.
15292 The menu bar of terminal frames is treated specially as far as
15293 glyph matrices are concerned. Menu bar lines are not part of
15294 windows, so the update is done directly on the frame matrix rows
15295 for the menu bar. */
15298 display_menu_bar (w
)
15301 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15306 /* Don't do all this for graphical frames. */
15308 if (!NILP (Vwindow_system
))
15311 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15316 if (FRAME_MAC_P (f
))
15320 #ifdef USE_X_TOOLKIT
15321 xassert (!FRAME_WINDOW_P (f
));
15322 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15323 it
.first_visible_x
= 0;
15324 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15325 #else /* not USE_X_TOOLKIT */
15326 if (FRAME_WINDOW_P (f
))
15328 /* Menu bar lines are displayed in the desired matrix of the
15329 dummy window menu_bar_window. */
15330 struct window
*menu_w
;
15331 xassert (WINDOWP (f
->menu_bar_window
));
15332 menu_w
= XWINDOW (f
->menu_bar_window
);
15333 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15335 it
.first_visible_x
= 0;
15336 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15340 /* This is a TTY frame, i.e. character hpos/vpos are used as
15342 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15344 it
.first_visible_x
= 0;
15345 it
.last_visible_x
= FRAME_COLS (f
);
15347 #endif /* not USE_X_TOOLKIT */
15349 if (! mode_line_inverse_video
)
15350 /* Force the menu-bar to be displayed in the default face. */
15351 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15353 /* Clear all rows of the menu bar. */
15354 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15356 struct glyph_row
*row
= it
.glyph_row
+ i
;
15357 clear_glyph_row (row
);
15358 row
->enabled_p
= 1;
15359 row
->full_width_p
= 1;
15362 /* Display all items of the menu bar. */
15363 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15364 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15366 Lisp_Object string
;
15368 /* Stop at nil string. */
15369 string
= AREF (items
, i
+ 1);
15373 /* Remember where item was displayed. */
15374 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15376 /* Display the item, pad with one space. */
15377 if (it
.current_x
< it
.last_visible_x
)
15378 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15379 SCHARS (string
) + 1, 0, 0, -1);
15382 /* Fill out the line with spaces. */
15383 if (it
.current_x
< it
.last_visible_x
)
15384 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15386 /* Compute the total height of the lines. */
15387 compute_line_metrics (&it
);
15392 /***********************************************************************
15394 ***********************************************************************/
15396 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15397 FORCE is non-zero, redisplay mode lines unconditionally.
15398 Otherwise, redisplay only mode lines that are garbaged. Value is
15399 the number of windows whose mode lines were redisplayed. */
15402 redisplay_mode_lines (window
, force
)
15403 Lisp_Object window
;
15408 while (!NILP (window
))
15410 struct window
*w
= XWINDOW (window
);
15412 if (WINDOWP (w
->hchild
))
15413 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15414 else if (WINDOWP (w
->vchild
))
15415 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15417 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15418 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15420 struct text_pos lpoint
;
15421 struct buffer
*old
= current_buffer
;
15423 /* Set the window's buffer for the mode line display. */
15424 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15425 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15427 /* Point refers normally to the selected window. For any
15428 other window, set up appropriate value. */
15429 if (!EQ (window
, selected_window
))
15431 struct text_pos pt
;
15433 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15434 if (CHARPOS (pt
) < BEGV
)
15435 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15436 else if (CHARPOS (pt
) > (ZV
- 1))
15437 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15439 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15442 /* Display mode lines. */
15443 clear_glyph_matrix (w
->desired_matrix
);
15444 if (display_mode_lines (w
))
15447 w
->must_be_updated_p
= 1;
15450 /* Restore old settings. */
15451 set_buffer_internal_1 (old
);
15452 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15462 /* Display the mode and/or top line of window W. Value is the number
15463 of mode lines displayed. */
15466 display_mode_lines (w
)
15469 Lisp_Object old_selected_window
, old_selected_frame
;
15472 old_selected_frame
= selected_frame
;
15473 selected_frame
= w
->frame
;
15474 old_selected_window
= selected_window
;
15475 XSETWINDOW (selected_window
, w
);
15477 /* These will be set while the mode line specs are processed. */
15478 line_number_displayed
= 0;
15479 w
->column_number_displayed
= Qnil
;
15481 if (WINDOW_WANTS_MODELINE_P (w
))
15483 struct window
*sel_w
= XWINDOW (old_selected_window
);
15485 /* Select mode line face based on the real selected window. */
15486 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15487 current_buffer
->mode_line_format
);
15491 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15493 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15494 current_buffer
->header_line_format
);
15498 selected_frame
= old_selected_frame
;
15499 selected_window
= old_selected_window
;
15504 /* Display mode or top line of window W. FACE_ID specifies which line
15505 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15506 FORMAT is the mode line format to display. Value is the pixel
15507 height of the mode line displayed. */
15510 display_mode_line (w
, face_id
, format
)
15512 enum face_id face_id
;
15513 Lisp_Object format
;
15518 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15519 prepare_desired_row (it
.glyph_row
);
15521 it
.glyph_row
->mode_line_p
= 1;
15523 if (! mode_line_inverse_video
)
15524 /* Force the mode-line to be displayed in the default face. */
15525 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15527 /* Temporarily make frame's keyboard the current kboard so that
15528 kboard-local variables in the mode_line_format will get the right
15530 push_frame_kboard (it
.f
);
15531 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15532 pop_frame_kboard ();
15534 /* Fill up with spaces. */
15535 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15537 compute_line_metrics (&it
);
15538 it
.glyph_row
->full_width_p
= 1;
15539 it
.glyph_row
->continued_p
= 0;
15540 it
.glyph_row
->truncated_on_left_p
= 0;
15541 it
.glyph_row
->truncated_on_right_p
= 0;
15543 /* Make a 3D mode-line have a shadow at its right end. */
15544 face
= FACE_FROM_ID (it
.f
, face_id
);
15545 extend_face_to_end_of_line (&it
);
15546 if (face
->box
!= FACE_NO_BOX
)
15548 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15549 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15550 last
->right_box_line_p
= 1;
15553 return it
.glyph_row
->height
;
15556 /* Alist that caches the results of :propertize.
15557 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15558 Lisp_Object mode_line_proptrans_alist
;
15560 /* List of strings making up the mode-line. */
15561 Lisp_Object mode_line_string_list
;
15563 /* Base face property when building propertized mode line string. */
15564 static Lisp_Object mode_line_string_face
;
15565 static Lisp_Object mode_line_string_face_prop
;
15568 /* Contribute ELT to the mode line for window IT->w. How it
15569 translates into text depends on its data type.
15571 IT describes the display environment in which we display, as usual.
15573 DEPTH is the depth in recursion. It is used to prevent
15574 infinite recursion here.
15576 FIELD_WIDTH is the number of characters the display of ELT should
15577 occupy in the mode line, and PRECISION is the maximum number of
15578 characters to display from ELT's representation. See
15579 display_string for details.
15581 Returns the hpos of the end of the text generated by ELT.
15583 PROPS is a property list to add to any string we encounter.
15585 If RISKY is nonzero, remove (disregard) any properties in any string
15586 we encounter, and ignore :eval and :propertize.
15588 If the global variable `frame_title_ptr' is non-NULL, then the output
15589 is passed to `store_frame_title' instead of `display_string'. */
15592 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15595 int field_width
, precision
;
15596 Lisp_Object elt
, props
;
15599 int n
= 0, field
, prec
;
15604 elt
= build_string ("*too-deep*");
15608 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15612 /* A string: output it and check for %-constructs within it. */
15614 const unsigned char *this, *lisp_string
;
15616 if (!NILP (props
) || risky
)
15618 Lisp_Object oprops
, aelt
;
15619 oprops
= Ftext_properties_at (make_number (0), elt
);
15621 /* If the starting string's properties are not what
15622 we want, translate the string. Also, if the string
15623 is risky, do that anyway. */
15625 if (NILP (Fequal (props
, oprops
)) || risky
)
15627 /* If the starting string has properties,
15628 merge the specified ones onto the existing ones. */
15629 if (! NILP (oprops
) && !risky
)
15633 oprops
= Fcopy_sequence (oprops
);
15635 while (CONSP (tem
))
15637 oprops
= Fplist_put (oprops
, XCAR (tem
),
15638 XCAR (XCDR (tem
)));
15639 tem
= XCDR (XCDR (tem
));
15644 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15645 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15647 mode_line_proptrans_alist
15648 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15655 elt
= Fcopy_sequence (elt
);
15656 Fset_text_properties (make_number (0), Flength (elt
),
15658 /* Add this item to mode_line_proptrans_alist. */
15659 mode_line_proptrans_alist
15660 = Fcons (Fcons (elt
, props
),
15661 mode_line_proptrans_alist
);
15662 /* Truncate mode_line_proptrans_alist
15663 to at most 50 elements. */
15664 tem
= Fnthcdr (make_number (50),
15665 mode_line_proptrans_alist
);
15667 XSETCDR (tem
, Qnil
);
15672 this = SDATA (elt
);
15673 lisp_string
= this;
15677 prec
= precision
- n
;
15678 if (frame_title_ptr
)
15679 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15680 else if (!NILP (mode_line_string_list
))
15681 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15683 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15684 0, prec
, 0, STRING_MULTIBYTE (elt
));
15689 while ((precision
<= 0 || n
< precision
)
15691 && (frame_title_ptr
15692 || !NILP (mode_line_string_list
)
15693 || it
->current_x
< it
->last_visible_x
))
15695 const unsigned char *last
= this;
15697 /* Advance to end of string or next format specifier. */
15698 while ((c
= *this++) != '\0' && c
!= '%')
15701 if (this - 1 != last
)
15703 int nchars
, nbytes
;
15705 /* Output to end of string or up to '%'. Field width
15706 is length of string. Don't output more than
15707 PRECISION allows us. */
15710 prec
= c_string_width (last
, this - last
, precision
- n
,
15713 if (frame_title_ptr
)
15714 n
+= store_frame_title (last
, 0, prec
);
15715 else if (!NILP (mode_line_string_list
))
15717 int bytepos
= last
- lisp_string
;
15718 int charpos
= string_byte_to_char (elt
, bytepos
);
15719 int endpos
= (precision
<= 0
15720 ? string_byte_to_char (elt
,
15721 this - lisp_string
)
15722 : charpos
+ nchars
);
15724 n
+= store_mode_line_string (NULL
,
15725 Fsubstring (elt
, make_number (charpos
),
15726 make_number (endpos
)),
15731 int bytepos
= last
- lisp_string
;
15732 int charpos
= string_byte_to_char (elt
, bytepos
);
15733 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15735 STRING_MULTIBYTE (elt
));
15738 else /* c == '%' */
15740 const unsigned char *percent_position
= this;
15742 /* Get the specified minimum width. Zero means
15745 while ((c
= *this++) >= '0' && c
<= '9')
15746 field
= field
* 10 + c
- '0';
15748 /* Don't pad beyond the total padding allowed. */
15749 if (field_width
- n
> 0 && field
> field_width
- n
)
15750 field
= field_width
- n
;
15752 /* Note that either PRECISION <= 0 or N < PRECISION. */
15753 prec
= precision
- n
;
15756 n
+= display_mode_element (it
, depth
, field
, prec
,
15757 Vglobal_mode_string
, props
,
15762 int bytepos
, charpos
;
15763 unsigned char *spec
;
15765 bytepos
= percent_position
- lisp_string
;
15766 charpos
= (STRING_MULTIBYTE (elt
)
15767 ? string_byte_to_char (elt
, bytepos
)
15771 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15773 if (frame_title_ptr
)
15774 n
+= store_frame_title (spec
, field
, prec
);
15775 else if (!NILP (mode_line_string_list
))
15777 int len
= strlen (spec
);
15778 Lisp_Object tem
= make_string (spec
, len
);
15779 props
= Ftext_properties_at (make_number (charpos
), elt
);
15780 /* Should only keep face property in props */
15781 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15785 int nglyphs_before
, nwritten
;
15787 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15788 nwritten
= display_string (spec
, Qnil
, elt
,
15793 /* Assign to the glyphs written above the
15794 string where the `%x' came from, position
15798 struct glyph
*glyph
15799 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15803 for (i
= 0; i
< nwritten
; ++i
)
15805 glyph
[i
].object
= elt
;
15806 glyph
[i
].charpos
= charpos
;
15821 /* A symbol: process the value of the symbol recursively
15822 as if it appeared here directly. Avoid error if symbol void.
15823 Special case: if value of symbol is a string, output the string
15826 register Lisp_Object tem
;
15828 /* If the variable is not marked as risky to set
15829 then its contents are risky to use. */
15830 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15833 tem
= Fboundp (elt
);
15836 tem
= Fsymbol_value (elt
);
15837 /* If value is a string, output that string literally:
15838 don't check for % within it. */
15842 if (!EQ (tem
, elt
))
15844 /* Give up right away for nil or t. */
15854 register Lisp_Object car
, tem
;
15856 /* A cons cell: five distinct cases.
15857 If first element is :eval or :propertize, do something special.
15858 If first element is a string or a cons, process all the elements
15859 and effectively concatenate them.
15860 If first element is a negative number, truncate displaying cdr to
15861 at most that many characters. If positive, pad (with spaces)
15862 to at least that many characters.
15863 If first element is a symbol, process the cadr or caddr recursively
15864 according to whether the symbol's value is non-nil or nil. */
15866 if (EQ (car
, QCeval
))
15868 /* An element of the form (:eval FORM) means evaluate FORM
15869 and use the result as mode line elements. */
15874 if (CONSP (XCDR (elt
)))
15877 spec
= safe_eval (XCAR (XCDR (elt
)));
15878 n
+= display_mode_element (it
, depth
, field_width
- n
,
15879 precision
- n
, spec
, props
,
15883 else if (EQ (car
, QCpropertize
))
15885 /* An element of the form (:propertize ELT PROPS...)
15886 means display ELT but applying properties PROPS. */
15891 if (CONSP (XCDR (elt
)))
15892 n
+= display_mode_element (it
, depth
, field_width
- n
,
15893 precision
- n
, XCAR (XCDR (elt
)),
15894 XCDR (XCDR (elt
)), risky
);
15896 else if (SYMBOLP (car
))
15898 tem
= Fboundp (car
);
15902 /* elt is now the cdr, and we know it is a cons cell.
15903 Use its car if CAR has a non-nil value. */
15906 tem
= Fsymbol_value (car
);
15913 /* Symbol's value is nil (or symbol is unbound)
15914 Get the cddr of the original list
15915 and if possible find the caddr and use that. */
15919 else if (!CONSP (elt
))
15924 else if (INTEGERP (car
))
15926 register int lim
= XINT (car
);
15930 /* Negative int means reduce maximum width. */
15931 if (precision
<= 0)
15934 precision
= min (precision
, -lim
);
15938 /* Padding specified. Don't let it be more than
15939 current maximum. */
15941 lim
= min (precision
, lim
);
15943 /* If that's more padding than already wanted, queue it.
15944 But don't reduce padding already specified even if
15945 that is beyond the current truncation point. */
15946 field_width
= max (lim
, field_width
);
15950 else if (STRINGP (car
) || CONSP (car
))
15952 register int limit
= 50;
15953 /* Limit is to protect against circular lists. */
15956 && (precision
<= 0 || n
< precision
))
15958 n
+= display_mode_element (it
, depth
, field_width
- n
,
15959 precision
- n
, XCAR (elt
),
15969 elt
= build_string ("*invalid*");
15973 /* Pad to FIELD_WIDTH. */
15974 if (field_width
> 0 && n
< field_width
)
15976 if (frame_title_ptr
)
15977 n
+= store_frame_title ("", field_width
- n
, 0);
15978 else if (!NILP (mode_line_string_list
))
15979 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15981 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15988 /* Store a mode-line string element in mode_line_string_list.
15990 If STRING is non-null, display that C string. Otherwise, the Lisp
15991 string LISP_STRING is displayed.
15993 FIELD_WIDTH is the minimum number of output glyphs to produce.
15994 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15995 with spaces. FIELD_WIDTH <= 0 means don't pad.
15997 PRECISION is the maximum number of characters to output from
15998 STRING. PRECISION <= 0 means don't truncate the string.
16000 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16001 properties to the string.
16003 PROPS are the properties to add to the string.
16004 The mode_line_string_face face property is always added to the string.
16008 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16010 Lisp_Object lisp_string
;
16019 if (string
!= NULL
)
16021 len
= strlen (string
);
16022 if (precision
> 0 && len
> precision
)
16024 lisp_string
= make_string (string
, len
);
16026 props
= mode_line_string_face_prop
;
16027 else if (!NILP (mode_line_string_face
))
16029 Lisp_Object face
= Fsafe_plist_get (props
, Qface
);
16030 props
= Fcopy_sequence (props
);
16032 face
= mode_line_string_face
;
16034 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16035 props
= Fplist_put (props
, Qface
, face
);
16037 Fadd_text_properties (make_number (0), make_number (len
),
16038 props
, lisp_string
);
16042 len
= XFASTINT (Flength (lisp_string
));
16043 if (precision
> 0 && len
> precision
)
16046 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16049 if (!NILP (mode_line_string_face
))
16053 props
= Ftext_properties_at (make_number (0), lisp_string
);
16054 face
= Fsafe_plist_get (props
, Qface
);
16056 face
= mode_line_string_face
;
16058 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16059 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16061 lisp_string
= Fcopy_sequence (lisp_string
);
16064 Fadd_text_properties (make_number (0), make_number (len
),
16065 props
, lisp_string
);
16070 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16074 if (field_width
> len
)
16076 field_width
-= len
;
16077 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16079 Fadd_text_properties (make_number (0), make_number (field_width
),
16080 props
, lisp_string
);
16081 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16089 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16091 doc
: /* Format a string out of a mode line format specification.
16092 First arg FORMAT specifies the mode line format (see `mode-line-format'
16093 for details) to use.
16095 Optional second arg FACE specifies the face property to put
16096 on all characters for which no face is specified.
16097 t means whatever face the window's mode line currently uses
16098 \(either `mode-line' or `mode-line-inactive', depending).
16099 nil means the default is no face property.
16100 If FACE is an integer, the value string has no text properties.
16102 Optional third and fourth args WINDOW and BUFFER specify the window
16103 and buffer to use as the context for the formatting (defaults
16104 are the selected window and the window's buffer). */)
16105 (format
, face
, window
, buffer
)
16106 Lisp_Object format
, face
, window
, buffer
;
16111 struct buffer
*old_buffer
= NULL
;
16113 int no_props
= INTEGERP (face
);
16116 window
= selected_window
;
16117 CHECK_WINDOW (window
);
16118 w
= XWINDOW (window
);
16121 buffer
= w
->buffer
;
16122 CHECK_BUFFER (buffer
);
16125 return build_string ("");
16133 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16134 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16138 face_id
= DEFAULT_FACE_ID
;
16140 if (XBUFFER (buffer
) != current_buffer
)
16142 old_buffer
= current_buffer
;
16143 set_buffer_internal_1 (XBUFFER (buffer
));
16146 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16150 mode_line_string_face
= face
;
16151 mode_line_string_face_prop
16152 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16154 /* We need a dummy last element in mode_line_string_list to
16155 indicate we are building the propertized mode-line string.
16156 Using mode_line_string_face_prop here GC protects it. */
16157 mode_line_string_list
16158 = Fcons (mode_line_string_face_prop
, Qnil
);
16159 frame_title_ptr
= NULL
;
16163 mode_line_string_face_prop
= Qnil
;
16164 mode_line_string_list
= Qnil
;
16165 frame_title_ptr
= frame_title_buf
;
16168 push_frame_kboard (it
.f
);
16169 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16170 pop_frame_kboard ();
16173 set_buffer_internal_1 (old_buffer
);
16178 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16179 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
16180 make_string ("", 0));
16181 mode_line_string_face_prop
= Qnil
;
16182 mode_line_string_list
= Qnil
;
16186 len
= frame_title_ptr
- frame_title_buf
;
16187 if (len
> 0 && frame_title_ptr
[-1] == '-')
16189 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
16190 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
16192 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
16193 if (len
> frame_title_ptr
- frame_title_buf
)
16194 len
= frame_title_ptr
- frame_title_buf
;
16197 frame_title_ptr
= NULL
;
16198 return make_string (frame_title_buf
, len
);
16201 /* Write a null-terminated, right justified decimal representation of
16202 the positive integer D to BUF using a minimal field width WIDTH. */
16205 pint2str (buf
, width
, d
)
16206 register char *buf
;
16207 register int width
;
16210 register char *p
= buf
;
16218 *p
++ = d
% 10 + '0';
16223 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16234 /* Write a null-terminated, right justified decimal and "human
16235 readable" representation of the nonnegative integer D to BUF using
16236 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16238 static const char power_letter
[] =
16252 pint2hrstr (buf
, width
, d
)
16257 /* We aim to represent the nonnegative integer D as
16258 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16261 /* -1 means: do not use TENTHS. */
16265 /* Length of QUOTIENT.TENTHS as a string. */
16271 if (1000 <= quotient
)
16273 /* Scale to the appropriate EXPONENT. */
16276 remainder
= quotient
% 1000;
16280 while (1000 <= quotient
);
16282 /* Round to nearest and decide whether to use TENTHS or not. */
16285 tenths
= remainder
/ 100;
16286 if (50 <= remainder
% 100)
16293 if (quotient
== 10)
16301 if (500 <= remainder
)
16303 if (quotient
< 999)
16314 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16315 if (tenths
== -1 && quotient
<= 99)
16322 p
= psuffix
= buf
+ max (width
, length
);
16324 /* Print EXPONENT. */
16326 *psuffix
++ = power_letter
[exponent
];
16329 /* Print TENTHS. */
16332 *--p
= '0' + tenths
;
16336 /* Print QUOTIENT. */
16339 int digit
= quotient
% 10;
16340 *--p
= '0' + digit
;
16342 while ((quotient
/= 10) != 0);
16344 /* Print leading spaces. */
16349 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16350 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16351 type of CODING_SYSTEM. Return updated pointer into BUF. */
16353 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16356 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16357 Lisp_Object coding_system
;
16358 register char *buf
;
16362 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16363 const unsigned char *eol_str
;
16365 /* The EOL conversion we are using. */
16366 Lisp_Object eoltype
;
16368 val
= Fget (coding_system
, Qcoding_system
);
16371 if (!VECTORP (val
)) /* Not yet decided. */
16376 eoltype
= eol_mnemonic_undecided
;
16377 /* Don't mention EOL conversion if it isn't decided. */
16381 Lisp_Object eolvalue
;
16383 eolvalue
= Fget (coding_system
, Qeol_type
);
16386 *buf
++ = XFASTINT (AREF (val
, 1));
16390 /* The EOL conversion that is normal on this system. */
16392 if (NILP (eolvalue
)) /* Not yet decided. */
16393 eoltype
= eol_mnemonic_undecided
;
16394 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16395 eoltype
= eol_mnemonic_undecided
;
16396 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16397 eoltype
= (XFASTINT (eolvalue
) == 0
16398 ? eol_mnemonic_unix
16399 : (XFASTINT (eolvalue
) == 1
16400 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16406 /* Mention the EOL conversion if it is not the usual one. */
16407 if (STRINGP (eoltype
))
16409 eol_str
= SDATA (eoltype
);
16410 eol_str_len
= SBYTES (eoltype
);
16412 else if (INTEGERP (eoltype
)
16413 && CHAR_VALID_P (XINT (eoltype
), 0))
16415 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16416 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16421 eol_str
= invalid_eol_type
;
16422 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16424 bcopy (eol_str
, buf
, eol_str_len
);
16425 buf
+= eol_str_len
;
16431 /* Return a string for the output of a mode line %-spec for window W,
16432 generated by character C. PRECISION >= 0 means don't return a
16433 string longer than that value. FIELD_WIDTH > 0 means pad the
16434 string returned with spaces to that value. Return 1 in *MULTIBYTE
16435 if the result is multibyte text.
16437 Note we operate on the current buffer for most purposes,
16438 the exception being w->base_line_pos. */
16440 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16443 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16446 int field_width
, precision
;
16450 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16451 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16452 struct buffer
*b
= current_buffer
;
16460 if (!NILP (b
->read_only
))
16462 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16467 /* This differs from %* only for a modified read-only buffer. */
16468 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16470 if (!NILP (b
->read_only
))
16475 /* This differs from %* in ignoring read-only-ness. */
16476 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16488 if (command_loop_level
> 5)
16490 p
= decode_mode_spec_buf
;
16491 for (i
= 0; i
< command_loop_level
; i
++)
16494 return decode_mode_spec_buf
;
16502 if (command_loop_level
> 5)
16504 p
= decode_mode_spec_buf
;
16505 for (i
= 0; i
< command_loop_level
; i
++)
16508 return decode_mode_spec_buf
;
16515 /* Let lots_of_dashes be a string of infinite length. */
16516 if (!NILP (mode_line_string_list
))
16518 if (field_width
<= 0
16519 || field_width
> sizeof (lots_of_dashes
))
16521 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16522 decode_mode_spec_buf
[i
] = '-';
16523 decode_mode_spec_buf
[i
] = '\0';
16524 return decode_mode_spec_buf
;
16527 return lots_of_dashes
;
16536 int col
= (int) current_column (); /* iftc */
16537 w
->column_number_displayed
= make_number (col
);
16538 pint2str (decode_mode_spec_buf
, field_width
, col
);
16539 return decode_mode_spec_buf
;
16543 /* %F displays the frame name. */
16544 if (!NILP (f
->title
))
16545 return (char *) SDATA (f
->title
);
16546 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16547 return (char *) SDATA (f
->name
);
16556 int size
= ZV
- BEGV
;
16557 pint2str (decode_mode_spec_buf
, field_width
, size
);
16558 return decode_mode_spec_buf
;
16563 int size
= ZV
- BEGV
;
16564 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16565 return decode_mode_spec_buf
;
16570 int startpos
= XMARKER (w
->start
)->charpos
;
16571 int startpos_byte
= marker_byte_position (w
->start
);
16572 int line
, linepos
, linepos_byte
, topline
;
16574 int height
= WINDOW_TOTAL_LINES (w
);
16576 /* If we decided that this buffer isn't suitable for line numbers,
16577 don't forget that too fast. */
16578 if (EQ (w
->base_line_pos
, w
->buffer
))
16580 /* But do forget it, if the window shows a different buffer now. */
16581 else if (BUFFERP (w
->base_line_pos
))
16582 w
->base_line_pos
= Qnil
;
16584 /* If the buffer is very big, don't waste time. */
16585 if (INTEGERP (Vline_number_display_limit
)
16586 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16588 w
->base_line_pos
= Qnil
;
16589 w
->base_line_number
= Qnil
;
16593 if (!NILP (w
->base_line_number
)
16594 && !NILP (w
->base_line_pos
)
16595 && XFASTINT (w
->base_line_pos
) <= startpos
)
16597 line
= XFASTINT (w
->base_line_number
);
16598 linepos
= XFASTINT (w
->base_line_pos
);
16599 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16604 linepos
= BUF_BEGV (b
);
16605 linepos_byte
= BUF_BEGV_BYTE (b
);
16608 /* Count lines from base line to window start position. */
16609 nlines
= display_count_lines (linepos
, linepos_byte
,
16613 topline
= nlines
+ line
;
16615 /* Determine a new base line, if the old one is too close
16616 or too far away, or if we did not have one.
16617 "Too close" means it's plausible a scroll-down would
16618 go back past it. */
16619 if (startpos
== BUF_BEGV (b
))
16621 w
->base_line_number
= make_number (topline
);
16622 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16624 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16625 || linepos
== BUF_BEGV (b
))
16627 int limit
= BUF_BEGV (b
);
16628 int limit_byte
= BUF_BEGV_BYTE (b
);
16630 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16632 if (startpos
- distance
> limit
)
16634 limit
= startpos
- distance
;
16635 limit_byte
= CHAR_TO_BYTE (limit
);
16638 nlines
= display_count_lines (startpos
, startpos_byte
,
16640 - (height
* 2 + 30),
16642 /* If we couldn't find the lines we wanted within
16643 line_number_display_limit_width chars per line,
16644 give up on line numbers for this window. */
16645 if (position
== limit_byte
&& limit
== startpos
- distance
)
16647 w
->base_line_pos
= w
->buffer
;
16648 w
->base_line_number
= Qnil
;
16652 w
->base_line_number
= make_number (topline
- nlines
);
16653 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16656 /* Now count lines from the start pos to point. */
16657 nlines
= display_count_lines (startpos
, startpos_byte
,
16658 PT_BYTE
, PT
, &junk
);
16660 /* Record that we did display the line number. */
16661 line_number_displayed
= 1;
16663 /* Make the string to show. */
16664 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16665 return decode_mode_spec_buf
;
16668 char* p
= decode_mode_spec_buf
;
16669 int pad
= field_width
- 2;
16675 return decode_mode_spec_buf
;
16681 obj
= b
->mode_name
;
16685 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16691 int pos
= marker_position (w
->start
);
16692 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16694 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16696 if (pos
<= BUF_BEGV (b
))
16701 else if (pos
<= BUF_BEGV (b
))
16705 if (total
> 1000000)
16706 /* Do it differently for a large value, to avoid overflow. */
16707 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16709 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16710 /* We can't normally display a 3-digit number,
16711 so get us a 2-digit number that is close. */
16714 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16715 return decode_mode_spec_buf
;
16719 /* Display percentage of size above the bottom of the screen. */
16722 int toppos
= marker_position (w
->start
);
16723 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16724 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16726 if (botpos
>= BUF_ZV (b
))
16728 if (toppos
<= BUF_BEGV (b
))
16735 if (total
> 1000000)
16736 /* Do it differently for a large value, to avoid overflow. */
16737 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16739 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16740 /* We can't normally display a 3-digit number,
16741 so get us a 2-digit number that is close. */
16744 if (toppos
<= BUF_BEGV (b
))
16745 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16747 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16748 return decode_mode_spec_buf
;
16753 /* status of process */
16754 obj
= Fget_buffer_process (Fcurrent_buffer ());
16756 return "no process";
16757 #ifdef subprocesses
16758 obj
= Fsymbol_name (Fprocess_status (obj
));
16762 case 't': /* indicate TEXT or BINARY */
16763 #ifdef MODE_LINE_BINARY_TEXT
16764 return MODE_LINE_BINARY_TEXT (b
);
16770 /* coding-system (not including end-of-line format) */
16772 /* coding-system (including end-of-line type) */
16774 int eol_flag
= (c
== 'Z');
16775 char *p
= decode_mode_spec_buf
;
16777 if (! FRAME_WINDOW_P (f
))
16779 /* No need to mention EOL here--the terminal never needs
16780 to do EOL conversion. */
16781 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16782 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16784 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16787 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16788 #ifdef subprocesses
16789 obj
= Fget_buffer_process (Fcurrent_buffer ());
16790 if (PROCESSP (obj
))
16792 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16794 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16797 #endif /* subprocesses */
16800 return decode_mode_spec_buf
;
16806 *multibyte
= STRING_MULTIBYTE (obj
);
16807 return (char *) SDATA (obj
);
16814 /* Count up to COUNT lines starting from START / START_BYTE.
16815 But don't go beyond LIMIT_BYTE.
16816 Return the number of lines thus found (always nonnegative).
16818 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16821 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16822 int start
, start_byte
, limit_byte
, count
;
16825 register unsigned char *cursor
;
16826 unsigned char *base
;
16828 register int ceiling
;
16829 register unsigned char *ceiling_addr
;
16830 int orig_count
= count
;
16832 /* If we are not in selective display mode,
16833 check only for newlines. */
16834 int selective_display
= (!NILP (current_buffer
->selective_display
)
16835 && !INTEGERP (current_buffer
->selective_display
));
16839 while (start_byte
< limit_byte
)
16841 ceiling
= BUFFER_CEILING_OF (start_byte
);
16842 ceiling
= min (limit_byte
- 1, ceiling
);
16843 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16844 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16847 if (selective_display
)
16848 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16851 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16854 if (cursor
!= ceiling_addr
)
16858 start_byte
+= cursor
- base
+ 1;
16859 *byte_pos_ptr
= start_byte
;
16863 if (++cursor
== ceiling_addr
)
16869 start_byte
+= cursor
- base
;
16874 while (start_byte
> limit_byte
)
16876 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16877 ceiling
= max (limit_byte
, ceiling
);
16878 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16879 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16882 if (selective_display
)
16883 while (--cursor
!= ceiling_addr
16884 && *cursor
!= '\n' && *cursor
!= 015)
16887 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16890 if (cursor
!= ceiling_addr
)
16894 start_byte
+= cursor
- base
+ 1;
16895 *byte_pos_ptr
= start_byte
;
16896 /* When scanning backwards, we should
16897 not count the newline posterior to which we stop. */
16898 return - orig_count
- 1;
16904 /* Here we add 1 to compensate for the last decrement
16905 of CURSOR, which took it past the valid range. */
16906 start_byte
+= cursor
- base
+ 1;
16910 *byte_pos_ptr
= limit_byte
;
16913 return - orig_count
+ count
;
16914 return orig_count
- count
;
16920 /***********************************************************************
16922 ***********************************************************************/
16924 /* Display a NUL-terminated string, starting with index START.
16926 If STRING is non-null, display that C string. Otherwise, the Lisp
16927 string LISP_STRING is displayed.
16929 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16930 FACE_STRING. Display STRING or LISP_STRING with the face at
16931 FACE_STRING_POS in FACE_STRING:
16933 Display the string in the environment given by IT, but use the
16934 standard display table, temporarily.
16936 FIELD_WIDTH is the minimum number of output glyphs to produce.
16937 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16938 with spaces. If STRING has more characters, more than FIELD_WIDTH
16939 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16941 PRECISION is the maximum number of characters to output from
16942 STRING. PRECISION < 0 means don't truncate the string.
16944 This is roughly equivalent to printf format specifiers:
16946 FIELD_WIDTH PRECISION PRINTF
16947 ----------------------------------------
16953 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16954 display them, and < 0 means obey the current buffer's value of
16955 enable_multibyte_characters.
16957 Value is the number of glyphs produced. */
16960 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16961 start
, it
, field_width
, precision
, max_x
, multibyte
)
16962 unsigned char *string
;
16963 Lisp_Object lisp_string
;
16964 Lisp_Object face_string
;
16965 int face_string_pos
;
16968 int field_width
, precision
, max_x
;
16971 int hpos_at_start
= it
->hpos
;
16972 int saved_face_id
= it
->face_id
;
16973 struct glyph_row
*row
= it
->glyph_row
;
16975 /* Initialize the iterator IT for iteration over STRING beginning
16976 with index START. */
16977 reseat_to_string (it
, string
, lisp_string
, start
,
16978 precision
, field_width
, multibyte
);
16980 /* If displaying STRING, set up the face of the iterator
16981 from LISP_STRING, if that's given. */
16982 if (STRINGP (face_string
))
16988 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16989 0, it
->region_beg_charpos
,
16990 it
->region_end_charpos
,
16991 &endptr
, it
->base_face_id
, 0);
16992 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16993 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16996 /* Set max_x to the maximum allowed X position. Don't let it go
16997 beyond the right edge of the window. */
16999 max_x
= it
->last_visible_x
;
17001 max_x
= min (max_x
, it
->last_visible_x
);
17003 /* Skip over display elements that are not visible. because IT->w is
17005 if (it
->current_x
< it
->first_visible_x
)
17006 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17007 MOVE_TO_POS
| MOVE_TO_X
);
17009 row
->ascent
= it
->max_ascent
;
17010 row
->height
= it
->max_ascent
+ it
->max_descent
;
17011 row
->phys_ascent
= it
->max_phys_ascent
;
17012 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17013 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17015 /* This condition is for the case that we are called with current_x
17016 past last_visible_x. */
17017 while (it
->current_x
< max_x
)
17019 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17021 /* Get the next display element. */
17022 if (!get_next_display_element (it
))
17025 /* Produce glyphs. */
17026 x_before
= it
->current_x
;
17027 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17028 PRODUCE_GLYPHS (it
);
17030 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17033 while (i
< nglyphs
)
17035 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17037 if (!it
->truncate_lines_p
17038 && x
+ glyph
->pixel_width
> max_x
)
17040 /* End of continued line or max_x reached. */
17041 if (CHAR_GLYPH_PADDING_P (*glyph
))
17043 /* A wide character is unbreakable. */
17044 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17045 it
->current_x
= x_before
;
17049 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17054 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17056 /* Glyph is at least partially visible. */
17058 if (x
< it
->first_visible_x
)
17059 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17063 /* Glyph is off the left margin of the display area.
17064 Should not happen. */
17068 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17069 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17070 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17071 row
->phys_height
= max (row
->phys_height
,
17072 it
->max_phys_ascent
+ it
->max_phys_descent
);
17073 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17074 it
->max_extra_line_spacing
);
17075 x
+= glyph
->pixel_width
;
17079 /* Stop if max_x reached. */
17083 /* Stop at line ends. */
17084 if (ITERATOR_AT_END_OF_LINE_P (it
))
17086 it
->continuation_lines_width
= 0;
17090 set_iterator_to_next (it
, 1);
17092 /* Stop if truncating at the right edge. */
17093 if (it
->truncate_lines_p
17094 && it
->current_x
>= it
->last_visible_x
)
17096 /* Add truncation mark, but don't do it if the line is
17097 truncated at a padding space. */
17098 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17100 if (!FRAME_WINDOW_P (it
->f
))
17104 if (it
->current_x
> it
->last_visible_x
)
17106 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17107 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17109 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17111 row
->used
[TEXT_AREA
] = i
;
17112 produce_special_glyphs (it
, IT_TRUNCATION
);
17115 produce_special_glyphs (it
, IT_TRUNCATION
);
17117 it
->glyph_row
->truncated_on_right_p
= 1;
17123 /* Maybe insert a truncation at the left. */
17124 if (it
->first_visible_x
17125 && IT_CHARPOS (*it
) > 0)
17127 if (!FRAME_WINDOW_P (it
->f
))
17128 insert_left_trunc_glyphs (it
);
17129 it
->glyph_row
->truncated_on_left_p
= 1;
17132 it
->face_id
= saved_face_id
;
17134 /* Value is number of columns displayed. */
17135 return it
->hpos
- hpos_at_start
;
17140 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17141 appears as an element of LIST or as the car of an element of LIST.
17142 If PROPVAL is a list, compare each element against LIST in that
17143 way, and return 1/2 if any element of PROPVAL is found in LIST.
17144 Otherwise return 0. This function cannot quit.
17145 The return value is 2 if the text is invisible but with an ellipsis
17146 and 1 if it's invisible and without an ellipsis. */
17149 invisible_p (propval
, list
)
17150 register Lisp_Object propval
;
17153 register Lisp_Object tail
, proptail
;
17155 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17157 register Lisp_Object tem
;
17159 if (EQ (propval
, tem
))
17161 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17162 return NILP (XCDR (tem
)) ? 1 : 2;
17165 if (CONSP (propval
))
17167 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17169 Lisp_Object propelt
;
17170 propelt
= XCAR (proptail
);
17171 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17173 register Lisp_Object tem
;
17175 if (EQ (propelt
, tem
))
17177 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17178 return NILP (XCDR (tem
)) ? 1 : 2;
17186 /* Calculate a width or height in pixels from a specification using
17187 the following elements:
17190 NUM - a (fractional) multiple of the default font width/height
17191 (NUM) - specifies exactly NUM pixels
17192 UNIT - a fixed number of pixels, see below.
17193 ELEMENT - size of a display element in pixels, see below.
17194 (NUM . SPEC) - equals NUM * SPEC
17195 (+ SPEC SPEC ...) - add pixel values
17196 (- SPEC SPEC ...) - subtract pixel values
17197 (- SPEC) - negate pixel value
17200 INT or FLOAT - a number constant
17201 SYMBOL - use symbol's (buffer local) variable binding.
17204 in - pixels per inch *)
17205 mm - pixels per 1/1000 meter *)
17206 cm - pixels per 1/100 meter *)
17207 width - width of current font in pixels.
17208 height - height of current font in pixels.
17210 *) using the ratio(s) defined in display-pixels-per-inch.
17214 left-fringe - left fringe width in pixels
17215 right-fringe - right fringe width in pixels
17217 left-margin - left margin width in pixels
17218 right-margin - right margin width in pixels
17220 scroll-bar - scroll-bar area width in pixels
17224 Pixels corresponding to 5 inches:
17227 Total width of non-text areas on left side of window (if scroll-bar is on left):
17228 '(space :width (+ left-fringe left-margin scroll-bar))
17230 Align to first text column (in header line):
17231 '(space :align-to 0)
17233 Align to middle of text area minus half the width of variable `my-image'
17234 containing a loaded image:
17235 '(space :align-to (0.5 . (- text my-image)))
17237 Width of left margin minus width of 1 character in the default font:
17238 '(space :width (- left-margin 1))
17240 Width of left margin minus width of 2 characters in the current font:
17241 '(space :width (- left-margin (2 . width)))
17243 Center 1 character over left-margin (in header line):
17244 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17246 Different ways to express width of left fringe plus left margin minus one pixel:
17247 '(space :width (- (+ left-fringe left-margin) (1)))
17248 '(space :width (+ left-fringe left-margin (- (1))))
17249 '(space :width (+ left-fringe left-margin (-1)))
17253 #define NUMVAL(X) \
17254 ((INTEGERP (X) || FLOATP (X)) \
17259 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17264 int width_p
, *align_to
;
17268 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17269 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17272 return OK_PIXELS (0);
17274 if (SYMBOLP (prop
))
17276 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17278 char *unit
= SDATA (SYMBOL_NAME (prop
));
17280 if (unit
[0] == 'i' && unit
[1] == 'n')
17282 else if (unit
[0] == 'm' && unit
[1] == 'm')
17284 else if (unit
[0] == 'c' && unit
[1] == 'm')
17291 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17292 || (CONSP (Vdisplay_pixels_per_inch
)
17294 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17295 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17297 return OK_PIXELS (ppi
/ pixels
);
17303 #ifdef HAVE_WINDOW_SYSTEM
17304 if (EQ (prop
, Qheight
))
17305 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17306 if (EQ (prop
, Qwidth
))
17307 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17309 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17310 return OK_PIXELS (1);
17313 if (EQ (prop
, Qtext
))
17314 return OK_PIXELS (width_p
17315 ? window_box_width (it
->w
, TEXT_AREA
)
17316 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17318 if (align_to
&& *align_to
< 0)
17321 if (EQ (prop
, Qleft
))
17322 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17323 if (EQ (prop
, Qright
))
17324 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17325 if (EQ (prop
, Qcenter
))
17326 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17327 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17328 if (EQ (prop
, Qleft_fringe
))
17329 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17330 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17331 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17332 if (EQ (prop
, Qright_fringe
))
17333 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17334 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17335 : window_box_right_offset (it
->w
, TEXT_AREA
));
17336 if (EQ (prop
, Qleft_margin
))
17337 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17338 if (EQ (prop
, Qright_margin
))
17339 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17340 if (EQ (prop
, Qscroll_bar
))
17341 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17343 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17344 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17345 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17350 if (EQ (prop
, Qleft_fringe
))
17351 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17352 if (EQ (prop
, Qright_fringe
))
17353 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17354 if (EQ (prop
, Qleft_margin
))
17355 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17356 if (EQ (prop
, Qright_margin
))
17357 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17358 if (EQ (prop
, Qscroll_bar
))
17359 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17362 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17365 if (INTEGERP (prop
) || FLOATP (prop
))
17367 int base_unit
= (width_p
17368 ? FRAME_COLUMN_WIDTH (it
->f
)
17369 : FRAME_LINE_HEIGHT (it
->f
));
17370 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17375 Lisp_Object car
= XCAR (prop
);
17376 Lisp_Object cdr
= XCDR (prop
);
17380 #ifdef HAVE_WINDOW_SYSTEM
17381 if (valid_image_p (prop
))
17383 int id
= lookup_image (it
->f
, prop
);
17384 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17386 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17389 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17395 while (CONSP (cdr
))
17397 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17398 font
, width_p
, align_to
))
17401 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17406 if (EQ (car
, Qminus
))
17408 return OK_PIXELS (pixels
);
17411 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17414 if (INTEGERP (car
) || FLOATP (car
))
17417 pixels
= XFLOATINT (car
);
17419 return OK_PIXELS (pixels
);
17420 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17421 font
, width_p
, align_to
))
17422 return OK_PIXELS (pixels
* fact
);
17433 /***********************************************************************
17435 ***********************************************************************/
17437 #ifdef HAVE_WINDOW_SYSTEM
17442 dump_glyph_string (s
)
17443 struct glyph_string
*s
;
17445 fprintf (stderr
, "glyph string\n");
17446 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17447 s
->x
, s
->y
, s
->width
, s
->height
);
17448 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17449 fprintf (stderr
, " hl = %d\n", s
->hl
);
17450 fprintf (stderr
, " left overhang = %d, right = %d\n",
17451 s
->left_overhang
, s
->right_overhang
);
17452 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17453 fprintf (stderr
, " extends to end of line = %d\n",
17454 s
->extends_to_end_of_line_p
);
17455 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17456 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17459 #endif /* GLYPH_DEBUG */
17461 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17462 of XChar2b structures for S; it can't be allocated in
17463 init_glyph_string because it must be allocated via `alloca'. W
17464 is the window on which S is drawn. ROW and AREA are the glyph row
17465 and area within the row from which S is constructed. START is the
17466 index of the first glyph structure covered by S. HL is a
17467 face-override for drawing S. */
17470 #define OPTIONAL_HDC(hdc) hdc,
17471 #define DECLARE_HDC(hdc) HDC hdc;
17472 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17473 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17476 #ifndef OPTIONAL_HDC
17477 #define OPTIONAL_HDC(hdc)
17478 #define DECLARE_HDC(hdc)
17479 #define ALLOCATE_HDC(hdc, f)
17480 #define RELEASE_HDC(hdc, f)
17484 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17485 struct glyph_string
*s
;
17489 struct glyph_row
*row
;
17490 enum glyph_row_area area
;
17492 enum draw_glyphs_face hl
;
17494 bzero (s
, sizeof *s
);
17496 s
->f
= XFRAME (w
->frame
);
17500 s
->display
= FRAME_X_DISPLAY (s
->f
);
17501 s
->window
= FRAME_X_WINDOW (s
->f
);
17502 s
->char2b
= char2b
;
17506 s
->first_glyph
= row
->glyphs
[area
] + start
;
17507 s
->height
= row
->height
;
17508 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17510 /* Display the internal border below the tool-bar window. */
17511 if (WINDOWP (s
->f
->tool_bar_window
)
17512 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17513 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17515 s
->ybase
= s
->y
+ row
->ascent
;
17519 /* Append the list of glyph strings with head H and tail T to the list
17520 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17523 append_glyph_string_lists (head
, tail
, h
, t
)
17524 struct glyph_string
**head
, **tail
;
17525 struct glyph_string
*h
, *t
;
17539 /* Prepend the list of glyph strings with head H and tail T to the
17540 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17544 prepend_glyph_string_lists (head
, tail
, h
, t
)
17545 struct glyph_string
**head
, **tail
;
17546 struct glyph_string
*h
, *t
;
17560 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17561 Set *HEAD and *TAIL to the resulting list. */
17564 append_glyph_string (head
, tail
, s
)
17565 struct glyph_string
**head
, **tail
;
17566 struct glyph_string
*s
;
17568 s
->next
= s
->prev
= NULL
;
17569 append_glyph_string_lists (head
, tail
, s
, s
);
17573 /* Get face and two-byte form of character glyph GLYPH on frame F.
17574 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17575 a pointer to a realized face that is ready for display. */
17577 static INLINE
struct face
*
17578 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17580 struct glyph
*glyph
;
17586 xassert (glyph
->type
== CHAR_GLYPH
);
17587 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17592 if (!glyph
->multibyte_p
)
17594 /* Unibyte case. We don't have to encode, but we have to make
17595 sure to use a face suitable for unibyte. */
17596 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17598 else if (glyph
->u
.ch
< 128
17599 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17601 /* Case of ASCII in a face known to fit ASCII. */
17602 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17606 int c1
, c2
, charset
;
17608 /* Split characters into bytes. If c2 is -1 afterwards, C is
17609 really a one-byte character so that byte1 is zero. */
17610 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17612 STORE_XCHAR2B (char2b
, c1
, c2
);
17614 STORE_XCHAR2B (char2b
, 0, c1
);
17616 /* Maybe encode the character in *CHAR2B. */
17617 if (charset
!= CHARSET_ASCII
)
17619 struct font_info
*font_info
17620 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17623 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17627 /* Make sure X resources of the face are allocated. */
17628 xassert (face
!= NULL
);
17629 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17634 /* Fill glyph string S with composition components specified by S->cmp.
17636 FACES is an array of faces for all components of this composition.
17637 S->gidx is the index of the first component for S.
17638 OVERLAPS_P non-zero means S should draw the foreground only, and
17639 use its physical height for clipping.
17641 Value is the index of a component not in S. */
17644 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17645 struct glyph_string
*s
;
17646 struct face
**faces
;
17653 s
->for_overlaps_p
= overlaps_p
;
17655 s
->face
= faces
[s
->gidx
];
17656 s
->font
= s
->face
->font
;
17657 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17659 /* For all glyphs of this composition, starting at the offset
17660 S->gidx, until we reach the end of the definition or encounter a
17661 glyph that requires the different face, add it to S. */
17663 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17666 /* All glyph strings for the same composition has the same width,
17667 i.e. the width set for the first component of the composition. */
17669 s
->width
= s
->first_glyph
->pixel_width
;
17671 /* If the specified font could not be loaded, use the frame's
17672 default font, but record the fact that we couldn't load it in
17673 the glyph string so that we can draw rectangles for the
17674 characters of the glyph string. */
17675 if (s
->font
== NULL
)
17677 s
->font_not_found_p
= 1;
17678 s
->font
= FRAME_FONT (s
->f
);
17681 /* Adjust base line for subscript/superscript text. */
17682 s
->ybase
+= s
->first_glyph
->voffset
;
17684 xassert (s
->face
&& s
->face
->gc
);
17686 /* This glyph string must always be drawn with 16-bit functions. */
17689 return s
->gidx
+ s
->nchars
;
17693 /* Fill glyph string S from a sequence of character glyphs.
17695 FACE_ID is the face id of the string. START is the index of the
17696 first glyph to consider, END is the index of the last + 1.
17697 OVERLAPS_P non-zero means S should draw the foreground only, and
17698 use its physical height for clipping.
17700 Value is the index of the first glyph not in S. */
17703 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17704 struct glyph_string
*s
;
17706 int start
, end
, overlaps_p
;
17708 struct glyph
*glyph
, *last
;
17710 int glyph_not_available_p
;
17712 xassert (s
->f
== XFRAME (s
->w
->frame
));
17713 xassert (s
->nchars
== 0);
17714 xassert (start
>= 0 && end
> start
);
17716 s
->for_overlaps_p
= overlaps_p
,
17717 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17718 last
= s
->row
->glyphs
[s
->area
] + end
;
17719 voffset
= glyph
->voffset
;
17721 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17723 while (glyph
< last
17724 && glyph
->type
== CHAR_GLYPH
17725 && glyph
->voffset
== voffset
17726 /* Same face id implies same font, nowadays. */
17727 && glyph
->face_id
== face_id
17728 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17732 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17733 s
->char2b
+ s
->nchars
,
17735 s
->two_byte_p
= two_byte_p
;
17737 xassert (s
->nchars
<= end
- start
);
17738 s
->width
+= glyph
->pixel_width
;
17742 s
->font
= s
->face
->font
;
17743 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17745 /* If the specified font could not be loaded, use the frame's font,
17746 but record the fact that we couldn't load it in
17747 S->font_not_found_p so that we can draw rectangles for the
17748 characters of the glyph string. */
17749 if (s
->font
== NULL
|| glyph_not_available_p
)
17751 s
->font_not_found_p
= 1;
17752 s
->font
= FRAME_FONT (s
->f
);
17755 /* Adjust base line for subscript/superscript text. */
17756 s
->ybase
+= voffset
;
17758 xassert (s
->face
&& s
->face
->gc
);
17759 return glyph
- s
->row
->glyphs
[s
->area
];
17763 /* Fill glyph string S from image glyph S->first_glyph. */
17766 fill_image_glyph_string (s
)
17767 struct glyph_string
*s
;
17769 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17770 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17772 s
->slice
= s
->first_glyph
->slice
;
17773 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17774 s
->font
= s
->face
->font
;
17775 s
->width
= s
->first_glyph
->pixel_width
;
17777 /* Adjust base line for subscript/superscript text. */
17778 s
->ybase
+= s
->first_glyph
->voffset
;
17782 /* Fill glyph string S from a sequence of stretch glyphs.
17784 ROW is the glyph row in which the glyphs are found, AREA is the
17785 area within the row. START is the index of the first glyph to
17786 consider, END is the index of the last + 1.
17788 Value is the index of the first glyph not in S. */
17791 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17792 struct glyph_string
*s
;
17793 struct glyph_row
*row
;
17794 enum glyph_row_area area
;
17797 struct glyph
*glyph
, *last
;
17798 int voffset
, face_id
;
17800 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17802 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17803 last
= s
->row
->glyphs
[s
->area
] + end
;
17804 face_id
= glyph
->face_id
;
17805 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17806 s
->font
= s
->face
->font
;
17807 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17808 s
->width
= glyph
->pixel_width
;
17809 voffset
= glyph
->voffset
;
17813 && glyph
->type
== STRETCH_GLYPH
17814 && glyph
->voffset
== voffset
17815 && glyph
->face_id
== face_id
);
17817 s
->width
+= glyph
->pixel_width
;
17819 /* Adjust base line for subscript/superscript text. */
17820 s
->ybase
+= voffset
;
17822 /* The case that face->gc == 0 is handled when drawing the glyph
17823 string by calling PREPARE_FACE_FOR_DISPLAY. */
17825 return glyph
- s
->row
->glyphs
[s
->area
];
17830 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17831 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17832 assumed to be zero. */
17835 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17836 struct glyph
*glyph
;
17840 *left
= *right
= 0;
17842 if (glyph
->type
== CHAR_GLYPH
)
17846 struct font_info
*font_info
;
17850 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17852 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17853 if (font
/* ++KFS: Should this be font_info ? */
17854 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17856 if (pcm
->rbearing
> pcm
->width
)
17857 *right
= pcm
->rbearing
- pcm
->width
;
17858 if (pcm
->lbearing
< 0)
17859 *left
= -pcm
->lbearing
;
17865 /* Return the index of the first glyph preceding glyph string S that
17866 is overwritten by S because of S's left overhang. Value is -1
17867 if no glyphs are overwritten. */
17870 left_overwritten (s
)
17871 struct glyph_string
*s
;
17875 if (s
->left_overhang
)
17878 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17879 int first
= s
->first_glyph
- glyphs
;
17881 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17882 x
-= glyphs
[i
].pixel_width
;
17893 /* Return the index of the first glyph preceding glyph string S that
17894 is overwriting S because of its right overhang. Value is -1 if no
17895 glyph in front of S overwrites S. */
17898 left_overwriting (s
)
17899 struct glyph_string
*s
;
17902 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17903 int first
= s
->first_glyph
- glyphs
;
17907 for (i
= first
- 1; i
>= 0; --i
)
17910 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17913 x
-= glyphs
[i
].pixel_width
;
17920 /* Return the index of the last glyph following glyph string S that is
17921 not overwritten by S because of S's right overhang. Value is -1 if
17922 no such glyph is found. */
17925 right_overwritten (s
)
17926 struct glyph_string
*s
;
17930 if (s
->right_overhang
)
17933 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17934 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17935 int end
= s
->row
->used
[s
->area
];
17937 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17938 x
+= glyphs
[i
].pixel_width
;
17947 /* Return the index of the last glyph following glyph string S that
17948 overwrites S because of its left overhang. Value is negative
17949 if no such glyph is found. */
17952 right_overwriting (s
)
17953 struct glyph_string
*s
;
17956 int end
= s
->row
->used
[s
->area
];
17957 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17958 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17962 for (i
= first
; i
< end
; ++i
)
17965 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17968 x
+= glyphs
[i
].pixel_width
;
17975 /* Get face and two-byte form of character C in face FACE_ID on frame
17976 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17977 means we want to display multibyte text. DISPLAY_P non-zero means
17978 make sure that X resources for the face returned are allocated.
17979 Value is a pointer to a realized face that is ready for display if
17980 DISPLAY_P is non-zero. */
17982 static INLINE
struct face
*
17983 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17987 int multibyte_p
, display_p
;
17989 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17993 /* Unibyte case. We don't have to encode, but we have to make
17994 sure to use a face suitable for unibyte. */
17995 STORE_XCHAR2B (char2b
, 0, c
);
17996 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17997 face
= FACE_FROM_ID (f
, face_id
);
17999 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18001 /* Case of ASCII in a face known to fit ASCII. */
18002 STORE_XCHAR2B (char2b
, 0, c
);
18006 int c1
, c2
, charset
;
18008 /* Split characters into bytes. If c2 is -1 afterwards, C is
18009 really a one-byte character so that byte1 is zero. */
18010 SPLIT_CHAR (c
, charset
, c1
, c2
);
18012 STORE_XCHAR2B (char2b
, c1
, c2
);
18014 STORE_XCHAR2B (char2b
, 0, c1
);
18016 /* Maybe encode the character in *CHAR2B. */
18017 if (face
->font
!= NULL
)
18019 struct font_info
*font_info
18020 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18022 rif
->encode_char (c
, char2b
, font_info
, 0);
18026 /* Make sure X resources of the face are allocated. */
18027 #ifdef HAVE_X_WINDOWS
18031 xassert (face
!= NULL
);
18032 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18039 /* Set background width of glyph string S. START is the index of the
18040 first glyph following S. LAST_X is the right-most x-position + 1
18041 in the drawing area. */
18044 set_glyph_string_background_width (s
, start
, last_x
)
18045 struct glyph_string
*s
;
18049 /* If the face of this glyph string has to be drawn to the end of
18050 the drawing area, set S->extends_to_end_of_line_p. */
18051 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18053 if (start
== s
->row
->used
[s
->area
]
18054 && s
->area
== TEXT_AREA
18055 && ((s
->hl
== DRAW_NORMAL_TEXT
18056 && (s
->row
->fill_line_p
18057 || s
->face
->background
!= default_face
->background
18058 || s
->face
->stipple
!= default_face
->stipple
18059 || s
->row
->mouse_face_p
))
18060 || s
->hl
== DRAW_MOUSE_FACE
18061 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18062 && s
->row
->fill_line_p
)))
18063 s
->extends_to_end_of_line_p
= 1;
18065 /* If S extends its face to the end of the line, set its
18066 background_width to the distance to the right edge of the drawing
18068 if (s
->extends_to_end_of_line_p
)
18069 s
->background_width
= last_x
- s
->x
+ 1;
18071 s
->background_width
= s
->width
;
18075 /* Compute overhangs and x-positions for glyph string S and its
18076 predecessors, or successors. X is the starting x-position for S.
18077 BACKWARD_P non-zero means process predecessors. */
18080 compute_overhangs_and_x (s
, x
, backward_p
)
18081 struct glyph_string
*s
;
18089 if (rif
->compute_glyph_string_overhangs
)
18090 rif
->compute_glyph_string_overhangs (s
);
18100 if (rif
->compute_glyph_string_overhangs
)
18101 rif
->compute_glyph_string_overhangs (s
);
18111 /* The following macros are only called from draw_glyphs below.
18112 They reference the following parameters of that function directly:
18113 `w', `row', `area', and `overlap_p'
18114 as well as the following local variables:
18115 `s', `f', and `hdc' (in W32) */
18118 /* On W32, silently add local `hdc' variable to argument list of
18119 init_glyph_string. */
18120 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18121 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18123 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18124 init_glyph_string (s, char2b, w, row, area, start, hl)
18127 /* Add a glyph string for a stretch glyph to the list of strings
18128 between HEAD and TAIL. START is the index of the stretch glyph in
18129 row area AREA of glyph row ROW. END is the index of the last glyph
18130 in that glyph row area. X is the current output position assigned
18131 to the new glyph string constructed. HL overrides that face of the
18132 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18133 is the right-most x-position of the drawing area. */
18135 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18136 and below -- keep them on one line. */
18137 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18140 s = (struct glyph_string *) alloca (sizeof *s); \
18141 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18142 START = fill_stretch_glyph_string (s, row, area, START, END); \
18143 append_glyph_string (&HEAD, &TAIL, s); \
18149 /* Add a glyph string for an image glyph to the list of strings
18150 between HEAD and TAIL. START is the index of the image glyph in
18151 row area AREA of glyph row ROW. END is the index of the last glyph
18152 in that glyph row area. X is the current output position assigned
18153 to the new glyph string constructed. HL overrides that face of the
18154 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18155 is the right-most x-position of the drawing area. */
18157 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18160 s = (struct glyph_string *) alloca (sizeof *s); \
18161 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18162 fill_image_glyph_string (s); \
18163 append_glyph_string (&HEAD, &TAIL, s); \
18170 /* Add a glyph string for a sequence of character glyphs to the list
18171 of strings between HEAD and TAIL. START is the index of the first
18172 glyph in row area AREA of glyph row ROW that is part of the new
18173 glyph string. END is the index of the last glyph in that glyph row
18174 area. X is the current output position assigned to the new glyph
18175 string constructed. HL overrides that face of the glyph; e.g. it
18176 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18177 right-most x-position of the drawing area. */
18179 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18185 c = (row)->glyphs[area][START].u.ch; \
18186 face_id = (row)->glyphs[area][START].face_id; \
18188 s = (struct glyph_string *) alloca (sizeof *s); \
18189 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18190 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18191 append_glyph_string (&HEAD, &TAIL, s); \
18193 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18198 /* Add a glyph string for a composite sequence to the list of strings
18199 between HEAD and TAIL. START is the index of the first glyph in
18200 row area AREA of glyph row ROW that is part of the new glyph
18201 string. END is the index of the last glyph in that glyph row area.
18202 X is the current output position assigned to the new glyph string
18203 constructed. HL overrides that face of the glyph; e.g. it is
18204 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18205 x-position of the drawing area. */
18207 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18209 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18210 int face_id = (row)->glyphs[area][START].face_id; \
18211 struct face *base_face = FACE_FROM_ID (f, face_id); \
18212 struct composition *cmp = composition_table[cmp_id]; \
18213 int glyph_len = cmp->glyph_len; \
18215 struct face **faces; \
18216 struct glyph_string *first_s = NULL; \
18219 base_face = base_face->ascii_face; \
18220 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18221 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18222 /* At first, fill in `char2b' and `faces'. */ \
18223 for (n = 0; n < glyph_len; n++) \
18225 int c = COMPOSITION_GLYPH (cmp, n); \
18226 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18227 faces[n] = FACE_FROM_ID (f, this_face_id); \
18228 get_char_face_and_encoding (f, c, this_face_id, \
18229 char2b + n, 1, 1); \
18232 /* Make glyph_strings for each glyph sequence that is drawable by \
18233 the same face, and append them to HEAD/TAIL. */ \
18234 for (n = 0; n < cmp->glyph_len;) \
18236 s = (struct glyph_string *) alloca (sizeof *s); \
18237 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18238 append_glyph_string (&(HEAD), &(TAIL), s); \
18246 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18254 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18255 of AREA of glyph row ROW on window W between indices START and END.
18256 HL overrides the face for drawing glyph strings, e.g. it is
18257 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18258 x-positions of the drawing area.
18260 This is an ugly monster macro construct because we must use alloca
18261 to allocate glyph strings (because draw_glyphs can be called
18262 asynchronously). */
18264 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18267 HEAD = TAIL = NULL; \
18268 while (START < END) \
18270 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18271 switch (first_glyph->type) \
18274 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18278 case COMPOSITE_GLYPH: \
18279 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18283 case STRETCH_GLYPH: \
18284 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18288 case IMAGE_GLYPH: \
18289 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18297 set_glyph_string_background_width (s, START, LAST_X); \
18304 /* Draw glyphs between START and END in AREA of ROW on window W,
18305 starting at x-position X. X is relative to AREA in W. HL is a
18306 face-override with the following meaning:
18308 DRAW_NORMAL_TEXT draw normally
18309 DRAW_CURSOR draw in cursor face
18310 DRAW_MOUSE_FACE draw in mouse face.
18311 DRAW_INVERSE_VIDEO draw in mode line face
18312 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18313 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18315 If OVERLAPS_P is non-zero, draw only the foreground of characters
18316 and clip to the physical height of ROW.
18318 Value is the x-position reached, relative to AREA of W. */
18321 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18324 struct glyph_row
*row
;
18325 enum glyph_row_area area
;
18327 enum draw_glyphs_face hl
;
18330 struct glyph_string
*head
, *tail
;
18331 struct glyph_string
*s
;
18332 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18333 int last_x
, area_width
;
18336 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18339 ALLOCATE_HDC (hdc
, f
);
18341 /* Let's rather be paranoid than getting a SEGV. */
18342 end
= min (end
, row
->used
[area
]);
18343 start
= max (0, start
);
18344 start
= min (end
, start
);
18346 /* Translate X to frame coordinates. Set last_x to the right
18347 end of the drawing area. */
18348 if (row
->full_width_p
)
18350 /* X is relative to the left edge of W, without scroll bars
18352 x
+= WINDOW_LEFT_EDGE_X (w
);
18353 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18357 int area_left
= window_box_left (w
, area
);
18359 area_width
= window_box_width (w
, area
);
18360 last_x
= area_left
+ area_width
;
18363 /* Build a doubly-linked list of glyph_string structures between
18364 head and tail from what we have to draw. Note that the macro
18365 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18366 the reason we use a separate variable `i'. */
18368 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18370 x_reached
= tail
->x
+ tail
->background_width
;
18374 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18375 the row, redraw some glyphs in front or following the glyph
18376 strings built above. */
18377 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18380 struct glyph_string
*h
, *t
;
18382 /* Compute overhangs for all glyph strings. */
18383 if (rif
->compute_glyph_string_overhangs
)
18384 for (s
= head
; s
; s
= s
->next
)
18385 rif
->compute_glyph_string_overhangs (s
);
18387 /* Prepend glyph strings for glyphs in front of the first glyph
18388 string that are overwritten because of the first glyph
18389 string's left overhang. The background of all strings
18390 prepended must be drawn because the first glyph string
18392 i
= left_overwritten (head
);
18396 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18397 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18399 compute_overhangs_and_x (t
, head
->x
, 1);
18400 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18404 /* Prepend glyph strings for glyphs in front of the first glyph
18405 string that overwrite that glyph string because of their
18406 right overhang. For these strings, only the foreground must
18407 be drawn, because it draws over the glyph string at `head'.
18408 The background must not be drawn because this would overwrite
18409 right overhangs of preceding glyphs for which no glyph
18411 i
= left_overwriting (head
);
18415 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18416 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18417 for (s
= h
; s
; s
= s
->next
)
18418 s
->background_filled_p
= 1;
18419 compute_overhangs_and_x (t
, head
->x
, 1);
18420 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18423 /* Append glyphs strings for glyphs following the last glyph
18424 string tail that are overwritten by tail. The background of
18425 these strings has to be drawn because tail's foreground draws
18427 i
= right_overwritten (tail
);
18430 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18431 DRAW_NORMAL_TEXT
, x
, last_x
);
18432 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18433 append_glyph_string_lists (&head
, &tail
, h
, t
);
18437 /* Append glyph strings for glyphs following the last glyph
18438 string tail that overwrite tail. The foreground of such
18439 glyphs has to be drawn because it writes into the background
18440 of tail. The background must not be drawn because it could
18441 paint over the foreground of following glyphs. */
18442 i
= right_overwriting (tail
);
18446 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18447 DRAW_NORMAL_TEXT
, x
, last_x
);
18448 for (s
= h
; s
; s
= s
->next
)
18449 s
->background_filled_p
= 1;
18450 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18451 append_glyph_string_lists (&head
, &tail
, h
, t
);
18453 if (clip_head
|| clip_tail
)
18454 for (s
= head
; s
; s
= s
->next
)
18456 s
->clip_head
= clip_head
;
18457 s
->clip_tail
= clip_tail
;
18461 /* Draw all strings. */
18462 for (s
= head
; s
; s
= s
->next
)
18463 rif
->draw_glyph_string (s
);
18465 if (area
== TEXT_AREA
18466 && !row
->full_width_p
18467 /* When drawing overlapping rows, only the glyph strings'
18468 foreground is drawn, which doesn't erase a cursor
18472 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18473 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18474 : (tail
? tail
->x
+ tail
->background_width
: x
));
18476 int text_left
= window_box_left (w
, TEXT_AREA
);
18480 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18481 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18484 /* Value is the x-position up to which drawn, relative to AREA of W.
18485 This doesn't include parts drawn because of overhangs. */
18486 if (row
->full_width_p
)
18487 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18489 x_reached
-= window_box_left (w
, area
);
18491 RELEASE_HDC (hdc
, f
);
18496 /* Expand row matrix if too narrow. Don't expand if area
18499 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18501 if (!fonts_changed_p \
18502 && (it->glyph_row->glyphs[area] \
18503 < it->glyph_row->glyphs[area + 1])) \
18505 it->w->ncols_scale_factor++; \
18506 fonts_changed_p = 1; \
18510 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18511 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18517 struct glyph
*glyph
;
18518 enum glyph_row_area area
= it
->area
;
18520 xassert (it
->glyph_row
);
18521 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18523 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18524 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18526 glyph
->charpos
= CHARPOS (it
->position
);
18527 glyph
->object
= it
->object
;
18528 glyph
->pixel_width
= it
->pixel_width
;
18529 glyph
->ascent
= it
->ascent
;
18530 glyph
->descent
= it
->descent
;
18531 glyph
->voffset
= it
->voffset
;
18532 glyph
->type
= CHAR_GLYPH
;
18533 glyph
->multibyte_p
= it
->multibyte_p
;
18534 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18535 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18536 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18537 || it
->phys_descent
> it
->descent
);
18538 glyph
->padding_p
= 0;
18539 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18540 glyph
->face_id
= it
->face_id
;
18541 glyph
->u
.ch
= it
->char_to_display
;
18542 glyph
->slice
= null_glyph_slice
;
18543 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18544 ++it
->glyph_row
->used
[area
];
18547 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18550 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18551 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18554 append_composite_glyph (it
)
18557 struct glyph
*glyph
;
18558 enum glyph_row_area area
= it
->area
;
18560 xassert (it
->glyph_row
);
18562 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18563 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18565 glyph
->charpos
= CHARPOS (it
->position
);
18566 glyph
->object
= it
->object
;
18567 glyph
->pixel_width
= it
->pixel_width
;
18568 glyph
->ascent
= it
->ascent
;
18569 glyph
->descent
= it
->descent
;
18570 glyph
->voffset
= it
->voffset
;
18571 glyph
->type
= COMPOSITE_GLYPH
;
18572 glyph
->multibyte_p
= it
->multibyte_p
;
18573 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18574 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18575 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18576 || it
->phys_descent
> it
->descent
);
18577 glyph
->padding_p
= 0;
18578 glyph
->glyph_not_available_p
= 0;
18579 glyph
->face_id
= it
->face_id
;
18580 glyph
->u
.cmp_id
= it
->cmp_id
;
18581 glyph
->slice
= null_glyph_slice
;
18582 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18583 ++it
->glyph_row
->used
[area
];
18586 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18590 /* Change IT->ascent and IT->height according to the setting of
18594 take_vertical_position_into_account (it
)
18599 if (it
->voffset
< 0)
18600 /* Increase the ascent so that we can display the text higher
18602 it
->ascent
-= it
->voffset
;
18604 /* Increase the descent so that we can display the text lower
18606 it
->descent
+= it
->voffset
;
18611 /* Produce glyphs/get display metrics for the image IT is loaded with.
18612 See the description of struct display_iterator in dispextern.h for
18613 an overview of struct display_iterator. */
18616 produce_image_glyph (it
)
18622 struct glyph_slice slice
;
18624 xassert (it
->what
== IT_IMAGE
);
18626 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18628 /* Make sure X resources of the face is loaded. */
18629 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18631 if (it
->image_id
< 0)
18633 /* Fringe bitmap. */
18634 it
->ascent
= it
->phys_ascent
= 0;
18635 it
->descent
= it
->phys_descent
= 0;
18636 it
->pixel_width
= 0;
18641 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18643 /* Make sure X resources of the image is loaded. */
18644 prepare_image_for_display (it
->f
, img
);
18646 slice
.x
= slice
.y
= 0;
18647 slice
.width
= img
->width
;
18648 slice
.height
= img
->height
;
18650 if (INTEGERP (it
->slice
.x
))
18651 slice
.x
= XINT (it
->slice
.x
);
18652 else if (FLOATP (it
->slice
.x
))
18653 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18655 if (INTEGERP (it
->slice
.y
))
18656 slice
.y
= XINT (it
->slice
.y
);
18657 else if (FLOATP (it
->slice
.y
))
18658 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18660 if (INTEGERP (it
->slice
.width
))
18661 slice
.width
= XINT (it
->slice
.width
);
18662 else if (FLOATP (it
->slice
.width
))
18663 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18665 if (INTEGERP (it
->slice
.height
))
18666 slice
.height
= XINT (it
->slice
.height
);
18667 else if (FLOATP (it
->slice
.height
))
18668 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18670 if (slice
.x
>= img
->width
)
18671 slice
.x
= img
->width
;
18672 if (slice
.y
>= img
->height
)
18673 slice
.y
= img
->height
;
18674 if (slice
.x
+ slice
.width
>= img
->width
)
18675 slice
.width
= img
->width
- slice
.x
;
18676 if (slice
.y
+ slice
.height
> img
->height
)
18677 slice
.height
= img
->height
- slice
.y
;
18679 if (slice
.width
== 0 || slice
.height
== 0)
18682 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18684 it
->descent
= slice
.height
- glyph_ascent
;
18686 it
->descent
+= img
->vmargin
;
18687 if (slice
.y
+ slice
.height
== img
->height
)
18688 it
->descent
+= img
->vmargin
;
18689 it
->phys_descent
= it
->descent
;
18691 it
->pixel_width
= slice
.width
;
18693 it
->pixel_width
+= img
->hmargin
;
18694 if (slice
.x
+ slice
.width
== img
->width
)
18695 it
->pixel_width
+= img
->hmargin
;
18697 /* It's quite possible for images to have an ascent greater than
18698 their height, so don't get confused in that case. */
18699 if (it
->descent
< 0)
18702 #if 0 /* this breaks image tiling */
18703 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18704 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18705 if (face_ascent
> it
->ascent
)
18706 it
->ascent
= it
->phys_ascent
= face_ascent
;
18711 if (face
->box
!= FACE_NO_BOX
)
18713 if (face
->box_line_width
> 0)
18716 it
->ascent
+= face
->box_line_width
;
18717 if (slice
.y
+ slice
.height
== img
->height
)
18718 it
->descent
+= face
->box_line_width
;
18721 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18722 it
->pixel_width
+= abs (face
->box_line_width
);
18723 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18724 it
->pixel_width
+= abs (face
->box_line_width
);
18727 take_vertical_position_into_account (it
);
18731 struct glyph
*glyph
;
18732 enum glyph_row_area area
= it
->area
;
18734 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18735 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18737 glyph
->charpos
= CHARPOS (it
->position
);
18738 glyph
->object
= it
->object
;
18739 glyph
->pixel_width
= it
->pixel_width
;
18740 glyph
->ascent
= glyph_ascent
;
18741 glyph
->descent
= it
->descent
;
18742 glyph
->voffset
= it
->voffset
;
18743 glyph
->type
= IMAGE_GLYPH
;
18744 glyph
->multibyte_p
= it
->multibyte_p
;
18745 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18746 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18747 glyph
->overlaps_vertically_p
= 0;
18748 glyph
->padding_p
= 0;
18749 glyph
->glyph_not_available_p
= 0;
18750 glyph
->face_id
= it
->face_id
;
18751 glyph
->u
.img_id
= img
->id
;
18752 glyph
->slice
= slice
;
18753 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18754 ++it
->glyph_row
->used
[area
];
18757 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18762 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18763 of the glyph, WIDTH and HEIGHT are the width and height of the
18764 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18767 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18769 Lisp_Object object
;
18773 struct glyph
*glyph
;
18774 enum glyph_row_area area
= it
->area
;
18776 xassert (ascent
>= 0 && ascent
<= height
);
18778 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18779 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18781 glyph
->charpos
= CHARPOS (it
->position
);
18782 glyph
->object
= object
;
18783 glyph
->pixel_width
= width
;
18784 glyph
->ascent
= ascent
;
18785 glyph
->descent
= height
- ascent
;
18786 glyph
->voffset
= it
->voffset
;
18787 glyph
->type
= STRETCH_GLYPH
;
18788 glyph
->multibyte_p
= it
->multibyte_p
;
18789 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18790 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18791 glyph
->overlaps_vertically_p
= 0;
18792 glyph
->padding_p
= 0;
18793 glyph
->glyph_not_available_p
= 0;
18794 glyph
->face_id
= it
->face_id
;
18795 glyph
->u
.stretch
.ascent
= ascent
;
18796 glyph
->u
.stretch
.height
= height
;
18797 glyph
->slice
= null_glyph_slice
;
18798 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18799 ++it
->glyph_row
->used
[area
];
18802 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18806 /* Produce a stretch glyph for iterator IT. IT->object is the value
18807 of the glyph property displayed. The value must be a list
18808 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18811 1. `:width WIDTH' specifies that the space should be WIDTH *
18812 canonical char width wide. WIDTH may be an integer or floating
18815 2. `:relative-width FACTOR' specifies that the width of the stretch
18816 should be computed from the width of the first character having the
18817 `glyph' property, and should be FACTOR times that width.
18819 3. `:align-to HPOS' specifies that the space should be wide enough
18820 to reach HPOS, a value in canonical character units.
18822 Exactly one of the above pairs must be present.
18824 4. `:height HEIGHT' specifies that the height of the stretch produced
18825 should be HEIGHT, measured in canonical character units.
18827 5. `:relative-height FACTOR' specifies that the height of the
18828 stretch should be FACTOR times the height of the characters having
18829 the glyph property.
18831 Either none or exactly one of 4 or 5 must be present.
18833 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18834 of the stretch should be used for the ascent of the stretch.
18835 ASCENT must be in the range 0 <= ASCENT <= 100. */
18838 produce_stretch_glyph (it
)
18841 /* (space :width WIDTH :height HEIGHT ...) */
18842 Lisp_Object prop
, plist
;
18843 int width
= 0, height
= 0, align_to
= -1;
18844 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18847 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18848 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18850 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18852 /* List should start with `space'. */
18853 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18854 plist
= XCDR (it
->object
);
18856 /* Compute the width of the stretch. */
18857 if ((prop
= Fsafe_plist_get (plist
, QCwidth
), !NILP (prop
))
18858 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18860 /* Absolute width `:width WIDTH' specified and valid. */
18861 zero_width_ok_p
= 1;
18864 else if (prop
= Fsafe_plist_get (plist
, QCrelative_width
),
18867 /* Relative width `:relative-width FACTOR' specified and valid.
18868 Compute the width of the characters having the `glyph'
18871 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18874 if (it
->multibyte_p
)
18876 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18877 - IT_BYTEPOS (*it
));
18878 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18881 it2
.c
= *p
, it2
.len
= 1;
18883 it2
.glyph_row
= NULL
;
18884 it2
.what
= IT_CHARACTER
;
18885 x_produce_glyphs (&it2
);
18886 width
= NUMVAL (prop
) * it2
.pixel_width
;
18888 else if ((prop
= Fsafe_plist_get (plist
, QCalign_to
), !NILP (prop
))
18889 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18891 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18892 align_to
= (align_to
< 0
18894 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18895 else if (align_to
< 0)
18896 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18897 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18898 zero_width_ok_p
= 1;
18901 /* Nothing specified -> width defaults to canonical char width. */
18902 width
= FRAME_COLUMN_WIDTH (it
->f
);
18904 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18907 /* Compute height. */
18908 if ((prop
= Fsafe_plist_get (plist
, QCheight
), !NILP (prop
))
18909 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18912 zero_height_ok_p
= 1;
18914 else if (prop
= Fsafe_plist_get (plist
, QCrelative_height
),
18916 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18918 height
= FONT_HEIGHT (font
);
18920 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18923 /* Compute percentage of height used for ascent. If
18924 `:ascent ASCENT' is present and valid, use that. Otherwise,
18925 derive the ascent from the font in use. */
18926 if (prop
= Fsafe_plist_get (plist
, QCascent
),
18927 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18928 ascent
= height
* NUMVAL (prop
) / 100.0;
18929 else if (!NILP (prop
)
18930 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18931 ascent
= min (max (0, (int)tem
), height
);
18933 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18935 if (width
> 0 && height
> 0 && it
->glyph_row
)
18937 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18938 if (!STRINGP (object
))
18939 object
= it
->w
->buffer
;
18940 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18943 it
->pixel_width
= width
;
18944 it
->ascent
= it
->phys_ascent
= ascent
;
18945 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18946 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18948 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18950 if (face
->box_line_width
> 0)
18952 it
->ascent
+= face
->box_line_width
;
18953 it
->descent
+= face
->box_line_width
;
18956 if (it
->start_of_box_run_p
)
18957 it
->pixel_width
+= abs (face
->box_line_width
);
18958 if (it
->end_of_box_run_p
)
18959 it
->pixel_width
+= abs (face
->box_line_width
);
18962 take_vertical_position_into_account (it
);
18965 /* Get line-height and line-spacing property at point.
18966 If line-height has format (HEIGHT TOTAL), return TOTAL
18967 in TOTAL_HEIGHT. */
18970 get_line_height_property (it
, prop
)
18974 Lisp_Object position
, val
;
18976 if (STRINGP (it
->object
))
18977 position
= make_number (IT_STRING_CHARPOS (*it
));
18978 else if (BUFFERP (it
->object
))
18979 position
= make_number (IT_CHARPOS (*it
));
18983 return Fget_char_property (position
, prop
, it
->object
);
18986 /* Calculate line-height and line-spacing properties.
18987 An integer value specifies explicit pixel value.
18988 A float value specifies relative value to current face height.
18989 A cons (float . face-name) specifies relative value to
18990 height of specified face font.
18992 Returns height in pixels, or nil. */
18996 calc_line_height_property (it
, val
, font
, boff
, override
)
19000 int boff
, override
;
19002 Lisp_Object face_name
= Qnil
;
19003 int ascent
, descent
, height
;
19005 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19010 face_name
= XCAR (val
);
19012 if (!NUMBERP (val
))
19013 val
= make_number (1);
19014 if (NILP (face_name
))
19016 height
= it
->ascent
+ it
->descent
;
19021 if (NILP (face_name
))
19023 font
= FRAME_FONT (it
->f
);
19024 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19026 else if (EQ (face_name
, Qt
))
19034 struct font_info
*font_info
;
19036 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19038 return make_number (-1);
19040 face
= FACE_FROM_ID (it
->f
, face_id
);
19043 return make_number (-1);
19045 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19046 boff
= font_info
->baseline_offset
;
19047 if (font_info
->vertical_centering
)
19048 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19051 ascent
= FONT_BASE (font
) + boff
;
19052 descent
= FONT_DESCENT (font
) - boff
;
19056 it
->override_ascent
= ascent
;
19057 it
->override_descent
= descent
;
19058 it
->override_boff
= boff
;
19061 height
= ascent
+ descent
;
19065 height
= (int)(XFLOAT_DATA (val
) * height
);
19066 else if (INTEGERP (val
))
19067 height
*= XINT (val
);
19069 return make_number (height
);
19074 Produce glyphs/get display metrics for the display element IT is
19075 loaded with. See the description of struct display_iterator in
19076 dispextern.h for an overview of struct display_iterator. */
19079 x_produce_glyphs (it
)
19082 int extra_line_spacing
= it
->extra_line_spacing
;
19084 it
->glyph_not_available_p
= 0;
19086 if (it
->what
== IT_CHARACTER
)
19090 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19092 int font_not_found_p
;
19093 struct font_info
*font_info
;
19094 int boff
; /* baseline offset */
19095 /* We may change it->multibyte_p upon unibyte<->multibyte
19096 conversion. So, save the current value now and restore it
19099 Note: It seems that we don't have to record multibyte_p in
19100 struct glyph because the character code itself tells if or
19101 not the character is multibyte. Thus, in the future, we must
19102 consider eliminating the field `multibyte_p' in the struct
19104 int saved_multibyte_p
= it
->multibyte_p
;
19106 /* Maybe translate single-byte characters to multibyte, or the
19108 it
->char_to_display
= it
->c
;
19109 if (!ASCII_BYTE_P (it
->c
))
19111 if (unibyte_display_via_language_environment
19112 && SINGLE_BYTE_CHAR_P (it
->c
)
19114 || !NILP (Vnonascii_translation_table
)))
19116 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19117 it
->multibyte_p
= 1;
19118 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19119 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19121 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19122 && !it
->multibyte_p
)
19124 it
->multibyte_p
= 1;
19125 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19126 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19130 /* Get font to use. Encode IT->char_to_display. */
19131 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19132 &char2b
, it
->multibyte_p
, 0);
19135 /* When no suitable font found, use the default font. */
19136 font_not_found_p
= font
== NULL
;
19137 if (font_not_found_p
)
19139 font
= FRAME_FONT (it
->f
);
19140 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19145 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19146 boff
= font_info
->baseline_offset
;
19147 if (font_info
->vertical_centering
)
19148 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19151 if (it
->char_to_display
>= ' '
19152 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19154 /* Either unibyte or ASCII. */
19159 pcm
= rif
->per_char_metric (font
, &char2b
,
19160 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19162 if (it
->override_ascent
>= 0)
19164 it
->ascent
= it
->override_ascent
;
19165 it
->descent
= it
->override_descent
;
19166 boff
= it
->override_boff
;
19170 it
->ascent
= FONT_BASE (font
) + boff
;
19171 it
->descent
= FONT_DESCENT (font
) - boff
;
19176 it
->phys_ascent
= pcm
->ascent
+ boff
;
19177 it
->phys_descent
= pcm
->descent
- boff
;
19178 it
->pixel_width
= pcm
->width
;
19182 it
->glyph_not_available_p
= 1;
19183 it
->phys_ascent
= it
->ascent
;
19184 it
->phys_descent
= it
->descent
;
19185 it
->pixel_width
= FONT_WIDTH (font
);
19188 if (it
->constrain_row_ascent_descent_p
)
19190 if (it
->descent
> it
->max_descent
)
19192 it
->ascent
+= it
->descent
- it
->max_descent
;
19193 it
->descent
= it
->max_descent
;
19195 if (it
->ascent
> it
->max_ascent
)
19197 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19198 it
->ascent
= it
->max_ascent
;
19200 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19201 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19202 extra_line_spacing
= 0;
19205 /* If this is a space inside a region of text with
19206 `space-width' property, change its width. */
19207 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19209 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19211 /* If face has a box, add the box thickness to the character
19212 height. If character has a box line to the left and/or
19213 right, add the box line width to the character's width. */
19214 if (face
->box
!= FACE_NO_BOX
)
19216 int thick
= face
->box_line_width
;
19220 it
->ascent
+= thick
;
19221 it
->descent
+= thick
;
19226 if (it
->start_of_box_run_p
)
19227 it
->pixel_width
+= thick
;
19228 if (it
->end_of_box_run_p
)
19229 it
->pixel_width
+= thick
;
19232 /* If face has an overline, add the height of the overline
19233 (1 pixel) and a 1 pixel margin to the character height. */
19234 if (face
->overline_p
)
19237 if (it
->constrain_row_ascent_descent_p
)
19239 if (it
->ascent
> it
->max_ascent
)
19240 it
->ascent
= it
->max_ascent
;
19241 if (it
->descent
> it
->max_descent
)
19242 it
->descent
= it
->max_descent
;
19245 take_vertical_position_into_account (it
);
19247 /* If we have to actually produce glyphs, do it. */
19252 /* Translate a space with a `space-width' property
19253 into a stretch glyph. */
19254 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19255 / FONT_HEIGHT (font
));
19256 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19257 it
->ascent
+ it
->descent
, ascent
);
19262 /* If characters with lbearing or rbearing are displayed
19263 in this line, record that fact in a flag of the
19264 glyph row. This is used to optimize X output code. */
19265 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19266 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19269 else if (it
->char_to_display
== '\n')
19271 /* A newline has no width but we need the height of the line.
19272 But if previous part of the line set a height, don't
19273 increase that height */
19275 Lisp_Object height
;
19276 Lisp_Object total_height
= Qnil
;
19278 it
->override_ascent
= -1;
19279 it
->pixel_width
= 0;
19282 height
= get_line_height_property(it
, Qline_height
);
19283 /* Split (line-height total-height) list */
19285 && CONSP (XCDR (height
))
19286 && NILP (XCDR (XCDR (height
))))
19288 total_height
= XCAR (XCDR (height
));
19289 height
= XCAR (height
);
19291 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19293 if (it
->override_ascent
>= 0)
19295 it
->ascent
= it
->override_ascent
;
19296 it
->descent
= it
->override_descent
;
19297 boff
= it
->override_boff
;
19301 it
->ascent
= FONT_BASE (font
) + boff
;
19302 it
->descent
= FONT_DESCENT (font
) - boff
;
19305 if (EQ (height
, Qt
))
19307 if (it
->descent
> it
->max_descent
)
19309 it
->ascent
+= it
->descent
- it
->max_descent
;
19310 it
->descent
= it
->max_descent
;
19312 if (it
->ascent
> it
->max_ascent
)
19314 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19315 it
->ascent
= it
->max_ascent
;
19317 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19318 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19319 it
->constrain_row_ascent_descent_p
= 1;
19320 extra_line_spacing
= 0;
19324 Lisp_Object spacing
;
19327 it
->phys_ascent
= it
->ascent
;
19328 it
->phys_descent
= it
->descent
;
19330 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19331 && face
->box
!= FACE_NO_BOX
19332 && face
->box_line_width
> 0)
19334 it
->ascent
+= face
->box_line_width
;
19335 it
->descent
+= face
->box_line_width
;
19338 && XINT (height
) > it
->ascent
+ it
->descent
)
19339 it
->ascent
= XINT (height
) - it
->descent
;
19341 if (!NILP (total_height
))
19342 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19345 spacing
= get_line_height_property(it
, Qline_spacing
);
19346 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19348 if (INTEGERP (spacing
))
19350 extra_line_spacing
= XINT (spacing
);
19351 if (!NILP (total_height
))
19352 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19356 else if (it
->char_to_display
== '\t')
19358 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19359 int x
= it
->current_x
+ it
->continuation_lines_width
;
19360 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19362 /* If the distance from the current position to the next tab
19363 stop is less than a space character width, use the
19364 tab stop after that. */
19365 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19366 next_tab_x
+= tab_width
;
19368 it
->pixel_width
= next_tab_x
- x
;
19370 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19371 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19375 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19376 it
->ascent
+ it
->descent
, it
->ascent
);
19381 /* A multi-byte character. Assume that the display width of the
19382 character is the width of the character multiplied by the
19383 width of the font. */
19385 /* If we found a font, this font should give us the right
19386 metrics. If we didn't find a font, use the frame's
19387 default font and calculate the width of the character
19388 from the charset width; this is what old redisplay code
19391 pcm
= rif
->per_char_metric (font
, &char2b
,
19392 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19394 if (font_not_found_p
|| !pcm
)
19396 int charset
= CHAR_CHARSET (it
->char_to_display
);
19398 it
->glyph_not_available_p
= 1;
19399 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19400 * CHARSET_WIDTH (charset
));
19401 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19402 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19406 it
->pixel_width
= pcm
->width
;
19407 it
->phys_ascent
= pcm
->ascent
+ boff
;
19408 it
->phys_descent
= pcm
->descent
- boff
;
19410 && (pcm
->lbearing
< 0
19411 || pcm
->rbearing
> pcm
->width
))
19412 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19415 it
->ascent
= FONT_BASE (font
) + boff
;
19416 it
->descent
= FONT_DESCENT (font
) - boff
;
19417 if (face
->box
!= FACE_NO_BOX
)
19419 int thick
= face
->box_line_width
;
19423 it
->ascent
+= thick
;
19424 it
->descent
+= thick
;
19429 if (it
->start_of_box_run_p
)
19430 it
->pixel_width
+= thick
;
19431 if (it
->end_of_box_run_p
)
19432 it
->pixel_width
+= thick
;
19435 /* If face has an overline, add the height of the overline
19436 (1 pixel) and a 1 pixel margin to the character height. */
19437 if (face
->overline_p
)
19440 take_vertical_position_into_account (it
);
19445 it
->multibyte_p
= saved_multibyte_p
;
19447 else if (it
->what
== IT_COMPOSITION
)
19449 /* Note: A composition is represented as one glyph in the
19450 glyph matrix. There are no padding glyphs. */
19453 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19455 int font_not_found_p
;
19456 struct font_info
*font_info
;
19457 int boff
; /* baseline offset */
19458 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19460 /* Maybe translate single-byte characters to multibyte. */
19461 it
->char_to_display
= it
->c
;
19462 if (unibyte_display_via_language_environment
19463 && SINGLE_BYTE_CHAR_P (it
->c
)
19466 && !NILP (Vnonascii_translation_table
))))
19468 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19471 /* Get face and font to use. Encode IT->char_to_display. */
19472 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19473 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19474 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19475 &char2b
, it
->multibyte_p
, 0);
19478 /* When no suitable font found, use the default font. */
19479 font_not_found_p
= font
== NULL
;
19480 if (font_not_found_p
)
19482 font
= FRAME_FONT (it
->f
);
19483 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19488 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19489 boff
= font_info
->baseline_offset
;
19490 if (font_info
->vertical_centering
)
19491 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19494 /* There are no padding glyphs, so there is only one glyph to
19495 produce for the composition. Important is that pixel_width,
19496 ascent and descent are the values of what is drawn by
19497 draw_glyphs (i.e. the values of the overall glyphs composed). */
19500 /* If we have not yet calculated pixel size data of glyphs of
19501 the composition for the current face font, calculate them
19502 now. Theoretically, we have to check all fonts for the
19503 glyphs, but that requires much time and memory space. So,
19504 here we check only the font of the first glyph. This leads
19505 to incorrect display very rarely, and C-l (recenter) can
19506 correct the display anyway. */
19507 if (cmp
->font
!= (void *) font
)
19509 /* Ascent and descent of the font of the first character of
19510 this composition (adjusted by baseline offset). Ascent
19511 and descent of overall glyphs should not be less than
19512 them respectively. */
19513 int font_ascent
= FONT_BASE (font
) + boff
;
19514 int font_descent
= FONT_DESCENT (font
) - boff
;
19515 /* Bounding box of the overall glyphs. */
19516 int leftmost
, rightmost
, lowest
, highest
;
19517 int i
, width
, ascent
, descent
;
19519 cmp
->font
= (void *) font
;
19521 /* Initialize the bounding box. */
19523 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19524 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19526 width
= pcm
->width
;
19527 ascent
= pcm
->ascent
;
19528 descent
= pcm
->descent
;
19532 width
= FONT_WIDTH (font
);
19533 ascent
= FONT_BASE (font
);
19534 descent
= FONT_DESCENT (font
);
19538 lowest
= - descent
+ boff
;
19539 highest
= ascent
+ boff
;
19543 && font_info
->default_ascent
19544 && CHAR_TABLE_P (Vuse_default_ascent
)
19545 && !NILP (Faref (Vuse_default_ascent
,
19546 make_number (it
->char_to_display
))))
19547 highest
= font_info
->default_ascent
+ boff
;
19549 /* Draw the first glyph at the normal position. It may be
19550 shifted to right later if some other glyphs are drawn at
19552 cmp
->offsets
[0] = 0;
19553 cmp
->offsets
[1] = boff
;
19555 /* Set cmp->offsets for the remaining glyphs. */
19556 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19558 int left
, right
, btm
, top
;
19559 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19560 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19562 face
= FACE_FROM_ID (it
->f
, face_id
);
19563 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19564 &char2b
, it
->multibyte_p
, 0);
19568 font
= FRAME_FONT (it
->f
);
19569 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19575 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19576 boff
= font_info
->baseline_offset
;
19577 if (font_info
->vertical_centering
)
19578 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19582 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19583 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19585 width
= pcm
->width
;
19586 ascent
= pcm
->ascent
;
19587 descent
= pcm
->descent
;
19591 width
= FONT_WIDTH (font
);
19596 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19598 /* Relative composition with or without
19599 alternate chars. */
19600 left
= (leftmost
+ rightmost
- width
) / 2;
19601 btm
= - descent
+ boff
;
19602 if (font_info
&& font_info
->relative_compose
19603 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19604 || NILP (Faref (Vignore_relative_composition
,
19605 make_number (ch
)))))
19608 if (- descent
>= font_info
->relative_compose
)
19609 /* One extra pixel between two glyphs. */
19611 else if (ascent
<= 0)
19612 /* One extra pixel between two glyphs. */
19613 btm
= lowest
- 1 - ascent
- descent
;
19618 /* A composition rule is specified by an integer
19619 value that encodes global and new reference
19620 points (GREF and NREF). GREF and NREF are
19621 specified by numbers as below:
19623 0---1---2 -- ascent
19627 9--10--11 -- center
19629 ---3---4---5--- baseline
19631 6---7---8 -- descent
19633 int rule
= COMPOSITION_RULE (cmp
, i
);
19634 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19636 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19637 grefx
= gref
% 3, nrefx
= nref
% 3;
19638 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19641 + grefx
* (rightmost
- leftmost
) / 2
19642 - nrefx
* width
/ 2);
19643 btm
= ((grefy
== 0 ? highest
19645 : grefy
== 2 ? lowest
19646 : (highest
+ lowest
) / 2)
19647 - (nrefy
== 0 ? ascent
+ descent
19648 : nrefy
== 1 ? descent
- boff
19650 : (ascent
+ descent
) / 2));
19653 cmp
->offsets
[i
* 2] = left
;
19654 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19656 /* Update the bounding box of the overall glyphs. */
19657 right
= left
+ width
;
19658 top
= btm
+ descent
+ ascent
;
19659 if (left
< leftmost
)
19661 if (right
> rightmost
)
19669 /* If there are glyphs whose x-offsets are negative,
19670 shift all glyphs to the right and make all x-offsets
19674 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19675 cmp
->offsets
[i
* 2] -= leftmost
;
19676 rightmost
-= leftmost
;
19679 cmp
->pixel_width
= rightmost
;
19680 cmp
->ascent
= highest
;
19681 cmp
->descent
= - lowest
;
19682 if (cmp
->ascent
< font_ascent
)
19683 cmp
->ascent
= font_ascent
;
19684 if (cmp
->descent
< font_descent
)
19685 cmp
->descent
= font_descent
;
19688 it
->pixel_width
= cmp
->pixel_width
;
19689 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19690 it
->descent
= it
->phys_descent
= cmp
->descent
;
19692 if (face
->box
!= FACE_NO_BOX
)
19694 int thick
= face
->box_line_width
;
19698 it
->ascent
+= thick
;
19699 it
->descent
+= thick
;
19704 if (it
->start_of_box_run_p
)
19705 it
->pixel_width
+= thick
;
19706 if (it
->end_of_box_run_p
)
19707 it
->pixel_width
+= thick
;
19710 /* If face has an overline, add the height of the overline
19711 (1 pixel) and a 1 pixel margin to the character height. */
19712 if (face
->overline_p
)
19715 take_vertical_position_into_account (it
);
19718 append_composite_glyph (it
);
19720 else if (it
->what
== IT_IMAGE
)
19721 produce_image_glyph (it
);
19722 else if (it
->what
== IT_STRETCH
)
19723 produce_stretch_glyph (it
);
19725 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19726 because this isn't true for images with `:ascent 100'. */
19727 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19728 if (it
->area
== TEXT_AREA
)
19729 it
->current_x
+= it
->pixel_width
;
19731 if (extra_line_spacing
> 0)
19733 it
->descent
+= extra_line_spacing
;
19734 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19735 it
->max_extra_line_spacing
= extra_line_spacing
;
19738 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19739 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19740 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19741 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19745 Output LEN glyphs starting at START at the nominal cursor position.
19746 Advance the nominal cursor over the text. The global variable
19747 updated_window contains the window being updated, updated_row is
19748 the glyph row being updated, and updated_area is the area of that
19749 row being updated. */
19752 x_write_glyphs (start
, len
)
19753 struct glyph
*start
;
19758 xassert (updated_window
&& updated_row
);
19761 /* Write glyphs. */
19763 hpos
= start
- updated_row
->glyphs
[updated_area
];
19764 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19765 updated_row
, updated_area
,
19767 DRAW_NORMAL_TEXT
, 0);
19769 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19770 if (updated_area
== TEXT_AREA
19771 && updated_window
->phys_cursor_on_p
19772 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19773 && updated_window
->phys_cursor
.hpos
>= hpos
19774 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19775 updated_window
->phys_cursor_on_p
= 0;
19779 /* Advance the output cursor. */
19780 output_cursor
.hpos
+= len
;
19781 output_cursor
.x
= x
;
19786 Insert LEN glyphs from START at the nominal cursor position. */
19789 x_insert_glyphs (start
, len
)
19790 struct glyph
*start
;
19795 int line_height
, shift_by_width
, shifted_region_width
;
19796 struct glyph_row
*row
;
19797 struct glyph
*glyph
;
19798 int frame_x
, frame_y
, hpos
;
19800 xassert (updated_window
&& updated_row
);
19802 w
= updated_window
;
19803 f
= XFRAME (WINDOW_FRAME (w
));
19805 /* Get the height of the line we are in. */
19807 line_height
= row
->height
;
19809 /* Get the width of the glyphs to insert. */
19810 shift_by_width
= 0;
19811 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19812 shift_by_width
+= glyph
->pixel_width
;
19814 /* Get the width of the region to shift right. */
19815 shifted_region_width
= (window_box_width (w
, updated_area
)
19820 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19821 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19823 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19824 line_height
, shift_by_width
);
19826 /* Write the glyphs. */
19827 hpos
= start
- row
->glyphs
[updated_area
];
19828 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19830 DRAW_NORMAL_TEXT
, 0);
19832 /* Advance the output cursor. */
19833 output_cursor
.hpos
+= len
;
19834 output_cursor
.x
+= shift_by_width
;
19840 Erase the current text line from the nominal cursor position
19841 (inclusive) to pixel column TO_X (exclusive). The idea is that
19842 everything from TO_X onward is already erased.
19844 TO_X is a pixel position relative to updated_area of
19845 updated_window. TO_X == -1 means clear to the end of this area. */
19848 x_clear_end_of_line (to_x
)
19852 struct window
*w
= updated_window
;
19853 int max_x
, min_y
, max_y
;
19854 int from_x
, from_y
, to_y
;
19856 xassert (updated_window
&& updated_row
);
19857 f
= XFRAME (w
->frame
);
19859 if (updated_row
->full_width_p
)
19860 max_x
= WINDOW_TOTAL_WIDTH (w
);
19862 max_x
= window_box_width (w
, updated_area
);
19863 max_y
= window_text_bottom_y (w
);
19865 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19866 of window. For TO_X > 0, truncate to end of drawing area. */
19872 to_x
= min (to_x
, max_x
);
19874 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19876 /* Notice if the cursor will be cleared by this operation. */
19877 if (!updated_row
->full_width_p
)
19878 notice_overwritten_cursor (w
, updated_area
,
19879 output_cursor
.x
, -1,
19881 MATRIX_ROW_BOTTOM_Y (updated_row
));
19883 from_x
= output_cursor
.x
;
19885 /* Translate to frame coordinates. */
19886 if (updated_row
->full_width_p
)
19888 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19889 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19893 int area_left
= window_box_left (w
, updated_area
);
19894 from_x
+= area_left
;
19898 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19899 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19900 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19902 /* Prevent inadvertently clearing to end of the X window. */
19903 if (to_x
> from_x
&& to_y
> from_y
)
19906 rif
->clear_frame_area (f
, from_x
, from_y
,
19907 to_x
- from_x
, to_y
- from_y
);
19912 #endif /* HAVE_WINDOW_SYSTEM */
19916 /***********************************************************************
19918 ***********************************************************************/
19920 /* Value is the internal representation of the specified cursor type
19921 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19922 of the bar cursor. */
19924 static enum text_cursor_kinds
19925 get_specified_cursor_type (arg
, width
)
19929 enum text_cursor_kinds type
;
19934 if (EQ (arg
, Qbox
))
19935 return FILLED_BOX_CURSOR
;
19937 if (EQ (arg
, Qhollow
))
19938 return HOLLOW_BOX_CURSOR
;
19940 if (EQ (arg
, Qbar
))
19947 && EQ (XCAR (arg
), Qbar
)
19948 && INTEGERP (XCDR (arg
))
19949 && XINT (XCDR (arg
)) >= 0)
19951 *width
= XINT (XCDR (arg
));
19955 if (EQ (arg
, Qhbar
))
19958 return HBAR_CURSOR
;
19962 && EQ (XCAR (arg
), Qhbar
)
19963 && INTEGERP (XCDR (arg
))
19964 && XINT (XCDR (arg
)) >= 0)
19966 *width
= XINT (XCDR (arg
));
19967 return HBAR_CURSOR
;
19970 /* Treat anything unknown as "hollow box cursor".
19971 It was bad to signal an error; people have trouble fixing
19972 .Xdefaults with Emacs, when it has something bad in it. */
19973 type
= HOLLOW_BOX_CURSOR
;
19978 /* Set the default cursor types for specified frame. */
19980 set_frame_cursor_types (f
, arg
)
19987 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19988 FRAME_CURSOR_WIDTH (f
) = width
;
19990 /* By default, set up the blink-off state depending on the on-state. */
19992 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19995 FRAME_BLINK_OFF_CURSOR (f
)
19996 = get_specified_cursor_type (XCDR (tem
), &width
);
19997 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20000 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20004 /* Return the cursor we want to be displayed in window W. Return
20005 width of bar/hbar cursor through WIDTH arg. Return with
20006 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20007 (i.e. if the `system caret' should track this cursor).
20009 In a mini-buffer window, we want the cursor only to appear if we
20010 are reading input from this window. For the selected window, we
20011 want the cursor type given by the frame parameter or buffer local
20012 setting of cursor-type. If explicitly marked off, draw no cursor.
20013 In all other cases, we want a hollow box cursor. */
20015 static enum text_cursor_kinds
20016 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20018 struct glyph
*glyph
;
20020 int *active_cursor
;
20022 struct frame
*f
= XFRAME (w
->frame
);
20023 struct buffer
*b
= XBUFFER (w
->buffer
);
20024 int cursor_type
= DEFAULT_CURSOR
;
20025 Lisp_Object alt_cursor
;
20026 int non_selected
= 0;
20028 *active_cursor
= 1;
20031 if (cursor_in_echo_area
20032 && FRAME_HAS_MINIBUF_P (f
)
20033 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20035 if (w
== XWINDOW (echo_area_window
))
20037 *width
= FRAME_CURSOR_WIDTH (f
);
20038 return FRAME_DESIRED_CURSOR (f
);
20041 *active_cursor
= 0;
20045 /* Nonselected window or nonselected frame. */
20046 else if (w
!= XWINDOW (f
->selected_window
)
20047 #ifdef HAVE_WINDOW_SYSTEM
20048 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20052 *active_cursor
= 0;
20054 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20060 /* Never display a cursor in a window in which cursor-type is nil. */
20061 if (NILP (b
->cursor_type
))
20064 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20067 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
20068 return get_specified_cursor_type (alt_cursor
, width
);
20071 /* Get the normal cursor type for this window. */
20072 if (EQ (b
->cursor_type
, Qt
))
20074 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20075 *width
= FRAME_CURSOR_WIDTH (f
);
20078 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20080 /* Use normal cursor if not blinked off. */
20081 if (!w
->cursor_off_p
)
20083 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20084 if (cursor_type
== FILLED_BOX_CURSOR
)
20085 cursor_type
= HOLLOW_BOX_CURSOR
;
20087 return cursor_type
;
20090 /* Cursor is blinked off, so determine how to "toggle" it. */
20092 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20093 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20094 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20096 /* Then see if frame has specified a specific blink off cursor type. */
20097 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20099 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20100 return FRAME_BLINK_OFF_CURSOR (f
);
20104 /* Some people liked having a permanently visible blinking cursor,
20105 while others had very strong opinions against it. So it was
20106 decided to remove it. KFS 2003-09-03 */
20108 /* Finally perform built-in cursor blinking:
20109 filled box <-> hollow box
20110 wide [h]bar <-> narrow [h]bar
20111 narrow [h]bar <-> no cursor
20112 other type <-> no cursor */
20114 if (cursor_type
== FILLED_BOX_CURSOR
)
20115 return HOLLOW_BOX_CURSOR
;
20117 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20120 return cursor_type
;
20128 #ifdef HAVE_WINDOW_SYSTEM
20130 /* Notice when the text cursor of window W has been completely
20131 overwritten by a drawing operation that outputs glyphs in AREA
20132 starting at X0 and ending at X1 in the line starting at Y0 and
20133 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20134 the rest of the line after X0 has been written. Y coordinates
20135 are window-relative. */
20138 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20140 enum glyph_row_area area
;
20141 int x0
, y0
, x1
, y1
;
20143 int cx0
, cx1
, cy0
, cy1
;
20144 struct glyph_row
*row
;
20146 if (!w
->phys_cursor_on_p
)
20148 if (area
!= TEXT_AREA
)
20151 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
20152 if (!row
->displays_text_p
)
20155 if (row
->cursor_in_fringe_p
)
20157 row
->cursor_in_fringe_p
= 0;
20158 draw_fringe_bitmap (w
, row
, 0);
20159 w
->phys_cursor_on_p
= 0;
20163 cx0
= w
->phys_cursor
.x
;
20164 cx1
= cx0
+ w
->phys_cursor_width
;
20165 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20168 /* The cursor image will be completely removed from the
20169 screen if the output area intersects the cursor area in
20170 y-direction. When we draw in [y0 y1[, and some part of
20171 the cursor is at y < y0, that part must have been drawn
20172 before. When scrolling, the cursor is erased before
20173 actually scrolling, so we don't come here. When not
20174 scrolling, the rows above the old cursor row must have
20175 changed, and in this case these rows must have written
20176 over the cursor image.
20178 Likewise if part of the cursor is below y1, with the
20179 exception of the cursor being in the first blank row at
20180 the buffer and window end because update_text_area
20181 doesn't draw that row. (Except when it does, but
20182 that's handled in update_text_area.) */
20184 cy0
= w
->phys_cursor
.y
;
20185 cy1
= cy0
+ w
->phys_cursor_height
;
20186 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20189 w
->phys_cursor_on_p
= 0;
20192 #endif /* HAVE_WINDOW_SYSTEM */
20195 /************************************************************************
20197 ************************************************************************/
20199 #ifdef HAVE_WINDOW_SYSTEM
20202 Fix the display of area AREA of overlapping row ROW in window W. */
20205 x_fix_overlapping_area (w
, row
, area
)
20207 struct glyph_row
*row
;
20208 enum glyph_row_area area
;
20215 for (i
= 0; i
< row
->used
[area
];)
20217 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20219 int start
= i
, start_x
= x
;
20223 x
+= row
->glyphs
[area
][i
].pixel_width
;
20226 while (i
< row
->used
[area
]
20227 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20229 draw_glyphs (w
, start_x
, row
, area
,
20231 DRAW_NORMAL_TEXT
, 1);
20235 x
+= row
->glyphs
[area
][i
].pixel_width
;
20245 Draw the cursor glyph of window W in glyph row ROW. See the
20246 comment of draw_glyphs for the meaning of HL. */
20249 draw_phys_cursor_glyph (w
, row
, hl
)
20251 struct glyph_row
*row
;
20252 enum draw_glyphs_face hl
;
20254 /* If cursor hpos is out of bounds, don't draw garbage. This can
20255 happen in mini-buffer windows when switching between echo area
20256 glyphs and mini-buffer. */
20257 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20259 int on_p
= w
->phys_cursor_on_p
;
20261 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20262 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20264 w
->phys_cursor_on_p
= on_p
;
20266 if (hl
== DRAW_CURSOR
)
20267 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20268 /* When we erase the cursor, and ROW is overlapped by other
20269 rows, make sure that these overlapping parts of other rows
20271 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20273 if (row
> w
->current_matrix
->rows
20274 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20275 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20277 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20278 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20279 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20286 Erase the image of a cursor of window W from the screen. */
20289 erase_phys_cursor (w
)
20292 struct frame
*f
= XFRAME (w
->frame
);
20293 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20294 int hpos
= w
->phys_cursor
.hpos
;
20295 int vpos
= w
->phys_cursor
.vpos
;
20296 int mouse_face_here_p
= 0;
20297 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20298 struct glyph_row
*cursor_row
;
20299 struct glyph
*cursor_glyph
;
20300 enum draw_glyphs_face hl
;
20302 /* No cursor displayed or row invalidated => nothing to do on the
20304 if (w
->phys_cursor_type
== NO_CURSOR
)
20305 goto mark_cursor_off
;
20307 /* VPOS >= active_glyphs->nrows means that window has been resized.
20308 Don't bother to erase the cursor. */
20309 if (vpos
>= active_glyphs
->nrows
)
20310 goto mark_cursor_off
;
20312 /* If row containing cursor is marked invalid, there is nothing we
20314 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20315 if (!cursor_row
->enabled_p
)
20316 goto mark_cursor_off
;
20318 /* If line spacing is > 0, old cursor may only be partially visible in
20319 window after split-window. So adjust visible height. */
20320 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20321 window_text_bottom_y (w
) - cursor_row
->y
);
20323 /* If row is completely invisible, don't attempt to delete a cursor which
20324 isn't there. This can happen if cursor is at top of a window, and
20325 we switch to a buffer with a header line in that window. */
20326 if (cursor_row
->visible_height
<= 0)
20327 goto mark_cursor_off
;
20329 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20330 if (cursor_row
->cursor_in_fringe_p
)
20332 cursor_row
->cursor_in_fringe_p
= 0;
20333 draw_fringe_bitmap (w
, cursor_row
, 0);
20334 goto mark_cursor_off
;
20337 /* This can happen when the new row is shorter than the old one.
20338 In this case, either draw_glyphs or clear_end_of_line
20339 should have cleared the cursor. Note that we wouldn't be
20340 able to erase the cursor in this case because we don't have a
20341 cursor glyph at hand. */
20342 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20343 goto mark_cursor_off
;
20345 /* If the cursor is in the mouse face area, redisplay that when
20346 we clear the cursor. */
20347 if (! NILP (dpyinfo
->mouse_face_window
)
20348 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20349 && (vpos
> dpyinfo
->mouse_face_beg_row
20350 || (vpos
== dpyinfo
->mouse_face_beg_row
20351 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20352 && (vpos
< dpyinfo
->mouse_face_end_row
20353 || (vpos
== dpyinfo
->mouse_face_end_row
20354 && hpos
< dpyinfo
->mouse_face_end_col
))
20355 /* Don't redraw the cursor's spot in mouse face if it is at the
20356 end of a line (on a newline). The cursor appears there, but
20357 mouse highlighting does not. */
20358 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20359 mouse_face_here_p
= 1;
20361 /* Maybe clear the display under the cursor. */
20362 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20365 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20368 cursor_glyph
= get_phys_cursor_glyph (w
);
20369 if (cursor_glyph
== NULL
)
20370 goto mark_cursor_off
;
20372 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20373 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20374 width
= min (cursor_glyph
->pixel_width
,
20375 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20377 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20380 /* Erase the cursor by redrawing the character underneath it. */
20381 if (mouse_face_here_p
)
20382 hl
= DRAW_MOUSE_FACE
;
20384 hl
= DRAW_NORMAL_TEXT
;
20385 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20388 w
->phys_cursor_on_p
= 0;
20389 w
->phys_cursor_type
= NO_CURSOR
;
20394 Display or clear cursor of window W. If ON is zero, clear the
20395 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20396 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20399 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20401 int on
, hpos
, vpos
, x
, y
;
20403 struct frame
*f
= XFRAME (w
->frame
);
20404 int new_cursor_type
;
20405 int new_cursor_width
;
20407 struct glyph_row
*glyph_row
;
20408 struct glyph
*glyph
;
20410 /* This is pointless on invisible frames, and dangerous on garbaged
20411 windows and frames; in the latter case, the frame or window may
20412 be in the midst of changing its size, and x and y may be off the
20414 if (! FRAME_VISIBLE_P (f
)
20415 || FRAME_GARBAGED_P (f
)
20416 || vpos
>= w
->current_matrix
->nrows
20417 || hpos
>= w
->current_matrix
->matrix_w
)
20420 /* If cursor is off and we want it off, return quickly. */
20421 if (!on
&& !w
->phys_cursor_on_p
)
20424 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20425 /* If cursor row is not enabled, we don't really know where to
20426 display the cursor. */
20427 if (!glyph_row
->enabled_p
)
20429 w
->phys_cursor_on_p
= 0;
20434 if (!glyph_row
->exact_window_width_line_p
20435 || hpos
< glyph_row
->used
[TEXT_AREA
])
20436 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20438 xassert (interrupt_input_blocked
);
20440 /* Set new_cursor_type to the cursor we want to be displayed. */
20441 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20442 &new_cursor_width
, &active_cursor
);
20444 /* If cursor is currently being shown and we don't want it to be or
20445 it is in the wrong place, or the cursor type is not what we want,
20447 if (w
->phys_cursor_on_p
20449 || w
->phys_cursor
.x
!= x
20450 || w
->phys_cursor
.y
!= y
20451 || new_cursor_type
!= w
->phys_cursor_type
20452 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20453 && new_cursor_width
!= w
->phys_cursor_width
)))
20454 erase_phys_cursor (w
);
20456 /* Don't check phys_cursor_on_p here because that flag is only set
20457 to zero in some cases where we know that the cursor has been
20458 completely erased, to avoid the extra work of erasing the cursor
20459 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20460 still not be visible, or it has only been partly erased. */
20463 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20464 w
->phys_cursor_height
= glyph_row
->height
;
20466 /* Set phys_cursor_.* before x_draw_.* is called because some
20467 of them may need the information. */
20468 w
->phys_cursor
.x
= x
;
20469 w
->phys_cursor
.y
= glyph_row
->y
;
20470 w
->phys_cursor
.hpos
= hpos
;
20471 w
->phys_cursor
.vpos
= vpos
;
20474 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20475 new_cursor_type
, new_cursor_width
,
20476 on
, active_cursor
);
20480 /* Switch the display of W's cursor on or off, according to the value
20484 update_window_cursor (w
, on
)
20488 /* Don't update cursor in windows whose frame is in the process
20489 of being deleted. */
20490 if (w
->current_matrix
)
20493 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20494 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20500 /* Call update_window_cursor with parameter ON_P on all leaf windows
20501 in the window tree rooted at W. */
20504 update_cursor_in_window_tree (w
, on_p
)
20510 if (!NILP (w
->hchild
))
20511 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20512 else if (!NILP (w
->vchild
))
20513 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20515 update_window_cursor (w
, on_p
);
20517 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20523 Display the cursor on window W, or clear it, according to ON_P.
20524 Don't change the cursor's position. */
20527 x_update_cursor (f
, on_p
)
20531 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20536 Clear the cursor of window W to background color, and mark the
20537 cursor as not shown. This is used when the text where the cursor
20538 is is about to be rewritten. */
20544 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20545 update_window_cursor (w
, 0);
20550 Display the active region described by mouse_face_* according to DRAW. */
20553 show_mouse_face (dpyinfo
, draw
)
20554 Display_Info
*dpyinfo
;
20555 enum draw_glyphs_face draw
;
20557 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20558 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20560 if (/* If window is in the process of being destroyed, don't bother
20562 w
->current_matrix
!= NULL
20563 /* Don't update mouse highlight if hidden */
20564 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20565 /* Recognize when we are called to operate on rows that don't exist
20566 anymore. This can happen when a window is split. */
20567 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20569 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20570 struct glyph_row
*row
, *first
, *last
;
20572 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20573 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20575 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20577 int start_hpos
, end_hpos
, start_x
;
20579 /* For all but the first row, the highlight starts at column 0. */
20582 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20583 start_x
= dpyinfo
->mouse_face_beg_x
;
20592 end_hpos
= dpyinfo
->mouse_face_end_col
;
20594 end_hpos
= row
->used
[TEXT_AREA
];
20596 if (end_hpos
> start_hpos
)
20598 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20599 start_hpos
, end_hpos
,
20603 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20607 /* When we've written over the cursor, arrange for it to
20608 be displayed again. */
20609 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20612 display_and_set_cursor (w
, 1,
20613 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20614 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20619 /* Change the mouse cursor. */
20620 if (draw
== DRAW_NORMAL_TEXT
)
20621 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20622 else if (draw
== DRAW_MOUSE_FACE
)
20623 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20625 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20629 Clear out the mouse-highlighted active region.
20630 Redraw it un-highlighted first. Value is non-zero if mouse
20631 face was actually drawn unhighlighted. */
20634 clear_mouse_face (dpyinfo
)
20635 Display_Info
*dpyinfo
;
20639 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20641 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20645 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20646 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20647 dpyinfo
->mouse_face_window
= Qnil
;
20648 dpyinfo
->mouse_face_overlay
= Qnil
;
20654 Non-zero if physical cursor of window W is within mouse face. */
20657 cursor_in_mouse_face_p (w
)
20660 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20661 int in_mouse_face
= 0;
20663 if (WINDOWP (dpyinfo
->mouse_face_window
)
20664 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20666 int hpos
= w
->phys_cursor
.hpos
;
20667 int vpos
= w
->phys_cursor
.vpos
;
20669 if (vpos
>= dpyinfo
->mouse_face_beg_row
20670 && vpos
<= dpyinfo
->mouse_face_end_row
20671 && (vpos
> dpyinfo
->mouse_face_beg_row
20672 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20673 && (vpos
< dpyinfo
->mouse_face_end_row
20674 || hpos
< dpyinfo
->mouse_face_end_col
20675 || dpyinfo
->mouse_face_past_end
))
20679 return in_mouse_face
;
20685 /* Find the glyph matrix position of buffer position CHARPOS in window
20686 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20687 current glyphs must be up to date. If CHARPOS is above window
20688 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20689 of last line in W. In the row containing CHARPOS, stop before glyphs
20690 having STOP as object. */
20692 #if 1 /* This is a version of fast_find_position that's more correct
20693 in the presence of hscrolling, for example. I didn't install
20694 it right away because the problem fixed is minor, it failed
20695 in 20.x as well, and I think it's too risky to install
20696 so near the release of 21.1. 2001-09-25 gerd. */
20699 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20702 int *hpos
, *vpos
, *x
, *y
;
20705 struct glyph_row
*row
, *first
;
20706 struct glyph
*glyph
, *end
;
20709 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20710 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20715 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20719 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20722 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20726 /* If whole rows or last part of a row came from a display overlay,
20727 row_containing_pos will skip over such rows because their end pos
20728 equals the start pos of the overlay or interval. Backtrack if we
20729 have a STOP object and previous row's end glyph came from STOP. */
20732 struct glyph_row
*prev
= row
-1;
20733 while ((prev
= row
- 1, prev
>= first
)
20734 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
20735 && prev
->used
[TEXT_AREA
] > 0)
20737 end
= prev
->glyphs
[TEXT_AREA
];
20738 glyph
= end
+ prev
->used
[TEXT_AREA
];
20739 while (--glyph
>= end
20740 && INTEGERP (glyph
->object
));
20742 && !EQ (stop
, glyph
->object
))
20750 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20752 glyph
= row
->glyphs
[TEXT_AREA
];
20753 end
= glyph
+ row
->used
[TEXT_AREA
];
20755 /* Skip over glyphs not having an object at the start of the row.
20756 These are special glyphs like truncation marks on terminal
20758 if (row
->displays_text_p
)
20760 && INTEGERP (glyph
->object
)
20761 && !EQ (stop
, glyph
->object
)
20762 && glyph
->charpos
< 0)
20764 *x
+= glyph
->pixel_width
;
20769 && !INTEGERP (glyph
->object
)
20770 && !EQ (stop
, glyph
->object
)
20771 && (!BUFFERP (glyph
->object
)
20772 || glyph
->charpos
< charpos
))
20774 *x
+= glyph
->pixel_width
;
20778 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20785 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20788 int *hpos
, *vpos
, *x
, *y
;
20793 int maybe_next_line_p
= 0;
20794 int line_start_position
;
20795 int yb
= window_text_bottom_y (w
);
20796 struct glyph_row
*row
, *best_row
;
20797 int row_vpos
, best_row_vpos
;
20800 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20801 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20803 while (row
->y
< yb
)
20805 if (row
->used
[TEXT_AREA
])
20806 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20808 line_start_position
= 0;
20810 if (line_start_position
> pos
)
20812 /* If the position sought is the end of the buffer,
20813 don't include the blank lines at the bottom of the window. */
20814 else if (line_start_position
== pos
20815 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20817 maybe_next_line_p
= 1;
20820 else if (line_start_position
> 0)
20823 best_row_vpos
= row_vpos
;
20826 if (row
->y
+ row
->height
>= yb
)
20833 /* Find the right column within BEST_ROW. */
20835 current_x
= best_row
->x
;
20836 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20838 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20839 int charpos
= glyph
->charpos
;
20841 if (BUFFERP (glyph
->object
))
20843 if (charpos
== pos
)
20846 *vpos
= best_row_vpos
;
20851 else if (charpos
> pos
)
20854 else if (EQ (glyph
->object
, stop
))
20859 current_x
+= glyph
->pixel_width
;
20862 /* If we're looking for the end of the buffer,
20863 and we didn't find it in the line we scanned,
20864 use the start of the following line. */
20865 if (maybe_next_line_p
)
20870 current_x
= best_row
->x
;
20873 *vpos
= best_row_vpos
;
20874 *hpos
= lastcol
+ 1;
20883 /* Find the position of the glyph for position POS in OBJECT in
20884 window W's current matrix, and return in *X, *Y the pixel
20885 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20887 RIGHT_P non-zero means return the position of the right edge of the
20888 glyph, RIGHT_P zero means return the left edge position.
20890 If no glyph for POS exists in the matrix, return the position of
20891 the glyph with the next smaller position that is in the matrix, if
20892 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20893 exists in the matrix, return the position of the glyph with the
20894 next larger position in OBJECT.
20896 Value is non-zero if a glyph was found. */
20899 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20902 Lisp_Object object
;
20903 int *hpos
, *vpos
, *x
, *y
;
20906 int yb
= window_text_bottom_y (w
);
20907 struct glyph_row
*r
;
20908 struct glyph
*best_glyph
= NULL
;
20909 struct glyph_row
*best_row
= NULL
;
20912 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20913 r
->enabled_p
&& r
->y
< yb
;
20916 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20917 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20920 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20921 if (EQ (g
->object
, object
))
20923 if (g
->charpos
== pos
)
20930 else if (best_glyph
== NULL
20931 || ((abs (g
->charpos
- pos
)
20932 < abs (best_glyph
->charpos
- pos
))
20935 : g
->charpos
> pos
)))
20949 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20953 *x
+= best_glyph
->pixel_width
;
20958 *vpos
= best_row
- w
->current_matrix
->rows
;
20961 return best_glyph
!= NULL
;
20965 /* See if position X, Y is within a hot-spot of an image. */
20968 on_hot_spot_p (hot_spot
, x
, y
)
20969 Lisp_Object hot_spot
;
20972 if (!CONSP (hot_spot
))
20975 if (EQ (XCAR (hot_spot
), Qrect
))
20977 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20978 Lisp_Object rect
= XCDR (hot_spot
);
20982 if (!CONSP (XCAR (rect
)))
20984 if (!CONSP (XCDR (rect
)))
20986 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20988 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20990 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20992 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20996 else if (EQ (XCAR (hot_spot
), Qcircle
))
20998 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20999 Lisp_Object circ
= XCDR (hot_spot
);
21000 Lisp_Object lr
, lx0
, ly0
;
21002 && CONSP (XCAR (circ
))
21003 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21004 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21005 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21007 double r
= XFLOATINT (lr
);
21008 double dx
= XINT (lx0
) - x
;
21009 double dy
= XINT (ly0
) - y
;
21010 return (dx
* dx
+ dy
* dy
<= r
* r
);
21013 else if (EQ (XCAR (hot_spot
), Qpoly
))
21015 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21016 if (VECTORP (XCDR (hot_spot
)))
21018 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21019 Lisp_Object
*poly
= v
->contents
;
21023 Lisp_Object lx
, ly
;
21026 /* Need an even number of coordinates, and at least 3 edges. */
21027 if (n
< 6 || n
& 1)
21030 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21031 If count is odd, we are inside polygon. Pixels on edges
21032 may or may not be included depending on actual geometry of the
21034 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21035 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21037 x0
= XINT (lx
), y0
= XINT (ly
);
21038 for (i
= 0; i
< n
; i
+= 2)
21040 int x1
= x0
, y1
= y0
;
21041 if ((lx
= poly
[i
], !INTEGERP (lx
))
21042 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21044 x0
= XINT (lx
), y0
= XINT (ly
);
21046 /* Does this segment cross the X line? */
21054 if (y
> y0
&& y
> y1
)
21056 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21062 /* If we don't understand the format, pretend we're not in the hot-spot. */
21067 find_hot_spot (map
, x
, y
)
21071 while (CONSP (map
))
21073 if (CONSP (XCAR (map
))
21074 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21082 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21084 doc
: /* Lookup in image map MAP coordinates X and Y.
21085 An image map is an alist where each element has the format (AREA ID PLIST).
21086 An AREA is specified as either a rectangle, a circle, or a polygon:
21087 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21088 pixel coordinates of the upper left and bottom right corners.
21089 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21090 and the radius of the circle; r may be a float or integer.
21091 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21092 vector describes one corner in the polygon.
21093 Returns the alist element for the first matching AREA in MAP. */)
21104 return find_hot_spot (map
, XINT (x
), XINT (y
));
21108 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21110 define_frame_cursor1 (f
, cursor
, pointer
)
21113 Lisp_Object pointer
;
21115 /* Do not change cursor shape while dragging mouse. */
21116 if (!NILP (do_mouse_tracking
))
21119 if (!NILP (pointer
))
21121 if (EQ (pointer
, Qarrow
))
21122 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21123 else if (EQ (pointer
, Qhand
))
21124 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21125 else if (EQ (pointer
, Qtext
))
21126 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21127 else if (EQ (pointer
, intern ("hdrag")))
21128 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21129 #ifdef HAVE_X_WINDOWS
21130 else if (EQ (pointer
, intern ("vdrag")))
21131 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21133 else if (EQ (pointer
, intern ("hourglass")))
21134 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21135 else if (EQ (pointer
, Qmodeline
))
21136 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21138 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21141 if (cursor
!= No_Cursor
)
21142 rif
->define_frame_cursor (f
, cursor
);
21145 /* Take proper action when mouse has moved to the mode or header line
21146 or marginal area AREA of window W, x-position X and y-position Y.
21147 X is relative to the start of the text display area of W, so the
21148 width of bitmap areas and scroll bars must be subtracted to get a
21149 position relative to the start of the mode line. */
21152 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
21155 enum window_part area
;
21157 struct frame
*f
= XFRAME (w
->frame
);
21158 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21159 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21160 Lisp_Object pointer
= Qnil
;
21161 int charpos
, dx
, dy
, width
, height
;
21162 Lisp_Object string
, object
= Qnil
;
21163 Lisp_Object pos
, help
;
21165 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21166 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21167 &object
, &dx
, &dy
, &width
, &height
);
21170 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21171 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21172 &object
, &dx
, &dy
, &width
, &height
);
21177 if (IMAGEP (object
))
21179 Lisp_Object image_map
, hotspot
;
21180 if ((image_map
= Fsafe_plist_get (XCDR (object
), QCmap
),
21182 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21184 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21186 Lisp_Object area_id
, plist
;
21188 area_id
= XCAR (hotspot
);
21189 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21190 If so, we could look for mouse-enter, mouse-leave
21191 properties in PLIST (and do something...). */
21192 hotspot
= XCDR (hotspot
);
21193 if (CONSP (hotspot
)
21194 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21196 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21197 if (NILP (pointer
))
21199 help
= Fsafe_plist_get (plist
, Qhelp_echo
);
21202 help_echo_string
= help
;
21203 /* Is this correct? ++kfs */
21204 XSETWINDOW (help_echo_window
, w
);
21205 help_echo_object
= w
->buffer
;
21206 help_echo_pos
= charpos
;
21210 if (NILP (pointer
))
21211 pointer
= Fsafe_plist_get (XCDR (object
), QCpointer
);
21214 if (STRINGP (string
))
21216 pos
= make_number (charpos
);
21217 /* If we're on a string with `help-echo' text property, arrange
21218 for the help to be displayed. This is done by setting the
21219 global variable help_echo_string to the help string. */
21222 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21225 help_echo_string
= help
;
21226 XSETWINDOW (help_echo_window
, w
);
21227 help_echo_object
= string
;
21228 help_echo_pos
= charpos
;
21232 if (NILP (pointer
))
21233 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21235 /* Change the mouse pointer according to what is under X/Y. */
21236 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21239 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21240 if (!KEYMAPP (map
))
21241 map
= Fget_text_property (pos
, Qkeymap
, string
);
21242 if (!KEYMAPP (map
))
21243 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21247 define_frame_cursor1 (f
, cursor
, pointer
);
21252 Take proper action when the mouse has moved to position X, Y on
21253 frame F as regards highlighting characters that have mouse-face
21254 properties. Also de-highlighting chars where the mouse was before.
21255 X and Y can be negative or out of range. */
21258 note_mouse_highlight (f
, x
, y
)
21262 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21263 enum window_part part
;
21264 Lisp_Object window
;
21266 Cursor cursor
= No_Cursor
;
21267 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21270 /* When a menu is active, don't highlight because this looks odd. */
21271 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21272 if (popup_activated ())
21276 if (NILP (Vmouse_highlight
)
21277 || !f
->glyphs_initialized_p
)
21280 dpyinfo
->mouse_face_mouse_x
= x
;
21281 dpyinfo
->mouse_face_mouse_y
= y
;
21282 dpyinfo
->mouse_face_mouse_frame
= f
;
21284 if (dpyinfo
->mouse_face_defer
)
21287 if (gc_in_progress
)
21289 dpyinfo
->mouse_face_deferred_gc
= 1;
21293 /* Which window is that in? */
21294 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21296 /* If we were displaying active text in another window, clear that.
21297 Also clear if we move out of text area in same window. */
21298 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21299 || (part
!= ON_TEXT
&& !NILP (dpyinfo
->mouse_face_window
)))
21300 clear_mouse_face (dpyinfo
);
21302 /* Not on a window -> return. */
21303 if (!WINDOWP (window
))
21306 /* Reset help_echo_string. It will get recomputed below. */
21307 help_echo_string
= Qnil
;
21309 /* Convert to window-relative pixel coordinates. */
21310 w
= XWINDOW (window
);
21311 frame_to_window_pixel_xy (w
, &x
, &y
);
21313 /* Handle tool-bar window differently since it doesn't display a
21315 if (EQ (window
, f
->tool_bar_window
))
21317 note_tool_bar_highlight (f
, x
, y
);
21321 /* Mouse is on the mode, header line or margin? */
21322 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21323 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21325 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
21329 if (part
== ON_VERTICAL_BORDER
)
21330 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21331 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21332 || part
== ON_SCROLL_BAR
)
21333 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21335 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21337 /* Are we in a window whose display is up to date?
21338 And verify the buffer's text has not changed. */
21339 b
= XBUFFER (w
->buffer
);
21340 if (part
== ON_TEXT
21341 && EQ (w
->window_end_valid
, w
->buffer
)
21342 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21343 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21345 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21346 struct glyph
*glyph
;
21347 Lisp_Object object
;
21348 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21349 Lisp_Object
*overlay_vec
= NULL
;
21351 struct buffer
*obuf
;
21352 int obegv
, ozv
, same_region
;
21354 /* Find the glyph under X/Y. */
21355 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21357 /* Look for :pointer property on image. */
21358 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21360 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21361 if (img
!= NULL
&& IMAGEP (img
->spec
))
21363 Lisp_Object image_map
, hotspot
;
21364 if ((image_map
= Fsafe_plist_get (XCDR (img
->spec
), QCmap
),
21366 && (hotspot
= find_hot_spot (image_map
,
21367 glyph
->slice
.x
+ dx
,
21368 glyph
->slice
.y
+ dy
),
21370 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21372 Lisp_Object area_id
, plist
;
21374 area_id
= XCAR (hotspot
);
21375 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21376 If so, we could look for mouse-enter, mouse-leave
21377 properties in PLIST (and do something...). */
21378 hotspot
= XCDR (hotspot
);
21379 if (CONSP (hotspot
)
21380 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21382 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21383 if (NILP (pointer
))
21385 help_echo_string
= Fsafe_plist_get (plist
, Qhelp_echo
);
21386 if (!NILP (help_echo_string
))
21388 help_echo_window
= window
;
21389 help_echo_object
= glyph
->object
;
21390 help_echo_pos
= glyph
->charpos
;
21394 if (NILP (pointer
))
21395 pointer
= Fsafe_plist_get (XCDR (img
->spec
), QCpointer
);
21399 /* Clear mouse face if X/Y not over text. */
21401 || area
!= TEXT_AREA
21402 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21404 if (clear_mouse_face (dpyinfo
))
21405 cursor
= No_Cursor
;
21406 if (NILP (pointer
))
21408 if (area
!= TEXT_AREA
)
21409 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21411 pointer
= Vvoid_text_area_pointer
;
21416 pos
= glyph
->charpos
;
21417 object
= glyph
->object
;
21418 if (!STRINGP (object
) && !BUFFERP (object
))
21421 /* If we get an out-of-range value, return now; avoid an error. */
21422 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21425 /* Make the window's buffer temporarily current for
21426 overlays_at and compute_char_face. */
21427 obuf
= current_buffer
;
21428 current_buffer
= b
;
21434 /* Is this char mouse-active or does it have help-echo? */
21435 position
= make_number (pos
);
21437 if (BUFFERP (object
))
21439 /* Put all the overlays we want in a vector in overlay_vec. */
21440 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21441 /* Sort overlays into increasing priority order. */
21442 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21447 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21448 && vpos
>= dpyinfo
->mouse_face_beg_row
21449 && vpos
<= dpyinfo
->mouse_face_end_row
21450 && (vpos
> dpyinfo
->mouse_face_beg_row
21451 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21452 && (vpos
< dpyinfo
->mouse_face_end_row
21453 || hpos
< dpyinfo
->mouse_face_end_col
21454 || dpyinfo
->mouse_face_past_end
));
21457 cursor
= No_Cursor
;
21459 /* Check mouse-face highlighting. */
21461 /* If there exists an overlay with mouse-face overlapping
21462 the one we are currently highlighting, we have to
21463 check if we enter the overlapping overlay, and then
21464 highlight only that. */
21465 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21466 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21468 /* Find the highest priority overlay that has a mouse-face
21471 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21473 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21474 if (!NILP (mouse_face
))
21475 overlay
= overlay_vec
[i
];
21478 /* If we're actually highlighting the same overlay as
21479 before, there's no need to do that again. */
21480 if (!NILP (overlay
)
21481 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21482 goto check_help_echo
;
21484 dpyinfo
->mouse_face_overlay
= overlay
;
21486 /* Clear the display of the old active region, if any. */
21487 if (clear_mouse_face (dpyinfo
))
21488 cursor
= No_Cursor
;
21490 /* If no overlay applies, get a text property. */
21491 if (NILP (overlay
))
21492 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21494 /* Handle the overlay case. */
21495 if (!NILP (overlay
))
21497 /* Find the range of text around this char that
21498 should be active. */
21499 Lisp_Object before
, after
;
21502 before
= Foverlay_start (overlay
);
21503 after
= Foverlay_end (overlay
);
21504 /* Record this as the current active region. */
21505 fast_find_position (w
, XFASTINT (before
),
21506 &dpyinfo
->mouse_face_beg_col
,
21507 &dpyinfo
->mouse_face_beg_row
,
21508 &dpyinfo
->mouse_face_beg_x
,
21509 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21511 dpyinfo
->mouse_face_past_end
21512 = !fast_find_position (w
, XFASTINT (after
),
21513 &dpyinfo
->mouse_face_end_col
,
21514 &dpyinfo
->mouse_face_end_row
,
21515 &dpyinfo
->mouse_face_end_x
,
21516 &dpyinfo
->mouse_face_end_y
, Qnil
);
21517 dpyinfo
->mouse_face_window
= window
;
21519 dpyinfo
->mouse_face_face_id
21520 = face_at_buffer_position (w
, pos
, 0, 0,
21522 !dpyinfo
->mouse_face_hidden
);
21524 /* Display it as active. */
21525 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21526 cursor
= No_Cursor
;
21528 /* Handle the text property case. */
21529 else if (!NILP (mouse_face
) && BUFFERP (object
))
21531 /* Find the range of text around this char that
21532 should be active. */
21533 Lisp_Object before
, after
, beginning
, end
;
21536 beginning
= Fmarker_position (w
->start
);
21537 end
= make_number (BUF_Z (XBUFFER (object
))
21538 - XFASTINT (w
->window_end_pos
));
21540 = Fprevious_single_property_change (make_number (pos
+ 1),
21542 object
, beginning
);
21544 = Fnext_single_property_change (position
, Qmouse_face
,
21547 /* Record this as the current active region. */
21548 fast_find_position (w
, XFASTINT (before
),
21549 &dpyinfo
->mouse_face_beg_col
,
21550 &dpyinfo
->mouse_face_beg_row
,
21551 &dpyinfo
->mouse_face_beg_x
,
21552 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21553 dpyinfo
->mouse_face_past_end
21554 = !fast_find_position (w
, XFASTINT (after
),
21555 &dpyinfo
->mouse_face_end_col
,
21556 &dpyinfo
->mouse_face_end_row
,
21557 &dpyinfo
->mouse_face_end_x
,
21558 &dpyinfo
->mouse_face_end_y
, Qnil
);
21559 dpyinfo
->mouse_face_window
= window
;
21561 if (BUFFERP (object
))
21562 dpyinfo
->mouse_face_face_id
21563 = face_at_buffer_position (w
, pos
, 0, 0,
21565 !dpyinfo
->mouse_face_hidden
);
21567 /* Display it as active. */
21568 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21569 cursor
= No_Cursor
;
21571 else if (!NILP (mouse_face
) && STRINGP (object
))
21576 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21579 e
= Fnext_single_property_change (position
, Qmouse_face
,
21582 b
= make_number (0);
21584 e
= make_number (SCHARS (object
) - 1);
21585 fast_find_string_pos (w
, XINT (b
), object
,
21586 &dpyinfo
->mouse_face_beg_col
,
21587 &dpyinfo
->mouse_face_beg_row
,
21588 &dpyinfo
->mouse_face_beg_x
,
21589 &dpyinfo
->mouse_face_beg_y
, 0);
21590 fast_find_string_pos (w
, XINT (e
), object
,
21591 &dpyinfo
->mouse_face_end_col
,
21592 &dpyinfo
->mouse_face_end_row
,
21593 &dpyinfo
->mouse_face_end_x
,
21594 &dpyinfo
->mouse_face_end_y
, 1);
21595 dpyinfo
->mouse_face_past_end
= 0;
21596 dpyinfo
->mouse_face_window
= window
;
21597 dpyinfo
->mouse_face_face_id
21598 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21599 glyph
->face_id
, 1);
21600 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21601 cursor
= No_Cursor
;
21603 else if (STRINGP (object
) && NILP (mouse_face
))
21605 /* A string which doesn't have mouse-face, but
21606 the text ``under'' it might have. */
21607 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21608 int start
= MATRIX_ROW_START_CHARPOS (r
);
21610 pos
= string_buffer_position (w
, object
, start
);
21612 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21616 if (!NILP (mouse_face
) && !NILP (overlay
))
21618 Lisp_Object before
= Foverlay_start (overlay
);
21619 Lisp_Object after
= Foverlay_end (overlay
);
21622 /* Note that we might not be able to find position
21623 BEFORE in the glyph matrix if the overlay is
21624 entirely covered by a `display' property. In
21625 this case, we overshoot. So let's stop in
21626 the glyph matrix before glyphs for OBJECT. */
21627 fast_find_position (w
, XFASTINT (before
),
21628 &dpyinfo
->mouse_face_beg_col
,
21629 &dpyinfo
->mouse_face_beg_row
,
21630 &dpyinfo
->mouse_face_beg_x
,
21631 &dpyinfo
->mouse_face_beg_y
,
21634 dpyinfo
->mouse_face_past_end
21635 = !fast_find_position (w
, XFASTINT (after
),
21636 &dpyinfo
->mouse_face_end_col
,
21637 &dpyinfo
->mouse_face_end_row
,
21638 &dpyinfo
->mouse_face_end_x
,
21639 &dpyinfo
->mouse_face_end_y
,
21641 dpyinfo
->mouse_face_window
= window
;
21642 dpyinfo
->mouse_face_face_id
21643 = face_at_buffer_position (w
, pos
, 0, 0,
21645 !dpyinfo
->mouse_face_hidden
);
21647 /* Display it as active. */
21648 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21649 cursor
= No_Cursor
;
21656 /* Look for a `help-echo' property. */
21657 if (NILP (help_echo_string
)) {
21658 Lisp_Object help
, overlay
;
21660 /* Check overlays first. */
21661 help
= overlay
= Qnil
;
21662 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21664 overlay
= overlay_vec
[i
];
21665 help
= Foverlay_get (overlay
, Qhelp_echo
);
21670 help_echo_string
= help
;
21671 help_echo_window
= window
;
21672 help_echo_object
= overlay
;
21673 help_echo_pos
= pos
;
21677 Lisp_Object object
= glyph
->object
;
21678 int charpos
= glyph
->charpos
;
21680 /* Try text properties. */
21681 if (STRINGP (object
)
21683 && charpos
< SCHARS (object
))
21685 help
= Fget_text_property (make_number (charpos
),
21686 Qhelp_echo
, object
);
21689 /* If the string itself doesn't specify a help-echo,
21690 see if the buffer text ``under'' it does. */
21691 struct glyph_row
*r
21692 = MATRIX_ROW (w
->current_matrix
, vpos
);
21693 int start
= MATRIX_ROW_START_CHARPOS (r
);
21694 int pos
= string_buffer_position (w
, object
, start
);
21697 help
= Fget_char_property (make_number (pos
),
21698 Qhelp_echo
, w
->buffer
);
21702 object
= w
->buffer
;
21707 else if (BUFFERP (object
)
21710 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21715 help_echo_string
= help
;
21716 help_echo_window
= window
;
21717 help_echo_object
= object
;
21718 help_echo_pos
= charpos
;
21723 /* Look for a `pointer' property. */
21724 if (NILP (pointer
))
21726 /* Check overlays first. */
21727 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21728 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21730 if (NILP (pointer
))
21732 Lisp_Object object
= glyph
->object
;
21733 int charpos
= glyph
->charpos
;
21735 /* Try text properties. */
21736 if (STRINGP (object
)
21738 && charpos
< SCHARS (object
))
21740 pointer
= Fget_text_property (make_number (charpos
),
21742 if (NILP (pointer
))
21744 /* If the string itself doesn't specify a pointer,
21745 see if the buffer text ``under'' it does. */
21746 struct glyph_row
*r
21747 = MATRIX_ROW (w
->current_matrix
, vpos
);
21748 int start
= MATRIX_ROW_START_CHARPOS (r
);
21749 int pos
= string_buffer_position (w
, object
, start
);
21751 pointer
= Fget_char_property (make_number (pos
),
21752 Qpointer
, w
->buffer
);
21755 else if (BUFFERP (object
)
21758 pointer
= Fget_text_property (make_number (charpos
),
21765 current_buffer
= obuf
;
21770 define_frame_cursor1 (f
, cursor
, pointer
);
21775 Clear any mouse-face on window W. This function is part of the
21776 redisplay interface, and is called from try_window_id and similar
21777 functions to ensure the mouse-highlight is off. */
21780 x_clear_window_mouse_face (w
)
21783 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21784 Lisp_Object window
;
21787 XSETWINDOW (window
, w
);
21788 if (EQ (window
, dpyinfo
->mouse_face_window
))
21789 clear_mouse_face (dpyinfo
);
21795 Just discard the mouse face information for frame F, if any.
21796 This is used when the size of F is changed. */
21799 cancel_mouse_face (f
)
21802 Lisp_Object window
;
21803 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21805 window
= dpyinfo
->mouse_face_window
;
21806 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21808 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21809 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21810 dpyinfo
->mouse_face_window
= Qnil
;
21815 #endif /* HAVE_WINDOW_SYSTEM */
21818 /***********************************************************************
21820 ***********************************************************************/
21822 #ifdef HAVE_WINDOW_SYSTEM
21824 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21825 which intersects rectangle R. R is in window-relative coordinates. */
21828 expose_area (w
, row
, r
, area
)
21830 struct glyph_row
*row
;
21832 enum glyph_row_area area
;
21834 struct glyph
*first
= row
->glyphs
[area
];
21835 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21836 struct glyph
*last
;
21837 int first_x
, start_x
, x
;
21839 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21840 /* If row extends face to end of line write the whole line. */
21841 draw_glyphs (w
, 0, row
, area
,
21842 0, row
->used
[area
],
21843 DRAW_NORMAL_TEXT
, 0);
21846 /* Set START_X to the window-relative start position for drawing glyphs of
21847 AREA. The first glyph of the text area can be partially visible.
21848 The first glyphs of other areas cannot. */
21849 start_x
= window_box_left_offset (w
, area
);
21851 if (area
== TEXT_AREA
)
21854 /* Find the first glyph that must be redrawn. */
21856 && x
+ first
->pixel_width
< r
->x
)
21858 x
+= first
->pixel_width
;
21862 /* Find the last one. */
21866 && x
< r
->x
+ r
->width
)
21868 x
+= last
->pixel_width
;
21874 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21875 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21876 DRAW_NORMAL_TEXT
, 0);
21881 /* Redraw the parts of the glyph row ROW on window W intersecting
21882 rectangle R. R is in window-relative coordinates. Value is
21883 non-zero if mouse-face was overwritten. */
21886 expose_line (w
, row
, r
)
21888 struct glyph_row
*row
;
21891 xassert (row
->enabled_p
);
21893 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21894 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21895 0, row
->used
[TEXT_AREA
],
21896 DRAW_NORMAL_TEXT
, 0);
21899 if (row
->used
[LEFT_MARGIN_AREA
])
21900 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21901 if (row
->used
[TEXT_AREA
])
21902 expose_area (w
, row
, r
, TEXT_AREA
);
21903 if (row
->used
[RIGHT_MARGIN_AREA
])
21904 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21905 draw_row_fringe_bitmaps (w
, row
);
21908 return row
->mouse_face_p
;
21912 /* Redraw those parts of glyphs rows during expose event handling that
21913 overlap other rows. Redrawing of an exposed line writes over parts
21914 of lines overlapping that exposed line; this function fixes that.
21916 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21917 row in W's current matrix that is exposed and overlaps other rows.
21918 LAST_OVERLAPPING_ROW is the last such row. */
21921 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21923 struct glyph_row
*first_overlapping_row
;
21924 struct glyph_row
*last_overlapping_row
;
21926 struct glyph_row
*row
;
21928 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21929 if (row
->overlapping_p
)
21931 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21933 if (row
->used
[LEFT_MARGIN_AREA
])
21934 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21936 if (row
->used
[TEXT_AREA
])
21937 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21939 if (row
->used
[RIGHT_MARGIN_AREA
])
21940 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21945 /* Return non-zero if W's cursor intersects rectangle R. */
21948 phys_cursor_in_rect_p (w
, r
)
21952 XRectangle cr
, result
;
21953 struct glyph
*cursor_glyph
;
21955 cursor_glyph
= get_phys_cursor_glyph (w
);
21958 /* r is relative to W's box, but w->phys_cursor.x is relative
21959 to left edge of W's TEXT area. Adjust it. */
21960 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21961 cr
.y
= w
->phys_cursor
.y
;
21962 cr
.width
= cursor_glyph
->pixel_width
;
21963 cr
.height
= w
->phys_cursor_height
;
21964 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21965 I assume the effect is the same -- and this is portable. */
21966 return x_intersect_rectangles (&cr
, r
, &result
);
21974 Draw a vertical window border to the right of window W if W doesn't
21975 have vertical scroll bars. */
21978 x_draw_vertical_border (w
)
21981 /* We could do better, if we knew what type of scroll-bar the adjacent
21982 windows (on either side) have... But we don't :-(
21983 However, I think this works ok. ++KFS 2003-04-25 */
21985 /* Redraw borders between horizontally adjacent windows. Don't
21986 do it for frames with vertical scroll bars because either the
21987 right scroll bar of a window, or the left scroll bar of its
21988 neighbor will suffice as a border. */
21989 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
21992 if (!WINDOW_RIGHTMOST_P (w
)
21993 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21995 int x0
, x1
, y0
, y1
;
21997 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22000 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22002 else if (!WINDOW_LEFTMOST_P (w
)
22003 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22005 int x0
, x1
, y0
, y1
;
22007 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22010 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22015 /* Redraw the part of window W intersection rectangle FR. Pixel
22016 coordinates in FR are frame-relative. Call this function with
22017 input blocked. Value is non-zero if the exposure overwrites
22021 expose_window (w
, fr
)
22025 struct frame
*f
= XFRAME (w
->frame
);
22027 int mouse_face_overwritten_p
= 0;
22029 /* If window is not yet fully initialized, do nothing. This can
22030 happen when toolkit scroll bars are used and a window is split.
22031 Reconfiguring the scroll bar will generate an expose for a newly
22033 if (w
->current_matrix
== NULL
)
22036 /* When we're currently updating the window, display and current
22037 matrix usually don't agree. Arrange for a thorough display
22039 if (w
== updated_window
)
22041 SET_FRAME_GARBAGED (f
);
22045 /* Frame-relative pixel rectangle of W. */
22046 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22047 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22048 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22049 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22051 if (x_intersect_rectangles (fr
, &wr
, &r
))
22053 int yb
= window_text_bottom_y (w
);
22054 struct glyph_row
*row
;
22055 int cursor_cleared_p
;
22056 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22058 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22059 r
.x
, r
.y
, r
.width
, r
.height
));
22061 /* Convert to window coordinates. */
22062 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22063 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22065 /* Turn off the cursor. */
22066 if (!w
->pseudo_window_p
22067 && phys_cursor_in_rect_p (w
, &r
))
22069 x_clear_cursor (w
);
22070 cursor_cleared_p
= 1;
22073 cursor_cleared_p
= 0;
22075 /* Update lines intersecting rectangle R. */
22076 first_overlapping_row
= last_overlapping_row
= NULL
;
22077 for (row
= w
->current_matrix
->rows
;
22082 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22084 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22085 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22086 || (r
.y
>= y0
&& r
.y
< y1
)
22087 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22089 if (row
->overlapping_p
)
22091 if (first_overlapping_row
== NULL
)
22092 first_overlapping_row
= row
;
22093 last_overlapping_row
= row
;
22096 if (expose_line (w
, row
, &r
))
22097 mouse_face_overwritten_p
= 1;
22104 /* Display the mode line if there is one. */
22105 if (WINDOW_WANTS_MODELINE_P (w
)
22106 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22108 && row
->y
< r
.y
+ r
.height
)
22110 if (expose_line (w
, row
, &r
))
22111 mouse_face_overwritten_p
= 1;
22114 if (!w
->pseudo_window_p
)
22116 /* Fix the display of overlapping rows. */
22117 if (first_overlapping_row
)
22118 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22120 /* Draw border between windows. */
22121 x_draw_vertical_border (w
);
22123 /* Turn the cursor on again. */
22124 if (cursor_cleared_p
)
22125 update_window_cursor (w
, 1);
22129 return mouse_face_overwritten_p
;
22134 /* Redraw (parts) of all windows in the window tree rooted at W that
22135 intersect R. R contains frame pixel coordinates. Value is
22136 non-zero if the exposure overwrites mouse-face. */
22139 expose_window_tree (w
, r
)
22143 struct frame
*f
= XFRAME (w
->frame
);
22144 int mouse_face_overwritten_p
= 0;
22146 while (w
&& !FRAME_GARBAGED_P (f
))
22148 if (!NILP (w
->hchild
))
22149 mouse_face_overwritten_p
22150 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22151 else if (!NILP (w
->vchild
))
22152 mouse_face_overwritten_p
22153 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22155 mouse_face_overwritten_p
|= expose_window (w
, r
);
22157 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22160 return mouse_face_overwritten_p
;
22165 Redisplay an exposed area of frame F. X and Y are the upper-left
22166 corner of the exposed rectangle. W and H are width and height of
22167 the exposed area. All are pixel values. W or H zero means redraw
22168 the entire frame. */
22171 expose_frame (f
, x
, y
, w
, h
)
22176 int mouse_face_overwritten_p
= 0;
22178 TRACE ((stderr
, "expose_frame "));
22180 /* No need to redraw if frame will be redrawn soon. */
22181 if (FRAME_GARBAGED_P (f
))
22183 TRACE ((stderr
, " garbaged\n"));
22187 /* If basic faces haven't been realized yet, there is no point in
22188 trying to redraw anything. This can happen when we get an expose
22189 event while Emacs is starting, e.g. by moving another window. */
22190 if (FRAME_FACE_CACHE (f
) == NULL
22191 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22193 TRACE ((stderr
, " no faces\n"));
22197 if (w
== 0 || h
== 0)
22200 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22201 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22211 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22212 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22214 if (WINDOWP (f
->tool_bar_window
))
22215 mouse_face_overwritten_p
22216 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22218 #ifdef HAVE_X_WINDOWS
22220 #ifndef USE_X_TOOLKIT
22221 if (WINDOWP (f
->menu_bar_window
))
22222 mouse_face_overwritten_p
22223 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22224 #endif /* not USE_X_TOOLKIT */
22228 /* Some window managers support a focus-follows-mouse style with
22229 delayed raising of frames. Imagine a partially obscured frame,
22230 and moving the mouse into partially obscured mouse-face on that
22231 frame. The visible part of the mouse-face will be highlighted,
22232 then the WM raises the obscured frame. With at least one WM, KDE
22233 2.1, Emacs is not getting any event for the raising of the frame
22234 (even tried with SubstructureRedirectMask), only Expose events.
22235 These expose events will draw text normally, i.e. not
22236 highlighted. Which means we must redo the highlight here.
22237 Subsume it under ``we love X''. --gerd 2001-08-15 */
22238 /* Included in Windows version because Windows most likely does not
22239 do the right thing if any third party tool offers
22240 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22241 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22243 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22244 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22246 int x
= dpyinfo
->mouse_face_mouse_x
;
22247 int y
= dpyinfo
->mouse_face_mouse_y
;
22248 clear_mouse_face (dpyinfo
);
22249 note_mouse_highlight (f
, x
, y
);
22256 Determine the intersection of two rectangles R1 and R2. Return
22257 the intersection in *RESULT. Value is non-zero if RESULT is not
22261 x_intersect_rectangles (r1
, r2
, result
)
22262 XRectangle
*r1
, *r2
, *result
;
22264 XRectangle
*left
, *right
;
22265 XRectangle
*upper
, *lower
;
22266 int intersection_p
= 0;
22268 /* Rearrange so that R1 is the left-most rectangle. */
22270 left
= r1
, right
= r2
;
22272 left
= r2
, right
= r1
;
22274 /* X0 of the intersection is right.x0, if this is inside R1,
22275 otherwise there is no intersection. */
22276 if (right
->x
<= left
->x
+ left
->width
)
22278 result
->x
= right
->x
;
22280 /* The right end of the intersection is the minimum of the
22281 the right ends of left and right. */
22282 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22285 /* Same game for Y. */
22287 upper
= r1
, lower
= r2
;
22289 upper
= r2
, lower
= r1
;
22291 /* The upper end of the intersection is lower.y0, if this is inside
22292 of upper. Otherwise, there is no intersection. */
22293 if (lower
->y
<= upper
->y
+ upper
->height
)
22295 result
->y
= lower
->y
;
22297 /* The lower end of the intersection is the minimum of the lower
22298 ends of upper and lower. */
22299 result
->height
= (min (lower
->y
+ lower
->height
,
22300 upper
->y
+ upper
->height
)
22302 intersection_p
= 1;
22306 return intersection_p
;
22309 #endif /* HAVE_WINDOW_SYSTEM */
22312 /***********************************************************************
22314 ***********************************************************************/
22319 Vwith_echo_area_save_vector
= Qnil
;
22320 staticpro (&Vwith_echo_area_save_vector
);
22322 Vmessage_stack
= Qnil
;
22323 staticpro (&Vmessage_stack
);
22325 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22326 staticpro (&Qinhibit_redisplay
);
22328 message_dolog_marker1
= Fmake_marker ();
22329 staticpro (&message_dolog_marker1
);
22330 message_dolog_marker2
= Fmake_marker ();
22331 staticpro (&message_dolog_marker2
);
22332 message_dolog_marker3
= Fmake_marker ();
22333 staticpro (&message_dolog_marker3
);
22336 defsubr (&Sdump_frame_glyph_matrix
);
22337 defsubr (&Sdump_glyph_matrix
);
22338 defsubr (&Sdump_glyph_row
);
22339 defsubr (&Sdump_tool_bar_row
);
22340 defsubr (&Strace_redisplay
);
22341 defsubr (&Strace_to_stderr
);
22343 #ifdef HAVE_WINDOW_SYSTEM
22344 defsubr (&Stool_bar_lines_needed
);
22345 defsubr (&Slookup_image_map
);
22347 defsubr (&Sformat_mode_line
);
22349 staticpro (&Qmenu_bar_update_hook
);
22350 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22352 staticpro (&Qoverriding_terminal_local_map
);
22353 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22355 staticpro (&Qoverriding_local_map
);
22356 Qoverriding_local_map
= intern ("overriding-local-map");
22358 staticpro (&Qwindow_scroll_functions
);
22359 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22361 staticpro (&Qredisplay_end_trigger_functions
);
22362 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22364 staticpro (&Qinhibit_point_motion_hooks
);
22365 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22367 QCdata
= intern (":data");
22368 staticpro (&QCdata
);
22369 Qdisplay
= intern ("display");
22370 staticpro (&Qdisplay
);
22371 Qspace_width
= intern ("space-width");
22372 staticpro (&Qspace_width
);
22373 Qraise
= intern ("raise");
22374 staticpro (&Qraise
);
22375 Qslice
= intern ("slice");
22376 staticpro (&Qslice
);
22377 Qspace
= intern ("space");
22378 staticpro (&Qspace
);
22379 Qmargin
= intern ("margin");
22380 staticpro (&Qmargin
);
22381 Qpointer
= intern ("pointer");
22382 staticpro (&Qpointer
);
22383 Qleft_margin
= intern ("left-margin");
22384 staticpro (&Qleft_margin
);
22385 Qright_margin
= intern ("right-margin");
22386 staticpro (&Qright_margin
);
22387 Qcenter
= intern ("center");
22388 staticpro (&Qcenter
);
22389 Qline_height
= intern ("line-height");
22390 staticpro (&Qline_height
);
22391 QCalign_to
= intern (":align-to");
22392 staticpro (&QCalign_to
);
22393 QCrelative_width
= intern (":relative-width");
22394 staticpro (&QCrelative_width
);
22395 QCrelative_height
= intern (":relative-height");
22396 staticpro (&QCrelative_height
);
22397 QCeval
= intern (":eval");
22398 staticpro (&QCeval
);
22399 QCpropertize
= intern (":propertize");
22400 staticpro (&QCpropertize
);
22401 QCfile
= intern (":file");
22402 staticpro (&QCfile
);
22403 Qfontified
= intern ("fontified");
22404 staticpro (&Qfontified
);
22405 Qfontification_functions
= intern ("fontification-functions");
22406 staticpro (&Qfontification_functions
);
22407 Qtrailing_whitespace
= intern ("trailing-whitespace");
22408 staticpro (&Qtrailing_whitespace
);
22409 Qescape_glyph
= intern ("escape-glyph");
22410 staticpro (&Qescape_glyph
);
22411 Qimage
= intern ("image");
22412 staticpro (&Qimage
);
22413 QCmap
= intern (":map");
22414 staticpro (&QCmap
);
22415 QCpointer
= intern (":pointer");
22416 staticpro (&QCpointer
);
22417 Qrect
= intern ("rect");
22418 staticpro (&Qrect
);
22419 Qcircle
= intern ("circle");
22420 staticpro (&Qcircle
);
22421 Qpoly
= intern ("poly");
22422 staticpro (&Qpoly
);
22423 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22424 staticpro (&Qmessage_truncate_lines
);
22425 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
22426 staticpro (&Qcursor_in_non_selected_windows
);
22427 Qgrow_only
= intern ("grow-only");
22428 staticpro (&Qgrow_only
);
22429 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22430 staticpro (&Qinhibit_menubar_update
);
22431 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22432 staticpro (&Qinhibit_eval_during_redisplay
);
22433 Qposition
= intern ("position");
22434 staticpro (&Qposition
);
22435 Qbuffer_position
= intern ("buffer-position");
22436 staticpro (&Qbuffer_position
);
22437 Qobject
= intern ("object");
22438 staticpro (&Qobject
);
22439 Qbar
= intern ("bar");
22441 Qhbar
= intern ("hbar");
22442 staticpro (&Qhbar
);
22443 Qbox
= intern ("box");
22445 Qhollow
= intern ("hollow");
22446 staticpro (&Qhollow
);
22447 Qhand
= intern ("hand");
22448 staticpro (&Qhand
);
22449 Qarrow
= intern ("arrow");
22450 staticpro (&Qarrow
);
22451 Qtext
= intern ("text");
22452 staticpro (&Qtext
);
22453 Qrisky_local_variable
= intern ("risky-local-variable");
22454 staticpro (&Qrisky_local_variable
);
22455 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22456 staticpro (&Qinhibit_free_realized_faces
);
22458 list_of_error
= Fcons (Fcons (intern ("error"),
22459 Fcons (intern ("void-variable"), Qnil
)),
22461 staticpro (&list_of_error
);
22463 Qlast_arrow_position
= intern ("last-arrow-position");
22464 staticpro (&Qlast_arrow_position
);
22465 Qlast_arrow_string
= intern ("last-arrow-string");
22466 staticpro (&Qlast_arrow_string
);
22468 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22469 staticpro (&Qoverlay_arrow_string
);
22470 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22471 staticpro (&Qoverlay_arrow_bitmap
);
22473 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22474 staticpro (&echo_buffer
[0]);
22475 staticpro (&echo_buffer
[1]);
22477 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22478 staticpro (&echo_area_buffer
[0]);
22479 staticpro (&echo_area_buffer
[1]);
22481 Vmessages_buffer_name
= build_string ("*Messages*");
22482 staticpro (&Vmessages_buffer_name
);
22484 mode_line_proptrans_alist
= Qnil
;
22485 staticpro (&mode_line_proptrans_alist
);
22487 mode_line_string_list
= Qnil
;
22488 staticpro (&mode_line_string_list
);
22490 help_echo_string
= Qnil
;
22491 staticpro (&help_echo_string
);
22492 help_echo_object
= Qnil
;
22493 staticpro (&help_echo_object
);
22494 help_echo_window
= Qnil
;
22495 staticpro (&help_echo_window
);
22496 previous_help_echo_string
= Qnil
;
22497 staticpro (&previous_help_echo_string
);
22498 help_echo_pos
= -1;
22500 #ifdef HAVE_WINDOW_SYSTEM
22501 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22502 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22503 For example, if a block cursor is over a tab, it will be drawn as
22504 wide as that tab on the display. */);
22505 x_stretch_cursor_p
= 0;
22508 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22509 doc
: /* *Non-nil means highlight trailing whitespace.
22510 The face used for trailing whitespace is `trailing-whitespace'. */);
22511 Vshow_trailing_whitespace
= Qnil
;
22513 DEFVAR_LISP ("show-nonbreak-escape", &Vshow_nonbreak_escape
,
22514 doc
: /* *Non-nil means display escape character before non-break space and hyphen. */);
22515 Vshow_nonbreak_escape
= Qt
;
22517 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22518 doc
: /* *The pointer shape to show in void text areas.
22519 Nil means to show the text pointer. Other options are `arrow', `text',
22520 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22521 Vvoid_text_area_pointer
= Qarrow
;
22523 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22524 doc
: /* Non-nil means don't actually do any redisplay.
22525 This is used for internal purposes. */);
22526 Vinhibit_redisplay
= Qnil
;
22528 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22529 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22530 Vglobal_mode_string
= Qnil
;
22532 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22533 doc
: /* Marker for where to display an arrow on top of the buffer text.
22534 This must be the beginning of a line in order to work.
22535 See also `overlay-arrow-string'. */);
22536 Voverlay_arrow_position
= Qnil
;
22538 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22539 doc
: /* String to display as an arrow in non-window frames.
22540 See also `overlay-arrow-position'. */);
22541 Voverlay_arrow_string
= Qnil
;
22543 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22544 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22545 The symbols on this list are examined during redisplay to determine
22546 where to display overlay arrows. */);
22547 Voverlay_arrow_variable_list
22548 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22550 DEFVAR_INT ("scroll-step", &scroll_step
,
22551 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22552 If that fails to bring point back on frame, point is centered instead.
22553 If this is zero, point is always centered after it moves off frame.
22554 If you want scrolling to always be a line at a time, you should set
22555 `scroll-conservatively' to a large value rather than set this to 1. */);
22557 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22558 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22559 A value of zero means to scroll the text to center point vertically
22560 in the window. */);
22561 scroll_conservatively
= 0;
22563 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22564 doc
: /* *Number of lines of margin at the top and bottom of a window.
22565 Recenter the window whenever point gets within this many lines
22566 of the top or bottom of the window. */);
22569 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22570 doc
: /* Pixels per inch on current display.
22571 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22572 Vdisplay_pixels_per_inch
= make_float (72.0);
22575 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22578 DEFVAR_BOOL ("truncate-partial-width-windows",
22579 &truncate_partial_width_windows
,
22580 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22581 truncate_partial_width_windows
= 1;
22583 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22584 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22585 Any other value means to use the appropriate face, `mode-line',
22586 `header-line', or `menu' respectively. */);
22587 mode_line_inverse_video
= 1;
22589 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22590 doc
: /* *Maximum buffer size for which line number should be displayed.
22591 If the buffer is bigger than this, the line number does not appear
22592 in the mode line. A value of nil means no limit. */);
22593 Vline_number_display_limit
= Qnil
;
22595 DEFVAR_INT ("line-number-display-limit-width",
22596 &line_number_display_limit_width
,
22597 doc
: /* *Maximum line width (in characters) for line number display.
22598 If the average length of the lines near point is bigger than this, then the
22599 line number may be omitted from the mode line. */);
22600 line_number_display_limit_width
= 200;
22602 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22603 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22604 highlight_nonselected_windows
= 0;
22606 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22607 doc
: /* Non-nil if more than one frame is visible on this display.
22608 Minibuffer-only frames don't count, but iconified frames do.
22609 This variable is not guaranteed to be accurate except while processing
22610 `frame-title-format' and `icon-title-format'. */);
22612 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22613 doc
: /* Template for displaying the title bar of visible frames.
22614 \(Assuming the window manager supports this feature.)
22615 This variable has the same structure as `mode-line-format' (which see),
22616 and is used only on frames for which no explicit name has been set
22617 \(see `modify-frame-parameters'). */);
22619 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22620 doc
: /* Template for displaying the title bar of an iconified frame.
22621 \(Assuming the window manager supports this feature.)
22622 This variable has the same structure as `mode-line-format' (which see),
22623 and is used only on frames for which no explicit name has been set
22624 \(see `modify-frame-parameters'). */);
22626 = Vframe_title_format
22627 = Fcons (intern ("multiple-frames"),
22628 Fcons (build_string ("%b"),
22629 Fcons (Fcons (empty_string
,
22630 Fcons (intern ("invocation-name"),
22631 Fcons (build_string ("@"),
22632 Fcons (intern ("system-name"),
22636 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22637 doc
: /* Maximum number of lines to keep in the message log buffer.
22638 If nil, disable message logging. If t, log messages but don't truncate
22639 the buffer when it becomes large. */);
22640 Vmessage_log_max
= make_number (50);
22642 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22643 doc
: /* Functions called before redisplay, if window sizes have changed.
22644 The value should be a list of functions that take one argument.
22645 Just before redisplay, for each frame, if any of its windows have changed
22646 size since the last redisplay, or have been split or deleted,
22647 all the functions in the list are called, with the frame as argument. */);
22648 Vwindow_size_change_functions
= Qnil
;
22650 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22651 doc
: /* List of functions to call before redisplaying a window with scrolling.
22652 Each function is called with two arguments, the window
22653 and its new display-start position. Note that the value of `window-end'
22654 is not valid when these functions are called. */);
22655 Vwindow_scroll_functions
= Qnil
;
22657 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22658 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22659 mouse_autoselect_window
= 0;
22661 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22662 doc
: /* *Non-nil means automatically resize tool-bars.
22663 This increases a tool-bar's height if not all tool-bar items are visible.
22664 It decreases a tool-bar's height when it would display blank lines
22666 auto_resize_tool_bars_p
= 1;
22668 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22669 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22670 auto_raise_tool_bar_buttons_p
= 1;
22672 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
22673 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
22674 make_cursor_line_fully_visible_p
= 1;
22676 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22677 doc
: /* *Margin around tool-bar buttons in pixels.
22678 If an integer, use that for both horizontal and vertical margins.
22679 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22680 HORZ specifying the horizontal margin, and VERT specifying the
22681 vertical margin. */);
22682 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22684 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22685 doc
: /* *Relief thickness of tool-bar buttons. */);
22686 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22688 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22689 doc
: /* List of functions to call to fontify regions of text.
22690 Each function is called with one argument POS. Functions must
22691 fontify a region starting at POS in the current buffer, and give
22692 fontified regions the property `fontified'. */);
22693 Vfontification_functions
= Qnil
;
22694 Fmake_variable_buffer_local (Qfontification_functions
);
22696 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22697 &unibyte_display_via_language_environment
,
22698 doc
: /* *Non-nil means display unibyte text according to language environment.
22699 Specifically this means that unibyte non-ASCII characters
22700 are displayed by converting them to the equivalent multibyte characters
22701 according to the current language environment. As a result, they are
22702 displayed according to the current fontset. */);
22703 unibyte_display_via_language_environment
= 0;
22705 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22706 doc
: /* *Maximum height for resizing mini-windows.
22707 If a float, it specifies a fraction of the mini-window frame's height.
22708 If an integer, it specifies a number of lines. */);
22709 Vmax_mini_window_height
= make_float (0.25);
22711 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22712 doc
: /* *How to resize mini-windows.
22713 A value of nil means don't automatically resize mini-windows.
22714 A value of t means resize them to fit the text displayed in them.
22715 A value of `grow-only', the default, means let mini-windows grow
22716 only, until their display becomes empty, at which point the windows
22717 go back to their normal size. */);
22718 Vresize_mini_windows
= Qgrow_only
;
22720 DEFVAR_LISP ("cursor-in-non-selected-windows",
22721 &Vcursor_in_non_selected_windows
,
22722 doc
: /* *Cursor type to display in non-selected windows.
22723 t means to use hollow box cursor. See `cursor-type' for other values. */);
22724 Vcursor_in_non_selected_windows
= Qt
;
22726 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22727 doc
: /* Alist specifying how to blink the cursor off.
22728 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22729 `cursor-type' frame-parameter or variable equals ON-STATE,
22730 comparing using `equal', Emacs uses OFF-STATE to specify
22731 how to blink it off. */);
22732 Vblink_cursor_alist
= Qnil
;
22734 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22735 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22736 automatic_hscrolling_p
= 1;
22738 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22739 doc
: /* *How many columns away from the window edge point is allowed to get
22740 before automatic hscrolling will horizontally scroll the window. */);
22741 hscroll_margin
= 5;
22743 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22744 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22745 When point is less than `automatic-hscroll-margin' columns from the window
22746 edge, automatic hscrolling will scroll the window by the amount of columns
22747 determined by this variable. If its value is a positive integer, scroll that
22748 many columns. If it's a positive floating-point number, it specifies the
22749 fraction of the window's width to scroll. If it's nil or zero, point will be
22750 centered horizontally after the scroll. Any other value, including negative
22751 numbers, are treated as if the value were zero.
22753 Automatic hscrolling always moves point outside the scroll margin, so if
22754 point was more than scroll step columns inside the margin, the window will
22755 scroll more than the value given by the scroll step.
22757 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22758 and `scroll-right' overrides this variable's effect. */);
22759 Vhscroll_step
= make_number (0);
22761 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22762 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22763 Bind this around calls to `message' to let it take effect. */);
22764 message_truncate_lines
= 0;
22766 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22767 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22768 Can be used to update submenus whose contents should vary. */);
22769 Vmenu_bar_update_hook
= Qnil
;
22771 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22772 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22773 inhibit_menubar_update
= 0;
22775 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22776 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22777 inhibit_eval_during_redisplay
= 0;
22779 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22780 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22781 inhibit_free_realized_faces
= 0;
22784 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22785 doc
: /* Inhibit try_window_id display optimization. */);
22786 inhibit_try_window_id
= 0;
22788 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22789 doc
: /* Inhibit try_window_reusing display optimization. */);
22790 inhibit_try_window_reusing
= 0;
22792 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22793 doc
: /* Inhibit try_cursor_movement display optimization. */);
22794 inhibit_try_cursor_movement
= 0;
22795 #endif /* GLYPH_DEBUG */
22799 /* Initialize this module when Emacs starts. */
22804 Lisp_Object root_window
;
22805 struct window
*mini_w
;
22807 current_header_line_height
= current_mode_line_height
= -1;
22809 CHARPOS (this_line_start_pos
) = 0;
22811 mini_w
= XWINDOW (minibuf_window
);
22812 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22814 if (!noninteractive
)
22816 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22819 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22820 set_window_height (root_window
,
22821 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22823 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22824 set_window_height (minibuf_window
, 1, 0);
22826 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22827 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22829 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22830 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22831 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22833 /* The default ellipsis glyphs `...'. */
22834 for (i
= 0; i
< 3; ++i
)
22835 default_invis_vector
[i
] = make_number ('.');
22839 /* Allocate the buffer for frame titles.
22840 Also used for `format-mode-line'. */
22842 frame_title_buf
= (char *) xmalloc (size
);
22843 frame_title_buf_end
= frame_title_buf
+ size
;
22844 frame_title_ptr
= NULL
;
22847 help_echo_showing_p
= 0;
22851 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22852 (do not change this comment) */