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 /* Space between overline and text. */
715 EMACS_INT overline_margin
;
717 /* Value returned from text property handlers (see below). */
722 HANDLED_RECOMPUTE_PROPS
,
723 HANDLED_OVERLAY_STRING_CONSUMED
,
727 /* A description of text properties that redisplay is interested
732 /* The name of the property. */
735 /* A unique index for the property. */
738 /* A handler function called to set up iterator IT from the property
739 at IT's current position. Value is used to steer handle_stop. */
740 enum prop_handled (*handler
) P_ ((struct it
*it
));
743 static enum prop_handled handle_face_prop
P_ ((struct it
*));
744 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
745 static enum prop_handled handle_display_prop
P_ ((struct it
*));
746 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
747 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
748 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
750 /* Properties handled by iterators. */
752 static struct props it_props
[] =
754 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
755 /* Handle `face' before `display' because some sub-properties of
756 `display' need to know the face. */
757 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
758 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
759 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
760 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
764 /* Value is the position described by X. If X is a marker, value is
765 the marker_position of X. Otherwise, value is X. */
767 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
769 /* Enumeration returned by some move_it_.* functions internally. */
773 /* Not used. Undefined value. */
776 /* Move ended at the requested buffer position or ZV. */
777 MOVE_POS_MATCH_OR_ZV
,
779 /* Move ended at the requested X pixel position. */
782 /* Move within a line ended at the end of a line that must be
786 /* Move within a line ended at the end of a line that would
787 be displayed truncated. */
790 /* Move within a line ended at a line end. */
794 /* This counter is used to clear the face cache every once in a while
795 in redisplay_internal. It is incremented for each redisplay.
796 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
799 #define CLEAR_FACE_CACHE_COUNT 500
800 static int clear_face_cache_count
;
802 /* Similarly for the image cache. */
804 #ifdef HAVE_WINDOW_SYSTEM
805 #define CLEAR_IMAGE_CACHE_COUNT 101
806 static int clear_image_cache_count
;
809 /* Record the previous terminal frame we displayed. */
811 static struct frame
*previous_terminal_frame
;
813 /* Non-zero while redisplay_internal is in progress. */
817 /* Non-zero means don't free realized faces. Bound while freeing
818 realized faces is dangerous because glyph matrices might still
821 int inhibit_free_realized_faces
;
822 Lisp_Object Qinhibit_free_realized_faces
;
824 /* If a string, XTread_socket generates an event to display that string.
825 (The display is done in read_char.) */
827 Lisp_Object help_echo_string
;
828 Lisp_Object help_echo_window
;
829 Lisp_Object help_echo_object
;
832 /* Temporary variable for XTread_socket. */
834 Lisp_Object previous_help_echo_string
;
836 /* Null glyph slice */
838 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
841 /* Function prototypes. */
843 static void setup_for_ellipsis
P_ ((struct it
*, int));
844 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
845 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
846 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
847 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
848 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
849 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
852 static int invisible_text_between_p
P_ ((struct it
*, int, int));
855 static void pint2str
P_ ((char *, int, int));
856 static void pint2hrstr
P_ ((char *, int, int));
857 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
859 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
860 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
861 static void store_mode_line_noprop_char
P_ ((char));
862 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
863 static void x_consider_frame_title
P_ ((Lisp_Object
));
864 static void handle_stop
P_ ((struct it
*));
865 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
866 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
867 static void ensure_echo_area_buffers
P_ ((void));
868 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
869 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
870 static int with_echo_area_buffer
P_ ((struct window
*, int,
871 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
872 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
873 static void clear_garbaged_frames
P_ ((void));
874 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
875 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
876 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
877 static int display_echo_area
P_ ((struct window
*));
878 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
879 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
880 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
881 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
882 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
884 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
885 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
886 static void insert_left_trunc_glyphs
P_ ((struct it
*));
887 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
889 static void extend_face_to_end_of_line
P_ ((struct it
*));
890 static int append_space_for_newline
P_ ((struct it
*, int));
891 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
892 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
893 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
894 static int trailing_whitespace_p
P_ ((int));
895 static int message_log_check_duplicate
P_ ((int, int, int, int));
896 static void push_it
P_ ((struct it
*));
897 static void pop_it
P_ ((struct it
*));
898 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
899 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
900 static void redisplay_internal
P_ ((int));
901 static int echo_area_display
P_ ((int));
902 static void redisplay_windows
P_ ((Lisp_Object
));
903 static void redisplay_window
P_ ((Lisp_Object
, int));
904 static Lisp_Object
redisplay_window_error ();
905 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
906 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
907 static int update_menu_bar
P_ ((struct frame
*, int, int));
908 static int try_window_reusing_current_matrix
P_ ((struct window
*));
909 static int try_window_id
P_ ((struct window
*));
910 static int display_line
P_ ((struct it
*));
911 static int display_mode_lines
P_ ((struct window
*));
912 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
913 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
914 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
915 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
916 static void display_menu_bar
P_ ((struct window
*));
917 static int display_count_lines
P_ ((int, int, int, int, int *));
918 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
919 int, int, struct it
*, int, int, int, int));
920 static void compute_line_metrics
P_ ((struct it
*));
921 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
922 static int get_overlay_strings
P_ ((struct it
*, int));
923 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
924 static void next_overlay_string
P_ ((struct it
*));
925 static void reseat
P_ ((struct it
*, struct text_pos
, int));
926 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
927 static void back_to_previous_visible_line_start
P_ ((struct it
*));
928 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
929 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
930 static int next_element_from_ellipsis
P_ ((struct it
*));
931 static int next_element_from_display_vector
P_ ((struct it
*));
932 static int next_element_from_string
P_ ((struct it
*));
933 static int next_element_from_c_string
P_ ((struct it
*));
934 static int next_element_from_buffer
P_ ((struct it
*));
935 static int next_element_from_composition
P_ ((struct it
*));
936 static int next_element_from_image
P_ ((struct it
*));
937 static int next_element_from_stretch
P_ ((struct it
*));
938 static void load_overlay_strings
P_ ((struct it
*, int));
939 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
940 struct display_pos
*));
941 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
942 Lisp_Object
, int, int, int, int));
943 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
945 void move_it_vertically_backward
P_ ((struct it
*, int));
946 static void init_to_row_start
P_ ((struct it
*, struct window
*,
947 struct glyph_row
*));
948 static int init_to_row_end
P_ ((struct it
*, struct window
*,
949 struct glyph_row
*));
950 static void back_to_previous_line_start
P_ ((struct it
*));
951 static int forward_to_next_line_start
P_ ((struct it
*, int *));
952 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
954 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
955 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
956 static int number_of_chars
P_ ((unsigned char *, int));
957 static void compute_stop_pos
P_ ((struct it
*));
958 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
960 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
961 static int next_overlay_change
P_ ((int));
962 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
963 Lisp_Object
, struct text_pos
*,
965 static int underlying_face_id
P_ ((struct it
*));
966 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
969 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
970 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
972 #ifdef HAVE_WINDOW_SYSTEM
974 static void update_tool_bar
P_ ((struct frame
*, int));
975 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
976 static int redisplay_tool_bar
P_ ((struct frame
*));
977 static void display_tool_bar_line
P_ ((struct it
*, int));
978 static void notice_overwritten_cursor
P_ ((struct window
*,
980 int, int, int, int));
984 #endif /* HAVE_WINDOW_SYSTEM */
987 /***********************************************************************
988 Window display dimensions
989 ***********************************************************************/
991 /* Return the bottom boundary y-position for text lines in window W.
992 This is the first y position at which a line cannot start.
993 It is relative to the top of the window.
995 This is the height of W minus the height of a mode line, if any. */
998 window_text_bottom_y (w
)
1001 int height
= WINDOW_TOTAL_HEIGHT (w
);
1003 if (WINDOW_WANTS_MODELINE_P (w
))
1004 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1008 /* Return the pixel width of display area AREA of window W. AREA < 0
1009 means return the total width of W, not including fringes to
1010 the left and right of the window. */
1013 window_box_width (w
, area
)
1017 int cols
= XFASTINT (w
->total_cols
);
1020 if (!w
->pseudo_window_p
)
1022 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1024 if (area
== TEXT_AREA
)
1026 if (INTEGERP (w
->left_margin_cols
))
1027 cols
-= XFASTINT (w
->left_margin_cols
);
1028 if (INTEGERP (w
->right_margin_cols
))
1029 cols
-= XFASTINT (w
->right_margin_cols
);
1030 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1032 else if (area
== LEFT_MARGIN_AREA
)
1034 cols
= (INTEGERP (w
->left_margin_cols
)
1035 ? XFASTINT (w
->left_margin_cols
) : 0);
1038 else if (area
== RIGHT_MARGIN_AREA
)
1040 cols
= (INTEGERP (w
->right_margin_cols
)
1041 ? XFASTINT (w
->right_margin_cols
) : 0);
1046 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1050 /* Return the pixel height of the display area of window W, not
1051 including mode lines of W, if any. */
1054 window_box_height (w
)
1057 struct frame
*f
= XFRAME (w
->frame
);
1058 int height
= WINDOW_TOTAL_HEIGHT (w
);
1060 xassert (height
>= 0);
1062 /* Note: the code below that determines the mode-line/header-line
1063 height is essentially the same as that contained in the macro
1064 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1065 the appropriate glyph row has its `mode_line_p' flag set,
1066 and if it doesn't, uses estimate_mode_line_height instead. */
1068 if (WINDOW_WANTS_MODELINE_P (w
))
1070 struct glyph_row
*ml_row
1071 = (w
->current_matrix
&& w
->current_matrix
->rows
1072 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1074 if (ml_row
&& ml_row
->mode_line_p
)
1075 height
-= ml_row
->height
;
1077 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1080 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1082 struct glyph_row
*hl_row
1083 = (w
->current_matrix
&& w
->current_matrix
->rows
1084 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1086 if (hl_row
&& hl_row
->mode_line_p
)
1087 height
-= hl_row
->height
;
1089 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1092 /* With a very small font and a mode-line that's taller than
1093 default, we might end up with a negative height. */
1094 return max (0, height
);
1097 /* Return the window-relative coordinate of the left edge of display
1098 area AREA of window W. AREA < 0 means return the left edge of the
1099 whole window, to the right of the left fringe of W. */
1102 window_box_left_offset (w
, area
)
1108 if (w
->pseudo_window_p
)
1111 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1113 if (area
== TEXT_AREA
)
1114 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1115 + window_box_width (w
, LEFT_MARGIN_AREA
));
1116 else if (area
== RIGHT_MARGIN_AREA
)
1117 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1118 + window_box_width (w
, LEFT_MARGIN_AREA
)
1119 + window_box_width (w
, TEXT_AREA
)
1120 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1122 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1123 else if (area
== LEFT_MARGIN_AREA
1124 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1125 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1131 /* Return the window-relative coordinate of the right edge of display
1132 area AREA of window W. AREA < 0 means return the left edge of the
1133 whole window, to the left of the right fringe of W. */
1136 window_box_right_offset (w
, area
)
1140 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1143 /* Return the frame-relative coordinate of the left edge of display
1144 area AREA of window W. AREA < 0 means return the left edge of the
1145 whole window, to the right of the left fringe of W. */
1148 window_box_left (w
, area
)
1152 struct frame
*f
= XFRAME (w
->frame
);
1155 if (w
->pseudo_window_p
)
1156 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1158 x
= (WINDOW_LEFT_EDGE_X (w
)
1159 + window_box_left_offset (w
, area
));
1165 /* Return the frame-relative coordinate of the right edge of display
1166 area AREA of window W. AREA < 0 means return the left edge of the
1167 whole window, to the left of the right fringe of W. */
1170 window_box_right (w
, area
)
1174 return window_box_left (w
, area
) + window_box_width (w
, area
);
1177 /* Get the bounding box of the display area AREA of window W, without
1178 mode lines, in frame-relative coordinates. AREA < 0 means the
1179 whole window, not including the left and right fringes of
1180 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1181 coordinates of the upper-left corner of the box. Return in
1182 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1185 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1188 int *box_x
, *box_y
, *box_width
, *box_height
;
1191 *box_width
= window_box_width (w
, area
);
1193 *box_height
= window_box_height (w
);
1195 *box_x
= window_box_left (w
, area
);
1198 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1199 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1200 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1205 /* Get the bounding box of the display area AREA of window W, without
1206 mode lines. AREA < 0 means the whole window, not including the
1207 left and right fringe of the window. Return in *TOP_LEFT_X
1208 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1209 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1210 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1214 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1215 bottom_right_x
, bottom_right_y
)
1218 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1220 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1222 *bottom_right_x
+= *top_left_x
;
1223 *bottom_right_y
+= *top_left_y
;
1228 /***********************************************************************
1230 ***********************************************************************/
1232 /* Return the bottom y-position of the line the iterator IT is in.
1233 This can modify IT's settings. */
1239 int line_height
= it
->max_ascent
+ it
->max_descent
;
1240 int line_top_y
= it
->current_y
;
1242 if (line_height
== 0)
1245 line_height
= last_height
;
1246 else if (IT_CHARPOS (*it
) < ZV
)
1248 move_it_by_lines (it
, 1, 1);
1249 line_height
= (it
->max_ascent
|| it
->max_descent
1250 ? it
->max_ascent
+ it
->max_descent
1255 struct glyph_row
*row
= it
->glyph_row
;
1257 /* Use the default character height. */
1258 it
->glyph_row
= NULL
;
1259 it
->what
= IT_CHARACTER
;
1262 PRODUCE_GLYPHS (it
);
1263 line_height
= it
->ascent
+ it
->descent
;
1264 it
->glyph_row
= row
;
1268 return line_top_y
+ line_height
;
1272 /* Return 1 if position CHARPOS is visible in window W.
1273 If visible, set *X and *Y to pixel coordinates of top left corner.
1274 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1275 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1278 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1280 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1283 struct text_pos top
;
1285 struct buffer
*old_buffer
= NULL
;
1290 if (XBUFFER (w
->buffer
) != current_buffer
)
1292 old_buffer
= current_buffer
;
1293 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1296 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1298 /* Compute exact mode line heights. */
1299 if (WINDOW_WANTS_MODELINE_P (w
))
1300 current_mode_line_height
1301 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1302 current_buffer
->mode_line_format
);
1304 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1305 current_header_line_height
1306 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1307 current_buffer
->header_line_format
);
1309 start_display (&it
, w
, top
);
1310 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1311 MOVE_TO_POS
| MOVE_TO_Y
);
1313 /* Note that we may overshoot because of invisible text. */
1314 if (IT_CHARPOS (it
) >= charpos
)
1316 int top_x
= it
.current_x
;
1317 int top_y
= it
.current_y
;
1318 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1319 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1321 if (top_y
< window_top_y
)
1322 visible_p
= bottom_y
> window_top_y
;
1323 else if (top_y
< it
.last_visible_y
)
1328 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1329 *rtop
= max (0, window_top_y
- top_y
);
1330 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1331 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1332 - max (top_y
, window_top_y
)));
1341 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1342 move_it_by_lines (&it
, 1, 0);
1343 if (charpos
< IT_CHARPOS (it
))
1346 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1348 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1349 *rtop
= max (0, -it2
.current_y
);
1350 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1351 - it
.last_visible_y
));
1352 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1354 - max (it2
.current_y
,
1355 WINDOW_HEADER_LINE_HEIGHT (w
))));
1361 set_buffer_internal_1 (old_buffer
);
1363 current_header_line_height
= current_mode_line_height
= -1;
1365 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1366 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1369 /* Debugging code. */
1371 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1372 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1374 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1381 /* Return the next character from STR which is MAXLEN bytes long.
1382 Return in *LEN the length of the character. This is like
1383 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1384 we find one, we return a `?', but with the length of the invalid
1388 string_char_and_length (str
, maxlen
, len
)
1389 const unsigned char *str
;
1394 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1395 if (!CHAR_VALID_P (c
, 1))
1396 /* We may not change the length here because other places in Emacs
1397 don't use this function, i.e. they silently accept invalid
1406 /* Given a position POS containing a valid character and byte position
1407 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1409 static struct text_pos
1410 string_pos_nchars_ahead (pos
, string
, nchars
)
1411 struct text_pos pos
;
1415 xassert (STRINGP (string
) && nchars
>= 0);
1417 if (STRING_MULTIBYTE (string
))
1419 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1420 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1425 string_char_and_length (p
, rest
, &len
);
1426 p
+= len
, rest
-= len
;
1427 xassert (rest
>= 0);
1429 BYTEPOS (pos
) += len
;
1433 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1439 /* Value is the text position, i.e. character and byte position,
1440 for character position CHARPOS in STRING. */
1442 static INLINE
struct text_pos
1443 string_pos (charpos
, string
)
1447 struct text_pos pos
;
1448 xassert (STRINGP (string
));
1449 xassert (charpos
>= 0);
1450 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1455 /* Value is a text position, i.e. character and byte position, for
1456 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1457 means recognize multibyte characters. */
1459 static struct text_pos
1460 c_string_pos (charpos
, s
, multibyte_p
)
1465 struct text_pos pos
;
1467 xassert (s
!= NULL
);
1468 xassert (charpos
>= 0);
1472 int rest
= strlen (s
), len
;
1474 SET_TEXT_POS (pos
, 0, 0);
1477 string_char_and_length (s
, rest
, &len
);
1478 s
+= len
, rest
-= len
;
1479 xassert (rest
>= 0);
1481 BYTEPOS (pos
) += len
;
1485 SET_TEXT_POS (pos
, charpos
, charpos
);
1491 /* Value is the number of characters in C string S. MULTIBYTE_P
1492 non-zero means recognize multibyte characters. */
1495 number_of_chars (s
, multibyte_p
)
1503 int rest
= strlen (s
), len
;
1504 unsigned char *p
= (unsigned char *) s
;
1506 for (nchars
= 0; rest
> 0; ++nchars
)
1508 string_char_and_length (p
, rest
, &len
);
1509 rest
-= len
, p
+= len
;
1513 nchars
= strlen (s
);
1519 /* Compute byte position NEWPOS->bytepos corresponding to
1520 NEWPOS->charpos. POS is a known position in string STRING.
1521 NEWPOS->charpos must be >= POS.charpos. */
1524 compute_string_pos (newpos
, pos
, string
)
1525 struct text_pos
*newpos
, pos
;
1528 xassert (STRINGP (string
));
1529 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1531 if (STRING_MULTIBYTE (string
))
1532 *newpos
= string_pos_nchars_ahead (pos
, string
,
1533 CHARPOS (*newpos
) - CHARPOS (pos
));
1535 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1539 Return an estimation of the pixel height of mode or top lines on
1540 frame F. FACE_ID specifies what line's height to estimate. */
1543 estimate_mode_line_height (f
, face_id
)
1545 enum face_id face_id
;
1547 #ifdef HAVE_WINDOW_SYSTEM
1548 if (FRAME_WINDOW_P (f
))
1550 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1552 /* This function is called so early when Emacs starts that the face
1553 cache and mode line face are not yet initialized. */
1554 if (FRAME_FACE_CACHE (f
))
1556 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1560 height
= FONT_HEIGHT (face
->font
);
1561 if (face
->box_line_width
> 0)
1562 height
+= 2 * face
->box_line_width
;
1573 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1574 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1575 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1576 not force the value into range. */
1579 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1581 register int pix_x
, pix_y
;
1583 NativeRectangle
*bounds
;
1587 #ifdef HAVE_WINDOW_SYSTEM
1588 if (FRAME_WINDOW_P (f
))
1590 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1591 even for negative values. */
1593 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1595 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1597 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1598 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1601 STORE_NATIVE_RECT (*bounds
,
1602 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1603 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1604 FRAME_COLUMN_WIDTH (f
) - 1,
1605 FRAME_LINE_HEIGHT (f
) - 1);
1611 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1612 pix_x
= FRAME_TOTAL_COLS (f
);
1616 else if (pix_y
> FRAME_LINES (f
))
1617 pix_y
= FRAME_LINES (f
);
1627 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1628 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1629 can't tell the positions because W's display is not up to date,
1633 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1636 int *frame_x
, *frame_y
;
1638 #ifdef HAVE_WINDOW_SYSTEM
1639 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1643 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1644 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1646 if (display_completed
)
1648 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1649 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1650 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1656 hpos
+= glyph
->pixel_width
;
1660 /* If first glyph is partially visible, its first visible position is still 0. */
1672 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1673 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1684 #ifdef HAVE_WINDOW_SYSTEM
1686 /* Find the glyph under window-relative coordinates X/Y in window W.
1687 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1688 strings. Return in *HPOS and *VPOS the row and column number of
1689 the glyph found. Return in *AREA the glyph area containing X.
1690 Value is a pointer to the glyph found or null if X/Y is not on
1691 text, or we can't tell because W's current matrix is not up to
1694 static struct glyph
*
1695 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1698 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1700 struct glyph
*glyph
, *end
;
1701 struct glyph_row
*row
= NULL
;
1704 /* Find row containing Y. Give up if some row is not enabled. */
1705 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1707 row
= MATRIX_ROW (w
->current_matrix
, i
);
1708 if (!row
->enabled_p
)
1710 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1717 /* Give up if Y is not in the window. */
1718 if (i
== w
->current_matrix
->nrows
)
1721 /* Get the glyph area containing X. */
1722 if (w
->pseudo_window_p
)
1729 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1731 *area
= LEFT_MARGIN_AREA
;
1732 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1734 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1737 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1741 *area
= RIGHT_MARGIN_AREA
;
1742 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1746 /* Find glyph containing X. */
1747 glyph
= row
->glyphs
[*area
];
1748 end
= glyph
+ row
->used
[*area
];
1750 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1752 x
-= glyph
->pixel_width
;
1762 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1765 *hpos
= glyph
- row
->glyphs
[*area
];
1771 Convert frame-relative x/y to coordinates relative to window W.
1772 Takes pseudo-windows into account. */
1775 frame_to_window_pixel_xy (w
, x
, y
)
1779 if (w
->pseudo_window_p
)
1781 /* A pseudo-window is always full-width, and starts at the
1782 left edge of the frame, plus a frame border. */
1783 struct frame
*f
= XFRAME (w
->frame
);
1784 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1785 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1789 *x
-= WINDOW_LEFT_EDGE_X (w
);
1790 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1795 Return in RECTS[] at most N clipping rectangles for glyph string S.
1796 Return the number of stored rectangles. */
1799 get_glyph_string_clip_rects (s
, rects
, n
)
1800 struct glyph_string
*s
;
1801 NativeRectangle
*rects
;
1809 if (s
->row
->full_width_p
)
1811 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1812 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1813 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1815 /* Unless displaying a mode or menu bar line, which are always
1816 fully visible, clip to the visible part of the row. */
1817 if (s
->w
->pseudo_window_p
)
1818 r
.height
= s
->row
->visible_height
;
1820 r
.height
= s
->height
;
1824 /* This is a text line that may be partially visible. */
1825 r
.x
= window_box_left (s
->w
, s
->area
);
1826 r
.width
= window_box_width (s
->w
, s
->area
);
1827 r
.height
= s
->row
->visible_height
;
1831 if (r
.x
< s
->clip_head
->x
)
1833 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1834 r
.width
-= s
->clip_head
->x
- r
.x
;
1837 r
.x
= s
->clip_head
->x
;
1840 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1842 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1843 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1848 /* If S draws overlapping rows, it's sufficient to use the top and
1849 bottom of the window for clipping because this glyph string
1850 intentionally draws over other lines. */
1851 if (s
->for_overlaps
)
1853 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1854 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1856 /* Alas, the above simple strategy does not work for the
1857 environments with anti-aliased text: if the same text is
1858 drawn onto the same place multiple times, it gets thicker.
1859 If the overlap we are processing is for the erased cursor, we
1860 take the intersection with the rectagle of the cursor. */
1861 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1863 XRectangle rc
, r_save
= r
;
1865 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1866 rc
.y
= s
->w
->phys_cursor
.y
;
1867 rc
.width
= s
->w
->phys_cursor_width
;
1868 rc
.height
= s
->w
->phys_cursor_height
;
1870 x_intersect_rectangles (&r_save
, &rc
, &r
);
1875 /* Don't use S->y for clipping because it doesn't take partially
1876 visible lines into account. For example, it can be negative for
1877 partially visible lines at the top of a window. */
1878 if (!s
->row
->full_width_p
1879 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1880 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1882 r
.y
= max (0, s
->row
->y
);
1884 /* If drawing a tool-bar window, draw it over the internal border
1885 at the top of the window. */
1886 if (WINDOWP (s
->f
->tool_bar_window
)
1887 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1888 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1891 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1893 /* If drawing the cursor, don't let glyph draw outside its
1894 advertised boundaries. Cleartype does this under some circumstances. */
1895 if (s
->hl
== DRAW_CURSOR
)
1897 struct glyph
*glyph
= s
->first_glyph
;
1902 r
.width
-= s
->x
- r
.x
;
1905 r
.width
= min (r
.width
, glyph
->pixel_width
);
1907 /* If r.y is below window bottom, ensure that we still see a cursor. */
1908 height
= min (glyph
->ascent
+ glyph
->descent
,
1909 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1910 max_y
= window_text_bottom_y (s
->w
) - height
;
1911 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1912 if (s
->ybase
- glyph
->ascent
> max_y
)
1919 /* Don't draw cursor glyph taller than our actual glyph. */
1920 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1921 if (height
< r
.height
)
1923 max_y
= r
.y
+ r
.height
;
1924 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1925 r
.height
= min (max_y
- r
.y
, height
);
1930 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1931 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1933 #ifdef CONVERT_FROM_XRECT
1934 CONVERT_FROM_XRECT (r
, *rects
);
1942 /* If we are processing overlapping and allowed to return
1943 multiple clipping rectangles, we exclude the row of the glyph
1944 string from the clipping rectangle. This is to avoid drawing
1945 the same text on the environment with anti-aliasing. */
1946 #ifdef CONVERT_FROM_XRECT
1949 XRectangle
*rs
= rects
;
1951 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1953 if (s
->for_overlaps
& OVERLAPS_PRED
)
1956 if (r
.y
+ r
.height
> row_y
)
1959 rs
[i
].height
= row_y
- r
.y
;
1965 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1968 if (r
.y
< row_y
+ s
->row
->visible_height
)
1970 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1972 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1973 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1982 #ifdef CONVERT_FROM_XRECT
1983 for (i
= 0; i
< n
; i
++)
1984 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1991 Return in *NR the clipping rectangle for glyph string S. */
1994 get_glyph_string_clip_rect (s
, nr
)
1995 struct glyph_string
*s
;
1996 NativeRectangle
*nr
;
1998 get_glyph_string_clip_rects (s
, nr
, 1);
2003 Return the position and height of the phys cursor in window W.
2004 Set w->phys_cursor_width to width of phys cursor.
2008 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2010 struct glyph_row
*row
;
2011 struct glyph
*glyph
;
2012 int *xp
, *yp
, *heightp
;
2014 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2015 int x
, y
, wd
, h
, h0
, y0
;
2017 /* Compute the width of the rectangle to draw. If on a stretch
2018 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2019 rectangle as wide as the glyph, but use a canonical character
2021 wd
= glyph
->pixel_width
- 1;
2026 x
= w
->phys_cursor
.x
;
2033 if (glyph
->type
== STRETCH_GLYPH
2034 && !x_stretch_cursor_p
)
2035 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2036 w
->phys_cursor_width
= wd
;
2038 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2040 /* If y is below window bottom, ensure that we still see a cursor. */
2041 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2043 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2044 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2046 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2049 h
= max (h
- (y0
- y
) + 1, h0
);
2054 y0
= window_text_bottom_y (w
) - h0
;
2062 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2063 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2068 * Remember which glyph the mouse is over.
2072 remember_mouse_glyph (f
, gx
, gy
, rect
)
2075 NativeRectangle
*rect
;
2079 struct glyph_row
*r
, *gr
, *end_row
;
2080 enum window_part part
;
2081 enum glyph_row_area area
;
2082 int x
, y
, width
, height
;
2084 /* Try to determine frame pixel position and size of the glyph under
2085 frame pixel coordinates X/Y on frame F. */
2087 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2090 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2091 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2095 w
= XWINDOW (window
);
2096 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2097 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2099 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2100 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2102 if (w
->pseudo_window_p
)
2105 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2111 case ON_LEFT_MARGIN
:
2112 area
= LEFT_MARGIN_AREA
;
2115 case ON_RIGHT_MARGIN
:
2116 area
= RIGHT_MARGIN_AREA
;
2119 case ON_HEADER_LINE
:
2121 gr
= (part
== ON_HEADER_LINE
2122 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2123 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2126 goto text_glyph_row_found
;
2133 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2134 if (r
->y
+ r
->height
> y
)
2140 text_glyph_row_found
:
2143 struct glyph
*g
= gr
->glyphs
[area
];
2144 struct glyph
*end
= g
+ gr
->used
[area
];
2146 height
= gr
->height
;
2147 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2148 if (gx
+ g
->pixel_width
> x
)
2153 if (g
->type
== IMAGE_GLYPH
)
2155 /* Don't remember when mouse is over image, as
2156 image may have hot-spots. */
2157 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2160 width
= g
->pixel_width
;
2164 /* Use nominal char spacing at end of line. */
2166 gx
+= (x
/ width
) * width
;
2169 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2170 gx
+= window_box_left_offset (w
, area
);
2174 /* Use nominal line height at end of window. */
2175 gx
= (x
/ width
) * width
;
2177 gy
+= (y
/ height
) * height
;
2181 case ON_LEFT_FRINGE
:
2182 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2183 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2184 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2185 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2188 case ON_RIGHT_FRINGE
:
2189 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2190 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2191 : window_box_right_offset (w
, TEXT_AREA
));
2192 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2196 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2198 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2199 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2200 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2202 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2206 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2207 if (r
->y
+ r
->height
> y
)
2214 height
= gr
->height
;
2217 /* Use nominal line height at end of window. */
2219 gy
+= (y
/ height
) * height
;
2226 /* If there is no glyph under the mouse, then we divide the screen
2227 into a grid of the smallest glyph in the frame, and use that
2230 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2231 round down even for negative values. */
2237 gx
= (gx
/ width
) * width
;
2238 gy
= (gy
/ height
) * height
;
2243 gx
+= WINDOW_LEFT_EDGE_X (w
);
2244 gy
+= WINDOW_TOP_EDGE_Y (w
);
2247 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2249 /* Visible feedback for debugging. */
2252 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2253 f
->output_data
.x
->normal_gc
,
2254 gx
, gy
, width
, height
);
2260 #endif /* HAVE_WINDOW_SYSTEM */
2263 /***********************************************************************
2264 Lisp form evaluation
2265 ***********************************************************************/
2267 /* Error handler for safe_eval and safe_call. */
2270 safe_eval_handler (arg
)
2273 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2278 /* Evaluate SEXPR and return the result, or nil if something went
2279 wrong. Prevent redisplay during the evaluation. */
2287 if (inhibit_eval_during_redisplay
)
2291 int count
= SPECPDL_INDEX ();
2292 struct gcpro gcpro1
;
2295 specbind (Qinhibit_redisplay
, Qt
);
2296 /* Use Qt to ensure debugger does not run,
2297 so there is no possibility of wanting to redisplay. */
2298 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2301 val
= unbind_to (count
, val
);
2308 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2309 Return the result, or nil if something went wrong. Prevent
2310 redisplay during the evaluation. */
2313 safe_call (nargs
, args
)
2319 if (inhibit_eval_during_redisplay
)
2323 int count
= SPECPDL_INDEX ();
2324 struct gcpro gcpro1
;
2327 gcpro1
.nvars
= nargs
;
2328 specbind (Qinhibit_redisplay
, Qt
);
2329 /* Use Qt to ensure debugger does not run,
2330 so there is no possibility of wanting to redisplay. */
2331 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2334 val
= unbind_to (count
, val
);
2341 /* Call function FN with one argument ARG.
2342 Return the result, or nil if something went wrong. */
2345 safe_call1 (fn
, arg
)
2346 Lisp_Object fn
, arg
;
2348 Lisp_Object args
[2];
2351 return safe_call (2, args
);
2356 /***********************************************************************
2358 ***********************************************************************/
2362 /* Define CHECK_IT to perform sanity checks on iterators.
2363 This is for debugging. It is too slow to do unconditionally. */
2369 if (it
->method
== GET_FROM_STRING
)
2371 xassert (STRINGP (it
->string
));
2372 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2376 xassert (IT_STRING_CHARPOS (*it
) < 0);
2377 if (it
->method
== GET_FROM_BUFFER
)
2379 /* Check that character and byte positions agree. */
2380 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2385 xassert (it
->current
.dpvec_index
>= 0);
2387 xassert (it
->current
.dpvec_index
< 0);
2390 #define CHECK_IT(IT) check_it ((IT))
2394 #define CHECK_IT(IT) (void) 0
2401 /* Check that the window end of window W is what we expect it
2402 to be---the last row in the current matrix displaying text. */
2405 check_window_end (w
)
2408 if (!MINI_WINDOW_P (w
)
2409 && !NILP (w
->window_end_valid
))
2411 struct glyph_row
*row
;
2412 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2413 XFASTINT (w
->window_end_vpos
)),
2415 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2416 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2420 #define CHECK_WINDOW_END(W) check_window_end ((W))
2422 #else /* not GLYPH_DEBUG */
2424 #define CHECK_WINDOW_END(W) (void) 0
2426 #endif /* not GLYPH_DEBUG */
2430 /***********************************************************************
2431 Iterator initialization
2432 ***********************************************************************/
2434 /* Initialize IT for displaying current_buffer in window W, starting
2435 at character position CHARPOS. CHARPOS < 0 means that no buffer
2436 position is specified which is useful when the iterator is assigned
2437 a position later. BYTEPOS is the byte position corresponding to
2438 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2440 If ROW is not null, calls to produce_glyphs with IT as parameter
2441 will produce glyphs in that row.
2443 BASE_FACE_ID is the id of a base face to use. It must be one of
2444 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2445 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2446 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2448 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2449 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2450 will be initialized to use the corresponding mode line glyph row of
2451 the desired matrix of W. */
2454 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2457 int charpos
, bytepos
;
2458 struct glyph_row
*row
;
2459 enum face_id base_face_id
;
2461 int highlight_region_p
;
2463 /* Some precondition checks. */
2464 xassert (w
!= NULL
&& it
!= NULL
);
2465 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2468 /* If face attributes have been changed since the last redisplay,
2469 free realized faces now because they depend on face definitions
2470 that might have changed. Don't free faces while there might be
2471 desired matrices pending which reference these faces. */
2472 if (face_change_count
&& !inhibit_free_realized_faces
)
2474 face_change_count
= 0;
2475 free_all_realized_faces (Qnil
);
2478 /* Use one of the mode line rows of W's desired matrix if
2482 if (base_face_id
== MODE_LINE_FACE_ID
2483 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2484 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2485 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2486 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2490 bzero (it
, sizeof *it
);
2491 it
->current
.overlay_string_index
= -1;
2492 it
->current
.dpvec_index
= -1;
2493 it
->base_face_id
= base_face_id
;
2495 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2497 /* The window in which we iterate over current_buffer: */
2498 XSETWINDOW (it
->window
, w
);
2500 it
->f
= XFRAME (w
->frame
);
2502 /* Extra space between lines (on window systems only). */
2503 if (base_face_id
== DEFAULT_FACE_ID
2504 && FRAME_WINDOW_P (it
->f
))
2506 if (NATNUMP (current_buffer
->extra_line_spacing
))
2507 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2508 else if (FLOATP (current_buffer
->extra_line_spacing
))
2509 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2510 * FRAME_LINE_HEIGHT (it
->f
));
2511 else if (it
->f
->extra_line_spacing
> 0)
2512 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2513 it
->max_extra_line_spacing
= 0;
2516 /* If realized faces have been removed, e.g. because of face
2517 attribute changes of named faces, recompute them. When running
2518 in batch mode, the face cache of Vterminal_frame is null. If
2519 we happen to get called, make a dummy face cache. */
2520 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2521 init_frame_faces (it
->f
);
2522 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2523 recompute_basic_faces (it
->f
);
2525 /* Current value of the `slice', `space-width', and 'height' properties. */
2526 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2527 it
->space_width
= Qnil
;
2528 it
->font_height
= Qnil
;
2529 it
->override_ascent
= -1;
2531 /* Are control characters displayed as `^C'? */
2532 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2534 /* -1 means everything between a CR and the following line end
2535 is invisible. >0 means lines indented more than this value are
2537 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2538 ? XFASTINT (current_buffer
->selective_display
)
2539 : (!NILP (current_buffer
->selective_display
)
2541 it
->selective_display_ellipsis_p
2542 = !NILP (current_buffer
->selective_display_ellipses
);
2544 /* Display table to use. */
2545 it
->dp
= window_display_table (w
);
2547 /* Are multibyte characters enabled in current_buffer? */
2548 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2550 /* Non-zero if we should highlight the region. */
2552 = (!NILP (Vtransient_mark_mode
)
2553 && !NILP (current_buffer
->mark_active
)
2554 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2556 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2557 start and end of a visible region in window IT->w. Set both to
2558 -1 to indicate no region. */
2559 if (highlight_region_p
2560 /* Maybe highlight only in selected window. */
2561 && (/* Either show region everywhere. */
2562 highlight_nonselected_windows
2563 /* Or show region in the selected window. */
2564 || w
== XWINDOW (selected_window
)
2565 /* Or show the region if we are in the mini-buffer and W is
2566 the window the mini-buffer refers to. */
2567 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2568 && WINDOWP (minibuf_selected_window
)
2569 && w
== XWINDOW (minibuf_selected_window
))))
2571 int charpos
= marker_position (current_buffer
->mark
);
2572 it
->region_beg_charpos
= min (PT
, charpos
);
2573 it
->region_end_charpos
= max (PT
, charpos
);
2576 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2578 /* Get the position at which the redisplay_end_trigger hook should
2579 be run, if it is to be run at all. */
2580 if (MARKERP (w
->redisplay_end_trigger
)
2581 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2582 it
->redisplay_end_trigger_charpos
2583 = marker_position (w
->redisplay_end_trigger
);
2584 else if (INTEGERP (w
->redisplay_end_trigger
))
2585 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2587 /* Correct bogus values of tab_width. */
2588 it
->tab_width
= XINT (current_buffer
->tab_width
);
2589 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2592 /* Are lines in the display truncated? */
2593 it
->truncate_lines_p
2594 = (base_face_id
!= DEFAULT_FACE_ID
2595 || XINT (it
->w
->hscroll
)
2596 || (truncate_partial_width_windows
2597 && !WINDOW_FULL_WIDTH_P (it
->w
))
2598 || !NILP (current_buffer
->truncate_lines
));
2600 /* Get dimensions of truncation and continuation glyphs. These are
2601 displayed as fringe bitmaps under X, so we don't need them for such
2603 if (!FRAME_WINDOW_P (it
->f
))
2605 if (it
->truncate_lines_p
)
2607 /* We will need the truncation glyph. */
2608 xassert (it
->glyph_row
== NULL
);
2609 produce_special_glyphs (it
, IT_TRUNCATION
);
2610 it
->truncation_pixel_width
= it
->pixel_width
;
2614 /* We will need the continuation glyph. */
2615 xassert (it
->glyph_row
== NULL
);
2616 produce_special_glyphs (it
, IT_CONTINUATION
);
2617 it
->continuation_pixel_width
= it
->pixel_width
;
2620 /* Reset these values to zero because the produce_special_glyphs
2621 above has changed them. */
2622 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2623 it
->phys_ascent
= it
->phys_descent
= 0;
2626 /* Set this after getting the dimensions of truncation and
2627 continuation glyphs, so that we don't produce glyphs when calling
2628 produce_special_glyphs, above. */
2629 it
->glyph_row
= row
;
2630 it
->area
= TEXT_AREA
;
2632 /* Get the dimensions of the display area. The display area
2633 consists of the visible window area plus a horizontally scrolled
2634 part to the left of the window. All x-values are relative to the
2635 start of this total display area. */
2636 if (base_face_id
!= DEFAULT_FACE_ID
)
2638 /* Mode lines, menu bar in terminal frames. */
2639 it
->first_visible_x
= 0;
2640 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2645 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2646 it
->last_visible_x
= (it
->first_visible_x
2647 + window_box_width (w
, TEXT_AREA
));
2649 /* If we truncate lines, leave room for the truncator glyph(s) at
2650 the right margin. Otherwise, leave room for the continuation
2651 glyph(s). Truncation and continuation glyphs are not inserted
2652 for window-based redisplay. */
2653 if (!FRAME_WINDOW_P (it
->f
))
2655 if (it
->truncate_lines_p
)
2656 it
->last_visible_x
-= it
->truncation_pixel_width
;
2658 it
->last_visible_x
-= it
->continuation_pixel_width
;
2661 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2662 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2665 /* Leave room for a border glyph. */
2666 if (!FRAME_WINDOW_P (it
->f
)
2667 && !WINDOW_RIGHTMOST_P (it
->w
))
2668 it
->last_visible_x
-= 1;
2670 it
->last_visible_y
= window_text_bottom_y (w
);
2672 /* For mode lines and alike, arrange for the first glyph having a
2673 left box line if the face specifies a box. */
2674 if (base_face_id
!= DEFAULT_FACE_ID
)
2678 it
->face_id
= base_face_id
;
2680 /* If we have a boxed mode line, make the first character appear
2681 with a left box line. */
2682 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2683 if (face
->box
!= FACE_NO_BOX
)
2684 it
->start_of_box_run_p
= 1;
2687 /* If a buffer position was specified, set the iterator there,
2688 getting overlays and face properties from that position. */
2689 if (charpos
>= BUF_BEG (current_buffer
))
2691 it
->end_charpos
= ZV
;
2693 IT_CHARPOS (*it
) = charpos
;
2695 /* Compute byte position if not specified. */
2696 if (bytepos
< charpos
)
2697 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2699 IT_BYTEPOS (*it
) = bytepos
;
2701 it
->start
= it
->current
;
2703 /* Compute faces etc. */
2704 reseat (it
, it
->current
.pos
, 1);
2711 /* Initialize IT for the display of window W with window start POS. */
2714 start_display (it
, w
, pos
)
2717 struct text_pos pos
;
2719 struct glyph_row
*row
;
2720 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2722 row
= w
->desired_matrix
->rows
+ first_vpos
;
2723 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2724 it
->first_vpos
= first_vpos
;
2726 /* Don't reseat to previous visible line start if current start
2727 position is in a string or image. */
2728 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2730 int start_at_line_beg_p
;
2731 int first_y
= it
->current_y
;
2733 /* If window start is not at a line start, skip forward to POS to
2734 get the correct continuation lines width. */
2735 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2736 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2737 if (!start_at_line_beg_p
)
2741 reseat_at_previous_visible_line_start (it
);
2742 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2744 new_x
= it
->current_x
+ it
->pixel_width
;
2746 /* If lines are continued, this line may end in the middle
2747 of a multi-glyph character (e.g. a control character
2748 displayed as \003, or in the middle of an overlay
2749 string). In this case move_it_to above will not have
2750 taken us to the start of the continuation line but to the
2751 end of the continued line. */
2752 if (it
->current_x
> 0
2753 && !it
->truncate_lines_p
/* Lines are continued. */
2754 && (/* And glyph doesn't fit on the line. */
2755 new_x
> it
->last_visible_x
2756 /* Or it fits exactly and we're on a window
2758 || (new_x
== it
->last_visible_x
2759 && FRAME_WINDOW_P (it
->f
))))
2761 if (it
->current
.dpvec_index
>= 0
2762 || it
->current
.overlay_string_index
>= 0)
2764 set_iterator_to_next (it
, 1);
2765 move_it_in_display_line_to (it
, -1, -1, 0);
2768 it
->continuation_lines_width
+= it
->current_x
;
2771 /* We're starting a new display line, not affected by the
2772 height of the continued line, so clear the appropriate
2773 fields in the iterator structure. */
2774 it
->max_ascent
= it
->max_descent
= 0;
2775 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2777 it
->current_y
= first_y
;
2779 it
->current_x
= it
->hpos
= 0;
2783 #if 0 /* Don't assert the following because start_display is sometimes
2784 called intentionally with a window start that is not at a
2785 line start. Please leave this code in as a comment. */
2787 /* Window start should be on a line start, now. */
2788 xassert (it
->continuation_lines_width
2789 || IT_CHARPOS (it
) == BEGV
2790 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2795 /* Return 1 if POS is a position in ellipses displayed for invisible
2796 text. W is the window we display, for text property lookup. */
2799 in_ellipses_for_invisible_text_p (pos
, w
)
2800 struct display_pos
*pos
;
2803 Lisp_Object prop
, window
;
2805 int charpos
= CHARPOS (pos
->pos
);
2807 /* If POS specifies a position in a display vector, this might
2808 be for an ellipsis displayed for invisible text. We won't
2809 get the iterator set up for delivering that ellipsis unless
2810 we make sure that it gets aware of the invisible text. */
2811 if (pos
->dpvec_index
>= 0
2812 && pos
->overlay_string_index
< 0
2813 && CHARPOS (pos
->string_pos
) < 0
2815 && (XSETWINDOW (window
, w
),
2816 prop
= Fget_char_property (make_number (charpos
),
2817 Qinvisible
, window
),
2818 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2820 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2822 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2829 /* Initialize IT for stepping through current_buffer in window W,
2830 starting at position POS that includes overlay string and display
2831 vector/ control character translation position information. Value
2832 is zero if there are overlay strings with newlines at POS. */
2835 init_from_display_pos (it
, w
, pos
)
2838 struct display_pos
*pos
;
2840 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2841 int i
, overlay_strings_with_newlines
= 0;
2843 /* If POS specifies a position in a display vector, this might
2844 be for an ellipsis displayed for invisible text. We won't
2845 get the iterator set up for delivering that ellipsis unless
2846 we make sure that it gets aware of the invisible text. */
2847 if (in_ellipses_for_invisible_text_p (pos
, w
))
2853 /* Keep in mind: the call to reseat in init_iterator skips invisible
2854 text, so we might end up at a position different from POS. This
2855 is only a problem when POS is a row start after a newline and an
2856 overlay starts there with an after-string, and the overlay has an
2857 invisible property. Since we don't skip invisible text in
2858 display_line and elsewhere immediately after consuming the
2859 newline before the row start, such a POS will not be in a string,
2860 but the call to init_iterator below will move us to the
2862 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2864 /* This only scans the current chunk -- it should scan all chunks.
2865 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2866 to 16 in 22.1 to make this a lesser problem. */
2867 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2869 const char *s
= SDATA (it
->overlay_strings
[i
]);
2870 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2872 while (s
< e
&& *s
!= '\n')
2877 overlay_strings_with_newlines
= 1;
2882 /* If position is within an overlay string, set up IT to the right
2884 if (pos
->overlay_string_index
>= 0)
2888 /* If the first overlay string happens to have a `display'
2889 property for an image, the iterator will be set up for that
2890 image, and we have to undo that setup first before we can
2891 correct the overlay string index. */
2892 if (it
->method
== GET_FROM_IMAGE
)
2895 /* We already have the first chunk of overlay strings in
2896 IT->overlay_strings. Load more until the one for
2897 pos->overlay_string_index is in IT->overlay_strings. */
2898 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2900 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2901 it
->current
.overlay_string_index
= 0;
2904 load_overlay_strings (it
, 0);
2905 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2909 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2910 relative_index
= (it
->current
.overlay_string_index
2911 % OVERLAY_STRING_CHUNK_SIZE
);
2912 it
->string
= it
->overlay_strings
[relative_index
];
2913 xassert (STRINGP (it
->string
));
2914 it
->current
.string_pos
= pos
->string_pos
;
2915 it
->method
= GET_FROM_STRING
;
2918 #if 0 /* This is bogus because POS not having an overlay string
2919 position does not mean it's after the string. Example: A
2920 line starting with a before-string and initialization of IT
2921 to the previous row's end position. */
2922 else if (it
->current
.overlay_string_index
>= 0)
2924 /* If POS says we're already after an overlay string ending at
2925 POS, make sure to pop the iterator because it will be in
2926 front of that overlay string. When POS is ZV, we've thereby
2927 also ``processed'' overlay strings at ZV. */
2930 xassert (it
->current
.overlay_string_index
== -1);
2931 xassert (it
->method
== GET_FROM_BUFFER
);
2932 if (CHARPOS (pos
->pos
) == ZV
)
2933 it
->overlay_strings_at_end_processed_p
= 1;
2937 if (CHARPOS (pos
->string_pos
) >= 0)
2939 /* Recorded position is not in an overlay string, but in another
2940 string. This can only be a string from a `display' property.
2941 IT should already be filled with that string. */
2942 it
->current
.string_pos
= pos
->string_pos
;
2943 xassert (STRINGP (it
->string
));
2946 /* Restore position in display vector translations, control
2947 character translations or ellipses. */
2948 if (pos
->dpvec_index
>= 0)
2950 if (it
->dpvec
== NULL
)
2951 get_next_display_element (it
);
2952 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2953 it
->current
.dpvec_index
= pos
->dpvec_index
;
2957 return !overlay_strings_with_newlines
;
2961 /* Initialize IT for stepping through current_buffer in window W
2962 starting at ROW->start. */
2965 init_to_row_start (it
, w
, row
)
2968 struct glyph_row
*row
;
2970 init_from_display_pos (it
, w
, &row
->start
);
2971 it
->start
= row
->start
;
2972 it
->continuation_lines_width
= row
->continuation_lines_width
;
2977 /* Initialize IT for stepping through current_buffer in window W
2978 starting in the line following ROW, i.e. starting at ROW->end.
2979 Value is zero if there are overlay strings with newlines at ROW's
2983 init_to_row_end (it
, w
, row
)
2986 struct glyph_row
*row
;
2990 if (init_from_display_pos (it
, w
, &row
->end
))
2992 if (row
->continued_p
)
2993 it
->continuation_lines_width
2994 = row
->continuation_lines_width
+ row
->pixel_width
;
3005 /***********************************************************************
3007 ***********************************************************************/
3009 /* Called when IT reaches IT->stop_charpos. Handle text property and
3010 overlay changes. Set IT->stop_charpos to the next position where
3017 enum prop_handled handled
;
3018 int handle_overlay_change_p
;
3022 it
->current
.dpvec_index
= -1;
3023 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3024 it
->ignore_overlay_strings_at_pos_p
= 0;
3026 /* Use face of preceding text for ellipsis (if invisible) */
3027 if (it
->selective_display_ellipsis_p
)
3028 it
->saved_face_id
= it
->face_id
;
3032 handled
= HANDLED_NORMALLY
;
3034 /* Call text property handlers. */
3035 for (p
= it_props
; p
->handler
; ++p
)
3037 handled
= p
->handler (it
);
3039 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3041 else if (handled
== HANDLED_RETURN
)
3043 /* We still want to show before and after strings from
3044 overlays even if the actual buffer text is replaced. */
3045 if (!handle_overlay_change_p
|| it
->sp
> 1)
3047 if (!get_overlay_strings_1 (it
, 0, 0))
3049 it
->ignore_overlay_strings_at_pos_p
= 1;
3050 it
->string_from_display_prop_p
= 0;
3051 handle_overlay_change_p
= 0;
3052 handled
= HANDLED_RECOMPUTE_PROPS
;
3055 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3056 handle_overlay_change_p
= 0;
3059 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3061 /* Don't check for overlay strings below when set to deliver
3062 characters from a display vector. */
3063 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3064 handle_overlay_change_p
= 0;
3066 /* Handle overlay changes. */
3067 if (handle_overlay_change_p
)
3068 handled
= handle_overlay_change (it
);
3070 /* Determine where to stop next. */
3071 if (handled
== HANDLED_NORMALLY
)
3072 compute_stop_pos (it
);
3075 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3079 /* Compute IT->stop_charpos from text property and overlay change
3080 information for IT's current position. */
3083 compute_stop_pos (it
)
3086 register INTERVAL iv
, next_iv
;
3087 Lisp_Object object
, limit
, position
;
3089 /* If nowhere else, stop at the end. */
3090 it
->stop_charpos
= it
->end_charpos
;
3092 if (STRINGP (it
->string
))
3094 /* Strings are usually short, so don't limit the search for
3096 object
= it
->string
;
3098 position
= make_number (IT_STRING_CHARPOS (*it
));
3104 /* If next overlay change is in front of the current stop pos
3105 (which is IT->end_charpos), stop there. Note: value of
3106 next_overlay_change is point-max if no overlay change
3108 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3109 if (charpos
< it
->stop_charpos
)
3110 it
->stop_charpos
= charpos
;
3112 /* If showing the region, we have to stop at the region
3113 start or end because the face might change there. */
3114 if (it
->region_beg_charpos
> 0)
3116 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3117 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3118 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3119 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3122 /* Set up variables for computing the stop position from text
3123 property changes. */
3124 XSETBUFFER (object
, current_buffer
);
3125 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3126 position
= make_number (IT_CHARPOS (*it
));
3130 /* Get the interval containing IT's position. Value is a null
3131 interval if there isn't such an interval. */
3132 iv
= validate_interval_range (object
, &position
, &position
, 0);
3133 if (!NULL_INTERVAL_P (iv
))
3135 Lisp_Object values_here
[LAST_PROP_IDX
];
3138 /* Get properties here. */
3139 for (p
= it_props
; p
->handler
; ++p
)
3140 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3142 /* Look for an interval following iv that has different
3144 for (next_iv
= next_interval (iv
);
3145 (!NULL_INTERVAL_P (next_iv
)
3147 || XFASTINT (limit
) > next_iv
->position
));
3148 next_iv
= next_interval (next_iv
))
3150 for (p
= it_props
; p
->handler
; ++p
)
3152 Lisp_Object new_value
;
3154 new_value
= textget (next_iv
->plist
, *p
->name
);
3155 if (!EQ (values_here
[p
->idx
], new_value
))
3163 if (!NULL_INTERVAL_P (next_iv
))
3165 if (INTEGERP (limit
)
3166 && next_iv
->position
>= XFASTINT (limit
))
3167 /* No text property change up to limit. */
3168 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3170 /* Text properties change in next_iv. */
3171 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3175 xassert (STRINGP (it
->string
)
3176 || (it
->stop_charpos
>= BEGV
3177 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3181 /* Return the position of the next overlay change after POS in
3182 current_buffer. Value is point-max if no overlay change
3183 follows. This is like `next-overlay-change' but doesn't use
3187 next_overlay_change (pos
)
3192 Lisp_Object
*overlays
;
3195 /* Get all overlays at the given position. */
3196 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3198 /* If any of these overlays ends before endpos,
3199 use its ending point instead. */
3200 for (i
= 0; i
< noverlays
; ++i
)
3205 oend
= OVERLAY_END (overlays
[i
]);
3206 oendpos
= OVERLAY_POSITION (oend
);
3207 endpos
= min (endpos
, oendpos
);
3215 /***********************************************************************
3217 ***********************************************************************/
3219 /* Handle changes in the `fontified' property of the current buffer by
3220 calling hook functions from Qfontification_functions to fontify
3223 static enum prop_handled
3224 handle_fontified_prop (it
)
3227 Lisp_Object prop
, pos
;
3228 enum prop_handled handled
= HANDLED_NORMALLY
;
3230 if (!NILP (Vmemory_full
))
3233 /* Get the value of the `fontified' property at IT's current buffer
3234 position. (The `fontified' property doesn't have a special
3235 meaning in strings.) If the value is nil, call functions from
3236 Qfontification_functions. */
3237 if (!STRINGP (it
->string
)
3239 && !NILP (Vfontification_functions
)
3240 && !NILP (Vrun_hooks
)
3241 && (pos
= make_number (IT_CHARPOS (*it
)),
3242 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3245 int count
= SPECPDL_INDEX ();
3248 val
= Vfontification_functions
;
3249 specbind (Qfontification_functions
, Qnil
);
3251 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3252 safe_call1 (val
, pos
);
3255 Lisp_Object globals
, fn
;
3256 struct gcpro gcpro1
, gcpro2
;
3259 GCPRO2 (val
, globals
);
3261 for (; CONSP (val
); val
= XCDR (val
))
3267 /* A value of t indicates this hook has a local
3268 binding; it means to run the global binding too.
3269 In a global value, t should not occur. If it
3270 does, we must ignore it to avoid an endless
3272 for (globals
= Fdefault_value (Qfontification_functions
);
3274 globals
= XCDR (globals
))
3276 fn
= XCAR (globals
);
3278 safe_call1 (fn
, pos
);
3282 safe_call1 (fn
, pos
);
3288 unbind_to (count
, Qnil
);
3290 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3291 something. This avoids an endless loop if they failed to
3292 fontify the text for which reason ever. */
3293 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3294 handled
= HANDLED_RECOMPUTE_PROPS
;
3302 /***********************************************************************
3304 ***********************************************************************/
3306 /* Set up iterator IT from face properties at its current position.
3307 Called from handle_stop. */
3309 static enum prop_handled
3310 handle_face_prop (it
)
3313 int new_face_id
, next_stop
;
3315 if (!STRINGP (it
->string
))
3318 = face_at_buffer_position (it
->w
,
3320 it
->region_beg_charpos
,
3321 it
->region_end_charpos
,
3324 + TEXT_PROP_DISTANCE_LIMIT
),
3327 /* Is this a start of a run of characters with box face?
3328 Caveat: this can be called for a freshly initialized
3329 iterator; face_id is -1 in this case. We know that the new
3330 face will not change until limit, i.e. if the new face has a
3331 box, all characters up to limit will have one. But, as
3332 usual, we don't know whether limit is really the end. */
3333 if (new_face_id
!= it
->face_id
)
3335 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3337 /* If new face has a box but old face has not, this is
3338 the start of a run of characters with box, i.e. it has
3339 a shadow on the left side. The value of face_id of the
3340 iterator will be -1 if this is the initial call that gets
3341 the face. In this case, we have to look in front of IT's
3342 position and see whether there is a face != new_face_id. */
3343 it
->start_of_box_run_p
3344 = (new_face
->box
!= FACE_NO_BOX
3345 && (it
->face_id
>= 0
3346 || IT_CHARPOS (*it
) == BEG
3347 || new_face_id
!= face_before_it_pos (it
)));
3348 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3353 int base_face_id
, bufpos
;
3355 if (it
->current
.overlay_string_index
>= 0)
3356 bufpos
= IT_CHARPOS (*it
);
3360 /* For strings from a buffer, i.e. overlay strings or strings
3361 from a `display' property, use the face at IT's current
3362 buffer position as the base face to merge with, so that
3363 overlay strings appear in the same face as surrounding
3364 text, unless they specify their own faces. */
3365 base_face_id
= underlying_face_id (it
);
3367 new_face_id
= face_at_string_position (it
->w
,
3369 IT_STRING_CHARPOS (*it
),
3371 it
->region_beg_charpos
,
3372 it
->region_end_charpos
,
3376 #if 0 /* This shouldn't be neccessary. Let's check it. */
3377 /* If IT is used to display a mode line we would really like to
3378 use the mode line face instead of the frame's default face. */
3379 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3380 && new_face_id
== DEFAULT_FACE_ID
)
3381 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3384 /* Is this a start of a run of characters with box? Caveat:
3385 this can be called for a freshly allocated iterator; face_id
3386 is -1 is this case. We know that the new face will not
3387 change until the next check pos, i.e. if the new face has a
3388 box, all characters up to that position will have a
3389 box. But, as usual, we don't know whether that position
3390 is really the end. */
3391 if (new_face_id
!= it
->face_id
)
3393 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3394 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3396 /* If new face has a box but old face hasn't, this is the
3397 start of a run of characters with box, i.e. it has a
3398 shadow on the left side. */
3399 it
->start_of_box_run_p
3400 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3401 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3405 it
->face_id
= new_face_id
;
3406 return HANDLED_NORMALLY
;
3410 /* Return the ID of the face ``underlying'' IT's current position,
3411 which is in a string. If the iterator is associated with a
3412 buffer, return the face at IT's current buffer position.
3413 Otherwise, use the iterator's base_face_id. */
3416 underlying_face_id (it
)
3419 int face_id
= it
->base_face_id
, i
;
3421 xassert (STRINGP (it
->string
));
3423 for (i
= it
->sp
- 1; i
>= 0; --i
)
3424 if (NILP (it
->stack
[i
].string
))
3425 face_id
= it
->stack
[i
].face_id
;
3431 /* Compute the face one character before or after the current position
3432 of IT. BEFORE_P non-zero means get the face in front of IT's
3433 position. Value is the id of the face. */
3436 face_before_or_after_it_pos (it
, before_p
)
3441 int next_check_charpos
;
3442 struct text_pos pos
;
3444 xassert (it
->s
== NULL
);
3446 if (STRINGP (it
->string
))
3448 int bufpos
, base_face_id
;
3450 /* No face change past the end of the string (for the case
3451 we are padding with spaces). No face change before the
3453 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3454 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3457 /* Set pos to the position before or after IT's current position. */
3459 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3461 /* For composition, we must check the character after the
3463 pos
= (it
->what
== IT_COMPOSITION
3464 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3465 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3467 if (it
->current
.overlay_string_index
>= 0)
3468 bufpos
= IT_CHARPOS (*it
);
3472 base_face_id
= underlying_face_id (it
);
3474 /* Get the face for ASCII, or unibyte. */
3475 face_id
= face_at_string_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 IT->string is unibyte. */
3487 if (STRING_MULTIBYTE (it
->string
))
3489 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3490 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3492 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3494 c
= string_char_and_length (p
, rest
, &len
);
3495 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3500 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3501 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3504 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3505 pos
= it
->current
.pos
;
3508 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3511 if (it
->what
== IT_COMPOSITION
)
3512 /* For composition, we must check the position after the
3514 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3516 INC_TEXT_POS (pos
, it
->multibyte_p
);
3519 /* Determine face for CHARSET_ASCII, or unibyte. */
3520 face_id
= face_at_buffer_position (it
->w
,
3522 it
->region_beg_charpos
,
3523 it
->region_end_charpos
,
3524 &next_check_charpos
,
3527 /* Correct the face for charsets different from ASCII. Do it
3528 for the multibyte case only. The face returned above is
3529 suitable for unibyte text if current_buffer is unibyte. */
3530 if (it
->multibyte_p
)
3532 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3533 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3534 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3543 /***********************************************************************
3545 ***********************************************************************/
3547 /* Set up iterator IT from invisible properties at its current
3548 position. Called from handle_stop. */
3550 static enum prop_handled
3551 handle_invisible_prop (it
)
3554 enum prop_handled handled
= HANDLED_NORMALLY
;
3556 if (STRINGP (it
->string
))
3558 extern Lisp_Object Qinvisible
;
3559 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3561 /* Get the value of the invisible text property at the
3562 current position. Value will be nil if there is no such
3564 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3565 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3568 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3570 handled
= HANDLED_RECOMPUTE_PROPS
;
3572 /* Get the position at which the next change of the
3573 invisible text property can be found in IT->string.
3574 Value will be nil if the property value is the same for
3575 all the rest of IT->string. */
3576 XSETINT (limit
, SCHARS (it
->string
));
3577 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3580 /* Text at current position is invisible. The next
3581 change in the property is at position end_charpos.
3582 Move IT's current position to that position. */
3583 if (INTEGERP (end_charpos
)
3584 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3586 struct text_pos old
;
3587 old
= it
->current
.string_pos
;
3588 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3589 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3593 /* The rest of the string is invisible. If this is an
3594 overlay string, proceed with the next overlay string
3595 or whatever comes and return a character from there. */
3596 if (it
->current
.overlay_string_index
>= 0)
3598 next_overlay_string (it
);
3599 /* Don't check for overlay strings when we just
3600 finished processing them. */
3601 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3605 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3606 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3613 int invis_p
, newpos
, next_stop
, start_charpos
;
3614 Lisp_Object pos
, prop
, overlay
;
3616 /* First of all, is there invisible text at this position? */
3617 start_charpos
= IT_CHARPOS (*it
);
3618 pos
= make_number (IT_CHARPOS (*it
));
3619 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3621 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3623 /* If we are on invisible text, skip over it. */
3624 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3626 /* Record whether we have to display an ellipsis for the
3628 int display_ellipsis_p
= invis_p
== 2;
3630 handled
= HANDLED_RECOMPUTE_PROPS
;
3632 /* Loop skipping over invisible text. The loop is left at
3633 ZV or with IT on the first char being visible again. */
3636 /* Try to skip some invisible text. Return value is the
3637 position reached which can be equal to IT's position
3638 if there is nothing invisible here. This skips both
3639 over invisible text properties and overlays with
3640 invisible property. */
3641 newpos
= skip_invisible (IT_CHARPOS (*it
),
3642 &next_stop
, ZV
, it
->window
);
3644 /* If we skipped nothing at all we weren't at invisible
3645 text in the first place. If everything to the end of
3646 the buffer was skipped, end the loop. */
3647 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3651 /* We skipped some characters but not necessarily
3652 all there are. Check if we ended up on visible
3653 text. Fget_char_property returns the property of
3654 the char before the given position, i.e. if we
3655 get invis_p = 0, this means that the char at
3656 newpos is visible. */
3657 pos
= make_number (newpos
);
3658 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3659 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3662 /* If we ended up on invisible text, proceed to
3663 skip starting with next_stop. */
3665 IT_CHARPOS (*it
) = next_stop
;
3667 /* If there are adjacent invisible texts, don't lose the
3668 second one's ellipsis. */
3670 display_ellipsis_p
= 1;
3674 /* The position newpos is now either ZV or on visible text. */
3675 IT_CHARPOS (*it
) = newpos
;
3676 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3678 /* If there are before-strings at the start of invisible
3679 text, and the text is invisible because of a text
3680 property, arrange to show before-strings because 20.x did
3681 it that way. (If the text is invisible because of an
3682 overlay property instead of a text property, this is
3683 already handled in the overlay code.) */
3685 && get_overlay_strings (it
, start_charpos
))
3687 handled
= HANDLED_RECOMPUTE_PROPS
;
3688 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3690 else if (display_ellipsis_p
)
3692 /* Make sure that the glyphs of the ellipsis will get
3693 correct `charpos' values. If we would not update
3694 it->position here, the glyphs would belong to the
3695 last visible character _before_ the invisible
3696 text, which confuses `set_cursor_from_row'.
3698 We use the last invisible position instead of the
3699 first because this way the cursor is always drawn on
3700 the first "." of the ellipsis, whenever PT is inside
3701 the invisible text. Otherwise the cursor would be
3702 placed _after_ the ellipsis when the point is after the
3703 first invisible character. */
3704 if (!STRINGP (it
->object
))
3706 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3707 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3709 setup_for_ellipsis (it
, 0);
3718 /* Make iterator IT return `...' next.
3719 Replaces LEN characters from buffer. */
3722 setup_for_ellipsis (it
, len
)
3726 /* Use the display table definition for `...'. Invalid glyphs
3727 will be handled by the method returning elements from dpvec. */
3728 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3730 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3731 it
->dpvec
= v
->contents
;
3732 it
->dpend
= v
->contents
+ v
->size
;
3736 /* Default `...'. */
3737 it
->dpvec
= default_invis_vector
;
3738 it
->dpend
= default_invis_vector
+ 3;
3741 it
->dpvec_char_len
= len
;
3742 it
->current
.dpvec_index
= 0;
3743 it
->dpvec_face_id
= -1;
3745 /* Remember the current face id in case glyphs specify faces.
3746 IT's face is restored in set_iterator_to_next.
3747 saved_face_id was set to preceding char's face in handle_stop. */
3748 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3749 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3751 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3757 /***********************************************************************
3759 ***********************************************************************/
3761 /* Set up iterator IT from `display' property at its current position.
3762 Called from handle_stop.
3763 We return HANDLED_RETURN if some part of the display property
3764 overrides the display of the buffer text itself.
3765 Otherwise we return HANDLED_NORMALLY. */
3767 static enum prop_handled
3768 handle_display_prop (it
)
3771 Lisp_Object prop
, object
;
3772 struct text_pos
*position
;
3773 /* Nonzero if some property replaces the display of the text itself. */
3774 int display_replaced_p
= 0;
3776 if (STRINGP (it
->string
))
3778 object
= it
->string
;
3779 position
= &it
->current
.string_pos
;
3783 XSETWINDOW (object
, it
->w
);
3784 position
= &it
->current
.pos
;
3787 /* Reset those iterator values set from display property values. */
3788 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3789 it
->space_width
= Qnil
;
3790 it
->font_height
= Qnil
;
3793 /* We don't support recursive `display' properties, i.e. string
3794 values that have a string `display' property, that have a string
3795 `display' property etc. */
3796 if (!it
->string_from_display_prop_p
)
3797 it
->area
= TEXT_AREA
;
3799 prop
= Fget_char_property (make_number (position
->charpos
),
3802 return HANDLED_NORMALLY
;
3804 if (!STRINGP (it
->string
))
3805 object
= it
->w
->buffer
;
3808 /* Simple properties. */
3809 && !EQ (XCAR (prop
), Qimage
)
3810 && !EQ (XCAR (prop
), Qspace
)
3811 && !EQ (XCAR (prop
), Qwhen
)
3812 && !EQ (XCAR (prop
), Qslice
)
3813 && !EQ (XCAR (prop
), Qspace_width
)
3814 && !EQ (XCAR (prop
), Qheight
)
3815 && !EQ (XCAR (prop
), Qraise
)
3816 /* Marginal area specifications. */
3817 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3818 && !EQ (XCAR (prop
), Qleft_fringe
)
3819 && !EQ (XCAR (prop
), Qright_fringe
)
3820 && !NILP (XCAR (prop
)))
3822 for (; CONSP (prop
); prop
= XCDR (prop
))
3824 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3825 position
, display_replaced_p
))
3826 display_replaced_p
= 1;
3829 else if (VECTORP (prop
))
3832 for (i
= 0; i
< ASIZE (prop
); ++i
)
3833 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3834 position
, display_replaced_p
))
3835 display_replaced_p
= 1;
3839 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3840 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3841 return HANDLED_RECOMPUTE_PROPS
;
3843 display_replaced_p
= 1;
3846 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3850 /* Value is the position of the end of the `display' property starting
3851 at START_POS in OBJECT. */
3853 static struct text_pos
3854 display_prop_end (it
, object
, start_pos
)
3857 struct text_pos start_pos
;
3860 struct text_pos end_pos
;
3862 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3863 Qdisplay
, object
, Qnil
);
3864 CHARPOS (end_pos
) = XFASTINT (end
);
3865 if (STRINGP (object
))
3866 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3868 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3874 /* Set up IT from a single `display' specification PROP. OBJECT
3875 is the object in which the `display' property was found. *POSITION
3876 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3877 means that we previously saw a display specification which already
3878 replaced text display with something else, for example an image;
3879 we ignore such properties after the first one has been processed.
3881 If PROP is a `space' or `image' specification, and in some other
3882 cases too, set *POSITION to the position where the `display'
3885 Value is non-zero if something was found which replaces the display
3886 of buffer or string text. Specifically, the value is -1 if that
3887 "something" is "nothing". */
3890 handle_single_display_spec (it
, spec
, object
, position
,
3891 display_replaced_before_p
)
3895 struct text_pos
*position
;
3896 int display_replaced_before_p
;
3899 Lisp_Object location
, value
;
3900 struct text_pos start_pos
, save_pos
;
3903 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3904 If the result is non-nil, use VALUE instead of SPEC. */
3906 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3915 if (!NILP (form
) && !EQ (form
, Qt
))
3917 int count
= SPECPDL_INDEX ();
3918 struct gcpro gcpro1
;
3920 /* Bind `object' to the object having the `display' property, a
3921 buffer or string. Bind `position' to the position in the
3922 object where the property was found, and `buffer-position'
3923 to the current position in the buffer. */
3924 specbind (Qobject
, object
);
3925 specbind (Qposition
, make_number (CHARPOS (*position
)));
3926 specbind (Qbuffer_position
,
3927 make_number (STRINGP (object
)
3928 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3930 form
= safe_eval (form
);
3932 unbind_to (count
, Qnil
);
3938 /* Handle `(height HEIGHT)' specifications. */
3940 && EQ (XCAR (spec
), Qheight
)
3941 && CONSP (XCDR (spec
)))
3943 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3946 it
->font_height
= XCAR (XCDR (spec
));
3947 if (!NILP (it
->font_height
))
3949 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3950 int new_height
= -1;
3952 if (CONSP (it
->font_height
)
3953 && (EQ (XCAR (it
->font_height
), Qplus
)
3954 || EQ (XCAR (it
->font_height
), Qminus
))
3955 && CONSP (XCDR (it
->font_height
))
3956 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3958 /* `(+ N)' or `(- N)' where N is an integer. */
3959 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3960 if (EQ (XCAR (it
->font_height
), Qplus
))
3962 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3964 else if (FUNCTIONP (it
->font_height
))
3966 /* Call function with current height as argument.
3967 Value is the new height. */
3969 height
= safe_call1 (it
->font_height
,
3970 face
->lface
[LFACE_HEIGHT_INDEX
]);
3971 if (NUMBERP (height
))
3972 new_height
= XFLOATINT (height
);
3974 else if (NUMBERP (it
->font_height
))
3976 /* Value is a multiple of the canonical char height. */
3979 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3980 new_height
= (XFLOATINT (it
->font_height
)
3981 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3985 /* Evaluate IT->font_height with `height' bound to the
3986 current specified height to get the new height. */
3987 int count
= SPECPDL_INDEX ();
3989 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3990 value
= safe_eval (it
->font_height
);
3991 unbind_to (count
, Qnil
);
3993 if (NUMBERP (value
))
3994 new_height
= XFLOATINT (value
);
3998 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4004 /* Handle `(space_width WIDTH)'. */
4006 && EQ (XCAR (spec
), Qspace_width
)
4007 && CONSP (XCDR (spec
)))
4009 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4012 value
= XCAR (XCDR (spec
));
4013 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4014 it
->space_width
= value
;
4019 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4021 && EQ (XCAR (spec
), Qslice
))
4025 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4028 if (tem
= XCDR (spec
), CONSP (tem
))
4030 it
->slice
.x
= XCAR (tem
);
4031 if (tem
= XCDR (tem
), CONSP (tem
))
4033 it
->slice
.y
= XCAR (tem
);
4034 if (tem
= XCDR (tem
), CONSP (tem
))
4036 it
->slice
.width
= XCAR (tem
);
4037 if (tem
= XCDR (tem
), CONSP (tem
))
4038 it
->slice
.height
= XCAR (tem
);
4046 /* Handle `(raise FACTOR)'. */
4048 && EQ (XCAR (spec
), Qraise
)
4049 && CONSP (XCDR (spec
)))
4051 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4054 #ifdef HAVE_WINDOW_SYSTEM
4055 value
= XCAR (XCDR (spec
));
4056 if (NUMBERP (value
))
4058 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4059 it
->voffset
= - (XFLOATINT (value
)
4060 * (FONT_HEIGHT (face
->font
)));
4062 #endif /* HAVE_WINDOW_SYSTEM */
4067 /* Don't handle the other kinds of display specifications
4068 inside a string that we got from a `display' property. */
4069 if (it
->string_from_display_prop_p
)
4072 /* Characters having this form of property are not displayed, so
4073 we have to find the end of the property. */
4074 start_pos
= *position
;
4075 *position
= display_prop_end (it
, object
, start_pos
);
4078 /* Stop the scan at that end position--we assume that all
4079 text properties change there. */
4080 it
->stop_charpos
= position
->charpos
;
4082 /* Handle `(left-fringe BITMAP [FACE])'
4083 and `(right-fringe BITMAP [FACE])'. */
4085 && (EQ (XCAR (spec
), Qleft_fringe
)
4086 || EQ (XCAR (spec
), Qright_fringe
))
4087 && CONSP (XCDR (spec
)))
4089 int face_id
= DEFAULT_FACE_ID
;
4092 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4093 /* If we return here, POSITION has been advanced
4094 across the text with this property. */
4097 #ifdef HAVE_WINDOW_SYSTEM
4098 value
= XCAR (XCDR (spec
));
4099 if (!SYMBOLP (value
)
4100 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4101 /* If we return here, POSITION has been advanced
4102 across the text with this property. */
4105 if (CONSP (XCDR (XCDR (spec
))))
4107 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4108 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4109 'A', FRINGE_FACE_ID
, 0);
4114 /* Save current settings of IT so that we can restore them
4115 when we are finished with the glyph property value. */
4117 save_pos
= it
->position
;
4118 it
->position
= *position
;
4120 it
->position
= save_pos
;
4122 it
->area
= TEXT_AREA
;
4123 it
->what
= IT_IMAGE
;
4124 it
->image_id
= -1; /* no image */
4125 it
->position
= start_pos
;
4126 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4127 it
->method
= GET_FROM_IMAGE
;
4128 it
->face_id
= face_id
;
4130 /* Say that we haven't consumed the characters with
4131 `display' property yet. The call to pop_it in
4132 set_iterator_to_next will clean this up. */
4133 *position
= start_pos
;
4135 if (EQ (XCAR (spec
), Qleft_fringe
))
4137 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4138 it
->left_user_fringe_face_id
= face_id
;
4142 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4143 it
->right_user_fringe_face_id
= face_id
;
4145 #endif /* HAVE_WINDOW_SYSTEM */
4149 /* Prepare to handle `((margin left-margin) ...)',
4150 `((margin right-margin) ...)' and `((margin nil) ...)'
4151 prefixes for display specifications. */
4152 location
= Qunbound
;
4153 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4157 value
= XCDR (spec
);
4159 value
= XCAR (value
);
4162 if (EQ (XCAR (tem
), Qmargin
)
4163 && (tem
= XCDR (tem
),
4164 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4166 || EQ (tem
, Qleft_margin
)
4167 || EQ (tem
, Qright_margin
))))
4171 if (EQ (location
, Qunbound
))
4177 /* After this point, VALUE is the property after any
4178 margin prefix has been stripped. It must be a string,
4179 an image specification, or `(space ...)'.
4181 LOCATION specifies where to display: `left-margin',
4182 `right-margin' or nil. */
4184 valid_p
= (STRINGP (value
)
4185 #ifdef HAVE_WINDOW_SYSTEM
4186 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4187 #endif /* not HAVE_WINDOW_SYSTEM */
4188 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4190 if (valid_p
&& !display_replaced_before_p
)
4192 /* Save current settings of IT so that we can restore them
4193 when we are finished with the glyph property value. */
4194 save_pos
= it
->position
;
4195 it
->position
= *position
;
4197 it
->position
= save_pos
;
4199 if (NILP (location
))
4200 it
->area
= TEXT_AREA
;
4201 else if (EQ (location
, Qleft_margin
))
4202 it
->area
= LEFT_MARGIN_AREA
;
4204 it
->area
= RIGHT_MARGIN_AREA
;
4206 if (STRINGP (value
))
4208 if (SCHARS (value
) == 0)
4211 return -1; /* Replaced by "", i.e. nothing. */
4214 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4215 it
->current
.overlay_string_index
= -1;
4216 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4217 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4218 it
->method
= GET_FROM_STRING
;
4219 it
->stop_charpos
= 0;
4220 it
->string_from_display_prop_p
= 1;
4221 /* Say that we haven't consumed the characters with
4222 `display' property yet. The call to pop_it in
4223 set_iterator_to_next will clean this up. */
4224 *position
= start_pos
;
4226 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4228 it
->method
= GET_FROM_STRETCH
;
4230 *position
= it
->position
= start_pos
;
4232 #ifdef HAVE_WINDOW_SYSTEM
4235 it
->what
= IT_IMAGE
;
4236 it
->image_id
= lookup_image (it
->f
, value
);
4237 it
->position
= start_pos
;
4238 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4239 it
->method
= GET_FROM_IMAGE
;
4241 /* Say that we haven't consumed the characters with
4242 `display' property yet. The call to pop_it in
4243 set_iterator_to_next will clean this up. */
4244 *position
= start_pos
;
4246 #endif /* HAVE_WINDOW_SYSTEM */
4251 /* Invalid property or property not supported. Restore
4252 POSITION to what it was before. */
4253 *position
= start_pos
;
4258 /* Check if SPEC is a display specification value whose text should be
4259 treated as intangible. */
4262 single_display_spec_intangible_p (prop
)
4265 /* Skip over `when FORM'. */
4266 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4280 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4281 we don't need to treat text as intangible. */
4282 if (EQ (XCAR (prop
), Qmargin
))
4290 || EQ (XCAR (prop
), Qleft_margin
)
4291 || EQ (XCAR (prop
), Qright_margin
))
4295 return (CONSP (prop
)
4296 && (EQ (XCAR (prop
), Qimage
)
4297 || EQ (XCAR (prop
), Qspace
)));
4301 /* Check if PROP is a display property value whose text should be
4302 treated as intangible. */
4305 display_prop_intangible_p (prop
)
4309 && CONSP (XCAR (prop
))
4310 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4312 /* A list of sub-properties. */
4313 while (CONSP (prop
))
4315 if (single_display_spec_intangible_p (XCAR (prop
)))
4320 else if (VECTORP (prop
))
4322 /* A vector of sub-properties. */
4324 for (i
= 0; i
< ASIZE (prop
); ++i
)
4325 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4329 return single_display_spec_intangible_p (prop
);
4335 /* Return 1 if PROP is a display sub-property value containing STRING. */
4338 single_display_spec_string_p (prop
, string
)
4339 Lisp_Object prop
, string
;
4341 if (EQ (string
, prop
))
4344 /* Skip over `when FORM'. */
4345 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4354 /* Skip over `margin LOCATION'. */
4355 if (EQ (XCAR (prop
), Qmargin
))
4366 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4370 /* Return 1 if STRING appears in the `display' property PROP. */
4373 display_prop_string_p (prop
, string
)
4374 Lisp_Object prop
, string
;
4377 && CONSP (XCAR (prop
))
4378 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4380 /* A list of sub-properties. */
4381 while (CONSP (prop
))
4383 if (single_display_spec_string_p (XCAR (prop
), string
))
4388 else if (VECTORP (prop
))
4390 /* A vector of sub-properties. */
4392 for (i
= 0; i
< ASIZE (prop
); ++i
)
4393 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4397 return single_display_spec_string_p (prop
, string
);
4403 /* Determine from which buffer position in W's buffer STRING comes
4404 from. AROUND_CHARPOS is an approximate position where it could
4405 be from. Value is the buffer position or 0 if it couldn't be
4408 W's buffer must be current.
4410 This function is necessary because we don't record buffer positions
4411 in glyphs generated from strings (to keep struct glyph small).
4412 This function may only use code that doesn't eval because it is
4413 called asynchronously from note_mouse_highlight. */
4416 string_buffer_position (w
, string
, around_charpos
)
4421 Lisp_Object limit
, prop
, pos
;
4422 const int MAX_DISTANCE
= 1000;
4425 pos
= make_number (around_charpos
);
4426 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4427 while (!found
&& !EQ (pos
, limit
))
4429 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4430 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4433 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4438 pos
= make_number (around_charpos
);
4439 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4440 while (!found
&& !EQ (pos
, limit
))
4442 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4443 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4446 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4451 return found
? XINT (pos
) : 0;
4456 /***********************************************************************
4457 `composition' property
4458 ***********************************************************************/
4460 /* Set up iterator IT from `composition' property at its current
4461 position. Called from handle_stop. */
4463 static enum prop_handled
4464 handle_composition_prop (it
)
4467 Lisp_Object prop
, string
;
4468 int pos
, pos_byte
, end
;
4469 enum prop_handled handled
= HANDLED_NORMALLY
;
4471 if (STRINGP (it
->string
))
4473 pos
= IT_STRING_CHARPOS (*it
);
4474 pos_byte
= IT_STRING_BYTEPOS (*it
);
4475 string
= it
->string
;
4479 pos
= IT_CHARPOS (*it
);
4480 pos_byte
= IT_BYTEPOS (*it
);
4484 /* If there's a valid composition and point is not inside of the
4485 composition (in the case that the composition is from the current
4486 buffer), draw a glyph composed from the composition components. */
4487 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4488 && COMPOSITION_VALID_P (pos
, end
, prop
)
4489 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4491 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4495 struct composition
*cmp
= composition_table
[id
];
4497 if (cmp
->glyph_len
== 0)
4500 if (STRINGP (it
->string
))
4502 IT_STRING_CHARPOS (*it
) = end
;
4503 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4508 IT_CHARPOS (*it
) = end
;
4509 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4511 return HANDLED_RECOMPUTE_PROPS
;
4514 it
->stop_charpos
= end
;
4517 it
->method
= GET_FROM_COMPOSITION
;
4519 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4520 /* For a terminal, draw only the first character of the
4522 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4523 it
->len
= (STRINGP (it
->string
)
4524 ? string_char_to_byte (it
->string
, end
)
4525 : CHAR_TO_BYTE (end
)) - pos_byte
;
4526 handled
= HANDLED_RETURN
;
4535 /***********************************************************************
4537 ***********************************************************************/
4539 /* The following structure is used to record overlay strings for
4540 later sorting in load_overlay_strings. */
4542 struct overlay_entry
4544 Lisp_Object overlay
;
4551 /* Set up iterator IT from overlay strings at its current position.
4552 Called from handle_stop. */
4554 static enum prop_handled
4555 handle_overlay_change (it
)
4558 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4559 return HANDLED_RECOMPUTE_PROPS
;
4561 return HANDLED_NORMALLY
;
4565 /* Set up the next overlay string for delivery by IT, if there is an
4566 overlay string to deliver. Called by set_iterator_to_next when the
4567 end of the current overlay string is reached. If there are more
4568 overlay strings to display, IT->string and
4569 IT->current.overlay_string_index are set appropriately here.
4570 Otherwise IT->string is set to nil. */
4573 next_overlay_string (it
)
4576 ++it
->current
.overlay_string_index
;
4577 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4579 /* No more overlay strings. Restore IT's settings to what
4580 they were before overlay strings were processed, and
4581 continue to deliver from current_buffer. */
4582 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4586 || it
->method
== GET_FROM_COMPOSITION
4587 || (NILP (it
->string
)
4588 && it
->method
== GET_FROM_BUFFER
4589 && it
->stop_charpos
>= BEGV
4590 && it
->stop_charpos
<= it
->end_charpos
));
4591 it
->current
.overlay_string_index
= -1;
4592 it
->n_overlay_strings
= 0;
4594 /* If we're at the end of the buffer, record that we have
4595 processed the overlay strings there already, so that
4596 next_element_from_buffer doesn't try it again. */
4597 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4598 it
->overlay_strings_at_end_processed_p
= 1;
4600 /* If we have to display `...' for invisible text, set
4601 the iterator up for that. */
4602 if (display_ellipsis_p
)
4603 setup_for_ellipsis (it
, 0);
4607 /* There are more overlay strings to process. If
4608 IT->current.overlay_string_index has advanced to a position
4609 where we must load IT->overlay_strings with more strings, do
4611 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4613 if (it
->current
.overlay_string_index
&& i
== 0)
4614 load_overlay_strings (it
, 0);
4616 /* Initialize IT to deliver display elements from the overlay
4618 it
->string
= it
->overlay_strings
[i
];
4619 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4620 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4621 it
->method
= GET_FROM_STRING
;
4622 it
->stop_charpos
= 0;
4629 /* Compare two overlay_entry structures E1 and E2. Used as a
4630 comparison function for qsort in load_overlay_strings. Overlay
4631 strings for the same position are sorted so that
4633 1. All after-strings come in front of before-strings, except
4634 when they come from the same overlay.
4636 2. Within after-strings, strings are sorted so that overlay strings
4637 from overlays with higher priorities come first.
4639 2. Within before-strings, strings are sorted so that overlay
4640 strings from overlays with higher priorities come last.
4642 Value is analogous to strcmp. */
4646 compare_overlay_entries (e1
, e2
)
4649 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4650 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4653 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4655 /* Let after-strings appear in front of before-strings if
4656 they come from different overlays. */
4657 if (EQ (entry1
->overlay
, entry2
->overlay
))
4658 result
= entry1
->after_string_p
? 1 : -1;
4660 result
= entry1
->after_string_p
? -1 : 1;
4662 else if (entry1
->after_string_p
)
4663 /* After-strings sorted in order of decreasing priority. */
4664 result
= entry2
->priority
- entry1
->priority
;
4666 /* Before-strings sorted in order of increasing priority. */
4667 result
= entry1
->priority
- entry2
->priority
;
4673 /* Load the vector IT->overlay_strings with overlay strings from IT's
4674 current buffer position, or from CHARPOS if that is > 0. Set
4675 IT->n_overlays to the total number of overlay strings found.
4677 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4678 a time. On entry into load_overlay_strings,
4679 IT->current.overlay_string_index gives the number of overlay
4680 strings that have already been loaded by previous calls to this
4683 IT->add_overlay_start contains an additional overlay start
4684 position to consider for taking overlay strings from, if non-zero.
4685 This position comes into play when the overlay has an `invisible'
4686 property, and both before and after-strings. When we've skipped to
4687 the end of the overlay, because of its `invisible' property, we
4688 nevertheless want its before-string to appear.
4689 IT->add_overlay_start will contain the overlay start position
4692 Overlay strings are sorted so that after-string strings come in
4693 front of before-string strings. Within before and after-strings,
4694 strings are sorted by overlay priority. See also function
4695 compare_overlay_entries. */
4698 load_overlay_strings (it
, charpos
)
4702 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4703 Lisp_Object overlay
, window
, str
, invisible
;
4704 struct Lisp_Overlay
*ov
;
4707 int n
= 0, i
, j
, invis_p
;
4708 struct overlay_entry
*entries
4709 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4712 charpos
= IT_CHARPOS (*it
);
4714 /* Append the overlay string STRING of overlay OVERLAY to vector
4715 `entries' which has size `size' and currently contains `n'
4716 elements. AFTER_P non-zero means STRING is an after-string of
4718 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4721 Lisp_Object priority; \
4725 int new_size = 2 * size; \
4726 struct overlay_entry *old = entries; \
4728 (struct overlay_entry *) alloca (new_size \
4729 * sizeof *entries); \
4730 bcopy (old, entries, size * sizeof *entries); \
4734 entries[n].string = (STRING); \
4735 entries[n].overlay = (OVERLAY); \
4736 priority = Foverlay_get ((OVERLAY), Qpriority); \
4737 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4738 entries[n].after_string_p = (AFTER_P); \
4743 /* Process overlay before the overlay center. */
4744 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4746 XSETMISC (overlay
, ov
);
4747 xassert (OVERLAYP (overlay
));
4748 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4749 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4754 /* Skip this overlay if it doesn't start or end at IT's current
4756 if (end
!= charpos
&& start
!= charpos
)
4759 /* Skip this overlay if it doesn't apply to IT->w. */
4760 window
= Foverlay_get (overlay
, Qwindow
);
4761 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4764 /* If the text ``under'' the overlay is invisible, both before-
4765 and after-strings from this overlay are visible; start and
4766 end position are indistinguishable. */
4767 invisible
= Foverlay_get (overlay
, Qinvisible
);
4768 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4770 /* If overlay has a non-empty before-string, record it. */
4771 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4772 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4774 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4776 /* If overlay has a non-empty after-string, record it. */
4777 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4778 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4780 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4783 /* Process overlays after the overlay center. */
4784 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4786 XSETMISC (overlay
, ov
);
4787 xassert (OVERLAYP (overlay
));
4788 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4789 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4791 if (start
> charpos
)
4794 /* Skip this overlay if it doesn't start or end at IT's current
4796 if (end
!= charpos
&& start
!= charpos
)
4799 /* Skip this overlay if it doesn't apply to IT->w. */
4800 window
= Foverlay_get (overlay
, Qwindow
);
4801 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4804 /* If the text ``under'' the overlay is invisible, it has a zero
4805 dimension, and both before- and after-strings apply. */
4806 invisible
= Foverlay_get (overlay
, Qinvisible
);
4807 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4809 /* If overlay has a non-empty before-string, record it. */
4810 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4811 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4813 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4815 /* If overlay has a non-empty after-string, record it. */
4816 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4817 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4819 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4822 #undef RECORD_OVERLAY_STRING
4826 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4828 /* Record the total number of strings to process. */
4829 it
->n_overlay_strings
= n
;
4831 /* IT->current.overlay_string_index is the number of overlay strings
4832 that have already been consumed by IT. Copy some of the
4833 remaining overlay strings to IT->overlay_strings. */
4835 j
= it
->current
.overlay_string_index
;
4836 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4837 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4843 /* Get the first chunk of overlay strings at IT's current buffer
4844 position, or at CHARPOS if that is > 0. Value is non-zero if at
4845 least one overlay string was found. */
4848 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4852 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4853 process. This fills IT->overlay_strings with strings, and sets
4854 IT->n_overlay_strings to the total number of strings to process.
4855 IT->pos.overlay_string_index has to be set temporarily to zero
4856 because load_overlay_strings needs this; it must be set to -1
4857 when no overlay strings are found because a zero value would
4858 indicate a position in the first overlay string. */
4859 it
->current
.overlay_string_index
= 0;
4860 load_overlay_strings (it
, charpos
);
4862 /* If we found overlay strings, set up IT to deliver display
4863 elements from the first one. Otherwise set up IT to deliver
4864 from current_buffer. */
4865 if (it
->n_overlay_strings
)
4867 /* Make sure we know settings in current_buffer, so that we can
4868 restore meaningful values when we're done with the overlay
4871 compute_stop_pos (it
);
4872 xassert (it
->face_id
>= 0);
4874 /* Save IT's settings. They are restored after all overlay
4875 strings have been processed. */
4876 xassert (!compute_stop_p
|| it
->sp
== 0);
4879 /* Set up IT to deliver display elements from the first overlay
4881 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4882 it
->string
= it
->overlay_strings
[0];
4883 it
->stop_charpos
= 0;
4884 xassert (STRINGP (it
->string
));
4885 it
->end_charpos
= SCHARS (it
->string
);
4886 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4887 it
->method
= GET_FROM_STRING
;
4891 it
->current
.overlay_string_index
= -1;
4896 get_overlay_strings (it
, charpos
)
4901 it
->method
= GET_FROM_BUFFER
;
4903 (void) get_overlay_strings_1 (it
, charpos
, 1);
4907 /* Value is non-zero if we found at least one overlay string. */
4908 return STRINGP (it
->string
);
4913 /***********************************************************************
4914 Saving and restoring state
4915 ***********************************************************************/
4917 /* Save current settings of IT on IT->stack. Called, for example,
4918 before setting up IT for an overlay string, to be able to restore
4919 IT's settings to what they were after the overlay string has been
4926 struct iterator_stack_entry
*p
;
4928 xassert (it
->sp
< IT_STACK_SIZE
);
4929 p
= it
->stack
+ it
->sp
;
4931 p
->stop_charpos
= it
->stop_charpos
;
4932 xassert (it
->face_id
>= 0);
4933 p
->face_id
= it
->face_id
;
4934 p
->string
= it
->string
;
4935 p
->method
= it
->method
;
4938 case GET_FROM_IMAGE
:
4939 p
->u
.image
.object
= it
->object
;
4940 p
->u
.image
.image_id
= it
->image_id
;
4941 p
->u
.image
.slice
= it
->slice
;
4943 case GET_FROM_COMPOSITION
:
4944 p
->u
.comp
.object
= it
->object
;
4945 p
->u
.comp
.c
= it
->c
;
4946 p
->u
.comp
.len
= it
->len
;
4947 p
->u
.comp
.cmp_id
= it
->cmp_id
;
4948 p
->u
.comp
.cmp_len
= it
->cmp_len
;
4950 case GET_FROM_STRETCH
:
4951 p
->u
.stretch
.object
= it
->object
;
4954 p
->position
= it
->position
;
4955 p
->current
= it
->current
;
4956 p
->end_charpos
= it
->end_charpos
;
4957 p
->string_nchars
= it
->string_nchars
;
4959 p
->multibyte_p
= it
->multibyte_p
;
4960 p
->space_width
= it
->space_width
;
4961 p
->font_height
= it
->font_height
;
4962 p
->voffset
= it
->voffset
;
4963 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4964 p
->display_ellipsis_p
= 0;
4969 /* Restore IT's settings from IT->stack. Called, for example, when no
4970 more overlay strings must be processed, and we return to delivering
4971 display elements from a buffer, or when the end of a string from a
4972 `display' property is reached and we return to delivering display
4973 elements from an overlay string, or from a buffer. */
4979 struct iterator_stack_entry
*p
;
4981 xassert (it
->sp
> 0);
4983 p
= it
->stack
+ it
->sp
;
4984 it
->stop_charpos
= p
->stop_charpos
;
4985 it
->face_id
= p
->face_id
;
4986 it
->current
= p
->current
;
4987 it
->position
= p
->position
;
4988 it
->string
= p
->string
;
4989 if (NILP (it
->string
))
4990 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4991 it
->method
= p
->method
;
4994 case GET_FROM_IMAGE
:
4995 it
->image_id
= p
->u
.image
.image_id
;
4996 it
->object
= p
->u
.image
.object
;
4997 it
->slice
= p
->u
.image
.slice
;
4999 case GET_FROM_COMPOSITION
:
5000 it
->object
= p
->u
.comp
.object
;
5001 it
->c
= p
->u
.comp
.c
;
5002 it
->len
= p
->u
.comp
.len
;
5003 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5004 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5006 case GET_FROM_STRETCH
:
5007 it
->object
= p
->u
.comp
.object
;
5009 case GET_FROM_BUFFER
:
5010 it
->object
= it
->w
->buffer
;
5012 case GET_FROM_STRING
:
5013 it
->object
= it
->string
;
5016 it
->end_charpos
= p
->end_charpos
;
5017 it
->string_nchars
= p
->string_nchars
;
5019 it
->multibyte_p
= p
->multibyte_p
;
5020 it
->space_width
= p
->space_width
;
5021 it
->font_height
= p
->font_height
;
5022 it
->voffset
= p
->voffset
;
5023 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5028 /***********************************************************************
5030 ***********************************************************************/
5032 /* Set IT's current position to the previous line start. */
5035 back_to_previous_line_start (it
)
5038 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5039 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5043 /* Move IT to the next line start.
5045 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5046 we skipped over part of the text (as opposed to moving the iterator
5047 continuously over the text). Otherwise, don't change the value
5050 Newlines may come from buffer text, overlay strings, or strings
5051 displayed via the `display' property. That's the reason we can't
5052 simply use find_next_newline_no_quit.
5054 Note that this function may not skip over invisible text that is so
5055 because of text properties and immediately follows a newline. If
5056 it would, function reseat_at_next_visible_line_start, when called
5057 from set_iterator_to_next, would effectively make invisible
5058 characters following a newline part of the wrong glyph row, which
5059 leads to wrong cursor motion. */
5062 forward_to_next_line_start (it
, skipped_p
)
5066 int old_selective
, newline_found_p
, n
;
5067 const int MAX_NEWLINE_DISTANCE
= 500;
5069 /* If already on a newline, just consume it to avoid unintended
5070 skipping over invisible text below. */
5071 if (it
->what
== IT_CHARACTER
5073 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5075 set_iterator_to_next (it
, 0);
5080 /* Don't handle selective display in the following. It's (a)
5081 unnecessary because it's done by the caller, and (b) leads to an
5082 infinite recursion because next_element_from_ellipsis indirectly
5083 calls this function. */
5084 old_selective
= it
->selective
;
5087 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5088 from buffer text. */
5089 for (n
= newline_found_p
= 0;
5090 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5091 n
+= STRINGP (it
->string
) ? 0 : 1)
5093 if (!get_next_display_element (it
))
5095 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5096 set_iterator_to_next (it
, 0);
5099 /* If we didn't find a newline near enough, see if we can use a
5101 if (!newline_found_p
)
5103 int start
= IT_CHARPOS (*it
);
5104 int limit
= find_next_newline_no_quit (start
, 1);
5107 xassert (!STRINGP (it
->string
));
5109 /* If there isn't any `display' property in sight, and no
5110 overlays, we can just use the position of the newline in
5112 if (it
->stop_charpos
>= limit
5113 || ((pos
= Fnext_single_property_change (make_number (start
),
5115 Qnil
, make_number (limit
)),
5117 && next_overlay_change (start
) == ZV
))
5119 IT_CHARPOS (*it
) = limit
;
5120 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5121 *skipped_p
= newline_found_p
= 1;
5125 while (get_next_display_element (it
)
5126 && !newline_found_p
)
5128 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5129 set_iterator_to_next (it
, 0);
5134 it
->selective
= old_selective
;
5135 return newline_found_p
;
5139 /* Set IT's current position to the previous visible line start. Skip
5140 invisible text that is so either due to text properties or due to
5141 selective display. Caution: this does not change IT->current_x and
5145 back_to_previous_visible_line_start (it
)
5148 while (IT_CHARPOS (*it
) > BEGV
)
5150 back_to_previous_line_start (it
);
5152 if (IT_CHARPOS (*it
) <= BEGV
)
5155 /* If selective > 0, then lines indented more than that values
5157 if (it
->selective
> 0
5158 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5159 (double) it
->selective
)) /* iftc */
5162 /* Check the newline before point for invisibility. */
5165 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5166 Qinvisible
, it
->window
);
5167 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5171 if (IT_CHARPOS (*it
) <= BEGV
)
5178 Lisp_Object val
, overlay
;
5180 /* If newline is part of a composition, continue from start of composition */
5181 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5182 && beg
< IT_CHARPOS (*it
))
5185 /* If newline is replaced by a display property, find start of overlay
5186 or interval and continue search from that point. */
5188 pos
= --IT_CHARPOS (it2
);
5191 if (handle_display_prop (&it2
) == HANDLED_RETURN
5192 && !NILP (val
= get_char_property_and_overlay
5193 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5194 && (OVERLAYP (overlay
)
5195 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5196 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5199 /* Newline is not replaced by anything -- so we are done. */
5205 IT_CHARPOS (*it
) = beg
;
5206 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5210 it
->continuation_lines_width
= 0;
5212 xassert (IT_CHARPOS (*it
) >= BEGV
);
5213 xassert (IT_CHARPOS (*it
) == BEGV
5214 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5219 /* Reseat iterator IT at the previous visible line start. Skip
5220 invisible text that is so either due to text properties or due to
5221 selective display. At the end, update IT's overlay information,
5222 face information etc. */
5225 reseat_at_previous_visible_line_start (it
)
5228 back_to_previous_visible_line_start (it
);
5229 reseat (it
, it
->current
.pos
, 1);
5234 /* Reseat iterator IT on the next visible line start in the current
5235 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5236 preceding the line start. Skip over invisible text that is so
5237 because of selective display. Compute faces, overlays etc at the
5238 new position. Note that this function does not skip over text that
5239 is invisible because of text properties. */
5242 reseat_at_next_visible_line_start (it
, on_newline_p
)
5246 int newline_found_p
, skipped_p
= 0;
5248 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5250 /* Skip over lines that are invisible because they are indented
5251 more than the value of IT->selective. */
5252 if (it
->selective
> 0)
5253 while (IT_CHARPOS (*it
) < ZV
5254 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5255 (double) it
->selective
)) /* iftc */
5257 xassert (IT_BYTEPOS (*it
) == BEGV
5258 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5259 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5262 /* Position on the newline if that's what's requested. */
5263 if (on_newline_p
&& newline_found_p
)
5265 if (STRINGP (it
->string
))
5267 if (IT_STRING_CHARPOS (*it
) > 0)
5269 --IT_STRING_CHARPOS (*it
);
5270 --IT_STRING_BYTEPOS (*it
);
5273 else if (IT_CHARPOS (*it
) > BEGV
)
5277 reseat (it
, it
->current
.pos
, 0);
5281 reseat (it
, it
->current
.pos
, 0);
5288 /***********************************************************************
5289 Changing an iterator's position
5290 ***********************************************************************/
5292 /* Change IT's current position to POS in current_buffer. If FORCE_P
5293 is non-zero, always check for text properties at the new position.
5294 Otherwise, text properties are only looked up if POS >=
5295 IT->check_charpos of a property. */
5298 reseat (it
, pos
, force_p
)
5300 struct text_pos pos
;
5303 int original_pos
= IT_CHARPOS (*it
);
5305 reseat_1 (it
, pos
, 0);
5307 /* Determine where to check text properties. Avoid doing it
5308 where possible because text property lookup is very expensive. */
5310 || CHARPOS (pos
) > it
->stop_charpos
5311 || CHARPOS (pos
) < original_pos
)
5318 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5319 IT->stop_pos to POS, also. */
5322 reseat_1 (it
, pos
, set_stop_p
)
5324 struct text_pos pos
;
5327 /* Don't call this function when scanning a C string. */
5328 xassert (it
->s
== NULL
);
5330 /* POS must be a reasonable value. */
5331 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5333 it
->current
.pos
= it
->position
= pos
;
5334 it
->end_charpos
= ZV
;
5336 it
->current
.dpvec_index
= -1;
5337 it
->current
.overlay_string_index
= -1;
5338 IT_STRING_CHARPOS (*it
) = -1;
5339 IT_STRING_BYTEPOS (*it
) = -1;
5341 it
->method
= GET_FROM_BUFFER
;
5342 it
->object
= it
->w
->buffer
;
5343 it
->area
= TEXT_AREA
;
5344 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5346 it
->string_from_display_prop_p
= 0;
5347 it
->face_before_selective_p
= 0;
5350 it
->stop_charpos
= CHARPOS (pos
);
5354 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5355 If S is non-null, it is a C string to iterate over. Otherwise,
5356 STRING gives a Lisp string to iterate over.
5358 If PRECISION > 0, don't return more then PRECISION number of
5359 characters from the string.
5361 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5362 characters have been returned. FIELD_WIDTH < 0 means an infinite
5365 MULTIBYTE = 0 means disable processing of multibyte characters,
5366 MULTIBYTE > 0 means enable it,
5367 MULTIBYTE < 0 means use IT->multibyte_p.
5369 IT must be initialized via a prior call to init_iterator before
5370 calling this function. */
5373 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5378 int precision
, field_width
, multibyte
;
5380 /* No region in strings. */
5381 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5383 /* No text property checks performed by default, but see below. */
5384 it
->stop_charpos
= -1;
5386 /* Set iterator position and end position. */
5387 bzero (&it
->current
, sizeof it
->current
);
5388 it
->current
.overlay_string_index
= -1;
5389 it
->current
.dpvec_index
= -1;
5390 xassert (charpos
>= 0);
5392 /* If STRING is specified, use its multibyteness, otherwise use the
5393 setting of MULTIBYTE, if specified. */
5395 it
->multibyte_p
= multibyte
> 0;
5399 xassert (STRINGP (string
));
5400 it
->string
= string
;
5402 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5403 it
->method
= GET_FROM_STRING
;
5404 it
->current
.string_pos
= string_pos (charpos
, string
);
5411 /* Note that we use IT->current.pos, not it->current.string_pos,
5412 for displaying C strings. */
5413 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5414 if (it
->multibyte_p
)
5416 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5417 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5421 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5422 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5425 it
->method
= GET_FROM_C_STRING
;
5428 /* PRECISION > 0 means don't return more than PRECISION characters
5430 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5431 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5433 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5434 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5435 FIELD_WIDTH < 0 means infinite field width. This is useful for
5436 padding with `-' at the end of a mode line. */
5437 if (field_width
< 0)
5438 field_width
= INFINITY
;
5439 if (field_width
> it
->end_charpos
- charpos
)
5440 it
->end_charpos
= charpos
+ field_width
;
5442 /* Use the standard display table for displaying strings. */
5443 if (DISP_TABLE_P (Vstandard_display_table
))
5444 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5446 it
->stop_charpos
= charpos
;
5452 /***********************************************************************
5454 ***********************************************************************/
5456 /* Map enum it_method value to corresponding next_element_from_* function. */
5458 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5460 next_element_from_buffer
,
5461 next_element_from_display_vector
,
5462 next_element_from_composition
,
5463 next_element_from_string
,
5464 next_element_from_c_string
,
5465 next_element_from_image
,
5466 next_element_from_stretch
5470 /* Load IT's display element fields with information about the next
5471 display element from the current position of IT. Value is zero if
5472 end of buffer (or C string) is reached. */
5474 static struct frame
*last_escape_glyph_frame
= NULL
;
5475 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5476 static int last_escape_glyph_merged_face_id
= 0;
5479 get_next_display_element (it
)
5482 /* Non-zero means that we found a display element. Zero means that
5483 we hit the end of what we iterate over. Performance note: the
5484 function pointer `method' used here turns out to be faster than
5485 using a sequence of if-statements. */
5489 success_p
= (*get_next_element
[it
->method
]) (it
);
5491 if (it
->what
== IT_CHARACTER
)
5493 /* Map via display table or translate control characters.
5494 IT->c, IT->len etc. have been set to the next character by
5495 the function call above. If we have a display table, and it
5496 contains an entry for IT->c, translate it. Don't do this if
5497 IT->c itself comes from a display table, otherwise we could
5498 end up in an infinite recursion. (An alternative could be to
5499 count the recursion depth of this function and signal an
5500 error when a certain maximum depth is reached.) Is it worth
5502 if (success_p
&& it
->dpvec
== NULL
)
5507 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5510 struct Lisp_Vector
*v
= XVECTOR (dv
);
5512 /* Return the first character from the display table
5513 entry, if not empty. If empty, don't display the
5514 current character. */
5517 it
->dpvec_char_len
= it
->len
;
5518 it
->dpvec
= v
->contents
;
5519 it
->dpend
= v
->contents
+ v
->size
;
5520 it
->current
.dpvec_index
= 0;
5521 it
->dpvec_face_id
= -1;
5522 it
->saved_face_id
= it
->face_id
;
5523 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5528 set_iterator_to_next (it
, 0);
5533 /* Translate control characters into `\003' or `^C' form.
5534 Control characters coming from a display table entry are
5535 currently not translated because we use IT->dpvec to hold
5536 the translation. This could easily be changed but I
5537 don't believe that it is worth doing.
5539 If it->multibyte_p is nonzero, eight-bit characters and
5540 non-printable multibyte characters are also translated to
5543 If it->multibyte_p is zero, eight-bit characters that
5544 don't have corresponding multibyte char code are also
5545 translated to octal form. */
5546 else if ((it
->c
< ' '
5547 && (it
->area
!= TEXT_AREA
5548 /* In mode line, treat \n like other crl chars. */
5550 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5551 || (it
->c
!= '\n' && it
->c
!= '\t')))
5555 || !CHAR_PRINTABLE_P (it
->c
)
5556 || (!NILP (Vnobreak_char_display
)
5557 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5558 || it
->c
== 0x920 || it
->c
== 0x92d
5559 || it
->c
== 0xe20 || it
->c
== 0xe2d
5560 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5562 && (!unibyte_display_via_language_environment
5563 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5565 /* IT->c is a control character which must be displayed
5566 either as '\003' or as `^C' where the '\\' and '^'
5567 can be defined in the display table. Fill
5568 IT->ctl_chars with glyphs for what we have to
5569 display. Then, set IT->dpvec to these glyphs. */
5572 int face_id
, lface_id
= 0 ;
5575 /* Handle control characters with ^. */
5577 if (it
->c
< 128 && it
->ctl_arrow_p
)
5579 g
= '^'; /* default glyph for Control */
5580 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5582 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5583 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5585 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5586 lface_id
= FAST_GLYPH_FACE (g
);
5590 g
= FAST_GLYPH_CHAR (g
);
5591 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5594 else if (it
->f
== last_escape_glyph_frame
5595 && it
->face_id
== last_escape_glyph_face_id
)
5597 face_id
= last_escape_glyph_merged_face_id
;
5601 /* Merge the escape-glyph face into the current face. */
5602 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5604 last_escape_glyph_frame
= it
->f
;
5605 last_escape_glyph_face_id
= it
->face_id
;
5606 last_escape_glyph_merged_face_id
= face_id
;
5609 XSETINT (it
->ctl_chars
[0], g
);
5611 XSETINT (it
->ctl_chars
[1], g
);
5613 goto display_control
;
5616 /* Handle non-break space in the mode where it only gets
5619 if (EQ (Vnobreak_char_display
, Qt
)
5620 && (it
->c
== 0x8a0 || it
->c
== 0x920
5621 || it
->c
== 0xe20 || it
->c
== 0xf20))
5623 /* Merge the no-break-space face into the current face. */
5624 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5628 XSETINT (it
->ctl_chars
[0], g
);
5630 goto display_control
;
5633 /* Handle sequences that start with the "escape glyph". */
5635 /* the default escape glyph is \. */
5636 escape_glyph
= '\\';
5639 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5640 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5642 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5643 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5647 /* The display table specified a face.
5648 Merge it into face_id and also into escape_glyph. */
5649 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5650 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5653 else if (it
->f
== last_escape_glyph_frame
5654 && it
->face_id
== last_escape_glyph_face_id
)
5656 face_id
= last_escape_glyph_merged_face_id
;
5660 /* Merge the escape-glyph face into the current face. */
5661 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5663 last_escape_glyph_frame
= it
->f
;
5664 last_escape_glyph_face_id
= it
->face_id
;
5665 last_escape_glyph_merged_face_id
= face_id
;
5668 /* Handle soft hyphens in the mode where they only get
5671 if (EQ (Vnobreak_char_display
, Qt
)
5672 && (it
->c
== 0x8ad || it
->c
== 0x92d
5673 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5676 XSETINT (it
->ctl_chars
[0], g
);
5678 goto display_control
;
5681 /* Handle non-break space and soft hyphen
5682 with the escape glyph. */
5684 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5685 || it
->c
== 0x920 || it
->c
== 0x92d
5686 || it
->c
== 0xe20 || it
->c
== 0xe2d
5687 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5689 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5690 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5691 XSETINT (it
->ctl_chars
[1], g
);
5693 goto display_control
;
5697 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5701 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5702 if (SINGLE_BYTE_CHAR_P (it
->c
))
5703 str
[0] = it
->c
, len
= 1;
5706 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5709 /* It's an invalid character, which shouldn't
5710 happen actually, but due to bugs it may
5711 happen. Let's print the char as is, there's
5712 not much meaningful we can do with it. */
5714 str
[1] = it
->c
>> 8;
5715 str
[2] = it
->c
>> 16;
5716 str
[3] = it
->c
>> 24;
5721 for (i
= 0; i
< len
; i
++)
5723 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5724 /* Insert three more glyphs into IT->ctl_chars for
5725 the octal display of the character. */
5726 g
= ((str
[i
] >> 6) & 7) + '0';
5727 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5728 g
= ((str
[i
] >> 3) & 7) + '0';
5729 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5730 g
= (str
[i
] & 7) + '0';
5731 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5737 /* Set up IT->dpvec and return first character from it. */
5738 it
->dpvec_char_len
= it
->len
;
5739 it
->dpvec
= it
->ctl_chars
;
5740 it
->dpend
= it
->dpvec
+ ctl_len
;
5741 it
->current
.dpvec_index
= 0;
5742 it
->dpvec_face_id
= face_id
;
5743 it
->saved_face_id
= it
->face_id
;
5744 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5750 /* Adjust face id for a multibyte character. There are no
5751 multibyte character in unibyte text. */
5754 && FRAME_WINDOW_P (it
->f
))
5756 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5757 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5761 /* Is this character the last one of a run of characters with
5762 box? If yes, set IT->end_of_box_run_p to 1. */
5769 it
->end_of_box_run_p
5770 = ((face_id
= face_after_it_pos (it
),
5771 face_id
!= it
->face_id
)
5772 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5773 face
->box
== FACE_NO_BOX
));
5776 /* Value is 0 if end of buffer or string reached. */
5781 /* Move IT to the next display element.
5783 RESEAT_P non-zero means if called on a newline in buffer text,
5784 skip to the next visible line start.
5786 Functions get_next_display_element and set_iterator_to_next are
5787 separate because I find this arrangement easier to handle than a
5788 get_next_display_element function that also increments IT's
5789 position. The way it is we can first look at an iterator's current
5790 display element, decide whether it fits on a line, and if it does,
5791 increment the iterator position. The other way around we probably
5792 would either need a flag indicating whether the iterator has to be
5793 incremented the next time, or we would have to implement a
5794 decrement position function which would not be easy to write. */
5797 set_iterator_to_next (it
, reseat_p
)
5801 /* Reset flags indicating start and end of a sequence of characters
5802 with box. Reset them at the start of this function because
5803 moving the iterator to a new position might set them. */
5804 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5808 case GET_FROM_BUFFER
:
5809 /* The current display element of IT is a character from
5810 current_buffer. Advance in the buffer, and maybe skip over
5811 invisible lines that are so because of selective display. */
5812 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5813 reseat_at_next_visible_line_start (it
, 0);
5816 xassert (it
->len
!= 0);
5817 IT_BYTEPOS (*it
) += it
->len
;
5818 IT_CHARPOS (*it
) += 1;
5819 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5823 case GET_FROM_COMPOSITION
:
5824 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5825 xassert (it
->sp
> 0);
5827 if (it
->method
== GET_FROM_STRING
)
5829 IT_STRING_BYTEPOS (*it
) += it
->len
;
5830 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5831 goto consider_string_end
;
5833 else if (it
->method
== GET_FROM_BUFFER
)
5835 IT_BYTEPOS (*it
) += it
->len
;
5836 IT_CHARPOS (*it
) += it
->cmp_len
;
5840 case GET_FROM_C_STRING
:
5841 /* Current display element of IT is from a C string. */
5842 IT_BYTEPOS (*it
) += it
->len
;
5843 IT_CHARPOS (*it
) += 1;
5846 case GET_FROM_DISPLAY_VECTOR
:
5847 /* Current display element of IT is from a display table entry.
5848 Advance in the display table definition. Reset it to null if
5849 end reached, and continue with characters from buffers/
5851 ++it
->current
.dpvec_index
;
5853 /* Restore face of the iterator to what they were before the
5854 display vector entry (these entries may contain faces). */
5855 it
->face_id
= it
->saved_face_id
;
5857 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5859 int recheck_faces
= it
->ellipsis_p
;
5862 it
->method
= GET_FROM_C_STRING
;
5863 else if (STRINGP (it
->string
))
5864 it
->method
= GET_FROM_STRING
;
5867 it
->method
= GET_FROM_BUFFER
;
5868 it
->object
= it
->w
->buffer
;
5872 it
->current
.dpvec_index
= -1;
5874 /* Skip over characters which were displayed via IT->dpvec. */
5875 if (it
->dpvec_char_len
< 0)
5876 reseat_at_next_visible_line_start (it
, 1);
5877 else if (it
->dpvec_char_len
> 0)
5879 if (it
->method
== GET_FROM_STRING
5880 && it
->n_overlay_strings
> 0)
5881 it
->ignore_overlay_strings_at_pos_p
= 1;
5882 it
->len
= it
->dpvec_char_len
;
5883 set_iterator_to_next (it
, reseat_p
);
5886 /* Maybe recheck faces after display vector */
5888 it
->stop_charpos
= IT_CHARPOS (*it
);
5892 case GET_FROM_STRING
:
5893 /* Current display element is a character from a Lisp string. */
5894 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5895 IT_STRING_BYTEPOS (*it
) += it
->len
;
5896 IT_STRING_CHARPOS (*it
) += 1;
5898 consider_string_end
:
5900 if (it
->current
.overlay_string_index
>= 0)
5902 /* IT->string is an overlay string. Advance to the
5903 next, if there is one. */
5904 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5905 next_overlay_string (it
);
5909 /* IT->string is not an overlay string. If we reached
5910 its end, and there is something on IT->stack, proceed
5911 with what is on the stack. This can be either another
5912 string, this time an overlay string, or a buffer. */
5913 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5917 if (it
->method
== GET_FROM_STRING
)
5918 goto consider_string_end
;
5923 case GET_FROM_IMAGE
:
5924 case GET_FROM_STRETCH
:
5925 /* The position etc with which we have to proceed are on
5926 the stack. The position may be at the end of a string,
5927 if the `display' property takes up the whole string. */
5928 xassert (it
->sp
> 0);
5930 if (it
->method
== GET_FROM_STRING
)
5931 goto consider_string_end
;
5935 /* There are no other methods defined, so this should be a bug. */
5939 xassert (it
->method
!= GET_FROM_STRING
5940 || (STRINGP (it
->string
)
5941 && IT_STRING_CHARPOS (*it
) >= 0));
5944 /* Load IT's display element fields with information about the next
5945 display element which comes from a display table entry or from the
5946 result of translating a control character to one of the forms `^C'
5949 IT->dpvec holds the glyphs to return as characters.
5950 IT->saved_face_id holds the face id before the display vector--
5951 it is restored into IT->face_idin set_iterator_to_next. */
5954 next_element_from_display_vector (it
)
5958 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5960 it
->face_id
= it
->saved_face_id
;
5962 if (INTEGERP (*it
->dpvec
)
5963 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5967 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5968 it
->c
= FAST_GLYPH_CHAR (g
);
5969 it
->len
= CHAR_BYTES (it
->c
);
5971 /* The entry may contain a face id to use. Such a face id is
5972 the id of a Lisp face, not a realized face. A face id of
5973 zero means no face is specified. */
5974 if (it
->dpvec_face_id
>= 0)
5975 it
->face_id
= it
->dpvec_face_id
;
5978 int lface_id
= FAST_GLYPH_FACE (g
);
5980 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5985 /* Display table entry is invalid. Return a space. */
5986 it
->c
= ' ', it
->len
= 1;
5988 /* Don't change position and object of the iterator here. They are
5989 still the values of the character that had this display table
5990 entry or was translated, and that's what we want. */
5991 it
->what
= IT_CHARACTER
;
5996 /* Load IT with the next display element from Lisp string IT->string.
5997 IT->current.string_pos is the current position within the string.
5998 If IT->current.overlay_string_index >= 0, the Lisp string is an
6002 next_element_from_string (it
)
6005 struct text_pos position
;
6007 xassert (STRINGP (it
->string
));
6008 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6009 position
= it
->current
.string_pos
;
6011 /* Time to check for invisible text? */
6012 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6013 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6017 /* Since a handler may have changed IT->method, we must
6019 return get_next_display_element (it
);
6022 if (it
->current
.overlay_string_index
>= 0)
6024 /* Get the next character from an overlay string. In overlay
6025 strings, There is no field width or padding with spaces to
6027 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6032 else if (STRING_MULTIBYTE (it
->string
))
6034 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6035 const unsigned char *s
= (SDATA (it
->string
)
6036 + IT_STRING_BYTEPOS (*it
));
6037 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6041 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6047 /* Get the next character from a Lisp string that is not an
6048 overlay string. Such strings come from the mode line, for
6049 example. We may have to pad with spaces, or truncate the
6050 string. See also next_element_from_c_string. */
6051 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6056 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6058 /* Pad with spaces. */
6059 it
->c
= ' ', it
->len
= 1;
6060 CHARPOS (position
) = BYTEPOS (position
) = -1;
6062 else if (STRING_MULTIBYTE (it
->string
))
6064 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6065 const unsigned char *s
= (SDATA (it
->string
)
6066 + IT_STRING_BYTEPOS (*it
));
6067 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6071 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6076 /* Record what we have and where it came from. */
6077 it
->what
= IT_CHARACTER
;
6078 it
->object
= it
->string
;
6079 it
->position
= position
;
6084 /* Load IT with next display element from C string IT->s.
6085 IT->string_nchars is the maximum number of characters to return
6086 from the string. IT->end_charpos may be greater than
6087 IT->string_nchars when this function is called, in which case we
6088 may have to return padding spaces. Value is zero if end of string
6089 reached, including padding spaces. */
6092 next_element_from_c_string (it
)
6098 it
->what
= IT_CHARACTER
;
6099 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6102 /* IT's position can be greater IT->string_nchars in case a field
6103 width or precision has been specified when the iterator was
6105 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6107 /* End of the game. */
6111 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6113 /* Pad with spaces. */
6114 it
->c
= ' ', it
->len
= 1;
6115 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6117 else if (it
->multibyte_p
)
6119 /* Implementation note: The calls to strlen apparently aren't a
6120 performance problem because there is no noticeable performance
6121 difference between Emacs running in unibyte or multibyte mode. */
6122 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6123 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6127 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6133 /* Set up IT to return characters from an ellipsis, if appropriate.
6134 The definition of the ellipsis glyphs may come from a display table
6135 entry. This function Fills IT with the first glyph from the
6136 ellipsis if an ellipsis is to be displayed. */
6139 next_element_from_ellipsis (it
)
6142 if (it
->selective_display_ellipsis_p
)
6143 setup_for_ellipsis (it
, it
->len
);
6146 /* The face at the current position may be different from the
6147 face we find after the invisible text. Remember what it
6148 was in IT->saved_face_id, and signal that it's there by
6149 setting face_before_selective_p. */
6150 it
->saved_face_id
= it
->face_id
;
6151 it
->method
= GET_FROM_BUFFER
;
6152 it
->object
= it
->w
->buffer
;
6153 reseat_at_next_visible_line_start (it
, 1);
6154 it
->face_before_selective_p
= 1;
6157 return get_next_display_element (it
);
6161 /* Deliver an image display element. The iterator IT is already
6162 filled with image information (done in handle_display_prop). Value
6167 next_element_from_image (it
)
6170 it
->what
= IT_IMAGE
;
6175 /* Fill iterator IT with next display element from a stretch glyph
6176 property. IT->object is the value of the text property. Value is
6180 next_element_from_stretch (it
)
6183 it
->what
= IT_STRETCH
;
6188 /* Load IT with the next display element from current_buffer. Value
6189 is zero if end of buffer reached. IT->stop_charpos is the next
6190 position at which to stop and check for text properties or buffer
6194 next_element_from_buffer (it
)
6199 /* Check this assumption, otherwise, we would never enter the
6200 if-statement, below. */
6201 xassert (IT_CHARPOS (*it
) >= BEGV
6202 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6204 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6206 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6208 int overlay_strings_follow_p
;
6210 /* End of the game, except when overlay strings follow that
6211 haven't been returned yet. */
6212 if (it
->overlay_strings_at_end_processed_p
)
6213 overlay_strings_follow_p
= 0;
6216 it
->overlay_strings_at_end_processed_p
= 1;
6217 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6220 if (overlay_strings_follow_p
)
6221 success_p
= get_next_display_element (it
);
6225 it
->position
= it
->current
.pos
;
6232 return get_next_display_element (it
);
6237 /* No face changes, overlays etc. in sight, so just return a
6238 character from current_buffer. */
6241 /* Maybe run the redisplay end trigger hook. Performance note:
6242 This doesn't seem to cost measurable time. */
6243 if (it
->redisplay_end_trigger_charpos
6245 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6246 run_redisplay_end_trigger_hook (it
);
6248 /* Get the next character, maybe multibyte. */
6249 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6250 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6252 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6253 - IT_BYTEPOS (*it
));
6254 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6257 it
->c
= *p
, it
->len
= 1;
6259 /* Record what we have and where it came from. */
6260 it
->what
= IT_CHARACTER
;;
6261 it
->object
= it
->w
->buffer
;
6262 it
->position
= it
->current
.pos
;
6264 /* Normally we return the character found above, except when we
6265 really want to return an ellipsis for selective display. */
6270 /* A value of selective > 0 means hide lines indented more
6271 than that number of columns. */
6272 if (it
->selective
> 0
6273 && IT_CHARPOS (*it
) + 1 < ZV
6274 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6275 IT_BYTEPOS (*it
) + 1,
6276 (double) it
->selective
)) /* iftc */
6278 success_p
= next_element_from_ellipsis (it
);
6279 it
->dpvec_char_len
= -1;
6282 else if (it
->c
== '\r' && it
->selective
== -1)
6284 /* A value of selective == -1 means that everything from the
6285 CR to the end of the line is invisible, with maybe an
6286 ellipsis displayed for it. */
6287 success_p
= next_element_from_ellipsis (it
);
6288 it
->dpvec_char_len
= -1;
6293 /* Value is zero if end of buffer reached. */
6294 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6299 /* Run the redisplay end trigger hook for IT. */
6302 run_redisplay_end_trigger_hook (it
)
6305 Lisp_Object args
[3];
6307 /* IT->glyph_row should be non-null, i.e. we should be actually
6308 displaying something, or otherwise we should not run the hook. */
6309 xassert (it
->glyph_row
);
6311 /* Set up hook arguments. */
6312 args
[0] = Qredisplay_end_trigger_functions
;
6313 args
[1] = it
->window
;
6314 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6315 it
->redisplay_end_trigger_charpos
= 0;
6317 /* Since we are *trying* to run these functions, don't try to run
6318 them again, even if they get an error. */
6319 it
->w
->redisplay_end_trigger
= Qnil
;
6320 Frun_hook_with_args (3, args
);
6322 /* Notice if it changed the face of the character we are on. */
6323 handle_face_prop (it
);
6327 /* Deliver a composition display element. The iterator IT is already
6328 filled with composition information (done in
6329 handle_composition_prop). Value is always 1. */
6332 next_element_from_composition (it
)
6335 it
->what
= IT_COMPOSITION
;
6336 it
->position
= (STRINGP (it
->string
)
6337 ? it
->current
.string_pos
6339 if (STRINGP (it
->string
))
6340 it
->object
= it
->string
;
6342 it
->object
= it
->w
->buffer
;
6348 /***********************************************************************
6349 Moving an iterator without producing glyphs
6350 ***********************************************************************/
6352 /* Check if iterator is at a position corresponding to a valid buffer
6353 position after some move_it_ call. */
6355 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6356 ((it)->method == GET_FROM_STRING \
6357 ? IT_STRING_CHARPOS (*it) == 0 \
6361 /* Move iterator IT to a specified buffer or X position within one
6362 line on the display without producing glyphs.
6364 OP should be a bit mask including some or all of these bits:
6365 MOVE_TO_X: Stop on reaching x-position TO_X.
6366 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6367 Regardless of OP's value, stop in reaching the end of the display line.
6369 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6370 This means, in particular, that TO_X includes window's horizontal
6373 The return value has several possible values that
6374 say what condition caused the scan to stop:
6376 MOVE_POS_MATCH_OR_ZV
6377 - when TO_POS or ZV was reached.
6380 -when TO_X was reached before TO_POS or ZV were reached.
6383 - when we reached the end of the display area and the line must
6387 - when we reached the end of the display area and the line is
6391 - when we stopped at a line end, i.e. a newline or a CR and selective
6394 static enum move_it_result
6395 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6397 int to_charpos
, to_x
, op
;
6399 enum move_it_result result
= MOVE_UNDEFINED
;
6400 struct glyph_row
*saved_glyph_row
;
6402 /* Don't produce glyphs in produce_glyphs. */
6403 saved_glyph_row
= it
->glyph_row
;
6404 it
->glyph_row
= NULL
;
6406 #define BUFFER_POS_REACHED_P() \
6407 ((op & MOVE_TO_POS) != 0 \
6408 && BUFFERP (it->object) \
6409 && IT_CHARPOS (*it) >= to_charpos \
6410 && (it->method == GET_FROM_BUFFER \
6411 || (it->method == GET_FROM_DISPLAY_VECTOR \
6412 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6417 int x
, i
, ascent
= 0, descent
= 0;
6419 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6420 if ((op
& MOVE_TO_POS
) != 0
6421 && BUFFERP (it
->object
)
6422 && it
->method
== GET_FROM_BUFFER
6423 && IT_CHARPOS (*it
) > to_charpos
)
6425 result
= MOVE_POS_MATCH_OR_ZV
;
6429 /* Stop when ZV reached.
6430 We used to stop here when TO_CHARPOS reached as well, but that is
6431 too soon if this glyph does not fit on this line. So we handle it
6432 explicitly below. */
6433 if (!get_next_display_element (it
)
6434 || (it
->truncate_lines_p
6435 && BUFFER_POS_REACHED_P ()))
6437 result
= MOVE_POS_MATCH_OR_ZV
;
6441 /* The call to produce_glyphs will get the metrics of the
6442 display element IT is loaded with. We record in x the
6443 x-position before this display element in case it does not
6447 /* Remember the line height so far in case the next element doesn't
6449 if (!it
->truncate_lines_p
)
6451 ascent
= it
->max_ascent
;
6452 descent
= it
->max_descent
;
6455 PRODUCE_GLYPHS (it
);
6457 if (it
->area
!= TEXT_AREA
)
6459 set_iterator_to_next (it
, 1);
6463 /* The number of glyphs we get back in IT->nglyphs will normally
6464 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6465 character on a terminal frame, or (iii) a line end. For the
6466 second case, IT->nglyphs - 1 padding glyphs will be present
6467 (on X frames, there is only one glyph produced for a
6468 composite character.
6470 The behavior implemented below means, for continuation lines,
6471 that as many spaces of a TAB as fit on the current line are
6472 displayed there. For terminal frames, as many glyphs of a
6473 multi-glyph character are displayed in the current line, too.
6474 This is what the old redisplay code did, and we keep it that
6475 way. Under X, the whole shape of a complex character must
6476 fit on the line or it will be completely displayed in the
6479 Note that both for tabs and padding glyphs, all glyphs have
6483 /* More than one glyph or glyph doesn't fit on line. All
6484 glyphs have the same width. */
6485 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6487 int x_before_this_char
= x
;
6488 int hpos_before_this_char
= it
->hpos
;
6490 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6492 new_x
= x
+ single_glyph_width
;
6494 /* We want to leave anything reaching TO_X to the caller. */
6495 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6497 if (BUFFER_POS_REACHED_P ())
6498 goto buffer_pos_reached
;
6500 result
= MOVE_X_REACHED
;
6503 else if (/* Lines are continued. */
6504 !it
->truncate_lines_p
6505 && (/* And glyph doesn't fit on the line. */
6506 new_x
> it
->last_visible_x
6507 /* Or it fits exactly and we're on a window
6509 || (new_x
== it
->last_visible_x
6510 && FRAME_WINDOW_P (it
->f
))))
6512 if (/* IT->hpos == 0 means the very first glyph
6513 doesn't fit on the line, e.g. a wide image. */
6515 || (new_x
== it
->last_visible_x
6516 && FRAME_WINDOW_P (it
->f
)))
6519 it
->current_x
= new_x
;
6521 /* The character's last glyph just barely fits
6523 if (i
== it
->nglyphs
- 1)
6525 /* If this is the destination position,
6526 return a position *before* it in this row,
6527 now that we know it fits in this row. */
6528 if (BUFFER_POS_REACHED_P ())
6530 it
->hpos
= hpos_before_this_char
;
6531 it
->current_x
= x_before_this_char
;
6532 result
= MOVE_POS_MATCH_OR_ZV
;
6536 set_iterator_to_next (it
, 1);
6537 #ifdef HAVE_WINDOW_SYSTEM
6538 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6540 if (!get_next_display_element (it
))
6542 result
= MOVE_POS_MATCH_OR_ZV
;
6545 if (BUFFER_POS_REACHED_P ())
6547 if (ITERATOR_AT_END_OF_LINE_P (it
))
6548 result
= MOVE_POS_MATCH_OR_ZV
;
6550 result
= MOVE_LINE_CONTINUED
;
6553 if (ITERATOR_AT_END_OF_LINE_P (it
))
6555 result
= MOVE_NEWLINE_OR_CR
;
6559 #endif /* HAVE_WINDOW_SYSTEM */
6565 it
->max_ascent
= ascent
;
6566 it
->max_descent
= descent
;
6569 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6571 result
= MOVE_LINE_CONTINUED
;
6574 else if (BUFFER_POS_REACHED_P ())
6575 goto buffer_pos_reached
;
6576 else if (new_x
> it
->first_visible_x
)
6578 /* Glyph is visible. Increment number of glyphs that
6579 would be displayed. */
6584 /* Glyph is completely off the left margin of the display
6585 area. Nothing to do. */
6589 if (result
!= MOVE_UNDEFINED
)
6592 else if (BUFFER_POS_REACHED_P ())
6596 it
->max_ascent
= ascent
;
6597 it
->max_descent
= descent
;
6598 result
= MOVE_POS_MATCH_OR_ZV
;
6601 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6603 /* Stop when TO_X specified and reached. This check is
6604 necessary here because of lines consisting of a line end,
6605 only. The line end will not produce any glyphs and we
6606 would never get MOVE_X_REACHED. */
6607 xassert (it
->nglyphs
== 0);
6608 result
= MOVE_X_REACHED
;
6612 /* Is this a line end? If yes, we're done. */
6613 if (ITERATOR_AT_END_OF_LINE_P (it
))
6615 result
= MOVE_NEWLINE_OR_CR
;
6619 /* The current display element has been consumed. Advance
6621 set_iterator_to_next (it
, 1);
6623 /* Stop if lines are truncated and IT's current x-position is
6624 past the right edge of the window now. */
6625 if (it
->truncate_lines_p
6626 && it
->current_x
>= it
->last_visible_x
)
6628 #ifdef HAVE_WINDOW_SYSTEM
6629 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6631 if (!get_next_display_element (it
)
6632 || BUFFER_POS_REACHED_P ())
6634 result
= MOVE_POS_MATCH_OR_ZV
;
6637 if (ITERATOR_AT_END_OF_LINE_P (it
))
6639 result
= MOVE_NEWLINE_OR_CR
;
6643 #endif /* HAVE_WINDOW_SYSTEM */
6644 result
= MOVE_LINE_TRUNCATED
;
6649 #undef BUFFER_POS_REACHED_P
6651 /* Restore the iterator settings altered at the beginning of this
6653 it
->glyph_row
= saved_glyph_row
;
6658 /* Move IT forward until it satisfies one or more of the criteria in
6659 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6661 OP is a bit-mask that specifies where to stop, and in particular,
6662 which of those four position arguments makes a difference. See the
6663 description of enum move_operation_enum.
6665 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6666 screen line, this function will set IT to the next position >
6670 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6672 int to_charpos
, to_x
, to_y
, to_vpos
;
6675 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6681 if (op
& MOVE_TO_VPOS
)
6683 /* If no TO_CHARPOS and no TO_X specified, stop at the
6684 start of the line TO_VPOS. */
6685 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6687 if (it
->vpos
== to_vpos
)
6693 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6697 /* TO_VPOS >= 0 means stop at TO_X in the line at
6698 TO_VPOS, or at TO_POS, whichever comes first. */
6699 if (it
->vpos
== to_vpos
)
6705 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6707 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6712 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6714 /* We have reached TO_X but not in the line we want. */
6715 skip
= move_it_in_display_line_to (it
, to_charpos
,
6717 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6725 else if (op
& MOVE_TO_Y
)
6727 struct it it_backup
;
6729 /* TO_Y specified means stop at TO_X in the line containing
6730 TO_Y---or at TO_CHARPOS if this is reached first. The
6731 problem is that we can't really tell whether the line
6732 contains TO_Y before we have completely scanned it, and
6733 this may skip past TO_X. What we do is to first scan to
6736 If TO_X is not specified, use a TO_X of zero. The reason
6737 is to make the outcome of this function more predictable.
6738 If we didn't use TO_X == 0, we would stop at the end of
6739 the line which is probably not what a caller would expect
6741 skip
= move_it_in_display_line_to (it
, to_charpos
,
6745 | (op
& MOVE_TO_POS
)));
6747 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6748 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6754 /* If TO_X was reached, we would like to know whether TO_Y
6755 is in the line. This can only be said if we know the
6756 total line height which requires us to scan the rest of
6758 if (skip
== MOVE_X_REACHED
)
6761 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6762 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6764 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6767 /* Now, decide whether TO_Y is in this line. */
6768 line_height
= it
->max_ascent
+ it
->max_descent
;
6769 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6771 if (to_y
>= it
->current_y
6772 && to_y
< it
->current_y
+ line_height
)
6774 if (skip
== MOVE_X_REACHED
)
6775 /* If TO_Y is in this line and TO_X was reached above,
6776 we scanned too far. We have to restore IT's settings
6777 to the ones before skipping. */
6781 else if (skip
== MOVE_X_REACHED
)
6784 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6791 else if (BUFFERP (it
->object
)
6792 && it
->method
== GET_FROM_BUFFER
6793 && IT_CHARPOS (*it
) >= to_charpos
)
6794 skip
= MOVE_POS_MATCH_OR_ZV
;
6796 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6800 case MOVE_POS_MATCH_OR_ZV
:
6804 case MOVE_NEWLINE_OR_CR
:
6805 set_iterator_to_next (it
, 1);
6806 it
->continuation_lines_width
= 0;
6809 case MOVE_LINE_TRUNCATED
:
6810 it
->continuation_lines_width
= 0;
6811 reseat_at_next_visible_line_start (it
, 0);
6812 if ((op
& MOVE_TO_POS
) != 0
6813 && IT_CHARPOS (*it
) > to_charpos
)
6820 case MOVE_LINE_CONTINUED
:
6821 it
->continuation_lines_width
+= it
->current_x
;
6828 /* Reset/increment for the next run. */
6829 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6830 it
->current_x
= it
->hpos
= 0;
6831 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6833 last_height
= it
->max_ascent
+ it
->max_descent
;
6834 last_max_ascent
= it
->max_ascent
;
6835 it
->max_ascent
= it
->max_descent
= 0;
6840 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6844 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6846 If DY > 0, move IT backward at least that many pixels. DY = 0
6847 means move IT backward to the preceding line start or BEGV. This
6848 function may move over more than DY pixels if IT->current_y - DY
6849 ends up in the middle of a line; in this case IT->current_y will be
6850 set to the top of the line moved to. */
6853 move_it_vertically_backward (it
, dy
)
6864 start_pos
= IT_CHARPOS (*it
);
6866 /* Estimate how many newlines we must move back. */
6867 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6869 /* Set the iterator's position that many lines back. */
6870 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6871 back_to_previous_visible_line_start (it
);
6873 /* Reseat the iterator here. When moving backward, we don't want
6874 reseat to skip forward over invisible text, set up the iterator
6875 to deliver from overlay strings at the new position etc. So,
6876 use reseat_1 here. */
6877 reseat_1 (it
, it
->current
.pos
, 1);
6879 /* We are now surely at a line start. */
6880 it
->current_x
= it
->hpos
= 0;
6881 it
->continuation_lines_width
= 0;
6883 /* Move forward and see what y-distance we moved. First move to the
6884 start of the next line so that we get its height. We need this
6885 height to be able to tell whether we reached the specified
6888 it2
.max_ascent
= it2
.max_descent
= 0;
6891 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6892 MOVE_TO_POS
| MOVE_TO_VPOS
);
6894 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6895 xassert (IT_CHARPOS (*it
) >= BEGV
);
6898 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6899 xassert (IT_CHARPOS (*it
) >= BEGV
);
6900 /* H is the actual vertical distance from the position in *IT
6901 and the starting position. */
6902 h
= it2
.current_y
- it
->current_y
;
6903 /* NLINES is the distance in number of lines. */
6904 nlines
= it2
.vpos
- it
->vpos
;
6906 /* Correct IT's y and vpos position
6907 so that they are relative to the starting point. */
6913 /* DY == 0 means move to the start of the screen line. The
6914 value of nlines is > 0 if continuation lines were involved. */
6916 move_it_by_lines (it
, nlines
, 1);
6918 /* I think this assert is bogus if buffer contains
6919 invisible text or images. KFS. */
6920 xassert (IT_CHARPOS (*it
) <= start_pos
);
6925 /* The y-position we try to reach, relative to *IT.
6926 Note that H has been subtracted in front of the if-statement. */
6927 int target_y
= it
->current_y
+ h
- dy
;
6928 int y0
= it3
.current_y
;
6929 int y1
= line_bottom_y (&it3
);
6930 int line_height
= y1
- y0
;
6932 /* If we did not reach target_y, try to move further backward if
6933 we can. If we moved too far backward, try to move forward. */
6934 if (target_y
< it
->current_y
6935 /* This is heuristic. In a window that's 3 lines high, with
6936 a line height of 13 pixels each, recentering with point
6937 on the bottom line will try to move -39/2 = 19 pixels
6938 backward. Try to avoid moving into the first line. */
6939 && (it
->current_y
- target_y
6940 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6941 && IT_CHARPOS (*it
) > BEGV
)
6943 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6944 target_y
- it
->current_y
));
6945 dy
= it
->current_y
- target_y
;
6946 goto move_further_back
;
6948 else if (target_y
>= it
->current_y
+ line_height
6949 && IT_CHARPOS (*it
) < ZV
)
6951 /* Should move forward by at least one line, maybe more.
6953 Note: Calling move_it_by_lines can be expensive on
6954 terminal frames, where compute_motion is used (via
6955 vmotion) to do the job, when there are very long lines
6956 and truncate-lines is nil. That's the reason for
6957 treating terminal frames specially here. */
6959 if (!FRAME_WINDOW_P (it
->f
))
6960 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6965 move_it_by_lines (it
, 1, 1);
6967 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6971 /* I think this assert is bogus if buffer contains
6972 invisible text or images. KFS. */
6973 xassert (IT_CHARPOS (*it
) >= BEGV
);
6980 /* Move IT by a specified amount of pixel lines DY. DY negative means
6981 move backwards. DY = 0 means move to start of screen line. At the
6982 end, IT will be on the start of a screen line. */
6985 move_it_vertically (it
, dy
)
6990 move_it_vertically_backward (it
, -dy
);
6993 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6994 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6995 MOVE_TO_POS
| MOVE_TO_Y
);
6996 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6998 /* If buffer ends in ZV without a newline, move to the start of
6999 the line to satisfy the post-condition. */
7000 if (IT_CHARPOS (*it
) == ZV
7002 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7003 move_it_by_lines (it
, 0, 0);
7008 /* Move iterator IT past the end of the text line it is in. */
7011 move_it_past_eol (it
)
7014 enum move_it_result rc
;
7016 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7017 if (rc
== MOVE_NEWLINE_OR_CR
)
7018 set_iterator_to_next (it
, 0);
7022 #if 0 /* Currently not used. */
7024 /* Return non-zero if some text between buffer positions START_CHARPOS
7025 and END_CHARPOS is invisible. IT->window is the window for text
7029 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7031 int start_charpos
, end_charpos
;
7033 Lisp_Object prop
, limit
;
7034 int invisible_found_p
;
7036 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7038 /* Is text at START invisible? */
7039 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7041 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7042 invisible_found_p
= 1;
7045 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7047 make_number (end_charpos
));
7048 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7051 return invisible_found_p
;
7057 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7058 negative means move up. DVPOS == 0 means move to the start of the
7059 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7060 NEED_Y_P is zero, IT->current_y will be left unchanged.
7062 Further optimization ideas: If we would know that IT->f doesn't use
7063 a face with proportional font, we could be faster for
7064 truncate-lines nil. */
7067 move_it_by_lines (it
, dvpos
, need_y_p
)
7069 int dvpos
, need_y_p
;
7071 struct position pos
;
7073 if (!FRAME_WINDOW_P (it
->f
))
7075 struct text_pos textpos
;
7077 /* We can use vmotion on frames without proportional fonts. */
7078 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
7079 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
7080 reseat (it
, textpos
, 1);
7081 it
->vpos
+= pos
.vpos
;
7082 it
->current_y
+= pos
.vpos
;
7084 else if (dvpos
== 0)
7086 /* DVPOS == 0 means move to the start of the screen line. */
7087 move_it_vertically_backward (it
, 0);
7088 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7089 /* Let next call to line_bottom_y calculate real line height */
7094 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7095 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7096 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7101 int start_charpos
, i
;
7103 /* Start at the beginning of the screen line containing IT's
7104 position. This may actually move vertically backwards,
7105 in case of overlays, so adjust dvpos accordingly. */
7107 move_it_vertically_backward (it
, 0);
7110 /* Go back -DVPOS visible lines and reseat the iterator there. */
7111 start_charpos
= IT_CHARPOS (*it
);
7112 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7113 back_to_previous_visible_line_start (it
);
7114 reseat (it
, it
->current
.pos
, 1);
7116 /* Move further back if we end up in a string or an image. */
7117 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7119 /* First try to move to start of display line. */
7121 move_it_vertically_backward (it
, 0);
7123 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7125 /* If start of line is still in string or image,
7126 move further back. */
7127 back_to_previous_visible_line_start (it
);
7128 reseat (it
, it
->current
.pos
, 1);
7132 it
->current_x
= it
->hpos
= 0;
7134 /* Above call may have moved too far if continuation lines
7135 are involved. Scan forward and see if it did. */
7137 it2
.vpos
= it2
.current_y
= 0;
7138 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7139 it
->vpos
-= it2
.vpos
;
7140 it
->current_y
-= it2
.current_y
;
7141 it
->current_x
= it
->hpos
= 0;
7143 /* If we moved too far back, move IT some lines forward. */
7144 if (it2
.vpos
> -dvpos
)
7146 int delta
= it2
.vpos
+ dvpos
;
7148 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7149 /* Move back again if we got too far ahead. */
7150 if (IT_CHARPOS (*it
) >= start_charpos
)
7156 /* Return 1 if IT points into the middle of a display vector. */
7159 in_display_vector_p (it
)
7162 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7163 && it
->current
.dpvec_index
> 0
7164 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7168 /***********************************************************************
7170 ***********************************************************************/
7173 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7177 add_to_log (format
, arg1
, arg2
)
7179 Lisp_Object arg1
, arg2
;
7181 Lisp_Object args
[3];
7182 Lisp_Object msg
, fmt
;
7185 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7188 /* Do nothing if called asynchronously. Inserting text into
7189 a buffer may call after-change-functions and alike and
7190 that would means running Lisp asynchronously. */
7191 if (handling_signal
)
7195 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7197 args
[0] = fmt
= build_string (format
);
7200 msg
= Fformat (3, args
);
7202 len
= SBYTES (msg
) + 1;
7203 SAFE_ALLOCA (buffer
, char *, len
);
7204 bcopy (SDATA (msg
), buffer
, len
);
7206 message_dolog (buffer
, len
- 1, 1, 0);
7213 /* Output a newline in the *Messages* buffer if "needs" one. */
7216 message_log_maybe_newline ()
7218 if (message_log_need_newline
)
7219 message_dolog ("", 0, 1, 0);
7223 /* Add a string M of length NBYTES to the message log, optionally
7224 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7225 nonzero, means interpret the contents of M as multibyte. This
7226 function calls low-level routines in order to bypass text property
7227 hooks, etc. which might not be safe to run.
7229 This may GC (insert may run before/after change hooks),
7230 so the buffer M must NOT point to a Lisp string. */
7233 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7235 int nbytes
, nlflag
, multibyte
;
7237 if (!NILP (Vmemory_full
))
7240 if (!NILP (Vmessage_log_max
))
7242 struct buffer
*oldbuf
;
7243 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7244 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7245 int point_at_end
= 0;
7247 Lisp_Object old_deactivate_mark
, tem
;
7248 struct gcpro gcpro1
;
7250 old_deactivate_mark
= Vdeactivate_mark
;
7251 oldbuf
= current_buffer
;
7252 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7253 current_buffer
->undo_list
= Qt
;
7255 oldpoint
= message_dolog_marker1
;
7256 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7257 oldbegv
= message_dolog_marker2
;
7258 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7259 oldzv
= message_dolog_marker3
;
7260 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7261 GCPRO1 (old_deactivate_mark
);
7269 BEGV_BYTE
= BEG_BYTE
;
7272 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7274 /* Insert the string--maybe converting multibyte to single byte
7275 or vice versa, so that all the text fits the buffer. */
7277 && NILP (current_buffer
->enable_multibyte_characters
))
7279 int i
, c
, char_bytes
;
7280 unsigned char work
[1];
7282 /* Convert a multibyte string to single-byte
7283 for the *Message* buffer. */
7284 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7286 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7287 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7289 : multibyte_char_to_unibyte (c
, Qnil
));
7290 insert_1_both (work
, 1, 1, 1, 0, 0);
7293 else if (! multibyte
7294 && ! NILP (current_buffer
->enable_multibyte_characters
))
7296 int i
, c
, char_bytes
;
7297 unsigned char *msg
= (unsigned char *) m
;
7298 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7299 /* Convert a single-byte string to multibyte
7300 for the *Message* buffer. */
7301 for (i
= 0; i
< nbytes
; i
++)
7303 c
= unibyte_char_to_multibyte (msg
[i
]);
7304 char_bytes
= CHAR_STRING (c
, str
);
7305 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7309 insert_1 (m
, nbytes
, 1, 0, 0);
7313 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7314 insert_1 ("\n", 1, 1, 0, 0);
7316 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7318 this_bol_byte
= PT_BYTE
;
7320 /* See if this line duplicates the previous one.
7321 If so, combine duplicates. */
7324 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7326 prev_bol_byte
= PT_BYTE
;
7328 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7329 this_bol
, this_bol_byte
);
7332 del_range_both (prev_bol
, prev_bol_byte
,
7333 this_bol
, this_bol_byte
, 0);
7339 /* If you change this format, don't forget to also
7340 change message_log_check_duplicate. */
7341 sprintf (dupstr
, " [%d times]", dup
);
7342 duplen
= strlen (dupstr
);
7343 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7344 insert_1 (dupstr
, duplen
, 1, 0, 1);
7349 /* If we have more than the desired maximum number of lines
7350 in the *Messages* buffer now, delete the oldest ones.
7351 This is safe because we don't have undo in this buffer. */
7353 if (NATNUMP (Vmessage_log_max
))
7355 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7356 -XFASTINT (Vmessage_log_max
) - 1, 0);
7357 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7360 BEGV
= XMARKER (oldbegv
)->charpos
;
7361 BEGV_BYTE
= marker_byte_position (oldbegv
);
7370 ZV
= XMARKER (oldzv
)->charpos
;
7371 ZV_BYTE
= marker_byte_position (oldzv
);
7375 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7377 /* We can't do Fgoto_char (oldpoint) because it will run some
7379 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7380 XMARKER (oldpoint
)->bytepos
);
7383 unchain_marker (XMARKER (oldpoint
));
7384 unchain_marker (XMARKER (oldbegv
));
7385 unchain_marker (XMARKER (oldzv
));
7387 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7388 set_buffer_internal (oldbuf
);
7390 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7391 message_log_need_newline
= !nlflag
;
7392 Vdeactivate_mark
= old_deactivate_mark
;
7397 /* We are at the end of the buffer after just having inserted a newline.
7398 (Note: We depend on the fact we won't be crossing the gap.)
7399 Check to see if the most recent message looks a lot like the previous one.
7400 Return 0 if different, 1 if the new one should just replace it, or a
7401 value N > 1 if we should also append " [N times]". */
7404 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7405 int prev_bol
, this_bol
;
7406 int prev_bol_byte
, this_bol_byte
;
7409 int len
= Z_BYTE
- 1 - this_bol_byte
;
7411 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7412 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7414 for (i
= 0; i
< len
; i
++)
7416 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7424 if (*p1
++ == ' ' && *p1
++ == '[')
7427 while (*p1
>= '0' && *p1
<= '9')
7428 n
= n
* 10 + *p1
++ - '0';
7429 if (strncmp (p1
, " times]\n", 8) == 0)
7436 /* Display an echo area message M with a specified length of NBYTES
7437 bytes. The string may include null characters. If M is 0, clear
7438 out any existing message, and let the mini-buffer text show
7441 This may GC, so the buffer M must NOT point to a Lisp string. */
7444 message2 (m
, nbytes
, multibyte
)
7449 /* First flush out any partial line written with print. */
7450 message_log_maybe_newline ();
7452 message_dolog (m
, nbytes
, 1, multibyte
);
7453 message2_nolog (m
, nbytes
, multibyte
);
7457 /* The non-logging counterpart of message2. */
7460 message2_nolog (m
, nbytes
, multibyte
)
7462 int nbytes
, multibyte
;
7464 struct frame
*sf
= SELECTED_FRAME ();
7465 message_enable_multibyte
= multibyte
;
7469 if (noninteractive_need_newline
)
7470 putc ('\n', stderr
);
7471 noninteractive_need_newline
= 0;
7473 fwrite (m
, nbytes
, 1, stderr
);
7474 if (cursor_in_echo_area
== 0)
7475 fprintf (stderr
, "\n");
7478 /* A null message buffer means that the frame hasn't really been
7479 initialized yet. Error messages get reported properly by
7480 cmd_error, so this must be just an informative message; toss it. */
7481 else if (INTERACTIVE
7482 && sf
->glyphs_initialized_p
7483 && FRAME_MESSAGE_BUF (sf
))
7485 Lisp_Object mini_window
;
7488 /* Get the frame containing the mini-buffer
7489 that the selected frame is using. */
7490 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7491 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7493 FRAME_SAMPLE_VISIBILITY (f
);
7494 if (FRAME_VISIBLE_P (sf
)
7495 && ! FRAME_VISIBLE_P (f
))
7496 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7500 set_message (m
, Qnil
, nbytes
, multibyte
);
7501 if (minibuffer_auto_raise
)
7502 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7505 clear_message (1, 1);
7507 do_pending_window_change (0);
7508 echo_area_display (1);
7509 do_pending_window_change (0);
7510 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7511 (*frame_up_to_date_hook
) (f
);
7516 /* Display an echo area message M with a specified length of NBYTES
7517 bytes. The string may include null characters. If M is not a
7518 string, clear out any existing message, and let the mini-buffer
7521 This function cancels echoing. */
7524 message3 (m
, nbytes
, multibyte
)
7529 struct gcpro gcpro1
;
7532 clear_message (1,1);
7535 /* First flush out any partial line written with print. */
7536 message_log_maybe_newline ();
7542 SAFE_ALLOCA (buffer
, char *, nbytes
);
7543 bcopy (SDATA (m
), buffer
, nbytes
);
7544 message_dolog (buffer
, nbytes
, 1, multibyte
);
7547 message3_nolog (m
, nbytes
, multibyte
);
7553 /* The non-logging version of message3.
7554 This does not cancel echoing, because it is used for echoing.
7555 Perhaps we need to make a separate function for echoing
7556 and make this cancel echoing. */
7559 message3_nolog (m
, nbytes
, multibyte
)
7561 int nbytes
, multibyte
;
7563 struct frame
*sf
= SELECTED_FRAME ();
7564 message_enable_multibyte
= multibyte
;
7568 if (noninteractive_need_newline
)
7569 putc ('\n', stderr
);
7570 noninteractive_need_newline
= 0;
7572 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7573 if (cursor_in_echo_area
== 0)
7574 fprintf (stderr
, "\n");
7577 /* A null message buffer means that the frame hasn't really been
7578 initialized yet. Error messages get reported properly by
7579 cmd_error, so this must be just an informative message; toss it. */
7580 else if (INTERACTIVE
7581 && sf
->glyphs_initialized_p
7582 && FRAME_MESSAGE_BUF (sf
))
7584 Lisp_Object mini_window
;
7588 /* Get the frame containing the mini-buffer
7589 that the selected frame is using. */
7590 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7591 frame
= XWINDOW (mini_window
)->frame
;
7594 FRAME_SAMPLE_VISIBILITY (f
);
7595 if (FRAME_VISIBLE_P (sf
)
7596 && !FRAME_VISIBLE_P (f
))
7597 Fmake_frame_visible (frame
);
7599 if (STRINGP (m
) && SCHARS (m
) > 0)
7601 set_message (NULL
, m
, nbytes
, multibyte
);
7602 if (minibuffer_auto_raise
)
7603 Fraise_frame (frame
);
7604 /* Assume we are not echoing.
7605 (If we are, echo_now will override this.) */
7606 echo_message_buffer
= Qnil
;
7609 clear_message (1, 1);
7611 do_pending_window_change (0);
7612 echo_area_display (1);
7613 do_pending_window_change (0);
7614 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7615 (*frame_up_to_date_hook
) (f
);
7620 /* Display a null-terminated echo area message M. If M is 0, clear
7621 out any existing message, and let the mini-buffer text show through.
7623 The buffer M must continue to exist until after the echo area gets
7624 cleared or some other message gets displayed there. Do not pass
7625 text that is stored in a Lisp string. Do not pass text in a buffer
7626 that was alloca'd. */
7632 message2 (m
, (m
? strlen (m
) : 0), 0);
7636 /* The non-logging counterpart of message1. */
7642 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7645 /* Display a message M which contains a single %s
7646 which gets replaced with STRING. */
7649 message_with_string (m
, string
, log
)
7654 CHECK_STRING (string
);
7660 if (noninteractive_need_newline
)
7661 putc ('\n', stderr
);
7662 noninteractive_need_newline
= 0;
7663 fprintf (stderr
, m
, SDATA (string
));
7664 if (cursor_in_echo_area
== 0)
7665 fprintf (stderr
, "\n");
7669 else if (INTERACTIVE
)
7671 /* The frame whose minibuffer we're going to display the message on.
7672 It may be larger than the selected frame, so we need
7673 to use its buffer, not the selected frame's buffer. */
7674 Lisp_Object mini_window
;
7675 struct frame
*f
, *sf
= SELECTED_FRAME ();
7677 /* Get the frame containing the minibuffer
7678 that the selected frame is using. */
7679 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7680 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7682 /* A null message buffer means that the frame hasn't really been
7683 initialized yet. Error messages get reported properly by
7684 cmd_error, so this must be just an informative message; toss it. */
7685 if (FRAME_MESSAGE_BUF (f
))
7687 Lisp_Object args
[2], message
;
7688 struct gcpro gcpro1
, gcpro2
;
7690 args
[0] = build_string (m
);
7691 args
[1] = message
= string
;
7692 GCPRO2 (args
[0], message
);
7695 message
= Fformat (2, args
);
7698 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7700 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7704 /* Print should start at the beginning of the message
7705 buffer next time. */
7706 message_buf_print
= 0;
7712 /* Dump an informative message to the minibuf. If M is 0, clear out
7713 any existing message, and let the mini-buffer text show through. */
7717 message (m
, a1
, a2
, a3
)
7719 EMACS_INT a1
, a2
, a3
;
7725 if (noninteractive_need_newline
)
7726 putc ('\n', stderr
);
7727 noninteractive_need_newline
= 0;
7728 fprintf (stderr
, m
, a1
, a2
, a3
);
7729 if (cursor_in_echo_area
== 0)
7730 fprintf (stderr
, "\n");
7734 else if (INTERACTIVE
)
7736 /* The frame whose mini-buffer we're going to display the message
7737 on. It may be larger than the selected frame, so we need to
7738 use its buffer, not the selected frame's buffer. */
7739 Lisp_Object mini_window
;
7740 struct frame
*f
, *sf
= SELECTED_FRAME ();
7742 /* Get the frame containing the mini-buffer
7743 that the selected frame is using. */
7744 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7745 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7747 /* A null message buffer means that the frame hasn't really been
7748 initialized yet. Error messages get reported properly by
7749 cmd_error, so this must be just an informative message; toss
7751 if (FRAME_MESSAGE_BUF (f
))
7762 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7763 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7765 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7766 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7768 #endif /* NO_ARG_ARRAY */
7770 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7775 /* Print should start at the beginning of the message
7776 buffer next time. */
7777 message_buf_print
= 0;
7783 /* The non-logging version of message. */
7786 message_nolog (m
, a1
, a2
, a3
)
7788 EMACS_INT a1
, a2
, a3
;
7790 Lisp_Object old_log_max
;
7791 old_log_max
= Vmessage_log_max
;
7792 Vmessage_log_max
= Qnil
;
7793 message (m
, a1
, a2
, a3
);
7794 Vmessage_log_max
= old_log_max
;
7798 /* Display the current message in the current mini-buffer. This is
7799 only called from error handlers in process.c, and is not time
7805 if (!NILP (echo_area_buffer
[0]))
7808 string
= Fcurrent_message ();
7809 message3 (string
, SBYTES (string
),
7810 !NILP (current_buffer
->enable_multibyte_characters
));
7815 /* Make sure echo area buffers in `echo_buffers' are live.
7816 If they aren't, make new ones. */
7819 ensure_echo_area_buffers ()
7823 for (i
= 0; i
< 2; ++i
)
7824 if (!BUFFERP (echo_buffer
[i
])
7825 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7828 Lisp_Object old_buffer
;
7831 old_buffer
= echo_buffer
[i
];
7832 sprintf (name
, " *Echo Area %d*", i
);
7833 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7834 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7836 for (j
= 0; j
< 2; ++j
)
7837 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7838 echo_area_buffer
[j
] = echo_buffer
[i
];
7843 /* Call FN with args A1..A4 with either the current or last displayed
7844 echo_area_buffer as current buffer.
7846 WHICH zero means use the current message buffer
7847 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7848 from echo_buffer[] and clear it.
7850 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7851 suitable buffer from echo_buffer[] and clear it.
7853 Value is what FN returns. */
7856 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7859 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7865 int this_one
, the_other
, clear_buffer_p
, rc
;
7866 int count
= SPECPDL_INDEX ();
7868 /* If buffers aren't live, make new ones. */
7869 ensure_echo_area_buffers ();
7874 this_one
= 0, the_other
= 1;
7876 this_one
= 1, the_other
= 0;
7878 /* Choose a suitable buffer from echo_buffer[] is we don't
7880 if (NILP (echo_area_buffer
[this_one
]))
7882 echo_area_buffer
[this_one
]
7883 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7884 ? echo_buffer
[the_other
]
7885 : echo_buffer
[this_one
]);
7889 buffer
= echo_area_buffer
[this_one
];
7891 /* Don't get confused by reusing the buffer used for echoing
7892 for a different purpose. */
7893 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7896 record_unwind_protect (unwind_with_echo_area_buffer
,
7897 with_echo_area_buffer_unwind_data (w
));
7899 /* Make the echo area buffer current. Note that for display
7900 purposes, it is not necessary that the displayed window's buffer
7901 == current_buffer, except for text property lookup. So, let's
7902 only set that buffer temporarily here without doing a full
7903 Fset_window_buffer. We must also change w->pointm, though,
7904 because otherwise an assertions in unshow_buffer fails, and Emacs
7906 set_buffer_internal_1 (XBUFFER (buffer
));
7910 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7913 current_buffer
->undo_list
= Qt
;
7914 current_buffer
->read_only
= Qnil
;
7915 specbind (Qinhibit_read_only
, Qt
);
7916 specbind (Qinhibit_modification_hooks
, Qt
);
7918 if (clear_buffer_p
&& Z
> BEG
)
7921 xassert (BEGV
>= BEG
);
7922 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7924 rc
= fn (a1
, a2
, a3
, a4
);
7926 xassert (BEGV
>= BEG
);
7927 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7929 unbind_to (count
, Qnil
);
7934 /* Save state that should be preserved around the call to the function
7935 FN called in with_echo_area_buffer. */
7938 with_echo_area_buffer_unwind_data (w
)
7944 /* Reduce consing by keeping one vector in
7945 Vwith_echo_area_save_vector. */
7946 vector
= Vwith_echo_area_save_vector
;
7947 Vwith_echo_area_save_vector
= Qnil
;
7950 vector
= Fmake_vector (make_number (7), Qnil
);
7952 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7953 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7954 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7958 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7959 AREF (vector
, i
) = w
->buffer
; ++i
;
7960 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7961 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7966 for (; i
< end
; ++i
)
7967 AREF (vector
, i
) = Qnil
;
7970 xassert (i
== ASIZE (vector
));
7975 /* Restore global state from VECTOR which was created by
7976 with_echo_area_buffer_unwind_data. */
7979 unwind_with_echo_area_buffer (vector
)
7982 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7983 Vdeactivate_mark
= AREF (vector
, 1);
7984 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7986 if (WINDOWP (AREF (vector
, 3)))
7989 Lisp_Object buffer
, charpos
, bytepos
;
7991 w
= XWINDOW (AREF (vector
, 3));
7992 buffer
= AREF (vector
, 4);
7993 charpos
= AREF (vector
, 5);
7994 bytepos
= AREF (vector
, 6);
7997 set_marker_both (w
->pointm
, buffer
,
7998 XFASTINT (charpos
), XFASTINT (bytepos
));
8001 Vwith_echo_area_save_vector
= vector
;
8006 /* Set up the echo area for use by print functions. MULTIBYTE_P
8007 non-zero means we will print multibyte. */
8010 setup_echo_area_for_printing (multibyte_p
)
8013 /* If we can't find an echo area any more, exit. */
8014 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8017 ensure_echo_area_buffers ();
8019 if (!message_buf_print
)
8021 /* A message has been output since the last time we printed.
8022 Choose a fresh echo area buffer. */
8023 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8024 echo_area_buffer
[0] = echo_buffer
[1];
8026 echo_area_buffer
[0] = echo_buffer
[0];
8028 /* Switch to that buffer and clear it. */
8029 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8030 current_buffer
->truncate_lines
= Qnil
;
8034 int count
= SPECPDL_INDEX ();
8035 specbind (Qinhibit_read_only
, Qt
);
8036 /* Note that undo recording is always disabled. */
8038 unbind_to (count
, Qnil
);
8040 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8042 /* Set up the buffer for the multibyteness we need. */
8044 != !NILP (current_buffer
->enable_multibyte_characters
))
8045 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8047 /* Raise the frame containing the echo area. */
8048 if (minibuffer_auto_raise
)
8050 struct frame
*sf
= SELECTED_FRAME ();
8051 Lisp_Object mini_window
;
8052 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8053 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8056 message_log_maybe_newline ();
8057 message_buf_print
= 1;
8061 if (NILP (echo_area_buffer
[0]))
8063 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8064 echo_area_buffer
[0] = echo_buffer
[1];
8066 echo_area_buffer
[0] = echo_buffer
[0];
8069 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8071 /* Someone switched buffers between print requests. */
8072 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8073 current_buffer
->truncate_lines
= Qnil
;
8079 /* Display an echo area message in window W. Value is non-zero if W's
8080 height is changed. If display_last_displayed_message_p is
8081 non-zero, display the message that was last displayed, otherwise
8082 display the current message. */
8085 display_echo_area (w
)
8088 int i
, no_message_p
, window_height_changed_p
, count
;
8090 /* Temporarily disable garbage collections while displaying the echo
8091 area. This is done because a GC can print a message itself.
8092 That message would modify the echo area buffer's contents while a
8093 redisplay of the buffer is going on, and seriously confuse
8095 count
= inhibit_garbage_collection ();
8097 /* If there is no message, we must call display_echo_area_1
8098 nevertheless because it resizes the window. But we will have to
8099 reset the echo_area_buffer in question to nil at the end because
8100 with_echo_area_buffer will sets it to an empty buffer. */
8101 i
= display_last_displayed_message_p
? 1 : 0;
8102 no_message_p
= NILP (echo_area_buffer
[i
]);
8104 window_height_changed_p
8105 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8106 display_echo_area_1
,
8107 (EMACS_INT
) w
, Qnil
, 0, 0);
8110 echo_area_buffer
[i
] = Qnil
;
8112 unbind_to (count
, Qnil
);
8113 return window_height_changed_p
;
8117 /* Helper for display_echo_area. Display the current buffer which
8118 contains the current echo area message in window W, a mini-window,
8119 a pointer to which is passed in A1. A2..A4 are currently not used.
8120 Change the height of W so that all of the message is displayed.
8121 Value is non-zero if height of W was changed. */
8124 display_echo_area_1 (a1
, a2
, a3
, a4
)
8129 struct window
*w
= (struct window
*) a1
;
8131 struct text_pos start
;
8132 int window_height_changed_p
= 0;
8134 /* Do this before displaying, so that we have a large enough glyph
8135 matrix for the display. If we can't get enough space for the
8136 whole text, display the last N lines. That works by setting w->start. */
8137 window_height_changed_p
= resize_mini_window (w
, 0);
8139 /* Use the starting position chosen by resize_mini_window. */
8140 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8143 clear_glyph_matrix (w
->desired_matrix
);
8144 XSETWINDOW (window
, w
);
8145 try_window (window
, start
, 0);
8147 return window_height_changed_p
;
8151 /* Resize the echo area window to exactly the size needed for the
8152 currently displayed message, if there is one. If a mini-buffer
8153 is active, don't shrink it. */
8156 resize_echo_area_exactly ()
8158 if (BUFFERP (echo_area_buffer
[0])
8159 && WINDOWP (echo_area_window
))
8161 struct window
*w
= XWINDOW (echo_area_window
);
8163 Lisp_Object resize_exactly
;
8165 if (minibuf_level
== 0)
8166 resize_exactly
= Qt
;
8168 resize_exactly
= Qnil
;
8170 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8171 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8174 ++windows_or_buffers_changed
;
8175 ++update_mode_lines
;
8176 redisplay_internal (0);
8182 /* Callback function for with_echo_area_buffer, when used from
8183 resize_echo_area_exactly. A1 contains a pointer to the window to
8184 resize, EXACTLY non-nil means resize the mini-window exactly to the
8185 size of the text displayed. A3 and A4 are not used. Value is what
8186 resize_mini_window returns. */
8189 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8191 Lisp_Object exactly
;
8194 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8198 /* Resize mini-window W to fit the size of its contents. EXACT:P
8199 means size the window exactly to the size needed. Otherwise, it's
8200 only enlarged until W's buffer is empty.
8202 Set W->start to the right place to begin display. If the whole
8203 contents fit, start at the beginning. Otherwise, start so as
8204 to make the end of the contents appear. This is particularly
8205 important for y-or-n-p, but seems desirable generally.
8207 Value is non-zero if the window height has been changed. */
8210 resize_mini_window (w
, exact_p
)
8214 struct frame
*f
= XFRAME (w
->frame
);
8215 int window_height_changed_p
= 0;
8217 xassert (MINI_WINDOW_P (w
));
8219 /* By default, start display at the beginning. */
8220 set_marker_both (w
->start
, w
->buffer
,
8221 BUF_BEGV (XBUFFER (w
->buffer
)),
8222 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8224 /* Don't resize windows while redisplaying a window; it would
8225 confuse redisplay functions when the size of the window they are
8226 displaying changes from under them. Such a resizing can happen,
8227 for instance, when which-func prints a long message while
8228 we are running fontification-functions. We're running these
8229 functions with safe_call which binds inhibit-redisplay to t. */
8230 if (!NILP (Vinhibit_redisplay
))
8233 /* Nil means don't try to resize. */
8234 if (NILP (Vresize_mini_windows
)
8235 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8238 if (!FRAME_MINIBUF_ONLY_P (f
))
8241 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8242 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8243 int height
, max_height
;
8244 int unit
= FRAME_LINE_HEIGHT (f
);
8245 struct text_pos start
;
8246 struct buffer
*old_current_buffer
= NULL
;
8248 if (current_buffer
!= XBUFFER (w
->buffer
))
8250 old_current_buffer
= current_buffer
;
8251 set_buffer_internal (XBUFFER (w
->buffer
));
8254 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8256 /* Compute the max. number of lines specified by the user. */
8257 if (FLOATP (Vmax_mini_window_height
))
8258 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8259 else if (INTEGERP (Vmax_mini_window_height
))
8260 max_height
= XINT (Vmax_mini_window_height
);
8262 max_height
= total_height
/ 4;
8264 /* Correct that max. height if it's bogus. */
8265 max_height
= max (1, max_height
);
8266 max_height
= min (total_height
, max_height
);
8268 /* Find out the height of the text in the window. */
8269 if (it
.truncate_lines_p
)
8274 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8275 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8276 height
= it
.current_y
+ last_height
;
8278 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8279 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8280 height
= (height
+ unit
- 1) / unit
;
8283 /* Compute a suitable window start. */
8284 if (height
> max_height
)
8286 height
= max_height
;
8287 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8288 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8289 start
= it
.current
.pos
;
8292 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8293 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8295 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8297 /* Let it grow only, until we display an empty message, in which
8298 case the window shrinks again. */
8299 if (height
> WINDOW_TOTAL_LINES (w
))
8301 int old_height
= WINDOW_TOTAL_LINES (w
);
8302 freeze_window_starts (f
, 1);
8303 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8304 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8306 else if (height
< WINDOW_TOTAL_LINES (w
)
8307 && (exact_p
|| BEGV
== ZV
))
8309 int old_height
= WINDOW_TOTAL_LINES (w
);
8310 freeze_window_starts (f
, 0);
8311 shrink_mini_window (w
);
8312 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8317 /* Always resize to exact size needed. */
8318 if (height
> WINDOW_TOTAL_LINES (w
))
8320 int old_height
= WINDOW_TOTAL_LINES (w
);
8321 freeze_window_starts (f
, 1);
8322 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8323 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8325 else if (height
< WINDOW_TOTAL_LINES (w
))
8327 int old_height
= WINDOW_TOTAL_LINES (w
);
8328 freeze_window_starts (f
, 0);
8329 shrink_mini_window (w
);
8333 freeze_window_starts (f
, 1);
8334 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8337 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8341 if (old_current_buffer
)
8342 set_buffer_internal (old_current_buffer
);
8345 return window_height_changed_p
;
8349 /* Value is the current message, a string, or nil if there is no
8357 if (NILP (echo_area_buffer
[0]))
8361 with_echo_area_buffer (0, 0, current_message_1
,
8362 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8364 echo_area_buffer
[0] = Qnil
;
8372 current_message_1 (a1
, a2
, a3
, a4
)
8377 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8380 *msg
= make_buffer_string (BEG
, Z
, 1);
8387 /* Push the current message on Vmessage_stack for later restauration
8388 by restore_message. Value is non-zero if the current message isn't
8389 empty. This is a relatively infrequent operation, so it's not
8390 worth optimizing. */
8396 msg
= current_message ();
8397 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8398 return STRINGP (msg
);
8402 /* Restore message display from the top of Vmessage_stack. */
8409 xassert (CONSP (Vmessage_stack
));
8410 msg
= XCAR (Vmessage_stack
);
8412 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8414 message3_nolog (msg
, 0, 0);
8418 /* Handler for record_unwind_protect calling pop_message. */
8421 pop_message_unwind (dummy
)
8428 /* Pop the top-most entry off Vmessage_stack. */
8433 xassert (CONSP (Vmessage_stack
));
8434 Vmessage_stack
= XCDR (Vmessage_stack
);
8438 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8439 exits. If the stack is not empty, we have a missing pop_message
8443 check_message_stack ()
8445 if (!NILP (Vmessage_stack
))
8450 /* Truncate to NCHARS what will be displayed in the echo area the next
8451 time we display it---but don't redisplay it now. */
8454 truncate_echo_area (nchars
)
8458 echo_area_buffer
[0] = Qnil
;
8459 /* A null message buffer means that the frame hasn't really been
8460 initialized yet. Error messages get reported properly by
8461 cmd_error, so this must be just an informative message; toss it. */
8462 else if (!noninteractive
8464 && !NILP (echo_area_buffer
[0]))
8466 struct frame
*sf
= SELECTED_FRAME ();
8467 if (FRAME_MESSAGE_BUF (sf
))
8468 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8473 /* Helper function for truncate_echo_area. Truncate the current
8474 message to at most NCHARS characters. */
8477 truncate_message_1 (nchars
, a2
, a3
, a4
)
8482 if (BEG
+ nchars
< Z
)
8483 del_range (BEG
+ nchars
, Z
);
8485 echo_area_buffer
[0] = Qnil
;
8490 /* Set the current message to a substring of S or STRING.
8492 If STRING is a Lisp string, set the message to the first NBYTES
8493 bytes from STRING. NBYTES zero means use the whole string. If
8494 STRING is multibyte, the message will be displayed multibyte.
8496 If S is not null, set the message to the first LEN bytes of S. LEN
8497 zero means use the whole string. MULTIBYTE_P non-zero means S is
8498 multibyte. Display the message multibyte in that case.
8500 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8501 to t before calling set_message_1 (which calls insert).
8505 set_message (s
, string
, nbytes
, multibyte_p
)
8508 int nbytes
, multibyte_p
;
8510 message_enable_multibyte
8511 = ((s
&& multibyte_p
)
8512 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8514 with_echo_area_buffer (0, 0, set_message_1
,
8515 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8516 message_buf_print
= 0;
8517 help_echo_showing_p
= 0;
8521 /* Helper function for set_message. Arguments have the same meaning
8522 as there, with A1 corresponding to S and A2 corresponding to STRING
8523 This function is called with the echo area buffer being
8527 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8530 EMACS_INT nbytes
, multibyte_p
;
8532 const char *s
= (const char *) a1
;
8533 Lisp_Object string
= a2
;
8535 /* Change multibyteness of the echo buffer appropriately. */
8536 if (message_enable_multibyte
8537 != !NILP (current_buffer
->enable_multibyte_characters
))
8538 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8540 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8542 /* Insert new message at BEG. */
8543 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8546 if (STRINGP (string
))
8551 nbytes
= SBYTES (string
);
8552 nchars
= string_byte_to_char (string
, nbytes
);
8554 /* This function takes care of single/multibyte conversion. We
8555 just have to ensure that the echo area buffer has the right
8556 setting of enable_multibyte_characters. */
8557 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8562 nbytes
= strlen (s
);
8564 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8566 /* Convert from multi-byte to single-byte. */
8568 unsigned char work
[1];
8570 /* Convert a multibyte string to single-byte. */
8571 for (i
= 0; i
< nbytes
; i
+= n
)
8573 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8574 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8576 : multibyte_char_to_unibyte (c
, Qnil
));
8577 insert_1_both (work
, 1, 1, 1, 0, 0);
8580 else if (!multibyte_p
8581 && !NILP (current_buffer
->enable_multibyte_characters
))
8583 /* Convert from single-byte to multi-byte. */
8585 const unsigned char *msg
= (const unsigned char *) s
;
8586 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8588 /* Convert a single-byte string to multibyte. */
8589 for (i
= 0; i
< nbytes
; i
++)
8591 c
= unibyte_char_to_multibyte (msg
[i
]);
8592 n
= CHAR_STRING (c
, str
);
8593 insert_1_both (str
, 1, n
, 1, 0, 0);
8597 insert_1 (s
, nbytes
, 1, 0, 0);
8604 /* Clear messages. CURRENT_P non-zero means clear the current
8605 message. LAST_DISPLAYED_P non-zero means clear the message
8609 clear_message (current_p
, last_displayed_p
)
8610 int current_p
, last_displayed_p
;
8614 echo_area_buffer
[0] = Qnil
;
8615 message_cleared_p
= 1;
8618 if (last_displayed_p
)
8619 echo_area_buffer
[1] = Qnil
;
8621 message_buf_print
= 0;
8624 /* Clear garbaged frames.
8626 This function is used where the old redisplay called
8627 redraw_garbaged_frames which in turn called redraw_frame which in
8628 turn called clear_frame. The call to clear_frame was a source of
8629 flickering. I believe a clear_frame is not necessary. It should
8630 suffice in the new redisplay to invalidate all current matrices,
8631 and ensure a complete redisplay of all windows. */
8634 clear_garbaged_frames ()
8638 Lisp_Object tail
, frame
;
8639 int changed_count
= 0;
8641 FOR_EACH_FRAME (tail
, frame
)
8643 struct frame
*f
= XFRAME (frame
);
8645 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8649 Fredraw_frame (frame
);
8650 f
->force_flush_display_p
= 1;
8652 clear_current_matrices (f
);
8661 ++windows_or_buffers_changed
;
8666 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8667 is non-zero update selected_frame. Value is non-zero if the
8668 mini-windows height has been changed. */
8671 echo_area_display (update_frame_p
)
8674 Lisp_Object mini_window
;
8677 int window_height_changed_p
= 0;
8678 struct frame
*sf
= SELECTED_FRAME ();
8680 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8681 w
= XWINDOW (mini_window
);
8682 f
= XFRAME (WINDOW_FRAME (w
));
8684 /* Don't display if frame is invisible or not yet initialized. */
8685 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8688 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8690 #ifdef HAVE_WINDOW_SYSTEM
8691 /* When Emacs starts, selected_frame may be a visible terminal
8692 frame, even if we run under a window system. If we let this
8693 through, a message would be displayed on the terminal. */
8694 if (EQ (selected_frame
, Vterminal_frame
)
8695 && !NILP (Vwindow_system
))
8697 #endif /* HAVE_WINDOW_SYSTEM */
8700 /* Redraw garbaged frames. */
8702 clear_garbaged_frames ();
8704 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8706 echo_area_window
= mini_window
;
8707 window_height_changed_p
= display_echo_area (w
);
8708 w
->must_be_updated_p
= 1;
8710 /* Update the display, unless called from redisplay_internal.
8711 Also don't update the screen during redisplay itself. The
8712 update will happen at the end of redisplay, and an update
8713 here could cause confusion. */
8714 if (update_frame_p
&& !redisplaying_p
)
8718 /* If the display update has been interrupted by pending
8719 input, update mode lines in the frame. Due to the
8720 pending input, it might have been that redisplay hasn't
8721 been called, so that mode lines above the echo area are
8722 garbaged. This looks odd, so we prevent it here. */
8723 if (!display_completed
)
8724 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8726 if (window_height_changed_p
8727 /* Don't do this if Emacs is shutting down. Redisplay
8728 needs to run hooks. */
8729 && !NILP (Vrun_hooks
))
8731 /* Must update other windows. Likewise as in other
8732 cases, don't let this update be interrupted by
8734 int count
= SPECPDL_INDEX ();
8735 specbind (Qredisplay_dont_pause
, Qt
);
8736 windows_or_buffers_changed
= 1;
8737 redisplay_internal (0);
8738 unbind_to (count
, Qnil
);
8740 else if (FRAME_WINDOW_P (f
) && n
== 0)
8742 /* Window configuration is the same as before.
8743 Can do with a display update of the echo area,
8744 unless we displayed some mode lines. */
8745 update_single_window (w
, 1);
8746 rif
->flush_display (f
);
8749 update_frame (f
, 1, 1);
8751 /* If cursor is in the echo area, make sure that the next
8752 redisplay displays the minibuffer, so that the cursor will
8753 be replaced with what the minibuffer wants. */
8754 if (cursor_in_echo_area
)
8755 ++windows_or_buffers_changed
;
8758 else if (!EQ (mini_window
, selected_window
))
8759 windows_or_buffers_changed
++;
8761 /* The current message is now also the last one displayed. */
8762 echo_area_buffer
[1] = echo_area_buffer
[0];
8764 /* Prevent redisplay optimization in redisplay_internal by resetting
8765 this_line_start_pos. This is done because the mini-buffer now
8766 displays the message instead of its buffer text. */
8767 if (EQ (mini_window
, selected_window
))
8768 CHARPOS (this_line_start_pos
) = 0;
8770 return window_height_changed_p
;
8775 /***********************************************************************
8776 Mode Lines and Frame Titles
8777 ***********************************************************************/
8779 /* A buffer for constructing non-propertized mode-line strings and
8780 frame titles in it; allocated from the heap in init_xdisp and
8781 resized as needed in store_mode_line_noprop_char. */
8783 static char *mode_line_noprop_buf
;
8785 /* The buffer's end, and a current output position in it. */
8787 static char *mode_line_noprop_buf_end
;
8788 static char *mode_line_noprop_ptr
;
8790 #define MODE_LINE_NOPROP_LEN(start) \
8791 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8794 MODE_LINE_DISPLAY
= 0,
8800 /* Alist that caches the results of :propertize.
8801 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8802 static Lisp_Object mode_line_proptrans_alist
;
8804 /* List of strings making up the mode-line. */
8805 static Lisp_Object mode_line_string_list
;
8807 /* Base face property when building propertized mode line string. */
8808 static Lisp_Object mode_line_string_face
;
8809 static Lisp_Object mode_line_string_face_prop
;
8812 /* Unwind data for mode line strings */
8814 static Lisp_Object Vmode_line_unwind_vector
;
8817 format_mode_line_unwind_data (obuf
, save_proptrans
)
8818 struct buffer
*obuf
;
8822 /* Reduce consing by keeping one vector in
8823 Vwith_echo_area_save_vector. */
8824 vector
= Vmode_line_unwind_vector
;
8825 Vmode_line_unwind_vector
= Qnil
;
8828 vector
= Fmake_vector (make_number (7), Qnil
);
8830 AREF (vector
, 0) = make_number (mode_line_target
);
8831 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8832 AREF (vector
, 2) = mode_line_string_list
;
8833 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8834 AREF (vector
, 4) = mode_line_string_face
;
8835 AREF (vector
, 5) = mode_line_string_face_prop
;
8838 XSETBUFFER (AREF (vector
, 6), obuf
);
8840 AREF (vector
, 6) = Qnil
;
8846 unwind_format_mode_line (vector
)
8849 mode_line_target
= XINT (AREF (vector
, 0));
8850 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8851 mode_line_string_list
= AREF (vector
, 2);
8852 if (! EQ (AREF (vector
, 3), Qt
))
8853 mode_line_proptrans_alist
= AREF (vector
, 3);
8854 mode_line_string_face
= AREF (vector
, 4);
8855 mode_line_string_face_prop
= AREF (vector
, 5);
8857 if (!NILP (AREF (vector
, 6)))
8859 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8860 AREF (vector
, 6) = Qnil
;
8863 Vmode_line_unwind_vector
= vector
;
8868 /* Store a single character C for the frame title in mode_line_noprop_buf.
8869 Re-allocate mode_line_noprop_buf if necessary. */
8873 store_mode_line_noprop_char (char c
)
8875 store_mode_line_noprop_char (c
)
8879 /* If output position has reached the end of the allocated buffer,
8880 double the buffer's size. */
8881 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8883 int len
= MODE_LINE_NOPROP_LEN (0);
8884 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8885 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8886 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8887 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8890 *mode_line_noprop_ptr
++ = c
;
8894 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8895 mode_line_noprop_ptr. STR is the string to store. Do not copy
8896 characters that yield more columns than PRECISION; PRECISION <= 0
8897 means copy the whole string. Pad with spaces until FIELD_WIDTH
8898 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8899 pad. Called from display_mode_element when it is used to build a
8903 store_mode_line_noprop (str
, field_width
, precision
)
8904 const unsigned char *str
;
8905 int field_width
, precision
;
8910 /* Copy at most PRECISION chars from STR. */
8911 nbytes
= strlen (str
);
8912 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8914 store_mode_line_noprop_char (*str
++);
8916 /* Fill up with spaces until FIELD_WIDTH reached. */
8917 while (field_width
> 0
8920 store_mode_line_noprop_char (' ');
8927 /***********************************************************************
8929 ***********************************************************************/
8931 #ifdef HAVE_WINDOW_SYSTEM
8933 /* Set the title of FRAME, if it has changed. The title format is
8934 Vicon_title_format if FRAME is iconified, otherwise it is
8935 frame_title_format. */
8938 x_consider_frame_title (frame
)
8941 struct frame
*f
= XFRAME (frame
);
8943 if (FRAME_WINDOW_P (f
)
8944 || FRAME_MINIBUF_ONLY_P (f
)
8945 || f
->explicit_name
)
8947 /* Do we have more than one visible frame on this X display? */
8954 int count
= SPECPDL_INDEX ();
8956 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8958 Lisp_Object other_frame
= XCAR (tail
);
8959 struct frame
*tf
= XFRAME (other_frame
);
8962 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8963 && !FRAME_MINIBUF_ONLY_P (tf
)
8964 && !EQ (other_frame
, tip_frame
)
8965 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8969 /* Set global variable indicating that multiple frames exist. */
8970 multiple_frames
= CONSP (tail
);
8972 /* Switch to the buffer of selected window of the frame. Set up
8973 mode_line_target so that display_mode_element will output into
8974 mode_line_noprop_buf; then display the title. */
8975 record_unwind_protect (unwind_format_mode_line
,
8976 format_mode_line_unwind_data (current_buffer
, 0));
8978 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8979 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8981 mode_line_target
= MODE_LINE_TITLE
;
8982 title_start
= MODE_LINE_NOPROP_LEN (0);
8983 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8984 NULL
, DEFAULT_FACE_ID
);
8985 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8986 len
= MODE_LINE_NOPROP_LEN (title_start
);
8987 title
= mode_line_noprop_buf
+ title_start
;
8988 unbind_to (count
, Qnil
);
8990 /* Set the title only if it's changed. This avoids consing in
8991 the common case where it hasn't. (If it turns out that we've
8992 already wasted too much time by walking through the list with
8993 display_mode_element, then we might need to optimize at a
8994 higher level than this.) */
8995 if (! STRINGP (f
->name
)
8996 || SBYTES (f
->name
) != len
8997 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8998 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9002 #endif /* not HAVE_WINDOW_SYSTEM */
9007 /***********************************************************************
9009 ***********************************************************************/
9012 /* Prepare for redisplay by updating menu-bar item lists when
9013 appropriate. This can call eval. */
9016 prepare_menu_bars ()
9019 struct gcpro gcpro1
, gcpro2
;
9021 Lisp_Object tooltip_frame
;
9023 #ifdef HAVE_WINDOW_SYSTEM
9024 tooltip_frame
= tip_frame
;
9026 tooltip_frame
= Qnil
;
9029 /* Update all frame titles based on their buffer names, etc. We do
9030 this before the menu bars so that the buffer-menu will show the
9031 up-to-date frame titles. */
9032 #ifdef HAVE_WINDOW_SYSTEM
9033 if (windows_or_buffers_changed
|| update_mode_lines
)
9035 Lisp_Object tail
, frame
;
9037 FOR_EACH_FRAME (tail
, frame
)
9040 if (!EQ (frame
, tooltip_frame
)
9041 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9042 x_consider_frame_title (frame
);
9045 #endif /* HAVE_WINDOW_SYSTEM */
9047 /* Update the menu bar item lists, if appropriate. This has to be
9048 done before any actual redisplay or generation of display lines. */
9049 all_windows
= (update_mode_lines
9050 || buffer_shared
> 1
9051 || windows_or_buffers_changed
);
9054 Lisp_Object tail
, frame
;
9055 int count
= SPECPDL_INDEX ();
9056 /* 1 means that update_menu_bar has run its hooks
9057 so any further calls to update_menu_bar shouldn't do so again. */
9058 int menu_bar_hooks_run
= 0;
9060 record_unwind_save_match_data ();
9062 FOR_EACH_FRAME (tail
, frame
)
9066 /* Ignore tooltip frame. */
9067 if (EQ (frame
, tooltip_frame
))
9070 /* If a window on this frame changed size, report that to
9071 the user and clear the size-change flag. */
9072 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9074 Lisp_Object functions
;
9076 /* Clear flag first in case we get an error below. */
9077 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9078 functions
= Vwindow_size_change_functions
;
9079 GCPRO2 (tail
, functions
);
9081 while (CONSP (functions
))
9083 call1 (XCAR (functions
), frame
);
9084 functions
= XCDR (functions
);
9090 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9091 #ifdef HAVE_WINDOW_SYSTEM
9092 update_tool_bar (f
, 0);
9094 mac_update_title_bar (f
, 0);
9100 unbind_to (count
, Qnil
);
9104 struct frame
*sf
= SELECTED_FRAME ();
9105 update_menu_bar (sf
, 1, 0);
9106 #ifdef HAVE_WINDOW_SYSTEM
9107 update_tool_bar (sf
, 1);
9109 mac_update_title_bar (sf
, 1);
9114 /* Motif needs this. See comment in xmenu.c. Turn it off when
9115 pending_menu_activation is not defined. */
9116 #ifdef USE_X_TOOLKIT
9117 pending_menu_activation
= 0;
9122 /* Update the menu bar item list for frame F. This has to be done
9123 before we start to fill in any display lines, because it can call
9126 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9128 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9129 already ran the menu bar hooks for this redisplay, so there
9130 is no need to run them again. The return value is the
9131 updated value of this flag, to pass to the next call. */
9134 update_menu_bar (f
, save_match_data
, hooks_run
)
9136 int save_match_data
;
9140 register struct window
*w
;
9142 /* If called recursively during a menu update, do nothing. This can
9143 happen when, for instance, an activate-menubar-hook causes a
9145 if (inhibit_menubar_update
)
9148 window
= FRAME_SELECTED_WINDOW (f
);
9149 w
= XWINDOW (window
);
9151 #if 0 /* The if statement below this if statement used to include the
9152 condition !NILP (w->update_mode_line), rather than using
9153 update_mode_lines directly, and this if statement may have
9154 been added to make that condition work. Now the if
9155 statement below matches its comment, this isn't needed. */
9156 if (update_mode_lines
)
9157 w
->update_mode_line
= Qt
;
9160 if (FRAME_WINDOW_P (f
)
9162 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9163 || defined (USE_GTK)
9164 FRAME_EXTERNAL_MENU_BAR (f
)
9166 FRAME_MENU_BAR_LINES (f
) > 0
9168 : FRAME_MENU_BAR_LINES (f
) > 0)
9170 /* If the user has switched buffers or windows, we need to
9171 recompute to reflect the new bindings. But we'll
9172 recompute when update_mode_lines is set too; that means
9173 that people can use force-mode-line-update to request
9174 that the menu bar be recomputed. The adverse effect on
9175 the rest of the redisplay algorithm is about the same as
9176 windows_or_buffers_changed anyway. */
9177 if (windows_or_buffers_changed
9178 /* This used to test w->update_mode_line, but we believe
9179 there is no need to recompute the menu in that case. */
9180 || update_mode_lines
9181 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9182 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9183 != !NILP (w
->last_had_star
))
9184 || ((!NILP (Vtransient_mark_mode
)
9185 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9186 != !NILP (w
->region_showing
)))
9188 struct buffer
*prev
= current_buffer
;
9189 int count
= SPECPDL_INDEX ();
9191 specbind (Qinhibit_menubar_update
, Qt
);
9193 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9194 if (save_match_data
)
9195 record_unwind_save_match_data ();
9196 if (NILP (Voverriding_local_map_menu_flag
))
9198 specbind (Qoverriding_terminal_local_map
, Qnil
);
9199 specbind (Qoverriding_local_map
, Qnil
);
9204 /* Run the Lucid hook. */
9205 safe_run_hooks (Qactivate_menubar_hook
);
9207 /* If it has changed current-menubar from previous value,
9208 really recompute the menu-bar from the value. */
9209 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9210 call0 (Qrecompute_lucid_menubar
);
9212 safe_run_hooks (Qmenu_bar_update_hook
);
9217 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9219 /* Redisplay the menu bar in case we changed it. */
9220 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9221 || defined (USE_GTK)
9222 if (FRAME_WINDOW_P (f
))
9225 /* All frames on Mac OS share the same menubar. So only
9226 the selected frame should be allowed to set it. */
9227 if (f
== SELECTED_FRAME ())
9229 set_frame_menubar (f
, 0, 0);
9232 /* On a terminal screen, the menu bar is an ordinary screen
9233 line, and this makes it get updated. */
9234 w
->update_mode_line
= Qt
;
9235 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9236 /* In the non-toolkit version, the menu bar is an ordinary screen
9237 line, and this makes it get updated. */
9238 w
->update_mode_line
= Qt
;
9239 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9241 unbind_to (count
, Qnil
);
9242 set_buffer_internal_1 (prev
);
9251 /***********************************************************************
9253 ***********************************************************************/
9255 #ifdef HAVE_WINDOW_SYSTEM
9258 Nominal cursor position -- where to draw output.
9259 HPOS and VPOS are window relative glyph matrix coordinates.
9260 X and Y are window relative pixel coordinates. */
9262 struct cursor_pos output_cursor
;
9266 Set the global variable output_cursor to CURSOR. All cursor
9267 positions are relative to updated_window. */
9270 set_output_cursor (cursor
)
9271 struct cursor_pos
*cursor
;
9273 output_cursor
.hpos
= cursor
->hpos
;
9274 output_cursor
.vpos
= cursor
->vpos
;
9275 output_cursor
.x
= cursor
->x
;
9276 output_cursor
.y
= cursor
->y
;
9281 Set a nominal cursor position.
9283 HPOS and VPOS are column/row positions in a window glyph matrix. X
9284 and Y are window text area relative pixel positions.
9286 If this is done during an update, updated_window will contain the
9287 window that is being updated and the position is the future output
9288 cursor position for that window. If updated_window is null, use
9289 selected_window and display the cursor at the given position. */
9292 x_cursor_to (vpos
, hpos
, y
, x
)
9293 int vpos
, hpos
, y
, x
;
9297 /* If updated_window is not set, work on selected_window. */
9301 w
= XWINDOW (selected_window
);
9303 /* Set the output cursor. */
9304 output_cursor
.hpos
= hpos
;
9305 output_cursor
.vpos
= vpos
;
9306 output_cursor
.x
= x
;
9307 output_cursor
.y
= y
;
9309 /* If not called as part of an update, really display the cursor.
9310 This will also set the cursor position of W. */
9311 if (updated_window
== NULL
)
9314 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9315 if (rif
->flush_display_optional
)
9316 rif
->flush_display_optional (SELECTED_FRAME ());
9321 #endif /* HAVE_WINDOW_SYSTEM */
9324 /***********************************************************************
9326 ***********************************************************************/
9328 #ifdef HAVE_WINDOW_SYSTEM
9330 /* Where the mouse was last time we reported a mouse event. */
9332 FRAME_PTR last_mouse_frame
;
9334 /* Tool-bar item index of the item on which a mouse button was pressed
9337 int last_tool_bar_item
;
9340 /* Update the tool-bar item list for frame F. This has to be done
9341 before we start to fill in any display lines. Called from
9342 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9343 and restore it here. */
9346 update_tool_bar (f
, save_match_data
)
9348 int save_match_data
;
9351 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9353 int do_update
= WINDOWP (f
->tool_bar_window
)
9354 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9362 window
= FRAME_SELECTED_WINDOW (f
);
9363 w
= XWINDOW (window
);
9365 /* If the user has switched buffers or windows, we need to
9366 recompute to reflect the new bindings. But we'll
9367 recompute when update_mode_lines is set too; that means
9368 that people can use force-mode-line-update to request
9369 that the menu bar be recomputed. The adverse effect on
9370 the rest of the redisplay algorithm is about the same as
9371 windows_or_buffers_changed anyway. */
9372 if (windows_or_buffers_changed
9373 || !NILP (w
->update_mode_line
)
9374 || update_mode_lines
9375 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9376 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9377 != !NILP (w
->last_had_star
))
9378 || ((!NILP (Vtransient_mark_mode
)
9379 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9380 != !NILP (w
->region_showing
)))
9382 struct buffer
*prev
= current_buffer
;
9383 int count
= SPECPDL_INDEX ();
9384 Lisp_Object new_tool_bar
;
9386 struct gcpro gcpro1
;
9388 /* Set current_buffer to the buffer of the selected
9389 window of the frame, so that we get the right local
9391 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9393 /* Save match data, if we must. */
9394 if (save_match_data
)
9395 record_unwind_save_match_data ();
9397 /* Make sure that we don't accidentally use bogus keymaps. */
9398 if (NILP (Voverriding_local_map_menu_flag
))
9400 specbind (Qoverriding_terminal_local_map
, Qnil
);
9401 specbind (Qoverriding_local_map
, Qnil
);
9404 GCPRO1 (new_tool_bar
);
9406 /* Build desired tool-bar items from keymaps. */
9407 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9410 /* Redisplay the tool-bar if we changed it. */
9411 if (new_n_tool_bar
!= f
->n_tool_bar_items
9412 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9414 /* Redisplay that happens asynchronously due to an expose event
9415 may access f->tool_bar_items. Make sure we update both
9416 variables within BLOCK_INPUT so no such event interrupts. */
9418 f
->tool_bar_items
= new_tool_bar
;
9419 f
->n_tool_bar_items
= new_n_tool_bar
;
9420 w
->update_mode_line
= Qt
;
9426 unbind_to (count
, Qnil
);
9427 set_buffer_internal_1 (prev
);
9433 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9434 F's desired tool-bar contents. F->tool_bar_items must have
9435 been set up previously by calling prepare_menu_bars. */
9438 build_desired_tool_bar_string (f
)
9441 int i
, size
, size_needed
;
9442 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9443 Lisp_Object image
, plist
, props
;
9445 image
= plist
= props
= Qnil
;
9446 GCPRO3 (image
, plist
, props
);
9448 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9449 Otherwise, make a new string. */
9451 /* The size of the string we might be able to reuse. */
9452 size
= (STRINGP (f
->desired_tool_bar_string
)
9453 ? SCHARS (f
->desired_tool_bar_string
)
9456 /* We need one space in the string for each image. */
9457 size_needed
= f
->n_tool_bar_items
;
9459 /* Reuse f->desired_tool_bar_string, if possible. */
9460 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9461 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9465 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9466 Fremove_text_properties (make_number (0), make_number (size
),
9467 props
, f
->desired_tool_bar_string
);
9470 /* Put a `display' property on the string for the images to display,
9471 put a `menu_item' property on tool-bar items with a value that
9472 is the index of the item in F's tool-bar item vector. */
9473 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9475 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9477 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9478 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9479 int hmargin
, vmargin
, relief
, idx
, end
;
9480 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9482 /* If image is a vector, choose the image according to the
9484 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9485 if (VECTORP (image
))
9489 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9490 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9493 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9494 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9496 xassert (ASIZE (image
) >= idx
);
9497 image
= AREF (image
, idx
);
9502 /* Ignore invalid image specifications. */
9503 if (!valid_image_p (image
))
9506 /* Display the tool-bar button pressed, or depressed. */
9507 plist
= Fcopy_sequence (XCDR (image
));
9509 /* Compute margin and relief to draw. */
9510 relief
= (tool_bar_button_relief
>= 0
9511 ? tool_bar_button_relief
9512 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9513 hmargin
= vmargin
= relief
;
9515 if (INTEGERP (Vtool_bar_button_margin
)
9516 && XINT (Vtool_bar_button_margin
) > 0)
9518 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9519 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9521 else if (CONSP (Vtool_bar_button_margin
))
9523 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9524 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9525 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9527 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9528 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9529 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9532 if (auto_raise_tool_bar_buttons_p
)
9534 /* Add a `:relief' property to the image spec if the item is
9538 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9545 /* If image is selected, display it pressed, i.e. with a
9546 negative relief. If it's not selected, display it with a
9548 plist
= Fplist_put (plist
, QCrelief
,
9550 ? make_number (-relief
)
9551 : make_number (relief
)));
9556 /* Put a margin around the image. */
9557 if (hmargin
|| vmargin
)
9559 if (hmargin
== vmargin
)
9560 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9562 plist
= Fplist_put (plist
, QCmargin
,
9563 Fcons (make_number (hmargin
),
9564 make_number (vmargin
)));
9567 /* If button is not enabled, and we don't have special images
9568 for the disabled state, make the image appear disabled by
9569 applying an appropriate algorithm to it. */
9570 if (!enabled_p
&& idx
< 0)
9571 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9573 /* Put a `display' text property on the string for the image to
9574 display. Put a `menu-item' property on the string that gives
9575 the start of this item's properties in the tool-bar items
9577 image
= Fcons (Qimage
, plist
);
9578 props
= list4 (Qdisplay
, image
,
9579 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9581 /* Let the last image hide all remaining spaces in the tool bar
9582 string. The string can be longer than needed when we reuse a
9584 if (i
+ 1 == f
->n_tool_bar_items
)
9585 end
= SCHARS (f
->desired_tool_bar_string
);
9588 Fadd_text_properties (make_number (i
), make_number (end
),
9589 props
, f
->desired_tool_bar_string
);
9597 /* Display one line of the tool-bar of frame IT->f.
9599 HEIGHT specifies the desired height of the tool-bar line.
9600 If the actual height of the glyph row is less than HEIGHT, the
9601 row's height is increased to HEIGHT, and the icons are centered
9602 vertically in the new height.
9604 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9605 count a final empty row in case the tool-bar width exactly matches
9610 display_tool_bar_line (it
, height
)
9614 struct glyph_row
*row
= it
->glyph_row
;
9615 int max_x
= it
->last_visible_x
;
9618 prepare_desired_row (row
);
9619 row
->y
= it
->current_y
;
9621 /* Note that this isn't made use of if the face hasn't a box,
9622 so there's no need to check the face here. */
9623 it
->start_of_box_run_p
= 1;
9625 while (it
->current_x
< max_x
)
9627 int x
, n_glyphs_before
, i
, nglyphs
;
9628 struct it it_before
;
9630 /* Get the next display element. */
9631 if (!get_next_display_element (it
))
9633 /* Don't count empty row if we are counting needed tool-bar lines. */
9634 if (height
< 0 && !it
->hpos
)
9639 /* Produce glyphs. */
9640 n_glyphs_before
= row
->used
[TEXT_AREA
];
9643 PRODUCE_GLYPHS (it
);
9645 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9647 x
= it_before
.current_x
;
9650 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9652 if (x
+ glyph
->pixel_width
> max_x
)
9654 /* Glyph doesn't fit on line. Backtrack. */
9655 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9657 /* If this is the only glyph on this line, it will never fit on the
9658 toolbar, so skip it. But ensure there is at least one glyph,
9659 so we don't accidentally disable the tool-bar. */
9660 if (n_glyphs_before
== 0
9661 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9667 x
+= glyph
->pixel_width
;
9671 /* Stop at line ends. */
9672 if (ITERATOR_AT_END_OF_LINE_P (it
))
9675 set_iterator_to_next (it
, 1);
9680 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9681 /* Use default face for the border below the tool bar. */
9682 if (!row
->displays_text_p
)
9683 it
->face_id
= DEFAULT_FACE_ID
;
9684 extend_face_to_end_of_line (it
);
9685 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9686 last
->right_box_line_p
= 1;
9687 if (last
== row
->glyphs
[TEXT_AREA
])
9688 last
->left_box_line_p
= 1;
9690 /* Make line the desired height and center it vertically. */
9691 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9693 /* Don't add more than one line height. */
9694 height
%= FRAME_LINE_HEIGHT (it
->f
);
9695 it
->max_ascent
+= height
/ 2;
9696 it
->max_descent
+= (height
+ 1) / 2;
9699 compute_line_metrics (it
);
9701 /* If line is empty, make it occupy the rest of the tool-bar. */
9702 if (!row
->displays_text_p
)
9704 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9705 row
->ascent
= row
->phys_ascent
= 0;
9706 row
->extra_line_spacing
= 0;
9709 row
->full_width_p
= 1;
9710 row
->continued_p
= 0;
9711 row
->truncated_on_left_p
= 0;
9712 row
->truncated_on_right_p
= 0;
9714 it
->current_x
= it
->hpos
= 0;
9715 it
->current_y
+= row
->height
;
9721 /* Max tool-bar height. */
9723 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9724 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9726 /* Value is the number of screen lines needed to make all tool-bar
9727 items of frame F visible. The number of actual rows needed is
9728 returned in *N_ROWS if non-NULL. */
9731 tool_bar_lines_needed (f
, n_rows
)
9735 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9737 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9738 the desired matrix, so use (unused) mode-line row as temporary row to
9739 avoid destroying the first tool-bar row. */
9740 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9742 /* Initialize an iterator for iteration over
9743 F->desired_tool_bar_string in the tool-bar window of frame F. */
9744 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9745 it
.first_visible_x
= 0;
9746 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9747 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9749 while (!ITERATOR_AT_END_P (&it
))
9751 clear_glyph_row (temp_row
);
9752 it
.glyph_row
= temp_row
;
9753 display_tool_bar_line (&it
, -1);
9755 clear_glyph_row (temp_row
);
9757 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9759 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9761 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9765 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9767 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9776 frame
= selected_frame
;
9778 CHECK_FRAME (frame
);
9781 if (WINDOWP (f
->tool_bar_window
)
9782 || (w
= XWINDOW (f
->tool_bar_window
),
9783 WINDOW_TOTAL_LINES (w
) > 0))
9785 update_tool_bar (f
, 1);
9786 if (f
->n_tool_bar_items
)
9788 build_desired_tool_bar_string (f
);
9789 nlines
= tool_bar_lines_needed (f
, NULL
);
9793 return make_number (nlines
);
9797 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9798 height should be changed. */
9801 redisplay_tool_bar (f
)
9806 struct glyph_row
*row
;
9807 int change_height_p
= 0;
9810 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9811 update_frame_tool_bar (f
);
9815 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9816 do anything. This means you must start with tool-bar-lines
9817 non-zero to get the auto-sizing effect. Or in other words, you
9818 can turn off tool-bars by specifying tool-bar-lines zero. */
9819 if (!WINDOWP (f
->tool_bar_window
)
9820 || (w
= XWINDOW (f
->tool_bar_window
),
9821 WINDOW_TOTAL_LINES (w
) == 0))
9824 /* Set up an iterator for the tool-bar window. */
9825 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9826 it
.first_visible_x
= 0;
9827 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9830 /* Build a string that represents the contents of the tool-bar. */
9831 build_desired_tool_bar_string (f
);
9832 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9834 if (f
->n_tool_bar_rows
== 0)
9838 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9839 nlines
!= WINDOW_TOTAL_LINES (w
)))
9841 extern Lisp_Object Qtool_bar_lines
;
9843 int old_height
= WINDOW_TOTAL_LINES (w
);
9845 XSETFRAME (frame
, f
);
9846 Fmodify_frame_parameters (frame
,
9847 Fcons (Fcons (Qtool_bar_lines
,
9848 make_number (nlines
)),
9850 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9852 clear_glyph_matrix (w
->desired_matrix
);
9853 fonts_changed_p
= 1;
9859 /* Display as many lines as needed to display all tool-bar items. */
9861 if (f
->n_tool_bar_rows
> 0)
9863 int border
, rows
, height
, extra
;
9865 if (INTEGERP (Vtool_bar_border
))
9866 border
= XINT (Vtool_bar_border
);
9867 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9868 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9869 else if (EQ (Vtool_bar_border
, Qborder_width
))
9870 border
= f
->border_width
;
9876 rows
= f
->n_tool_bar_rows
;
9877 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9878 extra
= it
.last_visible_y
- border
- height
* rows
;
9880 while (it
.current_y
< it
.last_visible_y
)
9883 if (extra
> 0 && rows
-- > 0)
9885 h
= (extra
+ rows
- 1) / rows
;
9888 display_tool_bar_line (&it
, height
+ h
);
9893 while (it
.current_y
< it
.last_visible_y
)
9894 display_tool_bar_line (&it
, 0);
9897 /* It doesn't make much sense to try scrolling in the tool-bar
9898 window, so don't do it. */
9899 w
->desired_matrix
->no_scrolling_p
= 1;
9900 w
->must_be_updated_p
= 1;
9902 if (auto_resize_tool_bars_p
)
9905 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
9907 /* If we couldn't display everything, change the tool-bar's
9908 height if there is room for more. */
9909 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
9910 && it
.current_y
< max_tool_bar_height
)
9911 change_height_p
= 1;
9913 row
= it
.glyph_row
- 1;
9915 /* If there are blank lines at the end, except for a partially
9916 visible blank line at the end that is smaller than
9917 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9918 if (!row
->displays_text_p
9919 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9920 change_height_p
= 1;
9922 /* If row displays tool-bar items, but is partially visible,
9923 change the tool-bar's height. */
9924 if (row
->displays_text_p
9925 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
9926 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
9927 change_height_p
= 1;
9929 /* Resize windows as needed by changing the `tool-bar-lines'
9932 && (nlines
= tool_bar_lines_needed (f
, &nrows
),
9933 nlines
!= WINDOW_TOTAL_LINES (w
)))
9935 extern Lisp_Object Qtool_bar_lines
;
9937 int old_height
= WINDOW_TOTAL_LINES (w
);
9939 XSETFRAME (frame
, f
);
9940 Fmodify_frame_parameters (frame
,
9941 Fcons (Fcons (Qtool_bar_lines
,
9942 make_number (nlines
)),
9944 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9946 clear_glyph_matrix (w
->desired_matrix
);
9947 f
->n_tool_bar_rows
= nrows
;
9948 fonts_changed_p
= 1;
9953 return change_height_p
;
9957 /* Get information about the tool-bar item which is displayed in GLYPH
9958 on frame F. Return in *PROP_IDX the index where tool-bar item
9959 properties start in F->tool_bar_items. Value is zero if
9960 GLYPH doesn't display a tool-bar item. */
9963 tool_bar_item_info (f
, glyph
, prop_idx
)
9965 struct glyph
*glyph
;
9972 /* This function can be called asynchronously, which means we must
9973 exclude any possibility that Fget_text_property signals an
9975 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9976 charpos
= max (0, charpos
);
9978 /* Get the text property `menu-item' at pos. The value of that
9979 property is the start index of this item's properties in
9980 F->tool_bar_items. */
9981 prop
= Fget_text_property (make_number (charpos
),
9982 Qmenu_item
, f
->current_tool_bar_string
);
9983 if (INTEGERP (prop
))
9985 *prop_idx
= XINT (prop
);
9995 /* Get information about the tool-bar item at position X/Y on frame F.
9996 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9997 the current matrix of the tool-bar window of F, or NULL if not
9998 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9999 item in F->tool_bar_items. Value is
10001 -1 if X/Y is not on a tool-bar item
10002 0 if X/Y is on the same item that was highlighted before.
10006 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10009 struct glyph
**glyph
;
10010 int *hpos
, *vpos
, *prop_idx
;
10012 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10013 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10016 /* Find the glyph under X/Y. */
10017 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10018 if (*glyph
== NULL
)
10021 /* Get the start of this tool-bar item's properties in
10022 f->tool_bar_items. */
10023 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10026 /* Is mouse on the highlighted item? */
10027 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10028 && *vpos
>= dpyinfo
->mouse_face_beg_row
10029 && *vpos
<= dpyinfo
->mouse_face_end_row
10030 && (*vpos
> dpyinfo
->mouse_face_beg_row
10031 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10032 && (*vpos
< dpyinfo
->mouse_face_end_row
10033 || *hpos
< dpyinfo
->mouse_face_end_col
10034 || dpyinfo
->mouse_face_past_end
))
10042 Handle mouse button event on the tool-bar of frame F, at
10043 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10044 0 for button release. MODIFIERS is event modifiers for button
10048 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10051 unsigned int modifiers
;
10053 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10054 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10055 int hpos
, vpos
, prop_idx
;
10056 struct glyph
*glyph
;
10057 Lisp_Object enabled_p
;
10059 /* If not on the highlighted tool-bar item, return. */
10060 frame_to_window_pixel_xy (w
, &x
, &y
);
10061 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10064 /* If item is disabled, do nothing. */
10065 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10066 if (NILP (enabled_p
))
10071 /* Show item in pressed state. */
10072 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10073 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10074 last_tool_bar_item
= prop_idx
;
10078 Lisp_Object key
, frame
;
10079 struct input_event event
;
10080 EVENT_INIT (event
);
10082 /* Show item in released state. */
10083 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10084 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10086 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10088 XSETFRAME (frame
, f
);
10089 event
.kind
= TOOL_BAR_EVENT
;
10090 event
.frame_or_window
= frame
;
10092 kbd_buffer_store_event (&event
);
10094 event
.kind
= TOOL_BAR_EVENT
;
10095 event
.frame_or_window
= frame
;
10097 event
.modifiers
= modifiers
;
10098 kbd_buffer_store_event (&event
);
10099 last_tool_bar_item
= -1;
10104 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10105 tool-bar window-relative coordinates X/Y. Called from
10106 note_mouse_highlight. */
10109 note_tool_bar_highlight (f
, x
, y
)
10113 Lisp_Object window
= f
->tool_bar_window
;
10114 struct window
*w
= XWINDOW (window
);
10115 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10117 struct glyph
*glyph
;
10118 struct glyph_row
*row
;
10120 Lisp_Object enabled_p
;
10122 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10123 int mouse_down_p
, rc
;
10125 /* Function note_mouse_highlight is called with negative x(y
10126 values when mouse moves outside of the frame. */
10127 if (x
<= 0 || y
<= 0)
10129 clear_mouse_face (dpyinfo
);
10133 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10136 /* Not on tool-bar item. */
10137 clear_mouse_face (dpyinfo
);
10141 /* On same tool-bar item as before. */
10142 goto set_help_echo
;
10144 clear_mouse_face (dpyinfo
);
10146 /* Mouse is down, but on different tool-bar item? */
10147 mouse_down_p
= (dpyinfo
->grabbed
10148 && f
== last_mouse_frame
10149 && FRAME_LIVE_P (f
));
10151 && last_tool_bar_item
!= prop_idx
)
10154 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10155 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10157 /* If tool-bar item is not enabled, don't highlight it. */
10158 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10159 if (!NILP (enabled_p
))
10161 /* Compute the x-position of the glyph. In front and past the
10162 image is a space. We include this in the highlighted area. */
10163 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10164 for (i
= x
= 0; i
< hpos
; ++i
)
10165 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10167 /* Record this as the current active region. */
10168 dpyinfo
->mouse_face_beg_col
= hpos
;
10169 dpyinfo
->mouse_face_beg_row
= vpos
;
10170 dpyinfo
->mouse_face_beg_x
= x
;
10171 dpyinfo
->mouse_face_beg_y
= row
->y
;
10172 dpyinfo
->mouse_face_past_end
= 0;
10174 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10175 dpyinfo
->mouse_face_end_row
= vpos
;
10176 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10177 dpyinfo
->mouse_face_end_y
= row
->y
;
10178 dpyinfo
->mouse_face_window
= window
;
10179 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10181 /* Display it as active. */
10182 show_mouse_face (dpyinfo
, draw
);
10183 dpyinfo
->mouse_face_image_state
= draw
;
10188 /* Set help_echo_string to a help string to display for this tool-bar item.
10189 XTread_socket does the rest. */
10190 help_echo_object
= help_echo_window
= Qnil
;
10191 help_echo_pos
= -1;
10192 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10193 if (NILP (help_echo_string
))
10194 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10197 #endif /* HAVE_WINDOW_SYSTEM */
10201 /************************************************************************
10202 Horizontal scrolling
10203 ************************************************************************/
10205 static int hscroll_window_tree
P_ ((Lisp_Object
));
10206 static int hscroll_windows
P_ ((Lisp_Object
));
10208 /* For all leaf windows in the window tree rooted at WINDOW, set their
10209 hscroll value so that PT is (i) visible in the window, and (ii) so
10210 that it is not within a certain margin at the window's left and
10211 right border. Value is non-zero if any window's hscroll has been
10215 hscroll_window_tree (window
)
10216 Lisp_Object window
;
10218 int hscrolled_p
= 0;
10219 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10220 int hscroll_step_abs
= 0;
10221 double hscroll_step_rel
= 0;
10223 if (hscroll_relative_p
)
10225 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10226 if (hscroll_step_rel
< 0)
10228 hscroll_relative_p
= 0;
10229 hscroll_step_abs
= 0;
10232 else if (INTEGERP (Vhscroll_step
))
10234 hscroll_step_abs
= XINT (Vhscroll_step
);
10235 if (hscroll_step_abs
< 0)
10236 hscroll_step_abs
= 0;
10239 hscroll_step_abs
= 0;
10241 while (WINDOWP (window
))
10243 struct window
*w
= XWINDOW (window
);
10245 if (WINDOWP (w
->hchild
))
10246 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10247 else if (WINDOWP (w
->vchild
))
10248 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10249 else if (w
->cursor
.vpos
>= 0)
10252 int text_area_width
;
10253 struct glyph_row
*current_cursor_row
10254 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10255 struct glyph_row
*desired_cursor_row
10256 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10257 struct glyph_row
*cursor_row
10258 = (desired_cursor_row
->enabled_p
10259 ? desired_cursor_row
10260 : current_cursor_row
);
10262 text_area_width
= window_box_width (w
, TEXT_AREA
);
10264 /* Scroll when cursor is inside this scroll margin. */
10265 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10267 if ((XFASTINT (w
->hscroll
)
10268 && w
->cursor
.x
<= h_margin
)
10269 || (cursor_row
->enabled_p
10270 && cursor_row
->truncated_on_right_p
10271 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10275 struct buffer
*saved_current_buffer
;
10279 /* Find point in a display of infinite width. */
10280 saved_current_buffer
= current_buffer
;
10281 current_buffer
= XBUFFER (w
->buffer
);
10283 if (w
== XWINDOW (selected_window
))
10284 pt
= BUF_PT (current_buffer
);
10287 pt
= marker_position (w
->pointm
);
10288 pt
= max (BEGV
, pt
);
10292 /* Move iterator to pt starting at cursor_row->start in
10293 a line with infinite width. */
10294 init_to_row_start (&it
, w
, cursor_row
);
10295 it
.last_visible_x
= INFINITY
;
10296 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10297 current_buffer
= saved_current_buffer
;
10299 /* Position cursor in window. */
10300 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10301 hscroll
= max (0, (it
.current_x
10302 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10303 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10304 : (text_area_width
/ 2))))
10305 / FRAME_COLUMN_WIDTH (it
.f
);
10306 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10308 if (hscroll_relative_p
)
10309 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10312 wanted_x
= text_area_width
10313 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10316 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10320 if (hscroll_relative_p
)
10321 wanted_x
= text_area_width
* hscroll_step_rel
10324 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10327 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10329 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10331 /* Don't call Fset_window_hscroll if value hasn't
10332 changed because it will prevent redisplay
10334 if (XFASTINT (w
->hscroll
) != hscroll
)
10336 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10337 w
->hscroll
= make_number (hscroll
);
10346 /* Value is non-zero if hscroll of any leaf window has been changed. */
10347 return hscrolled_p
;
10351 /* Set hscroll so that cursor is visible and not inside horizontal
10352 scroll margins for all windows in the tree rooted at WINDOW. See
10353 also hscroll_window_tree above. Value is non-zero if any window's
10354 hscroll has been changed. If it has, desired matrices on the frame
10355 of WINDOW are cleared. */
10358 hscroll_windows (window
)
10359 Lisp_Object window
;
10363 if (automatic_hscrolling_p
)
10365 hscrolled_p
= hscroll_window_tree (window
);
10367 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10371 return hscrolled_p
;
10376 /************************************************************************
10378 ************************************************************************/
10380 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10381 to a non-zero value. This is sometimes handy to have in a debugger
10386 /* First and last unchanged row for try_window_id. */
10388 int debug_first_unchanged_at_end_vpos
;
10389 int debug_last_unchanged_at_beg_vpos
;
10391 /* Delta vpos and y. */
10393 int debug_dvpos
, debug_dy
;
10395 /* Delta in characters and bytes for try_window_id. */
10397 int debug_delta
, debug_delta_bytes
;
10399 /* Values of window_end_pos and window_end_vpos at the end of
10402 EMACS_INT debug_end_pos
, debug_end_vpos
;
10404 /* Append a string to W->desired_matrix->method. FMT is a printf
10405 format string. A1...A9 are a supplement for a variable-length
10406 argument list. If trace_redisplay_p is non-zero also printf the
10407 resulting string to stderr. */
10410 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10413 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10416 char *method
= w
->desired_matrix
->method
;
10417 int len
= strlen (method
);
10418 int size
= sizeof w
->desired_matrix
->method
;
10419 int remaining
= size
- len
- 1;
10421 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10422 if (len
&& remaining
)
10425 --remaining
, ++len
;
10428 strncpy (method
+ len
, buffer
, remaining
);
10430 if (trace_redisplay_p
)
10431 fprintf (stderr
, "%p (%s): %s\n",
10433 ((BUFFERP (w
->buffer
)
10434 && STRINGP (XBUFFER (w
->buffer
)->name
))
10435 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10440 #endif /* GLYPH_DEBUG */
10443 /* Value is non-zero if all changes in window W, which displays
10444 current_buffer, are in the text between START and END. START is a
10445 buffer position, END is given as a distance from Z. Used in
10446 redisplay_internal for display optimization. */
10449 text_outside_line_unchanged_p (w
, start
, end
)
10453 int unchanged_p
= 1;
10455 /* If text or overlays have changed, see where. */
10456 if (XFASTINT (w
->last_modified
) < MODIFF
10457 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10459 /* Gap in the line? */
10460 if (GPT
< start
|| Z
- GPT
< end
)
10463 /* Changes start in front of the line, or end after it? */
10465 && (BEG_UNCHANGED
< start
- 1
10466 || END_UNCHANGED
< end
))
10469 /* If selective display, can't optimize if changes start at the
10470 beginning of the line. */
10472 && INTEGERP (current_buffer
->selective_display
)
10473 && XINT (current_buffer
->selective_display
) > 0
10474 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10477 /* If there are overlays at the start or end of the line, these
10478 may have overlay strings with newlines in them. A change at
10479 START, for instance, may actually concern the display of such
10480 overlay strings as well, and they are displayed on different
10481 lines. So, quickly rule out this case. (For the future, it
10482 might be desirable to implement something more telling than
10483 just BEG/END_UNCHANGED.) */
10486 if (BEG
+ BEG_UNCHANGED
== start
10487 && overlay_touches_p (start
))
10489 if (END_UNCHANGED
== end
10490 && overlay_touches_p (Z
- end
))
10495 return unchanged_p
;
10499 /* Do a frame update, taking possible shortcuts into account. This is
10500 the main external entry point for redisplay.
10502 If the last redisplay displayed an echo area message and that message
10503 is no longer requested, we clear the echo area or bring back the
10504 mini-buffer if that is in use. */
10509 redisplay_internal (0);
10514 overlay_arrow_string_or_property (var
)
10519 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10522 return Voverlay_arrow_string
;
10525 /* Return 1 if there are any overlay-arrows in current_buffer. */
10527 overlay_arrow_in_current_buffer_p ()
10531 for (vlist
= Voverlay_arrow_variable_list
;
10533 vlist
= XCDR (vlist
))
10535 Lisp_Object var
= XCAR (vlist
);
10538 if (!SYMBOLP (var
))
10540 val
= find_symbol_value (var
);
10542 && current_buffer
== XMARKER (val
)->buffer
)
10549 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10553 overlay_arrows_changed_p ()
10557 for (vlist
= Voverlay_arrow_variable_list
;
10559 vlist
= XCDR (vlist
))
10561 Lisp_Object var
= XCAR (vlist
);
10562 Lisp_Object val
, pstr
;
10564 if (!SYMBOLP (var
))
10566 val
= find_symbol_value (var
);
10567 if (!MARKERP (val
))
10569 if (! EQ (COERCE_MARKER (val
),
10570 Fget (var
, Qlast_arrow_position
))
10571 || ! (pstr
= overlay_arrow_string_or_property (var
),
10572 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10578 /* Mark overlay arrows to be updated on next redisplay. */
10581 update_overlay_arrows (up_to_date
)
10586 for (vlist
= Voverlay_arrow_variable_list
;
10588 vlist
= XCDR (vlist
))
10590 Lisp_Object var
= XCAR (vlist
);
10592 if (!SYMBOLP (var
))
10595 if (up_to_date
> 0)
10597 Lisp_Object val
= find_symbol_value (var
);
10598 Fput (var
, Qlast_arrow_position
,
10599 COERCE_MARKER (val
));
10600 Fput (var
, Qlast_arrow_string
,
10601 overlay_arrow_string_or_property (var
));
10603 else if (up_to_date
< 0
10604 || !NILP (Fget (var
, Qlast_arrow_position
)))
10606 Fput (var
, Qlast_arrow_position
, Qt
);
10607 Fput (var
, Qlast_arrow_string
, Qt
);
10613 /* Return overlay arrow string to display at row.
10614 Return integer (bitmap number) for arrow bitmap in left fringe.
10615 Return nil if no overlay arrow. */
10618 overlay_arrow_at_row (it
, row
)
10620 struct glyph_row
*row
;
10624 for (vlist
= Voverlay_arrow_variable_list
;
10626 vlist
= XCDR (vlist
))
10628 Lisp_Object var
= XCAR (vlist
);
10631 if (!SYMBOLP (var
))
10634 val
= find_symbol_value (var
);
10637 && current_buffer
== XMARKER (val
)->buffer
10638 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10640 if (FRAME_WINDOW_P (it
->f
)
10641 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10643 #ifdef HAVE_WINDOW_SYSTEM
10644 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10647 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10648 return make_number (fringe_bitmap
);
10651 return make_number (-1); /* Use default arrow bitmap */
10653 return overlay_arrow_string_or_property (var
);
10660 /* Return 1 if point moved out of or into a composition. Otherwise
10661 return 0. PREV_BUF and PREV_PT are the last point buffer and
10662 position. BUF and PT are the current point buffer and position. */
10665 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10666 struct buffer
*prev_buf
, *buf
;
10671 Lisp_Object buffer
;
10673 XSETBUFFER (buffer
, buf
);
10674 /* Check a composition at the last point if point moved within the
10676 if (prev_buf
== buf
)
10679 /* Point didn't move. */
10682 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10683 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10684 && COMPOSITION_VALID_P (start
, end
, prop
)
10685 && start
< prev_pt
&& end
> prev_pt
)
10686 /* The last point was within the composition. Return 1 iff
10687 point moved out of the composition. */
10688 return (pt
<= start
|| pt
>= end
);
10691 /* Check a composition at the current point. */
10692 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10693 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10694 && COMPOSITION_VALID_P (start
, end
, prop
)
10695 && start
< pt
&& end
> pt
);
10699 /* Reconsider the setting of B->clip_changed which is displayed
10703 reconsider_clip_changes (w
, b
)
10707 if (b
->clip_changed
10708 && !NILP (w
->window_end_valid
)
10709 && w
->current_matrix
->buffer
== b
10710 && w
->current_matrix
->zv
== BUF_ZV (b
)
10711 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10712 b
->clip_changed
= 0;
10714 /* If display wasn't paused, and W is not a tool bar window, see if
10715 point has been moved into or out of a composition. In that case,
10716 we set b->clip_changed to 1 to force updating the screen. If
10717 b->clip_changed has already been set to 1, we can skip this
10719 if (!b
->clip_changed
10720 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10724 if (w
== XWINDOW (selected_window
))
10725 pt
= BUF_PT (current_buffer
);
10727 pt
= marker_position (w
->pointm
);
10729 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10730 || pt
!= XINT (w
->last_point
))
10731 && check_point_in_composition (w
->current_matrix
->buffer
,
10732 XINT (w
->last_point
),
10733 XBUFFER (w
->buffer
), pt
))
10734 b
->clip_changed
= 1;
10739 /* Select FRAME to forward the values of frame-local variables into C
10740 variables so that the redisplay routines can access those values
10744 select_frame_for_redisplay (frame
)
10747 Lisp_Object tail
, sym
, val
;
10748 Lisp_Object old
= selected_frame
;
10750 selected_frame
= frame
;
10752 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10753 if (CONSP (XCAR (tail
))
10754 && (sym
= XCAR (XCAR (tail
)),
10756 && (sym
= indirect_variable (sym
),
10757 val
= SYMBOL_VALUE (sym
),
10758 (BUFFER_LOCAL_VALUEP (val
)
10759 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10760 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10761 /* Use find_symbol_value rather than Fsymbol_value
10762 to avoid an error if it is void. */
10763 find_symbol_value (sym
);
10765 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10766 if (CONSP (XCAR (tail
))
10767 && (sym
= XCAR (XCAR (tail
)),
10769 && (sym
= indirect_variable (sym
),
10770 val
= SYMBOL_VALUE (sym
),
10771 (BUFFER_LOCAL_VALUEP (val
)
10772 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10773 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10774 find_symbol_value (sym
);
10778 #define STOP_POLLING \
10779 do { if (! polling_stopped_here) stop_polling (); \
10780 polling_stopped_here = 1; } while (0)
10782 #define RESUME_POLLING \
10783 do { if (polling_stopped_here) start_polling (); \
10784 polling_stopped_here = 0; } while (0)
10787 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10788 response to any user action; therefore, we should preserve the echo
10789 area. (Actually, our caller does that job.) Perhaps in the future
10790 avoid recentering windows if it is not necessary; currently that
10791 causes some problems. */
10794 redisplay_internal (preserve_echo_area
)
10795 int preserve_echo_area
;
10797 struct window
*w
= XWINDOW (selected_window
);
10798 struct frame
*f
= XFRAME (w
->frame
);
10800 int must_finish
= 0;
10801 struct text_pos tlbufpos
, tlendpos
;
10802 int number_of_visible_frames
;
10804 struct frame
*sf
= SELECTED_FRAME ();
10805 int polling_stopped_here
= 0;
10807 /* Non-zero means redisplay has to consider all windows on all
10808 frames. Zero means, only selected_window is considered. */
10809 int consider_all_windows_p
;
10811 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10813 /* No redisplay if running in batch mode or frame is not yet fully
10814 initialized, or redisplay is explicitly turned off by setting
10815 Vinhibit_redisplay. */
10817 || !NILP (Vinhibit_redisplay
)
10818 || !f
->glyphs_initialized_p
)
10821 /* The flag redisplay_performed_directly_p is set by
10822 direct_output_for_insert when it already did the whole screen
10823 update necessary. */
10824 if (redisplay_performed_directly_p
)
10826 redisplay_performed_directly_p
= 0;
10827 if (!hscroll_windows (selected_window
))
10831 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10832 if (popup_activated ())
10836 /* I don't think this happens but let's be paranoid. */
10837 if (redisplaying_p
)
10840 /* Record a function that resets redisplaying_p to its old value
10841 when we leave this function. */
10842 count
= SPECPDL_INDEX ();
10843 record_unwind_protect (unwind_redisplay
,
10844 Fcons (make_number (redisplaying_p
), selected_frame
));
10846 specbind (Qinhibit_free_realized_faces
, Qnil
);
10849 Lisp_Object tail
, frame
;
10851 FOR_EACH_FRAME (tail
, frame
)
10853 struct frame
*f
= XFRAME (frame
);
10854 f
->already_hscrolled_p
= 0;
10860 reconsider_clip_changes (w
, current_buffer
);
10861 last_escape_glyph_frame
= NULL
;
10862 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10864 /* If new fonts have been loaded that make a glyph matrix adjustment
10865 necessary, do it. */
10866 if (fonts_changed_p
)
10868 adjust_glyphs (NULL
);
10869 ++windows_or_buffers_changed
;
10870 fonts_changed_p
= 0;
10873 /* If face_change_count is non-zero, init_iterator will free all
10874 realized faces, which includes the faces referenced from current
10875 matrices. So, we can't reuse current matrices in this case. */
10876 if (face_change_count
)
10877 ++windows_or_buffers_changed
;
10879 if (! FRAME_WINDOW_P (sf
)
10880 && previous_terminal_frame
!= sf
)
10882 /* Since frames on an ASCII terminal share the same display
10883 area, displaying a different frame means redisplay the whole
10885 windows_or_buffers_changed
++;
10886 SET_FRAME_GARBAGED (sf
);
10887 XSETFRAME (Vterminal_frame
, sf
);
10889 previous_terminal_frame
= sf
;
10891 /* Set the visible flags for all frames. Do this before checking
10892 for resized or garbaged frames; they want to know if their frames
10893 are visible. See the comment in frame.h for
10894 FRAME_SAMPLE_VISIBILITY. */
10896 Lisp_Object tail
, frame
;
10898 number_of_visible_frames
= 0;
10900 FOR_EACH_FRAME (tail
, frame
)
10902 struct frame
*f
= XFRAME (frame
);
10904 FRAME_SAMPLE_VISIBILITY (f
);
10905 if (FRAME_VISIBLE_P (f
))
10906 ++number_of_visible_frames
;
10907 clear_desired_matrices (f
);
10911 /* Notice any pending interrupt request to change frame size. */
10912 do_pending_window_change (1);
10914 /* Clear frames marked as garbaged. */
10915 if (frame_garbaged
)
10916 clear_garbaged_frames ();
10918 /* Build menubar and tool-bar items. */
10919 if (NILP (Vmemory_full
))
10920 prepare_menu_bars ();
10922 if (windows_or_buffers_changed
)
10923 update_mode_lines
++;
10925 /* Detect case that we need to write or remove a star in the mode line. */
10926 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10928 w
->update_mode_line
= Qt
;
10929 if (buffer_shared
> 1)
10930 update_mode_lines
++;
10933 /* If %c is in the mode line, update it if needed. */
10934 if (!NILP (w
->column_number_displayed
)
10935 /* This alternative quickly identifies a common case
10936 where no change is needed. */
10937 && !(PT
== XFASTINT (w
->last_point
)
10938 && XFASTINT (w
->last_modified
) >= MODIFF
10939 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10940 && (XFASTINT (w
->column_number_displayed
)
10941 != (int) current_column ())) /* iftc */
10942 w
->update_mode_line
= Qt
;
10944 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10946 /* The variable buffer_shared is set in redisplay_window and
10947 indicates that we redisplay a buffer in different windows. See
10949 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10950 || cursor_type_changed
);
10952 /* If specs for an arrow have changed, do thorough redisplay
10953 to ensure we remove any arrow that should no longer exist. */
10954 if (overlay_arrows_changed_p ())
10955 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10957 /* Normally the message* functions will have already displayed and
10958 updated the echo area, but the frame may have been trashed, or
10959 the update may have been preempted, so display the echo area
10960 again here. Checking message_cleared_p captures the case that
10961 the echo area should be cleared. */
10962 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10963 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10964 || (message_cleared_p
10965 && minibuf_level
== 0
10966 /* If the mini-window is currently selected, this means the
10967 echo-area doesn't show through. */
10968 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10970 int window_height_changed_p
= echo_area_display (0);
10973 /* If we don't display the current message, don't clear the
10974 message_cleared_p flag, because, if we did, we wouldn't clear
10975 the echo area in the next redisplay which doesn't preserve
10977 if (!display_last_displayed_message_p
)
10978 message_cleared_p
= 0;
10980 if (fonts_changed_p
)
10982 else if (window_height_changed_p
)
10984 consider_all_windows_p
= 1;
10985 ++update_mode_lines
;
10986 ++windows_or_buffers_changed
;
10988 /* If window configuration was changed, frames may have been
10989 marked garbaged. Clear them or we will experience
10990 surprises wrt scrolling. */
10991 if (frame_garbaged
)
10992 clear_garbaged_frames ();
10995 else if (EQ (selected_window
, minibuf_window
)
10996 && (current_buffer
->clip_changed
10997 || XFASTINT (w
->last_modified
) < MODIFF
10998 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10999 && resize_mini_window (w
, 0))
11001 /* Resized active mini-window to fit the size of what it is
11002 showing if its contents might have changed. */
11004 consider_all_windows_p
= 1;
11005 ++windows_or_buffers_changed
;
11006 ++update_mode_lines
;
11008 /* If window configuration was changed, frames may have been
11009 marked garbaged. Clear them or we will experience
11010 surprises wrt scrolling. */
11011 if (frame_garbaged
)
11012 clear_garbaged_frames ();
11016 /* If showing the region, and mark has changed, we must redisplay
11017 the whole window. The assignment to this_line_start_pos prevents
11018 the optimization directly below this if-statement. */
11019 if (((!NILP (Vtransient_mark_mode
)
11020 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11021 != !NILP (w
->region_showing
))
11022 || (!NILP (w
->region_showing
)
11023 && !EQ (w
->region_showing
,
11024 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11025 CHARPOS (this_line_start_pos
) = 0;
11027 /* Optimize the case that only the line containing the cursor in the
11028 selected window has changed. Variables starting with this_ are
11029 set in display_line and record information about the line
11030 containing the cursor. */
11031 tlbufpos
= this_line_start_pos
;
11032 tlendpos
= this_line_end_pos
;
11033 if (!consider_all_windows_p
11034 && CHARPOS (tlbufpos
) > 0
11035 && NILP (w
->update_mode_line
)
11036 && !current_buffer
->clip_changed
11037 && !current_buffer
->prevent_redisplay_optimizations_p
11038 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11039 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11040 /* Make sure recorded data applies to current buffer, etc. */
11041 && this_line_buffer
== current_buffer
11042 && current_buffer
== XBUFFER (w
->buffer
)
11043 && NILP (w
->force_start
)
11044 && NILP (w
->optional_new_start
)
11045 /* Point must be on the line that we have info recorded about. */
11046 && PT
>= CHARPOS (tlbufpos
)
11047 && PT
<= Z
- CHARPOS (tlendpos
)
11048 /* All text outside that line, including its final newline,
11049 must be unchanged */
11050 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11051 CHARPOS (tlendpos
)))
11053 if (CHARPOS (tlbufpos
) > BEGV
11054 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11055 && (CHARPOS (tlbufpos
) == ZV
11056 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11057 /* Former continuation line has disappeared by becoming empty */
11059 else if (XFASTINT (w
->last_modified
) < MODIFF
11060 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11061 || MINI_WINDOW_P (w
))
11063 /* We have to handle the case of continuation around a
11064 wide-column character (See the comment in indent.c around
11067 For instance, in the following case:
11069 -------- Insert --------
11070 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11071 J_I_ ==> J_I_ `^^' are cursors.
11075 As we have to redraw the line above, we should goto cancel. */
11078 int line_height_before
= this_line_pixel_height
;
11080 /* Note that start_display will handle the case that the
11081 line starting at tlbufpos is a continuation lines. */
11082 start_display (&it
, w
, tlbufpos
);
11084 /* Implementation note: It this still necessary? */
11085 if (it
.current_x
!= this_line_start_x
)
11088 TRACE ((stderr
, "trying display optimization 1\n"));
11089 w
->cursor
.vpos
= -1;
11090 overlay_arrow_seen
= 0;
11091 it
.vpos
= this_line_vpos
;
11092 it
.current_y
= this_line_y
;
11093 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11094 display_line (&it
);
11096 /* If line contains point, is not continued,
11097 and ends at same distance from eob as before, we win */
11098 if (w
->cursor
.vpos
>= 0
11099 /* Line is not continued, otherwise this_line_start_pos
11100 would have been set to 0 in display_line. */
11101 && CHARPOS (this_line_start_pos
)
11102 /* Line ends as before. */
11103 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11104 /* Line has same height as before. Otherwise other lines
11105 would have to be shifted up or down. */
11106 && this_line_pixel_height
== line_height_before
)
11108 /* If this is not the window's last line, we must adjust
11109 the charstarts of the lines below. */
11110 if (it
.current_y
< it
.last_visible_y
)
11112 struct glyph_row
*row
11113 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11114 int delta
, delta_bytes
;
11116 if (Z
- CHARPOS (tlendpos
) == ZV
)
11118 /* This line ends at end of (accessible part of)
11119 buffer. There is no newline to count. */
11121 - CHARPOS (tlendpos
)
11122 - MATRIX_ROW_START_CHARPOS (row
));
11123 delta_bytes
= (Z_BYTE
11124 - BYTEPOS (tlendpos
)
11125 - MATRIX_ROW_START_BYTEPOS (row
));
11129 /* This line ends in a newline. Must take
11130 account of the newline and the rest of the
11131 text that follows. */
11133 - CHARPOS (tlendpos
)
11134 - MATRIX_ROW_START_CHARPOS (row
));
11135 delta_bytes
= (Z_BYTE
11136 - BYTEPOS (tlendpos
)
11137 - MATRIX_ROW_START_BYTEPOS (row
));
11140 increment_matrix_positions (w
->current_matrix
,
11141 this_line_vpos
+ 1,
11142 w
->current_matrix
->nrows
,
11143 delta
, delta_bytes
);
11146 /* If this row displays text now but previously didn't,
11147 or vice versa, w->window_end_vpos may have to be
11149 if ((it
.glyph_row
- 1)->displays_text_p
)
11151 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11152 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11154 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11155 && this_line_vpos
> 0)
11156 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11157 w
->window_end_valid
= Qnil
;
11159 /* Update hint: No need to try to scroll in update_window. */
11160 w
->desired_matrix
->no_scrolling_p
= 1;
11163 *w
->desired_matrix
->method
= 0;
11164 debug_method_add (w
, "optimization 1");
11166 #ifdef HAVE_WINDOW_SYSTEM
11167 update_window_fringes (w
, 0);
11174 else if (/* Cursor position hasn't changed. */
11175 PT
== XFASTINT (w
->last_point
)
11176 /* Make sure the cursor was last displayed
11177 in this window. Otherwise we have to reposition it. */
11178 && 0 <= w
->cursor
.vpos
11179 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11183 do_pending_window_change (1);
11185 /* We used to always goto end_of_redisplay here, but this
11186 isn't enough if we have a blinking cursor. */
11187 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11188 goto end_of_redisplay
;
11192 /* If highlighting the region, or if the cursor is in the echo area,
11193 then we can't just move the cursor. */
11194 else if (! (!NILP (Vtransient_mark_mode
)
11195 && !NILP (current_buffer
->mark_active
))
11196 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11197 || highlight_nonselected_windows
)
11198 && NILP (w
->region_showing
)
11199 && NILP (Vshow_trailing_whitespace
)
11200 && !cursor_in_echo_area
)
11203 struct glyph_row
*row
;
11205 /* Skip from tlbufpos to PT and see where it is. Note that
11206 PT may be in invisible text. If so, we will end at the
11207 next visible position. */
11208 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11209 NULL
, DEFAULT_FACE_ID
);
11210 it
.current_x
= this_line_start_x
;
11211 it
.current_y
= this_line_y
;
11212 it
.vpos
= this_line_vpos
;
11214 /* The call to move_it_to stops in front of PT, but
11215 moves over before-strings. */
11216 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11218 if (it
.vpos
== this_line_vpos
11219 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11222 xassert (this_line_vpos
== it
.vpos
);
11223 xassert (this_line_y
== it
.current_y
);
11224 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11226 *w
->desired_matrix
->method
= 0;
11227 debug_method_add (w
, "optimization 3");
11236 /* Text changed drastically or point moved off of line. */
11237 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11240 CHARPOS (this_line_start_pos
) = 0;
11241 consider_all_windows_p
|= buffer_shared
> 1;
11242 ++clear_face_cache_count
;
11243 #ifdef HAVE_WINDOW_SYSTEM
11244 ++clear_image_cache_count
;
11247 /* Build desired matrices, and update the display. If
11248 consider_all_windows_p is non-zero, do it for all windows on all
11249 frames. Otherwise do it for selected_window, only. */
11251 if (consider_all_windows_p
)
11253 Lisp_Object tail
, frame
;
11255 FOR_EACH_FRAME (tail
, frame
)
11256 XFRAME (frame
)->updated_p
= 0;
11258 /* Recompute # windows showing selected buffer. This will be
11259 incremented each time such a window is displayed. */
11262 FOR_EACH_FRAME (tail
, frame
)
11264 struct frame
*f
= XFRAME (frame
);
11266 if (FRAME_WINDOW_P (f
) || f
== sf
)
11268 if (! EQ (frame
, selected_frame
))
11269 /* Select the frame, for the sake of frame-local
11271 select_frame_for_redisplay (frame
);
11273 /* Mark all the scroll bars to be removed; we'll redeem
11274 the ones we want when we redisplay their windows. */
11275 if (condemn_scroll_bars_hook
)
11276 condemn_scroll_bars_hook (f
);
11278 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11279 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11281 /* Any scroll bars which redisplay_windows should have
11282 nuked should now go away. */
11283 if (judge_scroll_bars_hook
)
11284 judge_scroll_bars_hook (f
);
11286 /* If fonts changed, display again. */
11287 /* ??? rms: I suspect it is a mistake to jump all the way
11288 back to retry here. It should just retry this frame. */
11289 if (fonts_changed_p
)
11292 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11294 /* See if we have to hscroll. */
11295 if (!f
->already_hscrolled_p
)
11297 f
->already_hscrolled_p
= 1;
11298 if (hscroll_windows (f
->root_window
))
11302 /* Prevent various kinds of signals during display
11303 update. stdio is not robust about handling
11304 signals, which can cause an apparent I/O
11306 if (interrupt_input
)
11307 unrequest_sigio ();
11310 /* Update the display. */
11311 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11312 pause
|= update_frame (f
, 0, 0);
11313 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11325 /* Do the mark_window_display_accurate after all windows have
11326 been redisplayed because this call resets flags in buffers
11327 which are needed for proper redisplay. */
11328 FOR_EACH_FRAME (tail
, frame
)
11330 struct frame
*f
= XFRAME (frame
);
11333 mark_window_display_accurate (f
->root_window
, 1);
11334 if (frame_up_to_date_hook
)
11335 frame_up_to_date_hook (f
);
11340 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11342 Lisp_Object mini_window
;
11343 struct frame
*mini_frame
;
11345 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11346 /* Use list_of_error, not Qerror, so that
11347 we catch only errors and don't run the debugger. */
11348 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11350 redisplay_window_error
);
11352 /* Compare desired and current matrices, perform output. */
11355 /* If fonts changed, display again. */
11356 if (fonts_changed_p
)
11359 /* Prevent various kinds of signals during display update.
11360 stdio is not robust about handling signals,
11361 which can cause an apparent I/O error. */
11362 if (interrupt_input
)
11363 unrequest_sigio ();
11366 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11368 if (hscroll_windows (selected_window
))
11371 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11372 pause
= update_frame (sf
, 0, 0);
11375 /* We may have called echo_area_display at the top of this
11376 function. If the echo area is on another frame, that may
11377 have put text on a frame other than the selected one, so the
11378 above call to update_frame would not have caught it. Catch
11380 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11381 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11383 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11385 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11386 pause
|= update_frame (mini_frame
, 0, 0);
11387 if (!pause
&& hscroll_windows (mini_window
))
11392 /* If display was paused because of pending input, make sure we do a
11393 thorough update the next time. */
11396 /* Prevent the optimization at the beginning of
11397 redisplay_internal that tries a single-line update of the
11398 line containing the cursor in the selected window. */
11399 CHARPOS (this_line_start_pos
) = 0;
11401 /* Let the overlay arrow be updated the next time. */
11402 update_overlay_arrows (0);
11404 /* If we pause after scrolling, some rows in the current
11405 matrices of some windows are not valid. */
11406 if (!WINDOW_FULL_WIDTH_P (w
)
11407 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11408 update_mode_lines
= 1;
11412 if (!consider_all_windows_p
)
11414 /* This has already been done above if
11415 consider_all_windows_p is set. */
11416 mark_window_display_accurate_1 (w
, 1);
11418 /* Say overlay arrows are up to date. */
11419 update_overlay_arrows (1);
11421 if (frame_up_to_date_hook
!= 0)
11422 frame_up_to_date_hook (sf
);
11425 update_mode_lines
= 0;
11426 windows_or_buffers_changed
= 0;
11427 cursor_type_changed
= 0;
11430 /* Start SIGIO interrupts coming again. Having them off during the
11431 code above makes it less likely one will discard output, but not
11432 impossible, since there might be stuff in the system buffer here.
11433 But it is much hairier to try to do anything about that. */
11434 if (interrupt_input
)
11438 /* If a frame has become visible which was not before, redisplay
11439 again, so that we display it. Expose events for such a frame
11440 (which it gets when becoming visible) don't call the parts of
11441 redisplay constructing glyphs, so simply exposing a frame won't
11442 display anything in this case. So, we have to display these
11443 frames here explicitly. */
11446 Lisp_Object tail
, frame
;
11449 FOR_EACH_FRAME (tail
, frame
)
11451 int this_is_visible
= 0;
11453 if (XFRAME (frame
)->visible
)
11454 this_is_visible
= 1;
11455 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11456 if (XFRAME (frame
)->visible
)
11457 this_is_visible
= 1;
11459 if (this_is_visible
)
11463 if (new_count
!= number_of_visible_frames
)
11464 windows_or_buffers_changed
++;
11467 /* Change frame size now if a change is pending. */
11468 do_pending_window_change (1);
11470 /* If we just did a pending size change, or have additional
11471 visible frames, redisplay again. */
11472 if (windows_or_buffers_changed
&& !pause
)
11475 /* Clear the face cache eventually. */
11476 if (consider_all_windows_p
)
11478 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11480 clear_face_cache (0);
11481 clear_face_cache_count
= 0;
11483 #ifdef HAVE_WINDOW_SYSTEM
11484 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11486 Lisp_Object tail
, frame
;
11487 FOR_EACH_FRAME (tail
, frame
)
11489 struct frame
*f
= XFRAME (frame
);
11490 if (FRAME_WINDOW_P (f
))
11491 clear_image_cache (f
, 0);
11493 clear_image_cache_count
= 0;
11495 #endif /* HAVE_WINDOW_SYSTEM */
11499 unbind_to (count
, Qnil
);
11504 /* Redisplay, but leave alone any recent echo area message unless
11505 another message has been requested in its place.
11507 This is useful in situations where you need to redisplay but no
11508 user action has occurred, making it inappropriate for the message
11509 area to be cleared. See tracking_off and
11510 wait_reading_process_output for examples of these situations.
11512 FROM_WHERE is an integer saying from where this function was
11513 called. This is useful for debugging. */
11516 redisplay_preserve_echo_area (from_where
)
11519 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11521 if (!NILP (echo_area_buffer
[1]))
11523 /* We have a previously displayed message, but no current
11524 message. Redisplay the previous message. */
11525 display_last_displayed_message_p
= 1;
11526 redisplay_internal (1);
11527 display_last_displayed_message_p
= 0;
11530 redisplay_internal (1);
11532 if (rif
!= NULL
&& rif
->flush_display_optional
)
11533 rif
->flush_display_optional (NULL
);
11537 /* Function registered with record_unwind_protect in
11538 redisplay_internal. Reset redisplaying_p to the value it had
11539 before redisplay_internal was called, and clear
11540 prevent_freeing_realized_faces_p. It also selects the previously
11544 unwind_redisplay (val
)
11547 Lisp_Object old_redisplaying_p
, old_frame
;
11549 old_redisplaying_p
= XCAR (val
);
11550 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11551 old_frame
= XCDR (val
);
11552 if (! EQ (old_frame
, selected_frame
))
11553 select_frame_for_redisplay (old_frame
);
11558 /* Mark the display of window W as accurate or inaccurate. If
11559 ACCURATE_P is non-zero mark display of W as accurate. If
11560 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11561 redisplay_internal is called. */
11564 mark_window_display_accurate_1 (w
, accurate_p
)
11568 if (BUFFERP (w
->buffer
))
11570 struct buffer
*b
= XBUFFER (w
->buffer
);
11573 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11574 w
->last_overlay_modified
11575 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11577 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11581 b
->clip_changed
= 0;
11582 b
->prevent_redisplay_optimizations_p
= 0;
11584 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11585 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11586 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11587 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11589 w
->current_matrix
->buffer
= b
;
11590 w
->current_matrix
->begv
= BUF_BEGV (b
);
11591 w
->current_matrix
->zv
= BUF_ZV (b
);
11593 w
->last_cursor
= w
->cursor
;
11594 w
->last_cursor_off_p
= w
->cursor_off_p
;
11596 if (w
== XWINDOW (selected_window
))
11597 w
->last_point
= make_number (BUF_PT (b
));
11599 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11605 w
->window_end_valid
= w
->buffer
;
11606 #if 0 /* This is incorrect with variable-height lines. */
11607 xassert (XINT (w
->window_end_vpos
)
11608 < (WINDOW_TOTAL_LINES (w
)
11609 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11611 w
->update_mode_line
= Qnil
;
11616 /* Mark the display of windows in the window tree rooted at WINDOW as
11617 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11618 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11619 be redisplayed the next time redisplay_internal is called. */
11622 mark_window_display_accurate (window
, accurate_p
)
11623 Lisp_Object window
;
11628 for (; !NILP (window
); window
= w
->next
)
11630 w
= XWINDOW (window
);
11631 mark_window_display_accurate_1 (w
, accurate_p
);
11633 if (!NILP (w
->vchild
))
11634 mark_window_display_accurate (w
->vchild
, accurate_p
);
11635 if (!NILP (w
->hchild
))
11636 mark_window_display_accurate (w
->hchild
, accurate_p
);
11641 update_overlay_arrows (1);
11645 /* Force a thorough redisplay the next time by setting
11646 last_arrow_position and last_arrow_string to t, which is
11647 unequal to any useful value of Voverlay_arrow_... */
11648 update_overlay_arrows (-1);
11653 /* Return value in display table DP (Lisp_Char_Table *) for character
11654 C. Since a display table doesn't have any parent, we don't have to
11655 follow parent. Do not call this function directly but use the
11656 macro DISP_CHAR_VECTOR. */
11659 disp_char_vector (dp
, c
)
11660 struct Lisp_Char_Table
*dp
;
11666 if (SINGLE_BYTE_CHAR_P (c
))
11667 return (dp
->contents
[c
]);
11669 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11672 else if (code
[2] < 32)
11675 /* Here, the possible range of code[0] (== charset ID) is
11676 128..max_charset. Since the top level char table contains data
11677 for multibyte characters after 256th element, we must increment
11678 code[0] by 128 to get a correct index. */
11680 code
[3] = -1; /* anchor */
11682 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11684 val
= dp
->contents
[code
[i
]];
11685 if (!SUB_CHAR_TABLE_P (val
))
11686 return (NILP (val
) ? dp
->defalt
: val
);
11689 /* Here, val is a sub char table. We return the default value of
11691 return (dp
->defalt
);
11696 /***********************************************************************
11698 ***********************************************************************/
11700 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11703 redisplay_windows (window
)
11704 Lisp_Object window
;
11706 while (!NILP (window
))
11708 struct window
*w
= XWINDOW (window
);
11710 if (!NILP (w
->hchild
))
11711 redisplay_windows (w
->hchild
);
11712 else if (!NILP (w
->vchild
))
11713 redisplay_windows (w
->vchild
);
11716 displayed_buffer
= XBUFFER (w
->buffer
);
11717 /* Use list_of_error, not Qerror, so that
11718 we catch only errors and don't run the debugger. */
11719 internal_condition_case_1 (redisplay_window_0
, window
,
11721 redisplay_window_error
);
11729 redisplay_window_error ()
11731 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11736 redisplay_window_0 (window
)
11737 Lisp_Object window
;
11739 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11740 redisplay_window (window
, 0);
11745 redisplay_window_1 (window
)
11746 Lisp_Object window
;
11748 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11749 redisplay_window (window
, 1);
11754 /* Increment GLYPH until it reaches END or CONDITION fails while
11755 adding (GLYPH)->pixel_width to X. */
11757 #define SKIP_GLYPHS(glyph, end, x, condition) \
11760 (x) += (glyph)->pixel_width; \
11763 while ((glyph) < (end) && (condition))
11766 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11767 DELTA is the number of bytes by which positions recorded in ROW
11768 differ from current buffer positions.
11770 Return 0 if cursor is not on this row. 1 otherwise. */
11773 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11775 struct glyph_row
*row
;
11776 struct glyph_matrix
*matrix
;
11777 int delta
, delta_bytes
, dy
, dvpos
;
11779 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11780 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11781 struct glyph
*cursor
= NULL
;
11782 /* The first glyph that starts a sequence of glyphs from string. */
11783 struct glyph
*string_start
;
11784 /* The X coordinate of string_start. */
11785 int string_start_x
;
11786 /* The last known character position. */
11787 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11788 /* The last known character position before string_start. */
11789 int string_before_pos
;
11792 int cursor_from_overlay_pos
= 0;
11793 int pt_old
= PT
- delta
;
11795 /* Skip over glyphs not having an object at the start of the row.
11796 These are special glyphs like truncation marks on terminal
11798 if (row
->displays_text_p
)
11800 && INTEGERP (glyph
->object
)
11801 && glyph
->charpos
< 0)
11803 x
+= glyph
->pixel_width
;
11807 string_start
= NULL
;
11809 && !INTEGERP (glyph
->object
)
11810 && (!BUFFERP (glyph
->object
)
11811 || (last_pos
= glyph
->charpos
) < pt_old
))
11813 if (! STRINGP (glyph
->object
))
11815 string_start
= NULL
;
11816 x
+= glyph
->pixel_width
;
11818 if (cursor_from_overlay_pos
11819 && last_pos
>= cursor_from_overlay_pos
)
11821 cursor_from_overlay_pos
= 0;
11827 if (string_start
== NULL
)
11829 string_before_pos
= last_pos
;
11830 string_start
= glyph
;
11831 string_start_x
= x
;
11833 /* Skip all glyphs from string. */
11838 if ((cursor
== NULL
|| glyph
> cursor
)
11839 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11840 Qcursor
, (glyph
)->object
),
11842 && (pos
= string_buffer_position (w
, glyph
->object
,
11843 string_before_pos
),
11844 (pos
== 0 /* From overlay */
11845 || pos
== pt_old
)))
11847 /* Estimate overlay buffer position from the buffer
11848 positions of the glyphs before and after the overlay.
11849 Add 1 to last_pos so that if point corresponds to the
11850 glyph right after the overlay, we still use a 'cursor'
11851 property found in that overlay. */
11852 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11853 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11857 x
+= glyph
->pixel_width
;
11860 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11864 if (cursor
!= NULL
)
11869 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11871 /* Scan back over the ellipsis glyphs, decrementing positions. */
11872 while (glyph
> row
->glyphs
[TEXT_AREA
]
11873 && (glyph
- 1)->charpos
== last_pos
)
11874 glyph
--, x
-= glyph
->pixel_width
;
11875 /* That loop always goes one position too far,
11876 including the glyph before the ellipsis.
11877 So scan forward over that one. */
11878 x
+= glyph
->pixel_width
;
11881 else if (string_start
11882 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11884 /* We may have skipped over point because the previous glyphs
11885 are from string. As there's no easy way to know the
11886 character position of the current glyph, find the correct
11887 glyph on point by scanning from string_start again. */
11889 Lisp_Object string
;
11890 struct glyph
*stop
= glyph
;
11893 limit
= make_number (pt_old
+ 1);
11894 glyph
= string_start
;
11895 x
= string_start_x
;
11896 string
= glyph
->object
;
11897 pos
= string_buffer_position (w
, string
, string_before_pos
);
11898 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11899 because we always put cursor after overlay strings. */
11900 while (pos
== 0 && glyph
< stop
)
11902 string
= glyph
->object
;
11903 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11905 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11908 while (glyph
< stop
)
11910 pos
= XINT (Fnext_single_char_property_change
11911 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11914 /* Skip glyphs from the same string. */
11915 string
= glyph
->object
;
11916 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11917 /* Skip glyphs from an overlay. */
11918 while (glyph
< stop
11919 && ! string_buffer_position (w
, glyph
->object
, pos
))
11921 string
= glyph
->object
;
11922 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11926 /* If we reached the end of the line, and end was from a string,
11927 cursor is not on this line. */
11928 if (glyph
== end
&& row
->continued_p
)
11932 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11934 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11935 w
->cursor
.y
= row
->y
+ dy
;
11937 if (w
== XWINDOW (selected_window
))
11939 if (!row
->continued_p
11940 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11943 this_line_buffer
= XBUFFER (w
->buffer
);
11945 CHARPOS (this_line_start_pos
)
11946 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11947 BYTEPOS (this_line_start_pos
)
11948 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11950 CHARPOS (this_line_end_pos
)
11951 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11952 BYTEPOS (this_line_end_pos
)
11953 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11955 this_line_y
= w
->cursor
.y
;
11956 this_line_pixel_height
= row
->height
;
11957 this_line_vpos
= w
->cursor
.vpos
;
11958 this_line_start_x
= row
->x
;
11961 CHARPOS (this_line_start_pos
) = 0;
11968 /* Run window scroll functions, if any, for WINDOW with new window
11969 start STARTP. Sets the window start of WINDOW to that position.
11971 We assume that the window's buffer is really current. */
11973 static INLINE
struct text_pos
11974 run_window_scroll_functions (window
, startp
)
11975 Lisp_Object window
;
11976 struct text_pos startp
;
11978 struct window
*w
= XWINDOW (window
);
11979 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11981 if (current_buffer
!= XBUFFER (w
->buffer
))
11984 if (!NILP (Vwindow_scroll_functions
))
11986 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11987 make_number (CHARPOS (startp
)));
11988 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11989 /* In case the hook functions switch buffers. */
11990 if (current_buffer
!= XBUFFER (w
->buffer
))
11991 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11998 /* Make sure the line containing the cursor is fully visible.
11999 A value of 1 means there is nothing to be done.
12000 (Either the line is fully visible, or it cannot be made so,
12001 or we cannot tell.)
12003 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12004 is higher than window.
12006 A value of 0 means the caller should do scrolling
12007 as if point had gone off the screen. */
12010 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12013 int current_matrix_p
;
12015 struct glyph_matrix
*matrix
;
12016 struct glyph_row
*row
;
12019 if (!make_cursor_line_fully_visible_p
)
12022 /* It's not always possible to find the cursor, e.g, when a window
12023 is full of overlay strings. Don't do anything in that case. */
12024 if (w
->cursor
.vpos
< 0)
12027 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12028 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12030 /* If the cursor row is not partially visible, there's nothing to do. */
12031 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12034 /* If the row the cursor is in is taller than the window's height,
12035 it's not clear what to do, so do nothing. */
12036 window_height
= window_box_height (w
);
12037 if (row
->height
>= window_height
)
12039 if (!force_p
|| MINI_WINDOW_P (w
)
12040 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12046 /* This code used to try to scroll the window just enough to make
12047 the line visible. It returned 0 to say that the caller should
12048 allocate larger glyph matrices. */
12050 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12052 int dy
= row
->height
- row
->visible_height
;
12055 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12057 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12059 int dy
= - (row
->height
- row
->visible_height
);
12062 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12065 /* When we change the cursor y-position of the selected window,
12066 change this_line_y as well so that the display optimization for
12067 the cursor line of the selected window in redisplay_internal uses
12068 the correct y-position. */
12069 if (w
== XWINDOW (selected_window
))
12070 this_line_y
= w
->cursor
.y
;
12072 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12073 redisplay with larger matrices. */
12074 if (matrix
->nrows
< required_matrix_height (w
))
12076 fonts_changed_p
= 1;
12085 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12086 non-zero means only WINDOW is redisplayed in redisplay_internal.
12087 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12088 in redisplay_window to bring a partially visible line into view in
12089 the case that only the cursor has moved.
12091 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12092 last screen line's vertical height extends past the end of the screen.
12096 1 if scrolling succeeded
12098 0 if scrolling didn't find point.
12100 -1 if new fonts have been loaded so that we must interrupt
12101 redisplay, adjust glyph matrices, and try again. */
12107 SCROLLING_NEED_LARGER_MATRICES
12111 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12112 scroll_step
, temp_scroll_step
, last_line_misfit
)
12113 Lisp_Object window
;
12114 int just_this_one_p
;
12115 EMACS_INT scroll_conservatively
, scroll_step
;
12116 int temp_scroll_step
;
12117 int last_line_misfit
;
12119 struct window
*w
= XWINDOW (window
);
12120 struct frame
*f
= XFRAME (w
->frame
);
12121 struct text_pos scroll_margin_pos
;
12122 struct text_pos pos
;
12123 struct text_pos startp
;
12125 Lisp_Object window_end
;
12126 int this_scroll_margin
;
12130 int amount_to_scroll
= 0;
12131 Lisp_Object aggressive
;
12133 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12136 debug_method_add (w
, "try_scrolling");
12139 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12141 /* Compute scroll margin height in pixels. We scroll when point is
12142 within this distance from the top or bottom of the window. */
12143 if (scroll_margin
> 0)
12145 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12146 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12149 this_scroll_margin
= 0;
12151 /* Force scroll_conservatively to have a reasonable value so it doesn't
12152 cause an overflow while computing how much to scroll. */
12153 if (scroll_conservatively
)
12154 scroll_conservatively
= min (scroll_conservatively
,
12155 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12157 /* Compute how much we should try to scroll maximally to bring point
12159 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12160 scroll_max
= max (scroll_step
,
12161 max (scroll_conservatively
, temp_scroll_step
));
12162 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12163 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12164 /* We're trying to scroll because of aggressive scrolling
12165 but no scroll_step is set. Choose an arbitrary one. Maybe
12166 there should be a variable for this. */
12170 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12172 /* Decide whether we have to scroll down. Start at the window end
12173 and move this_scroll_margin up to find the position of the scroll
12175 window_end
= Fwindow_end (window
, Qt
);
12179 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12180 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12182 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12184 start_display (&it
, w
, scroll_margin_pos
);
12185 if (this_scroll_margin
)
12186 move_it_vertically_backward (&it
, this_scroll_margin
);
12187 if (extra_scroll_margin_lines
)
12188 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12189 scroll_margin_pos
= it
.current
.pos
;
12192 if (PT
>= CHARPOS (scroll_margin_pos
))
12196 /* Point is in the scroll margin at the bottom of the window, or
12197 below. Compute a new window start that makes point visible. */
12199 /* Compute the distance from the scroll margin to PT.
12200 Give up if the distance is greater than scroll_max. */
12201 start_display (&it
, w
, scroll_margin_pos
);
12203 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12204 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12206 /* To make point visible, we have to move the window start
12207 down so that the line the cursor is in is visible, which
12208 means we have to add in the height of the cursor line. */
12209 dy
= line_bottom_y (&it
) - y0
;
12211 if (dy
> scroll_max
)
12212 return SCROLLING_FAILED
;
12214 /* Move the window start down. If scrolling conservatively,
12215 move it just enough down to make point visible. If
12216 scroll_step is set, move it down by scroll_step. */
12217 start_display (&it
, w
, startp
);
12219 if (scroll_conservatively
)
12220 /* Set AMOUNT_TO_SCROLL to at least one line,
12221 and at most scroll_conservatively lines. */
12223 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12224 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12225 else if (scroll_step
|| temp_scroll_step
)
12226 amount_to_scroll
= scroll_max
;
12229 aggressive
= current_buffer
->scroll_up_aggressively
;
12230 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12231 if (NUMBERP (aggressive
))
12233 double float_amount
= XFLOATINT (aggressive
) * height
;
12234 amount_to_scroll
= float_amount
;
12235 if (amount_to_scroll
== 0 && float_amount
> 0)
12236 amount_to_scroll
= 1;
12240 if (amount_to_scroll
<= 0)
12241 return SCROLLING_FAILED
;
12243 /* If moving by amount_to_scroll leaves STARTP unchanged,
12244 move it down one screen line. */
12246 move_it_vertically (&it
, amount_to_scroll
);
12247 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12248 move_it_by_lines (&it
, 1, 1);
12249 startp
= it
.current
.pos
;
12253 /* See if point is inside the scroll margin at the top of the
12255 scroll_margin_pos
= startp
;
12256 if (this_scroll_margin
)
12258 start_display (&it
, w
, startp
);
12259 move_it_vertically (&it
, this_scroll_margin
);
12260 scroll_margin_pos
= it
.current
.pos
;
12263 if (PT
< CHARPOS (scroll_margin_pos
))
12265 /* Point is in the scroll margin at the top of the window or
12266 above what is displayed in the window. */
12269 /* Compute the vertical distance from PT to the scroll
12270 margin position. Give up if distance is greater than
12272 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12273 start_display (&it
, w
, pos
);
12275 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12276 it
.last_visible_y
, -1,
12277 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12278 dy
= it
.current_y
- y0
;
12279 if (dy
> scroll_max
)
12280 return SCROLLING_FAILED
;
12282 /* Compute new window start. */
12283 start_display (&it
, w
, startp
);
12285 if (scroll_conservatively
)
12287 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12288 else if (scroll_step
|| temp_scroll_step
)
12289 amount_to_scroll
= scroll_max
;
12292 aggressive
= current_buffer
->scroll_down_aggressively
;
12293 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12294 if (NUMBERP (aggressive
))
12296 double float_amount
= XFLOATINT (aggressive
) * height
;
12297 amount_to_scroll
= float_amount
;
12298 if (amount_to_scroll
== 0 && float_amount
> 0)
12299 amount_to_scroll
= 1;
12303 if (amount_to_scroll
<= 0)
12304 return SCROLLING_FAILED
;
12306 move_it_vertically_backward (&it
, amount_to_scroll
);
12307 startp
= it
.current
.pos
;
12311 /* Run window scroll functions. */
12312 startp
= run_window_scroll_functions (window
, startp
);
12314 /* Display the window. Give up if new fonts are loaded, or if point
12316 if (!try_window (window
, startp
, 0))
12317 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12318 else if (w
->cursor
.vpos
< 0)
12320 clear_glyph_matrix (w
->desired_matrix
);
12321 rc
= SCROLLING_FAILED
;
12325 /* Maybe forget recorded base line for line number display. */
12326 if (!just_this_one_p
12327 || current_buffer
->clip_changed
12328 || BEG_UNCHANGED
< CHARPOS (startp
))
12329 w
->base_line_number
= Qnil
;
12331 /* If cursor ends up on a partially visible line,
12332 treat that as being off the bottom of the screen. */
12333 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12335 clear_glyph_matrix (w
->desired_matrix
);
12336 ++extra_scroll_margin_lines
;
12339 rc
= SCROLLING_SUCCESS
;
12346 /* Compute a suitable window start for window W if display of W starts
12347 on a continuation line. Value is non-zero if a new window start
12350 The new window start will be computed, based on W's width, starting
12351 from the start of the continued line. It is the start of the
12352 screen line with the minimum distance from the old start W->start. */
12355 compute_window_start_on_continuation_line (w
)
12358 struct text_pos pos
, start_pos
;
12359 int window_start_changed_p
= 0;
12361 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12363 /* If window start is on a continuation line... Window start may be
12364 < BEGV in case there's invisible text at the start of the
12365 buffer (M-x rmail, for example). */
12366 if (CHARPOS (start_pos
) > BEGV
12367 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12370 struct glyph_row
*row
;
12372 /* Handle the case that the window start is out of range. */
12373 if (CHARPOS (start_pos
) < BEGV
)
12374 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12375 else if (CHARPOS (start_pos
) > ZV
)
12376 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12378 /* Find the start of the continued line. This should be fast
12379 because scan_buffer is fast (newline cache). */
12380 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12381 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12382 row
, DEFAULT_FACE_ID
);
12383 reseat_at_previous_visible_line_start (&it
);
12385 /* If the line start is "too far" away from the window start,
12386 say it takes too much time to compute a new window start. */
12387 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12388 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12390 int min_distance
, distance
;
12392 /* Move forward by display lines to find the new window
12393 start. If window width was enlarged, the new start can
12394 be expected to be > the old start. If window width was
12395 decreased, the new window start will be < the old start.
12396 So, we're looking for the display line start with the
12397 minimum distance from the old window start. */
12398 pos
= it
.current
.pos
;
12399 min_distance
= INFINITY
;
12400 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12401 distance
< min_distance
)
12403 min_distance
= distance
;
12404 pos
= it
.current
.pos
;
12405 move_it_by_lines (&it
, 1, 0);
12408 /* Set the window start there. */
12409 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12410 window_start_changed_p
= 1;
12414 return window_start_changed_p
;
12418 /* Try cursor movement in case text has not changed in window WINDOW,
12419 with window start STARTP. Value is
12421 CURSOR_MOVEMENT_SUCCESS if successful
12423 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12425 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12426 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12427 we want to scroll as if scroll-step were set to 1. See the code.
12429 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12430 which case we have to abort this redisplay, and adjust matrices
12435 CURSOR_MOVEMENT_SUCCESS
,
12436 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12437 CURSOR_MOVEMENT_MUST_SCROLL
,
12438 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12442 try_cursor_movement (window
, startp
, scroll_step
)
12443 Lisp_Object window
;
12444 struct text_pos startp
;
12447 struct window
*w
= XWINDOW (window
);
12448 struct frame
*f
= XFRAME (w
->frame
);
12449 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12452 if (inhibit_try_cursor_movement
)
12456 /* Handle case where text has not changed, only point, and it has
12457 not moved off the frame. */
12458 if (/* Point may be in this window. */
12459 PT
>= CHARPOS (startp
)
12460 /* Selective display hasn't changed. */
12461 && !current_buffer
->clip_changed
12462 /* Function force-mode-line-update is used to force a thorough
12463 redisplay. It sets either windows_or_buffers_changed or
12464 update_mode_lines. So don't take a shortcut here for these
12466 && !update_mode_lines
12467 && !windows_or_buffers_changed
12468 && !cursor_type_changed
12469 /* Can't use this case if highlighting a region. When a
12470 region exists, cursor movement has to do more than just
12472 && !(!NILP (Vtransient_mark_mode
)
12473 && !NILP (current_buffer
->mark_active
))
12474 && NILP (w
->region_showing
)
12475 && NILP (Vshow_trailing_whitespace
)
12476 /* Right after splitting windows, last_point may be nil. */
12477 && INTEGERP (w
->last_point
)
12478 /* This code is not used for mini-buffer for the sake of the case
12479 of redisplaying to replace an echo area message; since in
12480 that case the mini-buffer contents per se are usually
12481 unchanged. This code is of no real use in the mini-buffer
12482 since the handling of this_line_start_pos, etc., in redisplay
12483 handles the same cases. */
12484 && !EQ (window
, minibuf_window
)
12485 /* When splitting windows or for new windows, it happens that
12486 redisplay is called with a nil window_end_vpos or one being
12487 larger than the window. This should really be fixed in
12488 window.c. I don't have this on my list, now, so we do
12489 approximately the same as the old redisplay code. --gerd. */
12490 && INTEGERP (w
->window_end_vpos
)
12491 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12492 && (FRAME_WINDOW_P (f
)
12493 || !overlay_arrow_in_current_buffer_p ()))
12495 int this_scroll_margin
, top_scroll_margin
;
12496 struct glyph_row
*row
= NULL
;
12499 debug_method_add (w
, "cursor movement");
12502 /* Scroll if point within this distance from the top or bottom
12503 of the window. This is a pixel value. */
12504 this_scroll_margin
= max (0, scroll_margin
);
12505 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12506 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12508 top_scroll_margin
= this_scroll_margin
;
12509 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12510 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12512 /* Start with the row the cursor was displayed during the last
12513 not paused redisplay. Give up if that row is not valid. */
12514 if (w
->last_cursor
.vpos
< 0
12515 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12516 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12519 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12520 if (row
->mode_line_p
)
12522 if (!row
->enabled_p
)
12523 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12526 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12529 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12531 if (PT
> XFASTINT (w
->last_point
))
12533 /* Point has moved forward. */
12534 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12535 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12537 xassert (row
->enabled_p
);
12541 /* The end position of a row equals the start position
12542 of the next row. If PT is there, we would rather
12543 display it in the next line. */
12544 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12545 && MATRIX_ROW_END_CHARPOS (row
) == PT
12546 && !cursor_row_p (w
, row
))
12549 /* If within the scroll margin, scroll. Note that
12550 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12551 the next line would be drawn, and that
12552 this_scroll_margin can be zero. */
12553 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12554 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12555 /* Line is completely visible last line in window
12556 and PT is to be set in the next line. */
12557 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12558 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12559 && !row
->ends_at_zv_p
12560 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12563 else if (PT
< XFASTINT (w
->last_point
))
12565 /* Cursor has to be moved backward. Note that PT >=
12566 CHARPOS (startp) because of the outer if-statement. */
12567 while (!row
->mode_line_p
12568 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12569 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12570 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12571 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12572 row
> w
->current_matrix
->rows
12573 && (row
-1)->ends_in_newline_from_string_p
))))
12574 && (row
->y
> top_scroll_margin
12575 || CHARPOS (startp
) == BEGV
))
12577 xassert (row
->enabled_p
);
12581 /* Consider the following case: Window starts at BEGV,
12582 there is invisible, intangible text at BEGV, so that
12583 display starts at some point START > BEGV. It can
12584 happen that we are called with PT somewhere between
12585 BEGV and START. Try to handle that case. */
12586 if (row
< w
->current_matrix
->rows
12587 || row
->mode_line_p
)
12589 row
= w
->current_matrix
->rows
;
12590 if (row
->mode_line_p
)
12594 /* Due to newlines in overlay strings, we may have to
12595 skip forward over overlay strings. */
12596 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12597 && MATRIX_ROW_END_CHARPOS (row
) == PT
12598 && !cursor_row_p (w
, row
))
12601 /* If within the scroll margin, scroll. */
12602 if (row
->y
< top_scroll_margin
12603 && CHARPOS (startp
) != BEGV
)
12608 /* Cursor did not move. So don't scroll even if cursor line
12609 is partially visible, as it was so before. */
12610 rc
= CURSOR_MOVEMENT_SUCCESS
;
12613 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12614 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12616 /* if PT is not in the glyph row, give up. */
12617 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12619 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12620 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12621 && make_cursor_line_fully_visible_p
)
12623 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12624 && !row
->ends_at_zv_p
12625 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12626 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12627 else if (row
->height
> window_box_height (w
))
12629 /* If we end up in a partially visible line, let's
12630 make it fully visible, except when it's taller
12631 than the window, in which case we can't do much
12634 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12638 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12639 if (!cursor_row_fully_visible_p (w
, 0, 1))
12640 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12642 rc
= CURSOR_MOVEMENT_SUCCESS
;
12646 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12651 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12653 rc
= CURSOR_MOVEMENT_SUCCESS
;
12658 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12659 && MATRIX_ROW_START_CHARPOS (row
) == PT
12660 && cursor_row_p (w
, row
));
12669 set_vertical_scroll_bar (w
)
12672 int start
, end
, whole
;
12674 /* Calculate the start and end positions for the current window.
12675 At some point, it would be nice to choose between scrollbars
12676 which reflect the whole buffer size, with special markers
12677 indicating narrowing, and scrollbars which reflect only the
12680 Note that mini-buffers sometimes aren't displaying any text. */
12681 if (!MINI_WINDOW_P (w
)
12682 || (w
== XWINDOW (minibuf_window
)
12683 && NILP (echo_area_buffer
[0])))
12685 struct buffer
*buf
= XBUFFER (w
->buffer
);
12686 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12687 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12688 /* I don't think this is guaranteed to be right. For the
12689 moment, we'll pretend it is. */
12690 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12694 if (whole
< (end
- start
))
12695 whole
= end
- start
;
12698 start
= end
= whole
= 0;
12700 /* Indicate what this scroll bar ought to be displaying now. */
12701 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12705 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12706 selected_window is redisplayed.
12708 We can return without actually redisplaying the window if
12709 fonts_changed_p is nonzero. In that case, redisplay_internal will
12713 redisplay_window (window
, just_this_one_p
)
12714 Lisp_Object window
;
12715 int just_this_one_p
;
12717 struct window
*w
= XWINDOW (window
);
12718 struct frame
*f
= XFRAME (w
->frame
);
12719 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12720 struct buffer
*old
= current_buffer
;
12721 struct text_pos lpoint
, opoint
, startp
;
12722 int update_mode_line
;
12725 /* Record it now because it's overwritten. */
12726 int current_matrix_up_to_date_p
= 0;
12727 int used_current_matrix_p
= 0;
12728 /* This is less strict than current_matrix_up_to_date_p.
12729 It indictes that the buffer contents and narrowing are unchanged. */
12730 int buffer_unchanged_p
= 0;
12731 int temp_scroll_step
= 0;
12732 int count
= SPECPDL_INDEX ();
12734 int centering_position
= -1;
12735 int last_line_misfit
= 0;
12737 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12740 /* W must be a leaf window here. */
12741 xassert (!NILP (w
->buffer
));
12743 *w
->desired_matrix
->method
= 0;
12746 specbind (Qinhibit_point_motion_hooks
, Qt
);
12748 reconsider_clip_changes (w
, buffer
);
12750 /* Has the mode line to be updated? */
12751 update_mode_line
= (!NILP (w
->update_mode_line
)
12752 || update_mode_lines
12753 || buffer
->clip_changed
12754 || buffer
->prevent_redisplay_optimizations_p
);
12756 if (MINI_WINDOW_P (w
))
12758 if (w
== XWINDOW (echo_area_window
)
12759 && !NILP (echo_area_buffer
[0]))
12761 if (update_mode_line
)
12762 /* We may have to update a tty frame's menu bar or a
12763 tool-bar. Example `M-x C-h C-h C-g'. */
12764 goto finish_menu_bars
;
12766 /* We've already displayed the echo area glyphs in this window. */
12767 goto finish_scroll_bars
;
12769 else if ((w
!= XWINDOW (minibuf_window
)
12770 || minibuf_level
== 0)
12771 /* When buffer is nonempty, redisplay window normally. */
12772 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12773 /* Quail displays non-mini buffers in minibuffer window.
12774 In that case, redisplay the window normally. */
12775 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12777 /* W is a mini-buffer window, but it's not active, so clear
12779 int yb
= window_text_bottom_y (w
);
12780 struct glyph_row
*row
;
12783 for (y
= 0, row
= w
->desired_matrix
->rows
;
12785 y
+= row
->height
, ++row
)
12786 blank_row (w
, row
, y
);
12787 goto finish_scroll_bars
;
12790 clear_glyph_matrix (w
->desired_matrix
);
12793 /* Otherwise set up data on this window; select its buffer and point
12795 /* Really select the buffer, for the sake of buffer-local
12797 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12798 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12800 current_matrix_up_to_date_p
12801 = (!NILP (w
->window_end_valid
)
12802 && !current_buffer
->clip_changed
12803 && !current_buffer
->prevent_redisplay_optimizations_p
12804 && XFASTINT (w
->last_modified
) >= MODIFF
12805 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12808 = (!NILP (w
->window_end_valid
)
12809 && !current_buffer
->clip_changed
12810 && XFASTINT (w
->last_modified
) >= MODIFF
12811 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12813 /* When windows_or_buffers_changed is non-zero, we can't rely on
12814 the window end being valid, so set it to nil there. */
12815 if (windows_or_buffers_changed
)
12817 /* If window starts on a continuation line, maybe adjust the
12818 window start in case the window's width changed. */
12819 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12820 compute_window_start_on_continuation_line (w
);
12822 w
->window_end_valid
= Qnil
;
12825 /* Some sanity checks. */
12826 CHECK_WINDOW_END (w
);
12827 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12829 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12832 /* If %c is in mode line, update it if needed. */
12833 if (!NILP (w
->column_number_displayed
)
12834 /* This alternative quickly identifies a common case
12835 where no change is needed. */
12836 && !(PT
== XFASTINT (w
->last_point
)
12837 && XFASTINT (w
->last_modified
) >= MODIFF
12838 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12839 && (XFASTINT (w
->column_number_displayed
)
12840 != (int) current_column ())) /* iftc */
12841 update_mode_line
= 1;
12843 /* Count number of windows showing the selected buffer. An indirect
12844 buffer counts as its base buffer. */
12845 if (!just_this_one_p
)
12847 struct buffer
*current_base
, *window_base
;
12848 current_base
= current_buffer
;
12849 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12850 if (current_base
->base_buffer
)
12851 current_base
= current_base
->base_buffer
;
12852 if (window_base
->base_buffer
)
12853 window_base
= window_base
->base_buffer
;
12854 if (current_base
== window_base
)
12858 /* Point refers normally to the selected window. For any other
12859 window, set up appropriate value. */
12860 if (!EQ (window
, selected_window
))
12862 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12863 int new_pt_byte
= marker_byte_position (w
->pointm
);
12867 new_pt_byte
= BEGV_BYTE
;
12868 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12870 else if (new_pt
> (ZV
- 1))
12873 new_pt_byte
= ZV_BYTE
;
12874 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12877 /* We don't use SET_PT so that the point-motion hooks don't run. */
12878 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12881 /* If any of the character widths specified in the display table
12882 have changed, invalidate the width run cache. It's true that
12883 this may be a bit late to catch such changes, but the rest of
12884 redisplay goes (non-fatally) haywire when the display table is
12885 changed, so why should we worry about doing any better? */
12886 if (current_buffer
->width_run_cache
)
12888 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12890 if (! disptab_matches_widthtab (disptab
,
12891 XVECTOR (current_buffer
->width_table
)))
12893 invalidate_region_cache (current_buffer
,
12894 current_buffer
->width_run_cache
,
12896 recompute_width_table (current_buffer
, disptab
);
12900 /* If window-start is screwed up, choose a new one. */
12901 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12904 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12906 /* If someone specified a new starting point but did not insist,
12907 check whether it can be used. */
12908 if (!NILP (w
->optional_new_start
)
12909 && CHARPOS (startp
) >= BEGV
12910 && CHARPOS (startp
) <= ZV
)
12912 w
->optional_new_start
= Qnil
;
12913 start_display (&it
, w
, startp
);
12914 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12915 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12916 if (IT_CHARPOS (it
) == PT
)
12917 w
->force_start
= Qt
;
12918 /* IT may overshoot PT if text at PT is invisible. */
12919 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12920 w
->force_start
= Qt
;
12923 /* Handle case where place to start displaying has been specified,
12924 unless the specified location is outside the accessible range. */
12925 if (!NILP (w
->force_start
)
12926 || w
->frozen_window_start_p
)
12928 /* We set this later on if we have to adjust point. */
12932 w
->force_start
= Qnil
;
12934 w
->window_end_valid
= Qnil
;
12936 /* Forget any recorded base line for line number display. */
12937 if (!buffer_unchanged_p
)
12938 w
->base_line_number
= Qnil
;
12940 /* Redisplay the mode line. Select the buffer properly for that.
12941 Also, run the hook window-scroll-functions
12942 because we have scrolled. */
12943 /* Note, we do this after clearing force_start because
12944 if there's an error, it is better to forget about force_start
12945 than to get into an infinite loop calling the hook functions
12946 and having them get more errors. */
12947 if (!update_mode_line
12948 || ! NILP (Vwindow_scroll_functions
))
12950 update_mode_line
= 1;
12951 w
->update_mode_line
= Qt
;
12952 startp
= run_window_scroll_functions (window
, startp
);
12955 w
->last_modified
= make_number (0);
12956 w
->last_overlay_modified
= make_number (0);
12957 if (CHARPOS (startp
) < BEGV
)
12958 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12959 else if (CHARPOS (startp
) > ZV
)
12960 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12962 /* Redisplay, then check if cursor has been set during the
12963 redisplay. Give up if new fonts were loaded. */
12964 val
= try_window (window
, startp
, 1);
12967 w
->force_start
= Qt
;
12968 clear_glyph_matrix (w
->desired_matrix
);
12969 goto need_larger_matrices
;
12971 /* Point was outside the scroll margins. */
12973 new_vpos
= window_box_height (w
) / 2;
12975 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12977 /* If point does not appear, try to move point so it does
12978 appear. The desired matrix has been built above, so we
12979 can use it here. */
12980 new_vpos
= window_box_height (w
) / 2;
12983 if (!cursor_row_fully_visible_p (w
, 0, 0))
12985 /* Point does appear, but on a line partly visible at end of window.
12986 Move it back to a fully-visible line. */
12987 new_vpos
= window_box_height (w
);
12990 /* If we need to move point for either of the above reasons,
12991 now actually do it. */
12994 struct glyph_row
*row
;
12996 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12997 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13000 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13001 MATRIX_ROW_START_BYTEPOS (row
));
13003 if (w
!= XWINDOW (selected_window
))
13004 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13005 else if (current_buffer
== old
)
13006 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13008 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13010 /* If we are highlighting the region, then we just changed
13011 the region, so redisplay to show it. */
13012 if (!NILP (Vtransient_mark_mode
)
13013 && !NILP (current_buffer
->mark_active
))
13015 clear_glyph_matrix (w
->desired_matrix
);
13016 if (!try_window (window
, startp
, 0))
13017 goto need_larger_matrices
;
13022 debug_method_add (w
, "forced window start");
13027 /* Handle case where text has not changed, only point, and it has
13028 not moved off the frame, and we are not retrying after hscroll.
13029 (current_matrix_up_to_date_p is nonzero when retrying.) */
13030 if (current_matrix_up_to_date_p
13031 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13032 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13036 case CURSOR_MOVEMENT_SUCCESS
:
13037 used_current_matrix_p
= 1;
13040 #if 0 /* try_cursor_movement never returns this value. */
13041 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13042 goto need_larger_matrices
;
13045 case CURSOR_MOVEMENT_MUST_SCROLL
:
13046 goto try_to_scroll
;
13052 /* If current starting point was originally the beginning of a line
13053 but no longer is, find a new starting point. */
13054 else if (!NILP (w
->start_at_line_beg
)
13055 && !(CHARPOS (startp
) <= BEGV
13056 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13059 debug_method_add (w
, "recenter 1");
13064 /* Try scrolling with try_window_id. Value is > 0 if update has
13065 been done, it is -1 if we know that the same window start will
13066 not work. It is 0 if unsuccessful for some other reason. */
13067 else if ((tem
= try_window_id (w
)) != 0)
13070 debug_method_add (w
, "try_window_id %d", tem
);
13073 if (fonts_changed_p
)
13074 goto need_larger_matrices
;
13078 /* Otherwise try_window_id has returned -1 which means that we
13079 don't want the alternative below this comment to execute. */
13081 else if (CHARPOS (startp
) >= BEGV
13082 && CHARPOS (startp
) <= ZV
13083 && PT
>= CHARPOS (startp
)
13084 && (CHARPOS (startp
) < ZV
13085 /* Avoid starting at end of buffer. */
13086 || CHARPOS (startp
) == BEGV
13087 || (XFASTINT (w
->last_modified
) >= MODIFF
13088 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13091 /* If first window line is a continuation line, and window start
13092 is inside the modified region, but the first change is before
13093 current window start, we must select a new window start.*/
13094 if (NILP (w
->start_at_line_beg
)
13095 && CHARPOS (startp
) > BEGV
)
13097 /* Make sure beg_unchanged and end_unchanged are up to date.
13098 Do it only if buffer has really changed. This may or may
13099 not have been done by try_window_id (see which) already. */
13100 if (MODIFF
> SAVE_MODIFF
13101 /* This seems to happen sometimes after saving a buffer. */
13102 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13104 if (GPT
- BEG
< BEG_UNCHANGED
)
13105 BEG_UNCHANGED
= GPT
- BEG
;
13106 if (Z
- GPT
< END_UNCHANGED
)
13107 END_UNCHANGED
= Z
- GPT
;
13110 if (CHARPOS (startp
) > BEG
+ BEG_UNCHANGED
13111 && CHARPOS (startp
) <= Z
- END_UNCHANGED
)
13113 /* There doesn't seems to be a simple way to find a new
13114 window start that is near the old window start, so
13115 we just recenter. */
13121 debug_method_add (w
, "same window start");
13124 /* Try to redisplay starting at same place as before.
13125 If point has not moved off frame, accept the results. */
13126 if (!current_matrix_up_to_date_p
13127 /* Don't use try_window_reusing_current_matrix in this case
13128 because a window scroll function can have changed the
13130 || !NILP (Vwindow_scroll_functions
)
13131 || MINI_WINDOW_P (w
)
13132 || !(used_current_matrix_p
13133 = try_window_reusing_current_matrix (w
)))
13135 IF_DEBUG (debug_method_add (w
, "1"));
13136 if (try_window (window
, startp
, 1) < 0)
13137 /* -1 means we need to scroll.
13138 0 means we need new matrices, but fonts_changed_p
13139 is set in that case, so we will detect it below. */
13140 goto try_to_scroll
;
13143 if (fonts_changed_p
)
13144 goto need_larger_matrices
;
13146 if (w
->cursor
.vpos
>= 0)
13148 if (!just_this_one_p
13149 || current_buffer
->clip_changed
13150 || BEG_UNCHANGED
< CHARPOS (startp
))
13151 /* Forget any recorded base line for line number display. */
13152 w
->base_line_number
= Qnil
;
13154 if (!cursor_row_fully_visible_p (w
, 1, 0))
13156 clear_glyph_matrix (w
->desired_matrix
);
13157 last_line_misfit
= 1;
13159 /* Drop through and scroll. */
13164 clear_glyph_matrix (w
->desired_matrix
);
13169 w
->last_modified
= make_number (0);
13170 w
->last_overlay_modified
= make_number (0);
13172 /* Redisplay the mode line. Select the buffer properly for that. */
13173 if (!update_mode_line
)
13175 update_mode_line
= 1;
13176 w
->update_mode_line
= Qt
;
13179 /* Try to scroll by specified few lines. */
13180 if ((scroll_conservatively
13182 || temp_scroll_step
13183 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13184 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13185 && !current_buffer
->clip_changed
13186 && CHARPOS (startp
) >= BEGV
13187 && CHARPOS (startp
) <= ZV
)
13189 /* The function returns -1 if new fonts were loaded, 1 if
13190 successful, 0 if not successful. */
13191 int rc
= try_scrolling (window
, just_this_one_p
,
13192 scroll_conservatively
,
13194 temp_scroll_step
, last_line_misfit
);
13197 case SCROLLING_SUCCESS
:
13200 case SCROLLING_NEED_LARGER_MATRICES
:
13201 goto need_larger_matrices
;
13203 case SCROLLING_FAILED
:
13211 /* Finally, just choose place to start which centers point */
13214 if (centering_position
< 0)
13215 centering_position
= window_box_height (w
) / 2;
13218 debug_method_add (w
, "recenter");
13221 /* w->vscroll = 0; */
13223 /* Forget any previously recorded base line for line number display. */
13224 if (!buffer_unchanged_p
)
13225 w
->base_line_number
= Qnil
;
13227 /* Move backward half the height of the window. */
13228 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13229 it
.current_y
= it
.last_visible_y
;
13230 move_it_vertically_backward (&it
, centering_position
);
13231 xassert (IT_CHARPOS (it
) >= BEGV
);
13233 /* The function move_it_vertically_backward may move over more
13234 than the specified y-distance. If it->w is small, e.g. a
13235 mini-buffer window, we may end up in front of the window's
13236 display area. Start displaying at the start of the line
13237 containing PT in this case. */
13238 if (it
.current_y
<= 0)
13240 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13241 move_it_vertically_backward (&it
, 0);
13243 /* I think this assert is bogus if buffer contains
13244 invisible text or images. KFS. */
13245 xassert (IT_CHARPOS (it
) <= PT
);
13250 it
.current_x
= it
.hpos
= 0;
13252 /* Set startp here explicitly in case that helps avoid an infinite loop
13253 in case the window-scroll-functions functions get errors. */
13254 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13256 /* Run scroll hooks. */
13257 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13259 /* Redisplay the window. */
13260 if (!current_matrix_up_to_date_p
13261 || windows_or_buffers_changed
13262 || cursor_type_changed
13263 /* Don't use try_window_reusing_current_matrix in this case
13264 because it can have changed the buffer. */
13265 || !NILP (Vwindow_scroll_functions
)
13266 || !just_this_one_p
13267 || MINI_WINDOW_P (w
)
13268 || !(used_current_matrix_p
13269 = try_window_reusing_current_matrix (w
)))
13270 try_window (window
, startp
, 0);
13272 /* If new fonts have been loaded (due to fontsets), give up. We
13273 have to start a new redisplay since we need to re-adjust glyph
13275 if (fonts_changed_p
)
13276 goto need_larger_matrices
;
13278 /* If cursor did not appear assume that the middle of the window is
13279 in the first line of the window. Do it again with the next line.
13280 (Imagine a window of height 100, displaying two lines of height
13281 60. Moving back 50 from it->last_visible_y will end in the first
13283 if (w
->cursor
.vpos
< 0)
13285 if (!NILP (w
->window_end_valid
)
13286 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13288 clear_glyph_matrix (w
->desired_matrix
);
13289 move_it_by_lines (&it
, 1, 0);
13290 try_window (window
, it
.current
.pos
, 0);
13292 else if (PT
< IT_CHARPOS (it
))
13294 clear_glyph_matrix (w
->desired_matrix
);
13295 move_it_by_lines (&it
, -1, 0);
13296 try_window (window
, it
.current
.pos
, 0);
13300 /* Not much we can do about it. */
13304 /* Consider the following case: Window starts at BEGV, there is
13305 invisible, intangible text at BEGV, so that display starts at
13306 some point START > BEGV. It can happen that we are called with
13307 PT somewhere between BEGV and START. Try to handle that case. */
13308 if (w
->cursor
.vpos
< 0)
13310 struct glyph_row
*row
= w
->current_matrix
->rows
;
13311 if (row
->mode_line_p
)
13313 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13316 if (!cursor_row_fully_visible_p (w
, 0, 0))
13318 /* If vscroll is enabled, disable it and try again. */
13322 clear_glyph_matrix (w
->desired_matrix
);
13326 /* If centering point failed to make the whole line visible,
13327 put point at the top instead. That has to make the whole line
13328 visible, if it can be done. */
13329 if (centering_position
== 0)
13332 clear_glyph_matrix (w
->desired_matrix
);
13333 centering_position
= 0;
13339 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13340 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13341 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13344 /* Display the mode line, if we must. */
13345 if ((update_mode_line
13346 /* If window not full width, must redo its mode line
13347 if (a) the window to its side is being redone and
13348 (b) we do a frame-based redisplay. This is a consequence
13349 of how inverted lines are drawn in frame-based redisplay. */
13350 || (!just_this_one_p
13351 && !FRAME_WINDOW_P (f
)
13352 && !WINDOW_FULL_WIDTH_P (w
))
13353 /* Line number to display. */
13354 || INTEGERP (w
->base_line_pos
)
13355 /* Column number is displayed and different from the one displayed. */
13356 || (!NILP (w
->column_number_displayed
)
13357 && (XFASTINT (w
->column_number_displayed
)
13358 != (int) current_column ()))) /* iftc */
13359 /* This means that the window has a mode line. */
13360 && (WINDOW_WANTS_MODELINE_P (w
)
13361 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13363 display_mode_lines (w
);
13365 /* If mode line height has changed, arrange for a thorough
13366 immediate redisplay using the correct mode line height. */
13367 if (WINDOW_WANTS_MODELINE_P (w
)
13368 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13370 fonts_changed_p
= 1;
13371 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13372 = DESIRED_MODE_LINE_HEIGHT (w
);
13375 /* If top line height has changed, arrange for a thorough
13376 immediate redisplay using the correct mode line height. */
13377 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13378 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13380 fonts_changed_p
= 1;
13381 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13382 = DESIRED_HEADER_LINE_HEIGHT (w
);
13385 if (fonts_changed_p
)
13386 goto need_larger_matrices
;
13389 if (!line_number_displayed
13390 && !BUFFERP (w
->base_line_pos
))
13392 w
->base_line_pos
= Qnil
;
13393 w
->base_line_number
= Qnil
;
13398 /* When we reach a frame's selected window, redo the frame's menu bar. */
13399 if (update_mode_line
13400 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13402 int redisplay_menu_p
= 0;
13403 int redisplay_tool_bar_p
= 0;
13405 if (FRAME_WINDOW_P (f
))
13407 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13408 || defined (USE_GTK)
13409 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13411 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13415 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13417 if (redisplay_menu_p
)
13418 display_menu_bar (w
);
13420 #ifdef HAVE_WINDOW_SYSTEM
13422 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13424 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13425 && (FRAME_TOOL_BAR_LINES (f
) > 0
13426 || auto_resize_tool_bars_p
);
13430 if (redisplay_tool_bar_p
)
13431 redisplay_tool_bar (f
);
13435 #ifdef HAVE_WINDOW_SYSTEM
13436 if (FRAME_WINDOW_P (f
)
13437 && update_window_fringes (w
, (just_this_one_p
13438 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13439 || w
->pseudo_window_p
)))
13443 if (draw_window_fringes (w
, 1))
13444 x_draw_vertical_border (w
);
13448 #endif /* HAVE_WINDOW_SYSTEM */
13450 /* We go to this label, with fonts_changed_p nonzero,
13451 if it is necessary to try again using larger glyph matrices.
13452 We have to redeem the scroll bar even in this case,
13453 because the loop in redisplay_internal expects that. */
13454 need_larger_matrices
:
13456 finish_scroll_bars
:
13458 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13460 /* Set the thumb's position and size. */
13461 set_vertical_scroll_bar (w
);
13463 /* Note that we actually used the scroll bar attached to this
13464 window, so it shouldn't be deleted at the end of redisplay. */
13465 redeem_scroll_bar_hook (w
);
13468 /* Restore current_buffer and value of point in it. */
13469 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13470 set_buffer_internal_1 (old
);
13471 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13473 unbind_to (count
, Qnil
);
13477 /* Build the complete desired matrix of WINDOW with a window start
13478 buffer position POS.
13480 Value is 1 if successful. It is zero if fonts were loaded during
13481 redisplay which makes re-adjusting glyph matrices necessary, and -1
13482 if point would appear in the scroll margins.
13483 (We check that only if CHECK_MARGINS is nonzero. */
13486 try_window (window
, pos
, check_margins
)
13487 Lisp_Object window
;
13488 struct text_pos pos
;
13491 struct window
*w
= XWINDOW (window
);
13493 struct glyph_row
*last_text_row
= NULL
;
13495 /* Make POS the new window start. */
13496 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13498 /* Mark cursor position as unknown. No overlay arrow seen. */
13499 w
->cursor
.vpos
= -1;
13500 overlay_arrow_seen
= 0;
13502 /* Initialize iterator and info to start at POS. */
13503 start_display (&it
, w
, pos
);
13505 /* Display all lines of W. */
13506 while (it
.current_y
< it
.last_visible_y
)
13508 if (display_line (&it
))
13509 last_text_row
= it
.glyph_row
- 1;
13510 if (fonts_changed_p
)
13514 /* Don't let the cursor end in the scroll margins. */
13516 && !MINI_WINDOW_P (w
))
13518 int this_scroll_margin
;
13520 this_scroll_margin
= max (0, scroll_margin
);
13521 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13522 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13524 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13525 && w
->cursor
.y
< this_scroll_margin
13526 && CHARPOS (pos
) > BEGV
13527 && IT_CHARPOS (it
) < ZV
)
13528 /* rms: considering make_cursor_line_fully_visible_p here
13529 seems to give wrong results. We don't want to recenter
13530 when the last line is partly visible, we want to allow
13531 that case to be handled in the usual way. */
13532 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13534 w
->cursor
.vpos
= -1;
13535 clear_glyph_matrix (w
->desired_matrix
);
13540 /* If bottom moved off end of frame, change mode line percentage. */
13541 if (XFASTINT (w
->window_end_pos
) <= 0
13542 && Z
!= IT_CHARPOS (it
))
13543 w
->update_mode_line
= Qt
;
13545 /* Set window_end_pos to the offset of the last character displayed
13546 on the window from the end of current_buffer. Set
13547 window_end_vpos to its row number. */
13550 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13551 w
->window_end_bytepos
13552 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13554 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13556 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13557 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13558 ->displays_text_p
);
13562 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13563 w
->window_end_pos
= make_number (Z
- ZV
);
13564 w
->window_end_vpos
= make_number (0);
13567 /* But that is not valid info until redisplay finishes. */
13568 w
->window_end_valid
= Qnil
;
13574 /************************************************************************
13575 Window redisplay reusing current matrix when buffer has not changed
13576 ************************************************************************/
13578 /* Try redisplay of window W showing an unchanged buffer with a
13579 different window start than the last time it was displayed by
13580 reusing its current matrix. Value is non-zero if successful.
13581 W->start is the new window start. */
13584 try_window_reusing_current_matrix (w
)
13587 struct frame
*f
= XFRAME (w
->frame
);
13588 struct glyph_row
*row
, *bottom_row
;
13591 struct text_pos start
, new_start
;
13592 int nrows_scrolled
, i
;
13593 struct glyph_row
*last_text_row
;
13594 struct glyph_row
*last_reused_text_row
;
13595 struct glyph_row
*start_row
;
13596 int start_vpos
, min_y
, max_y
;
13599 if (inhibit_try_window_reusing
)
13603 if (/* This function doesn't handle terminal frames. */
13604 !FRAME_WINDOW_P (f
)
13605 /* Don't try to reuse the display if windows have been split
13607 || windows_or_buffers_changed
13608 || cursor_type_changed
)
13611 /* Can't do this if region may have changed. */
13612 if ((!NILP (Vtransient_mark_mode
)
13613 && !NILP (current_buffer
->mark_active
))
13614 || !NILP (w
->region_showing
)
13615 || !NILP (Vshow_trailing_whitespace
))
13618 /* If top-line visibility has changed, give up. */
13619 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13620 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13623 /* Give up if old or new display is scrolled vertically. We could
13624 make this function handle this, but right now it doesn't. */
13625 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13626 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13629 /* The variable new_start now holds the new window start. The old
13630 start `start' can be determined from the current matrix. */
13631 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13632 start
= start_row
->start
.pos
;
13633 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13635 /* Clear the desired matrix for the display below. */
13636 clear_glyph_matrix (w
->desired_matrix
);
13638 if (CHARPOS (new_start
) <= CHARPOS (start
))
13642 /* Don't use this method if the display starts with an ellipsis
13643 displayed for invisible text. It's not easy to handle that case
13644 below, and it's certainly not worth the effort since this is
13645 not a frequent case. */
13646 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13649 IF_DEBUG (debug_method_add (w
, "twu1"));
13651 /* Display up to a row that can be reused. The variable
13652 last_text_row is set to the last row displayed that displays
13653 text. Note that it.vpos == 0 if or if not there is a
13654 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13655 start_display (&it
, w
, new_start
);
13656 first_row_y
= it
.current_y
;
13657 w
->cursor
.vpos
= -1;
13658 last_text_row
= last_reused_text_row
= NULL
;
13660 while (it
.current_y
< it
.last_visible_y
13661 && !fonts_changed_p
)
13663 /* If we have reached into the characters in the START row,
13664 that means the line boundaries have changed. So we
13665 can't start copying with the row START. Maybe it will
13666 work to start copying with the following row. */
13667 while (IT_CHARPOS (it
) > CHARPOS (start
))
13669 /* Advance to the next row as the "start". */
13671 start
= start_row
->start
.pos
;
13672 /* If there are no more rows to try, or just one, give up. */
13673 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13674 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13675 || CHARPOS (start
) == ZV
)
13677 clear_glyph_matrix (w
->desired_matrix
);
13681 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13683 /* If we have reached alignment,
13684 we can copy the rest of the rows. */
13685 if (IT_CHARPOS (it
) == CHARPOS (start
))
13688 if (display_line (&it
))
13689 last_text_row
= it
.glyph_row
- 1;
13692 /* A value of current_y < last_visible_y means that we stopped
13693 at the previous window start, which in turn means that we
13694 have at least one reusable row. */
13695 if (it
.current_y
< it
.last_visible_y
)
13697 /* IT.vpos always starts from 0; it counts text lines. */
13698 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13700 /* Find PT if not already found in the lines displayed. */
13701 if (w
->cursor
.vpos
< 0)
13703 int dy
= it
.current_y
- start_row
->y
;
13705 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13706 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13708 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13709 dy
, nrows_scrolled
);
13712 clear_glyph_matrix (w
->desired_matrix
);
13717 /* Scroll the display. Do it before the current matrix is
13718 changed. The problem here is that update has not yet
13719 run, i.e. part of the current matrix is not up to date.
13720 scroll_run_hook will clear the cursor, and use the
13721 current matrix to get the height of the row the cursor is
13723 run
.current_y
= start_row
->y
;
13724 run
.desired_y
= it
.current_y
;
13725 run
.height
= it
.last_visible_y
- it
.current_y
;
13727 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13730 rif
->update_window_begin_hook (w
);
13731 rif
->clear_window_mouse_face (w
);
13732 rif
->scroll_run_hook (w
, &run
);
13733 rif
->update_window_end_hook (w
, 0, 0);
13737 /* Shift current matrix down by nrows_scrolled lines. */
13738 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13739 rotate_matrix (w
->current_matrix
,
13741 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13744 /* Disable lines that must be updated. */
13745 for (i
= 0; i
< it
.vpos
; ++i
)
13746 (start_row
+ i
)->enabled_p
= 0;
13748 /* Re-compute Y positions. */
13749 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13750 max_y
= it
.last_visible_y
;
13751 for (row
= start_row
+ nrows_scrolled
;
13755 row
->y
= it
.current_y
;
13756 row
->visible_height
= row
->height
;
13758 if (row
->y
< min_y
)
13759 row
->visible_height
-= min_y
- row
->y
;
13760 if (row
->y
+ row
->height
> max_y
)
13761 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13762 row
->redraw_fringe_bitmaps_p
= 1;
13764 it
.current_y
+= row
->height
;
13766 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13767 last_reused_text_row
= row
;
13768 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13772 /* Disable lines in the current matrix which are now
13773 below the window. */
13774 for (++row
; row
< bottom_row
; ++row
)
13775 row
->enabled_p
= row
->mode_line_p
= 0;
13778 /* Update window_end_pos etc.; last_reused_text_row is the last
13779 reused row from the current matrix containing text, if any.
13780 The value of last_text_row is the last displayed line
13781 containing text. */
13782 if (last_reused_text_row
)
13784 w
->window_end_bytepos
13785 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13787 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13789 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13790 w
->current_matrix
));
13792 else if (last_text_row
)
13794 w
->window_end_bytepos
13795 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13797 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13799 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13803 /* This window must be completely empty. */
13804 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13805 w
->window_end_pos
= make_number (Z
- ZV
);
13806 w
->window_end_vpos
= make_number (0);
13808 w
->window_end_valid
= Qnil
;
13810 /* Update hint: don't try scrolling again in update_window. */
13811 w
->desired_matrix
->no_scrolling_p
= 1;
13814 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13818 else if (CHARPOS (new_start
) > CHARPOS (start
))
13820 struct glyph_row
*pt_row
, *row
;
13821 struct glyph_row
*first_reusable_row
;
13822 struct glyph_row
*first_row_to_display
;
13824 int yb
= window_text_bottom_y (w
);
13826 /* Find the row starting at new_start, if there is one. Don't
13827 reuse a partially visible line at the end. */
13828 first_reusable_row
= start_row
;
13829 while (first_reusable_row
->enabled_p
13830 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13831 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13832 < CHARPOS (new_start
)))
13833 ++first_reusable_row
;
13835 /* Give up if there is no row to reuse. */
13836 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13837 || !first_reusable_row
->enabled_p
13838 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13839 != CHARPOS (new_start
)))
13842 /* We can reuse fully visible rows beginning with
13843 first_reusable_row to the end of the window. Set
13844 first_row_to_display to the first row that cannot be reused.
13845 Set pt_row to the row containing point, if there is any. */
13847 for (first_row_to_display
= first_reusable_row
;
13848 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13849 ++first_row_to_display
)
13851 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13852 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13853 pt_row
= first_row_to_display
;
13856 /* Start displaying at the start of first_row_to_display. */
13857 xassert (first_row_to_display
->y
< yb
);
13858 init_to_row_start (&it
, w
, first_row_to_display
);
13860 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13862 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13864 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13865 + WINDOW_HEADER_LINE_HEIGHT (w
));
13867 /* Display lines beginning with first_row_to_display in the
13868 desired matrix. Set last_text_row to the last row displayed
13869 that displays text. */
13870 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13871 if (pt_row
== NULL
)
13872 w
->cursor
.vpos
= -1;
13873 last_text_row
= NULL
;
13874 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13875 if (display_line (&it
))
13876 last_text_row
= it
.glyph_row
- 1;
13878 /* Give up If point isn't in a row displayed or reused. */
13879 if (w
->cursor
.vpos
< 0)
13881 clear_glyph_matrix (w
->desired_matrix
);
13885 /* If point is in a reused row, adjust y and vpos of the cursor
13889 w
->cursor
.vpos
-= nrows_scrolled
;
13890 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13893 /* Scroll the display. */
13894 run
.current_y
= first_reusable_row
->y
;
13895 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13896 run
.height
= it
.last_visible_y
- run
.current_y
;
13897 dy
= run
.current_y
- run
.desired_y
;
13902 rif
->update_window_begin_hook (w
);
13903 rif
->clear_window_mouse_face (w
);
13904 rif
->scroll_run_hook (w
, &run
);
13905 rif
->update_window_end_hook (w
, 0, 0);
13909 /* Adjust Y positions of reused rows. */
13910 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13911 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13912 max_y
= it
.last_visible_y
;
13913 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13916 row
->visible_height
= row
->height
;
13917 if (row
->y
< min_y
)
13918 row
->visible_height
-= min_y
- row
->y
;
13919 if (row
->y
+ row
->height
> max_y
)
13920 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13921 row
->redraw_fringe_bitmaps_p
= 1;
13924 /* Scroll the current matrix. */
13925 xassert (nrows_scrolled
> 0);
13926 rotate_matrix (w
->current_matrix
,
13928 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13931 /* Disable rows not reused. */
13932 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13933 row
->enabled_p
= 0;
13935 /* Point may have moved to a different line, so we cannot assume that
13936 the previous cursor position is valid; locate the correct row. */
13939 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13940 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13944 w
->cursor
.y
= row
->y
;
13946 if (row
< bottom_row
)
13948 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13949 while (glyph
->charpos
< PT
)
13952 w
->cursor
.x
+= glyph
->pixel_width
;
13958 /* Adjust window end. A null value of last_text_row means that
13959 the window end is in reused rows which in turn means that
13960 only its vpos can have changed. */
13963 w
->window_end_bytepos
13964 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13966 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13968 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13973 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13976 w
->window_end_valid
= Qnil
;
13977 w
->desired_matrix
->no_scrolling_p
= 1;
13980 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13990 /************************************************************************
13991 Window redisplay reusing current matrix when buffer has changed
13992 ************************************************************************/
13994 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13995 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13997 static struct glyph_row
*
13998 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13999 struct glyph_row
*));
14002 /* Return the last row in MATRIX displaying text. If row START is
14003 non-null, start searching with that row. IT gives the dimensions
14004 of the display. Value is null if matrix is empty; otherwise it is
14005 a pointer to the row found. */
14007 static struct glyph_row
*
14008 find_last_row_displaying_text (matrix
, it
, start
)
14009 struct glyph_matrix
*matrix
;
14011 struct glyph_row
*start
;
14013 struct glyph_row
*row
, *row_found
;
14015 /* Set row_found to the last row in IT->w's current matrix
14016 displaying text. The loop looks funny but think of partially
14019 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14020 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14022 xassert (row
->enabled_p
);
14024 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14033 /* Return the last row in the current matrix of W that is not affected
14034 by changes at the start of current_buffer that occurred since W's
14035 current matrix was built. Value is null if no such row exists.
14037 BEG_UNCHANGED us the number of characters unchanged at the start of
14038 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14039 first changed character in current_buffer. Characters at positions <
14040 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14041 when the current matrix was built. */
14043 static struct glyph_row
*
14044 find_last_unchanged_at_beg_row (w
)
14047 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14048 struct glyph_row
*row
;
14049 struct glyph_row
*row_found
= NULL
;
14050 int yb
= window_text_bottom_y (w
);
14052 /* Find the last row displaying unchanged text. */
14053 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14054 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14055 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14057 if (/* If row ends before first_changed_pos, it is unchanged,
14058 except in some case. */
14059 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14060 /* When row ends in ZV and we write at ZV it is not
14062 && !row
->ends_at_zv_p
14063 /* When first_changed_pos is the end of a continued line,
14064 row is not unchanged because it may be no longer
14066 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14067 && (row
->continued_p
14068 || row
->exact_window_width_line_p
)))
14071 /* Stop if last visible row. */
14072 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14082 /* Find the first glyph row in the current matrix of W that is not
14083 affected by changes at the end of current_buffer since the
14084 time W's current matrix was built.
14086 Return in *DELTA the number of chars by which buffer positions in
14087 unchanged text at the end of current_buffer must be adjusted.
14089 Return in *DELTA_BYTES the corresponding number of bytes.
14091 Value is null if no such row exists, i.e. all rows are affected by
14094 static struct glyph_row
*
14095 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14097 int *delta
, *delta_bytes
;
14099 struct glyph_row
*row
;
14100 struct glyph_row
*row_found
= NULL
;
14102 *delta
= *delta_bytes
= 0;
14104 /* Display must not have been paused, otherwise the current matrix
14105 is not up to date. */
14106 if (NILP (w
->window_end_valid
))
14109 /* A value of window_end_pos >= END_UNCHANGED means that the window
14110 end is in the range of changed text. If so, there is no
14111 unchanged row at the end of W's current matrix. */
14112 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14115 /* Set row to the last row in W's current matrix displaying text. */
14116 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14118 /* If matrix is entirely empty, no unchanged row exists. */
14119 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14121 /* The value of row is the last glyph row in the matrix having a
14122 meaningful buffer position in it. The end position of row
14123 corresponds to window_end_pos. This allows us to translate
14124 buffer positions in the current matrix to current buffer
14125 positions for characters not in changed text. */
14126 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14127 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14128 int last_unchanged_pos
, last_unchanged_pos_old
;
14129 struct glyph_row
*first_text_row
14130 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14132 *delta
= Z
- Z_old
;
14133 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14135 /* Set last_unchanged_pos to the buffer position of the last
14136 character in the buffer that has not been changed. Z is the
14137 index + 1 of the last character in current_buffer, i.e. by
14138 subtracting END_UNCHANGED we get the index of the last
14139 unchanged character, and we have to add BEG to get its buffer
14141 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14142 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14144 /* Search backward from ROW for a row displaying a line that
14145 starts at a minimum position >= last_unchanged_pos_old. */
14146 for (; row
> first_text_row
; --row
)
14148 /* This used to abort, but it can happen.
14149 It is ok to just stop the search instead here. KFS. */
14150 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14153 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14158 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14165 /* Make sure that glyph rows in the current matrix of window W
14166 reference the same glyph memory as corresponding rows in the
14167 frame's frame matrix. This function is called after scrolling W's
14168 current matrix on a terminal frame in try_window_id and
14169 try_window_reusing_current_matrix. */
14172 sync_frame_with_window_matrix_rows (w
)
14175 struct frame
*f
= XFRAME (w
->frame
);
14176 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14178 /* Preconditions: W must be a leaf window and full-width. Its frame
14179 must have a frame matrix. */
14180 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14181 xassert (WINDOW_FULL_WIDTH_P (w
));
14182 xassert (!FRAME_WINDOW_P (f
));
14184 /* If W is a full-width window, glyph pointers in W's current matrix
14185 have, by definition, to be the same as glyph pointers in the
14186 corresponding frame matrix. Note that frame matrices have no
14187 marginal areas (see build_frame_matrix). */
14188 window_row
= w
->current_matrix
->rows
;
14189 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14190 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14191 while (window_row
< window_row_end
)
14193 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14194 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14196 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14197 frame_row
->glyphs
[TEXT_AREA
] = start
;
14198 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14199 frame_row
->glyphs
[LAST_AREA
] = end
;
14201 /* Disable frame rows whose corresponding window rows have
14202 been disabled in try_window_id. */
14203 if (!window_row
->enabled_p
)
14204 frame_row
->enabled_p
= 0;
14206 ++window_row
, ++frame_row
;
14211 /* Find the glyph row in window W containing CHARPOS. Consider all
14212 rows between START and END (not inclusive). END null means search
14213 all rows to the end of the display area of W. Value is the row
14214 containing CHARPOS or null. */
14217 row_containing_pos (w
, charpos
, start
, end
, dy
)
14220 struct glyph_row
*start
, *end
;
14223 struct glyph_row
*row
= start
;
14226 /* If we happen to start on a header-line, skip that. */
14227 if (row
->mode_line_p
)
14230 if ((end
&& row
>= end
) || !row
->enabled_p
)
14233 last_y
= window_text_bottom_y (w
) - dy
;
14237 /* Give up if we have gone too far. */
14238 if (end
&& row
>= end
)
14240 /* This formerly returned if they were equal.
14241 I think that both quantities are of a "last plus one" type;
14242 if so, when they are equal, the row is within the screen. -- rms. */
14243 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14246 /* If it is in this row, return this row. */
14247 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14248 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14249 /* The end position of a row equals the start
14250 position of the next row. If CHARPOS is there, we
14251 would rather display it in the next line, except
14252 when this line ends in ZV. */
14253 && !row
->ends_at_zv_p
14254 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14255 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14262 /* Try to redisplay window W by reusing its existing display. W's
14263 current matrix must be up to date when this function is called,
14264 i.e. window_end_valid must not be nil.
14268 1 if display has been updated
14269 0 if otherwise unsuccessful
14270 -1 if redisplay with same window start is known not to succeed
14272 The following steps are performed:
14274 1. Find the last row in the current matrix of W that is not
14275 affected by changes at the start of current_buffer. If no such row
14278 2. Find the first row in W's current matrix that is not affected by
14279 changes at the end of current_buffer. Maybe there is no such row.
14281 3. Display lines beginning with the row + 1 found in step 1 to the
14282 row found in step 2 or, if step 2 didn't find a row, to the end of
14285 4. If cursor is not known to appear on the window, give up.
14287 5. If display stopped at the row found in step 2, scroll the
14288 display and current matrix as needed.
14290 6. Maybe display some lines at the end of W, if we must. This can
14291 happen under various circumstances, like a partially visible line
14292 becoming fully visible, or because newly displayed lines are displayed
14293 in smaller font sizes.
14295 7. Update W's window end information. */
14301 struct frame
*f
= XFRAME (w
->frame
);
14302 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14303 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14304 struct glyph_row
*last_unchanged_at_beg_row
;
14305 struct glyph_row
*first_unchanged_at_end_row
;
14306 struct glyph_row
*row
;
14307 struct glyph_row
*bottom_row
;
14310 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14311 struct text_pos start_pos
;
14313 int first_unchanged_at_end_vpos
= 0;
14314 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14315 struct text_pos start
;
14316 int first_changed_charpos
, last_changed_charpos
;
14319 if (inhibit_try_window_id
)
14323 /* This is handy for debugging. */
14325 #define GIVE_UP(X) \
14327 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14331 #define GIVE_UP(X) return 0
14334 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14336 /* Don't use this for mini-windows because these can show
14337 messages and mini-buffers, and we don't handle that here. */
14338 if (MINI_WINDOW_P (w
))
14341 /* This flag is used to prevent redisplay optimizations. */
14342 if (windows_or_buffers_changed
|| cursor_type_changed
)
14345 /* Verify that narrowing has not changed.
14346 Also verify that we were not told to prevent redisplay optimizations.
14347 It would be nice to further
14348 reduce the number of cases where this prevents try_window_id. */
14349 if (current_buffer
->clip_changed
14350 || current_buffer
->prevent_redisplay_optimizations_p
)
14353 /* Window must either use window-based redisplay or be full width. */
14354 if (!FRAME_WINDOW_P (f
)
14355 && (!line_ins_del_ok
14356 || !WINDOW_FULL_WIDTH_P (w
)))
14359 /* Give up if point is not known NOT to appear in W. */
14360 if (PT
< CHARPOS (start
))
14363 /* Another way to prevent redisplay optimizations. */
14364 if (XFASTINT (w
->last_modified
) == 0)
14367 /* Verify that window is not hscrolled. */
14368 if (XFASTINT (w
->hscroll
) != 0)
14371 /* Verify that display wasn't paused. */
14372 if (NILP (w
->window_end_valid
))
14375 /* Can't use this if highlighting a region because a cursor movement
14376 will do more than just set the cursor. */
14377 if (!NILP (Vtransient_mark_mode
)
14378 && !NILP (current_buffer
->mark_active
))
14381 /* Likewise if highlighting trailing whitespace. */
14382 if (!NILP (Vshow_trailing_whitespace
))
14385 /* Likewise if showing a region. */
14386 if (!NILP (w
->region_showing
))
14389 /* Can use this if overlay arrow position and or string have changed. */
14390 if (overlay_arrows_changed_p ())
14394 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14395 only if buffer has really changed. The reason is that the gap is
14396 initially at Z for freshly visited files. The code below would
14397 set end_unchanged to 0 in that case. */
14398 if (MODIFF
> SAVE_MODIFF
14399 /* This seems to happen sometimes after saving a buffer. */
14400 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14402 if (GPT
- BEG
< BEG_UNCHANGED
)
14403 BEG_UNCHANGED
= GPT
- BEG
;
14404 if (Z
- GPT
< END_UNCHANGED
)
14405 END_UNCHANGED
= Z
- GPT
;
14408 /* The position of the first and last character that has been changed. */
14409 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14410 last_changed_charpos
= Z
- END_UNCHANGED
;
14412 /* If window starts after a line end, and the last change is in
14413 front of that newline, then changes don't affect the display.
14414 This case happens with stealth-fontification. Note that although
14415 the display is unchanged, glyph positions in the matrix have to
14416 be adjusted, of course. */
14417 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14418 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14419 && ((last_changed_charpos
< CHARPOS (start
)
14420 && CHARPOS (start
) == BEGV
)
14421 || (last_changed_charpos
< CHARPOS (start
) - 1
14422 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14424 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14425 struct glyph_row
*r0
;
14427 /* Compute how many chars/bytes have been added to or removed
14428 from the buffer. */
14429 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14430 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14432 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14434 /* Give up if PT is not in the window. Note that it already has
14435 been checked at the start of try_window_id that PT is not in
14436 front of the window start. */
14437 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14440 /* If window start is unchanged, we can reuse the whole matrix
14441 as is, after adjusting glyph positions. No need to compute
14442 the window end again, since its offset from Z hasn't changed. */
14443 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14444 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14445 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14446 /* PT must not be in a partially visible line. */
14447 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14448 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14450 /* Adjust positions in the glyph matrix. */
14451 if (delta
|| delta_bytes
)
14453 struct glyph_row
*r1
14454 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14455 increment_matrix_positions (w
->current_matrix
,
14456 MATRIX_ROW_VPOS (r0
, current_matrix
),
14457 MATRIX_ROW_VPOS (r1
, current_matrix
),
14458 delta
, delta_bytes
);
14461 /* Set the cursor. */
14462 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14464 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14471 /* Handle the case that changes are all below what is displayed in
14472 the window, and that PT is in the window. This shortcut cannot
14473 be taken if ZV is visible in the window, and text has been added
14474 there that is visible in the window. */
14475 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14476 /* ZV is not visible in the window, or there are no
14477 changes at ZV, actually. */
14478 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14479 || first_changed_charpos
== last_changed_charpos
))
14481 struct glyph_row
*r0
;
14483 /* Give up if PT is not in the window. Note that it already has
14484 been checked at the start of try_window_id that PT is not in
14485 front of the window start. */
14486 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14489 /* If window start is unchanged, we can reuse the whole matrix
14490 as is, without changing glyph positions since no text has
14491 been added/removed in front of the window end. */
14492 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14493 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14494 /* PT must not be in a partially visible line. */
14495 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14496 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14498 /* We have to compute the window end anew since text
14499 can have been added/removed after it. */
14501 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14502 w
->window_end_bytepos
14503 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14505 /* Set the cursor. */
14506 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14508 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14515 /* Give up if window start is in the changed area.
14517 The condition used to read
14519 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14521 but why that was tested escapes me at the moment. */
14522 if (CHARPOS (start
) >= first_changed_charpos
14523 && CHARPOS (start
) <= last_changed_charpos
)
14526 /* Check that window start agrees with the start of the first glyph
14527 row in its current matrix. Check this after we know the window
14528 start is not in changed text, otherwise positions would not be
14530 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14531 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14534 /* Give up if the window ends in strings. Overlay strings
14535 at the end are difficult to handle, so don't try. */
14536 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14537 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14540 /* Compute the position at which we have to start displaying new
14541 lines. Some of the lines at the top of the window might be
14542 reusable because they are not displaying changed text. Find the
14543 last row in W's current matrix not affected by changes at the
14544 start of current_buffer. Value is null if changes start in the
14545 first line of window. */
14546 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14547 if (last_unchanged_at_beg_row
)
14549 /* Avoid starting to display in the moddle of a character, a TAB
14550 for instance. This is easier than to set up the iterator
14551 exactly, and it's not a frequent case, so the additional
14552 effort wouldn't really pay off. */
14553 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14554 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14555 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14556 --last_unchanged_at_beg_row
;
14558 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14561 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14563 start_pos
= it
.current
.pos
;
14565 /* Start displaying new lines in the desired matrix at the same
14566 vpos we would use in the current matrix, i.e. below
14567 last_unchanged_at_beg_row. */
14568 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14570 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14571 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14573 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14577 /* There are no reusable lines at the start of the window.
14578 Start displaying in the first text line. */
14579 start_display (&it
, w
, start
);
14580 it
.vpos
= it
.first_vpos
;
14581 start_pos
= it
.current
.pos
;
14584 /* Find the first row that is not affected by changes at the end of
14585 the buffer. Value will be null if there is no unchanged row, in
14586 which case we must redisplay to the end of the window. delta
14587 will be set to the value by which buffer positions beginning with
14588 first_unchanged_at_end_row have to be adjusted due to text
14590 first_unchanged_at_end_row
14591 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14592 IF_DEBUG (debug_delta
= delta
);
14593 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14595 /* Set stop_pos to the buffer position up to which we will have to
14596 display new lines. If first_unchanged_at_end_row != NULL, this
14597 is the buffer position of the start of the line displayed in that
14598 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14599 that we don't stop at a buffer position. */
14601 if (first_unchanged_at_end_row
)
14603 xassert (last_unchanged_at_beg_row
== NULL
14604 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14606 /* If this is a continuation line, move forward to the next one
14607 that isn't. Changes in lines above affect this line.
14608 Caution: this may move first_unchanged_at_end_row to a row
14609 not displaying text. */
14610 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14611 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14612 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14613 < it
.last_visible_y
))
14614 ++first_unchanged_at_end_row
;
14616 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14617 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14618 >= it
.last_visible_y
))
14619 first_unchanged_at_end_row
= NULL
;
14622 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14624 first_unchanged_at_end_vpos
14625 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14626 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14629 else if (last_unchanged_at_beg_row
== NULL
)
14635 /* Either there is no unchanged row at the end, or the one we have
14636 now displays text. This is a necessary condition for the window
14637 end pos calculation at the end of this function. */
14638 xassert (first_unchanged_at_end_row
== NULL
14639 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14641 debug_last_unchanged_at_beg_vpos
14642 = (last_unchanged_at_beg_row
14643 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14645 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14647 #endif /* GLYPH_DEBUG != 0 */
14650 /* Display new lines. Set last_text_row to the last new line
14651 displayed which has text on it, i.e. might end up as being the
14652 line where the window_end_vpos is. */
14653 w
->cursor
.vpos
= -1;
14654 last_text_row
= NULL
;
14655 overlay_arrow_seen
= 0;
14656 while (it
.current_y
< it
.last_visible_y
14657 && !fonts_changed_p
14658 && (first_unchanged_at_end_row
== NULL
14659 || IT_CHARPOS (it
) < stop_pos
))
14661 if (display_line (&it
))
14662 last_text_row
= it
.glyph_row
- 1;
14665 if (fonts_changed_p
)
14669 /* Compute differences in buffer positions, y-positions etc. for
14670 lines reused at the bottom of the window. Compute what we can
14672 if (first_unchanged_at_end_row
14673 /* No lines reused because we displayed everything up to the
14674 bottom of the window. */
14675 && it
.current_y
< it
.last_visible_y
)
14678 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14680 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14681 run
.current_y
= first_unchanged_at_end_row
->y
;
14682 run
.desired_y
= run
.current_y
+ dy
;
14683 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14687 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14688 first_unchanged_at_end_row
= NULL
;
14690 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14693 /* Find the cursor if not already found. We have to decide whether
14694 PT will appear on this window (it sometimes doesn't, but this is
14695 not a very frequent case.) This decision has to be made before
14696 the current matrix is altered. A value of cursor.vpos < 0 means
14697 that PT is either in one of the lines beginning at
14698 first_unchanged_at_end_row or below the window. Don't care for
14699 lines that might be displayed later at the window end; as
14700 mentioned, this is not a frequent case. */
14701 if (w
->cursor
.vpos
< 0)
14703 /* Cursor in unchanged rows at the top? */
14704 if (PT
< CHARPOS (start_pos
)
14705 && last_unchanged_at_beg_row
)
14707 row
= row_containing_pos (w
, PT
,
14708 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14709 last_unchanged_at_beg_row
+ 1, 0);
14711 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14714 /* Start from first_unchanged_at_end_row looking for PT. */
14715 else if (first_unchanged_at_end_row
)
14717 row
= row_containing_pos (w
, PT
- delta
,
14718 first_unchanged_at_end_row
, NULL
, 0);
14720 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14721 delta_bytes
, dy
, dvpos
);
14724 /* Give up if cursor was not found. */
14725 if (w
->cursor
.vpos
< 0)
14727 clear_glyph_matrix (w
->desired_matrix
);
14732 /* Don't let the cursor end in the scroll margins. */
14734 int this_scroll_margin
, cursor_height
;
14736 this_scroll_margin
= max (0, scroll_margin
);
14737 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14738 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14739 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14741 if ((w
->cursor
.y
< this_scroll_margin
14742 && CHARPOS (start
) > BEGV
)
14743 /* Old redisplay didn't take scroll margin into account at the bottom,
14744 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14745 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14746 ? cursor_height
+ this_scroll_margin
14747 : 1)) > it
.last_visible_y
)
14749 w
->cursor
.vpos
= -1;
14750 clear_glyph_matrix (w
->desired_matrix
);
14755 /* Scroll the display. Do it before changing the current matrix so
14756 that xterm.c doesn't get confused about where the cursor glyph is
14758 if (dy
&& run
.height
)
14762 if (FRAME_WINDOW_P (f
))
14764 rif
->update_window_begin_hook (w
);
14765 rif
->clear_window_mouse_face (w
);
14766 rif
->scroll_run_hook (w
, &run
);
14767 rif
->update_window_end_hook (w
, 0, 0);
14771 /* Terminal frame. In this case, dvpos gives the number of
14772 lines to scroll by; dvpos < 0 means scroll up. */
14773 int first_unchanged_at_end_vpos
14774 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14775 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14776 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14777 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14778 + window_internal_height (w
));
14780 /* Perform the operation on the screen. */
14783 /* Scroll last_unchanged_at_beg_row to the end of the
14784 window down dvpos lines. */
14785 set_terminal_window (end
);
14787 /* On dumb terminals delete dvpos lines at the end
14788 before inserting dvpos empty lines. */
14789 if (!scroll_region_ok
)
14790 ins_del_lines (end
- dvpos
, -dvpos
);
14792 /* Insert dvpos empty lines in front of
14793 last_unchanged_at_beg_row. */
14794 ins_del_lines (from
, dvpos
);
14796 else if (dvpos
< 0)
14798 /* Scroll up last_unchanged_at_beg_vpos to the end of
14799 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14800 set_terminal_window (end
);
14802 /* Delete dvpos lines in front of
14803 last_unchanged_at_beg_vpos. ins_del_lines will set
14804 the cursor to the given vpos and emit |dvpos| delete
14806 ins_del_lines (from
+ dvpos
, dvpos
);
14808 /* On a dumb terminal insert dvpos empty lines at the
14810 if (!scroll_region_ok
)
14811 ins_del_lines (end
+ dvpos
, -dvpos
);
14814 set_terminal_window (0);
14820 /* Shift reused rows of the current matrix to the right position.
14821 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14823 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14824 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14827 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14828 bottom_vpos
, dvpos
);
14829 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14832 else if (dvpos
> 0)
14834 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14835 bottom_vpos
, dvpos
);
14836 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14837 first_unchanged_at_end_vpos
+ dvpos
, 0);
14840 /* For frame-based redisplay, make sure that current frame and window
14841 matrix are in sync with respect to glyph memory. */
14842 if (!FRAME_WINDOW_P (f
))
14843 sync_frame_with_window_matrix_rows (w
);
14845 /* Adjust buffer positions in reused rows. */
14847 increment_matrix_positions (current_matrix
,
14848 first_unchanged_at_end_vpos
+ dvpos
,
14849 bottom_vpos
, delta
, delta_bytes
);
14851 /* Adjust Y positions. */
14853 shift_glyph_matrix (w
, current_matrix
,
14854 first_unchanged_at_end_vpos
+ dvpos
,
14857 if (first_unchanged_at_end_row
)
14859 first_unchanged_at_end_row
+= dvpos
;
14860 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14861 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14862 first_unchanged_at_end_row
= NULL
;
14865 /* If scrolling up, there may be some lines to display at the end of
14867 last_text_row_at_end
= NULL
;
14870 /* Scrolling up can leave for example a partially visible line
14871 at the end of the window to be redisplayed. */
14872 /* Set last_row to the glyph row in the current matrix where the
14873 window end line is found. It has been moved up or down in
14874 the matrix by dvpos. */
14875 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14876 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14878 /* If last_row is the window end line, it should display text. */
14879 xassert (last_row
->displays_text_p
);
14881 /* If window end line was partially visible before, begin
14882 displaying at that line. Otherwise begin displaying with the
14883 line following it. */
14884 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14886 init_to_row_start (&it
, w
, last_row
);
14887 it
.vpos
= last_vpos
;
14888 it
.current_y
= last_row
->y
;
14892 init_to_row_end (&it
, w
, last_row
);
14893 it
.vpos
= 1 + last_vpos
;
14894 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14898 /* We may start in a continuation line. If so, we have to
14899 get the right continuation_lines_width and current_x. */
14900 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14901 it
.hpos
= it
.current_x
= 0;
14903 /* Display the rest of the lines at the window end. */
14904 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14905 while (it
.current_y
< it
.last_visible_y
14906 && !fonts_changed_p
)
14908 /* Is it always sure that the display agrees with lines in
14909 the current matrix? I don't think so, so we mark rows
14910 displayed invalid in the current matrix by setting their
14911 enabled_p flag to zero. */
14912 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14913 if (display_line (&it
))
14914 last_text_row_at_end
= it
.glyph_row
- 1;
14918 /* Update window_end_pos and window_end_vpos. */
14919 if (first_unchanged_at_end_row
14920 && !last_text_row_at_end
)
14922 /* Window end line if one of the preserved rows from the current
14923 matrix. Set row to the last row displaying text in current
14924 matrix starting at first_unchanged_at_end_row, after
14926 xassert (first_unchanged_at_end_row
->displays_text_p
);
14927 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14928 first_unchanged_at_end_row
);
14929 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14931 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14932 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14934 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14935 xassert (w
->window_end_bytepos
>= 0);
14936 IF_DEBUG (debug_method_add (w
, "A"));
14938 else if (last_text_row_at_end
)
14941 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14942 w
->window_end_bytepos
14943 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14945 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14946 xassert (w
->window_end_bytepos
>= 0);
14947 IF_DEBUG (debug_method_add (w
, "B"));
14949 else if (last_text_row
)
14951 /* We have displayed either to the end of the window or at the
14952 end of the window, i.e. the last row with text is to be found
14953 in the desired matrix. */
14955 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14956 w
->window_end_bytepos
14957 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14959 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14960 xassert (w
->window_end_bytepos
>= 0);
14962 else if (first_unchanged_at_end_row
== NULL
14963 && last_text_row
== NULL
14964 && last_text_row_at_end
== NULL
)
14966 /* Displayed to end of window, but no line containing text was
14967 displayed. Lines were deleted at the end of the window. */
14968 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14969 int vpos
= XFASTINT (w
->window_end_vpos
);
14970 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14971 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14974 row
== NULL
&& vpos
>= first_vpos
;
14975 --vpos
, --current_row
, --desired_row
)
14977 if (desired_row
->enabled_p
)
14979 if (desired_row
->displays_text_p
)
14982 else if (current_row
->displays_text_p
)
14986 xassert (row
!= NULL
);
14987 w
->window_end_vpos
= make_number (vpos
+ 1);
14988 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14989 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14990 xassert (w
->window_end_bytepos
>= 0);
14991 IF_DEBUG (debug_method_add (w
, "C"));
14996 #if 0 /* This leads to problems, for instance when the cursor is
14997 at ZV, and the cursor line displays no text. */
14998 /* Disable rows below what's displayed in the window. This makes
14999 debugging easier. */
15000 enable_glyph_matrix_rows (current_matrix
,
15001 XFASTINT (w
->window_end_vpos
) + 1,
15005 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15006 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15008 /* Record that display has not been completed. */
15009 w
->window_end_valid
= Qnil
;
15010 w
->desired_matrix
->no_scrolling_p
= 1;
15018 /***********************************************************************
15019 More debugging support
15020 ***********************************************************************/
15024 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15025 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15026 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15029 /* Dump the contents of glyph matrix MATRIX on stderr.
15031 GLYPHS 0 means don't show glyph contents.
15032 GLYPHS 1 means show glyphs in short form
15033 GLYPHS > 1 means show glyphs in long form. */
15036 dump_glyph_matrix (matrix
, glyphs
)
15037 struct glyph_matrix
*matrix
;
15041 for (i
= 0; i
< matrix
->nrows
; ++i
)
15042 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15046 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15047 the glyph row and area where the glyph comes from. */
15050 dump_glyph (row
, glyph
, area
)
15051 struct glyph_row
*row
;
15052 struct glyph
*glyph
;
15055 if (glyph
->type
== CHAR_GLYPH
)
15058 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15059 glyph
- row
->glyphs
[TEXT_AREA
],
15062 (BUFFERP (glyph
->object
)
15064 : (STRINGP (glyph
->object
)
15067 glyph
->pixel_width
,
15069 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15073 glyph
->left_box_line_p
,
15074 glyph
->right_box_line_p
);
15076 else if (glyph
->type
== STRETCH_GLYPH
)
15079 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15080 glyph
- row
->glyphs
[TEXT_AREA
],
15083 (BUFFERP (glyph
->object
)
15085 : (STRINGP (glyph
->object
)
15088 glyph
->pixel_width
,
15092 glyph
->left_box_line_p
,
15093 glyph
->right_box_line_p
);
15095 else if (glyph
->type
== IMAGE_GLYPH
)
15098 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15099 glyph
- row
->glyphs
[TEXT_AREA
],
15102 (BUFFERP (glyph
->object
)
15104 : (STRINGP (glyph
->object
)
15107 glyph
->pixel_width
,
15111 glyph
->left_box_line_p
,
15112 glyph
->right_box_line_p
);
15114 else if (glyph
->type
== COMPOSITE_GLYPH
)
15117 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15118 glyph
- row
->glyphs
[TEXT_AREA
],
15121 (BUFFERP (glyph
->object
)
15123 : (STRINGP (glyph
->object
)
15126 glyph
->pixel_width
,
15130 glyph
->left_box_line_p
,
15131 glyph
->right_box_line_p
);
15136 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15137 GLYPHS 0 means don't show glyph contents.
15138 GLYPHS 1 means show glyphs in short form
15139 GLYPHS > 1 means show glyphs in long form. */
15142 dump_glyph_row (row
, vpos
, glyphs
)
15143 struct glyph_row
*row
;
15148 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15149 fprintf (stderr
, "======================================================================\n");
15151 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15152 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15154 MATRIX_ROW_START_CHARPOS (row
),
15155 MATRIX_ROW_END_CHARPOS (row
),
15156 row
->used
[TEXT_AREA
],
15157 row
->contains_overlapping_glyphs_p
,
15159 row
->truncated_on_left_p
,
15160 row
->truncated_on_right_p
,
15162 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15163 row
->displays_text_p
,
15166 row
->ends_in_middle_of_char_p
,
15167 row
->starts_in_middle_of_char_p
,
15173 row
->visible_height
,
15176 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15177 row
->end
.overlay_string_index
,
15178 row
->continuation_lines_width
);
15179 fprintf (stderr
, "%9d %5d\n",
15180 CHARPOS (row
->start
.string_pos
),
15181 CHARPOS (row
->end
.string_pos
));
15182 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15183 row
->end
.dpvec_index
);
15190 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15192 struct glyph
*glyph
= row
->glyphs
[area
];
15193 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15195 /* Glyph for a line end in text. */
15196 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15199 if (glyph
< glyph_end
)
15200 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15202 for (; glyph
< glyph_end
; ++glyph
)
15203 dump_glyph (row
, glyph
, area
);
15206 else if (glyphs
== 1)
15210 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15212 char *s
= (char *) alloca (row
->used
[area
] + 1);
15215 for (i
= 0; i
< row
->used
[area
]; ++i
)
15217 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15218 if (glyph
->type
== CHAR_GLYPH
15219 && glyph
->u
.ch
< 0x80
15220 && glyph
->u
.ch
>= ' ')
15221 s
[i
] = glyph
->u
.ch
;
15227 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15233 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15234 Sdump_glyph_matrix
, 0, 1, "p",
15235 doc
: /* Dump the current matrix of the selected window to stderr.
15236 Shows contents of glyph row structures. With non-nil
15237 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15238 glyphs in short form, otherwise show glyphs in long form. */)
15240 Lisp_Object glyphs
;
15242 struct window
*w
= XWINDOW (selected_window
);
15243 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15245 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15246 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15247 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15248 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15249 fprintf (stderr
, "=============================================\n");
15250 dump_glyph_matrix (w
->current_matrix
,
15251 NILP (glyphs
) ? 0 : XINT (glyphs
));
15256 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15257 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15260 struct frame
*f
= XFRAME (selected_frame
);
15261 dump_glyph_matrix (f
->current_matrix
, 1);
15266 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15267 doc
: /* Dump glyph row ROW to stderr.
15268 GLYPH 0 means don't dump glyphs.
15269 GLYPH 1 means dump glyphs in short form.
15270 GLYPH > 1 or omitted means dump glyphs in long form. */)
15272 Lisp_Object row
, glyphs
;
15274 struct glyph_matrix
*matrix
;
15277 CHECK_NUMBER (row
);
15278 matrix
= XWINDOW (selected_window
)->current_matrix
;
15280 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15281 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15283 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15288 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15289 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15290 GLYPH 0 means don't dump glyphs.
15291 GLYPH 1 means dump glyphs in short form.
15292 GLYPH > 1 or omitted means dump glyphs in long form. */)
15294 Lisp_Object row
, glyphs
;
15296 struct frame
*sf
= SELECTED_FRAME ();
15297 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15300 CHECK_NUMBER (row
);
15302 if (vpos
>= 0 && vpos
< m
->nrows
)
15303 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15304 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15309 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15310 doc
: /* Toggle tracing of redisplay.
15311 With ARG, turn tracing on if and only if ARG is positive. */)
15316 trace_redisplay_p
= !trace_redisplay_p
;
15319 arg
= Fprefix_numeric_value (arg
);
15320 trace_redisplay_p
= XINT (arg
) > 0;
15327 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15328 doc
: /* Like `format', but print result to stderr.
15329 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15334 Lisp_Object s
= Fformat (nargs
, args
);
15335 fprintf (stderr
, "%s", SDATA (s
));
15339 #endif /* GLYPH_DEBUG */
15343 /***********************************************************************
15344 Building Desired Matrix Rows
15345 ***********************************************************************/
15347 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15348 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15350 static struct glyph_row
*
15351 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15353 Lisp_Object overlay_arrow_string
;
15355 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15356 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15357 struct buffer
*old
= current_buffer
;
15358 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15359 int arrow_len
= SCHARS (overlay_arrow_string
);
15360 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15361 const unsigned char *p
;
15364 int n_glyphs_before
;
15366 set_buffer_temp (buffer
);
15367 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15368 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15369 SET_TEXT_POS (it
.position
, 0, 0);
15371 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15373 while (p
< arrow_end
)
15375 Lisp_Object face
, ilisp
;
15377 /* Get the next character. */
15379 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15381 it
.c
= *p
, it
.len
= 1;
15384 /* Get its face. */
15385 ilisp
= make_number (p
- arrow_string
);
15386 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15387 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15389 /* Compute its width, get its glyphs. */
15390 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15391 SET_TEXT_POS (it
.position
, -1, -1);
15392 PRODUCE_GLYPHS (&it
);
15394 /* If this character doesn't fit any more in the line, we have
15395 to remove some glyphs. */
15396 if (it
.current_x
> it
.last_visible_x
)
15398 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15403 set_buffer_temp (old
);
15404 return it
.glyph_row
;
15408 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15409 glyphs are only inserted for terminal frames since we can't really
15410 win with truncation glyphs when partially visible glyphs are
15411 involved. Which glyphs to insert is determined by
15412 produce_special_glyphs. */
15415 insert_left_trunc_glyphs (it
)
15418 struct it truncate_it
;
15419 struct glyph
*from
, *end
, *to
, *toend
;
15421 xassert (!FRAME_WINDOW_P (it
->f
));
15423 /* Get the truncation glyphs. */
15425 truncate_it
.current_x
= 0;
15426 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15427 truncate_it
.glyph_row
= &scratch_glyph_row
;
15428 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15429 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15430 truncate_it
.object
= make_number (0);
15431 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15433 /* Overwrite glyphs from IT with truncation glyphs. */
15434 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15435 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15436 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15437 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15442 /* There may be padding glyphs left over. Overwrite them too. */
15443 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15445 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15451 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15455 /* Compute the pixel height and width of IT->glyph_row.
15457 Most of the time, ascent and height of a display line will be equal
15458 to the max_ascent and max_height values of the display iterator
15459 structure. This is not the case if
15461 1. We hit ZV without displaying anything. In this case, max_ascent
15462 and max_height will be zero.
15464 2. We have some glyphs that don't contribute to the line height.
15465 (The glyph row flag contributes_to_line_height_p is for future
15466 pixmap extensions).
15468 The first case is easily covered by using default values because in
15469 these cases, the line height does not really matter, except that it
15470 must not be zero. */
15473 compute_line_metrics (it
)
15476 struct glyph_row
*row
= it
->glyph_row
;
15479 if (FRAME_WINDOW_P (it
->f
))
15481 int i
, min_y
, max_y
;
15483 /* The line may consist of one space only, that was added to
15484 place the cursor on it. If so, the row's height hasn't been
15486 if (row
->height
== 0)
15488 if (it
->max_ascent
+ it
->max_descent
== 0)
15489 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15490 row
->ascent
= it
->max_ascent
;
15491 row
->height
= it
->max_ascent
+ it
->max_descent
;
15492 row
->phys_ascent
= it
->max_phys_ascent
;
15493 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15494 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15497 /* Compute the width of this line. */
15498 row
->pixel_width
= row
->x
;
15499 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15500 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15502 xassert (row
->pixel_width
>= 0);
15503 xassert (row
->ascent
>= 0 && row
->height
> 0);
15505 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15506 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15508 /* If first line's physical ascent is larger than its logical
15509 ascent, use the physical ascent, and make the row taller.
15510 This makes accented characters fully visible. */
15511 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15512 && row
->phys_ascent
> row
->ascent
)
15514 row
->height
+= row
->phys_ascent
- row
->ascent
;
15515 row
->ascent
= row
->phys_ascent
;
15518 /* Compute how much of the line is visible. */
15519 row
->visible_height
= row
->height
;
15521 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15522 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15524 if (row
->y
< min_y
)
15525 row
->visible_height
-= min_y
- row
->y
;
15526 if (row
->y
+ row
->height
> max_y
)
15527 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15531 row
->pixel_width
= row
->used
[TEXT_AREA
];
15532 if (row
->continued_p
)
15533 row
->pixel_width
-= it
->continuation_pixel_width
;
15534 else if (row
->truncated_on_right_p
)
15535 row
->pixel_width
-= it
->truncation_pixel_width
;
15536 row
->ascent
= row
->phys_ascent
= 0;
15537 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15538 row
->extra_line_spacing
= 0;
15541 /* Compute a hash code for this row. */
15543 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15544 for (i
= 0; i
< row
->used
[area
]; ++i
)
15545 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15546 + row
->glyphs
[area
][i
].u
.val
15547 + row
->glyphs
[area
][i
].face_id
15548 + row
->glyphs
[area
][i
].padding_p
15549 + (row
->glyphs
[area
][i
].type
<< 2));
15551 it
->max_ascent
= it
->max_descent
= 0;
15552 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15556 /* Append one space to the glyph row of iterator IT if doing a
15557 window-based redisplay. The space has the same face as
15558 IT->face_id. Value is non-zero if a space was added.
15560 This function is called to make sure that there is always one glyph
15561 at the end of a glyph row that the cursor can be set on under
15562 window-systems. (If there weren't such a glyph we would not know
15563 how wide and tall a box cursor should be displayed).
15565 At the same time this space let's a nicely handle clearing to the
15566 end of the line if the row ends in italic text. */
15569 append_space_for_newline (it
, default_face_p
)
15571 int default_face_p
;
15573 if (FRAME_WINDOW_P (it
->f
))
15575 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15577 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15578 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15580 /* Save some values that must not be changed.
15581 Must save IT->c and IT->len because otherwise
15582 ITERATOR_AT_END_P wouldn't work anymore after
15583 append_space_for_newline has been called. */
15584 enum display_element_type saved_what
= it
->what
;
15585 int saved_c
= it
->c
, saved_len
= it
->len
;
15586 int saved_x
= it
->current_x
;
15587 int saved_face_id
= it
->face_id
;
15588 struct text_pos saved_pos
;
15589 Lisp_Object saved_object
;
15592 saved_object
= it
->object
;
15593 saved_pos
= it
->position
;
15595 it
->what
= IT_CHARACTER
;
15596 bzero (&it
->position
, sizeof it
->position
);
15597 it
->object
= make_number (0);
15601 if (default_face_p
)
15602 it
->face_id
= DEFAULT_FACE_ID
;
15603 else if (it
->face_before_selective_p
)
15604 it
->face_id
= it
->saved_face_id
;
15605 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15606 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15608 PRODUCE_GLYPHS (it
);
15610 it
->override_ascent
= -1;
15611 it
->constrain_row_ascent_descent_p
= 0;
15612 it
->current_x
= saved_x
;
15613 it
->object
= saved_object
;
15614 it
->position
= saved_pos
;
15615 it
->what
= saved_what
;
15616 it
->face_id
= saved_face_id
;
15617 it
->len
= saved_len
;
15627 /* Extend the face of the last glyph in the text area of IT->glyph_row
15628 to the end of the display line. Called from display_line.
15629 If the glyph row is empty, add a space glyph to it so that we
15630 know the face to draw. Set the glyph row flag fill_line_p. */
15633 extend_face_to_end_of_line (it
)
15637 struct frame
*f
= it
->f
;
15639 /* If line is already filled, do nothing. */
15640 if (it
->current_x
>= it
->last_visible_x
)
15643 /* Face extension extends the background and box of IT->face_id
15644 to the end of the line. If the background equals the background
15645 of the frame, we don't have to do anything. */
15646 if (it
->face_before_selective_p
)
15647 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15649 face
= FACE_FROM_ID (f
, it
->face_id
);
15651 if (FRAME_WINDOW_P (f
)
15652 && it
->glyph_row
->displays_text_p
15653 && face
->box
== FACE_NO_BOX
15654 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15658 /* Set the glyph row flag indicating that the face of the last glyph
15659 in the text area has to be drawn to the end of the text area. */
15660 it
->glyph_row
->fill_line_p
= 1;
15662 /* If current character of IT is not ASCII, make sure we have the
15663 ASCII face. This will be automatically undone the next time
15664 get_next_display_element returns a multibyte character. Note
15665 that the character will always be single byte in unibyte text. */
15666 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15668 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15671 if (FRAME_WINDOW_P (f
))
15673 /* If the row is empty, add a space with the current face of IT,
15674 so that we know which face to draw. */
15675 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15677 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15678 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15679 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15684 /* Save some values that must not be changed. */
15685 int saved_x
= it
->current_x
;
15686 struct text_pos saved_pos
;
15687 Lisp_Object saved_object
;
15688 enum display_element_type saved_what
= it
->what
;
15689 int saved_face_id
= it
->face_id
;
15691 saved_object
= it
->object
;
15692 saved_pos
= it
->position
;
15694 it
->what
= IT_CHARACTER
;
15695 bzero (&it
->position
, sizeof it
->position
);
15696 it
->object
= make_number (0);
15699 it
->face_id
= face
->id
;
15701 PRODUCE_GLYPHS (it
);
15703 while (it
->current_x
<= it
->last_visible_x
)
15704 PRODUCE_GLYPHS (it
);
15706 /* Don't count these blanks really. It would let us insert a left
15707 truncation glyph below and make us set the cursor on them, maybe. */
15708 it
->current_x
= saved_x
;
15709 it
->object
= saved_object
;
15710 it
->position
= saved_pos
;
15711 it
->what
= saved_what
;
15712 it
->face_id
= saved_face_id
;
15717 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15718 trailing whitespace. */
15721 trailing_whitespace_p (charpos
)
15724 int bytepos
= CHAR_TO_BYTE (charpos
);
15727 while (bytepos
< ZV_BYTE
15728 && (c
= FETCH_CHAR (bytepos
),
15729 c
== ' ' || c
== '\t'))
15732 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15734 if (bytepos
!= PT_BYTE
)
15741 /* Highlight trailing whitespace, if any, in ROW. */
15744 highlight_trailing_whitespace (f
, row
)
15746 struct glyph_row
*row
;
15748 int used
= row
->used
[TEXT_AREA
];
15752 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15753 struct glyph
*glyph
= start
+ used
- 1;
15755 /* Skip over glyphs inserted to display the cursor at the
15756 end of a line, for extending the face of the last glyph
15757 to the end of the line on terminals, and for truncation
15758 and continuation glyphs. */
15759 while (glyph
>= start
15760 && glyph
->type
== CHAR_GLYPH
15761 && INTEGERP (glyph
->object
))
15764 /* If last glyph is a space or stretch, and it's trailing
15765 whitespace, set the face of all trailing whitespace glyphs in
15766 IT->glyph_row to `trailing-whitespace'. */
15768 && BUFFERP (glyph
->object
)
15769 && (glyph
->type
== STRETCH_GLYPH
15770 || (glyph
->type
== CHAR_GLYPH
15771 && glyph
->u
.ch
== ' '))
15772 && trailing_whitespace_p (glyph
->charpos
))
15774 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15778 while (glyph
>= start
15779 && BUFFERP (glyph
->object
)
15780 && (glyph
->type
== STRETCH_GLYPH
15781 || (glyph
->type
== CHAR_GLYPH
15782 && glyph
->u
.ch
== ' ')))
15783 (glyph
--)->face_id
= face_id
;
15789 /* Value is non-zero if glyph row ROW in window W should be
15790 used to hold the cursor. */
15793 cursor_row_p (w
, row
)
15795 struct glyph_row
*row
;
15797 int cursor_row_p
= 1;
15799 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15801 /* If the row ends with a newline from a string, we don't want
15802 the cursor there, but we still want it at the start of the
15803 string if the string starts in this row.
15804 If the row is continued it doesn't end in a newline. */
15805 if (CHARPOS (row
->end
.string_pos
) >= 0)
15806 cursor_row_p
= (row
->continued_p
15807 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15808 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15810 /* If the row ends in middle of a real character,
15811 and the line is continued, we want the cursor here.
15812 That's because MATRIX_ROW_END_CHARPOS would equal
15813 PT if PT is before the character. */
15814 if (!row
->ends_in_ellipsis_p
)
15815 cursor_row_p
= row
->continued_p
;
15817 /* If the row ends in an ellipsis, then
15818 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15819 We want that position to be displayed after the ellipsis. */
15822 /* If the row ends at ZV, display the cursor at the end of that
15823 row instead of at the start of the row below. */
15824 else if (row
->ends_at_zv_p
)
15830 return cursor_row_p
;
15834 /* Construct the glyph row IT->glyph_row in the desired matrix of
15835 IT->w from text at the current position of IT. See dispextern.h
15836 for an overview of struct it. Value is non-zero if
15837 IT->glyph_row displays text, as opposed to a line displaying ZV
15844 struct glyph_row
*row
= it
->glyph_row
;
15845 Lisp_Object overlay_arrow_string
;
15847 /* We always start displaying at hpos zero even if hscrolled. */
15848 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15850 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15851 >= it
->w
->desired_matrix
->nrows
)
15853 it
->w
->nrows_scale_factor
++;
15854 fonts_changed_p
= 1;
15858 /* Is IT->w showing the region? */
15859 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15861 /* Clear the result glyph row and enable it. */
15862 prepare_desired_row (row
);
15864 row
->y
= it
->current_y
;
15865 row
->start
= it
->start
;
15866 row
->continuation_lines_width
= it
->continuation_lines_width
;
15867 row
->displays_text_p
= 1;
15868 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15869 it
->starts_in_middle_of_char_p
= 0;
15871 /* Arrange the overlays nicely for our purposes. Usually, we call
15872 display_line on only one line at a time, in which case this
15873 can't really hurt too much, or we call it on lines which appear
15874 one after another in the buffer, in which case all calls to
15875 recenter_overlay_lists but the first will be pretty cheap. */
15876 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15878 /* Move over display elements that are not visible because we are
15879 hscrolled. This may stop at an x-position < IT->first_visible_x
15880 if the first glyph is partially visible or if we hit a line end. */
15881 if (it
->current_x
< it
->first_visible_x
)
15883 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15884 MOVE_TO_POS
| MOVE_TO_X
);
15887 /* Get the initial row height. This is either the height of the
15888 text hscrolled, if there is any, or zero. */
15889 row
->ascent
= it
->max_ascent
;
15890 row
->height
= it
->max_ascent
+ it
->max_descent
;
15891 row
->phys_ascent
= it
->max_phys_ascent
;
15892 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15893 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15895 /* Loop generating characters. The loop is left with IT on the next
15896 character to display. */
15899 int n_glyphs_before
, hpos_before
, x_before
;
15901 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15903 /* Retrieve the next thing to display. Value is zero if end of
15905 if (!get_next_display_element (it
))
15907 /* Maybe add a space at the end of this line that is used to
15908 display the cursor there under X. Set the charpos of the
15909 first glyph of blank lines not corresponding to any text
15911 #ifdef HAVE_WINDOW_SYSTEM
15912 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15913 row
->exact_window_width_line_p
= 1;
15915 #endif /* HAVE_WINDOW_SYSTEM */
15916 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15917 || row
->used
[TEXT_AREA
] == 0)
15919 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15920 row
->displays_text_p
= 0;
15922 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15923 && (!MINI_WINDOW_P (it
->w
)
15924 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15925 row
->indicate_empty_line_p
= 1;
15928 it
->continuation_lines_width
= 0;
15929 row
->ends_at_zv_p
= 1;
15933 /* Now, get the metrics of what we want to display. This also
15934 generates glyphs in `row' (which is IT->glyph_row). */
15935 n_glyphs_before
= row
->used
[TEXT_AREA
];
15938 /* Remember the line height so far in case the next element doesn't
15939 fit on the line. */
15940 if (!it
->truncate_lines_p
)
15942 ascent
= it
->max_ascent
;
15943 descent
= it
->max_descent
;
15944 phys_ascent
= it
->max_phys_ascent
;
15945 phys_descent
= it
->max_phys_descent
;
15948 PRODUCE_GLYPHS (it
);
15950 /* If this display element was in marginal areas, continue with
15952 if (it
->area
!= TEXT_AREA
)
15954 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15955 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15956 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15957 row
->phys_height
= max (row
->phys_height
,
15958 it
->max_phys_ascent
+ it
->max_phys_descent
);
15959 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15960 it
->max_extra_line_spacing
);
15961 set_iterator_to_next (it
, 1);
15965 /* Does the display element fit on the line? If we truncate
15966 lines, we should draw past the right edge of the window. If
15967 we don't truncate, we want to stop so that we can display the
15968 continuation glyph before the right margin. If lines are
15969 continued, there are two possible strategies for characters
15970 resulting in more than 1 glyph (e.g. tabs): Display as many
15971 glyphs as possible in this line and leave the rest for the
15972 continuation line, or display the whole element in the next
15973 line. Original redisplay did the former, so we do it also. */
15974 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15975 hpos_before
= it
->hpos
;
15978 if (/* Not a newline. */
15980 /* Glyphs produced fit entirely in the line. */
15981 && it
->current_x
< it
->last_visible_x
)
15983 it
->hpos
+= nglyphs
;
15984 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15985 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15986 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15987 row
->phys_height
= max (row
->phys_height
,
15988 it
->max_phys_ascent
+ it
->max_phys_descent
);
15989 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15990 it
->max_extra_line_spacing
);
15991 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15992 row
->x
= x
- it
->first_visible_x
;
15997 struct glyph
*glyph
;
15999 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16001 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16002 new_x
= x
+ glyph
->pixel_width
;
16004 if (/* Lines are continued. */
16005 !it
->truncate_lines_p
16006 && (/* Glyph doesn't fit on the line. */
16007 new_x
> it
->last_visible_x
16008 /* Or it fits exactly on a window system frame. */
16009 || (new_x
== it
->last_visible_x
16010 && FRAME_WINDOW_P (it
->f
))))
16012 /* End of a continued line. */
16015 || (new_x
== it
->last_visible_x
16016 && FRAME_WINDOW_P (it
->f
)))
16018 /* Current glyph is the only one on the line or
16019 fits exactly on the line. We must continue
16020 the line because we can't draw the cursor
16021 after the glyph. */
16022 row
->continued_p
= 1;
16023 it
->current_x
= new_x
;
16024 it
->continuation_lines_width
+= new_x
;
16026 if (i
== nglyphs
- 1)
16028 set_iterator_to_next (it
, 1);
16029 #ifdef HAVE_WINDOW_SYSTEM
16030 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16032 if (!get_next_display_element (it
))
16034 row
->exact_window_width_line_p
= 1;
16035 it
->continuation_lines_width
= 0;
16036 row
->continued_p
= 0;
16037 row
->ends_at_zv_p
= 1;
16039 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16041 row
->continued_p
= 0;
16042 row
->exact_window_width_line_p
= 1;
16045 #endif /* HAVE_WINDOW_SYSTEM */
16048 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16049 && !FRAME_WINDOW_P (it
->f
))
16051 /* A padding glyph that doesn't fit on this line.
16052 This means the whole character doesn't fit
16054 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16056 /* Fill the rest of the row with continuation
16057 glyphs like in 20.x. */
16058 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16059 < row
->glyphs
[1 + TEXT_AREA
])
16060 produce_special_glyphs (it
, IT_CONTINUATION
);
16062 row
->continued_p
= 1;
16063 it
->current_x
= x_before
;
16064 it
->continuation_lines_width
+= x_before
;
16066 /* Restore the height to what it was before the
16067 element not fitting on the line. */
16068 it
->max_ascent
= ascent
;
16069 it
->max_descent
= descent
;
16070 it
->max_phys_ascent
= phys_ascent
;
16071 it
->max_phys_descent
= phys_descent
;
16073 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16075 /* A TAB that extends past the right edge of the
16076 window. This produces a single glyph on
16077 window system frames. We leave the glyph in
16078 this row and let it fill the row, but don't
16079 consume the TAB. */
16080 it
->continuation_lines_width
+= it
->last_visible_x
;
16081 row
->ends_in_middle_of_char_p
= 1;
16082 row
->continued_p
= 1;
16083 glyph
->pixel_width
= it
->last_visible_x
- x
;
16084 it
->starts_in_middle_of_char_p
= 1;
16088 /* Something other than a TAB that draws past
16089 the right edge of the window. Restore
16090 positions to values before the element. */
16091 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16093 /* Display continuation glyphs. */
16094 if (!FRAME_WINDOW_P (it
->f
))
16095 produce_special_glyphs (it
, IT_CONTINUATION
);
16096 row
->continued_p
= 1;
16098 it
->current_x
= x_before
;
16099 it
->continuation_lines_width
+= x
;
16100 extend_face_to_end_of_line (it
);
16102 if (nglyphs
> 1 && i
> 0)
16104 row
->ends_in_middle_of_char_p
= 1;
16105 it
->starts_in_middle_of_char_p
= 1;
16108 /* Restore the height to what it was before the
16109 element not fitting on the line. */
16110 it
->max_ascent
= ascent
;
16111 it
->max_descent
= descent
;
16112 it
->max_phys_ascent
= phys_ascent
;
16113 it
->max_phys_descent
= phys_descent
;
16118 else if (new_x
> it
->first_visible_x
)
16120 /* Increment number of glyphs actually displayed. */
16123 if (x
< it
->first_visible_x
)
16124 /* Glyph is partially visible, i.e. row starts at
16125 negative X position. */
16126 row
->x
= x
- it
->first_visible_x
;
16130 /* Glyph is completely off the left margin of the
16131 window. This should not happen because of the
16132 move_it_in_display_line at the start of this
16133 function, unless the text display area of the
16134 window is empty. */
16135 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16139 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16140 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16141 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16142 row
->phys_height
= max (row
->phys_height
,
16143 it
->max_phys_ascent
+ it
->max_phys_descent
);
16144 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16145 it
->max_extra_line_spacing
);
16147 /* End of this display line if row is continued. */
16148 if (row
->continued_p
|| row
->ends_at_zv_p
)
16153 /* Is this a line end? If yes, we're also done, after making
16154 sure that a non-default face is extended up to the right
16155 margin of the window. */
16156 if (ITERATOR_AT_END_OF_LINE_P (it
))
16158 int used_before
= row
->used
[TEXT_AREA
];
16160 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16162 #ifdef HAVE_WINDOW_SYSTEM
16163 /* Add a space at the end of the line that is used to
16164 display the cursor there. */
16165 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16166 append_space_for_newline (it
, 0);
16167 #endif /* HAVE_WINDOW_SYSTEM */
16169 /* Extend the face to the end of the line. */
16170 extend_face_to_end_of_line (it
);
16172 /* Make sure we have the position. */
16173 if (used_before
== 0)
16174 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16176 /* Consume the line end. This skips over invisible lines. */
16177 set_iterator_to_next (it
, 1);
16178 it
->continuation_lines_width
= 0;
16182 /* Proceed with next display element. Note that this skips
16183 over lines invisible because of selective display. */
16184 set_iterator_to_next (it
, 1);
16186 /* If we truncate lines, we are done when the last displayed
16187 glyphs reach past the right margin of the window. */
16188 if (it
->truncate_lines_p
16189 && (FRAME_WINDOW_P (it
->f
)
16190 ? (it
->current_x
>= it
->last_visible_x
)
16191 : (it
->current_x
> it
->last_visible_x
)))
16193 /* Maybe add truncation glyphs. */
16194 if (!FRAME_WINDOW_P (it
->f
))
16198 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16199 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16202 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16204 row
->used
[TEXT_AREA
] = i
;
16205 produce_special_glyphs (it
, IT_TRUNCATION
);
16208 #ifdef HAVE_WINDOW_SYSTEM
16211 /* Don't truncate if we can overflow newline into fringe. */
16212 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16214 if (!get_next_display_element (it
))
16216 it
->continuation_lines_width
= 0;
16217 row
->ends_at_zv_p
= 1;
16218 row
->exact_window_width_line_p
= 1;
16221 if (ITERATOR_AT_END_OF_LINE_P (it
))
16223 row
->exact_window_width_line_p
= 1;
16224 goto at_end_of_line
;
16228 #endif /* HAVE_WINDOW_SYSTEM */
16230 row
->truncated_on_right_p
= 1;
16231 it
->continuation_lines_width
= 0;
16232 reseat_at_next_visible_line_start (it
, 0);
16233 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16234 it
->hpos
= hpos_before
;
16235 it
->current_x
= x_before
;
16240 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16241 at the left window margin. */
16242 if (it
->first_visible_x
16243 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16245 if (!FRAME_WINDOW_P (it
->f
))
16246 insert_left_trunc_glyphs (it
);
16247 row
->truncated_on_left_p
= 1;
16250 /* If the start of this line is the overlay arrow-position, then
16251 mark this glyph row as the one containing the overlay arrow.
16252 This is clearly a mess with variable size fonts. It would be
16253 better to let it be displayed like cursors under X. */
16254 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16255 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16256 !NILP (overlay_arrow_string
)))
16258 /* Overlay arrow in window redisplay is a fringe bitmap. */
16259 if (STRINGP (overlay_arrow_string
))
16261 struct glyph_row
*arrow_row
16262 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16263 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16264 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16265 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16266 struct glyph
*p2
, *end
;
16268 /* Copy the arrow glyphs. */
16269 while (glyph
< arrow_end
)
16272 /* Throw away padding glyphs. */
16274 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16275 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16281 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16286 xassert (INTEGERP (overlay_arrow_string
));
16287 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16289 overlay_arrow_seen
= 1;
16292 /* Compute pixel dimensions of this line. */
16293 compute_line_metrics (it
);
16295 /* Remember the position at which this line ends. */
16296 row
->end
= it
->current
;
16298 /* Record whether this row ends inside an ellipsis. */
16299 row
->ends_in_ellipsis_p
16300 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16301 && it
->ellipsis_p
);
16303 /* Save fringe bitmaps in this row. */
16304 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16305 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16306 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16307 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16309 it
->left_user_fringe_bitmap
= 0;
16310 it
->left_user_fringe_face_id
= 0;
16311 it
->right_user_fringe_bitmap
= 0;
16312 it
->right_user_fringe_face_id
= 0;
16314 /* Maybe set the cursor. */
16315 if (it
->w
->cursor
.vpos
< 0
16316 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16317 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16318 && cursor_row_p (it
->w
, row
))
16319 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16321 /* Highlight trailing whitespace. */
16322 if (!NILP (Vshow_trailing_whitespace
))
16323 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16325 /* Prepare for the next line. This line starts horizontally at (X
16326 HPOS) = (0 0). Vertical positions are incremented. As a
16327 convenience for the caller, IT->glyph_row is set to the next
16329 it
->current_x
= it
->hpos
= 0;
16330 it
->current_y
+= row
->height
;
16333 it
->start
= it
->current
;
16334 return row
->displays_text_p
;
16339 /***********************************************************************
16341 ***********************************************************************/
16343 /* Redisplay the menu bar in the frame for window W.
16345 The menu bar of X frames that don't have X toolkit support is
16346 displayed in a special window W->frame->menu_bar_window.
16348 The menu bar of terminal frames is treated specially as far as
16349 glyph matrices are concerned. Menu bar lines are not part of
16350 windows, so the update is done directly on the frame matrix rows
16351 for the menu bar. */
16354 display_menu_bar (w
)
16357 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16362 /* Don't do all this for graphical frames. */
16364 if (!NILP (Vwindow_system
))
16367 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16372 if (FRAME_MAC_P (f
))
16376 #ifdef USE_X_TOOLKIT
16377 xassert (!FRAME_WINDOW_P (f
));
16378 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16379 it
.first_visible_x
= 0;
16380 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16381 #else /* not USE_X_TOOLKIT */
16382 if (FRAME_WINDOW_P (f
))
16384 /* Menu bar lines are displayed in the desired matrix of the
16385 dummy window menu_bar_window. */
16386 struct window
*menu_w
;
16387 xassert (WINDOWP (f
->menu_bar_window
));
16388 menu_w
= XWINDOW (f
->menu_bar_window
);
16389 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16391 it
.first_visible_x
= 0;
16392 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16396 /* This is a TTY frame, i.e. character hpos/vpos are used as
16398 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16400 it
.first_visible_x
= 0;
16401 it
.last_visible_x
= FRAME_COLS (f
);
16403 #endif /* not USE_X_TOOLKIT */
16405 if (! mode_line_inverse_video
)
16406 /* Force the menu-bar to be displayed in the default face. */
16407 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16409 /* Clear all rows of the menu bar. */
16410 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16412 struct glyph_row
*row
= it
.glyph_row
+ i
;
16413 clear_glyph_row (row
);
16414 row
->enabled_p
= 1;
16415 row
->full_width_p
= 1;
16418 /* Display all items of the menu bar. */
16419 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16420 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16422 Lisp_Object string
;
16424 /* Stop at nil string. */
16425 string
= AREF (items
, i
+ 1);
16429 /* Remember where item was displayed. */
16430 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16432 /* Display the item, pad with one space. */
16433 if (it
.current_x
< it
.last_visible_x
)
16434 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16435 SCHARS (string
) + 1, 0, 0, -1);
16438 /* Fill out the line with spaces. */
16439 if (it
.current_x
< it
.last_visible_x
)
16440 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16442 /* Compute the total height of the lines. */
16443 compute_line_metrics (&it
);
16448 /***********************************************************************
16450 ***********************************************************************/
16452 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16453 FORCE is non-zero, redisplay mode lines unconditionally.
16454 Otherwise, redisplay only mode lines that are garbaged. Value is
16455 the number of windows whose mode lines were redisplayed. */
16458 redisplay_mode_lines (window
, force
)
16459 Lisp_Object window
;
16464 while (!NILP (window
))
16466 struct window
*w
= XWINDOW (window
);
16468 if (WINDOWP (w
->hchild
))
16469 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16470 else if (WINDOWP (w
->vchild
))
16471 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16473 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16474 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16476 struct text_pos lpoint
;
16477 struct buffer
*old
= current_buffer
;
16479 /* Set the window's buffer for the mode line display. */
16480 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16481 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16483 /* Point refers normally to the selected window. For any
16484 other window, set up appropriate value. */
16485 if (!EQ (window
, selected_window
))
16487 struct text_pos pt
;
16489 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16490 if (CHARPOS (pt
) < BEGV
)
16491 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16492 else if (CHARPOS (pt
) > (ZV
- 1))
16493 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16495 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16498 /* Display mode lines. */
16499 clear_glyph_matrix (w
->desired_matrix
);
16500 if (display_mode_lines (w
))
16503 w
->must_be_updated_p
= 1;
16506 /* Restore old settings. */
16507 set_buffer_internal_1 (old
);
16508 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16518 /* Display the mode and/or top line of window W. Value is the number
16519 of mode lines displayed. */
16522 display_mode_lines (w
)
16525 Lisp_Object old_selected_window
, old_selected_frame
;
16528 old_selected_frame
= selected_frame
;
16529 selected_frame
= w
->frame
;
16530 old_selected_window
= selected_window
;
16531 XSETWINDOW (selected_window
, w
);
16533 /* These will be set while the mode line specs are processed. */
16534 line_number_displayed
= 0;
16535 w
->column_number_displayed
= Qnil
;
16537 if (WINDOW_WANTS_MODELINE_P (w
))
16539 struct window
*sel_w
= XWINDOW (old_selected_window
);
16541 /* Select mode line face based on the real selected window. */
16542 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16543 current_buffer
->mode_line_format
);
16547 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16549 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16550 current_buffer
->header_line_format
);
16554 selected_frame
= old_selected_frame
;
16555 selected_window
= old_selected_window
;
16560 /* Display mode or top line of window W. FACE_ID specifies which line
16561 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16562 FORMAT is the mode line format to display. Value is the pixel
16563 height of the mode line displayed. */
16566 display_mode_line (w
, face_id
, format
)
16568 enum face_id face_id
;
16569 Lisp_Object format
;
16573 int count
= SPECPDL_INDEX ();
16575 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16576 prepare_desired_row (it
.glyph_row
);
16578 it
.glyph_row
->mode_line_p
= 1;
16580 if (! mode_line_inverse_video
)
16581 /* Force the mode-line to be displayed in the default face. */
16582 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16584 record_unwind_protect (unwind_format_mode_line
,
16585 format_mode_line_unwind_data (NULL
, 0));
16587 mode_line_target
= MODE_LINE_DISPLAY
;
16589 /* Temporarily make frame's keyboard the current kboard so that
16590 kboard-local variables in the mode_line_format will get the right
16592 push_frame_kboard (it
.f
);
16593 record_unwind_save_match_data ();
16594 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16595 pop_frame_kboard ();
16597 unbind_to (count
, Qnil
);
16599 /* Fill up with spaces. */
16600 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16602 compute_line_metrics (&it
);
16603 it
.glyph_row
->full_width_p
= 1;
16604 it
.glyph_row
->continued_p
= 0;
16605 it
.glyph_row
->truncated_on_left_p
= 0;
16606 it
.glyph_row
->truncated_on_right_p
= 0;
16608 /* Make a 3D mode-line have a shadow at its right end. */
16609 face
= FACE_FROM_ID (it
.f
, face_id
);
16610 extend_face_to_end_of_line (&it
);
16611 if (face
->box
!= FACE_NO_BOX
)
16613 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16614 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16615 last
->right_box_line_p
= 1;
16618 return it
.glyph_row
->height
;
16621 /* Move element ELT in LIST to the front of LIST.
16622 Return the updated list. */
16625 move_elt_to_front (elt
, list
)
16626 Lisp_Object elt
, list
;
16628 register Lisp_Object tail
, prev
;
16629 register Lisp_Object tem
;
16633 while (CONSP (tail
))
16639 /* Splice out the link TAIL. */
16641 list
= XCDR (tail
);
16643 Fsetcdr (prev
, XCDR (tail
));
16645 /* Now make it the first. */
16646 Fsetcdr (tail
, list
);
16651 tail
= XCDR (tail
);
16655 /* Not found--return unchanged LIST. */
16659 /* Contribute ELT to the mode line for window IT->w. How it
16660 translates into text depends on its data type.
16662 IT describes the display environment in which we display, as usual.
16664 DEPTH is the depth in recursion. It is used to prevent
16665 infinite recursion here.
16667 FIELD_WIDTH is the number of characters the display of ELT should
16668 occupy in the mode line, and PRECISION is the maximum number of
16669 characters to display from ELT's representation. See
16670 display_string for details.
16672 Returns the hpos of the end of the text generated by ELT.
16674 PROPS is a property list to add to any string we encounter.
16676 If RISKY is nonzero, remove (disregard) any properties in any string
16677 we encounter, and ignore :eval and :propertize.
16679 The global variable `mode_line_target' determines whether the
16680 output is passed to `store_mode_line_noprop',
16681 `store_mode_line_string', or `display_string'. */
16684 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16687 int field_width
, precision
;
16688 Lisp_Object elt
, props
;
16691 int n
= 0, field
, prec
;
16696 elt
= build_string ("*too-deep*");
16700 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16704 /* A string: output it and check for %-constructs within it. */
16708 if (SCHARS (elt
) > 0
16709 && (!NILP (props
) || risky
))
16711 Lisp_Object oprops
, aelt
;
16712 oprops
= Ftext_properties_at (make_number (0), elt
);
16714 /* If the starting string's properties are not what
16715 we want, translate the string. Also, if the string
16716 is risky, do that anyway. */
16718 if (NILP (Fequal (props
, oprops
)) || risky
)
16720 /* If the starting string has properties,
16721 merge the specified ones onto the existing ones. */
16722 if (! NILP (oprops
) && !risky
)
16726 oprops
= Fcopy_sequence (oprops
);
16728 while (CONSP (tem
))
16730 oprops
= Fplist_put (oprops
, XCAR (tem
),
16731 XCAR (XCDR (tem
)));
16732 tem
= XCDR (XCDR (tem
));
16737 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16738 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16740 /* AELT is what we want. Move it to the front
16741 without consing. */
16743 mode_line_proptrans_alist
16744 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16750 /* If AELT has the wrong props, it is useless.
16751 so get rid of it. */
16753 mode_line_proptrans_alist
16754 = Fdelq (aelt
, mode_line_proptrans_alist
);
16756 elt
= Fcopy_sequence (elt
);
16757 Fset_text_properties (make_number (0), Flength (elt
),
16759 /* Add this item to mode_line_proptrans_alist. */
16760 mode_line_proptrans_alist
16761 = Fcons (Fcons (elt
, props
),
16762 mode_line_proptrans_alist
);
16763 /* Truncate mode_line_proptrans_alist
16764 to at most 50 elements. */
16765 tem
= Fnthcdr (make_number (50),
16766 mode_line_proptrans_alist
);
16768 XSETCDR (tem
, Qnil
);
16777 prec
= precision
- n
;
16778 switch (mode_line_target
)
16780 case MODE_LINE_NOPROP
:
16781 case MODE_LINE_TITLE
:
16782 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16784 case MODE_LINE_STRING
:
16785 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16787 case MODE_LINE_DISPLAY
:
16788 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16789 0, prec
, 0, STRING_MULTIBYTE (elt
));
16796 /* Handle the non-literal case. */
16798 while ((precision
<= 0 || n
< precision
)
16799 && SREF (elt
, offset
) != 0
16800 && (mode_line_target
!= MODE_LINE_DISPLAY
16801 || it
->current_x
< it
->last_visible_x
))
16803 int last_offset
= offset
;
16805 /* Advance to end of string or next format specifier. */
16806 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16809 if (offset
- 1 != last_offset
)
16811 int nchars
, nbytes
;
16813 /* Output to end of string or up to '%'. Field width
16814 is length of string. Don't output more than
16815 PRECISION allows us. */
16818 prec
= c_string_width (SDATA (elt
) + last_offset
,
16819 offset
- last_offset
, precision
- n
,
16822 switch (mode_line_target
)
16824 case MODE_LINE_NOPROP
:
16825 case MODE_LINE_TITLE
:
16826 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16828 case MODE_LINE_STRING
:
16830 int bytepos
= last_offset
;
16831 int charpos
= string_byte_to_char (elt
, bytepos
);
16832 int endpos
= (precision
<= 0
16833 ? string_byte_to_char (elt
, offset
)
16834 : charpos
+ nchars
);
16836 n
+= store_mode_line_string (NULL
,
16837 Fsubstring (elt
, make_number (charpos
),
16838 make_number (endpos
)),
16842 case MODE_LINE_DISPLAY
:
16844 int bytepos
= last_offset
;
16845 int charpos
= string_byte_to_char (elt
, bytepos
);
16847 if (precision
<= 0)
16848 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16849 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16851 STRING_MULTIBYTE (elt
));
16856 else /* c == '%' */
16858 int percent_position
= offset
;
16860 /* Get the specified minimum width. Zero means
16863 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16864 field
= field
* 10 + c
- '0';
16866 /* Don't pad beyond the total padding allowed. */
16867 if (field_width
- n
> 0 && field
> field_width
- n
)
16868 field
= field_width
- n
;
16870 /* Note that either PRECISION <= 0 or N < PRECISION. */
16871 prec
= precision
- n
;
16874 n
+= display_mode_element (it
, depth
, field
, prec
,
16875 Vglobal_mode_string
, props
,
16880 int bytepos
, charpos
;
16881 unsigned char *spec
;
16883 bytepos
= percent_position
;
16884 charpos
= (STRING_MULTIBYTE (elt
)
16885 ? string_byte_to_char (elt
, bytepos
)
16889 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16891 switch (mode_line_target
)
16893 case MODE_LINE_NOPROP
:
16894 case MODE_LINE_TITLE
:
16895 n
+= store_mode_line_noprop (spec
, field
, prec
);
16897 case MODE_LINE_STRING
:
16899 int len
= strlen (spec
);
16900 Lisp_Object tem
= make_string (spec
, len
);
16901 props
= Ftext_properties_at (make_number (charpos
), elt
);
16902 /* Should only keep face property in props */
16903 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16906 case MODE_LINE_DISPLAY
:
16908 int nglyphs_before
, nwritten
;
16910 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16911 nwritten
= display_string (spec
, Qnil
, elt
,
16916 /* Assign to the glyphs written above the
16917 string where the `%x' came from, position
16921 struct glyph
*glyph
16922 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16926 for (i
= 0; i
< nwritten
; ++i
)
16928 glyph
[i
].object
= elt
;
16929 glyph
[i
].charpos
= charpos
;
16946 /* A symbol: process the value of the symbol recursively
16947 as if it appeared here directly. Avoid error if symbol void.
16948 Special case: if value of symbol is a string, output the string
16951 register Lisp_Object tem
;
16953 /* If the variable is not marked as risky to set
16954 then its contents are risky to use. */
16955 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16958 tem
= Fboundp (elt
);
16961 tem
= Fsymbol_value (elt
);
16962 /* If value is a string, output that string literally:
16963 don't check for % within it. */
16967 if (!EQ (tem
, elt
))
16969 /* Give up right away for nil or t. */
16979 register Lisp_Object car
, tem
;
16981 /* A cons cell: five distinct cases.
16982 If first element is :eval or :propertize, do something special.
16983 If first element is a string or a cons, process all the elements
16984 and effectively concatenate them.
16985 If first element is a negative number, truncate displaying cdr to
16986 at most that many characters. If positive, pad (with spaces)
16987 to at least that many characters.
16988 If first element is a symbol, process the cadr or caddr recursively
16989 according to whether the symbol's value is non-nil or nil. */
16991 if (EQ (car
, QCeval
))
16993 /* An element of the form (:eval FORM) means evaluate FORM
16994 and use the result as mode line elements. */
16999 if (CONSP (XCDR (elt
)))
17002 spec
= safe_eval (XCAR (XCDR (elt
)));
17003 n
+= display_mode_element (it
, depth
, field_width
- n
,
17004 precision
- n
, spec
, props
,
17008 else if (EQ (car
, QCpropertize
))
17010 /* An element of the form (:propertize ELT PROPS...)
17011 means display ELT but applying properties PROPS. */
17016 if (CONSP (XCDR (elt
)))
17017 n
+= display_mode_element (it
, depth
, field_width
- n
,
17018 precision
- n
, XCAR (XCDR (elt
)),
17019 XCDR (XCDR (elt
)), risky
);
17021 else if (SYMBOLP (car
))
17023 tem
= Fboundp (car
);
17027 /* elt is now the cdr, and we know it is a cons cell.
17028 Use its car if CAR has a non-nil value. */
17031 tem
= Fsymbol_value (car
);
17038 /* Symbol's value is nil (or symbol is unbound)
17039 Get the cddr of the original list
17040 and if possible find the caddr and use that. */
17044 else if (!CONSP (elt
))
17049 else if (INTEGERP (car
))
17051 register int lim
= XINT (car
);
17055 /* Negative int means reduce maximum width. */
17056 if (precision
<= 0)
17059 precision
= min (precision
, -lim
);
17063 /* Padding specified. Don't let it be more than
17064 current maximum. */
17066 lim
= min (precision
, lim
);
17068 /* If that's more padding than already wanted, queue it.
17069 But don't reduce padding already specified even if
17070 that is beyond the current truncation point. */
17071 field_width
= max (lim
, field_width
);
17075 else if (STRINGP (car
) || CONSP (car
))
17077 register int limit
= 50;
17078 /* Limit is to protect against circular lists. */
17081 && (precision
<= 0 || n
< precision
))
17083 n
+= display_mode_element (it
, depth
,
17084 /* Do padding only after the last
17085 element in the list. */
17086 (! CONSP (XCDR (elt
))
17089 precision
- n
, XCAR (elt
),
17099 elt
= build_string ("*invalid*");
17103 /* Pad to FIELD_WIDTH. */
17104 if (field_width
> 0 && n
< field_width
)
17106 switch (mode_line_target
)
17108 case MODE_LINE_NOPROP
:
17109 case MODE_LINE_TITLE
:
17110 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17112 case MODE_LINE_STRING
:
17113 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17115 case MODE_LINE_DISPLAY
:
17116 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17125 /* Store a mode-line string element in mode_line_string_list.
17127 If STRING is non-null, display that C string. Otherwise, the Lisp
17128 string LISP_STRING is displayed.
17130 FIELD_WIDTH is the minimum number of output glyphs to produce.
17131 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17132 with spaces. FIELD_WIDTH <= 0 means don't pad.
17134 PRECISION is the maximum number of characters to output from
17135 STRING. PRECISION <= 0 means don't truncate the string.
17137 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17138 properties to the string.
17140 PROPS are the properties to add to the string.
17141 The mode_line_string_face face property is always added to the string.
17145 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17147 Lisp_Object lisp_string
;
17156 if (string
!= NULL
)
17158 len
= strlen (string
);
17159 if (precision
> 0 && len
> precision
)
17161 lisp_string
= make_string (string
, len
);
17163 props
= mode_line_string_face_prop
;
17164 else if (!NILP (mode_line_string_face
))
17166 Lisp_Object face
= Fplist_get (props
, Qface
);
17167 props
= Fcopy_sequence (props
);
17169 face
= mode_line_string_face
;
17171 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17172 props
= Fplist_put (props
, Qface
, face
);
17174 Fadd_text_properties (make_number (0), make_number (len
),
17175 props
, lisp_string
);
17179 len
= XFASTINT (Flength (lisp_string
));
17180 if (precision
> 0 && len
> precision
)
17183 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17186 if (!NILP (mode_line_string_face
))
17190 props
= Ftext_properties_at (make_number (0), lisp_string
);
17191 face
= Fplist_get (props
, Qface
);
17193 face
= mode_line_string_face
;
17195 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17196 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17198 lisp_string
= Fcopy_sequence (lisp_string
);
17201 Fadd_text_properties (make_number (0), make_number (len
),
17202 props
, lisp_string
);
17207 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17211 if (field_width
> len
)
17213 field_width
-= len
;
17214 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17216 Fadd_text_properties (make_number (0), make_number (field_width
),
17217 props
, lisp_string
);
17218 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17226 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17228 doc
: /* Format a string out of a mode line format specification.
17229 First arg FORMAT specifies the mode line format (see `mode-line-format'
17230 for details) to use.
17232 Optional second arg FACE specifies the face property to put
17233 on all characters for which no face is specified.
17234 t means whatever face the window's mode line currently uses
17235 \(either `mode-line' or `mode-line-inactive', depending).
17236 nil means the default is no face property.
17237 If FACE is an integer, the value string has no text properties.
17239 Optional third and fourth args WINDOW and BUFFER specify the window
17240 and buffer to use as the context for the formatting (defaults
17241 are the selected window and the window's buffer). */)
17242 (format
, face
, window
, buffer
)
17243 Lisp_Object format
, face
, window
, buffer
;
17248 struct buffer
*old_buffer
= NULL
;
17250 int no_props
= INTEGERP (face
);
17251 int count
= SPECPDL_INDEX ();
17253 int string_start
= 0;
17256 window
= selected_window
;
17257 CHECK_WINDOW (window
);
17258 w
= XWINDOW (window
);
17261 buffer
= w
->buffer
;
17262 CHECK_BUFFER (buffer
);
17265 return build_string ("");
17273 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17274 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17278 face_id
= DEFAULT_FACE_ID
;
17280 if (XBUFFER (buffer
) != current_buffer
)
17281 old_buffer
= current_buffer
;
17283 /* Save things including mode_line_proptrans_alist,
17284 and set that to nil so that we don't alter the outer value. */
17285 record_unwind_protect (unwind_format_mode_line
,
17286 format_mode_line_unwind_data (old_buffer
, 1));
17287 mode_line_proptrans_alist
= Qnil
;
17290 set_buffer_internal_1 (XBUFFER (buffer
));
17292 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17296 mode_line_target
= MODE_LINE_NOPROP
;
17297 mode_line_string_face_prop
= Qnil
;
17298 mode_line_string_list
= Qnil
;
17299 string_start
= MODE_LINE_NOPROP_LEN (0);
17303 mode_line_target
= MODE_LINE_STRING
;
17304 mode_line_string_list
= Qnil
;
17305 mode_line_string_face
= face
;
17306 mode_line_string_face_prop
17307 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17310 push_frame_kboard (it
.f
);
17311 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17312 pop_frame_kboard ();
17316 len
= MODE_LINE_NOPROP_LEN (string_start
);
17317 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17321 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17322 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17323 make_string ("", 0));
17326 unbind_to (count
, Qnil
);
17330 /* Write a null-terminated, right justified decimal representation of
17331 the positive integer D to BUF using a minimal field width WIDTH. */
17334 pint2str (buf
, width
, d
)
17335 register char *buf
;
17336 register int width
;
17339 register char *p
= buf
;
17347 *p
++ = d
% 10 + '0';
17352 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17363 /* Write a null-terminated, right justified decimal and "human
17364 readable" representation of the nonnegative integer D to BUF using
17365 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17367 static const char power_letter
[] =
17381 pint2hrstr (buf
, width
, d
)
17386 /* We aim to represent the nonnegative integer D as
17387 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17390 /* -1 means: do not use TENTHS. */
17394 /* Length of QUOTIENT.TENTHS as a string. */
17400 if (1000 <= quotient
)
17402 /* Scale to the appropriate EXPONENT. */
17405 remainder
= quotient
% 1000;
17409 while (1000 <= quotient
);
17411 /* Round to nearest and decide whether to use TENTHS or not. */
17414 tenths
= remainder
/ 100;
17415 if (50 <= remainder
% 100)
17422 if (quotient
== 10)
17430 if (500 <= remainder
)
17432 if (quotient
< 999)
17443 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17444 if (tenths
== -1 && quotient
<= 99)
17451 p
= psuffix
= buf
+ max (width
, length
);
17453 /* Print EXPONENT. */
17455 *psuffix
++ = power_letter
[exponent
];
17458 /* Print TENTHS. */
17461 *--p
= '0' + tenths
;
17465 /* Print QUOTIENT. */
17468 int digit
= quotient
% 10;
17469 *--p
= '0' + digit
;
17471 while ((quotient
/= 10) != 0);
17473 /* Print leading spaces. */
17478 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17479 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17480 type of CODING_SYSTEM. Return updated pointer into BUF. */
17482 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17485 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17486 Lisp_Object coding_system
;
17487 register char *buf
;
17491 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17492 const unsigned char *eol_str
;
17494 /* The EOL conversion we are using. */
17495 Lisp_Object eoltype
;
17497 val
= Fget (coding_system
, Qcoding_system
);
17500 if (!VECTORP (val
)) /* Not yet decided. */
17505 eoltype
= eol_mnemonic_undecided
;
17506 /* Don't mention EOL conversion if it isn't decided. */
17510 Lisp_Object eolvalue
;
17512 eolvalue
= Fget (coding_system
, Qeol_type
);
17515 *buf
++ = XFASTINT (AREF (val
, 1));
17519 /* The EOL conversion that is normal on this system. */
17521 if (NILP (eolvalue
)) /* Not yet decided. */
17522 eoltype
= eol_mnemonic_undecided
;
17523 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17524 eoltype
= eol_mnemonic_undecided
;
17525 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17526 eoltype
= (XFASTINT (eolvalue
) == 0
17527 ? eol_mnemonic_unix
17528 : (XFASTINT (eolvalue
) == 1
17529 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17535 /* Mention the EOL conversion if it is not the usual one. */
17536 if (STRINGP (eoltype
))
17538 eol_str
= SDATA (eoltype
);
17539 eol_str_len
= SBYTES (eoltype
);
17541 else if (INTEGERP (eoltype
)
17542 && CHAR_VALID_P (XINT (eoltype
), 0))
17544 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17545 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17550 eol_str
= invalid_eol_type
;
17551 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17553 bcopy (eol_str
, buf
, eol_str_len
);
17554 buf
+= eol_str_len
;
17560 /* Return a string for the output of a mode line %-spec for window W,
17561 generated by character C. PRECISION >= 0 means don't return a
17562 string longer than that value. FIELD_WIDTH > 0 means pad the
17563 string returned with spaces to that value. Return 1 in *MULTIBYTE
17564 if the result is multibyte text.
17566 Note we operate on the current buffer for most purposes,
17567 the exception being w->base_line_pos. */
17569 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17572 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17575 int field_width
, precision
;
17579 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17580 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17581 struct buffer
*b
= current_buffer
;
17589 if (!NILP (b
->read_only
))
17591 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17596 /* This differs from %* only for a modified read-only buffer. */
17597 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17599 if (!NILP (b
->read_only
))
17604 /* This differs from %* in ignoring read-only-ness. */
17605 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17617 if (command_loop_level
> 5)
17619 p
= decode_mode_spec_buf
;
17620 for (i
= 0; i
< command_loop_level
; i
++)
17623 return decode_mode_spec_buf
;
17631 if (command_loop_level
> 5)
17633 p
= decode_mode_spec_buf
;
17634 for (i
= 0; i
< command_loop_level
; i
++)
17637 return decode_mode_spec_buf
;
17644 /* Let lots_of_dashes be a string of infinite length. */
17645 if (mode_line_target
== MODE_LINE_NOPROP
||
17646 mode_line_target
== MODE_LINE_STRING
)
17648 if (field_width
<= 0
17649 || field_width
> sizeof (lots_of_dashes
))
17651 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17652 decode_mode_spec_buf
[i
] = '-';
17653 decode_mode_spec_buf
[i
] = '\0';
17654 return decode_mode_spec_buf
;
17657 return lots_of_dashes
;
17666 int col
= (int) current_column (); /* iftc */
17667 w
->column_number_displayed
= make_number (col
);
17668 pint2str (decode_mode_spec_buf
, field_width
, col
);
17669 return decode_mode_spec_buf
;
17673 #ifndef SYSTEM_MALLOC
17675 if (NILP (Vmemory_full
))
17678 return "!MEM FULL! ";
17685 /* %F displays the frame name. */
17686 if (!NILP (f
->title
))
17687 return (char *) SDATA (f
->title
);
17688 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17689 return (char *) SDATA (f
->name
);
17698 int size
= ZV
- BEGV
;
17699 pint2str (decode_mode_spec_buf
, field_width
, size
);
17700 return decode_mode_spec_buf
;
17705 int size
= ZV
- BEGV
;
17706 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17707 return decode_mode_spec_buf
;
17712 int startpos
= XMARKER (w
->start
)->charpos
;
17713 int startpos_byte
= marker_byte_position (w
->start
);
17714 int line
, linepos
, linepos_byte
, topline
;
17716 int height
= WINDOW_TOTAL_LINES (w
);
17718 /* If we decided that this buffer isn't suitable for line numbers,
17719 don't forget that too fast. */
17720 if (EQ (w
->base_line_pos
, w
->buffer
))
17722 /* But do forget it, if the window shows a different buffer now. */
17723 else if (BUFFERP (w
->base_line_pos
))
17724 w
->base_line_pos
= Qnil
;
17726 /* If the buffer is very big, don't waste time. */
17727 if (INTEGERP (Vline_number_display_limit
)
17728 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17730 w
->base_line_pos
= Qnil
;
17731 w
->base_line_number
= Qnil
;
17735 if (!NILP (w
->base_line_number
)
17736 && !NILP (w
->base_line_pos
)
17737 && XFASTINT (w
->base_line_pos
) <= startpos
)
17739 line
= XFASTINT (w
->base_line_number
);
17740 linepos
= XFASTINT (w
->base_line_pos
);
17741 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17746 linepos
= BUF_BEGV (b
);
17747 linepos_byte
= BUF_BEGV_BYTE (b
);
17750 /* Count lines from base line to window start position. */
17751 nlines
= display_count_lines (linepos
, linepos_byte
,
17755 topline
= nlines
+ line
;
17757 /* Determine a new base line, if the old one is too close
17758 or too far away, or if we did not have one.
17759 "Too close" means it's plausible a scroll-down would
17760 go back past it. */
17761 if (startpos
== BUF_BEGV (b
))
17763 w
->base_line_number
= make_number (topline
);
17764 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17766 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17767 || linepos
== BUF_BEGV (b
))
17769 int limit
= BUF_BEGV (b
);
17770 int limit_byte
= BUF_BEGV_BYTE (b
);
17772 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17774 if (startpos
- distance
> limit
)
17776 limit
= startpos
- distance
;
17777 limit_byte
= CHAR_TO_BYTE (limit
);
17780 nlines
= display_count_lines (startpos
, startpos_byte
,
17782 - (height
* 2 + 30),
17784 /* If we couldn't find the lines we wanted within
17785 line_number_display_limit_width chars per line,
17786 give up on line numbers for this window. */
17787 if (position
== limit_byte
&& limit
== startpos
- distance
)
17789 w
->base_line_pos
= w
->buffer
;
17790 w
->base_line_number
= Qnil
;
17794 w
->base_line_number
= make_number (topline
- nlines
);
17795 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17798 /* Now count lines from the start pos to point. */
17799 nlines
= display_count_lines (startpos
, startpos_byte
,
17800 PT_BYTE
, PT
, &junk
);
17802 /* Record that we did display the line number. */
17803 line_number_displayed
= 1;
17805 /* Make the string to show. */
17806 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17807 return decode_mode_spec_buf
;
17810 char* p
= decode_mode_spec_buf
;
17811 int pad
= field_width
- 2;
17817 return decode_mode_spec_buf
;
17823 obj
= b
->mode_name
;
17827 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17833 int pos
= marker_position (w
->start
);
17834 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17836 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17838 if (pos
<= BUF_BEGV (b
))
17843 else if (pos
<= BUF_BEGV (b
))
17847 if (total
> 1000000)
17848 /* Do it differently for a large value, to avoid overflow. */
17849 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17851 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17852 /* We can't normally display a 3-digit number,
17853 so get us a 2-digit number that is close. */
17856 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17857 return decode_mode_spec_buf
;
17861 /* Display percentage of size above the bottom of the screen. */
17864 int toppos
= marker_position (w
->start
);
17865 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17866 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17868 if (botpos
>= BUF_ZV (b
))
17870 if (toppos
<= BUF_BEGV (b
))
17877 if (total
> 1000000)
17878 /* Do it differently for a large value, to avoid overflow. */
17879 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17881 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17882 /* We can't normally display a 3-digit number,
17883 so get us a 2-digit number that is close. */
17886 if (toppos
<= BUF_BEGV (b
))
17887 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17889 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17890 return decode_mode_spec_buf
;
17895 /* status of process */
17896 obj
= Fget_buffer_process (Fcurrent_buffer ());
17898 return "no process";
17899 #ifdef subprocesses
17900 obj
= Fsymbol_name (Fprocess_status (obj
));
17904 case 't': /* indicate TEXT or BINARY */
17905 #ifdef MODE_LINE_BINARY_TEXT
17906 return MODE_LINE_BINARY_TEXT (b
);
17912 /* coding-system (not including end-of-line format) */
17914 /* coding-system (including end-of-line type) */
17916 int eol_flag
= (c
== 'Z');
17917 char *p
= decode_mode_spec_buf
;
17919 if (! FRAME_WINDOW_P (f
))
17921 /* No need to mention EOL here--the terminal never needs
17922 to do EOL conversion. */
17923 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17924 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17926 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17929 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17930 #ifdef subprocesses
17931 obj
= Fget_buffer_process (Fcurrent_buffer ());
17932 if (PROCESSP (obj
))
17934 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17936 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17939 #endif /* subprocesses */
17942 return decode_mode_spec_buf
;
17948 *multibyte
= STRING_MULTIBYTE (obj
);
17949 return (char *) SDATA (obj
);
17956 /* Count up to COUNT lines starting from START / START_BYTE.
17957 But don't go beyond LIMIT_BYTE.
17958 Return the number of lines thus found (always nonnegative).
17960 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17963 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17964 int start
, start_byte
, limit_byte
, count
;
17967 register unsigned char *cursor
;
17968 unsigned char *base
;
17970 register int ceiling
;
17971 register unsigned char *ceiling_addr
;
17972 int orig_count
= count
;
17974 /* If we are not in selective display mode,
17975 check only for newlines. */
17976 int selective_display
= (!NILP (current_buffer
->selective_display
)
17977 && !INTEGERP (current_buffer
->selective_display
));
17981 while (start_byte
< limit_byte
)
17983 ceiling
= BUFFER_CEILING_OF (start_byte
);
17984 ceiling
= min (limit_byte
- 1, ceiling
);
17985 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17986 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17989 if (selective_display
)
17990 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17993 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17996 if (cursor
!= ceiling_addr
)
18000 start_byte
+= cursor
- base
+ 1;
18001 *byte_pos_ptr
= start_byte
;
18005 if (++cursor
== ceiling_addr
)
18011 start_byte
+= cursor
- base
;
18016 while (start_byte
> limit_byte
)
18018 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18019 ceiling
= max (limit_byte
, ceiling
);
18020 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18021 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18024 if (selective_display
)
18025 while (--cursor
!= ceiling_addr
18026 && *cursor
!= '\n' && *cursor
!= 015)
18029 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18032 if (cursor
!= ceiling_addr
)
18036 start_byte
+= cursor
- base
+ 1;
18037 *byte_pos_ptr
= start_byte
;
18038 /* When scanning backwards, we should
18039 not count the newline posterior to which we stop. */
18040 return - orig_count
- 1;
18046 /* Here we add 1 to compensate for the last decrement
18047 of CURSOR, which took it past the valid range. */
18048 start_byte
+= cursor
- base
+ 1;
18052 *byte_pos_ptr
= limit_byte
;
18055 return - orig_count
+ count
;
18056 return orig_count
- count
;
18062 /***********************************************************************
18064 ***********************************************************************/
18066 /* Display a NUL-terminated string, starting with index START.
18068 If STRING is non-null, display that C string. Otherwise, the Lisp
18069 string LISP_STRING is displayed.
18071 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18072 FACE_STRING. Display STRING or LISP_STRING with the face at
18073 FACE_STRING_POS in FACE_STRING:
18075 Display the string in the environment given by IT, but use the
18076 standard display table, temporarily.
18078 FIELD_WIDTH is the minimum number of output glyphs to produce.
18079 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18080 with spaces. If STRING has more characters, more than FIELD_WIDTH
18081 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18083 PRECISION is the maximum number of characters to output from
18084 STRING. PRECISION < 0 means don't truncate the string.
18086 This is roughly equivalent to printf format specifiers:
18088 FIELD_WIDTH PRECISION PRINTF
18089 ----------------------------------------
18095 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18096 display them, and < 0 means obey the current buffer's value of
18097 enable_multibyte_characters.
18099 Value is the number of columns displayed. */
18102 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18103 start
, it
, field_width
, precision
, max_x
, multibyte
)
18104 unsigned char *string
;
18105 Lisp_Object lisp_string
;
18106 Lisp_Object face_string
;
18107 int face_string_pos
;
18110 int field_width
, precision
, max_x
;
18113 int hpos_at_start
= it
->hpos
;
18114 int saved_face_id
= it
->face_id
;
18115 struct glyph_row
*row
= it
->glyph_row
;
18117 /* Initialize the iterator IT for iteration over STRING beginning
18118 with index START. */
18119 reseat_to_string (it
, string
, lisp_string
, start
,
18120 precision
, field_width
, multibyte
);
18122 /* If displaying STRING, set up the face of the iterator
18123 from LISP_STRING, if that's given. */
18124 if (STRINGP (face_string
))
18130 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18131 0, it
->region_beg_charpos
,
18132 it
->region_end_charpos
,
18133 &endptr
, it
->base_face_id
, 0);
18134 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18135 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18138 /* Set max_x to the maximum allowed X position. Don't let it go
18139 beyond the right edge of the window. */
18141 max_x
= it
->last_visible_x
;
18143 max_x
= min (max_x
, it
->last_visible_x
);
18145 /* Skip over display elements that are not visible. because IT->w is
18147 if (it
->current_x
< it
->first_visible_x
)
18148 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18149 MOVE_TO_POS
| MOVE_TO_X
);
18151 row
->ascent
= it
->max_ascent
;
18152 row
->height
= it
->max_ascent
+ it
->max_descent
;
18153 row
->phys_ascent
= it
->max_phys_ascent
;
18154 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18155 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18157 /* This condition is for the case that we are called with current_x
18158 past last_visible_x. */
18159 while (it
->current_x
< max_x
)
18161 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18163 /* Get the next display element. */
18164 if (!get_next_display_element (it
))
18167 /* Produce glyphs. */
18168 x_before
= it
->current_x
;
18169 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18170 PRODUCE_GLYPHS (it
);
18172 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18175 while (i
< nglyphs
)
18177 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18179 if (!it
->truncate_lines_p
18180 && x
+ glyph
->pixel_width
> max_x
)
18182 /* End of continued line or max_x reached. */
18183 if (CHAR_GLYPH_PADDING_P (*glyph
))
18185 /* A wide character is unbreakable. */
18186 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18187 it
->current_x
= x_before
;
18191 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18196 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18198 /* Glyph is at least partially visible. */
18200 if (x
< it
->first_visible_x
)
18201 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18205 /* Glyph is off the left margin of the display area.
18206 Should not happen. */
18210 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18211 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18212 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18213 row
->phys_height
= max (row
->phys_height
,
18214 it
->max_phys_ascent
+ it
->max_phys_descent
);
18215 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18216 it
->max_extra_line_spacing
);
18217 x
+= glyph
->pixel_width
;
18221 /* Stop if max_x reached. */
18225 /* Stop at line ends. */
18226 if (ITERATOR_AT_END_OF_LINE_P (it
))
18228 it
->continuation_lines_width
= 0;
18232 set_iterator_to_next (it
, 1);
18234 /* Stop if truncating at the right edge. */
18235 if (it
->truncate_lines_p
18236 && it
->current_x
>= it
->last_visible_x
)
18238 /* Add truncation mark, but don't do it if the line is
18239 truncated at a padding space. */
18240 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18242 if (!FRAME_WINDOW_P (it
->f
))
18246 if (it
->current_x
> it
->last_visible_x
)
18248 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18249 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18251 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18253 row
->used
[TEXT_AREA
] = i
;
18254 produce_special_glyphs (it
, IT_TRUNCATION
);
18257 produce_special_glyphs (it
, IT_TRUNCATION
);
18259 it
->glyph_row
->truncated_on_right_p
= 1;
18265 /* Maybe insert a truncation at the left. */
18266 if (it
->first_visible_x
18267 && IT_CHARPOS (*it
) > 0)
18269 if (!FRAME_WINDOW_P (it
->f
))
18270 insert_left_trunc_glyphs (it
);
18271 it
->glyph_row
->truncated_on_left_p
= 1;
18274 it
->face_id
= saved_face_id
;
18276 /* Value is number of columns displayed. */
18277 return it
->hpos
- hpos_at_start
;
18282 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18283 appears as an element of LIST or as the car of an element of LIST.
18284 If PROPVAL is a list, compare each element against LIST in that
18285 way, and return 1/2 if any element of PROPVAL is found in LIST.
18286 Otherwise return 0. This function cannot quit.
18287 The return value is 2 if the text is invisible but with an ellipsis
18288 and 1 if it's invisible and without an ellipsis. */
18291 invisible_p (propval
, list
)
18292 register Lisp_Object propval
;
18295 register Lisp_Object tail
, proptail
;
18297 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18299 register Lisp_Object tem
;
18301 if (EQ (propval
, tem
))
18303 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18304 return NILP (XCDR (tem
)) ? 1 : 2;
18307 if (CONSP (propval
))
18309 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18311 Lisp_Object propelt
;
18312 propelt
= XCAR (proptail
);
18313 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18315 register Lisp_Object tem
;
18317 if (EQ (propelt
, tem
))
18319 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18320 return NILP (XCDR (tem
)) ? 1 : 2;
18328 /* Calculate a width or height in pixels from a specification using
18329 the following elements:
18332 NUM - a (fractional) multiple of the default font width/height
18333 (NUM) - specifies exactly NUM pixels
18334 UNIT - a fixed number of pixels, see below.
18335 ELEMENT - size of a display element in pixels, see below.
18336 (NUM . SPEC) - equals NUM * SPEC
18337 (+ SPEC SPEC ...) - add pixel values
18338 (- SPEC SPEC ...) - subtract pixel values
18339 (- SPEC) - negate pixel value
18342 INT or FLOAT - a number constant
18343 SYMBOL - use symbol's (buffer local) variable binding.
18346 in - pixels per inch *)
18347 mm - pixels per 1/1000 meter *)
18348 cm - pixels per 1/100 meter *)
18349 width - width of current font in pixels.
18350 height - height of current font in pixels.
18352 *) using the ratio(s) defined in display-pixels-per-inch.
18356 left-fringe - left fringe width in pixels
18357 right-fringe - right fringe width in pixels
18359 left-margin - left margin width in pixels
18360 right-margin - right margin width in pixels
18362 scroll-bar - scroll-bar area width in pixels
18366 Pixels corresponding to 5 inches:
18369 Total width of non-text areas on left side of window (if scroll-bar is on left):
18370 '(space :width (+ left-fringe left-margin scroll-bar))
18372 Align to first text column (in header line):
18373 '(space :align-to 0)
18375 Align to middle of text area minus half the width of variable `my-image'
18376 containing a loaded image:
18377 '(space :align-to (0.5 . (- text my-image)))
18379 Width of left margin minus width of 1 character in the default font:
18380 '(space :width (- left-margin 1))
18382 Width of left margin minus width of 2 characters in the current font:
18383 '(space :width (- left-margin (2 . width)))
18385 Center 1 character over left-margin (in header line):
18386 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18388 Different ways to express width of left fringe plus left margin minus one pixel:
18389 '(space :width (- (+ left-fringe left-margin) (1)))
18390 '(space :width (+ left-fringe left-margin (- (1))))
18391 '(space :width (+ left-fringe left-margin (-1)))
18395 #define NUMVAL(X) \
18396 ((INTEGERP (X) || FLOATP (X)) \
18401 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18406 int width_p
, *align_to
;
18410 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18411 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18414 return OK_PIXELS (0);
18416 if (SYMBOLP (prop
))
18418 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18420 char *unit
= SDATA (SYMBOL_NAME (prop
));
18422 if (unit
[0] == 'i' && unit
[1] == 'n')
18424 else if (unit
[0] == 'm' && unit
[1] == 'm')
18426 else if (unit
[0] == 'c' && unit
[1] == 'm')
18433 #ifdef HAVE_WINDOW_SYSTEM
18434 if (FRAME_WINDOW_P (it
->f
)
18436 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18437 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18439 return OK_PIXELS (ppi
/ pixels
);
18442 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18443 || (CONSP (Vdisplay_pixels_per_inch
)
18445 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18446 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18448 return OK_PIXELS (ppi
/ pixels
);
18454 #ifdef HAVE_WINDOW_SYSTEM
18455 if (EQ (prop
, Qheight
))
18456 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18457 if (EQ (prop
, Qwidth
))
18458 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18460 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18461 return OK_PIXELS (1);
18464 if (EQ (prop
, Qtext
))
18465 return OK_PIXELS (width_p
18466 ? window_box_width (it
->w
, TEXT_AREA
)
18467 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18469 if (align_to
&& *align_to
< 0)
18472 if (EQ (prop
, Qleft
))
18473 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18474 if (EQ (prop
, Qright
))
18475 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18476 if (EQ (prop
, Qcenter
))
18477 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18478 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18479 if (EQ (prop
, Qleft_fringe
))
18480 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18481 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18482 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18483 if (EQ (prop
, Qright_fringe
))
18484 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18485 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18486 : window_box_right_offset (it
->w
, TEXT_AREA
));
18487 if (EQ (prop
, Qleft_margin
))
18488 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18489 if (EQ (prop
, Qright_margin
))
18490 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18491 if (EQ (prop
, Qscroll_bar
))
18492 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18494 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18495 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18496 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18501 if (EQ (prop
, Qleft_fringe
))
18502 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18503 if (EQ (prop
, Qright_fringe
))
18504 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18505 if (EQ (prop
, Qleft_margin
))
18506 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18507 if (EQ (prop
, Qright_margin
))
18508 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18509 if (EQ (prop
, Qscroll_bar
))
18510 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18513 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18516 if (INTEGERP (prop
) || FLOATP (prop
))
18518 int base_unit
= (width_p
18519 ? FRAME_COLUMN_WIDTH (it
->f
)
18520 : FRAME_LINE_HEIGHT (it
->f
));
18521 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18526 Lisp_Object car
= XCAR (prop
);
18527 Lisp_Object cdr
= XCDR (prop
);
18531 #ifdef HAVE_WINDOW_SYSTEM
18532 if (valid_image_p (prop
))
18534 int id
= lookup_image (it
->f
, prop
);
18535 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18537 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18540 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18546 while (CONSP (cdr
))
18548 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18549 font
, width_p
, align_to
))
18552 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18557 if (EQ (car
, Qminus
))
18559 return OK_PIXELS (pixels
);
18562 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18565 if (INTEGERP (car
) || FLOATP (car
))
18568 pixels
= XFLOATINT (car
);
18570 return OK_PIXELS (pixels
);
18571 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18572 font
, width_p
, align_to
))
18573 return OK_PIXELS (pixels
* fact
);
18584 /***********************************************************************
18586 ***********************************************************************/
18588 #ifdef HAVE_WINDOW_SYSTEM
18593 dump_glyph_string (s
)
18594 struct glyph_string
*s
;
18596 fprintf (stderr
, "glyph string\n");
18597 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18598 s
->x
, s
->y
, s
->width
, s
->height
);
18599 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18600 fprintf (stderr
, " hl = %d\n", s
->hl
);
18601 fprintf (stderr
, " left overhang = %d, right = %d\n",
18602 s
->left_overhang
, s
->right_overhang
);
18603 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18604 fprintf (stderr
, " extends to end of line = %d\n",
18605 s
->extends_to_end_of_line_p
);
18606 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18607 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18610 #endif /* GLYPH_DEBUG */
18612 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18613 of XChar2b structures for S; it can't be allocated in
18614 init_glyph_string because it must be allocated via `alloca'. W
18615 is the window on which S is drawn. ROW and AREA are the glyph row
18616 and area within the row from which S is constructed. START is the
18617 index of the first glyph structure covered by S. HL is a
18618 face-override for drawing S. */
18621 #define OPTIONAL_HDC(hdc) hdc,
18622 #define DECLARE_HDC(hdc) HDC hdc;
18623 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18624 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18627 #ifndef OPTIONAL_HDC
18628 #define OPTIONAL_HDC(hdc)
18629 #define DECLARE_HDC(hdc)
18630 #define ALLOCATE_HDC(hdc, f)
18631 #define RELEASE_HDC(hdc, f)
18635 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18636 struct glyph_string
*s
;
18640 struct glyph_row
*row
;
18641 enum glyph_row_area area
;
18643 enum draw_glyphs_face hl
;
18645 bzero (s
, sizeof *s
);
18647 s
->f
= XFRAME (w
->frame
);
18651 s
->display
= FRAME_X_DISPLAY (s
->f
);
18652 s
->window
= FRAME_X_WINDOW (s
->f
);
18653 s
->char2b
= char2b
;
18657 s
->first_glyph
= row
->glyphs
[area
] + start
;
18658 s
->height
= row
->height
;
18659 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18661 /* Display the internal border below the tool-bar window. */
18662 if (WINDOWP (s
->f
->tool_bar_window
)
18663 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18664 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18666 s
->ybase
= s
->y
+ row
->ascent
;
18670 /* Append the list of glyph strings with head H and tail T to the list
18671 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18674 append_glyph_string_lists (head
, tail
, h
, t
)
18675 struct glyph_string
**head
, **tail
;
18676 struct glyph_string
*h
, *t
;
18690 /* Prepend the list of glyph strings with head H and tail T to the
18691 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18695 prepend_glyph_string_lists (head
, tail
, h
, t
)
18696 struct glyph_string
**head
, **tail
;
18697 struct glyph_string
*h
, *t
;
18711 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18712 Set *HEAD and *TAIL to the resulting list. */
18715 append_glyph_string (head
, tail
, s
)
18716 struct glyph_string
**head
, **tail
;
18717 struct glyph_string
*s
;
18719 s
->next
= s
->prev
= NULL
;
18720 append_glyph_string_lists (head
, tail
, s
, s
);
18724 /* Get face and two-byte form of character glyph GLYPH on frame F.
18725 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18726 a pointer to a realized face that is ready for display. */
18728 static INLINE
struct face
*
18729 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18731 struct glyph
*glyph
;
18737 xassert (glyph
->type
== CHAR_GLYPH
);
18738 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18743 if (!glyph
->multibyte_p
)
18745 /* Unibyte case. We don't have to encode, but we have to make
18746 sure to use a face suitable for unibyte. */
18747 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18749 else if (glyph
->u
.ch
< 128)
18751 /* Case of ASCII in a face known to fit ASCII. */
18752 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18756 int c1
, c2
, charset
;
18758 /* Split characters into bytes. If c2 is -1 afterwards, C is
18759 really a one-byte character so that byte1 is zero. */
18760 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18762 STORE_XCHAR2B (char2b
, c1
, c2
);
18764 STORE_XCHAR2B (char2b
, 0, c1
);
18766 /* Maybe encode the character in *CHAR2B. */
18767 if (charset
!= CHARSET_ASCII
)
18769 struct font_info
*font_info
18770 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18773 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18777 /* Make sure X resources of the face are allocated. */
18778 xassert (face
!= NULL
);
18779 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18784 /* Fill glyph string S with composition components specified by S->cmp.
18786 FACES is an array of faces for all components of this composition.
18787 S->gidx is the index of the first component for S.
18789 OVERLAPS non-zero means S should draw the foreground only, and use
18790 its physical height for clipping. See also draw_glyphs.
18792 Value is the index of a component not in S. */
18795 fill_composite_glyph_string (s
, faces
, overlaps
)
18796 struct glyph_string
*s
;
18797 struct face
**faces
;
18804 s
->for_overlaps
= overlaps
;
18806 s
->face
= faces
[s
->gidx
];
18807 s
->font
= s
->face
->font
;
18808 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18810 /* For all glyphs of this composition, starting at the offset
18811 S->gidx, until we reach the end of the definition or encounter a
18812 glyph that requires the different face, add it to S. */
18814 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18817 /* All glyph strings for the same composition has the same width,
18818 i.e. the width set for the first component of the composition. */
18820 s
->width
= s
->first_glyph
->pixel_width
;
18822 /* If the specified font could not be loaded, use the frame's
18823 default font, but record the fact that we couldn't load it in
18824 the glyph string so that we can draw rectangles for the
18825 characters of the glyph string. */
18826 if (s
->font
== NULL
)
18828 s
->font_not_found_p
= 1;
18829 s
->font
= FRAME_FONT (s
->f
);
18832 /* Adjust base line for subscript/superscript text. */
18833 s
->ybase
+= s
->first_glyph
->voffset
;
18835 xassert (s
->face
&& s
->face
->gc
);
18837 /* This glyph string must always be drawn with 16-bit functions. */
18840 return s
->gidx
+ s
->nchars
;
18844 /* Fill glyph string S from a sequence of character glyphs.
18846 FACE_ID is the face id of the string. START is the index of the
18847 first glyph to consider, END is the index of the last + 1.
18848 OVERLAPS non-zero means S should draw the foreground only, and use
18849 its physical height for clipping. See also draw_glyphs.
18851 Value is the index of the first glyph not in S. */
18854 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18855 struct glyph_string
*s
;
18857 int start
, end
, overlaps
;
18859 struct glyph
*glyph
, *last
;
18861 int glyph_not_available_p
;
18863 xassert (s
->f
== XFRAME (s
->w
->frame
));
18864 xassert (s
->nchars
== 0);
18865 xassert (start
>= 0 && end
> start
);
18867 s
->for_overlaps
= overlaps
,
18868 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18869 last
= s
->row
->glyphs
[s
->area
] + end
;
18870 voffset
= glyph
->voffset
;
18872 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18874 while (glyph
< last
18875 && glyph
->type
== CHAR_GLYPH
18876 && glyph
->voffset
== voffset
18877 /* Same face id implies same font, nowadays. */
18878 && glyph
->face_id
== face_id
18879 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18883 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18884 s
->char2b
+ s
->nchars
,
18886 s
->two_byte_p
= two_byte_p
;
18888 xassert (s
->nchars
<= end
- start
);
18889 s
->width
+= glyph
->pixel_width
;
18893 s
->font
= s
->face
->font
;
18894 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18896 /* If the specified font could not be loaded, use the frame's font,
18897 but record the fact that we couldn't load it in
18898 S->font_not_found_p so that we can draw rectangles for the
18899 characters of the glyph string. */
18900 if (s
->font
== NULL
|| glyph_not_available_p
)
18902 s
->font_not_found_p
= 1;
18903 s
->font
= FRAME_FONT (s
->f
);
18906 /* Adjust base line for subscript/superscript text. */
18907 s
->ybase
+= voffset
;
18909 xassert (s
->face
&& s
->face
->gc
);
18910 return glyph
- s
->row
->glyphs
[s
->area
];
18914 /* Fill glyph string S from image glyph S->first_glyph. */
18917 fill_image_glyph_string (s
)
18918 struct glyph_string
*s
;
18920 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18921 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18923 s
->slice
= s
->first_glyph
->slice
;
18924 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18925 s
->font
= s
->face
->font
;
18926 s
->width
= s
->first_glyph
->pixel_width
;
18928 /* Adjust base line for subscript/superscript text. */
18929 s
->ybase
+= s
->first_glyph
->voffset
;
18933 /* Fill glyph string S from a sequence of stretch glyphs.
18935 ROW is the glyph row in which the glyphs are found, AREA is the
18936 area within the row. START is the index of the first glyph to
18937 consider, END is the index of the last + 1.
18939 Value is the index of the first glyph not in S. */
18942 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18943 struct glyph_string
*s
;
18944 struct glyph_row
*row
;
18945 enum glyph_row_area area
;
18948 struct glyph
*glyph
, *last
;
18949 int voffset
, face_id
;
18951 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18953 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18954 last
= s
->row
->glyphs
[s
->area
] + end
;
18955 face_id
= glyph
->face_id
;
18956 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18957 s
->font
= s
->face
->font
;
18958 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18959 s
->width
= glyph
->pixel_width
;
18961 voffset
= glyph
->voffset
;
18965 && glyph
->type
== STRETCH_GLYPH
18966 && glyph
->voffset
== voffset
18967 && glyph
->face_id
== face_id
);
18969 s
->width
+= glyph
->pixel_width
;
18971 /* Adjust base line for subscript/superscript text. */
18972 s
->ybase
+= voffset
;
18974 /* The case that face->gc == 0 is handled when drawing the glyph
18975 string by calling PREPARE_FACE_FOR_DISPLAY. */
18977 return glyph
- s
->row
->glyphs
[s
->area
];
18982 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18983 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18984 assumed to be zero. */
18987 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18988 struct glyph
*glyph
;
18992 *left
= *right
= 0;
18994 if (glyph
->type
== CHAR_GLYPH
)
18998 struct font_info
*font_info
;
19002 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19004 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19005 if (font
/* ++KFS: Should this be font_info ? */
19006 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19008 if (pcm
->rbearing
> pcm
->width
)
19009 *right
= pcm
->rbearing
- pcm
->width
;
19010 if (pcm
->lbearing
< 0)
19011 *left
= -pcm
->lbearing
;
19017 /* Return the index of the first glyph preceding glyph string S that
19018 is overwritten by S because of S's left overhang. Value is -1
19019 if no glyphs are overwritten. */
19022 left_overwritten (s
)
19023 struct glyph_string
*s
;
19027 if (s
->left_overhang
)
19030 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19031 int first
= s
->first_glyph
- glyphs
;
19033 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19034 x
-= glyphs
[i
].pixel_width
;
19045 /* Return the index of the first glyph preceding glyph string S that
19046 is overwriting S because of its right overhang. Value is -1 if no
19047 glyph in front of S overwrites S. */
19050 left_overwriting (s
)
19051 struct glyph_string
*s
;
19054 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19055 int first
= s
->first_glyph
- glyphs
;
19059 for (i
= first
- 1; i
>= 0; --i
)
19062 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19065 x
-= glyphs
[i
].pixel_width
;
19072 /* Return the index of the last glyph following glyph string S that is
19073 not overwritten by S because of S's right overhang. Value is -1 if
19074 no such glyph is found. */
19077 right_overwritten (s
)
19078 struct glyph_string
*s
;
19082 if (s
->right_overhang
)
19085 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19086 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19087 int end
= s
->row
->used
[s
->area
];
19089 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19090 x
+= glyphs
[i
].pixel_width
;
19099 /* Return the index of the last glyph following glyph string S that
19100 overwrites S because of its left overhang. Value is negative
19101 if no such glyph is found. */
19104 right_overwriting (s
)
19105 struct glyph_string
*s
;
19108 int end
= s
->row
->used
[s
->area
];
19109 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19110 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19114 for (i
= first
; i
< end
; ++i
)
19117 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19120 x
+= glyphs
[i
].pixel_width
;
19127 /* Get face and two-byte form of character C in face FACE_ID on frame
19128 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19129 means we want to display multibyte text. DISPLAY_P non-zero means
19130 make sure that X resources for the face returned are allocated.
19131 Value is a pointer to a realized face that is ready for display if
19132 DISPLAY_P is non-zero. */
19134 static INLINE
struct face
*
19135 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19139 int multibyte_p
, display_p
;
19141 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19145 /* Unibyte case. We don't have to encode, but we have to make
19146 sure to use a face suitable for unibyte. */
19147 STORE_XCHAR2B (char2b
, 0, c
);
19148 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19149 face
= FACE_FROM_ID (f
, face_id
);
19153 /* Case of ASCII in a face known to fit ASCII. */
19154 STORE_XCHAR2B (char2b
, 0, c
);
19158 int c1
, c2
, charset
;
19160 /* Split characters into bytes. If c2 is -1 afterwards, C is
19161 really a one-byte character so that byte1 is zero. */
19162 SPLIT_CHAR (c
, charset
, c1
, c2
);
19164 STORE_XCHAR2B (char2b
, c1
, c2
);
19166 STORE_XCHAR2B (char2b
, 0, c1
);
19168 /* Maybe encode the character in *CHAR2B. */
19169 if (face
->font
!= NULL
)
19171 struct font_info
*font_info
19172 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19174 rif
->encode_char (c
, char2b
, font_info
, 0);
19178 /* Make sure X resources of the face are allocated. */
19179 #ifdef HAVE_X_WINDOWS
19183 xassert (face
!= NULL
);
19184 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19191 /* Set background width of glyph string S. START is the index of the
19192 first glyph following S. LAST_X is the right-most x-position + 1
19193 in the drawing area. */
19196 set_glyph_string_background_width (s
, start
, last_x
)
19197 struct glyph_string
*s
;
19201 /* If the face of this glyph string has to be drawn to the end of
19202 the drawing area, set S->extends_to_end_of_line_p. */
19204 if (start
== s
->row
->used
[s
->area
]
19205 && s
->area
== TEXT_AREA
19206 && ((s
->row
->fill_line_p
19207 && (s
->hl
== DRAW_NORMAL_TEXT
19208 || s
->hl
== DRAW_IMAGE_RAISED
19209 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19210 || s
->hl
== DRAW_MOUSE_FACE
))
19211 s
->extends_to_end_of_line_p
= 1;
19213 /* If S extends its face to the end of the line, set its
19214 background_width to the distance to the right edge of the drawing
19216 if (s
->extends_to_end_of_line_p
)
19217 s
->background_width
= last_x
- s
->x
+ 1;
19219 s
->background_width
= s
->width
;
19223 /* Compute overhangs and x-positions for glyph string S and its
19224 predecessors, or successors. X is the starting x-position for S.
19225 BACKWARD_P non-zero means process predecessors. */
19228 compute_overhangs_and_x (s
, x
, backward_p
)
19229 struct glyph_string
*s
;
19237 if (rif
->compute_glyph_string_overhangs
)
19238 rif
->compute_glyph_string_overhangs (s
);
19248 if (rif
->compute_glyph_string_overhangs
)
19249 rif
->compute_glyph_string_overhangs (s
);
19259 /* The following macros are only called from draw_glyphs below.
19260 They reference the following parameters of that function directly:
19261 `w', `row', `area', and `overlap_p'
19262 as well as the following local variables:
19263 `s', `f', and `hdc' (in W32) */
19266 /* On W32, silently add local `hdc' variable to argument list of
19267 init_glyph_string. */
19268 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19269 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19271 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19272 init_glyph_string (s, char2b, w, row, area, start, hl)
19275 /* Add a glyph string for a stretch glyph to the list of strings
19276 between HEAD and TAIL. START is the index of the stretch glyph in
19277 row area AREA of glyph row ROW. END is the index of the last glyph
19278 in that glyph row area. X is the current output position assigned
19279 to the new glyph string constructed. HL overrides that face of the
19280 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19281 is the right-most x-position of the drawing area. */
19283 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19284 and below -- keep them on one line. */
19285 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19288 s = (struct glyph_string *) alloca (sizeof *s); \
19289 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19290 START = fill_stretch_glyph_string (s, row, area, START, END); \
19291 append_glyph_string (&HEAD, &TAIL, s); \
19297 /* Add a glyph string for an image glyph to the list of strings
19298 between HEAD and TAIL. START is the index of the image glyph in
19299 row area AREA of glyph row ROW. END is the index of the last glyph
19300 in that glyph row area. X is the current output position assigned
19301 to the new glyph string constructed. HL overrides that face of the
19302 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19303 is the right-most x-position of the drawing area. */
19305 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19308 s = (struct glyph_string *) alloca (sizeof *s); \
19309 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19310 fill_image_glyph_string (s); \
19311 append_glyph_string (&HEAD, &TAIL, s); \
19318 /* Add a glyph string for a sequence of character glyphs to the list
19319 of strings between HEAD and TAIL. START is the index of the first
19320 glyph in row area AREA of glyph row ROW that is part of the new
19321 glyph string. END is the index of the last glyph in that glyph row
19322 area. X is the current output position assigned to the new glyph
19323 string constructed. HL overrides that face of the glyph; e.g. it
19324 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19325 right-most x-position of the drawing area. */
19327 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19333 c = (row)->glyphs[area][START].u.ch; \
19334 face_id = (row)->glyphs[area][START].face_id; \
19336 s = (struct glyph_string *) alloca (sizeof *s); \
19337 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19338 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19339 append_glyph_string (&HEAD, &TAIL, s); \
19341 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19346 /* Add a glyph string for a composite sequence to the list of strings
19347 between HEAD and TAIL. START is the index of the first glyph in
19348 row area AREA of glyph row ROW that is part of the new glyph
19349 string. END is the index of the last glyph in that glyph row area.
19350 X is the current output position assigned to the new glyph string
19351 constructed. HL overrides that face of the glyph; e.g. it is
19352 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19353 x-position of the drawing area. */
19355 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19357 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19358 int face_id = (row)->glyphs[area][START].face_id; \
19359 struct face *base_face = FACE_FROM_ID (f, face_id); \
19360 struct composition *cmp = composition_table[cmp_id]; \
19361 int glyph_len = cmp->glyph_len; \
19363 struct face **faces; \
19364 struct glyph_string *first_s = NULL; \
19367 base_face = base_face->ascii_face; \
19368 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19369 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19370 /* At first, fill in `char2b' and `faces'. */ \
19371 for (n = 0; n < glyph_len; n++) \
19373 int c = COMPOSITION_GLYPH (cmp, n); \
19374 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19375 faces[n] = FACE_FROM_ID (f, this_face_id); \
19376 get_char_face_and_encoding (f, c, this_face_id, \
19377 char2b + n, 1, 1); \
19380 /* Make glyph_strings for each glyph sequence that is drawable by \
19381 the same face, and append them to HEAD/TAIL. */ \
19382 for (n = 0; n < cmp->glyph_len;) \
19384 s = (struct glyph_string *) alloca (sizeof *s); \
19385 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19386 append_glyph_string (&(HEAD), &(TAIL), s); \
19394 n = fill_composite_glyph_string (s, faces, overlaps); \
19402 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19403 of AREA of glyph row ROW on window W between indices START and END.
19404 HL overrides the face for drawing glyph strings, e.g. it is
19405 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19406 x-positions of the drawing area.
19408 This is an ugly monster macro construct because we must use alloca
19409 to allocate glyph strings (because draw_glyphs can be called
19410 asynchronously). */
19412 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19415 HEAD = TAIL = NULL; \
19416 while (START < END) \
19418 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19419 switch (first_glyph->type) \
19422 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19426 case COMPOSITE_GLYPH: \
19427 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19431 case STRETCH_GLYPH: \
19432 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19436 case IMAGE_GLYPH: \
19437 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19445 set_glyph_string_background_width (s, START, LAST_X); \
19452 /* Draw glyphs between START and END in AREA of ROW on window W,
19453 starting at x-position X. X is relative to AREA in W. HL is a
19454 face-override with the following meaning:
19456 DRAW_NORMAL_TEXT draw normally
19457 DRAW_CURSOR draw in cursor face
19458 DRAW_MOUSE_FACE draw in mouse face.
19459 DRAW_INVERSE_VIDEO draw in mode line face
19460 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19461 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19463 If OVERLAPS is non-zero, draw only the foreground of characters and
19464 clip to the physical height of ROW. Non-zero value also defines
19465 the overlapping part to be drawn:
19467 OVERLAPS_PRED overlap with preceding rows
19468 OVERLAPS_SUCC overlap with succeeding rows
19469 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19470 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19472 Value is the x-position reached, relative to AREA of W. */
19475 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19478 struct glyph_row
*row
;
19479 enum glyph_row_area area
;
19481 enum draw_glyphs_face hl
;
19484 struct glyph_string
*head
, *tail
;
19485 struct glyph_string
*s
;
19486 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19487 int last_x
, area_width
;
19490 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19493 ALLOCATE_HDC (hdc
, f
);
19495 /* Let's rather be paranoid than getting a SEGV. */
19496 end
= min (end
, row
->used
[area
]);
19497 start
= max (0, start
);
19498 start
= min (end
, start
);
19500 /* Translate X to frame coordinates. Set last_x to the right
19501 end of the drawing area. */
19502 if (row
->full_width_p
)
19504 /* X is relative to the left edge of W, without scroll bars
19506 x
+= WINDOW_LEFT_EDGE_X (w
);
19507 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19511 int area_left
= window_box_left (w
, area
);
19513 area_width
= window_box_width (w
, area
);
19514 last_x
= area_left
+ area_width
;
19517 /* Build a doubly-linked list of glyph_string structures between
19518 head and tail from what we have to draw. Note that the macro
19519 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19520 the reason we use a separate variable `i'. */
19522 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19524 x_reached
= tail
->x
+ tail
->background_width
;
19528 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19529 the row, redraw some glyphs in front or following the glyph
19530 strings built above. */
19531 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19534 struct glyph_string
*h
, *t
;
19536 /* Compute overhangs for all glyph strings. */
19537 if (rif
->compute_glyph_string_overhangs
)
19538 for (s
= head
; s
; s
= s
->next
)
19539 rif
->compute_glyph_string_overhangs (s
);
19541 /* Prepend glyph strings for glyphs in front of the first glyph
19542 string that are overwritten because of the first glyph
19543 string's left overhang. The background of all strings
19544 prepended must be drawn because the first glyph string
19546 i
= left_overwritten (head
);
19550 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19551 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19553 compute_overhangs_and_x (t
, head
->x
, 1);
19554 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19558 /* Prepend glyph strings for glyphs in front of the first glyph
19559 string that overwrite that glyph string because of their
19560 right overhang. For these strings, only the foreground must
19561 be drawn, because it draws over the glyph string at `head'.
19562 The background must not be drawn because this would overwrite
19563 right overhangs of preceding glyphs for which no glyph
19565 i
= left_overwriting (head
);
19569 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19570 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19571 for (s
= h
; s
; s
= s
->next
)
19572 s
->background_filled_p
= 1;
19573 compute_overhangs_and_x (t
, head
->x
, 1);
19574 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19577 /* Append glyphs strings for glyphs following the last glyph
19578 string tail that are overwritten by tail. The background of
19579 these strings has to be drawn because tail's foreground draws
19581 i
= right_overwritten (tail
);
19584 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19585 DRAW_NORMAL_TEXT
, x
, last_x
);
19586 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19587 append_glyph_string_lists (&head
, &tail
, h
, t
);
19591 /* Append glyph strings for glyphs following the last glyph
19592 string tail that overwrite tail. The foreground of such
19593 glyphs has to be drawn because it writes into the background
19594 of tail. The background must not be drawn because it could
19595 paint over the foreground of following glyphs. */
19596 i
= right_overwriting (tail
);
19600 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19601 DRAW_NORMAL_TEXT
, x
, last_x
);
19602 for (s
= h
; s
; s
= s
->next
)
19603 s
->background_filled_p
= 1;
19604 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19605 append_glyph_string_lists (&head
, &tail
, h
, t
);
19607 if (clip_head
|| clip_tail
)
19608 for (s
= head
; s
; s
= s
->next
)
19610 s
->clip_head
= clip_head
;
19611 s
->clip_tail
= clip_tail
;
19615 /* Draw all strings. */
19616 for (s
= head
; s
; s
= s
->next
)
19617 rif
->draw_glyph_string (s
);
19619 if (area
== TEXT_AREA
19620 && !row
->full_width_p
19621 /* When drawing overlapping rows, only the glyph strings'
19622 foreground is drawn, which doesn't erase a cursor
19626 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19627 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19628 : (tail
? tail
->x
+ tail
->background_width
: x
));
19630 int text_left
= window_box_left (w
, TEXT_AREA
);
19634 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19635 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19638 /* Value is the x-position up to which drawn, relative to AREA of W.
19639 This doesn't include parts drawn because of overhangs. */
19640 if (row
->full_width_p
)
19641 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19643 x_reached
-= window_box_left (w
, area
);
19645 RELEASE_HDC (hdc
, f
);
19650 /* Expand row matrix if too narrow. Don't expand if area
19653 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19655 if (!fonts_changed_p \
19656 && (it->glyph_row->glyphs[area] \
19657 < it->glyph_row->glyphs[area + 1])) \
19659 it->w->ncols_scale_factor++; \
19660 fonts_changed_p = 1; \
19664 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19665 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19671 struct glyph
*glyph
;
19672 enum glyph_row_area area
= it
->area
;
19674 xassert (it
->glyph_row
);
19675 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19677 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19678 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19680 glyph
->charpos
= CHARPOS (it
->position
);
19681 glyph
->object
= it
->object
;
19682 glyph
->pixel_width
= it
->pixel_width
;
19683 glyph
->ascent
= it
->ascent
;
19684 glyph
->descent
= it
->descent
;
19685 glyph
->voffset
= it
->voffset
;
19686 glyph
->type
= CHAR_GLYPH
;
19687 glyph
->multibyte_p
= it
->multibyte_p
;
19688 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19689 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19690 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19691 || it
->phys_descent
> it
->descent
);
19692 glyph
->padding_p
= 0;
19693 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19694 glyph
->face_id
= it
->face_id
;
19695 glyph
->u
.ch
= it
->char_to_display
;
19696 glyph
->slice
= null_glyph_slice
;
19697 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19698 ++it
->glyph_row
->used
[area
];
19701 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19704 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19705 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19708 append_composite_glyph (it
)
19711 struct glyph
*glyph
;
19712 enum glyph_row_area area
= it
->area
;
19714 xassert (it
->glyph_row
);
19716 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19717 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19719 glyph
->charpos
= CHARPOS (it
->position
);
19720 glyph
->object
= it
->object
;
19721 glyph
->pixel_width
= it
->pixel_width
;
19722 glyph
->ascent
= it
->ascent
;
19723 glyph
->descent
= it
->descent
;
19724 glyph
->voffset
= it
->voffset
;
19725 glyph
->type
= COMPOSITE_GLYPH
;
19726 glyph
->multibyte_p
= it
->multibyte_p
;
19727 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19728 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19729 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19730 || it
->phys_descent
> it
->descent
);
19731 glyph
->padding_p
= 0;
19732 glyph
->glyph_not_available_p
= 0;
19733 glyph
->face_id
= it
->face_id
;
19734 glyph
->u
.cmp_id
= it
->cmp_id
;
19735 glyph
->slice
= null_glyph_slice
;
19736 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19737 ++it
->glyph_row
->used
[area
];
19740 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19744 /* Change IT->ascent and IT->height according to the setting of
19748 take_vertical_position_into_account (it
)
19753 if (it
->voffset
< 0)
19754 /* Increase the ascent so that we can display the text higher
19756 it
->ascent
-= it
->voffset
;
19758 /* Increase the descent so that we can display the text lower
19760 it
->descent
+= it
->voffset
;
19765 /* Produce glyphs/get display metrics for the image IT is loaded with.
19766 See the description of struct display_iterator in dispextern.h for
19767 an overview of struct display_iterator. */
19770 produce_image_glyph (it
)
19776 struct glyph_slice slice
;
19778 xassert (it
->what
== IT_IMAGE
);
19780 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19782 /* Make sure X resources of the face is loaded. */
19783 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19785 if (it
->image_id
< 0)
19787 /* Fringe bitmap. */
19788 it
->ascent
= it
->phys_ascent
= 0;
19789 it
->descent
= it
->phys_descent
= 0;
19790 it
->pixel_width
= 0;
19795 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19797 /* Make sure X resources of the image is loaded. */
19798 prepare_image_for_display (it
->f
, img
);
19800 slice
.x
= slice
.y
= 0;
19801 slice
.width
= img
->width
;
19802 slice
.height
= img
->height
;
19804 if (INTEGERP (it
->slice
.x
))
19805 slice
.x
= XINT (it
->slice
.x
);
19806 else if (FLOATP (it
->slice
.x
))
19807 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19809 if (INTEGERP (it
->slice
.y
))
19810 slice
.y
= XINT (it
->slice
.y
);
19811 else if (FLOATP (it
->slice
.y
))
19812 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19814 if (INTEGERP (it
->slice
.width
))
19815 slice
.width
= XINT (it
->slice
.width
);
19816 else if (FLOATP (it
->slice
.width
))
19817 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19819 if (INTEGERP (it
->slice
.height
))
19820 slice
.height
= XINT (it
->slice
.height
);
19821 else if (FLOATP (it
->slice
.height
))
19822 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19824 if (slice
.x
>= img
->width
)
19825 slice
.x
= img
->width
;
19826 if (slice
.y
>= img
->height
)
19827 slice
.y
= img
->height
;
19828 if (slice
.x
+ slice
.width
>= img
->width
)
19829 slice
.width
= img
->width
- slice
.x
;
19830 if (slice
.y
+ slice
.height
> img
->height
)
19831 slice
.height
= img
->height
- slice
.y
;
19833 if (slice
.width
== 0 || slice
.height
== 0)
19836 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19838 it
->descent
= slice
.height
- glyph_ascent
;
19840 it
->descent
+= img
->vmargin
;
19841 if (slice
.y
+ slice
.height
== img
->height
)
19842 it
->descent
+= img
->vmargin
;
19843 it
->phys_descent
= it
->descent
;
19845 it
->pixel_width
= slice
.width
;
19847 it
->pixel_width
+= img
->hmargin
;
19848 if (slice
.x
+ slice
.width
== img
->width
)
19849 it
->pixel_width
+= img
->hmargin
;
19851 /* It's quite possible for images to have an ascent greater than
19852 their height, so don't get confused in that case. */
19853 if (it
->descent
< 0)
19856 #if 0 /* this breaks image tiling */
19857 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19858 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19859 if (face_ascent
> it
->ascent
)
19860 it
->ascent
= it
->phys_ascent
= face_ascent
;
19865 if (face
->box
!= FACE_NO_BOX
)
19867 if (face
->box_line_width
> 0)
19870 it
->ascent
+= face
->box_line_width
;
19871 if (slice
.y
+ slice
.height
== img
->height
)
19872 it
->descent
+= face
->box_line_width
;
19875 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19876 it
->pixel_width
+= abs (face
->box_line_width
);
19877 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19878 it
->pixel_width
+= abs (face
->box_line_width
);
19881 take_vertical_position_into_account (it
);
19885 struct glyph
*glyph
;
19886 enum glyph_row_area area
= it
->area
;
19888 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19889 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19891 glyph
->charpos
= CHARPOS (it
->position
);
19892 glyph
->object
= it
->object
;
19893 glyph
->pixel_width
= it
->pixel_width
;
19894 glyph
->ascent
= glyph_ascent
;
19895 glyph
->descent
= it
->descent
;
19896 glyph
->voffset
= it
->voffset
;
19897 glyph
->type
= IMAGE_GLYPH
;
19898 glyph
->multibyte_p
= it
->multibyte_p
;
19899 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19900 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19901 glyph
->overlaps_vertically_p
= 0;
19902 glyph
->padding_p
= 0;
19903 glyph
->glyph_not_available_p
= 0;
19904 glyph
->face_id
= it
->face_id
;
19905 glyph
->u
.img_id
= img
->id
;
19906 glyph
->slice
= slice
;
19907 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19908 ++it
->glyph_row
->used
[area
];
19911 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19916 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19917 of the glyph, WIDTH and HEIGHT are the width and height of the
19918 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19921 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19923 Lisp_Object object
;
19927 struct glyph
*glyph
;
19928 enum glyph_row_area area
= it
->area
;
19930 xassert (ascent
>= 0 && ascent
<= height
);
19932 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19933 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19935 glyph
->charpos
= CHARPOS (it
->position
);
19936 glyph
->object
= object
;
19937 glyph
->pixel_width
= width
;
19938 glyph
->ascent
= ascent
;
19939 glyph
->descent
= height
- ascent
;
19940 glyph
->voffset
= it
->voffset
;
19941 glyph
->type
= STRETCH_GLYPH
;
19942 glyph
->multibyte_p
= it
->multibyte_p
;
19943 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19944 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19945 glyph
->overlaps_vertically_p
= 0;
19946 glyph
->padding_p
= 0;
19947 glyph
->glyph_not_available_p
= 0;
19948 glyph
->face_id
= it
->face_id
;
19949 glyph
->u
.stretch
.ascent
= ascent
;
19950 glyph
->u
.stretch
.height
= height
;
19951 glyph
->slice
= null_glyph_slice
;
19952 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19953 ++it
->glyph_row
->used
[area
];
19956 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19960 /* Produce a stretch glyph for iterator IT. IT->object is the value
19961 of the glyph property displayed. The value must be a list
19962 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19965 1. `:width WIDTH' specifies that the space should be WIDTH *
19966 canonical char width wide. WIDTH may be an integer or floating
19969 2. `:relative-width FACTOR' specifies that the width of the stretch
19970 should be computed from the width of the first character having the
19971 `glyph' property, and should be FACTOR times that width.
19973 3. `:align-to HPOS' specifies that the space should be wide enough
19974 to reach HPOS, a value in canonical character units.
19976 Exactly one of the above pairs must be present.
19978 4. `:height HEIGHT' specifies that the height of the stretch produced
19979 should be HEIGHT, measured in canonical character units.
19981 5. `:relative-height FACTOR' specifies that the height of the
19982 stretch should be FACTOR times the height of the characters having
19983 the glyph property.
19985 Either none or exactly one of 4 or 5 must be present.
19987 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19988 of the stretch should be used for the ascent of the stretch.
19989 ASCENT must be in the range 0 <= ASCENT <= 100. */
19992 produce_stretch_glyph (it
)
19995 /* (space :width WIDTH :height HEIGHT ...) */
19996 Lisp_Object prop
, plist
;
19997 int width
= 0, height
= 0, align_to
= -1;
19998 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20001 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20002 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20004 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20006 /* List should start with `space'. */
20007 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20008 plist
= XCDR (it
->object
);
20010 /* Compute the width of the stretch. */
20011 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20012 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20014 /* Absolute width `:width WIDTH' specified and valid. */
20015 zero_width_ok_p
= 1;
20018 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20021 /* Relative width `:relative-width FACTOR' specified and valid.
20022 Compute the width of the characters having the `glyph'
20025 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20028 if (it
->multibyte_p
)
20030 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20031 - IT_BYTEPOS (*it
));
20032 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20035 it2
.c
= *p
, it2
.len
= 1;
20037 it2
.glyph_row
= NULL
;
20038 it2
.what
= IT_CHARACTER
;
20039 x_produce_glyphs (&it2
);
20040 width
= NUMVAL (prop
) * it2
.pixel_width
;
20042 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20043 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20045 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20046 align_to
= (align_to
< 0
20048 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20049 else if (align_to
< 0)
20050 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20051 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20052 zero_width_ok_p
= 1;
20055 /* Nothing specified -> width defaults to canonical char width. */
20056 width
= FRAME_COLUMN_WIDTH (it
->f
);
20058 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20061 /* Compute height. */
20062 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20063 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20066 zero_height_ok_p
= 1;
20068 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20070 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20072 height
= FONT_HEIGHT (font
);
20074 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20077 /* Compute percentage of height used for ascent. If
20078 `:ascent ASCENT' is present and valid, use that. Otherwise,
20079 derive the ascent from the font in use. */
20080 if (prop
= Fplist_get (plist
, QCascent
),
20081 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20082 ascent
= height
* NUMVAL (prop
) / 100.0;
20083 else if (!NILP (prop
)
20084 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20085 ascent
= min (max (0, (int)tem
), height
);
20087 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20089 if (width
> 0 && !it
->truncate_lines_p
20090 && it
->current_x
+ width
> it
->last_visible_x
)
20091 width
= it
->last_visible_x
- it
->current_x
- 1;
20093 if (width
> 0 && height
> 0 && it
->glyph_row
)
20095 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20096 if (!STRINGP (object
))
20097 object
= it
->w
->buffer
;
20098 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20101 it
->pixel_width
= width
;
20102 it
->ascent
= it
->phys_ascent
= ascent
;
20103 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20104 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20106 take_vertical_position_into_account (it
);
20109 /* Get line-height and line-spacing property at point.
20110 If line-height has format (HEIGHT TOTAL), return TOTAL
20111 in TOTAL_HEIGHT. */
20114 get_line_height_property (it
, prop
)
20118 Lisp_Object position
;
20120 if (STRINGP (it
->object
))
20121 position
= make_number (IT_STRING_CHARPOS (*it
));
20122 else if (BUFFERP (it
->object
))
20123 position
= make_number (IT_CHARPOS (*it
));
20127 return Fget_char_property (position
, prop
, it
->object
);
20130 /* Calculate line-height and line-spacing properties.
20131 An integer value specifies explicit pixel value.
20132 A float value specifies relative value to current face height.
20133 A cons (float . face-name) specifies relative value to
20134 height of specified face font.
20136 Returns height in pixels, or nil. */
20140 calc_line_height_property (it
, val
, font
, boff
, override
)
20144 int boff
, override
;
20146 Lisp_Object face_name
= Qnil
;
20147 int ascent
, descent
, height
;
20149 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20154 face_name
= XCAR (val
);
20156 if (!NUMBERP (val
))
20157 val
= make_number (1);
20158 if (NILP (face_name
))
20160 height
= it
->ascent
+ it
->descent
;
20165 if (NILP (face_name
))
20167 font
= FRAME_FONT (it
->f
);
20168 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20170 else if (EQ (face_name
, Qt
))
20178 struct font_info
*font_info
;
20180 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20182 return make_number (-1);
20184 face
= FACE_FROM_ID (it
->f
, face_id
);
20187 return make_number (-1);
20189 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20190 boff
= font_info
->baseline_offset
;
20191 if (font_info
->vertical_centering
)
20192 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20195 ascent
= FONT_BASE (font
) + boff
;
20196 descent
= FONT_DESCENT (font
) - boff
;
20200 it
->override_ascent
= ascent
;
20201 it
->override_descent
= descent
;
20202 it
->override_boff
= boff
;
20205 height
= ascent
+ descent
;
20209 height
= (int)(XFLOAT_DATA (val
) * height
);
20210 else if (INTEGERP (val
))
20211 height
*= XINT (val
);
20213 return make_number (height
);
20218 Produce glyphs/get display metrics for the display element IT is
20219 loaded with. See the description of struct it in dispextern.h
20220 for an overview of struct it. */
20223 x_produce_glyphs (it
)
20226 int extra_line_spacing
= it
->extra_line_spacing
;
20228 it
->glyph_not_available_p
= 0;
20230 if (it
->what
== IT_CHARACTER
)
20234 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20236 int font_not_found_p
;
20237 struct font_info
*font_info
;
20238 int boff
; /* baseline offset */
20239 /* We may change it->multibyte_p upon unibyte<->multibyte
20240 conversion. So, save the current value now and restore it
20243 Note: It seems that we don't have to record multibyte_p in
20244 struct glyph because the character code itself tells if or
20245 not the character is multibyte. Thus, in the future, we must
20246 consider eliminating the field `multibyte_p' in the struct
20248 int saved_multibyte_p
= it
->multibyte_p
;
20250 /* Maybe translate single-byte characters to multibyte, or the
20252 it
->char_to_display
= it
->c
;
20253 if (!ASCII_BYTE_P (it
->c
))
20255 if (unibyte_display_via_language_environment
20256 && SINGLE_BYTE_CHAR_P (it
->c
)
20258 || !NILP (Vnonascii_translation_table
)))
20260 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20261 it
->multibyte_p
= 1;
20262 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20263 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20265 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20266 && !it
->multibyte_p
)
20268 it
->multibyte_p
= 1;
20269 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20270 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20274 /* Get font to use. Encode IT->char_to_display. */
20275 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20276 &char2b
, it
->multibyte_p
, 0);
20279 /* When no suitable font found, use the default font. */
20280 font_not_found_p
= font
== NULL
;
20281 if (font_not_found_p
)
20283 font
= FRAME_FONT (it
->f
);
20284 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20289 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20290 boff
= font_info
->baseline_offset
;
20291 if (font_info
->vertical_centering
)
20292 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20295 if (it
->char_to_display
>= ' '
20296 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20298 /* Either unibyte or ASCII. */
20303 pcm
= rif
->per_char_metric (font
, &char2b
,
20304 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20306 if (it
->override_ascent
>= 0)
20308 it
->ascent
= it
->override_ascent
;
20309 it
->descent
= it
->override_descent
;
20310 boff
= it
->override_boff
;
20314 it
->ascent
= FONT_BASE (font
) + boff
;
20315 it
->descent
= FONT_DESCENT (font
) - boff
;
20320 it
->phys_ascent
= pcm
->ascent
+ boff
;
20321 it
->phys_descent
= pcm
->descent
- boff
;
20322 it
->pixel_width
= pcm
->width
;
20326 it
->glyph_not_available_p
= 1;
20327 it
->phys_ascent
= it
->ascent
;
20328 it
->phys_descent
= it
->descent
;
20329 it
->pixel_width
= FONT_WIDTH (font
);
20332 if (it
->constrain_row_ascent_descent_p
)
20334 if (it
->descent
> it
->max_descent
)
20336 it
->ascent
+= it
->descent
- it
->max_descent
;
20337 it
->descent
= it
->max_descent
;
20339 if (it
->ascent
> it
->max_ascent
)
20341 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20342 it
->ascent
= it
->max_ascent
;
20344 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20345 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20346 extra_line_spacing
= 0;
20349 /* If this is a space inside a region of text with
20350 `space-width' property, change its width. */
20351 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20353 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20355 /* If face has a box, add the box thickness to the character
20356 height. If character has a box line to the left and/or
20357 right, add the box line width to the character's width. */
20358 if (face
->box
!= FACE_NO_BOX
)
20360 int thick
= face
->box_line_width
;
20364 it
->ascent
+= thick
;
20365 it
->descent
+= thick
;
20370 if (it
->start_of_box_run_p
)
20371 it
->pixel_width
+= thick
;
20372 if (it
->end_of_box_run_p
)
20373 it
->pixel_width
+= thick
;
20376 /* If face has an overline, add the height of the overline
20377 (1 pixel) and a 1 pixel margin to the character height. */
20378 if (face
->overline_p
)
20379 it
->ascent
+= overline_margin
;
20381 if (it
->constrain_row_ascent_descent_p
)
20383 if (it
->ascent
> it
->max_ascent
)
20384 it
->ascent
= it
->max_ascent
;
20385 if (it
->descent
> it
->max_descent
)
20386 it
->descent
= it
->max_descent
;
20389 take_vertical_position_into_account (it
);
20391 /* If we have to actually produce glyphs, do it. */
20396 /* Translate a space with a `space-width' property
20397 into a stretch glyph. */
20398 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20399 / FONT_HEIGHT (font
));
20400 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20401 it
->ascent
+ it
->descent
, ascent
);
20406 /* If characters with lbearing or rbearing are displayed
20407 in this line, record that fact in a flag of the
20408 glyph row. This is used to optimize X output code. */
20409 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20410 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20413 else if (it
->char_to_display
== '\n')
20415 /* A newline has no width but we need the height of the line.
20416 But if previous part of the line set a height, don't
20417 increase that height */
20419 Lisp_Object height
;
20420 Lisp_Object total_height
= Qnil
;
20422 it
->override_ascent
= -1;
20423 it
->pixel_width
= 0;
20426 height
= get_line_height_property(it
, Qline_height
);
20427 /* Split (line-height total-height) list */
20429 && CONSP (XCDR (height
))
20430 && NILP (XCDR (XCDR (height
))))
20432 total_height
= XCAR (XCDR (height
));
20433 height
= XCAR (height
);
20435 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20437 if (it
->override_ascent
>= 0)
20439 it
->ascent
= it
->override_ascent
;
20440 it
->descent
= it
->override_descent
;
20441 boff
= it
->override_boff
;
20445 it
->ascent
= FONT_BASE (font
) + boff
;
20446 it
->descent
= FONT_DESCENT (font
) - boff
;
20449 if (EQ (height
, Qt
))
20451 if (it
->descent
> it
->max_descent
)
20453 it
->ascent
+= it
->descent
- it
->max_descent
;
20454 it
->descent
= it
->max_descent
;
20456 if (it
->ascent
> it
->max_ascent
)
20458 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20459 it
->ascent
= it
->max_ascent
;
20461 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20462 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20463 it
->constrain_row_ascent_descent_p
= 1;
20464 extra_line_spacing
= 0;
20468 Lisp_Object spacing
;
20470 it
->phys_ascent
= it
->ascent
;
20471 it
->phys_descent
= it
->descent
;
20473 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20474 && face
->box
!= FACE_NO_BOX
20475 && face
->box_line_width
> 0)
20477 it
->ascent
+= face
->box_line_width
;
20478 it
->descent
+= face
->box_line_width
;
20481 && XINT (height
) > it
->ascent
+ it
->descent
)
20482 it
->ascent
= XINT (height
) - it
->descent
;
20484 if (!NILP (total_height
))
20485 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20488 spacing
= get_line_height_property(it
, Qline_spacing
);
20489 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20491 if (INTEGERP (spacing
))
20493 extra_line_spacing
= XINT (spacing
);
20494 if (!NILP (total_height
))
20495 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20499 else if (it
->char_to_display
== '\t')
20501 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20502 int x
= it
->current_x
+ it
->continuation_lines_width
;
20503 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20505 /* If the distance from the current position to the next tab
20506 stop is less than a space character width, use the
20507 tab stop after that. */
20508 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20509 next_tab_x
+= tab_width
;
20511 it
->pixel_width
= next_tab_x
- x
;
20513 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20514 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20518 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20519 it
->ascent
+ it
->descent
, it
->ascent
);
20524 /* A multi-byte character. Assume that the display width of the
20525 character is the width of the character multiplied by the
20526 width of the font. */
20528 /* If we found a font, this font should give us the right
20529 metrics. If we didn't find a font, use the frame's
20530 default font and calculate the width of the character
20531 from the charset width; this is what old redisplay code
20534 pcm
= rif
->per_char_metric (font
, &char2b
,
20535 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20537 if (font_not_found_p
|| !pcm
)
20539 int charset
= CHAR_CHARSET (it
->char_to_display
);
20541 it
->glyph_not_available_p
= 1;
20542 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20543 * CHARSET_WIDTH (charset
));
20544 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20545 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20549 it
->pixel_width
= pcm
->width
;
20550 it
->phys_ascent
= pcm
->ascent
+ boff
;
20551 it
->phys_descent
= pcm
->descent
- boff
;
20553 && (pcm
->lbearing
< 0
20554 || pcm
->rbearing
> pcm
->width
))
20555 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20558 it
->ascent
= FONT_BASE (font
) + boff
;
20559 it
->descent
= FONT_DESCENT (font
) - boff
;
20560 if (face
->box
!= FACE_NO_BOX
)
20562 int thick
= face
->box_line_width
;
20566 it
->ascent
+= thick
;
20567 it
->descent
+= thick
;
20572 if (it
->start_of_box_run_p
)
20573 it
->pixel_width
+= thick
;
20574 if (it
->end_of_box_run_p
)
20575 it
->pixel_width
+= thick
;
20578 /* If face has an overline, add the height of the overline
20579 (1 pixel) and a 1 pixel margin to the character height. */
20580 if (face
->overline_p
)
20581 it
->ascent
+= overline_margin
;
20583 take_vertical_position_into_account (it
);
20588 it
->multibyte_p
= saved_multibyte_p
;
20590 else if (it
->what
== IT_COMPOSITION
)
20592 /* Note: A composition is represented as one glyph in the
20593 glyph matrix. There are no padding glyphs. */
20596 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20598 int font_not_found_p
;
20599 struct font_info
*font_info
;
20600 int boff
; /* baseline offset */
20601 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20603 /* Maybe translate single-byte characters to multibyte. */
20604 it
->char_to_display
= it
->c
;
20605 if (unibyte_display_via_language_environment
20606 && SINGLE_BYTE_CHAR_P (it
->c
)
20609 && !NILP (Vnonascii_translation_table
))))
20611 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20614 /* Get face and font to use. Encode IT->char_to_display. */
20615 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20616 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20617 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20618 &char2b
, it
->multibyte_p
, 0);
20621 /* When no suitable font found, use the default font. */
20622 font_not_found_p
= font
== NULL
;
20623 if (font_not_found_p
)
20625 font
= FRAME_FONT (it
->f
);
20626 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20631 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20632 boff
= font_info
->baseline_offset
;
20633 if (font_info
->vertical_centering
)
20634 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20637 /* There are no padding glyphs, so there is only one glyph to
20638 produce for the composition. Important is that pixel_width,
20639 ascent and descent are the values of what is drawn by
20640 draw_glyphs (i.e. the values of the overall glyphs composed). */
20643 /* If we have not yet calculated pixel size data of glyphs of
20644 the composition for the current face font, calculate them
20645 now. Theoretically, we have to check all fonts for the
20646 glyphs, but that requires much time and memory space. So,
20647 here we check only the font of the first glyph. This leads
20648 to incorrect display very rarely, and C-l (recenter) can
20649 correct the display anyway. */
20650 if (cmp
->font
!= (void *) font
)
20652 /* Ascent and descent of the font of the first character of
20653 this composition (adjusted by baseline offset). Ascent
20654 and descent of overall glyphs should not be less than
20655 them respectively. */
20656 int font_ascent
= FONT_BASE (font
) + boff
;
20657 int font_descent
= FONT_DESCENT (font
) - boff
;
20658 /* Bounding box of the overall glyphs. */
20659 int leftmost
, rightmost
, lowest
, highest
;
20660 int i
, width
, ascent
, descent
;
20662 cmp
->font
= (void *) font
;
20664 /* Initialize the bounding box. */
20666 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20667 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20669 width
= pcm
->width
;
20670 ascent
= pcm
->ascent
;
20671 descent
= pcm
->descent
;
20675 width
= FONT_WIDTH (font
);
20676 ascent
= FONT_BASE (font
);
20677 descent
= FONT_DESCENT (font
);
20681 lowest
= - descent
+ boff
;
20682 highest
= ascent
+ boff
;
20686 && font_info
->default_ascent
20687 && CHAR_TABLE_P (Vuse_default_ascent
)
20688 && !NILP (Faref (Vuse_default_ascent
,
20689 make_number (it
->char_to_display
))))
20690 highest
= font_info
->default_ascent
+ boff
;
20692 /* Draw the first glyph at the normal position. It may be
20693 shifted to right later if some other glyphs are drawn at
20695 cmp
->offsets
[0] = 0;
20696 cmp
->offsets
[1] = boff
;
20698 /* Set cmp->offsets for the remaining glyphs. */
20699 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20701 int left
, right
, btm
, top
;
20702 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20703 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20705 face
= FACE_FROM_ID (it
->f
, face_id
);
20706 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20707 &char2b
, it
->multibyte_p
, 0);
20711 font
= FRAME_FONT (it
->f
);
20712 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20718 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20719 boff
= font_info
->baseline_offset
;
20720 if (font_info
->vertical_centering
)
20721 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20725 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20726 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20728 width
= pcm
->width
;
20729 ascent
= pcm
->ascent
;
20730 descent
= pcm
->descent
;
20734 width
= FONT_WIDTH (font
);
20739 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20741 /* Relative composition with or without
20742 alternate chars. */
20743 left
= (leftmost
+ rightmost
- width
) / 2;
20744 btm
= - descent
+ boff
;
20745 if (font_info
&& font_info
->relative_compose
20746 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20747 || NILP (Faref (Vignore_relative_composition
,
20748 make_number (ch
)))))
20751 if (- descent
>= font_info
->relative_compose
)
20752 /* One extra pixel between two glyphs. */
20754 else if (ascent
<= 0)
20755 /* One extra pixel between two glyphs. */
20756 btm
= lowest
- 1 - ascent
- descent
;
20761 /* A composition rule is specified by an integer
20762 value that encodes global and new reference
20763 points (GREF and NREF). GREF and NREF are
20764 specified by numbers as below:
20766 0---1---2 -- ascent
20770 9--10--11 -- center
20772 ---3---4---5--- baseline
20774 6---7---8 -- descent
20776 int rule
= COMPOSITION_RULE (cmp
, i
);
20777 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20779 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20780 grefx
= gref
% 3, nrefx
= nref
% 3;
20781 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20784 + grefx
* (rightmost
- leftmost
) / 2
20785 - nrefx
* width
/ 2);
20786 btm
= ((grefy
== 0 ? highest
20788 : grefy
== 2 ? lowest
20789 : (highest
+ lowest
) / 2)
20790 - (nrefy
== 0 ? ascent
+ descent
20791 : nrefy
== 1 ? descent
- boff
20793 : (ascent
+ descent
) / 2));
20796 cmp
->offsets
[i
* 2] = left
;
20797 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20799 /* Update the bounding box of the overall glyphs. */
20800 right
= left
+ width
;
20801 top
= btm
+ descent
+ ascent
;
20802 if (left
< leftmost
)
20804 if (right
> rightmost
)
20812 /* If there are glyphs whose x-offsets are negative,
20813 shift all glyphs to the right and make all x-offsets
20817 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20818 cmp
->offsets
[i
* 2] -= leftmost
;
20819 rightmost
-= leftmost
;
20822 cmp
->pixel_width
= rightmost
;
20823 cmp
->ascent
= highest
;
20824 cmp
->descent
= - lowest
;
20825 if (cmp
->ascent
< font_ascent
)
20826 cmp
->ascent
= font_ascent
;
20827 if (cmp
->descent
< font_descent
)
20828 cmp
->descent
= font_descent
;
20831 it
->pixel_width
= cmp
->pixel_width
;
20832 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20833 it
->descent
= it
->phys_descent
= cmp
->descent
;
20835 if (face
->box
!= FACE_NO_BOX
)
20837 int thick
= face
->box_line_width
;
20841 it
->ascent
+= thick
;
20842 it
->descent
+= thick
;
20847 if (it
->start_of_box_run_p
)
20848 it
->pixel_width
+= thick
;
20849 if (it
->end_of_box_run_p
)
20850 it
->pixel_width
+= thick
;
20853 /* If face has an overline, add the height of the overline
20854 (1 pixel) and a 1 pixel margin to the character height. */
20855 if (face
->overline_p
)
20856 it
->ascent
+= overline_margin
;
20858 take_vertical_position_into_account (it
);
20861 append_composite_glyph (it
);
20863 else if (it
->what
== IT_IMAGE
)
20864 produce_image_glyph (it
);
20865 else if (it
->what
== IT_STRETCH
)
20866 produce_stretch_glyph (it
);
20868 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20869 because this isn't true for images with `:ascent 100'. */
20870 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20871 if (it
->area
== TEXT_AREA
)
20872 it
->current_x
+= it
->pixel_width
;
20874 if (extra_line_spacing
> 0)
20876 it
->descent
+= extra_line_spacing
;
20877 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20878 it
->max_extra_line_spacing
= extra_line_spacing
;
20881 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20882 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20883 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20884 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20888 Output LEN glyphs starting at START at the nominal cursor position.
20889 Advance the nominal cursor over the text. The global variable
20890 updated_window contains the window being updated, updated_row is
20891 the glyph row being updated, and updated_area is the area of that
20892 row being updated. */
20895 x_write_glyphs (start
, len
)
20896 struct glyph
*start
;
20901 xassert (updated_window
&& updated_row
);
20904 /* Write glyphs. */
20906 hpos
= start
- updated_row
->glyphs
[updated_area
];
20907 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20908 updated_row
, updated_area
,
20910 DRAW_NORMAL_TEXT
, 0);
20912 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20913 if (updated_area
== TEXT_AREA
20914 && updated_window
->phys_cursor_on_p
20915 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20916 && updated_window
->phys_cursor
.hpos
>= hpos
20917 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20918 updated_window
->phys_cursor_on_p
= 0;
20922 /* Advance the output cursor. */
20923 output_cursor
.hpos
+= len
;
20924 output_cursor
.x
= x
;
20929 Insert LEN glyphs from START at the nominal cursor position. */
20932 x_insert_glyphs (start
, len
)
20933 struct glyph
*start
;
20938 int line_height
, shift_by_width
, shifted_region_width
;
20939 struct glyph_row
*row
;
20940 struct glyph
*glyph
;
20941 int frame_x
, frame_y
, hpos
;
20943 xassert (updated_window
&& updated_row
);
20945 w
= updated_window
;
20946 f
= XFRAME (WINDOW_FRAME (w
));
20948 /* Get the height of the line we are in. */
20950 line_height
= row
->height
;
20952 /* Get the width of the glyphs to insert. */
20953 shift_by_width
= 0;
20954 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20955 shift_by_width
+= glyph
->pixel_width
;
20957 /* Get the width of the region to shift right. */
20958 shifted_region_width
= (window_box_width (w
, updated_area
)
20963 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20964 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20966 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20967 line_height
, shift_by_width
);
20969 /* Write the glyphs. */
20970 hpos
= start
- row
->glyphs
[updated_area
];
20971 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20973 DRAW_NORMAL_TEXT
, 0);
20975 /* Advance the output cursor. */
20976 output_cursor
.hpos
+= len
;
20977 output_cursor
.x
+= shift_by_width
;
20983 Erase the current text line from the nominal cursor position
20984 (inclusive) to pixel column TO_X (exclusive). The idea is that
20985 everything from TO_X onward is already erased.
20987 TO_X is a pixel position relative to updated_area of
20988 updated_window. TO_X == -1 means clear to the end of this area. */
20991 x_clear_end_of_line (to_x
)
20995 struct window
*w
= updated_window
;
20996 int max_x
, min_y
, max_y
;
20997 int from_x
, from_y
, to_y
;
20999 xassert (updated_window
&& updated_row
);
21000 f
= XFRAME (w
->frame
);
21002 if (updated_row
->full_width_p
)
21003 max_x
= WINDOW_TOTAL_WIDTH (w
);
21005 max_x
= window_box_width (w
, updated_area
);
21006 max_y
= window_text_bottom_y (w
);
21008 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21009 of window. For TO_X > 0, truncate to end of drawing area. */
21015 to_x
= min (to_x
, max_x
);
21017 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21019 /* Notice if the cursor will be cleared by this operation. */
21020 if (!updated_row
->full_width_p
)
21021 notice_overwritten_cursor (w
, updated_area
,
21022 output_cursor
.x
, -1,
21024 MATRIX_ROW_BOTTOM_Y (updated_row
));
21026 from_x
= output_cursor
.x
;
21028 /* Translate to frame coordinates. */
21029 if (updated_row
->full_width_p
)
21031 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21032 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21036 int area_left
= window_box_left (w
, updated_area
);
21037 from_x
+= area_left
;
21041 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21042 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21043 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21045 /* Prevent inadvertently clearing to end of the X window. */
21046 if (to_x
> from_x
&& to_y
> from_y
)
21049 rif
->clear_frame_area (f
, from_x
, from_y
,
21050 to_x
- from_x
, to_y
- from_y
);
21055 #endif /* HAVE_WINDOW_SYSTEM */
21059 /***********************************************************************
21061 ***********************************************************************/
21063 /* Value is the internal representation of the specified cursor type
21064 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21065 of the bar cursor. */
21067 static enum text_cursor_kinds
21068 get_specified_cursor_type (arg
, width
)
21072 enum text_cursor_kinds type
;
21077 if (EQ (arg
, Qbox
))
21078 return FILLED_BOX_CURSOR
;
21080 if (EQ (arg
, Qhollow
))
21081 return HOLLOW_BOX_CURSOR
;
21083 if (EQ (arg
, Qbar
))
21090 && EQ (XCAR (arg
), Qbar
)
21091 && INTEGERP (XCDR (arg
))
21092 && XINT (XCDR (arg
)) >= 0)
21094 *width
= XINT (XCDR (arg
));
21098 if (EQ (arg
, Qhbar
))
21101 return HBAR_CURSOR
;
21105 && EQ (XCAR (arg
), Qhbar
)
21106 && INTEGERP (XCDR (arg
))
21107 && XINT (XCDR (arg
)) >= 0)
21109 *width
= XINT (XCDR (arg
));
21110 return HBAR_CURSOR
;
21113 /* Treat anything unknown as "hollow box cursor".
21114 It was bad to signal an error; people have trouble fixing
21115 .Xdefaults with Emacs, when it has something bad in it. */
21116 type
= HOLLOW_BOX_CURSOR
;
21121 /* Set the default cursor types for specified frame. */
21123 set_frame_cursor_types (f
, arg
)
21130 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21131 FRAME_CURSOR_WIDTH (f
) = width
;
21133 /* By default, set up the blink-off state depending on the on-state. */
21135 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21138 FRAME_BLINK_OFF_CURSOR (f
)
21139 = get_specified_cursor_type (XCDR (tem
), &width
);
21140 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21143 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21147 /* Return the cursor we want to be displayed in window W. Return
21148 width of bar/hbar cursor through WIDTH arg. Return with
21149 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21150 (i.e. if the `system caret' should track this cursor).
21152 In a mini-buffer window, we want the cursor only to appear if we
21153 are reading input from this window. For the selected window, we
21154 want the cursor type given by the frame parameter or buffer local
21155 setting of cursor-type. If explicitly marked off, draw no cursor.
21156 In all other cases, we want a hollow box cursor. */
21158 static enum text_cursor_kinds
21159 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21161 struct glyph
*glyph
;
21163 int *active_cursor
;
21165 struct frame
*f
= XFRAME (w
->frame
);
21166 struct buffer
*b
= XBUFFER (w
->buffer
);
21167 int cursor_type
= DEFAULT_CURSOR
;
21168 Lisp_Object alt_cursor
;
21169 int non_selected
= 0;
21171 *active_cursor
= 1;
21174 if (cursor_in_echo_area
21175 && FRAME_HAS_MINIBUF_P (f
)
21176 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21178 if (w
== XWINDOW (echo_area_window
))
21180 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21182 *width
= FRAME_CURSOR_WIDTH (f
);
21183 return FRAME_DESIRED_CURSOR (f
);
21186 return get_specified_cursor_type (b
->cursor_type
, width
);
21189 *active_cursor
= 0;
21193 /* Nonselected window or nonselected frame. */
21194 else if (w
!= XWINDOW (f
->selected_window
)
21195 #ifdef HAVE_WINDOW_SYSTEM
21196 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21200 *active_cursor
= 0;
21202 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21208 /* Never display a cursor in a window in which cursor-type is nil. */
21209 if (NILP (b
->cursor_type
))
21212 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21215 alt_cursor
= b
->cursor_in_non_selected_windows
;
21216 return get_specified_cursor_type (alt_cursor
, width
);
21219 /* Get the normal cursor type for this window. */
21220 if (EQ (b
->cursor_type
, Qt
))
21222 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21223 *width
= FRAME_CURSOR_WIDTH (f
);
21226 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21228 /* Use normal cursor if not blinked off. */
21229 if (!w
->cursor_off_p
)
21231 #ifdef HAVE_WINDOW_SYSTEM
21232 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21234 if (cursor_type
== FILLED_BOX_CURSOR
)
21236 /* Using a block cursor on large images can be very annoying.
21237 So use a hollow cursor for "large" images. */
21238 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21239 if (img
!= NULL
&& IMAGEP (img
->spec
))
21241 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21242 where N = size of default frame font size.
21243 This should cover most of the "tiny" icons people may use. */
21244 if (img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21245 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21246 cursor_type
= HOLLOW_BOX_CURSOR
;
21249 else if (cursor_type
!= NO_CURSOR
)
21251 /* Display current only supports BOX and HOLLOW cursors for images.
21252 So for now, unconditionally use a HOLLOW cursor when cursor is
21253 not a solid box cursor. */
21254 cursor_type
= HOLLOW_BOX_CURSOR
;
21258 return cursor_type
;
21261 /* Cursor is blinked off, so determine how to "toggle" it. */
21263 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21264 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21265 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21267 /* Then see if frame has specified a specific blink off cursor type. */
21268 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21270 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21271 return FRAME_BLINK_OFF_CURSOR (f
);
21275 /* Some people liked having a permanently visible blinking cursor,
21276 while others had very strong opinions against it. So it was
21277 decided to remove it. KFS 2003-09-03 */
21279 /* Finally perform built-in cursor blinking:
21280 filled box <-> hollow box
21281 wide [h]bar <-> narrow [h]bar
21282 narrow [h]bar <-> no cursor
21283 other type <-> no cursor */
21285 if (cursor_type
== FILLED_BOX_CURSOR
)
21286 return HOLLOW_BOX_CURSOR
;
21288 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21291 return cursor_type
;
21299 #ifdef HAVE_WINDOW_SYSTEM
21301 /* Notice when the text cursor of window W has been completely
21302 overwritten by a drawing operation that outputs glyphs in AREA
21303 starting at X0 and ending at X1 in the line starting at Y0 and
21304 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21305 the rest of the line after X0 has been written. Y coordinates
21306 are window-relative. */
21309 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21311 enum glyph_row_area area
;
21312 int x0
, y0
, x1
, y1
;
21314 int cx0
, cx1
, cy0
, cy1
;
21315 struct glyph_row
*row
;
21317 if (!w
->phys_cursor_on_p
)
21319 if (area
!= TEXT_AREA
)
21322 if (w
->phys_cursor
.vpos
< 0
21323 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21324 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21325 !(row
->enabled_p
&& row
->displays_text_p
)))
21328 if (row
->cursor_in_fringe_p
)
21330 row
->cursor_in_fringe_p
= 0;
21331 draw_fringe_bitmap (w
, row
, 0);
21332 w
->phys_cursor_on_p
= 0;
21336 cx0
= w
->phys_cursor
.x
;
21337 cx1
= cx0
+ w
->phys_cursor_width
;
21338 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21341 /* The cursor image will be completely removed from the
21342 screen if the output area intersects the cursor area in
21343 y-direction. When we draw in [y0 y1[, and some part of
21344 the cursor is at y < y0, that part must have been drawn
21345 before. When scrolling, the cursor is erased before
21346 actually scrolling, so we don't come here. When not
21347 scrolling, the rows above the old cursor row must have
21348 changed, and in this case these rows must have written
21349 over the cursor image.
21351 Likewise if part of the cursor is below y1, with the
21352 exception of the cursor being in the first blank row at
21353 the buffer and window end because update_text_area
21354 doesn't draw that row. (Except when it does, but
21355 that's handled in update_text_area.) */
21357 cy0
= w
->phys_cursor
.y
;
21358 cy1
= cy0
+ w
->phys_cursor_height
;
21359 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21362 w
->phys_cursor_on_p
= 0;
21365 #endif /* HAVE_WINDOW_SYSTEM */
21368 /************************************************************************
21370 ************************************************************************/
21372 #ifdef HAVE_WINDOW_SYSTEM
21375 Fix the display of area AREA of overlapping row ROW in window W
21376 with respect to the overlapping part OVERLAPS. */
21379 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21381 struct glyph_row
*row
;
21382 enum glyph_row_area area
;
21390 for (i
= 0; i
< row
->used
[area
];)
21392 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21394 int start
= i
, start_x
= x
;
21398 x
+= row
->glyphs
[area
][i
].pixel_width
;
21401 while (i
< row
->used
[area
]
21402 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21404 draw_glyphs (w
, start_x
, row
, area
,
21406 DRAW_NORMAL_TEXT
, overlaps
);
21410 x
+= row
->glyphs
[area
][i
].pixel_width
;
21420 Draw the cursor glyph of window W in glyph row ROW. See the
21421 comment of draw_glyphs for the meaning of HL. */
21424 draw_phys_cursor_glyph (w
, row
, hl
)
21426 struct glyph_row
*row
;
21427 enum draw_glyphs_face hl
;
21429 /* If cursor hpos is out of bounds, don't draw garbage. This can
21430 happen in mini-buffer windows when switching between echo area
21431 glyphs and mini-buffer. */
21432 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21434 int on_p
= w
->phys_cursor_on_p
;
21436 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21437 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21439 w
->phys_cursor_on_p
= on_p
;
21441 if (hl
== DRAW_CURSOR
)
21442 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21443 /* When we erase the cursor, and ROW is overlapped by other
21444 rows, make sure that these overlapping parts of other rows
21446 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21448 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21450 if (row
> w
->current_matrix
->rows
21451 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21452 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21453 OVERLAPS_ERASED_CURSOR
);
21455 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21456 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21457 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21458 OVERLAPS_ERASED_CURSOR
);
21465 Erase the image of a cursor of window W from the screen. */
21468 erase_phys_cursor (w
)
21471 struct frame
*f
= XFRAME (w
->frame
);
21472 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21473 int hpos
= w
->phys_cursor
.hpos
;
21474 int vpos
= w
->phys_cursor
.vpos
;
21475 int mouse_face_here_p
= 0;
21476 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21477 struct glyph_row
*cursor_row
;
21478 struct glyph
*cursor_glyph
;
21479 enum draw_glyphs_face hl
;
21481 /* No cursor displayed or row invalidated => nothing to do on the
21483 if (w
->phys_cursor_type
== NO_CURSOR
)
21484 goto mark_cursor_off
;
21486 /* VPOS >= active_glyphs->nrows means that window has been resized.
21487 Don't bother to erase the cursor. */
21488 if (vpos
>= active_glyphs
->nrows
)
21489 goto mark_cursor_off
;
21491 /* If row containing cursor is marked invalid, there is nothing we
21493 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21494 if (!cursor_row
->enabled_p
)
21495 goto mark_cursor_off
;
21497 /* If line spacing is > 0, old cursor may only be partially visible in
21498 window after split-window. So adjust visible height. */
21499 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21500 window_text_bottom_y (w
) - cursor_row
->y
);
21502 /* If row is completely invisible, don't attempt to delete a cursor which
21503 isn't there. This can happen if cursor is at top of a window, and
21504 we switch to a buffer with a header line in that window. */
21505 if (cursor_row
->visible_height
<= 0)
21506 goto mark_cursor_off
;
21508 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21509 if (cursor_row
->cursor_in_fringe_p
)
21511 cursor_row
->cursor_in_fringe_p
= 0;
21512 draw_fringe_bitmap (w
, cursor_row
, 0);
21513 goto mark_cursor_off
;
21516 /* This can happen when the new row is shorter than the old one.
21517 In this case, either draw_glyphs or clear_end_of_line
21518 should have cleared the cursor. Note that we wouldn't be
21519 able to erase the cursor in this case because we don't have a
21520 cursor glyph at hand. */
21521 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21522 goto mark_cursor_off
;
21524 /* If the cursor is in the mouse face area, redisplay that when
21525 we clear the cursor. */
21526 if (! NILP (dpyinfo
->mouse_face_window
)
21527 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21528 && (vpos
> dpyinfo
->mouse_face_beg_row
21529 || (vpos
== dpyinfo
->mouse_face_beg_row
21530 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21531 && (vpos
< dpyinfo
->mouse_face_end_row
21532 || (vpos
== dpyinfo
->mouse_face_end_row
21533 && hpos
< dpyinfo
->mouse_face_end_col
))
21534 /* Don't redraw the cursor's spot in mouse face if it is at the
21535 end of a line (on a newline). The cursor appears there, but
21536 mouse highlighting does not. */
21537 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21538 mouse_face_here_p
= 1;
21540 /* Maybe clear the display under the cursor. */
21541 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21544 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21547 cursor_glyph
= get_phys_cursor_glyph (w
);
21548 if (cursor_glyph
== NULL
)
21549 goto mark_cursor_off
;
21551 width
= cursor_glyph
->pixel_width
;
21552 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21553 x
= w
->phys_cursor
.x
;
21555 width
-= left_x
- x
;
21556 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21557 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21558 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21561 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21564 /* Erase the cursor by redrawing the character underneath it. */
21565 if (mouse_face_here_p
)
21566 hl
= DRAW_MOUSE_FACE
;
21568 hl
= DRAW_NORMAL_TEXT
;
21569 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21572 w
->phys_cursor_on_p
= 0;
21573 w
->phys_cursor_type
= NO_CURSOR
;
21578 Display or clear cursor of window W. If ON is zero, clear the
21579 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21580 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21583 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21585 int on
, hpos
, vpos
, x
, y
;
21587 struct frame
*f
= XFRAME (w
->frame
);
21588 int new_cursor_type
;
21589 int new_cursor_width
;
21591 struct glyph_row
*glyph_row
;
21592 struct glyph
*glyph
;
21594 /* This is pointless on invisible frames, and dangerous on garbaged
21595 windows and frames; in the latter case, the frame or window may
21596 be in the midst of changing its size, and x and y may be off the
21598 if (! FRAME_VISIBLE_P (f
)
21599 || FRAME_GARBAGED_P (f
)
21600 || vpos
>= w
->current_matrix
->nrows
21601 || hpos
>= w
->current_matrix
->matrix_w
)
21604 /* If cursor is off and we want it off, return quickly. */
21605 if (!on
&& !w
->phys_cursor_on_p
)
21608 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21609 /* If cursor row is not enabled, we don't really know where to
21610 display the cursor. */
21611 if (!glyph_row
->enabled_p
)
21613 w
->phys_cursor_on_p
= 0;
21618 if (!glyph_row
->exact_window_width_line_p
21619 || hpos
< glyph_row
->used
[TEXT_AREA
])
21620 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21622 xassert (interrupt_input_blocked
);
21624 /* Set new_cursor_type to the cursor we want to be displayed. */
21625 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21626 &new_cursor_width
, &active_cursor
);
21628 /* If cursor is currently being shown and we don't want it to be or
21629 it is in the wrong place, or the cursor type is not what we want,
21631 if (w
->phys_cursor_on_p
21633 || w
->phys_cursor
.x
!= x
21634 || w
->phys_cursor
.y
!= y
21635 || new_cursor_type
!= w
->phys_cursor_type
21636 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21637 && new_cursor_width
!= w
->phys_cursor_width
)))
21638 erase_phys_cursor (w
);
21640 /* Don't check phys_cursor_on_p here because that flag is only set
21641 to zero in some cases where we know that the cursor has been
21642 completely erased, to avoid the extra work of erasing the cursor
21643 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21644 still not be visible, or it has only been partly erased. */
21647 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21648 w
->phys_cursor_height
= glyph_row
->height
;
21650 /* Set phys_cursor_.* before x_draw_.* is called because some
21651 of them may need the information. */
21652 w
->phys_cursor
.x
= x
;
21653 w
->phys_cursor
.y
= glyph_row
->y
;
21654 w
->phys_cursor
.hpos
= hpos
;
21655 w
->phys_cursor
.vpos
= vpos
;
21658 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21659 new_cursor_type
, new_cursor_width
,
21660 on
, active_cursor
);
21664 /* Switch the display of W's cursor on or off, according to the value
21668 update_window_cursor (w
, on
)
21672 /* Don't update cursor in windows whose frame is in the process
21673 of being deleted. */
21674 if (w
->current_matrix
)
21677 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21678 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21684 /* Call update_window_cursor with parameter ON_P on all leaf windows
21685 in the window tree rooted at W. */
21688 update_cursor_in_window_tree (w
, on_p
)
21694 if (!NILP (w
->hchild
))
21695 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21696 else if (!NILP (w
->vchild
))
21697 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21699 update_window_cursor (w
, on_p
);
21701 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21707 Display the cursor on window W, or clear it, according to ON_P.
21708 Don't change the cursor's position. */
21711 x_update_cursor (f
, on_p
)
21715 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21720 Clear the cursor of window W to background color, and mark the
21721 cursor as not shown. This is used when the text where the cursor
21722 is is about to be rewritten. */
21728 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21729 update_window_cursor (w
, 0);
21734 Display the active region described by mouse_face_* according to DRAW. */
21737 show_mouse_face (dpyinfo
, draw
)
21738 Display_Info
*dpyinfo
;
21739 enum draw_glyphs_face draw
;
21741 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21742 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21744 if (/* If window is in the process of being destroyed, don't bother
21746 w
->current_matrix
!= NULL
21747 /* Don't update mouse highlight if hidden */
21748 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21749 /* Recognize when we are called to operate on rows that don't exist
21750 anymore. This can happen when a window is split. */
21751 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21753 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21754 struct glyph_row
*row
, *first
, *last
;
21756 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21757 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21759 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21761 int start_hpos
, end_hpos
, start_x
;
21763 /* For all but the first row, the highlight starts at column 0. */
21766 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21767 start_x
= dpyinfo
->mouse_face_beg_x
;
21776 end_hpos
= dpyinfo
->mouse_face_end_col
;
21779 end_hpos
= row
->used
[TEXT_AREA
];
21780 if (draw
== DRAW_NORMAL_TEXT
)
21781 row
->fill_line_p
= 1; /* Clear to end of line */
21784 if (end_hpos
> start_hpos
)
21786 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21787 start_hpos
, end_hpos
,
21791 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21795 /* When we've written over the cursor, arrange for it to
21796 be displayed again. */
21797 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21800 display_and_set_cursor (w
, 1,
21801 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21802 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21807 /* Change the mouse cursor. */
21808 if (draw
== DRAW_NORMAL_TEXT
)
21809 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21810 else if (draw
== DRAW_MOUSE_FACE
)
21811 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21813 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21817 Clear out the mouse-highlighted active region.
21818 Redraw it un-highlighted first. Value is non-zero if mouse
21819 face was actually drawn unhighlighted. */
21822 clear_mouse_face (dpyinfo
)
21823 Display_Info
*dpyinfo
;
21827 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21829 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21833 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21834 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21835 dpyinfo
->mouse_face_window
= Qnil
;
21836 dpyinfo
->mouse_face_overlay
= Qnil
;
21842 Non-zero if physical cursor of window W is within mouse face. */
21845 cursor_in_mouse_face_p (w
)
21848 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21849 int in_mouse_face
= 0;
21851 if (WINDOWP (dpyinfo
->mouse_face_window
)
21852 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21854 int hpos
= w
->phys_cursor
.hpos
;
21855 int vpos
= w
->phys_cursor
.vpos
;
21857 if (vpos
>= dpyinfo
->mouse_face_beg_row
21858 && vpos
<= dpyinfo
->mouse_face_end_row
21859 && (vpos
> dpyinfo
->mouse_face_beg_row
21860 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21861 && (vpos
< dpyinfo
->mouse_face_end_row
21862 || hpos
< dpyinfo
->mouse_face_end_col
21863 || dpyinfo
->mouse_face_past_end
))
21867 return in_mouse_face
;
21873 /* Find the glyph matrix position of buffer position CHARPOS in window
21874 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21875 current glyphs must be up to date. If CHARPOS is above window
21876 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21877 of last line in W. In the row containing CHARPOS, stop before glyphs
21878 having STOP as object. */
21880 #if 1 /* This is a version of fast_find_position that's more correct
21881 in the presence of hscrolling, for example. I didn't install
21882 it right away because the problem fixed is minor, it failed
21883 in 20.x as well, and I think it's too risky to install
21884 so near the release of 21.1. 2001-09-25 gerd. */
21887 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21890 int *hpos
, *vpos
, *x
, *y
;
21893 struct glyph_row
*row
, *first
;
21894 struct glyph
*glyph
, *end
;
21897 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21898 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21903 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21907 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21910 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21914 /* If whole rows or last part of a row came from a display overlay,
21915 row_containing_pos will skip over such rows because their end pos
21916 equals the start pos of the overlay or interval.
21918 Move back if we have a STOP object and previous row's
21919 end glyph came from STOP. */
21922 struct glyph_row
*prev
;
21923 while ((prev
= row
- 1, prev
>= first
)
21924 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21925 && prev
->used
[TEXT_AREA
] > 0)
21927 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21928 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21929 while (--glyph
>= beg
21930 && INTEGERP (glyph
->object
));
21932 || !EQ (stop
, glyph
->object
))
21940 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21942 glyph
= row
->glyphs
[TEXT_AREA
];
21943 end
= glyph
+ row
->used
[TEXT_AREA
];
21945 /* Skip over glyphs not having an object at the start of the row.
21946 These are special glyphs like truncation marks on terminal
21948 if (row
->displays_text_p
)
21950 && INTEGERP (glyph
->object
)
21951 && !EQ (stop
, glyph
->object
)
21952 && glyph
->charpos
< 0)
21954 *x
+= glyph
->pixel_width
;
21959 && !INTEGERP (glyph
->object
)
21960 && !EQ (stop
, glyph
->object
)
21961 && (!BUFFERP (glyph
->object
)
21962 || glyph
->charpos
< charpos
))
21964 *x
+= glyph
->pixel_width
;
21968 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21975 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21978 int *hpos
, *vpos
, *x
, *y
;
21983 int maybe_next_line_p
= 0;
21984 int line_start_position
;
21985 int yb
= window_text_bottom_y (w
);
21986 struct glyph_row
*row
, *best_row
;
21987 int row_vpos
, best_row_vpos
;
21990 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21991 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21993 while (row
->y
< yb
)
21995 if (row
->used
[TEXT_AREA
])
21996 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21998 line_start_position
= 0;
22000 if (line_start_position
> pos
)
22002 /* If the position sought is the end of the buffer,
22003 don't include the blank lines at the bottom of the window. */
22004 else if (line_start_position
== pos
22005 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22007 maybe_next_line_p
= 1;
22010 else if (line_start_position
> 0)
22013 best_row_vpos
= row_vpos
;
22016 if (row
->y
+ row
->height
>= yb
)
22023 /* Find the right column within BEST_ROW. */
22025 current_x
= best_row
->x
;
22026 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22028 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22029 int charpos
= glyph
->charpos
;
22031 if (BUFFERP (glyph
->object
))
22033 if (charpos
== pos
)
22036 *vpos
= best_row_vpos
;
22041 else if (charpos
> pos
)
22044 else if (EQ (glyph
->object
, stop
))
22049 current_x
+= glyph
->pixel_width
;
22052 /* If we're looking for the end of the buffer,
22053 and we didn't find it in the line we scanned,
22054 use the start of the following line. */
22055 if (maybe_next_line_p
)
22060 current_x
= best_row
->x
;
22063 *vpos
= best_row_vpos
;
22064 *hpos
= lastcol
+ 1;
22073 /* Find the position of the glyph for position POS in OBJECT in
22074 window W's current matrix, and return in *X, *Y the pixel
22075 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22077 RIGHT_P non-zero means return the position of the right edge of the
22078 glyph, RIGHT_P zero means return the left edge position.
22080 If no glyph for POS exists in the matrix, return the position of
22081 the glyph with the next smaller position that is in the matrix, if
22082 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22083 exists in the matrix, return the position of the glyph with the
22084 next larger position in OBJECT.
22086 Value is non-zero if a glyph was found. */
22089 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22092 Lisp_Object object
;
22093 int *hpos
, *vpos
, *x
, *y
;
22096 int yb
= window_text_bottom_y (w
);
22097 struct glyph_row
*r
;
22098 struct glyph
*best_glyph
= NULL
;
22099 struct glyph_row
*best_row
= NULL
;
22102 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22103 r
->enabled_p
&& r
->y
< yb
;
22106 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22107 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22110 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22111 if (EQ (g
->object
, object
))
22113 if (g
->charpos
== pos
)
22120 else if (best_glyph
== NULL
22121 || ((abs (g
->charpos
- pos
)
22122 < abs (best_glyph
->charpos
- pos
))
22125 : g
->charpos
> pos
)))
22139 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22143 *x
+= best_glyph
->pixel_width
;
22148 *vpos
= best_row
- w
->current_matrix
->rows
;
22151 return best_glyph
!= NULL
;
22155 /* See if position X, Y is within a hot-spot of an image. */
22158 on_hot_spot_p (hot_spot
, x
, y
)
22159 Lisp_Object hot_spot
;
22162 if (!CONSP (hot_spot
))
22165 if (EQ (XCAR (hot_spot
), Qrect
))
22167 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22168 Lisp_Object rect
= XCDR (hot_spot
);
22172 if (!CONSP (XCAR (rect
)))
22174 if (!CONSP (XCDR (rect
)))
22176 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22178 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22180 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22182 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22186 else if (EQ (XCAR (hot_spot
), Qcircle
))
22188 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22189 Lisp_Object circ
= XCDR (hot_spot
);
22190 Lisp_Object lr
, lx0
, ly0
;
22192 && CONSP (XCAR (circ
))
22193 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22194 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22195 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22197 double r
= XFLOATINT (lr
);
22198 double dx
= XINT (lx0
) - x
;
22199 double dy
= XINT (ly0
) - y
;
22200 return (dx
* dx
+ dy
* dy
<= r
* r
);
22203 else if (EQ (XCAR (hot_spot
), Qpoly
))
22205 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22206 if (VECTORP (XCDR (hot_spot
)))
22208 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22209 Lisp_Object
*poly
= v
->contents
;
22213 Lisp_Object lx
, ly
;
22216 /* Need an even number of coordinates, and at least 3 edges. */
22217 if (n
< 6 || n
& 1)
22220 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22221 If count is odd, we are inside polygon. Pixels on edges
22222 may or may not be included depending on actual geometry of the
22224 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22225 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22227 x0
= XINT (lx
), y0
= XINT (ly
);
22228 for (i
= 0; i
< n
; i
+= 2)
22230 int x1
= x0
, y1
= y0
;
22231 if ((lx
= poly
[i
], !INTEGERP (lx
))
22232 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22234 x0
= XINT (lx
), y0
= XINT (ly
);
22236 /* Does this segment cross the X line? */
22244 if (y
> y0
&& y
> y1
)
22246 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22252 /* If we don't understand the format, pretend we're not in the hot-spot. */
22257 find_hot_spot (map
, x
, y
)
22261 while (CONSP (map
))
22263 if (CONSP (XCAR (map
))
22264 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22272 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22274 doc
: /* Lookup in image map MAP coordinates X and Y.
22275 An image map is an alist where each element has the format (AREA ID PLIST).
22276 An AREA is specified as either a rectangle, a circle, or a polygon:
22277 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22278 pixel coordinates of the upper left and bottom right corners.
22279 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22280 and the radius of the circle; r may be a float or integer.
22281 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22282 vector describes one corner in the polygon.
22283 Returns the alist element for the first matching AREA in MAP. */)
22294 return find_hot_spot (map
, XINT (x
), XINT (y
));
22298 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22300 define_frame_cursor1 (f
, cursor
, pointer
)
22303 Lisp_Object pointer
;
22305 /* Do not change cursor shape while dragging mouse. */
22306 if (!NILP (do_mouse_tracking
))
22309 if (!NILP (pointer
))
22311 if (EQ (pointer
, Qarrow
))
22312 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22313 else if (EQ (pointer
, Qhand
))
22314 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22315 else if (EQ (pointer
, Qtext
))
22316 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22317 else if (EQ (pointer
, intern ("hdrag")))
22318 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22319 #ifdef HAVE_X_WINDOWS
22320 else if (EQ (pointer
, intern ("vdrag")))
22321 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22323 else if (EQ (pointer
, intern ("hourglass")))
22324 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22325 else if (EQ (pointer
, Qmodeline
))
22326 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22328 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22331 if (cursor
!= No_Cursor
)
22332 rif
->define_frame_cursor (f
, cursor
);
22335 /* Take proper action when mouse has moved to the mode or header line
22336 or marginal area AREA of window W, x-position X and y-position Y.
22337 X is relative to the start of the text display area of W, so the
22338 width of bitmap areas and scroll bars must be subtracted to get a
22339 position relative to the start of the mode line. */
22342 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22343 Lisp_Object window
;
22345 enum window_part area
;
22347 struct window
*w
= XWINDOW (window
);
22348 struct frame
*f
= XFRAME (w
->frame
);
22349 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22350 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22351 Lisp_Object pointer
= Qnil
;
22352 int charpos
, dx
, dy
, width
, height
;
22353 Lisp_Object string
, object
= Qnil
;
22354 Lisp_Object pos
, help
;
22356 Lisp_Object mouse_face
;
22357 int original_x_pixel
= x
;
22358 struct glyph
* glyph
= NULL
;
22359 struct glyph_row
*row
;
22361 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22366 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22367 &object
, &dx
, &dy
, &width
, &height
);
22369 row
= (area
== ON_MODE_LINE
22370 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22371 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22374 if (row
->mode_line_p
&& row
->enabled_p
)
22376 glyph
= row
->glyphs
[TEXT_AREA
];
22377 end
= glyph
+ row
->used
[TEXT_AREA
];
22379 for (x0
= original_x_pixel
;
22380 glyph
< end
&& x0
>= glyph
->pixel_width
;
22382 x0
-= glyph
->pixel_width
;
22390 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22391 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22392 &object
, &dx
, &dy
, &width
, &height
);
22397 if (IMAGEP (object
))
22399 Lisp_Object image_map
, hotspot
;
22400 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22402 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22404 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22406 Lisp_Object area_id
, plist
;
22408 area_id
= XCAR (hotspot
);
22409 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22410 If so, we could look for mouse-enter, mouse-leave
22411 properties in PLIST (and do something...). */
22412 hotspot
= XCDR (hotspot
);
22413 if (CONSP (hotspot
)
22414 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22416 pointer
= Fplist_get (plist
, Qpointer
);
22417 if (NILP (pointer
))
22419 help
= Fplist_get (plist
, Qhelp_echo
);
22422 help_echo_string
= help
;
22423 /* Is this correct? ++kfs */
22424 XSETWINDOW (help_echo_window
, w
);
22425 help_echo_object
= w
->buffer
;
22426 help_echo_pos
= charpos
;
22430 if (NILP (pointer
))
22431 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22434 if (STRINGP (string
))
22436 pos
= make_number (charpos
);
22437 /* If we're on a string with `help-echo' text property, arrange
22438 for the help to be displayed. This is done by setting the
22439 global variable help_echo_string to the help string. */
22442 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22445 help_echo_string
= help
;
22446 XSETWINDOW (help_echo_window
, w
);
22447 help_echo_object
= string
;
22448 help_echo_pos
= charpos
;
22452 if (NILP (pointer
))
22453 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22455 /* Change the mouse pointer according to what is under X/Y. */
22456 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22459 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22460 if (!KEYMAPP (map
))
22461 map
= Fget_text_property (pos
, Qkeymap
, string
);
22462 if (!KEYMAPP (map
))
22463 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22466 /* Change the mouse face according to what is under X/Y. */
22467 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22468 if (!NILP (mouse_face
)
22469 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22474 struct glyph
* tmp_glyph
;
22478 int total_pixel_width
;
22483 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22484 Qmouse_face
, string
, Qnil
);
22486 b
= make_number (0);
22488 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22490 e
= make_number (SCHARS (string
));
22492 /* Calculate the position(glyph position: GPOS) of GLYPH in
22493 displayed string. GPOS is different from CHARPOS.
22495 CHARPOS is the position of glyph in internal string
22496 object. A mode line string format has structures which
22497 is converted to a flatten by emacs lisp interpreter.
22498 The internal string is an element of the structures.
22499 The displayed string is the flatten string. */
22500 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22501 tmp_glyph
->charpos
>= XINT (b
);
22502 tmp_glyph
--, gpos
++)
22504 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22508 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22509 displayed string holding GLYPH.
22511 GSEQ_LENGTH is different from SCHARS (STRING).
22512 SCHARS (STRING) returns the length of the internal string. */
22513 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22514 tmp_glyph
->charpos
< XINT (e
);
22515 tmp_glyph
++, gseq_length
++)
22517 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22521 total_pixel_width
= 0;
22522 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22523 total_pixel_width
+= tmp_glyph
->pixel_width
;
22525 /* Pre calculation of re-rendering position */
22527 hpos
= (area
== ON_MODE_LINE
22528 ? (w
->current_matrix
)->nrows
- 1
22531 /* If the re-rendering position is included in the last
22532 re-rendering area, we should do nothing. */
22533 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22534 && dpyinfo
->mouse_face_beg_col
<= vpos
22535 && vpos
< dpyinfo
->mouse_face_end_col
22536 && dpyinfo
->mouse_face_beg_row
== hpos
)
22539 if (clear_mouse_face (dpyinfo
))
22540 cursor
= No_Cursor
;
22542 dpyinfo
->mouse_face_beg_col
= vpos
;
22543 dpyinfo
->mouse_face_beg_row
= hpos
;
22545 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22546 dpyinfo
->mouse_face_beg_y
= 0;
22548 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22549 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22551 dpyinfo
->mouse_face_end_x
= 0;
22552 dpyinfo
->mouse_face_end_y
= 0;
22554 dpyinfo
->mouse_face_past_end
= 0;
22555 dpyinfo
->mouse_face_window
= window
;
22557 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22560 glyph
->face_id
, 1);
22561 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22563 if (NILP (pointer
))
22566 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22567 clear_mouse_face (dpyinfo
);
22569 define_frame_cursor1 (f
, cursor
, pointer
);
22574 Take proper action when the mouse has moved to position X, Y on
22575 frame F as regards highlighting characters that have mouse-face
22576 properties. Also de-highlighting chars where the mouse was before.
22577 X and Y can be negative or out of range. */
22580 note_mouse_highlight (f
, x
, y
)
22584 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22585 enum window_part part
;
22586 Lisp_Object window
;
22588 Cursor cursor
= No_Cursor
;
22589 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22592 /* When a menu is active, don't highlight because this looks odd. */
22593 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22594 if (popup_activated ())
22598 if (NILP (Vmouse_highlight
)
22599 || !f
->glyphs_initialized_p
)
22602 dpyinfo
->mouse_face_mouse_x
= x
;
22603 dpyinfo
->mouse_face_mouse_y
= y
;
22604 dpyinfo
->mouse_face_mouse_frame
= f
;
22606 if (dpyinfo
->mouse_face_defer
)
22609 if (gc_in_progress
)
22611 dpyinfo
->mouse_face_deferred_gc
= 1;
22615 /* Which window is that in? */
22616 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22618 /* If we were displaying active text in another window, clear that.
22619 Also clear if we move out of text area in same window. */
22620 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22621 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22622 && !NILP (dpyinfo
->mouse_face_window
)))
22623 clear_mouse_face (dpyinfo
);
22625 /* Not on a window -> return. */
22626 if (!WINDOWP (window
))
22629 /* Reset help_echo_string. It will get recomputed below. */
22630 help_echo_string
= Qnil
;
22632 /* Convert to window-relative pixel coordinates. */
22633 w
= XWINDOW (window
);
22634 frame_to_window_pixel_xy (w
, &x
, &y
);
22636 /* Handle tool-bar window differently since it doesn't display a
22638 if (EQ (window
, f
->tool_bar_window
))
22640 note_tool_bar_highlight (f
, x
, y
);
22644 /* Mouse is on the mode, header line or margin? */
22645 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22646 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22648 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22652 if (part
== ON_VERTICAL_BORDER
)
22654 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22655 help_echo_string
= build_string ("drag-mouse-1: resize");
22657 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22658 || part
== ON_SCROLL_BAR
)
22659 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22661 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22663 /* Are we in a window whose display is up to date?
22664 And verify the buffer's text has not changed. */
22665 b
= XBUFFER (w
->buffer
);
22666 if (part
== ON_TEXT
22667 && EQ (w
->window_end_valid
, w
->buffer
)
22668 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22669 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22671 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22672 struct glyph
*glyph
;
22673 Lisp_Object object
;
22674 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22675 Lisp_Object
*overlay_vec
= NULL
;
22677 struct buffer
*obuf
;
22678 int obegv
, ozv
, same_region
;
22680 /* Find the glyph under X/Y. */
22681 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22683 /* Look for :pointer property on image. */
22684 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22686 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22687 if (img
!= NULL
&& IMAGEP (img
->spec
))
22689 Lisp_Object image_map
, hotspot
;
22690 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22692 && (hotspot
= find_hot_spot (image_map
,
22693 glyph
->slice
.x
+ dx
,
22694 glyph
->slice
.y
+ dy
),
22696 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22698 Lisp_Object area_id
, plist
;
22700 area_id
= XCAR (hotspot
);
22701 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22702 If so, we could look for mouse-enter, mouse-leave
22703 properties in PLIST (and do something...). */
22704 hotspot
= XCDR (hotspot
);
22705 if (CONSP (hotspot
)
22706 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22708 pointer
= Fplist_get (plist
, Qpointer
);
22709 if (NILP (pointer
))
22711 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22712 if (!NILP (help_echo_string
))
22714 help_echo_window
= window
;
22715 help_echo_object
= glyph
->object
;
22716 help_echo_pos
= glyph
->charpos
;
22720 if (NILP (pointer
))
22721 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22725 /* Clear mouse face if X/Y not over text. */
22727 || area
!= TEXT_AREA
22728 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22730 if (clear_mouse_face (dpyinfo
))
22731 cursor
= No_Cursor
;
22732 if (NILP (pointer
))
22734 if (area
!= TEXT_AREA
)
22735 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22737 pointer
= Vvoid_text_area_pointer
;
22742 pos
= glyph
->charpos
;
22743 object
= glyph
->object
;
22744 if (!STRINGP (object
) && !BUFFERP (object
))
22747 /* If we get an out-of-range value, return now; avoid an error. */
22748 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22751 /* Make the window's buffer temporarily current for
22752 overlays_at and compute_char_face. */
22753 obuf
= current_buffer
;
22754 current_buffer
= b
;
22760 /* Is this char mouse-active or does it have help-echo? */
22761 position
= make_number (pos
);
22763 if (BUFFERP (object
))
22765 /* Put all the overlays we want in a vector in overlay_vec. */
22766 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22767 /* Sort overlays into increasing priority order. */
22768 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22773 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22774 && vpos
>= dpyinfo
->mouse_face_beg_row
22775 && vpos
<= dpyinfo
->mouse_face_end_row
22776 && (vpos
> dpyinfo
->mouse_face_beg_row
22777 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22778 && (vpos
< dpyinfo
->mouse_face_end_row
22779 || hpos
< dpyinfo
->mouse_face_end_col
22780 || dpyinfo
->mouse_face_past_end
));
22783 cursor
= No_Cursor
;
22785 /* Check mouse-face highlighting. */
22787 /* If there exists an overlay with mouse-face overlapping
22788 the one we are currently highlighting, we have to
22789 check if we enter the overlapping overlay, and then
22790 highlight only that. */
22791 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22792 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22794 /* Find the highest priority overlay that has a mouse-face
22797 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22799 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22800 if (!NILP (mouse_face
))
22801 overlay
= overlay_vec
[i
];
22804 /* If we're actually highlighting the same overlay as
22805 before, there's no need to do that again. */
22806 if (!NILP (overlay
)
22807 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22808 goto check_help_echo
;
22810 dpyinfo
->mouse_face_overlay
= overlay
;
22812 /* Clear the display of the old active region, if any. */
22813 if (clear_mouse_face (dpyinfo
))
22814 cursor
= No_Cursor
;
22816 /* If no overlay applies, get a text property. */
22817 if (NILP (overlay
))
22818 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22820 /* Handle the overlay case. */
22821 if (!NILP (overlay
))
22823 /* Find the range of text around this char that
22824 should be active. */
22825 Lisp_Object before
, after
;
22828 before
= Foverlay_start (overlay
);
22829 after
= Foverlay_end (overlay
);
22830 /* Record this as the current active region. */
22831 fast_find_position (w
, XFASTINT (before
),
22832 &dpyinfo
->mouse_face_beg_col
,
22833 &dpyinfo
->mouse_face_beg_row
,
22834 &dpyinfo
->mouse_face_beg_x
,
22835 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22837 dpyinfo
->mouse_face_past_end
22838 = !fast_find_position (w
, XFASTINT (after
),
22839 &dpyinfo
->mouse_face_end_col
,
22840 &dpyinfo
->mouse_face_end_row
,
22841 &dpyinfo
->mouse_face_end_x
,
22842 &dpyinfo
->mouse_face_end_y
, Qnil
);
22843 dpyinfo
->mouse_face_window
= window
;
22845 dpyinfo
->mouse_face_face_id
22846 = face_at_buffer_position (w
, pos
, 0, 0,
22848 !dpyinfo
->mouse_face_hidden
);
22850 /* Display it as active. */
22851 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22852 cursor
= No_Cursor
;
22854 /* Handle the text property case. */
22855 else if (!NILP (mouse_face
) && BUFFERP (object
))
22857 /* Find the range of text around this char that
22858 should be active. */
22859 Lisp_Object before
, after
, beginning
, end
;
22862 beginning
= Fmarker_position (w
->start
);
22863 end
= make_number (BUF_Z (XBUFFER (object
))
22864 - XFASTINT (w
->window_end_pos
));
22866 = Fprevious_single_property_change (make_number (pos
+ 1),
22868 object
, beginning
);
22870 = Fnext_single_property_change (position
, Qmouse_face
,
22873 /* Record this as the current active region. */
22874 fast_find_position (w
, XFASTINT (before
),
22875 &dpyinfo
->mouse_face_beg_col
,
22876 &dpyinfo
->mouse_face_beg_row
,
22877 &dpyinfo
->mouse_face_beg_x
,
22878 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22879 dpyinfo
->mouse_face_past_end
22880 = !fast_find_position (w
, XFASTINT (after
),
22881 &dpyinfo
->mouse_face_end_col
,
22882 &dpyinfo
->mouse_face_end_row
,
22883 &dpyinfo
->mouse_face_end_x
,
22884 &dpyinfo
->mouse_face_end_y
, Qnil
);
22885 dpyinfo
->mouse_face_window
= window
;
22887 if (BUFFERP (object
))
22888 dpyinfo
->mouse_face_face_id
22889 = face_at_buffer_position (w
, pos
, 0, 0,
22891 !dpyinfo
->mouse_face_hidden
);
22893 /* Display it as active. */
22894 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22895 cursor
= No_Cursor
;
22897 else if (!NILP (mouse_face
) && STRINGP (object
))
22902 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22905 e
= Fnext_single_property_change (position
, Qmouse_face
,
22908 b
= make_number (0);
22910 e
= make_number (SCHARS (object
) - 1);
22912 fast_find_string_pos (w
, XINT (b
), object
,
22913 &dpyinfo
->mouse_face_beg_col
,
22914 &dpyinfo
->mouse_face_beg_row
,
22915 &dpyinfo
->mouse_face_beg_x
,
22916 &dpyinfo
->mouse_face_beg_y
, 0);
22917 fast_find_string_pos (w
, XINT (e
), object
,
22918 &dpyinfo
->mouse_face_end_col
,
22919 &dpyinfo
->mouse_face_end_row
,
22920 &dpyinfo
->mouse_face_end_x
,
22921 &dpyinfo
->mouse_face_end_y
, 1);
22922 dpyinfo
->mouse_face_past_end
= 0;
22923 dpyinfo
->mouse_face_window
= window
;
22924 dpyinfo
->mouse_face_face_id
22925 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22926 glyph
->face_id
, 1);
22927 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22928 cursor
= No_Cursor
;
22930 else if (STRINGP (object
) && NILP (mouse_face
))
22932 /* A string which doesn't have mouse-face, but
22933 the text ``under'' it might have. */
22934 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22935 int start
= MATRIX_ROW_START_CHARPOS (r
);
22937 pos
= string_buffer_position (w
, object
, start
);
22939 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22943 if (!NILP (mouse_face
) && !NILP (overlay
))
22945 Lisp_Object before
= Foverlay_start (overlay
);
22946 Lisp_Object after
= Foverlay_end (overlay
);
22949 /* Note that we might not be able to find position
22950 BEFORE in the glyph matrix if the overlay is
22951 entirely covered by a `display' property. In
22952 this case, we overshoot. So let's stop in
22953 the glyph matrix before glyphs for OBJECT. */
22954 fast_find_position (w
, XFASTINT (before
),
22955 &dpyinfo
->mouse_face_beg_col
,
22956 &dpyinfo
->mouse_face_beg_row
,
22957 &dpyinfo
->mouse_face_beg_x
,
22958 &dpyinfo
->mouse_face_beg_y
,
22961 dpyinfo
->mouse_face_past_end
22962 = !fast_find_position (w
, XFASTINT (after
),
22963 &dpyinfo
->mouse_face_end_col
,
22964 &dpyinfo
->mouse_face_end_row
,
22965 &dpyinfo
->mouse_face_end_x
,
22966 &dpyinfo
->mouse_face_end_y
,
22968 dpyinfo
->mouse_face_window
= window
;
22969 dpyinfo
->mouse_face_face_id
22970 = face_at_buffer_position (w
, pos
, 0, 0,
22972 !dpyinfo
->mouse_face_hidden
);
22974 /* Display it as active. */
22975 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22976 cursor
= No_Cursor
;
22983 /* Look for a `help-echo' property. */
22984 if (NILP (help_echo_string
)) {
22985 Lisp_Object help
, overlay
;
22987 /* Check overlays first. */
22988 help
= overlay
= Qnil
;
22989 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22991 overlay
= overlay_vec
[i
];
22992 help
= Foverlay_get (overlay
, Qhelp_echo
);
22997 help_echo_string
= help
;
22998 help_echo_window
= window
;
22999 help_echo_object
= overlay
;
23000 help_echo_pos
= pos
;
23004 Lisp_Object object
= glyph
->object
;
23005 int charpos
= glyph
->charpos
;
23007 /* Try text properties. */
23008 if (STRINGP (object
)
23010 && charpos
< SCHARS (object
))
23012 help
= Fget_text_property (make_number (charpos
),
23013 Qhelp_echo
, object
);
23016 /* If the string itself doesn't specify a help-echo,
23017 see if the buffer text ``under'' it does. */
23018 struct glyph_row
*r
23019 = MATRIX_ROW (w
->current_matrix
, vpos
);
23020 int start
= MATRIX_ROW_START_CHARPOS (r
);
23021 int pos
= string_buffer_position (w
, object
, start
);
23024 help
= Fget_char_property (make_number (pos
),
23025 Qhelp_echo
, w
->buffer
);
23029 object
= w
->buffer
;
23034 else if (BUFFERP (object
)
23037 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23042 help_echo_string
= help
;
23043 help_echo_window
= window
;
23044 help_echo_object
= object
;
23045 help_echo_pos
= charpos
;
23050 /* Look for a `pointer' property. */
23051 if (NILP (pointer
))
23053 /* Check overlays first. */
23054 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23055 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23057 if (NILP (pointer
))
23059 Lisp_Object object
= glyph
->object
;
23060 int charpos
= glyph
->charpos
;
23062 /* Try text properties. */
23063 if (STRINGP (object
)
23065 && charpos
< SCHARS (object
))
23067 pointer
= Fget_text_property (make_number (charpos
),
23069 if (NILP (pointer
))
23071 /* If the string itself doesn't specify a pointer,
23072 see if the buffer text ``under'' it does. */
23073 struct glyph_row
*r
23074 = MATRIX_ROW (w
->current_matrix
, vpos
);
23075 int start
= MATRIX_ROW_START_CHARPOS (r
);
23076 int pos
= string_buffer_position (w
, object
, start
);
23078 pointer
= Fget_char_property (make_number (pos
),
23079 Qpointer
, w
->buffer
);
23082 else if (BUFFERP (object
)
23085 pointer
= Fget_text_property (make_number (charpos
),
23092 current_buffer
= obuf
;
23097 define_frame_cursor1 (f
, cursor
, pointer
);
23102 Clear any mouse-face on window W. This function is part of the
23103 redisplay interface, and is called from try_window_id and similar
23104 functions to ensure the mouse-highlight is off. */
23107 x_clear_window_mouse_face (w
)
23110 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23111 Lisp_Object window
;
23114 XSETWINDOW (window
, w
);
23115 if (EQ (window
, dpyinfo
->mouse_face_window
))
23116 clear_mouse_face (dpyinfo
);
23122 Just discard the mouse face information for frame F, if any.
23123 This is used when the size of F is changed. */
23126 cancel_mouse_face (f
)
23129 Lisp_Object window
;
23130 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23132 window
= dpyinfo
->mouse_face_window
;
23133 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23135 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23136 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23137 dpyinfo
->mouse_face_window
= Qnil
;
23142 #endif /* HAVE_WINDOW_SYSTEM */
23145 /***********************************************************************
23147 ***********************************************************************/
23149 #ifdef HAVE_WINDOW_SYSTEM
23151 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23152 which intersects rectangle R. R is in window-relative coordinates. */
23155 expose_area (w
, row
, r
, area
)
23157 struct glyph_row
*row
;
23159 enum glyph_row_area area
;
23161 struct glyph
*first
= row
->glyphs
[area
];
23162 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23163 struct glyph
*last
;
23164 int first_x
, start_x
, x
;
23166 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23167 /* If row extends face to end of line write the whole line. */
23168 draw_glyphs (w
, 0, row
, area
,
23169 0, row
->used
[area
],
23170 DRAW_NORMAL_TEXT
, 0);
23173 /* Set START_X to the window-relative start position for drawing glyphs of
23174 AREA. The first glyph of the text area can be partially visible.
23175 The first glyphs of other areas cannot. */
23176 start_x
= window_box_left_offset (w
, area
);
23178 if (area
== TEXT_AREA
)
23181 /* Find the first glyph that must be redrawn. */
23183 && x
+ first
->pixel_width
< r
->x
)
23185 x
+= first
->pixel_width
;
23189 /* Find the last one. */
23193 && x
< r
->x
+ r
->width
)
23195 x
+= last
->pixel_width
;
23201 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23202 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23203 DRAW_NORMAL_TEXT
, 0);
23208 /* Redraw the parts of the glyph row ROW on window W intersecting
23209 rectangle R. R is in window-relative coordinates. Value is
23210 non-zero if mouse-face was overwritten. */
23213 expose_line (w
, row
, r
)
23215 struct glyph_row
*row
;
23218 xassert (row
->enabled_p
);
23220 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23221 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23222 0, row
->used
[TEXT_AREA
],
23223 DRAW_NORMAL_TEXT
, 0);
23226 if (row
->used
[LEFT_MARGIN_AREA
])
23227 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23228 if (row
->used
[TEXT_AREA
])
23229 expose_area (w
, row
, r
, TEXT_AREA
);
23230 if (row
->used
[RIGHT_MARGIN_AREA
])
23231 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23232 draw_row_fringe_bitmaps (w
, row
);
23235 return row
->mouse_face_p
;
23239 /* Redraw those parts of glyphs rows during expose event handling that
23240 overlap other rows. Redrawing of an exposed line writes over parts
23241 of lines overlapping that exposed line; this function fixes that.
23243 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23244 row in W's current matrix that is exposed and overlaps other rows.
23245 LAST_OVERLAPPING_ROW is the last such row. */
23248 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23250 struct glyph_row
*first_overlapping_row
;
23251 struct glyph_row
*last_overlapping_row
;
23253 struct glyph_row
*row
;
23255 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23256 if (row
->overlapping_p
)
23258 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23260 if (row
->used
[LEFT_MARGIN_AREA
])
23261 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23263 if (row
->used
[TEXT_AREA
])
23264 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23266 if (row
->used
[RIGHT_MARGIN_AREA
])
23267 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23272 /* Return non-zero if W's cursor intersects rectangle R. */
23275 phys_cursor_in_rect_p (w
, r
)
23279 XRectangle cr
, result
;
23280 struct glyph
*cursor_glyph
;
23282 cursor_glyph
= get_phys_cursor_glyph (w
);
23285 /* r is relative to W's box, but w->phys_cursor.x is relative
23286 to left edge of W's TEXT area. Adjust it. */
23287 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23288 cr
.y
= w
->phys_cursor
.y
;
23289 cr
.width
= cursor_glyph
->pixel_width
;
23290 cr
.height
= w
->phys_cursor_height
;
23291 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23292 I assume the effect is the same -- and this is portable. */
23293 return x_intersect_rectangles (&cr
, r
, &result
);
23301 Draw a vertical window border to the right of window W if W doesn't
23302 have vertical scroll bars. */
23305 x_draw_vertical_border (w
)
23308 /* We could do better, if we knew what type of scroll-bar the adjacent
23309 windows (on either side) have... But we don't :-(
23310 However, I think this works ok. ++KFS 2003-04-25 */
23312 /* Redraw borders between horizontally adjacent windows. Don't
23313 do it for frames with vertical scroll bars because either the
23314 right scroll bar of a window, or the left scroll bar of its
23315 neighbor will suffice as a border. */
23316 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23319 if (!WINDOW_RIGHTMOST_P (w
)
23320 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23322 int x0
, x1
, y0
, y1
;
23324 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23327 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23330 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23332 else if (!WINDOW_LEFTMOST_P (w
)
23333 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23335 int x0
, x1
, y0
, y1
;
23337 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23340 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23343 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23348 /* Redraw the part of window W intersection rectangle FR. Pixel
23349 coordinates in FR are frame-relative. Call this function with
23350 input blocked. Value is non-zero if the exposure overwrites
23354 expose_window (w
, fr
)
23358 struct frame
*f
= XFRAME (w
->frame
);
23360 int mouse_face_overwritten_p
= 0;
23362 /* If window is not yet fully initialized, do nothing. This can
23363 happen when toolkit scroll bars are used and a window is split.
23364 Reconfiguring the scroll bar will generate an expose for a newly
23366 if (w
->current_matrix
== NULL
)
23369 /* When we're currently updating the window, display and current
23370 matrix usually don't agree. Arrange for a thorough display
23372 if (w
== updated_window
)
23374 SET_FRAME_GARBAGED (f
);
23378 /* Frame-relative pixel rectangle of W. */
23379 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23380 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23381 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23382 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23384 if (x_intersect_rectangles (fr
, &wr
, &r
))
23386 int yb
= window_text_bottom_y (w
);
23387 struct glyph_row
*row
;
23388 int cursor_cleared_p
;
23389 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23391 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23392 r
.x
, r
.y
, r
.width
, r
.height
));
23394 /* Convert to window coordinates. */
23395 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23396 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23398 /* Turn off the cursor. */
23399 if (!w
->pseudo_window_p
23400 && phys_cursor_in_rect_p (w
, &r
))
23402 x_clear_cursor (w
);
23403 cursor_cleared_p
= 1;
23406 cursor_cleared_p
= 0;
23408 /* Update lines intersecting rectangle R. */
23409 first_overlapping_row
= last_overlapping_row
= NULL
;
23410 for (row
= w
->current_matrix
->rows
;
23415 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23417 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23418 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23419 || (r
.y
>= y0
&& r
.y
< y1
)
23420 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23422 /* A header line may be overlapping, but there is no need
23423 to fix overlapping areas for them. KFS 2005-02-12 */
23424 if (row
->overlapping_p
&& !row
->mode_line_p
)
23426 if (first_overlapping_row
== NULL
)
23427 first_overlapping_row
= row
;
23428 last_overlapping_row
= row
;
23431 if (expose_line (w
, row
, &r
))
23432 mouse_face_overwritten_p
= 1;
23439 /* Display the mode line if there is one. */
23440 if (WINDOW_WANTS_MODELINE_P (w
)
23441 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23443 && row
->y
< r
.y
+ r
.height
)
23445 if (expose_line (w
, row
, &r
))
23446 mouse_face_overwritten_p
= 1;
23449 if (!w
->pseudo_window_p
)
23451 /* Fix the display of overlapping rows. */
23452 if (first_overlapping_row
)
23453 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23455 /* Draw border between windows. */
23456 x_draw_vertical_border (w
);
23458 /* Turn the cursor on again. */
23459 if (cursor_cleared_p
)
23460 update_window_cursor (w
, 1);
23464 return mouse_face_overwritten_p
;
23469 /* Redraw (parts) of all windows in the window tree rooted at W that
23470 intersect R. R contains frame pixel coordinates. Value is
23471 non-zero if the exposure overwrites mouse-face. */
23474 expose_window_tree (w
, r
)
23478 struct frame
*f
= XFRAME (w
->frame
);
23479 int mouse_face_overwritten_p
= 0;
23481 while (w
&& !FRAME_GARBAGED_P (f
))
23483 if (!NILP (w
->hchild
))
23484 mouse_face_overwritten_p
23485 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23486 else if (!NILP (w
->vchild
))
23487 mouse_face_overwritten_p
23488 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23490 mouse_face_overwritten_p
|= expose_window (w
, r
);
23492 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23495 return mouse_face_overwritten_p
;
23500 Redisplay an exposed area of frame F. X and Y are the upper-left
23501 corner of the exposed rectangle. W and H are width and height of
23502 the exposed area. All are pixel values. W or H zero means redraw
23503 the entire frame. */
23506 expose_frame (f
, x
, y
, w
, h
)
23511 int mouse_face_overwritten_p
= 0;
23513 TRACE ((stderr
, "expose_frame "));
23515 /* No need to redraw if frame will be redrawn soon. */
23516 if (FRAME_GARBAGED_P (f
))
23518 TRACE ((stderr
, " garbaged\n"));
23522 /* If basic faces haven't been realized yet, there is no point in
23523 trying to redraw anything. This can happen when we get an expose
23524 event while Emacs is starting, e.g. by moving another window. */
23525 if (FRAME_FACE_CACHE (f
) == NULL
23526 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23528 TRACE ((stderr
, " no faces\n"));
23532 if (w
== 0 || h
== 0)
23535 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23536 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23546 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23547 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23549 if (WINDOWP (f
->tool_bar_window
))
23550 mouse_face_overwritten_p
23551 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23553 #ifdef HAVE_X_WINDOWS
23555 #ifndef USE_X_TOOLKIT
23556 if (WINDOWP (f
->menu_bar_window
))
23557 mouse_face_overwritten_p
23558 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23559 #endif /* not USE_X_TOOLKIT */
23563 /* Some window managers support a focus-follows-mouse style with
23564 delayed raising of frames. Imagine a partially obscured frame,
23565 and moving the mouse into partially obscured mouse-face on that
23566 frame. The visible part of the mouse-face will be highlighted,
23567 then the WM raises the obscured frame. With at least one WM, KDE
23568 2.1, Emacs is not getting any event for the raising of the frame
23569 (even tried with SubstructureRedirectMask), only Expose events.
23570 These expose events will draw text normally, i.e. not
23571 highlighted. Which means we must redo the highlight here.
23572 Subsume it under ``we love X''. --gerd 2001-08-15 */
23573 /* Included in Windows version because Windows most likely does not
23574 do the right thing if any third party tool offers
23575 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23576 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23578 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23579 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23581 int x
= dpyinfo
->mouse_face_mouse_x
;
23582 int y
= dpyinfo
->mouse_face_mouse_y
;
23583 clear_mouse_face (dpyinfo
);
23584 note_mouse_highlight (f
, x
, y
);
23591 Determine the intersection of two rectangles R1 and R2. Return
23592 the intersection in *RESULT. Value is non-zero if RESULT is not
23596 x_intersect_rectangles (r1
, r2
, result
)
23597 XRectangle
*r1
, *r2
, *result
;
23599 XRectangle
*left
, *right
;
23600 XRectangle
*upper
, *lower
;
23601 int intersection_p
= 0;
23603 /* Rearrange so that R1 is the left-most rectangle. */
23605 left
= r1
, right
= r2
;
23607 left
= r2
, right
= r1
;
23609 /* X0 of the intersection is right.x0, if this is inside R1,
23610 otherwise there is no intersection. */
23611 if (right
->x
<= left
->x
+ left
->width
)
23613 result
->x
= right
->x
;
23615 /* The right end of the intersection is the minimum of the
23616 the right ends of left and right. */
23617 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23620 /* Same game for Y. */
23622 upper
= r1
, lower
= r2
;
23624 upper
= r2
, lower
= r1
;
23626 /* The upper end of the intersection is lower.y0, if this is inside
23627 of upper. Otherwise, there is no intersection. */
23628 if (lower
->y
<= upper
->y
+ upper
->height
)
23630 result
->y
= lower
->y
;
23632 /* The lower end of the intersection is the minimum of the lower
23633 ends of upper and lower. */
23634 result
->height
= (min (lower
->y
+ lower
->height
,
23635 upper
->y
+ upper
->height
)
23637 intersection_p
= 1;
23641 return intersection_p
;
23644 #endif /* HAVE_WINDOW_SYSTEM */
23647 /***********************************************************************
23649 ***********************************************************************/
23654 Vwith_echo_area_save_vector
= Qnil
;
23655 staticpro (&Vwith_echo_area_save_vector
);
23657 Vmessage_stack
= Qnil
;
23658 staticpro (&Vmessage_stack
);
23660 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23661 staticpro (&Qinhibit_redisplay
);
23663 message_dolog_marker1
= Fmake_marker ();
23664 staticpro (&message_dolog_marker1
);
23665 message_dolog_marker2
= Fmake_marker ();
23666 staticpro (&message_dolog_marker2
);
23667 message_dolog_marker3
= Fmake_marker ();
23668 staticpro (&message_dolog_marker3
);
23671 defsubr (&Sdump_frame_glyph_matrix
);
23672 defsubr (&Sdump_glyph_matrix
);
23673 defsubr (&Sdump_glyph_row
);
23674 defsubr (&Sdump_tool_bar_row
);
23675 defsubr (&Strace_redisplay
);
23676 defsubr (&Strace_to_stderr
);
23678 #ifdef HAVE_WINDOW_SYSTEM
23679 defsubr (&Stool_bar_lines_needed
);
23680 defsubr (&Slookup_image_map
);
23682 defsubr (&Sformat_mode_line
);
23684 staticpro (&Qmenu_bar_update_hook
);
23685 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23687 staticpro (&Qoverriding_terminal_local_map
);
23688 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23690 staticpro (&Qoverriding_local_map
);
23691 Qoverriding_local_map
= intern ("overriding-local-map");
23693 staticpro (&Qwindow_scroll_functions
);
23694 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23696 staticpro (&Qredisplay_end_trigger_functions
);
23697 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23699 staticpro (&Qinhibit_point_motion_hooks
);
23700 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23702 QCdata
= intern (":data");
23703 staticpro (&QCdata
);
23704 Qdisplay
= intern ("display");
23705 staticpro (&Qdisplay
);
23706 Qspace_width
= intern ("space-width");
23707 staticpro (&Qspace_width
);
23708 Qraise
= intern ("raise");
23709 staticpro (&Qraise
);
23710 Qslice
= intern ("slice");
23711 staticpro (&Qslice
);
23712 Qspace
= intern ("space");
23713 staticpro (&Qspace
);
23714 Qmargin
= intern ("margin");
23715 staticpro (&Qmargin
);
23716 Qpointer
= intern ("pointer");
23717 staticpro (&Qpointer
);
23718 Qleft_margin
= intern ("left-margin");
23719 staticpro (&Qleft_margin
);
23720 Qright_margin
= intern ("right-margin");
23721 staticpro (&Qright_margin
);
23722 Qcenter
= intern ("center");
23723 staticpro (&Qcenter
);
23724 Qline_height
= intern ("line-height");
23725 staticpro (&Qline_height
);
23726 QCalign_to
= intern (":align-to");
23727 staticpro (&QCalign_to
);
23728 QCrelative_width
= intern (":relative-width");
23729 staticpro (&QCrelative_width
);
23730 QCrelative_height
= intern (":relative-height");
23731 staticpro (&QCrelative_height
);
23732 QCeval
= intern (":eval");
23733 staticpro (&QCeval
);
23734 QCpropertize
= intern (":propertize");
23735 staticpro (&QCpropertize
);
23736 QCfile
= intern (":file");
23737 staticpro (&QCfile
);
23738 Qfontified
= intern ("fontified");
23739 staticpro (&Qfontified
);
23740 Qfontification_functions
= intern ("fontification-functions");
23741 staticpro (&Qfontification_functions
);
23742 Qtrailing_whitespace
= intern ("trailing-whitespace");
23743 staticpro (&Qtrailing_whitespace
);
23744 Qescape_glyph
= intern ("escape-glyph");
23745 staticpro (&Qescape_glyph
);
23746 Qnobreak_space
= intern ("nobreak-space");
23747 staticpro (&Qnobreak_space
);
23748 Qimage
= intern ("image");
23749 staticpro (&Qimage
);
23750 QCmap
= intern (":map");
23751 staticpro (&QCmap
);
23752 QCpointer
= intern (":pointer");
23753 staticpro (&QCpointer
);
23754 Qrect
= intern ("rect");
23755 staticpro (&Qrect
);
23756 Qcircle
= intern ("circle");
23757 staticpro (&Qcircle
);
23758 Qpoly
= intern ("poly");
23759 staticpro (&Qpoly
);
23760 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23761 staticpro (&Qmessage_truncate_lines
);
23762 Qgrow_only
= intern ("grow-only");
23763 staticpro (&Qgrow_only
);
23764 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23765 staticpro (&Qinhibit_menubar_update
);
23766 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23767 staticpro (&Qinhibit_eval_during_redisplay
);
23768 Qposition
= intern ("position");
23769 staticpro (&Qposition
);
23770 Qbuffer_position
= intern ("buffer-position");
23771 staticpro (&Qbuffer_position
);
23772 Qobject
= intern ("object");
23773 staticpro (&Qobject
);
23774 Qbar
= intern ("bar");
23776 Qhbar
= intern ("hbar");
23777 staticpro (&Qhbar
);
23778 Qbox
= intern ("box");
23780 Qhollow
= intern ("hollow");
23781 staticpro (&Qhollow
);
23782 Qhand
= intern ("hand");
23783 staticpro (&Qhand
);
23784 Qarrow
= intern ("arrow");
23785 staticpro (&Qarrow
);
23786 Qtext
= intern ("text");
23787 staticpro (&Qtext
);
23788 Qrisky_local_variable
= intern ("risky-local-variable");
23789 staticpro (&Qrisky_local_variable
);
23790 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23791 staticpro (&Qinhibit_free_realized_faces
);
23793 list_of_error
= Fcons (Fcons (intern ("error"),
23794 Fcons (intern ("void-variable"), Qnil
)),
23796 staticpro (&list_of_error
);
23798 Qlast_arrow_position
= intern ("last-arrow-position");
23799 staticpro (&Qlast_arrow_position
);
23800 Qlast_arrow_string
= intern ("last-arrow-string");
23801 staticpro (&Qlast_arrow_string
);
23803 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23804 staticpro (&Qoverlay_arrow_string
);
23805 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23806 staticpro (&Qoverlay_arrow_bitmap
);
23808 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23809 staticpro (&echo_buffer
[0]);
23810 staticpro (&echo_buffer
[1]);
23812 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23813 staticpro (&echo_area_buffer
[0]);
23814 staticpro (&echo_area_buffer
[1]);
23816 Vmessages_buffer_name
= build_string ("*Messages*");
23817 staticpro (&Vmessages_buffer_name
);
23819 mode_line_proptrans_alist
= Qnil
;
23820 staticpro (&mode_line_proptrans_alist
);
23821 mode_line_string_list
= Qnil
;
23822 staticpro (&mode_line_string_list
);
23823 mode_line_string_face
= Qnil
;
23824 staticpro (&mode_line_string_face
);
23825 mode_line_string_face_prop
= Qnil
;
23826 staticpro (&mode_line_string_face_prop
);
23827 Vmode_line_unwind_vector
= Qnil
;
23828 staticpro (&Vmode_line_unwind_vector
);
23830 help_echo_string
= Qnil
;
23831 staticpro (&help_echo_string
);
23832 help_echo_object
= Qnil
;
23833 staticpro (&help_echo_object
);
23834 help_echo_window
= Qnil
;
23835 staticpro (&help_echo_window
);
23836 previous_help_echo_string
= Qnil
;
23837 staticpro (&previous_help_echo_string
);
23838 help_echo_pos
= -1;
23840 #ifdef HAVE_WINDOW_SYSTEM
23841 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23842 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23843 For example, if a block cursor is over a tab, it will be drawn as
23844 wide as that tab on the display. */);
23845 x_stretch_cursor_p
= 0;
23848 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23849 doc
: /* *Non-nil means highlight trailing whitespace.
23850 The face used for trailing whitespace is `trailing-whitespace'. */);
23851 Vshow_trailing_whitespace
= Qnil
;
23853 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23854 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23855 A value of t means highlight the character itself (for nobreak space,
23856 use face `nobreak-space').
23857 A value of nil means no highlighting.
23858 Other values mean display the escape glyph followed by an ordinary
23859 space or ordinary hyphen. */);
23860 Vnobreak_char_display
= Qt
;
23862 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23863 doc
: /* *The pointer shape to show in void text areas.
23864 A value of nil means to show the text pointer. Other options are `arrow',
23865 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23866 Vvoid_text_area_pointer
= Qarrow
;
23868 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23869 doc
: /* Non-nil means don't actually do any redisplay.
23870 This is used for internal purposes. */);
23871 Vinhibit_redisplay
= Qnil
;
23873 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23874 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23875 Vglobal_mode_string
= Qnil
;
23877 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23878 doc
: /* Marker for where to display an arrow on top of the buffer text.
23879 This must be the beginning of a line in order to work.
23880 See also `overlay-arrow-string'. */);
23881 Voverlay_arrow_position
= Qnil
;
23883 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23884 doc
: /* String to display as an arrow in non-window frames.
23885 See also `overlay-arrow-position'. */);
23886 Voverlay_arrow_string
= build_string ("=>");
23888 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23889 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23890 The symbols on this list are examined during redisplay to determine
23891 where to display overlay arrows. */);
23892 Voverlay_arrow_variable_list
23893 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23895 DEFVAR_INT ("scroll-step", &scroll_step
,
23896 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23897 If that fails to bring point back on frame, point is centered instead.
23898 If this is zero, point is always centered after it moves off frame.
23899 If you want scrolling to always be a line at a time, you should set
23900 `scroll-conservatively' to a large value rather than set this to 1. */);
23902 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23903 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23904 A value of zero means to scroll the text to center point vertically
23905 in the window. */);
23906 scroll_conservatively
= 0;
23908 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23909 doc
: /* *Number of lines of margin at the top and bottom of a window.
23910 Recenter the window whenever point gets within this many lines
23911 of the top or bottom of the window. */);
23914 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23915 doc
: /* Pixels per inch value for non-window system displays.
23916 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23917 Vdisplay_pixels_per_inch
= make_float (72.0);
23920 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23923 DEFVAR_BOOL ("truncate-partial-width-windows",
23924 &truncate_partial_width_windows
,
23925 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23926 truncate_partial_width_windows
= 1;
23928 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23929 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23930 Any other value means to use the appropriate face, `mode-line',
23931 `header-line', or `menu' respectively. */);
23932 mode_line_inverse_video
= 1;
23934 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23935 doc
: /* *Maximum buffer size for which line number should be displayed.
23936 If the buffer is bigger than this, the line number does not appear
23937 in the mode line. A value of nil means no limit. */);
23938 Vline_number_display_limit
= Qnil
;
23940 DEFVAR_INT ("line-number-display-limit-width",
23941 &line_number_display_limit_width
,
23942 doc
: /* *Maximum line width (in characters) for line number display.
23943 If the average length of the lines near point is bigger than this, then the
23944 line number may be omitted from the mode line. */);
23945 line_number_display_limit_width
= 200;
23947 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23948 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23949 highlight_nonselected_windows
= 0;
23951 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23952 doc
: /* Non-nil if more than one frame is visible on this display.
23953 Minibuffer-only frames don't count, but iconified frames do.
23954 This variable is not guaranteed to be accurate except while processing
23955 `frame-title-format' and `icon-title-format'. */);
23957 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23958 doc
: /* Template for displaying the title bar of visible frames.
23959 \(Assuming the window manager supports this feature.)
23960 This variable has the same structure as `mode-line-format' (which see),
23961 and is used only on frames for which no explicit name has been set
23962 \(see `modify-frame-parameters'). */);
23964 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23965 doc
: /* Template for displaying the title bar of an iconified frame.
23966 \(Assuming the window manager supports this feature.)
23967 This variable has the same structure as `mode-line-format' (which see),
23968 and is used only on frames for which no explicit name has been set
23969 \(see `modify-frame-parameters'). */);
23971 = Vframe_title_format
23972 = Fcons (intern ("multiple-frames"),
23973 Fcons (build_string ("%b"),
23974 Fcons (Fcons (empty_string
,
23975 Fcons (intern ("invocation-name"),
23976 Fcons (build_string ("@"),
23977 Fcons (intern ("system-name"),
23981 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23982 doc
: /* Maximum number of lines to keep in the message log buffer.
23983 If nil, disable message logging. If t, log messages but don't truncate
23984 the buffer when it becomes large. */);
23985 Vmessage_log_max
= make_number (50);
23987 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23988 doc
: /* Functions called before redisplay, if window sizes have changed.
23989 The value should be a list of functions that take one argument.
23990 Just before redisplay, for each frame, if any of its windows have changed
23991 size since the last redisplay, or have been split or deleted,
23992 all the functions in the list are called, with the frame as argument. */);
23993 Vwindow_size_change_functions
= Qnil
;
23995 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23996 doc
: /* List of functions to call before redisplaying a window with scrolling.
23997 Each function is called with two arguments, the window
23998 and its new display-start position. Note that the value of `window-end'
23999 is not valid when these functions are called. */);
24000 Vwindow_scroll_functions
= Qnil
;
24002 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24003 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24004 Each function is called with two arguments, the window and the end trigger value.
24005 See `set-window-redisplay-end-trigger'. */);
24006 Vredisplay_end_trigger_functions
= Qnil
;
24008 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
24009 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
24010 mouse_autoselect_window
= 0;
24012 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
24013 doc
: /* *Non-nil means automatically resize tool-bars.
24014 This increases a tool-bar's height if not all tool-bar items are visible.
24015 It decreases a tool-bar's height when it would display blank lines
24017 auto_resize_tool_bars_p
= 1;
24019 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24020 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24021 auto_raise_tool_bar_buttons_p
= 1;
24023 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24024 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24025 make_cursor_line_fully_visible_p
= 1;
24027 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24028 doc
: /* *Border below tool-bar in pixels.
24029 If an integer, use it as the height of the border.
24030 If it is one of `internal-border-width' or `border-width', use the
24031 value of the corresponding frame parameter.
24032 Otherwise, no border is added below the tool-bar. */);
24033 Vtool_bar_border
= Qinternal_border_width
;
24035 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24036 doc
: /* *Margin around tool-bar buttons in pixels.
24037 If an integer, use that for both horizontal and vertical margins.
24038 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24039 HORZ specifying the horizontal margin, and VERT specifying the
24040 vertical margin. */);
24041 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24043 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24044 doc
: /* *Relief thickness of tool-bar buttons. */);
24045 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24047 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24048 doc
: /* List of functions to call to fontify regions of text.
24049 Each function is called with one argument POS. Functions must
24050 fontify a region starting at POS in the current buffer, and give
24051 fontified regions the property `fontified'. */);
24052 Vfontification_functions
= Qnil
;
24053 Fmake_variable_buffer_local (Qfontification_functions
);
24055 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24056 &unibyte_display_via_language_environment
,
24057 doc
: /* *Non-nil means display unibyte text according to language environment.
24058 Specifically this means that unibyte non-ASCII characters
24059 are displayed by converting them to the equivalent multibyte characters
24060 according to the current language environment. As a result, they are
24061 displayed according to the current fontset. */);
24062 unibyte_display_via_language_environment
= 0;
24064 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24065 doc
: /* *Maximum height for resizing mini-windows.
24066 If a float, it specifies a fraction of the mini-window frame's height.
24067 If an integer, it specifies a number of lines. */);
24068 Vmax_mini_window_height
= make_float (0.25);
24070 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24071 doc
: /* *How to resize mini-windows.
24072 A value of nil means don't automatically resize mini-windows.
24073 A value of t means resize them to fit the text displayed in them.
24074 A value of `grow-only', the default, means let mini-windows grow
24075 only, until their display becomes empty, at which point the windows
24076 go back to their normal size. */);
24077 Vresize_mini_windows
= Qgrow_only
;
24079 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24080 doc
: /* Alist specifying how to blink the cursor off.
24081 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24082 `cursor-type' frame-parameter or variable equals ON-STATE,
24083 comparing using `equal', Emacs uses OFF-STATE to specify
24084 how to blink it off. ON-STATE and OFF-STATE are values for
24085 the `cursor-type' frame parameter.
24087 If a frame's ON-STATE has no entry in this list,
24088 the frame's other specifications determine how to blink the cursor off. */);
24089 Vblink_cursor_alist
= Qnil
;
24091 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24092 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24093 automatic_hscrolling_p
= 1;
24095 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24096 doc
: /* *How many columns away from the window edge point is allowed to get
24097 before automatic hscrolling will horizontally scroll the window. */);
24098 hscroll_margin
= 5;
24100 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24101 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24102 When point is less than `hscroll-margin' columns from the window
24103 edge, automatic hscrolling will scroll the window by the amount of columns
24104 determined by this variable. If its value is a positive integer, scroll that
24105 many columns. If it's a positive floating-point number, it specifies the
24106 fraction of the window's width to scroll. If it's nil or zero, point will be
24107 centered horizontally after the scroll. Any other value, including negative
24108 numbers, are treated as if the value were zero.
24110 Automatic hscrolling always moves point outside the scroll margin, so if
24111 point was more than scroll step columns inside the margin, the window will
24112 scroll more than the value given by the scroll step.
24114 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24115 and `scroll-right' overrides this variable's effect. */);
24116 Vhscroll_step
= make_number (0);
24118 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24119 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24120 Bind this around calls to `message' to let it take effect. */);
24121 message_truncate_lines
= 0;
24123 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24124 doc
: /* Normal hook run to update the menu bar definitions.
24125 Redisplay runs this hook before it redisplays the menu bar.
24126 This is used to update submenus such as Buffers,
24127 whose contents depend on various data. */);
24128 Vmenu_bar_update_hook
= Qnil
;
24130 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24131 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24132 inhibit_menubar_update
= 0;
24134 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24135 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24136 inhibit_eval_during_redisplay
= 0;
24138 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24139 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24140 inhibit_free_realized_faces
= 0;
24143 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24144 doc
: /* Inhibit try_window_id display optimization. */);
24145 inhibit_try_window_id
= 0;
24147 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24148 doc
: /* Inhibit try_window_reusing display optimization. */);
24149 inhibit_try_window_reusing
= 0;
24151 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24152 doc
: /* Inhibit try_cursor_movement display optimization. */);
24153 inhibit_try_cursor_movement
= 0;
24154 #endif /* GLYPH_DEBUG */
24156 DEFVAR_INT ("overline-margin", &overline_margin
,
24157 doc
: /* *Space between overline and text, in pixels.
24158 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24159 margin to the caracter height. */);
24160 overline_margin
= 2;
24164 /* Initialize this module when Emacs starts. */
24169 Lisp_Object root_window
;
24170 struct window
*mini_w
;
24172 current_header_line_height
= current_mode_line_height
= -1;
24174 CHARPOS (this_line_start_pos
) = 0;
24176 mini_w
= XWINDOW (minibuf_window
);
24177 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24179 if (!noninteractive
)
24181 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24184 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24185 set_window_height (root_window
,
24186 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24188 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24189 set_window_height (minibuf_window
, 1, 0);
24191 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24192 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24194 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24195 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24196 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24198 /* The default ellipsis glyphs `...'. */
24199 for (i
= 0; i
< 3; ++i
)
24200 default_invis_vector
[i
] = make_number ('.');
24204 /* Allocate the buffer for frame titles.
24205 Also used for `format-mode-line'. */
24207 mode_line_noprop_buf
= (char *) xmalloc (size
);
24208 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24209 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24210 mode_line_target
= MODE_LINE_DISPLAY
;
24213 help_echo_showing_p
= 0;
24217 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24218 (do not change this comment) */