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 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1276 and header-lines heights. */
1279 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1281 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1284 struct text_pos top
;
1286 struct buffer
*old_buffer
= NULL
;
1291 if (XBUFFER (w
->buffer
) != current_buffer
)
1293 old_buffer
= current_buffer
;
1294 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1297 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1299 /* Compute exact mode line heights, if requested. */
1300 if (exact_mode_line_heights_p
)
1302 if (WINDOW_WANTS_MODELINE_P (w
))
1303 current_mode_line_height
1304 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1305 current_buffer
->mode_line_format
);
1307 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1308 current_header_line_height
1309 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1310 current_buffer
->header_line_format
);
1313 start_display (&it
, w
, top
);
1314 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1315 MOVE_TO_POS
| MOVE_TO_Y
);
1317 /* Note that we may overshoot because of invisible text. */
1318 if (IT_CHARPOS (it
) >= charpos
)
1320 int top_x
= it
.current_x
;
1321 int top_y
= it
.current_y
;
1322 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1323 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1325 if (top_y
< window_top_y
)
1326 visible_p
= bottom_y
> window_top_y
;
1327 else if (top_y
< it
.last_visible_y
)
1332 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1333 *rtop
= max (0, window_top_y
- top_y
);
1334 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1342 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1343 move_it_by_lines (&it
, 1, 0);
1344 if (charpos
< IT_CHARPOS (it
))
1347 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1349 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1350 *rtop
= max (0, -it2
.current_y
);
1351 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1352 - it
.last_visible_y
));
1357 set_buffer_internal_1 (old_buffer
);
1359 current_header_line_height
= current_mode_line_height
= -1;
1361 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1362 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1368 /* Return the next character from STR which is MAXLEN bytes long.
1369 Return in *LEN the length of the character. This is like
1370 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1371 we find one, we return a `?', but with the length of the invalid
1375 string_char_and_length (str
, maxlen
, len
)
1376 const unsigned char *str
;
1381 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1382 if (!CHAR_VALID_P (c
, 1))
1383 /* We may not change the length here because other places in Emacs
1384 don't use this function, i.e. they silently accept invalid
1393 /* Given a position POS containing a valid character and byte position
1394 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1396 static struct text_pos
1397 string_pos_nchars_ahead (pos
, string
, nchars
)
1398 struct text_pos pos
;
1402 xassert (STRINGP (string
) && nchars
>= 0);
1404 if (STRING_MULTIBYTE (string
))
1406 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1407 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1412 string_char_and_length (p
, rest
, &len
);
1413 p
+= len
, rest
-= len
;
1414 xassert (rest
>= 0);
1416 BYTEPOS (pos
) += len
;
1420 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1426 /* Value is the text position, i.e. character and byte position,
1427 for character position CHARPOS in STRING. */
1429 static INLINE
struct text_pos
1430 string_pos (charpos
, string
)
1434 struct text_pos pos
;
1435 xassert (STRINGP (string
));
1436 xassert (charpos
>= 0);
1437 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1442 /* Value is a text position, i.e. character and byte position, for
1443 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1444 means recognize multibyte characters. */
1446 static struct text_pos
1447 c_string_pos (charpos
, s
, multibyte_p
)
1452 struct text_pos pos
;
1454 xassert (s
!= NULL
);
1455 xassert (charpos
>= 0);
1459 int rest
= strlen (s
), len
;
1461 SET_TEXT_POS (pos
, 0, 0);
1464 string_char_and_length (s
, rest
, &len
);
1465 s
+= len
, rest
-= len
;
1466 xassert (rest
>= 0);
1468 BYTEPOS (pos
) += len
;
1472 SET_TEXT_POS (pos
, charpos
, charpos
);
1478 /* Value is the number of characters in C string S. MULTIBYTE_P
1479 non-zero means recognize multibyte characters. */
1482 number_of_chars (s
, multibyte_p
)
1490 int rest
= strlen (s
), len
;
1491 unsigned char *p
= (unsigned char *) s
;
1493 for (nchars
= 0; rest
> 0; ++nchars
)
1495 string_char_and_length (p
, rest
, &len
);
1496 rest
-= len
, p
+= len
;
1500 nchars
= strlen (s
);
1506 /* Compute byte position NEWPOS->bytepos corresponding to
1507 NEWPOS->charpos. POS is a known position in string STRING.
1508 NEWPOS->charpos must be >= POS.charpos. */
1511 compute_string_pos (newpos
, pos
, string
)
1512 struct text_pos
*newpos
, pos
;
1515 xassert (STRINGP (string
));
1516 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1518 if (STRING_MULTIBYTE (string
))
1519 *newpos
= string_pos_nchars_ahead (pos
, string
,
1520 CHARPOS (*newpos
) - CHARPOS (pos
));
1522 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1526 Return an estimation of the pixel height of mode or top lines on
1527 frame F. FACE_ID specifies what line's height to estimate. */
1530 estimate_mode_line_height (f
, face_id
)
1532 enum face_id face_id
;
1534 #ifdef HAVE_WINDOW_SYSTEM
1535 if (FRAME_WINDOW_P (f
))
1537 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1539 /* This function is called so early when Emacs starts that the face
1540 cache and mode line face are not yet initialized. */
1541 if (FRAME_FACE_CACHE (f
))
1543 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1547 height
= FONT_HEIGHT (face
->font
);
1548 if (face
->box_line_width
> 0)
1549 height
+= 2 * face
->box_line_width
;
1560 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1561 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1562 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1563 not force the value into range. */
1566 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1568 register int pix_x
, pix_y
;
1570 NativeRectangle
*bounds
;
1574 #ifdef HAVE_WINDOW_SYSTEM
1575 if (FRAME_WINDOW_P (f
))
1577 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1578 even for negative values. */
1580 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1582 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1584 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1585 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1588 STORE_NATIVE_RECT (*bounds
,
1589 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1590 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1591 FRAME_COLUMN_WIDTH (f
) - 1,
1592 FRAME_LINE_HEIGHT (f
) - 1);
1598 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1599 pix_x
= FRAME_TOTAL_COLS (f
);
1603 else if (pix_y
> FRAME_LINES (f
))
1604 pix_y
= FRAME_LINES (f
);
1614 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1615 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1616 can't tell the positions because W's display is not up to date,
1620 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1623 int *frame_x
, *frame_y
;
1625 #ifdef HAVE_WINDOW_SYSTEM
1626 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1630 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1631 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1633 if (display_completed
)
1635 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1636 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1637 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1643 hpos
+= glyph
->pixel_width
;
1647 /* If first glyph is partially visible, its first visible position is still 0. */
1659 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1660 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1671 #ifdef HAVE_WINDOW_SYSTEM
1673 /* Find the glyph under window-relative coordinates X/Y in window W.
1674 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1675 strings. Return in *HPOS and *VPOS the row and column number of
1676 the glyph found. Return in *AREA the glyph area containing X.
1677 Value is a pointer to the glyph found or null if X/Y is not on
1678 text, or we can't tell because W's current matrix is not up to
1681 static struct glyph
*
1682 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1685 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1687 struct glyph
*glyph
, *end
;
1688 struct glyph_row
*row
= NULL
;
1691 /* Find row containing Y. Give up if some row is not enabled. */
1692 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1694 row
= MATRIX_ROW (w
->current_matrix
, i
);
1695 if (!row
->enabled_p
)
1697 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1704 /* Give up if Y is not in the window. */
1705 if (i
== w
->current_matrix
->nrows
)
1708 /* Get the glyph area containing X. */
1709 if (w
->pseudo_window_p
)
1716 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1718 *area
= LEFT_MARGIN_AREA
;
1719 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1721 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1724 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1728 *area
= RIGHT_MARGIN_AREA
;
1729 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1733 /* Find glyph containing X. */
1734 glyph
= row
->glyphs
[*area
];
1735 end
= glyph
+ row
->used
[*area
];
1737 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1739 x
-= glyph
->pixel_width
;
1749 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1752 *hpos
= glyph
- row
->glyphs
[*area
];
1758 Convert frame-relative x/y to coordinates relative to window W.
1759 Takes pseudo-windows into account. */
1762 frame_to_window_pixel_xy (w
, x
, y
)
1766 if (w
->pseudo_window_p
)
1768 /* A pseudo-window is always full-width, and starts at the
1769 left edge of the frame, plus a frame border. */
1770 struct frame
*f
= XFRAME (w
->frame
);
1771 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1772 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1776 *x
-= WINDOW_LEFT_EDGE_X (w
);
1777 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1782 Return in RECTS[] at most N clipping rectangles for glyph string S.
1783 Return the number of stored rectangles. */
1786 get_glyph_string_clip_rects (s
, rects
, n
)
1787 struct glyph_string
*s
;
1788 NativeRectangle
*rects
;
1796 if (s
->row
->full_width_p
)
1798 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1799 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1800 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1802 /* Unless displaying a mode or menu bar line, which are always
1803 fully visible, clip to the visible part of the row. */
1804 if (s
->w
->pseudo_window_p
)
1805 r
.height
= s
->row
->visible_height
;
1807 r
.height
= s
->height
;
1811 /* This is a text line that may be partially visible. */
1812 r
.x
= window_box_left (s
->w
, s
->area
);
1813 r
.width
= window_box_width (s
->w
, s
->area
);
1814 r
.height
= s
->row
->visible_height
;
1818 if (r
.x
< s
->clip_head
->x
)
1820 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1821 r
.width
-= s
->clip_head
->x
- r
.x
;
1824 r
.x
= s
->clip_head
->x
;
1827 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1829 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1830 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1835 /* If S draws overlapping rows, it's sufficient to use the top and
1836 bottom of the window for clipping because this glyph string
1837 intentionally draws over other lines. */
1838 if (s
->for_overlaps
)
1840 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1841 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1843 /* Alas, the above simple strategy does not work for the
1844 environments with anti-aliased text: if the same text is
1845 drawn onto the same place multiple times, it gets thicker.
1846 If the overlap we are processing is for the erased cursor, we
1847 take the intersection with the rectagle of the cursor. */
1848 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1850 XRectangle rc
, r_save
= r
;
1852 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1853 rc
.y
= s
->w
->phys_cursor
.y
;
1854 rc
.width
= s
->w
->phys_cursor_width
;
1855 rc
.height
= s
->w
->phys_cursor_height
;
1857 x_intersect_rectangles (&r_save
, &rc
, &r
);
1862 /* Don't use S->y for clipping because it doesn't take partially
1863 visible lines into account. For example, it can be negative for
1864 partially visible lines at the top of a window. */
1865 if (!s
->row
->full_width_p
1866 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1867 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1869 r
.y
= max (0, s
->row
->y
);
1871 /* If drawing a tool-bar window, draw it over the internal border
1872 at the top of the window. */
1873 if (WINDOWP (s
->f
->tool_bar_window
)
1874 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1875 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1878 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1880 /* If drawing the cursor, don't let glyph draw outside its
1881 advertised boundaries. Cleartype does this under some circumstances. */
1882 if (s
->hl
== DRAW_CURSOR
)
1884 struct glyph
*glyph
= s
->first_glyph
;
1889 r
.width
-= s
->x
- r
.x
;
1892 r
.width
= min (r
.width
, glyph
->pixel_width
);
1894 /* If r.y is below window bottom, ensure that we still see a cursor. */
1895 height
= min (glyph
->ascent
+ glyph
->descent
,
1896 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1897 max_y
= window_text_bottom_y (s
->w
) - height
;
1898 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1899 if (s
->ybase
- glyph
->ascent
> max_y
)
1906 /* Don't draw cursor glyph taller than our actual glyph. */
1907 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1908 if (height
< r
.height
)
1910 max_y
= r
.y
+ r
.height
;
1911 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1912 r
.height
= min (max_y
- r
.y
, height
);
1917 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1918 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1920 #ifdef CONVERT_FROM_XRECT
1921 CONVERT_FROM_XRECT (r
, *rects
);
1929 /* If we are processing overlapping and allowed to return
1930 multiple clipping rectangles, we exclude the row of the glyph
1931 string from the clipping rectangle. This is to avoid drawing
1932 the same text on the environment with anti-aliasing. */
1933 #ifdef CONVERT_FROM_XRECT
1936 XRectangle
*rs
= rects
;
1938 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1940 if (s
->for_overlaps
& OVERLAPS_PRED
)
1943 if (r
.y
+ r
.height
> row_y
)
1946 rs
[i
].height
= row_y
- r
.y
;
1952 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1955 if (r
.y
< row_y
+ s
->row
->visible_height
)
1957 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1959 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1960 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1969 #ifdef CONVERT_FROM_XRECT
1970 for (i
= 0; i
< n
; i
++)
1971 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1978 Return in *NR the clipping rectangle for glyph string S. */
1981 get_glyph_string_clip_rect (s
, nr
)
1982 struct glyph_string
*s
;
1983 NativeRectangle
*nr
;
1985 get_glyph_string_clip_rects (s
, nr
, 1);
1990 Return the position and height of the phys cursor in window W.
1991 Set w->phys_cursor_width to width of phys cursor.
1995 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
1997 struct glyph_row
*row
;
1998 struct glyph
*glyph
;
1999 int *xp
, *yp
, *heightp
;
2001 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2002 int x
, y
, wd
, h
, h0
, y0
;
2004 /* Compute the width of the rectangle to draw. If on a stretch
2005 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2006 rectangle as wide as the glyph, but use a canonical character
2008 wd
= glyph
->pixel_width
- 1;
2013 x
= w
->phys_cursor
.x
;
2020 if (glyph
->type
== STRETCH_GLYPH
2021 && !x_stretch_cursor_p
)
2022 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2023 w
->phys_cursor_width
= wd
;
2025 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2027 /* If y is below window bottom, ensure that we still see a cursor. */
2028 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2030 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2031 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2033 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2036 h
= max (h
- (y0
- y
) + 1, h0
);
2041 y0
= window_text_bottom_y (w
) - h0
;
2049 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2050 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2055 * Remember which glyph the mouse is over.
2059 remember_mouse_glyph (f
, gx
, gy
, rect
)
2062 NativeRectangle
*rect
;
2066 struct glyph_row
*r
, *gr
, *end_row
;
2067 enum window_part part
;
2068 enum glyph_row_area area
;
2069 int x
, y
, width
, height
;
2071 /* Try to determine frame pixel position and size of the glyph under
2072 frame pixel coordinates X/Y on frame F. */
2074 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2077 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2078 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2082 w
= XWINDOW (window
);
2083 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2084 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2086 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2087 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2089 if (w
->pseudo_window_p
)
2092 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2098 case ON_LEFT_MARGIN
:
2099 area
= LEFT_MARGIN_AREA
;
2102 case ON_RIGHT_MARGIN
:
2103 area
= RIGHT_MARGIN_AREA
;
2106 case ON_HEADER_LINE
:
2108 gr
= (part
== ON_HEADER_LINE
2109 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2110 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2113 goto text_glyph_row_found
;
2120 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2121 if (r
->y
+ r
->height
> y
)
2127 text_glyph_row_found
:
2130 struct glyph
*g
= gr
->glyphs
[area
];
2131 struct glyph
*end
= g
+ gr
->used
[area
];
2133 height
= gr
->height
;
2134 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2135 if (gx
+ g
->pixel_width
> x
)
2140 if (g
->type
== IMAGE_GLYPH
)
2142 /* Don't remember when mouse is over image, as
2143 image may have hot-spots. */
2144 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2147 width
= g
->pixel_width
;
2151 /* Use nominal char spacing at end of line. */
2153 gx
+= (x
/ width
) * width
;
2156 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2157 gx
+= window_box_left_offset (w
, area
);
2161 /* Use nominal line height at end of window. */
2162 gx
= (x
/ width
) * width
;
2164 gy
+= (y
/ height
) * height
;
2168 case ON_LEFT_FRINGE
:
2169 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2170 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2171 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2172 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2175 case ON_RIGHT_FRINGE
:
2176 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2177 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2178 : window_box_right_offset (w
, TEXT_AREA
));
2179 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2183 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2185 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2186 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2187 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2189 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2193 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2194 if (r
->y
+ r
->height
> y
)
2201 height
= gr
->height
;
2204 /* Use nominal line height at end of window. */
2206 gy
+= (y
/ height
) * height
;
2213 /* If there is no glyph under the mouse, then we divide the screen
2214 into a grid of the smallest glyph in the frame, and use that
2217 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2218 round down even for negative values. */
2224 gx
= (gx
/ width
) * width
;
2225 gy
= (gy
/ height
) * height
;
2230 gx
+= WINDOW_LEFT_EDGE_X (w
);
2231 gy
+= WINDOW_TOP_EDGE_Y (w
);
2234 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2236 /* Visible feedback for debugging. */
2239 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2240 f
->output_data
.x
->normal_gc
,
2241 gx
, gy
, width
, height
);
2247 #endif /* HAVE_WINDOW_SYSTEM */
2250 /***********************************************************************
2251 Lisp form evaluation
2252 ***********************************************************************/
2254 /* Error handler for safe_eval and safe_call. */
2257 safe_eval_handler (arg
)
2260 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2265 /* Evaluate SEXPR and return the result, or nil if something went
2266 wrong. Prevent redisplay during the evaluation. */
2274 if (inhibit_eval_during_redisplay
)
2278 int count
= SPECPDL_INDEX ();
2279 struct gcpro gcpro1
;
2282 specbind (Qinhibit_redisplay
, Qt
);
2283 /* Use Qt to ensure debugger does not run,
2284 so there is no possibility of wanting to redisplay. */
2285 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2288 val
= unbind_to (count
, val
);
2295 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2296 Return the result, or nil if something went wrong. Prevent
2297 redisplay during the evaluation. */
2300 safe_call (nargs
, args
)
2306 if (inhibit_eval_during_redisplay
)
2310 int count
= SPECPDL_INDEX ();
2311 struct gcpro gcpro1
;
2314 gcpro1
.nvars
= nargs
;
2315 specbind (Qinhibit_redisplay
, Qt
);
2316 /* Use Qt to ensure debugger does not run,
2317 so there is no possibility of wanting to redisplay. */
2318 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2321 val
= unbind_to (count
, val
);
2328 /* Call function FN with one argument ARG.
2329 Return the result, or nil if something went wrong. */
2332 safe_call1 (fn
, arg
)
2333 Lisp_Object fn
, arg
;
2335 Lisp_Object args
[2];
2338 return safe_call (2, args
);
2343 /***********************************************************************
2345 ***********************************************************************/
2349 /* Define CHECK_IT to perform sanity checks on iterators.
2350 This is for debugging. It is too slow to do unconditionally. */
2356 if (it
->method
== GET_FROM_STRING
)
2358 xassert (STRINGP (it
->string
));
2359 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2363 xassert (IT_STRING_CHARPOS (*it
) < 0);
2364 if (it
->method
== GET_FROM_BUFFER
)
2366 /* Check that character and byte positions agree. */
2367 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2372 xassert (it
->current
.dpvec_index
>= 0);
2374 xassert (it
->current
.dpvec_index
< 0);
2377 #define CHECK_IT(IT) check_it ((IT))
2381 #define CHECK_IT(IT) (void) 0
2388 /* Check that the window end of window W is what we expect it
2389 to be---the last row in the current matrix displaying text. */
2392 check_window_end (w
)
2395 if (!MINI_WINDOW_P (w
)
2396 && !NILP (w
->window_end_valid
))
2398 struct glyph_row
*row
;
2399 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2400 XFASTINT (w
->window_end_vpos
)),
2402 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2403 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2407 #define CHECK_WINDOW_END(W) check_window_end ((W))
2409 #else /* not GLYPH_DEBUG */
2411 #define CHECK_WINDOW_END(W) (void) 0
2413 #endif /* not GLYPH_DEBUG */
2417 /***********************************************************************
2418 Iterator initialization
2419 ***********************************************************************/
2421 /* Initialize IT for displaying current_buffer in window W, starting
2422 at character position CHARPOS. CHARPOS < 0 means that no buffer
2423 position is specified which is useful when the iterator is assigned
2424 a position later. BYTEPOS is the byte position corresponding to
2425 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2427 If ROW is not null, calls to produce_glyphs with IT as parameter
2428 will produce glyphs in that row.
2430 BASE_FACE_ID is the id of a base face to use. It must be one of
2431 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2432 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2433 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2435 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2436 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2437 will be initialized to use the corresponding mode line glyph row of
2438 the desired matrix of W. */
2441 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2444 int charpos
, bytepos
;
2445 struct glyph_row
*row
;
2446 enum face_id base_face_id
;
2448 int highlight_region_p
;
2450 /* Some precondition checks. */
2451 xassert (w
!= NULL
&& it
!= NULL
);
2452 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2455 /* If face attributes have been changed since the last redisplay,
2456 free realized faces now because they depend on face definitions
2457 that might have changed. Don't free faces while there might be
2458 desired matrices pending which reference these faces. */
2459 if (face_change_count
&& !inhibit_free_realized_faces
)
2461 face_change_count
= 0;
2462 free_all_realized_faces (Qnil
);
2465 /* Use one of the mode line rows of W's desired matrix if
2469 if (base_face_id
== MODE_LINE_FACE_ID
2470 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2471 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2472 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2473 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2477 bzero (it
, sizeof *it
);
2478 it
->current
.overlay_string_index
= -1;
2479 it
->current
.dpvec_index
= -1;
2480 it
->base_face_id
= base_face_id
;
2482 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2484 /* The window in which we iterate over current_buffer: */
2485 XSETWINDOW (it
->window
, w
);
2487 it
->f
= XFRAME (w
->frame
);
2489 /* Extra space between lines (on window systems only). */
2490 if (base_face_id
== DEFAULT_FACE_ID
2491 && FRAME_WINDOW_P (it
->f
))
2493 if (NATNUMP (current_buffer
->extra_line_spacing
))
2494 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2495 else if (FLOATP (current_buffer
->extra_line_spacing
))
2496 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2497 * FRAME_LINE_HEIGHT (it
->f
));
2498 else if (it
->f
->extra_line_spacing
> 0)
2499 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2500 it
->max_extra_line_spacing
= 0;
2503 /* If realized faces have been removed, e.g. because of face
2504 attribute changes of named faces, recompute them. When running
2505 in batch mode, the face cache of Vterminal_frame is null. If
2506 we happen to get called, make a dummy face cache. */
2507 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2508 init_frame_faces (it
->f
);
2509 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2510 recompute_basic_faces (it
->f
);
2512 /* Current value of the `slice', `space-width', and 'height' properties. */
2513 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2514 it
->space_width
= Qnil
;
2515 it
->font_height
= Qnil
;
2516 it
->override_ascent
= -1;
2518 /* Are control characters displayed as `^C'? */
2519 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2521 /* -1 means everything between a CR and the following line end
2522 is invisible. >0 means lines indented more than this value are
2524 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2525 ? XFASTINT (current_buffer
->selective_display
)
2526 : (!NILP (current_buffer
->selective_display
)
2528 it
->selective_display_ellipsis_p
2529 = !NILP (current_buffer
->selective_display_ellipses
);
2531 /* Display table to use. */
2532 it
->dp
= window_display_table (w
);
2534 /* Are multibyte characters enabled in current_buffer? */
2535 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2537 /* Non-zero if we should highlight the region. */
2539 = (!NILP (Vtransient_mark_mode
)
2540 && !NILP (current_buffer
->mark_active
)
2541 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2543 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2544 start and end of a visible region in window IT->w. Set both to
2545 -1 to indicate no region. */
2546 if (highlight_region_p
2547 /* Maybe highlight only in selected window. */
2548 && (/* Either show region everywhere. */
2549 highlight_nonselected_windows
2550 /* Or show region in the selected window. */
2551 || w
== XWINDOW (selected_window
)
2552 /* Or show the region if we are in the mini-buffer and W is
2553 the window the mini-buffer refers to. */
2554 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2555 && WINDOWP (minibuf_selected_window
)
2556 && w
== XWINDOW (minibuf_selected_window
))))
2558 int charpos
= marker_position (current_buffer
->mark
);
2559 it
->region_beg_charpos
= min (PT
, charpos
);
2560 it
->region_end_charpos
= max (PT
, charpos
);
2563 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2565 /* Get the position at which the redisplay_end_trigger hook should
2566 be run, if it is to be run at all. */
2567 if (MARKERP (w
->redisplay_end_trigger
)
2568 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2569 it
->redisplay_end_trigger_charpos
2570 = marker_position (w
->redisplay_end_trigger
);
2571 else if (INTEGERP (w
->redisplay_end_trigger
))
2572 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2574 /* Correct bogus values of tab_width. */
2575 it
->tab_width
= XINT (current_buffer
->tab_width
);
2576 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2579 /* Are lines in the display truncated? */
2580 it
->truncate_lines_p
2581 = (base_face_id
!= DEFAULT_FACE_ID
2582 || XINT (it
->w
->hscroll
)
2583 || (truncate_partial_width_windows
2584 && !WINDOW_FULL_WIDTH_P (it
->w
))
2585 || !NILP (current_buffer
->truncate_lines
));
2587 /* Get dimensions of truncation and continuation glyphs. These are
2588 displayed as fringe bitmaps under X, so we don't need them for such
2590 if (!FRAME_WINDOW_P (it
->f
))
2592 if (it
->truncate_lines_p
)
2594 /* We will need the truncation glyph. */
2595 xassert (it
->glyph_row
== NULL
);
2596 produce_special_glyphs (it
, IT_TRUNCATION
);
2597 it
->truncation_pixel_width
= it
->pixel_width
;
2601 /* We will need the continuation glyph. */
2602 xassert (it
->glyph_row
== NULL
);
2603 produce_special_glyphs (it
, IT_CONTINUATION
);
2604 it
->continuation_pixel_width
= it
->pixel_width
;
2607 /* Reset these values to zero because the produce_special_glyphs
2608 above has changed them. */
2609 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2610 it
->phys_ascent
= it
->phys_descent
= 0;
2613 /* Set this after getting the dimensions of truncation and
2614 continuation glyphs, so that we don't produce glyphs when calling
2615 produce_special_glyphs, above. */
2616 it
->glyph_row
= row
;
2617 it
->area
= TEXT_AREA
;
2619 /* Get the dimensions of the display area. The display area
2620 consists of the visible window area plus a horizontally scrolled
2621 part to the left of the window. All x-values are relative to the
2622 start of this total display area. */
2623 if (base_face_id
!= DEFAULT_FACE_ID
)
2625 /* Mode lines, menu bar in terminal frames. */
2626 it
->first_visible_x
= 0;
2627 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2632 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2633 it
->last_visible_x
= (it
->first_visible_x
2634 + window_box_width (w
, TEXT_AREA
));
2636 /* If we truncate lines, leave room for the truncator glyph(s) at
2637 the right margin. Otherwise, leave room for the continuation
2638 glyph(s). Truncation and continuation glyphs are not inserted
2639 for window-based redisplay. */
2640 if (!FRAME_WINDOW_P (it
->f
))
2642 if (it
->truncate_lines_p
)
2643 it
->last_visible_x
-= it
->truncation_pixel_width
;
2645 it
->last_visible_x
-= it
->continuation_pixel_width
;
2648 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2649 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2652 /* Leave room for a border glyph. */
2653 if (!FRAME_WINDOW_P (it
->f
)
2654 && !WINDOW_RIGHTMOST_P (it
->w
))
2655 it
->last_visible_x
-= 1;
2657 it
->last_visible_y
= window_text_bottom_y (w
);
2659 /* For mode lines and alike, arrange for the first glyph having a
2660 left box line if the face specifies a box. */
2661 if (base_face_id
!= DEFAULT_FACE_ID
)
2665 it
->face_id
= base_face_id
;
2667 /* If we have a boxed mode line, make the first character appear
2668 with a left box line. */
2669 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2670 if (face
->box
!= FACE_NO_BOX
)
2671 it
->start_of_box_run_p
= 1;
2674 /* If a buffer position was specified, set the iterator there,
2675 getting overlays and face properties from that position. */
2676 if (charpos
>= BUF_BEG (current_buffer
))
2678 it
->end_charpos
= ZV
;
2680 IT_CHARPOS (*it
) = charpos
;
2682 /* Compute byte position if not specified. */
2683 if (bytepos
< charpos
)
2684 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2686 IT_BYTEPOS (*it
) = bytepos
;
2688 it
->start
= it
->current
;
2690 /* Compute faces etc. */
2691 reseat (it
, it
->current
.pos
, 1);
2698 /* Initialize IT for the display of window W with window start POS. */
2701 start_display (it
, w
, pos
)
2704 struct text_pos pos
;
2706 struct glyph_row
*row
;
2707 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2709 row
= w
->desired_matrix
->rows
+ first_vpos
;
2710 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2711 it
->first_vpos
= first_vpos
;
2713 /* Don't reseat to previous visible line start if current start
2714 position is in a string or image. */
2715 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2717 int start_at_line_beg_p
;
2718 int first_y
= it
->current_y
;
2720 /* If window start is not at a line start, skip forward to POS to
2721 get the correct continuation lines width. */
2722 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2723 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2724 if (!start_at_line_beg_p
)
2728 reseat_at_previous_visible_line_start (it
);
2729 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2731 new_x
= it
->current_x
+ it
->pixel_width
;
2733 /* If lines are continued, this line may end in the middle
2734 of a multi-glyph character (e.g. a control character
2735 displayed as \003, or in the middle of an overlay
2736 string). In this case move_it_to above will not have
2737 taken us to the start of the continuation line but to the
2738 end of the continued line. */
2739 if (it
->current_x
> 0
2740 && !it
->truncate_lines_p
/* Lines are continued. */
2741 && (/* And glyph doesn't fit on the line. */
2742 new_x
> it
->last_visible_x
2743 /* Or it fits exactly and we're on a window
2745 || (new_x
== it
->last_visible_x
2746 && FRAME_WINDOW_P (it
->f
))))
2748 if (it
->current
.dpvec_index
>= 0
2749 || it
->current
.overlay_string_index
>= 0)
2751 set_iterator_to_next (it
, 1);
2752 move_it_in_display_line_to (it
, -1, -1, 0);
2755 it
->continuation_lines_width
+= it
->current_x
;
2758 /* We're starting a new display line, not affected by the
2759 height of the continued line, so clear the appropriate
2760 fields in the iterator structure. */
2761 it
->max_ascent
= it
->max_descent
= 0;
2762 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2764 it
->current_y
= first_y
;
2766 it
->current_x
= it
->hpos
= 0;
2770 #if 0 /* Don't assert the following because start_display is sometimes
2771 called intentionally with a window start that is not at a
2772 line start. Please leave this code in as a comment. */
2774 /* Window start should be on a line start, now. */
2775 xassert (it
->continuation_lines_width
2776 || IT_CHARPOS (it
) == BEGV
2777 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2782 /* Return 1 if POS is a position in ellipses displayed for invisible
2783 text. W is the window we display, for text property lookup. */
2786 in_ellipses_for_invisible_text_p (pos
, w
)
2787 struct display_pos
*pos
;
2790 Lisp_Object prop
, window
;
2792 int charpos
= CHARPOS (pos
->pos
);
2794 /* If POS specifies a position in a display vector, this might
2795 be for an ellipsis displayed for invisible text. We won't
2796 get the iterator set up for delivering that ellipsis unless
2797 we make sure that it gets aware of the invisible text. */
2798 if (pos
->dpvec_index
>= 0
2799 && pos
->overlay_string_index
< 0
2800 && CHARPOS (pos
->string_pos
) < 0
2802 && (XSETWINDOW (window
, w
),
2803 prop
= Fget_char_property (make_number (charpos
),
2804 Qinvisible
, window
),
2805 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2807 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2809 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2816 /* Initialize IT for stepping through current_buffer in window W,
2817 starting at position POS that includes overlay string and display
2818 vector/ control character translation position information. Value
2819 is zero if there are overlay strings with newlines at POS. */
2822 init_from_display_pos (it
, w
, pos
)
2825 struct display_pos
*pos
;
2827 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2828 int i
, overlay_strings_with_newlines
= 0;
2830 /* If POS specifies a position in a display vector, this might
2831 be for an ellipsis displayed for invisible text. We won't
2832 get the iterator set up for delivering that ellipsis unless
2833 we make sure that it gets aware of the invisible text. */
2834 if (in_ellipses_for_invisible_text_p (pos
, w
))
2840 /* Keep in mind: the call to reseat in init_iterator skips invisible
2841 text, so we might end up at a position different from POS. This
2842 is only a problem when POS is a row start after a newline and an
2843 overlay starts there with an after-string, and the overlay has an
2844 invisible property. Since we don't skip invisible text in
2845 display_line and elsewhere immediately after consuming the
2846 newline before the row start, such a POS will not be in a string,
2847 but the call to init_iterator below will move us to the
2849 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2851 /* This only scans the current chunk -- it should scan all chunks.
2852 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2853 to 16 in 22.1 to make this a lesser problem. */
2854 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2856 const char *s
= SDATA (it
->overlay_strings
[i
]);
2857 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2859 while (s
< e
&& *s
!= '\n')
2864 overlay_strings_with_newlines
= 1;
2869 /* If position is within an overlay string, set up IT to the right
2871 if (pos
->overlay_string_index
>= 0)
2875 /* If the first overlay string happens to have a `display'
2876 property for an image, the iterator will be set up for that
2877 image, and we have to undo that setup first before we can
2878 correct the overlay string index. */
2879 if (it
->method
== GET_FROM_IMAGE
)
2882 /* We already have the first chunk of overlay strings in
2883 IT->overlay_strings. Load more until the one for
2884 pos->overlay_string_index is in IT->overlay_strings. */
2885 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2887 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2888 it
->current
.overlay_string_index
= 0;
2891 load_overlay_strings (it
, 0);
2892 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2896 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2897 relative_index
= (it
->current
.overlay_string_index
2898 % OVERLAY_STRING_CHUNK_SIZE
);
2899 it
->string
= it
->overlay_strings
[relative_index
];
2900 xassert (STRINGP (it
->string
));
2901 it
->current
.string_pos
= pos
->string_pos
;
2902 it
->method
= GET_FROM_STRING
;
2905 #if 0 /* This is bogus because POS not having an overlay string
2906 position does not mean it's after the string. Example: A
2907 line starting with a before-string and initialization of IT
2908 to the previous row's end position. */
2909 else if (it
->current
.overlay_string_index
>= 0)
2911 /* If POS says we're already after an overlay string ending at
2912 POS, make sure to pop the iterator because it will be in
2913 front of that overlay string. When POS is ZV, we've thereby
2914 also ``processed'' overlay strings at ZV. */
2917 xassert (it
->current
.overlay_string_index
== -1);
2918 xassert (it
->method
== GET_FROM_BUFFER
);
2919 if (CHARPOS (pos
->pos
) == ZV
)
2920 it
->overlay_strings_at_end_processed_p
= 1;
2924 if (CHARPOS (pos
->string_pos
) >= 0)
2926 /* Recorded position is not in an overlay string, but in another
2927 string. This can only be a string from a `display' property.
2928 IT should already be filled with that string. */
2929 it
->current
.string_pos
= pos
->string_pos
;
2930 xassert (STRINGP (it
->string
));
2933 /* Restore position in display vector translations, control
2934 character translations or ellipses. */
2935 if (pos
->dpvec_index
>= 0)
2937 if (it
->dpvec
== NULL
)
2938 get_next_display_element (it
);
2939 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2940 it
->current
.dpvec_index
= pos
->dpvec_index
;
2944 return !overlay_strings_with_newlines
;
2948 /* Initialize IT for stepping through current_buffer in window W
2949 starting at ROW->start. */
2952 init_to_row_start (it
, w
, row
)
2955 struct glyph_row
*row
;
2957 init_from_display_pos (it
, w
, &row
->start
);
2958 it
->start
= row
->start
;
2959 it
->continuation_lines_width
= row
->continuation_lines_width
;
2964 /* Initialize IT for stepping through current_buffer in window W
2965 starting in the line following ROW, i.e. starting at ROW->end.
2966 Value is zero if there are overlay strings with newlines at ROW's
2970 init_to_row_end (it
, w
, row
)
2973 struct glyph_row
*row
;
2977 if (init_from_display_pos (it
, w
, &row
->end
))
2979 if (row
->continued_p
)
2980 it
->continuation_lines_width
2981 = row
->continuation_lines_width
+ row
->pixel_width
;
2992 /***********************************************************************
2994 ***********************************************************************/
2996 /* Called when IT reaches IT->stop_charpos. Handle text property and
2997 overlay changes. Set IT->stop_charpos to the next position where
3004 enum prop_handled handled
;
3005 int handle_overlay_change_p
;
3009 it
->current
.dpvec_index
= -1;
3010 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3011 it
->ignore_overlay_strings_at_pos_p
= 0;
3013 /* Use face of preceding text for ellipsis (if invisible) */
3014 if (it
->selective_display_ellipsis_p
)
3015 it
->saved_face_id
= it
->face_id
;
3019 handled
= HANDLED_NORMALLY
;
3021 /* Call text property handlers. */
3022 for (p
= it_props
; p
->handler
; ++p
)
3024 handled
= p
->handler (it
);
3026 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3028 else if (handled
== HANDLED_RETURN
)
3030 /* We still want to show before and after strings from
3031 overlays even if the actual buffer text is replaced. */
3032 if (!handle_overlay_change_p
|| it
->sp
> 1)
3034 if (!get_overlay_strings_1 (it
, 0, 0))
3036 it
->ignore_overlay_strings_at_pos_p
= 1;
3037 it
->string_from_display_prop_p
= 0;
3038 handle_overlay_change_p
= 0;
3039 handled
= HANDLED_RECOMPUTE_PROPS
;
3042 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3043 handle_overlay_change_p
= 0;
3046 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3048 /* Don't check for overlay strings below when set to deliver
3049 characters from a display vector. */
3050 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3051 handle_overlay_change_p
= 0;
3053 /* Handle overlay changes. */
3054 if (handle_overlay_change_p
)
3055 handled
= handle_overlay_change (it
);
3057 /* Determine where to stop next. */
3058 if (handled
== HANDLED_NORMALLY
)
3059 compute_stop_pos (it
);
3062 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3066 /* Compute IT->stop_charpos from text property and overlay change
3067 information for IT's current position. */
3070 compute_stop_pos (it
)
3073 register INTERVAL iv
, next_iv
;
3074 Lisp_Object object
, limit
, position
;
3076 /* If nowhere else, stop at the end. */
3077 it
->stop_charpos
= it
->end_charpos
;
3079 if (STRINGP (it
->string
))
3081 /* Strings are usually short, so don't limit the search for
3083 object
= it
->string
;
3085 position
= make_number (IT_STRING_CHARPOS (*it
));
3091 /* If next overlay change is in front of the current stop pos
3092 (which is IT->end_charpos), stop there. Note: value of
3093 next_overlay_change is point-max if no overlay change
3095 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3096 if (charpos
< it
->stop_charpos
)
3097 it
->stop_charpos
= charpos
;
3099 /* If showing the region, we have to stop at the region
3100 start or end because the face might change there. */
3101 if (it
->region_beg_charpos
> 0)
3103 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3104 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3105 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3106 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3109 /* Set up variables for computing the stop position from text
3110 property changes. */
3111 XSETBUFFER (object
, current_buffer
);
3112 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3113 position
= make_number (IT_CHARPOS (*it
));
3117 /* Get the interval containing IT's position. Value is a null
3118 interval if there isn't such an interval. */
3119 iv
= validate_interval_range (object
, &position
, &position
, 0);
3120 if (!NULL_INTERVAL_P (iv
))
3122 Lisp_Object values_here
[LAST_PROP_IDX
];
3125 /* Get properties here. */
3126 for (p
= it_props
; p
->handler
; ++p
)
3127 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3129 /* Look for an interval following iv that has different
3131 for (next_iv
= next_interval (iv
);
3132 (!NULL_INTERVAL_P (next_iv
)
3134 || XFASTINT (limit
) > next_iv
->position
));
3135 next_iv
= next_interval (next_iv
))
3137 for (p
= it_props
; p
->handler
; ++p
)
3139 Lisp_Object new_value
;
3141 new_value
= textget (next_iv
->plist
, *p
->name
);
3142 if (!EQ (values_here
[p
->idx
], new_value
))
3150 if (!NULL_INTERVAL_P (next_iv
))
3152 if (INTEGERP (limit
)
3153 && next_iv
->position
>= XFASTINT (limit
))
3154 /* No text property change up to limit. */
3155 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3157 /* Text properties change in next_iv. */
3158 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3162 xassert (STRINGP (it
->string
)
3163 || (it
->stop_charpos
>= BEGV
3164 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3168 /* Return the position of the next overlay change after POS in
3169 current_buffer. Value is point-max if no overlay change
3170 follows. This is like `next-overlay-change' but doesn't use
3174 next_overlay_change (pos
)
3179 Lisp_Object
*overlays
;
3182 /* Get all overlays at the given position. */
3183 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3185 /* If any of these overlays ends before endpos,
3186 use its ending point instead. */
3187 for (i
= 0; i
< noverlays
; ++i
)
3192 oend
= OVERLAY_END (overlays
[i
]);
3193 oendpos
= OVERLAY_POSITION (oend
);
3194 endpos
= min (endpos
, oendpos
);
3202 /***********************************************************************
3204 ***********************************************************************/
3206 /* Handle changes in the `fontified' property of the current buffer by
3207 calling hook functions from Qfontification_functions to fontify
3210 static enum prop_handled
3211 handle_fontified_prop (it
)
3214 Lisp_Object prop
, pos
;
3215 enum prop_handled handled
= HANDLED_NORMALLY
;
3217 if (!NILP (Vmemory_full
))
3220 /* Get the value of the `fontified' property at IT's current buffer
3221 position. (The `fontified' property doesn't have a special
3222 meaning in strings.) If the value is nil, call functions from
3223 Qfontification_functions. */
3224 if (!STRINGP (it
->string
)
3226 && !NILP (Vfontification_functions
)
3227 && !NILP (Vrun_hooks
)
3228 && (pos
= make_number (IT_CHARPOS (*it
)),
3229 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3232 int count
= SPECPDL_INDEX ();
3235 val
= Vfontification_functions
;
3236 specbind (Qfontification_functions
, Qnil
);
3238 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3239 safe_call1 (val
, pos
);
3242 Lisp_Object globals
, fn
;
3243 struct gcpro gcpro1
, gcpro2
;
3246 GCPRO2 (val
, globals
);
3248 for (; CONSP (val
); val
= XCDR (val
))
3254 /* A value of t indicates this hook has a local
3255 binding; it means to run the global binding too.
3256 In a global value, t should not occur. If it
3257 does, we must ignore it to avoid an endless
3259 for (globals
= Fdefault_value (Qfontification_functions
);
3261 globals
= XCDR (globals
))
3263 fn
= XCAR (globals
);
3265 safe_call1 (fn
, pos
);
3269 safe_call1 (fn
, pos
);
3275 unbind_to (count
, Qnil
);
3277 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3278 something. This avoids an endless loop if they failed to
3279 fontify the text for which reason ever. */
3280 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3281 handled
= HANDLED_RECOMPUTE_PROPS
;
3289 /***********************************************************************
3291 ***********************************************************************/
3293 /* Set up iterator IT from face properties at its current position.
3294 Called from handle_stop. */
3296 static enum prop_handled
3297 handle_face_prop (it
)
3300 int new_face_id
, next_stop
;
3302 if (!STRINGP (it
->string
))
3305 = face_at_buffer_position (it
->w
,
3307 it
->region_beg_charpos
,
3308 it
->region_end_charpos
,
3311 + TEXT_PROP_DISTANCE_LIMIT
),
3314 /* Is this a start of a run of characters with box face?
3315 Caveat: this can be called for a freshly initialized
3316 iterator; face_id is -1 in this case. We know that the new
3317 face will not change until limit, i.e. if the new face has a
3318 box, all characters up to limit will have one. But, as
3319 usual, we don't know whether limit is really the end. */
3320 if (new_face_id
!= it
->face_id
)
3322 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3324 /* If new face has a box but old face has not, this is
3325 the start of a run of characters with box, i.e. it has
3326 a shadow on the left side. The value of face_id of the
3327 iterator will be -1 if this is the initial call that gets
3328 the face. In this case, we have to look in front of IT's
3329 position and see whether there is a face != new_face_id. */
3330 it
->start_of_box_run_p
3331 = (new_face
->box
!= FACE_NO_BOX
3332 && (it
->face_id
>= 0
3333 || IT_CHARPOS (*it
) == BEG
3334 || new_face_id
!= face_before_it_pos (it
)));
3335 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3340 int base_face_id
, bufpos
;
3342 if (it
->current
.overlay_string_index
>= 0)
3343 bufpos
= IT_CHARPOS (*it
);
3347 /* For strings from a buffer, i.e. overlay strings or strings
3348 from a `display' property, use the face at IT's current
3349 buffer position as the base face to merge with, so that
3350 overlay strings appear in the same face as surrounding
3351 text, unless they specify their own faces. */
3352 base_face_id
= underlying_face_id (it
);
3354 new_face_id
= face_at_string_position (it
->w
,
3356 IT_STRING_CHARPOS (*it
),
3358 it
->region_beg_charpos
,
3359 it
->region_end_charpos
,
3363 #if 0 /* This shouldn't be neccessary. Let's check it. */
3364 /* If IT is used to display a mode line we would really like to
3365 use the mode line face instead of the frame's default face. */
3366 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3367 && new_face_id
== DEFAULT_FACE_ID
)
3368 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3371 /* Is this a start of a run of characters with box? Caveat:
3372 this can be called for a freshly allocated iterator; face_id
3373 is -1 is this case. We know that the new face will not
3374 change until the next check pos, i.e. if the new face has a
3375 box, all characters up to that position will have a
3376 box. But, as usual, we don't know whether that position
3377 is really the end. */
3378 if (new_face_id
!= it
->face_id
)
3380 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3381 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3383 /* If new face has a box but old face hasn't, this is the
3384 start of a run of characters with box, i.e. it has a
3385 shadow on the left side. */
3386 it
->start_of_box_run_p
3387 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3388 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3392 it
->face_id
= new_face_id
;
3393 return HANDLED_NORMALLY
;
3397 /* Return the ID of the face ``underlying'' IT's current position,
3398 which is in a string. If the iterator is associated with a
3399 buffer, return the face at IT's current buffer position.
3400 Otherwise, use the iterator's base_face_id. */
3403 underlying_face_id (it
)
3406 int face_id
= it
->base_face_id
, i
;
3408 xassert (STRINGP (it
->string
));
3410 for (i
= it
->sp
- 1; i
>= 0; --i
)
3411 if (NILP (it
->stack
[i
].string
))
3412 face_id
= it
->stack
[i
].face_id
;
3418 /* Compute the face one character before or after the current position
3419 of IT. BEFORE_P non-zero means get the face in front of IT's
3420 position. Value is the id of the face. */
3423 face_before_or_after_it_pos (it
, before_p
)
3428 int next_check_charpos
;
3429 struct text_pos pos
;
3431 xassert (it
->s
== NULL
);
3433 if (STRINGP (it
->string
))
3435 int bufpos
, base_face_id
;
3437 /* No face change past the end of the string (for the case
3438 we are padding with spaces). No face change before the
3440 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3441 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3444 /* Set pos to the position before or after IT's current position. */
3446 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3448 /* For composition, we must check the character after the
3450 pos
= (it
->what
== IT_COMPOSITION
3451 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3452 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3454 if (it
->current
.overlay_string_index
>= 0)
3455 bufpos
= IT_CHARPOS (*it
);
3459 base_face_id
= underlying_face_id (it
);
3461 /* Get the face for ASCII, or unibyte. */
3462 face_id
= face_at_string_position (it
->w
,
3466 it
->region_beg_charpos
,
3467 it
->region_end_charpos
,
3468 &next_check_charpos
,
3471 /* Correct the face for charsets different from ASCII. Do it
3472 for the multibyte case only. The face returned above is
3473 suitable for unibyte text if IT->string is unibyte. */
3474 if (STRING_MULTIBYTE (it
->string
))
3476 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3477 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3479 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3481 c
= string_char_and_length (p
, rest
, &len
);
3482 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3487 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3488 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3491 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3492 pos
= it
->current
.pos
;
3495 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3498 if (it
->what
== IT_COMPOSITION
)
3499 /* For composition, we must check the position after the
3501 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3503 INC_TEXT_POS (pos
, it
->multibyte_p
);
3506 /* Determine face for CHARSET_ASCII, or unibyte. */
3507 face_id
= face_at_buffer_position (it
->w
,
3509 it
->region_beg_charpos
,
3510 it
->region_end_charpos
,
3511 &next_check_charpos
,
3514 /* Correct the face for charsets different from ASCII. Do it
3515 for the multibyte case only. The face returned above is
3516 suitable for unibyte text if current_buffer is unibyte. */
3517 if (it
->multibyte_p
)
3519 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3520 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3521 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3530 /***********************************************************************
3532 ***********************************************************************/
3534 /* Set up iterator IT from invisible properties at its current
3535 position. Called from handle_stop. */
3537 static enum prop_handled
3538 handle_invisible_prop (it
)
3541 enum prop_handled handled
= HANDLED_NORMALLY
;
3543 if (STRINGP (it
->string
))
3545 extern Lisp_Object Qinvisible
;
3546 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3548 /* Get the value of the invisible text property at the
3549 current position. Value will be nil if there is no such
3551 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3552 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3555 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3557 handled
= HANDLED_RECOMPUTE_PROPS
;
3559 /* Get the position at which the next change of the
3560 invisible text property can be found in IT->string.
3561 Value will be nil if the property value is the same for
3562 all the rest of IT->string. */
3563 XSETINT (limit
, SCHARS (it
->string
));
3564 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3567 /* Text at current position is invisible. The next
3568 change in the property is at position end_charpos.
3569 Move IT's current position to that position. */
3570 if (INTEGERP (end_charpos
)
3571 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3573 struct text_pos old
;
3574 old
= it
->current
.string_pos
;
3575 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3576 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3580 /* The rest of the string is invisible. If this is an
3581 overlay string, proceed with the next overlay string
3582 or whatever comes and return a character from there. */
3583 if (it
->current
.overlay_string_index
>= 0)
3585 next_overlay_string (it
);
3586 /* Don't check for overlay strings when we just
3587 finished processing them. */
3588 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3592 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3593 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3600 int invis_p
, newpos
, next_stop
, start_charpos
;
3601 Lisp_Object pos
, prop
, overlay
;
3603 /* First of all, is there invisible text at this position? */
3604 start_charpos
= IT_CHARPOS (*it
);
3605 pos
= make_number (IT_CHARPOS (*it
));
3606 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3608 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3610 /* If we are on invisible text, skip over it. */
3611 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3613 /* Record whether we have to display an ellipsis for the
3615 int display_ellipsis_p
= invis_p
== 2;
3617 handled
= HANDLED_RECOMPUTE_PROPS
;
3619 /* Loop skipping over invisible text. The loop is left at
3620 ZV or with IT on the first char being visible again. */
3623 /* Try to skip some invisible text. Return value is the
3624 position reached which can be equal to IT's position
3625 if there is nothing invisible here. This skips both
3626 over invisible text properties and overlays with
3627 invisible property. */
3628 newpos
= skip_invisible (IT_CHARPOS (*it
),
3629 &next_stop
, ZV
, it
->window
);
3631 /* If we skipped nothing at all we weren't at invisible
3632 text in the first place. If everything to the end of
3633 the buffer was skipped, end the loop. */
3634 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3638 /* We skipped some characters but not necessarily
3639 all there are. Check if we ended up on visible
3640 text. Fget_char_property returns the property of
3641 the char before the given position, i.e. if we
3642 get invis_p = 0, this means that the char at
3643 newpos is visible. */
3644 pos
= make_number (newpos
);
3645 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3646 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3649 /* If we ended up on invisible text, proceed to
3650 skip starting with next_stop. */
3652 IT_CHARPOS (*it
) = next_stop
;
3654 /* If there are adjacent invisible texts, don't lose the
3655 second one's ellipsis. */
3657 display_ellipsis_p
= 1;
3661 /* The position newpos is now either ZV or on visible text. */
3662 IT_CHARPOS (*it
) = newpos
;
3663 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3665 /* If there are before-strings at the start of invisible
3666 text, and the text is invisible because of a text
3667 property, arrange to show before-strings because 20.x did
3668 it that way. (If the text is invisible because of an
3669 overlay property instead of a text property, this is
3670 already handled in the overlay code.) */
3672 && get_overlay_strings (it
, start_charpos
))
3674 handled
= HANDLED_RECOMPUTE_PROPS
;
3675 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3677 else if (display_ellipsis_p
)
3679 /* Make sure that the glyphs of the ellipsis will get
3680 correct `charpos' values. If we would not update
3681 it->position here, the glyphs would belong to the
3682 last visible character _before_ the invisible
3683 text, which confuses `set_cursor_from_row'.
3685 We use the last invisible position instead of the
3686 first because this way the cursor is always drawn on
3687 the first "." of the ellipsis, whenever PT is inside
3688 the invisible text. Otherwise the cursor would be
3689 placed _after_ the ellipsis when the point is after the
3690 first invisible character. */
3691 if (!STRINGP (it
->object
))
3693 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3694 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3696 setup_for_ellipsis (it
, 0);
3705 /* Make iterator IT return `...' next.
3706 Replaces LEN characters from buffer. */
3709 setup_for_ellipsis (it
, len
)
3713 /* Use the display table definition for `...'. Invalid glyphs
3714 will be handled by the method returning elements from dpvec. */
3715 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3717 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3718 it
->dpvec
= v
->contents
;
3719 it
->dpend
= v
->contents
+ v
->size
;
3723 /* Default `...'. */
3724 it
->dpvec
= default_invis_vector
;
3725 it
->dpend
= default_invis_vector
+ 3;
3728 it
->dpvec_char_len
= len
;
3729 it
->current
.dpvec_index
= 0;
3730 it
->dpvec_face_id
= -1;
3732 /* Remember the current face id in case glyphs specify faces.
3733 IT's face is restored in set_iterator_to_next.
3734 saved_face_id was set to preceding char's face in handle_stop. */
3735 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3736 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3738 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3744 /***********************************************************************
3746 ***********************************************************************/
3748 /* Set up iterator IT from `display' property at its current position.
3749 Called from handle_stop.
3750 We return HANDLED_RETURN if some part of the display property
3751 overrides the display of the buffer text itself.
3752 Otherwise we return HANDLED_NORMALLY. */
3754 static enum prop_handled
3755 handle_display_prop (it
)
3758 Lisp_Object prop
, object
;
3759 struct text_pos
*position
;
3760 /* Nonzero if some property replaces the display of the text itself. */
3761 int display_replaced_p
= 0;
3763 if (STRINGP (it
->string
))
3765 object
= it
->string
;
3766 position
= &it
->current
.string_pos
;
3770 XSETWINDOW (object
, it
->w
);
3771 position
= &it
->current
.pos
;
3774 /* Reset those iterator values set from display property values. */
3775 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3776 it
->space_width
= Qnil
;
3777 it
->font_height
= Qnil
;
3780 /* We don't support recursive `display' properties, i.e. string
3781 values that have a string `display' property, that have a string
3782 `display' property etc. */
3783 if (!it
->string_from_display_prop_p
)
3784 it
->area
= TEXT_AREA
;
3786 prop
= Fget_char_property (make_number (position
->charpos
),
3789 return HANDLED_NORMALLY
;
3791 if (!STRINGP (it
->string
))
3792 object
= it
->w
->buffer
;
3795 /* Simple properties. */
3796 && !EQ (XCAR (prop
), Qimage
)
3797 && !EQ (XCAR (prop
), Qspace
)
3798 && !EQ (XCAR (prop
), Qwhen
)
3799 && !EQ (XCAR (prop
), Qslice
)
3800 && !EQ (XCAR (prop
), Qspace_width
)
3801 && !EQ (XCAR (prop
), Qheight
)
3802 && !EQ (XCAR (prop
), Qraise
)
3803 /* Marginal area specifications. */
3804 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3805 && !EQ (XCAR (prop
), Qleft_fringe
)
3806 && !EQ (XCAR (prop
), Qright_fringe
)
3807 && !NILP (XCAR (prop
)))
3809 for (; CONSP (prop
); prop
= XCDR (prop
))
3811 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3812 position
, display_replaced_p
))
3813 display_replaced_p
= 1;
3816 else if (VECTORP (prop
))
3819 for (i
= 0; i
< ASIZE (prop
); ++i
)
3820 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3821 position
, display_replaced_p
))
3822 display_replaced_p
= 1;
3826 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3827 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3828 return HANDLED_RECOMPUTE_PROPS
;
3830 display_replaced_p
= 1;
3833 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3837 /* Value is the position of the end of the `display' property starting
3838 at START_POS in OBJECT. */
3840 static struct text_pos
3841 display_prop_end (it
, object
, start_pos
)
3844 struct text_pos start_pos
;
3847 struct text_pos end_pos
;
3849 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3850 Qdisplay
, object
, Qnil
);
3851 CHARPOS (end_pos
) = XFASTINT (end
);
3852 if (STRINGP (object
))
3853 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3855 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3861 /* Set up IT from a single `display' specification PROP. OBJECT
3862 is the object in which the `display' property was found. *POSITION
3863 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3864 means that we previously saw a display specification which already
3865 replaced text display with something else, for example an image;
3866 we ignore such properties after the first one has been processed.
3868 If PROP is a `space' or `image' specification, and in some other
3869 cases too, set *POSITION to the position where the `display'
3872 Value is non-zero if something was found which replaces the display
3873 of buffer or string text. Specifically, the value is -1 if that
3874 "something" is "nothing". */
3877 handle_single_display_spec (it
, spec
, object
, position
,
3878 display_replaced_before_p
)
3882 struct text_pos
*position
;
3883 int display_replaced_before_p
;
3886 Lisp_Object location
, value
;
3887 struct text_pos start_pos
, save_pos
;
3890 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3891 If the result is non-nil, use VALUE instead of SPEC. */
3893 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3902 if (!NILP (form
) && !EQ (form
, Qt
))
3904 int count
= SPECPDL_INDEX ();
3905 struct gcpro gcpro1
;
3907 /* Bind `object' to the object having the `display' property, a
3908 buffer or string. Bind `position' to the position in the
3909 object where the property was found, and `buffer-position'
3910 to the current position in the buffer. */
3911 specbind (Qobject
, object
);
3912 specbind (Qposition
, make_number (CHARPOS (*position
)));
3913 specbind (Qbuffer_position
,
3914 make_number (STRINGP (object
)
3915 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3917 form
= safe_eval (form
);
3919 unbind_to (count
, Qnil
);
3925 /* Handle `(height HEIGHT)' specifications. */
3927 && EQ (XCAR (spec
), Qheight
)
3928 && CONSP (XCDR (spec
)))
3930 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3933 it
->font_height
= XCAR (XCDR (spec
));
3934 if (!NILP (it
->font_height
))
3936 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3937 int new_height
= -1;
3939 if (CONSP (it
->font_height
)
3940 && (EQ (XCAR (it
->font_height
), Qplus
)
3941 || EQ (XCAR (it
->font_height
), Qminus
))
3942 && CONSP (XCDR (it
->font_height
))
3943 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3945 /* `(+ N)' or `(- N)' where N is an integer. */
3946 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3947 if (EQ (XCAR (it
->font_height
), Qplus
))
3949 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3951 else if (FUNCTIONP (it
->font_height
))
3953 /* Call function with current height as argument.
3954 Value is the new height. */
3956 height
= safe_call1 (it
->font_height
,
3957 face
->lface
[LFACE_HEIGHT_INDEX
]);
3958 if (NUMBERP (height
))
3959 new_height
= XFLOATINT (height
);
3961 else if (NUMBERP (it
->font_height
))
3963 /* Value is a multiple of the canonical char height. */
3966 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3967 new_height
= (XFLOATINT (it
->font_height
)
3968 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3972 /* Evaluate IT->font_height with `height' bound to the
3973 current specified height to get the new height. */
3974 int count
= SPECPDL_INDEX ();
3976 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3977 value
= safe_eval (it
->font_height
);
3978 unbind_to (count
, Qnil
);
3980 if (NUMBERP (value
))
3981 new_height
= XFLOATINT (value
);
3985 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3991 /* Handle `(space_width WIDTH)'. */
3993 && EQ (XCAR (spec
), Qspace_width
)
3994 && CONSP (XCDR (spec
)))
3996 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3999 value
= XCAR (XCDR (spec
));
4000 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4001 it
->space_width
= value
;
4006 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4008 && EQ (XCAR (spec
), Qslice
))
4012 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4015 if (tem
= XCDR (spec
), CONSP (tem
))
4017 it
->slice
.x
= XCAR (tem
);
4018 if (tem
= XCDR (tem
), CONSP (tem
))
4020 it
->slice
.y
= XCAR (tem
);
4021 if (tem
= XCDR (tem
), CONSP (tem
))
4023 it
->slice
.width
= XCAR (tem
);
4024 if (tem
= XCDR (tem
), CONSP (tem
))
4025 it
->slice
.height
= XCAR (tem
);
4033 /* Handle `(raise FACTOR)'. */
4035 && EQ (XCAR (spec
), Qraise
)
4036 && CONSP (XCDR (spec
)))
4038 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4041 #ifdef HAVE_WINDOW_SYSTEM
4042 value
= XCAR (XCDR (spec
));
4043 if (NUMBERP (value
))
4045 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4046 it
->voffset
= - (XFLOATINT (value
)
4047 * (FONT_HEIGHT (face
->font
)));
4049 #endif /* HAVE_WINDOW_SYSTEM */
4054 /* Don't handle the other kinds of display specifications
4055 inside a string that we got from a `display' property. */
4056 if (it
->string_from_display_prop_p
)
4059 /* Characters having this form of property are not displayed, so
4060 we have to find the end of the property. */
4061 start_pos
= *position
;
4062 *position
= display_prop_end (it
, object
, start_pos
);
4065 /* Stop the scan at that end position--we assume that all
4066 text properties change there. */
4067 it
->stop_charpos
= position
->charpos
;
4069 /* Handle `(left-fringe BITMAP [FACE])'
4070 and `(right-fringe BITMAP [FACE])'. */
4072 && (EQ (XCAR (spec
), Qleft_fringe
)
4073 || EQ (XCAR (spec
), Qright_fringe
))
4074 && CONSP (XCDR (spec
)))
4076 int face_id
= DEFAULT_FACE_ID
;
4079 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4080 /* If we return here, POSITION has been advanced
4081 across the text with this property. */
4084 #ifdef HAVE_WINDOW_SYSTEM
4085 value
= XCAR (XCDR (spec
));
4086 if (!SYMBOLP (value
)
4087 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4088 /* If we return here, POSITION has been advanced
4089 across the text with this property. */
4092 if (CONSP (XCDR (XCDR (spec
))))
4094 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4095 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4096 'A', FRINGE_FACE_ID
, 0);
4101 /* Save current settings of IT so that we can restore them
4102 when we are finished with the glyph property value. */
4104 save_pos
= it
->position
;
4105 it
->position
= *position
;
4107 it
->position
= save_pos
;
4109 it
->area
= TEXT_AREA
;
4110 it
->what
= IT_IMAGE
;
4111 it
->image_id
= -1; /* no image */
4112 it
->position
= start_pos
;
4113 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4114 it
->method
= GET_FROM_IMAGE
;
4115 it
->face_id
= face_id
;
4117 /* Say that we haven't consumed the characters with
4118 `display' property yet. The call to pop_it in
4119 set_iterator_to_next will clean this up. */
4120 *position
= start_pos
;
4122 if (EQ (XCAR (spec
), Qleft_fringe
))
4124 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4125 it
->left_user_fringe_face_id
= face_id
;
4129 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4130 it
->right_user_fringe_face_id
= face_id
;
4132 #endif /* HAVE_WINDOW_SYSTEM */
4136 /* Prepare to handle `((margin left-margin) ...)',
4137 `((margin right-margin) ...)' and `((margin nil) ...)'
4138 prefixes for display specifications. */
4139 location
= Qunbound
;
4140 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4144 value
= XCDR (spec
);
4146 value
= XCAR (value
);
4149 if (EQ (XCAR (tem
), Qmargin
)
4150 && (tem
= XCDR (tem
),
4151 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4153 || EQ (tem
, Qleft_margin
)
4154 || EQ (tem
, Qright_margin
))))
4158 if (EQ (location
, Qunbound
))
4164 /* After this point, VALUE is the property after any
4165 margin prefix has been stripped. It must be a string,
4166 an image specification, or `(space ...)'.
4168 LOCATION specifies where to display: `left-margin',
4169 `right-margin' or nil. */
4171 valid_p
= (STRINGP (value
)
4172 #ifdef HAVE_WINDOW_SYSTEM
4173 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4174 #endif /* not HAVE_WINDOW_SYSTEM */
4175 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4177 if (valid_p
&& !display_replaced_before_p
)
4179 /* Save current settings of IT so that we can restore them
4180 when we are finished with the glyph property value. */
4181 save_pos
= it
->position
;
4182 it
->position
= *position
;
4184 it
->position
= save_pos
;
4186 if (NILP (location
))
4187 it
->area
= TEXT_AREA
;
4188 else if (EQ (location
, Qleft_margin
))
4189 it
->area
= LEFT_MARGIN_AREA
;
4191 it
->area
= RIGHT_MARGIN_AREA
;
4193 if (STRINGP (value
))
4195 if (SCHARS (value
) == 0)
4198 return -1; /* Replaced by "", i.e. nothing. */
4201 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4202 it
->current
.overlay_string_index
= -1;
4203 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4204 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4205 it
->method
= GET_FROM_STRING
;
4206 it
->stop_charpos
= 0;
4207 it
->string_from_display_prop_p
= 1;
4208 /* Say that we haven't consumed the characters with
4209 `display' property yet. The call to pop_it in
4210 set_iterator_to_next will clean this up. */
4211 *position
= start_pos
;
4213 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4215 it
->method
= GET_FROM_STRETCH
;
4217 *position
= it
->position
= start_pos
;
4219 #ifdef HAVE_WINDOW_SYSTEM
4222 it
->what
= IT_IMAGE
;
4223 it
->image_id
= lookup_image (it
->f
, value
);
4224 it
->position
= start_pos
;
4225 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4226 it
->method
= GET_FROM_IMAGE
;
4228 /* Say that we haven't consumed the characters with
4229 `display' property yet. The call to pop_it in
4230 set_iterator_to_next will clean this up. */
4231 *position
= start_pos
;
4233 #endif /* HAVE_WINDOW_SYSTEM */
4238 /* Invalid property or property not supported. Restore
4239 POSITION to what it was before. */
4240 *position
= start_pos
;
4245 /* Check if SPEC is a display specification value whose text should be
4246 treated as intangible. */
4249 single_display_spec_intangible_p (prop
)
4252 /* Skip over `when FORM'. */
4253 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4267 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4268 we don't need to treat text as intangible. */
4269 if (EQ (XCAR (prop
), Qmargin
))
4277 || EQ (XCAR (prop
), Qleft_margin
)
4278 || EQ (XCAR (prop
), Qright_margin
))
4282 return (CONSP (prop
)
4283 && (EQ (XCAR (prop
), Qimage
)
4284 || EQ (XCAR (prop
), Qspace
)));
4288 /* Check if PROP is a display property value whose text should be
4289 treated as intangible. */
4292 display_prop_intangible_p (prop
)
4296 && CONSP (XCAR (prop
))
4297 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4299 /* A list of sub-properties. */
4300 while (CONSP (prop
))
4302 if (single_display_spec_intangible_p (XCAR (prop
)))
4307 else if (VECTORP (prop
))
4309 /* A vector of sub-properties. */
4311 for (i
= 0; i
< ASIZE (prop
); ++i
)
4312 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4316 return single_display_spec_intangible_p (prop
);
4322 /* Return 1 if PROP is a display sub-property value containing STRING. */
4325 single_display_spec_string_p (prop
, string
)
4326 Lisp_Object prop
, string
;
4328 if (EQ (string
, prop
))
4331 /* Skip over `when FORM'. */
4332 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4341 /* Skip over `margin LOCATION'. */
4342 if (EQ (XCAR (prop
), Qmargin
))
4353 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4357 /* Return 1 if STRING appears in the `display' property PROP. */
4360 display_prop_string_p (prop
, string
)
4361 Lisp_Object prop
, string
;
4364 && CONSP (XCAR (prop
))
4365 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4367 /* A list of sub-properties. */
4368 while (CONSP (prop
))
4370 if (single_display_spec_string_p (XCAR (prop
), string
))
4375 else if (VECTORP (prop
))
4377 /* A vector of sub-properties. */
4379 for (i
= 0; i
< ASIZE (prop
); ++i
)
4380 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4384 return single_display_spec_string_p (prop
, string
);
4390 /* Determine from which buffer position in W's buffer STRING comes
4391 from. AROUND_CHARPOS is an approximate position where it could
4392 be from. Value is the buffer position or 0 if it couldn't be
4395 W's buffer must be current.
4397 This function is necessary because we don't record buffer positions
4398 in glyphs generated from strings (to keep struct glyph small).
4399 This function may only use code that doesn't eval because it is
4400 called asynchronously from note_mouse_highlight. */
4403 string_buffer_position (w
, string
, around_charpos
)
4408 Lisp_Object limit
, prop
, pos
;
4409 const int MAX_DISTANCE
= 1000;
4412 pos
= make_number (around_charpos
);
4413 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4414 while (!found
&& !EQ (pos
, limit
))
4416 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4417 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4420 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4425 pos
= make_number (around_charpos
);
4426 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
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
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4438 return found
? XINT (pos
) : 0;
4443 /***********************************************************************
4444 `composition' property
4445 ***********************************************************************/
4447 /* Set up iterator IT from `composition' property at its current
4448 position. Called from handle_stop. */
4450 static enum prop_handled
4451 handle_composition_prop (it
)
4454 Lisp_Object prop
, string
;
4455 int pos
, pos_byte
, end
;
4456 enum prop_handled handled
= HANDLED_NORMALLY
;
4458 if (STRINGP (it
->string
))
4460 pos
= IT_STRING_CHARPOS (*it
);
4461 pos_byte
= IT_STRING_BYTEPOS (*it
);
4462 string
= it
->string
;
4466 pos
= IT_CHARPOS (*it
);
4467 pos_byte
= IT_BYTEPOS (*it
);
4471 /* If there's a valid composition and point is not inside of the
4472 composition (in the case that the composition is from the current
4473 buffer), draw a glyph composed from the composition components. */
4474 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4475 && COMPOSITION_VALID_P (pos
, end
, prop
)
4476 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4478 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4482 struct composition
*cmp
= composition_table
[id
];
4484 if (cmp
->glyph_len
== 0)
4487 if (STRINGP (it
->string
))
4489 IT_STRING_CHARPOS (*it
) = end
;
4490 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4495 IT_CHARPOS (*it
) = end
;
4496 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4498 return HANDLED_RECOMPUTE_PROPS
;
4501 it
->stop_charpos
= end
;
4504 it
->method
= GET_FROM_COMPOSITION
;
4506 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4507 /* For a terminal, draw only the first character of the
4509 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4510 it
->len
= (STRINGP (it
->string
)
4511 ? string_char_to_byte (it
->string
, end
)
4512 : CHAR_TO_BYTE (end
)) - pos_byte
;
4513 handled
= HANDLED_RETURN
;
4522 /***********************************************************************
4524 ***********************************************************************/
4526 /* The following structure is used to record overlay strings for
4527 later sorting in load_overlay_strings. */
4529 struct overlay_entry
4531 Lisp_Object overlay
;
4538 /* Set up iterator IT from overlay strings at its current position.
4539 Called from handle_stop. */
4541 static enum prop_handled
4542 handle_overlay_change (it
)
4545 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4546 return HANDLED_RECOMPUTE_PROPS
;
4548 return HANDLED_NORMALLY
;
4552 /* Set up the next overlay string for delivery by IT, if there is an
4553 overlay string to deliver. Called by set_iterator_to_next when the
4554 end of the current overlay string is reached. If there are more
4555 overlay strings to display, IT->string and
4556 IT->current.overlay_string_index are set appropriately here.
4557 Otherwise IT->string is set to nil. */
4560 next_overlay_string (it
)
4563 ++it
->current
.overlay_string_index
;
4564 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4566 /* No more overlay strings. Restore IT's settings to what
4567 they were before overlay strings were processed, and
4568 continue to deliver from current_buffer. */
4569 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4573 || it
->method
== GET_FROM_COMPOSITION
4574 || (NILP (it
->string
)
4575 && it
->method
== GET_FROM_BUFFER
4576 && it
->stop_charpos
>= BEGV
4577 && it
->stop_charpos
<= it
->end_charpos
));
4578 it
->current
.overlay_string_index
= -1;
4579 it
->n_overlay_strings
= 0;
4581 /* If we're at the end of the buffer, record that we have
4582 processed the overlay strings there already, so that
4583 next_element_from_buffer doesn't try it again. */
4584 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4585 it
->overlay_strings_at_end_processed_p
= 1;
4587 /* If we have to display `...' for invisible text, set
4588 the iterator up for that. */
4589 if (display_ellipsis_p
)
4590 setup_for_ellipsis (it
, 0);
4594 /* There are more overlay strings to process. If
4595 IT->current.overlay_string_index has advanced to a position
4596 where we must load IT->overlay_strings with more strings, do
4598 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4600 if (it
->current
.overlay_string_index
&& i
== 0)
4601 load_overlay_strings (it
, 0);
4603 /* Initialize IT to deliver display elements from the overlay
4605 it
->string
= it
->overlay_strings
[i
];
4606 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4607 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4608 it
->method
= GET_FROM_STRING
;
4609 it
->stop_charpos
= 0;
4616 /* Compare two overlay_entry structures E1 and E2. Used as a
4617 comparison function for qsort in load_overlay_strings. Overlay
4618 strings for the same position are sorted so that
4620 1. All after-strings come in front of before-strings, except
4621 when they come from the same overlay.
4623 2. Within after-strings, strings are sorted so that overlay strings
4624 from overlays with higher priorities come first.
4626 2. Within before-strings, strings are sorted so that overlay
4627 strings from overlays with higher priorities come last.
4629 Value is analogous to strcmp. */
4633 compare_overlay_entries (e1
, e2
)
4636 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4637 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4640 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4642 /* Let after-strings appear in front of before-strings if
4643 they come from different overlays. */
4644 if (EQ (entry1
->overlay
, entry2
->overlay
))
4645 result
= entry1
->after_string_p
? 1 : -1;
4647 result
= entry1
->after_string_p
? -1 : 1;
4649 else if (entry1
->after_string_p
)
4650 /* After-strings sorted in order of decreasing priority. */
4651 result
= entry2
->priority
- entry1
->priority
;
4653 /* Before-strings sorted in order of increasing priority. */
4654 result
= entry1
->priority
- entry2
->priority
;
4660 /* Load the vector IT->overlay_strings with overlay strings from IT's
4661 current buffer position, or from CHARPOS if that is > 0. Set
4662 IT->n_overlays to the total number of overlay strings found.
4664 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4665 a time. On entry into load_overlay_strings,
4666 IT->current.overlay_string_index gives the number of overlay
4667 strings that have already been loaded by previous calls to this
4670 IT->add_overlay_start contains an additional overlay start
4671 position to consider for taking overlay strings from, if non-zero.
4672 This position comes into play when the overlay has an `invisible'
4673 property, and both before and after-strings. When we've skipped to
4674 the end of the overlay, because of its `invisible' property, we
4675 nevertheless want its before-string to appear.
4676 IT->add_overlay_start will contain the overlay start position
4679 Overlay strings are sorted so that after-string strings come in
4680 front of before-string strings. Within before and after-strings,
4681 strings are sorted by overlay priority. See also function
4682 compare_overlay_entries. */
4685 load_overlay_strings (it
, charpos
)
4689 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4690 Lisp_Object overlay
, window
, str
, invisible
;
4691 struct Lisp_Overlay
*ov
;
4694 int n
= 0, i
, j
, invis_p
;
4695 struct overlay_entry
*entries
4696 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4699 charpos
= IT_CHARPOS (*it
);
4701 /* Append the overlay string STRING of overlay OVERLAY to vector
4702 `entries' which has size `size' and currently contains `n'
4703 elements. AFTER_P non-zero means STRING is an after-string of
4705 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4708 Lisp_Object priority; \
4712 int new_size = 2 * size; \
4713 struct overlay_entry *old = entries; \
4715 (struct overlay_entry *) alloca (new_size \
4716 * sizeof *entries); \
4717 bcopy (old, entries, size * sizeof *entries); \
4721 entries[n].string = (STRING); \
4722 entries[n].overlay = (OVERLAY); \
4723 priority = Foverlay_get ((OVERLAY), Qpriority); \
4724 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4725 entries[n].after_string_p = (AFTER_P); \
4730 /* Process overlay before the overlay center. */
4731 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4733 XSETMISC (overlay
, ov
);
4734 xassert (OVERLAYP (overlay
));
4735 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4736 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4741 /* Skip this overlay if it doesn't start or end at IT's current
4743 if (end
!= charpos
&& start
!= charpos
)
4746 /* Skip this overlay if it doesn't apply to IT->w. */
4747 window
= Foverlay_get (overlay
, Qwindow
);
4748 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4751 /* If the text ``under'' the overlay is invisible, both before-
4752 and after-strings from this overlay are visible; start and
4753 end position are indistinguishable. */
4754 invisible
= Foverlay_get (overlay
, Qinvisible
);
4755 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4757 /* If overlay has a non-empty before-string, record it. */
4758 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4759 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4761 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4763 /* If overlay has a non-empty after-string, record it. */
4764 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4765 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4767 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4770 /* Process overlays after the overlay center. */
4771 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4773 XSETMISC (overlay
, ov
);
4774 xassert (OVERLAYP (overlay
));
4775 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4776 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4778 if (start
> charpos
)
4781 /* Skip this overlay if it doesn't start or end at IT's current
4783 if (end
!= charpos
&& start
!= charpos
)
4786 /* Skip this overlay if it doesn't apply to IT->w. */
4787 window
= Foverlay_get (overlay
, Qwindow
);
4788 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4791 /* If the text ``under'' the overlay is invisible, it has a zero
4792 dimension, and both before- and after-strings apply. */
4793 invisible
= Foverlay_get (overlay
, Qinvisible
);
4794 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4796 /* If overlay has a non-empty before-string, record it. */
4797 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4798 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4800 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4802 /* If overlay has a non-empty after-string, record it. */
4803 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4804 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4806 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4809 #undef RECORD_OVERLAY_STRING
4813 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4815 /* Record the total number of strings to process. */
4816 it
->n_overlay_strings
= n
;
4818 /* IT->current.overlay_string_index is the number of overlay strings
4819 that have already been consumed by IT. Copy some of the
4820 remaining overlay strings to IT->overlay_strings. */
4822 j
= it
->current
.overlay_string_index
;
4823 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4824 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4830 /* Get the first chunk of overlay strings at IT's current buffer
4831 position, or at CHARPOS if that is > 0. Value is non-zero if at
4832 least one overlay string was found. */
4835 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4839 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4840 process. This fills IT->overlay_strings with strings, and sets
4841 IT->n_overlay_strings to the total number of strings to process.
4842 IT->pos.overlay_string_index has to be set temporarily to zero
4843 because load_overlay_strings needs this; it must be set to -1
4844 when no overlay strings are found because a zero value would
4845 indicate a position in the first overlay string. */
4846 it
->current
.overlay_string_index
= 0;
4847 load_overlay_strings (it
, charpos
);
4849 /* If we found overlay strings, set up IT to deliver display
4850 elements from the first one. Otherwise set up IT to deliver
4851 from current_buffer. */
4852 if (it
->n_overlay_strings
)
4854 /* Make sure we know settings in current_buffer, so that we can
4855 restore meaningful values when we're done with the overlay
4858 compute_stop_pos (it
);
4859 xassert (it
->face_id
>= 0);
4861 /* Save IT's settings. They are restored after all overlay
4862 strings have been processed. */
4863 xassert (!compute_stop_p
|| it
->sp
== 0);
4866 /* Set up IT to deliver display elements from the first overlay
4868 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4869 it
->string
= it
->overlay_strings
[0];
4870 it
->stop_charpos
= 0;
4871 xassert (STRINGP (it
->string
));
4872 it
->end_charpos
= SCHARS (it
->string
);
4873 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4874 it
->method
= GET_FROM_STRING
;
4878 it
->current
.overlay_string_index
= -1;
4883 get_overlay_strings (it
, charpos
)
4888 it
->method
= GET_FROM_BUFFER
;
4890 (void) get_overlay_strings_1 (it
, charpos
, 1);
4894 /* Value is non-zero if we found at least one overlay string. */
4895 return STRINGP (it
->string
);
4900 /***********************************************************************
4901 Saving and restoring state
4902 ***********************************************************************/
4904 /* Save current settings of IT on IT->stack. Called, for example,
4905 before setting up IT for an overlay string, to be able to restore
4906 IT's settings to what they were after the overlay string has been
4913 struct iterator_stack_entry
*p
;
4915 xassert (it
->sp
< IT_STACK_SIZE
);
4916 p
= it
->stack
+ it
->sp
;
4918 p
->stop_charpos
= it
->stop_charpos
;
4919 xassert (it
->face_id
>= 0);
4920 p
->face_id
= it
->face_id
;
4921 p
->string
= it
->string
;
4922 p
->method
= it
->method
;
4925 case GET_FROM_IMAGE
:
4926 p
->u
.image
.object
= it
->object
;
4927 p
->u
.image
.image_id
= it
->image_id
;
4928 p
->u
.image
.slice
= it
->slice
;
4930 case GET_FROM_COMPOSITION
:
4931 p
->u
.comp
.object
= it
->object
;
4932 p
->u
.comp
.c
= it
->c
;
4933 p
->u
.comp
.len
= it
->len
;
4934 p
->u
.comp
.cmp_id
= it
->cmp_id
;
4935 p
->u
.comp
.cmp_len
= it
->cmp_len
;
4937 case GET_FROM_STRETCH
:
4938 p
->u
.stretch
.object
= it
->object
;
4941 p
->position
= it
->position
;
4942 p
->current
= it
->current
;
4943 p
->end_charpos
= it
->end_charpos
;
4944 p
->string_nchars
= it
->string_nchars
;
4946 p
->multibyte_p
= it
->multibyte_p
;
4947 p
->space_width
= it
->space_width
;
4948 p
->font_height
= it
->font_height
;
4949 p
->voffset
= it
->voffset
;
4950 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4951 p
->display_ellipsis_p
= 0;
4956 /* Restore IT's settings from IT->stack. Called, for example, when no
4957 more overlay strings must be processed, and we return to delivering
4958 display elements from a buffer, or when the end of a string from a
4959 `display' property is reached and we return to delivering display
4960 elements from an overlay string, or from a buffer. */
4966 struct iterator_stack_entry
*p
;
4968 xassert (it
->sp
> 0);
4970 p
= it
->stack
+ it
->sp
;
4971 it
->stop_charpos
= p
->stop_charpos
;
4972 it
->face_id
= p
->face_id
;
4973 it
->current
= p
->current
;
4974 it
->position
= p
->position
;
4975 it
->string
= p
->string
;
4976 if (NILP (it
->string
))
4977 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4978 it
->method
= p
->method
;
4981 case GET_FROM_IMAGE
:
4982 it
->image_id
= p
->u
.image
.image_id
;
4983 it
->object
= p
->u
.image
.object
;
4984 it
->slice
= p
->u
.image
.slice
;
4986 case GET_FROM_COMPOSITION
:
4987 it
->object
= p
->u
.comp
.object
;
4988 it
->c
= p
->u
.comp
.c
;
4989 it
->len
= p
->u
.comp
.len
;
4990 it
->cmp_id
= p
->u
.comp
.cmp_id
;
4991 it
->cmp_len
= p
->u
.comp
.cmp_len
;
4993 case GET_FROM_STRETCH
:
4994 it
->object
= p
->u
.comp
.object
;
4996 case GET_FROM_BUFFER
:
4997 it
->object
= it
->w
->buffer
;
4999 case GET_FROM_STRING
:
5000 it
->object
= it
->string
;
5003 it
->end_charpos
= p
->end_charpos
;
5004 it
->string_nchars
= p
->string_nchars
;
5006 it
->multibyte_p
= p
->multibyte_p
;
5007 it
->space_width
= p
->space_width
;
5008 it
->font_height
= p
->font_height
;
5009 it
->voffset
= p
->voffset
;
5010 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5015 /***********************************************************************
5017 ***********************************************************************/
5019 /* Set IT's current position to the previous line start. */
5022 back_to_previous_line_start (it
)
5025 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5026 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5030 /* Move IT to the next line start.
5032 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5033 we skipped over part of the text (as opposed to moving the iterator
5034 continuously over the text). Otherwise, don't change the value
5037 Newlines may come from buffer text, overlay strings, or strings
5038 displayed via the `display' property. That's the reason we can't
5039 simply use find_next_newline_no_quit.
5041 Note that this function may not skip over invisible text that is so
5042 because of text properties and immediately follows a newline. If
5043 it would, function reseat_at_next_visible_line_start, when called
5044 from set_iterator_to_next, would effectively make invisible
5045 characters following a newline part of the wrong glyph row, which
5046 leads to wrong cursor motion. */
5049 forward_to_next_line_start (it
, skipped_p
)
5053 int old_selective
, newline_found_p
, n
;
5054 const int MAX_NEWLINE_DISTANCE
= 500;
5056 /* If already on a newline, just consume it to avoid unintended
5057 skipping over invisible text below. */
5058 if (it
->what
== IT_CHARACTER
5060 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5062 set_iterator_to_next (it
, 0);
5067 /* Don't handle selective display in the following. It's (a)
5068 unnecessary because it's done by the caller, and (b) leads to an
5069 infinite recursion because next_element_from_ellipsis indirectly
5070 calls this function. */
5071 old_selective
= it
->selective
;
5074 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5075 from buffer text. */
5076 for (n
= newline_found_p
= 0;
5077 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5078 n
+= STRINGP (it
->string
) ? 0 : 1)
5080 if (!get_next_display_element (it
))
5082 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5083 set_iterator_to_next (it
, 0);
5086 /* If we didn't find a newline near enough, see if we can use a
5088 if (!newline_found_p
)
5090 int start
= IT_CHARPOS (*it
);
5091 int limit
= find_next_newline_no_quit (start
, 1);
5094 xassert (!STRINGP (it
->string
));
5096 /* If there isn't any `display' property in sight, and no
5097 overlays, we can just use the position of the newline in
5099 if (it
->stop_charpos
>= limit
5100 || ((pos
= Fnext_single_property_change (make_number (start
),
5102 Qnil
, make_number (limit
)),
5104 && next_overlay_change (start
) == ZV
))
5106 IT_CHARPOS (*it
) = limit
;
5107 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5108 *skipped_p
= newline_found_p
= 1;
5112 while (get_next_display_element (it
)
5113 && !newline_found_p
)
5115 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5116 set_iterator_to_next (it
, 0);
5121 it
->selective
= old_selective
;
5122 return newline_found_p
;
5126 /* Set IT's current position to the previous visible line start. Skip
5127 invisible text that is so either due to text properties or due to
5128 selective display. Caution: this does not change IT->current_x and
5132 back_to_previous_visible_line_start (it
)
5135 while (IT_CHARPOS (*it
) > BEGV
)
5137 back_to_previous_line_start (it
);
5139 if (IT_CHARPOS (*it
) <= BEGV
)
5142 /* If selective > 0, then lines indented more than that values
5144 if (it
->selective
> 0
5145 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5146 (double) it
->selective
)) /* iftc */
5149 /* Check the newline before point for invisibility. */
5152 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5153 Qinvisible
, it
->window
);
5154 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5158 if (IT_CHARPOS (*it
) <= BEGV
)
5165 Lisp_Object val
, overlay
;
5167 /* If newline is part of a composition, continue from start of composition */
5168 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5169 && beg
< IT_CHARPOS (*it
))
5172 /* If newline is replaced by a display property, find start of overlay
5173 or interval and continue search from that point. */
5175 pos
= --IT_CHARPOS (it2
);
5178 if (handle_display_prop (&it2
) == HANDLED_RETURN
5179 && !NILP (val
= get_char_property_and_overlay
5180 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5181 && (OVERLAYP (overlay
)
5182 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5183 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5186 /* Newline is not replaced by anything -- so we are done. */
5192 IT_CHARPOS (*it
) = beg
;
5193 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5197 it
->continuation_lines_width
= 0;
5199 xassert (IT_CHARPOS (*it
) >= BEGV
);
5200 xassert (IT_CHARPOS (*it
) == BEGV
5201 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5206 /* Reseat iterator IT at the previous visible line start. Skip
5207 invisible text that is so either due to text properties or due to
5208 selective display. At the end, update IT's overlay information,
5209 face information etc. */
5212 reseat_at_previous_visible_line_start (it
)
5215 back_to_previous_visible_line_start (it
);
5216 reseat (it
, it
->current
.pos
, 1);
5221 /* Reseat iterator IT on the next visible line start in the current
5222 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5223 preceding the line start. Skip over invisible text that is so
5224 because of selective display. Compute faces, overlays etc at the
5225 new position. Note that this function does not skip over text that
5226 is invisible because of text properties. */
5229 reseat_at_next_visible_line_start (it
, on_newline_p
)
5233 int newline_found_p
, skipped_p
= 0;
5235 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5237 /* Skip over lines that are invisible because they are indented
5238 more than the value of IT->selective. */
5239 if (it
->selective
> 0)
5240 while (IT_CHARPOS (*it
) < ZV
5241 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5242 (double) it
->selective
)) /* iftc */
5244 xassert (IT_BYTEPOS (*it
) == BEGV
5245 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5246 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5249 /* Position on the newline if that's what's requested. */
5250 if (on_newline_p
&& newline_found_p
)
5252 if (STRINGP (it
->string
))
5254 if (IT_STRING_CHARPOS (*it
) > 0)
5256 --IT_STRING_CHARPOS (*it
);
5257 --IT_STRING_BYTEPOS (*it
);
5260 else if (IT_CHARPOS (*it
) > BEGV
)
5264 reseat (it
, it
->current
.pos
, 0);
5268 reseat (it
, it
->current
.pos
, 0);
5275 /***********************************************************************
5276 Changing an iterator's position
5277 ***********************************************************************/
5279 /* Change IT's current position to POS in current_buffer. If FORCE_P
5280 is non-zero, always check for text properties at the new position.
5281 Otherwise, text properties are only looked up if POS >=
5282 IT->check_charpos of a property. */
5285 reseat (it
, pos
, force_p
)
5287 struct text_pos pos
;
5290 int original_pos
= IT_CHARPOS (*it
);
5292 reseat_1 (it
, pos
, 0);
5294 /* Determine where to check text properties. Avoid doing it
5295 where possible because text property lookup is very expensive. */
5297 || CHARPOS (pos
) > it
->stop_charpos
5298 || CHARPOS (pos
) < original_pos
)
5305 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5306 IT->stop_pos to POS, also. */
5309 reseat_1 (it
, pos
, set_stop_p
)
5311 struct text_pos pos
;
5314 /* Don't call this function when scanning a C string. */
5315 xassert (it
->s
== NULL
);
5317 /* POS must be a reasonable value. */
5318 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5320 it
->current
.pos
= it
->position
= pos
;
5321 it
->end_charpos
= ZV
;
5323 it
->current
.dpvec_index
= -1;
5324 it
->current
.overlay_string_index
= -1;
5325 IT_STRING_CHARPOS (*it
) = -1;
5326 IT_STRING_BYTEPOS (*it
) = -1;
5328 it
->method
= GET_FROM_BUFFER
;
5329 it
->object
= it
->w
->buffer
;
5330 it
->area
= TEXT_AREA
;
5331 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5333 it
->string_from_display_prop_p
= 0;
5334 it
->face_before_selective_p
= 0;
5337 it
->stop_charpos
= CHARPOS (pos
);
5341 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5342 If S is non-null, it is a C string to iterate over. Otherwise,
5343 STRING gives a Lisp string to iterate over.
5345 If PRECISION > 0, don't return more then PRECISION number of
5346 characters from the string.
5348 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5349 characters have been returned. FIELD_WIDTH < 0 means an infinite
5352 MULTIBYTE = 0 means disable processing of multibyte characters,
5353 MULTIBYTE > 0 means enable it,
5354 MULTIBYTE < 0 means use IT->multibyte_p.
5356 IT must be initialized via a prior call to init_iterator before
5357 calling this function. */
5360 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5365 int precision
, field_width
, multibyte
;
5367 /* No region in strings. */
5368 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5370 /* No text property checks performed by default, but see below. */
5371 it
->stop_charpos
= -1;
5373 /* Set iterator position and end position. */
5374 bzero (&it
->current
, sizeof it
->current
);
5375 it
->current
.overlay_string_index
= -1;
5376 it
->current
.dpvec_index
= -1;
5377 xassert (charpos
>= 0);
5379 /* If STRING is specified, use its multibyteness, otherwise use the
5380 setting of MULTIBYTE, if specified. */
5382 it
->multibyte_p
= multibyte
> 0;
5386 xassert (STRINGP (string
));
5387 it
->string
= string
;
5389 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5390 it
->method
= GET_FROM_STRING
;
5391 it
->current
.string_pos
= string_pos (charpos
, string
);
5398 /* Note that we use IT->current.pos, not it->current.string_pos,
5399 for displaying C strings. */
5400 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5401 if (it
->multibyte_p
)
5403 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5404 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5408 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5409 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5412 it
->method
= GET_FROM_C_STRING
;
5415 /* PRECISION > 0 means don't return more than PRECISION characters
5417 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5418 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5420 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5421 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5422 FIELD_WIDTH < 0 means infinite field width. This is useful for
5423 padding with `-' at the end of a mode line. */
5424 if (field_width
< 0)
5425 field_width
= INFINITY
;
5426 if (field_width
> it
->end_charpos
- charpos
)
5427 it
->end_charpos
= charpos
+ field_width
;
5429 /* Use the standard display table for displaying strings. */
5430 if (DISP_TABLE_P (Vstandard_display_table
))
5431 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5433 it
->stop_charpos
= charpos
;
5439 /***********************************************************************
5441 ***********************************************************************/
5443 /* Map enum it_method value to corresponding next_element_from_* function. */
5445 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5447 next_element_from_buffer
,
5448 next_element_from_display_vector
,
5449 next_element_from_composition
,
5450 next_element_from_string
,
5451 next_element_from_c_string
,
5452 next_element_from_image
,
5453 next_element_from_stretch
5457 /* Load IT's display element fields with information about the next
5458 display element from the current position of IT. Value is zero if
5459 end of buffer (or C string) is reached. */
5461 static struct frame
*last_escape_glyph_frame
= NULL
;
5462 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5463 static int last_escape_glyph_merged_face_id
= 0;
5466 get_next_display_element (it
)
5469 /* Non-zero means that we found a display element. Zero means that
5470 we hit the end of what we iterate over. Performance note: the
5471 function pointer `method' used here turns out to be faster than
5472 using a sequence of if-statements. */
5476 success_p
= (*get_next_element
[it
->method
]) (it
);
5478 if (it
->what
== IT_CHARACTER
)
5480 /* Map via display table or translate control characters.
5481 IT->c, IT->len etc. have been set to the next character by
5482 the function call above. If we have a display table, and it
5483 contains an entry for IT->c, translate it. Don't do this if
5484 IT->c itself comes from a display table, otherwise we could
5485 end up in an infinite recursion. (An alternative could be to
5486 count the recursion depth of this function and signal an
5487 error when a certain maximum depth is reached.) Is it worth
5489 if (success_p
&& it
->dpvec
== NULL
)
5494 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5497 struct Lisp_Vector
*v
= XVECTOR (dv
);
5499 /* Return the first character from the display table
5500 entry, if not empty. If empty, don't display the
5501 current character. */
5504 it
->dpvec_char_len
= it
->len
;
5505 it
->dpvec
= v
->contents
;
5506 it
->dpend
= v
->contents
+ v
->size
;
5507 it
->current
.dpvec_index
= 0;
5508 it
->dpvec_face_id
= -1;
5509 it
->saved_face_id
= it
->face_id
;
5510 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5515 set_iterator_to_next (it
, 0);
5520 /* Translate control characters into `\003' or `^C' form.
5521 Control characters coming from a display table entry are
5522 currently not translated because we use IT->dpvec to hold
5523 the translation. This could easily be changed but I
5524 don't believe that it is worth doing.
5526 If it->multibyte_p is nonzero, eight-bit characters and
5527 non-printable multibyte characters are also translated to
5530 If it->multibyte_p is zero, eight-bit characters that
5531 don't have corresponding multibyte char code are also
5532 translated to octal form. */
5533 else if ((it
->c
< ' '
5534 && (it
->area
!= TEXT_AREA
5535 /* In mode line, treat \n like other crl chars. */
5537 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5538 || (it
->c
!= '\n' && it
->c
!= '\t')))
5542 || !CHAR_PRINTABLE_P (it
->c
)
5543 || (!NILP (Vnobreak_char_display
)
5544 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5545 || it
->c
== 0x920 || it
->c
== 0x92d
5546 || it
->c
== 0xe20 || it
->c
== 0xe2d
5547 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5549 && (!unibyte_display_via_language_environment
5550 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5552 /* IT->c is a control character which must be displayed
5553 either as '\003' or as `^C' where the '\\' and '^'
5554 can be defined in the display table. Fill
5555 IT->ctl_chars with glyphs for what we have to
5556 display. Then, set IT->dpvec to these glyphs. */
5559 int face_id
, lface_id
= 0 ;
5562 /* Handle control characters with ^. */
5564 if (it
->c
< 128 && it
->ctl_arrow_p
)
5566 g
= '^'; /* default glyph for Control */
5567 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5569 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5570 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5572 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5573 lface_id
= FAST_GLYPH_FACE (g
);
5577 g
= FAST_GLYPH_CHAR (g
);
5578 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5581 else if (it
->f
== last_escape_glyph_frame
5582 && it
->face_id
== last_escape_glyph_face_id
)
5584 face_id
= last_escape_glyph_merged_face_id
;
5588 /* Merge the escape-glyph face into the current face. */
5589 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5591 last_escape_glyph_frame
= it
->f
;
5592 last_escape_glyph_face_id
= it
->face_id
;
5593 last_escape_glyph_merged_face_id
= face_id
;
5596 XSETINT (it
->ctl_chars
[0], g
);
5598 XSETINT (it
->ctl_chars
[1], g
);
5600 goto display_control
;
5603 /* Handle non-break space in the mode where it only gets
5606 if (EQ (Vnobreak_char_display
, Qt
)
5607 && (it
->c
== 0x8a0 || it
->c
== 0x920
5608 || it
->c
== 0xe20 || it
->c
== 0xf20))
5610 /* Merge the no-break-space face into the current face. */
5611 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5615 XSETINT (it
->ctl_chars
[0], g
);
5617 goto display_control
;
5620 /* Handle sequences that start with the "escape glyph". */
5622 /* the default escape glyph is \. */
5623 escape_glyph
= '\\';
5626 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5627 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5629 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5630 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5634 /* The display table specified a face.
5635 Merge it into face_id and also into escape_glyph. */
5636 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5637 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5640 else if (it
->f
== last_escape_glyph_frame
5641 && it
->face_id
== last_escape_glyph_face_id
)
5643 face_id
= last_escape_glyph_merged_face_id
;
5647 /* Merge the escape-glyph face into the current face. */
5648 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5650 last_escape_glyph_frame
= it
->f
;
5651 last_escape_glyph_face_id
= it
->face_id
;
5652 last_escape_glyph_merged_face_id
= face_id
;
5655 /* Handle soft hyphens in the mode where they only get
5658 if (EQ (Vnobreak_char_display
, Qt
)
5659 && (it
->c
== 0x8ad || it
->c
== 0x92d
5660 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5663 XSETINT (it
->ctl_chars
[0], g
);
5665 goto display_control
;
5668 /* Handle non-break space and soft hyphen
5669 with the escape glyph. */
5671 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5672 || it
->c
== 0x920 || it
->c
== 0x92d
5673 || it
->c
== 0xe20 || it
->c
== 0xe2d
5674 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5676 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5677 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5678 XSETINT (it
->ctl_chars
[1], g
);
5680 goto display_control
;
5684 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5688 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5689 if (SINGLE_BYTE_CHAR_P (it
->c
))
5690 str
[0] = it
->c
, len
= 1;
5693 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5696 /* It's an invalid character, which shouldn't
5697 happen actually, but due to bugs it may
5698 happen. Let's print the char as is, there's
5699 not much meaningful we can do with it. */
5701 str
[1] = it
->c
>> 8;
5702 str
[2] = it
->c
>> 16;
5703 str
[3] = it
->c
>> 24;
5708 for (i
= 0; i
< len
; i
++)
5710 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5711 /* Insert three more glyphs into IT->ctl_chars for
5712 the octal display of the character. */
5713 g
= ((str
[i
] >> 6) & 7) + '0';
5714 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5715 g
= ((str
[i
] >> 3) & 7) + '0';
5716 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5717 g
= (str
[i
] & 7) + '0';
5718 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5724 /* Set up IT->dpvec and return first character from it. */
5725 it
->dpvec_char_len
= it
->len
;
5726 it
->dpvec
= it
->ctl_chars
;
5727 it
->dpend
= it
->dpvec
+ ctl_len
;
5728 it
->current
.dpvec_index
= 0;
5729 it
->dpvec_face_id
= face_id
;
5730 it
->saved_face_id
= it
->face_id
;
5731 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5737 /* Adjust face id for a multibyte character. There are no
5738 multibyte character in unibyte text. */
5741 && FRAME_WINDOW_P (it
->f
))
5743 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5744 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5748 /* Is this character the last one of a run of characters with
5749 box? If yes, set IT->end_of_box_run_p to 1. */
5756 it
->end_of_box_run_p
5757 = ((face_id
= face_after_it_pos (it
),
5758 face_id
!= it
->face_id
)
5759 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5760 face
->box
== FACE_NO_BOX
));
5763 /* Value is 0 if end of buffer or string reached. */
5768 /* Move IT to the next display element.
5770 RESEAT_P non-zero means if called on a newline in buffer text,
5771 skip to the next visible line start.
5773 Functions get_next_display_element and set_iterator_to_next are
5774 separate because I find this arrangement easier to handle than a
5775 get_next_display_element function that also increments IT's
5776 position. The way it is we can first look at an iterator's current
5777 display element, decide whether it fits on a line, and if it does,
5778 increment the iterator position. The other way around we probably
5779 would either need a flag indicating whether the iterator has to be
5780 incremented the next time, or we would have to implement a
5781 decrement position function which would not be easy to write. */
5784 set_iterator_to_next (it
, reseat_p
)
5788 /* Reset flags indicating start and end of a sequence of characters
5789 with box. Reset them at the start of this function because
5790 moving the iterator to a new position might set them. */
5791 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5795 case GET_FROM_BUFFER
:
5796 /* The current display element of IT is a character from
5797 current_buffer. Advance in the buffer, and maybe skip over
5798 invisible lines that are so because of selective display. */
5799 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5800 reseat_at_next_visible_line_start (it
, 0);
5803 xassert (it
->len
!= 0);
5804 IT_BYTEPOS (*it
) += it
->len
;
5805 IT_CHARPOS (*it
) += 1;
5806 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5810 case GET_FROM_COMPOSITION
:
5811 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5812 xassert (it
->sp
> 0);
5814 if (it
->method
== GET_FROM_STRING
)
5816 IT_STRING_BYTEPOS (*it
) += it
->len
;
5817 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5818 goto consider_string_end
;
5820 else if (it
->method
== GET_FROM_BUFFER
)
5822 IT_BYTEPOS (*it
) += it
->len
;
5823 IT_CHARPOS (*it
) += it
->cmp_len
;
5827 case GET_FROM_C_STRING
:
5828 /* Current display element of IT is from a C string. */
5829 IT_BYTEPOS (*it
) += it
->len
;
5830 IT_CHARPOS (*it
) += 1;
5833 case GET_FROM_DISPLAY_VECTOR
:
5834 /* Current display element of IT is from a display table entry.
5835 Advance in the display table definition. Reset it to null if
5836 end reached, and continue with characters from buffers/
5838 ++it
->current
.dpvec_index
;
5840 /* Restore face of the iterator to what they were before the
5841 display vector entry (these entries may contain faces). */
5842 it
->face_id
= it
->saved_face_id
;
5844 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5846 int recheck_faces
= it
->ellipsis_p
;
5849 it
->method
= GET_FROM_C_STRING
;
5850 else if (STRINGP (it
->string
))
5851 it
->method
= GET_FROM_STRING
;
5854 it
->method
= GET_FROM_BUFFER
;
5855 it
->object
= it
->w
->buffer
;
5859 it
->current
.dpvec_index
= -1;
5861 /* Skip over characters which were displayed via IT->dpvec. */
5862 if (it
->dpvec_char_len
< 0)
5863 reseat_at_next_visible_line_start (it
, 1);
5864 else if (it
->dpvec_char_len
> 0)
5866 if (it
->method
== GET_FROM_STRING
5867 && it
->n_overlay_strings
> 0)
5868 it
->ignore_overlay_strings_at_pos_p
= 1;
5869 it
->len
= it
->dpvec_char_len
;
5870 set_iterator_to_next (it
, reseat_p
);
5873 /* Maybe recheck faces after display vector */
5875 it
->stop_charpos
= IT_CHARPOS (*it
);
5879 case GET_FROM_STRING
:
5880 /* Current display element is a character from a Lisp string. */
5881 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5882 IT_STRING_BYTEPOS (*it
) += it
->len
;
5883 IT_STRING_CHARPOS (*it
) += 1;
5885 consider_string_end
:
5887 if (it
->current
.overlay_string_index
>= 0)
5889 /* IT->string is an overlay string. Advance to the
5890 next, if there is one. */
5891 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5892 next_overlay_string (it
);
5896 /* IT->string is not an overlay string. If we reached
5897 its end, and there is something on IT->stack, proceed
5898 with what is on the stack. This can be either another
5899 string, this time an overlay string, or a buffer. */
5900 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5904 if (it
->method
== GET_FROM_STRING
)
5905 goto consider_string_end
;
5910 case GET_FROM_IMAGE
:
5911 case GET_FROM_STRETCH
:
5912 /* The position etc with which we have to proceed are on
5913 the stack. The position may be at the end of a string,
5914 if the `display' property takes up the whole string. */
5915 xassert (it
->sp
> 0);
5917 if (it
->method
== GET_FROM_STRING
)
5918 goto consider_string_end
;
5922 /* There are no other methods defined, so this should be a bug. */
5926 xassert (it
->method
!= GET_FROM_STRING
5927 || (STRINGP (it
->string
)
5928 && IT_STRING_CHARPOS (*it
) >= 0));
5931 /* Load IT's display element fields with information about the next
5932 display element which comes from a display table entry or from the
5933 result of translating a control character to one of the forms `^C'
5936 IT->dpvec holds the glyphs to return as characters.
5937 IT->saved_face_id holds the face id before the display vector--
5938 it is restored into IT->face_idin set_iterator_to_next. */
5941 next_element_from_display_vector (it
)
5945 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5947 it
->face_id
= it
->saved_face_id
;
5949 if (INTEGERP (*it
->dpvec
)
5950 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5954 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5955 it
->c
= FAST_GLYPH_CHAR (g
);
5956 it
->len
= CHAR_BYTES (it
->c
);
5958 /* The entry may contain a face id to use. Such a face id is
5959 the id of a Lisp face, not a realized face. A face id of
5960 zero means no face is specified. */
5961 if (it
->dpvec_face_id
>= 0)
5962 it
->face_id
= it
->dpvec_face_id
;
5965 int lface_id
= FAST_GLYPH_FACE (g
);
5967 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5972 /* Display table entry is invalid. Return a space. */
5973 it
->c
= ' ', it
->len
= 1;
5975 /* Don't change position and object of the iterator here. They are
5976 still the values of the character that had this display table
5977 entry or was translated, and that's what we want. */
5978 it
->what
= IT_CHARACTER
;
5983 /* Load IT with the next display element from Lisp string IT->string.
5984 IT->current.string_pos is the current position within the string.
5985 If IT->current.overlay_string_index >= 0, the Lisp string is an
5989 next_element_from_string (it
)
5992 struct text_pos position
;
5994 xassert (STRINGP (it
->string
));
5995 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5996 position
= it
->current
.string_pos
;
5998 /* Time to check for invisible text? */
5999 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6000 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6004 /* Since a handler may have changed IT->method, we must
6006 return get_next_display_element (it
);
6009 if (it
->current
.overlay_string_index
>= 0)
6011 /* Get the next character from an overlay string. In overlay
6012 strings, There is no field width or padding with spaces to
6014 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6019 else if (STRING_MULTIBYTE (it
->string
))
6021 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6022 const unsigned char *s
= (SDATA (it
->string
)
6023 + IT_STRING_BYTEPOS (*it
));
6024 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6028 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6034 /* Get the next character from a Lisp string that is not an
6035 overlay string. Such strings come from the mode line, for
6036 example. We may have to pad with spaces, or truncate the
6037 string. See also next_element_from_c_string. */
6038 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6043 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6045 /* Pad with spaces. */
6046 it
->c
= ' ', it
->len
= 1;
6047 CHARPOS (position
) = BYTEPOS (position
) = -1;
6049 else if (STRING_MULTIBYTE (it
->string
))
6051 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6052 const unsigned char *s
= (SDATA (it
->string
)
6053 + IT_STRING_BYTEPOS (*it
));
6054 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6058 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6063 /* Record what we have and where it came from. */
6064 it
->what
= IT_CHARACTER
;
6065 it
->object
= it
->string
;
6066 it
->position
= position
;
6071 /* Load IT with next display element from C string IT->s.
6072 IT->string_nchars is the maximum number of characters to return
6073 from the string. IT->end_charpos may be greater than
6074 IT->string_nchars when this function is called, in which case we
6075 may have to return padding spaces. Value is zero if end of string
6076 reached, including padding spaces. */
6079 next_element_from_c_string (it
)
6085 it
->what
= IT_CHARACTER
;
6086 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6089 /* IT's position can be greater IT->string_nchars in case a field
6090 width or precision has been specified when the iterator was
6092 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6094 /* End of the game. */
6098 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6100 /* Pad with spaces. */
6101 it
->c
= ' ', it
->len
= 1;
6102 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6104 else if (it
->multibyte_p
)
6106 /* Implementation note: The calls to strlen apparently aren't a
6107 performance problem because there is no noticeable performance
6108 difference between Emacs running in unibyte or multibyte mode. */
6109 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6110 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6114 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6120 /* Set up IT to return characters from an ellipsis, if appropriate.
6121 The definition of the ellipsis glyphs may come from a display table
6122 entry. This function Fills IT with the first glyph from the
6123 ellipsis if an ellipsis is to be displayed. */
6126 next_element_from_ellipsis (it
)
6129 if (it
->selective_display_ellipsis_p
)
6130 setup_for_ellipsis (it
, it
->len
);
6133 /* The face at the current position may be different from the
6134 face we find after the invisible text. Remember what it
6135 was in IT->saved_face_id, and signal that it's there by
6136 setting face_before_selective_p. */
6137 it
->saved_face_id
= it
->face_id
;
6138 it
->method
= GET_FROM_BUFFER
;
6139 it
->object
= it
->w
->buffer
;
6140 reseat_at_next_visible_line_start (it
, 1);
6141 it
->face_before_selective_p
= 1;
6144 return get_next_display_element (it
);
6148 /* Deliver an image display element. The iterator IT is already
6149 filled with image information (done in handle_display_prop). Value
6154 next_element_from_image (it
)
6157 it
->what
= IT_IMAGE
;
6162 /* Fill iterator IT with next display element from a stretch glyph
6163 property. IT->object is the value of the text property. Value is
6167 next_element_from_stretch (it
)
6170 it
->what
= IT_STRETCH
;
6175 /* Load IT with the next display element from current_buffer. Value
6176 is zero if end of buffer reached. IT->stop_charpos is the next
6177 position at which to stop and check for text properties or buffer
6181 next_element_from_buffer (it
)
6186 /* Check this assumption, otherwise, we would never enter the
6187 if-statement, below. */
6188 xassert (IT_CHARPOS (*it
) >= BEGV
6189 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6191 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6193 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6195 int overlay_strings_follow_p
;
6197 /* End of the game, except when overlay strings follow that
6198 haven't been returned yet. */
6199 if (it
->overlay_strings_at_end_processed_p
)
6200 overlay_strings_follow_p
= 0;
6203 it
->overlay_strings_at_end_processed_p
= 1;
6204 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6207 if (overlay_strings_follow_p
)
6208 success_p
= get_next_display_element (it
);
6212 it
->position
= it
->current
.pos
;
6219 return get_next_display_element (it
);
6224 /* No face changes, overlays etc. in sight, so just return a
6225 character from current_buffer. */
6228 /* Maybe run the redisplay end trigger hook. Performance note:
6229 This doesn't seem to cost measurable time. */
6230 if (it
->redisplay_end_trigger_charpos
6232 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6233 run_redisplay_end_trigger_hook (it
);
6235 /* Get the next character, maybe multibyte. */
6236 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6237 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6239 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6240 - IT_BYTEPOS (*it
));
6241 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6244 it
->c
= *p
, it
->len
= 1;
6246 /* Record what we have and where it came from. */
6247 it
->what
= IT_CHARACTER
;;
6248 it
->object
= it
->w
->buffer
;
6249 it
->position
= it
->current
.pos
;
6251 /* Normally we return the character found above, except when we
6252 really want to return an ellipsis for selective display. */
6257 /* A value of selective > 0 means hide lines indented more
6258 than that number of columns. */
6259 if (it
->selective
> 0
6260 && IT_CHARPOS (*it
) + 1 < ZV
6261 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6262 IT_BYTEPOS (*it
) + 1,
6263 (double) it
->selective
)) /* iftc */
6265 success_p
= next_element_from_ellipsis (it
);
6266 it
->dpvec_char_len
= -1;
6269 else if (it
->c
== '\r' && it
->selective
== -1)
6271 /* A value of selective == -1 means that everything from the
6272 CR to the end of the line is invisible, with maybe an
6273 ellipsis displayed for it. */
6274 success_p
= next_element_from_ellipsis (it
);
6275 it
->dpvec_char_len
= -1;
6280 /* Value is zero if end of buffer reached. */
6281 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6286 /* Run the redisplay end trigger hook for IT. */
6289 run_redisplay_end_trigger_hook (it
)
6292 Lisp_Object args
[3];
6294 /* IT->glyph_row should be non-null, i.e. we should be actually
6295 displaying something, or otherwise we should not run the hook. */
6296 xassert (it
->glyph_row
);
6298 /* Set up hook arguments. */
6299 args
[0] = Qredisplay_end_trigger_functions
;
6300 args
[1] = it
->window
;
6301 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6302 it
->redisplay_end_trigger_charpos
= 0;
6304 /* Since we are *trying* to run these functions, don't try to run
6305 them again, even if they get an error. */
6306 it
->w
->redisplay_end_trigger
= Qnil
;
6307 Frun_hook_with_args (3, args
);
6309 /* Notice if it changed the face of the character we are on. */
6310 handle_face_prop (it
);
6314 /* Deliver a composition display element. The iterator IT is already
6315 filled with composition information (done in
6316 handle_composition_prop). Value is always 1. */
6319 next_element_from_composition (it
)
6322 it
->what
= IT_COMPOSITION
;
6323 it
->position
= (STRINGP (it
->string
)
6324 ? it
->current
.string_pos
6326 if (STRINGP (it
->string
))
6327 it
->object
= it
->string
;
6329 it
->object
= it
->w
->buffer
;
6335 /***********************************************************************
6336 Moving an iterator without producing glyphs
6337 ***********************************************************************/
6339 /* Check if iterator is at a position corresponding to a valid buffer
6340 position after some move_it_ call. */
6342 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6343 ((it)->method == GET_FROM_STRING \
6344 ? IT_STRING_CHARPOS (*it) == 0 \
6348 /* Move iterator IT to a specified buffer or X position within one
6349 line on the display without producing glyphs.
6351 OP should be a bit mask including some or all of these bits:
6352 MOVE_TO_X: Stop on reaching x-position TO_X.
6353 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6354 Regardless of OP's value, stop in reaching the end of the display line.
6356 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6357 This means, in particular, that TO_X includes window's horizontal
6360 The return value has several possible values that
6361 say what condition caused the scan to stop:
6363 MOVE_POS_MATCH_OR_ZV
6364 - when TO_POS or ZV was reached.
6367 -when TO_X was reached before TO_POS or ZV were reached.
6370 - when we reached the end of the display area and the line must
6374 - when we reached the end of the display area and the line is
6378 - when we stopped at a line end, i.e. a newline or a CR and selective
6381 static enum move_it_result
6382 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6384 int to_charpos
, to_x
, op
;
6386 enum move_it_result result
= MOVE_UNDEFINED
;
6387 struct glyph_row
*saved_glyph_row
;
6389 /* Don't produce glyphs in produce_glyphs. */
6390 saved_glyph_row
= it
->glyph_row
;
6391 it
->glyph_row
= NULL
;
6393 #define BUFFER_POS_REACHED_P() \
6394 ((op & MOVE_TO_POS) != 0 \
6395 && BUFFERP (it->object) \
6396 && IT_CHARPOS (*it) >= to_charpos \
6397 && (it->method == GET_FROM_BUFFER \
6398 || (it->method == GET_FROM_DISPLAY_VECTOR \
6399 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6404 int x
, i
, ascent
= 0, descent
= 0;
6406 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6407 if ((op
& MOVE_TO_POS
) != 0
6408 && BUFFERP (it
->object
)
6409 && it
->method
== GET_FROM_BUFFER
6410 && IT_CHARPOS (*it
) > to_charpos
)
6412 result
= MOVE_POS_MATCH_OR_ZV
;
6416 /* Stop when ZV reached.
6417 We used to stop here when TO_CHARPOS reached as well, but that is
6418 too soon if this glyph does not fit on this line. So we handle it
6419 explicitly below. */
6420 if (!get_next_display_element (it
)
6421 || (it
->truncate_lines_p
6422 && BUFFER_POS_REACHED_P ()))
6424 result
= MOVE_POS_MATCH_OR_ZV
;
6428 /* The call to produce_glyphs will get the metrics of the
6429 display element IT is loaded with. We record in x the
6430 x-position before this display element in case it does not
6434 /* Remember the line height so far in case the next element doesn't
6436 if (!it
->truncate_lines_p
)
6438 ascent
= it
->max_ascent
;
6439 descent
= it
->max_descent
;
6442 PRODUCE_GLYPHS (it
);
6444 if (it
->area
!= TEXT_AREA
)
6446 set_iterator_to_next (it
, 1);
6450 /* The number of glyphs we get back in IT->nglyphs will normally
6451 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6452 character on a terminal frame, or (iii) a line end. For the
6453 second case, IT->nglyphs - 1 padding glyphs will be present
6454 (on X frames, there is only one glyph produced for a
6455 composite character.
6457 The behavior implemented below means, for continuation lines,
6458 that as many spaces of a TAB as fit on the current line are
6459 displayed there. For terminal frames, as many glyphs of a
6460 multi-glyph character are displayed in the current line, too.
6461 This is what the old redisplay code did, and we keep it that
6462 way. Under X, the whole shape of a complex character must
6463 fit on the line or it will be completely displayed in the
6466 Note that both for tabs and padding glyphs, all glyphs have
6470 /* More than one glyph or glyph doesn't fit on line. All
6471 glyphs have the same width. */
6472 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6474 int x_before_this_char
= x
;
6475 int hpos_before_this_char
= it
->hpos
;
6477 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6479 new_x
= x
+ single_glyph_width
;
6481 /* We want to leave anything reaching TO_X to the caller. */
6482 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6484 if (BUFFER_POS_REACHED_P ())
6485 goto buffer_pos_reached
;
6487 result
= MOVE_X_REACHED
;
6490 else if (/* Lines are continued. */
6491 !it
->truncate_lines_p
6492 && (/* And glyph doesn't fit on the line. */
6493 new_x
> it
->last_visible_x
6494 /* Or it fits exactly and we're on a window
6496 || (new_x
== it
->last_visible_x
6497 && FRAME_WINDOW_P (it
->f
))))
6499 if (/* IT->hpos == 0 means the very first glyph
6500 doesn't fit on the line, e.g. a wide image. */
6502 || (new_x
== it
->last_visible_x
6503 && FRAME_WINDOW_P (it
->f
)))
6506 it
->current_x
= new_x
;
6508 /* The character's last glyph just barely fits
6510 if (i
== it
->nglyphs
- 1)
6512 /* If this is the destination position,
6513 return a position *before* it in this row,
6514 now that we know it fits in this row. */
6515 if (BUFFER_POS_REACHED_P ())
6517 it
->hpos
= hpos_before_this_char
;
6518 it
->current_x
= x_before_this_char
;
6519 result
= MOVE_POS_MATCH_OR_ZV
;
6523 set_iterator_to_next (it
, 1);
6524 #ifdef HAVE_WINDOW_SYSTEM
6525 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6527 if (!get_next_display_element (it
))
6529 result
= MOVE_POS_MATCH_OR_ZV
;
6532 if (BUFFER_POS_REACHED_P ())
6534 if (ITERATOR_AT_END_OF_LINE_P (it
))
6535 result
= MOVE_POS_MATCH_OR_ZV
;
6537 result
= MOVE_LINE_CONTINUED
;
6540 if (ITERATOR_AT_END_OF_LINE_P (it
))
6542 result
= MOVE_NEWLINE_OR_CR
;
6546 #endif /* HAVE_WINDOW_SYSTEM */
6552 it
->max_ascent
= ascent
;
6553 it
->max_descent
= descent
;
6556 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6558 result
= MOVE_LINE_CONTINUED
;
6561 else if (BUFFER_POS_REACHED_P ())
6562 goto buffer_pos_reached
;
6563 else if (new_x
> it
->first_visible_x
)
6565 /* Glyph is visible. Increment number of glyphs that
6566 would be displayed. */
6571 /* Glyph is completely off the left margin of the display
6572 area. Nothing to do. */
6576 if (result
!= MOVE_UNDEFINED
)
6579 else if (BUFFER_POS_REACHED_P ())
6583 it
->max_ascent
= ascent
;
6584 it
->max_descent
= descent
;
6585 result
= MOVE_POS_MATCH_OR_ZV
;
6588 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6590 /* Stop when TO_X specified and reached. This check is
6591 necessary here because of lines consisting of a line end,
6592 only. The line end will not produce any glyphs and we
6593 would never get MOVE_X_REACHED. */
6594 xassert (it
->nglyphs
== 0);
6595 result
= MOVE_X_REACHED
;
6599 /* Is this a line end? If yes, we're done. */
6600 if (ITERATOR_AT_END_OF_LINE_P (it
))
6602 result
= MOVE_NEWLINE_OR_CR
;
6606 /* The current display element has been consumed. Advance
6608 set_iterator_to_next (it
, 1);
6610 /* Stop if lines are truncated and IT's current x-position is
6611 past the right edge of the window now. */
6612 if (it
->truncate_lines_p
6613 && it
->current_x
>= it
->last_visible_x
)
6615 #ifdef HAVE_WINDOW_SYSTEM
6616 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6618 if (!get_next_display_element (it
)
6619 || BUFFER_POS_REACHED_P ())
6621 result
= MOVE_POS_MATCH_OR_ZV
;
6624 if (ITERATOR_AT_END_OF_LINE_P (it
))
6626 result
= MOVE_NEWLINE_OR_CR
;
6630 #endif /* HAVE_WINDOW_SYSTEM */
6631 result
= MOVE_LINE_TRUNCATED
;
6636 #undef BUFFER_POS_REACHED_P
6638 /* Restore the iterator settings altered at the beginning of this
6640 it
->glyph_row
= saved_glyph_row
;
6645 /* Move IT forward until it satisfies one or more of the criteria in
6646 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6648 OP is a bit-mask that specifies where to stop, and in particular,
6649 which of those four position arguments makes a difference. See the
6650 description of enum move_operation_enum.
6652 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6653 screen line, this function will set IT to the next position >
6657 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6659 int to_charpos
, to_x
, to_y
, to_vpos
;
6662 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6668 if (op
& MOVE_TO_VPOS
)
6670 /* If no TO_CHARPOS and no TO_X specified, stop at the
6671 start of the line TO_VPOS. */
6672 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6674 if (it
->vpos
== to_vpos
)
6680 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6684 /* TO_VPOS >= 0 means stop at TO_X in the line at
6685 TO_VPOS, or at TO_POS, whichever comes first. */
6686 if (it
->vpos
== to_vpos
)
6692 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6694 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6699 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6701 /* We have reached TO_X but not in the line we want. */
6702 skip
= move_it_in_display_line_to (it
, to_charpos
,
6704 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6712 else if (op
& MOVE_TO_Y
)
6714 struct it it_backup
;
6716 /* TO_Y specified means stop at TO_X in the line containing
6717 TO_Y---or at TO_CHARPOS if this is reached first. The
6718 problem is that we can't really tell whether the line
6719 contains TO_Y before we have completely scanned it, and
6720 this may skip past TO_X. What we do is to first scan to
6723 If TO_X is not specified, use a TO_X of zero. The reason
6724 is to make the outcome of this function more predictable.
6725 If we didn't use TO_X == 0, we would stop at the end of
6726 the line which is probably not what a caller would expect
6728 skip
= move_it_in_display_line_to (it
, to_charpos
,
6732 | (op
& MOVE_TO_POS
)));
6734 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6735 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6741 /* If TO_X was reached, we would like to know whether TO_Y
6742 is in the line. This can only be said if we know the
6743 total line height which requires us to scan the rest of
6745 if (skip
== MOVE_X_REACHED
)
6748 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6749 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6751 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6754 /* Now, decide whether TO_Y is in this line. */
6755 line_height
= it
->max_ascent
+ it
->max_descent
;
6756 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6758 if (to_y
>= it
->current_y
6759 && to_y
< it
->current_y
+ line_height
)
6761 if (skip
== MOVE_X_REACHED
)
6762 /* If TO_Y is in this line and TO_X was reached above,
6763 we scanned too far. We have to restore IT's settings
6764 to the ones before skipping. */
6768 else if (skip
== MOVE_X_REACHED
)
6771 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6778 else if (BUFFERP (it
->object
)
6779 && it
->method
== GET_FROM_BUFFER
6780 && IT_CHARPOS (*it
) >= to_charpos
)
6781 skip
= MOVE_POS_MATCH_OR_ZV
;
6783 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6787 case MOVE_POS_MATCH_OR_ZV
:
6791 case MOVE_NEWLINE_OR_CR
:
6792 set_iterator_to_next (it
, 1);
6793 it
->continuation_lines_width
= 0;
6796 case MOVE_LINE_TRUNCATED
:
6797 it
->continuation_lines_width
= 0;
6798 reseat_at_next_visible_line_start (it
, 0);
6799 if ((op
& MOVE_TO_POS
) != 0
6800 && IT_CHARPOS (*it
) > to_charpos
)
6807 case MOVE_LINE_CONTINUED
:
6808 it
->continuation_lines_width
+= it
->current_x
;
6815 /* Reset/increment for the next run. */
6816 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6817 it
->current_x
= it
->hpos
= 0;
6818 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6820 last_height
= it
->max_ascent
+ it
->max_descent
;
6821 last_max_ascent
= it
->max_ascent
;
6822 it
->max_ascent
= it
->max_descent
= 0;
6827 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6831 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6833 If DY > 0, move IT backward at least that many pixels. DY = 0
6834 means move IT backward to the preceding line start or BEGV. This
6835 function may move over more than DY pixels if IT->current_y - DY
6836 ends up in the middle of a line; in this case IT->current_y will be
6837 set to the top of the line moved to. */
6840 move_it_vertically_backward (it
, dy
)
6851 start_pos
= IT_CHARPOS (*it
);
6853 /* Estimate how many newlines we must move back. */
6854 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6856 /* Set the iterator's position that many lines back. */
6857 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6858 back_to_previous_visible_line_start (it
);
6860 /* Reseat the iterator here. When moving backward, we don't want
6861 reseat to skip forward over invisible text, set up the iterator
6862 to deliver from overlay strings at the new position etc. So,
6863 use reseat_1 here. */
6864 reseat_1 (it
, it
->current
.pos
, 1);
6866 /* We are now surely at a line start. */
6867 it
->current_x
= it
->hpos
= 0;
6868 it
->continuation_lines_width
= 0;
6870 /* Move forward and see what y-distance we moved. First move to the
6871 start of the next line so that we get its height. We need this
6872 height to be able to tell whether we reached the specified
6875 it2
.max_ascent
= it2
.max_descent
= 0;
6878 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6879 MOVE_TO_POS
| MOVE_TO_VPOS
);
6881 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6882 xassert (IT_CHARPOS (*it
) >= BEGV
);
6885 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6886 xassert (IT_CHARPOS (*it
) >= BEGV
);
6887 /* H is the actual vertical distance from the position in *IT
6888 and the starting position. */
6889 h
= it2
.current_y
- it
->current_y
;
6890 /* NLINES is the distance in number of lines. */
6891 nlines
= it2
.vpos
- it
->vpos
;
6893 /* Correct IT's y and vpos position
6894 so that they are relative to the starting point. */
6900 /* DY == 0 means move to the start of the screen line. The
6901 value of nlines is > 0 if continuation lines were involved. */
6903 move_it_by_lines (it
, nlines
, 1);
6905 /* I think this assert is bogus if buffer contains
6906 invisible text or images. KFS. */
6907 xassert (IT_CHARPOS (*it
) <= start_pos
);
6912 /* The y-position we try to reach, relative to *IT.
6913 Note that H has been subtracted in front of the if-statement. */
6914 int target_y
= it
->current_y
+ h
- dy
;
6915 int y0
= it3
.current_y
;
6916 int y1
= line_bottom_y (&it3
);
6917 int line_height
= y1
- y0
;
6919 /* If we did not reach target_y, try to move further backward if
6920 we can. If we moved too far backward, try to move forward. */
6921 if (target_y
< it
->current_y
6922 /* This is heuristic. In a window that's 3 lines high, with
6923 a line height of 13 pixels each, recentering with point
6924 on the bottom line will try to move -39/2 = 19 pixels
6925 backward. Try to avoid moving into the first line. */
6926 && (it
->current_y
- target_y
6927 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6928 && IT_CHARPOS (*it
) > BEGV
)
6930 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6931 target_y
- it
->current_y
));
6932 dy
= it
->current_y
- target_y
;
6933 goto move_further_back
;
6935 else if (target_y
>= it
->current_y
+ line_height
6936 && IT_CHARPOS (*it
) < ZV
)
6938 /* Should move forward by at least one line, maybe more.
6940 Note: Calling move_it_by_lines can be expensive on
6941 terminal frames, where compute_motion is used (via
6942 vmotion) to do the job, when there are very long lines
6943 and truncate-lines is nil. That's the reason for
6944 treating terminal frames specially here. */
6946 if (!FRAME_WINDOW_P (it
->f
))
6947 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6952 move_it_by_lines (it
, 1, 1);
6954 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6958 /* I think this assert is bogus if buffer contains
6959 invisible text or images. KFS. */
6960 xassert (IT_CHARPOS (*it
) >= BEGV
);
6967 /* Move IT by a specified amount of pixel lines DY. DY negative means
6968 move backwards. DY = 0 means move to start of screen line. At the
6969 end, IT will be on the start of a screen line. */
6972 move_it_vertically (it
, dy
)
6977 move_it_vertically_backward (it
, -dy
);
6980 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6981 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6982 MOVE_TO_POS
| MOVE_TO_Y
);
6983 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6985 /* If buffer ends in ZV without a newline, move to the start of
6986 the line to satisfy the post-condition. */
6987 if (IT_CHARPOS (*it
) == ZV
6989 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6990 move_it_by_lines (it
, 0, 0);
6995 /* Move iterator IT past the end of the text line it is in. */
6998 move_it_past_eol (it
)
7001 enum move_it_result rc
;
7003 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7004 if (rc
== MOVE_NEWLINE_OR_CR
)
7005 set_iterator_to_next (it
, 0);
7009 #if 0 /* Currently not used. */
7011 /* Return non-zero if some text between buffer positions START_CHARPOS
7012 and END_CHARPOS is invisible. IT->window is the window for text
7016 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7018 int start_charpos
, end_charpos
;
7020 Lisp_Object prop
, limit
;
7021 int invisible_found_p
;
7023 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7025 /* Is text at START invisible? */
7026 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7028 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7029 invisible_found_p
= 1;
7032 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7034 make_number (end_charpos
));
7035 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7038 return invisible_found_p
;
7044 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7045 negative means move up. DVPOS == 0 means move to the start of the
7046 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7047 NEED_Y_P is zero, IT->current_y will be left unchanged.
7049 Further optimization ideas: If we would know that IT->f doesn't use
7050 a face with proportional font, we could be faster for
7051 truncate-lines nil. */
7054 move_it_by_lines (it
, dvpos
, need_y_p
)
7056 int dvpos
, need_y_p
;
7058 struct position pos
;
7060 if (!FRAME_WINDOW_P (it
->f
))
7062 struct text_pos textpos
;
7064 /* We can use vmotion on frames without proportional fonts. */
7065 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
7066 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
7067 reseat (it
, textpos
, 1);
7068 it
->vpos
+= pos
.vpos
;
7069 it
->current_y
+= pos
.vpos
;
7071 else if (dvpos
== 0)
7073 /* DVPOS == 0 means move to the start of the screen line. */
7074 move_it_vertically_backward (it
, 0);
7075 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7076 /* Let next call to line_bottom_y calculate real line height */
7081 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7082 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7083 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7088 int start_charpos
, i
;
7090 /* Start at the beginning of the screen line containing IT's
7091 position. This may actually move vertically backwards,
7092 in case of overlays, so adjust dvpos accordingly. */
7094 move_it_vertically_backward (it
, 0);
7097 /* Go back -DVPOS visible lines and reseat the iterator there. */
7098 start_charpos
= IT_CHARPOS (*it
);
7099 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7100 back_to_previous_visible_line_start (it
);
7101 reseat (it
, it
->current
.pos
, 1);
7103 /* Move further back if we end up in a string or an image. */
7104 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7106 /* First try to move to start of display line. */
7108 move_it_vertically_backward (it
, 0);
7110 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7112 /* If start of line is still in string or image,
7113 move further back. */
7114 back_to_previous_visible_line_start (it
);
7115 reseat (it
, it
->current
.pos
, 1);
7119 it
->current_x
= it
->hpos
= 0;
7121 /* Above call may have moved too far if continuation lines
7122 are involved. Scan forward and see if it did. */
7124 it2
.vpos
= it2
.current_y
= 0;
7125 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7126 it
->vpos
-= it2
.vpos
;
7127 it
->current_y
-= it2
.current_y
;
7128 it
->current_x
= it
->hpos
= 0;
7130 /* If we moved too far back, move IT some lines forward. */
7131 if (it2
.vpos
> -dvpos
)
7133 int delta
= it2
.vpos
+ dvpos
;
7135 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7136 /* Move back again if we got too far ahead. */
7137 if (IT_CHARPOS (*it
) >= start_charpos
)
7143 /* Return 1 if IT points into the middle of a display vector. */
7146 in_display_vector_p (it
)
7149 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7150 && it
->current
.dpvec_index
> 0
7151 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7155 /***********************************************************************
7157 ***********************************************************************/
7160 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7164 add_to_log (format
, arg1
, arg2
)
7166 Lisp_Object arg1
, arg2
;
7168 Lisp_Object args
[3];
7169 Lisp_Object msg
, fmt
;
7172 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7175 /* Do nothing if called asynchronously. Inserting text into
7176 a buffer may call after-change-functions and alike and
7177 that would means running Lisp asynchronously. */
7178 if (handling_signal
)
7182 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7184 args
[0] = fmt
= build_string (format
);
7187 msg
= Fformat (3, args
);
7189 len
= SBYTES (msg
) + 1;
7190 SAFE_ALLOCA (buffer
, char *, len
);
7191 bcopy (SDATA (msg
), buffer
, len
);
7193 message_dolog (buffer
, len
- 1, 1, 0);
7200 /* Output a newline in the *Messages* buffer if "needs" one. */
7203 message_log_maybe_newline ()
7205 if (message_log_need_newline
)
7206 message_dolog ("", 0, 1, 0);
7210 /* Add a string M of length NBYTES to the message log, optionally
7211 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7212 nonzero, means interpret the contents of M as multibyte. This
7213 function calls low-level routines in order to bypass text property
7214 hooks, etc. which might not be safe to run.
7216 This may GC (insert may run before/after change hooks),
7217 so the buffer M must NOT point to a Lisp string. */
7220 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7222 int nbytes
, nlflag
, multibyte
;
7224 if (!NILP (Vmemory_full
))
7227 if (!NILP (Vmessage_log_max
))
7229 struct buffer
*oldbuf
;
7230 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7231 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7232 int point_at_end
= 0;
7234 Lisp_Object old_deactivate_mark
, tem
;
7235 struct gcpro gcpro1
;
7237 old_deactivate_mark
= Vdeactivate_mark
;
7238 oldbuf
= current_buffer
;
7239 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7240 current_buffer
->undo_list
= Qt
;
7242 oldpoint
= message_dolog_marker1
;
7243 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7244 oldbegv
= message_dolog_marker2
;
7245 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7246 oldzv
= message_dolog_marker3
;
7247 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7248 GCPRO1 (old_deactivate_mark
);
7256 BEGV_BYTE
= BEG_BYTE
;
7259 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7261 /* Insert the string--maybe converting multibyte to single byte
7262 or vice versa, so that all the text fits the buffer. */
7264 && NILP (current_buffer
->enable_multibyte_characters
))
7266 int i
, c
, char_bytes
;
7267 unsigned char work
[1];
7269 /* Convert a multibyte string to single-byte
7270 for the *Message* buffer. */
7271 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7273 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7274 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7276 : multibyte_char_to_unibyte (c
, Qnil
));
7277 insert_1_both (work
, 1, 1, 1, 0, 0);
7280 else if (! multibyte
7281 && ! NILP (current_buffer
->enable_multibyte_characters
))
7283 int i
, c
, char_bytes
;
7284 unsigned char *msg
= (unsigned char *) m
;
7285 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7286 /* Convert a single-byte string to multibyte
7287 for the *Message* buffer. */
7288 for (i
= 0; i
< nbytes
; i
++)
7290 c
= unibyte_char_to_multibyte (msg
[i
]);
7291 char_bytes
= CHAR_STRING (c
, str
);
7292 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7296 insert_1 (m
, nbytes
, 1, 0, 0);
7300 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7301 insert_1 ("\n", 1, 1, 0, 0);
7303 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7305 this_bol_byte
= PT_BYTE
;
7307 /* See if this line duplicates the previous one.
7308 If so, combine duplicates. */
7311 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7313 prev_bol_byte
= PT_BYTE
;
7315 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7316 this_bol
, this_bol_byte
);
7319 del_range_both (prev_bol
, prev_bol_byte
,
7320 this_bol
, this_bol_byte
, 0);
7326 /* If you change this format, don't forget to also
7327 change message_log_check_duplicate. */
7328 sprintf (dupstr
, " [%d times]", dup
);
7329 duplen
= strlen (dupstr
);
7330 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7331 insert_1 (dupstr
, duplen
, 1, 0, 1);
7336 /* If we have more than the desired maximum number of lines
7337 in the *Messages* buffer now, delete the oldest ones.
7338 This is safe because we don't have undo in this buffer. */
7340 if (NATNUMP (Vmessage_log_max
))
7342 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7343 -XFASTINT (Vmessage_log_max
) - 1, 0);
7344 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7347 BEGV
= XMARKER (oldbegv
)->charpos
;
7348 BEGV_BYTE
= marker_byte_position (oldbegv
);
7357 ZV
= XMARKER (oldzv
)->charpos
;
7358 ZV_BYTE
= marker_byte_position (oldzv
);
7362 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7364 /* We can't do Fgoto_char (oldpoint) because it will run some
7366 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7367 XMARKER (oldpoint
)->bytepos
);
7370 unchain_marker (XMARKER (oldpoint
));
7371 unchain_marker (XMARKER (oldbegv
));
7372 unchain_marker (XMARKER (oldzv
));
7374 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7375 set_buffer_internal (oldbuf
);
7377 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7378 message_log_need_newline
= !nlflag
;
7379 Vdeactivate_mark
= old_deactivate_mark
;
7384 /* We are at the end of the buffer after just having inserted a newline.
7385 (Note: We depend on the fact we won't be crossing the gap.)
7386 Check to see if the most recent message looks a lot like the previous one.
7387 Return 0 if different, 1 if the new one should just replace it, or a
7388 value N > 1 if we should also append " [N times]". */
7391 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7392 int prev_bol
, this_bol
;
7393 int prev_bol_byte
, this_bol_byte
;
7396 int len
= Z_BYTE
- 1 - this_bol_byte
;
7398 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7399 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7401 for (i
= 0; i
< len
; i
++)
7403 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7411 if (*p1
++ == ' ' && *p1
++ == '[')
7414 while (*p1
>= '0' && *p1
<= '9')
7415 n
= n
* 10 + *p1
++ - '0';
7416 if (strncmp (p1
, " times]\n", 8) == 0)
7423 /* Display an echo area message M with a specified length of NBYTES
7424 bytes. The string may include null characters. If M is 0, clear
7425 out any existing message, and let the mini-buffer text show
7428 This may GC, so the buffer M must NOT point to a Lisp string. */
7431 message2 (m
, nbytes
, multibyte
)
7436 /* First flush out any partial line written with print. */
7437 message_log_maybe_newline ();
7439 message_dolog (m
, nbytes
, 1, multibyte
);
7440 message2_nolog (m
, nbytes
, multibyte
);
7444 /* The non-logging counterpart of message2. */
7447 message2_nolog (m
, nbytes
, multibyte
)
7449 int nbytes
, multibyte
;
7451 struct frame
*sf
= SELECTED_FRAME ();
7452 message_enable_multibyte
= multibyte
;
7456 if (noninteractive_need_newline
)
7457 putc ('\n', stderr
);
7458 noninteractive_need_newline
= 0;
7460 fwrite (m
, nbytes
, 1, stderr
);
7461 if (cursor_in_echo_area
== 0)
7462 fprintf (stderr
, "\n");
7465 /* A null message buffer means that the frame hasn't really been
7466 initialized yet. Error messages get reported properly by
7467 cmd_error, so this must be just an informative message; toss it. */
7468 else if (INTERACTIVE
7469 && sf
->glyphs_initialized_p
7470 && FRAME_MESSAGE_BUF (sf
))
7472 Lisp_Object mini_window
;
7475 /* Get the frame containing the mini-buffer
7476 that the selected frame is using. */
7477 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7478 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7480 FRAME_SAMPLE_VISIBILITY (f
);
7481 if (FRAME_VISIBLE_P (sf
)
7482 && ! FRAME_VISIBLE_P (f
))
7483 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7487 set_message (m
, Qnil
, nbytes
, multibyte
);
7488 if (minibuffer_auto_raise
)
7489 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7492 clear_message (1, 1);
7494 do_pending_window_change (0);
7495 echo_area_display (1);
7496 do_pending_window_change (0);
7497 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7498 (*frame_up_to_date_hook
) (f
);
7503 /* Display an echo area message M with a specified length of NBYTES
7504 bytes. The string may include null characters. If M is not a
7505 string, clear out any existing message, and let the mini-buffer
7508 This function cancels echoing. */
7511 message3 (m
, nbytes
, multibyte
)
7516 struct gcpro gcpro1
;
7519 clear_message (1,1);
7522 /* First flush out any partial line written with print. */
7523 message_log_maybe_newline ();
7529 SAFE_ALLOCA (buffer
, char *, nbytes
);
7530 bcopy (SDATA (m
), buffer
, nbytes
);
7531 message_dolog (buffer
, nbytes
, 1, multibyte
);
7534 message3_nolog (m
, nbytes
, multibyte
);
7540 /* The non-logging version of message3.
7541 This does not cancel echoing, because it is used for echoing.
7542 Perhaps we need to make a separate function for echoing
7543 and make this cancel echoing. */
7546 message3_nolog (m
, nbytes
, multibyte
)
7548 int nbytes
, multibyte
;
7550 struct frame
*sf
= SELECTED_FRAME ();
7551 message_enable_multibyte
= multibyte
;
7555 if (noninteractive_need_newline
)
7556 putc ('\n', stderr
);
7557 noninteractive_need_newline
= 0;
7559 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7560 if (cursor_in_echo_area
== 0)
7561 fprintf (stderr
, "\n");
7564 /* A null message buffer means that the frame hasn't really been
7565 initialized yet. Error messages get reported properly by
7566 cmd_error, so this must be just an informative message; toss it. */
7567 else if (INTERACTIVE
7568 && sf
->glyphs_initialized_p
7569 && FRAME_MESSAGE_BUF (sf
))
7571 Lisp_Object mini_window
;
7575 /* Get the frame containing the mini-buffer
7576 that the selected frame is using. */
7577 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7578 frame
= XWINDOW (mini_window
)->frame
;
7581 FRAME_SAMPLE_VISIBILITY (f
);
7582 if (FRAME_VISIBLE_P (sf
)
7583 && !FRAME_VISIBLE_P (f
))
7584 Fmake_frame_visible (frame
);
7586 if (STRINGP (m
) && SCHARS (m
) > 0)
7588 set_message (NULL
, m
, nbytes
, multibyte
);
7589 if (minibuffer_auto_raise
)
7590 Fraise_frame (frame
);
7591 /* Assume we are not echoing.
7592 (If we are, echo_now will override this.) */
7593 echo_message_buffer
= Qnil
;
7596 clear_message (1, 1);
7598 do_pending_window_change (0);
7599 echo_area_display (1);
7600 do_pending_window_change (0);
7601 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7602 (*frame_up_to_date_hook
) (f
);
7607 /* Display a null-terminated echo area message M. If M is 0, clear
7608 out any existing message, and let the mini-buffer text show through.
7610 The buffer M must continue to exist until after the echo area gets
7611 cleared or some other message gets displayed there. Do not pass
7612 text that is stored in a Lisp string. Do not pass text in a buffer
7613 that was alloca'd. */
7619 message2 (m
, (m
? strlen (m
) : 0), 0);
7623 /* The non-logging counterpart of message1. */
7629 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7632 /* Display a message M which contains a single %s
7633 which gets replaced with STRING. */
7636 message_with_string (m
, string
, log
)
7641 CHECK_STRING (string
);
7647 if (noninteractive_need_newline
)
7648 putc ('\n', stderr
);
7649 noninteractive_need_newline
= 0;
7650 fprintf (stderr
, m
, SDATA (string
));
7651 if (cursor_in_echo_area
== 0)
7652 fprintf (stderr
, "\n");
7656 else if (INTERACTIVE
)
7658 /* The frame whose minibuffer we're going to display the message on.
7659 It may be larger than the selected frame, so we need
7660 to use its buffer, not the selected frame's buffer. */
7661 Lisp_Object mini_window
;
7662 struct frame
*f
, *sf
= SELECTED_FRAME ();
7664 /* Get the frame containing the minibuffer
7665 that the selected frame is using. */
7666 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7667 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7669 /* A null message buffer means that the frame hasn't really been
7670 initialized yet. Error messages get reported properly by
7671 cmd_error, so this must be just an informative message; toss it. */
7672 if (FRAME_MESSAGE_BUF (f
))
7674 Lisp_Object args
[2], message
;
7675 struct gcpro gcpro1
, gcpro2
;
7677 args
[0] = build_string (m
);
7678 args
[1] = message
= string
;
7679 GCPRO2 (args
[0], message
);
7682 message
= Fformat (2, args
);
7685 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7687 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7691 /* Print should start at the beginning of the message
7692 buffer next time. */
7693 message_buf_print
= 0;
7699 /* Dump an informative message to the minibuf. If M is 0, clear out
7700 any existing message, and let the mini-buffer text show through. */
7704 message (m
, a1
, a2
, a3
)
7706 EMACS_INT a1
, a2
, a3
;
7712 if (noninteractive_need_newline
)
7713 putc ('\n', stderr
);
7714 noninteractive_need_newline
= 0;
7715 fprintf (stderr
, m
, a1
, a2
, a3
);
7716 if (cursor_in_echo_area
== 0)
7717 fprintf (stderr
, "\n");
7721 else if (INTERACTIVE
)
7723 /* The frame whose mini-buffer we're going to display the message
7724 on. It may be larger than the selected frame, so we need to
7725 use its buffer, not the selected frame's buffer. */
7726 Lisp_Object mini_window
;
7727 struct frame
*f
, *sf
= SELECTED_FRAME ();
7729 /* Get the frame containing the mini-buffer
7730 that the selected frame is using. */
7731 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7732 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7734 /* A null message buffer means that the frame hasn't really been
7735 initialized yet. Error messages get reported properly by
7736 cmd_error, so this must be just an informative message; toss
7738 if (FRAME_MESSAGE_BUF (f
))
7749 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7750 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7752 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7753 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7755 #endif /* NO_ARG_ARRAY */
7757 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7762 /* Print should start at the beginning of the message
7763 buffer next time. */
7764 message_buf_print
= 0;
7770 /* The non-logging version of message. */
7773 message_nolog (m
, a1
, a2
, a3
)
7775 EMACS_INT a1
, a2
, a3
;
7777 Lisp_Object old_log_max
;
7778 old_log_max
= Vmessage_log_max
;
7779 Vmessage_log_max
= Qnil
;
7780 message (m
, a1
, a2
, a3
);
7781 Vmessage_log_max
= old_log_max
;
7785 /* Display the current message in the current mini-buffer. This is
7786 only called from error handlers in process.c, and is not time
7792 if (!NILP (echo_area_buffer
[0]))
7795 string
= Fcurrent_message ();
7796 message3 (string
, SBYTES (string
),
7797 !NILP (current_buffer
->enable_multibyte_characters
));
7802 /* Make sure echo area buffers in `echo_buffers' are live.
7803 If they aren't, make new ones. */
7806 ensure_echo_area_buffers ()
7810 for (i
= 0; i
< 2; ++i
)
7811 if (!BUFFERP (echo_buffer
[i
])
7812 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7815 Lisp_Object old_buffer
;
7818 old_buffer
= echo_buffer
[i
];
7819 sprintf (name
, " *Echo Area %d*", i
);
7820 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7821 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7823 for (j
= 0; j
< 2; ++j
)
7824 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7825 echo_area_buffer
[j
] = echo_buffer
[i
];
7830 /* Call FN with args A1..A4 with either the current or last displayed
7831 echo_area_buffer as current buffer.
7833 WHICH zero means use the current message buffer
7834 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7835 from echo_buffer[] and clear it.
7837 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7838 suitable buffer from echo_buffer[] and clear it.
7840 Value is what FN returns. */
7843 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7846 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7852 int this_one
, the_other
, clear_buffer_p
, rc
;
7853 int count
= SPECPDL_INDEX ();
7855 /* If buffers aren't live, make new ones. */
7856 ensure_echo_area_buffers ();
7861 this_one
= 0, the_other
= 1;
7863 this_one
= 1, the_other
= 0;
7865 /* Choose a suitable buffer from echo_buffer[] is we don't
7867 if (NILP (echo_area_buffer
[this_one
]))
7869 echo_area_buffer
[this_one
]
7870 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7871 ? echo_buffer
[the_other
]
7872 : echo_buffer
[this_one
]);
7876 buffer
= echo_area_buffer
[this_one
];
7878 /* Don't get confused by reusing the buffer used for echoing
7879 for a different purpose. */
7880 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7883 record_unwind_protect (unwind_with_echo_area_buffer
,
7884 with_echo_area_buffer_unwind_data (w
));
7886 /* Make the echo area buffer current. Note that for display
7887 purposes, it is not necessary that the displayed window's buffer
7888 == current_buffer, except for text property lookup. So, let's
7889 only set that buffer temporarily here without doing a full
7890 Fset_window_buffer. We must also change w->pointm, though,
7891 because otherwise an assertions in unshow_buffer fails, and Emacs
7893 set_buffer_internal_1 (XBUFFER (buffer
));
7897 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7900 current_buffer
->undo_list
= Qt
;
7901 current_buffer
->read_only
= Qnil
;
7902 specbind (Qinhibit_read_only
, Qt
);
7903 specbind (Qinhibit_modification_hooks
, Qt
);
7905 if (clear_buffer_p
&& Z
> BEG
)
7908 xassert (BEGV
>= BEG
);
7909 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7911 rc
= fn (a1
, a2
, a3
, a4
);
7913 xassert (BEGV
>= BEG
);
7914 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7916 unbind_to (count
, Qnil
);
7921 /* Save state that should be preserved around the call to the function
7922 FN called in with_echo_area_buffer. */
7925 with_echo_area_buffer_unwind_data (w
)
7931 /* Reduce consing by keeping one vector in
7932 Vwith_echo_area_save_vector. */
7933 vector
= Vwith_echo_area_save_vector
;
7934 Vwith_echo_area_save_vector
= Qnil
;
7937 vector
= Fmake_vector (make_number (7), Qnil
);
7939 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7940 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7941 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7945 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7946 AREF (vector
, i
) = w
->buffer
; ++i
;
7947 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7948 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7953 for (; i
< end
; ++i
)
7954 AREF (vector
, i
) = Qnil
;
7957 xassert (i
== ASIZE (vector
));
7962 /* Restore global state from VECTOR which was created by
7963 with_echo_area_buffer_unwind_data. */
7966 unwind_with_echo_area_buffer (vector
)
7969 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7970 Vdeactivate_mark
= AREF (vector
, 1);
7971 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7973 if (WINDOWP (AREF (vector
, 3)))
7976 Lisp_Object buffer
, charpos
, bytepos
;
7978 w
= XWINDOW (AREF (vector
, 3));
7979 buffer
= AREF (vector
, 4);
7980 charpos
= AREF (vector
, 5);
7981 bytepos
= AREF (vector
, 6);
7984 set_marker_both (w
->pointm
, buffer
,
7985 XFASTINT (charpos
), XFASTINT (bytepos
));
7988 Vwith_echo_area_save_vector
= vector
;
7993 /* Set up the echo area for use by print functions. MULTIBYTE_P
7994 non-zero means we will print multibyte. */
7997 setup_echo_area_for_printing (multibyte_p
)
8000 /* If we can't find an echo area any more, exit. */
8001 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8004 ensure_echo_area_buffers ();
8006 if (!message_buf_print
)
8008 /* A message has been output since the last time we printed.
8009 Choose a fresh echo area buffer. */
8010 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8011 echo_area_buffer
[0] = echo_buffer
[1];
8013 echo_area_buffer
[0] = echo_buffer
[0];
8015 /* Switch to that buffer and clear it. */
8016 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8017 current_buffer
->truncate_lines
= Qnil
;
8021 int count
= SPECPDL_INDEX ();
8022 specbind (Qinhibit_read_only
, Qt
);
8023 /* Note that undo recording is always disabled. */
8025 unbind_to (count
, Qnil
);
8027 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8029 /* Set up the buffer for the multibyteness we need. */
8031 != !NILP (current_buffer
->enable_multibyte_characters
))
8032 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8034 /* Raise the frame containing the echo area. */
8035 if (minibuffer_auto_raise
)
8037 struct frame
*sf
= SELECTED_FRAME ();
8038 Lisp_Object mini_window
;
8039 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8040 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8043 message_log_maybe_newline ();
8044 message_buf_print
= 1;
8048 if (NILP (echo_area_buffer
[0]))
8050 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8051 echo_area_buffer
[0] = echo_buffer
[1];
8053 echo_area_buffer
[0] = echo_buffer
[0];
8056 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8058 /* Someone switched buffers between print requests. */
8059 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8060 current_buffer
->truncate_lines
= Qnil
;
8066 /* Display an echo area message in window W. Value is non-zero if W's
8067 height is changed. If display_last_displayed_message_p is
8068 non-zero, display the message that was last displayed, otherwise
8069 display the current message. */
8072 display_echo_area (w
)
8075 int i
, no_message_p
, window_height_changed_p
, count
;
8077 /* Temporarily disable garbage collections while displaying the echo
8078 area. This is done because a GC can print a message itself.
8079 That message would modify the echo area buffer's contents while a
8080 redisplay of the buffer is going on, and seriously confuse
8082 count
= inhibit_garbage_collection ();
8084 /* If there is no message, we must call display_echo_area_1
8085 nevertheless because it resizes the window. But we will have to
8086 reset the echo_area_buffer in question to nil at the end because
8087 with_echo_area_buffer will sets it to an empty buffer. */
8088 i
= display_last_displayed_message_p
? 1 : 0;
8089 no_message_p
= NILP (echo_area_buffer
[i
]);
8091 window_height_changed_p
8092 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8093 display_echo_area_1
,
8094 (EMACS_INT
) w
, Qnil
, 0, 0);
8097 echo_area_buffer
[i
] = Qnil
;
8099 unbind_to (count
, Qnil
);
8100 return window_height_changed_p
;
8104 /* Helper for display_echo_area. Display the current buffer which
8105 contains the current echo area message in window W, a mini-window,
8106 a pointer to which is passed in A1. A2..A4 are currently not used.
8107 Change the height of W so that all of the message is displayed.
8108 Value is non-zero if height of W was changed. */
8111 display_echo_area_1 (a1
, a2
, a3
, a4
)
8116 struct window
*w
= (struct window
*) a1
;
8118 struct text_pos start
;
8119 int window_height_changed_p
= 0;
8121 /* Do this before displaying, so that we have a large enough glyph
8122 matrix for the display. If we can't get enough space for the
8123 whole text, display the last N lines. That works by setting w->start. */
8124 window_height_changed_p
= resize_mini_window (w
, 0);
8126 /* Use the starting position chosen by resize_mini_window. */
8127 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8130 clear_glyph_matrix (w
->desired_matrix
);
8131 XSETWINDOW (window
, w
);
8132 try_window (window
, start
, 0);
8134 return window_height_changed_p
;
8138 /* Resize the echo area window to exactly the size needed for the
8139 currently displayed message, if there is one. If a mini-buffer
8140 is active, don't shrink it. */
8143 resize_echo_area_exactly ()
8145 if (BUFFERP (echo_area_buffer
[0])
8146 && WINDOWP (echo_area_window
))
8148 struct window
*w
= XWINDOW (echo_area_window
);
8150 Lisp_Object resize_exactly
;
8152 if (minibuf_level
== 0)
8153 resize_exactly
= Qt
;
8155 resize_exactly
= Qnil
;
8157 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8158 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8161 ++windows_or_buffers_changed
;
8162 ++update_mode_lines
;
8163 redisplay_internal (0);
8169 /* Callback function for with_echo_area_buffer, when used from
8170 resize_echo_area_exactly. A1 contains a pointer to the window to
8171 resize, EXACTLY non-nil means resize the mini-window exactly to the
8172 size of the text displayed. A3 and A4 are not used. Value is what
8173 resize_mini_window returns. */
8176 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8178 Lisp_Object exactly
;
8181 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8185 /* Resize mini-window W to fit the size of its contents. EXACT:P
8186 means size the window exactly to the size needed. Otherwise, it's
8187 only enlarged until W's buffer is empty.
8189 Set W->start to the right place to begin display. If the whole
8190 contents fit, start at the beginning. Otherwise, start so as
8191 to make the end of the contents appear. This is particularly
8192 important for y-or-n-p, but seems desirable generally.
8194 Value is non-zero if the window height has been changed. */
8197 resize_mini_window (w
, exact_p
)
8201 struct frame
*f
= XFRAME (w
->frame
);
8202 int window_height_changed_p
= 0;
8204 xassert (MINI_WINDOW_P (w
));
8206 /* By default, start display at the beginning. */
8207 set_marker_both (w
->start
, w
->buffer
,
8208 BUF_BEGV (XBUFFER (w
->buffer
)),
8209 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8211 /* Don't resize windows while redisplaying a window; it would
8212 confuse redisplay functions when the size of the window they are
8213 displaying changes from under them. Such a resizing can happen,
8214 for instance, when which-func prints a long message while
8215 we are running fontification-functions. We're running these
8216 functions with safe_call which binds inhibit-redisplay to t. */
8217 if (!NILP (Vinhibit_redisplay
))
8220 /* Nil means don't try to resize. */
8221 if (NILP (Vresize_mini_windows
)
8222 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8225 if (!FRAME_MINIBUF_ONLY_P (f
))
8228 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8229 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8230 int height
, max_height
;
8231 int unit
= FRAME_LINE_HEIGHT (f
);
8232 struct text_pos start
;
8233 struct buffer
*old_current_buffer
= NULL
;
8235 if (current_buffer
!= XBUFFER (w
->buffer
))
8237 old_current_buffer
= current_buffer
;
8238 set_buffer_internal (XBUFFER (w
->buffer
));
8241 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8243 /* Compute the max. number of lines specified by the user. */
8244 if (FLOATP (Vmax_mini_window_height
))
8245 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8246 else if (INTEGERP (Vmax_mini_window_height
))
8247 max_height
= XINT (Vmax_mini_window_height
);
8249 max_height
= total_height
/ 4;
8251 /* Correct that max. height if it's bogus. */
8252 max_height
= max (1, max_height
);
8253 max_height
= min (total_height
, max_height
);
8255 /* Find out the height of the text in the window. */
8256 if (it
.truncate_lines_p
)
8261 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8262 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8263 height
= it
.current_y
+ last_height
;
8265 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8266 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8267 height
= (height
+ unit
- 1) / unit
;
8270 /* Compute a suitable window start. */
8271 if (height
> max_height
)
8273 height
= max_height
;
8274 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8275 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8276 start
= it
.current
.pos
;
8279 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8280 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8282 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8284 /* Let it grow only, until we display an empty message, in which
8285 case the window shrinks again. */
8286 if (height
> WINDOW_TOTAL_LINES (w
))
8288 int old_height
= WINDOW_TOTAL_LINES (w
);
8289 freeze_window_starts (f
, 1);
8290 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8291 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8293 else if (height
< WINDOW_TOTAL_LINES (w
)
8294 && (exact_p
|| BEGV
== ZV
))
8296 int old_height
= WINDOW_TOTAL_LINES (w
);
8297 freeze_window_starts (f
, 0);
8298 shrink_mini_window (w
);
8299 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8304 /* Always resize to exact size needed. */
8305 if (height
> WINDOW_TOTAL_LINES (w
))
8307 int old_height
= WINDOW_TOTAL_LINES (w
);
8308 freeze_window_starts (f
, 1);
8309 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8310 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8312 else if (height
< WINDOW_TOTAL_LINES (w
))
8314 int old_height
= WINDOW_TOTAL_LINES (w
);
8315 freeze_window_starts (f
, 0);
8316 shrink_mini_window (w
);
8320 freeze_window_starts (f
, 1);
8321 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8324 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8328 if (old_current_buffer
)
8329 set_buffer_internal (old_current_buffer
);
8332 return window_height_changed_p
;
8336 /* Value is the current message, a string, or nil if there is no
8344 if (NILP (echo_area_buffer
[0]))
8348 with_echo_area_buffer (0, 0, current_message_1
,
8349 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8351 echo_area_buffer
[0] = Qnil
;
8359 current_message_1 (a1
, a2
, a3
, a4
)
8364 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8367 *msg
= make_buffer_string (BEG
, Z
, 1);
8374 /* Push the current message on Vmessage_stack for later restauration
8375 by restore_message. Value is non-zero if the current message isn't
8376 empty. This is a relatively infrequent operation, so it's not
8377 worth optimizing. */
8383 msg
= current_message ();
8384 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8385 return STRINGP (msg
);
8389 /* Restore message display from the top of Vmessage_stack. */
8396 xassert (CONSP (Vmessage_stack
));
8397 msg
= XCAR (Vmessage_stack
);
8399 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8401 message3_nolog (msg
, 0, 0);
8405 /* Handler for record_unwind_protect calling pop_message. */
8408 pop_message_unwind (dummy
)
8415 /* Pop the top-most entry off Vmessage_stack. */
8420 xassert (CONSP (Vmessage_stack
));
8421 Vmessage_stack
= XCDR (Vmessage_stack
);
8425 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8426 exits. If the stack is not empty, we have a missing pop_message
8430 check_message_stack ()
8432 if (!NILP (Vmessage_stack
))
8437 /* Truncate to NCHARS what will be displayed in the echo area the next
8438 time we display it---but don't redisplay it now. */
8441 truncate_echo_area (nchars
)
8445 echo_area_buffer
[0] = Qnil
;
8446 /* A null message buffer means that the frame hasn't really been
8447 initialized yet. Error messages get reported properly by
8448 cmd_error, so this must be just an informative message; toss it. */
8449 else if (!noninteractive
8451 && !NILP (echo_area_buffer
[0]))
8453 struct frame
*sf
= SELECTED_FRAME ();
8454 if (FRAME_MESSAGE_BUF (sf
))
8455 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8460 /* Helper function for truncate_echo_area. Truncate the current
8461 message to at most NCHARS characters. */
8464 truncate_message_1 (nchars
, a2
, a3
, a4
)
8469 if (BEG
+ nchars
< Z
)
8470 del_range (BEG
+ nchars
, Z
);
8472 echo_area_buffer
[0] = Qnil
;
8477 /* Set the current message to a substring of S or STRING.
8479 If STRING is a Lisp string, set the message to the first NBYTES
8480 bytes from STRING. NBYTES zero means use the whole string. If
8481 STRING is multibyte, the message will be displayed multibyte.
8483 If S is not null, set the message to the first LEN bytes of S. LEN
8484 zero means use the whole string. MULTIBYTE_P non-zero means S is
8485 multibyte. Display the message multibyte in that case.
8487 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8488 to t before calling set_message_1 (which calls insert).
8492 set_message (s
, string
, nbytes
, multibyte_p
)
8495 int nbytes
, multibyte_p
;
8497 message_enable_multibyte
8498 = ((s
&& multibyte_p
)
8499 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8501 with_echo_area_buffer (0, 0, set_message_1
,
8502 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8503 message_buf_print
= 0;
8504 help_echo_showing_p
= 0;
8508 /* Helper function for set_message. Arguments have the same meaning
8509 as there, with A1 corresponding to S and A2 corresponding to STRING
8510 This function is called with the echo area buffer being
8514 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8517 EMACS_INT nbytes
, multibyte_p
;
8519 const char *s
= (const char *) a1
;
8520 Lisp_Object string
= a2
;
8522 /* Change multibyteness of the echo buffer appropriately. */
8523 if (message_enable_multibyte
8524 != !NILP (current_buffer
->enable_multibyte_characters
))
8525 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8527 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8529 /* Insert new message at BEG. */
8530 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8533 if (STRINGP (string
))
8538 nbytes
= SBYTES (string
);
8539 nchars
= string_byte_to_char (string
, nbytes
);
8541 /* This function takes care of single/multibyte conversion. We
8542 just have to ensure that the echo area buffer has the right
8543 setting of enable_multibyte_characters. */
8544 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8549 nbytes
= strlen (s
);
8551 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8553 /* Convert from multi-byte to single-byte. */
8555 unsigned char work
[1];
8557 /* Convert a multibyte string to single-byte. */
8558 for (i
= 0; i
< nbytes
; i
+= n
)
8560 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8561 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8563 : multibyte_char_to_unibyte (c
, Qnil
));
8564 insert_1_both (work
, 1, 1, 1, 0, 0);
8567 else if (!multibyte_p
8568 && !NILP (current_buffer
->enable_multibyte_characters
))
8570 /* Convert from single-byte to multi-byte. */
8572 const unsigned char *msg
= (const unsigned char *) s
;
8573 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8575 /* Convert a single-byte string to multibyte. */
8576 for (i
= 0; i
< nbytes
; i
++)
8578 c
= unibyte_char_to_multibyte (msg
[i
]);
8579 n
= CHAR_STRING (c
, str
);
8580 insert_1_both (str
, 1, n
, 1, 0, 0);
8584 insert_1 (s
, nbytes
, 1, 0, 0);
8591 /* Clear messages. CURRENT_P non-zero means clear the current
8592 message. LAST_DISPLAYED_P non-zero means clear the message
8596 clear_message (current_p
, last_displayed_p
)
8597 int current_p
, last_displayed_p
;
8601 echo_area_buffer
[0] = Qnil
;
8602 message_cleared_p
= 1;
8605 if (last_displayed_p
)
8606 echo_area_buffer
[1] = Qnil
;
8608 message_buf_print
= 0;
8611 /* Clear garbaged frames.
8613 This function is used where the old redisplay called
8614 redraw_garbaged_frames which in turn called redraw_frame which in
8615 turn called clear_frame. The call to clear_frame was a source of
8616 flickering. I believe a clear_frame is not necessary. It should
8617 suffice in the new redisplay to invalidate all current matrices,
8618 and ensure a complete redisplay of all windows. */
8621 clear_garbaged_frames ()
8625 Lisp_Object tail
, frame
;
8626 int changed_count
= 0;
8628 FOR_EACH_FRAME (tail
, frame
)
8630 struct frame
*f
= XFRAME (frame
);
8632 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8636 Fredraw_frame (frame
);
8637 f
->force_flush_display_p
= 1;
8639 clear_current_matrices (f
);
8648 ++windows_or_buffers_changed
;
8653 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8654 is non-zero update selected_frame. Value is non-zero if the
8655 mini-windows height has been changed. */
8658 echo_area_display (update_frame_p
)
8661 Lisp_Object mini_window
;
8664 int window_height_changed_p
= 0;
8665 struct frame
*sf
= SELECTED_FRAME ();
8667 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8668 w
= XWINDOW (mini_window
);
8669 f
= XFRAME (WINDOW_FRAME (w
));
8671 /* Don't display if frame is invisible or not yet initialized. */
8672 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8675 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8677 #ifdef HAVE_WINDOW_SYSTEM
8678 /* When Emacs starts, selected_frame may be a visible terminal
8679 frame, even if we run under a window system. If we let this
8680 through, a message would be displayed on the terminal. */
8681 if (EQ (selected_frame
, Vterminal_frame
)
8682 && !NILP (Vwindow_system
))
8684 #endif /* HAVE_WINDOW_SYSTEM */
8687 /* Redraw garbaged frames. */
8689 clear_garbaged_frames ();
8691 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8693 echo_area_window
= mini_window
;
8694 window_height_changed_p
= display_echo_area (w
);
8695 w
->must_be_updated_p
= 1;
8697 /* Update the display, unless called from redisplay_internal.
8698 Also don't update the screen during redisplay itself. The
8699 update will happen at the end of redisplay, and an update
8700 here could cause confusion. */
8701 if (update_frame_p
&& !redisplaying_p
)
8705 /* If the display update has been interrupted by pending
8706 input, update mode lines in the frame. Due to the
8707 pending input, it might have been that redisplay hasn't
8708 been called, so that mode lines above the echo area are
8709 garbaged. This looks odd, so we prevent it here. */
8710 if (!display_completed
)
8711 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8713 if (window_height_changed_p
8714 /* Don't do this if Emacs is shutting down. Redisplay
8715 needs to run hooks. */
8716 && !NILP (Vrun_hooks
))
8718 /* Must update other windows. Likewise as in other
8719 cases, don't let this update be interrupted by
8721 int count
= SPECPDL_INDEX ();
8722 specbind (Qredisplay_dont_pause
, Qt
);
8723 windows_or_buffers_changed
= 1;
8724 redisplay_internal (0);
8725 unbind_to (count
, Qnil
);
8727 else if (FRAME_WINDOW_P (f
) && n
== 0)
8729 /* Window configuration is the same as before.
8730 Can do with a display update of the echo area,
8731 unless we displayed some mode lines. */
8732 update_single_window (w
, 1);
8733 rif
->flush_display (f
);
8736 update_frame (f
, 1, 1);
8738 /* If cursor is in the echo area, make sure that the next
8739 redisplay displays the minibuffer, so that the cursor will
8740 be replaced with what the minibuffer wants. */
8741 if (cursor_in_echo_area
)
8742 ++windows_or_buffers_changed
;
8745 else if (!EQ (mini_window
, selected_window
))
8746 windows_or_buffers_changed
++;
8748 /* The current message is now also the last one displayed. */
8749 echo_area_buffer
[1] = echo_area_buffer
[0];
8751 /* Prevent redisplay optimization in redisplay_internal by resetting
8752 this_line_start_pos. This is done because the mini-buffer now
8753 displays the message instead of its buffer text. */
8754 if (EQ (mini_window
, selected_window
))
8755 CHARPOS (this_line_start_pos
) = 0;
8757 return window_height_changed_p
;
8762 /***********************************************************************
8763 Mode Lines and Frame Titles
8764 ***********************************************************************/
8766 /* A buffer for constructing non-propertized mode-line strings and
8767 frame titles in it; allocated from the heap in init_xdisp and
8768 resized as needed in store_mode_line_noprop_char. */
8770 static char *mode_line_noprop_buf
;
8772 /* The buffer's end, and a current output position in it. */
8774 static char *mode_line_noprop_buf_end
;
8775 static char *mode_line_noprop_ptr
;
8777 #define MODE_LINE_NOPROP_LEN(start) \
8778 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8781 MODE_LINE_DISPLAY
= 0,
8787 /* Alist that caches the results of :propertize.
8788 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8789 static Lisp_Object mode_line_proptrans_alist
;
8791 /* List of strings making up the mode-line. */
8792 static Lisp_Object mode_line_string_list
;
8794 /* Base face property when building propertized mode line string. */
8795 static Lisp_Object mode_line_string_face
;
8796 static Lisp_Object mode_line_string_face_prop
;
8799 /* Unwind data for mode line strings */
8801 static Lisp_Object Vmode_line_unwind_vector
;
8804 format_mode_line_unwind_data (obuf
, save_proptrans
)
8805 struct buffer
*obuf
;
8809 /* Reduce consing by keeping one vector in
8810 Vwith_echo_area_save_vector. */
8811 vector
= Vmode_line_unwind_vector
;
8812 Vmode_line_unwind_vector
= Qnil
;
8815 vector
= Fmake_vector (make_number (7), Qnil
);
8817 AREF (vector
, 0) = make_number (mode_line_target
);
8818 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8819 AREF (vector
, 2) = mode_line_string_list
;
8820 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8821 AREF (vector
, 4) = mode_line_string_face
;
8822 AREF (vector
, 5) = mode_line_string_face_prop
;
8825 XSETBUFFER (AREF (vector
, 6), obuf
);
8827 AREF (vector
, 6) = Qnil
;
8833 unwind_format_mode_line (vector
)
8836 mode_line_target
= XINT (AREF (vector
, 0));
8837 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8838 mode_line_string_list
= AREF (vector
, 2);
8839 if (! EQ (AREF (vector
, 3), Qt
))
8840 mode_line_proptrans_alist
= AREF (vector
, 3);
8841 mode_line_string_face
= AREF (vector
, 4);
8842 mode_line_string_face_prop
= AREF (vector
, 5);
8844 if (!NILP (AREF (vector
, 6)))
8846 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8847 AREF (vector
, 6) = Qnil
;
8850 Vmode_line_unwind_vector
= vector
;
8855 /* Store a single character C for the frame title in mode_line_noprop_buf.
8856 Re-allocate mode_line_noprop_buf if necessary. */
8860 store_mode_line_noprop_char (char c
)
8862 store_mode_line_noprop_char (c
)
8866 /* If output position has reached the end of the allocated buffer,
8867 double the buffer's size. */
8868 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8870 int len
= MODE_LINE_NOPROP_LEN (0);
8871 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8872 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8873 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8874 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8877 *mode_line_noprop_ptr
++ = c
;
8881 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8882 mode_line_noprop_ptr. STR is the string to store. Do not copy
8883 characters that yield more columns than PRECISION; PRECISION <= 0
8884 means copy the whole string. Pad with spaces until FIELD_WIDTH
8885 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8886 pad. Called from display_mode_element when it is used to build a
8890 store_mode_line_noprop (str
, field_width
, precision
)
8891 const unsigned char *str
;
8892 int field_width
, precision
;
8897 /* Copy at most PRECISION chars from STR. */
8898 nbytes
= strlen (str
);
8899 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8901 store_mode_line_noprop_char (*str
++);
8903 /* Fill up with spaces until FIELD_WIDTH reached. */
8904 while (field_width
> 0
8907 store_mode_line_noprop_char (' ');
8914 /***********************************************************************
8916 ***********************************************************************/
8918 #ifdef HAVE_WINDOW_SYSTEM
8920 /* Set the title of FRAME, if it has changed. The title format is
8921 Vicon_title_format if FRAME is iconified, otherwise it is
8922 frame_title_format. */
8925 x_consider_frame_title (frame
)
8928 struct frame
*f
= XFRAME (frame
);
8930 if (FRAME_WINDOW_P (f
)
8931 || FRAME_MINIBUF_ONLY_P (f
)
8932 || f
->explicit_name
)
8934 /* Do we have more than one visible frame on this X display? */
8941 int count
= SPECPDL_INDEX ();
8943 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8945 Lisp_Object other_frame
= XCAR (tail
);
8946 struct frame
*tf
= XFRAME (other_frame
);
8949 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8950 && !FRAME_MINIBUF_ONLY_P (tf
)
8951 && !EQ (other_frame
, tip_frame
)
8952 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8956 /* Set global variable indicating that multiple frames exist. */
8957 multiple_frames
= CONSP (tail
);
8959 /* Switch to the buffer of selected window of the frame. Set up
8960 mode_line_target so that display_mode_element will output into
8961 mode_line_noprop_buf; then display the title. */
8962 record_unwind_protect (unwind_format_mode_line
,
8963 format_mode_line_unwind_data (current_buffer
, 0));
8965 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8966 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8968 mode_line_target
= MODE_LINE_TITLE
;
8969 title_start
= MODE_LINE_NOPROP_LEN (0);
8970 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8971 NULL
, DEFAULT_FACE_ID
);
8972 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8973 len
= MODE_LINE_NOPROP_LEN (title_start
);
8974 title
= mode_line_noprop_buf
+ title_start
;
8975 unbind_to (count
, Qnil
);
8977 /* Set the title only if it's changed. This avoids consing in
8978 the common case where it hasn't. (If it turns out that we've
8979 already wasted too much time by walking through the list with
8980 display_mode_element, then we might need to optimize at a
8981 higher level than this.) */
8982 if (! STRINGP (f
->name
)
8983 || SBYTES (f
->name
) != len
8984 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8985 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8989 #endif /* not HAVE_WINDOW_SYSTEM */
8994 /***********************************************************************
8996 ***********************************************************************/
8999 /* Prepare for redisplay by updating menu-bar item lists when
9000 appropriate. This can call eval. */
9003 prepare_menu_bars ()
9006 struct gcpro gcpro1
, gcpro2
;
9008 Lisp_Object tooltip_frame
;
9010 #ifdef HAVE_WINDOW_SYSTEM
9011 tooltip_frame
= tip_frame
;
9013 tooltip_frame
= Qnil
;
9016 /* Update all frame titles based on their buffer names, etc. We do
9017 this before the menu bars so that the buffer-menu will show the
9018 up-to-date frame titles. */
9019 #ifdef HAVE_WINDOW_SYSTEM
9020 if (windows_or_buffers_changed
|| update_mode_lines
)
9022 Lisp_Object tail
, frame
;
9024 FOR_EACH_FRAME (tail
, frame
)
9027 if (!EQ (frame
, tooltip_frame
)
9028 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9029 x_consider_frame_title (frame
);
9032 #endif /* HAVE_WINDOW_SYSTEM */
9034 /* Update the menu bar item lists, if appropriate. This has to be
9035 done before any actual redisplay or generation of display lines. */
9036 all_windows
= (update_mode_lines
9037 || buffer_shared
> 1
9038 || windows_or_buffers_changed
);
9041 Lisp_Object tail
, frame
;
9042 int count
= SPECPDL_INDEX ();
9043 /* 1 means that update_menu_bar has run its hooks
9044 so any further calls to update_menu_bar shouldn't do so again. */
9045 int menu_bar_hooks_run
= 0;
9047 record_unwind_save_match_data ();
9049 FOR_EACH_FRAME (tail
, frame
)
9053 /* Ignore tooltip frame. */
9054 if (EQ (frame
, tooltip_frame
))
9057 /* If a window on this frame changed size, report that to
9058 the user and clear the size-change flag. */
9059 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9061 Lisp_Object functions
;
9063 /* Clear flag first in case we get an error below. */
9064 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9065 functions
= Vwindow_size_change_functions
;
9066 GCPRO2 (tail
, functions
);
9068 while (CONSP (functions
))
9070 call1 (XCAR (functions
), frame
);
9071 functions
= XCDR (functions
);
9077 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9078 #ifdef HAVE_WINDOW_SYSTEM
9079 update_tool_bar (f
, 0);
9081 mac_update_title_bar (f
, 0);
9087 unbind_to (count
, Qnil
);
9091 struct frame
*sf
= SELECTED_FRAME ();
9092 update_menu_bar (sf
, 1, 0);
9093 #ifdef HAVE_WINDOW_SYSTEM
9094 update_tool_bar (sf
, 1);
9096 mac_update_title_bar (sf
, 1);
9101 /* Motif needs this. See comment in xmenu.c. Turn it off when
9102 pending_menu_activation is not defined. */
9103 #ifdef USE_X_TOOLKIT
9104 pending_menu_activation
= 0;
9109 /* Update the menu bar item list for frame F. This has to be done
9110 before we start to fill in any display lines, because it can call
9113 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9115 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9116 already ran the menu bar hooks for this redisplay, so there
9117 is no need to run them again. The return value is the
9118 updated value of this flag, to pass to the next call. */
9121 update_menu_bar (f
, save_match_data
, hooks_run
)
9123 int save_match_data
;
9127 register struct window
*w
;
9129 /* If called recursively during a menu update, do nothing. This can
9130 happen when, for instance, an activate-menubar-hook causes a
9132 if (inhibit_menubar_update
)
9135 window
= FRAME_SELECTED_WINDOW (f
);
9136 w
= XWINDOW (window
);
9138 #if 0 /* The if statement below this if statement used to include the
9139 condition !NILP (w->update_mode_line), rather than using
9140 update_mode_lines directly, and this if statement may have
9141 been added to make that condition work. Now the if
9142 statement below matches its comment, this isn't needed. */
9143 if (update_mode_lines
)
9144 w
->update_mode_line
= Qt
;
9147 if (FRAME_WINDOW_P (f
)
9149 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9150 || defined (USE_GTK)
9151 FRAME_EXTERNAL_MENU_BAR (f
)
9153 FRAME_MENU_BAR_LINES (f
) > 0
9155 : FRAME_MENU_BAR_LINES (f
) > 0)
9157 /* If the user has switched buffers or windows, we need to
9158 recompute to reflect the new bindings. But we'll
9159 recompute when update_mode_lines is set too; that means
9160 that people can use force-mode-line-update to request
9161 that the menu bar be recomputed. The adverse effect on
9162 the rest of the redisplay algorithm is about the same as
9163 windows_or_buffers_changed anyway. */
9164 if (windows_or_buffers_changed
9165 /* This used to test w->update_mode_line, but we believe
9166 there is no need to recompute the menu in that case. */
9167 || update_mode_lines
9168 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9169 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9170 != !NILP (w
->last_had_star
))
9171 || ((!NILP (Vtransient_mark_mode
)
9172 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9173 != !NILP (w
->region_showing
)))
9175 struct buffer
*prev
= current_buffer
;
9176 int count
= SPECPDL_INDEX ();
9178 specbind (Qinhibit_menubar_update
, Qt
);
9180 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9181 if (save_match_data
)
9182 record_unwind_save_match_data ();
9183 if (NILP (Voverriding_local_map_menu_flag
))
9185 specbind (Qoverriding_terminal_local_map
, Qnil
);
9186 specbind (Qoverriding_local_map
, Qnil
);
9191 /* Run the Lucid hook. */
9192 safe_run_hooks (Qactivate_menubar_hook
);
9194 /* If it has changed current-menubar from previous value,
9195 really recompute the menu-bar from the value. */
9196 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9197 call0 (Qrecompute_lucid_menubar
);
9199 safe_run_hooks (Qmenu_bar_update_hook
);
9204 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9206 /* Redisplay the menu bar in case we changed it. */
9207 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9208 || defined (USE_GTK)
9209 if (FRAME_WINDOW_P (f
))
9212 /* All frames on Mac OS share the same menubar. So only
9213 the selected frame should be allowed to set it. */
9214 if (f
== SELECTED_FRAME ())
9216 set_frame_menubar (f
, 0, 0);
9219 /* On a terminal screen, the menu bar is an ordinary screen
9220 line, and this makes it get updated. */
9221 w
->update_mode_line
= Qt
;
9222 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9223 /* In the non-toolkit version, the menu bar is an ordinary screen
9224 line, and this makes it get updated. */
9225 w
->update_mode_line
= Qt
;
9226 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9228 unbind_to (count
, Qnil
);
9229 set_buffer_internal_1 (prev
);
9238 /***********************************************************************
9240 ***********************************************************************/
9242 #ifdef HAVE_WINDOW_SYSTEM
9245 Nominal cursor position -- where to draw output.
9246 HPOS and VPOS are window relative glyph matrix coordinates.
9247 X and Y are window relative pixel coordinates. */
9249 struct cursor_pos output_cursor
;
9253 Set the global variable output_cursor to CURSOR. All cursor
9254 positions are relative to updated_window. */
9257 set_output_cursor (cursor
)
9258 struct cursor_pos
*cursor
;
9260 output_cursor
.hpos
= cursor
->hpos
;
9261 output_cursor
.vpos
= cursor
->vpos
;
9262 output_cursor
.x
= cursor
->x
;
9263 output_cursor
.y
= cursor
->y
;
9268 Set a nominal cursor position.
9270 HPOS and VPOS are column/row positions in a window glyph matrix. X
9271 and Y are window text area relative pixel positions.
9273 If this is done during an update, updated_window will contain the
9274 window that is being updated and the position is the future output
9275 cursor position for that window. If updated_window is null, use
9276 selected_window and display the cursor at the given position. */
9279 x_cursor_to (vpos
, hpos
, y
, x
)
9280 int vpos
, hpos
, y
, x
;
9284 /* If updated_window is not set, work on selected_window. */
9288 w
= XWINDOW (selected_window
);
9290 /* Set the output cursor. */
9291 output_cursor
.hpos
= hpos
;
9292 output_cursor
.vpos
= vpos
;
9293 output_cursor
.x
= x
;
9294 output_cursor
.y
= y
;
9296 /* If not called as part of an update, really display the cursor.
9297 This will also set the cursor position of W. */
9298 if (updated_window
== NULL
)
9301 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9302 if (rif
->flush_display_optional
)
9303 rif
->flush_display_optional (SELECTED_FRAME ());
9308 #endif /* HAVE_WINDOW_SYSTEM */
9311 /***********************************************************************
9313 ***********************************************************************/
9315 #ifdef HAVE_WINDOW_SYSTEM
9317 /* Where the mouse was last time we reported a mouse event. */
9319 FRAME_PTR last_mouse_frame
;
9321 /* Tool-bar item index of the item on which a mouse button was pressed
9324 int last_tool_bar_item
;
9327 /* Update the tool-bar item list for frame F. This has to be done
9328 before we start to fill in any display lines. Called from
9329 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9330 and restore it here. */
9333 update_tool_bar (f
, save_match_data
)
9335 int save_match_data
;
9338 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9340 int do_update
= WINDOWP (f
->tool_bar_window
)
9341 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9349 window
= FRAME_SELECTED_WINDOW (f
);
9350 w
= XWINDOW (window
);
9352 /* If the user has switched buffers or windows, we need to
9353 recompute to reflect the new bindings. But we'll
9354 recompute when update_mode_lines is set too; that means
9355 that people can use force-mode-line-update to request
9356 that the menu bar be recomputed. The adverse effect on
9357 the rest of the redisplay algorithm is about the same as
9358 windows_or_buffers_changed anyway. */
9359 if (windows_or_buffers_changed
9360 || !NILP (w
->update_mode_line
)
9361 || update_mode_lines
9362 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9363 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9364 != !NILP (w
->last_had_star
))
9365 || ((!NILP (Vtransient_mark_mode
)
9366 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9367 != !NILP (w
->region_showing
)))
9369 struct buffer
*prev
= current_buffer
;
9370 int count
= SPECPDL_INDEX ();
9371 Lisp_Object new_tool_bar
;
9373 struct gcpro gcpro1
;
9375 /* Set current_buffer to the buffer of the selected
9376 window of the frame, so that we get the right local
9378 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9380 /* Save match data, if we must. */
9381 if (save_match_data
)
9382 record_unwind_save_match_data ();
9384 /* Make sure that we don't accidentally use bogus keymaps. */
9385 if (NILP (Voverriding_local_map_menu_flag
))
9387 specbind (Qoverriding_terminal_local_map
, Qnil
);
9388 specbind (Qoverriding_local_map
, Qnil
);
9391 GCPRO1 (new_tool_bar
);
9393 /* Build desired tool-bar items from keymaps. */
9394 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9397 /* Redisplay the tool-bar if we changed it. */
9398 if (new_n_tool_bar
!= f
->n_tool_bar_items
9399 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9401 /* Redisplay that happens asynchronously due to an expose event
9402 may access f->tool_bar_items. Make sure we update both
9403 variables within BLOCK_INPUT so no such event interrupts. */
9405 f
->tool_bar_items
= new_tool_bar
;
9406 f
->n_tool_bar_items
= new_n_tool_bar
;
9407 w
->update_mode_line
= Qt
;
9413 unbind_to (count
, Qnil
);
9414 set_buffer_internal_1 (prev
);
9420 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9421 F's desired tool-bar contents. F->tool_bar_items must have
9422 been set up previously by calling prepare_menu_bars. */
9425 build_desired_tool_bar_string (f
)
9428 int i
, size
, size_needed
;
9429 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9430 Lisp_Object image
, plist
, props
;
9432 image
= plist
= props
= Qnil
;
9433 GCPRO3 (image
, plist
, props
);
9435 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9436 Otherwise, make a new string. */
9438 /* The size of the string we might be able to reuse. */
9439 size
= (STRINGP (f
->desired_tool_bar_string
)
9440 ? SCHARS (f
->desired_tool_bar_string
)
9443 /* We need one space in the string for each image. */
9444 size_needed
= f
->n_tool_bar_items
;
9446 /* Reuse f->desired_tool_bar_string, if possible. */
9447 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9448 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9452 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9453 Fremove_text_properties (make_number (0), make_number (size
),
9454 props
, f
->desired_tool_bar_string
);
9457 /* Put a `display' property on the string for the images to display,
9458 put a `menu_item' property on tool-bar items with a value that
9459 is the index of the item in F's tool-bar item vector. */
9460 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9462 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9464 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9465 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9466 int hmargin
, vmargin
, relief
, idx
, end
;
9467 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9469 /* If image is a vector, choose the image according to the
9471 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9472 if (VECTORP (image
))
9476 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9477 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9480 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9481 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9483 xassert (ASIZE (image
) >= idx
);
9484 image
= AREF (image
, idx
);
9489 /* Ignore invalid image specifications. */
9490 if (!valid_image_p (image
))
9493 /* Display the tool-bar button pressed, or depressed. */
9494 plist
= Fcopy_sequence (XCDR (image
));
9496 /* Compute margin and relief to draw. */
9497 relief
= (tool_bar_button_relief
>= 0
9498 ? tool_bar_button_relief
9499 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9500 hmargin
= vmargin
= relief
;
9502 if (INTEGERP (Vtool_bar_button_margin
)
9503 && XINT (Vtool_bar_button_margin
) > 0)
9505 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9506 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9508 else if (CONSP (Vtool_bar_button_margin
))
9510 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9511 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9512 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9514 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9515 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9516 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9519 if (auto_raise_tool_bar_buttons_p
)
9521 /* Add a `:relief' property to the image spec if the item is
9525 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9532 /* If image is selected, display it pressed, i.e. with a
9533 negative relief. If it's not selected, display it with a
9535 plist
= Fplist_put (plist
, QCrelief
,
9537 ? make_number (-relief
)
9538 : make_number (relief
)));
9543 /* Put a margin around the image. */
9544 if (hmargin
|| vmargin
)
9546 if (hmargin
== vmargin
)
9547 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9549 plist
= Fplist_put (plist
, QCmargin
,
9550 Fcons (make_number (hmargin
),
9551 make_number (vmargin
)));
9554 /* If button is not enabled, and we don't have special images
9555 for the disabled state, make the image appear disabled by
9556 applying an appropriate algorithm to it. */
9557 if (!enabled_p
&& idx
< 0)
9558 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9560 /* Put a `display' text property on the string for the image to
9561 display. Put a `menu-item' property on the string that gives
9562 the start of this item's properties in the tool-bar items
9564 image
= Fcons (Qimage
, plist
);
9565 props
= list4 (Qdisplay
, image
,
9566 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9568 /* Let the last image hide all remaining spaces in the tool bar
9569 string. The string can be longer than needed when we reuse a
9571 if (i
+ 1 == f
->n_tool_bar_items
)
9572 end
= SCHARS (f
->desired_tool_bar_string
);
9575 Fadd_text_properties (make_number (i
), make_number (end
),
9576 props
, f
->desired_tool_bar_string
);
9584 /* Display one line of the tool-bar of frame IT->f.
9586 HEIGHT specifies the desired height of the tool-bar line.
9587 If the actual height of the glyph row is less than HEIGHT, the
9588 row's height is increased to HEIGHT, and the icons are centered
9589 vertically in the new height.
9591 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9592 count a final empty row in case the tool-bar width exactly matches
9597 display_tool_bar_line (it
, height
)
9601 struct glyph_row
*row
= it
->glyph_row
;
9602 int max_x
= it
->last_visible_x
;
9605 prepare_desired_row (row
);
9606 row
->y
= it
->current_y
;
9608 /* Note that this isn't made use of if the face hasn't a box,
9609 so there's no need to check the face here. */
9610 it
->start_of_box_run_p
= 1;
9612 while (it
->current_x
< max_x
)
9614 int x
, n_glyphs_before
, i
, nglyphs
;
9615 struct it it_before
;
9617 /* Get the next display element. */
9618 if (!get_next_display_element (it
))
9620 /* Don't count empty row if we are counting needed tool-bar lines. */
9621 if (height
< 0 && !it
->hpos
)
9626 /* Produce glyphs. */
9627 n_glyphs_before
= row
->used
[TEXT_AREA
];
9630 PRODUCE_GLYPHS (it
);
9632 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9634 x
= it_before
.current_x
;
9637 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9639 if (x
+ glyph
->pixel_width
> max_x
)
9641 /* Glyph doesn't fit on line. Backtrack. */
9642 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9644 /* If this is the only glyph on this line, it will never fit on the
9645 toolbar, so skip it. But ensure there is at least one glyph,
9646 so we don't accidentally disable the tool-bar. */
9647 if (n_glyphs_before
== 0
9648 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9654 x
+= glyph
->pixel_width
;
9658 /* Stop at line ends. */
9659 if (ITERATOR_AT_END_OF_LINE_P (it
))
9662 set_iterator_to_next (it
, 1);
9667 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9668 /* Use default face for the border below the tool bar. */
9669 if (!row
->displays_text_p
)
9670 it
->face_id
= DEFAULT_FACE_ID
;
9671 extend_face_to_end_of_line (it
);
9672 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9673 last
->right_box_line_p
= 1;
9674 if (last
== row
->glyphs
[TEXT_AREA
])
9675 last
->left_box_line_p
= 1;
9677 /* Make line the desired height and center it vertically. */
9678 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9680 /* Don't add more than one line height. */
9681 height
%= FRAME_LINE_HEIGHT (it
->f
);
9682 it
->max_ascent
+= height
/ 2;
9683 it
->max_descent
+= (height
+ 1) / 2;
9686 compute_line_metrics (it
);
9688 /* If line is empty, make it occupy the rest of the tool-bar. */
9689 if (!row
->displays_text_p
)
9691 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9692 row
->ascent
= row
->phys_ascent
= 0;
9693 row
->extra_line_spacing
= 0;
9696 row
->full_width_p
= 1;
9697 row
->continued_p
= 0;
9698 row
->truncated_on_left_p
= 0;
9699 row
->truncated_on_right_p
= 0;
9701 it
->current_x
= it
->hpos
= 0;
9702 it
->current_y
+= row
->height
;
9708 /* Max tool-bar height. */
9710 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9711 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9713 /* Value is the number of screen lines needed to make all tool-bar
9714 items of frame F visible. The number of actual rows needed is
9715 returned in *N_ROWS if non-NULL. */
9718 tool_bar_lines_needed (f
, n_rows
)
9722 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9724 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9725 the desired matrix, so use (unused) mode-line row as temporary row to
9726 avoid destroying the first tool-bar row. */
9727 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9729 /* Initialize an iterator for iteration over
9730 F->desired_tool_bar_string in the tool-bar window of frame F. */
9731 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9732 it
.first_visible_x
= 0;
9733 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9734 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9736 while (!ITERATOR_AT_END_P (&it
))
9738 clear_glyph_row (temp_row
);
9739 it
.glyph_row
= temp_row
;
9740 display_tool_bar_line (&it
, -1);
9742 clear_glyph_row (temp_row
);
9744 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9746 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9748 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9752 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9754 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9763 frame
= selected_frame
;
9765 CHECK_FRAME (frame
);
9768 if (WINDOWP (f
->tool_bar_window
)
9769 || (w
= XWINDOW (f
->tool_bar_window
),
9770 WINDOW_TOTAL_LINES (w
) > 0))
9772 update_tool_bar (f
, 1);
9773 if (f
->n_tool_bar_items
)
9775 build_desired_tool_bar_string (f
);
9776 nlines
= tool_bar_lines_needed (f
, NULL
);
9780 return make_number (nlines
);
9784 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9785 height should be changed. */
9788 redisplay_tool_bar (f
)
9793 struct glyph_row
*row
;
9794 int change_height_p
= 0;
9797 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9798 update_frame_tool_bar (f
);
9802 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9803 do anything. This means you must start with tool-bar-lines
9804 non-zero to get the auto-sizing effect. Or in other words, you
9805 can turn off tool-bars by specifying tool-bar-lines zero. */
9806 if (!WINDOWP (f
->tool_bar_window
)
9807 || (w
= XWINDOW (f
->tool_bar_window
),
9808 WINDOW_TOTAL_LINES (w
) == 0))
9811 /* Set up an iterator for the tool-bar window. */
9812 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9813 it
.first_visible_x
= 0;
9814 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9817 /* Build a string that represents the contents of the tool-bar. */
9818 build_desired_tool_bar_string (f
);
9819 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9821 if (f
->n_tool_bar_rows
== 0)
9825 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9826 nlines
!= WINDOW_TOTAL_LINES (w
)))
9828 extern Lisp_Object Qtool_bar_lines
;
9830 int old_height
= WINDOW_TOTAL_LINES (w
);
9832 XSETFRAME (frame
, f
);
9833 Fmodify_frame_parameters (frame
,
9834 Fcons (Fcons (Qtool_bar_lines
,
9835 make_number (nlines
)),
9837 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9839 clear_glyph_matrix (w
->desired_matrix
);
9840 fonts_changed_p
= 1;
9846 /* Display as many lines as needed to display all tool-bar items. */
9848 if (f
->n_tool_bar_rows
> 0)
9850 int border
, rows
, height
, extra
;
9852 if (INTEGERP (Vtool_bar_border
))
9853 border
= XINT (Vtool_bar_border
);
9854 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9855 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9856 else if (EQ (Vtool_bar_border
, Qborder_width
))
9857 border
= f
->border_width
;
9863 rows
= f
->n_tool_bar_rows
;
9864 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9865 extra
= it
.last_visible_y
- border
- height
* rows
;
9867 while (it
.current_y
< it
.last_visible_y
)
9870 if (extra
> 0 && rows
-- > 0)
9872 h
= (extra
+ rows
- 1) / rows
;
9875 display_tool_bar_line (&it
, height
+ h
);
9880 while (it
.current_y
< it
.last_visible_y
)
9881 display_tool_bar_line (&it
, 0);
9884 /* It doesn't make much sense to try scrolling in the tool-bar
9885 window, so don't do it. */
9886 w
->desired_matrix
->no_scrolling_p
= 1;
9887 w
->must_be_updated_p
= 1;
9889 if (auto_resize_tool_bars_p
)
9892 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
9894 /* If we couldn't display everything, change the tool-bar's
9895 height if there is room for more. */
9896 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
9897 && it
.current_y
< max_tool_bar_height
)
9898 change_height_p
= 1;
9900 row
= it
.glyph_row
- 1;
9902 /* If there are blank lines at the end, except for a partially
9903 visible blank line at the end that is smaller than
9904 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9905 if (!row
->displays_text_p
9906 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9907 change_height_p
= 1;
9909 /* If row displays tool-bar items, but is partially visible,
9910 change the tool-bar's height. */
9911 if (row
->displays_text_p
9912 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
9913 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
9914 change_height_p
= 1;
9916 /* Resize windows as needed by changing the `tool-bar-lines'
9919 && (nlines
= tool_bar_lines_needed (f
, &nrows
),
9920 nlines
!= WINDOW_TOTAL_LINES (w
)))
9922 extern Lisp_Object Qtool_bar_lines
;
9924 int old_height
= WINDOW_TOTAL_LINES (w
);
9926 XSETFRAME (frame
, f
);
9927 Fmodify_frame_parameters (frame
,
9928 Fcons (Fcons (Qtool_bar_lines
,
9929 make_number (nlines
)),
9931 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9933 clear_glyph_matrix (w
->desired_matrix
);
9934 f
->n_tool_bar_rows
= nrows
;
9935 fonts_changed_p
= 1;
9940 return change_height_p
;
9944 /* Get information about the tool-bar item which is displayed in GLYPH
9945 on frame F. Return in *PROP_IDX the index where tool-bar item
9946 properties start in F->tool_bar_items. Value is zero if
9947 GLYPH doesn't display a tool-bar item. */
9950 tool_bar_item_info (f
, glyph
, prop_idx
)
9952 struct glyph
*glyph
;
9959 /* This function can be called asynchronously, which means we must
9960 exclude any possibility that Fget_text_property signals an
9962 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9963 charpos
= max (0, charpos
);
9965 /* Get the text property `menu-item' at pos. The value of that
9966 property is the start index of this item's properties in
9967 F->tool_bar_items. */
9968 prop
= Fget_text_property (make_number (charpos
),
9969 Qmenu_item
, f
->current_tool_bar_string
);
9970 if (INTEGERP (prop
))
9972 *prop_idx
= XINT (prop
);
9982 /* Get information about the tool-bar item at position X/Y on frame F.
9983 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9984 the current matrix of the tool-bar window of F, or NULL if not
9985 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9986 item in F->tool_bar_items. Value is
9988 -1 if X/Y is not on a tool-bar item
9989 0 if X/Y is on the same item that was highlighted before.
9993 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9996 struct glyph
**glyph
;
9997 int *hpos
, *vpos
, *prop_idx
;
9999 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10000 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10003 /* Find the glyph under X/Y. */
10004 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10005 if (*glyph
== NULL
)
10008 /* Get the start of this tool-bar item's properties in
10009 f->tool_bar_items. */
10010 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10013 /* Is mouse on the highlighted item? */
10014 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10015 && *vpos
>= dpyinfo
->mouse_face_beg_row
10016 && *vpos
<= dpyinfo
->mouse_face_end_row
10017 && (*vpos
> dpyinfo
->mouse_face_beg_row
10018 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10019 && (*vpos
< dpyinfo
->mouse_face_end_row
10020 || *hpos
< dpyinfo
->mouse_face_end_col
10021 || dpyinfo
->mouse_face_past_end
))
10029 Handle mouse button event on the tool-bar of frame F, at
10030 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10031 0 for button release. MODIFIERS is event modifiers for button
10035 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10038 unsigned int modifiers
;
10040 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10041 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10042 int hpos
, vpos
, prop_idx
;
10043 struct glyph
*glyph
;
10044 Lisp_Object enabled_p
;
10046 /* If not on the highlighted tool-bar item, return. */
10047 frame_to_window_pixel_xy (w
, &x
, &y
);
10048 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10051 /* If item is disabled, do nothing. */
10052 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10053 if (NILP (enabled_p
))
10058 /* Show item in pressed state. */
10059 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10060 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10061 last_tool_bar_item
= prop_idx
;
10065 Lisp_Object key
, frame
;
10066 struct input_event event
;
10067 EVENT_INIT (event
);
10069 /* Show item in released state. */
10070 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10071 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10073 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10075 XSETFRAME (frame
, f
);
10076 event
.kind
= TOOL_BAR_EVENT
;
10077 event
.frame_or_window
= frame
;
10079 kbd_buffer_store_event (&event
);
10081 event
.kind
= TOOL_BAR_EVENT
;
10082 event
.frame_or_window
= frame
;
10084 event
.modifiers
= modifiers
;
10085 kbd_buffer_store_event (&event
);
10086 last_tool_bar_item
= -1;
10091 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10092 tool-bar window-relative coordinates X/Y. Called from
10093 note_mouse_highlight. */
10096 note_tool_bar_highlight (f
, x
, y
)
10100 Lisp_Object window
= f
->tool_bar_window
;
10101 struct window
*w
= XWINDOW (window
);
10102 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10104 struct glyph
*glyph
;
10105 struct glyph_row
*row
;
10107 Lisp_Object enabled_p
;
10109 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10110 int mouse_down_p
, rc
;
10112 /* Function note_mouse_highlight is called with negative x(y
10113 values when mouse moves outside of the frame. */
10114 if (x
<= 0 || y
<= 0)
10116 clear_mouse_face (dpyinfo
);
10120 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10123 /* Not on tool-bar item. */
10124 clear_mouse_face (dpyinfo
);
10128 /* On same tool-bar item as before. */
10129 goto set_help_echo
;
10131 clear_mouse_face (dpyinfo
);
10133 /* Mouse is down, but on different tool-bar item? */
10134 mouse_down_p
= (dpyinfo
->grabbed
10135 && f
== last_mouse_frame
10136 && FRAME_LIVE_P (f
));
10138 && last_tool_bar_item
!= prop_idx
)
10141 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10142 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10144 /* If tool-bar item is not enabled, don't highlight it. */
10145 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10146 if (!NILP (enabled_p
))
10148 /* Compute the x-position of the glyph. In front and past the
10149 image is a space. We include this in the highlighted area. */
10150 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10151 for (i
= x
= 0; i
< hpos
; ++i
)
10152 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10154 /* Record this as the current active region. */
10155 dpyinfo
->mouse_face_beg_col
= hpos
;
10156 dpyinfo
->mouse_face_beg_row
= vpos
;
10157 dpyinfo
->mouse_face_beg_x
= x
;
10158 dpyinfo
->mouse_face_beg_y
= row
->y
;
10159 dpyinfo
->mouse_face_past_end
= 0;
10161 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10162 dpyinfo
->mouse_face_end_row
= vpos
;
10163 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10164 dpyinfo
->mouse_face_end_y
= row
->y
;
10165 dpyinfo
->mouse_face_window
= window
;
10166 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10168 /* Display it as active. */
10169 show_mouse_face (dpyinfo
, draw
);
10170 dpyinfo
->mouse_face_image_state
= draw
;
10175 /* Set help_echo_string to a help string to display for this tool-bar item.
10176 XTread_socket does the rest. */
10177 help_echo_object
= help_echo_window
= Qnil
;
10178 help_echo_pos
= -1;
10179 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10180 if (NILP (help_echo_string
))
10181 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10184 #endif /* HAVE_WINDOW_SYSTEM */
10188 /************************************************************************
10189 Horizontal scrolling
10190 ************************************************************************/
10192 static int hscroll_window_tree
P_ ((Lisp_Object
));
10193 static int hscroll_windows
P_ ((Lisp_Object
));
10195 /* For all leaf windows in the window tree rooted at WINDOW, set their
10196 hscroll value so that PT is (i) visible in the window, and (ii) so
10197 that it is not within a certain margin at the window's left and
10198 right border. Value is non-zero if any window's hscroll has been
10202 hscroll_window_tree (window
)
10203 Lisp_Object window
;
10205 int hscrolled_p
= 0;
10206 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10207 int hscroll_step_abs
= 0;
10208 double hscroll_step_rel
= 0;
10210 if (hscroll_relative_p
)
10212 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10213 if (hscroll_step_rel
< 0)
10215 hscroll_relative_p
= 0;
10216 hscroll_step_abs
= 0;
10219 else if (INTEGERP (Vhscroll_step
))
10221 hscroll_step_abs
= XINT (Vhscroll_step
);
10222 if (hscroll_step_abs
< 0)
10223 hscroll_step_abs
= 0;
10226 hscroll_step_abs
= 0;
10228 while (WINDOWP (window
))
10230 struct window
*w
= XWINDOW (window
);
10232 if (WINDOWP (w
->hchild
))
10233 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10234 else if (WINDOWP (w
->vchild
))
10235 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10236 else if (w
->cursor
.vpos
>= 0)
10239 int text_area_width
;
10240 struct glyph_row
*current_cursor_row
10241 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10242 struct glyph_row
*desired_cursor_row
10243 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10244 struct glyph_row
*cursor_row
10245 = (desired_cursor_row
->enabled_p
10246 ? desired_cursor_row
10247 : current_cursor_row
);
10249 text_area_width
= window_box_width (w
, TEXT_AREA
);
10251 /* Scroll when cursor is inside this scroll margin. */
10252 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10254 if ((XFASTINT (w
->hscroll
)
10255 && w
->cursor
.x
<= h_margin
)
10256 || (cursor_row
->enabled_p
10257 && cursor_row
->truncated_on_right_p
10258 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10262 struct buffer
*saved_current_buffer
;
10266 /* Find point in a display of infinite width. */
10267 saved_current_buffer
= current_buffer
;
10268 current_buffer
= XBUFFER (w
->buffer
);
10270 if (w
== XWINDOW (selected_window
))
10271 pt
= BUF_PT (current_buffer
);
10274 pt
= marker_position (w
->pointm
);
10275 pt
= max (BEGV
, pt
);
10279 /* Move iterator to pt starting at cursor_row->start in
10280 a line with infinite width. */
10281 init_to_row_start (&it
, w
, cursor_row
);
10282 it
.last_visible_x
= INFINITY
;
10283 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10284 current_buffer
= saved_current_buffer
;
10286 /* Position cursor in window. */
10287 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10288 hscroll
= max (0, (it
.current_x
10289 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10290 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10291 : (text_area_width
/ 2))))
10292 / FRAME_COLUMN_WIDTH (it
.f
);
10293 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10295 if (hscroll_relative_p
)
10296 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10299 wanted_x
= text_area_width
10300 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10303 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10307 if (hscroll_relative_p
)
10308 wanted_x
= text_area_width
* hscroll_step_rel
10311 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10314 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10316 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10318 /* Don't call Fset_window_hscroll if value hasn't
10319 changed because it will prevent redisplay
10321 if (XFASTINT (w
->hscroll
) != hscroll
)
10323 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10324 w
->hscroll
= make_number (hscroll
);
10333 /* Value is non-zero if hscroll of any leaf window has been changed. */
10334 return hscrolled_p
;
10338 /* Set hscroll so that cursor is visible and not inside horizontal
10339 scroll margins for all windows in the tree rooted at WINDOW. See
10340 also hscroll_window_tree above. Value is non-zero if any window's
10341 hscroll has been changed. If it has, desired matrices on the frame
10342 of WINDOW are cleared. */
10345 hscroll_windows (window
)
10346 Lisp_Object window
;
10350 if (automatic_hscrolling_p
)
10352 hscrolled_p
= hscroll_window_tree (window
);
10354 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10358 return hscrolled_p
;
10363 /************************************************************************
10365 ************************************************************************/
10367 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10368 to a non-zero value. This is sometimes handy to have in a debugger
10373 /* First and last unchanged row for try_window_id. */
10375 int debug_first_unchanged_at_end_vpos
;
10376 int debug_last_unchanged_at_beg_vpos
;
10378 /* Delta vpos and y. */
10380 int debug_dvpos
, debug_dy
;
10382 /* Delta in characters and bytes for try_window_id. */
10384 int debug_delta
, debug_delta_bytes
;
10386 /* Values of window_end_pos and window_end_vpos at the end of
10389 EMACS_INT debug_end_pos
, debug_end_vpos
;
10391 /* Append a string to W->desired_matrix->method. FMT is a printf
10392 format string. A1...A9 are a supplement for a variable-length
10393 argument list. If trace_redisplay_p is non-zero also printf the
10394 resulting string to stderr. */
10397 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10400 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10403 char *method
= w
->desired_matrix
->method
;
10404 int len
= strlen (method
);
10405 int size
= sizeof w
->desired_matrix
->method
;
10406 int remaining
= size
- len
- 1;
10408 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10409 if (len
&& remaining
)
10412 --remaining
, ++len
;
10415 strncpy (method
+ len
, buffer
, remaining
);
10417 if (trace_redisplay_p
)
10418 fprintf (stderr
, "%p (%s): %s\n",
10420 ((BUFFERP (w
->buffer
)
10421 && STRINGP (XBUFFER (w
->buffer
)->name
))
10422 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10427 #endif /* GLYPH_DEBUG */
10430 /* Value is non-zero if all changes in window W, which displays
10431 current_buffer, are in the text between START and END. START is a
10432 buffer position, END is given as a distance from Z. Used in
10433 redisplay_internal for display optimization. */
10436 text_outside_line_unchanged_p (w
, start
, end
)
10440 int unchanged_p
= 1;
10442 /* If text or overlays have changed, see where. */
10443 if (XFASTINT (w
->last_modified
) < MODIFF
10444 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10446 /* Gap in the line? */
10447 if (GPT
< start
|| Z
- GPT
< end
)
10450 /* Changes start in front of the line, or end after it? */
10452 && (BEG_UNCHANGED
< start
- 1
10453 || END_UNCHANGED
< end
))
10456 /* If selective display, can't optimize if changes start at the
10457 beginning of the line. */
10459 && INTEGERP (current_buffer
->selective_display
)
10460 && XINT (current_buffer
->selective_display
) > 0
10461 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10464 /* If there are overlays at the start or end of the line, these
10465 may have overlay strings with newlines in them. A change at
10466 START, for instance, may actually concern the display of such
10467 overlay strings as well, and they are displayed on different
10468 lines. So, quickly rule out this case. (For the future, it
10469 might be desirable to implement something more telling than
10470 just BEG/END_UNCHANGED.) */
10473 if (BEG
+ BEG_UNCHANGED
== start
10474 && overlay_touches_p (start
))
10476 if (END_UNCHANGED
== end
10477 && overlay_touches_p (Z
- end
))
10482 return unchanged_p
;
10486 /* Do a frame update, taking possible shortcuts into account. This is
10487 the main external entry point for redisplay.
10489 If the last redisplay displayed an echo area message and that message
10490 is no longer requested, we clear the echo area or bring back the
10491 mini-buffer if that is in use. */
10496 redisplay_internal (0);
10501 overlay_arrow_string_or_property (var
)
10506 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10509 return Voverlay_arrow_string
;
10512 /* Return 1 if there are any overlay-arrows in current_buffer. */
10514 overlay_arrow_in_current_buffer_p ()
10518 for (vlist
= Voverlay_arrow_variable_list
;
10520 vlist
= XCDR (vlist
))
10522 Lisp_Object var
= XCAR (vlist
);
10525 if (!SYMBOLP (var
))
10527 val
= find_symbol_value (var
);
10529 && current_buffer
== XMARKER (val
)->buffer
)
10536 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10540 overlay_arrows_changed_p ()
10544 for (vlist
= Voverlay_arrow_variable_list
;
10546 vlist
= XCDR (vlist
))
10548 Lisp_Object var
= XCAR (vlist
);
10549 Lisp_Object val
, pstr
;
10551 if (!SYMBOLP (var
))
10553 val
= find_symbol_value (var
);
10554 if (!MARKERP (val
))
10556 if (! EQ (COERCE_MARKER (val
),
10557 Fget (var
, Qlast_arrow_position
))
10558 || ! (pstr
= overlay_arrow_string_or_property (var
),
10559 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10565 /* Mark overlay arrows to be updated on next redisplay. */
10568 update_overlay_arrows (up_to_date
)
10573 for (vlist
= Voverlay_arrow_variable_list
;
10575 vlist
= XCDR (vlist
))
10577 Lisp_Object var
= XCAR (vlist
);
10579 if (!SYMBOLP (var
))
10582 if (up_to_date
> 0)
10584 Lisp_Object val
= find_symbol_value (var
);
10585 Fput (var
, Qlast_arrow_position
,
10586 COERCE_MARKER (val
));
10587 Fput (var
, Qlast_arrow_string
,
10588 overlay_arrow_string_or_property (var
));
10590 else if (up_to_date
< 0
10591 || !NILP (Fget (var
, Qlast_arrow_position
)))
10593 Fput (var
, Qlast_arrow_position
, Qt
);
10594 Fput (var
, Qlast_arrow_string
, Qt
);
10600 /* Return overlay arrow string to display at row.
10601 Return integer (bitmap number) for arrow bitmap in left fringe.
10602 Return nil if no overlay arrow. */
10605 overlay_arrow_at_row (it
, row
)
10607 struct glyph_row
*row
;
10611 for (vlist
= Voverlay_arrow_variable_list
;
10613 vlist
= XCDR (vlist
))
10615 Lisp_Object var
= XCAR (vlist
);
10618 if (!SYMBOLP (var
))
10621 val
= find_symbol_value (var
);
10624 && current_buffer
== XMARKER (val
)->buffer
10625 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10627 if (FRAME_WINDOW_P (it
->f
)
10628 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10630 #ifdef HAVE_WINDOW_SYSTEM
10631 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10634 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10635 return make_number (fringe_bitmap
);
10638 return make_number (-1); /* Use default arrow bitmap */
10640 return overlay_arrow_string_or_property (var
);
10647 /* Return 1 if point moved out of or into a composition. Otherwise
10648 return 0. PREV_BUF and PREV_PT are the last point buffer and
10649 position. BUF and PT are the current point buffer and position. */
10652 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10653 struct buffer
*prev_buf
, *buf
;
10658 Lisp_Object buffer
;
10660 XSETBUFFER (buffer
, buf
);
10661 /* Check a composition at the last point if point moved within the
10663 if (prev_buf
== buf
)
10666 /* Point didn't move. */
10669 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10670 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10671 && COMPOSITION_VALID_P (start
, end
, prop
)
10672 && start
< prev_pt
&& end
> prev_pt
)
10673 /* The last point was within the composition. Return 1 iff
10674 point moved out of the composition. */
10675 return (pt
<= start
|| pt
>= end
);
10678 /* Check a composition at the current point. */
10679 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10680 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10681 && COMPOSITION_VALID_P (start
, end
, prop
)
10682 && start
< pt
&& end
> pt
);
10686 /* Reconsider the setting of B->clip_changed which is displayed
10690 reconsider_clip_changes (w
, b
)
10694 if (b
->clip_changed
10695 && !NILP (w
->window_end_valid
)
10696 && w
->current_matrix
->buffer
== b
10697 && w
->current_matrix
->zv
== BUF_ZV (b
)
10698 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10699 b
->clip_changed
= 0;
10701 /* If display wasn't paused, and W is not a tool bar window, see if
10702 point has been moved into or out of a composition. In that case,
10703 we set b->clip_changed to 1 to force updating the screen. If
10704 b->clip_changed has already been set to 1, we can skip this
10706 if (!b
->clip_changed
10707 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10711 if (w
== XWINDOW (selected_window
))
10712 pt
= BUF_PT (current_buffer
);
10714 pt
= marker_position (w
->pointm
);
10716 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10717 || pt
!= XINT (w
->last_point
))
10718 && check_point_in_composition (w
->current_matrix
->buffer
,
10719 XINT (w
->last_point
),
10720 XBUFFER (w
->buffer
), pt
))
10721 b
->clip_changed
= 1;
10726 /* Select FRAME to forward the values of frame-local variables into C
10727 variables so that the redisplay routines can access those values
10731 select_frame_for_redisplay (frame
)
10734 Lisp_Object tail
, sym
, val
;
10735 Lisp_Object old
= selected_frame
;
10737 selected_frame
= frame
;
10739 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10740 if (CONSP (XCAR (tail
))
10741 && (sym
= XCAR (XCAR (tail
)),
10743 && (sym
= indirect_variable (sym
),
10744 val
= SYMBOL_VALUE (sym
),
10745 (BUFFER_LOCAL_VALUEP (val
)
10746 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10747 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10748 /* Use find_symbol_value rather than Fsymbol_value
10749 to avoid an error if it is void. */
10750 find_symbol_value (sym
);
10752 for (tail
= XFRAME (old
)->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 find_symbol_value (sym
);
10765 #define STOP_POLLING \
10766 do { if (! polling_stopped_here) stop_polling (); \
10767 polling_stopped_here = 1; } while (0)
10769 #define RESUME_POLLING \
10770 do { if (polling_stopped_here) start_polling (); \
10771 polling_stopped_here = 0; } while (0)
10774 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10775 response to any user action; therefore, we should preserve the echo
10776 area. (Actually, our caller does that job.) Perhaps in the future
10777 avoid recentering windows if it is not necessary; currently that
10778 causes some problems. */
10781 redisplay_internal (preserve_echo_area
)
10782 int preserve_echo_area
;
10784 struct window
*w
= XWINDOW (selected_window
);
10785 struct frame
*f
= XFRAME (w
->frame
);
10787 int must_finish
= 0;
10788 struct text_pos tlbufpos
, tlendpos
;
10789 int number_of_visible_frames
;
10791 struct frame
*sf
= SELECTED_FRAME ();
10792 int polling_stopped_here
= 0;
10794 /* Non-zero means redisplay has to consider all windows on all
10795 frames. Zero means, only selected_window is considered. */
10796 int consider_all_windows_p
;
10798 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10800 /* No redisplay if running in batch mode or frame is not yet fully
10801 initialized, or redisplay is explicitly turned off by setting
10802 Vinhibit_redisplay. */
10804 || !NILP (Vinhibit_redisplay
)
10805 || !f
->glyphs_initialized_p
)
10808 /* The flag redisplay_performed_directly_p is set by
10809 direct_output_for_insert when it already did the whole screen
10810 update necessary. */
10811 if (redisplay_performed_directly_p
)
10813 redisplay_performed_directly_p
= 0;
10814 if (!hscroll_windows (selected_window
))
10818 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10819 if (popup_activated ())
10823 /* I don't think this happens but let's be paranoid. */
10824 if (redisplaying_p
)
10827 /* Record a function that resets redisplaying_p to its old value
10828 when we leave this function. */
10829 count
= SPECPDL_INDEX ();
10830 record_unwind_protect (unwind_redisplay
,
10831 Fcons (make_number (redisplaying_p
), selected_frame
));
10833 specbind (Qinhibit_free_realized_faces
, Qnil
);
10836 Lisp_Object tail
, frame
;
10838 FOR_EACH_FRAME (tail
, frame
)
10840 struct frame
*f
= XFRAME (frame
);
10841 f
->already_hscrolled_p
= 0;
10847 reconsider_clip_changes (w
, current_buffer
);
10848 last_escape_glyph_frame
= NULL
;
10849 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10851 /* If new fonts have been loaded that make a glyph matrix adjustment
10852 necessary, do it. */
10853 if (fonts_changed_p
)
10855 adjust_glyphs (NULL
);
10856 ++windows_or_buffers_changed
;
10857 fonts_changed_p
= 0;
10860 /* If face_change_count is non-zero, init_iterator will free all
10861 realized faces, which includes the faces referenced from current
10862 matrices. So, we can't reuse current matrices in this case. */
10863 if (face_change_count
)
10864 ++windows_or_buffers_changed
;
10866 if (! FRAME_WINDOW_P (sf
)
10867 && previous_terminal_frame
!= sf
)
10869 /* Since frames on an ASCII terminal share the same display
10870 area, displaying a different frame means redisplay the whole
10872 windows_or_buffers_changed
++;
10873 SET_FRAME_GARBAGED (sf
);
10874 XSETFRAME (Vterminal_frame
, sf
);
10876 previous_terminal_frame
= sf
;
10878 /* Set the visible flags for all frames. Do this before checking
10879 for resized or garbaged frames; they want to know if their frames
10880 are visible. See the comment in frame.h for
10881 FRAME_SAMPLE_VISIBILITY. */
10883 Lisp_Object tail
, frame
;
10885 number_of_visible_frames
= 0;
10887 FOR_EACH_FRAME (tail
, frame
)
10889 struct frame
*f
= XFRAME (frame
);
10891 FRAME_SAMPLE_VISIBILITY (f
);
10892 if (FRAME_VISIBLE_P (f
))
10893 ++number_of_visible_frames
;
10894 clear_desired_matrices (f
);
10898 /* Notice any pending interrupt request to change frame size. */
10899 do_pending_window_change (1);
10901 /* Clear frames marked as garbaged. */
10902 if (frame_garbaged
)
10903 clear_garbaged_frames ();
10905 /* Build menubar and tool-bar items. */
10906 if (NILP (Vmemory_full
))
10907 prepare_menu_bars ();
10909 if (windows_or_buffers_changed
)
10910 update_mode_lines
++;
10912 /* Detect case that we need to write or remove a star in the mode line. */
10913 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10915 w
->update_mode_line
= Qt
;
10916 if (buffer_shared
> 1)
10917 update_mode_lines
++;
10920 /* If %c is in the mode line, update it if needed. */
10921 if (!NILP (w
->column_number_displayed
)
10922 /* This alternative quickly identifies a common case
10923 where no change is needed. */
10924 && !(PT
== XFASTINT (w
->last_point
)
10925 && XFASTINT (w
->last_modified
) >= MODIFF
10926 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10927 && (XFASTINT (w
->column_number_displayed
)
10928 != (int) current_column ())) /* iftc */
10929 w
->update_mode_line
= Qt
;
10931 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10933 /* The variable buffer_shared is set in redisplay_window and
10934 indicates that we redisplay a buffer in different windows. See
10936 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10937 || cursor_type_changed
);
10939 /* If specs for an arrow have changed, do thorough redisplay
10940 to ensure we remove any arrow that should no longer exist. */
10941 if (overlay_arrows_changed_p ())
10942 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10944 /* Normally the message* functions will have already displayed and
10945 updated the echo area, but the frame may have been trashed, or
10946 the update may have been preempted, so display the echo area
10947 again here. Checking message_cleared_p captures the case that
10948 the echo area should be cleared. */
10949 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10950 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10951 || (message_cleared_p
10952 && minibuf_level
== 0
10953 /* If the mini-window is currently selected, this means the
10954 echo-area doesn't show through. */
10955 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10957 int window_height_changed_p
= echo_area_display (0);
10960 /* If we don't display the current message, don't clear the
10961 message_cleared_p flag, because, if we did, we wouldn't clear
10962 the echo area in the next redisplay which doesn't preserve
10964 if (!display_last_displayed_message_p
)
10965 message_cleared_p
= 0;
10967 if (fonts_changed_p
)
10969 else if (window_height_changed_p
)
10971 consider_all_windows_p
= 1;
10972 ++update_mode_lines
;
10973 ++windows_or_buffers_changed
;
10975 /* If window configuration was changed, frames may have been
10976 marked garbaged. Clear them or we will experience
10977 surprises wrt scrolling. */
10978 if (frame_garbaged
)
10979 clear_garbaged_frames ();
10982 else if (EQ (selected_window
, minibuf_window
)
10983 && (current_buffer
->clip_changed
10984 || XFASTINT (w
->last_modified
) < MODIFF
10985 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10986 && resize_mini_window (w
, 0))
10988 /* Resized active mini-window to fit the size of what it is
10989 showing if its contents might have changed. */
10991 consider_all_windows_p
= 1;
10992 ++windows_or_buffers_changed
;
10993 ++update_mode_lines
;
10995 /* If window configuration was changed, frames may have been
10996 marked garbaged. Clear them or we will experience
10997 surprises wrt scrolling. */
10998 if (frame_garbaged
)
10999 clear_garbaged_frames ();
11003 /* If showing the region, and mark has changed, we must redisplay
11004 the whole window. The assignment to this_line_start_pos prevents
11005 the optimization directly below this if-statement. */
11006 if (((!NILP (Vtransient_mark_mode
)
11007 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11008 != !NILP (w
->region_showing
))
11009 || (!NILP (w
->region_showing
)
11010 && !EQ (w
->region_showing
,
11011 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11012 CHARPOS (this_line_start_pos
) = 0;
11014 /* Optimize the case that only the line containing the cursor in the
11015 selected window has changed. Variables starting with this_ are
11016 set in display_line and record information about the line
11017 containing the cursor. */
11018 tlbufpos
= this_line_start_pos
;
11019 tlendpos
= this_line_end_pos
;
11020 if (!consider_all_windows_p
11021 && CHARPOS (tlbufpos
) > 0
11022 && NILP (w
->update_mode_line
)
11023 && !current_buffer
->clip_changed
11024 && !current_buffer
->prevent_redisplay_optimizations_p
11025 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11026 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11027 /* Make sure recorded data applies to current buffer, etc. */
11028 && this_line_buffer
== current_buffer
11029 && current_buffer
== XBUFFER (w
->buffer
)
11030 && NILP (w
->force_start
)
11031 && NILP (w
->optional_new_start
)
11032 /* Point must be on the line that we have info recorded about. */
11033 && PT
>= CHARPOS (tlbufpos
)
11034 && PT
<= Z
- CHARPOS (tlendpos
)
11035 /* All text outside that line, including its final newline,
11036 must be unchanged */
11037 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11038 CHARPOS (tlendpos
)))
11040 if (CHARPOS (tlbufpos
) > BEGV
11041 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11042 && (CHARPOS (tlbufpos
) == ZV
11043 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11044 /* Former continuation line has disappeared by becoming empty */
11046 else if (XFASTINT (w
->last_modified
) < MODIFF
11047 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11048 || MINI_WINDOW_P (w
))
11050 /* We have to handle the case of continuation around a
11051 wide-column character (See the comment in indent.c around
11054 For instance, in the following case:
11056 -------- Insert --------
11057 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11058 J_I_ ==> J_I_ `^^' are cursors.
11062 As we have to redraw the line above, we should goto cancel. */
11065 int line_height_before
= this_line_pixel_height
;
11067 /* Note that start_display will handle the case that the
11068 line starting at tlbufpos is a continuation lines. */
11069 start_display (&it
, w
, tlbufpos
);
11071 /* Implementation note: It this still necessary? */
11072 if (it
.current_x
!= this_line_start_x
)
11075 TRACE ((stderr
, "trying display optimization 1\n"));
11076 w
->cursor
.vpos
= -1;
11077 overlay_arrow_seen
= 0;
11078 it
.vpos
= this_line_vpos
;
11079 it
.current_y
= this_line_y
;
11080 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11081 display_line (&it
);
11083 /* If line contains point, is not continued,
11084 and ends at same distance from eob as before, we win */
11085 if (w
->cursor
.vpos
>= 0
11086 /* Line is not continued, otherwise this_line_start_pos
11087 would have been set to 0 in display_line. */
11088 && CHARPOS (this_line_start_pos
)
11089 /* Line ends as before. */
11090 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11091 /* Line has same height as before. Otherwise other lines
11092 would have to be shifted up or down. */
11093 && this_line_pixel_height
== line_height_before
)
11095 /* If this is not the window's last line, we must adjust
11096 the charstarts of the lines below. */
11097 if (it
.current_y
< it
.last_visible_y
)
11099 struct glyph_row
*row
11100 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11101 int delta
, delta_bytes
;
11103 if (Z
- CHARPOS (tlendpos
) == ZV
)
11105 /* This line ends at end of (accessible part of)
11106 buffer. There is no newline to count. */
11108 - CHARPOS (tlendpos
)
11109 - MATRIX_ROW_START_CHARPOS (row
));
11110 delta_bytes
= (Z_BYTE
11111 - BYTEPOS (tlendpos
)
11112 - MATRIX_ROW_START_BYTEPOS (row
));
11116 /* This line ends in a newline. Must take
11117 account of the newline and the rest of the
11118 text that follows. */
11120 - CHARPOS (tlendpos
)
11121 - MATRIX_ROW_START_CHARPOS (row
));
11122 delta_bytes
= (Z_BYTE
11123 - BYTEPOS (tlendpos
)
11124 - MATRIX_ROW_START_BYTEPOS (row
));
11127 increment_matrix_positions (w
->current_matrix
,
11128 this_line_vpos
+ 1,
11129 w
->current_matrix
->nrows
,
11130 delta
, delta_bytes
);
11133 /* If this row displays text now but previously didn't,
11134 or vice versa, w->window_end_vpos may have to be
11136 if ((it
.glyph_row
- 1)->displays_text_p
)
11138 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11139 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11141 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11142 && this_line_vpos
> 0)
11143 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11144 w
->window_end_valid
= Qnil
;
11146 /* Update hint: No need to try to scroll in update_window. */
11147 w
->desired_matrix
->no_scrolling_p
= 1;
11150 *w
->desired_matrix
->method
= 0;
11151 debug_method_add (w
, "optimization 1");
11153 #ifdef HAVE_WINDOW_SYSTEM
11154 update_window_fringes (w
, 0);
11161 else if (/* Cursor position hasn't changed. */
11162 PT
== XFASTINT (w
->last_point
)
11163 /* Make sure the cursor was last displayed
11164 in this window. Otherwise we have to reposition it. */
11165 && 0 <= w
->cursor
.vpos
11166 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11170 do_pending_window_change (1);
11172 /* We used to always goto end_of_redisplay here, but this
11173 isn't enough if we have a blinking cursor. */
11174 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11175 goto end_of_redisplay
;
11179 /* If highlighting the region, or if the cursor is in the echo area,
11180 then we can't just move the cursor. */
11181 else if (! (!NILP (Vtransient_mark_mode
)
11182 && !NILP (current_buffer
->mark_active
))
11183 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11184 || highlight_nonselected_windows
)
11185 && NILP (w
->region_showing
)
11186 && NILP (Vshow_trailing_whitespace
)
11187 && !cursor_in_echo_area
)
11190 struct glyph_row
*row
;
11192 /* Skip from tlbufpos to PT and see where it is. Note that
11193 PT may be in invisible text. If so, we will end at the
11194 next visible position. */
11195 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11196 NULL
, DEFAULT_FACE_ID
);
11197 it
.current_x
= this_line_start_x
;
11198 it
.current_y
= this_line_y
;
11199 it
.vpos
= this_line_vpos
;
11201 /* The call to move_it_to stops in front of PT, but
11202 moves over before-strings. */
11203 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11205 if (it
.vpos
== this_line_vpos
11206 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11209 xassert (this_line_vpos
== it
.vpos
);
11210 xassert (this_line_y
== it
.current_y
);
11211 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11213 *w
->desired_matrix
->method
= 0;
11214 debug_method_add (w
, "optimization 3");
11223 /* Text changed drastically or point moved off of line. */
11224 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11227 CHARPOS (this_line_start_pos
) = 0;
11228 consider_all_windows_p
|= buffer_shared
> 1;
11229 ++clear_face_cache_count
;
11230 #ifdef HAVE_WINDOW_SYSTEM
11231 ++clear_image_cache_count
;
11234 /* Build desired matrices, and update the display. If
11235 consider_all_windows_p is non-zero, do it for all windows on all
11236 frames. Otherwise do it for selected_window, only. */
11238 if (consider_all_windows_p
)
11240 Lisp_Object tail
, frame
;
11242 FOR_EACH_FRAME (tail
, frame
)
11243 XFRAME (frame
)->updated_p
= 0;
11245 /* Recompute # windows showing selected buffer. This will be
11246 incremented each time such a window is displayed. */
11249 FOR_EACH_FRAME (tail
, frame
)
11251 struct frame
*f
= XFRAME (frame
);
11253 if (FRAME_WINDOW_P (f
) || f
== sf
)
11255 if (! EQ (frame
, selected_frame
))
11256 /* Select the frame, for the sake of frame-local
11258 select_frame_for_redisplay (frame
);
11260 /* Mark all the scroll bars to be removed; we'll redeem
11261 the ones we want when we redisplay their windows. */
11262 if (condemn_scroll_bars_hook
)
11263 condemn_scroll_bars_hook (f
);
11265 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11266 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11268 /* Any scroll bars which redisplay_windows should have
11269 nuked should now go away. */
11270 if (judge_scroll_bars_hook
)
11271 judge_scroll_bars_hook (f
);
11273 /* If fonts changed, display again. */
11274 /* ??? rms: I suspect it is a mistake to jump all the way
11275 back to retry here. It should just retry this frame. */
11276 if (fonts_changed_p
)
11279 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11281 /* See if we have to hscroll. */
11282 if (!f
->already_hscrolled_p
)
11284 f
->already_hscrolled_p
= 1;
11285 if (hscroll_windows (f
->root_window
))
11289 /* Prevent various kinds of signals during display
11290 update. stdio is not robust about handling
11291 signals, which can cause an apparent I/O
11293 if (interrupt_input
)
11294 unrequest_sigio ();
11297 /* Update the display. */
11298 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11299 pause
|= update_frame (f
, 0, 0);
11300 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11312 /* Do the mark_window_display_accurate after all windows have
11313 been redisplayed because this call resets flags in buffers
11314 which are needed for proper redisplay. */
11315 FOR_EACH_FRAME (tail
, frame
)
11317 struct frame
*f
= XFRAME (frame
);
11320 mark_window_display_accurate (f
->root_window
, 1);
11321 if (frame_up_to_date_hook
)
11322 frame_up_to_date_hook (f
);
11327 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11329 Lisp_Object mini_window
;
11330 struct frame
*mini_frame
;
11332 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11333 /* Use list_of_error, not Qerror, so that
11334 we catch only errors and don't run the debugger. */
11335 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11337 redisplay_window_error
);
11339 /* Compare desired and current matrices, perform output. */
11342 /* If fonts changed, display again. */
11343 if (fonts_changed_p
)
11346 /* Prevent various kinds of signals during display update.
11347 stdio is not robust about handling signals,
11348 which can cause an apparent I/O error. */
11349 if (interrupt_input
)
11350 unrequest_sigio ();
11353 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11355 if (hscroll_windows (selected_window
))
11358 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11359 pause
= update_frame (sf
, 0, 0);
11362 /* We may have called echo_area_display at the top of this
11363 function. If the echo area is on another frame, that may
11364 have put text on a frame other than the selected one, so the
11365 above call to update_frame would not have caught it. Catch
11367 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11368 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11370 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11372 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11373 pause
|= update_frame (mini_frame
, 0, 0);
11374 if (!pause
&& hscroll_windows (mini_window
))
11379 /* If display was paused because of pending input, make sure we do a
11380 thorough update the next time. */
11383 /* Prevent the optimization at the beginning of
11384 redisplay_internal that tries a single-line update of the
11385 line containing the cursor in the selected window. */
11386 CHARPOS (this_line_start_pos
) = 0;
11388 /* Let the overlay arrow be updated the next time. */
11389 update_overlay_arrows (0);
11391 /* If we pause after scrolling, some rows in the current
11392 matrices of some windows are not valid. */
11393 if (!WINDOW_FULL_WIDTH_P (w
)
11394 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11395 update_mode_lines
= 1;
11399 if (!consider_all_windows_p
)
11401 /* This has already been done above if
11402 consider_all_windows_p is set. */
11403 mark_window_display_accurate_1 (w
, 1);
11405 /* Say overlay arrows are up to date. */
11406 update_overlay_arrows (1);
11408 if (frame_up_to_date_hook
!= 0)
11409 frame_up_to_date_hook (sf
);
11412 update_mode_lines
= 0;
11413 windows_or_buffers_changed
= 0;
11414 cursor_type_changed
= 0;
11417 /* Start SIGIO interrupts coming again. Having them off during the
11418 code above makes it less likely one will discard output, but not
11419 impossible, since there might be stuff in the system buffer here.
11420 But it is much hairier to try to do anything about that. */
11421 if (interrupt_input
)
11425 /* If a frame has become visible which was not before, redisplay
11426 again, so that we display it. Expose events for such a frame
11427 (which it gets when becoming visible) don't call the parts of
11428 redisplay constructing glyphs, so simply exposing a frame won't
11429 display anything in this case. So, we have to display these
11430 frames here explicitly. */
11433 Lisp_Object tail
, frame
;
11436 FOR_EACH_FRAME (tail
, frame
)
11438 int this_is_visible
= 0;
11440 if (XFRAME (frame
)->visible
)
11441 this_is_visible
= 1;
11442 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11443 if (XFRAME (frame
)->visible
)
11444 this_is_visible
= 1;
11446 if (this_is_visible
)
11450 if (new_count
!= number_of_visible_frames
)
11451 windows_or_buffers_changed
++;
11454 /* Change frame size now if a change is pending. */
11455 do_pending_window_change (1);
11457 /* If we just did a pending size change, or have additional
11458 visible frames, redisplay again. */
11459 if (windows_or_buffers_changed
&& !pause
)
11462 /* Clear the face cache eventually. */
11463 if (consider_all_windows_p
)
11465 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11467 clear_face_cache (0);
11468 clear_face_cache_count
= 0;
11470 #ifdef HAVE_WINDOW_SYSTEM
11471 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11473 Lisp_Object tail
, frame
;
11474 FOR_EACH_FRAME (tail
, frame
)
11476 struct frame
*f
= XFRAME (frame
);
11477 if (FRAME_WINDOW_P (f
))
11478 clear_image_cache (f
, 0);
11480 clear_image_cache_count
= 0;
11482 #endif /* HAVE_WINDOW_SYSTEM */
11486 unbind_to (count
, Qnil
);
11491 /* Redisplay, but leave alone any recent echo area message unless
11492 another message has been requested in its place.
11494 This is useful in situations where you need to redisplay but no
11495 user action has occurred, making it inappropriate for the message
11496 area to be cleared. See tracking_off and
11497 wait_reading_process_output for examples of these situations.
11499 FROM_WHERE is an integer saying from where this function was
11500 called. This is useful for debugging. */
11503 redisplay_preserve_echo_area (from_where
)
11506 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11508 if (!NILP (echo_area_buffer
[1]))
11510 /* We have a previously displayed message, but no current
11511 message. Redisplay the previous message. */
11512 display_last_displayed_message_p
= 1;
11513 redisplay_internal (1);
11514 display_last_displayed_message_p
= 0;
11517 redisplay_internal (1);
11519 if (rif
!= NULL
&& rif
->flush_display_optional
)
11520 rif
->flush_display_optional (NULL
);
11524 /* Function registered with record_unwind_protect in
11525 redisplay_internal. Reset redisplaying_p to the value it had
11526 before redisplay_internal was called, and clear
11527 prevent_freeing_realized_faces_p. It also selects the previously
11531 unwind_redisplay (val
)
11534 Lisp_Object old_redisplaying_p
, old_frame
;
11536 old_redisplaying_p
= XCAR (val
);
11537 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11538 old_frame
= XCDR (val
);
11539 if (! EQ (old_frame
, selected_frame
))
11540 select_frame_for_redisplay (old_frame
);
11545 /* Mark the display of window W as accurate or inaccurate. If
11546 ACCURATE_P is non-zero mark display of W as accurate. If
11547 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11548 redisplay_internal is called. */
11551 mark_window_display_accurate_1 (w
, accurate_p
)
11555 if (BUFFERP (w
->buffer
))
11557 struct buffer
*b
= XBUFFER (w
->buffer
);
11560 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11561 w
->last_overlay_modified
11562 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11564 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11568 b
->clip_changed
= 0;
11569 b
->prevent_redisplay_optimizations_p
= 0;
11571 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11572 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11573 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11574 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11576 w
->current_matrix
->buffer
= b
;
11577 w
->current_matrix
->begv
= BUF_BEGV (b
);
11578 w
->current_matrix
->zv
= BUF_ZV (b
);
11580 w
->last_cursor
= w
->cursor
;
11581 w
->last_cursor_off_p
= w
->cursor_off_p
;
11583 if (w
== XWINDOW (selected_window
))
11584 w
->last_point
= make_number (BUF_PT (b
));
11586 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11592 w
->window_end_valid
= w
->buffer
;
11593 #if 0 /* This is incorrect with variable-height lines. */
11594 xassert (XINT (w
->window_end_vpos
)
11595 < (WINDOW_TOTAL_LINES (w
)
11596 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11598 w
->update_mode_line
= Qnil
;
11603 /* Mark the display of windows in the window tree rooted at WINDOW as
11604 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11605 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11606 be redisplayed the next time redisplay_internal is called. */
11609 mark_window_display_accurate (window
, accurate_p
)
11610 Lisp_Object window
;
11615 for (; !NILP (window
); window
= w
->next
)
11617 w
= XWINDOW (window
);
11618 mark_window_display_accurate_1 (w
, accurate_p
);
11620 if (!NILP (w
->vchild
))
11621 mark_window_display_accurate (w
->vchild
, accurate_p
);
11622 if (!NILP (w
->hchild
))
11623 mark_window_display_accurate (w
->hchild
, accurate_p
);
11628 update_overlay_arrows (1);
11632 /* Force a thorough redisplay the next time by setting
11633 last_arrow_position and last_arrow_string to t, which is
11634 unequal to any useful value of Voverlay_arrow_... */
11635 update_overlay_arrows (-1);
11640 /* Return value in display table DP (Lisp_Char_Table *) for character
11641 C. Since a display table doesn't have any parent, we don't have to
11642 follow parent. Do not call this function directly but use the
11643 macro DISP_CHAR_VECTOR. */
11646 disp_char_vector (dp
, c
)
11647 struct Lisp_Char_Table
*dp
;
11653 if (SINGLE_BYTE_CHAR_P (c
))
11654 return (dp
->contents
[c
]);
11656 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11659 else if (code
[2] < 32)
11662 /* Here, the possible range of code[0] (== charset ID) is
11663 128..max_charset. Since the top level char table contains data
11664 for multibyte characters after 256th element, we must increment
11665 code[0] by 128 to get a correct index. */
11667 code
[3] = -1; /* anchor */
11669 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11671 val
= dp
->contents
[code
[i
]];
11672 if (!SUB_CHAR_TABLE_P (val
))
11673 return (NILP (val
) ? dp
->defalt
: val
);
11676 /* Here, val is a sub char table. We return the default value of
11678 return (dp
->defalt
);
11683 /***********************************************************************
11685 ***********************************************************************/
11687 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11690 redisplay_windows (window
)
11691 Lisp_Object window
;
11693 while (!NILP (window
))
11695 struct window
*w
= XWINDOW (window
);
11697 if (!NILP (w
->hchild
))
11698 redisplay_windows (w
->hchild
);
11699 else if (!NILP (w
->vchild
))
11700 redisplay_windows (w
->vchild
);
11703 displayed_buffer
= XBUFFER (w
->buffer
);
11704 /* Use list_of_error, not Qerror, so that
11705 we catch only errors and don't run the debugger. */
11706 internal_condition_case_1 (redisplay_window_0
, window
,
11708 redisplay_window_error
);
11716 redisplay_window_error ()
11718 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11723 redisplay_window_0 (window
)
11724 Lisp_Object window
;
11726 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11727 redisplay_window (window
, 0);
11732 redisplay_window_1 (window
)
11733 Lisp_Object window
;
11735 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11736 redisplay_window (window
, 1);
11741 /* Increment GLYPH until it reaches END or CONDITION fails while
11742 adding (GLYPH)->pixel_width to X. */
11744 #define SKIP_GLYPHS(glyph, end, x, condition) \
11747 (x) += (glyph)->pixel_width; \
11750 while ((glyph) < (end) && (condition))
11753 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11754 DELTA is the number of bytes by which positions recorded in ROW
11755 differ from current buffer positions.
11757 Return 0 if cursor is not on this row. 1 otherwise. */
11760 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11762 struct glyph_row
*row
;
11763 struct glyph_matrix
*matrix
;
11764 int delta
, delta_bytes
, dy
, dvpos
;
11766 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11767 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11768 struct glyph
*cursor
= NULL
;
11769 /* The first glyph that starts a sequence of glyphs from string. */
11770 struct glyph
*string_start
;
11771 /* The X coordinate of string_start. */
11772 int string_start_x
;
11773 /* The last known character position. */
11774 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11775 /* The last known character position before string_start. */
11776 int string_before_pos
;
11779 int cursor_from_overlay_pos
= 0;
11780 int pt_old
= PT
- delta
;
11782 /* Skip over glyphs not having an object at the start of the row.
11783 These are special glyphs like truncation marks on terminal
11785 if (row
->displays_text_p
)
11787 && INTEGERP (glyph
->object
)
11788 && glyph
->charpos
< 0)
11790 x
+= glyph
->pixel_width
;
11794 string_start
= NULL
;
11796 && !INTEGERP (glyph
->object
)
11797 && (!BUFFERP (glyph
->object
)
11798 || (last_pos
= glyph
->charpos
) < pt_old
))
11800 if (! STRINGP (glyph
->object
))
11802 string_start
= NULL
;
11803 x
+= glyph
->pixel_width
;
11805 if (cursor_from_overlay_pos
11806 && last_pos
>= cursor_from_overlay_pos
)
11808 cursor_from_overlay_pos
= 0;
11814 if (string_start
== NULL
)
11816 string_before_pos
= last_pos
;
11817 string_start
= glyph
;
11818 string_start_x
= x
;
11820 /* Skip all glyphs from string. */
11825 if ((cursor
== NULL
|| glyph
> cursor
)
11826 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11827 Qcursor
, (glyph
)->object
),
11829 && (pos
= string_buffer_position (w
, glyph
->object
,
11830 string_before_pos
),
11831 (pos
== 0 /* From overlay */
11832 || pos
== pt_old
)))
11834 /* Estimate overlay buffer position from the buffer
11835 positions of the glyphs before and after the overlay.
11836 Add 1 to last_pos so that if point corresponds to the
11837 glyph right after the overlay, we still use a 'cursor'
11838 property found in that overlay. */
11839 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11840 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11844 x
+= glyph
->pixel_width
;
11847 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11851 if (cursor
!= NULL
)
11856 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11858 /* Scan back over the ellipsis glyphs, decrementing positions. */
11859 while (glyph
> row
->glyphs
[TEXT_AREA
]
11860 && (glyph
- 1)->charpos
== last_pos
)
11861 glyph
--, x
-= glyph
->pixel_width
;
11862 /* That loop always goes one position too far,
11863 including the glyph before the ellipsis.
11864 So scan forward over that one. */
11865 x
+= glyph
->pixel_width
;
11868 else if (string_start
11869 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11871 /* We may have skipped over point because the previous glyphs
11872 are from string. As there's no easy way to know the
11873 character position of the current glyph, find the correct
11874 glyph on point by scanning from string_start again. */
11876 Lisp_Object string
;
11877 struct glyph
*stop
= glyph
;
11880 limit
= make_number (pt_old
+ 1);
11881 glyph
= string_start
;
11882 x
= string_start_x
;
11883 string
= glyph
->object
;
11884 pos
= string_buffer_position (w
, string
, string_before_pos
);
11885 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11886 because we always put cursor after overlay strings. */
11887 while (pos
== 0 && glyph
< stop
)
11889 string
= glyph
->object
;
11890 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11892 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11895 while (glyph
< stop
)
11897 pos
= XINT (Fnext_single_char_property_change
11898 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11901 /* Skip glyphs from the same string. */
11902 string
= glyph
->object
;
11903 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11904 /* Skip glyphs from an overlay. */
11905 while (glyph
< stop
11906 && ! string_buffer_position (w
, glyph
->object
, pos
))
11908 string
= glyph
->object
;
11909 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11913 /* If we reached the end of the line, and end was from a string,
11914 cursor is not on this line. */
11915 if (glyph
== end
&& row
->continued_p
)
11919 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11921 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11922 w
->cursor
.y
= row
->y
+ dy
;
11924 if (w
== XWINDOW (selected_window
))
11926 if (!row
->continued_p
11927 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11930 this_line_buffer
= XBUFFER (w
->buffer
);
11932 CHARPOS (this_line_start_pos
)
11933 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11934 BYTEPOS (this_line_start_pos
)
11935 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11937 CHARPOS (this_line_end_pos
)
11938 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11939 BYTEPOS (this_line_end_pos
)
11940 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11942 this_line_y
= w
->cursor
.y
;
11943 this_line_pixel_height
= row
->height
;
11944 this_line_vpos
= w
->cursor
.vpos
;
11945 this_line_start_x
= row
->x
;
11948 CHARPOS (this_line_start_pos
) = 0;
11955 /* Run window scroll functions, if any, for WINDOW with new window
11956 start STARTP. Sets the window start of WINDOW to that position.
11958 We assume that the window's buffer is really current. */
11960 static INLINE
struct text_pos
11961 run_window_scroll_functions (window
, startp
)
11962 Lisp_Object window
;
11963 struct text_pos startp
;
11965 struct window
*w
= XWINDOW (window
);
11966 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11968 if (current_buffer
!= XBUFFER (w
->buffer
))
11971 if (!NILP (Vwindow_scroll_functions
))
11973 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11974 make_number (CHARPOS (startp
)));
11975 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11976 /* In case the hook functions switch buffers. */
11977 if (current_buffer
!= XBUFFER (w
->buffer
))
11978 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11985 /* Make sure the line containing the cursor is fully visible.
11986 A value of 1 means there is nothing to be done.
11987 (Either the line is fully visible, or it cannot be made so,
11988 or we cannot tell.)
11990 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11991 is higher than window.
11993 A value of 0 means the caller should do scrolling
11994 as if point had gone off the screen. */
11997 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12000 int current_matrix_p
;
12002 struct glyph_matrix
*matrix
;
12003 struct glyph_row
*row
;
12006 if (!make_cursor_line_fully_visible_p
)
12009 /* It's not always possible to find the cursor, e.g, when a window
12010 is full of overlay strings. Don't do anything in that case. */
12011 if (w
->cursor
.vpos
< 0)
12014 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12015 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12017 /* If the cursor row is not partially visible, there's nothing to do. */
12018 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12021 /* If the row the cursor is in is taller than the window's height,
12022 it's not clear what to do, so do nothing. */
12023 window_height
= window_box_height (w
);
12024 if (row
->height
>= window_height
)
12026 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
12032 /* This code used to try to scroll the window just enough to make
12033 the line visible. It returned 0 to say that the caller should
12034 allocate larger glyph matrices. */
12036 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12038 int dy
= row
->height
- row
->visible_height
;
12041 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12043 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12045 int dy
= - (row
->height
- row
->visible_height
);
12048 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12051 /* When we change the cursor y-position of the selected window,
12052 change this_line_y as well so that the display optimization for
12053 the cursor line of the selected window in redisplay_internal uses
12054 the correct y-position. */
12055 if (w
== XWINDOW (selected_window
))
12056 this_line_y
= w
->cursor
.y
;
12058 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12059 redisplay with larger matrices. */
12060 if (matrix
->nrows
< required_matrix_height (w
))
12062 fonts_changed_p
= 1;
12071 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12072 non-zero means only WINDOW is redisplayed in redisplay_internal.
12073 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12074 in redisplay_window to bring a partially visible line into view in
12075 the case that only the cursor has moved.
12077 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12078 last screen line's vertical height extends past the end of the screen.
12082 1 if scrolling succeeded
12084 0 if scrolling didn't find point.
12086 -1 if new fonts have been loaded so that we must interrupt
12087 redisplay, adjust glyph matrices, and try again. */
12093 SCROLLING_NEED_LARGER_MATRICES
12097 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12098 scroll_step
, temp_scroll_step
, last_line_misfit
)
12099 Lisp_Object window
;
12100 int just_this_one_p
;
12101 EMACS_INT scroll_conservatively
, scroll_step
;
12102 int temp_scroll_step
;
12103 int last_line_misfit
;
12105 struct window
*w
= XWINDOW (window
);
12106 struct frame
*f
= XFRAME (w
->frame
);
12107 struct text_pos scroll_margin_pos
;
12108 struct text_pos pos
;
12109 struct text_pos startp
;
12111 Lisp_Object window_end
;
12112 int this_scroll_margin
;
12116 int amount_to_scroll
= 0;
12117 Lisp_Object aggressive
;
12119 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12122 debug_method_add (w
, "try_scrolling");
12125 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12127 /* Compute scroll margin height in pixels. We scroll when point is
12128 within this distance from the top or bottom of the window. */
12129 if (scroll_margin
> 0)
12131 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12132 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12135 this_scroll_margin
= 0;
12137 /* Force scroll_conservatively to have a reasonable value so it doesn't
12138 cause an overflow while computing how much to scroll. */
12139 if (scroll_conservatively
)
12140 scroll_conservatively
= min (scroll_conservatively
,
12141 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12143 /* Compute how much we should try to scroll maximally to bring point
12145 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12146 scroll_max
= max (scroll_step
,
12147 max (scroll_conservatively
, temp_scroll_step
));
12148 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12149 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12150 /* We're trying to scroll because of aggressive scrolling
12151 but no scroll_step is set. Choose an arbitrary one. Maybe
12152 there should be a variable for this. */
12156 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12158 /* Decide whether we have to scroll down. Start at the window end
12159 and move this_scroll_margin up to find the position of the scroll
12161 window_end
= Fwindow_end (window
, Qt
);
12165 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12166 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12168 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12170 start_display (&it
, w
, scroll_margin_pos
);
12171 if (this_scroll_margin
)
12172 move_it_vertically_backward (&it
, this_scroll_margin
);
12173 if (extra_scroll_margin_lines
)
12174 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12175 scroll_margin_pos
= it
.current
.pos
;
12178 if (PT
>= CHARPOS (scroll_margin_pos
))
12182 /* Point is in the scroll margin at the bottom of the window, or
12183 below. Compute a new window start that makes point visible. */
12185 /* Compute the distance from the scroll margin to PT.
12186 Give up if the distance is greater than scroll_max. */
12187 start_display (&it
, w
, scroll_margin_pos
);
12189 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12190 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12192 /* To make point visible, we have to move the window start
12193 down so that the line the cursor is in is visible, which
12194 means we have to add in the height of the cursor line. */
12195 dy
= line_bottom_y (&it
) - y0
;
12197 if (dy
> scroll_max
)
12198 return SCROLLING_FAILED
;
12200 /* Move the window start down. If scrolling conservatively,
12201 move it just enough down to make point visible. If
12202 scroll_step is set, move it down by scroll_step. */
12203 start_display (&it
, w
, startp
);
12205 if (scroll_conservatively
)
12206 /* Set AMOUNT_TO_SCROLL to at least one line,
12207 and at most scroll_conservatively lines. */
12209 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12210 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12211 else if (scroll_step
|| temp_scroll_step
)
12212 amount_to_scroll
= scroll_max
;
12215 aggressive
= current_buffer
->scroll_up_aggressively
;
12216 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12217 if (NUMBERP (aggressive
))
12219 double float_amount
= XFLOATINT (aggressive
) * height
;
12220 amount_to_scroll
= float_amount
;
12221 if (amount_to_scroll
== 0 && float_amount
> 0)
12222 amount_to_scroll
= 1;
12226 if (amount_to_scroll
<= 0)
12227 return SCROLLING_FAILED
;
12229 /* If moving by amount_to_scroll leaves STARTP unchanged,
12230 move it down one screen line. */
12232 move_it_vertically (&it
, amount_to_scroll
);
12233 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12234 move_it_by_lines (&it
, 1, 1);
12235 startp
= it
.current
.pos
;
12239 /* See if point is inside the scroll margin at the top of the
12241 scroll_margin_pos
= startp
;
12242 if (this_scroll_margin
)
12244 start_display (&it
, w
, startp
);
12245 move_it_vertically (&it
, this_scroll_margin
);
12246 scroll_margin_pos
= it
.current
.pos
;
12249 if (PT
< CHARPOS (scroll_margin_pos
))
12251 /* Point is in the scroll margin at the top of the window or
12252 above what is displayed in the window. */
12255 /* Compute the vertical distance from PT to the scroll
12256 margin position. Give up if distance is greater than
12258 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12259 start_display (&it
, w
, pos
);
12261 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12262 it
.last_visible_y
, -1,
12263 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12264 dy
= it
.current_y
- y0
;
12265 if (dy
> scroll_max
)
12266 return SCROLLING_FAILED
;
12268 /* Compute new window start. */
12269 start_display (&it
, w
, startp
);
12271 if (scroll_conservatively
)
12273 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12274 else if (scroll_step
|| temp_scroll_step
)
12275 amount_to_scroll
= scroll_max
;
12278 aggressive
= current_buffer
->scroll_down_aggressively
;
12279 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12280 if (NUMBERP (aggressive
))
12282 double float_amount
= XFLOATINT (aggressive
) * height
;
12283 amount_to_scroll
= float_amount
;
12284 if (amount_to_scroll
== 0 && float_amount
> 0)
12285 amount_to_scroll
= 1;
12289 if (amount_to_scroll
<= 0)
12290 return SCROLLING_FAILED
;
12292 move_it_vertically_backward (&it
, amount_to_scroll
);
12293 startp
= it
.current
.pos
;
12297 /* Run window scroll functions. */
12298 startp
= run_window_scroll_functions (window
, startp
);
12300 /* Display the window. Give up if new fonts are loaded, or if point
12302 if (!try_window (window
, startp
, 0))
12303 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12304 else if (w
->cursor
.vpos
< 0)
12306 clear_glyph_matrix (w
->desired_matrix
);
12307 rc
= SCROLLING_FAILED
;
12311 /* Maybe forget recorded base line for line number display. */
12312 if (!just_this_one_p
12313 || current_buffer
->clip_changed
12314 || BEG_UNCHANGED
< CHARPOS (startp
))
12315 w
->base_line_number
= Qnil
;
12317 /* If cursor ends up on a partially visible line,
12318 treat that as being off the bottom of the screen. */
12319 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12321 clear_glyph_matrix (w
->desired_matrix
);
12322 ++extra_scroll_margin_lines
;
12325 rc
= SCROLLING_SUCCESS
;
12332 /* Compute a suitable window start for window W if display of W starts
12333 on a continuation line. Value is non-zero if a new window start
12336 The new window start will be computed, based on W's width, starting
12337 from the start of the continued line. It is the start of the
12338 screen line with the minimum distance from the old start W->start. */
12341 compute_window_start_on_continuation_line (w
)
12344 struct text_pos pos
, start_pos
;
12345 int window_start_changed_p
= 0;
12347 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12349 /* If window start is on a continuation line... Window start may be
12350 < BEGV in case there's invisible text at the start of the
12351 buffer (M-x rmail, for example). */
12352 if (CHARPOS (start_pos
) > BEGV
12353 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12356 struct glyph_row
*row
;
12358 /* Handle the case that the window start is out of range. */
12359 if (CHARPOS (start_pos
) < BEGV
)
12360 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12361 else if (CHARPOS (start_pos
) > ZV
)
12362 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12364 /* Find the start of the continued line. This should be fast
12365 because scan_buffer is fast (newline cache). */
12366 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12367 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12368 row
, DEFAULT_FACE_ID
);
12369 reseat_at_previous_visible_line_start (&it
);
12371 /* If the line start is "too far" away from the window start,
12372 say it takes too much time to compute a new window start. */
12373 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12374 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12376 int min_distance
, distance
;
12378 /* Move forward by display lines to find the new window
12379 start. If window width was enlarged, the new start can
12380 be expected to be > the old start. If window width was
12381 decreased, the new window start will be < the old start.
12382 So, we're looking for the display line start with the
12383 minimum distance from the old window start. */
12384 pos
= it
.current
.pos
;
12385 min_distance
= INFINITY
;
12386 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12387 distance
< min_distance
)
12389 min_distance
= distance
;
12390 pos
= it
.current
.pos
;
12391 move_it_by_lines (&it
, 1, 0);
12394 /* Set the window start there. */
12395 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12396 window_start_changed_p
= 1;
12400 return window_start_changed_p
;
12404 /* Try cursor movement in case text has not changed in window WINDOW,
12405 with window start STARTP. Value is
12407 CURSOR_MOVEMENT_SUCCESS if successful
12409 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12411 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12412 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12413 we want to scroll as if scroll-step were set to 1. See the code.
12415 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12416 which case we have to abort this redisplay, and adjust matrices
12421 CURSOR_MOVEMENT_SUCCESS
,
12422 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12423 CURSOR_MOVEMENT_MUST_SCROLL
,
12424 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12428 try_cursor_movement (window
, startp
, scroll_step
)
12429 Lisp_Object window
;
12430 struct text_pos startp
;
12433 struct window
*w
= XWINDOW (window
);
12434 struct frame
*f
= XFRAME (w
->frame
);
12435 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12438 if (inhibit_try_cursor_movement
)
12442 /* Handle case where text has not changed, only point, and it has
12443 not moved off the frame. */
12444 if (/* Point may be in this window. */
12445 PT
>= CHARPOS (startp
)
12446 /* Selective display hasn't changed. */
12447 && !current_buffer
->clip_changed
12448 /* Function force-mode-line-update is used to force a thorough
12449 redisplay. It sets either windows_or_buffers_changed or
12450 update_mode_lines. So don't take a shortcut here for these
12452 && !update_mode_lines
12453 && !windows_or_buffers_changed
12454 && !cursor_type_changed
12455 /* Can't use this case if highlighting a region. When a
12456 region exists, cursor movement has to do more than just
12458 && !(!NILP (Vtransient_mark_mode
)
12459 && !NILP (current_buffer
->mark_active
))
12460 && NILP (w
->region_showing
)
12461 && NILP (Vshow_trailing_whitespace
)
12462 /* Right after splitting windows, last_point may be nil. */
12463 && INTEGERP (w
->last_point
)
12464 /* This code is not used for mini-buffer for the sake of the case
12465 of redisplaying to replace an echo area message; since in
12466 that case the mini-buffer contents per se are usually
12467 unchanged. This code is of no real use in the mini-buffer
12468 since the handling of this_line_start_pos, etc., in redisplay
12469 handles the same cases. */
12470 && !EQ (window
, minibuf_window
)
12471 /* When splitting windows or for new windows, it happens that
12472 redisplay is called with a nil window_end_vpos or one being
12473 larger than the window. This should really be fixed in
12474 window.c. I don't have this on my list, now, so we do
12475 approximately the same as the old redisplay code. --gerd. */
12476 && INTEGERP (w
->window_end_vpos
)
12477 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12478 && (FRAME_WINDOW_P (f
)
12479 || !overlay_arrow_in_current_buffer_p ()))
12481 int this_scroll_margin
, top_scroll_margin
;
12482 struct glyph_row
*row
= NULL
;
12485 debug_method_add (w
, "cursor movement");
12488 /* Scroll if point within this distance from the top or bottom
12489 of the window. This is a pixel value. */
12490 this_scroll_margin
= max (0, scroll_margin
);
12491 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12492 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12494 top_scroll_margin
= this_scroll_margin
;
12495 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12496 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12498 /* Start with the row the cursor was displayed during the last
12499 not paused redisplay. Give up if that row is not valid. */
12500 if (w
->last_cursor
.vpos
< 0
12501 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12502 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12505 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12506 if (row
->mode_line_p
)
12508 if (!row
->enabled_p
)
12509 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12512 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12515 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12517 if (PT
> XFASTINT (w
->last_point
))
12519 /* Point has moved forward. */
12520 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12521 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12523 xassert (row
->enabled_p
);
12527 /* The end position of a row equals the start position
12528 of the next row. If PT is there, we would rather
12529 display it in the next line. */
12530 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12531 && MATRIX_ROW_END_CHARPOS (row
) == PT
12532 && !cursor_row_p (w
, row
))
12535 /* If within the scroll margin, scroll. Note that
12536 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12537 the next line would be drawn, and that
12538 this_scroll_margin can be zero. */
12539 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12540 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12541 /* Line is completely visible last line in window
12542 and PT is to be set in the next line. */
12543 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12544 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12545 && !row
->ends_at_zv_p
12546 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12549 else if (PT
< XFASTINT (w
->last_point
))
12551 /* Cursor has to be moved backward. Note that PT >=
12552 CHARPOS (startp) because of the outer if-statement. */
12553 while (!row
->mode_line_p
12554 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12555 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12556 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12557 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12558 row
> w
->current_matrix
->rows
12559 && (row
-1)->ends_in_newline_from_string_p
))))
12560 && (row
->y
> top_scroll_margin
12561 || CHARPOS (startp
) == BEGV
))
12563 xassert (row
->enabled_p
);
12567 /* Consider the following case: Window starts at BEGV,
12568 there is invisible, intangible text at BEGV, so that
12569 display starts at some point START > BEGV. It can
12570 happen that we are called with PT somewhere between
12571 BEGV and START. Try to handle that case. */
12572 if (row
< w
->current_matrix
->rows
12573 || row
->mode_line_p
)
12575 row
= w
->current_matrix
->rows
;
12576 if (row
->mode_line_p
)
12580 /* Due to newlines in overlay strings, we may have to
12581 skip forward over overlay strings. */
12582 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12583 && MATRIX_ROW_END_CHARPOS (row
) == PT
12584 && !cursor_row_p (w
, row
))
12587 /* If within the scroll margin, scroll. */
12588 if (row
->y
< top_scroll_margin
12589 && CHARPOS (startp
) != BEGV
)
12594 /* Cursor did not move. So don't scroll even if cursor line
12595 is partially visible, as it was so before. */
12596 rc
= CURSOR_MOVEMENT_SUCCESS
;
12599 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12600 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12602 /* if PT is not in the glyph row, give up. */
12603 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12605 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12606 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12607 && make_cursor_line_fully_visible_p
)
12609 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12610 && !row
->ends_at_zv_p
12611 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12612 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12613 else if (row
->height
> window_box_height (w
))
12615 /* If we end up in a partially visible line, let's
12616 make it fully visible, except when it's taller
12617 than the window, in which case we can't do much
12620 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12624 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12625 if (!cursor_row_fully_visible_p (w
, 0, 1))
12626 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12628 rc
= CURSOR_MOVEMENT_SUCCESS
;
12632 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12637 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12639 rc
= CURSOR_MOVEMENT_SUCCESS
;
12644 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12645 && MATRIX_ROW_START_CHARPOS (row
) == PT
12646 && cursor_row_p (w
, row
));
12655 set_vertical_scroll_bar (w
)
12658 int start
, end
, whole
;
12660 /* Calculate the start and end positions for the current window.
12661 At some point, it would be nice to choose between scrollbars
12662 which reflect the whole buffer size, with special markers
12663 indicating narrowing, and scrollbars which reflect only the
12666 Note that mini-buffers sometimes aren't displaying any text. */
12667 if (!MINI_WINDOW_P (w
)
12668 || (w
== XWINDOW (minibuf_window
)
12669 && NILP (echo_area_buffer
[0])))
12671 struct buffer
*buf
= XBUFFER (w
->buffer
);
12672 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12673 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12674 /* I don't think this is guaranteed to be right. For the
12675 moment, we'll pretend it is. */
12676 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12680 if (whole
< (end
- start
))
12681 whole
= end
- start
;
12684 start
= end
= whole
= 0;
12686 /* Indicate what this scroll bar ought to be displaying now. */
12687 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12691 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12692 selected_window is redisplayed.
12694 We can return without actually redisplaying the window if
12695 fonts_changed_p is nonzero. In that case, redisplay_internal will
12699 redisplay_window (window
, just_this_one_p
)
12700 Lisp_Object window
;
12701 int just_this_one_p
;
12703 struct window
*w
= XWINDOW (window
);
12704 struct frame
*f
= XFRAME (w
->frame
);
12705 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12706 struct buffer
*old
= current_buffer
;
12707 struct text_pos lpoint
, opoint
, startp
;
12708 int update_mode_line
;
12711 /* Record it now because it's overwritten. */
12712 int current_matrix_up_to_date_p
= 0;
12713 int used_current_matrix_p
= 0;
12714 /* This is less strict than current_matrix_up_to_date_p.
12715 It indictes that the buffer contents and narrowing are unchanged. */
12716 int buffer_unchanged_p
= 0;
12717 int temp_scroll_step
= 0;
12718 int count
= SPECPDL_INDEX ();
12720 int centering_position
= -1;
12721 int last_line_misfit
= 0;
12723 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12726 /* W must be a leaf window here. */
12727 xassert (!NILP (w
->buffer
));
12729 *w
->desired_matrix
->method
= 0;
12732 specbind (Qinhibit_point_motion_hooks
, Qt
);
12734 reconsider_clip_changes (w
, buffer
);
12736 /* Has the mode line to be updated? */
12737 update_mode_line
= (!NILP (w
->update_mode_line
)
12738 || update_mode_lines
12739 || buffer
->clip_changed
12740 || buffer
->prevent_redisplay_optimizations_p
);
12742 if (MINI_WINDOW_P (w
))
12744 if (w
== XWINDOW (echo_area_window
)
12745 && !NILP (echo_area_buffer
[0]))
12747 if (update_mode_line
)
12748 /* We may have to update a tty frame's menu bar or a
12749 tool-bar. Example `M-x C-h C-h C-g'. */
12750 goto finish_menu_bars
;
12752 /* We've already displayed the echo area glyphs in this window. */
12753 goto finish_scroll_bars
;
12755 else if ((w
!= XWINDOW (minibuf_window
)
12756 || minibuf_level
== 0)
12757 /* When buffer is nonempty, redisplay window normally. */
12758 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12759 /* Quail displays non-mini buffers in minibuffer window.
12760 In that case, redisplay the window normally. */
12761 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12763 /* W is a mini-buffer window, but it's not active, so clear
12765 int yb
= window_text_bottom_y (w
);
12766 struct glyph_row
*row
;
12769 for (y
= 0, row
= w
->desired_matrix
->rows
;
12771 y
+= row
->height
, ++row
)
12772 blank_row (w
, row
, y
);
12773 goto finish_scroll_bars
;
12776 clear_glyph_matrix (w
->desired_matrix
);
12779 /* Otherwise set up data on this window; select its buffer and point
12781 /* Really select the buffer, for the sake of buffer-local
12783 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12784 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12786 current_matrix_up_to_date_p
12787 = (!NILP (w
->window_end_valid
)
12788 && !current_buffer
->clip_changed
12789 && !current_buffer
->prevent_redisplay_optimizations_p
12790 && XFASTINT (w
->last_modified
) >= MODIFF
12791 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12794 = (!NILP (w
->window_end_valid
)
12795 && !current_buffer
->clip_changed
12796 && XFASTINT (w
->last_modified
) >= MODIFF
12797 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12799 /* When windows_or_buffers_changed is non-zero, we can't rely on
12800 the window end being valid, so set it to nil there. */
12801 if (windows_or_buffers_changed
)
12803 /* If window starts on a continuation line, maybe adjust the
12804 window start in case the window's width changed. */
12805 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12806 compute_window_start_on_continuation_line (w
);
12808 w
->window_end_valid
= Qnil
;
12811 /* Some sanity checks. */
12812 CHECK_WINDOW_END (w
);
12813 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12815 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12818 /* If %c is in mode line, update it if needed. */
12819 if (!NILP (w
->column_number_displayed
)
12820 /* This alternative quickly identifies a common case
12821 where no change is needed. */
12822 && !(PT
== XFASTINT (w
->last_point
)
12823 && XFASTINT (w
->last_modified
) >= MODIFF
12824 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12825 && (XFASTINT (w
->column_number_displayed
)
12826 != (int) current_column ())) /* iftc */
12827 update_mode_line
= 1;
12829 /* Count number of windows showing the selected buffer. An indirect
12830 buffer counts as its base buffer. */
12831 if (!just_this_one_p
)
12833 struct buffer
*current_base
, *window_base
;
12834 current_base
= current_buffer
;
12835 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12836 if (current_base
->base_buffer
)
12837 current_base
= current_base
->base_buffer
;
12838 if (window_base
->base_buffer
)
12839 window_base
= window_base
->base_buffer
;
12840 if (current_base
== window_base
)
12844 /* Point refers normally to the selected window. For any other
12845 window, set up appropriate value. */
12846 if (!EQ (window
, selected_window
))
12848 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12849 int new_pt_byte
= marker_byte_position (w
->pointm
);
12853 new_pt_byte
= BEGV_BYTE
;
12854 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12856 else if (new_pt
> (ZV
- 1))
12859 new_pt_byte
= ZV_BYTE
;
12860 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12863 /* We don't use SET_PT so that the point-motion hooks don't run. */
12864 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12867 /* If any of the character widths specified in the display table
12868 have changed, invalidate the width run cache. It's true that
12869 this may be a bit late to catch such changes, but the rest of
12870 redisplay goes (non-fatally) haywire when the display table is
12871 changed, so why should we worry about doing any better? */
12872 if (current_buffer
->width_run_cache
)
12874 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12876 if (! disptab_matches_widthtab (disptab
,
12877 XVECTOR (current_buffer
->width_table
)))
12879 invalidate_region_cache (current_buffer
,
12880 current_buffer
->width_run_cache
,
12882 recompute_width_table (current_buffer
, disptab
);
12886 /* If window-start is screwed up, choose a new one. */
12887 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12890 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12892 /* If someone specified a new starting point but did not insist,
12893 check whether it can be used. */
12894 if (!NILP (w
->optional_new_start
)
12895 && CHARPOS (startp
) >= BEGV
12896 && CHARPOS (startp
) <= ZV
)
12898 w
->optional_new_start
= Qnil
;
12899 start_display (&it
, w
, startp
);
12900 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12901 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12902 if (IT_CHARPOS (it
) == PT
)
12903 w
->force_start
= Qt
;
12904 /* IT may overshoot PT if text at PT is invisible. */
12905 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12906 w
->force_start
= Qt
;
12909 /* Handle case where place to start displaying has been specified,
12910 unless the specified location is outside the accessible range. */
12911 if (!NILP (w
->force_start
)
12912 || w
->frozen_window_start_p
)
12914 /* We set this later on if we have to adjust point. */
12918 w
->force_start
= Qnil
;
12920 w
->window_end_valid
= Qnil
;
12922 /* Forget any recorded base line for line number display. */
12923 if (!buffer_unchanged_p
)
12924 w
->base_line_number
= Qnil
;
12926 /* Redisplay the mode line. Select the buffer properly for that.
12927 Also, run the hook window-scroll-functions
12928 because we have scrolled. */
12929 /* Note, we do this after clearing force_start because
12930 if there's an error, it is better to forget about force_start
12931 than to get into an infinite loop calling the hook functions
12932 and having them get more errors. */
12933 if (!update_mode_line
12934 || ! NILP (Vwindow_scroll_functions
))
12936 update_mode_line
= 1;
12937 w
->update_mode_line
= Qt
;
12938 startp
= run_window_scroll_functions (window
, startp
);
12941 w
->last_modified
= make_number (0);
12942 w
->last_overlay_modified
= make_number (0);
12943 if (CHARPOS (startp
) < BEGV
)
12944 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12945 else if (CHARPOS (startp
) > ZV
)
12946 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12948 /* Redisplay, then check if cursor has been set during the
12949 redisplay. Give up if new fonts were loaded. */
12950 val
= try_window (window
, startp
, 1);
12953 w
->force_start
= Qt
;
12954 clear_glyph_matrix (w
->desired_matrix
);
12955 goto need_larger_matrices
;
12957 /* Point was outside the scroll margins. */
12959 new_vpos
= window_box_height (w
) / 2;
12961 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12963 /* If point does not appear, try to move point so it does
12964 appear. The desired matrix has been built above, so we
12965 can use it here. */
12966 new_vpos
= window_box_height (w
) / 2;
12969 if (!cursor_row_fully_visible_p (w
, 0, 0))
12971 /* Point does appear, but on a line partly visible at end of window.
12972 Move it back to a fully-visible line. */
12973 new_vpos
= window_box_height (w
);
12976 /* If we need to move point for either of the above reasons,
12977 now actually do it. */
12980 struct glyph_row
*row
;
12982 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12983 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12986 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12987 MATRIX_ROW_START_BYTEPOS (row
));
12989 if (w
!= XWINDOW (selected_window
))
12990 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12991 else if (current_buffer
== old
)
12992 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12994 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12996 /* If we are highlighting the region, then we just changed
12997 the region, so redisplay to show it. */
12998 if (!NILP (Vtransient_mark_mode
)
12999 && !NILP (current_buffer
->mark_active
))
13001 clear_glyph_matrix (w
->desired_matrix
);
13002 if (!try_window (window
, startp
, 0))
13003 goto need_larger_matrices
;
13008 debug_method_add (w
, "forced window start");
13013 /* Handle case where text has not changed, only point, and it has
13014 not moved off the frame, and we are not retrying after hscroll.
13015 (current_matrix_up_to_date_p is nonzero when retrying.) */
13016 if (current_matrix_up_to_date_p
13017 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13018 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13022 case CURSOR_MOVEMENT_SUCCESS
:
13023 used_current_matrix_p
= 1;
13026 #if 0 /* try_cursor_movement never returns this value. */
13027 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13028 goto need_larger_matrices
;
13031 case CURSOR_MOVEMENT_MUST_SCROLL
:
13032 goto try_to_scroll
;
13038 /* If current starting point was originally the beginning of a line
13039 but no longer is, find a new starting point. */
13040 else if (!NILP (w
->start_at_line_beg
)
13041 && !(CHARPOS (startp
) <= BEGV
13042 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13045 debug_method_add (w
, "recenter 1");
13050 /* Try scrolling with try_window_id. Value is > 0 if update has
13051 been done, it is -1 if we know that the same window start will
13052 not work. It is 0 if unsuccessful for some other reason. */
13053 else if ((tem
= try_window_id (w
)) != 0)
13056 debug_method_add (w
, "try_window_id %d", tem
);
13059 if (fonts_changed_p
)
13060 goto need_larger_matrices
;
13064 /* Otherwise try_window_id has returned -1 which means that we
13065 don't want the alternative below this comment to execute. */
13067 else if (CHARPOS (startp
) >= BEGV
13068 && CHARPOS (startp
) <= ZV
13069 && PT
>= CHARPOS (startp
)
13070 && (CHARPOS (startp
) < ZV
13071 /* Avoid starting at end of buffer. */
13072 || CHARPOS (startp
) == BEGV
13073 || (XFASTINT (w
->last_modified
) >= MODIFF
13074 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13077 /* If first window line is a continuation line, and window start
13078 is inside the modified region, but the first change is before
13079 current window start, we must select a new window start.*/
13080 if (NILP (w
->start_at_line_beg
)
13081 && CHARPOS (startp
) > BEGV
)
13083 /* Make sure beg_unchanged and end_unchanged are up to date.
13084 Do it only if buffer has really changed. This may or may
13085 not have been done by try_window_id (see which) already. */
13086 if (MODIFF
> SAVE_MODIFF
13087 /* This seems to happen sometimes after saving a buffer. */
13088 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13090 if (GPT
- BEG
< BEG_UNCHANGED
)
13091 BEG_UNCHANGED
= GPT
- BEG
;
13092 if (Z
- GPT
< END_UNCHANGED
)
13093 END_UNCHANGED
= Z
- GPT
;
13096 if (CHARPOS (startp
) > BEG
+ BEG_UNCHANGED
13097 && CHARPOS (startp
) <= Z
- END_UNCHANGED
)
13099 /* There doesn't seems to be a simple way to find a new
13100 window start that is near the old window start, so
13101 we just recenter. */
13107 debug_method_add (w
, "same window start");
13110 /* Try to redisplay starting at same place as before.
13111 If point has not moved off frame, accept the results. */
13112 if (!current_matrix_up_to_date_p
13113 /* Don't use try_window_reusing_current_matrix in this case
13114 because a window scroll function can have changed the
13116 || !NILP (Vwindow_scroll_functions
)
13117 || MINI_WINDOW_P (w
)
13118 || !(used_current_matrix_p
13119 = try_window_reusing_current_matrix (w
)))
13121 IF_DEBUG (debug_method_add (w
, "1"));
13122 if (try_window (window
, startp
, 1) < 0)
13123 /* -1 means we need to scroll.
13124 0 means we need new matrices, but fonts_changed_p
13125 is set in that case, so we will detect it below. */
13126 goto try_to_scroll
;
13129 if (fonts_changed_p
)
13130 goto need_larger_matrices
;
13132 if (w
->cursor
.vpos
>= 0)
13134 if (!just_this_one_p
13135 || current_buffer
->clip_changed
13136 || BEG_UNCHANGED
< CHARPOS (startp
))
13137 /* Forget any recorded base line for line number display. */
13138 w
->base_line_number
= Qnil
;
13140 if (!cursor_row_fully_visible_p (w
, 1, 0))
13142 clear_glyph_matrix (w
->desired_matrix
);
13143 last_line_misfit
= 1;
13145 /* Drop through and scroll. */
13150 clear_glyph_matrix (w
->desired_matrix
);
13155 w
->last_modified
= make_number (0);
13156 w
->last_overlay_modified
= make_number (0);
13158 /* Redisplay the mode line. Select the buffer properly for that. */
13159 if (!update_mode_line
)
13161 update_mode_line
= 1;
13162 w
->update_mode_line
= Qt
;
13165 /* Try to scroll by specified few lines. */
13166 if ((scroll_conservatively
13168 || temp_scroll_step
13169 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13170 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13171 && !current_buffer
->clip_changed
13172 && CHARPOS (startp
) >= BEGV
13173 && CHARPOS (startp
) <= ZV
)
13175 /* The function returns -1 if new fonts were loaded, 1 if
13176 successful, 0 if not successful. */
13177 int rc
= try_scrolling (window
, just_this_one_p
,
13178 scroll_conservatively
,
13180 temp_scroll_step
, last_line_misfit
);
13183 case SCROLLING_SUCCESS
:
13186 case SCROLLING_NEED_LARGER_MATRICES
:
13187 goto need_larger_matrices
;
13189 case SCROLLING_FAILED
:
13197 /* Finally, just choose place to start which centers point */
13200 if (centering_position
< 0)
13201 centering_position
= window_box_height (w
) / 2;
13204 debug_method_add (w
, "recenter");
13207 /* w->vscroll = 0; */
13209 /* Forget any previously recorded base line for line number display. */
13210 if (!buffer_unchanged_p
)
13211 w
->base_line_number
= Qnil
;
13213 /* Move backward half the height of the window. */
13214 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13215 it
.current_y
= it
.last_visible_y
;
13216 move_it_vertically_backward (&it
, centering_position
);
13217 xassert (IT_CHARPOS (it
) >= BEGV
);
13219 /* The function move_it_vertically_backward may move over more
13220 than the specified y-distance. If it->w is small, e.g. a
13221 mini-buffer window, we may end up in front of the window's
13222 display area. Start displaying at the start of the line
13223 containing PT in this case. */
13224 if (it
.current_y
<= 0)
13226 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13227 move_it_vertically_backward (&it
, 0);
13229 /* I think this assert is bogus if buffer contains
13230 invisible text or images. KFS. */
13231 xassert (IT_CHARPOS (it
) <= PT
);
13236 it
.current_x
= it
.hpos
= 0;
13238 /* Set startp here explicitly in case that helps avoid an infinite loop
13239 in case the window-scroll-functions functions get errors. */
13240 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13242 /* Run scroll hooks. */
13243 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13245 /* Redisplay the window. */
13246 if (!current_matrix_up_to_date_p
13247 || windows_or_buffers_changed
13248 || cursor_type_changed
13249 /* Don't use try_window_reusing_current_matrix in this case
13250 because it can have changed the buffer. */
13251 || !NILP (Vwindow_scroll_functions
)
13252 || !just_this_one_p
13253 || MINI_WINDOW_P (w
)
13254 || !(used_current_matrix_p
13255 = try_window_reusing_current_matrix (w
)))
13256 try_window (window
, startp
, 0);
13258 /* If new fonts have been loaded (due to fontsets), give up. We
13259 have to start a new redisplay since we need to re-adjust glyph
13261 if (fonts_changed_p
)
13262 goto need_larger_matrices
;
13264 /* If cursor did not appear assume that the middle of the window is
13265 in the first line of the window. Do it again with the next line.
13266 (Imagine a window of height 100, displaying two lines of height
13267 60. Moving back 50 from it->last_visible_y will end in the first
13269 if (w
->cursor
.vpos
< 0)
13271 if (!NILP (w
->window_end_valid
)
13272 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13274 clear_glyph_matrix (w
->desired_matrix
);
13275 move_it_by_lines (&it
, 1, 0);
13276 try_window (window
, it
.current
.pos
, 0);
13278 else if (PT
< IT_CHARPOS (it
))
13280 clear_glyph_matrix (w
->desired_matrix
);
13281 move_it_by_lines (&it
, -1, 0);
13282 try_window (window
, it
.current
.pos
, 0);
13286 /* Not much we can do about it. */
13290 /* Consider the following case: Window starts at BEGV, there is
13291 invisible, intangible text at BEGV, so that display starts at
13292 some point START > BEGV. It can happen that we are called with
13293 PT somewhere between BEGV and START. Try to handle that case. */
13294 if (w
->cursor
.vpos
< 0)
13296 struct glyph_row
*row
= w
->current_matrix
->rows
;
13297 if (row
->mode_line_p
)
13299 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13302 if (!cursor_row_fully_visible_p (w
, 0, 0))
13304 /* If vscroll is enabled, disable it and try again. */
13308 clear_glyph_matrix (w
->desired_matrix
);
13312 /* If centering point failed to make the whole line visible,
13313 put point at the top instead. That has to make the whole line
13314 visible, if it can be done. */
13315 if (centering_position
== 0)
13318 clear_glyph_matrix (w
->desired_matrix
);
13319 centering_position
= 0;
13325 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13326 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13327 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13330 /* Display the mode line, if we must. */
13331 if ((update_mode_line
13332 /* If window not full width, must redo its mode line
13333 if (a) the window to its side is being redone and
13334 (b) we do a frame-based redisplay. This is a consequence
13335 of how inverted lines are drawn in frame-based redisplay. */
13336 || (!just_this_one_p
13337 && !FRAME_WINDOW_P (f
)
13338 && !WINDOW_FULL_WIDTH_P (w
))
13339 /* Line number to display. */
13340 || INTEGERP (w
->base_line_pos
)
13341 /* Column number is displayed and different from the one displayed. */
13342 || (!NILP (w
->column_number_displayed
)
13343 && (XFASTINT (w
->column_number_displayed
)
13344 != (int) current_column ()))) /* iftc */
13345 /* This means that the window has a mode line. */
13346 && (WINDOW_WANTS_MODELINE_P (w
)
13347 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13349 display_mode_lines (w
);
13351 /* If mode line height has changed, arrange for a thorough
13352 immediate redisplay using the correct mode line height. */
13353 if (WINDOW_WANTS_MODELINE_P (w
)
13354 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13356 fonts_changed_p
= 1;
13357 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13358 = DESIRED_MODE_LINE_HEIGHT (w
);
13361 /* If top line height has changed, arrange for a thorough
13362 immediate redisplay using the correct mode line height. */
13363 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13364 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13366 fonts_changed_p
= 1;
13367 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13368 = DESIRED_HEADER_LINE_HEIGHT (w
);
13371 if (fonts_changed_p
)
13372 goto need_larger_matrices
;
13375 if (!line_number_displayed
13376 && !BUFFERP (w
->base_line_pos
))
13378 w
->base_line_pos
= Qnil
;
13379 w
->base_line_number
= Qnil
;
13384 /* When we reach a frame's selected window, redo the frame's menu bar. */
13385 if (update_mode_line
13386 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13388 int redisplay_menu_p
= 0;
13389 int redisplay_tool_bar_p
= 0;
13391 if (FRAME_WINDOW_P (f
))
13393 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13394 || defined (USE_GTK)
13395 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13397 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13401 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13403 if (redisplay_menu_p
)
13404 display_menu_bar (w
);
13406 #ifdef HAVE_WINDOW_SYSTEM
13408 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13410 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13411 && (FRAME_TOOL_BAR_LINES (f
) > 0
13412 || auto_resize_tool_bars_p
);
13416 if (redisplay_tool_bar_p
)
13417 redisplay_tool_bar (f
);
13421 #ifdef HAVE_WINDOW_SYSTEM
13422 if (FRAME_WINDOW_P (f
)
13423 && update_window_fringes (w
, (just_this_one_p
13424 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13425 || w
->pseudo_window_p
)))
13429 if (draw_window_fringes (w
, 1))
13430 x_draw_vertical_border (w
);
13434 #endif /* HAVE_WINDOW_SYSTEM */
13436 /* We go to this label, with fonts_changed_p nonzero,
13437 if it is necessary to try again using larger glyph matrices.
13438 We have to redeem the scroll bar even in this case,
13439 because the loop in redisplay_internal expects that. */
13440 need_larger_matrices
:
13442 finish_scroll_bars
:
13444 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13446 /* Set the thumb's position and size. */
13447 set_vertical_scroll_bar (w
);
13449 /* Note that we actually used the scroll bar attached to this
13450 window, so it shouldn't be deleted at the end of redisplay. */
13451 redeem_scroll_bar_hook (w
);
13454 /* Restore current_buffer and value of point in it. */
13455 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13456 set_buffer_internal_1 (old
);
13457 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13459 unbind_to (count
, Qnil
);
13463 /* Build the complete desired matrix of WINDOW with a window start
13464 buffer position POS.
13466 Value is 1 if successful. It is zero if fonts were loaded during
13467 redisplay which makes re-adjusting glyph matrices necessary, and -1
13468 if point would appear in the scroll margins.
13469 (We check that only if CHECK_MARGINS is nonzero. */
13472 try_window (window
, pos
, check_margins
)
13473 Lisp_Object window
;
13474 struct text_pos pos
;
13477 struct window
*w
= XWINDOW (window
);
13479 struct glyph_row
*last_text_row
= NULL
;
13481 /* Make POS the new window start. */
13482 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13484 /* Mark cursor position as unknown. No overlay arrow seen. */
13485 w
->cursor
.vpos
= -1;
13486 overlay_arrow_seen
= 0;
13488 /* Initialize iterator and info to start at POS. */
13489 start_display (&it
, w
, pos
);
13491 /* Display all lines of W. */
13492 while (it
.current_y
< it
.last_visible_y
)
13494 if (display_line (&it
))
13495 last_text_row
= it
.glyph_row
- 1;
13496 if (fonts_changed_p
)
13500 /* Don't let the cursor end in the scroll margins. */
13502 && !MINI_WINDOW_P (w
))
13504 int this_scroll_margin
;
13506 this_scroll_margin
= max (0, scroll_margin
);
13507 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13508 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13510 if ((w
->cursor
.y
< this_scroll_margin
13511 && CHARPOS (pos
) > BEGV
13512 && IT_CHARPOS (it
) < ZV
)
13513 /* rms: considering make_cursor_line_fully_visible_p here
13514 seems to give wrong results. We don't want to recenter
13515 when the last line is partly visible, we want to allow
13516 that case to be handled in the usual way. */
13517 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13519 w
->cursor
.vpos
= -1;
13520 clear_glyph_matrix (w
->desired_matrix
);
13525 /* If bottom moved off end of frame, change mode line percentage. */
13526 if (XFASTINT (w
->window_end_pos
) <= 0
13527 && Z
!= IT_CHARPOS (it
))
13528 w
->update_mode_line
= Qt
;
13530 /* Set window_end_pos to the offset of the last character displayed
13531 on the window from the end of current_buffer. Set
13532 window_end_vpos to its row number. */
13535 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13536 w
->window_end_bytepos
13537 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13539 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13541 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13542 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13543 ->displays_text_p
);
13547 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13548 w
->window_end_pos
= make_number (Z
- ZV
);
13549 w
->window_end_vpos
= make_number (0);
13552 /* But that is not valid info until redisplay finishes. */
13553 w
->window_end_valid
= Qnil
;
13559 /************************************************************************
13560 Window redisplay reusing current matrix when buffer has not changed
13561 ************************************************************************/
13563 /* Try redisplay of window W showing an unchanged buffer with a
13564 different window start than the last time it was displayed by
13565 reusing its current matrix. Value is non-zero if successful.
13566 W->start is the new window start. */
13569 try_window_reusing_current_matrix (w
)
13572 struct frame
*f
= XFRAME (w
->frame
);
13573 struct glyph_row
*row
, *bottom_row
;
13576 struct text_pos start
, new_start
;
13577 int nrows_scrolled
, i
;
13578 struct glyph_row
*last_text_row
;
13579 struct glyph_row
*last_reused_text_row
;
13580 struct glyph_row
*start_row
;
13581 int start_vpos
, min_y
, max_y
;
13584 if (inhibit_try_window_reusing
)
13588 if (/* This function doesn't handle terminal frames. */
13589 !FRAME_WINDOW_P (f
)
13590 /* Don't try to reuse the display if windows have been split
13592 || windows_or_buffers_changed
13593 || cursor_type_changed
)
13596 /* Can't do this if region may have changed. */
13597 if ((!NILP (Vtransient_mark_mode
)
13598 && !NILP (current_buffer
->mark_active
))
13599 || !NILP (w
->region_showing
)
13600 || !NILP (Vshow_trailing_whitespace
))
13603 /* If top-line visibility has changed, give up. */
13604 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13605 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13608 /* Give up if old or new display is scrolled vertically. We could
13609 make this function handle this, but right now it doesn't. */
13610 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13611 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13614 /* The variable new_start now holds the new window start. The old
13615 start `start' can be determined from the current matrix. */
13616 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13617 start
= start_row
->start
.pos
;
13618 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13620 /* Clear the desired matrix for the display below. */
13621 clear_glyph_matrix (w
->desired_matrix
);
13623 if (CHARPOS (new_start
) <= CHARPOS (start
))
13627 /* Don't use this method if the display starts with an ellipsis
13628 displayed for invisible text. It's not easy to handle that case
13629 below, and it's certainly not worth the effort since this is
13630 not a frequent case. */
13631 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13634 IF_DEBUG (debug_method_add (w
, "twu1"));
13636 /* Display up to a row that can be reused. The variable
13637 last_text_row is set to the last row displayed that displays
13638 text. Note that it.vpos == 0 if or if not there is a
13639 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13640 start_display (&it
, w
, new_start
);
13641 first_row_y
= it
.current_y
;
13642 w
->cursor
.vpos
= -1;
13643 last_text_row
= last_reused_text_row
= NULL
;
13645 while (it
.current_y
< it
.last_visible_y
13646 && !fonts_changed_p
)
13648 /* If we have reached into the characters in the START row,
13649 that means the line boundaries have changed. So we
13650 can't start copying with the row START. Maybe it will
13651 work to start copying with the following row. */
13652 while (IT_CHARPOS (it
) > CHARPOS (start
))
13654 /* Advance to the next row as the "start". */
13656 start
= start_row
->start
.pos
;
13657 /* If there are no more rows to try, or just one, give up. */
13658 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13659 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13660 || CHARPOS (start
) == ZV
)
13662 clear_glyph_matrix (w
->desired_matrix
);
13666 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13668 /* If we have reached alignment,
13669 we can copy the rest of the rows. */
13670 if (IT_CHARPOS (it
) == CHARPOS (start
))
13673 if (display_line (&it
))
13674 last_text_row
= it
.glyph_row
- 1;
13677 /* A value of current_y < last_visible_y means that we stopped
13678 at the previous window start, which in turn means that we
13679 have at least one reusable row. */
13680 if (it
.current_y
< it
.last_visible_y
)
13682 /* IT.vpos always starts from 0; it counts text lines. */
13683 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13685 /* Find PT if not already found in the lines displayed. */
13686 if (w
->cursor
.vpos
< 0)
13688 int dy
= it
.current_y
- start_row
->y
;
13690 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13691 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13693 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13694 dy
, nrows_scrolled
);
13697 clear_glyph_matrix (w
->desired_matrix
);
13702 /* Scroll the display. Do it before the current matrix is
13703 changed. The problem here is that update has not yet
13704 run, i.e. part of the current matrix is not up to date.
13705 scroll_run_hook will clear the cursor, and use the
13706 current matrix to get the height of the row the cursor is
13708 run
.current_y
= start_row
->y
;
13709 run
.desired_y
= it
.current_y
;
13710 run
.height
= it
.last_visible_y
- it
.current_y
;
13712 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13715 rif
->update_window_begin_hook (w
);
13716 rif
->clear_window_mouse_face (w
);
13717 rif
->scroll_run_hook (w
, &run
);
13718 rif
->update_window_end_hook (w
, 0, 0);
13722 /* Shift current matrix down by nrows_scrolled lines. */
13723 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13724 rotate_matrix (w
->current_matrix
,
13726 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13729 /* Disable lines that must be updated. */
13730 for (i
= 0; i
< it
.vpos
; ++i
)
13731 (start_row
+ i
)->enabled_p
= 0;
13733 /* Re-compute Y positions. */
13734 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13735 max_y
= it
.last_visible_y
;
13736 for (row
= start_row
+ nrows_scrolled
;
13740 row
->y
= it
.current_y
;
13741 row
->visible_height
= row
->height
;
13743 if (row
->y
< min_y
)
13744 row
->visible_height
-= min_y
- row
->y
;
13745 if (row
->y
+ row
->height
> max_y
)
13746 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13747 row
->redraw_fringe_bitmaps_p
= 1;
13749 it
.current_y
+= row
->height
;
13751 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13752 last_reused_text_row
= row
;
13753 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13757 /* Disable lines in the current matrix which are now
13758 below the window. */
13759 for (++row
; row
< bottom_row
; ++row
)
13760 row
->enabled_p
= row
->mode_line_p
= 0;
13763 /* Update window_end_pos etc.; last_reused_text_row is the last
13764 reused row from the current matrix containing text, if any.
13765 The value of last_text_row is the last displayed line
13766 containing text. */
13767 if (last_reused_text_row
)
13769 w
->window_end_bytepos
13770 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13772 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13774 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13775 w
->current_matrix
));
13777 else if (last_text_row
)
13779 w
->window_end_bytepos
13780 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13782 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13784 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13788 /* This window must be completely empty. */
13789 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13790 w
->window_end_pos
= make_number (Z
- ZV
);
13791 w
->window_end_vpos
= make_number (0);
13793 w
->window_end_valid
= Qnil
;
13795 /* Update hint: don't try scrolling again in update_window. */
13796 w
->desired_matrix
->no_scrolling_p
= 1;
13799 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13803 else if (CHARPOS (new_start
) > CHARPOS (start
))
13805 struct glyph_row
*pt_row
, *row
;
13806 struct glyph_row
*first_reusable_row
;
13807 struct glyph_row
*first_row_to_display
;
13809 int yb
= window_text_bottom_y (w
);
13811 /* Find the row starting at new_start, if there is one. Don't
13812 reuse a partially visible line at the end. */
13813 first_reusable_row
= start_row
;
13814 while (first_reusable_row
->enabled_p
13815 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13816 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13817 < CHARPOS (new_start
)))
13818 ++first_reusable_row
;
13820 /* Give up if there is no row to reuse. */
13821 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13822 || !first_reusable_row
->enabled_p
13823 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13824 != CHARPOS (new_start
)))
13827 /* We can reuse fully visible rows beginning with
13828 first_reusable_row to the end of the window. Set
13829 first_row_to_display to the first row that cannot be reused.
13830 Set pt_row to the row containing point, if there is any. */
13832 for (first_row_to_display
= first_reusable_row
;
13833 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13834 ++first_row_to_display
)
13836 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13837 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13838 pt_row
= first_row_to_display
;
13841 /* Start displaying at the start of first_row_to_display. */
13842 xassert (first_row_to_display
->y
< yb
);
13843 init_to_row_start (&it
, w
, first_row_to_display
);
13845 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13847 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13849 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13850 + WINDOW_HEADER_LINE_HEIGHT (w
));
13852 /* Display lines beginning with first_row_to_display in the
13853 desired matrix. Set last_text_row to the last row displayed
13854 that displays text. */
13855 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13856 if (pt_row
== NULL
)
13857 w
->cursor
.vpos
= -1;
13858 last_text_row
= NULL
;
13859 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13860 if (display_line (&it
))
13861 last_text_row
= it
.glyph_row
- 1;
13863 /* Give up If point isn't in a row displayed or reused. */
13864 if (w
->cursor
.vpos
< 0)
13866 clear_glyph_matrix (w
->desired_matrix
);
13870 /* If point is in a reused row, adjust y and vpos of the cursor
13874 w
->cursor
.vpos
-= nrows_scrolled
;
13875 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13878 /* Scroll the display. */
13879 run
.current_y
= first_reusable_row
->y
;
13880 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13881 run
.height
= it
.last_visible_y
- run
.current_y
;
13882 dy
= run
.current_y
- run
.desired_y
;
13887 rif
->update_window_begin_hook (w
);
13888 rif
->clear_window_mouse_face (w
);
13889 rif
->scroll_run_hook (w
, &run
);
13890 rif
->update_window_end_hook (w
, 0, 0);
13894 /* Adjust Y positions of reused rows. */
13895 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13896 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13897 max_y
= it
.last_visible_y
;
13898 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13901 row
->visible_height
= row
->height
;
13902 if (row
->y
< min_y
)
13903 row
->visible_height
-= min_y
- row
->y
;
13904 if (row
->y
+ row
->height
> max_y
)
13905 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13906 row
->redraw_fringe_bitmaps_p
= 1;
13909 /* Scroll the current matrix. */
13910 xassert (nrows_scrolled
> 0);
13911 rotate_matrix (w
->current_matrix
,
13913 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13916 /* Disable rows not reused. */
13917 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13918 row
->enabled_p
= 0;
13920 /* Point may have moved to a different line, so we cannot assume that
13921 the previous cursor position is valid; locate the correct row. */
13924 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13925 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13929 w
->cursor
.y
= row
->y
;
13931 if (row
< bottom_row
)
13933 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13934 while (glyph
->charpos
< PT
)
13937 w
->cursor
.x
+= glyph
->pixel_width
;
13943 /* Adjust window end. A null value of last_text_row means that
13944 the window end is in reused rows which in turn means that
13945 only its vpos can have changed. */
13948 w
->window_end_bytepos
13949 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13951 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13953 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13958 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13961 w
->window_end_valid
= Qnil
;
13962 w
->desired_matrix
->no_scrolling_p
= 1;
13965 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13975 /************************************************************************
13976 Window redisplay reusing current matrix when buffer has changed
13977 ************************************************************************/
13979 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13980 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13982 static struct glyph_row
*
13983 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13984 struct glyph_row
*));
13987 /* Return the last row in MATRIX displaying text. If row START is
13988 non-null, start searching with that row. IT gives the dimensions
13989 of the display. Value is null if matrix is empty; otherwise it is
13990 a pointer to the row found. */
13992 static struct glyph_row
*
13993 find_last_row_displaying_text (matrix
, it
, start
)
13994 struct glyph_matrix
*matrix
;
13996 struct glyph_row
*start
;
13998 struct glyph_row
*row
, *row_found
;
14000 /* Set row_found to the last row in IT->w's current matrix
14001 displaying text. The loop looks funny but think of partially
14004 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14005 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14007 xassert (row
->enabled_p
);
14009 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14018 /* Return the last row in the current matrix of W that is not affected
14019 by changes at the start of current_buffer that occurred since W's
14020 current matrix was built. Value is null if no such row exists.
14022 BEG_UNCHANGED us the number of characters unchanged at the start of
14023 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14024 first changed character in current_buffer. Characters at positions <
14025 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14026 when the current matrix was built. */
14028 static struct glyph_row
*
14029 find_last_unchanged_at_beg_row (w
)
14032 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14033 struct glyph_row
*row
;
14034 struct glyph_row
*row_found
= NULL
;
14035 int yb
= window_text_bottom_y (w
);
14037 /* Find the last row displaying unchanged text. */
14038 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14039 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14040 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14042 if (/* If row ends before first_changed_pos, it is unchanged,
14043 except in some case. */
14044 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14045 /* When row ends in ZV and we write at ZV it is not
14047 && !row
->ends_at_zv_p
14048 /* When first_changed_pos is the end of a continued line,
14049 row is not unchanged because it may be no longer
14051 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14052 && (row
->continued_p
14053 || row
->exact_window_width_line_p
)))
14056 /* Stop if last visible row. */
14057 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14067 /* Find the first glyph row in the current matrix of W that is not
14068 affected by changes at the end of current_buffer since the
14069 time W's current matrix was built.
14071 Return in *DELTA the number of chars by which buffer positions in
14072 unchanged text at the end of current_buffer must be adjusted.
14074 Return in *DELTA_BYTES the corresponding number of bytes.
14076 Value is null if no such row exists, i.e. all rows are affected by
14079 static struct glyph_row
*
14080 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14082 int *delta
, *delta_bytes
;
14084 struct glyph_row
*row
;
14085 struct glyph_row
*row_found
= NULL
;
14087 *delta
= *delta_bytes
= 0;
14089 /* Display must not have been paused, otherwise the current matrix
14090 is not up to date. */
14091 if (NILP (w
->window_end_valid
))
14094 /* A value of window_end_pos >= END_UNCHANGED means that the window
14095 end is in the range of changed text. If so, there is no
14096 unchanged row at the end of W's current matrix. */
14097 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14100 /* Set row to the last row in W's current matrix displaying text. */
14101 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14103 /* If matrix is entirely empty, no unchanged row exists. */
14104 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14106 /* The value of row is the last glyph row in the matrix having a
14107 meaningful buffer position in it. The end position of row
14108 corresponds to window_end_pos. This allows us to translate
14109 buffer positions in the current matrix to current buffer
14110 positions for characters not in changed text. */
14111 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14112 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14113 int last_unchanged_pos
, last_unchanged_pos_old
;
14114 struct glyph_row
*first_text_row
14115 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14117 *delta
= Z
- Z_old
;
14118 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14120 /* Set last_unchanged_pos to the buffer position of the last
14121 character in the buffer that has not been changed. Z is the
14122 index + 1 of the last character in current_buffer, i.e. by
14123 subtracting END_UNCHANGED we get the index of the last
14124 unchanged character, and we have to add BEG to get its buffer
14126 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14127 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14129 /* Search backward from ROW for a row displaying a line that
14130 starts at a minimum position >= last_unchanged_pos_old. */
14131 for (; row
> first_text_row
; --row
)
14133 /* This used to abort, but it can happen.
14134 It is ok to just stop the search instead here. KFS. */
14135 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14138 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14143 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14150 /* Make sure that glyph rows in the current matrix of window W
14151 reference the same glyph memory as corresponding rows in the
14152 frame's frame matrix. This function is called after scrolling W's
14153 current matrix on a terminal frame in try_window_id and
14154 try_window_reusing_current_matrix. */
14157 sync_frame_with_window_matrix_rows (w
)
14160 struct frame
*f
= XFRAME (w
->frame
);
14161 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14163 /* Preconditions: W must be a leaf window and full-width. Its frame
14164 must have a frame matrix. */
14165 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14166 xassert (WINDOW_FULL_WIDTH_P (w
));
14167 xassert (!FRAME_WINDOW_P (f
));
14169 /* If W is a full-width window, glyph pointers in W's current matrix
14170 have, by definition, to be the same as glyph pointers in the
14171 corresponding frame matrix. Note that frame matrices have no
14172 marginal areas (see build_frame_matrix). */
14173 window_row
= w
->current_matrix
->rows
;
14174 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14175 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14176 while (window_row
< window_row_end
)
14178 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14179 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14181 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14182 frame_row
->glyphs
[TEXT_AREA
] = start
;
14183 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14184 frame_row
->glyphs
[LAST_AREA
] = end
;
14186 /* Disable frame rows whose corresponding window rows have
14187 been disabled in try_window_id. */
14188 if (!window_row
->enabled_p
)
14189 frame_row
->enabled_p
= 0;
14191 ++window_row
, ++frame_row
;
14196 /* Find the glyph row in window W containing CHARPOS. Consider all
14197 rows between START and END (not inclusive). END null means search
14198 all rows to the end of the display area of W. Value is the row
14199 containing CHARPOS or null. */
14202 row_containing_pos (w
, charpos
, start
, end
, dy
)
14205 struct glyph_row
*start
, *end
;
14208 struct glyph_row
*row
= start
;
14211 /* If we happen to start on a header-line, skip that. */
14212 if (row
->mode_line_p
)
14215 if ((end
&& row
>= end
) || !row
->enabled_p
)
14218 last_y
= window_text_bottom_y (w
) - dy
;
14222 /* Give up if we have gone too far. */
14223 if (end
&& row
>= end
)
14225 /* This formerly returned if they were equal.
14226 I think that both quantities are of a "last plus one" type;
14227 if so, when they are equal, the row is within the screen. -- rms. */
14228 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14231 /* If it is in this row, return this row. */
14232 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14233 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14234 /* The end position of a row equals the start
14235 position of the next row. If CHARPOS is there, we
14236 would rather display it in the next line, except
14237 when this line ends in ZV. */
14238 && !row
->ends_at_zv_p
14239 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14240 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14247 /* Try to redisplay window W by reusing its existing display. W's
14248 current matrix must be up to date when this function is called,
14249 i.e. window_end_valid must not be nil.
14253 1 if display has been updated
14254 0 if otherwise unsuccessful
14255 -1 if redisplay with same window start is known not to succeed
14257 The following steps are performed:
14259 1. Find the last row in the current matrix of W that is not
14260 affected by changes at the start of current_buffer. If no such row
14263 2. Find the first row in W's current matrix that is not affected by
14264 changes at the end of current_buffer. Maybe there is no such row.
14266 3. Display lines beginning with the row + 1 found in step 1 to the
14267 row found in step 2 or, if step 2 didn't find a row, to the end of
14270 4. If cursor is not known to appear on the window, give up.
14272 5. If display stopped at the row found in step 2, scroll the
14273 display and current matrix as needed.
14275 6. Maybe display some lines at the end of W, if we must. This can
14276 happen under various circumstances, like a partially visible line
14277 becoming fully visible, or because newly displayed lines are displayed
14278 in smaller font sizes.
14280 7. Update W's window end information. */
14286 struct frame
*f
= XFRAME (w
->frame
);
14287 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14288 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14289 struct glyph_row
*last_unchanged_at_beg_row
;
14290 struct glyph_row
*first_unchanged_at_end_row
;
14291 struct glyph_row
*row
;
14292 struct glyph_row
*bottom_row
;
14295 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14296 struct text_pos start_pos
;
14298 int first_unchanged_at_end_vpos
= 0;
14299 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14300 struct text_pos start
;
14301 int first_changed_charpos
, last_changed_charpos
;
14304 if (inhibit_try_window_id
)
14308 /* This is handy for debugging. */
14310 #define GIVE_UP(X) \
14312 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14316 #define GIVE_UP(X) return 0
14319 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14321 /* Don't use this for mini-windows because these can show
14322 messages and mini-buffers, and we don't handle that here. */
14323 if (MINI_WINDOW_P (w
))
14326 /* This flag is used to prevent redisplay optimizations. */
14327 if (windows_or_buffers_changed
|| cursor_type_changed
)
14330 /* Verify that narrowing has not changed.
14331 Also verify that we were not told to prevent redisplay optimizations.
14332 It would be nice to further
14333 reduce the number of cases where this prevents try_window_id. */
14334 if (current_buffer
->clip_changed
14335 || current_buffer
->prevent_redisplay_optimizations_p
)
14338 /* Window must either use window-based redisplay or be full width. */
14339 if (!FRAME_WINDOW_P (f
)
14340 && (!line_ins_del_ok
14341 || !WINDOW_FULL_WIDTH_P (w
)))
14344 /* Give up if point is not known NOT to appear in W. */
14345 if (PT
< CHARPOS (start
))
14348 /* Another way to prevent redisplay optimizations. */
14349 if (XFASTINT (w
->last_modified
) == 0)
14352 /* Verify that window is not hscrolled. */
14353 if (XFASTINT (w
->hscroll
) != 0)
14356 /* Verify that display wasn't paused. */
14357 if (NILP (w
->window_end_valid
))
14360 /* Can't use this if highlighting a region because a cursor movement
14361 will do more than just set the cursor. */
14362 if (!NILP (Vtransient_mark_mode
)
14363 && !NILP (current_buffer
->mark_active
))
14366 /* Likewise if highlighting trailing whitespace. */
14367 if (!NILP (Vshow_trailing_whitespace
))
14370 /* Likewise if showing a region. */
14371 if (!NILP (w
->region_showing
))
14374 /* Can use this if overlay arrow position and or string have changed. */
14375 if (overlay_arrows_changed_p ())
14379 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14380 only if buffer has really changed. The reason is that the gap is
14381 initially at Z for freshly visited files. The code below would
14382 set end_unchanged to 0 in that case. */
14383 if (MODIFF
> SAVE_MODIFF
14384 /* This seems to happen sometimes after saving a buffer. */
14385 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14387 if (GPT
- BEG
< BEG_UNCHANGED
)
14388 BEG_UNCHANGED
= GPT
- BEG
;
14389 if (Z
- GPT
< END_UNCHANGED
)
14390 END_UNCHANGED
= Z
- GPT
;
14393 /* The position of the first and last character that has been changed. */
14394 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14395 last_changed_charpos
= Z
- END_UNCHANGED
;
14397 /* If window starts after a line end, and the last change is in
14398 front of that newline, then changes don't affect the display.
14399 This case happens with stealth-fontification. Note that although
14400 the display is unchanged, glyph positions in the matrix have to
14401 be adjusted, of course. */
14402 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14403 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14404 && ((last_changed_charpos
< CHARPOS (start
)
14405 && CHARPOS (start
) == BEGV
)
14406 || (last_changed_charpos
< CHARPOS (start
) - 1
14407 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14409 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14410 struct glyph_row
*r0
;
14412 /* Compute how many chars/bytes have been added to or removed
14413 from the buffer. */
14414 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14415 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14417 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14419 /* Give up if PT is not in the window. Note that it already has
14420 been checked at the start of try_window_id that PT is not in
14421 front of the window start. */
14422 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14425 /* If window start is unchanged, we can reuse the whole matrix
14426 as is, after adjusting glyph positions. No need to compute
14427 the window end again, since its offset from Z hasn't changed. */
14428 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14429 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14430 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14431 /* PT must not be in a partially visible line. */
14432 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14433 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14435 /* Adjust positions in the glyph matrix. */
14436 if (delta
|| delta_bytes
)
14438 struct glyph_row
*r1
14439 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14440 increment_matrix_positions (w
->current_matrix
,
14441 MATRIX_ROW_VPOS (r0
, current_matrix
),
14442 MATRIX_ROW_VPOS (r1
, current_matrix
),
14443 delta
, delta_bytes
);
14446 /* Set the cursor. */
14447 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14449 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14456 /* Handle the case that changes are all below what is displayed in
14457 the window, and that PT is in the window. This shortcut cannot
14458 be taken if ZV is visible in the window, and text has been added
14459 there that is visible in the window. */
14460 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14461 /* ZV is not visible in the window, or there are no
14462 changes at ZV, actually. */
14463 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14464 || first_changed_charpos
== last_changed_charpos
))
14466 struct glyph_row
*r0
;
14468 /* Give up if PT is not in the window. Note that it already has
14469 been checked at the start of try_window_id that PT is not in
14470 front of the window start. */
14471 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14474 /* If window start is unchanged, we can reuse the whole matrix
14475 as is, without changing glyph positions since no text has
14476 been added/removed in front of the window end. */
14477 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14478 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14479 /* PT must not be in a partially visible line. */
14480 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14481 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14483 /* We have to compute the window end anew since text
14484 can have been added/removed after it. */
14486 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14487 w
->window_end_bytepos
14488 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14490 /* Set the cursor. */
14491 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14493 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14500 /* Give up if window start is in the changed area.
14502 The condition used to read
14504 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14506 but why that was tested escapes me at the moment. */
14507 if (CHARPOS (start
) >= first_changed_charpos
14508 && CHARPOS (start
) <= last_changed_charpos
)
14511 /* Check that window start agrees with the start of the first glyph
14512 row in its current matrix. Check this after we know the window
14513 start is not in changed text, otherwise positions would not be
14515 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14516 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14519 /* Give up if the window ends in strings. Overlay strings
14520 at the end are difficult to handle, so don't try. */
14521 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14522 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14525 /* Compute the position at which we have to start displaying new
14526 lines. Some of the lines at the top of the window might be
14527 reusable because they are not displaying changed text. Find the
14528 last row in W's current matrix not affected by changes at the
14529 start of current_buffer. Value is null if changes start in the
14530 first line of window. */
14531 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14532 if (last_unchanged_at_beg_row
)
14534 /* Avoid starting to display in the moddle of a character, a TAB
14535 for instance. This is easier than to set up the iterator
14536 exactly, and it's not a frequent case, so the additional
14537 effort wouldn't really pay off. */
14538 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14539 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14540 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14541 --last_unchanged_at_beg_row
;
14543 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14546 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14548 start_pos
= it
.current
.pos
;
14550 /* Start displaying new lines in the desired matrix at the same
14551 vpos we would use in the current matrix, i.e. below
14552 last_unchanged_at_beg_row. */
14553 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14555 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14556 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14558 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14562 /* There are no reusable lines at the start of the window.
14563 Start displaying in the first text line. */
14564 start_display (&it
, w
, start
);
14565 it
.vpos
= it
.first_vpos
;
14566 start_pos
= it
.current
.pos
;
14569 /* Find the first row that is not affected by changes at the end of
14570 the buffer. Value will be null if there is no unchanged row, in
14571 which case we must redisplay to the end of the window. delta
14572 will be set to the value by which buffer positions beginning with
14573 first_unchanged_at_end_row have to be adjusted due to text
14575 first_unchanged_at_end_row
14576 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14577 IF_DEBUG (debug_delta
= delta
);
14578 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14580 /* Set stop_pos to the buffer position up to which we will have to
14581 display new lines. If first_unchanged_at_end_row != NULL, this
14582 is the buffer position of the start of the line displayed in that
14583 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14584 that we don't stop at a buffer position. */
14586 if (first_unchanged_at_end_row
)
14588 xassert (last_unchanged_at_beg_row
== NULL
14589 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14591 /* If this is a continuation line, move forward to the next one
14592 that isn't. Changes in lines above affect this line.
14593 Caution: this may move first_unchanged_at_end_row to a row
14594 not displaying text. */
14595 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14596 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14597 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14598 < it
.last_visible_y
))
14599 ++first_unchanged_at_end_row
;
14601 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14602 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14603 >= it
.last_visible_y
))
14604 first_unchanged_at_end_row
= NULL
;
14607 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14609 first_unchanged_at_end_vpos
14610 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14611 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14614 else if (last_unchanged_at_beg_row
== NULL
)
14620 /* Either there is no unchanged row at the end, or the one we have
14621 now displays text. This is a necessary condition for the window
14622 end pos calculation at the end of this function. */
14623 xassert (first_unchanged_at_end_row
== NULL
14624 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14626 debug_last_unchanged_at_beg_vpos
14627 = (last_unchanged_at_beg_row
14628 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14630 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14632 #endif /* GLYPH_DEBUG != 0 */
14635 /* Display new lines. Set last_text_row to the last new line
14636 displayed which has text on it, i.e. might end up as being the
14637 line where the window_end_vpos is. */
14638 w
->cursor
.vpos
= -1;
14639 last_text_row
= NULL
;
14640 overlay_arrow_seen
= 0;
14641 while (it
.current_y
< it
.last_visible_y
14642 && !fonts_changed_p
14643 && (first_unchanged_at_end_row
== NULL
14644 || IT_CHARPOS (it
) < stop_pos
))
14646 if (display_line (&it
))
14647 last_text_row
= it
.glyph_row
- 1;
14650 if (fonts_changed_p
)
14654 /* Compute differences in buffer positions, y-positions etc. for
14655 lines reused at the bottom of the window. Compute what we can
14657 if (first_unchanged_at_end_row
14658 /* No lines reused because we displayed everything up to the
14659 bottom of the window. */
14660 && it
.current_y
< it
.last_visible_y
)
14663 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14665 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14666 run
.current_y
= first_unchanged_at_end_row
->y
;
14667 run
.desired_y
= run
.current_y
+ dy
;
14668 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14672 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14673 first_unchanged_at_end_row
= NULL
;
14675 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14678 /* Find the cursor if not already found. We have to decide whether
14679 PT will appear on this window (it sometimes doesn't, but this is
14680 not a very frequent case.) This decision has to be made before
14681 the current matrix is altered. A value of cursor.vpos < 0 means
14682 that PT is either in one of the lines beginning at
14683 first_unchanged_at_end_row or below the window. Don't care for
14684 lines that might be displayed later at the window end; as
14685 mentioned, this is not a frequent case. */
14686 if (w
->cursor
.vpos
< 0)
14688 /* Cursor in unchanged rows at the top? */
14689 if (PT
< CHARPOS (start_pos
)
14690 && last_unchanged_at_beg_row
)
14692 row
= row_containing_pos (w
, PT
,
14693 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14694 last_unchanged_at_beg_row
+ 1, 0);
14696 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14699 /* Start from first_unchanged_at_end_row looking for PT. */
14700 else if (first_unchanged_at_end_row
)
14702 row
= row_containing_pos (w
, PT
- delta
,
14703 first_unchanged_at_end_row
, NULL
, 0);
14705 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14706 delta_bytes
, dy
, dvpos
);
14709 /* Give up if cursor was not found. */
14710 if (w
->cursor
.vpos
< 0)
14712 clear_glyph_matrix (w
->desired_matrix
);
14717 /* Don't let the cursor end in the scroll margins. */
14719 int this_scroll_margin
, cursor_height
;
14721 this_scroll_margin
= max (0, scroll_margin
);
14722 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14723 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14724 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14726 if ((w
->cursor
.y
< this_scroll_margin
14727 && CHARPOS (start
) > BEGV
)
14728 /* Old redisplay didn't take scroll margin into account at the bottom,
14729 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14730 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14731 ? cursor_height
+ this_scroll_margin
14732 : 1)) > it
.last_visible_y
)
14734 w
->cursor
.vpos
= -1;
14735 clear_glyph_matrix (w
->desired_matrix
);
14740 /* Scroll the display. Do it before changing the current matrix so
14741 that xterm.c doesn't get confused about where the cursor glyph is
14743 if (dy
&& run
.height
)
14747 if (FRAME_WINDOW_P (f
))
14749 rif
->update_window_begin_hook (w
);
14750 rif
->clear_window_mouse_face (w
);
14751 rif
->scroll_run_hook (w
, &run
);
14752 rif
->update_window_end_hook (w
, 0, 0);
14756 /* Terminal frame. In this case, dvpos gives the number of
14757 lines to scroll by; dvpos < 0 means scroll up. */
14758 int first_unchanged_at_end_vpos
14759 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14760 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14761 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14762 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14763 + window_internal_height (w
));
14765 /* Perform the operation on the screen. */
14768 /* Scroll last_unchanged_at_beg_row to the end of the
14769 window down dvpos lines. */
14770 set_terminal_window (end
);
14772 /* On dumb terminals delete dvpos lines at the end
14773 before inserting dvpos empty lines. */
14774 if (!scroll_region_ok
)
14775 ins_del_lines (end
- dvpos
, -dvpos
);
14777 /* Insert dvpos empty lines in front of
14778 last_unchanged_at_beg_row. */
14779 ins_del_lines (from
, dvpos
);
14781 else if (dvpos
< 0)
14783 /* Scroll up last_unchanged_at_beg_vpos to the end of
14784 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14785 set_terminal_window (end
);
14787 /* Delete dvpos lines in front of
14788 last_unchanged_at_beg_vpos. ins_del_lines will set
14789 the cursor to the given vpos and emit |dvpos| delete
14791 ins_del_lines (from
+ dvpos
, dvpos
);
14793 /* On a dumb terminal insert dvpos empty lines at the
14795 if (!scroll_region_ok
)
14796 ins_del_lines (end
+ dvpos
, -dvpos
);
14799 set_terminal_window (0);
14805 /* Shift reused rows of the current matrix to the right position.
14806 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14808 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14809 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14812 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14813 bottom_vpos
, dvpos
);
14814 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14817 else if (dvpos
> 0)
14819 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14820 bottom_vpos
, dvpos
);
14821 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14822 first_unchanged_at_end_vpos
+ dvpos
, 0);
14825 /* For frame-based redisplay, make sure that current frame and window
14826 matrix are in sync with respect to glyph memory. */
14827 if (!FRAME_WINDOW_P (f
))
14828 sync_frame_with_window_matrix_rows (w
);
14830 /* Adjust buffer positions in reused rows. */
14832 increment_matrix_positions (current_matrix
,
14833 first_unchanged_at_end_vpos
+ dvpos
,
14834 bottom_vpos
, delta
, delta_bytes
);
14836 /* Adjust Y positions. */
14838 shift_glyph_matrix (w
, current_matrix
,
14839 first_unchanged_at_end_vpos
+ dvpos
,
14842 if (first_unchanged_at_end_row
)
14844 first_unchanged_at_end_row
+= dvpos
;
14845 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14846 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14847 first_unchanged_at_end_row
= NULL
;
14850 /* If scrolling up, there may be some lines to display at the end of
14852 last_text_row_at_end
= NULL
;
14855 /* Scrolling up can leave for example a partially visible line
14856 at the end of the window to be redisplayed. */
14857 /* Set last_row to the glyph row in the current matrix where the
14858 window end line is found. It has been moved up or down in
14859 the matrix by dvpos. */
14860 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14861 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14863 /* If last_row is the window end line, it should display text. */
14864 xassert (last_row
->displays_text_p
);
14866 /* If window end line was partially visible before, begin
14867 displaying at that line. Otherwise begin displaying with the
14868 line following it. */
14869 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14871 init_to_row_start (&it
, w
, last_row
);
14872 it
.vpos
= last_vpos
;
14873 it
.current_y
= last_row
->y
;
14877 init_to_row_end (&it
, w
, last_row
);
14878 it
.vpos
= 1 + last_vpos
;
14879 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14883 /* We may start in a continuation line. If so, we have to
14884 get the right continuation_lines_width and current_x. */
14885 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14886 it
.hpos
= it
.current_x
= 0;
14888 /* Display the rest of the lines at the window end. */
14889 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14890 while (it
.current_y
< it
.last_visible_y
14891 && !fonts_changed_p
)
14893 /* Is it always sure that the display agrees with lines in
14894 the current matrix? I don't think so, so we mark rows
14895 displayed invalid in the current matrix by setting their
14896 enabled_p flag to zero. */
14897 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14898 if (display_line (&it
))
14899 last_text_row_at_end
= it
.glyph_row
- 1;
14903 /* Update window_end_pos and window_end_vpos. */
14904 if (first_unchanged_at_end_row
14905 && !last_text_row_at_end
)
14907 /* Window end line if one of the preserved rows from the current
14908 matrix. Set row to the last row displaying text in current
14909 matrix starting at first_unchanged_at_end_row, after
14911 xassert (first_unchanged_at_end_row
->displays_text_p
);
14912 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14913 first_unchanged_at_end_row
);
14914 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14916 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14917 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14919 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14920 xassert (w
->window_end_bytepos
>= 0);
14921 IF_DEBUG (debug_method_add (w
, "A"));
14923 else if (last_text_row_at_end
)
14926 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14927 w
->window_end_bytepos
14928 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14930 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14931 xassert (w
->window_end_bytepos
>= 0);
14932 IF_DEBUG (debug_method_add (w
, "B"));
14934 else if (last_text_row
)
14936 /* We have displayed either to the end of the window or at the
14937 end of the window, i.e. the last row with text is to be found
14938 in the desired matrix. */
14940 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14941 w
->window_end_bytepos
14942 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14944 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14945 xassert (w
->window_end_bytepos
>= 0);
14947 else if (first_unchanged_at_end_row
== NULL
14948 && last_text_row
== NULL
14949 && last_text_row_at_end
== NULL
)
14951 /* Displayed to end of window, but no line containing text was
14952 displayed. Lines were deleted at the end of the window. */
14953 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14954 int vpos
= XFASTINT (w
->window_end_vpos
);
14955 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14956 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14959 row
== NULL
&& vpos
>= first_vpos
;
14960 --vpos
, --current_row
, --desired_row
)
14962 if (desired_row
->enabled_p
)
14964 if (desired_row
->displays_text_p
)
14967 else if (current_row
->displays_text_p
)
14971 xassert (row
!= NULL
);
14972 w
->window_end_vpos
= make_number (vpos
+ 1);
14973 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14974 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14975 xassert (w
->window_end_bytepos
>= 0);
14976 IF_DEBUG (debug_method_add (w
, "C"));
14981 #if 0 /* This leads to problems, for instance when the cursor is
14982 at ZV, and the cursor line displays no text. */
14983 /* Disable rows below what's displayed in the window. This makes
14984 debugging easier. */
14985 enable_glyph_matrix_rows (current_matrix
,
14986 XFASTINT (w
->window_end_vpos
) + 1,
14990 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14991 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14993 /* Record that display has not been completed. */
14994 w
->window_end_valid
= Qnil
;
14995 w
->desired_matrix
->no_scrolling_p
= 1;
15003 /***********************************************************************
15004 More debugging support
15005 ***********************************************************************/
15009 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15010 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15011 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15014 /* Dump the contents of glyph matrix MATRIX on stderr.
15016 GLYPHS 0 means don't show glyph contents.
15017 GLYPHS 1 means show glyphs in short form
15018 GLYPHS > 1 means show glyphs in long form. */
15021 dump_glyph_matrix (matrix
, glyphs
)
15022 struct glyph_matrix
*matrix
;
15026 for (i
= 0; i
< matrix
->nrows
; ++i
)
15027 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15031 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15032 the glyph row and area where the glyph comes from. */
15035 dump_glyph (row
, glyph
, area
)
15036 struct glyph_row
*row
;
15037 struct glyph
*glyph
;
15040 if (glyph
->type
== CHAR_GLYPH
)
15043 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15044 glyph
- row
->glyphs
[TEXT_AREA
],
15047 (BUFFERP (glyph
->object
)
15049 : (STRINGP (glyph
->object
)
15052 glyph
->pixel_width
,
15054 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15058 glyph
->left_box_line_p
,
15059 glyph
->right_box_line_p
);
15061 else if (glyph
->type
== STRETCH_GLYPH
)
15064 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15065 glyph
- row
->glyphs
[TEXT_AREA
],
15068 (BUFFERP (glyph
->object
)
15070 : (STRINGP (glyph
->object
)
15073 glyph
->pixel_width
,
15077 glyph
->left_box_line_p
,
15078 glyph
->right_box_line_p
);
15080 else if (glyph
->type
== IMAGE_GLYPH
)
15083 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15084 glyph
- row
->glyphs
[TEXT_AREA
],
15087 (BUFFERP (glyph
->object
)
15089 : (STRINGP (glyph
->object
)
15092 glyph
->pixel_width
,
15096 glyph
->left_box_line_p
,
15097 glyph
->right_box_line_p
);
15099 else if (glyph
->type
== COMPOSITE_GLYPH
)
15102 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15103 glyph
- row
->glyphs
[TEXT_AREA
],
15106 (BUFFERP (glyph
->object
)
15108 : (STRINGP (glyph
->object
)
15111 glyph
->pixel_width
,
15115 glyph
->left_box_line_p
,
15116 glyph
->right_box_line_p
);
15121 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15122 GLYPHS 0 means don't show glyph contents.
15123 GLYPHS 1 means show glyphs in short form
15124 GLYPHS > 1 means show glyphs in long form. */
15127 dump_glyph_row (row
, vpos
, glyphs
)
15128 struct glyph_row
*row
;
15133 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15134 fprintf (stderr
, "======================================================================\n");
15136 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15137 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15139 MATRIX_ROW_START_CHARPOS (row
),
15140 MATRIX_ROW_END_CHARPOS (row
),
15141 row
->used
[TEXT_AREA
],
15142 row
->contains_overlapping_glyphs_p
,
15144 row
->truncated_on_left_p
,
15145 row
->truncated_on_right_p
,
15147 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15148 row
->displays_text_p
,
15151 row
->ends_in_middle_of_char_p
,
15152 row
->starts_in_middle_of_char_p
,
15158 row
->visible_height
,
15161 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15162 row
->end
.overlay_string_index
,
15163 row
->continuation_lines_width
);
15164 fprintf (stderr
, "%9d %5d\n",
15165 CHARPOS (row
->start
.string_pos
),
15166 CHARPOS (row
->end
.string_pos
));
15167 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15168 row
->end
.dpvec_index
);
15175 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15177 struct glyph
*glyph
= row
->glyphs
[area
];
15178 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15180 /* Glyph for a line end in text. */
15181 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15184 if (glyph
< glyph_end
)
15185 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15187 for (; glyph
< glyph_end
; ++glyph
)
15188 dump_glyph (row
, glyph
, area
);
15191 else if (glyphs
== 1)
15195 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15197 char *s
= (char *) alloca (row
->used
[area
] + 1);
15200 for (i
= 0; i
< row
->used
[area
]; ++i
)
15202 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15203 if (glyph
->type
== CHAR_GLYPH
15204 && glyph
->u
.ch
< 0x80
15205 && glyph
->u
.ch
>= ' ')
15206 s
[i
] = glyph
->u
.ch
;
15212 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15218 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15219 Sdump_glyph_matrix
, 0, 1, "p",
15220 doc
: /* Dump the current matrix of the selected window to stderr.
15221 Shows contents of glyph row structures. With non-nil
15222 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15223 glyphs in short form, otherwise show glyphs in long form. */)
15225 Lisp_Object glyphs
;
15227 struct window
*w
= XWINDOW (selected_window
);
15228 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15230 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15231 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15232 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15233 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15234 fprintf (stderr
, "=============================================\n");
15235 dump_glyph_matrix (w
->current_matrix
,
15236 NILP (glyphs
) ? 0 : XINT (glyphs
));
15241 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15242 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15245 struct frame
*f
= XFRAME (selected_frame
);
15246 dump_glyph_matrix (f
->current_matrix
, 1);
15251 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15252 doc
: /* Dump glyph row ROW to stderr.
15253 GLYPH 0 means don't dump glyphs.
15254 GLYPH 1 means dump glyphs in short form.
15255 GLYPH > 1 or omitted means dump glyphs in long form. */)
15257 Lisp_Object row
, glyphs
;
15259 struct glyph_matrix
*matrix
;
15262 CHECK_NUMBER (row
);
15263 matrix
= XWINDOW (selected_window
)->current_matrix
;
15265 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15266 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15268 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15273 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15274 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15275 GLYPH 0 means don't dump glyphs.
15276 GLYPH 1 means dump glyphs in short form.
15277 GLYPH > 1 or omitted means dump glyphs in long form. */)
15279 Lisp_Object row
, glyphs
;
15281 struct frame
*sf
= SELECTED_FRAME ();
15282 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15285 CHECK_NUMBER (row
);
15287 if (vpos
>= 0 && vpos
< m
->nrows
)
15288 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15289 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15294 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15295 doc
: /* Toggle tracing of redisplay.
15296 With ARG, turn tracing on if and only if ARG is positive. */)
15301 trace_redisplay_p
= !trace_redisplay_p
;
15304 arg
= Fprefix_numeric_value (arg
);
15305 trace_redisplay_p
= XINT (arg
) > 0;
15312 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15313 doc
: /* Like `format', but print result to stderr.
15314 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15319 Lisp_Object s
= Fformat (nargs
, args
);
15320 fprintf (stderr
, "%s", SDATA (s
));
15324 #endif /* GLYPH_DEBUG */
15328 /***********************************************************************
15329 Building Desired Matrix Rows
15330 ***********************************************************************/
15332 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15333 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15335 static struct glyph_row
*
15336 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15338 Lisp_Object overlay_arrow_string
;
15340 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15341 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15342 struct buffer
*old
= current_buffer
;
15343 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15344 int arrow_len
= SCHARS (overlay_arrow_string
);
15345 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15346 const unsigned char *p
;
15349 int n_glyphs_before
;
15351 set_buffer_temp (buffer
);
15352 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15353 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15354 SET_TEXT_POS (it
.position
, 0, 0);
15356 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15358 while (p
< arrow_end
)
15360 Lisp_Object face
, ilisp
;
15362 /* Get the next character. */
15364 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15366 it
.c
= *p
, it
.len
= 1;
15369 /* Get its face. */
15370 ilisp
= make_number (p
- arrow_string
);
15371 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15372 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15374 /* Compute its width, get its glyphs. */
15375 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15376 SET_TEXT_POS (it
.position
, -1, -1);
15377 PRODUCE_GLYPHS (&it
);
15379 /* If this character doesn't fit any more in the line, we have
15380 to remove some glyphs. */
15381 if (it
.current_x
> it
.last_visible_x
)
15383 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15388 set_buffer_temp (old
);
15389 return it
.glyph_row
;
15393 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15394 glyphs are only inserted for terminal frames since we can't really
15395 win with truncation glyphs when partially visible glyphs are
15396 involved. Which glyphs to insert is determined by
15397 produce_special_glyphs. */
15400 insert_left_trunc_glyphs (it
)
15403 struct it truncate_it
;
15404 struct glyph
*from
, *end
, *to
, *toend
;
15406 xassert (!FRAME_WINDOW_P (it
->f
));
15408 /* Get the truncation glyphs. */
15410 truncate_it
.current_x
= 0;
15411 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15412 truncate_it
.glyph_row
= &scratch_glyph_row
;
15413 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15414 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15415 truncate_it
.object
= make_number (0);
15416 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15418 /* Overwrite glyphs from IT with truncation glyphs. */
15419 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15420 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15421 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15422 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15427 /* There may be padding glyphs left over. Overwrite them too. */
15428 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15430 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15436 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15440 /* Compute the pixel height and width of IT->glyph_row.
15442 Most of the time, ascent and height of a display line will be equal
15443 to the max_ascent and max_height values of the display iterator
15444 structure. This is not the case if
15446 1. We hit ZV without displaying anything. In this case, max_ascent
15447 and max_height will be zero.
15449 2. We have some glyphs that don't contribute to the line height.
15450 (The glyph row flag contributes_to_line_height_p is for future
15451 pixmap extensions).
15453 The first case is easily covered by using default values because in
15454 these cases, the line height does not really matter, except that it
15455 must not be zero. */
15458 compute_line_metrics (it
)
15461 struct glyph_row
*row
= it
->glyph_row
;
15464 if (FRAME_WINDOW_P (it
->f
))
15466 int i
, min_y
, max_y
;
15468 /* The line may consist of one space only, that was added to
15469 place the cursor on it. If so, the row's height hasn't been
15471 if (row
->height
== 0)
15473 if (it
->max_ascent
+ it
->max_descent
== 0)
15474 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15475 row
->ascent
= it
->max_ascent
;
15476 row
->height
= it
->max_ascent
+ it
->max_descent
;
15477 row
->phys_ascent
= it
->max_phys_ascent
;
15478 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15479 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15482 /* Compute the width of this line. */
15483 row
->pixel_width
= row
->x
;
15484 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15485 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15487 xassert (row
->pixel_width
>= 0);
15488 xassert (row
->ascent
>= 0 && row
->height
> 0);
15490 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15491 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15493 /* If first line's physical ascent is larger than its logical
15494 ascent, use the physical ascent, and make the row taller.
15495 This makes accented characters fully visible. */
15496 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15497 && row
->phys_ascent
> row
->ascent
)
15499 row
->height
+= row
->phys_ascent
- row
->ascent
;
15500 row
->ascent
= row
->phys_ascent
;
15503 /* Compute how much of the line is visible. */
15504 row
->visible_height
= row
->height
;
15506 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15507 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15509 if (row
->y
< min_y
)
15510 row
->visible_height
-= min_y
- row
->y
;
15511 if (row
->y
+ row
->height
> max_y
)
15512 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15516 row
->pixel_width
= row
->used
[TEXT_AREA
];
15517 if (row
->continued_p
)
15518 row
->pixel_width
-= it
->continuation_pixel_width
;
15519 else if (row
->truncated_on_right_p
)
15520 row
->pixel_width
-= it
->truncation_pixel_width
;
15521 row
->ascent
= row
->phys_ascent
= 0;
15522 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15523 row
->extra_line_spacing
= 0;
15526 /* Compute a hash code for this row. */
15528 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15529 for (i
= 0; i
< row
->used
[area
]; ++i
)
15530 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15531 + row
->glyphs
[area
][i
].u
.val
15532 + row
->glyphs
[area
][i
].face_id
15533 + row
->glyphs
[area
][i
].padding_p
15534 + (row
->glyphs
[area
][i
].type
<< 2));
15536 it
->max_ascent
= it
->max_descent
= 0;
15537 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15541 /* Append one space to the glyph row of iterator IT if doing a
15542 window-based redisplay. The space has the same face as
15543 IT->face_id. Value is non-zero if a space was added.
15545 This function is called to make sure that there is always one glyph
15546 at the end of a glyph row that the cursor can be set on under
15547 window-systems. (If there weren't such a glyph we would not know
15548 how wide and tall a box cursor should be displayed).
15550 At the same time this space let's a nicely handle clearing to the
15551 end of the line if the row ends in italic text. */
15554 append_space_for_newline (it
, default_face_p
)
15556 int default_face_p
;
15558 if (FRAME_WINDOW_P (it
->f
))
15560 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15562 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15563 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15565 /* Save some values that must not be changed.
15566 Must save IT->c and IT->len because otherwise
15567 ITERATOR_AT_END_P wouldn't work anymore after
15568 append_space_for_newline has been called. */
15569 enum display_element_type saved_what
= it
->what
;
15570 int saved_c
= it
->c
, saved_len
= it
->len
;
15571 int saved_x
= it
->current_x
;
15572 int saved_face_id
= it
->face_id
;
15573 struct text_pos saved_pos
;
15574 Lisp_Object saved_object
;
15577 saved_object
= it
->object
;
15578 saved_pos
= it
->position
;
15580 it
->what
= IT_CHARACTER
;
15581 bzero (&it
->position
, sizeof it
->position
);
15582 it
->object
= make_number (0);
15586 if (default_face_p
)
15587 it
->face_id
= DEFAULT_FACE_ID
;
15588 else if (it
->face_before_selective_p
)
15589 it
->face_id
= it
->saved_face_id
;
15590 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15591 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15593 PRODUCE_GLYPHS (it
);
15595 it
->override_ascent
= -1;
15596 it
->constrain_row_ascent_descent_p
= 0;
15597 it
->current_x
= saved_x
;
15598 it
->object
= saved_object
;
15599 it
->position
= saved_pos
;
15600 it
->what
= saved_what
;
15601 it
->face_id
= saved_face_id
;
15602 it
->len
= saved_len
;
15612 /* Extend the face of the last glyph in the text area of IT->glyph_row
15613 to the end of the display line. Called from display_line.
15614 If the glyph row is empty, add a space glyph to it so that we
15615 know the face to draw. Set the glyph row flag fill_line_p. */
15618 extend_face_to_end_of_line (it
)
15622 struct frame
*f
= it
->f
;
15624 /* If line is already filled, do nothing. */
15625 if (it
->current_x
>= it
->last_visible_x
)
15628 /* Face extension extends the background and box of IT->face_id
15629 to the end of the line. If the background equals the background
15630 of the frame, we don't have to do anything. */
15631 if (it
->face_before_selective_p
)
15632 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15634 face
= FACE_FROM_ID (f
, it
->face_id
);
15636 if (FRAME_WINDOW_P (f
)
15637 && it
->glyph_row
->displays_text_p
15638 && face
->box
== FACE_NO_BOX
15639 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15643 /* Set the glyph row flag indicating that the face of the last glyph
15644 in the text area has to be drawn to the end of the text area. */
15645 it
->glyph_row
->fill_line_p
= 1;
15647 /* If current character of IT is not ASCII, make sure we have the
15648 ASCII face. This will be automatically undone the next time
15649 get_next_display_element returns a multibyte character. Note
15650 that the character will always be single byte in unibyte text. */
15651 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15653 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15656 if (FRAME_WINDOW_P (f
))
15658 /* If the row is empty, add a space with the current face of IT,
15659 so that we know which face to draw. */
15660 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15662 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15663 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15664 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15669 /* Save some values that must not be changed. */
15670 int saved_x
= it
->current_x
;
15671 struct text_pos saved_pos
;
15672 Lisp_Object saved_object
;
15673 enum display_element_type saved_what
= it
->what
;
15674 int saved_face_id
= it
->face_id
;
15676 saved_object
= it
->object
;
15677 saved_pos
= it
->position
;
15679 it
->what
= IT_CHARACTER
;
15680 bzero (&it
->position
, sizeof it
->position
);
15681 it
->object
= make_number (0);
15684 it
->face_id
= face
->id
;
15686 PRODUCE_GLYPHS (it
);
15688 while (it
->current_x
<= it
->last_visible_x
)
15689 PRODUCE_GLYPHS (it
);
15691 /* Don't count these blanks really. It would let us insert a left
15692 truncation glyph below and make us set the cursor on them, maybe. */
15693 it
->current_x
= saved_x
;
15694 it
->object
= saved_object
;
15695 it
->position
= saved_pos
;
15696 it
->what
= saved_what
;
15697 it
->face_id
= saved_face_id
;
15702 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15703 trailing whitespace. */
15706 trailing_whitespace_p (charpos
)
15709 int bytepos
= CHAR_TO_BYTE (charpos
);
15712 while (bytepos
< ZV_BYTE
15713 && (c
= FETCH_CHAR (bytepos
),
15714 c
== ' ' || c
== '\t'))
15717 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15719 if (bytepos
!= PT_BYTE
)
15726 /* Highlight trailing whitespace, if any, in ROW. */
15729 highlight_trailing_whitespace (f
, row
)
15731 struct glyph_row
*row
;
15733 int used
= row
->used
[TEXT_AREA
];
15737 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15738 struct glyph
*glyph
= start
+ used
- 1;
15740 /* Skip over glyphs inserted to display the cursor at the
15741 end of a line, for extending the face of the last glyph
15742 to the end of the line on terminals, and for truncation
15743 and continuation glyphs. */
15744 while (glyph
>= start
15745 && glyph
->type
== CHAR_GLYPH
15746 && INTEGERP (glyph
->object
))
15749 /* If last glyph is a space or stretch, and it's trailing
15750 whitespace, set the face of all trailing whitespace glyphs in
15751 IT->glyph_row to `trailing-whitespace'. */
15753 && BUFFERP (glyph
->object
)
15754 && (glyph
->type
== STRETCH_GLYPH
15755 || (glyph
->type
== CHAR_GLYPH
15756 && glyph
->u
.ch
== ' '))
15757 && trailing_whitespace_p (glyph
->charpos
))
15759 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15763 while (glyph
>= start
15764 && BUFFERP (glyph
->object
)
15765 && (glyph
->type
== STRETCH_GLYPH
15766 || (glyph
->type
== CHAR_GLYPH
15767 && glyph
->u
.ch
== ' ')))
15768 (glyph
--)->face_id
= face_id
;
15774 /* Value is non-zero if glyph row ROW in window W should be
15775 used to hold the cursor. */
15778 cursor_row_p (w
, row
)
15780 struct glyph_row
*row
;
15782 int cursor_row_p
= 1;
15784 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15786 /* If the row ends with a newline from a string, we don't want
15787 the cursor there, but we still want it at the start of the
15788 string if the string starts in this row.
15789 If the row is continued it doesn't end in a newline. */
15790 if (CHARPOS (row
->end
.string_pos
) >= 0)
15791 cursor_row_p
= (row
->continued_p
15792 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15793 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15795 /* If the row ends in middle of a real character,
15796 and the line is continued, we want the cursor here.
15797 That's because MATRIX_ROW_END_CHARPOS would equal
15798 PT if PT is before the character. */
15799 if (!row
->ends_in_ellipsis_p
)
15800 cursor_row_p
= row
->continued_p
;
15802 /* If the row ends in an ellipsis, then
15803 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15804 We want that position to be displayed after the ellipsis. */
15807 /* If the row ends at ZV, display the cursor at the end of that
15808 row instead of at the start of the row below. */
15809 else if (row
->ends_at_zv_p
)
15815 return cursor_row_p
;
15819 /* Construct the glyph row IT->glyph_row in the desired matrix of
15820 IT->w from text at the current position of IT. See dispextern.h
15821 for an overview of struct it. Value is non-zero if
15822 IT->glyph_row displays text, as opposed to a line displaying ZV
15829 struct glyph_row
*row
= it
->glyph_row
;
15830 Lisp_Object overlay_arrow_string
;
15832 /* We always start displaying at hpos zero even if hscrolled. */
15833 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15835 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15836 >= it
->w
->desired_matrix
->nrows
)
15838 it
->w
->nrows_scale_factor
++;
15839 fonts_changed_p
= 1;
15843 /* Is IT->w showing the region? */
15844 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15846 /* Clear the result glyph row and enable it. */
15847 prepare_desired_row (row
);
15849 row
->y
= it
->current_y
;
15850 row
->start
= it
->start
;
15851 row
->continuation_lines_width
= it
->continuation_lines_width
;
15852 row
->displays_text_p
= 1;
15853 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15854 it
->starts_in_middle_of_char_p
= 0;
15856 /* Arrange the overlays nicely for our purposes. Usually, we call
15857 display_line on only one line at a time, in which case this
15858 can't really hurt too much, or we call it on lines which appear
15859 one after another in the buffer, in which case all calls to
15860 recenter_overlay_lists but the first will be pretty cheap. */
15861 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15863 /* Move over display elements that are not visible because we are
15864 hscrolled. This may stop at an x-position < IT->first_visible_x
15865 if the first glyph is partially visible or if we hit a line end. */
15866 if (it
->current_x
< it
->first_visible_x
)
15868 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15869 MOVE_TO_POS
| MOVE_TO_X
);
15872 /* Get the initial row height. This is either the height of the
15873 text hscrolled, if there is any, or zero. */
15874 row
->ascent
= it
->max_ascent
;
15875 row
->height
= it
->max_ascent
+ it
->max_descent
;
15876 row
->phys_ascent
= it
->max_phys_ascent
;
15877 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15878 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15880 /* Loop generating characters. The loop is left with IT on the next
15881 character to display. */
15884 int n_glyphs_before
, hpos_before
, x_before
;
15886 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15888 /* Retrieve the next thing to display. Value is zero if end of
15890 if (!get_next_display_element (it
))
15892 /* Maybe add a space at the end of this line that is used to
15893 display the cursor there under X. Set the charpos of the
15894 first glyph of blank lines not corresponding to any text
15896 #ifdef HAVE_WINDOW_SYSTEM
15897 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15898 row
->exact_window_width_line_p
= 1;
15900 #endif /* HAVE_WINDOW_SYSTEM */
15901 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15902 || row
->used
[TEXT_AREA
] == 0)
15904 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15905 row
->displays_text_p
= 0;
15907 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15908 && (!MINI_WINDOW_P (it
->w
)
15909 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15910 row
->indicate_empty_line_p
= 1;
15913 it
->continuation_lines_width
= 0;
15914 row
->ends_at_zv_p
= 1;
15918 /* Now, get the metrics of what we want to display. This also
15919 generates glyphs in `row' (which is IT->glyph_row). */
15920 n_glyphs_before
= row
->used
[TEXT_AREA
];
15923 /* Remember the line height so far in case the next element doesn't
15924 fit on the line. */
15925 if (!it
->truncate_lines_p
)
15927 ascent
= it
->max_ascent
;
15928 descent
= it
->max_descent
;
15929 phys_ascent
= it
->max_phys_ascent
;
15930 phys_descent
= it
->max_phys_descent
;
15933 PRODUCE_GLYPHS (it
);
15935 /* If this display element was in marginal areas, continue with
15937 if (it
->area
!= TEXT_AREA
)
15939 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15940 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15941 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15942 row
->phys_height
= max (row
->phys_height
,
15943 it
->max_phys_ascent
+ it
->max_phys_descent
);
15944 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15945 it
->max_extra_line_spacing
);
15946 set_iterator_to_next (it
, 1);
15950 /* Does the display element fit on the line? If we truncate
15951 lines, we should draw past the right edge of the window. If
15952 we don't truncate, we want to stop so that we can display the
15953 continuation glyph before the right margin. If lines are
15954 continued, there are two possible strategies for characters
15955 resulting in more than 1 glyph (e.g. tabs): Display as many
15956 glyphs as possible in this line and leave the rest for the
15957 continuation line, or display the whole element in the next
15958 line. Original redisplay did the former, so we do it also. */
15959 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15960 hpos_before
= it
->hpos
;
15963 if (/* Not a newline. */
15965 /* Glyphs produced fit entirely in the line. */
15966 && it
->current_x
< it
->last_visible_x
)
15968 it
->hpos
+= nglyphs
;
15969 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15970 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15971 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15972 row
->phys_height
= max (row
->phys_height
,
15973 it
->max_phys_ascent
+ it
->max_phys_descent
);
15974 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15975 it
->max_extra_line_spacing
);
15976 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15977 row
->x
= x
- it
->first_visible_x
;
15982 struct glyph
*glyph
;
15984 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15986 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15987 new_x
= x
+ glyph
->pixel_width
;
15989 if (/* Lines are continued. */
15990 !it
->truncate_lines_p
15991 && (/* Glyph doesn't fit on the line. */
15992 new_x
> it
->last_visible_x
15993 /* Or it fits exactly on a window system frame. */
15994 || (new_x
== it
->last_visible_x
15995 && FRAME_WINDOW_P (it
->f
))))
15997 /* End of a continued line. */
16000 || (new_x
== it
->last_visible_x
16001 && FRAME_WINDOW_P (it
->f
)))
16003 /* Current glyph is the only one on the line or
16004 fits exactly on the line. We must continue
16005 the line because we can't draw the cursor
16006 after the glyph. */
16007 row
->continued_p
= 1;
16008 it
->current_x
= new_x
;
16009 it
->continuation_lines_width
+= new_x
;
16011 if (i
== nglyphs
- 1)
16013 set_iterator_to_next (it
, 1);
16014 #ifdef HAVE_WINDOW_SYSTEM
16015 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16017 if (!get_next_display_element (it
))
16019 row
->exact_window_width_line_p
= 1;
16020 it
->continuation_lines_width
= 0;
16021 row
->continued_p
= 0;
16022 row
->ends_at_zv_p
= 1;
16024 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16026 row
->continued_p
= 0;
16027 row
->exact_window_width_line_p
= 1;
16030 #endif /* HAVE_WINDOW_SYSTEM */
16033 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16034 && !FRAME_WINDOW_P (it
->f
))
16036 /* A padding glyph that doesn't fit on this line.
16037 This means the whole character doesn't fit
16039 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16041 /* Fill the rest of the row with continuation
16042 glyphs like in 20.x. */
16043 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16044 < row
->glyphs
[1 + TEXT_AREA
])
16045 produce_special_glyphs (it
, IT_CONTINUATION
);
16047 row
->continued_p
= 1;
16048 it
->current_x
= x_before
;
16049 it
->continuation_lines_width
+= x_before
;
16051 /* Restore the height to what it was before the
16052 element not fitting on the line. */
16053 it
->max_ascent
= ascent
;
16054 it
->max_descent
= descent
;
16055 it
->max_phys_ascent
= phys_ascent
;
16056 it
->max_phys_descent
= phys_descent
;
16058 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16060 /* A TAB that extends past the right edge of the
16061 window. This produces a single glyph on
16062 window system frames. We leave the glyph in
16063 this row and let it fill the row, but don't
16064 consume the TAB. */
16065 it
->continuation_lines_width
+= it
->last_visible_x
;
16066 row
->ends_in_middle_of_char_p
= 1;
16067 row
->continued_p
= 1;
16068 glyph
->pixel_width
= it
->last_visible_x
- x
;
16069 it
->starts_in_middle_of_char_p
= 1;
16073 /* Something other than a TAB that draws past
16074 the right edge of the window. Restore
16075 positions to values before the element. */
16076 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16078 /* Display continuation glyphs. */
16079 if (!FRAME_WINDOW_P (it
->f
))
16080 produce_special_glyphs (it
, IT_CONTINUATION
);
16081 row
->continued_p
= 1;
16083 it
->current_x
= x_before
;
16084 it
->continuation_lines_width
+= x
;
16085 extend_face_to_end_of_line (it
);
16087 if (nglyphs
> 1 && i
> 0)
16089 row
->ends_in_middle_of_char_p
= 1;
16090 it
->starts_in_middle_of_char_p
= 1;
16093 /* Restore the height to what it was before the
16094 element not fitting on the line. */
16095 it
->max_ascent
= ascent
;
16096 it
->max_descent
= descent
;
16097 it
->max_phys_ascent
= phys_ascent
;
16098 it
->max_phys_descent
= phys_descent
;
16103 else if (new_x
> it
->first_visible_x
)
16105 /* Increment number of glyphs actually displayed. */
16108 if (x
< it
->first_visible_x
)
16109 /* Glyph is partially visible, i.e. row starts at
16110 negative X position. */
16111 row
->x
= x
- it
->first_visible_x
;
16115 /* Glyph is completely off the left margin of the
16116 window. This should not happen because of the
16117 move_it_in_display_line at the start of this
16118 function, unless the text display area of the
16119 window is empty. */
16120 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16124 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16125 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16126 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16127 row
->phys_height
= max (row
->phys_height
,
16128 it
->max_phys_ascent
+ it
->max_phys_descent
);
16129 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16130 it
->max_extra_line_spacing
);
16132 /* End of this display line if row is continued. */
16133 if (row
->continued_p
|| row
->ends_at_zv_p
)
16138 /* Is this a line end? If yes, we're also done, after making
16139 sure that a non-default face is extended up to the right
16140 margin of the window. */
16141 if (ITERATOR_AT_END_OF_LINE_P (it
))
16143 int used_before
= row
->used
[TEXT_AREA
];
16145 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16147 #ifdef HAVE_WINDOW_SYSTEM
16148 /* Add a space at the end of the line that is used to
16149 display the cursor there. */
16150 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16151 append_space_for_newline (it
, 0);
16152 #endif /* HAVE_WINDOW_SYSTEM */
16154 /* Extend the face to the end of the line. */
16155 extend_face_to_end_of_line (it
);
16157 /* Make sure we have the position. */
16158 if (used_before
== 0)
16159 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16161 /* Consume the line end. This skips over invisible lines. */
16162 set_iterator_to_next (it
, 1);
16163 it
->continuation_lines_width
= 0;
16167 /* Proceed with next display element. Note that this skips
16168 over lines invisible because of selective display. */
16169 set_iterator_to_next (it
, 1);
16171 /* If we truncate lines, we are done when the last displayed
16172 glyphs reach past the right margin of the window. */
16173 if (it
->truncate_lines_p
16174 && (FRAME_WINDOW_P (it
->f
)
16175 ? (it
->current_x
>= it
->last_visible_x
)
16176 : (it
->current_x
> it
->last_visible_x
)))
16178 /* Maybe add truncation glyphs. */
16179 if (!FRAME_WINDOW_P (it
->f
))
16183 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16184 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16187 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16189 row
->used
[TEXT_AREA
] = i
;
16190 produce_special_glyphs (it
, IT_TRUNCATION
);
16193 #ifdef HAVE_WINDOW_SYSTEM
16196 /* Don't truncate if we can overflow newline into fringe. */
16197 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16199 if (!get_next_display_element (it
))
16201 it
->continuation_lines_width
= 0;
16202 row
->ends_at_zv_p
= 1;
16203 row
->exact_window_width_line_p
= 1;
16206 if (ITERATOR_AT_END_OF_LINE_P (it
))
16208 row
->exact_window_width_line_p
= 1;
16209 goto at_end_of_line
;
16213 #endif /* HAVE_WINDOW_SYSTEM */
16215 row
->truncated_on_right_p
= 1;
16216 it
->continuation_lines_width
= 0;
16217 reseat_at_next_visible_line_start (it
, 0);
16218 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16219 it
->hpos
= hpos_before
;
16220 it
->current_x
= x_before
;
16225 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16226 at the left window margin. */
16227 if (it
->first_visible_x
16228 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16230 if (!FRAME_WINDOW_P (it
->f
))
16231 insert_left_trunc_glyphs (it
);
16232 row
->truncated_on_left_p
= 1;
16235 /* If the start of this line is the overlay arrow-position, then
16236 mark this glyph row as the one containing the overlay arrow.
16237 This is clearly a mess with variable size fonts. It would be
16238 better to let it be displayed like cursors under X. */
16239 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16240 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16241 !NILP (overlay_arrow_string
)))
16243 /* Overlay arrow in window redisplay is a fringe bitmap. */
16244 if (STRINGP (overlay_arrow_string
))
16246 struct glyph_row
*arrow_row
16247 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16248 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16249 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16250 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16251 struct glyph
*p2
, *end
;
16253 /* Copy the arrow glyphs. */
16254 while (glyph
< arrow_end
)
16257 /* Throw away padding glyphs. */
16259 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16260 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16266 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16271 xassert (INTEGERP (overlay_arrow_string
));
16272 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16274 overlay_arrow_seen
= 1;
16277 /* Compute pixel dimensions of this line. */
16278 compute_line_metrics (it
);
16280 /* Remember the position at which this line ends. */
16281 row
->end
= it
->current
;
16283 /* Record whether this row ends inside an ellipsis. */
16284 row
->ends_in_ellipsis_p
16285 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16286 && it
->ellipsis_p
);
16288 /* Save fringe bitmaps in this row. */
16289 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16290 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16291 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16292 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16294 it
->left_user_fringe_bitmap
= 0;
16295 it
->left_user_fringe_face_id
= 0;
16296 it
->right_user_fringe_bitmap
= 0;
16297 it
->right_user_fringe_face_id
= 0;
16299 /* Maybe set the cursor. */
16300 if (it
->w
->cursor
.vpos
< 0
16301 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16302 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16303 && cursor_row_p (it
->w
, row
))
16304 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16306 /* Highlight trailing whitespace. */
16307 if (!NILP (Vshow_trailing_whitespace
))
16308 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16310 /* Prepare for the next line. This line starts horizontally at (X
16311 HPOS) = (0 0). Vertical positions are incremented. As a
16312 convenience for the caller, IT->glyph_row is set to the next
16314 it
->current_x
= it
->hpos
= 0;
16315 it
->current_y
+= row
->height
;
16318 it
->start
= it
->current
;
16319 return row
->displays_text_p
;
16324 /***********************************************************************
16326 ***********************************************************************/
16328 /* Redisplay the menu bar in the frame for window W.
16330 The menu bar of X frames that don't have X toolkit support is
16331 displayed in a special window W->frame->menu_bar_window.
16333 The menu bar of terminal frames is treated specially as far as
16334 glyph matrices are concerned. Menu bar lines are not part of
16335 windows, so the update is done directly on the frame matrix rows
16336 for the menu bar. */
16339 display_menu_bar (w
)
16342 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16347 /* Don't do all this for graphical frames. */
16349 if (!NILP (Vwindow_system
))
16352 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16357 if (FRAME_MAC_P (f
))
16361 #ifdef USE_X_TOOLKIT
16362 xassert (!FRAME_WINDOW_P (f
));
16363 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16364 it
.first_visible_x
= 0;
16365 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16366 #else /* not USE_X_TOOLKIT */
16367 if (FRAME_WINDOW_P (f
))
16369 /* Menu bar lines are displayed in the desired matrix of the
16370 dummy window menu_bar_window. */
16371 struct window
*menu_w
;
16372 xassert (WINDOWP (f
->menu_bar_window
));
16373 menu_w
= XWINDOW (f
->menu_bar_window
);
16374 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16376 it
.first_visible_x
= 0;
16377 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16381 /* This is a TTY frame, i.e. character hpos/vpos are used as
16383 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16385 it
.first_visible_x
= 0;
16386 it
.last_visible_x
= FRAME_COLS (f
);
16388 #endif /* not USE_X_TOOLKIT */
16390 if (! mode_line_inverse_video
)
16391 /* Force the menu-bar to be displayed in the default face. */
16392 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16394 /* Clear all rows of the menu bar. */
16395 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16397 struct glyph_row
*row
= it
.glyph_row
+ i
;
16398 clear_glyph_row (row
);
16399 row
->enabled_p
= 1;
16400 row
->full_width_p
= 1;
16403 /* Display all items of the menu bar. */
16404 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16405 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16407 Lisp_Object string
;
16409 /* Stop at nil string. */
16410 string
= AREF (items
, i
+ 1);
16414 /* Remember where item was displayed. */
16415 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16417 /* Display the item, pad with one space. */
16418 if (it
.current_x
< it
.last_visible_x
)
16419 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16420 SCHARS (string
) + 1, 0, 0, -1);
16423 /* Fill out the line with spaces. */
16424 if (it
.current_x
< it
.last_visible_x
)
16425 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16427 /* Compute the total height of the lines. */
16428 compute_line_metrics (&it
);
16433 /***********************************************************************
16435 ***********************************************************************/
16437 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16438 FORCE is non-zero, redisplay mode lines unconditionally.
16439 Otherwise, redisplay only mode lines that are garbaged. Value is
16440 the number of windows whose mode lines were redisplayed. */
16443 redisplay_mode_lines (window
, force
)
16444 Lisp_Object window
;
16449 while (!NILP (window
))
16451 struct window
*w
= XWINDOW (window
);
16453 if (WINDOWP (w
->hchild
))
16454 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16455 else if (WINDOWP (w
->vchild
))
16456 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16458 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16459 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16461 struct text_pos lpoint
;
16462 struct buffer
*old
= current_buffer
;
16464 /* Set the window's buffer for the mode line display. */
16465 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16466 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16468 /* Point refers normally to the selected window. For any
16469 other window, set up appropriate value. */
16470 if (!EQ (window
, selected_window
))
16472 struct text_pos pt
;
16474 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16475 if (CHARPOS (pt
) < BEGV
)
16476 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16477 else if (CHARPOS (pt
) > (ZV
- 1))
16478 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16480 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16483 /* Display mode lines. */
16484 clear_glyph_matrix (w
->desired_matrix
);
16485 if (display_mode_lines (w
))
16488 w
->must_be_updated_p
= 1;
16491 /* Restore old settings. */
16492 set_buffer_internal_1 (old
);
16493 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16503 /* Display the mode and/or top line of window W. Value is the number
16504 of mode lines displayed. */
16507 display_mode_lines (w
)
16510 Lisp_Object old_selected_window
, old_selected_frame
;
16513 old_selected_frame
= selected_frame
;
16514 selected_frame
= w
->frame
;
16515 old_selected_window
= selected_window
;
16516 XSETWINDOW (selected_window
, w
);
16518 /* These will be set while the mode line specs are processed. */
16519 line_number_displayed
= 0;
16520 w
->column_number_displayed
= Qnil
;
16522 if (WINDOW_WANTS_MODELINE_P (w
))
16524 struct window
*sel_w
= XWINDOW (old_selected_window
);
16526 /* Select mode line face based on the real selected window. */
16527 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16528 current_buffer
->mode_line_format
);
16532 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16534 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16535 current_buffer
->header_line_format
);
16539 selected_frame
= old_selected_frame
;
16540 selected_window
= old_selected_window
;
16545 /* Display mode or top line of window W. FACE_ID specifies which line
16546 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16547 FORMAT is the mode line format to display. Value is the pixel
16548 height of the mode line displayed. */
16551 display_mode_line (w
, face_id
, format
)
16553 enum face_id face_id
;
16554 Lisp_Object format
;
16558 int count
= SPECPDL_INDEX ();
16560 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16561 prepare_desired_row (it
.glyph_row
);
16563 it
.glyph_row
->mode_line_p
= 1;
16565 if (! mode_line_inverse_video
)
16566 /* Force the mode-line to be displayed in the default face. */
16567 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16569 record_unwind_protect (unwind_format_mode_line
,
16570 format_mode_line_unwind_data (NULL
, 0));
16572 mode_line_target
= MODE_LINE_DISPLAY
;
16574 /* Temporarily make frame's keyboard the current kboard so that
16575 kboard-local variables in the mode_line_format will get the right
16577 push_frame_kboard (it
.f
);
16578 record_unwind_save_match_data ();
16579 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16580 pop_frame_kboard ();
16582 unbind_to (count
, Qnil
);
16584 /* Fill up with spaces. */
16585 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16587 compute_line_metrics (&it
);
16588 it
.glyph_row
->full_width_p
= 1;
16589 it
.glyph_row
->continued_p
= 0;
16590 it
.glyph_row
->truncated_on_left_p
= 0;
16591 it
.glyph_row
->truncated_on_right_p
= 0;
16593 /* Make a 3D mode-line have a shadow at its right end. */
16594 face
= FACE_FROM_ID (it
.f
, face_id
);
16595 extend_face_to_end_of_line (&it
);
16596 if (face
->box
!= FACE_NO_BOX
)
16598 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16599 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16600 last
->right_box_line_p
= 1;
16603 return it
.glyph_row
->height
;
16606 /* Move element ELT in LIST to the front of LIST.
16607 Return the updated list. */
16610 move_elt_to_front (elt
, list
)
16611 Lisp_Object elt
, list
;
16613 register Lisp_Object tail
, prev
;
16614 register Lisp_Object tem
;
16618 while (CONSP (tail
))
16624 /* Splice out the link TAIL. */
16626 list
= XCDR (tail
);
16628 Fsetcdr (prev
, XCDR (tail
));
16630 /* Now make it the first. */
16631 Fsetcdr (tail
, list
);
16636 tail
= XCDR (tail
);
16640 /* Not found--return unchanged LIST. */
16644 /* Contribute ELT to the mode line for window IT->w. How it
16645 translates into text depends on its data type.
16647 IT describes the display environment in which we display, as usual.
16649 DEPTH is the depth in recursion. It is used to prevent
16650 infinite recursion here.
16652 FIELD_WIDTH is the number of characters the display of ELT should
16653 occupy in the mode line, and PRECISION is the maximum number of
16654 characters to display from ELT's representation. See
16655 display_string for details.
16657 Returns the hpos of the end of the text generated by ELT.
16659 PROPS is a property list to add to any string we encounter.
16661 If RISKY is nonzero, remove (disregard) any properties in any string
16662 we encounter, and ignore :eval and :propertize.
16664 The global variable `mode_line_target' determines whether the
16665 output is passed to `store_mode_line_noprop',
16666 `store_mode_line_string', or `display_string'. */
16669 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16672 int field_width
, precision
;
16673 Lisp_Object elt
, props
;
16676 int n
= 0, field
, prec
;
16681 elt
= build_string ("*too-deep*");
16685 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16689 /* A string: output it and check for %-constructs within it. */
16693 if (SCHARS (elt
) > 0
16694 && (!NILP (props
) || risky
))
16696 Lisp_Object oprops
, aelt
;
16697 oprops
= Ftext_properties_at (make_number (0), elt
);
16699 /* If the starting string's properties are not what
16700 we want, translate the string. Also, if the string
16701 is risky, do that anyway. */
16703 if (NILP (Fequal (props
, oprops
)) || risky
)
16705 /* If the starting string has properties,
16706 merge the specified ones onto the existing ones. */
16707 if (! NILP (oprops
) && !risky
)
16711 oprops
= Fcopy_sequence (oprops
);
16713 while (CONSP (tem
))
16715 oprops
= Fplist_put (oprops
, XCAR (tem
),
16716 XCAR (XCDR (tem
)));
16717 tem
= XCDR (XCDR (tem
));
16722 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16723 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16725 /* AELT is what we want. Move it to the front
16726 without consing. */
16728 mode_line_proptrans_alist
16729 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16735 /* If AELT has the wrong props, it is useless.
16736 so get rid of it. */
16738 mode_line_proptrans_alist
16739 = Fdelq (aelt
, mode_line_proptrans_alist
);
16741 elt
= Fcopy_sequence (elt
);
16742 Fset_text_properties (make_number (0), Flength (elt
),
16744 /* Add this item to mode_line_proptrans_alist. */
16745 mode_line_proptrans_alist
16746 = Fcons (Fcons (elt
, props
),
16747 mode_line_proptrans_alist
);
16748 /* Truncate mode_line_proptrans_alist
16749 to at most 50 elements. */
16750 tem
= Fnthcdr (make_number (50),
16751 mode_line_proptrans_alist
);
16753 XSETCDR (tem
, Qnil
);
16762 prec
= precision
- n
;
16763 switch (mode_line_target
)
16765 case MODE_LINE_NOPROP
:
16766 case MODE_LINE_TITLE
:
16767 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16769 case MODE_LINE_STRING
:
16770 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16772 case MODE_LINE_DISPLAY
:
16773 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16774 0, prec
, 0, STRING_MULTIBYTE (elt
));
16781 /* Handle the non-literal case. */
16783 while ((precision
<= 0 || n
< precision
)
16784 && SREF (elt
, offset
) != 0
16785 && (mode_line_target
!= MODE_LINE_DISPLAY
16786 || it
->current_x
< it
->last_visible_x
))
16788 int last_offset
= offset
;
16790 /* Advance to end of string or next format specifier. */
16791 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16794 if (offset
- 1 != last_offset
)
16796 int nchars
, nbytes
;
16798 /* Output to end of string or up to '%'. Field width
16799 is length of string. Don't output more than
16800 PRECISION allows us. */
16803 prec
= c_string_width (SDATA (elt
) + last_offset
,
16804 offset
- last_offset
, precision
- n
,
16807 switch (mode_line_target
)
16809 case MODE_LINE_NOPROP
:
16810 case MODE_LINE_TITLE
:
16811 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16813 case MODE_LINE_STRING
:
16815 int bytepos
= last_offset
;
16816 int charpos
= string_byte_to_char (elt
, bytepos
);
16817 int endpos
= (precision
<= 0
16818 ? string_byte_to_char (elt
, offset
)
16819 : charpos
+ nchars
);
16821 n
+= store_mode_line_string (NULL
,
16822 Fsubstring (elt
, make_number (charpos
),
16823 make_number (endpos
)),
16827 case MODE_LINE_DISPLAY
:
16829 int bytepos
= last_offset
;
16830 int charpos
= string_byte_to_char (elt
, bytepos
);
16832 if (precision
<= 0)
16833 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16834 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16836 STRING_MULTIBYTE (elt
));
16841 else /* c == '%' */
16843 int percent_position
= offset
;
16845 /* Get the specified minimum width. Zero means
16848 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16849 field
= field
* 10 + c
- '0';
16851 /* Don't pad beyond the total padding allowed. */
16852 if (field_width
- n
> 0 && field
> field_width
- n
)
16853 field
= field_width
- n
;
16855 /* Note that either PRECISION <= 0 or N < PRECISION. */
16856 prec
= precision
- n
;
16859 n
+= display_mode_element (it
, depth
, field
, prec
,
16860 Vglobal_mode_string
, props
,
16865 int bytepos
, charpos
;
16866 unsigned char *spec
;
16868 bytepos
= percent_position
;
16869 charpos
= (STRING_MULTIBYTE (elt
)
16870 ? string_byte_to_char (elt
, bytepos
)
16874 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16876 switch (mode_line_target
)
16878 case MODE_LINE_NOPROP
:
16879 case MODE_LINE_TITLE
:
16880 n
+= store_mode_line_noprop (spec
, field
, prec
);
16882 case MODE_LINE_STRING
:
16884 int len
= strlen (spec
);
16885 Lisp_Object tem
= make_string (spec
, len
);
16886 props
= Ftext_properties_at (make_number (charpos
), elt
);
16887 /* Should only keep face property in props */
16888 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16891 case MODE_LINE_DISPLAY
:
16893 int nglyphs_before
, nwritten
;
16895 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16896 nwritten
= display_string (spec
, Qnil
, elt
,
16901 /* Assign to the glyphs written above the
16902 string where the `%x' came from, position
16906 struct glyph
*glyph
16907 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16911 for (i
= 0; i
< nwritten
; ++i
)
16913 glyph
[i
].object
= elt
;
16914 glyph
[i
].charpos
= charpos
;
16931 /* A symbol: process the value of the symbol recursively
16932 as if it appeared here directly. Avoid error if symbol void.
16933 Special case: if value of symbol is a string, output the string
16936 register Lisp_Object tem
;
16938 /* If the variable is not marked as risky to set
16939 then its contents are risky to use. */
16940 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16943 tem
= Fboundp (elt
);
16946 tem
= Fsymbol_value (elt
);
16947 /* If value is a string, output that string literally:
16948 don't check for % within it. */
16952 if (!EQ (tem
, elt
))
16954 /* Give up right away for nil or t. */
16964 register Lisp_Object car
, tem
;
16966 /* A cons cell: five distinct cases.
16967 If first element is :eval or :propertize, do something special.
16968 If first element is a string or a cons, process all the elements
16969 and effectively concatenate them.
16970 If first element is a negative number, truncate displaying cdr to
16971 at most that many characters. If positive, pad (with spaces)
16972 to at least that many characters.
16973 If first element is a symbol, process the cadr or caddr recursively
16974 according to whether the symbol's value is non-nil or nil. */
16976 if (EQ (car
, QCeval
))
16978 /* An element of the form (:eval FORM) means evaluate FORM
16979 and use the result as mode line elements. */
16984 if (CONSP (XCDR (elt
)))
16987 spec
= safe_eval (XCAR (XCDR (elt
)));
16988 n
+= display_mode_element (it
, depth
, field_width
- n
,
16989 precision
- n
, spec
, props
,
16993 else if (EQ (car
, QCpropertize
))
16995 /* An element of the form (:propertize ELT PROPS...)
16996 means display ELT but applying properties PROPS. */
17001 if (CONSP (XCDR (elt
)))
17002 n
+= display_mode_element (it
, depth
, field_width
- n
,
17003 precision
- n
, XCAR (XCDR (elt
)),
17004 XCDR (XCDR (elt
)), risky
);
17006 else if (SYMBOLP (car
))
17008 tem
= Fboundp (car
);
17012 /* elt is now the cdr, and we know it is a cons cell.
17013 Use its car if CAR has a non-nil value. */
17016 tem
= Fsymbol_value (car
);
17023 /* Symbol's value is nil (or symbol is unbound)
17024 Get the cddr of the original list
17025 and if possible find the caddr and use that. */
17029 else if (!CONSP (elt
))
17034 else if (INTEGERP (car
))
17036 register int lim
= XINT (car
);
17040 /* Negative int means reduce maximum width. */
17041 if (precision
<= 0)
17044 precision
= min (precision
, -lim
);
17048 /* Padding specified. Don't let it be more than
17049 current maximum. */
17051 lim
= min (precision
, lim
);
17053 /* If that's more padding than already wanted, queue it.
17054 But don't reduce padding already specified even if
17055 that is beyond the current truncation point. */
17056 field_width
= max (lim
, field_width
);
17060 else if (STRINGP (car
) || CONSP (car
))
17062 register int limit
= 50;
17063 /* Limit is to protect against circular lists. */
17066 && (precision
<= 0 || n
< precision
))
17068 n
+= display_mode_element (it
, depth
,
17069 /* Do padding only after the last
17070 element in the list. */
17071 (! CONSP (XCDR (elt
))
17074 precision
- n
, XCAR (elt
),
17084 elt
= build_string ("*invalid*");
17088 /* Pad to FIELD_WIDTH. */
17089 if (field_width
> 0 && n
< field_width
)
17091 switch (mode_line_target
)
17093 case MODE_LINE_NOPROP
:
17094 case MODE_LINE_TITLE
:
17095 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17097 case MODE_LINE_STRING
:
17098 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17100 case MODE_LINE_DISPLAY
:
17101 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17110 /* Store a mode-line string element in mode_line_string_list.
17112 If STRING is non-null, display that C string. Otherwise, the Lisp
17113 string LISP_STRING is displayed.
17115 FIELD_WIDTH is the minimum number of output glyphs to produce.
17116 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17117 with spaces. FIELD_WIDTH <= 0 means don't pad.
17119 PRECISION is the maximum number of characters to output from
17120 STRING. PRECISION <= 0 means don't truncate the string.
17122 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17123 properties to the string.
17125 PROPS are the properties to add to the string.
17126 The mode_line_string_face face property is always added to the string.
17130 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17132 Lisp_Object lisp_string
;
17141 if (string
!= NULL
)
17143 len
= strlen (string
);
17144 if (precision
> 0 && len
> precision
)
17146 lisp_string
= make_string (string
, len
);
17148 props
= mode_line_string_face_prop
;
17149 else if (!NILP (mode_line_string_face
))
17151 Lisp_Object face
= Fplist_get (props
, Qface
);
17152 props
= Fcopy_sequence (props
);
17154 face
= mode_line_string_face
;
17156 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17157 props
= Fplist_put (props
, Qface
, face
);
17159 Fadd_text_properties (make_number (0), make_number (len
),
17160 props
, lisp_string
);
17164 len
= XFASTINT (Flength (lisp_string
));
17165 if (precision
> 0 && len
> precision
)
17168 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17171 if (!NILP (mode_line_string_face
))
17175 props
= Ftext_properties_at (make_number (0), lisp_string
);
17176 face
= Fplist_get (props
, Qface
);
17178 face
= mode_line_string_face
;
17180 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17181 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17183 lisp_string
= Fcopy_sequence (lisp_string
);
17186 Fadd_text_properties (make_number (0), make_number (len
),
17187 props
, lisp_string
);
17192 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17196 if (field_width
> len
)
17198 field_width
-= len
;
17199 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17201 Fadd_text_properties (make_number (0), make_number (field_width
),
17202 props
, lisp_string
);
17203 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17211 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17213 doc
: /* Format a string out of a mode line format specification.
17214 First arg FORMAT specifies the mode line format (see `mode-line-format'
17215 for details) to use.
17217 Optional second arg FACE specifies the face property to put
17218 on all characters for which no face is specified.
17219 t means whatever face the window's mode line currently uses
17220 \(either `mode-line' or `mode-line-inactive', depending).
17221 nil means the default is no face property.
17222 If FACE is an integer, the value string has no text properties.
17224 Optional third and fourth args WINDOW and BUFFER specify the window
17225 and buffer to use as the context for the formatting (defaults
17226 are the selected window and the window's buffer). */)
17227 (format
, face
, window
, buffer
)
17228 Lisp_Object format
, face
, window
, buffer
;
17233 struct buffer
*old_buffer
= NULL
;
17235 int no_props
= INTEGERP (face
);
17236 int count
= SPECPDL_INDEX ();
17238 int string_start
= 0;
17241 window
= selected_window
;
17242 CHECK_WINDOW (window
);
17243 w
= XWINDOW (window
);
17246 buffer
= w
->buffer
;
17247 CHECK_BUFFER (buffer
);
17250 return build_string ("");
17258 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17259 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17263 face_id
= DEFAULT_FACE_ID
;
17265 if (XBUFFER (buffer
) != current_buffer
)
17266 old_buffer
= current_buffer
;
17268 /* Save things including mode_line_proptrans_alist,
17269 and set that to nil so that we don't alter the outer value. */
17270 record_unwind_protect (unwind_format_mode_line
,
17271 format_mode_line_unwind_data (old_buffer
, 1));
17272 mode_line_proptrans_alist
= Qnil
;
17275 set_buffer_internal_1 (XBUFFER (buffer
));
17277 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17281 mode_line_target
= MODE_LINE_NOPROP
;
17282 mode_line_string_face_prop
= Qnil
;
17283 mode_line_string_list
= Qnil
;
17284 string_start
= MODE_LINE_NOPROP_LEN (0);
17288 mode_line_target
= MODE_LINE_STRING
;
17289 mode_line_string_list
= Qnil
;
17290 mode_line_string_face
= face
;
17291 mode_line_string_face_prop
17292 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17295 push_frame_kboard (it
.f
);
17296 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17297 pop_frame_kboard ();
17301 len
= MODE_LINE_NOPROP_LEN (string_start
);
17302 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17306 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17307 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17308 make_string ("", 0));
17311 unbind_to (count
, Qnil
);
17315 /* Write a null-terminated, right justified decimal representation of
17316 the positive integer D to BUF using a minimal field width WIDTH. */
17319 pint2str (buf
, width
, d
)
17320 register char *buf
;
17321 register int width
;
17324 register char *p
= buf
;
17332 *p
++ = d
% 10 + '0';
17337 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17348 /* Write a null-terminated, right justified decimal and "human
17349 readable" representation of the nonnegative integer D to BUF using
17350 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17352 static const char power_letter
[] =
17366 pint2hrstr (buf
, width
, d
)
17371 /* We aim to represent the nonnegative integer D as
17372 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17375 /* -1 means: do not use TENTHS. */
17379 /* Length of QUOTIENT.TENTHS as a string. */
17385 if (1000 <= quotient
)
17387 /* Scale to the appropriate EXPONENT. */
17390 remainder
= quotient
% 1000;
17394 while (1000 <= quotient
);
17396 /* Round to nearest and decide whether to use TENTHS or not. */
17399 tenths
= remainder
/ 100;
17400 if (50 <= remainder
% 100)
17407 if (quotient
== 10)
17415 if (500 <= remainder
)
17417 if (quotient
< 999)
17428 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17429 if (tenths
== -1 && quotient
<= 99)
17436 p
= psuffix
= buf
+ max (width
, length
);
17438 /* Print EXPONENT. */
17440 *psuffix
++ = power_letter
[exponent
];
17443 /* Print TENTHS. */
17446 *--p
= '0' + tenths
;
17450 /* Print QUOTIENT. */
17453 int digit
= quotient
% 10;
17454 *--p
= '0' + digit
;
17456 while ((quotient
/= 10) != 0);
17458 /* Print leading spaces. */
17463 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17464 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17465 type of CODING_SYSTEM. Return updated pointer into BUF. */
17467 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17470 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17471 Lisp_Object coding_system
;
17472 register char *buf
;
17476 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17477 const unsigned char *eol_str
;
17479 /* The EOL conversion we are using. */
17480 Lisp_Object eoltype
;
17482 val
= Fget (coding_system
, Qcoding_system
);
17485 if (!VECTORP (val
)) /* Not yet decided. */
17490 eoltype
= eol_mnemonic_undecided
;
17491 /* Don't mention EOL conversion if it isn't decided. */
17495 Lisp_Object eolvalue
;
17497 eolvalue
= Fget (coding_system
, Qeol_type
);
17500 *buf
++ = XFASTINT (AREF (val
, 1));
17504 /* The EOL conversion that is normal on this system. */
17506 if (NILP (eolvalue
)) /* Not yet decided. */
17507 eoltype
= eol_mnemonic_undecided
;
17508 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17509 eoltype
= eol_mnemonic_undecided
;
17510 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17511 eoltype
= (XFASTINT (eolvalue
) == 0
17512 ? eol_mnemonic_unix
17513 : (XFASTINT (eolvalue
) == 1
17514 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17520 /* Mention the EOL conversion if it is not the usual one. */
17521 if (STRINGP (eoltype
))
17523 eol_str
= SDATA (eoltype
);
17524 eol_str_len
= SBYTES (eoltype
);
17526 else if (INTEGERP (eoltype
)
17527 && CHAR_VALID_P (XINT (eoltype
), 0))
17529 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17530 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17535 eol_str
= invalid_eol_type
;
17536 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17538 bcopy (eol_str
, buf
, eol_str_len
);
17539 buf
+= eol_str_len
;
17545 /* Return a string for the output of a mode line %-spec for window W,
17546 generated by character C. PRECISION >= 0 means don't return a
17547 string longer than that value. FIELD_WIDTH > 0 means pad the
17548 string returned with spaces to that value. Return 1 in *MULTIBYTE
17549 if the result is multibyte text.
17551 Note we operate on the current buffer for most purposes,
17552 the exception being w->base_line_pos. */
17554 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17557 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17560 int field_width
, precision
;
17564 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17565 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17566 struct buffer
*b
= current_buffer
;
17574 if (!NILP (b
->read_only
))
17576 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17581 /* This differs from %* only for a modified read-only buffer. */
17582 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17584 if (!NILP (b
->read_only
))
17589 /* This differs from %* in ignoring read-only-ness. */
17590 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17602 if (command_loop_level
> 5)
17604 p
= decode_mode_spec_buf
;
17605 for (i
= 0; i
< command_loop_level
; i
++)
17608 return decode_mode_spec_buf
;
17616 if (command_loop_level
> 5)
17618 p
= decode_mode_spec_buf
;
17619 for (i
= 0; i
< command_loop_level
; i
++)
17622 return decode_mode_spec_buf
;
17629 /* Let lots_of_dashes be a string of infinite length. */
17630 if (mode_line_target
== MODE_LINE_NOPROP
||
17631 mode_line_target
== MODE_LINE_STRING
)
17633 if (field_width
<= 0
17634 || field_width
> sizeof (lots_of_dashes
))
17636 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17637 decode_mode_spec_buf
[i
] = '-';
17638 decode_mode_spec_buf
[i
] = '\0';
17639 return decode_mode_spec_buf
;
17642 return lots_of_dashes
;
17651 int col
= (int) current_column (); /* iftc */
17652 w
->column_number_displayed
= make_number (col
);
17653 pint2str (decode_mode_spec_buf
, field_width
, col
);
17654 return decode_mode_spec_buf
;
17658 #ifndef SYSTEM_MALLOC
17660 if (NILP (Vmemory_full
))
17663 return "!MEM FULL! ";
17670 /* %F displays the frame name. */
17671 if (!NILP (f
->title
))
17672 return (char *) SDATA (f
->title
);
17673 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17674 return (char *) SDATA (f
->name
);
17683 int size
= ZV
- BEGV
;
17684 pint2str (decode_mode_spec_buf
, field_width
, size
);
17685 return decode_mode_spec_buf
;
17690 int size
= ZV
- BEGV
;
17691 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17692 return decode_mode_spec_buf
;
17697 int startpos
= XMARKER (w
->start
)->charpos
;
17698 int startpos_byte
= marker_byte_position (w
->start
);
17699 int line
, linepos
, linepos_byte
, topline
;
17701 int height
= WINDOW_TOTAL_LINES (w
);
17703 /* If we decided that this buffer isn't suitable for line numbers,
17704 don't forget that too fast. */
17705 if (EQ (w
->base_line_pos
, w
->buffer
))
17707 /* But do forget it, if the window shows a different buffer now. */
17708 else if (BUFFERP (w
->base_line_pos
))
17709 w
->base_line_pos
= Qnil
;
17711 /* If the buffer is very big, don't waste time. */
17712 if (INTEGERP (Vline_number_display_limit
)
17713 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17715 w
->base_line_pos
= Qnil
;
17716 w
->base_line_number
= Qnil
;
17720 if (!NILP (w
->base_line_number
)
17721 && !NILP (w
->base_line_pos
)
17722 && XFASTINT (w
->base_line_pos
) <= startpos
)
17724 line
= XFASTINT (w
->base_line_number
);
17725 linepos
= XFASTINT (w
->base_line_pos
);
17726 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17731 linepos
= BUF_BEGV (b
);
17732 linepos_byte
= BUF_BEGV_BYTE (b
);
17735 /* Count lines from base line to window start position. */
17736 nlines
= display_count_lines (linepos
, linepos_byte
,
17740 topline
= nlines
+ line
;
17742 /* Determine a new base line, if the old one is too close
17743 or too far away, or if we did not have one.
17744 "Too close" means it's plausible a scroll-down would
17745 go back past it. */
17746 if (startpos
== BUF_BEGV (b
))
17748 w
->base_line_number
= make_number (topline
);
17749 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17751 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17752 || linepos
== BUF_BEGV (b
))
17754 int limit
= BUF_BEGV (b
);
17755 int limit_byte
= BUF_BEGV_BYTE (b
);
17757 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17759 if (startpos
- distance
> limit
)
17761 limit
= startpos
- distance
;
17762 limit_byte
= CHAR_TO_BYTE (limit
);
17765 nlines
= display_count_lines (startpos
, startpos_byte
,
17767 - (height
* 2 + 30),
17769 /* If we couldn't find the lines we wanted within
17770 line_number_display_limit_width chars per line,
17771 give up on line numbers for this window. */
17772 if (position
== limit_byte
&& limit
== startpos
- distance
)
17774 w
->base_line_pos
= w
->buffer
;
17775 w
->base_line_number
= Qnil
;
17779 w
->base_line_number
= make_number (topline
- nlines
);
17780 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17783 /* Now count lines from the start pos to point. */
17784 nlines
= display_count_lines (startpos
, startpos_byte
,
17785 PT_BYTE
, PT
, &junk
);
17787 /* Record that we did display the line number. */
17788 line_number_displayed
= 1;
17790 /* Make the string to show. */
17791 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17792 return decode_mode_spec_buf
;
17795 char* p
= decode_mode_spec_buf
;
17796 int pad
= field_width
- 2;
17802 return decode_mode_spec_buf
;
17808 obj
= b
->mode_name
;
17812 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17818 int pos
= marker_position (w
->start
);
17819 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17821 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17823 if (pos
<= BUF_BEGV (b
))
17828 else if (pos
<= BUF_BEGV (b
))
17832 if (total
> 1000000)
17833 /* Do it differently for a large value, to avoid overflow. */
17834 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17836 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17837 /* We can't normally display a 3-digit number,
17838 so get us a 2-digit number that is close. */
17841 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17842 return decode_mode_spec_buf
;
17846 /* Display percentage of size above the bottom of the screen. */
17849 int toppos
= marker_position (w
->start
);
17850 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17851 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17853 if (botpos
>= BUF_ZV (b
))
17855 if (toppos
<= BUF_BEGV (b
))
17862 if (total
> 1000000)
17863 /* Do it differently for a large value, to avoid overflow. */
17864 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17866 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17867 /* We can't normally display a 3-digit number,
17868 so get us a 2-digit number that is close. */
17871 if (toppos
<= BUF_BEGV (b
))
17872 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17874 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17875 return decode_mode_spec_buf
;
17880 /* status of process */
17881 obj
= Fget_buffer_process (Fcurrent_buffer ());
17883 return "no process";
17884 #ifdef subprocesses
17885 obj
= Fsymbol_name (Fprocess_status (obj
));
17889 case 't': /* indicate TEXT or BINARY */
17890 #ifdef MODE_LINE_BINARY_TEXT
17891 return MODE_LINE_BINARY_TEXT (b
);
17897 /* coding-system (not including end-of-line format) */
17899 /* coding-system (including end-of-line type) */
17901 int eol_flag
= (c
== 'Z');
17902 char *p
= decode_mode_spec_buf
;
17904 if (! FRAME_WINDOW_P (f
))
17906 /* No need to mention EOL here--the terminal never needs
17907 to do EOL conversion. */
17908 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17909 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17911 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17914 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17915 #ifdef subprocesses
17916 obj
= Fget_buffer_process (Fcurrent_buffer ());
17917 if (PROCESSP (obj
))
17919 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17921 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17924 #endif /* subprocesses */
17927 return decode_mode_spec_buf
;
17933 *multibyte
= STRING_MULTIBYTE (obj
);
17934 return (char *) SDATA (obj
);
17941 /* Count up to COUNT lines starting from START / START_BYTE.
17942 But don't go beyond LIMIT_BYTE.
17943 Return the number of lines thus found (always nonnegative).
17945 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17948 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17949 int start
, start_byte
, limit_byte
, count
;
17952 register unsigned char *cursor
;
17953 unsigned char *base
;
17955 register int ceiling
;
17956 register unsigned char *ceiling_addr
;
17957 int orig_count
= count
;
17959 /* If we are not in selective display mode,
17960 check only for newlines. */
17961 int selective_display
= (!NILP (current_buffer
->selective_display
)
17962 && !INTEGERP (current_buffer
->selective_display
));
17966 while (start_byte
< limit_byte
)
17968 ceiling
= BUFFER_CEILING_OF (start_byte
);
17969 ceiling
= min (limit_byte
- 1, ceiling
);
17970 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17971 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17974 if (selective_display
)
17975 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17978 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17981 if (cursor
!= ceiling_addr
)
17985 start_byte
+= cursor
- base
+ 1;
17986 *byte_pos_ptr
= start_byte
;
17990 if (++cursor
== ceiling_addr
)
17996 start_byte
+= cursor
- base
;
18001 while (start_byte
> limit_byte
)
18003 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18004 ceiling
= max (limit_byte
, ceiling
);
18005 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18006 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18009 if (selective_display
)
18010 while (--cursor
!= ceiling_addr
18011 && *cursor
!= '\n' && *cursor
!= 015)
18014 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18017 if (cursor
!= ceiling_addr
)
18021 start_byte
+= cursor
- base
+ 1;
18022 *byte_pos_ptr
= start_byte
;
18023 /* When scanning backwards, we should
18024 not count the newline posterior to which we stop. */
18025 return - orig_count
- 1;
18031 /* Here we add 1 to compensate for the last decrement
18032 of CURSOR, which took it past the valid range. */
18033 start_byte
+= cursor
- base
+ 1;
18037 *byte_pos_ptr
= limit_byte
;
18040 return - orig_count
+ count
;
18041 return orig_count
- count
;
18047 /***********************************************************************
18049 ***********************************************************************/
18051 /* Display a NUL-terminated string, starting with index START.
18053 If STRING is non-null, display that C string. Otherwise, the Lisp
18054 string LISP_STRING is displayed.
18056 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18057 FACE_STRING. Display STRING or LISP_STRING with the face at
18058 FACE_STRING_POS in FACE_STRING:
18060 Display the string in the environment given by IT, but use the
18061 standard display table, temporarily.
18063 FIELD_WIDTH is the minimum number of output glyphs to produce.
18064 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18065 with spaces. If STRING has more characters, more than FIELD_WIDTH
18066 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18068 PRECISION is the maximum number of characters to output from
18069 STRING. PRECISION < 0 means don't truncate the string.
18071 This is roughly equivalent to printf format specifiers:
18073 FIELD_WIDTH PRECISION PRINTF
18074 ----------------------------------------
18080 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18081 display them, and < 0 means obey the current buffer's value of
18082 enable_multibyte_characters.
18084 Value is the number of columns displayed. */
18087 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18088 start
, it
, field_width
, precision
, max_x
, multibyte
)
18089 unsigned char *string
;
18090 Lisp_Object lisp_string
;
18091 Lisp_Object face_string
;
18092 int face_string_pos
;
18095 int field_width
, precision
, max_x
;
18098 int hpos_at_start
= it
->hpos
;
18099 int saved_face_id
= it
->face_id
;
18100 struct glyph_row
*row
= it
->glyph_row
;
18102 /* Initialize the iterator IT for iteration over STRING beginning
18103 with index START. */
18104 reseat_to_string (it
, string
, lisp_string
, start
,
18105 precision
, field_width
, multibyte
);
18107 /* If displaying STRING, set up the face of the iterator
18108 from LISP_STRING, if that's given. */
18109 if (STRINGP (face_string
))
18115 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18116 0, it
->region_beg_charpos
,
18117 it
->region_end_charpos
,
18118 &endptr
, it
->base_face_id
, 0);
18119 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18120 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18123 /* Set max_x to the maximum allowed X position. Don't let it go
18124 beyond the right edge of the window. */
18126 max_x
= it
->last_visible_x
;
18128 max_x
= min (max_x
, it
->last_visible_x
);
18130 /* Skip over display elements that are not visible. because IT->w is
18132 if (it
->current_x
< it
->first_visible_x
)
18133 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18134 MOVE_TO_POS
| MOVE_TO_X
);
18136 row
->ascent
= it
->max_ascent
;
18137 row
->height
= it
->max_ascent
+ it
->max_descent
;
18138 row
->phys_ascent
= it
->max_phys_ascent
;
18139 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18140 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18142 /* This condition is for the case that we are called with current_x
18143 past last_visible_x. */
18144 while (it
->current_x
< max_x
)
18146 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18148 /* Get the next display element. */
18149 if (!get_next_display_element (it
))
18152 /* Produce glyphs. */
18153 x_before
= it
->current_x
;
18154 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18155 PRODUCE_GLYPHS (it
);
18157 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18160 while (i
< nglyphs
)
18162 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18164 if (!it
->truncate_lines_p
18165 && x
+ glyph
->pixel_width
> max_x
)
18167 /* End of continued line or max_x reached. */
18168 if (CHAR_GLYPH_PADDING_P (*glyph
))
18170 /* A wide character is unbreakable. */
18171 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18172 it
->current_x
= x_before
;
18176 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18181 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18183 /* Glyph is at least partially visible. */
18185 if (x
< it
->first_visible_x
)
18186 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18190 /* Glyph is off the left margin of the display area.
18191 Should not happen. */
18195 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18196 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18197 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18198 row
->phys_height
= max (row
->phys_height
,
18199 it
->max_phys_ascent
+ it
->max_phys_descent
);
18200 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18201 it
->max_extra_line_spacing
);
18202 x
+= glyph
->pixel_width
;
18206 /* Stop if max_x reached. */
18210 /* Stop at line ends. */
18211 if (ITERATOR_AT_END_OF_LINE_P (it
))
18213 it
->continuation_lines_width
= 0;
18217 set_iterator_to_next (it
, 1);
18219 /* Stop if truncating at the right edge. */
18220 if (it
->truncate_lines_p
18221 && it
->current_x
>= it
->last_visible_x
)
18223 /* Add truncation mark, but don't do it if the line is
18224 truncated at a padding space. */
18225 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18227 if (!FRAME_WINDOW_P (it
->f
))
18231 if (it
->current_x
> it
->last_visible_x
)
18233 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18234 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18236 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18238 row
->used
[TEXT_AREA
] = i
;
18239 produce_special_glyphs (it
, IT_TRUNCATION
);
18242 produce_special_glyphs (it
, IT_TRUNCATION
);
18244 it
->glyph_row
->truncated_on_right_p
= 1;
18250 /* Maybe insert a truncation at the left. */
18251 if (it
->first_visible_x
18252 && IT_CHARPOS (*it
) > 0)
18254 if (!FRAME_WINDOW_P (it
->f
))
18255 insert_left_trunc_glyphs (it
);
18256 it
->glyph_row
->truncated_on_left_p
= 1;
18259 it
->face_id
= saved_face_id
;
18261 /* Value is number of columns displayed. */
18262 return it
->hpos
- hpos_at_start
;
18267 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18268 appears as an element of LIST or as the car of an element of LIST.
18269 If PROPVAL is a list, compare each element against LIST in that
18270 way, and return 1/2 if any element of PROPVAL is found in LIST.
18271 Otherwise return 0. This function cannot quit.
18272 The return value is 2 if the text is invisible but with an ellipsis
18273 and 1 if it's invisible and without an ellipsis. */
18276 invisible_p (propval
, list
)
18277 register Lisp_Object propval
;
18280 register Lisp_Object tail
, proptail
;
18282 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18284 register Lisp_Object tem
;
18286 if (EQ (propval
, tem
))
18288 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18289 return NILP (XCDR (tem
)) ? 1 : 2;
18292 if (CONSP (propval
))
18294 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18296 Lisp_Object propelt
;
18297 propelt
= XCAR (proptail
);
18298 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18300 register Lisp_Object tem
;
18302 if (EQ (propelt
, tem
))
18304 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18305 return NILP (XCDR (tem
)) ? 1 : 2;
18313 /* Calculate a width or height in pixels from a specification using
18314 the following elements:
18317 NUM - a (fractional) multiple of the default font width/height
18318 (NUM) - specifies exactly NUM pixels
18319 UNIT - a fixed number of pixels, see below.
18320 ELEMENT - size of a display element in pixels, see below.
18321 (NUM . SPEC) - equals NUM * SPEC
18322 (+ SPEC SPEC ...) - add pixel values
18323 (- SPEC SPEC ...) - subtract pixel values
18324 (- SPEC) - negate pixel value
18327 INT or FLOAT - a number constant
18328 SYMBOL - use symbol's (buffer local) variable binding.
18331 in - pixels per inch *)
18332 mm - pixels per 1/1000 meter *)
18333 cm - pixels per 1/100 meter *)
18334 width - width of current font in pixels.
18335 height - height of current font in pixels.
18337 *) using the ratio(s) defined in display-pixels-per-inch.
18341 left-fringe - left fringe width in pixels
18342 right-fringe - right fringe width in pixels
18344 left-margin - left margin width in pixels
18345 right-margin - right margin width in pixels
18347 scroll-bar - scroll-bar area width in pixels
18351 Pixels corresponding to 5 inches:
18354 Total width of non-text areas on left side of window (if scroll-bar is on left):
18355 '(space :width (+ left-fringe left-margin scroll-bar))
18357 Align to first text column (in header line):
18358 '(space :align-to 0)
18360 Align to middle of text area minus half the width of variable `my-image'
18361 containing a loaded image:
18362 '(space :align-to (0.5 . (- text my-image)))
18364 Width of left margin minus width of 1 character in the default font:
18365 '(space :width (- left-margin 1))
18367 Width of left margin minus width of 2 characters in the current font:
18368 '(space :width (- left-margin (2 . width)))
18370 Center 1 character over left-margin (in header line):
18371 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18373 Different ways to express width of left fringe plus left margin minus one pixel:
18374 '(space :width (- (+ left-fringe left-margin) (1)))
18375 '(space :width (+ left-fringe left-margin (- (1))))
18376 '(space :width (+ left-fringe left-margin (-1)))
18380 #define NUMVAL(X) \
18381 ((INTEGERP (X) || FLOATP (X)) \
18386 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18391 int width_p
, *align_to
;
18395 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18396 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18399 return OK_PIXELS (0);
18401 if (SYMBOLP (prop
))
18403 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18405 char *unit
= SDATA (SYMBOL_NAME (prop
));
18407 if (unit
[0] == 'i' && unit
[1] == 'n')
18409 else if (unit
[0] == 'm' && unit
[1] == 'm')
18411 else if (unit
[0] == 'c' && unit
[1] == 'm')
18418 #ifdef HAVE_WINDOW_SYSTEM
18419 if (FRAME_WINDOW_P (it
->f
)
18421 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18422 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18424 return OK_PIXELS (ppi
/ pixels
);
18427 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18428 || (CONSP (Vdisplay_pixels_per_inch
)
18430 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18431 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18433 return OK_PIXELS (ppi
/ pixels
);
18439 #ifdef HAVE_WINDOW_SYSTEM
18440 if (EQ (prop
, Qheight
))
18441 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18442 if (EQ (prop
, Qwidth
))
18443 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18445 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18446 return OK_PIXELS (1);
18449 if (EQ (prop
, Qtext
))
18450 return OK_PIXELS (width_p
18451 ? window_box_width (it
->w
, TEXT_AREA
)
18452 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18454 if (align_to
&& *align_to
< 0)
18457 if (EQ (prop
, Qleft
))
18458 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18459 if (EQ (prop
, Qright
))
18460 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18461 if (EQ (prop
, Qcenter
))
18462 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18463 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18464 if (EQ (prop
, Qleft_fringe
))
18465 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18466 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18467 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18468 if (EQ (prop
, Qright_fringe
))
18469 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18470 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18471 : window_box_right_offset (it
->w
, TEXT_AREA
));
18472 if (EQ (prop
, Qleft_margin
))
18473 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18474 if (EQ (prop
, Qright_margin
))
18475 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18476 if (EQ (prop
, Qscroll_bar
))
18477 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18479 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18480 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18481 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18486 if (EQ (prop
, Qleft_fringe
))
18487 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18488 if (EQ (prop
, Qright_fringe
))
18489 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18490 if (EQ (prop
, Qleft_margin
))
18491 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18492 if (EQ (prop
, Qright_margin
))
18493 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18494 if (EQ (prop
, Qscroll_bar
))
18495 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18498 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18501 if (INTEGERP (prop
) || FLOATP (prop
))
18503 int base_unit
= (width_p
18504 ? FRAME_COLUMN_WIDTH (it
->f
)
18505 : FRAME_LINE_HEIGHT (it
->f
));
18506 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18511 Lisp_Object car
= XCAR (prop
);
18512 Lisp_Object cdr
= XCDR (prop
);
18516 #ifdef HAVE_WINDOW_SYSTEM
18517 if (valid_image_p (prop
))
18519 int id
= lookup_image (it
->f
, prop
);
18520 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18522 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18525 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18531 while (CONSP (cdr
))
18533 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18534 font
, width_p
, align_to
))
18537 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18542 if (EQ (car
, Qminus
))
18544 return OK_PIXELS (pixels
);
18547 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18550 if (INTEGERP (car
) || FLOATP (car
))
18553 pixels
= XFLOATINT (car
);
18555 return OK_PIXELS (pixels
);
18556 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18557 font
, width_p
, align_to
))
18558 return OK_PIXELS (pixels
* fact
);
18569 /***********************************************************************
18571 ***********************************************************************/
18573 #ifdef HAVE_WINDOW_SYSTEM
18578 dump_glyph_string (s
)
18579 struct glyph_string
*s
;
18581 fprintf (stderr
, "glyph string\n");
18582 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18583 s
->x
, s
->y
, s
->width
, s
->height
);
18584 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18585 fprintf (stderr
, " hl = %d\n", s
->hl
);
18586 fprintf (stderr
, " left overhang = %d, right = %d\n",
18587 s
->left_overhang
, s
->right_overhang
);
18588 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18589 fprintf (stderr
, " extends to end of line = %d\n",
18590 s
->extends_to_end_of_line_p
);
18591 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18592 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18595 #endif /* GLYPH_DEBUG */
18597 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18598 of XChar2b structures for S; it can't be allocated in
18599 init_glyph_string because it must be allocated via `alloca'. W
18600 is the window on which S is drawn. ROW and AREA are the glyph row
18601 and area within the row from which S is constructed. START is the
18602 index of the first glyph structure covered by S. HL is a
18603 face-override for drawing S. */
18606 #define OPTIONAL_HDC(hdc) hdc,
18607 #define DECLARE_HDC(hdc) HDC hdc;
18608 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18609 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18612 #ifndef OPTIONAL_HDC
18613 #define OPTIONAL_HDC(hdc)
18614 #define DECLARE_HDC(hdc)
18615 #define ALLOCATE_HDC(hdc, f)
18616 #define RELEASE_HDC(hdc, f)
18620 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18621 struct glyph_string
*s
;
18625 struct glyph_row
*row
;
18626 enum glyph_row_area area
;
18628 enum draw_glyphs_face hl
;
18630 bzero (s
, sizeof *s
);
18632 s
->f
= XFRAME (w
->frame
);
18636 s
->display
= FRAME_X_DISPLAY (s
->f
);
18637 s
->window
= FRAME_X_WINDOW (s
->f
);
18638 s
->char2b
= char2b
;
18642 s
->first_glyph
= row
->glyphs
[area
] + start
;
18643 s
->height
= row
->height
;
18644 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18646 /* Display the internal border below the tool-bar window. */
18647 if (WINDOWP (s
->f
->tool_bar_window
)
18648 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18649 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18651 s
->ybase
= s
->y
+ row
->ascent
;
18655 /* Append the list of glyph strings with head H and tail T to the list
18656 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18659 append_glyph_string_lists (head
, tail
, h
, t
)
18660 struct glyph_string
**head
, **tail
;
18661 struct glyph_string
*h
, *t
;
18675 /* Prepend the list of glyph strings with head H and tail T to the
18676 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18680 prepend_glyph_string_lists (head
, tail
, h
, t
)
18681 struct glyph_string
**head
, **tail
;
18682 struct glyph_string
*h
, *t
;
18696 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18697 Set *HEAD and *TAIL to the resulting list. */
18700 append_glyph_string (head
, tail
, s
)
18701 struct glyph_string
**head
, **tail
;
18702 struct glyph_string
*s
;
18704 s
->next
= s
->prev
= NULL
;
18705 append_glyph_string_lists (head
, tail
, s
, s
);
18709 /* Get face and two-byte form of character glyph GLYPH on frame F.
18710 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18711 a pointer to a realized face that is ready for display. */
18713 static INLINE
struct face
*
18714 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18716 struct glyph
*glyph
;
18722 xassert (glyph
->type
== CHAR_GLYPH
);
18723 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18728 if (!glyph
->multibyte_p
)
18730 /* Unibyte case. We don't have to encode, but we have to make
18731 sure to use a face suitable for unibyte. */
18732 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18734 else if (glyph
->u
.ch
< 128)
18736 /* Case of ASCII in a face known to fit ASCII. */
18737 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18741 int c1
, c2
, charset
;
18743 /* Split characters into bytes. If c2 is -1 afterwards, C is
18744 really a one-byte character so that byte1 is zero. */
18745 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18747 STORE_XCHAR2B (char2b
, c1
, c2
);
18749 STORE_XCHAR2B (char2b
, 0, c1
);
18751 /* Maybe encode the character in *CHAR2B. */
18752 if (charset
!= CHARSET_ASCII
)
18754 struct font_info
*font_info
18755 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18758 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18762 /* Make sure X resources of the face are allocated. */
18763 xassert (face
!= NULL
);
18764 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18769 /* Fill glyph string S with composition components specified by S->cmp.
18771 FACES is an array of faces for all components of this composition.
18772 S->gidx is the index of the first component for S.
18774 OVERLAPS non-zero means S should draw the foreground only, and use
18775 its physical height for clipping. See also draw_glyphs.
18777 Value is the index of a component not in S. */
18780 fill_composite_glyph_string (s
, faces
, overlaps
)
18781 struct glyph_string
*s
;
18782 struct face
**faces
;
18789 s
->for_overlaps
= overlaps
;
18791 s
->face
= faces
[s
->gidx
];
18792 s
->font
= s
->face
->font
;
18793 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18795 /* For all glyphs of this composition, starting at the offset
18796 S->gidx, until we reach the end of the definition or encounter a
18797 glyph that requires the different face, add it to S. */
18799 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18802 /* All glyph strings for the same composition has the same width,
18803 i.e. the width set for the first component of the composition. */
18805 s
->width
= s
->first_glyph
->pixel_width
;
18807 /* If the specified font could not be loaded, use the frame's
18808 default font, but record the fact that we couldn't load it in
18809 the glyph string so that we can draw rectangles for the
18810 characters of the glyph string. */
18811 if (s
->font
== NULL
)
18813 s
->font_not_found_p
= 1;
18814 s
->font
= FRAME_FONT (s
->f
);
18817 /* Adjust base line for subscript/superscript text. */
18818 s
->ybase
+= s
->first_glyph
->voffset
;
18820 xassert (s
->face
&& s
->face
->gc
);
18822 /* This glyph string must always be drawn with 16-bit functions. */
18825 return s
->gidx
+ s
->nchars
;
18829 /* Fill glyph string S from a sequence of character glyphs.
18831 FACE_ID is the face id of the string. START is the index of the
18832 first glyph to consider, END is the index of the last + 1.
18833 OVERLAPS non-zero means S should draw the foreground only, and use
18834 its physical height for clipping. See also draw_glyphs.
18836 Value is the index of the first glyph not in S. */
18839 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18840 struct glyph_string
*s
;
18842 int start
, end
, overlaps
;
18844 struct glyph
*glyph
, *last
;
18846 int glyph_not_available_p
;
18848 xassert (s
->f
== XFRAME (s
->w
->frame
));
18849 xassert (s
->nchars
== 0);
18850 xassert (start
>= 0 && end
> start
);
18852 s
->for_overlaps
= overlaps
,
18853 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18854 last
= s
->row
->glyphs
[s
->area
] + end
;
18855 voffset
= glyph
->voffset
;
18857 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18859 while (glyph
< last
18860 && glyph
->type
== CHAR_GLYPH
18861 && glyph
->voffset
== voffset
18862 /* Same face id implies same font, nowadays. */
18863 && glyph
->face_id
== face_id
18864 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18868 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18869 s
->char2b
+ s
->nchars
,
18871 s
->two_byte_p
= two_byte_p
;
18873 xassert (s
->nchars
<= end
- start
);
18874 s
->width
+= glyph
->pixel_width
;
18878 s
->font
= s
->face
->font
;
18879 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18881 /* If the specified font could not be loaded, use the frame's font,
18882 but record the fact that we couldn't load it in
18883 S->font_not_found_p so that we can draw rectangles for the
18884 characters of the glyph string. */
18885 if (s
->font
== NULL
|| glyph_not_available_p
)
18887 s
->font_not_found_p
= 1;
18888 s
->font
= FRAME_FONT (s
->f
);
18891 /* Adjust base line for subscript/superscript text. */
18892 s
->ybase
+= voffset
;
18894 xassert (s
->face
&& s
->face
->gc
);
18895 return glyph
- s
->row
->glyphs
[s
->area
];
18899 /* Fill glyph string S from image glyph S->first_glyph. */
18902 fill_image_glyph_string (s
)
18903 struct glyph_string
*s
;
18905 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18906 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18908 s
->slice
= s
->first_glyph
->slice
;
18909 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18910 s
->font
= s
->face
->font
;
18911 s
->width
= s
->first_glyph
->pixel_width
;
18913 /* Adjust base line for subscript/superscript text. */
18914 s
->ybase
+= s
->first_glyph
->voffset
;
18918 /* Fill glyph string S from a sequence of stretch glyphs.
18920 ROW is the glyph row in which the glyphs are found, AREA is the
18921 area within the row. START is the index of the first glyph to
18922 consider, END is the index of the last + 1.
18924 Value is the index of the first glyph not in S. */
18927 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18928 struct glyph_string
*s
;
18929 struct glyph_row
*row
;
18930 enum glyph_row_area area
;
18933 struct glyph
*glyph
, *last
;
18934 int voffset
, face_id
;
18936 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18938 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18939 last
= s
->row
->glyphs
[s
->area
] + end
;
18940 face_id
= glyph
->face_id
;
18941 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18942 s
->font
= s
->face
->font
;
18943 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18944 s
->width
= glyph
->pixel_width
;
18946 voffset
= glyph
->voffset
;
18950 && glyph
->type
== STRETCH_GLYPH
18951 && glyph
->voffset
== voffset
18952 && glyph
->face_id
== face_id
);
18954 s
->width
+= glyph
->pixel_width
;
18956 /* Adjust base line for subscript/superscript text. */
18957 s
->ybase
+= voffset
;
18959 /* The case that face->gc == 0 is handled when drawing the glyph
18960 string by calling PREPARE_FACE_FOR_DISPLAY. */
18962 return glyph
- s
->row
->glyphs
[s
->area
];
18967 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18968 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18969 assumed to be zero. */
18972 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18973 struct glyph
*glyph
;
18977 *left
= *right
= 0;
18979 if (glyph
->type
== CHAR_GLYPH
)
18983 struct font_info
*font_info
;
18987 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18989 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18990 if (font
/* ++KFS: Should this be font_info ? */
18991 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18993 if (pcm
->rbearing
> pcm
->width
)
18994 *right
= pcm
->rbearing
- pcm
->width
;
18995 if (pcm
->lbearing
< 0)
18996 *left
= -pcm
->lbearing
;
19002 /* Return the index of the first glyph preceding glyph string S that
19003 is overwritten by S because of S's left overhang. Value is -1
19004 if no glyphs are overwritten. */
19007 left_overwritten (s
)
19008 struct glyph_string
*s
;
19012 if (s
->left_overhang
)
19015 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19016 int first
= s
->first_glyph
- glyphs
;
19018 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19019 x
-= glyphs
[i
].pixel_width
;
19030 /* Return the index of the first glyph preceding glyph string S that
19031 is overwriting S because of its right overhang. Value is -1 if no
19032 glyph in front of S overwrites S. */
19035 left_overwriting (s
)
19036 struct glyph_string
*s
;
19039 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19040 int first
= s
->first_glyph
- glyphs
;
19044 for (i
= first
- 1; i
>= 0; --i
)
19047 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19050 x
-= glyphs
[i
].pixel_width
;
19057 /* Return the index of the last glyph following glyph string S that is
19058 not overwritten by S because of S's right overhang. Value is -1 if
19059 no such glyph is found. */
19062 right_overwritten (s
)
19063 struct glyph_string
*s
;
19067 if (s
->right_overhang
)
19070 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19071 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19072 int end
= s
->row
->used
[s
->area
];
19074 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19075 x
+= glyphs
[i
].pixel_width
;
19084 /* Return the index of the last glyph following glyph string S that
19085 overwrites S because of its left overhang. Value is negative
19086 if no such glyph is found. */
19089 right_overwriting (s
)
19090 struct glyph_string
*s
;
19093 int end
= s
->row
->used
[s
->area
];
19094 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19095 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19099 for (i
= first
; i
< end
; ++i
)
19102 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19105 x
+= glyphs
[i
].pixel_width
;
19112 /* Get face and two-byte form of character C in face FACE_ID on frame
19113 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19114 means we want to display multibyte text. DISPLAY_P non-zero means
19115 make sure that X resources for the face returned are allocated.
19116 Value is a pointer to a realized face that is ready for display if
19117 DISPLAY_P is non-zero. */
19119 static INLINE
struct face
*
19120 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19124 int multibyte_p
, display_p
;
19126 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19130 /* Unibyte case. We don't have to encode, but we have to make
19131 sure to use a face suitable for unibyte. */
19132 STORE_XCHAR2B (char2b
, 0, c
);
19133 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19134 face
= FACE_FROM_ID (f
, face_id
);
19138 /* Case of ASCII in a face known to fit ASCII. */
19139 STORE_XCHAR2B (char2b
, 0, c
);
19143 int c1
, c2
, charset
;
19145 /* Split characters into bytes. If c2 is -1 afterwards, C is
19146 really a one-byte character so that byte1 is zero. */
19147 SPLIT_CHAR (c
, charset
, c1
, c2
);
19149 STORE_XCHAR2B (char2b
, c1
, c2
);
19151 STORE_XCHAR2B (char2b
, 0, c1
);
19153 /* Maybe encode the character in *CHAR2B. */
19154 if (face
->font
!= NULL
)
19156 struct font_info
*font_info
19157 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19159 rif
->encode_char (c
, char2b
, font_info
, 0);
19163 /* Make sure X resources of the face are allocated. */
19164 #ifdef HAVE_X_WINDOWS
19168 xassert (face
!= NULL
);
19169 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19176 /* Set background width of glyph string S. START is the index of the
19177 first glyph following S. LAST_X is the right-most x-position + 1
19178 in the drawing area. */
19181 set_glyph_string_background_width (s
, start
, last_x
)
19182 struct glyph_string
*s
;
19186 /* If the face of this glyph string has to be drawn to the end of
19187 the drawing area, set S->extends_to_end_of_line_p. */
19189 if (start
== s
->row
->used
[s
->area
]
19190 && s
->area
== TEXT_AREA
19191 && ((s
->row
->fill_line_p
19192 && (s
->hl
== DRAW_NORMAL_TEXT
19193 || s
->hl
== DRAW_IMAGE_RAISED
19194 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19195 || s
->hl
== DRAW_MOUSE_FACE
))
19196 s
->extends_to_end_of_line_p
= 1;
19198 /* If S extends its face to the end of the line, set its
19199 background_width to the distance to the right edge of the drawing
19201 if (s
->extends_to_end_of_line_p
)
19202 s
->background_width
= last_x
- s
->x
+ 1;
19204 s
->background_width
= s
->width
;
19208 /* Compute overhangs and x-positions for glyph string S and its
19209 predecessors, or successors. X is the starting x-position for S.
19210 BACKWARD_P non-zero means process predecessors. */
19213 compute_overhangs_and_x (s
, x
, backward_p
)
19214 struct glyph_string
*s
;
19222 if (rif
->compute_glyph_string_overhangs
)
19223 rif
->compute_glyph_string_overhangs (s
);
19233 if (rif
->compute_glyph_string_overhangs
)
19234 rif
->compute_glyph_string_overhangs (s
);
19244 /* The following macros are only called from draw_glyphs below.
19245 They reference the following parameters of that function directly:
19246 `w', `row', `area', and `overlap_p'
19247 as well as the following local variables:
19248 `s', `f', and `hdc' (in W32) */
19251 /* On W32, silently add local `hdc' variable to argument list of
19252 init_glyph_string. */
19253 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19254 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19256 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19257 init_glyph_string (s, char2b, w, row, area, start, hl)
19260 /* Add a glyph string for a stretch glyph to the list of strings
19261 between HEAD and TAIL. START is the index of the stretch glyph in
19262 row area AREA of glyph row ROW. END is the index of the last glyph
19263 in that glyph row area. X is the current output position assigned
19264 to the new glyph string constructed. HL overrides that face of the
19265 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19266 is the right-most x-position of the drawing area. */
19268 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19269 and below -- keep them on one line. */
19270 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19273 s = (struct glyph_string *) alloca (sizeof *s); \
19274 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19275 START = fill_stretch_glyph_string (s, row, area, START, END); \
19276 append_glyph_string (&HEAD, &TAIL, s); \
19282 /* Add a glyph string for an image glyph to the list of strings
19283 between HEAD and TAIL. START is the index of the image glyph in
19284 row area AREA of glyph row ROW. END is the index of the last glyph
19285 in that glyph row area. X is the current output position assigned
19286 to the new glyph string constructed. HL overrides that face of the
19287 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19288 is the right-most x-position of the drawing area. */
19290 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19293 s = (struct glyph_string *) alloca (sizeof *s); \
19294 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19295 fill_image_glyph_string (s); \
19296 append_glyph_string (&HEAD, &TAIL, s); \
19303 /* Add a glyph string for a sequence of character glyphs to the list
19304 of strings between HEAD and TAIL. START is the index of the first
19305 glyph in row area AREA of glyph row ROW that is part of the new
19306 glyph string. END is the index of the last glyph in that glyph row
19307 area. X is the current output position assigned to the new glyph
19308 string constructed. HL overrides that face of the glyph; e.g. it
19309 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19310 right-most x-position of the drawing area. */
19312 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19318 c = (row)->glyphs[area][START].u.ch; \
19319 face_id = (row)->glyphs[area][START].face_id; \
19321 s = (struct glyph_string *) alloca (sizeof *s); \
19322 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19323 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19324 append_glyph_string (&HEAD, &TAIL, s); \
19326 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19331 /* Add a glyph string for a composite sequence to the list of strings
19332 between HEAD and TAIL. START is the index of the first glyph in
19333 row area AREA of glyph row ROW that is part of the new glyph
19334 string. END is the index of the last glyph in that glyph row area.
19335 X is the current output position assigned to the new glyph string
19336 constructed. HL overrides that face of the glyph; e.g. it is
19337 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19338 x-position of the drawing area. */
19340 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19342 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19343 int face_id = (row)->glyphs[area][START].face_id; \
19344 struct face *base_face = FACE_FROM_ID (f, face_id); \
19345 struct composition *cmp = composition_table[cmp_id]; \
19346 int glyph_len = cmp->glyph_len; \
19348 struct face **faces; \
19349 struct glyph_string *first_s = NULL; \
19352 base_face = base_face->ascii_face; \
19353 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19354 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19355 /* At first, fill in `char2b' and `faces'. */ \
19356 for (n = 0; n < glyph_len; n++) \
19358 int c = COMPOSITION_GLYPH (cmp, n); \
19359 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19360 faces[n] = FACE_FROM_ID (f, this_face_id); \
19361 get_char_face_and_encoding (f, c, this_face_id, \
19362 char2b + n, 1, 1); \
19365 /* Make glyph_strings for each glyph sequence that is drawable by \
19366 the same face, and append them to HEAD/TAIL. */ \
19367 for (n = 0; n < cmp->glyph_len;) \
19369 s = (struct glyph_string *) alloca (sizeof *s); \
19370 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19371 append_glyph_string (&(HEAD), &(TAIL), s); \
19379 n = fill_composite_glyph_string (s, faces, overlaps); \
19387 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19388 of AREA of glyph row ROW on window W between indices START and END.
19389 HL overrides the face for drawing glyph strings, e.g. it is
19390 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19391 x-positions of the drawing area.
19393 This is an ugly monster macro construct because we must use alloca
19394 to allocate glyph strings (because draw_glyphs can be called
19395 asynchronously). */
19397 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19400 HEAD = TAIL = NULL; \
19401 while (START < END) \
19403 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19404 switch (first_glyph->type) \
19407 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19411 case COMPOSITE_GLYPH: \
19412 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19416 case STRETCH_GLYPH: \
19417 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19421 case IMAGE_GLYPH: \
19422 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19430 set_glyph_string_background_width (s, START, LAST_X); \
19437 /* Draw glyphs between START and END in AREA of ROW on window W,
19438 starting at x-position X. X is relative to AREA in W. HL is a
19439 face-override with the following meaning:
19441 DRAW_NORMAL_TEXT draw normally
19442 DRAW_CURSOR draw in cursor face
19443 DRAW_MOUSE_FACE draw in mouse face.
19444 DRAW_INVERSE_VIDEO draw in mode line face
19445 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19446 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19448 If OVERLAPS is non-zero, draw only the foreground of characters and
19449 clip to the physical height of ROW. Non-zero value also defines
19450 the overlapping part to be drawn:
19452 OVERLAPS_PRED overlap with preceding rows
19453 OVERLAPS_SUCC overlap with succeeding rows
19454 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19455 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19457 Value is the x-position reached, relative to AREA of W. */
19460 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19463 struct glyph_row
*row
;
19464 enum glyph_row_area area
;
19466 enum draw_glyphs_face hl
;
19469 struct glyph_string
*head
, *tail
;
19470 struct glyph_string
*s
;
19471 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19472 int last_x
, area_width
;
19475 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19478 ALLOCATE_HDC (hdc
, f
);
19480 /* Let's rather be paranoid than getting a SEGV. */
19481 end
= min (end
, row
->used
[area
]);
19482 start
= max (0, start
);
19483 start
= min (end
, start
);
19485 /* Translate X to frame coordinates. Set last_x to the right
19486 end of the drawing area. */
19487 if (row
->full_width_p
)
19489 /* X is relative to the left edge of W, without scroll bars
19491 x
+= WINDOW_LEFT_EDGE_X (w
);
19492 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19496 int area_left
= window_box_left (w
, area
);
19498 area_width
= window_box_width (w
, area
);
19499 last_x
= area_left
+ area_width
;
19502 /* Build a doubly-linked list of glyph_string structures between
19503 head and tail from what we have to draw. Note that the macro
19504 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19505 the reason we use a separate variable `i'. */
19507 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19509 x_reached
= tail
->x
+ tail
->background_width
;
19513 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19514 the row, redraw some glyphs in front or following the glyph
19515 strings built above. */
19516 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19519 struct glyph_string
*h
, *t
;
19521 /* Compute overhangs for all glyph strings. */
19522 if (rif
->compute_glyph_string_overhangs
)
19523 for (s
= head
; s
; s
= s
->next
)
19524 rif
->compute_glyph_string_overhangs (s
);
19526 /* Prepend glyph strings for glyphs in front of the first glyph
19527 string that are overwritten because of the first glyph
19528 string's left overhang. The background of all strings
19529 prepended must be drawn because the first glyph string
19531 i
= left_overwritten (head
);
19535 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19536 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19538 compute_overhangs_and_x (t
, head
->x
, 1);
19539 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19543 /* Prepend glyph strings for glyphs in front of the first glyph
19544 string that overwrite that glyph string because of their
19545 right overhang. For these strings, only the foreground must
19546 be drawn, because it draws over the glyph string at `head'.
19547 The background must not be drawn because this would overwrite
19548 right overhangs of preceding glyphs for which no glyph
19550 i
= left_overwriting (head
);
19554 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19555 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19556 for (s
= h
; s
; s
= s
->next
)
19557 s
->background_filled_p
= 1;
19558 compute_overhangs_and_x (t
, head
->x
, 1);
19559 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19562 /* Append glyphs strings for glyphs following the last glyph
19563 string tail that are overwritten by tail. The background of
19564 these strings has to be drawn because tail's foreground draws
19566 i
= right_overwritten (tail
);
19569 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19570 DRAW_NORMAL_TEXT
, x
, last_x
);
19571 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19572 append_glyph_string_lists (&head
, &tail
, h
, t
);
19576 /* Append glyph strings for glyphs following the last glyph
19577 string tail that overwrite tail. The foreground of such
19578 glyphs has to be drawn because it writes into the background
19579 of tail. The background must not be drawn because it could
19580 paint over the foreground of following glyphs. */
19581 i
= right_overwriting (tail
);
19585 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19586 DRAW_NORMAL_TEXT
, x
, last_x
);
19587 for (s
= h
; s
; s
= s
->next
)
19588 s
->background_filled_p
= 1;
19589 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19590 append_glyph_string_lists (&head
, &tail
, h
, t
);
19592 if (clip_head
|| clip_tail
)
19593 for (s
= head
; s
; s
= s
->next
)
19595 s
->clip_head
= clip_head
;
19596 s
->clip_tail
= clip_tail
;
19600 /* Draw all strings. */
19601 for (s
= head
; s
; s
= s
->next
)
19602 rif
->draw_glyph_string (s
);
19604 if (area
== TEXT_AREA
19605 && !row
->full_width_p
19606 /* When drawing overlapping rows, only the glyph strings'
19607 foreground is drawn, which doesn't erase a cursor
19611 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19612 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19613 : (tail
? tail
->x
+ tail
->background_width
: x
));
19615 int text_left
= window_box_left (w
, TEXT_AREA
);
19619 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19620 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19623 /* Value is the x-position up to which drawn, relative to AREA of W.
19624 This doesn't include parts drawn because of overhangs. */
19625 if (row
->full_width_p
)
19626 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19628 x_reached
-= window_box_left (w
, area
);
19630 RELEASE_HDC (hdc
, f
);
19635 /* Expand row matrix if too narrow. Don't expand if area
19638 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19640 if (!fonts_changed_p \
19641 && (it->glyph_row->glyphs[area] \
19642 < it->glyph_row->glyphs[area + 1])) \
19644 it->w->ncols_scale_factor++; \
19645 fonts_changed_p = 1; \
19649 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19650 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19656 struct glyph
*glyph
;
19657 enum glyph_row_area area
= it
->area
;
19659 xassert (it
->glyph_row
);
19660 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19662 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19663 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19665 glyph
->charpos
= CHARPOS (it
->position
);
19666 glyph
->object
= it
->object
;
19667 glyph
->pixel_width
= it
->pixel_width
;
19668 glyph
->ascent
= it
->ascent
;
19669 glyph
->descent
= it
->descent
;
19670 glyph
->voffset
= it
->voffset
;
19671 glyph
->type
= CHAR_GLYPH
;
19672 glyph
->multibyte_p
= it
->multibyte_p
;
19673 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19674 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19675 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19676 || it
->phys_descent
> it
->descent
);
19677 glyph
->padding_p
= 0;
19678 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19679 glyph
->face_id
= it
->face_id
;
19680 glyph
->u
.ch
= it
->char_to_display
;
19681 glyph
->slice
= null_glyph_slice
;
19682 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19683 ++it
->glyph_row
->used
[area
];
19686 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19689 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19690 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19693 append_composite_glyph (it
)
19696 struct glyph
*glyph
;
19697 enum glyph_row_area area
= it
->area
;
19699 xassert (it
->glyph_row
);
19701 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19702 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19704 glyph
->charpos
= CHARPOS (it
->position
);
19705 glyph
->object
= it
->object
;
19706 glyph
->pixel_width
= it
->pixel_width
;
19707 glyph
->ascent
= it
->ascent
;
19708 glyph
->descent
= it
->descent
;
19709 glyph
->voffset
= it
->voffset
;
19710 glyph
->type
= COMPOSITE_GLYPH
;
19711 glyph
->multibyte_p
= it
->multibyte_p
;
19712 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19713 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19714 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19715 || it
->phys_descent
> it
->descent
);
19716 glyph
->padding_p
= 0;
19717 glyph
->glyph_not_available_p
= 0;
19718 glyph
->face_id
= it
->face_id
;
19719 glyph
->u
.cmp_id
= it
->cmp_id
;
19720 glyph
->slice
= null_glyph_slice
;
19721 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19722 ++it
->glyph_row
->used
[area
];
19725 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19729 /* Change IT->ascent and IT->height according to the setting of
19733 take_vertical_position_into_account (it
)
19738 if (it
->voffset
< 0)
19739 /* Increase the ascent so that we can display the text higher
19741 it
->ascent
-= it
->voffset
;
19743 /* Increase the descent so that we can display the text lower
19745 it
->descent
+= it
->voffset
;
19750 /* Produce glyphs/get display metrics for the image IT is loaded with.
19751 See the description of struct display_iterator in dispextern.h for
19752 an overview of struct display_iterator. */
19755 produce_image_glyph (it
)
19761 struct glyph_slice slice
;
19763 xassert (it
->what
== IT_IMAGE
);
19765 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19767 /* Make sure X resources of the face is loaded. */
19768 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19770 if (it
->image_id
< 0)
19772 /* Fringe bitmap. */
19773 it
->ascent
= it
->phys_ascent
= 0;
19774 it
->descent
= it
->phys_descent
= 0;
19775 it
->pixel_width
= 0;
19780 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19782 /* Make sure X resources of the image is loaded. */
19783 prepare_image_for_display (it
->f
, img
);
19785 slice
.x
= slice
.y
= 0;
19786 slice
.width
= img
->width
;
19787 slice
.height
= img
->height
;
19789 if (INTEGERP (it
->slice
.x
))
19790 slice
.x
= XINT (it
->slice
.x
);
19791 else if (FLOATP (it
->slice
.x
))
19792 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19794 if (INTEGERP (it
->slice
.y
))
19795 slice
.y
= XINT (it
->slice
.y
);
19796 else if (FLOATP (it
->slice
.y
))
19797 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19799 if (INTEGERP (it
->slice
.width
))
19800 slice
.width
= XINT (it
->slice
.width
);
19801 else if (FLOATP (it
->slice
.width
))
19802 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19804 if (INTEGERP (it
->slice
.height
))
19805 slice
.height
= XINT (it
->slice
.height
);
19806 else if (FLOATP (it
->slice
.height
))
19807 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19809 if (slice
.x
>= img
->width
)
19810 slice
.x
= img
->width
;
19811 if (slice
.y
>= img
->height
)
19812 slice
.y
= img
->height
;
19813 if (slice
.x
+ slice
.width
>= img
->width
)
19814 slice
.width
= img
->width
- slice
.x
;
19815 if (slice
.y
+ slice
.height
> img
->height
)
19816 slice
.height
= img
->height
- slice
.y
;
19818 if (slice
.width
== 0 || slice
.height
== 0)
19821 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19823 it
->descent
= slice
.height
- glyph_ascent
;
19825 it
->descent
+= img
->vmargin
;
19826 if (slice
.y
+ slice
.height
== img
->height
)
19827 it
->descent
+= img
->vmargin
;
19828 it
->phys_descent
= it
->descent
;
19830 it
->pixel_width
= slice
.width
;
19832 it
->pixel_width
+= img
->hmargin
;
19833 if (slice
.x
+ slice
.width
== img
->width
)
19834 it
->pixel_width
+= img
->hmargin
;
19836 /* It's quite possible for images to have an ascent greater than
19837 their height, so don't get confused in that case. */
19838 if (it
->descent
< 0)
19841 #if 0 /* this breaks image tiling */
19842 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19843 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19844 if (face_ascent
> it
->ascent
)
19845 it
->ascent
= it
->phys_ascent
= face_ascent
;
19850 if (face
->box
!= FACE_NO_BOX
)
19852 if (face
->box_line_width
> 0)
19855 it
->ascent
+= face
->box_line_width
;
19856 if (slice
.y
+ slice
.height
== img
->height
)
19857 it
->descent
+= face
->box_line_width
;
19860 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19861 it
->pixel_width
+= abs (face
->box_line_width
);
19862 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19863 it
->pixel_width
+= abs (face
->box_line_width
);
19866 take_vertical_position_into_account (it
);
19870 struct glyph
*glyph
;
19871 enum glyph_row_area area
= it
->area
;
19873 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19874 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19876 glyph
->charpos
= CHARPOS (it
->position
);
19877 glyph
->object
= it
->object
;
19878 glyph
->pixel_width
= it
->pixel_width
;
19879 glyph
->ascent
= glyph_ascent
;
19880 glyph
->descent
= it
->descent
;
19881 glyph
->voffset
= it
->voffset
;
19882 glyph
->type
= IMAGE_GLYPH
;
19883 glyph
->multibyte_p
= it
->multibyte_p
;
19884 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19885 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19886 glyph
->overlaps_vertically_p
= 0;
19887 glyph
->padding_p
= 0;
19888 glyph
->glyph_not_available_p
= 0;
19889 glyph
->face_id
= it
->face_id
;
19890 glyph
->u
.img_id
= img
->id
;
19891 glyph
->slice
= slice
;
19892 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19893 ++it
->glyph_row
->used
[area
];
19896 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19901 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19902 of the glyph, WIDTH and HEIGHT are the width and height of the
19903 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19906 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19908 Lisp_Object object
;
19912 struct glyph
*glyph
;
19913 enum glyph_row_area area
= it
->area
;
19915 xassert (ascent
>= 0 && ascent
<= height
);
19917 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19918 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19920 glyph
->charpos
= CHARPOS (it
->position
);
19921 glyph
->object
= object
;
19922 glyph
->pixel_width
= width
;
19923 glyph
->ascent
= ascent
;
19924 glyph
->descent
= height
- ascent
;
19925 glyph
->voffset
= it
->voffset
;
19926 glyph
->type
= STRETCH_GLYPH
;
19927 glyph
->multibyte_p
= it
->multibyte_p
;
19928 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19929 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19930 glyph
->overlaps_vertically_p
= 0;
19931 glyph
->padding_p
= 0;
19932 glyph
->glyph_not_available_p
= 0;
19933 glyph
->face_id
= it
->face_id
;
19934 glyph
->u
.stretch
.ascent
= ascent
;
19935 glyph
->u
.stretch
.height
= height
;
19936 glyph
->slice
= null_glyph_slice
;
19937 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19938 ++it
->glyph_row
->used
[area
];
19941 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19945 /* Produce a stretch glyph for iterator IT. IT->object is the value
19946 of the glyph property displayed. The value must be a list
19947 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19950 1. `:width WIDTH' specifies that the space should be WIDTH *
19951 canonical char width wide. WIDTH may be an integer or floating
19954 2. `:relative-width FACTOR' specifies that the width of the stretch
19955 should be computed from the width of the first character having the
19956 `glyph' property, and should be FACTOR times that width.
19958 3. `:align-to HPOS' specifies that the space should be wide enough
19959 to reach HPOS, a value in canonical character units.
19961 Exactly one of the above pairs must be present.
19963 4. `:height HEIGHT' specifies that the height of the stretch produced
19964 should be HEIGHT, measured in canonical character units.
19966 5. `:relative-height FACTOR' specifies that the height of the
19967 stretch should be FACTOR times the height of the characters having
19968 the glyph property.
19970 Either none or exactly one of 4 or 5 must be present.
19972 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19973 of the stretch should be used for the ascent of the stretch.
19974 ASCENT must be in the range 0 <= ASCENT <= 100. */
19977 produce_stretch_glyph (it
)
19980 /* (space :width WIDTH :height HEIGHT ...) */
19981 Lisp_Object prop
, plist
;
19982 int width
= 0, height
= 0, align_to
= -1;
19983 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19986 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19987 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19989 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19991 /* List should start with `space'. */
19992 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19993 plist
= XCDR (it
->object
);
19995 /* Compute the width of the stretch. */
19996 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19997 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19999 /* Absolute width `:width WIDTH' specified and valid. */
20000 zero_width_ok_p
= 1;
20003 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20006 /* Relative width `:relative-width FACTOR' specified and valid.
20007 Compute the width of the characters having the `glyph'
20010 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20013 if (it
->multibyte_p
)
20015 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20016 - IT_BYTEPOS (*it
));
20017 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20020 it2
.c
= *p
, it2
.len
= 1;
20022 it2
.glyph_row
= NULL
;
20023 it2
.what
= IT_CHARACTER
;
20024 x_produce_glyphs (&it2
);
20025 width
= NUMVAL (prop
) * it2
.pixel_width
;
20027 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20028 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20030 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20031 align_to
= (align_to
< 0
20033 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20034 else if (align_to
< 0)
20035 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20036 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20037 zero_width_ok_p
= 1;
20040 /* Nothing specified -> width defaults to canonical char width. */
20041 width
= FRAME_COLUMN_WIDTH (it
->f
);
20043 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20046 /* Compute height. */
20047 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20048 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20051 zero_height_ok_p
= 1;
20053 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20055 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20057 height
= FONT_HEIGHT (font
);
20059 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20062 /* Compute percentage of height used for ascent. If
20063 `:ascent ASCENT' is present and valid, use that. Otherwise,
20064 derive the ascent from the font in use. */
20065 if (prop
= Fplist_get (plist
, QCascent
),
20066 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20067 ascent
= height
* NUMVAL (prop
) / 100.0;
20068 else if (!NILP (prop
)
20069 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20070 ascent
= min (max (0, (int)tem
), height
);
20072 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20074 if (width
> 0 && !it
->truncate_lines_p
20075 && it
->current_x
+ width
> it
->last_visible_x
)
20076 width
= it
->last_visible_x
- it
->current_x
- 1;
20078 if (width
> 0 && height
> 0 && it
->glyph_row
)
20080 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20081 if (!STRINGP (object
))
20082 object
= it
->w
->buffer
;
20083 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20086 it
->pixel_width
= width
;
20087 it
->ascent
= it
->phys_ascent
= ascent
;
20088 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20089 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20091 take_vertical_position_into_account (it
);
20094 /* Get line-height and line-spacing property at point.
20095 If line-height has format (HEIGHT TOTAL), return TOTAL
20096 in TOTAL_HEIGHT. */
20099 get_line_height_property (it
, prop
)
20103 Lisp_Object position
;
20105 if (STRINGP (it
->object
))
20106 position
= make_number (IT_STRING_CHARPOS (*it
));
20107 else if (BUFFERP (it
->object
))
20108 position
= make_number (IT_CHARPOS (*it
));
20112 return Fget_char_property (position
, prop
, it
->object
);
20115 /* Calculate line-height and line-spacing properties.
20116 An integer value specifies explicit pixel value.
20117 A float value specifies relative value to current face height.
20118 A cons (float . face-name) specifies relative value to
20119 height of specified face font.
20121 Returns height in pixels, or nil. */
20125 calc_line_height_property (it
, val
, font
, boff
, override
)
20129 int boff
, override
;
20131 Lisp_Object face_name
= Qnil
;
20132 int ascent
, descent
, height
;
20134 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20139 face_name
= XCAR (val
);
20141 if (!NUMBERP (val
))
20142 val
= make_number (1);
20143 if (NILP (face_name
))
20145 height
= it
->ascent
+ it
->descent
;
20150 if (NILP (face_name
))
20152 font
= FRAME_FONT (it
->f
);
20153 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20155 else if (EQ (face_name
, Qt
))
20163 struct font_info
*font_info
;
20165 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20167 return make_number (-1);
20169 face
= FACE_FROM_ID (it
->f
, face_id
);
20172 return make_number (-1);
20174 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20175 boff
= font_info
->baseline_offset
;
20176 if (font_info
->vertical_centering
)
20177 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20180 ascent
= FONT_BASE (font
) + boff
;
20181 descent
= FONT_DESCENT (font
) - boff
;
20185 it
->override_ascent
= ascent
;
20186 it
->override_descent
= descent
;
20187 it
->override_boff
= boff
;
20190 height
= ascent
+ descent
;
20194 height
= (int)(XFLOAT_DATA (val
) * height
);
20195 else if (INTEGERP (val
))
20196 height
*= XINT (val
);
20198 return make_number (height
);
20203 Produce glyphs/get display metrics for the display element IT is
20204 loaded with. See the description of struct it in dispextern.h
20205 for an overview of struct it. */
20208 x_produce_glyphs (it
)
20211 int extra_line_spacing
= it
->extra_line_spacing
;
20213 it
->glyph_not_available_p
= 0;
20215 if (it
->what
== IT_CHARACTER
)
20219 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20221 int font_not_found_p
;
20222 struct font_info
*font_info
;
20223 int boff
; /* baseline offset */
20224 /* We may change it->multibyte_p upon unibyte<->multibyte
20225 conversion. So, save the current value now and restore it
20228 Note: It seems that we don't have to record multibyte_p in
20229 struct glyph because the character code itself tells if or
20230 not the character is multibyte. Thus, in the future, we must
20231 consider eliminating the field `multibyte_p' in the struct
20233 int saved_multibyte_p
= it
->multibyte_p
;
20235 /* Maybe translate single-byte characters to multibyte, or the
20237 it
->char_to_display
= it
->c
;
20238 if (!ASCII_BYTE_P (it
->c
))
20240 if (unibyte_display_via_language_environment
20241 && SINGLE_BYTE_CHAR_P (it
->c
)
20243 || !NILP (Vnonascii_translation_table
)))
20245 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20246 it
->multibyte_p
= 1;
20247 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20248 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20250 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20251 && !it
->multibyte_p
)
20253 it
->multibyte_p
= 1;
20254 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20255 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20259 /* Get font to use. Encode IT->char_to_display. */
20260 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20261 &char2b
, it
->multibyte_p
, 0);
20264 /* When no suitable font found, use the default font. */
20265 font_not_found_p
= font
== NULL
;
20266 if (font_not_found_p
)
20268 font
= FRAME_FONT (it
->f
);
20269 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20274 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20275 boff
= font_info
->baseline_offset
;
20276 if (font_info
->vertical_centering
)
20277 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20280 if (it
->char_to_display
>= ' '
20281 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20283 /* Either unibyte or ASCII. */
20288 pcm
= rif
->per_char_metric (font
, &char2b
,
20289 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20291 if (it
->override_ascent
>= 0)
20293 it
->ascent
= it
->override_ascent
;
20294 it
->descent
= it
->override_descent
;
20295 boff
= it
->override_boff
;
20299 it
->ascent
= FONT_BASE (font
) + boff
;
20300 it
->descent
= FONT_DESCENT (font
) - boff
;
20305 it
->phys_ascent
= pcm
->ascent
+ boff
;
20306 it
->phys_descent
= pcm
->descent
- boff
;
20307 it
->pixel_width
= pcm
->width
;
20311 it
->glyph_not_available_p
= 1;
20312 it
->phys_ascent
= it
->ascent
;
20313 it
->phys_descent
= it
->descent
;
20314 it
->pixel_width
= FONT_WIDTH (font
);
20317 if (it
->constrain_row_ascent_descent_p
)
20319 if (it
->descent
> it
->max_descent
)
20321 it
->ascent
+= it
->descent
- it
->max_descent
;
20322 it
->descent
= it
->max_descent
;
20324 if (it
->ascent
> it
->max_ascent
)
20326 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20327 it
->ascent
= it
->max_ascent
;
20329 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20330 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20331 extra_line_spacing
= 0;
20334 /* If this is a space inside a region of text with
20335 `space-width' property, change its width. */
20336 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20338 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20340 /* If face has a box, add the box thickness to the character
20341 height. If character has a box line to the left and/or
20342 right, add the box line width to the character's width. */
20343 if (face
->box
!= FACE_NO_BOX
)
20345 int thick
= face
->box_line_width
;
20349 it
->ascent
+= thick
;
20350 it
->descent
+= thick
;
20355 if (it
->start_of_box_run_p
)
20356 it
->pixel_width
+= thick
;
20357 if (it
->end_of_box_run_p
)
20358 it
->pixel_width
+= thick
;
20361 /* If face has an overline, add the height of the overline
20362 (1 pixel) and a 1 pixel margin to the character height. */
20363 if (face
->overline_p
)
20364 it
->ascent
+= overline_margin
;
20366 if (it
->constrain_row_ascent_descent_p
)
20368 if (it
->ascent
> it
->max_ascent
)
20369 it
->ascent
= it
->max_ascent
;
20370 if (it
->descent
> it
->max_descent
)
20371 it
->descent
= it
->max_descent
;
20374 take_vertical_position_into_account (it
);
20376 /* If we have to actually produce glyphs, do it. */
20381 /* Translate a space with a `space-width' property
20382 into a stretch glyph. */
20383 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20384 / FONT_HEIGHT (font
));
20385 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20386 it
->ascent
+ it
->descent
, ascent
);
20391 /* If characters with lbearing or rbearing are displayed
20392 in this line, record that fact in a flag of the
20393 glyph row. This is used to optimize X output code. */
20394 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20395 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20398 else if (it
->char_to_display
== '\n')
20400 /* A newline has no width but we need the height of the line.
20401 But if previous part of the line set a height, don't
20402 increase that height */
20404 Lisp_Object height
;
20405 Lisp_Object total_height
= Qnil
;
20407 it
->override_ascent
= -1;
20408 it
->pixel_width
= 0;
20411 height
= get_line_height_property(it
, Qline_height
);
20412 /* Split (line-height total-height) list */
20414 && CONSP (XCDR (height
))
20415 && NILP (XCDR (XCDR (height
))))
20417 total_height
= XCAR (XCDR (height
));
20418 height
= XCAR (height
);
20420 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20422 if (it
->override_ascent
>= 0)
20424 it
->ascent
= it
->override_ascent
;
20425 it
->descent
= it
->override_descent
;
20426 boff
= it
->override_boff
;
20430 it
->ascent
= FONT_BASE (font
) + boff
;
20431 it
->descent
= FONT_DESCENT (font
) - boff
;
20434 if (EQ (height
, Qt
))
20436 if (it
->descent
> it
->max_descent
)
20438 it
->ascent
+= it
->descent
- it
->max_descent
;
20439 it
->descent
= it
->max_descent
;
20441 if (it
->ascent
> it
->max_ascent
)
20443 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20444 it
->ascent
= it
->max_ascent
;
20446 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20447 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20448 it
->constrain_row_ascent_descent_p
= 1;
20449 extra_line_spacing
= 0;
20453 Lisp_Object spacing
;
20455 it
->phys_ascent
= it
->ascent
;
20456 it
->phys_descent
= it
->descent
;
20458 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20459 && face
->box
!= FACE_NO_BOX
20460 && face
->box_line_width
> 0)
20462 it
->ascent
+= face
->box_line_width
;
20463 it
->descent
+= face
->box_line_width
;
20466 && XINT (height
) > it
->ascent
+ it
->descent
)
20467 it
->ascent
= XINT (height
) - it
->descent
;
20469 if (!NILP (total_height
))
20470 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20473 spacing
= get_line_height_property(it
, Qline_spacing
);
20474 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20476 if (INTEGERP (spacing
))
20478 extra_line_spacing
= XINT (spacing
);
20479 if (!NILP (total_height
))
20480 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20484 else if (it
->char_to_display
== '\t')
20486 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20487 int x
= it
->current_x
+ it
->continuation_lines_width
;
20488 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20490 /* If the distance from the current position to the next tab
20491 stop is less than a space character width, use the
20492 tab stop after that. */
20493 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20494 next_tab_x
+= tab_width
;
20496 it
->pixel_width
= next_tab_x
- x
;
20498 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20499 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20503 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20504 it
->ascent
+ it
->descent
, it
->ascent
);
20509 /* A multi-byte character. Assume that the display width of the
20510 character is the width of the character multiplied by the
20511 width of the font. */
20513 /* If we found a font, this font should give us the right
20514 metrics. If we didn't find a font, use the frame's
20515 default font and calculate the width of the character
20516 from the charset width; this is what old redisplay code
20519 pcm
= rif
->per_char_metric (font
, &char2b
,
20520 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20522 if (font_not_found_p
|| !pcm
)
20524 int charset
= CHAR_CHARSET (it
->char_to_display
);
20526 it
->glyph_not_available_p
= 1;
20527 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20528 * CHARSET_WIDTH (charset
));
20529 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20530 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20534 it
->pixel_width
= pcm
->width
;
20535 it
->phys_ascent
= pcm
->ascent
+ boff
;
20536 it
->phys_descent
= pcm
->descent
- boff
;
20538 && (pcm
->lbearing
< 0
20539 || pcm
->rbearing
> pcm
->width
))
20540 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20543 it
->ascent
= FONT_BASE (font
) + boff
;
20544 it
->descent
= FONT_DESCENT (font
) - boff
;
20545 if (face
->box
!= FACE_NO_BOX
)
20547 int thick
= face
->box_line_width
;
20551 it
->ascent
+= thick
;
20552 it
->descent
+= thick
;
20557 if (it
->start_of_box_run_p
)
20558 it
->pixel_width
+= thick
;
20559 if (it
->end_of_box_run_p
)
20560 it
->pixel_width
+= thick
;
20563 /* If face has an overline, add the height of the overline
20564 (1 pixel) and a 1 pixel margin to the character height. */
20565 if (face
->overline_p
)
20566 it
->ascent
+= overline_margin
;
20568 take_vertical_position_into_account (it
);
20573 it
->multibyte_p
= saved_multibyte_p
;
20575 else if (it
->what
== IT_COMPOSITION
)
20577 /* Note: A composition is represented as one glyph in the
20578 glyph matrix. There are no padding glyphs. */
20581 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20583 int font_not_found_p
;
20584 struct font_info
*font_info
;
20585 int boff
; /* baseline offset */
20586 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20588 /* Maybe translate single-byte characters to multibyte. */
20589 it
->char_to_display
= it
->c
;
20590 if (unibyte_display_via_language_environment
20591 && SINGLE_BYTE_CHAR_P (it
->c
)
20594 && !NILP (Vnonascii_translation_table
))))
20596 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20599 /* Get face and font to use. Encode IT->char_to_display. */
20600 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20601 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20602 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20603 &char2b
, it
->multibyte_p
, 0);
20606 /* When no suitable font found, use the default font. */
20607 font_not_found_p
= font
== NULL
;
20608 if (font_not_found_p
)
20610 font
= FRAME_FONT (it
->f
);
20611 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20616 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20617 boff
= font_info
->baseline_offset
;
20618 if (font_info
->vertical_centering
)
20619 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20622 /* There are no padding glyphs, so there is only one glyph to
20623 produce for the composition. Important is that pixel_width,
20624 ascent and descent are the values of what is drawn by
20625 draw_glyphs (i.e. the values of the overall glyphs composed). */
20628 /* If we have not yet calculated pixel size data of glyphs of
20629 the composition for the current face font, calculate them
20630 now. Theoretically, we have to check all fonts for the
20631 glyphs, but that requires much time and memory space. So,
20632 here we check only the font of the first glyph. This leads
20633 to incorrect display very rarely, and C-l (recenter) can
20634 correct the display anyway. */
20635 if (cmp
->font
!= (void *) font
)
20637 /* Ascent and descent of the font of the first character of
20638 this composition (adjusted by baseline offset). Ascent
20639 and descent of overall glyphs should not be less than
20640 them respectively. */
20641 int font_ascent
= FONT_BASE (font
) + boff
;
20642 int font_descent
= FONT_DESCENT (font
) - boff
;
20643 /* Bounding box of the overall glyphs. */
20644 int leftmost
, rightmost
, lowest
, highest
;
20645 int i
, width
, ascent
, descent
;
20647 cmp
->font
= (void *) font
;
20649 /* Initialize the bounding box. */
20651 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20652 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20654 width
= pcm
->width
;
20655 ascent
= pcm
->ascent
;
20656 descent
= pcm
->descent
;
20660 width
= FONT_WIDTH (font
);
20661 ascent
= FONT_BASE (font
);
20662 descent
= FONT_DESCENT (font
);
20666 lowest
= - descent
+ boff
;
20667 highest
= ascent
+ boff
;
20671 && font_info
->default_ascent
20672 && CHAR_TABLE_P (Vuse_default_ascent
)
20673 && !NILP (Faref (Vuse_default_ascent
,
20674 make_number (it
->char_to_display
))))
20675 highest
= font_info
->default_ascent
+ boff
;
20677 /* Draw the first glyph at the normal position. It may be
20678 shifted to right later if some other glyphs are drawn at
20680 cmp
->offsets
[0] = 0;
20681 cmp
->offsets
[1] = boff
;
20683 /* Set cmp->offsets for the remaining glyphs. */
20684 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20686 int left
, right
, btm
, top
;
20687 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20688 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20690 face
= FACE_FROM_ID (it
->f
, face_id
);
20691 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20692 &char2b
, it
->multibyte_p
, 0);
20696 font
= FRAME_FONT (it
->f
);
20697 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20703 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20704 boff
= font_info
->baseline_offset
;
20705 if (font_info
->vertical_centering
)
20706 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20710 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20711 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20713 width
= pcm
->width
;
20714 ascent
= pcm
->ascent
;
20715 descent
= pcm
->descent
;
20719 width
= FONT_WIDTH (font
);
20724 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20726 /* Relative composition with or without
20727 alternate chars. */
20728 left
= (leftmost
+ rightmost
- width
) / 2;
20729 btm
= - descent
+ boff
;
20730 if (font_info
&& font_info
->relative_compose
20731 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20732 || NILP (Faref (Vignore_relative_composition
,
20733 make_number (ch
)))))
20736 if (- descent
>= font_info
->relative_compose
)
20737 /* One extra pixel between two glyphs. */
20739 else if (ascent
<= 0)
20740 /* One extra pixel between two glyphs. */
20741 btm
= lowest
- 1 - ascent
- descent
;
20746 /* A composition rule is specified by an integer
20747 value that encodes global and new reference
20748 points (GREF and NREF). GREF and NREF are
20749 specified by numbers as below:
20751 0---1---2 -- ascent
20755 9--10--11 -- center
20757 ---3---4---5--- baseline
20759 6---7---8 -- descent
20761 int rule
= COMPOSITION_RULE (cmp
, i
);
20762 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20764 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20765 grefx
= gref
% 3, nrefx
= nref
% 3;
20766 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20769 + grefx
* (rightmost
- leftmost
) / 2
20770 - nrefx
* width
/ 2);
20771 btm
= ((grefy
== 0 ? highest
20773 : grefy
== 2 ? lowest
20774 : (highest
+ lowest
) / 2)
20775 - (nrefy
== 0 ? ascent
+ descent
20776 : nrefy
== 1 ? descent
- boff
20778 : (ascent
+ descent
) / 2));
20781 cmp
->offsets
[i
* 2] = left
;
20782 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20784 /* Update the bounding box of the overall glyphs. */
20785 right
= left
+ width
;
20786 top
= btm
+ descent
+ ascent
;
20787 if (left
< leftmost
)
20789 if (right
> rightmost
)
20797 /* If there are glyphs whose x-offsets are negative,
20798 shift all glyphs to the right and make all x-offsets
20802 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20803 cmp
->offsets
[i
* 2] -= leftmost
;
20804 rightmost
-= leftmost
;
20807 cmp
->pixel_width
= rightmost
;
20808 cmp
->ascent
= highest
;
20809 cmp
->descent
= - lowest
;
20810 if (cmp
->ascent
< font_ascent
)
20811 cmp
->ascent
= font_ascent
;
20812 if (cmp
->descent
< font_descent
)
20813 cmp
->descent
= font_descent
;
20816 it
->pixel_width
= cmp
->pixel_width
;
20817 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20818 it
->descent
= it
->phys_descent
= cmp
->descent
;
20820 if (face
->box
!= FACE_NO_BOX
)
20822 int thick
= face
->box_line_width
;
20826 it
->ascent
+= thick
;
20827 it
->descent
+= thick
;
20832 if (it
->start_of_box_run_p
)
20833 it
->pixel_width
+= thick
;
20834 if (it
->end_of_box_run_p
)
20835 it
->pixel_width
+= thick
;
20838 /* If face has an overline, add the height of the overline
20839 (1 pixel) and a 1 pixel margin to the character height. */
20840 if (face
->overline_p
)
20841 it
->ascent
+= overline_margin
;
20843 take_vertical_position_into_account (it
);
20846 append_composite_glyph (it
);
20848 else if (it
->what
== IT_IMAGE
)
20849 produce_image_glyph (it
);
20850 else if (it
->what
== IT_STRETCH
)
20851 produce_stretch_glyph (it
);
20853 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20854 because this isn't true for images with `:ascent 100'. */
20855 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20856 if (it
->area
== TEXT_AREA
)
20857 it
->current_x
+= it
->pixel_width
;
20859 if (extra_line_spacing
> 0)
20861 it
->descent
+= extra_line_spacing
;
20862 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20863 it
->max_extra_line_spacing
= extra_line_spacing
;
20866 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20867 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20868 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20869 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20873 Output LEN glyphs starting at START at the nominal cursor position.
20874 Advance the nominal cursor over the text. The global variable
20875 updated_window contains the window being updated, updated_row is
20876 the glyph row being updated, and updated_area is the area of that
20877 row being updated. */
20880 x_write_glyphs (start
, len
)
20881 struct glyph
*start
;
20886 xassert (updated_window
&& updated_row
);
20889 /* Write glyphs. */
20891 hpos
= start
- updated_row
->glyphs
[updated_area
];
20892 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20893 updated_row
, updated_area
,
20895 DRAW_NORMAL_TEXT
, 0);
20897 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20898 if (updated_area
== TEXT_AREA
20899 && updated_window
->phys_cursor_on_p
20900 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20901 && updated_window
->phys_cursor
.hpos
>= hpos
20902 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20903 updated_window
->phys_cursor_on_p
= 0;
20907 /* Advance the output cursor. */
20908 output_cursor
.hpos
+= len
;
20909 output_cursor
.x
= x
;
20914 Insert LEN glyphs from START at the nominal cursor position. */
20917 x_insert_glyphs (start
, len
)
20918 struct glyph
*start
;
20923 int line_height
, shift_by_width
, shifted_region_width
;
20924 struct glyph_row
*row
;
20925 struct glyph
*glyph
;
20926 int frame_x
, frame_y
, hpos
;
20928 xassert (updated_window
&& updated_row
);
20930 w
= updated_window
;
20931 f
= XFRAME (WINDOW_FRAME (w
));
20933 /* Get the height of the line we are in. */
20935 line_height
= row
->height
;
20937 /* Get the width of the glyphs to insert. */
20938 shift_by_width
= 0;
20939 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20940 shift_by_width
+= glyph
->pixel_width
;
20942 /* Get the width of the region to shift right. */
20943 shifted_region_width
= (window_box_width (w
, updated_area
)
20948 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20949 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20951 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20952 line_height
, shift_by_width
);
20954 /* Write the glyphs. */
20955 hpos
= start
- row
->glyphs
[updated_area
];
20956 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20958 DRAW_NORMAL_TEXT
, 0);
20960 /* Advance the output cursor. */
20961 output_cursor
.hpos
+= len
;
20962 output_cursor
.x
+= shift_by_width
;
20968 Erase the current text line from the nominal cursor position
20969 (inclusive) to pixel column TO_X (exclusive). The idea is that
20970 everything from TO_X onward is already erased.
20972 TO_X is a pixel position relative to updated_area of
20973 updated_window. TO_X == -1 means clear to the end of this area. */
20976 x_clear_end_of_line (to_x
)
20980 struct window
*w
= updated_window
;
20981 int max_x
, min_y
, max_y
;
20982 int from_x
, from_y
, to_y
;
20984 xassert (updated_window
&& updated_row
);
20985 f
= XFRAME (w
->frame
);
20987 if (updated_row
->full_width_p
)
20988 max_x
= WINDOW_TOTAL_WIDTH (w
);
20990 max_x
= window_box_width (w
, updated_area
);
20991 max_y
= window_text_bottom_y (w
);
20993 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20994 of window. For TO_X > 0, truncate to end of drawing area. */
21000 to_x
= min (to_x
, max_x
);
21002 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21004 /* Notice if the cursor will be cleared by this operation. */
21005 if (!updated_row
->full_width_p
)
21006 notice_overwritten_cursor (w
, updated_area
,
21007 output_cursor
.x
, -1,
21009 MATRIX_ROW_BOTTOM_Y (updated_row
));
21011 from_x
= output_cursor
.x
;
21013 /* Translate to frame coordinates. */
21014 if (updated_row
->full_width_p
)
21016 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21017 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21021 int area_left
= window_box_left (w
, updated_area
);
21022 from_x
+= area_left
;
21026 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21027 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21028 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21030 /* Prevent inadvertently clearing to end of the X window. */
21031 if (to_x
> from_x
&& to_y
> from_y
)
21034 rif
->clear_frame_area (f
, from_x
, from_y
,
21035 to_x
- from_x
, to_y
- from_y
);
21040 #endif /* HAVE_WINDOW_SYSTEM */
21044 /***********************************************************************
21046 ***********************************************************************/
21048 /* Value is the internal representation of the specified cursor type
21049 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21050 of the bar cursor. */
21052 static enum text_cursor_kinds
21053 get_specified_cursor_type (arg
, width
)
21057 enum text_cursor_kinds type
;
21062 if (EQ (arg
, Qbox
))
21063 return FILLED_BOX_CURSOR
;
21065 if (EQ (arg
, Qhollow
))
21066 return HOLLOW_BOX_CURSOR
;
21068 if (EQ (arg
, Qbar
))
21075 && EQ (XCAR (arg
), Qbar
)
21076 && INTEGERP (XCDR (arg
))
21077 && XINT (XCDR (arg
)) >= 0)
21079 *width
= XINT (XCDR (arg
));
21083 if (EQ (arg
, Qhbar
))
21086 return HBAR_CURSOR
;
21090 && EQ (XCAR (arg
), Qhbar
)
21091 && INTEGERP (XCDR (arg
))
21092 && XINT (XCDR (arg
)) >= 0)
21094 *width
= XINT (XCDR (arg
));
21095 return HBAR_CURSOR
;
21098 /* Treat anything unknown as "hollow box cursor".
21099 It was bad to signal an error; people have trouble fixing
21100 .Xdefaults with Emacs, when it has something bad in it. */
21101 type
= HOLLOW_BOX_CURSOR
;
21106 /* Set the default cursor types for specified frame. */
21108 set_frame_cursor_types (f
, arg
)
21115 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21116 FRAME_CURSOR_WIDTH (f
) = width
;
21118 /* By default, set up the blink-off state depending on the on-state. */
21120 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21123 FRAME_BLINK_OFF_CURSOR (f
)
21124 = get_specified_cursor_type (XCDR (tem
), &width
);
21125 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21128 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21132 /* Return the cursor we want to be displayed in window W. Return
21133 width of bar/hbar cursor through WIDTH arg. Return with
21134 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21135 (i.e. if the `system caret' should track this cursor).
21137 In a mini-buffer window, we want the cursor only to appear if we
21138 are reading input from this window. For the selected window, we
21139 want the cursor type given by the frame parameter or buffer local
21140 setting of cursor-type. If explicitly marked off, draw no cursor.
21141 In all other cases, we want a hollow box cursor. */
21143 static enum text_cursor_kinds
21144 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21146 struct glyph
*glyph
;
21148 int *active_cursor
;
21150 struct frame
*f
= XFRAME (w
->frame
);
21151 struct buffer
*b
= XBUFFER (w
->buffer
);
21152 int cursor_type
= DEFAULT_CURSOR
;
21153 Lisp_Object alt_cursor
;
21154 int non_selected
= 0;
21156 *active_cursor
= 1;
21159 if (cursor_in_echo_area
21160 && FRAME_HAS_MINIBUF_P (f
)
21161 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21163 if (w
== XWINDOW (echo_area_window
))
21165 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21167 *width
= FRAME_CURSOR_WIDTH (f
);
21168 return FRAME_DESIRED_CURSOR (f
);
21171 return get_specified_cursor_type (b
->cursor_type
, width
);
21174 *active_cursor
= 0;
21178 /* Nonselected window or nonselected frame. */
21179 else if (w
!= XWINDOW (f
->selected_window
)
21180 #ifdef HAVE_WINDOW_SYSTEM
21181 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21185 *active_cursor
= 0;
21187 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21193 /* Never display a cursor in a window in which cursor-type is nil. */
21194 if (NILP (b
->cursor_type
))
21197 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21200 alt_cursor
= b
->cursor_in_non_selected_windows
;
21201 return get_specified_cursor_type (alt_cursor
, width
);
21204 /* Get the normal cursor type for this window. */
21205 if (EQ (b
->cursor_type
, Qt
))
21207 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21208 *width
= FRAME_CURSOR_WIDTH (f
);
21211 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21213 /* Use normal cursor if not blinked off. */
21214 if (!w
->cursor_off_p
)
21216 #ifdef HAVE_WINDOW_SYSTEM
21217 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21219 if (cursor_type
== FILLED_BOX_CURSOR
)
21221 /* Using a block cursor on large images can be very annoying.
21222 So use a hollow cursor for "large" images. */
21223 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21224 if (img
!= NULL
&& IMAGEP (img
->spec
))
21226 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21227 where N = size of default frame font size.
21228 This should cover most of the "tiny" icons people may use. */
21229 if (img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21230 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21231 cursor_type
= HOLLOW_BOX_CURSOR
;
21234 else if (cursor_type
!= NO_CURSOR
)
21236 /* Display current only supports BOX and HOLLOW cursors for images.
21237 So for now, unconditionally use a HOLLOW cursor when cursor is
21238 not a solid box cursor. */
21239 cursor_type
= HOLLOW_BOX_CURSOR
;
21243 return cursor_type
;
21246 /* Cursor is blinked off, so determine how to "toggle" it. */
21248 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21249 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21250 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21252 /* Then see if frame has specified a specific blink off cursor type. */
21253 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21255 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21256 return FRAME_BLINK_OFF_CURSOR (f
);
21260 /* Some people liked having a permanently visible blinking cursor,
21261 while others had very strong opinions against it. So it was
21262 decided to remove it. KFS 2003-09-03 */
21264 /* Finally perform built-in cursor blinking:
21265 filled box <-> hollow box
21266 wide [h]bar <-> narrow [h]bar
21267 narrow [h]bar <-> no cursor
21268 other type <-> no cursor */
21270 if (cursor_type
== FILLED_BOX_CURSOR
)
21271 return HOLLOW_BOX_CURSOR
;
21273 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21276 return cursor_type
;
21284 #ifdef HAVE_WINDOW_SYSTEM
21286 /* Notice when the text cursor of window W has been completely
21287 overwritten by a drawing operation that outputs glyphs in AREA
21288 starting at X0 and ending at X1 in the line starting at Y0 and
21289 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21290 the rest of the line after X0 has been written. Y coordinates
21291 are window-relative. */
21294 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21296 enum glyph_row_area area
;
21297 int x0
, y0
, x1
, y1
;
21299 int cx0
, cx1
, cy0
, cy1
;
21300 struct glyph_row
*row
;
21302 if (!w
->phys_cursor_on_p
)
21304 if (area
!= TEXT_AREA
)
21307 if (w
->phys_cursor
.vpos
< 0
21308 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21309 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21310 !(row
->enabled_p
&& row
->displays_text_p
)))
21313 if (row
->cursor_in_fringe_p
)
21315 row
->cursor_in_fringe_p
= 0;
21316 draw_fringe_bitmap (w
, row
, 0);
21317 w
->phys_cursor_on_p
= 0;
21321 cx0
= w
->phys_cursor
.x
;
21322 cx1
= cx0
+ w
->phys_cursor_width
;
21323 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21326 /* The cursor image will be completely removed from the
21327 screen if the output area intersects the cursor area in
21328 y-direction. When we draw in [y0 y1[, and some part of
21329 the cursor is at y < y0, that part must have been drawn
21330 before. When scrolling, the cursor is erased before
21331 actually scrolling, so we don't come here. When not
21332 scrolling, the rows above the old cursor row must have
21333 changed, and in this case these rows must have written
21334 over the cursor image.
21336 Likewise if part of the cursor is below y1, with the
21337 exception of the cursor being in the first blank row at
21338 the buffer and window end because update_text_area
21339 doesn't draw that row. (Except when it does, but
21340 that's handled in update_text_area.) */
21342 cy0
= w
->phys_cursor
.y
;
21343 cy1
= cy0
+ w
->phys_cursor_height
;
21344 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21347 w
->phys_cursor_on_p
= 0;
21350 #endif /* HAVE_WINDOW_SYSTEM */
21353 /************************************************************************
21355 ************************************************************************/
21357 #ifdef HAVE_WINDOW_SYSTEM
21360 Fix the display of area AREA of overlapping row ROW in window W
21361 with respect to the overlapping part OVERLAPS. */
21364 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21366 struct glyph_row
*row
;
21367 enum glyph_row_area area
;
21375 for (i
= 0; i
< row
->used
[area
];)
21377 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21379 int start
= i
, start_x
= x
;
21383 x
+= row
->glyphs
[area
][i
].pixel_width
;
21386 while (i
< row
->used
[area
]
21387 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21389 draw_glyphs (w
, start_x
, row
, area
,
21391 DRAW_NORMAL_TEXT
, overlaps
);
21395 x
+= row
->glyphs
[area
][i
].pixel_width
;
21405 Draw the cursor glyph of window W in glyph row ROW. See the
21406 comment of draw_glyphs for the meaning of HL. */
21409 draw_phys_cursor_glyph (w
, row
, hl
)
21411 struct glyph_row
*row
;
21412 enum draw_glyphs_face hl
;
21414 /* If cursor hpos is out of bounds, don't draw garbage. This can
21415 happen in mini-buffer windows when switching between echo area
21416 glyphs and mini-buffer. */
21417 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21419 int on_p
= w
->phys_cursor_on_p
;
21421 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21422 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21424 w
->phys_cursor_on_p
= on_p
;
21426 if (hl
== DRAW_CURSOR
)
21427 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21428 /* When we erase the cursor, and ROW is overlapped by other
21429 rows, make sure that these overlapping parts of other rows
21431 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21433 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21435 if (row
> w
->current_matrix
->rows
21436 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21437 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21438 OVERLAPS_ERASED_CURSOR
);
21440 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21441 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21442 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21443 OVERLAPS_ERASED_CURSOR
);
21450 Erase the image of a cursor of window W from the screen. */
21453 erase_phys_cursor (w
)
21456 struct frame
*f
= XFRAME (w
->frame
);
21457 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21458 int hpos
= w
->phys_cursor
.hpos
;
21459 int vpos
= w
->phys_cursor
.vpos
;
21460 int mouse_face_here_p
= 0;
21461 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21462 struct glyph_row
*cursor_row
;
21463 struct glyph
*cursor_glyph
;
21464 enum draw_glyphs_face hl
;
21466 /* No cursor displayed or row invalidated => nothing to do on the
21468 if (w
->phys_cursor_type
== NO_CURSOR
)
21469 goto mark_cursor_off
;
21471 /* VPOS >= active_glyphs->nrows means that window has been resized.
21472 Don't bother to erase the cursor. */
21473 if (vpos
>= active_glyphs
->nrows
)
21474 goto mark_cursor_off
;
21476 /* If row containing cursor is marked invalid, there is nothing we
21478 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21479 if (!cursor_row
->enabled_p
)
21480 goto mark_cursor_off
;
21482 /* If line spacing is > 0, old cursor may only be partially visible in
21483 window after split-window. So adjust visible height. */
21484 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21485 window_text_bottom_y (w
) - cursor_row
->y
);
21487 /* If row is completely invisible, don't attempt to delete a cursor which
21488 isn't there. This can happen if cursor is at top of a window, and
21489 we switch to a buffer with a header line in that window. */
21490 if (cursor_row
->visible_height
<= 0)
21491 goto mark_cursor_off
;
21493 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21494 if (cursor_row
->cursor_in_fringe_p
)
21496 cursor_row
->cursor_in_fringe_p
= 0;
21497 draw_fringe_bitmap (w
, cursor_row
, 0);
21498 goto mark_cursor_off
;
21501 /* This can happen when the new row is shorter than the old one.
21502 In this case, either draw_glyphs or clear_end_of_line
21503 should have cleared the cursor. Note that we wouldn't be
21504 able to erase the cursor in this case because we don't have a
21505 cursor glyph at hand. */
21506 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21507 goto mark_cursor_off
;
21509 /* If the cursor is in the mouse face area, redisplay that when
21510 we clear the cursor. */
21511 if (! NILP (dpyinfo
->mouse_face_window
)
21512 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21513 && (vpos
> dpyinfo
->mouse_face_beg_row
21514 || (vpos
== dpyinfo
->mouse_face_beg_row
21515 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21516 && (vpos
< dpyinfo
->mouse_face_end_row
21517 || (vpos
== dpyinfo
->mouse_face_end_row
21518 && hpos
< dpyinfo
->mouse_face_end_col
))
21519 /* Don't redraw the cursor's spot in mouse face if it is at the
21520 end of a line (on a newline). The cursor appears there, but
21521 mouse highlighting does not. */
21522 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21523 mouse_face_here_p
= 1;
21525 /* Maybe clear the display under the cursor. */
21526 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21529 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21532 cursor_glyph
= get_phys_cursor_glyph (w
);
21533 if (cursor_glyph
== NULL
)
21534 goto mark_cursor_off
;
21536 width
= cursor_glyph
->pixel_width
;
21537 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21538 x
= w
->phys_cursor
.x
;
21540 width
-= left_x
- x
;
21541 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21542 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21543 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21546 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21549 /* Erase the cursor by redrawing the character underneath it. */
21550 if (mouse_face_here_p
)
21551 hl
= DRAW_MOUSE_FACE
;
21553 hl
= DRAW_NORMAL_TEXT
;
21554 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21557 w
->phys_cursor_on_p
= 0;
21558 w
->phys_cursor_type
= NO_CURSOR
;
21563 Display or clear cursor of window W. If ON is zero, clear the
21564 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21565 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21568 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21570 int on
, hpos
, vpos
, x
, y
;
21572 struct frame
*f
= XFRAME (w
->frame
);
21573 int new_cursor_type
;
21574 int new_cursor_width
;
21576 struct glyph_row
*glyph_row
;
21577 struct glyph
*glyph
;
21579 /* This is pointless on invisible frames, and dangerous on garbaged
21580 windows and frames; in the latter case, the frame or window may
21581 be in the midst of changing its size, and x and y may be off the
21583 if (! FRAME_VISIBLE_P (f
)
21584 || FRAME_GARBAGED_P (f
)
21585 || vpos
>= w
->current_matrix
->nrows
21586 || hpos
>= w
->current_matrix
->matrix_w
)
21589 /* If cursor is off and we want it off, return quickly. */
21590 if (!on
&& !w
->phys_cursor_on_p
)
21593 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21594 /* If cursor row is not enabled, we don't really know where to
21595 display the cursor. */
21596 if (!glyph_row
->enabled_p
)
21598 w
->phys_cursor_on_p
= 0;
21603 if (!glyph_row
->exact_window_width_line_p
21604 || hpos
< glyph_row
->used
[TEXT_AREA
])
21605 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21607 xassert (interrupt_input_blocked
);
21609 /* Set new_cursor_type to the cursor we want to be displayed. */
21610 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21611 &new_cursor_width
, &active_cursor
);
21613 /* If cursor is currently being shown and we don't want it to be or
21614 it is in the wrong place, or the cursor type is not what we want,
21616 if (w
->phys_cursor_on_p
21618 || w
->phys_cursor
.x
!= x
21619 || w
->phys_cursor
.y
!= y
21620 || new_cursor_type
!= w
->phys_cursor_type
21621 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21622 && new_cursor_width
!= w
->phys_cursor_width
)))
21623 erase_phys_cursor (w
);
21625 /* Don't check phys_cursor_on_p here because that flag is only set
21626 to zero in some cases where we know that the cursor has been
21627 completely erased, to avoid the extra work of erasing the cursor
21628 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21629 still not be visible, or it has only been partly erased. */
21632 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21633 w
->phys_cursor_height
= glyph_row
->height
;
21635 /* Set phys_cursor_.* before x_draw_.* is called because some
21636 of them may need the information. */
21637 w
->phys_cursor
.x
= x
;
21638 w
->phys_cursor
.y
= glyph_row
->y
;
21639 w
->phys_cursor
.hpos
= hpos
;
21640 w
->phys_cursor
.vpos
= vpos
;
21643 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21644 new_cursor_type
, new_cursor_width
,
21645 on
, active_cursor
);
21649 /* Switch the display of W's cursor on or off, according to the value
21653 update_window_cursor (w
, on
)
21657 /* Don't update cursor in windows whose frame is in the process
21658 of being deleted. */
21659 if (w
->current_matrix
)
21662 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21663 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21669 /* Call update_window_cursor with parameter ON_P on all leaf windows
21670 in the window tree rooted at W. */
21673 update_cursor_in_window_tree (w
, on_p
)
21679 if (!NILP (w
->hchild
))
21680 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21681 else if (!NILP (w
->vchild
))
21682 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21684 update_window_cursor (w
, on_p
);
21686 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21692 Display the cursor on window W, or clear it, according to ON_P.
21693 Don't change the cursor's position. */
21696 x_update_cursor (f
, on_p
)
21700 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21705 Clear the cursor of window W to background color, and mark the
21706 cursor as not shown. This is used when the text where the cursor
21707 is is about to be rewritten. */
21713 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21714 update_window_cursor (w
, 0);
21719 Display the active region described by mouse_face_* according to DRAW. */
21722 show_mouse_face (dpyinfo
, draw
)
21723 Display_Info
*dpyinfo
;
21724 enum draw_glyphs_face draw
;
21726 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21727 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21729 if (/* If window is in the process of being destroyed, don't bother
21731 w
->current_matrix
!= NULL
21732 /* Don't update mouse highlight if hidden */
21733 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21734 /* Recognize when we are called to operate on rows that don't exist
21735 anymore. This can happen when a window is split. */
21736 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21738 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21739 struct glyph_row
*row
, *first
, *last
;
21741 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21742 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21744 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21746 int start_hpos
, end_hpos
, start_x
;
21748 /* For all but the first row, the highlight starts at column 0. */
21751 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21752 start_x
= dpyinfo
->mouse_face_beg_x
;
21761 end_hpos
= dpyinfo
->mouse_face_end_col
;
21764 end_hpos
= row
->used
[TEXT_AREA
];
21765 if (draw
== DRAW_NORMAL_TEXT
)
21766 row
->fill_line_p
= 1; /* Clear to end of line */
21769 if (end_hpos
> start_hpos
)
21771 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21772 start_hpos
, end_hpos
,
21776 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21780 /* When we've written over the cursor, arrange for it to
21781 be displayed again. */
21782 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21785 display_and_set_cursor (w
, 1,
21786 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21787 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21792 /* Change the mouse cursor. */
21793 if (draw
== DRAW_NORMAL_TEXT
)
21794 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21795 else if (draw
== DRAW_MOUSE_FACE
)
21796 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21798 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21802 Clear out the mouse-highlighted active region.
21803 Redraw it un-highlighted first. Value is non-zero if mouse
21804 face was actually drawn unhighlighted. */
21807 clear_mouse_face (dpyinfo
)
21808 Display_Info
*dpyinfo
;
21812 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21814 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21818 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21819 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21820 dpyinfo
->mouse_face_window
= Qnil
;
21821 dpyinfo
->mouse_face_overlay
= Qnil
;
21827 Non-zero if physical cursor of window W is within mouse face. */
21830 cursor_in_mouse_face_p (w
)
21833 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21834 int in_mouse_face
= 0;
21836 if (WINDOWP (dpyinfo
->mouse_face_window
)
21837 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21839 int hpos
= w
->phys_cursor
.hpos
;
21840 int vpos
= w
->phys_cursor
.vpos
;
21842 if (vpos
>= dpyinfo
->mouse_face_beg_row
21843 && vpos
<= dpyinfo
->mouse_face_end_row
21844 && (vpos
> dpyinfo
->mouse_face_beg_row
21845 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21846 && (vpos
< dpyinfo
->mouse_face_end_row
21847 || hpos
< dpyinfo
->mouse_face_end_col
21848 || dpyinfo
->mouse_face_past_end
))
21852 return in_mouse_face
;
21858 /* Find the glyph matrix position of buffer position CHARPOS in window
21859 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21860 current glyphs must be up to date. If CHARPOS is above window
21861 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21862 of last line in W. In the row containing CHARPOS, stop before glyphs
21863 having STOP as object. */
21865 #if 1 /* This is a version of fast_find_position that's more correct
21866 in the presence of hscrolling, for example. I didn't install
21867 it right away because the problem fixed is minor, it failed
21868 in 20.x as well, and I think it's too risky to install
21869 so near the release of 21.1. 2001-09-25 gerd. */
21872 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21875 int *hpos
, *vpos
, *x
, *y
;
21878 struct glyph_row
*row
, *first
;
21879 struct glyph
*glyph
, *end
;
21882 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21883 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21888 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21892 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21895 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21899 /* If whole rows or last part of a row came from a display overlay,
21900 row_containing_pos will skip over such rows because their end pos
21901 equals the start pos of the overlay or interval.
21903 Move back if we have a STOP object and previous row's
21904 end glyph came from STOP. */
21907 struct glyph_row
*prev
;
21908 while ((prev
= row
- 1, prev
>= first
)
21909 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21910 && prev
->used
[TEXT_AREA
] > 0)
21912 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21913 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21914 while (--glyph
>= beg
21915 && INTEGERP (glyph
->object
));
21917 || !EQ (stop
, glyph
->object
))
21925 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21927 glyph
= row
->glyphs
[TEXT_AREA
];
21928 end
= glyph
+ row
->used
[TEXT_AREA
];
21930 /* Skip over glyphs not having an object at the start of the row.
21931 These are special glyphs like truncation marks on terminal
21933 if (row
->displays_text_p
)
21935 && INTEGERP (glyph
->object
)
21936 && !EQ (stop
, glyph
->object
)
21937 && glyph
->charpos
< 0)
21939 *x
+= glyph
->pixel_width
;
21944 && !INTEGERP (glyph
->object
)
21945 && !EQ (stop
, glyph
->object
)
21946 && (!BUFFERP (glyph
->object
)
21947 || glyph
->charpos
< charpos
))
21949 *x
+= glyph
->pixel_width
;
21953 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21960 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21963 int *hpos
, *vpos
, *x
, *y
;
21968 int maybe_next_line_p
= 0;
21969 int line_start_position
;
21970 int yb
= window_text_bottom_y (w
);
21971 struct glyph_row
*row
, *best_row
;
21972 int row_vpos
, best_row_vpos
;
21975 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21976 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21978 while (row
->y
< yb
)
21980 if (row
->used
[TEXT_AREA
])
21981 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21983 line_start_position
= 0;
21985 if (line_start_position
> pos
)
21987 /* If the position sought is the end of the buffer,
21988 don't include the blank lines at the bottom of the window. */
21989 else if (line_start_position
== pos
21990 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21992 maybe_next_line_p
= 1;
21995 else if (line_start_position
> 0)
21998 best_row_vpos
= row_vpos
;
22001 if (row
->y
+ row
->height
>= yb
)
22008 /* Find the right column within BEST_ROW. */
22010 current_x
= best_row
->x
;
22011 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22013 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22014 int charpos
= glyph
->charpos
;
22016 if (BUFFERP (glyph
->object
))
22018 if (charpos
== pos
)
22021 *vpos
= best_row_vpos
;
22026 else if (charpos
> pos
)
22029 else if (EQ (glyph
->object
, stop
))
22034 current_x
+= glyph
->pixel_width
;
22037 /* If we're looking for the end of the buffer,
22038 and we didn't find it in the line we scanned,
22039 use the start of the following line. */
22040 if (maybe_next_line_p
)
22045 current_x
= best_row
->x
;
22048 *vpos
= best_row_vpos
;
22049 *hpos
= lastcol
+ 1;
22058 /* Find the position of the glyph for position POS in OBJECT in
22059 window W's current matrix, and return in *X, *Y the pixel
22060 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22062 RIGHT_P non-zero means return the position of the right edge of the
22063 glyph, RIGHT_P zero means return the left edge position.
22065 If no glyph for POS exists in the matrix, return the position of
22066 the glyph with the next smaller position that is in the matrix, if
22067 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22068 exists in the matrix, return the position of the glyph with the
22069 next larger position in OBJECT.
22071 Value is non-zero if a glyph was found. */
22074 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22077 Lisp_Object object
;
22078 int *hpos
, *vpos
, *x
, *y
;
22081 int yb
= window_text_bottom_y (w
);
22082 struct glyph_row
*r
;
22083 struct glyph
*best_glyph
= NULL
;
22084 struct glyph_row
*best_row
= NULL
;
22087 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22088 r
->enabled_p
&& r
->y
< yb
;
22091 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22092 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22095 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22096 if (EQ (g
->object
, object
))
22098 if (g
->charpos
== pos
)
22105 else if (best_glyph
== NULL
22106 || ((abs (g
->charpos
- pos
)
22107 < abs (best_glyph
->charpos
- pos
))
22110 : g
->charpos
> pos
)))
22124 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22128 *x
+= best_glyph
->pixel_width
;
22133 *vpos
= best_row
- w
->current_matrix
->rows
;
22136 return best_glyph
!= NULL
;
22140 /* See if position X, Y is within a hot-spot of an image. */
22143 on_hot_spot_p (hot_spot
, x
, y
)
22144 Lisp_Object hot_spot
;
22147 if (!CONSP (hot_spot
))
22150 if (EQ (XCAR (hot_spot
), Qrect
))
22152 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22153 Lisp_Object rect
= XCDR (hot_spot
);
22157 if (!CONSP (XCAR (rect
)))
22159 if (!CONSP (XCDR (rect
)))
22161 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22163 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22165 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22167 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22171 else if (EQ (XCAR (hot_spot
), Qcircle
))
22173 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22174 Lisp_Object circ
= XCDR (hot_spot
);
22175 Lisp_Object lr
, lx0
, ly0
;
22177 && CONSP (XCAR (circ
))
22178 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22179 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22180 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22182 double r
= XFLOATINT (lr
);
22183 double dx
= XINT (lx0
) - x
;
22184 double dy
= XINT (ly0
) - y
;
22185 return (dx
* dx
+ dy
* dy
<= r
* r
);
22188 else if (EQ (XCAR (hot_spot
), Qpoly
))
22190 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22191 if (VECTORP (XCDR (hot_spot
)))
22193 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22194 Lisp_Object
*poly
= v
->contents
;
22198 Lisp_Object lx
, ly
;
22201 /* Need an even number of coordinates, and at least 3 edges. */
22202 if (n
< 6 || n
& 1)
22205 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22206 If count is odd, we are inside polygon. Pixels on edges
22207 may or may not be included depending on actual geometry of the
22209 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22210 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22212 x0
= XINT (lx
), y0
= XINT (ly
);
22213 for (i
= 0; i
< n
; i
+= 2)
22215 int x1
= x0
, y1
= y0
;
22216 if ((lx
= poly
[i
], !INTEGERP (lx
))
22217 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22219 x0
= XINT (lx
), y0
= XINT (ly
);
22221 /* Does this segment cross the X line? */
22229 if (y
> y0
&& y
> y1
)
22231 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22237 /* If we don't understand the format, pretend we're not in the hot-spot. */
22242 find_hot_spot (map
, x
, y
)
22246 while (CONSP (map
))
22248 if (CONSP (XCAR (map
))
22249 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22257 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22259 doc
: /* Lookup in image map MAP coordinates X and Y.
22260 An image map is an alist where each element has the format (AREA ID PLIST).
22261 An AREA is specified as either a rectangle, a circle, or a polygon:
22262 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22263 pixel coordinates of the upper left and bottom right corners.
22264 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22265 and the radius of the circle; r may be a float or integer.
22266 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22267 vector describes one corner in the polygon.
22268 Returns the alist element for the first matching AREA in MAP. */)
22279 return find_hot_spot (map
, XINT (x
), XINT (y
));
22283 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22285 define_frame_cursor1 (f
, cursor
, pointer
)
22288 Lisp_Object pointer
;
22290 /* Do not change cursor shape while dragging mouse. */
22291 if (!NILP (do_mouse_tracking
))
22294 if (!NILP (pointer
))
22296 if (EQ (pointer
, Qarrow
))
22297 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22298 else if (EQ (pointer
, Qhand
))
22299 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22300 else if (EQ (pointer
, Qtext
))
22301 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22302 else if (EQ (pointer
, intern ("hdrag")))
22303 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22304 #ifdef HAVE_X_WINDOWS
22305 else if (EQ (pointer
, intern ("vdrag")))
22306 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22308 else if (EQ (pointer
, intern ("hourglass")))
22309 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22310 else if (EQ (pointer
, Qmodeline
))
22311 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22313 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22316 if (cursor
!= No_Cursor
)
22317 rif
->define_frame_cursor (f
, cursor
);
22320 /* Take proper action when mouse has moved to the mode or header line
22321 or marginal area AREA of window W, x-position X and y-position Y.
22322 X is relative to the start of the text display area of W, so the
22323 width of bitmap areas and scroll bars must be subtracted to get a
22324 position relative to the start of the mode line. */
22327 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22328 Lisp_Object window
;
22330 enum window_part area
;
22332 struct window
*w
= XWINDOW (window
);
22333 struct frame
*f
= XFRAME (w
->frame
);
22334 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22335 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22336 Lisp_Object pointer
= Qnil
;
22337 int charpos
, dx
, dy
, width
, height
;
22338 Lisp_Object string
, object
= Qnil
;
22339 Lisp_Object pos
, help
;
22341 Lisp_Object mouse_face
;
22342 int original_x_pixel
= x
;
22343 struct glyph
* glyph
= NULL
;
22344 struct glyph_row
*row
;
22346 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22351 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22352 &object
, &dx
, &dy
, &width
, &height
);
22354 row
= (area
== ON_MODE_LINE
22355 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22356 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22359 if (row
->mode_line_p
&& row
->enabled_p
)
22361 glyph
= row
->glyphs
[TEXT_AREA
];
22362 end
= glyph
+ row
->used
[TEXT_AREA
];
22364 for (x0
= original_x_pixel
;
22365 glyph
< end
&& x0
>= glyph
->pixel_width
;
22367 x0
-= glyph
->pixel_width
;
22375 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22376 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22377 &object
, &dx
, &dy
, &width
, &height
);
22382 if (IMAGEP (object
))
22384 Lisp_Object image_map
, hotspot
;
22385 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22387 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22389 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22391 Lisp_Object area_id
, plist
;
22393 area_id
= XCAR (hotspot
);
22394 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22395 If so, we could look for mouse-enter, mouse-leave
22396 properties in PLIST (and do something...). */
22397 hotspot
= XCDR (hotspot
);
22398 if (CONSP (hotspot
)
22399 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22401 pointer
= Fplist_get (plist
, Qpointer
);
22402 if (NILP (pointer
))
22404 help
= Fplist_get (plist
, Qhelp_echo
);
22407 help_echo_string
= help
;
22408 /* Is this correct? ++kfs */
22409 XSETWINDOW (help_echo_window
, w
);
22410 help_echo_object
= w
->buffer
;
22411 help_echo_pos
= charpos
;
22415 if (NILP (pointer
))
22416 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22419 if (STRINGP (string
))
22421 pos
= make_number (charpos
);
22422 /* If we're on a string with `help-echo' text property, arrange
22423 for the help to be displayed. This is done by setting the
22424 global variable help_echo_string to the help string. */
22427 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22430 help_echo_string
= help
;
22431 XSETWINDOW (help_echo_window
, w
);
22432 help_echo_object
= string
;
22433 help_echo_pos
= charpos
;
22437 if (NILP (pointer
))
22438 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22440 /* Change the mouse pointer according to what is under X/Y. */
22441 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22444 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22445 if (!KEYMAPP (map
))
22446 map
= Fget_text_property (pos
, Qkeymap
, string
);
22447 if (!KEYMAPP (map
))
22448 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22451 /* Change the mouse face according to what is under X/Y. */
22452 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22453 if (!NILP (mouse_face
)
22454 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22459 struct glyph
* tmp_glyph
;
22463 int total_pixel_width
;
22468 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22469 Qmouse_face
, string
, Qnil
);
22471 b
= make_number (0);
22473 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22475 e
= make_number (SCHARS (string
));
22477 /* Calculate the position(glyph position: GPOS) of GLYPH in
22478 displayed string. GPOS is different from CHARPOS.
22480 CHARPOS is the position of glyph in internal string
22481 object. A mode line string format has structures which
22482 is converted to a flatten by emacs lisp interpreter.
22483 The internal string is an element of the structures.
22484 The displayed string is the flatten string. */
22485 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22486 tmp_glyph
->charpos
>= XINT (b
);
22487 tmp_glyph
--, gpos
++)
22489 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22493 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22494 displayed string holding GLYPH.
22496 GSEQ_LENGTH is different from SCHARS (STRING).
22497 SCHARS (STRING) returns the length of the internal string. */
22498 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22499 tmp_glyph
->charpos
< XINT (e
);
22500 tmp_glyph
++, gseq_length
++)
22502 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22506 total_pixel_width
= 0;
22507 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22508 total_pixel_width
+= tmp_glyph
->pixel_width
;
22510 /* Pre calculation of re-rendering position */
22512 hpos
= (area
== ON_MODE_LINE
22513 ? (w
->current_matrix
)->nrows
- 1
22516 /* If the re-rendering position is included in the last
22517 re-rendering area, we should do nothing. */
22518 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22519 && dpyinfo
->mouse_face_beg_col
<= vpos
22520 && vpos
< dpyinfo
->mouse_face_end_col
22521 && dpyinfo
->mouse_face_beg_row
== hpos
)
22524 if (clear_mouse_face (dpyinfo
))
22525 cursor
= No_Cursor
;
22527 dpyinfo
->mouse_face_beg_col
= vpos
;
22528 dpyinfo
->mouse_face_beg_row
= hpos
;
22530 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22531 dpyinfo
->mouse_face_beg_y
= 0;
22533 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22534 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22536 dpyinfo
->mouse_face_end_x
= 0;
22537 dpyinfo
->mouse_face_end_y
= 0;
22539 dpyinfo
->mouse_face_past_end
= 0;
22540 dpyinfo
->mouse_face_window
= window
;
22542 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22545 glyph
->face_id
, 1);
22546 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22548 if (NILP (pointer
))
22551 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22552 clear_mouse_face (dpyinfo
);
22554 define_frame_cursor1 (f
, cursor
, pointer
);
22559 Take proper action when the mouse has moved to position X, Y on
22560 frame F as regards highlighting characters that have mouse-face
22561 properties. Also de-highlighting chars where the mouse was before.
22562 X and Y can be negative or out of range. */
22565 note_mouse_highlight (f
, x
, y
)
22569 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22570 enum window_part part
;
22571 Lisp_Object window
;
22573 Cursor cursor
= No_Cursor
;
22574 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22577 /* When a menu is active, don't highlight because this looks odd. */
22578 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22579 if (popup_activated ())
22583 if (NILP (Vmouse_highlight
)
22584 || !f
->glyphs_initialized_p
)
22587 dpyinfo
->mouse_face_mouse_x
= x
;
22588 dpyinfo
->mouse_face_mouse_y
= y
;
22589 dpyinfo
->mouse_face_mouse_frame
= f
;
22591 if (dpyinfo
->mouse_face_defer
)
22594 if (gc_in_progress
)
22596 dpyinfo
->mouse_face_deferred_gc
= 1;
22600 /* Which window is that in? */
22601 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22603 /* If we were displaying active text in another window, clear that.
22604 Also clear if we move out of text area in same window. */
22605 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22606 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22607 && !NILP (dpyinfo
->mouse_face_window
)))
22608 clear_mouse_face (dpyinfo
);
22610 /* Not on a window -> return. */
22611 if (!WINDOWP (window
))
22614 /* Reset help_echo_string. It will get recomputed below. */
22615 help_echo_string
= Qnil
;
22617 /* Convert to window-relative pixel coordinates. */
22618 w
= XWINDOW (window
);
22619 frame_to_window_pixel_xy (w
, &x
, &y
);
22621 /* Handle tool-bar window differently since it doesn't display a
22623 if (EQ (window
, f
->tool_bar_window
))
22625 note_tool_bar_highlight (f
, x
, y
);
22629 /* Mouse is on the mode, header line or margin? */
22630 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22631 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22633 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22637 if (part
== ON_VERTICAL_BORDER
)
22639 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22640 help_echo_string
= build_string ("drag-mouse-1: resize");
22642 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22643 || part
== ON_SCROLL_BAR
)
22644 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22646 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22648 /* Are we in a window whose display is up to date?
22649 And verify the buffer's text has not changed. */
22650 b
= XBUFFER (w
->buffer
);
22651 if (part
== ON_TEXT
22652 && EQ (w
->window_end_valid
, w
->buffer
)
22653 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22654 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22656 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22657 struct glyph
*glyph
;
22658 Lisp_Object object
;
22659 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22660 Lisp_Object
*overlay_vec
= NULL
;
22662 struct buffer
*obuf
;
22663 int obegv
, ozv
, same_region
;
22665 /* Find the glyph under X/Y. */
22666 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22668 /* Look for :pointer property on image. */
22669 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22671 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22672 if (img
!= NULL
&& IMAGEP (img
->spec
))
22674 Lisp_Object image_map
, hotspot
;
22675 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22677 && (hotspot
= find_hot_spot (image_map
,
22678 glyph
->slice
.x
+ dx
,
22679 glyph
->slice
.y
+ dy
),
22681 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22683 Lisp_Object area_id
, plist
;
22685 area_id
= XCAR (hotspot
);
22686 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22687 If so, we could look for mouse-enter, mouse-leave
22688 properties in PLIST (and do something...). */
22689 hotspot
= XCDR (hotspot
);
22690 if (CONSP (hotspot
)
22691 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22693 pointer
= Fplist_get (plist
, Qpointer
);
22694 if (NILP (pointer
))
22696 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22697 if (!NILP (help_echo_string
))
22699 help_echo_window
= window
;
22700 help_echo_object
= glyph
->object
;
22701 help_echo_pos
= glyph
->charpos
;
22705 if (NILP (pointer
))
22706 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22710 /* Clear mouse face if X/Y not over text. */
22712 || area
!= TEXT_AREA
22713 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22715 if (clear_mouse_face (dpyinfo
))
22716 cursor
= No_Cursor
;
22717 if (NILP (pointer
))
22719 if (area
!= TEXT_AREA
)
22720 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22722 pointer
= Vvoid_text_area_pointer
;
22727 pos
= glyph
->charpos
;
22728 object
= glyph
->object
;
22729 if (!STRINGP (object
) && !BUFFERP (object
))
22732 /* If we get an out-of-range value, return now; avoid an error. */
22733 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22736 /* Make the window's buffer temporarily current for
22737 overlays_at and compute_char_face. */
22738 obuf
= current_buffer
;
22739 current_buffer
= b
;
22745 /* Is this char mouse-active or does it have help-echo? */
22746 position
= make_number (pos
);
22748 if (BUFFERP (object
))
22750 /* Put all the overlays we want in a vector in overlay_vec. */
22751 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22752 /* Sort overlays into increasing priority order. */
22753 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22758 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22759 && vpos
>= dpyinfo
->mouse_face_beg_row
22760 && vpos
<= dpyinfo
->mouse_face_end_row
22761 && (vpos
> dpyinfo
->mouse_face_beg_row
22762 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22763 && (vpos
< dpyinfo
->mouse_face_end_row
22764 || hpos
< dpyinfo
->mouse_face_end_col
22765 || dpyinfo
->mouse_face_past_end
));
22768 cursor
= No_Cursor
;
22770 /* Check mouse-face highlighting. */
22772 /* If there exists an overlay with mouse-face overlapping
22773 the one we are currently highlighting, we have to
22774 check if we enter the overlapping overlay, and then
22775 highlight only that. */
22776 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22777 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22779 /* Find the highest priority overlay that has a mouse-face
22782 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22784 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22785 if (!NILP (mouse_face
))
22786 overlay
= overlay_vec
[i
];
22789 /* If we're actually highlighting the same overlay as
22790 before, there's no need to do that again. */
22791 if (!NILP (overlay
)
22792 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22793 goto check_help_echo
;
22795 dpyinfo
->mouse_face_overlay
= overlay
;
22797 /* Clear the display of the old active region, if any. */
22798 if (clear_mouse_face (dpyinfo
))
22799 cursor
= No_Cursor
;
22801 /* If no overlay applies, get a text property. */
22802 if (NILP (overlay
))
22803 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22805 /* Handle the overlay case. */
22806 if (!NILP (overlay
))
22808 /* Find the range of text around this char that
22809 should be active. */
22810 Lisp_Object before
, after
;
22813 before
= Foverlay_start (overlay
);
22814 after
= Foverlay_end (overlay
);
22815 /* Record this as the current active region. */
22816 fast_find_position (w
, XFASTINT (before
),
22817 &dpyinfo
->mouse_face_beg_col
,
22818 &dpyinfo
->mouse_face_beg_row
,
22819 &dpyinfo
->mouse_face_beg_x
,
22820 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22822 dpyinfo
->mouse_face_past_end
22823 = !fast_find_position (w
, XFASTINT (after
),
22824 &dpyinfo
->mouse_face_end_col
,
22825 &dpyinfo
->mouse_face_end_row
,
22826 &dpyinfo
->mouse_face_end_x
,
22827 &dpyinfo
->mouse_face_end_y
, Qnil
);
22828 dpyinfo
->mouse_face_window
= window
;
22830 dpyinfo
->mouse_face_face_id
22831 = face_at_buffer_position (w
, pos
, 0, 0,
22833 !dpyinfo
->mouse_face_hidden
);
22835 /* Display it as active. */
22836 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22837 cursor
= No_Cursor
;
22839 /* Handle the text property case. */
22840 else if (!NILP (mouse_face
) && BUFFERP (object
))
22842 /* Find the range of text around this char that
22843 should be active. */
22844 Lisp_Object before
, after
, beginning
, end
;
22847 beginning
= Fmarker_position (w
->start
);
22848 end
= make_number (BUF_Z (XBUFFER (object
))
22849 - XFASTINT (w
->window_end_pos
));
22851 = Fprevious_single_property_change (make_number (pos
+ 1),
22853 object
, beginning
);
22855 = Fnext_single_property_change (position
, Qmouse_face
,
22858 /* Record this as the current active region. */
22859 fast_find_position (w
, XFASTINT (before
),
22860 &dpyinfo
->mouse_face_beg_col
,
22861 &dpyinfo
->mouse_face_beg_row
,
22862 &dpyinfo
->mouse_face_beg_x
,
22863 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22864 dpyinfo
->mouse_face_past_end
22865 = !fast_find_position (w
, XFASTINT (after
),
22866 &dpyinfo
->mouse_face_end_col
,
22867 &dpyinfo
->mouse_face_end_row
,
22868 &dpyinfo
->mouse_face_end_x
,
22869 &dpyinfo
->mouse_face_end_y
, Qnil
);
22870 dpyinfo
->mouse_face_window
= window
;
22872 if (BUFFERP (object
))
22873 dpyinfo
->mouse_face_face_id
22874 = face_at_buffer_position (w
, pos
, 0, 0,
22876 !dpyinfo
->mouse_face_hidden
);
22878 /* Display it as active. */
22879 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22880 cursor
= No_Cursor
;
22882 else if (!NILP (mouse_face
) && STRINGP (object
))
22887 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22890 e
= Fnext_single_property_change (position
, Qmouse_face
,
22893 b
= make_number (0);
22895 e
= make_number (SCHARS (object
) - 1);
22897 fast_find_string_pos (w
, XINT (b
), object
,
22898 &dpyinfo
->mouse_face_beg_col
,
22899 &dpyinfo
->mouse_face_beg_row
,
22900 &dpyinfo
->mouse_face_beg_x
,
22901 &dpyinfo
->mouse_face_beg_y
, 0);
22902 fast_find_string_pos (w
, XINT (e
), object
,
22903 &dpyinfo
->mouse_face_end_col
,
22904 &dpyinfo
->mouse_face_end_row
,
22905 &dpyinfo
->mouse_face_end_x
,
22906 &dpyinfo
->mouse_face_end_y
, 1);
22907 dpyinfo
->mouse_face_past_end
= 0;
22908 dpyinfo
->mouse_face_window
= window
;
22909 dpyinfo
->mouse_face_face_id
22910 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22911 glyph
->face_id
, 1);
22912 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22913 cursor
= No_Cursor
;
22915 else if (STRINGP (object
) && NILP (mouse_face
))
22917 /* A string which doesn't have mouse-face, but
22918 the text ``under'' it might have. */
22919 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22920 int start
= MATRIX_ROW_START_CHARPOS (r
);
22922 pos
= string_buffer_position (w
, object
, start
);
22924 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22928 if (!NILP (mouse_face
) && !NILP (overlay
))
22930 Lisp_Object before
= Foverlay_start (overlay
);
22931 Lisp_Object after
= Foverlay_end (overlay
);
22934 /* Note that we might not be able to find position
22935 BEFORE in the glyph matrix if the overlay is
22936 entirely covered by a `display' property. In
22937 this case, we overshoot. So let's stop in
22938 the glyph matrix before glyphs for OBJECT. */
22939 fast_find_position (w
, XFASTINT (before
),
22940 &dpyinfo
->mouse_face_beg_col
,
22941 &dpyinfo
->mouse_face_beg_row
,
22942 &dpyinfo
->mouse_face_beg_x
,
22943 &dpyinfo
->mouse_face_beg_y
,
22946 dpyinfo
->mouse_face_past_end
22947 = !fast_find_position (w
, XFASTINT (after
),
22948 &dpyinfo
->mouse_face_end_col
,
22949 &dpyinfo
->mouse_face_end_row
,
22950 &dpyinfo
->mouse_face_end_x
,
22951 &dpyinfo
->mouse_face_end_y
,
22953 dpyinfo
->mouse_face_window
= window
;
22954 dpyinfo
->mouse_face_face_id
22955 = face_at_buffer_position (w
, pos
, 0, 0,
22957 !dpyinfo
->mouse_face_hidden
);
22959 /* Display it as active. */
22960 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22961 cursor
= No_Cursor
;
22968 /* Look for a `help-echo' property. */
22969 if (NILP (help_echo_string
)) {
22970 Lisp_Object help
, overlay
;
22972 /* Check overlays first. */
22973 help
= overlay
= Qnil
;
22974 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22976 overlay
= overlay_vec
[i
];
22977 help
= Foverlay_get (overlay
, Qhelp_echo
);
22982 help_echo_string
= help
;
22983 help_echo_window
= window
;
22984 help_echo_object
= overlay
;
22985 help_echo_pos
= pos
;
22989 Lisp_Object object
= glyph
->object
;
22990 int charpos
= glyph
->charpos
;
22992 /* Try text properties. */
22993 if (STRINGP (object
)
22995 && charpos
< SCHARS (object
))
22997 help
= Fget_text_property (make_number (charpos
),
22998 Qhelp_echo
, object
);
23001 /* If the string itself doesn't specify a help-echo,
23002 see if the buffer text ``under'' it does. */
23003 struct glyph_row
*r
23004 = MATRIX_ROW (w
->current_matrix
, vpos
);
23005 int start
= MATRIX_ROW_START_CHARPOS (r
);
23006 int pos
= string_buffer_position (w
, object
, start
);
23009 help
= Fget_char_property (make_number (pos
),
23010 Qhelp_echo
, w
->buffer
);
23014 object
= w
->buffer
;
23019 else if (BUFFERP (object
)
23022 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23027 help_echo_string
= help
;
23028 help_echo_window
= window
;
23029 help_echo_object
= object
;
23030 help_echo_pos
= charpos
;
23035 /* Look for a `pointer' property. */
23036 if (NILP (pointer
))
23038 /* Check overlays first. */
23039 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23040 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23042 if (NILP (pointer
))
23044 Lisp_Object object
= glyph
->object
;
23045 int charpos
= glyph
->charpos
;
23047 /* Try text properties. */
23048 if (STRINGP (object
)
23050 && charpos
< SCHARS (object
))
23052 pointer
= Fget_text_property (make_number (charpos
),
23054 if (NILP (pointer
))
23056 /* If the string itself doesn't specify a pointer,
23057 see if the buffer text ``under'' it does. */
23058 struct glyph_row
*r
23059 = MATRIX_ROW (w
->current_matrix
, vpos
);
23060 int start
= MATRIX_ROW_START_CHARPOS (r
);
23061 int pos
= string_buffer_position (w
, object
, start
);
23063 pointer
= Fget_char_property (make_number (pos
),
23064 Qpointer
, w
->buffer
);
23067 else if (BUFFERP (object
)
23070 pointer
= Fget_text_property (make_number (charpos
),
23077 current_buffer
= obuf
;
23082 define_frame_cursor1 (f
, cursor
, pointer
);
23087 Clear any mouse-face on window W. This function is part of the
23088 redisplay interface, and is called from try_window_id and similar
23089 functions to ensure the mouse-highlight is off. */
23092 x_clear_window_mouse_face (w
)
23095 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23096 Lisp_Object window
;
23099 XSETWINDOW (window
, w
);
23100 if (EQ (window
, dpyinfo
->mouse_face_window
))
23101 clear_mouse_face (dpyinfo
);
23107 Just discard the mouse face information for frame F, if any.
23108 This is used when the size of F is changed. */
23111 cancel_mouse_face (f
)
23114 Lisp_Object window
;
23115 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23117 window
= dpyinfo
->mouse_face_window
;
23118 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23120 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23121 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23122 dpyinfo
->mouse_face_window
= Qnil
;
23127 #endif /* HAVE_WINDOW_SYSTEM */
23130 /***********************************************************************
23132 ***********************************************************************/
23134 #ifdef HAVE_WINDOW_SYSTEM
23136 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23137 which intersects rectangle R. R is in window-relative coordinates. */
23140 expose_area (w
, row
, r
, area
)
23142 struct glyph_row
*row
;
23144 enum glyph_row_area area
;
23146 struct glyph
*first
= row
->glyphs
[area
];
23147 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23148 struct glyph
*last
;
23149 int first_x
, start_x
, x
;
23151 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23152 /* If row extends face to end of line write the whole line. */
23153 draw_glyphs (w
, 0, row
, area
,
23154 0, row
->used
[area
],
23155 DRAW_NORMAL_TEXT
, 0);
23158 /* Set START_X to the window-relative start position for drawing glyphs of
23159 AREA. The first glyph of the text area can be partially visible.
23160 The first glyphs of other areas cannot. */
23161 start_x
= window_box_left_offset (w
, area
);
23163 if (area
== TEXT_AREA
)
23166 /* Find the first glyph that must be redrawn. */
23168 && x
+ first
->pixel_width
< r
->x
)
23170 x
+= first
->pixel_width
;
23174 /* Find the last one. */
23178 && x
< r
->x
+ r
->width
)
23180 x
+= last
->pixel_width
;
23186 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23187 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23188 DRAW_NORMAL_TEXT
, 0);
23193 /* Redraw the parts of the glyph row ROW on window W intersecting
23194 rectangle R. R is in window-relative coordinates. Value is
23195 non-zero if mouse-face was overwritten. */
23198 expose_line (w
, row
, r
)
23200 struct glyph_row
*row
;
23203 xassert (row
->enabled_p
);
23205 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23206 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23207 0, row
->used
[TEXT_AREA
],
23208 DRAW_NORMAL_TEXT
, 0);
23211 if (row
->used
[LEFT_MARGIN_AREA
])
23212 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23213 if (row
->used
[TEXT_AREA
])
23214 expose_area (w
, row
, r
, TEXT_AREA
);
23215 if (row
->used
[RIGHT_MARGIN_AREA
])
23216 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23217 draw_row_fringe_bitmaps (w
, row
);
23220 return row
->mouse_face_p
;
23224 /* Redraw those parts of glyphs rows during expose event handling that
23225 overlap other rows. Redrawing of an exposed line writes over parts
23226 of lines overlapping that exposed line; this function fixes that.
23228 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23229 row in W's current matrix that is exposed and overlaps other rows.
23230 LAST_OVERLAPPING_ROW is the last such row. */
23233 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23235 struct glyph_row
*first_overlapping_row
;
23236 struct glyph_row
*last_overlapping_row
;
23238 struct glyph_row
*row
;
23240 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23241 if (row
->overlapping_p
)
23243 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23245 if (row
->used
[LEFT_MARGIN_AREA
])
23246 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23248 if (row
->used
[TEXT_AREA
])
23249 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23251 if (row
->used
[RIGHT_MARGIN_AREA
])
23252 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23257 /* Return non-zero if W's cursor intersects rectangle R. */
23260 phys_cursor_in_rect_p (w
, r
)
23264 XRectangle cr
, result
;
23265 struct glyph
*cursor_glyph
;
23267 cursor_glyph
= get_phys_cursor_glyph (w
);
23270 /* r is relative to W's box, but w->phys_cursor.x is relative
23271 to left edge of W's TEXT area. Adjust it. */
23272 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23273 cr
.y
= w
->phys_cursor
.y
;
23274 cr
.width
= cursor_glyph
->pixel_width
;
23275 cr
.height
= w
->phys_cursor_height
;
23276 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23277 I assume the effect is the same -- and this is portable. */
23278 return x_intersect_rectangles (&cr
, r
, &result
);
23286 Draw a vertical window border to the right of window W if W doesn't
23287 have vertical scroll bars. */
23290 x_draw_vertical_border (w
)
23293 /* We could do better, if we knew what type of scroll-bar the adjacent
23294 windows (on either side) have... But we don't :-(
23295 However, I think this works ok. ++KFS 2003-04-25 */
23297 /* Redraw borders between horizontally adjacent windows. Don't
23298 do it for frames with vertical scroll bars because either the
23299 right scroll bar of a window, or the left scroll bar of its
23300 neighbor will suffice as a border. */
23301 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23304 if (!WINDOW_RIGHTMOST_P (w
)
23305 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23307 int x0
, x1
, y0
, y1
;
23309 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23312 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23315 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23317 else if (!WINDOW_LEFTMOST_P (w
)
23318 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23320 int x0
, x1
, y0
, y1
;
23322 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23325 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23328 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23333 /* Redraw the part of window W intersection rectangle FR. Pixel
23334 coordinates in FR are frame-relative. Call this function with
23335 input blocked. Value is non-zero if the exposure overwrites
23339 expose_window (w
, fr
)
23343 struct frame
*f
= XFRAME (w
->frame
);
23345 int mouse_face_overwritten_p
= 0;
23347 /* If window is not yet fully initialized, do nothing. This can
23348 happen when toolkit scroll bars are used and a window is split.
23349 Reconfiguring the scroll bar will generate an expose for a newly
23351 if (w
->current_matrix
== NULL
)
23354 /* When we're currently updating the window, display and current
23355 matrix usually don't agree. Arrange for a thorough display
23357 if (w
== updated_window
)
23359 SET_FRAME_GARBAGED (f
);
23363 /* Frame-relative pixel rectangle of W. */
23364 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23365 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23366 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23367 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23369 if (x_intersect_rectangles (fr
, &wr
, &r
))
23371 int yb
= window_text_bottom_y (w
);
23372 struct glyph_row
*row
;
23373 int cursor_cleared_p
;
23374 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23376 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23377 r
.x
, r
.y
, r
.width
, r
.height
));
23379 /* Convert to window coordinates. */
23380 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23381 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23383 /* Turn off the cursor. */
23384 if (!w
->pseudo_window_p
23385 && phys_cursor_in_rect_p (w
, &r
))
23387 x_clear_cursor (w
);
23388 cursor_cleared_p
= 1;
23391 cursor_cleared_p
= 0;
23393 /* Update lines intersecting rectangle R. */
23394 first_overlapping_row
= last_overlapping_row
= NULL
;
23395 for (row
= w
->current_matrix
->rows
;
23400 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23402 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23403 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23404 || (r
.y
>= y0
&& r
.y
< y1
)
23405 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23407 /* A header line may be overlapping, but there is no need
23408 to fix overlapping areas for them. KFS 2005-02-12 */
23409 if (row
->overlapping_p
&& !row
->mode_line_p
)
23411 if (first_overlapping_row
== NULL
)
23412 first_overlapping_row
= row
;
23413 last_overlapping_row
= row
;
23416 if (expose_line (w
, row
, &r
))
23417 mouse_face_overwritten_p
= 1;
23424 /* Display the mode line if there is one. */
23425 if (WINDOW_WANTS_MODELINE_P (w
)
23426 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23428 && row
->y
< r
.y
+ r
.height
)
23430 if (expose_line (w
, row
, &r
))
23431 mouse_face_overwritten_p
= 1;
23434 if (!w
->pseudo_window_p
)
23436 /* Fix the display of overlapping rows. */
23437 if (first_overlapping_row
)
23438 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23440 /* Draw border between windows. */
23441 x_draw_vertical_border (w
);
23443 /* Turn the cursor on again. */
23444 if (cursor_cleared_p
)
23445 update_window_cursor (w
, 1);
23449 return mouse_face_overwritten_p
;
23454 /* Redraw (parts) of all windows in the window tree rooted at W that
23455 intersect R. R contains frame pixel coordinates. Value is
23456 non-zero if the exposure overwrites mouse-face. */
23459 expose_window_tree (w
, r
)
23463 struct frame
*f
= XFRAME (w
->frame
);
23464 int mouse_face_overwritten_p
= 0;
23466 while (w
&& !FRAME_GARBAGED_P (f
))
23468 if (!NILP (w
->hchild
))
23469 mouse_face_overwritten_p
23470 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23471 else if (!NILP (w
->vchild
))
23472 mouse_face_overwritten_p
23473 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23475 mouse_face_overwritten_p
|= expose_window (w
, r
);
23477 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23480 return mouse_face_overwritten_p
;
23485 Redisplay an exposed area of frame F. X and Y are the upper-left
23486 corner of the exposed rectangle. W and H are width and height of
23487 the exposed area. All are pixel values. W or H zero means redraw
23488 the entire frame. */
23491 expose_frame (f
, x
, y
, w
, h
)
23496 int mouse_face_overwritten_p
= 0;
23498 TRACE ((stderr
, "expose_frame "));
23500 /* No need to redraw if frame will be redrawn soon. */
23501 if (FRAME_GARBAGED_P (f
))
23503 TRACE ((stderr
, " garbaged\n"));
23507 /* If basic faces haven't been realized yet, there is no point in
23508 trying to redraw anything. This can happen when we get an expose
23509 event while Emacs is starting, e.g. by moving another window. */
23510 if (FRAME_FACE_CACHE (f
) == NULL
23511 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23513 TRACE ((stderr
, " no faces\n"));
23517 if (w
== 0 || h
== 0)
23520 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23521 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23531 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23532 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23534 if (WINDOWP (f
->tool_bar_window
))
23535 mouse_face_overwritten_p
23536 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23538 #ifdef HAVE_X_WINDOWS
23540 #ifndef USE_X_TOOLKIT
23541 if (WINDOWP (f
->menu_bar_window
))
23542 mouse_face_overwritten_p
23543 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23544 #endif /* not USE_X_TOOLKIT */
23548 /* Some window managers support a focus-follows-mouse style with
23549 delayed raising of frames. Imagine a partially obscured frame,
23550 and moving the mouse into partially obscured mouse-face on that
23551 frame. The visible part of the mouse-face will be highlighted,
23552 then the WM raises the obscured frame. With at least one WM, KDE
23553 2.1, Emacs is not getting any event for the raising of the frame
23554 (even tried with SubstructureRedirectMask), only Expose events.
23555 These expose events will draw text normally, i.e. not
23556 highlighted. Which means we must redo the highlight here.
23557 Subsume it under ``we love X''. --gerd 2001-08-15 */
23558 /* Included in Windows version because Windows most likely does not
23559 do the right thing if any third party tool offers
23560 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23561 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23563 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23564 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23566 int x
= dpyinfo
->mouse_face_mouse_x
;
23567 int y
= dpyinfo
->mouse_face_mouse_y
;
23568 clear_mouse_face (dpyinfo
);
23569 note_mouse_highlight (f
, x
, y
);
23576 Determine the intersection of two rectangles R1 and R2. Return
23577 the intersection in *RESULT. Value is non-zero if RESULT is not
23581 x_intersect_rectangles (r1
, r2
, result
)
23582 XRectangle
*r1
, *r2
, *result
;
23584 XRectangle
*left
, *right
;
23585 XRectangle
*upper
, *lower
;
23586 int intersection_p
= 0;
23588 /* Rearrange so that R1 is the left-most rectangle. */
23590 left
= r1
, right
= r2
;
23592 left
= r2
, right
= r1
;
23594 /* X0 of the intersection is right.x0, if this is inside R1,
23595 otherwise there is no intersection. */
23596 if (right
->x
<= left
->x
+ left
->width
)
23598 result
->x
= right
->x
;
23600 /* The right end of the intersection is the minimum of the
23601 the right ends of left and right. */
23602 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23605 /* Same game for Y. */
23607 upper
= r1
, lower
= r2
;
23609 upper
= r2
, lower
= r1
;
23611 /* The upper end of the intersection is lower.y0, if this is inside
23612 of upper. Otherwise, there is no intersection. */
23613 if (lower
->y
<= upper
->y
+ upper
->height
)
23615 result
->y
= lower
->y
;
23617 /* The lower end of the intersection is the minimum of the lower
23618 ends of upper and lower. */
23619 result
->height
= (min (lower
->y
+ lower
->height
,
23620 upper
->y
+ upper
->height
)
23622 intersection_p
= 1;
23626 return intersection_p
;
23629 #endif /* HAVE_WINDOW_SYSTEM */
23632 /***********************************************************************
23634 ***********************************************************************/
23639 Vwith_echo_area_save_vector
= Qnil
;
23640 staticpro (&Vwith_echo_area_save_vector
);
23642 Vmessage_stack
= Qnil
;
23643 staticpro (&Vmessage_stack
);
23645 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23646 staticpro (&Qinhibit_redisplay
);
23648 message_dolog_marker1
= Fmake_marker ();
23649 staticpro (&message_dolog_marker1
);
23650 message_dolog_marker2
= Fmake_marker ();
23651 staticpro (&message_dolog_marker2
);
23652 message_dolog_marker3
= Fmake_marker ();
23653 staticpro (&message_dolog_marker3
);
23656 defsubr (&Sdump_frame_glyph_matrix
);
23657 defsubr (&Sdump_glyph_matrix
);
23658 defsubr (&Sdump_glyph_row
);
23659 defsubr (&Sdump_tool_bar_row
);
23660 defsubr (&Strace_redisplay
);
23661 defsubr (&Strace_to_stderr
);
23663 #ifdef HAVE_WINDOW_SYSTEM
23664 defsubr (&Stool_bar_lines_needed
);
23665 defsubr (&Slookup_image_map
);
23667 defsubr (&Sformat_mode_line
);
23669 staticpro (&Qmenu_bar_update_hook
);
23670 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23672 staticpro (&Qoverriding_terminal_local_map
);
23673 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23675 staticpro (&Qoverriding_local_map
);
23676 Qoverriding_local_map
= intern ("overriding-local-map");
23678 staticpro (&Qwindow_scroll_functions
);
23679 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23681 staticpro (&Qredisplay_end_trigger_functions
);
23682 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23684 staticpro (&Qinhibit_point_motion_hooks
);
23685 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23687 QCdata
= intern (":data");
23688 staticpro (&QCdata
);
23689 Qdisplay
= intern ("display");
23690 staticpro (&Qdisplay
);
23691 Qspace_width
= intern ("space-width");
23692 staticpro (&Qspace_width
);
23693 Qraise
= intern ("raise");
23694 staticpro (&Qraise
);
23695 Qslice
= intern ("slice");
23696 staticpro (&Qslice
);
23697 Qspace
= intern ("space");
23698 staticpro (&Qspace
);
23699 Qmargin
= intern ("margin");
23700 staticpro (&Qmargin
);
23701 Qpointer
= intern ("pointer");
23702 staticpro (&Qpointer
);
23703 Qleft_margin
= intern ("left-margin");
23704 staticpro (&Qleft_margin
);
23705 Qright_margin
= intern ("right-margin");
23706 staticpro (&Qright_margin
);
23707 Qcenter
= intern ("center");
23708 staticpro (&Qcenter
);
23709 Qline_height
= intern ("line-height");
23710 staticpro (&Qline_height
);
23711 QCalign_to
= intern (":align-to");
23712 staticpro (&QCalign_to
);
23713 QCrelative_width
= intern (":relative-width");
23714 staticpro (&QCrelative_width
);
23715 QCrelative_height
= intern (":relative-height");
23716 staticpro (&QCrelative_height
);
23717 QCeval
= intern (":eval");
23718 staticpro (&QCeval
);
23719 QCpropertize
= intern (":propertize");
23720 staticpro (&QCpropertize
);
23721 QCfile
= intern (":file");
23722 staticpro (&QCfile
);
23723 Qfontified
= intern ("fontified");
23724 staticpro (&Qfontified
);
23725 Qfontification_functions
= intern ("fontification-functions");
23726 staticpro (&Qfontification_functions
);
23727 Qtrailing_whitespace
= intern ("trailing-whitespace");
23728 staticpro (&Qtrailing_whitespace
);
23729 Qescape_glyph
= intern ("escape-glyph");
23730 staticpro (&Qescape_glyph
);
23731 Qnobreak_space
= intern ("nobreak-space");
23732 staticpro (&Qnobreak_space
);
23733 Qimage
= intern ("image");
23734 staticpro (&Qimage
);
23735 QCmap
= intern (":map");
23736 staticpro (&QCmap
);
23737 QCpointer
= intern (":pointer");
23738 staticpro (&QCpointer
);
23739 Qrect
= intern ("rect");
23740 staticpro (&Qrect
);
23741 Qcircle
= intern ("circle");
23742 staticpro (&Qcircle
);
23743 Qpoly
= intern ("poly");
23744 staticpro (&Qpoly
);
23745 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23746 staticpro (&Qmessage_truncate_lines
);
23747 Qgrow_only
= intern ("grow-only");
23748 staticpro (&Qgrow_only
);
23749 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23750 staticpro (&Qinhibit_menubar_update
);
23751 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23752 staticpro (&Qinhibit_eval_during_redisplay
);
23753 Qposition
= intern ("position");
23754 staticpro (&Qposition
);
23755 Qbuffer_position
= intern ("buffer-position");
23756 staticpro (&Qbuffer_position
);
23757 Qobject
= intern ("object");
23758 staticpro (&Qobject
);
23759 Qbar
= intern ("bar");
23761 Qhbar
= intern ("hbar");
23762 staticpro (&Qhbar
);
23763 Qbox
= intern ("box");
23765 Qhollow
= intern ("hollow");
23766 staticpro (&Qhollow
);
23767 Qhand
= intern ("hand");
23768 staticpro (&Qhand
);
23769 Qarrow
= intern ("arrow");
23770 staticpro (&Qarrow
);
23771 Qtext
= intern ("text");
23772 staticpro (&Qtext
);
23773 Qrisky_local_variable
= intern ("risky-local-variable");
23774 staticpro (&Qrisky_local_variable
);
23775 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23776 staticpro (&Qinhibit_free_realized_faces
);
23778 list_of_error
= Fcons (Fcons (intern ("error"),
23779 Fcons (intern ("void-variable"), Qnil
)),
23781 staticpro (&list_of_error
);
23783 Qlast_arrow_position
= intern ("last-arrow-position");
23784 staticpro (&Qlast_arrow_position
);
23785 Qlast_arrow_string
= intern ("last-arrow-string");
23786 staticpro (&Qlast_arrow_string
);
23788 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23789 staticpro (&Qoverlay_arrow_string
);
23790 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23791 staticpro (&Qoverlay_arrow_bitmap
);
23793 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23794 staticpro (&echo_buffer
[0]);
23795 staticpro (&echo_buffer
[1]);
23797 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23798 staticpro (&echo_area_buffer
[0]);
23799 staticpro (&echo_area_buffer
[1]);
23801 Vmessages_buffer_name
= build_string ("*Messages*");
23802 staticpro (&Vmessages_buffer_name
);
23804 mode_line_proptrans_alist
= Qnil
;
23805 staticpro (&mode_line_proptrans_alist
);
23806 mode_line_string_list
= Qnil
;
23807 staticpro (&mode_line_string_list
);
23808 mode_line_string_face
= Qnil
;
23809 staticpro (&mode_line_string_face
);
23810 mode_line_string_face_prop
= Qnil
;
23811 staticpro (&mode_line_string_face_prop
);
23812 Vmode_line_unwind_vector
= Qnil
;
23813 staticpro (&Vmode_line_unwind_vector
);
23815 help_echo_string
= Qnil
;
23816 staticpro (&help_echo_string
);
23817 help_echo_object
= Qnil
;
23818 staticpro (&help_echo_object
);
23819 help_echo_window
= Qnil
;
23820 staticpro (&help_echo_window
);
23821 previous_help_echo_string
= Qnil
;
23822 staticpro (&previous_help_echo_string
);
23823 help_echo_pos
= -1;
23825 #ifdef HAVE_WINDOW_SYSTEM
23826 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23827 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23828 For example, if a block cursor is over a tab, it will be drawn as
23829 wide as that tab on the display. */);
23830 x_stretch_cursor_p
= 0;
23833 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23834 doc
: /* *Non-nil means highlight trailing whitespace.
23835 The face used for trailing whitespace is `trailing-whitespace'. */);
23836 Vshow_trailing_whitespace
= Qnil
;
23838 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23839 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23840 A value of t means highlight the character itself (for nobreak space,
23841 use face `nobreak-space').
23842 A value of nil means no highlighting.
23843 Other values mean display the escape glyph followed by an ordinary
23844 space or ordinary hyphen. */);
23845 Vnobreak_char_display
= Qt
;
23847 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23848 doc
: /* *The pointer shape to show in void text areas.
23849 A value of nil means to show the text pointer. Other options are `arrow',
23850 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23851 Vvoid_text_area_pointer
= Qarrow
;
23853 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23854 doc
: /* Non-nil means don't actually do any redisplay.
23855 This is used for internal purposes. */);
23856 Vinhibit_redisplay
= Qnil
;
23858 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23859 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23860 Vglobal_mode_string
= Qnil
;
23862 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23863 doc
: /* Marker for where to display an arrow on top of the buffer text.
23864 This must be the beginning of a line in order to work.
23865 See also `overlay-arrow-string'. */);
23866 Voverlay_arrow_position
= Qnil
;
23868 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23869 doc
: /* String to display as an arrow in non-window frames.
23870 See also `overlay-arrow-position'. */);
23871 Voverlay_arrow_string
= build_string ("=>");
23873 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23874 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23875 The symbols on this list are examined during redisplay to determine
23876 where to display overlay arrows. */);
23877 Voverlay_arrow_variable_list
23878 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23880 DEFVAR_INT ("scroll-step", &scroll_step
,
23881 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23882 If that fails to bring point back on frame, point is centered instead.
23883 If this is zero, point is always centered after it moves off frame.
23884 If you want scrolling to always be a line at a time, you should set
23885 `scroll-conservatively' to a large value rather than set this to 1. */);
23887 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23888 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23889 A value of zero means to scroll the text to center point vertically
23890 in the window. */);
23891 scroll_conservatively
= 0;
23893 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23894 doc
: /* *Number of lines of margin at the top and bottom of a window.
23895 Recenter the window whenever point gets within this many lines
23896 of the top or bottom of the window. */);
23899 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23900 doc
: /* Pixels per inch value for non-window system displays.
23901 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23902 Vdisplay_pixels_per_inch
= make_float (72.0);
23905 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23908 DEFVAR_BOOL ("truncate-partial-width-windows",
23909 &truncate_partial_width_windows
,
23910 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23911 truncate_partial_width_windows
= 1;
23913 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23914 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23915 Any other value means to use the appropriate face, `mode-line',
23916 `header-line', or `menu' respectively. */);
23917 mode_line_inverse_video
= 1;
23919 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23920 doc
: /* *Maximum buffer size for which line number should be displayed.
23921 If the buffer is bigger than this, the line number does not appear
23922 in the mode line. A value of nil means no limit. */);
23923 Vline_number_display_limit
= Qnil
;
23925 DEFVAR_INT ("line-number-display-limit-width",
23926 &line_number_display_limit_width
,
23927 doc
: /* *Maximum line width (in characters) for line number display.
23928 If the average length of the lines near point is bigger than this, then the
23929 line number may be omitted from the mode line. */);
23930 line_number_display_limit_width
= 200;
23932 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23933 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23934 highlight_nonselected_windows
= 0;
23936 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23937 doc
: /* Non-nil if more than one frame is visible on this display.
23938 Minibuffer-only frames don't count, but iconified frames do.
23939 This variable is not guaranteed to be accurate except while processing
23940 `frame-title-format' and `icon-title-format'. */);
23942 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23943 doc
: /* Template for displaying the title bar of visible frames.
23944 \(Assuming the window manager supports this feature.)
23945 This variable has the same structure as `mode-line-format' (which see),
23946 and is used only on frames for which no explicit name has been set
23947 \(see `modify-frame-parameters'). */);
23949 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23950 doc
: /* Template for displaying the title bar of an iconified frame.
23951 \(Assuming the window manager supports this feature.)
23952 This variable has the same structure as `mode-line-format' (which see),
23953 and is used only on frames for which no explicit name has been set
23954 \(see `modify-frame-parameters'). */);
23956 = Vframe_title_format
23957 = Fcons (intern ("multiple-frames"),
23958 Fcons (build_string ("%b"),
23959 Fcons (Fcons (empty_string
,
23960 Fcons (intern ("invocation-name"),
23961 Fcons (build_string ("@"),
23962 Fcons (intern ("system-name"),
23966 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23967 doc
: /* Maximum number of lines to keep in the message log buffer.
23968 If nil, disable message logging. If t, log messages but don't truncate
23969 the buffer when it becomes large. */);
23970 Vmessage_log_max
= make_number (50);
23972 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23973 doc
: /* Functions called before redisplay, if window sizes have changed.
23974 The value should be a list of functions that take one argument.
23975 Just before redisplay, for each frame, if any of its windows have changed
23976 size since the last redisplay, or have been split or deleted,
23977 all the functions in the list are called, with the frame as argument. */);
23978 Vwindow_size_change_functions
= Qnil
;
23980 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23981 doc
: /* List of functions to call before redisplaying a window with scrolling.
23982 Each function is called with two arguments, the window
23983 and its new display-start position. Note that the value of `window-end'
23984 is not valid when these functions are called. */);
23985 Vwindow_scroll_functions
= Qnil
;
23987 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23988 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23989 Each function is called with two arguments, the window and the end trigger value.
23990 See `set-window-redisplay-end-trigger'. */);
23991 Vredisplay_end_trigger_functions
= Qnil
;
23993 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23994 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23995 mouse_autoselect_window
= 0;
23997 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23998 doc
: /* *Non-nil means automatically resize tool-bars.
23999 This increases a tool-bar's height if not all tool-bar items are visible.
24000 It decreases a tool-bar's height when it would display blank lines
24002 auto_resize_tool_bars_p
= 1;
24004 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24005 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24006 auto_raise_tool_bar_buttons_p
= 1;
24008 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24009 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24010 make_cursor_line_fully_visible_p
= 1;
24012 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24013 doc
: /* *Border below tool-bar in pixels.
24014 If an integer, use it as the height of the border.
24015 If it is one of `internal-border-width' or `border-width', use the
24016 value of the corresponding frame parameter.
24017 Otherwise, no border is added below the tool-bar. */);
24018 Vtool_bar_border
= Qinternal_border_width
;
24020 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24021 doc
: /* *Margin around tool-bar buttons in pixels.
24022 If an integer, use that for both horizontal and vertical margins.
24023 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24024 HORZ specifying the horizontal margin, and VERT specifying the
24025 vertical margin. */);
24026 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24028 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24029 doc
: /* *Relief thickness of tool-bar buttons. */);
24030 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24032 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24033 doc
: /* List of functions to call to fontify regions of text.
24034 Each function is called with one argument POS. Functions must
24035 fontify a region starting at POS in the current buffer, and give
24036 fontified regions the property `fontified'. */);
24037 Vfontification_functions
= Qnil
;
24038 Fmake_variable_buffer_local (Qfontification_functions
);
24040 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24041 &unibyte_display_via_language_environment
,
24042 doc
: /* *Non-nil means display unibyte text according to language environment.
24043 Specifically this means that unibyte non-ASCII characters
24044 are displayed by converting them to the equivalent multibyte characters
24045 according to the current language environment. As a result, they are
24046 displayed according to the current fontset. */);
24047 unibyte_display_via_language_environment
= 0;
24049 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24050 doc
: /* *Maximum height for resizing mini-windows.
24051 If a float, it specifies a fraction of the mini-window frame's height.
24052 If an integer, it specifies a number of lines. */);
24053 Vmax_mini_window_height
= make_float (0.25);
24055 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24056 doc
: /* *How to resize mini-windows.
24057 A value of nil means don't automatically resize mini-windows.
24058 A value of t means resize them to fit the text displayed in them.
24059 A value of `grow-only', the default, means let mini-windows grow
24060 only, until their display becomes empty, at which point the windows
24061 go back to their normal size. */);
24062 Vresize_mini_windows
= Qgrow_only
;
24064 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24065 doc
: /* Alist specifying how to blink the cursor off.
24066 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24067 `cursor-type' frame-parameter or variable equals ON-STATE,
24068 comparing using `equal', Emacs uses OFF-STATE to specify
24069 how to blink it off. ON-STATE and OFF-STATE are values for
24070 the `cursor-type' frame parameter.
24072 If a frame's ON-STATE has no entry in this list,
24073 the frame's other specifications determine how to blink the cursor off. */);
24074 Vblink_cursor_alist
= Qnil
;
24076 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24077 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24078 automatic_hscrolling_p
= 1;
24080 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24081 doc
: /* *How many columns away from the window edge point is allowed to get
24082 before automatic hscrolling will horizontally scroll the window. */);
24083 hscroll_margin
= 5;
24085 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24086 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24087 When point is less than `hscroll-margin' columns from the window
24088 edge, automatic hscrolling will scroll the window by the amount of columns
24089 determined by this variable. If its value is a positive integer, scroll that
24090 many columns. If it's a positive floating-point number, it specifies the
24091 fraction of the window's width to scroll. If it's nil or zero, point will be
24092 centered horizontally after the scroll. Any other value, including negative
24093 numbers, are treated as if the value were zero.
24095 Automatic hscrolling always moves point outside the scroll margin, so if
24096 point was more than scroll step columns inside the margin, the window will
24097 scroll more than the value given by the scroll step.
24099 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24100 and `scroll-right' overrides this variable's effect. */);
24101 Vhscroll_step
= make_number (0);
24103 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24104 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24105 Bind this around calls to `message' to let it take effect. */);
24106 message_truncate_lines
= 0;
24108 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24109 doc
: /* Normal hook run to update the menu bar definitions.
24110 Redisplay runs this hook before it redisplays the menu bar.
24111 This is used to update submenus such as Buffers,
24112 whose contents depend on various data. */);
24113 Vmenu_bar_update_hook
= Qnil
;
24115 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24116 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24117 inhibit_menubar_update
= 0;
24119 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24120 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24121 inhibit_eval_during_redisplay
= 0;
24123 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24124 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24125 inhibit_free_realized_faces
= 0;
24128 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24129 doc
: /* Inhibit try_window_id display optimization. */);
24130 inhibit_try_window_id
= 0;
24132 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24133 doc
: /* Inhibit try_window_reusing display optimization. */);
24134 inhibit_try_window_reusing
= 0;
24136 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24137 doc
: /* Inhibit try_cursor_movement display optimization. */);
24138 inhibit_try_cursor_movement
= 0;
24139 #endif /* GLYPH_DEBUG */
24141 DEFVAR_INT ("overline-margin", &overline_margin
,
24142 doc
: /* *Space between overline and text, in pixels.
24143 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24144 margin to the caracter height. */);
24145 overline_margin
= 2;
24149 /* Initialize this module when Emacs starts. */
24154 Lisp_Object root_window
;
24155 struct window
*mini_w
;
24157 current_header_line_height
= current_mode_line_height
= -1;
24159 CHARPOS (this_line_start_pos
) = 0;
24161 mini_w
= XWINDOW (minibuf_window
);
24162 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24164 if (!noninteractive
)
24166 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24169 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24170 set_window_height (root_window
,
24171 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24173 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24174 set_window_height (minibuf_window
, 1, 0);
24176 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24177 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24179 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24180 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24181 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24183 /* The default ellipsis glyphs `...'. */
24184 for (i
= 0; i
< 3; ++i
)
24185 default_invis_vector
[i
] = make_number ('.');
24189 /* Allocate the buffer for frame titles.
24190 Also used for `format-mode-line'. */
24192 mode_line_noprop_buf
= (char *) xmalloc (size
);
24193 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24194 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24195 mode_line_target
= MODE_LINE_DISPLAY
;
24198 help_echo_showing_p
= 0;
24202 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24203 (do not change this comment) */