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 it
->method
= GET_FROM_COMPOSITION
;
4452 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4453 /* For a terminal, draw only the first character of the
4455 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4456 it
->len
= (STRINGP (it
->string
)
4457 ? string_char_to_byte (it
->string
, end
)
4458 : CHAR_TO_BYTE (end
)) - pos_byte
;
4459 it
->stop_charpos
= end
;
4460 handled
= HANDLED_RETURN
;
4469 /***********************************************************************
4471 ***********************************************************************/
4473 /* The following structure is used to record overlay strings for
4474 later sorting in load_overlay_strings. */
4476 struct overlay_entry
4478 Lisp_Object overlay
;
4485 /* Set up iterator IT from overlay strings at its current position.
4486 Called from handle_stop. */
4488 static enum prop_handled
4489 handle_overlay_change (it
)
4492 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4493 return HANDLED_RECOMPUTE_PROPS
;
4495 return HANDLED_NORMALLY
;
4499 /* Set up the next overlay string for delivery by IT, if there is an
4500 overlay string to deliver. Called by set_iterator_to_next when the
4501 end of the current overlay string is reached. If there are more
4502 overlay strings to display, IT->string and
4503 IT->current.overlay_string_index are set appropriately here.
4504 Otherwise IT->string is set to nil. */
4507 next_overlay_string (it
)
4510 ++it
->current
.overlay_string_index
;
4511 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4513 /* No more overlay strings. Restore IT's settings to what
4514 they were before overlay strings were processed, and
4515 continue to deliver from current_buffer. */
4516 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4519 xassert (it
->stop_charpos
>= BEGV
4520 && it
->stop_charpos
<= it
->end_charpos
);
4522 it
->current
.overlay_string_index
= -1;
4523 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4524 it
->n_overlay_strings
= 0;
4525 it
->method
= GET_FROM_BUFFER
;
4527 /* If we're at the end of the buffer, record that we have
4528 processed the overlay strings there already, so that
4529 next_element_from_buffer doesn't try it again. */
4530 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4531 it
->overlay_strings_at_end_processed_p
= 1;
4533 /* If we have to display `...' for invisible text, set
4534 the iterator up for that. */
4535 if (display_ellipsis_p
)
4536 setup_for_ellipsis (it
, 0);
4540 /* There are more overlay strings to process. If
4541 IT->current.overlay_string_index has advanced to a position
4542 where we must load IT->overlay_strings with more strings, do
4544 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4546 if (it
->current
.overlay_string_index
&& i
== 0)
4547 load_overlay_strings (it
, 0);
4549 /* Initialize IT to deliver display elements from the overlay
4551 it
->string
= it
->overlay_strings
[i
];
4552 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4553 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4554 it
->method
= GET_FROM_STRING
;
4555 it
->stop_charpos
= 0;
4562 /* Compare two overlay_entry structures E1 and E2. Used as a
4563 comparison function for qsort in load_overlay_strings. Overlay
4564 strings for the same position are sorted so that
4566 1. All after-strings come in front of before-strings, except
4567 when they come from the same overlay.
4569 2. Within after-strings, strings are sorted so that overlay strings
4570 from overlays with higher priorities come first.
4572 2. Within before-strings, strings are sorted so that overlay
4573 strings from overlays with higher priorities come last.
4575 Value is analogous to strcmp. */
4579 compare_overlay_entries (e1
, e2
)
4582 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4583 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4586 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4588 /* Let after-strings appear in front of before-strings if
4589 they come from different overlays. */
4590 if (EQ (entry1
->overlay
, entry2
->overlay
))
4591 result
= entry1
->after_string_p
? 1 : -1;
4593 result
= entry1
->after_string_p
? -1 : 1;
4595 else if (entry1
->after_string_p
)
4596 /* After-strings sorted in order of decreasing priority. */
4597 result
= entry2
->priority
- entry1
->priority
;
4599 /* Before-strings sorted in order of increasing priority. */
4600 result
= entry1
->priority
- entry2
->priority
;
4606 /* Load the vector IT->overlay_strings with overlay strings from IT's
4607 current buffer position, or from CHARPOS if that is > 0. Set
4608 IT->n_overlays to the total number of overlay strings found.
4610 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4611 a time. On entry into load_overlay_strings,
4612 IT->current.overlay_string_index gives the number of overlay
4613 strings that have already been loaded by previous calls to this
4616 IT->add_overlay_start contains an additional overlay start
4617 position to consider for taking overlay strings from, if non-zero.
4618 This position comes into play when the overlay has an `invisible'
4619 property, and both before and after-strings. When we've skipped to
4620 the end of the overlay, because of its `invisible' property, we
4621 nevertheless want its before-string to appear.
4622 IT->add_overlay_start will contain the overlay start position
4625 Overlay strings are sorted so that after-string strings come in
4626 front of before-string strings. Within before and after-strings,
4627 strings are sorted by overlay priority. See also function
4628 compare_overlay_entries. */
4631 load_overlay_strings (it
, charpos
)
4635 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4636 Lisp_Object overlay
, window
, str
, invisible
;
4637 struct Lisp_Overlay
*ov
;
4640 int n
= 0, i
, j
, invis_p
;
4641 struct overlay_entry
*entries
4642 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4645 charpos
= IT_CHARPOS (*it
);
4647 /* Append the overlay string STRING of overlay OVERLAY to vector
4648 `entries' which has size `size' and currently contains `n'
4649 elements. AFTER_P non-zero means STRING is an after-string of
4651 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4654 Lisp_Object priority; \
4658 int new_size = 2 * size; \
4659 struct overlay_entry *old = entries; \
4661 (struct overlay_entry *) alloca (new_size \
4662 * sizeof *entries); \
4663 bcopy (old, entries, size * sizeof *entries); \
4667 entries[n].string = (STRING); \
4668 entries[n].overlay = (OVERLAY); \
4669 priority = Foverlay_get ((OVERLAY), Qpriority); \
4670 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4671 entries[n].after_string_p = (AFTER_P); \
4676 /* Process overlay before the overlay center. */
4677 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4679 XSETMISC (overlay
, ov
);
4680 xassert (OVERLAYP (overlay
));
4681 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4682 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4687 /* Skip this overlay if it doesn't start or end at IT's current
4689 if (end
!= charpos
&& start
!= charpos
)
4692 /* Skip this overlay if it doesn't apply to IT->w. */
4693 window
= Foverlay_get (overlay
, Qwindow
);
4694 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4697 /* If the text ``under'' the overlay is invisible, both before-
4698 and after-strings from this overlay are visible; start and
4699 end position are indistinguishable. */
4700 invisible
= Foverlay_get (overlay
, Qinvisible
);
4701 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4703 /* If overlay has a non-empty before-string, record it. */
4704 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4705 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4707 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4709 /* If overlay has a non-empty after-string, record it. */
4710 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4711 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4713 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4716 /* Process overlays after the overlay center. */
4717 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4719 XSETMISC (overlay
, ov
);
4720 xassert (OVERLAYP (overlay
));
4721 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4722 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4724 if (start
> charpos
)
4727 /* Skip this overlay if it doesn't start or end at IT's current
4729 if (end
!= charpos
&& start
!= charpos
)
4732 /* Skip this overlay if it doesn't apply to IT->w. */
4733 window
= Foverlay_get (overlay
, Qwindow
);
4734 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4737 /* If the text ``under'' the overlay is invisible, it has a zero
4738 dimension, and both before- and after-strings apply. */
4739 invisible
= Foverlay_get (overlay
, Qinvisible
);
4740 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4742 /* If overlay has a non-empty before-string, record it. */
4743 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4744 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4746 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4748 /* If overlay has a non-empty after-string, record it. */
4749 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4750 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4752 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4755 #undef RECORD_OVERLAY_STRING
4759 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4761 /* Record the total number of strings to process. */
4762 it
->n_overlay_strings
= n
;
4764 /* IT->current.overlay_string_index is the number of overlay strings
4765 that have already been consumed by IT. Copy some of the
4766 remaining overlay strings to IT->overlay_strings. */
4768 j
= it
->current
.overlay_string_index
;
4769 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4770 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4776 /* Get the first chunk of overlay strings at IT's current buffer
4777 position, or at CHARPOS if that is > 0. Value is non-zero if at
4778 least one overlay string was found. */
4781 get_overlay_strings (it
, charpos
)
4785 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4786 process. This fills IT->overlay_strings with strings, and sets
4787 IT->n_overlay_strings to the total number of strings to process.
4788 IT->pos.overlay_string_index has to be set temporarily to zero
4789 because load_overlay_strings needs this; it must be set to -1
4790 when no overlay strings are found because a zero value would
4791 indicate a position in the first overlay string. */
4792 it
->current
.overlay_string_index
= 0;
4793 load_overlay_strings (it
, charpos
);
4795 /* If we found overlay strings, set up IT to deliver display
4796 elements from the first one. Otherwise set up IT to deliver
4797 from current_buffer. */
4798 if (it
->n_overlay_strings
)
4800 /* Make sure we know settings in current_buffer, so that we can
4801 restore meaningful values when we're done with the overlay
4803 compute_stop_pos (it
);
4804 xassert (it
->face_id
>= 0);
4806 /* Save IT's settings. They are restored after all overlay
4807 strings have been processed. */
4808 xassert (it
->sp
== 0);
4811 /* Set up IT to deliver display elements from the first overlay
4813 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4814 it
->string
= it
->overlay_strings
[0];
4815 it
->stop_charpos
= 0;
4816 xassert (STRINGP (it
->string
));
4817 it
->end_charpos
= SCHARS (it
->string
);
4818 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4819 it
->method
= GET_FROM_STRING
;
4824 it
->current
.overlay_string_index
= -1;
4825 it
->method
= GET_FROM_BUFFER
;
4830 /* Value is non-zero if we found at least one overlay string. */
4831 return STRINGP (it
->string
);
4836 /***********************************************************************
4837 Saving and restoring state
4838 ***********************************************************************/
4840 /* Save current settings of IT on IT->stack. Called, for example,
4841 before setting up IT for an overlay string, to be able to restore
4842 IT's settings to what they were after the overlay string has been
4849 struct iterator_stack_entry
*p
;
4851 xassert (it
->sp
< 2);
4852 p
= it
->stack
+ it
->sp
;
4854 p
->stop_charpos
= it
->stop_charpos
;
4855 xassert (it
->face_id
>= 0);
4856 p
->face_id
= it
->face_id
;
4857 p
->string
= it
->string
;
4858 p
->pos
= it
->current
;
4859 p
->end_charpos
= it
->end_charpos
;
4860 p
->string_nchars
= it
->string_nchars
;
4862 p
->multibyte_p
= it
->multibyte_p
;
4863 p
->slice
= it
->slice
;
4864 p
->space_width
= it
->space_width
;
4865 p
->font_height
= it
->font_height
;
4866 p
->voffset
= it
->voffset
;
4867 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4868 p
->display_ellipsis_p
= 0;
4873 /* Restore IT's settings from IT->stack. Called, for example, when no
4874 more overlay strings must be processed, and we return to delivering
4875 display elements from a buffer, or when the end of a string from a
4876 `display' property is reached and we return to delivering display
4877 elements from an overlay string, or from a buffer. */
4883 struct iterator_stack_entry
*p
;
4885 xassert (it
->sp
> 0);
4887 p
= it
->stack
+ it
->sp
;
4888 it
->stop_charpos
= p
->stop_charpos
;
4889 it
->face_id
= p
->face_id
;
4890 it
->string
= p
->string
;
4891 it
->current
= p
->pos
;
4892 it
->end_charpos
= p
->end_charpos
;
4893 it
->string_nchars
= p
->string_nchars
;
4895 it
->multibyte_p
= p
->multibyte_p
;
4896 it
->slice
= p
->slice
;
4897 it
->space_width
= p
->space_width
;
4898 it
->font_height
= p
->font_height
;
4899 it
->voffset
= p
->voffset
;
4900 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4905 /***********************************************************************
4907 ***********************************************************************/
4909 /* Set IT's current position to the previous line start. */
4912 back_to_previous_line_start (it
)
4915 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4916 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4920 /* Move IT to the next line start.
4922 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4923 we skipped over part of the text (as opposed to moving the iterator
4924 continuously over the text). Otherwise, don't change the value
4927 Newlines may come from buffer text, overlay strings, or strings
4928 displayed via the `display' property. That's the reason we can't
4929 simply use find_next_newline_no_quit.
4931 Note that this function may not skip over invisible text that is so
4932 because of text properties and immediately follows a newline. If
4933 it would, function reseat_at_next_visible_line_start, when called
4934 from set_iterator_to_next, would effectively make invisible
4935 characters following a newline part of the wrong glyph row, which
4936 leads to wrong cursor motion. */
4939 forward_to_next_line_start (it
, skipped_p
)
4943 int old_selective
, newline_found_p
, n
;
4944 const int MAX_NEWLINE_DISTANCE
= 500;
4946 /* If already on a newline, just consume it to avoid unintended
4947 skipping over invisible text below. */
4948 if (it
->what
== IT_CHARACTER
4950 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4952 set_iterator_to_next (it
, 0);
4957 /* Don't handle selective display in the following. It's (a)
4958 unnecessary because it's done by the caller, and (b) leads to an
4959 infinite recursion because next_element_from_ellipsis indirectly
4960 calls this function. */
4961 old_selective
= it
->selective
;
4964 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4965 from buffer text. */
4966 for (n
= newline_found_p
= 0;
4967 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4968 n
+= STRINGP (it
->string
) ? 0 : 1)
4970 if (!get_next_display_element (it
))
4972 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4973 set_iterator_to_next (it
, 0);
4976 /* If we didn't find a newline near enough, see if we can use a
4978 if (!newline_found_p
)
4980 int start
= IT_CHARPOS (*it
);
4981 int limit
= find_next_newline_no_quit (start
, 1);
4984 xassert (!STRINGP (it
->string
));
4986 /* If there isn't any `display' property in sight, and no
4987 overlays, we can just use the position of the newline in
4989 if (it
->stop_charpos
>= limit
4990 || ((pos
= Fnext_single_property_change (make_number (start
),
4992 Qnil
, make_number (limit
)),
4994 && next_overlay_change (start
) == ZV
))
4996 IT_CHARPOS (*it
) = limit
;
4997 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4998 *skipped_p
= newline_found_p
= 1;
5002 while (get_next_display_element (it
)
5003 && !newline_found_p
)
5005 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5006 set_iterator_to_next (it
, 0);
5011 it
->selective
= old_selective
;
5012 return newline_found_p
;
5016 /* Set IT's current position to the previous visible line start. Skip
5017 invisible text that is so either due to text properties or due to
5018 selective display. Caution: this does not change IT->current_x and
5022 back_to_previous_visible_line_start (it
)
5025 while (IT_CHARPOS (*it
) > BEGV
)
5027 back_to_previous_line_start (it
);
5028 if (IT_CHARPOS (*it
) <= BEGV
)
5031 /* If selective > 0, then lines indented more than that values
5033 if (it
->selective
> 0
5034 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5035 (double) it
->selective
)) /* iftc */
5038 /* Check the newline before point for invisibility. */
5041 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5042 Qinvisible
, it
->window
);
5043 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5047 /* If newline has a display property that replaces the newline with something
5048 else (image or text), find start of overlay or interval and continue search
5050 if (IT_CHARPOS (*it
) > BEGV
)
5052 struct it it2
= *it
;
5055 Lisp_Object val
, overlay
;
5057 pos
= --IT_CHARPOS (it2
);
5060 if (handle_display_prop (&it2
) == HANDLED_RETURN
5061 && !NILP (val
= get_char_property_and_overlay
5062 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5063 && (OVERLAYP (overlay
)
5064 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5065 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5069 IT_CHARPOS (*it
) = beg
;
5070 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5078 xassert (IT_CHARPOS (*it
) >= BEGV
);
5079 xassert (IT_CHARPOS (*it
) == BEGV
5080 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5085 /* Reseat iterator IT at the previous visible line start. Skip
5086 invisible text that is so either due to text properties or due to
5087 selective display. At the end, update IT's overlay information,
5088 face information etc. */
5091 reseat_at_previous_visible_line_start (it
)
5094 back_to_previous_visible_line_start (it
);
5095 reseat (it
, it
->current
.pos
, 1);
5100 /* Reseat iterator IT on the next visible line start in the current
5101 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5102 preceding the line start. Skip over invisible text that is so
5103 because of selective display. Compute faces, overlays etc at the
5104 new position. Note that this function does not skip over text that
5105 is invisible because of text properties. */
5108 reseat_at_next_visible_line_start (it
, on_newline_p
)
5112 int newline_found_p
, skipped_p
= 0;
5114 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5116 /* Skip over lines that are invisible because they are indented
5117 more than the value of IT->selective. */
5118 if (it
->selective
> 0)
5119 while (IT_CHARPOS (*it
) < ZV
5120 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5121 (double) it
->selective
)) /* iftc */
5123 xassert (IT_BYTEPOS (*it
) == BEGV
5124 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5125 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5128 /* Position on the newline if that's what's requested. */
5129 if (on_newline_p
&& newline_found_p
)
5131 if (STRINGP (it
->string
))
5133 if (IT_STRING_CHARPOS (*it
) > 0)
5135 --IT_STRING_CHARPOS (*it
);
5136 --IT_STRING_BYTEPOS (*it
);
5139 else if (IT_CHARPOS (*it
) > BEGV
)
5143 reseat (it
, it
->current
.pos
, 0);
5147 reseat (it
, it
->current
.pos
, 0);
5154 /***********************************************************************
5155 Changing an iterator's position
5156 ***********************************************************************/
5158 /* Change IT's current position to POS in current_buffer. If FORCE_P
5159 is non-zero, always check for text properties at the new position.
5160 Otherwise, text properties are only looked up if POS >=
5161 IT->check_charpos of a property. */
5164 reseat (it
, pos
, force_p
)
5166 struct text_pos pos
;
5169 int original_pos
= IT_CHARPOS (*it
);
5171 reseat_1 (it
, pos
, 0);
5173 /* Determine where to check text properties. Avoid doing it
5174 where possible because text property lookup is very expensive. */
5176 || CHARPOS (pos
) > it
->stop_charpos
5177 || CHARPOS (pos
) < original_pos
)
5184 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5185 IT->stop_pos to POS, also. */
5188 reseat_1 (it
, pos
, set_stop_p
)
5190 struct text_pos pos
;
5193 /* Don't call this function when scanning a C string. */
5194 xassert (it
->s
== NULL
);
5196 /* POS must be a reasonable value. */
5197 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5199 it
->current
.pos
= it
->position
= pos
;
5200 XSETBUFFER (it
->object
, current_buffer
);
5201 it
->end_charpos
= ZV
;
5203 it
->current
.dpvec_index
= -1;
5204 it
->current
.overlay_string_index
= -1;
5205 IT_STRING_CHARPOS (*it
) = -1;
5206 IT_STRING_BYTEPOS (*it
) = -1;
5208 it
->method
= GET_FROM_BUFFER
;
5209 /* RMS: I added this to fix a bug in move_it_vertically_backward
5210 where it->area continued to relate to the starting point
5211 for the backward motion. Bug report from
5212 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
5213 However, I am not sure whether reseat still does the right thing
5214 in general after this change. */
5215 it
->area
= TEXT_AREA
;
5216 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5218 it
->face_before_selective_p
= 0;
5221 it
->stop_charpos
= CHARPOS (pos
);
5225 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5226 If S is non-null, it is a C string to iterate over. Otherwise,
5227 STRING gives a Lisp string to iterate over.
5229 If PRECISION > 0, don't return more then PRECISION number of
5230 characters from the string.
5232 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5233 characters have been returned. FIELD_WIDTH < 0 means an infinite
5236 MULTIBYTE = 0 means disable processing of multibyte characters,
5237 MULTIBYTE > 0 means enable it,
5238 MULTIBYTE < 0 means use IT->multibyte_p.
5240 IT must be initialized via a prior call to init_iterator before
5241 calling this function. */
5244 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5249 int precision
, field_width
, multibyte
;
5251 /* No region in strings. */
5252 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5254 /* No text property checks performed by default, but see below. */
5255 it
->stop_charpos
= -1;
5257 /* Set iterator position and end position. */
5258 bzero (&it
->current
, sizeof it
->current
);
5259 it
->current
.overlay_string_index
= -1;
5260 it
->current
.dpvec_index
= -1;
5261 xassert (charpos
>= 0);
5263 /* If STRING is specified, use its multibyteness, otherwise use the
5264 setting of MULTIBYTE, if specified. */
5266 it
->multibyte_p
= multibyte
> 0;
5270 xassert (STRINGP (string
));
5271 it
->string
= string
;
5273 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5274 it
->method
= GET_FROM_STRING
;
5275 it
->current
.string_pos
= string_pos (charpos
, string
);
5282 /* Note that we use IT->current.pos, not it->current.string_pos,
5283 for displaying C strings. */
5284 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5285 if (it
->multibyte_p
)
5287 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5288 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5292 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5293 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5296 it
->method
= GET_FROM_C_STRING
;
5299 /* PRECISION > 0 means don't return more than PRECISION characters
5301 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5302 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5304 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5305 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5306 FIELD_WIDTH < 0 means infinite field width. This is useful for
5307 padding with `-' at the end of a mode line. */
5308 if (field_width
< 0)
5309 field_width
= INFINITY
;
5310 if (field_width
> it
->end_charpos
- charpos
)
5311 it
->end_charpos
= charpos
+ field_width
;
5313 /* Use the standard display table for displaying strings. */
5314 if (DISP_TABLE_P (Vstandard_display_table
))
5315 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5317 it
->stop_charpos
= charpos
;
5323 /***********************************************************************
5325 ***********************************************************************/
5327 /* Map enum it_method value to corresponding next_element_from_* function. */
5329 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5331 next_element_from_buffer
,
5332 next_element_from_display_vector
,
5333 next_element_from_composition
,
5334 next_element_from_string
,
5335 next_element_from_c_string
,
5336 next_element_from_image
,
5337 next_element_from_stretch
5341 /* Load IT's display element fields with information about the next
5342 display element from the current position of IT. Value is zero if
5343 end of buffer (or C string) is reached. */
5345 static struct frame
*last_escape_glyph_frame
= NULL
;
5346 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5347 static int last_escape_glyph_merged_face_id
= 0;
5350 get_next_display_element (it
)
5353 /* Non-zero means that we found a display element. Zero means that
5354 we hit the end of what we iterate over. Performance note: the
5355 function pointer `method' used here turns out to be faster than
5356 using a sequence of if-statements. */
5360 success_p
= (*get_next_element
[it
->method
]) (it
);
5362 if (it
->what
== IT_CHARACTER
)
5364 /* Map via display table or translate control characters.
5365 IT->c, IT->len etc. have been set to the next character by
5366 the function call above. If we have a display table, and it
5367 contains an entry for IT->c, translate it. Don't do this if
5368 IT->c itself comes from a display table, otherwise we could
5369 end up in an infinite recursion. (An alternative could be to
5370 count the recursion depth of this function and signal an
5371 error when a certain maximum depth is reached.) Is it worth
5373 if (success_p
&& it
->dpvec
== NULL
)
5378 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5381 struct Lisp_Vector
*v
= XVECTOR (dv
);
5383 /* Return the first character from the display table
5384 entry, if not empty. If empty, don't display the
5385 current character. */
5388 it
->dpvec_char_len
= it
->len
;
5389 it
->dpvec
= v
->contents
;
5390 it
->dpend
= v
->contents
+ v
->size
;
5391 it
->current
.dpvec_index
= 0;
5392 it
->dpvec_face_id
= -1;
5393 it
->saved_face_id
= it
->face_id
;
5394 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5399 set_iterator_to_next (it
, 0);
5404 /* Translate control characters into `\003' or `^C' form.
5405 Control characters coming from a display table entry are
5406 currently not translated because we use IT->dpvec to hold
5407 the translation. This could easily be changed but I
5408 don't believe that it is worth doing.
5410 If it->multibyte_p is nonzero, eight-bit characters and
5411 non-printable multibyte characters are also translated to
5414 If it->multibyte_p is zero, eight-bit characters that
5415 don't have corresponding multibyte char code are also
5416 translated to octal form. */
5417 else if ((it
->c
< ' '
5418 && (it
->area
!= TEXT_AREA
5419 /* In mode line, treat \n like other crl chars. */
5421 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5422 || (it
->c
!= '\n' && it
->c
!= '\t')))
5426 || !CHAR_PRINTABLE_P (it
->c
)
5427 || (!NILP (Vnobreak_char_display
)
5428 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5429 || it
->c
== 0x920 || it
->c
== 0x92d
5430 || it
->c
== 0xe20 || it
->c
== 0xe2d
5431 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5433 && (!unibyte_display_via_language_environment
5434 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5436 /* IT->c is a control character which must be displayed
5437 either as '\003' or as `^C' where the '\\' and '^'
5438 can be defined in the display table. Fill
5439 IT->ctl_chars with glyphs for what we have to
5440 display. Then, set IT->dpvec to these glyphs. */
5443 int face_id
, lface_id
= 0 ;
5446 /* Handle control characters with ^. */
5448 if (it
->c
< 128 && it
->ctl_arrow_p
)
5450 g
= '^'; /* default glyph for Control */
5451 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5453 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5454 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5456 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5457 lface_id
= FAST_GLYPH_FACE (g
);
5461 g
= FAST_GLYPH_CHAR (g
);
5462 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5465 else if (it
->f
== last_escape_glyph_frame
5466 && it
->face_id
== last_escape_glyph_face_id
)
5468 face_id
= last_escape_glyph_merged_face_id
;
5472 /* Merge the escape-glyph face into the current face. */
5473 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5475 last_escape_glyph_frame
= it
->f
;
5476 last_escape_glyph_face_id
= it
->face_id
;
5477 last_escape_glyph_merged_face_id
= face_id
;
5480 XSETINT (it
->ctl_chars
[0], g
);
5482 XSETINT (it
->ctl_chars
[1], g
);
5484 goto display_control
;
5487 /* Handle non-break space in the mode where it only gets
5490 if (EQ (Vnobreak_char_display
, Qt
)
5491 && (it
->c
== 0x8a0 || it
->c
== 0x920
5492 || it
->c
== 0xe20 || it
->c
== 0xf20))
5494 /* Merge the no-break-space face into the current face. */
5495 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5499 XSETINT (it
->ctl_chars
[0], g
);
5501 goto display_control
;
5504 /* Handle sequences that start with the "escape glyph". */
5506 /* the default escape glyph is \. */
5507 escape_glyph
= '\\';
5510 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5511 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5513 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5514 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5518 /* The display table specified a face.
5519 Merge it into face_id and also into escape_glyph. */
5520 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5521 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5524 else if (it
->f
== last_escape_glyph_frame
5525 && it
->face_id
== last_escape_glyph_face_id
)
5527 face_id
= last_escape_glyph_merged_face_id
;
5531 /* Merge the escape-glyph face into the current face. */
5532 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5534 last_escape_glyph_frame
= it
->f
;
5535 last_escape_glyph_face_id
= it
->face_id
;
5536 last_escape_glyph_merged_face_id
= face_id
;
5539 /* Handle soft hyphens in the mode where they only get
5542 if (EQ (Vnobreak_char_display
, Qt
)
5543 && (it
->c
== 0x8ad || it
->c
== 0x92d
5544 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5547 XSETINT (it
->ctl_chars
[0], g
);
5549 goto display_control
;
5552 /* Handle non-break space and soft hyphen
5553 with the escape glyph. */
5555 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5556 || it
->c
== 0x920 || it
->c
== 0x92d
5557 || it
->c
== 0xe20 || it
->c
== 0xe2d
5558 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5560 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5561 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5562 XSETINT (it
->ctl_chars
[1], g
);
5564 goto display_control
;
5568 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5572 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5573 if (SINGLE_BYTE_CHAR_P (it
->c
))
5574 str
[0] = it
->c
, len
= 1;
5577 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5580 /* It's an invalid character, which shouldn't
5581 happen actually, but due to bugs it may
5582 happen. Let's print the char as is, there's
5583 not much meaningful we can do with it. */
5585 str
[1] = it
->c
>> 8;
5586 str
[2] = it
->c
>> 16;
5587 str
[3] = it
->c
>> 24;
5592 for (i
= 0; i
< len
; i
++)
5594 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5595 /* Insert three more glyphs into IT->ctl_chars for
5596 the octal display of the character. */
5597 g
= ((str
[i
] >> 6) & 7) + '0';
5598 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5599 g
= ((str
[i
] >> 3) & 7) + '0';
5600 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5601 g
= (str
[i
] & 7) + '0';
5602 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5608 /* Set up IT->dpvec and return first character from it. */
5609 it
->dpvec_char_len
= it
->len
;
5610 it
->dpvec
= it
->ctl_chars
;
5611 it
->dpend
= it
->dpvec
+ ctl_len
;
5612 it
->current
.dpvec_index
= 0;
5613 it
->dpvec_face_id
= face_id
;
5614 it
->saved_face_id
= it
->face_id
;
5615 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5621 /* Adjust face id for a multibyte character. There are no
5622 multibyte character in unibyte text. */
5625 && FRAME_WINDOW_P (it
->f
))
5627 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5628 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5632 /* Is this character the last one of a run of characters with
5633 box? If yes, set IT->end_of_box_run_p to 1. */
5640 it
->end_of_box_run_p
5641 = ((face_id
= face_after_it_pos (it
),
5642 face_id
!= it
->face_id
)
5643 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5644 face
->box
== FACE_NO_BOX
));
5647 /* Value is 0 if end of buffer or string reached. */
5652 /* Move IT to the next display element.
5654 RESEAT_P non-zero means if called on a newline in buffer text,
5655 skip to the next visible line start.
5657 Functions get_next_display_element and set_iterator_to_next are
5658 separate because I find this arrangement easier to handle than a
5659 get_next_display_element function that also increments IT's
5660 position. The way it is we can first look at an iterator's current
5661 display element, decide whether it fits on a line, and if it does,
5662 increment the iterator position. The other way around we probably
5663 would either need a flag indicating whether the iterator has to be
5664 incremented the next time, or we would have to implement a
5665 decrement position function which would not be easy to write. */
5668 set_iterator_to_next (it
, reseat_p
)
5672 /* Reset flags indicating start and end of a sequence of characters
5673 with box. Reset them at the start of this function because
5674 moving the iterator to a new position might set them. */
5675 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5679 case GET_FROM_BUFFER
:
5680 /* The current display element of IT is a character from
5681 current_buffer. Advance in the buffer, and maybe skip over
5682 invisible lines that are so because of selective display. */
5683 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5684 reseat_at_next_visible_line_start (it
, 0);
5687 xassert (it
->len
!= 0);
5688 IT_BYTEPOS (*it
) += it
->len
;
5689 IT_CHARPOS (*it
) += 1;
5690 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5694 case GET_FROM_COMPOSITION
:
5695 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5696 if (STRINGP (it
->string
))
5698 IT_STRING_BYTEPOS (*it
) += it
->len
;
5699 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5700 it
->method
= GET_FROM_STRING
;
5701 goto consider_string_end
;
5705 IT_BYTEPOS (*it
) += it
->len
;
5706 IT_CHARPOS (*it
) += it
->cmp_len
;
5707 it
->method
= GET_FROM_BUFFER
;
5711 case GET_FROM_C_STRING
:
5712 /* Current display element of IT is from a C string. */
5713 IT_BYTEPOS (*it
) += it
->len
;
5714 IT_CHARPOS (*it
) += 1;
5717 case GET_FROM_DISPLAY_VECTOR
:
5718 /* Current display element of IT is from a display table entry.
5719 Advance in the display table definition. Reset it to null if
5720 end reached, and continue with characters from buffers/
5722 ++it
->current
.dpvec_index
;
5724 /* Restore face of the iterator to what they were before the
5725 display vector entry (these entries may contain faces). */
5726 it
->face_id
= it
->saved_face_id
;
5728 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5730 int recheck_faces
= it
->ellipsis_p
;
5733 it
->method
= GET_FROM_C_STRING
;
5734 else if (STRINGP (it
->string
))
5735 it
->method
= GET_FROM_STRING
;
5737 it
->method
= GET_FROM_BUFFER
;
5740 it
->current
.dpvec_index
= -1;
5742 /* Skip over characters which were displayed via IT->dpvec. */
5743 if (it
->dpvec_char_len
< 0)
5744 reseat_at_next_visible_line_start (it
, 1);
5745 else if (it
->dpvec_char_len
> 0)
5747 if (it
->method
== GET_FROM_STRING
5748 && it
->n_overlay_strings
> 0)
5749 it
->ignore_overlay_strings_at_pos_p
= 1;
5750 it
->len
= it
->dpvec_char_len
;
5751 set_iterator_to_next (it
, reseat_p
);
5754 /* Maybe recheck faces after display vector */
5756 it
->stop_charpos
= IT_CHARPOS (*it
);
5760 case GET_FROM_STRING
:
5761 /* Current display element is a character from a Lisp string. */
5762 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5763 IT_STRING_BYTEPOS (*it
) += it
->len
;
5764 IT_STRING_CHARPOS (*it
) += 1;
5766 consider_string_end
:
5768 if (it
->current
.overlay_string_index
>= 0)
5770 /* IT->string is an overlay string. Advance to the
5771 next, if there is one. */
5772 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5773 next_overlay_string (it
);
5777 /* IT->string is not an overlay string. If we reached
5778 its end, and there is something on IT->stack, proceed
5779 with what is on the stack. This can be either another
5780 string, this time an overlay string, or a buffer. */
5781 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5785 if (STRINGP (it
->string
))
5786 goto consider_string_end
;
5787 it
->method
= GET_FROM_BUFFER
;
5792 case GET_FROM_IMAGE
:
5793 case GET_FROM_STRETCH
:
5794 /* The position etc with which we have to proceed are on
5795 the stack. The position may be at the end of a string,
5796 if the `display' property takes up the whole string. */
5797 xassert (it
->sp
> 0);
5800 if (STRINGP (it
->string
))
5802 it
->method
= GET_FROM_STRING
;
5803 goto consider_string_end
;
5805 it
->method
= GET_FROM_BUFFER
;
5809 /* There are no other methods defined, so this should be a bug. */
5813 xassert (it
->method
!= GET_FROM_STRING
5814 || (STRINGP (it
->string
)
5815 && IT_STRING_CHARPOS (*it
) >= 0));
5818 /* Load IT's display element fields with information about the next
5819 display element which comes from a display table entry or from the
5820 result of translating a control character to one of the forms `^C'
5823 IT->dpvec holds the glyphs to return as characters.
5824 IT->saved_face_id holds the face id before the display vector--
5825 it is restored into IT->face_idin set_iterator_to_next. */
5828 next_element_from_display_vector (it
)
5832 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5834 it
->face_id
= it
->saved_face_id
;
5836 if (INTEGERP (*it
->dpvec
)
5837 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5841 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5842 it
->c
= FAST_GLYPH_CHAR (g
);
5843 it
->len
= CHAR_BYTES (it
->c
);
5845 /* The entry may contain a face id to use. Such a face id is
5846 the id of a Lisp face, not a realized face. A face id of
5847 zero means no face is specified. */
5848 if (it
->dpvec_face_id
>= 0)
5849 it
->face_id
= it
->dpvec_face_id
;
5852 int lface_id
= FAST_GLYPH_FACE (g
);
5854 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5859 /* Display table entry is invalid. Return a space. */
5860 it
->c
= ' ', it
->len
= 1;
5862 /* Don't change position and object of the iterator here. They are
5863 still the values of the character that had this display table
5864 entry or was translated, and that's what we want. */
5865 it
->what
= IT_CHARACTER
;
5870 /* Load IT with the next display element from Lisp string IT->string.
5871 IT->current.string_pos is the current position within the string.
5872 If IT->current.overlay_string_index >= 0, the Lisp string is an
5876 next_element_from_string (it
)
5879 struct text_pos position
;
5881 xassert (STRINGP (it
->string
));
5882 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5883 position
= it
->current
.string_pos
;
5885 /* Time to check for invisible text? */
5886 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5887 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5891 /* Since a handler may have changed IT->method, we must
5893 return get_next_display_element (it
);
5896 if (it
->current
.overlay_string_index
>= 0)
5898 /* Get the next character from an overlay string. In overlay
5899 strings, There is no field width or padding with spaces to
5901 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5906 else if (STRING_MULTIBYTE (it
->string
))
5908 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5909 const unsigned char *s
= (SDATA (it
->string
)
5910 + IT_STRING_BYTEPOS (*it
));
5911 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5915 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5921 /* Get the next character from a Lisp string that is not an
5922 overlay string. Such strings come from the mode line, for
5923 example. We may have to pad with spaces, or truncate the
5924 string. See also next_element_from_c_string. */
5925 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5930 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5932 /* Pad with spaces. */
5933 it
->c
= ' ', it
->len
= 1;
5934 CHARPOS (position
) = BYTEPOS (position
) = -1;
5936 else if (STRING_MULTIBYTE (it
->string
))
5938 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5939 const unsigned char *s
= (SDATA (it
->string
)
5940 + IT_STRING_BYTEPOS (*it
));
5941 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5945 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5950 /* Record what we have and where it came from. Note that we store a
5951 buffer position in IT->position although it could arguably be a
5953 it
->what
= IT_CHARACTER
;
5954 it
->object
= it
->string
;
5955 it
->position
= position
;
5960 /* Load IT with next display element from C string IT->s.
5961 IT->string_nchars is the maximum number of characters to return
5962 from the string. IT->end_charpos may be greater than
5963 IT->string_nchars when this function is called, in which case we
5964 may have to return padding spaces. Value is zero if end of string
5965 reached, including padding spaces. */
5968 next_element_from_c_string (it
)
5974 it
->what
= IT_CHARACTER
;
5975 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5978 /* IT's position can be greater IT->string_nchars in case a field
5979 width or precision has been specified when the iterator was
5981 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5983 /* End of the game. */
5987 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5989 /* Pad with spaces. */
5990 it
->c
= ' ', it
->len
= 1;
5991 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5993 else if (it
->multibyte_p
)
5995 /* Implementation note: The calls to strlen apparently aren't a
5996 performance problem because there is no noticeable performance
5997 difference between Emacs running in unibyte or multibyte mode. */
5998 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5999 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6003 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6009 /* Set up IT to return characters from an ellipsis, if appropriate.
6010 The definition of the ellipsis glyphs may come from a display table
6011 entry. This function Fills IT with the first glyph from the
6012 ellipsis if an ellipsis is to be displayed. */
6015 next_element_from_ellipsis (it
)
6018 if (it
->selective_display_ellipsis_p
)
6019 setup_for_ellipsis (it
, it
->len
);
6022 /* The face at the current position may be different from the
6023 face we find after the invisible text. Remember what it
6024 was in IT->saved_face_id, and signal that it's there by
6025 setting face_before_selective_p. */
6026 it
->saved_face_id
= it
->face_id
;
6027 it
->method
= GET_FROM_BUFFER
;
6028 reseat_at_next_visible_line_start (it
, 1);
6029 it
->face_before_selective_p
= 1;
6032 return get_next_display_element (it
);
6036 /* Deliver an image display element. The iterator IT is already
6037 filled with image information (done in handle_display_prop). Value
6042 next_element_from_image (it
)
6045 it
->what
= IT_IMAGE
;
6050 /* Fill iterator IT with next display element from a stretch glyph
6051 property. IT->object is the value of the text property. Value is
6055 next_element_from_stretch (it
)
6058 it
->what
= IT_STRETCH
;
6063 /* Load IT with the next display element from current_buffer. Value
6064 is zero if end of buffer reached. IT->stop_charpos is the next
6065 position at which to stop and check for text properties or buffer
6069 next_element_from_buffer (it
)
6074 /* Check this assumption, otherwise, we would never enter the
6075 if-statement, below. */
6076 xassert (IT_CHARPOS (*it
) >= BEGV
6077 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6079 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6081 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6083 int overlay_strings_follow_p
;
6085 /* End of the game, except when overlay strings follow that
6086 haven't been returned yet. */
6087 if (it
->overlay_strings_at_end_processed_p
)
6088 overlay_strings_follow_p
= 0;
6091 it
->overlay_strings_at_end_processed_p
= 1;
6092 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6095 if (overlay_strings_follow_p
)
6096 success_p
= get_next_display_element (it
);
6100 it
->position
= it
->current
.pos
;
6107 return get_next_display_element (it
);
6112 /* No face changes, overlays etc. in sight, so just return a
6113 character from current_buffer. */
6116 /* Maybe run the redisplay end trigger hook. Performance note:
6117 This doesn't seem to cost measurable time. */
6118 if (it
->redisplay_end_trigger_charpos
6120 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6121 run_redisplay_end_trigger_hook (it
);
6123 /* Get the next character, maybe multibyte. */
6124 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6125 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6127 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6128 - IT_BYTEPOS (*it
));
6129 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6132 it
->c
= *p
, it
->len
= 1;
6134 /* Record what we have and where it came from. */
6135 it
->what
= IT_CHARACTER
;;
6136 it
->object
= it
->w
->buffer
;
6137 it
->position
= it
->current
.pos
;
6139 /* Normally we return the character found above, except when we
6140 really want to return an ellipsis for selective display. */
6145 /* A value of selective > 0 means hide lines indented more
6146 than that number of columns. */
6147 if (it
->selective
> 0
6148 && IT_CHARPOS (*it
) + 1 < ZV
6149 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6150 IT_BYTEPOS (*it
) + 1,
6151 (double) it
->selective
)) /* iftc */
6153 success_p
= next_element_from_ellipsis (it
);
6154 it
->dpvec_char_len
= -1;
6157 else if (it
->c
== '\r' && it
->selective
== -1)
6159 /* A value of selective == -1 means that everything from the
6160 CR to the end of the line is invisible, with maybe an
6161 ellipsis displayed for it. */
6162 success_p
= next_element_from_ellipsis (it
);
6163 it
->dpvec_char_len
= -1;
6168 /* Value is zero if end of buffer reached. */
6169 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6174 /* Run the redisplay end trigger hook for IT. */
6177 run_redisplay_end_trigger_hook (it
)
6180 Lisp_Object args
[3];
6182 /* IT->glyph_row should be non-null, i.e. we should be actually
6183 displaying something, or otherwise we should not run the hook. */
6184 xassert (it
->glyph_row
);
6186 /* Set up hook arguments. */
6187 args
[0] = Qredisplay_end_trigger_functions
;
6188 args
[1] = it
->window
;
6189 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6190 it
->redisplay_end_trigger_charpos
= 0;
6192 /* Since we are *trying* to run these functions, don't try to run
6193 them again, even if they get an error. */
6194 it
->w
->redisplay_end_trigger
= Qnil
;
6195 Frun_hook_with_args (3, args
);
6197 /* Notice if it changed the face of the character we are on. */
6198 handle_face_prop (it
);
6202 /* Deliver a composition display element. The iterator IT is already
6203 filled with composition information (done in
6204 handle_composition_prop). Value is always 1. */
6207 next_element_from_composition (it
)
6210 it
->what
= IT_COMPOSITION
;
6211 it
->position
= (STRINGP (it
->string
)
6212 ? it
->current
.string_pos
6219 /***********************************************************************
6220 Moving an iterator without producing glyphs
6221 ***********************************************************************/
6223 /* Check if iterator is at a position corresponding to a valid buffer
6224 position after some move_it_ call. */
6226 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6227 ((it)->method == GET_FROM_STRING \
6228 ? IT_STRING_CHARPOS (*it) == 0 \
6232 /* Move iterator IT to a specified buffer or X position within one
6233 line on the display without producing glyphs.
6235 OP should be a bit mask including some or all of these bits:
6236 MOVE_TO_X: Stop on reaching x-position TO_X.
6237 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6238 Regardless of OP's value, stop in reaching the end of the display line.
6240 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6241 This means, in particular, that TO_X includes window's horizontal
6244 The return value has several possible values that
6245 say what condition caused the scan to stop:
6247 MOVE_POS_MATCH_OR_ZV
6248 - when TO_POS or ZV was reached.
6251 -when TO_X was reached before TO_POS or ZV were reached.
6254 - when we reached the end of the display area and the line must
6258 - when we reached the end of the display area and the line is
6262 - when we stopped at a line end, i.e. a newline or a CR and selective
6265 static enum move_it_result
6266 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6268 int to_charpos
, to_x
, op
;
6270 enum move_it_result result
= MOVE_UNDEFINED
;
6271 struct glyph_row
*saved_glyph_row
;
6273 /* Don't produce glyphs in produce_glyphs. */
6274 saved_glyph_row
= it
->glyph_row
;
6275 it
->glyph_row
= NULL
;
6277 #define BUFFER_POS_REACHED_P() \
6278 ((op & MOVE_TO_POS) != 0 \
6279 && BUFFERP (it->object) \
6280 && IT_CHARPOS (*it) >= to_charpos \
6281 && (it->method == GET_FROM_BUFFER \
6282 || (it->method == GET_FROM_DISPLAY_VECTOR \
6283 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6288 int x
, i
, ascent
= 0, descent
= 0;
6290 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6291 if ((op
& MOVE_TO_POS
) != 0
6292 && BUFFERP (it
->object
)
6293 && it
->method
== GET_FROM_BUFFER
6294 && IT_CHARPOS (*it
) > to_charpos
)
6296 result
= MOVE_POS_MATCH_OR_ZV
;
6300 /* Stop when ZV reached.
6301 We used to stop here when TO_CHARPOS reached as well, but that is
6302 too soon if this glyph does not fit on this line. So we handle it
6303 explicitly below. */
6304 if (!get_next_display_element (it
)
6305 || (it
->truncate_lines_p
6306 && BUFFER_POS_REACHED_P ()))
6308 result
= MOVE_POS_MATCH_OR_ZV
;
6312 /* The call to produce_glyphs will get the metrics of the
6313 display element IT is loaded with. We record in x the
6314 x-position before this display element in case it does not
6318 /* Remember the line height so far in case the next element doesn't
6320 if (!it
->truncate_lines_p
)
6322 ascent
= it
->max_ascent
;
6323 descent
= it
->max_descent
;
6326 PRODUCE_GLYPHS (it
);
6328 if (it
->area
!= TEXT_AREA
)
6330 set_iterator_to_next (it
, 1);
6334 /* The number of glyphs we get back in IT->nglyphs will normally
6335 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6336 character on a terminal frame, or (iii) a line end. For the
6337 second case, IT->nglyphs - 1 padding glyphs will be present
6338 (on X frames, there is only one glyph produced for a
6339 composite character.
6341 The behavior implemented below means, for continuation lines,
6342 that as many spaces of a TAB as fit on the current line are
6343 displayed there. For terminal frames, as many glyphs of a
6344 multi-glyph character are displayed in the current line, too.
6345 This is what the old redisplay code did, and we keep it that
6346 way. Under X, the whole shape of a complex character must
6347 fit on the line or it will be completely displayed in the
6350 Note that both for tabs and padding glyphs, all glyphs have
6354 /* More than one glyph or glyph doesn't fit on line. All
6355 glyphs have the same width. */
6356 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6358 int x_before_this_char
= x
;
6359 int hpos_before_this_char
= it
->hpos
;
6361 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6363 new_x
= x
+ single_glyph_width
;
6365 /* We want to leave anything reaching TO_X to the caller. */
6366 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6368 if (BUFFER_POS_REACHED_P ())
6369 goto buffer_pos_reached
;
6371 result
= MOVE_X_REACHED
;
6374 else if (/* Lines are continued. */
6375 !it
->truncate_lines_p
6376 && (/* And glyph doesn't fit on the line. */
6377 new_x
> it
->last_visible_x
6378 /* Or it fits exactly and we're on a window
6380 || (new_x
== it
->last_visible_x
6381 && FRAME_WINDOW_P (it
->f
))))
6383 if (/* IT->hpos == 0 means the very first glyph
6384 doesn't fit on the line, e.g. a wide image. */
6386 || (new_x
== it
->last_visible_x
6387 && FRAME_WINDOW_P (it
->f
)))
6390 it
->current_x
= new_x
;
6392 /* The character's last glyph just barely fits
6394 if (i
== it
->nglyphs
- 1)
6396 /* If this is the destination position,
6397 return a position *before* it in this row,
6398 now that we know it fits in this row. */
6399 if (BUFFER_POS_REACHED_P ())
6401 it
->hpos
= hpos_before_this_char
;
6402 it
->current_x
= x_before_this_char
;
6403 result
= MOVE_POS_MATCH_OR_ZV
;
6407 set_iterator_to_next (it
, 1);
6408 #ifdef HAVE_WINDOW_SYSTEM
6409 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6411 if (!get_next_display_element (it
))
6413 result
= MOVE_POS_MATCH_OR_ZV
;
6416 if (BUFFER_POS_REACHED_P ())
6418 if (ITERATOR_AT_END_OF_LINE_P (it
))
6419 result
= MOVE_POS_MATCH_OR_ZV
;
6421 result
= MOVE_LINE_CONTINUED
;
6424 if (ITERATOR_AT_END_OF_LINE_P (it
))
6426 result
= MOVE_NEWLINE_OR_CR
;
6430 #endif /* HAVE_WINDOW_SYSTEM */
6436 it
->max_ascent
= ascent
;
6437 it
->max_descent
= descent
;
6440 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6442 result
= MOVE_LINE_CONTINUED
;
6445 else if (BUFFER_POS_REACHED_P ())
6446 goto buffer_pos_reached
;
6447 else if (new_x
> it
->first_visible_x
)
6449 /* Glyph is visible. Increment number of glyphs that
6450 would be displayed. */
6455 /* Glyph is completely off the left margin of the display
6456 area. Nothing to do. */
6460 if (result
!= MOVE_UNDEFINED
)
6463 else if (BUFFER_POS_REACHED_P ())
6467 it
->max_ascent
= ascent
;
6468 it
->max_descent
= descent
;
6469 result
= MOVE_POS_MATCH_OR_ZV
;
6472 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6474 /* Stop when TO_X specified and reached. This check is
6475 necessary here because of lines consisting of a line end,
6476 only. The line end will not produce any glyphs and we
6477 would never get MOVE_X_REACHED. */
6478 xassert (it
->nglyphs
== 0);
6479 result
= MOVE_X_REACHED
;
6483 /* Is this a line end? If yes, we're done. */
6484 if (ITERATOR_AT_END_OF_LINE_P (it
))
6486 result
= MOVE_NEWLINE_OR_CR
;
6490 /* The current display element has been consumed. Advance
6492 set_iterator_to_next (it
, 1);
6494 /* Stop if lines are truncated and IT's current x-position is
6495 past the right edge of the window now. */
6496 if (it
->truncate_lines_p
6497 && it
->current_x
>= it
->last_visible_x
)
6499 #ifdef HAVE_WINDOW_SYSTEM
6500 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6502 if (!get_next_display_element (it
)
6503 || BUFFER_POS_REACHED_P ())
6505 result
= MOVE_POS_MATCH_OR_ZV
;
6508 if (ITERATOR_AT_END_OF_LINE_P (it
))
6510 result
= MOVE_NEWLINE_OR_CR
;
6514 #endif /* HAVE_WINDOW_SYSTEM */
6515 result
= MOVE_LINE_TRUNCATED
;
6520 #undef BUFFER_POS_REACHED_P
6522 /* Restore the iterator settings altered at the beginning of this
6524 it
->glyph_row
= saved_glyph_row
;
6529 /* Move IT forward until it satisfies one or more of the criteria in
6530 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6532 OP is a bit-mask that specifies where to stop, and in particular,
6533 which of those four position arguments makes a difference. See the
6534 description of enum move_operation_enum.
6536 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6537 screen line, this function will set IT to the next position >
6541 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6543 int to_charpos
, to_x
, to_y
, to_vpos
;
6546 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6552 if (op
& MOVE_TO_VPOS
)
6554 /* If no TO_CHARPOS and no TO_X specified, stop at the
6555 start of the line TO_VPOS. */
6556 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6558 if (it
->vpos
== to_vpos
)
6564 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6568 /* TO_VPOS >= 0 means stop at TO_X in the line at
6569 TO_VPOS, or at TO_POS, whichever comes first. */
6570 if (it
->vpos
== to_vpos
)
6576 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6578 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6583 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6585 /* We have reached TO_X but not in the line we want. */
6586 skip
= move_it_in_display_line_to (it
, to_charpos
,
6588 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6596 else if (op
& MOVE_TO_Y
)
6598 struct it it_backup
;
6600 /* TO_Y specified means stop at TO_X in the line containing
6601 TO_Y---or at TO_CHARPOS if this is reached first. The
6602 problem is that we can't really tell whether the line
6603 contains TO_Y before we have completely scanned it, and
6604 this may skip past TO_X. What we do is to first scan to
6607 If TO_X is not specified, use a TO_X of zero. The reason
6608 is to make the outcome of this function more predictable.
6609 If we didn't use TO_X == 0, we would stop at the end of
6610 the line which is probably not what a caller would expect
6612 skip
= move_it_in_display_line_to (it
, to_charpos
,
6616 | (op
& MOVE_TO_POS
)));
6618 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6619 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6625 /* If TO_X was reached, we would like to know whether TO_Y
6626 is in the line. This can only be said if we know the
6627 total line height which requires us to scan the rest of
6629 if (skip
== MOVE_X_REACHED
)
6632 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6633 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6635 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6638 /* Now, decide whether TO_Y is in this line. */
6639 line_height
= it
->max_ascent
+ it
->max_descent
;
6640 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6642 if (to_y
>= it
->current_y
6643 && to_y
< it
->current_y
+ line_height
)
6645 if (skip
== MOVE_X_REACHED
)
6646 /* If TO_Y is in this line and TO_X was reached above,
6647 we scanned too far. We have to restore IT's settings
6648 to the ones before skipping. */
6652 else if (skip
== MOVE_X_REACHED
)
6655 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6663 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6667 case MOVE_POS_MATCH_OR_ZV
:
6671 case MOVE_NEWLINE_OR_CR
:
6672 set_iterator_to_next (it
, 1);
6673 it
->continuation_lines_width
= 0;
6676 case MOVE_LINE_TRUNCATED
:
6677 it
->continuation_lines_width
= 0;
6678 reseat_at_next_visible_line_start (it
, 0);
6679 if ((op
& MOVE_TO_POS
) != 0
6680 && IT_CHARPOS (*it
) > to_charpos
)
6687 case MOVE_LINE_CONTINUED
:
6688 it
->continuation_lines_width
+= it
->current_x
;
6695 /* Reset/increment for the next run. */
6696 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6697 it
->current_x
= it
->hpos
= 0;
6698 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6700 last_height
= it
->max_ascent
+ it
->max_descent
;
6701 last_max_ascent
= it
->max_ascent
;
6702 it
->max_ascent
= it
->max_descent
= 0;
6707 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6711 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6713 If DY > 0, move IT backward at least that many pixels. DY = 0
6714 means move IT backward to the preceding line start or BEGV. This
6715 function may move over more than DY pixels if IT->current_y - DY
6716 ends up in the middle of a line; in this case IT->current_y will be
6717 set to the top of the line moved to. */
6720 move_it_vertically_backward (it
, dy
)
6731 start_pos
= IT_CHARPOS (*it
);
6733 /* Estimate how many newlines we must move back. */
6734 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6736 /* Set the iterator's position that many lines back. */
6737 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6738 back_to_previous_visible_line_start (it
);
6740 /* Reseat the iterator here. When moving backward, we don't want
6741 reseat to skip forward over invisible text, set up the iterator
6742 to deliver from overlay strings at the new position etc. So,
6743 use reseat_1 here. */
6744 reseat_1 (it
, it
->current
.pos
, 1);
6746 /* We are now surely at a line start. */
6747 it
->current_x
= it
->hpos
= 0;
6748 it
->continuation_lines_width
= 0;
6750 /* Move forward and see what y-distance we moved. First move to the
6751 start of the next line so that we get its height. We need this
6752 height to be able to tell whether we reached the specified
6755 it2
.max_ascent
= it2
.max_descent
= 0;
6758 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6759 MOVE_TO_POS
| MOVE_TO_VPOS
);
6761 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6762 xassert (IT_CHARPOS (*it
) >= BEGV
);
6765 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6766 xassert (IT_CHARPOS (*it
) >= BEGV
);
6767 /* H is the actual vertical distance from the position in *IT
6768 and the starting position. */
6769 h
= it2
.current_y
- it
->current_y
;
6770 /* NLINES is the distance in number of lines. */
6771 nlines
= it2
.vpos
- it
->vpos
;
6773 /* Correct IT's y and vpos position
6774 so that they are relative to the starting point. */
6780 /* DY == 0 means move to the start of the screen line. The
6781 value of nlines is > 0 if continuation lines were involved. */
6783 move_it_by_lines (it
, nlines
, 1);
6785 /* I think this assert is bogus if buffer contains
6786 invisible text or images. KFS. */
6787 xassert (IT_CHARPOS (*it
) <= start_pos
);
6792 /* The y-position we try to reach, relative to *IT.
6793 Note that H has been subtracted in front of the if-statement. */
6794 int target_y
= it
->current_y
+ h
- dy
;
6795 int y0
= it3
.current_y
;
6796 int y1
= line_bottom_y (&it3
);
6797 int line_height
= y1
- y0
;
6799 /* If we did not reach target_y, try to move further backward if
6800 we can. If we moved too far backward, try to move forward. */
6801 if (target_y
< it
->current_y
6802 /* This is heuristic. In a window that's 3 lines high, with
6803 a line height of 13 pixels each, recentering with point
6804 on the bottom line will try to move -39/2 = 19 pixels
6805 backward. Try to avoid moving into the first line. */
6806 && (it
->current_y
- target_y
6807 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6808 && IT_CHARPOS (*it
) > BEGV
)
6810 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6811 target_y
- it
->current_y
));
6812 dy
= it
->current_y
- target_y
;
6813 goto move_further_back
;
6815 else if (target_y
>= it
->current_y
+ line_height
6816 && IT_CHARPOS (*it
) < ZV
)
6818 /* Should move forward by at least one line, maybe more.
6820 Note: Calling move_it_by_lines can be expensive on
6821 terminal frames, where compute_motion is used (via
6822 vmotion) to do the job, when there are very long lines
6823 and truncate-lines is nil. That's the reason for
6824 treating terminal frames specially here. */
6826 if (!FRAME_WINDOW_P (it
->f
))
6827 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6832 move_it_by_lines (it
, 1, 1);
6834 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6838 /* I think this assert is bogus if buffer contains
6839 invisible text or images. KFS. */
6840 xassert (IT_CHARPOS (*it
) >= BEGV
);
6847 /* Move IT by a specified amount of pixel lines DY. DY negative means
6848 move backwards. DY = 0 means move to start of screen line. At the
6849 end, IT will be on the start of a screen line. */
6852 move_it_vertically (it
, dy
)
6857 move_it_vertically_backward (it
, -dy
);
6860 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6861 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6862 MOVE_TO_POS
| MOVE_TO_Y
);
6863 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6865 /* If buffer ends in ZV without a newline, move to the start of
6866 the line to satisfy the post-condition. */
6867 if (IT_CHARPOS (*it
) == ZV
6869 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6870 move_it_by_lines (it
, 0, 0);
6875 /* Move iterator IT past the end of the text line it is in. */
6878 move_it_past_eol (it
)
6881 enum move_it_result rc
;
6883 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6884 if (rc
== MOVE_NEWLINE_OR_CR
)
6885 set_iterator_to_next (it
, 0);
6889 #if 0 /* Currently not used. */
6891 /* Return non-zero if some text between buffer positions START_CHARPOS
6892 and END_CHARPOS is invisible. IT->window is the window for text
6896 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6898 int start_charpos
, end_charpos
;
6900 Lisp_Object prop
, limit
;
6901 int invisible_found_p
;
6903 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6905 /* Is text at START invisible? */
6906 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6908 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6909 invisible_found_p
= 1;
6912 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6914 make_number (end_charpos
));
6915 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6918 return invisible_found_p
;
6924 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6925 negative means move up. DVPOS == 0 means move to the start of the
6926 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6927 NEED_Y_P is zero, IT->current_y will be left unchanged.
6929 Further optimization ideas: If we would know that IT->f doesn't use
6930 a face with proportional font, we could be faster for
6931 truncate-lines nil. */
6934 move_it_by_lines (it
, dvpos
, need_y_p
)
6936 int dvpos
, need_y_p
;
6938 struct position pos
;
6940 if (!FRAME_WINDOW_P (it
->f
))
6942 struct text_pos textpos
;
6944 /* We can use vmotion on frames without proportional fonts. */
6945 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6946 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6947 reseat (it
, textpos
, 1);
6948 it
->vpos
+= pos
.vpos
;
6949 it
->current_y
+= pos
.vpos
;
6951 else if (dvpos
== 0)
6953 /* DVPOS == 0 means move to the start of the screen line. */
6954 move_it_vertically_backward (it
, 0);
6955 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6956 /* Let next call to line_bottom_y calculate real line height */
6961 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6962 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6963 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6968 int start_charpos
, i
;
6970 /* Start at the beginning of the screen line containing IT's
6971 position. This may actually move vertically backwards,
6972 in case of overlays, so adjust dvpos accordingly. */
6974 move_it_vertically_backward (it
, 0);
6977 /* Go back -DVPOS visible lines and reseat the iterator there. */
6978 start_charpos
= IT_CHARPOS (*it
);
6979 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6980 back_to_previous_visible_line_start (it
);
6981 reseat (it
, it
->current
.pos
, 1);
6983 /* Move further back if we end up in a string or an image. */
6984 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6986 /* First try to move to start of display line. */
6988 move_it_vertically_backward (it
, 0);
6990 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6992 /* If start of line is still in string or image,
6993 move further back. */
6994 back_to_previous_visible_line_start (it
);
6995 reseat (it
, it
->current
.pos
, 1);
6999 it
->current_x
= it
->hpos
= 0;
7001 /* Above call may have moved too far if continuation lines
7002 are involved. Scan forward and see if it did. */
7004 it2
.vpos
= it2
.current_y
= 0;
7005 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7006 it
->vpos
-= it2
.vpos
;
7007 it
->current_y
-= it2
.current_y
;
7008 it
->current_x
= it
->hpos
= 0;
7010 /* If we moved too far back, move IT some lines forward. */
7011 if (it2
.vpos
> -dvpos
)
7013 int delta
= it2
.vpos
+ dvpos
;
7015 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7016 /* Move back again if we got too far ahead. */
7017 if (IT_CHARPOS (*it
) >= start_charpos
)
7023 /* Return 1 if IT points into the middle of a display vector. */
7026 in_display_vector_p (it
)
7029 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7030 && it
->current
.dpvec_index
> 0
7031 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7035 /***********************************************************************
7037 ***********************************************************************/
7040 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7044 add_to_log (format
, arg1
, arg2
)
7046 Lisp_Object arg1
, arg2
;
7048 Lisp_Object args
[3];
7049 Lisp_Object msg
, fmt
;
7052 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7055 /* Do nothing if called asynchronously. Inserting text into
7056 a buffer may call after-change-functions and alike and
7057 that would means running Lisp asynchronously. */
7058 if (handling_signal
)
7062 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7064 args
[0] = fmt
= build_string (format
);
7067 msg
= Fformat (3, args
);
7069 len
= SBYTES (msg
) + 1;
7070 SAFE_ALLOCA (buffer
, char *, len
);
7071 bcopy (SDATA (msg
), buffer
, len
);
7073 message_dolog (buffer
, len
- 1, 1, 0);
7080 /* Output a newline in the *Messages* buffer if "needs" one. */
7083 message_log_maybe_newline ()
7085 if (message_log_need_newline
)
7086 message_dolog ("", 0, 1, 0);
7090 /* Add a string M of length NBYTES to the message log, optionally
7091 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7092 nonzero, means interpret the contents of M as multibyte. This
7093 function calls low-level routines in order to bypass text property
7094 hooks, etc. which might not be safe to run.
7096 This may GC (insert may run before/after change hooks),
7097 so the buffer M must NOT point to a Lisp string. */
7100 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7102 int nbytes
, nlflag
, multibyte
;
7104 if (!NILP (Vmemory_full
))
7107 if (!NILP (Vmessage_log_max
))
7109 struct buffer
*oldbuf
;
7110 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7111 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7112 int point_at_end
= 0;
7114 Lisp_Object old_deactivate_mark
, tem
;
7115 struct gcpro gcpro1
;
7117 old_deactivate_mark
= Vdeactivate_mark
;
7118 oldbuf
= current_buffer
;
7119 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7120 current_buffer
->undo_list
= Qt
;
7122 oldpoint
= message_dolog_marker1
;
7123 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7124 oldbegv
= message_dolog_marker2
;
7125 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7126 oldzv
= message_dolog_marker3
;
7127 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7128 GCPRO1 (old_deactivate_mark
);
7136 BEGV_BYTE
= BEG_BYTE
;
7139 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7141 /* Insert the string--maybe converting multibyte to single byte
7142 or vice versa, so that all the text fits the buffer. */
7144 && NILP (current_buffer
->enable_multibyte_characters
))
7146 int i
, c
, char_bytes
;
7147 unsigned char work
[1];
7149 /* Convert a multibyte string to single-byte
7150 for the *Message* buffer. */
7151 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7153 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7154 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7156 : multibyte_char_to_unibyte (c
, Qnil
));
7157 insert_1_both (work
, 1, 1, 1, 0, 0);
7160 else if (! multibyte
7161 && ! NILP (current_buffer
->enable_multibyte_characters
))
7163 int i
, c
, char_bytes
;
7164 unsigned char *msg
= (unsigned char *) m
;
7165 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7166 /* Convert a single-byte string to multibyte
7167 for the *Message* buffer. */
7168 for (i
= 0; i
< nbytes
; i
++)
7170 c
= unibyte_char_to_multibyte (msg
[i
]);
7171 char_bytes
= CHAR_STRING (c
, str
);
7172 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7176 insert_1 (m
, nbytes
, 1, 0, 0);
7180 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7181 insert_1 ("\n", 1, 1, 0, 0);
7183 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7185 this_bol_byte
= PT_BYTE
;
7187 /* See if this line duplicates the previous one.
7188 If so, combine duplicates. */
7191 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7193 prev_bol_byte
= PT_BYTE
;
7195 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7196 this_bol
, this_bol_byte
);
7199 del_range_both (prev_bol
, prev_bol_byte
,
7200 this_bol
, this_bol_byte
, 0);
7206 /* If you change this format, don't forget to also
7207 change message_log_check_duplicate. */
7208 sprintf (dupstr
, " [%d times]", dup
);
7209 duplen
= strlen (dupstr
);
7210 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7211 insert_1 (dupstr
, duplen
, 1, 0, 1);
7216 /* If we have more than the desired maximum number of lines
7217 in the *Messages* buffer now, delete the oldest ones.
7218 This is safe because we don't have undo in this buffer. */
7220 if (NATNUMP (Vmessage_log_max
))
7222 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7223 -XFASTINT (Vmessage_log_max
) - 1, 0);
7224 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7227 BEGV
= XMARKER (oldbegv
)->charpos
;
7228 BEGV_BYTE
= marker_byte_position (oldbegv
);
7237 ZV
= XMARKER (oldzv
)->charpos
;
7238 ZV_BYTE
= marker_byte_position (oldzv
);
7242 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7244 /* We can't do Fgoto_char (oldpoint) because it will run some
7246 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7247 XMARKER (oldpoint
)->bytepos
);
7250 unchain_marker (XMARKER (oldpoint
));
7251 unchain_marker (XMARKER (oldbegv
));
7252 unchain_marker (XMARKER (oldzv
));
7254 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7255 set_buffer_internal (oldbuf
);
7257 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7258 message_log_need_newline
= !nlflag
;
7259 Vdeactivate_mark
= old_deactivate_mark
;
7264 /* We are at the end of the buffer after just having inserted a newline.
7265 (Note: We depend on the fact we won't be crossing the gap.)
7266 Check to see if the most recent message looks a lot like the previous one.
7267 Return 0 if different, 1 if the new one should just replace it, or a
7268 value N > 1 if we should also append " [N times]". */
7271 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7272 int prev_bol
, this_bol
;
7273 int prev_bol_byte
, this_bol_byte
;
7276 int len
= Z_BYTE
- 1 - this_bol_byte
;
7278 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7279 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7281 for (i
= 0; i
< len
; i
++)
7283 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7291 if (*p1
++ == ' ' && *p1
++ == '[')
7294 while (*p1
>= '0' && *p1
<= '9')
7295 n
= n
* 10 + *p1
++ - '0';
7296 if (strncmp (p1
, " times]\n", 8) == 0)
7303 /* Display an echo area message M with a specified length of NBYTES
7304 bytes. The string may include null characters. If M is 0, clear
7305 out any existing message, and let the mini-buffer text show
7308 This may GC, so the buffer M must NOT point to a Lisp string. */
7311 message2 (m
, nbytes
, multibyte
)
7316 /* First flush out any partial line written with print. */
7317 message_log_maybe_newline ();
7319 message_dolog (m
, nbytes
, 1, multibyte
);
7320 message2_nolog (m
, nbytes
, multibyte
);
7324 /* The non-logging counterpart of message2. */
7327 message2_nolog (m
, nbytes
, multibyte
)
7329 int nbytes
, multibyte
;
7331 struct frame
*sf
= SELECTED_FRAME ();
7332 message_enable_multibyte
= multibyte
;
7336 if (noninteractive_need_newline
)
7337 putc ('\n', stderr
);
7338 noninteractive_need_newline
= 0;
7340 fwrite (m
, nbytes
, 1, stderr
);
7341 if (cursor_in_echo_area
== 0)
7342 fprintf (stderr
, "\n");
7345 /* A null message buffer means that the frame hasn't really been
7346 initialized yet. Error messages get reported properly by
7347 cmd_error, so this must be just an informative message; toss it. */
7348 else if (INTERACTIVE
7349 && sf
->glyphs_initialized_p
7350 && FRAME_MESSAGE_BUF (sf
))
7352 Lisp_Object mini_window
;
7355 /* Get the frame containing the mini-buffer
7356 that the selected frame is using. */
7357 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7358 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7360 FRAME_SAMPLE_VISIBILITY (f
);
7361 if (FRAME_VISIBLE_P (sf
)
7362 && ! FRAME_VISIBLE_P (f
))
7363 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7367 set_message (m
, Qnil
, nbytes
, multibyte
);
7368 if (minibuffer_auto_raise
)
7369 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7372 clear_message (1, 1);
7374 do_pending_window_change (0);
7375 echo_area_display (1);
7376 do_pending_window_change (0);
7377 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7378 (*frame_up_to_date_hook
) (f
);
7383 /* Display an echo area message M with a specified length of NBYTES
7384 bytes. The string may include null characters. If M is not a
7385 string, clear out any existing message, and let the mini-buffer
7388 This function cancels echoing. */
7391 message3 (m
, nbytes
, multibyte
)
7396 struct gcpro gcpro1
;
7399 clear_message (1,1);
7402 /* First flush out any partial line written with print. */
7403 message_log_maybe_newline ();
7409 SAFE_ALLOCA (buffer
, char *, nbytes
);
7410 bcopy (SDATA (m
), buffer
, nbytes
);
7411 message_dolog (buffer
, nbytes
, 1, multibyte
);
7414 message3_nolog (m
, nbytes
, multibyte
);
7420 /* The non-logging version of message3.
7421 This does not cancel echoing, because it is used for echoing.
7422 Perhaps we need to make a separate function for echoing
7423 and make this cancel echoing. */
7426 message3_nolog (m
, nbytes
, multibyte
)
7428 int nbytes
, multibyte
;
7430 struct frame
*sf
= SELECTED_FRAME ();
7431 message_enable_multibyte
= multibyte
;
7435 if (noninteractive_need_newline
)
7436 putc ('\n', stderr
);
7437 noninteractive_need_newline
= 0;
7439 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7440 if (cursor_in_echo_area
== 0)
7441 fprintf (stderr
, "\n");
7444 /* A null message buffer means that the frame hasn't really been
7445 initialized yet. Error messages get reported properly by
7446 cmd_error, so this must be just an informative message; toss it. */
7447 else if (INTERACTIVE
7448 && sf
->glyphs_initialized_p
7449 && FRAME_MESSAGE_BUF (sf
))
7451 Lisp_Object mini_window
;
7455 /* Get the frame containing the mini-buffer
7456 that the selected frame is using. */
7457 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7458 frame
= XWINDOW (mini_window
)->frame
;
7461 FRAME_SAMPLE_VISIBILITY (f
);
7462 if (FRAME_VISIBLE_P (sf
)
7463 && !FRAME_VISIBLE_P (f
))
7464 Fmake_frame_visible (frame
);
7466 if (STRINGP (m
) && SCHARS (m
) > 0)
7468 set_message (NULL
, m
, nbytes
, multibyte
);
7469 if (minibuffer_auto_raise
)
7470 Fraise_frame (frame
);
7471 /* Assume we are not echoing.
7472 (If we are, echo_now will override this.) */
7473 echo_message_buffer
= Qnil
;
7476 clear_message (1, 1);
7478 do_pending_window_change (0);
7479 echo_area_display (1);
7480 do_pending_window_change (0);
7481 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7482 (*frame_up_to_date_hook
) (f
);
7487 /* Display a null-terminated echo area message M. If M is 0, clear
7488 out any existing message, and let the mini-buffer text show through.
7490 The buffer M must continue to exist until after the echo area gets
7491 cleared or some other message gets displayed there. Do not pass
7492 text that is stored in a Lisp string. Do not pass text in a buffer
7493 that was alloca'd. */
7499 message2 (m
, (m
? strlen (m
) : 0), 0);
7503 /* The non-logging counterpart of message1. */
7509 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7512 /* Display a message M which contains a single %s
7513 which gets replaced with STRING. */
7516 message_with_string (m
, string
, log
)
7521 CHECK_STRING (string
);
7527 if (noninteractive_need_newline
)
7528 putc ('\n', stderr
);
7529 noninteractive_need_newline
= 0;
7530 fprintf (stderr
, m
, SDATA (string
));
7531 if (cursor_in_echo_area
== 0)
7532 fprintf (stderr
, "\n");
7536 else if (INTERACTIVE
)
7538 /* The frame whose minibuffer we're going to display the message on.
7539 It may be larger than the selected frame, so we need
7540 to use its buffer, not the selected frame's buffer. */
7541 Lisp_Object mini_window
;
7542 struct frame
*f
, *sf
= SELECTED_FRAME ();
7544 /* Get the frame containing the minibuffer
7545 that the selected frame is using. */
7546 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7547 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7549 /* A null message buffer means that the frame hasn't really been
7550 initialized yet. Error messages get reported properly by
7551 cmd_error, so this must be just an informative message; toss it. */
7552 if (FRAME_MESSAGE_BUF (f
))
7554 Lisp_Object args
[2], message
;
7555 struct gcpro gcpro1
, gcpro2
;
7557 args
[0] = build_string (m
);
7558 args
[1] = message
= string
;
7559 GCPRO2 (args
[0], message
);
7562 message
= Fformat (2, args
);
7565 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7567 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7571 /* Print should start at the beginning of the message
7572 buffer next time. */
7573 message_buf_print
= 0;
7579 /* Dump an informative message to the minibuf. If M is 0, clear out
7580 any existing message, and let the mini-buffer text show through. */
7584 message (m
, a1
, a2
, a3
)
7586 EMACS_INT a1
, a2
, a3
;
7592 if (noninteractive_need_newline
)
7593 putc ('\n', stderr
);
7594 noninteractive_need_newline
= 0;
7595 fprintf (stderr
, m
, a1
, a2
, a3
);
7596 if (cursor_in_echo_area
== 0)
7597 fprintf (stderr
, "\n");
7601 else if (INTERACTIVE
)
7603 /* The frame whose mini-buffer we're going to display the message
7604 on. It may be larger than the selected frame, so we need to
7605 use its buffer, not the selected frame's buffer. */
7606 Lisp_Object mini_window
;
7607 struct frame
*f
, *sf
= SELECTED_FRAME ();
7609 /* Get the frame containing the mini-buffer
7610 that the selected frame is using. */
7611 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7612 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7614 /* A null message buffer means that the frame hasn't really been
7615 initialized yet. Error messages get reported properly by
7616 cmd_error, so this must be just an informative message; toss
7618 if (FRAME_MESSAGE_BUF (f
))
7629 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7630 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7632 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7633 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7635 #endif /* NO_ARG_ARRAY */
7637 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7642 /* Print should start at the beginning of the message
7643 buffer next time. */
7644 message_buf_print
= 0;
7650 /* The non-logging version of message. */
7653 message_nolog (m
, a1
, a2
, a3
)
7655 EMACS_INT a1
, a2
, a3
;
7657 Lisp_Object old_log_max
;
7658 old_log_max
= Vmessage_log_max
;
7659 Vmessage_log_max
= Qnil
;
7660 message (m
, a1
, a2
, a3
);
7661 Vmessage_log_max
= old_log_max
;
7665 /* Display the current message in the current mini-buffer. This is
7666 only called from error handlers in process.c, and is not time
7672 if (!NILP (echo_area_buffer
[0]))
7675 string
= Fcurrent_message ();
7676 message3 (string
, SBYTES (string
),
7677 !NILP (current_buffer
->enable_multibyte_characters
));
7682 /* Make sure echo area buffers in `echo_buffers' are live.
7683 If they aren't, make new ones. */
7686 ensure_echo_area_buffers ()
7690 for (i
= 0; i
< 2; ++i
)
7691 if (!BUFFERP (echo_buffer
[i
])
7692 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7695 Lisp_Object old_buffer
;
7698 old_buffer
= echo_buffer
[i
];
7699 sprintf (name
, " *Echo Area %d*", i
);
7700 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7701 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7703 for (j
= 0; j
< 2; ++j
)
7704 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7705 echo_area_buffer
[j
] = echo_buffer
[i
];
7710 /* Call FN with args A1..A4 with either the current or last displayed
7711 echo_area_buffer as current buffer.
7713 WHICH zero means use the current message buffer
7714 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7715 from echo_buffer[] and clear it.
7717 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7718 suitable buffer from echo_buffer[] and clear it.
7720 Value is what FN returns. */
7723 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7726 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7732 int this_one
, the_other
, clear_buffer_p
, rc
;
7733 int count
= SPECPDL_INDEX ();
7735 /* If buffers aren't live, make new ones. */
7736 ensure_echo_area_buffers ();
7741 this_one
= 0, the_other
= 1;
7743 this_one
= 1, the_other
= 0;
7745 /* Choose a suitable buffer from echo_buffer[] is we don't
7747 if (NILP (echo_area_buffer
[this_one
]))
7749 echo_area_buffer
[this_one
]
7750 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7751 ? echo_buffer
[the_other
]
7752 : echo_buffer
[this_one
]);
7756 buffer
= echo_area_buffer
[this_one
];
7758 /* Don't get confused by reusing the buffer used for echoing
7759 for a different purpose. */
7760 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7763 record_unwind_protect (unwind_with_echo_area_buffer
,
7764 with_echo_area_buffer_unwind_data (w
));
7766 /* Make the echo area buffer current. Note that for display
7767 purposes, it is not necessary that the displayed window's buffer
7768 == current_buffer, except for text property lookup. So, let's
7769 only set that buffer temporarily here without doing a full
7770 Fset_window_buffer. We must also change w->pointm, though,
7771 because otherwise an assertions in unshow_buffer fails, and Emacs
7773 set_buffer_internal_1 (XBUFFER (buffer
));
7777 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7780 current_buffer
->undo_list
= Qt
;
7781 current_buffer
->read_only
= Qnil
;
7782 specbind (Qinhibit_read_only
, Qt
);
7783 specbind (Qinhibit_modification_hooks
, Qt
);
7785 if (clear_buffer_p
&& Z
> BEG
)
7788 xassert (BEGV
>= BEG
);
7789 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7791 rc
= fn (a1
, a2
, a3
, a4
);
7793 xassert (BEGV
>= BEG
);
7794 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7796 unbind_to (count
, Qnil
);
7801 /* Save state that should be preserved around the call to the function
7802 FN called in with_echo_area_buffer. */
7805 with_echo_area_buffer_unwind_data (w
)
7811 /* Reduce consing by keeping one vector in
7812 Vwith_echo_area_save_vector. */
7813 vector
= Vwith_echo_area_save_vector
;
7814 Vwith_echo_area_save_vector
= Qnil
;
7817 vector
= Fmake_vector (make_number (7), Qnil
);
7819 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7820 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7821 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7825 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7826 AREF (vector
, i
) = w
->buffer
; ++i
;
7827 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7828 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7833 for (; i
< end
; ++i
)
7834 AREF (vector
, i
) = Qnil
;
7837 xassert (i
== ASIZE (vector
));
7842 /* Restore global state from VECTOR which was created by
7843 with_echo_area_buffer_unwind_data. */
7846 unwind_with_echo_area_buffer (vector
)
7849 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7850 Vdeactivate_mark
= AREF (vector
, 1);
7851 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7853 if (WINDOWP (AREF (vector
, 3)))
7856 Lisp_Object buffer
, charpos
, bytepos
;
7858 w
= XWINDOW (AREF (vector
, 3));
7859 buffer
= AREF (vector
, 4);
7860 charpos
= AREF (vector
, 5);
7861 bytepos
= AREF (vector
, 6);
7864 set_marker_both (w
->pointm
, buffer
,
7865 XFASTINT (charpos
), XFASTINT (bytepos
));
7868 Vwith_echo_area_save_vector
= vector
;
7873 /* Set up the echo area for use by print functions. MULTIBYTE_P
7874 non-zero means we will print multibyte. */
7877 setup_echo_area_for_printing (multibyte_p
)
7880 /* If we can't find an echo area any more, exit. */
7881 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7884 ensure_echo_area_buffers ();
7886 if (!message_buf_print
)
7888 /* A message has been output since the last time we printed.
7889 Choose a fresh echo area buffer. */
7890 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7891 echo_area_buffer
[0] = echo_buffer
[1];
7893 echo_area_buffer
[0] = echo_buffer
[0];
7895 /* Switch to that buffer and clear it. */
7896 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7897 current_buffer
->truncate_lines
= Qnil
;
7901 int count
= SPECPDL_INDEX ();
7902 specbind (Qinhibit_read_only
, Qt
);
7903 /* Note that undo recording is always disabled. */
7905 unbind_to (count
, Qnil
);
7907 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7909 /* Set up the buffer for the multibyteness we need. */
7911 != !NILP (current_buffer
->enable_multibyte_characters
))
7912 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7914 /* Raise the frame containing the echo area. */
7915 if (minibuffer_auto_raise
)
7917 struct frame
*sf
= SELECTED_FRAME ();
7918 Lisp_Object mini_window
;
7919 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7920 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7923 message_log_maybe_newline ();
7924 message_buf_print
= 1;
7928 if (NILP (echo_area_buffer
[0]))
7930 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7931 echo_area_buffer
[0] = echo_buffer
[1];
7933 echo_area_buffer
[0] = echo_buffer
[0];
7936 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7938 /* Someone switched buffers between print requests. */
7939 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7940 current_buffer
->truncate_lines
= Qnil
;
7946 /* Display an echo area message in window W. Value is non-zero if W's
7947 height is changed. If display_last_displayed_message_p is
7948 non-zero, display the message that was last displayed, otherwise
7949 display the current message. */
7952 display_echo_area (w
)
7955 int i
, no_message_p
, window_height_changed_p
, count
;
7957 /* Temporarily disable garbage collections while displaying the echo
7958 area. This is done because a GC can print a message itself.
7959 That message would modify the echo area buffer's contents while a
7960 redisplay of the buffer is going on, and seriously confuse
7962 count
= inhibit_garbage_collection ();
7964 /* If there is no message, we must call display_echo_area_1
7965 nevertheless because it resizes the window. But we will have to
7966 reset the echo_area_buffer in question to nil at the end because
7967 with_echo_area_buffer will sets it to an empty buffer. */
7968 i
= display_last_displayed_message_p
? 1 : 0;
7969 no_message_p
= NILP (echo_area_buffer
[i
]);
7971 window_height_changed_p
7972 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7973 display_echo_area_1
,
7974 (EMACS_INT
) w
, Qnil
, 0, 0);
7977 echo_area_buffer
[i
] = Qnil
;
7979 unbind_to (count
, Qnil
);
7980 return window_height_changed_p
;
7984 /* Helper for display_echo_area. Display the current buffer which
7985 contains the current echo area message in window W, a mini-window,
7986 a pointer to which is passed in A1. A2..A4 are currently not used.
7987 Change the height of W so that all of the message is displayed.
7988 Value is non-zero if height of W was changed. */
7991 display_echo_area_1 (a1
, a2
, a3
, a4
)
7996 struct window
*w
= (struct window
*) a1
;
7998 struct text_pos start
;
7999 int window_height_changed_p
= 0;
8001 /* Do this before displaying, so that we have a large enough glyph
8002 matrix for the display. If we can't get enough space for the
8003 whole text, display the last N lines. That works by setting w->start. */
8004 window_height_changed_p
= resize_mini_window (w
, 0);
8006 /* Use the starting position chosen by resize_mini_window. */
8007 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8010 clear_glyph_matrix (w
->desired_matrix
);
8011 XSETWINDOW (window
, w
);
8012 try_window (window
, start
, 0);
8014 return window_height_changed_p
;
8018 /* Resize the echo area window to exactly the size needed for the
8019 currently displayed message, if there is one. If a mini-buffer
8020 is active, don't shrink it. */
8023 resize_echo_area_exactly ()
8025 if (BUFFERP (echo_area_buffer
[0])
8026 && WINDOWP (echo_area_window
))
8028 struct window
*w
= XWINDOW (echo_area_window
);
8030 Lisp_Object resize_exactly
;
8032 if (minibuf_level
== 0)
8033 resize_exactly
= Qt
;
8035 resize_exactly
= Qnil
;
8037 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8038 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8041 ++windows_or_buffers_changed
;
8042 ++update_mode_lines
;
8043 redisplay_internal (0);
8049 /* Callback function for with_echo_area_buffer, when used from
8050 resize_echo_area_exactly. A1 contains a pointer to the window to
8051 resize, EXACTLY non-nil means resize the mini-window exactly to the
8052 size of the text displayed. A3 and A4 are not used. Value is what
8053 resize_mini_window returns. */
8056 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8058 Lisp_Object exactly
;
8061 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8065 /* Resize mini-window W to fit the size of its contents. EXACT:P
8066 means size the window exactly to the size needed. Otherwise, it's
8067 only enlarged until W's buffer is empty.
8069 Set W->start to the right place to begin display. If the whole
8070 contents fit, start at the beginning. Otherwise, start so as
8071 to make the end of the contents appear. This is particularly
8072 important for y-or-n-p, but seems desirable generally.
8074 Value is non-zero if the window height has been changed. */
8077 resize_mini_window (w
, exact_p
)
8081 struct frame
*f
= XFRAME (w
->frame
);
8082 int window_height_changed_p
= 0;
8084 xassert (MINI_WINDOW_P (w
));
8086 /* By default, start display at the beginning. */
8087 set_marker_both (w
->start
, w
->buffer
,
8088 BUF_BEGV (XBUFFER (w
->buffer
)),
8089 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8091 /* Don't resize windows while redisplaying a window; it would
8092 confuse redisplay functions when the size of the window they are
8093 displaying changes from under them. Such a resizing can happen,
8094 for instance, when which-func prints a long message while
8095 we are running fontification-functions. We're running these
8096 functions with safe_call which binds inhibit-redisplay to t. */
8097 if (!NILP (Vinhibit_redisplay
))
8100 /* Nil means don't try to resize. */
8101 if (NILP (Vresize_mini_windows
)
8102 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8105 if (!FRAME_MINIBUF_ONLY_P (f
))
8108 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8109 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8110 int height
, max_height
;
8111 int unit
= FRAME_LINE_HEIGHT (f
);
8112 struct text_pos start
;
8113 struct buffer
*old_current_buffer
= NULL
;
8115 if (current_buffer
!= XBUFFER (w
->buffer
))
8117 old_current_buffer
= current_buffer
;
8118 set_buffer_internal (XBUFFER (w
->buffer
));
8121 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8123 /* Compute the max. number of lines specified by the user. */
8124 if (FLOATP (Vmax_mini_window_height
))
8125 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8126 else if (INTEGERP (Vmax_mini_window_height
))
8127 max_height
= XINT (Vmax_mini_window_height
);
8129 max_height
= total_height
/ 4;
8131 /* Correct that max. height if it's bogus. */
8132 max_height
= max (1, max_height
);
8133 max_height
= min (total_height
, max_height
);
8135 /* Find out the height of the text in the window. */
8136 if (it
.truncate_lines_p
)
8141 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8142 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8143 height
= it
.current_y
+ last_height
;
8145 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8146 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8147 height
= (height
+ unit
- 1) / unit
;
8150 /* Compute a suitable window start. */
8151 if (height
> max_height
)
8153 height
= max_height
;
8154 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8155 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8156 start
= it
.current
.pos
;
8159 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8160 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8162 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8164 /* Let it grow only, until we display an empty message, in which
8165 case the window shrinks again. */
8166 if (height
> WINDOW_TOTAL_LINES (w
))
8168 int old_height
= WINDOW_TOTAL_LINES (w
);
8169 freeze_window_starts (f
, 1);
8170 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8171 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8173 else if (height
< WINDOW_TOTAL_LINES (w
)
8174 && (exact_p
|| BEGV
== ZV
))
8176 int old_height
= WINDOW_TOTAL_LINES (w
);
8177 freeze_window_starts (f
, 0);
8178 shrink_mini_window (w
);
8179 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8184 /* Always resize to exact size needed. */
8185 if (height
> WINDOW_TOTAL_LINES (w
))
8187 int old_height
= WINDOW_TOTAL_LINES (w
);
8188 freeze_window_starts (f
, 1);
8189 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8190 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8192 else if (height
< WINDOW_TOTAL_LINES (w
))
8194 int old_height
= WINDOW_TOTAL_LINES (w
);
8195 freeze_window_starts (f
, 0);
8196 shrink_mini_window (w
);
8200 freeze_window_starts (f
, 1);
8201 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8204 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8208 if (old_current_buffer
)
8209 set_buffer_internal (old_current_buffer
);
8212 return window_height_changed_p
;
8216 /* Value is the current message, a string, or nil if there is no
8224 if (NILP (echo_area_buffer
[0]))
8228 with_echo_area_buffer (0, 0, current_message_1
,
8229 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8231 echo_area_buffer
[0] = Qnil
;
8239 current_message_1 (a1
, a2
, a3
, a4
)
8244 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8247 *msg
= make_buffer_string (BEG
, Z
, 1);
8254 /* Push the current message on Vmessage_stack for later restauration
8255 by restore_message. Value is non-zero if the current message isn't
8256 empty. This is a relatively infrequent operation, so it's not
8257 worth optimizing. */
8263 msg
= current_message ();
8264 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8265 return STRINGP (msg
);
8269 /* Restore message display from the top of Vmessage_stack. */
8276 xassert (CONSP (Vmessage_stack
));
8277 msg
= XCAR (Vmessage_stack
);
8279 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8281 message3_nolog (msg
, 0, 0);
8285 /* Handler for record_unwind_protect calling pop_message. */
8288 pop_message_unwind (dummy
)
8295 /* Pop the top-most entry off Vmessage_stack. */
8300 xassert (CONSP (Vmessage_stack
));
8301 Vmessage_stack
= XCDR (Vmessage_stack
);
8305 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8306 exits. If the stack is not empty, we have a missing pop_message
8310 check_message_stack ()
8312 if (!NILP (Vmessage_stack
))
8317 /* Truncate to NCHARS what will be displayed in the echo area the next
8318 time we display it---but don't redisplay it now. */
8321 truncate_echo_area (nchars
)
8325 echo_area_buffer
[0] = Qnil
;
8326 /* A null message buffer means that the frame hasn't really been
8327 initialized yet. Error messages get reported properly by
8328 cmd_error, so this must be just an informative message; toss it. */
8329 else if (!noninteractive
8331 && !NILP (echo_area_buffer
[0]))
8333 struct frame
*sf
= SELECTED_FRAME ();
8334 if (FRAME_MESSAGE_BUF (sf
))
8335 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8340 /* Helper function for truncate_echo_area. Truncate the current
8341 message to at most NCHARS characters. */
8344 truncate_message_1 (nchars
, a2
, a3
, a4
)
8349 if (BEG
+ nchars
< Z
)
8350 del_range (BEG
+ nchars
, Z
);
8352 echo_area_buffer
[0] = Qnil
;
8357 /* Set the current message to a substring of S or STRING.
8359 If STRING is a Lisp string, set the message to the first NBYTES
8360 bytes from STRING. NBYTES zero means use the whole string. If
8361 STRING is multibyte, the message will be displayed multibyte.
8363 If S is not null, set the message to the first LEN bytes of S. LEN
8364 zero means use the whole string. MULTIBYTE_P non-zero means S is
8365 multibyte. Display the message multibyte in that case.
8367 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8368 to t before calling set_message_1 (which calls insert).
8372 set_message (s
, string
, nbytes
, multibyte_p
)
8375 int nbytes
, multibyte_p
;
8377 message_enable_multibyte
8378 = ((s
&& multibyte_p
)
8379 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8381 with_echo_area_buffer (0, 0, set_message_1
,
8382 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8383 message_buf_print
= 0;
8384 help_echo_showing_p
= 0;
8388 /* Helper function for set_message. Arguments have the same meaning
8389 as there, with A1 corresponding to S and A2 corresponding to STRING
8390 This function is called with the echo area buffer being
8394 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8397 EMACS_INT nbytes
, multibyte_p
;
8399 const char *s
= (const char *) a1
;
8400 Lisp_Object string
= a2
;
8402 /* Change multibyteness of the echo buffer appropriately. */
8403 if (message_enable_multibyte
8404 != !NILP (current_buffer
->enable_multibyte_characters
))
8405 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8407 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8409 /* Insert new message at BEG. */
8410 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8413 if (STRINGP (string
))
8418 nbytes
= SBYTES (string
);
8419 nchars
= string_byte_to_char (string
, nbytes
);
8421 /* This function takes care of single/multibyte conversion. We
8422 just have to ensure that the echo area buffer has the right
8423 setting of enable_multibyte_characters. */
8424 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8429 nbytes
= strlen (s
);
8431 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8433 /* Convert from multi-byte to single-byte. */
8435 unsigned char work
[1];
8437 /* Convert a multibyte string to single-byte. */
8438 for (i
= 0; i
< nbytes
; i
+= n
)
8440 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8441 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8443 : multibyte_char_to_unibyte (c
, Qnil
));
8444 insert_1_both (work
, 1, 1, 1, 0, 0);
8447 else if (!multibyte_p
8448 && !NILP (current_buffer
->enable_multibyte_characters
))
8450 /* Convert from single-byte to multi-byte. */
8452 const unsigned char *msg
= (const unsigned char *) s
;
8453 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8455 /* Convert a single-byte string to multibyte. */
8456 for (i
= 0; i
< nbytes
; i
++)
8458 c
= unibyte_char_to_multibyte (msg
[i
]);
8459 n
= CHAR_STRING (c
, str
);
8460 insert_1_both (str
, 1, n
, 1, 0, 0);
8464 insert_1 (s
, nbytes
, 1, 0, 0);
8471 /* Clear messages. CURRENT_P non-zero means clear the current
8472 message. LAST_DISPLAYED_P non-zero means clear the message
8476 clear_message (current_p
, last_displayed_p
)
8477 int current_p
, last_displayed_p
;
8481 echo_area_buffer
[0] = Qnil
;
8482 message_cleared_p
= 1;
8485 if (last_displayed_p
)
8486 echo_area_buffer
[1] = Qnil
;
8488 message_buf_print
= 0;
8491 /* Clear garbaged frames.
8493 This function is used where the old redisplay called
8494 redraw_garbaged_frames which in turn called redraw_frame which in
8495 turn called clear_frame. The call to clear_frame was a source of
8496 flickering. I believe a clear_frame is not necessary. It should
8497 suffice in the new redisplay to invalidate all current matrices,
8498 and ensure a complete redisplay of all windows. */
8501 clear_garbaged_frames ()
8505 Lisp_Object tail
, frame
;
8506 int changed_count
= 0;
8508 FOR_EACH_FRAME (tail
, frame
)
8510 struct frame
*f
= XFRAME (frame
);
8512 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8516 Fredraw_frame (frame
);
8517 f
->force_flush_display_p
= 1;
8519 clear_current_matrices (f
);
8528 ++windows_or_buffers_changed
;
8533 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8534 is non-zero update selected_frame. Value is non-zero if the
8535 mini-windows height has been changed. */
8538 echo_area_display (update_frame_p
)
8541 Lisp_Object mini_window
;
8544 int window_height_changed_p
= 0;
8545 struct frame
*sf
= SELECTED_FRAME ();
8547 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8548 w
= XWINDOW (mini_window
);
8549 f
= XFRAME (WINDOW_FRAME (w
));
8551 /* Don't display if frame is invisible or not yet initialized. */
8552 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8555 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8557 #ifdef HAVE_WINDOW_SYSTEM
8558 /* When Emacs starts, selected_frame may be a visible terminal
8559 frame, even if we run under a window system. If we let this
8560 through, a message would be displayed on the terminal. */
8561 if (EQ (selected_frame
, Vterminal_frame
)
8562 && !NILP (Vwindow_system
))
8564 #endif /* HAVE_WINDOW_SYSTEM */
8567 /* Redraw garbaged frames. */
8569 clear_garbaged_frames ();
8571 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8573 echo_area_window
= mini_window
;
8574 window_height_changed_p
= display_echo_area (w
);
8575 w
->must_be_updated_p
= 1;
8577 /* Update the display, unless called from redisplay_internal.
8578 Also don't update the screen during redisplay itself. The
8579 update will happen at the end of redisplay, and an update
8580 here could cause confusion. */
8581 if (update_frame_p
&& !redisplaying_p
)
8585 /* If the display update has been interrupted by pending
8586 input, update mode lines in the frame. Due to the
8587 pending input, it might have been that redisplay hasn't
8588 been called, so that mode lines above the echo area are
8589 garbaged. This looks odd, so we prevent it here. */
8590 if (!display_completed
)
8591 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8593 if (window_height_changed_p
8594 /* Don't do this if Emacs is shutting down. Redisplay
8595 needs to run hooks. */
8596 && !NILP (Vrun_hooks
))
8598 /* Must update other windows. Likewise as in other
8599 cases, don't let this update be interrupted by
8601 int count
= SPECPDL_INDEX ();
8602 specbind (Qredisplay_dont_pause
, Qt
);
8603 windows_or_buffers_changed
= 1;
8604 redisplay_internal (0);
8605 unbind_to (count
, Qnil
);
8607 else if (FRAME_WINDOW_P (f
) && n
== 0)
8609 /* Window configuration is the same as before.
8610 Can do with a display update of the echo area,
8611 unless we displayed some mode lines. */
8612 update_single_window (w
, 1);
8613 rif
->flush_display (f
);
8616 update_frame (f
, 1, 1);
8618 /* If cursor is in the echo area, make sure that the next
8619 redisplay displays the minibuffer, so that the cursor will
8620 be replaced with what the minibuffer wants. */
8621 if (cursor_in_echo_area
)
8622 ++windows_or_buffers_changed
;
8625 else if (!EQ (mini_window
, selected_window
))
8626 windows_or_buffers_changed
++;
8628 /* The current message is now also the last one displayed. */
8629 echo_area_buffer
[1] = echo_area_buffer
[0];
8631 /* Prevent redisplay optimization in redisplay_internal by resetting
8632 this_line_start_pos. This is done because the mini-buffer now
8633 displays the message instead of its buffer text. */
8634 if (EQ (mini_window
, selected_window
))
8635 CHARPOS (this_line_start_pos
) = 0;
8637 return window_height_changed_p
;
8642 /***********************************************************************
8643 Mode Lines and Frame Titles
8644 ***********************************************************************/
8646 /* A buffer for constructing non-propertized mode-line strings and
8647 frame titles in it; allocated from the heap in init_xdisp and
8648 resized as needed in store_mode_line_noprop_char. */
8650 static char *mode_line_noprop_buf
;
8652 /* The buffer's end, and a current output position in it. */
8654 static char *mode_line_noprop_buf_end
;
8655 static char *mode_line_noprop_ptr
;
8657 #define MODE_LINE_NOPROP_LEN(start) \
8658 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8661 MODE_LINE_DISPLAY
= 0,
8667 /* Alist that caches the results of :propertize.
8668 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8669 static Lisp_Object mode_line_proptrans_alist
;
8671 /* List of strings making up the mode-line. */
8672 static Lisp_Object mode_line_string_list
;
8674 /* Base face property when building propertized mode line string. */
8675 static Lisp_Object mode_line_string_face
;
8676 static Lisp_Object mode_line_string_face_prop
;
8679 /* Unwind data for mode line strings */
8681 static Lisp_Object Vmode_line_unwind_vector
;
8684 format_mode_line_unwind_data (obuf
, save_proptrans
)
8685 struct buffer
*obuf
;
8689 /* Reduce consing by keeping one vector in
8690 Vwith_echo_area_save_vector. */
8691 vector
= Vmode_line_unwind_vector
;
8692 Vmode_line_unwind_vector
= Qnil
;
8695 vector
= Fmake_vector (make_number (7), Qnil
);
8697 AREF (vector
, 0) = make_number (mode_line_target
);
8698 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8699 AREF (vector
, 2) = mode_line_string_list
;
8700 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8701 AREF (vector
, 4) = mode_line_string_face
;
8702 AREF (vector
, 5) = mode_line_string_face_prop
;
8705 XSETBUFFER (AREF (vector
, 6), obuf
);
8707 AREF (vector
, 6) = Qnil
;
8713 unwind_format_mode_line (vector
)
8716 mode_line_target
= XINT (AREF (vector
, 0));
8717 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8718 mode_line_string_list
= AREF (vector
, 2);
8719 if (! EQ (AREF (vector
, 3), Qt
))
8720 mode_line_proptrans_alist
= AREF (vector
, 3);
8721 mode_line_string_face
= AREF (vector
, 4);
8722 mode_line_string_face_prop
= AREF (vector
, 5);
8724 if (!NILP (AREF (vector
, 6)))
8726 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8727 AREF (vector
, 6) = Qnil
;
8730 Vmode_line_unwind_vector
= vector
;
8735 /* Store a single character C for the frame title in mode_line_noprop_buf.
8736 Re-allocate mode_line_noprop_buf if necessary. */
8740 store_mode_line_noprop_char (char c
)
8742 store_mode_line_noprop_char (c
)
8746 /* If output position has reached the end of the allocated buffer,
8747 double the buffer's size. */
8748 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8750 int len
= MODE_LINE_NOPROP_LEN (0);
8751 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8752 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8753 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8754 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8757 *mode_line_noprop_ptr
++ = c
;
8761 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8762 mode_line_noprop_ptr. STR is the string to store. Do not copy
8763 characters that yield more columns than PRECISION; PRECISION <= 0
8764 means copy the whole string. Pad with spaces until FIELD_WIDTH
8765 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8766 pad. Called from display_mode_element when it is used to build a
8770 store_mode_line_noprop (str
, field_width
, precision
)
8771 const unsigned char *str
;
8772 int field_width
, precision
;
8777 /* Copy at most PRECISION chars from STR. */
8778 nbytes
= strlen (str
);
8779 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8781 store_mode_line_noprop_char (*str
++);
8783 /* Fill up with spaces until FIELD_WIDTH reached. */
8784 while (field_width
> 0
8787 store_mode_line_noprop_char (' ');
8794 /***********************************************************************
8796 ***********************************************************************/
8798 #ifdef HAVE_WINDOW_SYSTEM
8800 /* Set the title of FRAME, if it has changed. The title format is
8801 Vicon_title_format if FRAME is iconified, otherwise it is
8802 frame_title_format. */
8805 x_consider_frame_title (frame
)
8808 struct frame
*f
= XFRAME (frame
);
8810 if (FRAME_WINDOW_P (f
)
8811 || FRAME_MINIBUF_ONLY_P (f
)
8812 || f
->explicit_name
)
8814 /* Do we have more than one visible frame on this X display? */
8821 int count
= SPECPDL_INDEX ();
8823 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8825 Lisp_Object other_frame
= XCAR (tail
);
8826 struct frame
*tf
= XFRAME (other_frame
);
8829 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8830 && !FRAME_MINIBUF_ONLY_P (tf
)
8831 && !EQ (other_frame
, tip_frame
)
8832 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8836 /* Set global variable indicating that multiple frames exist. */
8837 multiple_frames
= CONSP (tail
);
8839 /* Switch to the buffer of selected window of the frame. Set up
8840 mode_line_target so that display_mode_element will output into
8841 mode_line_noprop_buf; then display the title. */
8842 record_unwind_protect (unwind_format_mode_line
,
8843 format_mode_line_unwind_data (current_buffer
, 0));
8845 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8846 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8848 mode_line_target
= MODE_LINE_TITLE
;
8849 title_start
= MODE_LINE_NOPROP_LEN (0);
8850 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8851 NULL
, DEFAULT_FACE_ID
);
8852 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8853 len
= MODE_LINE_NOPROP_LEN (title_start
);
8854 title
= mode_line_noprop_buf
+ title_start
;
8855 unbind_to (count
, Qnil
);
8857 /* Set the title only if it's changed. This avoids consing in
8858 the common case where it hasn't. (If it turns out that we've
8859 already wasted too much time by walking through the list with
8860 display_mode_element, then we might need to optimize at a
8861 higher level than this.) */
8862 if (! STRINGP (f
->name
)
8863 || SBYTES (f
->name
) != len
8864 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8865 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8869 #endif /* not HAVE_WINDOW_SYSTEM */
8874 /***********************************************************************
8876 ***********************************************************************/
8879 /* Prepare for redisplay by updating menu-bar item lists when
8880 appropriate. This can call eval. */
8883 prepare_menu_bars ()
8886 struct gcpro gcpro1
, gcpro2
;
8888 Lisp_Object tooltip_frame
;
8890 #ifdef HAVE_WINDOW_SYSTEM
8891 tooltip_frame
= tip_frame
;
8893 tooltip_frame
= Qnil
;
8896 /* Update all frame titles based on their buffer names, etc. We do
8897 this before the menu bars so that the buffer-menu will show the
8898 up-to-date frame titles. */
8899 #ifdef HAVE_WINDOW_SYSTEM
8900 if (windows_or_buffers_changed
|| update_mode_lines
)
8902 Lisp_Object tail
, frame
;
8904 FOR_EACH_FRAME (tail
, frame
)
8907 if (!EQ (frame
, tooltip_frame
)
8908 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8909 x_consider_frame_title (frame
);
8912 #endif /* HAVE_WINDOW_SYSTEM */
8914 /* Update the menu bar item lists, if appropriate. This has to be
8915 done before any actual redisplay or generation of display lines. */
8916 all_windows
= (update_mode_lines
8917 || buffer_shared
> 1
8918 || windows_or_buffers_changed
);
8921 Lisp_Object tail
, frame
;
8922 int count
= SPECPDL_INDEX ();
8924 record_unwind_save_match_data ();
8926 FOR_EACH_FRAME (tail
, frame
)
8930 /* Ignore tooltip frame. */
8931 if (EQ (frame
, tooltip_frame
))
8934 /* If a window on this frame changed size, report that to
8935 the user and clear the size-change flag. */
8936 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8938 Lisp_Object functions
;
8940 /* Clear flag first in case we get an error below. */
8941 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8942 functions
= Vwindow_size_change_functions
;
8943 GCPRO2 (tail
, functions
);
8945 while (CONSP (functions
))
8947 call1 (XCAR (functions
), frame
);
8948 functions
= XCDR (functions
);
8954 update_menu_bar (f
, 0);
8955 #ifdef HAVE_WINDOW_SYSTEM
8956 update_tool_bar (f
, 0);
8961 unbind_to (count
, Qnil
);
8965 struct frame
*sf
= SELECTED_FRAME ();
8966 update_menu_bar (sf
, 1);
8967 #ifdef HAVE_WINDOW_SYSTEM
8968 update_tool_bar (sf
, 1);
8972 /* Motif needs this. See comment in xmenu.c. Turn it off when
8973 pending_menu_activation is not defined. */
8974 #ifdef USE_X_TOOLKIT
8975 pending_menu_activation
= 0;
8980 /* Update the menu bar item list for frame F. This has to be done
8981 before we start to fill in any display lines, because it can call
8984 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8987 update_menu_bar (f
, save_match_data
)
8989 int save_match_data
;
8992 register struct window
*w
;
8994 /* If called recursively during a menu update, do nothing. This can
8995 happen when, for instance, an activate-menubar-hook causes a
8997 if (inhibit_menubar_update
)
9000 window
= FRAME_SELECTED_WINDOW (f
);
9001 w
= XWINDOW (window
);
9003 #if 0 /* The if statement below this if statement used to include the
9004 condition !NILP (w->update_mode_line), rather than using
9005 update_mode_lines directly, and this if statement may have
9006 been added to make that condition work. Now the if
9007 statement below matches its comment, this isn't needed. */
9008 if (update_mode_lines
)
9009 w
->update_mode_line
= Qt
;
9012 if (FRAME_WINDOW_P (f
)
9014 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9015 || defined (USE_GTK)
9016 FRAME_EXTERNAL_MENU_BAR (f
)
9018 FRAME_MENU_BAR_LINES (f
) > 0
9020 : FRAME_MENU_BAR_LINES (f
) > 0)
9022 /* If the user has switched buffers or windows, we need to
9023 recompute to reflect the new bindings. But we'll
9024 recompute when update_mode_lines is set too; that means
9025 that people can use force-mode-line-update to request
9026 that the menu bar be recomputed. The adverse effect on
9027 the rest of the redisplay algorithm is about the same as
9028 windows_or_buffers_changed anyway. */
9029 if (windows_or_buffers_changed
9030 /* This used to test w->update_mode_line, but we believe
9031 there is no need to recompute the menu in that case. */
9032 || update_mode_lines
9033 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9034 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9035 != !NILP (w
->last_had_star
))
9036 || ((!NILP (Vtransient_mark_mode
)
9037 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9038 != !NILP (w
->region_showing
)))
9040 struct buffer
*prev
= current_buffer
;
9041 int count
= SPECPDL_INDEX ();
9043 specbind (Qinhibit_menubar_update
, Qt
);
9045 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9046 if (save_match_data
)
9047 record_unwind_save_match_data ();
9048 if (NILP (Voverriding_local_map_menu_flag
))
9050 specbind (Qoverriding_terminal_local_map
, Qnil
);
9051 specbind (Qoverriding_local_map
, Qnil
);
9054 /* Run the Lucid hook. */
9055 safe_run_hooks (Qactivate_menubar_hook
);
9057 /* If it has changed current-menubar from previous value,
9058 really recompute the menu-bar from the value. */
9059 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9060 call0 (Qrecompute_lucid_menubar
);
9062 safe_run_hooks (Qmenu_bar_update_hook
);
9063 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9065 /* Redisplay the menu bar in case we changed it. */
9066 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9067 || defined (USE_GTK)
9068 if (FRAME_WINDOW_P (f
))
9071 /* All frames on Mac OS share the same menubar. So only
9072 the selected frame should be allowed to set it. */
9073 if (f
== SELECTED_FRAME ())
9075 set_frame_menubar (f
, 0, 0);
9078 /* On a terminal screen, the menu bar is an ordinary screen
9079 line, and this makes it get updated. */
9080 w
->update_mode_line
= Qt
;
9081 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9082 /* In the non-toolkit version, the menu bar is an ordinary screen
9083 line, and this makes it get updated. */
9084 w
->update_mode_line
= Qt
;
9085 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9087 unbind_to (count
, Qnil
);
9088 set_buffer_internal_1 (prev
);
9095 /***********************************************************************
9097 ***********************************************************************/
9099 #ifdef HAVE_WINDOW_SYSTEM
9102 Nominal cursor position -- where to draw output.
9103 HPOS and VPOS are window relative glyph matrix coordinates.
9104 X and Y are window relative pixel coordinates. */
9106 struct cursor_pos output_cursor
;
9110 Set the global variable output_cursor to CURSOR. All cursor
9111 positions are relative to updated_window. */
9114 set_output_cursor (cursor
)
9115 struct cursor_pos
*cursor
;
9117 output_cursor
.hpos
= cursor
->hpos
;
9118 output_cursor
.vpos
= cursor
->vpos
;
9119 output_cursor
.x
= cursor
->x
;
9120 output_cursor
.y
= cursor
->y
;
9125 Set a nominal cursor position.
9127 HPOS and VPOS are column/row positions in a window glyph matrix. X
9128 and Y are window text area relative pixel positions.
9130 If this is done during an update, updated_window will contain the
9131 window that is being updated and the position is the future output
9132 cursor position for that window. If updated_window is null, use
9133 selected_window and display the cursor at the given position. */
9136 x_cursor_to (vpos
, hpos
, y
, x
)
9137 int vpos
, hpos
, y
, x
;
9141 /* If updated_window is not set, work on selected_window. */
9145 w
= XWINDOW (selected_window
);
9147 /* Set the output cursor. */
9148 output_cursor
.hpos
= hpos
;
9149 output_cursor
.vpos
= vpos
;
9150 output_cursor
.x
= x
;
9151 output_cursor
.y
= y
;
9153 /* If not called as part of an update, really display the cursor.
9154 This will also set the cursor position of W. */
9155 if (updated_window
== NULL
)
9158 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9159 if (rif
->flush_display_optional
)
9160 rif
->flush_display_optional (SELECTED_FRAME ());
9165 #endif /* HAVE_WINDOW_SYSTEM */
9168 /***********************************************************************
9170 ***********************************************************************/
9172 #ifdef HAVE_WINDOW_SYSTEM
9174 /* Where the mouse was last time we reported a mouse event. */
9176 FRAME_PTR last_mouse_frame
;
9178 /* Tool-bar item index of the item on which a mouse button was pressed
9181 int last_tool_bar_item
;
9184 /* Update the tool-bar item list for frame F. This has to be done
9185 before we start to fill in any display lines. Called from
9186 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9187 and restore it here. */
9190 update_tool_bar (f
, save_match_data
)
9192 int save_match_data
;
9195 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9197 int do_update
= WINDOWP (f
->tool_bar_window
)
9198 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9206 window
= FRAME_SELECTED_WINDOW (f
);
9207 w
= XWINDOW (window
);
9209 /* If the user has switched buffers or windows, we need to
9210 recompute to reflect the new bindings. But we'll
9211 recompute when update_mode_lines is set too; that means
9212 that people can use force-mode-line-update to request
9213 that the menu bar be recomputed. The adverse effect on
9214 the rest of the redisplay algorithm is about the same as
9215 windows_or_buffers_changed anyway. */
9216 if (windows_or_buffers_changed
9217 || !NILP (w
->update_mode_line
)
9218 || update_mode_lines
9219 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9220 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9221 != !NILP (w
->last_had_star
))
9222 || ((!NILP (Vtransient_mark_mode
)
9223 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9224 != !NILP (w
->region_showing
)))
9226 struct buffer
*prev
= current_buffer
;
9227 int count
= SPECPDL_INDEX ();
9228 Lisp_Object new_tool_bar
;
9230 struct gcpro gcpro1
;
9232 /* Set current_buffer to the buffer of the selected
9233 window of the frame, so that we get the right local
9235 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9237 /* Save match data, if we must. */
9238 if (save_match_data
)
9239 record_unwind_save_match_data ();
9241 /* Make sure that we don't accidentally use bogus keymaps. */
9242 if (NILP (Voverriding_local_map_menu_flag
))
9244 specbind (Qoverriding_terminal_local_map
, Qnil
);
9245 specbind (Qoverriding_local_map
, Qnil
);
9248 GCPRO1 (new_tool_bar
);
9250 /* Build desired tool-bar items from keymaps. */
9251 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9254 /* Redisplay the tool-bar if we changed it. */
9255 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9257 /* Redisplay that happens asynchronously due to an expose event
9258 may access f->tool_bar_items. Make sure we update both
9259 variables within BLOCK_INPUT so no such event interrupts. */
9261 f
->tool_bar_items
= new_tool_bar
;
9262 f
->n_tool_bar_items
= new_n_tool_bar
;
9263 w
->update_mode_line
= Qt
;
9269 unbind_to (count
, Qnil
);
9270 set_buffer_internal_1 (prev
);
9276 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9277 F's desired tool-bar contents. F->tool_bar_items must have
9278 been set up previously by calling prepare_menu_bars. */
9281 build_desired_tool_bar_string (f
)
9284 int i
, size
, size_needed
;
9285 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9286 Lisp_Object image
, plist
, props
;
9288 image
= plist
= props
= Qnil
;
9289 GCPRO3 (image
, plist
, props
);
9291 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9292 Otherwise, make a new string. */
9294 /* The size of the string we might be able to reuse. */
9295 size
= (STRINGP (f
->desired_tool_bar_string
)
9296 ? SCHARS (f
->desired_tool_bar_string
)
9299 /* We need one space in the string for each image. */
9300 size_needed
= f
->n_tool_bar_items
;
9302 /* Reuse f->desired_tool_bar_string, if possible. */
9303 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9304 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9308 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9309 Fremove_text_properties (make_number (0), make_number (size
),
9310 props
, f
->desired_tool_bar_string
);
9313 /* Put a `display' property on the string for the images to display,
9314 put a `menu_item' property on tool-bar items with a value that
9315 is the index of the item in F's tool-bar item vector. */
9316 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9318 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9320 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9321 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9322 int hmargin
, vmargin
, relief
, idx
, end
;
9323 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9325 /* If image is a vector, choose the image according to the
9327 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9328 if (VECTORP (image
))
9332 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9333 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9336 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9337 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9339 xassert (ASIZE (image
) >= idx
);
9340 image
= AREF (image
, idx
);
9345 /* Ignore invalid image specifications. */
9346 if (!valid_image_p (image
))
9349 /* Display the tool-bar button pressed, or depressed. */
9350 plist
= Fcopy_sequence (XCDR (image
));
9352 /* Compute margin and relief to draw. */
9353 relief
= (tool_bar_button_relief
>= 0
9354 ? tool_bar_button_relief
9355 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9356 hmargin
= vmargin
= relief
;
9358 if (INTEGERP (Vtool_bar_button_margin
)
9359 && XINT (Vtool_bar_button_margin
) > 0)
9361 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9362 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9364 else if (CONSP (Vtool_bar_button_margin
))
9366 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9367 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9368 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9370 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9371 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9372 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9375 if (auto_raise_tool_bar_buttons_p
)
9377 /* Add a `:relief' property to the image spec if the item is
9381 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9388 /* If image is selected, display it pressed, i.e. with a
9389 negative relief. If it's not selected, display it with a
9391 plist
= Fplist_put (plist
, QCrelief
,
9393 ? make_number (-relief
)
9394 : make_number (relief
)));
9399 /* Put a margin around the image. */
9400 if (hmargin
|| vmargin
)
9402 if (hmargin
== vmargin
)
9403 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9405 plist
= Fplist_put (plist
, QCmargin
,
9406 Fcons (make_number (hmargin
),
9407 make_number (vmargin
)));
9410 /* If button is not enabled, and we don't have special images
9411 for the disabled state, make the image appear disabled by
9412 applying an appropriate algorithm to it. */
9413 if (!enabled_p
&& idx
< 0)
9414 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9416 /* Put a `display' text property on the string for the image to
9417 display. Put a `menu-item' property on the string that gives
9418 the start of this item's properties in the tool-bar items
9420 image
= Fcons (Qimage
, plist
);
9421 props
= list4 (Qdisplay
, image
,
9422 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9424 /* Let the last image hide all remaining spaces in the tool bar
9425 string. The string can be longer than needed when we reuse a
9427 if (i
+ 1 == f
->n_tool_bar_items
)
9428 end
= SCHARS (f
->desired_tool_bar_string
);
9431 Fadd_text_properties (make_number (i
), make_number (end
),
9432 props
, f
->desired_tool_bar_string
);
9440 /* Display one line of the tool-bar of frame IT->f.
9442 HEIGHT specifies the desired height of the tool-bar line.
9443 If the actual height of the glyph row is less than HEIGHT, the
9444 row's height is increased to HEIGHT, and the icons are centered
9445 vertically in the new height.
9447 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9448 count a final empty row in case the tool-bar width exactly matches
9453 display_tool_bar_line (it
, height
)
9457 struct glyph_row
*row
= it
->glyph_row
;
9458 int max_x
= it
->last_visible_x
;
9461 prepare_desired_row (row
);
9462 row
->y
= it
->current_y
;
9464 /* Note that this isn't made use of if the face hasn't a box,
9465 so there's no need to check the face here. */
9466 it
->start_of_box_run_p
= 1;
9468 while (it
->current_x
< max_x
)
9470 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9472 /* Get the next display element. */
9473 if (!get_next_display_element (it
))
9475 /* Don't count empty row if we are counting needed tool-bar lines. */
9476 if (height
< 0 && !it
->hpos
)
9481 /* Produce glyphs. */
9482 x_before
= it
->current_x
;
9483 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9484 PRODUCE_GLYPHS (it
);
9486 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9491 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9493 if (x
+ glyph
->pixel_width
> max_x
)
9495 /* Glyph doesn't fit on line. */
9496 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9502 x
+= glyph
->pixel_width
;
9506 /* Stop at line ends. */
9507 if (ITERATOR_AT_END_OF_LINE_P (it
))
9510 set_iterator_to_next (it
, 1);
9515 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9516 /* Use default face for the border below the tool bar. */
9517 if (!row
->displays_text_p
)
9518 it
->face_id
= DEFAULT_FACE_ID
;
9519 extend_face_to_end_of_line (it
);
9520 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9521 last
->right_box_line_p
= 1;
9522 if (last
== row
->glyphs
[TEXT_AREA
])
9523 last
->left_box_line_p
= 1;
9525 /* Make line the desired height and center it vertically. */
9526 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9528 it
->max_ascent
+= height
/ 2;
9529 it
->max_descent
+= (height
+ 1) / 2;
9532 compute_line_metrics (it
);
9534 /* If line is empty, make it occupy the rest of the tool-bar. */
9535 if (!row
->displays_text_p
)
9537 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9538 row
->ascent
= row
->phys_ascent
= 0;
9539 row
->extra_line_spacing
= 0;
9542 row
->full_width_p
= 1;
9543 row
->continued_p
= 0;
9544 row
->truncated_on_left_p
= 0;
9545 row
->truncated_on_right_p
= 0;
9547 it
->current_x
= it
->hpos
= 0;
9548 it
->current_y
+= row
->height
;
9554 /* Value is the number of screen lines needed to make all tool-bar
9555 items of frame F visible. The number of actual rows needed is
9556 returned in *N_ROWS if non-NULL. */
9559 tool_bar_lines_needed (f
, n_rows
)
9563 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9565 struct glyph_row
*temp_row
= w
->desired_matrix
->rows
;
9567 /* Initialize an iterator for iteration over
9568 F->desired_tool_bar_string in the tool-bar window of frame F. */
9569 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9570 it
.first_visible_x
= 0;
9571 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9572 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9574 while (!ITERATOR_AT_END_P (&it
))
9576 clear_glyph_row (temp_row
);
9577 it
.glyph_row
= temp_row
;
9578 display_tool_bar_line (&it
, -1);
9580 clear_glyph_row (temp_row
);
9582 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9584 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9586 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9590 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9592 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9601 frame
= selected_frame
;
9603 CHECK_FRAME (frame
);
9606 if (WINDOWP (f
->tool_bar_window
)
9607 || (w
= XWINDOW (f
->tool_bar_window
),
9608 WINDOW_TOTAL_LINES (w
) > 0))
9610 update_tool_bar (f
, 1);
9611 if (f
->n_tool_bar_items
)
9613 build_desired_tool_bar_string (f
);
9614 nlines
= tool_bar_lines_needed (f
, NULL
);
9618 return make_number (nlines
);
9622 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9623 height should be changed. */
9626 redisplay_tool_bar (f
)
9631 struct glyph_row
*row
;
9632 int change_height_p
= 0;
9635 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9636 update_frame_tool_bar (f
);
9640 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9641 do anything. This means you must start with tool-bar-lines
9642 non-zero to get the auto-sizing effect. Or in other words, you
9643 can turn off tool-bars by specifying tool-bar-lines zero. */
9644 if (!WINDOWP (f
->tool_bar_window
)
9645 || (w
= XWINDOW (f
->tool_bar_window
),
9646 WINDOW_TOTAL_LINES (w
) == 0))
9649 /* Set up an iterator for the tool-bar window. */
9650 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9651 it
.first_visible_x
= 0;
9652 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9655 /* Build a string that represents the contents of the tool-bar. */
9656 build_desired_tool_bar_string (f
);
9657 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9659 if (f
->n_tool_bar_rows
== 0)
9663 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9664 nlines
!= WINDOW_TOTAL_LINES (w
)))
9666 extern Lisp_Object Qtool_bar_lines
;
9668 int old_height
= WINDOW_TOTAL_LINES (w
);
9670 XSETFRAME (frame
, f
);
9671 clear_glyph_matrix (w
->desired_matrix
);
9672 Fmodify_frame_parameters (frame
,
9673 Fcons (Fcons (Qtool_bar_lines
,
9674 make_number (nlines
)),
9676 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9678 fonts_changed_p
= 1;
9684 /* Display as many lines as needed to display all tool-bar items. */
9686 if (f
->n_tool_bar_rows
> 0)
9688 int border
, rows
, height
, extra
;
9690 if (INTEGERP (Vtool_bar_border
))
9691 border
= XINT (Vtool_bar_border
);
9692 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9693 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9694 else if (EQ (Vtool_bar_border
, Qborder_width
))
9695 border
= f
->border_width
;
9701 rows
= f
->n_tool_bar_rows
;
9702 height
= (it
.last_visible_y
- border
) / rows
;
9703 extra
= it
.last_visible_y
- border
- height
* rows
;
9705 while (it
.current_y
< it
.last_visible_y
)
9708 if (extra
> 0 && rows
-- > 0)
9710 h
= (extra
+ rows
- 1) / rows
;
9713 display_tool_bar_line (&it
, height
+ h
);
9718 while (it
.current_y
< it
.last_visible_y
)
9719 display_tool_bar_line (&it
, 0);
9722 /* It doesn't make much sense to try scrolling in the tool-bar
9723 window, so don't do it. */
9724 w
->desired_matrix
->no_scrolling_p
= 1;
9725 w
->must_be_updated_p
= 1;
9727 if (auto_resize_tool_bars_p
)
9731 /* If we couldn't display everything, change the tool-bar's
9733 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9734 change_height_p
= 1;
9736 /* If there are blank lines at the end, except for a partially
9737 visible blank line at the end that is smaller than
9738 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9739 row
= it
.glyph_row
- 1;
9740 if (!row
->displays_text_p
9741 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9742 change_height_p
= 1;
9744 /* If row displays tool-bar items, but is partially visible,
9745 change the tool-bar's height. */
9746 if (row
->displays_text_p
9747 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9748 change_height_p
= 1;
9750 /* Resize windows as needed by changing the `tool-bar-lines'
9753 && (nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9754 nlines
!= WINDOW_TOTAL_LINES (w
)))
9756 extern Lisp_Object Qtool_bar_lines
;
9758 int old_height
= WINDOW_TOTAL_LINES (w
);
9760 XSETFRAME (frame
, f
);
9761 clear_glyph_matrix (w
->desired_matrix
);
9762 Fmodify_frame_parameters (frame
,
9763 Fcons (Fcons (Qtool_bar_lines
,
9764 make_number (nlines
)),
9766 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9767 fonts_changed_p
= 1;
9771 return change_height_p
;
9775 /* Get information about the tool-bar item which is displayed in GLYPH
9776 on frame F. Return in *PROP_IDX the index where tool-bar item
9777 properties start in F->tool_bar_items. Value is zero if
9778 GLYPH doesn't display a tool-bar item. */
9781 tool_bar_item_info (f
, glyph
, prop_idx
)
9783 struct glyph
*glyph
;
9790 /* This function can be called asynchronously, which means we must
9791 exclude any possibility that Fget_text_property signals an
9793 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9794 charpos
= max (0, charpos
);
9796 /* Get the text property `menu-item' at pos. The value of that
9797 property is the start index of this item's properties in
9798 F->tool_bar_items. */
9799 prop
= Fget_text_property (make_number (charpos
),
9800 Qmenu_item
, f
->current_tool_bar_string
);
9801 if (INTEGERP (prop
))
9803 *prop_idx
= XINT (prop
);
9813 /* Get information about the tool-bar item at position X/Y on frame F.
9814 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9815 the current matrix of the tool-bar window of F, or NULL if not
9816 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9817 item in F->tool_bar_items. Value is
9819 -1 if X/Y is not on a tool-bar item
9820 0 if X/Y is on the same item that was highlighted before.
9824 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9827 struct glyph
**glyph
;
9828 int *hpos
, *vpos
, *prop_idx
;
9830 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9831 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9834 /* Find the glyph under X/Y. */
9835 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9839 /* Get the start of this tool-bar item's properties in
9840 f->tool_bar_items. */
9841 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9844 /* Is mouse on the highlighted item? */
9845 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9846 && *vpos
>= dpyinfo
->mouse_face_beg_row
9847 && *vpos
<= dpyinfo
->mouse_face_end_row
9848 && (*vpos
> dpyinfo
->mouse_face_beg_row
9849 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9850 && (*vpos
< dpyinfo
->mouse_face_end_row
9851 || *hpos
< dpyinfo
->mouse_face_end_col
9852 || dpyinfo
->mouse_face_past_end
))
9860 Handle mouse button event on the tool-bar of frame F, at
9861 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9862 0 for button release. MODIFIERS is event modifiers for button
9866 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9869 unsigned int modifiers
;
9871 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9872 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9873 int hpos
, vpos
, prop_idx
;
9874 struct glyph
*glyph
;
9875 Lisp_Object enabled_p
;
9877 /* If not on the highlighted tool-bar item, return. */
9878 frame_to_window_pixel_xy (w
, &x
, &y
);
9879 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9882 /* If item is disabled, do nothing. */
9883 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9884 if (NILP (enabled_p
))
9889 /* Show item in pressed state. */
9890 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9891 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9892 last_tool_bar_item
= prop_idx
;
9896 Lisp_Object key
, frame
;
9897 struct input_event event
;
9900 /* Show item in released state. */
9901 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9902 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9904 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9906 XSETFRAME (frame
, f
);
9907 event
.kind
= TOOL_BAR_EVENT
;
9908 event
.frame_or_window
= frame
;
9910 kbd_buffer_store_event (&event
);
9912 event
.kind
= TOOL_BAR_EVENT
;
9913 event
.frame_or_window
= frame
;
9915 event
.modifiers
= modifiers
;
9916 kbd_buffer_store_event (&event
);
9917 last_tool_bar_item
= -1;
9922 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9923 tool-bar window-relative coordinates X/Y. Called from
9924 note_mouse_highlight. */
9927 note_tool_bar_highlight (f
, x
, y
)
9931 Lisp_Object window
= f
->tool_bar_window
;
9932 struct window
*w
= XWINDOW (window
);
9933 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9935 struct glyph
*glyph
;
9936 struct glyph_row
*row
;
9938 Lisp_Object enabled_p
;
9940 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9941 int mouse_down_p
, rc
;
9943 /* Function note_mouse_highlight is called with negative x(y
9944 values when mouse moves outside of the frame. */
9945 if (x
<= 0 || y
<= 0)
9947 clear_mouse_face (dpyinfo
);
9951 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9954 /* Not on tool-bar item. */
9955 clear_mouse_face (dpyinfo
);
9959 /* On same tool-bar item as before. */
9962 clear_mouse_face (dpyinfo
);
9964 /* Mouse is down, but on different tool-bar item? */
9965 mouse_down_p
= (dpyinfo
->grabbed
9966 && f
== last_mouse_frame
9967 && FRAME_LIVE_P (f
));
9969 && last_tool_bar_item
!= prop_idx
)
9972 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9973 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9975 /* If tool-bar item is not enabled, don't highlight it. */
9976 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9977 if (!NILP (enabled_p
))
9979 /* Compute the x-position of the glyph. In front and past the
9980 image is a space. We include this in the highlighted area. */
9981 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9982 for (i
= x
= 0; i
< hpos
; ++i
)
9983 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9985 /* Record this as the current active region. */
9986 dpyinfo
->mouse_face_beg_col
= hpos
;
9987 dpyinfo
->mouse_face_beg_row
= vpos
;
9988 dpyinfo
->mouse_face_beg_x
= x
;
9989 dpyinfo
->mouse_face_beg_y
= row
->y
;
9990 dpyinfo
->mouse_face_past_end
= 0;
9992 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9993 dpyinfo
->mouse_face_end_row
= vpos
;
9994 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9995 dpyinfo
->mouse_face_end_y
= row
->y
;
9996 dpyinfo
->mouse_face_window
= window
;
9997 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9999 /* Display it as active. */
10000 show_mouse_face (dpyinfo
, draw
);
10001 dpyinfo
->mouse_face_image_state
= draw
;
10006 /* Set help_echo_string to a help string to display for this tool-bar item.
10007 XTread_socket does the rest. */
10008 help_echo_object
= help_echo_window
= Qnil
;
10009 help_echo_pos
= -1;
10010 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10011 if (NILP (help_echo_string
))
10012 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10015 #endif /* HAVE_WINDOW_SYSTEM */
10019 /************************************************************************
10020 Horizontal scrolling
10021 ************************************************************************/
10023 static int hscroll_window_tree
P_ ((Lisp_Object
));
10024 static int hscroll_windows
P_ ((Lisp_Object
));
10026 /* For all leaf windows in the window tree rooted at WINDOW, set their
10027 hscroll value so that PT is (i) visible in the window, and (ii) so
10028 that it is not within a certain margin at the window's left and
10029 right border. Value is non-zero if any window's hscroll has been
10033 hscroll_window_tree (window
)
10034 Lisp_Object window
;
10036 int hscrolled_p
= 0;
10037 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10038 int hscroll_step_abs
= 0;
10039 double hscroll_step_rel
= 0;
10041 if (hscroll_relative_p
)
10043 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10044 if (hscroll_step_rel
< 0)
10046 hscroll_relative_p
= 0;
10047 hscroll_step_abs
= 0;
10050 else if (INTEGERP (Vhscroll_step
))
10052 hscroll_step_abs
= XINT (Vhscroll_step
);
10053 if (hscroll_step_abs
< 0)
10054 hscroll_step_abs
= 0;
10057 hscroll_step_abs
= 0;
10059 while (WINDOWP (window
))
10061 struct window
*w
= XWINDOW (window
);
10063 if (WINDOWP (w
->hchild
))
10064 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10065 else if (WINDOWP (w
->vchild
))
10066 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10067 else if (w
->cursor
.vpos
>= 0)
10070 int text_area_width
;
10071 struct glyph_row
*current_cursor_row
10072 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10073 struct glyph_row
*desired_cursor_row
10074 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10075 struct glyph_row
*cursor_row
10076 = (desired_cursor_row
->enabled_p
10077 ? desired_cursor_row
10078 : current_cursor_row
);
10080 text_area_width
= window_box_width (w
, TEXT_AREA
);
10082 /* Scroll when cursor is inside this scroll margin. */
10083 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10085 if ((XFASTINT (w
->hscroll
)
10086 && w
->cursor
.x
<= h_margin
)
10087 || (cursor_row
->enabled_p
10088 && cursor_row
->truncated_on_right_p
10089 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10093 struct buffer
*saved_current_buffer
;
10097 /* Find point in a display of infinite width. */
10098 saved_current_buffer
= current_buffer
;
10099 current_buffer
= XBUFFER (w
->buffer
);
10101 if (w
== XWINDOW (selected_window
))
10102 pt
= BUF_PT (current_buffer
);
10105 pt
= marker_position (w
->pointm
);
10106 pt
= max (BEGV
, pt
);
10110 /* Move iterator to pt starting at cursor_row->start in
10111 a line with infinite width. */
10112 init_to_row_start (&it
, w
, cursor_row
);
10113 it
.last_visible_x
= INFINITY
;
10114 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10115 current_buffer
= saved_current_buffer
;
10117 /* Position cursor in window. */
10118 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10119 hscroll
= max (0, (it
.current_x
10120 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10121 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10122 : (text_area_width
/ 2))))
10123 / FRAME_COLUMN_WIDTH (it
.f
);
10124 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10126 if (hscroll_relative_p
)
10127 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10130 wanted_x
= text_area_width
10131 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10134 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10138 if (hscroll_relative_p
)
10139 wanted_x
= text_area_width
* hscroll_step_rel
10142 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10145 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10147 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10149 /* Don't call Fset_window_hscroll if value hasn't
10150 changed because it will prevent redisplay
10152 if (XFASTINT (w
->hscroll
) != hscroll
)
10154 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10155 w
->hscroll
= make_number (hscroll
);
10164 /* Value is non-zero if hscroll of any leaf window has been changed. */
10165 return hscrolled_p
;
10169 /* Set hscroll so that cursor is visible and not inside horizontal
10170 scroll margins for all windows in the tree rooted at WINDOW. See
10171 also hscroll_window_tree above. Value is non-zero if any window's
10172 hscroll has been changed. If it has, desired matrices on the frame
10173 of WINDOW are cleared. */
10176 hscroll_windows (window
)
10177 Lisp_Object window
;
10181 if (automatic_hscrolling_p
)
10183 hscrolled_p
= hscroll_window_tree (window
);
10185 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10189 return hscrolled_p
;
10194 /************************************************************************
10196 ************************************************************************/
10198 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10199 to a non-zero value. This is sometimes handy to have in a debugger
10204 /* First and last unchanged row for try_window_id. */
10206 int debug_first_unchanged_at_end_vpos
;
10207 int debug_last_unchanged_at_beg_vpos
;
10209 /* Delta vpos and y. */
10211 int debug_dvpos
, debug_dy
;
10213 /* Delta in characters and bytes for try_window_id. */
10215 int debug_delta
, debug_delta_bytes
;
10217 /* Values of window_end_pos and window_end_vpos at the end of
10220 EMACS_INT debug_end_pos
, debug_end_vpos
;
10222 /* Append a string to W->desired_matrix->method. FMT is a printf
10223 format string. A1...A9 are a supplement for a variable-length
10224 argument list. If trace_redisplay_p is non-zero also printf the
10225 resulting string to stderr. */
10228 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10231 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10234 char *method
= w
->desired_matrix
->method
;
10235 int len
= strlen (method
);
10236 int size
= sizeof w
->desired_matrix
->method
;
10237 int remaining
= size
- len
- 1;
10239 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10240 if (len
&& remaining
)
10243 --remaining
, ++len
;
10246 strncpy (method
+ len
, buffer
, remaining
);
10248 if (trace_redisplay_p
)
10249 fprintf (stderr
, "%p (%s): %s\n",
10251 ((BUFFERP (w
->buffer
)
10252 && STRINGP (XBUFFER (w
->buffer
)->name
))
10253 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10258 #endif /* GLYPH_DEBUG */
10261 /* Value is non-zero if all changes in window W, which displays
10262 current_buffer, are in the text between START and END. START is a
10263 buffer position, END is given as a distance from Z. Used in
10264 redisplay_internal for display optimization. */
10267 text_outside_line_unchanged_p (w
, start
, end
)
10271 int unchanged_p
= 1;
10273 /* If text or overlays have changed, see where. */
10274 if (XFASTINT (w
->last_modified
) < MODIFF
10275 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10277 /* Gap in the line? */
10278 if (GPT
< start
|| Z
- GPT
< end
)
10281 /* Changes start in front of the line, or end after it? */
10283 && (BEG_UNCHANGED
< start
- 1
10284 || END_UNCHANGED
< end
))
10287 /* If selective display, can't optimize if changes start at the
10288 beginning of the line. */
10290 && INTEGERP (current_buffer
->selective_display
)
10291 && XINT (current_buffer
->selective_display
) > 0
10292 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10295 /* If there are overlays at the start or end of the line, these
10296 may have overlay strings with newlines in them. A change at
10297 START, for instance, may actually concern the display of such
10298 overlay strings as well, and they are displayed on different
10299 lines. So, quickly rule out this case. (For the future, it
10300 might be desirable to implement something more telling than
10301 just BEG/END_UNCHANGED.) */
10304 if (BEG
+ BEG_UNCHANGED
== start
10305 && overlay_touches_p (start
))
10307 if (END_UNCHANGED
== end
10308 && overlay_touches_p (Z
- end
))
10313 return unchanged_p
;
10317 /* Do a frame update, taking possible shortcuts into account. This is
10318 the main external entry point for redisplay.
10320 If the last redisplay displayed an echo area message and that message
10321 is no longer requested, we clear the echo area or bring back the
10322 mini-buffer if that is in use. */
10327 redisplay_internal (0);
10332 overlay_arrow_string_or_property (var
)
10337 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10340 return Voverlay_arrow_string
;
10343 /* Return 1 if there are any overlay-arrows in current_buffer. */
10345 overlay_arrow_in_current_buffer_p ()
10349 for (vlist
= Voverlay_arrow_variable_list
;
10351 vlist
= XCDR (vlist
))
10353 Lisp_Object var
= XCAR (vlist
);
10356 if (!SYMBOLP (var
))
10358 val
= find_symbol_value (var
);
10360 && current_buffer
== XMARKER (val
)->buffer
)
10367 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10371 overlay_arrows_changed_p ()
10375 for (vlist
= Voverlay_arrow_variable_list
;
10377 vlist
= XCDR (vlist
))
10379 Lisp_Object var
= XCAR (vlist
);
10380 Lisp_Object val
, pstr
;
10382 if (!SYMBOLP (var
))
10384 val
= find_symbol_value (var
);
10385 if (!MARKERP (val
))
10387 if (! EQ (COERCE_MARKER (val
),
10388 Fget (var
, Qlast_arrow_position
))
10389 || ! (pstr
= overlay_arrow_string_or_property (var
),
10390 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10396 /* Mark overlay arrows to be updated on next redisplay. */
10399 update_overlay_arrows (up_to_date
)
10404 for (vlist
= Voverlay_arrow_variable_list
;
10406 vlist
= XCDR (vlist
))
10408 Lisp_Object var
= XCAR (vlist
);
10410 if (!SYMBOLP (var
))
10413 if (up_to_date
> 0)
10415 Lisp_Object val
= find_symbol_value (var
);
10416 Fput (var
, Qlast_arrow_position
,
10417 COERCE_MARKER (val
));
10418 Fput (var
, Qlast_arrow_string
,
10419 overlay_arrow_string_or_property (var
));
10421 else if (up_to_date
< 0
10422 || !NILP (Fget (var
, Qlast_arrow_position
)))
10424 Fput (var
, Qlast_arrow_position
, Qt
);
10425 Fput (var
, Qlast_arrow_string
, Qt
);
10431 /* Return overlay arrow string to display at row.
10432 Return integer (bitmap number) for arrow bitmap in left fringe.
10433 Return nil if no overlay arrow. */
10436 overlay_arrow_at_row (it
, row
)
10438 struct glyph_row
*row
;
10442 for (vlist
= Voverlay_arrow_variable_list
;
10444 vlist
= XCDR (vlist
))
10446 Lisp_Object var
= XCAR (vlist
);
10449 if (!SYMBOLP (var
))
10452 val
= find_symbol_value (var
);
10455 && current_buffer
== XMARKER (val
)->buffer
10456 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10458 if (FRAME_WINDOW_P (it
->f
)
10459 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10461 #ifdef HAVE_WINDOW_SYSTEM
10462 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10465 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10466 return make_number (fringe_bitmap
);
10469 return make_number (-1); /* Use default arrow bitmap */
10471 return overlay_arrow_string_or_property (var
);
10478 /* Return 1 if point moved out of or into a composition. Otherwise
10479 return 0. PREV_BUF and PREV_PT are the last point buffer and
10480 position. BUF and PT are the current point buffer and position. */
10483 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10484 struct buffer
*prev_buf
, *buf
;
10489 Lisp_Object buffer
;
10491 XSETBUFFER (buffer
, buf
);
10492 /* Check a composition at the last point if point moved within the
10494 if (prev_buf
== buf
)
10497 /* Point didn't move. */
10500 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10501 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10502 && COMPOSITION_VALID_P (start
, end
, prop
)
10503 && start
< prev_pt
&& end
> prev_pt
)
10504 /* The last point was within the composition. Return 1 iff
10505 point moved out of the composition. */
10506 return (pt
<= start
|| pt
>= end
);
10509 /* Check a composition at the current point. */
10510 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10511 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10512 && COMPOSITION_VALID_P (start
, end
, prop
)
10513 && start
< pt
&& end
> pt
);
10517 /* Reconsider the setting of B->clip_changed which is displayed
10521 reconsider_clip_changes (w
, b
)
10525 if (b
->clip_changed
10526 && !NILP (w
->window_end_valid
)
10527 && w
->current_matrix
->buffer
== b
10528 && w
->current_matrix
->zv
== BUF_ZV (b
)
10529 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10530 b
->clip_changed
= 0;
10532 /* If display wasn't paused, and W is not a tool bar window, see if
10533 point has been moved into or out of a composition. In that case,
10534 we set b->clip_changed to 1 to force updating the screen. If
10535 b->clip_changed has already been set to 1, we can skip this
10537 if (!b
->clip_changed
10538 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10542 if (w
== XWINDOW (selected_window
))
10543 pt
= BUF_PT (current_buffer
);
10545 pt
= marker_position (w
->pointm
);
10547 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10548 || pt
!= XINT (w
->last_point
))
10549 && check_point_in_composition (w
->current_matrix
->buffer
,
10550 XINT (w
->last_point
),
10551 XBUFFER (w
->buffer
), pt
))
10552 b
->clip_changed
= 1;
10557 /* Select FRAME to forward the values of frame-local variables into C
10558 variables so that the redisplay routines can access those values
10562 select_frame_for_redisplay (frame
)
10565 Lisp_Object tail
, sym
, val
;
10566 Lisp_Object old
= selected_frame
;
10568 selected_frame
= frame
;
10570 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10571 if (CONSP (XCAR (tail
))
10572 && (sym
= XCAR (XCAR (tail
)),
10574 && (sym
= indirect_variable (sym
),
10575 val
= SYMBOL_VALUE (sym
),
10576 (BUFFER_LOCAL_VALUEP (val
)
10577 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10578 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10579 /* Use find_symbol_value rather than Fsymbol_value
10580 to avoid an error if it is void. */
10581 find_symbol_value (sym
);
10583 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10584 if (CONSP (XCAR (tail
))
10585 && (sym
= XCAR (XCAR (tail
)),
10587 && (sym
= indirect_variable (sym
),
10588 val
= SYMBOL_VALUE (sym
),
10589 (BUFFER_LOCAL_VALUEP (val
)
10590 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10591 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10592 find_symbol_value (sym
);
10596 #define STOP_POLLING \
10597 do { if (! polling_stopped_here) stop_polling (); \
10598 polling_stopped_here = 1; } while (0)
10600 #define RESUME_POLLING \
10601 do { if (polling_stopped_here) start_polling (); \
10602 polling_stopped_here = 0; } while (0)
10605 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10606 response to any user action; therefore, we should preserve the echo
10607 area. (Actually, our caller does that job.) Perhaps in the future
10608 avoid recentering windows if it is not necessary; currently that
10609 causes some problems. */
10612 redisplay_internal (preserve_echo_area
)
10613 int preserve_echo_area
;
10615 struct window
*w
= XWINDOW (selected_window
);
10616 struct frame
*f
= XFRAME (w
->frame
);
10618 int must_finish
= 0;
10619 struct text_pos tlbufpos
, tlendpos
;
10620 int number_of_visible_frames
;
10622 struct frame
*sf
= SELECTED_FRAME ();
10623 int polling_stopped_here
= 0;
10625 /* Non-zero means redisplay has to consider all windows on all
10626 frames. Zero means, only selected_window is considered. */
10627 int consider_all_windows_p
;
10629 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10631 /* No redisplay if running in batch mode or frame is not yet fully
10632 initialized, or redisplay is explicitly turned off by setting
10633 Vinhibit_redisplay. */
10635 || !NILP (Vinhibit_redisplay
)
10636 || !f
->glyphs_initialized_p
)
10639 /* The flag redisplay_performed_directly_p is set by
10640 direct_output_for_insert when it already did the whole screen
10641 update necessary. */
10642 if (redisplay_performed_directly_p
)
10644 redisplay_performed_directly_p
= 0;
10645 if (!hscroll_windows (selected_window
))
10649 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10650 if (popup_activated ())
10654 /* I don't think this happens but let's be paranoid. */
10655 if (redisplaying_p
)
10658 /* Record a function that resets redisplaying_p to its old value
10659 when we leave this function. */
10660 count
= SPECPDL_INDEX ();
10661 record_unwind_protect (unwind_redisplay
,
10662 Fcons (make_number (redisplaying_p
), selected_frame
));
10664 specbind (Qinhibit_free_realized_faces
, Qnil
);
10667 Lisp_Object tail
, frame
;
10669 FOR_EACH_FRAME (tail
, frame
)
10671 struct frame
*f
= XFRAME (frame
);
10672 f
->already_hscrolled_p
= 0;
10678 reconsider_clip_changes (w
, current_buffer
);
10679 last_escape_glyph_frame
= NULL
;
10680 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10682 /* If new fonts have been loaded that make a glyph matrix adjustment
10683 necessary, do it. */
10684 if (fonts_changed_p
)
10686 adjust_glyphs (NULL
);
10687 ++windows_or_buffers_changed
;
10688 fonts_changed_p
= 0;
10691 /* If face_change_count is non-zero, init_iterator will free all
10692 realized faces, which includes the faces referenced from current
10693 matrices. So, we can't reuse current matrices in this case. */
10694 if (face_change_count
)
10695 ++windows_or_buffers_changed
;
10697 if (! FRAME_WINDOW_P (sf
)
10698 && previous_terminal_frame
!= sf
)
10700 /* Since frames on an ASCII terminal share the same display
10701 area, displaying a different frame means redisplay the whole
10703 windows_or_buffers_changed
++;
10704 SET_FRAME_GARBAGED (sf
);
10705 XSETFRAME (Vterminal_frame
, sf
);
10707 previous_terminal_frame
= sf
;
10709 /* Set the visible flags for all frames. Do this before checking
10710 for resized or garbaged frames; they want to know if their frames
10711 are visible. See the comment in frame.h for
10712 FRAME_SAMPLE_VISIBILITY. */
10714 Lisp_Object tail
, frame
;
10716 number_of_visible_frames
= 0;
10718 FOR_EACH_FRAME (tail
, frame
)
10720 struct frame
*f
= XFRAME (frame
);
10722 FRAME_SAMPLE_VISIBILITY (f
);
10723 if (FRAME_VISIBLE_P (f
))
10724 ++number_of_visible_frames
;
10725 clear_desired_matrices (f
);
10729 /* Notice any pending interrupt request to change frame size. */
10730 do_pending_window_change (1);
10732 /* Clear frames marked as garbaged. */
10733 if (frame_garbaged
)
10734 clear_garbaged_frames ();
10736 /* Build menubar and tool-bar items. */
10737 if (NILP (Vmemory_full
))
10738 prepare_menu_bars ();
10740 if (windows_or_buffers_changed
)
10741 update_mode_lines
++;
10743 /* Detect case that we need to write or remove a star in the mode line. */
10744 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10746 w
->update_mode_line
= Qt
;
10747 if (buffer_shared
> 1)
10748 update_mode_lines
++;
10751 /* If %c is in the mode line, update it if needed. */
10752 if (!NILP (w
->column_number_displayed
)
10753 /* This alternative quickly identifies a common case
10754 where no change is needed. */
10755 && !(PT
== XFASTINT (w
->last_point
)
10756 && XFASTINT (w
->last_modified
) >= MODIFF
10757 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10758 && (XFASTINT (w
->column_number_displayed
)
10759 != (int) current_column ())) /* iftc */
10760 w
->update_mode_line
= Qt
;
10762 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10764 /* The variable buffer_shared is set in redisplay_window and
10765 indicates that we redisplay a buffer in different windows. See
10767 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10768 || cursor_type_changed
);
10770 /* If specs for an arrow have changed, do thorough redisplay
10771 to ensure we remove any arrow that should no longer exist. */
10772 if (overlay_arrows_changed_p ())
10773 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10775 /* Normally the message* functions will have already displayed and
10776 updated the echo area, but the frame may have been trashed, or
10777 the update may have been preempted, so display the echo area
10778 again here. Checking message_cleared_p captures the case that
10779 the echo area should be cleared. */
10780 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10781 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10782 || (message_cleared_p
10783 && minibuf_level
== 0
10784 /* If the mini-window is currently selected, this means the
10785 echo-area doesn't show through. */
10786 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10788 int window_height_changed_p
= echo_area_display (0);
10791 /* If we don't display the current message, don't clear the
10792 message_cleared_p flag, because, if we did, we wouldn't clear
10793 the echo area in the next redisplay which doesn't preserve
10795 if (!display_last_displayed_message_p
)
10796 message_cleared_p
= 0;
10798 if (fonts_changed_p
)
10800 else if (window_height_changed_p
)
10802 consider_all_windows_p
= 1;
10803 ++update_mode_lines
;
10804 ++windows_or_buffers_changed
;
10806 /* If window configuration was changed, frames may have been
10807 marked garbaged. Clear them or we will experience
10808 surprises wrt scrolling. */
10809 if (frame_garbaged
)
10810 clear_garbaged_frames ();
10813 else if (EQ (selected_window
, minibuf_window
)
10814 && (current_buffer
->clip_changed
10815 || XFASTINT (w
->last_modified
) < MODIFF
10816 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10817 && resize_mini_window (w
, 0))
10819 /* Resized active mini-window to fit the size of what it is
10820 showing if its contents might have changed. */
10822 consider_all_windows_p
= 1;
10823 ++windows_or_buffers_changed
;
10824 ++update_mode_lines
;
10826 /* If window configuration was changed, frames may have been
10827 marked garbaged. Clear them or we will experience
10828 surprises wrt scrolling. */
10829 if (frame_garbaged
)
10830 clear_garbaged_frames ();
10834 /* If showing the region, and mark has changed, we must redisplay
10835 the whole window. The assignment to this_line_start_pos prevents
10836 the optimization directly below this if-statement. */
10837 if (((!NILP (Vtransient_mark_mode
)
10838 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10839 != !NILP (w
->region_showing
))
10840 || (!NILP (w
->region_showing
)
10841 && !EQ (w
->region_showing
,
10842 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10843 CHARPOS (this_line_start_pos
) = 0;
10845 /* Optimize the case that only the line containing the cursor in the
10846 selected window has changed. Variables starting with this_ are
10847 set in display_line and record information about the line
10848 containing the cursor. */
10849 tlbufpos
= this_line_start_pos
;
10850 tlendpos
= this_line_end_pos
;
10851 if (!consider_all_windows_p
10852 && CHARPOS (tlbufpos
) > 0
10853 && NILP (w
->update_mode_line
)
10854 && !current_buffer
->clip_changed
10855 && !current_buffer
->prevent_redisplay_optimizations_p
10856 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10857 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10858 /* Make sure recorded data applies to current buffer, etc. */
10859 && this_line_buffer
== current_buffer
10860 && current_buffer
== XBUFFER (w
->buffer
)
10861 && NILP (w
->force_start
)
10862 && NILP (w
->optional_new_start
)
10863 /* Point must be on the line that we have info recorded about. */
10864 && PT
>= CHARPOS (tlbufpos
)
10865 && PT
<= Z
- CHARPOS (tlendpos
)
10866 /* All text outside that line, including its final newline,
10867 must be unchanged */
10868 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10869 CHARPOS (tlendpos
)))
10871 if (CHARPOS (tlbufpos
) > BEGV
10872 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10873 && (CHARPOS (tlbufpos
) == ZV
10874 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10875 /* Former continuation line has disappeared by becoming empty */
10877 else if (XFASTINT (w
->last_modified
) < MODIFF
10878 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10879 || MINI_WINDOW_P (w
))
10881 /* We have to handle the case of continuation around a
10882 wide-column character (See the comment in indent.c around
10885 For instance, in the following case:
10887 -------- Insert --------
10888 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10889 J_I_ ==> J_I_ `^^' are cursors.
10893 As we have to redraw the line above, we should goto cancel. */
10896 int line_height_before
= this_line_pixel_height
;
10898 /* Note that start_display will handle the case that the
10899 line starting at tlbufpos is a continuation lines. */
10900 start_display (&it
, w
, tlbufpos
);
10902 /* Implementation note: It this still necessary? */
10903 if (it
.current_x
!= this_line_start_x
)
10906 TRACE ((stderr
, "trying display optimization 1\n"));
10907 w
->cursor
.vpos
= -1;
10908 overlay_arrow_seen
= 0;
10909 it
.vpos
= this_line_vpos
;
10910 it
.current_y
= this_line_y
;
10911 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10912 display_line (&it
);
10914 /* If line contains point, is not continued,
10915 and ends at same distance from eob as before, we win */
10916 if (w
->cursor
.vpos
>= 0
10917 /* Line is not continued, otherwise this_line_start_pos
10918 would have been set to 0 in display_line. */
10919 && CHARPOS (this_line_start_pos
)
10920 /* Line ends as before. */
10921 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10922 /* Line has same height as before. Otherwise other lines
10923 would have to be shifted up or down. */
10924 && this_line_pixel_height
== line_height_before
)
10926 /* If this is not the window's last line, we must adjust
10927 the charstarts of the lines below. */
10928 if (it
.current_y
< it
.last_visible_y
)
10930 struct glyph_row
*row
10931 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10932 int delta
, delta_bytes
;
10934 if (Z
- CHARPOS (tlendpos
) == ZV
)
10936 /* This line ends at end of (accessible part of)
10937 buffer. There is no newline to count. */
10939 - CHARPOS (tlendpos
)
10940 - MATRIX_ROW_START_CHARPOS (row
));
10941 delta_bytes
= (Z_BYTE
10942 - BYTEPOS (tlendpos
)
10943 - MATRIX_ROW_START_BYTEPOS (row
));
10947 /* This line ends in a newline. Must take
10948 account of the newline and the rest of the
10949 text that follows. */
10951 - CHARPOS (tlendpos
)
10952 - MATRIX_ROW_START_CHARPOS (row
));
10953 delta_bytes
= (Z_BYTE
10954 - BYTEPOS (tlendpos
)
10955 - MATRIX_ROW_START_BYTEPOS (row
));
10958 increment_matrix_positions (w
->current_matrix
,
10959 this_line_vpos
+ 1,
10960 w
->current_matrix
->nrows
,
10961 delta
, delta_bytes
);
10964 /* If this row displays text now but previously didn't,
10965 or vice versa, w->window_end_vpos may have to be
10967 if ((it
.glyph_row
- 1)->displays_text_p
)
10969 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10970 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10972 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10973 && this_line_vpos
> 0)
10974 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10975 w
->window_end_valid
= Qnil
;
10977 /* Update hint: No need to try to scroll in update_window. */
10978 w
->desired_matrix
->no_scrolling_p
= 1;
10981 *w
->desired_matrix
->method
= 0;
10982 debug_method_add (w
, "optimization 1");
10984 #ifdef HAVE_WINDOW_SYSTEM
10985 update_window_fringes (w
, 0);
10992 else if (/* Cursor position hasn't changed. */
10993 PT
== XFASTINT (w
->last_point
)
10994 /* Make sure the cursor was last displayed
10995 in this window. Otherwise we have to reposition it. */
10996 && 0 <= w
->cursor
.vpos
10997 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11001 do_pending_window_change (1);
11003 /* We used to always goto end_of_redisplay here, but this
11004 isn't enough if we have a blinking cursor. */
11005 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11006 goto end_of_redisplay
;
11010 /* If highlighting the region, or if the cursor is in the echo area,
11011 then we can't just move the cursor. */
11012 else if (! (!NILP (Vtransient_mark_mode
)
11013 && !NILP (current_buffer
->mark_active
))
11014 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11015 || highlight_nonselected_windows
)
11016 && NILP (w
->region_showing
)
11017 && NILP (Vshow_trailing_whitespace
)
11018 && !cursor_in_echo_area
)
11021 struct glyph_row
*row
;
11023 /* Skip from tlbufpos to PT and see where it is. Note that
11024 PT may be in invisible text. If so, we will end at the
11025 next visible position. */
11026 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11027 NULL
, DEFAULT_FACE_ID
);
11028 it
.current_x
= this_line_start_x
;
11029 it
.current_y
= this_line_y
;
11030 it
.vpos
= this_line_vpos
;
11032 /* The call to move_it_to stops in front of PT, but
11033 moves over before-strings. */
11034 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11036 if (it
.vpos
== this_line_vpos
11037 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11040 xassert (this_line_vpos
== it
.vpos
);
11041 xassert (this_line_y
== it
.current_y
);
11042 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11044 *w
->desired_matrix
->method
= 0;
11045 debug_method_add (w
, "optimization 3");
11054 /* Text changed drastically or point moved off of line. */
11055 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11058 CHARPOS (this_line_start_pos
) = 0;
11059 consider_all_windows_p
|= buffer_shared
> 1;
11060 ++clear_face_cache_count
;
11061 #ifdef HAVE_WINDOW_SYSTEM
11062 ++clear_image_cache_count
;
11065 /* Build desired matrices, and update the display. If
11066 consider_all_windows_p is non-zero, do it for all windows on all
11067 frames. Otherwise do it for selected_window, only. */
11069 if (consider_all_windows_p
)
11071 Lisp_Object tail
, frame
;
11073 FOR_EACH_FRAME (tail
, frame
)
11074 XFRAME (frame
)->updated_p
= 0;
11076 /* Recompute # windows showing selected buffer. This will be
11077 incremented each time such a window is displayed. */
11080 FOR_EACH_FRAME (tail
, frame
)
11082 struct frame
*f
= XFRAME (frame
);
11084 if (FRAME_WINDOW_P (f
) || f
== sf
)
11086 if (! EQ (frame
, selected_frame
))
11087 /* Select the frame, for the sake of frame-local
11089 select_frame_for_redisplay (frame
);
11091 /* Mark all the scroll bars to be removed; we'll redeem
11092 the ones we want when we redisplay their windows. */
11093 if (condemn_scroll_bars_hook
)
11094 condemn_scroll_bars_hook (f
);
11096 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11097 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11099 /* Any scroll bars which redisplay_windows should have
11100 nuked should now go away. */
11101 if (judge_scroll_bars_hook
)
11102 judge_scroll_bars_hook (f
);
11104 /* If fonts changed, display again. */
11105 /* ??? rms: I suspect it is a mistake to jump all the way
11106 back to retry here. It should just retry this frame. */
11107 if (fonts_changed_p
)
11110 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11112 /* See if we have to hscroll. */
11113 if (!f
->already_hscrolled_p
)
11115 f
->already_hscrolled_p
= 1;
11116 if (hscroll_windows (f
->root_window
))
11120 /* Prevent various kinds of signals during display
11121 update. stdio is not robust about handling
11122 signals, which can cause an apparent I/O
11124 if (interrupt_input
)
11125 unrequest_sigio ();
11128 /* Update the display. */
11129 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11130 pause
|= update_frame (f
, 0, 0);
11131 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11143 /* Do the mark_window_display_accurate after all windows have
11144 been redisplayed because this call resets flags in buffers
11145 which are needed for proper redisplay. */
11146 FOR_EACH_FRAME (tail
, frame
)
11148 struct frame
*f
= XFRAME (frame
);
11151 mark_window_display_accurate (f
->root_window
, 1);
11152 if (frame_up_to_date_hook
)
11153 frame_up_to_date_hook (f
);
11158 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11160 Lisp_Object mini_window
;
11161 struct frame
*mini_frame
;
11163 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11164 /* Use list_of_error, not Qerror, so that
11165 we catch only errors and don't run the debugger. */
11166 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11168 redisplay_window_error
);
11170 /* Compare desired and current matrices, perform output. */
11173 /* If fonts changed, display again. */
11174 if (fonts_changed_p
)
11177 /* Prevent various kinds of signals during display update.
11178 stdio is not robust about handling signals,
11179 which can cause an apparent I/O error. */
11180 if (interrupt_input
)
11181 unrequest_sigio ();
11184 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11186 if (hscroll_windows (selected_window
))
11189 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11190 pause
= update_frame (sf
, 0, 0);
11193 /* We may have called echo_area_display at the top of this
11194 function. If the echo area is on another frame, that may
11195 have put text on a frame other than the selected one, so the
11196 above call to update_frame would not have caught it. Catch
11198 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11199 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11201 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11203 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11204 pause
|= update_frame (mini_frame
, 0, 0);
11205 if (!pause
&& hscroll_windows (mini_window
))
11210 /* If display was paused because of pending input, make sure we do a
11211 thorough update the next time. */
11214 /* Prevent the optimization at the beginning of
11215 redisplay_internal that tries a single-line update of the
11216 line containing the cursor in the selected window. */
11217 CHARPOS (this_line_start_pos
) = 0;
11219 /* Let the overlay arrow be updated the next time. */
11220 update_overlay_arrows (0);
11222 /* If we pause after scrolling, some rows in the current
11223 matrices of some windows are not valid. */
11224 if (!WINDOW_FULL_WIDTH_P (w
)
11225 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11226 update_mode_lines
= 1;
11230 if (!consider_all_windows_p
)
11232 /* This has already been done above if
11233 consider_all_windows_p is set. */
11234 mark_window_display_accurate_1 (w
, 1);
11236 /* Say overlay arrows are up to date. */
11237 update_overlay_arrows (1);
11239 if (frame_up_to_date_hook
!= 0)
11240 frame_up_to_date_hook (sf
);
11243 update_mode_lines
= 0;
11244 windows_or_buffers_changed
= 0;
11245 cursor_type_changed
= 0;
11248 /* Start SIGIO interrupts coming again. Having them off during the
11249 code above makes it less likely one will discard output, but not
11250 impossible, since there might be stuff in the system buffer here.
11251 But it is much hairier to try to do anything about that. */
11252 if (interrupt_input
)
11256 /* If a frame has become visible which was not before, redisplay
11257 again, so that we display it. Expose events for such a frame
11258 (which it gets when becoming visible) don't call the parts of
11259 redisplay constructing glyphs, so simply exposing a frame won't
11260 display anything in this case. So, we have to display these
11261 frames here explicitly. */
11264 Lisp_Object tail
, frame
;
11267 FOR_EACH_FRAME (tail
, frame
)
11269 int this_is_visible
= 0;
11271 if (XFRAME (frame
)->visible
)
11272 this_is_visible
= 1;
11273 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11274 if (XFRAME (frame
)->visible
)
11275 this_is_visible
= 1;
11277 if (this_is_visible
)
11281 if (new_count
!= number_of_visible_frames
)
11282 windows_or_buffers_changed
++;
11285 /* Change frame size now if a change is pending. */
11286 do_pending_window_change (1);
11288 /* If we just did a pending size change, or have additional
11289 visible frames, redisplay again. */
11290 if (windows_or_buffers_changed
&& !pause
)
11293 /* Clear the face cache eventually. */
11294 if (consider_all_windows_p
)
11296 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11298 clear_face_cache (0);
11299 clear_face_cache_count
= 0;
11301 #ifdef HAVE_WINDOW_SYSTEM
11302 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11304 Lisp_Object tail
, frame
;
11305 FOR_EACH_FRAME (tail
, frame
)
11307 struct frame
*f
= XFRAME (frame
);
11308 if (FRAME_WINDOW_P (f
))
11309 clear_image_cache (f
, 0);
11311 clear_image_cache_count
= 0;
11313 #endif /* HAVE_WINDOW_SYSTEM */
11317 unbind_to (count
, Qnil
);
11322 /* Redisplay, but leave alone any recent echo area message unless
11323 another message has been requested in its place.
11325 This is useful in situations where you need to redisplay but no
11326 user action has occurred, making it inappropriate for the message
11327 area to be cleared. See tracking_off and
11328 wait_reading_process_output for examples of these situations.
11330 FROM_WHERE is an integer saying from where this function was
11331 called. This is useful for debugging. */
11334 redisplay_preserve_echo_area (from_where
)
11337 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11339 if (!NILP (echo_area_buffer
[1]))
11341 /* We have a previously displayed message, but no current
11342 message. Redisplay the previous message. */
11343 display_last_displayed_message_p
= 1;
11344 redisplay_internal (1);
11345 display_last_displayed_message_p
= 0;
11348 redisplay_internal (1);
11350 if (rif
!= NULL
&& rif
->flush_display_optional
)
11351 rif
->flush_display_optional (NULL
);
11355 /* Function registered with record_unwind_protect in
11356 redisplay_internal. Reset redisplaying_p to the value it had
11357 before redisplay_internal was called, and clear
11358 prevent_freeing_realized_faces_p. It also selects the previously
11362 unwind_redisplay (val
)
11365 Lisp_Object old_redisplaying_p
, old_frame
;
11367 old_redisplaying_p
= XCAR (val
);
11368 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11369 old_frame
= XCDR (val
);
11370 if (! EQ (old_frame
, selected_frame
))
11371 select_frame_for_redisplay (old_frame
);
11376 /* Mark the display of window W as accurate or inaccurate. If
11377 ACCURATE_P is non-zero mark display of W as accurate. If
11378 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11379 redisplay_internal is called. */
11382 mark_window_display_accurate_1 (w
, accurate_p
)
11386 if (BUFFERP (w
->buffer
))
11388 struct buffer
*b
= XBUFFER (w
->buffer
);
11391 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11392 w
->last_overlay_modified
11393 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11395 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11399 b
->clip_changed
= 0;
11400 b
->prevent_redisplay_optimizations_p
= 0;
11402 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11403 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11404 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11405 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11407 w
->current_matrix
->buffer
= b
;
11408 w
->current_matrix
->begv
= BUF_BEGV (b
);
11409 w
->current_matrix
->zv
= BUF_ZV (b
);
11411 w
->last_cursor
= w
->cursor
;
11412 w
->last_cursor_off_p
= w
->cursor_off_p
;
11414 if (w
== XWINDOW (selected_window
))
11415 w
->last_point
= make_number (BUF_PT (b
));
11417 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11423 w
->window_end_valid
= w
->buffer
;
11424 #if 0 /* This is incorrect with variable-height lines. */
11425 xassert (XINT (w
->window_end_vpos
)
11426 < (WINDOW_TOTAL_LINES (w
)
11427 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11429 w
->update_mode_line
= Qnil
;
11434 /* Mark the display of windows in the window tree rooted at WINDOW as
11435 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11436 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11437 be redisplayed the next time redisplay_internal is called. */
11440 mark_window_display_accurate (window
, accurate_p
)
11441 Lisp_Object window
;
11446 for (; !NILP (window
); window
= w
->next
)
11448 w
= XWINDOW (window
);
11449 mark_window_display_accurate_1 (w
, accurate_p
);
11451 if (!NILP (w
->vchild
))
11452 mark_window_display_accurate (w
->vchild
, accurate_p
);
11453 if (!NILP (w
->hchild
))
11454 mark_window_display_accurate (w
->hchild
, accurate_p
);
11459 update_overlay_arrows (1);
11463 /* Force a thorough redisplay the next time by setting
11464 last_arrow_position and last_arrow_string to t, which is
11465 unequal to any useful value of Voverlay_arrow_... */
11466 update_overlay_arrows (-1);
11471 /* Return value in display table DP (Lisp_Char_Table *) for character
11472 C. Since a display table doesn't have any parent, we don't have to
11473 follow parent. Do not call this function directly but use the
11474 macro DISP_CHAR_VECTOR. */
11477 disp_char_vector (dp
, c
)
11478 struct Lisp_Char_Table
*dp
;
11484 if (SINGLE_BYTE_CHAR_P (c
))
11485 return (dp
->contents
[c
]);
11487 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11490 else if (code
[2] < 32)
11493 /* Here, the possible range of code[0] (== charset ID) is
11494 128..max_charset. Since the top level char table contains data
11495 for multibyte characters after 256th element, we must increment
11496 code[0] by 128 to get a correct index. */
11498 code
[3] = -1; /* anchor */
11500 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11502 val
= dp
->contents
[code
[i
]];
11503 if (!SUB_CHAR_TABLE_P (val
))
11504 return (NILP (val
) ? dp
->defalt
: val
);
11507 /* Here, val is a sub char table. We return the default value of
11509 return (dp
->defalt
);
11514 /***********************************************************************
11516 ***********************************************************************/
11518 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11521 redisplay_windows (window
)
11522 Lisp_Object window
;
11524 while (!NILP (window
))
11526 struct window
*w
= XWINDOW (window
);
11528 if (!NILP (w
->hchild
))
11529 redisplay_windows (w
->hchild
);
11530 else if (!NILP (w
->vchild
))
11531 redisplay_windows (w
->vchild
);
11534 displayed_buffer
= XBUFFER (w
->buffer
);
11535 /* Use list_of_error, not Qerror, so that
11536 we catch only errors and don't run the debugger. */
11537 internal_condition_case_1 (redisplay_window_0
, window
,
11539 redisplay_window_error
);
11547 redisplay_window_error ()
11549 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11554 redisplay_window_0 (window
)
11555 Lisp_Object window
;
11557 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11558 redisplay_window (window
, 0);
11563 redisplay_window_1 (window
)
11564 Lisp_Object window
;
11566 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11567 redisplay_window (window
, 1);
11572 /* Increment GLYPH until it reaches END or CONDITION fails while
11573 adding (GLYPH)->pixel_width to X. */
11575 #define SKIP_GLYPHS(glyph, end, x, condition) \
11578 (x) += (glyph)->pixel_width; \
11581 while ((glyph) < (end) && (condition))
11584 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11585 DELTA is the number of bytes by which positions recorded in ROW
11586 differ from current buffer positions. */
11589 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11591 struct glyph_row
*row
;
11592 struct glyph_matrix
*matrix
;
11593 int delta
, delta_bytes
, dy
, dvpos
;
11595 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11596 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11597 struct glyph
*cursor
= NULL
;
11598 /* The first glyph that starts a sequence of glyphs from string. */
11599 struct glyph
*string_start
;
11600 /* The X coordinate of string_start. */
11601 int string_start_x
;
11602 /* The last known character position. */
11603 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11604 /* The last known character position before string_start. */
11605 int string_before_pos
;
11608 int cursor_from_overlay_pos
= 0;
11609 int pt_old
= PT
- delta
;
11611 /* Skip over glyphs not having an object at the start of the row.
11612 These are special glyphs like truncation marks on terminal
11614 if (row
->displays_text_p
)
11616 && INTEGERP (glyph
->object
)
11617 && glyph
->charpos
< 0)
11619 x
+= glyph
->pixel_width
;
11623 string_start
= NULL
;
11625 && !INTEGERP (glyph
->object
)
11626 && (!BUFFERP (glyph
->object
)
11627 || (last_pos
= glyph
->charpos
) < pt_old
))
11629 if (! STRINGP (glyph
->object
))
11631 string_start
= NULL
;
11632 x
+= glyph
->pixel_width
;
11634 if (cursor_from_overlay_pos
11635 && last_pos
>= cursor_from_overlay_pos
)
11637 cursor_from_overlay_pos
= 0;
11643 string_before_pos
= last_pos
;
11644 string_start
= glyph
;
11645 string_start_x
= x
;
11646 /* Skip all glyphs from string. */
11651 if ((cursor
== NULL
|| glyph
> cursor
)
11652 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11653 Qcursor
, (glyph
)->object
),
11655 && (pos
= string_buffer_position (w
, glyph
->object
,
11656 string_before_pos
),
11657 (pos
== 0 /* From overlay */
11658 || pos
== pt_old
)))
11660 /* Estimate overlay buffer position from the buffer
11661 positions of the glyphs before and after the overlay.
11662 Add 1 to last_pos so that if point corresponds to the
11663 glyph right after the overlay, we still use a 'cursor'
11664 property found in that overlay. */
11665 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11666 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11670 x
+= glyph
->pixel_width
;
11673 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11677 if (cursor
!= NULL
)
11682 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11684 /* Scan back over the ellipsis glyphs, decrementing positions. */
11685 while (glyph
> row
->glyphs
[TEXT_AREA
]
11686 && (glyph
- 1)->charpos
== last_pos
)
11687 glyph
--, x
-= glyph
->pixel_width
;
11688 /* That loop always goes one position too far,
11689 including the glyph before the ellipsis.
11690 So scan forward over that one. */
11691 x
+= glyph
->pixel_width
;
11694 else if (string_start
11695 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11697 /* We may have skipped over point because the previous glyphs
11698 are from string. As there's no easy way to know the
11699 character position of the current glyph, find the correct
11700 glyph on point by scanning from string_start again. */
11702 Lisp_Object string
;
11705 limit
= make_number (pt_old
+ 1);
11707 glyph
= string_start
;
11708 x
= string_start_x
;
11709 string
= glyph
->object
;
11710 pos
= string_buffer_position (w
, string
, string_before_pos
);
11711 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11712 because we always put cursor after overlay strings. */
11713 while (pos
== 0 && glyph
< end
)
11715 string
= glyph
->object
;
11716 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11718 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11721 while (glyph
< end
)
11723 pos
= XINT (Fnext_single_char_property_change
11724 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11727 /* Skip glyphs from the same string. */
11728 string
= glyph
->object
;
11729 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11730 /* Skip glyphs from an overlay. */
11732 && ! string_buffer_position (w
, glyph
->object
, pos
))
11734 string
= glyph
->object
;
11735 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11740 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11742 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11743 w
->cursor
.y
= row
->y
+ dy
;
11745 if (w
== XWINDOW (selected_window
))
11747 if (!row
->continued_p
11748 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11751 this_line_buffer
= XBUFFER (w
->buffer
);
11753 CHARPOS (this_line_start_pos
)
11754 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11755 BYTEPOS (this_line_start_pos
)
11756 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11758 CHARPOS (this_line_end_pos
)
11759 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11760 BYTEPOS (this_line_end_pos
)
11761 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11763 this_line_y
= w
->cursor
.y
;
11764 this_line_pixel_height
= row
->height
;
11765 this_line_vpos
= w
->cursor
.vpos
;
11766 this_line_start_x
= row
->x
;
11769 CHARPOS (this_line_start_pos
) = 0;
11774 /* Run window scroll functions, if any, for WINDOW with new window
11775 start STARTP. Sets the window start of WINDOW to that position.
11777 We assume that the window's buffer is really current. */
11779 static INLINE
struct text_pos
11780 run_window_scroll_functions (window
, startp
)
11781 Lisp_Object window
;
11782 struct text_pos startp
;
11784 struct window
*w
= XWINDOW (window
);
11785 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11787 if (current_buffer
!= XBUFFER (w
->buffer
))
11790 if (!NILP (Vwindow_scroll_functions
))
11792 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11793 make_number (CHARPOS (startp
)));
11794 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11795 /* In case the hook functions switch buffers. */
11796 if (current_buffer
!= XBUFFER (w
->buffer
))
11797 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11804 /* Make sure the line containing the cursor is fully visible.
11805 A value of 1 means there is nothing to be done.
11806 (Either the line is fully visible, or it cannot be made so,
11807 or we cannot tell.)
11809 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11810 is higher than window.
11812 A value of 0 means the caller should do scrolling
11813 as if point had gone off the screen. */
11816 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11819 int current_matrix_p
;
11821 struct glyph_matrix
*matrix
;
11822 struct glyph_row
*row
;
11825 if (!make_cursor_line_fully_visible_p
)
11828 /* It's not always possible to find the cursor, e.g, when a window
11829 is full of overlay strings. Don't do anything in that case. */
11830 if (w
->cursor
.vpos
< 0)
11833 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11834 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11836 /* If the cursor row is not partially visible, there's nothing to do. */
11837 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11840 /* If the row the cursor is in is taller than the window's height,
11841 it's not clear what to do, so do nothing. */
11842 window_height
= window_box_height (w
);
11843 if (row
->height
>= window_height
)
11845 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11851 /* This code used to try to scroll the window just enough to make
11852 the line visible. It returned 0 to say that the caller should
11853 allocate larger glyph matrices. */
11855 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11857 int dy
= row
->height
- row
->visible_height
;
11860 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11862 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11864 int dy
= - (row
->height
- row
->visible_height
);
11867 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11870 /* When we change the cursor y-position of the selected window,
11871 change this_line_y as well so that the display optimization for
11872 the cursor line of the selected window in redisplay_internal uses
11873 the correct y-position. */
11874 if (w
== XWINDOW (selected_window
))
11875 this_line_y
= w
->cursor
.y
;
11877 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11878 redisplay with larger matrices. */
11879 if (matrix
->nrows
< required_matrix_height (w
))
11881 fonts_changed_p
= 1;
11890 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11891 non-zero means only WINDOW is redisplayed in redisplay_internal.
11892 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11893 in redisplay_window to bring a partially visible line into view in
11894 the case that only the cursor has moved.
11896 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11897 last screen line's vertical height extends past the end of the screen.
11901 1 if scrolling succeeded
11903 0 if scrolling didn't find point.
11905 -1 if new fonts have been loaded so that we must interrupt
11906 redisplay, adjust glyph matrices, and try again. */
11912 SCROLLING_NEED_LARGER_MATRICES
11916 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11917 scroll_step
, temp_scroll_step
, last_line_misfit
)
11918 Lisp_Object window
;
11919 int just_this_one_p
;
11920 EMACS_INT scroll_conservatively
, scroll_step
;
11921 int temp_scroll_step
;
11922 int last_line_misfit
;
11924 struct window
*w
= XWINDOW (window
);
11925 struct frame
*f
= XFRAME (w
->frame
);
11926 struct text_pos scroll_margin_pos
;
11927 struct text_pos pos
;
11928 struct text_pos startp
;
11930 Lisp_Object window_end
;
11931 int this_scroll_margin
;
11935 int amount_to_scroll
= 0;
11936 Lisp_Object aggressive
;
11938 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11941 debug_method_add (w
, "try_scrolling");
11944 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11946 /* Compute scroll margin height in pixels. We scroll when point is
11947 within this distance from the top or bottom of the window. */
11948 if (scroll_margin
> 0)
11950 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11951 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11954 this_scroll_margin
= 0;
11956 /* Force scroll_conservatively to have a reasonable value so it doesn't
11957 cause an overflow while computing how much to scroll. */
11958 if (scroll_conservatively
)
11959 scroll_conservatively
= min (scroll_conservatively
,
11960 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11962 /* Compute how much we should try to scroll maximally to bring point
11964 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11965 scroll_max
= max (scroll_step
,
11966 max (scroll_conservatively
, temp_scroll_step
));
11967 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11968 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11969 /* We're trying to scroll because of aggressive scrolling
11970 but no scroll_step is set. Choose an arbitrary one. Maybe
11971 there should be a variable for this. */
11975 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11977 /* Decide whether we have to scroll down. Start at the window end
11978 and move this_scroll_margin up to find the position of the scroll
11980 window_end
= Fwindow_end (window
, Qt
);
11984 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11985 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11987 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11989 start_display (&it
, w
, scroll_margin_pos
);
11990 if (this_scroll_margin
)
11991 move_it_vertically_backward (&it
, this_scroll_margin
);
11992 if (extra_scroll_margin_lines
)
11993 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11994 scroll_margin_pos
= it
.current
.pos
;
11997 if (PT
>= CHARPOS (scroll_margin_pos
))
12001 /* Point is in the scroll margin at the bottom of the window, or
12002 below. Compute a new window start that makes point visible. */
12004 /* Compute the distance from the scroll margin to PT.
12005 Give up if the distance is greater than scroll_max. */
12006 start_display (&it
, w
, scroll_margin_pos
);
12008 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12009 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12011 /* To make point visible, we have to move the window start
12012 down so that the line the cursor is in is visible, which
12013 means we have to add in the height of the cursor line. */
12014 dy
= line_bottom_y (&it
) - y0
;
12016 if (dy
> scroll_max
)
12017 return SCROLLING_FAILED
;
12019 /* Move the window start down. If scrolling conservatively,
12020 move it just enough down to make point visible. If
12021 scroll_step is set, move it down by scroll_step. */
12022 start_display (&it
, w
, startp
);
12024 if (scroll_conservatively
)
12025 /* Set AMOUNT_TO_SCROLL to at least one line,
12026 and at most scroll_conservatively lines. */
12028 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12029 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12030 else if (scroll_step
|| temp_scroll_step
)
12031 amount_to_scroll
= scroll_max
;
12034 aggressive
= current_buffer
->scroll_up_aggressively
;
12035 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12036 if (NUMBERP (aggressive
))
12038 double float_amount
= XFLOATINT (aggressive
) * height
;
12039 amount_to_scroll
= float_amount
;
12040 if (amount_to_scroll
== 0 && float_amount
> 0)
12041 amount_to_scroll
= 1;
12045 if (amount_to_scroll
<= 0)
12046 return SCROLLING_FAILED
;
12048 /* If moving by amount_to_scroll leaves STARTP unchanged,
12049 move it down one screen line. */
12051 move_it_vertically (&it
, amount_to_scroll
);
12052 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12053 move_it_by_lines (&it
, 1, 1);
12054 startp
= it
.current
.pos
;
12058 /* See if point is inside the scroll margin at the top of the
12060 scroll_margin_pos
= startp
;
12061 if (this_scroll_margin
)
12063 start_display (&it
, w
, startp
);
12064 move_it_vertically (&it
, this_scroll_margin
);
12065 scroll_margin_pos
= it
.current
.pos
;
12068 if (PT
< CHARPOS (scroll_margin_pos
))
12070 /* Point is in the scroll margin at the top of the window or
12071 above what is displayed in the window. */
12074 /* Compute the vertical distance from PT to the scroll
12075 margin position. Give up if distance is greater than
12077 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12078 start_display (&it
, w
, pos
);
12080 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12081 it
.last_visible_y
, -1,
12082 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12083 dy
= it
.current_y
- y0
;
12084 if (dy
> scroll_max
)
12085 return SCROLLING_FAILED
;
12087 /* Compute new window start. */
12088 start_display (&it
, w
, startp
);
12090 if (scroll_conservatively
)
12092 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12093 else if (scroll_step
|| temp_scroll_step
)
12094 amount_to_scroll
= scroll_max
;
12097 aggressive
= current_buffer
->scroll_down_aggressively
;
12098 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12099 if (NUMBERP (aggressive
))
12101 double float_amount
= XFLOATINT (aggressive
) * height
;
12102 amount_to_scroll
= float_amount
;
12103 if (amount_to_scroll
== 0 && float_amount
> 0)
12104 amount_to_scroll
= 1;
12108 if (amount_to_scroll
<= 0)
12109 return SCROLLING_FAILED
;
12111 move_it_vertically_backward (&it
, amount_to_scroll
);
12112 startp
= it
.current
.pos
;
12116 /* Run window scroll functions. */
12117 startp
= run_window_scroll_functions (window
, startp
);
12119 /* Display the window. Give up if new fonts are loaded, or if point
12121 if (!try_window (window
, startp
, 0))
12122 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12123 else if (w
->cursor
.vpos
< 0)
12125 clear_glyph_matrix (w
->desired_matrix
);
12126 rc
= SCROLLING_FAILED
;
12130 /* Maybe forget recorded base line for line number display. */
12131 if (!just_this_one_p
12132 || current_buffer
->clip_changed
12133 || BEG_UNCHANGED
< CHARPOS (startp
))
12134 w
->base_line_number
= Qnil
;
12136 /* If cursor ends up on a partially visible line,
12137 treat that as being off the bottom of the screen. */
12138 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12140 clear_glyph_matrix (w
->desired_matrix
);
12141 ++extra_scroll_margin_lines
;
12144 rc
= SCROLLING_SUCCESS
;
12151 /* Compute a suitable window start for window W if display of W starts
12152 on a continuation line. Value is non-zero if a new window start
12155 The new window start will be computed, based on W's width, starting
12156 from the start of the continued line. It is the start of the
12157 screen line with the minimum distance from the old start W->start. */
12160 compute_window_start_on_continuation_line (w
)
12163 struct text_pos pos
, start_pos
;
12164 int window_start_changed_p
= 0;
12166 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12168 /* If window start is on a continuation line... Window start may be
12169 < BEGV in case there's invisible text at the start of the
12170 buffer (M-x rmail, for example). */
12171 if (CHARPOS (start_pos
) > BEGV
12172 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12175 struct glyph_row
*row
;
12177 /* Handle the case that the window start is out of range. */
12178 if (CHARPOS (start_pos
) < BEGV
)
12179 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12180 else if (CHARPOS (start_pos
) > ZV
)
12181 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12183 /* Find the start of the continued line. This should be fast
12184 because scan_buffer is fast (newline cache). */
12185 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12186 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12187 row
, DEFAULT_FACE_ID
);
12188 reseat_at_previous_visible_line_start (&it
);
12190 /* If the line start is "too far" away from the window start,
12191 say it takes too much time to compute a new window start. */
12192 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12193 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12195 int min_distance
, distance
;
12197 /* Move forward by display lines to find the new window
12198 start. If window width was enlarged, the new start can
12199 be expected to be > the old start. If window width was
12200 decreased, the new window start will be < the old start.
12201 So, we're looking for the display line start with the
12202 minimum distance from the old window start. */
12203 pos
= it
.current
.pos
;
12204 min_distance
= INFINITY
;
12205 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12206 distance
< min_distance
)
12208 min_distance
= distance
;
12209 pos
= it
.current
.pos
;
12210 move_it_by_lines (&it
, 1, 0);
12213 /* Set the window start there. */
12214 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12215 window_start_changed_p
= 1;
12219 return window_start_changed_p
;
12223 /* Try cursor movement in case text has not changed in window WINDOW,
12224 with window start STARTP. Value is
12226 CURSOR_MOVEMENT_SUCCESS if successful
12228 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12230 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12231 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12232 we want to scroll as if scroll-step were set to 1. See the code.
12234 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12235 which case we have to abort this redisplay, and adjust matrices
12240 CURSOR_MOVEMENT_SUCCESS
,
12241 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12242 CURSOR_MOVEMENT_MUST_SCROLL
,
12243 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12247 try_cursor_movement (window
, startp
, scroll_step
)
12248 Lisp_Object window
;
12249 struct text_pos startp
;
12252 struct window
*w
= XWINDOW (window
);
12253 struct frame
*f
= XFRAME (w
->frame
);
12254 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12257 if (inhibit_try_cursor_movement
)
12261 /* Handle case where text has not changed, only point, and it has
12262 not moved off the frame. */
12263 if (/* Point may be in this window. */
12264 PT
>= CHARPOS (startp
)
12265 /* Selective display hasn't changed. */
12266 && !current_buffer
->clip_changed
12267 /* Function force-mode-line-update is used to force a thorough
12268 redisplay. It sets either windows_or_buffers_changed or
12269 update_mode_lines. So don't take a shortcut here for these
12271 && !update_mode_lines
12272 && !windows_or_buffers_changed
12273 && !cursor_type_changed
12274 /* Can't use this case if highlighting a region. When a
12275 region exists, cursor movement has to do more than just
12277 && !(!NILP (Vtransient_mark_mode
)
12278 && !NILP (current_buffer
->mark_active
))
12279 && NILP (w
->region_showing
)
12280 && NILP (Vshow_trailing_whitespace
)
12281 /* Right after splitting windows, last_point may be nil. */
12282 && INTEGERP (w
->last_point
)
12283 /* This code is not used for mini-buffer for the sake of the case
12284 of redisplaying to replace an echo area message; since in
12285 that case the mini-buffer contents per se are usually
12286 unchanged. This code is of no real use in the mini-buffer
12287 since the handling of this_line_start_pos, etc., in redisplay
12288 handles the same cases. */
12289 && !EQ (window
, minibuf_window
)
12290 /* When splitting windows or for new windows, it happens that
12291 redisplay is called with a nil window_end_vpos or one being
12292 larger than the window. This should really be fixed in
12293 window.c. I don't have this on my list, now, so we do
12294 approximately the same as the old redisplay code. --gerd. */
12295 && INTEGERP (w
->window_end_vpos
)
12296 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12297 && (FRAME_WINDOW_P (f
)
12298 || !overlay_arrow_in_current_buffer_p ()))
12300 int this_scroll_margin
, top_scroll_margin
;
12301 struct glyph_row
*row
= NULL
;
12304 debug_method_add (w
, "cursor movement");
12307 /* Scroll if point within this distance from the top or bottom
12308 of the window. This is a pixel value. */
12309 this_scroll_margin
= max (0, scroll_margin
);
12310 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12311 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12313 top_scroll_margin
= this_scroll_margin
;
12314 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12315 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12317 /* Start with the row the cursor was displayed during the last
12318 not paused redisplay. Give up if that row is not valid. */
12319 if (w
->last_cursor
.vpos
< 0
12320 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12321 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12324 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12325 if (row
->mode_line_p
)
12327 if (!row
->enabled_p
)
12328 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12331 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12334 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12336 if (PT
> XFASTINT (w
->last_point
))
12338 /* Point has moved forward. */
12339 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12340 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12342 xassert (row
->enabled_p
);
12346 /* The end position of a row equals the start position
12347 of the next row. If PT is there, we would rather
12348 display it in the next line. */
12349 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12350 && MATRIX_ROW_END_CHARPOS (row
) == PT
12351 && !cursor_row_p (w
, row
))
12354 /* If within the scroll margin, scroll. Note that
12355 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12356 the next line would be drawn, and that
12357 this_scroll_margin can be zero. */
12358 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12359 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12360 /* Line is completely visible last line in window
12361 and PT is to be set in the next line. */
12362 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12363 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12364 && !row
->ends_at_zv_p
12365 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12368 else if (PT
< XFASTINT (w
->last_point
))
12370 /* Cursor has to be moved backward. Note that PT >=
12371 CHARPOS (startp) because of the outer if-statement. */
12372 while (!row
->mode_line_p
12373 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12374 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12375 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12376 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12377 row
> w
->current_matrix
->rows
12378 && (row
-1)->ends_in_newline_from_string_p
))))
12379 && (row
->y
> top_scroll_margin
12380 || CHARPOS (startp
) == BEGV
))
12382 xassert (row
->enabled_p
);
12386 /* Consider the following case: Window starts at BEGV,
12387 there is invisible, intangible text at BEGV, so that
12388 display starts at some point START > BEGV. It can
12389 happen that we are called with PT somewhere between
12390 BEGV and START. Try to handle that case. */
12391 if (row
< w
->current_matrix
->rows
12392 || row
->mode_line_p
)
12394 row
= w
->current_matrix
->rows
;
12395 if (row
->mode_line_p
)
12399 /* Due to newlines in overlay strings, we may have to
12400 skip forward over overlay strings. */
12401 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12402 && MATRIX_ROW_END_CHARPOS (row
) == PT
12403 && !cursor_row_p (w
, row
))
12406 /* If within the scroll margin, scroll. */
12407 if (row
->y
< top_scroll_margin
12408 && CHARPOS (startp
) != BEGV
)
12413 /* Cursor did not move. So don't scroll even if cursor line
12414 is partially visible, as it was so before. */
12415 rc
= CURSOR_MOVEMENT_SUCCESS
;
12418 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12419 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12421 /* if PT is not in the glyph row, give up. */
12422 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12424 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12425 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12426 && make_cursor_line_fully_visible_p
)
12428 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12429 && !row
->ends_at_zv_p
12430 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12431 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12432 else if (row
->height
> window_box_height (w
))
12434 /* If we end up in a partially visible line, let's
12435 make it fully visible, except when it's taller
12436 than the window, in which case we can't do much
12439 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12443 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12444 if (!cursor_row_fully_visible_p (w
, 0, 1))
12445 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12447 rc
= CURSOR_MOVEMENT_SUCCESS
;
12451 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12454 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12455 rc
= CURSOR_MOVEMENT_SUCCESS
;
12464 set_vertical_scroll_bar (w
)
12467 int start
, end
, whole
;
12469 /* Calculate the start and end positions for the current window.
12470 At some point, it would be nice to choose between scrollbars
12471 which reflect the whole buffer size, with special markers
12472 indicating narrowing, and scrollbars which reflect only the
12475 Note that mini-buffers sometimes aren't displaying any text. */
12476 if (!MINI_WINDOW_P (w
)
12477 || (w
== XWINDOW (minibuf_window
)
12478 && NILP (echo_area_buffer
[0])))
12480 struct buffer
*buf
= XBUFFER (w
->buffer
);
12481 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12482 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12483 /* I don't think this is guaranteed to be right. For the
12484 moment, we'll pretend it is. */
12485 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12489 if (whole
< (end
- start
))
12490 whole
= end
- start
;
12493 start
= end
= whole
= 0;
12495 /* Indicate what this scroll bar ought to be displaying now. */
12496 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12500 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12501 selected_window is redisplayed.
12503 We can return without actually redisplaying the window if
12504 fonts_changed_p is nonzero. In that case, redisplay_internal will
12508 redisplay_window (window
, just_this_one_p
)
12509 Lisp_Object window
;
12510 int just_this_one_p
;
12512 struct window
*w
= XWINDOW (window
);
12513 struct frame
*f
= XFRAME (w
->frame
);
12514 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12515 struct buffer
*old
= current_buffer
;
12516 struct text_pos lpoint
, opoint
, startp
;
12517 int update_mode_line
;
12520 /* Record it now because it's overwritten. */
12521 int current_matrix_up_to_date_p
= 0;
12522 int used_current_matrix_p
= 0;
12523 /* This is less strict than current_matrix_up_to_date_p.
12524 It indictes that the buffer contents and narrowing are unchanged. */
12525 int buffer_unchanged_p
= 0;
12526 int temp_scroll_step
= 0;
12527 int count
= SPECPDL_INDEX ();
12529 int centering_position
= -1;
12530 int last_line_misfit
= 0;
12532 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12535 /* W must be a leaf window here. */
12536 xassert (!NILP (w
->buffer
));
12538 *w
->desired_matrix
->method
= 0;
12541 specbind (Qinhibit_point_motion_hooks
, Qt
);
12543 reconsider_clip_changes (w
, buffer
);
12545 /* Has the mode line to be updated? */
12546 update_mode_line
= (!NILP (w
->update_mode_line
)
12547 || update_mode_lines
12548 || buffer
->clip_changed
12549 || buffer
->prevent_redisplay_optimizations_p
);
12551 if (MINI_WINDOW_P (w
))
12553 if (w
== XWINDOW (echo_area_window
)
12554 && !NILP (echo_area_buffer
[0]))
12556 if (update_mode_line
)
12557 /* We may have to update a tty frame's menu bar or a
12558 tool-bar. Example `M-x C-h C-h C-g'. */
12559 goto finish_menu_bars
;
12561 /* We've already displayed the echo area glyphs in this window. */
12562 goto finish_scroll_bars
;
12564 else if ((w
!= XWINDOW (minibuf_window
)
12565 || minibuf_level
== 0)
12566 /* When buffer is nonempty, redisplay window normally. */
12567 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12568 /* Quail displays non-mini buffers in minibuffer window.
12569 In that case, redisplay the window normally. */
12570 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12572 /* W is a mini-buffer window, but it's not active, so clear
12574 int yb
= window_text_bottom_y (w
);
12575 struct glyph_row
*row
;
12578 for (y
= 0, row
= w
->desired_matrix
->rows
;
12580 y
+= row
->height
, ++row
)
12581 blank_row (w
, row
, y
);
12582 goto finish_scroll_bars
;
12585 clear_glyph_matrix (w
->desired_matrix
);
12588 /* Otherwise set up data on this window; select its buffer and point
12590 /* Really select the buffer, for the sake of buffer-local
12592 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12593 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12595 current_matrix_up_to_date_p
12596 = (!NILP (w
->window_end_valid
)
12597 && !current_buffer
->clip_changed
12598 && !current_buffer
->prevent_redisplay_optimizations_p
12599 && XFASTINT (w
->last_modified
) >= MODIFF
12600 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12603 = (!NILP (w
->window_end_valid
)
12604 && !current_buffer
->clip_changed
12605 && XFASTINT (w
->last_modified
) >= MODIFF
12606 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12608 /* When windows_or_buffers_changed is non-zero, we can't rely on
12609 the window end being valid, so set it to nil there. */
12610 if (windows_or_buffers_changed
)
12612 /* If window starts on a continuation line, maybe adjust the
12613 window start in case the window's width changed. */
12614 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12615 compute_window_start_on_continuation_line (w
);
12617 w
->window_end_valid
= Qnil
;
12620 /* Some sanity checks. */
12621 CHECK_WINDOW_END (w
);
12622 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12624 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12627 /* If %c is in mode line, update it if needed. */
12628 if (!NILP (w
->column_number_displayed
)
12629 /* This alternative quickly identifies a common case
12630 where no change is needed. */
12631 && !(PT
== XFASTINT (w
->last_point
)
12632 && XFASTINT (w
->last_modified
) >= MODIFF
12633 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12634 && (XFASTINT (w
->column_number_displayed
)
12635 != (int) current_column ())) /* iftc */
12636 update_mode_line
= 1;
12638 /* Count number of windows showing the selected buffer. An indirect
12639 buffer counts as its base buffer. */
12640 if (!just_this_one_p
)
12642 struct buffer
*current_base
, *window_base
;
12643 current_base
= current_buffer
;
12644 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12645 if (current_base
->base_buffer
)
12646 current_base
= current_base
->base_buffer
;
12647 if (window_base
->base_buffer
)
12648 window_base
= window_base
->base_buffer
;
12649 if (current_base
== window_base
)
12653 /* Point refers normally to the selected window. For any other
12654 window, set up appropriate value. */
12655 if (!EQ (window
, selected_window
))
12657 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12658 int new_pt_byte
= marker_byte_position (w
->pointm
);
12662 new_pt_byte
= BEGV_BYTE
;
12663 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12665 else if (new_pt
> (ZV
- 1))
12668 new_pt_byte
= ZV_BYTE
;
12669 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12672 /* We don't use SET_PT so that the point-motion hooks don't run. */
12673 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12676 /* If any of the character widths specified in the display table
12677 have changed, invalidate the width run cache. It's true that
12678 this may be a bit late to catch such changes, but the rest of
12679 redisplay goes (non-fatally) haywire when the display table is
12680 changed, so why should we worry about doing any better? */
12681 if (current_buffer
->width_run_cache
)
12683 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12685 if (! disptab_matches_widthtab (disptab
,
12686 XVECTOR (current_buffer
->width_table
)))
12688 invalidate_region_cache (current_buffer
,
12689 current_buffer
->width_run_cache
,
12691 recompute_width_table (current_buffer
, disptab
);
12695 /* If window-start is screwed up, choose a new one. */
12696 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12699 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12701 /* If someone specified a new starting point but did not insist,
12702 check whether it can be used. */
12703 if (!NILP (w
->optional_new_start
)
12704 && CHARPOS (startp
) >= BEGV
12705 && CHARPOS (startp
) <= ZV
)
12707 w
->optional_new_start
= Qnil
;
12708 start_display (&it
, w
, startp
);
12709 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12710 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12711 if (IT_CHARPOS (it
) == PT
)
12712 w
->force_start
= Qt
;
12713 /* IT may overshoot PT if text at PT is invisible. */
12714 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12715 w
->force_start
= Qt
;
12718 /* Handle case where place to start displaying has been specified,
12719 unless the specified location is outside the accessible range. */
12720 if (!NILP (w
->force_start
)
12721 || w
->frozen_window_start_p
)
12723 /* We set this later on if we have to adjust point. */
12727 w
->force_start
= Qnil
;
12729 w
->window_end_valid
= Qnil
;
12731 /* Forget any recorded base line for line number display. */
12732 if (!buffer_unchanged_p
)
12733 w
->base_line_number
= Qnil
;
12735 /* Redisplay the mode line. Select the buffer properly for that.
12736 Also, run the hook window-scroll-functions
12737 because we have scrolled. */
12738 /* Note, we do this after clearing force_start because
12739 if there's an error, it is better to forget about force_start
12740 than to get into an infinite loop calling the hook functions
12741 and having them get more errors. */
12742 if (!update_mode_line
12743 || ! NILP (Vwindow_scroll_functions
))
12745 update_mode_line
= 1;
12746 w
->update_mode_line
= Qt
;
12747 startp
= run_window_scroll_functions (window
, startp
);
12750 w
->last_modified
= make_number (0);
12751 w
->last_overlay_modified
= make_number (0);
12752 if (CHARPOS (startp
) < BEGV
)
12753 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12754 else if (CHARPOS (startp
) > ZV
)
12755 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12757 /* Redisplay, then check if cursor has been set during the
12758 redisplay. Give up if new fonts were loaded. */
12759 val
= try_window (window
, startp
, 1);
12762 w
->force_start
= Qt
;
12763 clear_glyph_matrix (w
->desired_matrix
);
12764 goto need_larger_matrices
;
12766 /* Point was outside the scroll margins. */
12768 new_vpos
= window_box_height (w
) / 2;
12770 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12772 /* If point does not appear, try to move point so it does
12773 appear. The desired matrix has been built above, so we
12774 can use it here. */
12775 new_vpos
= window_box_height (w
) / 2;
12778 if (!cursor_row_fully_visible_p (w
, 0, 0))
12780 /* Point does appear, but on a line partly visible at end of window.
12781 Move it back to a fully-visible line. */
12782 new_vpos
= window_box_height (w
);
12785 /* If we need to move point for either of the above reasons,
12786 now actually do it. */
12789 struct glyph_row
*row
;
12791 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12792 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12795 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12796 MATRIX_ROW_START_BYTEPOS (row
));
12798 if (w
!= XWINDOW (selected_window
))
12799 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12800 else if (current_buffer
== old
)
12801 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12803 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12805 /* If we are highlighting the region, then we just changed
12806 the region, so redisplay to show it. */
12807 if (!NILP (Vtransient_mark_mode
)
12808 && !NILP (current_buffer
->mark_active
))
12810 clear_glyph_matrix (w
->desired_matrix
);
12811 if (!try_window (window
, startp
, 0))
12812 goto need_larger_matrices
;
12817 debug_method_add (w
, "forced window start");
12822 /* Handle case where text has not changed, only point, and it has
12823 not moved off the frame, and we are not retrying after hscroll.
12824 (current_matrix_up_to_date_p is nonzero when retrying.) */
12825 if (current_matrix_up_to_date_p
12826 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12827 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12831 case CURSOR_MOVEMENT_SUCCESS
:
12832 used_current_matrix_p
= 1;
12835 #if 0 /* try_cursor_movement never returns this value. */
12836 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12837 goto need_larger_matrices
;
12840 case CURSOR_MOVEMENT_MUST_SCROLL
:
12841 goto try_to_scroll
;
12847 /* If current starting point was originally the beginning of a line
12848 but no longer is, find a new starting point. */
12849 else if (!NILP (w
->start_at_line_beg
)
12850 && !(CHARPOS (startp
) <= BEGV
12851 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12854 debug_method_add (w
, "recenter 1");
12859 /* Try scrolling with try_window_id. Value is > 0 if update has
12860 been done, it is -1 if we know that the same window start will
12861 not work. It is 0 if unsuccessful for some other reason. */
12862 else if ((tem
= try_window_id (w
)) != 0)
12865 debug_method_add (w
, "try_window_id %d", tem
);
12868 if (fonts_changed_p
)
12869 goto need_larger_matrices
;
12873 /* Otherwise try_window_id has returned -1 which means that we
12874 don't want the alternative below this comment to execute. */
12876 else if (CHARPOS (startp
) >= BEGV
12877 && CHARPOS (startp
) <= ZV
12878 && PT
>= CHARPOS (startp
)
12879 && (CHARPOS (startp
) < ZV
12880 /* Avoid starting at end of buffer. */
12881 || CHARPOS (startp
) == BEGV
12882 || (XFASTINT (w
->last_modified
) >= MODIFF
12883 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12886 /* If first window line is a continuation line, and window start
12887 is inside the modified region, but the first change is before
12888 current window start, we must select a new window start.*/
12889 if (NILP (w
->start_at_line_beg
)
12890 && CHARPOS (startp
) > BEGV
)
12892 /* Make sure beg_unchanged and end_unchanged are up to date.
12893 Do it only if buffer has really changed. This may or may
12894 not have been done by try_window_id (see which) already. */
12895 if (MODIFF
> SAVE_MODIFF
12896 /* This seems to happen sometimes after saving a buffer. */
12897 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12899 if (GPT
- BEG
< BEG_UNCHANGED
)
12900 BEG_UNCHANGED
= GPT
- BEG
;
12901 if (Z
- GPT
< END_UNCHANGED
)
12902 END_UNCHANGED
= Z
- GPT
;
12905 if (CHARPOS (startp
) > BEG
+ BEG_UNCHANGED
12906 && CHARPOS (startp
) <= Z
- END_UNCHANGED
)
12908 /* There doesn't seems to be a simple way to find a new
12909 window start that is near the old window start, so
12910 we just recenter. */
12916 debug_method_add (w
, "same window start");
12919 /* Try to redisplay starting at same place as before.
12920 If point has not moved off frame, accept the results. */
12921 if (!current_matrix_up_to_date_p
12922 /* Don't use try_window_reusing_current_matrix in this case
12923 because a window scroll function can have changed the
12925 || !NILP (Vwindow_scroll_functions
)
12926 || MINI_WINDOW_P (w
)
12927 || !(used_current_matrix_p
12928 = try_window_reusing_current_matrix (w
)))
12930 IF_DEBUG (debug_method_add (w
, "1"));
12931 if (try_window (window
, startp
, 1) < 0)
12932 /* -1 means we need to scroll.
12933 0 means we need new matrices, but fonts_changed_p
12934 is set in that case, so we will detect it below. */
12935 goto try_to_scroll
;
12938 if (fonts_changed_p
)
12939 goto need_larger_matrices
;
12941 if (w
->cursor
.vpos
>= 0)
12943 if (!just_this_one_p
12944 || current_buffer
->clip_changed
12945 || BEG_UNCHANGED
< CHARPOS (startp
))
12946 /* Forget any recorded base line for line number display. */
12947 w
->base_line_number
= Qnil
;
12949 if (!cursor_row_fully_visible_p (w
, 1, 0))
12951 clear_glyph_matrix (w
->desired_matrix
);
12952 last_line_misfit
= 1;
12954 /* Drop through and scroll. */
12959 clear_glyph_matrix (w
->desired_matrix
);
12964 w
->last_modified
= make_number (0);
12965 w
->last_overlay_modified
= make_number (0);
12967 /* Redisplay the mode line. Select the buffer properly for that. */
12968 if (!update_mode_line
)
12970 update_mode_line
= 1;
12971 w
->update_mode_line
= Qt
;
12974 /* Try to scroll by specified few lines. */
12975 if ((scroll_conservatively
12977 || temp_scroll_step
12978 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12979 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12980 && !current_buffer
->clip_changed
12981 && CHARPOS (startp
) >= BEGV
12982 && CHARPOS (startp
) <= ZV
)
12984 /* The function returns -1 if new fonts were loaded, 1 if
12985 successful, 0 if not successful. */
12986 int rc
= try_scrolling (window
, just_this_one_p
,
12987 scroll_conservatively
,
12989 temp_scroll_step
, last_line_misfit
);
12992 case SCROLLING_SUCCESS
:
12995 case SCROLLING_NEED_LARGER_MATRICES
:
12996 goto need_larger_matrices
;
12998 case SCROLLING_FAILED
:
13006 /* Finally, just choose place to start which centers point */
13009 if (centering_position
< 0)
13010 centering_position
= window_box_height (w
) / 2;
13013 debug_method_add (w
, "recenter");
13016 /* w->vscroll = 0; */
13018 /* Forget any previously recorded base line for line number display. */
13019 if (!buffer_unchanged_p
)
13020 w
->base_line_number
= Qnil
;
13022 /* Move backward half the height of the window. */
13023 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13024 it
.current_y
= it
.last_visible_y
;
13025 move_it_vertically_backward (&it
, centering_position
);
13026 xassert (IT_CHARPOS (it
) >= BEGV
);
13028 /* The function move_it_vertically_backward may move over more
13029 than the specified y-distance. If it->w is small, e.g. a
13030 mini-buffer window, we may end up in front of the window's
13031 display area. Start displaying at the start of the line
13032 containing PT in this case. */
13033 if (it
.current_y
<= 0)
13035 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13036 move_it_vertically_backward (&it
, 0);
13038 /* I think this assert is bogus if buffer contains
13039 invisible text or images. KFS. */
13040 xassert (IT_CHARPOS (it
) <= PT
);
13045 it
.current_x
= it
.hpos
= 0;
13047 /* Set startp here explicitly in case that helps avoid an infinite loop
13048 in case the window-scroll-functions functions get errors. */
13049 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13051 /* Run scroll hooks. */
13052 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13054 /* Redisplay the window. */
13055 if (!current_matrix_up_to_date_p
13056 || windows_or_buffers_changed
13057 || cursor_type_changed
13058 /* Don't use try_window_reusing_current_matrix in this case
13059 because it can have changed the buffer. */
13060 || !NILP (Vwindow_scroll_functions
)
13061 || !just_this_one_p
13062 || MINI_WINDOW_P (w
)
13063 || !(used_current_matrix_p
13064 = try_window_reusing_current_matrix (w
)))
13065 try_window (window
, startp
, 0);
13067 /* If new fonts have been loaded (due to fontsets), give up. We
13068 have to start a new redisplay since we need to re-adjust glyph
13070 if (fonts_changed_p
)
13071 goto need_larger_matrices
;
13073 /* If cursor did not appear assume that the middle of the window is
13074 in the first line of the window. Do it again with the next line.
13075 (Imagine a window of height 100, displaying two lines of height
13076 60. Moving back 50 from it->last_visible_y will end in the first
13078 if (w
->cursor
.vpos
< 0)
13080 if (!NILP (w
->window_end_valid
)
13081 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13083 clear_glyph_matrix (w
->desired_matrix
);
13084 move_it_by_lines (&it
, 1, 0);
13085 try_window (window
, it
.current
.pos
, 0);
13087 else if (PT
< IT_CHARPOS (it
))
13089 clear_glyph_matrix (w
->desired_matrix
);
13090 move_it_by_lines (&it
, -1, 0);
13091 try_window (window
, it
.current
.pos
, 0);
13095 /* Not much we can do about it. */
13099 /* Consider the following case: Window starts at BEGV, there is
13100 invisible, intangible text at BEGV, so that display starts at
13101 some point START > BEGV. It can happen that we are called with
13102 PT somewhere between BEGV and START. Try to handle that case. */
13103 if (w
->cursor
.vpos
< 0)
13105 struct glyph_row
*row
= w
->current_matrix
->rows
;
13106 if (row
->mode_line_p
)
13108 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13111 if (!cursor_row_fully_visible_p (w
, 0, 0))
13113 /* If vscroll is enabled, disable it and try again. */
13117 clear_glyph_matrix (w
->desired_matrix
);
13121 /* If centering point failed to make the whole line visible,
13122 put point at the top instead. That has to make the whole line
13123 visible, if it can be done. */
13124 if (centering_position
== 0)
13127 clear_glyph_matrix (w
->desired_matrix
);
13128 centering_position
= 0;
13134 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13135 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13136 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13139 /* Display the mode line, if we must. */
13140 if ((update_mode_line
13141 /* If window not full width, must redo its mode line
13142 if (a) the window to its side is being redone and
13143 (b) we do a frame-based redisplay. This is a consequence
13144 of how inverted lines are drawn in frame-based redisplay. */
13145 || (!just_this_one_p
13146 && !FRAME_WINDOW_P (f
)
13147 && !WINDOW_FULL_WIDTH_P (w
))
13148 /* Line number to display. */
13149 || INTEGERP (w
->base_line_pos
)
13150 /* Column number is displayed and different from the one displayed. */
13151 || (!NILP (w
->column_number_displayed
)
13152 && (XFASTINT (w
->column_number_displayed
)
13153 != (int) current_column ()))) /* iftc */
13154 /* This means that the window has a mode line. */
13155 && (WINDOW_WANTS_MODELINE_P (w
)
13156 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13158 display_mode_lines (w
);
13160 /* If mode line height has changed, arrange for a thorough
13161 immediate redisplay using the correct mode line height. */
13162 if (WINDOW_WANTS_MODELINE_P (w
)
13163 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13165 fonts_changed_p
= 1;
13166 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13167 = DESIRED_MODE_LINE_HEIGHT (w
);
13170 /* If top line height has changed, arrange for a thorough
13171 immediate redisplay using the correct mode line height. */
13172 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13173 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13175 fonts_changed_p
= 1;
13176 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13177 = DESIRED_HEADER_LINE_HEIGHT (w
);
13180 if (fonts_changed_p
)
13181 goto need_larger_matrices
;
13184 if (!line_number_displayed
13185 && !BUFFERP (w
->base_line_pos
))
13187 w
->base_line_pos
= Qnil
;
13188 w
->base_line_number
= Qnil
;
13193 /* When we reach a frame's selected window, redo the frame's menu bar. */
13194 if (update_mode_line
13195 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13197 int redisplay_menu_p
= 0;
13198 int redisplay_tool_bar_p
= 0;
13200 if (FRAME_WINDOW_P (f
))
13202 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13203 || defined (USE_GTK)
13204 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13206 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13210 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13212 if (redisplay_menu_p
)
13213 display_menu_bar (w
);
13215 #ifdef HAVE_WINDOW_SYSTEM
13217 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13219 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13220 && (FRAME_TOOL_BAR_LINES (f
) > 0
13221 || auto_resize_tool_bars_p
);
13225 if (redisplay_tool_bar_p
)
13226 redisplay_tool_bar (f
);
13230 #ifdef HAVE_WINDOW_SYSTEM
13231 if (FRAME_WINDOW_P (f
)
13232 && update_window_fringes (w
, (just_this_one_p
13233 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13234 || w
->pseudo_window_p
)))
13238 if (draw_window_fringes (w
, 1))
13239 x_draw_vertical_border (w
);
13243 #endif /* HAVE_WINDOW_SYSTEM */
13245 /* We go to this label, with fonts_changed_p nonzero,
13246 if it is necessary to try again using larger glyph matrices.
13247 We have to redeem the scroll bar even in this case,
13248 because the loop in redisplay_internal expects that. */
13249 need_larger_matrices
:
13251 finish_scroll_bars
:
13253 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13255 /* Set the thumb's position and size. */
13256 set_vertical_scroll_bar (w
);
13258 /* Note that we actually used the scroll bar attached to this
13259 window, so it shouldn't be deleted at the end of redisplay. */
13260 redeem_scroll_bar_hook (w
);
13263 /* Restore current_buffer and value of point in it. */
13264 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13265 set_buffer_internal_1 (old
);
13266 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13268 unbind_to (count
, Qnil
);
13272 /* Build the complete desired matrix of WINDOW with a window start
13273 buffer position POS.
13275 Value is 1 if successful. It is zero if fonts were loaded during
13276 redisplay which makes re-adjusting glyph matrices necessary, and -1
13277 if point would appear in the scroll margins.
13278 (We check that only if CHECK_MARGINS is nonzero. */
13281 try_window (window
, pos
, check_margins
)
13282 Lisp_Object window
;
13283 struct text_pos pos
;
13286 struct window
*w
= XWINDOW (window
);
13288 struct glyph_row
*last_text_row
= NULL
;
13290 /* Make POS the new window start. */
13291 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13293 /* Mark cursor position as unknown. No overlay arrow seen. */
13294 w
->cursor
.vpos
= -1;
13295 overlay_arrow_seen
= 0;
13297 /* Initialize iterator and info to start at POS. */
13298 start_display (&it
, w
, pos
);
13300 /* Display all lines of W. */
13301 while (it
.current_y
< it
.last_visible_y
)
13303 if (display_line (&it
))
13304 last_text_row
= it
.glyph_row
- 1;
13305 if (fonts_changed_p
)
13309 /* Don't let the cursor end in the scroll margins. */
13311 && !MINI_WINDOW_P (w
))
13313 int this_scroll_margin
;
13315 this_scroll_margin
= max (0, scroll_margin
);
13316 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13317 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13319 if ((w
->cursor
.y
< this_scroll_margin
13320 && CHARPOS (pos
) > BEGV
13321 && IT_CHARPOS (it
) < ZV
)
13322 /* rms: considering make_cursor_line_fully_visible_p here
13323 seems to give wrong results. We don't want to recenter
13324 when the last line is partly visible, we want to allow
13325 that case to be handled in the usual way. */
13326 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13328 w
->cursor
.vpos
= -1;
13329 clear_glyph_matrix (w
->desired_matrix
);
13334 /* If bottom moved off end of frame, change mode line percentage. */
13335 if (XFASTINT (w
->window_end_pos
) <= 0
13336 && Z
!= IT_CHARPOS (it
))
13337 w
->update_mode_line
= Qt
;
13339 /* Set window_end_pos to the offset of the last character displayed
13340 on the window from the end of current_buffer. Set
13341 window_end_vpos to its row number. */
13344 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13345 w
->window_end_bytepos
13346 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13348 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13350 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13351 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13352 ->displays_text_p
);
13356 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13357 w
->window_end_pos
= make_number (Z
- ZV
);
13358 w
->window_end_vpos
= make_number (0);
13361 /* But that is not valid info until redisplay finishes. */
13362 w
->window_end_valid
= Qnil
;
13368 /************************************************************************
13369 Window redisplay reusing current matrix when buffer has not changed
13370 ************************************************************************/
13372 /* Try redisplay of window W showing an unchanged buffer with a
13373 different window start than the last time it was displayed by
13374 reusing its current matrix. Value is non-zero if successful.
13375 W->start is the new window start. */
13378 try_window_reusing_current_matrix (w
)
13381 struct frame
*f
= XFRAME (w
->frame
);
13382 struct glyph_row
*row
, *bottom_row
;
13385 struct text_pos start
, new_start
;
13386 int nrows_scrolled
, i
;
13387 struct glyph_row
*last_text_row
;
13388 struct glyph_row
*last_reused_text_row
;
13389 struct glyph_row
*start_row
;
13390 int start_vpos
, min_y
, max_y
;
13393 if (inhibit_try_window_reusing
)
13397 if (/* This function doesn't handle terminal frames. */
13398 !FRAME_WINDOW_P (f
)
13399 /* Don't try to reuse the display if windows have been split
13401 || windows_or_buffers_changed
13402 || cursor_type_changed
)
13405 /* Can't do this if region may have changed. */
13406 if ((!NILP (Vtransient_mark_mode
)
13407 && !NILP (current_buffer
->mark_active
))
13408 || !NILP (w
->region_showing
)
13409 || !NILP (Vshow_trailing_whitespace
))
13412 /* If top-line visibility has changed, give up. */
13413 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13414 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13417 /* Give up if old or new display is scrolled vertically. We could
13418 make this function handle this, but right now it doesn't. */
13419 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13420 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13423 /* The variable new_start now holds the new window start. The old
13424 start `start' can be determined from the current matrix. */
13425 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13426 start
= start_row
->start
.pos
;
13427 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13429 /* Clear the desired matrix for the display below. */
13430 clear_glyph_matrix (w
->desired_matrix
);
13432 if (CHARPOS (new_start
) <= CHARPOS (start
))
13436 /* Don't use this method if the display starts with an ellipsis
13437 displayed for invisible text. It's not easy to handle that case
13438 below, and it's certainly not worth the effort since this is
13439 not a frequent case. */
13440 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13443 IF_DEBUG (debug_method_add (w
, "twu1"));
13445 /* Display up to a row that can be reused. The variable
13446 last_text_row is set to the last row displayed that displays
13447 text. Note that it.vpos == 0 if or if not there is a
13448 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13449 start_display (&it
, w
, new_start
);
13450 first_row_y
= it
.current_y
;
13451 w
->cursor
.vpos
= -1;
13452 last_text_row
= last_reused_text_row
= NULL
;
13454 while (it
.current_y
< it
.last_visible_y
13455 && !fonts_changed_p
)
13457 /* If we have reached into the characters in the START row,
13458 that means the line boundaries have changed. So we
13459 can't start copying with the row START. Maybe it will
13460 work to start copying with the following row. */
13461 while (IT_CHARPOS (it
) > CHARPOS (start
))
13463 /* Advance to the next row as the "start". */
13465 start
= start_row
->start
.pos
;
13466 /* If there are no more rows to try, or just one, give up. */
13467 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13468 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13469 || CHARPOS (start
) == ZV
)
13471 clear_glyph_matrix (w
->desired_matrix
);
13475 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13477 /* If we have reached alignment,
13478 we can copy the rest of the rows. */
13479 if (IT_CHARPOS (it
) == CHARPOS (start
))
13482 if (display_line (&it
))
13483 last_text_row
= it
.glyph_row
- 1;
13486 /* A value of current_y < last_visible_y means that we stopped
13487 at the previous window start, which in turn means that we
13488 have at least one reusable row. */
13489 if (it
.current_y
< it
.last_visible_y
)
13491 /* IT.vpos always starts from 0; it counts text lines. */
13492 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13494 /* Find PT if not already found in the lines displayed. */
13495 if (w
->cursor
.vpos
< 0)
13497 int dy
= it
.current_y
- start_row
->y
;
13499 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13500 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13502 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13503 dy
, nrows_scrolled
);
13506 clear_glyph_matrix (w
->desired_matrix
);
13511 /* Scroll the display. Do it before the current matrix is
13512 changed. The problem here is that update has not yet
13513 run, i.e. part of the current matrix is not up to date.
13514 scroll_run_hook will clear the cursor, and use the
13515 current matrix to get the height of the row the cursor is
13517 run
.current_y
= start_row
->y
;
13518 run
.desired_y
= it
.current_y
;
13519 run
.height
= it
.last_visible_y
- it
.current_y
;
13521 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13524 rif
->update_window_begin_hook (w
);
13525 rif
->clear_window_mouse_face (w
);
13526 rif
->scroll_run_hook (w
, &run
);
13527 rif
->update_window_end_hook (w
, 0, 0);
13531 /* Shift current matrix down by nrows_scrolled lines. */
13532 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13533 rotate_matrix (w
->current_matrix
,
13535 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13538 /* Disable lines that must be updated. */
13539 for (i
= 0; i
< it
.vpos
; ++i
)
13540 (start_row
+ i
)->enabled_p
= 0;
13542 /* Re-compute Y positions. */
13543 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13544 max_y
= it
.last_visible_y
;
13545 for (row
= start_row
+ nrows_scrolled
;
13549 row
->y
= it
.current_y
;
13550 row
->visible_height
= row
->height
;
13552 if (row
->y
< min_y
)
13553 row
->visible_height
-= min_y
- row
->y
;
13554 if (row
->y
+ row
->height
> max_y
)
13555 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13556 row
->redraw_fringe_bitmaps_p
= 1;
13558 it
.current_y
+= row
->height
;
13560 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13561 last_reused_text_row
= row
;
13562 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13566 /* Disable lines in the current matrix which are now
13567 below the window. */
13568 for (++row
; row
< bottom_row
; ++row
)
13569 row
->enabled_p
= row
->mode_line_p
= 0;
13572 /* Update window_end_pos etc.; last_reused_text_row is the last
13573 reused row from the current matrix containing text, if any.
13574 The value of last_text_row is the last displayed line
13575 containing text. */
13576 if (last_reused_text_row
)
13578 w
->window_end_bytepos
13579 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13581 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13583 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13584 w
->current_matrix
));
13586 else if (last_text_row
)
13588 w
->window_end_bytepos
13589 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13591 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13593 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13597 /* This window must be completely empty. */
13598 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13599 w
->window_end_pos
= make_number (Z
- ZV
);
13600 w
->window_end_vpos
= make_number (0);
13602 w
->window_end_valid
= Qnil
;
13604 /* Update hint: don't try scrolling again in update_window. */
13605 w
->desired_matrix
->no_scrolling_p
= 1;
13608 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13612 else if (CHARPOS (new_start
) > CHARPOS (start
))
13614 struct glyph_row
*pt_row
, *row
;
13615 struct glyph_row
*first_reusable_row
;
13616 struct glyph_row
*first_row_to_display
;
13618 int yb
= window_text_bottom_y (w
);
13620 /* Find the row starting at new_start, if there is one. Don't
13621 reuse a partially visible line at the end. */
13622 first_reusable_row
= start_row
;
13623 while (first_reusable_row
->enabled_p
13624 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13625 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13626 < CHARPOS (new_start
)))
13627 ++first_reusable_row
;
13629 /* Give up if there is no row to reuse. */
13630 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13631 || !first_reusable_row
->enabled_p
13632 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13633 != CHARPOS (new_start
)))
13636 /* We can reuse fully visible rows beginning with
13637 first_reusable_row to the end of the window. Set
13638 first_row_to_display to the first row that cannot be reused.
13639 Set pt_row to the row containing point, if there is any. */
13641 for (first_row_to_display
= first_reusable_row
;
13642 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13643 ++first_row_to_display
)
13645 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13646 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13647 pt_row
= first_row_to_display
;
13650 /* Start displaying at the start of first_row_to_display. */
13651 xassert (first_row_to_display
->y
< yb
);
13652 init_to_row_start (&it
, w
, first_row_to_display
);
13654 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13656 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13658 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13659 + WINDOW_HEADER_LINE_HEIGHT (w
));
13661 /* Display lines beginning with first_row_to_display in the
13662 desired matrix. Set last_text_row to the last row displayed
13663 that displays text. */
13664 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13665 if (pt_row
== NULL
)
13666 w
->cursor
.vpos
= -1;
13667 last_text_row
= NULL
;
13668 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13669 if (display_line (&it
))
13670 last_text_row
= it
.glyph_row
- 1;
13672 /* Give up If point isn't in a row displayed or reused. */
13673 if (w
->cursor
.vpos
< 0)
13675 clear_glyph_matrix (w
->desired_matrix
);
13679 /* If point is in a reused row, adjust y and vpos of the cursor
13683 w
->cursor
.vpos
-= nrows_scrolled
;
13684 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13687 /* Scroll the display. */
13688 run
.current_y
= first_reusable_row
->y
;
13689 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13690 run
.height
= it
.last_visible_y
- run
.current_y
;
13691 dy
= run
.current_y
- run
.desired_y
;
13696 rif
->update_window_begin_hook (w
);
13697 rif
->clear_window_mouse_face (w
);
13698 rif
->scroll_run_hook (w
, &run
);
13699 rif
->update_window_end_hook (w
, 0, 0);
13703 /* Adjust Y positions of reused rows. */
13704 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13705 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13706 max_y
= it
.last_visible_y
;
13707 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13710 row
->visible_height
= row
->height
;
13711 if (row
->y
< min_y
)
13712 row
->visible_height
-= min_y
- row
->y
;
13713 if (row
->y
+ row
->height
> max_y
)
13714 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13715 row
->redraw_fringe_bitmaps_p
= 1;
13718 /* Scroll the current matrix. */
13719 xassert (nrows_scrolled
> 0);
13720 rotate_matrix (w
->current_matrix
,
13722 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13725 /* Disable rows not reused. */
13726 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13727 row
->enabled_p
= 0;
13729 /* Point may have moved to a different line, so we cannot assume that
13730 the previous cursor position is valid; locate the correct row. */
13733 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13734 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13738 w
->cursor
.y
= row
->y
;
13740 if (row
< bottom_row
)
13742 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13743 while (glyph
->charpos
< PT
)
13746 w
->cursor
.x
+= glyph
->pixel_width
;
13752 /* Adjust window end. A null value of last_text_row means that
13753 the window end is in reused rows which in turn means that
13754 only its vpos can have changed. */
13757 w
->window_end_bytepos
13758 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13760 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13762 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13767 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13770 w
->window_end_valid
= Qnil
;
13771 w
->desired_matrix
->no_scrolling_p
= 1;
13774 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13784 /************************************************************************
13785 Window redisplay reusing current matrix when buffer has changed
13786 ************************************************************************/
13788 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13789 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13791 static struct glyph_row
*
13792 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13793 struct glyph_row
*));
13796 /* Return the last row in MATRIX displaying text. If row START is
13797 non-null, start searching with that row. IT gives the dimensions
13798 of the display. Value is null if matrix is empty; otherwise it is
13799 a pointer to the row found. */
13801 static struct glyph_row
*
13802 find_last_row_displaying_text (matrix
, it
, start
)
13803 struct glyph_matrix
*matrix
;
13805 struct glyph_row
*start
;
13807 struct glyph_row
*row
, *row_found
;
13809 /* Set row_found to the last row in IT->w's current matrix
13810 displaying text. The loop looks funny but think of partially
13813 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13814 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13816 xassert (row
->enabled_p
);
13818 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13827 /* Return the last row in the current matrix of W that is not affected
13828 by changes at the start of current_buffer that occurred since W's
13829 current matrix was built. Value is null if no such row exists.
13831 BEG_UNCHANGED us the number of characters unchanged at the start of
13832 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13833 first changed character in current_buffer. Characters at positions <
13834 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13835 when the current matrix was built. */
13837 static struct glyph_row
*
13838 find_last_unchanged_at_beg_row (w
)
13841 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13842 struct glyph_row
*row
;
13843 struct glyph_row
*row_found
= NULL
;
13844 int yb
= window_text_bottom_y (w
);
13846 /* Find the last row displaying unchanged text. */
13847 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13848 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13849 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13851 if (/* If row ends before first_changed_pos, it is unchanged,
13852 except in some case. */
13853 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13854 /* When row ends in ZV and we write at ZV it is not
13856 && !row
->ends_at_zv_p
13857 /* When first_changed_pos is the end of a continued line,
13858 row is not unchanged because it may be no longer
13860 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13861 && (row
->continued_p
13862 || row
->exact_window_width_line_p
)))
13865 /* Stop if last visible row. */
13866 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13876 /* Find the first glyph row in the current matrix of W that is not
13877 affected by changes at the end of current_buffer since the
13878 time W's current matrix was built.
13880 Return in *DELTA the number of chars by which buffer positions in
13881 unchanged text at the end of current_buffer must be adjusted.
13883 Return in *DELTA_BYTES the corresponding number of bytes.
13885 Value is null if no such row exists, i.e. all rows are affected by
13888 static struct glyph_row
*
13889 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13891 int *delta
, *delta_bytes
;
13893 struct glyph_row
*row
;
13894 struct glyph_row
*row_found
= NULL
;
13896 *delta
= *delta_bytes
= 0;
13898 /* Display must not have been paused, otherwise the current matrix
13899 is not up to date. */
13900 if (NILP (w
->window_end_valid
))
13903 /* A value of window_end_pos >= END_UNCHANGED means that the window
13904 end is in the range of changed text. If so, there is no
13905 unchanged row at the end of W's current matrix. */
13906 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13909 /* Set row to the last row in W's current matrix displaying text. */
13910 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13912 /* If matrix is entirely empty, no unchanged row exists. */
13913 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13915 /* The value of row is the last glyph row in the matrix having a
13916 meaningful buffer position in it. The end position of row
13917 corresponds to window_end_pos. This allows us to translate
13918 buffer positions in the current matrix to current buffer
13919 positions for characters not in changed text. */
13920 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13921 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13922 int last_unchanged_pos
, last_unchanged_pos_old
;
13923 struct glyph_row
*first_text_row
13924 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13926 *delta
= Z
- Z_old
;
13927 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13929 /* Set last_unchanged_pos to the buffer position of the last
13930 character in the buffer that has not been changed. Z is the
13931 index + 1 of the last character in current_buffer, i.e. by
13932 subtracting END_UNCHANGED we get the index of the last
13933 unchanged character, and we have to add BEG to get its buffer
13935 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13936 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13938 /* Search backward from ROW for a row displaying a line that
13939 starts at a minimum position >= last_unchanged_pos_old. */
13940 for (; row
> first_text_row
; --row
)
13942 /* This used to abort, but it can happen.
13943 It is ok to just stop the search instead here. KFS. */
13944 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13947 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13952 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13959 /* Make sure that glyph rows in the current matrix of window W
13960 reference the same glyph memory as corresponding rows in the
13961 frame's frame matrix. This function is called after scrolling W's
13962 current matrix on a terminal frame in try_window_id and
13963 try_window_reusing_current_matrix. */
13966 sync_frame_with_window_matrix_rows (w
)
13969 struct frame
*f
= XFRAME (w
->frame
);
13970 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13972 /* Preconditions: W must be a leaf window and full-width. Its frame
13973 must have a frame matrix. */
13974 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13975 xassert (WINDOW_FULL_WIDTH_P (w
));
13976 xassert (!FRAME_WINDOW_P (f
));
13978 /* If W is a full-width window, glyph pointers in W's current matrix
13979 have, by definition, to be the same as glyph pointers in the
13980 corresponding frame matrix. Note that frame matrices have no
13981 marginal areas (see build_frame_matrix). */
13982 window_row
= w
->current_matrix
->rows
;
13983 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13984 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13985 while (window_row
< window_row_end
)
13987 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13988 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13990 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13991 frame_row
->glyphs
[TEXT_AREA
] = start
;
13992 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13993 frame_row
->glyphs
[LAST_AREA
] = end
;
13995 /* Disable frame rows whose corresponding window rows have
13996 been disabled in try_window_id. */
13997 if (!window_row
->enabled_p
)
13998 frame_row
->enabled_p
= 0;
14000 ++window_row
, ++frame_row
;
14005 /* Find the glyph row in window W containing CHARPOS. Consider all
14006 rows between START and END (not inclusive). END null means search
14007 all rows to the end of the display area of W. Value is the row
14008 containing CHARPOS or null. */
14011 row_containing_pos (w
, charpos
, start
, end
, dy
)
14014 struct glyph_row
*start
, *end
;
14017 struct glyph_row
*row
= start
;
14020 /* If we happen to start on a header-line, skip that. */
14021 if (row
->mode_line_p
)
14024 if ((end
&& row
>= end
) || !row
->enabled_p
)
14027 last_y
= window_text_bottom_y (w
) - dy
;
14031 /* Give up if we have gone too far. */
14032 if (end
&& row
>= end
)
14034 /* This formerly returned if they were equal.
14035 I think that both quantities are of a "last plus one" type;
14036 if so, when they are equal, the row is within the screen. -- rms. */
14037 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14040 /* If it is in this row, return this row. */
14041 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14042 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14043 /* The end position of a row equals the start
14044 position of the next row. If CHARPOS is there, we
14045 would rather display it in the next line, except
14046 when this line ends in ZV. */
14047 && !row
->ends_at_zv_p
14048 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14049 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14056 /* Try to redisplay window W by reusing its existing display. W's
14057 current matrix must be up to date when this function is called,
14058 i.e. window_end_valid must not be nil.
14062 1 if display has been updated
14063 0 if otherwise unsuccessful
14064 -1 if redisplay with same window start is known not to succeed
14066 The following steps are performed:
14068 1. Find the last row in the current matrix of W that is not
14069 affected by changes at the start of current_buffer. If no such row
14072 2. Find the first row in W's current matrix that is not affected by
14073 changes at the end of current_buffer. Maybe there is no such row.
14075 3. Display lines beginning with the row + 1 found in step 1 to the
14076 row found in step 2 or, if step 2 didn't find a row, to the end of
14079 4. If cursor is not known to appear on the window, give up.
14081 5. If display stopped at the row found in step 2, scroll the
14082 display and current matrix as needed.
14084 6. Maybe display some lines at the end of W, if we must. This can
14085 happen under various circumstances, like a partially visible line
14086 becoming fully visible, or because newly displayed lines are displayed
14087 in smaller font sizes.
14089 7. Update W's window end information. */
14095 struct frame
*f
= XFRAME (w
->frame
);
14096 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14097 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14098 struct glyph_row
*last_unchanged_at_beg_row
;
14099 struct glyph_row
*first_unchanged_at_end_row
;
14100 struct glyph_row
*row
;
14101 struct glyph_row
*bottom_row
;
14104 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14105 struct text_pos start_pos
;
14107 int first_unchanged_at_end_vpos
= 0;
14108 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14109 struct text_pos start
;
14110 int first_changed_charpos
, last_changed_charpos
;
14113 if (inhibit_try_window_id
)
14117 /* This is handy for debugging. */
14119 #define GIVE_UP(X) \
14121 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14125 #define GIVE_UP(X) return 0
14128 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14130 /* Don't use this for mini-windows because these can show
14131 messages and mini-buffers, and we don't handle that here. */
14132 if (MINI_WINDOW_P (w
))
14135 /* This flag is used to prevent redisplay optimizations. */
14136 if (windows_or_buffers_changed
|| cursor_type_changed
)
14139 /* Verify that narrowing has not changed.
14140 Also verify that we were not told to prevent redisplay optimizations.
14141 It would be nice to further
14142 reduce the number of cases where this prevents try_window_id. */
14143 if (current_buffer
->clip_changed
14144 || current_buffer
->prevent_redisplay_optimizations_p
)
14147 /* Window must either use window-based redisplay or be full width. */
14148 if (!FRAME_WINDOW_P (f
)
14149 && (!line_ins_del_ok
14150 || !WINDOW_FULL_WIDTH_P (w
)))
14153 /* Give up if point is not known NOT to appear in W. */
14154 if (PT
< CHARPOS (start
))
14157 /* Another way to prevent redisplay optimizations. */
14158 if (XFASTINT (w
->last_modified
) == 0)
14161 /* Verify that window is not hscrolled. */
14162 if (XFASTINT (w
->hscroll
) != 0)
14165 /* Verify that display wasn't paused. */
14166 if (NILP (w
->window_end_valid
))
14169 /* Can't use this if highlighting a region because a cursor movement
14170 will do more than just set the cursor. */
14171 if (!NILP (Vtransient_mark_mode
)
14172 && !NILP (current_buffer
->mark_active
))
14175 /* Likewise if highlighting trailing whitespace. */
14176 if (!NILP (Vshow_trailing_whitespace
))
14179 /* Likewise if showing a region. */
14180 if (!NILP (w
->region_showing
))
14183 /* Can use this if overlay arrow position and or string have changed. */
14184 if (overlay_arrows_changed_p ())
14188 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14189 only if buffer has really changed. The reason is that the gap is
14190 initially at Z for freshly visited files. The code below would
14191 set end_unchanged to 0 in that case. */
14192 if (MODIFF
> SAVE_MODIFF
14193 /* This seems to happen sometimes after saving a buffer. */
14194 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14196 if (GPT
- BEG
< BEG_UNCHANGED
)
14197 BEG_UNCHANGED
= GPT
- BEG
;
14198 if (Z
- GPT
< END_UNCHANGED
)
14199 END_UNCHANGED
= Z
- GPT
;
14202 /* The position of the first and last character that has been changed. */
14203 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14204 last_changed_charpos
= Z
- END_UNCHANGED
;
14206 /* If window starts after a line end, and the last change is in
14207 front of that newline, then changes don't affect the display.
14208 This case happens with stealth-fontification. Note that although
14209 the display is unchanged, glyph positions in the matrix have to
14210 be adjusted, of course. */
14211 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14212 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14213 && ((last_changed_charpos
< CHARPOS (start
)
14214 && CHARPOS (start
) == BEGV
)
14215 || (last_changed_charpos
< CHARPOS (start
) - 1
14216 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14218 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14219 struct glyph_row
*r0
;
14221 /* Compute how many chars/bytes have been added to or removed
14222 from the buffer. */
14223 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14224 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14226 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14228 /* Give up if PT is not in the window. Note that it already has
14229 been checked at the start of try_window_id that PT is not in
14230 front of the window start. */
14231 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14234 /* If window start is unchanged, we can reuse the whole matrix
14235 as is, after adjusting glyph positions. No need to compute
14236 the window end again, since its offset from Z hasn't changed. */
14237 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14238 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14239 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14240 /* PT must not be in a partially visible line. */
14241 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14242 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14244 /* Adjust positions in the glyph matrix. */
14245 if (delta
|| delta_bytes
)
14247 struct glyph_row
*r1
14248 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14249 increment_matrix_positions (w
->current_matrix
,
14250 MATRIX_ROW_VPOS (r0
, current_matrix
),
14251 MATRIX_ROW_VPOS (r1
, current_matrix
),
14252 delta
, delta_bytes
);
14255 /* Set the cursor. */
14256 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14258 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14265 /* Handle the case that changes are all below what is displayed in
14266 the window, and that PT is in the window. This shortcut cannot
14267 be taken if ZV is visible in the window, and text has been added
14268 there that is visible in the window. */
14269 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14270 /* ZV is not visible in the window, or there are no
14271 changes at ZV, actually. */
14272 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14273 || first_changed_charpos
== last_changed_charpos
))
14275 struct glyph_row
*r0
;
14277 /* Give up if PT is not in the window. Note that it already has
14278 been checked at the start of try_window_id that PT is not in
14279 front of the window start. */
14280 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14283 /* If window start is unchanged, we can reuse the whole matrix
14284 as is, without changing glyph positions since no text has
14285 been added/removed in front of the window end. */
14286 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14287 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14288 /* PT must not be in a partially visible line. */
14289 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14290 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14292 /* We have to compute the window end anew since text
14293 can have been added/removed after it. */
14295 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14296 w
->window_end_bytepos
14297 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14299 /* Set the cursor. */
14300 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14302 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14309 /* Give up if window start is in the changed area.
14311 The condition used to read
14313 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14315 but why that was tested escapes me at the moment. */
14316 if (CHARPOS (start
) >= first_changed_charpos
14317 && CHARPOS (start
) <= last_changed_charpos
)
14320 /* Check that window start agrees with the start of the first glyph
14321 row in its current matrix. Check this after we know the window
14322 start is not in changed text, otherwise positions would not be
14324 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14325 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14328 /* Give up if the window ends in strings. Overlay strings
14329 at the end are difficult to handle, so don't try. */
14330 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14331 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14334 /* Compute the position at which we have to start displaying new
14335 lines. Some of the lines at the top of the window might be
14336 reusable because they are not displaying changed text. Find the
14337 last row in W's current matrix not affected by changes at the
14338 start of current_buffer. Value is null if changes start in the
14339 first line of window. */
14340 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14341 if (last_unchanged_at_beg_row
)
14343 /* Avoid starting to display in the moddle of a character, a TAB
14344 for instance. This is easier than to set up the iterator
14345 exactly, and it's not a frequent case, so the additional
14346 effort wouldn't really pay off. */
14347 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14348 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14349 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14350 --last_unchanged_at_beg_row
;
14352 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14355 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14357 start_pos
= it
.current
.pos
;
14359 /* Start displaying new lines in the desired matrix at the same
14360 vpos we would use in the current matrix, i.e. below
14361 last_unchanged_at_beg_row. */
14362 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14364 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14365 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14367 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14371 /* There are no reusable lines at the start of the window.
14372 Start displaying in the first text line. */
14373 start_display (&it
, w
, start
);
14374 it
.vpos
= it
.first_vpos
;
14375 start_pos
= it
.current
.pos
;
14378 /* Find the first row that is not affected by changes at the end of
14379 the buffer. Value will be null if there is no unchanged row, in
14380 which case we must redisplay to the end of the window. delta
14381 will be set to the value by which buffer positions beginning with
14382 first_unchanged_at_end_row have to be adjusted due to text
14384 first_unchanged_at_end_row
14385 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14386 IF_DEBUG (debug_delta
= delta
);
14387 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14389 /* Set stop_pos to the buffer position up to which we will have to
14390 display new lines. If first_unchanged_at_end_row != NULL, this
14391 is the buffer position of the start of the line displayed in that
14392 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14393 that we don't stop at a buffer position. */
14395 if (first_unchanged_at_end_row
)
14397 xassert (last_unchanged_at_beg_row
== NULL
14398 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14400 /* If this is a continuation line, move forward to the next one
14401 that isn't. Changes in lines above affect this line.
14402 Caution: this may move first_unchanged_at_end_row to a row
14403 not displaying text. */
14404 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14405 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14406 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14407 < it
.last_visible_y
))
14408 ++first_unchanged_at_end_row
;
14410 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14411 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14412 >= it
.last_visible_y
))
14413 first_unchanged_at_end_row
= NULL
;
14416 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14418 first_unchanged_at_end_vpos
14419 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14420 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14423 else if (last_unchanged_at_beg_row
== NULL
)
14429 /* Either there is no unchanged row at the end, or the one we have
14430 now displays text. This is a necessary condition for the window
14431 end pos calculation at the end of this function. */
14432 xassert (first_unchanged_at_end_row
== NULL
14433 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14435 debug_last_unchanged_at_beg_vpos
14436 = (last_unchanged_at_beg_row
14437 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14439 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14441 #endif /* GLYPH_DEBUG != 0 */
14444 /* Display new lines. Set last_text_row to the last new line
14445 displayed which has text on it, i.e. might end up as being the
14446 line where the window_end_vpos is. */
14447 w
->cursor
.vpos
= -1;
14448 last_text_row
= NULL
;
14449 overlay_arrow_seen
= 0;
14450 while (it
.current_y
< it
.last_visible_y
14451 && !fonts_changed_p
14452 && (first_unchanged_at_end_row
== NULL
14453 || IT_CHARPOS (it
) < stop_pos
))
14455 if (display_line (&it
))
14456 last_text_row
= it
.glyph_row
- 1;
14459 if (fonts_changed_p
)
14463 /* Compute differences in buffer positions, y-positions etc. for
14464 lines reused at the bottom of the window. Compute what we can
14466 if (first_unchanged_at_end_row
14467 /* No lines reused because we displayed everything up to the
14468 bottom of the window. */
14469 && it
.current_y
< it
.last_visible_y
)
14472 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14474 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14475 run
.current_y
= first_unchanged_at_end_row
->y
;
14476 run
.desired_y
= run
.current_y
+ dy
;
14477 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14481 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14482 first_unchanged_at_end_row
= NULL
;
14484 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14487 /* Find the cursor if not already found. We have to decide whether
14488 PT will appear on this window (it sometimes doesn't, but this is
14489 not a very frequent case.) This decision has to be made before
14490 the current matrix is altered. A value of cursor.vpos < 0 means
14491 that PT is either in one of the lines beginning at
14492 first_unchanged_at_end_row or below the window. Don't care for
14493 lines that might be displayed later at the window end; as
14494 mentioned, this is not a frequent case. */
14495 if (w
->cursor
.vpos
< 0)
14497 /* Cursor in unchanged rows at the top? */
14498 if (PT
< CHARPOS (start_pos
)
14499 && last_unchanged_at_beg_row
)
14501 row
= row_containing_pos (w
, PT
,
14502 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14503 last_unchanged_at_beg_row
+ 1, 0);
14505 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14508 /* Start from first_unchanged_at_end_row looking for PT. */
14509 else if (first_unchanged_at_end_row
)
14511 row
= row_containing_pos (w
, PT
- delta
,
14512 first_unchanged_at_end_row
, NULL
, 0);
14514 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14515 delta_bytes
, dy
, dvpos
);
14518 /* Give up if cursor was not found. */
14519 if (w
->cursor
.vpos
< 0)
14521 clear_glyph_matrix (w
->desired_matrix
);
14526 /* Don't let the cursor end in the scroll margins. */
14528 int this_scroll_margin
, cursor_height
;
14530 this_scroll_margin
= max (0, scroll_margin
);
14531 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14532 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14533 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14535 if ((w
->cursor
.y
< this_scroll_margin
14536 && CHARPOS (start
) > BEGV
)
14537 /* Old redisplay didn't take scroll margin into account at the bottom,
14538 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14539 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14540 ? cursor_height
+ this_scroll_margin
14541 : 1)) > it
.last_visible_y
)
14543 w
->cursor
.vpos
= -1;
14544 clear_glyph_matrix (w
->desired_matrix
);
14549 /* Scroll the display. Do it before changing the current matrix so
14550 that xterm.c doesn't get confused about where the cursor glyph is
14552 if (dy
&& run
.height
)
14556 if (FRAME_WINDOW_P (f
))
14558 rif
->update_window_begin_hook (w
);
14559 rif
->clear_window_mouse_face (w
);
14560 rif
->scroll_run_hook (w
, &run
);
14561 rif
->update_window_end_hook (w
, 0, 0);
14565 /* Terminal frame. In this case, dvpos gives the number of
14566 lines to scroll by; dvpos < 0 means scroll up. */
14567 int first_unchanged_at_end_vpos
14568 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14569 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14570 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14571 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14572 + window_internal_height (w
));
14574 /* Perform the operation on the screen. */
14577 /* Scroll last_unchanged_at_beg_row to the end of the
14578 window down dvpos lines. */
14579 set_terminal_window (end
);
14581 /* On dumb terminals delete dvpos lines at the end
14582 before inserting dvpos empty lines. */
14583 if (!scroll_region_ok
)
14584 ins_del_lines (end
- dvpos
, -dvpos
);
14586 /* Insert dvpos empty lines in front of
14587 last_unchanged_at_beg_row. */
14588 ins_del_lines (from
, dvpos
);
14590 else if (dvpos
< 0)
14592 /* Scroll up last_unchanged_at_beg_vpos to the end of
14593 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14594 set_terminal_window (end
);
14596 /* Delete dvpos lines in front of
14597 last_unchanged_at_beg_vpos. ins_del_lines will set
14598 the cursor to the given vpos and emit |dvpos| delete
14600 ins_del_lines (from
+ dvpos
, dvpos
);
14602 /* On a dumb terminal insert dvpos empty lines at the
14604 if (!scroll_region_ok
)
14605 ins_del_lines (end
+ dvpos
, -dvpos
);
14608 set_terminal_window (0);
14614 /* Shift reused rows of the current matrix to the right position.
14615 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14617 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14618 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14621 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14622 bottom_vpos
, dvpos
);
14623 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14626 else if (dvpos
> 0)
14628 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14629 bottom_vpos
, dvpos
);
14630 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14631 first_unchanged_at_end_vpos
+ dvpos
, 0);
14634 /* For frame-based redisplay, make sure that current frame and window
14635 matrix are in sync with respect to glyph memory. */
14636 if (!FRAME_WINDOW_P (f
))
14637 sync_frame_with_window_matrix_rows (w
);
14639 /* Adjust buffer positions in reused rows. */
14641 increment_matrix_positions (current_matrix
,
14642 first_unchanged_at_end_vpos
+ dvpos
,
14643 bottom_vpos
, delta
, delta_bytes
);
14645 /* Adjust Y positions. */
14647 shift_glyph_matrix (w
, current_matrix
,
14648 first_unchanged_at_end_vpos
+ dvpos
,
14651 if (first_unchanged_at_end_row
)
14653 first_unchanged_at_end_row
+= dvpos
;
14654 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14655 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14656 first_unchanged_at_end_row
= NULL
;
14659 /* If scrolling up, there may be some lines to display at the end of
14661 last_text_row_at_end
= NULL
;
14664 /* Scrolling up can leave for example a partially visible line
14665 at the end of the window to be redisplayed. */
14666 /* Set last_row to the glyph row in the current matrix where the
14667 window end line is found. It has been moved up or down in
14668 the matrix by dvpos. */
14669 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14670 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14672 /* If last_row is the window end line, it should display text. */
14673 xassert (last_row
->displays_text_p
);
14675 /* If window end line was partially visible before, begin
14676 displaying at that line. Otherwise begin displaying with the
14677 line following it. */
14678 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14680 init_to_row_start (&it
, w
, last_row
);
14681 it
.vpos
= last_vpos
;
14682 it
.current_y
= last_row
->y
;
14686 init_to_row_end (&it
, w
, last_row
);
14687 it
.vpos
= 1 + last_vpos
;
14688 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14692 /* We may start in a continuation line. If so, we have to
14693 get the right continuation_lines_width and current_x. */
14694 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14695 it
.hpos
= it
.current_x
= 0;
14697 /* Display the rest of the lines at the window end. */
14698 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14699 while (it
.current_y
< it
.last_visible_y
14700 && !fonts_changed_p
)
14702 /* Is it always sure that the display agrees with lines in
14703 the current matrix? I don't think so, so we mark rows
14704 displayed invalid in the current matrix by setting their
14705 enabled_p flag to zero. */
14706 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14707 if (display_line (&it
))
14708 last_text_row_at_end
= it
.glyph_row
- 1;
14712 /* Update window_end_pos and window_end_vpos. */
14713 if (first_unchanged_at_end_row
14714 && !last_text_row_at_end
)
14716 /* Window end line if one of the preserved rows from the current
14717 matrix. Set row to the last row displaying text in current
14718 matrix starting at first_unchanged_at_end_row, after
14720 xassert (first_unchanged_at_end_row
->displays_text_p
);
14721 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14722 first_unchanged_at_end_row
);
14723 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14725 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14726 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14728 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14729 xassert (w
->window_end_bytepos
>= 0);
14730 IF_DEBUG (debug_method_add (w
, "A"));
14732 else if (last_text_row_at_end
)
14735 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14736 w
->window_end_bytepos
14737 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14739 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14740 xassert (w
->window_end_bytepos
>= 0);
14741 IF_DEBUG (debug_method_add (w
, "B"));
14743 else if (last_text_row
)
14745 /* We have displayed either to the end of the window or at the
14746 end of the window, i.e. the last row with text is to be found
14747 in the desired matrix. */
14749 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14750 w
->window_end_bytepos
14751 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14753 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14754 xassert (w
->window_end_bytepos
>= 0);
14756 else if (first_unchanged_at_end_row
== NULL
14757 && last_text_row
== NULL
14758 && last_text_row_at_end
== NULL
)
14760 /* Displayed to end of window, but no line containing text was
14761 displayed. Lines were deleted at the end of the window. */
14762 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14763 int vpos
= XFASTINT (w
->window_end_vpos
);
14764 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14765 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14768 row
== NULL
&& vpos
>= first_vpos
;
14769 --vpos
, --current_row
, --desired_row
)
14771 if (desired_row
->enabled_p
)
14773 if (desired_row
->displays_text_p
)
14776 else if (current_row
->displays_text_p
)
14780 xassert (row
!= NULL
);
14781 w
->window_end_vpos
= make_number (vpos
+ 1);
14782 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14783 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14784 xassert (w
->window_end_bytepos
>= 0);
14785 IF_DEBUG (debug_method_add (w
, "C"));
14790 #if 0 /* This leads to problems, for instance when the cursor is
14791 at ZV, and the cursor line displays no text. */
14792 /* Disable rows below what's displayed in the window. This makes
14793 debugging easier. */
14794 enable_glyph_matrix_rows (current_matrix
,
14795 XFASTINT (w
->window_end_vpos
) + 1,
14799 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14800 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14802 /* Record that display has not been completed. */
14803 w
->window_end_valid
= Qnil
;
14804 w
->desired_matrix
->no_scrolling_p
= 1;
14812 /***********************************************************************
14813 More debugging support
14814 ***********************************************************************/
14818 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14819 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14820 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14823 /* Dump the contents of glyph matrix MATRIX on stderr.
14825 GLYPHS 0 means don't show glyph contents.
14826 GLYPHS 1 means show glyphs in short form
14827 GLYPHS > 1 means show glyphs in long form. */
14830 dump_glyph_matrix (matrix
, glyphs
)
14831 struct glyph_matrix
*matrix
;
14835 for (i
= 0; i
< matrix
->nrows
; ++i
)
14836 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14840 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14841 the glyph row and area where the glyph comes from. */
14844 dump_glyph (row
, glyph
, area
)
14845 struct glyph_row
*row
;
14846 struct glyph
*glyph
;
14849 if (glyph
->type
== CHAR_GLYPH
)
14852 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14853 glyph
- row
->glyphs
[TEXT_AREA
],
14856 (BUFFERP (glyph
->object
)
14858 : (STRINGP (glyph
->object
)
14861 glyph
->pixel_width
,
14863 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14867 glyph
->left_box_line_p
,
14868 glyph
->right_box_line_p
);
14870 else if (glyph
->type
== STRETCH_GLYPH
)
14873 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14874 glyph
- row
->glyphs
[TEXT_AREA
],
14877 (BUFFERP (glyph
->object
)
14879 : (STRINGP (glyph
->object
)
14882 glyph
->pixel_width
,
14886 glyph
->left_box_line_p
,
14887 glyph
->right_box_line_p
);
14889 else if (glyph
->type
== IMAGE_GLYPH
)
14892 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14893 glyph
- row
->glyphs
[TEXT_AREA
],
14896 (BUFFERP (glyph
->object
)
14898 : (STRINGP (glyph
->object
)
14901 glyph
->pixel_width
,
14905 glyph
->left_box_line_p
,
14906 glyph
->right_box_line_p
);
14911 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14912 GLYPHS 0 means don't show glyph contents.
14913 GLYPHS 1 means show glyphs in short form
14914 GLYPHS > 1 means show glyphs in long form. */
14917 dump_glyph_row (row
, vpos
, glyphs
)
14918 struct glyph_row
*row
;
14923 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
14924 fprintf (stderr
, "======================================================================\n");
14926 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14927 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14929 MATRIX_ROW_START_CHARPOS (row
),
14930 MATRIX_ROW_END_CHARPOS (row
),
14931 row
->used
[TEXT_AREA
],
14932 row
->contains_overlapping_glyphs_p
,
14934 row
->truncated_on_left_p
,
14935 row
->truncated_on_right_p
,
14937 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14938 row
->displays_text_p
,
14941 row
->ends_in_middle_of_char_p
,
14942 row
->starts_in_middle_of_char_p
,
14948 row
->visible_height
,
14951 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14952 row
->end
.overlay_string_index
,
14953 row
->continuation_lines_width
);
14954 fprintf (stderr
, "%9d %5d\n",
14955 CHARPOS (row
->start
.string_pos
),
14956 CHARPOS (row
->end
.string_pos
));
14957 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14958 row
->end
.dpvec_index
);
14965 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14967 struct glyph
*glyph
= row
->glyphs
[area
];
14968 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14970 /* Glyph for a line end in text. */
14971 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14974 if (glyph
< glyph_end
)
14975 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14977 for (; glyph
< glyph_end
; ++glyph
)
14978 dump_glyph (row
, glyph
, area
);
14981 else if (glyphs
== 1)
14985 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14987 char *s
= (char *) alloca (row
->used
[area
] + 1);
14990 for (i
= 0; i
< row
->used
[area
]; ++i
)
14992 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14993 if (glyph
->type
== CHAR_GLYPH
14994 && glyph
->u
.ch
< 0x80
14995 && glyph
->u
.ch
>= ' ')
14996 s
[i
] = glyph
->u
.ch
;
15002 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15008 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15009 Sdump_glyph_matrix
, 0, 1, "p",
15010 doc
: /* Dump the current matrix of the selected window to stderr.
15011 Shows contents of glyph row structures. With non-nil
15012 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15013 glyphs in short form, otherwise show glyphs in long form. */)
15015 Lisp_Object glyphs
;
15017 struct window
*w
= XWINDOW (selected_window
);
15018 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15020 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15021 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15022 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15023 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15024 fprintf (stderr
, "=============================================\n");
15025 dump_glyph_matrix (w
->current_matrix
,
15026 NILP (glyphs
) ? 0 : XINT (glyphs
));
15031 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15032 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15035 struct frame
*f
= XFRAME (selected_frame
);
15036 dump_glyph_matrix (f
->current_matrix
, 1);
15041 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15042 doc
: /* Dump glyph row ROW to stderr.
15043 GLYPH 0 means don't dump glyphs.
15044 GLYPH 1 means dump glyphs in short form.
15045 GLYPH > 1 or omitted means dump glyphs in long form. */)
15047 Lisp_Object row
, glyphs
;
15049 struct glyph_matrix
*matrix
;
15052 CHECK_NUMBER (row
);
15053 matrix
= XWINDOW (selected_window
)->current_matrix
;
15055 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15056 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15058 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15063 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15064 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15065 GLYPH 0 means don't dump glyphs.
15066 GLYPH 1 means dump glyphs in short form.
15067 GLYPH > 1 or omitted means dump glyphs in long form. */)
15069 Lisp_Object row
, glyphs
;
15071 struct frame
*sf
= SELECTED_FRAME ();
15072 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15075 CHECK_NUMBER (row
);
15077 if (vpos
>= 0 && vpos
< m
->nrows
)
15078 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15079 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15084 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15085 doc
: /* Toggle tracing of redisplay.
15086 With ARG, turn tracing on if and only if ARG is positive. */)
15091 trace_redisplay_p
= !trace_redisplay_p
;
15094 arg
= Fprefix_numeric_value (arg
);
15095 trace_redisplay_p
= XINT (arg
) > 0;
15102 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15103 doc
: /* Like `format', but print result to stderr.
15104 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15109 Lisp_Object s
= Fformat (nargs
, args
);
15110 fprintf (stderr
, "%s", SDATA (s
));
15114 #endif /* GLYPH_DEBUG */
15118 /***********************************************************************
15119 Building Desired Matrix Rows
15120 ***********************************************************************/
15122 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15123 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15125 static struct glyph_row
*
15126 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15128 Lisp_Object overlay_arrow_string
;
15130 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15131 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15132 struct buffer
*old
= current_buffer
;
15133 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15134 int arrow_len
= SCHARS (overlay_arrow_string
);
15135 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15136 const unsigned char *p
;
15139 int n_glyphs_before
;
15141 set_buffer_temp (buffer
);
15142 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15143 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15144 SET_TEXT_POS (it
.position
, 0, 0);
15146 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15148 while (p
< arrow_end
)
15150 Lisp_Object face
, ilisp
;
15152 /* Get the next character. */
15154 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15156 it
.c
= *p
, it
.len
= 1;
15159 /* Get its face. */
15160 ilisp
= make_number (p
- arrow_string
);
15161 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15162 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15164 /* Compute its width, get its glyphs. */
15165 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15166 SET_TEXT_POS (it
.position
, -1, -1);
15167 PRODUCE_GLYPHS (&it
);
15169 /* If this character doesn't fit any more in the line, we have
15170 to remove some glyphs. */
15171 if (it
.current_x
> it
.last_visible_x
)
15173 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15178 set_buffer_temp (old
);
15179 return it
.glyph_row
;
15183 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15184 glyphs are only inserted for terminal frames since we can't really
15185 win with truncation glyphs when partially visible glyphs are
15186 involved. Which glyphs to insert is determined by
15187 produce_special_glyphs. */
15190 insert_left_trunc_glyphs (it
)
15193 struct it truncate_it
;
15194 struct glyph
*from
, *end
, *to
, *toend
;
15196 xassert (!FRAME_WINDOW_P (it
->f
));
15198 /* Get the truncation glyphs. */
15200 truncate_it
.current_x
= 0;
15201 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15202 truncate_it
.glyph_row
= &scratch_glyph_row
;
15203 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15204 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15205 truncate_it
.object
= make_number (0);
15206 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15208 /* Overwrite glyphs from IT with truncation glyphs. */
15209 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15210 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15211 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15212 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15217 /* There may be padding glyphs left over. Overwrite them too. */
15218 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15220 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15226 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15230 /* Compute the pixel height and width of IT->glyph_row.
15232 Most of the time, ascent and height of a display line will be equal
15233 to the max_ascent and max_height values of the display iterator
15234 structure. This is not the case if
15236 1. We hit ZV without displaying anything. In this case, max_ascent
15237 and max_height will be zero.
15239 2. We have some glyphs that don't contribute to the line height.
15240 (The glyph row flag contributes_to_line_height_p is for future
15241 pixmap extensions).
15243 The first case is easily covered by using default values because in
15244 these cases, the line height does not really matter, except that it
15245 must not be zero. */
15248 compute_line_metrics (it
)
15251 struct glyph_row
*row
= it
->glyph_row
;
15254 if (FRAME_WINDOW_P (it
->f
))
15256 int i
, min_y
, max_y
;
15258 /* The line may consist of one space only, that was added to
15259 place the cursor on it. If so, the row's height hasn't been
15261 if (row
->height
== 0)
15263 if (it
->max_ascent
+ it
->max_descent
== 0)
15264 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15265 row
->ascent
= it
->max_ascent
;
15266 row
->height
= it
->max_ascent
+ it
->max_descent
;
15267 row
->phys_ascent
= it
->max_phys_ascent
;
15268 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15269 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15272 /* Compute the width of this line. */
15273 row
->pixel_width
= row
->x
;
15274 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15275 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15277 xassert (row
->pixel_width
>= 0);
15278 xassert (row
->ascent
>= 0 && row
->height
> 0);
15280 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15281 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15283 /* If first line's physical ascent is larger than its logical
15284 ascent, use the physical ascent, and make the row taller.
15285 This makes accented characters fully visible. */
15286 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15287 && row
->phys_ascent
> row
->ascent
)
15289 row
->height
+= row
->phys_ascent
- row
->ascent
;
15290 row
->ascent
= row
->phys_ascent
;
15293 /* Compute how much of the line is visible. */
15294 row
->visible_height
= row
->height
;
15296 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15297 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15299 if (row
->y
< min_y
)
15300 row
->visible_height
-= min_y
- row
->y
;
15301 if (row
->y
+ row
->height
> max_y
)
15302 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15306 row
->pixel_width
= row
->used
[TEXT_AREA
];
15307 if (row
->continued_p
)
15308 row
->pixel_width
-= it
->continuation_pixel_width
;
15309 else if (row
->truncated_on_right_p
)
15310 row
->pixel_width
-= it
->truncation_pixel_width
;
15311 row
->ascent
= row
->phys_ascent
= 0;
15312 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15313 row
->extra_line_spacing
= 0;
15316 /* Compute a hash code for this row. */
15318 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15319 for (i
= 0; i
< row
->used
[area
]; ++i
)
15320 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15321 + row
->glyphs
[area
][i
].u
.val
15322 + row
->glyphs
[area
][i
].face_id
15323 + row
->glyphs
[area
][i
].padding_p
15324 + (row
->glyphs
[area
][i
].type
<< 2));
15326 it
->max_ascent
= it
->max_descent
= 0;
15327 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15331 /* Append one space to the glyph row of iterator IT if doing a
15332 window-based redisplay. The space has the same face as
15333 IT->face_id. Value is non-zero if a space was added.
15335 This function is called to make sure that there is always one glyph
15336 at the end of a glyph row that the cursor can be set on under
15337 window-systems. (If there weren't such a glyph we would not know
15338 how wide and tall a box cursor should be displayed).
15340 At the same time this space let's a nicely handle clearing to the
15341 end of the line if the row ends in italic text. */
15344 append_space_for_newline (it
, default_face_p
)
15346 int default_face_p
;
15348 if (FRAME_WINDOW_P (it
->f
))
15350 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15352 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15353 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15355 /* Save some values that must not be changed.
15356 Must save IT->c and IT->len because otherwise
15357 ITERATOR_AT_END_P wouldn't work anymore after
15358 append_space_for_newline has been called. */
15359 enum display_element_type saved_what
= it
->what
;
15360 int saved_c
= it
->c
, saved_len
= it
->len
;
15361 int saved_x
= it
->current_x
;
15362 int saved_face_id
= it
->face_id
;
15363 struct text_pos saved_pos
;
15364 Lisp_Object saved_object
;
15367 saved_object
= it
->object
;
15368 saved_pos
= it
->position
;
15370 it
->what
= IT_CHARACTER
;
15371 bzero (&it
->position
, sizeof it
->position
);
15372 it
->object
= make_number (0);
15376 if (default_face_p
)
15377 it
->face_id
= DEFAULT_FACE_ID
;
15378 else if (it
->face_before_selective_p
)
15379 it
->face_id
= it
->saved_face_id
;
15380 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15381 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15383 PRODUCE_GLYPHS (it
);
15385 it
->override_ascent
= -1;
15386 it
->constrain_row_ascent_descent_p
= 0;
15387 it
->current_x
= saved_x
;
15388 it
->object
= saved_object
;
15389 it
->position
= saved_pos
;
15390 it
->what
= saved_what
;
15391 it
->face_id
= saved_face_id
;
15392 it
->len
= saved_len
;
15402 /* Extend the face of the last glyph in the text area of IT->glyph_row
15403 to the end of the display line. Called from display_line.
15404 If the glyph row is empty, add a space glyph to it so that we
15405 know the face to draw. Set the glyph row flag fill_line_p. */
15408 extend_face_to_end_of_line (it
)
15412 struct frame
*f
= it
->f
;
15414 /* If line is already filled, do nothing. */
15415 if (it
->current_x
>= it
->last_visible_x
)
15418 /* Face extension extends the background and box of IT->face_id
15419 to the end of the line. If the background equals the background
15420 of the frame, we don't have to do anything. */
15421 if (it
->face_before_selective_p
)
15422 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15424 face
= FACE_FROM_ID (f
, it
->face_id
);
15426 if (FRAME_WINDOW_P (f
)
15427 && it
->glyph_row
->displays_text_p
15428 && face
->box
== FACE_NO_BOX
15429 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15433 /* Set the glyph row flag indicating that the face of the last glyph
15434 in the text area has to be drawn to the end of the text area. */
15435 it
->glyph_row
->fill_line_p
= 1;
15437 /* If current character of IT is not ASCII, make sure we have the
15438 ASCII face. This will be automatically undone the next time
15439 get_next_display_element returns a multibyte character. Note
15440 that the character will always be single byte in unibyte text. */
15441 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15443 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15446 if (FRAME_WINDOW_P (f
))
15448 /* If the row is empty, add a space with the current face of IT,
15449 so that we know which face to draw. */
15450 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15452 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15453 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15454 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15459 /* Save some values that must not be changed. */
15460 int saved_x
= it
->current_x
;
15461 struct text_pos saved_pos
;
15462 Lisp_Object saved_object
;
15463 enum display_element_type saved_what
= it
->what
;
15464 int saved_face_id
= it
->face_id
;
15466 saved_object
= it
->object
;
15467 saved_pos
= it
->position
;
15469 it
->what
= IT_CHARACTER
;
15470 bzero (&it
->position
, sizeof it
->position
);
15471 it
->object
= make_number (0);
15474 it
->face_id
= face
->id
;
15476 PRODUCE_GLYPHS (it
);
15478 while (it
->current_x
<= it
->last_visible_x
)
15479 PRODUCE_GLYPHS (it
);
15481 /* Don't count these blanks really. It would let us insert a left
15482 truncation glyph below and make us set the cursor on them, maybe. */
15483 it
->current_x
= saved_x
;
15484 it
->object
= saved_object
;
15485 it
->position
= saved_pos
;
15486 it
->what
= saved_what
;
15487 it
->face_id
= saved_face_id
;
15492 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15493 trailing whitespace. */
15496 trailing_whitespace_p (charpos
)
15499 int bytepos
= CHAR_TO_BYTE (charpos
);
15502 while (bytepos
< ZV_BYTE
15503 && (c
= FETCH_CHAR (bytepos
),
15504 c
== ' ' || c
== '\t'))
15507 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15509 if (bytepos
!= PT_BYTE
)
15516 /* Highlight trailing whitespace, if any, in ROW. */
15519 highlight_trailing_whitespace (f
, row
)
15521 struct glyph_row
*row
;
15523 int used
= row
->used
[TEXT_AREA
];
15527 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15528 struct glyph
*glyph
= start
+ used
- 1;
15530 /* Skip over glyphs inserted to display the cursor at the
15531 end of a line, for extending the face of the last glyph
15532 to the end of the line on terminals, and for truncation
15533 and continuation glyphs. */
15534 while (glyph
>= start
15535 && glyph
->type
== CHAR_GLYPH
15536 && INTEGERP (glyph
->object
))
15539 /* If last glyph is a space or stretch, and it's trailing
15540 whitespace, set the face of all trailing whitespace glyphs in
15541 IT->glyph_row to `trailing-whitespace'. */
15543 && BUFFERP (glyph
->object
)
15544 && (glyph
->type
== STRETCH_GLYPH
15545 || (glyph
->type
== CHAR_GLYPH
15546 && glyph
->u
.ch
== ' '))
15547 && trailing_whitespace_p (glyph
->charpos
))
15549 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15553 while (glyph
>= start
15554 && BUFFERP (glyph
->object
)
15555 && (glyph
->type
== STRETCH_GLYPH
15556 || (glyph
->type
== CHAR_GLYPH
15557 && glyph
->u
.ch
== ' ')))
15558 (glyph
--)->face_id
= face_id
;
15564 /* Value is non-zero if glyph row ROW in window W should be
15565 used to hold the cursor. */
15568 cursor_row_p (w
, row
)
15570 struct glyph_row
*row
;
15572 int cursor_row_p
= 1;
15574 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15576 /* If the row ends with a newline from a string, we don't want
15577 the cursor there, but we still want it at the start of the
15578 string if the string starts in this row.
15579 If the row is continued it doesn't end in a newline. */
15580 if (CHARPOS (row
->end
.string_pos
) >= 0)
15581 cursor_row_p
= (row
->continued_p
15582 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15583 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15585 /* If the row ends in middle of a real character,
15586 and the line is continued, we want the cursor here.
15587 That's because MATRIX_ROW_END_CHARPOS would equal
15588 PT if PT is before the character. */
15589 if (!row
->ends_in_ellipsis_p
)
15590 cursor_row_p
= row
->continued_p
;
15592 /* If the row ends in an ellipsis, then
15593 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15594 We want that position to be displayed after the ellipsis. */
15597 /* If the row ends at ZV, display the cursor at the end of that
15598 row instead of at the start of the row below. */
15599 else if (row
->ends_at_zv_p
)
15605 return cursor_row_p
;
15609 /* Construct the glyph row IT->glyph_row in the desired matrix of
15610 IT->w from text at the current position of IT. See dispextern.h
15611 for an overview of struct it. Value is non-zero if
15612 IT->glyph_row displays text, as opposed to a line displaying ZV
15619 struct glyph_row
*row
= it
->glyph_row
;
15620 Lisp_Object overlay_arrow_string
;
15622 /* We always start displaying at hpos zero even if hscrolled. */
15623 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15625 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15626 >= it
->w
->desired_matrix
->nrows
)
15628 it
->w
->nrows_scale_factor
++;
15629 fonts_changed_p
= 1;
15633 /* Is IT->w showing the region? */
15634 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15636 /* Clear the result glyph row and enable it. */
15637 prepare_desired_row (row
);
15639 row
->y
= it
->current_y
;
15640 row
->start
= it
->start
;
15641 row
->continuation_lines_width
= it
->continuation_lines_width
;
15642 row
->displays_text_p
= 1;
15643 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15644 it
->starts_in_middle_of_char_p
= 0;
15646 /* Arrange the overlays nicely for our purposes. Usually, we call
15647 display_line on only one line at a time, in which case this
15648 can't really hurt too much, or we call it on lines which appear
15649 one after another in the buffer, in which case all calls to
15650 recenter_overlay_lists but the first will be pretty cheap. */
15651 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15653 /* Move over display elements that are not visible because we are
15654 hscrolled. This may stop at an x-position < IT->first_visible_x
15655 if the first glyph is partially visible or if we hit a line end. */
15656 if (it
->current_x
< it
->first_visible_x
)
15658 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15659 MOVE_TO_POS
| MOVE_TO_X
);
15662 /* Get the initial row height. This is either the height of the
15663 text hscrolled, if there is any, or zero. */
15664 row
->ascent
= it
->max_ascent
;
15665 row
->height
= it
->max_ascent
+ it
->max_descent
;
15666 row
->phys_ascent
= it
->max_phys_ascent
;
15667 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15668 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15670 /* Loop generating characters. The loop is left with IT on the next
15671 character to display. */
15674 int n_glyphs_before
, hpos_before
, x_before
;
15676 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15678 /* Retrieve the next thing to display. Value is zero if end of
15680 if (!get_next_display_element (it
))
15682 /* Maybe add a space at the end of this line that is used to
15683 display the cursor there under X. Set the charpos of the
15684 first glyph of blank lines not corresponding to any text
15686 #ifdef HAVE_WINDOW_SYSTEM
15687 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15688 row
->exact_window_width_line_p
= 1;
15690 #endif /* HAVE_WINDOW_SYSTEM */
15691 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15692 || row
->used
[TEXT_AREA
] == 0)
15694 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15695 row
->displays_text_p
= 0;
15697 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15698 && (!MINI_WINDOW_P (it
->w
)
15699 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15700 row
->indicate_empty_line_p
= 1;
15703 it
->continuation_lines_width
= 0;
15704 row
->ends_at_zv_p
= 1;
15708 /* Now, get the metrics of what we want to display. This also
15709 generates glyphs in `row' (which is IT->glyph_row). */
15710 n_glyphs_before
= row
->used
[TEXT_AREA
];
15713 /* Remember the line height so far in case the next element doesn't
15714 fit on the line. */
15715 if (!it
->truncate_lines_p
)
15717 ascent
= it
->max_ascent
;
15718 descent
= it
->max_descent
;
15719 phys_ascent
= it
->max_phys_ascent
;
15720 phys_descent
= it
->max_phys_descent
;
15723 PRODUCE_GLYPHS (it
);
15725 /* If this display element was in marginal areas, continue with
15727 if (it
->area
!= TEXT_AREA
)
15729 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15730 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15731 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15732 row
->phys_height
= max (row
->phys_height
,
15733 it
->max_phys_ascent
+ it
->max_phys_descent
);
15734 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15735 it
->max_extra_line_spacing
);
15736 set_iterator_to_next (it
, 1);
15740 /* Does the display element fit on the line? If we truncate
15741 lines, we should draw past the right edge of the window. If
15742 we don't truncate, we want to stop so that we can display the
15743 continuation glyph before the right margin. If lines are
15744 continued, there are two possible strategies for characters
15745 resulting in more than 1 glyph (e.g. tabs): Display as many
15746 glyphs as possible in this line and leave the rest for the
15747 continuation line, or display the whole element in the next
15748 line. Original redisplay did the former, so we do it also. */
15749 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15750 hpos_before
= it
->hpos
;
15753 if (/* Not a newline. */
15755 /* Glyphs produced fit entirely in the line. */
15756 && it
->current_x
< it
->last_visible_x
)
15758 it
->hpos
+= nglyphs
;
15759 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15760 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15761 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15762 row
->phys_height
= max (row
->phys_height
,
15763 it
->max_phys_ascent
+ it
->max_phys_descent
);
15764 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15765 it
->max_extra_line_spacing
);
15766 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15767 row
->x
= x
- it
->first_visible_x
;
15772 struct glyph
*glyph
;
15774 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15776 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15777 new_x
= x
+ glyph
->pixel_width
;
15779 if (/* Lines are continued. */
15780 !it
->truncate_lines_p
15781 && (/* Glyph doesn't fit on the line. */
15782 new_x
> it
->last_visible_x
15783 /* Or it fits exactly on a window system frame. */
15784 || (new_x
== it
->last_visible_x
15785 && FRAME_WINDOW_P (it
->f
))))
15787 /* End of a continued line. */
15790 || (new_x
== it
->last_visible_x
15791 && FRAME_WINDOW_P (it
->f
)))
15793 /* Current glyph is the only one on the line or
15794 fits exactly on the line. We must continue
15795 the line because we can't draw the cursor
15796 after the glyph. */
15797 row
->continued_p
= 1;
15798 it
->current_x
= new_x
;
15799 it
->continuation_lines_width
+= new_x
;
15801 if (i
== nglyphs
- 1)
15803 set_iterator_to_next (it
, 1);
15804 #ifdef HAVE_WINDOW_SYSTEM
15805 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15807 if (!get_next_display_element (it
))
15809 row
->exact_window_width_line_p
= 1;
15810 it
->continuation_lines_width
= 0;
15811 row
->continued_p
= 0;
15812 row
->ends_at_zv_p
= 1;
15814 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15816 row
->continued_p
= 0;
15817 row
->exact_window_width_line_p
= 1;
15820 #endif /* HAVE_WINDOW_SYSTEM */
15823 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15824 && !FRAME_WINDOW_P (it
->f
))
15826 /* A padding glyph that doesn't fit on this line.
15827 This means the whole character doesn't fit
15829 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15831 /* Fill the rest of the row with continuation
15832 glyphs like in 20.x. */
15833 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15834 < row
->glyphs
[1 + TEXT_AREA
])
15835 produce_special_glyphs (it
, IT_CONTINUATION
);
15837 row
->continued_p
= 1;
15838 it
->current_x
= x_before
;
15839 it
->continuation_lines_width
+= x_before
;
15841 /* Restore the height to what it was before the
15842 element not fitting on the line. */
15843 it
->max_ascent
= ascent
;
15844 it
->max_descent
= descent
;
15845 it
->max_phys_ascent
= phys_ascent
;
15846 it
->max_phys_descent
= phys_descent
;
15848 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15850 /* A TAB that extends past the right edge of the
15851 window. This produces a single glyph on
15852 window system frames. We leave the glyph in
15853 this row and let it fill the row, but don't
15854 consume the TAB. */
15855 it
->continuation_lines_width
+= it
->last_visible_x
;
15856 row
->ends_in_middle_of_char_p
= 1;
15857 row
->continued_p
= 1;
15858 glyph
->pixel_width
= it
->last_visible_x
- x
;
15859 it
->starts_in_middle_of_char_p
= 1;
15863 /* Something other than a TAB that draws past
15864 the right edge of the window. Restore
15865 positions to values before the element. */
15866 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15868 /* Display continuation glyphs. */
15869 if (!FRAME_WINDOW_P (it
->f
))
15870 produce_special_glyphs (it
, IT_CONTINUATION
);
15871 row
->continued_p
= 1;
15873 it
->current_x
= x_before
;
15874 it
->continuation_lines_width
+= x
;
15875 extend_face_to_end_of_line (it
);
15877 if (nglyphs
> 1 && i
> 0)
15879 row
->ends_in_middle_of_char_p
= 1;
15880 it
->starts_in_middle_of_char_p
= 1;
15883 /* Restore the height to what it was before the
15884 element not fitting on the line. */
15885 it
->max_ascent
= ascent
;
15886 it
->max_descent
= descent
;
15887 it
->max_phys_ascent
= phys_ascent
;
15888 it
->max_phys_descent
= phys_descent
;
15893 else if (new_x
> it
->first_visible_x
)
15895 /* Increment number of glyphs actually displayed. */
15898 if (x
< it
->first_visible_x
)
15899 /* Glyph is partially visible, i.e. row starts at
15900 negative X position. */
15901 row
->x
= x
- it
->first_visible_x
;
15905 /* Glyph is completely off the left margin of the
15906 window. This should not happen because of the
15907 move_it_in_display_line at the start of this
15908 function, unless the text display area of the
15909 window is empty. */
15910 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15914 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15915 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15916 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15917 row
->phys_height
= max (row
->phys_height
,
15918 it
->max_phys_ascent
+ it
->max_phys_descent
);
15919 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15920 it
->max_extra_line_spacing
);
15922 /* End of this display line if row is continued. */
15923 if (row
->continued_p
|| row
->ends_at_zv_p
)
15928 /* Is this a line end? If yes, we're also done, after making
15929 sure that a non-default face is extended up to the right
15930 margin of the window. */
15931 if (ITERATOR_AT_END_OF_LINE_P (it
))
15933 int used_before
= row
->used
[TEXT_AREA
];
15935 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15937 #ifdef HAVE_WINDOW_SYSTEM
15938 /* Add a space at the end of the line that is used to
15939 display the cursor there. */
15940 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15941 append_space_for_newline (it
, 0);
15942 #endif /* HAVE_WINDOW_SYSTEM */
15944 /* Extend the face to the end of the line. */
15945 extend_face_to_end_of_line (it
);
15947 /* Make sure we have the position. */
15948 if (used_before
== 0)
15949 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15951 /* Consume the line end. This skips over invisible lines. */
15952 set_iterator_to_next (it
, 1);
15953 it
->continuation_lines_width
= 0;
15957 /* Proceed with next display element. Note that this skips
15958 over lines invisible because of selective display. */
15959 set_iterator_to_next (it
, 1);
15961 /* If we truncate lines, we are done when the last displayed
15962 glyphs reach past the right margin of the window. */
15963 if (it
->truncate_lines_p
15964 && (FRAME_WINDOW_P (it
->f
)
15965 ? (it
->current_x
>= it
->last_visible_x
)
15966 : (it
->current_x
> it
->last_visible_x
)))
15968 /* Maybe add truncation glyphs. */
15969 if (!FRAME_WINDOW_P (it
->f
))
15973 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15974 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15977 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15979 row
->used
[TEXT_AREA
] = i
;
15980 produce_special_glyphs (it
, IT_TRUNCATION
);
15983 #ifdef HAVE_WINDOW_SYSTEM
15986 /* Don't truncate if we can overflow newline into fringe. */
15987 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15989 if (!get_next_display_element (it
))
15991 it
->continuation_lines_width
= 0;
15992 row
->ends_at_zv_p
= 1;
15993 row
->exact_window_width_line_p
= 1;
15996 if (ITERATOR_AT_END_OF_LINE_P (it
))
15998 row
->exact_window_width_line_p
= 1;
15999 goto at_end_of_line
;
16003 #endif /* HAVE_WINDOW_SYSTEM */
16005 row
->truncated_on_right_p
= 1;
16006 it
->continuation_lines_width
= 0;
16007 reseat_at_next_visible_line_start (it
, 0);
16008 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16009 it
->hpos
= hpos_before
;
16010 it
->current_x
= x_before
;
16015 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16016 at the left window margin. */
16017 if (it
->first_visible_x
16018 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16020 if (!FRAME_WINDOW_P (it
->f
))
16021 insert_left_trunc_glyphs (it
);
16022 row
->truncated_on_left_p
= 1;
16025 /* If the start of this line is the overlay arrow-position, then
16026 mark this glyph row as the one containing the overlay arrow.
16027 This is clearly a mess with variable size fonts. It would be
16028 better to let it be displayed like cursors under X. */
16029 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16030 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16031 !NILP (overlay_arrow_string
)))
16033 /* Overlay arrow in window redisplay is a fringe bitmap. */
16034 if (STRINGP (overlay_arrow_string
))
16036 struct glyph_row
*arrow_row
16037 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16038 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16039 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16040 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16041 struct glyph
*p2
, *end
;
16043 /* Copy the arrow glyphs. */
16044 while (glyph
< arrow_end
)
16047 /* Throw away padding glyphs. */
16049 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16050 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16056 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16061 xassert (INTEGERP (overlay_arrow_string
));
16062 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16064 overlay_arrow_seen
= 1;
16067 /* Compute pixel dimensions of this line. */
16068 compute_line_metrics (it
);
16070 /* Remember the position at which this line ends. */
16071 row
->end
= it
->current
;
16073 /* Record whether this row ends inside an ellipsis. */
16074 row
->ends_in_ellipsis_p
16075 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16076 && it
->ellipsis_p
);
16078 /* Save fringe bitmaps in this row. */
16079 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16080 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16081 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16082 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16084 it
->left_user_fringe_bitmap
= 0;
16085 it
->left_user_fringe_face_id
= 0;
16086 it
->right_user_fringe_bitmap
= 0;
16087 it
->right_user_fringe_face_id
= 0;
16089 /* Maybe set the cursor. */
16090 if (it
->w
->cursor
.vpos
< 0
16091 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16092 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16093 && cursor_row_p (it
->w
, row
))
16094 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16096 /* Highlight trailing whitespace. */
16097 if (!NILP (Vshow_trailing_whitespace
))
16098 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16100 /* Prepare for the next line. This line starts horizontally at (X
16101 HPOS) = (0 0). Vertical positions are incremented. As a
16102 convenience for the caller, IT->glyph_row is set to the next
16104 it
->current_x
= it
->hpos
= 0;
16105 it
->current_y
+= row
->height
;
16108 it
->start
= it
->current
;
16109 return row
->displays_text_p
;
16114 /***********************************************************************
16116 ***********************************************************************/
16118 /* Redisplay the menu bar in the frame for window W.
16120 The menu bar of X frames that don't have X toolkit support is
16121 displayed in a special window W->frame->menu_bar_window.
16123 The menu bar of terminal frames is treated specially as far as
16124 glyph matrices are concerned. Menu bar lines are not part of
16125 windows, so the update is done directly on the frame matrix rows
16126 for the menu bar. */
16129 display_menu_bar (w
)
16132 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16137 /* Don't do all this for graphical frames. */
16139 if (!NILP (Vwindow_system
))
16142 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16147 if (FRAME_MAC_P (f
))
16151 #ifdef USE_X_TOOLKIT
16152 xassert (!FRAME_WINDOW_P (f
));
16153 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16154 it
.first_visible_x
= 0;
16155 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16156 #else /* not USE_X_TOOLKIT */
16157 if (FRAME_WINDOW_P (f
))
16159 /* Menu bar lines are displayed in the desired matrix of the
16160 dummy window menu_bar_window. */
16161 struct window
*menu_w
;
16162 xassert (WINDOWP (f
->menu_bar_window
));
16163 menu_w
= XWINDOW (f
->menu_bar_window
);
16164 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16166 it
.first_visible_x
= 0;
16167 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16171 /* This is a TTY frame, i.e. character hpos/vpos are used as
16173 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16175 it
.first_visible_x
= 0;
16176 it
.last_visible_x
= FRAME_COLS (f
);
16178 #endif /* not USE_X_TOOLKIT */
16180 if (! mode_line_inverse_video
)
16181 /* Force the menu-bar to be displayed in the default face. */
16182 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16184 /* Clear all rows of the menu bar. */
16185 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16187 struct glyph_row
*row
= it
.glyph_row
+ i
;
16188 clear_glyph_row (row
);
16189 row
->enabled_p
= 1;
16190 row
->full_width_p
= 1;
16193 /* Display all items of the menu bar. */
16194 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16195 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16197 Lisp_Object string
;
16199 /* Stop at nil string. */
16200 string
= AREF (items
, i
+ 1);
16204 /* Remember where item was displayed. */
16205 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16207 /* Display the item, pad with one space. */
16208 if (it
.current_x
< it
.last_visible_x
)
16209 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16210 SCHARS (string
) + 1, 0, 0, -1);
16213 /* Fill out the line with spaces. */
16214 if (it
.current_x
< it
.last_visible_x
)
16215 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16217 /* Compute the total height of the lines. */
16218 compute_line_metrics (&it
);
16223 /***********************************************************************
16225 ***********************************************************************/
16227 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16228 FORCE is non-zero, redisplay mode lines unconditionally.
16229 Otherwise, redisplay only mode lines that are garbaged. Value is
16230 the number of windows whose mode lines were redisplayed. */
16233 redisplay_mode_lines (window
, force
)
16234 Lisp_Object window
;
16239 while (!NILP (window
))
16241 struct window
*w
= XWINDOW (window
);
16243 if (WINDOWP (w
->hchild
))
16244 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16245 else if (WINDOWP (w
->vchild
))
16246 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16248 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16249 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16251 struct text_pos lpoint
;
16252 struct buffer
*old
= current_buffer
;
16254 /* Set the window's buffer for the mode line display. */
16255 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16256 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16258 /* Point refers normally to the selected window. For any
16259 other window, set up appropriate value. */
16260 if (!EQ (window
, selected_window
))
16262 struct text_pos pt
;
16264 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16265 if (CHARPOS (pt
) < BEGV
)
16266 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16267 else if (CHARPOS (pt
) > (ZV
- 1))
16268 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16270 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16273 /* Display mode lines. */
16274 clear_glyph_matrix (w
->desired_matrix
);
16275 if (display_mode_lines (w
))
16278 w
->must_be_updated_p
= 1;
16281 /* Restore old settings. */
16282 set_buffer_internal_1 (old
);
16283 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16293 /* Display the mode and/or top line of window W. Value is the number
16294 of mode lines displayed. */
16297 display_mode_lines (w
)
16300 Lisp_Object old_selected_window
, old_selected_frame
;
16303 old_selected_frame
= selected_frame
;
16304 selected_frame
= w
->frame
;
16305 old_selected_window
= selected_window
;
16306 XSETWINDOW (selected_window
, w
);
16308 /* These will be set while the mode line specs are processed. */
16309 line_number_displayed
= 0;
16310 w
->column_number_displayed
= Qnil
;
16312 if (WINDOW_WANTS_MODELINE_P (w
))
16314 struct window
*sel_w
= XWINDOW (old_selected_window
);
16316 /* Select mode line face based on the real selected window. */
16317 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16318 current_buffer
->mode_line_format
);
16322 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16324 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16325 current_buffer
->header_line_format
);
16329 selected_frame
= old_selected_frame
;
16330 selected_window
= old_selected_window
;
16335 /* Display mode or top line of window W. FACE_ID specifies which line
16336 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16337 FORMAT is the mode line format to display. Value is the pixel
16338 height of the mode line displayed. */
16341 display_mode_line (w
, face_id
, format
)
16343 enum face_id face_id
;
16344 Lisp_Object format
;
16348 int count
= SPECPDL_INDEX ();
16350 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16351 prepare_desired_row (it
.glyph_row
);
16353 it
.glyph_row
->mode_line_p
= 1;
16355 if (! mode_line_inverse_video
)
16356 /* Force the mode-line to be displayed in the default face. */
16357 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16359 record_unwind_protect (unwind_format_mode_line
,
16360 format_mode_line_unwind_data (NULL
, 0));
16362 mode_line_target
= MODE_LINE_DISPLAY
;
16364 /* Temporarily make frame's keyboard the current kboard so that
16365 kboard-local variables in the mode_line_format will get the right
16367 push_frame_kboard (it
.f
);
16368 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16369 pop_frame_kboard ();
16371 unbind_to (count
, Qnil
);
16373 /* Fill up with spaces. */
16374 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16376 compute_line_metrics (&it
);
16377 it
.glyph_row
->full_width_p
= 1;
16378 it
.glyph_row
->continued_p
= 0;
16379 it
.glyph_row
->truncated_on_left_p
= 0;
16380 it
.glyph_row
->truncated_on_right_p
= 0;
16382 /* Make a 3D mode-line have a shadow at its right end. */
16383 face
= FACE_FROM_ID (it
.f
, face_id
);
16384 extend_face_to_end_of_line (&it
);
16385 if (face
->box
!= FACE_NO_BOX
)
16387 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16388 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16389 last
->right_box_line_p
= 1;
16392 return it
.glyph_row
->height
;
16395 /* Move element ELT in LIST to the front of LIST.
16396 Return the updated list. */
16399 move_elt_to_front (elt
, list
)
16400 Lisp_Object elt
, list
;
16402 register Lisp_Object tail
, prev
;
16403 register Lisp_Object tem
;
16407 while (CONSP (tail
))
16413 /* Splice out the link TAIL. */
16415 list
= XCDR (tail
);
16417 Fsetcdr (prev
, XCDR (tail
));
16419 /* Now make it the first. */
16420 Fsetcdr (tail
, list
);
16425 tail
= XCDR (tail
);
16429 /* Not found--return unchanged LIST. */
16433 /* Contribute ELT to the mode line for window IT->w. How it
16434 translates into text depends on its data type.
16436 IT describes the display environment in which we display, as usual.
16438 DEPTH is the depth in recursion. It is used to prevent
16439 infinite recursion here.
16441 FIELD_WIDTH is the number of characters the display of ELT should
16442 occupy in the mode line, and PRECISION is the maximum number of
16443 characters to display from ELT's representation. See
16444 display_string for details.
16446 Returns the hpos of the end of the text generated by ELT.
16448 PROPS is a property list to add to any string we encounter.
16450 If RISKY is nonzero, remove (disregard) any properties in any string
16451 we encounter, and ignore :eval and :propertize.
16453 The global variable `mode_line_target' determines whether the
16454 output is passed to `store_mode_line_noprop',
16455 `store_mode_line_string', or `display_string'. */
16458 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16461 int field_width
, precision
;
16462 Lisp_Object elt
, props
;
16465 int n
= 0, field
, prec
;
16470 elt
= build_string ("*too-deep*");
16474 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16478 /* A string: output it and check for %-constructs within it. */
16482 if (SCHARS (elt
) > 0
16483 && (!NILP (props
) || risky
))
16485 Lisp_Object oprops
, aelt
;
16486 oprops
= Ftext_properties_at (make_number (0), elt
);
16488 /* If the starting string's properties are not what
16489 we want, translate the string. Also, if the string
16490 is risky, do that anyway. */
16492 if (NILP (Fequal (props
, oprops
)) || risky
)
16494 /* If the starting string has properties,
16495 merge the specified ones onto the existing ones. */
16496 if (! NILP (oprops
) && !risky
)
16500 oprops
= Fcopy_sequence (oprops
);
16502 while (CONSP (tem
))
16504 oprops
= Fplist_put (oprops
, XCAR (tem
),
16505 XCAR (XCDR (tem
)));
16506 tem
= XCDR (XCDR (tem
));
16511 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16512 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16514 /* AELT is what we want. Move it to the front
16515 without consing. */
16517 mode_line_proptrans_alist
16518 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16524 /* If AELT has the wrong props, it is useless.
16525 so get rid of it. */
16527 mode_line_proptrans_alist
16528 = Fdelq (aelt
, mode_line_proptrans_alist
);
16530 elt
= Fcopy_sequence (elt
);
16531 Fset_text_properties (make_number (0), Flength (elt
),
16533 /* Add this item to mode_line_proptrans_alist. */
16534 mode_line_proptrans_alist
16535 = Fcons (Fcons (elt
, props
),
16536 mode_line_proptrans_alist
);
16537 /* Truncate mode_line_proptrans_alist
16538 to at most 50 elements. */
16539 tem
= Fnthcdr (make_number (50),
16540 mode_line_proptrans_alist
);
16542 XSETCDR (tem
, Qnil
);
16551 prec
= precision
- n
;
16552 switch (mode_line_target
)
16554 case MODE_LINE_NOPROP
:
16555 case MODE_LINE_TITLE
:
16556 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16558 case MODE_LINE_STRING
:
16559 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16561 case MODE_LINE_DISPLAY
:
16562 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16563 0, prec
, 0, STRING_MULTIBYTE (elt
));
16570 /* Handle the non-literal case. */
16572 while ((precision
<= 0 || n
< precision
)
16573 && SREF (elt
, offset
) != 0
16574 && (mode_line_target
!= MODE_LINE_DISPLAY
16575 || it
->current_x
< it
->last_visible_x
))
16577 int last_offset
= offset
;
16579 /* Advance to end of string or next format specifier. */
16580 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16583 if (offset
- 1 != last_offset
)
16585 int nchars
, nbytes
;
16587 /* Output to end of string or up to '%'. Field width
16588 is length of string. Don't output more than
16589 PRECISION allows us. */
16592 prec
= c_string_width (SDATA (elt
) + last_offset
,
16593 offset
- last_offset
, precision
- n
,
16596 switch (mode_line_target
)
16598 case MODE_LINE_NOPROP
:
16599 case MODE_LINE_TITLE
:
16600 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16602 case MODE_LINE_STRING
:
16604 int bytepos
= last_offset
;
16605 int charpos
= string_byte_to_char (elt
, bytepos
);
16606 int endpos
= (precision
<= 0
16607 ? string_byte_to_char (elt
, offset
)
16608 : charpos
+ nchars
);
16610 n
+= store_mode_line_string (NULL
,
16611 Fsubstring (elt
, make_number (charpos
),
16612 make_number (endpos
)),
16616 case MODE_LINE_DISPLAY
:
16618 int bytepos
= last_offset
;
16619 int charpos
= string_byte_to_char (elt
, bytepos
);
16621 if (precision
<= 0)
16622 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16623 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16625 STRING_MULTIBYTE (elt
));
16630 else /* c == '%' */
16632 int percent_position
= offset
;
16634 /* Get the specified minimum width. Zero means
16637 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16638 field
= field
* 10 + c
- '0';
16640 /* Don't pad beyond the total padding allowed. */
16641 if (field_width
- n
> 0 && field
> field_width
- n
)
16642 field
= field_width
- n
;
16644 /* Note that either PRECISION <= 0 or N < PRECISION. */
16645 prec
= precision
- n
;
16648 n
+= display_mode_element (it
, depth
, field
, prec
,
16649 Vglobal_mode_string
, props
,
16654 int bytepos
, charpos
;
16655 unsigned char *spec
;
16657 bytepos
= percent_position
;
16658 charpos
= (STRING_MULTIBYTE (elt
)
16659 ? string_byte_to_char (elt
, bytepos
)
16663 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16665 switch (mode_line_target
)
16667 case MODE_LINE_NOPROP
:
16668 case MODE_LINE_TITLE
:
16669 n
+= store_mode_line_noprop (spec
, field
, prec
);
16671 case MODE_LINE_STRING
:
16673 int len
= strlen (spec
);
16674 Lisp_Object tem
= make_string (spec
, len
);
16675 props
= Ftext_properties_at (make_number (charpos
), elt
);
16676 /* Should only keep face property in props */
16677 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16680 case MODE_LINE_DISPLAY
:
16682 int nglyphs_before
, nwritten
;
16684 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16685 nwritten
= display_string (spec
, Qnil
, elt
,
16690 /* Assign to the glyphs written above the
16691 string where the `%x' came from, position
16695 struct glyph
*glyph
16696 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16700 for (i
= 0; i
< nwritten
; ++i
)
16702 glyph
[i
].object
= elt
;
16703 glyph
[i
].charpos
= charpos
;
16720 /* A symbol: process the value of the symbol recursively
16721 as if it appeared here directly. Avoid error if symbol void.
16722 Special case: if value of symbol is a string, output the string
16725 register Lisp_Object tem
;
16727 /* If the variable is not marked as risky to set
16728 then its contents are risky to use. */
16729 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16732 tem
= Fboundp (elt
);
16735 tem
= Fsymbol_value (elt
);
16736 /* If value is a string, output that string literally:
16737 don't check for % within it. */
16741 if (!EQ (tem
, elt
))
16743 /* Give up right away for nil or t. */
16753 register Lisp_Object car
, tem
;
16755 /* A cons cell: five distinct cases.
16756 If first element is :eval or :propertize, do something special.
16757 If first element is a string or a cons, process all the elements
16758 and effectively concatenate them.
16759 If first element is a negative number, truncate displaying cdr to
16760 at most that many characters. If positive, pad (with spaces)
16761 to at least that many characters.
16762 If first element is a symbol, process the cadr or caddr recursively
16763 according to whether the symbol's value is non-nil or nil. */
16765 if (EQ (car
, QCeval
))
16767 /* An element of the form (:eval FORM) means evaluate FORM
16768 and use the result as mode line elements. */
16773 if (CONSP (XCDR (elt
)))
16776 spec
= safe_eval (XCAR (XCDR (elt
)));
16777 n
+= display_mode_element (it
, depth
, field_width
- n
,
16778 precision
- n
, spec
, props
,
16782 else if (EQ (car
, QCpropertize
))
16784 /* An element of the form (:propertize ELT PROPS...)
16785 means display ELT but applying properties PROPS. */
16790 if (CONSP (XCDR (elt
)))
16791 n
+= display_mode_element (it
, depth
, field_width
- n
,
16792 precision
- n
, XCAR (XCDR (elt
)),
16793 XCDR (XCDR (elt
)), risky
);
16795 else if (SYMBOLP (car
))
16797 tem
= Fboundp (car
);
16801 /* elt is now the cdr, and we know it is a cons cell.
16802 Use its car if CAR has a non-nil value. */
16805 tem
= Fsymbol_value (car
);
16812 /* Symbol's value is nil (or symbol is unbound)
16813 Get the cddr of the original list
16814 and if possible find the caddr and use that. */
16818 else if (!CONSP (elt
))
16823 else if (INTEGERP (car
))
16825 register int lim
= XINT (car
);
16829 /* Negative int means reduce maximum width. */
16830 if (precision
<= 0)
16833 precision
= min (precision
, -lim
);
16837 /* Padding specified. Don't let it be more than
16838 current maximum. */
16840 lim
= min (precision
, lim
);
16842 /* If that's more padding than already wanted, queue it.
16843 But don't reduce padding already specified even if
16844 that is beyond the current truncation point. */
16845 field_width
= max (lim
, field_width
);
16849 else if (STRINGP (car
) || CONSP (car
))
16851 register int limit
= 50;
16852 /* Limit is to protect against circular lists. */
16855 && (precision
<= 0 || n
< precision
))
16857 n
+= display_mode_element (it
, depth
,
16858 /* Do padding only after the last
16859 element in the list. */
16860 (! CONSP (XCDR (elt
))
16863 precision
- n
, XCAR (elt
),
16873 elt
= build_string ("*invalid*");
16877 /* Pad to FIELD_WIDTH. */
16878 if (field_width
> 0 && n
< field_width
)
16880 switch (mode_line_target
)
16882 case MODE_LINE_NOPROP
:
16883 case MODE_LINE_TITLE
:
16884 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16886 case MODE_LINE_STRING
:
16887 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16889 case MODE_LINE_DISPLAY
:
16890 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16899 /* Store a mode-line string element in mode_line_string_list.
16901 If STRING is non-null, display that C string. Otherwise, the Lisp
16902 string LISP_STRING is displayed.
16904 FIELD_WIDTH is the minimum number of output glyphs to produce.
16905 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16906 with spaces. FIELD_WIDTH <= 0 means don't pad.
16908 PRECISION is the maximum number of characters to output from
16909 STRING. PRECISION <= 0 means don't truncate the string.
16911 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16912 properties to the string.
16914 PROPS are the properties to add to the string.
16915 The mode_line_string_face face property is always added to the string.
16919 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16921 Lisp_Object lisp_string
;
16930 if (string
!= NULL
)
16932 len
= strlen (string
);
16933 if (precision
> 0 && len
> precision
)
16935 lisp_string
= make_string (string
, len
);
16937 props
= mode_line_string_face_prop
;
16938 else if (!NILP (mode_line_string_face
))
16940 Lisp_Object face
= Fplist_get (props
, Qface
);
16941 props
= Fcopy_sequence (props
);
16943 face
= mode_line_string_face
;
16945 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16946 props
= Fplist_put (props
, Qface
, face
);
16948 Fadd_text_properties (make_number (0), make_number (len
),
16949 props
, lisp_string
);
16953 len
= XFASTINT (Flength (lisp_string
));
16954 if (precision
> 0 && len
> precision
)
16957 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16960 if (!NILP (mode_line_string_face
))
16964 props
= Ftext_properties_at (make_number (0), lisp_string
);
16965 face
= Fplist_get (props
, Qface
);
16967 face
= mode_line_string_face
;
16969 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16970 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16972 lisp_string
= Fcopy_sequence (lisp_string
);
16975 Fadd_text_properties (make_number (0), make_number (len
),
16976 props
, lisp_string
);
16981 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16985 if (field_width
> len
)
16987 field_width
-= len
;
16988 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16990 Fadd_text_properties (make_number (0), make_number (field_width
),
16991 props
, lisp_string
);
16992 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17000 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17002 doc
: /* Format a string out of a mode line format specification.
17003 First arg FORMAT specifies the mode line format (see `mode-line-format'
17004 for details) to use.
17006 Optional second arg FACE specifies the face property to put
17007 on all characters for which no face is specified.
17008 t means whatever face the window's mode line currently uses
17009 \(either `mode-line' or `mode-line-inactive', depending).
17010 nil means the default is no face property.
17011 If FACE is an integer, the value string has no text properties.
17013 Optional third and fourth args WINDOW and BUFFER specify the window
17014 and buffer to use as the context for the formatting (defaults
17015 are the selected window and the window's buffer). */)
17016 (format
, face
, window
, buffer
)
17017 Lisp_Object format
, face
, window
, buffer
;
17022 struct buffer
*old_buffer
= NULL
;
17024 int no_props
= INTEGERP (face
);
17025 int count
= SPECPDL_INDEX ();
17027 int string_start
= 0;
17030 window
= selected_window
;
17031 CHECK_WINDOW (window
);
17032 w
= XWINDOW (window
);
17035 buffer
= w
->buffer
;
17036 CHECK_BUFFER (buffer
);
17039 return build_string ("");
17047 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17048 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17052 face_id
= DEFAULT_FACE_ID
;
17054 if (XBUFFER (buffer
) != current_buffer
)
17055 old_buffer
= current_buffer
;
17057 /* Save things including mode_line_proptrans_alist,
17058 and set that to nil so that we don't alter the outer value. */
17059 record_unwind_protect (unwind_format_mode_line
,
17060 format_mode_line_unwind_data (old_buffer
, 1));
17061 mode_line_proptrans_alist
= Qnil
;
17064 set_buffer_internal_1 (XBUFFER (buffer
));
17066 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17070 mode_line_target
= MODE_LINE_NOPROP
;
17071 mode_line_string_face_prop
= Qnil
;
17072 mode_line_string_list
= Qnil
;
17073 string_start
= MODE_LINE_NOPROP_LEN (0);
17077 mode_line_target
= MODE_LINE_STRING
;
17078 mode_line_string_list
= Qnil
;
17079 mode_line_string_face
= face
;
17080 mode_line_string_face_prop
17081 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17084 push_frame_kboard (it
.f
);
17085 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17086 pop_frame_kboard ();
17090 len
= MODE_LINE_NOPROP_LEN (string_start
);
17091 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17095 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17096 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17097 make_string ("", 0));
17100 unbind_to (count
, Qnil
);
17104 /* Write a null-terminated, right justified decimal representation of
17105 the positive integer D to BUF using a minimal field width WIDTH. */
17108 pint2str (buf
, width
, d
)
17109 register char *buf
;
17110 register int width
;
17113 register char *p
= buf
;
17121 *p
++ = d
% 10 + '0';
17126 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17137 /* Write a null-terminated, right justified decimal and "human
17138 readable" representation of the nonnegative integer D to BUF using
17139 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17141 static const char power_letter
[] =
17155 pint2hrstr (buf
, width
, d
)
17160 /* We aim to represent the nonnegative integer D as
17161 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17164 /* -1 means: do not use TENTHS. */
17168 /* Length of QUOTIENT.TENTHS as a string. */
17174 if (1000 <= quotient
)
17176 /* Scale to the appropriate EXPONENT. */
17179 remainder
= quotient
% 1000;
17183 while (1000 <= quotient
);
17185 /* Round to nearest and decide whether to use TENTHS or not. */
17188 tenths
= remainder
/ 100;
17189 if (50 <= remainder
% 100)
17196 if (quotient
== 10)
17204 if (500 <= remainder
)
17206 if (quotient
< 999)
17217 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17218 if (tenths
== -1 && quotient
<= 99)
17225 p
= psuffix
= buf
+ max (width
, length
);
17227 /* Print EXPONENT. */
17229 *psuffix
++ = power_letter
[exponent
];
17232 /* Print TENTHS. */
17235 *--p
= '0' + tenths
;
17239 /* Print QUOTIENT. */
17242 int digit
= quotient
% 10;
17243 *--p
= '0' + digit
;
17245 while ((quotient
/= 10) != 0);
17247 /* Print leading spaces. */
17252 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17253 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17254 type of CODING_SYSTEM. Return updated pointer into BUF. */
17256 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17259 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17260 Lisp_Object coding_system
;
17261 register char *buf
;
17265 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17266 const unsigned char *eol_str
;
17268 /* The EOL conversion we are using. */
17269 Lisp_Object eoltype
;
17271 val
= Fget (coding_system
, Qcoding_system
);
17274 if (!VECTORP (val
)) /* Not yet decided. */
17279 eoltype
= eol_mnemonic_undecided
;
17280 /* Don't mention EOL conversion if it isn't decided. */
17284 Lisp_Object eolvalue
;
17286 eolvalue
= Fget (coding_system
, Qeol_type
);
17289 *buf
++ = XFASTINT (AREF (val
, 1));
17293 /* The EOL conversion that is normal on this system. */
17295 if (NILP (eolvalue
)) /* Not yet decided. */
17296 eoltype
= eol_mnemonic_undecided
;
17297 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17298 eoltype
= eol_mnemonic_undecided
;
17299 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17300 eoltype
= (XFASTINT (eolvalue
) == 0
17301 ? eol_mnemonic_unix
17302 : (XFASTINT (eolvalue
) == 1
17303 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17309 /* Mention the EOL conversion if it is not the usual one. */
17310 if (STRINGP (eoltype
))
17312 eol_str
= SDATA (eoltype
);
17313 eol_str_len
= SBYTES (eoltype
);
17315 else if (INTEGERP (eoltype
)
17316 && CHAR_VALID_P (XINT (eoltype
), 0))
17318 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17319 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17324 eol_str
= invalid_eol_type
;
17325 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17327 bcopy (eol_str
, buf
, eol_str_len
);
17328 buf
+= eol_str_len
;
17334 /* Return a string for the output of a mode line %-spec for window W,
17335 generated by character C. PRECISION >= 0 means don't return a
17336 string longer than that value. FIELD_WIDTH > 0 means pad the
17337 string returned with spaces to that value. Return 1 in *MULTIBYTE
17338 if the result is multibyte text.
17340 Note we operate on the current buffer for most purposes,
17341 the exception being w->base_line_pos. */
17343 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17346 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17349 int field_width
, precision
;
17353 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17354 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17355 struct buffer
*b
= current_buffer
;
17363 if (!NILP (b
->read_only
))
17365 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17370 /* This differs from %* only for a modified read-only buffer. */
17371 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17373 if (!NILP (b
->read_only
))
17378 /* This differs from %* in ignoring read-only-ness. */
17379 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17391 if (command_loop_level
> 5)
17393 p
= decode_mode_spec_buf
;
17394 for (i
= 0; i
< command_loop_level
; i
++)
17397 return decode_mode_spec_buf
;
17405 if (command_loop_level
> 5)
17407 p
= decode_mode_spec_buf
;
17408 for (i
= 0; i
< command_loop_level
; i
++)
17411 return decode_mode_spec_buf
;
17418 /* Let lots_of_dashes be a string of infinite length. */
17419 if (mode_line_target
== MODE_LINE_NOPROP
||
17420 mode_line_target
== MODE_LINE_STRING
)
17422 if (field_width
<= 0
17423 || field_width
> sizeof (lots_of_dashes
))
17425 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17426 decode_mode_spec_buf
[i
] = '-';
17427 decode_mode_spec_buf
[i
] = '\0';
17428 return decode_mode_spec_buf
;
17431 return lots_of_dashes
;
17440 int col
= (int) current_column (); /* iftc */
17441 w
->column_number_displayed
= make_number (col
);
17442 pint2str (decode_mode_spec_buf
, field_width
, col
);
17443 return decode_mode_spec_buf
;
17447 #ifndef SYSTEM_MALLOC
17449 if (NILP (Vmemory_full
))
17452 return "!MEM FULL! ";
17459 /* %F displays the frame name. */
17460 if (!NILP (f
->title
))
17461 return (char *) SDATA (f
->title
);
17462 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17463 return (char *) SDATA (f
->name
);
17472 int size
= ZV
- BEGV
;
17473 pint2str (decode_mode_spec_buf
, field_width
, size
);
17474 return decode_mode_spec_buf
;
17479 int size
= ZV
- BEGV
;
17480 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17481 return decode_mode_spec_buf
;
17486 int startpos
= XMARKER (w
->start
)->charpos
;
17487 int startpos_byte
= marker_byte_position (w
->start
);
17488 int line
, linepos
, linepos_byte
, topline
;
17490 int height
= WINDOW_TOTAL_LINES (w
);
17492 /* If we decided that this buffer isn't suitable for line numbers,
17493 don't forget that too fast. */
17494 if (EQ (w
->base_line_pos
, w
->buffer
))
17496 /* But do forget it, if the window shows a different buffer now. */
17497 else if (BUFFERP (w
->base_line_pos
))
17498 w
->base_line_pos
= Qnil
;
17500 /* If the buffer is very big, don't waste time. */
17501 if (INTEGERP (Vline_number_display_limit
)
17502 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17504 w
->base_line_pos
= Qnil
;
17505 w
->base_line_number
= Qnil
;
17509 if (!NILP (w
->base_line_number
)
17510 && !NILP (w
->base_line_pos
)
17511 && XFASTINT (w
->base_line_pos
) <= startpos
)
17513 line
= XFASTINT (w
->base_line_number
);
17514 linepos
= XFASTINT (w
->base_line_pos
);
17515 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17520 linepos
= BUF_BEGV (b
);
17521 linepos_byte
= BUF_BEGV_BYTE (b
);
17524 /* Count lines from base line to window start position. */
17525 nlines
= display_count_lines (linepos
, linepos_byte
,
17529 topline
= nlines
+ line
;
17531 /* Determine a new base line, if the old one is too close
17532 or too far away, or if we did not have one.
17533 "Too close" means it's plausible a scroll-down would
17534 go back past it. */
17535 if (startpos
== BUF_BEGV (b
))
17537 w
->base_line_number
= make_number (topline
);
17538 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17540 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17541 || linepos
== BUF_BEGV (b
))
17543 int limit
= BUF_BEGV (b
);
17544 int limit_byte
= BUF_BEGV_BYTE (b
);
17546 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17548 if (startpos
- distance
> limit
)
17550 limit
= startpos
- distance
;
17551 limit_byte
= CHAR_TO_BYTE (limit
);
17554 nlines
= display_count_lines (startpos
, startpos_byte
,
17556 - (height
* 2 + 30),
17558 /* If we couldn't find the lines we wanted within
17559 line_number_display_limit_width chars per line,
17560 give up on line numbers for this window. */
17561 if (position
== limit_byte
&& limit
== startpos
- distance
)
17563 w
->base_line_pos
= w
->buffer
;
17564 w
->base_line_number
= Qnil
;
17568 w
->base_line_number
= make_number (topline
- nlines
);
17569 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17572 /* Now count lines from the start pos to point. */
17573 nlines
= display_count_lines (startpos
, startpos_byte
,
17574 PT_BYTE
, PT
, &junk
);
17576 /* Record that we did display the line number. */
17577 line_number_displayed
= 1;
17579 /* Make the string to show. */
17580 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17581 return decode_mode_spec_buf
;
17584 char* p
= decode_mode_spec_buf
;
17585 int pad
= field_width
- 2;
17591 return decode_mode_spec_buf
;
17597 obj
= b
->mode_name
;
17601 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17607 int pos
= marker_position (w
->start
);
17608 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17610 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17612 if (pos
<= BUF_BEGV (b
))
17617 else if (pos
<= BUF_BEGV (b
))
17621 if (total
> 1000000)
17622 /* Do it differently for a large value, to avoid overflow. */
17623 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17625 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17626 /* We can't normally display a 3-digit number,
17627 so get us a 2-digit number that is close. */
17630 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17631 return decode_mode_spec_buf
;
17635 /* Display percentage of size above the bottom of the screen. */
17638 int toppos
= marker_position (w
->start
);
17639 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17640 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17642 if (botpos
>= BUF_ZV (b
))
17644 if (toppos
<= BUF_BEGV (b
))
17651 if (total
> 1000000)
17652 /* Do it differently for a large value, to avoid overflow. */
17653 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17655 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17656 /* We can't normally display a 3-digit number,
17657 so get us a 2-digit number that is close. */
17660 if (toppos
<= BUF_BEGV (b
))
17661 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17663 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17664 return decode_mode_spec_buf
;
17669 /* status of process */
17670 obj
= Fget_buffer_process (Fcurrent_buffer ());
17672 return "no process";
17673 #ifdef subprocesses
17674 obj
= Fsymbol_name (Fprocess_status (obj
));
17678 case 't': /* indicate TEXT or BINARY */
17679 #ifdef MODE_LINE_BINARY_TEXT
17680 return MODE_LINE_BINARY_TEXT (b
);
17686 /* coding-system (not including end-of-line format) */
17688 /* coding-system (including end-of-line type) */
17690 int eol_flag
= (c
== 'Z');
17691 char *p
= decode_mode_spec_buf
;
17693 if (! FRAME_WINDOW_P (f
))
17695 /* No need to mention EOL here--the terminal never needs
17696 to do EOL conversion. */
17697 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17698 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17700 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17703 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17704 #ifdef subprocesses
17705 obj
= Fget_buffer_process (Fcurrent_buffer ());
17706 if (PROCESSP (obj
))
17708 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17710 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17713 #endif /* subprocesses */
17716 return decode_mode_spec_buf
;
17722 *multibyte
= STRING_MULTIBYTE (obj
);
17723 return (char *) SDATA (obj
);
17730 /* Count up to COUNT lines starting from START / START_BYTE.
17731 But don't go beyond LIMIT_BYTE.
17732 Return the number of lines thus found (always nonnegative).
17734 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17737 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17738 int start
, start_byte
, limit_byte
, count
;
17741 register unsigned char *cursor
;
17742 unsigned char *base
;
17744 register int ceiling
;
17745 register unsigned char *ceiling_addr
;
17746 int orig_count
= count
;
17748 /* If we are not in selective display mode,
17749 check only for newlines. */
17750 int selective_display
= (!NILP (current_buffer
->selective_display
)
17751 && !INTEGERP (current_buffer
->selective_display
));
17755 while (start_byte
< limit_byte
)
17757 ceiling
= BUFFER_CEILING_OF (start_byte
);
17758 ceiling
= min (limit_byte
- 1, ceiling
);
17759 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17760 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17763 if (selective_display
)
17764 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17767 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17770 if (cursor
!= ceiling_addr
)
17774 start_byte
+= cursor
- base
+ 1;
17775 *byte_pos_ptr
= start_byte
;
17779 if (++cursor
== ceiling_addr
)
17785 start_byte
+= cursor
- base
;
17790 while (start_byte
> limit_byte
)
17792 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17793 ceiling
= max (limit_byte
, ceiling
);
17794 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17795 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17798 if (selective_display
)
17799 while (--cursor
!= ceiling_addr
17800 && *cursor
!= '\n' && *cursor
!= 015)
17803 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17806 if (cursor
!= ceiling_addr
)
17810 start_byte
+= cursor
- base
+ 1;
17811 *byte_pos_ptr
= start_byte
;
17812 /* When scanning backwards, we should
17813 not count the newline posterior to which we stop. */
17814 return - orig_count
- 1;
17820 /* Here we add 1 to compensate for the last decrement
17821 of CURSOR, which took it past the valid range. */
17822 start_byte
+= cursor
- base
+ 1;
17826 *byte_pos_ptr
= limit_byte
;
17829 return - orig_count
+ count
;
17830 return orig_count
- count
;
17836 /***********************************************************************
17838 ***********************************************************************/
17840 /* Display a NUL-terminated string, starting with index START.
17842 If STRING is non-null, display that C string. Otherwise, the Lisp
17843 string LISP_STRING is displayed.
17845 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17846 FACE_STRING. Display STRING or LISP_STRING with the face at
17847 FACE_STRING_POS in FACE_STRING:
17849 Display the string in the environment given by IT, but use the
17850 standard display table, temporarily.
17852 FIELD_WIDTH is the minimum number of output glyphs to produce.
17853 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17854 with spaces. If STRING has more characters, more than FIELD_WIDTH
17855 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17857 PRECISION is the maximum number of characters to output from
17858 STRING. PRECISION < 0 means don't truncate the string.
17860 This is roughly equivalent to printf format specifiers:
17862 FIELD_WIDTH PRECISION PRINTF
17863 ----------------------------------------
17869 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17870 display them, and < 0 means obey the current buffer's value of
17871 enable_multibyte_characters.
17873 Value is the number of columns displayed. */
17876 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17877 start
, it
, field_width
, precision
, max_x
, multibyte
)
17878 unsigned char *string
;
17879 Lisp_Object lisp_string
;
17880 Lisp_Object face_string
;
17881 int face_string_pos
;
17884 int field_width
, precision
, max_x
;
17887 int hpos_at_start
= it
->hpos
;
17888 int saved_face_id
= it
->face_id
;
17889 struct glyph_row
*row
= it
->glyph_row
;
17891 /* Initialize the iterator IT for iteration over STRING beginning
17892 with index START. */
17893 reseat_to_string (it
, string
, lisp_string
, start
,
17894 precision
, field_width
, multibyte
);
17896 /* If displaying STRING, set up the face of the iterator
17897 from LISP_STRING, if that's given. */
17898 if (STRINGP (face_string
))
17904 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17905 0, it
->region_beg_charpos
,
17906 it
->region_end_charpos
,
17907 &endptr
, it
->base_face_id
, 0);
17908 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17909 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17912 /* Set max_x to the maximum allowed X position. Don't let it go
17913 beyond the right edge of the window. */
17915 max_x
= it
->last_visible_x
;
17917 max_x
= min (max_x
, it
->last_visible_x
);
17919 /* Skip over display elements that are not visible. because IT->w is
17921 if (it
->current_x
< it
->first_visible_x
)
17922 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17923 MOVE_TO_POS
| MOVE_TO_X
);
17925 row
->ascent
= it
->max_ascent
;
17926 row
->height
= it
->max_ascent
+ it
->max_descent
;
17927 row
->phys_ascent
= it
->max_phys_ascent
;
17928 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17929 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17931 /* This condition is for the case that we are called with current_x
17932 past last_visible_x. */
17933 while (it
->current_x
< max_x
)
17935 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17937 /* Get the next display element. */
17938 if (!get_next_display_element (it
))
17941 /* Produce glyphs. */
17942 x_before
= it
->current_x
;
17943 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17944 PRODUCE_GLYPHS (it
);
17946 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17949 while (i
< nglyphs
)
17951 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17953 if (!it
->truncate_lines_p
17954 && x
+ glyph
->pixel_width
> max_x
)
17956 /* End of continued line or max_x reached. */
17957 if (CHAR_GLYPH_PADDING_P (*glyph
))
17959 /* A wide character is unbreakable. */
17960 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17961 it
->current_x
= x_before
;
17965 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17970 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17972 /* Glyph is at least partially visible. */
17974 if (x
< it
->first_visible_x
)
17975 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17979 /* Glyph is off the left margin of the display area.
17980 Should not happen. */
17984 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17985 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17986 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17987 row
->phys_height
= max (row
->phys_height
,
17988 it
->max_phys_ascent
+ it
->max_phys_descent
);
17989 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17990 it
->max_extra_line_spacing
);
17991 x
+= glyph
->pixel_width
;
17995 /* Stop if max_x reached. */
17999 /* Stop at line ends. */
18000 if (ITERATOR_AT_END_OF_LINE_P (it
))
18002 it
->continuation_lines_width
= 0;
18006 set_iterator_to_next (it
, 1);
18008 /* Stop if truncating at the right edge. */
18009 if (it
->truncate_lines_p
18010 && it
->current_x
>= it
->last_visible_x
)
18012 /* Add truncation mark, but don't do it if the line is
18013 truncated at a padding space. */
18014 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18016 if (!FRAME_WINDOW_P (it
->f
))
18020 if (it
->current_x
> it
->last_visible_x
)
18022 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18023 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18025 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18027 row
->used
[TEXT_AREA
] = i
;
18028 produce_special_glyphs (it
, IT_TRUNCATION
);
18031 produce_special_glyphs (it
, IT_TRUNCATION
);
18033 it
->glyph_row
->truncated_on_right_p
= 1;
18039 /* Maybe insert a truncation at the left. */
18040 if (it
->first_visible_x
18041 && IT_CHARPOS (*it
) > 0)
18043 if (!FRAME_WINDOW_P (it
->f
))
18044 insert_left_trunc_glyphs (it
);
18045 it
->glyph_row
->truncated_on_left_p
= 1;
18048 it
->face_id
= saved_face_id
;
18050 /* Value is number of columns displayed. */
18051 return it
->hpos
- hpos_at_start
;
18056 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18057 appears as an element of LIST or as the car of an element of LIST.
18058 If PROPVAL is a list, compare each element against LIST in that
18059 way, and return 1/2 if any element of PROPVAL is found in LIST.
18060 Otherwise return 0. This function cannot quit.
18061 The return value is 2 if the text is invisible but with an ellipsis
18062 and 1 if it's invisible and without an ellipsis. */
18065 invisible_p (propval
, list
)
18066 register Lisp_Object propval
;
18069 register Lisp_Object tail
, proptail
;
18071 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18073 register Lisp_Object tem
;
18075 if (EQ (propval
, tem
))
18077 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18078 return NILP (XCDR (tem
)) ? 1 : 2;
18081 if (CONSP (propval
))
18083 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18085 Lisp_Object propelt
;
18086 propelt
= XCAR (proptail
);
18087 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18089 register Lisp_Object tem
;
18091 if (EQ (propelt
, tem
))
18093 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18094 return NILP (XCDR (tem
)) ? 1 : 2;
18102 /* Calculate a width or height in pixels from a specification using
18103 the following elements:
18106 NUM - a (fractional) multiple of the default font width/height
18107 (NUM) - specifies exactly NUM pixels
18108 UNIT - a fixed number of pixels, see below.
18109 ELEMENT - size of a display element in pixels, see below.
18110 (NUM . SPEC) - equals NUM * SPEC
18111 (+ SPEC SPEC ...) - add pixel values
18112 (- SPEC SPEC ...) - subtract pixel values
18113 (- SPEC) - negate pixel value
18116 INT or FLOAT - a number constant
18117 SYMBOL - use symbol's (buffer local) variable binding.
18120 in - pixels per inch *)
18121 mm - pixels per 1/1000 meter *)
18122 cm - pixels per 1/100 meter *)
18123 width - width of current font in pixels.
18124 height - height of current font in pixels.
18126 *) using the ratio(s) defined in display-pixels-per-inch.
18130 left-fringe - left fringe width in pixels
18131 right-fringe - right fringe width in pixels
18133 left-margin - left margin width in pixels
18134 right-margin - right margin width in pixels
18136 scroll-bar - scroll-bar area width in pixels
18140 Pixels corresponding to 5 inches:
18143 Total width of non-text areas on left side of window (if scroll-bar is on left):
18144 '(space :width (+ left-fringe left-margin scroll-bar))
18146 Align to first text column (in header line):
18147 '(space :align-to 0)
18149 Align to middle of text area minus half the width of variable `my-image'
18150 containing a loaded image:
18151 '(space :align-to (0.5 . (- text my-image)))
18153 Width of left margin minus width of 1 character in the default font:
18154 '(space :width (- left-margin 1))
18156 Width of left margin minus width of 2 characters in the current font:
18157 '(space :width (- left-margin (2 . width)))
18159 Center 1 character over left-margin (in header line):
18160 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18162 Different ways to express width of left fringe plus left margin minus one pixel:
18163 '(space :width (- (+ left-fringe left-margin) (1)))
18164 '(space :width (+ left-fringe left-margin (- (1))))
18165 '(space :width (+ left-fringe left-margin (-1)))
18169 #define NUMVAL(X) \
18170 ((INTEGERP (X) || FLOATP (X)) \
18175 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18180 int width_p
, *align_to
;
18184 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18185 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18188 return OK_PIXELS (0);
18190 if (SYMBOLP (prop
))
18192 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18194 char *unit
= SDATA (SYMBOL_NAME (prop
));
18196 if (unit
[0] == 'i' && unit
[1] == 'n')
18198 else if (unit
[0] == 'm' && unit
[1] == 'm')
18200 else if (unit
[0] == 'c' && unit
[1] == 'm')
18207 #ifdef HAVE_WINDOW_SYSTEM
18208 if (FRAME_WINDOW_P (it
->f
)
18210 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18211 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18213 return OK_PIXELS (ppi
/ pixels
);
18216 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18217 || (CONSP (Vdisplay_pixels_per_inch
)
18219 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18220 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18222 return OK_PIXELS (ppi
/ pixels
);
18228 #ifdef HAVE_WINDOW_SYSTEM
18229 if (EQ (prop
, Qheight
))
18230 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18231 if (EQ (prop
, Qwidth
))
18232 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18234 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18235 return OK_PIXELS (1);
18238 if (EQ (prop
, Qtext
))
18239 return OK_PIXELS (width_p
18240 ? window_box_width (it
->w
, TEXT_AREA
)
18241 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18243 if (align_to
&& *align_to
< 0)
18246 if (EQ (prop
, Qleft
))
18247 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18248 if (EQ (prop
, Qright
))
18249 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18250 if (EQ (prop
, Qcenter
))
18251 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18252 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18253 if (EQ (prop
, Qleft_fringe
))
18254 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18255 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18256 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18257 if (EQ (prop
, Qright_fringe
))
18258 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18259 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18260 : window_box_right_offset (it
->w
, TEXT_AREA
));
18261 if (EQ (prop
, Qleft_margin
))
18262 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18263 if (EQ (prop
, Qright_margin
))
18264 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18265 if (EQ (prop
, Qscroll_bar
))
18266 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18268 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18269 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18270 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18275 if (EQ (prop
, Qleft_fringe
))
18276 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18277 if (EQ (prop
, Qright_fringe
))
18278 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18279 if (EQ (prop
, Qleft_margin
))
18280 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18281 if (EQ (prop
, Qright_margin
))
18282 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18283 if (EQ (prop
, Qscroll_bar
))
18284 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18287 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18290 if (INTEGERP (prop
) || FLOATP (prop
))
18292 int base_unit
= (width_p
18293 ? FRAME_COLUMN_WIDTH (it
->f
)
18294 : FRAME_LINE_HEIGHT (it
->f
));
18295 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18300 Lisp_Object car
= XCAR (prop
);
18301 Lisp_Object cdr
= XCDR (prop
);
18305 #ifdef HAVE_WINDOW_SYSTEM
18306 if (valid_image_p (prop
))
18308 int id
= lookup_image (it
->f
, prop
);
18309 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18311 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18314 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18320 while (CONSP (cdr
))
18322 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18323 font
, width_p
, align_to
))
18326 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18331 if (EQ (car
, Qminus
))
18333 return OK_PIXELS (pixels
);
18336 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18339 if (INTEGERP (car
) || FLOATP (car
))
18342 pixels
= XFLOATINT (car
);
18344 return OK_PIXELS (pixels
);
18345 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18346 font
, width_p
, align_to
))
18347 return OK_PIXELS (pixels
* fact
);
18358 /***********************************************************************
18360 ***********************************************************************/
18362 #ifdef HAVE_WINDOW_SYSTEM
18367 dump_glyph_string (s
)
18368 struct glyph_string
*s
;
18370 fprintf (stderr
, "glyph string\n");
18371 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18372 s
->x
, s
->y
, s
->width
, s
->height
);
18373 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18374 fprintf (stderr
, " hl = %d\n", s
->hl
);
18375 fprintf (stderr
, " left overhang = %d, right = %d\n",
18376 s
->left_overhang
, s
->right_overhang
);
18377 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18378 fprintf (stderr
, " extends to end of line = %d\n",
18379 s
->extends_to_end_of_line_p
);
18380 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18381 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18384 #endif /* GLYPH_DEBUG */
18386 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18387 of XChar2b structures for S; it can't be allocated in
18388 init_glyph_string because it must be allocated via `alloca'. W
18389 is the window on which S is drawn. ROW and AREA are the glyph row
18390 and area within the row from which S is constructed. START is the
18391 index of the first glyph structure covered by S. HL is a
18392 face-override for drawing S. */
18395 #define OPTIONAL_HDC(hdc) hdc,
18396 #define DECLARE_HDC(hdc) HDC hdc;
18397 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18398 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18401 #ifndef OPTIONAL_HDC
18402 #define OPTIONAL_HDC(hdc)
18403 #define DECLARE_HDC(hdc)
18404 #define ALLOCATE_HDC(hdc, f)
18405 #define RELEASE_HDC(hdc, f)
18409 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18410 struct glyph_string
*s
;
18414 struct glyph_row
*row
;
18415 enum glyph_row_area area
;
18417 enum draw_glyphs_face hl
;
18419 bzero (s
, sizeof *s
);
18421 s
->f
= XFRAME (w
->frame
);
18425 s
->display
= FRAME_X_DISPLAY (s
->f
);
18426 s
->window
= FRAME_X_WINDOW (s
->f
);
18427 s
->char2b
= char2b
;
18431 s
->first_glyph
= row
->glyphs
[area
] + start
;
18432 s
->height
= row
->height
;
18433 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18435 /* Display the internal border below the tool-bar window. */
18436 if (WINDOWP (s
->f
->tool_bar_window
)
18437 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18438 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18440 s
->ybase
= s
->y
+ row
->ascent
;
18444 /* Append the list of glyph strings with head H and tail T to the list
18445 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18448 append_glyph_string_lists (head
, tail
, h
, t
)
18449 struct glyph_string
**head
, **tail
;
18450 struct glyph_string
*h
, *t
;
18464 /* Prepend the list of glyph strings with head H and tail T to the
18465 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18469 prepend_glyph_string_lists (head
, tail
, h
, t
)
18470 struct glyph_string
**head
, **tail
;
18471 struct glyph_string
*h
, *t
;
18485 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18486 Set *HEAD and *TAIL to the resulting list. */
18489 append_glyph_string (head
, tail
, s
)
18490 struct glyph_string
**head
, **tail
;
18491 struct glyph_string
*s
;
18493 s
->next
= s
->prev
= NULL
;
18494 append_glyph_string_lists (head
, tail
, s
, s
);
18498 /* Get face and two-byte form of character glyph GLYPH on frame F.
18499 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18500 a pointer to a realized face that is ready for display. */
18502 static INLINE
struct face
*
18503 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18505 struct glyph
*glyph
;
18511 xassert (glyph
->type
== CHAR_GLYPH
);
18512 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18517 if (!glyph
->multibyte_p
)
18519 /* Unibyte case. We don't have to encode, but we have to make
18520 sure to use a face suitable for unibyte. */
18521 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18523 else if (glyph
->u
.ch
< 128
18524 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18526 /* Case of ASCII in a face known to fit ASCII. */
18527 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18531 int c1
, c2
, charset
;
18533 /* Split characters into bytes. If c2 is -1 afterwards, C is
18534 really a one-byte character so that byte1 is zero. */
18535 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18537 STORE_XCHAR2B (char2b
, c1
, c2
);
18539 STORE_XCHAR2B (char2b
, 0, c1
);
18541 /* Maybe encode the character in *CHAR2B. */
18542 if (charset
!= CHARSET_ASCII
)
18544 struct font_info
*font_info
18545 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18548 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18552 /* Make sure X resources of the face are allocated. */
18553 xassert (face
!= NULL
);
18554 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18559 /* Fill glyph string S with composition components specified by S->cmp.
18561 FACES is an array of faces for all components of this composition.
18562 S->gidx is the index of the first component for S.
18564 OVERLAPS non-zero means S should draw the foreground only, and use
18565 its physical height for clipping. See also draw_glyphs.
18567 Value is the index of a component not in S. */
18570 fill_composite_glyph_string (s
, faces
, overlaps
)
18571 struct glyph_string
*s
;
18572 struct face
**faces
;
18579 s
->for_overlaps
= overlaps
;
18581 s
->face
= faces
[s
->gidx
];
18582 s
->font
= s
->face
->font
;
18583 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18585 /* For all glyphs of this composition, starting at the offset
18586 S->gidx, until we reach the end of the definition or encounter a
18587 glyph that requires the different face, add it to S. */
18589 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18592 /* All glyph strings for the same composition has the same width,
18593 i.e. the width set for the first component of the composition. */
18595 s
->width
= s
->first_glyph
->pixel_width
;
18597 /* If the specified font could not be loaded, use the frame's
18598 default font, but record the fact that we couldn't load it in
18599 the glyph string so that we can draw rectangles for the
18600 characters of the glyph string. */
18601 if (s
->font
== NULL
)
18603 s
->font_not_found_p
= 1;
18604 s
->font
= FRAME_FONT (s
->f
);
18607 /* Adjust base line for subscript/superscript text. */
18608 s
->ybase
+= s
->first_glyph
->voffset
;
18610 xassert (s
->face
&& s
->face
->gc
);
18612 /* This glyph string must always be drawn with 16-bit functions. */
18615 return s
->gidx
+ s
->nchars
;
18619 /* Fill glyph string S from a sequence of character glyphs.
18621 FACE_ID is the face id of the string. START is the index of the
18622 first glyph to consider, END is the index of the last + 1.
18623 OVERLAPS non-zero means S should draw the foreground only, and use
18624 its physical height for clipping. See also draw_glyphs.
18626 Value is the index of the first glyph not in S. */
18629 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18630 struct glyph_string
*s
;
18632 int start
, end
, overlaps
;
18634 struct glyph
*glyph
, *last
;
18636 int glyph_not_available_p
;
18638 xassert (s
->f
== XFRAME (s
->w
->frame
));
18639 xassert (s
->nchars
== 0);
18640 xassert (start
>= 0 && end
> start
);
18642 s
->for_overlaps
= overlaps
,
18643 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18644 last
= s
->row
->glyphs
[s
->area
] + end
;
18645 voffset
= glyph
->voffset
;
18647 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18649 while (glyph
< last
18650 && glyph
->type
== CHAR_GLYPH
18651 && glyph
->voffset
== voffset
18652 /* Same face id implies same font, nowadays. */
18653 && glyph
->face_id
== face_id
18654 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18658 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18659 s
->char2b
+ s
->nchars
,
18661 s
->two_byte_p
= two_byte_p
;
18663 xassert (s
->nchars
<= end
- start
);
18664 s
->width
+= glyph
->pixel_width
;
18668 s
->font
= s
->face
->font
;
18669 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18671 /* If the specified font could not be loaded, use the frame's font,
18672 but record the fact that we couldn't load it in
18673 S->font_not_found_p so that we can draw rectangles for the
18674 characters of the glyph string. */
18675 if (s
->font
== NULL
|| glyph_not_available_p
)
18677 s
->font_not_found_p
= 1;
18678 s
->font
= FRAME_FONT (s
->f
);
18681 /* Adjust base line for subscript/superscript text. */
18682 s
->ybase
+= voffset
;
18684 xassert (s
->face
&& s
->face
->gc
);
18685 return glyph
- s
->row
->glyphs
[s
->area
];
18689 /* Fill glyph string S from image glyph S->first_glyph. */
18692 fill_image_glyph_string (s
)
18693 struct glyph_string
*s
;
18695 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18696 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18698 s
->slice
= s
->first_glyph
->slice
;
18699 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18700 s
->font
= s
->face
->font
;
18701 s
->width
= s
->first_glyph
->pixel_width
;
18703 /* Adjust base line for subscript/superscript text. */
18704 s
->ybase
+= s
->first_glyph
->voffset
;
18708 /* Fill glyph string S from a sequence of stretch glyphs.
18710 ROW is the glyph row in which the glyphs are found, AREA is the
18711 area within the row. START is the index of the first glyph to
18712 consider, END is the index of the last + 1.
18714 Value is the index of the first glyph not in S. */
18717 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18718 struct glyph_string
*s
;
18719 struct glyph_row
*row
;
18720 enum glyph_row_area area
;
18723 struct glyph
*glyph
, *last
;
18724 int voffset
, face_id
;
18726 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18728 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18729 last
= s
->row
->glyphs
[s
->area
] + end
;
18730 face_id
= glyph
->face_id
;
18731 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18732 s
->font
= s
->face
->font
;
18733 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18734 s
->width
= glyph
->pixel_width
;
18736 voffset
= glyph
->voffset
;
18740 && glyph
->type
== STRETCH_GLYPH
18741 && glyph
->voffset
== voffset
18742 && glyph
->face_id
== face_id
);
18744 s
->width
+= glyph
->pixel_width
;
18746 /* Adjust base line for subscript/superscript text. */
18747 s
->ybase
+= voffset
;
18749 /* The case that face->gc == 0 is handled when drawing the glyph
18750 string by calling PREPARE_FACE_FOR_DISPLAY. */
18752 return glyph
- s
->row
->glyphs
[s
->area
];
18757 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18758 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18759 assumed to be zero. */
18762 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18763 struct glyph
*glyph
;
18767 *left
= *right
= 0;
18769 if (glyph
->type
== CHAR_GLYPH
)
18773 struct font_info
*font_info
;
18777 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18779 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18780 if (font
/* ++KFS: Should this be font_info ? */
18781 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18783 if (pcm
->rbearing
> pcm
->width
)
18784 *right
= pcm
->rbearing
- pcm
->width
;
18785 if (pcm
->lbearing
< 0)
18786 *left
= -pcm
->lbearing
;
18792 /* Return the index of the first glyph preceding glyph string S that
18793 is overwritten by S because of S's left overhang. Value is -1
18794 if no glyphs are overwritten. */
18797 left_overwritten (s
)
18798 struct glyph_string
*s
;
18802 if (s
->left_overhang
)
18805 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18806 int first
= s
->first_glyph
- glyphs
;
18808 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18809 x
-= glyphs
[i
].pixel_width
;
18820 /* Return the index of the first glyph preceding glyph string S that
18821 is overwriting S because of its right overhang. Value is -1 if no
18822 glyph in front of S overwrites S. */
18825 left_overwriting (s
)
18826 struct glyph_string
*s
;
18829 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18830 int first
= s
->first_glyph
- glyphs
;
18834 for (i
= first
- 1; i
>= 0; --i
)
18837 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18840 x
-= glyphs
[i
].pixel_width
;
18847 /* Return the index of the last glyph following glyph string S that is
18848 not overwritten by S because of S's right overhang. Value is -1 if
18849 no such glyph is found. */
18852 right_overwritten (s
)
18853 struct glyph_string
*s
;
18857 if (s
->right_overhang
)
18860 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18861 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18862 int end
= s
->row
->used
[s
->area
];
18864 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18865 x
+= glyphs
[i
].pixel_width
;
18874 /* Return the index of the last glyph following glyph string S that
18875 overwrites S because of its left overhang. Value is negative
18876 if no such glyph is found. */
18879 right_overwriting (s
)
18880 struct glyph_string
*s
;
18883 int end
= s
->row
->used
[s
->area
];
18884 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18885 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18889 for (i
= first
; i
< end
; ++i
)
18892 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18895 x
+= glyphs
[i
].pixel_width
;
18902 /* Get face and two-byte form of character C in face FACE_ID on frame
18903 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18904 means we want to display multibyte text. DISPLAY_P non-zero means
18905 make sure that X resources for the face returned are allocated.
18906 Value is a pointer to a realized face that is ready for display if
18907 DISPLAY_P is non-zero. */
18909 static INLINE
struct face
*
18910 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18914 int multibyte_p
, display_p
;
18916 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18920 /* Unibyte case. We don't have to encode, but we have to make
18921 sure to use a face suitable for unibyte. */
18922 STORE_XCHAR2B (char2b
, 0, c
);
18923 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18924 face
= FACE_FROM_ID (f
, face_id
);
18926 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18928 /* Case of ASCII in a face known to fit ASCII. */
18929 STORE_XCHAR2B (char2b
, 0, c
);
18933 int c1
, c2
, charset
;
18935 /* Split characters into bytes. If c2 is -1 afterwards, C is
18936 really a one-byte character so that byte1 is zero. */
18937 SPLIT_CHAR (c
, charset
, c1
, c2
);
18939 STORE_XCHAR2B (char2b
, c1
, c2
);
18941 STORE_XCHAR2B (char2b
, 0, c1
);
18943 /* Maybe encode the character in *CHAR2B. */
18944 if (face
->font
!= NULL
)
18946 struct font_info
*font_info
18947 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18949 rif
->encode_char (c
, char2b
, font_info
, 0);
18953 /* Make sure X resources of the face are allocated. */
18954 #ifdef HAVE_X_WINDOWS
18958 xassert (face
!= NULL
);
18959 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18966 /* Set background width of glyph string S. START is the index of the
18967 first glyph following S. LAST_X is the right-most x-position + 1
18968 in the drawing area. */
18971 set_glyph_string_background_width (s
, start
, last_x
)
18972 struct glyph_string
*s
;
18976 /* If the face of this glyph string has to be drawn to the end of
18977 the drawing area, set S->extends_to_end_of_line_p. */
18979 if (start
== s
->row
->used
[s
->area
]
18980 && s
->area
== TEXT_AREA
18981 && ((s
->row
->fill_line_p
18982 && (s
->hl
== DRAW_NORMAL_TEXT
18983 || s
->hl
== DRAW_IMAGE_RAISED
18984 || s
->hl
== DRAW_IMAGE_SUNKEN
))
18985 || s
->hl
== DRAW_MOUSE_FACE
))
18986 s
->extends_to_end_of_line_p
= 1;
18988 /* If S extends its face to the end of the line, set its
18989 background_width to the distance to the right edge of the drawing
18991 if (s
->extends_to_end_of_line_p
)
18992 s
->background_width
= last_x
- s
->x
+ 1;
18994 s
->background_width
= s
->width
;
18998 /* Compute overhangs and x-positions for glyph string S and its
18999 predecessors, or successors. X is the starting x-position for S.
19000 BACKWARD_P non-zero means process predecessors. */
19003 compute_overhangs_and_x (s
, x
, backward_p
)
19004 struct glyph_string
*s
;
19012 if (rif
->compute_glyph_string_overhangs
)
19013 rif
->compute_glyph_string_overhangs (s
);
19023 if (rif
->compute_glyph_string_overhangs
)
19024 rif
->compute_glyph_string_overhangs (s
);
19034 /* The following macros are only called from draw_glyphs below.
19035 They reference the following parameters of that function directly:
19036 `w', `row', `area', and `overlap_p'
19037 as well as the following local variables:
19038 `s', `f', and `hdc' (in W32) */
19041 /* On W32, silently add local `hdc' variable to argument list of
19042 init_glyph_string. */
19043 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19044 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19046 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19047 init_glyph_string (s, char2b, w, row, area, start, hl)
19050 /* Add a glyph string for a stretch glyph to the list of strings
19051 between HEAD and TAIL. START is the index of the stretch glyph in
19052 row area AREA of glyph row ROW. END is the index of the last glyph
19053 in that glyph row area. X is the current output position assigned
19054 to the new glyph string constructed. HL overrides that face of the
19055 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19056 is the right-most x-position of the drawing area. */
19058 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19059 and below -- keep them on one line. */
19060 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19063 s = (struct glyph_string *) alloca (sizeof *s); \
19064 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19065 START = fill_stretch_glyph_string (s, row, area, START, END); \
19066 append_glyph_string (&HEAD, &TAIL, s); \
19072 /* Add a glyph string for an image glyph to the list of strings
19073 between HEAD and TAIL. START is the index of the image glyph in
19074 row area AREA of glyph row ROW. END is the index of the last glyph
19075 in that glyph row area. X is the current output position assigned
19076 to the new glyph string constructed. HL overrides that face of the
19077 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19078 is the right-most x-position of the drawing area. */
19080 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19083 s = (struct glyph_string *) alloca (sizeof *s); \
19084 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19085 fill_image_glyph_string (s); \
19086 append_glyph_string (&HEAD, &TAIL, s); \
19093 /* Add a glyph string for a sequence of character glyphs to the list
19094 of strings between HEAD and TAIL. START is the index of the first
19095 glyph in row area AREA of glyph row ROW that is part of the new
19096 glyph string. END is the index of the last glyph in that glyph row
19097 area. X is the current output position assigned to the new glyph
19098 string constructed. HL overrides that face of the glyph; e.g. it
19099 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19100 right-most x-position of the drawing area. */
19102 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19108 c = (row)->glyphs[area][START].u.ch; \
19109 face_id = (row)->glyphs[area][START].face_id; \
19111 s = (struct glyph_string *) alloca (sizeof *s); \
19112 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19113 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19114 append_glyph_string (&HEAD, &TAIL, s); \
19116 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19121 /* Add a glyph string for a composite sequence to the list of strings
19122 between HEAD and TAIL. START is the index of the first glyph in
19123 row area AREA of glyph row ROW that is part of the new glyph
19124 string. END is the index of the last glyph in that glyph row area.
19125 X is the current output position assigned to the new glyph string
19126 constructed. HL overrides that face of the glyph; e.g. it is
19127 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19128 x-position of the drawing area. */
19130 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19132 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19133 int face_id = (row)->glyphs[area][START].face_id; \
19134 struct face *base_face = FACE_FROM_ID (f, face_id); \
19135 struct composition *cmp = composition_table[cmp_id]; \
19136 int glyph_len = cmp->glyph_len; \
19138 struct face **faces; \
19139 struct glyph_string *first_s = NULL; \
19142 base_face = base_face->ascii_face; \
19143 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19144 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19145 /* At first, fill in `char2b' and `faces'. */ \
19146 for (n = 0; n < glyph_len; n++) \
19148 int c = COMPOSITION_GLYPH (cmp, n); \
19149 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19150 faces[n] = FACE_FROM_ID (f, this_face_id); \
19151 get_char_face_and_encoding (f, c, this_face_id, \
19152 char2b + n, 1, 1); \
19155 /* Make glyph_strings for each glyph sequence that is drawable by \
19156 the same face, and append them to HEAD/TAIL. */ \
19157 for (n = 0; n < cmp->glyph_len;) \
19159 s = (struct glyph_string *) alloca (sizeof *s); \
19160 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19161 append_glyph_string (&(HEAD), &(TAIL), s); \
19169 n = fill_composite_glyph_string (s, faces, overlaps); \
19177 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19178 of AREA of glyph row ROW on window W between indices START and END.
19179 HL overrides the face for drawing glyph strings, e.g. it is
19180 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19181 x-positions of the drawing area.
19183 This is an ugly monster macro construct because we must use alloca
19184 to allocate glyph strings (because draw_glyphs can be called
19185 asynchronously). */
19187 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19190 HEAD = TAIL = NULL; \
19191 while (START < END) \
19193 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19194 switch (first_glyph->type) \
19197 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19201 case COMPOSITE_GLYPH: \
19202 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19206 case STRETCH_GLYPH: \
19207 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19211 case IMAGE_GLYPH: \
19212 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19220 set_glyph_string_background_width (s, START, LAST_X); \
19227 /* Draw glyphs between START and END in AREA of ROW on window W,
19228 starting at x-position X. X is relative to AREA in W. HL is a
19229 face-override with the following meaning:
19231 DRAW_NORMAL_TEXT draw normally
19232 DRAW_CURSOR draw in cursor face
19233 DRAW_MOUSE_FACE draw in mouse face.
19234 DRAW_INVERSE_VIDEO draw in mode line face
19235 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19236 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19238 If OVERLAPS is non-zero, draw only the foreground of characters and
19239 clip to the physical height of ROW. Non-zero value also defines
19240 the overlapping part to be drawn:
19242 OVERLAPS_PRED overlap with preceding rows
19243 OVERLAPS_SUCC overlap with succeeding rows
19244 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19245 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19247 Value is the x-position reached, relative to AREA of W. */
19250 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19253 struct glyph_row
*row
;
19254 enum glyph_row_area area
;
19256 enum draw_glyphs_face hl
;
19259 struct glyph_string
*head
, *tail
;
19260 struct glyph_string
*s
;
19261 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19262 int last_x
, area_width
;
19265 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19268 ALLOCATE_HDC (hdc
, f
);
19270 /* Let's rather be paranoid than getting a SEGV. */
19271 end
= min (end
, row
->used
[area
]);
19272 start
= max (0, start
);
19273 start
= min (end
, start
);
19275 /* Translate X to frame coordinates. Set last_x to the right
19276 end of the drawing area. */
19277 if (row
->full_width_p
)
19279 /* X is relative to the left edge of W, without scroll bars
19281 x
+= WINDOW_LEFT_EDGE_X (w
);
19282 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19286 int area_left
= window_box_left (w
, area
);
19288 area_width
= window_box_width (w
, area
);
19289 last_x
= area_left
+ area_width
;
19292 /* Build a doubly-linked list of glyph_string structures between
19293 head and tail from what we have to draw. Note that the macro
19294 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19295 the reason we use a separate variable `i'. */
19297 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19299 x_reached
= tail
->x
+ tail
->background_width
;
19303 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19304 the row, redraw some glyphs in front or following the glyph
19305 strings built above. */
19306 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19309 struct glyph_string
*h
, *t
;
19311 /* Compute overhangs for all glyph strings. */
19312 if (rif
->compute_glyph_string_overhangs
)
19313 for (s
= head
; s
; s
= s
->next
)
19314 rif
->compute_glyph_string_overhangs (s
);
19316 /* Prepend glyph strings for glyphs in front of the first glyph
19317 string that are overwritten because of the first glyph
19318 string's left overhang. The background of all strings
19319 prepended must be drawn because the first glyph string
19321 i
= left_overwritten (head
);
19325 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19326 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19328 compute_overhangs_and_x (t
, head
->x
, 1);
19329 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19333 /* Prepend glyph strings for glyphs in front of the first glyph
19334 string that overwrite that glyph string because of their
19335 right overhang. For these strings, only the foreground must
19336 be drawn, because it draws over the glyph string at `head'.
19337 The background must not be drawn because this would overwrite
19338 right overhangs of preceding glyphs for which no glyph
19340 i
= left_overwriting (head
);
19344 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19345 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19346 for (s
= h
; s
; s
= s
->next
)
19347 s
->background_filled_p
= 1;
19348 compute_overhangs_and_x (t
, head
->x
, 1);
19349 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19352 /* Append glyphs strings for glyphs following the last glyph
19353 string tail that are overwritten by tail. The background of
19354 these strings has to be drawn because tail's foreground draws
19356 i
= right_overwritten (tail
);
19359 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19360 DRAW_NORMAL_TEXT
, x
, last_x
);
19361 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19362 append_glyph_string_lists (&head
, &tail
, h
, t
);
19366 /* Append glyph strings for glyphs following the last glyph
19367 string tail that overwrite tail. The foreground of such
19368 glyphs has to be drawn because it writes into the background
19369 of tail. The background must not be drawn because it could
19370 paint over the foreground of following glyphs. */
19371 i
= right_overwriting (tail
);
19375 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19376 DRAW_NORMAL_TEXT
, x
, last_x
);
19377 for (s
= h
; s
; s
= s
->next
)
19378 s
->background_filled_p
= 1;
19379 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19380 append_glyph_string_lists (&head
, &tail
, h
, t
);
19382 if (clip_head
|| clip_tail
)
19383 for (s
= head
; s
; s
= s
->next
)
19385 s
->clip_head
= clip_head
;
19386 s
->clip_tail
= clip_tail
;
19390 /* Draw all strings. */
19391 for (s
= head
; s
; s
= s
->next
)
19392 rif
->draw_glyph_string (s
);
19394 if (area
== TEXT_AREA
19395 && !row
->full_width_p
19396 /* When drawing overlapping rows, only the glyph strings'
19397 foreground is drawn, which doesn't erase a cursor
19401 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19402 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19403 : (tail
? tail
->x
+ tail
->background_width
: x
));
19405 int text_left
= window_box_left (w
, TEXT_AREA
);
19409 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19410 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19413 /* Value is the x-position up to which drawn, relative to AREA of W.
19414 This doesn't include parts drawn because of overhangs. */
19415 if (row
->full_width_p
)
19416 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19418 x_reached
-= window_box_left (w
, area
);
19420 RELEASE_HDC (hdc
, f
);
19425 /* Expand row matrix if too narrow. Don't expand if area
19428 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19430 if (!fonts_changed_p \
19431 && (it->glyph_row->glyphs[area] \
19432 < it->glyph_row->glyphs[area + 1])) \
19434 it->w->ncols_scale_factor++; \
19435 fonts_changed_p = 1; \
19439 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19440 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19446 struct glyph
*glyph
;
19447 enum glyph_row_area area
= it
->area
;
19449 xassert (it
->glyph_row
);
19450 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19452 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19453 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19455 glyph
->charpos
= CHARPOS (it
->position
);
19456 glyph
->object
= it
->object
;
19457 glyph
->pixel_width
= it
->pixel_width
;
19458 glyph
->ascent
= it
->ascent
;
19459 glyph
->descent
= it
->descent
;
19460 glyph
->voffset
= it
->voffset
;
19461 glyph
->type
= CHAR_GLYPH
;
19462 glyph
->multibyte_p
= it
->multibyte_p
;
19463 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19464 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19465 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19466 || it
->phys_descent
> it
->descent
);
19467 glyph
->padding_p
= 0;
19468 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19469 glyph
->face_id
= it
->face_id
;
19470 glyph
->u
.ch
= it
->char_to_display
;
19471 glyph
->slice
= null_glyph_slice
;
19472 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19473 ++it
->glyph_row
->used
[area
];
19476 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19479 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19480 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19483 append_composite_glyph (it
)
19486 struct glyph
*glyph
;
19487 enum glyph_row_area area
= it
->area
;
19489 xassert (it
->glyph_row
);
19491 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19492 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19494 glyph
->charpos
= CHARPOS (it
->position
);
19495 glyph
->object
= it
->object
;
19496 glyph
->pixel_width
= it
->pixel_width
;
19497 glyph
->ascent
= it
->ascent
;
19498 glyph
->descent
= it
->descent
;
19499 glyph
->voffset
= it
->voffset
;
19500 glyph
->type
= COMPOSITE_GLYPH
;
19501 glyph
->multibyte_p
= it
->multibyte_p
;
19502 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19503 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19504 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19505 || it
->phys_descent
> it
->descent
);
19506 glyph
->padding_p
= 0;
19507 glyph
->glyph_not_available_p
= 0;
19508 glyph
->face_id
= it
->face_id
;
19509 glyph
->u
.cmp_id
= it
->cmp_id
;
19510 glyph
->slice
= null_glyph_slice
;
19511 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19512 ++it
->glyph_row
->used
[area
];
19515 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19519 /* Change IT->ascent and IT->height according to the setting of
19523 take_vertical_position_into_account (it
)
19528 if (it
->voffset
< 0)
19529 /* Increase the ascent so that we can display the text higher
19531 it
->ascent
-= it
->voffset
;
19533 /* Increase the descent so that we can display the text lower
19535 it
->descent
+= it
->voffset
;
19540 /* Produce glyphs/get display metrics for the image IT is loaded with.
19541 See the description of struct display_iterator in dispextern.h for
19542 an overview of struct display_iterator. */
19545 produce_image_glyph (it
)
19551 struct glyph_slice slice
;
19553 xassert (it
->what
== IT_IMAGE
);
19555 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19557 /* Make sure X resources of the face is loaded. */
19558 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19560 if (it
->image_id
< 0)
19562 /* Fringe bitmap. */
19563 it
->ascent
= it
->phys_ascent
= 0;
19564 it
->descent
= it
->phys_descent
= 0;
19565 it
->pixel_width
= 0;
19570 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19572 /* Make sure X resources of the image is loaded. */
19573 prepare_image_for_display (it
->f
, img
);
19575 slice
.x
= slice
.y
= 0;
19576 slice
.width
= img
->width
;
19577 slice
.height
= img
->height
;
19579 if (INTEGERP (it
->slice
.x
))
19580 slice
.x
= XINT (it
->slice
.x
);
19581 else if (FLOATP (it
->slice
.x
))
19582 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19584 if (INTEGERP (it
->slice
.y
))
19585 slice
.y
= XINT (it
->slice
.y
);
19586 else if (FLOATP (it
->slice
.y
))
19587 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19589 if (INTEGERP (it
->slice
.width
))
19590 slice
.width
= XINT (it
->slice
.width
);
19591 else if (FLOATP (it
->slice
.width
))
19592 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19594 if (INTEGERP (it
->slice
.height
))
19595 slice
.height
= XINT (it
->slice
.height
);
19596 else if (FLOATP (it
->slice
.height
))
19597 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19599 if (slice
.x
>= img
->width
)
19600 slice
.x
= img
->width
;
19601 if (slice
.y
>= img
->height
)
19602 slice
.y
= img
->height
;
19603 if (slice
.x
+ slice
.width
>= img
->width
)
19604 slice
.width
= img
->width
- slice
.x
;
19605 if (slice
.y
+ slice
.height
> img
->height
)
19606 slice
.height
= img
->height
- slice
.y
;
19608 if (slice
.width
== 0 || slice
.height
== 0)
19611 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19613 it
->descent
= slice
.height
- glyph_ascent
;
19615 it
->descent
+= img
->vmargin
;
19616 if (slice
.y
+ slice
.height
== img
->height
)
19617 it
->descent
+= img
->vmargin
;
19618 it
->phys_descent
= it
->descent
;
19620 it
->pixel_width
= slice
.width
;
19622 it
->pixel_width
+= img
->hmargin
;
19623 if (slice
.x
+ slice
.width
== img
->width
)
19624 it
->pixel_width
+= img
->hmargin
;
19626 /* It's quite possible for images to have an ascent greater than
19627 their height, so don't get confused in that case. */
19628 if (it
->descent
< 0)
19631 #if 0 /* this breaks image tiling */
19632 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19633 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19634 if (face_ascent
> it
->ascent
)
19635 it
->ascent
= it
->phys_ascent
= face_ascent
;
19640 if (face
->box
!= FACE_NO_BOX
)
19642 if (face
->box_line_width
> 0)
19645 it
->ascent
+= face
->box_line_width
;
19646 if (slice
.y
+ slice
.height
== img
->height
)
19647 it
->descent
+= face
->box_line_width
;
19650 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19651 it
->pixel_width
+= abs (face
->box_line_width
);
19652 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19653 it
->pixel_width
+= abs (face
->box_line_width
);
19656 take_vertical_position_into_account (it
);
19660 struct glyph
*glyph
;
19661 enum glyph_row_area area
= it
->area
;
19663 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19664 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19666 glyph
->charpos
= CHARPOS (it
->position
);
19667 glyph
->object
= it
->object
;
19668 glyph
->pixel_width
= it
->pixel_width
;
19669 glyph
->ascent
= glyph_ascent
;
19670 glyph
->descent
= it
->descent
;
19671 glyph
->voffset
= it
->voffset
;
19672 glyph
->type
= IMAGE_GLYPH
;
19673 glyph
->multibyte_p
= it
->multibyte_p
;
19674 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19675 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19676 glyph
->overlaps_vertically_p
= 0;
19677 glyph
->padding_p
= 0;
19678 glyph
->glyph_not_available_p
= 0;
19679 glyph
->face_id
= it
->face_id
;
19680 glyph
->u
.img_id
= img
->id
;
19681 glyph
->slice
= slice
;
19682 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19683 ++it
->glyph_row
->used
[area
];
19686 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19691 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19692 of the glyph, WIDTH and HEIGHT are the width and height of the
19693 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19696 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19698 Lisp_Object object
;
19702 struct glyph
*glyph
;
19703 enum glyph_row_area area
= it
->area
;
19705 xassert (ascent
>= 0 && ascent
<= height
);
19707 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19708 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19710 glyph
->charpos
= CHARPOS (it
->position
);
19711 glyph
->object
= object
;
19712 glyph
->pixel_width
= width
;
19713 glyph
->ascent
= ascent
;
19714 glyph
->descent
= height
- ascent
;
19715 glyph
->voffset
= it
->voffset
;
19716 glyph
->type
= STRETCH_GLYPH
;
19717 glyph
->multibyte_p
= it
->multibyte_p
;
19718 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19719 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19720 glyph
->overlaps_vertically_p
= 0;
19721 glyph
->padding_p
= 0;
19722 glyph
->glyph_not_available_p
= 0;
19723 glyph
->face_id
= it
->face_id
;
19724 glyph
->u
.stretch
.ascent
= ascent
;
19725 glyph
->u
.stretch
.height
= height
;
19726 glyph
->slice
= null_glyph_slice
;
19727 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19728 ++it
->glyph_row
->used
[area
];
19731 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19735 /* Produce a stretch glyph for iterator IT. IT->object is the value
19736 of the glyph property displayed. The value must be a list
19737 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19740 1. `:width WIDTH' specifies that the space should be WIDTH *
19741 canonical char width wide. WIDTH may be an integer or floating
19744 2. `:relative-width FACTOR' specifies that the width of the stretch
19745 should be computed from the width of the first character having the
19746 `glyph' property, and should be FACTOR times that width.
19748 3. `:align-to HPOS' specifies that the space should be wide enough
19749 to reach HPOS, a value in canonical character units.
19751 Exactly one of the above pairs must be present.
19753 4. `:height HEIGHT' specifies that the height of the stretch produced
19754 should be HEIGHT, measured in canonical character units.
19756 5. `:relative-height FACTOR' specifies that the height of the
19757 stretch should be FACTOR times the height of the characters having
19758 the glyph property.
19760 Either none or exactly one of 4 or 5 must be present.
19762 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19763 of the stretch should be used for the ascent of the stretch.
19764 ASCENT must be in the range 0 <= ASCENT <= 100. */
19767 produce_stretch_glyph (it
)
19770 /* (space :width WIDTH :height HEIGHT ...) */
19771 Lisp_Object prop
, plist
;
19772 int width
= 0, height
= 0, align_to
= -1;
19773 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19776 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19777 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19779 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19781 /* List should start with `space'. */
19782 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19783 plist
= XCDR (it
->object
);
19785 /* Compute the width of the stretch. */
19786 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19787 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19789 /* Absolute width `:width WIDTH' specified and valid. */
19790 zero_width_ok_p
= 1;
19793 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19796 /* Relative width `:relative-width FACTOR' specified and valid.
19797 Compute the width of the characters having the `glyph'
19800 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19803 if (it
->multibyte_p
)
19805 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19806 - IT_BYTEPOS (*it
));
19807 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19810 it2
.c
= *p
, it2
.len
= 1;
19812 it2
.glyph_row
= NULL
;
19813 it2
.what
= IT_CHARACTER
;
19814 x_produce_glyphs (&it2
);
19815 width
= NUMVAL (prop
) * it2
.pixel_width
;
19817 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19818 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19820 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19821 align_to
= (align_to
< 0
19823 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19824 else if (align_to
< 0)
19825 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19826 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19827 zero_width_ok_p
= 1;
19830 /* Nothing specified -> width defaults to canonical char width. */
19831 width
= FRAME_COLUMN_WIDTH (it
->f
);
19833 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19836 /* Compute height. */
19837 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19838 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19841 zero_height_ok_p
= 1;
19843 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19845 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19847 height
= FONT_HEIGHT (font
);
19849 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19852 /* Compute percentage of height used for ascent. If
19853 `:ascent ASCENT' is present and valid, use that. Otherwise,
19854 derive the ascent from the font in use. */
19855 if (prop
= Fplist_get (plist
, QCascent
),
19856 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19857 ascent
= height
* NUMVAL (prop
) / 100.0;
19858 else if (!NILP (prop
)
19859 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19860 ascent
= min (max (0, (int)tem
), height
);
19862 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19864 if (width
> 0 && !it
->truncate_lines_p
19865 && it
->current_x
+ width
> it
->last_visible_x
)
19866 width
= it
->last_visible_x
- it
->current_x
- 1;
19868 if (width
> 0 && height
> 0 && it
->glyph_row
)
19870 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19871 if (!STRINGP (object
))
19872 object
= it
->w
->buffer
;
19873 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19876 it
->pixel_width
= width
;
19877 it
->ascent
= it
->phys_ascent
= ascent
;
19878 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19879 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19881 take_vertical_position_into_account (it
);
19884 /* Get line-height and line-spacing property at point.
19885 If line-height has format (HEIGHT TOTAL), return TOTAL
19886 in TOTAL_HEIGHT. */
19889 get_line_height_property (it
, prop
)
19893 Lisp_Object position
;
19895 if (STRINGP (it
->object
))
19896 position
= make_number (IT_STRING_CHARPOS (*it
));
19897 else if (BUFFERP (it
->object
))
19898 position
= make_number (IT_CHARPOS (*it
));
19902 return Fget_char_property (position
, prop
, it
->object
);
19905 /* Calculate line-height and line-spacing properties.
19906 An integer value specifies explicit pixel value.
19907 A float value specifies relative value to current face height.
19908 A cons (float . face-name) specifies relative value to
19909 height of specified face font.
19911 Returns height in pixels, or nil. */
19915 calc_line_height_property (it
, val
, font
, boff
, override
)
19919 int boff
, override
;
19921 Lisp_Object face_name
= Qnil
;
19922 int ascent
, descent
, height
;
19924 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19929 face_name
= XCAR (val
);
19931 if (!NUMBERP (val
))
19932 val
= make_number (1);
19933 if (NILP (face_name
))
19935 height
= it
->ascent
+ it
->descent
;
19940 if (NILP (face_name
))
19942 font
= FRAME_FONT (it
->f
);
19943 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19945 else if (EQ (face_name
, Qt
))
19953 struct font_info
*font_info
;
19955 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19957 return make_number (-1);
19959 face
= FACE_FROM_ID (it
->f
, face_id
);
19962 return make_number (-1);
19964 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19965 boff
= font_info
->baseline_offset
;
19966 if (font_info
->vertical_centering
)
19967 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19970 ascent
= FONT_BASE (font
) + boff
;
19971 descent
= FONT_DESCENT (font
) - boff
;
19975 it
->override_ascent
= ascent
;
19976 it
->override_descent
= descent
;
19977 it
->override_boff
= boff
;
19980 height
= ascent
+ descent
;
19984 height
= (int)(XFLOAT_DATA (val
) * height
);
19985 else if (INTEGERP (val
))
19986 height
*= XINT (val
);
19988 return make_number (height
);
19993 Produce glyphs/get display metrics for the display element IT is
19994 loaded with. See the description of struct it in dispextern.h
19995 for an overview of struct it. */
19998 x_produce_glyphs (it
)
20001 int extra_line_spacing
= it
->extra_line_spacing
;
20003 it
->glyph_not_available_p
= 0;
20005 if (it
->what
== IT_CHARACTER
)
20009 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20011 int font_not_found_p
;
20012 struct font_info
*font_info
;
20013 int boff
; /* baseline offset */
20014 /* We may change it->multibyte_p upon unibyte<->multibyte
20015 conversion. So, save the current value now and restore it
20018 Note: It seems that we don't have to record multibyte_p in
20019 struct glyph because the character code itself tells if or
20020 not the character is multibyte. Thus, in the future, we must
20021 consider eliminating the field `multibyte_p' in the struct
20023 int saved_multibyte_p
= it
->multibyte_p
;
20025 /* Maybe translate single-byte characters to multibyte, or the
20027 it
->char_to_display
= it
->c
;
20028 if (!ASCII_BYTE_P (it
->c
))
20030 if (unibyte_display_via_language_environment
20031 && SINGLE_BYTE_CHAR_P (it
->c
)
20033 || !NILP (Vnonascii_translation_table
)))
20035 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20036 it
->multibyte_p
= 1;
20037 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20038 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20040 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20041 && !it
->multibyte_p
)
20043 it
->multibyte_p
= 1;
20044 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20045 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20049 /* Get font to use. Encode IT->char_to_display. */
20050 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20051 &char2b
, it
->multibyte_p
, 0);
20054 /* When no suitable font found, use the default font. */
20055 font_not_found_p
= font
== NULL
;
20056 if (font_not_found_p
)
20058 font
= FRAME_FONT (it
->f
);
20059 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20064 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20065 boff
= font_info
->baseline_offset
;
20066 if (font_info
->vertical_centering
)
20067 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20070 if (it
->char_to_display
>= ' '
20071 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20073 /* Either unibyte or ASCII. */
20078 pcm
= rif
->per_char_metric (font
, &char2b
,
20079 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20081 if (it
->override_ascent
>= 0)
20083 it
->ascent
= it
->override_ascent
;
20084 it
->descent
= it
->override_descent
;
20085 boff
= it
->override_boff
;
20089 it
->ascent
= FONT_BASE (font
) + boff
;
20090 it
->descent
= FONT_DESCENT (font
) - boff
;
20095 it
->phys_ascent
= pcm
->ascent
+ boff
;
20096 it
->phys_descent
= pcm
->descent
- boff
;
20097 it
->pixel_width
= pcm
->width
;
20101 it
->glyph_not_available_p
= 1;
20102 it
->phys_ascent
= it
->ascent
;
20103 it
->phys_descent
= it
->descent
;
20104 it
->pixel_width
= FONT_WIDTH (font
);
20107 if (it
->constrain_row_ascent_descent_p
)
20109 if (it
->descent
> it
->max_descent
)
20111 it
->ascent
+= it
->descent
- it
->max_descent
;
20112 it
->descent
= it
->max_descent
;
20114 if (it
->ascent
> it
->max_ascent
)
20116 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20117 it
->ascent
= it
->max_ascent
;
20119 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20120 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20121 extra_line_spacing
= 0;
20124 /* If this is a space inside a region of text with
20125 `space-width' property, change its width. */
20126 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20128 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20130 /* If face has a box, add the box thickness to the character
20131 height. If character has a box line to the left and/or
20132 right, add the box line width to the character's width. */
20133 if (face
->box
!= FACE_NO_BOX
)
20135 int thick
= face
->box_line_width
;
20139 it
->ascent
+= thick
;
20140 it
->descent
+= thick
;
20145 if (it
->start_of_box_run_p
)
20146 it
->pixel_width
+= thick
;
20147 if (it
->end_of_box_run_p
)
20148 it
->pixel_width
+= thick
;
20151 /* If face has an overline, add the height of the overline
20152 (1 pixel) and a 1 pixel margin to the character height. */
20153 if (face
->overline_p
)
20156 if (it
->constrain_row_ascent_descent_p
)
20158 if (it
->ascent
> it
->max_ascent
)
20159 it
->ascent
= it
->max_ascent
;
20160 if (it
->descent
> it
->max_descent
)
20161 it
->descent
= it
->max_descent
;
20164 take_vertical_position_into_account (it
);
20166 /* If we have to actually produce glyphs, do it. */
20171 /* Translate a space with a `space-width' property
20172 into a stretch glyph. */
20173 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20174 / FONT_HEIGHT (font
));
20175 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20176 it
->ascent
+ it
->descent
, ascent
);
20181 /* If characters with lbearing or rbearing are displayed
20182 in this line, record that fact in a flag of the
20183 glyph row. This is used to optimize X output code. */
20184 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20185 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20188 else if (it
->char_to_display
== '\n')
20190 /* A newline has no width but we need the height of the line.
20191 But if previous part of the line set a height, don't
20192 increase that height */
20194 Lisp_Object height
;
20195 Lisp_Object total_height
= Qnil
;
20197 it
->override_ascent
= -1;
20198 it
->pixel_width
= 0;
20201 height
= get_line_height_property(it
, Qline_height
);
20202 /* Split (line-height total-height) list */
20204 && CONSP (XCDR (height
))
20205 && NILP (XCDR (XCDR (height
))))
20207 total_height
= XCAR (XCDR (height
));
20208 height
= XCAR (height
);
20210 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20212 if (it
->override_ascent
>= 0)
20214 it
->ascent
= it
->override_ascent
;
20215 it
->descent
= it
->override_descent
;
20216 boff
= it
->override_boff
;
20220 it
->ascent
= FONT_BASE (font
) + boff
;
20221 it
->descent
= FONT_DESCENT (font
) - boff
;
20224 if (EQ (height
, Qt
))
20226 if (it
->descent
> it
->max_descent
)
20228 it
->ascent
+= it
->descent
- it
->max_descent
;
20229 it
->descent
= it
->max_descent
;
20231 if (it
->ascent
> it
->max_ascent
)
20233 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20234 it
->ascent
= it
->max_ascent
;
20236 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20237 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20238 it
->constrain_row_ascent_descent_p
= 1;
20239 extra_line_spacing
= 0;
20243 Lisp_Object spacing
;
20245 it
->phys_ascent
= it
->ascent
;
20246 it
->phys_descent
= it
->descent
;
20248 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20249 && face
->box
!= FACE_NO_BOX
20250 && face
->box_line_width
> 0)
20252 it
->ascent
+= face
->box_line_width
;
20253 it
->descent
+= face
->box_line_width
;
20256 && XINT (height
) > it
->ascent
+ it
->descent
)
20257 it
->ascent
= XINT (height
) - it
->descent
;
20259 if (!NILP (total_height
))
20260 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20263 spacing
= get_line_height_property(it
, Qline_spacing
);
20264 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20266 if (INTEGERP (spacing
))
20268 extra_line_spacing
= XINT (spacing
);
20269 if (!NILP (total_height
))
20270 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20274 else if (it
->char_to_display
== '\t')
20276 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20277 int x
= it
->current_x
+ it
->continuation_lines_width
;
20278 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20280 /* If the distance from the current position to the next tab
20281 stop is less than a space character width, use the
20282 tab stop after that. */
20283 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20284 next_tab_x
+= tab_width
;
20286 it
->pixel_width
= next_tab_x
- x
;
20288 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20289 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20293 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20294 it
->ascent
+ it
->descent
, it
->ascent
);
20299 /* A multi-byte character. Assume that the display width of the
20300 character is the width of the character multiplied by the
20301 width of the font. */
20303 /* If we found a font, this font should give us the right
20304 metrics. If we didn't find a font, use the frame's
20305 default font and calculate the width of the character
20306 from the charset width; this is what old redisplay code
20309 pcm
= rif
->per_char_metric (font
, &char2b
,
20310 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20312 if (font_not_found_p
|| !pcm
)
20314 int charset
= CHAR_CHARSET (it
->char_to_display
);
20316 it
->glyph_not_available_p
= 1;
20317 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20318 * CHARSET_WIDTH (charset
));
20319 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20320 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20324 it
->pixel_width
= pcm
->width
;
20325 it
->phys_ascent
= pcm
->ascent
+ boff
;
20326 it
->phys_descent
= pcm
->descent
- boff
;
20328 && (pcm
->lbearing
< 0
20329 || pcm
->rbearing
> pcm
->width
))
20330 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20333 it
->ascent
= FONT_BASE (font
) + boff
;
20334 it
->descent
= FONT_DESCENT (font
) - boff
;
20335 if (face
->box
!= FACE_NO_BOX
)
20337 int thick
= face
->box_line_width
;
20341 it
->ascent
+= thick
;
20342 it
->descent
+= thick
;
20347 if (it
->start_of_box_run_p
)
20348 it
->pixel_width
+= thick
;
20349 if (it
->end_of_box_run_p
)
20350 it
->pixel_width
+= thick
;
20353 /* If face has an overline, add the height of the overline
20354 (1 pixel) and a 1 pixel margin to the character height. */
20355 if (face
->overline_p
)
20358 take_vertical_position_into_account (it
);
20363 it
->multibyte_p
= saved_multibyte_p
;
20365 else if (it
->what
== IT_COMPOSITION
)
20367 /* Note: A composition is represented as one glyph in the
20368 glyph matrix. There are no padding glyphs. */
20371 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20373 int font_not_found_p
;
20374 struct font_info
*font_info
;
20375 int boff
; /* baseline offset */
20376 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20378 /* Maybe translate single-byte characters to multibyte. */
20379 it
->char_to_display
= it
->c
;
20380 if (unibyte_display_via_language_environment
20381 && SINGLE_BYTE_CHAR_P (it
->c
)
20384 && !NILP (Vnonascii_translation_table
))))
20386 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20389 /* Get face and font to use. Encode IT->char_to_display. */
20390 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20391 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20392 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20393 &char2b
, it
->multibyte_p
, 0);
20396 /* When no suitable font found, use the default font. */
20397 font_not_found_p
= font
== NULL
;
20398 if (font_not_found_p
)
20400 font
= FRAME_FONT (it
->f
);
20401 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20406 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20407 boff
= font_info
->baseline_offset
;
20408 if (font_info
->vertical_centering
)
20409 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20412 /* There are no padding glyphs, so there is only one glyph to
20413 produce for the composition. Important is that pixel_width,
20414 ascent and descent are the values of what is drawn by
20415 draw_glyphs (i.e. the values of the overall glyphs composed). */
20418 /* If we have not yet calculated pixel size data of glyphs of
20419 the composition for the current face font, calculate them
20420 now. Theoretically, we have to check all fonts for the
20421 glyphs, but that requires much time and memory space. So,
20422 here we check only the font of the first glyph. This leads
20423 to incorrect display very rarely, and C-l (recenter) can
20424 correct the display anyway. */
20425 if (cmp
->font
!= (void *) font
)
20427 /* Ascent and descent of the font of the first character of
20428 this composition (adjusted by baseline offset). Ascent
20429 and descent of overall glyphs should not be less than
20430 them respectively. */
20431 int font_ascent
= FONT_BASE (font
) + boff
;
20432 int font_descent
= FONT_DESCENT (font
) - boff
;
20433 /* Bounding box of the overall glyphs. */
20434 int leftmost
, rightmost
, lowest
, highest
;
20435 int i
, width
, ascent
, descent
;
20437 cmp
->font
= (void *) font
;
20439 /* Initialize the bounding box. */
20441 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20442 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20444 width
= pcm
->width
;
20445 ascent
= pcm
->ascent
;
20446 descent
= pcm
->descent
;
20450 width
= FONT_WIDTH (font
);
20451 ascent
= FONT_BASE (font
);
20452 descent
= FONT_DESCENT (font
);
20456 lowest
= - descent
+ boff
;
20457 highest
= ascent
+ boff
;
20461 && font_info
->default_ascent
20462 && CHAR_TABLE_P (Vuse_default_ascent
)
20463 && !NILP (Faref (Vuse_default_ascent
,
20464 make_number (it
->char_to_display
))))
20465 highest
= font_info
->default_ascent
+ boff
;
20467 /* Draw the first glyph at the normal position. It may be
20468 shifted to right later if some other glyphs are drawn at
20470 cmp
->offsets
[0] = 0;
20471 cmp
->offsets
[1] = boff
;
20473 /* Set cmp->offsets for the remaining glyphs. */
20474 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20476 int left
, right
, btm
, top
;
20477 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20478 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20480 face
= FACE_FROM_ID (it
->f
, face_id
);
20481 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20482 &char2b
, it
->multibyte_p
, 0);
20486 font
= FRAME_FONT (it
->f
);
20487 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20493 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20494 boff
= font_info
->baseline_offset
;
20495 if (font_info
->vertical_centering
)
20496 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20500 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20501 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20503 width
= pcm
->width
;
20504 ascent
= pcm
->ascent
;
20505 descent
= pcm
->descent
;
20509 width
= FONT_WIDTH (font
);
20514 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20516 /* Relative composition with or without
20517 alternate chars. */
20518 left
= (leftmost
+ rightmost
- width
) / 2;
20519 btm
= - descent
+ boff
;
20520 if (font_info
&& font_info
->relative_compose
20521 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20522 || NILP (Faref (Vignore_relative_composition
,
20523 make_number (ch
)))))
20526 if (- descent
>= font_info
->relative_compose
)
20527 /* One extra pixel between two glyphs. */
20529 else if (ascent
<= 0)
20530 /* One extra pixel between two glyphs. */
20531 btm
= lowest
- 1 - ascent
- descent
;
20536 /* A composition rule is specified by an integer
20537 value that encodes global and new reference
20538 points (GREF and NREF). GREF and NREF are
20539 specified by numbers as below:
20541 0---1---2 -- ascent
20545 9--10--11 -- center
20547 ---3---4---5--- baseline
20549 6---7---8 -- descent
20551 int rule
= COMPOSITION_RULE (cmp
, i
);
20552 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20554 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20555 grefx
= gref
% 3, nrefx
= nref
% 3;
20556 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20559 + grefx
* (rightmost
- leftmost
) / 2
20560 - nrefx
* width
/ 2);
20561 btm
= ((grefy
== 0 ? highest
20563 : grefy
== 2 ? lowest
20564 : (highest
+ lowest
) / 2)
20565 - (nrefy
== 0 ? ascent
+ descent
20566 : nrefy
== 1 ? descent
- boff
20568 : (ascent
+ descent
) / 2));
20571 cmp
->offsets
[i
* 2] = left
;
20572 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20574 /* Update the bounding box of the overall glyphs. */
20575 right
= left
+ width
;
20576 top
= btm
+ descent
+ ascent
;
20577 if (left
< leftmost
)
20579 if (right
> rightmost
)
20587 /* If there are glyphs whose x-offsets are negative,
20588 shift all glyphs to the right and make all x-offsets
20592 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20593 cmp
->offsets
[i
* 2] -= leftmost
;
20594 rightmost
-= leftmost
;
20597 cmp
->pixel_width
= rightmost
;
20598 cmp
->ascent
= highest
;
20599 cmp
->descent
= - lowest
;
20600 if (cmp
->ascent
< font_ascent
)
20601 cmp
->ascent
= font_ascent
;
20602 if (cmp
->descent
< font_descent
)
20603 cmp
->descent
= font_descent
;
20606 it
->pixel_width
= cmp
->pixel_width
;
20607 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20608 it
->descent
= it
->phys_descent
= cmp
->descent
;
20610 if (face
->box
!= FACE_NO_BOX
)
20612 int thick
= face
->box_line_width
;
20616 it
->ascent
+= thick
;
20617 it
->descent
+= thick
;
20622 if (it
->start_of_box_run_p
)
20623 it
->pixel_width
+= thick
;
20624 if (it
->end_of_box_run_p
)
20625 it
->pixel_width
+= thick
;
20628 /* If face has an overline, add the height of the overline
20629 (1 pixel) and a 1 pixel margin to the character height. */
20630 if (face
->overline_p
)
20633 take_vertical_position_into_account (it
);
20636 append_composite_glyph (it
);
20638 else if (it
->what
== IT_IMAGE
)
20639 produce_image_glyph (it
);
20640 else if (it
->what
== IT_STRETCH
)
20641 produce_stretch_glyph (it
);
20643 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20644 because this isn't true for images with `:ascent 100'. */
20645 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20646 if (it
->area
== TEXT_AREA
)
20647 it
->current_x
+= it
->pixel_width
;
20649 if (extra_line_spacing
> 0)
20651 it
->descent
+= extra_line_spacing
;
20652 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20653 it
->max_extra_line_spacing
= extra_line_spacing
;
20656 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20657 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20658 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20659 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20663 Output LEN glyphs starting at START at the nominal cursor position.
20664 Advance the nominal cursor over the text. The global variable
20665 updated_window contains the window being updated, updated_row is
20666 the glyph row being updated, and updated_area is the area of that
20667 row being updated. */
20670 x_write_glyphs (start
, len
)
20671 struct glyph
*start
;
20676 xassert (updated_window
&& updated_row
);
20679 /* Write glyphs. */
20681 hpos
= start
- updated_row
->glyphs
[updated_area
];
20682 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20683 updated_row
, updated_area
,
20685 DRAW_NORMAL_TEXT
, 0);
20687 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20688 if (updated_area
== TEXT_AREA
20689 && updated_window
->phys_cursor_on_p
20690 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20691 && updated_window
->phys_cursor
.hpos
>= hpos
20692 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20693 updated_window
->phys_cursor_on_p
= 0;
20697 /* Advance the output cursor. */
20698 output_cursor
.hpos
+= len
;
20699 output_cursor
.x
= x
;
20704 Insert LEN glyphs from START at the nominal cursor position. */
20707 x_insert_glyphs (start
, len
)
20708 struct glyph
*start
;
20713 int line_height
, shift_by_width
, shifted_region_width
;
20714 struct glyph_row
*row
;
20715 struct glyph
*glyph
;
20716 int frame_x
, frame_y
, hpos
;
20718 xassert (updated_window
&& updated_row
);
20720 w
= updated_window
;
20721 f
= XFRAME (WINDOW_FRAME (w
));
20723 /* Get the height of the line we are in. */
20725 line_height
= row
->height
;
20727 /* Get the width of the glyphs to insert. */
20728 shift_by_width
= 0;
20729 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20730 shift_by_width
+= glyph
->pixel_width
;
20732 /* Get the width of the region to shift right. */
20733 shifted_region_width
= (window_box_width (w
, updated_area
)
20738 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20739 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20741 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20742 line_height
, shift_by_width
);
20744 /* Write the glyphs. */
20745 hpos
= start
- row
->glyphs
[updated_area
];
20746 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20748 DRAW_NORMAL_TEXT
, 0);
20750 /* Advance the output cursor. */
20751 output_cursor
.hpos
+= len
;
20752 output_cursor
.x
+= shift_by_width
;
20758 Erase the current text line from the nominal cursor position
20759 (inclusive) to pixel column TO_X (exclusive). The idea is that
20760 everything from TO_X onward is already erased.
20762 TO_X is a pixel position relative to updated_area of
20763 updated_window. TO_X == -1 means clear to the end of this area. */
20766 x_clear_end_of_line (to_x
)
20770 struct window
*w
= updated_window
;
20771 int max_x
, min_y
, max_y
;
20772 int from_x
, from_y
, to_y
;
20774 xassert (updated_window
&& updated_row
);
20775 f
= XFRAME (w
->frame
);
20777 if (updated_row
->full_width_p
)
20778 max_x
= WINDOW_TOTAL_WIDTH (w
);
20780 max_x
= window_box_width (w
, updated_area
);
20781 max_y
= window_text_bottom_y (w
);
20783 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20784 of window. For TO_X > 0, truncate to end of drawing area. */
20790 to_x
= min (to_x
, max_x
);
20792 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20794 /* Notice if the cursor will be cleared by this operation. */
20795 if (!updated_row
->full_width_p
)
20796 notice_overwritten_cursor (w
, updated_area
,
20797 output_cursor
.x
, -1,
20799 MATRIX_ROW_BOTTOM_Y (updated_row
));
20801 from_x
= output_cursor
.x
;
20803 /* Translate to frame coordinates. */
20804 if (updated_row
->full_width_p
)
20806 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20807 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20811 int area_left
= window_box_left (w
, updated_area
);
20812 from_x
+= area_left
;
20816 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20817 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20818 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20820 /* Prevent inadvertently clearing to end of the X window. */
20821 if (to_x
> from_x
&& to_y
> from_y
)
20824 rif
->clear_frame_area (f
, from_x
, from_y
,
20825 to_x
- from_x
, to_y
- from_y
);
20830 #endif /* HAVE_WINDOW_SYSTEM */
20834 /***********************************************************************
20836 ***********************************************************************/
20838 /* Value is the internal representation of the specified cursor type
20839 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20840 of the bar cursor. */
20842 static enum text_cursor_kinds
20843 get_specified_cursor_type (arg
, width
)
20847 enum text_cursor_kinds type
;
20852 if (EQ (arg
, Qbox
))
20853 return FILLED_BOX_CURSOR
;
20855 if (EQ (arg
, Qhollow
))
20856 return HOLLOW_BOX_CURSOR
;
20858 if (EQ (arg
, Qbar
))
20865 && EQ (XCAR (arg
), Qbar
)
20866 && INTEGERP (XCDR (arg
))
20867 && XINT (XCDR (arg
)) >= 0)
20869 *width
= XINT (XCDR (arg
));
20873 if (EQ (arg
, Qhbar
))
20876 return HBAR_CURSOR
;
20880 && EQ (XCAR (arg
), Qhbar
)
20881 && INTEGERP (XCDR (arg
))
20882 && XINT (XCDR (arg
)) >= 0)
20884 *width
= XINT (XCDR (arg
));
20885 return HBAR_CURSOR
;
20888 /* Treat anything unknown as "hollow box cursor".
20889 It was bad to signal an error; people have trouble fixing
20890 .Xdefaults with Emacs, when it has something bad in it. */
20891 type
= HOLLOW_BOX_CURSOR
;
20896 /* Set the default cursor types for specified frame. */
20898 set_frame_cursor_types (f
, arg
)
20905 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20906 FRAME_CURSOR_WIDTH (f
) = width
;
20908 /* By default, set up the blink-off state depending on the on-state. */
20910 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20913 FRAME_BLINK_OFF_CURSOR (f
)
20914 = get_specified_cursor_type (XCDR (tem
), &width
);
20915 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20918 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20922 /* Return the cursor we want to be displayed in window W. Return
20923 width of bar/hbar cursor through WIDTH arg. Return with
20924 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20925 (i.e. if the `system caret' should track this cursor).
20927 In a mini-buffer window, we want the cursor only to appear if we
20928 are reading input from this window. For the selected window, we
20929 want the cursor type given by the frame parameter or buffer local
20930 setting of cursor-type. If explicitly marked off, draw no cursor.
20931 In all other cases, we want a hollow box cursor. */
20933 static enum text_cursor_kinds
20934 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20936 struct glyph
*glyph
;
20938 int *active_cursor
;
20940 struct frame
*f
= XFRAME (w
->frame
);
20941 struct buffer
*b
= XBUFFER (w
->buffer
);
20942 int cursor_type
= DEFAULT_CURSOR
;
20943 Lisp_Object alt_cursor
;
20944 int non_selected
= 0;
20946 *active_cursor
= 1;
20949 if (cursor_in_echo_area
20950 && FRAME_HAS_MINIBUF_P (f
)
20951 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20953 if (w
== XWINDOW (echo_area_window
))
20955 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
20957 *width
= FRAME_CURSOR_WIDTH (f
);
20958 return FRAME_DESIRED_CURSOR (f
);
20961 return get_specified_cursor_type (b
->cursor_type
, width
);
20964 *active_cursor
= 0;
20968 /* Nonselected window or nonselected frame. */
20969 else if (w
!= XWINDOW (f
->selected_window
)
20970 #ifdef HAVE_WINDOW_SYSTEM
20971 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20975 *active_cursor
= 0;
20977 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20983 /* Never display a cursor in a window in which cursor-type is nil. */
20984 if (NILP (b
->cursor_type
))
20987 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20990 alt_cursor
= b
->cursor_in_non_selected_windows
;
20991 return get_specified_cursor_type (alt_cursor
, width
);
20994 /* Get the normal cursor type for this window. */
20995 if (EQ (b
->cursor_type
, Qt
))
20997 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20998 *width
= FRAME_CURSOR_WIDTH (f
);
21001 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21003 /* Use normal cursor if not blinked off. */
21004 if (!w
->cursor_off_p
)
21006 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
21007 if (cursor_type
== FILLED_BOX_CURSOR
)
21008 cursor_type
= HOLLOW_BOX_CURSOR
;
21010 return cursor_type
;
21013 /* Cursor is blinked off, so determine how to "toggle" it. */
21015 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21016 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21017 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21019 /* Then see if frame has specified a specific blink off cursor type. */
21020 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21022 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21023 return FRAME_BLINK_OFF_CURSOR (f
);
21027 /* Some people liked having a permanently visible blinking cursor,
21028 while others had very strong opinions against it. So it was
21029 decided to remove it. KFS 2003-09-03 */
21031 /* Finally perform built-in cursor blinking:
21032 filled box <-> hollow box
21033 wide [h]bar <-> narrow [h]bar
21034 narrow [h]bar <-> no cursor
21035 other type <-> no cursor */
21037 if (cursor_type
== FILLED_BOX_CURSOR
)
21038 return HOLLOW_BOX_CURSOR
;
21040 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21043 return cursor_type
;
21051 #ifdef HAVE_WINDOW_SYSTEM
21053 /* Notice when the text cursor of window W has been completely
21054 overwritten by a drawing operation that outputs glyphs in AREA
21055 starting at X0 and ending at X1 in the line starting at Y0 and
21056 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21057 the rest of the line after X0 has been written. Y coordinates
21058 are window-relative. */
21061 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21063 enum glyph_row_area area
;
21064 int x0
, y0
, x1
, y1
;
21066 int cx0
, cx1
, cy0
, cy1
;
21067 struct glyph_row
*row
;
21069 if (!w
->phys_cursor_on_p
)
21071 if (area
!= TEXT_AREA
)
21074 if (w
->phys_cursor
.vpos
< 0
21075 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21076 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21077 !(row
->enabled_p
&& row
->displays_text_p
)))
21080 if (row
->cursor_in_fringe_p
)
21082 row
->cursor_in_fringe_p
= 0;
21083 draw_fringe_bitmap (w
, row
, 0);
21084 w
->phys_cursor_on_p
= 0;
21088 cx0
= w
->phys_cursor
.x
;
21089 cx1
= cx0
+ w
->phys_cursor_width
;
21090 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21093 /* The cursor image will be completely removed from the
21094 screen if the output area intersects the cursor area in
21095 y-direction. When we draw in [y0 y1[, and some part of
21096 the cursor is at y < y0, that part must have been drawn
21097 before. When scrolling, the cursor is erased before
21098 actually scrolling, so we don't come here. When not
21099 scrolling, the rows above the old cursor row must have
21100 changed, and in this case these rows must have written
21101 over the cursor image.
21103 Likewise if part of the cursor is below y1, with the
21104 exception of the cursor being in the first blank row at
21105 the buffer and window end because update_text_area
21106 doesn't draw that row. (Except when it does, but
21107 that's handled in update_text_area.) */
21109 cy0
= w
->phys_cursor
.y
;
21110 cy1
= cy0
+ w
->phys_cursor_height
;
21111 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21114 w
->phys_cursor_on_p
= 0;
21117 #endif /* HAVE_WINDOW_SYSTEM */
21120 /************************************************************************
21122 ************************************************************************/
21124 #ifdef HAVE_WINDOW_SYSTEM
21127 Fix the display of area AREA of overlapping row ROW in window W
21128 with respect to the overlapping part OVERLAPS. */
21131 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21133 struct glyph_row
*row
;
21134 enum glyph_row_area area
;
21142 for (i
= 0; i
< row
->used
[area
];)
21144 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21146 int start
= i
, start_x
= x
;
21150 x
+= row
->glyphs
[area
][i
].pixel_width
;
21153 while (i
< row
->used
[area
]
21154 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21156 draw_glyphs (w
, start_x
, row
, area
,
21158 DRAW_NORMAL_TEXT
, overlaps
);
21162 x
+= row
->glyphs
[area
][i
].pixel_width
;
21172 Draw the cursor glyph of window W in glyph row ROW. See the
21173 comment of draw_glyphs for the meaning of HL. */
21176 draw_phys_cursor_glyph (w
, row
, hl
)
21178 struct glyph_row
*row
;
21179 enum draw_glyphs_face hl
;
21181 /* If cursor hpos is out of bounds, don't draw garbage. This can
21182 happen in mini-buffer windows when switching between echo area
21183 glyphs and mini-buffer. */
21184 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21186 int on_p
= w
->phys_cursor_on_p
;
21188 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21189 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21191 w
->phys_cursor_on_p
= on_p
;
21193 if (hl
== DRAW_CURSOR
)
21194 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21195 /* When we erase the cursor, and ROW is overlapped by other
21196 rows, make sure that these overlapping parts of other rows
21198 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21200 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21202 if (row
> w
->current_matrix
->rows
21203 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21204 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21205 OVERLAPS_ERASED_CURSOR
);
21207 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21208 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21209 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21210 OVERLAPS_ERASED_CURSOR
);
21217 Erase the image of a cursor of window W from the screen. */
21220 erase_phys_cursor (w
)
21223 struct frame
*f
= XFRAME (w
->frame
);
21224 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21225 int hpos
= w
->phys_cursor
.hpos
;
21226 int vpos
= w
->phys_cursor
.vpos
;
21227 int mouse_face_here_p
= 0;
21228 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21229 struct glyph_row
*cursor_row
;
21230 struct glyph
*cursor_glyph
;
21231 enum draw_glyphs_face hl
;
21233 /* No cursor displayed or row invalidated => nothing to do on the
21235 if (w
->phys_cursor_type
== NO_CURSOR
)
21236 goto mark_cursor_off
;
21238 /* VPOS >= active_glyphs->nrows means that window has been resized.
21239 Don't bother to erase the cursor. */
21240 if (vpos
>= active_glyphs
->nrows
)
21241 goto mark_cursor_off
;
21243 /* If row containing cursor is marked invalid, there is nothing we
21245 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21246 if (!cursor_row
->enabled_p
)
21247 goto mark_cursor_off
;
21249 /* If line spacing is > 0, old cursor may only be partially visible in
21250 window after split-window. So adjust visible height. */
21251 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21252 window_text_bottom_y (w
) - cursor_row
->y
);
21254 /* If row is completely invisible, don't attempt to delete a cursor which
21255 isn't there. This can happen if cursor is at top of a window, and
21256 we switch to a buffer with a header line in that window. */
21257 if (cursor_row
->visible_height
<= 0)
21258 goto mark_cursor_off
;
21260 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21261 if (cursor_row
->cursor_in_fringe_p
)
21263 cursor_row
->cursor_in_fringe_p
= 0;
21264 draw_fringe_bitmap (w
, cursor_row
, 0);
21265 goto mark_cursor_off
;
21268 /* This can happen when the new row is shorter than the old one.
21269 In this case, either draw_glyphs or clear_end_of_line
21270 should have cleared the cursor. Note that we wouldn't be
21271 able to erase the cursor in this case because we don't have a
21272 cursor glyph at hand. */
21273 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21274 goto mark_cursor_off
;
21276 /* If the cursor is in the mouse face area, redisplay that when
21277 we clear the cursor. */
21278 if (! NILP (dpyinfo
->mouse_face_window
)
21279 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21280 && (vpos
> dpyinfo
->mouse_face_beg_row
21281 || (vpos
== dpyinfo
->mouse_face_beg_row
21282 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21283 && (vpos
< dpyinfo
->mouse_face_end_row
21284 || (vpos
== dpyinfo
->mouse_face_end_row
21285 && hpos
< dpyinfo
->mouse_face_end_col
))
21286 /* Don't redraw the cursor's spot in mouse face if it is at the
21287 end of a line (on a newline). The cursor appears there, but
21288 mouse highlighting does not. */
21289 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21290 mouse_face_here_p
= 1;
21292 /* Maybe clear the display under the cursor. */
21293 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21296 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21299 cursor_glyph
= get_phys_cursor_glyph (w
);
21300 if (cursor_glyph
== NULL
)
21301 goto mark_cursor_off
;
21303 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21304 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21305 width
= min (cursor_glyph
->pixel_width
,
21306 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21308 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21311 /* Erase the cursor by redrawing the character underneath it. */
21312 if (mouse_face_here_p
)
21313 hl
= DRAW_MOUSE_FACE
;
21315 hl
= DRAW_NORMAL_TEXT
;
21316 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21319 w
->phys_cursor_on_p
= 0;
21320 w
->phys_cursor_type
= NO_CURSOR
;
21325 Display or clear cursor of window W. If ON is zero, clear the
21326 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21327 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21330 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21332 int on
, hpos
, vpos
, x
, y
;
21334 struct frame
*f
= XFRAME (w
->frame
);
21335 int new_cursor_type
;
21336 int new_cursor_width
;
21338 struct glyph_row
*glyph_row
;
21339 struct glyph
*glyph
;
21341 /* This is pointless on invisible frames, and dangerous on garbaged
21342 windows and frames; in the latter case, the frame or window may
21343 be in the midst of changing its size, and x and y may be off the
21345 if (! FRAME_VISIBLE_P (f
)
21346 || FRAME_GARBAGED_P (f
)
21347 || vpos
>= w
->current_matrix
->nrows
21348 || hpos
>= w
->current_matrix
->matrix_w
)
21351 /* If cursor is off and we want it off, return quickly. */
21352 if (!on
&& !w
->phys_cursor_on_p
)
21355 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21356 /* If cursor row is not enabled, we don't really know where to
21357 display the cursor. */
21358 if (!glyph_row
->enabled_p
)
21360 w
->phys_cursor_on_p
= 0;
21365 if (!glyph_row
->exact_window_width_line_p
21366 || hpos
< glyph_row
->used
[TEXT_AREA
])
21367 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21369 xassert (interrupt_input_blocked
);
21371 /* Set new_cursor_type to the cursor we want to be displayed. */
21372 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21373 &new_cursor_width
, &active_cursor
);
21375 /* If cursor is currently being shown and we don't want it to be or
21376 it is in the wrong place, or the cursor type is not what we want,
21378 if (w
->phys_cursor_on_p
21380 || w
->phys_cursor
.x
!= x
21381 || w
->phys_cursor
.y
!= y
21382 || new_cursor_type
!= w
->phys_cursor_type
21383 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21384 && new_cursor_width
!= w
->phys_cursor_width
)))
21385 erase_phys_cursor (w
);
21387 /* Don't check phys_cursor_on_p here because that flag is only set
21388 to zero in some cases where we know that the cursor has been
21389 completely erased, to avoid the extra work of erasing the cursor
21390 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21391 still not be visible, or it has only been partly erased. */
21394 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21395 w
->phys_cursor_height
= glyph_row
->height
;
21397 /* Set phys_cursor_.* before x_draw_.* is called because some
21398 of them may need the information. */
21399 w
->phys_cursor
.x
= x
;
21400 w
->phys_cursor
.y
= glyph_row
->y
;
21401 w
->phys_cursor
.hpos
= hpos
;
21402 w
->phys_cursor
.vpos
= vpos
;
21405 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21406 new_cursor_type
, new_cursor_width
,
21407 on
, active_cursor
);
21411 /* Switch the display of W's cursor on or off, according to the value
21415 update_window_cursor (w
, on
)
21419 /* Don't update cursor in windows whose frame is in the process
21420 of being deleted. */
21421 if (w
->current_matrix
)
21424 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21425 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21431 /* Call update_window_cursor with parameter ON_P on all leaf windows
21432 in the window tree rooted at W. */
21435 update_cursor_in_window_tree (w
, on_p
)
21441 if (!NILP (w
->hchild
))
21442 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21443 else if (!NILP (w
->vchild
))
21444 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21446 update_window_cursor (w
, on_p
);
21448 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21454 Display the cursor on window W, or clear it, according to ON_P.
21455 Don't change the cursor's position. */
21458 x_update_cursor (f
, on_p
)
21462 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21467 Clear the cursor of window W to background color, and mark the
21468 cursor as not shown. This is used when the text where the cursor
21469 is is about to be rewritten. */
21475 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21476 update_window_cursor (w
, 0);
21481 Display the active region described by mouse_face_* according to DRAW. */
21484 show_mouse_face (dpyinfo
, draw
)
21485 Display_Info
*dpyinfo
;
21486 enum draw_glyphs_face draw
;
21488 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21489 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21491 if (/* If window is in the process of being destroyed, don't bother
21493 w
->current_matrix
!= NULL
21494 /* Don't update mouse highlight if hidden */
21495 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21496 /* Recognize when we are called to operate on rows that don't exist
21497 anymore. This can happen when a window is split. */
21498 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21500 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21501 struct glyph_row
*row
, *first
, *last
;
21503 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21504 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21506 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21508 int start_hpos
, end_hpos
, start_x
;
21510 /* For all but the first row, the highlight starts at column 0. */
21513 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21514 start_x
= dpyinfo
->mouse_face_beg_x
;
21523 end_hpos
= dpyinfo
->mouse_face_end_col
;
21526 end_hpos
= row
->used
[TEXT_AREA
];
21527 if (draw
== DRAW_NORMAL_TEXT
)
21528 row
->fill_line_p
= 1; /* Clear to end of line */
21531 if (end_hpos
> start_hpos
)
21533 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21534 start_hpos
, end_hpos
,
21538 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21542 /* When we've written over the cursor, arrange for it to
21543 be displayed again. */
21544 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21547 display_and_set_cursor (w
, 1,
21548 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21549 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21554 /* Change the mouse cursor. */
21555 if (draw
== DRAW_NORMAL_TEXT
)
21556 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21557 else if (draw
== DRAW_MOUSE_FACE
)
21558 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21560 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21564 Clear out the mouse-highlighted active region.
21565 Redraw it un-highlighted first. Value is non-zero if mouse
21566 face was actually drawn unhighlighted. */
21569 clear_mouse_face (dpyinfo
)
21570 Display_Info
*dpyinfo
;
21574 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21576 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21580 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21581 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21582 dpyinfo
->mouse_face_window
= Qnil
;
21583 dpyinfo
->mouse_face_overlay
= Qnil
;
21589 Non-zero if physical cursor of window W is within mouse face. */
21592 cursor_in_mouse_face_p (w
)
21595 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21596 int in_mouse_face
= 0;
21598 if (WINDOWP (dpyinfo
->mouse_face_window
)
21599 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21601 int hpos
= w
->phys_cursor
.hpos
;
21602 int vpos
= w
->phys_cursor
.vpos
;
21604 if (vpos
>= dpyinfo
->mouse_face_beg_row
21605 && vpos
<= dpyinfo
->mouse_face_end_row
21606 && (vpos
> dpyinfo
->mouse_face_beg_row
21607 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21608 && (vpos
< dpyinfo
->mouse_face_end_row
21609 || hpos
< dpyinfo
->mouse_face_end_col
21610 || dpyinfo
->mouse_face_past_end
))
21614 return in_mouse_face
;
21620 /* Find the glyph matrix position of buffer position CHARPOS in window
21621 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21622 current glyphs must be up to date. If CHARPOS is above window
21623 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21624 of last line in W. In the row containing CHARPOS, stop before glyphs
21625 having STOP as object. */
21627 #if 1 /* This is a version of fast_find_position that's more correct
21628 in the presence of hscrolling, for example. I didn't install
21629 it right away because the problem fixed is minor, it failed
21630 in 20.x as well, and I think it's too risky to install
21631 so near the release of 21.1. 2001-09-25 gerd. */
21634 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21637 int *hpos
, *vpos
, *x
, *y
;
21640 struct glyph_row
*row
, *first
;
21641 struct glyph
*glyph
, *end
;
21644 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21645 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21650 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21654 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21657 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21661 /* If whole rows or last part of a row came from a display overlay,
21662 row_containing_pos will skip over such rows because their end pos
21663 equals the start pos of the overlay or interval.
21665 Move back if we have a STOP object and previous row's
21666 end glyph came from STOP. */
21669 struct glyph_row
*prev
;
21670 while ((prev
= row
- 1, prev
>= first
)
21671 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21672 && prev
->used
[TEXT_AREA
] > 0)
21674 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21675 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21676 while (--glyph
>= beg
21677 && INTEGERP (glyph
->object
));
21679 || !EQ (stop
, glyph
->object
))
21687 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21689 glyph
= row
->glyphs
[TEXT_AREA
];
21690 end
= glyph
+ row
->used
[TEXT_AREA
];
21692 /* Skip over glyphs not having an object at the start of the row.
21693 These are special glyphs like truncation marks on terminal
21695 if (row
->displays_text_p
)
21697 && INTEGERP (glyph
->object
)
21698 && !EQ (stop
, glyph
->object
)
21699 && glyph
->charpos
< 0)
21701 *x
+= glyph
->pixel_width
;
21706 && !INTEGERP (glyph
->object
)
21707 && !EQ (stop
, glyph
->object
)
21708 && (!BUFFERP (glyph
->object
)
21709 || glyph
->charpos
< charpos
))
21711 *x
+= glyph
->pixel_width
;
21715 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21722 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21725 int *hpos
, *vpos
, *x
, *y
;
21730 int maybe_next_line_p
= 0;
21731 int line_start_position
;
21732 int yb
= window_text_bottom_y (w
);
21733 struct glyph_row
*row
, *best_row
;
21734 int row_vpos
, best_row_vpos
;
21737 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21738 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21740 while (row
->y
< yb
)
21742 if (row
->used
[TEXT_AREA
])
21743 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21745 line_start_position
= 0;
21747 if (line_start_position
> pos
)
21749 /* If the position sought is the end of the buffer,
21750 don't include the blank lines at the bottom of the window. */
21751 else if (line_start_position
== pos
21752 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21754 maybe_next_line_p
= 1;
21757 else if (line_start_position
> 0)
21760 best_row_vpos
= row_vpos
;
21763 if (row
->y
+ row
->height
>= yb
)
21770 /* Find the right column within BEST_ROW. */
21772 current_x
= best_row
->x
;
21773 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21775 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21776 int charpos
= glyph
->charpos
;
21778 if (BUFFERP (glyph
->object
))
21780 if (charpos
== pos
)
21783 *vpos
= best_row_vpos
;
21788 else if (charpos
> pos
)
21791 else if (EQ (glyph
->object
, stop
))
21796 current_x
+= glyph
->pixel_width
;
21799 /* If we're looking for the end of the buffer,
21800 and we didn't find it in the line we scanned,
21801 use the start of the following line. */
21802 if (maybe_next_line_p
)
21807 current_x
= best_row
->x
;
21810 *vpos
= best_row_vpos
;
21811 *hpos
= lastcol
+ 1;
21820 /* Find the position of the glyph for position POS in OBJECT in
21821 window W's current matrix, and return in *X, *Y the pixel
21822 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21824 RIGHT_P non-zero means return the position of the right edge of the
21825 glyph, RIGHT_P zero means return the left edge position.
21827 If no glyph for POS exists in the matrix, return the position of
21828 the glyph with the next smaller position that is in the matrix, if
21829 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21830 exists in the matrix, return the position of the glyph with the
21831 next larger position in OBJECT.
21833 Value is non-zero if a glyph was found. */
21836 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21839 Lisp_Object object
;
21840 int *hpos
, *vpos
, *x
, *y
;
21843 int yb
= window_text_bottom_y (w
);
21844 struct glyph_row
*r
;
21845 struct glyph
*best_glyph
= NULL
;
21846 struct glyph_row
*best_row
= NULL
;
21849 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21850 r
->enabled_p
&& r
->y
< yb
;
21853 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21854 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21857 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21858 if (EQ (g
->object
, object
))
21860 if (g
->charpos
== pos
)
21867 else if (best_glyph
== NULL
21868 || ((abs (g
->charpos
- pos
)
21869 < abs (best_glyph
->charpos
- pos
))
21872 : g
->charpos
> pos
)))
21886 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21890 *x
+= best_glyph
->pixel_width
;
21895 *vpos
= best_row
- w
->current_matrix
->rows
;
21898 return best_glyph
!= NULL
;
21902 /* See if position X, Y is within a hot-spot of an image. */
21905 on_hot_spot_p (hot_spot
, x
, y
)
21906 Lisp_Object hot_spot
;
21909 if (!CONSP (hot_spot
))
21912 if (EQ (XCAR (hot_spot
), Qrect
))
21914 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21915 Lisp_Object rect
= XCDR (hot_spot
);
21919 if (!CONSP (XCAR (rect
)))
21921 if (!CONSP (XCDR (rect
)))
21923 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21925 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21927 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21929 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21933 else if (EQ (XCAR (hot_spot
), Qcircle
))
21935 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21936 Lisp_Object circ
= XCDR (hot_spot
);
21937 Lisp_Object lr
, lx0
, ly0
;
21939 && CONSP (XCAR (circ
))
21940 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21941 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21942 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21944 double r
= XFLOATINT (lr
);
21945 double dx
= XINT (lx0
) - x
;
21946 double dy
= XINT (ly0
) - y
;
21947 return (dx
* dx
+ dy
* dy
<= r
* r
);
21950 else if (EQ (XCAR (hot_spot
), Qpoly
))
21952 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21953 if (VECTORP (XCDR (hot_spot
)))
21955 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21956 Lisp_Object
*poly
= v
->contents
;
21960 Lisp_Object lx
, ly
;
21963 /* Need an even number of coordinates, and at least 3 edges. */
21964 if (n
< 6 || n
& 1)
21967 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21968 If count is odd, we are inside polygon. Pixels on edges
21969 may or may not be included depending on actual geometry of the
21971 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21972 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21974 x0
= XINT (lx
), y0
= XINT (ly
);
21975 for (i
= 0; i
< n
; i
+= 2)
21977 int x1
= x0
, y1
= y0
;
21978 if ((lx
= poly
[i
], !INTEGERP (lx
))
21979 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21981 x0
= XINT (lx
), y0
= XINT (ly
);
21983 /* Does this segment cross the X line? */
21991 if (y
> y0
&& y
> y1
)
21993 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21999 /* If we don't understand the format, pretend we're not in the hot-spot. */
22004 find_hot_spot (map
, x
, y
)
22008 while (CONSP (map
))
22010 if (CONSP (XCAR (map
))
22011 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22019 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22021 doc
: /* Lookup in image map MAP coordinates X and Y.
22022 An image map is an alist where each element has the format (AREA ID PLIST).
22023 An AREA is specified as either a rectangle, a circle, or a polygon:
22024 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22025 pixel coordinates of the upper left and bottom right corners.
22026 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22027 and the radius of the circle; r may be a float or integer.
22028 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22029 vector describes one corner in the polygon.
22030 Returns the alist element for the first matching AREA in MAP. */)
22041 return find_hot_spot (map
, XINT (x
), XINT (y
));
22045 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22047 define_frame_cursor1 (f
, cursor
, pointer
)
22050 Lisp_Object pointer
;
22052 /* Do not change cursor shape while dragging mouse. */
22053 if (!NILP (do_mouse_tracking
))
22056 if (!NILP (pointer
))
22058 if (EQ (pointer
, Qarrow
))
22059 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22060 else if (EQ (pointer
, Qhand
))
22061 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22062 else if (EQ (pointer
, Qtext
))
22063 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22064 else if (EQ (pointer
, intern ("hdrag")))
22065 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22066 #ifdef HAVE_X_WINDOWS
22067 else if (EQ (pointer
, intern ("vdrag")))
22068 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22070 else if (EQ (pointer
, intern ("hourglass")))
22071 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22072 else if (EQ (pointer
, Qmodeline
))
22073 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22075 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22078 if (cursor
!= No_Cursor
)
22079 rif
->define_frame_cursor (f
, cursor
);
22082 /* Take proper action when mouse has moved to the mode or header line
22083 or marginal area AREA of window W, x-position X and y-position Y.
22084 X is relative to the start of the text display area of W, so the
22085 width of bitmap areas and scroll bars must be subtracted to get a
22086 position relative to the start of the mode line. */
22089 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22090 Lisp_Object window
;
22092 enum window_part area
;
22094 struct window
*w
= XWINDOW (window
);
22095 struct frame
*f
= XFRAME (w
->frame
);
22096 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22097 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22098 Lisp_Object pointer
= Qnil
;
22099 int charpos
, dx
, dy
, width
, height
;
22100 Lisp_Object string
, object
= Qnil
;
22101 Lisp_Object pos
, help
;
22103 Lisp_Object mouse_face
;
22104 int original_x_pixel
= x
;
22105 struct glyph
* glyph
= NULL
;
22106 struct glyph_row
*row
;
22108 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22113 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22114 &object
, &dx
, &dy
, &width
, &height
);
22116 row
= (area
== ON_MODE_LINE
22117 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22118 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22121 if (row
->mode_line_p
&& row
->enabled_p
)
22123 glyph
= row
->glyphs
[TEXT_AREA
];
22124 end
= glyph
+ row
->used
[TEXT_AREA
];
22126 for (x0
= original_x_pixel
;
22127 glyph
< end
&& x0
>= glyph
->pixel_width
;
22129 x0
-= glyph
->pixel_width
;
22137 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22138 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22139 &object
, &dx
, &dy
, &width
, &height
);
22144 if (IMAGEP (object
))
22146 Lisp_Object image_map
, hotspot
;
22147 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22149 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22151 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22153 Lisp_Object area_id
, plist
;
22155 area_id
= XCAR (hotspot
);
22156 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22157 If so, we could look for mouse-enter, mouse-leave
22158 properties in PLIST (and do something...). */
22159 hotspot
= XCDR (hotspot
);
22160 if (CONSP (hotspot
)
22161 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22163 pointer
= Fplist_get (plist
, Qpointer
);
22164 if (NILP (pointer
))
22166 help
= Fplist_get (plist
, Qhelp_echo
);
22169 help_echo_string
= help
;
22170 /* Is this correct? ++kfs */
22171 XSETWINDOW (help_echo_window
, w
);
22172 help_echo_object
= w
->buffer
;
22173 help_echo_pos
= charpos
;
22177 if (NILP (pointer
))
22178 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22181 if (STRINGP (string
))
22183 pos
= make_number (charpos
);
22184 /* If we're on a string with `help-echo' text property, arrange
22185 for the help to be displayed. This is done by setting the
22186 global variable help_echo_string to the help string. */
22189 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22192 help_echo_string
= help
;
22193 XSETWINDOW (help_echo_window
, w
);
22194 help_echo_object
= string
;
22195 help_echo_pos
= charpos
;
22199 if (NILP (pointer
))
22200 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22202 /* Change the mouse pointer according to what is under X/Y. */
22203 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22206 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22207 if (!KEYMAPP (map
))
22208 map
= Fget_text_property (pos
, Qkeymap
, string
);
22209 if (!KEYMAPP (map
))
22210 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22213 /* Change the mouse face according to what is under X/Y. */
22214 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22215 if (!NILP (mouse_face
)
22216 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22221 struct glyph
* tmp_glyph
;
22225 int total_pixel_width
;
22230 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22231 Qmouse_face
, string
, Qnil
);
22233 b
= make_number (0);
22235 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22237 e
= make_number (SCHARS (string
));
22239 /* Calculate the position(glyph position: GPOS) of GLYPH in
22240 displayed string. GPOS is different from CHARPOS.
22242 CHARPOS is the position of glyph in internal string
22243 object. A mode line string format has structures which
22244 is converted to a flatten by emacs lisp interpreter.
22245 The internal string is an element of the structures.
22246 The displayed string is the flatten string. */
22247 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22248 tmp_glyph
->charpos
>= XINT (b
);
22249 tmp_glyph
--, gpos
++)
22251 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22255 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22256 displayed string holding GLYPH.
22258 GSEQ_LENGTH is different from SCHARS (STRING).
22259 SCHARS (STRING) returns the length of the internal string. */
22260 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22261 tmp_glyph
->charpos
< XINT (e
);
22262 tmp_glyph
++, gseq_length
++)
22264 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22268 total_pixel_width
= 0;
22269 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22270 total_pixel_width
+= tmp_glyph
->pixel_width
;
22272 /* Pre calculation of re-rendering position */
22274 hpos
= (area
== ON_MODE_LINE
22275 ? (w
->current_matrix
)->nrows
- 1
22278 /* If the re-rendering position is included in the last
22279 re-rendering area, we should do nothing. */
22280 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22281 && dpyinfo
->mouse_face_beg_col
<= vpos
22282 && vpos
< dpyinfo
->mouse_face_end_col
22283 && dpyinfo
->mouse_face_beg_row
== hpos
)
22286 if (clear_mouse_face (dpyinfo
))
22287 cursor
= No_Cursor
;
22289 dpyinfo
->mouse_face_beg_col
= vpos
;
22290 dpyinfo
->mouse_face_beg_row
= hpos
;
22292 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22293 dpyinfo
->mouse_face_beg_y
= 0;
22295 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22296 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22298 dpyinfo
->mouse_face_end_x
= 0;
22299 dpyinfo
->mouse_face_end_y
= 0;
22301 dpyinfo
->mouse_face_past_end
= 0;
22302 dpyinfo
->mouse_face_window
= window
;
22304 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22307 glyph
->face_id
, 1);
22308 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22310 if (NILP (pointer
))
22313 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22314 clear_mouse_face (dpyinfo
);
22316 define_frame_cursor1 (f
, cursor
, pointer
);
22321 Take proper action when the mouse has moved to position X, Y on
22322 frame F as regards highlighting characters that have mouse-face
22323 properties. Also de-highlighting chars where the mouse was before.
22324 X and Y can be negative or out of range. */
22327 note_mouse_highlight (f
, x
, y
)
22331 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22332 enum window_part part
;
22333 Lisp_Object window
;
22335 Cursor cursor
= No_Cursor
;
22336 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22339 /* When a menu is active, don't highlight because this looks odd. */
22340 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22341 if (popup_activated ())
22345 if (NILP (Vmouse_highlight
)
22346 || !f
->glyphs_initialized_p
)
22349 dpyinfo
->mouse_face_mouse_x
= x
;
22350 dpyinfo
->mouse_face_mouse_y
= y
;
22351 dpyinfo
->mouse_face_mouse_frame
= f
;
22353 if (dpyinfo
->mouse_face_defer
)
22356 if (gc_in_progress
)
22358 dpyinfo
->mouse_face_deferred_gc
= 1;
22362 /* Which window is that in? */
22363 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22365 /* If we were displaying active text in another window, clear that.
22366 Also clear if we move out of text area in same window. */
22367 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22368 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22369 && !NILP (dpyinfo
->mouse_face_window
)))
22370 clear_mouse_face (dpyinfo
);
22372 /* Not on a window -> return. */
22373 if (!WINDOWP (window
))
22376 /* Reset help_echo_string. It will get recomputed below. */
22377 help_echo_string
= Qnil
;
22379 /* Convert to window-relative pixel coordinates. */
22380 w
= XWINDOW (window
);
22381 frame_to_window_pixel_xy (w
, &x
, &y
);
22383 /* Handle tool-bar window differently since it doesn't display a
22385 if (EQ (window
, f
->tool_bar_window
))
22387 note_tool_bar_highlight (f
, x
, y
);
22391 /* Mouse is on the mode, header line or margin? */
22392 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22393 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22395 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22399 if (part
== ON_VERTICAL_BORDER
)
22401 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22402 help_echo_string
= build_string ("drag-mouse-1: resize");
22404 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22405 || part
== ON_SCROLL_BAR
)
22406 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22408 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22410 /* Are we in a window whose display is up to date?
22411 And verify the buffer's text has not changed. */
22412 b
= XBUFFER (w
->buffer
);
22413 if (part
== ON_TEXT
22414 && EQ (w
->window_end_valid
, w
->buffer
)
22415 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22416 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22418 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22419 struct glyph
*glyph
;
22420 Lisp_Object object
;
22421 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22422 Lisp_Object
*overlay_vec
= NULL
;
22424 struct buffer
*obuf
;
22425 int obegv
, ozv
, same_region
;
22427 /* Find the glyph under X/Y. */
22428 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22430 /* Look for :pointer property on image. */
22431 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22433 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22434 if (img
!= NULL
&& IMAGEP (img
->spec
))
22436 Lisp_Object image_map
, hotspot
;
22437 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22439 && (hotspot
= find_hot_spot (image_map
,
22440 glyph
->slice
.x
+ dx
,
22441 glyph
->slice
.y
+ dy
),
22443 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22445 Lisp_Object area_id
, plist
;
22447 area_id
= XCAR (hotspot
);
22448 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22449 If so, we could look for mouse-enter, mouse-leave
22450 properties in PLIST (and do something...). */
22451 hotspot
= XCDR (hotspot
);
22452 if (CONSP (hotspot
)
22453 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22455 pointer
= Fplist_get (plist
, Qpointer
);
22456 if (NILP (pointer
))
22458 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22459 if (!NILP (help_echo_string
))
22461 help_echo_window
= window
;
22462 help_echo_object
= glyph
->object
;
22463 help_echo_pos
= glyph
->charpos
;
22467 if (NILP (pointer
))
22468 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22472 /* Clear mouse face if X/Y not over text. */
22474 || area
!= TEXT_AREA
22475 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22477 if (clear_mouse_face (dpyinfo
))
22478 cursor
= No_Cursor
;
22479 if (NILP (pointer
))
22481 if (area
!= TEXT_AREA
)
22482 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22484 pointer
= Vvoid_text_area_pointer
;
22489 pos
= glyph
->charpos
;
22490 object
= glyph
->object
;
22491 if (!STRINGP (object
) && !BUFFERP (object
))
22494 /* If we get an out-of-range value, return now; avoid an error. */
22495 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22498 /* Make the window's buffer temporarily current for
22499 overlays_at and compute_char_face. */
22500 obuf
= current_buffer
;
22501 current_buffer
= b
;
22507 /* Is this char mouse-active or does it have help-echo? */
22508 position
= make_number (pos
);
22510 if (BUFFERP (object
))
22512 /* Put all the overlays we want in a vector in overlay_vec. */
22513 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22514 /* Sort overlays into increasing priority order. */
22515 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22520 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22521 && vpos
>= dpyinfo
->mouse_face_beg_row
22522 && vpos
<= dpyinfo
->mouse_face_end_row
22523 && (vpos
> dpyinfo
->mouse_face_beg_row
22524 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22525 && (vpos
< dpyinfo
->mouse_face_end_row
22526 || hpos
< dpyinfo
->mouse_face_end_col
22527 || dpyinfo
->mouse_face_past_end
));
22530 cursor
= No_Cursor
;
22532 /* Check mouse-face highlighting. */
22534 /* If there exists an overlay with mouse-face overlapping
22535 the one we are currently highlighting, we have to
22536 check if we enter the overlapping overlay, and then
22537 highlight only that. */
22538 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22539 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22541 /* Find the highest priority overlay that has a mouse-face
22544 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22546 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22547 if (!NILP (mouse_face
))
22548 overlay
= overlay_vec
[i
];
22551 /* If we're actually highlighting the same overlay as
22552 before, there's no need to do that again. */
22553 if (!NILP (overlay
)
22554 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22555 goto check_help_echo
;
22557 dpyinfo
->mouse_face_overlay
= overlay
;
22559 /* Clear the display of the old active region, if any. */
22560 if (clear_mouse_face (dpyinfo
))
22561 cursor
= No_Cursor
;
22563 /* If no overlay applies, get a text property. */
22564 if (NILP (overlay
))
22565 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22567 /* Handle the overlay case. */
22568 if (!NILP (overlay
))
22570 /* Find the range of text around this char that
22571 should be active. */
22572 Lisp_Object before
, after
;
22575 before
= Foverlay_start (overlay
);
22576 after
= Foverlay_end (overlay
);
22577 /* Record this as the current active region. */
22578 fast_find_position (w
, XFASTINT (before
),
22579 &dpyinfo
->mouse_face_beg_col
,
22580 &dpyinfo
->mouse_face_beg_row
,
22581 &dpyinfo
->mouse_face_beg_x
,
22582 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22584 dpyinfo
->mouse_face_past_end
22585 = !fast_find_position (w
, XFASTINT (after
),
22586 &dpyinfo
->mouse_face_end_col
,
22587 &dpyinfo
->mouse_face_end_row
,
22588 &dpyinfo
->mouse_face_end_x
,
22589 &dpyinfo
->mouse_face_end_y
, Qnil
);
22590 dpyinfo
->mouse_face_window
= window
;
22592 dpyinfo
->mouse_face_face_id
22593 = face_at_buffer_position (w
, pos
, 0, 0,
22595 !dpyinfo
->mouse_face_hidden
);
22597 /* Display it as active. */
22598 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22599 cursor
= No_Cursor
;
22601 /* Handle the text property case. */
22602 else if (!NILP (mouse_face
) && BUFFERP (object
))
22604 /* Find the range of text around this char that
22605 should be active. */
22606 Lisp_Object before
, after
, beginning
, end
;
22609 beginning
= Fmarker_position (w
->start
);
22610 end
= make_number (BUF_Z (XBUFFER (object
))
22611 - XFASTINT (w
->window_end_pos
));
22613 = Fprevious_single_property_change (make_number (pos
+ 1),
22615 object
, beginning
);
22617 = Fnext_single_property_change (position
, Qmouse_face
,
22620 /* Record this as the current active region. */
22621 fast_find_position (w
, XFASTINT (before
),
22622 &dpyinfo
->mouse_face_beg_col
,
22623 &dpyinfo
->mouse_face_beg_row
,
22624 &dpyinfo
->mouse_face_beg_x
,
22625 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22626 dpyinfo
->mouse_face_past_end
22627 = !fast_find_position (w
, XFASTINT (after
),
22628 &dpyinfo
->mouse_face_end_col
,
22629 &dpyinfo
->mouse_face_end_row
,
22630 &dpyinfo
->mouse_face_end_x
,
22631 &dpyinfo
->mouse_face_end_y
, Qnil
);
22632 dpyinfo
->mouse_face_window
= window
;
22634 if (BUFFERP (object
))
22635 dpyinfo
->mouse_face_face_id
22636 = face_at_buffer_position (w
, pos
, 0, 0,
22638 !dpyinfo
->mouse_face_hidden
);
22640 /* Display it as active. */
22641 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22642 cursor
= No_Cursor
;
22644 else if (!NILP (mouse_face
) && STRINGP (object
))
22649 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22652 e
= Fnext_single_property_change (position
, Qmouse_face
,
22655 b
= make_number (0);
22657 e
= make_number (SCHARS (object
) - 1);
22659 fast_find_string_pos (w
, XINT (b
), object
,
22660 &dpyinfo
->mouse_face_beg_col
,
22661 &dpyinfo
->mouse_face_beg_row
,
22662 &dpyinfo
->mouse_face_beg_x
,
22663 &dpyinfo
->mouse_face_beg_y
, 0);
22664 fast_find_string_pos (w
, XINT (e
), object
,
22665 &dpyinfo
->mouse_face_end_col
,
22666 &dpyinfo
->mouse_face_end_row
,
22667 &dpyinfo
->mouse_face_end_x
,
22668 &dpyinfo
->mouse_face_end_y
, 1);
22669 dpyinfo
->mouse_face_past_end
= 0;
22670 dpyinfo
->mouse_face_window
= window
;
22671 dpyinfo
->mouse_face_face_id
22672 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22673 glyph
->face_id
, 1);
22674 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22675 cursor
= No_Cursor
;
22677 else if (STRINGP (object
) && NILP (mouse_face
))
22679 /* A string which doesn't have mouse-face, but
22680 the text ``under'' it might have. */
22681 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22682 int start
= MATRIX_ROW_START_CHARPOS (r
);
22684 pos
= string_buffer_position (w
, object
, start
);
22686 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22690 if (!NILP (mouse_face
) && !NILP (overlay
))
22692 Lisp_Object before
= Foverlay_start (overlay
);
22693 Lisp_Object after
= Foverlay_end (overlay
);
22696 /* Note that we might not be able to find position
22697 BEFORE in the glyph matrix if the overlay is
22698 entirely covered by a `display' property. In
22699 this case, we overshoot. So let's stop in
22700 the glyph matrix before glyphs for OBJECT. */
22701 fast_find_position (w
, XFASTINT (before
),
22702 &dpyinfo
->mouse_face_beg_col
,
22703 &dpyinfo
->mouse_face_beg_row
,
22704 &dpyinfo
->mouse_face_beg_x
,
22705 &dpyinfo
->mouse_face_beg_y
,
22708 dpyinfo
->mouse_face_past_end
22709 = !fast_find_position (w
, XFASTINT (after
),
22710 &dpyinfo
->mouse_face_end_col
,
22711 &dpyinfo
->mouse_face_end_row
,
22712 &dpyinfo
->mouse_face_end_x
,
22713 &dpyinfo
->mouse_face_end_y
,
22715 dpyinfo
->mouse_face_window
= window
;
22716 dpyinfo
->mouse_face_face_id
22717 = face_at_buffer_position (w
, pos
, 0, 0,
22719 !dpyinfo
->mouse_face_hidden
);
22721 /* Display it as active. */
22722 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22723 cursor
= No_Cursor
;
22730 /* Look for a `help-echo' property. */
22731 if (NILP (help_echo_string
)) {
22732 Lisp_Object help
, overlay
;
22734 /* Check overlays first. */
22735 help
= overlay
= Qnil
;
22736 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22738 overlay
= overlay_vec
[i
];
22739 help
= Foverlay_get (overlay
, Qhelp_echo
);
22744 help_echo_string
= help
;
22745 help_echo_window
= window
;
22746 help_echo_object
= overlay
;
22747 help_echo_pos
= pos
;
22751 Lisp_Object object
= glyph
->object
;
22752 int charpos
= glyph
->charpos
;
22754 /* Try text properties. */
22755 if (STRINGP (object
)
22757 && charpos
< SCHARS (object
))
22759 help
= Fget_text_property (make_number (charpos
),
22760 Qhelp_echo
, object
);
22763 /* If the string itself doesn't specify a help-echo,
22764 see if the buffer text ``under'' it does. */
22765 struct glyph_row
*r
22766 = MATRIX_ROW (w
->current_matrix
, vpos
);
22767 int start
= MATRIX_ROW_START_CHARPOS (r
);
22768 int pos
= string_buffer_position (w
, object
, start
);
22771 help
= Fget_char_property (make_number (pos
),
22772 Qhelp_echo
, w
->buffer
);
22776 object
= w
->buffer
;
22781 else if (BUFFERP (object
)
22784 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22789 help_echo_string
= help
;
22790 help_echo_window
= window
;
22791 help_echo_object
= object
;
22792 help_echo_pos
= charpos
;
22797 /* Look for a `pointer' property. */
22798 if (NILP (pointer
))
22800 /* Check overlays first. */
22801 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22802 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22804 if (NILP (pointer
))
22806 Lisp_Object object
= glyph
->object
;
22807 int charpos
= glyph
->charpos
;
22809 /* Try text properties. */
22810 if (STRINGP (object
)
22812 && charpos
< SCHARS (object
))
22814 pointer
= Fget_text_property (make_number (charpos
),
22816 if (NILP (pointer
))
22818 /* If the string itself doesn't specify a pointer,
22819 see if the buffer text ``under'' it does. */
22820 struct glyph_row
*r
22821 = MATRIX_ROW (w
->current_matrix
, vpos
);
22822 int start
= MATRIX_ROW_START_CHARPOS (r
);
22823 int pos
= string_buffer_position (w
, object
, start
);
22825 pointer
= Fget_char_property (make_number (pos
),
22826 Qpointer
, w
->buffer
);
22829 else if (BUFFERP (object
)
22832 pointer
= Fget_text_property (make_number (charpos
),
22839 current_buffer
= obuf
;
22844 define_frame_cursor1 (f
, cursor
, pointer
);
22849 Clear any mouse-face on window W. This function is part of the
22850 redisplay interface, and is called from try_window_id and similar
22851 functions to ensure the mouse-highlight is off. */
22854 x_clear_window_mouse_face (w
)
22857 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22858 Lisp_Object window
;
22861 XSETWINDOW (window
, w
);
22862 if (EQ (window
, dpyinfo
->mouse_face_window
))
22863 clear_mouse_face (dpyinfo
);
22869 Just discard the mouse face information for frame F, if any.
22870 This is used when the size of F is changed. */
22873 cancel_mouse_face (f
)
22876 Lisp_Object window
;
22877 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22879 window
= dpyinfo
->mouse_face_window
;
22880 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22882 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22883 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22884 dpyinfo
->mouse_face_window
= Qnil
;
22889 #endif /* HAVE_WINDOW_SYSTEM */
22892 /***********************************************************************
22894 ***********************************************************************/
22896 #ifdef HAVE_WINDOW_SYSTEM
22898 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22899 which intersects rectangle R. R is in window-relative coordinates. */
22902 expose_area (w
, row
, r
, area
)
22904 struct glyph_row
*row
;
22906 enum glyph_row_area area
;
22908 struct glyph
*first
= row
->glyphs
[area
];
22909 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22910 struct glyph
*last
;
22911 int first_x
, start_x
, x
;
22913 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22914 /* If row extends face to end of line write the whole line. */
22915 draw_glyphs (w
, 0, row
, area
,
22916 0, row
->used
[area
],
22917 DRAW_NORMAL_TEXT
, 0);
22920 /* Set START_X to the window-relative start position for drawing glyphs of
22921 AREA. The first glyph of the text area can be partially visible.
22922 The first glyphs of other areas cannot. */
22923 start_x
= window_box_left_offset (w
, area
);
22925 if (area
== TEXT_AREA
)
22928 /* Find the first glyph that must be redrawn. */
22930 && x
+ first
->pixel_width
< r
->x
)
22932 x
+= first
->pixel_width
;
22936 /* Find the last one. */
22940 && x
< r
->x
+ r
->width
)
22942 x
+= last
->pixel_width
;
22948 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22949 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22950 DRAW_NORMAL_TEXT
, 0);
22955 /* Redraw the parts of the glyph row ROW on window W intersecting
22956 rectangle R. R is in window-relative coordinates. Value is
22957 non-zero if mouse-face was overwritten. */
22960 expose_line (w
, row
, r
)
22962 struct glyph_row
*row
;
22965 xassert (row
->enabled_p
);
22967 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22968 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22969 0, row
->used
[TEXT_AREA
],
22970 DRAW_NORMAL_TEXT
, 0);
22973 if (row
->used
[LEFT_MARGIN_AREA
])
22974 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22975 if (row
->used
[TEXT_AREA
])
22976 expose_area (w
, row
, r
, TEXT_AREA
);
22977 if (row
->used
[RIGHT_MARGIN_AREA
])
22978 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22979 draw_row_fringe_bitmaps (w
, row
);
22982 return row
->mouse_face_p
;
22986 /* Redraw those parts of glyphs rows during expose event handling that
22987 overlap other rows. Redrawing of an exposed line writes over parts
22988 of lines overlapping that exposed line; this function fixes that.
22990 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22991 row in W's current matrix that is exposed and overlaps other rows.
22992 LAST_OVERLAPPING_ROW is the last such row. */
22995 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22997 struct glyph_row
*first_overlapping_row
;
22998 struct glyph_row
*last_overlapping_row
;
23000 struct glyph_row
*row
;
23002 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23003 if (row
->overlapping_p
)
23005 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23007 if (row
->used
[LEFT_MARGIN_AREA
])
23008 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23010 if (row
->used
[TEXT_AREA
])
23011 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23013 if (row
->used
[RIGHT_MARGIN_AREA
])
23014 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23019 /* Return non-zero if W's cursor intersects rectangle R. */
23022 phys_cursor_in_rect_p (w
, r
)
23026 XRectangle cr
, result
;
23027 struct glyph
*cursor_glyph
;
23029 cursor_glyph
= get_phys_cursor_glyph (w
);
23032 /* r is relative to W's box, but w->phys_cursor.x is relative
23033 to left edge of W's TEXT area. Adjust it. */
23034 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23035 cr
.y
= w
->phys_cursor
.y
;
23036 cr
.width
= cursor_glyph
->pixel_width
;
23037 cr
.height
= w
->phys_cursor_height
;
23038 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23039 I assume the effect is the same -- and this is portable. */
23040 return x_intersect_rectangles (&cr
, r
, &result
);
23048 Draw a vertical window border to the right of window W if W doesn't
23049 have vertical scroll bars. */
23052 x_draw_vertical_border (w
)
23055 /* We could do better, if we knew what type of scroll-bar the adjacent
23056 windows (on either side) have... But we don't :-(
23057 However, I think this works ok. ++KFS 2003-04-25 */
23059 /* Redraw borders between horizontally adjacent windows. Don't
23060 do it for frames with vertical scroll bars because either the
23061 right scroll bar of a window, or the left scroll bar of its
23062 neighbor will suffice as a border. */
23063 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23066 if (!WINDOW_RIGHTMOST_P (w
)
23067 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23069 int x0
, x1
, y0
, y1
;
23071 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23074 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23077 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23079 else if (!WINDOW_LEFTMOST_P (w
)
23080 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23082 int x0
, x1
, y0
, y1
;
23084 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23087 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23090 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23095 /* Redraw the part of window W intersection rectangle FR. Pixel
23096 coordinates in FR are frame-relative. Call this function with
23097 input blocked. Value is non-zero if the exposure overwrites
23101 expose_window (w
, fr
)
23105 struct frame
*f
= XFRAME (w
->frame
);
23107 int mouse_face_overwritten_p
= 0;
23109 /* If window is not yet fully initialized, do nothing. This can
23110 happen when toolkit scroll bars are used and a window is split.
23111 Reconfiguring the scroll bar will generate an expose for a newly
23113 if (w
->current_matrix
== NULL
)
23116 /* When we're currently updating the window, display and current
23117 matrix usually don't agree. Arrange for a thorough display
23119 if (w
== updated_window
)
23121 SET_FRAME_GARBAGED (f
);
23125 /* Frame-relative pixel rectangle of W. */
23126 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23127 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23128 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23129 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23131 if (x_intersect_rectangles (fr
, &wr
, &r
))
23133 int yb
= window_text_bottom_y (w
);
23134 struct glyph_row
*row
;
23135 int cursor_cleared_p
;
23136 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23138 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23139 r
.x
, r
.y
, r
.width
, r
.height
));
23141 /* Convert to window coordinates. */
23142 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23143 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23145 /* Turn off the cursor. */
23146 if (!w
->pseudo_window_p
23147 && phys_cursor_in_rect_p (w
, &r
))
23149 x_clear_cursor (w
);
23150 cursor_cleared_p
= 1;
23153 cursor_cleared_p
= 0;
23155 /* Update lines intersecting rectangle R. */
23156 first_overlapping_row
= last_overlapping_row
= NULL
;
23157 for (row
= w
->current_matrix
->rows
;
23162 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23164 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23165 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23166 || (r
.y
>= y0
&& r
.y
< y1
)
23167 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23169 /* A header line may be overlapping, but there is no need
23170 to fix overlapping areas for them. KFS 2005-02-12 */
23171 if (row
->overlapping_p
&& !row
->mode_line_p
)
23173 if (first_overlapping_row
== NULL
)
23174 first_overlapping_row
= row
;
23175 last_overlapping_row
= row
;
23178 if (expose_line (w
, row
, &r
))
23179 mouse_face_overwritten_p
= 1;
23186 /* Display the mode line if there is one. */
23187 if (WINDOW_WANTS_MODELINE_P (w
)
23188 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23190 && row
->y
< r
.y
+ r
.height
)
23192 if (expose_line (w
, row
, &r
))
23193 mouse_face_overwritten_p
= 1;
23196 if (!w
->pseudo_window_p
)
23198 /* Fix the display of overlapping rows. */
23199 if (first_overlapping_row
)
23200 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23202 /* Draw border between windows. */
23203 x_draw_vertical_border (w
);
23205 /* Turn the cursor on again. */
23206 if (cursor_cleared_p
)
23207 update_window_cursor (w
, 1);
23211 return mouse_face_overwritten_p
;
23216 /* Redraw (parts) of all windows in the window tree rooted at W that
23217 intersect R. R contains frame pixel coordinates. Value is
23218 non-zero if the exposure overwrites mouse-face. */
23221 expose_window_tree (w
, r
)
23225 struct frame
*f
= XFRAME (w
->frame
);
23226 int mouse_face_overwritten_p
= 0;
23228 while (w
&& !FRAME_GARBAGED_P (f
))
23230 if (!NILP (w
->hchild
))
23231 mouse_face_overwritten_p
23232 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23233 else if (!NILP (w
->vchild
))
23234 mouse_face_overwritten_p
23235 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23237 mouse_face_overwritten_p
|= expose_window (w
, r
);
23239 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23242 return mouse_face_overwritten_p
;
23247 Redisplay an exposed area of frame F. X and Y are the upper-left
23248 corner of the exposed rectangle. W and H are width and height of
23249 the exposed area. All are pixel values. W or H zero means redraw
23250 the entire frame. */
23253 expose_frame (f
, x
, y
, w
, h
)
23258 int mouse_face_overwritten_p
= 0;
23260 TRACE ((stderr
, "expose_frame "));
23262 /* No need to redraw if frame will be redrawn soon. */
23263 if (FRAME_GARBAGED_P (f
))
23265 TRACE ((stderr
, " garbaged\n"));
23269 /* If basic faces haven't been realized yet, there is no point in
23270 trying to redraw anything. This can happen when we get an expose
23271 event while Emacs is starting, e.g. by moving another window. */
23272 if (FRAME_FACE_CACHE (f
) == NULL
23273 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23275 TRACE ((stderr
, " no faces\n"));
23279 if (w
== 0 || h
== 0)
23282 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23283 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23293 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23294 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23296 if (WINDOWP (f
->tool_bar_window
))
23297 mouse_face_overwritten_p
23298 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23300 #ifdef HAVE_X_WINDOWS
23302 #ifndef USE_X_TOOLKIT
23303 if (WINDOWP (f
->menu_bar_window
))
23304 mouse_face_overwritten_p
23305 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23306 #endif /* not USE_X_TOOLKIT */
23310 /* Some window managers support a focus-follows-mouse style with
23311 delayed raising of frames. Imagine a partially obscured frame,
23312 and moving the mouse into partially obscured mouse-face on that
23313 frame. The visible part of the mouse-face will be highlighted,
23314 then the WM raises the obscured frame. With at least one WM, KDE
23315 2.1, Emacs is not getting any event for the raising of the frame
23316 (even tried with SubstructureRedirectMask), only Expose events.
23317 These expose events will draw text normally, i.e. not
23318 highlighted. Which means we must redo the highlight here.
23319 Subsume it under ``we love X''. --gerd 2001-08-15 */
23320 /* Included in Windows version because Windows most likely does not
23321 do the right thing if any third party tool offers
23322 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23323 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23325 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23326 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23328 int x
= dpyinfo
->mouse_face_mouse_x
;
23329 int y
= dpyinfo
->mouse_face_mouse_y
;
23330 clear_mouse_face (dpyinfo
);
23331 note_mouse_highlight (f
, x
, y
);
23338 Determine the intersection of two rectangles R1 and R2. Return
23339 the intersection in *RESULT. Value is non-zero if RESULT is not
23343 x_intersect_rectangles (r1
, r2
, result
)
23344 XRectangle
*r1
, *r2
, *result
;
23346 XRectangle
*left
, *right
;
23347 XRectangle
*upper
, *lower
;
23348 int intersection_p
= 0;
23350 /* Rearrange so that R1 is the left-most rectangle. */
23352 left
= r1
, right
= r2
;
23354 left
= r2
, right
= r1
;
23356 /* X0 of the intersection is right.x0, if this is inside R1,
23357 otherwise there is no intersection. */
23358 if (right
->x
<= left
->x
+ left
->width
)
23360 result
->x
= right
->x
;
23362 /* The right end of the intersection is the minimum of the
23363 the right ends of left and right. */
23364 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23367 /* Same game for Y. */
23369 upper
= r1
, lower
= r2
;
23371 upper
= r2
, lower
= r1
;
23373 /* The upper end of the intersection is lower.y0, if this is inside
23374 of upper. Otherwise, there is no intersection. */
23375 if (lower
->y
<= upper
->y
+ upper
->height
)
23377 result
->y
= lower
->y
;
23379 /* The lower end of the intersection is the minimum of the lower
23380 ends of upper and lower. */
23381 result
->height
= (min (lower
->y
+ lower
->height
,
23382 upper
->y
+ upper
->height
)
23384 intersection_p
= 1;
23388 return intersection_p
;
23391 #endif /* HAVE_WINDOW_SYSTEM */
23394 /***********************************************************************
23396 ***********************************************************************/
23401 Vwith_echo_area_save_vector
= Qnil
;
23402 staticpro (&Vwith_echo_area_save_vector
);
23404 Vmessage_stack
= Qnil
;
23405 staticpro (&Vmessage_stack
);
23407 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23408 staticpro (&Qinhibit_redisplay
);
23410 message_dolog_marker1
= Fmake_marker ();
23411 staticpro (&message_dolog_marker1
);
23412 message_dolog_marker2
= Fmake_marker ();
23413 staticpro (&message_dolog_marker2
);
23414 message_dolog_marker3
= Fmake_marker ();
23415 staticpro (&message_dolog_marker3
);
23418 defsubr (&Sdump_frame_glyph_matrix
);
23419 defsubr (&Sdump_glyph_matrix
);
23420 defsubr (&Sdump_glyph_row
);
23421 defsubr (&Sdump_tool_bar_row
);
23422 defsubr (&Strace_redisplay
);
23423 defsubr (&Strace_to_stderr
);
23425 #ifdef HAVE_WINDOW_SYSTEM
23426 defsubr (&Stool_bar_lines_needed
);
23427 defsubr (&Slookup_image_map
);
23429 defsubr (&Sformat_mode_line
);
23431 staticpro (&Qmenu_bar_update_hook
);
23432 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23434 staticpro (&Qoverriding_terminal_local_map
);
23435 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23437 staticpro (&Qoverriding_local_map
);
23438 Qoverriding_local_map
= intern ("overriding-local-map");
23440 staticpro (&Qwindow_scroll_functions
);
23441 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23443 staticpro (&Qredisplay_end_trigger_functions
);
23444 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23446 staticpro (&Qinhibit_point_motion_hooks
);
23447 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23449 QCdata
= intern (":data");
23450 staticpro (&QCdata
);
23451 Qdisplay
= intern ("display");
23452 staticpro (&Qdisplay
);
23453 Qspace_width
= intern ("space-width");
23454 staticpro (&Qspace_width
);
23455 Qraise
= intern ("raise");
23456 staticpro (&Qraise
);
23457 Qslice
= intern ("slice");
23458 staticpro (&Qslice
);
23459 Qspace
= intern ("space");
23460 staticpro (&Qspace
);
23461 Qmargin
= intern ("margin");
23462 staticpro (&Qmargin
);
23463 Qpointer
= intern ("pointer");
23464 staticpro (&Qpointer
);
23465 Qleft_margin
= intern ("left-margin");
23466 staticpro (&Qleft_margin
);
23467 Qright_margin
= intern ("right-margin");
23468 staticpro (&Qright_margin
);
23469 Qcenter
= intern ("center");
23470 staticpro (&Qcenter
);
23471 Qline_height
= intern ("line-height");
23472 staticpro (&Qline_height
);
23473 QCalign_to
= intern (":align-to");
23474 staticpro (&QCalign_to
);
23475 QCrelative_width
= intern (":relative-width");
23476 staticpro (&QCrelative_width
);
23477 QCrelative_height
= intern (":relative-height");
23478 staticpro (&QCrelative_height
);
23479 QCeval
= intern (":eval");
23480 staticpro (&QCeval
);
23481 QCpropertize
= intern (":propertize");
23482 staticpro (&QCpropertize
);
23483 QCfile
= intern (":file");
23484 staticpro (&QCfile
);
23485 Qfontified
= intern ("fontified");
23486 staticpro (&Qfontified
);
23487 Qfontification_functions
= intern ("fontification-functions");
23488 staticpro (&Qfontification_functions
);
23489 Qtrailing_whitespace
= intern ("trailing-whitespace");
23490 staticpro (&Qtrailing_whitespace
);
23491 Qescape_glyph
= intern ("escape-glyph");
23492 staticpro (&Qescape_glyph
);
23493 Qnobreak_space
= intern ("nobreak-space");
23494 staticpro (&Qnobreak_space
);
23495 Qimage
= intern ("image");
23496 staticpro (&Qimage
);
23497 QCmap
= intern (":map");
23498 staticpro (&QCmap
);
23499 QCpointer
= intern (":pointer");
23500 staticpro (&QCpointer
);
23501 Qrect
= intern ("rect");
23502 staticpro (&Qrect
);
23503 Qcircle
= intern ("circle");
23504 staticpro (&Qcircle
);
23505 Qpoly
= intern ("poly");
23506 staticpro (&Qpoly
);
23507 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23508 staticpro (&Qmessage_truncate_lines
);
23509 Qgrow_only
= intern ("grow-only");
23510 staticpro (&Qgrow_only
);
23511 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23512 staticpro (&Qinhibit_menubar_update
);
23513 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23514 staticpro (&Qinhibit_eval_during_redisplay
);
23515 Qposition
= intern ("position");
23516 staticpro (&Qposition
);
23517 Qbuffer_position
= intern ("buffer-position");
23518 staticpro (&Qbuffer_position
);
23519 Qobject
= intern ("object");
23520 staticpro (&Qobject
);
23521 Qbar
= intern ("bar");
23523 Qhbar
= intern ("hbar");
23524 staticpro (&Qhbar
);
23525 Qbox
= intern ("box");
23527 Qhollow
= intern ("hollow");
23528 staticpro (&Qhollow
);
23529 Qhand
= intern ("hand");
23530 staticpro (&Qhand
);
23531 Qarrow
= intern ("arrow");
23532 staticpro (&Qarrow
);
23533 Qtext
= intern ("text");
23534 staticpro (&Qtext
);
23535 Qrisky_local_variable
= intern ("risky-local-variable");
23536 staticpro (&Qrisky_local_variable
);
23537 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23538 staticpro (&Qinhibit_free_realized_faces
);
23540 list_of_error
= Fcons (Fcons (intern ("error"),
23541 Fcons (intern ("void-variable"), Qnil
)),
23543 staticpro (&list_of_error
);
23545 Qlast_arrow_position
= intern ("last-arrow-position");
23546 staticpro (&Qlast_arrow_position
);
23547 Qlast_arrow_string
= intern ("last-arrow-string");
23548 staticpro (&Qlast_arrow_string
);
23550 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23551 staticpro (&Qoverlay_arrow_string
);
23552 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23553 staticpro (&Qoverlay_arrow_bitmap
);
23555 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23556 staticpro (&echo_buffer
[0]);
23557 staticpro (&echo_buffer
[1]);
23559 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23560 staticpro (&echo_area_buffer
[0]);
23561 staticpro (&echo_area_buffer
[1]);
23563 Vmessages_buffer_name
= build_string ("*Messages*");
23564 staticpro (&Vmessages_buffer_name
);
23566 mode_line_proptrans_alist
= Qnil
;
23567 staticpro (&mode_line_proptrans_alist
);
23568 mode_line_string_list
= Qnil
;
23569 staticpro (&mode_line_string_list
);
23570 mode_line_string_face
= Qnil
;
23571 staticpro (&mode_line_string_face
);
23572 mode_line_string_face_prop
= Qnil
;
23573 staticpro (&mode_line_string_face_prop
);
23574 Vmode_line_unwind_vector
= Qnil
;
23575 staticpro (&Vmode_line_unwind_vector
);
23577 help_echo_string
= Qnil
;
23578 staticpro (&help_echo_string
);
23579 help_echo_object
= Qnil
;
23580 staticpro (&help_echo_object
);
23581 help_echo_window
= Qnil
;
23582 staticpro (&help_echo_window
);
23583 previous_help_echo_string
= Qnil
;
23584 staticpro (&previous_help_echo_string
);
23585 help_echo_pos
= -1;
23587 #ifdef HAVE_WINDOW_SYSTEM
23588 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23589 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23590 For example, if a block cursor is over a tab, it will be drawn as
23591 wide as that tab on the display. */);
23592 x_stretch_cursor_p
= 0;
23595 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23596 doc
: /* *Non-nil means highlight trailing whitespace.
23597 The face used for trailing whitespace is `trailing-whitespace'. */);
23598 Vshow_trailing_whitespace
= Qnil
;
23600 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23601 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23602 A value of t means highlight the character itself (for nobreak space,
23603 use face `nobreak-space').
23604 A value of nil means no highlighting.
23605 Other values mean display the escape glyph followed by an ordinary
23606 space or ordinary hyphen. */);
23607 Vnobreak_char_display
= Qt
;
23609 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23610 doc
: /* *The pointer shape to show in void text areas.
23611 A value of nil means to show the text pointer. Other options are `arrow',
23612 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23613 Vvoid_text_area_pointer
= Qarrow
;
23615 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23616 doc
: /* Non-nil means don't actually do any redisplay.
23617 This is used for internal purposes. */);
23618 Vinhibit_redisplay
= Qnil
;
23620 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23621 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23622 Vglobal_mode_string
= Qnil
;
23624 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23625 doc
: /* Marker for where to display an arrow on top of the buffer text.
23626 This must be the beginning of a line in order to work.
23627 See also `overlay-arrow-string'. */);
23628 Voverlay_arrow_position
= Qnil
;
23630 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23631 doc
: /* String to display as an arrow in non-window frames.
23632 See also `overlay-arrow-position'. */);
23633 Voverlay_arrow_string
= build_string ("=>");
23635 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23636 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23637 The symbols on this list are examined during redisplay to determine
23638 where to display overlay arrows. */);
23639 Voverlay_arrow_variable_list
23640 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23642 DEFVAR_INT ("scroll-step", &scroll_step
,
23643 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23644 If that fails to bring point back on frame, point is centered instead.
23645 If this is zero, point is always centered after it moves off frame.
23646 If you want scrolling to always be a line at a time, you should set
23647 `scroll-conservatively' to a large value rather than set this to 1. */);
23649 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23650 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23651 A value of zero means to scroll the text to center point vertically
23652 in the window. */);
23653 scroll_conservatively
= 0;
23655 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23656 doc
: /* *Number of lines of margin at the top and bottom of a window.
23657 Recenter the window whenever point gets within this many lines
23658 of the top or bottom of the window. */);
23661 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23662 doc
: /* Pixels per inch value for non-window system displays.
23663 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23664 Vdisplay_pixels_per_inch
= make_float (72.0);
23667 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23670 DEFVAR_BOOL ("truncate-partial-width-windows",
23671 &truncate_partial_width_windows
,
23672 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23673 truncate_partial_width_windows
= 1;
23675 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23676 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23677 Any other value means to use the appropriate face, `mode-line',
23678 `header-line', or `menu' respectively. */);
23679 mode_line_inverse_video
= 1;
23681 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23682 doc
: /* *Maximum buffer size for which line number should be displayed.
23683 If the buffer is bigger than this, the line number does not appear
23684 in the mode line. A value of nil means no limit. */);
23685 Vline_number_display_limit
= Qnil
;
23687 DEFVAR_INT ("line-number-display-limit-width",
23688 &line_number_display_limit_width
,
23689 doc
: /* *Maximum line width (in characters) for line number display.
23690 If the average length of the lines near point is bigger than this, then the
23691 line number may be omitted from the mode line. */);
23692 line_number_display_limit_width
= 200;
23694 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23695 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23696 highlight_nonselected_windows
= 0;
23698 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23699 doc
: /* Non-nil if more than one frame is visible on this display.
23700 Minibuffer-only frames don't count, but iconified frames do.
23701 This variable is not guaranteed to be accurate except while processing
23702 `frame-title-format' and `icon-title-format'. */);
23704 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23705 doc
: /* Template for displaying the title bar of visible frames.
23706 \(Assuming the window manager supports this feature.)
23707 This variable has the same structure as `mode-line-format' (which see),
23708 and is used only on frames for which no explicit name has been set
23709 \(see `modify-frame-parameters'). */);
23711 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23712 doc
: /* Template for displaying the title bar of an iconified frame.
23713 \(Assuming the window manager supports this feature.)
23714 This variable has the same structure as `mode-line-format' (which see),
23715 and is used only on frames for which no explicit name has been set
23716 \(see `modify-frame-parameters'). */);
23718 = Vframe_title_format
23719 = Fcons (intern ("multiple-frames"),
23720 Fcons (build_string ("%b"),
23721 Fcons (Fcons (empty_string
,
23722 Fcons (intern ("invocation-name"),
23723 Fcons (build_string ("@"),
23724 Fcons (intern ("system-name"),
23728 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23729 doc
: /* Maximum number of lines to keep in the message log buffer.
23730 If nil, disable message logging. If t, log messages but don't truncate
23731 the buffer when it becomes large. */);
23732 Vmessage_log_max
= make_number (50);
23734 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23735 doc
: /* Functions called before redisplay, if window sizes have changed.
23736 The value should be a list of functions that take one argument.
23737 Just before redisplay, for each frame, if any of its windows have changed
23738 size since the last redisplay, or have been split or deleted,
23739 all the functions in the list are called, with the frame as argument. */);
23740 Vwindow_size_change_functions
= Qnil
;
23742 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23743 doc
: /* List of functions to call before redisplaying a window with scrolling.
23744 Each function is called with two arguments, the window
23745 and its new display-start position. Note that the value of `window-end'
23746 is not valid when these functions are called. */);
23747 Vwindow_scroll_functions
= Qnil
;
23749 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23750 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23751 Each function is called with two arguments, the window and the end trigger value.
23752 See `set-window-redisplay-end-trigger'. */);
23753 Vredisplay_end_trigger_functions
= Qnil
;
23755 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23756 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23757 mouse_autoselect_window
= 0;
23759 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23760 doc
: /* *Non-nil means automatically resize tool-bars.
23761 This increases a tool-bar's height if not all tool-bar items are visible.
23762 It decreases a tool-bar's height when it would display blank lines
23764 auto_resize_tool_bars_p
= 1;
23766 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23767 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23768 auto_raise_tool_bar_buttons_p
= 1;
23770 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23771 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23772 make_cursor_line_fully_visible_p
= 1;
23774 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
23775 doc
: /* *Border below tool-bar in pixels.
23776 If an integer, use it as the height of the border.
23777 If it is one of `internal-border-width' or `border-width', use the
23778 value of the corresponding frame parameter.
23779 Otherwise, no border is added below the tool-bar. */);
23780 Vtool_bar_border
= Qinternal_border_width
;
23782 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23783 doc
: /* *Margin around tool-bar buttons in pixels.
23784 If an integer, use that for both horizontal and vertical margins.
23785 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23786 HORZ specifying the horizontal margin, and VERT specifying the
23787 vertical margin. */);
23788 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23790 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23791 doc
: /* *Relief thickness of tool-bar buttons. */);
23792 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23794 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23795 doc
: /* List of functions to call to fontify regions of text.
23796 Each function is called with one argument POS. Functions must
23797 fontify a region starting at POS in the current buffer, and give
23798 fontified regions the property `fontified'. */);
23799 Vfontification_functions
= Qnil
;
23800 Fmake_variable_buffer_local (Qfontification_functions
);
23802 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23803 &unibyte_display_via_language_environment
,
23804 doc
: /* *Non-nil means display unibyte text according to language environment.
23805 Specifically this means that unibyte non-ASCII characters
23806 are displayed by converting them to the equivalent multibyte characters
23807 according to the current language environment. As a result, they are
23808 displayed according to the current fontset. */);
23809 unibyte_display_via_language_environment
= 0;
23811 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23812 doc
: /* *Maximum height for resizing mini-windows.
23813 If a float, it specifies a fraction of the mini-window frame's height.
23814 If an integer, it specifies a number of lines. */);
23815 Vmax_mini_window_height
= make_float (0.25);
23817 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23818 doc
: /* *How to resize mini-windows.
23819 A value of nil means don't automatically resize mini-windows.
23820 A value of t means resize them to fit the text displayed in them.
23821 A value of `grow-only', the default, means let mini-windows grow
23822 only, until their display becomes empty, at which point the windows
23823 go back to their normal size. */);
23824 Vresize_mini_windows
= Qgrow_only
;
23826 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23827 doc
: /* Alist specifying how to blink the cursor off.
23828 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23829 `cursor-type' frame-parameter or variable equals ON-STATE,
23830 comparing using `equal', Emacs uses OFF-STATE to specify
23831 how to blink it off. ON-STATE and OFF-STATE are values for
23832 the `cursor-type' frame parameter.
23834 If a frame's ON-STATE has no entry in this list,
23835 the frame's other specifications determine how to blink the cursor off. */);
23836 Vblink_cursor_alist
= Qnil
;
23838 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23839 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23840 automatic_hscrolling_p
= 1;
23842 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23843 doc
: /* *How many columns away from the window edge point is allowed to get
23844 before automatic hscrolling will horizontally scroll the window. */);
23845 hscroll_margin
= 5;
23847 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23848 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23849 When point is less than `hscroll-margin' columns from the window
23850 edge, automatic hscrolling will scroll the window by the amount of columns
23851 determined by this variable. If its value is a positive integer, scroll that
23852 many columns. If it's a positive floating-point number, it specifies the
23853 fraction of the window's width to scroll. If it's nil or zero, point will be
23854 centered horizontally after the scroll. Any other value, including negative
23855 numbers, are treated as if the value were zero.
23857 Automatic hscrolling always moves point outside the scroll margin, so if
23858 point was more than scroll step columns inside the margin, the window will
23859 scroll more than the value given by the scroll step.
23861 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23862 and `scroll-right' overrides this variable's effect. */);
23863 Vhscroll_step
= make_number (0);
23865 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23866 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23867 Bind this around calls to `message' to let it take effect. */);
23868 message_truncate_lines
= 0;
23870 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23871 doc
: /* Normal hook run to update the menu bar definitions.
23872 Redisplay runs this hook before it redisplays the menu bar.
23873 This is used to update submenus such as Buffers,
23874 whose contents depend on various data. */);
23875 Vmenu_bar_update_hook
= Qnil
;
23877 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23878 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23879 inhibit_menubar_update
= 0;
23881 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23882 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23883 inhibit_eval_during_redisplay
= 0;
23885 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23886 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23887 inhibit_free_realized_faces
= 0;
23890 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23891 doc
: /* Inhibit try_window_id display optimization. */);
23892 inhibit_try_window_id
= 0;
23894 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23895 doc
: /* Inhibit try_window_reusing display optimization. */);
23896 inhibit_try_window_reusing
= 0;
23898 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23899 doc
: /* Inhibit try_cursor_movement display optimization. */);
23900 inhibit_try_cursor_movement
= 0;
23901 #endif /* GLYPH_DEBUG */
23905 /* Initialize this module when Emacs starts. */
23910 Lisp_Object root_window
;
23911 struct window
*mini_w
;
23913 current_header_line_height
= current_mode_line_height
= -1;
23915 CHARPOS (this_line_start_pos
) = 0;
23917 mini_w
= XWINDOW (minibuf_window
);
23918 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23920 if (!noninteractive
)
23922 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23925 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23926 set_window_height (root_window
,
23927 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23929 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23930 set_window_height (minibuf_window
, 1, 0);
23932 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23933 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23935 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23936 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23937 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23939 /* The default ellipsis glyphs `...'. */
23940 for (i
= 0; i
< 3; ++i
)
23941 default_invis_vector
[i
] = make_number ('.');
23945 /* Allocate the buffer for frame titles.
23946 Also used for `format-mode-line'. */
23948 mode_line_noprop_buf
= (char *) xmalloc (size
);
23949 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23950 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23951 mode_line_target
= MODE_LINE_DISPLAY
;
23954 help_echo_showing_p
= 0;
23958 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23959 (do not change this comment) */