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];
8090 /* Prevent redisplay optimization in redisplay_internal by resetting
8091 this_line_start_pos. This is done because the mini-buffer now
8092 displays the message instead of its buffer text. */
8093 if (EQ (mini_window
, selected_window
))
8094 CHARPOS (this_line_start_pos
) = 0;
8096 return window_height_changed_p
;
8101 /***********************************************************************
8103 ***********************************************************************/
8106 /* The frame title buffering code is also used by Fformat_mode_line.
8107 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
8109 /* A buffer for constructing frame titles in it; allocated from the
8110 heap in init_xdisp and resized as needed in store_frame_title_char. */
8112 static char *frame_title_buf
;
8114 /* The buffer's end, and a current output position in it. */
8116 static char *frame_title_buf_end
;
8117 static char *frame_title_ptr
;
8120 /* Store a single character C for the frame title in frame_title_buf.
8121 Re-allocate frame_title_buf if necessary. */
8125 store_frame_title_char (char c
)
8127 store_frame_title_char (c
)
8131 /* If output position has reached the end of the allocated buffer,
8132 double the buffer's size. */
8133 if (frame_title_ptr
== frame_title_buf_end
)
8135 int len
= frame_title_ptr
- frame_title_buf
;
8136 int new_size
= 2 * len
* sizeof *frame_title_buf
;
8137 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
8138 frame_title_buf_end
= frame_title_buf
+ new_size
;
8139 frame_title_ptr
= frame_title_buf
+ len
;
8142 *frame_title_ptr
++ = c
;
8146 /* Store part of a frame title in frame_title_buf, beginning at
8147 frame_title_ptr. STR is the string to store. Do not copy
8148 characters that yield more columns than PRECISION; PRECISION <= 0
8149 means copy the whole string. Pad with spaces until FIELD_WIDTH
8150 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8151 pad. Called from display_mode_element when it is used to build a
8155 store_frame_title (str
, field_width
, precision
)
8156 const unsigned char *str
;
8157 int field_width
, precision
;
8162 /* Copy at most PRECISION chars from STR. */
8163 nbytes
= strlen (str
);
8164 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8166 store_frame_title_char (*str
++);
8168 /* Fill up with spaces until FIELD_WIDTH reached. */
8169 while (field_width
> 0
8172 store_frame_title_char (' ');
8179 #ifdef HAVE_WINDOW_SYSTEM
8181 /* Set the title of FRAME, if it has changed. The title format is
8182 Vicon_title_format if FRAME is iconified, otherwise it is
8183 frame_title_format. */
8186 x_consider_frame_title (frame
)
8189 struct frame
*f
= XFRAME (frame
);
8191 if (FRAME_WINDOW_P (f
)
8192 || FRAME_MINIBUF_ONLY_P (f
)
8193 || f
->explicit_name
)
8195 /* Do we have more than one visible frame on this X display? */
8198 struct buffer
*obuf
;
8202 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8204 Lisp_Object other_frame
= XCAR (tail
);
8205 struct frame
*tf
= XFRAME (other_frame
);
8208 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8209 && !FRAME_MINIBUF_ONLY_P (tf
)
8210 && !EQ (other_frame
, tip_frame
)
8211 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8215 /* Set global variable indicating that multiple frames exist. */
8216 multiple_frames
= CONSP (tail
);
8218 /* Switch to the buffer of selected window of the frame. Set up
8219 frame_title_ptr so that display_mode_element will output into it;
8220 then display the title. */
8221 obuf
= current_buffer
;
8222 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8223 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8224 frame_title_ptr
= frame_title_buf
;
8225 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8226 NULL
, DEFAULT_FACE_ID
);
8227 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8228 len
= frame_title_ptr
- frame_title_buf
;
8229 frame_title_ptr
= NULL
;
8230 set_buffer_internal_1 (obuf
);
8232 /* Set the title only if it's changed. This avoids consing in
8233 the common case where it hasn't. (If it turns out that we've
8234 already wasted too much time by walking through the list with
8235 display_mode_element, then we might need to optimize at a
8236 higher level than this.) */
8237 if (! STRINGP (f
->name
)
8238 || SBYTES (f
->name
) != len
8239 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8240 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8244 #endif /* not HAVE_WINDOW_SYSTEM */
8249 /***********************************************************************
8251 ***********************************************************************/
8254 /* Prepare for redisplay by updating menu-bar item lists when
8255 appropriate. This can call eval. */
8258 prepare_menu_bars ()
8261 struct gcpro gcpro1
, gcpro2
;
8263 Lisp_Object tooltip_frame
;
8265 #ifdef HAVE_WINDOW_SYSTEM
8266 tooltip_frame
= tip_frame
;
8268 tooltip_frame
= Qnil
;
8271 /* Update all frame titles based on their buffer names, etc. We do
8272 this before the menu bars so that the buffer-menu will show the
8273 up-to-date frame titles. */
8274 #ifdef HAVE_WINDOW_SYSTEM
8275 if (windows_or_buffers_changed
|| update_mode_lines
)
8277 Lisp_Object tail
, frame
;
8279 FOR_EACH_FRAME (tail
, frame
)
8282 if (!EQ (frame
, tooltip_frame
)
8283 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8284 x_consider_frame_title (frame
);
8287 #endif /* HAVE_WINDOW_SYSTEM */
8289 /* Update the menu bar item lists, if appropriate. This has to be
8290 done before any actual redisplay or generation of display lines. */
8291 all_windows
= (update_mode_lines
8292 || buffer_shared
> 1
8293 || windows_or_buffers_changed
);
8296 Lisp_Object tail
, frame
;
8297 int count
= SPECPDL_INDEX ();
8299 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8301 FOR_EACH_FRAME (tail
, frame
)
8305 /* Ignore tooltip frame. */
8306 if (EQ (frame
, tooltip_frame
))
8309 /* If a window on this frame changed size, report that to
8310 the user and clear the size-change flag. */
8311 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8313 Lisp_Object functions
;
8315 /* Clear flag first in case we get an error below. */
8316 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8317 functions
= Vwindow_size_change_functions
;
8318 GCPRO2 (tail
, functions
);
8320 while (CONSP (functions
))
8322 call1 (XCAR (functions
), frame
);
8323 functions
= XCDR (functions
);
8329 update_menu_bar (f
, 0);
8330 #ifdef HAVE_WINDOW_SYSTEM
8331 update_tool_bar (f
, 0);
8336 unbind_to (count
, Qnil
);
8340 struct frame
*sf
= SELECTED_FRAME ();
8341 update_menu_bar (sf
, 1);
8342 #ifdef HAVE_WINDOW_SYSTEM
8343 update_tool_bar (sf
, 1);
8347 /* Motif needs this. See comment in xmenu.c. Turn it off when
8348 pending_menu_activation is not defined. */
8349 #ifdef USE_X_TOOLKIT
8350 pending_menu_activation
= 0;
8355 /* Update the menu bar item list for frame F. This has to be done
8356 before we start to fill in any display lines, because it can call
8359 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8362 update_menu_bar (f
, save_match_data
)
8364 int save_match_data
;
8367 register struct window
*w
;
8369 /* If called recursively during a menu update, do nothing. This can
8370 happen when, for instance, an activate-menubar-hook causes a
8372 if (inhibit_menubar_update
)
8375 window
= FRAME_SELECTED_WINDOW (f
);
8376 w
= XWINDOW (window
);
8378 #if 0 /* The if statement below this if statement used to include the
8379 condition !NILP (w->update_mode_line), rather than using
8380 update_mode_lines directly, and this if statement may have
8381 been added to make that condition work. Now the if
8382 statement below matches its comment, this isn't needed. */
8383 if (update_mode_lines
)
8384 w
->update_mode_line
= Qt
;
8387 if (FRAME_WINDOW_P (f
)
8389 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8390 || defined (USE_GTK)
8391 FRAME_EXTERNAL_MENU_BAR (f
)
8393 FRAME_MENU_BAR_LINES (f
) > 0
8395 : FRAME_MENU_BAR_LINES (f
) > 0)
8397 /* If the user has switched buffers or windows, we need to
8398 recompute to reflect the new bindings. But we'll
8399 recompute when update_mode_lines is set too; that means
8400 that people can use force-mode-line-update to request
8401 that the menu bar be recomputed. The adverse effect on
8402 the rest of the redisplay algorithm is about the same as
8403 windows_or_buffers_changed anyway. */
8404 if (windows_or_buffers_changed
8405 /* This used to test w->update_mode_line, but we believe
8406 there is no need to recompute the menu in that case. */
8407 || update_mode_lines
8408 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8409 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8410 != !NILP (w
->last_had_star
))
8411 || ((!NILP (Vtransient_mark_mode
)
8412 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8413 != !NILP (w
->region_showing
)))
8415 struct buffer
*prev
= current_buffer
;
8416 int count
= SPECPDL_INDEX ();
8418 specbind (Qinhibit_menubar_update
, Qt
);
8420 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8421 if (save_match_data
)
8422 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8423 if (NILP (Voverriding_local_map_menu_flag
))
8425 specbind (Qoverriding_terminal_local_map
, Qnil
);
8426 specbind (Qoverriding_local_map
, Qnil
);
8429 /* Run the Lucid hook. */
8430 safe_run_hooks (Qactivate_menubar_hook
);
8432 /* If it has changed current-menubar from previous value,
8433 really recompute the menu-bar from the value. */
8434 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8435 call0 (Qrecompute_lucid_menubar
);
8437 safe_run_hooks (Qmenu_bar_update_hook
);
8438 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8440 /* Redisplay the menu bar in case we changed it. */
8441 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8442 || defined (USE_GTK)
8443 if (FRAME_WINDOW_P (f
)
8444 #if defined (MAC_OS)
8445 /* All frames on Mac OS share the same menubar. So only the
8446 selected frame should be allowed to set it. */
8447 && f
== SELECTED_FRAME ()
8450 set_frame_menubar (f
, 0, 0);
8452 /* On a terminal screen, the menu bar is an ordinary screen
8453 line, and this makes it get updated. */
8454 w
->update_mode_line
= Qt
;
8455 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8456 /* In the non-toolkit version, the menu bar is an ordinary screen
8457 line, and this makes it get updated. */
8458 w
->update_mode_line
= Qt
;
8459 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8461 unbind_to (count
, Qnil
);
8462 set_buffer_internal_1 (prev
);
8469 /***********************************************************************
8471 ***********************************************************************/
8473 #ifdef HAVE_WINDOW_SYSTEM
8476 Nominal cursor position -- where to draw output.
8477 HPOS and VPOS are window relative glyph matrix coordinates.
8478 X and Y are window relative pixel coordinates. */
8480 struct cursor_pos output_cursor
;
8484 Set the global variable output_cursor to CURSOR. All cursor
8485 positions are relative to updated_window. */
8488 set_output_cursor (cursor
)
8489 struct cursor_pos
*cursor
;
8491 output_cursor
.hpos
= cursor
->hpos
;
8492 output_cursor
.vpos
= cursor
->vpos
;
8493 output_cursor
.x
= cursor
->x
;
8494 output_cursor
.y
= cursor
->y
;
8499 Set a nominal cursor position.
8501 HPOS and VPOS are column/row positions in a window glyph matrix. X
8502 and Y are window text area relative pixel positions.
8504 If this is done during an update, updated_window will contain the
8505 window that is being updated and the position is the future output
8506 cursor position for that window. If updated_window is null, use
8507 selected_window and display the cursor at the given position. */
8510 x_cursor_to (vpos
, hpos
, y
, x
)
8511 int vpos
, hpos
, y
, x
;
8515 /* If updated_window is not set, work on selected_window. */
8519 w
= XWINDOW (selected_window
);
8521 /* Set the output cursor. */
8522 output_cursor
.hpos
= hpos
;
8523 output_cursor
.vpos
= vpos
;
8524 output_cursor
.x
= x
;
8525 output_cursor
.y
= y
;
8527 /* If not called as part of an update, really display the cursor.
8528 This will also set the cursor position of W. */
8529 if (updated_window
== NULL
)
8532 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8533 if (rif
->flush_display_optional
)
8534 rif
->flush_display_optional (SELECTED_FRAME ());
8539 #endif /* HAVE_WINDOW_SYSTEM */
8542 /***********************************************************************
8544 ***********************************************************************/
8546 #ifdef HAVE_WINDOW_SYSTEM
8548 /* Where the mouse was last time we reported a mouse event. */
8550 FRAME_PTR last_mouse_frame
;
8552 /* Tool-bar item index of the item on which a mouse button was pressed
8555 int last_tool_bar_item
;
8558 /* Update the tool-bar item list for frame F. This has to be done
8559 before we start to fill in any display lines. Called from
8560 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8561 and restore it here. */
8564 update_tool_bar (f
, save_match_data
)
8566 int save_match_data
;
8569 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8571 int do_update
= WINDOWP (f
->tool_bar_window
)
8572 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8580 window
= FRAME_SELECTED_WINDOW (f
);
8581 w
= XWINDOW (window
);
8583 /* If the user has switched buffers or windows, we need to
8584 recompute to reflect the new bindings. But we'll
8585 recompute when update_mode_lines is set too; that means
8586 that people can use force-mode-line-update to request
8587 that the menu bar be recomputed. The adverse effect on
8588 the rest of the redisplay algorithm is about the same as
8589 windows_or_buffers_changed anyway. */
8590 if (windows_or_buffers_changed
8591 || !NILP (w
->update_mode_line
)
8592 || update_mode_lines
8593 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8594 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8595 != !NILP (w
->last_had_star
))
8596 || ((!NILP (Vtransient_mark_mode
)
8597 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8598 != !NILP (w
->region_showing
)))
8600 struct buffer
*prev
= current_buffer
;
8601 int count
= SPECPDL_INDEX ();
8602 Lisp_Object new_tool_bar
;
8604 struct gcpro gcpro1
;
8606 /* Set current_buffer to the buffer of the selected
8607 window of the frame, so that we get the right local
8609 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8611 /* Save match data, if we must. */
8612 if (save_match_data
)
8613 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8615 /* Make sure that we don't accidentally use bogus keymaps. */
8616 if (NILP (Voverriding_local_map_menu_flag
))
8618 specbind (Qoverriding_terminal_local_map
, Qnil
);
8619 specbind (Qoverriding_local_map
, Qnil
);
8622 GCPRO1 (new_tool_bar
);
8624 /* Build desired tool-bar items from keymaps. */
8625 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8628 /* Redisplay the tool-bar if we changed it. */
8629 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8631 /* Redisplay that happens asynchronously due to an expose event
8632 may access f->tool_bar_items. Make sure we update both
8633 variables within BLOCK_INPUT so no such event interrupts. */
8635 f
->tool_bar_items
= new_tool_bar
;
8636 f
->n_tool_bar_items
= new_n_tool_bar
;
8637 w
->update_mode_line
= Qt
;
8643 unbind_to (count
, Qnil
);
8644 set_buffer_internal_1 (prev
);
8650 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8651 F's desired tool-bar contents. F->tool_bar_items must have
8652 been set up previously by calling prepare_menu_bars. */
8655 build_desired_tool_bar_string (f
)
8658 int i
, size
, size_needed
;
8659 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8660 Lisp_Object image
, plist
, props
;
8662 image
= plist
= props
= Qnil
;
8663 GCPRO3 (image
, plist
, props
);
8665 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8666 Otherwise, make a new string. */
8668 /* The size of the string we might be able to reuse. */
8669 size
= (STRINGP (f
->desired_tool_bar_string
)
8670 ? SCHARS (f
->desired_tool_bar_string
)
8673 /* We need one space in the string for each image. */
8674 size_needed
= f
->n_tool_bar_items
;
8676 /* Reuse f->desired_tool_bar_string, if possible. */
8677 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8678 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8682 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8683 Fremove_text_properties (make_number (0), make_number (size
),
8684 props
, f
->desired_tool_bar_string
);
8687 /* Put a `display' property on the string for the images to display,
8688 put a `menu_item' property on tool-bar items with a value that
8689 is the index of the item in F's tool-bar item vector. */
8690 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8692 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8694 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8695 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8696 int hmargin
, vmargin
, relief
, idx
, end
;
8697 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8699 /* If image is a vector, choose the image according to the
8701 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8702 if (VECTORP (image
))
8706 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8707 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8710 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8711 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8713 xassert (ASIZE (image
) >= idx
);
8714 image
= AREF (image
, idx
);
8719 /* Ignore invalid image specifications. */
8720 if (!valid_image_p (image
))
8723 /* Display the tool-bar button pressed, or depressed. */
8724 plist
= Fcopy_sequence (XCDR (image
));
8726 /* Compute margin and relief to draw. */
8727 relief
= (tool_bar_button_relief
>= 0
8728 ? tool_bar_button_relief
8729 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8730 hmargin
= vmargin
= relief
;
8732 if (INTEGERP (Vtool_bar_button_margin
)
8733 && XINT (Vtool_bar_button_margin
) > 0)
8735 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8736 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8738 else if (CONSP (Vtool_bar_button_margin
))
8740 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8741 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8742 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8744 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8745 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8746 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8749 if (auto_raise_tool_bar_buttons_p
)
8751 /* Add a `:relief' property to the image spec if the item is
8755 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8762 /* If image is selected, display it pressed, i.e. with a
8763 negative relief. If it's not selected, display it with a
8765 plist
= Fplist_put (plist
, QCrelief
,
8767 ? make_number (-relief
)
8768 : make_number (relief
)));
8773 /* Put a margin around the image. */
8774 if (hmargin
|| vmargin
)
8776 if (hmargin
== vmargin
)
8777 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8779 plist
= Fplist_put (plist
, QCmargin
,
8780 Fcons (make_number (hmargin
),
8781 make_number (vmargin
)));
8784 /* If button is not enabled, and we don't have special images
8785 for the disabled state, make the image appear disabled by
8786 applying an appropriate algorithm to it. */
8787 if (!enabled_p
&& idx
< 0)
8788 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8790 /* Put a `display' text property on the string for the image to
8791 display. Put a `menu-item' property on the string that gives
8792 the start of this item's properties in the tool-bar items
8794 image
= Fcons (Qimage
, plist
);
8795 props
= list4 (Qdisplay
, image
,
8796 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8798 /* Let the last image hide all remaining spaces in the tool bar
8799 string. The string can be longer than needed when we reuse a
8801 if (i
+ 1 == f
->n_tool_bar_items
)
8802 end
= SCHARS (f
->desired_tool_bar_string
);
8805 Fadd_text_properties (make_number (i
), make_number (end
),
8806 props
, f
->desired_tool_bar_string
);
8814 /* Display one line of the tool-bar of frame IT->f. */
8817 display_tool_bar_line (it
)
8820 struct glyph_row
*row
= it
->glyph_row
;
8821 int max_x
= it
->last_visible_x
;
8824 prepare_desired_row (row
);
8825 row
->y
= it
->current_y
;
8827 /* Note that this isn't made use of if the face hasn't a box,
8828 so there's no need to check the face here. */
8829 it
->start_of_box_run_p
= 1;
8831 while (it
->current_x
< max_x
)
8833 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8835 /* Get the next display element. */
8836 if (!get_next_display_element (it
))
8839 /* Produce glyphs. */
8840 x_before
= it
->current_x
;
8841 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8842 PRODUCE_GLYPHS (it
);
8844 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8849 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8851 if (x
+ glyph
->pixel_width
> max_x
)
8853 /* Glyph doesn't fit on line. */
8854 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8860 x
+= glyph
->pixel_width
;
8864 /* Stop at line ends. */
8865 if (ITERATOR_AT_END_OF_LINE_P (it
))
8868 set_iterator_to_next (it
, 1);
8873 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8874 extend_face_to_end_of_line (it
);
8875 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8876 last
->right_box_line_p
= 1;
8877 if (last
== row
->glyphs
[TEXT_AREA
])
8878 last
->left_box_line_p
= 1;
8879 compute_line_metrics (it
);
8881 /* If line is empty, make it occupy the rest of the tool-bar. */
8882 if (!row
->displays_text_p
)
8884 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8885 row
->ascent
= row
->phys_ascent
= 0;
8886 row
->extra_line_spacing
= 0;
8889 row
->full_width_p
= 1;
8890 row
->continued_p
= 0;
8891 row
->truncated_on_left_p
= 0;
8892 row
->truncated_on_right_p
= 0;
8894 it
->current_x
= it
->hpos
= 0;
8895 it
->current_y
+= row
->height
;
8901 /* Value is the number of screen lines needed to make all tool-bar
8902 items of frame F visible. */
8905 tool_bar_lines_needed (f
)
8908 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8911 /* Initialize an iterator for iteration over
8912 F->desired_tool_bar_string in the tool-bar window of frame F. */
8913 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8914 it
.first_visible_x
= 0;
8915 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8916 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8918 while (!ITERATOR_AT_END_P (&it
))
8920 it
.glyph_row
= w
->desired_matrix
->rows
;
8921 clear_glyph_row (it
.glyph_row
);
8922 display_tool_bar_line (&it
);
8925 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8929 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8931 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8940 frame
= selected_frame
;
8942 CHECK_FRAME (frame
);
8945 if (WINDOWP (f
->tool_bar_window
)
8946 || (w
= XWINDOW (f
->tool_bar_window
),
8947 WINDOW_TOTAL_LINES (w
) > 0))
8949 update_tool_bar (f
, 1);
8950 if (f
->n_tool_bar_items
)
8952 build_desired_tool_bar_string (f
);
8953 nlines
= tool_bar_lines_needed (f
);
8957 return make_number (nlines
);
8961 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8962 height should be changed. */
8965 redisplay_tool_bar (f
)
8970 struct glyph_row
*row
;
8971 int change_height_p
= 0;
8974 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8975 update_frame_tool_bar (f
);
8979 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8980 do anything. This means you must start with tool-bar-lines
8981 non-zero to get the auto-sizing effect. Or in other words, you
8982 can turn off tool-bars by specifying tool-bar-lines zero. */
8983 if (!WINDOWP (f
->tool_bar_window
)
8984 || (w
= XWINDOW (f
->tool_bar_window
),
8985 WINDOW_TOTAL_LINES (w
) == 0))
8988 /* Set up an iterator for the tool-bar window. */
8989 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8990 it
.first_visible_x
= 0;
8991 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8994 /* Build a string that represents the contents of the tool-bar. */
8995 build_desired_tool_bar_string (f
);
8996 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8998 /* Display as many lines as needed to display all tool-bar items. */
8999 while (it
.current_y
< it
.last_visible_y
)
9000 display_tool_bar_line (&it
);
9002 /* It doesn't make much sense to try scrolling in the tool-bar
9003 window, so don't do it. */
9004 w
->desired_matrix
->no_scrolling_p
= 1;
9005 w
->must_be_updated_p
= 1;
9007 if (auto_resize_tool_bars_p
)
9011 /* If we couldn't display everything, change the tool-bar's
9013 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9014 change_height_p
= 1;
9016 /* If there are blank lines at the end, except for a partially
9017 visible blank line at the end that is smaller than
9018 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9019 row
= it
.glyph_row
- 1;
9020 if (!row
->displays_text_p
9021 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9022 change_height_p
= 1;
9024 /* If row displays tool-bar items, but is partially visible,
9025 change the tool-bar's height. */
9026 if (row
->displays_text_p
9027 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9028 change_height_p
= 1;
9030 /* Resize windows as needed by changing the `tool-bar-lines'
9033 && (nlines
= tool_bar_lines_needed (f
),
9034 nlines
!= WINDOW_TOTAL_LINES (w
)))
9036 extern Lisp_Object Qtool_bar_lines
;
9038 int old_height
= WINDOW_TOTAL_LINES (w
);
9040 XSETFRAME (frame
, f
);
9041 clear_glyph_matrix (w
->desired_matrix
);
9042 Fmodify_frame_parameters (frame
,
9043 Fcons (Fcons (Qtool_bar_lines
,
9044 make_number (nlines
)),
9046 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9047 fonts_changed_p
= 1;
9051 return change_height_p
;
9055 /* Get information about the tool-bar item which is displayed in GLYPH
9056 on frame F. Return in *PROP_IDX the index where tool-bar item
9057 properties start in F->tool_bar_items. Value is zero if
9058 GLYPH doesn't display a tool-bar item. */
9061 tool_bar_item_info (f
, glyph
, prop_idx
)
9063 struct glyph
*glyph
;
9070 /* This function can be called asynchronously, which means we must
9071 exclude any possibility that Fget_text_property signals an
9073 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9074 charpos
= max (0, charpos
);
9076 /* Get the text property `menu-item' at pos. The value of that
9077 property is the start index of this item's properties in
9078 F->tool_bar_items. */
9079 prop
= Fget_text_property (make_number (charpos
),
9080 Qmenu_item
, f
->current_tool_bar_string
);
9081 if (INTEGERP (prop
))
9083 *prop_idx
= XINT (prop
);
9093 /* Get information about the tool-bar item at position X/Y on frame F.
9094 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9095 the current matrix of the tool-bar window of F, or NULL if not
9096 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9097 item in F->tool_bar_items. Value is
9099 -1 if X/Y is not on a tool-bar item
9100 0 if X/Y is on the same item that was highlighted before.
9104 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9107 struct glyph
**glyph
;
9108 int *hpos
, *vpos
, *prop_idx
;
9110 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9111 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9114 /* Find the glyph under X/Y. */
9115 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9119 /* Get the start of this tool-bar item's properties in
9120 f->tool_bar_items. */
9121 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9124 /* Is mouse on the highlighted item? */
9125 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9126 && *vpos
>= dpyinfo
->mouse_face_beg_row
9127 && *vpos
<= dpyinfo
->mouse_face_end_row
9128 && (*vpos
> dpyinfo
->mouse_face_beg_row
9129 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9130 && (*vpos
< dpyinfo
->mouse_face_end_row
9131 || *hpos
< dpyinfo
->mouse_face_end_col
9132 || dpyinfo
->mouse_face_past_end
))
9140 Handle mouse button event on the tool-bar of frame F, at
9141 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9142 0 for button release. MODIFIERS is event modifiers for button
9146 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9149 unsigned int modifiers
;
9151 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9152 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9153 int hpos
, vpos
, prop_idx
;
9154 struct glyph
*glyph
;
9155 Lisp_Object enabled_p
;
9157 /* If not on the highlighted tool-bar item, return. */
9158 frame_to_window_pixel_xy (w
, &x
, &y
);
9159 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9162 /* If item is disabled, do nothing. */
9163 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9164 if (NILP (enabled_p
))
9169 /* Show item in pressed state. */
9170 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9171 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9172 last_tool_bar_item
= prop_idx
;
9176 Lisp_Object key
, frame
;
9177 struct input_event event
;
9180 /* Show item in released state. */
9181 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9182 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9184 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9186 XSETFRAME (frame
, f
);
9187 event
.kind
= TOOL_BAR_EVENT
;
9188 event
.frame_or_window
= frame
;
9190 kbd_buffer_store_event (&event
);
9192 event
.kind
= TOOL_BAR_EVENT
;
9193 event
.frame_or_window
= frame
;
9195 event
.modifiers
= modifiers
;
9196 kbd_buffer_store_event (&event
);
9197 last_tool_bar_item
= -1;
9202 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9203 tool-bar window-relative coordinates X/Y. Called from
9204 note_mouse_highlight. */
9207 note_tool_bar_highlight (f
, x
, y
)
9211 Lisp_Object window
= f
->tool_bar_window
;
9212 struct window
*w
= XWINDOW (window
);
9213 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9215 struct glyph
*glyph
;
9216 struct glyph_row
*row
;
9218 Lisp_Object enabled_p
;
9220 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9221 int mouse_down_p
, rc
;
9223 /* Function note_mouse_highlight is called with negative x(y
9224 values when mouse moves outside of the frame. */
9225 if (x
<= 0 || y
<= 0)
9227 clear_mouse_face (dpyinfo
);
9231 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9234 /* Not on tool-bar item. */
9235 clear_mouse_face (dpyinfo
);
9239 /* On same tool-bar item as before. */
9242 clear_mouse_face (dpyinfo
);
9244 /* Mouse is down, but on different tool-bar item? */
9245 mouse_down_p
= (dpyinfo
->grabbed
9246 && f
== last_mouse_frame
9247 && FRAME_LIVE_P (f
));
9249 && last_tool_bar_item
!= prop_idx
)
9252 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9253 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9255 /* If tool-bar item is not enabled, don't highlight it. */
9256 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9257 if (!NILP (enabled_p
))
9259 /* Compute the x-position of the glyph. In front and past the
9260 image is a space. We include this in the highlighted area. */
9261 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9262 for (i
= x
= 0; i
< hpos
; ++i
)
9263 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9265 /* Record this as the current active region. */
9266 dpyinfo
->mouse_face_beg_col
= hpos
;
9267 dpyinfo
->mouse_face_beg_row
= vpos
;
9268 dpyinfo
->mouse_face_beg_x
= x
;
9269 dpyinfo
->mouse_face_beg_y
= row
->y
;
9270 dpyinfo
->mouse_face_past_end
= 0;
9272 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9273 dpyinfo
->mouse_face_end_row
= vpos
;
9274 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9275 dpyinfo
->mouse_face_end_y
= row
->y
;
9276 dpyinfo
->mouse_face_window
= window
;
9277 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9279 /* Display it as active. */
9280 show_mouse_face (dpyinfo
, draw
);
9281 dpyinfo
->mouse_face_image_state
= draw
;
9286 /* Set help_echo_string to a help string to display for this tool-bar item.
9287 XTread_socket does the rest. */
9288 help_echo_object
= help_echo_window
= Qnil
;
9290 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9291 if (NILP (help_echo_string
))
9292 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9295 #endif /* HAVE_WINDOW_SYSTEM */
9299 /************************************************************************
9300 Horizontal scrolling
9301 ************************************************************************/
9303 static int hscroll_window_tree
P_ ((Lisp_Object
));
9304 static int hscroll_windows
P_ ((Lisp_Object
));
9306 /* For all leaf windows in the window tree rooted at WINDOW, set their
9307 hscroll value so that PT is (i) visible in the window, and (ii) so
9308 that it is not within a certain margin at the window's left and
9309 right border. Value is non-zero if any window's hscroll has been
9313 hscroll_window_tree (window
)
9316 int hscrolled_p
= 0;
9317 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9318 int hscroll_step_abs
= 0;
9319 double hscroll_step_rel
= 0;
9321 if (hscroll_relative_p
)
9323 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9324 if (hscroll_step_rel
< 0)
9326 hscroll_relative_p
= 0;
9327 hscroll_step_abs
= 0;
9330 else if (INTEGERP (Vhscroll_step
))
9332 hscroll_step_abs
= XINT (Vhscroll_step
);
9333 if (hscroll_step_abs
< 0)
9334 hscroll_step_abs
= 0;
9337 hscroll_step_abs
= 0;
9339 while (WINDOWP (window
))
9341 struct window
*w
= XWINDOW (window
);
9343 if (WINDOWP (w
->hchild
))
9344 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9345 else if (WINDOWP (w
->vchild
))
9346 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9347 else if (w
->cursor
.vpos
>= 0)
9350 int text_area_width
;
9351 struct glyph_row
*current_cursor_row
9352 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9353 struct glyph_row
*desired_cursor_row
9354 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9355 struct glyph_row
*cursor_row
9356 = (desired_cursor_row
->enabled_p
9357 ? desired_cursor_row
9358 : current_cursor_row
);
9360 text_area_width
= window_box_width (w
, TEXT_AREA
);
9362 /* Scroll when cursor is inside this scroll margin. */
9363 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9365 if ((XFASTINT (w
->hscroll
)
9366 && w
->cursor
.x
<= h_margin
)
9367 || (cursor_row
->enabled_p
9368 && cursor_row
->truncated_on_right_p
9369 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9373 struct buffer
*saved_current_buffer
;
9377 /* Find point in a display of infinite width. */
9378 saved_current_buffer
= current_buffer
;
9379 current_buffer
= XBUFFER (w
->buffer
);
9381 if (w
== XWINDOW (selected_window
))
9382 pt
= BUF_PT (current_buffer
);
9385 pt
= marker_position (w
->pointm
);
9386 pt
= max (BEGV
, pt
);
9390 /* Move iterator to pt starting at cursor_row->start in
9391 a line with infinite width. */
9392 init_to_row_start (&it
, w
, cursor_row
);
9393 it
.last_visible_x
= INFINITY
;
9394 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9395 current_buffer
= saved_current_buffer
;
9397 /* Position cursor in window. */
9398 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9399 hscroll
= max (0, (it
.current_x
9400 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9401 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9402 : (text_area_width
/ 2))))
9403 / FRAME_COLUMN_WIDTH (it
.f
);
9404 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9406 if (hscroll_relative_p
)
9407 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9410 wanted_x
= text_area_width
9411 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9414 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9418 if (hscroll_relative_p
)
9419 wanted_x
= text_area_width
* hscroll_step_rel
9422 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9425 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9427 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9429 /* Don't call Fset_window_hscroll if value hasn't
9430 changed because it will prevent redisplay
9432 if (XFASTINT (w
->hscroll
) != hscroll
)
9434 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9435 w
->hscroll
= make_number (hscroll
);
9444 /* Value is non-zero if hscroll of any leaf window has been changed. */
9449 /* Set hscroll so that cursor is visible and not inside horizontal
9450 scroll margins for all windows in the tree rooted at WINDOW. See
9451 also hscroll_window_tree above. Value is non-zero if any window's
9452 hscroll has been changed. If it has, desired matrices on the frame
9453 of WINDOW are cleared. */
9456 hscroll_windows (window
)
9461 if (automatic_hscrolling_p
)
9463 hscrolled_p
= hscroll_window_tree (window
);
9465 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9474 /************************************************************************
9476 ************************************************************************/
9478 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9479 to a non-zero value. This is sometimes handy to have in a debugger
9484 /* First and last unchanged row for try_window_id. */
9486 int debug_first_unchanged_at_end_vpos
;
9487 int debug_last_unchanged_at_beg_vpos
;
9489 /* Delta vpos and y. */
9491 int debug_dvpos
, debug_dy
;
9493 /* Delta in characters and bytes for try_window_id. */
9495 int debug_delta
, debug_delta_bytes
;
9497 /* Values of window_end_pos and window_end_vpos at the end of
9500 EMACS_INT debug_end_pos
, debug_end_vpos
;
9502 /* Append a string to W->desired_matrix->method. FMT is a printf
9503 format string. A1...A9 are a supplement for a variable-length
9504 argument list. If trace_redisplay_p is non-zero also printf the
9505 resulting string to stderr. */
9508 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9511 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9514 char *method
= w
->desired_matrix
->method
;
9515 int len
= strlen (method
);
9516 int size
= sizeof w
->desired_matrix
->method
;
9517 int remaining
= size
- len
- 1;
9519 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9520 if (len
&& remaining
)
9526 strncpy (method
+ len
, buffer
, remaining
);
9528 if (trace_redisplay_p
)
9529 fprintf (stderr
, "%p (%s): %s\n",
9531 ((BUFFERP (w
->buffer
)
9532 && STRINGP (XBUFFER (w
->buffer
)->name
))
9533 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9538 #endif /* GLYPH_DEBUG */
9541 /* Value is non-zero if all changes in window W, which displays
9542 current_buffer, are in the text between START and END. START is a
9543 buffer position, END is given as a distance from Z. Used in
9544 redisplay_internal for display optimization. */
9547 text_outside_line_unchanged_p (w
, start
, end
)
9551 int unchanged_p
= 1;
9553 /* If text or overlays have changed, see where. */
9554 if (XFASTINT (w
->last_modified
) < MODIFF
9555 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9557 /* Gap in the line? */
9558 if (GPT
< start
|| Z
- GPT
< end
)
9561 /* Changes start in front of the line, or end after it? */
9563 && (BEG_UNCHANGED
< start
- 1
9564 || END_UNCHANGED
< end
))
9567 /* If selective display, can't optimize if changes start at the
9568 beginning of the line. */
9570 && INTEGERP (current_buffer
->selective_display
)
9571 && XINT (current_buffer
->selective_display
) > 0
9572 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9575 /* If there are overlays at the start or end of the line, these
9576 may have overlay strings with newlines in them. A change at
9577 START, for instance, may actually concern the display of such
9578 overlay strings as well, and they are displayed on different
9579 lines. So, quickly rule out this case. (For the future, it
9580 might be desirable to implement something more telling than
9581 just BEG/END_UNCHANGED.) */
9584 if (BEG
+ BEG_UNCHANGED
== start
9585 && overlay_touches_p (start
))
9587 if (END_UNCHANGED
== end
9588 && overlay_touches_p (Z
- end
))
9597 /* Do a frame update, taking possible shortcuts into account. This is
9598 the main external entry point for redisplay.
9600 If the last redisplay displayed an echo area message and that message
9601 is no longer requested, we clear the echo area or bring back the
9602 mini-buffer if that is in use. */
9607 redisplay_internal (0);
9612 overlay_arrow_string_or_property (var
, pbitmap
)
9616 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9622 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9623 *pbitmap
= XINT (bitmap
);
9628 return Voverlay_arrow_string
;
9631 /* Return 1 if there are any overlay-arrows in current_buffer. */
9633 overlay_arrow_in_current_buffer_p ()
9637 for (vlist
= Voverlay_arrow_variable_list
;
9639 vlist
= XCDR (vlist
))
9641 Lisp_Object var
= XCAR (vlist
);
9646 val
= find_symbol_value (var
);
9648 && current_buffer
== XMARKER (val
)->buffer
)
9655 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9659 overlay_arrows_changed_p ()
9663 for (vlist
= Voverlay_arrow_variable_list
;
9665 vlist
= XCDR (vlist
))
9667 Lisp_Object var
= XCAR (vlist
);
9668 Lisp_Object val
, pstr
;
9672 val
= find_symbol_value (var
);
9675 if (! EQ (COERCE_MARKER (val
),
9676 Fget (var
, Qlast_arrow_position
))
9677 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9678 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9684 /* Mark overlay arrows to be updated on next redisplay. */
9687 update_overlay_arrows (up_to_date
)
9692 for (vlist
= Voverlay_arrow_variable_list
;
9694 vlist
= XCDR (vlist
))
9696 Lisp_Object var
= XCAR (vlist
);
9703 Lisp_Object val
= find_symbol_value (var
);
9704 Fput (var
, Qlast_arrow_position
,
9705 COERCE_MARKER (val
));
9706 Fput (var
, Qlast_arrow_string
,
9707 overlay_arrow_string_or_property (var
, 0));
9709 else if (up_to_date
< 0
9710 || !NILP (Fget (var
, Qlast_arrow_position
)))
9712 Fput (var
, Qlast_arrow_position
, Qt
);
9713 Fput (var
, Qlast_arrow_string
, Qt
);
9719 /* Return overlay arrow string to display at row.
9720 Return t if display as bitmap in left fringe.
9721 Return nil if no overlay arrow. */
9724 overlay_arrow_at_row (it
, row
, pbitmap
)
9726 struct glyph_row
*row
;
9731 for (vlist
= Voverlay_arrow_variable_list
;
9733 vlist
= XCDR (vlist
))
9735 Lisp_Object var
= XCAR (vlist
);
9741 val
= find_symbol_value (var
);
9744 && current_buffer
== XMARKER (val
)->buffer
9745 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9747 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9748 if (FRAME_WINDOW_P (it
->f
)
9749 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9761 /* Return 1 if point moved out of or into a composition. Otherwise
9762 return 0. PREV_BUF and PREV_PT are the last point buffer and
9763 position. BUF and PT are the current point buffer and position. */
9766 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9767 struct buffer
*prev_buf
, *buf
;
9774 XSETBUFFER (buffer
, buf
);
9775 /* Check a composition at the last point if point moved within the
9777 if (prev_buf
== buf
)
9780 /* Point didn't move. */
9783 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9784 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9785 && COMPOSITION_VALID_P (start
, end
, prop
)
9786 && start
< prev_pt
&& end
> prev_pt
)
9787 /* The last point was within the composition. Return 1 iff
9788 point moved out of the composition. */
9789 return (pt
<= start
|| pt
>= end
);
9792 /* Check a composition at the current point. */
9793 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9794 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9795 && COMPOSITION_VALID_P (start
, end
, prop
)
9796 && start
< pt
&& end
> pt
);
9800 /* Reconsider the setting of B->clip_changed which is displayed
9804 reconsider_clip_changes (w
, b
)
9809 && !NILP (w
->window_end_valid
)
9810 && w
->current_matrix
->buffer
== b
9811 && w
->current_matrix
->zv
== BUF_ZV (b
)
9812 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9813 b
->clip_changed
= 0;
9815 /* If display wasn't paused, and W is not a tool bar window, see if
9816 point has been moved into or out of a composition. In that case,
9817 we set b->clip_changed to 1 to force updating the screen. If
9818 b->clip_changed has already been set to 1, we can skip this
9820 if (!b
->clip_changed
9821 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9825 if (w
== XWINDOW (selected_window
))
9826 pt
= BUF_PT (current_buffer
);
9828 pt
= marker_position (w
->pointm
);
9830 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9831 || pt
!= XINT (w
->last_point
))
9832 && check_point_in_composition (w
->current_matrix
->buffer
,
9833 XINT (w
->last_point
),
9834 XBUFFER (w
->buffer
), pt
))
9835 b
->clip_changed
= 1;
9840 /* Select FRAME to forward the values of frame-local variables into C
9841 variables so that the redisplay routines can access those values
9845 select_frame_for_redisplay (frame
)
9848 Lisp_Object tail
, sym
, val
;
9849 Lisp_Object old
= selected_frame
;
9851 selected_frame
= frame
;
9853 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9854 if (CONSP (XCAR (tail
))
9855 && (sym
= XCAR (XCAR (tail
)),
9857 && (sym
= indirect_variable (sym
),
9858 val
= SYMBOL_VALUE (sym
),
9859 (BUFFER_LOCAL_VALUEP (val
)
9860 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9861 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9862 Fsymbol_value (sym
);
9864 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9865 if (CONSP (XCAR (tail
))
9866 && (sym
= XCAR (XCAR (tail
)),
9868 && (sym
= indirect_variable (sym
),
9869 val
= SYMBOL_VALUE (sym
),
9870 (BUFFER_LOCAL_VALUEP (val
)
9871 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9872 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9873 Fsymbol_value (sym
);
9877 #define STOP_POLLING \
9878 do { if (! polling_stopped_here) stop_polling (); \
9879 polling_stopped_here = 1; } while (0)
9881 #define RESUME_POLLING \
9882 do { if (polling_stopped_here) start_polling (); \
9883 polling_stopped_here = 0; } while (0)
9886 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9887 response to any user action; therefore, we should preserve the echo
9888 area. (Actually, our caller does that job.) Perhaps in the future
9889 avoid recentering windows if it is not necessary; currently that
9890 causes some problems. */
9893 redisplay_internal (preserve_echo_area
)
9894 int preserve_echo_area
;
9896 struct window
*w
= XWINDOW (selected_window
);
9897 struct frame
*f
= XFRAME (w
->frame
);
9899 int must_finish
= 0;
9900 struct text_pos tlbufpos
, tlendpos
;
9901 int number_of_visible_frames
;
9903 struct frame
*sf
= SELECTED_FRAME ();
9904 int polling_stopped_here
= 0;
9906 /* Non-zero means redisplay has to consider all windows on all
9907 frames. Zero means, only selected_window is considered. */
9908 int consider_all_windows_p
;
9910 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9912 /* No redisplay if running in batch mode or frame is not yet fully
9913 initialized, or redisplay is explicitly turned off by setting
9914 Vinhibit_redisplay. */
9916 || !NILP (Vinhibit_redisplay
)
9917 || !f
->glyphs_initialized_p
)
9920 /* The flag redisplay_performed_directly_p is set by
9921 direct_output_for_insert when it already did the whole screen
9922 update necessary. */
9923 if (redisplay_performed_directly_p
)
9925 redisplay_performed_directly_p
= 0;
9926 if (!hscroll_windows (selected_window
))
9930 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9931 if (popup_activated ())
9935 /* I don't think this happens but let's be paranoid. */
9939 /* Record a function that resets redisplaying_p to its old value
9940 when we leave this function. */
9941 count
= SPECPDL_INDEX ();
9942 record_unwind_protect (unwind_redisplay
,
9943 Fcons (make_number (redisplaying_p
), selected_frame
));
9945 specbind (Qinhibit_free_realized_faces
, Qnil
);
9949 reconsider_clip_changes (w
, current_buffer
);
9951 /* If new fonts have been loaded that make a glyph matrix adjustment
9952 necessary, do it. */
9953 if (fonts_changed_p
)
9955 adjust_glyphs (NULL
);
9956 ++windows_or_buffers_changed
;
9957 fonts_changed_p
= 0;
9960 /* If face_change_count is non-zero, init_iterator will free all
9961 realized faces, which includes the faces referenced from current
9962 matrices. So, we can't reuse current matrices in this case. */
9963 if (face_change_count
)
9964 ++windows_or_buffers_changed
;
9966 if (! FRAME_WINDOW_P (sf
)
9967 && previous_terminal_frame
!= sf
)
9969 /* Since frames on an ASCII terminal share the same display
9970 area, displaying a different frame means redisplay the whole
9972 windows_or_buffers_changed
++;
9973 SET_FRAME_GARBAGED (sf
);
9974 XSETFRAME (Vterminal_frame
, sf
);
9976 previous_terminal_frame
= sf
;
9978 /* Set the visible flags for all frames. Do this before checking
9979 for resized or garbaged frames; they want to know if their frames
9980 are visible. See the comment in frame.h for
9981 FRAME_SAMPLE_VISIBILITY. */
9983 Lisp_Object tail
, frame
;
9985 number_of_visible_frames
= 0;
9987 FOR_EACH_FRAME (tail
, frame
)
9989 struct frame
*f
= XFRAME (frame
);
9991 FRAME_SAMPLE_VISIBILITY (f
);
9992 if (FRAME_VISIBLE_P (f
))
9993 ++number_of_visible_frames
;
9994 clear_desired_matrices (f
);
9998 /* Notice any pending interrupt request to change frame size. */
9999 do_pending_window_change (1);
10001 /* Clear frames marked as garbaged. */
10002 if (frame_garbaged
)
10003 clear_garbaged_frames ();
10005 /* Build menubar and tool-bar items. */
10006 prepare_menu_bars ();
10008 if (windows_or_buffers_changed
)
10009 update_mode_lines
++;
10011 /* Detect case that we need to write or remove a star in the mode line. */
10012 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10014 w
->update_mode_line
= Qt
;
10015 if (buffer_shared
> 1)
10016 update_mode_lines
++;
10019 /* If %c is in the mode line, update it if needed. */
10020 if (!NILP (w
->column_number_displayed
)
10021 /* This alternative quickly identifies a common case
10022 where no change is needed. */
10023 && !(PT
== XFASTINT (w
->last_point
)
10024 && XFASTINT (w
->last_modified
) >= MODIFF
10025 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10026 && (XFASTINT (w
->column_number_displayed
)
10027 != (int) current_column ())) /* iftc */
10028 w
->update_mode_line
= Qt
;
10030 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10032 /* The variable buffer_shared is set in redisplay_window and
10033 indicates that we redisplay a buffer in different windows. See
10035 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10036 || cursor_type_changed
);
10038 /* If specs for an arrow have changed, do thorough redisplay
10039 to ensure we remove any arrow that should no longer exist. */
10040 if (overlay_arrows_changed_p ())
10041 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10043 /* Normally the message* functions will have already displayed and
10044 updated the echo area, but the frame may have been trashed, or
10045 the update may have been preempted, so display the echo area
10046 again here. Checking message_cleared_p captures the case that
10047 the echo area should be cleared. */
10048 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10049 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10050 || (message_cleared_p
10051 && minibuf_level
== 0
10052 /* If the mini-window is currently selected, this means the
10053 echo-area doesn't show through. */
10054 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10056 int window_height_changed_p
= echo_area_display (0);
10059 /* If we don't display the current message, don't clear the
10060 message_cleared_p flag, because, if we did, we wouldn't clear
10061 the echo area in the next redisplay which doesn't preserve
10063 if (!display_last_displayed_message_p
)
10064 message_cleared_p
= 0;
10066 if (fonts_changed_p
)
10068 else if (window_height_changed_p
)
10070 consider_all_windows_p
= 1;
10071 ++update_mode_lines
;
10072 ++windows_or_buffers_changed
;
10074 /* If window configuration was changed, frames may have been
10075 marked garbaged. Clear them or we will experience
10076 surprises wrt scrolling. */
10077 if (frame_garbaged
)
10078 clear_garbaged_frames ();
10081 else if (EQ (selected_window
, minibuf_window
)
10082 && (current_buffer
->clip_changed
10083 || XFASTINT (w
->last_modified
) < MODIFF
10084 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10085 && resize_mini_window (w
, 0))
10087 /* Resized active mini-window to fit the size of what it is
10088 showing if its contents might have changed. */
10090 consider_all_windows_p
= 1;
10091 ++windows_or_buffers_changed
;
10092 ++update_mode_lines
;
10094 /* If window configuration was changed, frames may have been
10095 marked garbaged. Clear them or we will experience
10096 surprises wrt scrolling. */
10097 if (frame_garbaged
)
10098 clear_garbaged_frames ();
10102 /* If showing the region, and mark has changed, we must redisplay
10103 the whole window. The assignment to this_line_start_pos prevents
10104 the optimization directly below this if-statement. */
10105 if (((!NILP (Vtransient_mark_mode
)
10106 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10107 != !NILP (w
->region_showing
))
10108 || (!NILP (w
->region_showing
)
10109 && !EQ (w
->region_showing
,
10110 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10111 CHARPOS (this_line_start_pos
) = 0;
10113 /* Optimize the case that only the line containing the cursor in the
10114 selected window has changed. Variables starting with this_ are
10115 set in display_line and record information about the line
10116 containing the cursor. */
10117 tlbufpos
= this_line_start_pos
;
10118 tlendpos
= this_line_end_pos
;
10119 if (!consider_all_windows_p
10120 && CHARPOS (tlbufpos
) > 0
10121 && NILP (w
->update_mode_line
)
10122 && !current_buffer
->clip_changed
10123 && !current_buffer
->prevent_redisplay_optimizations_p
10124 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10125 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10126 /* Make sure recorded data applies to current buffer, etc. */
10127 && this_line_buffer
== current_buffer
10128 && current_buffer
== XBUFFER (w
->buffer
)
10129 && NILP (w
->force_start
)
10130 && NILP (w
->optional_new_start
)
10131 /* Point must be on the line that we have info recorded about. */
10132 && PT
>= CHARPOS (tlbufpos
)
10133 && PT
<= Z
- CHARPOS (tlendpos
)
10134 /* All text outside that line, including its final newline,
10135 must be unchanged */
10136 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10137 CHARPOS (tlendpos
)))
10139 if (CHARPOS (tlbufpos
) > BEGV
10140 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10141 && (CHARPOS (tlbufpos
) == ZV
10142 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10143 /* Former continuation line has disappeared by becoming empty */
10145 else if (XFASTINT (w
->last_modified
) < MODIFF
10146 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10147 || MINI_WINDOW_P (w
))
10149 /* We have to handle the case of continuation around a
10150 wide-column character (See the comment in indent.c around
10153 For instance, in the following case:
10155 -------- Insert --------
10156 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10157 J_I_ ==> J_I_ `^^' are cursors.
10161 As we have to redraw the line above, we should goto cancel. */
10164 int line_height_before
= this_line_pixel_height
;
10166 /* Note that start_display will handle the case that the
10167 line starting at tlbufpos is a continuation lines. */
10168 start_display (&it
, w
, tlbufpos
);
10170 /* Implementation note: It this still necessary? */
10171 if (it
.current_x
!= this_line_start_x
)
10174 TRACE ((stderr
, "trying display optimization 1\n"));
10175 w
->cursor
.vpos
= -1;
10176 overlay_arrow_seen
= 0;
10177 it
.vpos
= this_line_vpos
;
10178 it
.current_y
= this_line_y
;
10179 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10180 display_line (&it
);
10182 /* If line contains point, is not continued,
10183 and ends at same distance from eob as before, we win */
10184 if (w
->cursor
.vpos
>= 0
10185 /* Line is not continued, otherwise this_line_start_pos
10186 would have been set to 0 in display_line. */
10187 && CHARPOS (this_line_start_pos
)
10188 /* Line ends as before. */
10189 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10190 /* Line has same height as before. Otherwise other lines
10191 would have to be shifted up or down. */
10192 && this_line_pixel_height
== line_height_before
)
10194 /* If this is not the window's last line, we must adjust
10195 the charstarts of the lines below. */
10196 if (it
.current_y
< it
.last_visible_y
)
10198 struct glyph_row
*row
10199 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10200 int delta
, delta_bytes
;
10202 if (Z
- CHARPOS (tlendpos
) == ZV
)
10204 /* This line ends at end of (accessible part of)
10205 buffer. There is no newline to count. */
10207 - CHARPOS (tlendpos
)
10208 - MATRIX_ROW_START_CHARPOS (row
));
10209 delta_bytes
= (Z_BYTE
10210 - BYTEPOS (tlendpos
)
10211 - MATRIX_ROW_START_BYTEPOS (row
));
10215 /* This line ends in a newline. Must take
10216 account of the newline and the rest of the
10217 text that follows. */
10219 - CHARPOS (tlendpos
)
10220 - MATRIX_ROW_START_CHARPOS (row
));
10221 delta_bytes
= (Z_BYTE
10222 - BYTEPOS (tlendpos
)
10223 - MATRIX_ROW_START_BYTEPOS (row
));
10226 increment_matrix_positions (w
->current_matrix
,
10227 this_line_vpos
+ 1,
10228 w
->current_matrix
->nrows
,
10229 delta
, delta_bytes
);
10232 /* If this row displays text now but previously didn't,
10233 or vice versa, w->window_end_vpos may have to be
10235 if ((it
.glyph_row
- 1)->displays_text_p
)
10237 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10238 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10240 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10241 && this_line_vpos
> 0)
10242 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10243 w
->window_end_valid
= Qnil
;
10245 /* Update hint: No need to try to scroll in update_window. */
10246 w
->desired_matrix
->no_scrolling_p
= 1;
10249 *w
->desired_matrix
->method
= 0;
10250 debug_method_add (w
, "optimization 1");
10252 #ifdef HAVE_WINDOW_SYSTEM
10253 update_window_fringes (w
, 0);
10260 else if (/* Cursor position hasn't changed. */
10261 PT
== XFASTINT (w
->last_point
)
10262 /* Make sure the cursor was last displayed
10263 in this window. Otherwise we have to reposition it. */
10264 && 0 <= w
->cursor
.vpos
10265 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10269 do_pending_window_change (1);
10271 /* We used to always goto end_of_redisplay here, but this
10272 isn't enough if we have a blinking cursor. */
10273 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10274 goto end_of_redisplay
;
10278 /* If highlighting the region, or if the cursor is in the echo area,
10279 then we can't just move the cursor. */
10280 else if (! (!NILP (Vtransient_mark_mode
)
10281 && !NILP (current_buffer
->mark_active
))
10282 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10283 || highlight_nonselected_windows
)
10284 && NILP (w
->region_showing
)
10285 && NILP (Vshow_trailing_whitespace
)
10286 && !cursor_in_echo_area
)
10289 struct glyph_row
*row
;
10291 /* Skip from tlbufpos to PT and see where it is. Note that
10292 PT may be in invisible text. If so, we will end at the
10293 next visible position. */
10294 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10295 NULL
, DEFAULT_FACE_ID
);
10296 it
.current_x
= this_line_start_x
;
10297 it
.current_y
= this_line_y
;
10298 it
.vpos
= this_line_vpos
;
10300 /* The call to move_it_to stops in front of PT, but
10301 moves over before-strings. */
10302 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10304 if (it
.vpos
== this_line_vpos
10305 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10308 xassert (this_line_vpos
== it
.vpos
);
10309 xassert (this_line_y
== it
.current_y
);
10310 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10312 *w
->desired_matrix
->method
= 0;
10313 debug_method_add (w
, "optimization 3");
10322 /* Text changed drastically or point moved off of line. */
10323 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10326 CHARPOS (this_line_start_pos
) = 0;
10327 consider_all_windows_p
|= buffer_shared
> 1;
10328 ++clear_face_cache_count
;
10331 /* Build desired matrices, and update the display. If
10332 consider_all_windows_p is non-zero, do it for all windows on all
10333 frames. Otherwise do it for selected_window, only. */
10335 if (consider_all_windows_p
)
10337 Lisp_Object tail
, frame
;
10338 int i
, n
= 0, size
= 50;
10339 struct frame
**updated
10340 = (struct frame
**) alloca (size
* sizeof *updated
);
10342 /* Clear the face cache eventually. */
10343 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10345 clear_face_cache (0);
10346 clear_face_cache_count
= 0;
10349 /* Recompute # windows showing selected buffer. This will be
10350 incremented each time such a window is displayed. */
10353 FOR_EACH_FRAME (tail
, frame
)
10355 struct frame
*f
= XFRAME (frame
);
10357 if (FRAME_WINDOW_P (f
) || f
== sf
)
10359 if (! EQ (frame
, selected_frame
))
10360 /* Select the frame, for the sake of frame-local
10362 select_frame_for_redisplay (frame
);
10364 #ifdef HAVE_WINDOW_SYSTEM
10365 if (clear_face_cache_count
% 50 == 0
10366 && FRAME_WINDOW_P (f
))
10367 clear_image_cache (f
, 0);
10368 #endif /* HAVE_WINDOW_SYSTEM */
10370 /* Mark all the scroll bars to be removed; we'll redeem
10371 the ones we want when we redisplay their windows. */
10372 if (condemn_scroll_bars_hook
)
10373 condemn_scroll_bars_hook (f
);
10375 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10376 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10378 /* Any scroll bars which redisplay_windows should have
10379 nuked should now go away. */
10380 if (judge_scroll_bars_hook
)
10381 judge_scroll_bars_hook (f
);
10383 /* If fonts changed, display again. */
10384 /* ??? rms: I suspect it is a mistake to jump all the way
10385 back to retry here. It should just retry this frame. */
10386 if (fonts_changed_p
)
10389 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10391 /* See if we have to hscroll. */
10392 if (hscroll_windows (f
->root_window
))
10395 /* Prevent various kinds of signals during display
10396 update. stdio is not robust about handling
10397 signals, which can cause an apparent I/O
10399 if (interrupt_input
)
10400 unrequest_sigio ();
10403 /* Update the display. */
10404 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10405 pause
|= update_frame (f
, 0, 0);
10406 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10413 int nbytes
= size
* sizeof *updated
;
10414 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10415 bcopy (updated
, p
, nbytes
);
10426 /* Do the mark_window_display_accurate after all windows have
10427 been redisplayed because this call resets flags in buffers
10428 which are needed for proper redisplay. */
10429 for (i
= 0; i
< n
; ++i
)
10431 struct frame
*f
= updated
[i
];
10432 mark_window_display_accurate (f
->root_window
, 1);
10433 if (frame_up_to_date_hook
)
10434 frame_up_to_date_hook (f
);
10438 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10440 Lisp_Object mini_window
;
10441 struct frame
*mini_frame
;
10443 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10444 /* Use list_of_error, not Qerror, so that
10445 we catch only errors and don't run the debugger. */
10446 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10448 redisplay_window_error
);
10450 /* Compare desired and current matrices, perform output. */
10453 /* If fonts changed, display again. */
10454 if (fonts_changed_p
)
10457 /* Prevent various kinds of signals during display update.
10458 stdio is not robust about handling signals,
10459 which can cause an apparent I/O error. */
10460 if (interrupt_input
)
10461 unrequest_sigio ();
10464 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10466 if (hscroll_windows (selected_window
))
10469 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10470 pause
= update_frame (sf
, 0, 0);
10473 /* We may have called echo_area_display at the top of this
10474 function. If the echo area is on another frame, that may
10475 have put text on a frame other than the selected one, so the
10476 above call to update_frame would not have caught it. Catch
10478 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10479 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10481 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10483 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10484 pause
|= update_frame (mini_frame
, 0, 0);
10485 if (!pause
&& hscroll_windows (mini_window
))
10490 /* If display was paused because of pending input, make sure we do a
10491 thorough update the next time. */
10494 /* Prevent the optimization at the beginning of
10495 redisplay_internal that tries a single-line update of the
10496 line containing the cursor in the selected window. */
10497 CHARPOS (this_line_start_pos
) = 0;
10499 /* Let the overlay arrow be updated the next time. */
10500 update_overlay_arrows (0);
10502 /* If we pause after scrolling, some rows in the current
10503 matrices of some windows are not valid. */
10504 if (!WINDOW_FULL_WIDTH_P (w
)
10505 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10506 update_mode_lines
= 1;
10510 if (!consider_all_windows_p
)
10512 /* This has already been done above if
10513 consider_all_windows_p is set. */
10514 mark_window_display_accurate_1 (w
, 1);
10516 /* Say overlay arrows are up to date. */
10517 update_overlay_arrows (1);
10519 if (frame_up_to_date_hook
!= 0)
10520 frame_up_to_date_hook (sf
);
10523 update_mode_lines
= 0;
10524 windows_or_buffers_changed
= 0;
10525 cursor_type_changed
= 0;
10528 /* Start SIGIO interrupts coming again. Having them off during the
10529 code above makes it less likely one will discard output, but not
10530 impossible, since there might be stuff in the system buffer here.
10531 But it is much hairier to try to do anything about that. */
10532 if (interrupt_input
)
10536 /* If a frame has become visible which was not before, redisplay
10537 again, so that we display it. Expose events for such a frame
10538 (which it gets when becoming visible) don't call the parts of
10539 redisplay constructing glyphs, so simply exposing a frame won't
10540 display anything in this case. So, we have to display these
10541 frames here explicitly. */
10544 Lisp_Object tail
, frame
;
10547 FOR_EACH_FRAME (tail
, frame
)
10549 int this_is_visible
= 0;
10551 if (XFRAME (frame
)->visible
)
10552 this_is_visible
= 1;
10553 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10554 if (XFRAME (frame
)->visible
)
10555 this_is_visible
= 1;
10557 if (this_is_visible
)
10561 if (new_count
!= number_of_visible_frames
)
10562 windows_or_buffers_changed
++;
10565 /* Change frame size now if a change is pending. */
10566 do_pending_window_change (1);
10568 /* If we just did a pending size change, or have additional
10569 visible frames, redisplay again. */
10570 if (windows_or_buffers_changed
&& !pause
)
10574 unbind_to (count
, Qnil
);
10579 /* Redisplay, but leave alone any recent echo area message unless
10580 another message has been requested in its place.
10582 This is useful in situations where you need to redisplay but no
10583 user action has occurred, making it inappropriate for the message
10584 area to be cleared. See tracking_off and
10585 wait_reading_process_output for examples of these situations.
10587 FROM_WHERE is an integer saying from where this function was
10588 called. This is useful for debugging. */
10591 redisplay_preserve_echo_area (from_where
)
10594 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10596 if (!NILP (echo_area_buffer
[1]))
10598 /* We have a previously displayed message, but no current
10599 message. Redisplay the previous message. */
10600 display_last_displayed_message_p
= 1;
10601 redisplay_internal (1);
10602 display_last_displayed_message_p
= 0;
10605 redisplay_internal (1);
10607 if (rif
!= NULL
&& rif
->flush_display_optional
)
10608 rif
->flush_display_optional (NULL
);
10612 /* Function registered with record_unwind_protect in
10613 redisplay_internal. Reset redisplaying_p to the value it had
10614 before redisplay_internal was called, and clear
10615 prevent_freeing_realized_faces_p. It also selects the previously
10619 unwind_redisplay (val
)
10622 Lisp_Object old_redisplaying_p
, old_frame
;
10624 old_redisplaying_p
= XCAR (val
);
10625 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10626 old_frame
= XCDR (val
);
10627 if (! EQ (old_frame
, selected_frame
))
10628 select_frame_for_redisplay (old_frame
);
10633 /* Mark the display of window W as accurate or inaccurate. If
10634 ACCURATE_P is non-zero mark display of W as accurate. If
10635 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10636 redisplay_internal is called. */
10639 mark_window_display_accurate_1 (w
, accurate_p
)
10643 if (BUFFERP (w
->buffer
))
10645 struct buffer
*b
= XBUFFER (w
->buffer
);
10648 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10649 w
->last_overlay_modified
10650 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10652 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10656 b
->clip_changed
= 0;
10657 b
->prevent_redisplay_optimizations_p
= 0;
10659 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10660 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10661 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10662 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10664 w
->current_matrix
->buffer
= b
;
10665 w
->current_matrix
->begv
= BUF_BEGV (b
);
10666 w
->current_matrix
->zv
= BUF_ZV (b
);
10668 w
->last_cursor
= w
->cursor
;
10669 w
->last_cursor_off_p
= w
->cursor_off_p
;
10671 if (w
== XWINDOW (selected_window
))
10672 w
->last_point
= make_number (BUF_PT (b
));
10674 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10680 w
->window_end_valid
= w
->buffer
;
10681 #if 0 /* This is incorrect with variable-height lines. */
10682 xassert (XINT (w
->window_end_vpos
)
10683 < (WINDOW_TOTAL_LINES (w
)
10684 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10686 w
->update_mode_line
= Qnil
;
10691 /* Mark the display of windows in the window tree rooted at WINDOW as
10692 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10693 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10694 be redisplayed the next time redisplay_internal is called. */
10697 mark_window_display_accurate (window
, accurate_p
)
10698 Lisp_Object window
;
10703 for (; !NILP (window
); window
= w
->next
)
10705 w
= XWINDOW (window
);
10706 mark_window_display_accurate_1 (w
, accurate_p
);
10708 if (!NILP (w
->vchild
))
10709 mark_window_display_accurate (w
->vchild
, accurate_p
);
10710 if (!NILP (w
->hchild
))
10711 mark_window_display_accurate (w
->hchild
, accurate_p
);
10716 update_overlay_arrows (1);
10720 /* Force a thorough redisplay the next time by setting
10721 last_arrow_position and last_arrow_string to t, which is
10722 unequal to any useful value of Voverlay_arrow_... */
10723 update_overlay_arrows (-1);
10728 /* Return value in display table DP (Lisp_Char_Table *) for character
10729 C. Since a display table doesn't have any parent, we don't have to
10730 follow parent. Do not call this function directly but use the
10731 macro DISP_CHAR_VECTOR. */
10734 disp_char_vector (dp
, c
)
10735 struct Lisp_Char_Table
*dp
;
10741 if (SINGLE_BYTE_CHAR_P (c
))
10742 return (dp
->contents
[c
]);
10744 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10747 else if (code
[2] < 32)
10750 /* Here, the possible range of code[0] (== charset ID) is
10751 128..max_charset. Since the top level char table contains data
10752 for multibyte characters after 256th element, we must increment
10753 code[0] by 128 to get a correct index. */
10755 code
[3] = -1; /* anchor */
10757 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10759 val
= dp
->contents
[code
[i
]];
10760 if (!SUB_CHAR_TABLE_P (val
))
10761 return (NILP (val
) ? dp
->defalt
: val
);
10764 /* Here, val is a sub char table. We return the default value of
10766 return (dp
->defalt
);
10771 /***********************************************************************
10773 ***********************************************************************/
10775 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10778 redisplay_windows (window
)
10779 Lisp_Object window
;
10781 while (!NILP (window
))
10783 struct window
*w
= XWINDOW (window
);
10785 if (!NILP (w
->hchild
))
10786 redisplay_windows (w
->hchild
);
10787 else if (!NILP (w
->vchild
))
10788 redisplay_windows (w
->vchild
);
10791 displayed_buffer
= XBUFFER (w
->buffer
);
10792 /* Use list_of_error, not Qerror, so that
10793 we catch only errors and don't run the debugger. */
10794 internal_condition_case_1 (redisplay_window_0
, window
,
10796 redisplay_window_error
);
10804 redisplay_window_error ()
10806 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10811 redisplay_window_0 (window
)
10812 Lisp_Object window
;
10814 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10815 redisplay_window (window
, 0);
10820 redisplay_window_1 (window
)
10821 Lisp_Object window
;
10823 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10824 redisplay_window (window
, 1);
10829 /* Increment GLYPH until it reaches END or CONDITION fails while
10830 adding (GLYPH)->pixel_width to X. */
10832 #define SKIP_GLYPHS(glyph, end, x, condition) \
10835 (x) += (glyph)->pixel_width; \
10838 while ((glyph) < (end) && (condition))
10841 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10842 DELTA is the number of bytes by which positions recorded in ROW
10843 differ from current buffer positions. */
10846 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10848 struct glyph_row
*row
;
10849 struct glyph_matrix
*matrix
;
10850 int delta
, delta_bytes
, dy
, dvpos
;
10852 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10853 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10854 struct glyph
*cursor
= NULL
;
10855 /* The first glyph that starts a sequence of glyphs from string. */
10856 struct glyph
*string_start
;
10857 /* The X coordinate of string_start. */
10858 int string_start_x
;
10859 /* The last known character position. */
10860 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10861 /* The last known character position before string_start. */
10862 int string_before_pos
;
10865 int cursor_from_overlay_pos
= 0;
10866 int pt_old
= PT
- delta
;
10868 /* Skip over glyphs not having an object at the start of the row.
10869 These are special glyphs like truncation marks on terminal
10871 if (row
->displays_text_p
)
10873 && INTEGERP (glyph
->object
)
10874 && glyph
->charpos
< 0)
10876 x
+= glyph
->pixel_width
;
10880 string_start
= NULL
;
10882 && !INTEGERP (glyph
->object
)
10883 && (!BUFFERP (glyph
->object
)
10884 || (last_pos
= glyph
->charpos
) < pt_old
))
10886 if (! STRINGP (glyph
->object
))
10888 string_start
= NULL
;
10889 x
+= glyph
->pixel_width
;
10891 if (cursor_from_overlay_pos
10892 && last_pos
> cursor_from_overlay_pos
)
10894 cursor_from_overlay_pos
= 0;
10900 string_before_pos
= last_pos
;
10901 string_start
= glyph
;
10902 string_start_x
= x
;
10903 /* Skip all glyphs from string. */
10907 if ((cursor
== NULL
|| glyph
> cursor
)
10908 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
10909 Qcursor
, (glyph
)->object
))
10910 && (pos
= string_buffer_position (w
, glyph
->object
,
10911 string_before_pos
),
10912 (pos
== 0 /* From overlay */
10913 || pos
== pt_old
)))
10915 /* Estimate overlay buffer position from the buffer
10916 positions of the glyphs before and after the overlay.
10917 Add 1 to last_pos so that if point corresponds to the
10918 glyph right after the overlay, we still use a 'cursor'
10919 property found in that overlay. */
10920 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
10924 x
+= glyph
->pixel_width
;
10927 while (glyph
< end
&& STRINGP (glyph
->object
));
10931 if (cursor
!= NULL
)
10936 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
10938 /* Scan back over the ellipsis glyphs, decrementing positions. */
10939 while (glyph
> row
->glyphs
[TEXT_AREA
]
10940 && (glyph
- 1)->charpos
== last_pos
)
10941 glyph
--, x
-= glyph
->pixel_width
;
10942 /* That loop always goes one position too far,
10943 including the glyph before the ellipsis.
10944 So scan forward over that one. */
10945 x
+= glyph
->pixel_width
;
10948 else if (string_start
10949 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10951 /* We may have skipped over point because the previous glyphs
10952 are from string. As there's no easy way to know the
10953 character position of the current glyph, find the correct
10954 glyph on point by scanning from string_start again. */
10956 Lisp_Object string
;
10959 limit
= make_number (pt_old
+ 1);
10961 glyph
= string_start
;
10962 x
= string_start_x
;
10963 string
= glyph
->object
;
10964 pos
= string_buffer_position (w
, string
, string_before_pos
);
10965 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10966 because we always put cursor after overlay strings. */
10967 while (pos
== 0 && glyph
< end
)
10969 string
= glyph
->object
;
10970 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10972 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10975 while (glyph
< end
)
10977 pos
= XINT (Fnext_single_char_property_change
10978 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10981 /* Skip glyphs from the same string. */
10982 string
= glyph
->object
;
10983 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10984 /* Skip glyphs from an overlay. */
10986 && ! string_buffer_position (w
, glyph
->object
, pos
))
10988 string
= glyph
->object
;
10989 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10994 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10996 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10997 w
->cursor
.y
= row
->y
+ dy
;
10999 if (w
== XWINDOW (selected_window
))
11001 if (!row
->continued_p
11002 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11005 this_line_buffer
= XBUFFER (w
->buffer
);
11007 CHARPOS (this_line_start_pos
)
11008 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11009 BYTEPOS (this_line_start_pos
)
11010 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11012 CHARPOS (this_line_end_pos
)
11013 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11014 BYTEPOS (this_line_end_pos
)
11015 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11017 this_line_y
= w
->cursor
.y
;
11018 this_line_pixel_height
= row
->height
;
11019 this_line_vpos
= w
->cursor
.vpos
;
11020 this_line_start_x
= row
->x
;
11023 CHARPOS (this_line_start_pos
) = 0;
11028 /* Run window scroll functions, if any, for WINDOW with new window
11029 start STARTP. Sets the window start of WINDOW to that position.
11031 We assume that the window's buffer is really current. */
11033 static INLINE
struct text_pos
11034 run_window_scroll_functions (window
, startp
)
11035 Lisp_Object window
;
11036 struct text_pos startp
;
11038 struct window
*w
= XWINDOW (window
);
11039 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11041 if (current_buffer
!= XBUFFER (w
->buffer
))
11044 if (!NILP (Vwindow_scroll_functions
))
11046 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11047 make_number (CHARPOS (startp
)));
11048 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11049 /* In case the hook functions switch buffers. */
11050 if (current_buffer
!= XBUFFER (w
->buffer
))
11051 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11058 /* Make sure the line containing the cursor is fully visible.
11059 A value of 1 means there is nothing to be done.
11060 (Either the line is fully visible, or it cannot be made so,
11061 or we cannot tell.)
11063 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11064 is higher than window.
11066 A value of 0 means the caller should do scrolling
11067 as if point had gone off the screen. */
11070 make_cursor_line_fully_visible (w
, force_p
)
11074 struct glyph_matrix
*matrix
;
11075 struct glyph_row
*row
;
11078 if (!make_cursor_line_fully_visible_p
)
11081 /* It's not always possible to find the cursor, e.g, when a window
11082 is full of overlay strings. Don't do anything in that case. */
11083 if (w
->cursor
.vpos
< 0)
11086 matrix
= w
->desired_matrix
;
11087 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11089 /* If the cursor row is not partially visible, there's nothing to do. */
11090 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11093 /* If the row the cursor is in is taller than the window's height,
11094 it's not clear what to do, so do nothing. */
11095 window_height
= window_box_height (w
);
11096 if (row
->height
>= window_height
)
11098 if (!force_p
|| w
->vscroll
)
11104 /* This code used to try to scroll the window just enough to make
11105 the line visible. It returned 0 to say that the caller should
11106 allocate larger glyph matrices. */
11108 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11110 int dy
= row
->height
- row
->visible_height
;
11113 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11115 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11117 int dy
= - (row
->height
- row
->visible_height
);
11120 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11123 /* When we change the cursor y-position of the selected window,
11124 change this_line_y as well so that the display optimization for
11125 the cursor line of the selected window in redisplay_internal uses
11126 the correct y-position. */
11127 if (w
== XWINDOW (selected_window
))
11128 this_line_y
= w
->cursor
.y
;
11130 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11131 redisplay with larger matrices. */
11132 if (matrix
->nrows
< required_matrix_height (w
))
11134 fonts_changed_p
= 1;
11143 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11144 non-zero means only WINDOW is redisplayed in redisplay_internal.
11145 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11146 in redisplay_window to bring a partially visible line into view in
11147 the case that only the cursor has moved.
11149 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11150 last screen line's vertical height extends past the end of the screen.
11154 1 if scrolling succeeded
11156 0 if scrolling didn't find point.
11158 -1 if new fonts have been loaded so that we must interrupt
11159 redisplay, adjust glyph matrices, and try again. */
11165 SCROLLING_NEED_LARGER_MATRICES
11169 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11170 scroll_step
, temp_scroll_step
, last_line_misfit
)
11171 Lisp_Object window
;
11172 int just_this_one_p
;
11173 EMACS_INT scroll_conservatively
, scroll_step
;
11174 int temp_scroll_step
;
11175 int last_line_misfit
;
11177 struct window
*w
= XWINDOW (window
);
11178 struct frame
*f
= XFRAME (w
->frame
);
11179 struct text_pos scroll_margin_pos
;
11180 struct text_pos pos
;
11181 struct text_pos startp
;
11183 Lisp_Object window_end
;
11184 int this_scroll_margin
;
11188 int amount_to_scroll
= 0;
11189 Lisp_Object aggressive
;
11191 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11194 debug_method_add (w
, "try_scrolling");
11197 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11199 /* Compute scroll margin height in pixels. We scroll when point is
11200 within this distance from the top or bottom of the window. */
11201 if (scroll_margin
> 0)
11203 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11204 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11207 this_scroll_margin
= 0;
11209 /* Force scroll_conservatively to have a reasonable value so it doesn't
11210 cause an overflow while computing how much to scroll. */
11211 if (scroll_conservatively
)
11212 scroll_conservatively
= min (scroll_conservatively
,
11213 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11215 /* Compute how much we should try to scroll maximally to bring point
11217 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11218 scroll_max
= max (scroll_step
,
11219 max (scroll_conservatively
, temp_scroll_step
));
11220 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11221 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11222 /* We're trying to scroll because of aggressive scrolling
11223 but no scroll_step is set. Choose an arbitrary one. Maybe
11224 there should be a variable for this. */
11228 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11230 /* Decide whether we have to scroll down. Start at the window end
11231 and move this_scroll_margin up to find the position of the scroll
11233 window_end
= Fwindow_end (window
, Qt
);
11237 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11238 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11240 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11242 start_display (&it
, w
, scroll_margin_pos
);
11243 if (this_scroll_margin
)
11244 move_it_vertically_backward (&it
, this_scroll_margin
);
11245 if (extra_scroll_margin_lines
)
11246 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11247 scroll_margin_pos
= it
.current
.pos
;
11250 if (PT
>= CHARPOS (scroll_margin_pos
))
11254 /* Point is in the scroll margin at the bottom of the window, or
11255 below. Compute a new window start that makes point visible. */
11257 /* Compute the distance from the scroll margin to PT.
11258 Give up if the distance is greater than scroll_max. */
11259 start_display (&it
, w
, scroll_margin_pos
);
11261 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11262 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11264 /* To make point visible, we have to move the window start
11265 down so that the line the cursor is in is visible, which
11266 means we have to add in the height of the cursor line. */
11267 dy
= line_bottom_y (&it
) - y0
;
11269 if (dy
> scroll_max
)
11270 return SCROLLING_FAILED
;
11272 /* Move the window start down. If scrolling conservatively,
11273 move it just enough down to make point visible. If
11274 scroll_step is set, move it down by scroll_step. */
11275 start_display (&it
, w
, startp
);
11277 if (scroll_conservatively
)
11278 /* Set AMOUNT_TO_SCROLL to at least one line,
11279 and at most scroll_conservatively lines. */
11281 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11282 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11283 else if (scroll_step
|| temp_scroll_step
)
11284 amount_to_scroll
= scroll_max
;
11287 aggressive
= current_buffer
->scroll_up_aggressively
;
11288 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11289 if (NUMBERP (aggressive
))
11291 double float_amount
= XFLOATINT (aggressive
) * height
;
11292 amount_to_scroll
= float_amount
;
11293 if (amount_to_scroll
== 0 && float_amount
> 0)
11294 amount_to_scroll
= 1;
11298 if (amount_to_scroll
<= 0)
11299 return SCROLLING_FAILED
;
11301 /* If moving by amount_to_scroll leaves STARTP unchanged,
11302 move it down one screen line. */
11304 move_it_vertically (&it
, amount_to_scroll
);
11305 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11306 move_it_by_lines (&it
, 1, 1);
11307 startp
= it
.current
.pos
;
11311 /* See if point is inside the scroll margin at the top of the
11313 scroll_margin_pos
= startp
;
11314 if (this_scroll_margin
)
11316 start_display (&it
, w
, startp
);
11317 move_it_vertically (&it
, this_scroll_margin
);
11318 scroll_margin_pos
= it
.current
.pos
;
11321 if (PT
< CHARPOS (scroll_margin_pos
))
11323 /* Point is in the scroll margin at the top of the window or
11324 above what is displayed in the window. */
11327 /* Compute the vertical distance from PT to the scroll
11328 margin position. Give up if distance is greater than
11330 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11331 start_display (&it
, w
, pos
);
11333 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11334 it
.last_visible_y
, -1,
11335 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11336 dy
= it
.current_y
- y0
;
11337 if (dy
> scroll_max
)
11338 return SCROLLING_FAILED
;
11340 /* Compute new window start. */
11341 start_display (&it
, w
, startp
);
11343 if (scroll_conservatively
)
11345 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11346 else if (scroll_step
|| temp_scroll_step
)
11347 amount_to_scroll
= scroll_max
;
11350 aggressive
= current_buffer
->scroll_down_aggressively
;
11351 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11352 if (NUMBERP (aggressive
))
11354 double float_amount
= XFLOATINT (aggressive
) * height
;
11355 amount_to_scroll
= float_amount
;
11356 if (amount_to_scroll
== 0 && float_amount
> 0)
11357 amount_to_scroll
= 1;
11361 if (amount_to_scroll
<= 0)
11362 return SCROLLING_FAILED
;
11364 move_it_vertically_backward (&it
, amount_to_scroll
);
11365 startp
= it
.current
.pos
;
11369 /* Run window scroll functions. */
11370 startp
= run_window_scroll_functions (window
, startp
);
11372 /* Display the window. Give up if new fonts are loaded, or if point
11374 if (!try_window (window
, startp
))
11375 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11376 else if (w
->cursor
.vpos
< 0)
11378 clear_glyph_matrix (w
->desired_matrix
);
11379 rc
= SCROLLING_FAILED
;
11383 /* Maybe forget recorded base line for line number display. */
11384 if (!just_this_one_p
11385 || current_buffer
->clip_changed
11386 || BEG_UNCHANGED
< CHARPOS (startp
))
11387 w
->base_line_number
= Qnil
;
11389 /* If cursor ends up on a partially visible line,
11390 treat that as being off the bottom of the screen. */
11391 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11393 clear_glyph_matrix (w
->desired_matrix
);
11394 ++extra_scroll_margin_lines
;
11397 rc
= SCROLLING_SUCCESS
;
11404 /* Compute a suitable window start for window W if display of W starts
11405 on a continuation line. Value is non-zero if a new window start
11408 The new window start will be computed, based on W's width, starting
11409 from the start of the continued line. It is the start of the
11410 screen line with the minimum distance from the old start W->start. */
11413 compute_window_start_on_continuation_line (w
)
11416 struct text_pos pos
, start_pos
;
11417 int window_start_changed_p
= 0;
11419 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11421 /* If window start is on a continuation line... Window start may be
11422 < BEGV in case there's invisible text at the start of the
11423 buffer (M-x rmail, for example). */
11424 if (CHARPOS (start_pos
) > BEGV
11425 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11428 struct glyph_row
*row
;
11430 /* Handle the case that the window start is out of range. */
11431 if (CHARPOS (start_pos
) < BEGV
)
11432 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11433 else if (CHARPOS (start_pos
) > ZV
)
11434 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11436 /* Find the start of the continued line. This should be fast
11437 because scan_buffer is fast (newline cache). */
11438 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11439 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11440 row
, DEFAULT_FACE_ID
);
11441 reseat_at_previous_visible_line_start (&it
);
11443 /* If the line start is "too far" away from the window start,
11444 say it takes too much time to compute a new window start. */
11445 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11446 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11448 int min_distance
, distance
;
11450 /* Move forward by display lines to find the new window
11451 start. If window width was enlarged, the new start can
11452 be expected to be > the old start. If window width was
11453 decreased, the new window start will be < the old start.
11454 So, we're looking for the display line start with the
11455 minimum distance from the old window start. */
11456 pos
= it
.current
.pos
;
11457 min_distance
= INFINITY
;
11458 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11459 distance
< min_distance
)
11461 min_distance
= distance
;
11462 pos
= it
.current
.pos
;
11463 move_it_by_lines (&it
, 1, 0);
11466 /* Set the window start there. */
11467 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11468 window_start_changed_p
= 1;
11472 return window_start_changed_p
;
11476 /* Try cursor movement in case text has not changed in window WINDOW,
11477 with window start STARTP. Value is
11479 CURSOR_MOVEMENT_SUCCESS if successful
11481 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11483 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11484 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11485 we want to scroll as if scroll-step were set to 1. See the code.
11487 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11488 which case we have to abort this redisplay, and adjust matrices
11493 CURSOR_MOVEMENT_SUCCESS
,
11494 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11495 CURSOR_MOVEMENT_MUST_SCROLL
,
11496 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11500 try_cursor_movement (window
, startp
, scroll_step
)
11501 Lisp_Object window
;
11502 struct text_pos startp
;
11505 struct window
*w
= XWINDOW (window
);
11506 struct frame
*f
= XFRAME (w
->frame
);
11507 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11510 if (inhibit_try_cursor_movement
)
11514 /* Handle case where text has not changed, only point, and it has
11515 not moved off the frame. */
11516 if (/* Point may be in this window. */
11517 PT
>= CHARPOS (startp
)
11518 /* Selective display hasn't changed. */
11519 && !current_buffer
->clip_changed
11520 /* Function force-mode-line-update is used to force a thorough
11521 redisplay. It sets either windows_or_buffers_changed or
11522 update_mode_lines. So don't take a shortcut here for these
11524 && !update_mode_lines
11525 && !windows_or_buffers_changed
11526 && !cursor_type_changed
11527 /* Can't use this case if highlighting a region. When a
11528 region exists, cursor movement has to do more than just
11530 && !(!NILP (Vtransient_mark_mode
)
11531 && !NILP (current_buffer
->mark_active
))
11532 && NILP (w
->region_showing
)
11533 && NILP (Vshow_trailing_whitespace
)
11534 /* Right after splitting windows, last_point may be nil. */
11535 && INTEGERP (w
->last_point
)
11536 /* This code is not used for mini-buffer for the sake of the case
11537 of redisplaying to replace an echo area message; since in
11538 that case the mini-buffer contents per se are usually
11539 unchanged. This code is of no real use in the mini-buffer
11540 since the handling of this_line_start_pos, etc., in redisplay
11541 handles the same cases. */
11542 && !EQ (window
, minibuf_window
)
11543 /* When splitting windows or for new windows, it happens that
11544 redisplay is called with a nil window_end_vpos or one being
11545 larger than the window. This should really be fixed in
11546 window.c. I don't have this on my list, now, so we do
11547 approximately the same as the old redisplay code. --gerd. */
11548 && INTEGERP (w
->window_end_vpos
)
11549 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11550 && (FRAME_WINDOW_P (f
)
11551 || !overlay_arrow_in_current_buffer_p ()))
11553 int this_scroll_margin
, top_scroll_margin
;
11554 struct glyph_row
*row
= NULL
;
11557 debug_method_add (w
, "cursor movement");
11560 /* Scroll if point within this distance from the top or bottom
11561 of the window. This is a pixel value. */
11562 this_scroll_margin
= max (0, scroll_margin
);
11563 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11564 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11566 top_scroll_margin
= this_scroll_margin
;
11567 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11568 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11570 /* Start with the row the cursor was displayed during the last
11571 not paused redisplay. Give up if that row is not valid. */
11572 if (w
->last_cursor
.vpos
< 0
11573 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11574 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11577 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11578 if (row
->mode_line_p
)
11580 if (!row
->enabled_p
)
11581 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11584 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11587 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11589 if (PT
> XFASTINT (w
->last_point
))
11591 /* Point has moved forward. */
11592 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11593 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11595 xassert (row
->enabled_p
);
11599 /* The end position of a row equals the start position
11600 of the next row. If PT is there, we would rather
11601 display it in the next line. */
11602 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11603 && MATRIX_ROW_END_CHARPOS (row
) == PT
11604 && !cursor_row_p (w
, row
))
11607 /* If within the scroll margin, scroll. Note that
11608 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11609 the next line would be drawn, and that
11610 this_scroll_margin can be zero. */
11611 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11612 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11613 /* Line is completely visible last line in window
11614 and PT is to be set in the next line. */
11615 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11616 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11617 && !row
->ends_at_zv_p
11618 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11621 else if (PT
< XFASTINT (w
->last_point
))
11623 /* Cursor has to be moved backward. Note that PT >=
11624 CHARPOS (startp) because of the outer if-statement. */
11625 while (!row
->mode_line_p
11626 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11627 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11628 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11629 && (row
->y
> top_scroll_margin
11630 || CHARPOS (startp
) == BEGV
))
11632 xassert (row
->enabled_p
);
11636 /* Consider the following case: Window starts at BEGV,
11637 there is invisible, intangible text at BEGV, so that
11638 display starts at some point START > BEGV. It can
11639 happen that we are called with PT somewhere between
11640 BEGV and START. Try to handle that case. */
11641 if (row
< w
->current_matrix
->rows
11642 || row
->mode_line_p
)
11644 row
= w
->current_matrix
->rows
;
11645 if (row
->mode_line_p
)
11649 /* Due to newlines in overlay strings, we may have to
11650 skip forward over overlay strings. */
11651 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11652 && MATRIX_ROW_END_CHARPOS (row
) == PT
11653 && !cursor_row_p (w
, row
))
11656 /* If within the scroll margin, scroll. */
11657 if (row
->y
< top_scroll_margin
11658 && CHARPOS (startp
) != BEGV
)
11662 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11663 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11665 /* if PT is not in the glyph row, give up. */
11666 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11668 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11669 && make_cursor_line_fully_visible_p
)
11671 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11672 && !row
->ends_at_zv_p
11673 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11674 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11675 else if (row
->height
> window_box_height (w
))
11677 /* If we end up in a partially visible line, let's
11678 make it fully visible, except when it's taller
11679 than the window, in which case we can't do much
11682 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11686 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11687 if (!make_cursor_line_fully_visible (w
, 0))
11688 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11690 rc
= CURSOR_MOVEMENT_SUCCESS
;
11694 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11697 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11698 rc
= CURSOR_MOVEMENT_SUCCESS
;
11707 set_vertical_scroll_bar (w
)
11710 int start
, end
, whole
;
11712 /* Calculate the start and end positions for the current window.
11713 At some point, it would be nice to choose between scrollbars
11714 which reflect the whole buffer size, with special markers
11715 indicating narrowing, and scrollbars which reflect only the
11718 Note that mini-buffers sometimes aren't displaying any text. */
11719 if (!MINI_WINDOW_P (w
)
11720 || (w
== XWINDOW (minibuf_window
)
11721 && NILP (echo_area_buffer
[0])))
11723 struct buffer
*buf
= XBUFFER (w
->buffer
);
11724 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11725 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11726 /* I don't think this is guaranteed to be right. For the
11727 moment, we'll pretend it is. */
11728 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11732 if (whole
< (end
- start
))
11733 whole
= end
- start
;
11736 start
= end
= whole
= 0;
11738 /* Indicate what this scroll bar ought to be displaying now. */
11739 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11743 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11744 selected_window is redisplayed.
11746 We can return without actually redisplaying the window if
11747 fonts_changed_p is nonzero. In that case, redisplay_internal will
11751 redisplay_window (window
, just_this_one_p
)
11752 Lisp_Object window
;
11753 int just_this_one_p
;
11755 struct window
*w
= XWINDOW (window
);
11756 struct frame
*f
= XFRAME (w
->frame
);
11757 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11758 struct buffer
*old
= current_buffer
;
11759 struct text_pos lpoint
, opoint
, startp
;
11760 int update_mode_line
;
11763 /* Record it now because it's overwritten. */
11764 int current_matrix_up_to_date_p
= 0;
11765 int used_current_matrix_p
= 0;
11766 /* This is less strict than current_matrix_up_to_date_p.
11767 It indictes that the buffer contents and narrowing are unchanged. */
11768 int buffer_unchanged_p
= 0;
11769 int temp_scroll_step
= 0;
11770 int count
= SPECPDL_INDEX ();
11772 int centering_position
;
11773 int last_line_misfit
= 0;
11775 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11778 /* W must be a leaf window here. */
11779 xassert (!NILP (w
->buffer
));
11781 *w
->desired_matrix
->method
= 0;
11784 specbind (Qinhibit_point_motion_hooks
, Qt
);
11786 reconsider_clip_changes (w
, buffer
);
11788 /* Has the mode line to be updated? */
11789 update_mode_line
= (!NILP (w
->update_mode_line
)
11790 || update_mode_lines
11791 || buffer
->clip_changed
11792 || buffer
->prevent_redisplay_optimizations_p
);
11794 if (MINI_WINDOW_P (w
))
11796 if (w
== XWINDOW (echo_area_window
)
11797 && !NILP (echo_area_buffer
[0]))
11799 if (update_mode_line
)
11800 /* We may have to update a tty frame's menu bar or a
11801 tool-bar. Example `M-x C-h C-h C-g'. */
11802 goto finish_menu_bars
;
11804 /* We've already displayed the echo area glyphs in this window. */
11805 goto finish_scroll_bars
;
11807 else if ((w
!= XWINDOW (minibuf_window
)
11808 || minibuf_level
== 0)
11809 /* When buffer is nonempty, redisplay window normally. */
11810 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11811 /* Quail displays non-mini buffers in minibuffer window.
11812 In that case, redisplay the window normally. */
11813 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11815 /* W is a mini-buffer window, but it's not active, so clear
11817 int yb
= window_text_bottom_y (w
);
11818 struct glyph_row
*row
;
11821 for (y
= 0, row
= w
->desired_matrix
->rows
;
11823 y
+= row
->height
, ++row
)
11824 blank_row (w
, row
, y
);
11825 goto finish_scroll_bars
;
11828 clear_glyph_matrix (w
->desired_matrix
);
11831 /* Otherwise set up data on this window; select its buffer and point
11833 /* Really select the buffer, for the sake of buffer-local
11835 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11836 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11838 current_matrix_up_to_date_p
11839 = (!NILP (w
->window_end_valid
)
11840 && !current_buffer
->clip_changed
11841 && !current_buffer
->prevent_redisplay_optimizations_p
11842 && XFASTINT (w
->last_modified
) >= MODIFF
11843 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11846 = (!NILP (w
->window_end_valid
)
11847 && !current_buffer
->clip_changed
11848 && XFASTINT (w
->last_modified
) >= MODIFF
11849 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11851 /* When windows_or_buffers_changed is non-zero, we can't rely on
11852 the window end being valid, so set it to nil there. */
11853 if (windows_or_buffers_changed
)
11855 /* If window starts on a continuation line, maybe adjust the
11856 window start in case the window's width changed. */
11857 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11858 compute_window_start_on_continuation_line (w
);
11860 w
->window_end_valid
= Qnil
;
11863 /* Some sanity checks. */
11864 CHECK_WINDOW_END (w
);
11865 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11867 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11870 /* If %c is in mode line, update it if needed. */
11871 if (!NILP (w
->column_number_displayed
)
11872 /* This alternative quickly identifies a common case
11873 where no change is needed. */
11874 && !(PT
== XFASTINT (w
->last_point
)
11875 && XFASTINT (w
->last_modified
) >= MODIFF
11876 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11877 && (XFASTINT (w
->column_number_displayed
)
11878 != (int) current_column ())) /* iftc */
11879 update_mode_line
= 1;
11881 /* Count number of windows showing the selected buffer. An indirect
11882 buffer counts as its base buffer. */
11883 if (!just_this_one_p
)
11885 struct buffer
*current_base
, *window_base
;
11886 current_base
= current_buffer
;
11887 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11888 if (current_base
->base_buffer
)
11889 current_base
= current_base
->base_buffer
;
11890 if (window_base
->base_buffer
)
11891 window_base
= window_base
->base_buffer
;
11892 if (current_base
== window_base
)
11896 /* Point refers normally to the selected window. For any other
11897 window, set up appropriate value. */
11898 if (!EQ (window
, selected_window
))
11900 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11901 int new_pt_byte
= marker_byte_position (w
->pointm
);
11905 new_pt_byte
= BEGV_BYTE
;
11906 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11908 else if (new_pt
> (ZV
- 1))
11911 new_pt_byte
= ZV_BYTE
;
11912 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11915 /* We don't use SET_PT so that the point-motion hooks don't run. */
11916 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11919 /* If any of the character widths specified in the display table
11920 have changed, invalidate the width run cache. It's true that
11921 this may be a bit late to catch such changes, but the rest of
11922 redisplay goes (non-fatally) haywire when the display table is
11923 changed, so why should we worry about doing any better? */
11924 if (current_buffer
->width_run_cache
)
11926 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11928 if (! disptab_matches_widthtab (disptab
,
11929 XVECTOR (current_buffer
->width_table
)))
11931 invalidate_region_cache (current_buffer
,
11932 current_buffer
->width_run_cache
,
11934 recompute_width_table (current_buffer
, disptab
);
11938 /* If window-start is screwed up, choose a new one. */
11939 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11942 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11944 /* If someone specified a new starting point but did not insist,
11945 check whether it can be used. */
11946 if (!NILP (w
->optional_new_start
)
11947 && CHARPOS (startp
) >= BEGV
11948 && CHARPOS (startp
) <= ZV
)
11950 w
->optional_new_start
= Qnil
;
11951 start_display (&it
, w
, startp
);
11952 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11953 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11954 if (IT_CHARPOS (it
) == PT
)
11955 w
->force_start
= Qt
;
11956 /* IT may overshoot PT if text at PT is invisible. */
11957 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11958 w
->force_start
= Qt
;
11963 /* Handle case where place to start displaying has been specified,
11964 unless the specified location is outside the accessible range. */
11965 if (!NILP (w
->force_start
)
11966 || w
->frozen_window_start_p
)
11968 /* We set this later on if we have to adjust point. */
11971 w
->force_start
= Qnil
;
11973 w
->window_end_valid
= Qnil
;
11975 /* Forget any recorded base line for line number display. */
11976 if (!buffer_unchanged_p
)
11977 w
->base_line_number
= Qnil
;
11979 /* Redisplay the mode line. Select the buffer properly for that.
11980 Also, run the hook window-scroll-functions
11981 because we have scrolled. */
11982 /* Note, we do this after clearing force_start because
11983 if there's an error, it is better to forget about force_start
11984 than to get into an infinite loop calling the hook functions
11985 and having them get more errors. */
11986 if (!update_mode_line
11987 || ! NILP (Vwindow_scroll_functions
))
11989 update_mode_line
= 1;
11990 w
->update_mode_line
= Qt
;
11991 startp
= run_window_scroll_functions (window
, startp
);
11994 w
->last_modified
= make_number (0);
11995 w
->last_overlay_modified
= make_number (0);
11996 if (CHARPOS (startp
) < BEGV
)
11997 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11998 else if (CHARPOS (startp
) > ZV
)
11999 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12001 /* Redisplay, then check if cursor has been set during the
12002 redisplay. Give up if new fonts were loaded. */
12003 if (!try_window (window
, startp
))
12005 w
->force_start
= Qt
;
12006 clear_glyph_matrix (w
->desired_matrix
);
12007 goto need_larger_matrices
;
12010 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12012 /* If point does not appear, try to move point so it does
12013 appear. The desired matrix has been built above, so we
12014 can use it here. */
12015 new_vpos
= window_box_height (w
) / 2;
12018 if (!make_cursor_line_fully_visible (w
, 0))
12020 /* Point does appear, but on a line partly visible at end of window.
12021 Move it back to a fully-visible line. */
12022 new_vpos
= window_box_height (w
);
12025 /* If we need to move point for either of the above reasons,
12026 now actually do it. */
12029 struct glyph_row
*row
;
12031 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12032 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12035 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12036 MATRIX_ROW_START_BYTEPOS (row
));
12038 if (w
!= XWINDOW (selected_window
))
12039 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12040 else if (current_buffer
== old
)
12041 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12043 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12045 /* If we are highlighting the region, then we just changed
12046 the region, so redisplay to show it. */
12047 if (!NILP (Vtransient_mark_mode
)
12048 && !NILP (current_buffer
->mark_active
))
12050 clear_glyph_matrix (w
->desired_matrix
);
12051 if (!try_window (window
, startp
))
12052 goto need_larger_matrices
;
12057 debug_method_add (w
, "forced window start");
12062 /* Handle case where text has not changed, only point, and it has
12063 not moved off the frame, and we are not retrying after hscroll.
12064 (current_matrix_up_to_date_p is nonzero when retrying.) */
12065 if (current_matrix_up_to_date_p
12066 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12067 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12071 case CURSOR_MOVEMENT_SUCCESS
:
12072 used_current_matrix_p
= 1;
12075 #if 0 /* try_cursor_movement never returns this value. */
12076 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12077 goto need_larger_matrices
;
12080 case CURSOR_MOVEMENT_MUST_SCROLL
:
12081 goto try_to_scroll
;
12087 /* If current starting point was originally the beginning of a line
12088 but no longer is, find a new starting point. */
12089 else if (!NILP (w
->start_at_line_beg
)
12090 && !(CHARPOS (startp
) <= BEGV
12091 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12094 debug_method_add (w
, "recenter 1");
12099 /* Try scrolling with try_window_id. Value is > 0 if update has
12100 been done, it is -1 if we know that the same window start will
12101 not work. It is 0 if unsuccessful for some other reason. */
12102 else if ((tem
= try_window_id (w
)) != 0)
12105 debug_method_add (w
, "try_window_id %d", tem
);
12108 if (fonts_changed_p
)
12109 goto need_larger_matrices
;
12113 /* Otherwise try_window_id has returned -1 which means that we
12114 don't want the alternative below this comment to execute. */
12116 else if (CHARPOS (startp
) >= BEGV
12117 && CHARPOS (startp
) <= ZV
12118 && PT
>= CHARPOS (startp
)
12119 && (CHARPOS (startp
) < ZV
12120 /* Avoid starting at end of buffer. */
12121 || CHARPOS (startp
) == BEGV
12122 || (XFASTINT (w
->last_modified
) >= MODIFF
12123 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12126 debug_method_add (w
, "same window start");
12129 /* Try to redisplay starting at same place as before.
12130 If point has not moved off frame, accept the results. */
12131 if (!current_matrix_up_to_date_p
12132 /* Don't use try_window_reusing_current_matrix in this case
12133 because a window scroll function can have changed the
12135 || !NILP (Vwindow_scroll_functions
)
12136 || MINI_WINDOW_P (w
)
12137 || !(used_current_matrix_p
12138 = try_window_reusing_current_matrix (w
)))
12140 IF_DEBUG (debug_method_add (w
, "1"));
12141 try_window (window
, startp
);
12144 if (fonts_changed_p
)
12145 goto need_larger_matrices
;
12147 if (w
->cursor
.vpos
>= 0)
12149 if (!just_this_one_p
12150 || current_buffer
->clip_changed
12151 || BEG_UNCHANGED
< CHARPOS (startp
))
12152 /* Forget any recorded base line for line number display. */
12153 w
->base_line_number
= Qnil
;
12155 if (!make_cursor_line_fully_visible (w
, 1))
12157 clear_glyph_matrix (w
->desired_matrix
);
12158 last_line_misfit
= 1;
12160 /* Drop through and scroll. */
12165 clear_glyph_matrix (w
->desired_matrix
);
12170 w
->last_modified
= make_number (0);
12171 w
->last_overlay_modified
= make_number (0);
12173 /* Redisplay the mode line. Select the buffer properly for that. */
12174 if (!update_mode_line
)
12176 update_mode_line
= 1;
12177 w
->update_mode_line
= Qt
;
12180 /* Try to scroll by specified few lines. */
12181 if ((scroll_conservatively
12183 || temp_scroll_step
12184 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12185 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12186 && !current_buffer
->clip_changed
12187 && CHARPOS (startp
) >= BEGV
12188 && CHARPOS (startp
) <= ZV
)
12190 /* The function returns -1 if new fonts were loaded, 1 if
12191 successful, 0 if not successful. */
12192 int rc
= try_scrolling (window
, just_this_one_p
,
12193 scroll_conservatively
,
12195 temp_scroll_step
, last_line_misfit
);
12198 case SCROLLING_SUCCESS
:
12201 case SCROLLING_NEED_LARGER_MATRICES
:
12202 goto need_larger_matrices
;
12204 case SCROLLING_FAILED
:
12212 /* Finally, just choose place to start which centers point */
12215 centering_position
= window_box_height (w
) / 2;
12218 /* Jump here with centering_position already set to 0. */
12221 debug_method_add (w
, "recenter");
12224 /* w->vscroll = 0; */
12226 /* Forget any previously recorded base line for line number display. */
12227 if (!buffer_unchanged_p
)
12228 w
->base_line_number
= Qnil
;
12230 /* Move backward half the height of the window. */
12231 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12232 it
.current_y
= it
.last_visible_y
;
12233 move_it_vertically_backward (&it
, centering_position
);
12234 xassert (IT_CHARPOS (it
) >= BEGV
);
12236 /* The function move_it_vertically_backward may move over more
12237 than the specified y-distance. If it->w is small, e.g. a
12238 mini-buffer window, we may end up in front of the window's
12239 display area. Start displaying at the start of the line
12240 containing PT in this case. */
12241 if (it
.current_y
<= 0)
12243 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12244 move_it_vertically_backward (&it
, 0);
12245 xassert (IT_CHARPOS (it
) <= PT
);
12249 it
.current_x
= it
.hpos
= 0;
12251 /* Set startp here explicitly in case that helps avoid an infinite loop
12252 in case the window-scroll-functions functions get errors. */
12253 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12255 /* Run scroll hooks. */
12256 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12258 /* Redisplay the window. */
12259 if (!current_matrix_up_to_date_p
12260 || windows_or_buffers_changed
12261 || cursor_type_changed
12262 /* Don't use try_window_reusing_current_matrix in this case
12263 because it can have changed the buffer. */
12264 || !NILP (Vwindow_scroll_functions
)
12265 || !just_this_one_p
12266 || MINI_WINDOW_P (w
)
12267 || !(used_current_matrix_p
12268 = try_window_reusing_current_matrix (w
)))
12269 try_window (window
, startp
);
12271 /* If new fonts have been loaded (due to fontsets), give up. We
12272 have to start a new redisplay since we need to re-adjust glyph
12274 if (fonts_changed_p
)
12275 goto need_larger_matrices
;
12277 /* If cursor did not appear assume that the middle of the window is
12278 in the first line of the window. Do it again with the next line.
12279 (Imagine a window of height 100, displaying two lines of height
12280 60. Moving back 50 from it->last_visible_y will end in the first
12282 if (w
->cursor
.vpos
< 0)
12284 if (!NILP (w
->window_end_valid
)
12285 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12287 clear_glyph_matrix (w
->desired_matrix
);
12288 move_it_by_lines (&it
, 1, 0);
12289 try_window (window
, it
.current
.pos
);
12291 else if (PT
< IT_CHARPOS (it
))
12293 clear_glyph_matrix (w
->desired_matrix
);
12294 move_it_by_lines (&it
, -1, 0);
12295 try_window (window
, it
.current
.pos
);
12299 /* Not much we can do about it. */
12303 /* Consider the following case: Window starts at BEGV, there is
12304 invisible, intangible text at BEGV, so that display starts at
12305 some point START > BEGV. It can happen that we are called with
12306 PT somewhere between BEGV and START. Try to handle that case. */
12307 if (w
->cursor
.vpos
< 0)
12309 struct glyph_row
*row
= w
->current_matrix
->rows
;
12310 if (row
->mode_line_p
)
12312 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12315 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12317 /* If vscroll is enabled, disable it and try again. */
12321 clear_glyph_matrix (w
->desired_matrix
);
12325 /* If centering point failed to make the whole line visible,
12326 put point at the top instead. That has to make the whole line
12327 visible, if it can be done. */
12328 if (centering_position
== 0)
12330 clear_glyph_matrix (w
->desired_matrix
);
12331 centering_position
= 0;
12337 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12338 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12339 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12342 /* Display the mode line, if we must. */
12343 if ((update_mode_line
12344 /* If window not full width, must redo its mode line
12345 if (a) the window to its side is being redone and
12346 (b) we do a frame-based redisplay. This is a consequence
12347 of how inverted lines are drawn in frame-based redisplay. */
12348 || (!just_this_one_p
12349 && !FRAME_WINDOW_P (f
)
12350 && !WINDOW_FULL_WIDTH_P (w
))
12351 /* Line number to display. */
12352 || INTEGERP (w
->base_line_pos
)
12353 /* Column number is displayed and different from the one displayed. */
12354 || (!NILP (w
->column_number_displayed
)
12355 && (XFASTINT (w
->column_number_displayed
)
12356 != (int) current_column ()))) /* iftc */
12357 /* This means that the window has a mode line. */
12358 && (WINDOW_WANTS_MODELINE_P (w
)
12359 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12361 display_mode_lines (w
);
12363 /* If mode line height has changed, arrange for a thorough
12364 immediate redisplay using the correct mode line height. */
12365 if (WINDOW_WANTS_MODELINE_P (w
)
12366 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12368 fonts_changed_p
= 1;
12369 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12370 = DESIRED_MODE_LINE_HEIGHT (w
);
12373 /* If top line height has changed, arrange for a thorough
12374 immediate redisplay using the correct mode line height. */
12375 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12376 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12378 fonts_changed_p
= 1;
12379 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12380 = DESIRED_HEADER_LINE_HEIGHT (w
);
12383 if (fonts_changed_p
)
12384 goto need_larger_matrices
;
12387 if (!line_number_displayed
12388 && !BUFFERP (w
->base_line_pos
))
12390 w
->base_line_pos
= Qnil
;
12391 w
->base_line_number
= Qnil
;
12396 /* When we reach a frame's selected window, redo the frame's menu bar. */
12397 if (update_mode_line
12398 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12400 int redisplay_menu_p
= 0;
12401 int redisplay_tool_bar_p
= 0;
12403 if (FRAME_WINDOW_P (f
))
12405 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12406 || defined (USE_GTK)
12407 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12409 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12413 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12415 if (redisplay_menu_p
)
12416 display_menu_bar (w
);
12418 #ifdef HAVE_WINDOW_SYSTEM
12420 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12422 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12423 && (FRAME_TOOL_BAR_LINES (f
) > 0
12424 || auto_resize_tool_bars_p
);
12428 if (redisplay_tool_bar_p
)
12429 redisplay_tool_bar (f
);
12433 #ifdef HAVE_WINDOW_SYSTEM
12434 if (FRAME_WINDOW_P (f
)
12435 && update_window_fringes (w
, 0)
12436 && !just_this_one_p
12437 && (used_current_matrix_p
|| overlay_arrow_seen
)
12438 && !w
->pseudo_window_p
)
12442 if (draw_window_fringes (w
, 1))
12443 x_draw_vertical_border (w
);
12447 #endif /* HAVE_WINDOW_SYSTEM */
12449 /* We go to this label, with fonts_changed_p nonzero,
12450 if it is necessary to try again using larger glyph matrices.
12451 We have to redeem the scroll bar even in this case,
12452 because the loop in redisplay_internal expects that. */
12453 need_larger_matrices
:
12455 finish_scroll_bars
:
12457 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12459 /* Set the thumb's position and size. */
12460 set_vertical_scroll_bar (w
);
12462 /* Note that we actually used the scroll bar attached to this
12463 window, so it shouldn't be deleted at the end of redisplay. */
12464 redeem_scroll_bar_hook (w
);
12467 /* Restore current_buffer and value of point in it. */
12468 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12469 set_buffer_internal_1 (old
);
12470 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12472 unbind_to (count
, Qnil
);
12476 /* Build the complete desired matrix of WINDOW with a window start
12477 buffer position POS. Value is non-zero if successful. It is zero
12478 if fonts were loaded during redisplay which makes re-adjusting
12479 glyph matrices necessary. */
12482 try_window (window
, pos
)
12483 Lisp_Object window
;
12484 struct text_pos pos
;
12486 struct window
*w
= XWINDOW (window
);
12488 struct glyph_row
*last_text_row
= NULL
;
12490 /* Make POS the new window start. */
12491 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12493 /* Mark cursor position as unknown. No overlay arrow seen. */
12494 w
->cursor
.vpos
= -1;
12495 overlay_arrow_seen
= 0;
12497 /* Initialize iterator and info to start at POS. */
12498 start_display (&it
, w
, pos
);
12500 /* Display all lines of W. */
12501 while (it
.current_y
< it
.last_visible_y
)
12503 if (display_line (&it
))
12504 last_text_row
= it
.glyph_row
- 1;
12505 if (fonts_changed_p
)
12509 /* If bottom moved off end of frame, change mode line percentage. */
12510 if (XFASTINT (w
->window_end_pos
) <= 0
12511 && Z
!= IT_CHARPOS (it
))
12512 w
->update_mode_line
= Qt
;
12514 /* Set window_end_pos to the offset of the last character displayed
12515 on the window from the end of current_buffer. Set
12516 window_end_vpos to its row number. */
12519 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12520 w
->window_end_bytepos
12521 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12523 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12525 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12526 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12527 ->displays_text_p
);
12531 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12532 w
->window_end_pos
= make_number (Z
- ZV
);
12533 w
->window_end_vpos
= make_number (0);
12536 /* But that is not valid info until redisplay finishes. */
12537 w
->window_end_valid
= Qnil
;
12543 /************************************************************************
12544 Window redisplay reusing current matrix when buffer has not changed
12545 ************************************************************************/
12547 /* Try redisplay of window W showing an unchanged buffer with a
12548 different window start than the last time it was displayed by
12549 reusing its current matrix. Value is non-zero if successful.
12550 W->start is the new window start. */
12553 try_window_reusing_current_matrix (w
)
12556 struct frame
*f
= XFRAME (w
->frame
);
12557 struct glyph_row
*row
, *bottom_row
;
12560 struct text_pos start
, new_start
;
12561 int nrows_scrolled
, i
;
12562 struct glyph_row
*last_text_row
;
12563 struct glyph_row
*last_reused_text_row
;
12564 struct glyph_row
*start_row
;
12565 int start_vpos
, min_y
, max_y
;
12568 if (inhibit_try_window_reusing
)
12572 if (/* This function doesn't handle terminal frames. */
12573 !FRAME_WINDOW_P (f
)
12574 /* Don't try to reuse the display if windows have been split
12576 || windows_or_buffers_changed
12577 || cursor_type_changed
)
12580 /* Can't do this if region may have changed. */
12581 if ((!NILP (Vtransient_mark_mode
)
12582 && !NILP (current_buffer
->mark_active
))
12583 || !NILP (w
->region_showing
)
12584 || !NILP (Vshow_trailing_whitespace
))
12587 /* If top-line visibility has changed, give up. */
12588 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12589 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12592 /* Give up if old or new display is scrolled vertically. We could
12593 make this function handle this, but right now it doesn't. */
12594 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12595 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12598 /* The variable new_start now holds the new window start. The old
12599 start `start' can be determined from the current matrix. */
12600 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12601 start
= start_row
->start
.pos
;
12602 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12604 /* Clear the desired matrix for the display below. */
12605 clear_glyph_matrix (w
->desired_matrix
);
12607 if (CHARPOS (new_start
) <= CHARPOS (start
))
12611 /* Don't use this method if the display starts with an ellipsis
12612 displayed for invisible text. It's not easy to handle that case
12613 below, and it's certainly not worth the effort since this is
12614 not a frequent case. */
12615 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12618 IF_DEBUG (debug_method_add (w
, "twu1"));
12620 /* Display up to a row that can be reused. The variable
12621 last_text_row is set to the last row displayed that displays
12622 text. Note that it.vpos == 0 if or if not there is a
12623 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12624 start_display (&it
, w
, new_start
);
12625 first_row_y
= it
.current_y
;
12626 w
->cursor
.vpos
= -1;
12627 last_text_row
= last_reused_text_row
= NULL
;
12629 while (it
.current_y
< it
.last_visible_y
12630 && !fonts_changed_p
)
12632 /* If we have reached into the characters in the START row,
12633 that means the line boundaries have changed. So we
12634 can't start copying with the row START. Maybe it will
12635 work to start copying with the following row. */
12636 while (IT_CHARPOS (it
) > CHARPOS (start
))
12638 /* Advance to the next row as the "start". */
12640 start
= start_row
->start
.pos
;
12641 /* If there are no more rows to try, or just one, give up. */
12642 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12643 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12644 || CHARPOS (start
) == ZV
)
12646 clear_glyph_matrix (w
->desired_matrix
);
12650 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12652 /* If we have reached alignment,
12653 we can copy the rest of the rows. */
12654 if (IT_CHARPOS (it
) == CHARPOS (start
))
12657 if (display_line (&it
))
12658 last_text_row
= it
.glyph_row
- 1;
12661 /* A value of current_y < last_visible_y means that we stopped
12662 at the previous window start, which in turn means that we
12663 have at least one reusable row. */
12664 if (it
.current_y
< it
.last_visible_y
)
12666 /* IT.vpos always starts from 0; it counts text lines. */
12667 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12669 /* Find PT if not already found in the lines displayed. */
12670 if (w
->cursor
.vpos
< 0)
12672 int dy
= it
.current_y
- start_row
->y
;
12674 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12675 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12677 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12678 dy
, nrows_scrolled
);
12681 clear_glyph_matrix (w
->desired_matrix
);
12686 /* Scroll the display. Do it before the current matrix is
12687 changed. The problem here is that update has not yet
12688 run, i.e. part of the current matrix is not up to date.
12689 scroll_run_hook will clear the cursor, and use the
12690 current matrix to get the height of the row the cursor is
12692 run
.current_y
= start_row
->y
;
12693 run
.desired_y
= it
.current_y
;
12694 run
.height
= it
.last_visible_y
- it
.current_y
;
12696 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12699 rif
->update_window_begin_hook (w
);
12700 rif
->clear_window_mouse_face (w
);
12701 rif
->scroll_run_hook (w
, &run
);
12702 rif
->update_window_end_hook (w
, 0, 0);
12706 /* Shift current matrix down by nrows_scrolled lines. */
12707 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12708 rotate_matrix (w
->current_matrix
,
12710 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12713 /* Disable lines that must be updated. */
12714 for (i
= 0; i
< it
.vpos
; ++i
)
12715 (start_row
+ i
)->enabled_p
= 0;
12717 /* Re-compute Y positions. */
12718 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12719 max_y
= it
.last_visible_y
;
12720 for (row
= start_row
+ nrows_scrolled
;
12724 row
->y
= it
.current_y
;
12725 row
->visible_height
= row
->height
;
12727 if (row
->y
< min_y
)
12728 row
->visible_height
-= min_y
- row
->y
;
12729 if (row
->y
+ row
->height
> max_y
)
12730 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12731 row
->redraw_fringe_bitmaps_p
= 1;
12733 it
.current_y
+= row
->height
;
12735 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12736 last_reused_text_row
= row
;
12737 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12741 /* Disable lines in the current matrix which are now
12742 below the window. */
12743 for (++row
; row
< bottom_row
; ++row
)
12744 row
->enabled_p
= 0;
12747 /* Update window_end_pos etc.; last_reused_text_row is the last
12748 reused row from the current matrix containing text, if any.
12749 The value of last_text_row is the last displayed line
12750 containing text. */
12751 if (last_reused_text_row
)
12753 w
->window_end_bytepos
12754 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12756 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12758 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12759 w
->current_matrix
));
12761 else if (last_text_row
)
12763 w
->window_end_bytepos
12764 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12766 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12768 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12772 /* This window must be completely empty. */
12773 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12774 w
->window_end_pos
= make_number (Z
- ZV
);
12775 w
->window_end_vpos
= make_number (0);
12777 w
->window_end_valid
= Qnil
;
12779 /* Update hint: don't try scrolling again in update_window. */
12780 w
->desired_matrix
->no_scrolling_p
= 1;
12783 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12787 else if (CHARPOS (new_start
) > CHARPOS (start
))
12789 struct glyph_row
*pt_row
, *row
;
12790 struct glyph_row
*first_reusable_row
;
12791 struct glyph_row
*first_row_to_display
;
12793 int yb
= window_text_bottom_y (w
);
12795 /* Find the row starting at new_start, if there is one. Don't
12796 reuse a partially visible line at the end. */
12797 first_reusable_row
= start_row
;
12798 while (first_reusable_row
->enabled_p
12799 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12800 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12801 < CHARPOS (new_start
)))
12802 ++first_reusable_row
;
12804 /* Give up if there is no row to reuse. */
12805 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12806 || !first_reusable_row
->enabled_p
12807 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12808 != CHARPOS (new_start
)))
12811 /* We can reuse fully visible rows beginning with
12812 first_reusable_row to the end of the window. Set
12813 first_row_to_display to the first row that cannot be reused.
12814 Set pt_row to the row containing point, if there is any. */
12816 for (first_row_to_display
= first_reusable_row
;
12817 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12818 ++first_row_to_display
)
12820 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12821 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12822 pt_row
= first_row_to_display
;
12825 /* Start displaying at the start of first_row_to_display. */
12826 xassert (first_row_to_display
->y
< yb
);
12827 init_to_row_start (&it
, w
, first_row_to_display
);
12829 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12831 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12833 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12834 + WINDOW_HEADER_LINE_HEIGHT (w
));
12836 /* Display lines beginning with first_row_to_display in the
12837 desired matrix. Set last_text_row to the last row displayed
12838 that displays text. */
12839 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12840 if (pt_row
== NULL
)
12841 w
->cursor
.vpos
= -1;
12842 last_text_row
= NULL
;
12843 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12844 if (display_line (&it
))
12845 last_text_row
= it
.glyph_row
- 1;
12847 /* Give up If point isn't in a row displayed or reused. */
12848 if (w
->cursor
.vpos
< 0)
12850 clear_glyph_matrix (w
->desired_matrix
);
12854 /* If point is in a reused row, adjust y and vpos of the cursor
12858 w
->cursor
.vpos
-= nrows_scrolled
;
12859 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
12862 /* Scroll the display. */
12863 run
.current_y
= first_reusable_row
->y
;
12864 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12865 run
.height
= it
.last_visible_y
- run
.current_y
;
12866 dy
= run
.current_y
- run
.desired_y
;
12871 rif
->update_window_begin_hook (w
);
12872 rif
->clear_window_mouse_face (w
);
12873 rif
->scroll_run_hook (w
, &run
);
12874 rif
->update_window_end_hook (w
, 0, 0);
12878 /* Adjust Y positions of reused rows. */
12879 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12880 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12881 max_y
= it
.last_visible_y
;
12882 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12885 row
->visible_height
= row
->height
;
12886 if (row
->y
< min_y
)
12887 row
->visible_height
-= min_y
- row
->y
;
12888 if (row
->y
+ row
->height
> max_y
)
12889 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12890 row
->redraw_fringe_bitmaps_p
= 1;
12893 /* Scroll the current matrix. */
12894 xassert (nrows_scrolled
> 0);
12895 rotate_matrix (w
->current_matrix
,
12897 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12900 /* Disable rows not reused. */
12901 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12902 row
->enabled_p
= 0;
12904 /* Point may have moved to a different line, so we cannot assume that
12905 the previous cursor position is valid; locate the correct row. */
12908 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12909 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
12913 w
->cursor
.y
= row
->y
;
12915 if (row
< bottom_row
)
12917 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
12918 while (glyph
->charpos
< PT
)
12921 w
->cursor
.x
+= glyph
->pixel_width
;
12927 /* Adjust window end. A null value of last_text_row means that
12928 the window end is in reused rows which in turn means that
12929 only its vpos can have changed. */
12932 w
->window_end_bytepos
12933 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12935 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12937 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12942 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12945 w
->window_end_valid
= Qnil
;
12946 w
->desired_matrix
->no_scrolling_p
= 1;
12949 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12959 /************************************************************************
12960 Window redisplay reusing current matrix when buffer has changed
12961 ************************************************************************/
12963 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12964 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12966 static struct glyph_row
*
12967 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12968 struct glyph_row
*));
12971 /* Return the last row in MATRIX displaying text. If row START is
12972 non-null, start searching with that row. IT gives the dimensions
12973 of the display. Value is null if matrix is empty; otherwise it is
12974 a pointer to the row found. */
12976 static struct glyph_row
*
12977 find_last_row_displaying_text (matrix
, it
, start
)
12978 struct glyph_matrix
*matrix
;
12980 struct glyph_row
*start
;
12982 struct glyph_row
*row
, *row_found
;
12984 /* Set row_found to the last row in IT->w's current matrix
12985 displaying text. The loop looks funny but think of partially
12988 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12989 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12991 xassert (row
->enabled_p
);
12993 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13002 /* Return the last row in the current matrix of W that is not affected
13003 by changes at the start of current_buffer that occurred since W's
13004 current matrix was built. Value is null if no such row exists.
13006 BEG_UNCHANGED us the number of characters unchanged at the start of
13007 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13008 first changed character in current_buffer. Characters at positions <
13009 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13010 when the current matrix was built. */
13012 static struct glyph_row
*
13013 find_last_unchanged_at_beg_row (w
)
13016 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13017 struct glyph_row
*row
;
13018 struct glyph_row
*row_found
= NULL
;
13019 int yb
= window_text_bottom_y (w
);
13021 /* Find the last row displaying unchanged text. */
13022 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13023 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13024 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13026 if (/* If row ends before first_changed_pos, it is unchanged,
13027 except in some case. */
13028 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13029 /* When row ends in ZV and we write at ZV it is not
13031 && !row
->ends_at_zv_p
13032 /* When first_changed_pos is the end of a continued line,
13033 row is not unchanged because it may be no longer
13035 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13036 && (row
->continued_p
13037 || row
->exact_window_width_line_p
)))
13040 /* Stop if last visible row. */
13041 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13051 /* Find the first glyph row in the current matrix of W that is not
13052 affected by changes at the end of current_buffer since the
13053 time W's current matrix was built.
13055 Return in *DELTA the number of chars by which buffer positions in
13056 unchanged text at the end of current_buffer must be adjusted.
13058 Return in *DELTA_BYTES the corresponding number of bytes.
13060 Value is null if no such row exists, i.e. all rows are affected by
13063 static struct glyph_row
*
13064 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13066 int *delta
, *delta_bytes
;
13068 struct glyph_row
*row
;
13069 struct glyph_row
*row_found
= NULL
;
13071 *delta
= *delta_bytes
= 0;
13073 /* Display must not have been paused, otherwise the current matrix
13074 is not up to date. */
13075 if (NILP (w
->window_end_valid
))
13078 /* A value of window_end_pos >= END_UNCHANGED means that the window
13079 end is in the range of changed text. If so, there is no
13080 unchanged row at the end of W's current matrix. */
13081 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13084 /* Set row to the last row in W's current matrix displaying text. */
13085 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13087 /* If matrix is entirely empty, no unchanged row exists. */
13088 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13090 /* The value of row is the last glyph row in the matrix having a
13091 meaningful buffer position in it. The end position of row
13092 corresponds to window_end_pos. This allows us to translate
13093 buffer positions in the current matrix to current buffer
13094 positions for characters not in changed text. */
13095 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13096 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13097 int last_unchanged_pos
, last_unchanged_pos_old
;
13098 struct glyph_row
*first_text_row
13099 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13101 *delta
= Z
- Z_old
;
13102 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13104 /* Set last_unchanged_pos to the buffer position of the last
13105 character in the buffer that has not been changed. Z is the
13106 index + 1 of the last character in current_buffer, i.e. by
13107 subtracting END_UNCHANGED we get the index of the last
13108 unchanged character, and we have to add BEG to get its buffer
13110 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13111 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13113 /* Search backward from ROW for a row displaying a line that
13114 starts at a minimum position >= last_unchanged_pos_old. */
13115 for (; row
> first_text_row
; --row
)
13117 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13120 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13125 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13132 /* Make sure that glyph rows in the current matrix of window W
13133 reference the same glyph memory as corresponding rows in the
13134 frame's frame matrix. This function is called after scrolling W's
13135 current matrix on a terminal frame in try_window_id and
13136 try_window_reusing_current_matrix. */
13139 sync_frame_with_window_matrix_rows (w
)
13142 struct frame
*f
= XFRAME (w
->frame
);
13143 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13145 /* Preconditions: W must be a leaf window and full-width. Its frame
13146 must have a frame matrix. */
13147 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13148 xassert (WINDOW_FULL_WIDTH_P (w
));
13149 xassert (!FRAME_WINDOW_P (f
));
13151 /* If W is a full-width window, glyph pointers in W's current matrix
13152 have, by definition, to be the same as glyph pointers in the
13153 corresponding frame matrix. Note that frame matrices have no
13154 marginal areas (see build_frame_matrix). */
13155 window_row
= w
->current_matrix
->rows
;
13156 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13157 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13158 while (window_row
< window_row_end
)
13160 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13161 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13163 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13164 frame_row
->glyphs
[TEXT_AREA
] = start
;
13165 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13166 frame_row
->glyphs
[LAST_AREA
] = end
;
13168 /* Disable frame rows whose corresponding window rows have
13169 been disabled in try_window_id. */
13170 if (!window_row
->enabled_p
)
13171 frame_row
->enabled_p
= 0;
13173 ++window_row
, ++frame_row
;
13178 /* Find the glyph row in window W containing CHARPOS. Consider all
13179 rows between START and END (not inclusive). END null means search
13180 all rows to the end of the display area of W. Value is the row
13181 containing CHARPOS or null. */
13184 row_containing_pos (w
, charpos
, start
, end
, dy
)
13187 struct glyph_row
*start
, *end
;
13190 struct glyph_row
*row
= start
;
13193 /* If we happen to start on a header-line, skip that. */
13194 if (row
->mode_line_p
)
13197 if ((end
&& row
>= end
) || !row
->enabled_p
)
13200 last_y
= window_text_bottom_y (w
) - dy
;
13204 /* Give up if we have gone too far. */
13205 if (end
&& row
>= end
)
13207 /* This formerly returned if they were equal.
13208 I think that both quantities are of a "last plus one" type;
13209 if so, when they are equal, the row is within the screen. -- rms. */
13210 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13213 /* If it is in this row, return this row. */
13214 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13215 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13216 /* The end position of a row equals the start
13217 position of the next row. If CHARPOS is there, we
13218 would rather display it in the next line, except
13219 when this line ends in ZV. */
13220 && !row
->ends_at_zv_p
13221 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13222 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13229 /* Try to redisplay window W by reusing its existing display. W's
13230 current matrix must be up to date when this function is called,
13231 i.e. window_end_valid must not be nil.
13235 1 if display has been updated
13236 0 if otherwise unsuccessful
13237 -1 if redisplay with same window start is known not to succeed
13239 The following steps are performed:
13241 1. Find the last row in the current matrix of W that is not
13242 affected by changes at the start of current_buffer. If no such row
13245 2. Find the first row in W's current matrix that is not affected by
13246 changes at the end of current_buffer. Maybe there is no such row.
13248 3. Display lines beginning with the row + 1 found in step 1 to the
13249 row found in step 2 or, if step 2 didn't find a row, to the end of
13252 4. If cursor is not known to appear on the window, give up.
13254 5. If display stopped at the row found in step 2, scroll the
13255 display and current matrix as needed.
13257 6. Maybe display some lines at the end of W, if we must. This can
13258 happen under various circumstances, like a partially visible line
13259 becoming fully visible, or because newly displayed lines are displayed
13260 in smaller font sizes.
13262 7. Update W's window end information. */
13268 struct frame
*f
= XFRAME (w
->frame
);
13269 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13270 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13271 struct glyph_row
*last_unchanged_at_beg_row
;
13272 struct glyph_row
*first_unchanged_at_end_row
;
13273 struct glyph_row
*row
;
13274 struct glyph_row
*bottom_row
;
13277 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13278 struct text_pos start_pos
;
13280 int first_unchanged_at_end_vpos
= 0;
13281 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13282 struct text_pos start
;
13283 int first_changed_charpos
, last_changed_charpos
;
13286 if (inhibit_try_window_id
)
13290 /* This is handy for debugging. */
13292 #define GIVE_UP(X) \
13294 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13298 #define GIVE_UP(X) return 0
13301 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13303 /* Don't use this for mini-windows because these can show
13304 messages and mini-buffers, and we don't handle that here. */
13305 if (MINI_WINDOW_P (w
))
13308 /* This flag is used to prevent redisplay optimizations. */
13309 if (windows_or_buffers_changed
|| cursor_type_changed
)
13312 /* Verify that narrowing has not changed.
13313 Also verify that we were not told to prevent redisplay optimizations.
13314 It would be nice to further
13315 reduce the number of cases where this prevents try_window_id. */
13316 if (current_buffer
->clip_changed
13317 || current_buffer
->prevent_redisplay_optimizations_p
)
13320 /* Window must either use window-based redisplay or be full width. */
13321 if (!FRAME_WINDOW_P (f
)
13322 && (!line_ins_del_ok
13323 || !WINDOW_FULL_WIDTH_P (w
)))
13326 /* Give up if point is not known NOT to appear in W. */
13327 if (PT
< CHARPOS (start
))
13330 /* Another way to prevent redisplay optimizations. */
13331 if (XFASTINT (w
->last_modified
) == 0)
13334 /* Verify that window is not hscrolled. */
13335 if (XFASTINT (w
->hscroll
) != 0)
13338 /* Verify that display wasn't paused. */
13339 if (NILP (w
->window_end_valid
))
13342 /* Can't use this if highlighting a region because a cursor movement
13343 will do more than just set the cursor. */
13344 if (!NILP (Vtransient_mark_mode
)
13345 && !NILP (current_buffer
->mark_active
))
13348 /* Likewise if highlighting trailing whitespace. */
13349 if (!NILP (Vshow_trailing_whitespace
))
13352 /* Likewise if showing a region. */
13353 if (!NILP (w
->region_showing
))
13356 /* Can use this if overlay arrow position and or string have changed. */
13357 if (overlay_arrows_changed_p ())
13361 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13362 only if buffer has really changed. The reason is that the gap is
13363 initially at Z for freshly visited files. The code below would
13364 set end_unchanged to 0 in that case. */
13365 if (MODIFF
> SAVE_MODIFF
13366 /* This seems to happen sometimes after saving a buffer. */
13367 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13369 if (GPT
- BEG
< BEG_UNCHANGED
)
13370 BEG_UNCHANGED
= GPT
- BEG
;
13371 if (Z
- GPT
< END_UNCHANGED
)
13372 END_UNCHANGED
= Z
- GPT
;
13375 /* The position of the first and last character that has been changed. */
13376 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13377 last_changed_charpos
= Z
- END_UNCHANGED
;
13379 /* If window starts after a line end, and the last change is in
13380 front of that newline, then changes don't affect the display.
13381 This case happens with stealth-fontification. Note that although
13382 the display is unchanged, glyph positions in the matrix have to
13383 be adjusted, of course. */
13384 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13385 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13386 && ((last_changed_charpos
< CHARPOS (start
)
13387 && CHARPOS (start
) == BEGV
)
13388 || (last_changed_charpos
< CHARPOS (start
) - 1
13389 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13391 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13392 struct glyph_row
*r0
;
13394 /* Compute how many chars/bytes have been added to or removed
13395 from the buffer. */
13396 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13397 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13399 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13401 /* Give up if PT is not in the window. Note that it already has
13402 been checked at the start of try_window_id that PT is not in
13403 front of the window start. */
13404 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13407 /* If window start is unchanged, we can reuse the whole matrix
13408 as is, after adjusting glyph positions. No need to compute
13409 the window end again, since its offset from Z hasn't changed. */
13410 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13411 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13412 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13413 /* PT must not be in a partially visible line. */
13414 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13415 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13417 /* Adjust positions in the glyph matrix. */
13418 if (delta
|| delta_bytes
)
13420 struct glyph_row
*r1
13421 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13422 increment_matrix_positions (w
->current_matrix
,
13423 MATRIX_ROW_VPOS (r0
, current_matrix
),
13424 MATRIX_ROW_VPOS (r1
, current_matrix
),
13425 delta
, delta_bytes
);
13428 /* Set the cursor. */
13429 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13431 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13438 /* Handle the case that changes are all below what is displayed in
13439 the window, and that PT is in the window. This shortcut cannot
13440 be taken if ZV is visible in the window, and text has been added
13441 there that is visible in the window. */
13442 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13443 /* ZV is not visible in the window, or there are no
13444 changes at ZV, actually. */
13445 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13446 || first_changed_charpos
== last_changed_charpos
))
13448 struct glyph_row
*r0
;
13450 /* Give up if PT is not in the window. Note that it already has
13451 been checked at the start of try_window_id that PT is not in
13452 front of the window start. */
13453 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13456 /* If window start is unchanged, we can reuse the whole matrix
13457 as is, without changing glyph positions since no text has
13458 been added/removed in front of the window end. */
13459 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13460 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13461 /* PT must not be in a partially visible line. */
13462 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13463 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13465 /* We have to compute the window end anew since text
13466 can have been added/removed after it. */
13468 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13469 w
->window_end_bytepos
13470 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13472 /* Set the cursor. */
13473 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13475 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13482 /* Give up if window start is in the changed area.
13484 The condition used to read
13486 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13488 but why that was tested escapes me at the moment. */
13489 if (CHARPOS (start
) >= first_changed_charpos
13490 && CHARPOS (start
) <= last_changed_charpos
)
13493 /* Check that window start agrees with the start of the first glyph
13494 row in its current matrix. Check this after we know the window
13495 start is not in changed text, otherwise positions would not be
13497 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13498 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13501 /* Give up if the window ends in strings. Overlay strings
13502 at the end are difficult to handle, so don't try. */
13503 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13504 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13507 /* Compute the position at which we have to start displaying new
13508 lines. Some of the lines at the top of the window might be
13509 reusable because they are not displaying changed text. Find the
13510 last row in W's current matrix not affected by changes at the
13511 start of current_buffer. Value is null if changes start in the
13512 first line of window. */
13513 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13514 if (last_unchanged_at_beg_row
)
13516 /* Avoid starting to display in the moddle of a character, a TAB
13517 for instance. This is easier than to set up the iterator
13518 exactly, and it's not a frequent case, so the additional
13519 effort wouldn't really pay off. */
13520 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13521 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13522 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13523 --last_unchanged_at_beg_row
;
13525 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13528 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13530 start_pos
= it
.current
.pos
;
13532 /* Start displaying new lines in the desired matrix at the same
13533 vpos we would use in the current matrix, i.e. below
13534 last_unchanged_at_beg_row. */
13535 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13537 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13538 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13540 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13544 /* There are no reusable lines at the start of the window.
13545 Start displaying in the first text line. */
13546 start_display (&it
, w
, start
);
13547 it
.vpos
= it
.first_vpos
;
13548 start_pos
= it
.current
.pos
;
13551 /* Find the first row that is not affected by changes at the end of
13552 the buffer. Value will be null if there is no unchanged row, in
13553 which case we must redisplay to the end of the window. delta
13554 will be set to the value by which buffer positions beginning with
13555 first_unchanged_at_end_row have to be adjusted due to text
13557 first_unchanged_at_end_row
13558 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13559 IF_DEBUG (debug_delta
= delta
);
13560 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13562 /* Set stop_pos to the buffer position up to which we will have to
13563 display new lines. If first_unchanged_at_end_row != NULL, this
13564 is the buffer position of the start of the line displayed in that
13565 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13566 that we don't stop at a buffer position. */
13568 if (first_unchanged_at_end_row
)
13570 xassert (last_unchanged_at_beg_row
== NULL
13571 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13573 /* If this is a continuation line, move forward to the next one
13574 that isn't. Changes in lines above affect this line.
13575 Caution: this may move first_unchanged_at_end_row to a row
13576 not displaying text. */
13577 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13578 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13579 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13580 < it
.last_visible_y
))
13581 ++first_unchanged_at_end_row
;
13583 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13584 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13585 >= it
.last_visible_y
))
13586 first_unchanged_at_end_row
= NULL
;
13589 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13591 first_unchanged_at_end_vpos
13592 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13593 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13596 else if (last_unchanged_at_beg_row
== NULL
)
13602 /* Either there is no unchanged row at the end, or the one we have
13603 now displays text. This is a necessary condition for the window
13604 end pos calculation at the end of this function. */
13605 xassert (first_unchanged_at_end_row
== NULL
13606 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13608 debug_last_unchanged_at_beg_vpos
13609 = (last_unchanged_at_beg_row
13610 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13612 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13614 #endif /* GLYPH_DEBUG != 0 */
13617 /* Display new lines. Set last_text_row to the last new line
13618 displayed which has text on it, i.e. might end up as being the
13619 line where the window_end_vpos is. */
13620 w
->cursor
.vpos
= -1;
13621 last_text_row
= NULL
;
13622 overlay_arrow_seen
= 0;
13623 while (it
.current_y
< it
.last_visible_y
13624 && !fonts_changed_p
13625 && (first_unchanged_at_end_row
== NULL
13626 || IT_CHARPOS (it
) < stop_pos
))
13628 if (display_line (&it
))
13629 last_text_row
= it
.glyph_row
- 1;
13632 if (fonts_changed_p
)
13636 /* Compute differences in buffer positions, y-positions etc. for
13637 lines reused at the bottom of the window. Compute what we can
13639 if (first_unchanged_at_end_row
13640 /* No lines reused because we displayed everything up to the
13641 bottom of the window. */
13642 && it
.current_y
< it
.last_visible_y
)
13645 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13647 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13648 run
.current_y
= first_unchanged_at_end_row
->y
;
13649 run
.desired_y
= run
.current_y
+ dy
;
13650 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13654 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13655 first_unchanged_at_end_row
= NULL
;
13657 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13660 /* Find the cursor if not already found. We have to decide whether
13661 PT will appear on this window (it sometimes doesn't, but this is
13662 not a very frequent case.) This decision has to be made before
13663 the current matrix is altered. A value of cursor.vpos < 0 means
13664 that PT is either in one of the lines beginning at
13665 first_unchanged_at_end_row or below the window. Don't care for
13666 lines that might be displayed later at the window end; as
13667 mentioned, this is not a frequent case. */
13668 if (w
->cursor
.vpos
< 0)
13670 /* Cursor in unchanged rows at the top? */
13671 if (PT
< CHARPOS (start_pos
)
13672 && last_unchanged_at_beg_row
)
13674 row
= row_containing_pos (w
, PT
,
13675 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13676 last_unchanged_at_beg_row
+ 1, 0);
13678 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13681 /* Start from first_unchanged_at_end_row looking for PT. */
13682 else if (first_unchanged_at_end_row
)
13684 row
= row_containing_pos (w
, PT
- delta
,
13685 first_unchanged_at_end_row
, NULL
, 0);
13687 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13688 delta_bytes
, dy
, dvpos
);
13691 /* Give up if cursor was not found. */
13692 if (w
->cursor
.vpos
< 0)
13694 clear_glyph_matrix (w
->desired_matrix
);
13699 /* Don't let the cursor end in the scroll margins. */
13701 int this_scroll_margin
, cursor_height
;
13703 this_scroll_margin
= max (0, scroll_margin
);
13704 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13705 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13706 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13708 if ((w
->cursor
.y
< this_scroll_margin
13709 && CHARPOS (start
) > BEGV
)
13710 /* Old redisplay didn't take scroll margin into account at the bottom,
13711 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13712 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13713 ? cursor_height
+ this_scroll_margin
13714 : 1)) > it
.last_visible_y
)
13716 w
->cursor
.vpos
= -1;
13717 clear_glyph_matrix (w
->desired_matrix
);
13722 /* Scroll the display. Do it before changing the current matrix so
13723 that xterm.c doesn't get confused about where the cursor glyph is
13725 if (dy
&& run
.height
)
13729 if (FRAME_WINDOW_P (f
))
13731 rif
->update_window_begin_hook (w
);
13732 rif
->clear_window_mouse_face (w
);
13733 rif
->scroll_run_hook (w
, &run
);
13734 rif
->update_window_end_hook (w
, 0, 0);
13738 /* Terminal frame. In this case, dvpos gives the number of
13739 lines to scroll by; dvpos < 0 means scroll up. */
13740 int first_unchanged_at_end_vpos
13741 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13742 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13743 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13744 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13745 + window_internal_height (w
));
13747 /* Perform the operation on the screen. */
13750 /* Scroll last_unchanged_at_beg_row to the end of the
13751 window down dvpos lines. */
13752 set_terminal_window (end
);
13754 /* On dumb terminals delete dvpos lines at the end
13755 before inserting dvpos empty lines. */
13756 if (!scroll_region_ok
)
13757 ins_del_lines (end
- dvpos
, -dvpos
);
13759 /* Insert dvpos empty lines in front of
13760 last_unchanged_at_beg_row. */
13761 ins_del_lines (from
, dvpos
);
13763 else if (dvpos
< 0)
13765 /* Scroll up last_unchanged_at_beg_vpos to the end of
13766 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13767 set_terminal_window (end
);
13769 /* Delete dvpos lines in front of
13770 last_unchanged_at_beg_vpos. ins_del_lines will set
13771 the cursor to the given vpos and emit |dvpos| delete
13773 ins_del_lines (from
+ dvpos
, dvpos
);
13775 /* On a dumb terminal insert dvpos empty lines at the
13777 if (!scroll_region_ok
)
13778 ins_del_lines (end
+ dvpos
, -dvpos
);
13781 set_terminal_window (0);
13787 /* Shift reused rows of the current matrix to the right position.
13788 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13790 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13791 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13794 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13795 bottom_vpos
, dvpos
);
13796 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13799 else if (dvpos
> 0)
13801 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13802 bottom_vpos
, dvpos
);
13803 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13804 first_unchanged_at_end_vpos
+ dvpos
, 0);
13807 /* For frame-based redisplay, make sure that current frame and window
13808 matrix are in sync with respect to glyph memory. */
13809 if (!FRAME_WINDOW_P (f
))
13810 sync_frame_with_window_matrix_rows (w
);
13812 /* Adjust buffer positions in reused rows. */
13814 increment_matrix_positions (current_matrix
,
13815 first_unchanged_at_end_vpos
+ dvpos
,
13816 bottom_vpos
, delta
, delta_bytes
);
13818 /* Adjust Y positions. */
13820 shift_glyph_matrix (w
, current_matrix
,
13821 first_unchanged_at_end_vpos
+ dvpos
,
13824 if (first_unchanged_at_end_row
)
13825 first_unchanged_at_end_row
+= dvpos
;
13827 /* If scrolling up, there may be some lines to display at the end of
13829 last_text_row_at_end
= NULL
;
13832 /* Scrolling up can leave for example a partially visible line
13833 at the end of the window to be redisplayed. */
13834 /* Set last_row to the glyph row in the current matrix where the
13835 window end line is found. It has been moved up or down in
13836 the matrix by dvpos. */
13837 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13838 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13840 /* If last_row is the window end line, it should display text. */
13841 xassert (last_row
->displays_text_p
);
13843 /* If window end line was partially visible before, begin
13844 displaying at that line. Otherwise begin displaying with the
13845 line following it. */
13846 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13848 init_to_row_start (&it
, w
, last_row
);
13849 it
.vpos
= last_vpos
;
13850 it
.current_y
= last_row
->y
;
13854 init_to_row_end (&it
, w
, last_row
);
13855 it
.vpos
= 1 + last_vpos
;
13856 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13860 /* We may start in a continuation line. If so, we have to
13861 get the right continuation_lines_width and current_x. */
13862 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13863 it
.hpos
= it
.current_x
= 0;
13865 /* Display the rest of the lines at the window end. */
13866 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13867 while (it
.current_y
< it
.last_visible_y
13868 && !fonts_changed_p
)
13870 /* Is it always sure that the display agrees with lines in
13871 the current matrix? I don't think so, so we mark rows
13872 displayed invalid in the current matrix by setting their
13873 enabled_p flag to zero. */
13874 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13875 if (display_line (&it
))
13876 last_text_row_at_end
= it
.glyph_row
- 1;
13880 /* Update window_end_pos and window_end_vpos. */
13881 if (first_unchanged_at_end_row
13882 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13883 && !last_text_row_at_end
)
13885 /* Window end line if one of the preserved rows from the current
13886 matrix. Set row to the last row displaying text in current
13887 matrix starting at first_unchanged_at_end_row, after
13889 xassert (first_unchanged_at_end_row
->displays_text_p
);
13890 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13891 first_unchanged_at_end_row
);
13892 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13894 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13895 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13897 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13898 xassert (w
->window_end_bytepos
>= 0);
13899 IF_DEBUG (debug_method_add (w
, "A"));
13901 else if (last_text_row_at_end
)
13904 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13905 w
->window_end_bytepos
13906 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13908 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13909 xassert (w
->window_end_bytepos
>= 0);
13910 IF_DEBUG (debug_method_add (w
, "B"));
13912 else if (last_text_row
)
13914 /* We have displayed either to the end of the window or at the
13915 end of the window, i.e. the last row with text is to be found
13916 in the desired matrix. */
13918 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13919 w
->window_end_bytepos
13920 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13922 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13923 xassert (w
->window_end_bytepos
>= 0);
13925 else if (first_unchanged_at_end_row
== NULL
13926 && last_text_row
== NULL
13927 && last_text_row_at_end
== NULL
)
13929 /* Displayed to end of window, but no line containing text was
13930 displayed. Lines were deleted at the end of the window. */
13931 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13932 int vpos
= XFASTINT (w
->window_end_vpos
);
13933 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13934 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13937 row
== NULL
&& vpos
>= first_vpos
;
13938 --vpos
, --current_row
, --desired_row
)
13940 if (desired_row
->enabled_p
)
13942 if (desired_row
->displays_text_p
)
13945 else if (current_row
->displays_text_p
)
13949 xassert (row
!= NULL
);
13950 w
->window_end_vpos
= make_number (vpos
+ 1);
13951 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13952 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13953 xassert (w
->window_end_bytepos
>= 0);
13954 IF_DEBUG (debug_method_add (w
, "C"));
13959 #if 0 /* This leads to problems, for instance when the cursor is
13960 at ZV, and the cursor line displays no text. */
13961 /* Disable rows below what's displayed in the window. This makes
13962 debugging easier. */
13963 enable_glyph_matrix_rows (current_matrix
,
13964 XFASTINT (w
->window_end_vpos
) + 1,
13968 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13969 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13971 /* Record that display has not been completed. */
13972 w
->window_end_valid
= Qnil
;
13973 w
->desired_matrix
->no_scrolling_p
= 1;
13981 /***********************************************************************
13982 More debugging support
13983 ***********************************************************************/
13987 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13988 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13989 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13992 /* Dump the contents of glyph matrix MATRIX on stderr.
13994 GLYPHS 0 means don't show glyph contents.
13995 GLYPHS 1 means show glyphs in short form
13996 GLYPHS > 1 means show glyphs in long form. */
13999 dump_glyph_matrix (matrix
, glyphs
)
14000 struct glyph_matrix
*matrix
;
14004 for (i
= 0; i
< matrix
->nrows
; ++i
)
14005 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14009 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14010 the glyph row and area where the glyph comes from. */
14013 dump_glyph (row
, glyph
, area
)
14014 struct glyph_row
*row
;
14015 struct glyph
*glyph
;
14018 if (glyph
->type
== CHAR_GLYPH
)
14021 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14022 glyph
- row
->glyphs
[TEXT_AREA
],
14025 (BUFFERP (glyph
->object
)
14027 : (STRINGP (glyph
->object
)
14030 glyph
->pixel_width
,
14032 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14036 glyph
->left_box_line_p
,
14037 glyph
->right_box_line_p
);
14039 else if (glyph
->type
== STRETCH_GLYPH
)
14042 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14043 glyph
- row
->glyphs
[TEXT_AREA
],
14046 (BUFFERP (glyph
->object
)
14048 : (STRINGP (glyph
->object
)
14051 glyph
->pixel_width
,
14055 glyph
->left_box_line_p
,
14056 glyph
->right_box_line_p
);
14058 else if (glyph
->type
== IMAGE_GLYPH
)
14061 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14062 glyph
- row
->glyphs
[TEXT_AREA
],
14065 (BUFFERP (glyph
->object
)
14067 : (STRINGP (glyph
->object
)
14070 glyph
->pixel_width
,
14074 glyph
->left_box_line_p
,
14075 glyph
->right_box_line_p
);
14080 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14081 GLYPHS 0 means don't show glyph contents.
14082 GLYPHS 1 means show glyphs in short form
14083 GLYPHS > 1 means show glyphs in long form. */
14086 dump_glyph_row (row
, vpos
, glyphs
)
14087 struct glyph_row
*row
;
14092 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
14093 fprintf (stderr
, "=======================================================================\n");
14095 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
14096 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14098 MATRIX_ROW_START_CHARPOS (row
),
14099 MATRIX_ROW_END_CHARPOS (row
),
14100 row
->used
[TEXT_AREA
],
14101 row
->contains_overlapping_glyphs_p
,
14103 row
->truncated_on_left_p
,
14104 row
->truncated_on_right_p
,
14105 row
->overlay_arrow_p
,
14107 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14108 row
->displays_text_p
,
14111 row
->ends_in_middle_of_char_p
,
14112 row
->starts_in_middle_of_char_p
,
14118 row
->visible_height
,
14121 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14122 row
->end
.overlay_string_index
,
14123 row
->continuation_lines_width
);
14124 fprintf (stderr
, "%9d %5d\n",
14125 CHARPOS (row
->start
.string_pos
),
14126 CHARPOS (row
->end
.string_pos
));
14127 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14128 row
->end
.dpvec_index
);
14135 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14137 struct glyph
*glyph
= row
->glyphs
[area
];
14138 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14140 /* Glyph for a line end in text. */
14141 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14144 if (glyph
< glyph_end
)
14145 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14147 for (; glyph
< glyph_end
; ++glyph
)
14148 dump_glyph (row
, glyph
, area
);
14151 else if (glyphs
== 1)
14155 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14157 char *s
= (char *) alloca (row
->used
[area
] + 1);
14160 for (i
= 0; i
< row
->used
[area
]; ++i
)
14162 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14163 if (glyph
->type
== CHAR_GLYPH
14164 && glyph
->u
.ch
< 0x80
14165 && glyph
->u
.ch
>= ' ')
14166 s
[i
] = glyph
->u
.ch
;
14172 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14178 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14179 Sdump_glyph_matrix
, 0, 1, "p",
14180 doc
: /* Dump the current matrix of the selected window to stderr.
14181 Shows contents of glyph row structures. With non-nil
14182 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14183 glyphs in short form, otherwise show glyphs in long form. */)
14185 Lisp_Object glyphs
;
14187 struct window
*w
= XWINDOW (selected_window
);
14188 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14190 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14191 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14192 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14193 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14194 fprintf (stderr
, "=============================================\n");
14195 dump_glyph_matrix (w
->current_matrix
,
14196 NILP (glyphs
) ? 0 : XINT (glyphs
));
14201 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14202 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14205 struct frame
*f
= XFRAME (selected_frame
);
14206 dump_glyph_matrix (f
->current_matrix
, 1);
14211 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14212 doc
: /* Dump glyph row ROW to stderr.
14213 GLYPH 0 means don't dump glyphs.
14214 GLYPH 1 means dump glyphs in short form.
14215 GLYPH > 1 or omitted means dump glyphs in long form. */)
14217 Lisp_Object row
, glyphs
;
14219 struct glyph_matrix
*matrix
;
14222 CHECK_NUMBER (row
);
14223 matrix
= XWINDOW (selected_window
)->current_matrix
;
14225 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14226 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14228 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14233 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14234 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14235 GLYPH 0 means don't dump glyphs.
14236 GLYPH 1 means dump glyphs in short form.
14237 GLYPH > 1 or omitted means dump glyphs in long form. */)
14239 Lisp_Object row
, glyphs
;
14241 struct frame
*sf
= SELECTED_FRAME ();
14242 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14245 CHECK_NUMBER (row
);
14247 if (vpos
>= 0 && vpos
< m
->nrows
)
14248 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14249 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14254 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14255 doc
: /* Toggle tracing of redisplay.
14256 With ARG, turn tracing on if and only if ARG is positive. */)
14261 trace_redisplay_p
= !trace_redisplay_p
;
14264 arg
= Fprefix_numeric_value (arg
);
14265 trace_redisplay_p
= XINT (arg
) > 0;
14272 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14273 doc
: /* Like `format', but print result to stderr.
14274 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14279 Lisp_Object s
= Fformat (nargs
, args
);
14280 fprintf (stderr
, "%s", SDATA (s
));
14284 #endif /* GLYPH_DEBUG */
14288 /***********************************************************************
14289 Building Desired Matrix Rows
14290 ***********************************************************************/
14292 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14293 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14295 static struct glyph_row
*
14296 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14298 Lisp_Object overlay_arrow_string
;
14300 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14301 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14302 struct buffer
*old
= current_buffer
;
14303 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14304 int arrow_len
= SCHARS (overlay_arrow_string
);
14305 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14306 const unsigned char *p
;
14309 int n_glyphs_before
;
14311 set_buffer_temp (buffer
);
14312 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14313 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14314 SET_TEXT_POS (it
.position
, 0, 0);
14316 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14318 while (p
< arrow_end
)
14320 Lisp_Object face
, ilisp
;
14322 /* Get the next character. */
14324 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14326 it
.c
= *p
, it
.len
= 1;
14329 /* Get its face. */
14330 ilisp
= make_number (p
- arrow_string
);
14331 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14332 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14334 /* Compute its width, get its glyphs. */
14335 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14336 SET_TEXT_POS (it
.position
, -1, -1);
14337 PRODUCE_GLYPHS (&it
);
14339 /* If this character doesn't fit any more in the line, we have
14340 to remove some glyphs. */
14341 if (it
.current_x
> it
.last_visible_x
)
14343 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14348 set_buffer_temp (old
);
14349 return it
.glyph_row
;
14353 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14354 glyphs are only inserted for terminal frames since we can't really
14355 win with truncation glyphs when partially visible glyphs are
14356 involved. Which glyphs to insert is determined by
14357 produce_special_glyphs. */
14360 insert_left_trunc_glyphs (it
)
14363 struct it truncate_it
;
14364 struct glyph
*from
, *end
, *to
, *toend
;
14366 xassert (!FRAME_WINDOW_P (it
->f
));
14368 /* Get the truncation glyphs. */
14370 truncate_it
.current_x
= 0;
14371 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14372 truncate_it
.glyph_row
= &scratch_glyph_row
;
14373 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14374 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14375 truncate_it
.object
= make_number (0);
14376 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14378 /* Overwrite glyphs from IT with truncation glyphs. */
14379 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14380 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14381 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14382 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14387 /* There may be padding glyphs left over. Overwrite them too. */
14388 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14390 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14396 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14400 /* Compute the pixel height and width of IT->glyph_row.
14402 Most of the time, ascent and height of a display line will be equal
14403 to the max_ascent and max_height values of the display iterator
14404 structure. This is not the case if
14406 1. We hit ZV without displaying anything. In this case, max_ascent
14407 and max_height will be zero.
14409 2. We have some glyphs that don't contribute to the line height.
14410 (The glyph row flag contributes_to_line_height_p is for future
14411 pixmap extensions).
14413 The first case is easily covered by using default values because in
14414 these cases, the line height does not really matter, except that it
14415 must not be zero. */
14418 compute_line_metrics (it
)
14421 struct glyph_row
*row
= it
->glyph_row
;
14424 if (FRAME_WINDOW_P (it
->f
))
14426 int i
, min_y
, max_y
;
14428 /* The line may consist of one space only, that was added to
14429 place the cursor on it. If so, the row's height hasn't been
14431 if (row
->height
== 0)
14433 if (it
->max_ascent
+ it
->max_descent
== 0)
14434 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14435 row
->ascent
= it
->max_ascent
;
14436 row
->height
= it
->max_ascent
+ it
->max_descent
;
14437 row
->phys_ascent
= it
->max_phys_ascent
;
14438 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14439 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14442 /* Compute the width of this line. */
14443 row
->pixel_width
= row
->x
;
14444 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14445 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14447 xassert (row
->pixel_width
>= 0);
14448 xassert (row
->ascent
>= 0 && row
->height
> 0);
14450 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14451 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14453 /* If first line's physical ascent is larger than its logical
14454 ascent, use the physical ascent, and make the row taller.
14455 This makes accented characters fully visible. */
14456 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14457 && row
->phys_ascent
> row
->ascent
)
14459 row
->height
+= row
->phys_ascent
- row
->ascent
;
14460 row
->ascent
= row
->phys_ascent
;
14463 /* Compute how much of the line is visible. */
14464 row
->visible_height
= row
->height
;
14466 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14467 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14469 if (row
->y
< min_y
)
14470 row
->visible_height
-= min_y
- row
->y
;
14471 if (row
->y
+ row
->height
> max_y
)
14472 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14476 row
->pixel_width
= row
->used
[TEXT_AREA
];
14477 if (row
->continued_p
)
14478 row
->pixel_width
-= it
->continuation_pixel_width
;
14479 else if (row
->truncated_on_right_p
)
14480 row
->pixel_width
-= it
->truncation_pixel_width
;
14481 row
->ascent
= row
->phys_ascent
= 0;
14482 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14483 row
->extra_line_spacing
= 0;
14486 /* Compute a hash code for this row. */
14488 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14489 for (i
= 0; i
< row
->used
[area
]; ++i
)
14490 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14491 + row
->glyphs
[area
][i
].u
.val
14492 + row
->glyphs
[area
][i
].face_id
14493 + row
->glyphs
[area
][i
].padding_p
14494 + (row
->glyphs
[area
][i
].type
<< 2));
14496 it
->max_ascent
= it
->max_descent
= 0;
14497 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14501 /* Append one space to the glyph row of iterator IT if doing a
14502 window-based redisplay. The space has the same face as
14503 IT->face_id. Value is non-zero if a space was added.
14505 This function is called to make sure that there is always one glyph
14506 at the end of a glyph row that the cursor can be set on under
14507 window-systems. (If there weren't such a glyph we would not know
14508 how wide and tall a box cursor should be displayed).
14510 At the same time this space let's a nicely handle clearing to the
14511 end of the line if the row ends in italic text. */
14514 append_space_for_newline (it
, default_face_p
)
14516 int default_face_p
;
14518 if (FRAME_WINDOW_P (it
->f
))
14520 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14522 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14523 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14525 /* Save some values that must not be changed.
14526 Must save IT->c and IT->len because otherwise
14527 ITERATOR_AT_END_P wouldn't work anymore after
14528 append_space_for_newline has been called. */
14529 enum display_element_type saved_what
= it
->what
;
14530 int saved_c
= it
->c
, saved_len
= it
->len
;
14531 int saved_x
= it
->current_x
;
14532 int saved_face_id
= it
->face_id
;
14533 struct text_pos saved_pos
;
14534 Lisp_Object saved_object
;
14537 saved_object
= it
->object
;
14538 saved_pos
= it
->position
;
14540 it
->what
= IT_CHARACTER
;
14541 bzero (&it
->position
, sizeof it
->position
);
14542 it
->object
= make_number (0);
14546 if (default_face_p
)
14547 it
->face_id
= DEFAULT_FACE_ID
;
14548 else if (it
->face_before_selective_p
)
14549 it
->face_id
= it
->saved_face_id
;
14550 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14551 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14553 PRODUCE_GLYPHS (it
);
14555 it
->override_ascent
= -1;
14556 it
->constrain_row_ascent_descent_p
= 0;
14557 it
->current_x
= saved_x
;
14558 it
->object
= saved_object
;
14559 it
->position
= saved_pos
;
14560 it
->what
= saved_what
;
14561 it
->face_id
= saved_face_id
;
14562 it
->len
= saved_len
;
14572 /* Extend the face of the last glyph in the text area of IT->glyph_row
14573 to the end of the display line. Called from display_line.
14574 If the glyph row is empty, add a space glyph to it so that we
14575 know the face to draw. Set the glyph row flag fill_line_p. */
14578 extend_face_to_end_of_line (it
)
14582 struct frame
*f
= it
->f
;
14584 /* If line is already filled, do nothing. */
14585 if (it
->current_x
>= it
->last_visible_x
)
14588 /* Face extension extends the background and box of IT->face_id
14589 to the end of the line. If the background equals the background
14590 of the frame, we don't have to do anything. */
14591 if (it
->face_before_selective_p
)
14592 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14594 face
= FACE_FROM_ID (f
, it
->face_id
);
14596 if (FRAME_WINDOW_P (f
)
14597 && face
->box
== FACE_NO_BOX
14598 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14602 /* Set the glyph row flag indicating that the face of the last glyph
14603 in the text area has to be drawn to the end of the text area. */
14604 it
->glyph_row
->fill_line_p
= 1;
14606 /* If current character of IT is not ASCII, make sure we have the
14607 ASCII face. This will be automatically undone the next time
14608 get_next_display_element returns a multibyte character. Note
14609 that the character will always be single byte in unibyte text. */
14610 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14612 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14615 if (FRAME_WINDOW_P (f
))
14617 /* If the row is empty, add a space with the current face of IT,
14618 so that we know which face to draw. */
14619 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14621 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14622 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14623 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14628 /* Save some values that must not be changed. */
14629 int saved_x
= it
->current_x
;
14630 struct text_pos saved_pos
;
14631 Lisp_Object saved_object
;
14632 enum display_element_type saved_what
= it
->what
;
14633 int saved_face_id
= it
->face_id
;
14635 saved_object
= it
->object
;
14636 saved_pos
= it
->position
;
14638 it
->what
= IT_CHARACTER
;
14639 bzero (&it
->position
, sizeof it
->position
);
14640 it
->object
= make_number (0);
14643 it
->face_id
= face
->id
;
14645 PRODUCE_GLYPHS (it
);
14647 while (it
->current_x
<= it
->last_visible_x
)
14648 PRODUCE_GLYPHS (it
);
14650 /* Don't count these blanks really. It would let us insert a left
14651 truncation glyph below and make us set the cursor on them, maybe. */
14652 it
->current_x
= saved_x
;
14653 it
->object
= saved_object
;
14654 it
->position
= saved_pos
;
14655 it
->what
= saved_what
;
14656 it
->face_id
= saved_face_id
;
14661 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14662 trailing whitespace. */
14665 trailing_whitespace_p (charpos
)
14668 int bytepos
= CHAR_TO_BYTE (charpos
);
14671 while (bytepos
< ZV_BYTE
14672 && (c
= FETCH_CHAR (bytepos
),
14673 c
== ' ' || c
== '\t'))
14676 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14678 if (bytepos
!= PT_BYTE
)
14685 /* Highlight trailing whitespace, if any, in ROW. */
14688 highlight_trailing_whitespace (f
, row
)
14690 struct glyph_row
*row
;
14692 int used
= row
->used
[TEXT_AREA
];
14696 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14697 struct glyph
*glyph
= start
+ used
- 1;
14699 /* Skip over glyphs inserted to display the cursor at the
14700 end of a line, for extending the face of the last glyph
14701 to the end of the line on terminals, and for truncation
14702 and continuation glyphs. */
14703 while (glyph
>= start
14704 && glyph
->type
== CHAR_GLYPH
14705 && INTEGERP (glyph
->object
))
14708 /* If last glyph is a space or stretch, and it's trailing
14709 whitespace, set the face of all trailing whitespace glyphs in
14710 IT->glyph_row to `trailing-whitespace'. */
14712 && BUFFERP (glyph
->object
)
14713 && (glyph
->type
== STRETCH_GLYPH
14714 || (glyph
->type
== CHAR_GLYPH
14715 && glyph
->u
.ch
== ' '))
14716 && trailing_whitespace_p (glyph
->charpos
))
14718 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14722 while (glyph
>= start
14723 && BUFFERP (glyph
->object
)
14724 && (glyph
->type
== STRETCH_GLYPH
14725 || (glyph
->type
== CHAR_GLYPH
14726 && glyph
->u
.ch
== ' ')))
14727 (glyph
--)->face_id
= face_id
;
14733 /* Value is non-zero if glyph row ROW in window W should be
14734 used to hold the cursor. */
14737 cursor_row_p (w
, row
)
14739 struct glyph_row
*row
;
14741 int cursor_row_p
= 1;
14743 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14745 /* If the row ends with a newline from a string, we don't want
14746 the cursor there (if the row is continued it doesn't end in a
14748 if (CHARPOS (row
->end
.string_pos
) >= 0)
14749 cursor_row_p
= row
->continued_p
;
14750 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14752 /* If the row ends in middle of a real character,
14753 and the line is continued, we want the cursor here.
14754 That's because MATRIX_ROW_END_CHARPOS would equal
14755 PT if PT is before the character. */
14756 if (!row
->ends_in_ellipsis_p
)
14757 cursor_row_p
= row
->continued_p
;
14759 /* If the row ends in an ellipsis, then
14760 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
14761 We want that position to be displayed after the ellipsis. */
14764 /* If the row ends at ZV, display the cursor at the end of that
14765 row instead of at the start of the row below. */
14766 else if (row
->ends_at_zv_p
)
14772 return cursor_row_p
;
14776 /* Construct the glyph row IT->glyph_row in the desired matrix of
14777 IT->w from text at the current position of IT. See dispextern.h
14778 for an overview of struct it. Value is non-zero if
14779 IT->glyph_row displays text, as opposed to a line displaying ZV
14786 struct glyph_row
*row
= it
->glyph_row
;
14787 int overlay_arrow_bitmap
;
14788 Lisp_Object overlay_arrow_string
;
14790 /* We always start displaying at hpos zero even if hscrolled. */
14791 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14793 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14794 >= it
->w
->desired_matrix
->nrows
)
14796 it
->w
->nrows_scale_factor
++;
14797 fonts_changed_p
= 1;
14801 /* Is IT->w showing the region? */
14802 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14804 /* Clear the result glyph row and enable it. */
14805 prepare_desired_row (row
);
14807 row
->y
= it
->current_y
;
14808 row
->start
= it
->start
;
14809 row
->continuation_lines_width
= it
->continuation_lines_width
;
14810 row
->displays_text_p
= 1;
14811 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14812 it
->starts_in_middle_of_char_p
= 0;
14814 /* Arrange the overlays nicely for our purposes. Usually, we call
14815 display_line on only one line at a time, in which case this
14816 can't really hurt too much, or we call it on lines which appear
14817 one after another in the buffer, in which case all calls to
14818 recenter_overlay_lists but the first will be pretty cheap. */
14819 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14821 /* Move over display elements that are not visible because we are
14822 hscrolled. This may stop at an x-position < IT->first_visible_x
14823 if the first glyph is partially visible or if we hit a line end. */
14824 if (it
->current_x
< it
->first_visible_x
)
14826 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14827 MOVE_TO_POS
| MOVE_TO_X
);
14830 /* Get the initial row height. This is either the height of the
14831 text hscrolled, if there is any, or zero. */
14832 row
->ascent
= it
->max_ascent
;
14833 row
->height
= it
->max_ascent
+ it
->max_descent
;
14834 row
->phys_ascent
= it
->max_phys_ascent
;
14835 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14836 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14838 /* Loop generating characters. The loop is left with IT on the next
14839 character to display. */
14842 int n_glyphs_before
, hpos_before
, x_before
;
14844 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14846 /* Retrieve the next thing to display. Value is zero if end of
14848 if (!get_next_display_element (it
))
14850 /* Maybe add a space at the end of this line that is used to
14851 display the cursor there under X. Set the charpos of the
14852 first glyph of blank lines not corresponding to any text
14854 #ifdef HAVE_WINDOW_SYSTEM
14855 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14856 row
->exact_window_width_line_p
= 1;
14858 #endif /* HAVE_WINDOW_SYSTEM */
14859 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14860 || row
->used
[TEXT_AREA
] == 0)
14862 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14863 row
->displays_text_p
= 0;
14865 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14866 && (!MINI_WINDOW_P (it
->w
)
14867 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14868 row
->indicate_empty_line_p
= 1;
14871 it
->continuation_lines_width
= 0;
14872 row
->ends_at_zv_p
= 1;
14876 /* Now, get the metrics of what we want to display. This also
14877 generates glyphs in `row' (which is IT->glyph_row). */
14878 n_glyphs_before
= row
->used
[TEXT_AREA
];
14881 /* Remember the line height so far in case the next element doesn't
14882 fit on the line. */
14883 if (!it
->truncate_lines_p
)
14885 ascent
= it
->max_ascent
;
14886 descent
= it
->max_descent
;
14887 phys_ascent
= it
->max_phys_ascent
;
14888 phys_descent
= it
->max_phys_descent
;
14891 PRODUCE_GLYPHS (it
);
14893 /* If this display element was in marginal areas, continue with
14895 if (it
->area
!= TEXT_AREA
)
14897 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14898 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14899 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14900 row
->phys_height
= max (row
->phys_height
,
14901 it
->max_phys_ascent
+ it
->max_phys_descent
);
14902 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14903 it
->max_extra_line_spacing
);
14904 set_iterator_to_next (it
, 1);
14908 /* Does the display element fit on the line? If we truncate
14909 lines, we should draw past the right edge of the window. If
14910 we don't truncate, we want to stop so that we can display the
14911 continuation glyph before the right margin. If lines are
14912 continued, there are two possible strategies for characters
14913 resulting in more than 1 glyph (e.g. tabs): Display as many
14914 glyphs as possible in this line and leave the rest for the
14915 continuation line, or display the whole element in the next
14916 line. Original redisplay did the former, so we do it also. */
14917 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14918 hpos_before
= it
->hpos
;
14921 if (/* Not a newline. */
14923 /* Glyphs produced fit entirely in the line. */
14924 && it
->current_x
< it
->last_visible_x
)
14926 it
->hpos
+= nglyphs
;
14927 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14928 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14929 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14930 row
->phys_height
= max (row
->phys_height
,
14931 it
->max_phys_ascent
+ it
->max_phys_descent
);
14932 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14933 it
->max_extra_line_spacing
);
14934 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14935 row
->x
= x
- it
->first_visible_x
;
14940 struct glyph
*glyph
;
14942 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14944 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14945 new_x
= x
+ glyph
->pixel_width
;
14947 if (/* Lines are continued. */
14948 !it
->truncate_lines_p
14949 && (/* Glyph doesn't fit on the line. */
14950 new_x
> it
->last_visible_x
14951 /* Or it fits exactly on a window system frame. */
14952 || (new_x
== it
->last_visible_x
14953 && FRAME_WINDOW_P (it
->f
))))
14955 /* End of a continued line. */
14958 || (new_x
== it
->last_visible_x
14959 && FRAME_WINDOW_P (it
->f
)))
14961 /* Current glyph is the only one on the line or
14962 fits exactly on the line. We must continue
14963 the line because we can't draw the cursor
14964 after the glyph. */
14965 row
->continued_p
= 1;
14966 it
->current_x
= new_x
;
14967 it
->continuation_lines_width
+= new_x
;
14969 if (i
== nglyphs
- 1)
14971 set_iterator_to_next (it
, 1);
14972 #ifdef HAVE_WINDOW_SYSTEM
14973 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14975 if (!get_next_display_element (it
))
14977 row
->exact_window_width_line_p
= 1;
14978 it
->continuation_lines_width
= 0;
14979 row
->continued_p
= 0;
14980 row
->ends_at_zv_p
= 1;
14982 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14984 row
->continued_p
= 0;
14985 row
->exact_window_width_line_p
= 1;
14988 #endif /* HAVE_WINDOW_SYSTEM */
14991 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14992 && !FRAME_WINDOW_P (it
->f
))
14994 /* A padding glyph that doesn't fit on this line.
14995 This means the whole character doesn't fit
14997 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14999 /* Fill the rest of the row with continuation
15000 glyphs like in 20.x. */
15001 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15002 < row
->glyphs
[1 + TEXT_AREA
])
15003 produce_special_glyphs (it
, IT_CONTINUATION
);
15005 row
->continued_p
= 1;
15006 it
->current_x
= x_before
;
15007 it
->continuation_lines_width
+= x_before
;
15009 /* Restore the height to what it was before the
15010 element not fitting on the line. */
15011 it
->max_ascent
= ascent
;
15012 it
->max_descent
= descent
;
15013 it
->max_phys_ascent
= phys_ascent
;
15014 it
->max_phys_descent
= phys_descent
;
15016 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15018 /* A TAB that extends past the right edge of the
15019 window. This produces a single glyph on
15020 window system frames. We leave the glyph in
15021 this row and let it fill the row, but don't
15022 consume the TAB. */
15023 it
->continuation_lines_width
+= it
->last_visible_x
;
15024 row
->ends_in_middle_of_char_p
= 1;
15025 row
->continued_p
= 1;
15026 glyph
->pixel_width
= it
->last_visible_x
- x
;
15027 it
->starts_in_middle_of_char_p
= 1;
15031 /* Something other than a TAB that draws past
15032 the right edge of the window. Restore
15033 positions to values before the element. */
15034 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15036 /* Display continuation glyphs. */
15037 if (!FRAME_WINDOW_P (it
->f
))
15038 produce_special_glyphs (it
, IT_CONTINUATION
);
15039 row
->continued_p
= 1;
15041 it
->continuation_lines_width
+= x
;
15043 if (nglyphs
> 1 && i
> 0)
15045 row
->ends_in_middle_of_char_p
= 1;
15046 it
->starts_in_middle_of_char_p
= 1;
15049 /* Restore the height to what it was before the
15050 element not fitting on the line. */
15051 it
->max_ascent
= ascent
;
15052 it
->max_descent
= descent
;
15053 it
->max_phys_ascent
= phys_ascent
;
15054 it
->max_phys_descent
= phys_descent
;
15059 else if (new_x
> it
->first_visible_x
)
15061 /* Increment number of glyphs actually displayed. */
15064 if (x
< it
->first_visible_x
)
15065 /* Glyph is partially visible, i.e. row starts at
15066 negative X position. */
15067 row
->x
= x
- it
->first_visible_x
;
15071 /* Glyph is completely off the left margin of the
15072 window. This should not happen because of the
15073 move_it_in_display_line at the start of this
15074 function, unless the text display area of the
15075 window is empty. */
15076 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15080 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15081 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15082 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15083 row
->phys_height
= max (row
->phys_height
,
15084 it
->max_phys_ascent
+ it
->max_phys_descent
);
15085 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15086 it
->max_extra_line_spacing
);
15088 /* End of this display line if row is continued. */
15089 if (row
->continued_p
|| row
->ends_at_zv_p
)
15094 /* Is this a line end? If yes, we're also done, after making
15095 sure that a non-default face is extended up to the right
15096 margin of the window. */
15097 if (ITERATOR_AT_END_OF_LINE_P (it
))
15099 int used_before
= row
->used
[TEXT_AREA
];
15101 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15103 #ifdef HAVE_WINDOW_SYSTEM
15104 /* Add a space at the end of the line that is used to
15105 display the cursor there. */
15106 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15107 append_space_for_newline (it
, 0);
15108 #endif /* HAVE_WINDOW_SYSTEM */
15110 /* Extend the face to the end of the line. */
15111 extend_face_to_end_of_line (it
);
15113 /* Make sure we have the position. */
15114 if (used_before
== 0)
15115 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15117 /* Consume the line end. This skips over invisible lines. */
15118 set_iterator_to_next (it
, 1);
15119 it
->continuation_lines_width
= 0;
15123 /* Proceed with next display element. Note that this skips
15124 over lines invisible because of selective display. */
15125 set_iterator_to_next (it
, 1);
15127 /* If we truncate lines, we are done when the last displayed
15128 glyphs reach past the right margin of the window. */
15129 if (it
->truncate_lines_p
15130 && (FRAME_WINDOW_P (it
->f
)
15131 ? (it
->current_x
>= it
->last_visible_x
)
15132 : (it
->current_x
> it
->last_visible_x
)))
15134 /* Maybe add truncation glyphs. */
15135 if (!FRAME_WINDOW_P (it
->f
))
15139 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15140 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15143 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15145 row
->used
[TEXT_AREA
] = i
;
15146 produce_special_glyphs (it
, IT_TRUNCATION
);
15149 #ifdef HAVE_WINDOW_SYSTEM
15152 /* Don't truncate if we can overflow newline into fringe. */
15153 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15155 if (!get_next_display_element (it
))
15157 it
->continuation_lines_width
= 0;
15158 row
->ends_at_zv_p
= 1;
15159 row
->exact_window_width_line_p
= 1;
15162 if (ITERATOR_AT_END_OF_LINE_P (it
))
15164 row
->exact_window_width_line_p
= 1;
15165 goto at_end_of_line
;
15169 #endif /* HAVE_WINDOW_SYSTEM */
15171 row
->truncated_on_right_p
= 1;
15172 it
->continuation_lines_width
= 0;
15173 reseat_at_next_visible_line_start (it
, 0);
15174 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15175 it
->hpos
= hpos_before
;
15176 it
->current_x
= x_before
;
15181 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15182 at the left window margin. */
15183 if (it
->first_visible_x
15184 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15186 if (!FRAME_WINDOW_P (it
->f
))
15187 insert_left_trunc_glyphs (it
);
15188 row
->truncated_on_left_p
= 1;
15191 /* If the start of this line is the overlay arrow-position, then
15192 mark this glyph row as the one containing the overlay arrow.
15193 This is clearly a mess with variable size fonts. It would be
15194 better to let it be displayed like cursors under X. */
15195 if (! overlay_arrow_seen
15196 && (overlay_arrow_string
15197 = overlay_arrow_at_row (it
, row
, &overlay_arrow_bitmap
),
15198 !NILP (overlay_arrow_string
)))
15200 /* Overlay arrow in window redisplay is a fringe bitmap. */
15201 if (STRINGP (overlay_arrow_string
))
15203 struct glyph_row
*arrow_row
15204 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15205 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15206 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15207 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15208 struct glyph
*p2
, *end
;
15210 /* Copy the arrow glyphs. */
15211 while (glyph
< arrow_end
)
15214 /* Throw away padding glyphs. */
15216 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15217 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15223 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15228 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
15229 row
->overlay_arrow_p
= 1;
15231 overlay_arrow_seen
= 1;
15234 /* Compute pixel dimensions of this line. */
15235 compute_line_metrics (it
);
15237 /* Remember the position at which this line ends. */
15238 row
->end
= it
->current
;
15240 /* Record whether this row ends inside an ellipsis. */
15241 row
->ends_in_ellipsis_p
15242 = (it
->method
== next_element_from_display_vector
15243 && it
->ellipsis_p
);
15245 /* Save fringe bitmaps in this row. */
15246 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15247 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15248 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15249 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15251 it
->left_user_fringe_bitmap
= 0;
15252 it
->left_user_fringe_face_id
= 0;
15253 it
->right_user_fringe_bitmap
= 0;
15254 it
->right_user_fringe_face_id
= 0;
15256 /* Maybe set the cursor. */
15257 if (it
->w
->cursor
.vpos
< 0
15258 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15259 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15260 && cursor_row_p (it
->w
, row
))
15261 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15263 /* Highlight trailing whitespace. */
15264 if (!NILP (Vshow_trailing_whitespace
))
15265 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15267 /* Prepare for the next line. This line starts horizontally at (X
15268 HPOS) = (0 0). Vertical positions are incremented. As a
15269 convenience for the caller, IT->glyph_row is set to the next
15271 it
->current_x
= it
->hpos
= 0;
15272 it
->current_y
+= row
->height
;
15275 it
->start
= it
->current
;
15276 return row
->displays_text_p
;
15281 /***********************************************************************
15283 ***********************************************************************/
15285 /* Redisplay the menu bar in the frame for window W.
15287 The menu bar of X frames that don't have X toolkit support is
15288 displayed in a special window W->frame->menu_bar_window.
15290 The menu bar of terminal frames is treated specially as far as
15291 glyph matrices are concerned. Menu bar lines are not part of
15292 windows, so the update is done directly on the frame matrix rows
15293 for the menu bar. */
15296 display_menu_bar (w
)
15299 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15304 /* Don't do all this for graphical frames. */
15306 if (!NILP (Vwindow_system
))
15309 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15314 if (FRAME_MAC_P (f
))
15318 #ifdef USE_X_TOOLKIT
15319 xassert (!FRAME_WINDOW_P (f
));
15320 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15321 it
.first_visible_x
= 0;
15322 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15323 #else /* not USE_X_TOOLKIT */
15324 if (FRAME_WINDOW_P (f
))
15326 /* Menu bar lines are displayed in the desired matrix of the
15327 dummy window menu_bar_window. */
15328 struct window
*menu_w
;
15329 xassert (WINDOWP (f
->menu_bar_window
));
15330 menu_w
= XWINDOW (f
->menu_bar_window
);
15331 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15333 it
.first_visible_x
= 0;
15334 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15338 /* This is a TTY frame, i.e. character hpos/vpos are used as
15340 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15342 it
.first_visible_x
= 0;
15343 it
.last_visible_x
= FRAME_COLS (f
);
15345 #endif /* not USE_X_TOOLKIT */
15347 if (! mode_line_inverse_video
)
15348 /* Force the menu-bar to be displayed in the default face. */
15349 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15351 /* Clear all rows of the menu bar. */
15352 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15354 struct glyph_row
*row
= it
.glyph_row
+ i
;
15355 clear_glyph_row (row
);
15356 row
->enabled_p
= 1;
15357 row
->full_width_p
= 1;
15360 /* Display all items of the menu bar. */
15361 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15362 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15364 Lisp_Object string
;
15366 /* Stop at nil string. */
15367 string
= AREF (items
, i
+ 1);
15371 /* Remember where item was displayed. */
15372 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15374 /* Display the item, pad with one space. */
15375 if (it
.current_x
< it
.last_visible_x
)
15376 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15377 SCHARS (string
) + 1, 0, 0, -1);
15380 /* Fill out the line with spaces. */
15381 if (it
.current_x
< it
.last_visible_x
)
15382 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15384 /* Compute the total height of the lines. */
15385 compute_line_metrics (&it
);
15390 /***********************************************************************
15392 ***********************************************************************/
15394 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15395 FORCE is non-zero, redisplay mode lines unconditionally.
15396 Otherwise, redisplay only mode lines that are garbaged. Value is
15397 the number of windows whose mode lines were redisplayed. */
15400 redisplay_mode_lines (window
, force
)
15401 Lisp_Object window
;
15406 while (!NILP (window
))
15408 struct window
*w
= XWINDOW (window
);
15410 if (WINDOWP (w
->hchild
))
15411 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15412 else if (WINDOWP (w
->vchild
))
15413 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15415 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15416 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15418 struct text_pos lpoint
;
15419 struct buffer
*old
= current_buffer
;
15421 /* Set the window's buffer for the mode line display. */
15422 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15423 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15425 /* Point refers normally to the selected window. For any
15426 other window, set up appropriate value. */
15427 if (!EQ (window
, selected_window
))
15429 struct text_pos pt
;
15431 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15432 if (CHARPOS (pt
) < BEGV
)
15433 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15434 else if (CHARPOS (pt
) > (ZV
- 1))
15435 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15437 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15440 /* Display mode lines. */
15441 clear_glyph_matrix (w
->desired_matrix
);
15442 if (display_mode_lines (w
))
15445 w
->must_be_updated_p
= 1;
15448 /* Restore old settings. */
15449 set_buffer_internal_1 (old
);
15450 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15460 /* Display the mode and/or top line of window W. Value is the number
15461 of mode lines displayed. */
15464 display_mode_lines (w
)
15467 Lisp_Object old_selected_window
, old_selected_frame
;
15470 old_selected_frame
= selected_frame
;
15471 selected_frame
= w
->frame
;
15472 old_selected_window
= selected_window
;
15473 XSETWINDOW (selected_window
, w
);
15475 /* These will be set while the mode line specs are processed. */
15476 line_number_displayed
= 0;
15477 w
->column_number_displayed
= Qnil
;
15479 if (WINDOW_WANTS_MODELINE_P (w
))
15481 struct window
*sel_w
= XWINDOW (old_selected_window
);
15483 /* Select mode line face based on the real selected window. */
15484 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15485 current_buffer
->mode_line_format
);
15489 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15491 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15492 current_buffer
->header_line_format
);
15496 selected_frame
= old_selected_frame
;
15497 selected_window
= old_selected_window
;
15502 /* Display mode or top line of window W. FACE_ID specifies which line
15503 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15504 FORMAT is the mode line format to display. Value is the pixel
15505 height of the mode line displayed. */
15508 display_mode_line (w
, face_id
, format
)
15510 enum face_id face_id
;
15511 Lisp_Object format
;
15516 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15517 prepare_desired_row (it
.glyph_row
);
15519 it
.glyph_row
->mode_line_p
= 1;
15521 if (! mode_line_inverse_video
)
15522 /* Force the mode-line to be displayed in the default face. */
15523 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15525 /* Temporarily make frame's keyboard the current kboard so that
15526 kboard-local variables in the mode_line_format will get the right
15528 push_frame_kboard (it
.f
);
15529 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15530 pop_frame_kboard ();
15532 /* Fill up with spaces. */
15533 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15535 compute_line_metrics (&it
);
15536 it
.glyph_row
->full_width_p
= 1;
15537 it
.glyph_row
->continued_p
= 0;
15538 it
.glyph_row
->truncated_on_left_p
= 0;
15539 it
.glyph_row
->truncated_on_right_p
= 0;
15541 /* Make a 3D mode-line have a shadow at its right end. */
15542 face
= FACE_FROM_ID (it
.f
, face_id
);
15543 extend_face_to_end_of_line (&it
);
15544 if (face
->box
!= FACE_NO_BOX
)
15546 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15547 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15548 last
->right_box_line_p
= 1;
15551 return it
.glyph_row
->height
;
15554 /* Alist that caches the results of :propertize.
15555 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15556 Lisp_Object mode_line_proptrans_alist
;
15558 /* List of strings making up the mode-line. */
15559 Lisp_Object mode_line_string_list
;
15561 /* Base face property when building propertized mode line string. */
15562 static Lisp_Object mode_line_string_face
;
15563 static Lisp_Object mode_line_string_face_prop
;
15566 /* Contribute ELT to the mode line for window IT->w. How it
15567 translates into text depends on its data type.
15569 IT describes the display environment in which we display, as usual.
15571 DEPTH is the depth in recursion. It is used to prevent
15572 infinite recursion here.
15574 FIELD_WIDTH is the number of characters the display of ELT should
15575 occupy in the mode line, and PRECISION is the maximum number of
15576 characters to display from ELT's representation. See
15577 display_string for details.
15579 Returns the hpos of the end of the text generated by ELT.
15581 PROPS is a property list to add to any string we encounter.
15583 If RISKY is nonzero, remove (disregard) any properties in any string
15584 we encounter, and ignore :eval and :propertize.
15586 If the global variable `frame_title_ptr' is non-NULL, then the output
15587 is passed to `store_frame_title' instead of `display_string'. */
15590 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15593 int field_width
, precision
;
15594 Lisp_Object elt
, props
;
15597 int n
= 0, field
, prec
;
15602 elt
= build_string ("*too-deep*");
15606 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15610 /* A string: output it and check for %-constructs within it. */
15612 const unsigned char *this, *lisp_string
;
15614 if (!NILP (props
) || risky
)
15616 Lisp_Object oprops
, aelt
;
15617 oprops
= Ftext_properties_at (make_number (0), elt
);
15619 /* If the starting string's properties are not what
15620 we want, translate the string. Also, if the string
15621 is risky, do that anyway. */
15623 if (NILP (Fequal (props
, oprops
)) || risky
)
15625 /* If the starting string has properties,
15626 merge the specified ones onto the existing ones. */
15627 if (! NILP (oprops
) && !risky
)
15631 oprops
= Fcopy_sequence (oprops
);
15633 while (CONSP (tem
))
15635 oprops
= Fplist_put (oprops
, XCAR (tem
),
15636 XCAR (XCDR (tem
)));
15637 tem
= XCDR (XCDR (tem
));
15642 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15643 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15645 mode_line_proptrans_alist
15646 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15653 elt
= Fcopy_sequence (elt
);
15654 Fset_text_properties (make_number (0), Flength (elt
),
15656 /* Add this item to mode_line_proptrans_alist. */
15657 mode_line_proptrans_alist
15658 = Fcons (Fcons (elt
, props
),
15659 mode_line_proptrans_alist
);
15660 /* Truncate mode_line_proptrans_alist
15661 to at most 50 elements. */
15662 tem
= Fnthcdr (make_number (50),
15663 mode_line_proptrans_alist
);
15665 XSETCDR (tem
, Qnil
);
15670 this = SDATA (elt
);
15671 lisp_string
= this;
15675 prec
= precision
- n
;
15676 if (frame_title_ptr
)
15677 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15678 else if (!NILP (mode_line_string_list
))
15679 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15681 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15682 0, prec
, 0, STRING_MULTIBYTE (elt
));
15687 while ((precision
<= 0 || n
< precision
)
15689 && (frame_title_ptr
15690 || !NILP (mode_line_string_list
)
15691 || it
->current_x
< it
->last_visible_x
))
15693 const unsigned char *last
= this;
15695 /* Advance to end of string or next format specifier. */
15696 while ((c
= *this++) != '\0' && c
!= '%')
15699 if (this - 1 != last
)
15701 int nchars
, nbytes
;
15703 /* Output to end of string or up to '%'. Field width
15704 is length of string. Don't output more than
15705 PRECISION allows us. */
15708 prec
= c_string_width (last
, this - last
, precision
- n
,
15711 if (frame_title_ptr
)
15712 n
+= store_frame_title (last
, 0, prec
);
15713 else if (!NILP (mode_line_string_list
))
15715 int bytepos
= last
- lisp_string
;
15716 int charpos
= string_byte_to_char (elt
, bytepos
);
15717 int endpos
= (precision
<= 0
15718 ? string_byte_to_char (elt
,
15719 this - lisp_string
)
15720 : charpos
+ nchars
);
15722 n
+= store_mode_line_string (NULL
,
15723 Fsubstring (elt
, make_number (charpos
),
15724 make_number (endpos
)),
15729 int bytepos
= last
- lisp_string
;
15730 int charpos
= string_byte_to_char (elt
, bytepos
);
15731 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15733 STRING_MULTIBYTE (elt
));
15736 else /* c == '%' */
15738 const unsigned char *percent_position
= this;
15740 /* Get the specified minimum width. Zero means
15743 while ((c
= *this++) >= '0' && c
<= '9')
15744 field
= field
* 10 + c
- '0';
15746 /* Don't pad beyond the total padding allowed. */
15747 if (field_width
- n
> 0 && field
> field_width
- n
)
15748 field
= field_width
- n
;
15750 /* Note that either PRECISION <= 0 or N < PRECISION. */
15751 prec
= precision
- n
;
15754 n
+= display_mode_element (it
, depth
, field
, prec
,
15755 Vglobal_mode_string
, props
,
15760 int bytepos
, charpos
;
15761 unsigned char *spec
;
15763 bytepos
= percent_position
- lisp_string
;
15764 charpos
= (STRING_MULTIBYTE (elt
)
15765 ? string_byte_to_char (elt
, bytepos
)
15769 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15771 if (frame_title_ptr
)
15772 n
+= store_frame_title (spec
, field
, prec
);
15773 else if (!NILP (mode_line_string_list
))
15775 int len
= strlen (spec
);
15776 Lisp_Object tem
= make_string (spec
, len
);
15777 props
= Ftext_properties_at (make_number (charpos
), elt
);
15778 /* Should only keep face property in props */
15779 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15783 int nglyphs_before
, nwritten
;
15785 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15786 nwritten
= display_string (spec
, Qnil
, elt
,
15791 /* Assign to the glyphs written above the
15792 string where the `%x' came from, position
15796 struct glyph
*glyph
15797 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15801 for (i
= 0; i
< nwritten
; ++i
)
15803 glyph
[i
].object
= elt
;
15804 glyph
[i
].charpos
= charpos
;
15819 /* A symbol: process the value of the symbol recursively
15820 as if it appeared here directly. Avoid error if symbol void.
15821 Special case: if value of symbol is a string, output the string
15824 register Lisp_Object tem
;
15826 /* If the variable is not marked as risky to set
15827 then its contents are risky to use. */
15828 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15831 tem
= Fboundp (elt
);
15834 tem
= Fsymbol_value (elt
);
15835 /* If value is a string, output that string literally:
15836 don't check for % within it. */
15840 if (!EQ (tem
, elt
))
15842 /* Give up right away for nil or t. */
15852 register Lisp_Object car
, tem
;
15854 /* A cons cell: five distinct cases.
15855 If first element is :eval or :propertize, do something special.
15856 If first element is a string or a cons, process all the elements
15857 and effectively concatenate them.
15858 If first element is a negative number, truncate displaying cdr to
15859 at most that many characters. If positive, pad (with spaces)
15860 to at least that many characters.
15861 If first element is a symbol, process the cadr or caddr recursively
15862 according to whether the symbol's value is non-nil or nil. */
15864 if (EQ (car
, QCeval
))
15866 /* An element of the form (:eval FORM) means evaluate FORM
15867 and use the result as mode line elements. */
15872 if (CONSP (XCDR (elt
)))
15875 spec
= safe_eval (XCAR (XCDR (elt
)));
15876 n
+= display_mode_element (it
, depth
, field_width
- n
,
15877 precision
- n
, spec
, props
,
15881 else if (EQ (car
, QCpropertize
))
15883 /* An element of the form (:propertize ELT PROPS...)
15884 means display ELT but applying properties PROPS. */
15889 if (CONSP (XCDR (elt
)))
15890 n
+= display_mode_element (it
, depth
, field_width
- n
,
15891 precision
- n
, XCAR (XCDR (elt
)),
15892 XCDR (XCDR (elt
)), risky
);
15894 else if (SYMBOLP (car
))
15896 tem
= Fboundp (car
);
15900 /* elt is now the cdr, and we know it is a cons cell.
15901 Use its car if CAR has a non-nil value. */
15904 tem
= Fsymbol_value (car
);
15911 /* Symbol's value is nil (or symbol is unbound)
15912 Get the cddr of the original list
15913 and if possible find the caddr and use that. */
15917 else if (!CONSP (elt
))
15922 else if (INTEGERP (car
))
15924 register int lim
= XINT (car
);
15928 /* Negative int means reduce maximum width. */
15929 if (precision
<= 0)
15932 precision
= min (precision
, -lim
);
15936 /* Padding specified. Don't let it be more than
15937 current maximum. */
15939 lim
= min (precision
, lim
);
15941 /* If that's more padding than already wanted, queue it.
15942 But don't reduce padding already specified even if
15943 that is beyond the current truncation point. */
15944 field_width
= max (lim
, field_width
);
15948 else if (STRINGP (car
) || CONSP (car
))
15950 register int limit
= 50;
15951 /* Limit is to protect against circular lists. */
15954 && (precision
<= 0 || n
< precision
))
15956 n
+= display_mode_element (it
, depth
, field_width
- n
,
15957 precision
- n
, XCAR (elt
),
15967 elt
= build_string ("*invalid*");
15971 /* Pad to FIELD_WIDTH. */
15972 if (field_width
> 0 && n
< field_width
)
15974 if (frame_title_ptr
)
15975 n
+= store_frame_title ("", field_width
- n
, 0);
15976 else if (!NILP (mode_line_string_list
))
15977 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15979 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15986 /* Store a mode-line string element in mode_line_string_list.
15988 If STRING is non-null, display that C string. Otherwise, the Lisp
15989 string LISP_STRING is displayed.
15991 FIELD_WIDTH is the minimum number of output glyphs to produce.
15992 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15993 with spaces. FIELD_WIDTH <= 0 means don't pad.
15995 PRECISION is the maximum number of characters to output from
15996 STRING. PRECISION <= 0 means don't truncate the string.
15998 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15999 properties to the string.
16001 PROPS are the properties to add to the string.
16002 The mode_line_string_face face property is always added to the string.
16006 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16008 Lisp_Object lisp_string
;
16017 if (string
!= NULL
)
16019 len
= strlen (string
);
16020 if (precision
> 0 && len
> precision
)
16022 lisp_string
= make_string (string
, len
);
16024 props
= mode_line_string_face_prop
;
16025 else if (!NILP (mode_line_string_face
))
16027 Lisp_Object face
= Fsafe_plist_get (props
, Qface
);
16028 props
= Fcopy_sequence (props
);
16030 face
= mode_line_string_face
;
16032 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16033 props
= Fplist_put (props
, Qface
, face
);
16035 Fadd_text_properties (make_number (0), make_number (len
),
16036 props
, lisp_string
);
16040 len
= XFASTINT (Flength (lisp_string
));
16041 if (precision
> 0 && len
> precision
)
16044 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16047 if (!NILP (mode_line_string_face
))
16051 props
= Ftext_properties_at (make_number (0), lisp_string
);
16052 face
= Fsafe_plist_get (props
, Qface
);
16054 face
= mode_line_string_face
;
16056 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16057 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16059 lisp_string
= Fcopy_sequence (lisp_string
);
16062 Fadd_text_properties (make_number (0), make_number (len
),
16063 props
, lisp_string
);
16068 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16072 if (field_width
> len
)
16074 field_width
-= len
;
16075 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16077 Fadd_text_properties (make_number (0), make_number (field_width
),
16078 props
, lisp_string
);
16079 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16087 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16089 doc
: /* Format a string out of a mode line format specification.
16090 First arg FORMAT specifies the mode line format (see `mode-line-format'
16091 for details) to use.
16093 Optional second arg FACE specifies the face property to put
16094 on all characters for which no face is specified.
16095 t means whatever face the window's mode line currently uses
16096 \(either `mode-line' or `mode-line-inactive', depending).
16097 nil means the default is no face property.
16098 If FACE is an integer, the value string has no text properties.
16100 Optional third and fourth args WINDOW and BUFFER specify the window
16101 and buffer to use as the context for the formatting (defaults
16102 are the selected window and the window's buffer). */)
16103 (format
, face
, window
, buffer
)
16104 Lisp_Object format
, face
, window
, buffer
;
16109 struct buffer
*old_buffer
= NULL
;
16111 int no_props
= INTEGERP (face
);
16114 window
= selected_window
;
16115 CHECK_WINDOW (window
);
16116 w
= XWINDOW (window
);
16119 buffer
= w
->buffer
;
16120 CHECK_BUFFER (buffer
);
16123 return build_string ("");
16131 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16132 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16136 face_id
= DEFAULT_FACE_ID
;
16138 if (XBUFFER (buffer
) != current_buffer
)
16140 old_buffer
= current_buffer
;
16141 set_buffer_internal_1 (XBUFFER (buffer
));
16144 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16148 mode_line_string_face
= face
;
16149 mode_line_string_face_prop
16150 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16152 /* We need a dummy last element in mode_line_string_list to
16153 indicate we are building the propertized mode-line string.
16154 Using mode_line_string_face_prop here GC protects it. */
16155 mode_line_string_list
16156 = Fcons (mode_line_string_face_prop
, Qnil
);
16157 frame_title_ptr
= NULL
;
16161 mode_line_string_face_prop
= Qnil
;
16162 mode_line_string_list
= Qnil
;
16163 frame_title_ptr
= frame_title_buf
;
16166 push_frame_kboard (it
.f
);
16167 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16168 pop_frame_kboard ();
16171 set_buffer_internal_1 (old_buffer
);
16176 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16177 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
16178 make_string ("", 0));
16179 mode_line_string_face_prop
= Qnil
;
16180 mode_line_string_list
= Qnil
;
16184 len
= frame_title_ptr
- frame_title_buf
;
16185 if (len
> 0 && frame_title_ptr
[-1] == '-')
16187 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
16188 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
16190 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
16191 if (len
> frame_title_ptr
- frame_title_buf
)
16192 len
= frame_title_ptr
- frame_title_buf
;
16195 frame_title_ptr
= NULL
;
16196 return make_string (frame_title_buf
, len
);
16199 /* Write a null-terminated, right justified decimal representation of
16200 the positive integer D to BUF using a minimal field width WIDTH. */
16203 pint2str (buf
, width
, d
)
16204 register char *buf
;
16205 register int width
;
16208 register char *p
= buf
;
16216 *p
++ = d
% 10 + '0';
16221 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16232 /* Write a null-terminated, right justified decimal and "human
16233 readable" representation of the nonnegative integer D to BUF using
16234 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16236 static const char power_letter
[] =
16250 pint2hrstr (buf
, width
, d
)
16255 /* We aim to represent the nonnegative integer D as
16256 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16259 /* -1 means: do not use TENTHS. */
16263 /* Length of QUOTIENT.TENTHS as a string. */
16269 if (1000 <= quotient
)
16271 /* Scale to the appropriate EXPONENT. */
16274 remainder
= quotient
% 1000;
16278 while (1000 <= quotient
);
16280 /* Round to nearest and decide whether to use TENTHS or not. */
16283 tenths
= remainder
/ 100;
16284 if (50 <= remainder
% 100)
16291 if (quotient
== 10)
16299 if (500 <= remainder
)
16301 if (quotient
< 999)
16312 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16313 if (tenths
== -1 && quotient
<= 99)
16320 p
= psuffix
= buf
+ max (width
, length
);
16322 /* Print EXPONENT. */
16324 *psuffix
++ = power_letter
[exponent
];
16327 /* Print TENTHS. */
16330 *--p
= '0' + tenths
;
16334 /* Print QUOTIENT. */
16337 int digit
= quotient
% 10;
16338 *--p
= '0' + digit
;
16340 while ((quotient
/= 10) != 0);
16342 /* Print leading spaces. */
16347 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16348 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16349 type of CODING_SYSTEM. Return updated pointer into BUF. */
16351 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16354 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16355 Lisp_Object coding_system
;
16356 register char *buf
;
16360 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16361 const unsigned char *eol_str
;
16363 /* The EOL conversion we are using. */
16364 Lisp_Object eoltype
;
16366 val
= Fget (coding_system
, Qcoding_system
);
16369 if (!VECTORP (val
)) /* Not yet decided. */
16374 eoltype
= eol_mnemonic_undecided
;
16375 /* Don't mention EOL conversion if it isn't decided. */
16379 Lisp_Object eolvalue
;
16381 eolvalue
= Fget (coding_system
, Qeol_type
);
16384 *buf
++ = XFASTINT (AREF (val
, 1));
16388 /* The EOL conversion that is normal on this system. */
16390 if (NILP (eolvalue
)) /* Not yet decided. */
16391 eoltype
= eol_mnemonic_undecided
;
16392 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16393 eoltype
= eol_mnemonic_undecided
;
16394 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16395 eoltype
= (XFASTINT (eolvalue
) == 0
16396 ? eol_mnemonic_unix
16397 : (XFASTINT (eolvalue
) == 1
16398 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16404 /* Mention the EOL conversion if it is not the usual one. */
16405 if (STRINGP (eoltype
))
16407 eol_str
= SDATA (eoltype
);
16408 eol_str_len
= SBYTES (eoltype
);
16410 else if (INTEGERP (eoltype
)
16411 && CHAR_VALID_P (XINT (eoltype
), 0))
16413 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16414 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16419 eol_str
= invalid_eol_type
;
16420 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16422 bcopy (eol_str
, buf
, eol_str_len
);
16423 buf
+= eol_str_len
;
16429 /* Return a string for the output of a mode line %-spec for window W,
16430 generated by character C. PRECISION >= 0 means don't return a
16431 string longer than that value. FIELD_WIDTH > 0 means pad the
16432 string returned with spaces to that value. Return 1 in *MULTIBYTE
16433 if the result is multibyte text.
16435 Note we operate on the current buffer for most purposes,
16436 the exception being w->base_line_pos. */
16438 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16441 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16444 int field_width
, precision
;
16448 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16449 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16450 struct buffer
*b
= current_buffer
;
16458 if (!NILP (b
->read_only
))
16460 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16465 /* This differs from %* only for a modified read-only buffer. */
16466 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16468 if (!NILP (b
->read_only
))
16473 /* This differs from %* in ignoring read-only-ness. */
16474 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16486 if (command_loop_level
> 5)
16488 p
= decode_mode_spec_buf
;
16489 for (i
= 0; i
< command_loop_level
; i
++)
16492 return decode_mode_spec_buf
;
16500 if (command_loop_level
> 5)
16502 p
= decode_mode_spec_buf
;
16503 for (i
= 0; i
< command_loop_level
; i
++)
16506 return decode_mode_spec_buf
;
16513 /* Let lots_of_dashes be a string of infinite length. */
16514 if (!NILP (mode_line_string_list
))
16516 if (field_width
<= 0
16517 || field_width
> sizeof (lots_of_dashes
))
16519 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16520 decode_mode_spec_buf
[i
] = '-';
16521 decode_mode_spec_buf
[i
] = '\0';
16522 return decode_mode_spec_buf
;
16525 return lots_of_dashes
;
16534 int col
= (int) current_column (); /* iftc */
16535 w
->column_number_displayed
= make_number (col
);
16536 pint2str (decode_mode_spec_buf
, field_width
, col
);
16537 return decode_mode_spec_buf
;
16541 /* %F displays the frame name. */
16542 if (!NILP (f
->title
))
16543 return (char *) SDATA (f
->title
);
16544 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16545 return (char *) SDATA (f
->name
);
16554 int size
= ZV
- BEGV
;
16555 pint2str (decode_mode_spec_buf
, field_width
, size
);
16556 return decode_mode_spec_buf
;
16561 int size
= ZV
- BEGV
;
16562 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16563 return decode_mode_spec_buf
;
16568 int startpos
= XMARKER (w
->start
)->charpos
;
16569 int startpos_byte
= marker_byte_position (w
->start
);
16570 int line
, linepos
, linepos_byte
, topline
;
16572 int height
= WINDOW_TOTAL_LINES (w
);
16574 /* If we decided that this buffer isn't suitable for line numbers,
16575 don't forget that too fast. */
16576 if (EQ (w
->base_line_pos
, w
->buffer
))
16578 /* But do forget it, if the window shows a different buffer now. */
16579 else if (BUFFERP (w
->base_line_pos
))
16580 w
->base_line_pos
= Qnil
;
16582 /* If the buffer is very big, don't waste time. */
16583 if (INTEGERP (Vline_number_display_limit
)
16584 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16586 w
->base_line_pos
= Qnil
;
16587 w
->base_line_number
= Qnil
;
16591 if (!NILP (w
->base_line_number
)
16592 && !NILP (w
->base_line_pos
)
16593 && XFASTINT (w
->base_line_pos
) <= startpos
)
16595 line
= XFASTINT (w
->base_line_number
);
16596 linepos
= XFASTINT (w
->base_line_pos
);
16597 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16602 linepos
= BUF_BEGV (b
);
16603 linepos_byte
= BUF_BEGV_BYTE (b
);
16606 /* Count lines from base line to window start position. */
16607 nlines
= display_count_lines (linepos
, linepos_byte
,
16611 topline
= nlines
+ line
;
16613 /* Determine a new base line, if the old one is too close
16614 or too far away, or if we did not have one.
16615 "Too close" means it's plausible a scroll-down would
16616 go back past it. */
16617 if (startpos
== BUF_BEGV (b
))
16619 w
->base_line_number
= make_number (topline
);
16620 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16622 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16623 || linepos
== BUF_BEGV (b
))
16625 int limit
= BUF_BEGV (b
);
16626 int limit_byte
= BUF_BEGV_BYTE (b
);
16628 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16630 if (startpos
- distance
> limit
)
16632 limit
= startpos
- distance
;
16633 limit_byte
= CHAR_TO_BYTE (limit
);
16636 nlines
= display_count_lines (startpos
, startpos_byte
,
16638 - (height
* 2 + 30),
16640 /* If we couldn't find the lines we wanted within
16641 line_number_display_limit_width chars per line,
16642 give up on line numbers for this window. */
16643 if (position
== limit_byte
&& limit
== startpos
- distance
)
16645 w
->base_line_pos
= w
->buffer
;
16646 w
->base_line_number
= Qnil
;
16650 w
->base_line_number
= make_number (topline
- nlines
);
16651 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16654 /* Now count lines from the start pos to point. */
16655 nlines
= display_count_lines (startpos
, startpos_byte
,
16656 PT_BYTE
, PT
, &junk
);
16658 /* Record that we did display the line number. */
16659 line_number_displayed
= 1;
16661 /* Make the string to show. */
16662 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16663 return decode_mode_spec_buf
;
16666 char* p
= decode_mode_spec_buf
;
16667 int pad
= field_width
- 2;
16673 return decode_mode_spec_buf
;
16679 obj
= b
->mode_name
;
16683 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16689 int pos
= marker_position (w
->start
);
16690 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16692 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16694 if (pos
<= BUF_BEGV (b
))
16699 else if (pos
<= BUF_BEGV (b
))
16703 if (total
> 1000000)
16704 /* Do it differently for a large value, to avoid overflow. */
16705 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16707 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16708 /* We can't normally display a 3-digit number,
16709 so get us a 2-digit number that is close. */
16712 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16713 return decode_mode_spec_buf
;
16717 /* Display percentage of size above the bottom of the screen. */
16720 int toppos
= marker_position (w
->start
);
16721 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16722 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16724 if (botpos
>= BUF_ZV (b
))
16726 if (toppos
<= BUF_BEGV (b
))
16733 if (total
> 1000000)
16734 /* Do it differently for a large value, to avoid overflow. */
16735 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16737 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16738 /* We can't normally display a 3-digit number,
16739 so get us a 2-digit number that is close. */
16742 if (toppos
<= BUF_BEGV (b
))
16743 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16745 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16746 return decode_mode_spec_buf
;
16751 /* status of process */
16752 obj
= Fget_buffer_process (Fcurrent_buffer ());
16754 return "no process";
16755 #ifdef subprocesses
16756 obj
= Fsymbol_name (Fprocess_status (obj
));
16760 case 't': /* indicate TEXT or BINARY */
16761 #ifdef MODE_LINE_BINARY_TEXT
16762 return MODE_LINE_BINARY_TEXT (b
);
16768 /* coding-system (not including end-of-line format) */
16770 /* coding-system (including end-of-line type) */
16772 int eol_flag
= (c
== 'Z');
16773 char *p
= decode_mode_spec_buf
;
16775 if (! FRAME_WINDOW_P (f
))
16777 /* No need to mention EOL here--the terminal never needs
16778 to do EOL conversion. */
16779 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16780 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16782 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16785 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16786 #ifdef subprocesses
16787 obj
= Fget_buffer_process (Fcurrent_buffer ());
16788 if (PROCESSP (obj
))
16790 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16792 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16795 #endif /* subprocesses */
16798 return decode_mode_spec_buf
;
16804 *multibyte
= STRING_MULTIBYTE (obj
);
16805 return (char *) SDATA (obj
);
16812 /* Count up to COUNT lines starting from START / START_BYTE.
16813 But don't go beyond LIMIT_BYTE.
16814 Return the number of lines thus found (always nonnegative).
16816 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16819 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16820 int start
, start_byte
, limit_byte
, count
;
16823 register unsigned char *cursor
;
16824 unsigned char *base
;
16826 register int ceiling
;
16827 register unsigned char *ceiling_addr
;
16828 int orig_count
= count
;
16830 /* If we are not in selective display mode,
16831 check only for newlines. */
16832 int selective_display
= (!NILP (current_buffer
->selective_display
)
16833 && !INTEGERP (current_buffer
->selective_display
));
16837 while (start_byte
< limit_byte
)
16839 ceiling
= BUFFER_CEILING_OF (start_byte
);
16840 ceiling
= min (limit_byte
- 1, ceiling
);
16841 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16842 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16845 if (selective_display
)
16846 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16849 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16852 if (cursor
!= ceiling_addr
)
16856 start_byte
+= cursor
- base
+ 1;
16857 *byte_pos_ptr
= start_byte
;
16861 if (++cursor
== ceiling_addr
)
16867 start_byte
+= cursor
- base
;
16872 while (start_byte
> limit_byte
)
16874 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16875 ceiling
= max (limit_byte
, ceiling
);
16876 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16877 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16880 if (selective_display
)
16881 while (--cursor
!= ceiling_addr
16882 && *cursor
!= '\n' && *cursor
!= 015)
16885 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16888 if (cursor
!= ceiling_addr
)
16892 start_byte
+= cursor
- base
+ 1;
16893 *byte_pos_ptr
= start_byte
;
16894 /* When scanning backwards, we should
16895 not count the newline posterior to which we stop. */
16896 return - orig_count
- 1;
16902 /* Here we add 1 to compensate for the last decrement
16903 of CURSOR, which took it past the valid range. */
16904 start_byte
+= cursor
- base
+ 1;
16908 *byte_pos_ptr
= limit_byte
;
16911 return - orig_count
+ count
;
16912 return orig_count
- count
;
16918 /***********************************************************************
16920 ***********************************************************************/
16922 /* Display a NUL-terminated string, starting with index START.
16924 If STRING is non-null, display that C string. Otherwise, the Lisp
16925 string LISP_STRING is displayed.
16927 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16928 FACE_STRING. Display STRING or LISP_STRING with the face at
16929 FACE_STRING_POS in FACE_STRING:
16931 Display the string in the environment given by IT, but use the
16932 standard display table, temporarily.
16934 FIELD_WIDTH is the minimum number of output glyphs to produce.
16935 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16936 with spaces. If STRING has more characters, more than FIELD_WIDTH
16937 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16939 PRECISION is the maximum number of characters to output from
16940 STRING. PRECISION < 0 means don't truncate the string.
16942 This is roughly equivalent to printf format specifiers:
16944 FIELD_WIDTH PRECISION PRINTF
16945 ----------------------------------------
16951 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16952 display them, and < 0 means obey the current buffer's value of
16953 enable_multibyte_characters.
16955 Value is the number of glyphs produced. */
16958 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16959 start
, it
, field_width
, precision
, max_x
, multibyte
)
16960 unsigned char *string
;
16961 Lisp_Object lisp_string
;
16962 Lisp_Object face_string
;
16963 int face_string_pos
;
16966 int field_width
, precision
, max_x
;
16969 int hpos_at_start
= it
->hpos
;
16970 int saved_face_id
= it
->face_id
;
16971 struct glyph_row
*row
= it
->glyph_row
;
16973 /* Initialize the iterator IT for iteration over STRING beginning
16974 with index START. */
16975 reseat_to_string (it
, string
, lisp_string
, start
,
16976 precision
, field_width
, multibyte
);
16978 /* If displaying STRING, set up the face of the iterator
16979 from LISP_STRING, if that's given. */
16980 if (STRINGP (face_string
))
16986 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16987 0, it
->region_beg_charpos
,
16988 it
->region_end_charpos
,
16989 &endptr
, it
->base_face_id
, 0);
16990 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16991 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16994 /* Set max_x to the maximum allowed X position. Don't let it go
16995 beyond the right edge of the window. */
16997 max_x
= it
->last_visible_x
;
16999 max_x
= min (max_x
, it
->last_visible_x
);
17001 /* Skip over display elements that are not visible. because IT->w is
17003 if (it
->current_x
< it
->first_visible_x
)
17004 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17005 MOVE_TO_POS
| MOVE_TO_X
);
17007 row
->ascent
= it
->max_ascent
;
17008 row
->height
= it
->max_ascent
+ it
->max_descent
;
17009 row
->phys_ascent
= it
->max_phys_ascent
;
17010 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17011 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17013 /* This condition is for the case that we are called with current_x
17014 past last_visible_x. */
17015 while (it
->current_x
< max_x
)
17017 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17019 /* Get the next display element. */
17020 if (!get_next_display_element (it
))
17023 /* Produce glyphs. */
17024 x_before
= it
->current_x
;
17025 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17026 PRODUCE_GLYPHS (it
);
17028 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17031 while (i
< nglyphs
)
17033 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17035 if (!it
->truncate_lines_p
17036 && x
+ glyph
->pixel_width
> max_x
)
17038 /* End of continued line or max_x reached. */
17039 if (CHAR_GLYPH_PADDING_P (*glyph
))
17041 /* A wide character is unbreakable. */
17042 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17043 it
->current_x
= x_before
;
17047 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17052 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17054 /* Glyph is at least partially visible. */
17056 if (x
< it
->first_visible_x
)
17057 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17061 /* Glyph is off the left margin of the display area.
17062 Should not happen. */
17066 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17067 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17068 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17069 row
->phys_height
= max (row
->phys_height
,
17070 it
->max_phys_ascent
+ it
->max_phys_descent
);
17071 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17072 it
->max_extra_line_spacing
);
17073 x
+= glyph
->pixel_width
;
17077 /* Stop if max_x reached. */
17081 /* Stop at line ends. */
17082 if (ITERATOR_AT_END_OF_LINE_P (it
))
17084 it
->continuation_lines_width
= 0;
17088 set_iterator_to_next (it
, 1);
17090 /* Stop if truncating at the right edge. */
17091 if (it
->truncate_lines_p
17092 && it
->current_x
>= it
->last_visible_x
)
17094 /* Add truncation mark, but don't do it if the line is
17095 truncated at a padding space. */
17096 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17098 if (!FRAME_WINDOW_P (it
->f
))
17102 if (it
->current_x
> it
->last_visible_x
)
17104 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17105 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17107 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17109 row
->used
[TEXT_AREA
] = i
;
17110 produce_special_glyphs (it
, IT_TRUNCATION
);
17113 produce_special_glyphs (it
, IT_TRUNCATION
);
17115 it
->glyph_row
->truncated_on_right_p
= 1;
17121 /* Maybe insert a truncation at the left. */
17122 if (it
->first_visible_x
17123 && IT_CHARPOS (*it
) > 0)
17125 if (!FRAME_WINDOW_P (it
->f
))
17126 insert_left_trunc_glyphs (it
);
17127 it
->glyph_row
->truncated_on_left_p
= 1;
17130 it
->face_id
= saved_face_id
;
17132 /* Value is number of columns displayed. */
17133 return it
->hpos
- hpos_at_start
;
17138 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17139 appears as an element of LIST or as the car of an element of LIST.
17140 If PROPVAL is a list, compare each element against LIST in that
17141 way, and return 1/2 if any element of PROPVAL is found in LIST.
17142 Otherwise return 0. This function cannot quit.
17143 The return value is 2 if the text is invisible but with an ellipsis
17144 and 1 if it's invisible and without an ellipsis. */
17147 invisible_p (propval
, list
)
17148 register Lisp_Object propval
;
17151 register Lisp_Object tail
, proptail
;
17153 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17155 register Lisp_Object tem
;
17157 if (EQ (propval
, tem
))
17159 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17160 return NILP (XCDR (tem
)) ? 1 : 2;
17163 if (CONSP (propval
))
17165 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17167 Lisp_Object propelt
;
17168 propelt
= XCAR (proptail
);
17169 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17171 register Lisp_Object tem
;
17173 if (EQ (propelt
, tem
))
17175 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17176 return NILP (XCDR (tem
)) ? 1 : 2;
17184 /* Calculate a width or height in pixels from a specification using
17185 the following elements:
17188 NUM - a (fractional) multiple of the default font width/height
17189 (NUM) - specifies exactly NUM pixels
17190 UNIT - a fixed number of pixels, see below.
17191 ELEMENT - size of a display element in pixels, see below.
17192 (NUM . SPEC) - equals NUM * SPEC
17193 (+ SPEC SPEC ...) - add pixel values
17194 (- SPEC SPEC ...) - subtract pixel values
17195 (- SPEC) - negate pixel value
17198 INT or FLOAT - a number constant
17199 SYMBOL - use symbol's (buffer local) variable binding.
17202 in - pixels per inch *)
17203 mm - pixels per 1/1000 meter *)
17204 cm - pixels per 1/100 meter *)
17205 width - width of current font in pixels.
17206 height - height of current font in pixels.
17208 *) using the ratio(s) defined in display-pixels-per-inch.
17212 left-fringe - left fringe width in pixels
17213 right-fringe - right fringe width in pixels
17215 left-margin - left margin width in pixels
17216 right-margin - right margin width in pixels
17218 scroll-bar - scroll-bar area width in pixels
17222 Pixels corresponding to 5 inches:
17225 Total width of non-text areas on left side of window (if scroll-bar is on left):
17226 '(space :width (+ left-fringe left-margin scroll-bar))
17228 Align to first text column (in header line):
17229 '(space :align-to 0)
17231 Align to middle of text area minus half the width of variable `my-image'
17232 containing a loaded image:
17233 '(space :align-to (0.5 . (- text my-image)))
17235 Width of left margin minus width of 1 character in the default font:
17236 '(space :width (- left-margin 1))
17238 Width of left margin minus width of 2 characters in the current font:
17239 '(space :width (- left-margin (2 . width)))
17241 Center 1 character over left-margin (in header line):
17242 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17244 Different ways to express width of left fringe plus left margin minus one pixel:
17245 '(space :width (- (+ left-fringe left-margin) (1)))
17246 '(space :width (+ left-fringe left-margin (- (1))))
17247 '(space :width (+ left-fringe left-margin (-1)))
17251 #define NUMVAL(X) \
17252 ((INTEGERP (X) || FLOATP (X)) \
17257 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17262 int width_p
, *align_to
;
17266 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17267 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17270 return OK_PIXELS (0);
17272 if (SYMBOLP (prop
))
17274 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17276 char *unit
= SDATA (SYMBOL_NAME (prop
));
17278 if (unit
[0] == 'i' && unit
[1] == 'n')
17280 else if (unit
[0] == 'm' && unit
[1] == 'm')
17282 else if (unit
[0] == 'c' && unit
[1] == 'm')
17289 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17290 || (CONSP (Vdisplay_pixels_per_inch
)
17292 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17293 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17295 return OK_PIXELS (ppi
/ pixels
);
17301 #ifdef HAVE_WINDOW_SYSTEM
17302 if (EQ (prop
, Qheight
))
17303 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17304 if (EQ (prop
, Qwidth
))
17305 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17307 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17308 return OK_PIXELS (1);
17311 if (EQ (prop
, Qtext
))
17312 return OK_PIXELS (width_p
17313 ? window_box_width (it
->w
, TEXT_AREA
)
17314 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17316 if (align_to
&& *align_to
< 0)
17319 if (EQ (prop
, Qleft
))
17320 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17321 if (EQ (prop
, Qright
))
17322 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17323 if (EQ (prop
, Qcenter
))
17324 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17325 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17326 if (EQ (prop
, Qleft_fringe
))
17327 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17328 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17329 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17330 if (EQ (prop
, Qright_fringe
))
17331 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17332 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17333 : window_box_right_offset (it
->w
, TEXT_AREA
));
17334 if (EQ (prop
, Qleft_margin
))
17335 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17336 if (EQ (prop
, Qright_margin
))
17337 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17338 if (EQ (prop
, Qscroll_bar
))
17339 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17341 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17342 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17343 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17348 if (EQ (prop
, Qleft_fringe
))
17349 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17350 if (EQ (prop
, Qright_fringe
))
17351 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17352 if (EQ (prop
, Qleft_margin
))
17353 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17354 if (EQ (prop
, Qright_margin
))
17355 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17356 if (EQ (prop
, Qscroll_bar
))
17357 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17360 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17363 if (INTEGERP (prop
) || FLOATP (prop
))
17365 int base_unit
= (width_p
17366 ? FRAME_COLUMN_WIDTH (it
->f
)
17367 : FRAME_LINE_HEIGHT (it
->f
));
17368 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17373 Lisp_Object car
= XCAR (prop
);
17374 Lisp_Object cdr
= XCDR (prop
);
17378 #ifdef HAVE_WINDOW_SYSTEM
17379 if (valid_image_p (prop
))
17381 int id
= lookup_image (it
->f
, prop
);
17382 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17384 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17387 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17393 while (CONSP (cdr
))
17395 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17396 font
, width_p
, align_to
))
17399 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17404 if (EQ (car
, Qminus
))
17406 return OK_PIXELS (pixels
);
17409 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17412 if (INTEGERP (car
) || FLOATP (car
))
17415 pixels
= XFLOATINT (car
);
17417 return OK_PIXELS (pixels
);
17418 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17419 font
, width_p
, align_to
))
17420 return OK_PIXELS (pixels
* fact
);
17431 /***********************************************************************
17433 ***********************************************************************/
17435 #ifdef HAVE_WINDOW_SYSTEM
17440 dump_glyph_string (s
)
17441 struct glyph_string
*s
;
17443 fprintf (stderr
, "glyph string\n");
17444 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17445 s
->x
, s
->y
, s
->width
, s
->height
);
17446 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17447 fprintf (stderr
, " hl = %d\n", s
->hl
);
17448 fprintf (stderr
, " left overhang = %d, right = %d\n",
17449 s
->left_overhang
, s
->right_overhang
);
17450 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17451 fprintf (stderr
, " extends to end of line = %d\n",
17452 s
->extends_to_end_of_line_p
);
17453 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17454 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17457 #endif /* GLYPH_DEBUG */
17459 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17460 of XChar2b structures for S; it can't be allocated in
17461 init_glyph_string because it must be allocated via `alloca'. W
17462 is the window on which S is drawn. ROW and AREA are the glyph row
17463 and area within the row from which S is constructed. START is the
17464 index of the first glyph structure covered by S. HL is a
17465 face-override for drawing S. */
17468 #define OPTIONAL_HDC(hdc) hdc,
17469 #define DECLARE_HDC(hdc) HDC hdc;
17470 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17471 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17474 #ifndef OPTIONAL_HDC
17475 #define OPTIONAL_HDC(hdc)
17476 #define DECLARE_HDC(hdc)
17477 #define ALLOCATE_HDC(hdc, f)
17478 #define RELEASE_HDC(hdc, f)
17482 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17483 struct glyph_string
*s
;
17487 struct glyph_row
*row
;
17488 enum glyph_row_area area
;
17490 enum draw_glyphs_face hl
;
17492 bzero (s
, sizeof *s
);
17494 s
->f
= XFRAME (w
->frame
);
17498 s
->display
= FRAME_X_DISPLAY (s
->f
);
17499 s
->window
= FRAME_X_WINDOW (s
->f
);
17500 s
->char2b
= char2b
;
17504 s
->first_glyph
= row
->glyphs
[area
] + start
;
17505 s
->height
= row
->height
;
17506 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17508 /* Display the internal border below the tool-bar window. */
17509 if (WINDOWP (s
->f
->tool_bar_window
)
17510 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17511 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17513 s
->ybase
= s
->y
+ row
->ascent
;
17517 /* Append the list of glyph strings with head H and tail T to the list
17518 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17521 append_glyph_string_lists (head
, tail
, h
, t
)
17522 struct glyph_string
**head
, **tail
;
17523 struct glyph_string
*h
, *t
;
17537 /* Prepend the list of glyph strings with head H and tail T to the
17538 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17542 prepend_glyph_string_lists (head
, tail
, h
, t
)
17543 struct glyph_string
**head
, **tail
;
17544 struct glyph_string
*h
, *t
;
17558 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17559 Set *HEAD and *TAIL to the resulting list. */
17562 append_glyph_string (head
, tail
, s
)
17563 struct glyph_string
**head
, **tail
;
17564 struct glyph_string
*s
;
17566 s
->next
= s
->prev
= NULL
;
17567 append_glyph_string_lists (head
, tail
, s
, s
);
17571 /* Get face and two-byte form of character glyph GLYPH on frame F.
17572 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17573 a pointer to a realized face that is ready for display. */
17575 static INLINE
struct face
*
17576 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17578 struct glyph
*glyph
;
17584 xassert (glyph
->type
== CHAR_GLYPH
);
17585 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17590 if (!glyph
->multibyte_p
)
17592 /* Unibyte case. We don't have to encode, but we have to make
17593 sure to use a face suitable for unibyte. */
17594 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17596 else if (glyph
->u
.ch
< 128
17597 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17599 /* Case of ASCII in a face known to fit ASCII. */
17600 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17604 int c1
, c2
, charset
;
17606 /* Split characters into bytes. If c2 is -1 afterwards, C is
17607 really a one-byte character so that byte1 is zero. */
17608 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17610 STORE_XCHAR2B (char2b
, c1
, c2
);
17612 STORE_XCHAR2B (char2b
, 0, c1
);
17614 /* Maybe encode the character in *CHAR2B. */
17615 if (charset
!= CHARSET_ASCII
)
17617 struct font_info
*font_info
17618 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17621 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17625 /* Make sure X resources of the face are allocated. */
17626 xassert (face
!= NULL
);
17627 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17632 /* Fill glyph string S with composition components specified by S->cmp.
17634 FACES is an array of faces for all components of this composition.
17635 S->gidx is the index of the first component for S.
17636 OVERLAPS_P non-zero means S should draw the foreground only, and
17637 use its physical height for clipping.
17639 Value is the index of a component not in S. */
17642 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17643 struct glyph_string
*s
;
17644 struct face
**faces
;
17651 s
->for_overlaps_p
= overlaps_p
;
17653 s
->face
= faces
[s
->gidx
];
17654 s
->font
= s
->face
->font
;
17655 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17657 /* For all glyphs of this composition, starting at the offset
17658 S->gidx, until we reach the end of the definition or encounter a
17659 glyph that requires the different face, add it to S. */
17661 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17664 /* All glyph strings for the same composition has the same width,
17665 i.e. the width set for the first component of the composition. */
17667 s
->width
= s
->first_glyph
->pixel_width
;
17669 /* If the specified font could not be loaded, use the frame's
17670 default font, but record the fact that we couldn't load it in
17671 the glyph string so that we can draw rectangles for the
17672 characters of the glyph string. */
17673 if (s
->font
== NULL
)
17675 s
->font_not_found_p
= 1;
17676 s
->font
= FRAME_FONT (s
->f
);
17679 /* Adjust base line for subscript/superscript text. */
17680 s
->ybase
+= s
->first_glyph
->voffset
;
17682 xassert (s
->face
&& s
->face
->gc
);
17684 /* This glyph string must always be drawn with 16-bit functions. */
17687 return s
->gidx
+ s
->nchars
;
17691 /* Fill glyph string S from a sequence of character glyphs.
17693 FACE_ID is the face id of the string. START is the index of the
17694 first glyph to consider, END is the index of the last + 1.
17695 OVERLAPS_P non-zero means S should draw the foreground only, and
17696 use its physical height for clipping.
17698 Value is the index of the first glyph not in S. */
17701 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17702 struct glyph_string
*s
;
17704 int start
, end
, overlaps_p
;
17706 struct glyph
*glyph
, *last
;
17708 int glyph_not_available_p
;
17710 xassert (s
->f
== XFRAME (s
->w
->frame
));
17711 xassert (s
->nchars
== 0);
17712 xassert (start
>= 0 && end
> start
);
17714 s
->for_overlaps_p
= overlaps_p
,
17715 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17716 last
= s
->row
->glyphs
[s
->area
] + end
;
17717 voffset
= glyph
->voffset
;
17719 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17721 while (glyph
< last
17722 && glyph
->type
== CHAR_GLYPH
17723 && glyph
->voffset
== voffset
17724 /* Same face id implies same font, nowadays. */
17725 && glyph
->face_id
== face_id
17726 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17730 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17731 s
->char2b
+ s
->nchars
,
17733 s
->two_byte_p
= two_byte_p
;
17735 xassert (s
->nchars
<= end
- start
);
17736 s
->width
+= glyph
->pixel_width
;
17740 s
->font
= s
->face
->font
;
17741 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17743 /* If the specified font could not be loaded, use the frame's font,
17744 but record the fact that we couldn't load it in
17745 S->font_not_found_p so that we can draw rectangles for the
17746 characters of the glyph string. */
17747 if (s
->font
== NULL
|| glyph_not_available_p
)
17749 s
->font_not_found_p
= 1;
17750 s
->font
= FRAME_FONT (s
->f
);
17753 /* Adjust base line for subscript/superscript text. */
17754 s
->ybase
+= voffset
;
17756 xassert (s
->face
&& s
->face
->gc
);
17757 return glyph
- s
->row
->glyphs
[s
->area
];
17761 /* Fill glyph string S from image glyph S->first_glyph. */
17764 fill_image_glyph_string (s
)
17765 struct glyph_string
*s
;
17767 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17768 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17770 s
->slice
= s
->first_glyph
->slice
;
17771 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17772 s
->font
= s
->face
->font
;
17773 s
->width
= s
->first_glyph
->pixel_width
;
17775 /* Adjust base line for subscript/superscript text. */
17776 s
->ybase
+= s
->first_glyph
->voffset
;
17780 /* Fill glyph string S from a sequence of stretch glyphs.
17782 ROW is the glyph row in which the glyphs are found, AREA is the
17783 area within the row. START is the index of the first glyph to
17784 consider, END is the index of the last + 1.
17786 Value is the index of the first glyph not in S. */
17789 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17790 struct glyph_string
*s
;
17791 struct glyph_row
*row
;
17792 enum glyph_row_area area
;
17795 struct glyph
*glyph
, *last
;
17796 int voffset
, face_id
;
17798 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17800 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17801 last
= s
->row
->glyphs
[s
->area
] + end
;
17802 face_id
= glyph
->face_id
;
17803 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17804 s
->font
= s
->face
->font
;
17805 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17806 s
->width
= glyph
->pixel_width
;
17807 voffset
= glyph
->voffset
;
17811 && glyph
->type
== STRETCH_GLYPH
17812 && glyph
->voffset
== voffset
17813 && glyph
->face_id
== face_id
);
17815 s
->width
+= glyph
->pixel_width
;
17817 /* Adjust base line for subscript/superscript text. */
17818 s
->ybase
+= voffset
;
17820 /* The case that face->gc == 0 is handled when drawing the glyph
17821 string by calling PREPARE_FACE_FOR_DISPLAY. */
17823 return glyph
- s
->row
->glyphs
[s
->area
];
17828 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17829 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17830 assumed to be zero. */
17833 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17834 struct glyph
*glyph
;
17838 *left
= *right
= 0;
17840 if (glyph
->type
== CHAR_GLYPH
)
17844 struct font_info
*font_info
;
17848 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17850 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17851 if (font
/* ++KFS: Should this be font_info ? */
17852 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17854 if (pcm
->rbearing
> pcm
->width
)
17855 *right
= pcm
->rbearing
- pcm
->width
;
17856 if (pcm
->lbearing
< 0)
17857 *left
= -pcm
->lbearing
;
17863 /* Return the index of the first glyph preceding glyph string S that
17864 is overwritten by S because of S's left overhang. Value is -1
17865 if no glyphs are overwritten. */
17868 left_overwritten (s
)
17869 struct glyph_string
*s
;
17873 if (s
->left_overhang
)
17876 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17877 int first
= s
->first_glyph
- glyphs
;
17879 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17880 x
-= glyphs
[i
].pixel_width
;
17891 /* Return the index of the first glyph preceding glyph string S that
17892 is overwriting S because of its right overhang. Value is -1 if no
17893 glyph in front of S overwrites S. */
17896 left_overwriting (s
)
17897 struct glyph_string
*s
;
17900 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17901 int first
= s
->first_glyph
- glyphs
;
17905 for (i
= first
- 1; i
>= 0; --i
)
17908 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17911 x
-= glyphs
[i
].pixel_width
;
17918 /* Return the index of the last glyph following glyph string S that is
17919 not overwritten by S because of S's right overhang. Value is -1 if
17920 no such glyph is found. */
17923 right_overwritten (s
)
17924 struct glyph_string
*s
;
17928 if (s
->right_overhang
)
17931 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17932 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17933 int end
= s
->row
->used
[s
->area
];
17935 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17936 x
+= glyphs
[i
].pixel_width
;
17945 /* Return the index of the last glyph following glyph string S that
17946 overwrites S because of its left overhang. Value is negative
17947 if no such glyph is found. */
17950 right_overwriting (s
)
17951 struct glyph_string
*s
;
17954 int end
= s
->row
->used
[s
->area
];
17955 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17956 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17960 for (i
= first
; i
< end
; ++i
)
17963 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17966 x
+= glyphs
[i
].pixel_width
;
17973 /* Get face and two-byte form of character C in face FACE_ID on frame
17974 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17975 means we want to display multibyte text. DISPLAY_P non-zero means
17976 make sure that X resources for the face returned are allocated.
17977 Value is a pointer to a realized face that is ready for display if
17978 DISPLAY_P is non-zero. */
17980 static INLINE
struct face
*
17981 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17985 int multibyte_p
, display_p
;
17987 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17991 /* Unibyte case. We don't have to encode, but we have to make
17992 sure to use a face suitable for unibyte. */
17993 STORE_XCHAR2B (char2b
, 0, c
);
17994 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17995 face
= FACE_FROM_ID (f
, face_id
);
17997 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17999 /* Case of ASCII in a face known to fit ASCII. */
18000 STORE_XCHAR2B (char2b
, 0, c
);
18004 int c1
, c2
, charset
;
18006 /* Split characters into bytes. If c2 is -1 afterwards, C is
18007 really a one-byte character so that byte1 is zero. */
18008 SPLIT_CHAR (c
, charset
, c1
, c2
);
18010 STORE_XCHAR2B (char2b
, c1
, c2
);
18012 STORE_XCHAR2B (char2b
, 0, c1
);
18014 /* Maybe encode the character in *CHAR2B. */
18015 if (face
->font
!= NULL
)
18017 struct font_info
*font_info
18018 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18020 rif
->encode_char (c
, char2b
, font_info
, 0);
18024 /* Make sure X resources of the face are allocated. */
18025 #ifdef HAVE_X_WINDOWS
18029 xassert (face
!= NULL
);
18030 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18037 /* Set background width of glyph string S. START is the index of the
18038 first glyph following S. LAST_X is the right-most x-position + 1
18039 in the drawing area. */
18042 set_glyph_string_background_width (s
, start
, last_x
)
18043 struct glyph_string
*s
;
18047 /* If the face of this glyph string has to be drawn to the end of
18048 the drawing area, set S->extends_to_end_of_line_p. */
18049 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18051 if (start
== s
->row
->used
[s
->area
]
18052 && s
->area
== TEXT_AREA
18053 && ((s
->hl
== DRAW_NORMAL_TEXT
18054 && (s
->row
->fill_line_p
18055 || s
->face
->background
!= default_face
->background
18056 || s
->face
->stipple
!= default_face
->stipple
18057 || s
->row
->mouse_face_p
))
18058 || s
->hl
== DRAW_MOUSE_FACE
18059 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18060 && s
->row
->fill_line_p
)))
18061 s
->extends_to_end_of_line_p
= 1;
18063 /* If S extends its face to the end of the line, set its
18064 background_width to the distance to the right edge of the drawing
18066 if (s
->extends_to_end_of_line_p
)
18067 s
->background_width
= last_x
- s
->x
+ 1;
18069 s
->background_width
= s
->width
;
18073 /* Compute overhangs and x-positions for glyph string S and its
18074 predecessors, or successors. X is the starting x-position for S.
18075 BACKWARD_P non-zero means process predecessors. */
18078 compute_overhangs_and_x (s
, x
, backward_p
)
18079 struct glyph_string
*s
;
18087 if (rif
->compute_glyph_string_overhangs
)
18088 rif
->compute_glyph_string_overhangs (s
);
18098 if (rif
->compute_glyph_string_overhangs
)
18099 rif
->compute_glyph_string_overhangs (s
);
18109 /* The following macros are only called from draw_glyphs below.
18110 They reference the following parameters of that function directly:
18111 `w', `row', `area', and `overlap_p'
18112 as well as the following local variables:
18113 `s', `f', and `hdc' (in W32) */
18116 /* On W32, silently add local `hdc' variable to argument list of
18117 init_glyph_string. */
18118 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18119 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18121 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18122 init_glyph_string (s, char2b, w, row, area, start, hl)
18125 /* Add a glyph string for a stretch glyph to the list of strings
18126 between HEAD and TAIL. START is the index of the stretch glyph in
18127 row area AREA of glyph row ROW. END is the index of the last glyph
18128 in that glyph row area. X is the current output position assigned
18129 to the new glyph string constructed. HL overrides that face of the
18130 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18131 is the right-most x-position of the drawing area. */
18133 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18134 and below -- keep them on one line. */
18135 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18138 s = (struct glyph_string *) alloca (sizeof *s); \
18139 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18140 START = fill_stretch_glyph_string (s, row, area, START, END); \
18141 append_glyph_string (&HEAD, &TAIL, s); \
18147 /* Add a glyph string for an image glyph to the list of strings
18148 between HEAD and TAIL. START is the index of the image glyph in
18149 row area AREA of glyph row ROW. END is the index of the last glyph
18150 in that glyph row area. X is the current output position assigned
18151 to the new glyph string constructed. HL overrides that face of the
18152 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18153 is the right-most x-position of the drawing area. */
18155 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18158 s = (struct glyph_string *) alloca (sizeof *s); \
18159 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18160 fill_image_glyph_string (s); \
18161 append_glyph_string (&HEAD, &TAIL, s); \
18168 /* Add a glyph string for a sequence of character glyphs to the list
18169 of strings between HEAD and TAIL. START is the index of the first
18170 glyph in row area AREA of glyph row ROW that is part of the new
18171 glyph string. END is the index of the last glyph in that glyph row
18172 area. X is the current output position assigned to the new glyph
18173 string constructed. HL overrides that face of the glyph; e.g. it
18174 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18175 right-most x-position of the drawing area. */
18177 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18183 c = (row)->glyphs[area][START].u.ch; \
18184 face_id = (row)->glyphs[area][START].face_id; \
18186 s = (struct glyph_string *) alloca (sizeof *s); \
18187 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18188 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18189 append_glyph_string (&HEAD, &TAIL, s); \
18191 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18196 /* Add a glyph string for a composite sequence to the list of strings
18197 between HEAD and TAIL. START is the index of the first glyph in
18198 row area AREA of glyph row ROW that is part of the new glyph
18199 string. END is the index of the last glyph in that glyph row area.
18200 X is the current output position assigned to the new glyph string
18201 constructed. HL overrides that face of the glyph; e.g. it is
18202 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18203 x-position of the drawing area. */
18205 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18207 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18208 int face_id = (row)->glyphs[area][START].face_id; \
18209 struct face *base_face = FACE_FROM_ID (f, face_id); \
18210 struct composition *cmp = composition_table[cmp_id]; \
18211 int glyph_len = cmp->glyph_len; \
18213 struct face **faces; \
18214 struct glyph_string *first_s = NULL; \
18217 base_face = base_face->ascii_face; \
18218 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18219 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18220 /* At first, fill in `char2b' and `faces'. */ \
18221 for (n = 0; n < glyph_len; n++) \
18223 int c = COMPOSITION_GLYPH (cmp, n); \
18224 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18225 faces[n] = FACE_FROM_ID (f, this_face_id); \
18226 get_char_face_and_encoding (f, c, this_face_id, \
18227 char2b + n, 1, 1); \
18230 /* Make glyph_strings for each glyph sequence that is drawable by \
18231 the same face, and append them to HEAD/TAIL. */ \
18232 for (n = 0; n < cmp->glyph_len;) \
18234 s = (struct glyph_string *) alloca (sizeof *s); \
18235 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18236 append_glyph_string (&(HEAD), &(TAIL), s); \
18244 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18252 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18253 of AREA of glyph row ROW on window W between indices START and END.
18254 HL overrides the face for drawing glyph strings, e.g. it is
18255 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18256 x-positions of the drawing area.
18258 This is an ugly monster macro construct because we must use alloca
18259 to allocate glyph strings (because draw_glyphs can be called
18260 asynchronously). */
18262 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18265 HEAD = TAIL = NULL; \
18266 while (START < END) \
18268 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18269 switch (first_glyph->type) \
18272 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18276 case COMPOSITE_GLYPH: \
18277 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18281 case STRETCH_GLYPH: \
18282 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18286 case IMAGE_GLYPH: \
18287 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18295 set_glyph_string_background_width (s, START, LAST_X); \
18302 /* Draw glyphs between START and END in AREA of ROW on window W,
18303 starting at x-position X. X is relative to AREA in W. HL is a
18304 face-override with the following meaning:
18306 DRAW_NORMAL_TEXT draw normally
18307 DRAW_CURSOR draw in cursor face
18308 DRAW_MOUSE_FACE draw in mouse face.
18309 DRAW_INVERSE_VIDEO draw in mode line face
18310 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18311 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18313 If OVERLAPS_P is non-zero, draw only the foreground of characters
18314 and clip to the physical height of ROW.
18316 Value is the x-position reached, relative to AREA of W. */
18319 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18322 struct glyph_row
*row
;
18323 enum glyph_row_area area
;
18325 enum draw_glyphs_face hl
;
18328 struct glyph_string
*head
, *tail
;
18329 struct glyph_string
*s
;
18330 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18331 int last_x
, area_width
;
18334 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18337 ALLOCATE_HDC (hdc
, f
);
18339 /* Let's rather be paranoid than getting a SEGV. */
18340 end
= min (end
, row
->used
[area
]);
18341 start
= max (0, start
);
18342 start
= min (end
, start
);
18344 /* Translate X to frame coordinates. Set last_x to the right
18345 end of the drawing area. */
18346 if (row
->full_width_p
)
18348 /* X is relative to the left edge of W, without scroll bars
18350 x
+= WINDOW_LEFT_EDGE_X (w
);
18351 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18355 int area_left
= window_box_left (w
, area
);
18357 area_width
= window_box_width (w
, area
);
18358 last_x
= area_left
+ area_width
;
18361 /* Build a doubly-linked list of glyph_string structures between
18362 head and tail from what we have to draw. Note that the macro
18363 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18364 the reason we use a separate variable `i'. */
18366 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18368 x_reached
= tail
->x
+ tail
->background_width
;
18372 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18373 the row, redraw some glyphs in front or following the glyph
18374 strings built above. */
18375 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18378 struct glyph_string
*h
, *t
;
18380 /* Compute overhangs for all glyph strings. */
18381 if (rif
->compute_glyph_string_overhangs
)
18382 for (s
= head
; s
; s
= s
->next
)
18383 rif
->compute_glyph_string_overhangs (s
);
18385 /* Prepend glyph strings for glyphs in front of the first glyph
18386 string that are overwritten because of the first glyph
18387 string's left overhang. The background of all strings
18388 prepended must be drawn because the first glyph string
18390 i
= left_overwritten (head
);
18394 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18395 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18397 compute_overhangs_and_x (t
, head
->x
, 1);
18398 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18402 /* Prepend glyph strings for glyphs in front of the first glyph
18403 string that overwrite that glyph string because of their
18404 right overhang. For these strings, only the foreground must
18405 be drawn, because it draws over the glyph string at `head'.
18406 The background must not be drawn because this would overwrite
18407 right overhangs of preceding glyphs for which no glyph
18409 i
= left_overwriting (head
);
18413 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18414 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18415 for (s
= h
; s
; s
= s
->next
)
18416 s
->background_filled_p
= 1;
18417 compute_overhangs_and_x (t
, head
->x
, 1);
18418 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18421 /* Append glyphs strings for glyphs following the last glyph
18422 string tail that are overwritten by tail. The background of
18423 these strings has to be drawn because tail's foreground draws
18425 i
= right_overwritten (tail
);
18428 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18429 DRAW_NORMAL_TEXT
, x
, last_x
);
18430 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18431 append_glyph_string_lists (&head
, &tail
, h
, t
);
18435 /* Append glyph strings for glyphs following the last glyph
18436 string tail that overwrite tail. The foreground of such
18437 glyphs has to be drawn because it writes into the background
18438 of tail. The background must not be drawn because it could
18439 paint over the foreground of following glyphs. */
18440 i
= right_overwriting (tail
);
18444 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18445 DRAW_NORMAL_TEXT
, x
, last_x
);
18446 for (s
= h
; s
; s
= s
->next
)
18447 s
->background_filled_p
= 1;
18448 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18449 append_glyph_string_lists (&head
, &tail
, h
, t
);
18451 if (clip_head
|| clip_tail
)
18452 for (s
= head
; s
; s
= s
->next
)
18454 s
->clip_head
= clip_head
;
18455 s
->clip_tail
= clip_tail
;
18459 /* Draw all strings. */
18460 for (s
= head
; s
; s
= s
->next
)
18461 rif
->draw_glyph_string (s
);
18463 if (area
== TEXT_AREA
18464 && !row
->full_width_p
18465 /* When drawing overlapping rows, only the glyph strings'
18466 foreground is drawn, which doesn't erase a cursor
18470 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18471 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18472 : (tail
? tail
->x
+ tail
->background_width
: x
));
18474 int text_left
= window_box_left (w
, TEXT_AREA
);
18478 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18479 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18482 /* Value is the x-position up to which drawn, relative to AREA of W.
18483 This doesn't include parts drawn because of overhangs. */
18484 if (row
->full_width_p
)
18485 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18487 x_reached
-= window_box_left (w
, area
);
18489 RELEASE_HDC (hdc
, f
);
18494 /* Expand row matrix if too narrow. Don't expand if area
18497 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18499 if (!fonts_changed_p \
18500 && (it->glyph_row->glyphs[area] \
18501 < it->glyph_row->glyphs[area + 1])) \
18503 it->w->ncols_scale_factor++; \
18504 fonts_changed_p = 1; \
18508 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18509 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18515 struct glyph
*glyph
;
18516 enum glyph_row_area area
= it
->area
;
18518 xassert (it
->glyph_row
);
18519 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18521 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18522 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18524 glyph
->charpos
= CHARPOS (it
->position
);
18525 glyph
->object
= it
->object
;
18526 glyph
->pixel_width
= it
->pixel_width
;
18527 glyph
->ascent
= it
->ascent
;
18528 glyph
->descent
= it
->descent
;
18529 glyph
->voffset
= it
->voffset
;
18530 glyph
->type
= CHAR_GLYPH
;
18531 glyph
->multibyte_p
= it
->multibyte_p
;
18532 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18533 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18534 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18535 || it
->phys_descent
> it
->descent
);
18536 glyph
->padding_p
= 0;
18537 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18538 glyph
->face_id
= it
->face_id
;
18539 glyph
->u
.ch
= it
->char_to_display
;
18540 glyph
->slice
= null_glyph_slice
;
18541 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18542 ++it
->glyph_row
->used
[area
];
18545 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18548 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18549 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18552 append_composite_glyph (it
)
18555 struct glyph
*glyph
;
18556 enum glyph_row_area area
= it
->area
;
18558 xassert (it
->glyph_row
);
18560 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18561 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18563 glyph
->charpos
= CHARPOS (it
->position
);
18564 glyph
->object
= it
->object
;
18565 glyph
->pixel_width
= it
->pixel_width
;
18566 glyph
->ascent
= it
->ascent
;
18567 glyph
->descent
= it
->descent
;
18568 glyph
->voffset
= it
->voffset
;
18569 glyph
->type
= COMPOSITE_GLYPH
;
18570 glyph
->multibyte_p
= it
->multibyte_p
;
18571 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18572 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18573 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18574 || it
->phys_descent
> it
->descent
);
18575 glyph
->padding_p
= 0;
18576 glyph
->glyph_not_available_p
= 0;
18577 glyph
->face_id
= it
->face_id
;
18578 glyph
->u
.cmp_id
= it
->cmp_id
;
18579 glyph
->slice
= null_glyph_slice
;
18580 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18581 ++it
->glyph_row
->used
[area
];
18584 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18588 /* Change IT->ascent and IT->height according to the setting of
18592 take_vertical_position_into_account (it
)
18597 if (it
->voffset
< 0)
18598 /* Increase the ascent so that we can display the text higher
18600 it
->ascent
-= it
->voffset
;
18602 /* Increase the descent so that we can display the text lower
18604 it
->descent
+= it
->voffset
;
18609 /* Produce glyphs/get display metrics for the image IT is loaded with.
18610 See the description of struct display_iterator in dispextern.h for
18611 an overview of struct display_iterator. */
18614 produce_image_glyph (it
)
18620 struct glyph_slice slice
;
18622 xassert (it
->what
== IT_IMAGE
);
18624 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18626 /* Make sure X resources of the face is loaded. */
18627 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18629 if (it
->image_id
< 0)
18631 /* Fringe bitmap. */
18632 it
->ascent
= it
->phys_ascent
= 0;
18633 it
->descent
= it
->phys_descent
= 0;
18634 it
->pixel_width
= 0;
18639 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18641 /* Make sure X resources of the image is loaded. */
18642 prepare_image_for_display (it
->f
, img
);
18644 slice
.x
= slice
.y
= 0;
18645 slice
.width
= img
->width
;
18646 slice
.height
= img
->height
;
18648 if (INTEGERP (it
->slice
.x
))
18649 slice
.x
= XINT (it
->slice
.x
);
18650 else if (FLOATP (it
->slice
.x
))
18651 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18653 if (INTEGERP (it
->slice
.y
))
18654 slice
.y
= XINT (it
->slice
.y
);
18655 else if (FLOATP (it
->slice
.y
))
18656 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18658 if (INTEGERP (it
->slice
.width
))
18659 slice
.width
= XINT (it
->slice
.width
);
18660 else if (FLOATP (it
->slice
.width
))
18661 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18663 if (INTEGERP (it
->slice
.height
))
18664 slice
.height
= XINT (it
->slice
.height
);
18665 else if (FLOATP (it
->slice
.height
))
18666 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18668 if (slice
.x
>= img
->width
)
18669 slice
.x
= img
->width
;
18670 if (slice
.y
>= img
->height
)
18671 slice
.y
= img
->height
;
18672 if (slice
.x
+ slice
.width
>= img
->width
)
18673 slice
.width
= img
->width
- slice
.x
;
18674 if (slice
.y
+ slice
.height
> img
->height
)
18675 slice
.height
= img
->height
- slice
.y
;
18677 if (slice
.width
== 0 || slice
.height
== 0)
18680 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18682 it
->descent
= slice
.height
- glyph_ascent
;
18684 it
->descent
+= img
->vmargin
;
18685 if (slice
.y
+ slice
.height
== img
->height
)
18686 it
->descent
+= img
->vmargin
;
18687 it
->phys_descent
= it
->descent
;
18689 it
->pixel_width
= slice
.width
;
18691 it
->pixel_width
+= img
->hmargin
;
18692 if (slice
.x
+ slice
.width
== img
->width
)
18693 it
->pixel_width
+= img
->hmargin
;
18695 /* It's quite possible for images to have an ascent greater than
18696 their height, so don't get confused in that case. */
18697 if (it
->descent
< 0)
18700 #if 0 /* this breaks image tiling */
18701 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18702 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18703 if (face_ascent
> it
->ascent
)
18704 it
->ascent
= it
->phys_ascent
= face_ascent
;
18709 if (face
->box
!= FACE_NO_BOX
)
18711 if (face
->box_line_width
> 0)
18714 it
->ascent
+= face
->box_line_width
;
18715 if (slice
.y
+ slice
.height
== img
->height
)
18716 it
->descent
+= face
->box_line_width
;
18719 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18720 it
->pixel_width
+= abs (face
->box_line_width
);
18721 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18722 it
->pixel_width
+= abs (face
->box_line_width
);
18725 take_vertical_position_into_account (it
);
18729 struct glyph
*glyph
;
18730 enum glyph_row_area area
= it
->area
;
18732 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18733 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18735 glyph
->charpos
= CHARPOS (it
->position
);
18736 glyph
->object
= it
->object
;
18737 glyph
->pixel_width
= it
->pixel_width
;
18738 glyph
->ascent
= glyph_ascent
;
18739 glyph
->descent
= it
->descent
;
18740 glyph
->voffset
= it
->voffset
;
18741 glyph
->type
= IMAGE_GLYPH
;
18742 glyph
->multibyte_p
= it
->multibyte_p
;
18743 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18744 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18745 glyph
->overlaps_vertically_p
= 0;
18746 glyph
->padding_p
= 0;
18747 glyph
->glyph_not_available_p
= 0;
18748 glyph
->face_id
= it
->face_id
;
18749 glyph
->u
.img_id
= img
->id
;
18750 glyph
->slice
= slice
;
18751 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18752 ++it
->glyph_row
->used
[area
];
18755 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18760 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18761 of the glyph, WIDTH and HEIGHT are the width and height of the
18762 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18765 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18767 Lisp_Object object
;
18771 struct glyph
*glyph
;
18772 enum glyph_row_area area
= it
->area
;
18774 xassert (ascent
>= 0 && ascent
<= height
);
18776 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18777 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18779 glyph
->charpos
= CHARPOS (it
->position
);
18780 glyph
->object
= object
;
18781 glyph
->pixel_width
= width
;
18782 glyph
->ascent
= ascent
;
18783 glyph
->descent
= height
- ascent
;
18784 glyph
->voffset
= it
->voffset
;
18785 glyph
->type
= STRETCH_GLYPH
;
18786 glyph
->multibyte_p
= it
->multibyte_p
;
18787 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18788 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18789 glyph
->overlaps_vertically_p
= 0;
18790 glyph
->padding_p
= 0;
18791 glyph
->glyph_not_available_p
= 0;
18792 glyph
->face_id
= it
->face_id
;
18793 glyph
->u
.stretch
.ascent
= ascent
;
18794 glyph
->u
.stretch
.height
= height
;
18795 glyph
->slice
= null_glyph_slice
;
18796 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18797 ++it
->glyph_row
->used
[area
];
18800 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18804 /* Produce a stretch glyph for iterator IT. IT->object is the value
18805 of the glyph property displayed. The value must be a list
18806 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18809 1. `:width WIDTH' specifies that the space should be WIDTH *
18810 canonical char width wide. WIDTH may be an integer or floating
18813 2. `:relative-width FACTOR' specifies that the width of the stretch
18814 should be computed from the width of the first character having the
18815 `glyph' property, and should be FACTOR times that width.
18817 3. `:align-to HPOS' specifies that the space should be wide enough
18818 to reach HPOS, a value in canonical character units.
18820 Exactly one of the above pairs must be present.
18822 4. `:height HEIGHT' specifies that the height of the stretch produced
18823 should be HEIGHT, measured in canonical character units.
18825 5. `:relative-height FACTOR' specifies that the height of the
18826 stretch should be FACTOR times the height of the characters having
18827 the glyph property.
18829 Either none or exactly one of 4 or 5 must be present.
18831 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18832 of the stretch should be used for the ascent of the stretch.
18833 ASCENT must be in the range 0 <= ASCENT <= 100. */
18836 produce_stretch_glyph (it
)
18839 /* (space :width WIDTH :height HEIGHT ...) */
18840 Lisp_Object prop
, plist
;
18841 int width
= 0, height
= 0, align_to
= -1;
18842 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18845 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18846 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18848 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18850 /* List should start with `space'. */
18851 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18852 plist
= XCDR (it
->object
);
18854 /* Compute the width of the stretch. */
18855 if ((prop
= Fsafe_plist_get (plist
, QCwidth
), !NILP (prop
))
18856 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18858 /* Absolute width `:width WIDTH' specified and valid. */
18859 zero_width_ok_p
= 1;
18862 else if (prop
= Fsafe_plist_get (plist
, QCrelative_width
),
18865 /* Relative width `:relative-width FACTOR' specified and valid.
18866 Compute the width of the characters having the `glyph'
18869 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18872 if (it
->multibyte_p
)
18874 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18875 - IT_BYTEPOS (*it
));
18876 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18879 it2
.c
= *p
, it2
.len
= 1;
18881 it2
.glyph_row
= NULL
;
18882 it2
.what
= IT_CHARACTER
;
18883 x_produce_glyphs (&it2
);
18884 width
= NUMVAL (prop
) * it2
.pixel_width
;
18886 else if ((prop
= Fsafe_plist_get (plist
, QCalign_to
), !NILP (prop
))
18887 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18889 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18890 align_to
= (align_to
< 0
18892 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18893 else if (align_to
< 0)
18894 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18895 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18896 zero_width_ok_p
= 1;
18899 /* Nothing specified -> width defaults to canonical char width. */
18900 width
= FRAME_COLUMN_WIDTH (it
->f
);
18902 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18905 /* Compute height. */
18906 if ((prop
= Fsafe_plist_get (plist
, QCheight
), !NILP (prop
))
18907 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18910 zero_height_ok_p
= 1;
18912 else if (prop
= Fsafe_plist_get (plist
, QCrelative_height
),
18914 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18916 height
= FONT_HEIGHT (font
);
18918 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18921 /* Compute percentage of height used for ascent. If
18922 `:ascent ASCENT' is present and valid, use that. Otherwise,
18923 derive the ascent from the font in use. */
18924 if (prop
= Fsafe_plist_get (plist
, QCascent
),
18925 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18926 ascent
= height
* NUMVAL (prop
) / 100.0;
18927 else if (!NILP (prop
)
18928 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18929 ascent
= min (max (0, (int)tem
), height
);
18931 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18933 if (width
> 0 && height
> 0 && it
->glyph_row
)
18935 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18936 if (!STRINGP (object
))
18937 object
= it
->w
->buffer
;
18938 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18941 it
->pixel_width
= width
;
18942 it
->ascent
= it
->phys_ascent
= ascent
;
18943 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18944 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18946 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18948 if (face
->box_line_width
> 0)
18950 it
->ascent
+= face
->box_line_width
;
18951 it
->descent
+= face
->box_line_width
;
18954 if (it
->start_of_box_run_p
)
18955 it
->pixel_width
+= abs (face
->box_line_width
);
18956 if (it
->end_of_box_run_p
)
18957 it
->pixel_width
+= abs (face
->box_line_width
);
18960 take_vertical_position_into_account (it
);
18963 /* Get line-height and line-spacing property at point.
18964 If line-height has format (HEIGHT TOTAL), return TOTAL
18965 in TOTAL_HEIGHT. */
18968 get_line_height_property (it
, prop
)
18972 Lisp_Object position
, val
;
18974 if (STRINGP (it
->object
))
18975 position
= make_number (IT_STRING_CHARPOS (*it
));
18976 else if (BUFFERP (it
->object
))
18977 position
= make_number (IT_CHARPOS (*it
));
18981 return Fget_char_property (position
, prop
, it
->object
);
18984 /* Calculate line-height and line-spacing properties.
18985 An integer value specifies explicit pixel value.
18986 A float value specifies relative value to current face height.
18987 A cons (float . face-name) specifies relative value to
18988 height of specified face font.
18990 Returns height in pixels, or nil. */
18994 calc_line_height_property (it
, val
, font
, boff
, override
)
18998 int boff
, override
;
19000 Lisp_Object face_name
= Qnil
;
19001 int ascent
, descent
, height
;
19003 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19008 face_name
= XCAR (val
);
19010 if (!NUMBERP (val
))
19011 val
= make_number (1);
19012 if (NILP (face_name
))
19014 height
= it
->ascent
+ it
->descent
;
19019 if (NILP (face_name
))
19021 font
= FRAME_FONT (it
->f
);
19022 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19024 else if (EQ (face_name
, Qt
))
19032 struct font_info
*font_info
;
19034 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19036 return make_number (-1);
19038 face
= FACE_FROM_ID (it
->f
, face_id
);
19041 return make_number (-1);
19043 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19044 boff
= font_info
->baseline_offset
;
19045 if (font_info
->vertical_centering
)
19046 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19049 ascent
= FONT_BASE (font
) + boff
;
19050 descent
= FONT_DESCENT (font
) - boff
;
19054 it
->override_ascent
= ascent
;
19055 it
->override_descent
= descent
;
19056 it
->override_boff
= boff
;
19059 height
= ascent
+ descent
;
19063 height
= (int)(XFLOAT_DATA (val
) * height
);
19064 else if (INTEGERP (val
))
19065 height
*= XINT (val
);
19067 return make_number (height
);
19072 Produce glyphs/get display metrics for the display element IT is
19073 loaded with. See the description of struct display_iterator in
19074 dispextern.h for an overview of struct display_iterator. */
19077 x_produce_glyphs (it
)
19080 int extra_line_spacing
= it
->extra_line_spacing
;
19082 it
->glyph_not_available_p
= 0;
19084 if (it
->what
== IT_CHARACTER
)
19088 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19090 int font_not_found_p
;
19091 struct font_info
*font_info
;
19092 int boff
; /* baseline offset */
19093 /* We may change it->multibyte_p upon unibyte<->multibyte
19094 conversion. So, save the current value now and restore it
19097 Note: It seems that we don't have to record multibyte_p in
19098 struct glyph because the character code itself tells if or
19099 not the character is multibyte. Thus, in the future, we must
19100 consider eliminating the field `multibyte_p' in the struct
19102 int saved_multibyte_p
= it
->multibyte_p
;
19104 /* Maybe translate single-byte characters to multibyte, or the
19106 it
->char_to_display
= it
->c
;
19107 if (!ASCII_BYTE_P (it
->c
))
19109 if (unibyte_display_via_language_environment
19110 && SINGLE_BYTE_CHAR_P (it
->c
)
19112 || !NILP (Vnonascii_translation_table
)))
19114 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19115 it
->multibyte_p
= 1;
19116 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19117 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19119 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19120 && !it
->multibyte_p
)
19122 it
->multibyte_p
= 1;
19123 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19124 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19128 /* Get font to use. Encode IT->char_to_display. */
19129 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19130 &char2b
, it
->multibyte_p
, 0);
19133 /* When no suitable font found, use the default font. */
19134 font_not_found_p
= font
== NULL
;
19135 if (font_not_found_p
)
19137 font
= FRAME_FONT (it
->f
);
19138 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19143 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19144 boff
= font_info
->baseline_offset
;
19145 if (font_info
->vertical_centering
)
19146 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19149 if (it
->char_to_display
>= ' '
19150 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19152 /* Either unibyte or ASCII. */
19157 pcm
= rif
->per_char_metric (font
, &char2b
,
19158 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19160 if (it
->override_ascent
>= 0)
19162 it
->ascent
= it
->override_ascent
;
19163 it
->descent
= it
->override_descent
;
19164 boff
= it
->override_boff
;
19168 it
->ascent
= FONT_BASE (font
) + boff
;
19169 it
->descent
= FONT_DESCENT (font
) - boff
;
19174 it
->phys_ascent
= pcm
->ascent
+ boff
;
19175 it
->phys_descent
= pcm
->descent
- boff
;
19176 it
->pixel_width
= pcm
->width
;
19180 it
->glyph_not_available_p
= 1;
19181 it
->phys_ascent
= it
->ascent
;
19182 it
->phys_descent
= it
->descent
;
19183 it
->pixel_width
= FONT_WIDTH (font
);
19186 if (it
->constrain_row_ascent_descent_p
)
19188 if (it
->descent
> it
->max_descent
)
19190 it
->ascent
+= it
->descent
- it
->max_descent
;
19191 it
->descent
= it
->max_descent
;
19193 if (it
->ascent
> it
->max_ascent
)
19195 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19196 it
->ascent
= it
->max_ascent
;
19198 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19199 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19200 extra_line_spacing
= 0;
19203 /* If this is a space inside a region of text with
19204 `space-width' property, change its width. */
19205 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19207 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19209 /* If face has a box, add the box thickness to the character
19210 height. If character has a box line to the left and/or
19211 right, add the box line width to the character's width. */
19212 if (face
->box
!= FACE_NO_BOX
)
19214 int thick
= face
->box_line_width
;
19218 it
->ascent
+= thick
;
19219 it
->descent
+= thick
;
19224 if (it
->start_of_box_run_p
)
19225 it
->pixel_width
+= thick
;
19226 if (it
->end_of_box_run_p
)
19227 it
->pixel_width
+= thick
;
19230 /* If face has an overline, add the height of the overline
19231 (1 pixel) and a 1 pixel margin to the character height. */
19232 if (face
->overline_p
)
19235 if (it
->constrain_row_ascent_descent_p
)
19237 if (it
->ascent
> it
->max_ascent
)
19238 it
->ascent
= it
->max_ascent
;
19239 if (it
->descent
> it
->max_descent
)
19240 it
->descent
= it
->max_descent
;
19243 take_vertical_position_into_account (it
);
19245 /* If we have to actually produce glyphs, do it. */
19250 /* Translate a space with a `space-width' property
19251 into a stretch glyph. */
19252 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19253 / FONT_HEIGHT (font
));
19254 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19255 it
->ascent
+ it
->descent
, ascent
);
19260 /* If characters with lbearing or rbearing are displayed
19261 in this line, record that fact in a flag of the
19262 glyph row. This is used to optimize X output code. */
19263 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19264 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19267 else if (it
->char_to_display
== '\n')
19269 /* A newline has no width but we need the height of the line.
19270 But if previous part of the line set a height, don't
19271 increase that height */
19273 Lisp_Object height
;
19274 Lisp_Object total_height
= Qnil
;
19276 it
->override_ascent
= -1;
19277 it
->pixel_width
= 0;
19280 height
= get_line_height_property(it
, Qline_height
);
19281 /* Split (line-height total-height) list */
19283 && CONSP (XCDR (height
))
19284 && NILP (XCDR (XCDR (height
))))
19286 total_height
= XCAR (XCDR (height
));
19287 height
= XCAR (height
);
19289 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19291 if (it
->override_ascent
>= 0)
19293 it
->ascent
= it
->override_ascent
;
19294 it
->descent
= it
->override_descent
;
19295 boff
= it
->override_boff
;
19299 it
->ascent
= FONT_BASE (font
) + boff
;
19300 it
->descent
= FONT_DESCENT (font
) - boff
;
19303 if (EQ (height
, Qt
))
19305 if (it
->descent
> it
->max_descent
)
19307 it
->ascent
+= it
->descent
- it
->max_descent
;
19308 it
->descent
= it
->max_descent
;
19310 if (it
->ascent
> it
->max_ascent
)
19312 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19313 it
->ascent
= it
->max_ascent
;
19315 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19316 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19317 it
->constrain_row_ascent_descent_p
= 1;
19318 extra_line_spacing
= 0;
19322 Lisp_Object spacing
;
19325 it
->phys_ascent
= it
->ascent
;
19326 it
->phys_descent
= it
->descent
;
19328 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19329 && face
->box
!= FACE_NO_BOX
19330 && face
->box_line_width
> 0)
19332 it
->ascent
+= face
->box_line_width
;
19333 it
->descent
+= face
->box_line_width
;
19336 && XINT (height
) > it
->ascent
+ it
->descent
)
19337 it
->ascent
= XINT (height
) - it
->descent
;
19339 if (!NILP (total_height
))
19340 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19343 spacing
= get_line_height_property(it
, Qline_spacing
);
19344 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19346 if (INTEGERP (spacing
))
19348 extra_line_spacing
= XINT (spacing
);
19349 if (!NILP (total_height
))
19350 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19354 else if (it
->char_to_display
== '\t')
19356 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19357 int x
= it
->current_x
+ it
->continuation_lines_width
;
19358 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19360 /* If the distance from the current position to the next tab
19361 stop is less than a space character width, use the
19362 tab stop after that. */
19363 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19364 next_tab_x
+= tab_width
;
19366 it
->pixel_width
= next_tab_x
- x
;
19368 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19369 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19373 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19374 it
->ascent
+ it
->descent
, it
->ascent
);
19379 /* A multi-byte character. Assume that the display width of the
19380 character is the width of the character multiplied by the
19381 width of the font. */
19383 /* If we found a font, this font should give us the right
19384 metrics. If we didn't find a font, use the frame's
19385 default font and calculate the width of the character
19386 from the charset width; this is what old redisplay code
19389 pcm
= rif
->per_char_metric (font
, &char2b
,
19390 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19392 if (font_not_found_p
|| !pcm
)
19394 int charset
= CHAR_CHARSET (it
->char_to_display
);
19396 it
->glyph_not_available_p
= 1;
19397 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19398 * CHARSET_WIDTH (charset
));
19399 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19400 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19404 it
->pixel_width
= pcm
->width
;
19405 it
->phys_ascent
= pcm
->ascent
+ boff
;
19406 it
->phys_descent
= pcm
->descent
- boff
;
19408 && (pcm
->lbearing
< 0
19409 || pcm
->rbearing
> pcm
->width
))
19410 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19413 it
->ascent
= FONT_BASE (font
) + boff
;
19414 it
->descent
= FONT_DESCENT (font
) - boff
;
19415 if (face
->box
!= FACE_NO_BOX
)
19417 int thick
= face
->box_line_width
;
19421 it
->ascent
+= thick
;
19422 it
->descent
+= thick
;
19427 if (it
->start_of_box_run_p
)
19428 it
->pixel_width
+= thick
;
19429 if (it
->end_of_box_run_p
)
19430 it
->pixel_width
+= thick
;
19433 /* If face has an overline, add the height of the overline
19434 (1 pixel) and a 1 pixel margin to the character height. */
19435 if (face
->overline_p
)
19438 take_vertical_position_into_account (it
);
19443 it
->multibyte_p
= saved_multibyte_p
;
19445 else if (it
->what
== IT_COMPOSITION
)
19447 /* Note: A composition is represented as one glyph in the
19448 glyph matrix. There are no padding glyphs. */
19451 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19453 int font_not_found_p
;
19454 struct font_info
*font_info
;
19455 int boff
; /* baseline offset */
19456 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19458 /* Maybe translate single-byte characters to multibyte. */
19459 it
->char_to_display
= it
->c
;
19460 if (unibyte_display_via_language_environment
19461 && SINGLE_BYTE_CHAR_P (it
->c
)
19464 && !NILP (Vnonascii_translation_table
))))
19466 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19469 /* Get face and font to use. Encode IT->char_to_display. */
19470 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19471 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19472 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19473 &char2b
, it
->multibyte_p
, 0);
19476 /* When no suitable font found, use the default font. */
19477 font_not_found_p
= font
== NULL
;
19478 if (font_not_found_p
)
19480 font
= FRAME_FONT (it
->f
);
19481 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19486 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19487 boff
= font_info
->baseline_offset
;
19488 if (font_info
->vertical_centering
)
19489 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19492 /* There are no padding glyphs, so there is only one glyph to
19493 produce for the composition. Important is that pixel_width,
19494 ascent and descent are the values of what is drawn by
19495 draw_glyphs (i.e. the values of the overall glyphs composed). */
19498 /* If we have not yet calculated pixel size data of glyphs of
19499 the composition for the current face font, calculate them
19500 now. Theoretically, we have to check all fonts for the
19501 glyphs, but that requires much time and memory space. So,
19502 here we check only the font of the first glyph. This leads
19503 to incorrect display very rarely, and C-l (recenter) can
19504 correct the display anyway. */
19505 if (cmp
->font
!= (void *) font
)
19507 /* Ascent and descent of the font of the first character of
19508 this composition (adjusted by baseline offset). Ascent
19509 and descent of overall glyphs should not be less than
19510 them respectively. */
19511 int font_ascent
= FONT_BASE (font
) + boff
;
19512 int font_descent
= FONT_DESCENT (font
) - boff
;
19513 /* Bounding box of the overall glyphs. */
19514 int leftmost
, rightmost
, lowest
, highest
;
19515 int i
, width
, ascent
, descent
;
19517 cmp
->font
= (void *) font
;
19519 /* Initialize the bounding box. */
19521 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19522 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19524 width
= pcm
->width
;
19525 ascent
= pcm
->ascent
;
19526 descent
= pcm
->descent
;
19530 width
= FONT_WIDTH (font
);
19531 ascent
= FONT_BASE (font
);
19532 descent
= FONT_DESCENT (font
);
19536 lowest
= - descent
+ boff
;
19537 highest
= ascent
+ boff
;
19541 && font_info
->default_ascent
19542 && CHAR_TABLE_P (Vuse_default_ascent
)
19543 && !NILP (Faref (Vuse_default_ascent
,
19544 make_number (it
->char_to_display
))))
19545 highest
= font_info
->default_ascent
+ boff
;
19547 /* Draw the first glyph at the normal position. It may be
19548 shifted to right later if some other glyphs are drawn at
19550 cmp
->offsets
[0] = 0;
19551 cmp
->offsets
[1] = boff
;
19553 /* Set cmp->offsets for the remaining glyphs. */
19554 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19556 int left
, right
, btm
, top
;
19557 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19558 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19560 face
= FACE_FROM_ID (it
->f
, face_id
);
19561 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19562 &char2b
, it
->multibyte_p
, 0);
19566 font
= FRAME_FONT (it
->f
);
19567 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19573 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19574 boff
= font_info
->baseline_offset
;
19575 if (font_info
->vertical_centering
)
19576 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19580 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19581 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19583 width
= pcm
->width
;
19584 ascent
= pcm
->ascent
;
19585 descent
= pcm
->descent
;
19589 width
= FONT_WIDTH (font
);
19594 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19596 /* Relative composition with or without
19597 alternate chars. */
19598 left
= (leftmost
+ rightmost
- width
) / 2;
19599 btm
= - descent
+ boff
;
19600 if (font_info
&& font_info
->relative_compose
19601 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19602 || NILP (Faref (Vignore_relative_composition
,
19603 make_number (ch
)))))
19606 if (- descent
>= font_info
->relative_compose
)
19607 /* One extra pixel between two glyphs. */
19609 else if (ascent
<= 0)
19610 /* One extra pixel between two glyphs. */
19611 btm
= lowest
- 1 - ascent
- descent
;
19616 /* A composition rule is specified by an integer
19617 value that encodes global and new reference
19618 points (GREF and NREF). GREF and NREF are
19619 specified by numbers as below:
19621 0---1---2 -- ascent
19625 9--10--11 -- center
19627 ---3---4---5--- baseline
19629 6---7---8 -- descent
19631 int rule
= COMPOSITION_RULE (cmp
, i
);
19632 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19634 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19635 grefx
= gref
% 3, nrefx
= nref
% 3;
19636 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19639 + grefx
* (rightmost
- leftmost
) / 2
19640 - nrefx
* width
/ 2);
19641 btm
= ((grefy
== 0 ? highest
19643 : grefy
== 2 ? lowest
19644 : (highest
+ lowest
) / 2)
19645 - (nrefy
== 0 ? ascent
+ descent
19646 : nrefy
== 1 ? descent
- boff
19648 : (ascent
+ descent
) / 2));
19651 cmp
->offsets
[i
* 2] = left
;
19652 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19654 /* Update the bounding box of the overall glyphs. */
19655 right
= left
+ width
;
19656 top
= btm
+ descent
+ ascent
;
19657 if (left
< leftmost
)
19659 if (right
> rightmost
)
19667 /* If there are glyphs whose x-offsets are negative,
19668 shift all glyphs to the right and make all x-offsets
19672 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19673 cmp
->offsets
[i
* 2] -= leftmost
;
19674 rightmost
-= leftmost
;
19677 cmp
->pixel_width
= rightmost
;
19678 cmp
->ascent
= highest
;
19679 cmp
->descent
= - lowest
;
19680 if (cmp
->ascent
< font_ascent
)
19681 cmp
->ascent
= font_ascent
;
19682 if (cmp
->descent
< font_descent
)
19683 cmp
->descent
= font_descent
;
19686 it
->pixel_width
= cmp
->pixel_width
;
19687 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19688 it
->descent
= it
->phys_descent
= cmp
->descent
;
19690 if (face
->box
!= FACE_NO_BOX
)
19692 int thick
= face
->box_line_width
;
19696 it
->ascent
+= thick
;
19697 it
->descent
+= thick
;
19702 if (it
->start_of_box_run_p
)
19703 it
->pixel_width
+= thick
;
19704 if (it
->end_of_box_run_p
)
19705 it
->pixel_width
+= thick
;
19708 /* If face has an overline, add the height of the overline
19709 (1 pixel) and a 1 pixel margin to the character height. */
19710 if (face
->overline_p
)
19713 take_vertical_position_into_account (it
);
19716 append_composite_glyph (it
);
19718 else if (it
->what
== IT_IMAGE
)
19719 produce_image_glyph (it
);
19720 else if (it
->what
== IT_STRETCH
)
19721 produce_stretch_glyph (it
);
19723 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19724 because this isn't true for images with `:ascent 100'. */
19725 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19726 if (it
->area
== TEXT_AREA
)
19727 it
->current_x
+= it
->pixel_width
;
19729 if (extra_line_spacing
> 0)
19731 it
->descent
+= extra_line_spacing
;
19732 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19733 it
->max_extra_line_spacing
= extra_line_spacing
;
19736 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19737 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19738 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19739 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19743 Output LEN glyphs starting at START at the nominal cursor position.
19744 Advance the nominal cursor over the text. The global variable
19745 updated_window contains the window being updated, updated_row is
19746 the glyph row being updated, and updated_area is the area of that
19747 row being updated. */
19750 x_write_glyphs (start
, len
)
19751 struct glyph
*start
;
19756 xassert (updated_window
&& updated_row
);
19759 /* Write glyphs. */
19761 hpos
= start
- updated_row
->glyphs
[updated_area
];
19762 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19763 updated_row
, updated_area
,
19765 DRAW_NORMAL_TEXT
, 0);
19767 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19768 if (updated_area
== TEXT_AREA
19769 && updated_window
->phys_cursor_on_p
19770 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19771 && updated_window
->phys_cursor
.hpos
>= hpos
19772 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19773 updated_window
->phys_cursor_on_p
= 0;
19777 /* Advance the output cursor. */
19778 output_cursor
.hpos
+= len
;
19779 output_cursor
.x
= x
;
19784 Insert LEN glyphs from START at the nominal cursor position. */
19787 x_insert_glyphs (start
, len
)
19788 struct glyph
*start
;
19793 int line_height
, shift_by_width
, shifted_region_width
;
19794 struct glyph_row
*row
;
19795 struct glyph
*glyph
;
19796 int frame_x
, frame_y
, hpos
;
19798 xassert (updated_window
&& updated_row
);
19800 w
= updated_window
;
19801 f
= XFRAME (WINDOW_FRAME (w
));
19803 /* Get the height of the line we are in. */
19805 line_height
= row
->height
;
19807 /* Get the width of the glyphs to insert. */
19808 shift_by_width
= 0;
19809 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19810 shift_by_width
+= glyph
->pixel_width
;
19812 /* Get the width of the region to shift right. */
19813 shifted_region_width
= (window_box_width (w
, updated_area
)
19818 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19819 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19821 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19822 line_height
, shift_by_width
);
19824 /* Write the glyphs. */
19825 hpos
= start
- row
->glyphs
[updated_area
];
19826 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19828 DRAW_NORMAL_TEXT
, 0);
19830 /* Advance the output cursor. */
19831 output_cursor
.hpos
+= len
;
19832 output_cursor
.x
+= shift_by_width
;
19838 Erase the current text line from the nominal cursor position
19839 (inclusive) to pixel column TO_X (exclusive). The idea is that
19840 everything from TO_X onward is already erased.
19842 TO_X is a pixel position relative to updated_area of
19843 updated_window. TO_X == -1 means clear to the end of this area. */
19846 x_clear_end_of_line (to_x
)
19850 struct window
*w
= updated_window
;
19851 int max_x
, min_y
, max_y
;
19852 int from_x
, from_y
, to_y
;
19854 xassert (updated_window
&& updated_row
);
19855 f
= XFRAME (w
->frame
);
19857 if (updated_row
->full_width_p
)
19858 max_x
= WINDOW_TOTAL_WIDTH (w
);
19860 max_x
= window_box_width (w
, updated_area
);
19861 max_y
= window_text_bottom_y (w
);
19863 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19864 of window. For TO_X > 0, truncate to end of drawing area. */
19870 to_x
= min (to_x
, max_x
);
19872 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19874 /* Notice if the cursor will be cleared by this operation. */
19875 if (!updated_row
->full_width_p
)
19876 notice_overwritten_cursor (w
, updated_area
,
19877 output_cursor
.x
, -1,
19879 MATRIX_ROW_BOTTOM_Y (updated_row
));
19881 from_x
= output_cursor
.x
;
19883 /* Translate to frame coordinates. */
19884 if (updated_row
->full_width_p
)
19886 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19887 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19891 int area_left
= window_box_left (w
, updated_area
);
19892 from_x
+= area_left
;
19896 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19897 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19898 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19900 /* Prevent inadvertently clearing to end of the X window. */
19901 if (to_x
> from_x
&& to_y
> from_y
)
19904 rif
->clear_frame_area (f
, from_x
, from_y
,
19905 to_x
- from_x
, to_y
- from_y
);
19910 #endif /* HAVE_WINDOW_SYSTEM */
19914 /***********************************************************************
19916 ***********************************************************************/
19918 /* Value is the internal representation of the specified cursor type
19919 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19920 of the bar cursor. */
19922 static enum text_cursor_kinds
19923 get_specified_cursor_type (arg
, width
)
19927 enum text_cursor_kinds type
;
19932 if (EQ (arg
, Qbox
))
19933 return FILLED_BOX_CURSOR
;
19935 if (EQ (arg
, Qhollow
))
19936 return HOLLOW_BOX_CURSOR
;
19938 if (EQ (arg
, Qbar
))
19945 && EQ (XCAR (arg
), Qbar
)
19946 && INTEGERP (XCDR (arg
))
19947 && XINT (XCDR (arg
)) >= 0)
19949 *width
= XINT (XCDR (arg
));
19953 if (EQ (arg
, Qhbar
))
19956 return HBAR_CURSOR
;
19960 && EQ (XCAR (arg
), Qhbar
)
19961 && INTEGERP (XCDR (arg
))
19962 && XINT (XCDR (arg
)) >= 0)
19964 *width
= XINT (XCDR (arg
));
19965 return HBAR_CURSOR
;
19968 /* Treat anything unknown as "hollow box cursor".
19969 It was bad to signal an error; people have trouble fixing
19970 .Xdefaults with Emacs, when it has something bad in it. */
19971 type
= HOLLOW_BOX_CURSOR
;
19976 /* Set the default cursor types for specified frame. */
19978 set_frame_cursor_types (f
, arg
)
19985 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19986 FRAME_CURSOR_WIDTH (f
) = width
;
19988 /* By default, set up the blink-off state depending on the on-state. */
19990 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19993 FRAME_BLINK_OFF_CURSOR (f
)
19994 = get_specified_cursor_type (XCDR (tem
), &width
);
19995 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19998 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20002 /* Return the cursor we want to be displayed in window W. Return
20003 width of bar/hbar cursor through WIDTH arg. Return with
20004 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20005 (i.e. if the `system caret' should track this cursor).
20007 In a mini-buffer window, we want the cursor only to appear if we
20008 are reading input from this window. For the selected window, we
20009 want the cursor type given by the frame parameter or buffer local
20010 setting of cursor-type. If explicitly marked off, draw no cursor.
20011 In all other cases, we want a hollow box cursor. */
20013 static enum text_cursor_kinds
20014 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20016 struct glyph
*glyph
;
20018 int *active_cursor
;
20020 struct frame
*f
= XFRAME (w
->frame
);
20021 struct buffer
*b
= XBUFFER (w
->buffer
);
20022 int cursor_type
= DEFAULT_CURSOR
;
20023 Lisp_Object alt_cursor
;
20024 int non_selected
= 0;
20026 *active_cursor
= 1;
20029 if (cursor_in_echo_area
20030 && FRAME_HAS_MINIBUF_P (f
)
20031 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20033 if (w
== XWINDOW (echo_area_window
))
20035 *width
= FRAME_CURSOR_WIDTH (f
);
20036 return FRAME_DESIRED_CURSOR (f
);
20039 *active_cursor
= 0;
20043 /* Nonselected window or nonselected frame. */
20044 else if (w
!= XWINDOW (f
->selected_window
)
20045 #ifdef HAVE_WINDOW_SYSTEM
20046 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20050 *active_cursor
= 0;
20052 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20058 /* Never display a cursor in a window in which cursor-type is nil. */
20059 if (NILP (b
->cursor_type
))
20062 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20065 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
20066 return get_specified_cursor_type (alt_cursor
, width
);
20069 /* Get the normal cursor type for this window. */
20070 if (EQ (b
->cursor_type
, Qt
))
20072 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20073 *width
= FRAME_CURSOR_WIDTH (f
);
20076 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20078 /* Use normal cursor if not blinked off. */
20079 if (!w
->cursor_off_p
)
20081 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20082 if (cursor_type
== FILLED_BOX_CURSOR
)
20083 cursor_type
= HOLLOW_BOX_CURSOR
;
20085 return cursor_type
;
20088 /* Cursor is blinked off, so determine how to "toggle" it. */
20090 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20091 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20092 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20094 /* Then see if frame has specified a specific blink off cursor type. */
20095 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20097 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20098 return FRAME_BLINK_OFF_CURSOR (f
);
20102 /* Some people liked having a permanently visible blinking cursor,
20103 while others had very strong opinions against it. So it was
20104 decided to remove it. KFS 2003-09-03 */
20106 /* Finally perform built-in cursor blinking:
20107 filled box <-> hollow box
20108 wide [h]bar <-> narrow [h]bar
20109 narrow [h]bar <-> no cursor
20110 other type <-> no cursor */
20112 if (cursor_type
== FILLED_BOX_CURSOR
)
20113 return HOLLOW_BOX_CURSOR
;
20115 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20118 return cursor_type
;
20126 #ifdef HAVE_WINDOW_SYSTEM
20128 /* Notice when the text cursor of window W has been completely
20129 overwritten by a drawing operation that outputs glyphs in AREA
20130 starting at X0 and ending at X1 in the line starting at Y0 and
20131 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20132 the rest of the line after X0 has been written. Y coordinates
20133 are window-relative. */
20136 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20138 enum glyph_row_area area
;
20139 int x0
, y0
, x1
, y1
;
20141 int cx0
, cx1
, cy0
, cy1
;
20142 struct glyph_row
*row
;
20144 if (!w
->phys_cursor_on_p
)
20146 if (area
!= TEXT_AREA
)
20149 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
20150 if (!row
->displays_text_p
)
20153 if (row
->cursor_in_fringe_p
)
20155 row
->cursor_in_fringe_p
= 0;
20156 draw_fringe_bitmap (w
, row
, 0);
20157 w
->phys_cursor_on_p
= 0;
20161 cx0
= w
->phys_cursor
.x
;
20162 cx1
= cx0
+ w
->phys_cursor_width
;
20163 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20166 /* The cursor image will be completely removed from the
20167 screen if the output area intersects the cursor area in
20168 y-direction. When we draw in [y0 y1[, and some part of
20169 the cursor is at y < y0, that part must have been drawn
20170 before. When scrolling, the cursor is erased before
20171 actually scrolling, so we don't come here. When not
20172 scrolling, the rows above the old cursor row must have
20173 changed, and in this case these rows must have written
20174 over the cursor image.
20176 Likewise if part of the cursor is below y1, with the
20177 exception of the cursor being in the first blank row at
20178 the buffer and window end because update_text_area
20179 doesn't draw that row. (Except when it does, but
20180 that's handled in update_text_area.) */
20182 cy0
= w
->phys_cursor
.y
;
20183 cy1
= cy0
+ w
->phys_cursor_height
;
20184 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20187 w
->phys_cursor_on_p
= 0;
20190 #endif /* HAVE_WINDOW_SYSTEM */
20193 /************************************************************************
20195 ************************************************************************/
20197 #ifdef HAVE_WINDOW_SYSTEM
20200 Fix the display of area AREA of overlapping row ROW in window W. */
20203 x_fix_overlapping_area (w
, row
, area
)
20205 struct glyph_row
*row
;
20206 enum glyph_row_area area
;
20213 for (i
= 0; i
< row
->used
[area
];)
20215 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20217 int start
= i
, start_x
= x
;
20221 x
+= row
->glyphs
[area
][i
].pixel_width
;
20224 while (i
< row
->used
[area
]
20225 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20227 draw_glyphs (w
, start_x
, row
, area
,
20229 DRAW_NORMAL_TEXT
, 1);
20233 x
+= row
->glyphs
[area
][i
].pixel_width
;
20243 Draw the cursor glyph of window W in glyph row ROW. See the
20244 comment of draw_glyphs for the meaning of HL. */
20247 draw_phys_cursor_glyph (w
, row
, hl
)
20249 struct glyph_row
*row
;
20250 enum draw_glyphs_face hl
;
20252 /* If cursor hpos is out of bounds, don't draw garbage. This can
20253 happen in mini-buffer windows when switching between echo area
20254 glyphs and mini-buffer. */
20255 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20257 int on_p
= w
->phys_cursor_on_p
;
20259 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20260 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20262 w
->phys_cursor_on_p
= on_p
;
20264 if (hl
== DRAW_CURSOR
)
20265 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20266 /* When we erase the cursor, and ROW is overlapped by other
20267 rows, make sure that these overlapping parts of other rows
20269 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20271 if (row
> w
->current_matrix
->rows
20272 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20273 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20275 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20276 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20277 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20284 Erase the image of a cursor of window W from the screen. */
20287 erase_phys_cursor (w
)
20290 struct frame
*f
= XFRAME (w
->frame
);
20291 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20292 int hpos
= w
->phys_cursor
.hpos
;
20293 int vpos
= w
->phys_cursor
.vpos
;
20294 int mouse_face_here_p
= 0;
20295 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20296 struct glyph_row
*cursor_row
;
20297 struct glyph
*cursor_glyph
;
20298 enum draw_glyphs_face hl
;
20300 /* No cursor displayed or row invalidated => nothing to do on the
20302 if (w
->phys_cursor_type
== NO_CURSOR
)
20303 goto mark_cursor_off
;
20305 /* VPOS >= active_glyphs->nrows means that window has been resized.
20306 Don't bother to erase the cursor. */
20307 if (vpos
>= active_glyphs
->nrows
)
20308 goto mark_cursor_off
;
20310 /* If row containing cursor is marked invalid, there is nothing we
20312 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20313 if (!cursor_row
->enabled_p
)
20314 goto mark_cursor_off
;
20316 /* If line spacing is > 0, old cursor may only be partially visible in
20317 window after split-window. So adjust visible height. */
20318 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20319 window_text_bottom_y (w
) - cursor_row
->y
);
20321 /* If row is completely invisible, don't attempt to delete a cursor which
20322 isn't there. This can happen if cursor is at top of a window, and
20323 we switch to a buffer with a header line in that window. */
20324 if (cursor_row
->visible_height
<= 0)
20325 goto mark_cursor_off
;
20327 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20328 if (cursor_row
->cursor_in_fringe_p
)
20330 cursor_row
->cursor_in_fringe_p
= 0;
20331 draw_fringe_bitmap (w
, cursor_row
, 0);
20332 goto mark_cursor_off
;
20335 /* This can happen when the new row is shorter than the old one.
20336 In this case, either draw_glyphs or clear_end_of_line
20337 should have cleared the cursor. Note that we wouldn't be
20338 able to erase the cursor in this case because we don't have a
20339 cursor glyph at hand. */
20340 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20341 goto mark_cursor_off
;
20343 /* If the cursor is in the mouse face area, redisplay that when
20344 we clear the cursor. */
20345 if (! NILP (dpyinfo
->mouse_face_window
)
20346 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20347 && (vpos
> dpyinfo
->mouse_face_beg_row
20348 || (vpos
== dpyinfo
->mouse_face_beg_row
20349 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20350 && (vpos
< dpyinfo
->mouse_face_end_row
20351 || (vpos
== dpyinfo
->mouse_face_end_row
20352 && hpos
< dpyinfo
->mouse_face_end_col
))
20353 /* Don't redraw the cursor's spot in mouse face if it is at the
20354 end of a line (on a newline). The cursor appears there, but
20355 mouse highlighting does not. */
20356 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20357 mouse_face_here_p
= 1;
20359 /* Maybe clear the display under the cursor. */
20360 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20363 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20366 cursor_glyph
= get_phys_cursor_glyph (w
);
20367 if (cursor_glyph
== NULL
)
20368 goto mark_cursor_off
;
20370 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20371 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20372 width
= min (cursor_glyph
->pixel_width
,
20373 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20375 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20378 /* Erase the cursor by redrawing the character underneath it. */
20379 if (mouse_face_here_p
)
20380 hl
= DRAW_MOUSE_FACE
;
20382 hl
= DRAW_NORMAL_TEXT
;
20383 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20386 w
->phys_cursor_on_p
= 0;
20387 w
->phys_cursor_type
= NO_CURSOR
;
20392 Display or clear cursor of window W. If ON is zero, clear the
20393 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20394 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20397 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20399 int on
, hpos
, vpos
, x
, y
;
20401 struct frame
*f
= XFRAME (w
->frame
);
20402 int new_cursor_type
;
20403 int new_cursor_width
;
20405 struct glyph_row
*glyph_row
;
20406 struct glyph
*glyph
;
20408 /* This is pointless on invisible frames, and dangerous on garbaged
20409 windows and frames; in the latter case, the frame or window may
20410 be in the midst of changing its size, and x and y may be off the
20412 if (! FRAME_VISIBLE_P (f
)
20413 || FRAME_GARBAGED_P (f
)
20414 || vpos
>= w
->current_matrix
->nrows
20415 || hpos
>= w
->current_matrix
->matrix_w
)
20418 /* If cursor is off and we want it off, return quickly. */
20419 if (!on
&& !w
->phys_cursor_on_p
)
20422 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20423 /* If cursor row is not enabled, we don't really know where to
20424 display the cursor. */
20425 if (!glyph_row
->enabled_p
)
20427 w
->phys_cursor_on_p
= 0;
20432 if (!glyph_row
->exact_window_width_line_p
20433 || hpos
< glyph_row
->used
[TEXT_AREA
])
20434 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20436 xassert (interrupt_input_blocked
);
20438 /* Set new_cursor_type to the cursor we want to be displayed. */
20439 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20440 &new_cursor_width
, &active_cursor
);
20442 /* If cursor is currently being shown and we don't want it to be or
20443 it is in the wrong place, or the cursor type is not what we want,
20445 if (w
->phys_cursor_on_p
20447 || w
->phys_cursor
.x
!= x
20448 || w
->phys_cursor
.y
!= y
20449 || new_cursor_type
!= w
->phys_cursor_type
20450 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20451 && new_cursor_width
!= w
->phys_cursor_width
)))
20452 erase_phys_cursor (w
);
20454 /* Don't check phys_cursor_on_p here because that flag is only set
20455 to zero in some cases where we know that the cursor has been
20456 completely erased, to avoid the extra work of erasing the cursor
20457 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20458 still not be visible, or it has only been partly erased. */
20461 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20462 w
->phys_cursor_height
= glyph_row
->height
;
20464 /* Set phys_cursor_.* before x_draw_.* is called because some
20465 of them may need the information. */
20466 w
->phys_cursor
.x
= x
;
20467 w
->phys_cursor
.y
= glyph_row
->y
;
20468 w
->phys_cursor
.hpos
= hpos
;
20469 w
->phys_cursor
.vpos
= vpos
;
20472 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20473 new_cursor_type
, new_cursor_width
,
20474 on
, active_cursor
);
20478 /* Switch the display of W's cursor on or off, according to the value
20482 update_window_cursor (w
, on
)
20486 /* Don't update cursor in windows whose frame is in the process
20487 of being deleted. */
20488 if (w
->current_matrix
)
20491 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20492 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20498 /* Call update_window_cursor with parameter ON_P on all leaf windows
20499 in the window tree rooted at W. */
20502 update_cursor_in_window_tree (w
, on_p
)
20508 if (!NILP (w
->hchild
))
20509 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20510 else if (!NILP (w
->vchild
))
20511 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20513 update_window_cursor (w
, on_p
);
20515 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20521 Display the cursor on window W, or clear it, according to ON_P.
20522 Don't change the cursor's position. */
20525 x_update_cursor (f
, on_p
)
20529 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20534 Clear the cursor of window W to background color, and mark the
20535 cursor as not shown. This is used when the text where the cursor
20536 is is about to be rewritten. */
20542 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20543 update_window_cursor (w
, 0);
20548 Display the active region described by mouse_face_* according to DRAW. */
20551 show_mouse_face (dpyinfo
, draw
)
20552 Display_Info
*dpyinfo
;
20553 enum draw_glyphs_face draw
;
20555 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20556 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20558 if (/* If window is in the process of being destroyed, don't bother
20560 w
->current_matrix
!= NULL
20561 /* Don't update mouse highlight if hidden */
20562 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20563 /* Recognize when we are called to operate on rows that don't exist
20564 anymore. This can happen when a window is split. */
20565 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20567 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20568 struct glyph_row
*row
, *first
, *last
;
20570 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20571 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20573 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20575 int start_hpos
, end_hpos
, start_x
;
20577 /* For all but the first row, the highlight starts at column 0. */
20580 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20581 start_x
= dpyinfo
->mouse_face_beg_x
;
20590 end_hpos
= dpyinfo
->mouse_face_end_col
;
20592 end_hpos
= row
->used
[TEXT_AREA
];
20594 if (end_hpos
> start_hpos
)
20596 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20597 start_hpos
, end_hpos
,
20601 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20605 /* When we've written over the cursor, arrange for it to
20606 be displayed again. */
20607 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20610 display_and_set_cursor (w
, 1,
20611 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20612 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20617 /* Change the mouse cursor. */
20618 if (draw
== DRAW_NORMAL_TEXT
)
20619 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20620 else if (draw
== DRAW_MOUSE_FACE
)
20621 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20623 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20627 Clear out the mouse-highlighted active region.
20628 Redraw it un-highlighted first. Value is non-zero if mouse
20629 face was actually drawn unhighlighted. */
20632 clear_mouse_face (dpyinfo
)
20633 Display_Info
*dpyinfo
;
20637 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20639 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20643 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20644 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20645 dpyinfo
->mouse_face_window
= Qnil
;
20646 dpyinfo
->mouse_face_overlay
= Qnil
;
20652 Non-zero if physical cursor of window W is within mouse face. */
20655 cursor_in_mouse_face_p (w
)
20658 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20659 int in_mouse_face
= 0;
20661 if (WINDOWP (dpyinfo
->mouse_face_window
)
20662 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20664 int hpos
= w
->phys_cursor
.hpos
;
20665 int vpos
= w
->phys_cursor
.vpos
;
20667 if (vpos
>= dpyinfo
->mouse_face_beg_row
20668 && vpos
<= dpyinfo
->mouse_face_end_row
20669 && (vpos
> dpyinfo
->mouse_face_beg_row
20670 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20671 && (vpos
< dpyinfo
->mouse_face_end_row
20672 || hpos
< dpyinfo
->mouse_face_end_col
20673 || dpyinfo
->mouse_face_past_end
))
20677 return in_mouse_face
;
20683 /* Find the glyph matrix position of buffer position CHARPOS in window
20684 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20685 current glyphs must be up to date. If CHARPOS is above window
20686 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20687 of last line in W. In the row containing CHARPOS, stop before glyphs
20688 having STOP as object. */
20690 #if 1 /* This is a version of fast_find_position that's more correct
20691 in the presence of hscrolling, for example. I didn't install
20692 it right away because the problem fixed is minor, it failed
20693 in 20.x as well, and I think it's too risky to install
20694 so near the release of 21.1. 2001-09-25 gerd. */
20697 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20700 int *hpos
, *vpos
, *x
, *y
;
20703 struct glyph_row
*row
, *first
;
20704 struct glyph
*glyph
, *end
;
20707 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20708 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20713 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20717 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20720 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20724 /* If whole rows or last part of a row came from a display overlay,
20725 row_containing_pos will skip over such rows because their end pos
20726 equals the start pos of the overlay or interval. Backtrack if we
20727 have a STOP object and previous row's end glyph came from STOP. */
20730 struct glyph_row
*prev
= row
-1;
20731 while ((prev
= row
- 1, prev
>= first
)
20732 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
20733 && prev
->used
[TEXT_AREA
] > 0)
20735 end
= prev
->glyphs
[TEXT_AREA
];
20736 glyph
= end
+ prev
->used
[TEXT_AREA
];
20737 while (--glyph
>= end
20738 && INTEGERP (glyph
->object
));
20740 && !EQ (stop
, glyph
->object
))
20748 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20750 glyph
= row
->glyphs
[TEXT_AREA
];
20751 end
= glyph
+ row
->used
[TEXT_AREA
];
20753 /* Skip over glyphs not having an object at the start of the row.
20754 These are special glyphs like truncation marks on terminal
20756 if (row
->displays_text_p
)
20758 && INTEGERP (glyph
->object
)
20759 && !EQ (stop
, glyph
->object
)
20760 && glyph
->charpos
< 0)
20762 *x
+= glyph
->pixel_width
;
20767 && !INTEGERP (glyph
->object
)
20768 && !EQ (stop
, glyph
->object
)
20769 && (!BUFFERP (glyph
->object
)
20770 || glyph
->charpos
< charpos
))
20772 *x
+= glyph
->pixel_width
;
20776 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20783 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20786 int *hpos
, *vpos
, *x
, *y
;
20791 int maybe_next_line_p
= 0;
20792 int line_start_position
;
20793 int yb
= window_text_bottom_y (w
);
20794 struct glyph_row
*row
, *best_row
;
20795 int row_vpos
, best_row_vpos
;
20798 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20799 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20801 while (row
->y
< yb
)
20803 if (row
->used
[TEXT_AREA
])
20804 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20806 line_start_position
= 0;
20808 if (line_start_position
> pos
)
20810 /* If the position sought is the end of the buffer,
20811 don't include the blank lines at the bottom of the window. */
20812 else if (line_start_position
== pos
20813 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20815 maybe_next_line_p
= 1;
20818 else if (line_start_position
> 0)
20821 best_row_vpos
= row_vpos
;
20824 if (row
->y
+ row
->height
>= yb
)
20831 /* Find the right column within BEST_ROW. */
20833 current_x
= best_row
->x
;
20834 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20836 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20837 int charpos
= glyph
->charpos
;
20839 if (BUFFERP (glyph
->object
))
20841 if (charpos
== pos
)
20844 *vpos
= best_row_vpos
;
20849 else if (charpos
> pos
)
20852 else if (EQ (glyph
->object
, stop
))
20857 current_x
+= glyph
->pixel_width
;
20860 /* If we're looking for the end of the buffer,
20861 and we didn't find it in the line we scanned,
20862 use the start of the following line. */
20863 if (maybe_next_line_p
)
20868 current_x
= best_row
->x
;
20871 *vpos
= best_row_vpos
;
20872 *hpos
= lastcol
+ 1;
20881 /* Find the position of the glyph for position POS in OBJECT in
20882 window W's current matrix, and return in *X, *Y the pixel
20883 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20885 RIGHT_P non-zero means return the position of the right edge of the
20886 glyph, RIGHT_P zero means return the left edge position.
20888 If no glyph for POS exists in the matrix, return the position of
20889 the glyph with the next smaller position that is in the matrix, if
20890 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20891 exists in the matrix, return the position of the glyph with the
20892 next larger position in OBJECT.
20894 Value is non-zero if a glyph was found. */
20897 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20900 Lisp_Object object
;
20901 int *hpos
, *vpos
, *x
, *y
;
20904 int yb
= window_text_bottom_y (w
);
20905 struct glyph_row
*r
;
20906 struct glyph
*best_glyph
= NULL
;
20907 struct glyph_row
*best_row
= NULL
;
20910 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20911 r
->enabled_p
&& r
->y
< yb
;
20914 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20915 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20918 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20919 if (EQ (g
->object
, object
))
20921 if (g
->charpos
== pos
)
20928 else if (best_glyph
== NULL
20929 || ((abs (g
->charpos
- pos
)
20930 < abs (best_glyph
->charpos
- pos
))
20933 : g
->charpos
> pos
)))
20947 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20951 *x
+= best_glyph
->pixel_width
;
20956 *vpos
= best_row
- w
->current_matrix
->rows
;
20959 return best_glyph
!= NULL
;
20963 /* See if position X, Y is within a hot-spot of an image. */
20966 on_hot_spot_p (hot_spot
, x
, y
)
20967 Lisp_Object hot_spot
;
20970 if (!CONSP (hot_spot
))
20973 if (EQ (XCAR (hot_spot
), Qrect
))
20975 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20976 Lisp_Object rect
= XCDR (hot_spot
);
20980 if (!CONSP (XCAR (rect
)))
20982 if (!CONSP (XCDR (rect
)))
20984 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20986 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20988 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20990 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20994 else if (EQ (XCAR (hot_spot
), Qcircle
))
20996 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20997 Lisp_Object circ
= XCDR (hot_spot
);
20998 Lisp_Object lr
, lx0
, ly0
;
21000 && CONSP (XCAR (circ
))
21001 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21002 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21003 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21005 double r
= XFLOATINT (lr
);
21006 double dx
= XINT (lx0
) - x
;
21007 double dy
= XINT (ly0
) - y
;
21008 return (dx
* dx
+ dy
* dy
<= r
* r
);
21011 else if (EQ (XCAR (hot_spot
), Qpoly
))
21013 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21014 if (VECTORP (XCDR (hot_spot
)))
21016 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21017 Lisp_Object
*poly
= v
->contents
;
21021 Lisp_Object lx
, ly
;
21024 /* Need an even number of coordinates, and at least 3 edges. */
21025 if (n
< 6 || n
& 1)
21028 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21029 If count is odd, we are inside polygon. Pixels on edges
21030 may or may not be included depending on actual geometry of the
21032 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21033 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21035 x0
= XINT (lx
), y0
= XINT (ly
);
21036 for (i
= 0; i
< n
; i
+= 2)
21038 int x1
= x0
, y1
= y0
;
21039 if ((lx
= poly
[i
], !INTEGERP (lx
))
21040 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21042 x0
= XINT (lx
), y0
= XINT (ly
);
21044 /* Does this segment cross the X line? */
21052 if (y
> y0
&& y
> y1
)
21054 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21060 /* If we don't understand the format, pretend we're not in the hot-spot. */
21065 find_hot_spot (map
, x
, y
)
21069 while (CONSP (map
))
21071 if (CONSP (XCAR (map
))
21072 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21080 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21082 doc
: /* Lookup in image map MAP coordinates X and Y.
21083 An image map is an alist where each element has the format (AREA ID PLIST).
21084 An AREA is specified as either a rectangle, a circle, or a polygon:
21085 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21086 pixel coordinates of the upper left and bottom right corners.
21087 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21088 and the radius of the circle; r may be a float or integer.
21089 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21090 vector describes one corner in the polygon.
21091 Returns the alist element for the first matching AREA in MAP. */)
21102 return find_hot_spot (map
, XINT (x
), XINT (y
));
21106 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21108 define_frame_cursor1 (f
, cursor
, pointer
)
21111 Lisp_Object pointer
;
21113 /* Do not change cursor shape while dragging mouse. */
21114 if (!NILP (do_mouse_tracking
))
21117 if (!NILP (pointer
))
21119 if (EQ (pointer
, Qarrow
))
21120 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21121 else if (EQ (pointer
, Qhand
))
21122 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21123 else if (EQ (pointer
, Qtext
))
21124 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21125 else if (EQ (pointer
, intern ("hdrag")))
21126 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21127 #ifdef HAVE_X_WINDOWS
21128 else if (EQ (pointer
, intern ("vdrag")))
21129 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21131 else if (EQ (pointer
, intern ("hourglass")))
21132 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21133 else if (EQ (pointer
, Qmodeline
))
21134 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21136 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21139 if (cursor
!= No_Cursor
)
21140 rif
->define_frame_cursor (f
, cursor
);
21143 /* Take proper action when mouse has moved to the mode or header line
21144 or marginal area AREA of window W, x-position X and y-position Y.
21145 X is relative to the start of the text display area of W, so the
21146 width of bitmap areas and scroll bars must be subtracted to get a
21147 position relative to the start of the mode line. */
21150 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
21153 enum window_part area
;
21155 struct frame
*f
= XFRAME (w
->frame
);
21156 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21157 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21158 Lisp_Object pointer
= Qnil
;
21159 int charpos
, dx
, dy
, width
, height
;
21160 Lisp_Object string
, object
= Qnil
;
21161 Lisp_Object pos
, help
;
21163 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21164 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21165 &object
, &dx
, &dy
, &width
, &height
);
21168 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21169 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21170 &object
, &dx
, &dy
, &width
, &height
);
21175 if (IMAGEP (object
))
21177 Lisp_Object image_map
, hotspot
;
21178 if ((image_map
= Fsafe_plist_get (XCDR (object
), QCmap
),
21180 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21182 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21184 Lisp_Object area_id
, plist
;
21186 area_id
= XCAR (hotspot
);
21187 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21188 If so, we could look for mouse-enter, mouse-leave
21189 properties in PLIST (and do something...). */
21190 hotspot
= XCDR (hotspot
);
21191 if (CONSP (hotspot
)
21192 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21194 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21195 if (NILP (pointer
))
21197 help
= Fsafe_plist_get (plist
, Qhelp_echo
);
21200 help_echo_string
= help
;
21201 /* Is this correct? ++kfs */
21202 XSETWINDOW (help_echo_window
, w
);
21203 help_echo_object
= w
->buffer
;
21204 help_echo_pos
= charpos
;
21208 if (NILP (pointer
))
21209 pointer
= Fsafe_plist_get (XCDR (object
), QCpointer
);
21212 if (STRINGP (string
))
21214 pos
= make_number (charpos
);
21215 /* If we're on a string with `help-echo' text property, arrange
21216 for the help to be displayed. This is done by setting the
21217 global variable help_echo_string to the help string. */
21220 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21223 help_echo_string
= help
;
21224 XSETWINDOW (help_echo_window
, w
);
21225 help_echo_object
= string
;
21226 help_echo_pos
= charpos
;
21230 if (NILP (pointer
))
21231 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21233 /* Change the mouse pointer according to what is under X/Y. */
21234 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21237 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21238 if (!KEYMAPP (map
))
21239 map
= Fget_text_property (pos
, Qkeymap
, string
);
21240 if (!KEYMAPP (map
))
21241 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21245 define_frame_cursor1 (f
, cursor
, pointer
);
21250 Take proper action when the mouse has moved to position X, Y on
21251 frame F as regards highlighting characters that have mouse-face
21252 properties. Also de-highlighting chars where the mouse was before.
21253 X and Y can be negative or out of range. */
21256 note_mouse_highlight (f
, x
, y
)
21260 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21261 enum window_part part
;
21262 Lisp_Object window
;
21264 Cursor cursor
= No_Cursor
;
21265 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21268 /* When a menu is active, don't highlight because this looks odd. */
21269 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21270 if (popup_activated ())
21274 if (NILP (Vmouse_highlight
)
21275 || !f
->glyphs_initialized_p
)
21278 dpyinfo
->mouse_face_mouse_x
= x
;
21279 dpyinfo
->mouse_face_mouse_y
= y
;
21280 dpyinfo
->mouse_face_mouse_frame
= f
;
21282 if (dpyinfo
->mouse_face_defer
)
21285 if (gc_in_progress
)
21287 dpyinfo
->mouse_face_deferred_gc
= 1;
21291 /* Which window is that in? */
21292 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21294 /* If we were displaying active text in another window, clear that.
21295 Also clear if we move out of text area in same window. */
21296 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21297 || (part
!= ON_TEXT
&& !NILP (dpyinfo
->mouse_face_window
)))
21298 clear_mouse_face (dpyinfo
);
21300 /* Not on a window -> return. */
21301 if (!WINDOWP (window
))
21304 /* Reset help_echo_string. It will get recomputed below. */
21305 help_echo_string
= Qnil
;
21307 /* Convert to window-relative pixel coordinates. */
21308 w
= XWINDOW (window
);
21309 frame_to_window_pixel_xy (w
, &x
, &y
);
21311 /* Handle tool-bar window differently since it doesn't display a
21313 if (EQ (window
, f
->tool_bar_window
))
21315 note_tool_bar_highlight (f
, x
, y
);
21319 /* Mouse is on the mode, header line or margin? */
21320 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21321 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21323 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
21327 if (part
== ON_VERTICAL_BORDER
)
21328 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21329 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21330 || part
== ON_SCROLL_BAR
)
21331 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21333 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21335 /* Are we in a window whose display is up to date?
21336 And verify the buffer's text has not changed. */
21337 b
= XBUFFER (w
->buffer
);
21338 if (part
== ON_TEXT
21339 && EQ (w
->window_end_valid
, w
->buffer
)
21340 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21341 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21343 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21344 struct glyph
*glyph
;
21345 Lisp_Object object
;
21346 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21347 Lisp_Object
*overlay_vec
= NULL
;
21349 struct buffer
*obuf
;
21350 int obegv
, ozv
, same_region
;
21352 /* Find the glyph under X/Y. */
21353 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21355 /* Look for :pointer property on image. */
21356 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21358 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21359 if (img
!= NULL
&& IMAGEP (img
->spec
))
21361 Lisp_Object image_map
, hotspot
;
21362 if ((image_map
= Fsafe_plist_get (XCDR (img
->spec
), QCmap
),
21364 && (hotspot
= find_hot_spot (image_map
,
21365 glyph
->slice
.x
+ dx
,
21366 glyph
->slice
.y
+ dy
),
21368 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21370 Lisp_Object area_id
, plist
;
21372 area_id
= XCAR (hotspot
);
21373 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21374 If so, we could look for mouse-enter, mouse-leave
21375 properties in PLIST (and do something...). */
21376 hotspot
= XCDR (hotspot
);
21377 if (CONSP (hotspot
)
21378 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21380 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21381 if (NILP (pointer
))
21383 help_echo_string
= Fsafe_plist_get (plist
, Qhelp_echo
);
21384 if (!NILP (help_echo_string
))
21386 help_echo_window
= window
;
21387 help_echo_object
= glyph
->object
;
21388 help_echo_pos
= glyph
->charpos
;
21392 if (NILP (pointer
))
21393 pointer
= Fsafe_plist_get (XCDR (img
->spec
), QCpointer
);
21397 /* Clear mouse face if X/Y not over text. */
21399 || area
!= TEXT_AREA
21400 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21402 if (clear_mouse_face (dpyinfo
))
21403 cursor
= No_Cursor
;
21404 if (NILP (pointer
))
21406 if (area
!= TEXT_AREA
)
21407 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21409 pointer
= Vvoid_text_area_pointer
;
21414 pos
= glyph
->charpos
;
21415 object
= glyph
->object
;
21416 if (!STRINGP (object
) && !BUFFERP (object
))
21419 /* If we get an out-of-range value, return now; avoid an error. */
21420 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21423 /* Make the window's buffer temporarily current for
21424 overlays_at and compute_char_face. */
21425 obuf
= current_buffer
;
21426 current_buffer
= b
;
21432 /* Is this char mouse-active or does it have help-echo? */
21433 position
= make_number (pos
);
21435 if (BUFFERP (object
))
21437 /* Put all the overlays we want in a vector in overlay_vec. */
21438 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21439 /* Sort overlays into increasing priority order. */
21440 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21445 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21446 && vpos
>= dpyinfo
->mouse_face_beg_row
21447 && vpos
<= dpyinfo
->mouse_face_end_row
21448 && (vpos
> dpyinfo
->mouse_face_beg_row
21449 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21450 && (vpos
< dpyinfo
->mouse_face_end_row
21451 || hpos
< dpyinfo
->mouse_face_end_col
21452 || dpyinfo
->mouse_face_past_end
));
21455 cursor
= No_Cursor
;
21457 /* Check mouse-face highlighting. */
21459 /* If there exists an overlay with mouse-face overlapping
21460 the one we are currently highlighting, we have to
21461 check if we enter the overlapping overlay, and then
21462 highlight only that. */
21463 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21464 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21466 /* Find the highest priority overlay that has a mouse-face
21469 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21471 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21472 if (!NILP (mouse_face
))
21473 overlay
= overlay_vec
[i
];
21476 /* If we're actually highlighting the same overlay as
21477 before, there's no need to do that again. */
21478 if (!NILP (overlay
)
21479 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21480 goto check_help_echo
;
21482 dpyinfo
->mouse_face_overlay
= overlay
;
21484 /* Clear the display of the old active region, if any. */
21485 if (clear_mouse_face (dpyinfo
))
21486 cursor
= No_Cursor
;
21488 /* If no overlay applies, get a text property. */
21489 if (NILP (overlay
))
21490 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21492 /* Handle the overlay case. */
21493 if (!NILP (overlay
))
21495 /* Find the range of text around this char that
21496 should be active. */
21497 Lisp_Object before
, after
;
21500 before
= Foverlay_start (overlay
);
21501 after
= Foverlay_end (overlay
);
21502 /* Record this as the current active region. */
21503 fast_find_position (w
, XFASTINT (before
),
21504 &dpyinfo
->mouse_face_beg_col
,
21505 &dpyinfo
->mouse_face_beg_row
,
21506 &dpyinfo
->mouse_face_beg_x
,
21507 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21509 dpyinfo
->mouse_face_past_end
21510 = !fast_find_position (w
, XFASTINT (after
),
21511 &dpyinfo
->mouse_face_end_col
,
21512 &dpyinfo
->mouse_face_end_row
,
21513 &dpyinfo
->mouse_face_end_x
,
21514 &dpyinfo
->mouse_face_end_y
, Qnil
);
21515 dpyinfo
->mouse_face_window
= window
;
21517 dpyinfo
->mouse_face_face_id
21518 = face_at_buffer_position (w
, pos
, 0, 0,
21520 !dpyinfo
->mouse_face_hidden
);
21522 /* Display it as active. */
21523 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21524 cursor
= No_Cursor
;
21526 /* Handle the text property case. */
21527 else if (!NILP (mouse_face
) && BUFFERP (object
))
21529 /* Find the range of text around this char that
21530 should be active. */
21531 Lisp_Object before
, after
, beginning
, end
;
21534 beginning
= Fmarker_position (w
->start
);
21535 end
= make_number (BUF_Z (XBUFFER (object
))
21536 - XFASTINT (w
->window_end_pos
));
21538 = Fprevious_single_property_change (make_number (pos
+ 1),
21540 object
, beginning
);
21542 = Fnext_single_property_change (position
, Qmouse_face
,
21545 /* Record this as the current active region. */
21546 fast_find_position (w
, XFASTINT (before
),
21547 &dpyinfo
->mouse_face_beg_col
,
21548 &dpyinfo
->mouse_face_beg_row
,
21549 &dpyinfo
->mouse_face_beg_x
,
21550 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21551 dpyinfo
->mouse_face_past_end
21552 = !fast_find_position (w
, XFASTINT (after
),
21553 &dpyinfo
->mouse_face_end_col
,
21554 &dpyinfo
->mouse_face_end_row
,
21555 &dpyinfo
->mouse_face_end_x
,
21556 &dpyinfo
->mouse_face_end_y
, Qnil
);
21557 dpyinfo
->mouse_face_window
= window
;
21559 if (BUFFERP (object
))
21560 dpyinfo
->mouse_face_face_id
21561 = face_at_buffer_position (w
, pos
, 0, 0,
21563 !dpyinfo
->mouse_face_hidden
);
21565 /* Display it as active. */
21566 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21567 cursor
= No_Cursor
;
21569 else if (!NILP (mouse_face
) && STRINGP (object
))
21574 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21577 e
= Fnext_single_property_change (position
, Qmouse_face
,
21580 b
= make_number (0);
21582 e
= make_number (SCHARS (object
) - 1);
21583 fast_find_string_pos (w
, XINT (b
), object
,
21584 &dpyinfo
->mouse_face_beg_col
,
21585 &dpyinfo
->mouse_face_beg_row
,
21586 &dpyinfo
->mouse_face_beg_x
,
21587 &dpyinfo
->mouse_face_beg_y
, 0);
21588 fast_find_string_pos (w
, XINT (e
), object
,
21589 &dpyinfo
->mouse_face_end_col
,
21590 &dpyinfo
->mouse_face_end_row
,
21591 &dpyinfo
->mouse_face_end_x
,
21592 &dpyinfo
->mouse_face_end_y
, 1);
21593 dpyinfo
->mouse_face_past_end
= 0;
21594 dpyinfo
->mouse_face_window
= window
;
21595 dpyinfo
->mouse_face_face_id
21596 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21597 glyph
->face_id
, 1);
21598 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21599 cursor
= No_Cursor
;
21601 else if (STRINGP (object
) && NILP (mouse_face
))
21603 /* A string which doesn't have mouse-face, but
21604 the text ``under'' it might have. */
21605 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21606 int start
= MATRIX_ROW_START_CHARPOS (r
);
21608 pos
= string_buffer_position (w
, object
, start
);
21610 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21614 if (!NILP (mouse_face
) && !NILP (overlay
))
21616 Lisp_Object before
= Foverlay_start (overlay
);
21617 Lisp_Object after
= Foverlay_end (overlay
);
21620 /* Note that we might not be able to find position
21621 BEFORE in the glyph matrix if the overlay is
21622 entirely covered by a `display' property. In
21623 this case, we overshoot. So let's stop in
21624 the glyph matrix before glyphs for OBJECT. */
21625 fast_find_position (w
, XFASTINT (before
),
21626 &dpyinfo
->mouse_face_beg_col
,
21627 &dpyinfo
->mouse_face_beg_row
,
21628 &dpyinfo
->mouse_face_beg_x
,
21629 &dpyinfo
->mouse_face_beg_y
,
21632 dpyinfo
->mouse_face_past_end
21633 = !fast_find_position (w
, XFASTINT (after
),
21634 &dpyinfo
->mouse_face_end_col
,
21635 &dpyinfo
->mouse_face_end_row
,
21636 &dpyinfo
->mouse_face_end_x
,
21637 &dpyinfo
->mouse_face_end_y
,
21639 dpyinfo
->mouse_face_window
= window
;
21640 dpyinfo
->mouse_face_face_id
21641 = face_at_buffer_position (w
, pos
, 0, 0,
21643 !dpyinfo
->mouse_face_hidden
);
21645 /* Display it as active. */
21646 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21647 cursor
= No_Cursor
;
21654 /* Look for a `help-echo' property. */
21655 if (NILP (help_echo_string
)) {
21656 Lisp_Object help
, overlay
;
21658 /* Check overlays first. */
21659 help
= overlay
= Qnil
;
21660 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21662 overlay
= overlay_vec
[i
];
21663 help
= Foverlay_get (overlay
, Qhelp_echo
);
21668 help_echo_string
= help
;
21669 help_echo_window
= window
;
21670 help_echo_object
= overlay
;
21671 help_echo_pos
= pos
;
21675 Lisp_Object object
= glyph
->object
;
21676 int charpos
= glyph
->charpos
;
21678 /* Try text properties. */
21679 if (STRINGP (object
)
21681 && charpos
< SCHARS (object
))
21683 help
= Fget_text_property (make_number (charpos
),
21684 Qhelp_echo
, object
);
21687 /* If the string itself doesn't specify a help-echo,
21688 see if the buffer text ``under'' it does. */
21689 struct glyph_row
*r
21690 = MATRIX_ROW (w
->current_matrix
, vpos
);
21691 int start
= MATRIX_ROW_START_CHARPOS (r
);
21692 int pos
= string_buffer_position (w
, object
, start
);
21695 help
= Fget_char_property (make_number (pos
),
21696 Qhelp_echo
, w
->buffer
);
21700 object
= w
->buffer
;
21705 else if (BUFFERP (object
)
21708 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21713 help_echo_string
= help
;
21714 help_echo_window
= window
;
21715 help_echo_object
= object
;
21716 help_echo_pos
= charpos
;
21721 /* Look for a `pointer' property. */
21722 if (NILP (pointer
))
21724 /* Check overlays first. */
21725 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21726 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21728 if (NILP (pointer
))
21730 Lisp_Object object
= glyph
->object
;
21731 int charpos
= glyph
->charpos
;
21733 /* Try text properties. */
21734 if (STRINGP (object
)
21736 && charpos
< SCHARS (object
))
21738 pointer
= Fget_text_property (make_number (charpos
),
21740 if (NILP (pointer
))
21742 /* If the string itself doesn't specify a pointer,
21743 see if the buffer text ``under'' it does. */
21744 struct glyph_row
*r
21745 = MATRIX_ROW (w
->current_matrix
, vpos
);
21746 int start
= MATRIX_ROW_START_CHARPOS (r
);
21747 int pos
= string_buffer_position (w
, object
, start
);
21749 pointer
= Fget_char_property (make_number (pos
),
21750 Qpointer
, w
->buffer
);
21753 else if (BUFFERP (object
)
21756 pointer
= Fget_text_property (make_number (charpos
),
21763 current_buffer
= obuf
;
21768 define_frame_cursor1 (f
, cursor
, pointer
);
21773 Clear any mouse-face on window W. This function is part of the
21774 redisplay interface, and is called from try_window_id and similar
21775 functions to ensure the mouse-highlight is off. */
21778 x_clear_window_mouse_face (w
)
21781 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21782 Lisp_Object window
;
21785 XSETWINDOW (window
, w
);
21786 if (EQ (window
, dpyinfo
->mouse_face_window
))
21787 clear_mouse_face (dpyinfo
);
21793 Just discard the mouse face information for frame F, if any.
21794 This is used when the size of F is changed. */
21797 cancel_mouse_face (f
)
21800 Lisp_Object window
;
21801 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21803 window
= dpyinfo
->mouse_face_window
;
21804 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21806 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21807 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21808 dpyinfo
->mouse_face_window
= Qnil
;
21813 #endif /* HAVE_WINDOW_SYSTEM */
21816 /***********************************************************************
21818 ***********************************************************************/
21820 #ifdef HAVE_WINDOW_SYSTEM
21822 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21823 which intersects rectangle R. R is in window-relative coordinates. */
21826 expose_area (w
, row
, r
, area
)
21828 struct glyph_row
*row
;
21830 enum glyph_row_area area
;
21832 struct glyph
*first
= row
->glyphs
[area
];
21833 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21834 struct glyph
*last
;
21835 int first_x
, start_x
, x
;
21837 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21838 /* If row extends face to end of line write the whole line. */
21839 draw_glyphs (w
, 0, row
, area
,
21840 0, row
->used
[area
],
21841 DRAW_NORMAL_TEXT
, 0);
21844 /* Set START_X to the window-relative start position for drawing glyphs of
21845 AREA. The first glyph of the text area can be partially visible.
21846 The first glyphs of other areas cannot. */
21847 start_x
= window_box_left_offset (w
, area
);
21849 if (area
== TEXT_AREA
)
21852 /* Find the first glyph that must be redrawn. */
21854 && x
+ first
->pixel_width
< r
->x
)
21856 x
+= first
->pixel_width
;
21860 /* Find the last one. */
21864 && x
< r
->x
+ r
->width
)
21866 x
+= last
->pixel_width
;
21872 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21873 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21874 DRAW_NORMAL_TEXT
, 0);
21879 /* Redraw the parts of the glyph row ROW on window W intersecting
21880 rectangle R. R is in window-relative coordinates. Value is
21881 non-zero if mouse-face was overwritten. */
21884 expose_line (w
, row
, r
)
21886 struct glyph_row
*row
;
21889 xassert (row
->enabled_p
);
21891 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21892 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21893 0, row
->used
[TEXT_AREA
],
21894 DRAW_NORMAL_TEXT
, 0);
21897 if (row
->used
[LEFT_MARGIN_AREA
])
21898 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21899 if (row
->used
[TEXT_AREA
])
21900 expose_area (w
, row
, r
, TEXT_AREA
);
21901 if (row
->used
[RIGHT_MARGIN_AREA
])
21902 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21903 draw_row_fringe_bitmaps (w
, row
);
21906 return row
->mouse_face_p
;
21910 /* Redraw those parts of glyphs rows during expose event handling that
21911 overlap other rows. Redrawing of an exposed line writes over parts
21912 of lines overlapping that exposed line; this function fixes that.
21914 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21915 row in W's current matrix that is exposed and overlaps other rows.
21916 LAST_OVERLAPPING_ROW is the last such row. */
21919 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21921 struct glyph_row
*first_overlapping_row
;
21922 struct glyph_row
*last_overlapping_row
;
21924 struct glyph_row
*row
;
21926 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21927 if (row
->overlapping_p
)
21929 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21931 if (row
->used
[LEFT_MARGIN_AREA
])
21932 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21934 if (row
->used
[TEXT_AREA
])
21935 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21937 if (row
->used
[RIGHT_MARGIN_AREA
])
21938 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21943 /* Return non-zero if W's cursor intersects rectangle R. */
21946 phys_cursor_in_rect_p (w
, r
)
21950 XRectangle cr
, result
;
21951 struct glyph
*cursor_glyph
;
21953 cursor_glyph
= get_phys_cursor_glyph (w
);
21956 /* r is relative to W's box, but w->phys_cursor.x is relative
21957 to left edge of W's TEXT area. Adjust it. */
21958 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21959 cr
.y
= w
->phys_cursor
.y
;
21960 cr
.width
= cursor_glyph
->pixel_width
;
21961 cr
.height
= w
->phys_cursor_height
;
21962 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21963 I assume the effect is the same -- and this is portable. */
21964 return x_intersect_rectangles (&cr
, r
, &result
);
21972 Draw a vertical window border to the right of window W if W doesn't
21973 have vertical scroll bars. */
21976 x_draw_vertical_border (w
)
21979 /* We could do better, if we knew what type of scroll-bar the adjacent
21980 windows (on either side) have... But we don't :-(
21981 However, I think this works ok. ++KFS 2003-04-25 */
21983 /* Redraw borders between horizontally adjacent windows. Don't
21984 do it for frames with vertical scroll bars because either the
21985 right scroll bar of a window, or the left scroll bar of its
21986 neighbor will suffice as a border. */
21987 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
21990 if (!WINDOW_RIGHTMOST_P (w
)
21991 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21993 int x0
, x1
, y0
, y1
;
21995 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21998 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22000 else if (!WINDOW_LEFTMOST_P (w
)
22001 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22003 int x0
, x1
, y0
, y1
;
22005 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22008 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22013 /* Redraw the part of window W intersection rectangle FR. Pixel
22014 coordinates in FR are frame-relative. Call this function with
22015 input blocked. Value is non-zero if the exposure overwrites
22019 expose_window (w
, fr
)
22023 struct frame
*f
= XFRAME (w
->frame
);
22025 int mouse_face_overwritten_p
= 0;
22027 /* If window is not yet fully initialized, do nothing. This can
22028 happen when toolkit scroll bars are used and a window is split.
22029 Reconfiguring the scroll bar will generate an expose for a newly
22031 if (w
->current_matrix
== NULL
)
22034 /* When we're currently updating the window, display and current
22035 matrix usually don't agree. Arrange for a thorough display
22037 if (w
== updated_window
)
22039 SET_FRAME_GARBAGED (f
);
22043 /* Frame-relative pixel rectangle of W. */
22044 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22045 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22046 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22047 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22049 if (x_intersect_rectangles (fr
, &wr
, &r
))
22051 int yb
= window_text_bottom_y (w
);
22052 struct glyph_row
*row
;
22053 int cursor_cleared_p
;
22054 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22056 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22057 r
.x
, r
.y
, r
.width
, r
.height
));
22059 /* Convert to window coordinates. */
22060 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22061 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22063 /* Turn off the cursor. */
22064 if (!w
->pseudo_window_p
22065 && phys_cursor_in_rect_p (w
, &r
))
22067 x_clear_cursor (w
);
22068 cursor_cleared_p
= 1;
22071 cursor_cleared_p
= 0;
22073 /* Update lines intersecting rectangle R. */
22074 first_overlapping_row
= last_overlapping_row
= NULL
;
22075 for (row
= w
->current_matrix
->rows
;
22080 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22082 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22083 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22084 || (r
.y
>= y0
&& r
.y
< y1
)
22085 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22087 if (row
->overlapping_p
)
22089 if (first_overlapping_row
== NULL
)
22090 first_overlapping_row
= row
;
22091 last_overlapping_row
= row
;
22094 if (expose_line (w
, row
, &r
))
22095 mouse_face_overwritten_p
= 1;
22102 /* Display the mode line if there is one. */
22103 if (WINDOW_WANTS_MODELINE_P (w
)
22104 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22106 && row
->y
< r
.y
+ r
.height
)
22108 if (expose_line (w
, row
, &r
))
22109 mouse_face_overwritten_p
= 1;
22112 if (!w
->pseudo_window_p
)
22114 /* Fix the display of overlapping rows. */
22115 if (first_overlapping_row
)
22116 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22118 /* Draw border between windows. */
22119 x_draw_vertical_border (w
);
22121 /* Turn the cursor on again. */
22122 if (cursor_cleared_p
)
22123 update_window_cursor (w
, 1);
22127 return mouse_face_overwritten_p
;
22132 /* Redraw (parts) of all windows in the window tree rooted at W that
22133 intersect R. R contains frame pixel coordinates. Value is
22134 non-zero if the exposure overwrites mouse-face. */
22137 expose_window_tree (w
, r
)
22141 struct frame
*f
= XFRAME (w
->frame
);
22142 int mouse_face_overwritten_p
= 0;
22144 while (w
&& !FRAME_GARBAGED_P (f
))
22146 if (!NILP (w
->hchild
))
22147 mouse_face_overwritten_p
22148 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22149 else if (!NILP (w
->vchild
))
22150 mouse_face_overwritten_p
22151 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22153 mouse_face_overwritten_p
|= expose_window (w
, r
);
22155 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22158 return mouse_face_overwritten_p
;
22163 Redisplay an exposed area of frame F. X and Y are the upper-left
22164 corner of the exposed rectangle. W and H are width and height of
22165 the exposed area. All are pixel values. W or H zero means redraw
22166 the entire frame. */
22169 expose_frame (f
, x
, y
, w
, h
)
22174 int mouse_face_overwritten_p
= 0;
22176 TRACE ((stderr
, "expose_frame "));
22178 /* No need to redraw if frame will be redrawn soon. */
22179 if (FRAME_GARBAGED_P (f
))
22181 TRACE ((stderr
, " garbaged\n"));
22185 /* If basic faces haven't been realized yet, there is no point in
22186 trying to redraw anything. This can happen when we get an expose
22187 event while Emacs is starting, e.g. by moving another window. */
22188 if (FRAME_FACE_CACHE (f
) == NULL
22189 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22191 TRACE ((stderr
, " no faces\n"));
22195 if (w
== 0 || h
== 0)
22198 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22199 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22209 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22210 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22212 if (WINDOWP (f
->tool_bar_window
))
22213 mouse_face_overwritten_p
22214 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22216 #ifdef HAVE_X_WINDOWS
22218 #ifndef USE_X_TOOLKIT
22219 if (WINDOWP (f
->menu_bar_window
))
22220 mouse_face_overwritten_p
22221 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22222 #endif /* not USE_X_TOOLKIT */
22226 /* Some window managers support a focus-follows-mouse style with
22227 delayed raising of frames. Imagine a partially obscured frame,
22228 and moving the mouse into partially obscured mouse-face on that
22229 frame. The visible part of the mouse-face will be highlighted,
22230 then the WM raises the obscured frame. With at least one WM, KDE
22231 2.1, Emacs is not getting any event for the raising of the frame
22232 (even tried with SubstructureRedirectMask), only Expose events.
22233 These expose events will draw text normally, i.e. not
22234 highlighted. Which means we must redo the highlight here.
22235 Subsume it under ``we love X''. --gerd 2001-08-15 */
22236 /* Included in Windows version because Windows most likely does not
22237 do the right thing if any third party tool offers
22238 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22239 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22241 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22242 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22244 int x
= dpyinfo
->mouse_face_mouse_x
;
22245 int y
= dpyinfo
->mouse_face_mouse_y
;
22246 clear_mouse_face (dpyinfo
);
22247 note_mouse_highlight (f
, x
, y
);
22254 Determine the intersection of two rectangles R1 and R2. Return
22255 the intersection in *RESULT. Value is non-zero if RESULT is not
22259 x_intersect_rectangles (r1
, r2
, result
)
22260 XRectangle
*r1
, *r2
, *result
;
22262 XRectangle
*left
, *right
;
22263 XRectangle
*upper
, *lower
;
22264 int intersection_p
= 0;
22266 /* Rearrange so that R1 is the left-most rectangle. */
22268 left
= r1
, right
= r2
;
22270 left
= r2
, right
= r1
;
22272 /* X0 of the intersection is right.x0, if this is inside R1,
22273 otherwise there is no intersection. */
22274 if (right
->x
<= left
->x
+ left
->width
)
22276 result
->x
= right
->x
;
22278 /* The right end of the intersection is the minimum of the
22279 the right ends of left and right. */
22280 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22283 /* Same game for Y. */
22285 upper
= r1
, lower
= r2
;
22287 upper
= r2
, lower
= r1
;
22289 /* The upper end of the intersection is lower.y0, if this is inside
22290 of upper. Otherwise, there is no intersection. */
22291 if (lower
->y
<= upper
->y
+ upper
->height
)
22293 result
->y
= lower
->y
;
22295 /* The lower end of the intersection is the minimum of the lower
22296 ends of upper and lower. */
22297 result
->height
= (min (lower
->y
+ lower
->height
,
22298 upper
->y
+ upper
->height
)
22300 intersection_p
= 1;
22304 return intersection_p
;
22307 #endif /* HAVE_WINDOW_SYSTEM */
22310 /***********************************************************************
22312 ***********************************************************************/
22317 Vwith_echo_area_save_vector
= Qnil
;
22318 staticpro (&Vwith_echo_area_save_vector
);
22320 Vmessage_stack
= Qnil
;
22321 staticpro (&Vmessage_stack
);
22323 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22324 staticpro (&Qinhibit_redisplay
);
22326 message_dolog_marker1
= Fmake_marker ();
22327 staticpro (&message_dolog_marker1
);
22328 message_dolog_marker2
= Fmake_marker ();
22329 staticpro (&message_dolog_marker2
);
22330 message_dolog_marker3
= Fmake_marker ();
22331 staticpro (&message_dolog_marker3
);
22334 defsubr (&Sdump_frame_glyph_matrix
);
22335 defsubr (&Sdump_glyph_matrix
);
22336 defsubr (&Sdump_glyph_row
);
22337 defsubr (&Sdump_tool_bar_row
);
22338 defsubr (&Strace_redisplay
);
22339 defsubr (&Strace_to_stderr
);
22341 #ifdef HAVE_WINDOW_SYSTEM
22342 defsubr (&Stool_bar_lines_needed
);
22343 defsubr (&Slookup_image_map
);
22345 defsubr (&Sformat_mode_line
);
22347 staticpro (&Qmenu_bar_update_hook
);
22348 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22350 staticpro (&Qoverriding_terminal_local_map
);
22351 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22353 staticpro (&Qoverriding_local_map
);
22354 Qoverriding_local_map
= intern ("overriding-local-map");
22356 staticpro (&Qwindow_scroll_functions
);
22357 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22359 staticpro (&Qredisplay_end_trigger_functions
);
22360 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22362 staticpro (&Qinhibit_point_motion_hooks
);
22363 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22365 QCdata
= intern (":data");
22366 staticpro (&QCdata
);
22367 Qdisplay
= intern ("display");
22368 staticpro (&Qdisplay
);
22369 Qspace_width
= intern ("space-width");
22370 staticpro (&Qspace_width
);
22371 Qraise
= intern ("raise");
22372 staticpro (&Qraise
);
22373 Qslice
= intern ("slice");
22374 staticpro (&Qslice
);
22375 Qspace
= intern ("space");
22376 staticpro (&Qspace
);
22377 Qmargin
= intern ("margin");
22378 staticpro (&Qmargin
);
22379 Qpointer
= intern ("pointer");
22380 staticpro (&Qpointer
);
22381 Qleft_margin
= intern ("left-margin");
22382 staticpro (&Qleft_margin
);
22383 Qright_margin
= intern ("right-margin");
22384 staticpro (&Qright_margin
);
22385 Qcenter
= intern ("center");
22386 staticpro (&Qcenter
);
22387 Qline_height
= intern ("line-height");
22388 staticpro (&Qline_height
);
22389 QCalign_to
= intern (":align-to");
22390 staticpro (&QCalign_to
);
22391 QCrelative_width
= intern (":relative-width");
22392 staticpro (&QCrelative_width
);
22393 QCrelative_height
= intern (":relative-height");
22394 staticpro (&QCrelative_height
);
22395 QCeval
= intern (":eval");
22396 staticpro (&QCeval
);
22397 QCpropertize
= intern (":propertize");
22398 staticpro (&QCpropertize
);
22399 QCfile
= intern (":file");
22400 staticpro (&QCfile
);
22401 Qfontified
= intern ("fontified");
22402 staticpro (&Qfontified
);
22403 Qfontification_functions
= intern ("fontification-functions");
22404 staticpro (&Qfontification_functions
);
22405 Qtrailing_whitespace
= intern ("trailing-whitespace");
22406 staticpro (&Qtrailing_whitespace
);
22407 Qescape_glyph
= intern ("escape-glyph");
22408 staticpro (&Qescape_glyph
);
22409 Qimage
= intern ("image");
22410 staticpro (&Qimage
);
22411 QCmap
= intern (":map");
22412 staticpro (&QCmap
);
22413 QCpointer
= intern (":pointer");
22414 staticpro (&QCpointer
);
22415 Qrect
= intern ("rect");
22416 staticpro (&Qrect
);
22417 Qcircle
= intern ("circle");
22418 staticpro (&Qcircle
);
22419 Qpoly
= intern ("poly");
22420 staticpro (&Qpoly
);
22421 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22422 staticpro (&Qmessage_truncate_lines
);
22423 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
22424 staticpro (&Qcursor_in_non_selected_windows
);
22425 Qgrow_only
= intern ("grow-only");
22426 staticpro (&Qgrow_only
);
22427 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22428 staticpro (&Qinhibit_menubar_update
);
22429 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22430 staticpro (&Qinhibit_eval_during_redisplay
);
22431 Qposition
= intern ("position");
22432 staticpro (&Qposition
);
22433 Qbuffer_position
= intern ("buffer-position");
22434 staticpro (&Qbuffer_position
);
22435 Qobject
= intern ("object");
22436 staticpro (&Qobject
);
22437 Qbar
= intern ("bar");
22439 Qhbar
= intern ("hbar");
22440 staticpro (&Qhbar
);
22441 Qbox
= intern ("box");
22443 Qhollow
= intern ("hollow");
22444 staticpro (&Qhollow
);
22445 Qhand
= intern ("hand");
22446 staticpro (&Qhand
);
22447 Qarrow
= intern ("arrow");
22448 staticpro (&Qarrow
);
22449 Qtext
= intern ("text");
22450 staticpro (&Qtext
);
22451 Qrisky_local_variable
= intern ("risky-local-variable");
22452 staticpro (&Qrisky_local_variable
);
22453 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22454 staticpro (&Qinhibit_free_realized_faces
);
22456 list_of_error
= Fcons (Fcons (intern ("error"),
22457 Fcons (intern ("void-variable"), Qnil
)),
22459 staticpro (&list_of_error
);
22461 Qlast_arrow_position
= intern ("last-arrow-position");
22462 staticpro (&Qlast_arrow_position
);
22463 Qlast_arrow_string
= intern ("last-arrow-string");
22464 staticpro (&Qlast_arrow_string
);
22466 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22467 staticpro (&Qoverlay_arrow_string
);
22468 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22469 staticpro (&Qoverlay_arrow_bitmap
);
22471 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22472 staticpro (&echo_buffer
[0]);
22473 staticpro (&echo_buffer
[1]);
22475 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22476 staticpro (&echo_area_buffer
[0]);
22477 staticpro (&echo_area_buffer
[1]);
22479 Vmessages_buffer_name
= build_string ("*Messages*");
22480 staticpro (&Vmessages_buffer_name
);
22482 mode_line_proptrans_alist
= Qnil
;
22483 staticpro (&mode_line_proptrans_alist
);
22485 mode_line_string_list
= Qnil
;
22486 staticpro (&mode_line_string_list
);
22488 help_echo_string
= Qnil
;
22489 staticpro (&help_echo_string
);
22490 help_echo_object
= Qnil
;
22491 staticpro (&help_echo_object
);
22492 help_echo_window
= Qnil
;
22493 staticpro (&help_echo_window
);
22494 previous_help_echo_string
= Qnil
;
22495 staticpro (&previous_help_echo_string
);
22496 help_echo_pos
= -1;
22498 #ifdef HAVE_WINDOW_SYSTEM
22499 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22500 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22501 For example, if a block cursor is over a tab, it will be drawn as
22502 wide as that tab on the display. */);
22503 x_stretch_cursor_p
= 0;
22506 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22507 doc
: /* *Non-nil means highlight trailing whitespace.
22508 The face used for trailing whitespace is `trailing-whitespace'. */);
22509 Vshow_trailing_whitespace
= Qnil
;
22511 DEFVAR_LISP ("show-nonbreak-escape", &Vshow_nonbreak_escape
,
22512 doc
: /* *Non-nil means display escape character before non-break space and hyphen. */);
22513 Vshow_nonbreak_escape
= Qt
;
22515 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22516 doc
: /* *The pointer shape to show in void text areas.
22517 Nil means to show the text pointer. Other options are `arrow', `text',
22518 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22519 Vvoid_text_area_pointer
= Qarrow
;
22521 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22522 doc
: /* Non-nil means don't actually do any redisplay.
22523 This is used for internal purposes. */);
22524 Vinhibit_redisplay
= Qnil
;
22526 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22527 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22528 Vglobal_mode_string
= Qnil
;
22530 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22531 doc
: /* Marker for where to display an arrow on top of the buffer text.
22532 This must be the beginning of a line in order to work.
22533 See also `overlay-arrow-string'. */);
22534 Voverlay_arrow_position
= Qnil
;
22536 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22537 doc
: /* String to display as an arrow in non-window frames.
22538 See also `overlay-arrow-position'. */);
22539 Voverlay_arrow_string
= Qnil
;
22541 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22542 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22543 The symbols on this list are examined during redisplay to determine
22544 where to display overlay arrows. */);
22545 Voverlay_arrow_variable_list
22546 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22548 DEFVAR_INT ("scroll-step", &scroll_step
,
22549 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22550 If that fails to bring point back on frame, point is centered instead.
22551 If this is zero, point is always centered after it moves off frame.
22552 If you want scrolling to always be a line at a time, you should set
22553 `scroll-conservatively' to a large value rather than set this to 1. */);
22555 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22556 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22557 A value of zero means to scroll the text to center point vertically
22558 in the window. */);
22559 scroll_conservatively
= 0;
22561 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22562 doc
: /* *Number of lines of margin at the top and bottom of a window.
22563 Recenter the window whenever point gets within this many lines
22564 of the top or bottom of the window. */);
22567 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22568 doc
: /* Pixels per inch on current display.
22569 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22570 Vdisplay_pixels_per_inch
= make_float (72.0);
22573 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22576 DEFVAR_BOOL ("truncate-partial-width-windows",
22577 &truncate_partial_width_windows
,
22578 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22579 truncate_partial_width_windows
= 1;
22581 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22582 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22583 Any other value means to use the appropriate face, `mode-line',
22584 `header-line', or `menu' respectively. */);
22585 mode_line_inverse_video
= 1;
22587 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22588 doc
: /* *Maximum buffer size for which line number should be displayed.
22589 If the buffer is bigger than this, the line number does not appear
22590 in the mode line. A value of nil means no limit. */);
22591 Vline_number_display_limit
= Qnil
;
22593 DEFVAR_INT ("line-number-display-limit-width",
22594 &line_number_display_limit_width
,
22595 doc
: /* *Maximum line width (in characters) for line number display.
22596 If the average length of the lines near point is bigger than this, then the
22597 line number may be omitted from the mode line. */);
22598 line_number_display_limit_width
= 200;
22600 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22601 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22602 highlight_nonselected_windows
= 0;
22604 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22605 doc
: /* Non-nil if more than one frame is visible on this display.
22606 Minibuffer-only frames don't count, but iconified frames do.
22607 This variable is not guaranteed to be accurate except while processing
22608 `frame-title-format' and `icon-title-format'. */);
22610 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22611 doc
: /* Template for displaying the title bar of visible frames.
22612 \(Assuming the window manager supports this feature.)
22613 This variable has the same structure as `mode-line-format' (which see),
22614 and is used only on frames for which no explicit name has been set
22615 \(see `modify-frame-parameters'). */);
22617 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22618 doc
: /* Template for displaying the title bar of an iconified frame.
22619 \(Assuming the window manager supports this feature.)
22620 This variable has the same structure as `mode-line-format' (which see),
22621 and is used only on frames for which no explicit name has been set
22622 \(see `modify-frame-parameters'). */);
22624 = Vframe_title_format
22625 = Fcons (intern ("multiple-frames"),
22626 Fcons (build_string ("%b"),
22627 Fcons (Fcons (empty_string
,
22628 Fcons (intern ("invocation-name"),
22629 Fcons (build_string ("@"),
22630 Fcons (intern ("system-name"),
22634 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22635 doc
: /* Maximum number of lines to keep in the message log buffer.
22636 If nil, disable message logging. If t, log messages but don't truncate
22637 the buffer when it becomes large. */);
22638 Vmessage_log_max
= make_number (50);
22640 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22641 doc
: /* Functions called before redisplay, if window sizes have changed.
22642 The value should be a list of functions that take one argument.
22643 Just before redisplay, for each frame, if any of its windows have changed
22644 size since the last redisplay, or have been split or deleted,
22645 all the functions in the list are called, with the frame as argument. */);
22646 Vwindow_size_change_functions
= Qnil
;
22648 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22649 doc
: /* List of functions to call before redisplaying a window with scrolling.
22650 Each function is called with two arguments, the window
22651 and its new display-start position. Note that the value of `window-end'
22652 is not valid when these functions are called. */);
22653 Vwindow_scroll_functions
= Qnil
;
22655 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22656 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22657 mouse_autoselect_window
= 0;
22659 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22660 doc
: /* *Non-nil means automatically resize tool-bars.
22661 This increases a tool-bar's height if not all tool-bar items are visible.
22662 It decreases a tool-bar's height when it would display blank lines
22664 auto_resize_tool_bars_p
= 1;
22666 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22667 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22668 auto_raise_tool_bar_buttons_p
= 1;
22670 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
22671 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
22672 make_cursor_line_fully_visible_p
= 1;
22674 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22675 doc
: /* *Margin around tool-bar buttons in pixels.
22676 If an integer, use that for both horizontal and vertical margins.
22677 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22678 HORZ specifying the horizontal margin, and VERT specifying the
22679 vertical margin. */);
22680 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22682 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22683 doc
: /* *Relief thickness of tool-bar buttons. */);
22684 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22686 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22687 doc
: /* List of functions to call to fontify regions of text.
22688 Each function is called with one argument POS. Functions must
22689 fontify a region starting at POS in the current buffer, and give
22690 fontified regions the property `fontified'. */);
22691 Vfontification_functions
= Qnil
;
22692 Fmake_variable_buffer_local (Qfontification_functions
);
22694 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22695 &unibyte_display_via_language_environment
,
22696 doc
: /* *Non-nil means display unibyte text according to language environment.
22697 Specifically this means that unibyte non-ASCII characters
22698 are displayed by converting them to the equivalent multibyte characters
22699 according to the current language environment. As a result, they are
22700 displayed according to the current fontset. */);
22701 unibyte_display_via_language_environment
= 0;
22703 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22704 doc
: /* *Maximum height for resizing mini-windows.
22705 If a float, it specifies a fraction of the mini-window frame's height.
22706 If an integer, it specifies a number of lines. */);
22707 Vmax_mini_window_height
= make_float (0.25);
22709 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22710 doc
: /* *How to resize mini-windows.
22711 A value of nil means don't automatically resize mini-windows.
22712 A value of t means resize them to fit the text displayed in them.
22713 A value of `grow-only', the default, means let mini-windows grow
22714 only, until their display becomes empty, at which point the windows
22715 go back to their normal size. */);
22716 Vresize_mini_windows
= Qgrow_only
;
22718 DEFVAR_LISP ("cursor-in-non-selected-windows",
22719 &Vcursor_in_non_selected_windows
,
22720 doc
: /* *Cursor type to display in non-selected windows.
22721 t means to use hollow box cursor. See `cursor-type' for other values. */);
22722 Vcursor_in_non_selected_windows
= Qt
;
22724 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22725 doc
: /* Alist specifying how to blink the cursor off.
22726 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22727 `cursor-type' frame-parameter or variable equals ON-STATE,
22728 comparing using `equal', Emacs uses OFF-STATE to specify
22729 how to blink it off. */);
22730 Vblink_cursor_alist
= Qnil
;
22732 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22733 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22734 automatic_hscrolling_p
= 1;
22736 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22737 doc
: /* *How many columns away from the window edge point is allowed to get
22738 before automatic hscrolling will horizontally scroll the window. */);
22739 hscroll_margin
= 5;
22741 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22742 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22743 When point is less than `automatic-hscroll-margin' columns from the window
22744 edge, automatic hscrolling will scroll the window by the amount of columns
22745 determined by this variable. If its value is a positive integer, scroll that
22746 many columns. If it's a positive floating-point number, it specifies the
22747 fraction of the window's width to scroll. If it's nil or zero, point will be
22748 centered horizontally after the scroll. Any other value, including negative
22749 numbers, are treated as if the value were zero.
22751 Automatic hscrolling always moves point outside the scroll margin, so if
22752 point was more than scroll step columns inside the margin, the window will
22753 scroll more than the value given by the scroll step.
22755 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22756 and `scroll-right' overrides this variable's effect. */);
22757 Vhscroll_step
= make_number (0);
22759 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22760 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22761 Bind this around calls to `message' to let it take effect. */);
22762 message_truncate_lines
= 0;
22764 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22765 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22766 Can be used to update submenus whose contents should vary. */);
22767 Vmenu_bar_update_hook
= Qnil
;
22769 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22770 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22771 inhibit_menubar_update
= 0;
22773 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22774 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22775 inhibit_eval_during_redisplay
= 0;
22777 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22778 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22779 inhibit_free_realized_faces
= 0;
22782 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22783 doc
: /* Inhibit try_window_id display optimization. */);
22784 inhibit_try_window_id
= 0;
22786 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22787 doc
: /* Inhibit try_window_reusing display optimization. */);
22788 inhibit_try_window_reusing
= 0;
22790 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22791 doc
: /* Inhibit try_cursor_movement display optimization. */);
22792 inhibit_try_cursor_movement
= 0;
22793 #endif /* GLYPH_DEBUG */
22797 /* Initialize this module when Emacs starts. */
22802 Lisp_Object root_window
;
22803 struct window
*mini_w
;
22805 current_header_line_height
= current_mode_line_height
= -1;
22807 CHARPOS (this_line_start_pos
) = 0;
22809 mini_w
= XWINDOW (minibuf_window
);
22810 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22812 if (!noninteractive
)
22814 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22817 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22818 set_window_height (root_window
,
22819 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22821 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22822 set_window_height (minibuf_window
, 1, 0);
22824 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22825 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22827 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22828 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22829 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22831 /* The default ellipsis glyphs `...'. */
22832 for (i
= 0; i
< 3; ++i
)
22833 default_invis_vector
[i
] = make_number ('.');
22837 /* Allocate the buffer for frame titles.
22838 Also used for `format-mode-line'. */
22840 frame_title_buf
= (char *) xmalloc (size
);
22841 frame_title_buf_end
= frame_title_buf
+ size
;
22842 frame_title_ptr
= NULL
;
22845 help_echo_showing_p
= 0;
22849 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22850 (do not change this comment) */