1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-zero means automatically select any window when the mouse
260 cursor moves into it. */
261 int mouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin below tool bar in pixels. 0 or nil means no margin.
273 If value is `internal-border-width' or `border-width',
274 the corresponding frame parameter is used. */
276 Lisp_Object Vtool_bar_border
;
278 /* Margin around tool bar buttons in pixels. */
280 Lisp_Object Vtool_bar_button_margin
;
282 /* Thickness of shadow to draw around tool bar buttons. */
284 EMACS_INT tool_bar_button_relief
;
286 /* Non-zero means automatically resize tool-bars so that all tool-bar
287 items are visible, and no blank lines remain. */
289 int auto_resize_tool_bars_p
;
291 /* Non-zero means draw block and hollow cursor as wide as the glyph
292 under it. For example, if a block cursor is over a tab, it will be
293 drawn as wide as that tab on the display. */
295 int x_stretch_cursor_p
;
297 /* Non-nil means don't actually do any redisplay. */
299 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
301 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
303 int inhibit_eval_during_redisplay
;
305 /* Names of text properties relevant for redisplay. */
307 Lisp_Object Qdisplay
;
308 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
310 /* Symbols used in text property values. */
312 Lisp_Object Vdisplay_pixels_per_inch
;
313 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
314 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
317 Lisp_Object Qmargin
, Qpointer
;
318 Lisp_Object Qline_height
;
319 extern Lisp_Object Qheight
;
320 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
321 extern Lisp_Object Qscroll_bar
;
322 extern Lisp_Object Qcursor
;
324 /* Non-nil means highlight trailing whitespace. */
326 Lisp_Object Vshow_trailing_whitespace
;
328 /* Non-nil means escape non-break space and hyphens. */
330 Lisp_Object Vnobreak_char_display
;
332 #ifdef HAVE_WINDOW_SYSTEM
333 extern Lisp_Object Voverflow_newline_into_fringe
;
335 /* Test if overflow newline into fringe. Called with iterator IT
336 at or past right window margin, and with IT->current_x set. */
338 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
339 (!NILP (Voverflow_newline_into_fringe) \
340 && FRAME_WINDOW_P (it->f) \
341 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
342 && it->current_x == it->last_visible_x)
344 #endif /* HAVE_WINDOW_SYSTEM */
346 /* Non-nil means show the text cursor in void text areas
347 i.e. in blank areas after eol and eob. This used to be
348 the default in 21.3. */
350 Lisp_Object Vvoid_text_area_pointer
;
352 /* Name of the face used to highlight trailing whitespace. */
354 Lisp_Object Qtrailing_whitespace
;
356 /* Name and number of the face used to highlight escape glyphs. */
358 Lisp_Object Qescape_glyph
;
360 /* Name and number of the face used to highlight non-breaking spaces. */
362 Lisp_Object Qnobreak_space
;
364 /* The symbol `image' which is the car of the lists used to represent
369 /* The image map types. */
370 Lisp_Object QCmap
, QCpointer
;
371 Lisp_Object Qrect
, Qcircle
, Qpoly
;
373 /* Non-zero means print newline to stdout before next mini-buffer
376 int noninteractive_need_newline
;
378 /* Non-zero means print newline to message log before next message. */
380 static int message_log_need_newline
;
382 /* Three markers that message_dolog uses.
383 It could allocate them itself, but that causes trouble
384 in handling memory-full errors. */
385 static Lisp_Object message_dolog_marker1
;
386 static Lisp_Object message_dolog_marker2
;
387 static Lisp_Object message_dolog_marker3
;
389 /* The buffer position of the first character appearing entirely or
390 partially on the line of the selected window which contains the
391 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
392 redisplay optimization in redisplay_internal. */
394 static struct text_pos this_line_start_pos
;
396 /* Number of characters past the end of the line above, including the
397 terminating newline. */
399 static struct text_pos this_line_end_pos
;
401 /* The vertical positions and the height of this line. */
403 static int this_line_vpos
;
404 static int this_line_y
;
405 static int this_line_pixel_height
;
407 /* X position at which this display line starts. Usually zero;
408 negative if first character is partially visible. */
410 static int this_line_start_x
;
412 /* Buffer that this_line_.* variables are referring to. */
414 static struct buffer
*this_line_buffer
;
416 /* Nonzero means truncate lines in all windows less wide than the
419 int truncate_partial_width_windows
;
421 /* A flag to control how to display unibyte 8-bit character. */
423 int unibyte_display_via_language_environment
;
425 /* Nonzero means we have more than one non-mini-buffer-only frame.
426 Not guaranteed to be accurate except while parsing
427 frame-title-format. */
431 Lisp_Object Vglobal_mode_string
;
434 /* List of variables (symbols) which hold markers for overlay arrows.
435 The symbols on this list are examined during redisplay to determine
436 where to display overlay arrows. */
438 Lisp_Object Voverlay_arrow_variable_list
;
440 /* Marker for where to display an arrow on top of the buffer text. */
442 Lisp_Object Voverlay_arrow_position
;
444 /* String to display for the arrow. Only used on terminal frames. */
446 Lisp_Object Voverlay_arrow_string
;
448 /* Values of those variables at last redisplay are stored as
449 properties on `overlay-arrow-position' symbol. However, if
450 Voverlay_arrow_position is a marker, last-arrow-position is its
451 numerical position. */
453 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
455 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
456 properties on a symbol in overlay-arrow-variable-list. */
458 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
460 /* Like mode-line-format, but for the title bar on a visible frame. */
462 Lisp_Object Vframe_title_format
;
464 /* Like mode-line-format, but for the title bar on an iconified frame. */
466 Lisp_Object Vicon_title_format
;
468 /* List of functions to call when a window's size changes. These
469 functions get one arg, a frame on which one or more windows' sizes
472 static Lisp_Object Vwindow_size_change_functions
;
474 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
476 /* Nonzero if an overlay arrow has been displayed in this window. */
478 static int overlay_arrow_seen
;
480 /* Nonzero means highlight the region even in nonselected windows. */
482 int highlight_nonselected_windows
;
484 /* If cursor motion alone moves point off frame, try scrolling this
485 many lines up or down if that will bring it back. */
487 static EMACS_INT scroll_step
;
489 /* Nonzero means scroll just far enough to bring point back on the
490 screen, when appropriate. */
492 static EMACS_INT scroll_conservatively
;
494 /* Recenter the window whenever point gets within this many lines of
495 the top or bottom of the window. This value is translated into a
496 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
497 that there is really a fixed pixel height scroll margin. */
499 EMACS_INT scroll_margin
;
501 /* Number of windows showing the buffer of the selected window (or
502 another buffer with the same base buffer). keyboard.c refers to
507 /* Vector containing glyphs for an ellipsis `...'. */
509 static Lisp_Object default_invis_vector
[3];
511 /* Zero means display the mode-line/header-line/menu-bar in the default face
512 (this slightly odd definition is for compatibility with previous versions
513 of emacs), non-zero means display them using their respective faces.
515 This variable is deprecated. */
517 int mode_line_inverse_video
;
519 /* Prompt to display in front of the mini-buffer contents. */
521 Lisp_Object minibuf_prompt
;
523 /* Width of current mini-buffer prompt. Only set after display_line
524 of the line that contains the prompt. */
526 int minibuf_prompt_width
;
528 /* This is the window where the echo area message was displayed. It
529 is always a mini-buffer window, but it may not be the same window
530 currently active as a mini-buffer. */
532 Lisp_Object echo_area_window
;
534 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
535 pushes the current message and the value of
536 message_enable_multibyte on the stack, the function restore_message
537 pops the stack and displays MESSAGE again. */
539 Lisp_Object Vmessage_stack
;
541 /* Nonzero means multibyte characters were enabled when the echo area
542 message was specified. */
544 int message_enable_multibyte
;
546 /* Nonzero if we should redraw the mode lines on the next redisplay. */
548 int update_mode_lines
;
550 /* Nonzero if window sizes or contents have changed since last
551 redisplay that finished. */
553 int windows_or_buffers_changed
;
555 /* Nonzero means a frame's cursor type has been changed. */
557 int cursor_type_changed
;
559 /* Nonzero after display_mode_line if %l was used and it displayed a
562 int line_number_displayed
;
564 /* Maximum buffer size for which to display line numbers. */
566 Lisp_Object Vline_number_display_limit
;
568 /* Line width to consider when repositioning for line number display. */
570 static EMACS_INT line_number_display_limit_width
;
572 /* Number of lines to keep in the message log buffer. t means
573 infinite. nil means don't log at all. */
575 Lisp_Object Vmessage_log_max
;
577 /* The name of the *Messages* buffer, a string. */
579 static Lisp_Object Vmessages_buffer_name
;
581 /* Index 0 is the buffer that holds the current (desired) echo area message,
582 or nil if none is desired right now.
584 Index 1 is the buffer that holds the previously displayed echo area message,
585 or nil to indicate no message. This is normally what's on the screen now.
587 These two can point to the same buffer. That happens when the last
588 message output by the user (or made by echoing) has been displayed. */
590 Lisp_Object echo_area_buffer
[2];
592 /* Permanent pointers to the two buffers that are used for echo area
593 purposes. Once the two buffers are made, and their pointers are
594 placed here, these two slots remain unchanged unless those buffers
595 need to be created afresh. */
597 static Lisp_Object echo_buffer
[2];
599 /* A vector saved used in with_area_buffer to reduce consing. */
601 static Lisp_Object Vwith_echo_area_save_vector
;
603 /* Non-zero means display_echo_area should display the last echo area
604 message again. Set by redisplay_preserve_echo_area. */
606 static int display_last_displayed_message_p
;
608 /* Nonzero if echo area is being used by print; zero if being used by
611 int message_buf_print
;
613 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
615 Lisp_Object Qinhibit_menubar_update
;
616 int inhibit_menubar_update
;
618 /* Maximum height for resizing mini-windows. Either a float
619 specifying a fraction of the available height, or an integer
620 specifying a number of lines. */
622 Lisp_Object Vmax_mini_window_height
;
624 /* Non-zero means messages should be displayed with truncated
625 lines instead of being continued. */
627 int message_truncate_lines
;
628 Lisp_Object Qmessage_truncate_lines
;
630 /* Set to 1 in clear_message to make redisplay_internal aware
631 of an emptied echo area. */
633 static int message_cleared_p
;
635 /* How to blink the default frame cursor off. */
636 Lisp_Object Vblink_cursor_alist
;
638 /* A scratch glyph row with contents used for generating truncation
639 glyphs. Also used in direct_output_for_insert. */
641 #define MAX_SCRATCH_GLYPHS 100
642 struct glyph_row scratch_glyph_row
;
643 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
645 /* Ascent and height of the last line processed by move_it_to. */
647 static int last_max_ascent
, last_height
;
649 /* Non-zero if there's a help-echo in the echo area. */
651 int help_echo_showing_p
;
653 /* If >= 0, computed, exact values of mode-line and header-line height
654 to use in the macros CURRENT_MODE_LINE_HEIGHT and
655 CURRENT_HEADER_LINE_HEIGHT. */
657 int current_mode_line_height
, current_header_line_height
;
659 /* The maximum distance to look ahead for text properties. Values
660 that are too small let us call compute_char_face and similar
661 functions too often which is expensive. Values that are too large
662 let us call compute_char_face and alike too often because we
663 might not be interested in text properties that far away. */
665 #define TEXT_PROP_DISTANCE_LIMIT 100
669 /* Variables to turn off display optimizations from Lisp. */
671 int inhibit_try_window_id
, inhibit_try_window_reusing
;
672 int inhibit_try_cursor_movement
;
674 /* Non-zero means print traces of redisplay if compiled with
677 int trace_redisplay_p
;
679 #endif /* GLYPH_DEBUG */
681 #ifdef DEBUG_TRACE_MOVE
682 /* Non-zero means trace with TRACE_MOVE to stderr. */
685 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
687 #define TRACE_MOVE(x) (void) 0
690 /* Non-zero means automatically scroll windows horizontally to make
693 int automatic_hscrolling_p
;
695 /* How close to the margin can point get before the window is scrolled
697 EMACS_INT hscroll_margin
;
699 /* How much to scroll horizontally when point is inside the above margin. */
700 Lisp_Object Vhscroll_step
;
702 /* The variable `resize-mini-windows'. If nil, don't resize
703 mini-windows. If t, always resize them to fit the text they
704 display. If `grow-only', let mini-windows grow only until they
707 Lisp_Object Vresize_mini_windows
;
709 /* Buffer being redisplayed -- for redisplay_window_error. */
711 struct buffer
*displayed_buffer
;
713 /* Value returned from text property handlers (see below). */
718 HANDLED_RECOMPUTE_PROPS
,
719 HANDLED_OVERLAY_STRING_CONSUMED
,
723 /* A description of text properties that redisplay is interested
728 /* The name of the property. */
731 /* A unique index for the property. */
734 /* A handler function called to set up iterator IT from the property
735 at IT's current position. Value is used to steer handle_stop. */
736 enum prop_handled (*handler
) P_ ((struct it
*it
));
739 static enum prop_handled handle_face_prop
P_ ((struct it
*));
740 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
741 static enum prop_handled handle_display_prop
P_ ((struct it
*));
742 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
743 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
744 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
746 /* Properties handled by iterators. */
748 static struct props it_props
[] =
750 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
751 /* Handle `face' before `display' because some sub-properties of
752 `display' need to know the face. */
753 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
754 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
755 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
756 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
760 /* Value is the position described by X. If X is a marker, value is
761 the marker_position of X. Otherwise, value is X. */
763 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
765 /* Enumeration returned by some move_it_.* functions internally. */
769 /* Not used. Undefined value. */
772 /* Move ended at the requested buffer position or ZV. */
773 MOVE_POS_MATCH_OR_ZV
,
775 /* Move ended at the requested X pixel position. */
778 /* Move within a line ended at the end of a line that must be
782 /* Move within a line ended at the end of a line that would
783 be displayed truncated. */
786 /* Move within a line ended at a line end. */
790 /* This counter is used to clear the face cache every once in a while
791 in redisplay_internal. It is incremented for each redisplay.
792 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
795 #define CLEAR_FACE_CACHE_COUNT 500
796 static int clear_face_cache_count
;
798 /* Similarly for the image cache. */
800 #ifdef HAVE_WINDOW_SYSTEM
801 #define CLEAR_IMAGE_CACHE_COUNT 101
802 static int clear_image_cache_count
;
805 /* Record the previous terminal frame we displayed. */
807 static struct frame
*previous_terminal_frame
;
809 /* Non-zero while redisplay_internal is in progress. */
813 /* Non-zero means don't free realized faces. Bound while freeing
814 realized faces is dangerous because glyph matrices might still
817 int inhibit_free_realized_faces
;
818 Lisp_Object Qinhibit_free_realized_faces
;
820 /* If a string, XTread_socket generates an event to display that string.
821 (The display is done in read_char.) */
823 Lisp_Object help_echo_string
;
824 Lisp_Object help_echo_window
;
825 Lisp_Object help_echo_object
;
828 /* Temporary variable for XTread_socket. */
830 Lisp_Object previous_help_echo_string
;
832 /* Null glyph slice */
834 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
837 /* Function prototypes. */
839 static void setup_for_ellipsis
P_ ((struct it
*, int));
840 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
841 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
842 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
843 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
844 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
845 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
848 static int invisible_text_between_p
P_ ((struct it
*, int, int));
851 static void pint2str
P_ ((char *, int, int));
852 static void pint2hrstr
P_ ((char *, int, int));
853 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
855 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
856 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
857 static void store_mode_line_noprop_char
P_ ((char));
858 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
859 static void x_consider_frame_title
P_ ((Lisp_Object
));
860 static void handle_stop
P_ ((struct it
*));
861 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
862 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
863 static void ensure_echo_area_buffers
P_ ((void));
864 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
865 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
866 static int with_echo_area_buffer
P_ ((struct window
*, int,
867 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
868 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
869 static void clear_garbaged_frames
P_ ((void));
870 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
871 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
872 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
873 static int display_echo_area
P_ ((struct window
*));
874 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
875 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
876 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
877 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
878 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
880 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
881 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
882 static void insert_left_trunc_glyphs
P_ ((struct it
*));
883 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
885 static void extend_face_to_end_of_line
P_ ((struct it
*));
886 static int append_space_for_newline
P_ ((struct it
*, int));
887 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
888 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
889 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
890 static int trailing_whitespace_p
P_ ((int));
891 static int message_log_check_duplicate
P_ ((int, int, int, int));
892 static void push_it
P_ ((struct it
*));
893 static void pop_it
P_ ((struct it
*));
894 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
895 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
896 static void redisplay_internal
P_ ((int));
897 static int echo_area_display
P_ ((int));
898 static void redisplay_windows
P_ ((Lisp_Object
));
899 static void redisplay_window
P_ ((Lisp_Object
, int));
900 static Lisp_Object
redisplay_window_error ();
901 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
902 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
903 static void update_menu_bar
P_ ((struct frame
*, int));
904 static int try_window_reusing_current_matrix
P_ ((struct window
*));
905 static int try_window_id
P_ ((struct window
*));
906 static int display_line
P_ ((struct it
*));
907 static int display_mode_lines
P_ ((struct window
*));
908 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
909 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
910 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
911 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
912 static void display_menu_bar
P_ ((struct window
*));
913 static int display_count_lines
P_ ((int, int, int, int, int *));
914 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
915 int, int, struct it
*, int, int, int, int));
916 static void compute_line_metrics
P_ ((struct it
*));
917 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
918 static int get_overlay_strings
P_ ((struct it
*, int));
919 static void next_overlay_string
P_ ((struct it
*));
920 static void reseat
P_ ((struct it
*, struct text_pos
, int));
921 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
922 static void back_to_previous_visible_line_start
P_ ((struct it
*));
923 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
924 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
925 static int next_element_from_ellipsis
P_ ((struct it
*));
926 static int next_element_from_display_vector
P_ ((struct it
*));
927 static int next_element_from_string
P_ ((struct it
*));
928 static int next_element_from_c_string
P_ ((struct it
*));
929 static int next_element_from_buffer
P_ ((struct it
*));
930 static int next_element_from_composition
P_ ((struct it
*));
931 static int next_element_from_image
P_ ((struct it
*));
932 static int next_element_from_stretch
P_ ((struct it
*));
933 static void load_overlay_strings
P_ ((struct it
*, int));
934 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
935 struct display_pos
*));
936 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
937 Lisp_Object
, int, int, int, int));
938 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
940 void move_it_vertically_backward
P_ ((struct it
*, int));
941 static void init_to_row_start
P_ ((struct it
*, struct window
*,
942 struct glyph_row
*));
943 static int init_to_row_end
P_ ((struct it
*, struct window
*,
944 struct glyph_row
*));
945 static void back_to_previous_line_start
P_ ((struct it
*));
946 static int forward_to_next_line_start
P_ ((struct it
*, int *));
947 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
949 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
950 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
951 static int number_of_chars
P_ ((unsigned char *, int));
952 static void compute_stop_pos
P_ ((struct it
*));
953 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
955 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
956 static int next_overlay_change
P_ ((int));
957 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
958 Lisp_Object
, struct text_pos
*,
960 static int underlying_face_id
P_ ((struct it
*));
961 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
964 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
965 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
967 #ifdef HAVE_WINDOW_SYSTEM
969 static void update_tool_bar
P_ ((struct frame
*, int));
970 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
971 static int redisplay_tool_bar
P_ ((struct frame
*));
972 static void display_tool_bar_line
P_ ((struct it
*, int));
973 static void notice_overwritten_cursor
P_ ((struct window
*,
975 int, int, int, int));
979 #endif /* HAVE_WINDOW_SYSTEM */
982 /***********************************************************************
983 Window display dimensions
984 ***********************************************************************/
986 /* Return the bottom boundary y-position for text lines in window W.
987 This is the first y position at which a line cannot start.
988 It is relative to the top of the window.
990 This is the height of W minus the height of a mode line, if any. */
993 window_text_bottom_y (w
)
996 int height
= WINDOW_TOTAL_HEIGHT (w
);
998 if (WINDOW_WANTS_MODELINE_P (w
))
999 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1003 /* Return the pixel width of display area AREA of window W. AREA < 0
1004 means return the total width of W, not including fringes to
1005 the left and right of the window. */
1008 window_box_width (w
, area
)
1012 int cols
= XFASTINT (w
->total_cols
);
1015 if (!w
->pseudo_window_p
)
1017 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1019 if (area
== TEXT_AREA
)
1021 if (INTEGERP (w
->left_margin_cols
))
1022 cols
-= XFASTINT (w
->left_margin_cols
);
1023 if (INTEGERP (w
->right_margin_cols
))
1024 cols
-= XFASTINT (w
->right_margin_cols
);
1025 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1027 else if (area
== LEFT_MARGIN_AREA
)
1029 cols
= (INTEGERP (w
->left_margin_cols
)
1030 ? XFASTINT (w
->left_margin_cols
) : 0);
1033 else if (area
== RIGHT_MARGIN_AREA
)
1035 cols
= (INTEGERP (w
->right_margin_cols
)
1036 ? XFASTINT (w
->right_margin_cols
) : 0);
1041 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1045 /* Return the pixel height of the display area of window W, not
1046 including mode lines of W, if any. */
1049 window_box_height (w
)
1052 struct frame
*f
= XFRAME (w
->frame
);
1053 int height
= WINDOW_TOTAL_HEIGHT (w
);
1055 xassert (height
>= 0);
1057 /* Note: the code below that determines the mode-line/header-line
1058 height is essentially the same as that contained in the macro
1059 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1060 the appropriate glyph row has its `mode_line_p' flag set,
1061 and if it doesn't, uses estimate_mode_line_height instead. */
1063 if (WINDOW_WANTS_MODELINE_P (w
))
1065 struct glyph_row
*ml_row
1066 = (w
->current_matrix
&& w
->current_matrix
->rows
1067 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1069 if (ml_row
&& ml_row
->mode_line_p
)
1070 height
-= ml_row
->height
;
1072 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1075 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1077 struct glyph_row
*hl_row
1078 = (w
->current_matrix
&& w
->current_matrix
->rows
1079 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1081 if (hl_row
&& hl_row
->mode_line_p
)
1082 height
-= hl_row
->height
;
1084 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1087 /* With a very small font and a mode-line that's taller than
1088 default, we might end up with a negative height. */
1089 return max (0, height
);
1092 /* Return the window-relative coordinate of the left edge of display
1093 area AREA of window W. AREA < 0 means return the left edge of the
1094 whole window, to the right of the left fringe of W. */
1097 window_box_left_offset (w
, area
)
1103 if (w
->pseudo_window_p
)
1106 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1108 if (area
== TEXT_AREA
)
1109 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1110 + window_box_width (w
, LEFT_MARGIN_AREA
));
1111 else if (area
== RIGHT_MARGIN_AREA
)
1112 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1113 + window_box_width (w
, LEFT_MARGIN_AREA
)
1114 + window_box_width (w
, TEXT_AREA
)
1115 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1117 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1118 else if (area
== LEFT_MARGIN_AREA
1119 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1120 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1126 /* Return the window-relative coordinate of the right edge of display
1127 area AREA of window W. AREA < 0 means return the left edge of the
1128 whole window, to the left of the right fringe of W. */
1131 window_box_right_offset (w
, area
)
1135 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1138 /* Return the frame-relative coordinate of the left edge of display
1139 area AREA of window W. AREA < 0 means return the left edge of the
1140 whole window, to the right of the left fringe of W. */
1143 window_box_left (w
, area
)
1147 struct frame
*f
= XFRAME (w
->frame
);
1150 if (w
->pseudo_window_p
)
1151 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1153 x
= (WINDOW_LEFT_EDGE_X (w
)
1154 + window_box_left_offset (w
, area
));
1160 /* Return the frame-relative coordinate of the right edge of display
1161 area AREA of window W. AREA < 0 means return the left edge of the
1162 whole window, to the left of the right fringe of W. */
1165 window_box_right (w
, area
)
1169 return window_box_left (w
, area
) + window_box_width (w
, area
);
1172 /* Get the bounding box of the display area AREA of window W, without
1173 mode lines, in frame-relative coordinates. AREA < 0 means the
1174 whole window, not including the left and right fringes of
1175 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1176 coordinates of the upper-left corner of the box. Return in
1177 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1180 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1183 int *box_x
, *box_y
, *box_width
, *box_height
;
1186 *box_width
= window_box_width (w
, area
);
1188 *box_height
= window_box_height (w
);
1190 *box_x
= window_box_left (w
, area
);
1193 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1194 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1195 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1200 /* Get the bounding box of the display area AREA of window W, without
1201 mode lines. AREA < 0 means the whole window, not including the
1202 left and right fringe of the window. Return in *TOP_LEFT_X
1203 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1204 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1205 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1209 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1210 bottom_right_x
, bottom_right_y
)
1213 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1215 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1217 *bottom_right_x
+= *top_left_x
;
1218 *bottom_right_y
+= *top_left_y
;
1223 /***********************************************************************
1225 ***********************************************************************/
1227 /* Return the bottom y-position of the line the iterator IT is in.
1228 This can modify IT's settings. */
1234 int line_height
= it
->max_ascent
+ it
->max_descent
;
1235 int line_top_y
= it
->current_y
;
1237 if (line_height
== 0)
1240 line_height
= last_height
;
1241 else if (IT_CHARPOS (*it
) < ZV
)
1243 move_it_by_lines (it
, 1, 1);
1244 line_height
= (it
->max_ascent
|| it
->max_descent
1245 ? it
->max_ascent
+ it
->max_descent
1250 struct glyph_row
*row
= it
->glyph_row
;
1252 /* Use the default character height. */
1253 it
->glyph_row
= NULL
;
1254 it
->what
= IT_CHARACTER
;
1257 PRODUCE_GLYPHS (it
);
1258 line_height
= it
->ascent
+ it
->descent
;
1259 it
->glyph_row
= row
;
1263 return line_top_y
+ line_height
;
1267 /* Return 1 if position CHARPOS is visible in window W.
1268 If visible, set *X and *Y to pixel coordinates of top left corner.
1269 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1270 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1271 and header-lines heights. */
1274 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1276 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1279 struct text_pos top
;
1281 struct buffer
*old_buffer
= NULL
;
1286 if (XBUFFER (w
->buffer
) != current_buffer
)
1288 old_buffer
= current_buffer
;
1289 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1292 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1294 /* Compute exact mode line heights, if requested. */
1295 if (exact_mode_line_heights_p
)
1297 if (WINDOW_WANTS_MODELINE_P (w
))
1298 current_mode_line_height
1299 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1300 current_buffer
->mode_line_format
);
1302 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1303 current_header_line_height
1304 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1305 current_buffer
->header_line_format
);
1308 start_display (&it
, w
, top
);
1309 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1310 MOVE_TO_POS
| MOVE_TO_Y
);
1312 /* Note that we may overshoot because of invisible text. */
1313 if (IT_CHARPOS (it
) >= charpos
)
1315 int top_x
= it
.current_x
;
1316 int top_y
= it
.current_y
;
1317 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1318 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1320 if (top_y
< window_top_y
)
1321 visible_p
= bottom_y
> window_top_y
;
1322 else if (top_y
< it
.last_visible_y
)
1327 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1328 *rtop
= max (0, window_top_y
- top_y
);
1329 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1337 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1338 move_it_by_lines (&it
, 1, 0);
1339 if (charpos
< IT_CHARPOS (it
))
1342 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1344 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1345 *rtop
= max (0, -it2
.current_y
);
1346 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1347 - it
.last_visible_y
));
1352 set_buffer_internal_1 (old_buffer
);
1354 current_header_line_height
= current_mode_line_height
= -1;
1356 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1357 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1363 /* Return the next character from STR which is MAXLEN bytes long.
1364 Return in *LEN the length of the character. This is like
1365 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1366 we find one, we return a `?', but with the length of the invalid
1370 string_char_and_length (str
, maxlen
, len
)
1371 const unsigned char *str
;
1376 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1377 if (!CHAR_VALID_P (c
, 1))
1378 /* We may not change the length here because other places in Emacs
1379 don't use this function, i.e. they silently accept invalid
1388 /* Given a position POS containing a valid character and byte position
1389 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1391 static struct text_pos
1392 string_pos_nchars_ahead (pos
, string
, nchars
)
1393 struct text_pos pos
;
1397 xassert (STRINGP (string
) && nchars
>= 0);
1399 if (STRING_MULTIBYTE (string
))
1401 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1402 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1407 string_char_and_length (p
, rest
, &len
);
1408 p
+= len
, rest
-= len
;
1409 xassert (rest
>= 0);
1411 BYTEPOS (pos
) += len
;
1415 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1421 /* Value is the text position, i.e. character and byte position,
1422 for character position CHARPOS in STRING. */
1424 static INLINE
struct text_pos
1425 string_pos (charpos
, string
)
1429 struct text_pos pos
;
1430 xassert (STRINGP (string
));
1431 xassert (charpos
>= 0);
1432 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1437 /* Value is a text position, i.e. character and byte position, for
1438 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1439 means recognize multibyte characters. */
1441 static struct text_pos
1442 c_string_pos (charpos
, s
, multibyte_p
)
1447 struct text_pos pos
;
1449 xassert (s
!= NULL
);
1450 xassert (charpos
>= 0);
1454 int rest
= strlen (s
), len
;
1456 SET_TEXT_POS (pos
, 0, 0);
1459 string_char_and_length (s
, rest
, &len
);
1460 s
+= len
, rest
-= len
;
1461 xassert (rest
>= 0);
1463 BYTEPOS (pos
) += len
;
1467 SET_TEXT_POS (pos
, charpos
, charpos
);
1473 /* Value is the number of characters in C string S. MULTIBYTE_P
1474 non-zero means recognize multibyte characters. */
1477 number_of_chars (s
, multibyte_p
)
1485 int rest
= strlen (s
), len
;
1486 unsigned char *p
= (unsigned char *) s
;
1488 for (nchars
= 0; rest
> 0; ++nchars
)
1490 string_char_and_length (p
, rest
, &len
);
1491 rest
-= len
, p
+= len
;
1495 nchars
= strlen (s
);
1501 /* Compute byte position NEWPOS->bytepos corresponding to
1502 NEWPOS->charpos. POS is a known position in string STRING.
1503 NEWPOS->charpos must be >= POS.charpos. */
1506 compute_string_pos (newpos
, pos
, string
)
1507 struct text_pos
*newpos
, pos
;
1510 xassert (STRINGP (string
));
1511 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1513 if (STRING_MULTIBYTE (string
))
1514 *newpos
= string_pos_nchars_ahead (pos
, string
,
1515 CHARPOS (*newpos
) - CHARPOS (pos
));
1517 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1521 Return an estimation of the pixel height of mode or top lines on
1522 frame F. FACE_ID specifies what line's height to estimate. */
1525 estimate_mode_line_height (f
, face_id
)
1527 enum face_id face_id
;
1529 #ifdef HAVE_WINDOW_SYSTEM
1530 if (FRAME_WINDOW_P (f
))
1532 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1534 /* This function is called so early when Emacs starts that the face
1535 cache and mode line face are not yet initialized. */
1536 if (FRAME_FACE_CACHE (f
))
1538 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1542 height
= FONT_HEIGHT (face
->font
);
1543 if (face
->box_line_width
> 0)
1544 height
+= 2 * face
->box_line_width
;
1555 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1556 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1557 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1558 not force the value into range. */
1561 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1563 register int pix_x
, pix_y
;
1565 NativeRectangle
*bounds
;
1569 #ifdef HAVE_WINDOW_SYSTEM
1570 if (FRAME_WINDOW_P (f
))
1572 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1573 even for negative values. */
1575 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1577 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1579 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1580 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1583 STORE_NATIVE_RECT (*bounds
,
1584 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1585 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1586 FRAME_COLUMN_WIDTH (f
) - 1,
1587 FRAME_LINE_HEIGHT (f
) - 1);
1593 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1594 pix_x
= FRAME_TOTAL_COLS (f
);
1598 else if (pix_y
> FRAME_LINES (f
))
1599 pix_y
= FRAME_LINES (f
);
1609 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1610 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1611 can't tell the positions because W's display is not up to date,
1615 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1618 int *frame_x
, *frame_y
;
1620 #ifdef HAVE_WINDOW_SYSTEM
1621 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1625 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1626 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1628 if (display_completed
)
1630 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1631 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1632 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1638 hpos
+= glyph
->pixel_width
;
1642 /* If first glyph is partially visible, its first visible position is still 0. */
1654 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1655 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1666 #ifdef HAVE_WINDOW_SYSTEM
1668 /* Find the glyph under window-relative coordinates X/Y in window W.
1669 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1670 strings. Return in *HPOS and *VPOS the row and column number of
1671 the glyph found. Return in *AREA the glyph area containing X.
1672 Value is a pointer to the glyph found or null if X/Y is not on
1673 text, or we can't tell because W's current matrix is not up to
1676 static struct glyph
*
1677 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1680 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1682 struct glyph
*glyph
, *end
;
1683 struct glyph_row
*row
= NULL
;
1686 /* Find row containing Y. Give up if some row is not enabled. */
1687 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1689 row
= MATRIX_ROW (w
->current_matrix
, i
);
1690 if (!row
->enabled_p
)
1692 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1699 /* Give up if Y is not in the window. */
1700 if (i
== w
->current_matrix
->nrows
)
1703 /* Get the glyph area containing X. */
1704 if (w
->pseudo_window_p
)
1711 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1713 *area
= LEFT_MARGIN_AREA
;
1714 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1716 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1719 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1723 *area
= RIGHT_MARGIN_AREA
;
1724 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1728 /* Find glyph containing X. */
1729 glyph
= row
->glyphs
[*area
];
1730 end
= glyph
+ row
->used
[*area
];
1732 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1734 x
-= glyph
->pixel_width
;
1744 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1747 *hpos
= glyph
- row
->glyphs
[*area
];
1753 Convert frame-relative x/y to coordinates relative to window W.
1754 Takes pseudo-windows into account. */
1757 frame_to_window_pixel_xy (w
, x
, y
)
1761 if (w
->pseudo_window_p
)
1763 /* A pseudo-window is always full-width, and starts at the
1764 left edge of the frame, plus a frame border. */
1765 struct frame
*f
= XFRAME (w
->frame
);
1766 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1767 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1771 *x
-= WINDOW_LEFT_EDGE_X (w
);
1772 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1777 Return in RECTS[] at most N clipping rectangles for glyph string S.
1778 Return the number of stored rectangles. */
1781 get_glyph_string_clip_rects (s
, rects
, n
)
1782 struct glyph_string
*s
;
1783 NativeRectangle
*rects
;
1791 if (s
->row
->full_width_p
)
1793 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1794 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1795 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1797 /* Unless displaying a mode or menu bar line, which are always
1798 fully visible, clip to the visible part of the row. */
1799 if (s
->w
->pseudo_window_p
)
1800 r
.height
= s
->row
->visible_height
;
1802 r
.height
= s
->height
;
1806 /* This is a text line that may be partially visible. */
1807 r
.x
= window_box_left (s
->w
, s
->area
);
1808 r
.width
= window_box_width (s
->w
, s
->area
);
1809 r
.height
= s
->row
->visible_height
;
1813 if (r
.x
< s
->clip_head
->x
)
1815 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1816 r
.width
-= s
->clip_head
->x
- r
.x
;
1819 r
.x
= s
->clip_head
->x
;
1822 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1824 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1825 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1830 /* If S draws overlapping rows, it's sufficient to use the top and
1831 bottom of the window for clipping because this glyph string
1832 intentionally draws over other lines. */
1833 if (s
->for_overlaps
)
1835 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1836 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1838 /* Alas, the above simple strategy does not work for the
1839 environments with anti-aliased text: if the same text is
1840 drawn onto the same place multiple times, it gets thicker.
1841 If the overlap we are processing is for the erased cursor, we
1842 take the intersection with the rectagle of the cursor. */
1843 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1845 XRectangle rc
, r_save
= r
;
1847 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1848 rc
.y
= s
->w
->phys_cursor
.y
;
1849 rc
.width
= s
->w
->phys_cursor_width
;
1850 rc
.height
= s
->w
->phys_cursor_height
;
1852 x_intersect_rectangles (&r_save
, &rc
, &r
);
1857 /* Don't use S->y for clipping because it doesn't take partially
1858 visible lines into account. For example, it can be negative for
1859 partially visible lines at the top of a window. */
1860 if (!s
->row
->full_width_p
1861 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1862 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1864 r
.y
= max (0, s
->row
->y
);
1866 /* If drawing a tool-bar window, draw it over the internal border
1867 at the top of the window. */
1868 if (WINDOWP (s
->f
->tool_bar_window
)
1869 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1870 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1873 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1875 /* If drawing the cursor, don't let glyph draw outside its
1876 advertised boundaries. Cleartype does this under some circumstances. */
1877 if (s
->hl
== DRAW_CURSOR
)
1879 struct glyph
*glyph
= s
->first_glyph
;
1884 r
.width
-= s
->x
- r
.x
;
1887 r
.width
= min (r
.width
, glyph
->pixel_width
);
1889 /* If r.y is below window bottom, ensure that we still see a cursor. */
1890 height
= min (glyph
->ascent
+ glyph
->descent
,
1891 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1892 max_y
= window_text_bottom_y (s
->w
) - height
;
1893 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1894 if (s
->ybase
- glyph
->ascent
> max_y
)
1901 /* Don't draw cursor glyph taller than our actual glyph. */
1902 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1903 if (height
< r
.height
)
1905 max_y
= r
.y
+ r
.height
;
1906 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1907 r
.height
= min (max_y
- r
.y
, height
);
1912 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1913 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1915 #ifdef CONVERT_FROM_XRECT
1916 CONVERT_FROM_XRECT (r
, *rects
);
1924 /* If we are processing overlapping and allowed to return
1925 multiple clipping rectangles, we exclude the row of the glyph
1926 string from the clipping rectangle. This is to avoid drawing
1927 the same text on the environment with anti-aliasing. */
1928 #ifdef CONVERT_FROM_XRECT
1931 XRectangle
*rs
= rects
;
1933 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1935 if (s
->for_overlaps
& OVERLAPS_PRED
)
1938 if (r
.y
+ r
.height
> row_y
)
1941 rs
[i
].height
= row_y
- r
.y
;
1947 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1950 if (r
.y
< row_y
+ s
->row
->visible_height
)
1952 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1954 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1955 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1964 #ifdef CONVERT_FROM_XRECT
1965 for (i
= 0; i
< n
; i
++)
1966 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1973 Return in *NR the clipping rectangle for glyph string S. */
1976 get_glyph_string_clip_rect (s
, nr
)
1977 struct glyph_string
*s
;
1978 NativeRectangle
*nr
;
1980 get_glyph_string_clip_rects (s
, nr
, 1);
1985 Return the position and height of the phys cursor in window W.
1986 Set w->phys_cursor_width to width of phys cursor.
1990 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1992 struct glyph_row
*row
;
1993 struct glyph
*glyph
;
1996 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1997 int y
, wd
, h
, h0
, y0
;
1999 /* Compute the width of the rectangle to draw. If on a stretch
2000 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2001 rectangle as wide as the glyph, but use a canonical character
2003 wd
= glyph
->pixel_width
- 1;
2007 if (glyph
->type
== STRETCH_GLYPH
2008 && !x_stretch_cursor_p
)
2009 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2010 w
->phys_cursor_width
= wd
;
2012 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2014 /* If y is below window bottom, ensure that we still see a cursor. */
2015 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2017 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2018 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2020 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2023 h
= max (h
- (y0
- y
) + 1, h0
);
2028 y0
= window_text_bottom_y (w
) - h0
;
2037 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2041 * Remember which glyph the mouse is over.
2045 remember_mouse_glyph (f
, gx
, gy
, rect
)
2048 NativeRectangle
*rect
;
2052 struct glyph_row
*r
, *gr
, *end_row
;
2053 enum window_part part
;
2054 enum glyph_row_area area
;
2055 int x
, y
, width
, height
;
2057 /* Try to determine frame pixel position and size of the glyph under
2058 frame pixel coordinates X/Y on frame F. */
2060 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2063 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2064 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2068 w
= XWINDOW (window
);
2069 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2070 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2072 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2073 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2075 if (w
->pseudo_window_p
)
2078 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2084 case ON_LEFT_MARGIN
:
2085 area
= LEFT_MARGIN_AREA
;
2088 case ON_RIGHT_MARGIN
:
2089 area
= RIGHT_MARGIN_AREA
;
2092 case ON_HEADER_LINE
:
2094 gr
= (part
== ON_HEADER_LINE
2095 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2096 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2099 goto text_glyph_row_found
;
2106 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2107 if (r
->y
+ r
->height
> y
)
2113 text_glyph_row_found
:
2116 struct glyph
*g
= gr
->glyphs
[area
];
2117 struct glyph
*end
= g
+ gr
->used
[area
];
2119 height
= gr
->height
;
2120 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2121 if (gx
+ g
->pixel_width
> x
)
2126 if (g
->type
== IMAGE_GLYPH
)
2128 /* Don't remember when mouse is over image, as
2129 image may have hot-spots. */
2130 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2133 width
= g
->pixel_width
;
2137 /* Use nominal char spacing at end of line. */
2139 gx
+= (x
/ width
) * width
;
2142 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2143 gx
+= window_box_left_offset (w
, area
);
2147 /* Use nominal line height at end of window. */
2148 gx
= (x
/ width
) * width
;
2150 gy
+= (y
/ height
) * height
;
2154 case ON_LEFT_FRINGE
:
2155 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2156 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2157 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2158 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2161 case ON_RIGHT_FRINGE
:
2162 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2163 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2164 : window_box_right_offset (w
, TEXT_AREA
));
2165 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2169 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2171 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2172 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2173 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2175 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2179 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2180 if (r
->y
+ r
->height
> y
)
2187 height
= gr
->height
;
2190 /* Use nominal line height at end of window. */
2192 gy
+= (y
/ height
) * height
;
2199 /* If there is no glyph under the mouse, then we divide the screen
2200 into a grid of the smallest glyph in the frame, and use that
2203 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2204 round down even for negative values. */
2210 gx
= (gx
/ width
) * width
;
2211 gy
= (gy
/ height
) * height
;
2216 gx
+= WINDOW_LEFT_EDGE_X (w
);
2217 gy
+= WINDOW_TOP_EDGE_Y (w
);
2220 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2222 /* Visible feedback for debugging. */
2225 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2226 f
->output_data
.x
->normal_gc
,
2227 gx
, gy
, width
, height
);
2233 #endif /* HAVE_WINDOW_SYSTEM */
2236 /***********************************************************************
2237 Lisp form evaluation
2238 ***********************************************************************/
2240 /* Error handler for safe_eval and safe_call. */
2243 safe_eval_handler (arg
)
2246 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2251 /* Evaluate SEXPR and return the result, or nil if something went
2252 wrong. Prevent redisplay during the evaluation. */
2260 if (inhibit_eval_during_redisplay
)
2264 int count
= SPECPDL_INDEX ();
2265 struct gcpro gcpro1
;
2268 specbind (Qinhibit_redisplay
, Qt
);
2269 /* Use Qt to ensure debugger does not run,
2270 so there is no possibility of wanting to redisplay. */
2271 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2274 val
= unbind_to (count
, val
);
2281 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2282 Return the result, or nil if something went wrong. Prevent
2283 redisplay during the evaluation. */
2286 safe_call (nargs
, args
)
2292 if (inhibit_eval_during_redisplay
)
2296 int count
= SPECPDL_INDEX ();
2297 struct gcpro gcpro1
;
2300 gcpro1
.nvars
= nargs
;
2301 specbind (Qinhibit_redisplay
, Qt
);
2302 /* Use Qt to ensure debugger does not run,
2303 so there is no possibility of wanting to redisplay. */
2304 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2307 val
= unbind_to (count
, val
);
2314 /* Call function FN with one argument ARG.
2315 Return the result, or nil if something went wrong. */
2318 safe_call1 (fn
, arg
)
2319 Lisp_Object fn
, arg
;
2321 Lisp_Object args
[2];
2324 return safe_call (2, args
);
2329 /***********************************************************************
2331 ***********************************************************************/
2335 /* Define CHECK_IT to perform sanity checks on iterators.
2336 This is for debugging. It is too slow to do unconditionally. */
2342 if (it
->method
== GET_FROM_STRING
)
2344 xassert (STRINGP (it
->string
));
2345 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2349 xassert (IT_STRING_CHARPOS (*it
) < 0);
2350 if (it
->method
== GET_FROM_BUFFER
)
2352 /* Check that character and byte positions agree. */
2353 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2358 xassert (it
->current
.dpvec_index
>= 0);
2360 xassert (it
->current
.dpvec_index
< 0);
2363 #define CHECK_IT(IT) check_it ((IT))
2367 #define CHECK_IT(IT) (void) 0
2374 /* Check that the window end of window W is what we expect it
2375 to be---the last row in the current matrix displaying text. */
2378 check_window_end (w
)
2381 if (!MINI_WINDOW_P (w
)
2382 && !NILP (w
->window_end_valid
))
2384 struct glyph_row
*row
;
2385 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2386 XFASTINT (w
->window_end_vpos
)),
2388 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2389 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2393 #define CHECK_WINDOW_END(W) check_window_end ((W))
2395 #else /* not GLYPH_DEBUG */
2397 #define CHECK_WINDOW_END(W) (void) 0
2399 #endif /* not GLYPH_DEBUG */
2403 /***********************************************************************
2404 Iterator initialization
2405 ***********************************************************************/
2407 /* Initialize IT for displaying current_buffer in window W, starting
2408 at character position CHARPOS. CHARPOS < 0 means that no buffer
2409 position is specified which is useful when the iterator is assigned
2410 a position later. BYTEPOS is the byte position corresponding to
2411 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2413 If ROW is not null, calls to produce_glyphs with IT as parameter
2414 will produce glyphs in that row.
2416 BASE_FACE_ID is the id of a base face to use. It must be one of
2417 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2418 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2419 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2421 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2422 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2423 will be initialized to use the corresponding mode line glyph row of
2424 the desired matrix of W. */
2427 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2430 int charpos
, bytepos
;
2431 struct glyph_row
*row
;
2432 enum face_id base_face_id
;
2434 int highlight_region_p
;
2436 /* Some precondition checks. */
2437 xassert (w
!= NULL
&& it
!= NULL
);
2438 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2441 /* If face attributes have been changed since the last redisplay,
2442 free realized faces now because they depend on face definitions
2443 that might have changed. Don't free faces while there might be
2444 desired matrices pending which reference these faces. */
2445 if (face_change_count
&& !inhibit_free_realized_faces
)
2447 face_change_count
= 0;
2448 free_all_realized_faces (Qnil
);
2451 /* Use one of the mode line rows of W's desired matrix if
2455 if (base_face_id
== MODE_LINE_FACE_ID
2456 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2457 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2458 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2459 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2463 bzero (it
, sizeof *it
);
2464 it
->current
.overlay_string_index
= -1;
2465 it
->current
.dpvec_index
= -1;
2466 it
->base_face_id
= base_face_id
;
2468 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2470 /* The window in which we iterate over current_buffer: */
2471 XSETWINDOW (it
->window
, w
);
2473 it
->f
= XFRAME (w
->frame
);
2475 /* Extra space between lines (on window systems only). */
2476 if (base_face_id
== DEFAULT_FACE_ID
2477 && FRAME_WINDOW_P (it
->f
))
2479 if (NATNUMP (current_buffer
->extra_line_spacing
))
2480 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2481 else if (FLOATP (current_buffer
->extra_line_spacing
))
2482 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2483 * FRAME_LINE_HEIGHT (it
->f
));
2484 else if (it
->f
->extra_line_spacing
> 0)
2485 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2486 it
->max_extra_line_spacing
= 0;
2489 /* If realized faces have been removed, e.g. because of face
2490 attribute changes of named faces, recompute them. When running
2491 in batch mode, the face cache of Vterminal_frame is null. If
2492 we happen to get called, make a dummy face cache. */
2493 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2494 init_frame_faces (it
->f
);
2495 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2496 recompute_basic_faces (it
->f
);
2498 /* Current value of the `slice', `space-width', and 'height' properties. */
2499 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2500 it
->space_width
= Qnil
;
2501 it
->font_height
= Qnil
;
2502 it
->override_ascent
= -1;
2504 /* Are control characters displayed as `^C'? */
2505 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2507 /* -1 means everything between a CR and the following line end
2508 is invisible. >0 means lines indented more than this value are
2510 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2511 ? XFASTINT (current_buffer
->selective_display
)
2512 : (!NILP (current_buffer
->selective_display
)
2514 it
->selective_display_ellipsis_p
2515 = !NILP (current_buffer
->selective_display_ellipses
);
2517 /* Display table to use. */
2518 it
->dp
= window_display_table (w
);
2520 /* Are multibyte characters enabled in current_buffer? */
2521 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2523 /* Non-zero if we should highlight the region. */
2525 = (!NILP (Vtransient_mark_mode
)
2526 && !NILP (current_buffer
->mark_active
)
2527 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2529 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2530 start and end of a visible region in window IT->w. Set both to
2531 -1 to indicate no region. */
2532 if (highlight_region_p
2533 /* Maybe highlight only in selected window. */
2534 && (/* Either show region everywhere. */
2535 highlight_nonselected_windows
2536 /* Or show region in the selected window. */
2537 || w
== XWINDOW (selected_window
)
2538 /* Or show the region if we are in the mini-buffer and W is
2539 the window the mini-buffer refers to. */
2540 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2541 && WINDOWP (minibuf_selected_window
)
2542 && w
== XWINDOW (minibuf_selected_window
))))
2544 int charpos
= marker_position (current_buffer
->mark
);
2545 it
->region_beg_charpos
= min (PT
, charpos
);
2546 it
->region_end_charpos
= max (PT
, charpos
);
2549 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2551 /* Get the position at which the redisplay_end_trigger hook should
2552 be run, if it is to be run at all. */
2553 if (MARKERP (w
->redisplay_end_trigger
)
2554 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2555 it
->redisplay_end_trigger_charpos
2556 = marker_position (w
->redisplay_end_trigger
);
2557 else if (INTEGERP (w
->redisplay_end_trigger
))
2558 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2560 /* Correct bogus values of tab_width. */
2561 it
->tab_width
= XINT (current_buffer
->tab_width
);
2562 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2565 /* Are lines in the display truncated? */
2566 it
->truncate_lines_p
2567 = (base_face_id
!= DEFAULT_FACE_ID
2568 || XINT (it
->w
->hscroll
)
2569 || (truncate_partial_width_windows
2570 && !WINDOW_FULL_WIDTH_P (it
->w
))
2571 || !NILP (current_buffer
->truncate_lines
));
2573 /* Get dimensions of truncation and continuation glyphs. These are
2574 displayed as fringe bitmaps under X, so we don't need them for such
2576 if (!FRAME_WINDOW_P (it
->f
))
2578 if (it
->truncate_lines_p
)
2580 /* We will need the truncation glyph. */
2581 xassert (it
->glyph_row
== NULL
);
2582 produce_special_glyphs (it
, IT_TRUNCATION
);
2583 it
->truncation_pixel_width
= it
->pixel_width
;
2587 /* We will need the continuation glyph. */
2588 xassert (it
->glyph_row
== NULL
);
2589 produce_special_glyphs (it
, IT_CONTINUATION
);
2590 it
->continuation_pixel_width
= it
->pixel_width
;
2593 /* Reset these values to zero because the produce_special_glyphs
2594 above has changed them. */
2595 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2596 it
->phys_ascent
= it
->phys_descent
= 0;
2599 /* Set this after getting the dimensions of truncation and
2600 continuation glyphs, so that we don't produce glyphs when calling
2601 produce_special_glyphs, above. */
2602 it
->glyph_row
= row
;
2603 it
->area
= TEXT_AREA
;
2605 /* Get the dimensions of the display area. The display area
2606 consists of the visible window area plus a horizontally scrolled
2607 part to the left of the window. All x-values are relative to the
2608 start of this total display area. */
2609 if (base_face_id
!= DEFAULT_FACE_ID
)
2611 /* Mode lines, menu bar in terminal frames. */
2612 it
->first_visible_x
= 0;
2613 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2618 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2619 it
->last_visible_x
= (it
->first_visible_x
2620 + window_box_width (w
, TEXT_AREA
));
2622 /* If we truncate lines, leave room for the truncator glyph(s) at
2623 the right margin. Otherwise, leave room for the continuation
2624 glyph(s). Truncation and continuation glyphs are not inserted
2625 for window-based redisplay. */
2626 if (!FRAME_WINDOW_P (it
->f
))
2628 if (it
->truncate_lines_p
)
2629 it
->last_visible_x
-= it
->truncation_pixel_width
;
2631 it
->last_visible_x
-= it
->continuation_pixel_width
;
2634 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2635 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2638 /* Leave room for a border glyph. */
2639 if (!FRAME_WINDOW_P (it
->f
)
2640 && !WINDOW_RIGHTMOST_P (it
->w
))
2641 it
->last_visible_x
-= 1;
2643 it
->last_visible_y
= window_text_bottom_y (w
);
2645 /* For mode lines and alike, arrange for the first glyph having a
2646 left box line if the face specifies a box. */
2647 if (base_face_id
!= DEFAULT_FACE_ID
)
2651 it
->face_id
= base_face_id
;
2653 /* If we have a boxed mode line, make the first character appear
2654 with a left box line. */
2655 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2656 if (face
->box
!= FACE_NO_BOX
)
2657 it
->start_of_box_run_p
= 1;
2660 /* If a buffer position was specified, set the iterator there,
2661 getting overlays and face properties from that position. */
2662 if (charpos
>= BUF_BEG (current_buffer
))
2664 it
->end_charpos
= ZV
;
2666 IT_CHARPOS (*it
) = charpos
;
2668 /* Compute byte position if not specified. */
2669 if (bytepos
< charpos
)
2670 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2672 IT_BYTEPOS (*it
) = bytepos
;
2674 it
->start
= it
->current
;
2676 /* Compute faces etc. */
2677 reseat (it
, it
->current
.pos
, 1);
2684 /* Initialize IT for the display of window W with window start POS. */
2687 start_display (it
, w
, pos
)
2690 struct text_pos pos
;
2692 struct glyph_row
*row
;
2693 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2695 row
= w
->desired_matrix
->rows
+ first_vpos
;
2696 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2697 it
->first_vpos
= first_vpos
;
2699 /* Don't reseat to previous visible line start if current start
2700 position is in a string or image. */
2701 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2703 int start_at_line_beg_p
;
2704 int first_y
= it
->current_y
;
2706 /* If window start is not at a line start, skip forward to POS to
2707 get the correct continuation lines width. */
2708 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2709 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2710 if (!start_at_line_beg_p
)
2714 reseat_at_previous_visible_line_start (it
);
2715 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2717 new_x
= it
->current_x
+ it
->pixel_width
;
2719 /* If lines are continued, this line may end in the middle
2720 of a multi-glyph character (e.g. a control character
2721 displayed as \003, or in the middle of an overlay
2722 string). In this case move_it_to above will not have
2723 taken us to the start of the continuation line but to the
2724 end of the continued line. */
2725 if (it
->current_x
> 0
2726 && !it
->truncate_lines_p
/* Lines are continued. */
2727 && (/* And glyph doesn't fit on the line. */
2728 new_x
> it
->last_visible_x
2729 /* Or it fits exactly and we're on a window
2731 || (new_x
== it
->last_visible_x
2732 && FRAME_WINDOW_P (it
->f
))))
2734 if (it
->current
.dpvec_index
>= 0
2735 || it
->current
.overlay_string_index
>= 0)
2737 set_iterator_to_next (it
, 1);
2738 move_it_in_display_line_to (it
, -1, -1, 0);
2741 it
->continuation_lines_width
+= it
->current_x
;
2744 /* We're starting a new display line, not affected by the
2745 height of the continued line, so clear the appropriate
2746 fields in the iterator structure. */
2747 it
->max_ascent
= it
->max_descent
= 0;
2748 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2750 it
->current_y
= first_y
;
2752 it
->current_x
= it
->hpos
= 0;
2756 #if 0 /* Don't assert the following because start_display is sometimes
2757 called intentionally with a window start that is not at a
2758 line start. Please leave this code in as a comment. */
2760 /* Window start should be on a line start, now. */
2761 xassert (it
->continuation_lines_width
2762 || IT_CHARPOS (it
) == BEGV
2763 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2768 /* Return 1 if POS is a position in ellipses displayed for invisible
2769 text. W is the window we display, for text property lookup. */
2772 in_ellipses_for_invisible_text_p (pos
, w
)
2773 struct display_pos
*pos
;
2776 Lisp_Object prop
, window
;
2778 int charpos
= CHARPOS (pos
->pos
);
2780 /* If POS specifies a position in a display vector, this might
2781 be for an ellipsis displayed for invisible text. We won't
2782 get the iterator set up for delivering that ellipsis unless
2783 we make sure that it gets aware of the invisible text. */
2784 if (pos
->dpvec_index
>= 0
2785 && pos
->overlay_string_index
< 0
2786 && CHARPOS (pos
->string_pos
) < 0
2788 && (XSETWINDOW (window
, w
),
2789 prop
= Fget_char_property (make_number (charpos
),
2790 Qinvisible
, window
),
2791 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2793 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2795 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2802 /* Initialize IT for stepping through current_buffer in window W,
2803 starting at position POS that includes overlay string and display
2804 vector/ control character translation position information. Value
2805 is zero if there are overlay strings with newlines at POS. */
2808 init_from_display_pos (it
, w
, pos
)
2811 struct display_pos
*pos
;
2813 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2814 int i
, overlay_strings_with_newlines
= 0;
2816 /* If POS specifies a position in a display vector, this might
2817 be for an ellipsis displayed for invisible text. We won't
2818 get the iterator set up for delivering that ellipsis unless
2819 we make sure that it gets aware of the invisible text. */
2820 if (in_ellipses_for_invisible_text_p (pos
, w
))
2826 /* Keep in mind: the call to reseat in init_iterator skips invisible
2827 text, so we might end up at a position different from POS. This
2828 is only a problem when POS is a row start after a newline and an
2829 overlay starts there with an after-string, and the overlay has an
2830 invisible property. Since we don't skip invisible text in
2831 display_line and elsewhere immediately after consuming the
2832 newline before the row start, such a POS will not be in a string,
2833 but the call to init_iterator below will move us to the
2835 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2837 /* This only scans the current chunk -- it should scan all chunks.
2838 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2839 to 16 in 22.1 to make this a lesser problem. */
2840 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2842 const char *s
= SDATA (it
->overlay_strings
[i
]);
2843 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2845 while (s
< e
&& *s
!= '\n')
2850 overlay_strings_with_newlines
= 1;
2855 /* If position is within an overlay string, set up IT to the right
2857 if (pos
->overlay_string_index
>= 0)
2861 /* If the first overlay string happens to have a `display'
2862 property for an image, the iterator will be set up for that
2863 image, and we have to undo that setup first before we can
2864 correct the overlay string index. */
2865 if (it
->method
== GET_FROM_IMAGE
)
2868 /* We already have the first chunk of overlay strings in
2869 IT->overlay_strings. Load more until the one for
2870 pos->overlay_string_index is in IT->overlay_strings. */
2871 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2873 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2874 it
->current
.overlay_string_index
= 0;
2877 load_overlay_strings (it
, 0);
2878 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2882 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2883 relative_index
= (it
->current
.overlay_string_index
2884 % OVERLAY_STRING_CHUNK_SIZE
);
2885 it
->string
= it
->overlay_strings
[relative_index
];
2886 xassert (STRINGP (it
->string
));
2887 it
->current
.string_pos
= pos
->string_pos
;
2888 it
->method
= GET_FROM_STRING
;
2891 #if 0 /* This is bogus because POS not having an overlay string
2892 position does not mean it's after the string. Example: A
2893 line starting with a before-string and initialization of IT
2894 to the previous row's end position. */
2895 else if (it
->current
.overlay_string_index
>= 0)
2897 /* If POS says we're already after an overlay string ending at
2898 POS, make sure to pop the iterator because it will be in
2899 front of that overlay string. When POS is ZV, we've thereby
2900 also ``processed'' overlay strings at ZV. */
2903 it
->current
.overlay_string_index
= -1;
2904 it
->method
= GET_FROM_BUFFER
;
2905 if (CHARPOS (pos
->pos
) == ZV
)
2906 it
->overlay_strings_at_end_processed_p
= 1;
2910 if (CHARPOS (pos
->string_pos
) >= 0)
2912 /* Recorded position is not in an overlay string, but in another
2913 string. This can only be a string from a `display' property.
2914 IT should already be filled with that string. */
2915 it
->current
.string_pos
= pos
->string_pos
;
2916 xassert (STRINGP (it
->string
));
2919 /* Restore position in display vector translations, control
2920 character translations or ellipses. */
2921 if (pos
->dpvec_index
>= 0)
2923 if (it
->dpvec
== NULL
)
2924 get_next_display_element (it
);
2925 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2926 it
->current
.dpvec_index
= pos
->dpvec_index
;
2930 return !overlay_strings_with_newlines
;
2934 /* Initialize IT for stepping through current_buffer in window W
2935 starting at ROW->start. */
2938 init_to_row_start (it
, w
, row
)
2941 struct glyph_row
*row
;
2943 init_from_display_pos (it
, w
, &row
->start
);
2944 it
->start
= row
->start
;
2945 it
->continuation_lines_width
= row
->continuation_lines_width
;
2950 /* Initialize IT for stepping through current_buffer in window W
2951 starting in the line following ROW, i.e. starting at ROW->end.
2952 Value is zero if there are overlay strings with newlines at ROW's
2956 init_to_row_end (it
, w
, row
)
2959 struct glyph_row
*row
;
2963 if (init_from_display_pos (it
, w
, &row
->end
))
2965 if (row
->continued_p
)
2966 it
->continuation_lines_width
2967 = row
->continuation_lines_width
+ row
->pixel_width
;
2978 /***********************************************************************
2980 ***********************************************************************/
2982 /* Called when IT reaches IT->stop_charpos. Handle text property and
2983 overlay changes. Set IT->stop_charpos to the next position where
2990 enum prop_handled handled
;
2991 int handle_overlay_change_p
;
2995 it
->current
.dpvec_index
= -1;
2996 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2997 it
->ignore_overlay_strings_at_pos_p
= 0;
2999 /* Use face of preceding text for ellipsis (if invisible) */
3000 if (it
->selective_display_ellipsis_p
)
3001 it
->saved_face_id
= it
->face_id
;
3005 handled
= HANDLED_NORMALLY
;
3007 /* Call text property handlers. */
3008 for (p
= it_props
; p
->handler
; ++p
)
3010 handled
= p
->handler (it
);
3012 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3014 else if (handled
== HANDLED_RETURN
)
3016 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3017 handle_overlay_change_p
= 0;
3020 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3022 /* Don't check for overlay strings below when set to deliver
3023 characters from a display vector. */
3024 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3025 handle_overlay_change_p
= 0;
3027 /* Handle overlay changes. */
3028 if (handle_overlay_change_p
)
3029 handled
= handle_overlay_change (it
);
3031 /* Determine where to stop next. */
3032 if (handled
== HANDLED_NORMALLY
)
3033 compute_stop_pos (it
);
3036 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3040 /* Compute IT->stop_charpos from text property and overlay change
3041 information for IT's current position. */
3044 compute_stop_pos (it
)
3047 register INTERVAL iv
, next_iv
;
3048 Lisp_Object object
, limit
, position
;
3050 /* If nowhere else, stop at the end. */
3051 it
->stop_charpos
= it
->end_charpos
;
3053 if (STRINGP (it
->string
))
3055 /* Strings are usually short, so don't limit the search for
3057 object
= it
->string
;
3059 position
= make_number (IT_STRING_CHARPOS (*it
));
3065 /* If next overlay change is in front of the current stop pos
3066 (which is IT->end_charpos), stop there. Note: value of
3067 next_overlay_change is point-max if no overlay change
3069 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3070 if (charpos
< it
->stop_charpos
)
3071 it
->stop_charpos
= charpos
;
3073 /* If showing the region, we have to stop at the region
3074 start or end because the face might change there. */
3075 if (it
->region_beg_charpos
> 0)
3077 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3078 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3079 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3080 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3083 /* Set up variables for computing the stop position from text
3084 property changes. */
3085 XSETBUFFER (object
, current_buffer
);
3086 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3087 position
= make_number (IT_CHARPOS (*it
));
3091 /* Get the interval containing IT's position. Value is a null
3092 interval if there isn't such an interval. */
3093 iv
= validate_interval_range (object
, &position
, &position
, 0);
3094 if (!NULL_INTERVAL_P (iv
))
3096 Lisp_Object values_here
[LAST_PROP_IDX
];
3099 /* Get properties here. */
3100 for (p
= it_props
; p
->handler
; ++p
)
3101 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3103 /* Look for an interval following iv that has different
3105 for (next_iv
= next_interval (iv
);
3106 (!NULL_INTERVAL_P (next_iv
)
3108 || XFASTINT (limit
) > next_iv
->position
));
3109 next_iv
= next_interval (next_iv
))
3111 for (p
= it_props
; p
->handler
; ++p
)
3113 Lisp_Object new_value
;
3115 new_value
= textget (next_iv
->plist
, *p
->name
);
3116 if (!EQ (values_here
[p
->idx
], new_value
))
3124 if (!NULL_INTERVAL_P (next_iv
))
3126 if (INTEGERP (limit
)
3127 && next_iv
->position
>= XFASTINT (limit
))
3128 /* No text property change up to limit. */
3129 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3131 /* Text properties change in next_iv. */
3132 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3136 xassert (STRINGP (it
->string
)
3137 || (it
->stop_charpos
>= BEGV
3138 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3142 /* Return the position of the next overlay change after POS in
3143 current_buffer. Value is point-max if no overlay change
3144 follows. This is like `next-overlay-change' but doesn't use
3148 next_overlay_change (pos
)
3153 Lisp_Object
*overlays
;
3156 /* Get all overlays at the given position. */
3157 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3159 /* If any of these overlays ends before endpos,
3160 use its ending point instead. */
3161 for (i
= 0; i
< noverlays
; ++i
)
3166 oend
= OVERLAY_END (overlays
[i
]);
3167 oendpos
= OVERLAY_POSITION (oend
);
3168 endpos
= min (endpos
, oendpos
);
3176 /***********************************************************************
3178 ***********************************************************************/
3180 /* Handle changes in the `fontified' property of the current buffer by
3181 calling hook functions from Qfontification_functions to fontify
3184 static enum prop_handled
3185 handle_fontified_prop (it
)
3188 Lisp_Object prop
, pos
;
3189 enum prop_handled handled
= HANDLED_NORMALLY
;
3191 if (!NILP (Vmemory_full
))
3194 /* Get the value of the `fontified' property at IT's current buffer
3195 position. (The `fontified' property doesn't have a special
3196 meaning in strings.) If the value is nil, call functions from
3197 Qfontification_functions. */
3198 if (!STRINGP (it
->string
)
3200 && !NILP (Vfontification_functions
)
3201 && !NILP (Vrun_hooks
)
3202 && (pos
= make_number (IT_CHARPOS (*it
)),
3203 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3206 int count
= SPECPDL_INDEX ();
3209 val
= Vfontification_functions
;
3210 specbind (Qfontification_functions
, Qnil
);
3212 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3213 safe_call1 (val
, pos
);
3216 Lisp_Object globals
, fn
;
3217 struct gcpro gcpro1
, gcpro2
;
3220 GCPRO2 (val
, globals
);
3222 for (; CONSP (val
); val
= XCDR (val
))
3228 /* A value of t indicates this hook has a local
3229 binding; it means to run the global binding too.
3230 In a global value, t should not occur. If it
3231 does, we must ignore it to avoid an endless
3233 for (globals
= Fdefault_value (Qfontification_functions
);
3235 globals
= XCDR (globals
))
3237 fn
= XCAR (globals
);
3239 safe_call1 (fn
, pos
);
3243 safe_call1 (fn
, pos
);
3249 unbind_to (count
, Qnil
);
3251 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3252 something. This avoids an endless loop if they failed to
3253 fontify the text for which reason ever. */
3254 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3255 handled
= HANDLED_RECOMPUTE_PROPS
;
3263 /***********************************************************************
3265 ***********************************************************************/
3267 /* Set up iterator IT from face properties at its current position.
3268 Called from handle_stop. */
3270 static enum prop_handled
3271 handle_face_prop (it
)
3274 int new_face_id
, next_stop
;
3276 if (!STRINGP (it
->string
))
3279 = face_at_buffer_position (it
->w
,
3281 it
->region_beg_charpos
,
3282 it
->region_end_charpos
,
3285 + TEXT_PROP_DISTANCE_LIMIT
),
3288 /* Is this a start of a run of characters with box face?
3289 Caveat: this can be called for a freshly initialized
3290 iterator; face_id is -1 in this case. We know that the new
3291 face will not change until limit, i.e. if the new face has a
3292 box, all characters up to limit will have one. But, as
3293 usual, we don't know whether limit is really the end. */
3294 if (new_face_id
!= it
->face_id
)
3296 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3298 /* If new face has a box but old face has not, this is
3299 the start of a run of characters with box, i.e. it has
3300 a shadow on the left side. The value of face_id of the
3301 iterator will be -1 if this is the initial call that gets
3302 the face. In this case, we have to look in front of IT's
3303 position and see whether there is a face != new_face_id. */
3304 it
->start_of_box_run_p
3305 = (new_face
->box
!= FACE_NO_BOX
3306 && (it
->face_id
>= 0
3307 || IT_CHARPOS (*it
) == BEG
3308 || new_face_id
!= face_before_it_pos (it
)));
3309 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3314 int base_face_id
, bufpos
;
3316 if (it
->current
.overlay_string_index
>= 0)
3317 bufpos
= IT_CHARPOS (*it
);
3321 /* For strings from a buffer, i.e. overlay strings or strings
3322 from a `display' property, use the face at IT's current
3323 buffer position as the base face to merge with, so that
3324 overlay strings appear in the same face as surrounding
3325 text, unless they specify their own faces. */
3326 base_face_id
= underlying_face_id (it
);
3328 new_face_id
= face_at_string_position (it
->w
,
3330 IT_STRING_CHARPOS (*it
),
3332 it
->region_beg_charpos
,
3333 it
->region_end_charpos
,
3337 #if 0 /* This shouldn't be neccessary. Let's check it. */
3338 /* If IT is used to display a mode line we would really like to
3339 use the mode line face instead of the frame's default face. */
3340 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3341 && new_face_id
== DEFAULT_FACE_ID
)
3342 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3345 /* Is this a start of a run of characters with box? Caveat:
3346 this can be called for a freshly allocated iterator; face_id
3347 is -1 is this case. We know that the new face will not
3348 change until the next check pos, i.e. if the new face has a
3349 box, all characters up to that position will have a
3350 box. But, as usual, we don't know whether that position
3351 is really the end. */
3352 if (new_face_id
!= it
->face_id
)
3354 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3355 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3357 /* If new face has a box but old face hasn't, this is the
3358 start of a run of characters with box, i.e. it has a
3359 shadow on the left side. */
3360 it
->start_of_box_run_p
3361 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3362 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3366 it
->face_id
= new_face_id
;
3367 return HANDLED_NORMALLY
;
3371 /* Return the ID of the face ``underlying'' IT's current position,
3372 which is in a string. If the iterator is associated with a
3373 buffer, return the face at IT's current buffer position.
3374 Otherwise, use the iterator's base_face_id. */
3377 underlying_face_id (it
)
3380 int face_id
= it
->base_face_id
, i
;
3382 xassert (STRINGP (it
->string
));
3384 for (i
= it
->sp
- 1; i
>= 0; --i
)
3385 if (NILP (it
->stack
[i
].string
))
3386 face_id
= it
->stack
[i
].face_id
;
3392 /* Compute the face one character before or after the current position
3393 of IT. BEFORE_P non-zero means get the face in front of IT's
3394 position. Value is the id of the face. */
3397 face_before_or_after_it_pos (it
, before_p
)
3402 int next_check_charpos
;
3403 struct text_pos pos
;
3405 xassert (it
->s
== NULL
);
3407 if (STRINGP (it
->string
))
3409 int bufpos
, base_face_id
;
3411 /* No face change past the end of the string (for the case
3412 we are padding with spaces). No face change before the
3414 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3415 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3418 /* Set pos to the position before or after IT's current position. */
3420 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3422 /* For composition, we must check the character after the
3424 pos
= (it
->what
== IT_COMPOSITION
3425 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3426 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3428 if (it
->current
.overlay_string_index
>= 0)
3429 bufpos
= IT_CHARPOS (*it
);
3433 base_face_id
= underlying_face_id (it
);
3435 /* Get the face for ASCII, or unibyte. */
3436 face_id
= face_at_string_position (it
->w
,
3440 it
->region_beg_charpos
,
3441 it
->region_end_charpos
,
3442 &next_check_charpos
,
3445 /* Correct the face for charsets different from ASCII. Do it
3446 for the multibyte case only. The face returned above is
3447 suitable for unibyte text if IT->string is unibyte. */
3448 if (STRING_MULTIBYTE (it
->string
))
3450 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3451 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3453 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3455 c
= string_char_and_length (p
, rest
, &len
);
3456 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3461 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3462 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3465 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3466 pos
= it
->current
.pos
;
3469 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3472 if (it
->what
== IT_COMPOSITION
)
3473 /* For composition, we must check the position after the
3475 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3477 INC_TEXT_POS (pos
, it
->multibyte_p
);
3480 /* Determine face for CHARSET_ASCII, or unibyte. */
3481 face_id
= face_at_buffer_position (it
->w
,
3483 it
->region_beg_charpos
,
3484 it
->region_end_charpos
,
3485 &next_check_charpos
,
3488 /* Correct the face for charsets different from ASCII. Do it
3489 for the multibyte case only. The face returned above is
3490 suitable for unibyte text if current_buffer is unibyte. */
3491 if (it
->multibyte_p
)
3493 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3494 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3495 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3504 /***********************************************************************
3506 ***********************************************************************/
3508 /* Set up iterator IT from invisible properties at its current
3509 position. Called from handle_stop. */
3511 static enum prop_handled
3512 handle_invisible_prop (it
)
3515 enum prop_handled handled
= HANDLED_NORMALLY
;
3517 if (STRINGP (it
->string
))
3519 extern Lisp_Object Qinvisible
;
3520 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3522 /* Get the value of the invisible text property at the
3523 current position. Value will be nil if there is no such
3525 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3526 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3529 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3531 handled
= HANDLED_RECOMPUTE_PROPS
;
3533 /* Get the position at which the next change of the
3534 invisible text property can be found in IT->string.
3535 Value will be nil if the property value is the same for
3536 all the rest of IT->string. */
3537 XSETINT (limit
, SCHARS (it
->string
));
3538 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3541 /* Text at current position is invisible. The next
3542 change in the property is at position end_charpos.
3543 Move IT's current position to that position. */
3544 if (INTEGERP (end_charpos
)
3545 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3547 struct text_pos old
;
3548 old
= it
->current
.string_pos
;
3549 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3550 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3554 /* The rest of the string is invisible. If this is an
3555 overlay string, proceed with the next overlay string
3556 or whatever comes and return a character from there. */
3557 if (it
->current
.overlay_string_index
>= 0)
3559 next_overlay_string (it
);
3560 /* Don't check for overlay strings when we just
3561 finished processing them. */
3562 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3566 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3567 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3574 int invis_p
, newpos
, next_stop
, start_charpos
;
3575 Lisp_Object pos
, prop
, overlay
;
3577 /* First of all, is there invisible text at this position? */
3578 start_charpos
= IT_CHARPOS (*it
);
3579 pos
= make_number (IT_CHARPOS (*it
));
3580 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3582 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3584 /* If we are on invisible text, skip over it. */
3585 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3587 /* Record whether we have to display an ellipsis for the
3589 int display_ellipsis_p
= invis_p
== 2;
3591 handled
= HANDLED_RECOMPUTE_PROPS
;
3593 /* Loop skipping over invisible text. The loop is left at
3594 ZV or with IT on the first char being visible again. */
3597 /* Try to skip some invisible text. Return value is the
3598 position reached which can be equal to IT's position
3599 if there is nothing invisible here. This skips both
3600 over invisible text properties and overlays with
3601 invisible property. */
3602 newpos
= skip_invisible (IT_CHARPOS (*it
),
3603 &next_stop
, ZV
, it
->window
);
3605 /* If we skipped nothing at all we weren't at invisible
3606 text in the first place. If everything to the end of
3607 the buffer was skipped, end the loop. */
3608 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3612 /* We skipped some characters but not necessarily
3613 all there are. Check if we ended up on visible
3614 text. Fget_char_property returns the property of
3615 the char before the given position, i.e. if we
3616 get invis_p = 0, this means that the char at
3617 newpos is visible. */
3618 pos
= make_number (newpos
);
3619 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3620 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3623 /* If we ended up on invisible text, proceed to
3624 skip starting with next_stop. */
3626 IT_CHARPOS (*it
) = next_stop
;
3628 /* If there are adjacent invisible texts, don't lose the
3629 second one's ellipsis. */
3631 display_ellipsis_p
= 1;
3635 /* The position newpos is now either ZV or on visible text. */
3636 IT_CHARPOS (*it
) = newpos
;
3637 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3639 /* If there are before-strings at the start of invisible
3640 text, and the text is invisible because of a text
3641 property, arrange to show before-strings because 20.x did
3642 it that way. (If the text is invisible because of an
3643 overlay property instead of a text property, this is
3644 already handled in the overlay code.) */
3646 && get_overlay_strings (it
, start_charpos
))
3648 handled
= HANDLED_RECOMPUTE_PROPS
;
3649 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3651 else if (display_ellipsis_p
)
3653 /* Make sure that the glyphs of the ellipsis will get
3654 correct `charpos' values. If we would not update
3655 it->position here, the glyphs would belong to the
3656 last visible character _before_ the invisible
3657 text, which confuses `set_cursor_from_row'.
3659 We use the last invisible position instead of the
3660 first because this way the cursor is always drawn on
3661 the first "." of the ellipsis, whenever PT is inside
3662 the invisible text. Otherwise the cursor would be
3663 placed _after_ the ellipsis when the point is after the
3664 first invisible character. */
3665 if (!STRINGP (it
->object
))
3667 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3668 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3670 setup_for_ellipsis (it
, 0);
3679 /* Make iterator IT return `...' next.
3680 Replaces LEN characters from buffer. */
3683 setup_for_ellipsis (it
, len
)
3687 /* Use the display table definition for `...'. Invalid glyphs
3688 will be handled by the method returning elements from dpvec. */
3689 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3691 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3692 it
->dpvec
= v
->contents
;
3693 it
->dpend
= v
->contents
+ v
->size
;
3697 /* Default `...'. */
3698 it
->dpvec
= default_invis_vector
;
3699 it
->dpend
= default_invis_vector
+ 3;
3702 it
->dpvec_char_len
= len
;
3703 it
->current
.dpvec_index
= 0;
3704 it
->dpvec_face_id
= -1;
3706 /* Remember the current face id in case glyphs specify faces.
3707 IT's face is restored in set_iterator_to_next.
3708 saved_face_id was set to preceding char's face in handle_stop. */
3709 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3710 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3712 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3718 /***********************************************************************
3720 ***********************************************************************/
3722 /* Set up iterator IT from `display' property at its current position.
3723 Called from handle_stop.
3724 We return HANDLED_RETURN if some part of the display property
3725 overrides the display of the buffer text itself.
3726 Otherwise we return HANDLED_NORMALLY. */
3728 static enum prop_handled
3729 handle_display_prop (it
)
3732 Lisp_Object prop
, object
;
3733 struct text_pos
*position
;
3734 /* Nonzero if some property replaces the display of the text itself. */
3735 int display_replaced_p
= 0;
3737 if (STRINGP (it
->string
))
3739 object
= it
->string
;
3740 position
= &it
->current
.string_pos
;
3744 XSETWINDOW (object
, it
->w
);
3745 position
= &it
->current
.pos
;
3748 /* Reset those iterator values set from display property values. */
3749 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3750 it
->space_width
= Qnil
;
3751 it
->font_height
= Qnil
;
3754 /* We don't support recursive `display' properties, i.e. string
3755 values that have a string `display' property, that have a string
3756 `display' property etc. */
3757 if (!it
->string_from_display_prop_p
)
3758 it
->area
= TEXT_AREA
;
3760 prop
= Fget_char_property (make_number (position
->charpos
),
3763 return HANDLED_NORMALLY
;
3765 if (!STRINGP (it
->string
))
3766 object
= it
->w
->buffer
;
3769 /* Simple properties. */
3770 && !EQ (XCAR (prop
), Qimage
)
3771 && !EQ (XCAR (prop
), Qspace
)
3772 && !EQ (XCAR (prop
), Qwhen
)
3773 && !EQ (XCAR (prop
), Qslice
)
3774 && !EQ (XCAR (prop
), Qspace_width
)
3775 && !EQ (XCAR (prop
), Qheight
)
3776 && !EQ (XCAR (prop
), Qraise
)
3777 /* Marginal area specifications. */
3778 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3779 && !EQ (XCAR (prop
), Qleft_fringe
)
3780 && !EQ (XCAR (prop
), Qright_fringe
)
3781 && !NILP (XCAR (prop
)))
3783 for (; CONSP (prop
); prop
= XCDR (prop
))
3785 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3786 position
, display_replaced_p
))
3787 display_replaced_p
= 1;
3790 else if (VECTORP (prop
))
3793 for (i
= 0; i
< ASIZE (prop
); ++i
)
3794 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3795 position
, display_replaced_p
))
3796 display_replaced_p
= 1;
3800 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3801 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3802 return HANDLED_RECOMPUTE_PROPS
;
3804 display_replaced_p
= 1;
3807 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3811 /* Value is the position of the end of the `display' property starting
3812 at START_POS in OBJECT. */
3814 static struct text_pos
3815 display_prop_end (it
, object
, start_pos
)
3818 struct text_pos start_pos
;
3821 struct text_pos end_pos
;
3823 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3824 Qdisplay
, object
, Qnil
);
3825 CHARPOS (end_pos
) = XFASTINT (end
);
3826 if (STRINGP (object
))
3827 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3829 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3835 /* Set up IT from a single `display' specification PROP. OBJECT
3836 is the object in which the `display' property was found. *POSITION
3837 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3838 means that we previously saw a display specification which already
3839 replaced text display with something else, for example an image;
3840 we ignore such properties after the first one has been processed.
3842 If PROP is a `space' or `image' specification, and in some other
3843 cases too, set *POSITION to the position where the `display'
3846 Value is non-zero if something was found which replaces the display
3847 of buffer or string text. Specifically, the value is -1 if that
3848 "something" is "nothing". */
3851 handle_single_display_spec (it
, spec
, object
, position
,
3852 display_replaced_before_p
)
3856 struct text_pos
*position
;
3857 int display_replaced_before_p
;
3860 Lisp_Object location
, value
;
3861 struct text_pos start_pos
;
3864 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3865 If the result is non-nil, use VALUE instead of SPEC. */
3867 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3876 if (!NILP (form
) && !EQ (form
, Qt
))
3878 int count
= SPECPDL_INDEX ();
3879 struct gcpro gcpro1
;
3881 /* Bind `object' to the object having the `display' property, a
3882 buffer or string. Bind `position' to the position in the
3883 object where the property was found, and `buffer-position'
3884 to the current position in the buffer. */
3885 specbind (Qobject
, object
);
3886 specbind (Qposition
, make_number (CHARPOS (*position
)));
3887 specbind (Qbuffer_position
,
3888 make_number (STRINGP (object
)
3889 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3891 form
= safe_eval (form
);
3893 unbind_to (count
, Qnil
);
3899 /* Handle `(height HEIGHT)' specifications. */
3901 && EQ (XCAR (spec
), Qheight
)
3902 && CONSP (XCDR (spec
)))
3904 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3907 it
->font_height
= XCAR (XCDR (spec
));
3908 if (!NILP (it
->font_height
))
3910 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3911 int new_height
= -1;
3913 if (CONSP (it
->font_height
)
3914 && (EQ (XCAR (it
->font_height
), Qplus
)
3915 || EQ (XCAR (it
->font_height
), Qminus
))
3916 && CONSP (XCDR (it
->font_height
))
3917 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3919 /* `(+ N)' or `(- N)' where N is an integer. */
3920 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3921 if (EQ (XCAR (it
->font_height
), Qplus
))
3923 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3925 else if (FUNCTIONP (it
->font_height
))
3927 /* Call function with current height as argument.
3928 Value is the new height. */
3930 height
= safe_call1 (it
->font_height
,
3931 face
->lface
[LFACE_HEIGHT_INDEX
]);
3932 if (NUMBERP (height
))
3933 new_height
= XFLOATINT (height
);
3935 else if (NUMBERP (it
->font_height
))
3937 /* Value is a multiple of the canonical char height. */
3940 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3941 new_height
= (XFLOATINT (it
->font_height
)
3942 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3946 /* Evaluate IT->font_height with `height' bound to the
3947 current specified height to get the new height. */
3948 int count
= SPECPDL_INDEX ();
3950 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3951 value
= safe_eval (it
->font_height
);
3952 unbind_to (count
, Qnil
);
3954 if (NUMBERP (value
))
3955 new_height
= XFLOATINT (value
);
3959 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3965 /* Handle `(space_width WIDTH)'. */
3967 && EQ (XCAR (spec
), Qspace_width
)
3968 && CONSP (XCDR (spec
)))
3970 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3973 value
= XCAR (XCDR (spec
));
3974 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3975 it
->space_width
= value
;
3980 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3982 && EQ (XCAR (spec
), Qslice
))
3986 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3989 if (tem
= XCDR (spec
), CONSP (tem
))
3991 it
->slice
.x
= XCAR (tem
);
3992 if (tem
= XCDR (tem
), CONSP (tem
))
3994 it
->slice
.y
= XCAR (tem
);
3995 if (tem
= XCDR (tem
), CONSP (tem
))
3997 it
->slice
.width
= XCAR (tem
);
3998 if (tem
= XCDR (tem
), CONSP (tem
))
3999 it
->slice
.height
= XCAR (tem
);
4007 /* Handle `(raise FACTOR)'. */
4009 && EQ (XCAR (spec
), Qraise
)
4010 && CONSP (XCDR (spec
)))
4012 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4015 #ifdef HAVE_WINDOW_SYSTEM
4016 value
= XCAR (XCDR (spec
));
4017 if (NUMBERP (value
))
4019 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4020 it
->voffset
= - (XFLOATINT (value
)
4021 * (FONT_HEIGHT (face
->font
)));
4023 #endif /* HAVE_WINDOW_SYSTEM */
4028 /* Don't handle the other kinds of display specifications
4029 inside a string that we got from a `display' property. */
4030 if (it
->string_from_display_prop_p
)
4033 /* Characters having this form of property are not displayed, so
4034 we have to find the end of the property. */
4035 start_pos
= *position
;
4036 *position
= display_prop_end (it
, object
, start_pos
);
4039 /* Stop the scan at that end position--we assume that all
4040 text properties change there. */
4041 it
->stop_charpos
= position
->charpos
;
4043 /* Handle `(left-fringe BITMAP [FACE])'
4044 and `(right-fringe BITMAP [FACE])'. */
4046 && (EQ (XCAR (spec
), Qleft_fringe
)
4047 || EQ (XCAR (spec
), Qright_fringe
))
4048 && CONSP (XCDR (spec
)))
4050 int face_id
= DEFAULT_FACE_ID
;
4053 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4054 /* If we return here, POSITION has been advanced
4055 across the text with this property. */
4058 #ifdef HAVE_WINDOW_SYSTEM
4059 value
= XCAR (XCDR (spec
));
4060 if (!SYMBOLP (value
)
4061 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4062 /* If we return here, POSITION has been advanced
4063 across the text with this property. */
4066 if (CONSP (XCDR (XCDR (spec
))))
4068 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4069 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4070 'A', FRINGE_FACE_ID
, 0);
4075 /* Save current settings of IT so that we can restore them
4076 when we are finished with the glyph property value. */
4080 it
->area
= TEXT_AREA
;
4081 it
->what
= IT_IMAGE
;
4082 it
->image_id
= -1; /* no image */
4083 it
->position
= start_pos
;
4084 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4085 it
->method
= GET_FROM_IMAGE
;
4086 it
->face_id
= face_id
;
4088 /* Say that we haven't consumed the characters with
4089 `display' property yet. The call to pop_it in
4090 set_iterator_to_next will clean this up. */
4091 *position
= start_pos
;
4093 if (EQ (XCAR (spec
), Qleft_fringe
))
4095 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4096 it
->left_user_fringe_face_id
= face_id
;
4100 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4101 it
->right_user_fringe_face_id
= face_id
;
4103 #endif /* HAVE_WINDOW_SYSTEM */
4107 /* Prepare to handle `((margin left-margin) ...)',
4108 `((margin right-margin) ...)' and `((margin nil) ...)'
4109 prefixes for display specifications. */
4110 location
= Qunbound
;
4111 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4115 value
= XCDR (spec
);
4117 value
= XCAR (value
);
4120 if (EQ (XCAR (tem
), Qmargin
)
4121 && (tem
= XCDR (tem
),
4122 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4124 || EQ (tem
, Qleft_margin
)
4125 || EQ (tem
, Qright_margin
))))
4129 if (EQ (location
, Qunbound
))
4135 /* After this point, VALUE is the property after any
4136 margin prefix has been stripped. It must be a string,
4137 an image specification, or `(space ...)'.
4139 LOCATION specifies where to display: `left-margin',
4140 `right-margin' or nil. */
4142 valid_p
= (STRINGP (value
)
4143 #ifdef HAVE_WINDOW_SYSTEM
4144 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4145 #endif /* not HAVE_WINDOW_SYSTEM */
4146 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4148 if (valid_p
&& !display_replaced_before_p
)
4150 /* Save current settings of IT so that we can restore them
4151 when we are finished with the glyph property value. */
4154 if (NILP (location
))
4155 it
->area
= TEXT_AREA
;
4156 else if (EQ (location
, Qleft_margin
))
4157 it
->area
= LEFT_MARGIN_AREA
;
4159 it
->area
= RIGHT_MARGIN_AREA
;
4161 if (STRINGP (value
))
4163 if (SCHARS (value
) == 0)
4166 return -1; /* Replaced by "", i.e. nothing. */
4169 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4170 it
->current
.overlay_string_index
= -1;
4171 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4172 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4173 it
->method
= GET_FROM_STRING
;
4174 it
->stop_charpos
= 0;
4175 it
->string_from_display_prop_p
= 1;
4176 /* Say that we haven't consumed the characters with
4177 `display' property yet. The call to pop_it in
4178 set_iterator_to_next will clean this up. */
4179 *position
= start_pos
;
4181 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4183 it
->method
= GET_FROM_STRETCH
;
4185 *position
= it
->position
= start_pos
;
4187 #ifdef HAVE_WINDOW_SYSTEM
4190 it
->what
= IT_IMAGE
;
4191 it
->image_id
= lookup_image (it
->f
, value
);
4192 it
->position
= start_pos
;
4193 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4194 it
->method
= GET_FROM_IMAGE
;
4196 /* Say that we haven't consumed the characters with
4197 `display' property yet. The call to pop_it in
4198 set_iterator_to_next will clean this up. */
4199 *position
= start_pos
;
4201 #endif /* HAVE_WINDOW_SYSTEM */
4206 /* Invalid property or property not supported. Restore
4207 POSITION to what it was before. */
4208 *position
= start_pos
;
4213 /* Check if SPEC is a display specification value whose text should be
4214 treated as intangible. */
4217 single_display_spec_intangible_p (prop
)
4220 /* Skip over `when FORM'. */
4221 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4235 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4236 we don't need to treat text as intangible. */
4237 if (EQ (XCAR (prop
), Qmargin
))
4245 || EQ (XCAR (prop
), Qleft_margin
)
4246 || EQ (XCAR (prop
), Qright_margin
))
4250 return (CONSP (prop
)
4251 && (EQ (XCAR (prop
), Qimage
)
4252 || EQ (XCAR (prop
), Qspace
)));
4256 /* Check if PROP is a display property value whose text should be
4257 treated as intangible. */
4260 display_prop_intangible_p (prop
)
4264 && CONSP (XCAR (prop
))
4265 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4267 /* A list of sub-properties. */
4268 while (CONSP (prop
))
4270 if (single_display_spec_intangible_p (XCAR (prop
)))
4275 else if (VECTORP (prop
))
4277 /* A vector of sub-properties. */
4279 for (i
= 0; i
< ASIZE (prop
); ++i
)
4280 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4284 return single_display_spec_intangible_p (prop
);
4290 /* Return 1 if PROP is a display sub-property value containing STRING. */
4293 single_display_spec_string_p (prop
, string
)
4294 Lisp_Object prop
, string
;
4296 if (EQ (string
, prop
))
4299 /* Skip over `when FORM'. */
4300 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4309 /* Skip over `margin LOCATION'. */
4310 if (EQ (XCAR (prop
), Qmargin
))
4321 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4325 /* Return 1 if STRING appears in the `display' property PROP. */
4328 display_prop_string_p (prop
, string
)
4329 Lisp_Object prop
, string
;
4332 && CONSP (XCAR (prop
))
4333 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4335 /* A list of sub-properties. */
4336 while (CONSP (prop
))
4338 if (single_display_spec_string_p (XCAR (prop
), string
))
4343 else if (VECTORP (prop
))
4345 /* A vector of sub-properties. */
4347 for (i
= 0; i
< ASIZE (prop
); ++i
)
4348 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4352 return single_display_spec_string_p (prop
, string
);
4358 /* Determine from which buffer position in W's buffer STRING comes
4359 from. AROUND_CHARPOS is an approximate position where it could
4360 be from. Value is the buffer position or 0 if it couldn't be
4363 W's buffer must be current.
4365 This function is necessary because we don't record buffer positions
4366 in glyphs generated from strings (to keep struct glyph small).
4367 This function may only use code that doesn't eval because it is
4368 called asynchronously from note_mouse_highlight. */
4371 string_buffer_position (w
, string
, around_charpos
)
4376 Lisp_Object limit
, prop
, pos
;
4377 const int MAX_DISTANCE
= 1000;
4380 pos
= make_number (around_charpos
);
4381 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4382 while (!found
&& !EQ (pos
, limit
))
4384 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4385 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4388 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4393 pos
= make_number (around_charpos
);
4394 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4395 while (!found
&& !EQ (pos
, limit
))
4397 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4398 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4401 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4406 return found
? XINT (pos
) : 0;
4411 /***********************************************************************
4412 `composition' property
4413 ***********************************************************************/
4415 /* Set up iterator IT from `composition' property at its current
4416 position. Called from handle_stop. */
4418 static enum prop_handled
4419 handle_composition_prop (it
)
4422 Lisp_Object prop
, string
;
4423 int pos
, pos_byte
, end
;
4424 enum prop_handled handled
= HANDLED_NORMALLY
;
4426 if (STRINGP (it
->string
))
4428 pos
= IT_STRING_CHARPOS (*it
);
4429 pos_byte
= IT_STRING_BYTEPOS (*it
);
4430 string
= it
->string
;
4434 pos
= IT_CHARPOS (*it
);
4435 pos_byte
= IT_BYTEPOS (*it
);
4439 /* If there's a valid composition and point is not inside of the
4440 composition (in the case that the composition is from the current
4441 buffer), draw a glyph composed from the composition components. */
4442 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4443 && COMPOSITION_VALID_P (pos
, end
, prop
)
4444 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4446 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4450 struct composition
*cmp
= composition_table
[id
];
4452 if (cmp
->glyph_len
== 0)
4455 if (STRINGP (it
->string
))
4457 IT_STRING_CHARPOS (*it
) = end
;
4458 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4463 IT_CHARPOS (*it
) = end
;
4464 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4466 return HANDLED_RECOMPUTE_PROPS
;
4468 it
->method
= GET_FROM_COMPOSITION
;
4470 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4471 /* For a terminal, draw only the first character of the
4473 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4474 it
->len
= (STRINGP (it
->string
)
4475 ? string_char_to_byte (it
->string
, end
)
4476 : CHAR_TO_BYTE (end
)) - pos_byte
;
4477 it
->stop_charpos
= end
;
4478 handled
= HANDLED_RETURN
;
4487 /***********************************************************************
4489 ***********************************************************************/
4491 /* The following structure is used to record overlay strings for
4492 later sorting in load_overlay_strings. */
4494 struct overlay_entry
4496 Lisp_Object overlay
;
4503 /* Set up iterator IT from overlay strings at its current position.
4504 Called from handle_stop. */
4506 static enum prop_handled
4507 handle_overlay_change (it
)
4510 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4511 return HANDLED_RECOMPUTE_PROPS
;
4513 return HANDLED_NORMALLY
;
4517 /* Set up the next overlay string for delivery by IT, if there is an
4518 overlay string to deliver. Called by set_iterator_to_next when the
4519 end of the current overlay string is reached. If there are more
4520 overlay strings to display, IT->string and
4521 IT->current.overlay_string_index are set appropriately here.
4522 Otherwise IT->string is set to nil. */
4525 next_overlay_string (it
)
4528 ++it
->current
.overlay_string_index
;
4529 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4531 /* No more overlay strings. Restore IT's settings to what
4532 they were before overlay strings were processed, and
4533 continue to deliver from current_buffer. */
4534 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4537 xassert (it
->stop_charpos
>= BEGV
4538 && it
->stop_charpos
<= it
->end_charpos
);
4540 it
->current
.overlay_string_index
= -1;
4541 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4542 it
->n_overlay_strings
= 0;
4543 it
->method
= GET_FROM_BUFFER
;
4545 /* If we're at the end of the buffer, record that we have
4546 processed the overlay strings there already, so that
4547 next_element_from_buffer doesn't try it again. */
4548 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4549 it
->overlay_strings_at_end_processed_p
= 1;
4551 /* If we have to display `...' for invisible text, set
4552 the iterator up for that. */
4553 if (display_ellipsis_p
)
4554 setup_for_ellipsis (it
, 0);
4558 /* There are more overlay strings to process. If
4559 IT->current.overlay_string_index has advanced to a position
4560 where we must load IT->overlay_strings with more strings, do
4562 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4564 if (it
->current
.overlay_string_index
&& i
== 0)
4565 load_overlay_strings (it
, 0);
4567 /* Initialize IT to deliver display elements from the overlay
4569 it
->string
= it
->overlay_strings
[i
];
4570 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4571 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4572 it
->method
= GET_FROM_STRING
;
4573 it
->stop_charpos
= 0;
4580 /* Compare two overlay_entry structures E1 and E2. Used as a
4581 comparison function for qsort in load_overlay_strings. Overlay
4582 strings for the same position are sorted so that
4584 1. All after-strings come in front of before-strings, except
4585 when they come from the same overlay.
4587 2. Within after-strings, strings are sorted so that overlay strings
4588 from overlays with higher priorities come first.
4590 2. Within before-strings, strings are sorted so that overlay
4591 strings from overlays with higher priorities come last.
4593 Value is analogous to strcmp. */
4597 compare_overlay_entries (e1
, e2
)
4600 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4601 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4604 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4606 /* Let after-strings appear in front of before-strings if
4607 they come from different overlays. */
4608 if (EQ (entry1
->overlay
, entry2
->overlay
))
4609 result
= entry1
->after_string_p
? 1 : -1;
4611 result
= entry1
->after_string_p
? -1 : 1;
4613 else if (entry1
->after_string_p
)
4614 /* After-strings sorted in order of decreasing priority. */
4615 result
= entry2
->priority
- entry1
->priority
;
4617 /* Before-strings sorted in order of increasing priority. */
4618 result
= entry1
->priority
- entry2
->priority
;
4624 /* Load the vector IT->overlay_strings with overlay strings from IT's
4625 current buffer position, or from CHARPOS if that is > 0. Set
4626 IT->n_overlays to the total number of overlay strings found.
4628 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4629 a time. On entry into load_overlay_strings,
4630 IT->current.overlay_string_index gives the number of overlay
4631 strings that have already been loaded by previous calls to this
4634 IT->add_overlay_start contains an additional overlay start
4635 position to consider for taking overlay strings from, if non-zero.
4636 This position comes into play when the overlay has an `invisible'
4637 property, and both before and after-strings. When we've skipped to
4638 the end of the overlay, because of its `invisible' property, we
4639 nevertheless want its before-string to appear.
4640 IT->add_overlay_start will contain the overlay start position
4643 Overlay strings are sorted so that after-string strings come in
4644 front of before-string strings. Within before and after-strings,
4645 strings are sorted by overlay priority. See also function
4646 compare_overlay_entries. */
4649 load_overlay_strings (it
, charpos
)
4653 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4654 Lisp_Object overlay
, window
, str
, invisible
;
4655 struct Lisp_Overlay
*ov
;
4658 int n
= 0, i
, j
, invis_p
;
4659 struct overlay_entry
*entries
4660 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4663 charpos
= IT_CHARPOS (*it
);
4665 /* Append the overlay string STRING of overlay OVERLAY to vector
4666 `entries' which has size `size' and currently contains `n'
4667 elements. AFTER_P non-zero means STRING is an after-string of
4669 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4672 Lisp_Object priority; \
4676 int new_size = 2 * size; \
4677 struct overlay_entry *old = entries; \
4679 (struct overlay_entry *) alloca (new_size \
4680 * sizeof *entries); \
4681 bcopy (old, entries, size * sizeof *entries); \
4685 entries[n].string = (STRING); \
4686 entries[n].overlay = (OVERLAY); \
4687 priority = Foverlay_get ((OVERLAY), Qpriority); \
4688 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4689 entries[n].after_string_p = (AFTER_P); \
4694 /* Process overlay before the overlay center. */
4695 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4697 XSETMISC (overlay
, ov
);
4698 xassert (OVERLAYP (overlay
));
4699 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4700 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4705 /* Skip this overlay if it doesn't start or end at IT's current
4707 if (end
!= charpos
&& start
!= charpos
)
4710 /* Skip this overlay if it doesn't apply to IT->w. */
4711 window
= Foverlay_get (overlay
, Qwindow
);
4712 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4715 /* If the text ``under'' the overlay is invisible, both before-
4716 and after-strings from this overlay are visible; start and
4717 end position are indistinguishable. */
4718 invisible
= Foverlay_get (overlay
, Qinvisible
);
4719 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4721 /* If overlay has a non-empty before-string, record it. */
4722 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4723 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4725 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4727 /* If overlay has a non-empty after-string, record it. */
4728 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4729 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4731 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4734 /* Process overlays after the overlay center. */
4735 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4737 XSETMISC (overlay
, ov
);
4738 xassert (OVERLAYP (overlay
));
4739 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4740 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4742 if (start
> charpos
)
4745 /* Skip this overlay if it doesn't start or end at IT's current
4747 if (end
!= charpos
&& start
!= charpos
)
4750 /* Skip this overlay if it doesn't apply to IT->w. */
4751 window
= Foverlay_get (overlay
, Qwindow
);
4752 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4755 /* If the text ``under'' the overlay is invisible, it has a zero
4756 dimension, and both before- and after-strings apply. */
4757 invisible
= Foverlay_get (overlay
, Qinvisible
);
4758 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4760 /* If overlay has a non-empty before-string, record it. */
4761 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4762 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4764 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4766 /* If overlay has a non-empty after-string, record it. */
4767 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4768 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4770 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4773 #undef RECORD_OVERLAY_STRING
4777 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4779 /* Record the total number of strings to process. */
4780 it
->n_overlay_strings
= n
;
4782 /* IT->current.overlay_string_index is the number of overlay strings
4783 that have already been consumed by IT. Copy some of the
4784 remaining overlay strings to IT->overlay_strings. */
4786 j
= it
->current
.overlay_string_index
;
4787 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4788 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4794 /* Get the first chunk of overlay strings at IT's current buffer
4795 position, or at CHARPOS if that is > 0. Value is non-zero if at
4796 least one overlay string was found. */
4799 get_overlay_strings (it
, charpos
)
4803 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4804 process. This fills IT->overlay_strings with strings, and sets
4805 IT->n_overlay_strings to the total number of strings to process.
4806 IT->pos.overlay_string_index has to be set temporarily to zero
4807 because load_overlay_strings needs this; it must be set to -1
4808 when no overlay strings are found because a zero value would
4809 indicate a position in the first overlay string. */
4810 it
->current
.overlay_string_index
= 0;
4811 load_overlay_strings (it
, charpos
);
4813 /* If we found overlay strings, set up IT to deliver display
4814 elements from the first one. Otherwise set up IT to deliver
4815 from current_buffer. */
4816 if (it
->n_overlay_strings
)
4818 /* Make sure we know settings in current_buffer, so that we can
4819 restore meaningful values when we're done with the overlay
4821 compute_stop_pos (it
);
4822 xassert (it
->face_id
>= 0);
4824 /* Save IT's settings. They are restored after all overlay
4825 strings have been processed. */
4826 xassert (it
->sp
== 0);
4829 /* Set up IT to deliver display elements from the first overlay
4831 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4832 it
->string
= it
->overlay_strings
[0];
4833 it
->stop_charpos
= 0;
4834 xassert (STRINGP (it
->string
));
4835 it
->end_charpos
= SCHARS (it
->string
);
4836 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4837 it
->method
= GET_FROM_STRING
;
4842 it
->current
.overlay_string_index
= -1;
4843 it
->method
= GET_FROM_BUFFER
;
4848 /* Value is non-zero if we found at least one overlay string. */
4849 return STRINGP (it
->string
);
4854 /***********************************************************************
4855 Saving and restoring state
4856 ***********************************************************************/
4858 /* Save current settings of IT on IT->stack. Called, for example,
4859 before setting up IT for an overlay string, to be able to restore
4860 IT's settings to what they were after the overlay string has been
4867 struct iterator_stack_entry
*p
;
4869 xassert (it
->sp
< 2);
4870 p
= it
->stack
+ it
->sp
;
4872 p
->stop_charpos
= it
->stop_charpos
;
4873 xassert (it
->face_id
>= 0);
4874 p
->face_id
= it
->face_id
;
4875 p
->string
= it
->string
;
4876 p
->pos
= it
->current
;
4877 p
->end_charpos
= it
->end_charpos
;
4878 p
->string_nchars
= it
->string_nchars
;
4880 p
->multibyte_p
= it
->multibyte_p
;
4881 p
->slice
= it
->slice
;
4882 p
->space_width
= it
->space_width
;
4883 p
->font_height
= it
->font_height
;
4884 p
->voffset
= it
->voffset
;
4885 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4886 p
->display_ellipsis_p
= 0;
4891 /* Restore IT's settings from IT->stack. Called, for example, when no
4892 more overlay strings must be processed, and we return to delivering
4893 display elements from a buffer, or when the end of a string from a
4894 `display' property is reached and we return to delivering display
4895 elements from an overlay string, or from a buffer. */
4901 struct iterator_stack_entry
*p
;
4903 xassert (it
->sp
> 0);
4905 p
= it
->stack
+ it
->sp
;
4906 it
->stop_charpos
= p
->stop_charpos
;
4907 it
->face_id
= p
->face_id
;
4908 it
->string
= p
->string
;
4909 it
->current
= p
->pos
;
4910 it
->end_charpos
= p
->end_charpos
;
4911 it
->string_nchars
= p
->string_nchars
;
4913 it
->multibyte_p
= p
->multibyte_p
;
4914 it
->slice
= p
->slice
;
4915 it
->space_width
= p
->space_width
;
4916 it
->font_height
= p
->font_height
;
4917 it
->voffset
= p
->voffset
;
4918 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4923 /***********************************************************************
4925 ***********************************************************************/
4927 /* Set IT's current position to the previous line start. */
4930 back_to_previous_line_start (it
)
4933 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4934 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4938 /* Move IT to the next line start.
4940 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4941 we skipped over part of the text (as opposed to moving the iterator
4942 continuously over the text). Otherwise, don't change the value
4945 Newlines may come from buffer text, overlay strings, or strings
4946 displayed via the `display' property. That's the reason we can't
4947 simply use find_next_newline_no_quit.
4949 Note that this function may not skip over invisible text that is so
4950 because of text properties and immediately follows a newline. If
4951 it would, function reseat_at_next_visible_line_start, when called
4952 from set_iterator_to_next, would effectively make invisible
4953 characters following a newline part of the wrong glyph row, which
4954 leads to wrong cursor motion. */
4957 forward_to_next_line_start (it
, skipped_p
)
4961 int old_selective
, newline_found_p
, n
;
4962 const int MAX_NEWLINE_DISTANCE
= 500;
4964 /* If already on a newline, just consume it to avoid unintended
4965 skipping over invisible text below. */
4966 if (it
->what
== IT_CHARACTER
4968 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4970 set_iterator_to_next (it
, 0);
4975 /* Don't handle selective display in the following. It's (a)
4976 unnecessary because it's done by the caller, and (b) leads to an
4977 infinite recursion because next_element_from_ellipsis indirectly
4978 calls this function. */
4979 old_selective
= it
->selective
;
4982 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4983 from buffer text. */
4984 for (n
= newline_found_p
= 0;
4985 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4986 n
+= STRINGP (it
->string
) ? 0 : 1)
4988 if (!get_next_display_element (it
))
4990 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4991 set_iterator_to_next (it
, 0);
4994 /* If we didn't find a newline near enough, see if we can use a
4996 if (!newline_found_p
)
4998 int start
= IT_CHARPOS (*it
);
4999 int limit
= find_next_newline_no_quit (start
, 1);
5002 xassert (!STRINGP (it
->string
));
5004 /* If there isn't any `display' property in sight, and no
5005 overlays, we can just use the position of the newline in
5007 if (it
->stop_charpos
>= limit
5008 || ((pos
= Fnext_single_property_change (make_number (start
),
5010 Qnil
, make_number (limit
)),
5012 && next_overlay_change (start
) == ZV
))
5014 IT_CHARPOS (*it
) = limit
;
5015 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5016 *skipped_p
= newline_found_p
= 1;
5020 while (get_next_display_element (it
)
5021 && !newline_found_p
)
5023 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5024 set_iterator_to_next (it
, 0);
5029 it
->selective
= old_selective
;
5030 return newline_found_p
;
5034 /* Set IT's current position to the previous visible line start. Skip
5035 invisible text that is so either due to text properties or due to
5036 selective display. Caution: this does not change IT->current_x and
5040 back_to_previous_visible_line_start (it
)
5043 while (IT_CHARPOS (*it
) > BEGV
)
5045 back_to_previous_line_start (it
);
5046 if (IT_CHARPOS (*it
) <= BEGV
)
5049 /* If selective > 0, then lines indented more than that values
5051 if (it
->selective
> 0
5052 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5053 (double) it
->selective
)) /* iftc */
5056 /* Check the newline before point for invisibility. */
5059 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5060 Qinvisible
, it
->window
);
5061 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5065 /* If newline has a display property that replaces the newline with something
5066 else (image or text), find start of overlay or interval and continue search
5068 if (IT_CHARPOS (*it
) > BEGV
)
5070 struct it it2
= *it
;
5073 Lisp_Object val
, overlay
;
5075 pos
= --IT_CHARPOS (it2
);
5078 if (handle_display_prop (&it2
) == HANDLED_RETURN
5079 && !NILP (val
= get_char_property_and_overlay
5080 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5081 && (OVERLAYP (overlay
)
5082 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5083 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5087 IT_CHARPOS (*it
) = beg
;
5088 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5096 xassert (IT_CHARPOS (*it
) >= BEGV
);
5097 xassert (IT_CHARPOS (*it
) == BEGV
5098 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5103 /* Reseat iterator IT at the previous visible line start. Skip
5104 invisible text that is so either due to text properties or due to
5105 selective display. At the end, update IT's overlay information,
5106 face information etc. */
5109 reseat_at_previous_visible_line_start (it
)
5112 back_to_previous_visible_line_start (it
);
5113 reseat (it
, it
->current
.pos
, 1);
5118 /* Reseat iterator IT on the next visible line start in the current
5119 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5120 preceding the line start. Skip over invisible text that is so
5121 because of selective display. Compute faces, overlays etc at the
5122 new position. Note that this function does not skip over text that
5123 is invisible because of text properties. */
5126 reseat_at_next_visible_line_start (it
, on_newline_p
)
5130 int newline_found_p
, skipped_p
= 0;
5132 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5134 /* Skip over lines that are invisible because they are indented
5135 more than the value of IT->selective. */
5136 if (it
->selective
> 0)
5137 while (IT_CHARPOS (*it
) < ZV
5138 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5139 (double) it
->selective
)) /* iftc */
5141 xassert (IT_BYTEPOS (*it
) == BEGV
5142 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5143 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5146 /* Position on the newline if that's what's requested. */
5147 if (on_newline_p
&& newline_found_p
)
5149 if (STRINGP (it
->string
))
5151 if (IT_STRING_CHARPOS (*it
) > 0)
5153 --IT_STRING_CHARPOS (*it
);
5154 --IT_STRING_BYTEPOS (*it
);
5157 else if (IT_CHARPOS (*it
) > BEGV
)
5161 reseat (it
, it
->current
.pos
, 0);
5165 reseat (it
, it
->current
.pos
, 0);
5172 /***********************************************************************
5173 Changing an iterator's position
5174 ***********************************************************************/
5176 /* Change IT's current position to POS in current_buffer. If FORCE_P
5177 is non-zero, always check for text properties at the new position.
5178 Otherwise, text properties are only looked up if POS >=
5179 IT->check_charpos of a property. */
5182 reseat (it
, pos
, force_p
)
5184 struct text_pos pos
;
5187 int original_pos
= IT_CHARPOS (*it
);
5189 reseat_1 (it
, pos
, 0);
5191 /* Determine where to check text properties. Avoid doing it
5192 where possible because text property lookup is very expensive. */
5194 || CHARPOS (pos
) > it
->stop_charpos
5195 || CHARPOS (pos
) < original_pos
)
5202 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5203 IT->stop_pos to POS, also. */
5206 reseat_1 (it
, pos
, set_stop_p
)
5208 struct text_pos pos
;
5211 /* Don't call this function when scanning a C string. */
5212 xassert (it
->s
== NULL
);
5214 /* POS must be a reasonable value. */
5215 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5217 it
->current
.pos
= it
->position
= pos
;
5218 XSETBUFFER (it
->object
, current_buffer
);
5219 it
->end_charpos
= ZV
;
5221 it
->current
.dpvec_index
= -1;
5222 it
->current
.overlay_string_index
= -1;
5223 IT_STRING_CHARPOS (*it
) = -1;
5224 IT_STRING_BYTEPOS (*it
) = -1;
5226 it
->method
= GET_FROM_BUFFER
;
5227 /* RMS: I added this to fix a bug in move_it_vertically_backward
5228 where it->area continued to relate to the starting point
5229 for the backward motion. Bug report from
5230 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
5231 However, I am not sure whether reseat still does the right thing
5232 in general after this change. */
5233 it
->area
= TEXT_AREA
;
5234 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5236 it
->face_before_selective_p
= 0;
5239 it
->stop_charpos
= CHARPOS (pos
);
5243 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5244 If S is non-null, it is a C string to iterate over. Otherwise,
5245 STRING gives a Lisp string to iterate over.
5247 If PRECISION > 0, don't return more then PRECISION number of
5248 characters from the string.
5250 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5251 characters have been returned. FIELD_WIDTH < 0 means an infinite
5254 MULTIBYTE = 0 means disable processing of multibyte characters,
5255 MULTIBYTE > 0 means enable it,
5256 MULTIBYTE < 0 means use IT->multibyte_p.
5258 IT must be initialized via a prior call to init_iterator before
5259 calling this function. */
5262 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5267 int precision
, field_width
, multibyte
;
5269 /* No region in strings. */
5270 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5272 /* No text property checks performed by default, but see below. */
5273 it
->stop_charpos
= -1;
5275 /* Set iterator position and end position. */
5276 bzero (&it
->current
, sizeof it
->current
);
5277 it
->current
.overlay_string_index
= -1;
5278 it
->current
.dpvec_index
= -1;
5279 xassert (charpos
>= 0);
5281 /* If STRING is specified, use its multibyteness, otherwise use the
5282 setting of MULTIBYTE, if specified. */
5284 it
->multibyte_p
= multibyte
> 0;
5288 xassert (STRINGP (string
));
5289 it
->string
= string
;
5291 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5292 it
->method
= GET_FROM_STRING
;
5293 it
->current
.string_pos
= string_pos (charpos
, string
);
5300 /* Note that we use IT->current.pos, not it->current.string_pos,
5301 for displaying C strings. */
5302 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5303 if (it
->multibyte_p
)
5305 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5306 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5310 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5311 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5314 it
->method
= GET_FROM_C_STRING
;
5317 /* PRECISION > 0 means don't return more than PRECISION characters
5319 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5320 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5322 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5323 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5324 FIELD_WIDTH < 0 means infinite field width. This is useful for
5325 padding with `-' at the end of a mode line. */
5326 if (field_width
< 0)
5327 field_width
= INFINITY
;
5328 if (field_width
> it
->end_charpos
- charpos
)
5329 it
->end_charpos
= charpos
+ field_width
;
5331 /* Use the standard display table for displaying strings. */
5332 if (DISP_TABLE_P (Vstandard_display_table
))
5333 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5335 it
->stop_charpos
= charpos
;
5341 /***********************************************************************
5343 ***********************************************************************/
5345 /* Map enum it_method value to corresponding next_element_from_* function. */
5347 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5349 next_element_from_buffer
,
5350 next_element_from_display_vector
,
5351 next_element_from_composition
,
5352 next_element_from_string
,
5353 next_element_from_c_string
,
5354 next_element_from_image
,
5355 next_element_from_stretch
5359 /* Load IT's display element fields with information about the next
5360 display element from the current position of IT. Value is zero if
5361 end of buffer (or C string) is reached. */
5363 static struct frame
*last_escape_glyph_frame
= NULL
;
5364 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5365 static int last_escape_glyph_merged_face_id
= 0;
5368 get_next_display_element (it
)
5371 /* Non-zero means that we found a display element. Zero means that
5372 we hit the end of what we iterate over. Performance note: the
5373 function pointer `method' used here turns out to be faster than
5374 using a sequence of if-statements. */
5378 success_p
= (*get_next_element
[it
->method
]) (it
);
5380 if (it
->what
== IT_CHARACTER
)
5382 /* Map via display table or translate control characters.
5383 IT->c, IT->len etc. have been set to the next character by
5384 the function call above. If we have a display table, and it
5385 contains an entry for IT->c, translate it. Don't do this if
5386 IT->c itself comes from a display table, otherwise we could
5387 end up in an infinite recursion. (An alternative could be to
5388 count the recursion depth of this function and signal an
5389 error when a certain maximum depth is reached.) Is it worth
5391 if (success_p
&& it
->dpvec
== NULL
)
5396 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5399 struct Lisp_Vector
*v
= XVECTOR (dv
);
5401 /* Return the first character from the display table
5402 entry, if not empty. If empty, don't display the
5403 current character. */
5406 it
->dpvec_char_len
= it
->len
;
5407 it
->dpvec
= v
->contents
;
5408 it
->dpend
= v
->contents
+ v
->size
;
5409 it
->current
.dpvec_index
= 0;
5410 it
->dpvec_face_id
= -1;
5411 it
->saved_face_id
= it
->face_id
;
5412 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5417 set_iterator_to_next (it
, 0);
5422 /* Translate control characters into `\003' or `^C' form.
5423 Control characters coming from a display table entry are
5424 currently not translated because we use IT->dpvec to hold
5425 the translation. This could easily be changed but I
5426 don't believe that it is worth doing.
5428 If it->multibyte_p is nonzero, eight-bit characters and
5429 non-printable multibyte characters are also translated to
5432 If it->multibyte_p is zero, eight-bit characters that
5433 don't have corresponding multibyte char code are also
5434 translated to octal form. */
5435 else if ((it
->c
< ' '
5436 && (it
->area
!= TEXT_AREA
5437 /* In mode line, treat \n like other crl chars. */
5439 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5440 || (it
->c
!= '\n' && it
->c
!= '\t')))
5444 || !CHAR_PRINTABLE_P (it
->c
)
5445 || (!NILP (Vnobreak_char_display
)
5446 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5447 || it
->c
== 0x920 || it
->c
== 0x92d
5448 || it
->c
== 0xe20 || it
->c
== 0xe2d
5449 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5451 && (!unibyte_display_via_language_environment
5452 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5454 /* IT->c is a control character which must be displayed
5455 either as '\003' or as `^C' where the '\\' and '^'
5456 can be defined in the display table. Fill
5457 IT->ctl_chars with glyphs for what we have to
5458 display. Then, set IT->dpvec to these glyphs. */
5461 int face_id
, lface_id
= 0 ;
5464 /* Handle control characters with ^. */
5466 if (it
->c
< 128 && it
->ctl_arrow_p
)
5468 g
= '^'; /* default glyph for Control */
5469 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5471 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5472 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5474 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5475 lface_id
= FAST_GLYPH_FACE (g
);
5479 g
= FAST_GLYPH_CHAR (g
);
5480 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5483 else if (it
->f
== last_escape_glyph_frame
5484 && it
->face_id
== last_escape_glyph_face_id
)
5486 face_id
= last_escape_glyph_merged_face_id
;
5490 /* Merge the escape-glyph face into the current face. */
5491 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5493 last_escape_glyph_frame
= it
->f
;
5494 last_escape_glyph_face_id
= it
->face_id
;
5495 last_escape_glyph_merged_face_id
= face_id
;
5498 XSETINT (it
->ctl_chars
[0], g
);
5500 XSETINT (it
->ctl_chars
[1], g
);
5502 goto display_control
;
5505 /* Handle non-break space in the mode where it only gets
5508 if (EQ (Vnobreak_char_display
, Qt
)
5509 && (it
->c
== 0x8a0 || it
->c
== 0x920
5510 || it
->c
== 0xe20 || it
->c
== 0xf20))
5512 /* Merge the no-break-space face into the current face. */
5513 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5517 XSETINT (it
->ctl_chars
[0], g
);
5519 goto display_control
;
5522 /* Handle sequences that start with the "escape glyph". */
5524 /* the default escape glyph is \. */
5525 escape_glyph
= '\\';
5528 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5529 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5531 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5532 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5536 /* The display table specified a face.
5537 Merge it into face_id and also into escape_glyph. */
5538 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5539 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5542 else if (it
->f
== last_escape_glyph_frame
5543 && it
->face_id
== last_escape_glyph_face_id
)
5545 face_id
= last_escape_glyph_merged_face_id
;
5549 /* Merge the escape-glyph face into the current face. */
5550 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5552 last_escape_glyph_frame
= it
->f
;
5553 last_escape_glyph_face_id
= it
->face_id
;
5554 last_escape_glyph_merged_face_id
= face_id
;
5557 /* Handle soft hyphens in the mode where they only get
5560 if (EQ (Vnobreak_char_display
, Qt
)
5561 && (it
->c
== 0x8ad || it
->c
== 0x92d
5562 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5565 XSETINT (it
->ctl_chars
[0], g
);
5567 goto display_control
;
5570 /* Handle non-break space and soft hyphen
5571 with the escape glyph. */
5573 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5574 || it
->c
== 0x920 || it
->c
== 0x92d
5575 || it
->c
== 0xe20 || it
->c
== 0xe2d
5576 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5578 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5579 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5580 XSETINT (it
->ctl_chars
[1], g
);
5582 goto display_control
;
5586 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5590 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5591 if (SINGLE_BYTE_CHAR_P (it
->c
))
5592 str
[0] = it
->c
, len
= 1;
5595 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5598 /* It's an invalid character, which shouldn't
5599 happen actually, but due to bugs it may
5600 happen. Let's print the char as is, there's
5601 not much meaningful we can do with it. */
5603 str
[1] = it
->c
>> 8;
5604 str
[2] = it
->c
>> 16;
5605 str
[3] = it
->c
>> 24;
5610 for (i
= 0; i
< len
; i
++)
5612 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5613 /* Insert three more glyphs into IT->ctl_chars for
5614 the octal display of the character. */
5615 g
= ((str
[i
] >> 6) & 7) + '0';
5616 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5617 g
= ((str
[i
] >> 3) & 7) + '0';
5618 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5619 g
= (str
[i
] & 7) + '0';
5620 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5626 /* Set up IT->dpvec and return first character from it. */
5627 it
->dpvec_char_len
= it
->len
;
5628 it
->dpvec
= it
->ctl_chars
;
5629 it
->dpend
= it
->dpvec
+ ctl_len
;
5630 it
->current
.dpvec_index
= 0;
5631 it
->dpvec_face_id
= face_id
;
5632 it
->saved_face_id
= it
->face_id
;
5633 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5639 /* Adjust face id for a multibyte character. There are no
5640 multibyte character in unibyte text. */
5643 && FRAME_WINDOW_P (it
->f
))
5645 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5646 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5650 /* Is this character the last one of a run of characters with
5651 box? If yes, set IT->end_of_box_run_p to 1. */
5658 it
->end_of_box_run_p
5659 = ((face_id
= face_after_it_pos (it
),
5660 face_id
!= it
->face_id
)
5661 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5662 face
->box
== FACE_NO_BOX
));
5665 /* Value is 0 if end of buffer or string reached. */
5670 /* Move IT to the next display element.
5672 RESEAT_P non-zero means if called on a newline in buffer text,
5673 skip to the next visible line start.
5675 Functions get_next_display_element and set_iterator_to_next are
5676 separate because I find this arrangement easier to handle than a
5677 get_next_display_element function that also increments IT's
5678 position. The way it is we can first look at an iterator's current
5679 display element, decide whether it fits on a line, and if it does,
5680 increment the iterator position. The other way around we probably
5681 would either need a flag indicating whether the iterator has to be
5682 incremented the next time, or we would have to implement a
5683 decrement position function which would not be easy to write. */
5686 set_iterator_to_next (it
, reseat_p
)
5690 /* Reset flags indicating start and end of a sequence of characters
5691 with box. Reset them at the start of this function because
5692 moving the iterator to a new position might set them. */
5693 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5697 case GET_FROM_BUFFER
:
5698 /* The current display element of IT is a character from
5699 current_buffer. Advance in the buffer, and maybe skip over
5700 invisible lines that are so because of selective display. */
5701 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5702 reseat_at_next_visible_line_start (it
, 0);
5705 xassert (it
->len
!= 0);
5706 IT_BYTEPOS (*it
) += it
->len
;
5707 IT_CHARPOS (*it
) += 1;
5708 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5712 case GET_FROM_COMPOSITION
:
5713 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5714 if (STRINGP (it
->string
))
5716 IT_STRING_BYTEPOS (*it
) += it
->len
;
5717 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5718 it
->method
= GET_FROM_STRING
;
5719 goto consider_string_end
;
5723 IT_BYTEPOS (*it
) += it
->len
;
5724 IT_CHARPOS (*it
) += it
->cmp_len
;
5725 it
->method
= GET_FROM_BUFFER
;
5729 case GET_FROM_C_STRING
:
5730 /* Current display element of IT is from a C string. */
5731 IT_BYTEPOS (*it
) += it
->len
;
5732 IT_CHARPOS (*it
) += 1;
5735 case GET_FROM_DISPLAY_VECTOR
:
5736 /* Current display element of IT is from a display table entry.
5737 Advance in the display table definition. Reset it to null if
5738 end reached, and continue with characters from buffers/
5740 ++it
->current
.dpvec_index
;
5742 /* Restore face of the iterator to what they were before the
5743 display vector entry (these entries may contain faces). */
5744 it
->face_id
= it
->saved_face_id
;
5746 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5748 int recheck_faces
= it
->ellipsis_p
;
5751 it
->method
= GET_FROM_C_STRING
;
5752 else if (STRINGP (it
->string
))
5753 it
->method
= GET_FROM_STRING
;
5755 it
->method
= GET_FROM_BUFFER
;
5758 it
->current
.dpvec_index
= -1;
5760 /* Skip over characters which were displayed via IT->dpvec. */
5761 if (it
->dpvec_char_len
< 0)
5762 reseat_at_next_visible_line_start (it
, 1);
5763 else if (it
->dpvec_char_len
> 0)
5765 if (it
->method
== GET_FROM_STRING
5766 && it
->n_overlay_strings
> 0)
5767 it
->ignore_overlay_strings_at_pos_p
= 1;
5768 it
->len
= it
->dpvec_char_len
;
5769 set_iterator_to_next (it
, reseat_p
);
5772 /* Maybe recheck faces after display vector */
5774 it
->stop_charpos
= IT_CHARPOS (*it
);
5778 case GET_FROM_STRING
:
5779 /* Current display element is a character from a Lisp string. */
5780 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5781 IT_STRING_BYTEPOS (*it
) += it
->len
;
5782 IT_STRING_CHARPOS (*it
) += 1;
5784 consider_string_end
:
5786 if (it
->current
.overlay_string_index
>= 0)
5788 /* IT->string is an overlay string. Advance to the
5789 next, if there is one. */
5790 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5791 next_overlay_string (it
);
5795 /* IT->string is not an overlay string. If we reached
5796 its end, and there is something on IT->stack, proceed
5797 with what is on the stack. This can be either another
5798 string, this time an overlay string, or a buffer. */
5799 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5803 if (STRINGP (it
->string
))
5804 goto consider_string_end
;
5805 it
->method
= GET_FROM_BUFFER
;
5810 case GET_FROM_IMAGE
:
5811 case GET_FROM_STRETCH
:
5812 /* The position etc with which we have to proceed are on
5813 the stack. The position may be at the end of a string,
5814 if the `display' property takes up the whole string. */
5815 xassert (it
->sp
> 0);
5818 if (STRINGP (it
->string
))
5820 it
->method
= GET_FROM_STRING
;
5821 goto consider_string_end
;
5823 it
->method
= GET_FROM_BUFFER
;
5827 /* There are no other methods defined, so this should be a bug. */
5831 xassert (it
->method
!= GET_FROM_STRING
5832 || (STRINGP (it
->string
)
5833 && IT_STRING_CHARPOS (*it
) >= 0));
5836 /* Load IT's display element fields with information about the next
5837 display element which comes from a display table entry or from the
5838 result of translating a control character to one of the forms `^C'
5841 IT->dpvec holds the glyphs to return as characters.
5842 IT->saved_face_id holds the face id before the display vector--
5843 it is restored into IT->face_idin set_iterator_to_next. */
5846 next_element_from_display_vector (it
)
5850 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5852 it
->face_id
= it
->saved_face_id
;
5854 if (INTEGERP (*it
->dpvec
)
5855 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5859 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5860 it
->c
= FAST_GLYPH_CHAR (g
);
5861 it
->len
= CHAR_BYTES (it
->c
);
5863 /* The entry may contain a face id to use. Such a face id is
5864 the id of a Lisp face, not a realized face. A face id of
5865 zero means no face is specified. */
5866 if (it
->dpvec_face_id
>= 0)
5867 it
->face_id
= it
->dpvec_face_id
;
5870 int lface_id
= FAST_GLYPH_FACE (g
);
5872 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5877 /* Display table entry is invalid. Return a space. */
5878 it
->c
= ' ', it
->len
= 1;
5880 /* Don't change position and object of the iterator here. They are
5881 still the values of the character that had this display table
5882 entry or was translated, and that's what we want. */
5883 it
->what
= IT_CHARACTER
;
5888 /* Load IT with the next display element from Lisp string IT->string.
5889 IT->current.string_pos is the current position within the string.
5890 If IT->current.overlay_string_index >= 0, the Lisp string is an
5894 next_element_from_string (it
)
5897 struct text_pos position
;
5899 xassert (STRINGP (it
->string
));
5900 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5901 position
= it
->current
.string_pos
;
5903 /* Time to check for invisible text? */
5904 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5905 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5909 /* Since a handler may have changed IT->method, we must
5911 return get_next_display_element (it
);
5914 if (it
->current
.overlay_string_index
>= 0)
5916 /* Get the next character from an overlay string. In overlay
5917 strings, There is no field width or padding with spaces to
5919 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5924 else if (STRING_MULTIBYTE (it
->string
))
5926 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5927 const unsigned char *s
= (SDATA (it
->string
)
5928 + IT_STRING_BYTEPOS (*it
));
5929 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5933 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5939 /* Get the next character from a Lisp string that is not an
5940 overlay string. Such strings come from the mode line, for
5941 example. We may have to pad with spaces, or truncate the
5942 string. See also next_element_from_c_string. */
5943 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5948 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5950 /* Pad with spaces. */
5951 it
->c
= ' ', it
->len
= 1;
5952 CHARPOS (position
) = BYTEPOS (position
) = -1;
5954 else if (STRING_MULTIBYTE (it
->string
))
5956 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5957 const unsigned char *s
= (SDATA (it
->string
)
5958 + IT_STRING_BYTEPOS (*it
));
5959 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5963 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5968 /* Record what we have and where it came from. Note that we store a
5969 buffer position in IT->position although it could arguably be a
5971 it
->what
= IT_CHARACTER
;
5972 it
->object
= it
->string
;
5973 it
->position
= position
;
5978 /* Load IT with next display element from C string IT->s.
5979 IT->string_nchars is the maximum number of characters to return
5980 from the string. IT->end_charpos may be greater than
5981 IT->string_nchars when this function is called, in which case we
5982 may have to return padding spaces. Value is zero if end of string
5983 reached, including padding spaces. */
5986 next_element_from_c_string (it
)
5992 it
->what
= IT_CHARACTER
;
5993 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5996 /* IT's position can be greater IT->string_nchars in case a field
5997 width or precision has been specified when the iterator was
5999 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6001 /* End of the game. */
6005 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6007 /* Pad with spaces. */
6008 it
->c
= ' ', it
->len
= 1;
6009 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6011 else if (it
->multibyte_p
)
6013 /* Implementation note: The calls to strlen apparently aren't a
6014 performance problem because there is no noticeable performance
6015 difference between Emacs running in unibyte or multibyte mode. */
6016 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6017 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6021 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6027 /* Set up IT to return characters from an ellipsis, if appropriate.
6028 The definition of the ellipsis glyphs may come from a display table
6029 entry. This function Fills IT with the first glyph from the
6030 ellipsis if an ellipsis is to be displayed. */
6033 next_element_from_ellipsis (it
)
6036 if (it
->selective_display_ellipsis_p
)
6037 setup_for_ellipsis (it
, it
->len
);
6040 /* The face at the current position may be different from the
6041 face we find after the invisible text. Remember what it
6042 was in IT->saved_face_id, and signal that it's there by
6043 setting face_before_selective_p. */
6044 it
->saved_face_id
= it
->face_id
;
6045 it
->method
= GET_FROM_BUFFER
;
6046 reseat_at_next_visible_line_start (it
, 1);
6047 it
->face_before_selective_p
= 1;
6050 return get_next_display_element (it
);
6054 /* Deliver an image display element. The iterator IT is already
6055 filled with image information (done in handle_display_prop). Value
6060 next_element_from_image (it
)
6063 it
->what
= IT_IMAGE
;
6068 /* Fill iterator IT with next display element from a stretch glyph
6069 property. IT->object is the value of the text property. Value is
6073 next_element_from_stretch (it
)
6076 it
->what
= IT_STRETCH
;
6081 /* Load IT with the next display element from current_buffer. Value
6082 is zero if end of buffer reached. IT->stop_charpos is the next
6083 position at which to stop and check for text properties or buffer
6087 next_element_from_buffer (it
)
6092 /* Check this assumption, otherwise, we would never enter the
6093 if-statement, below. */
6094 xassert (IT_CHARPOS (*it
) >= BEGV
6095 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6097 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6099 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6101 int overlay_strings_follow_p
;
6103 /* End of the game, except when overlay strings follow that
6104 haven't been returned yet. */
6105 if (it
->overlay_strings_at_end_processed_p
)
6106 overlay_strings_follow_p
= 0;
6109 it
->overlay_strings_at_end_processed_p
= 1;
6110 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6113 if (overlay_strings_follow_p
)
6114 success_p
= get_next_display_element (it
);
6118 it
->position
= it
->current
.pos
;
6125 return get_next_display_element (it
);
6130 /* No face changes, overlays etc. in sight, so just return a
6131 character from current_buffer. */
6134 /* Maybe run the redisplay end trigger hook. Performance note:
6135 This doesn't seem to cost measurable time. */
6136 if (it
->redisplay_end_trigger_charpos
6138 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6139 run_redisplay_end_trigger_hook (it
);
6141 /* Get the next character, maybe multibyte. */
6142 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6143 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6145 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6146 - IT_BYTEPOS (*it
));
6147 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6150 it
->c
= *p
, it
->len
= 1;
6152 /* Record what we have and where it came from. */
6153 it
->what
= IT_CHARACTER
;;
6154 it
->object
= it
->w
->buffer
;
6155 it
->position
= it
->current
.pos
;
6157 /* Normally we return the character found above, except when we
6158 really want to return an ellipsis for selective display. */
6163 /* A value of selective > 0 means hide lines indented more
6164 than that number of columns. */
6165 if (it
->selective
> 0
6166 && IT_CHARPOS (*it
) + 1 < ZV
6167 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6168 IT_BYTEPOS (*it
) + 1,
6169 (double) it
->selective
)) /* iftc */
6171 success_p
= next_element_from_ellipsis (it
);
6172 it
->dpvec_char_len
= -1;
6175 else if (it
->c
== '\r' && it
->selective
== -1)
6177 /* A value of selective == -1 means that everything from the
6178 CR to the end of the line is invisible, with maybe an
6179 ellipsis displayed for it. */
6180 success_p
= next_element_from_ellipsis (it
);
6181 it
->dpvec_char_len
= -1;
6186 /* Value is zero if end of buffer reached. */
6187 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6192 /* Run the redisplay end trigger hook for IT. */
6195 run_redisplay_end_trigger_hook (it
)
6198 Lisp_Object args
[3];
6200 /* IT->glyph_row should be non-null, i.e. we should be actually
6201 displaying something, or otherwise we should not run the hook. */
6202 xassert (it
->glyph_row
);
6204 /* Set up hook arguments. */
6205 args
[0] = Qredisplay_end_trigger_functions
;
6206 args
[1] = it
->window
;
6207 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6208 it
->redisplay_end_trigger_charpos
= 0;
6210 /* Since we are *trying* to run these functions, don't try to run
6211 them again, even if they get an error. */
6212 it
->w
->redisplay_end_trigger
= Qnil
;
6213 Frun_hook_with_args (3, args
);
6215 /* Notice if it changed the face of the character we are on. */
6216 handle_face_prop (it
);
6220 /* Deliver a composition display element. The iterator IT is already
6221 filled with composition information (done in
6222 handle_composition_prop). Value is always 1. */
6225 next_element_from_composition (it
)
6228 it
->what
= IT_COMPOSITION
;
6229 it
->position
= (STRINGP (it
->string
)
6230 ? it
->current
.string_pos
6237 /***********************************************************************
6238 Moving an iterator without producing glyphs
6239 ***********************************************************************/
6241 /* Check if iterator is at a position corresponding to a valid buffer
6242 position after some move_it_ call. */
6244 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6245 ((it)->method == GET_FROM_STRING \
6246 ? IT_STRING_CHARPOS (*it) == 0 \
6250 /* Move iterator IT to a specified buffer or X position within one
6251 line on the display without producing glyphs.
6253 OP should be a bit mask including some or all of these bits:
6254 MOVE_TO_X: Stop on reaching x-position TO_X.
6255 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6256 Regardless of OP's value, stop in reaching the end of the display line.
6258 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6259 This means, in particular, that TO_X includes window's horizontal
6262 The return value has several possible values that
6263 say what condition caused the scan to stop:
6265 MOVE_POS_MATCH_OR_ZV
6266 - when TO_POS or ZV was reached.
6269 -when TO_X was reached before TO_POS or ZV were reached.
6272 - when we reached the end of the display area and the line must
6276 - when we reached the end of the display area and the line is
6280 - when we stopped at a line end, i.e. a newline or a CR and selective
6283 static enum move_it_result
6284 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6286 int to_charpos
, to_x
, op
;
6288 enum move_it_result result
= MOVE_UNDEFINED
;
6289 struct glyph_row
*saved_glyph_row
;
6291 /* Don't produce glyphs in produce_glyphs. */
6292 saved_glyph_row
= it
->glyph_row
;
6293 it
->glyph_row
= NULL
;
6295 #define BUFFER_POS_REACHED_P() \
6296 ((op & MOVE_TO_POS) != 0 \
6297 && BUFFERP (it->object) \
6298 && IT_CHARPOS (*it) >= to_charpos \
6299 && (it->method == GET_FROM_BUFFER \
6300 || (it->method == GET_FROM_DISPLAY_VECTOR \
6301 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6306 int x
, i
, ascent
= 0, descent
= 0;
6308 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6309 if ((op
& MOVE_TO_POS
) != 0
6310 && BUFFERP (it
->object
)
6311 && it
->method
== GET_FROM_BUFFER
6312 && IT_CHARPOS (*it
) > to_charpos
)
6314 result
= MOVE_POS_MATCH_OR_ZV
;
6318 /* Stop when ZV reached.
6319 We used to stop here when TO_CHARPOS reached as well, but that is
6320 too soon if this glyph does not fit on this line. So we handle it
6321 explicitly below. */
6322 if (!get_next_display_element (it
)
6323 || (it
->truncate_lines_p
6324 && BUFFER_POS_REACHED_P ()))
6326 result
= MOVE_POS_MATCH_OR_ZV
;
6330 /* The call to produce_glyphs will get the metrics of the
6331 display element IT is loaded with. We record in x the
6332 x-position before this display element in case it does not
6336 /* Remember the line height so far in case the next element doesn't
6338 if (!it
->truncate_lines_p
)
6340 ascent
= it
->max_ascent
;
6341 descent
= it
->max_descent
;
6344 PRODUCE_GLYPHS (it
);
6346 if (it
->area
!= TEXT_AREA
)
6348 set_iterator_to_next (it
, 1);
6352 /* The number of glyphs we get back in IT->nglyphs will normally
6353 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6354 character on a terminal frame, or (iii) a line end. For the
6355 second case, IT->nglyphs - 1 padding glyphs will be present
6356 (on X frames, there is only one glyph produced for a
6357 composite character.
6359 The behavior implemented below means, for continuation lines,
6360 that as many spaces of a TAB as fit on the current line are
6361 displayed there. For terminal frames, as many glyphs of a
6362 multi-glyph character are displayed in the current line, too.
6363 This is what the old redisplay code did, and we keep it that
6364 way. Under X, the whole shape of a complex character must
6365 fit on the line or it will be completely displayed in the
6368 Note that both for tabs and padding glyphs, all glyphs have
6372 /* More than one glyph or glyph doesn't fit on line. All
6373 glyphs have the same width. */
6374 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6376 int x_before_this_char
= x
;
6377 int hpos_before_this_char
= it
->hpos
;
6379 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6381 new_x
= x
+ single_glyph_width
;
6383 /* We want to leave anything reaching TO_X to the caller. */
6384 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6386 if (BUFFER_POS_REACHED_P ())
6387 goto buffer_pos_reached
;
6389 result
= MOVE_X_REACHED
;
6392 else if (/* Lines are continued. */
6393 !it
->truncate_lines_p
6394 && (/* And glyph doesn't fit on the line. */
6395 new_x
> it
->last_visible_x
6396 /* Or it fits exactly and we're on a window
6398 || (new_x
== it
->last_visible_x
6399 && FRAME_WINDOW_P (it
->f
))))
6401 if (/* IT->hpos == 0 means the very first glyph
6402 doesn't fit on the line, e.g. a wide image. */
6404 || (new_x
== it
->last_visible_x
6405 && FRAME_WINDOW_P (it
->f
)))
6408 it
->current_x
= new_x
;
6410 /* The character's last glyph just barely fits
6412 if (i
== it
->nglyphs
- 1)
6414 /* If this is the destination position,
6415 return a position *before* it in this row,
6416 now that we know it fits in this row. */
6417 if (BUFFER_POS_REACHED_P ())
6419 it
->hpos
= hpos_before_this_char
;
6420 it
->current_x
= x_before_this_char
;
6421 result
= MOVE_POS_MATCH_OR_ZV
;
6425 set_iterator_to_next (it
, 1);
6426 #ifdef HAVE_WINDOW_SYSTEM
6427 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6429 if (!get_next_display_element (it
))
6431 result
= MOVE_POS_MATCH_OR_ZV
;
6434 if (BUFFER_POS_REACHED_P ())
6436 if (ITERATOR_AT_END_OF_LINE_P (it
))
6437 result
= MOVE_POS_MATCH_OR_ZV
;
6439 result
= MOVE_LINE_CONTINUED
;
6442 if (ITERATOR_AT_END_OF_LINE_P (it
))
6444 result
= MOVE_NEWLINE_OR_CR
;
6448 #endif /* HAVE_WINDOW_SYSTEM */
6454 it
->max_ascent
= ascent
;
6455 it
->max_descent
= descent
;
6458 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6460 result
= MOVE_LINE_CONTINUED
;
6463 else if (BUFFER_POS_REACHED_P ())
6464 goto buffer_pos_reached
;
6465 else if (new_x
> it
->first_visible_x
)
6467 /* Glyph is visible. Increment number of glyphs that
6468 would be displayed. */
6473 /* Glyph is completely off the left margin of the display
6474 area. Nothing to do. */
6478 if (result
!= MOVE_UNDEFINED
)
6481 else if (BUFFER_POS_REACHED_P ())
6485 it
->max_ascent
= ascent
;
6486 it
->max_descent
= descent
;
6487 result
= MOVE_POS_MATCH_OR_ZV
;
6490 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6492 /* Stop when TO_X specified and reached. This check is
6493 necessary here because of lines consisting of a line end,
6494 only. The line end will not produce any glyphs and we
6495 would never get MOVE_X_REACHED. */
6496 xassert (it
->nglyphs
== 0);
6497 result
= MOVE_X_REACHED
;
6501 /* Is this a line end? If yes, we're done. */
6502 if (ITERATOR_AT_END_OF_LINE_P (it
))
6504 result
= MOVE_NEWLINE_OR_CR
;
6508 /* The current display element has been consumed. Advance
6510 set_iterator_to_next (it
, 1);
6512 /* Stop if lines are truncated and IT's current x-position is
6513 past the right edge of the window now. */
6514 if (it
->truncate_lines_p
6515 && it
->current_x
>= it
->last_visible_x
)
6517 #ifdef HAVE_WINDOW_SYSTEM
6518 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6520 if (!get_next_display_element (it
)
6521 || BUFFER_POS_REACHED_P ())
6523 result
= MOVE_POS_MATCH_OR_ZV
;
6526 if (ITERATOR_AT_END_OF_LINE_P (it
))
6528 result
= MOVE_NEWLINE_OR_CR
;
6532 #endif /* HAVE_WINDOW_SYSTEM */
6533 result
= MOVE_LINE_TRUNCATED
;
6538 #undef BUFFER_POS_REACHED_P
6540 /* Restore the iterator settings altered at the beginning of this
6542 it
->glyph_row
= saved_glyph_row
;
6547 /* Move IT forward until it satisfies one or more of the criteria in
6548 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6550 OP is a bit-mask that specifies where to stop, and in particular,
6551 which of those four position arguments makes a difference. See the
6552 description of enum move_operation_enum.
6554 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6555 screen line, this function will set IT to the next position >
6559 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6561 int to_charpos
, to_x
, to_y
, to_vpos
;
6564 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6570 if (op
& MOVE_TO_VPOS
)
6572 /* If no TO_CHARPOS and no TO_X specified, stop at the
6573 start of the line TO_VPOS. */
6574 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6576 if (it
->vpos
== to_vpos
)
6582 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6586 /* TO_VPOS >= 0 means stop at TO_X in the line at
6587 TO_VPOS, or at TO_POS, whichever comes first. */
6588 if (it
->vpos
== to_vpos
)
6594 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6596 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6601 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6603 /* We have reached TO_X but not in the line we want. */
6604 skip
= move_it_in_display_line_to (it
, to_charpos
,
6606 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6614 else if (op
& MOVE_TO_Y
)
6616 struct it it_backup
;
6618 /* TO_Y specified means stop at TO_X in the line containing
6619 TO_Y---or at TO_CHARPOS if this is reached first. The
6620 problem is that we can't really tell whether the line
6621 contains TO_Y before we have completely scanned it, and
6622 this may skip past TO_X. What we do is to first scan to
6625 If TO_X is not specified, use a TO_X of zero. The reason
6626 is to make the outcome of this function more predictable.
6627 If we didn't use TO_X == 0, we would stop at the end of
6628 the line which is probably not what a caller would expect
6630 skip
= move_it_in_display_line_to (it
, to_charpos
,
6634 | (op
& MOVE_TO_POS
)));
6636 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6637 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6643 /* If TO_X was reached, we would like to know whether TO_Y
6644 is in the line. This can only be said if we know the
6645 total line height which requires us to scan the rest of
6647 if (skip
== MOVE_X_REACHED
)
6650 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6651 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6653 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6656 /* Now, decide whether TO_Y is in this line. */
6657 line_height
= it
->max_ascent
+ it
->max_descent
;
6658 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6660 if (to_y
>= it
->current_y
6661 && to_y
< it
->current_y
+ line_height
)
6663 if (skip
== MOVE_X_REACHED
)
6664 /* If TO_Y is in this line and TO_X was reached above,
6665 we scanned too far. We have to restore IT's settings
6666 to the ones before skipping. */
6670 else if (skip
== MOVE_X_REACHED
)
6673 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6681 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6685 case MOVE_POS_MATCH_OR_ZV
:
6689 case MOVE_NEWLINE_OR_CR
:
6690 set_iterator_to_next (it
, 1);
6691 it
->continuation_lines_width
= 0;
6694 case MOVE_LINE_TRUNCATED
:
6695 it
->continuation_lines_width
= 0;
6696 reseat_at_next_visible_line_start (it
, 0);
6697 if ((op
& MOVE_TO_POS
) != 0
6698 && IT_CHARPOS (*it
) > to_charpos
)
6705 case MOVE_LINE_CONTINUED
:
6706 it
->continuation_lines_width
+= it
->current_x
;
6713 /* Reset/increment for the next run. */
6714 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6715 it
->current_x
= it
->hpos
= 0;
6716 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6718 last_height
= it
->max_ascent
+ it
->max_descent
;
6719 last_max_ascent
= it
->max_ascent
;
6720 it
->max_ascent
= it
->max_descent
= 0;
6725 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6729 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6731 If DY > 0, move IT backward at least that many pixels. DY = 0
6732 means move IT backward to the preceding line start or BEGV. This
6733 function may move over more than DY pixels if IT->current_y - DY
6734 ends up in the middle of a line; in this case IT->current_y will be
6735 set to the top of the line moved to. */
6738 move_it_vertically_backward (it
, dy
)
6749 start_pos
= IT_CHARPOS (*it
);
6751 /* Estimate how many newlines we must move back. */
6752 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6754 /* Set the iterator's position that many lines back. */
6755 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6756 back_to_previous_visible_line_start (it
);
6758 /* Reseat the iterator here. When moving backward, we don't want
6759 reseat to skip forward over invisible text, set up the iterator
6760 to deliver from overlay strings at the new position etc. So,
6761 use reseat_1 here. */
6762 reseat_1 (it
, it
->current
.pos
, 1);
6764 /* We are now surely at a line start. */
6765 it
->current_x
= it
->hpos
= 0;
6766 it
->continuation_lines_width
= 0;
6768 /* Move forward and see what y-distance we moved. First move to the
6769 start of the next line so that we get its height. We need this
6770 height to be able to tell whether we reached the specified
6773 it2
.max_ascent
= it2
.max_descent
= 0;
6776 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6777 MOVE_TO_POS
| MOVE_TO_VPOS
);
6779 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6780 xassert (IT_CHARPOS (*it
) >= BEGV
);
6783 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6784 xassert (IT_CHARPOS (*it
) >= BEGV
);
6785 /* H is the actual vertical distance from the position in *IT
6786 and the starting position. */
6787 h
= it2
.current_y
- it
->current_y
;
6788 /* NLINES is the distance in number of lines. */
6789 nlines
= it2
.vpos
- it
->vpos
;
6791 /* Correct IT's y and vpos position
6792 so that they are relative to the starting point. */
6798 /* DY == 0 means move to the start of the screen line. The
6799 value of nlines is > 0 if continuation lines were involved. */
6801 move_it_by_lines (it
, nlines
, 1);
6803 /* I think this assert is bogus if buffer contains
6804 invisible text or images. KFS. */
6805 xassert (IT_CHARPOS (*it
) <= start_pos
);
6810 /* The y-position we try to reach, relative to *IT.
6811 Note that H has been subtracted in front of the if-statement. */
6812 int target_y
= it
->current_y
+ h
- dy
;
6813 int y0
= it3
.current_y
;
6814 int y1
= line_bottom_y (&it3
);
6815 int line_height
= y1
- y0
;
6817 /* If we did not reach target_y, try to move further backward if
6818 we can. If we moved too far backward, try to move forward. */
6819 if (target_y
< it
->current_y
6820 /* This is heuristic. In a window that's 3 lines high, with
6821 a line height of 13 pixels each, recentering with point
6822 on the bottom line will try to move -39/2 = 19 pixels
6823 backward. Try to avoid moving into the first line. */
6824 && (it
->current_y
- target_y
6825 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6826 && IT_CHARPOS (*it
) > BEGV
)
6828 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6829 target_y
- it
->current_y
));
6830 dy
= it
->current_y
- target_y
;
6831 goto move_further_back
;
6833 else if (target_y
>= it
->current_y
+ line_height
6834 && IT_CHARPOS (*it
) < ZV
)
6836 /* Should move forward by at least one line, maybe more.
6838 Note: Calling move_it_by_lines can be expensive on
6839 terminal frames, where compute_motion is used (via
6840 vmotion) to do the job, when there are very long lines
6841 and truncate-lines is nil. That's the reason for
6842 treating terminal frames specially here. */
6844 if (!FRAME_WINDOW_P (it
->f
))
6845 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6850 move_it_by_lines (it
, 1, 1);
6852 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6856 /* I think this assert is bogus if buffer contains
6857 invisible text or images. KFS. */
6858 xassert (IT_CHARPOS (*it
) >= BEGV
);
6865 /* Move IT by a specified amount of pixel lines DY. DY negative means
6866 move backwards. DY = 0 means move to start of screen line. At the
6867 end, IT will be on the start of a screen line. */
6870 move_it_vertically (it
, dy
)
6875 move_it_vertically_backward (it
, -dy
);
6878 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6879 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6880 MOVE_TO_POS
| MOVE_TO_Y
);
6881 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6883 /* If buffer ends in ZV without a newline, move to the start of
6884 the line to satisfy the post-condition. */
6885 if (IT_CHARPOS (*it
) == ZV
6887 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6888 move_it_by_lines (it
, 0, 0);
6893 /* Move iterator IT past the end of the text line it is in. */
6896 move_it_past_eol (it
)
6899 enum move_it_result rc
;
6901 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6902 if (rc
== MOVE_NEWLINE_OR_CR
)
6903 set_iterator_to_next (it
, 0);
6907 #if 0 /* Currently not used. */
6909 /* Return non-zero if some text between buffer positions START_CHARPOS
6910 and END_CHARPOS is invisible. IT->window is the window for text
6914 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6916 int start_charpos
, end_charpos
;
6918 Lisp_Object prop
, limit
;
6919 int invisible_found_p
;
6921 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6923 /* Is text at START invisible? */
6924 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6926 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6927 invisible_found_p
= 1;
6930 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6932 make_number (end_charpos
));
6933 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6936 return invisible_found_p
;
6942 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6943 negative means move up. DVPOS == 0 means move to the start of the
6944 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6945 NEED_Y_P is zero, IT->current_y will be left unchanged.
6947 Further optimization ideas: If we would know that IT->f doesn't use
6948 a face with proportional font, we could be faster for
6949 truncate-lines nil. */
6952 move_it_by_lines (it
, dvpos
, need_y_p
)
6954 int dvpos
, need_y_p
;
6956 struct position pos
;
6958 if (!FRAME_WINDOW_P (it
->f
))
6960 struct text_pos textpos
;
6962 /* We can use vmotion on frames without proportional fonts. */
6963 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6964 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6965 reseat (it
, textpos
, 1);
6966 it
->vpos
+= pos
.vpos
;
6967 it
->current_y
+= pos
.vpos
;
6969 else if (dvpos
== 0)
6971 /* DVPOS == 0 means move to the start of the screen line. */
6972 move_it_vertically_backward (it
, 0);
6973 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6974 /* Let next call to line_bottom_y calculate real line height */
6979 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6980 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6981 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6986 int start_charpos
, i
;
6988 /* Start at the beginning of the screen line containing IT's
6989 position. This may actually move vertically backwards,
6990 in case of overlays, so adjust dvpos accordingly. */
6992 move_it_vertically_backward (it
, 0);
6995 /* Go back -DVPOS visible lines and reseat the iterator there. */
6996 start_charpos
= IT_CHARPOS (*it
);
6997 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6998 back_to_previous_visible_line_start (it
);
6999 reseat (it
, it
->current
.pos
, 1);
7001 /* Move further back if we end up in a string or an image. */
7002 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7004 /* First try to move to start of display line. */
7006 move_it_vertically_backward (it
, 0);
7008 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7010 /* If start of line is still in string or image,
7011 move further back. */
7012 back_to_previous_visible_line_start (it
);
7013 reseat (it
, it
->current
.pos
, 1);
7017 it
->current_x
= it
->hpos
= 0;
7019 /* Above call may have moved too far if continuation lines
7020 are involved. Scan forward and see if it did. */
7022 it2
.vpos
= it2
.current_y
= 0;
7023 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7024 it
->vpos
-= it2
.vpos
;
7025 it
->current_y
-= it2
.current_y
;
7026 it
->current_x
= it
->hpos
= 0;
7028 /* If we moved too far back, move IT some lines forward. */
7029 if (it2
.vpos
> -dvpos
)
7031 int delta
= it2
.vpos
+ dvpos
;
7033 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7034 /* Move back again if we got too far ahead. */
7035 if (IT_CHARPOS (*it
) >= start_charpos
)
7041 /* Return 1 if IT points into the middle of a display vector. */
7044 in_display_vector_p (it
)
7047 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7048 && it
->current
.dpvec_index
> 0
7049 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7053 /***********************************************************************
7055 ***********************************************************************/
7058 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7062 add_to_log (format
, arg1
, arg2
)
7064 Lisp_Object arg1
, arg2
;
7066 Lisp_Object args
[3];
7067 Lisp_Object msg
, fmt
;
7070 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7073 /* Do nothing if called asynchronously. Inserting text into
7074 a buffer may call after-change-functions and alike and
7075 that would means running Lisp asynchronously. */
7076 if (handling_signal
)
7080 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7082 args
[0] = fmt
= build_string (format
);
7085 msg
= Fformat (3, args
);
7087 len
= SBYTES (msg
) + 1;
7088 SAFE_ALLOCA (buffer
, char *, len
);
7089 bcopy (SDATA (msg
), buffer
, len
);
7091 message_dolog (buffer
, len
- 1, 1, 0);
7098 /* Output a newline in the *Messages* buffer if "needs" one. */
7101 message_log_maybe_newline ()
7103 if (message_log_need_newline
)
7104 message_dolog ("", 0, 1, 0);
7108 /* Add a string M of length NBYTES to the message log, optionally
7109 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7110 nonzero, means interpret the contents of M as multibyte. This
7111 function calls low-level routines in order to bypass text property
7112 hooks, etc. which might not be safe to run.
7114 This may GC (insert may run before/after change hooks),
7115 so the buffer M must NOT point to a Lisp string. */
7118 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7120 int nbytes
, nlflag
, multibyte
;
7122 if (!NILP (Vmemory_full
))
7125 if (!NILP (Vmessage_log_max
))
7127 struct buffer
*oldbuf
;
7128 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7129 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7130 int point_at_end
= 0;
7132 Lisp_Object old_deactivate_mark
, tem
;
7133 struct gcpro gcpro1
;
7135 old_deactivate_mark
= Vdeactivate_mark
;
7136 oldbuf
= current_buffer
;
7137 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7138 current_buffer
->undo_list
= Qt
;
7140 oldpoint
= message_dolog_marker1
;
7141 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7142 oldbegv
= message_dolog_marker2
;
7143 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7144 oldzv
= message_dolog_marker3
;
7145 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7146 GCPRO1 (old_deactivate_mark
);
7154 BEGV_BYTE
= BEG_BYTE
;
7157 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7159 /* Insert the string--maybe converting multibyte to single byte
7160 or vice versa, so that all the text fits the buffer. */
7162 && NILP (current_buffer
->enable_multibyte_characters
))
7164 int i
, c
, char_bytes
;
7165 unsigned char work
[1];
7167 /* Convert a multibyte string to single-byte
7168 for the *Message* buffer. */
7169 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7171 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7172 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7174 : multibyte_char_to_unibyte (c
, Qnil
));
7175 insert_1_both (work
, 1, 1, 1, 0, 0);
7178 else if (! multibyte
7179 && ! NILP (current_buffer
->enable_multibyte_characters
))
7181 int i
, c
, char_bytes
;
7182 unsigned char *msg
= (unsigned char *) m
;
7183 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7184 /* Convert a single-byte string to multibyte
7185 for the *Message* buffer. */
7186 for (i
= 0; i
< nbytes
; i
++)
7188 c
= unibyte_char_to_multibyte (msg
[i
]);
7189 char_bytes
= CHAR_STRING (c
, str
);
7190 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7194 insert_1 (m
, nbytes
, 1, 0, 0);
7198 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7199 insert_1 ("\n", 1, 1, 0, 0);
7201 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7203 this_bol_byte
= PT_BYTE
;
7205 /* See if this line duplicates the previous one.
7206 If so, combine duplicates. */
7209 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7211 prev_bol_byte
= PT_BYTE
;
7213 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7214 this_bol
, this_bol_byte
);
7217 del_range_both (prev_bol
, prev_bol_byte
,
7218 this_bol
, this_bol_byte
, 0);
7224 /* If you change this format, don't forget to also
7225 change message_log_check_duplicate. */
7226 sprintf (dupstr
, " [%d times]", dup
);
7227 duplen
= strlen (dupstr
);
7228 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7229 insert_1 (dupstr
, duplen
, 1, 0, 1);
7234 /* If we have more than the desired maximum number of lines
7235 in the *Messages* buffer now, delete the oldest ones.
7236 This is safe because we don't have undo in this buffer. */
7238 if (NATNUMP (Vmessage_log_max
))
7240 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7241 -XFASTINT (Vmessage_log_max
) - 1, 0);
7242 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7245 BEGV
= XMARKER (oldbegv
)->charpos
;
7246 BEGV_BYTE
= marker_byte_position (oldbegv
);
7255 ZV
= XMARKER (oldzv
)->charpos
;
7256 ZV_BYTE
= marker_byte_position (oldzv
);
7260 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7262 /* We can't do Fgoto_char (oldpoint) because it will run some
7264 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7265 XMARKER (oldpoint
)->bytepos
);
7268 unchain_marker (XMARKER (oldpoint
));
7269 unchain_marker (XMARKER (oldbegv
));
7270 unchain_marker (XMARKER (oldzv
));
7272 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7273 set_buffer_internal (oldbuf
);
7275 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7276 message_log_need_newline
= !nlflag
;
7277 Vdeactivate_mark
= old_deactivate_mark
;
7282 /* We are at the end of the buffer after just having inserted a newline.
7283 (Note: We depend on the fact we won't be crossing the gap.)
7284 Check to see if the most recent message looks a lot like the previous one.
7285 Return 0 if different, 1 if the new one should just replace it, or a
7286 value N > 1 if we should also append " [N times]". */
7289 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7290 int prev_bol
, this_bol
;
7291 int prev_bol_byte
, this_bol_byte
;
7294 int len
= Z_BYTE
- 1 - this_bol_byte
;
7296 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7297 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7299 for (i
= 0; i
< len
; i
++)
7301 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7309 if (*p1
++ == ' ' && *p1
++ == '[')
7312 while (*p1
>= '0' && *p1
<= '9')
7313 n
= n
* 10 + *p1
++ - '0';
7314 if (strncmp (p1
, " times]\n", 8) == 0)
7321 /* Display an echo area message M with a specified length of NBYTES
7322 bytes. The string may include null characters. If M is 0, clear
7323 out any existing message, and let the mini-buffer text show
7326 This may GC, so the buffer M must NOT point to a Lisp string. */
7329 message2 (m
, nbytes
, multibyte
)
7334 /* First flush out any partial line written with print. */
7335 message_log_maybe_newline ();
7337 message_dolog (m
, nbytes
, 1, multibyte
);
7338 message2_nolog (m
, nbytes
, multibyte
);
7342 /* The non-logging counterpart of message2. */
7345 message2_nolog (m
, nbytes
, multibyte
)
7347 int nbytes
, multibyte
;
7349 struct frame
*sf
= SELECTED_FRAME ();
7350 message_enable_multibyte
= multibyte
;
7354 if (noninteractive_need_newline
)
7355 putc ('\n', stderr
);
7356 noninteractive_need_newline
= 0;
7358 fwrite (m
, nbytes
, 1, stderr
);
7359 if (cursor_in_echo_area
== 0)
7360 fprintf (stderr
, "\n");
7363 /* A null message buffer means that the frame hasn't really been
7364 initialized yet. Error messages get reported properly by
7365 cmd_error, so this must be just an informative message; toss it. */
7366 else if (INTERACTIVE
7367 && sf
->glyphs_initialized_p
7368 && FRAME_MESSAGE_BUF (sf
))
7370 Lisp_Object mini_window
;
7373 /* Get the frame containing the mini-buffer
7374 that the selected frame is using. */
7375 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7376 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7378 FRAME_SAMPLE_VISIBILITY (f
);
7379 if (FRAME_VISIBLE_P (sf
)
7380 && ! FRAME_VISIBLE_P (f
))
7381 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7385 set_message (m
, Qnil
, nbytes
, multibyte
);
7386 if (minibuffer_auto_raise
)
7387 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7390 clear_message (1, 1);
7392 do_pending_window_change (0);
7393 echo_area_display (1);
7394 do_pending_window_change (0);
7395 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7396 (*frame_up_to_date_hook
) (f
);
7401 /* Display an echo area message M with a specified length of NBYTES
7402 bytes. The string may include null characters. If M is not a
7403 string, clear out any existing message, and let the mini-buffer
7406 This function cancels echoing. */
7409 message3 (m
, nbytes
, multibyte
)
7414 struct gcpro gcpro1
;
7417 clear_message (1,1);
7420 /* First flush out any partial line written with print. */
7421 message_log_maybe_newline ();
7427 SAFE_ALLOCA (buffer
, char *, nbytes
);
7428 bcopy (SDATA (m
), buffer
, nbytes
);
7429 message_dolog (buffer
, nbytes
, 1, multibyte
);
7432 message3_nolog (m
, nbytes
, multibyte
);
7438 /* The non-logging version of message3.
7439 This does not cancel echoing, because it is used for echoing.
7440 Perhaps we need to make a separate function for echoing
7441 and make this cancel echoing. */
7444 message3_nolog (m
, nbytes
, multibyte
)
7446 int nbytes
, multibyte
;
7448 struct frame
*sf
= SELECTED_FRAME ();
7449 message_enable_multibyte
= multibyte
;
7453 if (noninteractive_need_newline
)
7454 putc ('\n', stderr
);
7455 noninteractive_need_newline
= 0;
7457 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7458 if (cursor_in_echo_area
== 0)
7459 fprintf (stderr
, "\n");
7462 /* A null message buffer means that the frame hasn't really been
7463 initialized yet. Error messages get reported properly by
7464 cmd_error, so this must be just an informative message; toss it. */
7465 else if (INTERACTIVE
7466 && sf
->glyphs_initialized_p
7467 && FRAME_MESSAGE_BUF (sf
))
7469 Lisp_Object mini_window
;
7473 /* Get the frame containing the mini-buffer
7474 that the selected frame is using. */
7475 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7476 frame
= XWINDOW (mini_window
)->frame
;
7479 FRAME_SAMPLE_VISIBILITY (f
);
7480 if (FRAME_VISIBLE_P (sf
)
7481 && !FRAME_VISIBLE_P (f
))
7482 Fmake_frame_visible (frame
);
7484 if (STRINGP (m
) && SCHARS (m
) > 0)
7486 set_message (NULL
, m
, nbytes
, multibyte
);
7487 if (minibuffer_auto_raise
)
7488 Fraise_frame (frame
);
7489 /* Assume we are not echoing.
7490 (If we are, echo_now will override this.) */
7491 echo_message_buffer
= Qnil
;
7494 clear_message (1, 1);
7496 do_pending_window_change (0);
7497 echo_area_display (1);
7498 do_pending_window_change (0);
7499 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7500 (*frame_up_to_date_hook
) (f
);
7505 /* Display a null-terminated echo area message M. If M is 0, clear
7506 out any existing message, and let the mini-buffer text show through.
7508 The buffer M must continue to exist until after the echo area gets
7509 cleared or some other message gets displayed there. Do not pass
7510 text that is stored in a Lisp string. Do not pass text in a buffer
7511 that was alloca'd. */
7517 message2 (m
, (m
? strlen (m
) : 0), 0);
7521 /* The non-logging counterpart of message1. */
7527 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7530 /* Display a message M which contains a single %s
7531 which gets replaced with STRING. */
7534 message_with_string (m
, string
, log
)
7539 CHECK_STRING (string
);
7545 if (noninteractive_need_newline
)
7546 putc ('\n', stderr
);
7547 noninteractive_need_newline
= 0;
7548 fprintf (stderr
, m
, SDATA (string
));
7549 if (cursor_in_echo_area
== 0)
7550 fprintf (stderr
, "\n");
7554 else if (INTERACTIVE
)
7556 /* The frame whose minibuffer we're going to display the message on.
7557 It may be larger than the selected frame, so we need
7558 to use its buffer, not the selected frame's buffer. */
7559 Lisp_Object mini_window
;
7560 struct frame
*f
, *sf
= SELECTED_FRAME ();
7562 /* Get the frame containing the minibuffer
7563 that the selected frame is using. */
7564 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7565 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7567 /* A null message buffer means that the frame hasn't really been
7568 initialized yet. Error messages get reported properly by
7569 cmd_error, so this must be just an informative message; toss it. */
7570 if (FRAME_MESSAGE_BUF (f
))
7572 Lisp_Object args
[2], message
;
7573 struct gcpro gcpro1
, gcpro2
;
7575 args
[0] = build_string (m
);
7576 args
[1] = message
= string
;
7577 GCPRO2 (args
[0], message
);
7580 message
= Fformat (2, args
);
7583 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7585 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7589 /* Print should start at the beginning of the message
7590 buffer next time. */
7591 message_buf_print
= 0;
7597 /* Dump an informative message to the minibuf. If M is 0, clear out
7598 any existing message, and let the mini-buffer text show through. */
7602 message (m
, a1
, a2
, a3
)
7604 EMACS_INT a1
, a2
, a3
;
7610 if (noninteractive_need_newline
)
7611 putc ('\n', stderr
);
7612 noninteractive_need_newline
= 0;
7613 fprintf (stderr
, m
, a1
, a2
, a3
);
7614 if (cursor_in_echo_area
== 0)
7615 fprintf (stderr
, "\n");
7619 else if (INTERACTIVE
)
7621 /* The frame whose mini-buffer we're going to display the message
7622 on. It may be larger than the selected frame, so we need to
7623 use its buffer, not the selected frame's buffer. */
7624 Lisp_Object mini_window
;
7625 struct frame
*f
, *sf
= SELECTED_FRAME ();
7627 /* Get the frame containing the mini-buffer
7628 that the selected frame is using. */
7629 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7630 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7632 /* A null message buffer means that the frame hasn't really been
7633 initialized yet. Error messages get reported properly by
7634 cmd_error, so this must be just an informative message; toss
7636 if (FRAME_MESSAGE_BUF (f
))
7647 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7648 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7650 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7651 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7653 #endif /* NO_ARG_ARRAY */
7655 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7660 /* Print should start at the beginning of the message
7661 buffer next time. */
7662 message_buf_print
= 0;
7668 /* The non-logging version of message. */
7671 message_nolog (m
, a1
, a2
, a3
)
7673 EMACS_INT a1
, a2
, a3
;
7675 Lisp_Object old_log_max
;
7676 old_log_max
= Vmessage_log_max
;
7677 Vmessage_log_max
= Qnil
;
7678 message (m
, a1
, a2
, a3
);
7679 Vmessage_log_max
= old_log_max
;
7683 /* Display the current message in the current mini-buffer. This is
7684 only called from error handlers in process.c, and is not time
7690 if (!NILP (echo_area_buffer
[0]))
7693 string
= Fcurrent_message ();
7694 message3 (string
, SBYTES (string
),
7695 !NILP (current_buffer
->enable_multibyte_characters
));
7700 /* Make sure echo area buffers in `echo_buffers' are live.
7701 If they aren't, make new ones. */
7704 ensure_echo_area_buffers ()
7708 for (i
= 0; i
< 2; ++i
)
7709 if (!BUFFERP (echo_buffer
[i
])
7710 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7713 Lisp_Object old_buffer
;
7716 old_buffer
= echo_buffer
[i
];
7717 sprintf (name
, " *Echo Area %d*", i
);
7718 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7719 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7721 for (j
= 0; j
< 2; ++j
)
7722 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7723 echo_area_buffer
[j
] = echo_buffer
[i
];
7728 /* Call FN with args A1..A4 with either the current or last displayed
7729 echo_area_buffer as current buffer.
7731 WHICH zero means use the current message buffer
7732 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7733 from echo_buffer[] and clear it.
7735 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7736 suitable buffer from echo_buffer[] and clear it.
7738 Value is what FN returns. */
7741 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7744 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7750 int this_one
, the_other
, clear_buffer_p
, rc
;
7751 int count
= SPECPDL_INDEX ();
7753 /* If buffers aren't live, make new ones. */
7754 ensure_echo_area_buffers ();
7759 this_one
= 0, the_other
= 1;
7761 this_one
= 1, the_other
= 0;
7763 /* Choose a suitable buffer from echo_buffer[] is we don't
7765 if (NILP (echo_area_buffer
[this_one
]))
7767 echo_area_buffer
[this_one
]
7768 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7769 ? echo_buffer
[the_other
]
7770 : echo_buffer
[this_one
]);
7774 buffer
= echo_area_buffer
[this_one
];
7776 /* Don't get confused by reusing the buffer used for echoing
7777 for a different purpose. */
7778 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7781 record_unwind_protect (unwind_with_echo_area_buffer
,
7782 with_echo_area_buffer_unwind_data (w
));
7784 /* Make the echo area buffer current. Note that for display
7785 purposes, it is not necessary that the displayed window's buffer
7786 == current_buffer, except for text property lookup. So, let's
7787 only set that buffer temporarily here without doing a full
7788 Fset_window_buffer. We must also change w->pointm, though,
7789 because otherwise an assertions in unshow_buffer fails, and Emacs
7791 set_buffer_internal_1 (XBUFFER (buffer
));
7795 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7798 current_buffer
->undo_list
= Qt
;
7799 current_buffer
->read_only
= Qnil
;
7800 specbind (Qinhibit_read_only
, Qt
);
7801 specbind (Qinhibit_modification_hooks
, Qt
);
7803 if (clear_buffer_p
&& Z
> BEG
)
7806 xassert (BEGV
>= BEG
);
7807 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7809 rc
= fn (a1
, a2
, a3
, a4
);
7811 xassert (BEGV
>= BEG
);
7812 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7814 unbind_to (count
, Qnil
);
7819 /* Save state that should be preserved around the call to the function
7820 FN called in with_echo_area_buffer. */
7823 with_echo_area_buffer_unwind_data (w
)
7829 /* Reduce consing by keeping one vector in
7830 Vwith_echo_area_save_vector. */
7831 vector
= Vwith_echo_area_save_vector
;
7832 Vwith_echo_area_save_vector
= Qnil
;
7835 vector
= Fmake_vector (make_number (7), Qnil
);
7837 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7838 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7839 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7843 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7844 AREF (vector
, i
) = w
->buffer
; ++i
;
7845 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7846 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7851 for (; i
< end
; ++i
)
7852 AREF (vector
, i
) = Qnil
;
7855 xassert (i
== ASIZE (vector
));
7860 /* Restore global state from VECTOR which was created by
7861 with_echo_area_buffer_unwind_data. */
7864 unwind_with_echo_area_buffer (vector
)
7867 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7868 Vdeactivate_mark
= AREF (vector
, 1);
7869 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7871 if (WINDOWP (AREF (vector
, 3)))
7874 Lisp_Object buffer
, charpos
, bytepos
;
7876 w
= XWINDOW (AREF (vector
, 3));
7877 buffer
= AREF (vector
, 4);
7878 charpos
= AREF (vector
, 5);
7879 bytepos
= AREF (vector
, 6);
7882 set_marker_both (w
->pointm
, buffer
,
7883 XFASTINT (charpos
), XFASTINT (bytepos
));
7886 Vwith_echo_area_save_vector
= vector
;
7891 /* Set up the echo area for use by print functions. MULTIBYTE_P
7892 non-zero means we will print multibyte. */
7895 setup_echo_area_for_printing (multibyte_p
)
7898 /* If we can't find an echo area any more, exit. */
7899 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7902 ensure_echo_area_buffers ();
7904 if (!message_buf_print
)
7906 /* A message has been output since the last time we printed.
7907 Choose a fresh echo area buffer. */
7908 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7909 echo_area_buffer
[0] = echo_buffer
[1];
7911 echo_area_buffer
[0] = echo_buffer
[0];
7913 /* Switch to that buffer and clear it. */
7914 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7915 current_buffer
->truncate_lines
= Qnil
;
7919 int count
= SPECPDL_INDEX ();
7920 specbind (Qinhibit_read_only
, Qt
);
7921 /* Note that undo recording is always disabled. */
7923 unbind_to (count
, Qnil
);
7925 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7927 /* Set up the buffer for the multibyteness we need. */
7929 != !NILP (current_buffer
->enable_multibyte_characters
))
7930 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7932 /* Raise the frame containing the echo area. */
7933 if (minibuffer_auto_raise
)
7935 struct frame
*sf
= SELECTED_FRAME ();
7936 Lisp_Object mini_window
;
7937 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7938 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7941 message_log_maybe_newline ();
7942 message_buf_print
= 1;
7946 if (NILP (echo_area_buffer
[0]))
7948 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7949 echo_area_buffer
[0] = echo_buffer
[1];
7951 echo_area_buffer
[0] = echo_buffer
[0];
7954 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7956 /* Someone switched buffers between print requests. */
7957 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7958 current_buffer
->truncate_lines
= Qnil
;
7964 /* Display an echo area message in window W. Value is non-zero if W's
7965 height is changed. If display_last_displayed_message_p is
7966 non-zero, display the message that was last displayed, otherwise
7967 display the current message. */
7970 display_echo_area (w
)
7973 int i
, no_message_p
, window_height_changed_p
, count
;
7975 /* Temporarily disable garbage collections while displaying the echo
7976 area. This is done because a GC can print a message itself.
7977 That message would modify the echo area buffer's contents while a
7978 redisplay of the buffer is going on, and seriously confuse
7980 count
= inhibit_garbage_collection ();
7982 /* If there is no message, we must call display_echo_area_1
7983 nevertheless because it resizes the window. But we will have to
7984 reset the echo_area_buffer in question to nil at the end because
7985 with_echo_area_buffer will sets it to an empty buffer. */
7986 i
= display_last_displayed_message_p
? 1 : 0;
7987 no_message_p
= NILP (echo_area_buffer
[i
]);
7989 window_height_changed_p
7990 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7991 display_echo_area_1
,
7992 (EMACS_INT
) w
, Qnil
, 0, 0);
7995 echo_area_buffer
[i
] = Qnil
;
7997 unbind_to (count
, Qnil
);
7998 return window_height_changed_p
;
8002 /* Helper for display_echo_area. Display the current buffer which
8003 contains the current echo area message in window W, a mini-window,
8004 a pointer to which is passed in A1. A2..A4 are currently not used.
8005 Change the height of W so that all of the message is displayed.
8006 Value is non-zero if height of W was changed. */
8009 display_echo_area_1 (a1
, a2
, a3
, a4
)
8014 struct window
*w
= (struct window
*) a1
;
8016 struct text_pos start
;
8017 int window_height_changed_p
= 0;
8019 /* Do this before displaying, so that we have a large enough glyph
8020 matrix for the display. If we can't get enough space for the
8021 whole text, display the last N lines. That works by setting w->start. */
8022 window_height_changed_p
= resize_mini_window (w
, 0);
8024 /* Use the starting position chosen by resize_mini_window. */
8025 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8028 clear_glyph_matrix (w
->desired_matrix
);
8029 XSETWINDOW (window
, w
);
8030 try_window (window
, start
, 0);
8032 return window_height_changed_p
;
8036 /* Resize the echo area window to exactly the size needed for the
8037 currently displayed message, if there is one. If a mini-buffer
8038 is active, don't shrink it. */
8041 resize_echo_area_exactly ()
8043 if (BUFFERP (echo_area_buffer
[0])
8044 && WINDOWP (echo_area_window
))
8046 struct window
*w
= XWINDOW (echo_area_window
);
8048 Lisp_Object resize_exactly
;
8050 if (minibuf_level
== 0)
8051 resize_exactly
= Qt
;
8053 resize_exactly
= Qnil
;
8055 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8056 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8059 ++windows_or_buffers_changed
;
8060 ++update_mode_lines
;
8061 redisplay_internal (0);
8067 /* Callback function for with_echo_area_buffer, when used from
8068 resize_echo_area_exactly. A1 contains a pointer to the window to
8069 resize, EXACTLY non-nil means resize the mini-window exactly to the
8070 size of the text displayed. A3 and A4 are not used. Value is what
8071 resize_mini_window returns. */
8074 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8076 Lisp_Object exactly
;
8079 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8083 /* Resize mini-window W to fit the size of its contents. EXACT:P
8084 means size the window exactly to the size needed. Otherwise, it's
8085 only enlarged until W's buffer is empty.
8087 Set W->start to the right place to begin display. If the whole
8088 contents fit, start at the beginning. Otherwise, start so as
8089 to make the end of the contents appear. This is particularly
8090 important for y-or-n-p, but seems desirable generally.
8092 Value is non-zero if the window height has been changed. */
8095 resize_mini_window (w
, exact_p
)
8099 struct frame
*f
= XFRAME (w
->frame
);
8100 int window_height_changed_p
= 0;
8102 xassert (MINI_WINDOW_P (w
));
8104 /* By default, start display at the beginning. */
8105 set_marker_both (w
->start
, w
->buffer
,
8106 BUF_BEGV (XBUFFER (w
->buffer
)),
8107 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8109 /* Don't resize windows while redisplaying a window; it would
8110 confuse redisplay functions when the size of the window they are
8111 displaying changes from under them. Such a resizing can happen,
8112 for instance, when which-func prints a long message while
8113 we are running fontification-functions. We're running these
8114 functions with safe_call which binds inhibit-redisplay to t. */
8115 if (!NILP (Vinhibit_redisplay
))
8118 /* Nil means don't try to resize. */
8119 if (NILP (Vresize_mini_windows
)
8120 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8123 if (!FRAME_MINIBUF_ONLY_P (f
))
8126 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8127 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8128 int height
, max_height
;
8129 int unit
= FRAME_LINE_HEIGHT (f
);
8130 struct text_pos start
;
8131 struct buffer
*old_current_buffer
= NULL
;
8133 if (current_buffer
!= XBUFFER (w
->buffer
))
8135 old_current_buffer
= current_buffer
;
8136 set_buffer_internal (XBUFFER (w
->buffer
));
8139 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8141 /* Compute the max. number of lines specified by the user. */
8142 if (FLOATP (Vmax_mini_window_height
))
8143 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8144 else if (INTEGERP (Vmax_mini_window_height
))
8145 max_height
= XINT (Vmax_mini_window_height
);
8147 max_height
= total_height
/ 4;
8149 /* Correct that max. height if it's bogus. */
8150 max_height
= max (1, max_height
);
8151 max_height
= min (total_height
, max_height
);
8153 /* Find out the height of the text in the window. */
8154 if (it
.truncate_lines_p
)
8159 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8160 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8161 height
= it
.current_y
+ last_height
;
8163 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8164 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8165 height
= (height
+ unit
- 1) / unit
;
8168 /* Compute a suitable window start. */
8169 if (height
> max_height
)
8171 height
= max_height
;
8172 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8173 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8174 start
= it
.current
.pos
;
8177 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8178 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8180 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8182 /* Let it grow only, until we display an empty message, in which
8183 case the window shrinks again. */
8184 if (height
> WINDOW_TOTAL_LINES (w
))
8186 int old_height
= WINDOW_TOTAL_LINES (w
);
8187 freeze_window_starts (f
, 1);
8188 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8189 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8191 else if (height
< WINDOW_TOTAL_LINES (w
)
8192 && (exact_p
|| BEGV
== ZV
))
8194 int old_height
= WINDOW_TOTAL_LINES (w
);
8195 freeze_window_starts (f
, 0);
8196 shrink_mini_window (w
);
8197 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8202 /* Always resize to exact size needed. */
8203 if (height
> WINDOW_TOTAL_LINES (w
))
8205 int old_height
= WINDOW_TOTAL_LINES (w
);
8206 freeze_window_starts (f
, 1);
8207 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8208 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8210 else if (height
< WINDOW_TOTAL_LINES (w
))
8212 int old_height
= WINDOW_TOTAL_LINES (w
);
8213 freeze_window_starts (f
, 0);
8214 shrink_mini_window (w
);
8218 freeze_window_starts (f
, 1);
8219 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8222 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8226 if (old_current_buffer
)
8227 set_buffer_internal (old_current_buffer
);
8230 return window_height_changed_p
;
8234 /* Value is the current message, a string, or nil if there is no
8242 if (NILP (echo_area_buffer
[0]))
8246 with_echo_area_buffer (0, 0, current_message_1
,
8247 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8249 echo_area_buffer
[0] = Qnil
;
8257 current_message_1 (a1
, a2
, a3
, a4
)
8262 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8265 *msg
= make_buffer_string (BEG
, Z
, 1);
8272 /* Push the current message on Vmessage_stack for later restauration
8273 by restore_message. Value is non-zero if the current message isn't
8274 empty. This is a relatively infrequent operation, so it's not
8275 worth optimizing. */
8281 msg
= current_message ();
8282 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8283 return STRINGP (msg
);
8287 /* Restore message display from the top of Vmessage_stack. */
8294 xassert (CONSP (Vmessage_stack
));
8295 msg
= XCAR (Vmessage_stack
);
8297 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8299 message3_nolog (msg
, 0, 0);
8303 /* Handler for record_unwind_protect calling pop_message. */
8306 pop_message_unwind (dummy
)
8313 /* Pop the top-most entry off Vmessage_stack. */
8318 xassert (CONSP (Vmessage_stack
));
8319 Vmessage_stack
= XCDR (Vmessage_stack
);
8323 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8324 exits. If the stack is not empty, we have a missing pop_message
8328 check_message_stack ()
8330 if (!NILP (Vmessage_stack
))
8335 /* Truncate to NCHARS what will be displayed in the echo area the next
8336 time we display it---but don't redisplay it now. */
8339 truncate_echo_area (nchars
)
8343 echo_area_buffer
[0] = Qnil
;
8344 /* A null message buffer means that the frame hasn't really been
8345 initialized yet. Error messages get reported properly by
8346 cmd_error, so this must be just an informative message; toss it. */
8347 else if (!noninteractive
8349 && !NILP (echo_area_buffer
[0]))
8351 struct frame
*sf
= SELECTED_FRAME ();
8352 if (FRAME_MESSAGE_BUF (sf
))
8353 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8358 /* Helper function for truncate_echo_area. Truncate the current
8359 message to at most NCHARS characters. */
8362 truncate_message_1 (nchars
, a2
, a3
, a4
)
8367 if (BEG
+ nchars
< Z
)
8368 del_range (BEG
+ nchars
, Z
);
8370 echo_area_buffer
[0] = Qnil
;
8375 /* Set the current message to a substring of S or STRING.
8377 If STRING is a Lisp string, set the message to the first NBYTES
8378 bytes from STRING. NBYTES zero means use the whole string. If
8379 STRING is multibyte, the message will be displayed multibyte.
8381 If S is not null, set the message to the first LEN bytes of S. LEN
8382 zero means use the whole string. MULTIBYTE_P non-zero means S is
8383 multibyte. Display the message multibyte in that case.
8385 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8386 to t before calling set_message_1 (which calls insert).
8390 set_message (s
, string
, nbytes
, multibyte_p
)
8393 int nbytes
, multibyte_p
;
8395 message_enable_multibyte
8396 = ((s
&& multibyte_p
)
8397 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8399 with_echo_area_buffer (0, 0, set_message_1
,
8400 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8401 message_buf_print
= 0;
8402 help_echo_showing_p
= 0;
8406 /* Helper function for set_message. Arguments have the same meaning
8407 as there, with A1 corresponding to S and A2 corresponding to STRING
8408 This function is called with the echo area buffer being
8412 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8415 EMACS_INT nbytes
, multibyte_p
;
8417 const char *s
= (const char *) a1
;
8418 Lisp_Object string
= a2
;
8420 /* Change multibyteness of the echo buffer appropriately. */
8421 if (message_enable_multibyte
8422 != !NILP (current_buffer
->enable_multibyte_characters
))
8423 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8425 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8427 /* Insert new message at BEG. */
8428 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8431 if (STRINGP (string
))
8436 nbytes
= SBYTES (string
);
8437 nchars
= string_byte_to_char (string
, nbytes
);
8439 /* This function takes care of single/multibyte conversion. We
8440 just have to ensure that the echo area buffer has the right
8441 setting of enable_multibyte_characters. */
8442 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8447 nbytes
= strlen (s
);
8449 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8451 /* Convert from multi-byte to single-byte. */
8453 unsigned char work
[1];
8455 /* Convert a multibyte string to single-byte. */
8456 for (i
= 0; i
< nbytes
; i
+= n
)
8458 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8459 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8461 : multibyte_char_to_unibyte (c
, Qnil
));
8462 insert_1_both (work
, 1, 1, 1, 0, 0);
8465 else if (!multibyte_p
8466 && !NILP (current_buffer
->enable_multibyte_characters
))
8468 /* Convert from single-byte to multi-byte. */
8470 const unsigned char *msg
= (const unsigned char *) s
;
8471 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8473 /* Convert a single-byte string to multibyte. */
8474 for (i
= 0; i
< nbytes
; i
++)
8476 c
= unibyte_char_to_multibyte (msg
[i
]);
8477 n
= CHAR_STRING (c
, str
);
8478 insert_1_both (str
, 1, n
, 1, 0, 0);
8482 insert_1 (s
, nbytes
, 1, 0, 0);
8489 /* Clear messages. CURRENT_P non-zero means clear the current
8490 message. LAST_DISPLAYED_P non-zero means clear the message
8494 clear_message (current_p
, last_displayed_p
)
8495 int current_p
, last_displayed_p
;
8499 echo_area_buffer
[0] = Qnil
;
8500 message_cleared_p
= 1;
8503 if (last_displayed_p
)
8504 echo_area_buffer
[1] = Qnil
;
8506 message_buf_print
= 0;
8509 /* Clear garbaged frames.
8511 This function is used where the old redisplay called
8512 redraw_garbaged_frames which in turn called redraw_frame which in
8513 turn called clear_frame. The call to clear_frame was a source of
8514 flickering. I believe a clear_frame is not necessary. It should
8515 suffice in the new redisplay to invalidate all current matrices,
8516 and ensure a complete redisplay of all windows. */
8519 clear_garbaged_frames ()
8523 Lisp_Object tail
, frame
;
8524 int changed_count
= 0;
8526 FOR_EACH_FRAME (tail
, frame
)
8528 struct frame
*f
= XFRAME (frame
);
8530 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8534 Fredraw_frame (frame
);
8535 f
->force_flush_display_p
= 1;
8537 clear_current_matrices (f
);
8546 ++windows_or_buffers_changed
;
8551 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8552 is non-zero update selected_frame. Value is non-zero if the
8553 mini-windows height has been changed. */
8556 echo_area_display (update_frame_p
)
8559 Lisp_Object mini_window
;
8562 int window_height_changed_p
= 0;
8563 struct frame
*sf
= SELECTED_FRAME ();
8565 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8566 w
= XWINDOW (mini_window
);
8567 f
= XFRAME (WINDOW_FRAME (w
));
8569 /* Don't display if frame is invisible or not yet initialized. */
8570 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8573 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8575 #ifdef HAVE_WINDOW_SYSTEM
8576 /* When Emacs starts, selected_frame may be a visible terminal
8577 frame, even if we run under a window system. If we let this
8578 through, a message would be displayed on the terminal. */
8579 if (EQ (selected_frame
, Vterminal_frame
)
8580 && !NILP (Vwindow_system
))
8582 #endif /* HAVE_WINDOW_SYSTEM */
8585 /* Redraw garbaged frames. */
8587 clear_garbaged_frames ();
8589 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8591 echo_area_window
= mini_window
;
8592 window_height_changed_p
= display_echo_area (w
);
8593 w
->must_be_updated_p
= 1;
8595 /* Update the display, unless called from redisplay_internal.
8596 Also don't update the screen during redisplay itself. The
8597 update will happen at the end of redisplay, and an update
8598 here could cause confusion. */
8599 if (update_frame_p
&& !redisplaying_p
)
8603 /* If the display update has been interrupted by pending
8604 input, update mode lines in the frame. Due to the
8605 pending input, it might have been that redisplay hasn't
8606 been called, so that mode lines above the echo area are
8607 garbaged. This looks odd, so we prevent it here. */
8608 if (!display_completed
)
8609 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8611 if (window_height_changed_p
8612 /* Don't do this if Emacs is shutting down. Redisplay
8613 needs to run hooks. */
8614 && !NILP (Vrun_hooks
))
8616 /* Must update other windows. Likewise as in other
8617 cases, don't let this update be interrupted by
8619 int count
= SPECPDL_INDEX ();
8620 specbind (Qredisplay_dont_pause
, Qt
);
8621 windows_or_buffers_changed
= 1;
8622 redisplay_internal (0);
8623 unbind_to (count
, Qnil
);
8625 else if (FRAME_WINDOW_P (f
) && n
== 0)
8627 /* Window configuration is the same as before.
8628 Can do with a display update of the echo area,
8629 unless we displayed some mode lines. */
8630 update_single_window (w
, 1);
8631 rif
->flush_display (f
);
8634 update_frame (f
, 1, 1);
8636 /* If cursor is in the echo area, make sure that the next
8637 redisplay displays the minibuffer, so that the cursor will
8638 be replaced with what the minibuffer wants. */
8639 if (cursor_in_echo_area
)
8640 ++windows_or_buffers_changed
;
8643 else if (!EQ (mini_window
, selected_window
))
8644 windows_or_buffers_changed
++;
8646 /* The current message is now also the last one displayed. */
8647 echo_area_buffer
[1] = echo_area_buffer
[0];
8649 /* Prevent redisplay optimization in redisplay_internal by resetting
8650 this_line_start_pos. This is done because the mini-buffer now
8651 displays the message instead of its buffer text. */
8652 if (EQ (mini_window
, selected_window
))
8653 CHARPOS (this_line_start_pos
) = 0;
8655 return window_height_changed_p
;
8660 /***********************************************************************
8661 Mode Lines and Frame Titles
8662 ***********************************************************************/
8664 /* A buffer for constructing non-propertized mode-line strings and
8665 frame titles in it; allocated from the heap in init_xdisp and
8666 resized as needed in store_mode_line_noprop_char. */
8668 static char *mode_line_noprop_buf
;
8670 /* The buffer's end, and a current output position in it. */
8672 static char *mode_line_noprop_buf_end
;
8673 static char *mode_line_noprop_ptr
;
8675 #define MODE_LINE_NOPROP_LEN(start) \
8676 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8679 MODE_LINE_DISPLAY
= 0,
8685 /* Alist that caches the results of :propertize.
8686 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8687 static Lisp_Object mode_line_proptrans_alist
;
8689 /* List of strings making up the mode-line. */
8690 static Lisp_Object mode_line_string_list
;
8692 /* Base face property when building propertized mode line string. */
8693 static Lisp_Object mode_line_string_face
;
8694 static Lisp_Object mode_line_string_face_prop
;
8697 /* Unwind data for mode line strings */
8699 static Lisp_Object Vmode_line_unwind_vector
;
8702 format_mode_line_unwind_data (obuf
, save_proptrans
)
8703 struct buffer
*obuf
;
8707 /* Reduce consing by keeping one vector in
8708 Vwith_echo_area_save_vector. */
8709 vector
= Vmode_line_unwind_vector
;
8710 Vmode_line_unwind_vector
= Qnil
;
8713 vector
= Fmake_vector (make_number (7), Qnil
);
8715 AREF (vector
, 0) = make_number (mode_line_target
);
8716 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8717 AREF (vector
, 2) = mode_line_string_list
;
8718 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8719 AREF (vector
, 4) = mode_line_string_face
;
8720 AREF (vector
, 5) = mode_line_string_face_prop
;
8723 XSETBUFFER (AREF (vector
, 6), obuf
);
8725 AREF (vector
, 6) = Qnil
;
8731 unwind_format_mode_line (vector
)
8734 mode_line_target
= XINT (AREF (vector
, 0));
8735 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8736 mode_line_string_list
= AREF (vector
, 2);
8737 if (! EQ (AREF (vector
, 3), Qt
))
8738 mode_line_proptrans_alist
= AREF (vector
, 3);
8739 mode_line_string_face
= AREF (vector
, 4);
8740 mode_line_string_face_prop
= AREF (vector
, 5);
8742 if (!NILP (AREF (vector
, 6)))
8744 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8745 AREF (vector
, 6) = Qnil
;
8748 Vmode_line_unwind_vector
= vector
;
8753 /* Store a single character C for the frame title in mode_line_noprop_buf.
8754 Re-allocate mode_line_noprop_buf if necessary. */
8758 store_mode_line_noprop_char (char c
)
8760 store_mode_line_noprop_char (c
)
8764 /* If output position has reached the end of the allocated buffer,
8765 double the buffer's size. */
8766 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8768 int len
= MODE_LINE_NOPROP_LEN (0);
8769 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8770 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8771 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8772 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8775 *mode_line_noprop_ptr
++ = c
;
8779 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8780 mode_line_noprop_ptr. STR is the string to store. Do not copy
8781 characters that yield more columns than PRECISION; PRECISION <= 0
8782 means copy the whole string. Pad with spaces until FIELD_WIDTH
8783 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8784 pad. Called from display_mode_element when it is used to build a
8788 store_mode_line_noprop (str
, field_width
, precision
)
8789 const unsigned char *str
;
8790 int field_width
, precision
;
8795 /* Copy at most PRECISION chars from STR. */
8796 nbytes
= strlen (str
);
8797 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8799 store_mode_line_noprop_char (*str
++);
8801 /* Fill up with spaces until FIELD_WIDTH reached. */
8802 while (field_width
> 0
8805 store_mode_line_noprop_char (' ');
8812 /***********************************************************************
8814 ***********************************************************************/
8816 #ifdef HAVE_WINDOW_SYSTEM
8818 /* Set the title of FRAME, if it has changed. The title format is
8819 Vicon_title_format if FRAME is iconified, otherwise it is
8820 frame_title_format. */
8823 x_consider_frame_title (frame
)
8826 struct frame
*f
= XFRAME (frame
);
8828 if (FRAME_WINDOW_P (f
)
8829 || FRAME_MINIBUF_ONLY_P (f
)
8830 || f
->explicit_name
)
8832 /* Do we have more than one visible frame on this X display? */
8839 int count
= SPECPDL_INDEX ();
8841 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8843 Lisp_Object other_frame
= XCAR (tail
);
8844 struct frame
*tf
= XFRAME (other_frame
);
8847 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8848 && !FRAME_MINIBUF_ONLY_P (tf
)
8849 && !EQ (other_frame
, tip_frame
)
8850 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8854 /* Set global variable indicating that multiple frames exist. */
8855 multiple_frames
= CONSP (tail
);
8857 /* Switch to the buffer of selected window of the frame. Set up
8858 mode_line_target so that display_mode_element will output into
8859 mode_line_noprop_buf; then display the title. */
8860 record_unwind_protect (unwind_format_mode_line
,
8861 format_mode_line_unwind_data (current_buffer
, 0));
8863 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8864 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8866 mode_line_target
= MODE_LINE_TITLE
;
8867 title_start
= MODE_LINE_NOPROP_LEN (0);
8868 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8869 NULL
, DEFAULT_FACE_ID
);
8870 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8871 len
= MODE_LINE_NOPROP_LEN (title_start
);
8872 title
= mode_line_noprop_buf
+ title_start
;
8873 unbind_to (count
, Qnil
);
8875 /* Set the title only if it's changed. This avoids consing in
8876 the common case where it hasn't. (If it turns out that we've
8877 already wasted too much time by walking through the list with
8878 display_mode_element, then we might need to optimize at a
8879 higher level than this.) */
8880 if (! STRINGP (f
->name
)
8881 || SBYTES (f
->name
) != len
8882 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8883 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8887 #endif /* not HAVE_WINDOW_SYSTEM */
8892 /***********************************************************************
8894 ***********************************************************************/
8897 /* Prepare for redisplay by updating menu-bar item lists when
8898 appropriate. This can call eval. */
8901 prepare_menu_bars ()
8904 struct gcpro gcpro1
, gcpro2
;
8906 Lisp_Object tooltip_frame
;
8908 #ifdef HAVE_WINDOW_SYSTEM
8909 tooltip_frame
= tip_frame
;
8911 tooltip_frame
= Qnil
;
8914 /* Update all frame titles based on their buffer names, etc. We do
8915 this before the menu bars so that the buffer-menu will show the
8916 up-to-date frame titles. */
8917 #ifdef HAVE_WINDOW_SYSTEM
8918 if (windows_or_buffers_changed
|| update_mode_lines
)
8920 Lisp_Object tail
, frame
;
8922 FOR_EACH_FRAME (tail
, frame
)
8925 if (!EQ (frame
, tooltip_frame
)
8926 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8927 x_consider_frame_title (frame
);
8930 #endif /* HAVE_WINDOW_SYSTEM */
8932 /* Update the menu bar item lists, if appropriate. This has to be
8933 done before any actual redisplay or generation of display lines. */
8934 all_windows
= (update_mode_lines
8935 || buffer_shared
> 1
8936 || windows_or_buffers_changed
);
8939 Lisp_Object tail
, frame
;
8940 int count
= SPECPDL_INDEX ();
8942 record_unwind_save_match_data ();
8944 FOR_EACH_FRAME (tail
, frame
)
8948 /* Ignore tooltip frame. */
8949 if (EQ (frame
, tooltip_frame
))
8952 /* If a window on this frame changed size, report that to
8953 the user and clear the size-change flag. */
8954 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8956 Lisp_Object functions
;
8958 /* Clear flag first in case we get an error below. */
8959 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8960 functions
= Vwindow_size_change_functions
;
8961 GCPRO2 (tail
, functions
);
8963 while (CONSP (functions
))
8965 call1 (XCAR (functions
), frame
);
8966 functions
= XCDR (functions
);
8972 update_menu_bar (f
, 0);
8973 #ifdef HAVE_WINDOW_SYSTEM
8974 update_tool_bar (f
, 0);
8976 mac_update_title_bar (f
, 0);
8982 unbind_to (count
, Qnil
);
8986 struct frame
*sf
= SELECTED_FRAME ();
8987 update_menu_bar (sf
, 1);
8988 #ifdef HAVE_WINDOW_SYSTEM
8989 update_tool_bar (sf
, 1);
8991 mac_update_title_bar (sf
, 1);
8996 /* Motif needs this. See comment in xmenu.c. Turn it off when
8997 pending_menu_activation is not defined. */
8998 #ifdef USE_X_TOOLKIT
8999 pending_menu_activation
= 0;
9004 /* Update the menu bar item list for frame F. This has to be done
9005 before we start to fill in any display lines, because it can call
9008 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
9011 update_menu_bar (f
, save_match_data
)
9013 int save_match_data
;
9016 register struct window
*w
;
9018 /* If called recursively during a menu update, do nothing. This can
9019 happen when, for instance, an activate-menubar-hook causes a
9021 if (inhibit_menubar_update
)
9024 window
= FRAME_SELECTED_WINDOW (f
);
9025 w
= XWINDOW (window
);
9027 #if 0 /* The if statement below this if statement used to include the
9028 condition !NILP (w->update_mode_line), rather than using
9029 update_mode_lines directly, and this if statement may have
9030 been added to make that condition work. Now the if
9031 statement below matches its comment, this isn't needed. */
9032 if (update_mode_lines
)
9033 w
->update_mode_line
= Qt
;
9036 if (FRAME_WINDOW_P (f
)
9038 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9039 || defined (USE_GTK)
9040 FRAME_EXTERNAL_MENU_BAR (f
)
9042 FRAME_MENU_BAR_LINES (f
) > 0
9044 : FRAME_MENU_BAR_LINES (f
) > 0)
9046 /* If the user has switched buffers or windows, we need to
9047 recompute to reflect the new bindings. But we'll
9048 recompute when update_mode_lines is set too; that means
9049 that people can use force-mode-line-update to request
9050 that the menu bar be recomputed. The adverse effect on
9051 the rest of the redisplay algorithm is about the same as
9052 windows_or_buffers_changed anyway. */
9053 if (windows_or_buffers_changed
9054 /* This used to test w->update_mode_line, but we believe
9055 there is no need to recompute the menu in that case. */
9056 || update_mode_lines
9057 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9058 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9059 != !NILP (w
->last_had_star
))
9060 || ((!NILP (Vtransient_mark_mode
)
9061 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9062 != !NILP (w
->region_showing
)))
9064 struct buffer
*prev
= current_buffer
;
9065 int count
= SPECPDL_INDEX ();
9067 specbind (Qinhibit_menubar_update
, Qt
);
9069 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9070 if (save_match_data
)
9071 record_unwind_save_match_data ();
9072 if (NILP (Voverriding_local_map_menu_flag
))
9074 specbind (Qoverriding_terminal_local_map
, Qnil
);
9075 specbind (Qoverriding_local_map
, Qnil
);
9078 /* Run the Lucid hook. */
9079 safe_run_hooks (Qactivate_menubar_hook
);
9081 /* If it has changed current-menubar from previous value,
9082 really recompute the menu-bar from the value. */
9083 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9084 call0 (Qrecompute_lucid_menubar
);
9086 safe_run_hooks (Qmenu_bar_update_hook
);
9087 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9089 /* Redisplay the menu bar in case we changed it. */
9090 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9091 || defined (USE_GTK)
9092 if (FRAME_WINDOW_P (f
))
9095 /* All frames on Mac OS share the same menubar. So only
9096 the selected frame should be allowed to set it. */
9097 if (f
== SELECTED_FRAME ())
9099 set_frame_menubar (f
, 0, 0);
9102 /* On a terminal screen, the menu bar is an ordinary screen
9103 line, and this makes it get updated. */
9104 w
->update_mode_line
= Qt
;
9105 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9106 /* In the non-toolkit version, the menu bar is an ordinary screen
9107 line, and this makes it get updated. */
9108 w
->update_mode_line
= Qt
;
9109 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9111 unbind_to (count
, Qnil
);
9112 set_buffer_internal_1 (prev
);
9119 /***********************************************************************
9121 ***********************************************************************/
9123 #ifdef HAVE_WINDOW_SYSTEM
9126 Nominal cursor position -- where to draw output.
9127 HPOS and VPOS are window relative glyph matrix coordinates.
9128 X and Y are window relative pixel coordinates. */
9130 struct cursor_pos output_cursor
;
9134 Set the global variable output_cursor to CURSOR. All cursor
9135 positions are relative to updated_window. */
9138 set_output_cursor (cursor
)
9139 struct cursor_pos
*cursor
;
9141 output_cursor
.hpos
= cursor
->hpos
;
9142 output_cursor
.vpos
= cursor
->vpos
;
9143 output_cursor
.x
= cursor
->x
;
9144 output_cursor
.y
= cursor
->y
;
9149 Set a nominal cursor position.
9151 HPOS and VPOS are column/row positions in a window glyph matrix. X
9152 and Y are window text area relative pixel positions.
9154 If this is done during an update, updated_window will contain the
9155 window that is being updated and the position is the future output
9156 cursor position for that window. If updated_window is null, use
9157 selected_window and display the cursor at the given position. */
9160 x_cursor_to (vpos
, hpos
, y
, x
)
9161 int vpos
, hpos
, y
, x
;
9165 /* If updated_window is not set, work on selected_window. */
9169 w
= XWINDOW (selected_window
);
9171 /* Set the output cursor. */
9172 output_cursor
.hpos
= hpos
;
9173 output_cursor
.vpos
= vpos
;
9174 output_cursor
.x
= x
;
9175 output_cursor
.y
= y
;
9177 /* If not called as part of an update, really display the cursor.
9178 This will also set the cursor position of W. */
9179 if (updated_window
== NULL
)
9182 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9183 if (rif
->flush_display_optional
)
9184 rif
->flush_display_optional (SELECTED_FRAME ());
9189 #endif /* HAVE_WINDOW_SYSTEM */
9192 /***********************************************************************
9194 ***********************************************************************/
9196 #ifdef HAVE_WINDOW_SYSTEM
9198 /* Where the mouse was last time we reported a mouse event. */
9200 FRAME_PTR last_mouse_frame
;
9202 /* Tool-bar item index of the item on which a mouse button was pressed
9205 int last_tool_bar_item
;
9208 /* Update the tool-bar item list for frame F. This has to be done
9209 before we start to fill in any display lines. Called from
9210 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9211 and restore it here. */
9214 update_tool_bar (f
, save_match_data
)
9216 int save_match_data
;
9219 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9221 int do_update
= WINDOWP (f
->tool_bar_window
)
9222 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9230 window
= FRAME_SELECTED_WINDOW (f
);
9231 w
= XWINDOW (window
);
9233 /* If the user has switched buffers or windows, we need to
9234 recompute to reflect the new bindings. But we'll
9235 recompute when update_mode_lines is set too; that means
9236 that people can use force-mode-line-update to request
9237 that the menu bar be recomputed. The adverse effect on
9238 the rest of the redisplay algorithm is about the same as
9239 windows_or_buffers_changed anyway. */
9240 if (windows_or_buffers_changed
9241 || !NILP (w
->update_mode_line
)
9242 || update_mode_lines
9243 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9244 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9245 != !NILP (w
->last_had_star
))
9246 || ((!NILP (Vtransient_mark_mode
)
9247 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9248 != !NILP (w
->region_showing
)))
9250 struct buffer
*prev
= current_buffer
;
9251 int count
= SPECPDL_INDEX ();
9252 Lisp_Object new_tool_bar
;
9254 struct gcpro gcpro1
;
9256 /* Set current_buffer to the buffer of the selected
9257 window of the frame, so that we get the right local
9259 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9261 /* Save match data, if we must. */
9262 if (save_match_data
)
9263 record_unwind_save_match_data ();
9265 /* Make sure that we don't accidentally use bogus keymaps. */
9266 if (NILP (Voverriding_local_map_menu_flag
))
9268 specbind (Qoverriding_terminal_local_map
, Qnil
);
9269 specbind (Qoverriding_local_map
, Qnil
);
9272 GCPRO1 (new_tool_bar
);
9274 /* Build desired tool-bar items from keymaps. */
9275 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9278 /* Redisplay the tool-bar if we changed it. */
9279 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9281 /* Redisplay that happens asynchronously due to an expose event
9282 may access f->tool_bar_items. Make sure we update both
9283 variables within BLOCK_INPUT so no such event interrupts. */
9285 f
->tool_bar_items
= new_tool_bar
;
9286 f
->n_tool_bar_items
= new_n_tool_bar
;
9287 w
->update_mode_line
= Qt
;
9293 unbind_to (count
, Qnil
);
9294 set_buffer_internal_1 (prev
);
9300 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9301 F's desired tool-bar contents. F->tool_bar_items must have
9302 been set up previously by calling prepare_menu_bars. */
9305 build_desired_tool_bar_string (f
)
9308 int i
, size
, size_needed
;
9309 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9310 Lisp_Object image
, plist
, props
;
9312 image
= plist
= props
= Qnil
;
9313 GCPRO3 (image
, plist
, props
);
9315 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9316 Otherwise, make a new string. */
9318 /* The size of the string we might be able to reuse. */
9319 size
= (STRINGP (f
->desired_tool_bar_string
)
9320 ? SCHARS (f
->desired_tool_bar_string
)
9323 /* We need one space in the string for each image. */
9324 size_needed
= f
->n_tool_bar_items
;
9326 /* Reuse f->desired_tool_bar_string, if possible. */
9327 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9328 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9332 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9333 Fremove_text_properties (make_number (0), make_number (size
),
9334 props
, f
->desired_tool_bar_string
);
9337 /* Put a `display' property on the string for the images to display,
9338 put a `menu_item' property on tool-bar items with a value that
9339 is the index of the item in F's tool-bar item vector. */
9340 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9342 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9344 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9345 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9346 int hmargin
, vmargin
, relief
, idx
, end
;
9347 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9349 /* If image is a vector, choose the image according to the
9351 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9352 if (VECTORP (image
))
9356 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9357 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9360 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9361 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9363 xassert (ASIZE (image
) >= idx
);
9364 image
= AREF (image
, idx
);
9369 /* Ignore invalid image specifications. */
9370 if (!valid_image_p (image
))
9373 /* Display the tool-bar button pressed, or depressed. */
9374 plist
= Fcopy_sequence (XCDR (image
));
9376 /* Compute margin and relief to draw. */
9377 relief
= (tool_bar_button_relief
>= 0
9378 ? tool_bar_button_relief
9379 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9380 hmargin
= vmargin
= relief
;
9382 if (INTEGERP (Vtool_bar_button_margin
)
9383 && XINT (Vtool_bar_button_margin
) > 0)
9385 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9386 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9388 else if (CONSP (Vtool_bar_button_margin
))
9390 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9391 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9392 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9394 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9395 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9396 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9399 if (auto_raise_tool_bar_buttons_p
)
9401 /* Add a `:relief' property to the image spec if the item is
9405 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9412 /* If image is selected, display it pressed, i.e. with a
9413 negative relief. If it's not selected, display it with a
9415 plist
= Fplist_put (plist
, QCrelief
,
9417 ? make_number (-relief
)
9418 : make_number (relief
)));
9423 /* Put a margin around the image. */
9424 if (hmargin
|| vmargin
)
9426 if (hmargin
== vmargin
)
9427 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9429 plist
= Fplist_put (plist
, QCmargin
,
9430 Fcons (make_number (hmargin
),
9431 make_number (vmargin
)));
9434 /* If button is not enabled, and we don't have special images
9435 for the disabled state, make the image appear disabled by
9436 applying an appropriate algorithm to it. */
9437 if (!enabled_p
&& idx
< 0)
9438 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9440 /* Put a `display' text property on the string for the image to
9441 display. Put a `menu-item' property on the string that gives
9442 the start of this item's properties in the tool-bar items
9444 image
= Fcons (Qimage
, plist
);
9445 props
= list4 (Qdisplay
, image
,
9446 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9448 /* Let the last image hide all remaining spaces in the tool bar
9449 string. The string can be longer than needed when we reuse a
9451 if (i
+ 1 == f
->n_tool_bar_items
)
9452 end
= SCHARS (f
->desired_tool_bar_string
);
9455 Fadd_text_properties (make_number (i
), make_number (end
),
9456 props
, f
->desired_tool_bar_string
);
9464 /* Display one line of the tool-bar of frame IT->f.
9466 HEIGHT specifies the desired height of the tool-bar line.
9467 If the actual height of the glyph row is less than HEIGHT, the
9468 row's height is increased to HEIGHT, and the icons are centered
9469 vertically in the new height.
9471 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9472 count a final empty row in case the tool-bar width exactly matches
9477 display_tool_bar_line (it
, height
)
9481 struct glyph_row
*row
= it
->glyph_row
;
9482 int max_x
= it
->last_visible_x
;
9485 prepare_desired_row (row
);
9486 row
->y
= it
->current_y
;
9488 /* Note that this isn't made use of if the face hasn't a box,
9489 so there's no need to check the face here. */
9490 it
->start_of_box_run_p
= 1;
9492 while (it
->current_x
< max_x
)
9494 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9496 /* Get the next display element. */
9497 if (!get_next_display_element (it
))
9499 /* Don't count empty row if we are counting needed tool-bar lines. */
9500 if (height
< 0 && !it
->hpos
)
9505 /* Produce glyphs. */
9506 x_before
= it
->current_x
;
9507 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9508 PRODUCE_GLYPHS (it
);
9510 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9515 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9517 if (x
+ glyph
->pixel_width
> max_x
)
9519 /* Glyph doesn't fit on line. */
9520 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9526 x
+= glyph
->pixel_width
;
9530 /* Stop at line ends. */
9531 if (ITERATOR_AT_END_OF_LINE_P (it
))
9534 set_iterator_to_next (it
, 1);
9539 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9540 /* Use default face for the border below the tool bar. */
9541 if (!row
->displays_text_p
)
9542 it
->face_id
= DEFAULT_FACE_ID
;
9543 extend_face_to_end_of_line (it
);
9544 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9545 last
->right_box_line_p
= 1;
9546 if (last
== row
->glyphs
[TEXT_AREA
])
9547 last
->left_box_line_p
= 1;
9549 /* Make line the desired height and center it vertically. */
9550 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9552 it
->max_ascent
+= height
/ 2;
9553 it
->max_descent
+= (height
+ 1) / 2;
9556 compute_line_metrics (it
);
9558 /* If line is empty, make it occupy the rest of the tool-bar. */
9559 if (!row
->displays_text_p
)
9561 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9562 row
->ascent
= row
->phys_ascent
= 0;
9563 row
->extra_line_spacing
= 0;
9566 row
->full_width_p
= 1;
9567 row
->continued_p
= 0;
9568 row
->truncated_on_left_p
= 0;
9569 row
->truncated_on_right_p
= 0;
9571 it
->current_x
= it
->hpos
= 0;
9572 it
->current_y
+= row
->height
;
9578 /* Value is the number of screen lines needed to make all tool-bar
9579 items of frame F visible. The number of actual rows needed is
9580 returned in *N_ROWS if non-NULL. */
9583 tool_bar_lines_needed (f
, n_rows
)
9587 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9589 struct glyph_row
*temp_row
= w
->desired_matrix
->rows
;
9591 /* Initialize an iterator for iteration over
9592 F->desired_tool_bar_string in the tool-bar window of frame F. */
9593 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9594 it
.first_visible_x
= 0;
9595 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9596 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9598 while (!ITERATOR_AT_END_P (&it
))
9600 clear_glyph_row (temp_row
);
9601 it
.glyph_row
= temp_row
;
9602 display_tool_bar_line (&it
, -1);
9604 clear_glyph_row (temp_row
);
9606 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9608 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9610 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9614 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9616 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9625 frame
= selected_frame
;
9627 CHECK_FRAME (frame
);
9630 if (WINDOWP (f
->tool_bar_window
)
9631 || (w
= XWINDOW (f
->tool_bar_window
),
9632 WINDOW_TOTAL_LINES (w
) > 0))
9634 update_tool_bar (f
, 1);
9635 if (f
->n_tool_bar_items
)
9637 build_desired_tool_bar_string (f
);
9638 nlines
= tool_bar_lines_needed (f
, NULL
);
9642 return make_number (nlines
);
9646 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9647 height should be changed. */
9650 redisplay_tool_bar (f
)
9655 struct glyph_row
*row
;
9656 int change_height_p
= 0;
9659 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9660 update_frame_tool_bar (f
);
9664 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9665 do anything. This means you must start with tool-bar-lines
9666 non-zero to get the auto-sizing effect. Or in other words, you
9667 can turn off tool-bars by specifying tool-bar-lines zero. */
9668 if (!WINDOWP (f
->tool_bar_window
)
9669 || (w
= XWINDOW (f
->tool_bar_window
),
9670 WINDOW_TOTAL_LINES (w
) == 0))
9673 /* Set up an iterator for the tool-bar window. */
9674 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9675 it
.first_visible_x
= 0;
9676 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9679 /* Build a string that represents the contents of the tool-bar. */
9680 build_desired_tool_bar_string (f
);
9681 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9683 if (f
->n_tool_bar_rows
== 0)
9687 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9688 nlines
!= WINDOW_TOTAL_LINES (w
)))
9690 extern Lisp_Object Qtool_bar_lines
;
9692 int old_height
= WINDOW_TOTAL_LINES (w
);
9694 XSETFRAME (frame
, f
);
9695 clear_glyph_matrix (w
->desired_matrix
);
9696 Fmodify_frame_parameters (frame
,
9697 Fcons (Fcons (Qtool_bar_lines
,
9698 make_number (nlines
)),
9700 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9702 fonts_changed_p
= 1;
9708 /* Display as many lines as needed to display all tool-bar items. */
9710 if (f
->n_tool_bar_rows
> 0)
9712 int border
, rows
, height
, extra
;
9714 if (INTEGERP (Vtool_bar_border
))
9715 border
= XINT (Vtool_bar_border
);
9716 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9717 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9718 else if (EQ (Vtool_bar_border
, Qborder_width
))
9719 border
= f
->border_width
;
9725 rows
= f
->n_tool_bar_rows
;
9726 height
= (it
.last_visible_y
- border
) / rows
;
9727 extra
= it
.last_visible_y
- border
- height
* rows
;
9729 while (it
.current_y
< it
.last_visible_y
)
9732 if (extra
> 0 && rows
-- > 0)
9734 h
= (extra
+ rows
- 1) / rows
;
9737 display_tool_bar_line (&it
, height
+ h
);
9742 while (it
.current_y
< it
.last_visible_y
)
9743 display_tool_bar_line (&it
, 0);
9746 /* It doesn't make much sense to try scrolling in the tool-bar
9747 window, so don't do it. */
9748 w
->desired_matrix
->no_scrolling_p
= 1;
9749 w
->must_be_updated_p
= 1;
9751 if (auto_resize_tool_bars_p
)
9755 /* If we couldn't display everything, change the tool-bar's
9757 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9758 change_height_p
= 1;
9760 /* If there are blank lines at the end, except for a partially
9761 visible blank line at the end that is smaller than
9762 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9763 row
= it
.glyph_row
- 1;
9764 if (!row
->displays_text_p
9765 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9766 change_height_p
= 1;
9768 /* If row displays tool-bar items, but is partially visible,
9769 change the tool-bar's height. */
9770 if (row
->displays_text_p
9771 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9772 change_height_p
= 1;
9774 /* Resize windows as needed by changing the `tool-bar-lines'
9777 && (nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9778 nlines
!= WINDOW_TOTAL_LINES (w
)))
9780 extern Lisp_Object Qtool_bar_lines
;
9782 int old_height
= WINDOW_TOTAL_LINES (w
);
9784 XSETFRAME (frame
, f
);
9785 clear_glyph_matrix (w
->desired_matrix
);
9786 Fmodify_frame_parameters (frame
,
9787 Fcons (Fcons (Qtool_bar_lines
,
9788 make_number (nlines
)),
9790 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9791 fonts_changed_p
= 1;
9795 return change_height_p
;
9799 /* Get information about the tool-bar item which is displayed in GLYPH
9800 on frame F. Return in *PROP_IDX the index where tool-bar item
9801 properties start in F->tool_bar_items. Value is zero if
9802 GLYPH doesn't display a tool-bar item. */
9805 tool_bar_item_info (f
, glyph
, prop_idx
)
9807 struct glyph
*glyph
;
9814 /* This function can be called asynchronously, which means we must
9815 exclude any possibility that Fget_text_property signals an
9817 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9818 charpos
= max (0, charpos
);
9820 /* Get the text property `menu-item' at pos. The value of that
9821 property is the start index of this item's properties in
9822 F->tool_bar_items. */
9823 prop
= Fget_text_property (make_number (charpos
),
9824 Qmenu_item
, f
->current_tool_bar_string
);
9825 if (INTEGERP (prop
))
9827 *prop_idx
= XINT (prop
);
9837 /* Get information about the tool-bar item at position X/Y on frame F.
9838 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9839 the current matrix of the tool-bar window of F, or NULL if not
9840 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9841 item in F->tool_bar_items. Value is
9843 -1 if X/Y is not on a tool-bar item
9844 0 if X/Y is on the same item that was highlighted before.
9848 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9851 struct glyph
**glyph
;
9852 int *hpos
, *vpos
, *prop_idx
;
9854 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9855 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9858 /* Find the glyph under X/Y. */
9859 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9863 /* Get the start of this tool-bar item's properties in
9864 f->tool_bar_items. */
9865 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9868 /* Is mouse on the highlighted item? */
9869 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9870 && *vpos
>= dpyinfo
->mouse_face_beg_row
9871 && *vpos
<= dpyinfo
->mouse_face_end_row
9872 && (*vpos
> dpyinfo
->mouse_face_beg_row
9873 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9874 && (*vpos
< dpyinfo
->mouse_face_end_row
9875 || *hpos
< dpyinfo
->mouse_face_end_col
9876 || dpyinfo
->mouse_face_past_end
))
9884 Handle mouse button event on the tool-bar of frame F, at
9885 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9886 0 for button release. MODIFIERS is event modifiers for button
9890 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9893 unsigned int modifiers
;
9895 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9896 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9897 int hpos
, vpos
, prop_idx
;
9898 struct glyph
*glyph
;
9899 Lisp_Object enabled_p
;
9901 /* If not on the highlighted tool-bar item, return. */
9902 frame_to_window_pixel_xy (w
, &x
, &y
);
9903 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9906 /* If item is disabled, do nothing. */
9907 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9908 if (NILP (enabled_p
))
9913 /* Show item in pressed state. */
9914 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9915 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9916 last_tool_bar_item
= prop_idx
;
9920 Lisp_Object key
, frame
;
9921 struct input_event event
;
9924 /* Show item in released state. */
9925 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9926 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9928 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9930 XSETFRAME (frame
, f
);
9931 event
.kind
= TOOL_BAR_EVENT
;
9932 event
.frame_or_window
= frame
;
9934 kbd_buffer_store_event (&event
);
9936 event
.kind
= TOOL_BAR_EVENT
;
9937 event
.frame_or_window
= frame
;
9939 event
.modifiers
= modifiers
;
9940 kbd_buffer_store_event (&event
);
9941 last_tool_bar_item
= -1;
9946 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9947 tool-bar window-relative coordinates X/Y. Called from
9948 note_mouse_highlight. */
9951 note_tool_bar_highlight (f
, x
, y
)
9955 Lisp_Object window
= f
->tool_bar_window
;
9956 struct window
*w
= XWINDOW (window
);
9957 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9959 struct glyph
*glyph
;
9960 struct glyph_row
*row
;
9962 Lisp_Object enabled_p
;
9964 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9965 int mouse_down_p
, rc
;
9967 /* Function note_mouse_highlight is called with negative x(y
9968 values when mouse moves outside of the frame. */
9969 if (x
<= 0 || y
<= 0)
9971 clear_mouse_face (dpyinfo
);
9975 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9978 /* Not on tool-bar item. */
9979 clear_mouse_face (dpyinfo
);
9983 /* On same tool-bar item as before. */
9986 clear_mouse_face (dpyinfo
);
9988 /* Mouse is down, but on different tool-bar item? */
9989 mouse_down_p
= (dpyinfo
->grabbed
9990 && f
== last_mouse_frame
9991 && FRAME_LIVE_P (f
));
9993 && last_tool_bar_item
!= prop_idx
)
9996 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9997 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9999 /* If tool-bar item is not enabled, don't highlight it. */
10000 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10001 if (!NILP (enabled_p
))
10003 /* Compute the x-position of the glyph. In front and past the
10004 image is a space. We include this in the highlighted area. */
10005 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10006 for (i
= x
= 0; i
< hpos
; ++i
)
10007 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10009 /* Record this as the current active region. */
10010 dpyinfo
->mouse_face_beg_col
= hpos
;
10011 dpyinfo
->mouse_face_beg_row
= vpos
;
10012 dpyinfo
->mouse_face_beg_x
= x
;
10013 dpyinfo
->mouse_face_beg_y
= row
->y
;
10014 dpyinfo
->mouse_face_past_end
= 0;
10016 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10017 dpyinfo
->mouse_face_end_row
= vpos
;
10018 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10019 dpyinfo
->mouse_face_end_y
= row
->y
;
10020 dpyinfo
->mouse_face_window
= window
;
10021 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10023 /* Display it as active. */
10024 show_mouse_face (dpyinfo
, draw
);
10025 dpyinfo
->mouse_face_image_state
= draw
;
10030 /* Set help_echo_string to a help string to display for this tool-bar item.
10031 XTread_socket does the rest. */
10032 help_echo_object
= help_echo_window
= Qnil
;
10033 help_echo_pos
= -1;
10034 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10035 if (NILP (help_echo_string
))
10036 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10039 #endif /* HAVE_WINDOW_SYSTEM */
10043 /************************************************************************
10044 Horizontal scrolling
10045 ************************************************************************/
10047 static int hscroll_window_tree
P_ ((Lisp_Object
));
10048 static int hscroll_windows
P_ ((Lisp_Object
));
10050 /* For all leaf windows in the window tree rooted at WINDOW, set their
10051 hscroll value so that PT is (i) visible in the window, and (ii) so
10052 that it is not within a certain margin at the window's left and
10053 right border. Value is non-zero if any window's hscroll has been
10057 hscroll_window_tree (window
)
10058 Lisp_Object window
;
10060 int hscrolled_p
= 0;
10061 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10062 int hscroll_step_abs
= 0;
10063 double hscroll_step_rel
= 0;
10065 if (hscroll_relative_p
)
10067 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10068 if (hscroll_step_rel
< 0)
10070 hscroll_relative_p
= 0;
10071 hscroll_step_abs
= 0;
10074 else if (INTEGERP (Vhscroll_step
))
10076 hscroll_step_abs
= XINT (Vhscroll_step
);
10077 if (hscroll_step_abs
< 0)
10078 hscroll_step_abs
= 0;
10081 hscroll_step_abs
= 0;
10083 while (WINDOWP (window
))
10085 struct window
*w
= XWINDOW (window
);
10087 if (WINDOWP (w
->hchild
))
10088 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10089 else if (WINDOWP (w
->vchild
))
10090 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10091 else if (w
->cursor
.vpos
>= 0)
10094 int text_area_width
;
10095 struct glyph_row
*current_cursor_row
10096 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10097 struct glyph_row
*desired_cursor_row
10098 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10099 struct glyph_row
*cursor_row
10100 = (desired_cursor_row
->enabled_p
10101 ? desired_cursor_row
10102 : current_cursor_row
);
10104 text_area_width
= window_box_width (w
, TEXT_AREA
);
10106 /* Scroll when cursor is inside this scroll margin. */
10107 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10109 if ((XFASTINT (w
->hscroll
)
10110 && w
->cursor
.x
<= h_margin
)
10111 || (cursor_row
->enabled_p
10112 && cursor_row
->truncated_on_right_p
10113 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10117 struct buffer
*saved_current_buffer
;
10121 /* Find point in a display of infinite width. */
10122 saved_current_buffer
= current_buffer
;
10123 current_buffer
= XBUFFER (w
->buffer
);
10125 if (w
== XWINDOW (selected_window
))
10126 pt
= BUF_PT (current_buffer
);
10129 pt
= marker_position (w
->pointm
);
10130 pt
= max (BEGV
, pt
);
10134 /* Move iterator to pt starting at cursor_row->start in
10135 a line with infinite width. */
10136 init_to_row_start (&it
, w
, cursor_row
);
10137 it
.last_visible_x
= INFINITY
;
10138 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10139 current_buffer
= saved_current_buffer
;
10141 /* Position cursor in window. */
10142 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10143 hscroll
= max (0, (it
.current_x
10144 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10145 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10146 : (text_area_width
/ 2))))
10147 / FRAME_COLUMN_WIDTH (it
.f
);
10148 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10150 if (hscroll_relative_p
)
10151 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10154 wanted_x
= text_area_width
10155 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10158 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10162 if (hscroll_relative_p
)
10163 wanted_x
= text_area_width
* hscroll_step_rel
10166 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10169 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10171 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10173 /* Don't call Fset_window_hscroll if value hasn't
10174 changed because it will prevent redisplay
10176 if (XFASTINT (w
->hscroll
) != hscroll
)
10178 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10179 w
->hscroll
= make_number (hscroll
);
10188 /* Value is non-zero if hscroll of any leaf window has been changed. */
10189 return hscrolled_p
;
10193 /* Set hscroll so that cursor is visible and not inside horizontal
10194 scroll margins for all windows in the tree rooted at WINDOW. See
10195 also hscroll_window_tree above. Value is non-zero if any window's
10196 hscroll has been changed. If it has, desired matrices on the frame
10197 of WINDOW are cleared. */
10200 hscroll_windows (window
)
10201 Lisp_Object window
;
10205 if (automatic_hscrolling_p
)
10207 hscrolled_p
= hscroll_window_tree (window
);
10209 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10213 return hscrolled_p
;
10218 /************************************************************************
10220 ************************************************************************/
10222 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10223 to a non-zero value. This is sometimes handy to have in a debugger
10228 /* First and last unchanged row for try_window_id. */
10230 int debug_first_unchanged_at_end_vpos
;
10231 int debug_last_unchanged_at_beg_vpos
;
10233 /* Delta vpos and y. */
10235 int debug_dvpos
, debug_dy
;
10237 /* Delta in characters and bytes for try_window_id. */
10239 int debug_delta
, debug_delta_bytes
;
10241 /* Values of window_end_pos and window_end_vpos at the end of
10244 EMACS_INT debug_end_pos
, debug_end_vpos
;
10246 /* Append a string to W->desired_matrix->method. FMT is a printf
10247 format string. A1...A9 are a supplement for a variable-length
10248 argument list. If trace_redisplay_p is non-zero also printf the
10249 resulting string to stderr. */
10252 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10255 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10258 char *method
= w
->desired_matrix
->method
;
10259 int len
= strlen (method
);
10260 int size
= sizeof w
->desired_matrix
->method
;
10261 int remaining
= size
- len
- 1;
10263 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10264 if (len
&& remaining
)
10267 --remaining
, ++len
;
10270 strncpy (method
+ len
, buffer
, remaining
);
10272 if (trace_redisplay_p
)
10273 fprintf (stderr
, "%p (%s): %s\n",
10275 ((BUFFERP (w
->buffer
)
10276 && STRINGP (XBUFFER (w
->buffer
)->name
))
10277 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10282 #endif /* GLYPH_DEBUG */
10285 /* Value is non-zero if all changes in window W, which displays
10286 current_buffer, are in the text between START and END. START is a
10287 buffer position, END is given as a distance from Z. Used in
10288 redisplay_internal for display optimization. */
10291 text_outside_line_unchanged_p (w
, start
, end
)
10295 int unchanged_p
= 1;
10297 /* If text or overlays have changed, see where. */
10298 if (XFASTINT (w
->last_modified
) < MODIFF
10299 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10301 /* Gap in the line? */
10302 if (GPT
< start
|| Z
- GPT
< end
)
10305 /* Changes start in front of the line, or end after it? */
10307 && (BEG_UNCHANGED
< start
- 1
10308 || END_UNCHANGED
< end
))
10311 /* If selective display, can't optimize if changes start at the
10312 beginning of the line. */
10314 && INTEGERP (current_buffer
->selective_display
)
10315 && XINT (current_buffer
->selective_display
) > 0
10316 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10319 /* If there are overlays at the start or end of the line, these
10320 may have overlay strings with newlines in them. A change at
10321 START, for instance, may actually concern the display of such
10322 overlay strings as well, and they are displayed on different
10323 lines. So, quickly rule out this case. (For the future, it
10324 might be desirable to implement something more telling than
10325 just BEG/END_UNCHANGED.) */
10328 if (BEG
+ BEG_UNCHANGED
== start
10329 && overlay_touches_p (start
))
10331 if (END_UNCHANGED
== end
10332 && overlay_touches_p (Z
- end
))
10337 return unchanged_p
;
10341 /* Do a frame update, taking possible shortcuts into account. This is
10342 the main external entry point for redisplay.
10344 If the last redisplay displayed an echo area message and that message
10345 is no longer requested, we clear the echo area or bring back the
10346 mini-buffer if that is in use. */
10351 redisplay_internal (0);
10356 overlay_arrow_string_or_property (var
)
10361 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10364 return Voverlay_arrow_string
;
10367 /* Return 1 if there are any overlay-arrows in current_buffer. */
10369 overlay_arrow_in_current_buffer_p ()
10373 for (vlist
= Voverlay_arrow_variable_list
;
10375 vlist
= XCDR (vlist
))
10377 Lisp_Object var
= XCAR (vlist
);
10380 if (!SYMBOLP (var
))
10382 val
= find_symbol_value (var
);
10384 && current_buffer
== XMARKER (val
)->buffer
)
10391 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10395 overlay_arrows_changed_p ()
10399 for (vlist
= Voverlay_arrow_variable_list
;
10401 vlist
= XCDR (vlist
))
10403 Lisp_Object var
= XCAR (vlist
);
10404 Lisp_Object val
, pstr
;
10406 if (!SYMBOLP (var
))
10408 val
= find_symbol_value (var
);
10409 if (!MARKERP (val
))
10411 if (! EQ (COERCE_MARKER (val
),
10412 Fget (var
, Qlast_arrow_position
))
10413 || ! (pstr
= overlay_arrow_string_or_property (var
),
10414 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10420 /* Mark overlay arrows to be updated on next redisplay. */
10423 update_overlay_arrows (up_to_date
)
10428 for (vlist
= Voverlay_arrow_variable_list
;
10430 vlist
= XCDR (vlist
))
10432 Lisp_Object var
= XCAR (vlist
);
10434 if (!SYMBOLP (var
))
10437 if (up_to_date
> 0)
10439 Lisp_Object val
= find_symbol_value (var
);
10440 Fput (var
, Qlast_arrow_position
,
10441 COERCE_MARKER (val
));
10442 Fput (var
, Qlast_arrow_string
,
10443 overlay_arrow_string_or_property (var
));
10445 else if (up_to_date
< 0
10446 || !NILP (Fget (var
, Qlast_arrow_position
)))
10448 Fput (var
, Qlast_arrow_position
, Qt
);
10449 Fput (var
, Qlast_arrow_string
, Qt
);
10455 /* Return overlay arrow string to display at row.
10456 Return integer (bitmap number) for arrow bitmap in left fringe.
10457 Return nil if no overlay arrow. */
10460 overlay_arrow_at_row (it
, row
)
10462 struct glyph_row
*row
;
10466 for (vlist
= Voverlay_arrow_variable_list
;
10468 vlist
= XCDR (vlist
))
10470 Lisp_Object var
= XCAR (vlist
);
10473 if (!SYMBOLP (var
))
10476 val
= find_symbol_value (var
);
10479 && current_buffer
== XMARKER (val
)->buffer
10480 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10482 if (FRAME_WINDOW_P (it
->f
)
10483 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10485 #ifdef HAVE_WINDOW_SYSTEM
10486 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10489 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10490 return make_number (fringe_bitmap
);
10493 return make_number (-1); /* Use default arrow bitmap */
10495 return overlay_arrow_string_or_property (var
);
10502 /* Return 1 if point moved out of or into a composition. Otherwise
10503 return 0. PREV_BUF and PREV_PT are the last point buffer and
10504 position. BUF and PT are the current point buffer and position. */
10507 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10508 struct buffer
*prev_buf
, *buf
;
10513 Lisp_Object buffer
;
10515 XSETBUFFER (buffer
, buf
);
10516 /* Check a composition at the last point if point moved within the
10518 if (prev_buf
== buf
)
10521 /* Point didn't move. */
10524 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10525 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10526 && COMPOSITION_VALID_P (start
, end
, prop
)
10527 && start
< prev_pt
&& end
> prev_pt
)
10528 /* The last point was within the composition. Return 1 iff
10529 point moved out of the composition. */
10530 return (pt
<= start
|| pt
>= end
);
10533 /* Check a composition at the current point. */
10534 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10535 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10536 && COMPOSITION_VALID_P (start
, end
, prop
)
10537 && start
< pt
&& end
> pt
);
10541 /* Reconsider the setting of B->clip_changed which is displayed
10545 reconsider_clip_changes (w
, b
)
10549 if (b
->clip_changed
10550 && !NILP (w
->window_end_valid
)
10551 && w
->current_matrix
->buffer
== b
10552 && w
->current_matrix
->zv
== BUF_ZV (b
)
10553 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10554 b
->clip_changed
= 0;
10556 /* If display wasn't paused, and W is not a tool bar window, see if
10557 point has been moved into or out of a composition. In that case,
10558 we set b->clip_changed to 1 to force updating the screen. If
10559 b->clip_changed has already been set to 1, we can skip this
10561 if (!b
->clip_changed
10562 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10566 if (w
== XWINDOW (selected_window
))
10567 pt
= BUF_PT (current_buffer
);
10569 pt
= marker_position (w
->pointm
);
10571 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10572 || pt
!= XINT (w
->last_point
))
10573 && check_point_in_composition (w
->current_matrix
->buffer
,
10574 XINT (w
->last_point
),
10575 XBUFFER (w
->buffer
), pt
))
10576 b
->clip_changed
= 1;
10581 /* Select FRAME to forward the values of frame-local variables into C
10582 variables so that the redisplay routines can access those values
10586 select_frame_for_redisplay (frame
)
10589 Lisp_Object tail
, sym
, val
;
10590 Lisp_Object old
= selected_frame
;
10592 selected_frame
= frame
;
10594 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10595 if (CONSP (XCAR (tail
))
10596 && (sym
= XCAR (XCAR (tail
)),
10598 && (sym
= indirect_variable (sym
),
10599 val
= SYMBOL_VALUE (sym
),
10600 (BUFFER_LOCAL_VALUEP (val
)
10601 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10602 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10603 /* Use find_symbol_value rather than Fsymbol_value
10604 to avoid an error if it is void. */
10605 find_symbol_value (sym
);
10607 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10608 if (CONSP (XCAR (tail
))
10609 && (sym
= XCAR (XCAR (tail
)),
10611 && (sym
= indirect_variable (sym
),
10612 val
= SYMBOL_VALUE (sym
),
10613 (BUFFER_LOCAL_VALUEP (val
)
10614 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10615 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10616 find_symbol_value (sym
);
10620 #define STOP_POLLING \
10621 do { if (! polling_stopped_here) stop_polling (); \
10622 polling_stopped_here = 1; } while (0)
10624 #define RESUME_POLLING \
10625 do { if (polling_stopped_here) start_polling (); \
10626 polling_stopped_here = 0; } while (0)
10629 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10630 response to any user action; therefore, we should preserve the echo
10631 area. (Actually, our caller does that job.) Perhaps in the future
10632 avoid recentering windows if it is not necessary; currently that
10633 causes some problems. */
10636 redisplay_internal (preserve_echo_area
)
10637 int preserve_echo_area
;
10639 struct window
*w
= XWINDOW (selected_window
);
10640 struct frame
*f
= XFRAME (w
->frame
);
10642 int must_finish
= 0;
10643 struct text_pos tlbufpos
, tlendpos
;
10644 int number_of_visible_frames
;
10646 struct frame
*sf
= SELECTED_FRAME ();
10647 int polling_stopped_here
= 0;
10649 /* Non-zero means redisplay has to consider all windows on all
10650 frames. Zero means, only selected_window is considered. */
10651 int consider_all_windows_p
;
10653 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10655 /* No redisplay if running in batch mode or frame is not yet fully
10656 initialized, or redisplay is explicitly turned off by setting
10657 Vinhibit_redisplay. */
10659 || !NILP (Vinhibit_redisplay
)
10660 || !f
->glyphs_initialized_p
)
10663 /* The flag redisplay_performed_directly_p is set by
10664 direct_output_for_insert when it already did the whole screen
10665 update necessary. */
10666 if (redisplay_performed_directly_p
)
10668 redisplay_performed_directly_p
= 0;
10669 if (!hscroll_windows (selected_window
))
10673 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10674 if (popup_activated ())
10678 /* I don't think this happens but let's be paranoid. */
10679 if (redisplaying_p
)
10682 /* Record a function that resets redisplaying_p to its old value
10683 when we leave this function. */
10684 count
= SPECPDL_INDEX ();
10685 record_unwind_protect (unwind_redisplay
,
10686 Fcons (make_number (redisplaying_p
), selected_frame
));
10688 specbind (Qinhibit_free_realized_faces
, Qnil
);
10691 Lisp_Object tail
, frame
;
10693 FOR_EACH_FRAME (tail
, frame
)
10695 struct frame
*f
= XFRAME (frame
);
10696 f
->already_hscrolled_p
= 0;
10702 reconsider_clip_changes (w
, current_buffer
);
10703 last_escape_glyph_frame
= NULL
;
10704 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10706 /* If new fonts have been loaded that make a glyph matrix adjustment
10707 necessary, do it. */
10708 if (fonts_changed_p
)
10710 adjust_glyphs (NULL
);
10711 ++windows_or_buffers_changed
;
10712 fonts_changed_p
= 0;
10715 /* If face_change_count is non-zero, init_iterator will free all
10716 realized faces, which includes the faces referenced from current
10717 matrices. So, we can't reuse current matrices in this case. */
10718 if (face_change_count
)
10719 ++windows_or_buffers_changed
;
10721 if (! FRAME_WINDOW_P (sf
)
10722 && previous_terminal_frame
!= sf
)
10724 /* Since frames on an ASCII terminal share the same display
10725 area, displaying a different frame means redisplay the whole
10727 windows_or_buffers_changed
++;
10728 SET_FRAME_GARBAGED (sf
);
10729 XSETFRAME (Vterminal_frame
, sf
);
10731 previous_terminal_frame
= sf
;
10733 /* Set the visible flags for all frames. Do this before checking
10734 for resized or garbaged frames; they want to know if their frames
10735 are visible. See the comment in frame.h for
10736 FRAME_SAMPLE_VISIBILITY. */
10738 Lisp_Object tail
, frame
;
10740 number_of_visible_frames
= 0;
10742 FOR_EACH_FRAME (tail
, frame
)
10744 struct frame
*f
= XFRAME (frame
);
10746 FRAME_SAMPLE_VISIBILITY (f
);
10747 if (FRAME_VISIBLE_P (f
))
10748 ++number_of_visible_frames
;
10749 clear_desired_matrices (f
);
10753 /* Notice any pending interrupt request to change frame size. */
10754 do_pending_window_change (1);
10756 /* Clear frames marked as garbaged. */
10757 if (frame_garbaged
)
10758 clear_garbaged_frames ();
10760 /* Build menubar and tool-bar items. */
10761 if (NILP (Vmemory_full
))
10762 prepare_menu_bars ();
10764 if (windows_or_buffers_changed
)
10765 update_mode_lines
++;
10767 /* Detect case that we need to write or remove a star in the mode line. */
10768 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10770 w
->update_mode_line
= Qt
;
10771 if (buffer_shared
> 1)
10772 update_mode_lines
++;
10775 /* If %c is in the mode line, update it if needed. */
10776 if (!NILP (w
->column_number_displayed
)
10777 /* This alternative quickly identifies a common case
10778 where no change is needed. */
10779 && !(PT
== XFASTINT (w
->last_point
)
10780 && XFASTINT (w
->last_modified
) >= MODIFF
10781 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10782 && (XFASTINT (w
->column_number_displayed
)
10783 != (int) current_column ())) /* iftc */
10784 w
->update_mode_line
= Qt
;
10786 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10788 /* The variable buffer_shared is set in redisplay_window and
10789 indicates that we redisplay a buffer in different windows. See
10791 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10792 || cursor_type_changed
);
10794 /* If specs for an arrow have changed, do thorough redisplay
10795 to ensure we remove any arrow that should no longer exist. */
10796 if (overlay_arrows_changed_p ())
10797 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10799 /* Normally the message* functions will have already displayed and
10800 updated the echo area, but the frame may have been trashed, or
10801 the update may have been preempted, so display the echo area
10802 again here. Checking message_cleared_p captures the case that
10803 the echo area should be cleared. */
10804 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10805 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10806 || (message_cleared_p
10807 && minibuf_level
== 0
10808 /* If the mini-window is currently selected, this means the
10809 echo-area doesn't show through. */
10810 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10812 int window_height_changed_p
= echo_area_display (0);
10815 /* If we don't display the current message, don't clear the
10816 message_cleared_p flag, because, if we did, we wouldn't clear
10817 the echo area in the next redisplay which doesn't preserve
10819 if (!display_last_displayed_message_p
)
10820 message_cleared_p
= 0;
10822 if (fonts_changed_p
)
10824 else if (window_height_changed_p
)
10826 consider_all_windows_p
= 1;
10827 ++update_mode_lines
;
10828 ++windows_or_buffers_changed
;
10830 /* If window configuration was changed, frames may have been
10831 marked garbaged. Clear them or we will experience
10832 surprises wrt scrolling. */
10833 if (frame_garbaged
)
10834 clear_garbaged_frames ();
10837 else if (EQ (selected_window
, minibuf_window
)
10838 && (current_buffer
->clip_changed
10839 || XFASTINT (w
->last_modified
) < MODIFF
10840 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10841 && resize_mini_window (w
, 0))
10843 /* Resized active mini-window to fit the size of what it is
10844 showing if its contents might have changed. */
10846 consider_all_windows_p
= 1;
10847 ++windows_or_buffers_changed
;
10848 ++update_mode_lines
;
10850 /* If window configuration was changed, frames may have been
10851 marked garbaged. Clear them or we will experience
10852 surprises wrt scrolling. */
10853 if (frame_garbaged
)
10854 clear_garbaged_frames ();
10858 /* If showing the region, and mark has changed, we must redisplay
10859 the whole window. The assignment to this_line_start_pos prevents
10860 the optimization directly below this if-statement. */
10861 if (((!NILP (Vtransient_mark_mode
)
10862 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10863 != !NILP (w
->region_showing
))
10864 || (!NILP (w
->region_showing
)
10865 && !EQ (w
->region_showing
,
10866 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10867 CHARPOS (this_line_start_pos
) = 0;
10869 /* Optimize the case that only the line containing the cursor in the
10870 selected window has changed. Variables starting with this_ are
10871 set in display_line and record information about the line
10872 containing the cursor. */
10873 tlbufpos
= this_line_start_pos
;
10874 tlendpos
= this_line_end_pos
;
10875 if (!consider_all_windows_p
10876 && CHARPOS (tlbufpos
) > 0
10877 && NILP (w
->update_mode_line
)
10878 && !current_buffer
->clip_changed
10879 && !current_buffer
->prevent_redisplay_optimizations_p
10880 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10881 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10882 /* Make sure recorded data applies to current buffer, etc. */
10883 && this_line_buffer
== current_buffer
10884 && current_buffer
== XBUFFER (w
->buffer
)
10885 && NILP (w
->force_start
)
10886 && NILP (w
->optional_new_start
)
10887 /* Point must be on the line that we have info recorded about. */
10888 && PT
>= CHARPOS (tlbufpos
)
10889 && PT
<= Z
- CHARPOS (tlendpos
)
10890 /* All text outside that line, including its final newline,
10891 must be unchanged */
10892 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10893 CHARPOS (tlendpos
)))
10895 if (CHARPOS (tlbufpos
) > BEGV
10896 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10897 && (CHARPOS (tlbufpos
) == ZV
10898 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10899 /* Former continuation line has disappeared by becoming empty */
10901 else if (XFASTINT (w
->last_modified
) < MODIFF
10902 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10903 || MINI_WINDOW_P (w
))
10905 /* We have to handle the case of continuation around a
10906 wide-column character (See the comment in indent.c around
10909 For instance, in the following case:
10911 -------- Insert --------
10912 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10913 J_I_ ==> J_I_ `^^' are cursors.
10917 As we have to redraw the line above, we should goto cancel. */
10920 int line_height_before
= this_line_pixel_height
;
10922 /* Note that start_display will handle the case that the
10923 line starting at tlbufpos is a continuation lines. */
10924 start_display (&it
, w
, tlbufpos
);
10926 /* Implementation note: It this still necessary? */
10927 if (it
.current_x
!= this_line_start_x
)
10930 TRACE ((stderr
, "trying display optimization 1\n"));
10931 w
->cursor
.vpos
= -1;
10932 overlay_arrow_seen
= 0;
10933 it
.vpos
= this_line_vpos
;
10934 it
.current_y
= this_line_y
;
10935 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10936 display_line (&it
);
10938 /* If line contains point, is not continued,
10939 and ends at same distance from eob as before, we win */
10940 if (w
->cursor
.vpos
>= 0
10941 /* Line is not continued, otherwise this_line_start_pos
10942 would have been set to 0 in display_line. */
10943 && CHARPOS (this_line_start_pos
)
10944 /* Line ends as before. */
10945 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10946 /* Line has same height as before. Otherwise other lines
10947 would have to be shifted up or down. */
10948 && this_line_pixel_height
== line_height_before
)
10950 /* If this is not the window's last line, we must adjust
10951 the charstarts of the lines below. */
10952 if (it
.current_y
< it
.last_visible_y
)
10954 struct glyph_row
*row
10955 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10956 int delta
, delta_bytes
;
10958 if (Z
- CHARPOS (tlendpos
) == ZV
)
10960 /* This line ends at end of (accessible part of)
10961 buffer. There is no newline to count. */
10963 - CHARPOS (tlendpos
)
10964 - MATRIX_ROW_START_CHARPOS (row
));
10965 delta_bytes
= (Z_BYTE
10966 - BYTEPOS (tlendpos
)
10967 - MATRIX_ROW_START_BYTEPOS (row
));
10971 /* This line ends in a newline. Must take
10972 account of the newline and the rest of the
10973 text that follows. */
10975 - CHARPOS (tlendpos
)
10976 - MATRIX_ROW_START_CHARPOS (row
));
10977 delta_bytes
= (Z_BYTE
10978 - BYTEPOS (tlendpos
)
10979 - MATRIX_ROW_START_BYTEPOS (row
));
10982 increment_matrix_positions (w
->current_matrix
,
10983 this_line_vpos
+ 1,
10984 w
->current_matrix
->nrows
,
10985 delta
, delta_bytes
);
10988 /* If this row displays text now but previously didn't,
10989 or vice versa, w->window_end_vpos may have to be
10991 if ((it
.glyph_row
- 1)->displays_text_p
)
10993 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10994 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10996 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10997 && this_line_vpos
> 0)
10998 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10999 w
->window_end_valid
= Qnil
;
11001 /* Update hint: No need to try to scroll in update_window. */
11002 w
->desired_matrix
->no_scrolling_p
= 1;
11005 *w
->desired_matrix
->method
= 0;
11006 debug_method_add (w
, "optimization 1");
11008 #ifdef HAVE_WINDOW_SYSTEM
11009 update_window_fringes (w
, 0);
11016 else if (/* Cursor position hasn't changed. */
11017 PT
== XFASTINT (w
->last_point
)
11018 /* Make sure the cursor was last displayed
11019 in this window. Otherwise we have to reposition it. */
11020 && 0 <= w
->cursor
.vpos
11021 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11025 do_pending_window_change (1);
11027 /* We used to always goto end_of_redisplay here, but this
11028 isn't enough if we have a blinking cursor. */
11029 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11030 goto end_of_redisplay
;
11034 /* If highlighting the region, or if the cursor is in the echo area,
11035 then we can't just move the cursor. */
11036 else if (! (!NILP (Vtransient_mark_mode
)
11037 && !NILP (current_buffer
->mark_active
))
11038 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11039 || highlight_nonselected_windows
)
11040 && NILP (w
->region_showing
)
11041 && NILP (Vshow_trailing_whitespace
)
11042 && !cursor_in_echo_area
)
11045 struct glyph_row
*row
;
11047 /* Skip from tlbufpos to PT and see where it is. Note that
11048 PT may be in invisible text. If so, we will end at the
11049 next visible position. */
11050 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11051 NULL
, DEFAULT_FACE_ID
);
11052 it
.current_x
= this_line_start_x
;
11053 it
.current_y
= this_line_y
;
11054 it
.vpos
= this_line_vpos
;
11056 /* The call to move_it_to stops in front of PT, but
11057 moves over before-strings. */
11058 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11060 if (it
.vpos
== this_line_vpos
11061 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11064 xassert (this_line_vpos
== it
.vpos
);
11065 xassert (this_line_y
== it
.current_y
);
11066 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11068 *w
->desired_matrix
->method
= 0;
11069 debug_method_add (w
, "optimization 3");
11078 /* Text changed drastically or point moved off of line. */
11079 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11082 CHARPOS (this_line_start_pos
) = 0;
11083 consider_all_windows_p
|= buffer_shared
> 1;
11084 ++clear_face_cache_count
;
11085 #ifdef HAVE_WINDOW_SYSTEM
11086 ++clear_image_cache_count
;
11089 /* Build desired matrices, and update the display. If
11090 consider_all_windows_p is non-zero, do it for all windows on all
11091 frames. Otherwise do it for selected_window, only. */
11093 if (consider_all_windows_p
)
11095 Lisp_Object tail
, frame
;
11097 FOR_EACH_FRAME (tail
, frame
)
11098 XFRAME (frame
)->updated_p
= 0;
11100 /* Recompute # windows showing selected buffer. This will be
11101 incremented each time such a window is displayed. */
11104 FOR_EACH_FRAME (tail
, frame
)
11106 struct frame
*f
= XFRAME (frame
);
11108 if (FRAME_WINDOW_P (f
) || f
== sf
)
11110 if (! EQ (frame
, selected_frame
))
11111 /* Select the frame, for the sake of frame-local
11113 select_frame_for_redisplay (frame
);
11115 /* Mark all the scroll bars to be removed; we'll redeem
11116 the ones we want when we redisplay their windows. */
11117 if (condemn_scroll_bars_hook
)
11118 condemn_scroll_bars_hook (f
);
11120 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11121 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11123 /* Any scroll bars which redisplay_windows should have
11124 nuked should now go away. */
11125 if (judge_scroll_bars_hook
)
11126 judge_scroll_bars_hook (f
);
11128 /* If fonts changed, display again. */
11129 /* ??? rms: I suspect it is a mistake to jump all the way
11130 back to retry here. It should just retry this frame. */
11131 if (fonts_changed_p
)
11134 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11136 /* See if we have to hscroll. */
11137 if (!f
->already_hscrolled_p
)
11139 f
->already_hscrolled_p
= 1;
11140 if (hscroll_windows (f
->root_window
))
11144 /* Prevent various kinds of signals during display
11145 update. stdio is not robust about handling
11146 signals, which can cause an apparent I/O
11148 if (interrupt_input
)
11149 unrequest_sigio ();
11152 /* Update the display. */
11153 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11154 pause
|= update_frame (f
, 0, 0);
11155 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11167 /* Do the mark_window_display_accurate after all windows have
11168 been redisplayed because this call resets flags in buffers
11169 which are needed for proper redisplay. */
11170 FOR_EACH_FRAME (tail
, frame
)
11172 struct frame
*f
= XFRAME (frame
);
11175 mark_window_display_accurate (f
->root_window
, 1);
11176 if (frame_up_to_date_hook
)
11177 frame_up_to_date_hook (f
);
11182 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11184 Lisp_Object mini_window
;
11185 struct frame
*mini_frame
;
11187 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11188 /* Use list_of_error, not Qerror, so that
11189 we catch only errors and don't run the debugger. */
11190 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11192 redisplay_window_error
);
11194 /* Compare desired and current matrices, perform output. */
11197 /* If fonts changed, display again. */
11198 if (fonts_changed_p
)
11201 /* Prevent various kinds of signals during display update.
11202 stdio is not robust about handling signals,
11203 which can cause an apparent I/O error. */
11204 if (interrupt_input
)
11205 unrequest_sigio ();
11208 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11210 if (hscroll_windows (selected_window
))
11213 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11214 pause
= update_frame (sf
, 0, 0);
11217 /* We may have called echo_area_display at the top of this
11218 function. If the echo area is on another frame, that may
11219 have put text on a frame other than the selected one, so the
11220 above call to update_frame would not have caught it. Catch
11222 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11223 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11225 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11227 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11228 pause
|= update_frame (mini_frame
, 0, 0);
11229 if (!pause
&& hscroll_windows (mini_window
))
11234 /* If display was paused because of pending input, make sure we do a
11235 thorough update the next time. */
11238 /* Prevent the optimization at the beginning of
11239 redisplay_internal that tries a single-line update of the
11240 line containing the cursor in the selected window. */
11241 CHARPOS (this_line_start_pos
) = 0;
11243 /* Let the overlay arrow be updated the next time. */
11244 update_overlay_arrows (0);
11246 /* If we pause after scrolling, some rows in the current
11247 matrices of some windows are not valid. */
11248 if (!WINDOW_FULL_WIDTH_P (w
)
11249 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11250 update_mode_lines
= 1;
11254 if (!consider_all_windows_p
)
11256 /* This has already been done above if
11257 consider_all_windows_p is set. */
11258 mark_window_display_accurate_1 (w
, 1);
11260 /* Say overlay arrows are up to date. */
11261 update_overlay_arrows (1);
11263 if (frame_up_to_date_hook
!= 0)
11264 frame_up_to_date_hook (sf
);
11267 update_mode_lines
= 0;
11268 windows_or_buffers_changed
= 0;
11269 cursor_type_changed
= 0;
11272 /* Start SIGIO interrupts coming again. Having them off during the
11273 code above makes it less likely one will discard output, but not
11274 impossible, since there might be stuff in the system buffer here.
11275 But it is much hairier to try to do anything about that. */
11276 if (interrupt_input
)
11280 /* If a frame has become visible which was not before, redisplay
11281 again, so that we display it. Expose events for such a frame
11282 (which it gets when becoming visible) don't call the parts of
11283 redisplay constructing glyphs, so simply exposing a frame won't
11284 display anything in this case. So, we have to display these
11285 frames here explicitly. */
11288 Lisp_Object tail
, frame
;
11291 FOR_EACH_FRAME (tail
, frame
)
11293 int this_is_visible
= 0;
11295 if (XFRAME (frame
)->visible
)
11296 this_is_visible
= 1;
11297 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11298 if (XFRAME (frame
)->visible
)
11299 this_is_visible
= 1;
11301 if (this_is_visible
)
11305 if (new_count
!= number_of_visible_frames
)
11306 windows_or_buffers_changed
++;
11309 /* Change frame size now if a change is pending. */
11310 do_pending_window_change (1);
11312 /* If we just did a pending size change, or have additional
11313 visible frames, redisplay again. */
11314 if (windows_or_buffers_changed
&& !pause
)
11317 /* Clear the face cache eventually. */
11318 if (consider_all_windows_p
)
11320 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11322 clear_face_cache (0);
11323 clear_face_cache_count
= 0;
11325 #ifdef HAVE_WINDOW_SYSTEM
11326 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11328 Lisp_Object tail
, frame
;
11329 FOR_EACH_FRAME (tail
, frame
)
11331 struct frame
*f
= XFRAME (frame
);
11332 if (FRAME_WINDOW_P (f
))
11333 clear_image_cache (f
, 0);
11335 clear_image_cache_count
= 0;
11337 #endif /* HAVE_WINDOW_SYSTEM */
11341 unbind_to (count
, Qnil
);
11346 /* Redisplay, but leave alone any recent echo area message unless
11347 another message has been requested in its place.
11349 This is useful in situations where you need to redisplay but no
11350 user action has occurred, making it inappropriate for the message
11351 area to be cleared. See tracking_off and
11352 wait_reading_process_output for examples of these situations.
11354 FROM_WHERE is an integer saying from where this function was
11355 called. This is useful for debugging. */
11358 redisplay_preserve_echo_area (from_where
)
11361 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11363 if (!NILP (echo_area_buffer
[1]))
11365 /* We have a previously displayed message, but no current
11366 message. Redisplay the previous message. */
11367 display_last_displayed_message_p
= 1;
11368 redisplay_internal (1);
11369 display_last_displayed_message_p
= 0;
11372 redisplay_internal (1);
11374 if (rif
!= NULL
&& rif
->flush_display_optional
)
11375 rif
->flush_display_optional (NULL
);
11379 /* Function registered with record_unwind_protect in
11380 redisplay_internal. Reset redisplaying_p to the value it had
11381 before redisplay_internal was called, and clear
11382 prevent_freeing_realized_faces_p. It also selects the previously
11386 unwind_redisplay (val
)
11389 Lisp_Object old_redisplaying_p
, old_frame
;
11391 old_redisplaying_p
= XCAR (val
);
11392 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11393 old_frame
= XCDR (val
);
11394 if (! EQ (old_frame
, selected_frame
))
11395 select_frame_for_redisplay (old_frame
);
11400 /* Mark the display of window W as accurate or inaccurate. If
11401 ACCURATE_P is non-zero mark display of W as accurate. If
11402 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11403 redisplay_internal is called. */
11406 mark_window_display_accurate_1 (w
, accurate_p
)
11410 if (BUFFERP (w
->buffer
))
11412 struct buffer
*b
= XBUFFER (w
->buffer
);
11415 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11416 w
->last_overlay_modified
11417 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11419 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11423 b
->clip_changed
= 0;
11424 b
->prevent_redisplay_optimizations_p
= 0;
11426 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11427 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11428 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11429 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11431 w
->current_matrix
->buffer
= b
;
11432 w
->current_matrix
->begv
= BUF_BEGV (b
);
11433 w
->current_matrix
->zv
= BUF_ZV (b
);
11435 w
->last_cursor
= w
->cursor
;
11436 w
->last_cursor_off_p
= w
->cursor_off_p
;
11438 if (w
== XWINDOW (selected_window
))
11439 w
->last_point
= make_number (BUF_PT (b
));
11441 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11447 w
->window_end_valid
= w
->buffer
;
11448 #if 0 /* This is incorrect with variable-height lines. */
11449 xassert (XINT (w
->window_end_vpos
)
11450 < (WINDOW_TOTAL_LINES (w
)
11451 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11453 w
->update_mode_line
= Qnil
;
11458 /* Mark the display of windows in the window tree rooted at WINDOW as
11459 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11460 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11461 be redisplayed the next time redisplay_internal is called. */
11464 mark_window_display_accurate (window
, accurate_p
)
11465 Lisp_Object window
;
11470 for (; !NILP (window
); window
= w
->next
)
11472 w
= XWINDOW (window
);
11473 mark_window_display_accurate_1 (w
, accurate_p
);
11475 if (!NILP (w
->vchild
))
11476 mark_window_display_accurate (w
->vchild
, accurate_p
);
11477 if (!NILP (w
->hchild
))
11478 mark_window_display_accurate (w
->hchild
, accurate_p
);
11483 update_overlay_arrows (1);
11487 /* Force a thorough redisplay the next time by setting
11488 last_arrow_position and last_arrow_string to t, which is
11489 unequal to any useful value of Voverlay_arrow_... */
11490 update_overlay_arrows (-1);
11495 /* Return value in display table DP (Lisp_Char_Table *) for character
11496 C. Since a display table doesn't have any parent, we don't have to
11497 follow parent. Do not call this function directly but use the
11498 macro DISP_CHAR_VECTOR. */
11501 disp_char_vector (dp
, c
)
11502 struct Lisp_Char_Table
*dp
;
11508 if (SINGLE_BYTE_CHAR_P (c
))
11509 return (dp
->contents
[c
]);
11511 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11514 else if (code
[2] < 32)
11517 /* Here, the possible range of code[0] (== charset ID) is
11518 128..max_charset. Since the top level char table contains data
11519 for multibyte characters after 256th element, we must increment
11520 code[0] by 128 to get a correct index. */
11522 code
[3] = -1; /* anchor */
11524 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11526 val
= dp
->contents
[code
[i
]];
11527 if (!SUB_CHAR_TABLE_P (val
))
11528 return (NILP (val
) ? dp
->defalt
: val
);
11531 /* Here, val is a sub char table. We return the default value of
11533 return (dp
->defalt
);
11538 /***********************************************************************
11540 ***********************************************************************/
11542 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11545 redisplay_windows (window
)
11546 Lisp_Object window
;
11548 while (!NILP (window
))
11550 struct window
*w
= XWINDOW (window
);
11552 if (!NILP (w
->hchild
))
11553 redisplay_windows (w
->hchild
);
11554 else if (!NILP (w
->vchild
))
11555 redisplay_windows (w
->vchild
);
11558 displayed_buffer
= XBUFFER (w
->buffer
);
11559 /* Use list_of_error, not Qerror, so that
11560 we catch only errors and don't run the debugger. */
11561 internal_condition_case_1 (redisplay_window_0
, window
,
11563 redisplay_window_error
);
11571 redisplay_window_error ()
11573 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11578 redisplay_window_0 (window
)
11579 Lisp_Object window
;
11581 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11582 redisplay_window (window
, 0);
11587 redisplay_window_1 (window
)
11588 Lisp_Object window
;
11590 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11591 redisplay_window (window
, 1);
11596 /* Increment GLYPH until it reaches END or CONDITION fails while
11597 adding (GLYPH)->pixel_width to X. */
11599 #define SKIP_GLYPHS(glyph, end, x, condition) \
11602 (x) += (glyph)->pixel_width; \
11605 while ((glyph) < (end) && (condition))
11608 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11609 DELTA is the number of bytes by which positions recorded in ROW
11610 differ from current buffer positions. */
11613 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11615 struct glyph_row
*row
;
11616 struct glyph_matrix
*matrix
;
11617 int delta
, delta_bytes
, dy
, dvpos
;
11619 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11620 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11621 struct glyph
*cursor
= NULL
;
11622 /* The first glyph that starts a sequence of glyphs from string. */
11623 struct glyph
*string_start
;
11624 /* The X coordinate of string_start. */
11625 int string_start_x
;
11626 /* The last known character position. */
11627 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11628 /* The last known character position before string_start. */
11629 int string_before_pos
;
11632 int cursor_from_overlay_pos
= 0;
11633 int pt_old
= PT
- delta
;
11635 /* Skip over glyphs not having an object at the start of the row.
11636 These are special glyphs like truncation marks on terminal
11638 if (row
->displays_text_p
)
11640 && INTEGERP (glyph
->object
)
11641 && glyph
->charpos
< 0)
11643 x
+= glyph
->pixel_width
;
11647 string_start
= NULL
;
11649 && !INTEGERP (glyph
->object
)
11650 && (!BUFFERP (glyph
->object
)
11651 || (last_pos
= glyph
->charpos
) < pt_old
))
11653 if (! STRINGP (glyph
->object
))
11655 string_start
= NULL
;
11656 x
+= glyph
->pixel_width
;
11658 if (cursor_from_overlay_pos
11659 && last_pos
>= cursor_from_overlay_pos
)
11661 cursor_from_overlay_pos
= 0;
11667 string_before_pos
= last_pos
;
11668 string_start
= glyph
;
11669 string_start_x
= x
;
11670 /* Skip all glyphs from string. */
11675 if ((cursor
== NULL
|| glyph
> cursor
)
11676 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11677 Qcursor
, (glyph
)->object
),
11679 && (pos
= string_buffer_position (w
, glyph
->object
,
11680 string_before_pos
),
11681 (pos
== 0 /* From overlay */
11682 || pos
== pt_old
)))
11684 /* Estimate overlay buffer position from the buffer
11685 positions of the glyphs before and after the overlay.
11686 Add 1 to last_pos so that if point corresponds to the
11687 glyph right after the overlay, we still use a 'cursor'
11688 property found in that overlay. */
11689 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11690 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11694 x
+= glyph
->pixel_width
;
11697 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11701 if (cursor
!= NULL
)
11706 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11708 /* Scan back over the ellipsis glyphs, decrementing positions. */
11709 while (glyph
> row
->glyphs
[TEXT_AREA
]
11710 && (glyph
- 1)->charpos
== last_pos
)
11711 glyph
--, x
-= glyph
->pixel_width
;
11712 /* That loop always goes one position too far,
11713 including the glyph before the ellipsis.
11714 So scan forward over that one. */
11715 x
+= glyph
->pixel_width
;
11718 else if (string_start
11719 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11721 /* We may have skipped over point because the previous glyphs
11722 are from string. As there's no easy way to know the
11723 character position of the current glyph, find the correct
11724 glyph on point by scanning from string_start again. */
11726 Lisp_Object string
;
11729 limit
= make_number (pt_old
+ 1);
11731 glyph
= string_start
;
11732 x
= string_start_x
;
11733 string
= glyph
->object
;
11734 pos
= string_buffer_position (w
, string
, string_before_pos
);
11735 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11736 because we always put cursor after overlay strings. */
11737 while (pos
== 0 && glyph
< end
)
11739 string
= glyph
->object
;
11740 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11742 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11745 while (glyph
< end
)
11747 pos
= XINT (Fnext_single_char_property_change
11748 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11751 /* Skip glyphs from the same string. */
11752 string
= glyph
->object
;
11753 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11754 /* Skip glyphs from an overlay. */
11756 && ! string_buffer_position (w
, glyph
->object
, pos
))
11758 string
= glyph
->object
;
11759 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11764 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11766 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11767 w
->cursor
.y
= row
->y
+ dy
;
11769 if (w
== XWINDOW (selected_window
))
11771 if (!row
->continued_p
11772 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11775 this_line_buffer
= XBUFFER (w
->buffer
);
11777 CHARPOS (this_line_start_pos
)
11778 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11779 BYTEPOS (this_line_start_pos
)
11780 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11782 CHARPOS (this_line_end_pos
)
11783 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11784 BYTEPOS (this_line_end_pos
)
11785 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11787 this_line_y
= w
->cursor
.y
;
11788 this_line_pixel_height
= row
->height
;
11789 this_line_vpos
= w
->cursor
.vpos
;
11790 this_line_start_x
= row
->x
;
11793 CHARPOS (this_line_start_pos
) = 0;
11798 /* Run window scroll functions, if any, for WINDOW with new window
11799 start STARTP. Sets the window start of WINDOW to that position.
11801 We assume that the window's buffer is really current. */
11803 static INLINE
struct text_pos
11804 run_window_scroll_functions (window
, startp
)
11805 Lisp_Object window
;
11806 struct text_pos startp
;
11808 struct window
*w
= XWINDOW (window
);
11809 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11811 if (current_buffer
!= XBUFFER (w
->buffer
))
11814 if (!NILP (Vwindow_scroll_functions
))
11816 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11817 make_number (CHARPOS (startp
)));
11818 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11819 /* In case the hook functions switch buffers. */
11820 if (current_buffer
!= XBUFFER (w
->buffer
))
11821 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11828 /* Make sure the line containing the cursor is fully visible.
11829 A value of 1 means there is nothing to be done.
11830 (Either the line is fully visible, or it cannot be made so,
11831 or we cannot tell.)
11833 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11834 is higher than window.
11836 A value of 0 means the caller should do scrolling
11837 as if point had gone off the screen. */
11840 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11843 int current_matrix_p
;
11845 struct glyph_matrix
*matrix
;
11846 struct glyph_row
*row
;
11849 if (!make_cursor_line_fully_visible_p
)
11852 /* It's not always possible to find the cursor, e.g, when a window
11853 is full of overlay strings. Don't do anything in that case. */
11854 if (w
->cursor
.vpos
< 0)
11857 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11858 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11860 /* If the cursor row is not partially visible, there's nothing to do. */
11861 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11864 /* If the row the cursor is in is taller than the window's height,
11865 it's not clear what to do, so do nothing. */
11866 window_height
= window_box_height (w
);
11867 if (row
->height
>= window_height
)
11869 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11875 /* This code used to try to scroll the window just enough to make
11876 the line visible. It returned 0 to say that the caller should
11877 allocate larger glyph matrices. */
11879 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11881 int dy
= row
->height
- row
->visible_height
;
11884 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11886 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11888 int dy
= - (row
->height
- row
->visible_height
);
11891 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11894 /* When we change the cursor y-position of the selected window,
11895 change this_line_y as well so that the display optimization for
11896 the cursor line of the selected window in redisplay_internal uses
11897 the correct y-position. */
11898 if (w
== XWINDOW (selected_window
))
11899 this_line_y
= w
->cursor
.y
;
11901 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11902 redisplay with larger matrices. */
11903 if (matrix
->nrows
< required_matrix_height (w
))
11905 fonts_changed_p
= 1;
11914 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11915 non-zero means only WINDOW is redisplayed in redisplay_internal.
11916 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11917 in redisplay_window to bring a partially visible line into view in
11918 the case that only the cursor has moved.
11920 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11921 last screen line's vertical height extends past the end of the screen.
11925 1 if scrolling succeeded
11927 0 if scrolling didn't find point.
11929 -1 if new fonts have been loaded so that we must interrupt
11930 redisplay, adjust glyph matrices, and try again. */
11936 SCROLLING_NEED_LARGER_MATRICES
11940 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11941 scroll_step
, temp_scroll_step
, last_line_misfit
)
11942 Lisp_Object window
;
11943 int just_this_one_p
;
11944 EMACS_INT scroll_conservatively
, scroll_step
;
11945 int temp_scroll_step
;
11946 int last_line_misfit
;
11948 struct window
*w
= XWINDOW (window
);
11949 struct frame
*f
= XFRAME (w
->frame
);
11950 struct text_pos scroll_margin_pos
;
11951 struct text_pos pos
;
11952 struct text_pos startp
;
11954 Lisp_Object window_end
;
11955 int this_scroll_margin
;
11959 int amount_to_scroll
= 0;
11960 Lisp_Object aggressive
;
11962 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11965 debug_method_add (w
, "try_scrolling");
11968 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11970 /* Compute scroll margin height in pixels. We scroll when point is
11971 within this distance from the top or bottom of the window. */
11972 if (scroll_margin
> 0)
11974 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11975 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11978 this_scroll_margin
= 0;
11980 /* Force scroll_conservatively to have a reasonable value so it doesn't
11981 cause an overflow while computing how much to scroll. */
11982 if (scroll_conservatively
)
11983 scroll_conservatively
= min (scroll_conservatively
,
11984 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11986 /* Compute how much we should try to scroll maximally to bring point
11988 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11989 scroll_max
= max (scroll_step
,
11990 max (scroll_conservatively
, temp_scroll_step
));
11991 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11992 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11993 /* We're trying to scroll because of aggressive scrolling
11994 but no scroll_step is set. Choose an arbitrary one. Maybe
11995 there should be a variable for this. */
11999 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12001 /* Decide whether we have to scroll down. Start at the window end
12002 and move this_scroll_margin up to find the position of the scroll
12004 window_end
= Fwindow_end (window
, Qt
);
12008 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12009 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12011 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12013 start_display (&it
, w
, scroll_margin_pos
);
12014 if (this_scroll_margin
)
12015 move_it_vertically_backward (&it
, this_scroll_margin
);
12016 if (extra_scroll_margin_lines
)
12017 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12018 scroll_margin_pos
= it
.current
.pos
;
12021 if (PT
>= CHARPOS (scroll_margin_pos
))
12025 /* Point is in the scroll margin at the bottom of the window, or
12026 below. Compute a new window start that makes point visible. */
12028 /* Compute the distance from the scroll margin to PT.
12029 Give up if the distance is greater than scroll_max. */
12030 start_display (&it
, w
, scroll_margin_pos
);
12032 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12033 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12035 /* To make point visible, we have to move the window start
12036 down so that the line the cursor is in is visible, which
12037 means we have to add in the height of the cursor line. */
12038 dy
= line_bottom_y (&it
) - y0
;
12040 if (dy
> scroll_max
)
12041 return SCROLLING_FAILED
;
12043 /* Move the window start down. If scrolling conservatively,
12044 move it just enough down to make point visible. If
12045 scroll_step is set, move it down by scroll_step. */
12046 start_display (&it
, w
, startp
);
12048 if (scroll_conservatively
)
12049 /* Set AMOUNT_TO_SCROLL to at least one line,
12050 and at most scroll_conservatively lines. */
12052 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12053 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12054 else if (scroll_step
|| temp_scroll_step
)
12055 amount_to_scroll
= scroll_max
;
12058 aggressive
= current_buffer
->scroll_up_aggressively
;
12059 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12060 if (NUMBERP (aggressive
))
12062 double float_amount
= XFLOATINT (aggressive
) * height
;
12063 amount_to_scroll
= float_amount
;
12064 if (amount_to_scroll
== 0 && float_amount
> 0)
12065 amount_to_scroll
= 1;
12069 if (amount_to_scroll
<= 0)
12070 return SCROLLING_FAILED
;
12072 /* If moving by amount_to_scroll leaves STARTP unchanged,
12073 move it down one screen line. */
12075 move_it_vertically (&it
, amount_to_scroll
);
12076 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12077 move_it_by_lines (&it
, 1, 1);
12078 startp
= it
.current
.pos
;
12082 /* See if point is inside the scroll margin at the top of the
12084 scroll_margin_pos
= startp
;
12085 if (this_scroll_margin
)
12087 start_display (&it
, w
, startp
);
12088 move_it_vertically (&it
, this_scroll_margin
);
12089 scroll_margin_pos
= it
.current
.pos
;
12092 if (PT
< CHARPOS (scroll_margin_pos
))
12094 /* Point is in the scroll margin at the top of the window or
12095 above what is displayed in the window. */
12098 /* Compute the vertical distance from PT to the scroll
12099 margin position. Give up if distance is greater than
12101 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12102 start_display (&it
, w
, pos
);
12104 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12105 it
.last_visible_y
, -1,
12106 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12107 dy
= it
.current_y
- y0
;
12108 if (dy
> scroll_max
)
12109 return SCROLLING_FAILED
;
12111 /* Compute new window start. */
12112 start_display (&it
, w
, startp
);
12114 if (scroll_conservatively
)
12116 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12117 else if (scroll_step
|| temp_scroll_step
)
12118 amount_to_scroll
= scroll_max
;
12121 aggressive
= current_buffer
->scroll_down_aggressively
;
12122 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12123 if (NUMBERP (aggressive
))
12125 double float_amount
= XFLOATINT (aggressive
) * height
;
12126 amount_to_scroll
= float_amount
;
12127 if (amount_to_scroll
== 0 && float_amount
> 0)
12128 amount_to_scroll
= 1;
12132 if (amount_to_scroll
<= 0)
12133 return SCROLLING_FAILED
;
12135 move_it_vertically_backward (&it
, amount_to_scroll
);
12136 startp
= it
.current
.pos
;
12140 /* Run window scroll functions. */
12141 startp
= run_window_scroll_functions (window
, startp
);
12143 /* Display the window. Give up if new fonts are loaded, or if point
12145 if (!try_window (window
, startp
, 0))
12146 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12147 else if (w
->cursor
.vpos
< 0)
12149 clear_glyph_matrix (w
->desired_matrix
);
12150 rc
= SCROLLING_FAILED
;
12154 /* Maybe forget recorded base line for line number display. */
12155 if (!just_this_one_p
12156 || current_buffer
->clip_changed
12157 || BEG_UNCHANGED
< CHARPOS (startp
))
12158 w
->base_line_number
= Qnil
;
12160 /* If cursor ends up on a partially visible line,
12161 treat that as being off the bottom of the screen. */
12162 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12164 clear_glyph_matrix (w
->desired_matrix
);
12165 ++extra_scroll_margin_lines
;
12168 rc
= SCROLLING_SUCCESS
;
12175 /* Compute a suitable window start for window W if display of W starts
12176 on a continuation line. Value is non-zero if a new window start
12179 The new window start will be computed, based on W's width, starting
12180 from the start of the continued line. It is the start of the
12181 screen line with the minimum distance from the old start W->start. */
12184 compute_window_start_on_continuation_line (w
)
12187 struct text_pos pos
, start_pos
;
12188 int window_start_changed_p
= 0;
12190 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12192 /* If window start is on a continuation line... Window start may be
12193 < BEGV in case there's invisible text at the start of the
12194 buffer (M-x rmail, for example). */
12195 if (CHARPOS (start_pos
) > BEGV
12196 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12199 struct glyph_row
*row
;
12201 /* Handle the case that the window start is out of range. */
12202 if (CHARPOS (start_pos
) < BEGV
)
12203 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12204 else if (CHARPOS (start_pos
) > ZV
)
12205 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12207 /* Find the start of the continued line. This should be fast
12208 because scan_buffer is fast (newline cache). */
12209 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12210 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12211 row
, DEFAULT_FACE_ID
);
12212 reseat_at_previous_visible_line_start (&it
);
12214 /* If the line start is "too far" away from the window start,
12215 say it takes too much time to compute a new window start. */
12216 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12217 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12219 int min_distance
, distance
;
12221 /* Move forward by display lines to find the new window
12222 start. If window width was enlarged, the new start can
12223 be expected to be > the old start. If window width was
12224 decreased, the new window start will be < the old start.
12225 So, we're looking for the display line start with the
12226 minimum distance from the old window start. */
12227 pos
= it
.current
.pos
;
12228 min_distance
= INFINITY
;
12229 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12230 distance
< min_distance
)
12232 min_distance
= distance
;
12233 pos
= it
.current
.pos
;
12234 move_it_by_lines (&it
, 1, 0);
12237 /* Set the window start there. */
12238 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12239 window_start_changed_p
= 1;
12243 return window_start_changed_p
;
12247 /* Try cursor movement in case text has not changed in window WINDOW,
12248 with window start STARTP. Value is
12250 CURSOR_MOVEMENT_SUCCESS if successful
12252 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12254 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12255 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12256 we want to scroll as if scroll-step were set to 1. See the code.
12258 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12259 which case we have to abort this redisplay, and adjust matrices
12264 CURSOR_MOVEMENT_SUCCESS
,
12265 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12266 CURSOR_MOVEMENT_MUST_SCROLL
,
12267 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12271 try_cursor_movement (window
, startp
, scroll_step
)
12272 Lisp_Object window
;
12273 struct text_pos startp
;
12276 struct window
*w
= XWINDOW (window
);
12277 struct frame
*f
= XFRAME (w
->frame
);
12278 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12281 if (inhibit_try_cursor_movement
)
12285 /* Handle case where text has not changed, only point, and it has
12286 not moved off the frame. */
12287 if (/* Point may be in this window. */
12288 PT
>= CHARPOS (startp
)
12289 /* Selective display hasn't changed. */
12290 && !current_buffer
->clip_changed
12291 /* Function force-mode-line-update is used to force a thorough
12292 redisplay. It sets either windows_or_buffers_changed or
12293 update_mode_lines. So don't take a shortcut here for these
12295 && !update_mode_lines
12296 && !windows_or_buffers_changed
12297 && !cursor_type_changed
12298 /* Can't use this case if highlighting a region. When a
12299 region exists, cursor movement has to do more than just
12301 && !(!NILP (Vtransient_mark_mode
)
12302 && !NILP (current_buffer
->mark_active
))
12303 && NILP (w
->region_showing
)
12304 && NILP (Vshow_trailing_whitespace
)
12305 /* Right after splitting windows, last_point may be nil. */
12306 && INTEGERP (w
->last_point
)
12307 /* This code is not used for mini-buffer for the sake of the case
12308 of redisplaying to replace an echo area message; since in
12309 that case the mini-buffer contents per se are usually
12310 unchanged. This code is of no real use in the mini-buffer
12311 since the handling of this_line_start_pos, etc., in redisplay
12312 handles the same cases. */
12313 && !EQ (window
, minibuf_window
)
12314 /* When splitting windows or for new windows, it happens that
12315 redisplay is called with a nil window_end_vpos or one being
12316 larger than the window. This should really be fixed in
12317 window.c. I don't have this on my list, now, so we do
12318 approximately the same as the old redisplay code. --gerd. */
12319 && INTEGERP (w
->window_end_vpos
)
12320 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12321 && (FRAME_WINDOW_P (f
)
12322 || !overlay_arrow_in_current_buffer_p ()))
12324 int this_scroll_margin
, top_scroll_margin
;
12325 struct glyph_row
*row
= NULL
;
12328 debug_method_add (w
, "cursor movement");
12331 /* Scroll if point within this distance from the top or bottom
12332 of the window. This is a pixel value. */
12333 this_scroll_margin
= max (0, scroll_margin
);
12334 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12335 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12337 top_scroll_margin
= this_scroll_margin
;
12338 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12339 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12341 /* Start with the row the cursor was displayed during the last
12342 not paused redisplay. Give up if that row is not valid. */
12343 if (w
->last_cursor
.vpos
< 0
12344 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12345 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12348 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12349 if (row
->mode_line_p
)
12351 if (!row
->enabled_p
)
12352 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12355 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12358 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12360 if (PT
> XFASTINT (w
->last_point
))
12362 /* Point has moved forward. */
12363 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12364 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12366 xassert (row
->enabled_p
);
12370 /* The end position of a row equals the start position
12371 of the next row. If PT is there, we would rather
12372 display it in the next line. */
12373 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12374 && MATRIX_ROW_END_CHARPOS (row
) == PT
12375 && !cursor_row_p (w
, row
))
12378 /* If within the scroll margin, scroll. Note that
12379 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12380 the next line would be drawn, and that
12381 this_scroll_margin can be zero. */
12382 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12383 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12384 /* Line is completely visible last line in window
12385 and PT is to be set in the next line. */
12386 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12387 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12388 && !row
->ends_at_zv_p
12389 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12392 else if (PT
< XFASTINT (w
->last_point
))
12394 /* Cursor has to be moved backward. Note that PT >=
12395 CHARPOS (startp) because of the outer if-statement. */
12396 while (!row
->mode_line_p
12397 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12398 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12399 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12400 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12401 row
> w
->current_matrix
->rows
12402 && (row
-1)->ends_in_newline_from_string_p
))))
12403 && (row
->y
> top_scroll_margin
12404 || CHARPOS (startp
) == BEGV
))
12406 xassert (row
->enabled_p
);
12410 /* Consider the following case: Window starts at BEGV,
12411 there is invisible, intangible text at BEGV, so that
12412 display starts at some point START > BEGV. It can
12413 happen that we are called with PT somewhere between
12414 BEGV and START. Try to handle that case. */
12415 if (row
< w
->current_matrix
->rows
12416 || row
->mode_line_p
)
12418 row
= w
->current_matrix
->rows
;
12419 if (row
->mode_line_p
)
12423 /* Due to newlines in overlay strings, we may have to
12424 skip forward over overlay strings. */
12425 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12426 && MATRIX_ROW_END_CHARPOS (row
) == PT
12427 && !cursor_row_p (w
, row
))
12430 /* If within the scroll margin, scroll. */
12431 if (row
->y
< top_scroll_margin
12432 && CHARPOS (startp
) != BEGV
)
12437 /* Cursor did not move. So don't scroll even if cursor line
12438 is partially visible, as it was so before. */
12439 rc
= CURSOR_MOVEMENT_SUCCESS
;
12442 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12443 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12445 /* if PT is not in the glyph row, give up. */
12446 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12448 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12449 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12450 && make_cursor_line_fully_visible_p
)
12452 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12453 && !row
->ends_at_zv_p
12454 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12455 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12456 else if (row
->height
> window_box_height (w
))
12458 /* If we end up in a partially visible line, let's
12459 make it fully visible, except when it's taller
12460 than the window, in which case we can't do much
12463 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12467 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12468 if (!cursor_row_fully_visible_p (w
, 0, 1))
12469 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12471 rc
= CURSOR_MOVEMENT_SUCCESS
;
12475 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12478 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12479 rc
= CURSOR_MOVEMENT_SUCCESS
;
12488 set_vertical_scroll_bar (w
)
12491 int start
, end
, whole
;
12493 /* Calculate the start and end positions for the current window.
12494 At some point, it would be nice to choose between scrollbars
12495 which reflect the whole buffer size, with special markers
12496 indicating narrowing, and scrollbars which reflect only the
12499 Note that mini-buffers sometimes aren't displaying any text. */
12500 if (!MINI_WINDOW_P (w
)
12501 || (w
== XWINDOW (minibuf_window
)
12502 && NILP (echo_area_buffer
[0])))
12504 struct buffer
*buf
= XBUFFER (w
->buffer
);
12505 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12506 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12507 /* I don't think this is guaranteed to be right. For the
12508 moment, we'll pretend it is. */
12509 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12513 if (whole
< (end
- start
))
12514 whole
= end
- start
;
12517 start
= end
= whole
= 0;
12519 /* Indicate what this scroll bar ought to be displaying now. */
12520 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12524 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12525 selected_window is redisplayed.
12527 We can return without actually redisplaying the window if
12528 fonts_changed_p is nonzero. In that case, redisplay_internal will
12532 redisplay_window (window
, just_this_one_p
)
12533 Lisp_Object window
;
12534 int just_this_one_p
;
12536 struct window
*w
= XWINDOW (window
);
12537 struct frame
*f
= XFRAME (w
->frame
);
12538 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12539 struct buffer
*old
= current_buffer
;
12540 struct text_pos lpoint
, opoint
, startp
;
12541 int update_mode_line
;
12544 /* Record it now because it's overwritten. */
12545 int current_matrix_up_to_date_p
= 0;
12546 int used_current_matrix_p
= 0;
12547 /* This is less strict than current_matrix_up_to_date_p.
12548 It indictes that the buffer contents and narrowing are unchanged. */
12549 int buffer_unchanged_p
= 0;
12550 int temp_scroll_step
= 0;
12551 int count
= SPECPDL_INDEX ();
12553 int centering_position
= -1;
12554 int last_line_misfit
= 0;
12556 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12559 /* W must be a leaf window here. */
12560 xassert (!NILP (w
->buffer
));
12562 *w
->desired_matrix
->method
= 0;
12565 specbind (Qinhibit_point_motion_hooks
, Qt
);
12567 reconsider_clip_changes (w
, buffer
);
12569 /* Has the mode line to be updated? */
12570 update_mode_line
= (!NILP (w
->update_mode_line
)
12571 || update_mode_lines
12572 || buffer
->clip_changed
12573 || buffer
->prevent_redisplay_optimizations_p
);
12575 if (MINI_WINDOW_P (w
))
12577 if (w
== XWINDOW (echo_area_window
)
12578 && !NILP (echo_area_buffer
[0]))
12580 if (update_mode_line
)
12581 /* We may have to update a tty frame's menu bar or a
12582 tool-bar. Example `M-x C-h C-h C-g'. */
12583 goto finish_menu_bars
;
12585 /* We've already displayed the echo area glyphs in this window. */
12586 goto finish_scroll_bars
;
12588 else if ((w
!= XWINDOW (minibuf_window
)
12589 || minibuf_level
== 0)
12590 /* When buffer is nonempty, redisplay window normally. */
12591 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12592 /* Quail displays non-mini buffers in minibuffer window.
12593 In that case, redisplay the window normally. */
12594 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12596 /* W is a mini-buffer window, but it's not active, so clear
12598 int yb
= window_text_bottom_y (w
);
12599 struct glyph_row
*row
;
12602 for (y
= 0, row
= w
->desired_matrix
->rows
;
12604 y
+= row
->height
, ++row
)
12605 blank_row (w
, row
, y
);
12606 goto finish_scroll_bars
;
12609 clear_glyph_matrix (w
->desired_matrix
);
12612 /* Otherwise set up data on this window; select its buffer and point
12614 /* Really select the buffer, for the sake of buffer-local
12616 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12617 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12619 current_matrix_up_to_date_p
12620 = (!NILP (w
->window_end_valid
)
12621 && !current_buffer
->clip_changed
12622 && !current_buffer
->prevent_redisplay_optimizations_p
12623 && XFASTINT (w
->last_modified
) >= MODIFF
12624 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12627 = (!NILP (w
->window_end_valid
)
12628 && !current_buffer
->clip_changed
12629 && XFASTINT (w
->last_modified
) >= MODIFF
12630 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12632 /* When windows_or_buffers_changed is non-zero, we can't rely on
12633 the window end being valid, so set it to nil there. */
12634 if (windows_or_buffers_changed
)
12636 /* If window starts on a continuation line, maybe adjust the
12637 window start in case the window's width changed. */
12638 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12639 compute_window_start_on_continuation_line (w
);
12641 w
->window_end_valid
= Qnil
;
12644 /* Some sanity checks. */
12645 CHECK_WINDOW_END (w
);
12646 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12648 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12651 /* If %c is in mode line, update it if needed. */
12652 if (!NILP (w
->column_number_displayed
)
12653 /* This alternative quickly identifies a common case
12654 where no change is needed. */
12655 && !(PT
== XFASTINT (w
->last_point
)
12656 && XFASTINT (w
->last_modified
) >= MODIFF
12657 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12658 && (XFASTINT (w
->column_number_displayed
)
12659 != (int) current_column ())) /* iftc */
12660 update_mode_line
= 1;
12662 /* Count number of windows showing the selected buffer. An indirect
12663 buffer counts as its base buffer. */
12664 if (!just_this_one_p
)
12666 struct buffer
*current_base
, *window_base
;
12667 current_base
= current_buffer
;
12668 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12669 if (current_base
->base_buffer
)
12670 current_base
= current_base
->base_buffer
;
12671 if (window_base
->base_buffer
)
12672 window_base
= window_base
->base_buffer
;
12673 if (current_base
== window_base
)
12677 /* Point refers normally to the selected window. For any other
12678 window, set up appropriate value. */
12679 if (!EQ (window
, selected_window
))
12681 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12682 int new_pt_byte
= marker_byte_position (w
->pointm
);
12686 new_pt_byte
= BEGV_BYTE
;
12687 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12689 else if (new_pt
> (ZV
- 1))
12692 new_pt_byte
= ZV_BYTE
;
12693 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12696 /* We don't use SET_PT so that the point-motion hooks don't run. */
12697 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12700 /* If any of the character widths specified in the display table
12701 have changed, invalidate the width run cache. It's true that
12702 this may be a bit late to catch such changes, but the rest of
12703 redisplay goes (non-fatally) haywire when the display table is
12704 changed, so why should we worry about doing any better? */
12705 if (current_buffer
->width_run_cache
)
12707 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12709 if (! disptab_matches_widthtab (disptab
,
12710 XVECTOR (current_buffer
->width_table
)))
12712 invalidate_region_cache (current_buffer
,
12713 current_buffer
->width_run_cache
,
12715 recompute_width_table (current_buffer
, disptab
);
12719 /* If window-start is screwed up, choose a new one. */
12720 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12723 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12725 /* If someone specified a new starting point but did not insist,
12726 check whether it can be used. */
12727 if (!NILP (w
->optional_new_start
)
12728 && CHARPOS (startp
) >= BEGV
12729 && CHARPOS (startp
) <= ZV
)
12731 w
->optional_new_start
= Qnil
;
12732 start_display (&it
, w
, startp
);
12733 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12734 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12735 if (IT_CHARPOS (it
) == PT
)
12736 w
->force_start
= Qt
;
12737 /* IT may overshoot PT if text at PT is invisible. */
12738 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12739 w
->force_start
= Qt
;
12742 /* Handle case where place to start displaying has been specified,
12743 unless the specified location is outside the accessible range. */
12744 if (!NILP (w
->force_start
)
12745 || w
->frozen_window_start_p
)
12747 /* We set this later on if we have to adjust point. */
12751 w
->force_start
= Qnil
;
12753 w
->window_end_valid
= Qnil
;
12755 /* Forget any recorded base line for line number display. */
12756 if (!buffer_unchanged_p
)
12757 w
->base_line_number
= Qnil
;
12759 /* Redisplay the mode line. Select the buffer properly for that.
12760 Also, run the hook window-scroll-functions
12761 because we have scrolled. */
12762 /* Note, we do this after clearing force_start because
12763 if there's an error, it is better to forget about force_start
12764 than to get into an infinite loop calling the hook functions
12765 and having them get more errors. */
12766 if (!update_mode_line
12767 || ! NILP (Vwindow_scroll_functions
))
12769 update_mode_line
= 1;
12770 w
->update_mode_line
= Qt
;
12771 startp
= run_window_scroll_functions (window
, startp
);
12774 w
->last_modified
= make_number (0);
12775 w
->last_overlay_modified
= make_number (0);
12776 if (CHARPOS (startp
) < BEGV
)
12777 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12778 else if (CHARPOS (startp
) > ZV
)
12779 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12781 /* Redisplay, then check if cursor has been set during the
12782 redisplay. Give up if new fonts were loaded. */
12783 val
= try_window (window
, startp
, 1);
12786 w
->force_start
= Qt
;
12787 clear_glyph_matrix (w
->desired_matrix
);
12788 goto need_larger_matrices
;
12790 /* Point was outside the scroll margins. */
12792 new_vpos
= window_box_height (w
) / 2;
12794 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12796 /* If point does not appear, try to move point so it does
12797 appear. The desired matrix has been built above, so we
12798 can use it here. */
12799 new_vpos
= window_box_height (w
) / 2;
12802 if (!cursor_row_fully_visible_p (w
, 0, 0))
12804 /* Point does appear, but on a line partly visible at end of window.
12805 Move it back to a fully-visible line. */
12806 new_vpos
= window_box_height (w
);
12809 /* If we need to move point for either of the above reasons,
12810 now actually do it. */
12813 struct glyph_row
*row
;
12815 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12816 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12819 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12820 MATRIX_ROW_START_BYTEPOS (row
));
12822 if (w
!= XWINDOW (selected_window
))
12823 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12824 else if (current_buffer
== old
)
12825 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12827 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12829 /* If we are highlighting the region, then we just changed
12830 the region, so redisplay to show it. */
12831 if (!NILP (Vtransient_mark_mode
)
12832 && !NILP (current_buffer
->mark_active
))
12834 clear_glyph_matrix (w
->desired_matrix
);
12835 if (!try_window (window
, startp
, 0))
12836 goto need_larger_matrices
;
12841 debug_method_add (w
, "forced window start");
12846 /* Handle case where text has not changed, only point, and it has
12847 not moved off the frame, and we are not retrying after hscroll.
12848 (current_matrix_up_to_date_p is nonzero when retrying.) */
12849 if (current_matrix_up_to_date_p
12850 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12851 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12855 case CURSOR_MOVEMENT_SUCCESS
:
12856 used_current_matrix_p
= 1;
12859 #if 0 /* try_cursor_movement never returns this value. */
12860 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12861 goto need_larger_matrices
;
12864 case CURSOR_MOVEMENT_MUST_SCROLL
:
12865 goto try_to_scroll
;
12871 /* If current starting point was originally the beginning of a line
12872 but no longer is, find a new starting point. */
12873 else if (!NILP (w
->start_at_line_beg
)
12874 && !(CHARPOS (startp
) <= BEGV
12875 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12878 debug_method_add (w
, "recenter 1");
12883 /* Try scrolling with try_window_id. Value is > 0 if update has
12884 been done, it is -1 if we know that the same window start will
12885 not work. It is 0 if unsuccessful for some other reason. */
12886 else if ((tem
= try_window_id (w
)) != 0)
12889 debug_method_add (w
, "try_window_id %d", tem
);
12892 if (fonts_changed_p
)
12893 goto need_larger_matrices
;
12897 /* Otherwise try_window_id has returned -1 which means that we
12898 don't want the alternative below this comment to execute. */
12900 else if (CHARPOS (startp
) >= BEGV
12901 && CHARPOS (startp
) <= ZV
12902 && PT
>= CHARPOS (startp
)
12903 && (CHARPOS (startp
) < ZV
12904 /* Avoid starting at end of buffer. */
12905 || CHARPOS (startp
) == BEGV
12906 || (XFASTINT (w
->last_modified
) >= MODIFF
12907 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12910 /* If first window line is a continuation line, and window start
12911 is inside the modified region, but the first change is before
12912 current window start, we must select a new window start.*/
12913 if (NILP (w
->start_at_line_beg
)
12914 && CHARPOS (startp
) > BEGV
)
12916 /* Make sure beg_unchanged and end_unchanged are up to date.
12917 Do it only if buffer has really changed. This may or may
12918 not have been done by try_window_id (see which) already. */
12919 if (MODIFF
> SAVE_MODIFF
12920 /* This seems to happen sometimes after saving a buffer. */
12921 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12923 if (GPT
- BEG
< BEG_UNCHANGED
)
12924 BEG_UNCHANGED
= GPT
- BEG
;
12925 if (Z
- GPT
< END_UNCHANGED
)
12926 END_UNCHANGED
= Z
- GPT
;
12929 if (CHARPOS (startp
) > BEG
+ BEG_UNCHANGED
12930 && CHARPOS (startp
) <= Z
- END_UNCHANGED
)
12932 /* There doesn't seems to be a simple way to find a new
12933 window start that is near the old window start, so
12934 we just recenter. */
12940 debug_method_add (w
, "same window start");
12943 /* Try to redisplay starting at same place as before.
12944 If point has not moved off frame, accept the results. */
12945 if (!current_matrix_up_to_date_p
12946 /* Don't use try_window_reusing_current_matrix in this case
12947 because a window scroll function can have changed the
12949 || !NILP (Vwindow_scroll_functions
)
12950 || MINI_WINDOW_P (w
)
12951 || !(used_current_matrix_p
12952 = try_window_reusing_current_matrix (w
)))
12954 IF_DEBUG (debug_method_add (w
, "1"));
12955 if (try_window (window
, startp
, 1) < 0)
12956 /* -1 means we need to scroll.
12957 0 means we need new matrices, but fonts_changed_p
12958 is set in that case, so we will detect it below. */
12959 goto try_to_scroll
;
12962 if (fonts_changed_p
)
12963 goto need_larger_matrices
;
12965 if (w
->cursor
.vpos
>= 0)
12967 if (!just_this_one_p
12968 || current_buffer
->clip_changed
12969 || BEG_UNCHANGED
< CHARPOS (startp
))
12970 /* Forget any recorded base line for line number display. */
12971 w
->base_line_number
= Qnil
;
12973 if (!cursor_row_fully_visible_p (w
, 1, 0))
12975 clear_glyph_matrix (w
->desired_matrix
);
12976 last_line_misfit
= 1;
12978 /* Drop through and scroll. */
12983 clear_glyph_matrix (w
->desired_matrix
);
12988 w
->last_modified
= make_number (0);
12989 w
->last_overlay_modified
= make_number (0);
12991 /* Redisplay the mode line. Select the buffer properly for that. */
12992 if (!update_mode_line
)
12994 update_mode_line
= 1;
12995 w
->update_mode_line
= Qt
;
12998 /* Try to scroll by specified few lines. */
12999 if ((scroll_conservatively
13001 || temp_scroll_step
13002 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13003 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13004 && !current_buffer
->clip_changed
13005 && CHARPOS (startp
) >= BEGV
13006 && CHARPOS (startp
) <= ZV
)
13008 /* The function returns -1 if new fonts were loaded, 1 if
13009 successful, 0 if not successful. */
13010 int rc
= try_scrolling (window
, just_this_one_p
,
13011 scroll_conservatively
,
13013 temp_scroll_step
, last_line_misfit
);
13016 case SCROLLING_SUCCESS
:
13019 case SCROLLING_NEED_LARGER_MATRICES
:
13020 goto need_larger_matrices
;
13022 case SCROLLING_FAILED
:
13030 /* Finally, just choose place to start which centers point */
13033 if (centering_position
< 0)
13034 centering_position
= window_box_height (w
) / 2;
13037 debug_method_add (w
, "recenter");
13040 /* w->vscroll = 0; */
13042 /* Forget any previously recorded base line for line number display. */
13043 if (!buffer_unchanged_p
)
13044 w
->base_line_number
= Qnil
;
13046 /* Move backward half the height of the window. */
13047 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13048 it
.current_y
= it
.last_visible_y
;
13049 move_it_vertically_backward (&it
, centering_position
);
13050 xassert (IT_CHARPOS (it
) >= BEGV
);
13052 /* The function move_it_vertically_backward may move over more
13053 than the specified y-distance. If it->w is small, e.g. a
13054 mini-buffer window, we may end up in front of the window's
13055 display area. Start displaying at the start of the line
13056 containing PT in this case. */
13057 if (it
.current_y
<= 0)
13059 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13060 move_it_vertically_backward (&it
, 0);
13062 /* I think this assert is bogus if buffer contains
13063 invisible text or images. KFS. */
13064 xassert (IT_CHARPOS (it
) <= PT
);
13069 it
.current_x
= it
.hpos
= 0;
13071 /* Set startp here explicitly in case that helps avoid an infinite loop
13072 in case the window-scroll-functions functions get errors. */
13073 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13075 /* Run scroll hooks. */
13076 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13078 /* Redisplay the window. */
13079 if (!current_matrix_up_to_date_p
13080 || windows_or_buffers_changed
13081 || cursor_type_changed
13082 /* Don't use try_window_reusing_current_matrix in this case
13083 because it can have changed the buffer. */
13084 || !NILP (Vwindow_scroll_functions
)
13085 || !just_this_one_p
13086 || MINI_WINDOW_P (w
)
13087 || !(used_current_matrix_p
13088 = try_window_reusing_current_matrix (w
)))
13089 try_window (window
, startp
, 0);
13091 /* If new fonts have been loaded (due to fontsets), give up. We
13092 have to start a new redisplay since we need to re-adjust glyph
13094 if (fonts_changed_p
)
13095 goto need_larger_matrices
;
13097 /* If cursor did not appear assume that the middle of the window is
13098 in the first line of the window. Do it again with the next line.
13099 (Imagine a window of height 100, displaying two lines of height
13100 60. Moving back 50 from it->last_visible_y will end in the first
13102 if (w
->cursor
.vpos
< 0)
13104 if (!NILP (w
->window_end_valid
)
13105 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13107 clear_glyph_matrix (w
->desired_matrix
);
13108 move_it_by_lines (&it
, 1, 0);
13109 try_window (window
, it
.current
.pos
, 0);
13111 else if (PT
< IT_CHARPOS (it
))
13113 clear_glyph_matrix (w
->desired_matrix
);
13114 move_it_by_lines (&it
, -1, 0);
13115 try_window (window
, it
.current
.pos
, 0);
13119 /* Not much we can do about it. */
13123 /* Consider the following case: Window starts at BEGV, there is
13124 invisible, intangible text at BEGV, so that display starts at
13125 some point START > BEGV. It can happen that we are called with
13126 PT somewhere between BEGV and START. Try to handle that case. */
13127 if (w
->cursor
.vpos
< 0)
13129 struct glyph_row
*row
= w
->current_matrix
->rows
;
13130 if (row
->mode_line_p
)
13132 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13135 if (!cursor_row_fully_visible_p (w
, 0, 0))
13137 /* If vscroll is enabled, disable it and try again. */
13141 clear_glyph_matrix (w
->desired_matrix
);
13145 /* If centering point failed to make the whole line visible,
13146 put point at the top instead. That has to make the whole line
13147 visible, if it can be done. */
13148 if (centering_position
== 0)
13151 clear_glyph_matrix (w
->desired_matrix
);
13152 centering_position
= 0;
13158 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13159 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13160 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13163 /* Display the mode line, if we must. */
13164 if ((update_mode_line
13165 /* If window not full width, must redo its mode line
13166 if (a) the window to its side is being redone and
13167 (b) we do a frame-based redisplay. This is a consequence
13168 of how inverted lines are drawn in frame-based redisplay. */
13169 || (!just_this_one_p
13170 && !FRAME_WINDOW_P (f
)
13171 && !WINDOW_FULL_WIDTH_P (w
))
13172 /* Line number to display. */
13173 || INTEGERP (w
->base_line_pos
)
13174 /* Column number is displayed and different from the one displayed. */
13175 || (!NILP (w
->column_number_displayed
)
13176 && (XFASTINT (w
->column_number_displayed
)
13177 != (int) current_column ()))) /* iftc */
13178 /* This means that the window has a mode line. */
13179 && (WINDOW_WANTS_MODELINE_P (w
)
13180 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13182 display_mode_lines (w
);
13184 /* If mode line height has changed, arrange for a thorough
13185 immediate redisplay using the correct mode line height. */
13186 if (WINDOW_WANTS_MODELINE_P (w
)
13187 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13189 fonts_changed_p
= 1;
13190 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13191 = DESIRED_MODE_LINE_HEIGHT (w
);
13194 /* If top line height has changed, arrange for a thorough
13195 immediate redisplay using the correct mode line height. */
13196 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13197 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13199 fonts_changed_p
= 1;
13200 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13201 = DESIRED_HEADER_LINE_HEIGHT (w
);
13204 if (fonts_changed_p
)
13205 goto need_larger_matrices
;
13208 if (!line_number_displayed
13209 && !BUFFERP (w
->base_line_pos
))
13211 w
->base_line_pos
= Qnil
;
13212 w
->base_line_number
= Qnil
;
13217 /* When we reach a frame's selected window, redo the frame's menu bar. */
13218 if (update_mode_line
13219 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13221 int redisplay_menu_p
= 0;
13222 int redisplay_tool_bar_p
= 0;
13224 if (FRAME_WINDOW_P (f
))
13226 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13227 || defined (USE_GTK)
13228 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13230 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13234 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13236 if (redisplay_menu_p
)
13237 display_menu_bar (w
);
13239 #ifdef HAVE_WINDOW_SYSTEM
13241 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13243 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13244 && (FRAME_TOOL_BAR_LINES (f
) > 0
13245 || auto_resize_tool_bars_p
);
13249 if (redisplay_tool_bar_p
)
13250 redisplay_tool_bar (f
);
13254 #ifdef HAVE_WINDOW_SYSTEM
13255 if (FRAME_WINDOW_P (f
)
13256 && update_window_fringes (w
, (just_this_one_p
13257 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13258 || w
->pseudo_window_p
)))
13262 if (draw_window_fringes (w
, 1))
13263 x_draw_vertical_border (w
);
13267 #endif /* HAVE_WINDOW_SYSTEM */
13269 /* We go to this label, with fonts_changed_p nonzero,
13270 if it is necessary to try again using larger glyph matrices.
13271 We have to redeem the scroll bar even in this case,
13272 because the loop in redisplay_internal expects that. */
13273 need_larger_matrices
:
13275 finish_scroll_bars
:
13277 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13279 /* Set the thumb's position and size. */
13280 set_vertical_scroll_bar (w
);
13282 /* Note that we actually used the scroll bar attached to this
13283 window, so it shouldn't be deleted at the end of redisplay. */
13284 redeem_scroll_bar_hook (w
);
13287 /* Restore current_buffer and value of point in it. */
13288 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13289 set_buffer_internal_1 (old
);
13290 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13292 unbind_to (count
, Qnil
);
13296 /* Build the complete desired matrix of WINDOW with a window start
13297 buffer position POS.
13299 Value is 1 if successful. It is zero if fonts were loaded during
13300 redisplay which makes re-adjusting glyph matrices necessary, and -1
13301 if point would appear in the scroll margins.
13302 (We check that only if CHECK_MARGINS is nonzero. */
13305 try_window (window
, pos
, check_margins
)
13306 Lisp_Object window
;
13307 struct text_pos pos
;
13310 struct window
*w
= XWINDOW (window
);
13312 struct glyph_row
*last_text_row
= NULL
;
13314 /* Make POS the new window start. */
13315 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13317 /* Mark cursor position as unknown. No overlay arrow seen. */
13318 w
->cursor
.vpos
= -1;
13319 overlay_arrow_seen
= 0;
13321 /* Initialize iterator and info to start at POS. */
13322 start_display (&it
, w
, pos
);
13324 /* Display all lines of W. */
13325 while (it
.current_y
< it
.last_visible_y
)
13327 if (display_line (&it
))
13328 last_text_row
= it
.glyph_row
- 1;
13329 if (fonts_changed_p
)
13333 /* Don't let the cursor end in the scroll margins. */
13335 && !MINI_WINDOW_P (w
))
13337 int this_scroll_margin
;
13339 this_scroll_margin
= max (0, scroll_margin
);
13340 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13341 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13343 if ((w
->cursor
.y
< this_scroll_margin
13344 && CHARPOS (pos
) > BEGV
13345 && IT_CHARPOS (it
) < ZV
)
13346 /* rms: considering make_cursor_line_fully_visible_p here
13347 seems to give wrong results. We don't want to recenter
13348 when the last line is partly visible, we want to allow
13349 that case to be handled in the usual way. */
13350 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13352 w
->cursor
.vpos
= -1;
13353 clear_glyph_matrix (w
->desired_matrix
);
13358 /* If bottom moved off end of frame, change mode line percentage. */
13359 if (XFASTINT (w
->window_end_pos
) <= 0
13360 && Z
!= IT_CHARPOS (it
))
13361 w
->update_mode_line
= Qt
;
13363 /* Set window_end_pos to the offset of the last character displayed
13364 on the window from the end of current_buffer. Set
13365 window_end_vpos to its row number. */
13368 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13369 w
->window_end_bytepos
13370 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13372 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13374 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13375 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13376 ->displays_text_p
);
13380 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13381 w
->window_end_pos
= make_number (Z
- ZV
);
13382 w
->window_end_vpos
= make_number (0);
13385 /* But that is not valid info until redisplay finishes. */
13386 w
->window_end_valid
= Qnil
;
13392 /************************************************************************
13393 Window redisplay reusing current matrix when buffer has not changed
13394 ************************************************************************/
13396 /* Try redisplay of window W showing an unchanged buffer with a
13397 different window start than the last time it was displayed by
13398 reusing its current matrix. Value is non-zero if successful.
13399 W->start is the new window start. */
13402 try_window_reusing_current_matrix (w
)
13405 struct frame
*f
= XFRAME (w
->frame
);
13406 struct glyph_row
*row
, *bottom_row
;
13409 struct text_pos start
, new_start
;
13410 int nrows_scrolled
, i
;
13411 struct glyph_row
*last_text_row
;
13412 struct glyph_row
*last_reused_text_row
;
13413 struct glyph_row
*start_row
;
13414 int start_vpos
, min_y
, max_y
;
13417 if (inhibit_try_window_reusing
)
13421 if (/* This function doesn't handle terminal frames. */
13422 !FRAME_WINDOW_P (f
)
13423 /* Don't try to reuse the display if windows have been split
13425 || windows_or_buffers_changed
13426 || cursor_type_changed
)
13429 /* Can't do this if region may have changed. */
13430 if ((!NILP (Vtransient_mark_mode
)
13431 && !NILP (current_buffer
->mark_active
))
13432 || !NILP (w
->region_showing
)
13433 || !NILP (Vshow_trailing_whitespace
))
13436 /* If top-line visibility has changed, give up. */
13437 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13438 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13441 /* Give up if old or new display is scrolled vertically. We could
13442 make this function handle this, but right now it doesn't. */
13443 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13444 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13447 /* The variable new_start now holds the new window start. The old
13448 start `start' can be determined from the current matrix. */
13449 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13450 start
= start_row
->start
.pos
;
13451 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13453 /* Clear the desired matrix for the display below. */
13454 clear_glyph_matrix (w
->desired_matrix
);
13456 if (CHARPOS (new_start
) <= CHARPOS (start
))
13460 /* Don't use this method if the display starts with an ellipsis
13461 displayed for invisible text. It's not easy to handle that case
13462 below, and it's certainly not worth the effort since this is
13463 not a frequent case. */
13464 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13467 IF_DEBUG (debug_method_add (w
, "twu1"));
13469 /* Display up to a row that can be reused. The variable
13470 last_text_row is set to the last row displayed that displays
13471 text. Note that it.vpos == 0 if or if not there is a
13472 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13473 start_display (&it
, w
, new_start
);
13474 first_row_y
= it
.current_y
;
13475 w
->cursor
.vpos
= -1;
13476 last_text_row
= last_reused_text_row
= NULL
;
13478 while (it
.current_y
< it
.last_visible_y
13479 && !fonts_changed_p
)
13481 /* If we have reached into the characters in the START row,
13482 that means the line boundaries have changed. So we
13483 can't start copying with the row START. Maybe it will
13484 work to start copying with the following row. */
13485 while (IT_CHARPOS (it
) > CHARPOS (start
))
13487 /* Advance to the next row as the "start". */
13489 start
= start_row
->start
.pos
;
13490 /* If there are no more rows to try, or just one, give up. */
13491 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13492 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13493 || CHARPOS (start
) == ZV
)
13495 clear_glyph_matrix (w
->desired_matrix
);
13499 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13501 /* If we have reached alignment,
13502 we can copy the rest of the rows. */
13503 if (IT_CHARPOS (it
) == CHARPOS (start
))
13506 if (display_line (&it
))
13507 last_text_row
= it
.glyph_row
- 1;
13510 /* A value of current_y < last_visible_y means that we stopped
13511 at the previous window start, which in turn means that we
13512 have at least one reusable row. */
13513 if (it
.current_y
< it
.last_visible_y
)
13515 /* IT.vpos always starts from 0; it counts text lines. */
13516 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13518 /* Find PT if not already found in the lines displayed. */
13519 if (w
->cursor
.vpos
< 0)
13521 int dy
= it
.current_y
- start_row
->y
;
13523 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13524 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13526 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13527 dy
, nrows_scrolled
);
13530 clear_glyph_matrix (w
->desired_matrix
);
13535 /* Scroll the display. Do it before the current matrix is
13536 changed. The problem here is that update has not yet
13537 run, i.e. part of the current matrix is not up to date.
13538 scroll_run_hook will clear the cursor, and use the
13539 current matrix to get the height of the row the cursor is
13541 run
.current_y
= start_row
->y
;
13542 run
.desired_y
= it
.current_y
;
13543 run
.height
= it
.last_visible_y
- it
.current_y
;
13545 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13548 rif
->update_window_begin_hook (w
);
13549 rif
->clear_window_mouse_face (w
);
13550 rif
->scroll_run_hook (w
, &run
);
13551 rif
->update_window_end_hook (w
, 0, 0);
13555 /* Shift current matrix down by nrows_scrolled lines. */
13556 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13557 rotate_matrix (w
->current_matrix
,
13559 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13562 /* Disable lines that must be updated. */
13563 for (i
= 0; i
< it
.vpos
; ++i
)
13564 (start_row
+ i
)->enabled_p
= 0;
13566 /* Re-compute Y positions. */
13567 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13568 max_y
= it
.last_visible_y
;
13569 for (row
= start_row
+ nrows_scrolled
;
13573 row
->y
= it
.current_y
;
13574 row
->visible_height
= row
->height
;
13576 if (row
->y
< min_y
)
13577 row
->visible_height
-= min_y
- row
->y
;
13578 if (row
->y
+ row
->height
> max_y
)
13579 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13580 row
->redraw_fringe_bitmaps_p
= 1;
13582 it
.current_y
+= row
->height
;
13584 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13585 last_reused_text_row
= row
;
13586 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13590 /* Disable lines in the current matrix which are now
13591 below the window. */
13592 for (++row
; row
< bottom_row
; ++row
)
13593 row
->enabled_p
= row
->mode_line_p
= 0;
13596 /* Update window_end_pos etc.; last_reused_text_row is the last
13597 reused row from the current matrix containing text, if any.
13598 The value of last_text_row is the last displayed line
13599 containing text. */
13600 if (last_reused_text_row
)
13602 w
->window_end_bytepos
13603 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13605 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13607 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13608 w
->current_matrix
));
13610 else if (last_text_row
)
13612 w
->window_end_bytepos
13613 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13615 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13617 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13621 /* This window must be completely empty. */
13622 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13623 w
->window_end_pos
= make_number (Z
- ZV
);
13624 w
->window_end_vpos
= make_number (0);
13626 w
->window_end_valid
= Qnil
;
13628 /* Update hint: don't try scrolling again in update_window. */
13629 w
->desired_matrix
->no_scrolling_p
= 1;
13632 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13636 else if (CHARPOS (new_start
) > CHARPOS (start
))
13638 struct glyph_row
*pt_row
, *row
;
13639 struct glyph_row
*first_reusable_row
;
13640 struct glyph_row
*first_row_to_display
;
13642 int yb
= window_text_bottom_y (w
);
13644 /* Find the row starting at new_start, if there is one. Don't
13645 reuse a partially visible line at the end. */
13646 first_reusable_row
= start_row
;
13647 while (first_reusable_row
->enabled_p
13648 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13649 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13650 < CHARPOS (new_start
)))
13651 ++first_reusable_row
;
13653 /* Give up if there is no row to reuse. */
13654 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13655 || !first_reusable_row
->enabled_p
13656 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13657 != CHARPOS (new_start
)))
13660 /* We can reuse fully visible rows beginning with
13661 first_reusable_row to the end of the window. Set
13662 first_row_to_display to the first row that cannot be reused.
13663 Set pt_row to the row containing point, if there is any. */
13665 for (first_row_to_display
= first_reusable_row
;
13666 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13667 ++first_row_to_display
)
13669 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13670 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13671 pt_row
= first_row_to_display
;
13674 /* Start displaying at the start of first_row_to_display. */
13675 xassert (first_row_to_display
->y
< yb
);
13676 init_to_row_start (&it
, w
, first_row_to_display
);
13678 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13680 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13682 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13683 + WINDOW_HEADER_LINE_HEIGHT (w
));
13685 /* Display lines beginning with first_row_to_display in the
13686 desired matrix. Set last_text_row to the last row displayed
13687 that displays text. */
13688 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13689 if (pt_row
== NULL
)
13690 w
->cursor
.vpos
= -1;
13691 last_text_row
= NULL
;
13692 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13693 if (display_line (&it
))
13694 last_text_row
= it
.glyph_row
- 1;
13696 /* Give up If point isn't in a row displayed or reused. */
13697 if (w
->cursor
.vpos
< 0)
13699 clear_glyph_matrix (w
->desired_matrix
);
13703 /* If point is in a reused row, adjust y and vpos of the cursor
13707 w
->cursor
.vpos
-= nrows_scrolled
;
13708 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13711 /* Scroll the display. */
13712 run
.current_y
= first_reusable_row
->y
;
13713 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13714 run
.height
= it
.last_visible_y
- run
.current_y
;
13715 dy
= run
.current_y
- run
.desired_y
;
13720 rif
->update_window_begin_hook (w
);
13721 rif
->clear_window_mouse_face (w
);
13722 rif
->scroll_run_hook (w
, &run
);
13723 rif
->update_window_end_hook (w
, 0, 0);
13727 /* Adjust Y positions of reused rows. */
13728 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13729 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13730 max_y
= it
.last_visible_y
;
13731 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13734 row
->visible_height
= row
->height
;
13735 if (row
->y
< min_y
)
13736 row
->visible_height
-= min_y
- row
->y
;
13737 if (row
->y
+ row
->height
> max_y
)
13738 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13739 row
->redraw_fringe_bitmaps_p
= 1;
13742 /* Scroll the current matrix. */
13743 xassert (nrows_scrolled
> 0);
13744 rotate_matrix (w
->current_matrix
,
13746 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13749 /* Disable rows not reused. */
13750 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13751 row
->enabled_p
= 0;
13753 /* Point may have moved to a different line, so we cannot assume that
13754 the previous cursor position is valid; locate the correct row. */
13757 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13758 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13762 w
->cursor
.y
= row
->y
;
13764 if (row
< bottom_row
)
13766 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13767 while (glyph
->charpos
< PT
)
13770 w
->cursor
.x
+= glyph
->pixel_width
;
13776 /* Adjust window end. A null value of last_text_row means that
13777 the window end is in reused rows which in turn means that
13778 only its vpos can have changed. */
13781 w
->window_end_bytepos
13782 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13784 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13786 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13791 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13794 w
->window_end_valid
= Qnil
;
13795 w
->desired_matrix
->no_scrolling_p
= 1;
13798 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13808 /************************************************************************
13809 Window redisplay reusing current matrix when buffer has changed
13810 ************************************************************************/
13812 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13813 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13815 static struct glyph_row
*
13816 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13817 struct glyph_row
*));
13820 /* Return the last row in MATRIX displaying text. If row START is
13821 non-null, start searching with that row. IT gives the dimensions
13822 of the display. Value is null if matrix is empty; otherwise it is
13823 a pointer to the row found. */
13825 static struct glyph_row
*
13826 find_last_row_displaying_text (matrix
, it
, start
)
13827 struct glyph_matrix
*matrix
;
13829 struct glyph_row
*start
;
13831 struct glyph_row
*row
, *row_found
;
13833 /* Set row_found to the last row in IT->w's current matrix
13834 displaying text. The loop looks funny but think of partially
13837 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13838 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13840 xassert (row
->enabled_p
);
13842 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13851 /* Return the last row in the current matrix of W that is not affected
13852 by changes at the start of current_buffer that occurred since W's
13853 current matrix was built. Value is null if no such row exists.
13855 BEG_UNCHANGED us the number of characters unchanged at the start of
13856 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13857 first changed character in current_buffer. Characters at positions <
13858 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13859 when the current matrix was built. */
13861 static struct glyph_row
*
13862 find_last_unchanged_at_beg_row (w
)
13865 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13866 struct glyph_row
*row
;
13867 struct glyph_row
*row_found
= NULL
;
13868 int yb
= window_text_bottom_y (w
);
13870 /* Find the last row displaying unchanged text. */
13871 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13872 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13873 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13875 if (/* If row ends before first_changed_pos, it is unchanged,
13876 except in some case. */
13877 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13878 /* When row ends in ZV and we write at ZV it is not
13880 && !row
->ends_at_zv_p
13881 /* When first_changed_pos is the end of a continued line,
13882 row is not unchanged because it may be no longer
13884 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13885 && (row
->continued_p
13886 || row
->exact_window_width_line_p
)))
13889 /* Stop if last visible row. */
13890 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13900 /* Find the first glyph row in the current matrix of W that is not
13901 affected by changes at the end of current_buffer since the
13902 time W's current matrix was built.
13904 Return in *DELTA the number of chars by which buffer positions in
13905 unchanged text at the end of current_buffer must be adjusted.
13907 Return in *DELTA_BYTES the corresponding number of bytes.
13909 Value is null if no such row exists, i.e. all rows are affected by
13912 static struct glyph_row
*
13913 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13915 int *delta
, *delta_bytes
;
13917 struct glyph_row
*row
;
13918 struct glyph_row
*row_found
= NULL
;
13920 *delta
= *delta_bytes
= 0;
13922 /* Display must not have been paused, otherwise the current matrix
13923 is not up to date. */
13924 if (NILP (w
->window_end_valid
))
13927 /* A value of window_end_pos >= END_UNCHANGED means that the window
13928 end is in the range of changed text. If so, there is no
13929 unchanged row at the end of W's current matrix. */
13930 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13933 /* Set row to the last row in W's current matrix displaying text. */
13934 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13936 /* If matrix is entirely empty, no unchanged row exists. */
13937 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13939 /* The value of row is the last glyph row in the matrix having a
13940 meaningful buffer position in it. The end position of row
13941 corresponds to window_end_pos. This allows us to translate
13942 buffer positions in the current matrix to current buffer
13943 positions for characters not in changed text. */
13944 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13945 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13946 int last_unchanged_pos
, last_unchanged_pos_old
;
13947 struct glyph_row
*first_text_row
13948 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13950 *delta
= Z
- Z_old
;
13951 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13953 /* Set last_unchanged_pos to the buffer position of the last
13954 character in the buffer that has not been changed. Z is the
13955 index + 1 of the last character in current_buffer, i.e. by
13956 subtracting END_UNCHANGED we get the index of the last
13957 unchanged character, and we have to add BEG to get its buffer
13959 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13960 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13962 /* Search backward from ROW for a row displaying a line that
13963 starts at a minimum position >= last_unchanged_pos_old. */
13964 for (; row
> first_text_row
; --row
)
13966 /* This used to abort, but it can happen.
13967 It is ok to just stop the search instead here. KFS. */
13968 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13971 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13976 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13983 /* Make sure that glyph rows in the current matrix of window W
13984 reference the same glyph memory as corresponding rows in the
13985 frame's frame matrix. This function is called after scrolling W's
13986 current matrix on a terminal frame in try_window_id and
13987 try_window_reusing_current_matrix. */
13990 sync_frame_with_window_matrix_rows (w
)
13993 struct frame
*f
= XFRAME (w
->frame
);
13994 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13996 /* Preconditions: W must be a leaf window and full-width. Its frame
13997 must have a frame matrix. */
13998 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13999 xassert (WINDOW_FULL_WIDTH_P (w
));
14000 xassert (!FRAME_WINDOW_P (f
));
14002 /* If W is a full-width window, glyph pointers in W's current matrix
14003 have, by definition, to be the same as glyph pointers in the
14004 corresponding frame matrix. Note that frame matrices have no
14005 marginal areas (see build_frame_matrix). */
14006 window_row
= w
->current_matrix
->rows
;
14007 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14008 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14009 while (window_row
< window_row_end
)
14011 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14012 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14014 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14015 frame_row
->glyphs
[TEXT_AREA
] = start
;
14016 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14017 frame_row
->glyphs
[LAST_AREA
] = end
;
14019 /* Disable frame rows whose corresponding window rows have
14020 been disabled in try_window_id. */
14021 if (!window_row
->enabled_p
)
14022 frame_row
->enabled_p
= 0;
14024 ++window_row
, ++frame_row
;
14029 /* Find the glyph row in window W containing CHARPOS. Consider all
14030 rows between START and END (not inclusive). END null means search
14031 all rows to the end of the display area of W. Value is the row
14032 containing CHARPOS or null. */
14035 row_containing_pos (w
, charpos
, start
, end
, dy
)
14038 struct glyph_row
*start
, *end
;
14041 struct glyph_row
*row
= start
;
14044 /* If we happen to start on a header-line, skip that. */
14045 if (row
->mode_line_p
)
14048 if ((end
&& row
>= end
) || !row
->enabled_p
)
14051 last_y
= window_text_bottom_y (w
) - dy
;
14055 /* Give up if we have gone too far. */
14056 if (end
&& row
>= end
)
14058 /* This formerly returned if they were equal.
14059 I think that both quantities are of a "last plus one" type;
14060 if so, when they are equal, the row is within the screen. -- rms. */
14061 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14064 /* If it is in this row, return this row. */
14065 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14066 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14067 /* The end position of a row equals the start
14068 position of the next row. If CHARPOS is there, we
14069 would rather display it in the next line, except
14070 when this line ends in ZV. */
14071 && !row
->ends_at_zv_p
14072 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14073 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14080 /* Try to redisplay window W by reusing its existing display. W's
14081 current matrix must be up to date when this function is called,
14082 i.e. window_end_valid must not be nil.
14086 1 if display has been updated
14087 0 if otherwise unsuccessful
14088 -1 if redisplay with same window start is known not to succeed
14090 The following steps are performed:
14092 1. Find the last row in the current matrix of W that is not
14093 affected by changes at the start of current_buffer. If no such row
14096 2. Find the first row in W's current matrix that is not affected by
14097 changes at the end of current_buffer. Maybe there is no such row.
14099 3. Display lines beginning with the row + 1 found in step 1 to the
14100 row found in step 2 or, if step 2 didn't find a row, to the end of
14103 4. If cursor is not known to appear on the window, give up.
14105 5. If display stopped at the row found in step 2, scroll the
14106 display and current matrix as needed.
14108 6. Maybe display some lines at the end of W, if we must. This can
14109 happen under various circumstances, like a partially visible line
14110 becoming fully visible, or because newly displayed lines are displayed
14111 in smaller font sizes.
14113 7. Update W's window end information. */
14119 struct frame
*f
= XFRAME (w
->frame
);
14120 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14121 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14122 struct glyph_row
*last_unchanged_at_beg_row
;
14123 struct glyph_row
*first_unchanged_at_end_row
;
14124 struct glyph_row
*row
;
14125 struct glyph_row
*bottom_row
;
14128 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14129 struct text_pos start_pos
;
14131 int first_unchanged_at_end_vpos
= 0;
14132 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14133 struct text_pos start
;
14134 int first_changed_charpos
, last_changed_charpos
;
14137 if (inhibit_try_window_id
)
14141 /* This is handy for debugging. */
14143 #define GIVE_UP(X) \
14145 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14149 #define GIVE_UP(X) return 0
14152 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14154 /* Don't use this for mini-windows because these can show
14155 messages and mini-buffers, and we don't handle that here. */
14156 if (MINI_WINDOW_P (w
))
14159 /* This flag is used to prevent redisplay optimizations. */
14160 if (windows_or_buffers_changed
|| cursor_type_changed
)
14163 /* Verify that narrowing has not changed.
14164 Also verify that we were not told to prevent redisplay optimizations.
14165 It would be nice to further
14166 reduce the number of cases where this prevents try_window_id. */
14167 if (current_buffer
->clip_changed
14168 || current_buffer
->prevent_redisplay_optimizations_p
)
14171 /* Window must either use window-based redisplay or be full width. */
14172 if (!FRAME_WINDOW_P (f
)
14173 && (!line_ins_del_ok
14174 || !WINDOW_FULL_WIDTH_P (w
)))
14177 /* Give up if point is not known NOT to appear in W. */
14178 if (PT
< CHARPOS (start
))
14181 /* Another way to prevent redisplay optimizations. */
14182 if (XFASTINT (w
->last_modified
) == 0)
14185 /* Verify that window is not hscrolled. */
14186 if (XFASTINT (w
->hscroll
) != 0)
14189 /* Verify that display wasn't paused. */
14190 if (NILP (w
->window_end_valid
))
14193 /* Can't use this if highlighting a region because a cursor movement
14194 will do more than just set the cursor. */
14195 if (!NILP (Vtransient_mark_mode
)
14196 && !NILP (current_buffer
->mark_active
))
14199 /* Likewise if highlighting trailing whitespace. */
14200 if (!NILP (Vshow_trailing_whitespace
))
14203 /* Likewise if showing a region. */
14204 if (!NILP (w
->region_showing
))
14207 /* Can use this if overlay arrow position and or string have changed. */
14208 if (overlay_arrows_changed_p ())
14212 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14213 only if buffer has really changed. The reason is that the gap is
14214 initially at Z for freshly visited files. The code below would
14215 set end_unchanged to 0 in that case. */
14216 if (MODIFF
> SAVE_MODIFF
14217 /* This seems to happen sometimes after saving a buffer. */
14218 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14220 if (GPT
- BEG
< BEG_UNCHANGED
)
14221 BEG_UNCHANGED
= GPT
- BEG
;
14222 if (Z
- GPT
< END_UNCHANGED
)
14223 END_UNCHANGED
= Z
- GPT
;
14226 /* The position of the first and last character that has been changed. */
14227 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14228 last_changed_charpos
= Z
- END_UNCHANGED
;
14230 /* If window starts after a line end, and the last change is in
14231 front of that newline, then changes don't affect the display.
14232 This case happens with stealth-fontification. Note that although
14233 the display is unchanged, glyph positions in the matrix have to
14234 be adjusted, of course. */
14235 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14236 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14237 && ((last_changed_charpos
< CHARPOS (start
)
14238 && CHARPOS (start
) == BEGV
)
14239 || (last_changed_charpos
< CHARPOS (start
) - 1
14240 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14242 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14243 struct glyph_row
*r0
;
14245 /* Compute how many chars/bytes have been added to or removed
14246 from the buffer. */
14247 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14248 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14250 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14252 /* Give up if PT is not in the window. Note that it already has
14253 been checked at the start of try_window_id that PT is not in
14254 front of the window start. */
14255 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14258 /* If window start is unchanged, we can reuse the whole matrix
14259 as is, after adjusting glyph positions. No need to compute
14260 the window end again, since its offset from Z hasn't changed. */
14261 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14262 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14263 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14264 /* PT must not be in a partially visible line. */
14265 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14266 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14268 /* Adjust positions in the glyph matrix. */
14269 if (delta
|| delta_bytes
)
14271 struct glyph_row
*r1
14272 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14273 increment_matrix_positions (w
->current_matrix
,
14274 MATRIX_ROW_VPOS (r0
, current_matrix
),
14275 MATRIX_ROW_VPOS (r1
, current_matrix
),
14276 delta
, delta_bytes
);
14279 /* Set the cursor. */
14280 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14282 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14289 /* Handle the case that changes are all below what is displayed in
14290 the window, and that PT is in the window. This shortcut cannot
14291 be taken if ZV is visible in the window, and text has been added
14292 there that is visible in the window. */
14293 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14294 /* ZV is not visible in the window, or there are no
14295 changes at ZV, actually. */
14296 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14297 || first_changed_charpos
== last_changed_charpos
))
14299 struct glyph_row
*r0
;
14301 /* Give up if PT is not in the window. Note that it already has
14302 been checked at the start of try_window_id that PT is not in
14303 front of the window start. */
14304 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14307 /* If window start is unchanged, we can reuse the whole matrix
14308 as is, without changing glyph positions since no text has
14309 been added/removed in front of the window end. */
14310 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14311 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14312 /* PT must not be in a partially visible line. */
14313 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14314 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14316 /* We have to compute the window end anew since text
14317 can have been added/removed after it. */
14319 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14320 w
->window_end_bytepos
14321 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14323 /* Set the cursor. */
14324 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14326 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14333 /* Give up if window start is in the changed area.
14335 The condition used to read
14337 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14339 but why that was tested escapes me at the moment. */
14340 if (CHARPOS (start
) >= first_changed_charpos
14341 && CHARPOS (start
) <= last_changed_charpos
)
14344 /* Check that window start agrees with the start of the first glyph
14345 row in its current matrix. Check this after we know the window
14346 start is not in changed text, otherwise positions would not be
14348 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14349 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14352 /* Give up if the window ends in strings. Overlay strings
14353 at the end are difficult to handle, so don't try. */
14354 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14355 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14358 /* Compute the position at which we have to start displaying new
14359 lines. Some of the lines at the top of the window might be
14360 reusable because they are not displaying changed text. Find the
14361 last row in W's current matrix not affected by changes at the
14362 start of current_buffer. Value is null if changes start in the
14363 first line of window. */
14364 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14365 if (last_unchanged_at_beg_row
)
14367 /* Avoid starting to display in the moddle of a character, a TAB
14368 for instance. This is easier than to set up the iterator
14369 exactly, and it's not a frequent case, so the additional
14370 effort wouldn't really pay off. */
14371 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14372 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14373 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14374 --last_unchanged_at_beg_row
;
14376 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14379 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14381 start_pos
= it
.current
.pos
;
14383 /* Start displaying new lines in the desired matrix at the same
14384 vpos we would use in the current matrix, i.e. below
14385 last_unchanged_at_beg_row. */
14386 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14388 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14389 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14391 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14395 /* There are no reusable lines at the start of the window.
14396 Start displaying in the first text line. */
14397 start_display (&it
, w
, start
);
14398 it
.vpos
= it
.first_vpos
;
14399 start_pos
= it
.current
.pos
;
14402 /* Find the first row that is not affected by changes at the end of
14403 the buffer. Value will be null if there is no unchanged row, in
14404 which case we must redisplay to the end of the window. delta
14405 will be set to the value by which buffer positions beginning with
14406 first_unchanged_at_end_row have to be adjusted due to text
14408 first_unchanged_at_end_row
14409 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14410 IF_DEBUG (debug_delta
= delta
);
14411 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14413 /* Set stop_pos to the buffer position up to which we will have to
14414 display new lines. If first_unchanged_at_end_row != NULL, this
14415 is the buffer position of the start of the line displayed in that
14416 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14417 that we don't stop at a buffer position. */
14419 if (first_unchanged_at_end_row
)
14421 xassert (last_unchanged_at_beg_row
== NULL
14422 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14424 /* If this is a continuation line, move forward to the next one
14425 that isn't. Changes in lines above affect this line.
14426 Caution: this may move first_unchanged_at_end_row to a row
14427 not displaying text. */
14428 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14429 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14430 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14431 < it
.last_visible_y
))
14432 ++first_unchanged_at_end_row
;
14434 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14435 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14436 >= it
.last_visible_y
))
14437 first_unchanged_at_end_row
= NULL
;
14440 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14442 first_unchanged_at_end_vpos
14443 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14444 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14447 else if (last_unchanged_at_beg_row
== NULL
)
14453 /* Either there is no unchanged row at the end, or the one we have
14454 now displays text. This is a necessary condition for the window
14455 end pos calculation at the end of this function. */
14456 xassert (first_unchanged_at_end_row
== NULL
14457 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14459 debug_last_unchanged_at_beg_vpos
14460 = (last_unchanged_at_beg_row
14461 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14463 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14465 #endif /* GLYPH_DEBUG != 0 */
14468 /* Display new lines. Set last_text_row to the last new line
14469 displayed which has text on it, i.e. might end up as being the
14470 line where the window_end_vpos is. */
14471 w
->cursor
.vpos
= -1;
14472 last_text_row
= NULL
;
14473 overlay_arrow_seen
= 0;
14474 while (it
.current_y
< it
.last_visible_y
14475 && !fonts_changed_p
14476 && (first_unchanged_at_end_row
== NULL
14477 || IT_CHARPOS (it
) < stop_pos
))
14479 if (display_line (&it
))
14480 last_text_row
= it
.glyph_row
- 1;
14483 if (fonts_changed_p
)
14487 /* Compute differences in buffer positions, y-positions etc. for
14488 lines reused at the bottom of the window. Compute what we can
14490 if (first_unchanged_at_end_row
14491 /* No lines reused because we displayed everything up to the
14492 bottom of the window. */
14493 && it
.current_y
< it
.last_visible_y
)
14496 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14498 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14499 run
.current_y
= first_unchanged_at_end_row
->y
;
14500 run
.desired_y
= run
.current_y
+ dy
;
14501 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14505 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14506 first_unchanged_at_end_row
= NULL
;
14508 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14511 /* Find the cursor if not already found. We have to decide whether
14512 PT will appear on this window (it sometimes doesn't, but this is
14513 not a very frequent case.) This decision has to be made before
14514 the current matrix is altered. A value of cursor.vpos < 0 means
14515 that PT is either in one of the lines beginning at
14516 first_unchanged_at_end_row or below the window. Don't care for
14517 lines that might be displayed later at the window end; as
14518 mentioned, this is not a frequent case. */
14519 if (w
->cursor
.vpos
< 0)
14521 /* Cursor in unchanged rows at the top? */
14522 if (PT
< CHARPOS (start_pos
)
14523 && last_unchanged_at_beg_row
)
14525 row
= row_containing_pos (w
, PT
,
14526 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14527 last_unchanged_at_beg_row
+ 1, 0);
14529 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14532 /* Start from first_unchanged_at_end_row looking for PT. */
14533 else if (first_unchanged_at_end_row
)
14535 row
= row_containing_pos (w
, PT
- delta
,
14536 first_unchanged_at_end_row
, NULL
, 0);
14538 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14539 delta_bytes
, dy
, dvpos
);
14542 /* Give up if cursor was not found. */
14543 if (w
->cursor
.vpos
< 0)
14545 clear_glyph_matrix (w
->desired_matrix
);
14550 /* Don't let the cursor end in the scroll margins. */
14552 int this_scroll_margin
, cursor_height
;
14554 this_scroll_margin
= max (0, scroll_margin
);
14555 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14556 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14557 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14559 if ((w
->cursor
.y
< this_scroll_margin
14560 && CHARPOS (start
) > BEGV
)
14561 /* Old redisplay didn't take scroll margin into account at the bottom,
14562 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14563 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14564 ? cursor_height
+ this_scroll_margin
14565 : 1)) > it
.last_visible_y
)
14567 w
->cursor
.vpos
= -1;
14568 clear_glyph_matrix (w
->desired_matrix
);
14573 /* Scroll the display. Do it before changing the current matrix so
14574 that xterm.c doesn't get confused about where the cursor glyph is
14576 if (dy
&& run
.height
)
14580 if (FRAME_WINDOW_P (f
))
14582 rif
->update_window_begin_hook (w
);
14583 rif
->clear_window_mouse_face (w
);
14584 rif
->scroll_run_hook (w
, &run
);
14585 rif
->update_window_end_hook (w
, 0, 0);
14589 /* Terminal frame. In this case, dvpos gives the number of
14590 lines to scroll by; dvpos < 0 means scroll up. */
14591 int first_unchanged_at_end_vpos
14592 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14593 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14594 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14595 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14596 + window_internal_height (w
));
14598 /* Perform the operation on the screen. */
14601 /* Scroll last_unchanged_at_beg_row to the end of the
14602 window down dvpos lines. */
14603 set_terminal_window (end
);
14605 /* On dumb terminals delete dvpos lines at the end
14606 before inserting dvpos empty lines. */
14607 if (!scroll_region_ok
)
14608 ins_del_lines (end
- dvpos
, -dvpos
);
14610 /* Insert dvpos empty lines in front of
14611 last_unchanged_at_beg_row. */
14612 ins_del_lines (from
, dvpos
);
14614 else if (dvpos
< 0)
14616 /* Scroll up last_unchanged_at_beg_vpos to the end of
14617 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14618 set_terminal_window (end
);
14620 /* Delete dvpos lines in front of
14621 last_unchanged_at_beg_vpos. ins_del_lines will set
14622 the cursor to the given vpos and emit |dvpos| delete
14624 ins_del_lines (from
+ dvpos
, dvpos
);
14626 /* On a dumb terminal insert dvpos empty lines at the
14628 if (!scroll_region_ok
)
14629 ins_del_lines (end
+ dvpos
, -dvpos
);
14632 set_terminal_window (0);
14638 /* Shift reused rows of the current matrix to the right position.
14639 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14641 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14642 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14645 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14646 bottom_vpos
, dvpos
);
14647 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14650 else if (dvpos
> 0)
14652 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14653 bottom_vpos
, dvpos
);
14654 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14655 first_unchanged_at_end_vpos
+ dvpos
, 0);
14658 /* For frame-based redisplay, make sure that current frame and window
14659 matrix are in sync with respect to glyph memory. */
14660 if (!FRAME_WINDOW_P (f
))
14661 sync_frame_with_window_matrix_rows (w
);
14663 /* Adjust buffer positions in reused rows. */
14665 increment_matrix_positions (current_matrix
,
14666 first_unchanged_at_end_vpos
+ dvpos
,
14667 bottom_vpos
, delta
, delta_bytes
);
14669 /* Adjust Y positions. */
14671 shift_glyph_matrix (w
, current_matrix
,
14672 first_unchanged_at_end_vpos
+ dvpos
,
14675 if (first_unchanged_at_end_row
)
14677 first_unchanged_at_end_row
+= dvpos
;
14678 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14679 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14680 first_unchanged_at_end_row
= NULL
;
14683 /* If scrolling up, there may be some lines to display at the end of
14685 last_text_row_at_end
= NULL
;
14688 /* Scrolling up can leave for example a partially visible line
14689 at the end of the window to be redisplayed. */
14690 /* Set last_row to the glyph row in the current matrix where the
14691 window end line is found. It has been moved up or down in
14692 the matrix by dvpos. */
14693 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14694 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14696 /* If last_row is the window end line, it should display text. */
14697 xassert (last_row
->displays_text_p
);
14699 /* If window end line was partially visible before, begin
14700 displaying at that line. Otherwise begin displaying with the
14701 line following it. */
14702 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14704 init_to_row_start (&it
, w
, last_row
);
14705 it
.vpos
= last_vpos
;
14706 it
.current_y
= last_row
->y
;
14710 init_to_row_end (&it
, w
, last_row
);
14711 it
.vpos
= 1 + last_vpos
;
14712 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14716 /* We may start in a continuation line. If so, we have to
14717 get the right continuation_lines_width and current_x. */
14718 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14719 it
.hpos
= it
.current_x
= 0;
14721 /* Display the rest of the lines at the window end. */
14722 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14723 while (it
.current_y
< it
.last_visible_y
14724 && !fonts_changed_p
)
14726 /* Is it always sure that the display agrees with lines in
14727 the current matrix? I don't think so, so we mark rows
14728 displayed invalid in the current matrix by setting their
14729 enabled_p flag to zero. */
14730 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14731 if (display_line (&it
))
14732 last_text_row_at_end
= it
.glyph_row
- 1;
14736 /* Update window_end_pos and window_end_vpos. */
14737 if (first_unchanged_at_end_row
14738 && !last_text_row_at_end
)
14740 /* Window end line if one of the preserved rows from the current
14741 matrix. Set row to the last row displaying text in current
14742 matrix starting at first_unchanged_at_end_row, after
14744 xassert (first_unchanged_at_end_row
->displays_text_p
);
14745 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14746 first_unchanged_at_end_row
);
14747 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14749 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14750 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14752 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14753 xassert (w
->window_end_bytepos
>= 0);
14754 IF_DEBUG (debug_method_add (w
, "A"));
14756 else if (last_text_row_at_end
)
14759 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14760 w
->window_end_bytepos
14761 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14763 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14764 xassert (w
->window_end_bytepos
>= 0);
14765 IF_DEBUG (debug_method_add (w
, "B"));
14767 else if (last_text_row
)
14769 /* We have displayed either to the end of the window or at the
14770 end of the window, i.e. the last row with text is to be found
14771 in the desired matrix. */
14773 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14774 w
->window_end_bytepos
14775 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14777 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14778 xassert (w
->window_end_bytepos
>= 0);
14780 else if (first_unchanged_at_end_row
== NULL
14781 && last_text_row
== NULL
14782 && last_text_row_at_end
== NULL
)
14784 /* Displayed to end of window, but no line containing text was
14785 displayed. Lines were deleted at the end of the window. */
14786 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14787 int vpos
= XFASTINT (w
->window_end_vpos
);
14788 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14789 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14792 row
== NULL
&& vpos
>= first_vpos
;
14793 --vpos
, --current_row
, --desired_row
)
14795 if (desired_row
->enabled_p
)
14797 if (desired_row
->displays_text_p
)
14800 else if (current_row
->displays_text_p
)
14804 xassert (row
!= NULL
);
14805 w
->window_end_vpos
= make_number (vpos
+ 1);
14806 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14807 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14808 xassert (w
->window_end_bytepos
>= 0);
14809 IF_DEBUG (debug_method_add (w
, "C"));
14814 #if 0 /* This leads to problems, for instance when the cursor is
14815 at ZV, and the cursor line displays no text. */
14816 /* Disable rows below what's displayed in the window. This makes
14817 debugging easier. */
14818 enable_glyph_matrix_rows (current_matrix
,
14819 XFASTINT (w
->window_end_vpos
) + 1,
14823 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14824 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14826 /* Record that display has not been completed. */
14827 w
->window_end_valid
= Qnil
;
14828 w
->desired_matrix
->no_scrolling_p
= 1;
14836 /***********************************************************************
14837 More debugging support
14838 ***********************************************************************/
14842 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14843 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14844 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14847 /* Dump the contents of glyph matrix MATRIX on stderr.
14849 GLYPHS 0 means don't show glyph contents.
14850 GLYPHS 1 means show glyphs in short form
14851 GLYPHS > 1 means show glyphs in long form. */
14854 dump_glyph_matrix (matrix
, glyphs
)
14855 struct glyph_matrix
*matrix
;
14859 for (i
= 0; i
< matrix
->nrows
; ++i
)
14860 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14864 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14865 the glyph row and area where the glyph comes from. */
14868 dump_glyph (row
, glyph
, area
)
14869 struct glyph_row
*row
;
14870 struct glyph
*glyph
;
14873 if (glyph
->type
== CHAR_GLYPH
)
14876 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14877 glyph
- row
->glyphs
[TEXT_AREA
],
14880 (BUFFERP (glyph
->object
)
14882 : (STRINGP (glyph
->object
)
14885 glyph
->pixel_width
,
14887 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14891 glyph
->left_box_line_p
,
14892 glyph
->right_box_line_p
);
14894 else if (glyph
->type
== STRETCH_GLYPH
)
14897 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14898 glyph
- row
->glyphs
[TEXT_AREA
],
14901 (BUFFERP (glyph
->object
)
14903 : (STRINGP (glyph
->object
)
14906 glyph
->pixel_width
,
14910 glyph
->left_box_line_p
,
14911 glyph
->right_box_line_p
);
14913 else if (glyph
->type
== IMAGE_GLYPH
)
14916 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14917 glyph
- row
->glyphs
[TEXT_AREA
],
14920 (BUFFERP (glyph
->object
)
14922 : (STRINGP (glyph
->object
)
14925 glyph
->pixel_width
,
14929 glyph
->left_box_line_p
,
14930 glyph
->right_box_line_p
);
14935 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14936 GLYPHS 0 means don't show glyph contents.
14937 GLYPHS 1 means show glyphs in short form
14938 GLYPHS > 1 means show glyphs in long form. */
14941 dump_glyph_row (row
, vpos
, glyphs
)
14942 struct glyph_row
*row
;
14947 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
14948 fprintf (stderr
, "======================================================================\n");
14950 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14951 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14953 MATRIX_ROW_START_CHARPOS (row
),
14954 MATRIX_ROW_END_CHARPOS (row
),
14955 row
->used
[TEXT_AREA
],
14956 row
->contains_overlapping_glyphs_p
,
14958 row
->truncated_on_left_p
,
14959 row
->truncated_on_right_p
,
14961 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14962 row
->displays_text_p
,
14965 row
->ends_in_middle_of_char_p
,
14966 row
->starts_in_middle_of_char_p
,
14972 row
->visible_height
,
14975 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14976 row
->end
.overlay_string_index
,
14977 row
->continuation_lines_width
);
14978 fprintf (stderr
, "%9d %5d\n",
14979 CHARPOS (row
->start
.string_pos
),
14980 CHARPOS (row
->end
.string_pos
));
14981 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14982 row
->end
.dpvec_index
);
14989 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14991 struct glyph
*glyph
= row
->glyphs
[area
];
14992 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14994 /* Glyph for a line end in text. */
14995 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14998 if (glyph
< glyph_end
)
14999 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15001 for (; glyph
< glyph_end
; ++glyph
)
15002 dump_glyph (row
, glyph
, area
);
15005 else if (glyphs
== 1)
15009 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15011 char *s
= (char *) alloca (row
->used
[area
] + 1);
15014 for (i
= 0; i
< row
->used
[area
]; ++i
)
15016 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15017 if (glyph
->type
== CHAR_GLYPH
15018 && glyph
->u
.ch
< 0x80
15019 && glyph
->u
.ch
>= ' ')
15020 s
[i
] = glyph
->u
.ch
;
15026 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15032 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15033 Sdump_glyph_matrix
, 0, 1, "p",
15034 doc
: /* Dump the current matrix of the selected window to stderr.
15035 Shows contents of glyph row structures. With non-nil
15036 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15037 glyphs in short form, otherwise show glyphs in long form. */)
15039 Lisp_Object glyphs
;
15041 struct window
*w
= XWINDOW (selected_window
);
15042 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15044 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15045 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15046 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15047 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15048 fprintf (stderr
, "=============================================\n");
15049 dump_glyph_matrix (w
->current_matrix
,
15050 NILP (glyphs
) ? 0 : XINT (glyphs
));
15055 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15056 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15059 struct frame
*f
= XFRAME (selected_frame
);
15060 dump_glyph_matrix (f
->current_matrix
, 1);
15065 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15066 doc
: /* Dump glyph row ROW to stderr.
15067 GLYPH 0 means don't dump glyphs.
15068 GLYPH 1 means dump glyphs in short form.
15069 GLYPH > 1 or omitted means dump glyphs in long form. */)
15071 Lisp_Object row
, glyphs
;
15073 struct glyph_matrix
*matrix
;
15076 CHECK_NUMBER (row
);
15077 matrix
= XWINDOW (selected_window
)->current_matrix
;
15079 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15080 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15082 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15087 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15088 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15089 GLYPH 0 means don't dump glyphs.
15090 GLYPH 1 means dump glyphs in short form.
15091 GLYPH > 1 or omitted means dump glyphs in long form. */)
15093 Lisp_Object row
, glyphs
;
15095 struct frame
*sf
= SELECTED_FRAME ();
15096 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15099 CHECK_NUMBER (row
);
15101 if (vpos
>= 0 && vpos
< m
->nrows
)
15102 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15103 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15108 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15109 doc
: /* Toggle tracing of redisplay.
15110 With ARG, turn tracing on if and only if ARG is positive. */)
15115 trace_redisplay_p
= !trace_redisplay_p
;
15118 arg
= Fprefix_numeric_value (arg
);
15119 trace_redisplay_p
= XINT (arg
) > 0;
15126 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15127 doc
: /* Like `format', but print result to stderr.
15128 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15133 Lisp_Object s
= Fformat (nargs
, args
);
15134 fprintf (stderr
, "%s", SDATA (s
));
15138 #endif /* GLYPH_DEBUG */
15142 /***********************************************************************
15143 Building Desired Matrix Rows
15144 ***********************************************************************/
15146 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15147 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15149 static struct glyph_row
*
15150 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15152 Lisp_Object overlay_arrow_string
;
15154 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15155 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15156 struct buffer
*old
= current_buffer
;
15157 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15158 int arrow_len
= SCHARS (overlay_arrow_string
);
15159 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15160 const unsigned char *p
;
15163 int n_glyphs_before
;
15165 set_buffer_temp (buffer
);
15166 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15167 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15168 SET_TEXT_POS (it
.position
, 0, 0);
15170 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15172 while (p
< arrow_end
)
15174 Lisp_Object face
, ilisp
;
15176 /* Get the next character. */
15178 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15180 it
.c
= *p
, it
.len
= 1;
15183 /* Get its face. */
15184 ilisp
= make_number (p
- arrow_string
);
15185 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15186 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15188 /* Compute its width, get its glyphs. */
15189 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15190 SET_TEXT_POS (it
.position
, -1, -1);
15191 PRODUCE_GLYPHS (&it
);
15193 /* If this character doesn't fit any more in the line, we have
15194 to remove some glyphs. */
15195 if (it
.current_x
> it
.last_visible_x
)
15197 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15202 set_buffer_temp (old
);
15203 return it
.glyph_row
;
15207 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15208 glyphs are only inserted for terminal frames since we can't really
15209 win with truncation glyphs when partially visible glyphs are
15210 involved. Which glyphs to insert is determined by
15211 produce_special_glyphs. */
15214 insert_left_trunc_glyphs (it
)
15217 struct it truncate_it
;
15218 struct glyph
*from
, *end
, *to
, *toend
;
15220 xassert (!FRAME_WINDOW_P (it
->f
));
15222 /* Get the truncation glyphs. */
15224 truncate_it
.current_x
= 0;
15225 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15226 truncate_it
.glyph_row
= &scratch_glyph_row
;
15227 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15228 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15229 truncate_it
.object
= make_number (0);
15230 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15232 /* Overwrite glyphs from IT with truncation glyphs. */
15233 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15234 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15235 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15236 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15241 /* There may be padding glyphs left over. Overwrite them too. */
15242 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15244 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15250 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15254 /* Compute the pixel height and width of IT->glyph_row.
15256 Most of the time, ascent and height of a display line will be equal
15257 to the max_ascent and max_height values of the display iterator
15258 structure. This is not the case if
15260 1. We hit ZV without displaying anything. In this case, max_ascent
15261 and max_height will be zero.
15263 2. We have some glyphs that don't contribute to the line height.
15264 (The glyph row flag contributes_to_line_height_p is for future
15265 pixmap extensions).
15267 The first case is easily covered by using default values because in
15268 these cases, the line height does not really matter, except that it
15269 must not be zero. */
15272 compute_line_metrics (it
)
15275 struct glyph_row
*row
= it
->glyph_row
;
15278 if (FRAME_WINDOW_P (it
->f
))
15280 int i
, min_y
, max_y
;
15282 /* The line may consist of one space only, that was added to
15283 place the cursor on it. If so, the row's height hasn't been
15285 if (row
->height
== 0)
15287 if (it
->max_ascent
+ it
->max_descent
== 0)
15288 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15289 row
->ascent
= it
->max_ascent
;
15290 row
->height
= it
->max_ascent
+ it
->max_descent
;
15291 row
->phys_ascent
= it
->max_phys_ascent
;
15292 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15293 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15296 /* Compute the width of this line. */
15297 row
->pixel_width
= row
->x
;
15298 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15299 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15301 xassert (row
->pixel_width
>= 0);
15302 xassert (row
->ascent
>= 0 && row
->height
> 0);
15304 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15305 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15307 /* If first line's physical ascent is larger than its logical
15308 ascent, use the physical ascent, and make the row taller.
15309 This makes accented characters fully visible. */
15310 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15311 && row
->phys_ascent
> row
->ascent
)
15313 row
->height
+= row
->phys_ascent
- row
->ascent
;
15314 row
->ascent
= row
->phys_ascent
;
15317 /* Compute how much of the line is visible. */
15318 row
->visible_height
= row
->height
;
15320 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15321 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15323 if (row
->y
< min_y
)
15324 row
->visible_height
-= min_y
- row
->y
;
15325 if (row
->y
+ row
->height
> max_y
)
15326 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15330 row
->pixel_width
= row
->used
[TEXT_AREA
];
15331 if (row
->continued_p
)
15332 row
->pixel_width
-= it
->continuation_pixel_width
;
15333 else if (row
->truncated_on_right_p
)
15334 row
->pixel_width
-= it
->truncation_pixel_width
;
15335 row
->ascent
= row
->phys_ascent
= 0;
15336 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15337 row
->extra_line_spacing
= 0;
15340 /* Compute a hash code for this row. */
15342 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15343 for (i
= 0; i
< row
->used
[area
]; ++i
)
15344 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15345 + row
->glyphs
[area
][i
].u
.val
15346 + row
->glyphs
[area
][i
].face_id
15347 + row
->glyphs
[area
][i
].padding_p
15348 + (row
->glyphs
[area
][i
].type
<< 2));
15350 it
->max_ascent
= it
->max_descent
= 0;
15351 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15355 /* Append one space to the glyph row of iterator IT if doing a
15356 window-based redisplay. The space has the same face as
15357 IT->face_id. Value is non-zero if a space was added.
15359 This function is called to make sure that there is always one glyph
15360 at the end of a glyph row that the cursor can be set on under
15361 window-systems. (If there weren't such a glyph we would not know
15362 how wide and tall a box cursor should be displayed).
15364 At the same time this space let's a nicely handle clearing to the
15365 end of the line if the row ends in italic text. */
15368 append_space_for_newline (it
, default_face_p
)
15370 int default_face_p
;
15372 if (FRAME_WINDOW_P (it
->f
))
15374 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15376 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15377 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15379 /* Save some values that must not be changed.
15380 Must save IT->c and IT->len because otherwise
15381 ITERATOR_AT_END_P wouldn't work anymore after
15382 append_space_for_newline has been called. */
15383 enum display_element_type saved_what
= it
->what
;
15384 int saved_c
= it
->c
, saved_len
= it
->len
;
15385 int saved_x
= it
->current_x
;
15386 int saved_face_id
= it
->face_id
;
15387 struct text_pos saved_pos
;
15388 Lisp_Object saved_object
;
15391 saved_object
= it
->object
;
15392 saved_pos
= it
->position
;
15394 it
->what
= IT_CHARACTER
;
15395 bzero (&it
->position
, sizeof it
->position
);
15396 it
->object
= make_number (0);
15400 if (default_face_p
)
15401 it
->face_id
= DEFAULT_FACE_ID
;
15402 else if (it
->face_before_selective_p
)
15403 it
->face_id
= it
->saved_face_id
;
15404 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15405 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15407 PRODUCE_GLYPHS (it
);
15409 it
->override_ascent
= -1;
15410 it
->constrain_row_ascent_descent_p
= 0;
15411 it
->current_x
= saved_x
;
15412 it
->object
= saved_object
;
15413 it
->position
= saved_pos
;
15414 it
->what
= saved_what
;
15415 it
->face_id
= saved_face_id
;
15416 it
->len
= saved_len
;
15426 /* Extend the face of the last glyph in the text area of IT->glyph_row
15427 to the end of the display line. Called from display_line.
15428 If the glyph row is empty, add a space glyph to it so that we
15429 know the face to draw. Set the glyph row flag fill_line_p. */
15432 extend_face_to_end_of_line (it
)
15436 struct frame
*f
= it
->f
;
15438 /* If line is already filled, do nothing. */
15439 if (it
->current_x
>= it
->last_visible_x
)
15442 /* Face extension extends the background and box of IT->face_id
15443 to the end of the line. If the background equals the background
15444 of the frame, we don't have to do anything. */
15445 if (it
->face_before_selective_p
)
15446 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15448 face
= FACE_FROM_ID (f
, it
->face_id
);
15450 if (FRAME_WINDOW_P (f
)
15451 && it
->glyph_row
->displays_text_p
15452 && face
->box
== FACE_NO_BOX
15453 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15457 /* Set the glyph row flag indicating that the face of the last glyph
15458 in the text area has to be drawn to the end of the text area. */
15459 it
->glyph_row
->fill_line_p
= 1;
15461 /* If current character of IT is not ASCII, make sure we have the
15462 ASCII face. This will be automatically undone the next time
15463 get_next_display_element returns a multibyte character. Note
15464 that the character will always be single byte in unibyte text. */
15465 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15467 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15470 if (FRAME_WINDOW_P (f
))
15472 /* If the row is empty, add a space with the current face of IT,
15473 so that we know which face to draw. */
15474 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15476 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15477 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15478 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15483 /* Save some values that must not be changed. */
15484 int saved_x
= it
->current_x
;
15485 struct text_pos saved_pos
;
15486 Lisp_Object saved_object
;
15487 enum display_element_type saved_what
= it
->what
;
15488 int saved_face_id
= it
->face_id
;
15490 saved_object
= it
->object
;
15491 saved_pos
= it
->position
;
15493 it
->what
= IT_CHARACTER
;
15494 bzero (&it
->position
, sizeof it
->position
);
15495 it
->object
= make_number (0);
15498 it
->face_id
= face
->id
;
15500 PRODUCE_GLYPHS (it
);
15502 while (it
->current_x
<= it
->last_visible_x
)
15503 PRODUCE_GLYPHS (it
);
15505 /* Don't count these blanks really. It would let us insert a left
15506 truncation glyph below and make us set the cursor on them, maybe. */
15507 it
->current_x
= saved_x
;
15508 it
->object
= saved_object
;
15509 it
->position
= saved_pos
;
15510 it
->what
= saved_what
;
15511 it
->face_id
= saved_face_id
;
15516 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15517 trailing whitespace. */
15520 trailing_whitespace_p (charpos
)
15523 int bytepos
= CHAR_TO_BYTE (charpos
);
15526 while (bytepos
< ZV_BYTE
15527 && (c
= FETCH_CHAR (bytepos
),
15528 c
== ' ' || c
== '\t'))
15531 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15533 if (bytepos
!= PT_BYTE
)
15540 /* Highlight trailing whitespace, if any, in ROW. */
15543 highlight_trailing_whitespace (f
, row
)
15545 struct glyph_row
*row
;
15547 int used
= row
->used
[TEXT_AREA
];
15551 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15552 struct glyph
*glyph
= start
+ used
- 1;
15554 /* Skip over glyphs inserted to display the cursor at the
15555 end of a line, for extending the face of the last glyph
15556 to the end of the line on terminals, and for truncation
15557 and continuation glyphs. */
15558 while (glyph
>= start
15559 && glyph
->type
== CHAR_GLYPH
15560 && INTEGERP (glyph
->object
))
15563 /* If last glyph is a space or stretch, and it's trailing
15564 whitespace, set the face of all trailing whitespace glyphs in
15565 IT->glyph_row to `trailing-whitespace'. */
15567 && BUFFERP (glyph
->object
)
15568 && (glyph
->type
== STRETCH_GLYPH
15569 || (glyph
->type
== CHAR_GLYPH
15570 && glyph
->u
.ch
== ' '))
15571 && trailing_whitespace_p (glyph
->charpos
))
15573 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15577 while (glyph
>= start
15578 && BUFFERP (glyph
->object
)
15579 && (glyph
->type
== STRETCH_GLYPH
15580 || (glyph
->type
== CHAR_GLYPH
15581 && glyph
->u
.ch
== ' ')))
15582 (glyph
--)->face_id
= face_id
;
15588 /* Value is non-zero if glyph row ROW in window W should be
15589 used to hold the cursor. */
15592 cursor_row_p (w
, row
)
15594 struct glyph_row
*row
;
15596 int cursor_row_p
= 1;
15598 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15600 /* If the row ends with a newline from a string, we don't want
15601 the cursor there, but we still want it at the start of the
15602 string if the string starts in this row.
15603 If the row is continued it doesn't end in a newline. */
15604 if (CHARPOS (row
->end
.string_pos
) >= 0)
15605 cursor_row_p
= (row
->continued_p
15606 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15607 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15609 /* If the row ends in middle of a real character,
15610 and the line is continued, we want the cursor here.
15611 That's because MATRIX_ROW_END_CHARPOS would equal
15612 PT if PT is before the character. */
15613 if (!row
->ends_in_ellipsis_p
)
15614 cursor_row_p
= row
->continued_p
;
15616 /* If the row ends in an ellipsis, then
15617 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15618 We want that position to be displayed after the ellipsis. */
15621 /* If the row ends at ZV, display the cursor at the end of that
15622 row instead of at the start of the row below. */
15623 else if (row
->ends_at_zv_p
)
15629 return cursor_row_p
;
15633 /* Construct the glyph row IT->glyph_row in the desired matrix of
15634 IT->w from text at the current position of IT. See dispextern.h
15635 for an overview of struct it. Value is non-zero if
15636 IT->glyph_row displays text, as opposed to a line displaying ZV
15643 struct glyph_row
*row
= it
->glyph_row
;
15644 Lisp_Object overlay_arrow_string
;
15646 /* We always start displaying at hpos zero even if hscrolled. */
15647 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15649 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15650 >= it
->w
->desired_matrix
->nrows
)
15652 it
->w
->nrows_scale_factor
++;
15653 fonts_changed_p
= 1;
15657 /* Is IT->w showing the region? */
15658 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15660 /* Clear the result glyph row and enable it. */
15661 prepare_desired_row (row
);
15663 row
->y
= it
->current_y
;
15664 row
->start
= it
->start
;
15665 row
->continuation_lines_width
= it
->continuation_lines_width
;
15666 row
->displays_text_p
= 1;
15667 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15668 it
->starts_in_middle_of_char_p
= 0;
15670 /* Arrange the overlays nicely for our purposes. Usually, we call
15671 display_line on only one line at a time, in which case this
15672 can't really hurt too much, or we call it on lines which appear
15673 one after another in the buffer, in which case all calls to
15674 recenter_overlay_lists but the first will be pretty cheap. */
15675 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15677 /* Move over display elements that are not visible because we are
15678 hscrolled. This may stop at an x-position < IT->first_visible_x
15679 if the first glyph is partially visible or if we hit a line end. */
15680 if (it
->current_x
< it
->first_visible_x
)
15682 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15683 MOVE_TO_POS
| MOVE_TO_X
);
15686 /* Get the initial row height. This is either the height of the
15687 text hscrolled, if there is any, or zero. */
15688 row
->ascent
= it
->max_ascent
;
15689 row
->height
= it
->max_ascent
+ it
->max_descent
;
15690 row
->phys_ascent
= it
->max_phys_ascent
;
15691 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15692 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15694 /* Loop generating characters. The loop is left with IT on the next
15695 character to display. */
15698 int n_glyphs_before
, hpos_before
, x_before
;
15700 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15702 /* Retrieve the next thing to display. Value is zero if end of
15704 if (!get_next_display_element (it
))
15706 /* Maybe add a space at the end of this line that is used to
15707 display the cursor there under X. Set the charpos of the
15708 first glyph of blank lines not corresponding to any text
15710 #ifdef HAVE_WINDOW_SYSTEM
15711 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15712 row
->exact_window_width_line_p
= 1;
15714 #endif /* HAVE_WINDOW_SYSTEM */
15715 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15716 || row
->used
[TEXT_AREA
] == 0)
15718 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15719 row
->displays_text_p
= 0;
15721 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15722 && (!MINI_WINDOW_P (it
->w
)
15723 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15724 row
->indicate_empty_line_p
= 1;
15727 it
->continuation_lines_width
= 0;
15728 row
->ends_at_zv_p
= 1;
15732 /* Now, get the metrics of what we want to display. This also
15733 generates glyphs in `row' (which is IT->glyph_row). */
15734 n_glyphs_before
= row
->used
[TEXT_AREA
];
15737 /* Remember the line height so far in case the next element doesn't
15738 fit on the line. */
15739 if (!it
->truncate_lines_p
)
15741 ascent
= it
->max_ascent
;
15742 descent
= it
->max_descent
;
15743 phys_ascent
= it
->max_phys_ascent
;
15744 phys_descent
= it
->max_phys_descent
;
15747 PRODUCE_GLYPHS (it
);
15749 /* If this display element was in marginal areas, continue with
15751 if (it
->area
!= TEXT_AREA
)
15753 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15754 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15755 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15756 row
->phys_height
= max (row
->phys_height
,
15757 it
->max_phys_ascent
+ it
->max_phys_descent
);
15758 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15759 it
->max_extra_line_spacing
);
15760 set_iterator_to_next (it
, 1);
15764 /* Does the display element fit on the line? If we truncate
15765 lines, we should draw past the right edge of the window. If
15766 we don't truncate, we want to stop so that we can display the
15767 continuation glyph before the right margin. If lines are
15768 continued, there are two possible strategies for characters
15769 resulting in more than 1 glyph (e.g. tabs): Display as many
15770 glyphs as possible in this line and leave the rest for the
15771 continuation line, or display the whole element in the next
15772 line. Original redisplay did the former, so we do it also. */
15773 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15774 hpos_before
= it
->hpos
;
15777 if (/* Not a newline. */
15779 /* Glyphs produced fit entirely in the line. */
15780 && it
->current_x
< it
->last_visible_x
)
15782 it
->hpos
+= nglyphs
;
15783 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15784 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15785 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15786 row
->phys_height
= max (row
->phys_height
,
15787 it
->max_phys_ascent
+ it
->max_phys_descent
);
15788 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15789 it
->max_extra_line_spacing
);
15790 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15791 row
->x
= x
- it
->first_visible_x
;
15796 struct glyph
*glyph
;
15798 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15800 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15801 new_x
= x
+ glyph
->pixel_width
;
15803 if (/* Lines are continued. */
15804 !it
->truncate_lines_p
15805 && (/* Glyph doesn't fit on the line. */
15806 new_x
> it
->last_visible_x
15807 /* Or it fits exactly on a window system frame. */
15808 || (new_x
== it
->last_visible_x
15809 && FRAME_WINDOW_P (it
->f
))))
15811 /* End of a continued line. */
15814 || (new_x
== it
->last_visible_x
15815 && FRAME_WINDOW_P (it
->f
)))
15817 /* Current glyph is the only one on the line or
15818 fits exactly on the line. We must continue
15819 the line because we can't draw the cursor
15820 after the glyph. */
15821 row
->continued_p
= 1;
15822 it
->current_x
= new_x
;
15823 it
->continuation_lines_width
+= new_x
;
15825 if (i
== nglyphs
- 1)
15827 set_iterator_to_next (it
, 1);
15828 #ifdef HAVE_WINDOW_SYSTEM
15829 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15831 if (!get_next_display_element (it
))
15833 row
->exact_window_width_line_p
= 1;
15834 it
->continuation_lines_width
= 0;
15835 row
->continued_p
= 0;
15836 row
->ends_at_zv_p
= 1;
15838 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15840 row
->continued_p
= 0;
15841 row
->exact_window_width_line_p
= 1;
15844 #endif /* HAVE_WINDOW_SYSTEM */
15847 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15848 && !FRAME_WINDOW_P (it
->f
))
15850 /* A padding glyph that doesn't fit on this line.
15851 This means the whole character doesn't fit
15853 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15855 /* Fill the rest of the row with continuation
15856 glyphs like in 20.x. */
15857 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15858 < row
->glyphs
[1 + TEXT_AREA
])
15859 produce_special_glyphs (it
, IT_CONTINUATION
);
15861 row
->continued_p
= 1;
15862 it
->current_x
= x_before
;
15863 it
->continuation_lines_width
+= x_before
;
15865 /* Restore the height to what it was before the
15866 element not fitting on the line. */
15867 it
->max_ascent
= ascent
;
15868 it
->max_descent
= descent
;
15869 it
->max_phys_ascent
= phys_ascent
;
15870 it
->max_phys_descent
= phys_descent
;
15872 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15874 /* A TAB that extends past the right edge of the
15875 window. This produces a single glyph on
15876 window system frames. We leave the glyph in
15877 this row and let it fill the row, but don't
15878 consume the TAB. */
15879 it
->continuation_lines_width
+= it
->last_visible_x
;
15880 row
->ends_in_middle_of_char_p
= 1;
15881 row
->continued_p
= 1;
15882 glyph
->pixel_width
= it
->last_visible_x
- x
;
15883 it
->starts_in_middle_of_char_p
= 1;
15887 /* Something other than a TAB that draws past
15888 the right edge of the window. Restore
15889 positions to values before the element. */
15890 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15892 /* Display continuation glyphs. */
15893 if (!FRAME_WINDOW_P (it
->f
))
15894 produce_special_glyphs (it
, IT_CONTINUATION
);
15895 row
->continued_p
= 1;
15897 it
->current_x
= x_before
;
15898 it
->continuation_lines_width
+= x
;
15899 extend_face_to_end_of_line (it
);
15901 if (nglyphs
> 1 && i
> 0)
15903 row
->ends_in_middle_of_char_p
= 1;
15904 it
->starts_in_middle_of_char_p
= 1;
15907 /* Restore the height to what it was before the
15908 element not fitting on the line. */
15909 it
->max_ascent
= ascent
;
15910 it
->max_descent
= descent
;
15911 it
->max_phys_ascent
= phys_ascent
;
15912 it
->max_phys_descent
= phys_descent
;
15917 else if (new_x
> it
->first_visible_x
)
15919 /* Increment number of glyphs actually displayed. */
15922 if (x
< it
->first_visible_x
)
15923 /* Glyph is partially visible, i.e. row starts at
15924 negative X position. */
15925 row
->x
= x
- it
->first_visible_x
;
15929 /* Glyph is completely off the left margin of the
15930 window. This should not happen because of the
15931 move_it_in_display_line at the start of this
15932 function, unless the text display area of the
15933 window is empty. */
15934 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15938 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15939 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15940 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15941 row
->phys_height
= max (row
->phys_height
,
15942 it
->max_phys_ascent
+ it
->max_phys_descent
);
15943 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15944 it
->max_extra_line_spacing
);
15946 /* End of this display line if row is continued. */
15947 if (row
->continued_p
|| row
->ends_at_zv_p
)
15952 /* Is this a line end? If yes, we're also done, after making
15953 sure that a non-default face is extended up to the right
15954 margin of the window. */
15955 if (ITERATOR_AT_END_OF_LINE_P (it
))
15957 int used_before
= row
->used
[TEXT_AREA
];
15959 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15961 #ifdef HAVE_WINDOW_SYSTEM
15962 /* Add a space at the end of the line that is used to
15963 display the cursor there. */
15964 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15965 append_space_for_newline (it
, 0);
15966 #endif /* HAVE_WINDOW_SYSTEM */
15968 /* Extend the face to the end of the line. */
15969 extend_face_to_end_of_line (it
);
15971 /* Make sure we have the position. */
15972 if (used_before
== 0)
15973 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15975 /* Consume the line end. This skips over invisible lines. */
15976 set_iterator_to_next (it
, 1);
15977 it
->continuation_lines_width
= 0;
15981 /* Proceed with next display element. Note that this skips
15982 over lines invisible because of selective display. */
15983 set_iterator_to_next (it
, 1);
15985 /* If we truncate lines, we are done when the last displayed
15986 glyphs reach past the right margin of the window. */
15987 if (it
->truncate_lines_p
15988 && (FRAME_WINDOW_P (it
->f
)
15989 ? (it
->current_x
>= it
->last_visible_x
)
15990 : (it
->current_x
> it
->last_visible_x
)))
15992 /* Maybe add truncation glyphs. */
15993 if (!FRAME_WINDOW_P (it
->f
))
15997 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15998 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16001 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16003 row
->used
[TEXT_AREA
] = i
;
16004 produce_special_glyphs (it
, IT_TRUNCATION
);
16007 #ifdef HAVE_WINDOW_SYSTEM
16010 /* Don't truncate if we can overflow newline into fringe. */
16011 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16013 if (!get_next_display_element (it
))
16015 it
->continuation_lines_width
= 0;
16016 row
->ends_at_zv_p
= 1;
16017 row
->exact_window_width_line_p
= 1;
16020 if (ITERATOR_AT_END_OF_LINE_P (it
))
16022 row
->exact_window_width_line_p
= 1;
16023 goto at_end_of_line
;
16027 #endif /* HAVE_WINDOW_SYSTEM */
16029 row
->truncated_on_right_p
= 1;
16030 it
->continuation_lines_width
= 0;
16031 reseat_at_next_visible_line_start (it
, 0);
16032 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16033 it
->hpos
= hpos_before
;
16034 it
->current_x
= x_before
;
16039 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16040 at the left window margin. */
16041 if (it
->first_visible_x
16042 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16044 if (!FRAME_WINDOW_P (it
->f
))
16045 insert_left_trunc_glyphs (it
);
16046 row
->truncated_on_left_p
= 1;
16049 /* If the start of this line is the overlay arrow-position, then
16050 mark this glyph row as the one containing the overlay arrow.
16051 This is clearly a mess with variable size fonts. It would be
16052 better to let it be displayed like cursors under X. */
16053 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16054 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16055 !NILP (overlay_arrow_string
)))
16057 /* Overlay arrow in window redisplay is a fringe bitmap. */
16058 if (STRINGP (overlay_arrow_string
))
16060 struct glyph_row
*arrow_row
16061 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16062 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16063 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16064 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16065 struct glyph
*p2
, *end
;
16067 /* Copy the arrow glyphs. */
16068 while (glyph
< arrow_end
)
16071 /* Throw away padding glyphs. */
16073 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16074 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16080 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16085 xassert (INTEGERP (overlay_arrow_string
));
16086 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16088 overlay_arrow_seen
= 1;
16091 /* Compute pixel dimensions of this line. */
16092 compute_line_metrics (it
);
16094 /* Remember the position at which this line ends. */
16095 row
->end
= it
->current
;
16097 /* Record whether this row ends inside an ellipsis. */
16098 row
->ends_in_ellipsis_p
16099 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16100 && it
->ellipsis_p
);
16102 /* Save fringe bitmaps in this row. */
16103 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16104 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16105 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16106 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16108 it
->left_user_fringe_bitmap
= 0;
16109 it
->left_user_fringe_face_id
= 0;
16110 it
->right_user_fringe_bitmap
= 0;
16111 it
->right_user_fringe_face_id
= 0;
16113 /* Maybe set the cursor. */
16114 if (it
->w
->cursor
.vpos
< 0
16115 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16116 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16117 && cursor_row_p (it
->w
, row
))
16118 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16120 /* Highlight trailing whitespace. */
16121 if (!NILP (Vshow_trailing_whitespace
))
16122 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16124 /* Prepare for the next line. This line starts horizontally at (X
16125 HPOS) = (0 0). Vertical positions are incremented. As a
16126 convenience for the caller, IT->glyph_row is set to the next
16128 it
->current_x
= it
->hpos
= 0;
16129 it
->current_y
+= row
->height
;
16132 it
->start
= it
->current
;
16133 return row
->displays_text_p
;
16138 /***********************************************************************
16140 ***********************************************************************/
16142 /* Redisplay the menu bar in the frame for window W.
16144 The menu bar of X frames that don't have X toolkit support is
16145 displayed in a special window W->frame->menu_bar_window.
16147 The menu bar of terminal frames is treated specially as far as
16148 glyph matrices are concerned. Menu bar lines are not part of
16149 windows, so the update is done directly on the frame matrix rows
16150 for the menu bar. */
16153 display_menu_bar (w
)
16156 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16161 /* Don't do all this for graphical frames. */
16163 if (!NILP (Vwindow_system
))
16166 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16171 if (FRAME_MAC_P (f
))
16175 #ifdef USE_X_TOOLKIT
16176 xassert (!FRAME_WINDOW_P (f
));
16177 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16178 it
.first_visible_x
= 0;
16179 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16180 #else /* not USE_X_TOOLKIT */
16181 if (FRAME_WINDOW_P (f
))
16183 /* Menu bar lines are displayed in the desired matrix of the
16184 dummy window menu_bar_window. */
16185 struct window
*menu_w
;
16186 xassert (WINDOWP (f
->menu_bar_window
));
16187 menu_w
= XWINDOW (f
->menu_bar_window
);
16188 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16190 it
.first_visible_x
= 0;
16191 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16195 /* This is a TTY frame, i.e. character hpos/vpos are used as
16197 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16199 it
.first_visible_x
= 0;
16200 it
.last_visible_x
= FRAME_COLS (f
);
16202 #endif /* not USE_X_TOOLKIT */
16204 if (! mode_line_inverse_video
)
16205 /* Force the menu-bar to be displayed in the default face. */
16206 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16208 /* Clear all rows of the menu bar. */
16209 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16211 struct glyph_row
*row
= it
.glyph_row
+ i
;
16212 clear_glyph_row (row
);
16213 row
->enabled_p
= 1;
16214 row
->full_width_p
= 1;
16217 /* Display all items of the menu bar. */
16218 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16219 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16221 Lisp_Object string
;
16223 /* Stop at nil string. */
16224 string
= AREF (items
, i
+ 1);
16228 /* Remember where item was displayed. */
16229 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16231 /* Display the item, pad with one space. */
16232 if (it
.current_x
< it
.last_visible_x
)
16233 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16234 SCHARS (string
) + 1, 0, 0, -1);
16237 /* Fill out the line with spaces. */
16238 if (it
.current_x
< it
.last_visible_x
)
16239 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16241 /* Compute the total height of the lines. */
16242 compute_line_metrics (&it
);
16247 /***********************************************************************
16249 ***********************************************************************/
16251 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16252 FORCE is non-zero, redisplay mode lines unconditionally.
16253 Otherwise, redisplay only mode lines that are garbaged. Value is
16254 the number of windows whose mode lines were redisplayed. */
16257 redisplay_mode_lines (window
, force
)
16258 Lisp_Object window
;
16263 while (!NILP (window
))
16265 struct window
*w
= XWINDOW (window
);
16267 if (WINDOWP (w
->hchild
))
16268 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16269 else if (WINDOWP (w
->vchild
))
16270 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16272 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16273 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16275 struct text_pos lpoint
;
16276 struct buffer
*old
= current_buffer
;
16278 /* Set the window's buffer for the mode line display. */
16279 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16280 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16282 /* Point refers normally to the selected window. For any
16283 other window, set up appropriate value. */
16284 if (!EQ (window
, selected_window
))
16286 struct text_pos pt
;
16288 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16289 if (CHARPOS (pt
) < BEGV
)
16290 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16291 else if (CHARPOS (pt
) > (ZV
- 1))
16292 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16294 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16297 /* Display mode lines. */
16298 clear_glyph_matrix (w
->desired_matrix
);
16299 if (display_mode_lines (w
))
16302 w
->must_be_updated_p
= 1;
16305 /* Restore old settings. */
16306 set_buffer_internal_1 (old
);
16307 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16317 /* Display the mode and/or top line of window W. Value is the number
16318 of mode lines displayed. */
16321 display_mode_lines (w
)
16324 Lisp_Object old_selected_window
, old_selected_frame
;
16327 old_selected_frame
= selected_frame
;
16328 selected_frame
= w
->frame
;
16329 old_selected_window
= selected_window
;
16330 XSETWINDOW (selected_window
, w
);
16332 /* These will be set while the mode line specs are processed. */
16333 line_number_displayed
= 0;
16334 w
->column_number_displayed
= Qnil
;
16336 if (WINDOW_WANTS_MODELINE_P (w
))
16338 struct window
*sel_w
= XWINDOW (old_selected_window
);
16340 /* Select mode line face based on the real selected window. */
16341 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16342 current_buffer
->mode_line_format
);
16346 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16348 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16349 current_buffer
->header_line_format
);
16353 selected_frame
= old_selected_frame
;
16354 selected_window
= old_selected_window
;
16359 /* Display mode or top line of window W. FACE_ID specifies which line
16360 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16361 FORMAT is the mode line format to display. Value is the pixel
16362 height of the mode line displayed. */
16365 display_mode_line (w
, face_id
, format
)
16367 enum face_id face_id
;
16368 Lisp_Object format
;
16372 int count
= SPECPDL_INDEX ();
16374 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16375 prepare_desired_row (it
.glyph_row
);
16377 it
.glyph_row
->mode_line_p
= 1;
16379 if (! mode_line_inverse_video
)
16380 /* Force the mode-line to be displayed in the default face. */
16381 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16383 record_unwind_protect (unwind_format_mode_line
,
16384 format_mode_line_unwind_data (NULL
, 0));
16386 mode_line_target
= MODE_LINE_DISPLAY
;
16388 /* Temporarily make frame's keyboard the current kboard so that
16389 kboard-local variables in the mode_line_format will get the right
16391 push_frame_kboard (it
.f
);
16392 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16393 pop_frame_kboard ();
16395 unbind_to (count
, Qnil
);
16397 /* Fill up with spaces. */
16398 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16400 compute_line_metrics (&it
);
16401 it
.glyph_row
->full_width_p
= 1;
16402 it
.glyph_row
->continued_p
= 0;
16403 it
.glyph_row
->truncated_on_left_p
= 0;
16404 it
.glyph_row
->truncated_on_right_p
= 0;
16406 /* Make a 3D mode-line have a shadow at its right end. */
16407 face
= FACE_FROM_ID (it
.f
, face_id
);
16408 extend_face_to_end_of_line (&it
);
16409 if (face
->box
!= FACE_NO_BOX
)
16411 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16412 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16413 last
->right_box_line_p
= 1;
16416 return it
.glyph_row
->height
;
16419 /* Move element ELT in LIST to the front of LIST.
16420 Return the updated list. */
16423 move_elt_to_front (elt
, list
)
16424 Lisp_Object elt
, list
;
16426 register Lisp_Object tail
, prev
;
16427 register Lisp_Object tem
;
16431 while (CONSP (tail
))
16437 /* Splice out the link TAIL. */
16439 list
= XCDR (tail
);
16441 Fsetcdr (prev
, XCDR (tail
));
16443 /* Now make it the first. */
16444 Fsetcdr (tail
, list
);
16449 tail
= XCDR (tail
);
16453 /* Not found--return unchanged LIST. */
16457 /* Contribute ELT to the mode line for window IT->w. How it
16458 translates into text depends on its data type.
16460 IT describes the display environment in which we display, as usual.
16462 DEPTH is the depth in recursion. It is used to prevent
16463 infinite recursion here.
16465 FIELD_WIDTH is the number of characters the display of ELT should
16466 occupy in the mode line, and PRECISION is the maximum number of
16467 characters to display from ELT's representation. See
16468 display_string for details.
16470 Returns the hpos of the end of the text generated by ELT.
16472 PROPS is a property list to add to any string we encounter.
16474 If RISKY is nonzero, remove (disregard) any properties in any string
16475 we encounter, and ignore :eval and :propertize.
16477 The global variable `mode_line_target' determines whether the
16478 output is passed to `store_mode_line_noprop',
16479 `store_mode_line_string', or `display_string'. */
16482 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16485 int field_width
, precision
;
16486 Lisp_Object elt
, props
;
16489 int n
= 0, field
, prec
;
16494 elt
= build_string ("*too-deep*");
16498 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16502 /* A string: output it and check for %-constructs within it. */
16506 if (SCHARS (elt
) > 0
16507 && (!NILP (props
) || risky
))
16509 Lisp_Object oprops
, aelt
;
16510 oprops
= Ftext_properties_at (make_number (0), elt
);
16512 /* If the starting string's properties are not what
16513 we want, translate the string. Also, if the string
16514 is risky, do that anyway. */
16516 if (NILP (Fequal (props
, oprops
)) || risky
)
16518 /* If the starting string has properties,
16519 merge the specified ones onto the existing ones. */
16520 if (! NILP (oprops
) && !risky
)
16524 oprops
= Fcopy_sequence (oprops
);
16526 while (CONSP (tem
))
16528 oprops
= Fplist_put (oprops
, XCAR (tem
),
16529 XCAR (XCDR (tem
)));
16530 tem
= XCDR (XCDR (tem
));
16535 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16536 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16538 /* AELT is what we want. Move it to the front
16539 without consing. */
16541 mode_line_proptrans_alist
16542 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16548 /* If AELT has the wrong props, it is useless.
16549 so get rid of it. */
16551 mode_line_proptrans_alist
16552 = Fdelq (aelt
, mode_line_proptrans_alist
);
16554 elt
= Fcopy_sequence (elt
);
16555 Fset_text_properties (make_number (0), Flength (elt
),
16557 /* Add this item to mode_line_proptrans_alist. */
16558 mode_line_proptrans_alist
16559 = Fcons (Fcons (elt
, props
),
16560 mode_line_proptrans_alist
);
16561 /* Truncate mode_line_proptrans_alist
16562 to at most 50 elements. */
16563 tem
= Fnthcdr (make_number (50),
16564 mode_line_proptrans_alist
);
16566 XSETCDR (tem
, Qnil
);
16575 prec
= precision
- n
;
16576 switch (mode_line_target
)
16578 case MODE_LINE_NOPROP
:
16579 case MODE_LINE_TITLE
:
16580 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16582 case MODE_LINE_STRING
:
16583 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16585 case MODE_LINE_DISPLAY
:
16586 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16587 0, prec
, 0, STRING_MULTIBYTE (elt
));
16594 /* Handle the non-literal case. */
16596 while ((precision
<= 0 || n
< precision
)
16597 && SREF (elt
, offset
) != 0
16598 && (mode_line_target
!= MODE_LINE_DISPLAY
16599 || it
->current_x
< it
->last_visible_x
))
16601 int last_offset
= offset
;
16603 /* Advance to end of string or next format specifier. */
16604 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16607 if (offset
- 1 != last_offset
)
16609 int nchars
, nbytes
;
16611 /* Output to end of string or up to '%'. Field width
16612 is length of string. Don't output more than
16613 PRECISION allows us. */
16616 prec
= c_string_width (SDATA (elt
) + last_offset
,
16617 offset
- last_offset
, precision
- n
,
16620 switch (mode_line_target
)
16622 case MODE_LINE_NOPROP
:
16623 case MODE_LINE_TITLE
:
16624 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16626 case MODE_LINE_STRING
:
16628 int bytepos
= last_offset
;
16629 int charpos
= string_byte_to_char (elt
, bytepos
);
16630 int endpos
= (precision
<= 0
16631 ? string_byte_to_char (elt
, offset
)
16632 : charpos
+ nchars
);
16634 n
+= store_mode_line_string (NULL
,
16635 Fsubstring (elt
, make_number (charpos
),
16636 make_number (endpos
)),
16640 case MODE_LINE_DISPLAY
:
16642 int bytepos
= last_offset
;
16643 int charpos
= string_byte_to_char (elt
, bytepos
);
16645 if (precision
<= 0)
16646 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16647 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16649 STRING_MULTIBYTE (elt
));
16654 else /* c == '%' */
16656 int percent_position
= offset
;
16658 /* Get the specified minimum width. Zero means
16661 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16662 field
= field
* 10 + c
- '0';
16664 /* Don't pad beyond the total padding allowed. */
16665 if (field_width
- n
> 0 && field
> field_width
- n
)
16666 field
= field_width
- n
;
16668 /* Note that either PRECISION <= 0 or N < PRECISION. */
16669 prec
= precision
- n
;
16672 n
+= display_mode_element (it
, depth
, field
, prec
,
16673 Vglobal_mode_string
, props
,
16678 int bytepos
, charpos
;
16679 unsigned char *spec
;
16681 bytepos
= percent_position
;
16682 charpos
= (STRING_MULTIBYTE (elt
)
16683 ? string_byte_to_char (elt
, bytepos
)
16687 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16689 switch (mode_line_target
)
16691 case MODE_LINE_NOPROP
:
16692 case MODE_LINE_TITLE
:
16693 n
+= store_mode_line_noprop (spec
, field
, prec
);
16695 case MODE_LINE_STRING
:
16697 int len
= strlen (spec
);
16698 Lisp_Object tem
= make_string (spec
, len
);
16699 props
= Ftext_properties_at (make_number (charpos
), elt
);
16700 /* Should only keep face property in props */
16701 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16704 case MODE_LINE_DISPLAY
:
16706 int nglyphs_before
, nwritten
;
16708 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16709 nwritten
= display_string (spec
, Qnil
, elt
,
16714 /* Assign to the glyphs written above the
16715 string where the `%x' came from, position
16719 struct glyph
*glyph
16720 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16724 for (i
= 0; i
< nwritten
; ++i
)
16726 glyph
[i
].object
= elt
;
16727 glyph
[i
].charpos
= charpos
;
16744 /* A symbol: process the value of the symbol recursively
16745 as if it appeared here directly. Avoid error if symbol void.
16746 Special case: if value of symbol is a string, output the string
16749 register Lisp_Object tem
;
16751 /* If the variable is not marked as risky to set
16752 then its contents are risky to use. */
16753 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16756 tem
= Fboundp (elt
);
16759 tem
= Fsymbol_value (elt
);
16760 /* If value is a string, output that string literally:
16761 don't check for % within it. */
16765 if (!EQ (tem
, elt
))
16767 /* Give up right away for nil or t. */
16777 register Lisp_Object car
, tem
;
16779 /* A cons cell: five distinct cases.
16780 If first element is :eval or :propertize, do something special.
16781 If first element is a string or a cons, process all the elements
16782 and effectively concatenate them.
16783 If first element is a negative number, truncate displaying cdr to
16784 at most that many characters. If positive, pad (with spaces)
16785 to at least that many characters.
16786 If first element is a symbol, process the cadr or caddr recursively
16787 according to whether the symbol's value is non-nil or nil. */
16789 if (EQ (car
, QCeval
))
16791 /* An element of the form (:eval FORM) means evaluate FORM
16792 and use the result as mode line elements. */
16797 if (CONSP (XCDR (elt
)))
16800 spec
= safe_eval (XCAR (XCDR (elt
)));
16801 n
+= display_mode_element (it
, depth
, field_width
- n
,
16802 precision
- n
, spec
, props
,
16806 else if (EQ (car
, QCpropertize
))
16808 /* An element of the form (:propertize ELT PROPS...)
16809 means display ELT but applying properties PROPS. */
16814 if (CONSP (XCDR (elt
)))
16815 n
+= display_mode_element (it
, depth
, field_width
- n
,
16816 precision
- n
, XCAR (XCDR (elt
)),
16817 XCDR (XCDR (elt
)), risky
);
16819 else if (SYMBOLP (car
))
16821 tem
= Fboundp (car
);
16825 /* elt is now the cdr, and we know it is a cons cell.
16826 Use its car if CAR has a non-nil value. */
16829 tem
= Fsymbol_value (car
);
16836 /* Symbol's value is nil (or symbol is unbound)
16837 Get the cddr of the original list
16838 and if possible find the caddr and use that. */
16842 else if (!CONSP (elt
))
16847 else if (INTEGERP (car
))
16849 register int lim
= XINT (car
);
16853 /* Negative int means reduce maximum width. */
16854 if (precision
<= 0)
16857 precision
= min (precision
, -lim
);
16861 /* Padding specified. Don't let it be more than
16862 current maximum. */
16864 lim
= min (precision
, lim
);
16866 /* If that's more padding than already wanted, queue it.
16867 But don't reduce padding already specified even if
16868 that is beyond the current truncation point. */
16869 field_width
= max (lim
, field_width
);
16873 else if (STRINGP (car
) || CONSP (car
))
16875 register int limit
= 50;
16876 /* Limit is to protect against circular lists. */
16879 && (precision
<= 0 || n
< precision
))
16881 n
+= display_mode_element (it
, depth
,
16882 /* Do padding only after the last
16883 element in the list. */
16884 (! CONSP (XCDR (elt
))
16887 precision
- n
, XCAR (elt
),
16897 elt
= build_string ("*invalid*");
16901 /* Pad to FIELD_WIDTH. */
16902 if (field_width
> 0 && n
< field_width
)
16904 switch (mode_line_target
)
16906 case MODE_LINE_NOPROP
:
16907 case MODE_LINE_TITLE
:
16908 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16910 case MODE_LINE_STRING
:
16911 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16913 case MODE_LINE_DISPLAY
:
16914 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16923 /* Store a mode-line string element in mode_line_string_list.
16925 If STRING is non-null, display that C string. Otherwise, the Lisp
16926 string LISP_STRING is displayed.
16928 FIELD_WIDTH is the minimum number of output glyphs to produce.
16929 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16930 with spaces. FIELD_WIDTH <= 0 means don't pad.
16932 PRECISION is the maximum number of characters to output from
16933 STRING. PRECISION <= 0 means don't truncate the string.
16935 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16936 properties to the string.
16938 PROPS are the properties to add to the string.
16939 The mode_line_string_face face property is always added to the string.
16943 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16945 Lisp_Object lisp_string
;
16954 if (string
!= NULL
)
16956 len
= strlen (string
);
16957 if (precision
> 0 && len
> precision
)
16959 lisp_string
= make_string (string
, len
);
16961 props
= mode_line_string_face_prop
;
16962 else if (!NILP (mode_line_string_face
))
16964 Lisp_Object face
= Fplist_get (props
, Qface
);
16965 props
= Fcopy_sequence (props
);
16967 face
= mode_line_string_face
;
16969 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16970 props
= Fplist_put (props
, Qface
, face
);
16972 Fadd_text_properties (make_number (0), make_number (len
),
16973 props
, lisp_string
);
16977 len
= XFASTINT (Flength (lisp_string
));
16978 if (precision
> 0 && len
> precision
)
16981 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16984 if (!NILP (mode_line_string_face
))
16988 props
= Ftext_properties_at (make_number (0), lisp_string
);
16989 face
= Fplist_get (props
, Qface
);
16991 face
= mode_line_string_face
;
16993 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16994 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16996 lisp_string
= Fcopy_sequence (lisp_string
);
16999 Fadd_text_properties (make_number (0), make_number (len
),
17000 props
, lisp_string
);
17005 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17009 if (field_width
> len
)
17011 field_width
-= len
;
17012 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17014 Fadd_text_properties (make_number (0), make_number (field_width
),
17015 props
, lisp_string
);
17016 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17024 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17026 doc
: /* Format a string out of a mode line format specification.
17027 First arg FORMAT specifies the mode line format (see `mode-line-format'
17028 for details) to use.
17030 Optional second arg FACE specifies the face property to put
17031 on all characters for which no face is specified.
17032 t means whatever face the window's mode line currently uses
17033 \(either `mode-line' or `mode-line-inactive', depending).
17034 nil means the default is no face property.
17035 If FACE is an integer, the value string has no text properties.
17037 Optional third and fourth args WINDOW and BUFFER specify the window
17038 and buffer to use as the context for the formatting (defaults
17039 are the selected window and the window's buffer). */)
17040 (format
, face
, window
, buffer
)
17041 Lisp_Object format
, face
, window
, buffer
;
17046 struct buffer
*old_buffer
= NULL
;
17048 int no_props
= INTEGERP (face
);
17049 int count
= SPECPDL_INDEX ();
17051 int string_start
= 0;
17054 window
= selected_window
;
17055 CHECK_WINDOW (window
);
17056 w
= XWINDOW (window
);
17059 buffer
= w
->buffer
;
17060 CHECK_BUFFER (buffer
);
17063 return build_string ("");
17071 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17072 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17076 face_id
= DEFAULT_FACE_ID
;
17078 if (XBUFFER (buffer
) != current_buffer
)
17079 old_buffer
= current_buffer
;
17081 /* Save things including mode_line_proptrans_alist,
17082 and set that to nil so that we don't alter the outer value. */
17083 record_unwind_protect (unwind_format_mode_line
,
17084 format_mode_line_unwind_data (old_buffer
, 1));
17085 mode_line_proptrans_alist
= Qnil
;
17088 set_buffer_internal_1 (XBUFFER (buffer
));
17090 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17094 mode_line_target
= MODE_LINE_NOPROP
;
17095 mode_line_string_face_prop
= Qnil
;
17096 mode_line_string_list
= Qnil
;
17097 string_start
= MODE_LINE_NOPROP_LEN (0);
17101 mode_line_target
= MODE_LINE_STRING
;
17102 mode_line_string_list
= Qnil
;
17103 mode_line_string_face
= face
;
17104 mode_line_string_face_prop
17105 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17108 push_frame_kboard (it
.f
);
17109 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17110 pop_frame_kboard ();
17114 len
= MODE_LINE_NOPROP_LEN (string_start
);
17115 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17119 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17120 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17121 make_string ("", 0));
17124 unbind_to (count
, Qnil
);
17128 /* Write a null-terminated, right justified decimal representation of
17129 the positive integer D to BUF using a minimal field width WIDTH. */
17132 pint2str (buf
, width
, d
)
17133 register char *buf
;
17134 register int width
;
17137 register char *p
= buf
;
17145 *p
++ = d
% 10 + '0';
17150 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17161 /* Write a null-terminated, right justified decimal and "human
17162 readable" representation of the nonnegative integer D to BUF using
17163 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17165 static const char power_letter
[] =
17179 pint2hrstr (buf
, width
, d
)
17184 /* We aim to represent the nonnegative integer D as
17185 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17188 /* -1 means: do not use TENTHS. */
17192 /* Length of QUOTIENT.TENTHS as a string. */
17198 if (1000 <= quotient
)
17200 /* Scale to the appropriate EXPONENT. */
17203 remainder
= quotient
% 1000;
17207 while (1000 <= quotient
);
17209 /* Round to nearest and decide whether to use TENTHS or not. */
17212 tenths
= remainder
/ 100;
17213 if (50 <= remainder
% 100)
17220 if (quotient
== 10)
17228 if (500 <= remainder
)
17230 if (quotient
< 999)
17241 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17242 if (tenths
== -1 && quotient
<= 99)
17249 p
= psuffix
= buf
+ max (width
, length
);
17251 /* Print EXPONENT. */
17253 *psuffix
++ = power_letter
[exponent
];
17256 /* Print TENTHS. */
17259 *--p
= '0' + tenths
;
17263 /* Print QUOTIENT. */
17266 int digit
= quotient
% 10;
17267 *--p
= '0' + digit
;
17269 while ((quotient
/= 10) != 0);
17271 /* Print leading spaces. */
17276 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17277 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17278 type of CODING_SYSTEM. Return updated pointer into BUF. */
17280 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17283 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17284 Lisp_Object coding_system
;
17285 register char *buf
;
17289 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17290 const unsigned char *eol_str
;
17292 /* The EOL conversion we are using. */
17293 Lisp_Object eoltype
;
17295 val
= Fget (coding_system
, Qcoding_system
);
17298 if (!VECTORP (val
)) /* Not yet decided. */
17303 eoltype
= eol_mnemonic_undecided
;
17304 /* Don't mention EOL conversion if it isn't decided. */
17308 Lisp_Object eolvalue
;
17310 eolvalue
= Fget (coding_system
, Qeol_type
);
17313 *buf
++ = XFASTINT (AREF (val
, 1));
17317 /* The EOL conversion that is normal on this system. */
17319 if (NILP (eolvalue
)) /* Not yet decided. */
17320 eoltype
= eol_mnemonic_undecided
;
17321 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17322 eoltype
= eol_mnemonic_undecided
;
17323 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17324 eoltype
= (XFASTINT (eolvalue
) == 0
17325 ? eol_mnemonic_unix
17326 : (XFASTINT (eolvalue
) == 1
17327 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17333 /* Mention the EOL conversion if it is not the usual one. */
17334 if (STRINGP (eoltype
))
17336 eol_str
= SDATA (eoltype
);
17337 eol_str_len
= SBYTES (eoltype
);
17339 else if (INTEGERP (eoltype
)
17340 && CHAR_VALID_P (XINT (eoltype
), 0))
17342 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17343 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17348 eol_str
= invalid_eol_type
;
17349 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17351 bcopy (eol_str
, buf
, eol_str_len
);
17352 buf
+= eol_str_len
;
17358 /* Return a string for the output of a mode line %-spec for window W,
17359 generated by character C. PRECISION >= 0 means don't return a
17360 string longer than that value. FIELD_WIDTH > 0 means pad the
17361 string returned with spaces to that value. Return 1 in *MULTIBYTE
17362 if the result is multibyte text.
17364 Note we operate on the current buffer for most purposes,
17365 the exception being w->base_line_pos. */
17367 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17370 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17373 int field_width
, precision
;
17377 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17378 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17379 struct buffer
*b
= current_buffer
;
17387 if (!NILP (b
->read_only
))
17389 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17394 /* This differs from %* only for a modified read-only buffer. */
17395 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17397 if (!NILP (b
->read_only
))
17402 /* This differs from %* in ignoring read-only-ness. */
17403 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17415 if (command_loop_level
> 5)
17417 p
= decode_mode_spec_buf
;
17418 for (i
= 0; i
< command_loop_level
; i
++)
17421 return decode_mode_spec_buf
;
17429 if (command_loop_level
> 5)
17431 p
= decode_mode_spec_buf
;
17432 for (i
= 0; i
< command_loop_level
; i
++)
17435 return decode_mode_spec_buf
;
17442 /* Let lots_of_dashes be a string of infinite length. */
17443 if (mode_line_target
== MODE_LINE_NOPROP
||
17444 mode_line_target
== MODE_LINE_STRING
)
17446 if (field_width
<= 0
17447 || field_width
> sizeof (lots_of_dashes
))
17449 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17450 decode_mode_spec_buf
[i
] = '-';
17451 decode_mode_spec_buf
[i
] = '\0';
17452 return decode_mode_spec_buf
;
17455 return lots_of_dashes
;
17464 int col
= (int) current_column (); /* iftc */
17465 w
->column_number_displayed
= make_number (col
);
17466 pint2str (decode_mode_spec_buf
, field_width
, col
);
17467 return decode_mode_spec_buf
;
17471 #ifndef SYSTEM_MALLOC
17473 if (NILP (Vmemory_full
))
17476 return "!MEM FULL! ";
17483 /* %F displays the frame name. */
17484 if (!NILP (f
->title
))
17485 return (char *) SDATA (f
->title
);
17486 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17487 return (char *) SDATA (f
->name
);
17496 int size
= ZV
- BEGV
;
17497 pint2str (decode_mode_spec_buf
, field_width
, size
);
17498 return decode_mode_spec_buf
;
17503 int size
= ZV
- BEGV
;
17504 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17505 return decode_mode_spec_buf
;
17510 int startpos
= XMARKER (w
->start
)->charpos
;
17511 int startpos_byte
= marker_byte_position (w
->start
);
17512 int line
, linepos
, linepos_byte
, topline
;
17514 int height
= WINDOW_TOTAL_LINES (w
);
17516 /* If we decided that this buffer isn't suitable for line numbers,
17517 don't forget that too fast. */
17518 if (EQ (w
->base_line_pos
, w
->buffer
))
17520 /* But do forget it, if the window shows a different buffer now. */
17521 else if (BUFFERP (w
->base_line_pos
))
17522 w
->base_line_pos
= Qnil
;
17524 /* If the buffer is very big, don't waste time. */
17525 if (INTEGERP (Vline_number_display_limit
)
17526 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17528 w
->base_line_pos
= Qnil
;
17529 w
->base_line_number
= Qnil
;
17533 if (!NILP (w
->base_line_number
)
17534 && !NILP (w
->base_line_pos
)
17535 && XFASTINT (w
->base_line_pos
) <= startpos
)
17537 line
= XFASTINT (w
->base_line_number
);
17538 linepos
= XFASTINT (w
->base_line_pos
);
17539 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17544 linepos
= BUF_BEGV (b
);
17545 linepos_byte
= BUF_BEGV_BYTE (b
);
17548 /* Count lines from base line to window start position. */
17549 nlines
= display_count_lines (linepos
, linepos_byte
,
17553 topline
= nlines
+ line
;
17555 /* Determine a new base line, if the old one is too close
17556 or too far away, or if we did not have one.
17557 "Too close" means it's plausible a scroll-down would
17558 go back past it. */
17559 if (startpos
== BUF_BEGV (b
))
17561 w
->base_line_number
= make_number (topline
);
17562 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17564 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17565 || linepos
== BUF_BEGV (b
))
17567 int limit
= BUF_BEGV (b
);
17568 int limit_byte
= BUF_BEGV_BYTE (b
);
17570 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17572 if (startpos
- distance
> limit
)
17574 limit
= startpos
- distance
;
17575 limit_byte
= CHAR_TO_BYTE (limit
);
17578 nlines
= display_count_lines (startpos
, startpos_byte
,
17580 - (height
* 2 + 30),
17582 /* If we couldn't find the lines we wanted within
17583 line_number_display_limit_width chars per line,
17584 give up on line numbers for this window. */
17585 if (position
== limit_byte
&& limit
== startpos
- distance
)
17587 w
->base_line_pos
= w
->buffer
;
17588 w
->base_line_number
= Qnil
;
17592 w
->base_line_number
= make_number (topline
- nlines
);
17593 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17596 /* Now count lines from the start pos to point. */
17597 nlines
= display_count_lines (startpos
, startpos_byte
,
17598 PT_BYTE
, PT
, &junk
);
17600 /* Record that we did display the line number. */
17601 line_number_displayed
= 1;
17603 /* Make the string to show. */
17604 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17605 return decode_mode_spec_buf
;
17608 char* p
= decode_mode_spec_buf
;
17609 int pad
= field_width
- 2;
17615 return decode_mode_spec_buf
;
17621 obj
= b
->mode_name
;
17625 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17631 int pos
= marker_position (w
->start
);
17632 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17634 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17636 if (pos
<= BUF_BEGV (b
))
17641 else if (pos
<= BUF_BEGV (b
))
17645 if (total
> 1000000)
17646 /* Do it differently for a large value, to avoid overflow. */
17647 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17649 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17650 /* We can't normally display a 3-digit number,
17651 so get us a 2-digit number that is close. */
17654 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17655 return decode_mode_spec_buf
;
17659 /* Display percentage of size above the bottom of the screen. */
17662 int toppos
= marker_position (w
->start
);
17663 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17664 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17666 if (botpos
>= BUF_ZV (b
))
17668 if (toppos
<= BUF_BEGV (b
))
17675 if (total
> 1000000)
17676 /* Do it differently for a large value, to avoid overflow. */
17677 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17679 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17680 /* We can't normally display a 3-digit number,
17681 so get us a 2-digit number that is close. */
17684 if (toppos
<= BUF_BEGV (b
))
17685 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17687 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17688 return decode_mode_spec_buf
;
17693 /* status of process */
17694 obj
= Fget_buffer_process (Fcurrent_buffer ());
17696 return "no process";
17697 #ifdef subprocesses
17698 obj
= Fsymbol_name (Fprocess_status (obj
));
17702 case 't': /* indicate TEXT or BINARY */
17703 #ifdef MODE_LINE_BINARY_TEXT
17704 return MODE_LINE_BINARY_TEXT (b
);
17710 /* coding-system (not including end-of-line format) */
17712 /* coding-system (including end-of-line type) */
17714 int eol_flag
= (c
== 'Z');
17715 char *p
= decode_mode_spec_buf
;
17717 if (! FRAME_WINDOW_P (f
))
17719 /* No need to mention EOL here--the terminal never needs
17720 to do EOL conversion. */
17721 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17722 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17724 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17727 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17728 #ifdef subprocesses
17729 obj
= Fget_buffer_process (Fcurrent_buffer ());
17730 if (PROCESSP (obj
))
17732 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17734 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17737 #endif /* subprocesses */
17740 return decode_mode_spec_buf
;
17746 *multibyte
= STRING_MULTIBYTE (obj
);
17747 return (char *) SDATA (obj
);
17754 /* Count up to COUNT lines starting from START / START_BYTE.
17755 But don't go beyond LIMIT_BYTE.
17756 Return the number of lines thus found (always nonnegative).
17758 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17761 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17762 int start
, start_byte
, limit_byte
, count
;
17765 register unsigned char *cursor
;
17766 unsigned char *base
;
17768 register int ceiling
;
17769 register unsigned char *ceiling_addr
;
17770 int orig_count
= count
;
17772 /* If we are not in selective display mode,
17773 check only for newlines. */
17774 int selective_display
= (!NILP (current_buffer
->selective_display
)
17775 && !INTEGERP (current_buffer
->selective_display
));
17779 while (start_byte
< limit_byte
)
17781 ceiling
= BUFFER_CEILING_OF (start_byte
);
17782 ceiling
= min (limit_byte
- 1, ceiling
);
17783 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17784 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17787 if (selective_display
)
17788 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17791 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17794 if (cursor
!= ceiling_addr
)
17798 start_byte
+= cursor
- base
+ 1;
17799 *byte_pos_ptr
= start_byte
;
17803 if (++cursor
== ceiling_addr
)
17809 start_byte
+= cursor
- base
;
17814 while (start_byte
> limit_byte
)
17816 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17817 ceiling
= max (limit_byte
, ceiling
);
17818 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17819 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17822 if (selective_display
)
17823 while (--cursor
!= ceiling_addr
17824 && *cursor
!= '\n' && *cursor
!= 015)
17827 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17830 if (cursor
!= ceiling_addr
)
17834 start_byte
+= cursor
- base
+ 1;
17835 *byte_pos_ptr
= start_byte
;
17836 /* When scanning backwards, we should
17837 not count the newline posterior to which we stop. */
17838 return - orig_count
- 1;
17844 /* Here we add 1 to compensate for the last decrement
17845 of CURSOR, which took it past the valid range. */
17846 start_byte
+= cursor
- base
+ 1;
17850 *byte_pos_ptr
= limit_byte
;
17853 return - orig_count
+ count
;
17854 return orig_count
- count
;
17860 /***********************************************************************
17862 ***********************************************************************/
17864 /* Display a NUL-terminated string, starting with index START.
17866 If STRING is non-null, display that C string. Otherwise, the Lisp
17867 string LISP_STRING is displayed.
17869 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17870 FACE_STRING. Display STRING or LISP_STRING with the face at
17871 FACE_STRING_POS in FACE_STRING:
17873 Display the string in the environment given by IT, but use the
17874 standard display table, temporarily.
17876 FIELD_WIDTH is the minimum number of output glyphs to produce.
17877 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17878 with spaces. If STRING has more characters, more than FIELD_WIDTH
17879 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17881 PRECISION is the maximum number of characters to output from
17882 STRING. PRECISION < 0 means don't truncate the string.
17884 This is roughly equivalent to printf format specifiers:
17886 FIELD_WIDTH PRECISION PRINTF
17887 ----------------------------------------
17893 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17894 display them, and < 0 means obey the current buffer's value of
17895 enable_multibyte_characters.
17897 Value is the number of columns displayed. */
17900 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17901 start
, it
, field_width
, precision
, max_x
, multibyte
)
17902 unsigned char *string
;
17903 Lisp_Object lisp_string
;
17904 Lisp_Object face_string
;
17905 int face_string_pos
;
17908 int field_width
, precision
, max_x
;
17911 int hpos_at_start
= it
->hpos
;
17912 int saved_face_id
= it
->face_id
;
17913 struct glyph_row
*row
= it
->glyph_row
;
17915 /* Initialize the iterator IT for iteration over STRING beginning
17916 with index START. */
17917 reseat_to_string (it
, string
, lisp_string
, start
,
17918 precision
, field_width
, multibyte
);
17920 /* If displaying STRING, set up the face of the iterator
17921 from LISP_STRING, if that's given. */
17922 if (STRINGP (face_string
))
17928 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17929 0, it
->region_beg_charpos
,
17930 it
->region_end_charpos
,
17931 &endptr
, it
->base_face_id
, 0);
17932 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17933 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17936 /* Set max_x to the maximum allowed X position. Don't let it go
17937 beyond the right edge of the window. */
17939 max_x
= it
->last_visible_x
;
17941 max_x
= min (max_x
, it
->last_visible_x
);
17943 /* Skip over display elements that are not visible. because IT->w is
17945 if (it
->current_x
< it
->first_visible_x
)
17946 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17947 MOVE_TO_POS
| MOVE_TO_X
);
17949 row
->ascent
= it
->max_ascent
;
17950 row
->height
= it
->max_ascent
+ it
->max_descent
;
17951 row
->phys_ascent
= it
->max_phys_ascent
;
17952 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17953 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17955 /* This condition is for the case that we are called with current_x
17956 past last_visible_x. */
17957 while (it
->current_x
< max_x
)
17959 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17961 /* Get the next display element. */
17962 if (!get_next_display_element (it
))
17965 /* Produce glyphs. */
17966 x_before
= it
->current_x
;
17967 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17968 PRODUCE_GLYPHS (it
);
17970 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17973 while (i
< nglyphs
)
17975 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17977 if (!it
->truncate_lines_p
17978 && x
+ glyph
->pixel_width
> max_x
)
17980 /* End of continued line or max_x reached. */
17981 if (CHAR_GLYPH_PADDING_P (*glyph
))
17983 /* A wide character is unbreakable. */
17984 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17985 it
->current_x
= x_before
;
17989 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17994 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17996 /* Glyph is at least partially visible. */
17998 if (x
< it
->first_visible_x
)
17999 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18003 /* Glyph is off the left margin of the display area.
18004 Should not happen. */
18008 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18009 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18010 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18011 row
->phys_height
= max (row
->phys_height
,
18012 it
->max_phys_ascent
+ it
->max_phys_descent
);
18013 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18014 it
->max_extra_line_spacing
);
18015 x
+= glyph
->pixel_width
;
18019 /* Stop if max_x reached. */
18023 /* Stop at line ends. */
18024 if (ITERATOR_AT_END_OF_LINE_P (it
))
18026 it
->continuation_lines_width
= 0;
18030 set_iterator_to_next (it
, 1);
18032 /* Stop if truncating at the right edge. */
18033 if (it
->truncate_lines_p
18034 && it
->current_x
>= it
->last_visible_x
)
18036 /* Add truncation mark, but don't do it if the line is
18037 truncated at a padding space. */
18038 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18040 if (!FRAME_WINDOW_P (it
->f
))
18044 if (it
->current_x
> it
->last_visible_x
)
18046 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18047 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18049 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18051 row
->used
[TEXT_AREA
] = i
;
18052 produce_special_glyphs (it
, IT_TRUNCATION
);
18055 produce_special_glyphs (it
, IT_TRUNCATION
);
18057 it
->glyph_row
->truncated_on_right_p
= 1;
18063 /* Maybe insert a truncation at the left. */
18064 if (it
->first_visible_x
18065 && IT_CHARPOS (*it
) > 0)
18067 if (!FRAME_WINDOW_P (it
->f
))
18068 insert_left_trunc_glyphs (it
);
18069 it
->glyph_row
->truncated_on_left_p
= 1;
18072 it
->face_id
= saved_face_id
;
18074 /* Value is number of columns displayed. */
18075 return it
->hpos
- hpos_at_start
;
18080 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18081 appears as an element of LIST or as the car of an element of LIST.
18082 If PROPVAL is a list, compare each element against LIST in that
18083 way, and return 1/2 if any element of PROPVAL is found in LIST.
18084 Otherwise return 0. This function cannot quit.
18085 The return value is 2 if the text is invisible but with an ellipsis
18086 and 1 if it's invisible and without an ellipsis. */
18089 invisible_p (propval
, list
)
18090 register Lisp_Object propval
;
18093 register Lisp_Object tail
, proptail
;
18095 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18097 register Lisp_Object tem
;
18099 if (EQ (propval
, tem
))
18101 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18102 return NILP (XCDR (tem
)) ? 1 : 2;
18105 if (CONSP (propval
))
18107 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18109 Lisp_Object propelt
;
18110 propelt
= XCAR (proptail
);
18111 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18113 register Lisp_Object tem
;
18115 if (EQ (propelt
, tem
))
18117 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18118 return NILP (XCDR (tem
)) ? 1 : 2;
18126 /* Calculate a width or height in pixels from a specification using
18127 the following elements:
18130 NUM - a (fractional) multiple of the default font width/height
18131 (NUM) - specifies exactly NUM pixels
18132 UNIT - a fixed number of pixels, see below.
18133 ELEMENT - size of a display element in pixels, see below.
18134 (NUM . SPEC) - equals NUM * SPEC
18135 (+ SPEC SPEC ...) - add pixel values
18136 (- SPEC SPEC ...) - subtract pixel values
18137 (- SPEC) - negate pixel value
18140 INT or FLOAT - a number constant
18141 SYMBOL - use symbol's (buffer local) variable binding.
18144 in - pixels per inch *)
18145 mm - pixels per 1/1000 meter *)
18146 cm - pixels per 1/100 meter *)
18147 width - width of current font in pixels.
18148 height - height of current font in pixels.
18150 *) using the ratio(s) defined in display-pixels-per-inch.
18154 left-fringe - left fringe width in pixels
18155 right-fringe - right fringe width in pixels
18157 left-margin - left margin width in pixels
18158 right-margin - right margin width in pixels
18160 scroll-bar - scroll-bar area width in pixels
18164 Pixels corresponding to 5 inches:
18167 Total width of non-text areas on left side of window (if scroll-bar is on left):
18168 '(space :width (+ left-fringe left-margin scroll-bar))
18170 Align to first text column (in header line):
18171 '(space :align-to 0)
18173 Align to middle of text area minus half the width of variable `my-image'
18174 containing a loaded image:
18175 '(space :align-to (0.5 . (- text my-image)))
18177 Width of left margin minus width of 1 character in the default font:
18178 '(space :width (- left-margin 1))
18180 Width of left margin minus width of 2 characters in the current font:
18181 '(space :width (- left-margin (2 . width)))
18183 Center 1 character over left-margin (in header line):
18184 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18186 Different ways to express width of left fringe plus left margin minus one pixel:
18187 '(space :width (- (+ left-fringe left-margin) (1)))
18188 '(space :width (+ left-fringe left-margin (- (1))))
18189 '(space :width (+ left-fringe left-margin (-1)))
18193 #define NUMVAL(X) \
18194 ((INTEGERP (X) || FLOATP (X)) \
18199 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18204 int width_p
, *align_to
;
18208 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18209 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18212 return OK_PIXELS (0);
18214 if (SYMBOLP (prop
))
18216 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18218 char *unit
= SDATA (SYMBOL_NAME (prop
));
18220 if (unit
[0] == 'i' && unit
[1] == 'n')
18222 else if (unit
[0] == 'm' && unit
[1] == 'm')
18224 else if (unit
[0] == 'c' && unit
[1] == 'm')
18231 #ifdef HAVE_WINDOW_SYSTEM
18232 if (FRAME_WINDOW_P (it
->f
)
18234 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18235 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18237 return OK_PIXELS (ppi
/ pixels
);
18240 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18241 || (CONSP (Vdisplay_pixels_per_inch
)
18243 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18244 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18246 return OK_PIXELS (ppi
/ pixels
);
18252 #ifdef HAVE_WINDOW_SYSTEM
18253 if (EQ (prop
, Qheight
))
18254 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18255 if (EQ (prop
, Qwidth
))
18256 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18258 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18259 return OK_PIXELS (1);
18262 if (EQ (prop
, Qtext
))
18263 return OK_PIXELS (width_p
18264 ? window_box_width (it
->w
, TEXT_AREA
)
18265 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18267 if (align_to
&& *align_to
< 0)
18270 if (EQ (prop
, Qleft
))
18271 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18272 if (EQ (prop
, Qright
))
18273 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18274 if (EQ (prop
, Qcenter
))
18275 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18276 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18277 if (EQ (prop
, Qleft_fringe
))
18278 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18279 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18280 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18281 if (EQ (prop
, Qright_fringe
))
18282 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18283 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18284 : window_box_right_offset (it
->w
, TEXT_AREA
));
18285 if (EQ (prop
, Qleft_margin
))
18286 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18287 if (EQ (prop
, Qright_margin
))
18288 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18289 if (EQ (prop
, Qscroll_bar
))
18290 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18292 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18293 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18294 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18299 if (EQ (prop
, Qleft_fringe
))
18300 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18301 if (EQ (prop
, Qright_fringe
))
18302 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18303 if (EQ (prop
, Qleft_margin
))
18304 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18305 if (EQ (prop
, Qright_margin
))
18306 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18307 if (EQ (prop
, Qscroll_bar
))
18308 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18311 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18314 if (INTEGERP (prop
) || FLOATP (prop
))
18316 int base_unit
= (width_p
18317 ? FRAME_COLUMN_WIDTH (it
->f
)
18318 : FRAME_LINE_HEIGHT (it
->f
));
18319 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18324 Lisp_Object car
= XCAR (prop
);
18325 Lisp_Object cdr
= XCDR (prop
);
18329 #ifdef HAVE_WINDOW_SYSTEM
18330 if (valid_image_p (prop
))
18332 int id
= lookup_image (it
->f
, prop
);
18333 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18335 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18338 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18344 while (CONSP (cdr
))
18346 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18347 font
, width_p
, align_to
))
18350 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18355 if (EQ (car
, Qminus
))
18357 return OK_PIXELS (pixels
);
18360 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18363 if (INTEGERP (car
) || FLOATP (car
))
18366 pixels
= XFLOATINT (car
);
18368 return OK_PIXELS (pixels
);
18369 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18370 font
, width_p
, align_to
))
18371 return OK_PIXELS (pixels
* fact
);
18382 /***********************************************************************
18384 ***********************************************************************/
18386 #ifdef HAVE_WINDOW_SYSTEM
18391 dump_glyph_string (s
)
18392 struct glyph_string
*s
;
18394 fprintf (stderr
, "glyph string\n");
18395 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18396 s
->x
, s
->y
, s
->width
, s
->height
);
18397 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18398 fprintf (stderr
, " hl = %d\n", s
->hl
);
18399 fprintf (stderr
, " left overhang = %d, right = %d\n",
18400 s
->left_overhang
, s
->right_overhang
);
18401 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18402 fprintf (stderr
, " extends to end of line = %d\n",
18403 s
->extends_to_end_of_line_p
);
18404 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18405 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18408 #endif /* GLYPH_DEBUG */
18410 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18411 of XChar2b structures for S; it can't be allocated in
18412 init_glyph_string because it must be allocated via `alloca'. W
18413 is the window on which S is drawn. ROW and AREA are the glyph row
18414 and area within the row from which S is constructed. START is the
18415 index of the first glyph structure covered by S. HL is a
18416 face-override for drawing S. */
18419 #define OPTIONAL_HDC(hdc) hdc,
18420 #define DECLARE_HDC(hdc) HDC hdc;
18421 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18422 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18425 #ifndef OPTIONAL_HDC
18426 #define OPTIONAL_HDC(hdc)
18427 #define DECLARE_HDC(hdc)
18428 #define ALLOCATE_HDC(hdc, f)
18429 #define RELEASE_HDC(hdc, f)
18433 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18434 struct glyph_string
*s
;
18438 struct glyph_row
*row
;
18439 enum glyph_row_area area
;
18441 enum draw_glyphs_face hl
;
18443 bzero (s
, sizeof *s
);
18445 s
->f
= XFRAME (w
->frame
);
18449 s
->display
= FRAME_X_DISPLAY (s
->f
);
18450 s
->window
= FRAME_X_WINDOW (s
->f
);
18451 s
->char2b
= char2b
;
18455 s
->first_glyph
= row
->glyphs
[area
] + start
;
18456 s
->height
= row
->height
;
18457 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18459 /* Display the internal border below the tool-bar window. */
18460 if (WINDOWP (s
->f
->tool_bar_window
)
18461 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18462 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18464 s
->ybase
= s
->y
+ row
->ascent
;
18468 /* Append the list of glyph strings with head H and tail T to the list
18469 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18472 append_glyph_string_lists (head
, tail
, h
, t
)
18473 struct glyph_string
**head
, **tail
;
18474 struct glyph_string
*h
, *t
;
18488 /* Prepend the list of glyph strings with head H and tail T to the
18489 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18493 prepend_glyph_string_lists (head
, tail
, h
, t
)
18494 struct glyph_string
**head
, **tail
;
18495 struct glyph_string
*h
, *t
;
18509 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18510 Set *HEAD and *TAIL to the resulting list. */
18513 append_glyph_string (head
, tail
, s
)
18514 struct glyph_string
**head
, **tail
;
18515 struct glyph_string
*s
;
18517 s
->next
= s
->prev
= NULL
;
18518 append_glyph_string_lists (head
, tail
, s
, s
);
18522 /* Get face and two-byte form of character glyph GLYPH on frame F.
18523 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18524 a pointer to a realized face that is ready for display. */
18526 static INLINE
struct face
*
18527 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18529 struct glyph
*glyph
;
18535 xassert (glyph
->type
== CHAR_GLYPH
);
18536 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18541 if (!glyph
->multibyte_p
)
18543 /* Unibyte case. We don't have to encode, but we have to make
18544 sure to use a face suitable for unibyte. */
18545 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18547 else if (glyph
->u
.ch
< 128)
18549 /* Case of ASCII in a face known to fit ASCII. */
18550 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18554 int c1
, c2
, charset
;
18556 /* Split characters into bytes. If c2 is -1 afterwards, C is
18557 really a one-byte character so that byte1 is zero. */
18558 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18560 STORE_XCHAR2B (char2b
, c1
, c2
);
18562 STORE_XCHAR2B (char2b
, 0, c1
);
18564 /* Maybe encode the character in *CHAR2B. */
18565 if (charset
!= CHARSET_ASCII
)
18567 struct font_info
*font_info
18568 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18571 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18575 /* Make sure X resources of the face are allocated. */
18576 xassert (face
!= NULL
);
18577 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18582 /* Fill glyph string S with composition components specified by S->cmp.
18584 FACES is an array of faces for all components of this composition.
18585 S->gidx is the index of the first component for S.
18587 OVERLAPS non-zero means S should draw the foreground only, and use
18588 its physical height for clipping. See also draw_glyphs.
18590 Value is the index of a component not in S. */
18593 fill_composite_glyph_string (s
, faces
, overlaps
)
18594 struct glyph_string
*s
;
18595 struct face
**faces
;
18602 s
->for_overlaps
= overlaps
;
18604 s
->face
= faces
[s
->gidx
];
18605 s
->font
= s
->face
->font
;
18606 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18608 /* For all glyphs of this composition, starting at the offset
18609 S->gidx, until we reach the end of the definition or encounter a
18610 glyph that requires the different face, add it to S. */
18612 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18615 /* All glyph strings for the same composition has the same width,
18616 i.e. the width set for the first component of the composition. */
18618 s
->width
= s
->first_glyph
->pixel_width
;
18620 /* If the specified font could not be loaded, use the frame's
18621 default font, but record the fact that we couldn't load it in
18622 the glyph string so that we can draw rectangles for the
18623 characters of the glyph string. */
18624 if (s
->font
== NULL
)
18626 s
->font_not_found_p
= 1;
18627 s
->font
= FRAME_FONT (s
->f
);
18630 /* Adjust base line for subscript/superscript text. */
18631 s
->ybase
+= s
->first_glyph
->voffset
;
18633 xassert (s
->face
&& s
->face
->gc
);
18635 /* This glyph string must always be drawn with 16-bit functions. */
18638 return s
->gidx
+ s
->nchars
;
18642 /* Fill glyph string S from a sequence of character glyphs.
18644 FACE_ID is the face id of the string. START is the index of the
18645 first glyph to consider, END is the index of the last + 1.
18646 OVERLAPS non-zero means S should draw the foreground only, and use
18647 its physical height for clipping. See also draw_glyphs.
18649 Value is the index of the first glyph not in S. */
18652 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18653 struct glyph_string
*s
;
18655 int start
, end
, overlaps
;
18657 struct glyph
*glyph
, *last
;
18659 int glyph_not_available_p
;
18661 xassert (s
->f
== XFRAME (s
->w
->frame
));
18662 xassert (s
->nchars
== 0);
18663 xassert (start
>= 0 && end
> start
);
18665 s
->for_overlaps
= overlaps
,
18666 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18667 last
= s
->row
->glyphs
[s
->area
] + end
;
18668 voffset
= glyph
->voffset
;
18670 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18672 while (glyph
< last
18673 && glyph
->type
== CHAR_GLYPH
18674 && glyph
->voffset
== voffset
18675 /* Same face id implies same font, nowadays. */
18676 && glyph
->face_id
== face_id
18677 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18681 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18682 s
->char2b
+ s
->nchars
,
18684 s
->two_byte_p
= two_byte_p
;
18686 xassert (s
->nchars
<= end
- start
);
18687 s
->width
+= glyph
->pixel_width
;
18691 s
->font
= s
->face
->font
;
18692 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18694 /* If the specified font could not be loaded, use the frame's font,
18695 but record the fact that we couldn't load it in
18696 S->font_not_found_p so that we can draw rectangles for the
18697 characters of the glyph string. */
18698 if (s
->font
== NULL
|| glyph_not_available_p
)
18700 s
->font_not_found_p
= 1;
18701 s
->font
= FRAME_FONT (s
->f
);
18704 /* Adjust base line for subscript/superscript text. */
18705 s
->ybase
+= voffset
;
18707 xassert (s
->face
&& s
->face
->gc
);
18708 return glyph
- s
->row
->glyphs
[s
->area
];
18712 /* Fill glyph string S from image glyph S->first_glyph. */
18715 fill_image_glyph_string (s
)
18716 struct glyph_string
*s
;
18718 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18719 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18721 s
->slice
= s
->first_glyph
->slice
;
18722 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18723 s
->font
= s
->face
->font
;
18724 s
->width
= s
->first_glyph
->pixel_width
;
18726 /* Adjust base line for subscript/superscript text. */
18727 s
->ybase
+= s
->first_glyph
->voffset
;
18731 /* Fill glyph string S from a sequence of stretch glyphs.
18733 ROW is the glyph row in which the glyphs are found, AREA is the
18734 area within the row. START is the index of the first glyph to
18735 consider, END is the index of the last + 1.
18737 Value is the index of the first glyph not in S. */
18740 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18741 struct glyph_string
*s
;
18742 struct glyph_row
*row
;
18743 enum glyph_row_area area
;
18746 struct glyph
*glyph
, *last
;
18747 int voffset
, face_id
;
18749 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18751 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18752 last
= s
->row
->glyphs
[s
->area
] + end
;
18753 face_id
= glyph
->face_id
;
18754 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18755 s
->font
= s
->face
->font
;
18756 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18757 s
->width
= glyph
->pixel_width
;
18759 voffset
= glyph
->voffset
;
18763 && glyph
->type
== STRETCH_GLYPH
18764 && glyph
->voffset
== voffset
18765 && glyph
->face_id
== face_id
);
18767 s
->width
+= glyph
->pixel_width
;
18769 /* Adjust base line for subscript/superscript text. */
18770 s
->ybase
+= voffset
;
18772 /* The case that face->gc == 0 is handled when drawing the glyph
18773 string by calling PREPARE_FACE_FOR_DISPLAY. */
18775 return glyph
- s
->row
->glyphs
[s
->area
];
18780 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18781 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18782 assumed to be zero. */
18785 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18786 struct glyph
*glyph
;
18790 *left
= *right
= 0;
18792 if (glyph
->type
== CHAR_GLYPH
)
18796 struct font_info
*font_info
;
18800 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18802 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18803 if (font
/* ++KFS: Should this be font_info ? */
18804 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18806 if (pcm
->rbearing
> pcm
->width
)
18807 *right
= pcm
->rbearing
- pcm
->width
;
18808 if (pcm
->lbearing
< 0)
18809 *left
= -pcm
->lbearing
;
18815 /* Return the index of the first glyph preceding glyph string S that
18816 is overwritten by S because of S's left overhang. Value is -1
18817 if no glyphs are overwritten. */
18820 left_overwritten (s
)
18821 struct glyph_string
*s
;
18825 if (s
->left_overhang
)
18828 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18829 int first
= s
->first_glyph
- glyphs
;
18831 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18832 x
-= glyphs
[i
].pixel_width
;
18843 /* Return the index of the first glyph preceding glyph string S that
18844 is overwriting S because of its right overhang. Value is -1 if no
18845 glyph in front of S overwrites S. */
18848 left_overwriting (s
)
18849 struct glyph_string
*s
;
18852 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18853 int first
= s
->first_glyph
- glyphs
;
18857 for (i
= first
- 1; i
>= 0; --i
)
18860 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18863 x
-= glyphs
[i
].pixel_width
;
18870 /* Return the index of the last glyph following glyph string S that is
18871 not overwritten by S because of S's right overhang. Value is -1 if
18872 no such glyph is found. */
18875 right_overwritten (s
)
18876 struct glyph_string
*s
;
18880 if (s
->right_overhang
)
18883 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18884 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18885 int end
= s
->row
->used
[s
->area
];
18887 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18888 x
+= glyphs
[i
].pixel_width
;
18897 /* Return the index of the last glyph following glyph string S that
18898 overwrites S because of its left overhang. Value is negative
18899 if no such glyph is found. */
18902 right_overwriting (s
)
18903 struct glyph_string
*s
;
18906 int end
= s
->row
->used
[s
->area
];
18907 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18908 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18912 for (i
= first
; i
< end
; ++i
)
18915 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18918 x
+= glyphs
[i
].pixel_width
;
18925 /* Get face and two-byte form of character C in face FACE_ID on frame
18926 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18927 means we want to display multibyte text. DISPLAY_P non-zero means
18928 make sure that X resources for the face returned are allocated.
18929 Value is a pointer to a realized face that is ready for display if
18930 DISPLAY_P is non-zero. */
18932 static INLINE
struct face
*
18933 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18937 int multibyte_p
, display_p
;
18939 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18943 /* Unibyte case. We don't have to encode, but we have to make
18944 sure to use a face suitable for unibyte. */
18945 STORE_XCHAR2B (char2b
, 0, c
);
18946 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18947 face
= FACE_FROM_ID (f
, face_id
);
18951 /* Case of ASCII in a face known to fit ASCII. */
18952 STORE_XCHAR2B (char2b
, 0, c
);
18956 int c1
, c2
, charset
;
18958 /* Split characters into bytes. If c2 is -1 afterwards, C is
18959 really a one-byte character so that byte1 is zero. */
18960 SPLIT_CHAR (c
, charset
, c1
, c2
);
18962 STORE_XCHAR2B (char2b
, c1
, c2
);
18964 STORE_XCHAR2B (char2b
, 0, c1
);
18966 /* Maybe encode the character in *CHAR2B. */
18967 if (face
->font
!= NULL
)
18969 struct font_info
*font_info
18970 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18972 rif
->encode_char (c
, char2b
, font_info
, 0);
18976 /* Make sure X resources of the face are allocated. */
18977 #ifdef HAVE_X_WINDOWS
18981 xassert (face
!= NULL
);
18982 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18989 /* Set background width of glyph string S. START is the index of the
18990 first glyph following S. LAST_X is the right-most x-position + 1
18991 in the drawing area. */
18994 set_glyph_string_background_width (s
, start
, last_x
)
18995 struct glyph_string
*s
;
18999 /* If the face of this glyph string has to be drawn to the end of
19000 the drawing area, set S->extends_to_end_of_line_p. */
19002 if (start
== s
->row
->used
[s
->area
]
19003 && s
->area
== TEXT_AREA
19004 && ((s
->row
->fill_line_p
19005 && (s
->hl
== DRAW_NORMAL_TEXT
19006 || s
->hl
== DRAW_IMAGE_RAISED
19007 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19008 || s
->hl
== DRAW_MOUSE_FACE
))
19009 s
->extends_to_end_of_line_p
= 1;
19011 /* If S extends its face to the end of the line, set its
19012 background_width to the distance to the right edge of the drawing
19014 if (s
->extends_to_end_of_line_p
)
19015 s
->background_width
= last_x
- s
->x
+ 1;
19017 s
->background_width
= s
->width
;
19021 /* Compute overhangs and x-positions for glyph string S and its
19022 predecessors, or successors. X is the starting x-position for S.
19023 BACKWARD_P non-zero means process predecessors. */
19026 compute_overhangs_and_x (s
, x
, backward_p
)
19027 struct glyph_string
*s
;
19035 if (rif
->compute_glyph_string_overhangs
)
19036 rif
->compute_glyph_string_overhangs (s
);
19046 if (rif
->compute_glyph_string_overhangs
)
19047 rif
->compute_glyph_string_overhangs (s
);
19057 /* The following macros are only called from draw_glyphs below.
19058 They reference the following parameters of that function directly:
19059 `w', `row', `area', and `overlap_p'
19060 as well as the following local variables:
19061 `s', `f', and `hdc' (in W32) */
19064 /* On W32, silently add local `hdc' variable to argument list of
19065 init_glyph_string. */
19066 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19067 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19069 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19070 init_glyph_string (s, char2b, w, row, area, start, hl)
19073 /* Add a glyph string for a stretch glyph to the list of strings
19074 between HEAD and TAIL. START is the index of the stretch glyph in
19075 row area AREA of glyph row ROW. END is the index of the last glyph
19076 in that glyph row area. X is the current output position assigned
19077 to the new glyph string constructed. HL overrides that face of the
19078 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19079 is the right-most x-position of the drawing area. */
19081 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19082 and below -- keep them on one line. */
19083 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19086 s = (struct glyph_string *) alloca (sizeof *s); \
19087 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19088 START = fill_stretch_glyph_string (s, row, area, START, END); \
19089 append_glyph_string (&HEAD, &TAIL, s); \
19095 /* Add a glyph string for an image glyph to the list of strings
19096 between HEAD and TAIL. START is the index of the image glyph in
19097 row area AREA of glyph row ROW. END is the index of the last glyph
19098 in that glyph row area. X is the current output position assigned
19099 to the new glyph string constructed. HL overrides that face of the
19100 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19101 is the right-most x-position of the drawing area. */
19103 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19106 s = (struct glyph_string *) alloca (sizeof *s); \
19107 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19108 fill_image_glyph_string (s); \
19109 append_glyph_string (&HEAD, &TAIL, s); \
19116 /* Add a glyph string for a sequence of character glyphs to the list
19117 of strings between HEAD and TAIL. START is the index of the first
19118 glyph in row area AREA of glyph row ROW that is part of the new
19119 glyph string. END is the index of the last glyph in that glyph row
19120 area. X is the current output position assigned to the new glyph
19121 string constructed. HL overrides that face of the glyph; e.g. it
19122 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19123 right-most x-position of the drawing area. */
19125 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19131 c = (row)->glyphs[area][START].u.ch; \
19132 face_id = (row)->glyphs[area][START].face_id; \
19134 s = (struct glyph_string *) alloca (sizeof *s); \
19135 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19136 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19137 append_glyph_string (&HEAD, &TAIL, s); \
19139 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19144 /* Add a glyph string for a composite sequence to the list of strings
19145 between HEAD and TAIL. START is the index of the first glyph in
19146 row area AREA of glyph row ROW that is part of the new glyph
19147 string. END is the index of the last glyph in that glyph row area.
19148 X is the current output position assigned to the new glyph string
19149 constructed. HL overrides that face of the glyph; e.g. it is
19150 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19151 x-position of the drawing area. */
19153 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19155 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19156 int face_id = (row)->glyphs[area][START].face_id; \
19157 struct face *base_face = FACE_FROM_ID (f, face_id); \
19158 struct composition *cmp = composition_table[cmp_id]; \
19159 int glyph_len = cmp->glyph_len; \
19161 struct face **faces; \
19162 struct glyph_string *first_s = NULL; \
19165 base_face = base_face->ascii_face; \
19166 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19167 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19168 /* At first, fill in `char2b' and `faces'. */ \
19169 for (n = 0; n < glyph_len; n++) \
19171 int c = COMPOSITION_GLYPH (cmp, n); \
19172 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19173 faces[n] = FACE_FROM_ID (f, this_face_id); \
19174 get_char_face_and_encoding (f, c, this_face_id, \
19175 char2b + n, 1, 1); \
19178 /* Make glyph_strings for each glyph sequence that is drawable by \
19179 the same face, and append them to HEAD/TAIL. */ \
19180 for (n = 0; n < cmp->glyph_len;) \
19182 s = (struct glyph_string *) alloca (sizeof *s); \
19183 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19184 append_glyph_string (&(HEAD), &(TAIL), s); \
19192 n = fill_composite_glyph_string (s, faces, overlaps); \
19200 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19201 of AREA of glyph row ROW on window W between indices START and END.
19202 HL overrides the face for drawing glyph strings, e.g. it is
19203 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19204 x-positions of the drawing area.
19206 This is an ugly monster macro construct because we must use alloca
19207 to allocate glyph strings (because draw_glyphs can be called
19208 asynchronously). */
19210 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19213 HEAD = TAIL = NULL; \
19214 while (START < END) \
19216 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19217 switch (first_glyph->type) \
19220 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19224 case COMPOSITE_GLYPH: \
19225 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19229 case STRETCH_GLYPH: \
19230 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19234 case IMAGE_GLYPH: \
19235 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19243 set_glyph_string_background_width (s, START, LAST_X); \
19250 /* Draw glyphs between START and END in AREA of ROW on window W,
19251 starting at x-position X. X is relative to AREA in W. HL is a
19252 face-override with the following meaning:
19254 DRAW_NORMAL_TEXT draw normally
19255 DRAW_CURSOR draw in cursor face
19256 DRAW_MOUSE_FACE draw in mouse face.
19257 DRAW_INVERSE_VIDEO draw in mode line face
19258 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19259 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19261 If OVERLAPS is non-zero, draw only the foreground of characters and
19262 clip to the physical height of ROW. Non-zero value also defines
19263 the overlapping part to be drawn:
19265 OVERLAPS_PRED overlap with preceding rows
19266 OVERLAPS_SUCC overlap with succeeding rows
19267 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19268 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19270 Value is the x-position reached, relative to AREA of W. */
19273 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19276 struct glyph_row
*row
;
19277 enum glyph_row_area area
;
19279 enum draw_glyphs_face hl
;
19282 struct glyph_string
*head
, *tail
;
19283 struct glyph_string
*s
;
19284 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19285 int last_x
, area_width
;
19288 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19291 ALLOCATE_HDC (hdc
, f
);
19293 /* Let's rather be paranoid than getting a SEGV. */
19294 end
= min (end
, row
->used
[area
]);
19295 start
= max (0, start
);
19296 start
= min (end
, start
);
19298 /* Translate X to frame coordinates. Set last_x to the right
19299 end of the drawing area. */
19300 if (row
->full_width_p
)
19302 /* X is relative to the left edge of W, without scroll bars
19304 x
+= WINDOW_LEFT_EDGE_X (w
);
19305 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19309 int area_left
= window_box_left (w
, area
);
19311 area_width
= window_box_width (w
, area
);
19312 last_x
= area_left
+ area_width
;
19315 /* Build a doubly-linked list of glyph_string structures between
19316 head and tail from what we have to draw. Note that the macro
19317 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19318 the reason we use a separate variable `i'. */
19320 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19322 x_reached
= tail
->x
+ tail
->background_width
;
19326 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19327 the row, redraw some glyphs in front or following the glyph
19328 strings built above. */
19329 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19332 struct glyph_string
*h
, *t
;
19334 /* Compute overhangs for all glyph strings. */
19335 if (rif
->compute_glyph_string_overhangs
)
19336 for (s
= head
; s
; s
= s
->next
)
19337 rif
->compute_glyph_string_overhangs (s
);
19339 /* Prepend glyph strings for glyphs in front of the first glyph
19340 string that are overwritten because of the first glyph
19341 string's left overhang. The background of all strings
19342 prepended must be drawn because the first glyph string
19344 i
= left_overwritten (head
);
19348 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19349 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19351 compute_overhangs_and_x (t
, head
->x
, 1);
19352 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19356 /* Prepend glyph strings for glyphs in front of the first glyph
19357 string that overwrite that glyph string because of their
19358 right overhang. For these strings, only the foreground must
19359 be drawn, because it draws over the glyph string at `head'.
19360 The background must not be drawn because this would overwrite
19361 right overhangs of preceding glyphs for which no glyph
19363 i
= left_overwriting (head
);
19367 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19368 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19369 for (s
= h
; s
; s
= s
->next
)
19370 s
->background_filled_p
= 1;
19371 compute_overhangs_and_x (t
, head
->x
, 1);
19372 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19375 /* Append glyphs strings for glyphs following the last glyph
19376 string tail that are overwritten by tail. The background of
19377 these strings has to be drawn because tail's foreground draws
19379 i
= right_overwritten (tail
);
19382 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19383 DRAW_NORMAL_TEXT
, x
, last_x
);
19384 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19385 append_glyph_string_lists (&head
, &tail
, h
, t
);
19389 /* Append glyph strings for glyphs following the last glyph
19390 string tail that overwrite tail. The foreground of such
19391 glyphs has to be drawn because it writes into the background
19392 of tail. The background must not be drawn because it could
19393 paint over the foreground of following glyphs. */
19394 i
= right_overwriting (tail
);
19398 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19399 DRAW_NORMAL_TEXT
, x
, last_x
);
19400 for (s
= h
; s
; s
= s
->next
)
19401 s
->background_filled_p
= 1;
19402 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19403 append_glyph_string_lists (&head
, &tail
, h
, t
);
19405 if (clip_head
|| clip_tail
)
19406 for (s
= head
; s
; s
= s
->next
)
19408 s
->clip_head
= clip_head
;
19409 s
->clip_tail
= clip_tail
;
19413 /* Draw all strings. */
19414 for (s
= head
; s
; s
= s
->next
)
19415 rif
->draw_glyph_string (s
);
19417 if (area
== TEXT_AREA
19418 && !row
->full_width_p
19419 /* When drawing overlapping rows, only the glyph strings'
19420 foreground is drawn, which doesn't erase a cursor
19424 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19425 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19426 : (tail
? tail
->x
+ tail
->background_width
: x
));
19428 int text_left
= window_box_left (w
, TEXT_AREA
);
19432 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19433 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19436 /* Value is the x-position up to which drawn, relative to AREA of W.
19437 This doesn't include parts drawn because of overhangs. */
19438 if (row
->full_width_p
)
19439 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19441 x_reached
-= window_box_left (w
, area
);
19443 RELEASE_HDC (hdc
, f
);
19448 /* Expand row matrix if too narrow. Don't expand if area
19451 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19453 if (!fonts_changed_p \
19454 && (it->glyph_row->glyphs[area] \
19455 < it->glyph_row->glyphs[area + 1])) \
19457 it->w->ncols_scale_factor++; \
19458 fonts_changed_p = 1; \
19462 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19463 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19469 struct glyph
*glyph
;
19470 enum glyph_row_area area
= it
->area
;
19472 xassert (it
->glyph_row
);
19473 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19475 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19476 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19478 glyph
->charpos
= CHARPOS (it
->position
);
19479 glyph
->object
= it
->object
;
19480 glyph
->pixel_width
= it
->pixel_width
;
19481 glyph
->ascent
= it
->ascent
;
19482 glyph
->descent
= it
->descent
;
19483 glyph
->voffset
= it
->voffset
;
19484 glyph
->type
= CHAR_GLYPH
;
19485 glyph
->multibyte_p
= it
->multibyte_p
;
19486 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19487 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19488 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19489 || it
->phys_descent
> it
->descent
);
19490 glyph
->padding_p
= 0;
19491 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19492 glyph
->face_id
= it
->face_id
;
19493 glyph
->u
.ch
= it
->char_to_display
;
19494 glyph
->slice
= null_glyph_slice
;
19495 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19496 ++it
->glyph_row
->used
[area
];
19499 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19502 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19503 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19506 append_composite_glyph (it
)
19509 struct glyph
*glyph
;
19510 enum glyph_row_area area
= it
->area
;
19512 xassert (it
->glyph_row
);
19514 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19515 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19517 glyph
->charpos
= CHARPOS (it
->position
);
19518 glyph
->object
= it
->object
;
19519 glyph
->pixel_width
= it
->pixel_width
;
19520 glyph
->ascent
= it
->ascent
;
19521 glyph
->descent
= it
->descent
;
19522 glyph
->voffset
= it
->voffset
;
19523 glyph
->type
= COMPOSITE_GLYPH
;
19524 glyph
->multibyte_p
= it
->multibyte_p
;
19525 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19526 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19527 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19528 || it
->phys_descent
> it
->descent
);
19529 glyph
->padding_p
= 0;
19530 glyph
->glyph_not_available_p
= 0;
19531 glyph
->face_id
= it
->face_id
;
19532 glyph
->u
.cmp_id
= it
->cmp_id
;
19533 glyph
->slice
= null_glyph_slice
;
19534 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19535 ++it
->glyph_row
->used
[area
];
19538 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19542 /* Change IT->ascent and IT->height according to the setting of
19546 take_vertical_position_into_account (it
)
19551 if (it
->voffset
< 0)
19552 /* Increase the ascent so that we can display the text higher
19554 it
->ascent
-= it
->voffset
;
19556 /* Increase the descent so that we can display the text lower
19558 it
->descent
+= it
->voffset
;
19563 /* Produce glyphs/get display metrics for the image IT is loaded with.
19564 See the description of struct display_iterator in dispextern.h for
19565 an overview of struct display_iterator. */
19568 produce_image_glyph (it
)
19574 struct glyph_slice slice
;
19576 xassert (it
->what
== IT_IMAGE
);
19578 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19580 /* Make sure X resources of the face is loaded. */
19581 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19583 if (it
->image_id
< 0)
19585 /* Fringe bitmap. */
19586 it
->ascent
= it
->phys_ascent
= 0;
19587 it
->descent
= it
->phys_descent
= 0;
19588 it
->pixel_width
= 0;
19593 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19595 /* Make sure X resources of the image is loaded. */
19596 prepare_image_for_display (it
->f
, img
);
19598 slice
.x
= slice
.y
= 0;
19599 slice
.width
= img
->width
;
19600 slice
.height
= img
->height
;
19602 if (INTEGERP (it
->slice
.x
))
19603 slice
.x
= XINT (it
->slice
.x
);
19604 else if (FLOATP (it
->slice
.x
))
19605 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19607 if (INTEGERP (it
->slice
.y
))
19608 slice
.y
= XINT (it
->slice
.y
);
19609 else if (FLOATP (it
->slice
.y
))
19610 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19612 if (INTEGERP (it
->slice
.width
))
19613 slice
.width
= XINT (it
->slice
.width
);
19614 else if (FLOATP (it
->slice
.width
))
19615 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19617 if (INTEGERP (it
->slice
.height
))
19618 slice
.height
= XINT (it
->slice
.height
);
19619 else if (FLOATP (it
->slice
.height
))
19620 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19622 if (slice
.x
>= img
->width
)
19623 slice
.x
= img
->width
;
19624 if (slice
.y
>= img
->height
)
19625 slice
.y
= img
->height
;
19626 if (slice
.x
+ slice
.width
>= img
->width
)
19627 slice
.width
= img
->width
- slice
.x
;
19628 if (slice
.y
+ slice
.height
> img
->height
)
19629 slice
.height
= img
->height
- slice
.y
;
19631 if (slice
.width
== 0 || slice
.height
== 0)
19634 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19636 it
->descent
= slice
.height
- glyph_ascent
;
19638 it
->descent
+= img
->vmargin
;
19639 if (slice
.y
+ slice
.height
== img
->height
)
19640 it
->descent
+= img
->vmargin
;
19641 it
->phys_descent
= it
->descent
;
19643 it
->pixel_width
= slice
.width
;
19645 it
->pixel_width
+= img
->hmargin
;
19646 if (slice
.x
+ slice
.width
== img
->width
)
19647 it
->pixel_width
+= img
->hmargin
;
19649 /* It's quite possible for images to have an ascent greater than
19650 their height, so don't get confused in that case. */
19651 if (it
->descent
< 0)
19654 #if 0 /* this breaks image tiling */
19655 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19656 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19657 if (face_ascent
> it
->ascent
)
19658 it
->ascent
= it
->phys_ascent
= face_ascent
;
19663 if (face
->box
!= FACE_NO_BOX
)
19665 if (face
->box_line_width
> 0)
19668 it
->ascent
+= face
->box_line_width
;
19669 if (slice
.y
+ slice
.height
== img
->height
)
19670 it
->descent
+= face
->box_line_width
;
19673 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19674 it
->pixel_width
+= abs (face
->box_line_width
);
19675 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19676 it
->pixel_width
+= abs (face
->box_line_width
);
19679 take_vertical_position_into_account (it
);
19683 struct glyph
*glyph
;
19684 enum glyph_row_area area
= it
->area
;
19686 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19687 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19689 glyph
->charpos
= CHARPOS (it
->position
);
19690 glyph
->object
= it
->object
;
19691 glyph
->pixel_width
= it
->pixel_width
;
19692 glyph
->ascent
= glyph_ascent
;
19693 glyph
->descent
= it
->descent
;
19694 glyph
->voffset
= it
->voffset
;
19695 glyph
->type
= IMAGE_GLYPH
;
19696 glyph
->multibyte_p
= it
->multibyte_p
;
19697 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19698 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19699 glyph
->overlaps_vertically_p
= 0;
19700 glyph
->padding_p
= 0;
19701 glyph
->glyph_not_available_p
= 0;
19702 glyph
->face_id
= it
->face_id
;
19703 glyph
->u
.img_id
= img
->id
;
19704 glyph
->slice
= slice
;
19705 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19706 ++it
->glyph_row
->used
[area
];
19709 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19714 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19715 of the glyph, WIDTH and HEIGHT are the width and height of the
19716 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19719 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19721 Lisp_Object object
;
19725 struct glyph
*glyph
;
19726 enum glyph_row_area area
= it
->area
;
19728 xassert (ascent
>= 0 && ascent
<= height
);
19730 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19731 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19733 glyph
->charpos
= CHARPOS (it
->position
);
19734 glyph
->object
= object
;
19735 glyph
->pixel_width
= width
;
19736 glyph
->ascent
= ascent
;
19737 glyph
->descent
= height
- ascent
;
19738 glyph
->voffset
= it
->voffset
;
19739 glyph
->type
= STRETCH_GLYPH
;
19740 glyph
->multibyte_p
= it
->multibyte_p
;
19741 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19742 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19743 glyph
->overlaps_vertically_p
= 0;
19744 glyph
->padding_p
= 0;
19745 glyph
->glyph_not_available_p
= 0;
19746 glyph
->face_id
= it
->face_id
;
19747 glyph
->u
.stretch
.ascent
= ascent
;
19748 glyph
->u
.stretch
.height
= height
;
19749 glyph
->slice
= null_glyph_slice
;
19750 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19751 ++it
->glyph_row
->used
[area
];
19754 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19758 /* Produce a stretch glyph for iterator IT. IT->object is the value
19759 of the glyph property displayed. The value must be a list
19760 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19763 1. `:width WIDTH' specifies that the space should be WIDTH *
19764 canonical char width wide. WIDTH may be an integer or floating
19767 2. `:relative-width FACTOR' specifies that the width of the stretch
19768 should be computed from the width of the first character having the
19769 `glyph' property, and should be FACTOR times that width.
19771 3. `:align-to HPOS' specifies that the space should be wide enough
19772 to reach HPOS, a value in canonical character units.
19774 Exactly one of the above pairs must be present.
19776 4. `:height HEIGHT' specifies that the height of the stretch produced
19777 should be HEIGHT, measured in canonical character units.
19779 5. `:relative-height FACTOR' specifies that the height of the
19780 stretch should be FACTOR times the height of the characters having
19781 the glyph property.
19783 Either none or exactly one of 4 or 5 must be present.
19785 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19786 of the stretch should be used for the ascent of the stretch.
19787 ASCENT must be in the range 0 <= ASCENT <= 100. */
19790 produce_stretch_glyph (it
)
19793 /* (space :width WIDTH :height HEIGHT ...) */
19794 Lisp_Object prop
, plist
;
19795 int width
= 0, height
= 0, align_to
= -1;
19796 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19799 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19800 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19802 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19804 /* List should start with `space'. */
19805 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19806 plist
= XCDR (it
->object
);
19808 /* Compute the width of the stretch. */
19809 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19810 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19812 /* Absolute width `:width WIDTH' specified and valid. */
19813 zero_width_ok_p
= 1;
19816 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19819 /* Relative width `:relative-width FACTOR' specified and valid.
19820 Compute the width of the characters having the `glyph'
19823 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19826 if (it
->multibyte_p
)
19828 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19829 - IT_BYTEPOS (*it
));
19830 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19833 it2
.c
= *p
, it2
.len
= 1;
19835 it2
.glyph_row
= NULL
;
19836 it2
.what
= IT_CHARACTER
;
19837 x_produce_glyphs (&it2
);
19838 width
= NUMVAL (prop
) * it2
.pixel_width
;
19840 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19841 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19843 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19844 align_to
= (align_to
< 0
19846 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19847 else if (align_to
< 0)
19848 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19849 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19850 zero_width_ok_p
= 1;
19853 /* Nothing specified -> width defaults to canonical char width. */
19854 width
= FRAME_COLUMN_WIDTH (it
->f
);
19856 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19859 /* Compute height. */
19860 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19861 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19864 zero_height_ok_p
= 1;
19866 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19868 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19870 height
= FONT_HEIGHT (font
);
19872 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19875 /* Compute percentage of height used for ascent. If
19876 `:ascent ASCENT' is present and valid, use that. Otherwise,
19877 derive the ascent from the font in use. */
19878 if (prop
= Fplist_get (plist
, QCascent
),
19879 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19880 ascent
= height
* NUMVAL (prop
) / 100.0;
19881 else if (!NILP (prop
)
19882 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19883 ascent
= min (max (0, (int)tem
), height
);
19885 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19887 if (width
> 0 && !it
->truncate_lines_p
19888 && it
->current_x
+ width
> it
->last_visible_x
)
19889 width
= it
->last_visible_x
- it
->current_x
- 1;
19891 if (width
> 0 && height
> 0 && it
->glyph_row
)
19893 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19894 if (!STRINGP (object
))
19895 object
= it
->w
->buffer
;
19896 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19899 it
->pixel_width
= width
;
19900 it
->ascent
= it
->phys_ascent
= ascent
;
19901 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19902 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19904 take_vertical_position_into_account (it
);
19907 /* Get line-height and line-spacing property at point.
19908 If line-height has format (HEIGHT TOTAL), return TOTAL
19909 in TOTAL_HEIGHT. */
19912 get_line_height_property (it
, prop
)
19916 Lisp_Object position
;
19918 if (STRINGP (it
->object
))
19919 position
= make_number (IT_STRING_CHARPOS (*it
));
19920 else if (BUFFERP (it
->object
))
19921 position
= make_number (IT_CHARPOS (*it
));
19925 return Fget_char_property (position
, prop
, it
->object
);
19928 /* Calculate line-height and line-spacing properties.
19929 An integer value specifies explicit pixel value.
19930 A float value specifies relative value to current face height.
19931 A cons (float . face-name) specifies relative value to
19932 height of specified face font.
19934 Returns height in pixels, or nil. */
19938 calc_line_height_property (it
, val
, font
, boff
, override
)
19942 int boff
, override
;
19944 Lisp_Object face_name
= Qnil
;
19945 int ascent
, descent
, height
;
19947 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19952 face_name
= XCAR (val
);
19954 if (!NUMBERP (val
))
19955 val
= make_number (1);
19956 if (NILP (face_name
))
19958 height
= it
->ascent
+ it
->descent
;
19963 if (NILP (face_name
))
19965 font
= FRAME_FONT (it
->f
);
19966 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19968 else if (EQ (face_name
, Qt
))
19976 struct font_info
*font_info
;
19978 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19980 return make_number (-1);
19982 face
= FACE_FROM_ID (it
->f
, face_id
);
19985 return make_number (-1);
19987 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19988 boff
= font_info
->baseline_offset
;
19989 if (font_info
->vertical_centering
)
19990 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19993 ascent
= FONT_BASE (font
) + boff
;
19994 descent
= FONT_DESCENT (font
) - boff
;
19998 it
->override_ascent
= ascent
;
19999 it
->override_descent
= descent
;
20000 it
->override_boff
= boff
;
20003 height
= ascent
+ descent
;
20007 height
= (int)(XFLOAT_DATA (val
) * height
);
20008 else if (INTEGERP (val
))
20009 height
*= XINT (val
);
20011 return make_number (height
);
20016 Produce glyphs/get display metrics for the display element IT is
20017 loaded with. See the description of struct it in dispextern.h
20018 for an overview of struct it. */
20021 x_produce_glyphs (it
)
20024 int extra_line_spacing
= it
->extra_line_spacing
;
20026 it
->glyph_not_available_p
= 0;
20028 if (it
->what
== IT_CHARACTER
)
20032 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20034 int font_not_found_p
;
20035 struct font_info
*font_info
;
20036 int boff
; /* baseline offset */
20037 /* We may change it->multibyte_p upon unibyte<->multibyte
20038 conversion. So, save the current value now and restore it
20041 Note: It seems that we don't have to record multibyte_p in
20042 struct glyph because the character code itself tells if or
20043 not the character is multibyte. Thus, in the future, we must
20044 consider eliminating the field `multibyte_p' in the struct
20046 int saved_multibyte_p
= it
->multibyte_p
;
20048 /* Maybe translate single-byte characters to multibyte, or the
20050 it
->char_to_display
= it
->c
;
20051 if (!ASCII_BYTE_P (it
->c
))
20053 if (unibyte_display_via_language_environment
20054 && SINGLE_BYTE_CHAR_P (it
->c
)
20056 || !NILP (Vnonascii_translation_table
)))
20058 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20059 it
->multibyte_p
= 1;
20060 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20061 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20063 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20064 && !it
->multibyte_p
)
20066 it
->multibyte_p
= 1;
20067 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20068 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20072 /* Get font to use. Encode IT->char_to_display. */
20073 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20074 &char2b
, it
->multibyte_p
, 0);
20077 /* When no suitable font found, use the default font. */
20078 font_not_found_p
= font
== NULL
;
20079 if (font_not_found_p
)
20081 font
= FRAME_FONT (it
->f
);
20082 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20087 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20088 boff
= font_info
->baseline_offset
;
20089 if (font_info
->vertical_centering
)
20090 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20093 if (it
->char_to_display
>= ' '
20094 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20096 /* Either unibyte or ASCII. */
20101 pcm
= rif
->per_char_metric (font
, &char2b
,
20102 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20104 if (it
->override_ascent
>= 0)
20106 it
->ascent
= it
->override_ascent
;
20107 it
->descent
= it
->override_descent
;
20108 boff
= it
->override_boff
;
20112 it
->ascent
= FONT_BASE (font
) + boff
;
20113 it
->descent
= FONT_DESCENT (font
) - boff
;
20118 it
->phys_ascent
= pcm
->ascent
+ boff
;
20119 it
->phys_descent
= pcm
->descent
- boff
;
20120 it
->pixel_width
= pcm
->width
;
20124 it
->glyph_not_available_p
= 1;
20125 it
->phys_ascent
= it
->ascent
;
20126 it
->phys_descent
= it
->descent
;
20127 it
->pixel_width
= FONT_WIDTH (font
);
20130 if (it
->constrain_row_ascent_descent_p
)
20132 if (it
->descent
> it
->max_descent
)
20134 it
->ascent
+= it
->descent
- it
->max_descent
;
20135 it
->descent
= it
->max_descent
;
20137 if (it
->ascent
> it
->max_ascent
)
20139 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20140 it
->ascent
= it
->max_ascent
;
20142 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20143 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20144 extra_line_spacing
= 0;
20147 /* If this is a space inside a region of text with
20148 `space-width' property, change its width. */
20149 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20151 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20153 /* If face has a box, add the box thickness to the character
20154 height. If character has a box line to the left and/or
20155 right, add the box line width to the character's width. */
20156 if (face
->box
!= FACE_NO_BOX
)
20158 int thick
= face
->box_line_width
;
20162 it
->ascent
+= thick
;
20163 it
->descent
+= thick
;
20168 if (it
->start_of_box_run_p
)
20169 it
->pixel_width
+= thick
;
20170 if (it
->end_of_box_run_p
)
20171 it
->pixel_width
+= thick
;
20174 /* If face has an overline, add the height of the overline
20175 (1 pixel) and a 1 pixel margin to the character height. */
20176 if (face
->overline_p
)
20179 if (it
->constrain_row_ascent_descent_p
)
20181 if (it
->ascent
> it
->max_ascent
)
20182 it
->ascent
= it
->max_ascent
;
20183 if (it
->descent
> it
->max_descent
)
20184 it
->descent
= it
->max_descent
;
20187 take_vertical_position_into_account (it
);
20189 /* If we have to actually produce glyphs, do it. */
20194 /* Translate a space with a `space-width' property
20195 into a stretch glyph. */
20196 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20197 / FONT_HEIGHT (font
));
20198 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20199 it
->ascent
+ it
->descent
, ascent
);
20204 /* If characters with lbearing or rbearing are displayed
20205 in this line, record that fact in a flag of the
20206 glyph row. This is used to optimize X output code. */
20207 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20208 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20211 else if (it
->char_to_display
== '\n')
20213 /* A newline has no width but we need the height of the line.
20214 But if previous part of the line set a height, don't
20215 increase that height */
20217 Lisp_Object height
;
20218 Lisp_Object total_height
= Qnil
;
20220 it
->override_ascent
= -1;
20221 it
->pixel_width
= 0;
20224 height
= get_line_height_property(it
, Qline_height
);
20225 /* Split (line-height total-height) list */
20227 && CONSP (XCDR (height
))
20228 && NILP (XCDR (XCDR (height
))))
20230 total_height
= XCAR (XCDR (height
));
20231 height
= XCAR (height
);
20233 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20235 if (it
->override_ascent
>= 0)
20237 it
->ascent
= it
->override_ascent
;
20238 it
->descent
= it
->override_descent
;
20239 boff
= it
->override_boff
;
20243 it
->ascent
= FONT_BASE (font
) + boff
;
20244 it
->descent
= FONT_DESCENT (font
) - boff
;
20247 if (EQ (height
, Qt
))
20249 if (it
->descent
> it
->max_descent
)
20251 it
->ascent
+= it
->descent
- it
->max_descent
;
20252 it
->descent
= it
->max_descent
;
20254 if (it
->ascent
> it
->max_ascent
)
20256 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20257 it
->ascent
= it
->max_ascent
;
20259 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20260 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20261 it
->constrain_row_ascent_descent_p
= 1;
20262 extra_line_spacing
= 0;
20266 Lisp_Object spacing
;
20268 it
->phys_ascent
= it
->ascent
;
20269 it
->phys_descent
= it
->descent
;
20271 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20272 && face
->box
!= FACE_NO_BOX
20273 && face
->box_line_width
> 0)
20275 it
->ascent
+= face
->box_line_width
;
20276 it
->descent
+= face
->box_line_width
;
20279 && XINT (height
) > it
->ascent
+ it
->descent
)
20280 it
->ascent
= XINT (height
) - it
->descent
;
20282 if (!NILP (total_height
))
20283 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20286 spacing
= get_line_height_property(it
, Qline_spacing
);
20287 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20289 if (INTEGERP (spacing
))
20291 extra_line_spacing
= XINT (spacing
);
20292 if (!NILP (total_height
))
20293 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20297 else if (it
->char_to_display
== '\t')
20299 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20300 int x
= it
->current_x
+ it
->continuation_lines_width
;
20301 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20303 /* If the distance from the current position to the next tab
20304 stop is less than a space character width, use the
20305 tab stop after that. */
20306 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20307 next_tab_x
+= tab_width
;
20309 it
->pixel_width
= next_tab_x
- x
;
20311 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20312 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20316 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20317 it
->ascent
+ it
->descent
, it
->ascent
);
20322 /* A multi-byte character. Assume that the display width of the
20323 character is the width of the character multiplied by the
20324 width of the font. */
20326 /* If we found a font, this font should give us the right
20327 metrics. If we didn't find a font, use the frame's
20328 default font and calculate the width of the character
20329 from the charset width; this is what old redisplay code
20332 pcm
= rif
->per_char_metric (font
, &char2b
,
20333 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20335 if (font_not_found_p
|| !pcm
)
20337 int charset
= CHAR_CHARSET (it
->char_to_display
);
20339 it
->glyph_not_available_p
= 1;
20340 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20341 * CHARSET_WIDTH (charset
));
20342 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20343 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20347 it
->pixel_width
= pcm
->width
;
20348 it
->phys_ascent
= pcm
->ascent
+ boff
;
20349 it
->phys_descent
= pcm
->descent
- boff
;
20351 && (pcm
->lbearing
< 0
20352 || pcm
->rbearing
> pcm
->width
))
20353 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20356 it
->ascent
= FONT_BASE (font
) + boff
;
20357 it
->descent
= FONT_DESCENT (font
) - boff
;
20358 if (face
->box
!= FACE_NO_BOX
)
20360 int thick
= face
->box_line_width
;
20364 it
->ascent
+= thick
;
20365 it
->descent
+= thick
;
20370 if (it
->start_of_box_run_p
)
20371 it
->pixel_width
+= thick
;
20372 if (it
->end_of_box_run_p
)
20373 it
->pixel_width
+= thick
;
20376 /* If face has an overline, add the height of the overline
20377 (1 pixel) and a 1 pixel margin to the character height. */
20378 if (face
->overline_p
)
20381 take_vertical_position_into_account (it
);
20386 it
->multibyte_p
= saved_multibyte_p
;
20388 else if (it
->what
== IT_COMPOSITION
)
20390 /* Note: A composition is represented as one glyph in the
20391 glyph matrix. There are no padding glyphs. */
20394 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20396 int font_not_found_p
;
20397 struct font_info
*font_info
;
20398 int boff
; /* baseline offset */
20399 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20401 /* Maybe translate single-byte characters to multibyte. */
20402 it
->char_to_display
= it
->c
;
20403 if (unibyte_display_via_language_environment
20404 && SINGLE_BYTE_CHAR_P (it
->c
)
20407 && !NILP (Vnonascii_translation_table
))))
20409 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20412 /* Get face and font to use. Encode IT->char_to_display. */
20413 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20414 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20415 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20416 &char2b
, it
->multibyte_p
, 0);
20419 /* When no suitable font found, use the default font. */
20420 font_not_found_p
= font
== NULL
;
20421 if (font_not_found_p
)
20423 font
= FRAME_FONT (it
->f
);
20424 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20429 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20430 boff
= font_info
->baseline_offset
;
20431 if (font_info
->vertical_centering
)
20432 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20435 /* There are no padding glyphs, so there is only one glyph to
20436 produce for the composition. Important is that pixel_width,
20437 ascent and descent are the values of what is drawn by
20438 draw_glyphs (i.e. the values of the overall glyphs composed). */
20441 /* If we have not yet calculated pixel size data of glyphs of
20442 the composition for the current face font, calculate them
20443 now. Theoretically, we have to check all fonts for the
20444 glyphs, but that requires much time and memory space. So,
20445 here we check only the font of the first glyph. This leads
20446 to incorrect display very rarely, and C-l (recenter) can
20447 correct the display anyway. */
20448 if (cmp
->font
!= (void *) font
)
20450 /* Ascent and descent of the font of the first character of
20451 this composition (adjusted by baseline offset). Ascent
20452 and descent of overall glyphs should not be less than
20453 them respectively. */
20454 int font_ascent
= FONT_BASE (font
) + boff
;
20455 int font_descent
= FONT_DESCENT (font
) - boff
;
20456 /* Bounding box of the overall glyphs. */
20457 int leftmost
, rightmost
, lowest
, highest
;
20458 int i
, width
, ascent
, descent
;
20460 cmp
->font
= (void *) font
;
20462 /* Initialize the bounding box. */
20464 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20465 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20467 width
= pcm
->width
;
20468 ascent
= pcm
->ascent
;
20469 descent
= pcm
->descent
;
20473 width
= FONT_WIDTH (font
);
20474 ascent
= FONT_BASE (font
);
20475 descent
= FONT_DESCENT (font
);
20479 lowest
= - descent
+ boff
;
20480 highest
= ascent
+ boff
;
20484 && font_info
->default_ascent
20485 && CHAR_TABLE_P (Vuse_default_ascent
)
20486 && !NILP (Faref (Vuse_default_ascent
,
20487 make_number (it
->char_to_display
))))
20488 highest
= font_info
->default_ascent
+ boff
;
20490 /* Draw the first glyph at the normal position. It may be
20491 shifted to right later if some other glyphs are drawn at
20493 cmp
->offsets
[0] = 0;
20494 cmp
->offsets
[1] = boff
;
20496 /* Set cmp->offsets for the remaining glyphs. */
20497 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20499 int left
, right
, btm
, top
;
20500 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20501 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20503 face
= FACE_FROM_ID (it
->f
, face_id
);
20504 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20505 &char2b
, it
->multibyte_p
, 0);
20509 font
= FRAME_FONT (it
->f
);
20510 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20516 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20517 boff
= font_info
->baseline_offset
;
20518 if (font_info
->vertical_centering
)
20519 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20523 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20524 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20526 width
= pcm
->width
;
20527 ascent
= pcm
->ascent
;
20528 descent
= pcm
->descent
;
20532 width
= FONT_WIDTH (font
);
20537 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20539 /* Relative composition with or without
20540 alternate chars. */
20541 left
= (leftmost
+ rightmost
- width
) / 2;
20542 btm
= - descent
+ boff
;
20543 if (font_info
&& font_info
->relative_compose
20544 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20545 || NILP (Faref (Vignore_relative_composition
,
20546 make_number (ch
)))))
20549 if (- descent
>= font_info
->relative_compose
)
20550 /* One extra pixel between two glyphs. */
20552 else if (ascent
<= 0)
20553 /* One extra pixel between two glyphs. */
20554 btm
= lowest
- 1 - ascent
- descent
;
20559 /* A composition rule is specified by an integer
20560 value that encodes global and new reference
20561 points (GREF and NREF). GREF and NREF are
20562 specified by numbers as below:
20564 0---1---2 -- ascent
20568 9--10--11 -- center
20570 ---3---4---5--- baseline
20572 6---7---8 -- descent
20574 int rule
= COMPOSITION_RULE (cmp
, i
);
20575 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20577 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20578 grefx
= gref
% 3, nrefx
= nref
% 3;
20579 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20582 + grefx
* (rightmost
- leftmost
) / 2
20583 - nrefx
* width
/ 2);
20584 btm
= ((grefy
== 0 ? highest
20586 : grefy
== 2 ? lowest
20587 : (highest
+ lowest
) / 2)
20588 - (nrefy
== 0 ? ascent
+ descent
20589 : nrefy
== 1 ? descent
- boff
20591 : (ascent
+ descent
) / 2));
20594 cmp
->offsets
[i
* 2] = left
;
20595 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20597 /* Update the bounding box of the overall glyphs. */
20598 right
= left
+ width
;
20599 top
= btm
+ descent
+ ascent
;
20600 if (left
< leftmost
)
20602 if (right
> rightmost
)
20610 /* If there are glyphs whose x-offsets are negative,
20611 shift all glyphs to the right and make all x-offsets
20615 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20616 cmp
->offsets
[i
* 2] -= leftmost
;
20617 rightmost
-= leftmost
;
20620 cmp
->pixel_width
= rightmost
;
20621 cmp
->ascent
= highest
;
20622 cmp
->descent
= - lowest
;
20623 if (cmp
->ascent
< font_ascent
)
20624 cmp
->ascent
= font_ascent
;
20625 if (cmp
->descent
< font_descent
)
20626 cmp
->descent
= font_descent
;
20629 it
->pixel_width
= cmp
->pixel_width
;
20630 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20631 it
->descent
= it
->phys_descent
= cmp
->descent
;
20633 if (face
->box
!= FACE_NO_BOX
)
20635 int thick
= face
->box_line_width
;
20639 it
->ascent
+= thick
;
20640 it
->descent
+= thick
;
20645 if (it
->start_of_box_run_p
)
20646 it
->pixel_width
+= thick
;
20647 if (it
->end_of_box_run_p
)
20648 it
->pixel_width
+= thick
;
20651 /* If face has an overline, add the height of the overline
20652 (1 pixel) and a 1 pixel margin to the character height. */
20653 if (face
->overline_p
)
20656 take_vertical_position_into_account (it
);
20659 append_composite_glyph (it
);
20661 else if (it
->what
== IT_IMAGE
)
20662 produce_image_glyph (it
);
20663 else if (it
->what
== IT_STRETCH
)
20664 produce_stretch_glyph (it
);
20666 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20667 because this isn't true for images with `:ascent 100'. */
20668 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20669 if (it
->area
== TEXT_AREA
)
20670 it
->current_x
+= it
->pixel_width
;
20672 if (extra_line_spacing
> 0)
20674 it
->descent
+= extra_line_spacing
;
20675 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20676 it
->max_extra_line_spacing
= extra_line_spacing
;
20679 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20680 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20681 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20682 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20686 Output LEN glyphs starting at START at the nominal cursor position.
20687 Advance the nominal cursor over the text. The global variable
20688 updated_window contains the window being updated, updated_row is
20689 the glyph row being updated, and updated_area is the area of that
20690 row being updated. */
20693 x_write_glyphs (start
, len
)
20694 struct glyph
*start
;
20699 xassert (updated_window
&& updated_row
);
20702 /* Write glyphs. */
20704 hpos
= start
- updated_row
->glyphs
[updated_area
];
20705 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20706 updated_row
, updated_area
,
20708 DRAW_NORMAL_TEXT
, 0);
20710 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20711 if (updated_area
== TEXT_AREA
20712 && updated_window
->phys_cursor_on_p
20713 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20714 && updated_window
->phys_cursor
.hpos
>= hpos
20715 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20716 updated_window
->phys_cursor_on_p
= 0;
20720 /* Advance the output cursor. */
20721 output_cursor
.hpos
+= len
;
20722 output_cursor
.x
= x
;
20727 Insert LEN glyphs from START at the nominal cursor position. */
20730 x_insert_glyphs (start
, len
)
20731 struct glyph
*start
;
20736 int line_height
, shift_by_width
, shifted_region_width
;
20737 struct glyph_row
*row
;
20738 struct glyph
*glyph
;
20739 int frame_x
, frame_y
, hpos
;
20741 xassert (updated_window
&& updated_row
);
20743 w
= updated_window
;
20744 f
= XFRAME (WINDOW_FRAME (w
));
20746 /* Get the height of the line we are in. */
20748 line_height
= row
->height
;
20750 /* Get the width of the glyphs to insert. */
20751 shift_by_width
= 0;
20752 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20753 shift_by_width
+= glyph
->pixel_width
;
20755 /* Get the width of the region to shift right. */
20756 shifted_region_width
= (window_box_width (w
, updated_area
)
20761 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20762 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20764 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20765 line_height
, shift_by_width
);
20767 /* Write the glyphs. */
20768 hpos
= start
- row
->glyphs
[updated_area
];
20769 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20771 DRAW_NORMAL_TEXT
, 0);
20773 /* Advance the output cursor. */
20774 output_cursor
.hpos
+= len
;
20775 output_cursor
.x
+= shift_by_width
;
20781 Erase the current text line from the nominal cursor position
20782 (inclusive) to pixel column TO_X (exclusive). The idea is that
20783 everything from TO_X onward is already erased.
20785 TO_X is a pixel position relative to updated_area of
20786 updated_window. TO_X == -1 means clear to the end of this area. */
20789 x_clear_end_of_line (to_x
)
20793 struct window
*w
= updated_window
;
20794 int max_x
, min_y
, max_y
;
20795 int from_x
, from_y
, to_y
;
20797 xassert (updated_window
&& updated_row
);
20798 f
= XFRAME (w
->frame
);
20800 if (updated_row
->full_width_p
)
20801 max_x
= WINDOW_TOTAL_WIDTH (w
);
20803 max_x
= window_box_width (w
, updated_area
);
20804 max_y
= window_text_bottom_y (w
);
20806 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20807 of window. For TO_X > 0, truncate to end of drawing area. */
20813 to_x
= min (to_x
, max_x
);
20815 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20817 /* Notice if the cursor will be cleared by this operation. */
20818 if (!updated_row
->full_width_p
)
20819 notice_overwritten_cursor (w
, updated_area
,
20820 output_cursor
.x
, -1,
20822 MATRIX_ROW_BOTTOM_Y (updated_row
));
20824 from_x
= output_cursor
.x
;
20826 /* Translate to frame coordinates. */
20827 if (updated_row
->full_width_p
)
20829 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20830 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20834 int area_left
= window_box_left (w
, updated_area
);
20835 from_x
+= area_left
;
20839 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20840 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20841 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20843 /* Prevent inadvertently clearing to end of the X window. */
20844 if (to_x
> from_x
&& to_y
> from_y
)
20847 rif
->clear_frame_area (f
, from_x
, from_y
,
20848 to_x
- from_x
, to_y
- from_y
);
20853 #endif /* HAVE_WINDOW_SYSTEM */
20857 /***********************************************************************
20859 ***********************************************************************/
20861 /* Value is the internal representation of the specified cursor type
20862 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20863 of the bar cursor. */
20865 static enum text_cursor_kinds
20866 get_specified_cursor_type (arg
, width
)
20870 enum text_cursor_kinds type
;
20875 if (EQ (arg
, Qbox
))
20876 return FILLED_BOX_CURSOR
;
20878 if (EQ (arg
, Qhollow
))
20879 return HOLLOW_BOX_CURSOR
;
20881 if (EQ (arg
, Qbar
))
20888 && EQ (XCAR (arg
), Qbar
)
20889 && INTEGERP (XCDR (arg
))
20890 && XINT (XCDR (arg
)) >= 0)
20892 *width
= XINT (XCDR (arg
));
20896 if (EQ (arg
, Qhbar
))
20899 return HBAR_CURSOR
;
20903 && EQ (XCAR (arg
), Qhbar
)
20904 && INTEGERP (XCDR (arg
))
20905 && XINT (XCDR (arg
)) >= 0)
20907 *width
= XINT (XCDR (arg
));
20908 return HBAR_CURSOR
;
20911 /* Treat anything unknown as "hollow box cursor".
20912 It was bad to signal an error; people have trouble fixing
20913 .Xdefaults with Emacs, when it has something bad in it. */
20914 type
= HOLLOW_BOX_CURSOR
;
20919 /* Set the default cursor types for specified frame. */
20921 set_frame_cursor_types (f
, arg
)
20928 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20929 FRAME_CURSOR_WIDTH (f
) = width
;
20931 /* By default, set up the blink-off state depending on the on-state. */
20933 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20936 FRAME_BLINK_OFF_CURSOR (f
)
20937 = get_specified_cursor_type (XCDR (tem
), &width
);
20938 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20941 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20945 /* Return the cursor we want to be displayed in window W. Return
20946 width of bar/hbar cursor through WIDTH arg. Return with
20947 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20948 (i.e. if the `system caret' should track this cursor).
20950 In a mini-buffer window, we want the cursor only to appear if we
20951 are reading input from this window. For the selected window, we
20952 want the cursor type given by the frame parameter or buffer local
20953 setting of cursor-type. If explicitly marked off, draw no cursor.
20954 In all other cases, we want a hollow box cursor. */
20956 static enum text_cursor_kinds
20957 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20959 struct glyph
*glyph
;
20961 int *active_cursor
;
20963 struct frame
*f
= XFRAME (w
->frame
);
20964 struct buffer
*b
= XBUFFER (w
->buffer
);
20965 int cursor_type
= DEFAULT_CURSOR
;
20966 Lisp_Object alt_cursor
;
20967 int non_selected
= 0;
20969 *active_cursor
= 1;
20972 if (cursor_in_echo_area
20973 && FRAME_HAS_MINIBUF_P (f
)
20974 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20976 if (w
== XWINDOW (echo_area_window
))
20978 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
20980 *width
= FRAME_CURSOR_WIDTH (f
);
20981 return FRAME_DESIRED_CURSOR (f
);
20984 return get_specified_cursor_type (b
->cursor_type
, width
);
20987 *active_cursor
= 0;
20991 /* Nonselected window or nonselected frame. */
20992 else if (w
!= XWINDOW (f
->selected_window
)
20993 #ifdef HAVE_WINDOW_SYSTEM
20994 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20998 *active_cursor
= 0;
21000 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21006 /* Never display a cursor in a window in which cursor-type is nil. */
21007 if (NILP (b
->cursor_type
))
21010 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21013 alt_cursor
= b
->cursor_in_non_selected_windows
;
21014 return get_specified_cursor_type (alt_cursor
, width
);
21017 /* Get the normal cursor type for this window. */
21018 if (EQ (b
->cursor_type
, Qt
))
21020 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21021 *width
= FRAME_CURSOR_WIDTH (f
);
21024 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21026 /* Use normal cursor if not blinked off. */
21027 if (!w
->cursor_off_p
)
21029 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
21030 if (cursor_type
== FILLED_BOX_CURSOR
)
21031 cursor_type
= HOLLOW_BOX_CURSOR
;
21033 return cursor_type
;
21036 /* Cursor is blinked off, so determine how to "toggle" it. */
21038 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21039 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21040 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21042 /* Then see if frame has specified a specific blink off cursor type. */
21043 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21045 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21046 return FRAME_BLINK_OFF_CURSOR (f
);
21050 /* Some people liked having a permanently visible blinking cursor,
21051 while others had very strong opinions against it. So it was
21052 decided to remove it. KFS 2003-09-03 */
21054 /* Finally perform built-in cursor blinking:
21055 filled box <-> hollow box
21056 wide [h]bar <-> narrow [h]bar
21057 narrow [h]bar <-> no cursor
21058 other type <-> no cursor */
21060 if (cursor_type
== FILLED_BOX_CURSOR
)
21061 return HOLLOW_BOX_CURSOR
;
21063 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21066 return cursor_type
;
21074 #ifdef HAVE_WINDOW_SYSTEM
21076 /* Notice when the text cursor of window W has been completely
21077 overwritten by a drawing operation that outputs glyphs in AREA
21078 starting at X0 and ending at X1 in the line starting at Y0 and
21079 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21080 the rest of the line after X0 has been written. Y coordinates
21081 are window-relative. */
21084 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21086 enum glyph_row_area area
;
21087 int x0
, y0
, x1
, y1
;
21089 int cx0
, cx1
, cy0
, cy1
;
21090 struct glyph_row
*row
;
21092 if (!w
->phys_cursor_on_p
)
21094 if (area
!= TEXT_AREA
)
21097 if (w
->phys_cursor
.vpos
< 0
21098 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21099 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21100 !(row
->enabled_p
&& row
->displays_text_p
)))
21103 if (row
->cursor_in_fringe_p
)
21105 row
->cursor_in_fringe_p
= 0;
21106 draw_fringe_bitmap (w
, row
, 0);
21107 w
->phys_cursor_on_p
= 0;
21111 cx0
= w
->phys_cursor
.x
;
21112 cx1
= cx0
+ w
->phys_cursor_width
;
21113 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21116 /* The cursor image will be completely removed from the
21117 screen if the output area intersects the cursor area in
21118 y-direction. When we draw in [y0 y1[, and some part of
21119 the cursor is at y < y0, that part must have been drawn
21120 before. When scrolling, the cursor is erased before
21121 actually scrolling, so we don't come here. When not
21122 scrolling, the rows above the old cursor row must have
21123 changed, and in this case these rows must have written
21124 over the cursor image.
21126 Likewise if part of the cursor is below y1, with the
21127 exception of the cursor being in the first blank row at
21128 the buffer and window end because update_text_area
21129 doesn't draw that row. (Except when it does, but
21130 that's handled in update_text_area.) */
21132 cy0
= w
->phys_cursor
.y
;
21133 cy1
= cy0
+ w
->phys_cursor_height
;
21134 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21137 w
->phys_cursor_on_p
= 0;
21140 #endif /* HAVE_WINDOW_SYSTEM */
21143 /************************************************************************
21145 ************************************************************************/
21147 #ifdef HAVE_WINDOW_SYSTEM
21150 Fix the display of area AREA of overlapping row ROW in window W
21151 with respect to the overlapping part OVERLAPS. */
21154 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21156 struct glyph_row
*row
;
21157 enum glyph_row_area area
;
21165 for (i
= 0; i
< row
->used
[area
];)
21167 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21169 int start
= i
, start_x
= x
;
21173 x
+= row
->glyphs
[area
][i
].pixel_width
;
21176 while (i
< row
->used
[area
]
21177 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21179 draw_glyphs (w
, start_x
, row
, area
,
21181 DRAW_NORMAL_TEXT
, overlaps
);
21185 x
+= row
->glyphs
[area
][i
].pixel_width
;
21195 Draw the cursor glyph of window W in glyph row ROW. See the
21196 comment of draw_glyphs for the meaning of HL. */
21199 draw_phys_cursor_glyph (w
, row
, hl
)
21201 struct glyph_row
*row
;
21202 enum draw_glyphs_face hl
;
21204 /* If cursor hpos is out of bounds, don't draw garbage. This can
21205 happen in mini-buffer windows when switching between echo area
21206 glyphs and mini-buffer. */
21207 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21209 int on_p
= w
->phys_cursor_on_p
;
21211 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21212 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21214 w
->phys_cursor_on_p
= on_p
;
21216 if (hl
== DRAW_CURSOR
)
21217 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21218 /* When we erase the cursor, and ROW is overlapped by other
21219 rows, make sure that these overlapping parts of other rows
21221 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21223 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21225 if (row
> w
->current_matrix
->rows
21226 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21227 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21228 OVERLAPS_ERASED_CURSOR
);
21230 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21231 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21232 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21233 OVERLAPS_ERASED_CURSOR
);
21240 Erase the image of a cursor of window W from the screen. */
21243 erase_phys_cursor (w
)
21246 struct frame
*f
= XFRAME (w
->frame
);
21247 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21248 int hpos
= w
->phys_cursor
.hpos
;
21249 int vpos
= w
->phys_cursor
.vpos
;
21250 int mouse_face_here_p
= 0;
21251 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21252 struct glyph_row
*cursor_row
;
21253 struct glyph
*cursor_glyph
;
21254 enum draw_glyphs_face hl
;
21256 /* No cursor displayed or row invalidated => nothing to do on the
21258 if (w
->phys_cursor_type
== NO_CURSOR
)
21259 goto mark_cursor_off
;
21261 /* VPOS >= active_glyphs->nrows means that window has been resized.
21262 Don't bother to erase the cursor. */
21263 if (vpos
>= active_glyphs
->nrows
)
21264 goto mark_cursor_off
;
21266 /* If row containing cursor is marked invalid, there is nothing we
21268 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21269 if (!cursor_row
->enabled_p
)
21270 goto mark_cursor_off
;
21272 /* If line spacing is > 0, old cursor may only be partially visible in
21273 window after split-window. So adjust visible height. */
21274 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21275 window_text_bottom_y (w
) - cursor_row
->y
);
21277 /* If row is completely invisible, don't attempt to delete a cursor which
21278 isn't there. This can happen if cursor is at top of a window, and
21279 we switch to a buffer with a header line in that window. */
21280 if (cursor_row
->visible_height
<= 0)
21281 goto mark_cursor_off
;
21283 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21284 if (cursor_row
->cursor_in_fringe_p
)
21286 cursor_row
->cursor_in_fringe_p
= 0;
21287 draw_fringe_bitmap (w
, cursor_row
, 0);
21288 goto mark_cursor_off
;
21291 /* This can happen when the new row is shorter than the old one.
21292 In this case, either draw_glyphs or clear_end_of_line
21293 should have cleared the cursor. Note that we wouldn't be
21294 able to erase the cursor in this case because we don't have a
21295 cursor glyph at hand. */
21296 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21297 goto mark_cursor_off
;
21299 /* If the cursor is in the mouse face area, redisplay that when
21300 we clear the cursor. */
21301 if (! NILP (dpyinfo
->mouse_face_window
)
21302 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21303 && (vpos
> dpyinfo
->mouse_face_beg_row
21304 || (vpos
== dpyinfo
->mouse_face_beg_row
21305 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21306 && (vpos
< dpyinfo
->mouse_face_end_row
21307 || (vpos
== dpyinfo
->mouse_face_end_row
21308 && hpos
< dpyinfo
->mouse_face_end_col
))
21309 /* Don't redraw the cursor's spot in mouse face if it is at the
21310 end of a line (on a newline). The cursor appears there, but
21311 mouse highlighting does not. */
21312 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21313 mouse_face_here_p
= 1;
21315 /* Maybe clear the display under the cursor. */
21316 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21319 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21322 cursor_glyph
= get_phys_cursor_glyph (w
);
21323 if (cursor_glyph
== NULL
)
21324 goto mark_cursor_off
;
21326 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21327 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21328 width
= min (cursor_glyph
->pixel_width
,
21329 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21331 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21334 /* Erase the cursor by redrawing the character underneath it. */
21335 if (mouse_face_here_p
)
21336 hl
= DRAW_MOUSE_FACE
;
21338 hl
= DRAW_NORMAL_TEXT
;
21339 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21342 w
->phys_cursor_on_p
= 0;
21343 w
->phys_cursor_type
= NO_CURSOR
;
21348 Display or clear cursor of window W. If ON is zero, clear the
21349 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21350 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21353 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21355 int on
, hpos
, vpos
, x
, y
;
21357 struct frame
*f
= XFRAME (w
->frame
);
21358 int new_cursor_type
;
21359 int new_cursor_width
;
21361 struct glyph_row
*glyph_row
;
21362 struct glyph
*glyph
;
21364 /* This is pointless on invisible frames, and dangerous on garbaged
21365 windows and frames; in the latter case, the frame or window may
21366 be in the midst of changing its size, and x and y may be off the
21368 if (! FRAME_VISIBLE_P (f
)
21369 || FRAME_GARBAGED_P (f
)
21370 || vpos
>= w
->current_matrix
->nrows
21371 || hpos
>= w
->current_matrix
->matrix_w
)
21374 /* If cursor is off and we want it off, return quickly. */
21375 if (!on
&& !w
->phys_cursor_on_p
)
21378 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21379 /* If cursor row is not enabled, we don't really know where to
21380 display the cursor. */
21381 if (!glyph_row
->enabled_p
)
21383 w
->phys_cursor_on_p
= 0;
21388 if (!glyph_row
->exact_window_width_line_p
21389 || hpos
< glyph_row
->used
[TEXT_AREA
])
21390 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21392 xassert (interrupt_input_blocked
);
21394 /* Set new_cursor_type to the cursor we want to be displayed. */
21395 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21396 &new_cursor_width
, &active_cursor
);
21398 /* If cursor is currently being shown and we don't want it to be or
21399 it is in the wrong place, or the cursor type is not what we want,
21401 if (w
->phys_cursor_on_p
21403 || w
->phys_cursor
.x
!= x
21404 || w
->phys_cursor
.y
!= y
21405 || new_cursor_type
!= w
->phys_cursor_type
21406 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21407 && new_cursor_width
!= w
->phys_cursor_width
)))
21408 erase_phys_cursor (w
);
21410 /* Don't check phys_cursor_on_p here because that flag is only set
21411 to zero in some cases where we know that the cursor has been
21412 completely erased, to avoid the extra work of erasing the cursor
21413 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21414 still not be visible, or it has only been partly erased. */
21417 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21418 w
->phys_cursor_height
= glyph_row
->height
;
21420 /* Set phys_cursor_.* before x_draw_.* is called because some
21421 of them may need the information. */
21422 w
->phys_cursor
.x
= x
;
21423 w
->phys_cursor
.y
= glyph_row
->y
;
21424 w
->phys_cursor
.hpos
= hpos
;
21425 w
->phys_cursor
.vpos
= vpos
;
21428 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21429 new_cursor_type
, new_cursor_width
,
21430 on
, active_cursor
);
21434 /* Switch the display of W's cursor on or off, according to the value
21438 update_window_cursor (w
, on
)
21442 /* Don't update cursor in windows whose frame is in the process
21443 of being deleted. */
21444 if (w
->current_matrix
)
21447 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21448 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21454 /* Call update_window_cursor with parameter ON_P on all leaf windows
21455 in the window tree rooted at W. */
21458 update_cursor_in_window_tree (w
, on_p
)
21464 if (!NILP (w
->hchild
))
21465 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21466 else if (!NILP (w
->vchild
))
21467 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21469 update_window_cursor (w
, on_p
);
21471 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21477 Display the cursor on window W, or clear it, according to ON_P.
21478 Don't change the cursor's position. */
21481 x_update_cursor (f
, on_p
)
21485 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21490 Clear the cursor of window W to background color, and mark the
21491 cursor as not shown. This is used when the text where the cursor
21492 is is about to be rewritten. */
21498 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21499 update_window_cursor (w
, 0);
21504 Display the active region described by mouse_face_* according to DRAW. */
21507 show_mouse_face (dpyinfo
, draw
)
21508 Display_Info
*dpyinfo
;
21509 enum draw_glyphs_face draw
;
21511 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21512 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21514 if (/* If window is in the process of being destroyed, don't bother
21516 w
->current_matrix
!= NULL
21517 /* Don't update mouse highlight if hidden */
21518 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21519 /* Recognize when we are called to operate on rows that don't exist
21520 anymore. This can happen when a window is split. */
21521 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21523 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21524 struct glyph_row
*row
, *first
, *last
;
21526 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21527 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21529 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21531 int start_hpos
, end_hpos
, start_x
;
21533 /* For all but the first row, the highlight starts at column 0. */
21536 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21537 start_x
= dpyinfo
->mouse_face_beg_x
;
21546 end_hpos
= dpyinfo
->mouse_face_end_col
;
21549 end_hpos
= row
->used
[TEXT_AREA
];
21550 if (draw
== DRAW_NORMAL_TEXT
)
21551 row
->fill_line_p
= 1; /* Clear to end of line */
21554 if (end_hpos
> start_hpos
)
21556 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21557 start_hpos
, end_hpos
,
21561 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21565 /* When we've written over the cursor, arrange for it to
21566 be displayed again. */
21567 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21570 display_and_set_cursor (w
, 1,
21571 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21572 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21577 /* Change the mouse cursor. */
21578 if (draw
== DRAW_NORMAL_TEXT
)
21579 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21580 else if (draw
== DRAW_MOUSE_FACE
)
21581 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21583 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21587 Clear out the mouse-highlighted active region.
21588 Redraw it un-highlighted first. Value is non-zero if mouse
21589 face was actually drawn unhighlighted. */
21592 clear_mouse_face (dpyinfo
)
21593 Display_Info
*dpyinfo
;
21597 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21599 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21603 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21604 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21605 dpyinfo
->mouse_face_window
= Qnil
;
21606 dpyinfo
->mouse_face_overlay
= Qnil
;
21612 Non-zero if physical cursor of window W is within mouse face. */
21615 cursor_in_mouse_face_p (w
)
21618 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21619 int in_mouse_face
= 0;
21621 if (WINDOWP (dpyinfo
->mouse_face_window
)
21622 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21624 int hpos
= w
->phys_cursor
.hpos
;
21625 int vpos
= w
->phys_cursor
.vpos
;
21627 if (vpos
>= dpyinfo
->mouse_face_beg_row
21628 && vpos
<= dpyinfo
->mouse_face_end_row
21629 && (vpos
> dpyinfo
->mouse_face_beg_row
21630 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21631 && (vpos
< dpyinfo
->mouse_face_end_row
21632 || hpos
< dpyinfo
->mouse_face_end_col
21633 || dpyinfo
->mouse_face_past_end
))
21637 return in_mouse_face
;
21643 /* Find the glyph matrix position of buffer position CHARPOS in window
21644 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21645 current glyphs must be up to date. If CHARPOS is above window
21646 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21647 of last line in W. In the row containing CHARPOS, stop before glyphs
21648 having STOP as object. */
21650 #if 1 /* This is a version of fast_find_position that's more correct
21651 in the presence of hscrolling, for example. I didn't install
21652 it right away because the problem fixed is minor, it failed
21653 in 20.x as well, and I think it's too risky to install
21654 so near the release of 21.1. 2001-09-25 gerd. */
21657 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21660 int *hpos
, *vpos
, *x
, *y
;
21663 struct glyph_row
*row
, *first
;
21664 struct glyph
*glyph
, *end
;
21667 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21668 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21673 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21677 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21680 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21684 /* If whole rows or last part of a row came from a display overlay,
21685 row_containing_pos will skip over such rows because their end pos
21686 equals the start pos of the overlay or interval.
21688 Move back if we have a STOP object and previous row's
21689 end glyph came from STOP. */
21692 struct glyph_row
*prev
;
21693 while ((prev
= row
- 1, prev
>= first
)
21694 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21695 && prev
->used
[TEXT_AREA
] > 0)
21697 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21698 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21699 while (--glyph
>= beg
21700 && INTEGERP (glyph
->object
));
21702 || !EQ (stop
, glyph
->object
))
21710 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21712 glyph
= row
->glyphs
[TEXT_AREA
];
21713 end
= glyph
+ row
->used
[TEXT_AREA
];
21715 /* Skip over glyphs not having an object at the start of the row.
21716 These are special glyphs like truncation marks on terminal
21718 if (row
->displays_text_p
)
21720 && INTEGERP (glyph
->object
)
21721 && !EQ (stop
, glyph
->object
)
21722 && glyph
->charpos
< 0)
21724 *x
+= glyph
->pixel_width
;
21729 && !INTEGERP (glyph
->object
)
21730 && !EQ (stop
, glyph
->object
)
21731 && (!BUFFERP (glyph
->object
)
21732 || glyph
->charpos
< charpos
))
21734 *x
+= glyph
->pixel_width
;
21738 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21745 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21748 int *hpos
, *vpos
, *x
, *y
;
21753 int maybe_next_line_p
= 0;
21754 int line_start_position
;
21755 int yb
= window_text_bottom_y (w
);
21756 struct glyph_row
*row
, *best_row
;
21757 int row_vpos
, best_row_vpos
;
21760 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21761 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21763 while (row
->y
< yb
)
21765 if (row
->used
[TEXT_AREA
])
21766 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21768 line_start_position
= 0;
21770 if (line_start_position
> pos
)
21772 /* If the position sought is the end of the buffer,
21773 don't include the blank lines at the bottom of the window. */
21774 else if (line_start_position
== pos
21775 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21777 maybe_next_line_p
= 1;
21780 else if (line_start_position
> 0)
21783 best_row_vpos
= row_vpos
;
21786 if (row
->y
+ row
->height
>= yb
)
21793 /* Find the right column within BEST_ROW. */
21795 current_x
= best_row
->x
;
21796 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21798 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21799 int charpos
= glyph
->charpos
;
21801 if (BUFFERP (glyph
->object
))
21803 if (charpos
== pos
)
21806 *vpos
= best_row_vpos
;
21811 else if (charpos
> pos
)
21814 else if (EQ (glyph
->object
, stop
))
21819 current_x
+= glyph
->pixel_width
;
21822 /* If we're looking for the end of the buffer,
21823 and we didn't find it in the line we scanned,
21824 use the start of the following line. */
21825 if (maybe_next_line_p
)
21830 current_x
= best_row
->x
;
21833 *vpos
= best_row_vpos
;
21834 *hpos
= lastcol
+ 1;
21843 /* Find the position of the glyph for position POS in OBJECT in
21844 window W's current matrix, and return in *X, *Y the pixel
21845 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21847 RIGHT_P non-zero means return the position of the right edge of the
21848 glyph, RIGHT_P zero means return the left edge position.
21850 If no glyph for POS exists in the matrix, return the position of
21851 the glyph with the next smaller position that is in the matrix, if
21852 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21853 exists in the matrix, return the position of the glyph with the
21854 next larger position in OBJECT.
21856 Value is non-zero if a glyph was found. */
21859 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21862 Lisp_Object object
;
21863 int *hpos
, *vpos
, *x
, *y
;
21866 int yb
= window_text_bottom_y (w
);
21867 struct glyph_row
*r
;
21868 struct glyph
*best_glyph
= NULL
;
21869 struct glyph_row
*best_row
= NULL
;
21872 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21873 r
->enabled_p
&& r
->y
< yb
;
21876 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21877 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21880 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21881 if (EQ (g
->object
, object
))
21883 if (g
->charpos
== pos
)
21890 else if (best_glyph
== NULL
21891 || ((abs (g
->charpos
- pos
)
21892 < abs (best_glyph
->charpos
- pos
))
21895 : g
->charpos
> pos
)))
21909 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21913 *x
+= best_glyph
->pixel_width
;
21918 *vpos
= best_row
- w
->current_matrix
->rows
;
21921 return best_glyph
!= NULL
;
21925 /* See if position X, Y is within a hot-spot of an image. */
21928 on_hot_spot_p (hot_spot
, x
, y
)
21929 Lisp_Object hot_spot
;
21932 if (!CONSP (hot_spot
))
21935 if (EQ (XCAR (hot_spot
), Qrect
))
21937 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21938 Lisp_Object rect
= XCDR (hot_spot
);
21942 if (!CONSP (XCAR (rect
)))
21944 if (!CONSP (XCDR (rect
)))
21946 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21948 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21950 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21952 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21956 else if (EQ (XCAR (hot_spot
), Qcircle
))
21958 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21959 Lisp_Object circ
= XCDR (hot_spot
);
21960 Lisp_Object lr
, lx0
, ly0
;
21962 && CONSP (XCAR (circ
))
21963 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21964 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21965 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21967 double r
= XFLOATINT (lr
);
21968 double dx
= XINT (lx0
) - x
;
21969 double dy
= XINT (ly0
) - y
;
21970 return (dx
* dx
+ dy
* dy
<= r
* r
);
21973 else if (EQ (XCAR (hot_spot
), Qpoly
))
21975 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21976 if (VECTORP (XCDR (hot_spot
)))
21978 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21979 Lisp_Object
*poly
= v
->contents
;
21983 Lisp_Object lx
, ly
;
21986 /* Need an even number of coordinates, and at least 3 edges. */
21987 if (n
< 6 || n
& 1)
21990 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21991 If count is odd, we are inside polygon. Pixels on edges
21992 may or may not be included depending on actual geometry of the
21994 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21995 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21997 x0
= XINT (lx
), y0
= XINT (ly
);
21998 for (i
= 0; i
< n
; i
+= 2)
22000 int x1
= x0
, y1
= y0
;
22001 if ((lx
= poly
[i
], !INTEGERP (lx
))
22002 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22004 x0
= XINT (lx
), y0
= XINT (ly
);
22006 /* Does this segment cross the X line? */
22014 if (y
> y0
&& y
> y1
)
22016 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22022 /* If we don't understand the format, pretend we're not in the hot-spot. */
22027 find_hot_spot (map
, x
, y
)
22031 while (CONSP (map
))
22033 if (CONSP (XCAR (map
))
22034 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22042 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22044 doc
: /* Lookup in image map MAP coordinates X and Y.
22045 An image map is an alist where each element has the format (AREA ID PLIST).
22046 An AREA is specified as either a rectangle, a circle, or a polygon:
22047 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22048 pixel coordinates of the upper left and bottom right corners.
22049 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22050 and the radius of the circle; r may be a float or integer.
22051 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22052 vector describes one corner in the polygon.
22053 Returns the alist element for the first matching AREA in MAP. */)
22064 return find_hot_spot (map
, XINT (x
), XINT (y
));
22068 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22070 define_frame_cursor1 (f
, cursor
, pointer
)
22073 Lisp_Object pointer
;
22075 /* Do not change cursor shape while dragging mouse. */
22076 if (!NILP (do_mouse_tracking
))
22079 if (!NILP (pointer
))
22081 if (EQ (pointer
, Qarrow
))
22082 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22083 else if (EQ (pointer
, Qhand
))
22084 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22085 else if (EQ (pointer
, Qtext
))
22086 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22087 else if (EQ (pointer
, intern ("hdrag")))
22088 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22089 #ifdef HAVE_X_WINDOWS
22090 else if (EQ (pointer
, intern ("vdrag")))
22091 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22093 else if (EQ (pointer
, intern ("hourglass")))
22094 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22095 else if (EQ (pointer
, Qmodeline
))
22096 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22098 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22101 if (cursor
!= No_Cursor
)
22102 rif
->define_frame_cursor (f
, cursor
);
22105 /* Take proper action when mouse has moved to the mode or header line
22106 or marginal area AREA of window W, x-position X and y-position Y.
22107 X is relative to the start of the text display area of W, so the
22108 width of bitmap areas and scroll bars must be subtracted to get a
22109 position relative to the start of the mode line. */
22112 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22113 Lisp_Object window
;
22115 enum window_part area
;
22117 struct window
*w
= XWINDOW (window
);
22118 struct frame
*f
= XFRAME (w
->frame
);
22119 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22120 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22121 Lisp_Object pointer
= Qnil
;
22122 int charpos
, dx
, dy
, width
, height
;
22123 Lisp_Object string
, object
= Qnil
;
22124 Lisp_Object pos
, help
;
22126 Lisp_Object mouse_face
;
22127 int original_x_pixel
= x
;
22128 struct glyph
* glyph
= NULL
;
22129 struct glyph_row
*row
;
22131 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22136 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22137 &object
, &dx
, &dy
, &width
, &height
);
22139 row
= (area
== ON_MODE_LINE
22140 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22141 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22144 if (row
->mode_line_p
&& row
->enabled_p
)
22146 glyph
= row
->glyphs
[TEXT_AREA
];
22147 end
= glyph
+ row
->used
[TEXT_AREA
];
22149 for (x0
= original_x_pixel
;
22150 glyph
< end
&& x0
>= glyph
->pixel_width
;
22152 x0
-= glyph
->pixel_width
;
22160 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22161 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22162 &object
, &dx
, &dy
, &width
, &height
);
22167 if (IMAGEP (object
))
22169 Lisp_Object image_map
, hotspot
;
22170 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22172 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22174 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22176 Lisp_Object area_id
, plist
;
22178 area_id
= XCAR (hotspot
);
22179 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22180 If so, we could look for mouse-enter, mouse-leave
22181 properties in PLIST (and do something...). */
22182 hotspot
= XCDR (hotspot
);
22183 if (CONSP (hotspot
)
22184 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22186 pointer
= Fplist_get (plist
, Qpointer
);
22187 if (NILP (pointer
))
22189 help
= Fplist_get (plist
, Qhelp_echo
);
22192 help_echo_string
= help
;
22193 /* Is this correct? ++kfs */
22194 XSETWINDOW (help_echo_window
, w
);
22195 help_echo_object
= w
->buffer
;
22196 help_echo_pos
= charpos
;
22200 if (NILP (pointer
))
22201 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22204 if (STRINGP (string
))
22206 pos
= make_number (charpos
);
22207 /* If we're on a string with `help-echo' text property, arrange
22208 for the help to be displayed. This is done by setting the
22209 global variable help_echo_string to the help string. */
22212 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22215 help_echo_string
= help
;
22216 XSETWINDOW (help_echo_window
, w
);
22217 help_echo_object
= string
;
22218 help_echo_pos
= charpos
;
22222 if (NILP (pointer
))
22223 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22225 /* Change the mouse pointer according to what is under X/Y. */
22226 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22229 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22230 if (!KEYMAPP (map
))
22231 map
= Fget_text_property (pos
, Qkeymap
, string
);
22232 if (!KEYMAPP (map
))
22233 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22236 /* Change the mouse face according to what is under X/Y. */
22237 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22238 if (!NILP (mouse_face
)
22239 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22244 struct glyph
* tmp_glyph
;
22248 int total_pixel_width
;
22253 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22254 Qmouse_face
, string
, Qnil
);
22256 b
= make_number (0);
22258 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22260 e
= make_number (SCHARS (string
));
22262 /* Calculate the position(glyph position: GPOS) of GLYPH in
22263 displayed string. GPOS is different from CHARPOS.
22265 CHARPOS is the position of glyph in internal string
22266 object. A mode line string format has structures which
22267 is converted to a flatten by emacs lisp interpreter.
22268 The internal string is an element of the structures.
22269 The displayed string is the flatten string. */
22270 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22271 tmp_glyph
->charpos
>= XINT (b
);
22272 tmp_glyph
--, gpos
++)
22274 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22278 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22279 displayed string holding GLYPH.
22281 GSEQ_LENGTH is different from SCHARS (STRING).
22282 SCHARS (STRING) returns the length of the internal string. */
22283 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22284 tmp_glyph
->charpos
< XINT (e
);
22285 tmp_glyph
++, gseq_length
++)
22287 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22291 total_pixel_width
= 0;
22292 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22293 total_pixel_width
+= tmp_glyph
->pixel_width
;
22295 /* Pre calculation of re-rendering position */
22297 hpos
= (area
== ON_MODE_LINE
22298 ? (w
->current_matrix
)->nrows
- 1
22301 /* If the re-rendering position is included in the last
22302 re-rendering area, we should do nothing. */
22303 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22304 && dpyinfo
->mouse_face_beg_col
<= vpos
22305 && vpos
< dpyinfo
->mouse_face_end_col
22306 && dpyinfo
->mouse_face_beg_row
== hpos
)
22309 if (clear_mouse_face (dpyinfo
))
22310 cursor
= No_Cursor
;
22312 dpyinfo
->mouse_face_beg_col
= vpos
;
22313 dpyinfo
->mouse_face_beg_row
= hpos
;
22315 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22316 dpyinfo
->mouse_face_beg_y
= 0;
22318 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22319 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22321 dpyinfo
->mouse_face_end_x
= 0;
22322 dpyinfo
->mouse_face_end_y
= 0;
22324 dpyinfo
->mouse_face_past_end
= 0;
22325 dpyinfo
->mouse_face_window
= window
;
22327 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22330 glyph
->face_id
, 1);
22331 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22333 if (NILP (pointer
))
22336 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22337 clear_mouse_face (dpyinfo
);
22339 define_frame_cursor1 (f
, cursor
, pointer
);
22344 Take proper action when the mouse has moved to position X, Y on
22345 frame F as regards highlighting characters that have mouse-face
22346 properties. Also de-highlighting chars where the mouse was before.
22347 X and Y can be negative or out of range. */
22350 note_mouse_highlight (f
, x
, y
)
22354 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22355 enum window_part part
;
22356 Lisp_Object window
;
22358 Cursor cursor
= No_Cursor
;
22359 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22362 /* When a menu is active, don't highlight because this looks odd. */
22363 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22364 if (popup_activated ())
22368 if (NILP (Vmouse_highlight
)
22369 || !f
->glyphs_initialized_p
)
22372 dpyinfo
->mouse_face_mouse_x
= x
;
22373 dpyinfo
->mouse_face_mouse_y
= y
;
22374 dpyinfo
->mouse_face_mouse_frame
= f
;
22376 if (dpyinfo
->mouse_face_defer
)
22379 if (gc_in_progress
)
22381 dpyinfo
->mouse_face_deferred_gc
= 1;
22385 /* Which window is that in? */
22386 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22388 /* If we were displaying active text in another window, clear that.
22389 Also clear if we move out of text area in same window. */
22390 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22391 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22392 && !NILP (dpyinfo
->mouse_face_window
)))
22393 clear_mouse_face (dpyinfo
);
22395 /* Not on a window -> return. */
22396 if (!WINDOWP (window
))
22399 /* Reset help_echo_string. It will get recomputed below. */
22400 help_echo_string
= Qnil
;
22402 /* Convert to window-relative pixel coordinates. */
22403 w
= XWINDOW (window
);
22404 frame_to_window_pixel_xy (w
, &x
, &y
);
22406 /* Handle tool-bar window differently since it doesn't display a
22408 if (EQ (window
, f
->tool_bar_window
))
22410 note_tool_bar_highlight (f
, x
, y
);
22414 /* Mouse is on the mode, header line or margin? */
22415 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22416 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22418 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22422 if (part
== ON_VERTICAL_BORDER
)
22424 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22425 help_echo_string
= build_string ("drag-mouse-1: resize");
22427 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22428 || part
== ON_SCROLL_BAR
)
22429 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22431 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22433 /* Are we in a window whose display is up to date?
22434 And verify the buffer's text has not changed. */
22435 b
= XBUFFER (w
->buffer
);
22436 if (part
== ON_TEXT
22437 && EQ (w
->window_end_valid
, w
->buffer
)
22438 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22439 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22441 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22442 struct glyph
*glyph
;
22443 Lisp_Object object
;
22444 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22445 Lisp_Object
*overlay_vec
= NULL
;
22447 struct buffer
*obuf
;
22448 int obegv
, ozv
, same_region
;
22450 /* Find the glyph under X/Y. */
22451 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22453 /* Look for :pointer property on image. */
22454 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22456 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22457 if (img
!= NULL
&& IMAGEP (img
->spec
))
22459 Lisp_Object image_map
, hotspot
;
22460 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22462 && (hotspot
= find_hot_spot (image_map
,
22463 glyph
->slice
.x
+ dx
,
22464 glyph
->slice
.y
+ dy
),
22466 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22468 Lisp_Object area_id
, plist
;
22470 area_id
= XCAR (hotspot
);
22471 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22472 If so, we could look for mouse-enter, mouse-leave
22473 properties in PLIST (and do something...). */
22474 hotspot
= XCDR (hotspot
);
22475 if (CONSP (hotspot
)
22476 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22478 pointer
= Fplist_get (plist
, Qpointer
);
22479 if (NILP (pointer
))
22481 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22482 if (!NILP (help_echo_string
))
22484 help_echo_window
= window
;
22485 help_echo_object
= glyph
->object
;
22486 help_echo_pos
= glyph
->charpos
;
22490 if (NILP (pointer
))
22491 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22495 /* Clear mouse face if X/Y not over text. */
22497 || area
!= TEXT_AREA
22498 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22500 if (clear_mouse_face (dpyinfo
))
22501 cursor
= No_Cursor
;
22502 if (NILP (pointer
))
22504 if (area
!= TEXT_AREA
)
22505 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22507 pointer
= Vvoid_text_area_pointer
;
22512 pos
= glyph
->charpos
;
22513 object
= glyph
->object
;
22514 if (!STRINGP (object
) && !BUFFERP (object
))
22517 /* If we get an out-of-range value, return now; avoid an error. */
22518 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22521 /* Make the window's buffer temporarily current for
22522 overlays_at and compute_char_face. */
22523 obuf
= current_buffer
;
22524 current_buffer
= b
;
22530 /* Is this char mouse-active or does it have help-echo? */
22531 position
= make_number (pos
);
22533 if (BUFFERP (object
))
22535 /* Put all the overlays we want in a vector in overlay_vec. */
22536 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22537 /* Sort overlays into increasing priority order. */
22538 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22543 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22544 && vpos
>= dpyinfo
->mouse_face_beg_row
22545 && vpos
<= dpyinfo
->mouse_face_end_row
22546 && (vpos
> dpyinfo
->mouse_face_beg_row
22547 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22548 && (vpos
< dpyinfo
->mouse_face_end_row
22549 || hpos
< dpyinfo
->mouse_face_end_col
22550 || dpyinfo
->mouse_face_past_end
));
22553 cursor
= No_Cursor
;
22555 /* Check mouse-face highlighting. */
22557 /* If there exists an overlay with mouse-face overlapping
22558 the one we are currently highlighting, we have to
22559 check if we enter the overlapping overlay, and then
22560 highlight only that. */
22561 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22562 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22564 /* Find the highest priority overlay that has a mouse-face
22567 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22569 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22570 if (!NILP (mouse_face
))
22571 overlay
= overlay_vec
[i
];
22574 /* If we're actually highlighting the same overlay as
22575 before, there's no need to do that again. */
22576 if (!NILP (overlay
)
22577 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22578 goto check_help_echo
;
22580 dpyinfo
->mouse_face_overlay
= overlay
;
22582 /* Clear the display of the old active region, if any. */
22583 if (clear_mouse_face (dpyinfo
))
22584 cursor
= No_Cursor
;
22586 /* If no overlay applies, get a text property. */
22587 if (NILP (overlay
))
22588 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22590 /* Handle the overlay case. */
22591 if (!NILP (overlay
))
22593 /* Find the range of text around this char that
22594 should be active. */
22595 Lisp_Object before
, after
;
22598 before
= Foverlay_start (overlay
);
22599 after
= Foverlay_end (overlay
);
22600 /* Record this as the current active region. */
22601 fast_find_position (w
, XFASTINT (before
),
22602 &dpyinfo
->mouse_face_beg_col
,
22603 &dpyinfo
->mouse_face_beg_row
,
22604 &dpyinfo
->mouse_face_beg_x
,
22605 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22607 dpyinfo
->mouse_face_past_end
22608 = !fast_find_position (w
, XFASTINT (after
),
22609 &dpyinfo
->mouse_face_end_col
,
22610 &dpyinfo
->mouse_face_end_row
,
22611 &dpyinfo
->mouse_face_end_x
,
22612 &dpyinfo
->mouse_face_end_y
, Qnil
);
22613 dpyinfo
->mouse_face_window
= window
;
22615 dpyinfo
->mouse_face_face_id
22616 = face_at_buffer_position (w
, pos
, 0, 0,
22618 !dpyinfo
->mouse_face_hidden
);
22620 /* Display it as active. */
22621 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22622 cursor
= No_Cursor
;
22624 /* Handle the text property case. */
22625 else if (!NILP (mouse_face
) && BUFFERP (object
))
22627 /* Find the range of text around this char that
22628 should be active. */
22629 Lisp_Object before
, after
, beginning
, end
;
22632 beginning
= Fmarker_position (w
->start
);
22633 end
= make_number (BUF_Z (XBUFFER (object
))
22634 - XFASTINT (w
->window_end_pos
));
22636 = Fprevious_single_property_change (make_number (pos
+ 1),
22638 object
, beginning
);
22640 = Fnext_single_property_change (position
, Qmouse_face
,
22643 /* Record this as the current active region. */
22644 fast_find_position (w
, XFASTINT (before
),
22645 &dpyinfo
->mouse_face_beg_col
,
22646 &dpyinfo
->mouse_face_beg_row
,
22647 &dpyinfo
->mouse_face_beg_x
,
22648 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22649 dpyinfo
->mouse_face_past_end
22650 = !fast_find_position (w
, XFASTINT (after
),
22651 &dpyinfo
->mouse_face_end_col
,
22652 &dpyinfo
->mouse_face_end_row
,
22653 &dpyinfo
->mouse_face_end_x
,
22654 &dpyinfo
->mouse_face_end_y
, Qnil
);
22655 dpyinfo
->mouse_face_window
= window
;
22657 if (BUFFERP (object
))
22658 dpyinfo
->mouse_face_face_id
22659 = face_at_buffer_position (w
, pos
, 0, 0,
22661 !dpyinfo
->mouse_face_hidden
);
22663 /* Display it as active. */
22664 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22665 cursor
= No_Cursor
;
22667 else if (!NILP (mouse_face
) && STRINGP (object
))
22672 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22675 e
= Fnext_single_property_change (position
, Qmouse_face
,
22678 b
= make_number (0);
22680 e
= make_number (SCHARS (object
) - 1);
22682 fast_find_string_pos (w
, XINT (b
), object
,
22683 &dpyinfo
->mouse_face_beg_col
,
22684 &dpyinfo
->mouse_face_beg_row
,
22685 &dpyinfo
->mouse_face_beg_x
,
22686 &dpyinfo
->mouse_face_beg_y
, 0);
22687 fast_find_string_pos (w
, XINT (e
), object
,
22688 &dpyinfo
->mouse_face_end_col
,
22689 &dpyinfo
->mouse_face_end_row
,
22690 &dpyinfo
->mouse_face_end_x
,
22691 &dpyinfo
->mouse_face_end_y
, 1);
22692 dpyinfo
->mouse_face_past_end
= 0;
22693 dpyinfo
->mouse_face_window
= window
;
22694 dpyinfo
->mouse_face_face_id
22695 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22696 glyph
->face_id
, 1);
22697 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22698 cursor
= No_Cursor
;
22700 else if (STRINGP (object
) && NILP (mouse_face
))
22702 /* A string which doesn't have mouse-face, but
22703 the text ``under'' it might have. */
22704 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22705 int start
= MATRIX_ROW_START_CHARPOS (r
);
22707 pos
= string_buffer_position (w
, object
, start
);
22709 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22713 if (!NILP (mouse_face
) && !NILP (overlay
))
22715 Lisp_Object before
= Foverlay_start (overlay
);
22716 Lisp_Object after
= Foverlay_end (overlay
);
22719 /* Note that we might not be able to find position
22720 BEFORE in the glyph matrix if the overlay is
22721 entirely covered by a `display' property. In
22722 this case, we overshoot. So let's stop in
22723 the glyph matrix before glyphs for OBJECT. */
22724 fast_find_position (w
, XFASTINT (before
),
22725 &dpyinfo
->mouse_face_beg_col
,
22726 &dpyinfo
->mouse_face_beg_row
,
22727 &dpyinfo
->mouse_face_beg_x
,
22728 &dpyinfo
->mouse_face_beg_y
,
22731 dpyinfo
->mouse_face_past_end
22732 = !fast_find_position (w
, XFASTINT (after
),
22733 &dpyinfo
->mouse_face_end_col
,
22734 &dpyinfo
->mouse_face_end_row
,
22735 &dpyinfo
->mouse_face_end_x
,
22736 &dpyinfo
->mouse_face_end_y
,
22738 dpyinfo
->mouse_face_window
= window
;
22739 dpyinfo
->mouse_face_face_id
22740 = face_at_buffer_position (w
, pos
, 0, 0,
22742 !dpyinfo
->mouse_face_hidden
);
22744 /* Display it as active. */
22745 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22746 cursor
= No_Cursor
;
22753 /* Look for a `help-echo' property. */
22754 if (NILP (help_echo_string
)) {
22755 Lisp_Object help
, overlay
;
22757 /* Check overlays first. */
22758 help
= overlay
= Qnil
;
22759 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22761 overlay
= overlay_vec
[i
];
22762 help
= Foverlay_get (overlay
, Qhelp_echo
);
22767 help_echo_string
= help
;
22768 help_echo_window
= window
;
22769 help_echo_object
= overlay
;
22770 help_echo_pos
= pos
;
22774 Lisp_Object object
= glyph
->object
;
22775 int charpos
= glyph
->charpos
;
22777 /* Try text properties. */
22778 if (STRINGP (object
)
22780 && charpos
< SCHARS (object
))
22782 help
= Fget_text_property (make_number (charpos
),
22783 Qhelp_echo
, object
);
22786 /* If the string itself doesn't specify a help-echo,
22787 see if the buffer text ``under'' it does. */
22788 struct glyph_row
*r
22789 = MATRIX_ROW (w
->current_matrix
, vpos
);
22790 int start
= MATRIX_ROW_START_CHARPOS (r
);
22791 int pos
= string_buffer_position (w
, object
, start
);
22794 help
= Fget_char_property (make_number (pos
),
22795 Qhelp_echo
, w
->buffer
);
22799 object
= w
->buffer
;
22804 else if (BUFFERP (object
)
22807 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22812 help_echo_string
= help
;
22813 help_echo_window
= window
;
22814 help_echo_object
= object
;
22815 help_echo_pos
= charpos
;
22820 /* Look for a `pointer' property. */
22821 if (NILP (pointer
))
22823 /* Check overlays first. */
22824 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22825 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22827 if (NILP (pointer
))
22829 Lisp_Object object
= glyph
->object
;
22830 int charpos
= glyph
->charpos
;
22832 /* Try text properties. */
22833 if (STRINGP (object
)
22835 && charpos
< SCHARS (object
))
22837 pointer
= Fget_text_property (make_number (charpos
),
22839 if (NILP (pointer
))
22841 /* If the string itself doesn't specify a pointer,
22842 see if the buffer text ``under'' it does. */
22843 struct glyph_row
*r
22844 = MATRIX_ROW (w
->current_matrix
, vpos
);
22845 int start
= MATRIX_ROW_START_CHARPOS (r
);
22846 int pos
= string_buffer_position (w
, object
, start
);
22848 pointer
= Fget_char_property (make_number (pos
),
22849 Qpointer
, w
->buffer
);
22852 else if (BUFFERP (object
)
22855 pointer
= Fget_text_property (make_number (charpos
),
22862 current_buffer
= obuf
;
22867 define_frame_cursor1 (f
, cursor
, pointer
);
22872 Clear any mouse-face on window W. This function is part of the
22873 redisplay interface, and is called from try_window_id and similar
22874 functions to ensure the mouse-highlight is off. */
22877 x_clear_window_mouse_face (w
)
22880 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22881 Lisp_Object window
;
22884 XSETWINDOW (window
, w
);
22885 if (EQ (window
, dpyinfo
->mouse_face_window
))
22886 clear_mouse_face (dpyinfo
);
22892 Just discard the mouse face information for frame F, if any.
22893 This is used when the size of F is changed. */
22896 cancel_mouse_face (f
)
22899 Lisp_Object window
;
22900 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22902 window
= dpyinfo
->mouse_face_window
;
22903 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22905 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22906 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22907 dpyinfo
->mouse_face_window
= Qnil
;
22912 #endif /* HAVE_WINDOW_SYSTEM */
22915 /***********************************************************************
22917 ***********************************************************************/
22919 #ifdef HAVE_WINDOW_SYSTEM
22921 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22922 which intersects rectangle R. R is in window-relative coordinates. */
22925 expose_area (w
, row
, r
, area
)
22927 struct glyph_row
*row
;
22929 enum glyph_row_area area
;
22931 struct glyph
*first
= row
->glyphs
[area
];
22932 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22933 struct glyph
*last
;
22934 int first_x
, start_x
, x
;
22936 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22937 /* If row extends face to end of line write the whole line. */
22938 draw_glyphs (w
, 0, row
, area
,
22939 0, row
->used
[area
],
22940 DRAW_NORMAL_TEXT
, 0);
22943 /* Set START_X to the window-relative start position for drawing glyphs of
22944 AREA. The first glyph of the text area can be partially visible.
22945 The first glyphs of other areas cannot. */
22946 start_x
= window_box_left_offset (w
, area
);
22948 if (area
== TEXT_AREA
)
22951 /* Find the first glyph that must be redrawn. */
22953 && x
+ first
->pixel_width
< r
->x
)
22955 x
+= first
->pixel_width
;
22959 /* Find the last one. */
22963 && x
< r
->x
+ r
->width
)
22965 x
+= last
->pixel_width
;
22971 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22972 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22973 DRAW_NORMAL_TEXT
, 0);
22978 /* Redraw the parts of the glyph row ROW on window W intersecting
22979 rectangle R. R is in window-relative coordinates. Value is
22980 non-zero if mouse-face was overwritten. */
22983 expose_line (w
, row
, r
)
22985 struct glyph_row
*row
;
22988 xassert (row
->enabled_p
);
22990 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22991 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22992 0, row
->used
[TEXT_AREA
],
22993 DRAW_NORMAL_TEXT
, 0);
22996 if (row
->used
[LEFT_MARGIN_AREA
])
22997 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22998 if (row
->used
[TEXT_AREA
])
22999 expose_area (w
, row
, r
, TEXT_AREA
);
23000 if (row
->used
[RIGHT_MARGIN_AREA
])
23001 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23002 draw_row_fringe_bitmaps (w
, row
);
23005 return row
->mouse_face_p
;
23009 /* Redraw those parts of glyphs rows during expose event handling that
23010 overlap other rows. Redrawing of an exposed line writes over parts
23011 of lines overlapping that exposed line; this function fixes that.
23013 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23014 row in W's current matrix that is exposed and overlaps other rows.
23015 LAST_OVERLAPPING_ROW is the last such row. */
23018 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23020 struct glyph_row
*first_overlapping_row
;
23021 struct glyph_row
*last_overlapping_row
;
23023 struct glyph_row
*row
;
23025 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23026 if (row
->overlapping_p
)
23028 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23030 if (row
->used
[LEFT_MARGIN_AREA
])
23031 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23033 if (row
->used
[TEXT_AREA
])
23034 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23036 if (row
->used
[RIGHT_MARGIN_AREA
])
23037 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23042 /* Return non-zero if W's cursor intersects rectangle R. */
23045 phys_cursor_in_rect_p (w
, r
)
23049 XRectangle cr
, result
;
23050 struct glyph
*cursor_glyph
;
23052 cursor_glyph
= get_phys_cursor_glyph (w
);
23055 /* r is relative to W's box, but w->phys_cursor.x is relative
23056 to left edge of W's TEXT area. Adjust it. */
23057 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23058 cr
.y
= w
->phys_cursor
.y
;
23059 cr
.width
= cursor_glyph
->pixel_width
;
23060 cr
.height
= w
->phys_cursor_height
;
23061 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23062 I assume the effect is the same -- and this is portable. */
23063 return x_intersect_rectangles (&cr
, r
, &result
);
23071 Draw a vertical window border to the right of window W if W doesn't
23072 have vertical scroll bars. */
23075 x_draw_vertical_border (w
)
23078 /* We could do better, if we knew what type of scroll-bar the adjacent
23079 windows (on either side) have... But we don't :-(
23080 However, I think this works ok. ++KFS 2003-04-25 */
23082 /* Redraw borders between horizontally adjacent windows. Don't
23083 do it for frames with vertical scroll bars because either the
23084 right scroll bar of a window, or the left scroll bar of its
23085 neighbor will suffice as a border. */
23086 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23089 if (!WINDOW_RIGHTMOST_P (w
)
23090 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23092 int x0
, x1
, y0
, y1
;
23094 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23097 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23100 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23102 else if (!WINDOW_LEFTMOST_P (w
)
23103 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23105 int x0
, x1
, y0
, y1
;
23107 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23110 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23113 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23118 /* Redraw the part of window W intersection rectangle FR. Pixel
23119 coordinates in FR are frame-relative. Call this function with
23120 input blocked. Value is non-zero if the exposure overwrites
23124 expose_window (w
, fr
)
23128 struct frame
*f
= XFRAME (w
->frame
);
23130 int mouse_face_overwritten_p
= 0;
23132 /* If window is not yet fully initialized, do nothing. This can
23133 happen when toolkit scroll bars are used and a window is split.
23134 Reconfiguring the scroll bar will generate an expose for a newly
23136 if (w
->current_matrix
== NULL
)
23139 /* When we're currently updating the window, display and current
23140 matrix usually don't agree. Arrange for a thorough display
23142 if (w
== updated_window
)
23144 SET_FRAME_GARBAGED (f
);
23148 /* Frame-relative pixel rectangle of W. */
23149 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23150 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23151 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23152 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23154 if (x_intersect_rectangles (fr
, &wr
, &r
))
23156 int yb
= window_text_bottom_y (w
);
23157 struct glyph_row
*row
;
23158 int cursor_cleared_p
;
23159 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23161 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23162 r
.x
, r
.y
, r
.width
, r
.height
));
23164 /* Convert to window coordinates. */
23165 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23166 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23168 /* Turn off the cursor. */
23169 if (!w
->pseudo_window_p
23170 && phys_cursor_in_rect_p (w
, &r
))
23172 x_clear_cursor (w
);
23173 cursor_cleared_p
= 1;
23176 cursor_cleared_p
= 0;
23178 /* Update lines intersecting rectangle R. */
23179 first_overlapping_row
= last_overlapping_row
= NULL
;
23180 for (row
= w
->current_matrix
->rows
;
23185 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23187 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23188 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23189 || (r
.y
>= y0
&& r
.y
< y1
)
23190 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23192 /* A header line may be overlapping, but there is no need
23193 to fix overlapping areas for them. KFS 2005-02-12 */
23194 if (row
->overlapping_p
&& !row
->mode_line_p
)
23196 if (first_overlapping_row
== NULL
)
23197 first_overlapping_row
= row
;
23198 last_overlapping_row
= row
;
23201 if (expose_line (w
, row
, &r
))
23202 mouse_face_overwritten_p
= 1;
23209 /* Display the mode line if there is one. */
23210 if (WINDOW_WANTS_MODELINE_P (w
)
23211 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23213 && row
->y
< r
.y
+ r
.height
)
23215 if (expose_line (w
, row
, &r
))
23216 mouse_face_overwritten_p
= 1;
23219 if (!w
->pseudo_window_p
)
23221 /* Fix the display of overlapping rows. */
23222 if (first_overlapping_row
)
23223 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23225 /* Draw border between windows. */
23226 x_draw_vertical_border (w
);
23228 /* Turn the cursor on again. */
23229 if (cursor_cleared_p
)
23230 update_window_cursor (w
, 1);
23234 return mouse_face_overwritten_p
;
23239 /* Redraw (parts) of all windows in the window tree rooted at W that
23240 intersect R. R contains frame pixel coordinates. Value is
23241 non-zero if the exposure overwrites mouse-face. */
23244 expose_window_tree (w
, r
)
23248 struct frame
*f
= XFRAME (w
->frame
);
23249 int mouse_face_overwritten_p
= 0;
23251 while (w
&& !FRAME_GARBAGED_P (f
))
23253 if (!NILP (w
->hchild
))
23254 mouse_face_overwritten_p
23255 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23256 else if (!NILP (w
->vchild
))
23257 mouse_face_overwritten_p
23258 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23260 mouse_face_overwritten_p
|= expose_window (w
, r
);
23262 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23265 return mouse_face_overwritten_p
;
23270 Redisplay an exposed area of frame F. X and Y are the upper-left
23271 corner of the exposed rectangle. W and H are width and height of
23272 the exposed area. All are pixel values. W or H zero means redraw
23273 the entire frame. */
23276 expose_frame (f
, x
, y
, w
, h
)
23281 int mouse_face_overwritten_p
= 0;
23283 TRACE ((stderr
, "expose_frame "));
23285 /* No need to redraw if frame will be redrawn soon. */
23286 if (FRAME_GARBAGED_P (f
))
23288 TRACE ((stderr
, " garbaged\n"));
23292 /* If basic faces haven't been realized yet, there is no point in
23293 trying to redraw anything. This can happen when we get an expose
23294 event while Emacs is starting, e.g. by moving another window. */
23295 if (FRAME_FACE_CACHE (f
) == NULL
23296 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23298 TRACE ((stderr
, " no faces\n"));
23302 if (w
== 0 || h
== 0)
23305 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23306 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23316 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23317 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23319 if (WINDOWP (f
->tool_bar_window
))
23320 mouse_face_overwritten_p
23321 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23323 #ifdef HAVE_X_WINDOWS
23325 #ifndef USE_X_TOOLKIT
23326 if (WINDOWP (f
->menu_bar_window
))
23327 mouse_face_overwritten_p
23328 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23329 #endif /* not USE_X_TOOLKIT */
23333 /* Some window managers support a focus-follows-mouse style with
23334 delayed raising of frames. Imagine a partially obscured frame,
23335 and moving the mouse into partially obscured mouse-face on that
23336 frame. The visible part of the mouse-face will be highlighted,
23337 then the WM raises the obscured frame. With at least one WM, KDE
23338 2.1, Emacs is not getting any event for the raising of the frame
23339 (even tried with SubstructureRedirectMask), only Expose events.
23340 These expose events will draw text normally, i.e. not
23341 highlighted. Which means we must redo the highlight here.
23342 Subsume it under ``we love X''. --gerd 2001-08-15 */
23343 /* Included in Windows version because Windows most likely does not
23344 do the right thing if any third party tool offers
23345 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23346 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23348 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23349 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23351 int x
= dpyinfo
->mouse_face_mouse_x
;
23352 int y
= dpyinfo
->mouse_face_mouse_y
;
23353 clear_mouse_face (dpyinfo
);
23354 note_mouse_highlight (f
, x
, y
);
23361 Determine the intersection of two rectangles R1 and R2. Return
23362 the intersection in *RESULT. Value is non-zero if RESULT is not
23366 x_intersect_rectangles (r1
, r2
, result
)
23367 XRectangle
*r1
, *r2
, *result
;
23369 XRectangle
*left
, *right
;
23370 XRectangle
*upper
, *lower
;
23371 int intersection_p
= 0;
23373 /* Rearrange so that R1 is the left-most rectangle. */
23375 left
= r1
, right
= r2
;
23377 left
= r2
, right
= r1
;
23379 /* X0 of the intersection is right.x0, if this is inside R1,
23380 otherwise there is no intersection. */
23381 if (right
->x
<= left
->x
+ left
->width
)
23383 result
->x
= right
->x
;
23385 /* The right end of the intersection is the minimum of the
23386 the right ends of left and right. */
23387 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23390 /* Same game for Y. */
23392 upper
= r1
, lower
= r2
;
23394 upper
= r2
, lower
= r1
;
23396 /* The upper end of the intersection is lower.y0, if this is inside
23397 of upper. Otherwise, there is no intersection. */
23398 if (lower
->y
<= upper
->y
+ upper
->height
)
23400 result
->y
= lower
->y
;
23402 /* The lower end of the intersection is the minimum of the lower
23403 ends of upper and lower. */
23404 result
->height
= (min (lower
->y
+ lower
->height
,
23405 upper
->y
+ upper
->height
)
23407 intersection_p
= 1;
23411 return intersection_p
;
23414 #endif /* HAVE_WINDOW_SYSTEM */
23417 /***********************************************************************
23419 ***********************************************************************/
23424 Vwith_echo_area_save_vector
= Qnil
;
23425 staticpro (&Vwith_echo_area_save_vector
);
23427 Vmessage_stack
= Qnil
;
23428 staticpro (&Vmessage_stack
);
23430 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23431 staticpro (&Qinhibit_redisplay
);
23433 message_dolog_marker1
= Fmake_marker ();
23434 staticpro (&message_dolog_marker1
);
23435 message_dolog_marker2
= Fmake_marker ();
23436 staticpro (&message_dolog_marker2
);
23437 message_dolog_marker3
= Fmake_marker ();
23438 staticpro (&message_dolog_marker3
);
23441 defsubr (&Sdump_frame_glyph_matrix
);
23442 defsubr (&Sdump_glyph_matrix
);
23443 defsubr (&Sdump_glyph_row
);
23444 defsubr (&Sdump_tool_bar_row
);
23445 defsubr (&Strace_redisplay
);
23446 defsubr (&Strace_to_stderr
);
23448 #ifdef HAVE_WINDOW_SYSTEM
23449 defsubr (&Stool_bar_lines_needed
);
23450 defsubr (&Slookup_image_map
);
23452 defsubr (&Sformat_mode_line
);
23454 staticpro (&Qmenu_bar_update_hook
);
23455 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23457 staticpro (&Qoverriding_terminal_local_map
);
23458 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23460 staticpro (&Qoverriding_local_map
);
23461 Qoverriding_local_map
= intern ("overriding-local-map");
23463 staticpro (&Qwindow_scroll_functions
);
23464 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23466 staticpro (&Qredisplay_end_trigger_functions
);
23467 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23469 staticpro (&Qinhibit_point_motion_hooks
);
23470 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23472 QCdata
= intern (":data");
23473 staticpro (&QCdata
);
23474 Qdisplay
= intern ("display");
23475 staticpro (&Qdisplay
);
23476 Qspace_width
= intern ("space-width");
23477 staticpro (&Qspace_width
);
23478 Qraise
= intern ("raise");
23479 staticpro (&Qraise
);
23480 Qslice
= intern ("slice");
23481 staticpro (&Qslice
);
23482 Qspace
= intern ("space");
23483 staticpro (&Qspace
);
23484 Qmargin
= intern ("margin");
23485 staticpro (&Qmargin
);
23486 Qpointer
= intern ("pointer");
23487 staticpro (&Qpointer
);
23488 Qleft_margin
= intern ("left-margin");
23489 staticpro (&Qleft_margin
);
23490 Qright_margin
= intern ("right-margin");
23491 staticpro (&Qright_margin
);
23492 Qcenter
= intern ("center");
23493 staticpro (&Qcenter
);
23494 Qline_height
= intern ("line-height");
23495 staticpro (&Qline_height
);
23496 QCalign_to
= intern (":align-to");
23497 staticpro (&QCalign_to
);
23498 QCrelative_width
= intern (":relative-width");
23499 staticpro (&QCrelative_width
);
23500 QCrelative_height
= intern (":relative-height");
23501 staticpro (&QCrelative_height
);
23502 QCeval
= intern (":eval");
23503 staticpro (&QCeval
);
23504 QCpropertize
= intern (":propertize");
23505 staticpro (&QCpropertize
);
23506 QCfile
= intern (":file");
23507 staticpro (&QCfile
);
23508 Qfontified
= intern ("fontified");
23509 staticpro (&Qfontified
);
23510 Qfontification_functions
= intern ("fontification-functions");
23511 staticpro (&Qfontification_functions
);
23512 Qtrailing_whitespace
= intern ("trailing-whitespace");
23513 staticpro (&Qtrailing_whitespace
);
23514 Qescape_glyph
= intern ("escape-glyph");
23515 staticpro (&Qescape_glyph
);
23516 Qnobreak_space
= intern ("nobreak-space");
23517 staticpro (&Qnobreak_space
);
23518 Qimage
= intern ("image");
23519 staticpro (&Qimage
);
23520 QCmap
= intern (":map");
23521 staticpro (&QCmap
);
23522 QCpointer
= intern (":pointer");
23523 staticpro (&QCpointer
);
23524 Qrect
= intern ("rect");
23525 staticpro (&Qrect
);
23526 Qcircle
= intern ("circle");
23527 staticpro (&Qcircle
);
23528 Qpoly
= intern ("poly");
23529 staticpro (&Qpoly
);
23530 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23531 staticpro (&Qmessage_truncate_lines
);
23532 Qgrow_only
= intern ("grow-only");
23533 staticpro (&Qgrow_only
);
23534 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23535 staticpro (&Qinhibit_menubar_update
);
23536 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23537 staticpro (&Qinhibit_eval_during_redisplay
);
23538 Qposition
= intern ("position");
23539 staticpro (&Qposition
);
23540 Qbuffer_position
= intern ("buffer-position");
23541 staticpro (&Qbuffer_position
);
23542 Qobject
= intern ("object");
23543 staticpro (&Qobject
);
23544 Qbar
= intern ("bar");
23546 Qhbar
= intern ("hbar");
23547 staticpro (&Qhbar
);
23548 Qbox
= intern ("box");
23550 Qhollow
= intern ("hollow");
23551 staticpro (&Qhollow
);
23552 Qhand
= intern ("hand");
23553 staticpro (&Qhand
);
23554 Qarrow
= intern ("arrow");
23555 staticpro (&Qarrow
);
23556 Qtext
= intern ("text");
23557 staticpro (&Qtext
);
23558 Qrisky_local_variable
= intern ("risky-local-variable");
23559 staticpro (&Qrisky_local_variable
);
23560 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23561 staticpro (&Qinhibit_free_realized_faces
);
23563 list_of_error
= Fcons (Fcons (intern ("error"),
23564 Fcons (intern ("void-variable"), Qnil
)),
23566 staticpro (&list_of_error
);
23568 Qlast_arrow_position
= intern ("last-arrow-position");
23569 staticpro (&Qlast_arrow_position
);
23570 Qlast_arrow_string
= intern ("last-arrow-string");
23571 staticpro (&Qlast_arrow_string
);
23573 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23574 staticpro (&Qoverlay_arrow_string
);
23575 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23576 staticpro (&Qoverlay_arrow_bitmap
);
23578 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23579 staticpro (&echo_buffer
[0]);
23580 staticpro (&echo_buffer
[1]);
23582 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23583 staticpro (&echo_area_buffer
[0]);
23584 staticpro (&echo_area_buffer
[1]);
23586 Vmessages_buffer_name
= build_string ("*Messages*");
23587 staticpro (&Vmessages_buffer_name
);
23589 mode_line_proptrans_alist
= Qnil
;
23590 staticpro (&mode_line_proptrans_alist
);
23591 mode_line_string_list
= Qnil
;
23592 staticpro (&mode_line_string_list
);
23593 mode_line_string_face
= Qnil
;
23594 staticpro (&mode_line_string_face
);
23595 mode_line_string_face_prop
= Qnil
;
23596 staticpro (&mode_line_string_face_prop
);
23597 Vmode_line_unwind_vector
= Qnil
;
23598 staticpro (&Vmode_line_unwind_vector
);
23600 help_echo_string
= Qnil
;
23601 staticpro (&help_echo_string
);
23602 help_echo_object
= Qnil
;
23603 staticpro (&help_echo_object
);
23604 help_echo_window
= Qnil
;
23605 staticpro (&help_echo_window
);
23606 previous_help_echo_string
= Qnil
;
23607 staticpro (&previous_help_echo_string
);
23608 help_echo_pos
= -1;
23610 #ifdef HAVE_WINDOW_SYSTEM
23611 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23612 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23613 For example, if a block cursor is over a tab, it will be drawn as
23614 wide as that tab on the display. */);
23615 x_stretch_cursor_p
= 0;
23618 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23619 doc
: /* *Non-nil means highlight trailing whitespace.
23620 The face used for trailing whitespace is `trailing-whitespace'. */);
23621 Vshow_trailing_whitespace
= Qnil
;
23623 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23624 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23625 A value of t means highlight the character itself (for nobreak space,
23626 use face `nobreak-space').
23627 A value of nil means no highlighting.
23628 Other values mean display the escape glyph followed by an ordinary
23629 space or ordinary hyphen. */);
23630 Vnobreak_char_display
= Qt
;
23632 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23633 doc
: /* *The pointer shape to show in void text areas.
23634 A value of nil means to show the text pointer. Other options are `arrow',
23635 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23636 Vvoid_text_area_pointer
= Qarrow
;
23638 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23639 doc
: /* Non-nil means don't actually do any redisplay.
23640 This is used for internal purposes. */);
23641 Vinhibit_redisplay
= Qnil
;
23643 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23644 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23645 Vglobal_mode_string
= Qnil
;
23647 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23648 doc
: /* Marker for where to display an arrow on top of the buffer text.
23649 This must be the beginning of a line in order to work.
23650 See also `overlay-arrow-string'. */);
23651 Voverlay_arrow_position
= Qnil
;
23653 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23654 doc
: /* String to display as an arrow in non-window frames.
23655 See also `overlay-arrow-position'. */);
23656 Voverlay_arrow_string
= build_string ("=>");
23658 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23659 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23660 The symbols on this list are examined during redisplay to determine
23661 where to display overlay arrows. */);
23662 Voverlay_arrow_variable_list
23663 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23665 DEFVAR_INT ("scroll-step", &scroll_step
,
23666 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23667 If that fails to bring point back on frame, point is centered instead.
23668 If this is zero, point is always centered after it moves off frame.
23669 If you want scrolling to always be a line at a time, you should set
23670 `scroll-conservatively' to a large value rather than set this to 1. */);
23672 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23673 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23674 A value of zero means to scroll the text to center point vertically
23675 in the window. */);
23676 scroll_conservatively
= 0;
23678 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23679 doc
: /* *Number of lines of margin at the top and bottom of a window.
23680 Recenter the window whenever point gets within this many lines
23681 of the top or bottom of the window. */);
23684 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23685 doc
: /* Pixels per inch value for non-window system displays.
23686 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23687 Vdisplay_pixels_per_inch
= make_float (72.0);
23690 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23693 DEFVAR_BOOL ("truncate-partial-width-windows",
23694 &truncate_partial_width_windows
,
23695 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23696 truncate_partial_width_windows
= 1;
23698 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23699 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23700 Any other value means to use the appropriate face, `mode-line',
23701 `header-line', or `menu' respectively. */);
23702 mode_line_inverse_video
= 1;
23704 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23705 doc
: /* *Maximum buffer size for which line number should be displayed.
23706 If the buffer is bigger than this, the line number does not appear
23707 in the mode line. A value of nil means no limit. */);
23708 Vline_number_display_limit
= Qnil
;
23710 DEFVAR_INT ("line-number-display-limit-width",
23711 &line_number_display_limit_width
,
23712 doc
: /* *Maximum line width (in characters) for line number display.
23713 If the average length of the lines near point is bigger than this, then the
23714 line number may be omitted from the mode line. */);
23715 line_number_display_limit_width
= 200;
23717 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23718 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23719 highlight_nonselected_windows
= 0;
23721 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23722 doc
: /* Non-nil if more than one frame is visible on this display.
23723 Minibuffer-only frames don't count, but iconified frames do.
23724 This variable is not guaranteed to be accurate except while processing
23725 `frame-title-format' and `icon-title-format'. */);
23727 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23728 doc
: /* Template for displaying the title bar of visible frames.
23729 \(Assuming the window manager supports this feature.)
23730 This variable has the same structure as `mode-line-format' (which see),
23731 and is used only on frames for which no explicit name has been set
23732 \(see `modify-frame-parameters'). */);
23734 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23735 doc
: /* Template for displaying the title bar of an iconified frame.
23736 \(Assuming the window manager supports this feature.)
23737 This variable has the same structure as `mode-line-format' (which see),
23738 and is used only on frames for which no explicit name has been set
23739 \(see `modify-frame-parameters'). */);
23741 = Vframe_title_format
23742 = Fcons (intern ("multiple-frames"),
23743 Fcons (build_string ("%b"),
23744 Fcons (Fcons (empty_string
,
23745 Fcons (intern ("invocation-name"),
23746 Fcons (build_string ("@"),
23747 Fcons (intern ("system-name"),
23751 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23752 doc
: /* Maximum number of lines to keep in the message log buffer.
23753 If nil, disable message logging. If t, log messages but don't truncate
23754 the buffer when it becomes large. */);
23755 Vmessage_log_max
= make_number (50);
23757 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23758 doc
: /* Functions called before redisplay, if window sizes have changed.
23759 The value should be a list of functions that take one argument.
23760 Just before redisplay, for each frame, if any of its windows have changed
23761 size since the last redisplay, or have been split or deleted,
23762 all the functions in the list are called, with the frame as argument. */);
23763 Vwindow_size_change_functions
= Qnil
;
23765 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23766 doc
: /* List of functions to call before redisplaying a window with scrolling.
23767 Each function is called with two arguments, the window
23768 and its new display-start position. Note that the value of `window-end'
23769 is not valid when these functions are called. */);
23770 Vwindow_scroll_functions
= Qnil
;
23772 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23773 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23774 Each function is called with two arguments, the window and the end trigger value.
23775 See `set-window-redisplay-end-trigger'. */);
23776 Vredisplay_end_trigger_functions
= Qnil
;
23778 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23779 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23780 mouse_autoselect_window
= 0;
23782 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23783 doc
: /* *Non-nil means automatically resize tool-bars.
23784 This increases a tool-bar's height if not all tool-bar items are visible.
23785 It decreases a tool-bar's height when it would display blank lines
23787 auto_resize_tool_bars_p
= 1;
23789 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23790 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23791 auto_raise_tool_bar_buttons_p
= 1;
23793 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23794 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23795 make_cursor_line_fully_visible_p
= 1;
23797 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
23798 doc
: /* *Border below tool-bar in pixels.
23799 If an integer, use it as the height of the border.
23800 If it is one of `internal-border-width' or `border-width', use the
23801 value of the corresponding frame parameter.
23802 Otherwise, no border is added below the tool-bar. */);
23803 Vtool_bar_border
= Qinternal_border_width
;
23805 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23806 doc
: /* *Margin around tool-bar buttons in pixels.
23807 If an integer, use that for both horizontal and vertical margins.
23808 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23809 HORZ specifying the horizontal margin, and VERT specifying the
23810 vertical margin. */);
23811 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23813 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23814 doc
: /* *Relief thickness of tool-bar buttons. */);
23815 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23817 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23818 doc
: /* List of functions to call to fontify regions of text.
23819 Each function is called with one argument POS. Functions must
23820 fontify a region starting at POS in the current buffer, and give
23821 fontified regions the property `fontified'. */);
23822 Vfontification_functions
= Qnil
;
23823 Fmake_variable_buffer_local (Qfontification_functions
);
23825 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23826 &unibyte_display_via_language_environment
,
23827 doc
: /* *Non-nil means display unibyte text according to language environment.
23828 Specifically this means that unibyte non-ASCII characters
23829 are displayed by converting them to the equivalent multibyte characters
23830 according to the current language environment. As a result, they are
23831 displayed according to the current fontset. */);
23832 unibyte_display_via_language_environment
= 0;
23834 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23835 doc
: /* *Maximum height for resizing mini-windows.
23836 If a float, it specifies a fraction of the mini-window frame's height.
23837 If an integer, it specifies a number of lines. */);
23838 Vmax_mini_window_height
= make_float (0.25);
23840 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23841 doc
: /* *How to resize mini-windows.
23842 A value of nil means don't automatically resize mini-windows.
23843 A value of t means resize them to fit the text displayed in them.
23844 A value of `grow-only', the default, means let mini-windows grow
23845 only, until their display becomes empty, at which point the windows
23846 go back to their normal size. */);
23847 Vresize_mini_windows
= Qgrow_only
;
23849 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23850 doc
: /* Alist specifying how to blink the cursor off.
23851 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23852 `cursor-type' frame-parameter or variable equals ON-STATE,
23853 comparing using `equal', Emacs uses OFF-STATE to specify
23854 how to blink it off. ON-STATE and OFF-STATE are values for
23855 the `cursor-type' frame parameter.
23857 If a frame's ON-STATE has no entry in this list,
23858 the frame's other specifications determine how to blink the cursor off. */);
23859 Vblink_cursor_alist
= Qnil
;
23861 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23862 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23863 automatic_hscrolling_p
= 1;
23865 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23866 doc
: /* *How many columns away from the window edge point is allowed to get
23867 before automatic hscrolling will horizontally scroll the window. */);
23868 hscroll_margin
= 5;
23870 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23871 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23872 When point is less than `hscroll-margin' columns from the window
23873 edge, automatic hscrolling will scroll the window by the amount of columns
23874 determined by this variable. If its value is a positive integer, scroll that
23875 many columns. If it's a positive floating-point number, it specifies the
23876 fraction of the window's width to scroll. If it's nil or zero, point will be
23877 centered horizontally after the scroll. Any other value, including negative
23878 numbers, are treated as if the value were zero.
23880 Automatic hscrolling always moves point outside the scroll margin, so if
23881 point was more than scroll step columns inside the margin, the window will
23882 scroll more than the value given by the scroll step.
23884 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23885 and `scroll-right' overrides this variable's effect. */);
23886 Vhscroll_step
= make_number (0);
23888 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23889 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23890 Bind this around calls to `message' to let it take effect. */);
23891 message_truncate_lines
= 0;
23893 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23894 doc
: /* Normal hook run to update the menu bar definitions.
23895 Redisplay runs this hook before it redisplays the menu bar.
23896 This is used to update submenus such as Buffers,
23897 whose contents depend on various data. */);
23898 Vmenu_bar_update_hook
= Qnil
;
23900 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23901 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23902 inhibit_menubar_update
= 0;
23904 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23905 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23906 inhibit_eval_during_redisplay
= 0;
23908 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23909 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23910 inhibit_free_realized_faces
= 0;
23913 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23914 doc
: /* Inhibit try_window_id display optimization. */);
23915 inhibit_try_window_id
= 0;
23917 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23918 doc
: /* Inhibit try_window_reusing display optimization. */);
23919 inhibit_try_window_reusing
= 0;
23921 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23922 doc
: /* Inhibit try_cursor_movement display optimization. */);
23923 inhibit_try_cursor_movement
= 0;
23924 #endif /* GLYPH_DEBUG */
23928 /* Initialize this module when Emacs starts. */
23933 Lisp_Object root_window
;
23934 struct window
*mini_w
;
23936 current_header_line_height
= current_mode_line_height
= -1;
23938 CHARPOS (this_line_start_pos
) = 0;
23940 mini_w
= XWINDOW (minibuf_window
);
23941 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23943 if (!noninteractive
)
23945 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23948 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23949 set_window_height (root_window
,
23950 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23952 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23953 set_window_height (minibuf_window
, 1, 0);
23955 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23956 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23958 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23959 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23960 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23962 /* The default ellipsis glyphs `...'. */
23963 for (i
= 0; i
< 3; ++i
)
23964 default_invis_vector
[i
] = make_number ('.');
23968 /* Allocate the buffer for frame titles.
23969 Also used for `format-mode-line'. */
23971 mode_line_noprop_buf
= (char *) xmalloc (size
);
23972 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23973 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23974 mode_line_target
= MODE_LINE_DISPLAY
;
23977 help_echo_showing_p
= 0;
23981 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23982 (do not change this comment) */