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
)
1940 rs
[i
].height
= row_y
- r
.y
;
1945 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1948 if (r
.y
< row_y
+ s
->row
->visible_height
)
1949 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1951 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1952 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1960 #ifdef CONVERT_FROM_XRECT
1961 for (i
= 0; i
< n
; i
++)
1962 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1969 Return in *NR the clipping rectangle for glyph string S. */
1972 get_glyph_string_clip_rect (s
, nr
)
1973 struct glyph_string
*s
;
1974 NativeRectangle
*nr
;
1976 get_glyph_string_clip_rects (s
, nr
, 1);
1981 Return the position and height of the phys cursor in window W.
1982 Set w->phys_cursor_width to width of phys cursor.
1986 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1988 struct glyph_row
*row
;
1989 struct glyph
*glyph
;
1992 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1993 int y
, wd
, h
, h0
, y0
;
1995 /* Compute the width of the rectangle to draw. If on a stretch
1996 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1997 rectangle as wide as the glyph, but use a canonical character
1999 wd
= glyph
->pixel_width
- 1;
2003 if (glyph
->type
== STRETCH_GLYPH
2004 && !x_stretch_cursor_p
)
2005 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2006 w
->phys_cursor_width
= wd
;
2008 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2010 /* If y is below window bottom, ensure that we still see a cursor. */
2011 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2013 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2014 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2016 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2019 h
= max (h
- (y0
- y
) + 1, h0
);
2024 y0
= window_text_bottom_y (w
) - h0
;
2033 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2037 * Remember which glyph the mouse is over.
2041 remember_mouse_glyph (f
, gx
, gy
, rect
)
2044 NativeRectangle
*rect
;
2048 struct glyph_row
*r
, *gr
, *end_row
;
2049 enum window_part part
;
2050 enum glyph_row_area area
;
2051 int x
, y
, width
, height
;
2053 /* Try to determine frame pixel position and size of the glyph under
2054 frame pixel coordinates X/Y on frame F. */
2056 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2059 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2060 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2064 w
= XWINDOW (window
);
2065 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2066 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2068 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2069 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2071 if (w
->pseudo_window_p
)
2074 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2080 case ON_LEFT_MARGIN
:
2081 area
= LEFT_MARGIN_AREA
;
2084 case ON_RIGHT_MARGIN
:
2085 area
= RIGHT_MARGIN_AREA
;
2088 case ON_HEADER_LINE
:
2090 gr
= (part
== ON_HEADER_LINE
2091 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2092 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2095 goto text_glyph_row_found
;
2102 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2103 if (r
->y
+ r
->height
> y
)
2109 text_glyph_row_found
:
2112 struct glyph
*g
= gr
->glyphs
[area
];
2113 struct glyph
*end
= g
+ gr
->used
[area
];
2115 height
= gr
->height
;
2116 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2117 if (gx
+ g
->pixel_width
> x
)
2122 if (g
->type
== IMAGE_GLYPH
)
2124 /* Don't remember when mouse is over image, as
2125 image may have hot-spots. */
2126 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2129 width
= g
->pixel_width
;
2133 /* Use nominal char spacing at end of line. */
2135 gx
+= (x
/ width
) * width
;
2138 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2139 gx
+= window_box_left_offset (w
, area
);
2143 /* Use nominal line height at end of window. */
2144 gx
= (x
/ width
) * width
;
2146 gy
+= (y
/ height
) * height
;
2150 case ON_LEFT_FRINGE
:
2151 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2152 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2153 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2154 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2157 case ON_RIGHT_FRINGE
:
2158 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2159 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2160 : window_box_right_offset (w
, TEXT_AREA
));
2161 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2165 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2167 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2168 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2169 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2171 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2175 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2176 if (r
->y
+ r
->height
> y
)
2183 height
= gr
->height
;
2186 /* Use nominal line height at end of window. */
2188 gy
+= (y
/ height
) * height
;
2195 /* If there is no glyph under the mouse, then we divide the screen
2196 into a grid of the smallest glyph in the frame, and use that
2199 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2200 round down even for negative values. */
2206 gx
= (gx
/ width
) * width
;
2207 gy
= (gy
/ height
) * height
;
2212 gx
+= WINDOW_LEFT_EDGE_X (w
);
2213 gy
+= WINDOW_TOP_EDGE_Y (w
);
2216 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2218 /* Visible feedback for debugging. */
2221 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2222 f
->output_data
.x
->normal_gc
,
2223 gx
, gy
, width
, height
);
2229 #endif /* HAVE_WINDOW_SYSTEM */
2232 /***********************************************************************
2233 Lisp form evaluation
2234 ***********************************************************************/
2236 /* Error handler for safe_eval and safe_call. */
2239 safe_eval_handler (arg
)
2242 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2247 /* Evaluate SEXPR and return the result, or nil if something went
2248 wrong. Prevent redisplay during the evaluation. */
2256 if (inhibit_eval_during_redisplay
)
2260 int count
= SPECPDL_INDEX ();
2261 struct gcpro gcpro1
;
2264 specbind (Qinhibit_redisplay
, Qt
);
2265 /* Use Qt to ensure debugger does not run,
2266 so there is no possibility of wanting to redisplay. */
2267 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2270 val
= unbind_to (count
, val
);
2277 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2278 Return the result, or nil if something went wrong. Prevent
2279 redisplay during the evaluation. */
2282 safe_call (nargs
, args
)
2288 if (inhibit_eval_during_redisplay
)
2292 int count
= SPECPDL_INDEX ();
2293 struct gcpro gcpro1
;
2296 gcpro1
.nvars
= nargs
;
2297 specbind (Qinhibit_redisplay
, Qt
);
2298 /* Use Qt to ensure debugger does not run,
2299 so there is no possibility of wanting to redisplay. */
2300 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2303 val
= unbind_to (count
, val
);
2310 /* Call function FN with one argument ARG.
2311 Return the result, or nil if something went wrong. */
2314 safe_call1 (fn
, arg
)
2315 Lisp_Object fn
, arg
;
2317 Lisp_Object args
[2];
2320 return safe_call (2, args
);
2325 /***********************************************************************
2327 ***********************************************************************/
2331 /* Define CHECK_IT to perform sanity checks on iterators.
2332 This is for debugging. It is too slow to do unconditionally. */
2338 if (it
->method
== GET_FROM_STRING
)
2340 xassert (STRINGP (it
->string
));
2341 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2345 xassert (IT_STRING_CHARPOS (*it
) < 0);
2346 if (it
->method
== GET_FROM_BUFFER
)
2348 /* Check that character and byte positions agree. */
2349 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2354 xassert (it
->current
.dpvec_index
>= 0);
2356 xassert (it
->current
.dpvec_index
< 0);
2359 #define CHECK_IT(IT) check_it ((IT))
2363 #define CHECK_IT(IT) (void) 0
2370 /* Check that the window end of window W is what we expect it
2371 to be---the last row in the current matrix displaying text. */
2374 check_window_end (w
)
2377 if (!MINI_WINDOW_P (w
)
2378 && !NILP (w
->window_end_valid
))
2380 struct glyph_row
*row
;
2381 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2382 XFASTINT (w
->window_end_vpos
)),
2384 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2385 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2389 #define CHECK_WINDOW_END(W) check_window_end ((W))
2391 #else /* not GLYPH_DEBUG */
2393 #define CHECK_WINDOW_END(W) (void) 0
2395 #endif /* not GLYPH_DEBUG */
2399 /***********************************************************************
2400 Iterator initialization
2401 ***********************************************************************/
2403 /* Initialize IT for displaying current_buffer in window W, starting
2404 at character position CHARPOS. CHARPOS < 0 means that no buffer
2405 position is specified which is useful when the iterator is assigned
2406 a position later. BYTEPOS is the byte position corresponding to
2407 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2409 If ROW is not null, calls to produce_glyphs with IT as parameter
2410 will produce glyphs in that row.
2412 BASE_FACE_ID is the id of a base face to use. It must be one of
2413 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2414 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2415 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2417 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2418 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2419 will be initialized to use the corresponding mode line glyph row of
2420 the desired matrix of W. */
2423 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2426 int charpos
, bytepos
;
2427 struct glyph_row
*row
;
2428 enum face_id base_face_id
;
2430 int highlight_region_p
;
2432 /* Some precondition checks. */
2433 xassert (w
!= NULL
&& it
!= NULL
);
2434 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2437 /* If face attributes have been changed since the last redisplay,
2438 free realized faces now because they depend on face definitions
2439 that might have changed. Don't free faces while there might be
2440 desired matrices pending which reference these faces. */
2441 if (face_change_count
&& !inhibit_free_realized_faces
)
2443 face_change_count
= 0;
2444 free_all_realized_faces (Qnil
);
2447 /* Use one of the mode line rows of W's desired matrix if
2451 if (base_face_id
== MODE_LINE_FACE_ID
2452 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2453 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2454 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2455 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2459 bzero (it
, sizeof *it
);
2460 it
->current
.overlay_string_index
= -1;
2461 it
->current
.dpvec_index
= -1;
2462 it
->base_face_id
= base_face_id
;
2464 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2466 /* The window in which we iterate over current_buffer: */
2467 XSETWINDOW (it
->window
, w
);
2469 it
->f
= XFRAME (w
->frame
);
2471 /* Extra space between lines (on window systems only). */
2472 if (base_face_id
== DEFAULT_FACE_ID
2473 && FRAME_WINDOW_P (it
->f
))
2475 if (NATNUMP (current_buffer
->extra_line_spacing
))
2476 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2477 else if (FLOATP (current_buffer
->extra_line_spacing
))
2478 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2479 * FRAME_LINE_HEIGHT (it
->f
));
2480 else if (it
->f
->extra_line_spacing
> 0)
2481 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2482 it
->max_extra_line_spacing
= 0;
2485 /* If realized faces have been removed, e.g. because of face
2486 attribute changes of named faces, recompute them. When running
2487 in batch mode, the face cache of Vterminal_frame is null. If
2488 we happen to get called, make a dummy face cache. */
2489 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2490 init_frame_faces (it
->f
);
2491 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2492 recompute_basic_faces (it
->f
);
2494 /* Current value of the `slice', `space-width', and 'height' properties. */
2495 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2496 it
->space_width
= Qnil
;
2497 it
->font_height
= Qnil
;
2498 it
->override_ascent
= -1;
2500 /* Are control characters displayed as `^C'? */
2501 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2503 /* -1 means everything between a CR and the following line end
2504 is invisible. >0 means lines indented more than this value are
2506 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2507 ? XFASTINT (current_buffer
->selective_display
)
2508 : (!NILP (current_buffer
->selective_display
)
2510 it
->selective_display_ellipsis_p
2511 = !NILP (current_buffer
->selective_display_ellipses
);
2513 /* Display table to use. */
2514 it
->dp
= window_display_table (w
);
2516 /* Are multibyte characters enabled in current_buffer? */
2517 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2519 /* Non-zero if we should highlight the region. */
2521 = (!NILP (Vtransient_mark_mode
)
2522 && !NILP (current_buffer
->mark_active
)
2523 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2525 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2526 start and end of a visible region in window IT->w. Set both to
2527 -1 to indicate no region. */
2528 if (highlight_region_p
2529 /* Maybe highlight only in selected window. */
2530 && (/* Either show region everywhere. */
2531 highlight_nonselected_windows
2532 /* Or show region in the selected window. */
2533 || w
== XWINDOW (selected_window
)
2534 /* Or show the region if we are in the mini-buffer and W is
2535 the window the mini-buffer refers to. */
2536 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2537 && WINDOWP (minibuf_selected_window
)
2538 && w
== XWINDOW (minibuf_selected_window
))))
2540 int charpos
= marker_position (current_buffer
->mark
);
2541 it
->region_beg_charpos
= min (PT
, charpos
);
2542 it
->region_end_charpos
= max (PT
, charpos
);
2545 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2547 /* Get the position at which the redisplay_end_trigger hook should
2548 be run, if it is to be run at all. */
2549 if (MARKERP (w
->redisplay_end_trigger
)
2550 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2551 it
->redisplay_end_trigger_charpos
2552 = marker_position (w
->redisplay_end_trigger
);
2553 else if (INTEGERP (w
->redisplay_end_trigger
))
2554 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2556 /* Correct bogus values of tab_width. */
2557 it
->tab_width
= XINT (current_buffer
->tab_width
);
2558 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2561 /* Are lines in the display truncated? */
2562 it
->truncate_lines_p
2563 = (base_face_id
!= DEFAULT_FACE_ID
2564 || XINT (it
->w
->hscroll
)
2565 || (truncate_partial_width_windows
2566 && !WINDOW_FULL_WIDTH_P (it
->w
))
2567 || !NILP (current_buffer
->truncate_lines
));
2569 /* Get dimensions of truncation and continuation glyphs. These are
2570 displayed as fringe bitmaps under X, so we don't need them for such
2572 if (!FRAME_WINDOW_P (it
->f
))
2574 if (it
->truncate_lines_p
)
2576 /* We will need the truncation glyph. */
2577 xassert (it
->glyph_row
== NULL
);
2578 produce_special_glyphs (it
, IT_TRUNCATION
);
2579 it
->truncation_pixel_width
= it
->pixel_width
;
2583 /* We will need the continuation glyph. */
2584 xassert (it
->glyph_row
== NULL
);
2585 produce_special_glyphs (it
, IT_CONTINUATION
);
2586 it
->continuation_pixel_width
= it
->pixel_width
;
2589 /* Reset these values to zero because the produce_special_glyphs
2590 above has changed them. */
2591 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2592 it
->phys_ascent
= it
->phys_descent
= 0;
2595 /* Set this after getting the dimensions of truncation and
2596 continuation glyphs, so that we don't produce glyphs when calling
2597 produce_special_glyphs, above. */
2598 it
->glyph_row
= row
;
2599 it
->area
= TEXT_AREA
;
2601 /* Get the dimensions of the display area. The display area
2602 consists of the visible window area plus a horizontally scrolled
2603 part to the left of the window. All x-values are relative to the
2604 start of this total display area. */
2605 if (base_face_id
!= DEFAULT_FACE_ID
)
2607 /* Mode lines, menu bar in terminal frames. */
2608 it
->first_visible_x
= 0;
2609 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2614 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2615 it
->last_visible_x
= (it
->first_visible_x
2616 + window_box_width (w
, TEXT_AREA
));
2618 /* If we truncate lines, leave room for the truncator glyph(s) at
2619 the right margin. Otherwise, leave room for the continuation
2620 glyph(s). Truncation and continuation glyphs are not inserted
2621 for window-based redisplay. */
2622 if (!FRAME_WINDOW_P (it
->f
))
2624 if (it
->truncate_lines_p
)
2625 it
->last_visible_x
-= it
->truncation_pixel_width
;
2627 it
->last_visible_x
-= it
->continuation_pixel_width
;
2630 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2631 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2634 /* Leave room for a border glyph. */
2635 if (!FRAME_WINDOW_P (it
->f
)
2636 && !WINDOW_RIGHTMOST_P (it
->w
))
2637 it
->last_visible_x
-= 1;
2639 it
->last_visible_y
= window_text_bottom_y (w
);
2641 /* For mode lines and alike, arrange for the first glyph having a
2642 left box line if the face specifies a box. */
2643 if (base_face_id
!= DEFAULT_FACE_ID
)
2647 it
->face_id
= base_face_id
;
2649 /* If we have a boxed mode line, make the first character appear
2650 with a left box line. */
2651 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2652 if (face
->box
!= FACE_NO_BOX
)
2653 it
->start_of_box_run_p
= 1;
2656 /* If a buffer position was specified, set the iterator there,
2657 getting overlays and face properties from that position. */
2658 if (charpos
>= BUF_BEG (current_buffer
))
2660 it
->end_charpos
= ZV
;
2662 IT_CHARPOS (*it
) = charpos
;
2664 /* Compute byte position if not specified. */
2665 if (bytepos
< charpos
)
2666 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2668 IT_BYTEPOS (*it
) = bytepos
;
2670 it
->start
= it
->current
;
2672 /* Compute faces etc. */
2673 reseat (it
, it
->current
.pos
, 1);
2680 /* Initialize IT for the display of window W with window start POS. */
2683 start_display (it
, w
, pos
)
2686 struct text_pos pos
;
2688 struct glyph_row
*row
;
2689 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2691 row
= w
->desired_matrix
->rows
+ first_vpos
;
2692 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2693 it
->first_vpos
= first_vpos
;
2695 /* Don't reseat to previous visible line start if current start
2696 position is in a string or image. */
2697 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2699 int start_at_line_beg_p
;
2700 int first_y
= it
->current_y
;
2702 /* If window start is not at a line start, skip forward to POS to
2703 get the correct continuation lines width. */
2704 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2705 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2706 if (!start_at_line_beg_p
)
2710 reseat_at_previous_visible_line_start (it
);
2711 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2713 new_x
= it
->current_x
+ it
->pixel_width
;
2715 /* If lines are continued, this line may end in the middle
2716 of a multi-glyph character (e.g. a control character
2717 displayed as \003, or in the middle of an overlay
2718 string). In this case move_it_to above will not have
2719 taken us to the start of the continuation line but to the
2720 end of the continued line. */
2721 if (it
->current_x
> 0
2722 && !it
->truncate_lines_p
/* Lines are continued. */
2723 && (/* And glyph doesn't fit on the line. */
2724 new_x
> it
->last_visible_x
2725 /* Or it fits exactly and we're on a window
2727 || (new_x
== it
->last_visible_x
2728 && FRAME_WINDOW_P (it
->f
))))
2730 if (it
->current
.dpvec_index
>= 0
2731 || it
->current
.overlay_string_index
>= 0)
2733 set_iterator_to_next (it
, 1);
2734 move_it_in_display_line_to (it
, -1, -1, 0);
2737 it
->continuation_lines_width
+= it
->current_x
;
2740 /* We're starting a new display line, not affected by the
2741 height of the continued line, so clear the appropriate
2742 fields in the iterator structure. */
2743 it
->max_ascent
= it
->max_descent
= 0;
2744 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2746 it
->current_y
= first_y
;
2748 it
->current_x
= it
->hpos
= 0;
2752 #if 0 /* Don't assert the following because start_display is sometimes
2753 called intentionally with a window start that is not at a
2754 line start. Please leave this code in as a comment. */
2756 /* Window start should be on a line start, now. */
2757 xassert (it
->continuation_lines_width
2758 || IT_CHARPOS (it
) == BEGV
2759 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2764 /* Return 1 if POS is a position in ellipses displayed for invisible
2765 text. W is the window we display, for text property lookup. */
2768 in_ellipses_for_invisible_text_p (pos
, w
)
2769 struct display_pos
*pos
;
2772 Lisp_Object prop
, window
;
2774 int charpos
= CHARPOS (pos
->pos
);
2776 /* If POS specifies a position in a display vector, this might
2777 be for an ellipsis displayed for invisible text. We won't
2778 get the iterator set up for delivering that ellipsis unless
2779 we make sure that it gets aware of the invisible text. */
2780 if (pos
->dpvec_index
>= 0
2781 && pos
->overlay_string_index
< 0
2782 && CHARPOS (pos
->string_pos
) < 0
2784 && (XSETWINDOW (window
, w
),
2785 prop
= Fget_char_property (make_number (charpos
),
2786 Qinvisible
, window
),
2787 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2789 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2791 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2798 /* Initialize IT for stepping through current_buffer in window W,
2799 starting at position POS that includes overlay string and display
2800 vector/ control character translation position information. Value
2801 is zero if there are overlay strings with newlines at POS. */
2804 init_from_display_pos (it
, w
, pos
)
2807 struct display_pos
*pos
;
2809 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2810 int i
, overlay_strings_with_newlines
= 0;
2812 /* If POS specifies a position in a display vector, this might
2813 be for an ellipsis displayed for invisible text. We won't
2814 get the iterator set up for delivering that ellipsis unless
2815 we make sure that it gets aware of the invisible text. */
2816 if (in_ellipses_for_invisible_text_p (pos
, w
))
2822 /* Keep in mind: the call to reseat in init_iterator skips invisible
2823 text, so we might end up at a position different from POS. This
2824 is only a problem when POS is a row start after a newline and an
2825 overlay starts there with an after-string, and the overlay has an
2826 invisible property. Since we don't skip invisible text in
2827 display_line and elsewhere immediately after consuming the
2828 newline before the row start, such a POS will not be in a string,
2829 but the call to init_iterator below will move us to the
2831 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2833 /* This only scans the current chunk -- it should scan all chunks.
2834 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2835 to 16 in 22.1 to make this a lesser problem. */
2836 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2838 const char *s
= SDATA (it
->overlay_strings
[i
]);
2839 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2841 while (s
< e
&& *s
!= '\n')
2846 overlay_strings_with_newlines
= 1;
2851 /* If position is within an overlay string, set up IT to the right
2853 if (pos
->overlay_string_index
>= 0)
2857 /* If the first overlay string happens to have a `display'
2858 property for an image, the iterator will be set up for that
2859 image, and we have to undo that setup first before we can
2860 correct the overlay string index. */
2861 if (it
->method
== GET_FROM_IMAGE
)
2864 /* We already have the first chunk of overlay strings in
2865 IT->overlay_strings. Load more until the one for
2866 pos->overlay_string_index is in IT->overlay_strings. */
2867 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2869 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2870 it
->current
.overlay_string_index
= 0;
2873 load_overlay_strings (it
, 0);
2874 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2878 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2879 relative_index
= (it
->current
.overlay_string_index
2880 % OVERLAY_STRING_CHUNK_SIZE
);
2881 it
->string
= it
->overlay_strings
[relative_index
];
2882 xassert (STRINGP (it
->string
));
2883 it
->current
.string_pos
= pos
->string_pos
;
2884 it
->method
= GET_FROM_STRING
;
2887 #if 0 /* This is bogus because POS not having an overlay string
2888 position does not mean it's after the string. Example: A
2889 line starting with a before-string and initialization of IT
2890 to the previous row's end position. */
2891 else if (it
->current
.overlay_string_index
>= 0)
2893 /* If POS says we're already after an overlay string ending at
2894 POS, make sure to pop the iterator because it will be in
2895 front of that overlay string. When POS is ZV, we've thereby
2896 also ``processed'' overlay strings at ZV. */
2899 it
->current
.overlay_string_index
= -1;
2900 it
->method
= GET_FROM_BUFFER
;
2901 if (CHARPOS (pos
->pos
) == ZV
)
2902 it
->overlay_strings_at_end_processed_p
= 1;
2906 if (CHARPOS (pos
->string_pos
) >= 0)
2908 /* Recorded position is not in an overlay string, but in another
2909 string. This can only be a string from a `display' property.
2910 IT should already be filled with that string. */
2911 it
->current
.string_pos
= pos
->string_pos
;
2912 xassert (STRINGP (it
->string
));
2915 /* Restore position in display vector translations, control
2916 character translations or ellipses. */
2917 if (pos
->dpvec_index
>= 0)
2919 if (it
->dpvec
== NULL
)
2920 get_next_display_element (it
);
2921 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2922 it
->current
.dpvec_index
= pos
->dpvec_index
;
2926 return !overlay_strings_with_newlines
;
2930 /* Initialize IT for stepping through current_buffer in window W
2931 starting at ROW->start. */
2934 init_to_row_start (it
, w
, row
)
2937 struct glyph_row
*row
;
2939 init_from_display_pos (it
, w
, &row
->start
);
2940 it
->start
= row
->start
;
2941 it
->continuation_lines_width
= row
->continuation_lines_width
;
2946 /* Initialize IT for stepping through current_buffer in window W
2947 starting in the line following ROW, i.e. starting at ROW->end.
2948 Value is zero if there are overlay strings with newlines at ROW's
2952 init_to_row_end (it
, w
, row
)
2955 struct glyph_row
*row
;
2959 if (init_from_display_pos (it
, w
, &row
->end
))
2961 if (row
->continued_p
)
2962 it
->continuation_lines_width
2963 = row
->continuation_lines_width
+ row
->pixel_width
;
2974 /***********************************************************************
2976 ***********************************************************************/
2978 /* Called when IT reaches IT->stop_charpos. Handle text property and
2979 overlay changes. Set IT->stop_charpos to the next position where
2986 enum prop_handled handled
;
2987 int handle_overlay_change_p
;
2991 it
->current
.dpvec_index
= -1;
2992 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2993 it
->ignore_overlay_strings_at_pos_p
= 0;
2995 /* Use face of preceding text for ellipsis (if invisible) */
2996 if (it
->selective_display_ellipsis_p
)
2997 it
->saved_face_id
= it
->face_id
;
3001 handled
= HANDLED_NORMALLY
;
3003 /* Call text property handlers. */
3004 for (p
= it_props
; p
->handler
; ++p
)
3006 handled
= p
->handler (it
);
3008 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3010 else if (handled
== HANDLED_RETURN
)
3012 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3013 handle_overlay_change_p
= 0;
3016 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3018 /* Don't check for overlay strings below when set to deliver
3019 characters from a display vector. */
3020 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3021 handle_overlay_change_p
= 0;
3023 /* Handle overlay changes. */
3024 if (handle_overlay_change_p
)
3025 handled
= handle_overlay_change (it
);
3027 /* Determine where to stop next. */
3028 if (handled
== HANDLED_NORMALLY
)
3029 compute_stop_pos (it
);
3032 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3036 /* Compute IT->stop_charpos from text property and overlay change
3037 information for IT's current position. */
3040 compute_stop_pos (it
)
3043 register INTERVAL iv
, next_iv
;
3044 Lisp_Object object
, limit
, position
;
3046 /* If nowhere else, stop at the end. */
3047 it
->stop_charpos
= it
->end_charpos
;
3049 if (STRINGP (it
->string
))
3051 /* Strings are usually short, so don't limit the search for
3053 object
= it
->string
;
3055 position
= make_number (IT_STRING_CHARPOS (*it
));
3061 /* If next overlay change is in front of the current stop pos
3062 (which is IT->end_charpos), stop there. Note: value of
3063 next_overlay_change is point-max if no overlay change
3065 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3066 if (charpos
< it
->stop_charpos
)
3067 it
->stop_charpos
= charpos
;
3069 /* If showing the region, we have to stop at the region
3070 start or end because the face might change there. */
3071 if (it
->region_beg_charpos
> 0)
3073 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3074 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3075 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3076 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3079 /* Set up variables for computing the stop position from text
3080 property changes. */
3081 XSETBUFFER (object
, current_buffer
);
3082 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3083 position
= make_number (IT_CHARPOS (*it
));
3087 /* Get the interval containing IT's position. Value is a null
3088 interval if there isn't such an interval. */
3089 iv
= validate_interval_range (object
, &position
, &position
, 0);
3090 if (!NULL_INTERVAL_P (iv
))
3092 Lisp_Object values_here
[LAST_PROP_IDX
];
3095 /* Get properties here. */
3096 for (p
= it_props
; p
->handler
; ++p
)
3097 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3099 /* Look for an interval following iv that has different
3101 for (next_iv
= next_interval (iv
);
3102 (!NULL_INTERVAL_P (next_iv
)
3104 || XFASTINT (limit
) > next_iv
->position
));
3105 next_iv
= next_interval (next_iv
))
3107 for (p
= it_props
; p
->handler
; ++p
)
3109 Lisp_Object new_value
;
3111 new_value
= textget (next_iv
->plist
, *p
->name
);
3112 if (!EQ (values_here
[p
->idx
], new_value
))
3120 if (!NULL_INTERVAL_P (next_iv
))
3122 if (INTEGERP (limit
)
3123 && next_iv
->position
>= XFASTINT (limit
))
3124 /* No text property change up to limit. */
3125 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3127 /* Text properties change in next_iv. */
3128 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3132 xassert (STRINGP (it
->string
)
3133 || (it
->stop_charpos
>= BEGV
3134 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3138 /* Return the position of the next overlay change after POS in
3139 current_buffer. Value is point-max if no overlay change
3140 follows. This is like `next-overlay-change' but doesn't use
3144 next_overlay_change (pos
)
3149 Lisp_Object
*overlays
;
3152 /* Get all overlays at the given position. */
3153 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3155 /* If any of these overlays ends before endpos,
3156 use its ending point instead. */
3157 for (i
= 0; i
< noverlays
; ++i
)
3162 oend
= OVERLAY_END (overlays
[i
]);
3163 oendpos
= OVERLAY_POSITION (oend
);
3164 endpos
= min (endpos
, oendpos
);
3172 /***********************************************************************
3174 ***********************************************************************/
3176 /* Handle changes in the `fontified' property of the current buffer by
3177 calling hook functions from Qfontification_functions to fontify
3180 static enum prop_handled
3181 handle_fontified_prop (it
)
3184 Lisp_Object prop
, pos
;
3185 enum prop_handled handled
= HANDLED_NORMALLY
;
3187 if (!NILP (Vmemory_full
))
3190 /* Get the value of the `fontified' property at IT's current buffer
3191 position. (The `fontified' property doesn't have a special
3192 meaning in strings.) If the value is nil, call functions from
3193 Qfontification_functions. */
3194 if (!STRINGP (it
->string
)
3196 && !NILP (Vfontification_functions
)
3197 && !NILP (Vrun_hooks
)
3198 && (pos
= make_number (IT_CHARPOS (*it
)),
3199 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3202 int count
= SPECPDL_INDEX ();
3205 val
= Vfontification_functions
;
3206 specbind (Qfontification_functions
, Qnil
);
3208 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3209 safe_call1 (val
, pos
);
3212 Lisp_Object globals
, fn
;
3213 struct gcpro gcpro1
, gcpro2
;
3216 GCPRO2 (val
, globals
);
3218 for (; CONSP (val
); val
= XCDR (val
))
3224 /* A value of t indicates this hook has a local
3225 binding; it means to run the global binding too.
3226 In a global value, t should not occur. If it
3227 does, we must ignore it to avoid an endless
3229 for (globals
= Fdefault_value (Qfontification_functions
);
3231 globals
= XCDR (globals
))
3233 fn
= XCAR (globals
);
3235 safe_call1 (fn
, pos
);
3239 safe_call1 (fn
, pos
);
3245 unbind_to (count
, Qnil
);
3247 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3248 something. This avoids an endless loop if they failed to
3249 fontify the text for which reason ever. */
3250 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3251 handled
= HANDLED_RECOMPUTE_PROPS
;
3259 /***********************************************************************
3261 ***********************************************************************/
3263 /* Set up iterator IT from face properties at its current position.
3264 Called from handle_stop. */
3266 static enum prop_handled
3267 handle_face_prop (it
)
3270 int new_face_id
, next_stop
;
3272 if (!STRINGP (it
->string
))
3275 = face_at_buffer_position (it
->w
,
3277 it
->region_beg_charpos
,
3278 it
->region_end_charpos
,
3281 + TEXT_PROP_DISTANCE_LIMIT
),
3284 /* Is this a start of a run of characters with box face?
3285 Caveat: this can be called for a freshly initialized
3286 iterator; face_id is -1 in this case. We know that the new
3287 face will not change until limit, i.e. if the new face has a
3288 box, all characters up to limit will have one. But, as
3289 usual, we don't know whether limit is really the end. */
3290 if (new_face_id
!= it
->face_id
)
3292 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3294 /* If new face has a box but old face has not, this is
3295 the start of a run of characters with box, i.e. it has
3296 a shadow on the left side. The value of face_id of the
3297 iterator will be -1 if this is the initial call that gets
3298 the face. In this case, we have to look in front of IT's
3299 position and see whether there is a face != new_face_id. */
3300 it
->start_of_box_run_p
3301 = (new_face
->box
!= FACE_NO_BOX
3302 && (it
->face_id
>= 0
3303 || IT_CHARPOS (*it
) == BEG
3304 || new_face_id
!= face_before_it_pos (it
)));
3305 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3310 int base_face_id
, bufpos
;
3312 if (it
->current
.overlay_string_index
>= 0)
3313 bufpos
= IT_CHARPOS (*it
);
3317 /* For strings from a buffer, i.e. overlay strings or strings
3318 from a `display' property, use the face at IT's current
3319 buffer position as the base face to merge with, so that
3320 overlay strings appear in the same face as surrounding
3321 text, unless they specify their own faces. */
3322 base_face_id
= underlying_face_id (it
);
3324 new_face_id
= face_at_string_position (it
->w
,
3326 IT_STRING_CHARPOS (*it
),
3328 it
->region_beg_charpos
,
3329 it
->region_end_charpos
,
3333 #if 0 /* This shouldn't be neccessary. Let's check it. */
3334 /* If IT is used to display a mode line we would really like to
3335 use the mode line face instead of the frame's default face. */
3336 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3337 && new_face_id
== DEFAULT_FACE_ID
)
3338 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3341 /* Is this a start of a run of characters with box? Caveat:
3342 this can be called for a freshly allocated iterator; face_id
3343 is -1 is this case. We know that the new face will not
3344 change until the next check pos, i.e. if the new face has a
3345 box, all characters up to that position will have a
3346 box. But, as usual, we don't know whether that position
3347 is really the end. */
3348 if (new_face_id
!= it
->face_id
)
3350 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3351 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3353 /* If new face has a box but old face hasn't, this is the
3354 start of a run of characters with box, i.e. it has a
3355 shadow on the left side. */
3356 it
->start_of_box_run_p
3357 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3358 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3362 it
->face_id
= new_face_id
;
3363 return HANDLED_NORMALLY
;
3367 /* Return the ID of the face ``underlying'' IT's current position,
3368 which is in a string. If the iterator is associated with a
3369 buffer, return the face at IT's current buffer position.
3370 Otherwise, use the iterator's base_face_id. */
3373 underlying_face_id (it
)
3376 int face_id
= it
->base_face_id
, i
;
3378 xassert (STRINGP (it
->string
));
3380 for (i
= it
->sp
- 1; i
>= 0; --i
)
3381 if (NILP (it
->stack
[i
].string
))
3382 face_id
= it
->stack
[i
].face_id
;
3388 /* Compute the face one character before or after the current position
3389 of IT. BEFORE_P non-zero means get the face in front of IT's
3390 position. Value is the id of the face. */
3393 face_before_or_after_it_pos (it
, before_p
)
3398 int next_check_charpos
;
3399 struct text_pos pos
;
3401 xassert (it
->s
== NULL
);
3403 if (STRINGP (it
->string
))
3405 int bufpos
, base_face_id
;
3407 /* No face change past the end of the string (for the case
3408 we are padding with spaces). No face change before the
3410 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3411 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3414 /* Set pos to the position before or after IT's current position. */
3416 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3418 /* For composition, we must check the character after the
3420 pos
= (it
->what
== IT_COMPOSITION
3421 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3422 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3424 if (it
->current
.overlay_string_index
>= 0)
3425 bufpos
= IT_CHARPOS (*it
);
3429 base_face_id
= underlying_face_id (it
);
3431 /* Get the face for ASCII, or unibyte. */
3432 face_id
= face_at_string_position (it
->w
,
3436 it
->region_beg_charpos
,
3437 it
->region_end_charpos
,
3438 &next_check_charpos
,
3441 /* Correct the face for charsets different from ASCII. Do it
3442 for the multibyte case only. The face returned above is
3443 suitable for unibyte text if IT->string is unibyte. */
3444 if (STRING_MULTIBYTE (it
->string
))
3446 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3447 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3449 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3451 c
= string_char_and_length (p
, rest
, &len
);
3452 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3457 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3458 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3461 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3462 pos
= it
->current
.pos
;
3465 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3468 if (it
->what
== IT_COMPOSITION
)
3469 /* For composition, we must check the position after the
3471 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3473 INC_TEXT_POS (pos
, it
->multibyte_p
);
3476 /* Determine face for CHARSET_ASCII, or unibyte. */
3477 face_id
= face_at_buffer_position (it
->w
,
3479 it
->region_beg_charpos
,
3480 it
->region_end_charpos
,
3481 &next_check_charpos
,
3484 /* Correct the face for charsets different from ASCII. Do it
3485 for the multibyte case only. The face returned above is
3486 suitable for unibyte text if current_buffer is unibyte. */
3487 if (it
->multibyte_p
)
3489 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3490 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3491 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3500 /***********************************************************************
3502 ***********************************************************************/
3504 /* Set up iterator IT from invisible properties at its current
3505 position. Called from handle_stop. */
3507 static enum prop_handled
3508 handle_invisible_prop (it
)
3511 enum prop_handled handled
= HANDLED_NORMALLY
;
3513 if (STRINGP (it
->string
))
3515 extern Lisp_Object Qinvisible
;
3516 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3518 /* Get the value of the invisible text property at the
3519 current position. Value will be nil if there is no such
3521 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3522 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3525 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3527 handled
= HANDLED_RECOMPUTE_PROPS
;
3529 /* Get the position at which the next change of the
3530 invisible text property can be found in IT->string.
3531 Value will be nil if the property value is the same for
3532 all the rest of IT->string. */
3533 XSETINT (limit
, SCHARS (it
->string
));
3534 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3537 /* Text at current position is invisible. The next
3538 change in the property is at position end_charpos.
3539 Move IT's current position to that position. */
3540 if (INTEGERP (end_charpos
)
3541 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3543 struct text_pos old
;
3544 old
= it
->current
.string_pos
;
3545 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3546 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3550 /* The rest of the string is invisible. If this is an
3551 overlay string, proceed with the next overlay string
3552 or whatever comes and return a character from there. */
3553 if (it
->current
.overlay_string_index
>= 0)
3555 next_overlay_string (it
);
3556 /* Don't check for overlay strings when we just
3557 finished processing them. */
3558 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3562 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3563 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3570 int invis_p
, newpos
, next_stop
, start_charpos
;
3571 Lisp_Object pos
, prop
, overlay
;
3573 /* First of all, is there invisible text at this position? */
3574 start_charpos
= IT_CHARPOS (*it
);
3575 pos
= make_number (IT_CHARPOS (*it
));
3576 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3578 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3580 /* If we are on invisible text, skip over it. */
3581 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3583 /* Record whether we have to display an ellipsis for the
3585 int display_ellipsis_p
= invis_p
== 2;
3587 handled
= HANDLED_RECOMPUTE_PROPS
;
3589 /* Loop skipping over invisible text. The loop is left at
3590 ZV or with IT on the first char being visible again. */
3593 /* Try to skip some invisible text. Return value is the
3594 position reached which can be equal to IT's position
3595 if there is nothing invisible here. This skips both
3596 over invisible text properties and overlays with
3597 invisible property. */
3598 newpos
= skip_invisible (IT_CHARPOS (*it
),
3599 &next_stop
, ZV
, it
->window
);
3601 /* If we skipped nothing at all we weren't at invisible
3602 text in the first place. If everything to the end of
3603 the buffer was skipped, end the loop. */
3604 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3608 /* We skipped some characters but not necessarily
3609 all there are. Check if we ended up on visible
3610 text. Fget_char_property returns the property of
3611 the char before the given position, i.e. if we
3612 get invis_p = 0, this means that the char at
3613 newpos is visible. */
3614 pos
= make_number (newpos
);
3615 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3616 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3619 /* If we ended up on invisible text, proceed to
3620 skip starting with next_stop. */
3622 IT_CHARPOS (*it
) = next_stop
;
3624 /* If there are adjacent invisible texts, don't lose the
3625 second one's ellipsis. */
3627 display_ellipsis_p
= 1;
3631 /* The position newpos is now either ZV or on visible text. */
3632 IT_CHARPOS (*it
) = newpos
;
3633 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3635 /* If there are before-strings at the start of invisible
3636 text, and the text is invisible because of a text
3637 property, arrange to show before-strings because 20.x did
3638 it that way. (If the text is invisible because of an
3639 overlay property instead of a text property, this is
3640 already handled in the overlay code.) */
3642 && get_overlay_strings (it
, start_charpos
))
3644 handled
= HANDLED_RECOMPUTE_PROPS
;
3645 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3647 else if (display_ellipsis_p
)
3649 /* Make sure that the glyphs of the ellipsis will get
3650 correct `charpos' values. If we would not update
3651 it->position here, the glyphs would belong to the
3652 last visible character _before_ the invisible
3653 text, which confuses `set_cursor_from_row'.
3655 We use the last invisible position instead of the
3656 first because this way the cursor is always drawn on
3657 the first "." of the ellipsis, whenever PT is inside
3658 the invisible text. Otherwise the cursor would be
3659 placed _after_ the ellipsis when the point is after the
3660 first invisible character. */
3661 if (!STRINGP (it
->object
))
3663 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3664 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3666 setup_for_ellipsis (it
, 0);
3675 /* Make iterator IT return `...' next.
3676 Replaces LEN characters from buffer. */
3679 setup_for_ellipsis (it
, len
)
3683 /* Use the display table definition for `...'. Invalid glyphs
3684 will be handled by the method returning elements from dpvec. */
3685 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3687 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3688 it
->dpvec
= v
->contents
;
3689 it
->dpend
= v
->contents
+ v
->size
;
3693 /* Default `...'. */
3694 it
->dpvec
= default_invis_vector
;
3695 it
->dpend
= default_invis_vector
+ 3;
3698 it
->dpvec_char_len
= len
;
3699 it
->current
.dpvec_index
= 0;
3700 it
->dpvec_face_id
= -1;
3702 /* Remember the current face id in case glyphs specify faces.
3703 IT's face is restored in set_iterator_to_next.
3704 saved_face_id was set to preceding char's face in handle_stop. */
3705 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3706 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3708 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3714 /***********************************************************************
3716 ***********************************************************************/
3718 /* Set up iterator IT from `display' property at its current position.
3719 Called from handle_stop.
3720 We return HANDLED_RETURN if some part of the display property
3721 overrides the display of the buffer text itself.
3722 Otherwise we return HANDLED_NORMALLY. */
3724 static enum prop_handled
3725 handle_display_prop (it
)
3728 Lisp_Object prop
, object
;
3729 struct text_pos
*position
;
3730 /* Nonzero if some property replaces the display of the text itself. */
3731 int display_replaced_p
= 0;
3733 if (STRINGP (it
->string
))
3735 object
= it
->string
;
3736 position
= &it
->current
.string_pos
;
3740 XSETWINDOW (object
, it
->w
);
3741 position
= &it
->current
.pos
;
3744 /* Reset those iterator values set from display property values. */
3745 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3746 it
->space_width
= Qnil
;
3747 it
->font_height
= Qnil
;
3750 /* We don't support recursive `display' properties, i.e. string
3751 values that have a string `display' property, that have a string
3752 `display' property etc. */
3753 if (!it
->string_from_display_prop_p
)
3754 it
->area
= TEXT_AREA
;
3756 prop
= Fget_char_property (make_number (position
->charpos
),
3759 return HANDLED_NORMALLY
;
3761 if (!STRINGP (it
->string
))
3762 object
= it
->w
->buffer
;
3765 /* Simple properties. */
3766 && !EQ (XCAR (prop
), Qimage
)
3767 && !EQ (XCAR (prop
), Qspace
)
3768 && !EQ (XCAR (prop
), Qwhen
)
3769 && !EQ (XCAR (prop
), Qslice
)
3770 && !EQ (XCAR (prop
), Qspace_width
)
3771 && !EQ (XCAR (prop
), Qheight
)
3772 && !EQ (XCAR (prop
), Qraise
)
3773 /* Marginal area specifications. */
3774 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3775 && !EQ (XCAR (prop
), Qleft_fringe
)
3776 && !EQ (XCAR (prop
), Qright_fringe
)
3777 && !NILP (XCAR (prop
)))
3779 for (; CONSP (prop
); prop
= XCDR (prop
))
3781 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3782 position
, display_replaced_p
))
3783 display_replaced_p
= 1;
3786 else if (VECTORP (prop
))
3789 for (i
= 0; i
< ASIZE (prop
); ++i
)
3790 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3791 position
, display_replaced_p
))
3792 display_replaced_p
= 1;
3796 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3797 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3798 return HANDLED_RECOMPUTE_PROPS
;
3800 display_replaced_p
= 1;
3803 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3807 /* Value is the position of the end of the `display' property starting
3808 at START_POS in OBJECT. */
3810 static struct text_pos
3811 display_prop_end (it
, object
, start_pos
)
3814 struct text_pos start_pos
;
3817 struct text_pos end_pos
;
3819 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3820 Qdisplay
, object
, Qnil
);
3821 CHARPOS (end_pos
) = XFASTINT (end
);
3822 if (STRINGP (object
))
3823 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3825 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3831 /* Set up IT from a single `display' specification PROP. OBJECT
3832 is the object in which the `display' property was found. *POSITION
3833 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3834 means that we previously saw a display specification which already
3835 replaced text display with something else, for example an image;
3836 we ignore such properties after the first one has been processed.
3838 If PROP is a `space' or `image' specification, and in some other
3839 cases too, set *POSITION to the position where the `display'
3842 Value is non-zero if something was found which replaces the display
3843 of buffer or string text. Specifically, the value is -1 if that
3844 "something" is "nothing". */
3847 handle_single_display_spec (it
, spec
, object
, position
,
3848 display_replaced_before_p
)
3852 struct text_pos
*position
;
3853 int display_replaced_before_p
;
3856 Lisp_Object location
, value
;
3857 struct text_pos start_pos
;
3860 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3861 If the result is non-nil, use VALUE instead of SPEC. */
3863 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3872 if (!NILP (form
) && !EQ (form
, Qt
))
3874 int count
= SPECPDL_INDEX ();
3875 struct gcpro gcpro1
;
3877 /* Bind `object' to the object having the `display' property, a
3878 buffer or string. Bind `position' to the position in the
3879 object where the property was found, and `buffer-position'
3880 to the current position in the buffer. */
3881 specbind (Qobject
, object
);
3882 specbind (Qposition
, make_number (CHARPOS (*position
)));
3883 specbind (Qbuffer_position
,
3884 make_number (STRINGP (object
)
3885 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3887 form
= safe_eval (form
);
3889 unbind_to (count
, Qnil
);
3895 /* Handle `(height HEIGHT)' specifications. */
3897 && EQ (XCAR (spec
), Qheight
)
3898 && CONSP (XCDR (spec
)))
3900 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3903 it
->font_height
= XCAR (XCDR (spec
));
3904 if (!NILP (it
->font_height
))
3906 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3907 int new_height
= -1;
3909 if (CONSP (it
->font_height
)
3910 && (EQ (XCAR (it
->font_height
), Qplus
)
3911 || EQ (XCAR (it
->font_height
), Qminus
))
3912 && CONSP (XCDR (it
->font_height
))
3913 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3915 /* `(+ N)' or `(- N)' where N is an integer. */
3916 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3917 if (EQ (XCAR (it
->font_height
), Qplus
))
3919 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3921 else if (FUNCTIONP (it
->font_height
))
3923 /* Call function with current height as argument.
3924 Value is the new height. */
3926 height
= safe_call1 (it
->font_height
,
3927 face
->lface
[LFACE_HEIGHT_INDEX
]);
3928 if (NUMBERP (height
))
3929 new_height
= XFLOATINT (height
);
3931 else if (NUMBERP (it
->font_height
))
3933 /* Value is a multiple of the canonical char height. */
3936 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3937 new_height
= (XFLOATINT (it
->font_height
)
3938 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3942 /* Evaluate IT->font_height with `height' bound to the
3943 current specified height to get the new height. */
3944 int count
= SPECPDL_INDEX ();
3946 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3947 value
= safe_eval (it
->font_height
);
3948 unbind_to (count
, Qnil
);
3950 if (NUMBERP (value
))
3951 new_height
= XFLOATINT (value
);
3955 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3961 /* Handle `(space_width WIDTH)'. */
3963 && EQ (XCAR (spec
), Qspace_width
)
3964 && CONSP (XCDR (spec
)))
3966 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3969 value
= XCAR (XCDR (spec
));
3970 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3971 it
->space_width
= value
;
3976 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3978 && EQ (XCAR (spec
), Qslice
))
3982 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3985 if (tem
= XCDR (spec
), CONSP (tem
))
3987 it
->slice
.x
= XCAR (tem
);
3988 if (tem
= XCDR (tem
), CONSP (tem
))
3990 it
->slice
.y
= XCAR (tem
);
3991 if (tem
= XCDR (tem
), CONSP (tem
))
3993 it
->slice
.width
= XCAR (tem
);
3994 if (tem
= XCDR (tem
), CONSP (tem
))
3995 it
->slice
.height
= XCAR (tem
);
4003 /* Handle `(raise FACTOR)'. */
4005 && EQ (XCAR (spec
), Qraise
)
4006 && CONSP (XCDR (spec
)))
4008 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4011 #ifdef HAVE_WINDOW_SYSTEM
4012 value
= XCAR (XCDR (spec
));
4013 if (NUMBERP (value
))
4015 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4016 it
->voffset
= - (XFLOATINT (value
)
4017 * (FONT_HEIGHT (face
->font
)));
4019 #endif /* HAVE_WINDOW_SYSTEM */
4024 /* Don't handle the other kinds of display specifications
4025 inside a string that we got from a `display' property. */
4026 if (it
->string_from_display_prop_p
)
4029 /* Characters having this form of property are not displayed, so
4030 we have to find the end of the property. */
4031 start_pos
= *position
;
4032 *position
= display_prop_end (it
, object
, start_pos
);
4035 /* Stop the scan at that end position--we assume that all
4036 text properties change there. */
4037 it
->stop_charpos
= position
->charpos
;
4039 /* Handle `(left-fringe BITMAP [FACE])'
4040 and `(right-fringe BITMAP [FACE])'. */
4042 && (EQ (XCAR (spec
), Qleft_fringe
)
4043 || EQ (XCAR (spec
), Qright_fringe
))
4044 && CONSP (XCDR (spec
)))
4046 int face_id
= DEFAULT_FACE_ID
;
4049 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4050 /* If we return here, POSITION has been advanced
4051 across the text with this property. */
4054 #ifdef HAVE_WINDOW_SYSTEM
4055 value
= XCAR (XCDR (spec
));
4056 if (!SYMBOLP (value
)
4057 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4058 /* If we return here, POSITION has been advanced
4059 across the text with this property. */
4062 if (CONSP (XCDR (XCDR (spec
))))
4064 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4065 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4066 'A', FRINGE_FACE_ID
, 0);
4071 /* Save current settings of IT so that we can restore them
4072 when we are finished with the glyph property value. */
4076 it
->area
= TEXT_AREA
;
4077 it
->what
= IT_IMAGE
;
4078 it
->image_id
= -1; /* no image */
4079 it
->position
= start_pos
;
4080 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4081 it
->method
= GET_FROM_IMAGE
;
4082 it
->face_id
= face_id
;
4084 /* Say that we haven't consumed the characters with
4085 `display' property yet. The call to pop_it in
4086 set_iterator_to_next will clean this up. */
4087 *position
= start_pos
;
4089 if (EQ (XCAR (spec
), Qleft_fringe
))
4091 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4092 it
->left_user_fringe_face_id
= face_id
;
4096 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4097 it
->right_user_fringe_face_id
= face_id
;
4099 #endif /* HAVE_WINDOW_SYSTEM */
4103 /* Prepare to handle `((margin left-margin) ...)',
4104 `((margin right-margin) ...)' and `((margin nil) ...)'
4105 prefixes for display specifications. */
4106 location
= Qunbound
;
4107 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4111 value
= XCDR (spec
);
4113 value
= XCAR (value
);
4116 if (EQ (XCAR (tem
), Qmargin
)
4117 && (tem
= XCDR (tem
),
4118 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4120 || EQ (tem
, Qleft_margin
)
4121 || EQ (tem
, Qright_margin
))))
4125 if (EQ (location
, Qunbound
))
4131 /* After this point, VALUE is the property after any
4132 margin prefix has been stripped. It must be a string,
4133 an image specification, or `(space ...)'.
4135 LOCATION specifies where to display: `left-margin',
4136 `right-margin' or nil. */
4138 valid_p
= (STRINGP (value
)
4139 #ifdef HAVE_WINDOW_SYSTEM
4140 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4141 #endif /* not HAVE_WINDOW_SYSTEM */
4142 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4144 if (valid_p
&& !display_replaced_before_p
)
4146 /* Save current settings of IT so that we can restore them
4147 when we are finished with the glyph property value. */
4150 if (NILP (location
))
4151 it
->area
= TEXT_AREA
;
4152 else if (EQ (location
, Qleft_margin
))
4153 it
->area
= LEFT_MARGIN_AREA
;
4155 it
->area
= RIGHT_MARGIN_AREA
;
4157 if (STRINGP (value
))
4159 if (SCHARS (value
) == 0)
4162 return -1; /* Replaced by "", i.e. nothing. */
4165 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4166 it
->current
.overlay_string_index
= -1;
4167 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4168 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4169 it
->method
= GET_FROM_STRING
;
4170 it
->stop_charpos
= 0;
4171 it
->string_from_display_prop_p
= 1;
4172 /* Say that we haven't consumed the characters with
4173 `display' property yet. The call to pop_it in
4174 set_iterator_to_next will clean this up. */
4175 *position
= start_pos
;
4177 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4179 it
->method
= GET_FROM_STRETCH
;
4181 *position
= it
->position
= start_pos
;
4183 #ifdef HAVE_WINDOW_SYSTEM
4186 it
->what
= IT_IMAGE
;
4187 it
->image_id
= lookup_image (it
->f
, value
);
4188 it
->position
= start_pos
;
4189 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4190 it
->method
= GET_FROM_IMAGE
;
4192 /* Say that we haven't consumed the characters with
4193 `display' property yet. The call to pop_it in
4194 set_iterator_to_next will clean this up. */
4195 *position
= start_pos
;
4197 #endif /* HAVE_WINDOW_SYSTEM */
4202 /* Invalid property or property not supported. Restore
4203 POSITION to what it was before. */
4204 *position
= start_pos
;
4209 /* Check if SPEC is a display specification value whose text should be
4210 treated as intangible. */
4213 single_display_spec_intangible_p (prop
)
4216 /* Skip over `when FORM'. */
4217 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4231 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4232 we don't need to treat text as intangible. */
4233 if (EQ (XCAR (prop
), Qmargin
))
4241 || EQ (XCAR (prop
), Qleft_margin
)
4242 || EQ (XCAR (prop
), Qright_margin
))
4246 return (CONSP (prop
)
4247 && (EQ (XCAR (prop
), Qimage
)
4248 || EQ (XCAR (prop
), Qspace
)));
4252 /* Check if PROP is a display property value whose text should be
4253 treated as intangible. */
4256 display_prop_intangible_p (prop
)
4260 && CONSP (XCAR (prop
))
4261 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4263 /* A list of sub-properties. */
4264 while (CONSP (prop
))
4266 if (single_display_spec_intangible_p (XCAR (prop
)))
4271 else if (VECTORP (prop
))
4273 /* A vector of sub-properties. */
4275 for (i
= 0; i
< ASIZE (prop
); ++i
)
4276 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4280 return single_display_spec_intangible_p (prop
);
4286 /* Return 1 if PROP is a display sub-property value containing STRING. */
4289 single_display_spec_string_p (prop
, string
)
4290 Lisp_Object prop
, string
;
4292 if (EQ (string
, prop
))
4295 /* Skip over `when FORM'. */
4296 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4305 /* Skip over `margin LOCATION'. */
4306 if (EQ (XCAR (prop
), Qmargin
))
4317 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4321 /* Return 1 if STRING appears in the `display' property PROP. */
4324 display_prop_string_p (prop
, string
)
4325 Lisp_Object prop
, string
;
4328 && CONSP (XCAR (prop
))
4329 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4331 /* A list of sub-properties. */
4332 while (CONSP (prop
))
4334 if (single_display_spec_string_p (XCAR (prop
), string
))
4339 else if (VECTORP (prop
))
4341 /* A vector of sub-properties. */
4343 for (i
= 0; i
< ASIZE (prop
); ++i
)
4344 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4348 return single_display_spec_string_p (prop
, string
);
4354 /* Determine from which buffer position in W's buffer STRING comes
4355 from. AROUND_CHARPOS is an approximate position where it could
4356 be from. Value is the buffer position or 0 if it couldn't be
4359 W's buffer must be current.
4361 This function is necessary because we don't record buffer positions
4362 in glyphs generated from strings (to keep struct glyph small).
4363 This function may only use code that doesn't eval because it is
4364 called asynchronously from note_mouse_highlight. */
4367 string_buffer_position (w
, string
, around_charpos
)
4372 Lisp_Object limit
, prop
, pos
;
4373 const int MAX_DISTANCE
= 1000;
4376 pos
= make_number (around_charpos
);
4377 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4378 while (!found
&& !EQ (pos
, limit
))
4380 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4381 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4384 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4389 pos
= make_number (around_charpos
);
4390 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4391 while (!found
&& !EQ (pos
, limit
))
4393 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4394 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4397 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4402 return found
? XINT (pos
) : 0;
4407 /***********************************************************************
4408 `composition' property
4409 ***********************************************************************/
4411 /* Set up iterator IT from `composition' property at its current
4412 position. Called from handle_stop. */
4414 static enum prop_handled
4415 handle_composition_prop (it
)
4418 Lisp_Object prop
, string
;
4419 int pos
, pos_byte
, end
;
4420 enum prop_handled handled
= HANDLED_NORMALLY
;
4422 if (STRINGP (it
->string
))
4424 pos
= IT_STRING_CHARPOS (*it
);
4425 pos_byte
= IT_STRING_BYTEPOS (*it
);
4426 string
= it
->string
;
4430 pos
= IT_CHARPOS (*it
);
4431 pos_byte
= IT_BYTEPOS (*it
);
4435 /* If there's a valid composition and point is not inside of the
4436 composition (in the case that the composition is from the current
4437 buffer), draw a glyph composed from the composition components. */
4438 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4439 && COMPOSITION_VALID_P (pos
, end
, prop
)
4440 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4442 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4446 it
->method
= GET_FROM_COMPOSITION
;
4448 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4449 /* For a terminal, draw only the first character of the
4451 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4452 it
->len
= (STRINGP (it
->string
)
4453 ? string_char_to_byte (it
->string
, end
)
4454 : CHAR_TO_BYTE (end
)) - pos_byte
;
4455 it
->stop_charpos
= end
;
4456 handled
= HANDLED_RETURN
;
4465 /***********************************************************************
4467 ***********************************************************************/
4469 /* The following structure is used to record overlay strings for
4470 later sorting in load_overlay_strings. */
4472 struct overlay_entry
4474 Lisp_Object overlay
;
4481 /* Set up iterator IT from overlay strings at its current position.
4482 Called from handle_stop. */
4484 static enum prop_handled
4485 handle_overlay_change (it
)
4488 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4489 return HANDLED_RECOMPUTE_PROPS
;
4491 return HANDLED_NORMALLY
;
4495 /* Set up the next overlay string for delivery by IT, if there is an
4496 overlay string to deliver. Called by set_iterator_to_next when the
4497 end of the current overlay string is reached. If there are more
4498 overlay strings to display, IT->string and
4499 IT->current.overlay_string_index are set appropriately here.
4500 Otherwise IT->string is set to nil. */
4503 next_overlay_string (it
)
4506 ++it
->current
.overlay_string_index
;
4507 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4509 /* No more overlay strings. Restore IT's settings to what
4510 they were before overlay strings were processed, and
4511 continue to deliver from current_buffer. */
4512 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4515 xassert (it
->stop_charpos
>= BEGV
4516 && it
->stop_charpos
<= it
->end_charpos
);
4518 it
->current
.overlay_string_index
= -1;
4519 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4520 it
->n_overlay_strings
= 0;
4521 it
->method
= GET_FROM_BUFFER
;
4523 /* If we're at the end of the buffer, record that we have
4524 processed the overlay strings there already, so that
4525 next_element_from_buffer doesn't try it again. */
4526 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4527 it
->overlay_strings_at_end_processed_p
= 1;
4529 /* If we have to display `...' for invisible text, set
4530 the iterator up for that. */
4531 if (display_ellipsis_p
)
4532 setup_for_ellipsis (it
, 0);
4536 /* There are more overlay strings to process. If
4537 IT->current.overlay_string_index has advanced to a position
4538 where we must load IT->overlay_strings with more strings, do
4540 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4542 if (it
->current
.overlay_string_index
&& i
== 0)
4543 load_overlay_strings (it
, 0);
4545 /* Initialize IT to deliver display elements from the overlay
4547 it
->string
= it
->overlay_strings
[i
];
4548 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4549 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4550 it
->method
= GET_FROM_STRING
;
4551 it
->stop_charpos
= 0;
4558 /* Compare two overlay_entry structures E1 and E2. Used as a
4559 comparison function for qsort in load_overlay_strings. Overlay
4560 strings for the same position are sorted so that
4562 1. All after-strings come in front of before-strings, except
4563 when they come from the same overlay.
4565 2. Within after-strings, strings are sorted so that overlay strings
4566 from overlays with higher priorities come first.
4568 2. Within before-strings, strings are sorted so that overlay
4569 strings from overlays with higher priorities come last.
4571 Value is analogous to strcmp. */
4575 compare_overlay_entries (e1
, e2
)
4578 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4579 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4582 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4584 /* Let after-strings appear in front of before-strings if
4585 they come from different overlays. */
4586 if (EQ (entry1
->overlay
, entry2
->overlay
))
4587 result
= entry1
->after_string_p
? 1 : -1;
4589 result
= entry1
->after_string_p
? -1 : 1;
4591 else if (entry1
->after_string_p
)
4592 /* After-strings sorted in order of decreasing priority. */
4593 result
= entry2
->priority
- entry1
->priority
;
4595 /* Before-strings sorted in order of increasing priority. */
4596 result
= entry1
->priority
- entry2
->priority
;
4602 /* Load the vector IT->overlay_strings with overlay strings from IT's
4603 current buffer position, or from CHARPOS if that is > 0. Set
4604 IT->n_overlays to the total number of overlay strings found.
4606 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4607 a time. On entry into load_overlay_strings,
4608 IT->current.overlay_string_index gives the number of overlay
4609 strings that have already been loaded by previous calls to this
4612 IT->add_overlay_start contains an additional overlay start
4613 position to consider for taking overlay strings from, if non-zero.
4614 This position comes into play when the overlay has an `invisible'
4615 property, and both before and after-strings. When we've skipped to
4616 the end of the overlay, because of its `invisible' property, we
4617 nevertheless want its before-string to appear.
4618 IT->add_overlay_start will contain the overlay start position
4621 Overlay strings are sorted so that after-string strings come in
4622 front of before-string strings. Within before and after-strings,
4623 strings are sorted by overlay priority. See also function
4624 compare_overlay_entries. */
4627 load_overlay_strings (it
, charpos
)
4631 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4632 Lisp_Object overlay
, window
, str
, invisible
;
4633 struct Lisp_Overlay
*ov
;
4636 int n
= 0, i
, j
, invis_p
;
4637 struct overlay_entry
*entries
4638 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4641 charpos
= IT_CHARPOS (*it
);
4643 /* Append the overlay string STRING of overlay OVERLAY to vector
4644 `entries' which has size `size' and currently contains `n'
4645 elements. AFTER_P non-zero means STRING is an after-string of
4647 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4650 Lisp_Object priority; \
4654 int new_size = 2 * size; \
4655 struct overlay_entry *old = entries; \
4657 (struct overlay_entry *) alloca (new_size \
4658 * sizeof *entries); \
4659 bcopy (old, entries, size * sizeof *entries); \
4663 entries[n].string = (STRING); \
4664 entries[n].overlay = (OVERLAY); \
4665 priority = Foverlay_get ((OVERLAY), Qpriority); \
4666 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4667 entries[n].after_string_p = (AFTER_P); \
4672 /* Process overlay before the overlay center. */
4673 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4675 XSETMISC (overlay
, ov
);
4676 xassert (OVERLAYP (overlay
));
4677 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4678 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4683 /* Skip this overlay if it doesn't start or end at IT's current
4685 if (end
!= charpos
&& start
!= charpos
)
4688 /* Skip this overlay if it doesn't apply to IT->w. */
4689 window
= Foverlay_get (overlay
, Qwindow
);
4690 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4693 /* If the text ``under'' the overlay is invisible, both before-
4694 and after-strings from this overlay are visible; start and
4695 end position are indistinguishable. */
4696 invisible
= Foverlay_get (overlay
, Qinvisible
);
4697 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4699 /* If overlay has a non-empty before-string, record it. */
4700 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4701 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4703 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4705 /* If overlay has a non-empty after-string, record it. */
4706 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4707 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4709 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4712 /* Process overlays after the overlay center. */
4713 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4715 XSETMISC (overlay
, ov
);
4716 xassert (OVERLAYP (overlay
));
4717 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4718 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4720 if (start
> charpos
)
4723 /* Skip this overlay if it doesn't start or end at IT's current
4725 if (end
!= charpos
&& start
!= charpos
)
4728 /* Skip this overlay if it doesn't apply to IT->w. */
4729 window
= Foverlay_get (overlay
, Qwindow
);
4730 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4733 /* If the text ``under'' the overlay is invisible, it has a zero
4734 dimension, and both before- and after-strings apply. */
4735 invisible
= Foverlay_get (overlay
, Qinvisible
);
4736 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4738 /* If overlay has a non-empty before-string, record it. */
4739 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4740 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4742 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4744 /* If overlay has a non-empty after-string, record it. */
4745 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4746 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4748 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4751 #undef RECORD_OVERLAY_STRING
4755 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4757 /* Record the total number of strings to process. */
4758 it
->n_overlay_strings
= n
;
4760 /* IT->current.overlay_string_index is the number of overlay strings
4761 that have already been consumed by IT. Copy some of the
4762 remaining overlay strings to IT->overlay_strings. */
4764 j
= it
->current
.overlay_string_index
;
4765 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4766 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4772 /* Get the first chunk of overlay strings at IT's current buffer
4773 position, or at CHARPOS if that is > 0. Value is non-zero if at
4774 least one overlay string was found. */
4777 get_overlay_strings (it
, charpos
)
4781 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4782 process. This fills IT->overlay_strings with strings, and sets
4783 IT->n_overlay_strings to the total number of strings to process.
4784 IT->pos.overlay_string_index has to be set temporarily to zero
4785 because load_overlay_strings needs this; it must be set to -1
4786 when no overlay strings are found because a zero value would
4787 indicate a position in the first overlay string. */
4788 it
->current
.overlay_string_index
= 0;
4789 load_overlay_strings (it
, charpos
);
4791 /* If we found overlay strings, set up IT to deliver display
4792 elements from the first one. Otherwise set up IT to deliver
4793 from current_buffer. */
4794 if (it
->n_overlay_strings
)
4796 /* Make sure we know settings in current_buffer, so that we can
4797 restore meaningful values when we're done with the overlay
4799 compute_stop_pos (it
);
4800 xassert (it
->face_id
>= 0);
4802 /* Save IT's settings. They are restored after all overlay
4803 strings have been processed. */
4804 xassert (it
->sp
== 0);
4807 /* Set up IT to deliver display elements from the first overlay
4809 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4810 it
->string
= it
->overlay_strings
[0];
4811 it
->stop_charpos
= 0;
4812 xassert (STRINGP (it
->string
));
4813 it
->end_charpos
= SCHARS (it
->string
);
4814 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4815 it
->method
= GET_FROM_STRING
;
4820 it
->current
.overlay_string_index
= -1;
4821 it
->method
= GET_FROM_BUFFER
;
4826 /* Value is non-zero if we found at least one overlay string. */
4827 return STRINGP (it
->string
);
4832 /***********************************************************************
4833 Saving and restoring state
4834 ***********************************************************************/
4836 /* Save current settings of IT on IT->stack. Called, for example,
4837 before setting up IT for an overlay string, to be able to restore
4838 IT's settings to what they were after the overlay string has been
4845 struct iterator_stack_entry
*p
;
4847 xassert (it
->sp
< 2);
4848 p
= it
->stack
+ it
->sp
;
4850 p
->stop_charpos
= it
->stop_charpos
;
4851 xassert (it
->face_id
>= 0);
4852 p
->face_id
= it
->face_id
;
4853 p
->string
= it
->string
;
4854 p
->pos
= it
->current
;
4855 p
->end_charpos
= it
->end_charpos
;
4856 p
->string_nchars
= it
->string_nchars
;
4858 p
->multibyte_p
= it
->multibyte_p
;
4859 p
->slice
= it
->slice
;
4860 p
->space_width
= it
->space_width
;
4861 p
->font_height
= it
->font_height
;
4862 p
->voffset
= it
->voffset
;
4863 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4864 p
->display_ellipsis_p
= 0;
4869 /* Restore IT's settings from IT->stack. Called, for example, when no
4870 more overlay strings must be processed, and we return to delivering
4871 display elements from a buffer, or when the end of a string from a
4872 `display' property is reached and we return to delivering display
4873 elements from an overlay string, or from a buffer. */
4879 struct iterator_stack_entry
*p
;
4881 xassert (it
->sp
> 0);
4883 p
= it
->stack
+ it
->sp
;
4884 it
->stop_charpos
= p
->stop_charpos
;
4885 it
->face_id
= p
->face_id
;
4886 it
->string
= p
->string
;
4887 it
->current
= p
->pos
;
4888 it
->end_charpos
= p
->end_charpos
;
4889 it
->string_nchars
= p
->string_nchars
;
4891 it
->multibyte_p
= p
->multibyte_p
;
4892 it
->slice
= p
->slice
;
4893 it
->space_width
= p
->space_width
;
4894 it
->font_height
= p
->font_height
;
4895 it
->voffset
= p
->voffset
;
4896 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4901 /***********************************************************************
4903 ***********************************************************************/
4905 /* Set IT's current position to the previous line start. */
4908 back_to_previous_line_start (it
)
4911 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4912 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4916 /* Move IT to the next line start.
4918 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4919 we skipped over part of the text (as opposed to moving the iterator
4920 continuously over the text). Otherwise, don't change the value
4923 Newlines may come from buffer text, overlay strings, or strings
4924 displayed via the `display' property. That's the reason we can't
4925 simply use find_next_newline_no_quit.
4927 Note that this function may not skip over invisible text that is so
4928 because of text properties and immediately follows a newline. If
4929 it would, function reseat_at_next_visible_line_start, when called
4930 from set_iterator_to_next, would effectively make invisible
4931 characters following a newline part of the wrong glyph row, which
4932 leads to wrong cursor motion. */
4935 forward_to_next_line_start (it
, skipped_p
)
4939 int old_selective
, newline_found_p
, n
;
4940 const int MAX_NEWLINE_DISTANCE
= 500;
4942 /* If already on a newline, just consume it to avoid unintended
4943 skipping over invisible text below. */
4944 if (it
->what
== IT_CHARACTER
4946 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4948 set_iterator_to_next (it
, 0);
4953 /* Don't handle selective display in the following. It's (a)
4954 unnecessary because it's done by the caller, and (b) leads to an
4955 infinite recursion because next_element_from_ellipsis indirectly
4956 calls this function. */
4957 old_selective
= it
->selective
;
4960 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4961 from buffer text. */
4962 for (n
= newline_found_p
= 0;
4963 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4964 n
+= STRINGP (it
->string
) ? 0 : 1)
4966 if (!get_next_display_element (it
))
4968 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4969 set_iterator_to_next (it
, 0);
4972 /* If we didn't find a newline near enough, see if we can use a
4974 if (!newline_found_p
)
4976 int start
= IT_CHARPOS (*it
);
4977 int limit
= find_next_newline_no_quit (start
, 1);
4980 xassert (!STRINGP (it
->string
));
4982 /* If there isn't any `display' property in sight, and no
4983 overlays, we can just use the position of the newline in
4985 if (it
->stop_charpos
>= limit
4986 || ((pos
= Fnext_single_property_change (make_number (start
),
4988 Qnil
, make_number (limit
)),
4990 && next_overlay_change (start
) == ZV
))
4992 IT_CHARPOS (*it
) = limit
;
4993 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4994 *skipped_p
= newline_found_p
= 1;
4998 while (get_next_display_element (it
)
4999 && !newline_found_p
)
5001 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5002 set_iterator_to_next (it
, 0);
5007 it
->selective
= old_selective
;
5008 return newline_found_p
;
5012 /* Set IT's current position to the previous visible line start. Skip
5013 invisible text that is so either due to text properties or due to
5014 selective display. Caution: this does not change IT->current_x and
5018 back_to_previous_visible_line_start (it
)
5021 while (IT_CHARPOS (*it
) > BEGV
)
5023 back_to_previous_line_start (it
);
5024 if (IT_CHARPOS (*it
) <= BEGV
)
5027 /* If selective > 0, then lines indented more than that values
5029 if (it
->selective
> 0
5030 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5031 (double) it
->selective
)) /* iftc */
5034 /* Check the newline before point for invisibility. */
5037 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5038 Qinvisible
, it
->window
);
5039 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5043 /* If newline has a display property that replaces the newline with something
5044 else (image or text), find start of overlay or interval and continue search
5046 if (IT_CHARPOS (*it
) > BEGV
)
5048 struct it it2
= *it
;
5051 Lisp_Object val
, overlay
;
5053 pos
= --IT_CHARPOS (it2
);
5056 if (handle_display_prop (&it2
) == HANDLED_RETURN
5057 && !NILP (val
= get_char_property_and_overlay
5058 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5059 && (OVERLAYP (overlay
)
5060 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5061 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5065 IT_CHARPOS (*it
) = beg
;
5066 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5074 xassert (IT_CHARPOS (*it
) >= BEGV
);
5075 xassert (IT_CHARPOS (*it
) == BEGV
5076 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5081 /* Reseat iterator IT at the previous visible line start. Skip
5082 invisible text that is so either due to text properties or due to
5083 selective display. At the end, update IT's overlay information,
5084 face information etc. */
5087 reseat_at_previous_visible_line_start (it
)
5090 back_to_previous_visible_line_start (it
);
5091 reseat (it
, it
->current
.pos
, 1);
5096 /* Reseat iterator IT on the next visible line start in the current
5097 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5098 preceding the line start. Skip over invisible text that is so
5099 because of selective display. Compute faces, overlays etc at the
5100 new position. Note that this function does not skip over text that
5101 is invisible because of text properties. */
5104 reseat_at_next_visible_line_start (it
, on_newline_p
)
5108 int newline_found_p
, skipped_p
= 0;
5110 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5112 /* Skip over lines that are invisible because they are indented
5113 more than the value of IT->selective. */
5114 if (it
->selective
> 0)
5115 while (IT_CHARPOS (*it
) < ZV
5116 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5117 (double) it
->selective
)) /* iftc */
5119 xassert (IT_BYTEPOS (*it
) == BEGV
5120 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5121 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5124 /* Position on the newline if that's what's requested. */
5125 if (on_newline_p
&& newline_found_p
)
5127 if (STRINGP (it
->string
))
5129 if (IT_STRING_CHARPOS (*it
) > 0)
5131 --IT_STRING_CHARPOS (*it
);
5132 --IT_STRING_BYTEPOS (*it
);
5135 else if (IT_CHARPOS (*it
) > BEGV
)
5139 reseat (it
, it
->current
.pos
, 0);
5143 reseat (it
, it
->current
.pos
, 0);
5150 /***********************************************************************
5151 Changing an iterator's position
5152 ***********************************************************************/
5154 /* Change IT's current position to POS in current_buffer. If FORCE_P
5155 is non-zero, always check for text properties at the new position.
5156 Otherwise, text properties are only looked up if POS >=
5157 IT->check_charpos of a property. */
5160 reseat (it
, pos
, force_p
)
5162 struct text_pos pos
;
5165 int original_pos
= IT_CHARPOS (*it
);
5167 reseat_1 (it
, pos
, 0);
5169 /* Determine where to check text properties. Avoid doing it
5170 where possible because text property lookup is very expensive. */
5172 || CHARPOS (pos
) > it
->stop_charpos
5173 || CHARPOS (pos
) < original_pos
)
5180 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5181 IT->stop_pos to POS, also. */
5184 reseat_1 (it
, pos
, set_stop_p
)
5186 struct text_pos pos
;
5189 /* Don't call this function when scanning a C string. */
5190 xassert (it
->s
== NULL
);
5192 /* POS must be a reasonable value. */
5193 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5195 it
->current
.pos
= it
->position
= pos
;
5196 XSETBUFFER (it
->object
, current_buffer
);
5197 it
->end_charpos
= ZV
;
5199 it
->current
.dpvec_index
= -1;
5200 it
->current
.overlay_string_index
= -1;
5201 IT_STRING_CHARPOS (*it
) = -1;
5202 IT_STRING_BYTEPOS (*it
) = -1;
5204 it
->method
= GET_FROM_BUFFER
;
5205 /* RMS: I added this to fix a bug in move_it_vertically_backward
5206 where it->area continued to relate to the starting point
5207 for the backward motion. Bug report from
5208 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
5209 However, I am not sure whether reseat still does the right thing
5210 in general after this change. */
5211 it
->area
= TEXT_AREA
;
5212 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5214 it
->face_before_selective_p
= 0;
5217 it
->stop_charpos
= CHARPOS (pos
);
5221 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5222 If S is non-null, it is a C string to iterate over. Otherwise,
5223 STRING gives a Lisp string to iterate over.
5225 If PRECISION > 0, don't return more then PRECISION number of
5226 characters from the string.
5228 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5229 characters have been returned. FIELD_WIDTH < 0 means an infinite
5232 MULTIBYTE = 0 means disable processing of multibyte characters,
5233 MULTIBYTE > 0 means enable it,
5234 MULTIBYTE < 0 means use IT->multibyte_p.
5236 IT must be initialized via a prior call to init_iterator before
5237 calling this function. */
5240 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5245 int precision
, field_width
, multibyte
;
5247 /* No region in strings. */
5248 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5250 /* No text property checks performed by default, but see below. */
5251 it
->stop_charpos
= -1;
5253 /* Set iterator position and end position. */
5254 bzero (&it
->current
, sizeof it
->current
);
5255 it
->current
.overlay_string_index
= -1;
5256 it
->current
.dpvec_index
= -1;
5257 xassert (charpos
>= 0);
5259 /* If STRING is specified, use its multibyteness, otherwise use the
5260 setting of MULTIBYTE, if specified. */
5262 it
->multibyte_p
= multibyte
> 0;
5266 xassert (STRINGP (string
));
5267 it
->string
= string
;
5269 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5270 it
->method
= GET_FROM_STRING
;
5271 it
->current
.string_pos
= string_pos (charpos
, string
);
5278 /* Note that we use IT->current.pos, not it->current.string_pos,
5279 for displaying C strings. */
5280 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5281 if (it
->multibyte_p
)
5283 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5284 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5288 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5289 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5292 it
->method
= GET_FROM_C_STRING
;
5295 /* PRECISION > 0 means don't return more than PRECISION characters
5297 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5298 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5300 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5301 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5302 FIELD_WIDTH < 0 means infinite field width. This is useful for
5303 padding with `-' at the end of a mode line. */
5304 if (field_width
< 0)
5305 field_width
= INFINITY
;
5306 if (field_width
> it
->end_charpos
- charpos
)
5307 it
->end_charpos
= charpos
+ field_width
;
5309 /* Use the standard display table for displaying strings. */
5310 if (DISP_TABLE_P (Vstandard_display_table
))
5311 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5313 it
->stop_charpos
= charpos
;
5319 /***********************************************************************
5321 ***********************************************************************/
5323 /* Map enum it_method value to corresponding next_element_from_* function. */
5325 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5327 next_element_from_buffer
,
5328 next_element_from_display_vector
,
5329 next_element_from_composition
,
5330 next_element_from_string
,
5331 next_element_from_c_string
,
5332 next_element_from_image
,
5333 next_element_from_stretch
5337 /* Load IT's display element fields with information about the next
5338 display element from the current position of IT. Value is zero if
5339 end of buffer (or C string) is reached. */
5341 static struct frame
*last_escape_glyph_frame
= NULL
;
5342 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5343 static int last_escape_glyph_merged_face_id
= 0;
5346 get_next_display_element (it
)
5349 /* Non-zero means that we found a display element. Zero means that
5350 we hit the end of what we iterate over. Performance note: the
5351 function pointer `method' used here turns out to be faster than
5352 using a sequence of if-statements. */
5356 success_p
= (*get_next_element
[it
->method
]) (it
);
5358 if (it
->what
== IT_CHARACTER
)
5360 /* Map via display table or translate control characters.
5361 IT->c, IT->len etc. have been set to the next character by
5362 the function call above. If we have a display table, and it
5363 contains an entry for IT->c, translate it. Don't do this if
5364 IT->c itself comes from a display table, otherwise we could
5365 end up in an infinite recursion. (An alternative could be to
5366 count the recursion depth of this function and signal an
5367 error when a certain maximum depth is reached.) Is it worth
5369 if (success_p
&& it
->dpvec
== NULL
)
5374 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5377 struct Lisp_Vector
*v
= XVECTOR (dv
);
5379 /* Return the first character from the display table
5380 entry, if not empty. If empty, don't display the
5381 current character. */
5384 it
->dpvec_char_len
= it
->len
;
5385 it
->dpvec
= v
->contents
;
5386 it
->dpend
= v
->contents
+ v
->size
;
5387 it
->current
.dpvec_index
= 0;
5388 it
->dpvec_face_id
= -1;
5389 it
->saved_face_id
= it
->face_id
;
5390 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5395 set_iterator_to_next (it
, 0);
5400 /* Translate control characters into `\003' or `^C' form.
5401 Control characters coming from a display table entry are
5402 currently not translated because we use IT->dpvec to hold
5403 the translation. This could easily be changed but I
5404 don't believe that it is worth doing.
5406 If it->multibyte_p is nonzero, eight-bit characters and
5407 non-printable multibyte characters are also translated to
5410 If it->multibyte_p is zero, eight-bit characters that
5411 don't have corresponding multibyte char code are also
5412 translated to octal form. */
5413 else if ((it
->c
< ' '
5414 && (it
->area
!= TEXT_AREA
5415 /* In mode line, treat \n like other crl chars. */
5417 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5418 || (it
->c
!= '\n' && it
->c
!= '\t')))
5422 || !CHAR_PRINTABLE_P (it
->c
)
5423 || (!NILP (Vnobreak_char_display
)
5424 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5425 || it
->c
== 0x920 || it
->c
== 0x92d
5426 || it
->c
== 0xe20 || it
->c
== 0xe2d
5427 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5429 && (!unibyte_display_via_language_environment
5430 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5432 /* IT->c is a control character which must be displayed
5433 either as '\003' or as `^C' where the '\\' and '^'
5434 can be defined in the display table. Fill
5435 IT->ctl_chars with glyphs for what we have to
5436 display. Then, set IT->dpvec to these glyphs. */
5439 int face_id
, lface_id
= 0 ;
5442 /* Handle control characters with ^. */
5444 if (it
->c
< 128 && it
->ctl_arrow_p
)
5446 g
= '^'; /* default glyph for Control */
5447 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5449 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5450 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5452 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5453 lface_id
= FAST_GLYPH_FACE (g
);
5457 g
= FAST_GLYPH_CHAR (g
);
5458 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5461 else if (it
->f
== last_escape_glyph_frame
5462 && it
->face_id
== last_escape_glyph_face_id
)
5464 face_id
= last_escape_glyph_merged_face_id
;
5468 /* Merge the escape-glyph face into the current face. */
5469 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5471 last_escape_glyph_frame
= it
->f
;
5472 last_escape_glyph_face_id
= it
->face_id
;
5473 last_escape_glyph_merged_face_id
= face_id
;
5476 XSETINT (it
->ctl_chars
[0], g
);
5478 XSETINT (it
->ctl_chars
[1], g
);
5480 goto display_control
;
5483 /* Handle non-break space in the mode where it only gets
5486 if (EQ (Vnobreak_char_display
, Qt
)
5487 && (it
->c
== 0x8a0 || it
->c
== 0x920
5488 || it
->c
== 0xe20 || it
->c
== 0xf20))
5490 /* Merge the no-break-space face into the current face. */
5491 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5495 XSETINT (it
->ctl_chars
[0], g
);
5497 goto display_control
;
5500 /* Handle sequences that start with the "escape glyph". */
5502 /* the default escape glyph is \. */
5503 escape_glyph
= '\\';
5506 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5507 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5509 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5510 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5514 /* The display table specified a face.
5515 Merge it into face_id and also into escape_glyph. */
5516 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5517 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5520 else if (it
->f
== last_escape_glyph_frame
5521 && it
->face_id
== last_escape_glyph_face_id
)
5523 face_id
= last_escape_glyph_merged_face_id
;
5527 /* Merge the escape-glyph face into the current face. */
5528 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5530 last_escape_glyph_frame
= it
->f
;
5531 last_escape_glyph_face_id
= it
->face_id
;
5532 last_escape_glyph_merged_face_id
= face_id
;
5535 /* Handle soft hyphens in the mode where they only get
5538 if (EQ (Vnobreak_char_display
, Qt
)
5539 && (it
->c
== 0x8ad || it
->c
== 0x92d
5540 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5543 XSETINT (it
->ctl_chars
[0], g
);
5545 goto display_control
;
5548 /* Handle non-break space and soft hyphen
5549 with the escape glyph. */
5551 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5552 || it
->c
== 0x920 || it
->c
== 0x92d
5553 || it
->c
== 0xe20 || it
->c
== 0xe2d
5554 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5556 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5557 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5558 XSETINT (it
->ctl_chars
[1], g
);
5560 goto display_control
;
5564 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5568 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5569 if (SINGLE_BYTE_CHAR_P (it
->c
))
5570 str
[0] = it
->c
, len
= 1;
5573 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5576 /* It's an invalid character, which shouldn't
5577 happen actually, but due to bugs it may
5578 happen. Let's print the char as is, there's
5579 not much meaningful we can do with it. */
5581 str
[1] = it
->c
>> 8;
5582 str
[2] = it
->c
>> 16;
5583 str
[3] = it
->c
>> 24;
5588 for (i
= 0; i
< len
; i
++)
5590 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5591 /* Insert three more glyphs into IT->ctl_chars for
5592 the octal display of the character. */
5593 g
= ((str
[i
] >> 6) & 7) + '0';
5594 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5595 g
= ((str
[i
] >> 3) & 7) + '0';
5596 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5597 g
= (str
[i
] & 7) + '0';
5598 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5604 /* Set up IT->dpvec and return first character from it. */
5605 it
->dpvec_char_len
= it
->len
;
5606 it
->dpvec
= it
->ctl_chars
;
5607 it
->dpend
= it
->dpvec
+ ctl_len
;
5608 it
->current
.dpvec_index
= 0;
5609 it
->dpvec_face_id
= face_id
;
5610 it
->saved_face_id
= it
->face_id
;
5611 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5617 /* Adjust face id for a multibyte character. There are no
5618 multibyte character in unibyte text. */
5621 && FRAME_WINDOW_P (it
->f
))
5623 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5624 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5628 /* Is this character the last one of a run of characters with
5629 box? If yes, set IT->end_of_box_run_p to 1. */
5636 it
->end_of_box_run_p
5637 = ((face_id
= face_after_it_pos (it
),
5638 face_id
!= it
->face_id
)
5639 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5640 face
->box
== FACE_NO_BOX
));
5643 /* Value is 0 if end of buffer or string reached. */
5648 /* Move IT to the next display element.
5650 RESEAT_P non-zero means if called on a newline in buffer text,
5651 skip to the next visible line start.
5653 Functions get_next_display_element and set_iterator_to_next are
5654 separate because I find this arrangement easier to handle than a
5655 get_next_display_element function that also increments IT's
5656 position. The way it is we can first look at an iterator's current
5657 display element, decide whether it fits on a line, and if it does,
5658 increment the iterator position. The other way around we probably
5659 would either need a flag indicating whether the iterator has to be
5660 incremented the next time, or we would have to implement a
5661 decrement position function which would not be easy to write. */
5664 set_iterator_to_next (it
, reseat_p
)
5668 /* Reset flags indicating start and end of a sequence of characters
5669 with box. Reset them at the start of this function because
5670 moving the iterator to a new position might set them. */
5671 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5675 case GET_FROM_BUFFER
:
5676 /* The current display element of IT is a character from
5677 current_buffer. Advance in the buffer, and maybe skip over
5678 invisible lines that are so because of selective display. */
5679 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5680 reseat_at_next_visible_line_start (it
, 0);
5683 xassert (it
->len
!= 0);
5684 IT_BYTEPOS (*it
) += it
->len
;
5685 IT_CHARPOS (*it
) += 1;
5686 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5690 case GET_FROM_COMPOSITION
:
5691 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5692 if (STRINGP (it
->string
))
5694 IT_STRING_BYTEPOS (*it
) += it
->len
;
5695 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5696 it
->method
= GET_FROM_STRING
;
5697 goto consider_string_end
;
5701 IT_BYTEPOS (*it
) += it
->len
;
5702 IT_CHARPOS (*it
) += it
->cmp_len
;
5703 it
->method
= GET_FROM_BUFFER
;
5707 case GET_FROM_C_STRING
:
5708 /* Current display element of IT is from a C string. */
5709 IT_BYTEPOS (*it
) += it
->len
;
5710 IT_CHARPOS (*it
) += 1;
5713 case GET_FROM_DISPLAY_VECTOR
:
5714 /* Current display element of IT is from a display table entry.
5715 Advance in the display table definition. Reset it to null if
5716 end reached, and continue with characters from buffers/
5718 ++it
->current
.dpvec_index
;
5720 /* Restore face of the iterator to what they were before the
5721 display vector entry (these entries may contain faces). */
5722 it
->face_id
= it
->saved_face_id
;
5724 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5726 int recheck_faces
= it
->ellipsis_p
;
5729 it
->method
= GET_FROM_C_STRING
;
5730 else if (STRINGP (it
->string
))
5731 it
->method
= GET_FROM_STRING
;
5733 it
->method
= GET_FROM_BUFFER
;
5736 it
->current
.dpvec_index
= -1;
5738 /* Skip over characters which were displayed via IT->dpvec. */
5739 if (it
->dpvec_char_len
< 0)
5740 reseat_at_next_visible_line_start (it
, 1);
5741 else if (it
->dpvec_char_len
> 0)
5743 if (it
->method
== GET_FROM_STRING
5744 && it
->n_overlay_strings
> 0)
5745 it
->ignore_overlay_strings_at_pos_p
= 1;
5746 it
->len
= it
->dpvec_char_len
;
5747 set_iterator_to_next (it
, reseat_p
);
5750 /* Maybe recheck faces after display vector */
5752 it
->stop_charpos
= IT_CHARPOS (*it
);
5756 case GET_FROM_STRING
:
5757 /* Current display element is a character from a Lisp string. */
5758 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5759 IT_STRING_BYTEPOS (*it
) += it
->len
;
5760 IT_STRING_CHARPOS (*it
) += 1;
5762 consider_string_end
:
5764 if (it
->current
.overlay_string_index
>= 0)
5766 /* IT->string is an overlay string. Advance to the
5767 next, if there is one. */
5768 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5769 next_overlay_string (it
);
5773 /* IT->string is not an overlay string. If we reached
5774 its end, and there is something on IT->stack, proceed
5775 with what is on the stack. This can be either another
5776 string, this time an overlay string, or a buffer. */
5777 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5781 if (STRINGP (it
->string
))
5782 goto consider_string_end
;
5783 it
->method
= GET_FROM_BUFFER
;
5788 case GET_FROM_IMAGE
:
5789 case GET_FROM_STRETCH
:
5790 /* The position etc with which we have to proceed are on
5791 the stack. The position may be at the end of a string,
5792 if the `display' property takes up the whole string. */
5793 xassert (it
->sp
> 0);
5796 if (STRINGP (it
->string
))
5798 it
->method
= GET_FROM_STRING
;
5799 goto consider_string_end
;
5801 it
->method
= GET_FROM_BUFFER
;
5805 /* There are no other methods defined, so this should be a bug. */
5809 xassert (it
->method
!= GET_FROM_STRING
5810 || (STRINGP (it
->string
)
5811 && IT_STRING_CHARPOS (*it
) >= 0));
5814 /* Load IT's display element fields with information about the next
5815 display element which comes from a display table entry or from the
5816 result of translating a control character to one of the forms `^C'
5819 IT->dpvec holds the glyphs to return as characters.
5820 IT->saved_face_id holds the face id before the display vector--
5821 it is restored into IT->face_idin set_iterator_to_next. */
5824 next_element_from_display_vector (it
)
5828 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5830 it
->face_id
= it
->saved_face_id
;
5832 if (INTEGERP (*it
->dpvec
)
5833 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5837 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5838 it
->c
= FAST_GLYPH_CHAR (g
);
5839 it
->len
= CHAR_BYTES (it
->c
);
5841 /* The entry may contain a face id to use. Such a face id is
5842 the id of a Lisp face, not a realized face. A face id of
5843 zero means no face is specified. */
5844 if (it
->dpvec_face_id
>= 0)
5845 it
->face_id
= it
->dpvec_face_id
;
5848 int lface_id
= FAST_GLYPH_FACE (g
);
5850 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5855 /* Display table entry is invalid. Return a space. */
5856 it
->c
= ' ', it
->len
= 1;
5858 /* Don't change position and object of the iterator here. They are
5859 still the values of the character that had this display table
5860 entry or was translated, and that's what we want. */
5861 it
->what
= IT_CHARACTER
;
5866 /* Load IT with the next display element from Lisp string IT->string.
5867 IT->current.string_pos is the current position within the string.
5868 If IT->current.overlay_string_index >= 0, the Lisp string is an
5872 next_element_from_string (it
)
5875 struct text_pos position
;
5877 xassert (STRINGP (it
->string
));
5878 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5879 position
= it
->current
.string_pos
;
5881 /* Time to check for invisible text? */
5882 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5883 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5887 /* Since a handler may have changed IT->method, we must
5889 return get_next_display_element (it
);
5892 if (it
->current
.overlay_string_index
>= 0)
5894 /* Get the next character from an overlay string. In overlay
5895 strings, There is no field width or padding with spaces to
5897 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5902 else if (STRING_MULTIBYTE (it
->string
))
5904 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5905 const unsigned char *s
= (SDATA (it
->string
)
5906 + IT_STRING_BYTEPOS (*it
));
5907 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5911 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5917 /* Get the next character from a Lisp string that is not an
5918 overlay string. Such strings come from the mode line, for
5919 example. We may have to pad with spaces, or truncate the
5920 string. See also next_element_from_c_string. */
5921 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5926 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5928 /* Pad with spaces. */
5929 it
->c
= ' ', it
->len
= 1;
5930 CHARPOS (position
) = BYTEPOS (position
) = -1;
5932 else if (STRING_MULTIBYTE (it
->string
))
5934 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5935 const unsigned char *s
= (SDATA (it
->string
)
5936 + IT_STRING_BYTEPOS (*it
));
5937 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5941 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5946 /* Record what we have and where it came from. Note that we store a
5947 buffer position in IT->position although it could arguably be a
5949 it
->what
= IT_CHARACTER
;
5950 it
->object
= it
->string
;
5951 it
->position
= position
;
5956 /* Load IT with next display element from C string IT->s.
5957 IT->string_nchars is the maximum number of characters to return
5958 from the string. IT->end_charpos may be greater than
5959 IT->string_nchars when this function is called, in which case we
5960 may have to return padding spaces. Value is zero if end of string
5961 reached, including padding spaces. */
5964 next_element_from_c_string (it
)
5970 it
->what
= IT_CHARACTER
;
5971 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5974 /* IT's position can be greater IT->string_nchars in case a field
5975 width or precision has been specified when the iterator was
5977 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5979 /* End of the game. */
5983 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5985 /* Pad with spaces. */
5986 it
->c
= ' ', it
->len
= 1;
5987 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5989 else if (it
->multibyte_p
)
5991 /* Implementation note: The calls to strlen apparently aren't a
5992 performance problem because there is no noticeable performance
5993 difference between Emacs running in unibyte or multibyte mode. */
5994 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5995 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5999 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6005 /* Set up IT to return characters from an ellipsis, if appropriate.
6006 The definition of the ellipsis glyphs may come from a display table
6007 entry. This function Fills IT with the first glyph from the
6008 ellipsis if an ellipsis is to be displayed. */
6011 next_element_from_ellipsis (it
)
6014 if (it
->selective_display_ellipsis_p
)
6015 setup_for_ellipsis (it
, it
->len
);
6018 /* The face at the current position may be different from the
6019 face we find after the invisible text. Remember what it
6020 was in IT->saved_face_id, and signal that it's there by
6021 setting face_before_selective_p. */
6022 it
->saved_face_id
= it
->face_id
;
6023 it
->method
= GET_FROM_BUFFER
;
6024 reseat_at_next_visible_line_start (it
, 1);
6025 it
->face_before_selective_p
= 1;
6028 return get_next_display_element (it
);
6032 /* Deliver an image display element. The iterator IT is already
6033 filled with image information (done in handle_display_prop). Value
6038 next_element_from_image (it
)
6041 it
->what
= IT_IMAGE
;
6046 /* Fill iterator IT with next display element from a stretch glyph
6047 property. IT->object is the value of the text property. Value is
6051 next_element_from_stretch (it
)
6054 it
->what
= IT_STRETCH
;
6059 /* Load IT with the next display element from current_buffer. Value
6060 is zero if end of buffer reached. IT->stop_charpos is the next
6061 position at which to stop and check for text properties or buffer
6065 next_element_from_buffer (it
)
6070 /* Check this assumption, otherwise, we would never enter the
6071 if-statement, below. */
6072 xassert (IT_CHARPOS (*it
) >= BEGV
6073 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6075 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6077 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6079 int overlay_strings_follow_p
;
6081 /* End of the game, except when overlay strings follow that
6082 haven't been returned yet. */
6083 if (it
->overlay_strings_at_end_processed_p
)
6084 overlay_strings_follow_p
= 0;
6087 it
->overlay_strings_at_end_processed_p
= 1;
6088 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6091 if (overlay_strings_follow_p
)
6092 success_p
= get_next_display_element (it
);
6096 it
->position
= it
->current
.pos
;
6103 return get_next_display_element (it
);
6108 /* No face changes, overlays etc. in sight, so just return a
6109 character from current_buffer. */
6112 /* Maybe run the redisplay end trigger hook. Performance note:
6113 This doesn't seem to cost measurable time. */
6114 if (it
->redisplay_end_trigger_charpos
6116 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6117 run_redisplay_end_trigger_hook (it
);
6119 /* Get the next character, maybe multibyte. */
6120 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6121 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6123 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6124 - IT_BYTEPOS (*it
));
6125 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6128 it
->c
= *p
, it
->len
= 1;
6130 /* Record what we have and where it came from. */
6131 it
->what
= IT_CHARACTER
;;
6132 it
->object
= it
->w
->buffer
;
6133 it
->position
= it
->current
.pos
;
6135 /* Normally we return the character found above, except when we
6136 really want to return an ellipsis for selective display. */
6141 /* A value of selective > 0 means hide lines indented more
6142 than that number of columns. */
6143 if (it
->selective
> 0
6144 && IT_CHARPOS (*it
) + 1 < ZV
6145 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6146 IT_BYTEPOS (*it
) + 1,
6147 (double) it
->selective
)) /* iftc */
6149 success_p
= next_element_from_ellipsis (it
);
6150 it
->dpvec_char_len
= -1;
6153 else if (it
->c
== '\r' && it
->selective
== -1)
6155 /* A value of selective == -1 means that everything from the
6156 CR to the end of the line is invisible, with maybe an
6157 ellipsis displayed for it. */
6158 success_p
= next_element_from_ellipsis (it
);
6159 it
->dpvec_char_len
= -1;
6164 /* Value is zero if end of buffer reached. */
6165 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6170 /* Run the redisplay end trigger hook for IT. */
6173 run_redisplay_end_trigger_hook (it
)
6176 Lisp_Object args
[3];
6178 /* IT->glyph_row should be non-null, i.e. we should be actually
6179 displaying something, or otherwise we should not run the hook. */
6180 xassert (it
->glyph_row
);
6182 /* Set up hook arguments. */
6183 args
[0] = Qredisplay_end_trigger_functions
;
6184 args
[1] = it
->window
;
6185 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6186 it
->redisplay_end_trigger_charpos
= 0;
6188 /* Since we are *trying* to run these functions, don't try to run
6189 them again, even if they get an error. */
6190 it
->w
->redisplay_end_trigger
= Qnil
;
6191 Frun_hook_with_args (3, args
);
6193 /* Notice if it changed the face of the character we are on. */
6194 handle_face_prop (it
);
6198 /* Deliver a composition display element. The iterator IT is already
6199 filled with composition information (done in
6200 handle_composition_prop). Value is always 1. */
6203 next_element_from_composition (it
)
6206 it
->what
= IT_COMPOSITION
;
6207 it
->position
= (STRINGP (it
->string
)
6208 ? it
->current
.string_pos
6215 /***********************************************************************
6216 Moving an iterator without producing glyphs
6217 ***********************************************************************/
6219 /* Check if iterator is at a position corresponding to a valid buffer
6220 position after some move_it_ call. */
6222 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6223 ((it)->method == GET_FROM_STRING \
6224 ? IT_STRING_CHARPOS (*it) == 0 \
6228 /* Move iterator IT to a specified buffer or X position within one
6229 line on the display without producing glyphs.
6231 OP should be a bit mask including some or all of these bits:
6232 MOVE_TO_X: Stop on reaching x-position TO_X.
6233 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6234 Regardless of OP's value, stop in reaching the end of the display line.
6236 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6237 This means, in particular, that TO_X includes window's horizontal
6240 The return value has several possible values that
6241 say what condition caused the scan to stop:
6243 MOVE_POS_MATCH_OR_ZV
6244 - when TO_POS or ZV was reached.
6247 -when TO_X was reached before TO_POS or ZV were reached.
6250 - when we reached the end of the display area and the line must
6254 - when we reached the end of the display area and the line is
6258 - when we stopped at a line end, i.e. a newline or a CR and selective
6261 static enum move_it_result
6262 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6264 int to_charpos
, to_x
, op
;
6266 enum move_it_result result
= MOVE_UNDEFINED
;
6267 struct glyph_row
*saved_glyph_row
;
6269 /* Don't produce glyphs in produce_glyphs. */
6270 saved_glyph_row
= it
->glyph_row
;
6271 it
->glyph_row
= NULL
;
6273 #define BUFFER_POS_REACHED_P() \
6274 ((op & MOVE_TO_POS) != 0 \
6275 && BUFFERP (it->object) \
6276 && IT_CHARPOS (*it) >= to_charpos \
6277 && (it->method == GET_FROM_BUFFER \
6278 || (it->method == GET_FROM_DISPLAY_VECTOR \
6279 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6284 int x
, i
, ascent
= 0, descent
= 0;
6286 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6287 if ((op
& MOVE_TO_POS
) != 0
6288 && BUFFERP (it
->object
)
6289 && it
->method
== GET_FROM_BUFFER
6290 && IT_CHARPOS (*it
) > to_charpos
)
6292 result
= MOVE_POS_MATCH_OR_ZV
;
6296 /* Stop when ZV reached.
6297 We used to stop here when TO_CHARPOS reached as well, but that is
6298 too soon if this glyph does not fit on this line. So we handle it
6299 explicitly below. */
6300 if (!get_next_display_element (it
)
6301 || (it
->truncate_lines_p
6302 && BUFFER_POS_REACHED_P ()))
6304 result
= MOVE_POS_MATCH_OR_ZV
;
6308 /* The call to produce_glyphs will get the metrics of the
6309 display element IT is loaded with. We record in x the
6310 x-position before this display element in case it does not
6314 /* Remember the line height so far in case the next element doesn't
6316 if (!it
->truncate_lines_p
)
6318 ascent
= it
->max_ascent
;
6319 descent
= it
->max_descent
;
6322 PRODUCE_GLYPHS (it
);
6324 if (it
->area
!= TEXT_AREA
)
6326 set_iterator_to_next (it
, 1);
6330 /* The number of glyphs we get back in IT->nglyphs will normally
6331 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6332 character on a terminal frame, or (iii) a line end. For the
6333 second case, IT->nglyphs - 1 padding glyphs will be present
6334 (on X frames, there is only one glyph produced for a
6335 composite character.
6337 The behavior implemented below means, for continuation lines,
6338 that as many spaces of a TAB as fit on the current line are
6339 displayed there. For terminal frames, as many glyphs of a
6340 multi-glyph character are displayed in the current line, too.
6341 This is what the old redisplay code did, and we keep it that
6342 way. Under X, the whole shape of a complex character must
6343 fit on the line or it will be completely displayed in the
6346 Note that both for tabs and padding glyphs, all glyphs have
6350 /* More than one glyph or glyph doesn't fit on line. All
6351 glyphs have the same width. */
6352 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6354 int x_before_this_char
= x
;
6355 int hpos_before_this_char
= it
->hpos
;
6357 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6359 new_x
= x
+ single_glyph_width
;
6361 /* We want to leave anything reaching TO_X to the caller. */
6362 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6364 if (BUFFER_POS_REACHED_P ())
6365 goto buffer_pos_reached
;
6367 result
= MOVE_X_REACHED
;
6370 else if (/* Lines are continued. */
6371 !it
->truncate_lines_p
6372 && (/* And glyph doesn't fit on the line. */
6373 new_x
> it
->last_visible_x
6374 /* Or it fits exactly and we're on a window
6376 || (new_x
== it
->last_visible_x
6377 && FRAME_WINDOW_P (it
->f
))))
6379 if (/* IT->hpos == 0 means the very first glyph
6380 doesn't fit on the line, e.g. a wide image. */
6382 || (new_x
== it
->last_visible_x
6383 && FRAME_WINDOW_P (it
->f
)))
6386 it
->current_x
= new_x
;
6388 /* The character's last glyph just barely fits
6390 if (i
== it
->nglyphs
- 1)
6392 /* If this is the destination position,
6393 return a position *before* it in this row,
6394 now that we know it fits in this row. */
6395 if (BUFFER_POS_REACHED_P ())
6397 it
->hpos
= hpos_before_this_char
;
6398 it
->current_x
= x_before_this_char
;
6399 result
= MOVE_POS_MATCH_OR_ZV
;
6403 set_iterator_to_next (it
, 1);
6404 #ifdef HAVE_WINDOW_SYSTEM
6405 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6407 if (!get_next_display_element (it
))
6409 result
= MOVE_POS_MATCH_OR_ZV
;
6412 if (BUFFER_POS_REACHED_P ())
6414 if (ITERATOR_AT_END_OF_LINE_P (it
))
6415 result
= MOVE_POS_MATCH_OR_ZV
;
6417 result
= MOVE_LINE_CONTINUED
;
6420 if (ITERATOR_AT_END_OF_LINE_P (it
))
6422 result
= MOVE_NEWLINE_OR_CR
;
6426 #endif /* HAVE_WINDOW_SYSTEM */
6432 it
->max_ascent
= ascent
;
6433 it
->max_descent
= descent
;
6436 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6438 result
= MOVE_LINE_CONTINUED
;
6441 else if (BUFFER_POS_REACHED_P ())
6442 goto buffer_pos_reached
;
6443 else if (new_x
> it
->first_visible_x
)
6445 /* Glyph is visible. Increment number of glyphs that
6446 would be displayed. */
6451 /* Glyph is completely off the left margin of the display
6452 area. Nothing to do. */
6456 if (result
!= MOVE_UNDEFINED
)
6459 else if (BUFFER_POS_REACHED_P ())
6463 it
->max_ascent
= ascent
;
6464 it
->max_descent
= descent
;
6465 result
= MOVE_POS_MATCH_OR_ZV
;
6468 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6470 /* Stop when TO_X specified and reached. This check is
6471 necessary here because of lines consisting of a line end,
6472 only. The line end will not produce any glyphs and we
6473 would never get MOVE_X_REACHED. */
6474 xassert (it
->nglyphs
== 0);
6475 result
= MOVE_X_REACHED
;
6479 /* Is this a line end? If yes, we're done. */
6480 if (ITERATOR_AT_END_OF_LINE_P (it
))
6482 result
= MOVE_NEWLINE_OR_CR
;
6486 /* The current display element has been consumed. Advance
6488 set_iterator_to_next (it
, 1);
6490 /* Stop if lines are truncated and IT's current x-position is
6491 past the right edge of the window now. */
6492 if (it
->truncate_lines_p
6493 && it
->current_x
>= it
->last_visible_x
)
6495 #ifdef HAVE_WINDOW_SYSTEM
6496 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6498 if (!get_next_display_element (it
)
6499 || BUFFER_POS_REACHED_P ())
6501 result
= MOVE_POS_MATCH_OR_ZV
;
6504 if (ITERATOR_AT_END_OF_LINE_P (it
))
6506 result
= MOVE_NEWLINE_OR_CR
;
6510 #endif /* HAVE_WINDOW_SYSTEM */
6511 result
= MOVE_LINE_TRUNCATED
;
6516 #undef BUFFER_POS_REACHED_P
6518 /* Restore the iterator settings altered at the beginning of this
6520 it
->glyph_row
= saved_glyph_row
;
6525 /* Move IT forward until it satisfies one or more of the criteria in
6526 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6528 OP is a bit-mask that specifies where to stop, and in particular,
6529 which of those four position arguments makes a difference. See the
6530 description of enum move_operation_enum.
6532 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6533 screen line, this function will set IT to the next position >
6537 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6539 int to_charpos
, to_x
, to_y
, to_vpos
;
6542 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6548 if (op
& MOVE_TO_VPOS
)
6550 /* If no TO_CHARPOS and no TO_X specified, stop at the
6551 start of the line TO_VPOS. */
6552 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6554 if (it
->vpos
== to_vpos
)
6560 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6564 /* TO_VPOS >= 0 means stop at TO_X in the line at
6565 TO_VPOS, or at TO_POS, whichever comes first. */
6566 if (it
->vpos
== to_vpos
)
6572 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6574 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6579 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6581 /* We have reached TO_X but not in the line we want. */
6582 skip
= move_it_in_display_line_to (it
, to_charpos
,
6584 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6592 else if (op
& MOVE_TO_Y
)
6594 struct it it_backup
;
6596 /* TO_Y specified means stop at TO_X in the line containing
6597 TO_Y---or at TO_CHARPOS if this is reached first. The
6598 problem is that we can't really tell whether the line
6599 contains TO_Y before we have completely scanned it, and
6600 this may skip past TO_X. What we do is to first scan to
6603 If TO_X is not specified, use a TO_X of zero. The reason
6604 is to make the outcome of this function more predictable.
6605 If we didn't use TO_X == 0, we would stop at the end of
6606 the line which is probably not what a caller would expect
6608 skip
= move_it_in_display_line_to (it
, to_charpos
,
6612 | (op
& MOVE_TO_POS
)));
6614 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6615 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6621 /* If TO_X was reached, we would like to know whether TO_Y
6622 is in the line. This can only be said if we know the
6623 total line height which requires us to scan the rest of
6625 if (skip
== MOVE_X_REACHED
)
6628 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6629 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6631 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6634 /* Now, decide whether TO_Y is in this line. */
6635 line_height
= it
->max_ascent
+ it
->max_descent
;
6636 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6638 if (to_y
>= it
->current_y
6639 && to_y
< it
->current_y
+ line_height
)
6641 if (skip
== MOVE_X_REACHED
)
6642 /* If TO_Y is in this line and TO_X was reached above,
6643 we scanned too far. We have to restore IT's settings
6644 to the ones before skipping. */
6648 else if (skip
== MOVE_X_REACHED
)
6651 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6659 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6663 case MOVE_POS_MATCH_OR_ZV
:
6667 case MOVE_NEWLINE_OR_CR
:
6668 set_iterator_to_next (it
, 1);
6669 it
->continuation_lines_width
= 0;
6672 case MOVE_LINE_TRUNCATED
:
6673 it
->continuation_lines_width
= 0;
6674 reseat_at_next_visible_line_start (it
, 0);
6675 if ((op
& MOVE_TO_POS
) != 0
6676 && IT_CHARPOS (*it
) > to_charpos
)
6683 case MOVE_LINE_CONTINUED
:
6684 it
->continuation_lines_width
+= it
->current_x
;
6691 /* Reset/increment for the next run. */
6692 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6693 it
->current_x
= it
->hpos
= 0;
6694 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6696 last_height
= it
->max_ascent
+ it
->max_descent
;
6697 last_max_ascent
= it
->max_ascent
;
6698 it
->max_ascent
= it
->max_descent
= 0;
6703 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6707 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6709 If DY > 0, move IT backward at least that many pixels. DY = 0
6710 means move IT backward to the preceding line start or BEGV. This
6711 function may move over more than DY pixels if IT->current_y - DY
6712 ends up in the middle of a line; in this case IT->current_y will be
6713 set to the top of the line moved to. */
6716 move_it_vertically_backward (it
, dy
)
6727 start_pos
= IT_CHARPOS (*it
);
6729 /* Estimate how many newlines we must move back. */
6730 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6732 /* Set the iterator's position that many lines back. */
6733 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6734 back_to_previous_visible_line_start (it
);
6736 /* Reseat the iterator here. When moving backward, we don't want
6737 reseat to skip forward over invisible text, set up the iterator
6738 to deliver from overlay strings at the new position etc. So,
6739 use reseat_1 here. */
6740 reseat_1 (it
, it
->current
.pos
, 1);
6742 /* We are now surely at a line start. */
6743 it
->current_x
= it
->hpos
= 0;
6744 it
->continuation_lines_width
= 0;
6746 /* Move forward and see what y-distance we moved. First move to the
6747 start of the next line so that we get its height. We need this
6748 height to be able to tell whether we reached the specified
6751 it2
.max_ascent
= it2
.max_descent
= 0;
6754 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6755 MOVE_TO_POS
| MOVE_TO_VPOS
);
6757 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6758 xassert (IT_CHARPOS (*it
) >= BEGV
);
6761 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6762 xassert (IT_CHARPOS (*it
) >= BEGV
);
6763 /* H is the actual vertical distance from the position in *IT
6764 and the starting position. */
6765 h
= it2
.current_y
- it
->current_y
;
6766 /* NLINES is the distance in number of lines. */
6767 nlines
= it2
.vpos
- it
->vpos
;
6769 /* Correct IT's y and vpos position
6770 so that they are relative to the starting point. */
6776 /* DY == 0 means move to the start of the screen line. The
6777 value of nlines is > 0 if continuation lines were involved. */
6779 move_it_by_lines (it
, nlines
, 1);
6781 /* I think this assert is bogus if buffer contains
6782 invisible text or images. KFS. */
6783 xassert (IT_CHARPOS (*it
) <= start_pos
);
6788 /* The y-position we try to reach, relative to *IT.
6789 Note that H has been subtracted in front of the if-statement. */
6790 int target_y
= it
->current_y
+ h
- dy
;
6791 int y0
= it3
.current_y
;
6792 int y1
= line_bottom_y (&it3
);
6793 int line_height
= y1
- y0
;
6795 /* If we did not reach target_y, try to move further backward if
6796 we can. If we moved too far backward, try to move forward. */
6797 if (target_y
< it
->current_y
6798 /* This is heuristic. In a window that's 3 lines high, with
6799 a line height of 13 pixels each, recentering with point
6800 on the bottom line will try to move -39/2 = 19 pixels
6801 backward. Try to avoid moving into the first line. */
6802 && (it
->current_y
- target_y
6803 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6804 && IT_CHARPOS (*it
) > BEGV
)
6806 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6807 target_y
- it
->current_y
));
6808 dy
= it
->current_y
- target_y
;
6809 goto move_further_back
;
6811 else if (target_y
>= it
->current_y
+ line_height
6812 && IT_CHARPOS (*it
) < ZV
)
6814 /* Should move forward by at least one line, maybe more.
6816 Note: Calling move_it_by_lines can be expensive on
6817 terminal frames, where compute_motion is used (via
6818 vmotion) to do the job, when there are very long lines
6819 and truncate-lines is nil. That's the reason for
6820 treating terminal frames specially here. */
6822 if (!FRAME_WINDOW_P (it
->f
))
6823 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6828 move_it_by_lines (it
, 1, 1);
6830 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6834 /* I think this assert is bogus if buffer contains
6835 invisible text or images. KFS. */
6836 xassert (IT_CHARPOS (*it
) >= BEGV
);
6843 /* Move IT by a specified amount of pixel lines DY. DY negative means
6844 move backwards. DY = 0 means move to start of screen line. At the
6845 end, IT will be on the start of a screen line. */
6848 move_it_vertically (it
, dy
)
6853 move_it_vertically_backward (it
, -dy
);
6856 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6857 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6858 MOVE_TO_POS
| MOVE_TO_Y
);
6859 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6861 /* If buffer ends in ZV without a newline, move to the start of
6862 the line to satisfy the post-condition. */
6863 if (IT_CHARPOS (*it
) == ZV
6865 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6866 move_it_by_lines (it
, 0, 0);
6871 /* Move iterator IT past the end of the text line it is in. */
6874 move_it_past_eol (it
)
6877 enum move_it_result rc
;
6879 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6880 if (rc
== MOVE_NEWLINE_OR_CR
)
6881 set_iterator_to_next (it
, 0);
6885 #if 0 /* Currently not used. */
6887 /* Return non-zero if some text between buffer positions START_CHARPOS
6888 and END_CHARPOS is invisible. IT->window is the window for text
6892 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6894 int start_charpos
, end_charpos
;
6896 Lisp_Object prop
, limit
;
6897 int invisible_found_p
;
6899 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6901 /* Is text at START invisible? */
6902 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6904 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6905 invisible_found_p
= 1;
6908 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6910 make_number (end_charpos
));
6911 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6914 return invisible_found_p
;
6920 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6921 negative means move up. DVPOS == 0 means move to the start of the
6922 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6923 NEED_Y_P is zero, IT->current_y will be left unchanged.
6925 Further optimization ideas: If we would know that IT->f doesn't use
6926 a face with proportional font, we could be faster for
6927 truncate-lines nil. */
6930 move_it_by_lines (it
, dvpos
, need_y_p
)
6932 int dvpos
, need_y_p
;
6934 struct position pos
;
6936 if (!FRAME_WINDOW_P (it
->f
))
6938 struct text_pos textpos
;
6940 /* We can use vmotion on frames without proportional fonts. */
6941 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6942 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6943 reseat (it
, textpos
, 1);
6944 it
->vpos
+= pos
.vpos
;
6945 it
->current_y
+= pos
.vpos
;
6947 else if (dvpos
== 0)
6949 /* DVPOS == 0 means move to the start of the screen line. */
6950 move_it_vertically_backward (it
, 0);
6951 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6952 /* Let next call to line_bottom_y calculate real line height */
6957 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6958 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6959 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6964 int start_charpos
, i
;
6966 /* Start at the beginning of the screen line containing IT's
6967 position. This may actually move vertically backwards,
6968 in case of overlays, so adjust dvpos accordingly. */
6970 move_it_vertically_backward (it
, 0);
6973 /* Go back -DVPOS visible lines and reseat the iterator there. */
6974 start_charpos
= IT_CHARPOS (*it
);
6975 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6976 back_to_previous_visible_line_start (it
);
6977 reseat (it
, it
->current
.pos
, 1);
6979 /* Move further back if we end up in a string or an image. */
6980 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6982 /* First try to move to start of display line. */
6984 move_it_vertically_backward (it
, 0);
6986 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6988 /* If start of line is still in string or image,
6989 move further back. */
6990 back_to_previous_visible_line_start (it
);
6991 reseat (it
, it
->current
.pos
, 1);
6995 it
->current_x
= it
->hpos
= 0;
6997 /* Above call may have moved too far if continuation lines
6998 are involved. Scan forward and see if it did. */
7000 it2
.vpos
= it2
.current_y
= 0;
7001 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7002 it
->vpos
-= it2
.vpos
;
7003 it
->current_y
-= it2
.current_y
;
7004 it
->current_x
= it
->hpos
= 0;
7006 /* If we moved too far back, move IT some lines forward. */
7007 if (it2
.vpos
> -dvpos
)
7009 int delta
= it2
.vpos
+ dvpos
;
7011 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7012 /* Move back again if we got too far ahead. */
7013 if (IT_CHARPOS (*it
) >= start_charpos
)
7019 /* Return 1 if IT points into the middle of a display vector. */
7022 in_display_vector_p (it
)
7025 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7026 && it
->current
.dpvec_index
> 0
7027 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7031 /***********************************************************************
7033 ***********************************************************************/
7036 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7040 add_to_log (format
, arg1
, arg2
)
7042 Lisp_Object arg1
, arg2
;
7044 Lisp_Object args
[3];
7045 Lisp_Object msg
, fmt
;
7048 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7051 /* Do nothing if called asynchronously. Inserting text into
7052 a buffer may call after-change-functions and alike and
7053 that would means running Lisp asynchronously. */
7054 if (handling_signal
)
7058 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7060 args
[0] = fmt
= build_string (format
);
7063 msg
= Fformat (3, args
);
7065 len
= SBYTES (msg
) + 1;
7066 SAFE_ALLOCA (buffer
, char *, len
);
7067 bcopy (SDATA (msg
), buffer
, len
);
7069 message_dolog (buffer
, len
- 1, 1, 0);
7076 /* Output a newline in the *Messages* buffer if "needs" one. */
7079 message_log_maybe_newline ()
7081 if (message_log_need_newline
)
7082 message_dolog ("", 0, 1, 0);
7086 /* Add a string M of length NBYTES to the message log, optionally
7087 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7088 nonzero, means interpret the contents of M as multibyte. This
7089 function calls low-level routines in order to bypass text property
7090 hooks, etc. which might not be safe to run.
7092 This may GC (insert may run before/after change hooks),
7093 so the buffer M must NOT point to a Lisp string. */
7096 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7098 int nbytes
, nlflag
, multibyte
;
7100 if (!NILP (Vmemory_full
))
7103 if (!NILP (Vmessage_log_max
))
7105 struct buffer
*oldbuf
;
7106 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7107 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7108 int point_at_end
= 0;
7110 Lisp_Object old_deactivate_mark
, tem
;
7111 struct gcpro gcpro1
;
7113 old_deactivate_mark
= Vdeactivate_mark
;
7114 oldbuf
= current_buffer
;
7115 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7116 current_buffer
->undo_list
= Qt
;
7118 oldpoint
= message_dolog_marker1
;
7119 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7120 oldbegv
= message_dolog_marker2
;
7121 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7122 oldzv
= message_dolog_marker3
;
7123 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7124 GCPRO1 (old_deactivate_mark
);
7132 BEGV_BYTE
= BEG_BYTE
;
7135 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7137 /* Insert the string--maybe converting multibyte to single byte
7138 or vice versa, so that all the text fits the buffer. */
7140 && NILP (current_buffer
->enable_multibyte_characters
))
7142 int i
, c
, char_bytes
;
7143 unsigned char work
[1];
7145 /* Convert a multibyte string to single-byte
7146 for the *Message* buffer. */
7147 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7149 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7150 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7152 : multibyte_char_to_unibyte (c
, Qnil
));
7153 insert_1_both (work
, 1, 1, 1, 0, 0);
7156 else if (! multibyte
7157 && ! NILP (current_buffer
->enable_multibyte_characters
))
7159 int i
, c
, char_bytes
;
7160 unsigned char *msg
= (unsigned char *) m
;
7161 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7162 /* Convert a single-byte string to multibyte
7163 for the *Message* buffer. */
7164 for (i
= 0; i
< nbytes
; i
++)
7166 c
= unibyte_char_to_multibyte (msg
[i
]);
7167 char_bytes
= CHAR_STRING (c
, str
);
7168 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7172 insert_1 (m
, nbytes
, 1, 0, 0);
7176 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7177 insert_1 ("\n", 1, 1, 0, 0);
7179 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7181 this_bol_byte
= PT_BYTE
;
7183 /* See if this line duplicates the previous one.
7184 If so, combine duplicates. */
7187 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7189 prev_bol_byte
= PT_BYTE
;
7191 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7192 this_bol
, this_bol_byte
);
7195 del_range_both (prev_bol
, prev_bol_byte
,
7196 this_bol
, this_bol_byte
, 0);
7202 /* If you change this format, don't forget to also
7203 change message_log_check_duplicate. */
7204 sprintf (dupstr
, " [%d times]", dup
);
7205 duplen
= strlen (dupstr
);
7206 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7207 insert_1 (dupstr
, duplen
, 1, 0, 1);
7212 /* If we have more than the desired maximum number of lines
7213 in the *Messages* buffer now, delete the oldest ones.
7214 This is safe because we don't have undo in this buffer. */
7216 if (NATNUMP (Vmessage_log_max
))
7218 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7219 -XFASTINT (Vmessage_log_max
) - 1, 0);
7220 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7223 BEGV
= XMARKER (oldbegv
)->charpos
;
7224 BEGV_BYTE
= marker_byte_position (oldbegv
);
7233 ZV
= XMARKER (oldzv
)->charpos
;
7234 ZV_BYTE
= marker_byte_position (oldzv
);
7238 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7240 /* We can't do Fgoto_char (oldpoint) because it will run some
7242 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7243 XMARKER (oldpoint
)->bytepos
);
7246 unchain_marker (XMARKER (oldpoint
));
7247 unchain_marker (XMARKER (oldbegv
));
7248 unchain_marker (XMARKER (oldzv
));
7250 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7251 set_buffer_internal (oldbuf
);
7253 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7254 message_log_need_newline
= !nlflag
;
7255 Vdeactivate_mark
= old_deactivate_mark
;
7260 /* We are at the end of the buffer after just having inserted a newline.
7261 (Note: We depend on the fact we won't be crossing the gap.)
7262 Check to see if the most recent message looks a lot like the previous one.
7263 Return 0 if different, 1 if the new one should just replace it, or a
7264 value N > 1 if we should also append " [N times]". */
7267 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7268 int prev_bol
, this_bol
;
7269 int prev_bol_byte
, this_bol_byte
;
7272 int len
= Z_BYTE
- 1 - this_bol_byte
;
7274 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7275 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7277 for (i
= 0; i
< len
; i
++)
7279 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7287 if (*p1
++ == ' ' && *p1
++ == '[')
7290 while (*p1
>= '0' && *p1
<= '9')
7291 n
= n
* 10 + *p1
++ - '0';
7292 if (strncmp (p1
, " times]\n", 8) == 0)
7299 /* Display an echo area message M with a specified length of NBYTES
7300 bytes. The string may include null characters. If M is 0, clear
7301 out any existing message, and let the mini-buffer text show
7304 This may GC, so the buffer M must NOT point to a Lisp string. */
7307 message2 (m
, nbytes
, multibyte
)
7312 /* First flush out any partial line written with print. */
7313 message_log_maybe_newline ();
7315 message_dolog (m
, nbytes
, 1, multibyte
);
7316 message2_nolog (m
, nbytes
, multibyte
);
7320 /* The non-logging counterpart of message2. */
7323 message2_nolog (m
, nbytes
, multibyte
)
7325 int nbytes
, multibyte
;
7327 struct frame
*sf
= SELECTED_FRAME ();
7328 message_enable_multibyte
= multibyte
;
7332 if (noninteractive_need_newline
)
7333 putc ('\n', stderr
);
7334 noninteractive_need_newline
= 0;
7336 fwrite (m
, nbytes
, 1, stderr
);
7337 if (cursor_in_echo_area
== 0)
7338 fprintf (stderr
, "\n");
7341 /* A null message buffer means that the frame hasn't really been
7342 initialized yet. Error messages get reported properly by
7343 cmd_error, so this must be just an informative message; toss it. */
7344 else if (INTERACTIVE
7345 && sf
->glyphs_initialized_p
7346 && FRAME_MESSAGE_BUF (sf
))
7348 Lisp_Object mini_window
;
7351 /* Get the frame containing the mini-buffer
7352 that the selected frame is using. */
7353 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7354 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7356 FRAME_SAMPLE_VISIBILITY (f
);
7357 if (FRAME_VISIBLE_P (sf
)
7358 && ! FRAME_VISIBLE_P (f
))
7359 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7363 set_message (m
, Qnil
, nbytes
, multibyte
);
7364 if (minibuffer_auto_raise
)
7365 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7368 clear_message (1, 1);
7370 do_pending_window_change (0);
7371 echo_area_display (1);
7372 do_pending_window_change (0);
7373 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7374 (*frame_up_to_date_hook
) (f
);
7379 /* Display an echo area message M with a specified length of NBYTES
7380 bytes. The string may include null characters. If M is not a
7381 string, clear out any existing message, and let the mini-buffer
7384 This function cancels echoing. */
7387 message3 (m
, nbytes
, multibyte
)
7392 struct gcpro gcpro1
;
7395 clear_message (1,1);
7398 /* First flush out any partial line written with print. */
7399 message_log_maybe_newline ();
7405 SAFE_ALLOCA (buffer
, char *, nbytes
);
7406 bcopy (SDATA (m
), buffer
, nbytes
);
7407 message_dolog (buffer
, nbytes
, 1, multibyte
);
7410 message3_nolog (m
, nbytes
, multibyte
);
7416 /* The non-logging version of message3.
7417 This does not cancel echoing, because it is used for echoing.
7418 Perhaps we need to make a separate function for echoing
7419 and make this cancel echoing. */
7422 message3_nolog (m
, nbytes
, multibyte
)
7424 int nbytes
, multibyte
;
7426 struct frame
*sf
= SELECTED_FRAME ();
7427 message_enable_multibyte
= multibyte
;
7431 if (noninteractive_need_newline
)
7432 putc ('\n', stderr
);
7433 noninteractive_need_newline
= 0;
7435 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7436 if (cursor_in_echo_area
== 0)
7437 fprintf (stderr
, "\n");
7440 /* A null message buffer means that the frame hasn't really been
7441 initialized yet. Error messages get reported properly by
7442 cmd_error, so this must be just an informative message; toss it. */
7443 else if (INTERACTIVE
7444 && sf
->glyphs_initialized_p
7445 && FRAME_MESSAGE_BUF (sf
))
7447 Lisp_Object mini_window
;
7451 /* Get the frame containing the mini-buffer
7452 that the selected frame is using. */
7453 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7454 frame
= XWINDOW (mini_window
)->frame
;
7457 FRAME_SAMPLE_VISIBILITY (f
);
7458 if (FRAME_VISIBLE_P (sf
)
7459 && !FRAME_VISIBLE_P (f
))
7460 Fmake_frame_visible (frame
);
7462 if (STRINGP (m
) && SCHARS (m
) > 0)
7464 set_message (NULL
, m
, nbytes
, multibyte
);
7465 if (minibuffer_auto_raise
)
7466 Fraise_frame (frame
);
7467 /* Assume we are not echoing.
7468 (If we are, echo_now will override this.) */
7469 echo_message_buffer
= Qnil
;
7472 clear_message (1, 1);
7474 do_pending_window_change (0);
7475 echo_area_display (1);
7476 do_pending_window_change (0);
7477 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7478 (*frame_up_to_date_hook
) (f
);
7483 /* Display a null-terminated echo area message M. If M is 0, clear
7484 out any existing message, and let the mini-buffer text show through.
7486 The buffer M must continue to exist until after the echo area gets
7487 cleared or some other message gets displayed there. Do not pass
7488 text that is stored in a Lisp string. Do not pass text in a buffer
7489 that was alloca'd. */
7495 message2 (m
, (m
? strlen (m
) : 0), 0);
7499 /* The non-logging counterpart of message1. */
7505 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7508 /* Display a message M which contains a single %s
7509 which gets replaced with STRING. */
7512 message_with_string (m
, string
, log
)
7517 CHECK_STRING (string
);
7523 if (noninteractive_need_newline
)
7524 putc ('\n', stderr
);
7525 noninteractive_need_newline
= 0;
7526 fprintf (stderr
, m
, SDATA (string
));
7527 if (cursor_in_echo_area
== 0)
7528 fprintf (stderr
, "\n");
7532 else if (INTERACTIVE
)
7534 /* The frame whose minibuffer we're going to display the message on.
7535 It may be larger than the selected frame, so we need
7536 to use its buffer, not the selected frame's buffer. */
7537 Lisp_Object mini_window
;
7538 struct frame
*f
, *sf
= SELECTED_FRAME ();
7540 /* Get the frame containing the minibuffer
7541 that the selected frame is using. */
7542 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7543 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7545 /* A null message buffer means that the frame hasn't really been
7546 initialized yet. Error messages get reported properly by
7547 cmd_error, so this must be just an informative message; toss it. */
7548 if (FRAME_MESSAGE_BUF (f
))
7550 Lisp_Object args
[2], message
;
7551 struct gcpro gcpro1
, gcpro2
;
7553 args
[0] = build_string (m
);
7554 args
[1] = message
= string
;
7555 GCPRO2 (args
[0], message
);
7558 message
= Fformat (2, args
);
7561 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7563 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7567 /* Print should start at the beginning of the message
7568 buffer next time. */
7569 message_buf_print
= 0;
7575 /* Dump an informative message to the minibuf. If M is 0, clear out
7576 any existing message, and let the mini-buffer text show through. */
7580 message (m
, a1
, a2
, a3
)
7582 EMACS_INT a1
, a2
, a3
;
7588 if (noninteractive_need_newline
)
7589 putc ('\n', stderr
);
7590 noninteractive_need_newline
= 0;
7591 fprintf (stderr
, m
, a1
, a2
, a3
);
7592 if (cursor_in_echo_area
== 0)
7593 fprintf (stderr
, "\n");
7597 else if (INTERACTIVE
)
7599 /* The frame whose mini-buffer we're going to display the message
7600 on. It may be larger than the selected frame, so we need to
7601 use its buffer, not the selected frame's buffer. */
7602 Lisp_Object mini_window
;
7603 struct frame
*f
, *sf
= SELECTED_FRAME ();
7605 /* Get the frame containing the mini-buffer
7606 that the selected frame is using. */
7607 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7608 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7610 /* A null message buffer means that the frame hasn't really been
7611 initialized yet. Error messages get reported properly by
7612 cmd_error, so this must be just an informative message; toss
7614 if (FRAME_MESSAGE_BUF (f
))
7625 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7626 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7628 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7629 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7631 #endif /* NO_ARG_ARRAY */
7633 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7638 /* Print should start at the beginning of the message
7639 buffer next time. */
7640 message_buf_print
= 0;
7646 /* The non-logging version of message. */
7649 message_nolog (m
, a1
, a2
, a3
)
7651 EMACS_INT a1
, a2
, a3
;
7653 Lisp_Object old_log_max
;
7654 old_log_max
= Vmessage_log_max
;
7655 Vmessage_log_max
= Qnil
;
7656 message (m
, a1
, a2
, a3
);
7657 Vmessage_log_max
= old_log_max
;
7661 /* Display the current message in the current mini-buffer. This is
7662 only called from error handlers in process.c, and is not time
7668 if (!NILP (echo_area_buffer
[0]))
7671 string
= Fcurrent_message ();
7672 message3 (string
, SBYTES (string
),
7673 !NILP (current_buffer
->enable_multibyte_characters
));
7678 /* Make sure echo area buffers in `echo_buffers' are live.
7679 If they aren't, make new ones. */
7682 ensure_echo_area_buffers ()
7686 for (i
= 0; i
< 2; ++i
)
7687 if (!BUFFERP (echo_buffer
[i
])
7688 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7691 Lisp_Object old_buffer
;
7694 old_buffer
= echo_buffer
[i
];
7695 sprintf (name
, " *Echo Area %d*", i
);
7696 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7697 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7699 for (j
= 0; j
< 2; ++j
)
7700 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7701 echo_area_buffer
[j
] = echo_buffer
[i
];
7706 /* Call FN with args A1..A4 with either the current or last displayed
7707 echo_area_buffer as current buffer.
7709 WHICH zero means use the current message buffer
7710 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7711 from echo_buffer[] and clear it.
7713 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7714 suitable buffer from echo_buffer[] and clear it.
7716 Value is what FN returns. */
7719 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7722 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7728 int this_one
, the_other
, clear_buffer_p
, rc
;
7729 int count
= SPECPDL_INDEX ();
7731 /* If buffers aren't live, make new ones. */
7732 ensure_echo_area_buffers ();
7737 this_one
= 0, the_other
= 1;
7739 this_one
= 1, the_other
= 0;
7741 /* Choose a suitable buffer from echo_buffer[] is we don't
7743 if (NILP (echo_area_buffer
[this_one
]))
7745 echo_area_buffer
[this_one
]
7746 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7747 ? echo_buffer
[the_other
]
7748 : echo_buffer
[this_one
]);
7752 buffer
= echo_area_buffer
[this_one
];
7754 /* Don't get confused by reusing the buffer used for echoing
7755 for a different purpose. */
7756 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7759 record_unwind_protect (unwind_with_echo_area_buffer
,
7760 with_echo_area_buffer_unwind_data (w
));
7762 /* Make the echo area buffer current. Note that for display
7763 purposes, it is not necessary that the displayed window's buffer
7764 == current_buffer, except for text property lookup. So, let's
7765 only set that buffer temporarily here without doing a full
7766 Fset_window_buffer. We must also change w->pointm, though,
7767 because otherwise an assertions in unshow_buffer fails, and Emacs
7769 set_buffer_internal_1 (XBUFFER (buffer
));
7773 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7776 current_buffer
->undo_list
= Qt
;
7777 current_buffer
->read_only
= Qnil
;
7778 specbind (Qinhibit_read_only
, Qt
);
7779 specbind (Qinhibit_modification_hooks
, Qt
);
7781 if (clear_buffer_p
&& Z
> BEG
)
7784 xassert (BEGV
>= BEG
);
7785 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7787 rc
= fn (a1
, a2
, a3
, a4
);
7789 xassert (BEGV
>= BEG
);
7790 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7792 unbind_to (count
, Qnil
);
7797 /* Save state that should be preserved around the call to the function
7798 FN called in with_echo_area_buffer. */
7801 with_echo_area_buffer_unwind_data (w
)
7807 /* Reduce consing by keeping one vector in
7808 Vwith_echo_area_save_vector. */
7809 vector
= Vwith_echo_area_save_vector
;
7810 Vwith_echo_area_save_vector
= Qnil
;
7813 vector
= Fmake_vector (make_number (7), Qnil
);
7815 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7816 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7817 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7821 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7822 AREF (vector
, i
) = w
->buffer
; ++i
;
7823 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7824 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7829 for (; i
< end
; ++i
)
7830 AREF (vector
, i
) = Qnil
;
7833 xassert (i
== ASIZE (vector
));
7838 /* Restore global state from VECTOR which was created by
7839 with_echo_area_buffer_unwind_data. */
7842 unwind_with_echo_area_buffer (vector
)
7845 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7846 Vdeactivate_mark
= AREF (vector
, 1);
7847 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7849 if (WINDOWP (AREF (vector
, 3)))
7852 Lisp_Object buffer
, charpos
, bytepos
;
7854 w
= XWINDOW (AREF (vector
, 3));
7855 buffer
= AREF (vector
, 4);
7856 charpos
= AREF (vector
, 5);
7857 bytepos
= AREF (vector
, 6);
7860 set_marker_both (w
->pointm
, buffer
,
7861 XFASTINT (charpos
), XFASTINT (bytepos
));
7864 Vwith_echo_area_save_vector
= vector
;
7869 /* Set up the echo area for use by print functions. MULTIBYTE_P
7870 non-zero means we will print multibyte. */
7873 setup_echo_area_for_printing (multibyte_p
)
7876 /* If we can't find an echo area any more, exit. */
7877 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7880 ensure_echo_area_buffers ();
7882 if (!message_buf_print
)
7884 /* A message has been output since the last time we printed.
7885 Choose a fresh echo area buffer. */
7886 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7887 echo_area_buffer
[0] = echo_buffer
[1];
7889 echo_area_buffer
[0] = echo_buffer
[0];
7891 /* Switch to that buffer and clear it. */
7892 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7893 current_buffer
->truncate_lines
= Qnil
;
7897 int count
= SPECPDL_INDEX ();
7898 specbind (Qinhibit_read_only
, Qt
);
7899 /* Note that undo recording is always disabled. */
7901 unbind_to (count
, Qnil
);
7903 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7905 /* Set up the buffer for the multibyteness we need. */
7907 != !NILP (current_buffer
->enable_multibyte_characters
))
7908 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7910 /* Raise the frame containing the echo area. */
7911 if (minibuffer_auto_raise
)
7913 struct frame
*sf
= SELECTED_FRAME ();
7914 Lisp_Object mini_window
;
7915 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7916 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7919 message_log_maybe_newline ();
7920 message_buf_print
= 1;
7924 if (NILP (echo_area_buffer
[0]))
7926 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7927 echo_area_buffer
[0] = echo_buffer
[1];
7929 echo_area_buffer
[0] = echo_buffer
[0];
7932 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7934 /* Someone switched buffers between print requests. */
7935 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7936 current_buffer
->truncate_lines
= Qnil
;
7942 /* Display an echo area message in window W. Value is non-zero if W's
7943 height is changed. If display_last_displayed_message_p is
7944 non-zero, display the message that was last displayed, otherwise
7945 display the current message. */
7948 display_echo_area (w
)
7951 int i
, no_message_p
, window_height_changed_p
, count
;
7953 /* Temporarily disable garbage collections while displaying the echo
7954 area. This is done because a GC can print a message itself.
7955 That message would modify the echo area buffer's contents while a
7956 redisplay of the buffer is going on, and seriously confuse
7958 count
= inhibit_garbage_collection ();
7960 /* If there is no message, we must call display_echo_area_1
7961 nevertheless because it resizes the window. But we will have to
7962 reset the echo_area_buffer in question to nil at the end because
7963 with_echo_area_buffer will sets it to an empty buffer. */
7964 i
= display_last_displayed_message_p
? 1 : 0;
7965 no_message_p
= NILP (echo_area_buffer
[i
]);
7967 window_height_changed_p
7968 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7969 display_echo_area_1
,
7970 (EMACS_INT
) w
, Qnil
, 0, 0);
7973 echo_area_buffer
[i
] = Qnil
;
7975 unbind_to (count
, Qnil
);
7976 return window_height_changed_p
;
7980 /* Helper for display_echo_area. Display the current buffer which
7981 contains the current echo area message in window W, a mini-window,
7982 a pointer to which is passed in A1. A2..A4 are currently not used.
7983 Change the height of W so that all of the message is displayed.
7984 Value is non-zero if height of W was changed. */
7987 display_echo_area_1 (a1
, a2
, a3
, a4
)
7992 struct window
*w
= (struct window
*) a1
;
7994 struct text_pos start
;
7995 int window_height_changed_p
= 0;
7997 /* Do this before displaying, so that we have a large enough glyph
7998 matrix for the display. If we can't get enough space for the
7999 whole text, display the last N lines. That works by setting w->start. */
8000 window_height_changed_p
= resize_mini_window (w
, 0);
8002 /* Use the starting position chosen by resize_mini_window. */
8003 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8006 clear_glyph_matrix (w
->desired_matrix
);
8007 XSETWINDOW (window
, w
);
8008 try_window (window
, start
, 0);
8010 return window_height_changed_p
;
8014 /* Resize the echo area window to exactly the size needed for the
8015 currently displayed message, if there is one. If a mini-buffer
8016 is active, don't shrink it. */
8019 resize_echo_area_exactly ()
8021 if (BUFFERP (echo_area_buffer
[0])
8022 && WINDOWP (echo_area_window
))
8024 struct window
*w
= XWINDOW (echo_area_window
);
8026 Lisp_Object resize_exactly
;
8028 if (minibuf_level
== 0)
8029 resize_exactly
= Qt
;
8031 resize_exactly
= Qnil
;
8033 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8034 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8037 ++windows_or_buffers_changed
;
8038 ++update_mode_lines
;
8039 redisplay_internal (0);
8045 /* Callback function for with_echo_area_buffer, when used from
8046 resize_echo_area_exactly. A1 contains a pointer to the window to
8047 resize, EXACTLY non-nil means resize the mini-window exactly to the
8048 size of the text displayed. A3 and A4 are not used. Value is what
8049 resize_mini_window returns. */
8052 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8054 Lisp_Object exactly
;
8057 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8061 /* Resize mini-window W to fit the size of its contents. EXACT:P
8062 means size the window exactly to the size needed. Otherwise, it's
8063 only enlarged until W's buffer is empty.
8065 Set W->start to the right place to begin display. If the whole
8066 contents fit, start at the beginning. Otherwise, start so as
8067 to make the end of the contents appear. This is particularly
8068 important for y-or-n-p, but seems desirable generally.
8070 Value is non-zero if the window height has been changed. */
8073 resize_mini_window (w
, exact_p
)
8077 struct frame
*f
= XFRAME (w
->frame
);
8078 int window_height_changed_p
= 0;
8080 xassert (MINI_WINDOW_P (w
));
8082 /* By default, start display at the beginning. */
8083 set_marker_both (w
->start
, w
->buffer
,
8084 BUF_BEGV (XBUFFER (w
->buffer
)),
8085 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8087 /* Don't resize windows while redisplaying a window; it would
8088 confuse redisplay functions when the size of the window they are
8089 displaying changes from under them. Such a resizing can happen,
8090 for instance, when which-func prints a long message while
8091 we are running fontification-functions. We're running these
8092 functions with safe_call which binds inhibit-redisplay to t. */
8093 if (!NILP (Vinhibit_redisplay
))
8096 /* Nil means don't try to resize. */
8097 if (NILP (Vresize_mini_windows
)
8098 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8101 if (!FRAME_MINIBUF_ONLY_P (f
))
8104 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8105 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8106 int height
, max_height
;
8107 int unit
= FRAME_LINE_HEIGHT (f
);
8108 struct text_pos start
;
8109 struct buffer
*old_current_buffer
= NULL
;
8111 if (current_buffer
!= XBUFFER (w
->buffer
))
8113 old_current_buffer
= current_buffer
;
8114 set_buffer_internal (XBUFFER (w
->buffer
));
8117 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8119 /* Compute the max. number of lines specified by the user. */
8120 if (FLOATP (Vmax_mini_window_height
))
8121 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8122 else if (INTEGERP (Vmax_mini_window_height
))
8123 max_height
= XINT (Vmax_mini_window_height
);
8125 max_height
= total_height
/ 4;
8127 /* Correct that max. height if it's bogus. */
8128 max_height
= max (1, max_height
);
8129 max_height
= min (total_height
, max_height
);
8131 /* Find out the height of the text in the window. */
8132 if (it
.truncate_lines_p
)
8137 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8138 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8139 height
= it
.current_y
+ last_height
;
8141 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8142 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8143 height
= (height
+ unit
- 1) / unit
;
8146 /* Compute a suitable window start. */
8147 if (height
> max_height
)
8149 height
= max_height
;
8150 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8151 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8152 start
= it
.current
.pos
;
8155 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8156 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8158 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8160 /* Let it grow only, until we display an empty message, in which
8161 case the window shrinks again. */
8162 if (height
> WINDOW_TOTAL_LINES (w
))
8164 int old_height
= WINDOW_TOTAL_LINES (w
);
8165 freeze_window_starts (f
, 1);
8166 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8167 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8169 else if (height
< WINDOW_TOTAL_LINES (w
)
8170 && (exact_p
|| BEGV
== ZV
))
8172 int old_height
= WINDOW_TOTAL_LINES (w
);
8173 freeze_window_starts (f
, 0);
8174 shrink_mini_window (w
);
8175 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8180 /* Always resize to exact size needed. */
8181 if (height
> WINDOW_TOTAL_LINES (w
))
8183 int old_height
= WINDOW_TOTAL_LINES (w
);
8184 freeze_window_starts (f
, 1);
8185 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8186 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8188 else if (height
< WINDOW_TOTAL_LINES (w
))
8190 int old_height
= WINDOW_TOTAL_LINES (w
);
8191 freeze_window_starts (f
, 0);
8192 shrink_mini_window (w
);
8196 freeze_window_starts (f
, 1);
8197 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8200 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8204 if (old_current_buffer
)
8205 set_buffer_internal (old_current_buffer
);
8208 return window_height_changed_p
;
8212 /* Value is the current message, a string, or nil if there is no
8220 if (NILP (echo_area_buffer
[0]))
8224 with_echo_area_buffer (0, 0, current_message_1
,
8225 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8227 echo_area_buffer
[0] = Qnil
;
8235 current_message_1 (a1
, a2
, a3
, a4
)
8240 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8243 *msg
= make_buffer_string (BEG
, Z
, 1);
8250 /* Push the current message on Vmessage_stack for later restauration
8251 by restore_message. Value is non-zero if the current message isn't
8252 empty. This is a relatively infrequent operation, so it's not
8253 worth optimizing. */
8259 msg
= current_message ();
8260 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8261 return STRINGP (msg
);
8265 /* Restore message display from the top of Vmessage_stack. */
8272 xassert (CONSP (Vmessage_stack
));
8273 msg
= XCAR (Vmessage_stack
);
8275 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8277 message3_nolog (msg
, 0, 0);
8281 /* Handler for record_unwind_protect calling pop_message. */
8284 pop_message_unwind (dummy
)
8291 /* Pop the top-most entry off Vmessage_stack. */
8296 xassert (CONSP (Vmessage_stack
));
8297 Vmessage_stack
= XCDR (Vmessage_stack
);
8301 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8302 exits. If the stack is not empty, we have a missing pop_message
8306 check_message_stack ()
8308 if (!NILP (Vmessage_stack
))
8313 /* Truncate to NCHARS what will be displayed in the echo area the next
8314 time we display it---but don't redisplay it now. */
8317 truncate_echo_area (nchars
)
8321 echo_area_buffer
[0] = Qnil
;
8322 /* A null message buffer means that the frame hasn't really been
8323 initialized yet. Error messages get reported properly by
8324 cmd_error, so this must be just an informative message; toss it. */
8325 else if (!noninteractive
8327 && !NILP (echo_area_buffer
[0]))
8329 struct frame
*sf
= SELECTED_FRAME ();
8330 if (FRAME_MESSAGE_BUF (sf
))
8331 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8336 /* Helper function for truncate_echo_area. Truncate the current
8337 message to at most NCHARS characters. */
8340 truncate_message_1 (nchars
, a2
, a3
, a4
)
8345 if (BEG
+ nchars
< Z
)
8346 del_range (BEG
+ nchars
, Z
);
8348 echo_area_buffer
[0] = Qnil
;
8353 /* Set the current message to a substring of S or STRING.
8355 If STRING is a Lisp string, set the message to the first NBYTES
8356 bytes from STRING. NBYTES zero means use the whole string. If
8357 STRING is multibyte, the message will be displayed multibyte.
8359 If S is not null, set the message to the first LEN bytes of S. LEN
8360 zero means use the whole string. MULTIBYTE_P non-zero means S is
8361 multibyte. Display the message multibyte in that case.
8363 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8364 to t before calling set_message_1 (which calls insert).
8368 set_message (s
, string
, nbytes
, multibyte_p
)
8371 int nbytes
, multibyte_p
;
8373 message_enable_multibyte
8374 = ((s
&& multibyte_p
)
8375 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8377 with_echo_area_buffer (0, 0, set_message_1
,
8378 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8379 message_buf_print
= 0;
8380 help_echo_showing_p
= 0;
8384 /* Helper function for set_message. Arguments have the same meaning
8385 as there, with A1 corresponding to S and A2 corresponding to STRING
8386 This function is called with the echo area buffer being
8390 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8393 EMACS_INT nbytes
, multibyte_p
;
8395 const char *s
= (const char *) a1
;
8396 Lisp_Object string
= a2
;
8398 /* Change multibyteness of the echo buffer appropriately. */
8399 if (message_enable_multibyte
8400 != !NILP (current_buffer
->enable_multibyte_characters
))
8401 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8403 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8405 /* Insert new message at BEG. */
8406 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8409 if (STRINGP (string
))
8414 nbytes
= SBYTES (string
);
8415 nchars
= string_byte_to_char (string
, nbytes
);
8417 /* This function takes care of single/multibyte conversion. We
8418 just have to ensure that the echo area buffer has the right
8419 setting of enable_multibyte_characters. */
8420 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8425 nbytes
= strlen (s
);
8427 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8429 /* Convert from multi-byte to single-byte. */
8431 unsigned char work
[1];
8433 /* Convert a multibyte string to single-byte. */
8434 for (i
= 0; i
< nbytes
; i
+= n
)
8436 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8437 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8439 : multibyte_char_to_unibyte (c
, Qnil
));
8440 insert_1_both (work
, 1, 1, 1, 0, 0);
8443 else if (!multibyte_p
8444 && !NILP (current_buffer
->enable_multibyte_characters
))
8446 /* Convert from single-byte to multi-byte. */
8448 const unsigned char *msg
= (const unsigned char *) s
;
8449 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8451 /* Convert a single-byte string to multibyte. */
8452 for (i
= 0; i
< nbytes
; i
++)
8454 c
= unibyte_char_to_multibyte (msg
[i
]);
8455 n
= CHAR_STRING (c
, str
);
8456 insert_1_both (str
, 1, n
, 1, 0, 0);
8460 insert_1 (s
, nbytes
, 1, 0, 0);
8467 /* Clear messages. CURRENT_P non-zero means clear the current
8468 message. LAST_DISPLAYED_P non-zero means clear the message
8472 clear_message (current_p
, last_displayed_p
)
8473 int current_p
, last_displayed_p
;
8477 echo_area_buffer
[0] = Qnil
;
8478 message_cleared_p
= 1;
8481 if (last_displayed_p
)
8482 echo_area_buffer
[1] = Qnil
;
8484 message_buf_print
= 0;
8487 /* Clear garbaged frames.
8489 This function is used where the old redisplay called
8490 redraw_garbaged_frames which in turn called redraw_frame which in
8491 turn called clear_frame. The call to clear_frame was a source of
8492 flickering. I believe a clear_frame is not necessary. It should
8493 suffice in the new redisplay to invalidate all current matrices,
8494 and ensure a complete redisplay of all windows. */
8497 clear_garbaged_frames ()
8501 Lisp_Object tail
, frame
;
8502 int changed_count
= 0;
8504 FOR_EACH_FRAME (tail
, frame
)
8506 struct frame
*f
= XFRAME (frame
);
8508 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8512 Fredraw_frame (frame
);
8513 f
->force_flush_display_p
= 1;
8515 clear_current_matrices (f
);
8524 ++windows_or_buffers_changed
;
8529 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8530 is non-zero update selected_frame. Value is non-zero if the
8531 mini-windows height has been changed. */
8534 echo_area_display (update_frame_p
)
8537 Lisp_Object mini_window
;
8540 int window_height_changed_p
= 0;
8541 struct frame
*sf
= SELECTED_FRAME ();
8543 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8544 w
= XWINDOW (mini_window
);
8545 f
= XFRAME (WINDOW_FRAME (w
));
8547 /* Don't display if frame is invisible or not yet initialized. */
8548 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8551 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8553 #ifdef HAVE_WINDOW_SYSTEM
8554 /* When Emacs starts, selected_frame may be a visible terminal
8555 frame, even if we run under a window system. If we let this
8556 through, a message would be displayed on the terminal. */
8557 if (EQ (selected_frame
, Vterminal_frame
)
8558 && !NILP (Vwindow_system
))
8560 #endif /* HAVE_WINDOW_SYSTEM */
8563 /* Redraw garbaged frames. */
8565 clear_garbaged_frames ();
8567 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8569 echo_area_window
= mini_window
;
8570 window_height_changed_p
= display_echo_area (w
);
8571 w
->must_be_updated_p
= 1;
8573 /* Update the display, unless called from redisplay_internal.
8574 Also don't update the screen during redisplay itself. The
8575 update will happen at the end of redisplay, and an update
8576 here could cause confusion. */
8577 if (update_frame_p
&& !redisplaying_p
)
8581 /* If the display update has been interrupted by pending
8582 input, update mode lines in the frame. Due to the
8583 pending input, it might have been that redisplay hasn't
8584 been called, so that mode lines above the echo area are
8585 garbaged. This looks odd, so we prevent it here. */
8586 if (!display_completed
)
8587 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8589 if (window_height_changed_p
8590 /* Don't do this if Emacs is shutting down. Redisplay
8591 needs to run hooks. */
8592 && !NILP (Vrun_hooks
))
8594 /* Must update other windows. Likewise as in other
8595 cases, don't let this update be interrupted by
8597 int count
= SPECPDL_INDEX ();
8598 specbind (Qredisplay_dont_pause
, Qt
);
8599 windows_or_buffers_changed
= 1;
8600 redisplay_internal (0);
8601 unbind_to (count
, Qnil
);
8603 else if (FRAME_WINDOW_P (f
) && n
== 0)
8605 /* Window configuration is the same as before.
8606 Can do with a display update of the echo area,
8607 unless we displayed some mode lines. */
8608 update_single_window (w
, 1);
8609 rif
->flush_display (f
);
8612 update_frame (f
, 1, 1);
8614 /* If cursor is in the echo area, make sure that the next
8615 redisplay displays the minibuffer, so that the cursor will
8616 be replaced with what the minibuffer wants. */
8617 if (cursor_in_echo_area
)
8618 ++windows_or_buffers_changed
;
8621 else if (!EQ (mini_window
, selected_window
))
8622 windows_or_buffers_changed
++;
8624 /* The current message is now also the last one displayed. */
8625 echo_area_buffer
[1] = echo_area_buffer
[0];
8627 /* Prevent redisplay optimization in redisplay_internal by resetting
8628 this_line_start_pos. This is done because the mini-buffer now
8629 displays the message instead of its buffer text. */
8630 if (EQ (mini_window
, selected_window
))
8631 CHARPOS (this_line_start_pos
) = 0;
8633 return window_height_changed_p
;
8638 /***********************************************************************
8639 Mode Lines and Frame Titles
8640 ***********************************************************************/
8642 /* A buffer for constructing non-propertized mode-line strings and
8643 frame titles in it; allocated from the heap in init_xdisp and
8644 resized as needed in store_mode_line_noprop_char. */
8646 static char *mode_line_noprop_buf
;
8648 /* The buffer's end, and a current output position in it. */
8650 static char *mode_line_noprop_buf_end
;
8651 static char *mode_line_noprop_ptr
;
8653 #define MODE_LINE_NOPROP_LEN(start) \
8654 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8657 MODE_LINE_DISPLAY
= 0,
8663 /* Alist that caches the results of :propertize.
8664 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8665 static Lisp_Object mode_line_proptrans_alist
;
8667 /* List of strings making up the mode-line. */
8668 static Lisp_Object mode_line_string_list
;
8670 /* Base face property when building propertized mode line string. */
8671 static Lisp_Object mode_line_string_face
;
8672 static Lisp_Object mode_line_string_face_prop
;
8675 /* Unwind data for mode line strings */
8677 static Lisp_Object Vmode_line_unwind_vector
;
8680 format_mode_line_unwind_data (obuf
, save_proptrans
)
8681 struct buffer
*obuf
;
8685 /* Reduce consing by keeping one vector in
8686 Vwith_echo_area_save_vector. */
8687 vector
= Vmode_line_unwind_vector
;
8688 Vmode_line_unwind_vector
= Qnil
;
8691 vector
= Fmake_vector (make_number (7), Qnil
);
8693 AREF (vector
, 0) = make_number (mode_line_target
);
8694 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8695 AREF (vector
, 2) = mode_line_string_list
;
8696 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8697 AREF (vector
, 4) = mode_line_string_face
;
8698 AREF (vector
, 5) = mode_line_string_face_prop
;
8701 XSETBUFFER (AREF (vector
, 6), obuf
);
8703 AREF (vector
, 6) = Qnil
;
8709 unwind_format_mode_line (vector
)
8712 mode_line_target
= XINT (AREF (vector
, 0));
8713 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8714 mode_line_string_list
= AREF (vector
, 2);
8715 if (! EQ (AREF (vector
, 3), Qt
))
8716 mode_line_proptrans_alist
= AREF (vector
, 3);
8717 mode_line_string_face
= AREF (vector
, 4);
8718 mode_line_string_face_prop
= AREF (vector
, 5);
8720 if (!NILP (AREF (vector
, 6)))
8722 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8723 AREF (vector
, 6) = Qnil
;
8726 Vmode_line_unwind_vector
= vector
;
8731 /* Store a single character C for the frame title in mode_line_noprop_buf.
8732 Re-allocate mode_line_noprop_buf if necessary. */
8736 store_mode_line_noprop_char (char c
)
8738 store_mode_line_noprop_char (c
)
8742 /* If output position has reached the end of the allocated buffer,
8743 double the buffer's size. */
8744 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8746 int len
= MODE_LINE_NOPROP_LEN (0);
8747 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8748 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8749 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8750 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8753 *mode_line_noprop_ptr
++ = c
;
8757 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8758 mode_line_noprop_ptr. STR is the string to store. Do not copy
8759 characters that yield more columns than PRECISION; PRECISION <= 0
8760 means copy the whole string. Pad with spaces until FIELD_WIDTH
8761 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8762 pad. Called from display_mode_element when it is used to build a
8766 store_mode_line_noprop (str
, field_width
, precision
)
8767 const unsigned char *str
;
8768 int field_width
, precision
;
8773 /* Copy at most PRECISION chars from STR. */
8774 nbytes
= strlen (str
);
8775 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8777 store_mode_line_noprop_char (*str
++);
8779 /* Fill up with spaces until FIELD_WIDTH reached. */
8780 while (field_width
> 0
8783 store_mode_line_noprop_char (' ');
8790 /***********************************************************************
8792 ***********************************************************************/
8794 #ifdef HAVE_WINDOW_SYSTEM
8796 /* Set the title of FRAME, if it has changed. The title format is
8797 Vicon_title_format if FRAME is iconified, otherwise it is
8798 frame_title_format. */
8801 x_consider_frame_title (frame
)
8804 struct frame
*f
= XFRAME (frame
);
8806 if (FRAME_WINDOW_P (f
)
8807 || FRAME_MINIBUF_ONLY_P (f
)
8808 || f
->explicit_name
)
8810 /* Do we have more than one visible frame on this X display? */
8817 int count
= SPECPDL_INDEX ();
8819 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8821 Lisp_Object other_frame
= XCAR (tail
);
8822 struct frame
*tf
= XFRAME (other_frame
);
8825 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8826 && !FRAME_MINIBUF_ONLY_P (tf
)
8827 && !EQ (other_frame
, tip_frame
)
8828 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8832 /* Set global variable indicating that multiple frames exist. */
8833 multiple_frames
= CONSP (tail
);
8835 /* Switch to the buffer of selected window of the frame. Set up
8836 mode_line_target so that display_mode_element will output into
8837 mode_line_noprop_buf; then display the title. */
8838 record_unwind_protect (unwind_format_mode_line
,
8839 format_mode_line_unwind_data (current_buffer
, 0));
8841 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8842 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8844 mode_line_target
= MODE_LINE_TITLE
;
8845 title_start
= MODE_LINE_NOPROP_LEN (0);
8846 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8847 NULL
, DEFAULT_FACE_ID
);
8848 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8849 len
= MODE_LINE_NOPROP_LEN (title_start
);
8850 title
= mode_line_noprop_buf
+ title_start
;
8851 unbind_to (count
, Qnil
);
8853 /* Set the title only if it's changed. This avoids consing in
8854 the common case where it hasn't. (If it turns out that we've
8855 already wasted too much time by walking through the list with
8856 display_mode_element, then we might need to optimize at a
8857 higher level than this.) */
8858 if (! STRINGP (f
->name
)
8859 || SBYTES (f
->name
) != len
8860 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8861 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8865 #endif /* not HAVE_WINDOW_SYSTEM */
8870 /***********************************************************************
8872 ***********************************************************************/
8875 /* Prepare for redisplay by updating menu-bar item lists when
8876 appropriate. This can call eval. */
8879 prepare_menu_bars ()
8882 struct gcpro gcpro1
, gcpro2
;
8884 Lisp_Object tooltip_frame
;
8886 #ifdef HAVE_WINDOW_SYSTEM
8887 tooltip_frame
= tip_frame
;
8889 tooltip_frame
= Qnil
;
8892 /* Update all frame titles based on their buffer names, etc. We do
8893 this before the menu bars so that the buffer-menu will show the
8894 up-to-date frame titles. */
8895 #ifdef HAVE_WINDOW_SYSTEM
8896 if (windows_or_buffers_changed
|| update_mode_lines
)
8898 Lisp_Object tail
, frame
;
8900 FOR_EACH_FRAME (tail
, frame
)
8903 if (!EQ (frame
, tooltip_frame
)
8904 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8905 x_consider_frame_title (frame
);
8908 #endif /* HAVE_WINDOW_SYSTEM */
8910 /* Update the menu bar item lists, if appropriate. This has to be
8911 done before any actual redisplay or generation of display lines. */
8912 all_windows
= (update_mode_lines
8913 || buffer_shared
> 1
8914 || windows_or_buffers_changed
);
8917 Lisp_Object tail
, frame
;
8918 int count
= SPECPDL_INDEX ();
8920 record_unwind_save_match_data ();
8922 FOR_EACH_FRAME (tail
, frame
)
8926 /* Ignore tooltip frame. */
8927 if (EQ (frame
, tooltip_frame
))
8930 /* If a window on this frame changed size, report that to
8931 the user and clear the size-change flag. */
8932 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8934 Lisp_Object functions
;
8936 /* Clear flag first in case we get an error below. */
8937 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8938 functions
= Vwindow_size_change_functions
;
8939 GCPRO2 (tail
, functions
);
8941 while (CONSP (functions
))
8943 call1 (XCAR (functions
), frame
);
8944 functions
= XCDR (functions
);
8950 update_menu_bar (f
, 0);
8951 #ifdef HAVE_WINDOW_SYSTEM
8952 update_tool_bar (f
, 0);
8957 unbind_to (count
, Qnil
);
8961 struct frame
*sf
= SELECTED_FRAME ();
8962 update_menu_bar (sf
, 1);
8963 #ifdef HAVE_WINDOW_SYSTEM
8964 update_tool_bar (sf
, 1);
8968 /* Motif needs this. See comment in xmenu.c. Turn it off when
8969 pending_menu_activation is not defined. */
8970 #ifdef USE_X_TOOLKIT
8971 pending_menu_activation
= 0;
8976 /* Update the menu bar item list for frame F. This has to be done
8977 before we start to fill in any display lines, because it can call
8980 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8983 update_menu_bar (f
, save_match_data
)
8985 int save_match_data
;
8988 register struct window
*w
;
8990 /* If called recursively during a menu update, do nothing. This can
8991 happen when, for instance, an activate-menubar-hook causes a
8993 if (inhibit_menubar_update
)
8996 window
= FRAME_SELECTED_WINDOW (f
);
8997 w
= XWINDOW (window
);
8999 #if 0 /* The if statement below this if statement used to include the
9000 condition !NILP (w->update_mode_line), rather than using
9001 update_mode_lines directly, and this if statement may have
9002 been added to make that condition work. Now the if
9003 statement below matches its comment, this isn't needed. */
9004 if (update_mode_lines
)
9005 w
->update_mode_line
= Qt
;
9008 if (FRAME_WINDOW_P (f
)
9010 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9011 || defined (USE_GTK)
9012 FRAME_EXTERNAL_MENU_BAR (f
)
9014 FRAME_MENU_BAR_LINES (f
) > 0
9016 : FRAME_MENU_BAR_LINES (f
) > 0)
9018 /* If the user has switched buffers or windows, we need to
9019 recompute to reflect the new bindings. But we'll
9020 recompute when update_mode_lines is set too; that means
9021 that people can use force-mode-line-update to request
9022 that the menu bar be recomputed. The adverse effect on
9023 the rest of the redisplay algorithm is about the same as
9024 windows_or_buffers_changed anyway. */
9025 if (windows_or_buffers_changed
9026 /* This used to test w->update_mode_line, but we believe
9027 there is no need to recompute the menu in that case. */
9028 || update_mode_lines
9029 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9030 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9031 != !NILP (w
->last_had_star
))
9032 || ((!NILP (Vtransient_mark_mode
)
9033 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9034 != !NILP (w
->region_showing
)))
9036 struct buffer
*prev
= current_buffer
;
9037 int count
= SPECPDL_INDEX ();
9039 specbind (Qinhibit_menubar_update
, Qt
);
9041 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9042 if (save_match_data
)
9043 record_unwind_save_match_data ();
9044 if (NILP (Voverriding_local_map_menu_flag
))
9046 specbind (Qoverriding_terminal_local_map
, Qnil
);
9047 specbind (Qoverriding_local_map
, Qnil
);
9050 /* Run the Lucid hook. */
9051 safe_run_hooks (Qactivate_menubar_hook
);
9053 /* If it has changed current-menubar from previous value,
9054 really recompute the menu-bar from the value. */
9055 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9056 call0 (Qrecompute_lucid_menubar
);
9058 safe_run_hooks (Qmenu_bar_update_hook
);
9059 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9061 /* Redisplay the menu bar in case we changed it. */
9062 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9063 || defined (USE_GTK)
9064 if (FRAME_WINDOW_P (f
))
9067 /* All frames on Mac OS share the same menubar. So only
9068 the selected frame should be allowed to set it. */
9069 if (f
== SELECTED_FRAME ())
9071 set_frame_menubar (f
, 0, 0);
9074 /* On a terminal screen, the menu bar is an ordinary screen
9075 line, and this makes it get updated. */
9076 w
->update_mode_line
= Qt
;
9077 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9078 /* In the non-toolkit version, the menu bar is an ordinary screen
9079 line, and this makes it get updated. */
9080 w
->update_mode_line
= Qt
;
9081 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9083 unbind_to (count
, Qnil
);
9084 set_buffer_internal_1 (prev
);
9091 /***********************************************************************
9093 ***********************************************************************/
9095 #ifdef HAVE_WINDOW_SYSTEM
9098 Nominal cursor position -- where to draw output.
9099 HPOS and VPOS are window relative glyph matrix coordinates.
9100 X and Y are window relative pixel coordinates. */
9102 struct cursor_pos output_cursor
;
9106 Set the global variable output_cursor to CURSOR. All cursor
9107 positions are relative to updated_window. */
9110 set_output_cursor (cursor
)
9111 struct cursor_pos
*cursor
;
9113 output_cursor
.hpos
= cursor
->hpos
;
9114 output_cursor
.vpos
= cursor
->vpos
;
9115 output_cursor
.x
= cursor
->x
;
9116 output_cursor
.y
= cursor
->y
;
9121 Set a nominal cursor position.
9123 HPOS and VPOS are column/row positions in a window glyph matrix. X
9124 and Y are window text area relative pixel positions.
9126 If this is done during an update, updated_window will contain the
9127 window that is being updated and the position is the future output
9128 cursor position for that window. If updated_window is null, use
9129 selected_window and display the cursor at the given position. */
9132 x_cursor_to (vpos
, hpos
, y
, x
)
9133 int vpos
, hpos
, y
, x
;
9137 /* If updated_window is not set, work on selected_window. */
9141 w
= XWINDOW (selected_window
);
9143 /* Set the output cursor. */
9144 output_cursor
.hpos
= hpos
;
9145 output_cursor
.vpos
= vpos
;
9146 output_cursor
.x
= x
;
9147 output_cursor
.y
= y
;
9149 /* If not called as part of an update, really display the cursor.
9150 This will also set the cursor position of W. */
9151 if (updated_window
== NULL
)
9154 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9155 if (rif
->flush_display_optional
)
9156 rif
->flush_display_optional (SELECTED_FRAME ());
9161 #endif /* HAVE_WINDOW_SYSTEM */
9164 /***********************************************************************
9166 ***********************************************************************/
9168 #ifdef HAVE_WINDOW_SYSTEM
9170 /* Where the mouse was last time we reported a mouse event. */
9172 FRAME_PTR last_mouse_frame
;
9174 /* Tool-bar item index of the item on which a mouse button was pressed
9177 int last_tool_bar_item
;
9180 /* Update the tool-bar item list for frame F. This has to be done
9181 before we start to fill in any display lines. Called from
9182 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9183 and restore it here. */
9186 update_tool_bar (f
, save_match_data
)
9188 int save_match_data
;
9191 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9193 int do_update
= WINDOWP (f
->tool_bar_window
)
9194 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9202 window
= FRAME_SELECTED_WINDOW (f
);
9203 w
= XWINDOW (window
);
9205 /* If the user has switched buffers or windows, we need to
9206 recompute to reflect the new bindings. But we'll
9207 recompute when update_mode_lines is set too; that means
9208 that people can use force-mode-line-update to request
9209 that the menu bar be recomputed. The adverse effect on
9210 the rest of the redisplay algorithm is about the same as
9211 windows_or_buffers_changed anyway. */
9212 if (windows_or_buffers_changed
9213 || !NILP (w
->update_mode_line
)
9214 || update_mode_lines
9215 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9216 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9217 != !NILP (w
->last_had_star
))
9218 || ((!NILP (Vtransient_mark_mode
)
9219 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9220 != !NILP (w
->region_showing
)))
9222 struct buffer
*prev
= current_buffer
;
9223 int count
= SPECPDL_INDEX ();
9224 Lisp_Object new_tool_bar
;
9226 struct gcpro gcpro1
;
9228 /* Set current_buffer to the buffer of the selected
9229 window of the frame, so that we get the right local
9231 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9233 /* Save match data, if we must. */
9234 if (save_match_data
)
9235 record_unwind_save_match_data ();
9237 /* Make sure that we don't accidentally use bogus keymaps. */
9238 if (NILP (Voverriding_local_map_menu_flag
))
9240 specbind (Qoverriding_terminal_local_map
, Qnil
);
9241 specbind (Qoverriding_local_map
, Qnil
);
9244 GCPRO1 (new_tool_bar
);
9246 /* Build desired tool-bar items from keymaps. */
9247 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9250 /* Redisplay the tool-bar if we changed it. */
9251 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9253 /* Redisplay that happens asynchronously due to an expose event
9254 may access f->tool_bar_items. Make sure we update both
9255 variables within BLOCK_INPUT so no such event interrupts. */
9257 f
->tool_bar_items
= new_tool_bar
;
9258 f
->n_tool_bar_items
= new_n_tool_bar
;
9259 w
->update_mode_line
= Qt
;
9265 unbind_to (count
, Qnil
);
9266 set_buffer_internal_1 (prev
);
9272 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9273 F's desired tool-bar contents. F->tool_bar_items must have
9274 been set up previously by calling prepare_menu_bars. */
9277 build_desired_tool_bar_string (f
)
9280 int i
, size
, size_needed
;
9281 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9282 Lisp_Object image
, plist
, props
;
9284 image
= plist
= props
= Qnil
;
9285 GCPRO3 (image
, plist
, props
);
9287 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9288 Otherwise, make a new string. */
9290 /* The size of the string we might be able to reuse. */
9291 size
= (STRINGP (f
->desired_tool_bar_string
)
9292 ? SCHARS (f
->desired_tool_bar_string
)
9295 /* We need one space in the string for each image. */
9296 size_needed
= f
->n_tool_bar_items
;
9298 /* Reuse f->desired_tool_bar_string, if possible. */
9299 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9300 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9304 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9305 Fremove_text_properties (make_number (0), make_number (size
),
9306 props
, f
->desired_tool_bar_string
);
9309 /* Put a `display' property on the string for the images to display,
9310 put a `menu_item' property on tool-bar items with a value that
9311 is the index of the item in F's tool-bar item vector. */
9312 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9314 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9316 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9317 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9318 int hmargin
, vmargin
, relief
, idx
, end
;
9319 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9321 /* If image is a vector, choose the image according to the
9323 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9324 if (VECTORP (image
))
9328 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9329 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9332 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9333 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9335 xassert (ASIZE (image
) >= idx
);
9336 image
= AREF (image
, idx
);
9341 /* Ignore invalid image specifications. */
9342 if (!valid_image_p (image
))
9345 /* Display the tool-bar button pressed, or depressed. */
9346 plist
= Fcopy_sequence (XCDR (image
));
9348 /* Compute margin and relief to draw. */
9349 relief
= (tool_bar_button_relief
>= 0
9350 ? tool_bar_button_relief
9351 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9352 hmargin
= vmargin
= relief
;
9354 if (INTEGERP (Vtool_bar_button_margin
)
9355 && XINT (Vtool_bar_button_margin
) > 0)
9357 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9358 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9360 else if (CONSP (Vtool_bar_button_margin
))
9362 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9363 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9364 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9366 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9367 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9368 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9371 if (auto_raise_tool_bar_buttons_p
)
9373 /* Add a `:relief' property to the image spec if the item is
9377 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9384 /* If image is selected, display it pressed, i.e. with a
9385 negative relief. If it's not selected, display it with a
9387 plist
= Fplist_put (plist
, QCrelief
,
9389 ? make_number (-relief
)
9390 : make_number (relief
)));
9395 /* Put a margin around the image. */
9396 if (hmargin
|| vmargin
)
9398 if (hmargin
== vmargin
)
9399 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9401 plist
= Fplist_put (plist
, QCmargin
,
9402 Fcons (make_number (hmargin
),
9403 make_number (vmargin
)));
9406 /* If button is not enabled, and we don't have special images
9407 for the disabled state, make the image appear disabled by
9408 applying an appropriate algorithm to it. */
9409 if (!enabled_p
&& idx
< 0)
9410 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9412 /* Put a `display' text property on the string for the image to
9413 display. Put a `menu-item' property on the string that gives
9414 the start of this item's properties in the tool-bar items
9416 image
= Fcons (Qimage
, plist
);
9417 props
= list4 (Qdisplay
, image
,
9418 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9420 /* Let the last image hide all remaining spaces in the tool bar
9421 string. The string can be longer than needed when we reuse a
9423 if (i
+ 1 == f
->n_tool_bar_items
)
9424 end
= SCHARS (f
->desired_tool_bar_string
);
9427 Fadd_text_properties (make_number (i
), make_number (end
),
9428 props
, f
->desired_tool_bar_string
);
9436 /* Display one line of the tool-bar of frame IT->f.
9438 HEIGHT specifies the desired height of the tool-bar line.
9439 If the actual height of the glyph row is less than HEIGHT, the
9440 row's height is increased to HEIGHT, and the icons are centered
9441 vertically in the new height. */
9444 display_tool_bar_line (it
, height
)
9448 struct glyph_row
*row
= it
->glyph_row
;
9449 int max_x
= it
->last_visible_x
;
9452 prepare_desired_row (row
);
9453 row
->y
= it
->current_y
;
9455 /* Note that this isn't made use of if the face hasn't a box,
9456 so there's no need to check the face here. */
9457 it
->start_of_box_run_p
= 1;
9459 while (it
->current_x
< max_x
)
9461 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9463 /* Get the next display element. */
9464 if (!get_next_display_element (it
))
9467 /* Produce glyphs. */
9468 x_before
= it
->current_x
;
9469 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9470 PRODUCE_GLYPHS (it
);
9472 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9477 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9479 if (x
+ glyph
->pixel_width
> max_x
)
9481 /* Glyph doesn't fit on line. */
9482 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9488 x
+= glyph
->pixel_width
;
9492 /* Stop at line ends. */
9493 if (ITERATOR_AT_END_OF_LINE_P (it
))
9496 set_iterator_to_next (it
, 1);
9501 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9502 /* Use default face for the border below the tool bar. */
9503 if (!row
->displays_text_p
)
9504 it
->face_id
= DEFAULT_FACE_ID
;
9505 extend_face_to_end_of_line (it
);
9506 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9507 last
->right_box_line_p
= 1;
9508 if (last
== row
->glyphs
[TEXT_AREA
])
9509 last
->left_box_line_p
= 1;
9511 /* Make line the desired height and center it vertically. */
9512 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9514 it
->max_ascent
+= height
/ 2;
9515 it
->max_descent
+= (height
+ 1) / 2;
9518 compute_line_metrics (it
);
9520 /* If line is empty, make it occupy the rest of the tool-bar. */
9521 if (!row
->displays_text_p
)
9523 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9524 row
->ascent
= row
->phys_ascent
= 0;
9525 row
->extra_line_spacing
= 0;
9528 row
->full_width_p
= 1;
9529 row
->continued_p
= 0;
9530 row
->truncated_on_left_p
= 0;
9531 row
->truncated_on_right_p
= 0;
9533 it
->current_x
= it
->hpos
= 0;
9534 it
->current_y
+= row
->height
;
9540 /* Value is the number of screen lines needed to make all tool-bar
9541 items of frame F visible. The number of actual rows needed is
9542 returned in *N_ROWS if non-NULL. */
9545 tool_bar_lines_needed (f
, n_rows
)
9549 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9552 /* Initialize an iterator for iteration over
9553 F->desired_tool_bar_string in the tool-bar window of frame F. */
9554 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9555 it
.first_visible_x
= 0;
9556 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9557 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9559 while (!ITERATOR_AT_END_P (&it
))
9561 it
.glyph_row
= w
->desired_matrix
->rows
;
9562 clear_glyph_row (it
.glyph_row
);
9563 display_tool_bar_line (&it
, 0);
9569 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9573 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9575 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9584 frame
= selected_frame
;
9586 CHECK_FRAME (frame
);
9589 if (WINDOWP (f
->tool_bar_window
)
9590 || (w
= XWINDOW (f
->tool_bar_window
),
9591 WINDOW_TOTAL_LINES (w
) > 0))
9593 update_tool_bar (f
, 1);
9594 if (f
->n_tool_bar_items
)
9596 build_desired_tool_bar_string (f
);
9597 nlines
= tool_bar_lines_needed (f
, NULL
);
9601 return make_number (nlines
);
9605 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9606 height should be changed. */
9609 redisplay_tool_bar (f
)
9614 struct glyph_row
*row
;
9615 int change_height_p
= 0;
9618 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9619 update_frame_tool_bar (f
);
9623 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9624 do anything. This means you must start with tool-bar-lines
9625 non-zero to get the auto-sizing effect. Or in other words, you
9626 can turn off tool-bars by specifying tool-bar-lines zero. */
9627 if (!WINDOWP (f
->tool_bar_window
)
9628 || (w
= XWINDOW (f
->tool_bar_window
),
9629 WINDOW_TOTAL_LINES (w
) == 0))
9632 /* Set up an iterator for the tool-bar window. */
9633 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9634 it
.first_visible_x
= 0;
9635 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9638 /* Build a string that represents the contents of the tool-bar. */
9639 build_desired_tool_bar_string (f
);
9640 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9642 if (f
->n_tool_bar_rows
== 0)
9644 (void)tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
);
9645 if (f
->n_tool_bar_rows
== 0)
9646 f
->n_tool_bar_rows
= -1;
9649 /* Display as many lines as needed to display all tool-bar items. */
9651 if (f
->n_tool_bar_rows
> 0)
9653 int border
, rows
, height
, extra
;
9655 if (INTEGERP (Vtool_bar_border
))
9656 border
= XINT (Vtool_bar_border
);
9657 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9658 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9659 else if (EQ (Vtool_bar_border
, Qborder_width
))
9660 border
= f
->border_width
;
9666 rows
= f
->n_tool_bar_rows
;
9667 height
= (it
.last_visible_y
- border
) / rows
;
9668 extra
= it
.last_visible_y
- border
- height
* rows
;
9670 while (it
.current_y
< it
.last_visible_y
)
9673 if (extra
> 0 && rows
-- > 0)
9675 h
= (extra
+ rows
- 1) / rows
;
9678 display_tool_bar_line (&it
, height
+ h
);
9683 while (it
.current_y
< it
.last_visible_y
)
9684 display_tool_bar_line (&it
, 0);
9687 /* It doesn't make much sense to try scrolling in the tool-bar
9688 window, so don't do it. */
9689 w
->desired_matrix
->no_scrolling_p
= 1;
9690 w
->must_be_updated_p
= 1;
9692 if (auto_resize_tool_bars_p
)
9696 /* If we couldn't display everything, change the tool-bar's
9698 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9699 change_height_p
= 1;
9701 /* If there are blank lines at the end, except for a partially
9702 visible blank line at the end that is smaller than
9703 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9704 row
= it
.glyph_row
- 1;
9705 if (!row
->displays_text_p
9706 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9707 change_height_p
= 1;
9709 /* If row displays tool-bar items, but is partially visible,
9710 change the tool-bar's height. */
9711 if (row
->displays_text_p
9712 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9713 change_height_p
= 1;
9715 /* Resize windows as needed by changing the `tool-bar-lines'
9718 && (nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9719 nlines
!= WINDOW_TOTAL_LINES (w
)))
9721 extern Lisp_Object Qtool_bar_lines
;
9723 int old_height
= WINDOW_TOTAL_LINES (w
);
9725 XSETFRAME (frame
, f
);
9726 clear_glyph_matrix (w
->desired_matrix
);
9727 Fmodify_frame_parameters (frame
,
9728 Fcons (Fcons (Qtool_bar_lines
,
9729 make_number (nlines
)),
9731 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9732 fonts_changed_p
= 1;
9736 return change_height_p
;
9740 /* Get information about the tool-bar item which is displayed in GLYPH
9741 on frame F. Return in *PROP_IDX the index where tool-bar item
9742 properties start in F->tool_bar_items. Value is zero if
9743 GLYPH doesn't display a tool-bar item. */
9746 tool_bar_item_info (f
, glyph
, prop_idx
)
9748 struct glyph
*glyph
;
9755 /* This function can be called asynchronously, which means we must
9756 exclude any possibility that Fget_text_property signals an
9758 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9759 charpos
= max (0, charpos
);
9761 /* Get the text property `menu-item' at pos. The value of that
9762 property is the start index of this item's properties in
9763 F->tool_bar_items. */
9764 prop
= Fget_text_property (make_number (charpos
),
9765 Qmenu_item
, f
->current_tool_bar_string
);
9766 if (INTEGERP (prop
))
9768 *prop_idx
= XINT (prop
);
9778 /* Get information about the tool-bar item at position X/Y on frame F.
9779 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9780 the current matrix of the tool-bar window of F, or NULL if not
9781 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9782 item in F->tool_bar_items. Value is
9784 -1 if X/Y is not on a tool-bar item
9785 0 if X/Y is on the same item that was highlighted before.
9789 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9792 struct glyph
**glyph
;
9793 int *hpos
, *vpos
, *prop_idx
;
9795 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9796 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9799 /* Find the glyph under X/Y. */
9800 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9804 /* Get the start of this tool-bar item's properties in
9805 f->tool_bar_items. */
9806 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9809 /* Is mouse on the highlighted item? */
9810 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9811 && *vpos
>= dpyinfo
->mouse_face_beg_row
9812 && *vpos
<= dpyinfo
->mouse_face_end_row
9813 && (*vpos
> dpyinfo
->mouse_face_beg_row
9814 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9815 && (*vpos
< dpyinfo
->mouse_face_end_row
9816 || *hpos
< dpyinfo
->mouse_face_end_col
9817 || dpyinfo
->mouse_face_past_end
))
9825 Handle mouse button event on the tool-bar of frame F, at
9826 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9827 0 for button release. MODIFIERS is event modifiers for button
9831 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9834 unsigned int modifiers
;
9836 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9837 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9838 int hpos
, vpos
, prop_idx
;
9839 struct glyph
*glyph
;
9840 Lisp_Object enabled_p
;
9842 /* If not on the highlighted tool-bar item, return. */
9843 frame_to_window_pixel_xy (w
, &x
, &y
);
9844 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9847 /* If item is disabled, do nothing. */
9848 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9849 if (NILP (enabled_p
))
9854 /* Show item in pressed state. */
9855 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9856 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9857 last_tool_bar_item
= prop_idx
;
9861 Lisp_Object key
, frame
;
9862 struct input_event event
;
9865 /* Show item in released state. */
9866 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9867 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9869 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9871 XSETFRAME (frame
, f
);
9872 event
.kind
= TOOL_BAR_EVENT
;
9873 event
.frame_or_window
= frame
;
9875 kbd_buffer_store_event (&event
);
9877 event
.kind
= TOOL_BAR_EVENT
;
9878 event
.frame_or_window
= frame
;
9880 event
.modifiers
= modifiers
;
9881 kbd_buffer_store_event (&event
);
9882 last_tool_bar_item
= -1;
9887 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9888 tool-bar window-relative coordinates X/Y. Called from
9889 note_mouse_highlight. */
9892 note_tool_bar_highlight (f
, x
, y
)
9896 Lisp_Object window
= f
->tool_bar_window
;
9897 struct window
*w
= XWINDOW (window
);
9898 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9900 struct glyph
*glyph
;
9901 struct glyph_row
*row
;
9903 Lisp_Object enabled_p
;
9905 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9906 int mouse_down_p
, rc
;
9908 /* Function note_mouse_highlight is called with negative x(y
9909 values when mouse moves outside of the frame. */
9910 if (x
<= 0 || y
<= 0)
9912 clear_mouse_face (dpyinfo
);
9916 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9919 /* Not on tool-bar item. */
9920 clear_mouse_face (dpyinfo
);
9924 /* On same tool-bar item as before. */
9927 clear_mouse_face (dpyinfo
);
9929 /* Mouse is down, but on different tool-bar item? */
9930 mouse_down_p
= (dpyinfo
->grabbed
9931 && f
== last_mouse_frame
9932 && FRAME_LIVE_P (f
));
9934 && last_tool_bar_item
!= prop_idx
)
9937 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9938 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9940 /* If tool-bar item is not enabled, don't highlight it. */
9941 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9942 if (!NILP (enabled_p
))
9944 /* Compute the x-position of the glyph. In front and past the
9945 image is a space. We include this in the highlighted area. */
9946 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9947 for (i
= x
= 0; i
< hpos
; ++i
)
9948 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9950 /* Record this as the current active region. */
9951 dpyinfo
->mouse_face_beg_col
= hpos
;
9952 dpyinfo
->mouse_face_beg_row
= vpos
;
9953 dpyinfo
->mouse_face_beg_x
= x
;
9954 dpyinfo
->mouse_face_beg_y
= row
->y
;
9955 dpyinfo
->mouse_face_past_end
= 0;
9957 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9958 dpyinfo
->mouse_face_end_row
= vpos
;
9959 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9960 dpyinfo
->mouse_face_end_y
= row
->y
;
9961 dpyinfo
->mouse_face_window
= window
;
9962 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9964 /* Display it as active. */
9965 show_mouse_face (dpyinfo
, draw
);
9966 dpyinfo
->mouse_face_image_state
= draw
;
9971 /* Set help_echo_string to a help string to display for this tool-bar item.
9972 XTread_socket does the rest. */
9973 help_echo_object
= help_echo_window
= Qnil
;
9975 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9976 if (NILP (help_echo_string
))
9977 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9980 #endif /* HAVE_WINDOW_SYSTEM */
9984 /************************************************************************
9985 Horizontal scrolling
9986 ************************************************************************/
9988 static int hscroll_window_tree
P_ ((Lisp_Object
));
9989 static int hscroll_windows
P_ ((Lisp_Object
));
9991 /* For all leaf windows in the window tree rooted at WINDOW, set their
9992 hscroll value so that PT is (i) visible in the window, and (ii) so
9993 that it is not within a certain margin at the window's left and
9994 right border. Value is non-zero if any window's hscroll has been
9998 hscroll_window_tree (window
)
10001 int hscrolled_p
= 0;
10002 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10003 int hscroll_step_abs
= 0;
10004 double hscroll_step_rel
= 0;
10006 if (hscroll_relative_p
)
10008 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10009 if (hscroll_step_rel
< 0)
10011 hscroll_relative_p
= 0;
10012 hscroll_step_abs
= 0;
10015 else if (INTEGERP (Vhscroll_step
))
10017 hscroll_step_abs
= XINT (Vhscroll_step
);
10018 if (hscroll_step_abs
< 0)
10019 hscroll_step_abs
= 0;
10022 hscroll_step_abs
= 0;
10024 while (WINDOWP (window
))
10026 struct window
*w
= XWINDOW (window
);
10028 if (WINDOWP (w
->hchild
))
10029 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10030 else if (WINDOWP (w
->vchild
))
10031 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10032 else if (w
->cursor
.vpos
>= 0)
10035 int text_area_width
;
10036 struct glyph_row
*current_cursor_row
10037 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10038 struct glyph_row
*desired_cursor_row
10039 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10040 struct glyph_row
*cursor_row
10041 = (desired_cursor_row
->enabled_p
10042 ? desired_cursor_row
10043 : current_cursor_row
);
10045 text_area_width
= window_box_width (w
, TEXT_AREA
);
10047 /* Scroll when cursor is inside this scroll margin. */
10048 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10050 if ((XFASTINT (w
->hscroll
)
10051 && w
->cursor
.x
<= h_margin
)
10052 || (cursor_row
->enabled_p
10053 && cursor_row
->truncated_on_right_p
10054 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10058 struct buffer
*saved_current_buffer
;
10062 /* Find point in a display of infinite width. */
10063 saved_current_buffer
= current_buffer
;
10064 current_buffer
= XBUFFER (w
->buffer
);
10066 if (w
== XWINDOW (selected_window
))
10067 pt
= BUF_PT (current_buffer
);
10070 pt
= marker_position (w
->pointm
);
10071 pt
= max (BEGV
, pt
);
10075 /* Move iterator to pt starting at cursor_row->start in
10076 a line with infinite width. */
10077 init_to_row_start (&it
, w
, cursor_row
);
10078 it
.last_visible_x
= INFINITY
;
10079 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10080 current_buffer
= saved_current_buffer
;
10082 /* Position cursor in window. */
10083 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10084 hscroll
= max (0, (it
.current_x
10085 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10086 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10087 : (text_area_width
/ 2))))
10088 / FRAME_COLUMN_WIDTH (it
.f
);
10089 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10091 if (hscroll_relative_p
)
10092 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10095 wanted_x
= text_area_width
10096 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10099 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10103 if (hscroll_relative_p
)
10104 wanted_x
= text_area_width
* hscroll_step_rel
10107 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10110 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10112 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10114 /* Don't call Fset_window_hscroll if value hasn't
10115 changed because it will prevent redisplay
10117 if (XFASTINT (w
->hscroll
) != hscroll
)
10119 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10120 w
->hscroll
= make_number (hscroll
);
10129 /* Value is non-zero if hscroll of any leaf window has been changed. */
10130 return hscrolled_p
;
10134 /* Set hscroll so that cursor is visible and not inside horizontal
10135 scroll margins for all windows in the tree rooted at WINDOW. See
10136 also hscroll_window_tree above. Value is non-zero if any window's
10137 hscroll has been changed. If it has, desired matrices on the frame
10138 of WINDOW are cleared. */
10141 hscroll_windows (window
)
10142 Lisp_Object window
;
10146 if (automatic_hscrolling_p
)
10148 hscrolled_p
= hscroll_window_tree (window
);
10150 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10154 return hscrolled_p
;
10159 /************************************************************************
10161 ************************************************************************/
10163 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10164 to a non-zero value. This is sometimes handy to have in a debugger
10169 /* First and last unchanged row for try_window_id. */
10171 int debug_first_unchanged_at_end_vpos
;
10172 int debug_last_unchanged_at_beg_vpos
;
10174 /* Delta vpos and y. */
10176 int debug_dvpos
, debug_dy
;
10178 /* Delta in characters and bytes for try_window_id. */
10180 int debug_delta
, debug_delta_bytes
;
10182 /* Values of window_end_pos and window_end_vpos at the end of
10185 EMACS_INT debug_end_pos
, debug_end_vpos
;
10187 /* Append a string to W->desired_matrix->method. FMT is a printf
10188 format string. A1...A9 are a supplement for a variable-length
10189 argument list. If trace_redisplay_p is non-zero also printf the
10190 resulting string to stderr. */
10193 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10196 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10199 char *method
= w
->desired_matrix
->method
;
10200 int len
= strlen (method
);
10201 int size
= sizeof w
->desired_matrix
->method
;
10202 int remaining
= size
- len
- 1;
10204 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10205 if (len
&& remaining
)
10208 --remaining
, ++len
;
10211 strncpy (method
+ len
, buffer
, remaining
);
10213 if (trace_redisplay_p
)
10214 fprintf (stderr
, "%p (%s): %s\n",
10216 ((BUFFERP (w
->buffer
)
10217 && STRINGP (XBUFFER (w
->buffer
)->name
))
10218 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10223 #endif /* GLYPH_DEBUG */
10226 /* Value is non-zero if all changes in window W, which displays
10227 current_buffer, are in the text between START and END. START is a
10228 buffer position, END is given as a distance from Z. Used in
10229 redisplay_internal for display optimization. */
10232 text_outside_line_unchanged_p (w
, start
, end
)
10236 int unchanged_p
= 1;
10238 /* If text or overlays have changed, see where. */
10239 if (XFASTINT (w
->last_modified
) < MODIFF
10240 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10242 /* Gap in the line? */
10243 if (GPT
< start
|| Z
- GPT
< end
)
10246 /* Changes start in front of the line, or end after it? */
10248 && (BEG_UNCHANGED
< start
- 1
10249 || END_UNCHANGED
< end
))
10252 /* If selective display, can't optimize if changes start at the
10253 beginning of the line. */
10255 && INTEGERP (current_buffer
->selective_display
)
10256 && XINT (current_buffer
->selective_display
) > 0
10257 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10260 /* If there are overlays at the start or end of the line, these
10261 may have overlay strings with newlines in them. A change at
10262 START, for instance, may actually concern the display of such
10263 overlay strings as well, and they are displayed on different
10264 lines. So, quickly rule out this case. (For the future, it
10265 might be desirable to implement something more telling than
10266 just BEG/END_UNCHANGED.) */
10269 if (BEG
+ BEG_UNCHANGED
== start
10270 && overlay_touches_p (start
))
10272 if (END_UNCHANGED
== end
10273 && overlay_touches_p (Z
- end
))
10278 return unchanged_p
;
10282 /* Do a frame update, taking possible shortcuts into account. This is
10283 the main external entry point for redisplay.
10285 If the last redisplay displayed an echo area message and that message
10286 is no longer requested, we clear the echo area or bring back the
10287 mini-buffer if that is in use. */
10292 redisplay_internal (0);
10297 overlay_arrow_string_or_property (var
)
10302 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10305 return Voverlay_arrow_string
;
10308 /* Return 1 if there are any overlay-arrows in current_buffer. */
10310 overlay_arrow_in_current_buffer_p ()
10314 for (vlist
= Voverlay_arrow_variable_list
;
10316 vlist
= XCDR (vlist
))
10318 Lisp_Object var
= XCAR (vlist
);
10321 if (!SYMBOLP (var
))
10323 val
= find_symbol_value (var
);
10325 && current_buffer
== XMARKER (val
)->buffer
)
10332 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10336 overlay_arrows_changed_p ()
10340 for (vlist
= Voverlay_arrow_variable_list
;
10342 vlist
= XCDR (vlist
))
10344 Lisp_Object var
= XCAR (vlist
);
10345 Lisp_Object val
, pstr
;
10347 if (!SYMBOLP (var
))
10349 val
= find_symbol_value (var
);
10350 if (!MARKERP (val
))
10352 if (! EQ (COERCE_MARKER (val
),
10353 Fget (var
, Qlast_arrow_position
))
10354 || ! (pstr
= overlay_arrow_string_or_property (var
),
10355 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10361 /* Mark overlay arrows to be updated on next redisplay. */
10364 update_overlay_arrows (up_to_date
)
10369 for (vlist
= Voverlay_arrow_variable_list
;
10371 vlist
= XCDR (vlist
))
10373 Lisp_Object var
= XCAR (vlist
);
10375 if (!SYMBOLP (var
))
10378 if (up_to_date
> 0)
10380 Lisp_Object val
= find_symbol_value (var
);
10381 Fput (var
, Qlast_arrow_position
,
10382 COERCE_MARKER (val
));
10383 Fput (var
, Qlast_arrow_string
,
10384 overlay_arrow_string_or_property (var
));
10386 else if (up_to_date
< 0
10387 || !NILP (Fget (var
, Qlast_arrow_position
)))
10389 Fput (var
, Qlast_arrow_position
, Qt
);
10390 Fput (var
, Qlast_arrow_string
, Qt
);
10396 /* Return overlay arrow string to display at row.
10397 Return integer (bitmap number) for arrow bitmap in left fringe.
10398 Return nil if no overlay arrow. */
10401 overlay_arrow_at_row (it
, row
)
10403 struct glyph_row
*row
;
10407 for (vlist
= Voverlay_arrow_variable_list
;
10409 vlist
= XCDR (vlist
))
10411 Lisp_Object var
= XCAR (vlist
);
10414 if (!SYMBOLP (var
))
10417 val
= find_symbol_value (var
);
10420 && current_buffer
== XMARKER (val
)->buffer
10421 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10423 if (FRAME_WINDOW_P (it
->f
)
10424 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10426 #ifdef HAVE_WINDOW_SYSTEM
10427 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10430 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10431 return make_number (fringe_bitmap
);
10434 return make_number (-1); /* Use default arrow bitmap */
10436 return overlay_arrow_string_or_property (var
);
10443 /* Return 1 if point moved out of or into a composition. Otherwise
10444 return 0. PREV_BUF and PREV_PT are the last point buffer and
10445 position. BUF and PT are the current point buffer and position. */
10448 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10449 struct buffer
*prev_buf
, *buf
;
10454 Lisp_Object buffer
;
10456 XSETBUFFER (buffer
, buf
);
10457 /* Check a composition at the last point if point moved within the
10459 if (prev_buf
== buf
)
10462 /* Point didn't move. */
10465 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10466 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10467 && COMPOSITION_VALID_P (start
, end
, prop
)
10468 && start
< prev_pt
&& end
> prev_pt
)
10469 /* The last point was within the composition. Return 1 iff
10470 point moved out of the composition. */
10471 return (pt
<= start
|| pt
>= end
);
10474 /* Check a composition at the current point. */
10475 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10476 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10477 && COMPOSITION_VALID_P (start
, end
, prop
)
10478 && start
< pt
&& end
> pt
);
10482 /* Reconsider the setting of B->clip_changed which is displayed
10486 reconsider_clip_changes (w
, b
)
10490 if (b
->clip_changed
10491 && !NILP (w
->window_end_valid
)
10492 && w
->current_matrix
->buffer
== b
10493 && w
->current_matrix
->zv
== BUF_ZV (b
)
10494 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10495 b
->clip_changed
= 0;
10497 /* If display wasn't paused, and W is not a tool bar window, see if
10498 point has been moved into or out of a composition. In that case,
10499 we set b->clip_changed to 1 to force updating the screen. If
10500 b->clip_changed has already been set to 1, we can skip this
10502 if (!b
->clip_changed
10503 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10507 if (w
== XWINDOW (selected_window
))
10508 pt
= BUF_PT (current_buffer
);
10510 pt
= marker_position (w
->pointm
);
10512 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10513 || pt
!= XINT (w
->last_point
))
10514 && check_point_in_composition (w
->current_matrix
->buffer
,
10515 XINT (w
->last_point
),
10516 XBUFFER (w
->buffer
), pt
))
10517 b
->clip_changed
= 1;
10522 /* Select FRAME to forward the values of frame-local variables into C
10523 variables so that the redisplay routines can access those values
10527 select_frame_for_redisplay (frame
)
10530 Lisp_Object tail
, sym
, val
;
10531 Lisp_Object old
= selected_frame
;
10533 selected_frame
= frame
;
10535 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10536 if (CONSP (XCAR (tail
))
10537 && (sym
= XCAR (XCAR (tail
)),
10539 && (sym
= indirect_variable (sym
),
10540 val
= SYMBOL_VALUE (sym
),
10541 (BUFFER_LOCAL_VALUEP (val
)
10542 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10543 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10544 /* Use find_symbol_value rather than Fsymbol_value
10545 to avoid an error if it is void. */
10546 find_symbol_value (sym
);
10548 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10549 if (CONSP (XCAR (tail
))
10550 && (sym
= XCAR (XCAR (tail
)),
10552 && (sym
= indirect_variable (sym
),
10553 val
= SYMBOL_VALUE (sym
),
10554 (BUFFER_LOCAL_VALUEP (val
)
10555 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10556 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10557 find_symbol_value (sym
);
10561 #define STOP_POLLING \
10562 do { if (! polling_stopped_here) stop_polling (); \
10563 polling_stopped_here = 1; } while (0)
10565 #define RESUME_POLLING \
10566 do { if (polling_stopped_here) start_polling (); \
10567 polling_stopped_here = 0; } while (0)
10570 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10571 response to any user action; therefore, we should preserve the echo
10572 area. (Actually, our caller does that job.) Perhaps in the future
10573 avoid recentering windows if it is not necessary; currently that
10574 causes some problems. */
10577 redisplay_internal (preserve_echo_area
)
10578 int preserve_echo_area
;
10580 struct window
*w
= XWINDOW (selected_window
);
10581 struct frame
*f
= XFRAME (w
->frame
);
10583 int must_finish
= 0;
10584 struct text_pos tlbufpos
, tlendpos
;
10585 int number_of_visible_frames
;
10587 struct frame
*sf
= SELECTED_FRAME ();
10588 int polling_stopped_here
= 0;
10590 /* Non-zero means redisplay has to consider all windows on all
10591 frames. Zero means, only selected_window is considered. */
10592 int consider_all_windows_p
;
10594 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10596 /* No redisplay if running in batch mode or frame is not yet fully
10597 initialized, or redisplay is explicitly turned off by setting
10598 Vinhibit_redisplay. */
10600 || !NILP (Vinhibit_redisplay
)
10601 || !f
->glyphs_initialized_p
)
10604 /* The flag redisplay_performed_directly_p is set by
10605 direct_output_for_insert when it already did the whole screen
10606 update necessary. */
10607 if (redisplay_performed_directly_p
)
10609 redisplay_performed_directly_p
= 0;
10610 if (!hscroll_windows (selected_window
))
10614 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10615 if (popup_activated ())
10619 /* I don't think this happens but let's be paranoid. */
10620 if (redisplaying_p
)
10623 /* Record a function that resets redisplaying_p to its old value
10624 when we leave this function. */
10625 count
= SPECPDL_INDEX ();
10626 record_unwind_protect (unwind_redisplay
,
10627 Fcons (make_number (redisplaying_p
), selected_frame
));
10629 specbind (Qinhibit_free_realized_faces
, Qnil
);
10632 Lisp_Object tail
, frame
;
10634 FOR_EACH_FRAME (tail
, frame
)
10636 struct frame
*f
= XFRAME (frame
);
10637 f
->already_hscrolled_p
= 0;
10643 reconsider_clip_changes (w
, current_buffer
);
10644 last_escape_glyph_frame
= NULL
;
10645 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10647 /* If new fonts have been loaded that make a glyph matrix adjustment
10648 necessary, do it. */
10649 if (fonts_changed_p
)
10651 adjust_glyphs (NULL
);
10652 ++windows_or_buffers_changed
;
10653 fonts_changed_p
= 0;
10656 /* If face_change_count is non-zero, init_iterator will free all
10657 realized faces, which includes the faces referenced from current
10658 matrices. So, we can't reuse current matrices in this case. */
10659 if (face_change_count
)
10660 ++windows_or_buffers_changed
;
10662 if (! FRAME_WINDOW_P (sf
)
10663 && previous_terminal_frame
!= sf
)
10665 /* Since frames on an ASCII terminal share the same display
10666 area, displaying a different frame means redisplay the whole
10668 windows_or_buffers_changed
++;
10669 SET_FRAME_GARBAGED (sf
);
10670 XSETFRAME (Vterminal_frame
, sf
);
10672 previous_terminal_frame
= sf
;
10674 /* Set the visible flags for all frames. Do this before checking
10675 for resized or garbaged frames; they want to know if their frames
10676 are visible. See the comment in frame.h for
10677 FRAME_SAMPLE_VISIBILITY. */
10679 Lisp_Object tail
, frame
;
10681 number_of_visible_frames
= 0;
10683 FOR_EACH_FRAME (tail
, frame
)
10685 struct frame
*f
= XFRAME (frame
);
10687 FRAME_SAMPLE_VISIBILITY (f
);
10688 if (FRAME_VISIBLE_P (f
))
10689 ++number_of_visible_frames
;
10690 clear_desired_matrices (f
);
10694 /* Notice any pending interrupt request to change frame size. */
10695 do_pending_window_change (1);
10697 /* Clear frames marked as garbaged. */
10698 if (frame_garbaged
)
10699 clear_garbaged_frames ();
10701 /* Build menubar and tool-bar items. */
10702 if (NILP (Vmemory_full
))
10703 prepare_menu_bars ();
10705 if (windows_or_buffers_changed
)
10706 update_mode_lines
++;
10708 /* Detect case that we need to write or remove a star in the mode line. */
10709 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10711 w
->update_mode_line
= Qt
;
10712 if (buffer_shared
> 1)
10713 update_mode_lines
++;
10716 /* If %c is in the mode line, update it if needed. */
10717 if (!NILP (w
->column_number_displayed
)
10718 /* This alternative quickly identifies a common case
10719 where no change is needed. */
10720 && !(PT
== XFASTINT (w
->last_point
)
10721 && XFASTINT (w
->last_modified
) >= MODIFF
10722 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10723 && (XFASTINT (w
->column_number_displayed
)
10724 != (int) current_column ())) /* iftc */
10725 w
->update_mode_line
= Qt
;
10727 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10729 /* The variable buffer_shared is set in redisplay_window and
10730 indicates that we redisplay a buffer in different windows. See
10732 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10733 || cursor_type_changed
);
10735 /* If specs for an arrow have changed, do thorough redisplay
10736 to ensure we remove any arrow that should no longer exist. */
10737 if (overlay_arrows_changed_p ())
10738 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10740 /* Normally the message* functions will have already displayed and
10741 updated the echo area, but the frame may have been trashed, or
10742 the update may have been preempted, so display the echo area
10743 again here. Checking message_cleared_p captures the case that
10744 the echo area should be cleared. */
10745 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10746 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10747 || (message_cleared_p
10748 && minibuf_level
== 0
10749 /* If the mini-window is currently selected, this means the
10750 echo-area doesn't show through. */
10751 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10753 int window_height_changed_p
= echo_area_display (0);
10756 /* If we don't display the current message, don't clear the
10757 message_cleared_p flag, because, if we did, we wouldn't clear
10758 the echo area in the next redisplay which doesn't preserve
10760 if (!display_last_displayed_message_p
)
10761 message_cleared_p
= 0;
10763 if (fonts_changed_p
)
10765 else if (window_height_changed_p
)
10767 consider_all_windows_p
= 1;
10768 ++update_mode_lines
;
10769 ++windows_or_buffers_changed
;
10771 /* If window configuration was changed, frames may have been
10772 marked garbaged. Clear them or we will experience
10773 surprises wrt scrolling. */
10774 if (frame_garbaged
)
10775 clear_garbaged_frames ();
10778 else if (EQ (selected_window
, minibuf_window
)
10779 && (current_buffer
->clip_changed
10780 || XFASTINT (w
->last_modified
) < MODIFF
10781 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10782 && resize_mini_window (w
, 0))
10784 /* Resized active mini-window to fit the size of what it is
10785 showing if its contents might have changed. */
10787 consider_all_windows_p
= 1;
10788 ++windows_or_buffers_changed
;
10789 ++update_mode_lines
;
10791 /* If window configuration was changed, frames may have been
10792 marked garbaged. Clear them or we will experience
10793 surprises wrt scrolling. */
10794 if (frame_garbaged
)
10795 clear_garbaged_frames ();
10799 /* If showing the region, and mark has changed, we must redisplay
10800 the whole window. The assignment to this_line_start_pos prevents
10801 the optimization directly below this if-statement. */
10802 if (((!NILP (Vtransient_mark_mode
)
10803 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10804 != !NILP (w
->region_showing
))
10805 || (!NILP (w
->region_showing
)
10806 && !EQ (w
->region_showing
,
10807 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10808 CHARPOS (this_line_start_pos
) = 0;
10810 /* Optimize the case that only the line containing the cursor in the
10811 selected window has changed. Variables starting with this_ are
10812 set in display_line and record information about the line
10813 containing the cursor. */
10814 tlbufpos
= this_line_start_pos
;
10815 tlendpos
= this_line_end_pos
;
10816 if (!consider_all_windows_p
10817 && CHARPOS (tlbufpos
) > 0
10818 && NILP (w
->update_mode_line
)
10819 && !current_buffer
->clip_changed
10820 && !current_buffer
->prevent_redisplay_optimizations_p
10821 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10822 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10823 /* Make sure recorded data applies to current buffer, etc. */
10824 && this_line_buffer
== current_buffer
10825 && current_buffer
== XBUFFER (w
->buffer
)
10826 && NILP (w
->force_start
)
10827 && NILP (w
->optional_new_start
)
10828 /* Point must be on the line that we have info recorded about. */
10829 && PT
>= CHARPOS (tlbufpos
)
10830 && PT
<= Z
- CHARPOS (tlendpos
)
10831 /* All text outside that line, including its final newline,
10832 must be unchanged */
10833 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10834 CHARPOS (tlendpos
)))
10836 if (CHARPOS (tlbufpos
) > BEGV
10837 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10838 && (CHARPOS (tlbufpos
) == ZV
10839 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10840 /* Former continuation line has disappeared by becoming empty */
10842 else if (XFASTINT (w
->last_modified
) < MODIFF
10843 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10844 || MINI_WINDOW_P (w
))
10846 /* We have to handle the case of continuation around a
10847 wide-column character (See the comment in indent.c around
10850 For instance, in the following case:
10852 -------- Insert --------
10853 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10854 J_I_ ==> J_I_ `^^' are cursors.
10858 As we have to redraw the line above, we should goto cancel. */
10861 int line_height_before
= this_line_pixel_height
;
10863 /* Note that start_display will handle the case that the
10864 line starting at tlbufpos is a continuation lines. */
10865 start_display (&it
, w
, tlbufpos
);
10867 /* Implementation note: It this still necessary? */
10868 if (it
.current_x
!= this_line_start_x
)
10871 TRACE ((stderr
, "trying display optimization 1\n"));
10872 w
->cursor
.vpos
= -1;
10873 overlay_arrow_seen
= 0;
10874 it
.vpos
= this_line_vpos
;
10875 it
.current_y
= this_line_y
;
10876 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10877 display_line (&it
);
10879 /* If line contains point, is not continued,
10880 and ends at same distance from eob as before, we win */
10881 if (w
->cursor
.vpos
>= 0
10882 /* Line is not continued, otherwise this_line_start_pos
10883 would have been set to 0 in display_line. */
10884 && CHARPOS (this_line_start_pos
)
10885 /* Line ends as before. */
10886 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10887 /* Line has same height as before. Otherwise other lines
10888 would have to be shifted up or down. */
10889 && this_line_pixel_height
== line_height_before
)
10891 /* If this is not the window's last line, we must adjust
10892 the charstarts of the lines below. */
10893 if (it
.current_y
< it
.last_visible_y
)
10895 struct glyph_row
*row
10896 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10897 int delta
, delta_bytes
;
10899 if (Z
- CHARPOS (tlendpos
) == ZV
)
10901 /* This line ends at end of (accessible part of)
10902 buffer. There is no newline to count. */
10904 - CHARPOS (tlendpos
)
10905 - MATRIX_ROW_START_CHARPOS (row
));
10906 delta_bytes
= (Z_BYTE
10907 - BYTEPOS (tlendpos
)
10908 - MATRIX_ROW_START_BYTEPOS (row
));
10912 /* This line ends in a newline. Must take
10913 account of the newline and the rest of the
10914 text that follows. */
10916 - CHARPOS (tlendpos
)
10917 - MATRIX_ROW_START_CHARPOS (row
));
10918 delta_bytes
= (Z_BYTE
10919 - BYTEPOS (tlendpos
)
10920 - MATRIX_ROW_START_BYTEPOS (row
));
10923 increment_matrix_positions (w
->current_matrix
,
10924 this_line_vpos
+ 1,
10925 w
->current_matrix
->nrows
,
10926 delta
, delta_bytes
);
10929 /* If this row displays text now but previously didn't,
10930 or vice versa, w->window_end_vpos may have to be
10932 if ((it
.glyph_row
- 1)->displays_text_p
)
10934 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10935 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10937 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10938 && this_line_vpos
> 0)
10939 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10940 w
->window_end_valid
= Qnil
;
10942 /* Update hint: No need to try to scroll in update_window. */
10943 w
->desired_matrix
->no_scrolling_p
= 1;
10946 *w
->desired_matrix
->method
= 0;
10947 debug_method_add (w
, "optimization 1");
10949 #ifdef HAVE_WINDOW_SYSTEM
10950 update_window_fringes (w
, 0);
10957 else if (/* Cursor position hasn't changed. */
10958 PT
== XFASTINT (w
->last_point
)
10959 /* Make sure the cursor was last displayed
10960 in this window. Otherwise we have to reposition it. */
10961 && 0 <= w
->cursor
.vpos
10962 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10966 do_pending_window_change (1);
10968 /* We used to always goto end_of_redisplay here, but this
10969 isn't enough if we have a blinking cursor. */
10970 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10971 goto end_of_redisplay
;
10975 /* If highlighting the region, or if the cursor is in the echo area,
10976 then we can't just move the cursor. */
10977 else if (! (!NILP (Vtransient_mark_mode
)
10978 && !NILP (current_buffer
->mark_active
))
10979 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10980 || highlight_nonselected_windows
)
10981 && NILP (w
->region_showing
)
10982 && NILP (Vshow_trailing_whitespace
)
10983 && !cursor_in_echo_area
)
10986 struct glyph_row
*row
;
10988 /* Skip from tlbufpos to PT and see where it is. Note that
10989 PT may be in invisible text. If so, we will end at the
10990 next visible position. */
10991 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10992 NULL
, DEFAULT_FACE_ID
);
10993 it
.current_x
= this_line_start_x
;
10994 it
.current_y
= this_line_y
;
10995 it
.vpos
= this_line_vpos
;
10997 /* The call to move_it_to stops in front of PT, but
10998 moves over before-strings. */
10999 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11001 if (it
.vpos
== this_line_vpos
11002 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11005 xassert (this_line_vpos
== it
.vpos
);
11006 xassert (this_line_y
== it
.current_y
);
11007 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11009 *w
->desired_matrix
->method
= 0;
11010 debug_method_add (w
, "optimization 3");
11019 /* Text changed drastically or point moved off of line. */
11020 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11023 CHARPOS (this_line_start_pos
) = 0;
11024 consider_all_windows_p
|= buffer_shared
> 1;
11025 ++clear_face_cache_count
;
11026 #ifdef HAVE_WINDOW_SYSTEM
11027 ++clear_image_cache_count
;
11030 /* Build desired matrices, and update the display. If
11031 consider_all_windows_p is non-zero, do it for all windows on all
11032 frames. Otherwise do it for selected_window, only. */
11034 if (consider_all_windows_p
)
11036 Lisp_Object tail
, frame
;
11038 FOR_EACH_FRAME (tail
, frame
)
11039 XFRAME (frame
)->updated_p
= 0;
11041 /* Recompute # windows showing selected buffer. This will be
11042 incremented each time such a window is displayed. */
11045 FOR_EACH_FRAME (tail
, frame
)
11047 struct frame
*f
= XFRAME (frame
);
11049 if (FRAME_WINDOW_P (f
) || f
== sf
)
11051 if (! EQ (frame
, selected_frame
))
11052 /* Select the frame, for the sake of frame-local
11054 select_frame_for_redisplay (frame
);
11056 /* Mark all the scroll bars to be removed; we'll redeem
11057 the ones we want when we redisplay their windows. */
11058 if (condemn_scroll_bars_hook
)
11059 condemn_scroll_bars_hook (f
);
11061 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11062 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11064 /* Any scroll bars which redisplay_windows should have
11065 nuked should now go away. */
11066 if (judge_scroll_bars_hook
)
11067 judge_scroll_bars_hook (f
);
11069 /* If fonts changed, display again. */
11070 /* ??? rms: I suspect it is a mistake to jump all the way
11071 back to retry here. It should just retry this frame. */
11072 if (fonts_changed_p
)
11075 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11077 /* See if we have to hscroll. */
11078 if (!f
->already_hscrolled_p
)
11080 f
->already_hscrolled_p
= 1;
11081 if (hscroll_windows (f
->root_window
))
11085 /* Prevent various kinds of signals during display
11086 update. stdio is not robust about handling
11087 signals, which can cause an apparent I/O
11089 if (interrupt_input
)
11090 unrequest_sigio ();
11093 /* Update the display. */
11094 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11095 pause
|= update_frame (f
, 0, 0);
11096 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11108 /* Do the mark_window_display_accurate after all windows have
11109 been redisplayed because this call resets flags in buffers
11110 which are needed for proper redisplay. */
11111 FOR_EACH_FRAME (tail
, frame
)
11113 struct frame
*f
= XFRAME (frame
);
11116 mark_window_display_accurate (f
->root_window
, 1);
11117 if (frame_up_to_date_hook
)
11118 frame_up_to_date_hook (f
);
11123 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11125 Lisp_Object mini_window
;
11126 struct frame
*mini_frame
;
11128 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11129 /* Use list_of_error, not Qerror, so that
11130 we catch only errors and don't run the debugger. */
11131 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11133 redisplay_window_error
);
11135 /* Compare desired and current matrices, perform output. */
11138 /* If fonts changed, display again. */
11139 if (fonts_changed_p
)
11142 /* Prevent various kinds of signals during display update.
11143 stdio is not robust about handling signals,
11144 which can cause an apparent I/O error. */
11145 if (interrupt_input
)
11146 unrequest_sigio ();
11149 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11151 if (hscroll_windows (selected_window
))
11154 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11155 pause
= update_frame (sf
, 0, 0);
11158 /* We may have called echo_area_display at the top of this
11159 function. If the echo area is on another frame, that may
11160 have put text on a frame other than the selected one, so the
11161 above call to update_frame would not have caught it. Catch
11163 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11164 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11166 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11168 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11169 pause
|= update_frame (mini_frame
, 0, 0);
11170 if (!pause
&& hscroll_windows (mini_window
))
11175 /* If display was paused because of pending input, make sure we do a
11176 thorough update the next time. */
11179 /* Prevent the optimization at the beginning of
11180 redisplay_internal that tries a single-line update of the
11181 line containing the cursor in the selected window. */
11182 CHARPOS (this_line_start_pos
) = 0;
11184 /* Let the overlay arrow be updated the next time. */
11185 update_overlay_arrows (0);
11187 /* If we pause after scrolling, some rows in the current
11188 matrices of some windows are not valid. */
11189 if (!WINDOW_FULL_WIDTH_P (w
)
11190 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11191 update_mode_lines
= 1;
11195 if (!consider_all_windows_p
)
11197 /* This has already been done above if
11198 consider_all_windows_p is set. */
11199 mark_window_display_accurate_1 (w
, 1);
11201 /* Say overlay arrows are up to date. */
11202 update_overlay_arrows (1);
11204 if (frame_up_to_date_hook
!= 0)
11205 frame_up_to_date_hook (sf
);
11208 update_mode_lines
= 0;
11209 windows_or_buffers_changed
= 0;
11210 cursor_type_changed
= 0;
11213 /* Start SIGIO interrupts coming again. Having them off during the
11214 code above makes it less likely one will discard output, but not
11215 impossible, since there might be stuff in the system buffer here.
11216 But it is much hairier to try to do anything about that. */
11217 if (interrupt_input
)
11221 /* If a frame has become visible which was not before, redisplay
11222 again, so that we display it. Expose events for such a frame
11223 (which it gets when becoming visible) don't call the parts of
11224 redisplay constructing glyphs, so simply exposing a frame won't
11225 display anything in this case. So, we have to display these
11226 frames here explicitly. */
11229 Lisp_Object tail
, frame
;
11232 FOR_EACH_FRAME (tail
, frame
)
11234 int this_is_visible
= 0;
11236 if (XFRAME (frame
)->visible
)
11237 this_is_visible
= 1;
11238 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11239 if (XFRAME (frame
)->visible
)
11240 this_is_visible
= 1;
11242 if (this_is_visible
)
11246 if (new_count
!= number_of_visible_frames
)
11247 windows_or_buffers_changed
++;
11250 /* Change frame size now if a change is pending. */
11251 do_pending_window_change (1);
11253 /* If we just did a pending size change, or have additional
11254 visible frames, redisplay again. */
11255 if (windows_or_buffers_changed
&& !pause
)
11258 /* Clear the face cache eventually. */
11259 if (consider_all_windows_p
)
11261 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11263 clear_face_cache (0);
11264 clear_face_cache_count
= 0;
11266 #ifdef HAVE_WINDOW_SYSTEM
11267 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11269 Lisp_Object tail
, frame
;
11270 FOR_EACH_FRAME (tail
, frame
)
11272 struct frame
*f
= XFRAME (frame
);
11273 if (FRAME_WINDOW_P (f
))
11274 clear_image_cache (f
, 0);
11276 clear_image_cache_count
= 0;
11278 #endif /* HAVE_WINDOW_SYSTEM */
11282 unbind_to (count
, Qnil
);
11287 /* Redisplay, but leave alone any recent echo area message unless
11288 another message has been requested in its place.
11290 This is useful in situations where you need to redisplay but no
11291 user action has occurred, making it inappropriate for the message
11292 area to be cleared. See tracking_off and
11293 wait_reading_process_output for examples of these situations.
11295 FROM_WHERE is an integer saying from where this function was
11296 called. This is useful for debugging. */
11299 redisplay_preserve_echo_area (from_where
)
11302 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11304 if (!NILP (echo_area_buffer
[1]))
11306 /* We have a previously displayed message, but no current
11307 message. Redisplay the previous message. */
11308 display_last_displayed_message_p
= 1;
11309 redisplay_internal (1);
11310 display_last_displayed_message_p
= 0;
11313 redisplay_internal (1);
11315 if (rif
!= NULL
&& rif
->flush_display_optional
)
11316 rif
->flush_display_optional (NULL
);
11320 /* Function registered with record_unwind_protect in
11321 redisplay_internal. Reset redisplaying_p to the value it had
11322 before redisplay_internal was called, and clear
11323 prevent_freeing_realized_faces_p. It also selects the previously
11327 unwind_redisplay (val
)
11330 Lisp_Object old_redisplaying_p
, old_frame
;
11332 old_redisplaying_p
= XCAR (val
);
11333 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11334 old_frame
= XCDR (val
);
11335 if (! EQ (old_frame
, selected_frame
))
11336 select_frame_for_redisplay (old_frame
);
11341 /* Mark the display of window W as accurate or inaccurate. If
11342 ACCURATE_P is non-zero mark display of W as accurate. If
11343 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11344 redisplay_internal is called. */
11347 mark_window_display_accurate_1 (w
, accurate_p
)
11351 if (BUFFERP (w
->buffer
))
11353 struct buffer
*b
= XBUFFER (w
->buffer
);
11356 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11357 w
->last_overlay_modified
11358 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11360 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11364 b
->clip_changed
= 0;
11365 b
->prevent_redisplay_optimizations_p
= 0;
11367 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11368 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11369 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11370 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11372 w
->current_matrix
->buffer
= b
;
11373 w
->current_matrix
->begv
= BUF_BEGV (b
);
11374 w
->current_matrix
->zv
= BUF_ZV (b
);
11376 w
->last_cursor
= w
->cursor
;
11377 w
->last_cursor_off_p
= w
->cursor_off_p
;
11379 if (w
== XWINDOW (selected_window
))
11380 w
->last_point
= make_number (BUF_PT (b
));
11382 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11388 w
->window_end_valid
= w
->buffer
;
11389 #if 0 /* This is incorrect with variable-height lines. */
11390 xassert (XINT (w
->window_end_vpos
)
11391 < (WINDOW_TOTAL_LINES (w
)
11392 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11394 w
->update_mode_line
= Qnil
;
11399 /* Mark the display of windows in the window tree rooted at WINDOW as
11400 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11401 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11402 be redisplayed the next time redisplay_internal is called. */
11405 mark_window_display_accurate (window
, accurate_p
)
11406 Lisp_Object window
;
11411 for (; !NILP (window
); window
= w
->next
)
11413 w
= XWINDOW (window
);
11414 mark_window_display_accurate_1 (w
, accurate_p
);
11416 if (!NILP (w
->vchild
))
11417 mark_window_display_accurate (w
->vchild
, accurate_p
);
11418 if (!NILP (w
->hchild
))
11419 mark_window_display_accurate (w
->hchild
, accurate_p
);
11424 update_overlay_arrows (1);
11428 /* Force a thorough redisplay the next time by setting
11429 last_arrow_position and last_arrow_string to t, which is
11430 unequal to any useful value of Voverlay_arrow_... */
11431 update_overlay_arrows (-1);
11436 /* Return value in display table DP (Lisp_Char_Table *) for character
11437 C. Since a display table doesn't have any parent, we don't have to
11438 follow parent. Do not call this function directly but use the
11439 macro DISP_CHAR_VECTOR. */
11442 disp_char_vector (dp
, c
)
11443 struct Lisp_Char_Table
*dp
;
11449 if (SINGLE_BYTE_CHAR_P (c
))
11450 return (dp
->contents
[c
]);
11452 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11455 else if (code
[2] < 32)
11458 /* Here, the possible range of code[0] (== charset ID) is
11459 128..max_charset. Since the top level char table contains data
11460 for multibyte characters after 256th element, we must increment
11461 code[0] by 128 to get a correct index. */
11463 code
[3] = -1; /* anchor */
11465 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11467 val
= dp
->contents
[code
[i
]];
11468 if (!SUB_CHAR_TABLE_P (val
))
11469 return (NILP (val
) ? dp
->defalt
: val
);
11472 /* Here, val is a sub char table. We return the default value of
11474 return (dp
->defalt
);
11479 /***********************************************************************
11481 ***********************************************************************/
11483 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11486 redisplay_windows (window
)
11487 Lisp_Object window
;
11489 while (!NILP (window
))
11491 struct window
*w
= XWINDOW (window
);
11493 if (!NILP (w
->hchild
))
11494 redisplay_windows (w
->hchild
);
11495 else if (!NILP (w
->vchild
))
11496 redisplay_windows (w
->vchild
);
11499 displayed_buffer
= XBUFFER (w
->buffer
);
11500 /* Use list_of_error, not Qerror, so that
11501 we catch only errors and don't run the debugger. */
11502 internal_condition_case_1 (redisplay_window_0
, window
,
11504 redisplay_window_error
);
11512 redisplay_window_error ()
11514 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11519 redisplay_window_0 (window
)
11520 Lisp_Object window
;
11522 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11523 redisplay_window (window
, 0);
11528 redisplay_window_1 (window
)
11529 Lisp_Object window
;
11531 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11532 redisplay_window (window
, 1);
11537 /* Increment GLYPH until it reaches END or CONDITION fails while
11538 adding (GLYPH)->pixel_width to X. */
11540 #define SKIP_GLYPHS(glyph, end, x, condition) \
11543 (x) += (glyph)->pixel_width; \
11546 while ((glyph) < (end) && (condition))
11549 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11550 DELTA is the number of bytes by which positions recorded in ROW
11551 differ from current buffer positions. */
11554 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11556 struct glyph_row
*row
;
11557 struct glyph_matrix
*matrix
;
11558 int delta
, delta_bytes
, dy
, dvpos
;
11560 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11561 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11562 struct glyph
*cursor
= NULL
;
11563 /* The first glyph that starts a sequence of glyphs from string. */
11564 struct glyph
*string_start
;
11565 /* The X coordinate of string_start. */
11566 int string_start_x
;
11567 /* The last known character position. */
11568 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11569 /* The last known character position before string_start. */
11570 int string_before_pos
;
11573 int cursor_from_overlay_pos
= 0;
11574 int pt_old
= PT
- delta
;
11576 /* Skip over glyphs not having an object at the start of the row.
11577 These are special glyphs like truncation marks on terminal
11579 if (row
->displays_text_p
)
11581 && INTEGERP (glyph
->object
)
11582 && glyph
->charpos
< 0)
11584 x
+= glyph
->pixel_width
;
11588 string_start
= NULL
;
11590 && !INTEGERP (glyph
->object
)
11591 && (!BUFFERP (glyph
->object
)
11592 || (last_pos
= glyph
->charpos
) < pt_old
))
11594 if (! STRINGP (glyph
->object
))
11596 string_start
= NULL
;
11597 x
+= glyph
->pixel_width
;
11599 if (cursor_from_overlay_pos
11600 && last_pos
> cursor_from_overlay_pos
)
11602 cursor_from_overlay_pos
= 0;
11608 string_before_pos
= last_pos
;
11609 string_start
= glyph
;
11610 string_start_x
= x
;
11611 /* Skip all glyphs from string. */
11615 if ((cursor
== NULL
|| glyph
> cursor
)
11616 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11617 Qcursor
, (glyph
)->object
))
11618 && (pos
= string_buffer_position (w
, glyph
->object
,
11619 string_before_pos
),
11620 (pos
== 0 /* From overlay */
11621 || pos
== pt_old
)))
11623 /* Estimate overlay buffer position from the buffer
11624 positions of the glyphs before and after the overlay.
11625 Add 1 to last_pos so that if point corresponds to the
11626 glyph right after the overlay, we still use a 'cursor'
11627 property found in that overlay. */
11628 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11632 x
+= glyph
->pixel_width
;
11635 while (glyph
< end
&& STRINGP (glyph
->object
));
11639 if (cursor
!= NULL
)
11644 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11646 /* Scan back over the ellipsis glyphs, decrementing positions. */
11647 while (glyph
> row
->glyphs
[TEXT_AREA
]
11648 && (glyph
- 1)->charpos
== last_pos
)
11649 glyph
--, x
-= glyph
->pixel_width
;
11650 /* That loop always goes one position too far,
11651 including the glyph before the ellipsis.
11652 So scan forward over that one. */
11653 x
+= glyph
->pixel_width
;
11656 else if (string_start
11657 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11659 /* We may have skipped over point because the previous glyphs
11660 are from string. As there's no easy way to know the
11661 character position of the current glyph, find the correct
11662 glyph on point by scanning from string_start again. */
11664 Lisp_Object string
;
11667 limit
= make_number (pt_old
+ 1);
11669 glyph
= string_start
;
11670 x
= string_start_x
;
11671 string
= glyph
->object
;
11672 pos
= string_buffer_position (w
, string
, string_before_pos
);
11673 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11674 because we always put cursor after overlay strings. */
11675 while (pos
== 0 && glyph
< end
)
11677 string
= glyph
->object
;
11678 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11680 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11683 while (glyph
< end
)
11685 pos
= XINT (Fnext_single_char_property_change
11686 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11689 /* Skip glyphs from the same string. */
11690 string
= glyph
->object
;
11691 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11692 /* Skip glyphs from an overlay. */
11694 && ! string_buffer_position (w
, glyph
->object
, pos
))
11696 string
= glyph
->object
;
11697 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11702 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11704 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11705 w
->cursor
.y
= row
->y
+ dy
;
11707 if (w
== XWINDOW (selected_window
))
11709 if (!row
->continued_p
11710 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11713 this_line_buffer
= XBUFFER (w
->buffer
);
11715 CHARPOS (this_line_start_pos
)
11716 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11717 BYTEPOS (this_line_start_pos
)
11718 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11720 CHARPOS (this_line_end_pos
)
11721 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11722 BYTEPOS (this_line_end_pos
)
11723 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11725 this_line_y
= w
->cursor
.y
;
11726 this_line_pixel_height
= row
->height
;
11727 this_line_vpos
= w
->cursor
.vpos
;
11728 this_line_start_x
= row
->x
;
11731 CHARPOS (this_line_start_pos
) = 0;
11736 /* Run window scroll functions, if any, for WINDOW with new window
11737 start STARTP. Sets the window start of WINDOW to that position.
11739 We assume that the window's buffer is really current. */
11741 static INLINE
struct text_pos
11742 run_window_scroll_functions (window
, startp
)
11743 Lisp_Object window
;
11744 struct text_pos startp
;
11746 struct window
*w
= XWINDOW (window
);
11747 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11749 if (current_buffer
!= XBUFFER (w
->buffer
))
11752 if (!NILP (Vwindow_scroll_functions
))
11754 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11755 make_number (CHARPOS (startp
)));
11756 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11757 /* In case the hook functions switch buffers. */
11758 if (current_buffer
!= XBUFFER (w
->buffer
))
11759 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11766 /* Make sure the line containing the cursor is fully visible.
11767 A value of 1 means there is nothing to be done.
11768 (Either the line is fully visible, or it cannot be made so,
11769 or we cannot tell.)
11771 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11772 is higher than window.
11774 A value of 0 means the caller should do scrolling
11775 as if point had gone off the screen. */
11778 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11781 int current_matrix_p
;
11783 struct glyph_matrix
*matrix
;
11784 struct glyph_row
*row
;
11787 if (!make_cursor_line_fully_visible_p
)
11790 /* It's not always possible to find the cursor, e.g, when a window
11791 is full of overlay strings. Don't do anything in that case. */
11792 if (w
->cursor
.vpos
< 0)
11795 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11796 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11798 /* If the cursor row is not partially visible, there's nothing to do. */
11799 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11802 /* If the row the cursor is in is taller than the window's height,
11803 it's not clear what to do, so do nothing. */
11804 window_height
= window_box_height (w
);
11805 if (row
->height
>= window_height
)
11807 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11813 /* This code used to try to scroll the window just enough to make
11814 the line visible. It returned 0 to say that the caller should
11815 allocate larger glyph matrices. */
11817 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11819 int dy
= row
->height
- row
->visible_height
;
11822 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11824 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11826 int dy
= - (row
->height
- row
->visible_height
);
11829 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11832 /* When we change the cursor y-position of the selected window,
11833 change this_line_y as well so that the display optimization for
11834 the cursor line of the selected window in redisplay_internal uses
11835 the correct y-position. */
11836 if (w
== XWINDOW (selected_window
))
11837 this_line_y
= w
->cursor
.y
;
11839 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11840 redisplay with larger matrices. */
11841 if (matrix
->nrows
< required_matrix_height (w
))
11843 fonts_changed_p
= 1;
11852 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11853 non-zero means only WINDOW is redisplayed in redisplay_internal.
11854 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11855 in redisplay_window to bring a partially visible line into view in
11856 the case that only the cursor has moved.
11858 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11859 last screen line's vertical height extends past the end of the screen.
11863 1 if scrolling succeeded
11865 0 if scrolling didn't find point.
11867 -1 if new fonts have been loaded so that we must interrupt
11868 redisplay, adjust glyph matrices, and try again. */
11874 SCROLLING_NEED_LARGER_MATRICES
11878 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11879 scroll_step
, temp_scroll_step
, last_line_misfit
)
11880 Lisp_Object window
;
11881 int just_this_one_p
;
11882 EMACS_INT scroll_conservatively
, scroll_step
;
11883 int temp_scroll_step
;
11884 int last_line_misfit
;
11886 struct window
*w
= XWINDOW (window
);
11887 struct frame
*f
= XFRAME (w
->frame
);
11888 struct text_pos scroll_margin_pos
;
11889 struct text_pos pos
;
11890 struct text_pos startp
;
11892 Lisp_Object window_end
;
11893 int this_scroll_margin
;
11897 int amount_to_scroll
= 0;
11898 Lisp_Object aggressive
;
11900 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11903 debug_method_add (w
, "try_scrolling");
11906 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11908 /* Compute scroll margin height in pixels. We scroll when point is
11909 within this distance from the top or bottom of the window. */
11910 if (scroll_margin
> 0)
11912 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11913 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11916 this_scroll_margin
= 0;
11918 /* Force scroll_conservatively to have a reasonable value so it doesn't
11919 cause an overflow while computing how much to scroll. */
11920 if (scroll_conservatively
)
11921 scroll_conservatively
= min (scroll_conservatively
,
11922 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11924 /* Compute how much we should try to scroll maximally to bring point
11926 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11927 scroll_max
= max (scroll_step
,
11928 max (scroll_conservatively
, temp_scroll_step
));
11929 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11930 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11931 /* We're trying to scroll because of aggressive scrolling
11932 but no scroll_step is set. Choose an arbitrary one. Maybe
11933 there should be a variable for this. */
11937 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11939 /* Decide whether we have to scroll down. Start at the window end
11940 and move this_scroll_margin up to find the position of the scroll
11942 window_end
= Fwindow_end (window
, Qt
);
11946 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11947 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11949 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11951 start_display (&it
, w
, scroll_margin_pos
);
11952 if (this_scroll_margin
)
11953 move_it_vertically_backward (&it
, this_scroll_margin
);
11954 if (extra_scroll_margin_lines
)
11955 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11956 scroll_margin_pos
= it
.current
.pos
;
11959 if (PT
>= CHARPOS (scroll_margin_pos
))
11963 /* Point is in the scroll margin at the bottom of the window, or
11964 below. Compute a new window start that makes point visible. */
11966 /* Compute the distance from the scroll margin to PT.
11967 Give up if the distance is greater than scroll_max. */
11968 start_display (&it
, w
, scroll_margin_pos
);
11970 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11971 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11973 /* To make point visible, we have to move the window start
11974 down so that the line the cursor is in is visible, which
11975 means we have to add in the height of the cursor line. */
11976 dy
= line_bottom_y (&it
) - y0
;
11978 if (dy
> scroll_max
)
11979 return SCROLLING_FAILED
;
11981 /* Move the window start down. If scrolling conservatively,
11982 move it just enough down to make point visible. If
11983 scroll_step is set, move it down by scroll_step. */
11984 start_display (&it
, w
, startp
);
11986 if (scroll_conservatively
)
11987 /* Set AMOUNT_TO_SCROLL to at least one line,
11988 and at most scroll_conservatively lines. */
11990 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11991 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11992 else if (scroll_step
|| temp_scroll_step
)
11993 amount_to_scroll
= scroll_max
;
11996 aggressive
= current_buffer
->scroll_up_aggressively
;
11997 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11998 if (NUMBERP (aggressive
))
12000 double float_amount
= XFLOATINT (aggressive
) * height
;
12001 amount_to_scroll
= float_amount
;
12002 if (amount_to_scroll
== 0 && float_amount
> 0)
12003 amount_to_scroll
= 1;
12007 if (amount_to_scroll
<= 0)
12008 return SCROLLING_FAILED
;
12010 /* If moving by amount_to_scroll leaves STARTP unchanged,
12011 move it down one screen line. */
12013 move_it_vertically (&it
, amount_to_scroll
);
12014 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12015 move_it_by_lines (&it
, 1, 1);
12016 startp
= it
.current
.pos
;
12020 /* See if point is inside the scroll margin at the top of the
12022 scroll_margin_pos
= startp
;
12023 if (this_scroll_margin
)
12025 start_display (&it
, w
, startp
);
12026 move_it_vertically (&it
, this_scroll_margin
);
12027 scroll_margin_pos
= it
.current
.pos
;
12030 if (PT
< CHARPOS (scroll_margin_pos
))
12032 /* Point is in the scroll margin at the top of the window or
12033 above what is displayed in the window. */
12036 /* Compute the vertical distance from PT to the scroll
12037 margin position. Give up if distance is greater than
12039 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12040 start_display (&it
, w
, pos
);
12042 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12043 it
.last_visible_y
, -1,
12044 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12045 dy
= it
.current_y
- y0
;
12046 if (dy
> scroll_max
)
12047 return SCROLLING_FAILED
;
12049 /* Compute new window start. */
12050 start_display (&it
, w
, startp
);
12052 if (scroll_conservatively
)
12054 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12055 else if (scroll_step
|| temp_scroll_step
)
12056 amount_to_scroll
= scroll_max
;
12059 aggressive
= current_buffer
->scroll_down_aggressively
;
12060 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12061 if (NUMBERP (aggressive
))
12063 double float_amount
= XFLOATINT (aggressive
) * height
;
12064 amount_to_scroll
= float_amount
;
12065 if (amount_to_scroll
== 0 && float_amount
> 0)
12066 amount_to_scroll
= 1;
12070 if (amount_to_scroll
<= 0)
12071 return SCROLLING_FAILED
;
12073 move_it_vertically_backward (&it
, amount_to_scroll
);
12074 startp
= it
.current
.pos
;
12078 /* Run window scroll functions. */
12079 startp
= run_window_scroll_functions (window
, startp
);
12081 /* Display the window. Give up if new fonts are loaded, or if point
12083 if (!try_window (window
, startp
, 0))
12084 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12085 else if (w
->cursor
.vpos
< 0)
12087 clear_glyph_matrix (w
->desired_matrix
);
12088 rc
= SCROLLING_FAILED
;
12092 /* Maybe forget recorded base line for line number display. */
12093 if (!just_this_one_p
12094 || current_buffer
->clip_changed
12095 || BEG_UNCHANGED
< CHARPOS (startp
))
12096 w
->base_line_number
= Qnil
;
12098 /* If cursor ends up on a partially visible line,
12099 treat that as being off the bottom of the screen. */
12100 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12102 clear_glyph_matrix (w
->desired_matrix
);
12103 ++extra_scroll_margin_lines
;
12106 rc
= SCROLLING_SUCCESS
;
12113 /* Compute a suitable window start for window W if display of W starts
12114 on a continuation line. Value is non-zero if a new window start
12117 The new window start will be computed, based on W's width, starting
12118 from the start of the continued line. It is the start of the
12119 screen line with the minimum distance from the old start W->start. */
12122 compute_window_start_on_continuation_line (w
)
12125 struct text_pos pos
, start_pos
;
12126 int window_start_changed_p
= 0;
12128 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12130 /* If window start is on a continuation line... Window start may be
12131 < BEGV in case there's invisible text at the start of the
12132 buffer (M-x rmail, for example). */
12133 if (CHARPOS (start_pos
) > BEGV
12134 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12137 struct glyph_row
*row
;
12139 /* Handle the case that the window start is out of range. */
12140 if (CHARPOS (start_pos
) < BEGV
)
12141 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12142 else if (CHARPOS (start_pos
) > ZV
)
12143 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12145 /* Find the start of the continued line. This should be fast
12146 because scan_buffer is fast (newline cache). */
12147 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12148 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12149 row
, DEFAULT_FACE_ID
);
12150 reseat_at_previous_visible_line_start (&it
);
12152 /* If the line start is "too far" away from the window start,
12153 say it takes too much time to compute a new window start. */
12154 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12155 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12157 int min_distance
, distance
;
12159 /* Move forward by display lines to find the new window
12160 start. If window width was enlarged, the new start can
12161 be expected to be > the old start. If window width was
12162 decreased, the new window start will be < the old start.
12163 So, we're looking for the display line start with the
12164 minimum distance from the old window start. */
12165 pos
= it
.current
.pos
;
12166 min_distance
= INFINITY
;
12167 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12168 distance
< min_distance
)
12170 min_distance
= distance
;
12171 pos
= it
.current
.pos
;
12172 move_it_by_lines (&it
, 1, 0);
12175 /* Set the window start there. */
12176 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12177 window_start_changed_p
= 1;
12181 return window_start_changed_p
;
12185 /* Try cursor movement in case text has not changed in window WINDOW,
12186 with window start STARTP. Value is
12188 CURSOR_MOVEMENT_SUCCESS if successful
12190 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12192 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12193 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12194 we want to scroll as if scroll-step were set to 1. See the code.
12196 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12197 which case we have to abort this redisplay, and adjust matrices
12202 CURSOR_MOVEMENT_SUCCESS
,
12203 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12204 CURSOR_MOVEMENT_MUST_SCROLL
,
12205 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12209 try_cursor_movement (window
, startp
, scroll_step
)
12210 Lisp_Object window
;
12211 struct text_pos startp
;
12214 struct window
*w
= XWINDOW (window
);
12215 struct frame
*f
= XFRAME (w
->frame
);
12216 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12219 if (inhibit_try_cursor_movement
)
12223 /* Handle case where text has not changed, only point, and it has
12224 not moved off the frame. */
12225 if (/* Point may be in this window. */
12226 PT
>= CHARPOS (startp
)
12227 /* Selective display hasn't changed. */
12228 && !current_buffer
->clip_changed
12229 /* Function force-mode-line-update is used to force a thorough
12230 redisplay. It sets either windows_or_buffers_changed or
12231 update_mode_lines. So don't take a shortcut here for these
12233 && !update_mode_lines
12234 && !windows_or_buffers_changed
12235 && !cursor_type_changed
12236 /* Can't use this case if highlighting a region. When a
12237 region exists, cursor movement has to do more than just
12239 && !(!NILP (Vtransient_mark_mode
)
12240 && !NILP (current_buffer
->mark_active
))
12241 && NILP (w
->region_showing
)
12242 && NILP (Vshow_trailing_whitespace
)
12243 /* Right after splitting windows, last_point may be nil. */
12244 && INTEGERP (w
->last_point
)
12245 /* This code is not used for mini-buffer for the sake of the case
12246 of redisplaying to replace an echo area message; since in
12247 that case the mini-buffer contents per se are usually
12248 unchanged. This code is of no real use in the mini-buffer
12249 since the handling of this_line_start_pos, etc., in redisplay
12250 handles the same cases. */
12251 && !EQ (window
, minibuf_window
)
12252 /* When splitting windows or for new windows, it happens that
12253 redisplay is called with a nil window_end_vpos or one being
12254 larger than the window. This should really be fixed in
12255 window.c. I don't have this on my list, now, so we do
12256 approximately the same as the old redisplay code. --gerd. */
12257 && INTEGERP (w
->window_end_vpos
)
12258 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12259 && (FRAME_WINDOW_P (f
)
12260 || !overlay_arrow_in_current_buffer_p ()))
12262 int this_scroll_margin
, top_scroll_margin
;
12263 struct glyph_row
*row
= NULL
;
12266 debug_method_add (w
, "cursor movement");
12269 /* Scroll if point within this distance from the top or bottom
12270 of the window. This is a pixel value. */
12271 this_scroll_margin
= max (0, scroll_margin
);
12272 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12273 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12275 top_scroll_margin
= this_scroll_margin
;
12276 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12277 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12279 /* Start with the row the cursor was displayed during the last
12280 not paused redisplay. Give up if that row is not valid. */
12281 if (w
->last_cursor
.vpos
< 0
12282 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12283 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12286 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12287 if (row
->mode_line_p
)
12289 if (!row
->enabled_p
)
12290 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12293 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12296 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12298 if (PT
> XFASTINT (w
->last_point
))
12300 /* Point has moved forward. */
12301 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12302 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12304 xassert (row
->enabled_p
);
12308 /* The end position of a row equals the start position
12309 of the next row. If PT is there, we would rather
12310 display it in the next line. */
12311 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12312 && MATRIX_ROW_END_CHARPOS (row
) == PT
12313 && !cursor_row_p (w
, row
))
12316 /* If within the scroll margin, scroll. Note that
12317 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12318 the next line would be drawn, and that
12319 this_scroll_margin can be zero. */
12320 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12321 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12322 /* Line is completely visible last line in window
12323 and PT is to be set in the next line. */
12324 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12325 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12326 && !row
->ends_at_zv_p
12327 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12330 else if (PT
< XFASTINT (w
->last_point
))
12332 /* Cursor has to be moved backward. Note that PT >=
12333 CHARPOS (startp) because of the outer if-statement. */
12334 while (!row
->mode_line_p
12335 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12336 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12337 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12338 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12339 row
> w
->current_matrix
->rows
12340 && (row
-1)->ends_in_newline_from_string_p
))))
12341 && (row
->y
> top_scroll_margin
12342 || CHARPOS (startp
) == BEGV
))
12344 xassert (row
->enabled_p
);
12348 /* Consider the following case: Window starts at BEGV,
12349 there is invisible, intangible text at BEGV, so that
12350 display starts at some point START > BEGV. It can
12351 happen that we are called with PT somewhere between
12352 BEGV and START. Try to handle that case. */
12353 if (row
< w
->current_matrix
->rows
12354 || row
->mode_line_p
)
12356 row
= w
->current_matrix
->rows
;
12357 if (row
->mode_line_p
)
12361 /* Due to newlines in overlay strings, we may have to
12362 skip forward over overlay strings. */
12363 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12364 && MATRIX_ROW_END_CHARPOS (row
) == PT
12365 && !cursor_row_p (w
, row
))
12368 /* If within the scroll margin, scroll. */
12369 if (row
->y
< top_scroll_margin
12370 && CHARPOS (startp
) != BEGV
)
12375 /* Cursor did not move. So don't scroll even if cursor line
12376 is partially visible, as it was so before. */
12377 rc
= CURSOR_MOVEMENT_SUCCESS
;
12380 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12381 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12383 /* if PT is not in the glyph row, give up. */
12384 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12386 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12387 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12388 && make_cursor_line_fully_visible_p
)
12390 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12391 && !row
->ends_at_zv_p
12392 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12393 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12394 else if (row
->height
> window_box_height (w
))
12396 /* If we end up in a partially visible line, let's
12397 make it fully visible, except when it's taller
12398 than the window, in which case we can't do much
12401 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12405 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12406 if (!cursor_row_fully_visible_p (w
, 0, 1))
12407 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12409 rc
= CURSOR_MOVEMENT_SUCCESS
;
12413 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12416 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12417 rc
= CURSOR_MOVEMENT_SUCCESS
;
12426 set_vertical_scroll_bar (w
)
12429 int start
, end
, whole
;
12431 /* Calculate the start and end positions for the current window.
12432 At some point, it would be nice to choose between scrollbars
12433 which reflect the whole buffer size, with special markers
12434 indicating narrowing, and scrollbars which reflect only the
12437 Note that mini-buffers sometimes aren't displaying any text. */
12438 if (!MINI_WINDOW_P (w
)
12439 || (w
== XWINDOW (minibuf_window
)
12440 && NILP (echo_area_buffer
[0])))
12442 struct buffer
*buf
= XBUFFER (w
->buffer
);
12443 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12444 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12445 /* I don't think this is guaranteed to be right. For the
12446 moment, we'll pretend it is. */
12447 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12451 if (whole
< (end
- start
))
12452 whole
= end
- start
;
12455 start
= end
= whole
= 0;
12457 /* Indicate what this scroll bar ought to be displaying now. */
12458 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12462 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12463 selected_window is redisplayed.
12465 We can return without actually redisplaying the window if
12466 fonts_changed_p is nonzero. In that case, redisplay_internal will
12470 redisplay_window (window
, just_this_one_p
)
12471 Lisp_Object window
;
12472 int just_this_one_p
;
12474 struct window
*w
= XWINDOW (window
);
12475 struct frame
*f
= XFRAME (w
->frame
);
12476 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12477 struct buffer
*old
= current_buffer
;
12478 struct text_pos lpoint
, opoint
, startp
;
12479 int update_mode_line
;
12482 /* Record it now because it's overwritten. */
12483 int current_matrix_up_to_date_p
= 0;
12484 int used_current_matrix_p
= 0;
12485 /* This is less strict than current_matrix_up_to_date_p.
12486 It indictes that the buffer contents and narrowing are unchanged. */
12487 int buffer_unchanged_p
= 0;
12488 int temp_scroll_step
= 0;
12489 int count
= SPECPDL_INDEX ();
12491 int centering_position
= -1;
12492 int last_line_misfit
= 0;
12494 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12497 /* W must be a leaf window here. */
12498 xassert (!NILP (w
->buffer
));
12500 *w
->desired_matrix
->method
= 0;
12503 specbind (Qinhibit_point_motion_hooks
, Qt
);
12505 reconsider_clip_changes (w
, buffer
);
12507 /* Has the mode line to be updated? */
12508 update_mode_line
= (!NILP (w
->update_mode_line
)
12509 || update_mode_lines
12510 || buffer
->clip_changed
12511 || buffer
->prevent_redisplay_optimizations_p
);
12513 if (MINI_WINDOW_P (w
))
12515 if (w
== XWINDOW (echo_area_window
)
12516 && !NILP (echo_area_buffer
[0]))
12518 if (update_mode_line
)
12519 /* We may have to update a tty frame's menu bar or a
12520 tool-bar. Example `M-x C-h C-h C-g'. */
12521 goto finish_menu_bars
;
12523 /* We've already displayed the echo area glyphs in this window. */
12524 goto finish_scroll_bars
;
12526 else if ((w
!= XWINDOW (minibuf_window
)
12527 || minibuf_level
== 0)
12528 /* When buffer is nonempty, redisplay window normally. */
12529 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12530 /* Quail displays non-mini buffers in minibuffer window.
12531 In that case, redisplay the window normally. */
12532 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12534 /* W is a mini-buffer window, but it's not active, so clear
12536 int yb
= window_text_bottom_y (w
);
12537 struct glyph_row
*row
;
12540 for (y
= 0, row
= w
->desired_matrix
->rows
;
12542 y
+= row
->height
, ++row
)
12543 blank_row (w
, row
, y
);
12544 goto finish_scroll_bars
;
12547 clear_glyph_matrix (w
->desired_matrix
);
12550 /* Otherwise set up data on this window; select its buffer and point
12552 /* Really select the buffer, for the sake of buffer-local
12554 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12555 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12557 current_matrix_up_to_date_p
12558 = (!NILP (w
->window_end_valid
)
12559 && !current_buffer
->clip_changed
12560 && !current_buffer
->prevent_redisplay_optimizations_p
12561 && XFASTINT (w
->last_modified
) >= MODIFF
12562 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12565 = (!NILP (w
->window_end_valid
)
12566 && !current_buffer
->clip_changed
12567 && XFASTINT (w
->last_modified
) >= MODIFF
12568 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12570 /* When windows_or_buffers_changed is non-zero, we can't rely on
12571 the window end being valid, so set it to nil there. */
12572 if (windows_or_buffers_changed
)
12574 /* If window starts on a continuation line, maybe adjust the
12575 window start in case the window's width changed. */
12576 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12577 compute_window_start_on_continuation_line (w
);
12579 w
->window_end_valid
= Qnil
;
12582 /* Some sanity checks. */
12583 CHECK_WINDOW_END (w
);
12584 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12586 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12589 /* If %c is in mode line, update it if needed. */
12590 if (!NILP (w
->column_number_displayed
)
12591 /* This alternative quickly identifies a common case
12592 where no change is needed. */
12593 && !(PT
== XFASTINT (w
->last_point
)
12594 && XFASTINT (w
->last_modified
) >= MODIFF
12595 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12596 && (XFASTINT (w
->column_number_displayed
)
12597 != (int) current_column ())) /* iftc */
12598 update_mode_line
= 1;
12600 /* Count number of windows showing the selected buffer. An indirect
12601 buffer counts as its base buffer. */
12602 if (!just_this_one_p
)
12604 struct buffer
*current_base
, *window_base
;
12605 current_base
= current_buffer
;
12606 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12607 if (current_base
->base_buffer
)
12608 current_base
= current_base
->base_buffer
;
12609 if (window_base
->base_buffer
)
12610 window_base
= window_base
->base_buffer
;
12611 if (current_base
== window_base
)
12615 /* Point refers normally to the selected window. For any other
12616 window, set up appropriate value. */
12617 if (!EQ (window
, selected_window
))
12619 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12620 int new_pt_byte
= marker_byte_position (w
->pointm
);
12624 new_pt_byte
= BEGV_BYTE
;
12625 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12627 else if (new_pt
> (ZV
- 1))
12630 new_pt_byte
= ZV_BYTE
;
12631 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12634 /* We don't use SET_PT so that the point-motion hooks don't run. */
12635 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12638 /* If any of the character widths specified in the display table
12639 have changed, invalidate the width run cache. It's true that
12640 this may be a bit late to catch such changes, but the rest of
12641 redisplay goes (non-fatally) haywire when the display table is
12642 changed, so why should we worry about doing any better? */
12643 if (current_buffer
->width_run_cache
)
12645 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12647 if (! disptab_matches_widthtab (disptab
,
12648 XVECTOR (current_buffer
->width_table
)))
12650 invalidate_region_cache (current_buffer
,
12651 current_buffer
->width_run_cache
,
12653 recompute_width_table (current_buffer
, disptab
);
12657 /* If window-start is screwed up, choose a new one. */
12658 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12661 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12663 /* If someone specified a new starting point but did not insist,
12664 check whether it can be used. */
12665 if (!NILP (w
->optional_new_start
)
12666 && CHARPOS (startp
) >= BEGV
12667 && CHARPOS (startp
) <= ZV
)
12669 w
->optional_new_start
= Qnil
;
12670 start_display (&it
, w
, startp
);
12671 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12672 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12673 if (IT_CHARPOS (it
) == PT
)
12674 w
->force_start
= Qt
;
12675 /* IT may overshoot PT if text at PT is invisible. */
12676 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12677 w
->force_start
= Qt
;
12682 /* Handle case where place to start displaying has been specified,
12683 unless the specified location is outside the accessible range. */
12684 if (!NILP (w
->force_start
)
12685 || w
->frozen_window_start_p
)
12687 /* We set this later on if we have to adjust point. */
12691 w
->force_start
= Qnil
;
12693 w
->window_end_valid
= Qnil
;
12695 /* Forget any recorded base line for line number display. */
12696 if (!buffer_unchanged_p
)
12697 w
->base_line_number
= Qnil
;
12699 /* Redisplay the mode line. Select the buffer properly for that.
12700 Also, run the hook window-scroll-functions
12701 because we have scrolled. */
12702 /* Note, we do this after clearing force_start because
12703 if there's an error, it is better to forget about force_start
12704 than to get into an infinite loop calling the hook functions
12705 and having them get more errors. */
12706 if (!update_mode_line
12707 || ! NILP (Vwindow_scroll_functions
))
12709 update_mode_line
= 1;
12710 w
->update_mode_line
= Qt
;
12711 startp
= run_window_scroll_functions (window
, startp
);
12714 w
->last_modified
= make_number (0);
12715 w
->last_overlay_modified
= make_number (0);
12716 if (CHARPOS (startp
) < BEGV
)
12717 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12718 else if (CHARPOS (startp
) > ZV
)
12719 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12721 /* Redisplay, then check if cursor has been set during the
12722 redisplay. Give up if new fonts were loaded. */
12723 val
= try_window (window
, startp
, 1);
12726 w
->force_start
= Qt
;
12727 clear_glyph_matrix (w
->desired_matrix
);
12728 goto need_larger_matrices
;
12730 /* Point was outside the scroll margins. */
12732 new_vpos
= window_box_height (w
) / 2;
12734 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12736 /* If point does not appear, try to move point so it does
12737 appear. The desired matrix has been built above, so we
12738 can use it here. */
12739 new_vpos
= window_box_height (w
) / 2;
12742 if (!cursor_row_fully_visible_p (w
, 0, 0))
12744 /* Point does appear, but on a line partly visible at end of window.
12745 Move it back to a fully-visible line. */
12746 new_vpos
= window_box_height (w
);
12749 /* If we need to move point for either of the above reasons,
12750 now actually do it. */
12753 struct glyph_row
*row
;
12755 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12756 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12759 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12760 MATRIX_ROW_START_BYTEPOS (row
));
12762 if (w
!= XWINDOW (selected_window
))
12763 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12764 else if (current_buffer
== old
)
12765 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12767 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12769 /* If we are highlighting the region, then we just changed
12770 the region, so redisplay to show it. */
12771 if (!NILP (Vtransient_mark_mode
)
12772 && !NILP (current_buffer
->mark_active
))
12774 clear_glyph_matrix (w
->desired_matrix
);
12775 if (!try_window (window
, startp
, 0))
12776 goto need_larger_matrices
;
12781 debug_method_add (w
, "forced window start");
12786 /* Handle case where text has not changed, only point, and it has
12787 not moved off the frame, and we are not retrying after hscroll.
12788 (current_matrix_up_to_date_p is nonzero when retrying.) */
12789 if (current_matrix_up_to_date_p
12790 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12791 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12795 case CURSOR_MOVEMENT_SUCCESS
:
12796 used_current_matrix_p
= 1;
12799 #if 0 /* try_cursor_movement never returns this value. */
12800 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12801 goto need_larger_matrices
;
12804 case CURSOR_MOVEMENT_MUST_SCROLL
:
12805 goto try_to_scroll
;
12811 /* If current starting point was originally the beginning of a line
12812 but no longer is, find a new starting point. */
12813 else if (!NILP (w
->start_at_line_beg
)
12814 && !(CHARPOS (startp
) <= BEGV
12815 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12818 debug_method_add (w
, "recenter 1");
12823 /* Try scrolling with try_window_id. Value is > 0 if update has
12824 been done, it is -1 if we know that the same window start will
12825 not work. It is 0 if unsuccessful for some other reason. */
12826 else if ((tem
= try_window_id (w
)) != 0)
12829 debug_method_add (w
, "try_window_id %d", tem
);
12832 if (fonts_changed_p
)
12833 goto need_larger_matrices
;
12837 /* Otherwise try_window_id has returned -1 which means that we
12838 don't want the alternative below this comment to execute. */
12840 else if (CHARPOS (startp
) >= BEGV
12841 && CHARPOS (startp
) <= ZV
12842 && PT
>= CHARPOS (startp
)
12843 && (CHARPOS (startp
) < ZV
12844 /* Avoid starting at end of buffer. */
12845 || CHARPOS (startp
) == BEGV
12846 || (XFASTINT (w
->last_modified
) >= MODIFF
12847 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12850 debug_method_add (w
, "same window start");
12853 /* Try to redisplay starting at same place as before.
12854 If point has not moved off frame, accept the results. */
12855 if (!current_matrix_up_to_date_p
12856 /* Don't use try_window_reusing_current_matrix in this case
12857 because a window scroll function can have changed the
12859 || !NILP (Vwindow_scroll_functions
)
12860 || MINI_WINDOW_P (w
)
12861 || !(used_current_matrix_p
12862 = try_window_reusing_current_matrix (w
)))
12864 IF_DEBUG (debug_method_add (w
, "1"));
12865 if (try_window (window
, startp
, 1) < 0)
12866 /* -1 means we need to scroll.
12867 0 means we need new matrices, but fonts_changed_p
12868 is set in that case, so we will detect it below. */
12869 goto try_to_scroll
;
12872 if (fonts_changed_p
)
12873 goto need_larger_matrices
;
12875 if (w
->cursor
.vpos
>= 0)
12877 if (!just_this_one_p
12878 || current_buffer
->clip_changed
12879 || BEG_UNCHANGED
< CHARPOS (startp
))
12880 /* Forget any recorded base line for line number display. */
12881 w
->base_line_number
= Qnil
;
12883 if (!cursor_row_fully_visible_p (w
, 1, 0))
12885 clear_glyph_matrix (w
->desired_matrix
);
12886 last_line_misfit
= 1;
12888 /* Drop through and scroll. */
12893 clear_glyph_matrix (w
->desired_matrix
);
12898 w
->last_modified
= make_number (0);
12899 w
->last_overlay_modified
= make_number (0);
12901 /* Redisplay the mode line. Select the buffer properly for that. */
12902 if (!update_mode_line
)
12904 update_mode_line
= 1;
12905 w
->update_mode_line
= Qt
;
12908 /* Try to scroll by specified few lines. */
12909 if ((scroll_conservatively
12911 || temp_scroll_step
12912 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12913 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12914 && !current_buffer
->clip_changed
12915 && CHARPOS (startp
) >= BEGV
12916 && CHARPOS (startp
) <= ZV
)
12918 /* The function returns -1 if new fonts were loaded, 1 if
12919 successful, 0 if not successful. */
12920 int rc
= try_scrolling (window
, just_this_one_p
,
12921 scroll_conservatively
,
12923 temp_scroll_step
, last_line_misfit
);
12926 case SCROLLING_SUCCESS
:
12929 case SCROLLING_NEED_LARGER_MATRICES
:
12930 goto need_larger_matrices
;
12932 case SCROLLING_FAILED
:
12940 /* Finally, just choose place to start which centers point */
12943 if (centering_position
< 0)
12944 centering_position
= window_box_height (w
) / 2;
12947 debug_method_add (w
, "recenter");
12950 /* w->vscroll = 0; */
12952 /* Forget any previously recorded base line for line number display. */
12953 if (!buffer_unchanged_p
)
12954 w
->base_line_number
= Qnil
;
12956 /* Move backward half the height of the window. */
12957 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12958 it
.current_y
= it
.last_visible_y
;
12959 move_it_vertically_backward (&it
, centering_position
);
12960 xassert (IT_CHARPOS (it
) >= BEGV
);
12962 /* The function move_it_vertically_backward may move over more
12963 than the specified y-distance. If it->w is small, e.g. a
12964 mini-buffer window, we may end up in front of the window's
12965 display area. Start displaying at the start of the line
12966 containing PT in this case. */
12967 if (it
.current_y
<= 0)
12969 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12970 move_it_vertically_backward (&it
, 0);
12972 /* I think this assert is bogus if buffer contains
12973 invisible text or images. KFS. */
12974 xassert (IT_CHARPOS (it
) <= PT
);
12979 it
.current_x
= it
.hpos
= 0;
12981 /* Set startp here explicitly in case that helps avoid an infinite loop
12982 in case the window-scroll-functions functions get errors. */
12983 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12985 /* Run scroll hooks. */
12986 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12988 /* Redisplay the window. */
12989 if (!current_matrix_up_to_date_p
12990 || windows_or_buffers_changed
12991 || cursor_type_changed
12992 /* Don't use try_window_reusing_current_matrix in this case
12993 because it can have changed the buffer. */
12994 || !NILP (Vwindow_scroll_functions
)
12995 || !just_this_one_p
12996 || MINI_WINDOW_P (w
)
12997 || !(used_current_matrix_p
12998 = try_window_reusing_current_matrix (w
)))
12999 try_window (window
, startp
, 0);
13001 /* If new fonts have been loaded (due to fontsets), give up. We
13002 have to start a new redisplay since we need to re-adjust glyph
13004 if (fonts_changed_p
)
13005 goto need_larger_matrices
;
13007 /* If cursor did not appear assume that the middle of the window is
13008 in the first line of the window. Do it again with the next line.
13009 (Imagine a window of height 100, displaying two lines of height
13010 60. Moving back 50 from it->last_visible_y will end in the first
13012 if (w
->cursor
.vpos
< 0)
13014 if (!NILP (w
->window_end_valid
)
13015 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13017 clear_glyph_matrix (w
->desired_matrix
);
13018 move_it_by_lines (&it
, 1, 0);
13019 try_window (window
, it
.current
.pos
, 0);
13021 else if (PT
< IT_CHARPOS (it
))
13023 clear_glyph_matrix (w
->desired_matrix
);
13024 move_it_by_lines (&it
, -1, 0);
13025 try_window (window
, it
.current
.pos
, 0);
13029 /* Not much we can do about it. */
13033 /* Consider the following case: Window starts at BEGV, there is
13034 invisible, intangible text at BEGV, so that display starts at
13035 some point START > BEGV. It can happen that we are called with
13036 PT somewhere between BEGV and START. Try to handle that case. */
13037 if (w
->cursor
.vpos
< 0)
13039 struct glyph_row
*row
= w
->current_matrix
->rows
;
13040 if (row
->mode_line_p
)
13042 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13045 if (!cursor_row_fully_visible_p (w
, 0, 0))
13047 /* If vscroll is enabled, disable it and try again. */
13051 clear_glyph_matrix (w
->desired_matrix
);
13055 /* If centering point failed to make the whole line visible,
13056 put point at the top instead. That has to make the whole line
13057 visible, if it can be done. */
13058 if (centering_position
== 0)
13061 clear_glyph_matrix (w
->desired_matrix
);
13062 centering_position
= 0;
13068 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13069 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13070 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13073 /* Display the mode line, if we must. */
13074 if ((update_mode_line
13075 /* If window not full width, must redo its mode line
13076 if (a) the window to its side is being redone and
13077 (b) we do a frame-based redisplay. This is a consequence
13078 of how inverted lines are drawn in frame-based redisplay. */
13079 || (!just_this_one_p
13080 && !FRAME_WINDOW_P (f
)
13081 && !WINDOW_FULL_WIDTH_P (w
))
13082 /* Line number to display. */
13083 || INTEGERP (w
->base_line_pos
)
13084 /* Column number is displayed and different from the one displayed. */
13085 || (!NILP (w
->column_number_displayed
)
13086 && (XFASTINT (w
->column_number_displayed
)
13087 != (int) current_column ()))) /* iftc */
13088 /* This means that the window has a mode line. */
13089 && (WINDOW_WANTS_MODELINE_P (w
)
13090 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13092 display_mode_lines (w
);
13094 /* If mode line height has changed, arrange for a thorough
13095 immediate redisplay using the correct mode line height. */
13096 if (WINDOW_WANTS_MODELINE_P (w
)
13097 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13099 fonts_changed_p
= 1;
13100 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13101 = DESIRED_MODE_LINE_HEIGHT (w
);
13104 /* If top line height has changed, arrange for a thorough
13105 immediate redisplay using the correct mode line height. */
13106 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13107 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13109 fonts_changed_p
= 1;
13110 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13111 = DESIRED_HEADER_LINE_HEIGHT (w
);
13114 if (fonts_changed_p
)
13115 goto need_larger_matrices
;
13118 if (!line_number_displayed
13119 && !BUFFERP (w
->base_line_pos
))
13121 w
->base_line_pos
= Qnil
;
13122 w
->base_line_number
= Qnil
;
13127 /* When we reach a frame's selected window, redo the frame's menu bar. */
13128 if (update_mode_line
13129 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13131 int redisplay_menu_p
= 0;
13132 int redisplay_tool_bar_p
= 0;
13134 if (FRAME_WINDOW_P (f
))
13136 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13137 || defined (USE_GTK)
13138 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13140 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13144 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13146 if (redisplay_menu_p
)
13147 display_menu_bar (w
);
13149 #ifdef HAVE_WINDOW_SYSTEM
13151 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13153 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13154 && (FRAME_TOOL_BAR_LINES (f
) > 0
13155 || auto_resize_tool_bars_p
);
13159 if (redisplay_tool_bar_p
)
13160 redisplay_tool_bar (f
);
13164 #ifdef HAVE_WINDOW_SYSTEM
13165 if (FRAME_WINDOW_P (f
)
13166 && update_window_fringes (w
, (just_this_one_p
13167 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13168 || w
->pseudo_window_p
)))
13172 if (draw_window_fringes (w
, 1))
13173 x_draw_vertical_border (w
);
13177 #endif /* HAVE_WINDOW_SYSTEM */
13179 /* We go to this label, with fonts_changed_p nonzero,
13180 if it is necessary to try again using larger glyph matrices.
13181 We have to redeem the scroll bar even in this case,
13182 because the loop in redisplay_internal expects that. */
13183 need_larger_matrices
:
13185 finish_scroll_bars
:
13187 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13189 /* Set the thumb's position and size. */
13190 set_vertical_scroll_bar (w
);
13192 /* Note that we actually used the scroll bar attached to this
13193 window, so it shouldn't be deleted at the end of redisplay. */
13194 redeem_scroll_bar_hook (w
);
13197 /* Restore current_buffer and value of point in it. */
13198 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13199 set_buffer_internal_1 (old
);
13200 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13202 unbind_to (count
, Qnil
);
13206 /* Build the complete desired matrix of WINDOW with a window start
13207 buffer position POS.
13209 Value is 1 if successful. It is zero if fonts were loaded during
13210 redisplay which makes re-adjusting glyph matrices necessary, and -1
13211 if point would appear in the scroll margins.
13212 (We check that only if CHECK_MARGINS is nonzero. */
13215 try_window (window
, pos
, check_margins
)
13216 Lisp_Object window
;
13217 struct text_pos pos
;
13220 struct window
*w
= XWINDOW (window
);
13222 struct glyph_row
*last_text_row
= NULL
;
13224 /* Make POS the new window start. */
13225 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13227 /* Mark cursor position as unknown. No overlay arrow seen. */
13228 w
->cursor
.vpos
= -1;
13229 overlay_arrow_seen
= 0;
13231 /* Initialize iterator and info to start at POS. */
13232 start_display (&it
, w
, pos
);
13234 /* Display all lines of W. */
13235 while (it
.current_y
< it
.last_visible_y
)
13237 if (display_line (&it
))
13238 last_text_row
= it
.glyph_row
- 1;
13239 if (fonts_changed_p
)
13243 /* Don't let the cursor end in the scroll margins. */
13245 && !MINI_WINDOW_P (w
))
13247 int this_scroll_margin
;
13249 this_scroll_margin
= max (0, scroll_margin
);
13250 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13251 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13253 if ((w
->cursor
.y
< this_scroll_margin
13254 && CHARPOS (pos
) > BEGV
13255 && IT_CHARPOS (it
) < ZV
)
13256 /* rms: considering make_cursor_line_fully_visible_p here
13257 seems to give wrong results. We don't want to recenter
13258 when the last line is partly visible, we want to allow
13259 that case to be handled in the usual way. */
13260 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13262 w
->cursor
.vpos
= -1;
13263 clear_glyph_matrix (w
->desired_matrix
);
13268 /* If bottom moved off end of frame, change mode line percentage. */
13269 if (XFASTINT (w
->window_end_pos
) <= 0
13270 && Z
!= IT_CHARPOS (it
))
13271 w
->update_mode_line
= Qt
;
13273 /* Set window_end_pos to the offset of the last character displayed
13274 on the window from the end of current_buffer. Set
13275 window_end_vpos to its row number. */
13278 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13279 w
->window_end_bytepos
13280 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13282 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13284 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13285 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13286 ->displays_text_p
);
13290 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13291 w
->window_end_pos
= make_number (Z
- ZV
);
13292 w
->window_end_vpos
= make_number (0);
13295 /* But that is not valid info until redisplay finishes. */
13296 w
->window_end_valid
= Qnil
;
13302 /************************************************************************
13303 Window redisplay reusing current matrix when buffer has not changed
13304 ************************************************************************/
13306 /* Try redisplay of window W showing an unchanged buffer with a
13307 different window start than the last time it was displayed by
13308 reusing its current matrix. Value is non-zero if successful.
13309 W->start is the new window start. */
13312 try_window_reusing_current_matrix (w
)
13315 struct frame
*f
= XFRAME (w
->frame
);
13316 struct glyph_row
*row
, *bottom_row
;
13319 struct text_pos start
, new_start
;
13320 int nrows_scrolled
, i
;
13321 struct glyph_row
*last_text_row
;
13322 struct glyph_row
*last_reused_text_row
;
13323 struct glyph_row
*start_row
;
13324 int start_vpos
, min_y
, max_y
;
13327 if (inhibit_try_window_reusing
)
13331 if (/* This function doesn't handle terminal frames. */
13332 !FRAME_WINDOW_P (f
)
13333 /* Don't try to reuse the display if windows have been split
13335 || windows_or_buffers_changed
13336 || cursor_type_changed
)
13339 /* Can't do this if region may have changed. */
13340 if ((!NILP (Vtransient_mark_mode
)
13341 && !NILP (current_buffer
->mark_active
))
13342 || !NILP (w
->region_showing
)
13343 || !NILP (Vshow_trailing_whitespace
))
13346 /* If top-line visibility has changed, give up. */
13347 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13348 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13351 /* Give up if old or new display is scrolled vertically. We could
13352 make this function handle this, but right now it doesn't. */
13353 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13354 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13357 /* The variable new_start now holds the new window start. The old
13358 start `start' can be determined from the current matrix. */
13359 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13360 start
= start_row
->start
.pos
;
13361 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13363 /* Clear the desired matrix for the display below. */
13364 clear_glyph_matrix (w
->desired_matrix
);
13366 if (CHARPOS (new_start
) <= CHARPOS (start
))
13370 /* Don't use this method if the display starts with an ellipsis
13371 displayed for invisible text. It's not easy to handle that case
13372 below, and it's certainly not worth the effort since this is
13373 not a frequent case. */
13374 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13377 IF_DEBUG (debug_method_add (w
, "twu1"));
13379 /* Display up to a row that can be reused. The variable
13380 last_text_row is set to the last row displayed that displays
13381 text. Note that it.vpos == 0 if or if not there is a
13382 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13383 start_display (&it
, w
, new_start
);
13384 first_row_y
= it
.current_y
;
13385 w
->cursor
.vpos
= -1;
13386 last_text_row
= last_reused_text_row
= NULL
;
13388 while (it
.current_y
< it
.last_visible_y
13389 && !fonts_changed_p
)
13391 /* If we have reached into the characters in the START row,
13392 that means the line boundaries have changed. So we
13393 can't start copying with the row START. Maybe it will
13394 work to start copying with the following row. */
13395 while (IT_CHARPOS (it
) > CHARPOS (start
))
13397 /* Advance to the next row as the "start". */
13399 start
= start_row
->start
.pos
;
13400 /* If there are no more rows to try, or just one, give up. */
13401 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13402 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13403 || CHARPOS (start
) == ZV
)
13405 clear_glyph_matrix (w
->desired_matrix
);
13409 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13411 /* If we have reached alignment,
13412 we can copy the rest of the rows. */
13413 if (IT_CHARPOS (it
) == CHARPOS (start
))
13416 if (display_line (&it
))
13417 last_text_row
= it
.glyph_row
- 1;
13420 /* A value of current_y < last_visible_y means that we stopped
13421 at the previous window start, which in turn means that we
13422 have at least one reusable row. */
13423 if (it
.current_y
< it
.last_visible_y
)
13425 /* IT.vpos always starts from 0; it counts text lines. */
13426 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13428 /* Find PT if not already found in the lines displayed. */
13429 if (w
->cursor
.vpos
< 0)
13431 int dy
= it
.current_y
- start_row
->y
;
13433 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13434 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13436 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13437 dy
, nrows_scrolled
);
13440 clear_glyph_matrix (w
->desired_matrix
);
13445 /* Scroll the display. Do it before the current matrix is
13446 changed. The problem here is that update has not yet
13447 run, i.e. part of the current matrix is not up to date.
13448 scroll_run_hook will clear the cursor, and use the
13449 current matrix to get the height of the row the cursor is
13451 run
.current_y
= start_row
->y
;
13452 run
.desired_y
= it
.current_y
;
13453 run
.height
= it
.last_visible_y
- it
.current_y
;
13455 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13458 rif
->update_window_begin_hook (w
);
13459 rif
->clear_window_mouse_face (w
);
13460 rif
->scroll_run_hook (w
, &run
);
13461 rif
->update_window_end_hook (w
, 0, 0);
13465 /* Shift current matrix down by nrows_scrolled lines. */
13466 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13467 rotate_matrix (w
->current_matrix
,
13469 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13472 /* Disable lines that must be updated. */
13473 for (i
= 0; i
< it
.vpos
; ++i
)
13474 (start_row
+ i
)->enabled_p
= 0;
13476 /* Re-compute Y positions. */
13477 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13478 max_y
= it
.last_visible_y
;
13479 for (row
= start_row
+ nrows_scrolled
;
13483 row
->y
= it
.current_y
;
13484 row
->visible_height
= row
->height
;
13486 if (row
->y
< min_y
)
13487 row
->visible_height
-= min_y
- row
->y
;
13488 if (row
->y
+ row
->height
> max_y
)
13489 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13490 row
->redraw_fringe_bitmaps_p
= 1;
13492 it
.current_y
+= row
->height
;
13494 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13495 last_reused_text_row
= row
;
13496 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13500 /* Disable lines in the current matrix which are now
13501 below the window. */
13502 for (++row
; row
< bottom_row
; ++row
)
13503 row
->enabled_p
= row
->mode_line_p
= 0;
13506 /* Update window_end_pos etc.; last_reused_text_row is the last
13507 reused row from the current matrix containing text, if any.
13508 The value of last_text_row is the last displayed line
13509 containing text. */
13510 if (last_reused_text_row
)
13512 w
->window_end_bytepos
13513 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13515 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13517 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13518 w
->current_matrix
));
13520 else if (last_text_row
)
13522 w
->window_end_bytepos
13523 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13525 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13527 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13531 /* This window must be completely empty. */
13532 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13533 w
->window_end_pos
= make_number (Z
- ZV
);
13534 w
->window_end_vpos
= make_number (0);
13536 w
->window_end_valid
= Qnil
;
13538 /* Update hint: don't try scrolling again in update_window. */
13539 w
->desired_matrix
->no_scrolling_p
= 1;
13542 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13546 else if (CHARPOS (new_start
) > CHARPOS (start
))
13548 struct glyph_row
*pt_row
, *row
;
13549 struct glyph_row
*first_reusable_row
;
13550 struct glyph_row
*first_row_to_display
;
13552 int yb
= window_text_bottom_y (w
);
13554 /* Find the row starting at new_start, if there is one. Don't
13555 reuse a partially visible line at the end. */
13556 first_reusable_row
= start_row
;
13557 while (first_reusable_row
->enabled_p
13558 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13559 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13560 < CHARPOS (new_start
)))
13561 ++first_reusable_row
;
13563 /* Give up if there is no row to reuse. */
13564 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13565 || !first_reusable_row
->enabled_p
13566 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13567 != CHARPOS (new_start
)))
13570 /* We can reuse fully visible rows beginning with
13571 first_reusable_row to the end of the window. Set
13572 first_row_to_display to the first row that cannot be reused.
13573 Set pt_row to the row containing point, if there is any. */
13575 for (first_row_to_display
= first_reusable_row
;
13576 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13577 ++first_row_to_display
)
13579 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13580 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13581 pt_row
= first_row_to_display
;
13584 /* Start displaying at the start of first_row_to_display. */
13585 xassert (first_row_to_display
->y
< yb
);
13586 init_to_row_start (&it
, w
, first_row_to_display
);
13588 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13590 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13592 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13593 + WINDOW_HEADER_LINE_HEIGHT (w
));
13595 /* Display lines beginning with first_row_to_display in the
13596 desired matrix. Set last_text_row to the last row displayed
13597 that displays text. */
13598 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13599 if (pt_row
== NULL
)
13600 w
->cursor
.vpos
= -1;
13601 last_text_row
= NULL
;
13602 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13603 if (display_line (&it
))
13604 last_text_row
= it
.glyph_row
- 1;
13606 /* Give up If point isn't in a row displayed or reused. */
13607 if (w
->cursor
.vpos
< 0)
13609 clear_glyph_matrix (w
->desired_matrix
);
13613 /* If point is in a reused row, adjust y and vpos of the cursor
13617 w
->cursor
.vpos
-= nrows_scrolled
;
13618 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13621 /* Scroll the display. */
13622 run
.current_y
= first_reusable_row
->y
;
13623 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13624 run
.height
= it
.last_visible_y
- run
.current_y
;
13625 dy
= run
.current_y
- run
.desired_y
;
13630 rif
->update_window_begin_hook (w
);
13631 rif
->clear_window_mouse_face (w
);
13632 rif
->scroll_run_hook (w
, &run
);
13633 rif
->update_window_end_hook (w
, 0, 0);
13637 /* Adjust Y positions of reused rows. */
13638 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13639 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13640 max_y
= it
.last_visible_y
;
13641 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13644 row
->visible_height
= row
->height
;
13645 if (row
->y
< min_y
)
13646 row
->visible_height
-= min_y
- row
->y
;
13647 if (row
->y
+ row
->height
> max_y
)
13648 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13649 row
->redraw_fringe_bitmaps_p
= 1;
13652 /* Scroll the current matrix. */
13653 xassert (nrows_scrolled
> 0);
13654 rotate_matrix (w
->current_matrix
,
13656 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13659 /* Disable rows not reused. */
13660 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13661 row
->enabled_p
= 0;
13663 /* Point may have moved to a different line, so we cannot assume that
13664 the previous cursor position is valid; locate the correct row. */
13667 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13668 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13672 w
->cursor
.y
= row
->y
;
13674 if (row
< bottom_row
)
13676 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13677 while (glyph
->charpos
< PT
)
13680 w
->cursor
.x
+= glyph
->pixel_width
;
13686 /* Adjust window end. A null value of last_text_row means that
13687 the window end is in reused rows which in turn means that
13688 only its vpos can have changed. */
13691 w
->window_end_bytepos
13692 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13694 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13696 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13701 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13704 w
->window_end_valid
= Qnil
;
13705 w
->desired_matrix
->no_scrolling_p
= 1;
13708 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13718 /************************************************************************
13719 Window redisplay reusing current matrix when buffer has changed
13720 ************************************************************************/
13722 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13723 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13725 static struct glyph_row
*
13726 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13727 struct glyph_row
*));
13730 /* Return the last row in MATRIX displaying text. If row START is
13731 non-null, start searching with that row. IT gives the dimensions
13732 of the display. Value is null if matrix is empty; otherwise it is
13733 a pointer to the row found. */
13735 static struct glyph_row
*
13736 find_last_row_displaying_text (matrix
, it
, start
)
13737 struct glyph_matrix
*matrix
;
13739 struct glyph_row
*start
;
13741 struct glyph_row
*row
, *row_found
;
13743 /* Set row_found to the last row in IT->w's current matrix
13744 displaying text. The loop looks funny but think of partially
13747 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13748 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13750 xassert (row
->enabled_p
);
13752 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13761 /* Return the last row in the current matrix of W that is not affected
13762 by changes at the start of current_buffer that occurred since W's
13763 current matrix was built. Value is null if no such row exists.
13765 BEG_UNCHANGED us the number of characters unchanged at the start of
13766 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13767 first changed character in current_buffer. Characters at positions <
13768 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13769 when the current matrix was built. */
13771 static struct glyph_row
*
13772 find_last_unchanged_at_beg_row (w
)
13775 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13776 struct glyph_row
*row
;
13777 struct glyph_row
*row_found
= NULL
;
13778 int yb
= window_text_bottom_y (w
);
13780 /* Find the last row displaying unchanged text. */
13781 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13782 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13783 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13785 if (/* If row ends before first_changed_pos, it is unchanged,
13786 except in some case. */
13787 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13788 /* When row ends in ZV and we write at ZV it is not
13790 && !row
->ends_at_zv_p
13791 /* When first_changed_pos is the end of a continued line,
13792 row is not unchanged because it may be no longer
13794 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13795 && (row
->continued_p
13796 || row
->exact_window_width_line_p
)))
13799 /* Stop if last visible row. */
13800 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13810 /* Find the first glyph row in the current matrix of W that is not
13811 affected by changes at the end of current_buffer since the
13812 time W's current matrix was built.
13814 Return in *DELTA the number of chars by which buffer positions in
13815 unchanged text at the end of current_buffer must be adjusted.
13817 Return in *DELTA_BYTES the corresponding number of bytes.
13819 Value is null if no such row exists, i.e. all rows are affected by
13822 static struct glyph_row
*
13823 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13825 int *delta
, *delta_bytes
;
13827 struct glyph_row
*row
;
13828 struct glyph_row
*row_found
= NULL
;
13830 *delta
= *delta_bytes
= 0;
13832 /* Display must not have been paused, otherwise the current matrix
13833 is not up to date. */
13834 if (NILP (w
->window_end_valid
))
13837 /* A value of window_end_pos >= END_UNCHANGED means that the window
13838 end is in the range of changed text. If so, there is no
13839 unchanged row at the end of W's current matrix. */
13840 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13843 /* Set row to the last row in W's current matrix displaying text. */
13844 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13846 /* If matrix is entirely empty, no unchanged row exists. */
13847 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13849 /* The value of row is the last glyph row in the matrix having a
13850 meaningful buffer position in it. The end position of row
13851 corresponds to window_end_pos. This allows us to translate
13852 buffer positions in the current matrix to current buffer
13853 positions for characters not in changed text. */
13854 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13855 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13856 int last_unchanged_pos
, last_unchanged_pos_old
;
13857 struct glyph_row
*first_text_row
13858 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13860 *delta
= Z
- Z_old
;
13861 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13863 /* Set last_unchanged_pos to the buffer position of the last
13864 character in the buffer that has not been changed. Z is the
13865 index + 1 of the last character in current_buffer, i.e. by
13866 subtracting END_UNCHANGED we get the index of the last
13867 unchanged character, and we have to add BEG to get its buffer
13869 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13870 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13872 /* Search backward from ROW for a row displaying a line that
13873 starts at a minimum position >= last_unchanged_pos_old. */
13874 for (; row
> first_text_row
; --row
)
13876 /* This used to abort, but it can happen.
13877 It is ok to just stop the search instead here. KFS. */
13878 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13881 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13886 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13893 /* Make sure that glyph rows in the current matrix of window W
13894 reference the same glyph memory as corresponding rows in the
13895 frame's frame matrix. This function is called after scrolling W's
13896 current matrix on a terminal frame in try_window_id and
13897 try_window_reusing_current_matrix. */
13900 sync_frame_with_window_matrix_rows (w
)
13903 struct frame
*f
= XFRAME (w
->frame
);
13904 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13906 /* Preconditions: W must be a leaf window and full-width. Its frame
13907 must have a frame matrix. */
13908 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13909 xassert (WINDOW_FULL_WIDTH_P (w
));
13910 xassert (!FRAME_WINDOW_P (f
));
13912 /* If W is a full-width window, glyph pointers in W's current matrix
13913 have, by definition, to be the same as glyph pointers in the
13914 corresponding frame matrix. Note that frame matrices have no
13915 marginal areas (see build_frame_matrix). */
13916 window_row
= w
->current_matrix
->rows
;
13917 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13918 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13919 while (window_row
< window_row_end
)
13921 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13922 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13924 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13925 frame_row
->glyphs
[TEXT_AREA
] = start
;
13926 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13927 frame_row
->glyphs
[LAST_AREA
] = end
;
13929 /* Disable frame rows whose corresponding window rows have
13930 been disabled in try_window_id. */
13931 if (!window_row
->enabled_p
)
13932 frame_row
->enabled_p
= 0;
13934 ++window_row
, ++frame_row
;
13939 /* Find the glyph row in window W containing CHARPOS. Consider all
13940 rows between START and END (not inclusive). END null means search
13941 all rows to the end of the display area of W. Value is the row
13942 containing CHARPOS or null. */
13945 row_containing_pos (w
, charpos
, start
, end
, dy
)
13948 struct glyph_row
*start
, *end
;
13951 struct glyph_row
*row
= start
;
13954 /* If we happen to start on a header-line, skip that. */
13955 if (row
->mode_line_p
)
13958 if ((end
&& row
>= end
) || !row
->enabled_p
)
13961 last_y
= window_text_bottom_y (w
) - dy
;
13965 /* Give up if we have gone too far. */
13966 if (end
&& row
>= end
)
13968 /* This formerly returned if they were equal.
13969 I think that both quantities are of a "last plus one" type;
13970 if so, when they are equal, the row is within the screen. -- rms. */
13971 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13974 /* If it is in this row, return this row. */
13975 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13976 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13977 /* The end position of a row equals the start
13978 position of the next row. If CHARPOS is there, we
13979 would rather display it in the next line, except
13980 when this line ends in ZV. */
13981 && !row
->ends_at_zv_p
13982 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13983 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13990 /* Try to redisplay window W by reusing its existing display. W's
13991 current matrix must be up to date when this function is called,
13992 i.e. window_end_valid must not be nil.
13996 1 if display has been updated
13997 0 if otherwise unsuccessful
13998 -1 if redisplay with same window start is known not to succeed
14000 The following steps are performed:
14002 1. Find the last row in the current matrix of W that is not
14003 affected by changes at the start of current_buffer. If no such row
14006 2. Find the first row in W's current matrix that is not affected by
14007 changes at the end of current_buffer. Maybe there is no such row.
14009 3. Display lines beginning with the row + 1 found in step 1 to the
14010 row found in step 2 or, if step 2 didn't find a row, to the end of
14013 4. If cursor is not known to appear on the window, give up.
14015 5. If display stopped at the row found in step 2, scroll the
14016 display and current matrix as needed.
14018 6. Maybe display some lines at the end of W, if we must. This can
14019 happen under various circumstances, like a partially visible line
14020 becoming fully visible, or because newly displayed lines are displayed
14021 in smaller font sizes.
14023 7. Update W's window end information. */
14029 struct frame
*f
= XFRAME (w
->frame
);
14030 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14031 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14032 struct glyph_row
*last_unchanged_at_beg_row
;
14033 struct glyph_row
*first_unchanged_at_end_row
;
14034 struct glyph_row
*row
;
14035 struct glyph_row
*bottom_row
;
14038 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14039 struct text_pos start_pos
;
14041 int first_unchanged_at_end_vpos
= 0;
14042 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14043 struct text_pos start
;
14044 int first_changed_charpos
, last_changed_charpos
;
14047 if (inhibit_try_window_id
)
14051 /* This is handy for debugging. */
14053 #define GIVE_UP(X) \
14055 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14059 #define GIVE_UP(X) return 0
14062 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14064 /* Don't use this for mini-windows because these can show
14065 messages and mini-buffers, and we don't handle that here. */
14066 if (MINI_WINDOW_P (w
))
14069 /* This flag is used to prevent redisplay optimizations. */
14070 if (windows_or_buffers_changed
|| cursor_type_changed
)
14073 /* Verify that narrowing has not changed.
14074 Also verify that we were not told to prevent redisplay optimizations.
14075 It would be nice to further
14076 reduce the number of cases where this prevents try_window_id. */
14077 if (current_buffer
->clip_changed
14078 || current_buffer
->prevent_redisplay_optimizations_p
)
14081 /* Window must either use window-based redisplay or be full width. */
14082 if (!FRAME_WINDOW_P (f
)
14083 && (!line_ins_del_ok
14084 || !WINDOW_FULL_WIDTH_P (w
)))
14087 /* Give up if point is not known NOT to appear in W. */
14088 if (PT
< CHARPOS (start
))
14091 /* Another way to prevent redisplay optimizations. */
14092 if (XFASTINT (w
->last_modified
) == 0)
14095 /* Verify that window is not hscrolled. */
14096 if (XFASTINT (w
->hscroll
) != 0)
14099 /* Verify that display wasn't paused. */
14100 if (NILP (w
->window_end_valid
))
14103 /* Can't use this if highlighting a region because a cursor movement
14104 will do more than just set the cursor. */
14105 if (!NILP (Vtransient_mark_mode
)
14106 && !NILP (current_buffer
->mark_active
))
14109 /* Likewise if highlighting trailing whitespace. */
14110 if (!NILP (Vshow_trailing_whitespace
))
14113 /* Likewise if showing a region. */
14114 if (!NILP (w
->region_showing
))
14117 /* Can use this if overlay arrow position and or string have changed. */
14118 if (overlay_arrows_changed_p ())
14122 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14123 only if buffer has really changed. The reason is that the gap is
14124 initially at Z for freshly visited files. The code below would
14125 set end_unchanged to 0 in that case. */
14126 if (MODIFF
> SAVE_MODIFF
14127 /* This seems to happen sometimes after saving a buffer. */
14128 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14130 if (GPT
- BEG
< BEG_UNCHANGED
)
14131 BEG_UNCHANGED
= GPT
- BEG
;
14132 if (Z
- GPT
< END_UNCHANGED
)
14133 END_UNCHANGED
= Z
- GPT
;
14136 /* The position of the first and last character that has been changed. */
14137 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14138 last_changed_charpos
= Z
- END_UNCHANGED
;
14140 /* If window starts after a line end, and the last change is in
14141 front of that newline, then changes don't affect the display.
14142 This case happens with stealth-fontification. Note that although
14143 the display is unchanged, glyph positions in the matrix have to
14144 be adjusted, of course. */
14145 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14146 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14147 && ((last_changed_charpos
< CHARPOS (start
)
14148 && CHARPOS (start
) == BEGV
)
14149 || (last_changed_charpos
< CHARPOS (start
) - 1
14150 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14152 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14153 struct glyph_row
*r0
;
14155 /* Compute how many chars/bytes have been added to or removed
14156 from the buffer. */
14157 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14158 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14160 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14162 /* Give up if PT is not in the window. Note that it already has
14163 been checked at the start of try_window_id that PT is not in
14164 front of the window start. */
14165 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14168 /* If window start is unchanged, we can reuse the whole matrix
14169 as is, after adjusting glyph positions. No need to compute
14170 the window end again, since its offset from Z hasn't changed. */
14171 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14172 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14173 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14174 /* PT must not be in a partially visible line. */
14175 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14176 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14178 /* Adjust positions in the glyph matrix. */
14179 if (delta
|| delta_bytes
)
14181 struct glyph_row
*r1
14182 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14183 increment_matrix_positions (w
->current_matrix
,
14184 MATRIX_ROW_VPOS (r0
, current_matrix
),
14185 MATRIX_ROW_VPOS (r1
, current_matrix
),
14186 delta
, delta_bytes
);
14189 /* Set the cursor. */
14190 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14192 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14199 /* Handle the case that changes are all below what is displayed in
14200 the window, and that PT is in the window. This shortcut cannot
14201 be taken if ZV is visible in the window, and text has been added
14202 there that is visible in the window. */
14203 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14204 /* ZV is not visible in the window, or there are no
14205 changes at ZV, actually. */
14206 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14207 || first_changed_charpos
== last_changed_charpos
))
14209 struct glyph_row
*r0
;
14211 /* Give up if PT is not in the window. Note that it already has
14212 been checked at the start of try_window_id that PT is not in
14213 front of the window start. */
14214 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14217 /* If window start is unchanged, we can reuse the whole matrix
14218 as is, without changing glyph positions since no text has
14219 been added/removed in front of the window end. */
14220 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14221 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14222 /* PT must not be in a partially visible line. */
14223 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14224 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14226 /* We have to compute the window end anew since text
14227 can have been added/removed after it. */
14229 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14230 w
->window_end_bytepos
14231 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14233 /* Set the cursor. */
14234 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14236 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14243 /* Give up if window start is in the changed area.
14245 The condition used to read
14247 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14249 but why that was tested escapes me at the moment. */
14250 if (CHARPOS (start
) >= first_changed_charpos
14251 && CHARPOS (start
) <= last_changed_charpos
)
14254 /* Check that window start agrees with the start of the first glyph
14255 row in its current matrix. Check this after we know the window
14256 start is not in changed text, otherwise positions would not be
14258 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14259 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14262 /* Give up if the window ends in strings. Overlay strings
14263 at the end are difficult to handle, so don't try. */
14264 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14265 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14268 /* Compute the position at which we have to start displaying new
14269 lines. Some of the lines at the top of the window might be
14270 reusable because they are not displaying changed text. Find the
14271 last row in W's current matrix not affected by changes at the
14272 start of current_buffer. Value is null if changes start in the
14273 first line of window. */
14274 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14275 if (last_unchanged_at_beg_row
)
14277 /* Avoid starting to display in the moddle of a character, a TAB
14278 for instance. This is easier than to set up the iterator
14279 exactly, and it's not a frequent case, so the additional
14280 effort wouldn't really pay off. */
14281 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14282 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14283 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14284 --last_unchanged_at_beg_row
;
14286 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14289 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14291 start_pos
= it
.current
.pos
;
14293 /* Start displaying new lines in the desired matrix at the same
14294 vpos we would use in the current matrix, i.e. below
14295 last_unchanged_at_beg_row. */
14296 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14298 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14299 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14301 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14305 /* There are no reusable lines at the start of the window.
14306 Start displaying in the first text line. */
14307 start_display (&it
, w
, start
);
14308 it
.vpos
= it
.first_vpos
;
14309 start_pos
= it
.current
.pos
;
14312 /* Find the first row that is not affected by changes at the end of
14313 the buffer. Value will be null if there is no unchanged row, in
14314 which case we must redisplay to the end of the window. delta
14315 will be set to the value by which buffer positions beginning with
14316 first_unchanged_at_end_row have to be adjusted due to text
14318 first_unchanged_at_end_row
14319 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14320 IF_DEBUG (debug_delta
= delta
);
14321 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14323 /* Set stop_pos to the buffer position up to which we will have to
14324 display new lines. If first_unchanged_at_end_row != NULL, this
14325 is the buffer position of the start of the line displayed in that
14326 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14327 that we don't stop at a buffer position. */
14329 if (first_unchanged_at_end_row
)
14331 xassert (last_unchanged_at_beg_row
== NULL
14332 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14334 /* If this is a continuation line, move forward to the next one
14335 that isn't. Changes in lines above affect this line.
14336 Caution: this may move first_unchanged_at_end_row to a row
14337 not displaying text. */
14338 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14339 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14340 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14341 < it
.last_visible_y
))
14342 ++first_unchanged_at_end_row
;
14344 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14345 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14346 >= it
.last_visible_y
))
14347 first_unchanged_at_end_row
= NULL
;
14350 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14352 first_unchanged_at_end_vpos
14353 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14354 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14357 else if (last_unchanged_at_beg_row
== NULL
)
14363 /* Either there is no unchanged row at the end, or the one we have
14364 now displays text. This is a necessary condition for the window
14365 end pos calculation at the end of this function. */
14366 xassert (first_unchanged_at_end_row
== NULL
14367 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14369 debug_last_unchanged_at_beg_vpos
14370 = (last_unchanged_at_beg_row
14371 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14373 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14375 #endif /* GLYPH_DEBUG != 0 */
14378 /* Display new lines. Set last_text_row to the last new line
14379 displayed which has text on it, i.e. might end up as being the
14380 line where the window_end_vpos is. */
14381 w
->cursor
.vpos
= -1;
14382 last_text_row
= NULL
;
14383 overlay_arrow_seen
= 0;
14384 while (it
.current_y
< it
.last_visible_y
14385 && !fonts_changed_p
14386 && (first_unchanged_at_end_row
== NULL
14387 || IT_CHARPOS (it
) < stop_pos
))
14389 if (display_line (&it
))
14390 last_text_row
= it
.glyph_row
- 1;
14393 if (fonts_changed_p
)
14397 /* Compute differences in buffer positions, y-positions etc. for
14398 lines reused at the bottom of the window. Compute what we can
14400 if (first_unchanged_at_end_row
14401 /* No lines reused because we displayed everything up to the
14402 bottom of the window. */
14403 && it
.current_y
< it
.last_visible_y
)
14406 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14408 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14409 run
.current_y
= first_unchanged_at_end_row
->y
;
14410 run
.desired_y
= run
.current_y
+ dy
;
14411 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14415 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14416 first_unchanged_at_end_row
= NULL
;
14418 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14421 /* Find the cursor if not already found. We have to decide whether
14422 PT will appear on this window (it sometimes doesn't, but this is
14423 not a very frequent case.) This decision has to be made before
14424 the current matrix is altered. A value of cursor.vpos < 0 means
14425 that PT is either in one of the lines beginning at
14426 first_unchanged_at_end_row or below the window. Don't care for
14427 lines that might be displayed later at the window end; as
14428 mentioned, this is not a frequent case. */
14429 if (w
->cursor
.vpos
< 0)
14431 /* Cursor in unchanged rows at the top? */
14432 if (PT
< CHARPOS (start_pos
)
14433 && last_unchanged_at_beg_row
)
14435 row
= row_containing_pos (w
, PT
,
14436 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14437 last_unchanged_at_beg_row
+ 1, 0);
14439 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14442 /* Start from first_unchanged_at_end_row looking for PT. */
14443 else if (first_unchanged_at_end_row
)
14445 row
= row_containing_pos (w
, PT
- delta
,
14446 first_unchanged_at_end_row
, NULL
, 0);
14448 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14449 delta_bytes
, dy
, dvpos
);
14452 /* Give up if cursor was not found. */
14453 if (w
->cursor
.vpos
< 0)
14455 clear_glyph_matrix (w
->desired_matrix
);
14460 /* Don't let the cursor end in the scroll margins. */
14462 int this_scroll_margin
, cursor_height
;
14464 this_scroll_margin
= max (0, scroll_margin
);
14465 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14466 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14467 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14469 if ((w
->cursor
.y
< this_scroll_margin
14470 && CHARPOS (start
) > BEGV
)
14471 /* Old redisplay didn't take scroll margin into account at the bottom,
14472 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14473 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14474 ? cursor_height
+ this_scroll_margin
14475 : 1)) > it
.last_visible_y
)
14477 w
->cursor
.vpos
= -1;
14478 clear_glyph_matrix (w
->desired_matrix
);
14483 /* Scroll the display. Do it before changing the current matrix so
14484 that xterm.c doesn't get confused about where the cursor glyph is
14486 if (dy
&& run
.height
)
14490 if (FRAME_WINDOW_P (f
))
14492 rif
->update_window_begin_hook (w
);
14493 rif
->clear_window_mouse_face (w
);
14494 rif
->scroll_run_hook (w
, &run
);
14495 rif
->update_window_end_hook (w
, 0, 0);
14499 /* Terminal frame. In this case, dvpos gives the number of
14500 lines to scroll by; dvpos < 0 means scroll up. */
14501 int first_unchanged_at_end_vpos
14502 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14503 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14504 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14505 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14506 + window_internal_height (w
));
14508 /* Perform the operation on the screen. */
14511 /* Scroll last_unchanged_at_beg_row to the end of the
14512 window down dvpos lines. */
14513 set_terminal_window (end
);
14515 /* On dumb terminals delete dvpos lines at the end
14516 before inserting dvpos empty lines. */
14517 if (!scroll_region_ok
)
14518 ins_del_lines (end
- dvpos
, -dvpos
);
14520 /* Insert dvpos empty lines in front of
14521 last_unchanged_at_beg_row. */
14522 ins_del_lines (from
, dvpos
);
14524 else if (dvpos
< 0)
14526 /* Scroll up last_unchanged_at_beg_vpos to the end of
14527 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14528 set_terminal_window (end
);
14530 /* Delete dvpos lines in front of
14531 last_unchanged_at_beg_vpos. ins_del_lines will set
14532 the cursor to the given vpos and emit |dvpos| delete
14534 ins_del_lines (from
+ dvpos
, dvpos
);
14536 /* On a dumb terminal insert dvpos empty lines at the
14538 if (!scroll_region_ok
)
14539 ins_del_lines (end
+ dvpos
, -dvpos
);
14542 set_terminal_window (0);
14548 /* Shift reused rows of the current matrix to the right position.
14549 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14551 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14552 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14555 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14556 bottom_vpos
, dvpos
);
14557 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14560 else if (dvpos
> 0)
14562 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14563 bottom_vpos
, dvpos
);
14564 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14565 first_unchanged_at_end_vpos
+ dvpos
, 0);
14568 /* For frame-based redisplay, make sure that current frame and window
14569 matrix are in sync with respect to glyph memory. */
14570 if (!FRAME_WINDOW_P (f
))
14571 sync_frame_with_window_matrix_rows (w
);
14573 /* Adjust buffer positions in reused rows. */
14575 increment_matrix_positions (current_matrix
,
14576 first_unchanged_at_end_vpos
+ dvpos
,
14577 bottom_vpos
, delta
, delta_bytes
);
14579 /* Adjust Y positions. */
14581 shift_glyph_matrix (w
, current_matrix
,
14582 first_unchanged_at_end_vpos
+ dvpos
,
14585 if (first_unchanged_at_end_row
)
14587 first_unchanged_at_end_row
+= dvpos
;
14588 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14589 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14590 first_unchanged_at_end_row
= NULL
;
14593 /* If scrolling up, there may be some lines to display at the end of
14595 last_text_row_at_end
= NULL
;
14598 /* Scrolling up can leave for example a partially visible line
14599 at the end of the window to be redisplayed. */
14600 /* Set last_row to the glyph row in the current matrix where the
14601 window end line is found. It has been moved up or down in
14602 the matrix by dvpos. */
14603 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14604 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14606 /* If last_row is the window end line, it should display text. */
14607 xassert (last_row
->displays_text_p
);
14609 /* If window end line was partially visible before, begin
14610 displaying at that line. Otherwise begin displaying with the
14611 line following it. */
14612 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14614 init_to_row_start (&it
, w
, last_row
);
14615 it
.vpos
= last_vpos
;
14616 it
.current_y
= last_row
->y
;
14620 init_to_row_end (&it
, w
, last_row
);
14621 it
.vpos
= 1 + last_vpos
;
14622 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14626 /* We may start in a continuation line. If so, we have to
14627 get the right continuation_lines_width and current_x. */
14628 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14629 it
.hpos
= it
.current_x
= 0;
14631 /* Display the rest of the lines at the window end. */
14632 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14633 while (it
.current_y
< it
.last_visible_y
14634 && !fonts_changed_p
)
14636 /* Is it always sure that the display agrees with lines in
14637 the current matrix? I don't think so, so we mark rows
14638 displayed invalid in the current matrix by setting their
14639 enabled_p flag to zero. */
14640 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14641 if (display_line (&it
))
14642 last_text_row_at_end
= it
.glyph_row
- 1;
14646 /* Update window_end_pos and window_end_vpos. */
14647 if (first_unchanged_at_end_row
14648 && !last_text_row_at_end
)
14650 /* Window end line if one of the preserved rows from the current
14651 matrix. Set row to the last row displaying text in current
14652 matrix starting at first_unchanged_at_end_row, after
14654 xassert (first_unchanged_at_end_row
->displays_text_p
);
14655 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14656 first_unchanged_at_end_row
);
14657 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14659 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14660 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14662 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14663 xassert (w
->window_end_bytepos
>= 0);
14664 IF_DEBUG (debug_method_add (w
, "A"));
14666 else if (last_text_row_at_end
)
14669 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14670 w
->window_end_bytepos
14671 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14673 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14674 xassert (w
->window_end_bytepos
>= 0);
14675 IF_DEBUG (debug_method_add (w
, "B"));
14677 else if (last_text_row
)
14679 /* We have displayed either to the end of the window or at the
14680 end of the window, i.e. the last row with text is to be found
14681 in the desired matrix. */
14683 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14684 w
->window_end_bytepos
14685 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14687 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14688 xassert (w
->window_end_bytepos
>= 0);
14690 else if (first_unchanged_at_end_row
== NULL
14691 && last_text_row
== NULL
14692 && last_text_row_at_end
== NULL
)
14694 /* Displayed to end of window, but no line containing text was
14695 displayed. Lines were deleted at the end of the window. */
14696 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14697 int vpos
= XFASTINT (w
->window_end_vpos
);
14698 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14699 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14702 row
== NULL
&& vpos
>= first_vpos
;
14703 --vpos
, --current_row
, --desired_row
)
14705 if (desired_row
->enabled_p
)
14707 if (desired_row
->displays_text_p
)
14710 else if (current_row
->displays_text_p
)
14714 xassert (row
!= NULL
);
14715 w
->window_end_vpos
= make_number (vpos
+ 1);
14716 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14717 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14718 xassert (w
->window_end_bytepos
>= 0);
14719 IF_DEBUG (debug_method_add (w
, "C"));
14724 #if 0 /* This leads to problems, for instance when the cursor is
14725 at ZV, and the cursor line displays no text. */
14726 /* Disable rows below what's displayed in the window. This makes
14727 debugging easier. */
14728 enable_glyph_matrix_rows (current_matrix
,
14729 XFASTINT (w
->window_end_vpos
) + 1,
14733 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14734 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14736 /* Record that display has not been completed. */
14737 w
->window_end_valid
= Qnil
;
14738 w
->desired_matrix
->no_scrolling_p
= 1;
14746 /***********************************************************************
14747 More debugging support
14748 ***********************************************************************/
14752 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14753 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14754 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14757 /* Dump the contents of glyph matrix MATRIX on stderr.
14759 GLYPHS 0 means don't show glyph contents.
14760 GLYPHS 1 means show glyphs in short form
14761 GLYPHS > 1 means show glyphs in long form. */
14764 dump_glyph_matrix (matrix
, glyphs
)
14765 struct glyph_matrix
*matrix
;
14769 for (i
= 0; i
< matrix
->nrows
; ++i
)
14770 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14774 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14775 the glyph row and area where the glyph comes from. */
14778 dump_glyph (row
, glyph
, area
)
14779 struct glyph_row
*row
;
14780 struct glyph
*glyph
;
14783 if (glyph
->type
== CHAR_GLYPH
)
14786 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14787 glyph
- row
->glyphs
[TEXT_AREA
],
14790 (BUFFERP (glyph
->object
)
14792 : (STRINGP (glyph
->object
)
14795 glyph
->pixel_width
,
14797 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14801 glyph
->left_box_line_p
,
14802 glyph
->right_box_line_p
);
14804 else if (glyph
->type
== STRETCH_GLYPH
)
14807 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14808 glyph
- row
->glyphs
[TEXT_AREA
],
14811 (BUFFERP (glyph
->object
)
14813 : (STRINGP (glyph
->object
)
14816 glyph
->pixel_width
,
14820 glyph
->left_box_line_p
,
14821 glyph
->right_box_line_p
);
14823 else if (glyph
->type
== IMAGE_GLYPH
)
14826 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14827 glyph
- row
->glyphs
[TEXT_AREA
],
14830 (BUFFERP (glyph
->object
)
14832 : (STRINGP (glyph
->object
)
14835 glyph
->pixel_width
,
14839 glyph
->left_box_line_p
,
14840 glyph
->right_box_line_p
);
14845 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14846 GLYPHS 0 means don't show glyph contents.
14847 GLYPHS 1 means show glyphs in short form
14848 GLYPHS > 1 means show glyphs in long form. */
14851 dump_glyph_row (row
, vpos
, glyphs
)
14852 struct glyph_row
*row
;
14857 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14858 fprintf (stderr
, "======================================================================\n");
14860 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14861 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14863 MATRIX_ROW_START_CHARPOS (row
),
14864 MATRIX_ROW_END_CHARPOS (row
),
14865 row
->used
[TEXT_AREA
],
14866 row
->contains_overlapping_glyphs_p
,
14868 row
->truncated_on_left_p
,
14869 row
->truncated_on_right_p
,
14871 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14872 row
->displays_text_p
,
14875 row
->ends_in_middle_of_char_p
,
14876 row
->starts_in_middle_of_char_p
,
14882 row
->visible_height
,
14885 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14886 row
->end
.overlay_string_index
,
14887 row
->continuation_lines_width
);
14888 fprintf (stderr
, "%9d %5d\n",
14889 CHARPOS (row
->start
.string_pos
),
14890 CHARPOS (row
->end
.string_pos
));
14891 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14892 row
->end
.dpvec_index
);
14899 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14901 struct glyph
*glyph
= row
->glyphs
[area
];
14902 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14904 /* Glyph for a line end in text. */
14905 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14908 if (glyph
< glyph_end
)
14909 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14911 for (; glyph
< glyph_end
; ++glyph
)
14912 dump_glyph (row
, glyph
, area
);
14915 else if (glyphs
== 1)
14919 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14921 char *s
= (char *) alloca (row
->used
[area
] + 1);
14924 for (i
= 0; i
< row
->used
[area
]; ++i
)
14926 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14927 if (glyph
->type
== CHAR_GLYPH
14928 && glyph
->u
.ch
< 0x80
14929 && glyph
->u
.ch
>= ' ')
14930 s
[i
] = glyph
->u
.ch
;
14936 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14942 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14943 Sdump_glyph_matrix
, 0, 1, "p",
14944 doc
: /* Dump the current matrix of the selected window to stderr.
14945 Shows contents of glyph row structures. With non-nil
14946 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14947 glyphs in short form, otherwise show glyphs in long form. */)
14949 Lisp_Object glyphs
;
14951 struct window
*w
= XWINDOW (selected_window
);
14952 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14954 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14955 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14956 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14957 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14958 fprintf (stderr
, "=============================================\n");
14959 dump_glyph_matrix (w
->current_matrix
,
14960 NILP (glyphs
) ? 0 : XINT (glyphs
));
14965 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14966 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14969 struct frame
*f
= XFRAME (selected_frame
);
14970 dump_glyph_matrix (f
->current_matrix
, 1);
14975 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14976 doc
: /* Dump glyph row ROW to stderr.
14977 GLYPH 0 means don't dump glyphs.
14978 GLYPH 1 means dump glyphs in short form.
14979 GLYPH > 1 or omitted means dump glyphs in long form. */)
14981 Lisp_Object row
, glyphs
;
14983 struct glyph_matrix
*matrix
;
14986 CHECK_NUMBER (row
);
14987 matrix
= XWINDOW (selected_window
)->current_matrix
;
14989 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14990 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14992 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14997 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14998 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14999 GLYPH 0 means don't dump glyphs.
15000 GLYPH 1 means dump glyphs in short form.
15001 GLYPH > 1 or omitted means dump glyphs in long form. */)
15003 Lisp_Object row
, glyphs
;
15005 struct frame
*sf
= SELECTED_FRAME ();
15006 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15009 CHECK_NUMBER (row
);
15011 if (vpos
>= 0 && vpos
< m
->nrows
)
15012 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15013 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15018 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15019 doc
: /* Toggle tracing of redisplay.
15020 With ARG, turn tracing on if and only if ARG is positive. */)
15025 trace_redisplay_p
= !trace_redisplay_p
;
15028 arg
= Fprefix_numeric_value (arg
);
15029 trace_redisplay_p
= XINT (arg
) > 0;
15036 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15037 doc
: /* Like `format', but print result to stderr.
15038 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15043 Lisp_Object s
= Fformat (nargs
, args
);
15044 fprintf (stderr
, "%s", SDATA (s
));
15048 #endif /* GLYPH_DEBUG */
15052 /***********************************************************************
15053 Building Desired Matrix Rows
15054 ***********************************************************************/
15056 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15057 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15059 static struct glyph_row
*
15060 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15062 Lisp_Object overlay_arrow_string
;
15064 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15065 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15066 struct buffer
*old
= current_buffer
;
15067 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15068 int arrow_len
= SCHARS (overlay_arrow_string
);
15069 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15070 const unsigned char *p
;
15073 int n_glyphs_before
;
15075 set_buffer_temp (buffer
);
15076 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15077 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15078 SET_TEXT_POS (it
.position
, 0, 0);
15080 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15082 while (p
< arrow_end
)
15084 Lisp_Object face
, ilisp
;
15086 /* Get the next character. */
15088 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15090 it
.c
= *p
, it
.len
= 1;
15093 /* Get its face. */
15094 ilisp
= make_number (p
- arrow_string
);
15095 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15096 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15098 /* Compute its width, get its glyphs. */
15099 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15100 SET_TEXT_POS (it
.position
, -1, -1);
15101 PRODUCE_GLYPHS (&it
);
15103 /* If this character doesn't fit any more in the line, we have
15104 to remove some glyphs. */
15105 if (it
.current_x
> it
.last_visible_x
)
15107 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15112 set_buffer_temp (old
);
15113 return it
.glyph_row
;
15117 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15118 glyphs are only inserted for terminal frames since we can't really
15119 win with truncation glyphs when partially visible glyphs are
15120 involved. Which glyphs to insert is determined by
15121 produce_special_glyphs. */
15124 insert_left_trunc_glyphs (it
)
15127 struct it truncate_it
;
15128 struct glyph
*from
, *end
, *to
, *toend
;
15130 xassert (!FRAME_WINDOW_P (it
->f
));
15132 /* Get the truncation glyphs. */
15134 truncate_it
.current_x
= 0;
15135 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15136 truncate_it
.glyph_row
= &scratch_glyph_row
;
15137 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15138 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15139 truncate_it
.object
= make_number (0);
15140 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15142 /* Overwrite glyphs from IT with truncation glyphs. */
15143 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15144 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15145 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15146 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15151 /* There may be padding glyphs left over. Overwrite them too. */
15152 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15154 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15160 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15164 /* Compute the pixel height and width of IT->glyph_row.
15166 Most of the time, ascent and height of a display line will be equal
15167 to the max_ascent and max_height values of the display iterator
15168 structure. This is not the case if
15170 1. We hit ZV without displaying anything. In this case, max_ascent
15171 and max_height will be zero.
15173 2. We have some glyphs that don't contribute to the line height.
15174 (The glyph row flag contributes_to_line_height_p is for future
15175 pixmap extensions).
15177 The first case is easily covered by using default values because in
15178 these cases, the line height does not really matter, except that it
15179 must not be zero. */
15182 compute_line_metrics (it
)
15185 struct glyph_row
*row
= it
->glyph_row
;
15188 if (FRAME_WINDOW_P (it
->f
))
15190 int i
, min_y
, max_y
;
15192 /* The line may consist of one space only, that was added to
15193 place the cursor on it. If so, the row's height hasn't been
15195 if (row
->height
== 0)
15197 if (it
->max_ascent
+ it
->max_descent
== 0)
15198 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15199 row
->ascent
= it
->max_ascent
;
15200 row
->height
= it
->max_ascent
+ it
->max_descent
;
15201 row
->phys_ascent
= it
->max_phys_ascent
;
15202 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15203 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15206 /* Compute the width of this line. */
15207 row
->pixel_width
= row
->x
;
15208 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15209 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15211 xassert (row
->pixel_width
>= 0);
15212 xassert (row
->ascent
>= 0 && row
->height
> 0);
15214 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15215 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15217 /* If first line's physical ascent is larger than its logical
15218 ascent, use the physical ascent, and make the row taller.
15219 This makes accented characters fully visible. */
15220 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15221 && row
->phys_ascent
> row
->ascent
)
15223 row
->height
+= row
->phys_ascent
- row
->ascent
;
15224 row
->ascent
= row
->phys_ascent
;
15227 /* Compute how much of the line is visible. */
15228 row
->visible_height
= row
->height
;
15230 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15231 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15233 if (row
->y
< min_y
)
15234 row
->visible_height
-= min_y
- row
->y
;
15235 if (row
->y
+ row
->height
> max_y
)
15236 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15240 row
->pixel_width
= row
->used
[TEXT_AREA
];
15241 if (row
->continued_p
)
15242 row
->pixel_width
-= it
->continuation_pixel_width
;
15243 else if (row
->truncated_on_right_p
)
15244 row
->pixel_width
-= it
->truncation_pixel_width
;
15245 row
->ascent
= row
->phys_ascent
= 0;
15246 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15247 row
->extra_line_spacing
= 0;
15250 /* Compute a hash code for this row. */
15252 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15253 for (i
= 0; i
< row
->used
[area
]; ++i
)
15254 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15255 + row
->glyphs
[area
][i
].u
.val
15256 + row
->glyphs
[area
][i
].face_id
15257 + row
->glyphs
[area
][i
].padding_p
15258 + (row
->glyphs
[area
][i
].type
<< 2));
15260 it
->max_ascent
= it
->max_descent
= 0;
15261 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15265 /* Append one space to the glyph row of iterator IT if doing a
15266 window-based redisplay. The space has the same face as
15267 IT->face_id. Value is non-zero if a space was added.
15269 This function is called to make sure that there is always one glyph
15270 at the end of a glyph row that the cursor can be set on under
15271 window-systems. (If there weren't such a glyph we would not know
15272 how wide and tall a box cursor should be displayed).
15274 At the same time this space let's a nicely handle clearing to the
15275 end of the line if the row ends in italic text. */
15278 append_space_for_newline (it
, default_face_p
)
15280 int default_face_p
;
15282 if (FRAME_WINDOW_P (it
->f
))
15284 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15286 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15287 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15289 /* Save some values that must not be changed.
15290 Must save IT->c and IT->len because otherwise
15291 ITERATOR_AT_END_P wouldn't work anymore after
15292 append_space_for_newline has been called. */
15293 enum display_element_type saved_what
= it
->what
;
15294 int saved_c
= it
->c
, saved_len
= it
->len
;
15295 int saved_x
= it
->current_x
;
15296 int saved_face_id
= it
->face_id
;
15297 struct text_pos saved_pos
;
15298 Lisp_Object saved_object
;
15301 saved_object
= it
->object
;
15302 saved_pos
= it
->position
;
15304 it
->what
= IT_CHARACTER
;
15305 bzero (&it
->position
, sizeof it
->position
);
15306 it
->object
= make_number (0);
15310 if (default_face_p
)
15311 it
->face_id
= DEFAULT_FACE_ID
;
15312 else if (it
->face_before_selective_p
)
15313 it
->face_id
= it
->saved_face_id
;
15314 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15315 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15317 PRODUCE_GLYPHS (it
);
15319 it
->override_ascent
= -1;
15320 it
->constrain_row_ascent_descent_p
= 0;
15321 it
->current_x
= saved_x
;
15322 it
->object
= saved_object
;
15323 it
->position
= saved_pos
;
15324 it
->what
= saved_what
;
15325 it
->face_id
= saved_face_id
;
15326 it
->len
= saved_len
;
15336 /* Extend the face of the last glyph in the text area of IT->glyph_row
15337 to the end of the display line. Called from display_line.
15338 If the glyph row is empty, add a space glyph to it so that we
15339 know the face to draw. Set the glyph row flag fill_line_p. */
15342 extend_face_to_end_of_line (it
)
15346 struct frame
*f
= it
->f
;
15348 /* If line is already filled, do nothing. */
15349 if (it
->current_x
>= it
->last_visible_x
)
15352 /* Face extension extends the background and box of IT->face_id
15353 to the end of the line. If the background equals the background
15354 of the frame, we don't have to do anything. */
15355 if (it
->face_before_selective_p
)
15356 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15358 face
= FACE_FROM_ID (f
, it
->face_id
);
15360 if (FRAME_WINDOW_P (f
)
15361 && face
->box
== FACE_NO_BOX
15362 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15366 /* Set the glyph row flag indicating that the face of the last glyph
15367 in the text area has to be drawn to the end of the text area. */
15368 it
->glyph_row
->fill_line_p
= 1;
15370 /* If current character of IT is not ASCII, make sure we have the
15371 ASCII face. This will be automatically undone the next time
15372 get_next_display_element returns a multibyte character. Note
15373 that the character will always be single byte in unibyte text. */
15374 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15376 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15379 if (FRAME_WINDOW_P (f
))
15381 /* If the row is empty, add a space with the current face of IT,
15382 so that we know which face to draw. */
15383 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15385 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15386 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15387 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15392 /* Save some values that must not be changed. */
15393 int saved_x
= it
->current_x
;
15394 struct text_pos saved_pos
;
15395 Lisp_Object saved_object
;
15396 enum display_element_type saved_what
= it
->what
;
15397 int saved_face_id
= it
->face_id
;
15399 saved_object
= it
->object
;
15400 saved_pos
= it
->position
;
15402 it
->what
= IT_CHARACTER
;
15403 bzero (&it
->position
, sizeof it
->position
);
15404 it
->object
= make_number (0);
15407 it
->face_id
= face
->id
;
15409 PRODUCE_GLYPHS (it
);
15411 while (it
->current_x
<= it
->last_visible_x
)
15412 PRODUCE_GLYPHS (it
);
15414 /* Don't count these blanks really. It would let us insert a left
15415 truncation glyph below and make us set the cursor on them, maybe. */
15416 it
->current_x
= saved_x
;
15417 it
->object
= saved_object
;
15418 it
->position
= saved_pos
;
15419 it
->what
= saved_what
;
15420 it
->face_id
= saved_face_id
;
15425 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15426 trailing whitespace. */
15429 trailing_whitespace_p (charpos
)
15432 int bytepos
= CHAR_TO_BYTE (charpos
);
15435 while (bytepos
< ZV_BYTE
15436 && (c
= FETCH_CHAR (bytepos
),
15437 c
== ' ' || c
== '\t'))
15440 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15442 if (bytepos
!= PT_BYTE
)
15449 /* Highlight trailing whitespace, if any, in ROW. */
15452 highlight_trailing_whitespace (f
, row
)
15454 struct glyph_row
*row
;
15456 int used
= row
->used
[TEXT_AREA
];
15460 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15461 struct glyph
*glyph
= start
+ used
- 1;
15463 /* Skip over glyphs inserted to display the cursor at the
15464 end of a line, for extending the face of the last glyph
15465 to the end of the line on terminals, and for truncation
15466 and continuation glyphs. */
15467 while (glyph
>= start
15468 && glyph
->type
== CHAR_GLYPH
15469 && INTEGERP (glyph
->object
))
15472 /* If last glyph is a space or stretch, and it's trailing
15473 whitespace, set the face of all trailing whitespace glyphs in
15474 IT->glyph_row to `trailing-whitespace'. */
15476 && BUFFERP (glyph
->object
)
15477 && (glyph
->type
== STRETCH_GLYPH
15478 || (glyph
->type
== CHAR_GLYPH
15479 && glyph
->u
.ch
== ' '))
15480 && trailing_whitespace_p (glyph
->charpos
))
15482 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15486 while (glyph
>= start
15487 && BUFFERP (glyph
->object
)
15488 && (glyph
->type
== STRETCH_GLYPH
15489 || (glyph
->type
== CHAR_GLYPH
15490 && glyph
->u
.ch
== ' ')))
15491 (glyph
--)->face_id
= face_id
;
15497 /* Value is non-zero if glyph row ROW in window W should be
15498 used to hold the cursor. */
15501 cursor_row_p (w
, row
)
15503 struct glyph_row
*row
;
15505 int cursor_row_p
= 1;
15507 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15509 /* If the row ends with a newline from a string, we don't want
15510 the cursor there, but we still want it at the start of the
15511 string if the string starts in this row.
15512 If the row is continued it doesn't end in a newline. */
15513 if (CHARPOS (row
->end
.string_pos
) >= 0)
15514 cursor_row_p
= (row
->continued_p
15515 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15516 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15518 /* If the row ends in middle of a real character,
15519 and the line is continued, we want the cursor here.
15520 That's because MATRIX_ROW_END_CHARPOS would equal
15521 PT if PT is before the character. */
15522 if (!row
->ends_in_ellipsis_p
)
15523 cursor_row_p
= row
->continued_p
;
15525 /* If the row ends in an ellipsis, then
15526 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15527 We want that position to be displayed after the ellipsis. */
15530 /* If the row ends at ZV, display the cursor at the end of that
15531 row instead of at the start of the row below. */
15532 else if (row
->ends_at_zv_p
)
15538 return cursor_row_p
;
15542 /* Construct the glyph row IT->glyph_row in the desired matrix of
15543 IT->w from text at the current position of IT. See dispextern.h
15544 for an overview of struct it. Value is non-zero if
15545 IT->glyph_row displays text, as opposed to a line displaying ZV
15552 struct glyph_row
*row
= it
->glyph_row
;
15553 Lisp_Object overlay_arrow_string
;
15555 /* We always start displaying at hpos zero even if hscrolled. */
15556 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15558 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15559 >= it
->w
->desired_matrix
->nrows
)
15561 it
->w
->nrows_scale_factor
++;
15562 fonts_changed_p
= 1;
15566 /* Is IT->w showing the region? */
15567 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15569 /* Clear the result glyph row and enable it. */
15570 prepare_desired_row (row
);
15572 row
->y
= it
->current_y
;
15573 row
->start
= it
->start
;
15574 row
->continuation_lines_width
= it
->continuation_lines_width
;
15575 row
->displays_text_p
= 1;
15576 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15577 it
->starts_in_middle_of_char_p
= 0;
15579 /* Arrange the overlays nicely for our purposes. Usually, we call
15580 display_line on only one line at a time, in which case this
15581 can't really hurt too much, or we call it on lines which appear
15582 one after another in the buffer, in which case all calls to
15583 recenter_overlay_lists but the first will be pretty cheap. */
15584 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15586 /* Move over display elements that are not visible because we are
15587 hscrolled. This may stop at an x-position < IT->first_visible_x
15588 if the first glyph is partially visible or if we hit a line end. */
15589 if (it
->current_x
< it
->first_visible_x
)
15591 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15592 MOVE_TO_POS
| MOVE_TO_X
);
15595 /* Get the initial row height. This is either the height of the
15596 text hscrolled, if there is any, or zero. */
15597 row
->ascent
= it
->max_ascent
;
15598 row
->height
= it
->max_ascent
+ it
->max_descent
;
15599 row
->phys_ascent
= it
->max_phys_ascent
;
15600 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15601 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15603 /* Loop generating characters. The loop is left with IT on the next
15604 character to display. */
15607 int n_glyphs_before
, hpos_before
, x_before
;
15609 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15611 /* Retrieve the next thing to display. Value is zero if end of
15613 if (!get_next_display_element (it
))
15615 /* Maybe add a space at the end of this line that is used to
15616 display the cursor there under X. Set the charpos of the
15617 first glyph of blank lines not corresponding to any text
15619 #ifdef HAVE_WINDOW_SYSTEM
15620 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15621 row
->exact_window_width_line_p
= 1;
15623 #endif /* HAVE_WINDOW_SYSTEM */
15624 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15625 || row
->used
[TEXT_AREA
] == 0)
15627 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15628 row
->displays_text_p
= 0;
15630 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15631 && (!MINI_WINDOW_P (it
->w
)
15632 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15633 row
->indicate_empty_line_p
= 1;
15636 it
->continuation_lines_width
= 0;
15637 row
->ends_at_zv_p
= 1;
15641 /* Now, get the metrics of what we want to display. This also
15642 generates glyphs in `row' (which is IT->glyph_row). */
15643 n_glyphs_before
= row
->used
[TEXT_AREA
];
15646 /* Remember the line height so far in case the next element doesn't
15647 fit on the line. */
15648 if (!it
->truncate_lines_p
)
15650 ascent
= it
->max_ascent
;
15651 descent
= it
->max_descent
;
15652 phys_ascent
= it
->max_phys_ascent
;
15653 phys_descent
= it
->max_phys_descent
;
15656 PRODUCE_GLYPHS (it
);
15658 /* If this display element was in marginal areas, continue with
15660 if (it
->area
!= TEXT_AREA
)
15662 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15663 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15664 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15665 row
->phys_height
= max (row
->phys_height
,
15666 it
->max_phys_ascent
+ it
->max_phys_descent
);
15667 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15668 it
->max_extra_line_spacing
);
15669 set_iterator_to_next (it
, 1);
15673 /* Does the display element fit on the line? If we truncate
15674 lines, we should draw past the right edge of the window. If
15675 we don't truncate, we want to stop so that we can display the
15676 continuation glyph before the right margin. If lines are
15677 continued, there are two possible strategies for characters
15678 resulting in more than 1 glyph (e.g. tabs): Display as many
15679 glyphs as possible in this line and leave the rest for the
15680 continuation line, or display the whole element in the next
15681 line. Original redisplay did the former, so we do it also. */
15682 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15683 hpos_before
= it
->hpos
;
15686 if (/* Not a newline. */
15688 /* Glyphs produced fit entirely in the line. */
15689 && it
->current_x
< it
->last_visible_x
)
15691 it
->hpos
+= nglyphs
;
15692 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15693 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15694 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15695 row
->phys_height
= max (row
->phys_height
,
15696 it
->max_phys_ascent
+ it
->max_phys_descent
);
15697 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15698 it
->max_extra_line_spacing
);
15699 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15700 row
->x
= x
- it
->first_visible_x
;
15705 struct glyph
*glyph
;
15707 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15709 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15710 new_x
= x
+ glyph
->pixel_width
;
15712 if (/* Lines are continued. */
15713 !it
->truncate_lines_p
15714 && (/* Glyph doesn't fit on the line. */
15715 new_x
> it
->last_visible_x
15716 /* Or it fits exactly on a window system frame. */
15717 || (new_x
== it
->last_visible_x
15718 && FRAME_WINDOW_P (it
->f
))))
15720 /* End of a continued line. */
15723 || (new_x
== it
->last_visible_x
15724 && FRAME_WINDOW_P (it
->f
)))
15726 /* Current glyph is the only one on the line or
15727 fits exactly on the line. We must continue
15728 the line because we can't draw the cursor
15729 after the glyph. */
15730 row
->continued_p
= 1;
15731 it
->current_x
= new_x
;
15732 it
->continuation_lines_width
+= new_x
;
15734 if (i
== nglyphs
- 1)
15736 set_iterator_to_next (it
, 1);
15737 #ifdef HAVE_WINDOW_SYSTEM
15738 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15740 if (!get_next_display_element (it
))
15742 row
->exact_window_width_line_p
= 1;
15743 it
->continuation_lines_width
= 0;
15744 row
->continued_p
= 0;
15745 row
->ends_at_zv_p
= 1;
15747 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15749 row
->continued_p
= 0;
15750 row
->exact_window_width_line_p
= 1;
15753 #endif /* HAVE_WINDOW_SYSTEM */
15756 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15757 && !FRAME_WINDOW_P (it
->f
))
15759 /* A padding glyph that doesn't fit on this line.
15760 This means the whole character doesn't fit
15762 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15764 /* Fill the rest of the row with continuation
15765 glyphs like in 20.x. */
15766 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15767 < row
->glyphs
[1 + TEXT_AREA
])
15768 produce_special_glyphs (it
, IT_CONTINUATION
);
15770 row
->continued_p
= 1;
15771 it
->current_x
= x_before
;
15772 it
->continuation_lines_width
+= x_before
;
15774 /* Restore the height to what it was before the
15775 element not fitting on the line. */
15776 it
->max_ascent
= ascent
;
15777 it
->max_descent
= descent
;
15778 it
->max_phys_ascent
= phys_ascent
;
15779 it
->max_phys_descent
= phys_descent
;
15781 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15783 /* A TAB that extends past the right edge of the
15784 window. This produces a single glyph on
15785 window system frames. We leave the glyph in
15786 this row and let it fill the row, but don't
15787 consume the TAB. */
15788 it
->continuation_lines_width
+= it
->last_visible_x
;
15789 row
->ends_in_middle_of_char_p
= 1;
15790 row
->continued_p
= 1;
15791 glyph
->pixel_width
= it
->last_visible_x
- x
;
15792 it
->starts_in_middle_of_char_p
= 1;
15796 /* Something other than a TAB that draws past
15797 the right edge of the window. Restore
15798 positions to values before the element. */
15799 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15801 /* Display continuation glyphs. */
15802 if (!FRAME_WINDOW_P (it
->f
))
15803 produce_special_glyphs (it
, IT_CONTINUATION
);
15804 row
->continued_p
= 1;
15806 it
->current_x
= x_before
;
15807 it
->continuation_lines_width
+= x
;
15808 extend_face_to_end_of_line (it
);
15810 if (nglyphs
> 1 && i
> 0)
15812 row
->ends_in_middle_of_char_p
= 1;
15813 it
->starts_in_middle_of_char_p
= 1;
15816 /* Restore the height to what it was before the
15817 element not fitting on the line. */
15818 it
->max_ascent
= ascent
;
15819 it
->max_descent
= descent
;
15820 it
->max_phys_ascent
= phys_ascent
;
15821 it
->max_phys_descent
= phys_descent
;
15826 else if (new_x
> it
->first_visible_x
)
15828 /* Increment number of glyphs actually displayed. */
15831 if (x
< it
->first_visible_x
)
15832 /* Glyph is partially visible, i.e. row starts at
15833 negative X position. */
15834 row
->x
= x
- it
->first_visible_x
;
15838 /* Glyph is completely off the left margin of the
15839 window. This should not happen because of the
15840 move_it_in_display_line at the start of this
15841 function, unless the text display area of the
15842 window is empty. */
15843 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15847 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15848 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15849 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15850 row
->phys_height
= max (row
->phys_height
,
15851 it
->max_phys_ascent
+ it
->max_phys_descent
);
15852 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15853 it
->max_extra_line_spacing
);
15855 /* End of this display line if row is continued. */
15856 if (row
->continued_p
|| row
->ends_at_zv_p
)
15861 /* Is this a line end? If yes, we're also done, after making
15862 sure that a non-default face is extended up to the right
15863 margin of the window. */
15864 if (ITERATOR_AT_END_OF_LINE_P (it
))
15866 int used_before
= row
->used
[TEXT_AREA
];
15868 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15870 #ifdef HAVE_WINDOW_SYSTEM
15871 /* Add a space at the end of the line that is used to
15872 display the cursor there. */
15873 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15874 append_space_for_newline (it
, 0);
15875 #endif /* HAVE_WINDOW_SYSTEM */
15877 /* Extend the face to the end of the line. */
15878 extend_face_to_end_of_line (it
);
15880 /* Make sure we have the position. */
15881 if (used_before
== 0)
15882 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15884 /* Consume the line end. This skips over invisible lines. */
15885 set_iterator_to_next (it
, 1);
15886 it
->continuation_lines_width
= 0;
15890 /* Proceed with next display element. Note that this skips
15891 over lines invisible because of selective display. */
15892 set_iterator_to_next (it
, 1);
15894 /* If we truncate lines, we are done when the last displayed
15895 glyphs reach past the right margin of the window. */
15896 if (it
->truncate_lines_p
15897 && (FRAME_WINDOW_P (it
->f
)
15898 ? (it
->current_x
>= it
->last_visible_x
)
15899 : (it
->current_x
> it
->last_visible_x
)))
15901 /* Maybe add truncation glyphs. */
15902 if (!FRAME_WINDOW_P (it
->f
))
15906 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15907 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15910 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15912 row
->used
[TEXT_AREA
] = i
;
15913 produce_special_glyphs (it
, IT_TRUNCATION
);
15916 #ifdef HAVE_WINDOW_SYSTEM
15919 /* Don't truncate if we can overflow newline into fringe. */
15920 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15922 if (!get_next_display_element (it
))
15924 it
->continuation_lines_width
= 0;
15925 row
->ends_at_zv_p
= 1;
15926 row
->exact_window_width_line_p
= 1;
15929 if (ITERATOR_AT_END_OF_LINE_P (it
))
15931 row
->exact_window_width_line_p
= 1;
15932 goto at_end_of_line
;
15936 #endif /* HAVE_WINDOW_SYSTEM */
15938 row
->truncated_on_right_p
= 1;
15939 it
->continuation_lines_width
= 0;
15940 reseat_at_next_visible_line_start (it
, 0);
15941 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15942 it
->hpos
= hpos_before
;
15943 it
->current_x
= x_before
;
15948 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15949 at the left window margin. */
15950 if (it
->first_visible_x
15951 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15953 if (!FRAME_WINDOW_P (it
->f
))
15954 insert_left_trunc_glyphs (it
);
15955 row
->truncated_on_left_p
= 1;
15958 /* If the start of this line is the overlay arrow-position, then
15959 mark this glyph row as the one containing the overlay arrow.
15960 This is clearly a mess with variable size fonts. It would be
15961 better to let it be displayed like cursors under X. */
15962 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15963 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15964 !NILP (overlay_arrow_string
)))
15966 /* Overlay arrow in window redisplay is a fringe bitmap. */
15967 if (STRINGP (overlay_arrow_string
))
15969 struct glyph_row
*arrow_row
15970 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15971 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15972 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15973 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15974 struct glyph
*p2
, *end
;
15976 /* Copy the arrow glyphs. */
15977 while (glyph
< arrow_end
)
15980 /* Throw away padding glyphs. */
15982 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15983 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15989 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15994 xassert (INTEGERP (overlay_arrow_string
));
15995 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15997 overlay_arrow_seen
= 1;
16000 /* Compute pixel dimensions of this line. */
16001 compute_line_metrics (it
);
16003 /* Remember the position at which this line ends. */
16004 row
->end
= it
->current
;
16006 /* Record whether this row ends inside an ellipsis. */
16007 row
->ends_in_ellipsis_p
16008 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16009 && it
->ellipsis_p
);
16011 /* Save fringe bitmaps in this row. */
16012 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16013 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16014 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16015 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16017 it
->left_user_fringe_bitmap
= 0;
16018 it
->left_user_fringe_face_id
= 0;
16019 it
->right_user_fringe_bitmap
= 0;
16020 it
->right_user_fringe_face_id
= 0;
16022 /* Maybe set the cursor. */
16023 if (it
->w
->cursor
.vpos
< 0
16024 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16025 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16026 && cursor_row_p (it
->w
, row
))
16027 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16029 /* Highlight trailing whitespace. */
16030 if (!NILP (Vshow_trailing_whitespace
))
16031 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16033 /* Prepare for the next line. This line starts horizontally at (X
16034 HPOS) = (0 0). Vertical positions are incremented. As a
16035 convenience for the caller, IT->glyph_row is set to the next
16037 it
->current_x
= it
->hpos
= 0;
16038 it
->current_y
+= row
->height
;
16041 it
->start
= it
->current
;
16042 return row
->displays_text_p
;
16047 /***********************************************************************
16049 ***********************************************************************/
16051 /* Redisplay the menu bar in the frame for window W.
16053 The menu bar of X frames that don't have X toolkit support is
16054 displayed in a special window W->frame->menu_bar_window.
16056 The menu bar of terminal frames is treated specially as far as
16057 glyph matrices are concerned. Menu bar lines are not part of
16058 windows, so the update is done directly on the frame matrix rows
16059 for the menu bar. */
16062 display_menu_bar (w
)
16065 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16070 /* Don't do all this for graphical frames. */
16072 if (!NILP (Vwindow_system
))
16075 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16080 if (FRAME_MAC_P (f
))
16084 #ifdef USE_X_TOOLKIT
16085 xassert (!FRAME_WINDOW_P (f
));
16086 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16087 it
.first_visible_x
= 0;
16088 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16089 #else /* not USE_X_TOOLKIT */
16090 if (FRAME_WINDOW_P (f
))
16092 /* Menu bar lines are displayed in the desired matrix of the
16093 dummy window menu_bar_window. */
16094 struct window
*menu_w
;
16095 xassert (WINDOWP (f
->menu_bar_window
));
16096 menu_w
= XWINDOW (f
->menu_bar_window
);
16097 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16099 it
.first_visible_x
= 0;
16100 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16104 /* This is a TTY frame, i.e. character hpos/vpos are used as
16106 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16108 it
.first_visible_x
= 0;
16109 it
.last_visible_x
= FRAME_COLS (f
);
16111 #endif /* not USE_X_TOOLKIT */
16113 if (! mode_line_inverse_video
)
16114 /* Force the menu-bar to be displayed in the default face. */
16115 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16117 /* Clear all rows of the menu bar. */
16118 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16120 struct glyph_row
*row
= it
.glyph_row
+ i
;
16121 clear_glyph_row (row
);
16122 row
->enabled_p
= 1;
16123 row
->full_width_p
= 1;
16126 /* Display all items of the menu bar. */
16127 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16128 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16130 Lisp_Object string
;
16132 /* Stop at nil string. */
16133 string
= AREF (items
, i
+ 1);
16137 /* Remember where item was displayed. */
16138 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16140 /* Display the item, pad with one space. */
16141 if (it
.current_x
< it
.last_visible_x
)
16142 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16143 SCHARS (string
) + 1, 0, 0, -1);
16146 /* Fill out the line with spaces. */
16147 if (it
.current_x
< it
.last_visible_x
)
16148 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16150 /* Compute the total height of the lines. */
16151 compute_line_metrics (&it
);
16156 /***********************************************************************
16158 ***********************************************************************/
16160 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16161 FORCE is non-zero, redisplay mode lines unconditionally.
16162 Otherwise, redisplay only mode lines that are garbaged. Value is
16163 the number of windows whose mode lines were redisplayed. */
16166 redisplay_mode_lines (window
, force
)
16167 Lisp_Object window
;
16172 while (!NILP (window
))
16174 struct window
*w
= XWINDOW (window
);
16176 if (WINDOWP (w
->hchild
))
16177 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16178 else if (WINDOWP (w
->vchild
))
16179 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16181 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16182 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16184 struct text_pos lpoint
;
16185 struct buffer
*old
= current_buffer
;
16187 /* Set the window's buffer for the mode line display. */
16188 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16189 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16191 /* Point refers normally to the selected window. For any
16192 other window, set up appropriate value. */
16193 if (!EQ (window
, selected_window
))
16195 struct text_pos pt
;
16197 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16198 if (CHARPOS (pt
) < BEGV
)
16199 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16200 else if (CHARPOS (pt
) > (ZV
- 1))
16201 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16203 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16206 /* Display mode lines. */
16207 clear_glyph_matrix (w
->desired_matrix
);
16208 if (display_mode_lines (w
))
16211 w
->must_be_updated_p
= 1;
16214 /* Restore old settings. */
16215 set_buffer_internal_1 (old
);
16216 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16226 /* Display the mode and/or top line of window W. Value is the number
16227 of mode lines displayed. */
16230 display_mode_lines (w
)
16233 Lisp_Object old_selected_window
, old_selected_frame
;
16236 old_selected_frame
= selected_frame
;
16237 selected_frame
= w
->frame
;
16238 old_selected_window
= selected_window
;
16239 XSETWINDOW (selected_window
, w
);
16241 /* These will be set while the mode line specs are processed. */
16242 line_number_displayed
= 0;
16243 w
->column_number_displayed
= Qnil
;
16245 if (WINDOW_WANTS_MODELINE_P (w
))
16247 struct window
*sel_w
= XWINDOW (old_selected_window
);
16249 /* Select mode line face based on the real selected window. */
16250 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16251 current_buffer
->mode_line_format
);
16255 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16257 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16258 current_buffer
->header_line_format
);
16262 selected_frame
= old_selected_frame
;
16263 selected_window
= old_selected_window
;
16268 /* Display mode or top line of window W. FACE_ID specifies which line
16269 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16270 FORMAT is the mode line format to display. Value is the pixel
16271 height of the mode line displayed. */
16274 display_mode_line (w
, face_id
, format
)
16276 enum face_id face_id
;
16277 Lisp_Object format
;
16281 int count
= SPECPDL_INDEX ();
16283 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16284 prepare_desired_row (it
.glyph_row
);
16286 it
.glyph_row
->mode_line_p
= 1;
16288 if (! mode_line_inverse_video
)
16289 /* Force the mode-line to be displayed in the default face. */
16290 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16292 record_unwind_protect (unwind_format_mode_line
,
16293 format_mode_line_unwind_data (NULL
, 0));
16295 mode_line_target
= MODE_LINE_DISPLAY
;
16297 /* Temporarily make frame's keyboard the current kboard so that
16298 kboard-local variables in the mode_line_format will get the right
16300 push_frame_kboard (it
.f
);
16301 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16302 pop_frame_kboard ();
16304 unbind_to (count
, Qnil
);
16306 /* Fill up with spaces. */
16307 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16309 compute_line_metrics (&it
);
16310 it
.glyph_row
->full_width_p
= 1;
16311 it
.glyph_row
->continued_p
= 0;
16312 it
.glyph_row
->truncated_on_left_p
= 0;
16313 it
.glyph_row
->truncated_on_right_p
= 0;
16315 /* Make a 3D mode-line have a shadow at its right end. */
16316 face
= FACE_FROM_ID (it
.f
, face_id
);
16317 extend_face_to_end_of_line (&it
);
16318 if (face
->box
!= FACE_NO_BOX
)
16320 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16321 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16322 last
->right_box_line_p
= 1;
16325 return it
.glyph_row
->height
;
16328 /* Move element ELT in LIST to the front of LIST.
16329 Return the updated list. */
16332 move_elt_to_front (elt
, list
)
16333 Lisp_Object elt
, list
;
16335 register Lisp_Object tail
, prev
;
16336 register Lisp_Object tem
;
16340 while (CONSP (tail
))
16346 /* Splice out the link TAIL. */
16348 list
= XCDR (tail
);
16350 Fsetcdr (prev
, XCDR (tail
));
16352 /* Now make it the first. */
16353 Fsetcdr (tail
, list
);
16358 tail
= XCDR (tail
);
16362 /* Not found--return unchanged LIST. */
16366 /* Contribute ELT to the mode line for window IT->w. How it
16367 translates into text depends on its data type.
16369 IT describes the display environment in which we display, as usual.
16371 DEPTH is the depth in recursion. It is used to prevent
16372 infinite recursion here.
16374 FIELD_WIDTH is the number of characters the display of ELT should
16375 occupy in the mode line, and PRECISION is the maximum number of
16376 characters to display from ELT's representation. See
16377 display_string for details.
16379 Returns the hpos of the end of the text generated by ELT.
16381 PROPS is a property list to add to any string we encounter.
16383 If RISKY is nonzero, remove (disregard) any properties in any string
16384 we encounter, and ignore :eval and :propertize.
16386 The global variable `mode_line_target' determines whether the
16387 output is passed to `store_mode_line_noprop',
16388 `store_mode_line_string', or `display_string'. */
16391 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16394 int field_width
, precision
;
16395 Lisp_Object elt
, props
;
16398 int n
= 0, field
, prec
;
16403 elt
= build_string ("*too-deep*");
16407 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16411 /* A string: output it and check for %-constructs within it. */
16415 if (SCHARS (elt
) > 0
16416 && (!NILP (props
) || risky
))
16418 Lisp_Object oprops
, aelt
;
16419 oprops
= Ftext_properties_at (make_number (0), elt
);
16421 /* If the starting string's properties are not what
16422 we want, translate the string. Also, if the string
16423 is risky, do that anyway. */
16425 if (NILP (Fequal (props
, oprops
)) || risky
)
16427 /* If the starting string has properties,
16428 merge the specified ones onto the existing ones. */
16429 if (! NILP (oprops
) && !risky
)
16433 oprops
= Fcopy_sequence (oprops
);
16435 while (CONSP (tem
))
16437 oprops
= Fplist_put (oprops
, XCAR (tem
),
16438 XCAR (XCDR (tem
)));
16439 tem
= XCDR (XCDR (tem
));
16444 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16445 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16447 /* AELT is what we want. Move it to the front
16448 without consing. */
16450 mode_line_proptrans_alist
16451 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16457 /* If AELT has the wrong props, it is useless.
16458 so get rid of it. */
16460 mode_line_proptrans_alist
16461 = Fdelq (aelt
, mode_line_proptrans_alist
);
16463 elt
= Fcopy_sequence (elt
);
16464 Fset_text_properties (make_number (0), Flength (elt
),
16466 /* Add this item to mode_line_proptrans_alist. */
16467 mode_line_proptrans_alist
16468 = Fcons (Fcons (elt
, props
),
16469 mode_line_proptrans_alist
);
16470 /* Truncate mode_line_proptrans_alist
16471 to at most 50 elements. */
16472 tem
= Fnthcdr (make_number (50),
16473 mode_line_proptrans_alist
);
16475 XSETCDR (tem
, Qnil
);
16484 prec
= precision
- n
;
16485 switch (mode_line_target
)
16487 case MODE_LINE_NOPROP
:
16488 case MODE_LINE_TITLE
:
16489 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16491 case MODE_LINE_STRING
:
16492 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16494 case MODE_LINE_DISPLAY
:
16495 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16496 0, prec
, 0, STRING_MULTIBYTE (elt
));
16503 /* Handle the non-literal case. */
16505 while ((precision
<= 0 || n
< precision
)
16506 && SREF (elt
, offset
) != 0
16507 && (mode_line_target
!= MODE_LINE_DISPLAY
16508 || it
->current_x
< it
->last_visible_x
))
16510 int last_offset
= offset
;
16512 /* Advance to end of string or next format specifier. */
16513 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16516 if (offset
- 1 != last_offset
)
16518 int nchars
, nbytes
;
16520 /* Output to end of string or up to '%'. Field width
16521 is length of string. Don't output more than
16522 PRECISION allows us. */
16525 prec
= c_string_width (SDATA (elt
) + last_offset
,
16526 offset
- last_offset
, precision
- n
,
16529 switch (mode_line_target
)
16531 case MODE_LINE_NOPROP
:
16532 case MODE_LINE_TITLE
:
16533 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16535 case MODE_LINE_STRING
:
16537 int bytepos
= last_offset
;
16538 int charpos
= string_byte_to_char (elt
, bytepos
);
16539 int endpos
= (precision
<= 0
16540 ? string_byte_to_char (elt
, offset
)
16541 : charpos
+ nchars
);
16543 n
+= store_mode_line_string (NULL
,
16544 Fsubstring (elt
, make_number (charpos
),
16545 make_number (endpos
)),
16549 case MODE_LINE_DISPLAY
:
16551 int bytepos
= last_offset
;
16552 int charpos
= string_byte_to_char (elt
, bytepos
);
16554 if (precision
<= 0)
16555 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16556 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16558 STRING_MULTIBYTE (elt
));
16563 else /* c == '%' */
16565 int percent_position
= offset
;
16567 /* Get the specified minimum width. Zero means
16570 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16571 field
= field
* 10 + c
- '0';
16573 /* Don't pad beyond the total padding allowed. */
16574 if (field_width
- n
> 0 && field
> field_width
- n
)
16575 field
= field_width
- n
;
16577 /* Note that either PRECISION <= 0 or N < PRECISION. */
16578 prec
= precision
- n
;
16581 n
+= display_mode_element (it
, depth
, field
, prec
,
16582 Vglobal_mode_string
, props
,
16587 int bytepos
, charpos
;
16588 unsigned char *spec
;
16590 bytepos
= percent_position
;
16591 charpos
= (STRING_MULTIBYTE (elt
)
16592 ? string_byte_to_char (elt
, bytepos
)
16596 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16598 switch (mode_line_target
)
16600 case MODE_LINE_NOPROP
:
16601 case MODE_LINE_TITLE
:
16602 n
+= store_mode_line_noprop (spec
, field
, prec
);
16604 case MODE_LINE_STRING
:
16606 int len
= strlen (spec
);
16607 Lisp_Object tem
= make_string (spec
, len
);
16608 props
= Ftext_properties_at (make_number (charpos
), elt
);
16609 /* Should only keep face property in props */
16610 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16613 case MODE_LINE_DISPLAY
:
16615 int nglyphs_before
, nwritten
;
16617 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16618 nwritten
= display_string (spec
, Qnil
, elt
,
16623 /* Assign to the glyphs written above the
16624 string where the `%x' came from, position
16628 struct glyph
*glyph
16629 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16633 for (i
= 0; i
< nwritten
; ++i
)
16635 glyph
[i
].object
= elt
;
16636 glyph
[i
].charpos
= charpos
;
16653 /* A symbol: process the value of the symbol recursively
16654 as if it appeared here directly. Avoid error if symbol void.
16655 Special case: if value of symbol is a string, output the string
16658 register Lisp_Object tem
;
16660 /* If the variable is not marked as risky to set
16661 then its contents are risky to use. */
16662 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16665 tem
= Fboundp (elt
);
16668 tem
= Fsymbol_value (elt
);
16669 /* If value is a string, output that string literally:
16670 don't check for % within it. */
16674 if (!EQ (tem
, elt
))
16676 /* Give up right away for nil or t. */
16686 register Lisp_Object car
, tem
;
16688 /* A cons cell: five distinct cases.
16689 If first element is :eval or :propertize, do something special.
16690 If first element is a string or a cons, process all the elements
16691 and effectively concatenate them.
16692 If first element is a negative number, truncate displaying cdr to
16693 at most that many characters. If positive, pad (with spaces)
16694 to at least that many characters.
16695 If first element is a symbol, process the cadr or caddr recursively
16696 according to whether the symbol's value is non-nil or nil. */
16698 if (EQ (car
, QCeval
))
16700 /* An element of the form (:eval FORM) means evaluate FORM
16701 and use the result as mode line elements. */
16706 if (CONSP (XCDR (elt
)))
16709 spec
= safe_eval (XCAR (XCDR (elt
)));
16710 n
+= display_mode_element (it
, depth
, field_width
- n
,
16711 precision
- n
, spec
, props
,
16715 else if (EQ (car
, QCpropertize
))
16717 /* An element of the form (:propertize ELT PROPS...)
16718 means display ELT but applying properties PROPS. */
16723 if (CONSP (XCDR (elt
)))
16724 n
+= display_mode_element (it
, depth
, field_width
- n
,
16725 precision
- n
, XCAR (XCDR (elt
)),
16726 XCDR (XCDR (elt
)), risky
);
16728 else if (SYMBOLP (car
))
16730 tem
= Fboundp (car
);
16734 /* elt is now the cdr, and we know it is a cons cell.
16735 Use its car if CAR has a non-nil value. */
16738 tem
= Fsymbol_value (car
);
16745 /* Symbol's value is nil (or symbol is unbound)
16746 Get the cddr of the original list
16747 and if possible find the caddr and use that. */
16751 else if (!CONSP (elt
))
16756 else if (INTEGERP (car
))
16758 register int lim
= XINT (car
);
16762 /* Negative int means reduce maximum width. */
16763 if (precision
<= 0)
16766 precision
= min (precision
, -lim
);
16770 /* Padding specified. Don't let it be more than
16771 current maximum. */
16773 lim
= min (precision
, lim
);
16775 /* If that's more padding than already wanted, queue it.
16776 But don't reduce padding already specified even if
16777 that is beyond the current truncation point. */
16778 field_width
= max (lim
, field_width
);
16782 else if (STRINGP (car
) || CONSP (car
))
16784 register int limit
= 50;
16785 /* Limit is to protect against circular lists. */
16788 && (precision
<= 0 || n
< precision
))
16790 n
+= display_mode_element (it
, depth
,
16791 /* Do padding only after the last
16792 element in the list. */
16793 (! CONSP (XCDR (elt
))
16796 precision
- n
, XCAR (elt
),
16806 elt
= build_string ("*invalid*");
16810 /* Pad to FIELD_WIDTH. */
16811 if (field_width
> 0 && n
< field_width
)
16813 switch (mode_line_target
)
16815 case MODE_LINE_NOPROP
:
16816 case MODE_LINE_TITLE
:
16817 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16819 case MODE_LINE_STRING
:
16820 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16822 case MODE_LINE_DISPLAY
:
16823 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16832 /* Store a mode-line string element in mode_line_string_list.
16834 If STRING is non-null, display that C string. Otherwise, the Lisp
16835 string LISP_STRING is displayed.
16837 FIELD_WIDTH is the minimum number of output glyphs to produce.
16838 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16839 with spaces. FIELD_WIDTH <= 0 means don't pad.
16841 PRECISION is the maximum number of characters to output from
16842 STRING. PRECISION <= 0 means don't truncate the string.
16844 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16845 properties to the string.
16847 PROPS are the properties to add to the string.
16848 The mode_line_string_face face property is always added to the string.
16852 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16854 Lisp_Object lisp_string
;
16863 if (string
!= NULL
)
16865 len
= strlen (string
);
16866 if (precision
> 0 && len
> precision
)
16868 lisp_string
= make_string (string
, len
);
16870 props
= mode_line_string_face_prop
;
16871 else if (!NILP (mode_line_string_face
))
16873 Lisp_Object face
= Fplist_get (props
, Qface
);
16874 props
= Fcopy_sequence (props
);
16876 face
= mode_line_string_face
;
16878 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16879 props
= Fplist_put (props
, Qface
, face
);
16881 Fadd_text_properties (make_number (0), make_number (len
),
16882 props
, lisp_string
);
16886 len
= XFASTINT (Flength (lisp_string
));
16887 if (precision
> 0 && len
> precision
)
16890 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16893 if (!NILP (mode_line_string_face
))
16897 props
= Ftext_properties_at (make_number (0), lisp_string
);
16898 face
= Fplist_get (props
, Qface
);
16900 face
= mode_line_string_face
;
16902 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16903 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16905 lisp_string
= Fcopy_sequence (lisp_string
);
16908 Fadd_text_properties (make_number (0), make_number (len
),
16909 props
, lisp_string
);
16914 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16918 if (field_width
> len
)
16920 field_width
-= len
;
16921 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16923 Fadd_text_properties (make_number (0), make_number (field_width
),
16924 props
, lisp_string
);
16925 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16933 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16935 doc
: /* Format a string out of a mode line format specification.
16936 First arg FORMAT specifies the mode line format (see `mode-line-format'
16937 for details) to use.
16939 Optional second arg FACE specifies the face property to put
16940 on all characters for which no face is specified.
16941 t means whatever face the window's mode line currently uses
16942 \(either `mode-line' or `mode-line-inactive', depending).
16943 nil means the default is no face property.
16944 If FACE is an integer, the value string has no text properties.
16946 Optional third and fourth args WINDOW and BUFFER specify the window
16947 and buffer to use as the context for the formatting (defaults
16948 are the selected window and the window's buffer). */)
16949 (format
, face
, window
, buffer
)
16950 Lisp_Object format
, face
, window
, buffer
;
16955 struct buffer
*old_buffer
= NULL
;
16957 int no_props
= INTEGERP (face
);
16958 int count
= SPECPDL_INDEX ();
16960 int string_start
= 0;
16963 window
= selected_window
;
16964 CHECK_WINDOW (window
);
16965 w
= XWINDOW (window
);
16968 buffer
= w
->buffer
;
16969 CHECK_BUFFER (buffer
);
16972 return build_string ("");
16980 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16981 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16985 face_id
= DEFAULT_FACE_ID
;
16987 if (XBUFFER (buffer
) != current_buffer
)
16988 old_buffer
= current_buffer
;
16990 /* Save things including mode_line_proptrans_alist,
16991 and set that to nil so that we don't alter the outer value. */
16992 record_unwind_protect (unwind_format_mode_line
,
16993 format_mode_line_unwind_data (old_buffer
, 1));
16994 mode_line_proptrans_alist
= Qnil
;
16997 set_buffer_internal_1 (XBUFFER (buffer
));
16999 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17003 mode_line_target
= MODE_LINE_NOPROP
;
17004 mode_line_string_face_prop
= Qnil
;
17005 mode_line_string_list
= Qnil
;
17006 string_start
= MODE_LINE_NOPROP_LEN (0);
17010 mode_line_target
= MODE_LINE_STRING
;
17011 mode_line_string_list
= Qnil
;
17012 mode_line_string_face
= face
;
17013 mode_line_string_face_prop
17014 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17017 push_frame_kboard (it
.f
);
17018 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17019 pop_frame_kboard ();
17023 len
= MODE_LINE_NOPROP_LEN (string_start
);
17024 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17028 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17029 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17030 make_string ("", 0));
17033 unbind_to (count
, Qnil
);
17037 /* Write a null-terminated, right justified decimal representation of
17038 the positive integer D to BUF using a minimal field width WIDTH. */
17041 pint2str (buf
, width
, d
)
17042 register char *buf
;
17043 register int width
;
17046 register char *p
= buf
;
17054 *p
++ = d
% 10 + '0';
17059 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17070 /* Write a null-terminated, right justified decimal and "human
17071 readable" representation of the nonnegative integer D to BUF using
17072 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17074 static const char power_letter
[] =
17088 pint2hrstr (buf
, width
, d
)
17093 /* We aim to represent the nonnegative integer D as
17094 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17097 /* -1 means: do not use TENTHS. */
17101 /* Length of QUOTIENT.TENTHS as a string. */
17107 if (1000 <= quotient
)
17109 /* Scale to the appropriate EXPONENT. */
17112 remainder
= quotient
% 1000;
17116 while (1000 <= quotient
);
17118 /* Round to nearest and decide whether to use TENTHS or not. */
17121 tenths
= remainder
/ 100;
17122 if (50 <= remainder
% 100)
17129 if (quotient
== 10)
17137 if (500 <= remainder
)
17139 if (quotient
< 999)
17150 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17151 if (tenths
== -1 && quotient
<= 99)
17158 p
= psuffix
= buf
+ max (width
, length
);
17160 /* Print EXPONENT. */
17162 *psuffix
++ = power_letter
[exponent
];
17165 /* Print TENTHS. */
17168 *--p
= '0' + tenths
;
17172 /* Print QUOTIENT. */
17175 int digit
= quotient
% 10;
17176 *--p
= '0' + digit
;
17178 while ((quotient
/= 10) != 0);
17180 /* Print leading spaces. */
17185 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17186 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17187 type of CODING_SYSTEM. Return updated pointer into BUF. */
17189 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17192 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17193 Lisp_Object coding_system
;
17194 register char *buf
;
17198 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17199 const unsigned char *eol_str
;
17201 /* The EOL conversion we are using. */
17202 Lisp_Object eoltype
;
17204 val
= Fget (coding_system
, Qcoding_system
);
17207 if (!VECTORP (val
)) /* Not yet decided. */
17212 eoltype
= eol_mnemonic_undecided
;
17213 /* Don't mention EOL conversion if it isn't decided. */
17217 Lisp_Object eolvalue
;
17219 eolvalue
= Fget (coding_system
, Qeol_type
);
17222 *buf
++ = XFASTINT (AREF (val
, 1));
17226 /* The EOL conversion that is normal on this system. */
17228 if (NILP (eolvalue
)) /* Not yet decided. */
17229 eoltype
= eol_mnemonic_undecided
;
17230 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17231 eoltype
= eol_mnemonic_undecided
;
17232 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17233 eoltype
= (XFASTINT (eolvalue
) == 0
17234 ? eol_mnemonic_unix
17235 : (XFASTINT (eolvalue
) == 1
17236 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17242 /* Mention the EOL conversion if it is not the usual one. */
17243 if (STRINGP (eoltype
))
17245 eol_str
= SDATA (eoltype
);
17246 eol_str_len
= SBYTES (eoltype
);
17248 else if (INTEGERP (eoltype
)
17249 && CHAR_VALID_P (XINT (eoltype
), 0))
17251 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17252 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17257 eol_str
= invalid_eol_type
;
17258 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17260 bcopy (eol_str
, buf
, eol_str_len
);
17261 buf
+= eol_str_len
;
17267 /* Return a string for the output of a mode line %-spec for window W,
17268 generated by character C. PRECISION >= 0 means don't return a
17269 string longer than that value. FIELD_WIDTH > 0 means pad the
17270 string returned with spaces to that value. Return 1 in *MULTIBYTE
17271 if the result is multibyte text.
17273 Note we operate on the current buffer for most purposes,
17274 the exception being w->base_line_pos. */
17276 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17279 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17282 int field_width
, precision
;
17286 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17287 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17288 struct buffer
*b
= current_buffer
;
17296 if (!NILP (b
->read_only
))
17298 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17303 /* This differs from %* only for a modified read-only buffer. */
17304 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17306 if (!NILP (b
->read_only
))
17311 /* This differs from %* in ignoring read-only-ness. */
17312 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17324 if (command_loop_level
> 5)
17326 p
= decode_mode_spec_buf
;
17327 for (i
= 0; i
< command_loop_level
; i
++)
17330 return decode_mode_spec_buf
;
17338 if (command_loop_level
> 5)
17340 p
= decode_mode_spec_buf
;
17341 for (i
= 0; i
< command_loop_level
; i
++)
17344 return decode_mode_spec_buf
;
17351 /* Let lots_of_dashes be a string of infinite length. */
17352 if (mode_line_target
== MODE_LINE_NOPROP
||
17353 mode_line_target
== MODE_LINE_STRING
)
17355 if (field_width
<= 0
17356 || field_width
> sizeof (lots_of_dashes
))
17358 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17359 decode_mode_spec_buf
[i
] = '-';
17360 decode_mode_spec_buf
[i
] = '\0';
17361 return decode_mode_spec_buf
;
17364 return lots_of_dashes
;
17373 int col
= (int) current_column (); /* iftc */
17374 w
->column_number_displayed
= make_number (col
);
17375 pint2str (decode_mode_spec_buf
, field_width
, col
);
17376 return decode_mode_spec_buf
;
17380 #ifndef SYSTEM_MALLOC
17382 if (NILP (Vmemory_full
))
17385 return "!MEM FULL! ";
17392 /* %F displays the frame name. */
17393 if (!NILP (f
->title
))
17394 return (char *) SDATA (f
->title
);
17395 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17396 return (char *) SDATA (f
->name
);
17405 int size
= ZV
- BEGV
;
17406 pint2str (decode_mode_spec_buf
, field_width
, size
);
17407 return decode_mode_spec_buf
;
17412 int size
= ZV
- BEGV
;
17413 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17414 return decode_mode_spec_buf
;
17419 int startpos
= XMARKER (w
->start
)->charpos
;
17420 int startpos_byte
= marker_byte_position (w
->start
);
17421 int line
, linepos
, linepos_byte
, topline
;
17423 int height
= WINDOW_TOTAL_LINES (w
);
17425 /* If we decided that this buffer isn't suitable for line numbers,
17426 don't forget that too fast. */
17427 if (EQ (w
->base_line_pos
, w
->buffer
))
17429 /* But do forget it, if the window shows a different buffer now. */
17430 else if (BUFFERP (w
->base_line_pos
))
17431 w
->base_line_pos
= Qnil
;
17433 /* If the buffer is very big, don't waste time. */
17434 if (INTEGERP (Vline_number_display_limit
)
17435 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17437 w
->base_line_pos
= Qnil
;
17438 w
->base_line_number
= Qnil
;
17442 if (!NILP (w
->base_line_number
)
17443 && !NILP (w
->base_line_pos
)
17444 && XFASTINT (w
->base_line_pos
) <= startpos
)
17446 line
= XFASTINT (w
->base_line_number
);
17447 linepos
= XFASTINT (w
->base_line_pos
);
17448 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17453 linepos
= BUF_BEGV (b
);
17454 linepos_byte
= BUF_BEGV_BYTE (b
);
17457 /* Count lines from base line to window start position. */
17458 nlines
= display_count_lines (linepos
, linepos_byte
,
17462 topline
= nlines
+ line
;
17464 /* Determine a new base line, if the old one is too close
17465 or too far away, or if we did not have one.
17466 "Too close" means it's plausible a scroll-down would
17467 go back past it. */
17468 if (startpos
== BUF_BEGV (b
))
17470 w
->base_line_number
= make_number (topline
);
17471 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17473 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17474 || linepos
== BUF_BEGV (b
))
17476 int limit
= BUF_BEGV (b
);
17477 int limit_byte
= BUF_BEGV_BYTE (b
);
17479 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17481 if (startpos
- distance
> limit
)
17483 limit
= startpos
- distance
;
17484 limit_byte
= CHAR_TO_BYTE (limit
);
17487 nlines
= display_count_lines (startpos
, startpos_byte
,
17489 - (height
* 2 + 30),
17491 /* If we couldn't find the lines we wanted within
17492 line_number_display_limit_width chars per line,
17493 give up on line numbers for this window. */
17494 if (position
== limit_byte
&& limit
== startpos
- distance
)
17496 w
->base_line_pos
= w
->buffer
;
17497 w
->base_line_number
= Qnil
;
17501 w
->base_line_number
= make_number (topline
- nlines
);
17502 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17505 /* Now count lines from the start pos to point. */
17506 nlines
= display_count_lines (startpos
, startpos_byte
,
17507 PT_BYTE
, PT
, &junk
);
17509 /* Record that we did display the line number. */
17510 line_number_displayed
= 1;
17512 /* Make the string to show. */
17513 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17514 return decode_mode_spec_buf
;
17517 char* p
= decode_mode_spec_buf
;
17518 int pad
= field_width
- 2;
17524 return decode_mode_spec_buf
;
17530 obj
= b
->mode_name
;
17534 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17540 int pos
= marker_position (w
->start
);
17541 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17543 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17545 if (pos
<= BUF_BEGV (b
))
17550 else if (pos
<= BUF_BEGV (b
))
17554 if (total
> 1000000)
17555 /* Do it differently for a large value, to avoid overflow. */
17556 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17558 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17559 /* We can't normally display a 3-digit number,
17560 so get us a 2-digit number that is close. */
17563 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17564 return decode_mode_spec_buf
;
17568 /* Display percentage of size above the bottom of the screen. */
17571 int toppos
= marker_position (w
->start
);
17572 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17573 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17575 if (botpos
>= BUF_ZV (b
))
17577 if (toppos
<= BUF_BEGV (b
))
17584 if (total
> 1000000)
17585 /* Do it differently for a large value, to avoid overflow. */
17586 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17588 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17589 /* We can't normally display a 3-digit number,
17590 so get us a 2-digit number that is close. */
17593 if (toppos
<= BUF_BEGV (b
))
17594 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17596 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17597 return decode_mode_spec_buf
;
17602 /* status of process */
17603 obj
= Fget_buffer_process (Fcurrent_buffer ());
17605 return "no process";
17606 #ifdef subprocesses
17607 obj
= Fsymbol_name (Fprocess_status (obj
));
17611 case 't': /* indicate TEXT or BINARY */
17612 #ifdef MODE_LINE_BINARY_TEXT
17613 return MODE_LINE_BINARY_TEXT (b
);
17619 /* coding-system (not including end-of-line format) */
17621 /* coding-system (including end-of-line type) */
17623 int eol_flag
= (c
== 'Z');
17624 char *p
= decode_mode_spec_buf
;
17626 if (! FRAME_WINDOW_P (f
))
17628 /* No need to mention EOL here--the terminal never needs
17629 to do EOL conversion. */
17630 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17631 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17633 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17636 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17637 #ifdef subprocesses
17638 obj
= Fget_buffer_process (Fcurrent_buffer ());
17639 if (PROCESSP (obj
))
17641 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17643 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17646 #endif /* subprocesses */
17649 return decode_mode_spec_buf
;
17655 *multibyte
= STRING_MULTIBYTE (obj
);
17656 return (char *) SDATA (obj
);
17663 /* Count up to COUNT lines starting from START / START_BYTE.
17664 But don't go beyond LIMIT_BYTE.
17665 Return the number of lines thus found (always nonnegative).
17667 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17670 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17671 int start
, start_byte
, limit_byte
, count
;
17674 register unsigned char *cursor
;
17675 unsigned char *base
;
17677 register int ceiling
;
17678 register unsigned char *ceiling_addr
;
17679 int orig_count
= count
;
17681 /* If we are not in selective display mode,
17682 check only for newlines. */
17683 int selective_display
= (!NILP (current_buffer
->selective_display
)
17684 && !INTEGERP (current_buffer
->selective_display
));
17688 while (start_byte
< limit_byte
)
17690 ceiling
= BUFFER_CEILING_OF (start_byte
);
17691 ceiling
= min (limit_byte
- 1, ceiling
);
17692 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17693 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17696 if (selective_display
)
17697 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17700 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17703 if (cursor
!= ceiling_addr
)
17707 start_byte
+= cursor
- base
+ 1;
17708 *byte_pos_ptr
= start_byte
;
17712 if (++cursor
== ceiling_addr
)
17718 start_byte
+= cursor
- base
;
17723 while (start_byte
> limit_byte
)
17725 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17726 ceiling
= max (limit_byte
, ceiling
);
17727 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17728 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17731 if (selective_display
)
17732 while (--cursor
!= ceiling_addr
17733 && *cursor
!= '\n' && *cursor
!= 015)
17736 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17739 if (cursor
!= ceiling_addr
)
17743 start_byte
+= cursor
- base
+ 1;
17744 *byte_pos_ptr
= start_byte
;
17745 /* When scanning backwards, we should
17746 not count the newline posterior to which we stop. */
17747 return - orig_count
- 1;
17753 /* Here we add 1 to compensate for the last decrement
17754 of CURSOR, which took it past the valid range. */
17755 start_byte
+= cursor
- base
+ 1;
17759 *byte_pos_ptr
= limit_byte
;
17762 return - orig_count
+ count
;
17763 return orig_count
- count
;
17769 /***********************************************************************
17771 ***********************************************************************/
17773 /* Display a NUL-terminated string, starting with index START.
17775 If STRING is non-null, display that C string. Otherwise, the Lisp
17776 string LISP_STRING is displayed.
17778 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17779 FACE_STRING. Display STRING or LISP_STRING with the face at
17780 FACE_STRING_POS in FACE_STRING:
17782 Display the string in the environment given by IT, but use the
17783 standard display table, temporarily.
17785 FIELD_WIDTH is the minimum number of output glyphs to produce.
17786 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17787 with spaces. If STRING has more characters, more than FIELD_WIDTH
17788 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17790 PRECISION is the maximum number of characters to output from
17791 STRING. PRECISION < 0 means don't truncate the string.
17793 This is roughly equivalent to printf format specifiers:
17795 FIELD_WIDTH PRECISION PRINTF
17796 ----------------------------------------
17802 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17803 display them, and < 0 means obey the current buffer's value of
17804 enable_multibyte_characters.
17806 Value is the number of columns displayed. */
17809 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17810 start
, it
, field_width
, precision
, max_x
, multibyte
)
17811 unsigned char *string
;
17812 Lisp_Object lisp_string
;
17813 Lisp_Object face_string
;
17814 int face_string_pos
;
17817 int field_width
, precision
, max_x
;
17820 int hpos_at_start
= it
->hpos
;
17821 int saved_face_id
= it
->face_id
;
17822 struct glyph_row
*row
= it
->glyph_row
;
17824 /* Initialize the iterator IT for iteration over STRING beginning
17825 with index START. */
17826 reseat_to_string (it
, string
, lisp_string
, start
,
17827 precision
, field_width
, multibyte
);
17829 /* If displaying STRING, set up the face of the iterator
17830 from LISP_STRING, if that's given. */
17831 if (STRINGP (face_string
))
17837 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17838 0, it
->region_beg_charpos
,
17839 it
->region_end_charpos
,
17840 &endptr
, it
->base_face_id
, 0);
17841 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17842 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17845 /* Set max_x to the maximum allowed X position. Don't let it go
17846 beyond the right edge of the window. */
17848 max_x
= it
->last_visible_x
;
17850 max_x
= min (max_x
, it
->last_visible_x
);
17852 /* Skip over display elements that are not visible. because IT->w is
17854 if (it
->current_x
< it
->first_visible_x
)
17855 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17856 MOVE_TO_POS
| MOVE_TO_X
);
17858 row
->ascent
= it
->max_ascent
;
17859 row
->height
= it
->max_ascent
+ it
->max_descent
;
17860 row
->phys_ascent
= it
->max_phys_ascent
;
17861 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17862 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17864 /* This condition is for the case that we are called with current_x
17865 past last_visible_x. */
17866 while (it
->current_x
< max_x
)
17868 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17870 /* Get the next display element. */
17871 if (!get_next_display_element (it
))
17874 /* Produce glyphs. */
17875 x_before
= it
->current_x
;
17876 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17877 PRODUCE_GLYPHS (it
);
17879 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17882 while (i
< nglyphs
)
17884 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17886 if (!it
->truncate_lines_p
17887 && x
+ glyph
->pixel_width
> max_x
)
17889 /* End of continued line or max_x reached. */
17890 if (CHAR_GLYPH_PADDING_P (*glyph
))
17892 /* A wide character is unbreakable. */
17893 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17894 it
->current_x
= x_before
;
17898 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17903 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17905 /* Glyph is at least partially visible. */
17907 if (x
< it
->first_visible_x
)
17908 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17912 /* Glyph is off the left margin of the display area.
17913 Should not happen. */
17917 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17918 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17919 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17920 row
->phys_height
= max (row
->phys_height
,
17921 it
->max_phys_ascent
+ it
->max_phys_descent
);
17922 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17923 it
->max_extra_line_spacing
);
17924 x
+= glyph
->pixel_width
;
17928 /* Stop if max_x reached. */
17932 /* Stop at line ends. */
17933 if (ITERATOR_AT_END_OF_LINE_P (it
))
17935 it
->continuation_lines_width
= 0;
17939 set_iterator_to_next (it
, 1);
17941 /* Stop if truncating at the right edge. */
17942 if (it
->truncate_lines_p
17943 && it
->current_x
>= it
->last_visible_x
)
17945 /* Add truncation mark, but don't do it if the line is
17946 truncated at a padding space. */
17947 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17949 if (!FRAME_WINDOW_P (it
->f
))
17953 if (it
->current_x
> it
->last_visible_x
)
17955 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17956 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17958 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17960 row
->used
[TEXT_AREA
] = i
;
17961 produce_special_glyphs (it
, IT_TRUNCATION
);
17964 produce_special_glyphs (it
, IT_TRUNCATION
);
17966 it
->glyph_row
->truncated_on_right_p
= 1;
17972 /* Maybe insert a truncation at the left. */
17973 if (it
->first_visible_x
17974 && IT_CHARPOS (*it
) > 0)
17976 if (!FRAME_WINDOW_P (it
->f
))
17977 insert_left_trunc_glyphs (it
);
17978 it
->glyph_row
->truncated_on_left_p
= 1;
17981 it
->face_id
= saved_face_id
;
17983 /* Value is number of columns displayed. */
17984 return it
->hpos
- hpos_at_start
;
17989 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17990 appears as an element of LIST or as the car of an element of LIST.
17991 If PROPVAL is a list, compare each element against LIST in that
17992 way, and return 1/2 if any element of PROPVAL is found in LIST.
17993 Otherwise return 0. This function cannot quit.
17994 The return value is 2 if the text is invisible but with an ellipsis
17995 and 1 if it's invisible and without an ellipsis. */
17998 invisible_p (propval
, list
)
17999 register Lisp_Object propval
;
18002 register Lisp_Object tail
, proptail
;
18004 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18006 register Lisp_Object tem
;
18008 if (EQ (propval
, tem
))
18010 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18011 return NILP (XCDR (tem
)) ? 1 : 2;
18014 if (CONSP (propval
))
18016 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18018 Lisp_Object propelt
;
18019 propelt
= XCAR (proptail
);
18020 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18022 register Lisp_Object tem
;
18024 if (EQ (propelt
, tem
))
18026 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18027 return NILP (XCDR (tem
)) ? 1 : 2;
18035 /* Calculate a width or height in pixels from a specification using
18036 the following elements:
18039 NUM - a (fractional) multiple of the default font width/height
18040 (NUM) - specifies exactly NUM pixels
18041 UNIT - a fixed number of pixels, see below.
18042 ELEMENT - size of a display element in pixels, see below.
18043 (NUM . SPEC) - equals NUM * SPEC
18044 (+ SPEC SPEC ...) - add pixel values
18045 (- SPEC SPEC ...) - subtract pixel values
18046 (- SPEC) - negate pixel value
18049 INT or FLOAT - a number constant
18050 SYMBOL - use symbol's (buffer local) variable binding.
18053 in - pixels per inch *)
18054 mm - pixels per 1/1000 meter *)
18055 cm - pixels per 1/100 meter *)
18056 width - width of current font in pixels.
18057 height - height of current font in pixels.
18059 *) using the ratio(s) defined in display-pixels-per-inch.
18063 left-fringe - left fringe width in pixels
18064 right-fringe - right fringe width in pixels
18066 left-margin - left margin width in pixels
18067 right-margin - right margin width in pixels
18069 scroll-bar - scroll-bar area width in pixels
18073 Pixels corresponding to 5 inches:
18076 Total width of non-text areas on left side of window (if scroll-bar is on left):
18077 '(space :width (+ left-fringe left-margin scroll-bar))
18079 Align to first text column (in header line):
18080 '(space :align-to 0)
18082 Align to middle of text area minus half the width of variable `my-image'
18083 containing a loaded image:
18084 '(space :align-to (0.5 . (- text my-image)))
18086 Width of left margin minus width of 1 character in the default font:
18087 '(space :width (- left-margin 1))
18089 Width of left margin minus width of 2 characters in the current font:
18090 '(space :width (- left-margin (2 . width)))
18092 Center 1 character over left-margin (in header line):
18093 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18095 Different ways to express width of left fringe plus left margin minus one pixel:
18096 '(space :width (- (+ left-fringe left-margin) (1)))
18097 '(space :width (+ left-fringe left-margin (- (1))))
18098 '(space :width (+ left-fringe left-margin (-1)))
18102 #define NUMVAL(X) \
18103 ((INTEGERP (X) || FLOATP (X)) \
18108 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18113 int width_p
, *align_to
;
18117 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18118 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18121 return OK_PIXELS (0);
18123 if (SYMBOLP (prop
))
18125 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18127 char *unit
= SDATA (SYMBOL_NAME (prop
));
18129 if (unit
[0] == 'i' && unit
[1] == 'n')
18131 else if (unit
[0] == 'm' && unit
[1] == 'm')
18133 else if (unit
[0] == 'c' && unit
[1] == 'm')
18140 #ifdef HAVE_WINDOW_SYSTEM
18141 if (FRAME_WINDOW_P (it
->f
)
18143 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18144 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18146 return OK_PIXELS (ppi
/ pixels
);
18149 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18150 || (CONSP (Vdisplay_pixels_per_inch
)
18152 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18153 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18155 return OK_PIXELS (ppi
/ pixels
);
18161 #ifdef HAVE_WINDOW_SYSTEM
18162 if (EQ (prop
, Qheight
))
18163 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18164 if (EQ (prop
, Qwidth
))
18165 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18167 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18168 return OK_PIXELS (1);
18171 if (EQ (prop
, Qtext
))
18172 return OK_PIXELS (width_p
18173 ? window_box_width (it
->w
, TEXT_AREA
)
18174 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18176 if (align_to
&& *align_to
< 0)
18179 if (EQ (prop
, Qleft
))
18180 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18181 if (EQ (prop
, Qright
))
18182 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18183 if (EQ (prop
, Qcenter
))
18184 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18185 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18186 if (EQ (prop
, Qleft_fringe
))
18187 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18188 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18189 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18190 if (EQ (prop
, Qright_fringe
))
18191 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18192 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18193 : window_box_right_offset (it
->w
, TEXT_AREA
));
18194 if (EQ (prop
, Qleft_margin
))
18195 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18196 if (EQ (prop
, Qright_margin
))
18197 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18198 if (EQ (prop
, Qscroll_bar
))
18199 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18201 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18202 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18203 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18208 if (EQ (prop
, Qleft_fringe
))
18209 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18210 if (EQ (prop
, Qright_fringe
))
18211 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18212 if (EQ (prop
, Qleft_margin
))
18213 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18214 if (EQ (prop
, Qright_margin
))
18215 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18216 if (EQ (prop
, Qscroll_bar
))
18217 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18220 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18223 if (INTEGERP (prop
) || FLOATP (prop
))
18225 int base_unit
= (width_p
18226 ? FRAME_COLUMN_WIDTH (it
->f
)
18227 : FRAME_LINE_HEIGHT (it
->f
));
18228 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18233 Lisp_Object car
= XCAR (prop
);
18234 Lisp_Object cdr
= XCDR (prop
);
18238 #ifdef HAVE_WINDOW_SYSTEM
18239 if (valid_image_p (prop
))
18241 int id
= lookup_image (it
->f
, prop
);
18242 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18244 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18247 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18253 while (CONSP (cdr
))
18255 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18256 font
, width_p
, align_to
))
18259 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18264 if (EQ (car
, Qminus
))
18266 return OK_PIXELS (pixels
);
18269 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18272 if (INTEGERP (car
) || FLOATP (car
))
18275 pixels
= XFLOATINT (car
);
18277 return OK_PIXELS (pixels
);
18278 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18279 font
, width_p
, align_to
))
18280 return OK_PIXELS (pixels
* fact
);
18291 /***********************************************************************
18293 ***********************************************************************/
18295 #ifdef HAVE_WINDOW_SYSTEM
18300 dump_glyph_string (s
)
18301 struct glyph_string
*s
;
18303 fprintf (stderr
, "glyph string\n");
18304 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18305 s
->x
, s
->y
, s
->width
, s
->height
);
18306 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18307 fprintf (stderr
, " hl = %d\n", s
->hl
);
18308 fprintf (stderr
, " left overhang = %d, right = %d\n",
18309 s
->left_overhang
, s
->right_overhang
);
18310 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18311 fprintf (stderr
, " extends to end of line = %d\n",
18312 s
->extends_to_end_of_line_p
);
18313 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18314 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18317 #endif /* GLYPH_DEBUG */
18319 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18320 of XChar2b structures for S; it can't be allocated in
18321 init_glyph_string because it must be allocated via `alloca'. W
18322 is the window on which S is drawn. ROW and AREA are the glyph row
18323 and area within the row from which S is constructed. START is the
18324 index of the first glyph structure covered by S. HL is a
18325 face-override for drawing S. */
18328 #define OPTIONAL_HDC(hdc) hdc,
18329 #define DECLARE_HDC(hdc) HDC hdc;
18330 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18331 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18334 #ifndef OPTIONAL_HDC
18335 #define OPTIONAL_HDC(hdc)
18336 #define DECLARE_HDC(hdc)
18337 #define ALLOCATE_HDC(hdc, f)
18338 #define RELEASE_HDC(hdc, f)
18342 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18343 struct glyph_string
*s
;
18347 struct glyph_row
*row
;
18348 enum glyph_row_area area
;
18350 enum draw_glyphs_face hl
;
18352 bzero (s
, sizeof *s
);
18354 s
->f
= XFRAME (w
->frame
);
18358 s
->display
= FRAME_X_DISPLAY (s
->f
);
18359 s
->window
= FRAME_X_WINDOW (s
->f
);
18360 s
->char2b
= char2b
;
18364 s
->first_glyph
= row
->glyphs
[area
] + start
;
18365 s
->height
= row
->height
;
18366 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18368 /* Display the internal border below the tool-bar window. */
18369 if (WINDOWP (s
->f
->tool_bar_window
)
18370 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18371 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18373 s
->ybase
= s
->y
+ row
->ascent
;
18377 /* Append the list of glyph strings with head H and tail T to the list
18378 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18381 append_glyph_string_lists (head
, tail
, h
, t
)
18382 struct glyph_string
**head
, **tail
;
18383 struct glyph_string
*h
, *t
;
18397 /* Prepend the list of glyph strings with head H and tail T to the
18398 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18402 prepend_glyph_string_lists (head
, tail
, h
, t
)
18403 struct glyph_string
**head
, **tail
;
18404 struct glyph_string
*h
, *t
;
18418 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18419 Set *HEAD and *TAIL to the resulting list. */
18422 append_glyph_string (head
, tail
, s
)
18423 struct glyph_string
**head
, **tail
;
18424 struct glyph_string
*s
;
18426 s
->next
= s
->prev
= NULL
;
18427 append_glyph_string_lists (head
, tail
, s
, s
);
18431 /* Get face and two-byte form of character glyph GLYPH on frame F.
18432 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18433 a pointer to a realized face that is ready for display. */
18435 static INLINE
struct face
*
18436 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18438 struct glyph
*glyph
;
18444 xassert (glyph
->type
== CHAR_GLYPH
);
18445 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18450 if (!glyph
->multibyte_p
)
18452 /* Unibyte case. We don't have to encode, but we have to make
18453 sure to use a face suitable for unibyte. */
18454 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18456 else if (glyph
->u
.ch
< 128
18457 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18459 /* Case of ASCII in a face known to fit ASCII. */
18460 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18464 int c1
, c2
, charset
;
18466 /* Split characters into bytes. If c2 is -1 afterwards, C is
18467 really a one-byte character so that byte1 is zero. */
18468 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18470 STORE_XCHAR2B (char2b
, c1
, c2
);
18472 STORE_XCHAR2B (char2b
, 0, c1
);
18474 /* Maybe encode the character in *CHAR2B. */
18475 if (charset
!= CHARSET_ASCII
)
18477 struct font_info
*font_info
18478 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18481 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18485 /* Make sure X resources of the face are allocated. */
18486 xassert (face
!= NULL
);
18487 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18492 /* Fill glyph string S with composition components specified by S->cmp.
18494 FACES is an array of faces for all components of this composition.
18495 S->gidx is the index of the first component for S.
18497 OVERLAPS non-zero means S should draw the foreground only, and use
18498 its physical height for clipping. See also draw_glyphs.
18500 Value is the index of a component not in S. */
18503 fill_composite_glyph_string (s
, faces
, overlaps
)
18504 struct glyph_string
*s
;
18505 struct face
**faces
;
18512 s
->for_overlaps
= overlaps
;
18514 s
->face
= faces
[s
->gidx
];
18515 s
->font
= s
->face
->font
;
18516 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18518 /* For all glyphs of this composition, starting at the offset
18519 S->gidx, until we reach the end of the definition or encounter a
18520 glyph that requires the different face, add it to S. */
18522 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18525 /* All glyph strings for the same composition has the same width,
18526 i.e. the width set for the first component of the composition. */
18528 s
->width
= s
->first_glyph
->pixel_width
;
18530 /* If the specified font could not be loaded, use the frame's
18531 default font, but record the fact that we couldn't load it in
18532 the glyph string so that we can draw rectangles for the
18533 characters of the glyph string. */
18534 if (s
->font
== NULL
)
18536 s
->font_not_found_p
= 1;
18537 s
->font
= FRAME_FONT (s
->f
);
18540 /* Adjust base line for subscript/superscript text. */
18541 s
->ybase
+= s
->first_glyph
->voffset
;
18543 xassert (s
->face
&& s
->face
->gc
);
18545 /* This glyph string must always be drawn with 16-bit functions. */
18548 return s
->gidx
+ s
->nchars
;
18552 /* Fill glyph string S from a sequence of character glyphs.
18554 FACE_ID is the face id of the string. START is the index of the
18555 first glyph to consider, END is the index of the last + 1.
18556 OVERLAPS non-zero means S should draw the foreground only, and use
18557 its physical height for clipping. See also draw_glyphs.
18559 Value is the index of the first glyph not in S. */
18562 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18563 struct glyph_string
*s
;
18565 int start
, end
, overlaps
;
18567 struct glyph
*glyph
, *last
;
18569 int glyph_not_available_p
;
18571 xassert (s
->f
== XFRAME (s
->w
->frame
));
18572 xassert (s
->nchars
== 0);
18573 xassert (start
>= 0 && end
> start
);
18575 s
->for_overlaps
= overlaps
,
18576 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18577 last
= s
->row
->glyphs
[s
->area
] + end
;
18578 voffset
= glyph
->voffset
;
18580 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18582 while (glyph
< last
18583 && glyph
->type
== CHAR_GLYPH
18584 && glyph
->voffset
== voffset
18585 /* Same face id implies same font, nowadays. */
18586 && glyph
->face_id
== face_id
18587 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18591 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18592 s
->char2b
+ s
->nchars
,
18594 s
->two_byte_p
= two_byte_p
;
18596 xassert (s
->nchars
<= end
- start
);
18597 s
->width
+= glyph
->pixel_width
;
18601 s
->font
= s
->face
->font
;
18602 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18604 /* If the specified font could not be loaded, use the frame's font,
18605 but record the fact that we couldn't load it in
18606 S->font_not_found_p so that we can draw rectangles for the
18607 characters of the glyph string. */
18608 if (s
->font
== NULL
|| glyph_not_available_p
)
18610 s
->font_not_found_p
= 1;
18611 s
->font
= FRAME_FONT (s
->f
);
18614 /* Adjust base line for subscript/superscript text. */
18615 s
->ybase
+= voffset
;
18617 xassert (s
->face
&& s
->face
->gc
);
18618 return glyph
- s
->row
->glyphs
[s
->area
];
18622 /* Fill glyph string S from image glyph S->first_glyph. */
18625 fill_image_glyph_string (s
)
18626 struct glyph_string
*s
;
18628 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18629 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18631 s
->slice
= s
->first_glyph
->slice
;
18632 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18633 s
->font
= s
->face
->font
;
18634 s
->width
= s
->first_glyph
->pixel_width
;
18636 /* Adjust base line for subscript/superscript text. */
18637 s
->ybase
+= s
->first_glyph
->voffset
;
18641 /* Fill glyph string S from a sequence of stretch glyphs.
18643 ROW is the glyph row in which the glyphs are found, AREA is the
18644 area within the row. START is the index of the first glyph to
18645 consider, END is the index of the last + 1.
18647 Value is the index of the first glyph not in S. */
18650 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18651 struct glyph_string
*s
;
18652 struct glyph_row
*row
;
18653 enum glyph_row_area area
;
18656 struct glyph
*glyph
, *last
;
18657 int voffset
, face_id
;
18659 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18661 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18662 last
= s
->row
->glyphs
[s
->area
] + end
;
18663 face_id
= glyph
->face_id
;
18664 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18665 s
->font
= s
->face
->font
;
18666 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18667 s
->width
= glyph
->pixel_width
;
18668 voffset
= glyph
->voffset
;
18672 && glyph
->type
== STRETCH_GLYPH
18673 && glyph
->voffset
== voffset
18674 && glyph
->face_id
== face_id
);
18676 s
->width
+= glyph
->pixel_width
;
18678 /* Adjust base line for subscript/superscript text. */
18679 s
->ybase
+= voffset
;
18681 /* The case that face->gc == 0 is handled when drawing the glyph
18682 string by calling PREPARE_FACE_FOR_DISPLAY. */
18684 return glyph
- s
->row
->glyphs
[s
->area
];
18689 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18690 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18691 assumed to be zero. */
18694 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18695 struct glyph
*glyph
;
18699 *left
= *right
= 0;
18701 if (glyph
->type
== CHAR_GLYPH
)
18705 struct font_info
*font_info
;
18709 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18711 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18712 if (font
/* ++KFS: Should this be font_info ? */
18713 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18715 if (pcm
->rbearing
> pcm
->width
)
18716 *right
= pcm
->rbearing
- pcm
->width
;
18717 if (pcm
->lbearing
< 0)
18718 *left
= -pcm
->lbearing
;
18724 /* Return the index of the first glyph preceding glyph string S that
18725 is overwritten by S because of S's left overhang. Value is -1
18726 if no glyphs are overwritten. */
18729 left_overwritten (s
)
18730 struct glyph_string
*s
;
18734 if (s
->left_overhang
)
18737 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18738 int first
= s
->first_glyph
- glyphs
;
18740 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18741 x
-= glyphs
[i
].pixel_width
;
18752 /* Return the index of the first glyph preceding glyph string S that
18753 is overwriting S because of its right overhang. Value is -1 if no
18754 glyph in front of S overwrites S. */
18757 left_overwriting (s
)
18758 struct glyph_string
*s
;
18761 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18762 int first
= s
->first_glyph
- glyphs
;
18766 for (i
= first
- 1; i
>= 0; --i
)
18769 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18772 x
-= glyphs
[i
].pixel_width
;
18779 /* Return the index of the last glyph following glyph string S that is
18780 not overwritten by S because of S's right overhang. Value is -1 if
18781 no such glyph is found. */
18784 right_overwritten (s
)
18785 struct glyph_string
*s
;
18789 if (s
->right_overhang
)
18792 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18793 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18794 int end
= s
->row
->used
[s
->area
];
18796 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18797 x
+= glyphs
[i
].pixel_width
;
18806 /* Return the index of the last glyph following glyph string S that
18807 overwrites S because of its left overhang. Value is negative
18808 if no such glyph is found. */
18811 right_overwriting (s
)
18812 struct glyph_string
*s
;
18815 int end
= s
->row
->used
[s
->area
];
18816 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18817 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18821 for (i
= first
; i
< end
; ++i
)
18824 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18827 x
+= glyphs
[i
].pixel_width
;
18834 /* Get face and two-byte form of character C in face FACE_ID on frame
18835 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18836 means we want to display multibyte text. DISPLAY_P non-zero means
18837 make sure that X resources for the face returned are allocated.
18838 Value is a pointer to a realized face that is ready for display if
18839 DISPLAY_P is non-zero. */
18841 static INLINE
struct face
*
18842 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18846 int multibyte_p
, display_p
;
18848 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18852 /* Unibyte case. We don't have to encode, but we have to make
18853 sure to use a face suitable for unibyte. */
18854 STORE_XCHAR2B (char2b
, 0, c
);
18855 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18856 face
= FACE_FROM_ID (f
, face_id
);
18858 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18860 /* Case of ASCII in a face known to fit ASCII. */
18861 STORE_XCHAR2B (char2b
, 0, c
);
18865 int c1
, c2
, charset
;
18867 /* Split characters into bytes. If c2 is -1 afterwards, C is
18868 really a one-byte character so that byte1 is zero. */
18869 SPLIT_CHAR (c
, charset
, c1
, c2
);
18871 STORE_XCHAR2B (char2b
, c1
, c2
);
18873 STORE_XCHAR2B (char2b
, 0, c1
);
18875 /* Maybe encode the character in *CHAR2B. */
18876 if (face
->font
!= NULL
)
18878 struct font_info
*font_info
18879 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18881 rif
->encode_char (c
, char2b
, font_info
, 0);
18885 /* Make sure X resources of the face are allocated. */
18886 #ifdef HAVE_X_WINDOWS
18890 xassert (face
!= NULL
);
18891 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18898 /* Set background width of glyph string S. START is the index of the
18899 first glyph following S. LAST_X is the right-most x-position + 1
18900 in the drawing area. */
18903 set_glyph_string_background_width (s
, start
, last_x
)
18904 struct glyph_string
*s
;
18908 /* If the face of this glyph string has to be drawn to the end of
18909 the drawing area, set S->extends_to_end_of_line_p. */
18911 if (start
== s
->row
->used
[s
->area
]
18912 && s
->area
== TEXT_AREA
18913 && ((s
->row
->fill_line_p
18914 && (s
->hl
== DRAW_NORMAL_TEXT
18915 || s
->hl
== DRAW_IMAGE_RAISED
18916 || s
->hl
== DRAW_IMAGE_SUNKEN
))
18917 || s
->hl
== DRAW_MOUSE_FACE
))
18918 s
->extends_to_end_of_line_p
= 1;
18920 /* If S extends its face to the end of the line, set its
18921 background_width to the distance to the right edge of the drawing
18923 if (s
->extends_to_end_of_line_p
)
18924 s
->background_width
= last_x
- s
->x
+ 1;
18926 s
->background_width
= s
->width
;
18930 /* Compute overhangs and x-positions for glyph string S and its
18931 predecessors, or successors. X is the starting x-position for S.
18932 BACKWARD_P non-zero means process predecessors. */
18935 compute_overhangs_and_x (s
, x
, backward_p
)
18936 struct glyph_string
*s
;
18944 if (rif
->compute_glyph_string_overhangs
)
18945 rif
->compute_glyph_string_overhangs (s
);
18955 if (rif
->compute_glyph_string_overhangs
)
18956 rif
->compute_glyph_string_overhangs (s
);
18966 /* The following macros are only called from draw_glyphs below.
18967 They reference the following parameters of that function directly:
18968 `w', `row', `area', and `overlap_p'
18969 as well as the following local variables:
18970 `s', `f', and `hdc' (in W32) */
18973 /* On W32, silently add local `hdc' variable to argument list of
18974 init_glyph_string. */
18975 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18976 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18978 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18979 init_glyph_string (s, char2b, w, row, area, start, hl)
18982 /* Add a glyph string for a stretch glyph to the list of strings
18983 between HEAD and TAIL. START is the index of the stretch glyph in
18984 row area AREA of glyph row ROW. END is the index of the last glyph
18985 in that glyph row area. X is the current output position assigned
18986 to the new glyph string constructed. HL overrides that face of the
18987 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18988 is the right-most x-position of the drawing area. */
18990 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18991 and below -- keep them on one line. */
18992 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18995 s = (struct glyph_string *) alloca (sizeof *s); \
18996 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18997 START = fill_stretch_glyph_string (s, row, area, START, END); \
18998 append_glyph_string (&HEAD, &TAIL, s); \
19004 /* Add a glyph string for an image glyph to the list of strings
19005 between HEAD and TAIL. START is the index of the image glyph in
19006 row area AREA of glyph row ROW. END is the index of the last glyph
19007 in that glyph row area. X is the current output position assigned
19008 to the new glyph string constructed. HL overrides that face of the
19009 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19010 is the right-most x-position of the drawing area. */
19012 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19015 s = (struct glyph_string *) alloca (sizeof *s); \
19016 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19017 fill_image_glyph_string (s); \
19018 append_glyph_string (&HEAD, &TAIL, s); \
19025 /* Add a glyph string for a sequence of character glyphs to the list
19026 of strings between HEAD and TAIL. START is the index of the first
19027 glyph in row area AREA of glyph row ROW that is part of the new
19028 glyph string. END is the index of the last glyph in that glyph row
19029 area. X is the current output position assigned to the new glyph
19030 string constructed. HL overrides that face of the glyph; e.g. it
19031 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19032 right-most x-position of the drawing area. */
19034 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19040 c = (row)->glyphs[area][START].u.ch; \
19041 face_id = (row)->glyphs[area][START].face_id; \
19043 s = (struct glyph_string *) alloca (sizeof *s); \
19044 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19045 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19046 append_glyph_string (&HEAD, &TAIL, s); \
19048 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19053 /* Add a glyph string for a composite sequence to the list of strings
19054 between HEAD and TAIL. START is the index of the first glyph in
19055 row area AREA of glyph row ROW that is part of the new glyph
19056 string. END is the index of the last glyph in that glyph row area.
19057 X is the current output position assigned to the new glyph string
19058 constructed. HL overrides that face of the glyph; e.g. it is
19059 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19060 x-position of the drawing area. */
19062 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19064 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19065 int face_id = (row)->glyphs[area][START].face_id; \
19066 struct face *base_face = FACE_FROM_ID (f, face_id); \
19067 struct composition *cmp = composition_table[cmp_id]; \
19068 int glyph_len = cmp->glyph_len; \
19070 struct face **faces; \
19071 struct glyph_string *first_s = NULL; \
19074 base_face = base_face->ascii_face; \
19075 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19076 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19077 /* At first, fill in `char2b' and `faces'. */ \
19078 for (n = 0; n < glyph_len; n++) \
19080 int c = COMPOSITION_GLYPH (cmp, n); \
19081 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19082 faces[n] = FACE_FROM_ID (f, this_face_id); \
19083 get_char_face_and_encoding (f, c, this_face_id, \
19084 char2b + n, 1, 1); \
19087 /* Make glyph_strings for each glyph sequence that is drawable by \
19088 the same face, and append them to HEAD/TAIL. */ \
19089 for (n = 0; n < cmp->glyph_len;) \
19091 s = (struct glyph_string *) alloca (sizeof *s); \
19092 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19093 append_glyph_string (&(HEAD), &(TAIL), s); \
19101 n = fill_composite_glyph_string (s, faces, overlaps); \
19109 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19110 of AREA of glyph row ROW on window W between indices START and END.
19111 HL overrides the face for drawing glyph strings, e.g. it is
19112 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19113 x-positions of the drawing area.
19115 This is an ugly monster macro construct because we must use alloca
19116 to allocate glyph strings (because draw_glyphs can be called
19117 asynchronously). */
19119 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19122 HEAD = TAIL = NULL; \
19123 while (START < END) \
19125 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19126 switch (first_glyph->type) \
19129 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19133 case COMPOSITE_GLYPH: \
19134 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19138 case STRETCH_GLYPH: \
19139 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19143 case IMAGE_GLYPH: \
19144 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19152 set_glyph_string_background_width (s, START, LAST_X); \
19159 /* Draw glyphs between START and END in AREA of ROW on window W,
19160 starting at x-position X. X is relative to AREA in W. HL is a
19161 face-override with the following meaning:
19163 DRAW_NORMAL_TEXT draw normally
19164 DRAW_CURSOR draw in cursor face
19165 DRAW_MOUSE_FACE draw in mouse face.
19166 DRAW_INVERSE_VIDEO draw in mode line face
19167 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19168 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19170 If OVERLAPS is non-zero, draw only the foreground of characters and
19171 clip to the physical height of ROW. Non-zero value also defines
19172 the overlapping part to be drawn:
19174 OVERLAPS_PRED overlap with preceding rows
19175 OVERLAPS_SUCC overlap with succeeding rows
19176 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19177 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19179 Value is the x-position reached, relative to AREA of W. */
19182 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19185 struct glyph_row
*row
;
19186 enum glyph_row_area area
;
19188 enum draw_glyphs_face hl
;
19191 struct glyph_string
*head
, *tail
;
19192 struct glyph_string
*s
;
19193 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19194 int last_x
, area_width
;
19197 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19200 ALLOCATE_HDC (hdc
, f
);
19202 /* Let's rather be paranoid than getting a SEGV. */
19203 end
= min (end
, row
->used
[area
]);
19204 start
= max (0, start
);
19205 start
= min (end
, start
);
19207 /* Translate X to frame coordinates. Set last_x to the right
19208 end of the drawing area. */
19209 if (row
->full_width_p
)
19211 /* X is relative to the left edge of W, without scroll bars
19213 x
+= WINDOW_LEFT_EDGE_X (w
);
19214 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19218 int area_left
= window_box_left (w
, area
);
19220 area_width
= window_box_width (w
, area
);
19221 last_x
= area_left
+ area_width
;
19224 /* Build a doubly-linked list of glyph_string structures between
19225 head and tail from what we have to draw. Note that the macro
19226 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19227 the reason we use a separate variable `i'. */
19229 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19231 x_reached
= tail
->x
+ tail
->background_width
;
19235 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19236 the row, redraw some glyphs in front or following the glyph
19237 strings built above. */
19238 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19241 struct glyph_string
*h
, *t
;
19243 /* Compute overhangs for all glyph strings. */
19244 if (rif
->compute_glyph_string_overhangs
)
19245 for (s
= head
; s
; s
= s
->next
)
19246 rif
->compute_glyph_string_overhangs (s
);
19248 /* Prepend glyph strings for glyphs in front of the first glyph
19249 string that are overwritten because of the first glyph
19250 string's left overhang. The background of all strings
19251 prepended must be drawn because the first glyph string
19253 i
= left_overwritten (head
);
19257 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19258 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19260 compute_overhangs_and_x (t
, head
->x
, 1);
19261 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19265 /* Prepend glyph strings for glyphs in front of the first glyph
19266 string that overwrite that glyph string because of their
19267 right overhang. For these strings, only the foreground must
19268 be drawn, because it draws over the glyph string at `head'.
19269 The background must not be drawn because this would overwrite
19270 right overhangs of preceding glyphs for which no glyph
19272 i
= left_overwriting (head
);
19276 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19277 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19278 for (s
= h
; s
; s
= s
->next
)
19279 s
->background_filled_p
= 1;
19280 compute_overhangs_and_x (t
, head
->x
, 1);
19281 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19284 /* Append glyphs strings for glyphs following the last glyph
19285 string tail that are overwritten by tail. The background of
19286 these strings has to be drawn because tail's foreground draws
19288 i
= right_overwritten (tail
);
19291 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19292 DRAW_NORMAL_TEXT
, x
, last_x
);
19293 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19294 append_glyph_string_lists (&head
, &tail
, h
, t
);
19298 /* Append glyph strings for glyphs following the last glyph
19299 string tail that overwrite tail. The foreground of such
19300 glyphs has to be drawn because it writes into the background
19301 of tail. The background must not be drawn because it could
19302 paint over the foreground of following glyphs. */
19303 i
= right_overwriting (tail
);
19307 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19308 DRAW_NORMAL_TEXT
, x
, last_x
);
19309 for (s
= h
; s
; s
= s
->next
)
19310 s
->background_filled_p
= 1;
19311 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19312 append_glyph_string_lists (&head
, &tail
, h
, t
);
19314 if (clip_head
|| clip_tail
)
19315 for (s
= head
; s
; s
= s
->next
)
19317 s
->clip_head
= clip_head
;
19318 s
->clip_tail
= clip_tail
;
19322 /* Draw all strings. */
19323 for (s
= head
; s
; s
= s
->next
)
19324 rif
->draw_glyph_string (s
);
19326 if (area
== TEXT_AREA
19327 && !row
->full_width_p
19328 /* When drawing overlapping rows, only the glyph strings'
19329 foreground is drawn, which doesn't erase a cursor
19333 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19334 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19335 : (tail
? tail
->x
+ tail
->background_width
: x
));
19337 int text_left
= window_box_left (w
, TEXT_AREA
);
19341 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19342 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19345 /* Value is the x-position up to which drawn, relative to AREA of W.
19346 This doesn't include parts drawn because of overhangs. */
19347 if (row
->full_width_p
)
19348 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19350 x_reached
-= window_box_left (w
, area
);
19352 RELEASE_HDC (hdc
, f
);
19357 /* Expand row matrix if too narrow. Don't expand if area
19360 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19362 if (!fonts_changed_p \
19363 && (it->glyph_row->glyphs[area] \
19364 < it->glyph_row->glyphs[area + 1])) \
19366 it->w->ncols_scale_factor++; \
19367 fonts_changed_p = 1; \
19371 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19372 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19378 struct glyph
*glyph
;
19379 enum glyph_row_area area
= it
->area
;
19381 xassert (it
->glyph_row
);
19382 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19384 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19385 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19387 glyph
->charpos
= CHARPOS (it
->position
);
19388 glyph
->object
= it
->object
;
19389 glyph
->pixel_width
= it
->pixel_width
;
19390 glyph
->ascent
= it
->ascent
;
19391 glyph
->descent
= it
->descent
;
19392 glyph
->voffset
= it
->voffset
;
19393 glyph
->type
= CHAR_GLYPH
;
19394 glyph
->multibyte_p
= it
->multibyte_p
;
19395 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19396 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19397 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19398 || it
->phys_descent
> it
->descent
);
19399 glyph
->padding_p
= 0;
19400 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19401 glyph
->face_id
= it
->face_id
;
19402 glyph
->u
.ch
= it
->char_to_display
;
19403 glyph
->slice
= null_glyph_slice
;
19404 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19405 ++it
->glyph_row
->used
[area
];
19408 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19411 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19412 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19415 append_composite_glyph (it
)
19418 struct glyph
*glyph
;
19419 enum glyph_row_area area
= it
->area
;
19421 xassert (it
->glyph_row
);
19423 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19424 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19426 glyph
->charpos
= CHARPOS (it
->position
);
19427 glyph
->object
= it
->object
;
19428 glyph
->pixel_width
= it
->pixel_width
;
19429 glyph
->ascent
= it
->ascent
;
19430 glyph
->descent
= it
->descent
;
19431 glyph
->voffset
= it
->voffset
;
19432 glyph
->type
= COMPOSITE_GLYPH
;
19433 glyph
->multibyte_p
= it
->multibyte_p
;
19434 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19435 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19436 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19437 || it
->phys_descent
> it
->descent
);
19438 glyph
->padding_p
= 0;
19439 glyph
->glyph_not_available_p
= 0;
19440 glyph
->face_id
= it
->face_id
;
19441 glyph
->u
.cmp_id
= it
->cmp_id
;
19442 glyph
->slice
= null_glyph_slice
;
19443 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19444 ++it
->glyph_row
->used
[area
];
19447 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19451 /* Change IT->ascent and IT->height according to the setting of
19455 take_vertical_position_into_account (it
)
19460 if (it
->voffset
< 0)
19461 /* Increase the ascent so that we can display the text higher
19463 it
->ascent
-= it
->voffset
;
19465 /* Increase the descent so that we can display the text lower
19467 it
->descent
+= it
->voffset
;
19472 /* Produce glyphs/get display metrics for the image IT is loaded with.
19473 See the description of struct display_iterator in dispextern.h for
19474 an overview of struct display_iterator. */
19477 produce_image_glyph (it
)
19483 struct glyph_slice slice
;
19485 xassert (it
->what
== IT_IMAGE
);
19487 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19489 /* Make sure X resources of the face is loaded. */
19490 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19492 if (it
->image_id
< 0)
19494 /* Fringe bitmap. */
19495 it
->ascent
= it
->phys_ascent
= 0;
19496 it
->descent
= it
->phys_descent
= 0;
19497 it
->pixel_width
= 0;
19502 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19504 /* Make sure X resources of the image is loaded. */
19505 prepare_image_for_display (it
->f
, img
);
19507 slice
.x
= slice
.y
= 0;
19508 slice
.width
= img
->width
;
19509 slice
.height
= img
->height
;
19511 if (INTEGERP (it
->slice
.x
))
19512 slice
.x
= XINT (it
->slice
.x
);
19513 else if (FLOATP (it
->slice
.x
))
19514 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19516 if (INTEGERP (it
->slice
.y
))
19517 slice
.y
= XINT (it
->slice
.y
);
19518 else if (FLOATP (it
->slice
.y
))
19519 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19521 if (INTEGERP (it
->slice
.width
))
19522 slice
.width
= XINT (it
->slice
.width
);
19523 else if (FLOATP (it
->slice
.width
))
19524 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19526 if (INTEGERP (it
->slice
.height
))
19527 slice
.height
= XINT (it
->slice
.height
);
19528 else if (FLOATP (it
->slice
.height
))
19529 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19531 if (slice
.x
>= img
->width
)
19532 slice
.x
= img
->width
;
19533 if (slice
.y
>= img
->height
)
19534 slice
.y
= img
->height
;
19535 if (slice
.x
+ slice
.width
>= img
->width
)
19536 slice
.width
= img
->width
- slice
.x
;
19537 if (slice
.y
+ slice
.height
> img
->height
)
19538 slice
.height
= img
->height
- slice
.y
;
19540 if (slice
.width
== 0 || slice
.height
== 0)
19543 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19545 it
->descent
= slice
.height
- glyph_ascent
;
19547 it
->descent
+= img
->vmargin
;
19548 if (slice
.y
+ slice
.height
== img
->height
)
19549 it
->descent
+= img
->vmargin
;
19550 it
->phys_descent
= it
->descent
;
19552 it
->pixel_width
= slice
.width
;
19554 it
->pixel_width
+= img
->hmargin
;
19555 if (slice
.x
+ slice
.width
== img
->width
)
19556 it
->pixel_width
+= img
->hmargin
;
19558 /* It's quite possible for images to have an ascent greater than
19559 their height, so don't get confused in that case. */
19560 if (it
->descent
< 0)
19563 #if 0 /* this breaks image tiling */
19564 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19565 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19566 if (face_ascent
> it
->ascent
)
19567 it
->ascent
= it
->phys_ascent
= face_ascent
;
19572 if (face
->box
!= FACE_NO_BOX
)
19574 if (face
->box_line_width
> 0)
19577 it
->ascent
+= face
->box_line_width
;
19578 if (slice
.y
+ slice
.height
== img
->height
)
19579 it
->descent
+= face
->box_line_width
;
19582 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19583 it
->pixel_width
+= abs (face
->box_line_width
);
19584 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19585 it
->pixel_width
+= abs (face
->box_line_width
);
19588 take_vertical_position_into_account (it
);
19592 struct glyph
*glyph
;
19593 enum glyph_row_area area
= it
->area
;
19595 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19596 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19598 glyph
->charpos
= CHARPOS (it
->position
);
19599 glyph
->object
= it
->object
;
19600 glyph
->pixel_width
= it
->pixel_width
;
19601 glyph
->ascent
= glyph_ascent
;
19602 glyph
->descent
= it
->descent
;
19603 glyph
->voffset
= it
->voffset
;
19604 glyph
->type
= IMAGE_GLYPH
;
19605 glyph
->multibyte_p
= it
->multibyte_p
;
19606 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19607 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19608 glyph
->overlaps_vertically_p
= 0;
19609 glyph
->padding_p
= 0;
19610 glyph
->glyph_not_available_p
= 0;
19611 glyph
->face_id
= it
->face_id
;
19612 glyph
->u
.img_id
= img
->id
;
19613 glyph
->slice
= slice
;
19614 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19615 ++it
->glyph_row
->used
[area
];
19618 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19623 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19624 of the glyph, WIDTH and HEIGHT are the width and height of the
19625 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19628 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19630 Lisp_Object object
;
19634 struct glyph
*glyph
;
19635 enum glyph_row_area area
= it
->area
;
19637 xassert (ascent
>= 0 && ascent
<= height
);
19639 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19640 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19642 glyph
->charpos
= CHARPOS (it
->position
);
19643 glyph
->object
= object
;
19644 glyph
->pixel_width
= width
;
19645 glyph
->ascent
= ascent
;
19646 glyph
->descent
= height
- ascent
;
19647 glyph
->voffset
= it
->voffset
;
19648 glyph
->type
= STRETCH_GLYPH
;
19649 glyph
->multibyte_p
= it
->multibyte_p
;
19650 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19651 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19652 glyph
->overlaps_vertically_p
= 0;
19653 glyph
->padding_p
= 0;
19654 glyph
->glyph_not_available_p
= 0;
19655 glyph
->face_id
= it
->face_id
;
19656 glyph
->u
.stretch
.ascent
= ascent
;
19657 glyph
->u
.stretch
.height
= height
;
19658 glyph
->slice
= null_glyph_slice
;
19659 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19660 ++it
->glyph_row
->used
[area
];
19663 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19667 /* Produce a stretch glyph for iterator IT. IT->object is the value
19668 of the glyph property displayed. The value must be a list
19669 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19672 1. `:width WIDTH' specifies that the space should be WIDTH *
19673 canonical char width wide. WIDTH may be an integer or floating
19676 2. `:relative-width FACTOR' specifies that the width of the stretch
19677 should be computed from the width of the first character having the
19678 `glyph' property, and should be FACTOR times that width.
19680 3. `:align-to HPOS' specifies that the space should be wide enough
19681 to reach HPOS, a value in canonical character units.
19683 Exactly one of the above pairs must be present.
19685 4. `:height HEIGHT' specifies that the height of the stretch produced
19686 should be HEIGHT, measured in canonical character units.
19688 5. `:relative-height FACTOR' specifies that the height of the
19689 stretch should be FACTOR times the height of the characters having
19690 the glyph property.
19692 Either none or exactly one of 4 or 5 must be present.
19694 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19695 of the stretch should be used for the ascent of the stretch.
19696 ASCENT must be in the range 0 <= ASCENT <= 100. */
19699 produce_stretch_glyph (it
)
19702 /* (space :width WIDTH :height HEIGHT ...) */
19703 Lisp_Object prop
, plist
;
19704 int width
= 0, height
= 0, align_to
= -1;
19705 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19708 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19709 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19711 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19713 /* List should start with `space'. */
19714 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19715 plist
= XCDR (it
->object
);
19717 /* Compute the width of the stretch. */
19718 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19719 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19721 /* Absolute width `:width WIDTH' specified and valid. */
19722 zero_width_ok_p
= 1;
19725 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19728 /* Relative width `:relative-width FACTOR' specified and valid.
19729 Compute the width of the characters having the `glyph'
19732 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19735 if (it
->multibyte_p
)
19737 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19738 - IT_BYTEPOS (*it
));
19739 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19742 it2
.c
= *p
, it2
.len
= 1;
19744 it2
.glyph_row
= NULL
;
19745 it2
.what
= IT_CHARACTER
;
19746 x_produce_glyphs (&it2
);
19747 width
= NUMVAL (prop
) * it2
.pixel_width
;
19749 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19750 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19752 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19753 align_to
= (align_to
< 0
19755 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19756 else if (align_to
< 0)
19757 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19758 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19759 zero_width_ok_p
= 1;
19762 /* Nothing specified -> width defaults to canonical char width. */
19763 width
= FRAME_COLUMN_WIDTH (it
->f
);
19765 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19768 /* Compute height. */
19769 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19770 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19773 zero_height_ok_p
= 1;
19775 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19777 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19779 height
= FONT_HEIGHT (font
);
19781 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19784 /* Compute percentage of height used for ascent. If
19785 `:ascent ASCENT' is present and valid, use that. Otherwise,
19786 derive the ascent from the font in use. */
19787 if (prop
= Fplist_get (plist
, QCascent
),
19788 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19789 ascent
= height
* NUMVAL (prop
) / 100.0;
19790 else if (!NILP (prop
)
19791 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19792 ascent
= min (max (0, (int)tem
), height
);
19794 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19796 if (width
> 0 && !it
->truncate_lines_p
19797 && it
->current_x
+ width
> it
->last_visible_x
)
19798 width
= it
->last_visible_x
- it
->current_x
- 1;
19800 if (width
> 0 && height
> 0 && it
->glyph_row
)
19802 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19803 if (!STRINGP (object
))
19804 object
= it
->w
->buffer
;
19805 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19808 it
->pixel_width
= width
;
19809 it
->ascent
= it
->phys_ascent
= ascent
;
19810 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19811 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19813 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19815 if (face
->box_line_width
> 0)
19817 it
->ascent
+= face
->box_line_width
;
19818 it
->descent
+= face
->box_line_width
;
19821 if (it
->start_of_box_run_p
)
19822 it
->pixel_width
+= abs (face
->box_line_width
);
19823 if (it
->end_of_box_run_p
)
19824 it
->pixel_width
+= abs (face
->box_line_width
);
19827 take_vertical_position_into_account (it
);
19830 /* Get line-height and line-spacing property at point.
19831 If line-height has format (HEIGHT TOTAL), return TOTAL
19832 in TOTAL_HEIGHT. */
19835 get_line_height_property (it
, prop
)
19839 Lisp_Object position
;
19841 if (STRINGP (it
->object
))
19842 position
= make_number (IT_STRING_CHARPOS (*it
));
19843 else if (BUFFERP (it
->object
))
19844 position
= make_number (IT_CHARPOS (*it
));
19848 return Fget_char_property (position
, prop
, it
->object
);
19851 /* Calculate line-height and line-spacing properties.
19852 An integer value specifies explicit pixel value.
19853 A float value specifies relative value to current face height.
19854 A cons (float . face-name) specifies relative value to
19855 height of specified face font.
19857 Returns height in pixels, or nil. */
19861 calc_line_height_property (it
, val
, font
, boff
, override
)
19865 int boff
, override
;
19867 Lisp_Object face_name
= Qnil
;
19868 int ascent
, descent
, height
;
19870 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19875 face_name
= XCAR (val
);
19877 if (!NUMBERP (val
))
19878 val
= make_number (1);
19879 if (NILP (face_name
))
19881 height
= it
->ascent
+ it
->descent
;
19886 if (NILP (face_name
))
19888 font
= FRAME_FONT (it
->f
);
19889 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19891 else if (EQ (face_name
, Qt
))
19899 struct font_info
*font_info
;
19901 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19903 return make_number (-1);
19905 face
= FACE_FROM_ID (it
->f
, face_id
);
19908 return make_number (-1);
19910 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19911 boff
= font_info
->baseline_offset
;
19912 if (font_info
->vertical_centering
)
19913 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19916 ascent
= FONT_BASE (font
) + boff
;
19917 descent
= FONT_DESCENT (font
) - boff
;
19921 it
->override_ascent
= ascent
;
19922 it
->override_descent
= descent
;
19923 it
->override_boff
= boff
;
19926 height
= ascent
+ descent
;
19930 height
= (int)(XFLOAT_DATA (val
) * height
);
19931 else if (INTEGERP (val
))
19932 height
*= XINT (val
);
19934 return make_number (height
);
19939 Produce glyphs/get display metrics for the display element IT is
19940 loaded with. See the description of struct it in dispextern.h
19941 for an overview of struct it. */
19944 x_produce_glyphs (it
)
19947 int extra_line_spacing
= it
->extra_line_spacing
;
19949 it
->glyph_not_available_p
= 0;
19951 if (it
->what
== IT_CHARACTER
)
19955 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19957 int font_not_found_p
;
19958 struct font_info
*font_info
;
19959 int boff
; /* baseline offset */
19960 /* We may change it->multibyte_p upon unibyte<->multibyte
19961 conversion. So, save the current value now and restore it
19964 Note: It seems that we don't have to record multibyte_p in
19965 struct glyph because the character code itself tells if or
19966 not the character is multibyte. Thus, in the future, we must
19967 consider eliminating the field `multibyte_p' in the struct
19969 int saved_multibyte_p
= it
->multibyte_p
;
19971 /* Maybe translate single-byte characters to multibyte, or the
19973 it
->char_to_display
= it
->c
;
19974 if (!ASCII_BYTE_P (it
->c
))
19976 if (unibyte_display_via_language_environment
19977 && SINGLE_BYTE_CHAR_P (it
->c
)
19979 || !NILP (Vnonascii_translation_table
)))
19981 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19982 it
->multibyte_p
= 1;
19983 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19984 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19986 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19987 && !it
->multibyte_p
)
19989 it
->multibyte_p
= 1;
19990 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19991 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19995 /* Get font to use. Encode IT->char_to_display. */
19996 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19997 &char2b
, it
->multibyte_p
, 0);
20000 /* When no suitable font found, use the default font. */
20001 font_not_found_p
= font
== NULL
;
20002 if (font_not_found_p
)
20004 font
= FRAME_FONT (it
->f
);
20005 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20010 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20011 boff
= font_info
->baseline_offset
;
20012 if (font_info
->vertical_centering
)
20013 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20016 if (it
->char_to_display
>= ' '
20017 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20019 /* Either unibyte or ASCII. */
20024 pcm
= rif
->per_char_metric (font
, &char2b
,
20025 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20027 if (it
->override_ascent
>= 0)
20029 it
->ascent
= it
->override_ascent
;
20030 it
->descent
= it
->override_descent
;
20031 boff
= it
->override_boff
;
20035 it
->ascent
= FONT_BASE (font
) + boff
;
20036 it
->descent
= FONT_DESCENT (font
) - boff
;
20041 it
->phys_ascent
= pcm
->ascent
+ boff
;
20042 it
->phys_descent
= pcm
->descent
- boff
;
20043 it
->pixel_width
= pcm
->width
;
20047 it
->glyph_not_available_p
= 1;
20048 it
->phys_ascent
= it
->ascent
;
20049 it
->phys_descent
= it
->descent
;
20050 it
->pixel_width
= FONT_WIDTH (font
);
20053 if (it
->constrain_row_ascent_descent_p
)
20055 if (it
->descent
> it
->max_descent
)
20057 it
->ascent
+= it
->descent
- it
->max_descent
;
20058 it
->descent
= it
->max_descent
;
20060 if (it
->ascent
> it
->max_ascent
)
20062 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20063 it
->ascent
= it
->max_ascent
;
20065 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20066 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20067 extra_line_spacing
= 0;
20070 /* If this is a space inside a region of text with
20071 `space-width' property, change its width. */
20072 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20074 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20076 /* If face has a box, add the box thickness to the character
20077 height. If character has a box line to the left and/or
20078 right, add the box line width to the character's width. */
20079 if (face
->box
!= FACE_NO_BOX
)
20081 int thick
= face
->box_line_width
;
20085 it
->ascent
+= thick
;
20086 it
->descent
+= thick
;
20091 if (it
->start_of_box_run_p
)
20092 it
->pixel_width
+= thick
;
20093 if (it
->end_of_box_run_p
)
20094 it
->pixel_width
+= thick
;
20097 /* If face has an overline, add the height of the overline
20098 (1 pixel) and a 1 pixel margin to the character height. */
20099 if (face
->overline_p
)
20102 if (it
->constrain_row_ascent_descent_p
)
20104 if (it
->ascent
> it
->max_ascent
)
20105 it
->ascent
= it
->max_ascent
;
20106 if (it
->descent
> it
->max_descent
)
20107 it
->descent
= it
->max_descent
;
20110 take_vertical_position_into_account (it
);
20112 /* If we have to actually produce glyphs, do it. */
20117 /* Translate a space with a `space-width' property
20118 into a stretch glyph. */
20119 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20120 / FONT_HEIGHT (font
));
20121 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20122 it
->ascent
+ it
->descent
, ascent
);
20127 /* If characters with lbearing or rbearing are displayed
20128 in this line, record that fact in a flag of the
20129 glyph row. This is used to optimize X output code. */
20130 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20131 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20134 else if (it
->char_to_display
== '\n')
20136 /* A newline has no width but we need the height of the line.
20137 But if previous part of the line set a height, don't
20138 increase that height */
20140 Lisp_Object height
;
20141 Lisp_Object total_height
= Qnil
;
20143 it
->override_ascent
= -1;
20144 it
->pixel_width
= 0;
20147 height
= get_line_height_property(it
, Qline_height
);
20148 /* Split (line-height total-height) list */
20150 && CONSP (XCDR (height
))
20151 && NILP (XCDR (XCDR (height
))))
20153 total_height
= XCAR (XCDR (height
));
20154 height
= XCAR (height
);
20156 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20158 if (it
->override_ascent
>= 0)
20160 it
->ascent
= it
->override_ascent
;
20161 it
->descent
= it
->override_descent
;
20162 boff
= it
->override_boff
;
20166 it
->ascent
= FONT_BASE (font
) + boff
;
20167 it
->descent
= FONT_DESCENT (font
) - boff
;
20170 if (EQ (height
, Qt
))
20172 if (it
->descent
> it
->max_descent
)
20174 it
->ascent
+= it
->descent
- it
->max_descent
;
20175 it
->descent
= it
->max_descent
;
20177 if (it
->ascent
> it
->max_ascent
)
20179 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20180 it
->ascent
= it
->max_ascent
;
20182 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20183 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20184 it
->constrain_row_ascent_descent_p
= 1;
20185 extra_line_spacing
= 0;
20189 Lisp_Object spacing
;
20191 it
->phys_ascent
= it
->ascent
;
20192 it
->phys_descent
= it
->descent
;
20194 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20195 && face
->box
!= FACE_NO_BOX
20196 && face
->box_line_width
> 0)
20198 it
->ascent
+= face
->box_line_width
;
20199 it
->descent
+= face
->box_line_width
;
20202 && XINT (height
) > it
->ascent
+ it
->descent
)
20203 it
->ascent
= XINT (height
) - it
->descent
;
20205 if (!NILP (total_height
))
20206 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20209 spacing
= get_line_height_property(it
, Qline_spacing
);
20210 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20212 if (INTEGERP (spacing
))
20214 extra_line_spacing
= XINT (spacing
);
20215 if (!NILP (total_height
))
20216 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20220 else if (it
->char_to_display
== '\t')
20222 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20223 int x
= it
->current_x
+ it
->continuation_lines_width
;
20224 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20226 /* If the distance from the current position to the next tab
20227 stop is less than a space character width, use the
20228 tab stop after that. */
20229 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20230 next_tab_x
+= tab_width
;
20232 it
->pixel_width
= next_tab_x
- x
;
20234 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20235 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20239 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20240 it
->ascent
+ it
->descent
, it
->ascent
);
20245 /* A multi-byte character. Assume that the display width of the
20246 character is the width of the character multiplied by the
20247 width of the font. */
20249 /* If we found a font, this font should give us the right
20250 metrics. If we didn't find a font, use the frame's
20251 default font and calculate the width of the character
20252 from the charset width; this is what old redisplay code
20255 pcm
= rif
->per_char_metric (font
, &char2b
,
20256 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20258 if (font_not_found_p
|| !pcm
)
20260 int charset
= CHAR_CHARSET (it
->char_to_display
);
20262 it
->glyph_not_available_p
= 1;
20263 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20264 * CHARSET_WIDTH (charset
));
20265 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20266 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20270 it
->pixel_width
= pcm
->width
;
20271 it
->phys_ascent
= pcm
->ascent
+ boff
;
20272 it
->phys_descent
= pcm
->descent
- boff
;
20274 && (pcm
->lbearing
< 0
20275 || pcm
->rbearing
> pcm
->width
))
20276 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20279 it
->ascent
= FONT_BASE (font
) + boff
;
20280 it
->descent
= FONT_DESCENT (font
) - boff
;
20281 if (face
->box
!= FACE_NO_BOX
)
20283 int thick
= face
->box_line_width
;
20287 it
->ascent
+= thick
;
20288 it
->descent
+= thick
;
20293 if (it
->start_of_box_run_p
)
20294 it
->pixel_width
+= thick
;
20295 if (it
->end_of_box_run_p
)
20296 it
->pixel_width
+= thick
;
20299 /* If face has an overline, add the height of the overline
20300 (1 pixel) and a 1 pixel margin to the character height. */
20301 if (face
->overline_p
)
20304 take_vertical_position_into_account (it
);
20309 it
->multibyte_p
= saved_multibyte_p
;
20311 else if (it
->what
== IT_COMPOSITION
)
20313 /* Note: A composition is represented as one glyph in the
20314 glyph matrix. There are no padding glyphs. */
20317 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20319 int font_not_found_p
;
20320 struct font_info
*font_info
;
20321 int boff
; /* baseline offset */
20322 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20324 /* Maybe translate single-byte characters to multibyte. */
20325 it
->char_to_display
= it
->c
;
20326 if (unibyte_display_via_language_environment
20327 && SINGLE_BYTE_CHAR_P (it
->c
)
20330 && !NILP (Vnonascii_translation_table
))))
20332 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20335 /* Get face and font to use. Encode IT->char_to_display. */
20336 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20337 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20338 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20339 &char2b
, it
->multibyte_p
, 0);
20342 /* When no suitable font found, use the default font. */
20343 font_not_found_p
= font
== NULL
;
20344 if (font_not_found_p
)
20346 font
= FRAME_FONT (it
->f
);
20347 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20352 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20353 boff
= font_info
->baseline_offset
;
20354 if (font_info
->vertical_centering
)
20355 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20358 /* There are no padding glyphs, so there is only one glyph to
20359 produce for the composition. Important is that pixel_width,
20360 ascent and descent are the values of what is drawn by
20361 draw_glyphs (i.e. the values of the overall glyphs composed). */
20364 /* If we have not yet calculated pixel size data of glyphs of
20365 the composition for the current face font, calculate them
20366 now. Theoretically, we have to check all fonts for the
20367 glyphs, but that requires much time and memory space. So,
20368 here we check only the font of the first glyph. This leads
20369 to incorrect display very rarely, and C-l (recenter) can
20370 correct the display anyway. */
20371 if (cmp
->font
!= (void *) font
)
20373 /* Ascent and descent of the font of the first character of
20374 this composition (adjusted by baseline offset). Ascent
20375 and descent of overall glyphs should not be less than
20376 them respectively. */
20377 int font_ascent
= FONT_BASE (font
) + boff
;
20378 int font_descent
= FONT_DESCENT (font
) - boff
;
20379 /* Bounding box of the overall glyphs. */
20380 int leftmost
, rightmost
, lowest
, highest
;
20381 int i
, width
, ascent
, descent
;
20383 cmp
->font
= (void *) font
;
20385 /* Initialize the bounding box. */
20387 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20388 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20390 width
= pcm
->width
;
20391 ascent
= pcm
->ascent
;
20392 descent
= pcm
->descent
;
20396 width
= FONT_WIDTH (font
);
20397 ascent
= FONT_BASE (font
);
20398 descent
= FONT_DESCENT (font
);
20402 lowest
= - descent
+ boff
;
20403 highest
= ascent
+ boff
;
20407 && font_info
->default_ascent
20408 && CHAR_TABLE_P (Vuse_default_ascent
)
20409 && !NILP (Faref (Vuse_default_ascent
,
20410 make_number (it
->char_to_display
))))
20411 highest
= font_info
->default_ascent
+ boff
;
20413 /* Draw the first glyph at the normal position. It may be
20414 shifted to right later if some other glyphs are drawn at
20416 cmp
->offsets
[0] = 0;
20417 cmp
->offsets
[1] = boff
;
20419 /* Set cmp->offsets for the remaining glyphs. */
20420 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20422 int left
, right
, btm
, top
;
20423 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20424 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20426 face
= FACE_FROM_ID (it
->f
, face_id
);
20427 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20428 &char2b
, it
->multibyte_p
, 0);
20432 font
= FRAME_FONT (it
->f
);
20433 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20439 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20440 boff
= font_info
->baseline_offset
;
20441 if (font_info
->vertical_centering
)
20442 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20446 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20447 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20449 width
= pcm
->width
;
20450 ascent
= pcm
->ascent
;
20451 descent
= pcm
->descent
;
20455 width
= FONT_WIDTH (font
);
20460 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20462 /* Relative composition with or without
20463 alternate chars. */
20464 left
= (leftmost
+ rightmost
- width
) / 2;
20465 btm
= - descent
+ boff
;
20466 if (font_info
&& font_info
->relative_compose
20467 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20468 || NILP (Faref (Vignore_relative_composition
,
20469 make_number (ch
)))))
20472 if (- descent
>= font_info
->relative_compose
)
20473 /* One extra pixel between two glyphs. */
20475 else if (ascent
<= 0)
20476 /* One extra pixel between two glyphs. */
20477 btm
= lowest
- 1 - ascent
- descent
;
20482 /* A composition rule is specified by an integer
20483 value that encodes global and new reference
20484 points (GREF and NREF). GREF and NREF are
20485 specified by numbers as below:
20487 0---1---2 -- ascent
20491 9--10--11 -- center
20493 ---3---4---5--- baseline
20495 6---7---8 -- descent
20497 int rule
= COMPOSITION_RULE (cmp
, i
);
20498 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20500 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20501 grefx
= gref
% 3, nrefx
= nref
% 3;
20502 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20505 + grefx
* (rightmost
- leftmost
) / 2
20506 - nrefx
* width
/ 2);
20507 btm
= ((grefy
== 0 ? highest
20509 : grefy
== 2 ? lowest
20510 : (highest
+ lowest
) / 2)
20511 - (nrefy
== 0 ? ascent
+ descent
20512 : nrefy
== 1 ? descent
- boff
20514 : (ascent
+ descent
) / 2));
20517 cmp
->offsets
[i
* 2] = left
;
20518 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20520 /* Update the bounding box of the overall glyphs. */
20521 right
= left
+ width
;
20522 top
= btm
+ descent
+ ascent
;
20523 if (left
< leftmost
)
20525 if (right
> rightmost
)
20533 /* If there are glyphs whose x-offsets are negative,
20534 shift all glyphs to the right and make all x-offsets
20538 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20539 cmp
->offsets
[i
* 2] -= leftmost
;
20540 rightmost
-= leftmost
;
20543 cmp
->pixel_width
= rightmost
;
20544 cmp
->ascent
= highest
;
20545 cmp
->descent
= - lowest
;
20546 if (cmp
->ascent
< font_ascent
)
20547 cmp
->ascent
= font_ascent
;
20548 if (cmp
->descent
< font_descent
)
20549 cmp
->descent
= font_descent
;
20552 it
->pixel_width
= cmp
->pixel_width
;
20553 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20554 it
->descent
= it
->phys_descent
= cmp
->descent
;
20556 if (face
->box
!= FACE_NO_BOX
)
20558 int thick
= face
->box_line_width
;
20562 it
->ascent
+= thick
;
20563 it
->descent
+= thick
;
20568 if (it
->start_of_box_run_p
)
20569 it
->pixel_width
+= thick
;
20570 if (it
->end_of_box_run_p
)
20571 it
->pixel_width
+= thick
;
20574 /* If face has an overline, add the height of the overline
20575 (1 pixel) and a 1 pixel margin to the character height. */
20576 if (face
->overline_p
)
20579 take_vertical_position_into_account (it
);
20582 append_composite_glyph (it
);
20584 else if (it
->what
== IT_IMAGE
)
20585 produce_image_glyph (it
);
20586 else if (it
->what
== IT_STRETCH
)
20587 produce_stretch_glyph (it
);
20589 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20590 because this isn't true for images with `:ascent 100'. */
20591 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20592 if (it
->area
== TEXT_AREA
)
20593 it
->current_x
+= it
->pixel_width
;
20595 if (extra_line_spacing
> 0)
20597 it
->descent
+= extra_line_spacing
;
20598 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20599 it
->max_extra_line_spacing
= extra_line_spacing
;
20602 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20603 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20604 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20605 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20609 Output LEN glyphs starting at START at the nominal cursor position.
20610 Advance the nominal cursor over the text. The global variable
20611 updated_window contains the window being updated, updated_row is
20612 the glyph row being updated, and updated_area is the area of that
20613 row being updated. */
20616 x_write_glyphs (start
, len
)
20617 struct glyph
*start
;
20622 xassert (updated_window
&& updated_row
);
20625 /* Write glyphs. */
20627 hpos
= start
- updated_row
->glyphs
[updated_area
];
20628 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20629 updated_row
, updated_area
,
20631 DRAW_NORMAL_TEXT
, 0);
20633 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20634 if (updated_area
== TEXT_AREA
20635 && updated_window
->phys_cursor_on_p
20636 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20637 && updated_window
->phys_cursor
.hpos
>= hpos
20638 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20639 updated_window
->phys_cursor_on_p
= 0;
20643 /* Advance the output cursor. */
20644 output_cursor
.hpos
+= len
;
20645 output_cursor
.x
= x
;
20650 Insert LEN glyphs from START at the nominal cursor position. */
20653 x_insert_glyphs (start
, len
)
20654 struct glyph
*start
;
20659 int line_height
, shift_by_width
, shifted_region_width
;
20660 struct glyph_row
*row
;
20661 struct glyph
*glyph
;
20662 int frame_x
, frame_y
, hpos
;
20664 xassert (updated_window
&& updated_row
);
20666 w
= updated_window
;
20667 f
= XFRAME (WINDOW_FRAME (w
));
20669 /* Get the height of the line we are in. */
20671 line_height
= row
->height
;
20673 /* Get the width of the glyphs to insert. */
20674 shift_by_width
= 0;
20675 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20676 shift_by_width
+= glyph
->pixel_width
;
20678 /* Get the width of the region to shift right. */
20679 shifted_region_width
= (window_box_width (w
, updated_area
)
20684 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20685 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20687 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20688 line_height
, shift_by_width
);
20690 /* Write the glyphs. */
20691 hpos
= start
- row
->glyphs
[updated_area
];
20692 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20694 DRAW_NORMAL_TEXT
, 0);
20696 /* Advance the output cursor. */
20697 output_cursor
.hpos
+= len
;
20698 output_cursor
.x
+= shift_by_width
;
20704 Erase the current text line from the nominal cursor position
20705 (inclusive) to pixel column TO_X (exclusive). The idea is that
20706 everything from TO_X onward is already erased.
20708 TO_X is a pixel position relative to updated_area of
20709 updated_window. TO_X == -1 means clear to the end of this area. */
20712 x_clear_end_of_line (to_x
)
20716 struct window
*w
= updated_window
;
20717 int max_x
, min_y
, max_y
;
20718 int from_x
, from_y
, to_y
;
20720 xassert (updated_window
&& updated_row
);
20721 f
= XFRAME (w
->frame
);
20723 if (updated_row
->full_width_p
)
20724 max_x
= WINDOW_TOTAL_WIDTH (w
);
20726 max_x
= window_box_width (w
, updated_area
);
20727 max_y
= window_text_bottom_y (w
);
20729 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20730 of window. For TO_X > 0, truncate to end of drawing area. */
20736 to_x
= min (to_x
, max_x
);
20738 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20740 /* Notice if the cursor will be cleared by this operation. */
20741 if (!updated_row
->full_width_p
)
20742 notice_overwritten_cursor (w
, updated_area
,
20743 output_cursor
.x
, -1,
20745 MATRIX_ROW_BOTTOM_Y (updated_row
));
20747 from_x
= output_cursor
.x
;
20749 /* Translate to frame coordinates. */
20750 if (updated_row
->full_width_p
)
20752 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20753 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20757 int area_left
= window_box_left (w
, updated_area
);
20758 from_x
+= area_left
;
20762 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20763 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20764 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20766 /* Prevent inadvertently clearing to end of the X window. */
20767 if (to_x
> from_x
&& to_y
> from_y
)
20770 rif
->clear_frame_area (f
, from_x
, from_y
,
20771 to_x
- from_x
, to_y
- from_y
);
20776 #endif /* HAVE_WINDOW_SYSTEM */
20780 /***********************************************************************
20782 ***********************************************************************/
20784 /* Value is the internal representation of the specified cursor type
20785 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20786 of the bar cursor. */
20788 static enum text_cursor_kinds
20789 get_specified_cursor_type (arg
, width
)
20793 enum text_cursor_kinds type
;
20798 if (EQ (arg
, Qbox
))
20799 return FILLED_BOX_CURSOR
;
20801 if (EQ (arg
, Qhollow
))
20802 return HOLLOW_BOX_CURSOR
;
20804 if (EQ (arg
, Qbar
))
20811 && EQ (XCAR (arg
), Qbar
)
20812 && INTEGERP (XCDR (arg
))
20813 && XINT (XCDR (arg
)) >= 0)
20815 *width
= XINT (XCDR (arg
));
20819 if (EQ (arg
, Qhbar
))
20822 return HBAR_CURSOR
;
20826 && EQ (XCAR (arg
), Qhbar
)
20827 && INTEGERP (XCDR (arg
))
20828 && XINT (XCDR (arg
)) >= 0)
20830 *width
= XINT (XCDR (arg
));
20831 return HBAR_CURSOR
;
20834 /* Treat anything unknown as "hollow box cursor".
20835 It was bad to signal an error; people have trouble fixing
20836 .Xdefaults with Emacs, when it has something bad in it. */
20837 type
= HOLLOW_BOX_CURSOR
;
20842 /* Set the default cursor types for specified frame. */
20844 set_frame_cursor_types (f
, arg
)
20851 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20852 FRAME_CURSOR_WIDTH (f
) = width
;
20854 /* By default, set up the blink-off state depending on the on-state. */
20856 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20859 FRAME_BLINK_OFF_CURSOR (f
)
20860 = get_specified_cursor_type (XCDR (tem
), &width
);
20861 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20864 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20868 /* Return the cursor we want to be displayed in window W. Return
20869 width of bar/hbar cursor through WIDTH arg. Return with
20870 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20871 (i.e. if the `system caret' should track this cursor).
20873 In a mini-buffer window, we want the cursor only to appear if we
20874 are reading input from this window. For the selected window, we
20875 want the cursor type given by the frame parameter or buffer local
20876 setting of cursor-type. If explicitly marked off, draw no cursor.
20877 In all other cases, we want a hollow box cursor. */
20879 static enum text_cursor_kinds
20880 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20882 struct glyph
*glyph
;
20884 int *active_cursor
;
20886 struct frame
*f
= XFRAME (w
->frame
);
20887 struct buffer
*b
= XBUFFER (w
->buffer
);
20888 int cursor_type
= DEFAULT_CURSOR
;
20889 Lisp_Object alt_cursor
;
20890 int non_selected
= 0;
20892 *active_cursor
= 1;
20895 if (cursor_in_echo_area
20896 && FRAME_HAS_MINIBUF_P (f
)
20897 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20899 if (w
== XWINDOW (echo_area_window
))
20901 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
20903 *width
= FRAME_CURSOR_WIDTH (f
);
20904 return FRAME_DESIRED_CURSOR (f
);
20907 return get_specified_cursor_type (b
->cursor_type
, width
);
20910 *active_cursor
= 0;
20914 /* Nonselected window or nonselected frame. */
20915 else if (w
!= XWINDOW (f
->selected_window
)
20916 #ifdef HAVE_WINDOW_SYSTEM
20917 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20921 *active_cursor
= 0;
20923 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20929 /* Never display a cursor in a window in which cursor-type is nil. */
20930 if (NILP (b
->cursor_type
))
20933 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20936 alt_cursor
= b
->cursor_in_non_selected_windows
;
20937 return get_specified_cursor_type (alt_cursor
, width
);
20940 /* Get the normal cursor type for this window. */
20941 if (EQ (b
->cursor_type
, Qt
))
20943 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20944 *width
= FRAME_CURSOR_WIDTH (f
);
20947 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20949 /* Use normal cursor if not blinked off. */
20950 if (!w
->cursor_off_p
)
20952 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20953 if (cursor_type
== FILLED_BOX_CURSOR
)
20954 cursor_type
= HOLLOW_BOX_CURSOR
;
20956 return cursor_type
;
20959 /* Cursor is blinked off, so determine how to "toggle" it. */
20961 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20962 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20963 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20965 /* Then see if frame has specified a specific blink off cursor type. */
20966 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20968 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20969 return FRAME_BLINK_OFF_CURSOR (f
);
20973 /* Some people liked having a permanently visible blinking cursor,
20974 while others had very strong opinions against it. So it was
20975 decided to remove it. KFS 2003-09-03 */
20977 /* Finally perform built-in cursor blinking:
20978 filled box <-> hollow box
20979 wide [h]bar <-> narrow [h]bar
20980 narrow [h]bar <-> no cursor
20981 other type <-> no cursor */
20983 if (cursor_type
== FILLED_BOX_CURSOR
)
20984 return HOLLOW_BOX_CURSOR
;
20986 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20989 return cursor_type
;
20997 #ifdef HAVE_WINDOW_SYSTEM
20999 /* Notice when the text cursor of window W has been completely
21000 overwritten by a drawing operation that outputs glyphs in AREA
21001 starting at X0 and ending at X1 in the line starting at Y0 and
21002 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21003 the rest of the line after X0 has been written. Y coordinates
21004 are window-relative. */
21007 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21009 enum glyph_row_area area
;
21010 int x0
, y0
, x1
, y1
;
21012 int cx0
, cx1
, cy0
, cy1
;
21013 struct glyph_row
*row
;
21015 if (!w
->phys_cursor_on_p
)
21017 if (area
!= TEXT_AREA
)
21020 if (w
->phys_cursor
.vpos
< 0
21021 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21022 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21023 !(row
->enabled_p
&& row
->displays_text_p
)))
21026 if (row
->cursor_in_fringe_p
)
21028 row
->cursor_in_fringe_p
= 0;
21029 draw_fringe_bitmap (w
, row
, 0);
21030 w
->phys_cursor_on_p
= 0;
21034 cx0
= w
->phys_cursor
.x
;
21035 cx1
= cx0
+ w
->phys_cursor_width
;
21036 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21039 /* The cursor image will be completely removed from the
21040 screen if the output area intersects the cursor area in
21041 y-direction. When we draw in [y0 y1[, and some part of
21042 the cursor is at y < y0, that part must have been drawn
21043 before. When scrolling, the cursor is erased before
21044 actually scrolling, so we don't come here. When not
21045 scrolling, the rows above the old cursor row must have
21046 changed, and in this case these rows must have written
21047 over the cursor image.
21049 Likewise if part of the cursor is below y1, with the
21050 exception of the cursor being in the first blank row at
21051 the buffer and window end because update_text_area
21052 doesn't draw that row. (Except when it does, but
21053 that's handled in update_text_area.) */
21055 cy0
= w
->phys_cursor
.y
;
21056 cy1
= cy0
+ w
->phys_cursor_height
;
21057 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21060 w
->phys_cursor_on_p
= 0;
21063 #endif /* HAVE_WINDOW_SYSTEM */
21066 /************************************************************************
21068 ************************************************************************/
21070 #ifdef HAVE_WINDOW_SYSTEM
21073 Fix the display of area AREA of overlapping row ROW in window W
21074 with respect to the overlapping part OVERLAPS. */
21077 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21079 struct glyph_row
*row
;
21080 enum glyph_row_area area
;
21088 for (i
= 0; i
< row
->used
[area
];)
21090 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21092 int start
= i
, start_x
= x
;
21096 x
+= row
->glyphs
[area
][i
].pixel_width
;
21099 while (i
< row
->used
[area
]
21100 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21102 draw_glyphs (w
, start_x
, row
, area
,
21104 DRAW_NORMAL_TEXT
, overlaps
);
21108 x
+= row
->glyphs
[area
][i
].pixel_width
;
21118 Draw the cursor glyph of window W in glyph row ROW. See the
21119 comment of draw_glyphs for the meaning of HL. */
21122 draw_phys_cursor_glyph (w
, row
, hl
)
21124 struct glyph_row
*row
;
21125 enum draw_glyphs_face hl
;
21127 /* If cursor hpos is out of bounds, don't draw garbage. This can
21128 happen in mini-buffer windows when switching between echo area
21129 glyphs and mini-buffer. */
21130 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21132 int on_p
= w
->phys_cursor_on_p
;
21134 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21135 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21137 w
->phys_cursor_on_p
= on_p
;
21139 if (hl
== DRAW_CURSOR
)
21140 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21141 /* When we erase the cursor, and ROW is overlapped by other
21142 rows, make sure that these overlapping parts of other rows
21144 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21146 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21148 if (row
> w
->current_matrix
->rows
21149 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21150 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21151 OVERLAPS_ERASED_CURSOR
);
21153 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21154 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21155 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21156 OVERLAPS_ERASED_CURSOR
);
21163 Erase the image of a cursor of window W from the screen. */
21166 erase_phys_cursor (w
)
21169 struct frame
*f
= XFRAME (w
->frame
);
21170 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21171 int hpos
= w
->phys_cursor
.hpos
;
21172 int vpos
= w
->phys_cursor
.vpos
;
21173 int mouse_face_here_p
= 0;
21174 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21175 struct glyph_row
*cursor_row
;
21176 struct glyph
*cursor_glyph
;
21177 enum draw_glyphs_face hl
;
21179 /* No cursor displayed or row invalidated => nothing to do on the
21181 if (w
->phys_cursor_type
== NO_CURSOR
)
21182 goto mark_cursor_off
;
21184 /* VPOS >= active_glyphs->nrows means that window has been resized.
21185 Don't bother to erase the cursor. */
21186 if (vpos
>= active_glyphs
->nrows
)
21187 goto mark_cursor_off
;
21189 /* If row containing cursor is marked invalid, there is nothing we
21191 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21192 if (!cursor_row
->enabled_p
)
21193 goto mark_cursor_off
;
21195 /* If line spacing is > 0, old cursor may only be partially visible in
21196 window after split-window. So adjust visible height. */
21197 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21198 window_text_bottom_y (w
) - cursor_row
->y
);
21200 /* If row is completely invisible, don't attempt to delete a cursor which
21201 isn't there. This can happen if cursor is at top of a window, and
21202 we switch to a buffer with a header line in that window. */
21203 if (cursor_row
->visible_height
<= 0)
21204 goto mark_cursor_off
;
21206 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21207 if (cursor_row
->cursor_in_fringe_p
)
21209 cursor_row
->cursor_in_fringe_p
= 0;
21210 draw_fringe_bitmap (w
, cursor_row
, 0);
21211 goto mark_cursor_off
;
21214 /* This can happen when the new row is shorter than the old one.
21215 In this case, either draw_glyphs or clear_end_of_line
21216 should have cleared the cursor. Note that we wouldn't be
21217 able to erase the cursor in this case because we don't have a
21218 cursor glyph at hand. */
21219 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21220 goto mark_cursor_off
;
21222 /* If the cursor is in the mouse face area, redisplay that when
21223 we clear the cursor. */
21224 if (! NILP (dpyinfo
->mouse_face_window
)
21225 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21226 && (vpos
> dpyinfo
->mouse_face_beg_row
21227 || (vpos
== dpyinfo
->mouse_face_beg_row
21228 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21229 && (vpos
< dpyinfo
->mouse_face_end_row
21230 || (vpos
== dpyinfo
->mouse_face_end_row
21231 && hpos
< dpyinfo
->mouse_face_end_col
))
21232 /* Don't redraw the cursor's spot in mouse face if it is at the
21233 end of a line (on a newline). The cursor appears there, but
21234 mouse highlighting does not. */
21235 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21236 mouse_face_here_p
= 1;
21238 /* Maybe clear the display under the cursor. */
21239 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21242 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21245 cursor_glyph
= get_phys_cursor_glyph (w
);
21246 if (cursor_glyph
== NULL
)
21247 goto mark_cursor_off
;
21249 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21250 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21251 width
= min (cursor_glyph
->pixel_width
,
21252 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21254 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21257 /* Erase the cursor by redrawing the character underneath it. */
21258 if (mouse_face_here_p
)
21259 hl
= DRAW_MOUSE_FACE
;
21261 hl
= DRAW_NORMAL_TEXT
;
21262 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21265 w
->phys_cursor_on_p
= 0;
21266 w
->phys_cursor_type
= NO_CURSOR
;
21271 Display or clear cursor of window W. If ON is zero, clear the
21272 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21273 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21276 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21278 int on
, hpos
, vpos
, x
, y
;
21280 struct frame
*f
= XFRAME (w
->frame
);
21281 int new_cursor_type
;
21282 int new_cursor_width
;
21284 struct glyph_row
*glyph_row
;
21285 struct glyph
*glyph
;
21287 /* This is pointless on invisible frames, and dangerous on garbaged
21288 windows and frames; in the latter case, the frame or window may
21289 be in the midst of changing its size, and x and y may be off the
21291 if (! FRAME_VISIBLE_P (f
)
21292 || FRAME_GARBAGED_P (f
)
21293 || vpos
>= w
->current_matrix
->nrows
21294 || hpos
>= w
->current_matrix
->matrix_w
)
21297 /* If cursor is off and we want it off, return quickly. */
21298 if (!on
&& !w
->phys_cursor_on_p
)
21301 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21302 /* If cursor row is not enabled, we don't really know where to
21303 display the cursor. */
21304 if (!glyph_row
->enabled_p
)
21306 w
->phys_cursor_on_p
= 0;
21311 if (!glyph_row
->exact_window_width_line_p
21312 || hpos
< glyph_row
->used
[TEXT_AREA
])
21313 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21315 xassert (interrupt_input_blocked
);
21317 /* Set new_cursor_type to the cursor we want to be displayed. */
21318 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21319 &new_cursor_width
, &active_cursor
);
21321 /* If cursor is currently being shown and we don't want it to be or
21322 it is in the wrong place, or the cursor type is not what we want,
21324 if (w
->phys_cursor_on_p
21326 || w
->phys_cursor
.x
!= x
21327 || w
->phys_cursor
.y
!= y
21328 || new_cursor_type
!= w
->phys_cursor_type
21329 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21330 && new_cursor_width
!= w
->phys_cursor_width
)))
21331 erase_phys_cursor (w
);
21333 /* Don't check phys_cursor_on_p here because that flag is only set
21334 to zero in some cases where we know that the cursor has been
21335 completely erased, to avoid the extra work of erasing the cursor
21336 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21337 still not be visible, or it has only been partly erased. */
21340 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21341 w
->phys_cursor_height
= glyph_row
->height
;
21343 /* Set phys_cursor_.* before x_draw_.* is called because some
21344 of them may need the information. */
21345 w
->phys_cursor
.x
= x
;
21346 w
->phys_cursor
.y
= glyph_row
->y
;
21347 w
->phys_cursor
.hpos
= hpos
;
21348 w
->phys_cursor
.vpos
= vpos
;
21351 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21352 new_cursor_type
, new_cursor_width
,
21353 on
, active_cursor
);
21357 /* Switch the display of W's cursor on or off, according to the value
21361 update_window_cursor (w
, on
)
21365 /* Don't update cursor in windows whose frame is in the process
21366 of being deleted. */
21367 if (w
->current_matrix
)
21370 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21371 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21377 /* Call update_window_cursor with parameter ON_P on all leaf windows
21378 in the window tree rooted at W. */
21381 update_cursor_in_window_tree (w
, on_p
)
21387 if (!NILP (w
->hchild
))
21388 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21389 else if (!NILP (w
->vchild
))
21390 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21392 update_window_cursor (w
, on_p
);
21394 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21400 Display the cursor on window W, or clear it, according to ON_P.
21401 Don't change the cursor's position. */
21404 x_update_cursor (f
, on_p
)
21408 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21413 Clear the cursor of window W to background color, and mark the
21414 cursor as not shown. This is used when the text where the cursor
21415 is is about to be rewritten. */
21421 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21422 update_window_cursor (w
, 0);
21427 Display the active region described by mouse_face_* according to DRAW. */
21430 show_mouse_face (dpyinfo
, draw
)
21431 Display_Info
*dpyinfo
;
21432 enum draw_glyphs_face draw
;
21434 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21435 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21437 if (/* If window is in the process of being destroyed, don't bother
21439 w
->current_matrix
!= NULL
21440 /* Don't update mouse highlight if hidden */
21441 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21442 /* Recognize when we are called to operate on rows that don't exist
21443 anymore. This can happen when a window is split. */
21444 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21446 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21447 struct glyph_row
*row
, *first
, *last
;
21449 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21450 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21452 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21454 int start_hpos
, end_hpos
, start_x
;
21456 /* For all but the first row, the highlight starts at column 0. */
21459 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21460 start_x
= dpyinfo
->mouse_face_beg_x
;
21469 end_hpos
= dpyinfo
->mouse_face_end_col
;
21472 end_hpos
= row
->used
[TEXT_AREA
];
21473 if (draw
== DRAW_NORMAL_TEXT
)
21474 row
->fill_line_p
= 1; /* Clear to end of line */
21477 if (end_hpos
> start_hpos
)
21479 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21480 start_hpos
, end_hpos
,
21484 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21488 /* When we've written over the cursor, arrange for it to
21489 be displayed again. */
21490 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21493 display_and_set_cursor (w
, 1,
21494 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21495 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21500 /* Change the mouse cursor. */
21501 if (draw
== DRAW_NORMAL_TEXT
)
21502 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21503 else if (draw
== DRAW_MOUSE_FACE
)
21504 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21506 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21510 Clear out the mouse-highlighted active region.
21511 Redraw it un-highlighted first. Value is non-zero if mouse
21512 face was actually drawn unhighlighted. */
21515 clear_mouse_face (dpyinfo
)
21516 Display_Info
*dpyinfo
;
21520 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21522 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21526 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21527 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21528 dpyinfo
->mouse_face_window
= Qnil
;
21529 dpyinfo
->mouse_face_overlay
= Qnil
;
21535 Non-zero if physical cursor of window W is within mouse face. */
21538 cursor_in_mouse_face_p (w
)
21541 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21542 int in_mouse_face
= 0;
21544 if (WINDOWP (dpyinfo
->mouse_face_window
)
21545 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21547 int hpos
= w
->phys_cursor
.hpos
;
21548 int vpos
= w
->phys_cursor
.vpos
;
21550 if (vpos
>= dpyinfo
->mouse_face_beg_row
21551 && vpos
<= dpyinfo
->mouse_face_end_row
21552 && (vpos
> dpyinfo
->mouse_face_beg_row
21553 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21554 && (vpos
< dpyinfo
->mouse_face_end_row
21555 || hpos
< dpyinfo
->mouse_face_end_col
21556 || dpyinfo
->mouse_face_past_end
))
21560 return in_mouse_face
;
21566 /* Find the glyph matrix position of buffer position CHARPOS in window
21567 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21568 current glyphs must be up to date. If CHARPOS is above window
21569 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21570 of last line in W. In the row containing CHARPOS, stop before glyphs
21571 having STOP as object. */
21573 #if 1 /* This is a version of fast_find_position that's more correct
21574 in the presence of hscrolling, for example. I didn't install
21575 it right away because the problem fixed is minor, it failed
21576 in 20.x as well, and I think it's too risky to install
21577 so near the release of 21.1. 2001-09-25 gerd. */
21580 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21583 int *hpos
, *vpos
, *x
, *y
;
21586 struct glyph_row
*row
, *first
;
21587 struct glyph
*glyph
, *end
;
21590 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21591 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21596 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21600 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21603 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21607 /* If whole rows or last part of a row came from a display overlay,
21608 row_containing_pos will skip over such rows because their end pos
21609 equals the start pos of the overlay or interval.
21611 Move back if we have a STOP object and previous row's
21612 end glyph came from STOP. */
21615 struct glyph_row
*prev
;
21616 while ((prev
= row
- 1, prev
>= first
)
21617 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21618 && prev
->used
[TEXT_AREA
] > 0)
21620 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21621 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21622 while (--glyph
>= beg
21623 && INTEGERP (glyph
->object
));
21625 || !EQ (stop
, glyph
->object
))
21633 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21635 glyph
= row
->glyphs
[TEXT_AREA
];
21636 end
= glyph
+ row
->used
[TEXT_AREA
];
21638 /* Skip over glyphs not having an object at the start of the row.
21639 These are special glyphs like truncation marks on terminal
21641 if (row
->displays_text_p
)
21643 && INTEGERP (glyph
->object
)
21644 && !EQ (stop
, glyph
->object
)
21645 && glyph
->charpos
< 0)
21647 *x
+= glyph
->pixel_width
;
21652 && !INTEGERP (glyph
->object
)
21653 && !EQ (stop
, glyph
->object
)
21654 && (!BUFFERP (glyph
->object
)
21655 || glyph
->charpos
< charpos
))
21657 *x
+= glyph
->pixel_width
;
21661 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21668 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21671 int *hpos
, *vpos
, *x
, *y
;
21676 int maybe_next_line_p
= 0;
21677 int line_start_position
;
21678 int yb
= window_text_bottom_y (w
);
21679 struct glyph_row
*row
, *best_row
;
21680 int row_vpos
, best_row_vpos
;
21683 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21684 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21686 while (row
->y
< yb
)
21688 if (row
->used
[TEXT_AREA
])
21689 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21691 line_start_position
= 0;
21693 if (line_start_position
> pos
)
21695 /* If the position sought is the end of the buffer,
21696 don't include the blank lines at the bottom of the window. */
21697 else if (line_start_position
== pos
21698 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21700 maybe_next_line_p
= 1;
21703 else if (line_start_position
> 0)
21706 best_row_vpos
= row_vpos
;
21709 if (row
->y
+ row
->height
>= yb
)
21716 /* Find the right column within BEST_ROW. */
21718 current_x
= best_row
->x
;
21719 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21721 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21722 int charpos
= glyph
->charpos
;
21724 if (BUFFERP (glyph
->object
))
21726 if (charpos
== pos
)
21729 *vpos
= best_row_vpos
;
21734 else if (charpos
> pos
)
21737 else if (EQ (glyph
->object
, stop
))
21742 current_x
+= glyph
->pixel_width
;
21745 /* If we're looking for the end of the buffer,
21746 and we didn't find it in the line we scanned,
21747 use the start of the following line. */
21748 if (maybe_next_line_p
)
21753 current_x
= best_row
->x
;
21756 *vpos
= best_row_vpos
;
21757 *hpos
= lastcol
+ 1;
21766 /* Find the position of the glyph for position POS in OBJECT in
21767 window W's current matrix, and return in *X, *Y the pixel
21768 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21770 RIGHT_P non-zero means return the position of the right edge of the
21771 glyph, RIGHT_P zero means return the left edge position.
21773 If no glyph for POS exists in the matrix, return the position of
21774 the glyph with the next smaller position that is in the matrix, if
21775 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21776 exists in the matrix, return the position of the glyph with the
21777 next larger position in OBJECT.
21779 Value is non-zero if a glyph was found. */
21782 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21785 Lisp_Object object
;
21786 int *hpos
, *vpos
, *x
, *y
;
21789 int yb
= window_text_bottom_y (w
);
21790 struct glyph_row
*r
;
21791 struct glyph
*best_glyph
= NULL
;
21792 struct glyph_row
*best_row
= NULL
;
21795 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21796 r
->enabled_p
&& r
->y
< yb
;
21799 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21800 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21803 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21804 if (EQ (g
->object
, object
))
21806 if (g
->charpos
== pos
)
21813 else if (best_glyph
== NULL
21814 || ((abs (g
->charpos
- pos
)
21815 < abs (best_glyph
->charpos
- pos
))
21818 : g
->charpos
> pos
)))
21832 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21836 *x
+= best_glyph
->pixel_width
;
21841 *vpos
= best_row
- w
->current_matrix
->rows
;
21844 return best_glyph
!= NULL
;
21848 /* See if position X, Y is within a hot-spot of an image. */
21851 on_hot_spot_p (hot_spot
, x
, y
)
21852 Lisp_Object hot_spot
;
21855 if (!CONSP (hot_spot
))
21858 if (EQ (XCAR (hot_spot
), Qrect
))
21860 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21861 Lisp_Object rect
= XCDR (hot_spot
);
21865 if (!CONSP (XCAR (rect
)))
21867 if (!CONSP (XCDR (rect
)))
21869 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21871 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21873 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21875 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21879 else if (EQ (XCAR (hot_spot
), Qcircle
))
21881 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21882 Lisp_Object circ
= XCDR (hot_spot
);
21883 Lisp_Object lr
, lx0
, ly0
;
21885 && CONSP (XCAR (circ
))
21886 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21887 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21888 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21890 double r
= XFLOATINT (lr
);
21891 double dx
= XINT (lx0
) - x
;
21892 double dy
= XINT (ly0
) - y
;
21893 return (dx
* dx
+ dy
* dy
<= r
* r
);
21896 else if (EQ (XCAR (hot_spot
), Qpoly
))
21898 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21899 if (VECTORP (XCDR (hot_spot
)))
21901 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21902 Lisp_Object
*poly
= v
->contents
;
21906 Lisp_Object lx
, ly
;
21909 /* Need an even number of coordinates, and at least 3 edges. */
21910 if (n
< 6 || n
& 1)
21913 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21914 If count is odd, we are inside polygon. Pixels on edges
21915 may or may not be included depending on actual geometry of the
21917 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21918 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21920 x0
= XINT (lx
), y0
= XINT (ly
);
21921 for (i
= 0; i
< n
; i
+= 2)
21923 int x1
= x0
, y1
= y0
;
21924 if ((lx
= poly
[i
], !INTEGERP (lx
))
21925 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21927 x0
= XINT (lx
), y0
= XINT (ly
);
21929 /* Does this segment cross the X line? */
21937 if (y
> y0
&& y
> y1
)
21939 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21945 /* If we don't understand the format, pretend we're not in the hot-spot. */
21950 find_hot_spot (map
, x
, y
)
21954 while (CONSP (map
))
21956 if (CONSP (XCAR (map
))
21957 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21965 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21967 doc
: /* Lookup in image map MAP coordinates X and Y.
21968 An image map is an alist where each element has the format (AREA ID PLIST).
21969 An AREA is specified as either a rectangle, a circle, or a polygon:
21970 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21971 pixel coordinates of the upper left and bottom right corners.
21972 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21973 and the radius of the circle; r may be a float or integer.
21974 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21975 vector describes one corner in the polygon.
21976 Returns the alist element for the first matching AREA in MAP. */)
21987 return find_hot_spot (map
, XINT (x
), XINT (y
));
21991 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21993 define_frame_cursor1 (f
, cursor
, pointer
)
21996 Lisp_Object pointer
;
21998 /* Do not change cursor shape while dragging mouse. */
21999 if (!NILP (do_mouse_tracking
))
22002 if (!NILP (pointer
))
22004 if (EQ (pointer
, Qarrow
))
22005 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22006 else if (EQ (pointer
, Qhand
))
22007 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22008 else if (EQ (pointer
, Qtext
))
22009 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22010 else if (EQ (pointer
, intern ("hdrag")))
22011 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22012 #ifdef HAVE_X_WINDOWS
22013 else if (EQ (pointer
, intern ("vdrag")))
22014 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22016 else if (EQ (pointer
, intern ("hourglass")))
22017 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22018 else if (EQ (pointer
, Qmodeline
))
22019 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22021 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22024 if (cursor
!= No_Cursor
)
22025 rif
->define_frame_cursor (f
, cursor
);
22028 /* Take proper action when mouse has moved to the mode or header line
22029 or marginal area AREA of window W, x-position X and y-position Y.
22030 X is relative to the start of the text display area of W, so the
22031 width of bitmap areas and scroll bars must be subtracted to get a
22032 position relative to the start of the mode line. */
22035 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22036 Lisp_Object window
;
22038 enum window_part area
;
22040 struct window
*w
= XWINDOW (window
);
22041 struct frame
*f
= XFRAME (w
->frame
);
22042 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22043 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22044 Lisp_Object pointer
= Qnil
;
22045 int charpos
, dx
, dy
, width
, height
;
22046 Lisp_Object string
, object
= Qnil
;
22047 Lisp_Object pos
, help
;
22049 Lisp_Object mouse_face
;
22050 int original_x_pixel
= x
;
22051 struct glyph
* glyph
= NULL
;
22052 struct glyph_row
*row
;
22054 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22059 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22060 &object
, &dx
, &dy
, &width
, &height
);
22062 row
= (area
== ON_MODE_LINE
22063 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22064 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22067 if (row
->mode_line_p
&& row
->enabled_p
)
22069 glyph
= row
->glyphs
[TEXT_AREA
];
22070 end
= glyph
+ row
->used
[TEXT_AREA
];
22072 for (x0
= original_x_pixel
;
22073 glyph
< end
&& x0
>= glyph
->pixel_width
;
22075 x0
-= glyph
->pixel_width
;
22083 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22084 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22085 &object
, &dx
, &dy
, &width
, &height
);
22090 if (IMAGEP (object
))
22092 Lisp_Object image_map
, hotspot
;
22093 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22095 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22097 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22099 Lisp_Object area_id
, plist
;
22101 area_id
= XCAR (hotspot
);
22102 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22103 If so, we could look for mouse-enter, mouse-leave
22104 properties in PLIST (and do something...). */
22105 hotspot
= XCDR (hotspot
);
22106 if (CONSP (hotspot
)
22107 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22109 pointer
= Fplist_get (plist
, Qpointer
);
22110 if (NILP (pointer
))
22112 help
= Fplist_get (plist
, Qhelp_echo
);
22115 help_echo_string
= help
;
22116 /* Is this correct? ++kfs */
22117 XSETWINDOW (help_echo_window
, w
);
22118 help_echo_object
= w
->buffer
;
22119 help_echo_pos
= charpos
;
22123 if (NILP (pointer
))
22124 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22127 if (STRINGP (string
))
22129 pos
= make_number (charpos
);
22130 /* If we're on a string with `help-echo' text property, arrange
22131 for the help to be displayed. This is done by setting the
22132 global variable help_echo_string to the help string. */
22135 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22138 help_echo_string
= help
;
22139 XSETWINDOW (help_echo_window
, w
);
22140 help_echo_object
= string
;
22141 help_echo_pos
= charpos
;
22145 if (NILP (pointer
))
22146 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22148 /* Change the mouse pointer according to what is under X/Y. */
22149 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22152 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22153 if (!KEYMAPP (map
))
22154 map
= Fget_text_property (pos
, Qkeymap
, string
);
22155 if (!KEYMAPP (map
))
22156 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22159 /* Change the mouse face according to what is under X/Y. */
22160 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22161 if (!NILP (mouse_face
)
22162 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22167 struct glyph
* tmp_glyph
;
22171 int total_pixel_width
;
22176 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22177 Qmouse_face
, string
, Qnil
);
22179 b
= make_number (0);
22181 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22183 e
= make_number (SCHARS (string
));
22185 /* Calculate the position(glyph position: GPOS) of GLYPH in
22186 displayed string. GPOS is different from CHARPOS.
22188 CHARPOS is the position of glyph in internal string
22189 object. A mode line string format has structures which
22190 is converted to a flatten by emacs lisp interpreter.
22191 The internal string is an element of the structures.
22192 The displayed string is the flatten string. */
22193 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22194 tmp_glyph
->charpos
>= XINT (b
);
22195 tmp_glyph
--, gpos
++)
22197 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22201 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22202 displayed string holding GLYPH.
22204 GSEQ_LENGTH is different from SCHARS (STRING).
22205 SCHARS (STRING) returns the length of the internal string. */
22206 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22207 tmp_glyph
->charpos
< XINT (e
);
22208 tmp_glyph
++, gseq_length
++)
22210 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22214 total_pixel_width
= 0;
22215 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22216 total_pixel_width
+= tmp_glyph
->pixel_width
;
22218 /* Pre calculation of re-rendering position */
22220 hpos
= (area
== ON_MODE_LINE
22221 ? (w
->current_matrix
)->nrows
- 1
22224 /* If the re-rendering position is included in the last
22225 re-rendering area, we should do nothing. */
22226 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22227 && dpyinfo
->mouse_face_beg_col
<= vpos
22228 && vpos
< dpyinfo
->mouse_face_end_col
22229 && dpyinfo
->mouse_face_beg_row
== hpos
)
22232 if (clear_mouse_face (dpyinfo
))
22233 cursor
= No_Cursor
;
22235 dpyinfo
->mouse_face_beg_col
= vpos
;
22236 dpyinfo
->mouse_face_beg_row
= hpos
;
22238 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22239 dpyinfo
->mouse_face_beg_y
= 0;
22241 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22242 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22244 dpyinfo
->mouse_face_end_x
= 0;
22245 dpyinfo
->mouse_face_end_y
= 0;
22247 dpyinfo
->mouse_face_past_end
= 0;
22248 dpyinfo
->mouse_face_window
= window
;
22250 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22253 glyph
->face_id
, 1);
22254 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22256 if (NILP (pointer
))
22259 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22260 clear_mouse_face (dpyinfo
);
22262 define_frame_cursor1 (f
, cursor
, pointer
);
22267 Take proper action when the mouse has moved to position X, Y on
22268 frame F as regards highlighting characters that have mouse-face
22269 properties. Also de-highlighting chars where the mouse was before.
22270 X and Y can be negative or out of range. */
22273 note_mouse_highlight (f
, x
, y
)
22277 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22278 enum window_part part
;
22279 Lisp_Object window
;
22281 Cursor cursor
= No_Cursor
;
22282 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22285 /* When a menu is active, don't highlight because this looks odd. */
22286 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22287 if (popup_activated ())
22291 if (NILP (Vmouse_highlight
)
22292 || !f
->glyphs_initialized_p
)
22295 dpyinfo
->mouse_face_mouse_x
= x
;
22296 dpyinfo
->mouse_face_mouse_y
= y
;
22297 dpyinfo
->mouse_face_mouse_frame
= f
;
22299 if (dpyinfo
->mouse_face_defer
)
22302 if (gc_in_progress
)
22304 dpyinfo
->mouse_face_deferred_gc
= 1;
22308 /* Which window is that in? */
22309 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22311 /* If we were displaying active text in another window, clear that.
22312 Also clear if we move out of text area in same window. */
22313 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22314 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22315 && !NILP (dpyinfo
->mouse_face_window
)))
22316 clear_mouse_face (dpyinfo
);
22318 /* Not on a window -> return. */
22319 if (!WINDOWP (window
))
22322 /* Reset help_echo_string. It will get recomputed below. */
22323 help_echo_string
= Qnil
;
22325 /* Convert to window-relative pixel coordinates. */
22326 w
= XWINDOW (window
);
22327 frame_to_window_pixel_xy (w
, &x
, &y
);
22329 /* Handle tool-bar window differently since it doesn't display a
22331 if (EQ (window
, f
->tool_bar_window
))
22333 note_tool_bar_highlight (f
, x
, y
);
22337 /* Mouse is on the mode, header line or margin? */
22338 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22339 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22341 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22345 if (part
== ON_VERTICAL_BORDER
)
22346 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22347 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22348 || part
== ON_SCROLL_BAR
)
22349 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22351 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22353 /* Are we in a window whose display is up to date?
22354 And verify the buffer's text has not changed. */
22355 b
= XBUFFER (w
->buffer
);
22356 if (part
== ON_TEXT
22357 && EQ (w
->window_end_valid
, w
->buffer
)
22358 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22359 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22361 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22362 struct glyph
*glyph
;
22363 Lisp_Object object
;
22364 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22365 Lisp_Object
*overlay_vec
= NULL
;
22367 struct buffer
*obuf
;
22368 int obegv
, ozv
, same_region
;
22370 /* Find the glyph under X/Y. */
22371 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22373 /* Look for :pointer property on image. */
22374 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22376 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22377 if (img
!= NULL
&& IMAGEP (img
->spec
))
22379 Lisp_Object image_map
, hotspot
;
22380 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22382 && (hotspot
= find_hot_spot (image_map
,
22383 glyph
->slice
.x
+ dx
,
22384 glyph
->slice
.y
+ dy
),
22386 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22388 Lisp_Object area_id
, plist
;
22390 area_id
= XCAR (hotspot
);
22391 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22392 If so, we could look for mouse-enter, mouse-leave
22393 properties in PLIST (and do something...). */
22394 hotspot
= XCDR (hotspot
);
22395 if (CONSP (hotspot
)
22396 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22398 pointer
= Fplist_get (plist
, Qpointer
);
22399 if (NILP (pointer
))
22401 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22402 if (!NILP (help_echo_string
))
22404 help_echo_window
= window
;
22405 help_echo_object
= glyph
->object
;
22406 help_echo_pos
= glyph
->charpos
;
22410 if (NILP (pointer
))
22411 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22415 /* Clear mouse face if X/Y not over text. */
22417 || area
!= TEXT_AREA
22418 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22420 if (clear_mouse_face (dpyinfo
))
22421 cursor
= No_Cursor
;
22422 if (NILP (pointer
))
22424 if (area
!= TEXT_AREA
)
22425 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22427 pointer
= Vvoid_text_area_pointer
;
22432 pos
= glyph
->charpos
;
22433 object
= glyph
->object
;
22434 if (!STRINGP (object
) && !BUFFERP (object
))
22437 /* If we get an out-of-range value, return now; avoid an error. */
22438 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22441 /* Make the window's buffer temporarily current for
22442 overlays_at and compute_char_face. */
22443 obuf
= current_buffer
;
22444 current_buffer
= b
;
22450 /* Is this char mouse-active or does it have help-echo? */
22451 position
= make_number (pos
);
22453 if (BUFFERP (object
))
22455 /* Put all the overlays we want in a vector in overlay_vec. */
22456 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22457 /* Sort overlays into increasing priority order. */
22458 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22463 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22464 && vpos
>= dpyinfo
->mouse_face_beg_row
22465 && vpos
<= dpyinfo
->mouse_face_end_row
22466 && (vpos
> dpyinfo
->mouse_face_beg_row
22467 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22468 && (vpos
< dpyinfo
->mouse_face_end_row
22469 || hpos
< dpyinfo
->mouse_face_end_col
22470 || dpyinfo
->mouse_face_past_end
));
22473 cursor
= No_Cursor
;
22475 /* Check mouse-face highlighting. */
22477 /* If there exists an overlay with mouse-face overlapping
22478 the one we are currently highlighting, we have to
22479 check if we enter the overlapping overlay, and then
22480 highlight only that. */
22481 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22482 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22484 /* Find the highest priority overlay that has a mouse-face
22487 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22489 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22490 if (!NILP (mouse_face
))
22491 overlay
= overlay_vec
[i
];
22494 /* If we're actually highlighting the same overlay as
22495 before, there's no need to do that again. */
22496 if (!NILP (overlay
)
22497 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22498 goto check_help_echo
;
22500 dpyinfo
->mouse_face_overlay
= overlay
;
22502 /* Clear the display of the old active region, if any. */
22503 if (clear_mouse_face (dpyinfo
))
22504 cursor
= No_Cursor
;
22506 /* If no overlay applies, get a text property. */
22507 if (NILP (overlay
))
22508 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22510 /* Handle the overlay case. */
22511 if (!NILP (overlay
))
22513 /* Find the range of text around this char that
22514 should be active. */
22515 Lisp_Object before
, after
;
22518 before
= Foverlay_start (overlay
);
22519 after
= Foverlay_end (overlay
);
22520 /* Record this as the current active region. */
22521 fast_find_position (w
, XFASTINT (before
),
22522 &dpyinfo
->mouse_face_beg_col
,
22523 &dpyinfo
->mouse_face_beg_row
,
22524 &dpyinfo
->mouse_face_beg_x
,
22525 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22527 dpyinfo
->mouse_face_past_end
22528 = !fast_find_position (w
, XFASTINT (after
),
22529 &dpyinfo
->mouse_face_end_col
,
22530 &dpyinfo
->mouse_face_end_row
,
22531 &dpyinfo
->mouse_face_end_x
,
22532 &dpyinfo
->mouse_face_end_y
, Qnil
);
22533 dpyinfo
->mouse_face_window
= window
;
22535 dpyinfo
->mouse_face_face_id
22536 = face_at_buffer_position (w
, pos
, 0, 0,
22538 !dpyinfo
->mouse_face_hidden
);
22540 /* Display it as active. */
22541 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22542 cursor
= No_Cursor
;
22544 /* Handle the text property case. */
22545 else if (!NILP (mouse_face
) && BUFFERP (object
))
22547 /* Find the range of text around this char that
22548 should be active. */
22549 Lisp_Object before
, after
, beginning
, end
;
22552 beginning
= Fmarker_position (w
->start
);
22553 end
= make_number (BUF_Z (XBUFFER (object
))
22554 - XFASTINT (w
->window_end_pos
));
22556 = Fprevious_single_property_change (make_number (pos
+ 1),
22558 object
, beginning
);
22560 = Fnext_single_property_change (position
, Qmouse_face
,
22563 /* Record this as the current active region. */
22564 fast_find_position (w
, XFASTINT (before
),
22565 &dpyinfo
->mouse_face_beg_col
,
22566 &dpyinfo
->mouse_face_beg_row
,
22567 &dpyinfo
->mouse_face_beg_x
,
22568 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22569 dpyinfo
->mouse_face_past_end
22570 = !fast_find_position (w
, XFASTINT (after
),
22571 &dpyinfo
->mouse_face_end_col
,
22572 &dpyinfo
->mouse_face_end_row
,
22573 &dpyinfo
->mouse_face_end_x
,
22574 &dpyinfo
->mouse_face_end_y
, Qnil
);
22575 dpyinfo
->mouse_face_window
= window
;
22577 if (BUFFERP (object
))
22578 dpyinfo
->mouse_face_face_id
22579 = face_at_buffer_position (w
, pos
, 0, 0,
22581 !dpyinfo
->mouse_face_hidden
);
22583 /* Display it as active. */
22584 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22585 cursor
= No_Cursor
;
22587 else if (!NILP (mouse_face
) && STRINGP (object
))
22592 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22595 e
= Fnext_single_property_change (position
, Qmouse_face
,
22598 b
= make_number (0);
22600 e
= make_number (SCHARS (object
) - 1);
22602 fast_find_string_pos (w
, XINT (b
), object
,
22603 &dpyinfo
->mouse_face_beg_col
,
22604 &dpyinfo
->mouse_face_beg_row
,
22605 &dpyinfo
->mouse_face_beg_x
,
22606 &dpyinfo
->mouse_face_beg_y
, 0);
22607 fast_find_string_pos (w
, XINT (e
), object
,
22608 &dpyinfo
->mouse_face_end_col
,
22609 &dpyinfo
->mouse_face_end_row
,
22610 &dpyinfo
->mouse_face_end_x
,
22611 &dpyinfo
->mouse_face_end_y
, 1);
22612 dpyinfo
->mouse_face_past_end
= 0;
22613 dpyinfo
->mouse_face_window
= window
;
22614 dpyinfo
->mouse_face_face_id
22615 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22616 glyph
->face_id
, 1);
22617 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22618 cursor
= No_Cursor
;
22620 else if (STRINGP (object
) && NILP (mouse_face
))
22622 /* A string which doesn't have mouse-face, but
22623 the text ``under'' it might have. */
22624 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22625 int start
= MATRIX_ROW_START_CHARPOS (r
);
22627 pos
= string_buffer_position (w
, object
, start
);
22629 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22633 if (!NILP (mouse_face
) && !NILP (overlay
))
22635 Lisp_Object before
= Foverlay_start (overlay
);
22636 Lisp_Object after
= Foverlay_end (overlay
);
22639 /* Note that we might not be able to find position
22640 BEFORE in the glyph matrix if the overlay is
22641 entirely covered by a `display' property. In
22642 this case, we overshoot. So let's stop in
22643 the glyph matrix before glyphs for OBJECT. */
22644 fast_find_position (w
, XFASTINT (before
),
22645 &dpyinfo
->mouse_face_beg_col
,
22646 &dpyinfo
->mouse_face_beg_row
,
22647 &dpyinfo
->mouse_face_beg_x
,
22648 &dpyinfo
->mouse_face_beg_y
,
22651 dpyinfo
->mouse_face_past_end
22652 = !fast_find_position (w
, XFASTINT (after
),
22653 &dpyinfo
->mouse_face_end_col
,
22654 &dpyinfo
->mouse_face_end_row
,
22655 &dpyinfo
->mouse_face_end_x
,
22656 &dpyinfo
->mouse_face_end_y
,
22658 dpyinfo
->mouse_face_window
= window
;
22659 dpyinfo
->mouse_face_face_id
22660 = face_at_buffer_position (w
, pos
, 0, 0,
22662 !dpyinfo
->mouse_face_hidden
);
22664 /* Display it as active. */
22665 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22666 cursor
= No_Cursor
;
22673 /* Look for a `help-echo' property. */
22674 if (NILP (help_echo_string
)) {
22675 Lisp_Object help
, overlay
;
22677 /* Check overlays first. */
22678 help
= overlay
= Qnil
;
22679 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22681 overlay
= overlay_vec
[i
];
22682 help
= Foverlay_get (overlay
, Qhelp_echo
);
22687 help_echo_string
= help
;
22688 help_echo_window
= window
;
22689 help_echo_object
= overlay
;
22690 help_echo_pos
= pos
;
22694 Lisp_Object object
= glyph
->object
;
22695 int charpos
= glyph
->charpos
;
22697 /* Try text properties. */
22698 if (STRINGP (object
)
22700 && charpos
< SCHARS (object
))
22702 help
= Fget_text_property (make_number (charpos
),
22703 Qhelp_echo
, object
);
22706 /* If the string itself doesn't specify a help-echo,
22707 see if the buffer text ``under'' it does. */
22708 struct glyph_row
*r
22709 = MATRIX_ROW (w
->current_matrix
, vpos
);
22710 int start
= MATRIX_ROW_START_CHARPOS (r
);
22711 int pos
= string_buffer_position (w
, object
, start
);
22714 help
= Fget_char_property (make_number (pos
),
22715 Qhelp_echo
, w
->buffer
);
22719 object
= w
->buffer
;
22724 else if (BUFFERP (object
)
22727 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22732 help_echo_string
= help
;
22733 help_echo_window
= window
;
22734 help_echo_object
= object
;
22735 help_echo_pos
= charpos
;
22740 /* Look for a `pointer' property. */
22741 if (NILP (pointer
))
22743 /* Check overlays first. */
22744 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22745 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22747 if (NILP (pointer
))
22749 Lisp_Object object
= glyph
->object
;
22750 int charpos
= glyph
->charpos
;
22752 /* Try text properties. */
22753 if (STRINGP (object
)
22755 && charpos
< SCHARS (object
))
22757 pointer
= Fget_text_property (make_number (charpos
),
22759 if (NILP (pointer
))
22761 /* If the string itself doesn't specify a pointer,
22762 see if the buffer text ``under'' it does. */
22763 struct glyph_row
*r
22764 = MATRIX_ROW (w
->current_matrix
, vpos
);
22765 int start
= MATRIX_ROW_START_CHARPOS (r
);
22766 int pos
= string_buffer_position (w
, object
, start
);
22768 pointer
= Fget_char_property (make_number (pos
),
22769 Qpointer
, w
->buffer
);
22772 else if (BUFFERP (object
)
22775 pointer
= Fget_text_property (make_number (charpos
),
22782 current_buffer
= obuf
;
22787 define_frame_cursor1 (f
, cursor
, pointer
);
22792 Clear any mouse-face on window W. This function is part of the
22793 redisplay interface, and is called from try_window_id and similar
22794 functions to ensure the mouse-highlight is off. */
22797 x_clear_window_mouse_face (w
)
22800 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22801 Lisp_Object window
;
22804 XSETWINDOW (window
, w
);
22805 if (EQ (window
, dpyinfo
->mouse_face_window
))
22806 clear_mouse_face (dpyinfo
);
22812 Just discard the mouse face information for frame F, if any.
22813 This is used when the size of F is changed. */
22816 cancel_mouse_face (f
)
22819 Lisp_Object window
;
22820 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22822 window
= dpyinfo
->mouse_face_window
;
22823 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22825 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22826 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22827 dpyinfo
->mouse_face_window
= Qnil
;
22832 #endif /* HAVE_WINDOW_SYSTEM */
22835 /***********************************************************************
22837 ***********************************************************************/
22839 #ifdef HAVE_WINDOW_SYSTEM
22841 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22842 which intersects rectangle R. R is in window-relative coordinates. */
22845 expose_area (w
, row
, r
, area
)
22847 struct glyph_row
*row
;
22849 enum glyph_row_area area
;
22851 struct glyph
*first
= row
->glyphs
[area
];
22852 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22853 struct glyph
*last
;
22854 int first_x
, start_x
, x
;
22856 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22857 /* If row extends face to end of line write the whole line. */
22858 draw_glyphs (w
, 0, row
, area
,
22859 0, row
->used
[area
],
22860 DRAW_NORMAL_TEXT
, 0);
22863 /* Set START_X to the window-relative start position for drawing glyphs of
22864 AREA. The first glyph of the text area can be partially visible.
22865 The first glyphs of other areas cannot. */
22866 start_x
= window_box_left_offset (w
, area
);
22868 if (area
== TEXT_AREA
)
22871 /* Find the first glyph that must be redrawn. */
22873 && x
+ first
->pixel_width
< r
->x
)
22875 x
+= first
->pixel_width
;
22879 /* Find the last one. */
22883 && x
< r
->x
+ r
->width
)
22885 x
+= last
->pixel_width
;
22891 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22892 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22893 DRAW_NORMAL_TEXT
, 0);
22898 /* Redraw the parts of the glyph row ROW on window W intersecting
22899 rectangle R. R is in window-relative coordinates. Value is
22900 non-zero if mouse-face was overwritten. */
22903 expose_line (w
, row
, r
)
22905 struct glyph_row
*row
;
22908 xassert (row
->enabled_p
);
22910 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22911 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22912 0, row
->used
[TEXT_AREA
],
22913 DRAW_NORMAL_TEXT
, 0);
22916 if (row
->used
[LEFT_MARGIN_AREA
])
22917 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22918 if (row
->used
[TEXT_AREA
])
22919 expose_area (w
, row
, r
, TEXT_AREA
);
22920 if (row
->used
[RIGHT_MARGIN_AREA
])
22921 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22922 draw_row_fringe_bitmaps (w
, row
);
22925 return row
->mouse_face_p
;
22929 /* Redraw those parts of glyphs rows during expose event handling that
22930 overlap other rows. Redrawing of an exposed line writes over parts
22931 of lines overlapping that exposed line; this function fixes that.
22933 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22934 row in W's current matrix that is exposed and overlaps other rows.
22935 LAST_OVERLAPPING_ROW is the last such row. */
22938 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22940 struct glyph_row
*first_overlapping_row
;
22941 struct glyph_row
*last_overlapping_row
;
22943 struct glyph_row
*row
;
22945 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22946 if (row
->overlapping_p
)
22948 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22950 if (row
->used
[LEFT_MARGIN_AREA
])
22951 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
22953 if (row
->used
[TEXT_AREA
])
22954 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
22956 if (row
->used
[RIGHT_MARGIN_AREA
])
22957 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
22962 /* Return non-zero if W's cursor intersects rectangle R. */
22965 phys_cursor_in_rect_p (w
, r
)
22969 XRectangle cr
, result
;
22970 struct glyph
*cursor_glyph
;
22972 cursor_glyph
= get_phys_cursor_glyph (w
);
22975 /* r is relative to W's box, but w->phys_cursor.x is relative
22976 to left edge of W's TEXT area. Adjust it. */
22977 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22978 cr
.y
= w
->phys_cursor
.y
;
22979 cr
.width
= cursor_glyph
->pixel_width
;
22980 cr
.height
= w
->phys_cursor_height
;
22981 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22982 I assume the effect is the same -- and this is portable. */
22983 return x_intersect_rectangles (&cr
, r
, &result
);
22991 Draw a vertical window border to the right of window W if W doesn't
22992 have vertical scroll bars. */
22995 x_draw_vertical_border (w
)
22998 /* We could do better, if we knew what type of scroll-bar the adjacent
22999 windows (on either side) have... But we don't :-(
23000 However, I think this works ok. ++KFS 2003-04-25 */
23002 /* Redraw borders between horizontally adjacent windows. Don't
23003 do it for frames with vertical scroll bars because either the
23004 right scroll bar of a window, or the left scroll bar of its
23005 neighbor will suffice as a border. */
23006 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23009 if (!WINDOW_RIGHTMOST_P (w
)
23010 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23012 int x0
, x1
, y0
, y1
;
23014 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23017 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23020 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23022 else if (!WINDOW_LEFTMOST_P (w
)
23023 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23025 int x0
, x1
, y0
, y1
;
23027 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23030 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23033 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23038 /* Redraw the part of window W intersection rectangle FR. Pixel
23039 coordinates in FR are frame-relative. Call this function with
23040 input blocked. Value is non-zero if the exposure overwrites
23044 expose_window (w
, fr
)
23048 struct frame
*f
= XFRAME (w
->frame
);
23050 int mouse_face_overwritten_p
= 0;
23052 /* If window is not yet fully initialized, do nothing. This can
23053 happen when toolkit scroll bars are used and a window is split.
23054 Reconfiguring the scroll bar will generate an expose for a newly
23056 if (w
->current_matrix
== NULL
)
23059 /* When we're currently updating the window, display and current
23060 matrix usually don't agree. Arrange for a thorough display
23062 if (w
== updated_window
)
23064 SET_FRAME_GARBAGED (f
);
23068 /* Frame-relative pixel rectangle of W. */
23069 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23070 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23071 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23072 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23074 if (x_intersect_rectangles (fr
, &wr
, &r
))
23076 int yb
= window_text_bottom_y (w
);
23077 struct glyph_row
*row
;
23078 int cursor_cleared_p
;
23079 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23081 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23082 r
.x
, r
.y
, r
.width
, r
.height
));
23084 /* Convert to window coordinates. */
23085 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23086 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23088 /* Turn off the cursor. */
23089 if (!w
->pseudo_window_p
23090 && phys_cursor_in_rect_p (w
, &r
))
23092 x_clear_cursor (w
);
23093 cursor_cleared_p
= 1;
23096 cursor_cleared_p
= 0;
23098 /* Update lines intersecting rectangle R. */
23099 first_overlapping_row
= last_overlapping_row
= NULL
;
23100 for (row
= w
->current_matrix
->rows
;
23105 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23107 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23108 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23109 || (r
.y
>= y0
&& r
.y
< y1
)
23110 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23112 /* A header line may be overlapping, but there is no need
23113 to fix overlapping areas for them. KFS 2005-02-12 */
23114 if (row
->overlapping_p
&& !row
->mode_line_p
)
23116 if (first_overlapping_row
== NULL
)
23117 first_overlapping_row
= row
;
23118 last_overlapping_row
= row
;
23121 if (expose_line (w
, row
, &r
))
23122 mouse_face_overwritten_p
= 1;
23129 /* Display the mode line if there is one. */
23130 if (WINDOW_WANTS_MODELINE_P (w
)
23131 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23133 && row
->y
< r
.y
+ r
.height
)
23135 if (expose_line (w
, row
, &r
))
23136 mouse_face_overwritten_p
= 1;
23139 if (!w
->pseudo_window_p
)
23141 /* Fix the display of overlapping rows. */
23142 if (first_overlapping_row
)
23143 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23145 /* Draw border between windows. */
23146 x_draw_vertical_border (w
);
23148 /* Turn the cursor on again. */
23149 if (cursor_cleared_p
)
23150 update_window_cursor (w
, 1);
23154 return mouse_face_overwritten_p
;
23159 /* Redraw (parts) of all windows in the window tree rooted at W that
23160 intersect R. R contains frame pixel coordinates. Value is
23161 non-zero if the exposure overwrites mouse-face. */
23164 expose_window_tree (w
, r
)
23168 struct frame
*f
= XFRAME (w
->frame
);
23169 int mouse_face_overwritten_p
= 0;
23171 while (w
&& !FRAME_GARBAGED_P (f
))
23173 if (!NILP (w
->hchild
))
23174 mouse_face_overwritten_p
23175 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23176 else if (!NILP (w
->vchild
))
23177 mouse_face_overwritten_p
23178 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23180 mouse_face_overwritten_p
|= expose_window (w
, r
);
23182 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23185 return mouse_face_overwritten_p
;
23190 Redisplay an exposed area of frame F. X and Y are the upper-left
23191 corner of the exposed rectangle. W and H are width and height of
23192 the exposed area. All are pixel values. W or H zero means redraw
23193 the entire frame. */
23196 expose_frame (f
, x
, y
, w
, h
)
23201 int mouse_face_overwritten_p
= 0;
23203 TRACE ((stderr
, "expose_frame "));
23205 /* No need to redraw if frame will be redrawn soon. */
23206 if (FRAME_GARBAGED_P (f
))
23208 TRACE ((stderr
, " garbaged\n"));
23212 /* If basic faces haven't been realized yet, there is no point in
23213 trying to redraw anything. This can happen when we get an expose
23214 event while Emacs is starting, e.g. by moving another window. */
23215 if (FRAME_FACE_CACHE (f
) == NULL
23216 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23218 TRACE ((stderr
, " no faces\n"));
23222 if (w
== 0 || h
== 0)
23225 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23226 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23236 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23237 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23239 if (WINDOWP (f
->tool_bar_window
))
23240 mouse_face_overwritten_p
23241 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23243 #ifdef HAVE_X_WINDOWS
23245 #ifndef USE_X_TOOLKIT
23246 if (WINDOWP (f
->menu_bar_window
))
23247 mouse_face_overwritten_p
23248 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23249 #endif /* not USE_X_TOOLKIT */
23253 /* Some window managers support a focus-follows-mouse style with
23254 delayed raising of frames. Imagine a partially obscured frame,
23255 and moving the mouse into partially obscured mouse-face on that
23256 frame. The visible part of the mouse-face will be highlighted,
23257 then the WM raises the obscured frame. With at least one WM, KDE
23258 2.1, Emacs is not getting any event for the raising of the frame
23259 (even tried with SubstructureRedirectMask), only Expose events.
23260 These expose events will draw text normally, i.e. not
23261 highlighted. Which means we must redo the highlight here.
23262 Subsume it under ``we love X''. --gerd 2001-08-15 */
23263 /* Included in Windows version because Windows most likely does not
23264 do the right thing if any third party tool offers
23265 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23266 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23268 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23269 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23271 int x
= dpyinfo
->mouse_face_mouse_x
;
23272 int y
= dpyinfo
->mouse_face_mouse_y
;
23273 clear_mouse_face (dpyinfo
);
23274 note_mouse_highlight (f
, x
, y
);
23281 Determine the intersection of two rectangles R1 and R2. Return
23282 the intersection in *RESULT. Value is non-zero if RESULT is not
23286 x_intersect_rectangles (r1
, r2
, result
)
23287 XRectangle
*r1
, *r2
, *result
;
23289 XRectangle
*left
, *right
;
23290 XRectangle
*upper
, *lower
;
23291 int intersection_p
= 0;
23293 /* Rearrange so that R1 is the left-most rectangle. */
23295 left
= r1
, right
= r2
;
23297 left
= r2
, right
= r1
;
23299 /* X0 of the intersection is right.x0, if this is inside R1,
23300 otherwise there is no intersection. */
23301 if (right
->x
<= left
->x
+ left
->width
)
23303 result
->x
= right
->x
;
23305 /* The right end of the intersection is the minimum of the
23306 the right ends of left and right. */
23307 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23310 /* Same game for Y. */
23312 upper
= r1
, lower
= r2
;
23314 upper
= r2
, lower
= r1
;
23316 /* The upper end of the intersection is lower.y0, if this is inside
23317 of upper. Otherwise, there is no intersection. */
23318 if (lower
->y
<= upper
->y
+ upper
->height
)
23320 result
->y
= lower
->y
;
23322 /* The lower end of the intersection is the minimum of the lower
23323 ends of upper and lower. */
23324 result
->height
= (min (lower
->y
+ lower
->height
,
23325 upper
->y
+ upper
->height
)
23327 intersection_p
= 1;
23331 return intersection_p
;
23334 #endif /* HAVE_WINDOW_SYSTEM */
23337 /***********************************************************************
23339 ***********************************************************************/
23344 Vwith_echo_area_save_vector
= Qnil
;
23345 staticpro (&Vwith_echo_area_save_vector
);
23347 Vmessage_stack
= Qnil
;
23348 staticpro (&Vmessage_stack
);
23350 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23351 staticpro (&Qinhibit_redisplay
);
23353 message_dolog_marker1
= Fmake_marker ();
23354 staticpro (&message_dolog_marker1
);
23355 message_dolog_marker2
= Fmake_marker ();
23356 staticpro (&message_dolog_marker2
);
23357 message_dolog_marker3
= Fmake_marker ();
23358 staticpro (&message_dolog_marker3
);
23361 defsubr (&Sdump_frame_glyph_matrix
);
23362 defsubr (&Sdump_glyph_matrix
);
23363 defsubr (&Sdump_glyph_row
);
23364 defsubr (&Sdump_tool_bar_row
);
23365 defsubr (&Strace_redisplay
);
23366 defsubr (&Strace_to_stderr
);
23368 #ifdef HAVE_WINDOW_SYSTEM
23369 defsubr (&Stool_bar_lines_needed
);
23370 defsubr (&Slookup_image_map
);
23372 defsubr (&Sformat_mode_line
);
23374 staticpro (&Qmenu_bar_update_hook
);
23375 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23377 staticpro (&Qoverriding_terminal_local_map
);
23378 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23380 staticpro (&Qoverriding_local_map
);
23381 Qoverriding_local_map
= intern ("overriding-local-map");
23383 staticpro (&Qwindow_scroll_functions
);
23384 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23386 staticpro (&Qredisplay_end_trigger_functions
);
23387 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23389 staticpro (&Qinhibit_point_motion_hooks
);
23390 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23392 QCdata
= intern (":data");
23393 staticpro (&QCdata
);
23394 Qdisplay
= intern ("display");
23395 staticpro (&Qdisplay
);
23396 Qspace_width
= intern ("space-width");
23397 staticpro (&Qspace_width
);
23398 Qraise
= intern ("raise");
23399 staticpro (&Qraise
);
23400 Qslice
= intern ("slice");
23401 staticpro (&Qslice
);
23402 Qspace
= intern ("space");
23403 staticpro (&Qspace
);
23404 Qmargin
= intern ("margin");
23405 staticpro (&Qmargin
);
23406 Qpointer
= intern ("pointer");
23407 staticpro (&Qpointer
);
23408 Qleft_margin
= intern ("left-margin");
23409 staticpro (&Qleft_margin
);
23410 Qright_margin
= intern ("right-margin");
23411 staticpro (&Qright_margin
);
23412 Qcenter
= intern ("center");
23413 staticpro (&Qcenter
);
23414 Qline_height
= intern ("line-height");
23415 staticpro (&Qline_height
);
23416 QCalign_to
= intern (":align-to");
23417 staticpro (&QCalign_to
);
23418 QCrelative_width
= intern (":relative-width");
23419 staticpro (&QCrelative_width
);
23420 QCrelative_height
= intern (":relative-height");
23421 staticpro (&QCrelative_height
);
23422 QCeval
= intern (":eval");
23423 staticpro (&QCeval
);
23424 QCpropertize
= intern (":propertize");
23425 staticpro (&QCpropertize
);
23426 QCfile
= intern (":file");
23427 staticpro (&QCfile
);
23428 Qfontified
= intern ("fontified");
23429 staticpro (&Qfontified
);
23430 Qfontification_functions
= intern ("fontification-functions");
23431 staticpro (&Qfontification_functions
);
23432 Qtrailing_whitespace
= intern ("trailing-whitespace");
23433 staticpro (&Qtrailing_whitespace
);
23434 Qescape_glyph
= intern ("escape-glyph");
23435 staticpro (&Qescape_glyph
);
23436 Qnobreak_space
= intern ("nobreak-space");
23437 staticpro (&Qnobreak_space
);
23438 Qimage
= intern ("image");
23439 staticpro (&Qimage
);
23440 QCmap
= intern (":map");
23441 staticpro (&QCmap
);
23442 QCpointer
= intern (":pointer");
23443 staticpro (&QCpointer
);
23444 Qrect
= intern ("rect");
23445 staticpro (&Qrect
);
23446 Qcircle
= intern ("circle");
23447 staticpro (&Qcircle
);
23448 Qpoly
= intern ("poly");
23449 staticpro (&Qpoly
);
23450 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23451 staticpro (&Qmessage_truncate_lines
);
23452 Qgrow_only
= intern ("grow-only");
23453 staticpro (&Qgrow_only
);
23454 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23455 staticpro (&Qinhibit_menubar_update
);
23456 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23457 staticpro (&Qinhibit_eval_during_redisplay
);
23458 Qposition
= intern ("position");
23459 staticpro (&Qposition
);
23460 Qbuffer_position
= intern ("buffer-position");
23461 staticpro (&Qbuffer_position
);
23462 Qobject
= intern ("object");
23463 staticpro (&Qobject
);
23464 Qbar
= intern ("bar");
23466 Qhbar
= intern ("hbar");
23467 staticpro (&Qhbar
);
23468 Qbox
= intern ("box");
23470 Qhollow
= intern ("hollow");
23471 staticpro (&Qhollow
);
23472 Qhand
= intern ("hand");
23473 staticpro (&Qhand
);
23474 Qarrow
= intern ("arrow");
23475 staticpro (&Qarrow
);
23476 Qtext
= intern ("text");
23477 staticpro (&Qtext
);
23478 Qrisky_local_variable
= intern ("risky-local-variable");
23479 staticpro (&Qrisky_local_variable
);
23480 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23481 staticpro (&Qinhibit_free_realized_faces
);
23483 list_of_error
= Fcons (Fcons (intern ("error"),
23484 Fcons (intern ("void-variable"), Qnil
)),
23486 staticpro (&list_of_error
);
23488 Qlast_arrow_position
= intern ("last-arrow-position");
23489 staticpro (&Qlast_arrow_position
);
23490 Qlast_arrow_string
= intern ("last-arrow-string");
23491 staticpro (&Qlast_arrow_string
);
23493 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23494 staticpro (&Qoverlay_arrow_string
);
23495 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23496 staticpro (&Qoverlay_arrow_bitmap
);
23498 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23499 staticpro (&echo_buffer
[0]);
23500 staticpro (&echo_buffer
[1]);
23502 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23503 staticpro (&echo_area_buffer
[0]);
23504 staticpro (&echo_area_buffer
[1]);
23506 Vmessages_buffer_name
= build_string ("*Messages*");
23507 staticpro (&Vmessages_buffer_name
);
23509 mode_line_proptrans_alist
= Qnil
;
23510 staticpro (&mode_line_proptrans_alist
);
23511 mode_line_string_list
= Qnil
;
23512 staticpro (&mode_line_string_list
);
23513 mode_line_string_face
= Qnil
;
23514 staticpro (&mode_line_string_face
);
23515 mode_line_string_face_prop
= Qnil
;
23516 staticpro (&mode_line_string_face_prop
);
23517 Vmode_line_unwind_vector
= Qnil
;
23518 staticpro (&Vmode_line_unwind_vector
);
23520 help_echo_string
= Qnil
;
23521 staticpro (&help_echo_string
);
23522 help_echo_object
= Qnil
;
23523 staticpro (&help_echo_object
);
23524 help_echo_window
= Qnil
;
23525 staticpro (&help_echo_window
);
23526 previous_help_echo_string
= Qnil
;
23527 staticpro (&previous_help_echo_string
);
23528 help_echo_pos
= -1;
23530 #ifdef HAVE_WINDOW_SYSTEM
23531 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23532 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23533 For example, if a block cursor is over a tab, it will be drawn as
23534 wide as that tab on the display. */);
23535 x_stretch_cursor_p
= 0;
23538 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23539 doc
: /* *Non-nil means highlight trailing whitespace.
23540 The face used for trailing whitespace is `trailing-whitespace'. */);
23541 Vshow_trailing_whitespace
= Qnil
;
23543 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23544 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23545 A value of t means highlight the character itself (for nobreak space,
23546 use face `nobreak-space').
23547 A value of nil means no highlighting.
23548 Other values mean display the escape glyph followed by an ordinary
23549 space or ordinary hyphen. */);
23550 Vnobreak_char_display
= Qt
;
23552 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23553 doc
: /* *The pointer shape to show in void text areas.
23554 A value of nil means to show the text pointer. Other options are `arrow',
23555 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23556 Vvoid_text_area_pointer
= Qarrow
;
23558 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23559 doc
: /* Non-nil means don't actually do any redisplay.
23560 This is used for internal purposes. */);
23561 Vinhibit_redisplay
= Qnil
;
23563 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23564 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23565 Vglobal_mode_string
= Qnil
;
23567 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23568 doc
: /* Marker for where to display an arrow on top of the buffer text.
23569 This must be the beginning of a line in order to work.
23570 See also `overlay-arrow-string'. */);
23571 Voverlay_arrow_position
= Qnil
;
23573 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23574 doc
: /* String to display as an arrow in non-window frames.
23575 See also `overlay-arrow-position'. */);
23576 Voverlay_arrow_string
= build_string ("=>");
23578 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23579 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23580 The symbols on this list are examined during redisplay to determine
23581 where to display overlay arrows. */);
23582 Voverlay_arrow_variable_list
23583 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23585 DEFVAR_INT ("scroll-step", &scroll_step
,
23586 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23587 If that fails to bring point back on frame, point is centered instead.
23588 If this is zero, point is always centered after it moves off frame.
23589 If you want scrolling to always be a line at a time, you should set
23590 `scroll-conservatively' to a large value rather than set this to 1. */);
23592 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23593 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23594 A value of zero means to scroll the text to center point vertically
23595 in the window. */);
23596 scroll_conservatively
= 0;
23598 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23599 doc
: /* *Number of lines of margin at the top and bottom of a window.
23600 Recenter the window whenever point gets within this many lines
23601 of the top or bottom of the window. */);
23604 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23605 doc
: /* Pixels per inch value for non-window system displays.
23606 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23607 Vdisplay_pixels_per_inch
= make_float (72.0);
23610 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23613 DEFVAR_BOOL ("truncate-partial-width-windows",
23614 &truncate_partial_width_windows
,
23615 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23616 truncate_partial_width_windows
= 1;
23618 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23619 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23620 Any other value means to use the appropriate face, `mode-line',
23621 `header-line', or `menu' respectively. */);
23622 mode_line_inverse_video
= 1;
23624 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23625 doc
: /* *Maximum buffer size for which line number should be displayed.
23626 If the buffer is bigger than this, the line number does not appear
23627 in the mode line. A value of nil means no limit. */);
23628 Vline_number_display_limit
= Qnil
;
23630 DEFVAR_INT ("line-number-display-limit-width",
23631 &line_number_display_limit_width
,
23632 doc
: /* *Maximum line width (in characters) for line number display.
23633 If the average length of the lines near point is bigger than this, then the
23634 line number may be omitted from the mode line. */);
23635 line_number_display_limit_width
= 200;
23637 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23638 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23639 highlight_nonselected_windows
= 0;
23641 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23642 doc
: /* Non-nil if more than one frame is visible on this display.
23643 Minibuffer-only frames don't count, but iconified frames do.
23644 This variable is not guaranteed to be accurate except while processing
23645 `frame-title-format' and `icon-title-format'. */);
23647 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23648 doc
: /* Template for displaying the title bar of visible frames.
23649 \(Assuming the window manager supports this feature.)
23650 This variable has the same structure as `mode-line-format' (which see),
23651 and is used only on frames for which no explicit name has been set
23652 \(see `modify-frame-parameters'). */);
23654 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23655 doc
: /* Template for displaying the title bar of an iconified frame.
23656 \(Assuming the window manager supports this feature.)
23657 This variable has the same structure as `mode-line-format' (which see),
23658 and is used only on frames for which no explicit name has been set
23659 \(see `modify-frame-parameters'). */);
23661 = Vframe_title_format
23662 = Fcons (intern ("multiple-frames"),
23663 Fcons (build_string ("%b"),
23664 Fcons (Fcons (empty_string
,
23665 Fcons (intern ("invocation-name"),
23666 Fcons (build_string ("@"),
23667 Fcons (intern ("system-name"),
23671 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23672 doc
: /* Maximum number of lines to keep in the message log buffer.
23673 If nil, disable message logging. If t, log messages but don't truncate
23674 the buffer when it becomes large. */);
23675 Vmessage_log_max
= make_number (50);
23677 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23678 doc
: /* Functions called before redisplay, if window sizes have changed.
23679 The value should be a list of functions that take one argument.
23680 Just before redisplay, for each frame, if any of its windows have changed
23681 size since the last redisplay, or have been split or deleted,
23682 all the functions in the list are called, with the frame as argument. */);
23683 Vwindow_size_change_functions
= Qnil
;
23685 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23686 doc
: /* List of functions to call before redisplaying a window with scrolling.
23687 Each function is called with two arguments, the window
23688 and its new display-start position. Note that the value of `window-end'
23689 is not valid when these functions are called. */);
23690 Vwindow_scroll_functions
= Qnil
;
23692 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23693 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23694 Each function is called with two arguments, the window and the end trigger value.
23695 See `set-window-redisplay-end-trigger'. */);
23696 Vredisplay_end_trigger_functions
= Qnil
;
23698 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23699 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23700 mouse_autoselect_window
= 0;
23702 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23703 doc
: /* *Non-nil means automatically resize tool-bars.
23704 This increases a tool-bar's height if not all tool-bar items are visible.
23705 It decreases a tool-bar's height when it would display blank lines
23707 auto_resize_tool_bars_p
= 1;
23709 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23710 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23711 auto_raise_tool_bar_buttons_p
= 1;
23713 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23714 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23715 make_cursor_line_fully_visible_p
= 1;
23717 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
23718 doc
: /* *Border below tool-bar in pixels.
23719 If an integer, use it as the height of the border.
23720 If it is one of `internal-border-width' or `border-width', use the
23721 value of the corresponding frame parameter.
23722 Otherwise, no border is added below the tool-bar. */);
23723 Vtool_bar_border
= Qinternal_border_width
;
23725 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23726 doc
: /* *Margin around tool-bar buttons in pixels.
23727 If an integer, use that for both horizontal and vertical margins.
23728 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23729 HORZ specifying the horizontal margin, and VERT specifying the
23730 vertical margin. */);
23731 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23733 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23734 doc
: /* *Relief thickness of tool-bar buttons. */);
23735 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23737 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23738 doc
: /* List of functions to call to fontify regions of text.
23739 Each function is called with one argument POS. Functions must
23740 fontify a region starting at POS in the current buffer, and give
23741 fontified regions the property `fontified'. */);
23742 Vfontification_functions
= Qnil
;
23743 Fmake_variable_buffer_local (Qfontification_functions
);
23745 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23746 &unibyte_display_via_language_environment
,
23747 doc
: /* *Non-nil means display unibyte text according to language environment.
23748 Specifically this means that unibyte non-ASCII characters
23749 are displayed by converting them to the equivalent multibyte characters
23750 according to the current language environment. As a result, they are
23751 displayed according to the current fontset. */);
23752 unibyte_display_via_language_environment
= 0;
23754 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23755 doc
: /* *Maximum height for resizing mini-windows.
23756 If a float, it specifies a fraction of the mini-window frame's height.
23757 If an integer, it specifies a number of lines. */);
23758 Vmax_mini_window_height
= make_float (0.25);
23760 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23761 doc
: /* *How to resize mini-windows.
23762 A value of nil means don't automatically resize mini-windows.
23763 A value of t means resize them to fit the text displayed in them.
23764 A value of `grow-only', the default, means let mini-windows grow
23765 only, until their display becomes empty, at which point the windows
23766 go back to their normal size. */);
23767 Vresize_mini_windows
= Qgrow_only
;
23769 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23770 doc
: /* Alist specifying how to blink the cursor off.
23771 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23772 `cursor-type' frame-parameter or variable equals ON-STATE,
23773 comparing using `equal', Emacs uses OFF-STATE to specify
23774 how to blink it off. ON-STATE and OFF-STATE are values for
23775 the `cursor-type' frame parameter.
23777 If a frame's ON-STATE has no entry in this list,
23778 the frame's other specifications determine how to blink the cursor off. */);
23779 Vblink_cursor_alist
= Qnil
;
23781 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23782 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23783 automatic_hscrolling_p
= 1;
23785 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23786 doc
: /* *How many columns away from the window edge point is allowed to get
23787 before automatic hscrolling will horizontally scroll the window. */);
23788 hscroll_margin
= 5;
23790 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23791 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23792 When point is less than `automatic-hscroll-margin' columns from the window
23793 edge, automatic hscrolling will scroll the window by the amount of columns
23794 determined by this variable. If its value is a positive integer, scroll that
23795 many columns. If it's a positive floating-point number, it specifies the
23796 fraction of the window's width to scroll. If it's nil or zero, point will be
23797 centered horizontally after the scroll. Any other value, including negative
23798 numbers, are treated as if the value were zero.
23800 Automatic hscrolling always moves point outside the scroll margin, so if
23801 point was more than scroll step columns inside the margin, the window will
23802 scroll more than the value given by the scroll step.
23804 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23805 and `scroll-right' overrides this variable's effect. */);
23806 Vhscroll_step
= make_number (0);
23808 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23809 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23810 Bind this around calls to `message' to let it take effect. */);
23811 message_truncate_lines
= 0;
23813 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23814 doc
: /* Normal hook run to update the menu bar definitions.
23815 Redisplay runs this hook before it redisplays the menu bar.
23816 This is used to update submenus such as Buffers,
23817 whose contents depend on various data. */);
23818 Vmenu_bar_update_hook
= Qnil
;
23820 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23821 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23822 inhibit_menubar_update
= 0;
23824 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23825 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23826 inhibit_eval_during_redisplay
= 0;
23828 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23829 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23830 inhibit_free_realized_faces
= 0;
23833 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23834 doc
: /* Inhibit try_window_id display optimization. */);
23835 inhibit_try_window_id
= 0;
23837 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23838 doc
: /* Inhibit try_window_reusing display optimization. */);
23839 inhibit_try_window_reusing
= 0;
23841 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23842 doc
: /* Inhibit try_cursor_movement display optimization. */);
23843 inhibit_try_cursor_movement
= 0;
23844 #endif /* GLYPH_DEBUG */
23848 /* Initialize this module when Emacs starts. */
23853 Lisp_Object root_window
;
23854 struct window
*mini_w
;
23856 current_header_line_height
= current_mode_line_height
= -1;
23858 CHARPOS (this_line_start_pos
) = 0;
23860 mini_w
= XWINDOW (minibuf_window
);
23861 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23863 if (!noninteractive
)
23865 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23868 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23869 set_window_height (root_window
,
23870 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23872 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23873 set_window_height (minibuf_window
, 1, 0);
23875 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23876 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23878 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23879 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23880 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23882 /* The default ellipsis glyphs `...'. */
23883 for (i
= 0; i
< 3; ++i
)
23884 default_invis_vector
[i
] = make_number ('.');
23888 /* Allocate the buffer for frame titles.
23889 Also used for `format-mode-line'. */
23891 mode_line_noprop_buf
= (char *) xmalloc (size
);
23892 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23893 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23894 mode_line_target
= MODE_LINE_DISPLAY
;
23897 help_echo_showing_p
= 0;
23901 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23902 (do not change this comment) */