1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2015 Free Software Foundation,
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 3 of the License, or
11 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code.
36 The following diagram shows how redisplay code is invoked. As you
37 can see, Lisp calls redisplay and vice versa. Under window systems
38 like X, some portions of the redisplay code are also called
39 asynchronously during mouse movement or expose events. It is very
40 important that these code parts do NOT use the C library (malloc,
41 free) because many C libraries under Unix are not reentrant. They
42 may also NOT call functions of the Lisp interpreter which could
43 change the interpreter's state. If you don't follow these rules,
44 you will encounter bugs which are very hard to explain.
46 +--------------+ redisplay +----------------+
47 | Lisp machine |---------------->| Redisplay code |<--+
48 +--------------+ (xdisp.c) +----------------+ |
50 +----------------------------------+ |
51 Don't use this path when called |
54 expose_window (asynchronous) |
56 X expose events -----+
58 What does redisplay do? Obviously, it has to figure out somehow what
59 has been changed since the last time the display has been updated,
60 and to make these changes visible. Preferably it would do that in
61 a moderately intelligent way, i.e. fast.
63 Changes in buffer text can be deduced from window and buffer
64 structures, and from some global variables like `beg_unchanged' and
65 `end_unchanged'. The contents of the display are additionally
66 recorded in a `glyph matrix', a two-dimensional matrix of glyph
67 structures. Each row in such a matrix corresponds to a line on the
68 display, and each glyph in a row corresponds to a column displaying
69 a character, an image, or what else. This matrix is called the
70 `current glyph matrix' or `current matrix' in redisplay
73 For buffer parts that have been changed since the last update, a
74 second glyph matrix is constructed, the so called `desired glyph
75 matrix' or short `desired matrix'. Current and desired matrix are
76 then compared to find a cheap way to update the display, e.g. by
77 reusing part of the display by scrolling lines.
79 You will find a lot of redisplay optimizations when you start
80 looking at the innards of redisplay. The overall goal of all these
81 optimizations is to make redisplay fast because it is done
82 frequently. Some of these optimizations are implemented by the
87 This function tries to update the display if the text in the
88 window did not change and did not scroll, only point moved, and
89 it did not move off the displayed portion of the text.
91 . try_window_reusing_current_matrix
93 This function reuses the current matrix of a window when text
94 has not changed, but the window start changed (e.g., due to
99 This function attempts to redisplay a window by reusing parts of
100 its existing display. It finds and reuses the part that was not
101 changed, and redraws the rest. (The "id" part in the function's
102 name stands for "insert/delete", not for "identification" or
107 This function performs the full redisplay of a single window
108 assuming that its fonts were not changed and that the cursor
109 will not end up in the scroll margins. (Loading fonts requires
110 re-adjustment of dimensions of glyph matrices, which makes this
111 method impossible to use.)
113 These optimizations are tried in sequence (some can be skipped if
114 it is known that they are not applicable). If none of the
115 optimizations were successful, redisplay calls redisplay_windows,
116 which performs a full redisplay of all windows.
118 Note that there's one more important optimization up Emacs's
119 sleeve, but it is related to actually redrawing the potentially
120 changed portions of the window/frame, not to reproducing the
121 desired matrices of those potentially changed portions. Namely,
122 the function update_frame and its subroutines, which you will find
123 in dispnew.c, compare the desired matrices with the current
124 matrices, and only redraw the portions that changed. So it could
125 happen that the functions in this file for some reason decide that
126 the entire desired matrix needs to be regenerated from scratch, and
127 still only parts of the Emacs display, or even nothing at all, will
128 be actually delivered to the glass, because update_frame has found
129 that the new and the old screen contents are similar or identical.
133 Desired matrices are always built per Emacs window. The function
134 `display_line' is the central function to look at if you are
135 interested. It constructs one row in a desired matrix given an
136 iterator structure containing both a buffer position and a
137 description of the environment in which the text is to be
138 displayed. But this is too early, read on.
140 Characters and pixmaps displayed for a range of buffer text depend
141 on various settings of buffers and windows, on overlays and text
142 properties, on display tables, on selective display. The good news
143 is that all this hairy stuff is hidden behind a small set of
144 interface functions taking an iterator structure (struct it)
147 Iteration over things to be displayed is then simple. It is
148 started by initializing an iterator with a call to init_iterator,
149 passing it the buffer position where to start iteration. For
150 iteration over strings, pass -1 as the position to init_iterator,
151 and call reseat_to_string when the string is ready, to initialize
152 the iterator for that string. Thereafter, calls to
153 get_next_display_element fill the iterator structure with relevant
154 information about the next thing to display. Calls to
155 set_iterator_to_next move the iterator to the next thing.
157 Besides this, an iterator also contains information about the
158 display environment in which glyphs for display elements are to be
159 produced. It has fields for the width and height of the display,
160 the information whether long lines are truncated or continued, a
161 current X and Y position, and lots of other stuff you can better
164 Glyphs in a desired matrix are normally constructed in a loop
165 calling get_next_display_element and then PRODUCE_GLYPHS. The call
166 to PRODUCE_GLYPHS will fill the iterator structure with pixel
167 information about the element being displayed and at the same time
168 produce glyphs for it. If the display element fits on the line
169 being displayed, set_iterator_to_next is called next, otherwise the
170 glyphs produced are discarded. The function display_line is the
171 workhorse of filling glyph rows in the desired matrix with glyphs.
172 In addition to producing glyphs, it also handles line truncation
173 and continuation, word wrap, and cursor positioning (for the
174 latter, see also set_cursor_from_row).
178 That just couldn't be all, could it? What about terminal types not
179 supporting operations on sub-windows of the screen? To update the
180 display on such a terminal, window-based glyph matrices are not
181 well suited. To be able to reuse part of the display (scrolling
182 lines up and down), we must instead have a view of the whole
183 screen. This is what `frame matrices' are for. They are a trick.
185 Frames on terminals like above have a glyph pool. Windows on such
186 a frame sub-allocate their glyph memory from their frame's glyph
187 pool. The frame itself is given its own glyph matrices. By
188 coincidence---or maybe something else---rows in window glyph
189 matrices are slices of corresponding rows in frame matrices. Thus
190 writing to window matrices implicitly updates a frame matrix which
191 provides us with the view of the whole screen that we originally
192 wanted to have without having to move many bytes around. To be
193 honest, there is a little bit more done, but not much more. If you
194 plan to extend that code, take a look at dispnew.c. The function
195 build_frame_matrix is a good starting point.
197 Bidirectional display.
199 Bidirectional display adds quite some hair to this already complex
200 design. The good news are that a large portion of that hairy stuff
201 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
202 reordering engine which is called by set_iterator_to_next and
203 returns the next character to display in the visual order. See
204 commentary on bidi.c for more details. As far as redisplay is
205 concerned, the effect of calling bidi_move_to_visually_next, the
206 main interface of the reordering engine, is that the iterator gets
207 magically placed on the buffer or string position that is to be
208 displayed next. In other words, a linear iteration through the
209 buffer/string is replaced with a non-linear one. All the rest of
210 the redisplay is oblivious to the bidi reordering.
212 Well, almost oblivious---there are still complications, most of
213 them due to the fact that buffer and string positions no longer
214 change monotonously with glyph indices in a glyph row. Moreover,
215 for continued lines, the buffer positions may not even be
216 monotonously changing with vertical positions. Also, accounting
217 for face changes, overlays, etc. becomes more complex because
218 non-linear iteration could potentially skip many positions with
219 changes, and then cross them again on the way back...
221 One other prominent effect of bidirectional display is that some
222 paragraphs of text need to be displayed starting at the right
223 margin of the window---the so-called right-to-left, or R2L
224 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
225 which have their reversed_p flag set. The bidi reordering engine
226 produces characters in such rows starting from the character which
227 should be the rightmost on display. PRODUCE_GLYPHS then reverses
228 the order, when it fills up the glyph row whose reversed_p flag is
229 set, by prepending each new glyph to what is already there, instead
230 of appending it. When the glyph row is complete, the function
231 extend_face_to_end_of_line fills the empty space to the left of the
232 leftmost character with special glyphs, which will display as,
233 well, empty. On text terminals, these special glyphs are simply
234 blank characters. On graphics terminals, there's a single stretch
235 glyph of a suitably computed width. Both the blanks and the
236 stretch glyph are given the face of the background of the line.
237 This way, the terminal-specific back-end can still draw the glyphs
238 left to right, even for R2L lines.
240 Bidirectional display and character compositions
242 Some scripts cannot be displayed by drawing each character
243 individually, because adjacent characters change each other's shape
244 on display. For example, Arabic and Indic scripts belong to this
247 Emacs display supports this by providing "character compositions",
248 most of which is implemented in composite.c. During the buffer
249 scan that delivers characters to PRODUCE_GLYPHS, if the next
250 character to be delivered is a composed character, the iteration
251 calls composition_reseat_it and next_element_from_composition. If
252 they succeed to compose the character with one or more of the
253 following characters, the whole sequence of characters that where
254 composed is recorded in the `struct composition_it' object that is
255 part of the buffer iterator. The composed sequence could produce
256 one or more font glyphs (called "grapheme clusters") on the screen.
257 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
258 in the direction corresponding to the current bidi scan direction
259 (recorded in the scan_dir member of the `struct bidi_it' object
260 that is part of the buffer iterator). In particular, if the bidi
261 iterator currently scans the buffer backwards, the grapheme
262 clusters are delivered back to front. This reorders the grapheme
263 clusters as appropriate for the current bidi context. Note that
264 this means that the grapheme clusters are always stored in the
265 LGSTRING object (see composite.c) in the logical order.
267 Moving an iterator in bidirectional text
268 without producing glyphs
270 Note one important detail mentioned above: that the bidi reordering
271 engine, driven by the iterator, produces characters in R2L rows
272 starting at the character that will be the rightmost on display.
273 As far as the iterator is concerned, the geometry of such rows is
274 still left to right, i.e. the iterator "thinks" the first character
275 is at the leftmost pixel position. The iterator does not know that
276 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
277 delivers. This is important when functions from the move_it_*
278 family are used to get to certain screen position or to match
279 screen coordinates with buffer coordinates: these functions use the
280 iterator geometry, which is left to right even in R2L paragraphs.
281 This works well with most callers of move_it_*, because they need
282 to get to a specific column, and columns are still numbered in the
283 reading order, i.e. the rightmost character in a R2L paragraph is
284 still column zero. But some callers do not get well with this; a
285 notable example is mouse clicks that need to find the character
286 that corresponds to certain pixel coordinates. See
287 buffer_posn_from_coords in dispnew.c for how this is handled. */
295 #include "keyboard.h"
298 #include "termchar.h"
299 #include "dispextern.h"
300 #include "character.h"
304 #include "commands.h"
308 #include "termhooks.h"
309 #include "termopts.h"
310 #include "intervals.h"
313 #include "region-cache.h"
316 #include "blockinput.h"
317 #ifdef HAVE_WINDOW_SYSTEM
319 #endif /* HAVE_WINDOW_SYSTEM */
321 #ifndef FRAME_X_OUTPUT
322 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
325 #define INFINITY 10000000
327 /* Holds the list (error). */
328 static Lisp_Object list_of_error
;
330 #ifdef HAVE_WINDOW_SYSTEM
332 /* Test if overflow newline into fringe. Called with iterator IT
333 at or past right window margin, and with IT->current_x set. */
335 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
336 (!NILP (Voverflow_newline_into_fringe) \
337 && FRAME_WINDOW_P ((IT)->f) \
338 && ((IT)->bidi_it.paragraph_dir == R2L \
339 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
340 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
341 && (IT)->current_x == (IT)->last_visible_x)
343 #else /* !HAVE_WINDOW_SYSTEM */
344 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) false
345 #endif /* HAVE_WINDOW_SYSTEM */
347 /* Test if the display element loaded in IT, or the underlying buffer
348 or string character, is a space or a TAB character. This is used
349 to determine where word wrapping can occur. */
351 #define IT_DISPLAYING_WHITESPACE(it) \
352 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
353 || ((STRINGP (it->string) \
354 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
355 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
357 && (it->s[IT_BYTEPOS (*it)] == ' ' \
358 || it->s[IT_BYTEPOS (*it)] == '\t')) \
359 || (IT_BYTEPOS (*it) < ZV_BYTE \
360 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
361 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
363 /* True means print newline to stdout before next mini-buffer message. */
365 bool noninteractive_need_newline
;
367 /* True means print newline to message log before next message. */
369 static bool message_log_need_newline
;
371 /* Three markers that message_dolog uses.
372 It could allocate them itself, but that causes trouble
373 in handling memory-full errors. */
374 static Lisp_Object message_dolog_marker1
;
375 static Lisp_Object message_dolog_marker2
;
376 static Lisp_Object message_dolog_marker3
;
378 /* The buffer position of the first character appearing entirely or
379 partially on the line of the selected window which contains the
380 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
381 redisplay optimization in redisplay_internal. */
383 static struct text_pos this_line_start_pos
;
385 /* Number of characters past the end of the line above, including the
386 terminating newline. */
388 static struct text_pos this_line_end_pos
;
390 /* The vertical positions and the height of this line. */
392 static int this_line_vpos
;
393 static int this_line_y
;
394 static int this_line_pixel_height
;
396 /* X position at which this display line starts. Usually zero;
397 negative if first character is partially visible. */
399 static int this_line_start_x
;
401 /* The smallest character position seen by move_it_* functions as they
402 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
403 hscrolled lines, see display_line. */
405 static struct text_pos this_line_min_pos
;
407 /* Buffer that this_line_.* variables are referring to. */
409 static struct buffer
*this_line_buffer
;
411 /* True if an overlay arrow has been displayed in this window. */
413 static bool overlay_arrow_seen
;
415 /* Vector containing glyphs for an ellipsis `...'. */
417 static Lisp_Object default_invis_vector
[3];
419 /* This is the window where the echo area message was displayed. It
420 is always a mini-buffer window, but it may not be the same window
421 currently active as a mini-buffer. */
423 Lisp_Object echo_area_window
;
425 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
426 pushes the current message and the value of
427 message_enable_multibyte on the stack, the function restore_message
428 pops the stack and displays MESSAGE again. */
430 static Lisp_Object Vmessage_stack
;
432 /* True means multibyte characters were enabled when the echo area
433 message was specified. */
435 static bool message_enable_multibyte
;
437 /* Nonzero if we should redraw the mode lines on the next redisplay.
438 If it has value REDISPLAY_SOME, then only redisplay the mode lines where
439 the `redisplay' bit has been set. Otherwise, redisplay all mode lines
440 (the number used is then only used to track down the cause for this
443 int update_mode_lines
;
445 /* Nonzero if window sizes or contents other than selected-window have changed
446 since last redisplay that finished.
447 If it has value REDISPLAY_SOME, then only redisplay the windows where
448 the `redisplay' bit has been set. Otherwise, redisplay all windows
449 (the number used is then only used to track down the cause for this
452 int windows_or_buffers_changed
;
454 /* True after display_mode_line if %l was used and it displayed a
457 static bool line_number_displayed
;
459 /* The name of the *Messages* buffer, a string. */
461 static Lisp_Object Vmessages_buffer_name
;
463 /* Current, index 0, and last displayed echo area message. Either
464 buffers from echo_buffers, or nil to indicate no message. */
466 Lisp_Object echo_area_buffer
[2];
468 /* The buffers referenced from echo_area_buffer. */
470 static Lisp_Object echo_buffer
[2];
472 /* A vector saved used in with_area_buffer to reduce consing. */
474 static Lisp_Object Vwith_echo_area_save_vector
;
476 /* True means display_echo_area should display the last echo area
477 message again. Set by redisplay_preserve_echo_area. */
479 static bool display_last_displayed_message_p
;
481 /* True if echo area is being used by print; false if being used by
484 static bool message_buf_print
;
486 /* Set to true in clear_message to make redisplay_internal aware
487 of an emptied echo area. */
489 static bool message_cleared_p
;
491 /* A scratch glyph row with contents used for generating truncation
492 glyphs. Also used in direct_output_for_insert. */
494 #define MAX_SCRATCH_GLYPHS 100
495 static struct glyph_row scratch_glyph_row
;
496 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
498 /* Ascent and height of the last line processed by move_it_to. */
500 static int last_height
;
502 /* True if there's a help-echo in the echo area. */
504 bool help_echo_showing_p
;
506 /* The maximum distance to look ahead for text properties. Values
507 that are too small let us call compute_char_face and similar
508 functions too often which is expensive. Values that are too large
509 let us call compute_char_face and alike too often because we
510 might not be interested in text properties that far away. */
512 #define TEXT_PROP_DISTANCE_LIMIT 100
514 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
515 iterator state and later restore it. This is needed because the
516 bidi iterator on bidi.c keeps a stacked cache of its states, which
517 is really a singleton. When we use scratch iterator objects to
518 move around the buffer, we can cause the bidi cache to be pushed or
519 popped, and therefore we need to restore the cache state when we
520 return to the original iterator. */
521 #define SAVE_IT(ITCOPY, ITORIG, CACHE) \
524 bidi_unshelve_cache (CACHE, true); \
526 CACHE = bidi_shelve_cache (); \
529 #define RESTORE_IT(pITORIG, pITCOPY, CACHE) \
531 if (pITORIG != pITCOPY) \
532 *(pITORIG) = *(pITCOPY); \
533 bidi_unshelve_cache (CACHE, false); \
537 /* Functions to mark elements as needing redisplay. */
538 enum { REDISPLAY_SOME
= 2}; /* Arbitrary choice. */
541 redisplay_other_windows (void)
543 if (!windows_or_buffers_changed
)
544 windows_or_buffers_changed
= REDISPLAY_SOME
;
548 wset_redisplay (struct window
*w
)
550 /* Beware: selected_window can be nil during early stages. */
551 if (!EQ (make_lisp_ptr (w
, Lisp_Vectorlike
), selected_window
))
552 redisplay_other_windows ();
557 fset_redisplay (struct frame
*f
)
559 redisplay_other_windows ();
564 bset_redisplay (struct buffer
*b
)
566 int count
= buffer_window_count (b
);
569 /* ... it's visible in other window than selected, */
570 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
571 redisplay_other_windows ();
572 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
573 so that if we later set windows_or_buffers_changed, this buffer will
575 b
->text
->redisplay
= true;
580 bset_update_mode_line (struct buffer
*b
)
582 if (!update_mode_lines
)
583 update_mode_lines
= REDISPLAY_SOME
;
584 b
->text
->redisplay
= true;
589 /* True means print traces of redisplay if compiled with
590 GLYPH_DEBUG defined. */
592 bool trace_redisplay_p
;
594 #endif /* GLYPH_DEBUG */
596 #ifdef DEBUG_TRACE_MOVE
597 /* True means trace with TRACE_MOVE to stderr. */
598 static bool trace_move
;
600 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
602 #define TRACE_MOVE(x) (void) 0
605 /* Buffer being redisplayed -- for redisplay_window_error. */
607 static struct buffer
*displayed_buffer
;
609 /* Value returned from text property handlers (see below). */
614 HANDLED_RECOMPUTE_PROPS
,
615 HANDLED_OVERLAY_STRING_CONSUMED
,
619 /* A description of text properties that redisplay is interested
624 /* The symbol index of the name of the property. */
627 /* A unique index for the property. */
630 /* A handler function called to set up iterator IT from the property
631 at IT's current position. Value is used to steer handle_stop. */
632 enum prop_handled (*handler
) (struct it
*it
);
635 static enum prop_handled
handle_face_prop (struct it
*);
636 static enum prop_handled
handle_invisible_prop (struct it
*);
637 static enum prop_handled
handle_display_prop (struct it
*);
638 static enum prop_handled
handle_composition_prop (struct it
*);
639 static enum prop_handled
handle_overlay_change (struct it
*);
640 static enum prop_handled
handle_fontified_prop (struct it
*);
642 /* Properties handled by iterators. */
644 static struct props it_props
[] =
646 {SYMBOL_INDEX (Qfontified
), FONTIFIED_PROP_IDX
, handle_fontified_prop
},
647 /* Handle `face' before `display' because some sub-properties of
648 `display' need to know the face. */
649 {SYMBOL_INDEX (Qface
), FACE_PROP_IDX
, handle_face_prop
},
650 {SYMBOL_INDEX (Qdisplay
), DISPLAY_PROP_IDX
, handle_display_prop
},
651 {SYMBOL_INDEX (Qinvisible
), INVISIBLE_PROP_IDX
, handle_invisible_prop
},
652 {SYMBOL_INDEX (Qcomposition
), COMPOSITION_PROP_IDX
, handle_composition_prop
},
656 /* Value is the position described by X. If X is a marker, value is
657 the marker_position of X. Otherwise, value is X. */
659 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
661 /* Enumeration returned by some move_it_.* functions internally. */
665 /* Not used. Undefined value. */
668 /* Move ended at the requested buffer position or ZV. */
669 MOVE_POS_MATCH_OR_ZV
,
671 /* Move ended at the requested X pixel position. */
674 /* Move within a line ended at the end of a line that must be
678 /* Move within a line ended at the end of a line that would
679 be displayed truncated. */
682 /* Move within a line ended at a line end. */
686 /* This counter is used to clear the face cache every once in a while
687 in redisplay_internal. It is incremented for each redisplay.
688 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
691 #define CLEAR_FACE_CACHE_COUNT 500
692 static int clear_face_cache_count
;
694 /* Similarly for the image cache. */
696 #ifdef HAVE_WINDOW_SYSTEM
697 #define CLEAR_IMAGE_CACHE_COUNT 101
698 static int clear_image_cache_count
;
700 /* Null glyph slice */
701 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
704 /* True while redisplay_internal is in progress. */
708 /* If a string, XTread_socket generates an event to display that string.
709 (The display is done in read_char.) */
711 Lisp_Object help_echo_string
;
712 Lisp_Object help_echo_window
;
713 Lisp_Object help_echo_object
;
714 ptrdiff_t help_echo_pos
;
716 /* Temporary variable for XTread_socket. */
718 Lisp_Object previous_help_echo_string
;
720 /* Platform-independent portion of hourglass implementation. */
722 #ifdef HAVE_WINDOW_SYSTEM
724 /* True means an hourglass cursor is currently shown. */
725 static bool hourglass_shown_p
;
727 /* If non-null, an asynchronous timer that, when it expires, displays
728 an hourglass cursor on all frames. */
729 static struct atimer
*hourglass_atimer
;
731 #endif /* HAVE_WINDOW_SYSTEM */
733 /* Default number of seconds to wait before displaying an hourglass
735 #define DEFAULT_HOURGLASS_DELAY 1
737 #ifdef HAVE_WINDOW_SYSTEM
739 /* Default pixel width of `thin-space' display method. */
740 #define THIN_SPACE_WIDTH 1
742 #endif /* HAVE_WINDOW_SYSTEM */
744 /* Function prototypes. */
746 static void setup_for_ellipsis (struct it
*, int);
747 static void set_iterator_to_next (struct it
*, bool);
748 static void mark_window_display_accurate_1 (struct window
*, bool);
749 static bool row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
750 static bool cursor_row_p (struct glyph_row
*);
751 static int redisplay_mode_lines (Lisp_Object
, bool);
753 static void handle_line_prefix (struct it
*);
755 static void handle_stop_backwards (struct it
*, ptrdiff_t);
756 static void unwind_with_echo_area_buffer (Lisp_Object
);
757 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
758 static bool current_message_1 (ptrdiff_t, Lisp_Object
);
759 static bool truncate_message_1 (ptrdiff_t, Lisp_Object
);
760 static void set_message (Lisp_Object
);
761 static bool set_message_1 (ptrdiff_t, Lisp_Object
);
762 static bool display_echo_area_1 (ptrdiff_t, Lisp_Object
);
763 static bool resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
764 static void unwind_redisplay (void);
765 static void extend_face_to_end_of_line (struct it
*);
766 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
767 static void push_it (struct it
*, struct text_pos
*);
768 static void iterate_out_of_display_property (struct it
*);
769 static void pop_it (struct it
*);
770 static void redisplay_internal (void);
771 static bool echo_area_display (bool);
772 static void redisplay_windows (Lisp_Object
);
773 static void redisplay_window (Lisp_Object
, bool);
774 static Lisp_Object
redisplay_window_error (Lisp_Object
);
775 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
776 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
777 static bool set_cursor_from_row (struct window
*, struct glyph_row
*,
778 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
780 static bool update_menu_bar (struct frame
*, bool, bool);
781 static bool try_window_reusing_current_matrix (struct window
*);
782 static int try_window_id (struct window
*);
783 static bool display_line (struct it
*);
784 static int display_mode_lines (struct window
*);
785 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
786 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
,
788 static int store_mode_line_string (const char *, Lisp_Object
, bool, int, int,
790 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
791 static void display_menu_bar (struct window
*);
792 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
794 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
795 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
796 static void compute_line_metrics (struct it
*);
797 static void run_redisplay_end_trigger_hook (struct it
*);
798 static bool get_overlay_strings (struct it
*, ptrdiff_t);
799 static bool get_overlay_strings_1 (struct it
*, ptrdiff_t, bool);
800 static void next_overlay_string (struct it
*);
801 static void reseat (struct it
*, struct text_pos
, bool);
802 static void reseat_1 (struct it
*, struct text_pos
, bool);
803 static bool next_element_from_display_vector (struct it
*);
804 static bool next_element_from_string (struct it
*);
805 static bool next_element_from_c_string (struct it
*);
806 static bool next_element_from_buffer (struct it
*);
807 static bool next_element_from_composition (struct it
*);
808 static bool next_element_from_image (struct it
*);
809 static bool next_element_from_stretch (struct it
*);
810 static void load_overlay_strings (struct it
*, ptrdiff_t);
811 static bool get_next_display_element (struct it
*);
812 static enum move_it_result
813 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
814 enum move_operation_enum
);
815 static void get_visually_first_element (struct it
*);
816 static void compute_stop_pos (struct it
*);
817 static int face_before_or_after_it_pos (struct it
*, bool);
818 static ptrdiff_t next_overlay_change (ptrdiff_t);
819 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
820 Lisp_Object
, struct text_pos
*, ptrdiff_t, bool);
821 static int handle_single_display_spec (struct it
*, Lisp_Object
,
822 Lisp_Object
, Lisp_Object
,
823 struct text_pos
*, ptrdiff_t, int, bool);
824 static int underlying_face_id (struct it
*);
826 #define face_before_it_pos(IT) face_before_or_after_it_pos (IT, true)
827 #define face_after_it_pos(IT) face_before_or_after_it_pos (IT, false)
829 #ifdef HAVE_WINDOW_SYSTEM
831 static void update_tool_bar (struct frame
*, bool);
832 static void x_draw_bottom_divider (struct window
*w
);
833 static void notice_overwritten_cursor (struct window
*,
836 static void append_stretch_glyph (struct it
*, Lisp_Object
,
840 #endif /* HAVE_WINDOW_SYSTEM */
842 static void produce_special_glyphs (struct it
*, enum display_element_type
);
843 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
844 static bool coords_in_mouse_face_p (struct window
*, int, int);
848 /***********************************************************************
849 Window display dimensions
850 ***********************************************************************/
852 /* Return the bottom boundary y-position for text lines in window W.
853 This is the first y position at which a line cannot start.
854 It is relative to the top of the window.
856 This is the height of W minus the height of a mode line, if any. */
859 window_text_bottom_y (struct window
*w
)
861 int height
= WINDOW_PIXEL_HEIGHT (w
);
863 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
865 if (WINDOW_WANTS_MODELINE_P (w
))
866 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
868 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
873 /* Return the pixel width of display area AREA of window W.
874 ANY_AREA means return the total width of W, not including
875 fringes to the left and right of the window. */
878 window_box_width (struct window
*w
, enum glyph_row_area area
)
880 int width
= w
->pixel_width
;
882 if (!w
->pseudo_window_p
)
884 width
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
885 width
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
887 if (area
== TEXT_AREA
)
888 width
-= (WINDOW_MARGINS_WIDTH (w
)
889 + WINDOW_FRINGES_WIDTH (w
));
890 else if (area
== LEFT_MARGIN_AREA
)
891 width
= WINDOW_LEFT_MARGIN_WIDTH (w
);
892 else if (area
== RIGHT_MARGIN_AREA
)
893 width
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
896 /* With wide margins, fringes, etc. we might end up with a negative
897 width, correct that here. */
898 return max (0, width
);
902 /* Return the pixel height of the display area of window W, not
903 including mode lines of W, if any. */
906 window_box_height (struct window
*w
)
908 struct frame
*f
= XFRAME (w
->frame
);
909 int height
= WINDOW_PIXEL_HEIGHT (w
);
911 eassert (height
>= 0);
913 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
914 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
916 /* Note: the code below that determines the mode-line/header-line
917 height is essentially the same as that contained in the macro
918 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
919 the appropriate glyph row has its `mode_line_p' flag set,
920 and if it doesn't, uses estimate_mode_line_height instead. */
922 if (WINDOW_WANTS_MODELINE_P (w
))
924 struct glyph_row
*ml_row
925 = (w
->current_matrix
&& w
->current_matrix
->rows
926 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
928 if (ml_row
&& ml_row
->mode_line_p
)
929 height
-= ml_row
->height
;
931 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
934 if (WINDOW_WANTS_HEADER_LINE_P (w
))
936 struct glyph_row
*hl_row
937 = (w
->current_matrix
&& w
->current_matrix
->rows
938 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
940 if (hl_row
&& hl_row
->mode_line_p
)
941 height
-= hl_row
->height
;
943 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
946 /* With a very small font and a mode-line that's taller than
947 default, we might end up with a negative height. */
948 return max (0, height
);
951 /* Return the window-relative coordinate of the left edge of display
952 area AREA of window W. ANY_AREA means return the left edge of the
953 whole window, to the right of the left fringe of W. */
956 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
960 if (w
->pseudo_window_p
)
963 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
965 if (area
== TEXT_AREA
)
966 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
967 + window_box_width (w
, LEFT_MARGIN_AREA
));
968 else if (area
== RIGHT_MARGIN_AREA
)
969 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
970 + window_box_width (w
, LEFT_MARGIN_AREA
)
971 + window_box_width (w
, TEXT_AREA
)
972 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
974 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
975 else if (area
== LEFT_MARGIN_AREA
976 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
977 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
979 /* Don't return more than the window's pixel width. */
980 return min (x
, w
->pixel_width
);
984 /* Return the window-relative coordinate of the right edge of display
985 area AREA of window W. ANY_AREA means return the right edge of the
986 whole window, to the left of the right fringe of W. */
989 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
991 /* Don't return more than the window's pixel width. */
992 return min (window_box_left_offset (w
, area
) + window_box_width (w
, area
),
996 /* Return the frame-relative coordinate of the left edge of display
997 area AREA of window W. ANY_AREA means return the left edge of the
998 whole window, to the right of the left fringe of W. */
1001 window_box_left (struct window
*w
, enum glyph_row_area area
)
1003 struct frame
*f
= XFRAME (w
->frame
);
1006 if (w
->pseudo_window_p
)
1007 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1009 x
= (WINDOW_LEFT_EDGE_X (w
)
1010 + window_box_left_offset (w
, area
));
1016 /* Return the frame-relative coordinate of the right edge of display
1017 area AREA of window W. ANY_AREA means return the right edge of the
1018 whole window, to the left of the right fringe of W. */
1021 window_box_right (struct window
*w
, enum glyph_row_area area
)
1023 return window_box_left (w
, area
) + window_box_width (w
, area
);
1026 /* Get the bounding box of the display area AREA of window W, without
1027 mode lines, in frame-relative coordinates. ANY_AREA means the
1028 whole window, not including the left and right fringes of
1029 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1030 coordinates of the upper-left corner of the box. Return in
1031 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1034 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1035 int *box_y
, int *box_width
, int *box_height
)
1038 *box_width
= window_box_width (w
, area
);
1040 *box_height
= window_box_height (w
);
1042 *box_x
= window_box_left (w
, area
);
1045 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1046 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1047 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1051 #ifdef HAVE_WINDOW_SYSTEM
1053 /* Get the bounding box of the display area AREA of window W, without
1054 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1055 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1056 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1057 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1061 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1062 int *bottom_right_x
, int *bottom_right_y
)
1064 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1065 bottom_right_x
, bottom_right_y
);
1066 *bottom_right_x
+= *top_left_x
;
1067 *bottom_right_y
+= *top_left_y
;
1070 #endif /* HAVE_WINDOW_SYSTEM */
1072 /***********************************************************************
1074 ***********************************************************************/
1076 /* Return the bottom y-position of the line the iterator IT is in.
1077 This can modify IT's settings. */
1080 line_bottom_y (struct it
*it
)
1082 int line_height
= it
->max_ascent
+ it
->max_descent
;
1083 int line_top_y
= it
->current_y
;
1085 if (line_height
== 0)
1088 line_height
= last_height
;
1089 else if (IT_CHARPOS (*it
) < ZV
)
1091 move_it_by_lines (it
, 1);
1092 line_height
= (it
->max_ascent
|| it
->max_descent
1093 ? it
->max_ascent
+ it
->max_descent
1098 struct glyph_row
*row
= it
->glyph_row
;
1100 /* Use the default character height. */
1101 it
->glyph_row
= NULL
;
1102 it
->what
= IT_CHARACTER
;
1105 PRODUCE_GLYPHS (it
);
1106 line_height
= it
->ascent
+ it
->descent
;
1107 it
->glyph_row
= row
;
1111 return line_top_y
+ line_height
;
1114 DEFUN ("line-pixel-height", Fline_pixel_height
,
1115 Sline_pixel_height
, 0, 0, 0,
1116 doc
: /* Return height in pixels of text line in the selected window.
1118 Value is the height in pixels of the line at point. */)
1123 struct window
*w
= XWINDOW (selected_window
);
1124 struct buffer
*old_buffer
= NULL
;
1127 if (XBUFFER (w
->contents
) != current_buffer
)
1129 old_buffer
= current_buffer
;
1130 set_buffer_internal_1 (XBUFFER (w
->contents
));
1132 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1133 start_display (&it
, w
, pt
);
1134 it
.vpos
= it
.current_y
= 0;
1136 result
= make_number (line_bottom_y (&it
));
1138 set_buffer_internal_1 (old_buffer
);
1143 /* Return the default pixel height of text lines in window W. The
1144 value is the canonical height of the W frame's default font, plus
1145 any extra space required by the line-spacing variable or frame
1148 Implementation note: this ignores any line-spacing text properties
1149 put on the newline characters. This is because those properties
1150 only affect the _screen_ line ending in the newline (i.e., in a
1151 continued line, only the last screen line will be affected), which
1152 means only a small number of lines in a buffer can ever use this
1153 feature. Since this function is used to compute the default pixel
1154 equivalent of text lines in a window, we can safely ignore those
1155 few lines. For the same reasons, we ignore the line-height
1158 default_line_pixel_height (struct window
*w
)
1160 struct frame
*f
= WINDOW_XFRAME (w
);
1161 int height
= FRAME_LINE_HEIGHT (f
);
1163 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1165 struct buffer
*b
= XBUFFER (w
->contents
);
1166 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1169 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1172 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1173 height
+= XFASTINT (val
);
1174 else if (FLOATP (val
))
1176 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1183 height
+= f
->extra_line_spacing
;
1189 /* Subroutine of pos_visible_p below. Extracts a display string, if
1190 any, from the display spec given as its argument. */
1192 string_from_display_spec (Lisp_Object spec
)
1196 while (CONSP (spec
))
1198 if (STRINGP (XCAR (spec
)))
1203 else if (VECTORP (spec
))
1207 for (i
= 0; i
< ASIZE (spec
); i
++)
1209 if (STRINGP (AREF (spec
, i
)))
1210 return AREF (spec
, i
);
1219 /* Limit insanely large values of W->hscroll on frame F to the largest
1220 value that will still prevent first_visible_x and last_visible_x of
1221 'struct it' from overflowing an int. */
1223 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1225 ptrdiff_t window_hscroll
= w
->hscroll
;
1226 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1227 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1229 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1230 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1232 return window_hscroll
;
1235 /* Return true if position CHARPOS is visible in window W.
1236 CHARPOS < 0 means return info about WINDOW_END position.
1237 If visible, set *X and *Y to pixel coordinates of top left corner.
1238 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1239 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1242 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1243 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1246 void *itdata
= bidi_shelve_cache ();
1247 struct text_pos top
;
1248 bool visible_p
= false;
1249 struct buffer
*old_buffer
= NULL
;
1252 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1255 if (XBUFFER (w
->contents
) != current_buffer
)
1257 old_buffer
= current_buffer
;
1258 set_buffer_internal_1 (XBUFFER (w
->contents
));
1261 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1262 /* Scrolling a minibuffer window via scroll bar when the echo area
1263 shows long text sometimes resets the minibuffer contents behind
1265 if (CHARPOS (top
) > ZV
)
1266 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1268 /* Compute exact mode line heights. */
1269 if (WINDOW_WANTS_MODELINE_P (w
))
1271 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1272 BVAR (current_buffer
, mode_line_format
));
1274 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1275 w
->header_line_height
1276 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1277 BVAR (current_buffer
, header_line_format
));
1279 start_display (&it
, w
, top
);
1280 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1281 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1284 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
!= -1)
1285 && IT_CHARPOS (it
) >= charpos
)
1286 /* When scanning backwards under bidi iteration, move_it_to
1287 stops at or _before_ CHARPOS, because it stops at or to
1288 the _right_ of the character at CHARPOS. */
1289 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1290 && IT_CHARPOS (it
) <= charpos
)))
1292 /* We have reached CHARPOS, or passed it. How the call to
1293 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1294 or covered by a display property, move_it_to stops at the end
1295 of the invisible text, to the right of CHARPOS. (ii) If
1296 CHARPOS is in a display vector, move_it_to stops on its last
1298 int top_x
= it
.current_x
;
1299 int top_y
= it
.current_y
;
1300 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1303 void *save_it_data
= NULL
;
1305 /* Calling line_bottom_y may change it.method, it.position, etc. */
1306 SAVE_IT (save_it
, it
, save_it_data
);
1308 bottom_y
= line_bottom_y (&it
);
1309 if (top_y
< window_top_y
)
1310 visible_p
= bottom_y
> window_top_y
;
1311 else if (top_y
< it
.last_visible_y
)
1313 if (bottom_y
>= it
.last_visible_y
1314 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1315 && IT_CHARPOS (it
) < charpos
)
1317 /* When the last line of the window is scanned backwards
1318 under bidi iteration, we could be duped into thinking
1319 that we have passed CHARPOS, when in fact move_it_to
1320 simply stopped short of CHARPOS because it reached
1321 last_visible_y. To see if that's what happened, we call
1322 move_it_to again with a slightly larger vertical limit,
1323 and see if it actually moved vertically; if it did, we
1324 didn't really reach CHARPOS, which is beyond window end. */
1325 /* Why 10? because we don't know how many canonical lines
1326 will the height of the next line(s) be. So we guess. */
1327 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1329 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1330 MOVE_TO_POS
| MOVE_TO_Y
);
1331 if (it
.current_y
> top_y
)
1335 RESTORE_IT (&it
, &save_it
, save_it_data
);
1338 if (it
.method
== GET_FROM_DISPLAY_VECTOR
)
1340 /* We stopped on the last glyph of a display vector.
1341 Try and recompute. Hack alert! */
1342 if (charpos
< 2 || top
.charpos
>= charpos
)
1343 top_x
= it
.glyph_row
->x
;
1346 struct it it2
, it2_prev
;
1347 /* The idea is to get to the previous buffer
1348 position, consume the character there, and use
1349 the pixel coordinates we get after that. But if
1350 the previous buffer position is also displayed
1351 from a display vector, we need to consume all of
1352 the glyphs from that display vector. */
1353 start_display (&it2
, w
, top
);
1354 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1355 /* If we didn't get to CHARPOS - 1, there's some
1356 replacing display property at that position, and
1357 we stopped after it. That is exactly the place
1358 whose coordinates we want. */
1359 if (IT_CHARPOS (it2
) != charpos
- 1)
1363 /* Iterate until we get out of the display
1364 vector that displays the character at
1367 get_next_display_element (&it2
);
1368 PRODUCE_GLYPHS (&it2
);
1370 set_iterator_to_next (&it2
, true);
1371 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1372 && IT_CHARPOS (it2
) < charpos
);
1374 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1375 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1376 top_x
= it
.glyph_row
->x
;
1379 top_x
= it2_prev
.current_x
;
1380 top_y
= it2_prev
.current_y
;
1384 else if (IT_CHARPOS (it
) != charpos
)
1386 Lisp_Object cpos
= make_number (charpos
);
1387 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1388 Lisp_Object string
= string_from_display_spec (spec
);
1389 struct text_pos tpos
;
1390 bool newline_in_string
1392 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1394 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1395 bool replacing_spec_p
1397 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1398 charpos
, FRAME_WINDOW_P (it
.f
)));
1399 /* The tricky code below is needed because there's a
1400 discrepancy between move_it_to and how we set cursor
1401 when PT is at the beginning of a portion of text
1402 covered by a display property or an overlay with a
1403 display property, or the display line ends in a
1404 newline from a display string. move_it_to will stop
1405 _after_ such display strings, whereas
1406 set_cursor_from_row conspires with cursor_row_p to
1407 place the cursor on the first glyph produced from the
1410 /* We have overshoot PT because it is covered by a
1411 display property that replaces the text it covers.
1412 If the string includes embedded newlines, we are also
1413 in the wrong display line. Backtrack to the correct
1414 line, where the display property begins. */
1415 if (replacing_spec_p
)
1417 Lisp_Object startpos
, endpos
;
1418 EMACS_INT start
, end
;
1421 /* Find the first and the last buffer positions
1422 covered by the display string. */
1424 Fnext_single_char_property_change (cpos
, Qdisplay
,
1427 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1429 start
= XFASTINT (startpos
);
1430 end
= XFASTINT (endpos
);
1431 /* Move to the last buffer position before the
1432 display property. */
1433 start_display (&it3
, w
, top
);
1434 if (start
> CHARPOS (top
))
1435 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1436 /* Move forward one more line if the position before
1437 the display string is a newline or if it is the
1438 rightmost character on a line that is
1439 continued or word-wrapped. */
1440 if (it3
.method
== GET_FROM_BUFFER
1442 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1443 move_it_by_lines (&it3
, 1);
1444 else if (move_it_in_display_line_to (&it3
, -1,
1448 == MOVE_LINE_CONTINUED
)
1450 move_it_by_lines (&it3
, 1);
1451 /* When we are under word-wrap, the #$@%!
1452 move_it_by_lines moves 2 lines, so we need to
1454 if (it3
.line_wrap
== WORD_WRAP
)
1455 move_it_by_lines (&it3
, -1);
1458 /* Record the vertical coordinate of the display
1459 line where we wound up. */
1460 top_y
= it3
.current_y
;
1463 /* When characters are reordered for display,
1464 the character displayed to the left of the
1465 display string could be _after_ the display
1466 property in the logical order. Use the
1467 smallest vertical position of these two. */
1468 start_display (&it3
, w
, top
);
1469 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1470 if (it3
.current_y
< top_y
)
1471 top_y
= it3
.current_y
;
1473 /* Move from the top of the window to the beginning
1474 of the display line where the display string
1476 start_display (&it3
, w
, top
);
1477 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1478 /* If it3_moved stays false after the 'while' loop
1479 below, that means we already were at a newline
1480 before the loop (e.g., the display string begins
1481 with a newline), so we don't need to (and cannot)
1482 inspect the glyphs of it3.glyph_row, because
1483 PRODUCE_GLYPHS will not produce anything for a
1484 newline, and thus it3.glyph_row stays at its
1485 stale content it got at top of the window. */
1486 bool it3_moved
= false;
1487 /* Finally, advance the iterator until we hit the
1488 first display element whose character position is
1489 CHARPOS, or until the first newline from the
1490 display string, which signals the end of the
1492 while (get_next_display_element (&it3
))
1494 PRODUCE_GLYPHS (&it3
);
1495 if (IT_CHARPOS (it3
) == charpos
1496 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1499 set_iterator_to_next (&it3
, false);
1501 top_x
= it3
.current_x
- it3
.pixel_width
;
1502 /* Normally, we would exit the above loop because we
1503 found the display element whose character
1504 position is CHARPOS. For the contingency that we
1505 didn't, and stopped at the first newline from the
1506 display string, move back over the glyphs
1507 produced from the string, until we find the
1508 rightmost glyph not from the string. */
1510 && newline_in_string
1511 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1513 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1514 + it3
.glyph_row
->used
[TEXT_AREA
];
1516 while (EQ ((g
- 1)->object
, string
))
1519 top_x
-= g
->pixel_width
;
1521 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1522 + it3
.glyph_row
->used
[TEXT_AREA
]);
1528 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1529 *rtop
= max (0, window_top_y
- top_y
);
1530 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1531 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1532 - max (top_y
, window_top_y
)));
1534 if (it
.bidi_it
.paragraph_dir
== R2L
)
1540 /* Either we were asked to provide info about WINDOW_END, or
1541 CHARPOS is in the partially visible glyph row at end of
1544 void *it2data
= NULL
;
1546 SAVE_IT (it2
, it
, it2data
);
1547 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1548 move_it_by_lines (&it
, 1);
1549 if (charpos
< IT_CHARPOS (it
)
1550 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1553 RESTORE_IT (&it2
, &it2
, it2data
);
1554 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1556 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1557 *rtop
= max (0, -it2
.current_y
);
1558 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1559 - it
.last_visible_y
));
1560 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1562 - max (it2
.current_y
,
1563 WINDOW_HEADER_LINE_HEIGHT (w
))));
1565 if (it2
.bidi_it
.paragraph_dir
== R2L
)
1569 bidi_unshelve_cache (it2data
, true);
1571 bidi_unshelve_cache (itdata
, false);
1574 set_buffer_internal_1 (old_buffer
);
1580 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1581 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1582 /* For lines in an R2L paragraph, we need to mirror the X pixel
1583 coordinate wrt the text area. For the reasons, see the
1584 commentary in buffer_posn_from_coords and the explanation of
1585 the geometry used by the move_it_* functions at the end of
1586 the large commentary near the beginning of this file. */
1588 *x
= window_box_width (w
, TEXT_AREA
) - *x
- 1;
1592 /* Debugging code. */
1594 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1595 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1597 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1604 /* Return the next character from STR. Return in *LEN the length of
1605 the character. This is like STRING_CHAR_AND_LENGTH but never
1606 returns an invalid character. If we find one, we return a `?', but
1607 with the length of the invalid character. */
1610 string_char_and_length (const unsigned char *str
, int *len
)
1614 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1615 if (!CHAR_VALID_P (c
))
1616 /* We may not change the length here because other places in Emacs
1617 don't use this function, i.e. they silently accept invalid
1626 /* Given a position POS containing a valid character and byte position
1627 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1629 static struct text_pos
1630 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1632 eassert (STRINGP (string
) && nchars
>= 0);
1634 if (STRING_MULTIBYTE (string
))
1636 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1641 string_char_and_length (p
, &len
);
1644 BYTEPOS (pos
) += len
;
1648 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1654 /* Value is the text position, i.e. character and byte position,
1655 for character position CHARPOS in STRING. */
1657 static struct text_pos
1658 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1660 struct text_pos pos
;
1661 eassert (STRINGP (string
));
1662 eassert (charpos
>= 0);
1663 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1668 /* Value is a text position, i.e. character and byte position, for
1669 character position CHARPOS in C string S. MULTIBYTE_P
1670 means recognize multibyte characters. */
1672 static struct text_pos
1673 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1675 struct text_pos pos
;
1677 eassert (s
!= NULL
);
1678 eassert (charpos
>= 0);
1684 SET_TEXT_POS (pos
, 0, 0);
1687 string_char_and_length ((const unsigned char *) s
, &len
);
1690 BYTEPOS (pos
) += len
;
1694 SET_TEXT_POS (pos
, charpos
, charpos
);
1700 /* Value is the number of characters in C string S. MULTIBYTE_P
1701 means recognize multibyte characters. */
1704 number_of_chars (const char *s
, bool multibyte_p
)
1710 ptrdiff_t rest
= strlen (s
);
1712 const unsigned char *p
= (const unsigned char *) s
;
1714 for (nchars
= 0; rest
> 0; ++nchars
)
1716 string_char_and_length (p
, &len
);
1717 rest
-= len
, p
+= len
;
1721 nchars
= strlen (s
);
1727 /* Compute byte position NEWPOS->bytepos corresponding to
1728 NEWPOS->charpos. POS is a known position in string STRING.
1729 NEWPOS->charpos must be >= POS.charpos. */
1732 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1734 eassert (STRINGP (string
));
1735 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1737 if (STRING_MULTIBYTE (string
))
1738 *newpos
= string_pos_nchars_ahead (pos
, string
,
1739 CHARPOS (*newpos
) - CHARPOS (pos
));
1741 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1745 Return an estimation of the pixel height of mode or header lines on
1746 frame F. FACE_ID specifies what line's height to estimate. */
1749 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1751 #ifdef HAVE_WINDOW_SYSTEM
1752 if (FRAME_WINDOW_P (f
))
1754 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1756 /* This function is called so early when Emacs starts that the face
1757 cache and mode line face are not yet initialized. */
1758 if (FRAME_FACE_CACHE (f
))
1760 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1764 height
= FONT_HEIGHT (face
->font
);
1765 if (face
->box_line_width
> 0)
1766 height
+= 2 * face
->box_line_width
;
1777 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1778 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1779 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP, do
1780 not force the value into range. */
1783 pixel_to_glyph_coords (struct frame
*f
, int pix_x
, int pix_y
, int *x
, int *y
,
1784 NativeRectangle
*bounds
, bool noclip
)
1787 #ifdef HAVE_WINDOW_SYSTEM
1788 if (FRAME_WINDOW_P (f
))
1790 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1791 even for negative values. */
1793 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1795 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1797 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1798 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1801 STORE_NATIVE_RECT (*bounds
,
1802 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1803 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1804 FRAME_COLUMN_WIDTH (f
) - 1,
1805 FRAME_LINE_HEIGHT (f
) - 1);
1807 /* PXW: Should we clip pixels before converting to columns/lines? */
1812 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1813 pix_x
= FRAME_TOTAL_COLS (f
);
1817 else if (pix_y
> FRAME_TOTAL_LINES (f
))
1818 pix_y
= FRAME_TOTAL_LINES (f
);
1828 /* Find the glyph under window-relative coordinates X/Y in window W.
1829 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1830 strings. Return in *HPOS and *VPOS the row and column number of
1831 the glyph found. Return in *AREA the glyph area containing X.
1832 Value is a pointer to the glyph found or null if X/Y is not on
1833 text, or we can't tell because W's current matrix is not up to
1836 static struct glyph
*
1837 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1838 int *dx
, int *dy
, int *area
)
1840 struct glyph
*glyph
, *end
;
1841 struct glyph_row
*row
= NULL
;
1844 /* Find row containing Y. Give up if some row is not enabled. */
1845 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1847 row
= MATRIX_ROW (w
->current_matrix
, i
);
1848 if (!row
->enabled_p
)
1850 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1857 /* Give up if Y is not in the window. */
1858 if (i
== w
->current_matrix
->nrows
)
1861 /* Get the glyph area containing X. */
1862 if (w
->pseudo_window_p
)
1869 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1871 *area
= LEFT_MARGIN_AREA
;
1872 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1874 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1877 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1881 *area
= RIGHT_MARGIN_AREA
;
1882 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1886 /* Find glyph containing X. */
1887 glyph
= row
->glyphs
[*area
];
1888 end
= glyph
+ row
->used
[*area
];
1890 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1892 x
-= glyph
->pixel_width
;
1902 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1905 *hpos
= glyph
- row
->glyphs
[*area
];
1909 /* Convert frame-relative x/y to coordinates relative to window W.
1910 Takes pseudo-windows into account. */
1913 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1915 if (w
->pseudo_window_p
)
1917 /* A pseudo-window is always full-width, and starts at the
1918 left edge of the frame, plus a frame border. */
1919 struct frame
*f
= XFRAME (w
->frame
);
1920 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1921 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1925 *x
-= WINDOW_LEFT_EDGE_X (w
);
1926 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1930 #ifdef HAVE_WINDOW_SYSTEM
1933 Return in RECTS[] at most N clipping rectangles for glyph string S.
1934 Return the number of stored rectangles. */
1937 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1944 if (s
->row
->full_width_p
)
1946 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1947 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1948 if (s
->row
->mode_line_p
)
1949 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
1951 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
1953 /* Unless displaying a mode or menu bar line, which are always
1954 fully visible, clip to the visible part of the row. */
1955 if (s
->w
->pseudo_window_p
)
1956 r
.height
= s
->row
->visible_height
;
1958 r
.height
= s
->height
;
1962 /* This is a text line that may be partially visible. */
1963 r
.x
= window_box_left (s
->w
, s
->area
);
1964 r
.width
= window_box_width (s
->w
, s
->area
);
1965 r
.height
= s
->row
->visible_height
;
1969 if (r
.x
< s
->clip_head
->x
)
1971 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1972 r
.width
-= s
->clip_head
->x
- r
.x
;
1975 r
.x
= s
->clip_head
->x
;
1978 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1980 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1981 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1986 /* If S draws overlapping rows, it's sufficient to use the top and
1987 bottom of the window for clipping because this glyph string
1988 intentionally draws over other lines. */
1989 if (s
->for_overlaps
)
1991 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1992 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1994 /* Alas, the above simple strategy does not work for the
1995 environments with anti-aliased text: if the same text is
1996 drawn onto the same place multiple times, it gets thicker.
1997 If the overlap we are processing is for the erased cursor, we
1998 take the intersection with the rectangle of the cursor. */
1999 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2001 XRectangle rc
, r_save
= r
;
2003 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2004 rc
.y
= s
->w
->phys_cursor
.y
;
2005 rc
.width
= s
->w
->phys_cursor_width
;
2006 rc
.height
= s
->w
->phys_cursor_height
;
2008 x_intersect_rectangles (&r_save
, &rc
, &r
);
2013 /* Don't use S->y for clipping because it doesn't take partially
2014 visible lines into account. For example, it can be negative for
2015 partially visible lines at the top of a window. */
2016 if (!s
->row
->full_width_p
2017 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2018 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2020 r
.y
= max (0, s
->row
->y
);
2023 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2025 /* If drawing the cursor, don't let glyph draw outside its
2026 advertised boundaries. Cleartype does this under some circumstances. */
2027 if (s
->hl
== DRAW_CURSOR
)
2029 struct glyph
*glyph
= s
->first_glyph
;
2034 if (r
.width
>= s
->x
- r
.x
)
2035 r
.width
-= s
->x
- r
.x
;
2036 else /* R2L hscrolled row with cursor outside text area */
2040 r
.width
= min (r
.width
, glyph
->pixel_width
);
2042 /* If r.y is below window bottom, ensure that we still see a cursor. */
2043 height
= min (glyph
->ascent
+ glyph
->descent
,
2044 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2045 max_y
= window_text_bottom_y (s
->w
) - height
;
2046 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2047 if (s
->ybase
- glyph
->ascent
> max_y
)
2054 /* Don't draw cursor glyph taller than our actual glyph. */
2055 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2056 if (height
< r
.height
)
2058 max_y
= r
.y
+ r
.height
;
2059 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2060 r
.height
= min (max_y
- r
.y
, height
);
2067 XRectangle r_save
= r
;
2069 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2073 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2074 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2076 #ifdef CONVERT_FROM_XRECT
2077 CONVERT_FROM_XRECT (r
, *rects
);
2085 /* If we are processing overlapping and allowed to return
2086 multiple clipping rectangles, we exclude the row of the glyph
2087 string from the clipping rectangle. This is to avoid drawing
2088 the same text on the environment with anti-aliasing. */
2089 #ifdef CONVERT_FROM_XRECT
2092 XRectangle
*rs
= rects
;
2094 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2096 if (s
->for_overlaps
& OVERLAPS_PRED
)
2099 if (r
.y
+ r
.height
> row_y
)
2102 rs
[i
].height
= row_y
- r
.y
;
2108 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2111 if (r
.y
< row_y
+ s
->row
->visible_height
)
2113 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2115 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2116 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2125 #ifdef CONVERT_FROM_XRECT
2126 for (i
= 0; i
< n
; i
++)
2127 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2134 Return in *NR the clipping rectangle for glyph string S. */
2137 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2139 get_glyph_string_clip_rects (s
, nr
, 1);
2144 Return the position and height of the phys cursor in window W.
2145 Set w->phys_cursor_width to width of phys cursor.
2149 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2150 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2152 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2153 int x
, y
, wd
, h
, h0
, y0
, ascent
;
2155 /* Compute the width of the rectangle to draw. If on a stretch
2156 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2157 rectangle as wide as the glyph, but use a canonical character
2159 wd
= glyph
->pixel_width
;
2161 x
= w
->phys_cursor
.x
;
2168 if (glyph
->type
== STRETCH_GLYPH
2169 && !x_stretch_cursor_p
)
2170 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2171 w
->phys_cursor_width
= wd
;
2173 /* Don't let the hollow cursor glyph descend below the glyph row's
2174 ascent value, lest the hollow cursor looks funny. */
2175 y
= w
->phys_cursor
.y
;
2176 ascent
= row
->ascent
;
2177 if (row
->ascent
< glyph
->ascent
)
2179 y
=- glyph
->ascent
- row
->ascent
;
2180 ascent
= glyph
->ascent
;
2183 /* If y is below window bottom, ensure that we still see a cursor. */
2184 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2186 h
= max (h0
, ascent
+ glyph
->descent
);
2187 h0
= min (h0
, ascent
+ glyph
->descent
);
2189 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2192 h
= max (h
- (y0
- y
) + 1, h0
);
2197 y0
= window_text_bottom_y (w
) - h0
;
2205 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2206 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2211 * Remember which glyph the mouse is over.
2215 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2219 struct glyph_row
*r
, *gr
, *end_row
;
2220 enum window_part part
;
2221 enum glyph_row_area area
;
2222 int x
, y
, width
, height
;
2224 /* Try to determine frame pixel position and size of the glyph under
2225 frame pixel coordinates X/Y on frame F. */
2227 if (window_resize_pixelwise
)
2232 else if (!f
->glyphs_initialized_p
2233 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, false),
2236 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2237 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2241 w
= XWINDOW (window
);
2242 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2243 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2245 x
= window_relative_x_coord (w
, part
, gx
);
2246 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2248 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2249 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2251 if (w
->pseudo_window_p
)
2254 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2260 case ON_LEFT_MARGIN
:
2261 area
= LEFT_MARGIN_AREA
;
2264 case ON_RIGHT_MARGIN
:
2265 area
= RIGHT_MARGIN_AREA
;
2268 case ON_HEADER_LINE
:
2270 gr
= (part
== ON_HEADER_LINE
2271 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2272 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2275 goto text_glyph_row_found
;
2282 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2283 if (r
->y
+ r
->height
> y
)
2289 text_glyph_row_found
:
2292 struct glyph
*g
= gr
->glyphs
[area
];
2293 struct glyph
*end
= g
+ gr
->used
[area
];
2295 height
= gr
->height
;
2296 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2297 if (gx
+ g
->pixel_width
> x
)
2302 if (g
->type
== IMAGE_GLYPH
)
2304 /* Don't remember when mouse is over image, as
2305 image may have hot-spots. */
2306 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2309 width
= g
->pixel_width
;
2313 /* Use nominal char spacing at end of line. */
2315 gx
+= (x
/ width
) * width
;
2318 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2320 gx
+= window_box_left_offset (w
, area
);
2321 /* Don't expand over the modeline to make sure the vertical
2322 drag cursor is shown early enough. */
2323 height
= min (height
,
2324 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2329 /* Use nominal line height at end of window. */
2330 gx
= (x
/ width
) * width
;
2332 gy
+= (y
/ height
) * height
;
2333 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2334 /* See comment above. */
2335 height
= min (height
,
2336 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2340 case ON_LEFT_FRINGE
:
2341 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2342 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2343 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2344 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2347 case ON_RIGHT_FRINGE
:
2348 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2349 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2350 : window_box_right_offset (w
, TEXT_AREA
));
2351 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
2352 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
2353 && !WINDOW_RIGHTMOST_P (w
))
2354 if (gx
< WINDOW_PIXEL_WIDTH (w
) - width
)
2355 /* Make sure the vertical border can get her own glyph to the
2356 right of the one we build here. */
2357 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
) - width
;
2359 width
= WINDOW_PIXEL_WIDTH (w
) - gx
;
2361 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2365 case ON_VERTICAL_BORDER
:
2366 gx
= WINDOW_PIXEL_WIDTH (w
) - width
;
2369 case ON_VERTICAL_SCROLL_BAR
:
2370 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2372 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2373 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2374 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2376 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2380 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2381 if (r
->y
+ r
->height
> y
)
2388 height
= gr
->height
;
2391 /* Use nominal line height at end of window. */
2393 gy
+= (y
/ height
) * height
;
2397 case ON_RIGHT_DIVIDER
:
2398 gx
= WINDOW_PIXEL_WIDTH (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2399 width
= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2401 /* The bottom divider prevails. */
2402 height
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2405 case ON_BOTTOM_DIVIDER
:
2407 width
= WINDOW_PIXEL_WIDTH (w
);
2408 gy
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2409 height
= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2415 /* If there is no glyph under the mouse, then we divide the screen
2416 into a grid of the smallest glyph in the frame, and use that
2419 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2420 round down even for negative values. */
2426 gx
= (gx
/ width
) * width
;
2427 gy
= (gy
/ height
) * height
;
2433 gx
+= WINDOW_LEFT_EDGE_X (w
);
2434 gy
+= WINDOW_TOP_EDGE_Y (w
);
2437 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2439 /* Visible feedback for debugging. */
2440 #if false && defined HAVE_X_WINDOWS
2441 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2442 f
->output_data
.x
->normal_gc
,
2443 gx
, gy
, width
, height
);
2448 #endif /* HAVE_WINDOW_SYSTEM */
2451 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2454 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2455 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2457 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2460 /***********************************************************************
2461 Lisp form evaluation
2462 ***********************************************************************/
2464 /* Error handler for safe_eval and safe_call. */
2467 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2469 add_to_log ("Error during redisplay: %S signaled %S",
2470 Flist (nargs
, args
), arg
);
2474 /* Call function FUNC with the rest of NARGS - 1 arguments
2475 following. Return the result, or nil if something went
2476 wrong. Prevent redisplay during the evaluation. */
2479 safe__call (bool inhibit_quit
, ptrdiff_t nargs
, Lisp_Object func
, va_list ap
)
2483 if (inhibit_eval_during_redisplay
)
2488 ptrdiff_t count
= SPECPDL_INDEX ();
2491 SAFE_ALLOCA_LISP (args
, nargs
);
2494 for (i
= 1; i
< nargs
; i
++)
2495 args
[i
] = va_arg (ap
, Lisp_Object
);
2497 specbind (Qinhibit_redisplay
, Qt
);
2499 specbind (Qinhibit_quit
, Qt
);
2500 /* Use Qt to ensure debugger does not run,
2501 so there is no possibility of wanting to redisplay. */
2502 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2505 val
= unbind_to (count
, val
);
2512 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2517 va_start (ap
, func
);
2518 retval
= safe__call (false, nargs
, func
, ap
);
2523 /* Call function FN with one argument ARG.
2524 Return the result, or nil if something went wrong. */
2527 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2529 return safe_call (2, fn
, arg
);
2533 safe__call1 (bool inhibit_quit
, Lisp_Object fn
, ...)
2539 retval
= safe__call (inhibit_quit
, 2, fn
, ap
);
2545 safe_eval (Lisp_Object sexpr
)
2547 return safe__call1 (false, Qeval
, sexpr
);
2551 safe__eval (bool inhibit_quit
, Lisp_Object sexpr
)
2553 return safe__call1 (inhibit_quit
, Qeval
, sexpr
);
2556 /* Call function FN with two arguments ARG1 and ARG2.
2557 Return the result, or nil if something went wrong. */
2560 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2562 return safe_call (3, fn
, arg1
, arg2
);
2567 /***********************************************************************
2569 ***********************************************************************/
2571 /* Define CHECK_IT to perform sanity checks on iterators.
2572 This is for debugging. It is too slow to do unconditionally. */
2575 CHECK_IT (struct it
*it
)
2578 if (it
->method
== GET_FROM_STRING
)
2580 eassert (STRINGP (it
->string
));
2581 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2585 eassert (IT_STRING_CHARPOS (*it
) < 0);
2586 if (it
->method
== GET_FROM_BUFFER
)
2588 /* Check that character and byte positions agree. */
2589 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2594 eassert (it
->current
.dpvec_index
>= 0);
2596 eassert (it
->current
.dpvec_index
< 0);
2601 /* Check that the window end of window W is what we expect it
2602 to be---the last row in the current matrix displaying text. */
2605 CHECK_WINDOW_END (struct window
*w
)
2607 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2608 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2610 struct glyph_row
*row
;
2611 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2613 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2614 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2619 /***********************************************************************
2620 Iterator initialization
2621 ***********************************************************************/
2623 /* Initialize IT for displaying current_buffer in window W, starting
2624 at character position CHARPOS. CHARPOS < 0 means that no buffer
2625 position is specified which is useful when the iterator is assigned
2626 a position later. BYTEPOS is the byte position corresponding to
2629 If ROW is not null, calls to produce_glyphs with IT as parameter
2630 will produce glyphs in that row.
2632 BASE_FACE_ID is the id of a base face to use. It must be one of
2633 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2634 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2635 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2637 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2638 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2639 will be initialized to use the corresponding mode line glyph row of
2640 the desired matrix of W. */
2643 init_iterator (struct it
*it
, struct window
*w
,
2644 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2645 struct glyph_row
*row
, enum face_id base_face_id
)
2647 enum face_id remapped_base_face_id
= base_face_id
;
2649 /* Some precondition checks. */
2650 eassert (w
!= NULL
&& it
!= NULL
);
2651 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2654 /* If face attributes have been changed since the last redisplay,
2655 free realized faces now because they depend on face definitions
2656 that might have changed. Don't free faces while there might be
2657 desired matrices pending which reference these faces. */
2658 if (face_change
&& !inhibit_free_realized_faces
)
2660 face_change
= false;
2661 free_all_realized_faces (Qnil
);
2664 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2665 if (! NILP (Vface_remapping_alist
))
2666 remapped_base_face_id
2667 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2669 /* Use one of the mode line rows of W's desired matrix if
2673 if (base_face_id
== MODE_LINE_FACE_ID
2674 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2675 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2676 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2677 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2680 /* Clear IT, and set it->object and other IT's Lisp objects to Qnil.
2681 Other parts of redisplay rely on that. */
2682 memclear (it
, sizeof *it
);
2683 it
->current
.overlay_string_index
= -1;
2684 it
->current
.dpvec_index
= -1;
2685 it
->base_face_id
= remapped_base_face_id
;
2686 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2687 it
->paragraph_embedding
= L2R
;
2690 /* The window in which we iterate over current_buffer: */
2691 XSETWINDOW (it
->window
, w
);
2693 it
->f
= XFRAME (w
->frame
);
2697 /* Extra space between lines (on window systems only). */
2698 if (base_face_id
== DEFAULT_FACE_ID
2699 && FRAME_WINDOW_P (it
->f
))
2701 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2702 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2703 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2704 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2705 * FRAME_LINE_HEIGHT (it
->f
));
2706 else if (it
->f
->extra_line_spacing
> 0)
2707 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2710 /* If realized faces have been removed, e.g. because of face
2711 attribute changes of named faces, recompute them. When running
2712 in batch mode, the face cache of the initial frame is null. If
2713 we happen to get called, make a dummy face cache. */
2714 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2715 init_frame_faces (it
->f
);
2716 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2717 recompute_basic_faces (it
->f
);
2719 it
->override_ascent
= -1;
2721 /* Are control characters displayed as `^C'? */
2722 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2724 /* -1 means everything between a CR and the following line end
2725 is invisible. >0 means lines indented more than this value are
2727 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2729 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2731 : (!NILP (BVAR (current_buffer
, selective_display
))
2733 it
->selective_display_ellipsis_p
2734 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2736 /* Display table to use. */
2737 it
->dp
= window_display_table (w
);
2739 /* Are multibyte characters enabled in current_buffer? */
2740 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2742 /* Get the position at which the redisplay_end_trigger hook should
2743 be run, if it is to be run at all. */
2744 if (MARKERP (w
->redisplay_end_trigger
)
2745 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2746 it
->redisplay_end_trigger_charpos
2747 = marker_position (w
->redisplay_end_trigger
);
2748 else if (INTEGERP (w
->redisplay_end_trigger
))
2749 it
->redisplay_end_trigger_charpos
2750 = clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
),
2753 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2755 /* Are lines in the display truncated? */
2757 it
->line_wrap
= TRUNCATE
;
2758 if (base_face_id
== DEFAULT_FACE_ID
2760 && (WINDOW_FULL_WIDTH_P (it
->w
)
2761 || NILP (Vtruncate_partial_width_windows
)
2762 || (INTEGERP (Vtruncate_partial_width_windows
)
2763 /* PXW: Shall we do something about this? */
2764 && (XINT (Vtruncate_partial_width_windows
)
2765 <= WINDOW_TOTAL_COLS (it
->w
))))
2766 && NILP (BVAR (current_buffer
, truncate_lines
)))
2767 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2768 ? WINDOW_WRAP
: WORD_WRAP
;
2770 /* Get dimensions of truncation and continuation glyphs. These are
2771 displayed as fringe bitmaps under X, but we need them for such
2772 frames when the fringes are turned off. But leave the dimensions
2773 zero for tooltip frames, as these glyphs look ugly there and also
2774 sabotage calculations of tooltip dimensions in x-show-tip. */
2775 #ifdef HAVE_WINDOW_SYSTEM
2776 if (!(FRAME_WINDOW_P (it
->f
)
2777 && FRAMEP (tip_frame
)
2778 && it
->f
== XFRAME (tip_frame
)))
2781 if (it
->line_wrap
== TRUNCATE
)
2783 /* We will need the truncation glyph. */
2784 eassert (it
->glyph_row
== NULL
);
2785 produce_special_glyphs (it
, IT_TRUNCATION
);
2786 it
->truncation_pixel_width
= it
->pixel_width
;
2790 /* We will need the continuation glyph. */
2791 eassert (it
->glyph_row
== NULL
);
2792 produce_special_glyphs (it
, IT_CONTINUATION
);
2793 it
->continuation_pixel_width
= it
->pixel_width
;
2797 /* Reset these values to zero because the produce_special_glyphs
2798 above has changed them. */
2799 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2800 it
->phys_ascent
= it
->phys_descent
= 0;
2802 /* Set this after getting the dimensions of truncation and
2803 continuation glyphs, so that we don't produce glyphs when calling
2804 produce_special_glyphs, above. */
2805 it
->glyph_row
= row
;
2806 it
->area
= TEXT_AREA
;
2808 /* Get the dimensions of the display area. The display area
2809 consists of the visible window area plus a horizontally scrolled
2810 part to the left of the window. All x-values are relative to the
2811 start of this total display area. */
2812 if (base_face_id
!= DEFAULT_FACE_ID
)
2814 /* Mode lines, menu bar in terminal frames. */
2815 it
->first_visible_x
= 0;
2816 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2821 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2822 it
->last_visible_x
= (it
->first_visible_x
2823 + window_box_width (w
, TEXT_AREA
));
2825 /* If we truncate lines, leave room for the truncation glyph(s) at
2826 the right margin. Otherwise, leave room for the continuation
2827 glyph(s). Done only if the window has no right fringe. */
2828 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
2830 if (it
->line_wrap
== TRUNCATE
)
2831 it
->last_visible_x
-= it
->truncation_pixel_width
;
2833 it
->last_visible_x
-= it
->continuation_pixel_width
;
2836 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2837 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2840 /* Leave room for a border glyph. */
2841 if (!FRAME_WINDOW_P (it
->f
)
2842 && !WINDOW_RIGHTMOST_P (it
->w
))
2843 it
->last_visible_x
-= 1;
2845 it
->last_visible_y
= window_text_bottom_y (w
);
2847 /* For mode lines and alike, arrange for the first glyph having a
2848 left box line if the face specifies a box. */
2849 if (base_face_id
!= DEFAULT_FACE_ID
)
2853 it
->face_id
= remapped_base_face_id
;
2855 /* If we have a boxed mode line, make the first character appear
2856 with a left box line. */
2857 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2858 if (face
&& face
->box
!= FACE_NO_BOX
)
2859 it
->start_of_box_run_p
= true;
2862 /* If a buffer position was specified, set the iterator there,
2863 getting overlays and face properties from that position. */
2864 if (charpos
>= BUF_BEG (current_buffer
))
2866 it
->stop_charpos
= charpos
;
2867 it
->end_charpos
= ZV
;
2868 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2869 IT_CHARPOS (*it
) = charpos
;
2870 IT_BYTEPOS (*it
) = bytepos
;
2872 /* We will rely on `reseat' to set this up properly, via
2873 handle_face_prop. */
2874 it
->face_id
= it
->base_face_id
;
2876 it
->start
= it
->current
;
2877 /* Do we need to reorder bidirectional text? Not if this is a
2878 unibyte buffer: by definition, none of the single-byte
2879 characters are strong R2L, so no reordering is needed. And
2880 bidi.c doesn't support unibyte buffers anyway. Also, don't
2881 reorder while we are loading loadup.el, since the tables of
2882 character properties needed for reordering are not yet
2886 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2889 /* If we are to reorder bidirectional text, init the bidi
2893 /* Since we don't know at this point whether there will be
2894 any R2L lines in the window, we reserve space for
2895 truncation/continuation glyphs even if only the left
2896 fringe is absent. */
2897 if (base_face_id
== DEFAULT_FACE_ID
2898 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
2899 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
2901 if (it
->line_wrap
== TRUNCATE
)
2902 it
->last_visible_x
-= it
->truncation_pixel_width
;
2904 it
->last_visible_x
-= it
->continuation_pixel_width
;
2906 /* Note the paragraph direction that this buffer wants to
2908 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2910 it
->paragraph_embedding
= L2R
;
2911 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2913 it
->paragraph_embedding
= R2L
;
2915 it
->paragraph_embedding
= NEUTRAL_DIR
;
2916 bidi_unshelve_cache (NULL
, false);
2917 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2921 /* Compute faces etc. */
2922 reseat (it
, it
->current
.pos
, true);
2929 /* Initialize IT for the display of window W with window start POS. */
2932 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2934 struct glyph_row
*row
;
2935 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
2937 row
= w
->desired_matrix
->rows
+ first_vpos
;
2938 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2939 it
->first_vpos
= first_vpos
;
2941 /* Don't reseat to previous visible line start if current start
2942 position is in a string or image. */
2943 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2945 int first_y
= it
->current_y
;
2947 /* If window start is not at a line start, skip forward to POS to
2948 get the correct continuation lines width. */
2949 bool start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2950 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2951 if (!start_at_line_beg_p
)
2955 reseat_at_previous_visible_line_start (it
);
2956 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2958 new_x
= it
->current_x
+ it
->pixel_width
;
2960 /* If lines are continued, this line may end in the middle
2961 of a multi-glyph character (e.g. a control character
2962 displayed as \003, or in the middle of an overlay
2963 string). In this case move_it_to above will not have
2964 taken us to the start of the continuation line but to the
2965 end of the continued line. */
2966 if (it
->current_x
> 0
2967 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2968 && (/* And glyph doesn't fit on the line. */
2969 new_x
> it
->last_visible_x
2970 /* Or it fits exactly and we're on a window
2972 || (new_x
== it
->last_visible_x
2973 && FRAME_WINDOW_P (it
->f
)
2974 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2975 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2976 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2978 if ((it
->current
.dpvec_index
>= 0
2979 || it
->current
.overlay_string_index
>= 0)
2980 /* If we are on a newline from a display vector or
2981 overlay string, then we are already at the end of
2982 a screen line; no need to go to the next line in
2983 that case, as this line is not really continued.
2984 (If we do go to the next line, C-e will not DTRT.) */
2987 set_iterator_to_next (it
, true);
2988 move_it_in_display_line_to (it
, -1, -1, 0);
2991 it
->continuation_lines_width
+= it
->current_x
;
2993 /* If the character at POS is displayed via a display
2994 vector, move_it_to above stops at the final glyph of
2995 IT->dpvec. To make the caller redisplay that character
2996 again (a.k.a. start at POS), we need to reset the
2997 dpvec_index to the beginning of IT->dpvec. */
2998 else if (it
->current
.dpvec_index
>= 0)
2999 it
->current
.dpvec_index
= 0;
3001 /* We're starting a new display line, not affected by the
3002 height of the continued line, so clear the appropriate
3003 fields in the iterator structure. */
3004 it
->max_ascent
= it
->max_descent
= 0;
3005 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3007 it
->current_y
= first_y
;
3009 it
->current_x
= it
->hpos
= 0;
3015 /* Return true if POS is a position in ellipses displayed for invisible
3016 text. W is the window we display, for text property lookup. */
3019 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3021 Lisp_Object prop
, window
;
3022 bool ellipses_p
= false;
3023 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3025 /* If POS specifies a position in a display vector, this might
3026 be for an ellipsis displayed for invisible text. We won't
3027 get the iterator set up for delivering that ellipsis unless
3028 we make sure that it gets aware of the invisible text. */
3029 if (pos
->dpvec_index
>= 0
3030 && pos
->overlay_string_index
< 0
3031 && CHARPOS (pos
->string_pos
) < 0
3033 && (XSETWINDOW (window
, w
),
3034 prop
= Fget_char_property (make_number (charpos
),
3035 Qinvisible
, window
),
3036 TEXT_PROP_MEANS_INVISIBLE (prop
) == 0))
3038 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3040 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3047 /* Initialize IT for stepping through current_buffer in window W,
3048 starting at position POS that includes overlay string and display
3049 vector/ control character translation position information. Value
3050 is false if there are overlay strings with newlines at POS. */
3053 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3055 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3057 bool overlay_strings_with_newlines
= false;
3059 /* If POS specifies a position in a display vector, this might
3060 be for an ellipsis displayed for invisible text. We won't
3061 get the iterator set up for delivering that ellipsis unless
3062 we make sure that it gets aware of the invisible text. */
3063 if (in_ellipses_for_invisible_text_p (pos
, w
))
3069 /* Keep in mind: the call to reseat in init_iterator skips invisible
3070 text, so we might end up at a position different from POS. This
3071 is only a problem when POS is a row start after a newline and an
3072 overlay starts there with an after-string, and the overlay has an
3073 invisible property. Since we don't skip invisible text in
3074 display_line and elsewhere immediately after consuming the
3075 newline before the row start, such a POS will not be in a string,
3076 but the call to init_iterator below will move us to the
3078 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3080 /* This only scans the current chunk -- it should scan all chunks.
3081 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3082 to 16 in 22.1 to make this a lesser problem. */
3083 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3085 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3086 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3088 while (s
< e
&& *s
!= '\n')
3093 overlay_strings_with_newlines
= true;
3098 /* If position is within an overlay string, set up IT to the right
3100 if (pos
->overlay_string_index
>= 0)
3104 /* If the first overlay string happens to have a `display'
3105 property for an image, the iterator will be set up for that
3106 image, and we have to undo that setup first before we can
3107 correct the overlay string index. */
3108 if (it
->method
== GET_FROM_IMAGE
)
3111 /* We already have the first chunk of overlay strings in
3112 IT->overlay_strings. Load more until the one for
3113 pos->overlay_string_index is in IT->overlay_strings. */
3114 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3116 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3117 it
->current
.overlay_string_index
= 0;
3120 load_overlay_strings (it
, 0);
3121 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3125 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3126 relative_index
= (it
->current
.overlay_string_index
3127 % OVERLAY_STRING_CHUNK_SIZE
);
3128 it
->string
= it
->overlay_strings
[relative_index
];
3129 eassert (STRINGP (it
->string
));
3130 it
->current
.string_pos
= pos
->string_pos
;
3131 it
->method
= GET_FROM_STRING
;
3132 it
->end_charpos
= SCHARS (it
->string
);
3133 /* Set up the bidi iterator for this overlay string. */
3136 it
->bidi_it
.string
.lstring
= it
->string
;
3137 it
->bidi_it
.string
.s
= NULL
;
3138 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3139 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3140 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3141 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3142 it
->bidi_it
.w
= it
->w
;
3143 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3144 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3146 /* Synchronize the state of the bidi iterator with
3147 pos->string_pos. For any string position other than
3148 zero, this will be done automagically when we resume
3149 iteration over the string and get_visually_first_element
3150 is called. But if string_pos is zero, and the string is
3151 to be reordered for display, we need to resync manually,
3152 since it could be that the iteration state recorded in
3153 pos ended at string_pos of 0 moving backwards in string. */
3154 if (CHARPOS (pos
->string_pos
) == 0)
3156 get_visually_first_element (it
);
3157 if (IT_STRING_CHARPOS (*it
) != 0)
3160 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3161 bidi_move_to_visually_next (&it
->bidi_it
);
3162 } while (it
->bidi_it
.charpos
!= 0);
3164 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3165 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3169 if (CHARPOS (pos
->string_pos
) >= 0)
3171 /* Recorded position is not in an overlay string, but in another
3172 string. This can only be a string from a `display' property.
3173 IT should already be filled with that string. */
3174 it
->current
.string_pos
= pos
->string_pos
;
3175 eassert (STRINGP (it
->string
));
3177 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3178 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3181 /* Restore position in display vector translations, control
3182 character translations or ellipses. */
3183 if (pos
->dpvec_index
>= 0)
3185 if (it
->dpvec
== NULL
)
3186 get_next_display_element (it
);
3187 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3188 it
->current
.dpvec_index
= pos
->dpvec_index
;
3192 return !overlay_strings_with_newlines
;
3196 /* Initialize IT for stepping through current_buffer in window W
3197 starting at ROW->start. */
3200 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3202 init_from_display_pos (it
, w
, &row
->start
);
3203 it
->start
= row
->start
;
3204 it
->continuation_lines_width
= row
->continuation_lines_width
;
3209 /* Initialize IT for stepping through current_buffer in window W
3210 starting in the line following ROW, i.e. starting at ROW->end.
3211 Value is false if there are overlay strings with newlines at ROW's
3215 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3217 bool success
= false;
3219 if (init_from_display_pos (it
, w
, &row
->end
))
3221 if (row
->continued_p
)
3222 it
->continuation_lines_width
3223 = row
->continuation_lines_width
+ row
->pixel_width
;
3234 /***********************************************************************
3236 ***********************************************************************/
3238 /* Called when IT reaches IT->stop_charpos. Handle text property and
3239 overlay changes. Set IT->stop_charpos to the next position where
3243 handle_stop (struct it
*it
)
3245 enum prop_handled handled
;
3246 bool handle_overlay_change_p
;
3250 it
->current
.dpvec_index
= -1;
3251 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3252 it
->ellipsis_p
= false;
3254 /* Use face of preceding text for ellipsis (if invisible) */
3255 if (it
->selective_display_ellipsis_p
)
3256 it
->saved_face_id
= it
->face_id
;
3258 /* Here's the description of the semantics of, and the logic behind,
3259 the various HANDLED_* statuses:
3261 HANDLED_NORMALLY means the handler did its job, and the loop
3262 should proceed to calling the next handler in order.
3264 HANDLED_RECOMPUTE_PROPS means the handler caused a significant
3265 change in the properties and overlays at current position, so the
3266 loop should be restarted, to re-invoke the handlers that were
3267 already called. This happens when fontification-functions were
3268 called by handle_fontified_prop, and actually fontified
3269 something. Another case where HANDLED_RECOMPUTE_PROPS is
3270 returned is when we discover overlay strings that need to be
3271 displayed right away. The loop below will continue for as long
3272 as the status is HANDLED_RECOMPUTE_PROPS.
3274 HANDLED_RETURN means return immediately to the caller, to
3275 continue iteration without calling any further handlers. This is
3276 used when we need to act on some property right away, for example
3277 when we need to display the ellipsis or a replacing display
3278 property, such as display string or image.
3280 HANDLED_OVERLAY_STRING_CONSUMED means an overlay string was just
3281 consumed, and the handler switched to the next overlay string.
3282 This signals the loop below to refrain from looking for more
3283 overlays before all the overlay strings of the current overlay
3286 Some of the handlers called by the loop push the iterator state
3287 onto the stack (see 'push_it'), and arrange for the iteration to
3288 continue with another object, such as an image, a display string,
3289 or an overlay string. In most such cases, it->stop_charpos is
3290 set to the first character of the string, so that when the
3291 iteration resumes, this function will immediately be called
3292 again, to examine the properties at the beginning of the string.
3294 When a display or overlay string is exhausted, the iterator state
3295 is popped (see 'pop_it'), and iteration continues with the
3296 previous object. Again, in many such cases this function is
3297 called again to find the next position where properties might
3302 handled
= HANDLED_NORMALLY
;
3304 /* Call text property handlers. */
3305 for (p
= it_props
; p
->handler
; ++p
)
3307 handled
= p
->handler (it
);
3309 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3311 else if (handled
== HANDLED_RETURN
)
3313 /* We still want to show before and after strings from
3314 overlays even if the actual buffer text is replaced. */
3315 if (!handle_overlay_change_p
3317 /* Don't call get_overlay_strings_1 if we already
3318 have overlay strings loaded, because doing so
3319 will load them again and push the iterator state
3320 onto the stack one more time, which is not
3321 expected by the rest of the code that processes
3323 || (it
->current
.overlay_string_index
< 0
3324 && !get_overlay_strings_1 (it
, 0, false)))
3327 setup_for_ellipsis (it
, 0);
3328 /* When handling a display spec, we might load an
3329 empty string. In that case, discard it here. We
3330 used to discard it in handle_single_display_spec,
3331 but that causes get_overlay_strings_1, above, to
3332 ignore overlay strings that we must check. */
3333 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3337 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3341 it
->string_from_display_prop_p
= false;
3342 it
->from_disp_prop_p
= false;
3343 handle_overlay_change_p
= false;
3345 handled
= HANDLED_RECOMPUTE_PROPS
;
3348 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3349 handle_overlay_change_p
= false;
3352 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3354 /* Don't check for overlay strings below when set to deliver
3355 characters from a display vector. */
3356 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3357 handle_overlay_change_p
= false;
3359 /* Handle overlay changes.
3360 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3361 if it finds overlays. */
3362 if (handle_overlay_change_p
)
3363 handled
= handle_overlay_change (it
);
3368 setup_for_ellipsis (it
, 0);
3372 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3374 /* Determine where to stop next. */
3375 if (handled
== HANDLED_NORMALLY
)
3376 compute_stop_pos (it
);
3380 /* Compute IT->stop_charpos from text property and overlay change
3381 information for IT's current position. */
3384 compute_stop_pos (struct it
*it
)
3386 register INTERVAL iv
, next_iv
;
3387 Lisp_Object object
, limit
, position
;
3388 ptrdiff_t charpos
, bytepos
;
3390 if (STRINGP (it
->string
))
3392 /* Strings are usually short, so don't limit the search for
3394 it
->stop_charpos
= it
->end_charpos
;
3395 object
= it
->string
;
3397 charpos
= IT_STRING_CHARPOS (*it
);
3398 bytepos
= IT_STRING_BYTEPOS (*it
);
3404 /* If end_charpos is out of range for some reason, such as a
3405 misbehaving display function, rationalize it (Bug#5984). */
3406 if (it
->end_charpos
> ZV
)
3407 it
->end_charpos
= ZV
;
3408 it
->stop_charpos
= it
->end_charpos
;
3410 /* If next overlay change is in front of the current stop pos
3411 (which is IT->end_charpos), stop there. Note: value of
3412 next_overlay_change is point-max if no overlay change
3414 charpos
= IT_CHARPOS (*it
);
3415 bytepos
= IT_BYTEPOS (*it
);
3416 pos
= next_overlay_change (charpos
);
3417 if (pos
< it
->stop_charpos
)
3418 it
->stop_charpos
= pos
;
3420 /* Set up variables for computing the stop position from text
3421 property changes. */
3422 XSETBUFFER (object
, current_buffer
);
3423 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3426 /* Get the interval containing IT's position. Value is a null
3427 interval if there isn't such an interval. */
3428 position
= make_number (charpos
);
3429 iv
= validate_interval_range (object
, &position
, &position
, false);
3432 Lisp_Object values_here
[LAST_PROP_IDX
];
3435 /* Get properties here. */
3436 for (p
= it_props
; p
->handler
; ++p
)
3437 values_here
[p
->idx
] = textget (iv
->plist
,
3438 builtin_lisp_symbol (p
->name
));
3440 /* Look for an interval following iv that has different
3442 for (next_iv
= next_interval (iv
);
3445 || XFASTINT (limit
) > next_iv
->position
));
3446 next_iv
= next_interval (next_iv
))
3448 for (p
= it_props
; p
->handler
; ++p
)
3450 Lisp_Object new_value
= textget (next_iv
->plist
,
3451 builtin_lisp_symbol (p
->name
));
3452 if (!EQ (values_here
[p
->idx
], new_value
))
3462 if (INTEGERP (limit
)
3463 && next_iv
->position
>= XFASTINT (limit
))
3464 /* No text property change up to limit. */
3465 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3467 /* Text properties change in next_iv. */
3468 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3472 if (it
->cmp_it
.id
< 0)
3474 ptrdiff_t stoppos
= it
->end_charpos
;
3476 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3478 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3479 stoppos
, it
->string
);
3482 eassert (STRINGP (it
->string
)
3483 || (it
->stop_charpos
>= BEGV
3484 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3488 /* Return the position of the next overlay change after POS in
3489 current_buffer. Value is point-max if no overlay change
3490 follows. This is like `next-overlay-change' but doesn't use
3494 next_overlay_change (ptrdiff_t pos
)
3496 ptrdiff_t i
, noverlays
;
3498 Lisp_Object
*overlays
;
3501 /* Get all overlays at the given position. */
3502 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, true);
3504 /* If any of these overlays ends before endpos,
3505 use its ending point instead. */
3506 for (i
= 0; i
< noverlays
; ++i
)
3511 oend
= OVERLAY_END (overlays
[i
]);
3512 oendpos
= OVERLAY_POSITION (oend
);
3513 endpos
= min (endpos
, oendpos
);
3520 /* How many characters forward to search for a display property or
3521 display string. Searching too far forward makes the bidi display
3522 sluggish, especially in small windows. */
3523 #define MAX_DISP_SCAN 250
3525 /* Return the character position of a display string at or after
3526 position specified by POSITION. If no display string exists at or
3527 after POSITION, return ZV. A display string is either an overlay
3528 with `display' property whose value is a string, or a `display'
3529 text property whose value is a string. STRING is data about the
3530 string to iterate; if STRING->lstring is nil, we are iterating a
3531 buffer. FRAME_WINDOW_P is true when we are displaying a window
3532 on a GUI frame. DISP_PROP is set to zero if we searched
3533 MAX_DISP_SCAN characters forward without finding any display
3534 strings, non-zero otherwise. It is set to 2 if the display string
3535 uses any kind of `(space ...)' spec that will produce a stretch of
3536 white space in the text area. */
3538 compute_display_string_pos (struct text_pos
*position
,
3539 struct bidi_string_data
*string
,
3541 bool frame_window_p
, int *disp_prop
)
3543 /* OBJECT = nil means current buffer. */
3544 Lisp_Object object
, object1
;
3545 Lisp_Object pos
, spec
, limpos
;
3546 bool string_p
= string
&& (STRINGP (string
->lstring
) || string
->s
);
3547 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3548 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3549 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3551 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3552 struct text_pos tpos
;
3555 if (string
&& STRINGP (string
->lstring
))
3556 object1
= object
= string
->lstring
;
3557 else if (w
&& !string_p
)
3559 XSETWINDOW (object
, w
);
3563 object1
= object
= Qnil
;
3568 /* We don't support display properties whose values are strings
3569 that have display string properties. */
3570 || string
->from_disp_str
3571 /* C strings cannot have display properties. */
3572 || (string
->s
&& !STRINGP (object
)))
3578 /* If the character at CHARPOS is where the display string begins,
3580 pos
= make_number (charpos
);
3581 if (STRINGP (object
))
3582 bufpos
= string
->bufpos
;
3586 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3588 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3591 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3599 /* Look forward for the first character with a `display' property
3600 that will replace the underlying text when displayed. */
3601 limpos
= make_number (lim
);
3603 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3604 CHARPOS (tpos
) = XFASTINT (pos
);
3605 if (CHARPOS (tpos
) >= lim
)
3610 if (STRINGP (object
))
3611 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3613 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3614 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3615 if (!STRINGP (object
))
3616 bufpos
= CHARPOS (tpos
);
3617 } while (NILP (spec
)
3618 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3619 bufpos
, frame_window_p
)));
3623 return CHARPOS (tpos
);
3626 /* Return the character position of the end of the display string that
3627 started at CHARPOS. If there's no display string at CHARPOS,
3628 return -1. A display string is either an overlay with `display'
3629 property whose value is a string or a `display' text property whose
3630 value is a string. */
3632 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3634 /* OBJECT = nil means current buffer. */
3635 Lisp_Object object
=
3636 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3637 Lisp_Object pos
= make_number (charpos
);
3639 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3641 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3644 /* It could happen that the display property or overlay was removed
3645 since we found it in compute_display_string_pos above. One way
3646 this can happen is if JIT font-lock was called (through
3647 handle_fontified_prop), and jit-lock-functions remove text
3648 properties or overlays from the portion of buffer that includes
3649 CHARPOS. Muse mode is known to do that, for example. In this
3650 case, we return -1 to the caller, to signal that no display
3651 string is actually present at CHARPOS. See bidi_fetch_char for
3652 how this is handled.
3654 An alternative would be to never look for display properties past
3655 it->stop_charpos. But neither compute_display_string_pos nor
3656 bidi_fetch_char that calls it know or care where the next
3658 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3661 /* Look forward for the first character where the `display' property
3663 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3665 return XFASTINT (pos
);
3670 /***********************************************************************
3672 ***********************************************************************/
3674 /* Handle changes in the `fontified' property of the current buffer by
3675 calling hook functions from Qfontification_functions to fontify
3678 static enum prop_handled
3679 handle_fontified_prop (struct it
*it
)
3681 Lisp_Object prop
, pos
;
3682 enum prop_handled handled
= HANDLED_NORMALLY
;
3684 if (!NILP (Vmemory_full
))
3687 /* Get the value of the `fontified' property at IT's current buffer
3688 position. (The `fontified' property doesn't have a special
3689 meaning in strings.) If the value is nil, call functions from
3690 Qfontification_functions. */
3691 if (!STRINGP (it
->string
)
3693 && !NILP (Vfontification_functions
)
3694 && !NILP (Vrun_hooks
)
3695 && (pos
= make_number (IT_CHARPOS (*it
)),
3696 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3697 /* Ignore the special cased nil value always present at EOB since
3698 no amount of fontifying will be able to change it. */
3699 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3701 ptrdiff_t count
= SPECPDL_INDEX ();
3703 struct buffer
*obuf
= current_buffer
;
3704 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3705 bool old_clip_changed
= current_buffer
->clip_changed
;
3707 val
= Vfontification_functions
;
3708 specbind (Qfontification_functions
, Qnil
);
3710 eassert (it
->end_charpos
== ZV
);
3712 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3713 safe_call1 (val
, pos
);
3716 Lisp_Object fns
, fn
;
3717 struct gcpro gcpro1
, gcpro2
;
3722 for (; CONSP (val
); val
= XCDR (val
))
3728 /* A value of t indicates this hook has a local
3729 binding; it means to run the global binding too.
3730 In a global value, t should not occur. If it
3731 does, we must ignore it to avoid an endless
3733 for (fns
= Fdefault_value (Qfontification_functions
);
3739 safe_call1 (fn
, pos
);
3743 safe_call1 (fn
, pos
);
3749 unbind_to (count
, Qnil
);
3751 /* Fontification functions routinely call `save-restriction'.
3752 Normally, this tags clip_changed, which can confuse redisplay
3753 (see discussion in Bug#6671). Since we don't perform any
3754 special handling of fontification changes in the case where
3755 `save-restriction' isn't called, there's no point doing so in
3756 this case either. So, if the buffer's restrictions are
3757 actually left unchanged, reset clip_changed. */
3758 if (obuf
== current_buffer
)
3760 if (begv
== BEGV
&& zv
== ZV
)
3761 current_buffer
->clip_changed
= old_clip_changed
;
3763 /* There isn't much we can reasonably do to protect against
3764 misbehaving fontification, but here's a fig leaf. */
3765 else if (BUFFER_LIVE_P (obuf
))
3766 set_buffer_internal_1 (obuf
);
3768 /* The fontification code may have added/removed text.
3769 It could do even a lot worse, but let's at least protect against
3770 the most obvious case where only the text past `pos' gets changed',
3771 as is/was done in grep.el where some escapes sequences are turned
3772 into face properties (bug#7876). */
3773 it
->end_charpos
= ZV
;
3775 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3776 something. This avoids an endless loop if they failed to
3777 fontify the text for which reason ever. */
3778 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3779 handled
= HANDLED_RECOMPUTE_PROPS
;
3787 /***********************************************************************
3789 ***********************************************************************/
3791 /* Set up iterator IT from face properties at its current position.
3792 Called from handle_stop. */
3794 static enum prop_handled
3795 handle_face_prop (struct it
*it
)
3798 ptrdiff_t next_stop
;
3800 if (!STRINGP (it
->string
))
3803 = face_at_buffer_position (it
->w
,
3807 + TEXT_PROP_DISTANCE_LIMIT
),
3808 false, it
->base_face_id
);
3810 /* Is this a start of a run of characters with box face?
3811 Caveat: this can be called for a freshly initialized
3812 iterator; face_id is -1 in this case. We know that the new
3813 face will not change until limit, i.e. if the new face has a
3814 box, all characters up to limit will have one. But, as
3815 usual, we don't know whether limit is really the end. */
3816 if (new_face_id
!= it
->face_id
)
3818 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3819 /* If it->face_id is -1, old_face below will be NULL, see
3820 the definition of FACE_FROM_ID. This will happen if this
3821 is the initial call that gets the face. */
3822 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3824 /* If the value of face_id of the iterator is -1, we have to
3825 look in front of IT's position and see whether there is a
3826 face there that's different from new_face_id. */
3827 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3829 int prev_face_id
= face_before_it_pos (it
);
3831 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3834 /* If the new face has a box, but the old face does not,
3835 this is the start of a run of characters with box face,
3836 i.e. this character has a shadow on the left side. */
3837 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3838 && (old_face
== NULL
|| !old_face
->box
));
3839 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3847 Lisp_Object from_overlay
3848 = (it
->current
.overlay_string_index
>= 0
3849 ? it
->string_overlays
[it
->current
.overlay_string_index
3850 % OVERLAY_STRING_CHUNK_SIZE
]
3853 /* See if we got to this string directly or indirectly from
3854 an overlay property. That includes the before-string or
3855 after-string of an overlay, strings in display properties
3856 provided by an overlay, their text properties, etc.
3858 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3859 if (! NILP (from_overlay
))
3860 for (i
= it
->sp
- 1; i
>= 0; i
--)
3862 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3864 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3865 % OVERLAY_STRING_CHUNK_SIZE
];
3866 else if (! NILP (it
->stack
[i
].from_overlay
))
3867 from_overlay
= it
->stack
[i
].from_overlay
;
3869 if (!NILP (from_overlay
))
3873 if (! NILP (from_overlay
))
3875 bufpos
= IT_CHARPOS (*it
);
3876 /* For a string from an overlay, the base face depends
3877 only on text properties and ignores overlays. */
3879 = face_for_overlay_string (it
->w
,
3883 + TEXT_PROP_DISTANCE_LIMIT
),
3891 /* For strings from a `display' property, use the face at
3892 IT's current buffer position as the base face to merge
3893 with, so that overlay strings appear in the same face as
3894 surrounding text, unless they specify their own faces.
3895 For strings from wrap-prefix and line-prefix properties,
3896 use the default face, possibly remapped via
3897 Vface_remapping_alist. */
3898 /* Note that the fact that we use the face at _buffer_
3899 position means that a 'display' property on an overlay
3900 string will not inherit the face of that overlay string,
3901 but will instead revert to the face of buffer text
3902 covered by the overlay. This is visible, e.g., when the
3903 overlay specifies a box face, but neither the buffer nor
3904 the display string do. This sounds like a design bug,
3905 but Emacs always did that since v21.1, so changing that
3906 might be a big deal. */
3907 base_face_id
= it
->string_from_prefix_prop_p
3908 ? (!NILP (Vface_remapping_alist
)
3909 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3911 : underlying_face_id (it
);
3914 new_face_id
= face_at_string_position (it
->w
,
3916 IT_STRING_CHARPOS (*it
),
3919 base_face_id
, false);
3921 /* Is this a start of a run of characters with box? Caveat:
3922 this can be called for a freshly allocated iterator; face_id
3923 is -1 is this case. We know that the new face will not
3924 change until the next check pos, i.e. if the new face has a
3925 box, all characters up to that position will have a
3926 box. But, as usual, we don't know whether that position
3927 is really the end. */
3928 if (new_face_id
!= it
->face_id
)
3930 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3931 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3933 /* If new face has a box but old face hasn't, this is the
3934 start of a run of characters with box, i.e. it has a
3935 shadow on the left side. */
3936 it
->start_of_box_run_p
3937 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3938 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3942 it
->face_id
= new_face_id
;
3943 return HANDLED_NORMALLY
;
3947 /* Return the ID of the face ``underlying'' IT's current position,
3948 which is in a string. If the iterator is associated with a
3949 buffer, return the face at IT's current buffer position.
3950 Otherwise, use the iterator's base_face_id. */
3953 underlying_face_id (struct it
*it
)
3955 int face_id
= it
->base_face_id
, i
;
3957 eassert (STRINGP (it
->string
));
3959 for (i
= it
->sp
- 1; i
>= 0; --i
)
3960 if (NILP (it
->stack
[i
].string
))
3961 face_id
= it
->stack
[i
].face_id
;
3967 /* Compute the face one character before or after the current position
3968 of IT, in the visual order. BEFORE_P means get the face
3969 in front (to the left in L2R paragraphs, to the right in R2L
3970 paragraphs) of IT's screen position. Value is the ID of the face. */
3973 face_before_or_after_it_pos (struct it
*it
, bool before_p
)
3976 ptrdiff_t next_check_charpos
;
3978 void *it_copy_data
= NULL
;
3980 eassert (it
->s
== NULL
);
3982 if (STRINGP (it
->string
))
3984 ptrdiff_t bufpos
, charpos
;
3987 /* No face change past the end of the string (for the case
3988 we are padding with spaces). No face change before the
3990 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3991 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3996 /* Set charpos to the position before or after IT's current
3997 position, in the logical order, which in the non-bidi
3998 case is the same as the visual order. */
4000 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4001 else if (it
->what
== IT_COMPOSITION
)
4002 /* For composition, we must check the character after the
4004 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4006 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4012 /* With bidi iteration, the character before the current
4013 in the visual order cannot be found by simple
4014 iteration, because "reverse" reordering is not
4015 supported. Instead, we need to use the move_it_*
4016 family of functions. */
4017 /* Ignore face changes before the first visible
4018 character on this display line. */
4019 if (it
->current_x
<= it
->first_visible_x
)
4021 SAVE_IT (it_copy
, *it
, it_copy_data
);
4022 /* Implementation note: Since move_it_in_display_line
4023 works in the iterator geometry, and thinks the first
4024 character is always the leftmost, even in R2L lines,
4025 we don't need to distinguish between the R2L and L2R
4027 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4028 it_copy
.current_x
- 1, MOVE_TO_X
);
4029 charpos
= IT_STRING_CHARPOS (it_copy
);
4030 RESTORE_IT (it
, it
, it_copy_data
);
4034 /* Set charpos to the string position of the character
4035 that comes after IT's current position in the visual
4037 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4041 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4043 charpos
= it_copy
.bidi_it
.charpos
;
4046 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4048 if (it
->current
.overlay_string_index
>= 0)
4049 bufpos
= IT_CHARPOS (*it
);
4053 base_face_id
= underlying_face_id (it
);
4055 /* Get the face for ASCII, or unibyte. */
4056 face_id
= face_at_string_position (it
->w
,
4060 &next_check_charpos
,
4061 base_face_id
, false);
4063 /* Correct the face for charsets different from ASCII. Do it
4064 for the multibyte case only. The face returned above is
4065 suitable for unibyte text if IT->string is unibyte. */
4066 if (STRING_MULTIBYTE (it
->string
))
4068 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4069 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4071 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4073 c
= string_char_and_length (p
, &len
);
4074 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4079 struct text_pos pos
;
4081 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4082 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4085 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4086 pos
= it
->current
.pos
;
4091 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4094 if (it
->what
== IT_COMPOSITION
)
4096 /* For composition, we must check the position after
4098 pos
.charpos
+= it
->cmp_it
.nchars
;
4099 pos
.bytepos
+= it
->len
;
4102 INC_TEXT_POS (pos
, it
->multibyte_p
);
4109 /* With bidi iteration, the character before the current
4110 in the visual order cannot be found by simple
4111 iteration, because "reverse" reordering is not
4112 supported. Instead, we need to use the move_it_*
4113 family of functions. */
4114 /* Ignore face changes before the first visible
4115 character on this display line. */
4116 if (it
->current_x
<= it
->first_visible_x
)
4118 SAVE_IT (it_copy
, *it
, it_copy_data
);
4119 /* Implementation note: Since move_it_in_display_line
4120 works in the iterator geometry, and thinks the first
4121 character is always the leftmost, even in R2L lines,
4122 we don't need to distinguish between the R2L and L2R
4124 move_it_in_display_line (&it_copy
, ZV
,
4125 it_copy
.current_x
- 1, MOVE_TO_X
);
4126 pos
= it_copy
.current
.pos
;
4127 RESTORE_IT (it
, it
, it_copy_data
);
4131 /* Set charpos to the buffer position of the character
4132 that comes after IT's current position in the visual
4134 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4138 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4141 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4144 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4146 /* Determine face for CHARSET_ASCII, or unibyte. */
4147 face_id
= face_at_buffer_position (it
->w
,
4149 &next_check_charpos
,
4152 /* Correct the face for charsets different from ASCII. Do it
4153 for the multibyte case only. The face returned above is
4154 suitable for unibyte text if current_buffer is unibyte. */
4155 if (it
->multibyte_p
)
4157 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4158 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4159 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4168 /***********************************************************************
4170 ***********************************************************************/
4172 /* Set up iterator IT from invisible properties at its current
4173 position. Called from handle_stop. */
4175 static enum prop_handled
4176 handle_invisible_prop (struct it
*it
)
4178 enum prop_handled handled
= HANDLED_NORMALLY
;
4182 if (STRINGP (it
->string
))
4184 Lisp_Object end_charpos
, limit
, charpos
;
4186 /* Get the value of the invisible text property at the
4187 current position. Value will be nil if there is no such
4189 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4190 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4191 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4193 if (invis
!= 0 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4195 /* Record whether we have to display an ellipsis for the
4197 bool display_ellipsis_p
= (invis
== 2);
4198 ptrdiff_t len
, endpos
;
4200 handled
= HANDLED_RECOMPUTE_PROPS
;
4202 /* Get the position at which the next visible text can be
4203 found in IT->string, if any. */
4204 endpos
= len
= SCHARS (it
->string
);
4205 XSETINT (limit
, len
);
4208 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4210 if (INTEGERP (end_charpos
))
4212 endpos
= XFASTINT (end_charpos
);
4213 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4214 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4216 display_ellipsis_p
= true;
4219 while (invis
!= 0 && endpos
< len
);
4221 if (display_ellipsis_p
)
4222 it
->ellipsis_p
= true;
4226 /* Text at END_CHARPOS is visible. Move IT there. */
4227 struct text_pos old
;
4230 old
= it
->current
.string_pos
;
4231 oldpos
= CHARPOS (old
);
4234 if (it
->bidi_it
.first_elt
4235 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4236 bidi_paragraph_init (it
->paragraph_embedding
,
4237 &it
->bidi_it
, true);
4238 /* Bidi-iterate out of the invisible text. */
4241 bidi_move_to_visually_next (&it
->bidi_it
);
4243 while (oldpos
<= it
->bidi_it
.charpos
4244 && it
->bidi_it
.charpos
< endpos
);
4246 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4247 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4248 if (IT_CHARPOS (*it
) >= endpos
)
4249 it
->prev_stop
= endpos
;
4253 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4254 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4259 /* The rest of the string is invisible. If this is an
4260 overlay string, proceed with the next overlay string
4261 or whatever comes and return a character from there. */
4262 if (it
->current
.overlay_string_index
>= 0
4263 && !display_ellipsis_p
)
4265 next_overlay_string (it
);
4266 /* Don't check for overlay strings when we just
4267 finished processing them. */
4268 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4272 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4273 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4280 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4281 Lisp_Object pos
, overlay
;
4283 /* First of all, is there invisible text at this position? */
4284 tem
= start_charpos
= IT_CHARPOS (*it
);
4285 pos
= make_number (tem
);
4286 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4288 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4290 /* If we are on invisible text, skip over it. */
4291 if (invis
!= 0 && start_charpos
< it
->end_charpos
)
4293 /* Record whether we have to display an ellipsis for the
4295 bool display_ellipsis_p
= invis
== 2;
4297 handled
= HANDLED_RECOMPUTE_PROPS
;
4299 /* Loop skipping over invisible text. The loop is left at
4300 ZV or with IT on the first char being visible again. */
4303 /* Try to skip some invisible text. Return value is the
4304 position reached which can be equal to where we start
4305 if there is nothing invisible there. This skips both
4306 over invisible text properties and overlays with
4307 invisible property. */
4308 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4310 /* If we skipped nothing at all we weren't at invisible
4311 text in the first place. If everything to the end of
4312 the buffer was skipped, end the loop. */
4313 if (newpos
== tem
|| newpos
>= ZV
)
4317 /* We skipped some characters but not necessarily
4318 all there are. Check if we ended up on visible
4319 text. Fget_char_property returns the property of
4320 the char before the given position, i.e. if we
4321 get invis = 0, this means that the char at
4322 newpos is visible. */
4323 pos
= make_number (newpos
);
4324 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4325 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4328 /* If we ended up on invisible text, proceed to
4329 skip starting with next_stop. */
4333 /* If there are adjacent invisible texts, don't lose the
4334 second one's ellipsis. */
4336 display_ellipsis_p
= true;
4340 /* The position newpos is now either ZV or on visible text. */
4343 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4345 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4347 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4349 /* If the invisible text ends on a newline or on a
4350 character after a newline, we can avoid the costly,
4351 character by character, bidi iteration to NEWPOS, and
4352 instead simply reseat the iterator there. That's
4353 because all bidi reordering information is tossed at
4354 the newline. This is a big win for modes that hide
4355 complete lines, like Outline, Org, etc. */
4356 if (on_newline
|| after_newline
)
4358 struct text_pos tpos
;
4359 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4361 SET_TEXT_POS (tpos
, newpos
, bpos
);
4362 reseat_1 (it
, tpos
, false);
4363 /* If we reseat on a newline/ZV, we need to prep the
4364 bidi iterator for advancing to the next character
4365 after the newline/EOB, keeping the current paragraph
4366 direction (so that PRODUCE_GLYPHS does TRT wrt
4367 prepending/appending glyphs to a glyph row). */
4370 it
->bidi_it
.first_elt
= false;
4371 it
->bidi_it
.paragraph_dir
= pdir
;
4372 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4373 it
->bidi_it
.nchars
= 1;
4374 it
->bidi_it
.ch_len
= 1;
4377 else /* Must use the slow method. */
4379 /* With bidi iteration, the region of invisible text
4380 could start and/or end in the middle of a
4381 non-base embedding level. Therefore, we need to
4382 skip invisible text using the bidi iterator,
4383 starting at IT's current position, until we find
4384 ourselves outside of the invisible text.
4385 Skipping invisible text _after_ bidi iteration
4386 avoids affecting the visual order of the
4387 displayed text when invisible properties are
4388 added or removed. */
4389 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4391 /* If we were `reseat'ed to a new paragraph,
4392 determine the paragraph base direction. We
4393 need to do it now because
4394 next_element_from_buffer may not have a
4395 chance to do it, if we are going to skip any
4396 text at the beginning, which resets the
4398 bidi_paragraph_init (it
->paragraph_embedding
,
4399 &it
->bidi_it
, true);
4403 bidi_move_to_visually_next (&it
->bidi_it
);
4405 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4406 && it
->bidi_it
.charpos
< newpos
);
4407 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4408 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4409 /* If we overstepped NEWPOS, record its position in
4410 the iterator, so that we skip invisible text if
4411 later the bidi iteration lands us in the
4412 invisible region again. */
4413 if (IT_CHARPOS (*it
) >= newpos
)
4414 it
->prev_stop
= newpos
;
4419 IT_CHARPOS (*it
) = newpos
;
4420 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4423 if (display_ellipsis_p
)
4425 /* Make sure that the glyphs of the ellipsis will get
4426 correct `charpos' values. If we would not update
4427 it->position here, the glyphs would belong to the
4428 last visible character _before_ the invisible
4429 text, which confuses `set_cursor_from_row'.
4431 We use the last invisible position instead of the
4432 first because this way the cursor is always drawn on
4433 the first "." of the ellipsis, whenever PT is inside
4434 the invisible text. Otherwise the cursor would be
4435 placed _after_ the ellipsis when the point is after the
4436 first invisible character. */
4437 if (!STRINGP (it
->object
))
4439 it
->position
.charpos
= newpos
- 1;
4440 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4444 /* If there are before-strings at the start of invisible
4445 text, and the text is invisible because of a text
4446 property, arrange to show before-strings because 20.x did
4447 it that way. (If the text is invisible because of an
4448 overlay property instead of a text property, this is
4449 already handled in the overlay code.) */
4451 && get_overlay_strings (it
, it
->stop_charpos
))
4453 handled
= HANDLED_RECOMPUTE_PROPS
;
4456 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4457 /* The call to get_overlay_strings above recomputes
4458 it->stop_charpos, but it only considers changes
4459 in properties and overlays beyond iterator's
4460 current position. This causes us to miss changes
4461 that happen exactly where the invisible property
4462 ended. So we play it safe here and force the
4463 iterator to check for potential stop positions
4464 immediately after the invisible text. Note that
4465 if get_overlay_strings returns true, it
4466 normally also pushed the iterator stack, so we
4467 need to update the stop position in the slot
4468 below the current one. */
4469 it
->stack
[it
->sp
- 1].stop_charpos
4470 = CHARPOS (it
->stack
[it
->sp
- 1].current
.pos
);
4473 else if (display_ellipsis_p
)
4475 it
->ellipsis_p
= true;
4476 /* Let the ellipsis display before
4477 considering any properties of the following char.
4478 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4479 handled
= HANDLED_RETURN
;
4488 /* Make iterator IT return `...' next.
4489 Replaces LEN characters from buffer. */
4492 setup_for_ellipsis (struct it
*it
, int len
)
4494 /* Use the display table definition for `...'. Invalid glyphs
4495 will be handled by the method returning elements from dpvec. */
4496 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4498 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4499 it
->dpvec
= v
->contents
;
4500 it
->dpend
= v
->contents
+ v
->header
.size
;
4504 /* Default `...'. */
4505 it
->dpvec
= default_invis_vector
;
4506 it
->dpend
= default_invis_vector
+ 3;
4509 it
->dpvec_char_len
= len
;
4510 it
->current
.dpvec_index
= 0;
4511 it
->dpvec_face_id
= -1;
4513 /* Remember the current face id in case glyphs specify faces.
4514 IT's face is restored in set_iterator_to_next.
4515 saved_face_id was set to preceding char's face in handle_stop. */
4516 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4517 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4519 /* If the ellipsis represents buffer text, it means we advanced in
4520 the buffer, so we should no longer ignore overlay strings. */
4521 if (it
->method
== GET_FROM_BUFFER
)
4522 it
->ignore_overlay_strings_at_pos_p
= false;
4524 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4525 it
->ellipsis_p
= true;
4530 /***********************************************************************
4532 ***********************************************************************/
4534 /* Set up iterator IT from `display' property at its current position.
4535 Called from handle_stop.
4536 We return HANDLED_RETURN if some part of the display property
4537 overrides the display of the buffer text itself.
4538 Otherwise we return HANDLED_NORMALLY. */
4540 static enum prop_handled
4541 handle_display_prop (struct it
*it
)
4543 Lisp_Object propval
, object
, overlay
;
4544 struct text_pos
*position
;
4546 /* Nonzero if some property replaces the display of the text itself. */
4547 int display_replaced
= 0;
4549 if (STRINGP (it
->string
))
4551 object
= it
->string
;
4552 position
= &it
->current
.string_pos
;
4553 bufpos
= CHARPOS (it
->current
.pos
);
4557 XSETWINDOW (object
, it
->w
);
4558 position
= &it
->current
.pos
;
4559 bufpos
= CHARPOS (*position
);
4562 /* Reset those iterator values set from display property values. */
4563 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4564 it
->space_width
= Qnil
;
4565 it
->font_height
= Qnil
;
4568 /* We don't support recursive `display' properties, i.e. string
4569 values that have a string `display' property, that have a string
4570 `display' property etc. */
4571 if (!it
->string_from_display_prop_p
)
4572 it
->area
= TEXT_AREA
;
4574 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4575 Qdisplay
, object
, &overlay
);
4577 return HANDLED_NORMALLY
;
4578 /* Now OVERLAY is the overlay that gave us this property, or nil
4579 if it was a text property. */
4581 if (!STRINGP (it
->string
))
4582 object
= it
->w
->contents
;
4584 display_replaced
= handle_display_spec (it
, propval
, object
, overlay
,
4586 FRAME_WINDOW_P (it
->f
));
4587 return display_replaced
!= 0 ? HANDLED_RETURN
: HANDLED_NORMALLY
;
4590 /* Subroutine of handle_display_prop. Returns non-zero if the display
4591 specification in SPEC is a replacing specification, i.e. it would
4592 replace the text covered by `display' property with something else,
4593 such as an image or a display string. If SPEC includes any kind or
4594 `(space ...) specification, the value is 2; this is used by
4595 compute_display_string_pos, which see.
4597 See handle_single_display_spec for documentation of arguments.
4598 FRAME_WINDOW_P is true if the window being redisplayed is on a
4599 GUI frame; this argument is used only if IT is NULL, see below.
4601 IT can be NULL, if this is called by the bidi reordering code
4602 through compute_display_string_pos, which see. In that case, this
4603 function only examines SPEC, but does not otherwise "handle" it, in
4604 the sense that it doesn't set up members of IT from the display
4607 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4608 Lisp_Object overlay
, struct text_pos
*position
,
4609 ptrdiff_t bufpos
, bool frame_window_p
)
4614 /* Simple specifications. */
4615 && !EQ (XCAR (spec
), Qimage
)
4616 && !EQ (XCAR (spec
), Qspace
)
4617 && !EQ (XCAR (spec
), Qwhen
)
4618 && !EQ (XCAR (spec
), Qslice
)
4619 && !EQ (XCAR (spec
), Qspace_width
)
4620 && !EQ (XCAR (spec
), Qheight
)
4621 && !EQ (XCAR (spec
), Qraise
)
4622 /* Marginal area specifications. */
4623 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4624 && !EQ (XCAR (spec
), Qleft_fringe
)
4625 && !EQ (XCAR (spec
), Qright_fringe
)
4626 && !NILP (XCAR (spec
)))
4628 for (; CONSP (spec
); spec
= XCDR (spec
))
4630 int rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4631 overlay
, position
, bufpos
,
4632 replacing
, frame_window_p
);
4636 /* If some text in a string is replaced, `position' no
4637 longer points to the position of `object'. */
4638 if (!it
|| STRINGP (object
))
4643 else if (VECTORP (spec
))
4646 for (i
= 0; i
< ASIZE (spec
); ++i
)
4648 int rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4649 overlay
, position
, bufpos
,
4650 replacing
, frame_window_p
);
4654 /* If some text in a string is replaced, `position' no
4655 longer points to the position of `object'. */
4656 if (!it
|| STRINGP (object
))
4662 replacing
= handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4663 bufpos
, 0, frame_window_p
);
4667 /* Value is the position of the end of the `display' property starting
4668 at START_POS in OBJECT. */
4670 static struct text_pos
4671 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4674 struct text_pos end_pos
;
4676 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4677 Qdisplay
, object
, Qnil
);
4678 CHARPOS (end_pos
) = XFASTINT (end
);
4679 if (STRINGP (object
))
4680 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4682 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4688 /* Set up IT from a single `display' property specification SPEC. OBJECT
4689 is the object in which the `display' property was found. *POSITION
4690 is the position in OBJECT at which the `display' property was found.
4691 BUFPOS is the buffer position of OBJECT (different from POSITION if
4692 OBJECT is not a buffer). DISPLAY_REPLACED non-zero means that we
4693 previously saw a display specification which already replaced text
4694 display with something else, for example an image; we ignore such
4695 properties after the first one has been processed.
4697 OVERLAY is the overlay this `display' property came from,
4698 or nil if it was a text property.
4700 If SPEC is a `space' or `image' specification, and in some other
4701 cases too, set *POSITION to the position where the `display'
4704 If IT is NULL, only examine the property specification in SPEC, but
4705 don't set up IT. In that case, FRAME_WINDOW_P means SPEC
4706 is intended to be displayed in a window on a GUI frame.
4708 Value is non-zero if something was found which replaces the display
4709 of buffer or string text. */
4712 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4713 Lisp_Object overlay
, struct text_pos
*position
,
4714 ptrdiff_t bufpos
, int display_replaced
,
4715 bool frame_window_p
)
4718 Lisp_Object location
, value
;
4719 struct text_pos start_pos
= *position
;
4721 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4722 If the result is non-nil, use VALUE instead of SPEC. */
4724 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4733 if (!NILP (form
) && !EQ (form
, Qt
))
4735 ptrdiff_t count
= SPECPDL_INDEX ();
4736 struct gcpro gcpro1
;
4738 /* Bind `object' to the object having the `display' property, a
4739 buffer or string. Bind `position' to the position in the
4740 object where the property was found, and `buffer-position'
4741 to the current position in the buffer. */
4744 XSETBUFFER (object
, current_buffer
);
4745 specbind (Qobject
, object
);
4746 specbind (Qposition
, make_number (CHARPOS (*position
)));
4747 specbind (Qbuffer_position
, make_number (bufpos
));
4749 form
= safe_eval (form
);
4751 unbind_to (count
, Qnil
);
4757 /* Handle `(height HEIGHT)' specifications. */
4759 && EQ (XCAR (spec
), Qheight
)
4760 && CONSP (XCDR (spec
)))
4764 if (!FRAME_WINDOW_P (it
->f
))
4767 it
->font_height
= XCAR (XCDR (spec
));
4768 if (!NILP (it
->font_height
))
4770 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4771 int new_height
= -1;
4773 if (CONSP (it
->font_height
)
4774 && (EQ (XCAR (it
->font_height
), Qplus
)
4775 || EQ (XCAR (it
->font_height
), Qminus
))
4776 && CONSP (XCDR (it
->font_height
))
4777 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4779 /* `(+ N)' or `(- N)' where N is an integer. */
4780 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4781 if (EQ (XCAR (it
->font_height
), Qplus
))
4783 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4785 else if (FUNCTIONP (it
->font_height
))
4787 /* Call function with current height as argument.
4788 Value is the new height. */
4790 height
= safe_call1 (it
->font_height
,
4791 face
->lface
[LFACE_HEIGHT_INDEX
]);
4792 if (NUMBERP (height
))
4793 new_height
= XFLOATINT (height
);
4795 else if (NUMBERP (it
->font_height
))
4797 /* Value is a multiple of the canonical char height. */
4800 f
= FACE_FROM_ID (it
->f
,
4801 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4802 new_height
= (XFLOATINT (it
->font_height
)
4803 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4807 /* Evaluate IT->font_height with `height' bound to the
4808 current specified height to get the new height. */
4809 ptrdiff_t count
= SPECPDL_INDEX ();
4811 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4812 value
= safe_eval (it
->font_height
);
4813 unbind_to (count
, Qnil
);
4815 if (NUMBERP (value
))
4816 new_height
= XFLOATINT (value
);
4820 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4827 /* Handle `(space-width WIDTH)'. */
4829 && EQ (XCAR (spec
), Qspace_width
)
4830 && CONSP (XCDR (spec
)))
4834 if (!FRAME_WINDOW_P (it
->f
))
4837 value
= XCAR (XCDR (spec
));
4838 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4839 it
->space_width
= value
;
4845 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4847 && EQ (XCAR (spec
), Qslice
))
4853 if (!FRAME_WINDOW_P (it
->f
))
4856 if (tem
= XCDR (spec
), CONSP (tem
))
4858 it
->slice
.x
= XCAR (tem
);
4859 if (tem
= XCDR (tem
), CONSP (tem
))
4861 it
->slice
.y
= XCAR (tem
);
4862 if (tem
= XCDR (tem
), CONSP (tem
))
4864 it
->slice
.width
= XCAR (tem
);
4865 if (tem
= XCDR (tem
), CONSP (tem
))
4866 it
->slice
.height
= XCAR (tem
);
4875 /* Handle `(raise FACTOR)'. */
4877 && EQ (XCAR (spec
), Qraise
)
4878 && CONSP (XCDR (spec
)))
4882 if (!FRAME_WINDOW_P (it
->f
))
4885 #ifdef HAVE_WINDOW_SYSTEM
4886 value
= XCAR (XCDR (spec
));
4887 if (NUMBERP (value
))
4889 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4890 it
->voffset
= - (XFLOATINT (value
)
4891 * (FONT_HEIGHT (face
->font
)));
4893 #endif /* HAVE_WINDOW_SYSTEM */
4899 /* Don't handle the other kinds of display specifications
4900 inside a string that we got from a `display' property. */
4901 if (it
&& it
->string_from_display_prop_p
)
4904 /* Characters having this form of property are not displayed, so
4905 we have to find the end of the property. */
4908 start_pos
= *position
;
4909 *position
= display_prop_end (it
, object
, start_pos
);
4910 /* If the display property comes from an overlay, don't consider
4911 any potential stop_charpos values before the end of that
4912 overlay. Since display_prop_end will happily find another
4913 'display' property coming from some other overlay or text
4914 property on buffer positions before this overlay's end, we
4915 need to ignore them, or else we risk displaying this
4916 overlay's display string/image twice. */
4917 if (!NILP (overlay
))
4919 ptrdiff_t ovendpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4921 if (ovendpos
> CHARPOS (*position
))
4922 SET_TEXT_POS (*position
, ovendpos
, CHAR_TO_BYTE (ovendpos
));
4927 /* Stop the scan at that end position--we assume that all
4928 text properties change there. */
4930 it
->stop_charpos
= position
->charpos
;
4932 /* Handle `(left-fringe BITMAP [FACE])'
4933 and `(right-fringe BITMAP [FACE])'. */
4935 && (EQ (XCAR (spec
), Qleft_fringe
)
4936 || EQ (XCAR (spec
), Qright_fringe
))
4937 && CONSP (XCDR (spec
)))
4943 if (!FRAME_WINDOW_P (it
->f
))
4944 /* If we return here, POSITION has been advanced
4945 across the text with this property. */
4947 /* Synchronize the bidi iterator with POSITION. This is
4948 needed because we are not going to push the iterator
4949 on behalf of this display property, so there will be
4950 no pop_it call to do this synchronization for us. */
4953 it
->position
= *position
;
4954 iterate_out_of_display_property (it
);
4955 *position
= it
->position
;
4960 else if (!frame_window_p
)
4963 #ifdef HAVE_WINDOW_SYSTEM
4964 value
= XCAR (XCDR (spec
));
4965 if (!SYMBOLP (value
)
4966 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4967 /* If we return here, POSITION has been advanced
4968 across the text with this property. */
4970 if (it
&& it
->bidi_p
)
4972 it
->position
= *position
;
4973 iterate_out_of_display_property (it
);
4974 *position
= it
->position
;
4981 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4983 if (CONSP (XCDR (XCDR (spec
))))
4985 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4986 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4987 FRINGE_FACE_ID
, false);
4992 /* Save current settings of IT so that we can restore them
4993 when we are finished with the glyph property value. */
4994 push_it (it
, position
);
4996 it
->area
= TEXT_AREA
;
4997 it
->what
= IT_IMAGE
;
4998 it
->image_id
= -1; /* no image */
4999 it
->position
= start_pos
;
5000 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5001 it
->method
= GET_FROM_IMAGE
;
5002 it
->from_overlay
= Qnil
;
5003 it
->face_id
= face_id
;
5004 it
->from_disp_prop_p
= true;
5006 /* Say that we haven't consumed the characters with
5007 `display' property yet. The call to pop_it in
5008 set_iterator_to_next will clean this up. */
5009 *position
= start_pos
;
5011 if (EQ (XCAR (spec
), Qleft_fringe
))
5013 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5014 it
->left_user_fringe_face_id
= face_id
;
5018 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5019 it
->right_user_fringe_face_id
= face_id
;
5022 #endif /* HAVE_WINDOW_SYSTEM */
5026 /* Prepare to handle `((margin left-margin) ...)',
5027 `((margin right-margin) ...)' and `((margin nil) ...)'
5028 prefixes for display specifications. */
5029 location
= Qunbound
;
5030 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5034 value
= XCDR (spec
);
5036 value
= XCAR (value
);
5039 if (EQ (XCAR (tem
), Qmargin
)
5040 && (tem
= XCDR (tem
),
5041 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5043 || EQ (tem
, Qleft_margin
)
5044 || EQ (tem
, Qright_margin
))))
5048 if (EQ (location
, Qunbound
))
5054 /* After this point, VALUE is the property after any
5055 margin prefix has been stripped. It must be a string,
5056 an image specification, or `(space ...)'.
5058 LOCATION specifies where to display: `left-margin',
5059 `right-margin' or nil. */
5061 bool valid_p
= (STRINGP (value
)
5062 #ifdef HAVE_WINDOW_SYSTEM
5063 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5064 && valid_image_p (value
))
5065 #endif /* not HAVE_WINDOW_SYSTEM */
5066 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5068 if (valid_p
&& display_replaced
== 0)
5074 /* Callers need to know whether the display spec is any kind
5075 of `(space ...)' spec that is about to affect text-area
5077 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5082 /* Save current settings of IT so that we can restore them
5083 when we are finished with the glyph property value. */
5084 push_it (it
, position
);
5085 it
->from_overlay
= overlay
;
5086 it
->from_disp_prop_p
= true;
5088 if (NILP (location
))
5089 it
->area
= TEXT_AREA
;
5090 else if (EQ (location
, Qleft_margin
))
5091 it
->area
= LEFT_MARGIN_AREA
;
5093 it
->area
= RIGHT_MARGIN_AREA
;
5095 if (STRINGP (value
))
5098 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5099 it
->current
.overlay_string_index
= -1;
5100 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5101 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5102 it
->method
= GET_FROM_STRING
;
5103 it
->stop_charpos
= 0;
5105 it
->base_level_stop
= 0;
5106 it
->string_from_display_prop_p
= true;
5107 /* Say that we haven't consumed the characters with
5108 `display' property yet. The call to pop_it in
5109 set_iterator_to_next will clean this up. */
5110 if (BUFFERP (object
))
5111 *position
= start_pos
;
5113 /* Force paragraph direction to be that of the parent
5114 object. If the parent object's paragraph direction is
5115 not yet determined, default to L2R. */
5116 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5117 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5119 it
->paragraph_embedding
= L2R
;
5121 /* Set up the bidi iterator for this display string. */
5124 it
->bidi_it
.string
.lstring
= it
->string
;
5125 it
->bidi_it
.string
.s
= NULL
;
5126 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5127 it
->bidi_it
.string
.bufpos
= bufpos
;
5128 it
->bidi_it
.string
.from_disp_str
= true;
5129 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5130 it
->bidi_it
.w
= it
->w
;
5131 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5134 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5136 it
->method
= GET_FROM_STRETCH
;
5138 *position
= it
->position
= start_pos
;
5139 retval
= 1 + (it
->area
== TEXT_AREA
);
5141 #ifdef HAVE_WINDOW_SYSTEM
5144 it
->what
= IT_IMAGE
;
5145 it
->image_id
= lookup_image (it
->f
, value
);
5146 it
->position
= start_pos
;
5147 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5148 it
->method
= GET_FROM_IMAGE
;
5150 /* Say that we haven't consumed the characters with
5151 `display' property yet. The call to pop_it in
5152 set_iterator_to_next will clean this up. */
5153 *position
= start_pos
;
5155 #endif /* HAVE_WINDOW_SYSTEM */
5160 /* Invalid property or property not supported. Restore
5161 POSITION to what it was before. */
5162 *position
= start_pos
;
5166 /* Check if PROP is a display property value whose text should be
5167 treated as intangible. OVERLAY is the overlay from which PROP
5168 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5169 specify the buffer position covered by PROP. */
5172 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5173 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5175 bool frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5176 struct text_pos position
;
5178 SET_TEXT_POS (position
, charpos
, bytepos
);
5179 return (handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5180 &position
, charpos
, frame_window_p
)
5185 /* Return true if PROP is a display sub-property value containing STRING.
5187 Implementation note: this and the following function are really
5188 special cases of handle_display_spec and
5189 handle_single_display_spec, and should ideally use the same code.
5190 Until they do, these two pairs must be consistent and must be
5191 modified in sync. */
5194 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5196 if (EQ (string
, prop
))
5199 /* Skip over `when FORM'. */
5200 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5205 /* Actually, the condition following `when' should be eval'ed,
5206 like handle_single_display_spec does, and we should return
5207 false if it evaluates to nil. However, this function is
5208 called only when the buffer was already displayed and some
5209 glyph in the glyph matrix was found to come from a display
5210 string. Therefore, the condition was already evaluated, and
5211 the result was non-nil, otherwise the display string wouldn't
5212 have been displayed and we would have never been called for
5213 this property. Thus, we can skip the evaluation and assume
5214 its result is non-nil. */
5219 /* Skip over `margin LOCATION'. */
5220 if (EQ (XCAR (prop
), Qmargin
))
5231 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5235 /* Return true if STRING appears in the `display' property PROP. */
5238 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5241 && !EQ (XCAR (prop
), Qwhen
)
5242 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5244 /* A list of sub-properties. */
5245 while (CONSP (prop
))
5247 if (single_display_spec_string_p (XCAR (prop
), string
))
5252 else if (VECTORP (prop
))
5254 /* A vector of sub-properties. */
5256 for (i
= 0; i
< ASIZE (prop
); ++i
)
5257 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5261 return single_display_spec_string_p (prop
, string
);
5266 /* Look for STRING in overlays and text properties in the current
5267 buffer, between character positions FROM and TO (excluding TO).
5268 BACK_P means look back (in this case, TO is supposed to be
5270 Value is the first character position where STRING was found, or
5271 zero if it wasn't found before hitting TO.
5273 This function may only use code that doesn't eval because it is
5274 called asynchronously from note_mouse_highlight. */
5277 string_buffer_position_lim (Lisp_Object string
,
5278 ptrdiff_t from
, ptrdiff_t to
, bool back_p
)
5280 Lisp_Object limit
, prop
, pos
;
5283 pos
= make_number (max (from
, BEGV
));
5285 if (!back_p
) /* looking forward */
5287 limit
= make_number (min (to
, ZV
));
5288 while (!found
&& !EQ (pos
, limit
))
5290 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5291 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5294 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5298 else /* looking back */
5300 limit
= make_number (max (to
, BEGV
));
5301 while (!found
&& !EQ (pos
, limit
))
5303 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5304 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5307 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5312 return found
? XINT (pos
) : 0;
5315 /* Determine which buffer position in current buffer STRING comes from.
5316 AROUND_CHARPOS is an approximate position where it could come from.
5317 Value is the buffer position or 0 if it couldn't be determined.
5319 This function is necessary because we don't record buffer positions
5320 in glyphs generated from strings (to keep struct glyph small).
5321 This function may only use code that doesn't eval because it is
5322 called asynchronously from note_mouse_highlight. */
5325 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5327 const int MAX_DISTANCE
= 1000;
5328 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5329 around_charpos
+ MAX_DISTANCE
,
5333 found
= string_buffer_position_lim (string
, around_charpos
,
5334 around_charpos
- MAX_DISTANCE
, true);
5340 /***********************************************************************
5341 `composition' property
5342 ***********************************************************************/
5344 /* Set up iterator IT from `composition' property at its current
5345 position. Called from handle_stop. */
5347 static enum prop_handled
5348 handle_composition_prop (struct it
*it
)
5350 Lisp_Object prop
, string
;
5351 ptrdiff_t pos
, pos_byte
, start
, end
;
5353 if (STRINGP (it
->string
))
5357 pos
= IT_STRING_CHARPOS (*it
);
5358 pos_byte
= IT_STRING_BYTEPOS (*it
);
5359 string
= it
->string
;
5360 s
= SDATA (string
) + pos_byte
;
5361 it
->c
= STRING_CHAR (s
);
5365 pos
= IT_CHARPOS (*it
);
5366 pos_byte
= IT_BYTEPOS (*it
);
5368 it
->c
= FETCH_CHAR (pos_byte
);
5371 /* If there's a valid composition and point is not inside of the
5372 composition (in the case that the composition is from the current
5373 buffer), draw a glyph composed from the composition components. */
5374 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5375 && composition_valid_p (start
, end
, prop
)
5376 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5379 /* As we can't handle this situation (perhaps font-lock added
5380 a new composition), we just return here hoping that next
5381 redisplay will detect this composition much earlier. */
5382 return HANDLED_NORMALLY
;
5385 if (STRINGP (it
->string
))
5386 pos_byte
= string_char_to_byte (it
->string
, start
);
5388 pos_byte
= CHAR_TO_BYTE (start
);
5390 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5393 if (it
->cmp_it
.id
>= 0)
5396 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5397 it
->cmp_it
.nglyphs
= -1;
5401 return HANDLED_NORMALLY
;
5406 /***********************************************************************
5408 ***********************************************************************/
5410 /* The following structure is used to record overlay strings for
5411 later sorting in load_overlay_strings. */
5413 struct overlay_entry
5415 Lisp_Object overlay
;
5418 bool after_string_p
;
5422 /* Set up iterator IT from overlay strings at its current position.
5423 Called from handle_stop. */
5425 static enum prop_handled
5426 handle_overlay_change (struct it
*it
)
5428 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5429 return HANDLED_RECOMPUTE_PROPS
;
5431 return HANDLED_NORMALLY
;
5435 /* Set up the next overlay string for delivery by IT, if there is an
5436 overlay string to deliver. Called by set_iterator_to_next when the
5437 end of the current overlay string is reached. If there are more
5438 overlay strings to display, IT->string and
5439 IT->current.overlay_string_index are set appropriately here.
5440 Otherwise IT->string is set to nil. */
5443 next_overlay_string (struct it
*it
)
5445 ++it
->current
.overlay_string_index
;
5446 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5448 /* No more overlay strings. Restore IT's settings to what
5449 they were before overlay strings were processed, and
5450 continue to deliver from current_buffer. */
5452 it
->ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
5455 || (NILP (it
->string
)
5456 && it
->method
== GET_FROM_BUFFER
5457 && it
->stop_charpos
>= BEGV
5458 && it
->stop_charpos
<= it
->end_charpos
));
5459 it
->current
.overlay_string_index
= -1;
5460 it
->n_overlay_strings
= 0;
5461 /* If there's an empty display string on the stack, pop the
5462 stack, to resync the bidi iterator with IT's position. Such
5463 empty strings are pushed onto the stack in
5464 get_overlay_strings_1. */
5465 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5468 /* Since we've exhausted overlay strings at this buffer
5469 position, set the flag to ignore overlays until we move to
5470 another position. The flag is reset in
5471 next_element_from_buffer. */
5472 it
->ignore_overlay_strings_at_pos_p
= true;
5474 /* If we're at the end of the buffer, record that we have
5475 processed the overlay strings there already, so that
5476 next_element_from_buffer doesn't try it again. */
5477 if (NILP (it
->string
)
5478 && IT_CHARPOS (*it
) >= it
->end_charpos
5479 && it
->overlay_strings_charpos
>= it
->end_charpos
)
5480 it
->overlay_strings_at_end_processed_p
= true;
5481 /* Note: we reset overlay_strings_charpos only here, to make
5482 sure the just-processed overlays were indeed at EOB.
5483 Otherwise, overlays on text with invisible text property,
5484 which are processed with IT's position past the invisible
5485 text, might fool us into thinking the overlays at EOB were
5486 already processed (linum-mode can cause this, for
5488 it
->overlay_strings_charpos
= -1;
5492 /* There are more overlay strings to process. If
5493 IT->current.overlay_string_index has advanced to a position
5494 where we must load IT->overlay_strings with more strings, do
5495 it. We must load at the IT->overlay_strings_charpos where
5496 IT->n_overlay_strings was originally computed; when invisible
5497 text is present, this might not be IT_CHARPOS (Bug#7016). */
5498 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5500 if (it
->current
.overlay_string_index
&& i
== 0)
5501 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5503 /* Initialize IT to deliver display elements from the overlay
5505 it
->string
= it
->overlay_strings
[i
];
5506 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5507 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5508 it
->method
= GET_FROM_STRING
;
5509 it
->stop_charpos
= 0;
5510 it
->end_charpos
= SCHARS (it
->string
);
5511 if (it
->cmp_it
.stop_pos
>= 0)
5512 it
->cmp_it
.stop_pos
= 0;
5514 it
->base_level_stop
= 0;
5516 /* Set up the bidi iterator for this overlay string. */
5519 it
->bidi_it
.string
.lstring
= it
->string
;
5520 it
->bidi_it
.string
.s
= NULL
;
5521 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5522 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5523 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5524 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5525 it
->bidi_it
.w
= it
->w
;
5526 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5534 /* Compare two overlay_entry structures E1 and E2. Used as a
5535 comparison function for qsort in load_overlay_strings. Overlay
5536 strings for the same position are sorted so that
5538 1. All after-strings come in front of before-strings, except
5539 when they come from the same overlay.
5541 2. Within after-strings, strings are sorted so that overlay strings
5542 from overlays with higher priorities come first.
5544 2. Within before-strings, strings are sorted so that overlay
5545 strings from overlays with higher priorities come last.
5547 Value is analogous to strcmp. */
5551 compare_overlay_entries (const void *e1
, const void *e2
)
5553 struct overlay_entry
const *entry1
= e1
;
5554 struct overlay_entry
const *entry2
= e2
;
5557 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5559 /* Let after-strings appear in front of before-strings if
5560 they come from different overlays. */
5561 if (EQ (entry1
->overlay
, entry2
->overlay
))
5562 result
= entry1
->after_string_p
? 1 : -1;
5564 result
= entry1
->after_string_p
? -1 : 1;
5566 else if (entry1
->priority
!= entry2
->priority
)
5568 if (entry1
->after_string_p
)
5569 /* After-strings sorted in order of decreasing priority. */
5570 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5572 /* Before-strings sorted in order of increasing priority. */
5573 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5582 /* Load the vector IT->overlay_strings with overlay strings from IT's
5583 current buffer position, or from CHARPOS if that is > 0. Set
5584 IT->n_overlays to the total number of overlay strings found.
5586 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5587 a time. On entry into load_overlay_strings,
5588 IT->current.overlay_string_index gives the number of overlay
5589 strings that have already been loaded by previous calls to this
5592 IT->add_overlay_start contains an additional overlay start
5593 position to consider for taking overlay strings from, if non-zero.
5594 This position comes into play when the overlay has an `invisible'
5595 property, and both before and after-strings. When we've skipped to
5596 the end of the overlay, because of its `invisible' property, we
5597 nevertheless want its before-string to appear.
5598 IT->add_overlay_start will contain the overlay start position
5601 Overlay strings are sorted so that after-string strings come in
5602 front of before-string strings. Within before and after-strings,
5603 strings are sorted by overlay priority. See also function
5604 compare_overlay_entries. */
5607 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5609 Lisp_Object overlay
, window
, str
, invisible
;
5610 struct Lisp_Overlay
*ov
;
5611 ptrdiff_t start
, end
;
5612 ptrdiff_t n
= 0, i
, j
;
5614 struct overlay_entry entriesbuf
[20];
5615 ptrdiff_t size
= ARRAYELTS (entriesbuf
);
5616 struct overlay_entry
*entries
= entriesbuf
;
5620 charpos
= IT_CHARPOS (*it
);
5622 /* Append the overlay string STRING of overlay OVERLAY to vector
5623 `entries' which has size `size' and currently contains `n'
5624 elements. AFTER_P means STRING is an after-string of
5626 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5629 Lisp_Object priority; \
5633 struct overlay_entry *old = entries; \
5634 SAFE_NALLOCA (entries, 2, size); \
5635 memcpy (entries, old, size * sizeof *entries); \
5639 entries[n].string = (STRING); \
5640 entries[n].overlay = (OVERLAY); \
5641 priority = Foverlay_get ((OVERLAY), Qpriority); \
5642 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5643 entries[n].after_string_p = (AFTER_P); \
5648 /* Process overlay before the overlay center. */
5649 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5651 XSETMISC (overlay
, ov
);
5652 eassert (OVERLAYP (overlay
));
5653 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5654 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5659 /* Skip this overlay if it doesn't start or end at IT's current
5661 if (end
!= charpos
&& start
!= charpos
)
5664 /* Skip this overlay if it doesn't apply to IT->w. */
5665 window
= Foverlay_get (overlay
, Qwindow
);
5666 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5669 /* If the text ``under'' the overlay is invisible, both before-
5670 and after-strings from this overlay are visible; start and
5671 end position are indistinguishable. */
5672 invisible
= Foverlay_get (overlay
, Qinvisible
);
5673 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5675 /* If overlay has a non-empty before-string, record it. */
5676 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5677 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5679 RECORD_OVERLAY_STRING (overlay
, str
, false);
5681 /* If overlay has a non-empty after-string, record it. */
5682 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5683 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5685 RECORD_OVERLAY_STRING (overlay
, str
, true);
5688 /* Process overlays after the overlay center. */
5689 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5691 XSETMISC (overlay
, ov
);
5692 eassert (OVERLAYP (overlay
));
5693 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5694 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5696 if (start
> charpos
)
5699 /* Skip this overlay if it doesn't start or end at IT's current
5701 if (end
!= charpos
&& start
!= charpos
)
5704 /* Skip this overlay if it doesn't apply to IT->w. */
5705 window
= Foverlay_get (overlay
, Qwindow
);
5706 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5709 /* If the text ``under'' the overlay is invisible, it has a zero
5710 dimension, and both before- and after-strings apply. */
5711 invisible
= Foverlay_get (overlay
, Qinvisible
);
5712 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5714 /* If overlay has a non-empty before-string, record it. */
5715 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5716 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5718 RECORD_OVERLAY_STRING (overlay
, str
, false);
5720 /* If overlay has a non-empty after-string, record it. */
5721 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5722 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5724 RECORD_OVERLAY_STRING (overlay
, str
, true);
5727 #undef RECORD_OVERLAY_STRING
5731 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5733 /* Record number of overlay strings, and where we computed it. */
5734 it
->n_overlay_strings
= n
;
5735 it
->overlay_strings_charpos
= charpos
;
5737 /* IT->current.overlay_string_index is the number of overlay strings
5738 that have already been consumed by IT. Copy some of the
5739 remaining overlay strings to IT->overlay_strings. */
5741 j
= it
->current
.overlay_string_index
;
5742 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5744 it
->overlay_strings
[i
] = entries
[j
].string
;
5745 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5753 /* Get the first chunk of overlay strings at IT's current buffer
5754 position, or at CHARPOS if that is > 0. Value is true if at
5755 least one overlay string was found. */
5758 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, bool compute_stop_p
)
5760 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5761 process. This fills IT->overlay_strings with strings, and sets
5762 IT->n_overlay_strings to the total number of strings to process.
5763 IT->pos.overlay_string_index has to be set temporarily to zero
5764 because load_overlay_strings needs this; it must be set to -1
5765 when no overlay strings are found because a zero value would
5766 indicate a position in the first overlay string. */
5767 it
->current
.overlay_string_index
= 0;
5768 load_overlay_strings (it
, charpos
);
5770 /* If we found overlay strings, set up IT to deliver display
5771 elements from the first one. Otherwise set up IT to deliver
5772 from current_buffer. */
5773 if (it
->n_overlay_strings
)
5775 /* Make sure we know settings in current_buffer, so that we can
5776 restore meaningful values when we're done with the overlay
5779 compute_stop_pos (it
);
5780 eassert (it
->face_id
>= 0);
5782 /* Save IT's settings. They are restored after all overlay
5783 strings have been processed. */
5784 eassert (!compute_stop_p
|| it
->sp
== 0);
5786 /* When called from handle_stop, there might be an empty display
5787 string loaded. In that case, don't bother saving it. But
5788 don't use this optimization with the bidi iterator, since we
5789 need the corresponding pop_it call to resync the bidi
5790 iterator's position with IT's position, after we are done
5791 with the overlay strings. (The corresponding call to pop_it
5792 in case of an empty display string is in
5793 next_overlay_string.) */
5795 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5798 /* Set up IT to deliver display elements from the first overlay
5800 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5801 it
->string
= it
->overlay_strings
[0];
5802 it
->from_overlay
= Qnil
;
5803 it
->stop_charpos
= 0;
5804 eassert (STRINGP (it
->string
));
5805 it
->end_charpos
= SCHARS (it
->string
);
5807 it
->base_level_stop
= 0;
5808 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5809 it
->method
= GET_FROM_STRING
;
5810 it
->from_disp_prop_p
= 0;
5812 /* Force paragraph direction to be that of the parent
5814 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5815 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5817 it
->paragraph_embedding
= L2R
;
5819 /* Set up the bidi iterator for this overlay string. */
5822 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5824 it
->bidi_it
.string
.lstring
= it
->string
;
5825 it
->bidi_it
.string
.s
= NULL
;
5826 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5827 it
->bidi_it
.string
.bufpos
= pos
;
5828 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5829 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5830 it
->bidi_it
.w
= it
->w
;
5831 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5836 it
->current
.overlay_string_index
= -1;
5841 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5844 it
->method
= GET_FROM_BUFFER
;
5846 get_overlay_strings_1 (it
, charpos
, true);
5850 /* Value is true if we found at least one overlay string. */
5851 return STRINGP (it
->string
);
5856 /***********************************************************************
5857 Saving and restoring state
5858 ***********************************************************************/
5860 /* Save current settings of IT on IT->stack. Called, for example,
5861 before setting up IT for an overlay string, to be able to restore
5862 IT's settings to what they were after the overlay string has been
5863 processed. If POSITION is non-NULL, it is the position to save on
5864 the stack instead of IT->position. */
5867 push_it (struct it
*it
, struct text_pos
*position
)
5869 struct iterator_stack_entry
*p
;
5871 eassert (it
->sp
< IT_STACK_SIZE
);
5872 p
= it
->stack
+ it
->sp
;
5874 p
->stop_charpos
= it
->stop_charpos
;
5875 p
->prev_stop
= it
->prev_stop
;
5876 p
->base_level_stop
= it
->base_level_stop
;
5877 p
->cmp_it
= it
->cmp_it
;
5878 eassert (it
->face_id
>= 0);
5879 p
->face_id
= it
->face_id
;
5880 p
->string
= it
->string
;
5881 p
->method
= it
->method
;
5882 p
->from_overlay
= it
->from_overlay
;
5885 case GET_FROM_IMAGE
:
5886 p
->u
.image
.object
= it
->object
;
5887 p
->u
.image
.image_id
= it
->image_id
;
5888 p
->u
.image
.slice
= it
->slice
;
5890 case GET_FROM_STRETCH
:
5891 p
->u
.stretch
.object
= it
->object
;
5894 p
->position
= position
? *position
: it
->position
;
5895 p
->current
= it
->current
;
5896 p
->end_charpos
= it
->end_charpos
;
5897 p
->string_nchars
= it
->string_nchars
;
5899 p
->multibyte_p
= it
->multibyte_p
;
5900 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5901 p
->space_width
= it
->space_width
;
5902 p
->font_height
= it
->font_height
;
5903 p
->voffset
= it
->voffset
;
5904 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5905 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5906 p
->display_ellipsis_p
= false;
5907 p
->line_wrap
= it
->line_wrap
;
5908 p
->bidi_p
= it
->bidi_p
;
5909 p
->paragraph_embedding
= it
->paragraph_embedding
;
5910 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5913 /* Save the state of the bidi iterator as well. */
5915 bidi_push_it (&it
->bidi_it
);
5919 iterate_out_of_display_property (struct it
*it
)
5921 bool buffer_p
= !STRINGP (it
->string
);
5922 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5923 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5925 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5927 /* Maybe initialize paragraph direction. If we are at the beginning
5928 of a new paragraph, next_element_from_buffer may not have a
5929 chance to do that. */
5930 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5931 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
5932 /* prev_stop can be zero, so check against BEGV as well. */
5933 while (it
->bidi_it
.charpos
>= bob
5934 && it
->prev_stop
<= it
->bidi_it
.charpos
5935 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5936 && it
->bidi_it
.charpos
< eob
)
5937 bidi_move_to_visually_next (&it
->bidi_it
);
5938 /* Record the stop_pos we just crossed, for when we cross it
5940 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5941 it
->prev_stop
= CHARPOS (it
->position
);
5942 /* If we ended up not where pop_it put us, resync IT's
5943 positional members with the bidi iterator. */
5944 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5945 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5947 it
->current
.pos
= it
->position
;
5949 it
->current
.string_pos
= it
->position
;
5952 /* Restore IT's settings from IT->stack. Called, for example, when no
5953 more overlay strings must be processed, and we return to delivering
5954 display elements from a buffer, or when the end of a string from a
5955 `display' property is reached and we return to delivering display
5956 elements from an overlay string, or from a buffer. */
5959 pop_it (struct it
*it
)
5961 struct iterator_stack_entry
*p
;
5962 bool from_display_prop
= it
->from_disp_prop_p
;
5964 eassert (it
->sp
> 0);
5966 p
= it
->stack
+ it
->sp
;
5967 it
->stop_charpos
= p
->stop_charpos
;
5968 it
->prev_stop
= p
->prev_stop
;
5969 it
->base_level_stop
= p
->base_level_stop
;
5970 it
->cmp_it
= p
->cmp_it
;
5971 it
->face_id
= p
->face_id
;
5972 it
->current
= p
->current
;
5973 it
->position
= p
->position
;
5974 it
->string
= p
->string
;
5975 it
->from_overlay
= p
->from_overlay
;
5976 if (NILP (it
->string
))
5977 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5978 it
->method
= p
->method
;
5981 case GET_FROM_IMAGE
:
5982 it
->image_id
= p
->u
.image
.image_id
;
5983 it
->object
= p
->u
.image
.object
;
5984 it
->slice
= p
->u
.image
.slice
;
5986 case GET_FROM_STRETCH
:
5987 it
->object
= p
->u
.stretch
.object
;
5989 case GET_FROM_BUFFER
:
5990 it
->object
= it
->w
->contents
;
5992 case GET_FROM_STRING
:
5994 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5996 /* Restore the face_box_p flag, since it could have been
5997 overwritten by the face of the object that we just finished
6000 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
6001 it
->object
= it
->string
;
6004 case GET_FROM_DISPLAY_VECTOR
:
6006 it
->method
= GET_FROM_C_STRING
;
6007 else if (STRINGP (it
->string
))
6008 it
->method
= GET_FROM_STRING
;
6011 it
->method
= GET_FROM_BUFFER
;
6012 it
->object
= it
->w
->contents
;
6015 it
->end_charpos
= p
->end_charpos
;
6016 it
->string_nchars
= p
->string_nchars
;
6018 it
->multibyte_p
= p
->multibyte_p
;
6019 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
6020 it
->space_width
= p
->space_width
;
6021 it
->font_height
= p
->font_height
;
6022 it
->voffset
= p
->voffset
;
6023 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
6024 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
6025 it
->line_wrap
= p
->line_wrap
;
6026 it
->bidi_p
= p
->bidi_p
;
6027 it
->paragraph_embedding
= p
->paragraph_embedding
;
6028 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
6031 bidi_pop_it (&it
->bidi_it
);
6032 /* Bidi-iterate until we get out of the portion of text, if any,
6033 covered by a `display' text property or by an overlay with
6034 `display' property. (We cannot just jump there, because the
6035 internal coherency of the bidi iterator state can not be
6036 preserved across such jumps.) We also must determine the
6037 paragraph base direction if the overlay we just processed is
6038 at the beginning of a new paragraph. */
6039 if (from_display_prop
6040 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6041 iterate_out_of_display_property (it
);
6043 eassert ((BUFFERP (it
->object
)
6044 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6045 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6046 || (STRINGP (it
->object
)
6047 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6048 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6049 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6055 /***********************************************************************
6057 ***********************************************************************/
6059 /* Set IT's current position to the previous line start. */
6062 back_to_previous_line_start (struct it
*it
)
6064 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6067 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6071 /* Move IT to the next line start.
6073 Value is true if a newline was found. Set *SKIPPED_P to true if
6074 we skipped over part of the text (as opposed to moving the iterator
6075 continuously over the text). Otherwise, don't change the value
6078 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6079 iterator on the newline, if it was found.
6081 Newlines may come from buffer text, overlay strings, or strings
6082 displayed via the `display' property. That's the reason we can't
6083 simply use find_newline_no_quit.
6085 Note that this function may not skip over invisible text that is so
6086 because of text properties and immediately follows a newline. If
6087 it would, function reseat_at_next_visible_line_start, when called
6088 from set_iterator_to_next, would effectively make invisible
6089 characters following a newline part of the wrong glyph row, which
6090 leads to wrong cursor motion. */
6093 forward_to_next_line_start (struct it
*it
, bool *skipped_p
,
6094 struct bidi_it
*bidi_it_prev
)
6096 ptrdiff_t old_selective
;
6097 bool newline_found_p
= false;
6099 const int MAX_NEWLINE_DISTANCE
= 500;
6101 /* If already on a newline, just consume it to avoid unintended
6102 skipping over invisible text below. */
6103 if (it
->what
== IT_CHARACTER
6105 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6107 if (it
->bidi_p
&& bidi_it_prev
)
6108 *bidi_it_prev
= it
->bidi_it
;
6109 set_iterator_to_next (it
, false);
6114 /* Don't handle selective display in the following. It's (a)
6115 unnecessary because it's done by the caller, and (b) leads to an
6116 infinite recursion because next_element_from_ellipsis indirectly
6117 calls this function. */
6118 old_selective
= it
->selective
;
6121 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6122 from buffer text. */
6124 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6125 n
+= !STRINGP (it
->string
))
6127 if (!get_next_display_element (it
))
6129 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6130 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6131 *bidi_it_prev
= it
->bidi_it
;
6132 set_iterator_to_next (it
, false);
6135 /* If we didn't find a newline near enough, see if we can use a
6137 if (!newline_found_p
)
6139 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6140 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6144 eassert (!STRINGP (it
->string
));
6146 /* If there isn't any `display' property in sight, and no
6147 overlays, we can just use the position of the newline in
6149 if (it
->stop_charpos
>= limit
6150 || ((pos
= Fnext_single_property_change (make_number (start
),
6152 make_number (limit
)),
6154 && next_overlay_change (start
) == ZV
))
6158 IT_CHARPOS (*it
) = limit
;
6159 IT_BYTEPOS (*it
) = bytepos
;
6163 struct bidi_it bprev
;
6165 /* Help bidi.c avoid expensive searches for display
6166 properties and overlays, by telling it that there are
6167 none up to `limit'. */
6168 if (it
->bidi_it
.disp_pos
< limit
)
6170 it
->bidi_it
.disp_pos
= limit
;
6171 it
->bidi_it
.disp_prop
= 0;
6174 bprev
= it
->bidi_it
;
6175 bidi_move_to_visually_next (&it
->bidi_it
);
6176 } while (it
->bidi_it
.charpos
!= limit
);
6177 IT_CHARPOS (*it
) = limit
;
6178 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6180 *bidi_it_prev
= bprev
;
6182 *skipped_p
= newline_found_p
= true;
6186 while (get_next_display_element (it
)
6187 && !newline_found_p
)
6189 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6190 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6191 *bidi_it_prev
= it
->bidi_it
;
6192 set_iterator_to_next (it
, false);
6197 it
->selective
= old_selective
;
6198 return newline_found_p
;
6202 /* Set IT's current position to the previous visible line start. Skip
6203 invisible text that is so either due to text properties or due to
6204 selective display. Caution: this does not change IT->current_x and
6208 back_to_previous_visible_line_start (struct it
*it
)
6210 while (IT_CHARPOS (*it
) > BEGV
)
6212 back_to_previous_line_start (it
);
6214 if (IT_CHARPOS (*it
) <= BEGV
)
6217 /* If selective > 0, then lines indented more than its value are
6219 if (it
->selective
> 0
6220 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6224 /* Check the newline before point for invisibility. */
6227 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6228 Qinvisible
, it
->window
);
6229 if (TEXT_PROP_MEANS_INVISIBLE (prop
) != 0)
6233 if (IT_CHARPOS (*it
) <= BEGV
)
6238 void *it2data
= NULL
;
6241 Lisp_Object val
, overlay
;
6243 SAVE_IT (it2
, *it
, it2data
);
6245 /* If newline is part of a composition, continue from start of composition */
6246 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6247 && beg
< IT_CHARPOS (*it
))
6250 /* If newline is replaced by a display property, find start of overlay
6251 or interval and continue search from that point. */
6252 pos
= --IT_CHARPOS (it2
);
6255 bidi_unshelve_cache (NULL
, false);
6256 it2
.string_from_display_prop_p
= false;
6257 it2
.from_disp_prop_p
= false;
6258 if (handle_display_prop (&it2
) == HANDLED_RETURN
6259 && !NILP (val
= get_char_property_and_overlay
6260 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6261 && (OVERLAYP (overlay
)
6262 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6263 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6265 RESTORE_IT (it
, it
, it2data
);
6269 /* Newline is not replaced by anything -- so we are done. */
6270 RESTORE_IT (it
, it
, it2data
);
6276 IT_CHARPOS (*it
) = beg
;
6277 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6281 it
->continuation_lines_width
= 0;
6283 eassert (IT_CHARPOS (*it
) >= BEGV
);
6284 eassert (IT_CHARPOS (*it
) == BEGV
6285 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6290 /* Reseat iterator IT at the previous visible line start. Skip
6291 invisible text that is so either due to text properties or due to
6292 selective display. At the end, update IT's overlay information,
6293 face information etc. */
6296 reseat_at_previous_visible_line_start (struct it
*it
)
6298 back_to_previous_visible_line_start (it
);
6299 reseat (it
, it
->current
.pos
, true);
6304 /* Reseat iterator IT on the next visible line start in the current
6305 buffer. ON_NEWLINE_P means position IT on the newline
6306 preceding the line start. Skip over invisible text that is so
6307 because of selective display. Compute faces, overlays etc at the
6308 new position. Note that this function does not skip over text that
6309 is invisible because of text properties. */
6312 reseat_at_next_visible_line_start (struct it
*it
, bool on_newline_p
)
6314 bool skipped_p
= false;
6315 struct bidi_it bidi_it_prev
;
6316 bool newline_found_p
6317 = forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6319 /* Skip over lines that are invisible because they are indented
6320 more than the value of IT->selective. */
6321 if (it
->selective
> 0)
6322 while (IT_CHARPOS (*it
) < ZV
6323 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6326 eassert (IT_BYTEPOS (*it
) == BEGV
6327 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6329 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6332 /* Position on the newline if that's what's requested. */
6333 if (on_newline_p
&& newline_found_p
)
6335 if (STRINGP (it
->string
))
6337 if (IT_STRING_CHARPOS (*it
) > 0)
6341 --IT_STRING_CHARPOS (*it
);
6342 --IT_STRING_BYTEPOS (*it
);
6346 /* We need to restore the bidi iterator to the state
6347 it had on the newline, and resync the IT's
6348 position with that. */
6349 it
->bidi_it
= bidi_it_prev
;
6350 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6351 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6355 else if (IT_CHARPOS (*it
) > BEGV
)
6364 /* We need to restore the bidi iterator to the state it
6365 had on the newline and resync IT with that. */
6366 it
->bidi_it
= bidi_it_prev
;
6367 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6368 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6370 reseat (it
, it
->current
.pos
, false);
6374 reseat (it
, it
->current
.pos
, false);
6381 /***********************************************************************
6382 Changing an iterator's position
6383 ***********************************************************************/
6385 /* Change IT's current position to POS in current_buffer.
6386 If FORCE_P, always check for text properties at the new position.
6387 Otherwise, text properties are only looked up if POS >=
6388 IT->check_charpos of a property. */
6391 reseat (struct it
*it
, struct text_pos pos
, bool force_p
)
6393 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6395 reseat_1 (it
, pos
, false);
6397 /* Determine where to check text properties. Avoid doing it
6398 where possible because text property lookup is very expensive. */
6400 || CHARPOS (pos
) > it
->stop_charpos
6401 || CHARPOS (pos
) < original_pos
)
6405 /* For bidi iteration, we need to prime prev_stop and
6406 base_level_stop with our best estimations. */
6407 /* Implementation note: Of course, POS is not necessarily a
6408 stop position, so assigning prev_pos to it is a lie; we
6409 should have called compute_stop_backwards. However, if
6410 the current buffer does not include any R2L characters,
6411 that call would be a waste of cycles, because the
6412 iterator will never move back, and thus never cross this
6413 "fake" stop position. So we delay that backward search
6414 until the time we really need it, in next_element_from_buffer. */
6415 if (CHARPOS (pos
) != it
->prev_stop
)
6416 it
->prev_stop
= CHARPOS (pos
);
6417 if (CHARPOS (pos
) < it
->base_level_stop
)
6418 it
->base_level_stop
= 0; /* meaning it's unknown */
6424 it
->prev_stop
= it
->base_level_stop
= 0;
6433 /* Change IT's buffer position to POS. SET_STOP_P means set
6434 IT->stop_pos to POS, also. */
6437 reseat_1 (struct it
*it
, struct text_pos pos
, bool set_stop_p
)
6439 /* Don't call this function when scanning a C string. */
6440 eassert (it
->s
== NULL
);
6442 /* POS must be a reasonable value. */
6443 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6445 it
->current
.pos
= it
->position
= pos
;
6446 it
->end_charpos
= ZV
;
6448 it
->current
.dpvec_index
= -1;
6449 it
->current
.overlay_string_index
= -1;
6450 IT_STRING_CHARPOS (*it
) = -1;
6451 IT_STRING_BYTEPOS (*it
) = -1;
6453 it
->method
= GET_FROM_BUFFER
;
6454 it
->object
= it
->w
->contents
;
6455 it
->area
= TEXT_AREA
;
6456 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6458 it
->string_from_display_prop_p
= false;
6459 it
->string_from_prefix_prop_p
= false;
6461 it
->from_disp_prop_p
= false;
6462 it
->face_before_selective_p
= false;
6465 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6467 bidi_unshelve_cache (NULL
, false);
6468 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6469 it
->bidi_it
.string
.s
= NULL
;
6470 it
->bidi_it
.string
.lstring
= Qnil
;
6471 it
->bidi_it
.string
.bufpos
= 0;
6472 it
->bidi_it
.string
.from_disp_str
= false;
6473 it
->bidi_it
.string
.unibyte
= false;
6474 it
->bidi_it
.w
= it
->w
;
6479 it
->stop_charpos
= CHARPOS (pos
);
6480 it
->base_level_stop
= CHARPOS (pos
);
6482 /* This make the information stored in it->cmp_it invalidate. */
6487 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6488 If S is non-null, it is a C string to iterate over. Otherwise,
6489 STRING gives a Lisp string to iterate over.
6491 If PRECISION > 0, don't return more then PRECISION number of
6492 characters from the string.
6494 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6495 characters have been returned. FIELD_WIDTH < 0 means an infinite
6498 MULTIBYTE = 0 means disable processing of multibyte characters,
6499 MULTIBYTE > 0 means enable it,
6500 MULTIBYTE < 0 means use IT->multibyte_p.
6502 IT must be initialized via a prior call to init_iterator before
6503 calling this function. */
6506 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6507 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6510 /* No text property checks performed by default, but see below. */
6511 it
->stop_charpos
= -1;
6513 /* Set iterator position and end position. */
6514 memset (&it
->current
, 0, sizeof it
->current
);
6515 it
->current
.overlay_string_index
= -1;
6516 it
->current
.dpvec_index
= -1;
6517 eassert (charpos
>= 0);
6519 /* If STRING is specified, use its multibyteness, otherwise use the
6520 setting of MULTIBYTE, if specified. */
6522 it
->multibyte_p
= multibyte
> 0;
6524 /* Bidirectional reordering of strings is controlled by the default
6525 value of bidi-display-reordering. Don't try to reorder while
6526 loading loadup.el, as the necessary character property tables are
6527 not yet available. */
6530 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6534 eassert (STRINGP (string
));
6535 it
->string
= string
;
6537 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6538 it
->method
= GET_FROM_STRING
;
6539 it
->current
.string_pos
= string_pos (charpos
, string
);
6543 it
->bidi_it
.string
.lstring
= string
;
6544 it
->bidi_it
.string
.s
= NULL
;
6545 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6546 it
->bidi_it
.string
.bufpos
= 0;
6547 it
->bidi_it
.string
.from_disp_str
= false;
6548 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6549 it
->bidi_it
.w
= it
->w
;
6550 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6551 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6556 it
->s
= (const unsigned char *) s
;
6559 /* Note that we use IT->current.pos, not it->current.string_pos,
6560 for displaying C strings. */
6561 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6562 if (it
->multibyte_p
)
6564 it
->current
.pos
= c_string_pos (charpos
, s
, true);
6565 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, true);
6569 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6570 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6575 it
->bidi_it
.string
.lstring
= Qnil
;
6576 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6577 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6578 it
->bidi_it
.string
.bufpos
= 0;
6579 it
->bidi_it
.string
.from_disp_str
= false;
6580 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6581 it
->bidi_it
.w
= it
->w
;
6582 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6585 it
->method
= GET_FROM_C_STRING
;
6588 /* PRECISION > 0 means don't return more than PRECISION characters
6590 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6592 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6594 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6597 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6598 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6599 FIELD_WIDTH < 0 means infinite field width. This is useful for
6600 padding with `-' at the end of a mode line. */
6601 if (field_width
< 0)
6602 field_width
= INFINITY
;
6603 /* Implementation note: We deliberately don't enlarge
6604 it->bidi_it.string.schars here to fit it->end_charpos, because
6605 the bidi iterator cannot produce characters out of thin air. */
6606 if (field_width
> it
->end_charpos
- charpos
)
6607 it
->end_charpos
= charpos
+ field_width
;
6609 /* Use the standard display table for displaying strings. */
6610 if (DISP_TABLE_P (Vstandard_display_table
))
6611 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6613 it
->stop_charpos
= charpos
;
6614 it
->prev_stop
= charpos
;
6615 it
->base_level_stop
= 0;
6618 it
->bidi_it
.first_elt
= true;
6619 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6620 it
->bidi_it
.disp_pos
= -1;
6622 if (s
== NULL
&& it
->multibyte_p
)
6624 ptrdiff_t endpos
= SCHARS (it
->string
);
6625 if (endpos
> it
->end_charpos
)
6626 endpos
= it
->end_charpos
;
6627 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6635 /***********************************************************************
6637 ***********************************************************************/
6639 /* Map enum it_method value to corresponding next_element_from_* function. */
6641 typedef bool (*next_element_function
) (struct it
*);
6643 static next_element_function
const get_next_element
[NUM_IT_METHODS
] =
6645 next_element_from_buffer
,
6646 next_element_from_display_vector
,
6647 next_element_from_string
,
6648 next_element_from_c_string
,
6649 next_element_from_image
,
6650 next_element_from_stretch
6653 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6656 /* Return true iff a character at CHARPOS (and BYTEPOS) is composed
6657 (possibly with the following characters). */
6659 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6660 ((IT)->cmp_it.id >= 0 \
6661 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6662 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6663 END_CHARPOS, (IT)->w, \
6664 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6668 /* Lookup the char-table Vglyphless_char_display for character C (-1
6669 if we want information for no-font case), and return the display
6670 method symbol. By side-effect, update it->what and
6671 it->glyphless_method. This function is called from
6672 get_next_display_element for each character element, and from
6673 x_produce_glyphs when no suitable font was found. */
6676 lookup_glyphless_char_display (int c
, struct it
*it
)
6678 Lisp_Object glyphless_method
= Qnil
;
6680 if (CHAR_TABLE_P (Vglyphless_char_display
)
6681 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6685 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6686 if (CONSP (glyphless_method
))
6687 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6688 ? XCAR (glyphless_method
)
6689 : XCDR (glyphless_method
);
6692 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6696 if (NILP (glyphless_method
))
6699 /* The default is to display the character by a proper font. */
6701 /* The default for the no-font case is to display an empty box. */
6702 glyphless_method
= Qempty_box
;
6704 if (EQ (glyphless_method
, Qzero_width
))
6707 return glyphless_method
;
6708 /* This method can't be used for the no-font case. */
6709 glyphless_method
= Qempty_box
;
6711 if (EQ (glyphless_method
, Qthin_space
))
6712 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6713 else if (EQ (glyphless_method
, Qempty_box
))
6714 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6715 else if (EQ (glyphless_method
, Qhex_code
))
6716 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6717 else if (STRINGP (glyphless_method
))
6718 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6721 /* Invalid value. We use the default method. */
6722 glyphless_method
= Qnil
;
6725 it
->what
= IT_GLYPHLESS
;
6726 return glyphless_method
;
6729 /* Merge escape glyph face and cache the result. */
6731 static struct frame
*last_escape_glyph_frame
= NULL
;
6732 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6733 static int last_escape_glyph_merged_face_id
= 0;
6736 merge_escape_glyph_face (struct it
*it
)
6740 if (it
->f
== last_escape_glyph_frame
6741 && it
->face_id
== last_escape_glyph_face_id
)
6742 face_id
= last_escape_glyph_merged_face_id
;
6745 /* Merge the `escape-glyph' face into the current face. */
6746 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6747 last_escape_glyph_frame
= it
->f
;
6748 last_escape_glyph_face_id
= it
->face_id
;
6749 last_escape_glyph_merged_face_id
= face_id
;
6754 /* Likewise for glyphless glyph face. */
6756 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6757 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6758 static int last_glyphless_glyph_merged_face_id
= 0;
6761 merge_glyphless_glyph_face (struct it
*it
)
6765 if (it
->f
== last_glyphless_glyph_frame
6766 && it
->face_id
== last_glyphless_glyph_face_id
)
6767 face_id
= last_glyphless_glyph_merged_face_id
;
6770 /* Merge the `glyphless-char' face into the current face. */
6771 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6772 last_glyphless_glyph_frame
= it
->f
;
6773 last_glyphless_glyph_face_id
= it
->face_id
;
6774 last_glyphless_glyph_merged_face_id
= face_id
;
6779 /* Load IT's display element fields with information about the next
6780 display element from the current position of IT. Value is false if
6781 end of buffer (or C string) is reached. */
6784 get_next_display_element (struct it
*it
)
6786 /* True means that we found a display element. False means that
6787 we hit the end of what we iterate over. Performance note: the
6788 function pointer `method' used here turns out to be faster than
6789 using a sequence of if-statements. */
6793 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6795 if (it
->what
== IT_CHARACTER
)
6797 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6798 and only if (a) the resolved directionality of that character
6800 /* FIXME: Do we need an exception for characters from display
6802 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
6803 && !inhibit_bidi_mirroring
)
6804 it
->c
= bidi_mirror_char (it
->c
);
6805 /* Map via display table or translate control characters.
6806 IT->c, IT->len etc. have been set to the next character by
6807 the function call above. If we have a display table, and it
6808 contains an entry for IT->c, translate it. Don't do this if
6809 IT->c itself comes from a display table, otherwise we could
6810 end up in an infinite recursion. (An alternative could be to
6811 count the recursion depth of this function and signal an
6812 error when a certain maximum depth is reached.) Is it worth
6814 if (success_p
&& it
->dpvec
== NULL
)
6817 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6818 bool nonascii_space_p
= false;
6819 bool nonascii_hyphen_p
= false;
6820 int c
= it
->c
; /* This is the character to display. */
6822 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6824 eassert (SINGLE_BYTE_CHAR_P (c
));
6825 if (unibyte_display_via_language_environment
)
6827 c
= DECODE_CHAR (unibyte
, c
);
6829 c
= BYTE8_TO_CHAR (it
->c
);
6832 c
= BYTE8_TO_CHAR (it
->c
);
6836 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6839 struct Lisp_Vector
*v
= XVECTOR (dv
);
6841 /* Return the first character from the display table
6842 entry, if not empty. If empty, don't display the
6843 current character. */
6846 it
->dpvec_char_len
= it
->len
;
6847 it
->dpvec
= v
->contents
;
6848 it
->dpend
= v
->contents
+ v
->header
.size
;
6849 it
->current
.dpvec_index
= 0;
6850 it
->dpvec_face_id
= -1;
6851 it
->saved_face_id
= it
->face_id
;
6852 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6853 it
->ellipsis_p
= false;
6857 set_iterator_to_next (it
, false);
6862 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6864 if (it
->what
== IT_GLYPHLESS
)
6866 /* Don't display this character. */
6867 set_iterator_to_next (it
, false);
6871 /* If `nobreak-char-display' is non-nil, we display
6872 non-ASCII spaces and hyphens specially. */
6873 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6876 nonascii_space_p
= true;
6877 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6878 nonascii_hyphen_p
= true;
6881 /* Translate control characters into `\003' or `^C' form.
6882 Control characters coming from a display table entry are
6883 currently not translated because we use IT->dpvec to hold
6884 the translation. This could easily be changed but I
6885 don't believe that it is worth doing.
6887 The characters handled by `nobreak-char-display' must be
6890 Non-printable characters and raw-byte characters are also
6891 translated to octal form. */
6892 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
6893 ? (it
->area
!= TEXT_AREA
6894 /* In mode line, treat \n, \t like other crl chars. */
6897 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6898 || (c
!= '\n' && c
!= '\t'))
6900 || nonascii_hyphen_p
6902 || ! CHAR_PRINTABLE_P (c
))))
6904 /* C is a control character, non-ASCII space/hyphen,
6905 raw-byte, or a non-printable character which must be
6906 displayed either as '\003' or as `^C' where the '\\'
6907 and '^' can be defined in the display table. Fill
6908 IT->ctl_chars with glyphs for what we have to
6909 display. Then, set IT->dpvec to these glyphs. */
6916 /* Handle control characters with ^. */
6918 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6922 g
= '^'; /* default glyph for Control */
6923 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6925 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6927 g
= GLYPH_CODE_CHAR (gc
);
6928 lface_id
= GLYPH_CODE_FACE (gc
);
6932 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6933 : merge_escape_glyph_face (it
));
6935 XSETINT (it
->ctl_chars
[0], g
);
6936 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6938 goto display_control
;
6941 /* Handle non-ascii space in the mode where it only gets
6944 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6946 /* Merge `nobreak-space' into the current face. */
6947 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6949 XSETINT (it
->ctl_chars
[0], ' ');
6951 goto display_control
;
6954 /* Handle sequences that start with the "escape glyph". */
6956 /* the default escape glyph is \. */
6957 escape_glyph
= '\\';
6960 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6962 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6963 lface_id
= GLYPH_CODE_FACE (gc
);
6967 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6968 : merge_escape_glyph_face (it
));
6970 /* Draw non-ASCII hyphen with just highlighting: */
6972 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6974 XSETINT (it
->ctl_chars
[0], '-');
6976 goto display_control
;
6979 /* Draw non-ASCII space/hyphen with escape glyph: */
6981 if (nonascii_space_p
|| nonascii_hyphen_p
)
6983 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6984 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6986 goto display_control
;
6993 if (CHAR_BYTE8_P (c
))
6994 /* Display \200 instead of \17777600. */
6995 c
= CHAR_TO_BYTE8 (c
);
6996 len
= sprintf (str
, "%03o", c
+ 0u);
6998 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6999 for (i
= 0; i
< len
; i
++)
7000 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
7005 /* Set up IT->dpvec and return first character from it. */
7006 it
->dpvec_char_len
= it
->len
;
7007 it
->dpvec
= it
->ctl_chars
;
7008 it
->dpend
= it
->dpvec
+ ctl_len
;
7009 it
->current
.dpvec_index
= 0;
7010 it
->dpvec_face_id
= face_id
;
7011 it
->saved_face_id
= it
->face_id
;
7012 it
->method
= GET_FROM_DISPLAY_VECTOR
;
7013 it
->ellipsis_p
= false;
7016 it
->char_to_display
= c
;
7020 it
->char_to_display
= it
->c
;
7024 #ifdef HAVE_WINDOW_SYSTEM
7025 /* Adjust face id for a multibyte character. There are no multibyte
7026 character in unibyte text. */
7027 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
7030 && FRAME_WINDOW_P (it
->f
))
7032 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7034 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
7036 /* Automatic composition with glyph-string. */
7037 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
7039 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
7043 ptrdiff_t pos
= (it
->s
? -1
7044 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
7045 : IT_CHARPOS (*it
));
7048 if (it
->what
== IT_CHARACTER
)
7049 c
= it
->char_to_display
;
7052 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7056 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7057 /* TAB in a composition means display glyphs with
7058 padding space on the left or right. */
7059 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7062 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7065 #endif /* HAVE_WINDOW_SYSTEM */
7068 /* Is this character the last one of a run of characters with
7069 box? If yes, set IT->end_of_box_run_p to true. */
7073 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7075 int face_id
= underlying_face_id (it
);
7076 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7080 if (face
->box
== FACE_NO_BOX
)
7082 /* If the box comes from face properties in a
7083 display string, check faces in that string. */
7084 int string_face_id
= face_after_it_pos (it
);
7085 it
->end_of_box_run_p
7086 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7089 /* Otherwise, the box comes from the underlying face.
7090 If this is the last string character displayed, check
7091 the next buffer location. */
7092 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7093 /* n_overlay_strings is unreliable unless
7094 overlay_string_index is non-negative. */
7095 && ((it
->current
.overlay_string_index
>= 0
7096 && (it
->current
.overlay_string_index
7097 == it
->n_overlay_strings
- 1))
7098 /* A string from display property. */
7099 || it
->from_disp_prop_p
))
7103 struct text_pos pos
= it
->current
.pos
;
7105 /* For a string from a display property, the next
7106 buffer position is stored in the 'position'
7107 member of the iteration stack slot below the
7108 current one, see handle_single_display_spec. By
7109 contrast, it->current.pos was is not yet updated
7110 to point to that buffer position; that will
7111 happen in pop_it, after we finish displaying the
7112 current string. Note that we already checked
7113 above that it->sp is positive, so subtracting one
7115 if (it
->from_disp_prop_p
)
7116 pos
= (it
->stack
+ it
->sp
- 1)->position
;
7118 INC_TEXT_POS (pos
, it
->multibyte_p
);
7120 if (CHARPOS (pos
) >= ZV
)
7121 it
->end_of_box_run_p
= true;
7124 next_face_id
= face_at_buffer_position
7125 (it
->w
, CHARPOS (pos
), &ignore
,
7126 CHARPOS (pos
) + TEXT_PROP_DISTANCE_LIMIT
, false, -1);
7127 it
->end_of_box_run_p
7128 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7134 /* next_element_from_display_vector sets this flag according to
7135 faces of the display vector glyphs, see there. */
7136 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7138 int face_id
= face_after_it_pos (it
);
7139 it
->end_of_box_run_p
7140 = (face_id
!= it
->face_id
7141 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7144 /* If we reached the end of the object we've been iterating (e.g., a
7145 display string or an overlay string), and there's something on
7146 IT->stack, proceed with what's on the stack. It doesn't make
7147 sense to return false if there's unprocessed stuff on the stack,
7148 because otherwise that stuff will never be displayed. */
7149 if (!success_p
&& it
->sp
> 0)
7151 set_iterator_to_next (it
, false);
7152 success_p
= get_next_display_element (it
);
7155 /* Value is false if end of buffer or string reached. */
7160 /* Move IT to the next display element.
7162 RESEAT_P means if called on a newline in buffer text,
7163 skip to the next visible line start.
7165 Functions get_next_display_element and set_iterator_to_next are
7166 separate because I find this arrangement easier to handle than a
7167 get_next_display_element function that also increments IT's
7168 position. The way it is we can first look at an iterator's current
7169 display element, decide whether it fits on a line, and if it does,
7170 increment the iterator position. The other way around we probably
7171 would either need a flag indicating whether the iterator has to be
7172 incremented the next time, or we would have to implement a
7173 decrement position function which would not be easy to write. */
7176 set_iterator_to_next (struct it
*it
, bool reseat_p
)
7178 /* Reset flags indicating start and end of a sequence of characters
7179 with box. Reset them at the start of this function because
7180 moving the iterator to a new position might set them. */
7181 it
->start_of_box_run_p
= it
->end_of_box_run_p
= false;
7185 case GET_FROM_BUFFER
:
7186 /* The current display element of IT is a character from
7187 current_buffer. Advance in the buffer, and maybe skip over
7188 invisible lines that are so because of selective display. */
7189 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7190 reseat_at_next_visible_line_start (it
, false);
7191 else if (it
->cmp_it
.id
>= 0)
7193 /* We are currently getting glyphs from a composition. */
7196 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7197 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7203 /* Update IT's char/byte positions to point to the first
7204 character of the next grapheme cluster, or to the
7205 character visually after the current composition. */
7206 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7207 bidi_move_to_visually_next (&it
->bidi_it
);
7208 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7209 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7212 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7213 && it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7215 /* Composition created while scanning forward. Proceed
7216 to the next grapheme cluster. */
7217 it
->cmp_it
.from
= it
->cmp_it
.to
;
7219 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7220 && it
->cmp_it
.from
> 0)
7222 /* Composition created while scanning backward. Proceed
7223 to the previous grapheme cluster. */
7224 it
->cmp_it
.to
= it
->cmp_it
.from
;
7228 /* No more grapheme clusters in this composition.
7229 Find the next stop position. */
7230 ptrdiff_t stop
= it
->end_charpos
;
7232 if (it
->bidi_it
.scan_dir
< 0)
7233 /* Now we are scanning backward and don't know
7236 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7237 IT_BYTEPOS (*it
), stop
, Qnil
);
7242 eassert (it
->len
!= 0);
7246 IT_BYTEPOS (*it
) += it
->len
;
7247 IT_CHARPOS (*it
) += 1;
7251 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7252 /* If this is a new paragraph, determine its base
7253 direction (a.k.a. its base embedding level). */
7254 if (it
->bidi_it
.new_paragraph
)
7255 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
7257 bidi_move_to_visually_next (&it
->bidi_it
);
7258 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7259 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7260 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7262 /* As the scan direction was changed, we must
7263 re-compute the stop position for composition. */
7264 ptrdiff_t stop
= it
->end_charpos
;
7265 if (it
->bidi_it
.scan_dir
< 0)
7267 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7268 IT_BYTEPOS (*it
), stop
, Qnil
);
7271 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7275 case GET_FROM_C_STRING
:
7276 /* Current display element of IT is from a C string. */
7278 /* If the string position is beyond string's end, it means
7279 next_element_from_c_string is padding the string with
7280 blanks, in which case we bypass the bidi iterator,
7281 because it cannot deal with such virtual characters. */
7282 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7284 IT_BYTEPOS (*it
) += it
->len
;
7285 IT_CHARPOS (*it
) += 1;
7289 bidi_move_to_visually_next (&it
->bidi_it
);
7290 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7291 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7295 case GET_FROM_DISPLAY_VECTOR
:
7296 /* Current display element of IT is from a display table entry.
7297 Advance in the display table definition. Reset it to null if
7298 end reached, and continue with characters from buffers/
7300 ++it
->current
.dpvec_index
;
7302 /* Restore face of the iterator to what they were before the
7303 display vector entry (these entries may contain faces). */
7304 it
->face_id
= it
->saved_face_id
;
7306 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7308 bool recheck_faces
= it
->ellipsis_p
;
7311 it
->method
= GET_FROM_C_STRING
;
7312 else if (STRINGP (it
->string
))
7313 it
->method
= GET_FROM_STRING
;
7316 it
->method
= GET_FROM_BUFFER
;
7317 it
->object
= it
->w
->contents
;
7321 it
->current
.dpvec_index
= -1;
7323 /* Skip over characters which were displayed via IT->dpvec. */
7324 if (it
->dpvec_char_len
< 0)
7325 reseat_at_next_visible_line_start (it
, true);
7326 else if (it
->dpvec_char_len
> 0)
7328 it
->len
= it
->dpvec_char_len
;
7329 set_iterator_to_next (it
, reseat_p
);
7332 /* Maybe recheck faces after display vector. */
7335 if (it
->method
== GET_FROM_STRING
)
7336 it
->stop_charpos
= IT_STRING_CHARPOS (*it
);
7338 it
->stop_charpos
= IT_CHARPOS (*it
);
7343 case GET_FROM_STRING
:
7344 /* Current display element is a character from a Lisp string. */
7345 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7346 /* Don't advance past string end. These conditions are true
7347 when set_iterator_to_next is called at the end of
7348 get_next_display_element, in which case the Lisp string is
7349 already exhausted, and all we want is pop the iterator
7351 if (it
->current
.overlay_string_index
>= 0)
7353 /* This is an overlay string, so there's no padding with
7354 spaces, and the number of characters in the string is
7355 where the string ends. */
7356 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7357 goto consider_string_end
;
7361 /* Not an overlay string. There could be padding, so test
7362 against it->end_charpos. */
7363 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7364 goto consider_string_end
;
7366 if (it
->cmp_it
.id
>= 0)
7368 /* We are delivering display elements from a composition.
7369 Update the string position past the grapheme cluster
7370 we've just processed. */
7373 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7374 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7380 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7381 bidi_move_to_visually_next (&it
->bidi_it
);
7382 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7383 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7386 /* Did we exhaust all the grapheme clusters of this
7388 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7389 && (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
))
7391 /* Not all the grapheme clusters were processed yet;
7392 advance to the next cluster. */
7393 it
->cmp_it
.from
= it
->cmp_it
.to
;
7395 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7396 && it
->cmp_it
.from
> 0)
7398 /* Likewise: advance to the next cluster, but going in
7399 the reverse direction. */
7400 it
->cmp_it
.to
= it
->cmp_it
.from
;
7404 /* This composition was fully processed; find the next
7405 candidate place for checking for composed
7407 /* Always limit string searches to the string length;
7408 any padding spaces are not part of the string, and
7409 there cannot be any compositions in that padding. */
7410 ptrdiff_t stop
= SCHARS (it
->string
);
7412 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
7414 else if (it
->end_charpos
< stop
)
7416 /* Cf. PRECISION in reseat_to_string: we might be
7417 limited in how many of the string characters we
7419 stop
= it
->end_charpos
;
7421 composition_compute_stop_pos (&it
->cmp_it
,
7422 IT_STRING_CHARPOS (*it
),
7423 IT_STRING_BYTEPOS (*it
), stop
,
7430 /* If the string position is beyond string's end, it
7431 means next_element_from_string is padding the string
7432 with blanks, in which case we bypass the bidi
7433 iterator, because it cannot deal with such virtual
7435 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7437 IT_STRING_BYTEPOS (*it
) += it
->len
;
7438 IT_STRING_CHARPOS (*it
) += 1;
7442 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7444 bidi_move_to_visually_next (&it
->bidi_it
);
7445 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7446 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7447 /* If the scan direction changes, we may need to update
7448 the place where to check for composed characters. */
7449 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7451 ptrdiff_t stop
= SCHARS (it
->string
);
7453 if (it
->bidi_it
.scan_dir
< 0)
7455 else if (it
->end_charpos
< stop
)
7456 stop
= it
->end_charpos
;
7458 composition_compute_stop_pos (&it
->cmp_it
,
7459 IT_STRING_CHARPOS (*it
),
7460 IT_STRING_BYTEPOS (*it
), stop
,
7466 consider_string_end
:
7468 if (it
->current
.overlay_string_index
>= 0)
7470 /* IT->string is an overlay string. Advance to the
7471 next, if there is one. */
7472 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7474 it
->ellipsis_p
= false;
7475 next_overlay_string (it
);
7477 setup_for_ellipsis (it
, 0);
7482 /* IT->string is not an overlay string. If we reached
7483 its end, and there is something on IT->stack, proceed
7484 with what is on the stack. This can be either another
7485 string, this time an overlay string, or a buffer. */
7486 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7490 if (it
->method
== GET_FROM_STRING
)
7491 goto consider_string_end
;
7496 case GET_FROM_IMAGE
:
7497 case GET_FROM_STRETCH
:
7498 /* The position etc with which we have to proceed are on
7499 the stack. The position may be at the end of a string,
7500 if the `display' property takes up the whole string. */
7501 eassert (it
->sp
> 0);
7503 if (it
->method
== GET_FROM_STRING
)
7504 goto consider_string_end
;
7508 /* There are no other methods defined, so this should be a bug. */
7512 eassert (it
->method
!= GET_FROM_STRING
7513 || (STRINGP (it
->string
)
7514 && IT_STRING_CHARPOS (*it
) >= 0));
7517 /* Load IT's display element fields with information about the next
7518 display element which comes from a display table entry or from the
7519 result of translating a control character to one of the forms `^C'
7522 IT->dpvec holds the glyphs to return as characters.
7523 IT->saved_face_id holds the face id before the display vector--it
7524 is restored into IT->face_id in set_iterator_to_next. */
7527 next_element_from_display_vector (struct it
*it
)
7530 int prev_face_id
= it
->face_id
;
7534 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7536 it
->face_id
= it
->saved_face_id
;
7538 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7539 That seemed totally bogus - so I changed it... */
7540 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7542 if (GLYPH_CODE_P (gc
))
7544 struct face
*this_face
, *prev_face
, *next_face
;
7546 it
->c
= GLYPH_CODE_CHAR (gc
);
7547 it
->len
= CHAR_BYTES (it
->c
);
7549 /* The entry may contain a face id to use. Such a face id is
7550 the id of a Lisp face, not a realized face. A face id of
7551 zero means no face is specified. */
7552 if (it
->dpvec_face_id
>= 0)
7553 it
->face_id
= it
->dpvec_face_id
;
7556 int lface_id
= GLYPH_CODE_FACE (gc
);
7558 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7562 /* Glyphs in the display vector could have the box face, so we
7563 need to set the related flags in the iterator, as
7565 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7566 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7568 /* Is this character the first character of a box-face run? */
7569 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7571 || prev_face
->box
== FACE_NO_BOX
));
7573 /* For the last character of the box-face run, we need to look
7574 either at the next glyph from the display vector, or at the
7575 face we saw before the display vector. */
7576 next_face_id
= it
->saved_face_id
;
7577 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7579 if (it
->dpvec_face_id
>= 0)
7580 next_face_id
= it
->dpvec_face_id
;
7584 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7587 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7591 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7592 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7594 || next_face
->box
== FACE_NO_BOX
));
7595 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7598 /* Display table entry is invalid. Return a space. */
7599 it
->c
= ' ', it
->len
= 1;
7601 /* Don't change position and object of the iterator here. They are
7602 still the values of the character that had this display table
7603 entry or was translated, and that's what we want. */
7604 it
->what
= IT_CHARACTER
;
7608 /* Get the first element of string/buffer in the visual order, after
7609 being reseated to a new position in a string or a buffer. */
7611 get_visually_first_element (struct it
*it
)
7613 bool string_p
= STRINGP (it
->string
) || it
->s
;
7614 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7615 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7617 if (STRINGP (it
->string
))
7619 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7620 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7624 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7625 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7628 if (it
->bidi_it
.charpos
== eob
)
7630 /* Nothing to do, but reset the FIRST_ELT flag, like
7631 bidi_paragraph_init does, because we are not going to
7633 it
->bidi_it
.first_elt
= false;
7635 else if (it
->bidi_it
.charpos
== bob
7637 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7638 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7640 /* If we are at the beginning of a line/string, we can produce
7641 the next element right away. */
7642 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7643 bidi_move_to_visually_next (&it
->bidi_it
);
7647 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7649 /* We need to prime the bidi iterator starting at the line's or
7650 string's beginning, before we will be able to produce the
7653 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7655 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7656 IT_BYTEPOS (*it
), -1,
7657 &it
->bidi_it
.bytepos
);
7658 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7661 /* Now return to buffer/string position where we were asked
7662 to get the next display element, and produce that. */
7663 bidi_move_to_visually_next (&it
->bidi_it
);
7665 while (it
->bidi_it
.bytepos
!= orig_bytepos
7666 && it
->bidi_it
.charpos
< eob
);
7669 /* Adjust IT's position information to where we ended up. */
7670 if (STRINGP (it
->string
))
7672 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7673 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7677 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7678 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7681 if (STRINGP (it
->string
) || !it
->s
)
7683 ptrdiff_t stop
, charpos
, bytepos
;
7685 if (STRINGP (it
->string
))
7688 stop
= SCHARS (it
->string
);
7689 if (stop
> it
->end_charpos
)
7690 stop
= it
->end_charpos
;
7691 charpos
= IT_STRING_CHARPOS (*it
);
7692 bytepos
= IT_STRING_BYTEPOS (*it
);
7696 stop
= it
->end_charpos
;
7697 charpos
= IT_CHARPOS (*it
);
7698 bytepos
= IT_BYTEPOS (*it
);
7700 if (it
->bidi_it
.scan_dir
< 0)
7702 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7707 /* Load IT with the next display element from Lisp string IT->string.
7708 IT->current.string_pos is the current position within the string.
7709 If IT->current.overlay_string_index >= 0, the Lisp string is an
7713 next_element_from_string (struct it
*it
)
7715 struct text_pos position
;
7717 eassert (STRINGP (it
->string
));
7718 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7719 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7720 position
= it
->current
.string_pos
;
7722 /* With bidi reordering, the character to display might not be the
7723 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT means
7724 that we were reseat()ed to a new string, whose paragraph
7725 direction is not known. */
7726 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7728 get_visually_first_element (it
);
7729 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7732 /* Time to check for invisible text? */
7733 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7735 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7738 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7739 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7741 /* With bidi non-linear iteration, we could find
7742 ourselves far beyond the last computed stop_charpos,
7743 with several other stop positions in between that we
7744 missed. Scan them all now, in buffer's logical
7745 order, until we find and handle the last stop_charpos
7746 that precedes our current position. */
7747 handle_stop_backwards (it
, it
->stop_charpos
);
7748 return GET_NEXT_DISPLAY_ELEMENT (it
);
7754 /* Take note of the stop position we just moved
7755 across, for when we will move back across it. */
7756 it
->prev_stop
= it
->stop_charpos
;
7757 /* If we are at base paragraph embedding level, take
7758 note of the last stop position seen at this
7760 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7761 it
->base_level_stop
= it
->stop_charpos
;
7765 /* Since a handler may have changed IT->method, we must
7767 return GET_NEXT_DISPLAY_ELEMENT (it
);
7771 /* If we are before prev_stop, we may have overstepped
7772 on our way backwards a stop_pos, and if so, we need
7773 to handle that stop_pos. */
7774 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7775 /* We can sometimes back up for reasons that have nothing
7776 to do with bidi reordering. E.g., compositions. The
7777 code below is only needed when we are above the base
7778 embedding level, so test for that explicitly. */
7779 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7781 /* If we lost track of base_level_stop, we have no better
7782 place for handle_stop_backwards to start from than string
7783 beginning. This happens, e.g., when we were reseated to
7784 the previous screenful of text by vertical-motion. */
7785 if (it
->base_level_stop
<= 0
7786 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7787 it
->base_level_stop
= 0;
7788 handle_stop_backwards (it
, it
->base_level_stop
);
7789 return GET_NEXT_DISPLAY_ELEMENT (it
);
7793 if (it
->current
.overlay_string_index
>= 0)
7795 /* Get the next character from an overlay string. In overlay
7796 strings, there is no field width or padding with spaces to
7798 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7803 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7804 IT_STRING_BYTEPOS (*it
),
7805 it
->bidi_it
.scan_dir
< 0
7807 : SCHARS (it
->string
))
7808 && next_element_from_composition (it
))
7812 else if (STRING_MULTIBYTE (it
->string
))
7814 const unsigned char *s
= (SDATA (it
->string
)
7815 + IT_STRING_BYTEPOS (*it
));
7816 it
->c
= string_char_and_length (s
, &it
->len
);
7820 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7826 /* Get the next character from a Lisp string that is not an
7827 overlay string. Such strings come from the mode line, for
7828 example. We may have to pad with spaces, or truncate the
7829 string. See also next_element_from_c_string. */
7830 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7835 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7837 /* Pad with spaces. */
7838 it
->c
= ' ', it
->len
= 1;
7839 CHARPOS (position
) = BYTEPOS (position
) = -1;
7841 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7842 IT_STRING_BYTEPOS (*it
),
7843 it
->bidi_it
.scan_dir
< 0
7845 : it
->string_nchars
)
7846 && next_element_from_composition (it
))
7850 else if (STRING_MULTIBYTE (it
->string
))
7852 const unsigned char *s
= (SDATA (it
->string
)
7853 + IT_STRING_BYTEPOS (*it
));
7854 it
->c
= string_char_and_length (s
, &it
->len
);
7858 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7863 /* Record what we have and where it came from. */
7864 it
->what
= IT_CHARACTER
;
7865 it
->object
= it
->string
;
7866 it
->position
= position
;
7871 /* Load IT with next display element from C string IT->s.
7872 IT->string_nchars is the maximum number of characters to return
7873 from the string. IT->end_charpos may be greater than
7874 IT->string_nchars when this function is called, in which case we
7875 may have to return padding spaces. Value is false if end of string
7876 reached, including padding spaces. */
7879 next_element_from_c_string (struct it
*it
)
7881 bool success_p
= true;
7884 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7885 it
->what
= IT_CHARACTER
;
7886 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7887 it
->object
= make_number (0);
7889 /* With bidi reordering, the character to display might not be the
7890 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
7891 we were reseated to a new string, whose paragraph direction is
7893 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7894 get_visually_first_element (it
);
7896 /* IT's position can be greater than IT->string_nchars in case a
7897 field width or precision has been specified when the iterator was
7899 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7901 /* End of the game. */
7905 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7907 /* Pad with spaces. */
7908 it
->c
= ' ', it
->len
= 1;
7909 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7911 else if (it
->multibyte_p
)
7912 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7914 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7920 /* Set up IT to return characters from an ellipsis, if appropriate.
7921 The definition of the ellipsis glyphs may come from a display table
7922 entry. This function fills IT with the first glyph from the
7923 ellipsis if an ellipsis is to be displayed. */
7926 next_element_from_ellipsis (struct it
*it
)
7928 if (it
->selective_display_ellipsis_p
)
7929 setup_for_ellipsis (it
, it
->len
);
7932 /* The face at the current position may be different from the
7933 face we find after the invisible text. Remember what it
7934 was in IT->saved_face_id, and signal that it's there by
7935 setting face_before_selective_p. */
7936 it
->saved_face_id
= it
->face_id
;
7937 it
->method
= GET_FROM_BUFFER
;
7938 it
->object
= it
->w
->contents
;
7939 reseat_at_next_visible_line_start (it
, true);
7940 it
->face_before_selective_p
= true;
7943 return GET_NEXT_DISPLAY_ELEMENT (it
);
7947 /* Deliver an image display element. The iterator IT is already
7948 filled with image information (done in handle_display_prop). Value
7953 next_element_from_image (struct it
*it
)
7955 it
->what
= IT_IMAGE
;
7960 /* Fill iterator IT with next display element from a stretch glyph
7961 property. IT->object is the value of the text property. Value is
7965 next_element_from_stretch (struct it
*it
)
7967 it
->what
= IT_STRETCH
;
7971 /* Scan backwards from IT's current position until we find a stop
7972 position, or until BEGV. This is called when we find ourself
7973 before both the last known prev_stop and base_level_stop while
7974 reordering bidirectional text. */
7977 compute_stop_pos_backwards (struct it
*it
)
7979 const int SCAN_BACK_LIMIT
= 1000;
7980 struct text_pos pos
;
7981 struct display_pos save_current
= it
->current
;
7982 struct text_pos save_position
= it
->position
;
7983 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7984 ptrdiff_t where_we_are
= charpos
;
7985 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7986 ptrdiff_t save_end_pos
= it
->end_charpos
;
7988 eassert (NILP (it
->string
) && !it
->s
);
7989 eassert (it
->bidi_p
);
7993 it
->end_charpos
= min (charpos
+ 1, ZV
);
7994 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7995 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7996 reseat_1 (it
, pos
, false);
7997 compute_stop_pos (it
);
7998 /* We must advance forward, right? */
7999 if (it
->stop_charpos
<= charpos
)
8002 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
8004 if (it
->stop_charpos
<= where_we_are
)
8005 it
->prev_stop
= it
->stop_charpos
;
8007 it
->prev_stop
= BEGV
;
8009 it
->current
= save_current
;
8010 it
->position
= save_position
;
8011 it
->stop_charpos
= save_stop_pos
;
8012 it
->end_charpos
= save_end_pos
;
8015 /* Scan forward from CHARPOS in the current buffer/string, until we
8016 find a stop position > current IT's position. Then handle the stop
8017 position before that. This is called when we bump into a stop
8018 position while reordering bidirectional text. CHARPOS should be
8019 the last previously processed stop_pos (or BEGV/0, if none were
8020 processed yet) whose position is less that IT's current
8024 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8026 bool bufp
= !STRINGP (it
->string
);
8027 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8028 struct display_pos save_current
= it
->current
;
8029 struct text_pos save_position
= it
->position
;
8030 struct text_pos pos1
;
8031 ptrdiff_t next_stop
;
8033 /* Scan in strict logical order. */
8034 eassert (it
->bidi_p
);
8038 it
->prev_stop
= charpos
;
8041 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8042 reseat_1 (it
, pos1
, false);
8045 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8046 compute_stop_pos (it
);
8047 /* We must advance forward, right? */
8048 if (it
->stop_charpos
<= it
->prev_stop
)
8050 charpos
= it
->stop_charpos
;
8052 while (charpos
<= where_we_are
);
8055 it
->current
= save_current
;
8056 it
->position
= save_position
;
8057 next_stop
= it
->stop_charpos
;
8058 it
->stop_charpos
= it
->prev_stop
;
8060 it
->stop_charpos
= next_stop
;
8063 /* Load IT with the next display element from current_buffer. Value
8064 is false if end of buffer reached. IT->stop_charpos is the next
8065 position at which to stop and check for text properties or buffer
8069 next_element_from_buffer (struct it
*it
)
8071 bool success_p
= true;
8073 eassert (IT_CHARPOS (*it
) >= BEGV
);
8074 eassert (NILP (it
->string
) && !it
->s
);
8075 eassert (!it
->bidi_p
8076 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8077 && it
->bidi_it
.string
.s
== NULL
));
8079 /* With bidi reordering, the character to display might not be the
8080 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8081 we were reseat()ed to a new buffer position, which is potentially
8082 a different paragraph. */
8083 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8085 get_visually_first_element (it
);
8086 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8089 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8091 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8093 bool overlay_strings_follow_p
;
8095 /* End of the game, except when overlay strings follow that
8096 haven't been returned yet. */
8097 if (it
->overlay_strings_at_end_processed_p
)
8098 overlay_strings_follow_p
= false;
8101 it
->overlay_strings_at_end_processed_p
= true;
8102 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8105 if (overlay_strings_follow_p
)
8106 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8110 it
->position
= it
->current
.pos
;
8114 else if (!(!it
->bidi_p
8115 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8116 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8118 /* With bidi non-linear iteration, we could find ourselves
8119 far beyond the last computed stop_charpos, with several
8120 other stop positions in between that we missed. Scan
8121 them all now, in buffer's logical order, until we find
8122 and handle the last stop_charpos that precedes our
8123 current position. */
8124 handle_stop_backwards (it
, it
->stop_charpos
);
8125 it
->ignore_overlay_strings_at_pos_p
= false;
8126 return GET_NEXT_DISPLAY_ELEMENT (it
);
8132 /* Take note of the stop position we just moved across,
8133 for when we will move back across it. */
8134 it
->prev_stop
= it
->stop_charpos
;
8135 /* If we are at base paragraph embedding level, take
8136 note of the last stop position seen at this
8138 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8139 it
->base_level_stop
= it
->stop_charpos
;
8142 it
->ignore_overlay_strings_at_pos_p
= false;
8143 return GET_NEXT_DISPLAY_ELEMENT (it
);
8147 /* If we are before prev_stop, we may have overstepped on
8148 our way backwards a stop_pos, and if so, we need to
8149 handle that stop_pos. */
8150 && IT_CHARPOS (*it
) < it
->prev_stop
8151 /* We can sometimes back up for reasons that have nothing
8152 to do with bidi reordering. E.g., compositions. The
8153 code below is only needed when we are above the base
8154 embedding level, so test for that explicitly. */
8155 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8157 if (it
->base_level_stop
<= 0
8158 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8160 /* If we lost track of base_level_stop, we need to find
8161 prev_stop by looking backwards. This happens, e.g., when
8162 we were reseated to the previous screenful of text by
8164 it
->base_level_stop
= BEGV
;
8165 compute_stop_pos_backwards (it
);
8166 handle_stop_backwards (it
, it
->prev_stop
);
8169 handle_stop_backwards (it
, it
->base_level_stop
);
8170 it
->ignore_overlay_strings_at_pos_p
= false;
8171 return GET_NEXT_DISPLAY_ELEMENT (it
);
8175 /* No face changes, overlays etc. in sight, so just return a
8176 character from current_buffer. */
8180 /* We moved to the next buffer position, so any info about
8181 previously seen overlays is no longer valid. */
8182 it
->ignore_overlay_strings_at_pos_p
= false;
8184 /* Maybe run the redisplay end trigger hook. Performance note:
8185 This doesn't seem to cost measurable time. */
8186 if (it
->redisplay_end_trigger_charpos
8188 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8189 run_redisplay_end_trigger_hook (it
);
8191 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8192 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8194 && next_element_from_composition (it
))
8199 /* Get the next character, maybe multibyte. */
8200 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8201 if (it
->multibyte_p
&& !ASCII_CHAR_P (*p
))
8202 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8204 it
->c
= *p
, it
->len
= 1;
8206 /* Record what we have and where it came from. */
8207 it
->what
= IT_CHARACTER
;
8208 it
->object
= it
->w
->contents
;
8209 it
->position
= it
->current
.pos
;
8211 /* Normally we return the character found above, except when we
8212 really want to return an ellipsis for selective display. */
8217 /* A value of selective > 0 means hide lines indented more
8218 than that number of columns. */
8219 if (it
->selective
> 0
8220 && IT_CHARPOS (*it
) + 1 < ZV
8221 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8222 IT_BYTEPOS (*it
) + 1,
8225 success_p
= next_element_from_ellipsis (it
);
8226 it
->dpvec_char_len
= -1;
8229 else if (it
->c
== '\r' && it
->selective
== -1)
8231 /* A value of selective == -1 means that everything from the
8232 CR to the end of the line is invisible, with maybe an
8233 ellipsis displayed for it. */
8234 success_p
= next_element_from_ellipsis (it
);
8235 it
->dpvec_char_len
= -1;
8240 /* Value is false if end of buffer reached. */
8241 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8246 /* Run the redisplay end trigger hook for IT. */
8249 run_redisplay_end_trigger_hook (struct it
*it
)
8251 /* IT->glyph_row should be non-null, i.e. we should be actually
8252 displaying something, or otherwise we should not run the hook. */
8253 eassert (it
->glyph_row
);
8255 ptrdiff_t charpos
= it
->redisplay_end_trigger_charpos
;
8256 it
->redisplay_end_trigger_charpos
= 0;
8258 /* Since we are *trying* to run these functions, don't try to run
8259 them again, even if they get an error. */
8260 wset_redisplay_end_trigger (it
->w
, Qnil
);
8261 CALLN (Frun_hook_with_args
, Qredisplay_end_trigger_functions
, it
->window
,
8262 make_number (charpos
));
8264 /* Notice if it changed the face of the character we are on. */
8265 handle_face_prop (it
);
8269 /* Deliver a composition display element. Unlike the other
8270 next_element_from_XXX, this function is not registered in the array
8271 get_next_element[]. It is called from next_element_from_buffer and
8272 next_element_from_string when necessary. */
8275 next_element_from_composition (struct it
*it
)
8277 it
->what
= IT_COMPOSITION
;
8278 it
->len
= it
->cmp_it
.nbytes
;
8279 if (STRINGP (it
->string
))
8283 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8284 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8287 it
->position
= it
->current
.string_pos
;
8288 it
->object
= it
->string
;
8289 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8290 IT_STRING_BYTEPOS (*it
), it
->string
);
8296 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8297 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8300 if (it
->bidi_it
.new_paragraph
)
8301 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
8303 /* Resync the bidi iterator with IT's new position.
8304 FIXME: this doesn't support bidirectional text. */
8305 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8306 bidi_move_to_visually_next (&it
->bidi_it
);
8310 it
->position
= it
->current
.pos
;
8311 it
->object
= it
->w
->contents
;
8312 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8313 IT_BYTEPOS (*it
), Qnil
);
8320 /***********************************************************************
8321 Moving an iterator without producing glyphs
8322 ***********************************************************************/
8324 /* Check if iterator is at a position corresponding to a valid buffer
8325 position after some move_it_ call. */
8327 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8328 ((it)->method != GET_FROM_STRING || IT_STRING_CHARPOS (*it) == 0)
8331 /* Move iterator IT to a specified buffer or X position within one
8332 line on the display without producing glyphs.
8334 OP should be a bit mask including some or all of these bits:
8335 MOVE_TO_X: Stop upon reaching x-position TO_X.
8336 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8337 Regardless of OP's value, stop upon reaching the end of the display line.
8339 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8340 This means, in particular, that TO_X includes window's horizontal
8343 The return value has several possible values that
8344 say what condition caused the scan to stop:
8346 MOVE_POS_MATCH_OR_ZV
8347 - when TO_POS or ZV was reached.
8350 -when TO_X was reached before TO_POS or ZV were reached.
8353 - when we reached the end of the display area and the line must
8357 - when we reached the end of the display area and the line is
8361 - when we stopped at a line end, i.e. a newline or a CR and selective
8364 static enum move_it_result
8365 move_it_in_display_line_to (struct it
*it
,
8366 ptrdiff_t to_charpos
, int to_x
,
8367 enum move_operation_enum op
)
8369 enum move_it_result result
= MOVE_UNDEFINED
;
8370 struct glyph_row
*saved_glyph_row
;
8371 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8372 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8373 void *ppos_data
= NULL
;
8374 bool may_wrap
= false;
8375 enum it_method prev_method
= it
->method
;
8376 ptrdiff_t closest_pos
IF_LINT (= 0), prev_pos
= IT_CHARPOS (*it
);
8377 bool saw_smaller_pos
= prev_pos
< to_charpos
;
8379 /* Don't produce glyphs in produce_glyphs. */
8380 saved_glyph_row
= it
->glyph_row
;
8381 it
->glyph_row
= NULL
;
8383 /* Use wrap_it to save a copy of IT wherever a word wrap could
8384 occur. Use atpos_it to save a copy of IT at the desired buffer
8385 position, if found, so that we can scan ahead and check if the
8386 word later overshoots the window edge. Use atx_it similarly, for
8392 /* Use ppos_it under bidi reordering to save a copy of IT for the
8393 initial position. We restore that position in IT when we have
8394 scanned the entire display line without finding a match for
8395 TO_CHARPOS and all the character positions are greater than
8396 TO_CHARPOS. We then restart the scan from the initial position,
8397 and stop at CLOSEST_POS, which is a position > TO_CHARPOS that is
8398 the closest to TO_CHARPOS. */
8401 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8403 SAVE_IT (ppos_it
, *it
, ppos_data
);
8404 closest_pos
= IT_CHARPOS (*it
);
8410 #define BUFFER_POS_REACHED_P() \
8411 ((op & MOVE_TO_POS) != 0 \
8412 && BUFFERP (it->object) \
8413 && (IT_CHARPOS (*it) == to_charpos \
8415 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8416 && IT_CHARPOS (*it) > to_charpos) \
8417 || (it->what == IT_COMPOSITION \
8418 && ((IT_CHARPOS (*it) > to_charpos \
8419 && to_charpos >= it->cmp_it.charpos) \
8420 || (IT_CHARPOS (*it) < to_charpos \
8421 && to_charpos <= it->cmp_it.charpos)))) \
8422 && (it->method == GET_FROM_BUFFER \
8423 || (it->method == GET_FROM_DISPLAY_VECTOR \
8424 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8426 /* If there's a line-/wrap-prefix, handle it. */
8427 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8428 && it
->current_y
< it
->last_visible_y
)
8429 handle_line_prefix (it
);
8431 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8432 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8436 int x
, i
, ascent
= 0, descent
= 0;
8438 /* Utility macro to reset an iterator with x, ascent, and descent. */
8439 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8440 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8441 (IT)->max_descent = descent)
8443 /* Stop if we move beyond TO_CHARPOS (after an image or a
8444 display string or stretch glyph). */
8445 if ((op
& MOVE_TO_POS
) != 0
8446 && BUFFERP (it
->object
)
8447 && it
->method
== GET_FROM_BUFFER
8449 /* When the iterator is at base embedding level, we
8450 are guaranteed that characters are delivered for
8451 display in strictly increasing order of their
8452 buffer positions. */
8453 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8454 && IT_CHARPOS (*it
) > to_charpos
)
8456 && (prev_method
== GET_FROM_IMAGE
8457 || prev_method
== GET_FROM_STRETCH
8458 || prev_method
== GET_FROM_STRING
)
8459 /* Passed TO_CHARPOS from left to right. */
8460 && ((prev_pos
< to_charpos
8461 && IT_CHARPOS (*it
) > to_charpos
)
8462 /* Passed TO_CHARPOS from right to left. */
8463 || (prev_pos
> to_charpos
8464 && IT_CHARPOS (*it
) < to_charpos
)))))
8466 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8468 result
= MOVE_POS_MATCH_OR_ZV
;
8471 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8472 /* If wrap_it is valid, the current position might be in a
8473 word that is wrapped. So, save the iterator in
8474 atpos_it and continue to see if wrapping happens. */
8475 SAVE_IT (atpos_it
, *it
, atpos_data
);
8478 /* Stop when ZV reached.
8479 We used to stop here when TO_CHARPOS reached as well, but that is
8480 too soon if this glyph does not fit on this line. So we handle it
8481 explicitly below. */
8482 if (!get_next_display_element (it
))
8484 result
= MOVE_POS_MATCH_OR_ZV
;
8488 if (it
->line_wrap
== TRUNCATE
)
8490 if (BUFFER_POS_REACHED_P ())
8492 result
= MOVE_POS_MATCH_OR_ZV
;
8498 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
8500 if (IT_DISPLAYING_WHITESPACE (it
))
8504 /* We have reached a glyph that follows one or more
8505 whitespace characters. If the position is
8506 already found, we are done. */
8507 if (atpos_it
.sp
>= 0)
8509 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8510 result
= MOVE_POS_MATCH_OR_ZV
;
8515 RESTORE_IT (it
, &atx_it
, atx_data
);
8516 result
= MOVE_X_REACHED
;
8519 /* Otherwise, we can wrap here. */
8520 SAVE_IT (wrap_it
, *it
, wrap_data
);
8526 /* Remember the line height for the current line, in case
8527 the next element doesn't fit on the line. */
8528 ascent
= it
->max_ascent
;
8529 descent
= it
->max_descent
;
8531 /* The call to produce_glyphs will get the metrics of the
8532 display element IT is loaded with. Record the x-position
8533 before this display element, in case it doesn't fit on the
8537 PRODUCE_GLYPHS (it
);
8539 if (it
->area
!= TEXT_AREA
)
8541 prev_method
= it
->method
;
8542 if (it
->method
== GET_FROM_BUFFER
)
8543 prev_pos
= IT_CHARPOS (*it
);
8544 set_iterator_to_next (it
, true);
8545 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8546 SET_TEXT_POS (this_line_min_pos
,
8547 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8549 && (op
& MOVE_TO_POS
)
8550 && IT_CHARPOS (*it
) > to_charpos
8551 && IT_CHARPOS (*it
) < closest_pos
)
8552 closest_pos
= IT_CHARPOS (*it
);
8556 /* The number of glyphs we get back in IT->nglyphs will normally
8557 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8558 character on a terminal frame, or (iii) a line end. For the
8559 second case, IT->nglyphs - 1 padding glyphs will be present.
8560 (On X frames, there is only one glyph produced for a
8561 composite character.)
8563 The behavior implemented below means, for continuation lines,
8564 that as many spaces of a TAB as fit on the current line are
8565 displayed there. For terminal frames, as many glyphs of a
8566 multi-glyph character are displayed in the current line, too.
8567 This is what the old redisplay code did, and we keep it that
8568 way. Under X, the whole shape of a complex character must
8569 fit on the line or it will be completely displayed in the
8572 Note that both for tabs and padding glyphs, all glyphs have
8576 /* More than one glyph or glyph doesn't fit on line. All
8577 glyphs have the same width. */
8578 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8580 int x_before_this_char
= x
;
8581 int hpos_before_this_char
= it
->hpos
;
8583 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8585 new_x
= x
+ single_glyph_width
;
8587 /* We want to leave anything reaching TO_X to the caller. */
8588 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8590 if (BUFFER_POS_REACHED_P ())
8592 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8593 goto buffer_pos_reached
;
8594 if (atpos_it
.sp
< 0)
8596 SAVE_IT (atpos_it
, *it
, atpos_data
);
8597 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8602 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8605 result
= MOVE_X_REACHED
;
8610 SAVE_IT (atx_it
, *it
, atx_data
);
8611 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8616 if (/* Lines are continued. */
8617 it
->line_wrap
!= TRUNCATE
8618 && (/* And glyph doesn't fit on the line. */
8619 new_x
> it
->last_visible_x
8620 /* Or it fits exactly and we're on a window
8622 || (new_x
== it
->last_visible_x
8623 && FRAME_WINDOW_P (it
->f
)
8624 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8625 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8626 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8628 if (/* IT->hpos == 0 means the very first glyph
8629 doesn't fit on the line, e.g. a wide image. */
8631 || (new_x
== it
->last_visible_x
8632 && FRAME_WINDOW_P (it
->f
)))
8635 it
->current_x
= new_x
;
8637 /* The character's last glyph just barely fits
8639 if (i
== it
->nglyphs
- 1)
8641 /* If this is the destination position,
8642 return a position *before* it in this row,
8643 now that we know it fits in this row. */
8644 if (BUFFER_POS_REACHED_P ())
8646 if (it
->line_wrap
!= WORD_WRAP
8648 /* If we've just found whitespace to
8649 wrap, effectively ignore the
8650 previous wrap point -- it is no
8651 longer relevant, but we won't
8652 have an opportunity to update it,
8653 since we've reached the edge of
8654 this screen line. */
8656 && IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8658 it
->hpos
= hpos_before_this_char
;
8659 it
->current_x
= x_before_this_char
;
8660 result
= MOVE_POS_MATCH_OR_ZV
;
8663 if (it
->line_wrap
== WORD_WRAP
8666 SAVE_IT (atpos_it
, *it
, atpos_data
);
8667 atpos_it
.current_x
= x_before_this_char
;
8668 atpos_it
.hpos
= hpos_before_this_char
;
8672 prev_method
= it
->method
;
8673 if (it
->method
== GET_FROM_BUFFER
)
8674 prev_pos
= IT_CHARPOS (*it
);
8675 set_iterator_to_next (it
, true);
8676 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8677 SET_TEXT_POS (this_line_min_pos
,
8678 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8679 /* On graphical terminals, newlines may
8680 "overflow" into the fringe if
8681 overflow-newline-into-fringe is non-nil.
8682 On text terminals, and on graphical
8683 terminals with no right margin, newlines
8684 may overflow into the last glyph on the
8686 if (!FRAME_WINDOW_P (it
->f
)
8688 && it
->bidi_it
.paragraph_dir
== R2L
)
8689 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8690 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8691 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8693 if (!get_next_display_element (it
))
8695 result
= MOVE_POS_MATCH_OR_ZV
;
8698 if (BUFFER_POS_REACHED_P ())
8700 if (ITERATOR_AT_END_OF_LINE_P (it
))
8701 result
= MOVE_POS_MATCH_OR_ZV
;
8703 result
= MOVE_LINE_CONTINUED
;
8706 if (ITERATOR_AT_END_OF_LINE_P (it
)
8707 && (it
->line_wrap
!= WORD_WRAP
8709 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8711 result
= MOVE_NEWLINE_OR_CR
;
8718 IT_RESET_X_ASCENT_DESCENT (it
);
8720 /* If the screen line ends with whitespace, and we
8721 are under word-wrap, don't use wrap_it: it is no
8722 longer relevant, but we won't have an opportunity
8723 to update it, since we are done with this screen
8725 if (may_wrap
&& IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8727 /* If we've found TO_X, go back there, as we now
8728 know the last word fits on this screen line. */
8729 if ((op
& MOVE_TO_X
) && new_x
== it
->last_visible_x
8732 RESTORE_IT (it
, &atx_it
, atx_data
);
8735 result
= MOVE_X_REACHED
;
8739 else if (wrap_it
.sp
>= 0)
8741 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8746 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8748 result
= MOVE_LINE_CONTINUED
;
8752 if (BUFFER_POS_REACHED_P ())
8754 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8755 goto buffer_pos_reached
;
8756 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8758 SAVE_IT (atpos_it
, *it
, atpos_data
);
8759 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8763 if (new_x
> it
->first_visible_x
)
8765 /* Glyph is visible. Increment number of glyphs that
8766 would be displayed. */
8771 if (result
!= MOVE_UNDEFINED
)
8774 else if (BUFFER_POS_REACHED_P ())
8777 IT_RESET_X_ASCENT_DESCENT (it
);
8778 result
= MOVE_POS_MATCH_OR_ZV
;
8781 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8783 /* Stop when TO_X specified and reached. This check is
8784 necessary here because of lines consisting of a line end,
8785 only. The line end will not produce any glyphs and we
8786 would never get MOVE_X_REACHED. */
8787 eassert (it
->nglyphs
== 0);
8788 result
= MOVE_X_REACHED
;
8792 /* Is this a line end? If yes, we're done. */
8793 if (ITERATOR_AT_END_OF_LINE_P (it
))
8795 /* If we are past TO_CHARPOS, but never saw any character
8796 positions smaller than TO_CHARPOS, return
8797 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8799 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8801 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8803 if (closest_pos
< ZV
)
8805 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8806 /* Don't recurse if closest_pos is equal to
8807 to_charpos, since we have just tried that. */
8808 if (closest_pos
!= to_charpos
)
8809 move_it_in_display_line_to (it
, closest_pos
, -1,
8811 result
= MOVE_POS_MATCH_OR_ZV
;
8814 goto buffer_pos_reached
;
8816 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8817 && IT_CHARPOS (*it
) > to_charpos
)
8818 goto buffer_pos_reached
;
8820 result
= MOVE_NEWLINE_OR_CR
;
8823 result
= MOVE_NEWLINE_OR_CR
;
8827 prev_method
= it
->method
;
8828 if (it
->method
== GET_FROM_BUFFER
)
8829 prev_pos
= IT_CHARPOS (*it
);
8830 /* The current display element has been consumed. Advance
8832 set_iterator_to_next (it
, true);
8833 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8834 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8835 if (IT_CHARPOS (*it
) < to_charpos
)
8836 saw_smaller_pos
= true;
8838 && (op
& MOVE_TO_POS
)
8839 && IT_CHARPOS (*it
) >= to_charpos
8840 && IT_CHARPOS (*it
) < closest_pos
)
8841 closest_pos
= IT_CHARPOS (*it
);
8843 /* Stop if lines are truncated and IT's current x-position is
8844 past the right edge of the window now. */
8845 if (it
->line_wrap
== TRUNCATE
8846 && it
->current_x
>= it
->last_visible_x
)
8848 if (!FRAME_WINDOW_P (it
->f
)
8849 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8850 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8851 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8852 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8854 bool at_eob_p
= false;
8856 if ((at_eob_p
= !get_next_display_element (it
))
8857 || BUFFER_POS_REACHED_P ()
8858 /* If we are past TO_CHARPOS, but never saw any
8859 character positions smaller than TO_CHARPOS,
8860 return MOVE_POS_MATCH_OR_ZV, like the
8861 unidirectional display did. */
8862 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8864 && IT_CHARPOS (*it
) > to_charpos
))
8867 && !BUFFER_POS_REACHED_P ()
8868 && !at_eob_p
&& closest_pos
< ZV
)
8870 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8871 if (closest_pos
!= to_charpos
)
8872 move_it_in_display_line_to (it
, closest_pos
, -1,
8875 result
= MOVE_POS_MATCH_OR_ZV
;
8878 if (ITERATOR_AT_END_OF_LINE_P (it
))
8880 result
= MOVE_NEWLINE_OR_CR
;
8884 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8886 && IT_CHARPOS (*it
) > to_charpos
)
8888 if (closest_pos
< ZV
)
8890 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8891 if (closest_pos
!= to_charpos
)
8892 move_it_in_display_line_to (it
, closest_pos
, -1,
8895 result
= MOVE_POS_MATCH_OR_ZV
;
8898 result
= MOVE_LINE_TRUNCATED
;
8901 #undef IT_RESET_X_ASCENT_DESCENT
8904 #undef BUFFER_POS_REACHED_P
8906 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8907 restore the saved iterator. */
8908 if (atpos_it
.sp
>= 0)
8909 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8910 else if (atx_it
.sp
>= 0)
8911 RESTORE_IT (it
, &atx_it
, atx_data
);
8916 bidi_unshelve_cache (atpos_data
, true);
8918 bidi_unshelve_cache (atx_data
, true);
8920 bidi_unshelve_cache (wrap_data
, true);
8922 bidi_unshelve_cache (ppos_data
, true);
8924 /* Restore the iterator settings altered at the beginning of this
8926 it
->glyph_row
= saved_glyph_row
;
8930 /* For external use. */
8932 move_it_in_display_line (struct it
*it
,
8933 ptrdiff_t to_charpos
, int to_x
,
8934 enum move_operation_enum op
)
8936 if (it
->line_wrap
== WORD_WRAP
8937 && (op
& MOVE_TO_X
))
8940 void *save_data
= NULL
;
8943 SAVE_IT (save_it
, *it
, save_data
);
8944 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8945 /* When word-wrap is on, TO_X may lie past the end
8946 of a wrapped line. Then it->current is the
8947 character on the next line, so backtrack to the
8948 space before the wrap point. */
8949 if (skip
== MOVE_LINE_CONTINUED
)
8951 int prev_x
= max (it
->current_x
- 1, 0);
8952 RESTORE_IT (it
, &save_it
, save_data
);
8953 move_it_in_display_line_to
8954 (it
, -1, prev_x
, MOVE_TO_X
);
8957 bidi_unshelve_cache (save_data
, true);
8960 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8964 /* Move IT forward until it satisfies one or more of the criteria in
8965 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8967 OP is a bit-mask that specifies where to stop, and in particular,
8968 which of those four position arguments makes a difference. See the
8969 description of enum move_operation_enum.
8971 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8972 screen line, this function will set IT to the next position that is
8973 displayed to the right of TO_CHARPOS on the screen.
8975 Return the maximum pixel length of any line scanned but never more
8976 than it.last_visible_x. */
8979 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8981 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8982 int line_height
, line_start_x
= 0, reached
= 0;
8983 int max_current_x
= 0;
8984 void *backup_data
= NULL
;
8988 if (op
& MOVE_TO_VPOS
)
8990 /* If no TO_CHARPOS and no TO_X specified, stop at the
8991 start of the line TO_VPOS. */
8992 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8994 if (it
->vpos
== to_vpos
)
9000 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
9004 /* TO_VPOS >= 0 means stop at TO_X in the line at
9005 TO_VPOS, or at TO_POS, whichever comes first. */
9006 if (it
->vpos
== to_vpos
)
9012 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9014 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
9019 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
9021 /* We have reached TO_X but not in the line we want. */
9022 skip
= move_it_in_display_line_to (it
, to_charpos
,
9024 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9032 else if (op
& MOVE_TO_Y
)
9034 struct it it_backup
;
9036 if (it
->line_wrap
== WORD_WRAP
)
9037 SAVE_IT (it_backup
, *it
, backup_data
);
9039 /* TO_Y specified means stop at TO_X in the line containing
9040 TO_Y---or at TO_CHARPOS if this is reached first. The
9041 problem is that we can't really tell whether the line
9042 contains TO_Y before we have completely scanned it, and
9043 this may skip past TO_X. What we do is to first scan to
9046 If TO_X is not specified, use a TO_X of zero. The reason
9047 is to make the outcome of this function more predictable.
9048 If we didn't use TO_X == 0, we would stop at the end of
9049 the line which is probably not what a caller would expect
9051 skip
= move_it_in_display_line_to
9052 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
9053 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
9055 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
9056 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9058 else if (skip
== MOVE_X_REACHED
)
9060 /* If TO_X was reached, we want to know whether TO_Y is
9061 in the line. We know this is the case if the already
9062 scanned glyphs make the line tall enough. Otherwise,
9063 we must check by scanning the rest of the line. */
9064 line_height
= it
->max_ascent
+ it
->max_descent
;
9065 if (to_y
>= it
->current_y
9066 && to_y
< it
->current_y
+ line_height
)
9071 SAVE_IT (it_backup
, *it
, backup_data
);
9072 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9073 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9075 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9076 line_height
= it
->max_ascent
+ it
->max_descent
;
9077 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9079 if (to_y
>= it
->current_y
9080 && to_y
< it
->current_y
+ line_height
)
9082 /* If TO_Y is in this line and TO_X was reached
9083 above, we scanned too far. We have to restore
9084 IT's settings to the ones before skipping. But
9085 keep the more accurate values of max_ascent and
9086 max_descent we've found while skipping the rest
9087 of the line, for the sake of callers, such as
9088 pos_visible_p, that need to know the line
9090 int max_ascent
= it
->max_ascent
;
9091 int max_descent
= it
->max_descent
;
9093 RESTORE_IT (it
, &it_backup
, backup_data
);
9094 it
->max_ascent
= max_ascent
;
9095 it
->max_descent
= max_descent
;
9101 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9107 /* Check whether TO_Y is in this line. */
9108 line_height
= it
->max_ascent
+ it
->max_descent
;
9109 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9111 if (to_y
>= it
->current_y
9112 && to_y
< it
->current_y
+ line_height
)
9114 if (to_y
> it
->current_y
)
9115 max_current_x
= max (it
->current_x
, max_current_x
);
9117 /* When word-wrap is on, TO_X may lie past the end
9118 of a wrapped line. Then it->current is the
9119 character on the next line, so backtrack to the
9120 space before the wrap point. */
9121 if (skip
== MOVE_LINE_CONTINUED
9122 && it
->line_wrap
== WORD_WRAP
)
9124 int prev_x
= max (it
->current_x
- 1, 0);
9125 RESTORE_IT (it
, &it_backup
, backup_data
);
9126 skip
= move_it_in_display_line_to
9127 (it
, -1, prev_x
, MOVE_TO_X
);
9136 max_current_x
= max (it
->current_x
, max_current_x
);
9140 else if (BUFFERP (it
->object
)
9141 && (it
->method
== GET_FROM_BUFFER
9142 || it
->method
== GET_FROM_STRETCH
)
9143 && IT_CHARPOS (*it
) >= to_charpos
9144 /* Under bidi iteration, a call to set_iterator_to_next
9145 can scan far beyond to_charpos if the initial
9146 portion of the next line needs to be reordered. In
9147 that case, give move_it_in_display_line_to another
9150 && it
->bidi_it
.scan_dir
== -1))
9151 skip
= MOVE_POS_MATCH_OR_ZV
;
9153 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9157 case MOVE_POS_MATCH_OR_ZV
:
9158 max_current_x
= max (it
->current_x
, max_current_x
);
9162 case MOVE_NEWLINE_OR_CR
:
9163 max_current_x
= max (it
->current_x
, max_current_x
);
9164 set_iterator_to_next (it
, true);
9165 it
->continuation_lines_width
= 0;
9168 case MOVE_LINE_TRUNCATED
:
9169 max_current_x
= it
->last_visible_x
;
9170 it
->continuation_lines_width
= 0;
9171 reseat_at_next_visible_line_start (it
, false);
9172 if ((op
& MOVE_TO_POS
) != 0
9173 && IT_CHARPOS (*it
) > to_charpos
)
9180 case MOVE_LINE_CONTINUED
:
9181 max_current_x
= it
->last_visible_x
;
9182 /* For continued lines ending in a tab, some of the glyphs
9183 associated with the tab are displayed on the current
9184 line. Since it->current_x does not include these glyphs,
9185 we use it->last_visible_x instead. */
9188 it
->continuation_lines_width
+= it
->last_visible_x
;
9189 /* When moving by vpos, ensure that the iterator really
9190 advances to the next line (bug#847, bug#969). Fixme:
9191 do we need to do this in other circumstances? */
9192 if (it
->current_x
!= it
->last_visible_x
9193 && (op
& MOVE_TO_VPOS
)
9194 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9196 line_start_x
= it
->current_x
+ it
->pixel_width
9197 - it
->last_visible_x
;
9198 if (FRAME_WINDOW_P (it
->f
))
9200 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
9201 struct font
*face_font
= face
->font
;
9203 /* When display_line produces a continued line
9204 that ends in a TAB, it skips a tab stop that
9205 is closer than the font's space character
9206 width (see x_produce_glyphs where it produces
9207 the stretch glyph which represents a TAB).
9208 We need to reproduce the same logic here. */
9209 eassert (face_font
);
9212 if (line_start_x
< face_font
->space_width
)
9214 += it
->tab_width
* face_font
->space_width
;
9217 set_iterator_to_next (it
, false);
9221 it
->continuation_lines_width
+= it
->current_x
;
9228 /* Reset/increment for the next run. */
9229 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9230 it
->current_x
= line_start_x
;
9233 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9235 last_height
= it
->max_ascent
+ it
->max_descent
;
9236 it
->max_ascent
= it
->max_descent
= 0;
9241 /* On text terminals, we may stop at the end of a line in the middle
9242 of a multi-character glyph. If the glyph itself is continued,
9243 i.e. it is actually displayed on the next line, don't treat this
9244 stopping point as valid; move to the next line instead (unless
9245 that brings us offscreen). */
9246 if (!FRAME_WINDOW_P (it
->f
)
9248 && IT_CHARPOS (*it
) == to_charpos
9249 && it
->what
== IT_CHARACTER
9251 && it
->line_wrap
== WINDOW_WRAP
9252 && it
->current_x
== it
->last_visible_x
- 1
9255 && it
->w
->window_end_valid
9256 && it
->vpos
< it
->w
->window_end_vpos
)
9258 it
->continuation_lines_width
+= it
->current_x
;
9259 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9260 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9262 last_height
= it
->max_ascent
+ it
->max_descent
;
9266 bidi_unshelve_cache (backup_data
, true);
9268 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9270 return max_current_x
;
9274 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9276 If DY > 0, move IT backward at least that many pixels. DY = 0
9277 means move IT backward to the preceding line start or BEGV. This
9278 function may move over more than DY pixels if IT->current_y - DY
9279 ends up in the middle of a line; in this case IT->current_y will be
9280 set to the top of the line moved to. */
9283 move_it_vertically_backward (struct it
*it
, int dy
)
9287 void *it2data
= NULL
, *it3data
= NULL
;
9288 ptrdiff_t start_pos
;
9290 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9291 ptrdiff_t pos_limit
;
9296 start_pos
= IT_CHARPOS (*it
);
9298 /* Estimate how many newlines we must move back. */
9299 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9300 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9303 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9305 /* Set the iterator's position that many lines back. But don't go
9306 back more than NLINES full screen lines -- this wins a day with
9307 buffers which have very long lines. */
9308 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9309 back_to_previous_visible_line_start (it
);
9311 /* Reseat the iterator here. When moving backward, we don't want
9312 reseat to skip forward over invisible text, set up the iterator
9313 to deliver from overlay strings at the new position etc. So,
9314 use reseat_1 here. */
9315 reseat_1 (it
, it
->current
.pos
, true);
9317 /* We are now surely at a line start. */
9318 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9319 reordering is in effect. */
9320 it
->continuation_lines_width
= 0;
9322 /* Move forward and see what y-distance we moved. First move to the
9323 start of the next line so that we get its height. We need this
9324 height to be able to tell whether we reached the specified
9326 SAVE_IT (it2
, *it
, it2data
);
9327 it2
.max_ascent
= it2
.max_descent
= 0;
9330 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9331 MOVE_TO_POS
| MOVE_TO_VPOS
);
9333 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9334 /* If we are in a display string which starts at START_POS,
9335 and that display string includes a newline, and we are
9336 right after that newline (i.e. at the beginning of a
9337 display line), exit the loop, because otherwise we will
9338 infloop, since move_it_to will see that it is already at
9339 START_POS and will not move. */
9340 || (it2
.method
== GET_FROM_STRING
9341 && IT_CHARPOS (it2
) == start_pos
9342 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9343 eassert (IT_CHARPOS (*it
) >= BEGV
);
9344 SAVE_IT (it3
, it2
, it3data
);
9346 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9347 eassert (IT_CHARPOS (*it
) >= BEGV
);
9348 /* H is the actual vertical distance from the position in *IT
9349 and the starting position. */
9350 h
= it2
.current_y
- it
->current_y
;
9351 /* NLINES is the distance in number of lines. */
9352 nlines
= it2
.vpos
- it
->vpos
;
9354 /* Correct IT's y and vpos position
9355 so that they are relative to the starting point. */
9361 /* DY == 0 means move to the start of the screen line. The
9362 value of nlines is > 0 if continuation lines were involved,
9363 or if the original IT position was at start of a line. */
9364 RESTORE_IT (it
, it
, it2data
);
9366 move_it_by_lines (it
, nlines
);
9367 /* The above code moves us to some position NLINES down,
9368 usually to its first glyph (leftmost in an L2R line), but
9369 that's not necessarily the start of the line, under bidi
9370 reordering. We want to get to the character position
9371 that is immediately after the newline of the previous
9374 && !it
->continuation_lines_width
9375 && !STRINGP (it
->string
)
9376 && IT_CHARPOS (*it
) > BEGV
9377 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9379 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9382 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9383 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9385 bidi_unshelve_cache (it3data
, true);
9389 /* The y-position we try to reach, relative to *IT.
9390 Note that H has been subtracted in front of the if-statement. */
9391 int target_y
= it
->current_y
+ h
- dy
;
9392 int y0
= it3
.current_y
;
9396 RESTORE_IT (&it3
, &it3
, it3data
);
9397 y1
= line_bottom_y (&it3
);
9398 line_height
= y1
- y0
;
9399 RESTORE_IT (it
, it
, it2data
);
9400 /* If we did not reach target_y, try to move further backward if
9401 we can. If we moved too far backward, try to move forward. */
9402 if (target_y
< it
->current_y
9403 /* This is heuristic. In a window that's 3 lines high, with
9404 a line height of 13 pixels each, recentering with point
9405 on the bottom line will try to move -39/2 = 19 pixels
9406 backward. Try to avoid moving into the first line. */
9407 && (it
->current_y
- target_y
9408 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9409 && IT_CHARPOS (*it
) > BEGV
)
9411 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9412 target_y
- it
->current_y
));
9413 dy
= it
->current_y
- target_y
;
9414 goto move_further_back
;
9416 else if (target_y
>= it
->current_y
+ line_height
9417 && IT_CHARPOS (*it
) < ZV
)
9419 /* Should move forward by at least one line, maybe more.
9421 Note: Calling move_it_by_lines can be expensive on
9422 terminal frames, where compute_motion is used (via
9423 vmotion) to do the job, when there are very long lines
9424 and truncate-lines is nil. That's the reason for
9425 treating terminal frames specially here. */
9427 if (!FRAME_WINDOW_P (it
->f
))
9428 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9433 move_it_by_lines (it
, 1);
9435 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9442 /* Move IT by a specified amount of pixel lines DY. DY negative means
9443 move backwards. DY = 0 means move to start of screen line. At the
9444 end, IT will be on the start of a screen line. */
9447 move_it_vertically (struct it
*it
, int dy
)
9450 move_it_vertically_backward (it
, -dy
);
9453 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9454 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9455 MOVE_TO_POS
| MOVE_TO_Y
);
9456 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9458 /* If buffer ends in ZV without a newline, move to the start of
9459 the line to satisfy the post-condition. */
9460 if (IT_CHARPOS (*it
) == ZV
9462 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9463 move_it_by_lines (it
, 0);
9468 /* Move iterator IT past the end of the text line it is in. */
9471 move_it_past_eol (struct it
*it
)
9473 enum move_it_result rc
;
9475 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9476 if (rc
== MOVE_NEWLINE_OR_CR
)
9477 set_iterator_to_next (it
, false);
9481 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9482 negative means move up. DVPOS == 0 means move to the start of the
9485 Optimization idea: If we would know that IT->f doesn't use
9486 a face with proportional font, we could be faster for
9487 truncate-lines nil. */
9490 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9493 /* The commented-out optimization uses vmotion on terminals. This
9494 gives bad results, because elements like it->what, on which
9495 callers such as pos_visible_p rely, aren't updated. */
9496 /* struct position pos;
9497 if (!FRAME_WINDOW_P (it->f))
9499 struct text_pos textpos;
9501 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9502 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9503 reseat (it, textpos, true);
9504 it->vpos += pos.vpos;
9505 it->current_y += pos.vpos;
9511 /* DVPOS == 0 means move to the start of the screen line. */
9512 move_it_vertically_backward (it
, 0);
9513 /* Let next call to line_bottom_y calculate real line height. */
9518 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9519 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9521 /* Only move to the next buffer position if we ended up in a
9522 string from display property, not in an overlay string
9523 (before-string or after-string). That is because the
9524 latter don't conceal the underlying buffer position, so
9525 we can ask to move the iterator to the exact position we
9526 are interested in. Note that, even if we are already at
9527 IT_CHARPOS (*it), the call below is not a no-op, as it
9528 will detect that we are at the end of the string, pop the
9529 iterator, and compute it->current_x and it->hpos
9531 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9532 -1, -1, -1, MOVE_TO_POS
);
9538 void *it2data
= NULL
;
9539 ptrdiff_t start_charpos
, i
;
9541 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9542 bool hit_pos_limit
= false;
9543 ptrdiff_t pos_limit
;
9545 /* Start at the beginning of the screen line containing IT's
9546 position. This may actually move vertically backwards,
9547 in case of overlays, so adjust dvpos accordingly. */
9549 move_it_vertically_backward (it
, 0);
9552 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9553 screen lines, and reseat the iterator there. */
9554 start_charpos
= IT_CHARPOS (*it
);
9555 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9558 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9560 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9561 back_to_previous_visible_line_start (it
);
9562 if (i
> 0 && IT_CHARPOS (*it
) <= pos_limit
)
9563 hit_pos_limit
= true;
9564 reseat (it
, it
->current
.pos
, true);
9566 /* Move further back if we end up in a string or an image. */
9567 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9569 /* First try to move to start of display line. */
9571 move_it_vertically_backward (it
, 0);
9573 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9575 /* If start of line is still in string or image,
9576 move further back. */
9577 back_to_previous_visible_line_start (it
);
9578 reseat (it
, it
->current
.pos
, true);
9582 it
->current_x
= it
->hpos
= 0;
9584 /* Above call may have moved too far if continuation lines
9585 are involved. Scan forward and see if it did. */
9586 SAVE_IT (it2
, *it
, it2data
);
9587 it2
.vpos
= it2
.current_y
= 0;
9588 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9589 it
->vpos
-= it2
.vpos
;
9590 it
->current_y
-= it2
.current_y
;
9591 it
->current_x
= it
->hpos
= 0;
9593 /* If we moved too far back, move IT some lines forward. */
9594 if (it2
.vpos
> -dvpos
)
9596 int delta
= it2
.vpos
+ dvpos
;
9598 RESTORE_IT (&it2
, &it2
, it2data
);
9599 SAVE_IT (it2
, *it
, it2data
);
9600 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9601 /* Move back again if we got too far ahead. */
9602 if (IT_CHARPOS (*it
) >= start_charpos
)
9603 RESTORE_IT (it
, &it2
, it2data
);
9605 bidi_unshelve_cache (it2data
, true);
9607 else if (hit_pos_limit
&& pos_limit
> BEGV
9608 && dvpos
< 0 && it2
.vpos
< -dvpos
)
9610 /* If we hit the limit, but still didn't make it far enough
9611 back, that means there's a display string with a newline
9612 covering a large chunk of text, and that caused
9613 back_to_previous_visible_line_start try to go too far.
9614 Punish those who commit such atrocities by going back
9615 until we've reached DVPOS, after lifting the limit, which
9616 could make it slow for very long lines. "If it hurts,
9619 RESTORE_IT (it
, it
, it2data
);
9620 for (i
= -dvpos
; i
> 0; --i
)
9622 back_to_previous_visible_line_start (it
);
9625 reseat_1 (it
, it
->current
.pos
, true);
9628 RESTORE_IT (it
, it
, it2data
);
9632 /* Return true if IT points into the middle of a display vector. */
9635 in_display_vector_p (struct it
*it
)
9637 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9638 && it
->current
.dpvec_index
> 0
9639 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9642 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9643 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9644 WINDOW must be a live window and defaults to the selected one. The
9645 return value is a cons of the maximum pixel-width of any text line and
9646 the maximum pixel-height of all text lines.
9648 The optional argument FROM, if non-nil, specifies the first text
9649 position and defaults to the minimum accessible position of the buffer.
9650 If FROM is t, use the minimum accessible position that is not a newline
9651 character. TO, if non-nil, specifies the last text position and
9652 defaults to the maximum accessible position of the buffer. If TO is t,
9653 use the maximum accessible position that is not a newline character.
9655 The optional argument X-LIMIT, if non-nil, specifies the maximum text
9656 width that can be returned. X-LIMIT nil or omitted, means to use the
9657 pixel-width of WINDOW's body; use this if you do not intend to change
9658 the width of WINDOW. Use the maximum width WINDOW may assume if you
9659 intend to change WINDOW's width. In any case, text whose x-coordinate
9660 is beyond X-LIMIT is ignored. Since calculating the width of long lines
9661 can take some time, it's always a good idea to make this argument as
9662 small as possible; in particular, if the buffer contains long lines that
9663 shall be truncated anyway.
9665 The optional argument Y-LIMIT, if non-nil, specifies the maximum text
9666 height that can be returned. Text lines whose y-coordinate is beyond
9667 Y-LIMIT are ignored. Since calculating the text height of a large
9668 buffer can take some time, it makes sense to specify this argument if
9669 the size of the buffer is unknown.
9671 Optional argument MODE-AND-HEADER-LINE nil or omitted means do not
9672 include the height of the mode- or header-line of WINDOW in the return
9673 value. If it is either the symbol `mode-line' or `header-line', include
9674 only the height of that line, if present, in the return value. If t,
9675 include the height of both, if present, in the return value. */)
9676 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
,
9677 Lisp_Object y_limit
, Lisp_Object mode_and_header_line
)
9679 struct window
*w
= decode_live_window (window
);
9680 Lisp_Object buffer
= w
->contents
;
9683 struct buffer
*old_b
= NULL
;
9684 ptrdiff_t start
, end
, pos
;
9685 struct text_pos startp
;
9686 void *itdata
= NULL
;
9687 int c
, max_y
= -1, x
= 0, y
= 0;
9689 CHECK_BUFFER (buffer
);
9690 b
= XBUFFER (buffer
);
9692 if (b
!= current_buffer
)
9694 old_b
= current_buffer
;
9695 set_buffer_internal (b
);
9700 else if (EQ (from
, Qt
))
9703 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9704 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9706 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9711 CHECK_NUMBER_COERCE_MARKER (from
);
9712 start
= min (max (XINT (from
), BEGV
), ZV
);
9717 else if (EQ (to
, Qt
))
9720 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9721 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9723 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9728 CHECK_NUMBER_COERCE_MARKER (to
);
9729 end
= max (start
, min (XINT (to
), ZV
));
9732 if (!NILP (y_limit
))
9734 CHECK_NUMBER (y_limit
);
9735 max_y
= min (XINT (y_limit
), INT_MAX
);
9738 itdata
= bidi_shelve_cache ();
9739 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9740 start_display (&it
, w
, startp
);
9743 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9746 CHECK_NUMBER (x_limit
);
9747 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9748 /* Actually, we never want move_it_to stop at to_x. But to make
9749 sure that move_it_in_display_line_to always moves far enough,
9750 we set it to INT_MAX and specify MOVE_TO_X. */
9751 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9752 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9755 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9757 if (!EQ (mode_and_header_line
, Qheader_line
)
9758 && !EQ (mode_and_header_line
, Qt
))
9759 /* Do not count the header-line which was counted automatically by
9761 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9763 if (EQ (mode_and_header_line
, Qmode_line
)
9764 || EQ (mode_and_header_line
, Qt
))
9765 /* Do count the mode-line which is not included automatically by
9767 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9769 bidi_unshelve_cache (itdata
, false);
9772 set_buffer_internal (old_b
);
9774 return Fcons (make_number (x
), make_number (y
));
9777 /***********************************************************************
9779 ***********************************************************************/
9782 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9786 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9788 Lisp_Object msg
, fmt
;
9791 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9795 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9797 fmt
= build_string (format
);
9798 msg
= CALLN (Fformat
, fmt
, arg1
, arg2
);
9800 len
= SBYTES (msg
) + 1;
9801 buffer
= SAFE_ALLOCA (len
);
9802 memcpy (buffer
, SDATA (msg
), len
);
9804 message_dolog (buffer
, len
- 1, true, false);
9811 /* Output a newline in the *Messages* buffer if "needs" one. */
9814 message_log_maybe_newline (void)
9816 if (message_log_need_newline
)
9817 message_dolog ("", 0, true, false);
9821 /* Add a string M of length NBYTES to the message log, optionally
9822 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9823 true, means interpret the contents of M as multibyte. This
9824 function calls low-level routines in order to bypass text property
9825 hooks, etc. which might not be safe to run.
9827 This may GC (insert may run before/after change hooks),
9828 so the buffer M must NOT point to a Lisp string. */
9831 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9833 const unsigned char *msg
= (const unsigned char *) m
;
9835 if (!NILP (Vmemory_full
))
9838 if (!NILP (Vmessage_log_max
))
9840 struct buffer
*oldbuf
;
9841 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9842 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9843 ptrdiff_t point_at_end
= 0;
9844 ptrdiff_t zv_at_end
= 0;
9845 Lisp_Object old_deactivate_mark
;
9846 struct gcpro gcpro1
;
9848 old_deactivate_mark
= Vdeactivate_mark
;
9849 oldbuf
= current_buffer
;
9851 /* Ensure the Messages buffer exists, and switch to it.
9852 If we created it, set the major-mode. */
9853 bool newbuffer
= NILP (Fget_buffer (Vmessages_buffer_name
));
9854 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9856 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9857 call0 (intern ("messages-buffer-mode"));
9859 bset_undo_list (current_buffer
, Qt
);
9860 bset_cache_long_scans (current_buffer
, Qnil
);
9862 oldpoint
= message_dolog_marker1
;
9863 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9864 oldbegv
= message_dolog_marker2
;
9865 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9866 oldzv
= message_dolog_marker3
;
9867 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9868 GCPRO1 (old_deactivate_mark
);
9876 BEGV_BYTE
= BEG_BYTE
;
9879 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9881 /* Insert the string--maybe converting multibyte to single byte
9882 or vice versa, so that all the text fits the buffer. */
9884 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9890 /* Convert a multibyte string to single-byte
9891 for the *Message* buffer. */
9892 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9894 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9895 work
[0] = CHAR_TO_BYTE8 (c
);
9896 insert_1_both (work
, 1, 1, true, false, false);
9899 else if (! multibyte
9900 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9904 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9905 /* Convert a single-byte string to multibyte
9906 for the *Message* buffer. */
9907 for (i
= 0; i
< nbytes
; i
++)
9910 MAKE_CHAR_MULTIBYTE (c
);
9911 char_bytes
= CHAR_STRING (c
, str
);
9912 insert_1_both ((char *) str
, 1, char_bytes
, true, false, false);
9916 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
,
9917 true, false, false);
9921 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9924 insert_1_both ("\n", 1, 1, true, false, false);
9926 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, false);
9928 this_bol_byte
= PT_BYTE
;
9930 /* See if this line duplicates the previous one.
9931 If so, combine duplicates. */
9934 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, false);
9936 prev_bol_byte
= PT_BYTE
;
9938 dups
= message_log_check_duplicate (prev_bol_byte
,
9942 del_range_both (prev_bol
, prev_bol_byte
,
9943 this_bol
, this_bol_byte
, false);
9946 char dupstr
[sizeof " [ times]"
9947 + INT_STRLEN_BOUND (printmax_t
)];
9949 /* If you change this format, don't forget to also
9950 change message_log_check_duplicate. */
9951 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9952 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9953 insert_1_both (dupstr
, duplen
, duplen
,
9959 /* If we have more than the desired maximum number of lines
9960 in the *Messages* buffer now, delete the oldest ones.
9961 This is safe because we don't have undo in this buffer. */
9963 if (NATNUMP (Vmessage_log_max
))
9965 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9966 -XFASTINT (Vmessage_log_max
) - 1, false);
9967 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, false);
9970 BEGV
= marker_position (oldbegv
);
9971 BEGV_BYTE
= marker_byte_position (oldbegv
);
9980 ZV
= marker_position (oldzv
);
9981 ZV_BYTE
= marker_byte_position (oldzv
);
9985 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9987 /* We can't do Fgoto_char (oldpoint) because it will run some
9989 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9990 marker_byte_position (oldpoint
));
9993 unchain_marker (XMARKER (oldpoint
));
9994 unchain_marker (XMARKER (oldbegv
));
9995 unchain_marker (XMARKER (oldzv
));
9997 /* We called insert_1_both above with its 5th argument (PREPARE)
9998 false, which prevents insert_1_both from calling
9999 prepare_to_modify_buffer, which in turns prevents us from
10000 incrementing windows_or_buffers_changed even if *Messages* is
10001 shown in some window. So we must manually set
10002 windows_or_buffers_changed here to make up for that. */
10003 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10004 bset_redisplay (current_buffer
);
10006 set_buffer_internal (oldbuf
);
10008 message_log_need_newline
= !nlflag
;
10009 Vdeactivate_mark
= old_deactivate_mark
;
10014 /* We are at the end of the buffer after just having inserted a newline.
10015 (Note: We depend on the fact we won't be crossing the gap.)
10016 Check to see if the most recent message looks a lot like the previous one.
10017 Return 0 if different, 1 if the new one should just replace it, or a
10018 value N > 1 if we should also append " [N times]". */
10021 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
10024 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
10025 bool seen_dots
= false;
10026 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
10027 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
10029 for (i
= 0; i
< len
; i
++)
10031 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
10033 if (p1
[i
] != p2
[i
])
10039 if (*p1
++ == ' ' && *p1
++ == '[')
10042 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
10043 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
10050 /* Display an echo area message M with a specified length of NBYTES
10051 bytes. The string may include null characters. If M is not a
10052 string, clear out any existing message, and let the mini-buffer
10055 This function cancels echoing. */
10058 message3 (Lisp_Object m
)
10060 struct gcpro gcpro1
;
10063 clear_message (true, true);
10066 /* First flush out any partial line written with print. */
10067 message_log_maybe_newline ();
10070 ptrdiff_t nbytes
= SBYTES (m
);
10071 bool multibyte
= STRING_MULTIBYTE (m
);
10074 SAFE_ALLOCA_STRING (buffer
, m
);
10075 message_dolog (buffer
, nbytes
, true, multibyte
);
10078 if (! inhibit_message
)
10079 message3_nolog (m
);
10084 /* The non-logging version of message3.
10085 This does not cancel echoing, because it is used for echoing.
10086 Perhaps we need to make a separate function for echoing
10087 and make this cancel echoing. */
10090 message3_nolog (Lisp_Object m
)
10092 struct frame
*sf
= SELECTED_FRAME ();
10094 if (FRAME_INITIAL_P (sf
))
10096 if (noninteractive_need_newline
)
10097 putc ('\n', stderr
);
10098 noninteractive_need_newline
= false;
10101 Lisp_Object s
= ENCODE_SYSTEM (m
);
10103 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
10105 if (!cursor_in_echo_area
)
10106 fprintf (stderr
, "\n");
10109 /* Error messages get reported properly by cmd_error, so this must be just an
10110 informative message; if the frame hasn't really been initialized yet, just
10112 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
10114 /* Get the frame containing the mini-buffer
10115 that the selected frame is using. */
10116 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10117 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
10118 struct frame
*f
= XFRAME (frame
);
10120 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
10121 Fmake_frame_visible (frame
);
10123 if (STRINGP (m
) && SCHARS (m
) > 0)
10126 if (minibuffer_auto_raise
)
10127 Fraise_frame (frame
);
10128 /* Assume we are not echoing.
10129 (If we are, echo_now will override this.) */
10130 echo_message_buffer
= Qnil
;
10133 clear_message (true, true);
10135 do_pending_window_change (false);
10136 echo_area_display (true);
10137 do_pending_window_change (false);
10138 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
10139 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
10144 /* Display a null-terminated echo area message M. If M is 0, clear
10145 out any existing message, and let the mini-buffer text show through.
10147 The buffer M must continue to exist until after the echo area gets
10148 cleared or some other message gets displayed there. Do not pass
10149 text that is stored in a Lisp string. Do not pass text in a buffer
10150 that was alloca'd. */
10153 message1 (const char *m
)
10155 message3 (m
? build_unibyte_string (m
) : Qnil
);
10159 /* The non-logging counterpart of message1. */
10162 message1_nolog (const char *m
)
10164 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10167 /* Display a message M which contains a single %s
10168 which gets replaced with STRING. */
10171 message_with_string (const char *m
, Lisp_Object string
, bool log
)
10173 CHECK_STRING (string
);
10175 if (noninteractive
)
10179 /* ENCODE_SYSTEM below can GC and/or relocate the
10180 Lisp data, so make sure we don't use it here. */
10181 eassert (relocatable_string_data_p (m
) != 1);
10183 if (noninteractive_need_newline
)
10184 putc ('\n', stderr
);
10185 noninteractive_need_newline
= false;
10186 fprintf (stderr
, m
, SDATA (ENCODE_SYSTEM (string
)));
10187 if (!cursor_in_echo_area
)
10188 fprintf (stderr
, "\n");
10192 else if (INTERACTIVE
)
10194 /* The frame whose minibuffer we're going to display the message on.
10195 It may be larger than the selected frame, so we need
10196 to use its buffer, not the selected frame's buffer. */
10197 Lisp_Object mini_window
;
10198 struct frame
*f
, *sf
= SELECTED_FRAME ();
10200 /* Get the frame containing the minibuffer
10201 that the selected frame is using. */
10202 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10203 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10205 /* Error messages get reported properly by cmd_error, so this must be
10206 just an informative message; if the frame hasn't really been
10207 initialized yet, just toss it. */
10208 if (f
->glyphs_initialized_p
)
10210 struct gcpro gcpro1
, gcpro2
;
10212 Lisp_Object fmt
= build_string (m
);
10213 Lisp_Object msg
= string
;
10216 msg
= CALLN (Fformat
, fmt
, msg
);
10221 message3_nolog (msg
);
10225 /* Print should start at the beginning of the message
10226 buffer next time. */
10227 message_buf_print
= false;
10233 /* Dump an informative message to the minibuf. If M is 0, clear out
10234 any existing message, and let the mini-buffer text show through. */
10236 static void ATTRIBUTE_FORMAT_PRINTF (1, 0)
10237 vmessage (const char *m
, va_list ap
)
10239 if (noninteractive
)
10243 if (noninteractive_need_newline
)
10244 putc ('\n', stderr
);
10245 noninteractive_need_newline
= false;
10246 vfprintf (stderr
, m
, ap
);
10247 if (!cursor_in_echo_area
)
10248 fprintf (stderr
, "\n");
10252 else if (INTERACTIVE
)
10254 /* The frame whose mini-buffer we're going to display the message
10255 on. It may be larger than the selected frame, so we need to
10256 use its buffer, not the selected frame's buffer. */
10257 Lisp_Object mini_window
;
10258 struct frame
*f
, *sf
= SELECTED_FRAME ();
10260 /* Get the frame containing the mini-buffer
10261 that the selected frame is using. */
10262 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10263 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10265 /* Error messages get reported properly by cmd_error, so this must be
10266 just an informative message; if the frame hasn't really been
10267 initialized yet, just toss it. */
10268 if (f
->glyphs_initialized_p
)
10273 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10275 char *message_buf
= SAFE_ALLOCA (maxsize
+ 1);
10277 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10279 message3 (make_string (message_buf
, len
));
10285 /* Print should start at the beginning of the message
10286 buffer next time. */
10287 message_buf_print
= false;
10293 message (const char *m
, ...)
10303 /* The non-logging version of message. */
10306 message_nolog (const char *m
, ...)
10308 Lisp_Object old_log_max
;
10311 old_log_max
= Vmessage_log_max
;
10312 Vmessage_log_max
= Qnil
;
10314 Vmessage_log_max
= old_log_max
;
10320 /* Display the current message in the current mini-buffer. This is
10321 only called from error handlers in process.c, and is not time
10325 update_echo_area (void)
10327 if (!NILP (echo_area_buffer
[0]))
10329 Lisp_Object string
;
10330 string
= Fcurrent_message ();
10336 /* Make sure echo area buffers in `echo_buffers' are live.
10337 If they aren't, make new ones. */
10340 ensure_echo_area_buffers (void)
10344 for (i
= 0; i
< 2; ++i
)
10345 if (!BUFFERP (echo_buffer
[i
])
10346 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10349 Lisp_Object old_buffer
;
10352 old_buffer
= echo_buffer
[i
];
10353 echo_buffer
[i
] = Fget_buffer_create
10354 (make_formatted_string (name
, " *Echo Area %d*", i
));
10355 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10356 /* to force word wrap in echo area -
10357 it was decided to postpone this*/
10358 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10360 for (j
= 0; j
< 2; ++j
)
10361 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10362 echo_area_buffer
[j
] = echo_buffer
[i
];
10367 /* Call FN with args A1..A2 with either the current or last displayed
10368 echo_area_buffer as current buffer.
10370 WHICH zero means use the current message buffer
10371 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10372 from echo_buffer[] and clear it.
10374 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10375 suitable buffer from echo_buffer[] and clear it.
10377 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10378 that the current message becomes the last displayed one, make
10379 choose a suitable buffer for echo_area_buffer[0], and clear it.
10381 Value is what FN returns. */
10384 with_echo_area_buffer (struct window
*w
, int which
,
10385 bool (*fn
) (ptrdiff_t, Lisp_Object
),
10386 ptrdiff_t a1
, Lisp_Object a2
)
10388 Lisp_Object buffer
;
10389 bool this_one
, the_other
, clear_buffer_p
, rc
;
10390 ptrdiff_t count
= SPECPDL_INDEX ();
10392 /* If buffers aren't live, make new ones. */
10393 ensure_echo_area_buffers ();
10395 clear_buffer_p
= false;
10398 this_one
= false, the_other
= true;
10399 else if (which
> 0)
10400 this_one
= true, the_other
= false;
10403 this_one
= false, the_other
= true;
10404 clear_buffer_p
= true;
10406 /* We need a fresh one in case the current echo buffer equals
10407 the one containing the last displayed echo area message. */
10408 if (!NILP (echo_area_buffer
[this_one
])
10409 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10410 echo_area_buffer
[this_one
] = Qnil
;
10413 /* Choose a suitable buffer from echo_buffer[] is we don't
10415 if (NILP (echo_area_buffer
[this_one
]))
10417 echo_area_buffer
[this_one
]
10418 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10419 ? echo_buffer
[the_other
]
10420 : echo_buffer
[this_one
]);
10421 clear_buffer_p
= true;
10424 buffer
= echo_area_buffer
[this_one
];
10426 /* Don't get confused by reusing the buffer used for echoing
10427 for a different purpose. */
10428 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10431 record_unwind_protect (unwind_with_echo_area_buffer
,
10432 with_echo_area_buffer_unwind_data (w
));
10434 /* Make the echo area buffer current. Note that for display
10435 purposes, it is not necessary that the displayed window's buffer
10436 == current_buffer, except for text property lookup. So, let's
10437 only set that buffer temporarily here without doing a full
10438 Fset_window_buffer. We must also change w->pointm, though,
10439 because otherwise an assertions in unshow_buffer fails, and Emacs
10441 set_buffer_internal_1 (XBUFFER (buffer
));
10444 wset_buffer (w
, buffer
);
10445 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10446 set_marker_both (w
->old_pointm
, buffer
, BEG
, BEG_BYTE
);
10449 bset_undo_list (current_buffer
, Qt
);
10450 bset_read_only (current_buffer
, Qnil
);
10451 specbind (Qinhibit_read_only
, Qt
);
10452 specbind (Qinhibit_modification_hooks
, Qt
);
10454 if (clear_buffer_p
&& Z
> BEG
)
10455 del_range (BEG
, Z
);
10457 eassert (BEGV
>= BEG
);
10458 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10462 eassert (BEGV
>= BEG
);
10463 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10465 unbind_to (count
, Qnil
);
10470 /* Save state that should be preserved around the call to the function
10471 FN called in with_echo_area_buffer. */
10474 with_echo_area_buffer_unwind_data (struct window
*w
)
10477 Lisp_Object vector
, tmp
;
10479 /* Reduce consing by keeping one vector in
10480 Vwith_echo_area_save_vector. */
10481 vector
= Vwith_echo_area_save_vector
;
10482 Vwith_echo_area_save_vector
= Qnil
;
10485 vector
= Fmake_vector (make_number (11), Qnil
);
10487 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10488 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10489 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10493 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10494 ASET (vector
, i
, w
->contents
); ++i
;
10495 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10496 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10497 ASET (vector
, i
, make_number (marker_position (w
->old_pointm
))); ++i
;
10498 ASET (vector
, i
, make_number (marker_byte_position (w
->old_pointm
))); ++i
;
10499 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10500 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10505 for (; i
< end
; ++i
)
10506 ASET (vector
, i
, Qnil
);
10509 eassert (i
== ASIZE (vector
));
10514 /* Restore global state from VECTOR which was created by
10515 with_echo_area_buffer_unwind_data. */
10518 unwind_with_echo_area_buffer (Lisp_Object vector
)
10520 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10521 Vdeactivate_mark
= AREF (vector
, 1);
10522 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10524 if (WINDOWP (AREF (vector
, 3)))
10527 Lisp_Object buffer
;
10529 w
= XWINDOW (AREF (vector
, 3));
10530 buffer
= AREF (vector
, 4);
10532 wset_buffer (w
, buffer
);
10533 set_marker_both (w
->pointm
, buffer
,
10534 XFASTINT (AREF (vector
, 5)),
10535 XFASTINT (AREF (vector
, 6)));
10536 set_marker_both (w
->old_pointm
, buffer
,
10537 XFASTINT (AREF (vector
, 7)),
10538 XFASTINT (AREF (vector
, 8)));
10539 set_marker_both (w
->start
, buffer
,
10540 XFASTINT (AREF (vector
, 9)),
10541 XFASTINT (AREF (vector
, 10)));
10544 Vwith_echo_area_save_vector
= vector
;
10548 /* Set up the echo area for use by print functions. MULTIBYTE_P
10549 means we will print multibyte. */
10552 setup_echo_area_for_printing (bool multibyte_p
)
10554 /* If we can't find an echo area any more, exit. */
10555 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10556 Fkill_emacs (Qnil
);
10558 ensure_echo_area_buffers ();
10560 if (!message_buf_print
)
10562 /* A message has been output since the last time we printed.
10563 Choose a fresh echo area buffer. */
10564 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10565 echo_area_buffer
[0] = echo_buffer
[1];
10567 echo_area_buffer
[0] = echo_buffer
[0];
10569 /* Switch to that buffer and clear it. */
10570 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10571 bset_truncate_lines (current_buffer
, Qnil
);
10575 ptrdiff_t count
= SPECPDL_INDEX ();
10576 specbind (Qinhibit_read_only
, Qt
);
10577 /* Note that undo recording is always disabled. */
10578 del_range (BEG
, Z
);
10579 unbind_to (count
, Qnil
);
10581 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10583 /* Set up the buffer for the multibyteness we need. */
10585 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10586 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10588 /* Raise the frame containing the echo area. */
10589 if (minibuffer_auto_raise
)
10591 struct frame
*sf
= SELECTED_FRAME ();
10592 Lisp_Object mini_window
;
10593 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10594 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10597 message_log_maybe_newline ();
10598 message_buf_print
= true;
10602 if (NILP (echo_area_buffer
[0]))
10604 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10605 echo_area_buffer
[0] = echo_buffer
[1];
10607 echo_area_buffer
[0] = echo_buffer
[0];
10610 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10612 /* Someone switched buffers between print requests. */
10613 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10614 bset_truncate_lines (current_buffer
, Qnil
);
10620 /* Display an echo area message in window W. Value is true if W's
10621 height is changed. If display_last_displayed_message_p,
10622 display the message that was last displayed, otherwise
10623 display the current message. */
10626 display_echo_area (struct window
*w
)
10628 bool no_message_p
, window_height_changed_p
;
10630 /* Temporarily disable garbage collections while displaying the echo
10631 area. This is done because a GC can print a message itself.
10632 That message would modify the echo area buffer's contents while a
10633 redisplay of the buffer is going on, and seriously confuse
10635 ptrdiff_t count
= inhibit_garbage_collection ();
10637 /* If there is no message, we must call display_echo_area_1
10638 nevertheless because it resizes the window. But we will have to
10639 reset the echo_area_buffer in question to nil at the end because
10640 with_echo_area_buffer will sets it to an empty buffer. */
10641 bool i
= display_last_displayed_message_p
;
10642 no_message_p
= NILP (echo_area_buffer
[i
]);
10644 window_height_changed_p
10645 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10646 display_echo_area_1
,
10647 (intptr_t) w
, Qnil
);
10650 echo_area_buffer
[i
] = Qnil
;
10652 unbind_to (count
, Qnil
);
10653 return window_height_changed_p
;
10657 /* Helper for display_echo_area. Display the current buffer which
10658 contains the current echo area message in window W, a mini-window,
10659 a pointer to which is passed in A1. A2..A4 are currently not used.
10660 Change the height of W so that all of the message is displayed.
10661 Value is true if height of W was changed. */
10664 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10667 struct window
*w
= (struct window
*) i1
;
10668 Lisp_Object window
;
10669 struct text_pos start
;
10671 /* Do this before displaying, so that we have a large enough glyph
10672 matrix for the display. If we can't get enough space for the
10673 whole text, display the last N lines. That works by setting w->start. */
10674 bool window_height_changed_p
= resize_mini_window (w
, false);
10676 /* Use the starting position chosen by resize_mini_window. */
10677 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10680 clear_glyph_matrix (w
->desired_matrix
);
10681 XSETWINDOW (window
, w
);
10682 try_window (window
, start
, 0);
10684 return window_height_changed_p
;
10688 /* Resize the echo area window to exactly the size needed for the
10689 currently displayed message, if there is one. If a mini-buffer
10690 is active, don't shrink it. */
10693 resize_echo_area_exactly (void)
10695 if (BUFFERP (echo_area_buffer
[0])
10696 && WINDOWP (echo_area_window
))
10698 struct window
*w
= XWINDOW (echo_area_window
);
10699 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10700 bool resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10701 (intptr_t) w
, resize_exactly
);
10704 windows_or_buffers_changed
= 42;
10705 update_mode_lines
= 30;
10706 redisplay_internal ();
10712 /* Callback function for with_echo_area_buffer, when used from
10713 resize_echo_area_exactly. A1 contains a pointer to the window to
10714 resize, EXACTLY non-nil means resize the mini-window exactly to the
10715 size of the text displayed. A3 and A4 are not used. Value is what
10716 resize_mini_window returns. */
10719 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10722 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10726 /* Resize mini-window W to fit the size of its contents. EXACT_P
10727 means size the window exactly to the size needed. Otherwise, it's
10728 only enlarged until W's buffer is empty.
10730 Set W->start to the right place to begin display. If the whole
10731 contents fit, start at the beginning. Otherwise, start so as
10732 to make the end of the contents appear. This is particularly
10733 important for y-or-n-p, but seems desirable generally.
10735 Value is true if the window height has been changed. */
10738 resize_mini_window (struct window
*w
, bool exact_p
)
10740 struct frame
*f
= XFRAME (w
->frame
);
10741 bool window_height_changed_p
= false;
10743 eassert (MINI_WINDOW_P (w
));
10745 /* By default, start display at the beginning. */
10746 set_marker_both (w
->start
, w
->contents
,
10747 BUF_BEGV (XBUFFER (w
->contents
)),
10748 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10750 /* Don't resize windows while redisplaying a window; it would
10751 confuse redisplay functions when the size of the window they are
10752 displaying changes from under them. Such a resizing can happen,
10753 for instance, when which-func prints a long message while
10754 we are running fontification-functions. We're running these
10755 functions with safe_call which binds inhibit-redisplay to t. */
10756 if (!NILP (Vinhibit_redisplay
))
10759 /* Nil means don't try to resize. */
10760 if (NILP (Vresize_mini_windows
)
10761 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10764 if (!FRAME_MINIBUF_ONLY_P (f
))
10767 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10768 + WINDOW_PIXEL_HEIGHT (w
));
10769 int unit
= FRAME_LINE_HEIGHT (f
);
10770 int height
, max_height
;
10771 struct text_pos start
;
10772 struct buffer
*old_current_buffer
= NULL
;
10774 if (current_buffer
!= XBUFFER (w
->contents
))
10776 old_current_buffer
= current_buffer
;
10777 set_buffer_internal (XBUFFER (w
->contents
));
10780 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10782 /* Compute the max. number of lines specified by the user. */
10783 if (FLOATP (Vmax_mini_window_height
))
10784 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10785 else if (INTEGERP (Vmax_mini_window_height
))
10786 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10788 max_height
= total_height
/ 4;
10790 /* Correct that max. height if it's bogus. */
10791 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10793 /* Find out the height of the text in the window. */
10794 if (it
.line_wrap
== TRUNCATE
)
10799 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10800 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10801 height
= it
.current_y
+ last_height
;
10803 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10804 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10807 /* Compute a suitable window start. */
10808 if (height
> max_height
)
10810 height
= (max_height
/ unit
) * unit
;
10811 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10812 move_it_vertically_backward (&it
, height
- unit
);
10813 start
= it
.current
.pos
;
10816 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10817 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10819 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10821 /* Let it grow only, until we display an empty message, in which
10822 case the window shrinks again. */
10823 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10825 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10827 FRAME_WINDOWS_FROZEN (f
) = true;
10828 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
10829 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10831 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10832 && (exact_p
|| BEGV
== ZV
))
10834 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10836 FRAME_WINDOWS_FROZEN (f
) = false;
10837 shrink_mini_window (w
, true);
10838 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10843 /* Always resize to exact size needed. */
10844 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10846 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10848 FRAME_WINDOWS_FROZEN (f
) = true;
10849 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
10850 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10852 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
10854 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10856 FRAME_WINDOWS_FROZEN (f
) = false;
10857 shrink_mini_window (w
, true);
10861 FRAME_WINDOWS_FROZEN (f
) = true;
10862 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
10865 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10869 if (old_current_buffer
)
10870 set_buffer_internal (old_current_buffer
);
10873 return window_height_changed_p
;
10877 /* Value is the current message, a string, or nil if there is no
10878 current message. */
10881 current_message (void)
10885 if (!BUFFERP (echo_area_buffer
[0]))
10889 with_echo_area_buffer (0, 0, current_message_1
,
10890 (intptr_t) &msg
, Qnil
);
10892 echo_area_buffer
[0] = Qnil
;
10900 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10903 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10906 *msg
= make_buffer_string (BEG
, Z
, true);
10913 /* Push the current message on Vmessage_stack for later restoration
10914 by restore_message. Value is true if the current message isn't
10915 empty. This is a relatively infrequent operation, so it's not
10916 worth optimizing. */
10919 push_message (void)
10921 Lisp_Object msg
= current_message ();
10922 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10923 return STRINGP (msg
);
10927 /* Restore message display from the top of Vmessage_stack. */
10930 restore_message (void)
10932 eassert (CONSP (Vmessage_stack
));
10933 message3_nolog (XCAR (Vmessage_stack
));
10937 /* Handler for unwind-protect calling pop_message. */
10940 pop_message_unwind (void)
10942 /* Pop the top-most entry off Vmessage_stack. */
10943 eassert (CONSP (Vmessage_stack
));
10944 Vmessage_stack
= XCDR (Vmessage_stack
);
10948 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10949 exits. If the stack is not empty, we have a missing pop_message
10953 check_message_stack (void)
10955 if (!NILP (Vmessage_stack
))
10960 /* Truncate to NCHARS what will be displayed in the echo area the next
10961 time we display it---but don't redisplay it now. */
10964 truncate_echo_area (ptrdiff_t nchars
)
10967 echo_area_buffer
[0] = Qnil
;
10968 else if (!noninteractive
10970 && !NILP (echo_area_buffer
[0]))
10972 struct frame
*sf
= SELECTED_FRAME ();
10973 /* Error messages get reported properly by cmd_error, so this must be
10974 just an informative message; if the frame hasn't really been
10975 initialized yet, just toss it. */
10976 if (sf
->glyphs_initialized_p
)
10977 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10982 /* Helper function for truncate_echo_area. Truncate the current
10983 message to at most NCHARS characters. */
10986 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10988 if (BEG
+ nchars
< Z
)
10989 del_range (BEG
+ nchars
, Z
);
10991 echo_area_buffer
[0] = Qnil
;
10995 /* Set the current message to STRING. */
10998 set_message (Lisp_Object string
)
11000 eassert (STRINGP (string
));
11002 message_enable_multibyte
= STRING_MULTIBYTE (string
);
11004 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
11005 message_buf_print
= false;
11006 help_echo_showing_p
= false;
11008 if (STRINGP (Vdebug_on_message
)
11009 && STRINGP (string
)
11010 && fast_string_match (Vdebug_on_message
, string
) >= 0)
11011 call_debugger (list2 (Qerror
, string
));
11015 /* Helper function for set_message. First argument is ignored and second
11016 argument has the same meaning as for set_message.
11017 This function is called with the echo area buffer being current. */
11020 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
11022 eassert (STRINGP (string
));
11024 /* Change multibyteness of the echo buffer appropriately. */
11025 if (message_enable_multibyte
11026 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
11027 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
11029 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
11030 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
11031 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
11033 /* Insert new message at BEG. */
11034 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
11036 /* This function takes care of single/multibyte conversion.
11037 We just have to ensure that the echo area buffer has the right
11038 setting of enable_multibyte_characters. */
11039 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), true);
11045 /* Clear messages. CURRENT_P means clear the current message.
11046 LAST_DISPLAYED_P means clear the message last displayed. */
11049 clear_message (bool current_p
, bool last_displayed_p
)
11053 echo_area_buffer
[0] = Qnil
;
11054 message_cleared_p
= true;
11057 if (last_displayed_p
)
11058 echo_area_buffer
[1] = Qnil
;
11060 message_buf_print
= false;
11063 /* Clear garbaged frames.
11065 This function is used where the old redisplay called
11066 redraw_garbaged_frames which in turn called redraw_frame which in
11067 turn called clear_frame. The call to clear_frame was a source of
11068 flickering. I believe a clear_frame is not necessary. It should
11069 suffice in the new redisplay to invalidate all current matrices,
11070 and ensure a complete redisplay of all windows. */
11073 clear_garbaged_frames (void)
11075 if (frame_garbaged
)
11077 Lisp_Object tail
, frame
;
11079 FOR_EACH_FRAME (tail
, frame
)
11081 struct frame
*f
= XFRAME (frame
);
11083 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
11088 clear_current_matrices (f
);
11089 fset_redisplay (f
);
11090 f
->garbaged
= false;
11091 f
->resized_p
= false;
11095 frame_garbaged
= false;
11100 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P,
11101 update selected_frame. Value is true if the mini-windows height
11102 has been changed. */
11105 echo_area_display (bool update_frame_p
)
11107 Lisp_Object mini_window
;
11110 bool window_height_changed_p
= false;
11111 struct frame
*sf
= SELECTED_FRAME ();
11113 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11114 w
= XWINDOW (mini_window
);
11115 f
= XFRAME (WINDOW_FRAME (w
));
11117 /* Don't display if frame is invisible or not yet initialized. */
11118 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
11121 #ifdef HAVE_WINDOW_SYSTEM
11122 /* When Emacs starts, selected_frame may be the initial terminal
11123 frame. If we let this through, a message would be displayed on
11125 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
11127 #endif /* HAVE_WINDOW_SYSTEM */
11129 /* Redraw garbaged frames. */
11130 clear_garbaged_frames ();
11132 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
11134 echo_area_window
= mini_window
;
11135 window_height_changed_p
= display_echo_area (w
);
11136 w
->must_be_updated_p
= true;
11138 /* Update the display, unless called from redisplay_internal.
11139 Also don't update the screen during redisplay itself. The
11140 update will happen at the end of redisplay, and an update
11141 here could cause confusion. */
11142 if (update_frame_p
&& !redisplaying_p
)
11146 /* If the display update has been interrupted by pending
11147 input, update mode lines in the frame. Due to the
11148 pending input, it might have been that redisplay hasn't
11149 been called, so that mode lines above the echo area are
11150 garbaged. This looks odd, so we prevent it here. */
11151 if (!display_completed
)
11152 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11154 if (window_height_changed_p
11155 /* Don't do this if Emacs is shutting down. Redisplay
11156 needs to run hooks. */
11157 && !NILP (Vrun_hooks
))
11159 /* Must update other windows. Likewise as in other
11160 cases, don't let this update be interrupted by
11162 ptrdiff_t count
= SPECPDL_INDEX ();
11163 specbind (Qredisplay_dont_pause
, Qt
);
11164 windows_or_buffers_changed
= 44;
11165 redisplay_internal ();
11166 unbind_to (count
, Qnil
);
11168 else if (FRAME_WINDOW_P (f
) && n
== 0)
11170 /* Window configuration is the same as before.
11171 Can do with a display update of the echo area,
11172 unless we displayed some mode lines. */
11173 update_single_window (w
);
11177 update_frame (f
, true, true);
11179 /* If cursor is in the echo area, make sure that the next
11180 redisplay displays the minibuffer, so that the cursor will
11181 be replaced with what the minibuffer wants. */
11182 if (cursor_in_echo_area
)
11183 wset_redisplay (XWINDOW (mini_window
));
11186 else if (!EQ (mini_window
, selected_window
))
11187 wset_redisplay (XWINDOW (mini_window
));
11189 /* Last displayed message is now the current message. */
11190 echo_area_buffer
[1] = echo_area_buffer
[0];
11191 /* Inform read_char that we're not echoing. */
11192 echo_message_buffer
= Qnil
;
11194 /* Prevent redisplay optimization in redisplay_internal by resetting
11195 this_line_start_pos. This is done because the mini-buffer now
11196 displays the message instead of its buffer text. */
11197 if (EQ (mini_window
, selected_window
))
11198 CHARPOS (this_line_start_pos
) = 0;
11200 return window_height_changed_p
;
11203 /* True if W's buffer was changed but not saved. */
11206 window_buffer_changed (struct window
*w
)
11208 struct buffer
*b
= XBUFFER (w
->contents
);
11210 eassert (BUFFER_LIVE_P (b
));
11212 return (BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
;
11215 /* True if W has %c in its mode line and mode line should be updated. */
11218 mode_line_update_needed (struct window
*w
)
11220 return (w
->column_number_displayed
!= -1
11221 && !(PT
== w
->last_point
&& !window_outdated (w
))
11222 && (w
->column_number_displayed
!= current_column ()));
11225 /* True if window start of W is frozen and may not be changed during
11229 window_frozen_p (struct window
*w
)
11231 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11233 Lisp_Object window
;
11235 XSETWINDOW (window
, w
);
11236 if (MINI_WINDOW_P (w
))
11238 else if (EQ (window
, selected_window
))
11240 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11241 && EQ (window
, Vminibuf_scroll_window
))
11242 /* This special window can't be frozen too. */
11250 /***********************************************************************
11251 Mode Lines and Frame Titles
11252 ***********************************************************************/
11254 /* A buffer for constructing non-propertized mode-line strings and
11255 frame titles in it; allocated from the heap in init_xdisp and
11256 resized as needed in store_mode_line_noprop_char. */
11258 static char *mode_line_noprop_buf
;
11260 /* The buffer's end, and a current output position in it. */
11262 static char *mode_line_noprop_buf_end
;
11263 static char *mode_line_noprop_ptr
;
11265 #define MODE_LINE_NOPROP_LEN(start) \
11266 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11269 MODE_LINE_DISPLAY
= 0,
11273 } mode_line_target
;
11275 /* Alist that caches the results of :propertize.
11276 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11277 static Lisp_Object mode_line_proptrans_alist
;
11279 /* List of strings making up the mode-line. */
11280 static Lisp_Object mode_line_string_list
;
11282 /* Base face property when building propertized mode line string. */
11283 static Lisp_Object mode_line_string_face
;
11284 static Lisp_Object mode_line_string_face_prop
;
11287 /* Unwind data for mode line strings */
11289 static Lisp_Object Vmode_line_unwind_vector
;
11292 format_mode_line_unwind_data (struct frame
*target_frame
,
11293 struct buffer
*obuf
,
11295 bool save_proptrans
)
11297 Lisp_Object vector
, tmp
;
11299 /* Reduce consing by keeping one vector in
11300 Vwith_echo_area_save_vector. */
11301 vector
= Vmode_line_unwind_vector
;
11302 Vmode_line_unwind_vector
= Qnil
;
11305 vector
= Fmake_vector (make_number (10), Qnil
);
11307 ASET (vector
, 0, make_number (mode_line_target
));
11308 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11309 ASET (vector
, 2, mode_line_string_list
);
11310 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11311 ASET (vector
, 4, mode_line_string_face
);
11312 ASET (vector
, 5, mode_line_string_face_prop
);
11315 XSETBUFFER (tmp
, obuf
);
11318 ASET (vector
, 6, tmp
);
11319 ASET (vector
, 7, owin
);
11322 /* Similarly to `with-selected-window', if the operation selects
11323 a window on another frame, we must restore that frame's
11324 selected window, and (for a tty) the top-frame. */
11325 ASET (vector
, 8, target_frame
->selected_window
);
11326 if (FRAME_TERMCAP_P (target_frame
))
11327 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11334 unwind_format_mode_line (Lisp_Object vector
)
11336 Lisp_Object old_window
= AREF (vector
, 7);
11337 Lisp_Object target_frame_window
= AREF (vector
, 8);
11338 Lisp_Object old_top_frame
= AREF (vector
, 9);
11340 mode_line_target
= XINT (AREF (vector
, 0));
11341 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11342 mode_line_string_list
= AREF (vector
, 2);
11343 if (! EQ (AREF (vector
, 3), Qt
))
11344 mode_line_proptrans_alist
= AREF (vector
, 3);
11345 mode_line_string_face
= AREF (vector
, 4);
11346 mode_line_string_face_prop
= AREF (vector
, 5);
11348 /* Select window before buffer, since it may change the buffer. */
11349 if (!NILP (old_window
))
11351 /* If the operation that we are unwinding had selected a window
11352 on a different frame, reset its frame-selected-window. For a
11353 text terminal, reset its top-frame if necessary. */
11354 if (!NILP (target_frame_window
))
11357 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11359 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11360 Fselect_window (target_frame_window
, Qt
);
11362 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11363 Fselect_frame (old_top_frame
, Qt
);
11366 Fselect_window (old_window
, Qt
);
11369 if (!NILP (AREF (vector
, 6)))
11371 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11372 ASET (vector
, 6, Qnil
);
11375 Vmode_line_unwind_vector
= vector
;
11379 /* Store a single character C for the frame title in mode_line_noprop_buf.
11380 Re-allocate mode_line_noprop_buf if necessary. */
11383 store_mode_line_noprop_char (char c
)
11385 /* If output position has reached the end of the allocated buffer,
11386 increase the buffer's size. */
11387 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11389 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11390 ptrdiff_t size
= len
;
11391 mode_line_noprop_buf
=
11392 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11393 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11394 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11397 *mode_line_noprop_ptr
++ = c
;
11401 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11402 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11403 characters that yield more columns than PRECISION; PRECISION <= 0
11404 means copy the whole string. Pad with spaces until FIELD_WIDTH
11405 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11406 pad. Called from display_mode_element when it is used to build a
11410 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11412 const unsigned char *str
= (const unsigned char *) string
;
11414 ptrdiff_t dummy
, nbytes
;
11416 /* Copy at most PRECISION chars from STR. */
11417 nbytes
= strlen (string
);
11418 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11420 store_mode_line_noprop_char (*str
++);
11422 /* Fill up with spaces until FIELD_WIDTH reached. */
11423 while (field_width
> 0
11424 && n
< field_width
)
11426 store_mode_line_noprop_char (' ');
11433 /***********************************************************************
11435 ***********************************************************************/
11437 #ifdef HAVE_WINDOW_SYSTEM
11439 /* Set the title of FRAME, if it has changed. The title format is
11440 Vicon_title_format if FRAME is iconified, otherwise it is
11441 frame_title_format. */
11444 x_consider_frame_title (Lisp_Object frame
)
11446 struct frame
*f
= XFRAME (frame
);
11448 if (FRAME_WINDOW_P (f
)
11449 || FRAME_MINIBUF_ONLY_P (f
)
11450 || f
->explicit_name
)
11452 /* Do we have more than one visible frame on this X display? */
11453 Lisp_Object tail
, other_frame
, fmt
;
11454 ptrdiff_t title_start
;
11458 ptrdiff_t count
= SPECPDL_INDEX ();
11460 FOR_EACH_FRAME (tail
, other_frame
)
11462 struct frame
*tf
= XFRAME (other_frame
);
11465 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11466 && !FRAME_MINIBUF_ONLY_P (tf
)
11467 && !EQ (other_frame
, tip_frame
)
11468 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11472 /* Set global variable indicating that multiple frames exist. */
11473 multiple_frames
= CONSP (tail
);
11475 /* Switch to the buffer of selected window of the frame. Set up
11476 mode_line_target so that display_mode_element will output into
11477 mode_line_noprop_buf; then display the title. */
11478 record_unwind_protect (unwind_format_mode_line
,
11479 format_mode_line_unwind_data
11480 (f
, current_buffer
, selected_window
, false));
11482 Fselect_window (f
->selected_window
, Qt
);
11483 set_buffer_internal_1
11484 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11485 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11487 mode_line_target
= MODE_LINE_TITLE
;
11488 title_start
= MODE_LINE_NOPROP_LEN (0);
11489 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11490 NULL
, DEFAULT_FACE_ID
);
11491 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, false);
11492 len
= MODE_LINE_NOPROP_LEN (title_start
);
11493 title
= mode_line_noprop_buf
+ title_start
;
11494 unbind_to (count
, Qnil
);
11496 /* Set the title only if it's changed. This avoids consing in
11497 the common case where it hasn't. (If it turns out that we've
11498 already wasted too much time by walking through the list with
11499 display_mode_element, then we might need to optimize at a
11500 higher level than this.) */
11501 if (! STRINGP (f
->name
)
11502 || SBYTES (f
->name
) != len
11503 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11504 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11508 #endif /* not HAVE_WINDOW_SYSTEM */
11511 /***********************************************************************
11513 ***********************************************************************/
11515 /* True if we will not redisplay all visible windows. */
11516 #define REDISPLAY_SOME_P() \
11517 ((windows_or_buffers_changed == 0 \
11518 || windows_or_buffers_changed == REDISPLAY_SOME) \
11519 && (update_mode_lines == 0 \
11520 || update_mode_lines == REDISPLAY_SOME))
11522 /* Prepare for redisplay by updating menu-bar item lists when
11523 appropriate. This can call eval. */
11526 prepare_menu_bars (void)
11528 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11529 bool some_windows
= REDISPLAY_SOME_P ();
11530 struct gcpro gcpro1
, gcpro2
;
11531 Lisp_Object tooltip_frame
;
11533 #ifdef HAVE_WINDOW_SYSTEM
11534 tooltip_frame
= tip_frame
;
11536 tooltip_frame
= Qnil
;
11539 if (FUNCTIONP (Vpre_redisplay_function
))
11541 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11542 if (all_windows
&& some_windows
)
11544 Lisp_Object ws
= window_list ();
11545 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11547 Lisp_Object
this = XCAR (ws
);
11548 struct window
*w
= XWINDOW (this);
11550 || XFRAME (w
->frame
)->redisplay
11551 || XBUFFER (w
->contents
)->text
->redisplay
)
11553 windows
= Fcons (this, windows
);
11557 safe__call1 (true, Vpre_redisplay_function
, windows
);
11560 /* Update all frame titles based on their buffer names, etc. We do
11561 this before the menu bars so that the buffer-menu will show the
11562 up-to-date frame titles. */
11563 #ifdef HAVE_WINDOW_SYSTEM
11566 Lisp_Object tail
, frame
;
11568 FOR_EACH_FRAME (tail
, frame
)
11570 struct frame
*f
= XFRAME (frame
);
11571 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11575 && !XBUFFER (w
->contents
)->text
->redisplay
)
11578 if (!EQ (frame
, tooltip_frame
)
11579 && (FRAME_ICONIFIED_P (f
)
11580 || FRAME_VISIBLE_P (f
) == 1
11581 /* Exclude TTY frames that are obscured because they
11582 are not the top frame on their console. This is
11583 because x_consider_frame_title actually switches
11584 to the frame, which for TTY frames means it is
11585 marked as garbaged, and will be completely
11586 redrawn on the next redisplay cycle. This causes
11587 TTY frames to be completely redrawn, when there
11588 are more than one of them, even though nothing
11589 should be changed on display. */
11590 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11591 x_consider_frame_title (frame
);
11594 #endif /* HAVE_WINDOW_SYSTEM */
11596 /* Update the menu bar item lists, if appropriate. This has to be
11597 done before any actual redisplay or generation of display lines. */
11601 Lisp_Object tail
, frame
;
11602 ptrdiff_t count
= SPECPDL_INDEX ();
11603 /* True means that update_menu_bar has run its hooks
11604 so any further calls to update_menu_bar shouldn't do so again. */
11605 bool menu_bar_hooks_run
= false;
11607 record_unwind_save_match_data ();
11609 FOR_EACH_FRAME (tail
, frame
)
11611 struct frame
*f
= XFRAME (frame
);
11612 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11614 /* Ignore tooltip frame. */
11615 if (EQ (frame
, tooltip_frame
))
11621 && !XBUFFER (w
->contents
)->text
->redisplay
)
11624 /* If a window on this frame changed size, report that to
11625 the user and clear the size-change flag. */
11626 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11628 Lisp_Object functions
;
11630 /* Clear flag first in case we get an error below. */
11631 FRAME_WINDOW_SIZES_CHANGED (f
) = false;
11632 functions
= Vwindow_size_change_functions
;
11633 GCPRO2 (tail
, functions
);
11635 while (CONSP (functions
))
11637 if (!EQ (XCAR (functions
), Qt
))
11638 call1 (XCAR (functions
), frame
);
11639 functions
= XCDR (functions
);
11645 menu_bar_hooks_run
= update_menu_bar (f
, false, menu_bar_hooks_run
);
11646 #ifdef HAVE_WINDOW_SYSTEM
11647 update_tool_bar (f
, false);
11652 unbind_to (count
, Qnil
);
11656 struct frame
*sf
= SELECTED_FRAME ();
11657 update_menu_bar (sf
, true, false);
11658 #ifdef HAVE_WINDOW_SYSTEM
11659 update_tool_bar (sf
, true);
11665 /* Update the menu bar item list for frame F. This has to be done
11666 before we start to fill in any display lines, because it can call
11669 If SAVE_MATCH_DATA, we must save and restore it here.
11671 If HOOKS_RUN, a previous call to update_menu_bar
11672 already ran the menu bar hooks for this redisplay, so there
11673 is no need to run them again. The return value is the
11674 updated value of this flag, to pass to the next call. */
11677 update_menu_bar (struct frame
*f
, bool save_match_data
, bool hooks_run
)
11679 Lisp_Object window
;
11682 /* If called recursively during a menu update, do nothing. This can
11683 happen when, for instance, an activate-menubar-hook causes a
11685 if (inhibit_menubar_update
)
11688 window
= FRAME_SELECTED_WINDOW (f
);
11689 w
= XWINDOW (window
);
11691 if (FRAME_WINDOW_P (f
)
11693 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11694 || defined (HAVE_NS) || defined (USE_GTK)
11695 FRAME_EXTERNAL_MENU_BAR (f
)
11697 FRAME_MENU_BAR_LINES (f
) > 0
11699 : FRAME_MENU_BAR_LINES (f
) > 0)
11701 /* If the user has switched buffers or windows, we need to
11702 recompute to reflect the new bindings. But we'll
11703 recompute when update_mode_lines is set too; that means
11704 that people can use force-mode-line-update to request
11705 that the menu bar be recomputed. The adverse effect on
11706 the rest of the redisplay algorithm is about the same as
11707 windows_or_buffers_changed anyway. */
11708 if (windows_or_buffers_changed
11709 /* This used to test w->update_mode_line, but we believe
11710 there is no need to recompute the menu in that case. */
11711 || update_mode_lines
11712 || window_buffer_changed (w
))
11714 struct buffer
*prev
= current_buffer
;
11715 ptrdiff_t count
= SPECPDL_INDEX ();
11717 specbind (Qinhibit_menubar_update
, Qt
);
11719 set_buffer_internal_1 (XBUFFER (w
->contents
));
11720 if (save_match_data
)
11721 record_unwind_save_match_data ();
11722 if (NILP (Voverriding_local_map_menu_flag
))
11724 specbind (Qoverriding_terminal_local_map
, Qnil
);
11725 specbind (Qoverriding_local_map
, Qnil
);
11730 /* Run the Lucid hook. */
11731 safe_run_hooks (Qactivate_menubar_hook
);
11733 /* If it has changed current-menubar from previous value,
11734 really recompute the menu-bar from the value. */
11735 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11736 call0 (Qrecompute_lucid_menubar
);
11738 safe_run_hooks (Qmenu_bar_update_hook
);
11743 XSETFRAME (Vmenu_updating_frame
, f
);
11744 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11746 /* Redisplay the menu bar in case we changed it. */
11747 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11748 || defined (HAVE_NS) || defined (USE_GTK)
11749 if (FRAME_WINDOW_P (f
))
11751 #if defined (HAVE_NS)
11752 /* All frames on Mac OS share the same menubar. So only
11753 the selected frame should be allowed to set it. */
11754 if (f
== SELECTED_FRAME ())
11756 set_frame_menubar (f
, false, false);
11759 /* On a terminal screen, the menu bar is an ordinary screen
11760 line, and this makes it get updated. */
11761 w
->update_mode_line
= true;
11762 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11763 /* In the non-toolkit version, the menu bar is an ordinary screen
11764 line, and this makes it get updated. */
11765 w
->update_mode_line
= true;
11766 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11768 unbind_to (count
, Qnil
);
11769 set_buffer_internal_1 (prev
);
11776 /***********************************************************************
11778 ***********************************************************************/
11780 #ifdef HAVE_WINDOW_SYSTEM
11782 /* Select `frame' temporarily without running all the code in
11784 FIXME: Maybe do_switch_frame should be trimmed down similarly
11785 when `norecord' is set. */
11787 fast_set_selected_frame (Lisp_Object frame
)
11789 if (!EQ (selected_frame
, frame
))
11791 selected_frame
= frame
;
11792 selected_window
= XFRAME (frame
)->selected_window
;
11796 /* Update the tool-bar item list for frame F. This has to be done
11797 before we start to fill in any display lines. Called from
11798 prepare_menu_bars. If SAVE_MATCH_DATA, we must save
11799 and restore it here. */
11802 update_tool_bar (struct frame
*f
, bool save_match_data
)
11804 #if defined (USE_GTK) || defined (HAVE_NS)
11805 bool do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11807 bool do_update
= (WINDOWP (f
->tool_bar_window
)
11808 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0);
11813 Lisp_Object window
;
11816 window
= FRAME_SELECTED_WINDOW (f
);
11817 w
= XWINDOW (window
);
11819 /* If the user has switched buffers or windows, we need to
11820 recompute to reflect the new bindings. But we'll
11821 recompute when update_mode_lines is set too; that means
11822 that people can use force-mode-line-update to request
11823 that the menu bar be recomputed. The adverse effect on
11824 the rest of the redisplay algorithm is about the same as
11825 windows_or_buffers_changed anyway. */
11826 if (windows_or_buffers_changed
11827 || w
->update_mode_line
11828 || update_mode_lines
11829 || window_buffer_changed (w
))
11831 struct buffer
*prev
= current_buffer
;
11832 ptrdiff_t count
= SPECPDL_INDEX ();
11833 Lisp_Object frame
, new_tool_bar
;
11834 int new_n_tool_bar
;
11835 struct gcpro gcpro1
;
11837 /* Set current_buffer to the buffer of the selected
11838 window of the frame, so that we get the right local
11840 set_buffer_internal_1 (XBUFFER (w
->contents
));
11842 /* Save match data, if we must. */
11843 if (save_match_data
)
11844 record_unwind_save_match_data ();
11846 /* Make sure that we don't accidentally use bogus keymaps. */
11847 if (NILP (Voverriding_local_map_menu_flag
))
11849 specbind (Qoverriding_terminal_local_map
, Qnil
);
11850 specbind (Qoverriding_local_map
, Qnil
);
11853 GCPRO1 (new_tool_bar
);
11855 /* We must temporarily set the selected frame to this frame
11856 before calling tool_bar_items, because the calculation of
11857 the tool-bar keymap uses the selected frame (see
11858 `tool-bar-make-keymap' in tool-bar.el). */
11859 eassert (EQ (selected_window
,
11860 /* Since we only explicitly preserve selected_frame,
11861 check that selected_window would be redundant. */
11862 XFRAME (selected_frame
)->selected_window
));
11863 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11864 XSETFRAME (frame
, f
);
11865 fast_set_selected_frame (frame
);
11867 /* Build desired tool-bar items from keymaps. */
11869 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11872 /* Redisplay the tool-bar if we changed it. */
11873 if (new_n_tool_bar
!= f
->n_tool_bar_items
11874 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11876 /* Redisplay that happens asynchronously due to an expose event
11877 may access f->tool_bar_items. Make sure we update both
11878 variables within BLOCK_INPUT so no such event interrupts. */
11880 fset_tool_bar_items (f
, new_tool_bar
);
11881 f
->n_tool_bar_items
= new_n_tool_bar
;
11882 w
->update_mode_line
= true;
11888 unbind_to (count
, Qnil
);
11889 set_buffer_internal_1 (prev
);
11894 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11896 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11897 F's desired tool-bar contents. F->tool_bar_items must have
11898 been set up previously by calling prepare_menu_bars. */
11901 build_desired_tool_bar_string (struct frame
*f
)
11903 int i
, size
, size_needed
;
11904 struct gcpro gcpro1
, gcpro2
;
11905 Lisp_Object image
, plist
;
11907 image
= plist
= Qnil
;
11908 GCPRO2 (image
, plist
);
11910 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11911 Otherwise, make a new string. */
11913 /* The size of the string we might be able to reuse. */
11914 size
= (STRINGP (f
->desired_tool_bar_string
)
11915 ? SCHARS (f
->desired_tool_bar_string
)
11918 /* We need one space in the string for each image. */
11919 size_needed
= f
->n_tool_bar_items
;
11921 /* Reuse f->desired_tool_bar_string, if possible. */
11922 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11923 fset_desired_tool_bar_string
11924 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11927 AUTO_LIST4 (props
, Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11928 struct gcpro gcpro1
;
11930 Fremove_text_properties (make_number (0), make_number (size
),
11931 props
, f
->desired_tool_bar_string
);
11935 /* Put a `display' property on the string for the images to display,
11936 put a `menu_item' property on tool-bar items with a value that
11937 is the index of the item in F's tool-bar item vector. */
11938 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11940 #define PROP(IDX) \
11941 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11943 bool enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11944 bool selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11945 int hmargin
, vmargin
, relief
, idx
, end
;
11947 /* If image is a vector, choose the image according to the
11949 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11950 if (VECTORP (image
))
11954 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11955 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11958 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11959 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11961 eassert (ASIZE (image
) >= idx
);
11962 image
= AREF (image
, idx
);
11967 /* Ignore invalid image specifications. */
11968 if (!valid_image_p (image
))
11971 /* Display the tool-bar button pressed, or depressed. */
11972 plist
= Fcopy_sequence (XCDR (image
));
11974 /* Compute margin and relief to draw. */
11975 relief
= (tool_bar_button_relief
>= 0
11976 ? tool_bar_button_relief
11977 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11978 hmargin
= vmargin
= relief
;
11980 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11981 INT_MAX
- max (hmargin
, vmargin
)))
11983 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11984 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11986 else if (CONSP (Vtool_bar_button_margin
))
11988 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11989 INT_MAX
- hmargin
))
11990 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11992 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11993 INT_MAX
- vmargin
))
11994 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11997 if (auto_raise_tool_bar_buttons_p
)
11999 /* Add a `:relief' property to the image spec if the item is
12003 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
12010 /* If image is selected, display it pressed, i.e. with a
12011 negative relief. If it's not selected, display it with a
12013 plist
= Fplist_put (plist
, QCrelief
,
12015 ? make_number (-relief
)
12016 : make_number (relief
)));
12021 /* Put a margin around the image. */
12022 if (hmargin
|| vmargin
)
12024 if (hmargin
== vmargin
)
12025 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
12027 plist
= Fplist_put (plist
, QCmargin
,
12028 Fcons (make_number (hmargin
),
12029 make_number (vmargin
)));
12032 /* If button is not enabled, and we don't have special images
12033 for the disabled state, make the image appear disabled by
12034 applying an appropriate algorithm to it. */
12035 if (!enabled_p
&& idx
< 0)
12036 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
12038 /* Put a `display' text property on the string for the image to
12039 display. Put a `menu-item' property on the string that gives
12040 the start of this item's properties in the tool-bar items
12042 image
= Fcons (Qimage
, plist
);
12043 AUTO_LIST4 (props
, Qdisplay
, image
, Qmenu_item
,
12044 make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
12045 struct gcpro gcpro1
;
12048 /* Let the last image hide all remaining spaces in the tool bar
12049 string. The string can be longer than needed when we reuse a
12050 previous string. */
12051 if (i
+ 1 == f
->n_tool_bar_items
)
12052 end
= SCHARS (f
->desired_tool_bar_string
);
12055 Fadd_text_properties (make_number (i
), make_number (end
),
12056 props
, f
->desired_tool_bar_string
);
12065 /* Display one line of the tool-bar of frame IT->f.
12067 HEIGHT specifies the desired height of the tool-bar line.
12068 If the actual height of the glyph row is less than HEIGHT, the
12069 row's height is increased to HEIGHT, and the icons are centered
12070 vertically in the new height.
12072 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
12073 count a final empty row in case the tool-bar width exactly matches
12078 display_tool_bar_line (struct it
*it
, int height
)
12080 struct glyph_row
*row
= it
->glyph_row
;
12081 int max_x
= it
->last_visible_x
;
12082 struct glyph
*last
;
12084 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
12085 clear_glyph_row (row
);
12086 row
->enabled_p
= true;
12087 row
->y
= it
->current_y
;
12089 /* Note that this isn't made use of if the face hasn't a box,
12090 so there's no need to check the face here. */
12091 it
->start_of_box_run_p
= true;
12093 while (it
->current_x
< max_x
)
12095 int x
, n_glyphs_before
, i
, nglyphs
;
12096 struct it it_before
;
12098 /* Get the next display element. */
12099 if (!get_next_display_element (it
))
12101 /* Don't count empty row if we are counting needed tool-bar lines. */
12102 if (height
< 0 && !it
->hpos
)
12107 /* Produce glyphs. */
12108 n_glyphs_before
= row
->used
[TEXT_AREA
];
12111 PRODUCE_GLYPHS (it
);
12113 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12115 x
= it_before
.current_x
;
12116 while (i
< nglyphs
)
12118 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12120 if (x
+ glyph
->pixel_width
> max_x
)
12122 /* Glyph doesn't fit on line. Backtrack. */
12123 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12125 /* If this is the only glyph on this line, it will never fit on the
12126 tool-bar, so skip it. But ensure there is at least one glyph,
12127 so we don't accidentally disable the tool-bar. */
12128 if (n_glyphs_before
== 0
12129 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
12135 x
+= glyph
->pixel_width
;
12139 /* Stop at line end. */
12140 if (ITERATOR_AT_END_OF_LINE_P (it
))
12143 set_iterator_to_next (it
, true);
12148 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12150 /* Use default face for the border below the tool bar.
12152 FIXME: When auto-resize-tool-bars is grow-only, there is
12153 no additional border below the possibly empty tool-bar lines.
12154 So to make the extra empty lines look "normal", we have to
12155 use the tool-bar face for the border too. */
12156 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12157 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12158 it
->face_id
= DEFAULT_FACE_ID
;
12160 extend_face_to_end_of_line (it
);
12161 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12162 last
->right_box_line_p
= true;
12163 if (last
== row
->glyphs
[TEXT_AREA
])
12164 last
->left_box_line_p
= true;
12166 /* Make line the desired height and center it vertically. */
12167 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12169 /* Don't add more than one line height. */
12170 height
%= FRAME_LINE_HEIGHT (it
->f
);
12171 it
->max_ascent
+= height
/ 2;
12172 it
->max_descent
+= (height
+ 1) / 2;
12175 compute_line_metrics (it
);
12177 /* If line is empty, make it occupy the rest of the tool-bar. */
12178 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12180 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12181 row
->visible_height
= row
->height
;
12182 row
->ascent
= row
->phys_ascent
= 0;
12183 row
->extra_line_spacing
= 0;
12186 row
->full_width_p
= true;
12187 row
->continued_p
= false;
12188 row
->truncated_on_left_p
= false;
12189 row
->truncated_on_right_p
= false;
12191 it
->current_x
= it
->hpos
= 0;
12192 it
->current_y
+= row
->height
;
12198 /* Value is the number of pixels needed to make all tool-bar items of
12199 frame F visible. The actual number of glyph rows needed is
12200 returned in *N_ROWS if non-NULL. */
12202 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12204 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12206 /* tool_bar_height is called from redisplay_tool_bar after building
12207 the desired matrix, so use (unused) mode-line row as temporary row to
12208 avoid destroying the first tool-bar row. */
12209 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12211 /* Initialize an iterator for iteration over
12212 F->desired_tool_bar_string in the tool-bar window of frame F. */
12213 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12214 temp_row
->reversed_p
= false;
12215 it
.first_visible_x
= 0;
12216 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12217 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12218 it
.paragraph_embedding
= L2R
;
12220 while (!ITERATOR_AT_END_P (&it
))
12222 clear_glyph_row (temp_row
);
12223 it
.glyph_row
= temp_row
;
12224 display_tool_bar_line (&it
, -1);
12226 clear_glyph_row (temp_row
);
12228 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12230 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12233 return it
.current_y
;
12235 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12238 #endif /* !USE_GTK && !HAVE_NS */
12240 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12242 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12243 If FRAME is nil or omitted, use the selected frame. Optional argument
12244 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12245 (Lisp_Object frame
, Lisp_Object pixelwise
)
12249 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12250 struct frame
*f
= decode_any_frame (frame
);
12252 if (WINDOWP (f
->tool_bar_window
)
12253 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12255 update_tool_bar (f
, true);
12256 if (f
->n_tool_bar_items
)
12258 build_desired_tool_bar_string (f
);
12259 height
= tool_bar_height (f
, NULL
, !NILP (pixelwise
));
12264 return make_number (height
);
12268 /* Display the tool-bar of frame F. Value is true if tool-bar's
12269 height should be changed. */
12271 redisplay_tool_bar (struct frame
*f
)
12273 #if defined (USE_GTK) || defined (HAVE_NS)
12275 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12276 update_frame_tool_bar (f
);
12279 #else /* !USE_GTK && !HAVE_NS */
12283 struct glyph_row
*row
;
12285 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12286 do anything. This means you must start with tool-bar-lines
12287 non-zero to get the auto-sizing effect. Or in other words, you
12288 can turn off tool-bars by specifying tool-bar-lines zero. */
12289 if (!WINDOWP (f
->tool_bar_window
)
12290 || (w
= XWINDOW (f
->tool_bar_window
),
12291 WINDOW_TOTAL_LINES (w
) == 0))
12294 /* Set up an iterator for the tool-bar window. */
12295 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12296 it
.first_visible_x
= 0;
12297 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12298 row
= it
.glyph_row
;
12299 row
->reversed_p
= false;
12301 /* Build a string that represents the contents of the tool-bar. */
12302 build_desired_tool_bar_string (f
);
12303 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12304 /* FIXME: This should be controlled by a user option. But it
12305 doesn't make sense to have an R2L tool bar if the menu bar cannot
12306 be drawn also R2L, and making the menu bar R2L is tricky due
12307 toolkit-specific code that implements it. If an R2L tool bar is
12308 ever supported, display_tool_bar_line should also be augmented to
12309 call unproduce_glyphs like display_line and display_string
12311 it
.paragraph_embedding
= L2R
;
12313 if (f
->n_tool_bar_rows
== 0)
12315 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, true);
12317 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12319 x_change_tool_bar_height (f
, new_height
);
12320 frame_default_tool_bar_height
= new_height
;
12321 /* Always do that now. */
12322 clear_glyph_matrix (w
->desired_matrix
);
12323 f
->fonts_changed
= true;
12328 /* Display as many lines as needed to display all tool-bar items. */
12330 if (f
->n_tool_bar_rows
> 0)
12332 int border
, rows
, height
, extra
;
12334 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12335 border
= XINT (Vtool_bar_border
);
12336 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12337 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12338 else if (EQ (Vtool_bar_border
, Qborder_width
))
12339 border
= f
->border_width
;
12345 rows
= f
->n_tool_bar_rows
;
12346 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12347 extra
= it
.last_visible_y
- border
- height
* rows
;
12349 while (it
.current_y
< it
.last_visible_y
)
12352 if (extra
> 0 && rows
-- > 0)
12354 h
= (extra
+ rows
- 1) / rows
;
12357 display_tool_bar_line (&it
, height
+ h
);
12362 while (it
.current_y
< it
.last_visible_y
)
12363 display_tool_bar_line (&it
, 0);
12366 /* It doesn't make much sense to try scrolling in the tool-bar
12367 window, so don't do it. */
12368 w
->desired_matrix
->no_scrolling_p
= true;
12369 w
->must_be_updated_p
= true;
12371 if (!NILP (Vauto_resize_tool_bars
))
12373 bool change_height_p
= true;
12375 /* If we couldn't display everything, change the tool-bar's
12376 height if there is room for more. */
12377 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
12378 change_height_p
= true;
12380 /* We subtract 1 because display_tool_bar_line advances the
12381 glyph_row pointer before returning to its caller. We want to
12382 examine the last glyph row produced by
12383 display_tool_bar_line. */
12384 row
= it
.glyph_row
- 1;
12386 /* If there are blank lines at the end, except for a partially
12387 visible blank line at the end that is smaller than
12388 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12389 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12390 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12391 change_height_p
= true;
12393 /* If row displays tool-bar items, but is partially visible,
12394 change the tool-bar's height. */
12395 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12396 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
12397 change_height_p
= true;
12399 /* Resize windows as needed by changing the `tool-bar-lines'
12400 frame parameter. */
12401 if (change_height_p
)
12404 int new_height
= tool_bar_height (f
, &nrows
, true);
12406 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12407 && !f
->minimize_tool_bar_window_p
)
12408 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12409 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12410 f
->minimize_tool_bar_window_p
= false;
12412 if (change_height_p
)
12414 x_change_tool_bar_height (f
, new_height
);
12415 frame_default_tool_bar_height
= new_height
;
12416 clear_glyph_matrix (w
->desired_matrix
);
12417 f
->n_tool_bar_rows
= nrows
;
12418 f
->fonts_changed
= true;
12425 f
->minimize_tool_bar_window_p
= false;
12428 #endif /* USE_GTK || HAVE_NS */
12431 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12433 /* Get information about the tool-bar item which is displayed in GLYPH
12434 on frame F. Return in *PROP_IDX the index where tool-bar item
12435 properties start in F->tool_bar_items. Value is false if
12436 GLYPH doesn't display a tool-bar item. */
12439 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12444 /* This function can be called asynchronously, which means we must
12445 exclude any possibility that Fget_text_property signals an
12447 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12448 charpos
= max (0, charpos
);
12450 /* Get the text property `menu-item' at pos. The value of that
12451 property is the start index of this item's properties in
12452 F->tool_bar_items. */
12453 prop
= Fget_text_property (make_number (charpos
),
12454 Qmenu_item
, f
->current_tool_bar_string
);
12455 if (! INTEGERP (prop
))
12457 *prop_idx
= XINT (prop
);
12462 /* Get information about the tool-bar item at position X/Y on frame F.
12463 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12464 the current matrix of the tool-bar window of F, or NULL if not
12465 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12466 item in F->tool_bar_items. Value is
12468 -1 if X/Y is not on a tool-bar item
12469 0 if X/Y is on the same item that was highlighted before.
12473 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12474 int *hpos
, int *vpos
, int *prop_idx
)
12476 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12477 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12480 /* Find the glyph under X/Y. */
12481 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12482 if (*glyph
== NULL
)
12485 /* Get the start of this tool-bar item's properties in
12486 f->tool_bar_items. */
12487 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12490 /* Is mouse on the highlighted item? */
12491 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12492 && *vpos
>= hlinfo
->mouse_face_beg_row
12493 && *vpos
<= hlinfo
->mouse_face_end_row
12494 && (*vpos
> hlinfo
->mouse_face_beg_row
12495 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12496 && (*vpos
< hlinfo
->mouse_face_end_row
12497 || *hpos
< hlinfo
->mouse_face_end_col
12498 || hlinfo
->mouse_face_past_end
))
12506 Handle mouse button event on the tool-bar of frame F, at
12507 frame-relative coordinates X/Y. DOWN_P is true for a button press,
12508 false for button release. MODIFIERS is event modifiers for button
12512 handle_tool_bar_click (struct frame
*f
, int x
, int y
, bool down_p
,
12515 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12516 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12517 int hpos
, vpos
, prop_idx
;
12518 struct glyph
*glyph
;
12519 Lisp_Object enabled_p
;
12522 /* If not on the highlighted tool-bar item, and mouse-highlight is
12523 non-nil, return. This is so we generate the tool-bar button
12524 click only when the mouse button is released on the same item as
12525 where it was pressed. However, when mouse-highlight is disabled,
12526 generate the click when the button is released regardless of the
12527 highlight, since tool-bar items are not highlighted in that
12529 frame_to_window_pixel_xy (w
, &x
, &y
);
12530 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12532 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12535 /* When mouse-highlight is off, generate the click for the item
12536 where the button was pressed, disregarding where it was
12538 if (NILP (Vmouse_highlight
) && !down_p
)
12539 prop_idx
= f
->last_tool_bar_item
;
12541 /* If item is disabled, do nothing. */
12542 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12543 if (NILP (enabled_p
))
12548 /* Show item in pressed state. */
12549 if (!NILP (Vmouse_highlight
))
12550 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12551 f
->last_tool_bar_item
= prop_idx
;
12555 Lisp_Object key
, frame
;
12556 struct input_event event
;
12557 EVENT_INIT (event
);
12559 /* Show item in released state. */
12560 if (!NILP (Vmouse_highlight
))
12561 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12563 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12565 XSETFRAME (frame
, f
);
12566 event
.kind
= TOOL_BAR_EVENT
;
12567 event
.frame_or_window
= frame
;
12569 kbd_buffer_store_event (&event
);
12571 event
.kind
= TOOL_BAR_EVENT
;
12572 event
.frame_or_window
= frame
;
12574 event
.modifiers
= modifiers
;
12575 kbd_buffer_store_event (&event
);
12576 f
->last_tool_bar_item
= -1;
12581 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12582 tool-bar window-relative coordinates X/Y. Called from
12583 note_mouse_highlight. */
12586 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12588 Lisp_Object window
= f
->tool_bar_window
;
12589 struct window
*w
= XWINDOW (window
);
12590 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12591 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12593 struct glyph
*glyph
;
12594 struct glyph_row
*row
;
12596 Lisp_Object enabled_p
;
12598 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12602 /* Function note_mouse_highlight is called with negative X/Y
12603 values when mouse moves outside of the frame. */
12604 if (x
<= 0 || y
<= 0)
12606 clear_mouse_face (hlinfo
);
12610 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12613 /* Not on tool-bar item. */
12614 clear_mouse_face (hlinfo
);
12618 /* On same tool-bar item as before. */
12619 goto set_help_echo
;
12621 clear_mouse_face (hlinfo
);
12623 /* Mouse is down, but on different tool-bar item? */
12624 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12625 && f
== dpyinfo
->last_mouse_frame
);
12627 if (mouse_down_p
&& f
->last_tool_bar_item
!= prop_idx
)
12630 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12632 /* If tool-bar item is not enabled, don't highlight it. */
12633 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12634 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12636 /* Compute the x-position of the glyph. In front and past the
12637 image is a space. We include this in the highlighted area. */
12638 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12639 for (i
= x
= 0; i
< hpos
; ++i
)
12640 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12642 /* Record this as the current active region. */
12643 hlinfo
->mouse_face_beg_col
= hpos
;
12644 hlinfo
->mouse_face_beg_row
= vpos
;
12645 hlinfo
->mouse_face_beg_x
= x
;
12646 hlinfo
->mouse_face_past_end
= false;
12648 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12649 hlinfo
->mouse_face_end_row
= vpos
;
12650 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12651 hlinfo
->mouse_face_window
= window
;
12652 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12654 /* Display it as active. */
12655 show_mouse_face (hlinfo
, draw
);
12660 /* Set help_echo_string to a help string to display for this tool-bar item.
12661 XTread_socket does the rest. */
12662 help_echo_object
= help_echo_window
= Qnil
;
12663 help_echo_pos
= -1;
12664 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12665 if (NILP (help_echo_string
))
12666 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12669 #endif /* !USE_GTK && !HAVE_NS */
12671 #endif /* HAVE_WINDOW_SYSTEM */
12675 /************************************************************************
12676 Horizontal scrolling
12677 ************************************************************************/
12679 /* For all leaf windows in the window tree rooted at WINDOW, set their
12680 hscroll value so that PT is (i) visible in the window, and (ii) so
12681 that it is not within a certain margin at the window's left and
12682 right border. Value is true if any window's hscroll has been
12686 hscroll_window_tree (Lisp_Object window
)
12688 bool hscrolled_p
= false;
12689 bool hscroll_relative_p
= FLOATP (Vhscroll_step
);
12690 int hscroll_step_abs
= 0;
12691 double hscroll_step_rel
= 0;
12693 if (hscroll_relative_p
)
12695 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12696 if (hscroll_step_rel
< 0)
12698 hscroll_relative_p
= false;
12699 hscroll_step_abs
= 0;
12702 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12704 hscroll_step_abs
= XINT (Vhscroll_step
);
12705 if (hscroll_step_abs
< 0)
12706 hscroll_step_abs
= 0;
12709 hscroll_step_abs
= 0;
12711 while (WINDOWP (window
))
12713 struct window
*w
= XWINDOW (window
);
12715 if (WINDOWP (w
->contents
))
12716 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12717 else if (w
->cursor
.vpos
>= 0)
12720 int text_area_width
;
12721 struct glyph_row
*cursor_row
;
12722 struct glyph_row
*bottom_row
;
12724 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12725 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12726 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12728 cursor_row
= bottom_row
- 1;
12730 if (!cursor_row
->enabled_p
)
12732 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12733 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12734 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12736 cursor_row
= bottom_row
- 1;
12738 bool row_r2l_p
= cursor_row
->reversed_p
;
12740 text_area_width
= window_box_width (w
, TEXT_AREA
);
12742 /* Scroll when cursor is inside this scroll margin. */
12743 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12745 /* If the position of this window's point has explicitly
12746 changed, no more suspend auto hscrolling. */
12747 if (NILP (Fequal (Fwindow_point (window
), Fwindow_old_point (window
))))
12748 w
->suspend_auto_hscroll
= false;
12750 /* Remember window point. */
12751 Fset_marker (w
->old_pointm
,
12752 ((w
== XWINDOW (selected_window
))
12753 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
12754 : Fmarker_position (w
->pointm
)),
12757 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12758 && !w
->suspend_auto_hscroll
12759 /* In some pathological cases, like restoring a window
12760 configuration into a frame that is much smaller than
12761 the one from which the configuration was saved, we
12762 get glyph rows whose start and end have zero buffer
12763 positions, which we cannot handle below. Just skip
12765 && CHARPOS (cursor_row
->start
.pos
) >= BUF_BEG (w
->contents
)
12766 /* For left-to-right rows, hscroll when cursor is either
12767 (i) inside the right hscroll margin, or (ii) if it is
12768 inside the left margin and the window is already
12771 && ((w
->hscroll
&& w
->cursor
.x
<= h_margin
)
12772 || (cursor_row
->enabled_p
12773 && cursor_row
->truncated_on_right_p
12774 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12775 /* For right-to-left rows, the logic is similar,
12776 except that rules for scrolling to left and right
12777 are reversed. E.g., if cursor.x <= h_margin, we
12778 need to hscroll "to the right" unconditionally,
12779 and that will scroll the screen to the left so as
12780 to reveal the next portion of the row. */
12782 && ((cursor_row
->enabled_p
12783 /* FIXME: It is confusing to set the
12784 truncated_on_right_p flag when R2L rows
12785 are actually truncated on the left. */
12786 && cursor_row
->truncated_on_right_p
12787 && w
->cursor
.x
<= h_margin
)
12789 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12793 struct buffer
*saved_current_buffer
;
12797 /* Find point in a display of infinite width. */
12798 saved_current_buffer
= current_buffer
;
12799 current_buffer
= XBUFFER (w
->contents
);
12801 if (w
== XWINDOW (selected_window
))
12804 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12806 /* Move iterator to pt starting at cursor_row->start in
12807 a line with infinite width. */
12808 init_to_row_start (&it
, w
, cursor_row
);
12809 it
.last_visible_x
= INFINITY
;
12810 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12811 current_buffer
= saved_current_buffer
;
12813 /* Position cursor in window. */
12814 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12815 hscroll
= max (0, (it
.current_x
12816 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12817 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12818 : (text_area_width
/ 2))))
12819 / FRAME_COLUMN_WIDTH (it
.f
);
12820 else if ((!row_r2l_p
12821 && w
->cursor
.x
>= text_area_width
- h_margin
)
12822 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12824 if (hscroll_relative_p
)
12825 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12828 wanted_x
= text_area_width
12829 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12832 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12836 if (hscroll_relative_p
)
12837 wanted_x
= text_area_width
* hscroll_step_rel
12840 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12843 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12845 hscroll
= max (hscroll
, w
->min_hscroll
);
12847 /* Don't prevent redisplay optimizations if hscroll
12848 hasn't changed, as it will unnecessarily slow down
12850 if (w
->hscroll
!= hscroll
)
12852 struct buffer
*b
= XBUFFER (w
->contents
);
12853 b
->prevent_redisplay_optimizations_p
= true;
12854 w
->hscroll
= hscroll
;
12855 hscrolled_p
= true;
12863 /* Value is true if hscroll of any leaf window has been changed. */
12864 return hscrolled_p
;
12868 /* Set hscroll so that cursor is visible and not inside horizontal
12869 scroll margins for all windows in the tree rooted at WINDOW. See
12870 also hscroll_window_tree above. Value is true if any window's
12871 hscroll has been changed. If it has, desired matrices on the frame
12872 of WINDOW are cleared. */
12875 hscroll_windows (Lisp_Object window
)
12877 bool hscrolled_p
= hscroll_window_tree (window
);
12879 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12880 return hscrolled_p
;
12885 /************************************************************************
12887 ************************************************************************/
12889 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined.
12890 This is sometimes handy to have in a debugger session. */
12894 /* First and last unchanged row for try_window_id. */
12896 static int debug_first_unchanged_at_end_vpos
;
12897 static int debug_last_unchanged_at_beg_vpos
;
12899 /* Delta vpos and y. */
12901 static int debug_dvpos
, debug_dy
;
12903 /* Delta in characters and bytes for try_window_id. */
12905 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12907 /* Values of window_end_pos and window_end_vpos at the end of
12910 static ptrdiff_t debug_end_vpos
;
12912 /* Append a string to W->desired_matrix->method. FMT is a printf
12913 format string. If trace_redisplay_p is true also printf the
12914 resulting string to stderr. */
12916 static void debug_method_add (struct window
*, char const *, ...)
12917 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12920 debug_method_add (struct window
*w
, char const *fmt
, ...)
12923 char *method
= w
->desired_matrix
->method
;
12924 int len
= strlen (method
);
12925 int size
= sizeof w
->desired_matrix
->method
;
12926 int remaining
= size
- len
- 1;
12929 if (len
&& remaining
)
12932 --remaining
, ++len
;
12935 va_start (ap
, fmt
);
12936 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12939 if (trace_redisplay_p
)
12940 fprintf (stderr
, "%p (%s): %s\n",
12942 ((BUFFERP (w
->contents
)
12943 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12944 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12949 #endif /* GLYPH_DEBUG */
12952 /* Value is true if all changes in window W, which displays
12953 current_buffer, are in the text between START and END. START is a
12954 buffer position, END is given as a distance from Z. Used in
12955 redisplay_internal for display optimization. */
12958 text_outside_line_unchanged_p (struct window
*w
,
12959 ptrdiff_t start
, ptrdiff_t end
)
12961 bool unchanged_p
= true;
12963 /* If text or overlays have changed, see where. */
12964 if (window_outdated (w
))
12966 /* Gap in the line? */
12967 if (GPT
< start
|| Z
- GPT
< end
)
12968 unchanged_p
= false;
12970 /* Changes start in front of the line, or end after it? */
12972 && (BEG_UNCHANGED
< start
- 1
12973 || END_UNCHANGED
< end
))
12974 unchanged_p
= false;
12976 /* If selective display, can't optimize if changes start at the
12977 beginning of the line. */
12979 && INTEGERP (BVAR (current_buffer
, selective_display
))
12980 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12981 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12982 unchanged_p
= false;
12984 /* If there are overlays at the start or end of the line, these
12985 may have overlay strings with newlines in them. A change at
12986 START, for instance, may actually concern the display of such
12987 overlay strings as well, and they are displayed on different
12988 lines. So, quickly rule out this case. (For the future, it
12989 might be desirable to implement something more telling than
12990 just BEG/END_UNCHANGED.) */
12993 if (BEG
+ BEG_UNCHANGED
== start
12994 && overlay_touches_p (start
))
12995 unchanged_p
= false;
12996 if (END_UNCHANGED
== end
12997 && overlay_touches_p (Z
- end
))
12998 unchanged_p
= false;
13001 /* Under bidi reordering, adding or deleting a character in the
13002 beginning of a paragraph, before the first strong directional
13003 character, can change the base direction of the paragraph (unless
13004 the buffer specifies a fixed paragraph direction), which will
13005 require to redisplay the whole paragraph. It might be worthwhile
13006 to find the paragraph limits and widen the range of redisplayed
13007 lines to that, but for now just give up this optimization. */
13008 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
13009 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
13010 unchanged_p
= false;
13013 return unchanged_p
;
13017 /* Do a frame update, taking possible shortcuts into account. This is
13018 the main external entry point for redisplay.
13020 If the last redisplay displayed an echo area message and that message
13021 is no longer requested, we clear the echo area or bring back the
13022 mini-buffer if that is in use. */
13027 redisplay_internal ();
13032 overlay_arrow_string_or_property (Lisp_Object var
)
13036 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
13039 return Voverlay_arrow_string
;
13042 /* Return true if there are any overlay-arrows in current_buffer. */
13044 overlay_arrow_in_current_buffer_p (void)
13048 for (vlist
= Voverlay_arrow_variable_list
;
13050 vlist
= XCDR (vlist
))
13052 Lisp_Object var
= XCAR (vlist
);
13055 if (!SYMBOLP (var
))
13057 val
= find_symbol_value (var
);
13059 && current_buffer
== XMARKER (val
)->buffer
)
13066 /* Return true if any overlay_arrows have moved or overlay-arrow-string
13070 overlay_arrows_changed_p (void)
13074 for (vlist
= Voverlay_arrow_variable_list
;
13076 vlist
= XCDR (vlist
))
13078 Lisp_Object var
= XCAR (vlist
);
13079 Lisp_Object val
, pstr
;
13081 if (!SYMBOLP (var
))
13083 val
= find_symbol_value (var
);
13084 if (!MARKERP (val
))
13086 if (! EQ (COERCE_MARKER (val
),
13087 Fget (var
, Qlast_arrow_position
))
13088 || ! (pstr
= overlay_arrow_string_or_property (var
),
13089 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
13095 /* Mark overlay arrows to be updated on next redisplay. */
13098 update_overlay_arrows (int up_to_date
)
13102 for (vlist
= Voverlay_arrow_variable_list
;
13104 vlist
= XCDR (vlist
))
13106 Lisp_Object var
= XCAR (vlist
);
13108 if (!SYMBOLP (var
))
13111 if (up_to_date
> 0)
13113 Lisp_Object val
= find_symbol_value (var
);
13114 Fput (var
, Qlast_arrow_position
,
13115 COERCE_MARKER (val
));
13116 Fput (var
, Qlast_arrow_string
,
13117 overlay_arrow_string_or_property (var
));
13119 else if (up_to_date
< 0
13120 || !NILP (Fget (var
, Qlast_arrow_position
)))
13122 Fput (var
, Qlast_arrow_position
, Qt
);
13123 Fput (var
, Qlast_arrow_string
, Qt
);
13129 /* Return overlay arrow string to display at row.
13130 Return integer (bitmap number) for arrow bitmap in left fringe.
13131 Return nil if no overlay arrow. */
13134 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13138 for (vlist
= Voverlay_arrow_variable_list
;
13140 vlist
= XCDR (vlist
))
13142 Lisp_Object var
= XCAR (vlist
);
13145 if (!SYMBOLP (var
))
13148 val
= find_symbol_value (var
);
13151 && current_buffer
== XMARKER (val
)->buffer
13152 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13154 if (FRAME_WINDOW_P (it
->f
)
13155 /* FIXME: if ROW->reversed_p is set, this should test
13156 the right fringe, not the left one. */
13157 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13159 #ifdef HAVE_WINDOW_SYSTEM
13160 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13162 int fringe_bitmap
= lookup_fringe_bitmap (val
);
13163 if (fringe_bitmap
!= 0)
13164 return make_number (fringe_bitmap
);
13167 return make_number (-1); /* Use default arrow bitmap. */
13169 return overlay_arrow_string_or_property (var
);
13176 /* Return true if point moved out of or into a composition. Otherwise
13177 return false. PREV_BUF and PREV_PT are the last point buffer and
13178 position. BUF and PT are the current point buffer and position. */
13181 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13182 struct buffer
*buf
, ptrdiff_t pt
)
13184 ptrdiff_t start
, end
;
13186 Lisp_Object buffer
;
13188 XSETBUFFER (buffer
, buf
);
13189 /* Check a composition at the last point if point moved within the
13191 if (prev_buf
== buf
)
13194 /* Point didn't move. */
13197 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13198 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13199 && composition_valid_p (start
, end
, prop
)
13200 && start
< prev_pt
&& end
> prev_pt
)
13201 /* The last point was within the composition. Return true iff
13202 point moved out of the composition. */
13203 return (pt
<= start
|| pt
>= end
);
13206 /* Check a composition at the current point. */
13207 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13208 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13209 && composition_valid_p (start
, end
, prop
)
13210 && start
< pt
&& end
> pt
);
13213 /* Reconsider the clip changes of buffer which is displayed in W. */
13216 reconsider_clip_changes (struct window
*w
)
13218 struct buffer
*b
= XBUFFER (w
->contents
);
13220 if (b
->clip_changed
13221 && w
->window_end_valid
13222 && w
->current_matrix
->buffer
== b
13223 && w
->current_matrix
->zv
== BUF_ZV (b
)
13224 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13225 b
->clip_changed
= false;
13227 /* If display wasn't paused, and W is not a tool bar window, see if
13228 point has been moved into or out of a composition. In that case,
13229 set b->clip_changed to force updating the screen. If
13230 b->clip_changed has already been set, skip this check. */
13231 if (!b
->clip_changed
&& w
->window_end_valid
)
13233 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13234 ? PT
: marker_position (w
->pointm
));
13236 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13237 && check_point_in_composition (w
->current_matrix
->buffer
,
13238 w
->last_point
, b
, pt
))
13239 b
->clip_changed
= true;
13244 propagate_buffer_redisplay (void)
13245 { /* Resetting b->text->redisplay is problematic!
13246 We can't just reset it in the case that some window that displays
13247 it has not been redisplayed; and such a window can stay
13248 unredisplayed for a long time if it's currently invisible.
13249 But we do want to reset it at the end of redisplay otherwise
13250 its displayed windows will keep being redisplayed over and over
13252 So we copy all b->text->redisplay flags up to their windows here,
13253 such that mark_window_display_accurate can safely reset
13254 b->text->redisplay. */
13255 Lisp_Object ws
= window_list ();
13256 for (; CONSP (ws
); ws
= XCDR (ws
))
13258 struct window
*thisw
= XWINDOW (XCAR (ws
));
13259 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13260 if (thisb
->text
->redisplay
)
13261 thisw
->redisplay
= true;
13265 #define STOP_POLLING \
13266 do { if (! polling_stopped_here) stop_polling (); \
13267 polling_stopped_here = true; } while (false)
13269 #define RESUME_POLLING \
13270 do { if (polling_stopped_here) start_polling (); \
13271 polling_stopped_here = false; } while (false)
13274 /* Perhaps in the future avoid recentering windows if it
13275 is not necessary; currently that causes some problems. */
13278 redisplay_internal (void)
13280 struct window
*w
= XWINDOW (selected_window
);
13284 bool must_finish
= false, match_p
;
13285 struct text_pos tlbufpos
, tlendpos
;
13286 int number_of_visible_frames
;
13289 bool polling_stopped_here
= false;
13290 Lisp_Object tail
, frame
;
13292 /* True means redisplay has to consider all windows on all
13293 frames. False, only selected_window is considered. */
13294 bool consider_all_windows_p
;
13296 /* True means redisplay has to redisplay the miniwindow. */
13297 bool update_miniwindow_p
= false;
13299 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13301 /* No redisplay if running in batch mode or frame is not yet fully
13302 initialized, or redisplay is explicitly turned off by setting
13303 Vinhibit_redisplay. */
13304 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13305 || !NILP (Vinhibit_redisplay
))
13308 /* Don't examine these until after testing Vinhibit_redisplay.
13309 When Emacs is shutting down, perhaps because its connection to
13310 X has dropped, we should not look at them at all. */
13311 fr
= XFRAME (w
->frame
);
13312 sf
= SELECTED_FRAME ();
13314 if (!fr
->glyphs_initialized_p
)
13317 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13318 if (popup_activated ())
13322 /* I don't think this happens but let's be paranoid. */
13323 if (redisplaying_p
)
13326 /* Record a function that clears redisplaying_p
13327 when we leave this function. */
13328 count
= SPECPDL_INDEX ();
13329 record_unwind_protect_void (unwind_redisplay
);
13330 redisplaying_p
= true;
13331 specbind (Qinhibit_free_realized_faces
, Qnil
);
13333 /* Record this function, so it appears on the profiler's backtraces. */
13334 record_in_backtrace (Qredisplay_internal
, 0, 0);
13336 FOR_EACH_FRAME (tail
, frame
)
13337 XFRAME (frame
)->already_hscrolled_p
= false;
13340 /* Remember the currently selected window. */
13344 last_escape_glyph_frame
= NULL
;
13345 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13346 last_glyphless_glyph_frame
= NULL
;
13347 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13349 /* If face_change, init_iterator will free all realized faces, which
13350 includes the faces referenced from current matrices. So, we
13351 can't reuse current matrices in this case. */
13353 windows_or_buffers_changed
= 47;
13355 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13356 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13358 /* Since frames on a single ASCII terminal share the same
13359 display area, displaying a different frame means redisplay
13360 the whole thing. */
13361 SET_FRAME_GARBAGED (sf
);
13363 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13365 FRAME_TTY (sf
)->previous_frame
= sf
;
13368 /* Set the visible flags for all frames. Do this before checking for
13369 resized or garbaged frames; they want to know if their frames are
13370 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13371 number_of_visible_frames
= 0;
13373 FOR_EACH_FRAME (tail
, frame
)
13375 struct frame
*f
= XFRAME (frame
);
13377 if (FRAME_VISIBLE_P (f
))
13379 ++number_of_visible_frames
;
13380 /* Adjust matrices for visible frames only. */
13381 if (f
->fonts_changed
)
13383 adjust_frame_glyphs (f
);
13384 /* Disable all redisplay optimizations for this frame.
13385 This is because adjust_frame_glyphs resets the
13386 enabled_p flag for all glyph rows of all windows, so
13387 many optimizations will fail anyway, and some might
13388 fail to test that flag and do bogus things as
13390 SET_FRAME_GARBAGED (f
);
13391 f
->fonts_changed
= false;
13393 /* If cursor type has been changed on the frame
13394 other than selected, consider all frames. */
13395 if (f
!= sf
&& f
->cursor_type_changed
)
13396 update_mode_lines
= 31;
13398 clear_desired_matrices (f
);
13401 /* Notice any pending interrupt request to change frame size. */
13402 do_pending_window_change (true);
13404 /* do_pending_window_change could change the selected_window due to
13405 frame resizing which makes the selected window too small. */
13406 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13409 /* Clear frames marked as garbaged. */
13410 clear_garbaged_frames ();
13412 /* Build menubar and tool-bar items. */
13413 if (NILP (Vmemory_full
))
13414 prepare_menu_bars ();
13416 reconsider_clip_changes (w
);
13418 /* In most cases selected window displays current buffer. */
13419 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13422 /* Detect case that we need to write or remove a star in the mode line. */
13423 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13424 w
->update_mode_line
= true;
13426 if (mode_line_update_needed (w
))
13427 w
->update_mode_line
= true;
13429 /* If reconsider_clip_changes above decided that the narrowing
13430 in the current buffer changed, make sure all other windows
13431 showing that buffer will be redisplayed. */
13432 if (current_buffer
->clip_changed
)
13433 bset_update_mode_line (current_buffer
);
13436 /* Normally the message* functions will have already displayed and
13437 updated the echo area, but the frame may have been trashed, or
13438 the update may have been preempted, so display the echo area
13439 again here. Checking message_cleared_p captures the case that
13440 the echo area should be cleared. */
13441 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13442 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13443 || (message_cleared_p
13444 && minibuf_level
== 0
13445 /* If the mini-window is currently selected, this means the
13446 echo-area doesn't show through. */
13447 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13449 bool window_height_changed_p
= echo_area_display (false);
13451 if (message_cleared_p
)
13452 update_miniwindow_p
= true;
13454 must_finish
= true;
13456 /* If we don't display the current message, don't clear the
13457 message_cleared_p flag, because, if we did, we wouldn't clear
13458 the echo area in the next redisplay which doesn't preserve
13460 if (!display_last_displayed_message_p
)
13461 message_cleared_p
= false;
13463 if (window_height_changed_p
)
13465 windows_or_buffers_changed
= 50;
13467 /* If window configuration was changed, frames may have been
13468 marked garbaged. Clear them or we will experience
13469 surprises wrt scrolling. */
13470 clear_garbaged_frames ();
13473 else if (EQ (selected_window
, minibuf_window
)
13474 && (current_buffer
->clip_changed
|| window_outdated (w
))
13475 && resize_mini_window (w
, false))
13477 /* Resized active mini-window to fit the size of what it is
13478 showing if its contents might have changed. */
13479 must_finish
= true;
13481 /* If window configuration was changed, frames may have been
13482 marked garbaged. Clear them or we will experience
13483 surprises wrt scrolling. */
13484 clear_garbaged_frames ();
13487 if (windows_or_buffers_changed
&& !update_mode_lines
)
13488 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13489 only the windows's contents needs to be refreshed, or whether the
13490 mode-lines also need a refresh. */
13491 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13492 ? REDISPLAY_SOME
: 32);
13494 /* If specs for an arrow have changed, do thorough redisplay
13495 to ensure we remove any arrow that should no longer exist. */
13496 if (overlay_arrows_changed_p ())
13497 /* Apparently, this is the only case where we update other windows,
13498 without updating other mode-lines. */
13499 windows_or_buffers_changed
= 49;
13501 consider_all_windows_p
= (update_mode_lines
13502 || windows_or_buffers_changed
);
13504 #define AINC(a,i) \
13505 if (VECTORP (a) && i >= 0 && i < ASIZE (a) && INTEGERP (AREF (a, i))) \
13506 ASET (a, i, make_number (1 + XINT (AREF (a, i))))
13508 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13509 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13511 /* Optimize the case that only the line containing the cursor in the
13512 selected window has changed. Variables starting with this_ are
13513 set in display_line and record information about the line
13514 containing the cursor. */
13515 tlbufpos
= this_line_start_pos
;
13516 tlendpos
= this_line_end_pos
;
13517 if (!consider_all_windows_p
13518 && CHARPOS (tlbufpos
) > 0
13519 && !w
->update_mode_line
13520 && !current_buffer
->clip_changed
13521 && !current_buffer
->prevent_redisplay_optimizations_p
13522 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13523 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13524 && !XFRAME (w
->frame
)->cursor_type_changed
13525 /* Make sure recorded data applies to current buffer, etc. */
13526 && this_line_buffer
== current_buffer
13529 && !w
->optional_new_start
13530 /* Point must be on the line that we have info recorded about. */
13531 && PT
>= CHARPOS (tlbufpos
)
13532 && PT
<= Z
- CHARPOS (tlendpos
)
13533 /* All text outside that line, including its final newline,
13534 must be unchanged. */
13535 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13536 CHARPOS (tlendpos
)))
13538 if (CHARPOS (tlbufpos
) > BEGV
13539 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13540 && (CHARPOS (tlbufpos
) == ZV
13541 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13542 /* Former continuation line has disappeared by becoming empty. */
13544 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13546 /* We have to handle the case of continuation around a
13547 wide-column character (see the comment in indent.c around
13550 For instance, in the following case:
13552 -------- Insert --------
13553 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13554 J_I_ ==> J_I_ `^^' are cursors.
13558 As we have to redraw the line above, we cannot use this
13562 int line_height_before
= this_line_pixel_height
;
13564 /* Note that start_display will handle the case that the
13565 line starting at tlbufpos is a continuation line. */
13566 start_display (&it
, w
, tlbufpos
);
13568 /* Implementation note: It this still necessary? */
13569 if (it
.current_x
!= this_line_start_x
)
13572 TRACE ((stderr
, "trying display optimization 1\n"));
13573 w
->cursor
.vpos
= -1;
13574 overlay_arrow_seen
= false;
13575 it
.vpos
= this_line_vpos
;
13576 it
.current_y
= this_line_y
;
13577 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13578 display_line (&it
);
13580 /* If line contains point, is not continued,
13581 and ends at same distance from eob as before, we win. */
13582 if (w
->cursor
.vpos
>= 0
13583 /* Line is not continued, otherwise this_line_start_pos
13584 would have been set to 0 in display_line. */
13585 && CHARPOS (this_line_start_pos
)
13586 /* Line ends as before. */
13587 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13588 /* Line has same height as before. Otherwise other lines
13589 would have to be shifted up or down. */
13590 && this_line_pixel_height
== line_height_before
)
13592 /* If this is not the window's last line, we must adjust
13593 the charstarts of the lines below. */
13594 if (it
.current_y
< it
.last_visible_y
)
13596 struct glyph_row
*row
13597 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13598 ptrdiff_t delta
, delta_bytes
;
13600 /* We used to distinguish between two cases here,
13601 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13602 when the line ends in a newline or the end of the
13603 buffer's accessible portion. But both cases did
13604 the same, so they were collapsed. */
13606 - CHARPOS (tlendpos
)
13607 - MATRIX_ROW_START_CHARPOS (row
));
13608 delta_bytes
= (Z_BYTE
13609 - BYTEPOS (tlendpos
)
13610 - MATRIX_ROW_START_BYTEPOS (row
));
13612 increment_matrix_positions (w
->current_matrix
,
13613 this_line_vpos
+ 1,
13614 w
->current_matrix
->nrows
,
13615 delta
, delta_bytes
);
13618 /* If this row displays text now but previously didn't,
13619 or vice versa, w->window_end_vpos may have to be
13621 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13623 if (w
->window_end_vpos
< this_line_vpos
)
13624 w
->window_end_vpos
= this_line_vpos
;
13626 else if (w
->window_end_vpos
== this_line_vpos
13627 && this_line_vpos
> 0)
13628 w
->window_end_vpos
= this_line_vpos
- 1;
13629 w
->window_end_valid
= false;
13631 /* Update hint: No need to try to scroll in update_window. */
13632 w
->desired_matrix
->no_scrolling_p
= true;
13635 *w
->desired_matrix
->method
= 0;
13636 debug_method_add (w
, "optimization 1");
13638 #ifdef HAVE_WINDOW_SYSTEM
13639 update_window_fringes (w
, false);
13646 else if (/* Cursor position hasn't changed. */
13647 PT
== w
->last_point
13648 /* Make sure the cursor was last displayed
13649 in this window. Otherwise we have to reposition it. */
13651 /* PXW: Must be converted to pixels, probably. */
13652 && 0 <= w
->cursor
.vpos
13653 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13657 do_pending_window_change (true);
13658 /* If selected_window changed, redisplay again. */
13659 if (WINDOWP (selected_window
)
13660 && (w
= XWINDOW (selected_window
)) != sw
)
13663 /* We used to always goto end_of_redisplay here, but this
13664 isn't enough if we have a blinking cursor. */
13665 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13666 goto end_of_redisplay
;
13670 /* If highlighting the region, or if the cursor is in the echo area,
13671 then we can't just move the cursor. */
13672 else if (NILP (Vshow_trailing_whitespace
)
13673 && !cursor_in_echo_area
)
13676 struct glyph_row
*row
;
13678 /* Skip from tlbufpos to PT and see where it is. Note that
13679 PT may be in invisible text. If so, we will end at the
13680 next visible position. */
13681 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13682 NULL
, DEFAULT_FACE_ID
);
13683 it
.current_x
= this_line_start_x
;
13684 it
.current_y
= this_line_y
;
13685 it
.vpos
= this_line_vpos
;
13687 /* The call to move_it_to stops in front of PT, but
13688 moves over before-strings. */
13689 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13691 if (it
.vpos
== this_line_vpos
13692 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13695 eassert (this_line_vpos
== it
.vpos
);
13696 eassert (this_line_y
== it
.current_y
);
13697 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13699 *w
->desired_matrix
->method
= 0;
13700 debug_method_add (w
, "optimization 3");
13709 /* Text changed drastically or point moved off of line. */
13710 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13713 CHARPOS (this_line_start_pos
) = 0;
13714 ++clear_face_cache_count
;
13715 #ifdef HAVE_WINDOW_SYSTEM
13716 ++clear_image_cache_count
;
13719 /* Build desired matrices, and update the display. If
13720 consider_all_windows_p, do it for all windows on all frames.
13721 Otherwise do it for selected_window, only. */
13723 if (consider_all_windows_p
)
13725 FOR_EACH_FRAME (tail
, frame
)
13726 XFRAME (frame
)->updated_p
= false;
13728 propagate_buffer_redisplay ();
13730 FOR_EACH_FRAME (tail
, frame
)
13732 struct frame
*f
= XFRAME (frame
);
13734 /* We don't have to do anything for unselected terminal
13736 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13737 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13742 #if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_GTK) && !defined (HAVE_NS)
13743 /* Redisplay internal tool bar if this is the first time so we
13744 can adjust the frame height right now, if necessary. */
13745 if (!f
->tool_bar_redisplayed_once
)
13747 if (redisplay_tool_bar (f
))
13748 adjust_frame_glyphs (f
);
13749 f
->tool_bar_redisplayed_once
= true;
13753 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13756 /* Only GC scrollbars when we redisplay the whole frame. */
13757 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13758 /* Mark all the scroll bars to be removed; we'll redeem
13759 the ones we want when we redisplay their windows. */
13760 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13761 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13763 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13764 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13765 /* Remember that the invisible frames need to be redisplayed next
13766 time they're visible. */
13767 else if (!REDISPLAY_SOME_P ())
13768 f
->redisplay
= true;
13770 /* The X error handler may have deleted that frame. */
13771 if (!FRAME_LIVE_P (f
))
13774 /* Any scroll bars which redisplay_windows should have
13775 nuked should now go away. */
13776 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13777 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13779 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13781 /* If fonts changed on visible frame, display again. */
13782 if (f
->fonts_changed
)
13784 adjust_frame_glyphs (f
);
13785 /* Disable all redisplay optimizations for this
13786 frame. For the reasons, see the comment near
13787 the previous call to adjust_frame_glyphs above. */
13788 SET_FRAME_GARBAGED (f
);
13789 f
->fonts_changed
= false;
13793 /* See if we have to hscroll. */
13794 if (!f
->already_hscrolled_p
)
13796 f
->already_hscrolled_p
= true;
13797 if (hscroll_windows (f
->root_window
))
13801 /* Prevent various kinds of signals during display
13802 update. stdio is not robust about handling
13803 signals, which can cause an apparent I/O error. */
13804 if (interrupt_input
)
13805 unrequest_sigio ();
13808 pending
|= update_frame (f
, false, false);
13809 f
->cursor_type_changed
= false;
13810 f
->updated_p
= true;
13815 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13819 /* Do the mark_window_display_accurate after all windows have
13820 been redisplayed because this call resets flags in buffers
13821 which are needed for proper redisplay. */
13822 FOR_EACH_FRAME (tail
, frame
)
13824 struct frame
*f
= XFRAME (frame
);
13827 f
->redisplay
= false;
13828 mark_window_display_accurate (f
->root_window
, true);
13829 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13830 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13835 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13837 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13838 struct frame
*mini_frame
;
13840 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13841 /* Use list_of_error, not Qerror, so that
13842 we catch only errors and don't run the debugger. */
13843 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13845 redisplay_window_error
);
13846 if (update_miniwindow_p
)
13847 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13849 redisplay_window_error
);
13851 /* Compare desired and current matrices, perform output. */
13854 /* If fonts changed, display again. */
13855 if (sf
->fonts_changed
)
13858 /* Prevent various kinds of signals during display update.
13859 stdio is not robust about handling signals,
13860 which can cause an apparent I/O error. */
13861 if (interrupt_input
)
13862 unrequest_sigio ();
13865 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13867 if (hscroll_windows (selected_window
))
13870 XWINDOW (selected_window
)->must_be_updated_p
= true;
13871 pending
= update_frame (sf
, false, false);
13872 sf
->cursor_type_changed
= false;
13875 /* We may have called echo_area_display at the top of this
13876 function. If the echo area is on another frame, that may
13877 have put text on a frame other than the selected one, so the
13878 above call to update_frame would not have caught it. Catch
13880 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13881 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13883 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13885 XWINDOW (mini_window
)->must_be_updated_p
= true;
13886 pending
|= update_frame (mini_frame
, false, false);
13887 mini_frame
->cursor_type_changed
= false;
13888 if (!pending
&& hscroll_windows (mini_window
))
13893 /* If display was paused because of pending input, make sure we do a
13894 thorough update the next time. */
13897 /* Prevent the optimization at the beginning of
13898 redisplay_internal that tries a single-line update of the
13899 line containing the cursor in the selected window. */
13900 CHARPOS (this_line_start_pos
) = 0;
13902 /* Let the overlay arrow be updated the next time. */
13903 update_overlay_arrows (0);
13905 /* If we pause after scrolling, some rows in the current
13906 matrices of some windows are not valid. */
13907 if (!WINDOW_FULL_WIDTH_P (w
)
13908 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13909 update_mode_lines
= 36;
13913 if (!consider_all_windows_p
)
13915 /* This has already been done above if
13916 consider_all_windows_p is set. */
13917 if (XBUFFER (w
->contents
)->text
->redisplay
13918 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13919 /* This can happen if b->text->redisplay was set during
13921 propagate_buffer_redisplay ();
13922 mark_window_display_accurate_1 (w
, true);
13924 /* Say overlay arrows are up to date. */
13925 update_overlay_arrows (1);
13927 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13928 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13931 update_mode_lines
= 0;
13932 windows_or_buffers_changed
= 0;
13935 /* Start SIGIO interrupts coming again. Having them off during the
13936 code above makes it less likely one will discard output, but not
13937 impossible, since there might be stuff in the system buffer here.
13938 But it is much hairier to try to do anything about that. */
13939 if (interrupt_input
)
13943 /* If a frame has become visible which was not before, redisplay
13944 again, so that we display it. Expose events for such a frame
13945 (which it gets when becoming visible) don't call the parts of
13946 redisplay constructing glyphs, so simply exposing a frame won't
13947 display anything in this case. So, we have to display these
13948 frames here explicitly. */
13953 FOR_EACH_FRAME (tail
, frame
)
13955 if (XFRAME (frame
)->visible
)
13959 if (new_count
!= number_of_visible_frames
)
13960 windows_or_buffers_changed
= 52;
13963 /* Change frame size now if a change is pending. */
13964 do_pending_window_change (true);
13966 /* If we just did a pending size change, or have additional
13967 visible frames, or selected_window changed, redisplay again. */
13968 if ((windows_or_buffers_changed
&& !pending
)
13969 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13972 /* Clear the face and image caches.
13974 We used to do this only if consider_all_windows_p. But the cache
13975 needs to be cleared if a timer creates images in the current
13976 buffer (e.g. the test case in Bug#6230). */
13978 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13980 clear_face_cache (false);
13981 clear_face_cache_count
= 0;
13984 #ifdef HAVE_WINDOW_SYSTEM
13985 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13987 clear_image_caches (Qnil
);
13988 clear_image_cache_count
= 0;
13990 #endif /* HAVE_WINDOW_SYSTEM */
13994 ns_set_doc_edited ();
13996 if (interrupt_input
&& interrupts_deferred
)
13999 unbind_to (count
, Qnil
);
14004 /* Redisplay, but leave alone any recent echo area message unless
14005 another message has been requested in its place.
14007 This is useful in situations where you need to redisplay but no
14008 user action has occurred, making it inappropriate for the message
14009 area to be cleared. See tracking_off and
14010 wait_reading_process_output for examples of these situations.
14012 FROM_WHERE is an integer saying from where this function was
14013 called. This is useful for debugging. */
14016 redisplay_preserve_echo_area (int from_where
)
14018 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
14020 if (!NILP (echo_area_buffer
[1]))
14022 /* We have a previously displayed message, but no current
14023 message. Redisplay the previous message. */
14024 display_last_displayed_message_p
= true;
14025 redisplay_internal ();
14026 display_last_displayed_message_p
= false;
14029 redisplay_internal ();
14031 flush_frame (SELECTED_FRAME ());
14035 /* Function registered with record_unwind_protect in redisplay_internal. */
14038 unwind_redisplay (void)
14040 redisplaying_p
= false;
14044 /* Mark the display of leaf window W as accurate or inaccurate.
14045 If ACCURATE_P, mark display of W as accurate.
14046 If !ACCURATE_P, arrange for W to be redisplayed the next
14047 time redisplay_internal is called. */
14050 mark_window_display_accurate_1 (struct window
*w
, bool accurate_p
)
14052 struct buffer
*b
= XBUFFER (w
->contents
);
14054 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
14055 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
14056 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
14060 b
->clip_changed
= false;
14061 b
->prevent_redisplay_optimizations_p
= false;
14062 eassert (buffer_window_count (b
) > 0);
14063 /* Resetting b->text->redisplay is problematic!
14064 In order to make it safer to do it here, redisplay_internal must
14065 have copied all b->text->redisplay to their respective windows. */
14066 b
->text
->redisplay
= false;
14068 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
14069 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
14070 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
14071 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
14073 w
->current_matrix
->buffer
= b
;
14074 w
->current_matrix
->begv
= BUF_BEGV (b
);
14075 w
->current_matrix
->zv
= BUF_ZV (b
);
14077 w
->last_cursor_vpos
= w
->cursor
.vpos
;
14078 w
->last_cursor_off_p
= w
->cursor_off_p
;
14080 if (w
== XWINDOW (selected_window
))
14081 w
->last_point
= BUF_PT (b
);
14083 w
->last_point
= marker_position (w
->pointm
);
14085 w
->window_end_valid
= true;
14086 w
->update_mode_line
= false;
14089 w
->redisplay
= !accurate_p
;
14093 /* Mark the display of windows in the window tree rooted at WINDOW as
14094 accurate or inaccurate. If ACCURATE_P, mark display of
14095 windows as accurate. If !ACCURATE_P, arrange for windows to
14096 be redisplayed the next time redisplay_internal is called. */
14099 mark_window_display_accurate (Lisp_Object window
, bool accurate_p
)
14103 for (; !NILP (window
); window
= w
->next
)
14105 w
= XWINDOW (window
);
14106 if (WINDOWP (w
->contents
))
14107 mark_window_display_accurate (w
->contents
, accurate_p
);
14109 mark_window_display_accurate_1 (w
, accurate_p
);
14113 update_overlay_arrows (1);
14115 /* Force a thorough redisplay the next time by setting
14116 last_arrow_position and last_arrow_string to t, which is
14117 unequal to any useful value of Voverlay_arrow_... */
14118 update_overlay_arrows (-1);
14122 /* Return value in display table DP (Lisp_Char_Table *) for character
14123 C. Since a display table doesn't have any parent, we don't have to
14124 follow parent. Do not call this function directly but use the
14125 macro DISP_CHAR_VECTOR. */
14128 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
14132 if (ASCII_CHAR_P (c
))
14135 if (SUB_CHAR_TABLE_P (val
))
14136 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14142 XSETCHAR_TABLE (table
, dp
);
14143 val
= char_table_ref (table
, c
);
14152 /***********************************************************************
14154 ***********************************************************************/
14156 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14159 redisplay_windows (Lisp_Object window
)
14161 while (!NILP (window
))
14163 struct window
*w
= XWINDOW (window
);
14165 if (WINDOWP (w
->contents
))
14166 redisplay_windows (w
->contents
);
14167 else if (BUFFERP (w
->contents
))
14169 displayed_buffer
= XBUFFER (w
->contents
);
14170 /* Use list_of_error, not Qerror, so that
14171 we catch only errors and don't run the debugger. */
14172 internal_condition_case_1 (redisplay_window_0
, window
,
14174 redisplay_window_error
);
14182 redisplay_window_error (Lisp_Object ignore
)
14184 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14189 redisplay_window_0 (Lisp_Object window
)
14191 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14192 redisplay_window (window
, false);
14197 redisplay_window_1 (Lisp_Object window
)
14199 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14200 redisplay_window (window
, true);
14205 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14206 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14207 which positions recorded in ROW differ from current buffer
14210 Return true iff cursor is on this row. */
14213 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14214 struct glyph_matrix
*matrix
,
14215 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14218 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14219 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14220 struct glyph
*cursor
= NULL
;
14221 /* The last known character position in row. */
14222 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14224 ptrdiff_t pt_old
= PT
- delta
;
14225 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14226 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14227 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14228 /* A glyph beyond the edge of TEXT_AREA which we should never
14230 struct glyph
*glyphs_end
= end
;
14231 /* True means we've found a match for cursor position, but that
14232 glyph has the avoid_cursor_p flag set. */
14233 bool match_with_avoid_cursor
= false;
14234 /* True means we've seen at least one glyph that came from a
14236 bool string_seen
= false;
14237 /* Largest and smallest buffer positions seen so far during scan of
14239 ptrdiff_t bpos_max
= pos_before
;
14240 ptrdiff_t bpos_min
= pos_after
;
14241 /* Last buffer position covered by an overlay string with an integer
14242 `cursor' property. */
14243 ptrdiff_t bpos_covered
= 0;
14244 /* True means the display string on which to display the cursor
14245 comes from a text property, not from an overlay. */
14246 bool string_from_text_prop
= false;
14248 /* Don't even try doing anything if called for a mode-line or
14249 header-line row, since the rest of the code isn't prepared to
14250 deal with such calamities. */
14251 eassert (!row
->mode_line_p
);
14252 if (row
->mode_line_p
)
14255 /* Skip over glyphs not having an object at the start and the end of
14256 the row. These are special glyphs like truncation marks on
14257 terminal frames. */
14258 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14260 if (!row
->reversed_p
)
14263 && NILP (glyph
->object
)
14264 && glyph
->charpos
< 0)
14266 x
+= glyph
->pixel_width
;
14270 && NILP ((end
- 1)->object
)
14271 /* CHARPOS is zero for blanks and stretch glyphs
14272 inserted by extend_face_to_end_of_line. */
14273 && (end
- 1)->charpos
<= 0)
14275 glyph_before
= glyph
- 1;
14282 /* If the glyph row is reversed, we need to process it from back
14283 to front, so swap the edge pointers. */
14284 glyphs_end
= end
= glyph
- 1;
14285 glyph
+= row
->used
[TEXT_AREA
] - 1;
14287 while (glyph
> end
+ 1
14288 && NILP (glyph
->object
)
14289 && glyph
->charpos
< 0)
14292 x
-= glyph
->pixel_width
;
14294 if (NILP (glyph
->object
) && glyph
->charpos
< 0)
14296 /* By default, in reversed rows we put the cursor on the
14297 rightmost (first in the reading order) glyph. */
14298 for (g
= end
+ 1; g
< glyph
; g
++)
14299 x
+= g
->pixel_width
;
14301 && NILP ((end
+ 1)->object
)
14302 && (end
+ 1)->charpos
<= 0)
14304 glyph_before
= glyph
+ 1;
14308 else if (row
->reversed_p
)
14310 /* In R2L rows that don't display text, put the cursor on the
14311 rightmost glyph. Case in point: an empty last line that is
14312 part of an R2L paragraph. */
14314 /* Avoid placing the cursor on the last glyph of the row, where
14315 on terminal frames we hold the vertical border between
14316 adjacent windows. */
14317 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14318 && !WINDOW_RIGHTMOST_P (w
)
14319 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14321 x
= -1; /* will be computed below, at label compute_x */
14324 /* Step 1: Try to find the glyph whose character position
14325 corresponds to point. If that's not possible, find 2 glyphs
14326 whose character positions are the closest to point, one before
14327 point, the other after it. */
14328 if (!row
->reversed_p
)
14329 while (/* not marched to end of glyph row */
14331 /* glyph was not inserted by redisplay for internal purposes */
14332 && !NILP (glyph
->object
))
14334 if (BUFFERP (glyph
->object
))
14336 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14338 if (glyph
->charpos
> bpos_max
)
14339 bpos_max
= glyph
->charpos
;
14340 if (glyph
->charpos
< bpos_min
)
14341 bpos_min
= glyph
->charpos
;
14342 if (!glyph
->avoid_cursor_p
)
14344 /* If we hit point, we've found the glyph on which to
14345 display the cursor. */
14348 match_with_avoid_cursor
= false;
14351 /* See if we've found a better approximation to
14352 POS_BEFORE or to POS_AFTER. */
14353 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14355 pos_before
= glyph
->charpos
;
14356 glyph_before
= glyph
;
14358 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14360 pos_after
= glyph
->charpos
;
14361 glyph_after
= glyph
;
14364 else if (dpos
== 0)
14365 match_with_avoid_cursor
= true;
14367 else if (STRINGP (glyph
->object
))
14369 Lisp_Object chprop
;
14370 ptrdiff_t glyph_pos
= glyph
->charpos
;
14372 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14374 if (!NILP (chprop
))
14376 /* If the string came from a `display' text property,
14377 look up the buffer position of that property and
14378 use that position to update bpos_max, as if we
14379 actually saw such a position in one of the row's
14380 glyphs. This helps with supporting integer values
14381 of `cursor' property on the display string in
14382 situations where most or all of the row's buffer
14383 text is completely covered by display properties,
14384 so that no glyph with valid buffer positions is
14385 ever seen in the row. */
14386 ptrdiff_t prop_pos
=
14387 string_buffer_position_lim (glyph
->object
, pos_before
,
14390 if (prop_pos
>= pos_before
)
14391 bpos_max
= prop_pos
;
14393 if (INTEGERP (chprop
))
14395 bpos_covered
= bpos_max
+ XINT (chprop
);
14396 /* If the `cursor' property covers buffer positions up
14397 to and including point, we should display cursor on
14398 this glyph. Note that, if a `cursor' property on one
14399 of the string's characters has an integer value, we
14400 will break out of the loop below _before_ we get to
14401 the position match above. IOW, integer values of
14402 the `cursor' property override the "exact match for
14403 point" strategy of positioning the cursor. */
14404 /* Implementation note: bpos_max == pt_old when, e.g.,
14405 we are in an empty line, where bpos_max is set to
14406 MATRIX_ROW_START_CHARPOS, see above. */
14407 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14414 string_seen
= true;
14416 x
+= glyph
->pixel_width
;
14419 else if (glyph
> end
) /* row is reversed */
14420 while (!NILP (glyph
->object
))
14422 if (BUFFERP (glyph
->object
))
14424 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14426 if (glyph
->charpos
> bpos_max
)
14427 bpos_max
= glyph
->charpos
;
14428 if (glyph
->charpos
< bpos_min
)
14429 bpos_min
= glyph
->charpos
;
14430 if (!glyph
->avoid_cursor_p
)
14434 match_with_avoid_cursor
= false;
14437 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14439 pos_before
= glyph
->charpos
;
14440 glyph_before
= glyph
;
14442 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14444 pos_after
= glyph
->charpos
;
14445 glyph_after
= glyph
;
14448 else if (dpos
== 0)
14449 match_with_avoid_cursor
= true;
14451 else if (STRINGP (glyph
->object
))
14453 Lisp_Object chprop
;
14454 ptrdiff_t glyph_pos
= glyph
->charpos
;
14456 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14458 if (!NILP (chprop
))
14460 ptrdiff_t prop_pos
=
14461 string_buffer_position_lim (glyph
->object
, pos_before
,
14464 if (prop_pos
>= pos_before
)
14465 bpos_max
= prop_pos
;
14467 if (INTEGERP (chprop
))
14469 bpos_covered
= bpos_max
+ XINT (chprop
);
14470 /* If the `cursor' property covers buffer positions up
14471 to and including point, we should display cursor on
14473 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14479 string_seen
= true;
14482 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14484 x
--; /* can't use any pixel_width */
14487 x
-= glyph
->pixel_width
;
14490 /* Step 2: If we didn't find an exact match for point, we need to
14491 look for a proper place to put the cursor among glyphs between
14492 GLYPH_BEFORE and GLYPH_AFTER. */
14493 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14494 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14495 && !(bpos_max
<= pt_old
&& pt_old
<= bpos_covered
))
14497 /* An empty line has a single glyph whose OBJECT is nil and
14498 whose CHARPOS is the position of a newline on that line.
14499 Note that on a TTY, there are more glyphs after that, which
14500 were produced by extend_face_to_end_of_line, but their
14501 CHARPOS is zero or negative. */
14502 bool empty_line_p
=
14503 ((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14504 && NILP (glyph
->object
) && glyph
->charpos
> 0
14505 /* On a TTY, continued and truncated rows also have a glyph at
14506 their end whose OBJECT is nil and whose CHARPOS is
14507 positive (the continuation and truncation glyphs), but such
14508 rows are obviously not "empty". */
14509 && !(row
->continued_p
|| row
->truncated_on_right_p
));
14511 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14513 ptrdiff_t ellipsis_pos
;
14515 /* Scan back over the ellipsis glyphs. */
14516 if (!row
->reversed_p
)
14518 ellipsis_pos
= (glyph
- 1)->charpos
;
14519 while (glyph
> row
->glyphs
[TEXT_AREA
]
14520 && (glyph
- 1)->charpos
== ellipsis_pos
)
14521 glyph
--, x
-= glyph
->pixel_width
;
14522 /* That loop always goes one position too far, including
14523 the glyph before the ellipsis. So scan forward over
14525 x
+= glyph
->pixel_width
;
14528 else /* row is reversed */
14530 ellipsis_pos
= (glyph
+ 1)->charpos
;
14531 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14532 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14533 glyph
++, x
+= glyph
->pixel_width
;
14534 x
-= glyph
->pixel_width
;
14538 else if (match_with_avoid_cursor
)
14540 cursor
= glyph_after
;
14543 else if (string_seen
)
14545 int incr
= row
->reversed_p
? -1 : +1;
14547 /* Need to find the glyph that came out of a string which is
14548 present at point. That glyph is somewhere between
14549 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14550 positioned between POS_BEFORE and POS_AFTER in the
14552 struct glyph
*start
, *stop
;
14553 ptrdiff_t pos
= pos_before
;
14557 /* If the row ends in a newline from a display string,
14558 reordering could have moved the glyphs belonging to the
14559 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14560 in this case we extend the search to the last glyph in
14561 the row that was not inserted by redisplay. */
14562 if (row
->ends_in_newline_from_string_p
)
14565 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14568 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14569 correspond to POS_BEFORE and POS_AFTER, respectively. We
14570 need START and STOP in the order that corresponds to the
14571 row's direction as given by its reversed_p flag. If the
14572 directionality of characters between POS_BEFORE and
14573 POS_AFTER is the opposite of the row's base direction,
14574 these characters will have been reordered for display,
14575 and we need to reverse START and STOP. */
14576 if (!row
->reversed_p
)
14578 start
= min (glyph_before
, glyph_after
);
14579 stop
= max (glyph_before
, glyph_after
);
14583 start
= max (glyph_before
, glyph_after
);
14584 stop
= min (glyph_before
, glyph_after
);
14586 for (glyph
= start
+ incr
;
14587 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14590 /* Any glyphs that come from the buffer are here because
14591 of bidi reordering. Skip them, and only pay
14592 attention to glyphs that came from some string. */
14593 if (STRINGP (glyph
->object
))
14597 /* If the display property covers the newline, we
14598 need to search for it one position farther. */
14599 ptrdiff_t lim
= pos_after
14600 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14602 string_from_text_prop
= false;
14603 str
= glyph
->object
;
14604 tem
= string_buffer_position_lim (str
, pos
, lim
, false);
14605 if (tem
== 0 /* from overlay */
14608 /* If the string from which this glyph came is
14609 found in the buffer at point, or at position
14610 that is closer to point than pos_after, then
14611 we've found the glyph we've been looking for.
14612 If it comes from an overlay (tem == 0), and
14613 it has the `cursor' property on one of its
14614 glyphs, record that glyph as a candidate for
14615 displaying the cursor. (As in the
14616 unidirectional version, we will display the
14617 cursor on the last candidate we find.) */
14620 || (tem
- pt_old
> 0 && tem
< pos_after
))
14622 /* The glyphs from this string could have
14623 been reordered. Find the one with the
14624 smallest string position. Or there could
14625 be a character in the string with the
14626 `cursor' property, which means display
14627 cursor on that character's glyph. */
14628 ptrdiff_t strpos
= glyph
->charpos
;
14633 string_from_text_prop
= true;
14636 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14637 && EQ (glyph
->object
, str
);
14641 ptrdiff_t gpos
= glyph
->charpos
;
14643 cprop
= Fget_char_property (make_number (gpos
),
14651 if (tem
&& glyph
->charpos
< strpos
)
14653 strpos
= glyph
->charpos
;
14659 || (tem
- pt_old
> 0 && tem
< pos_after
))
14663 pos
= tem
+ 1; /* don't find previous instances */
14665 /* This string is not what we want; skip all of the
14666 glyphs that came from it. */
14667 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14668 && EQ (glyph
->object
, str
))
14675 /* If we reached the end of the line, and END was from a string,
14676 the cursor is not on this line. */
14678 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14679 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14680 && STRINGP (end
->object
)
14681 && row
->continued_p
)
14684 /* A truncated row may not include PT among its character positions.
14685 Setting the cursor inside the scroll margin will trigger
14686 recalculation of hscroll in hscroll_window_tree. But if a
14687 display string covers point, defer to the string-handling
14688 code below to figure this out. */
14689 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14691 cursor
= glyph_before
;
14694 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14695 /* Zero-width characters produce no glyphs. */
14697 && (row
->reversed_p
14698 ? glyph_after
> glyphs_end
14699 : glyph_after
< glyphs_end
)))
14701 cursor
= glyph_after
;
14707 if (cursor
!= NULL
)
14709 else if (glyph
== glyphs_end
14710 && pos_before
== pos_after
14711 && STRINGP ((row
->reversed_p
14712 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14713 : row
->glyphs
[TEXT_AREA
])->object
))
14715 /* If all the glyphs of this row came from strings, put the
14716 cursor on the first glyph of the row. This avoids having the
14717 cursor outside of the text area in this very rare and hard
14721 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14722 : row
->glyphs
[TEXT_AREA
];
14728 /* Need to compute x that corresponds to GLYPH. */
14729 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14731 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14733 x
+= g
->pixel_width
;
14737 /* ROW could be part of a continued line, which, under bidi
14738 reordering, might have other rows whose start and end charpos
14739 occlude point. Only set w->cursor if we found a better
14740 approximation to the cursor position than we have from previously
14741 examined candidate rows belonging to the same continued line. */
14742 if (/* We already have a candidate row. */
14743 w
->cursor
.vpos
>= 0
14744 /* That candidate is not the row we are processing. */
14745 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14746 /* Make sure cursor.vpos specifies a row whose start and end
14747 charpos occlude point, and it is valid candidate for being a
14748 cursor-row. This is because some callers of this function
14749 leave cursor.vpos at the row where the cursor was displayed
14750 during the last redisplay cycle. */
14751 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14752 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14753 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14756 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14758 /* Don't consider glyphs that are outside TEXT_AREA. */
14759 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14761 /* Keep the candidate whose buffer position is the closest to
14762 point or has the `cursor' property. */
14763 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14764 w
->cursor
.hpos
>= 0
14765 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14766 && ((BUFFERP (g1
->object
)
14767 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14768 || (BUFFERP (glyph
->object
)
14769 && eabs (g1
->charpos
- pt_old
)
14770 < eabs (glyph
->charpos
- pt_old
))))
14771 /* Previous candidate is a glyph from a string that has
14772 a non-nil `cursor' property. */
14773 || (STRINGP (g1
->object
)
14774 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14775 Qcursor
, g1
->object
))
14776 /* Previous candidate is from the same display
14777 string as this one, and the display string
14778 came from a text property. */
14779 || (EQ (g1
->object
, glyph
->object
)
14780 && string_from_text_prop
)
14781 /* this candidate is from newline and its
14782 position is not an exact match */
14783 || (NILP (glyph
->object
)
14784 && glyph
->charpos
!= pt_old
)))))
14786 /* If this candidate gives an exact match, use that. */
14787 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14788 /* If this candidate is a glyph created for the
14789 terminating newline of a line, and point is on that
14790 newline, it wins because it's an exact match. */
14791 || (!row
->continued_p
14792 && NILP (glyph
->object
)
14793 && glyph
->charpos
== 0
14794 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14795 /* Otherwise, keep the candidate that comes from a row
14796 spanning less buffer positions. This may win when one or
14797 both candidate positions are on glyphs that came from
14798 display strings, for which we cannot compare buffer
14800 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14801 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14802 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14805 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14807 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14808 w
->cursor
.y
= row
->y
+ dy
;
14810 if (w
== XWINDOW (selected_window
))
14812 if (!row
->continued_p
14813 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14816 this_line_buffer
= XBUFFER (w
->contents
);
14818 CHARPOS (this_line_start_pos
)
14819 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14820 BYTEPOS (this_line_start_pos
)
14821 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14823 CHARPOS (this_line_end_pos
)
14824 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14825 BYTEPOS (this_line_end_pos
)
14826 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14828 this_line_y
= w
->cursor
.y
;
14829 this_line_pixel_height
= row
->height
;
14830 this_line_vpos
= w
->cursor
.vpos
;
14831 this_line_start_x
= row
->x
;
14834 CHARPOS (this_line_start_pos
) = 0;
14841 /* Run window scroll functions, if any, for WINDOW with new window
14842 start STARTP. Sets the window start of WINDOW to that position.
14844 We assume that the window's buffer is really current. */
14846 static struct text_pos
14847 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14849 struct window
*w
= XWINDOW (window
);
14850 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14852 eassert (current_buffer
== XBUFFER (w
->contents
));
14854 if (!NILP (Vwindow_scroll_functions
))
14856 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14857 make_number (CHARPOS (startp
)));
14858 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14859 /* In case the hook functions switch buffers. */
14860 set_buffer_internal (XBUFFER (w
->contents
));
14867 /* Make sure the line containing the cursor is fully visible.
14868 A value of true means there is nothing to be done.
14869 (Either the line is fully visible, or it cannot be made so,
14870 or we cannot tell.)
14872 If FORCE_P, return false even if partial visible cursor row
14873 is higher than window.
14875 If CURRENT_MATRIX_P, use the information from the
14876 window's current glyph matrix; otherwise use the desired glyph
14879 A value of false means the caller should do scrolling
14880 as if point had gone off the screen. */
14883 cursor_row_fully_visible_p (struct window
*w
, bool force_p
,
14884 bool current_matrix_p
)
14886 struct glyph_matrix
*matrix
;
14887 struct glyph_row
*row
;
14890 if (!make_cursor_line_fully_visible_p
)
14893 /* It's not always possible to find the cursor, e.g, when a window
14894 is full of overlay strings. Don't do anything in that case. */
14895 if (w
->cursor
.vpos
< 0)
14898 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14899 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14901 /* If the cursor row is not partially visible, there's nothing to do. */
14902 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14905 /* If the row the cursor is in is taller than the window's height,
14906 it's not clear what to do, so do nothing. */
14907 window_height
= window_box_height (w
);
14908 if (row
->height
>= window_height
)
14910 if (!force_p
|| MINI_WINDOW_P (w
)
14911 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14918 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14919 means only WINDOW is redisplayed in redisplay_internal.
14920 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14921 in redisplay_window to bring a partially visible line into view in
14922 the case that only the cursor has moved.
14924 LAST_LINE_MISFIT should be true if we're scrolling because the
14925 last screen line's vertical height extends past the end of the screen.
14929 1 if scrolling succeeded
14931 0 if scrolling didn't find point.
14933 -1 if new fonts have been loaded so that we must interrupt
14934 redisplay, adjust glyph matrices, and try again. */
14940 SCROLLING_NEED_LARGER_MATRICES
14943 /* If scroll-conservatively is more than this, never recenter.
14945 If you change this, don't forget to update the doc string of
14946 `scroll-conservatively' and the Emacs manual. */
14947 #define SCROLL_LIMIT 100
14950 try_scrolling (Lisp_Object window
, bool just_this_one_p
,
14951 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14952 bool temp_scroll_step
, bool last_line_misfit
)
14954 struct window
*w
= XWINDOW (window
);
14955 struct frame
*f
= XFRAME (w
->frame
);
14956 struct text_pos pos
, startp
;
14958 int this_scroll_margin
, scroll_max
, rc
, height
;
14959 int dy
= 0, amount_to_scroll
= 0;
14960 bool scroll_down_p
= false;
14961 int extra_scroll_margin_lines
= last_line_misfit
;
14962 Lisp_Object aggressive
;
14963 /* We will never try scrolling more than this number of lines. */
14964 int scroll_limit
= SCROLL_LIMIT
;
14965 int frame_line_height
= default_line_pixel_height (w
);
14966 int window_total_lines
14967 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14970 debug_method_add (w
, "try_scrolling");
14973 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14975 /* Compute scroll margin height in pixels. We scroll when point is
14976 within this distance from the top or bottom of the window. */
14977 if (scroll_margin
> 0)
14978 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14979 * frame_line_height
;
14981 this_scroll_margin
= 0;
14983 /* Force arg_scroll_conservatively to have a reasonable value, to
14984 avoid scrolling too far away with slow move_it_* functions. Note
14985 that the user can supply scroll-conservatively equal to
14986 `most-positive-fixnum', which can be larger than INT_MAX. */
14987 if (arg_scroll_conservatively
> scroll_limit
)
14989 arg_scroll_conservatively
= scroll_limit
+ 1;
14990 scroll_max
= scroll_limit
* frame_line_height
;
14992 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14993 /* Compute how much we should try to scroll maximally to bring
14994 point into view. */
14995 scroll_max
= (max (scroll_step
,
14996 max (arg_scroll_conservatively
, temp_scroll_step
))
14997 * frame_line_height
);
14998 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14999 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
15000 /* We're trying to scroll because of aggressive scrolling but no
15001 scroll_step is set. Choose an arbitrary one. */
15002 scroll_max
= 10 * frame_line_height
;
15008 /* Decide whether to scroll down. */
15009 if (PT
> CHARPOS (startp
))
15011 int scroll_margin_y
;
15013 /* Compute the pixel ypos of the scroll margin, then move IT to
15014 either that ypos or PT, whichever comes first. */
15015 start_display (&it
, w
, startp
);
15016 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
15017 - frame_line_height
* extra_scroll_margin_lines
;
15018 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
15019 (MOVE_TO_POS
| MOVE_TO_Y
));
15021 if (PT
> CHARPOS (it
.current
.pos
))
15023 int y0
= line_bottom_y (&it
);
15024 /* Compute how many pixels below window bottom to stop searching
15025 for PT. This avoids costly search for PT that is far away if
15026 the user limited scrolling by a small number of lines, but
15027 always finds PT if scroll_conservatively is set to a large
15028 number, such as most-positive-fixnum. */
15029 int slack
= max (scroll_max
, 10 * frame_line_height
);
15030 int y_to_move
= it
.last_visible_y
+ slack
;
15032 /* Compute the distance from the scroll margin to PT or to
15033 the scroll limit, whichever comes first. This should
15034 include the height of the cursor line, to make that line
15036 move_it_to (&it
, PT
, -1, y_to_move
,
15037 -1, MOVE_TO_POS
| MOVE_TO_Y
);
15038 dy
= line_bottom_y (&it
) - y0
;
15040 if (dy
> scroll_max
)
15041 return SCROLLING_FAILED
;
15044 scroll_down_p
= true;
15050 /* Point is in or below the bottom scroll margin, so move the
15051 window start down. If scrolling conservatively, move it just
15052 enough down to make point visible. If scroll_step is set,
15053 move it down by scroll_step. */
15054 if (arg_scroll_conservatively
)
15056 = min (max (dy
, frame_line_height
),
15057 frame_line_height
* arg_scroll_conservatively
);
15058 else if (scroll_step
|| temp_scroll_step
)
15059 amount_to_scroll
= scroll_max
;
15062 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
15063 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15064 if (NUMBERP (aggressive
))
15066 double float_amount
= XFLOATINT (aggressive
) * height
;
15067 int aggressive_scroll
= float_amount
;
15068 if (aggressive_scroll
== 0 && float_amount
> 0)
15069 aggressive_scroll
= 1;
15070 /* Don't let point enter the scroll margin near top of
15071 the window. This could happen if the value of
15072 scroll_up_aggressively is too large and there are
15073 non-zero margins, because scroll_up_aggressively
15074 means put point that fraction of window height
15075 _from_the_bottom_margin_. */
15076 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15077 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15078 amount_to_scroll
= dy
+ aggressive_scroll
;
15082 if (amount_to_scroll
<= 0)
15083 return SCROLLING_FAILED
;
15085 start_display (&it
, w
, startp
);
15086 if (arg_scroll_conservatively
<= scroll_limit
)
15087 move_it_vertically (&it
, amount_to_scroll
);
15090 /* Extra precision for users who set scroll-conservatively
15091 to a large number: make sure the amount we scroll
15092 the window start is never less than amount_to_scroll,
15093 which was computed as distance from window bottom to
15094 point. This matters when lines at window top and lines
15095 below window bottom have different height. */
15097 void *it1data
= NULL
;
15098 /* We use a temporary it1 because line_bottom_y can modify
15099 its argument, if it moves one line down; see there. */
15102 SAVE_IT (it1
, it
, it1data
);
15103 start_y
= line_bottom_y (&it1
);
15105 RESTORE_IT (&it
, &it
, it1data
);
15106 move_it_by_lines (&it
, 1);
15107 SAVE_IT (it1
, it
, it1data
);
15108 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
15111 /* If STARTP is unchanged, move it down another screen line. */
15112 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
15113 move_it_by_lines (&it
, 1);
15114 startp
= it
.current
.pos
;
15118 struct text_pos scroll_margin_pos
= startp
;
15121 /* See if point is inside the scroll margin at the top of the
15123 if (this_scroll_margin
)
15127 start_display (&it
, w
, startp
);
15128 y_start
= it
.current_y
;
15129 move_it_vertically (&it
, this_scroll_margin
);
15130 scroll_margin_pos
= it
.current
.pos
;
15131 /* If we didn't move enough before hitting ZV, request
15132 additional amount of scroll, to move point out of the
15134 if (IT_CHARPOS (it
) == ZV
15135 && it
.current_y
- y_start
< this_scroll_margin
)
15136 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
15139 if (PT
< CHARPOS (scroll_margin_pos
))
15141 /* Point is in the scroll margin at the top of the window or
15142 above what is displayed in the window. */
15145 /* Compute the vertical distance from PT to the scroll
15146 margin position. Move as far as scroll_max allows, or
15147 one screenful, or 10 screen lines, whichever is largest.
15148 Give up if distance is greater than scroll_max or if we
15149 didn't reach the scroll margin position. */
15150 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15151 start_display (&it
, w
, pos
);
15153 y_to_move
= max (it
.last_visible_y
,
15154 max (scroll_max
, 10 * frame_line_height
));
15155 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15157 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15158 dy
= it
.current_y
- y0
;
15159 if (dy
> scroll_max
15160 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15161 return SCROLLING_FAILED
;
15163 /* Additional scroll for when ZV was too close to point. */
15166 /* Compute new window start. */
15167 start_display (&it
, w
, startp
);
15169 if (arg_scroll_conservatively
)
15170 amount_to_scroll
= max (dy
, frame_line_height
15171 * max (scroll_step
, temp_scroll_step
));
15172 else if (scroll_step
|| temp_scroll_step
)
15173 amount_to_scroll
= scroll_max
;
15176 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15177 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15178 if (NUMBERP (aggressive
))
15180 double float_amount
= XFLOATINT (aggressive
) * height
;
15181 int aggressive_scroll
= float_amount
;
15182 if (aggressive_scroll
== 0 && float_amount
> 0)
15183 aggressive_scroll
= 1;
15184 /* Don't let point enter the scroll margin near
15185 bottom of the window, if the value of
15186 scroll_down_aggressively happens to be too
15188 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15189 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15190 amount_to_scroll
= dy
+ aggressive_scroll
;
15194 if (amount_to_scroll
<= 0)
15195 return SCROLLING_FAILED
;
15197 move_it_vertically_backward (&it
, amount_to_scroll
);
15198 startp
= it
.current
.pos
;
15202 /* Run window scroll functions. */
15203 startp
= run_window_scroll_functions (window
, startp
);
15205 /* Display the window. Give up if new fonts are loaded, or if point
15207 if (!try_window (window
, startp
, 0))
15208 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15209 else if (w
->cursor
.vpos
< 0)
15211 clear_glyph_matrix (w
->desired_matrix
);
15212 rc
= SCROLLING_FAILED
;
15216 /* Maybe forget recorded base line for line number display. */
15217 if (!just_this_one_p
15218 || current_buffer
->clip_changed
15219 || BEG_UNCHANGED
< CHARPOS (startp
))
15220 w
->base_line_number
= 0;
15222 /* If cursor ends up on a partially visible line,
15223 treat that as being off the bottom of the screen. */
15224 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1,
15226 /* It's possible that the cursor is on the first line of the
15227 buffer, which is partially obscured due to a vscroll
15228 (Bug#7537). In that case, avoid looping forever. */
15229 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15231 clear_glyph_matrix (w
->desired_matrix
);
15232 ++extra_scroll_margin_lines
;
15235 rc
= SCROLLING_SUCCESS
;
15242 /* Compute a suitable window start for window W if display of W starts
15243 on a continuation line. Value is true if a new window start
15246 The new window start will be computed, based on W's width, starting
15247 from the start of the continued line. It is the start of the
15248 screen line with the minimum distance from the old start W->start. */
15251 compute_window_start_on_continuation_line (struct window
*w
)
15253 struct text_pos pos
, start_pos
;
15254 bool window_start_changed_p
= false;
15256 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15258 /* If window start is on a continuation line... Window start may be
15259 < BEGV in case there's invisible text at the start of the
15260 buffer (M-x rmail, for example). */
15261 if (CHARPOS (start_pos
) > BEGV
15262 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15265 struct glyph_row
*row
;
15267 /* Handle the case that the window start is out of range. */
15268 if (CHARPOS (start_pos
) < BEGV
)
15269 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15270 else if (CHARPOS (start_pos
) > ZV
)
15271 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15273 /* Find the start of the continued line. This should be fast
15274 because find_newline is fast (newline cache). */
15275 row
= w
->desired_matrix
->rows
+ WINDOW_WANTS_HEADER_LINE_P (w
);
15276 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15277 row
, DEFAULT_FACE_ID
);
15278 reseat_at_previous_visible_line_start (&it
);
15280 /* If the line start is "too far" away from the window start,
15281 say it takes too much time to compute a new window start. */
15282 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15283 /* PXW: Do we need upper bounds here? */
15284 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15286 int min_distance
, distance
;
15288 /* Move forward by display lines to find the new window
15289 start. If window width was enlarged, the new start can
15290 be expected to be > the old start. If window width was
15291 decreased, the new window start will be < the old start.
15292 So, we're looking for the display line start with the
15293 minimum distance from the old window start. */
15294 pos
= it
.current
.pos
;
15295 min_distance
= INFINITY
;
15296 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15297 distance
< min_distance
)
15299 min_distance
= distance
;
15300 pos
= it
.current
.pos
;
15301 if (it
.line_wrap
== WORD_WRAP
)
15303 /* Under WORD_WRAP, move_it_by_lines is likely to
15304 overshoot and stop not at the first, but the
15305 second character from the left margin. So in
15306 that case, we need a more tight control on the X
15307 coordinate of the iterator than move_it_by_lines
15308 promises in its contract. The method is to first
15309 go to the last (rightmost) visible character of a
15310 line, then move to the leftmost character on the
15311 next line in a separate call. */
15312 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15313 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15314 move_it_to (&it
, ZV
, 0,
15315 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15316 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15319 move_it_by_lines (&it
, 1);
15322 /* Set the window start there. */
15323 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15324 window_start_changed_p
= true;
15328 return window_start_changed_p
;
15332 /* Try cursor movement in case text has not changed in window WINDOW,
15333 with window start STARTP. Value is
15335 CURSOR_MOVEMENT_SUCCESS if successful
15337 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15339 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15340 display. *SCROLL_STEP is set to true, under certain circumstances, if
15341 we want to scroll as if scroll-step were set to 1. See the code.
15343 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15344 which case we have to abort this redisplay, and adjust matrices
15349 CURSOR_MOVEMENT_SUCCESS
,
15350 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15351 CURSOR_MOVEMENT_MUST_SCROLL
,
15352 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15356 try_cursor_movement (Lisp_Object window
, struct text_pos startp
,
15359 struct window
*w
= XWINDOW (window
);
15360 struct frame
*f
= XFRAME (w
->frame
);
15361 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15364 if (inhibit_try_cursor_movement
)
15368 /* Previously, there was a check for Lisp integer in the
15369 if-statement below. Now, this field is converted to
15370 ptrdiff_t, thus zero means invalid position in a buffer. */
15371 eassert (w
->last_point
> 0);
15372 /* Likewise there was a check whether window_end_vpos is nil or larger
15373 than the window. Now window_end_vpos is int and so never nil, but
15374 let's leave eassert to check whether it fits in the window. */
15375 eassert (!w
->window_end_valid
15376 || w
->window_end_vpos
< w
->current_matrix
->nrows
);
15378 /* Handle case where text has not changed, only point, and it has
15379 not moved off the frame. */
15380 if (/* Point may be in this window. */
15381 PT
>= CHARPOS (startp
)
15382 /* Selective display hasn't changed. */
15383 && !current_buffer
->clip_changed
15384 /* Function force-mode-line-update is used to force a thorough
15385 redisplay. It sets either windows_or_buffers_changed or
15386 update_mode_lines. So don't take a shortcut here for these
15388 && !update_mode_lines
15389 && !windows_or_buffers_changed
15390 && !f
->cursor_type_changed
15391 && NILP (Vshow_trailing_whitespace
)
15392 /* This code is not used for mini-buffer for the sake of the case
15393 of redisplaying to replace an echo area message; since in
15394 that case the mini-buffer contents per se are usually
15395 unchanged. This code is of no real use in the mini-buffer
15396 since the handling of this_line_start_pos, etc., in redisplay
15397 handles the same cases. */
15398 && !EQ (window
, minibuf_window
)
15399 && (FRAME_WINDOW_P (f
)
15400 || !overlay_arrow_in_current_buffer_p ()))
15402 int this_scroll_margin
, top_scroll_margin
;
15403 struct glyph_row
*row
= NULL
;
15404 int frame_line_height
= default_line_pixel_height (w
);
15405 int window_total_lines
15406 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15409 debug_method_add (w
, "cursor movement");
15412 /* Scroll if point within this distance from the top or bottom
15413 of the window. This is a pixel value. */
15414 if (scroll_margin
> 0)
15416 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15417 this_scroll_margin
*= frame_line_height
;
15420 this_scroll_margin
= 0;
15422 top_scroll_margin
= this_scroll_margin
;
15423 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15424 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15426 /* Start with the row the cursor was displayed during the last
15427 not paused redisplay. Give up if that row is not valid. */
15428 if (w
->last_cursor_vpos
< 0
15429 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15430 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15433 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15434 if (row
->mode_line_p
)
15436 if (!row
->enabled_p
)
15437 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15440 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15442 bool scroll_p
= false, must_scroll
= false;
15443 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15445 if (PT
> w
->last_point
)
15447 /* Point has moved forward. */
15448 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15449 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15451 eassert (row
->enabled_p
);
15455 /* If the end position of a row equals the start
15456 position of the next row, and PT is at that position,
15457 we would rather display cursor in the next line. */
15458 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15459 && MATRIX_ROW_END_CHARPOS (row
) == PT
15460 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15461 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15462 && !cursor_row_p (row
))
15465 /* If within the scroll margin, scroll. Note that
15466 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15467 the next line would be drawn, and that
15468 this_scroll_margin can be zero. */
15469 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15470 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15471 /* Line is completely visible last line in window
15472 and PT is to be set in the next line. */
15473 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15474 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15475 && !row
->ends_at_zv_p
15476 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15479 else if (PT
< w
->last_point
)
15481 /* Cursor has to be moved backward. Note that PT >=
15482 CHARPOS (startp) because of the outer if-statement. */
15483 while (!row
->mode_line_p
15484 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15485 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15486 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15487 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15488 row
> w
->current_matrix
->rows
15489 && (row
-1)->ends_in_newline_from_string_p
))))
15490 && (row
->y
> top_scroll_margin
15491 || CHARPOS (startp
) == BEGV
))
15493 eassert (row
->enabled_p
);
15497 /* Consider the following case: Window starts at BEGV,
15498 there is invisible, intangible text at BEGV, so that
15499 display starts at some point START > BEGV. It can
15500 happen that we are called with PT somewhere between
15501 BEGV and START. Try to handle that case. */
15502 if (row
< w
->current_matrix
->rows
15503 || row
->mode_line_p
)
15505 row
= w
->current_matrix
->rows
;
15506 if (row
->mode_line_p
)
15510 /* Due to newlines in overlay strings, we may have to
15511 skip forward over overlay strings. */
15512 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15513 && MATRIX_ROW_END_CHARPOS (row
) == PT
15514 && !cursor_row_p (row
))
15517 /* If within the scroll margin, scroll. */
15518 if (row
->y
< top_scroll_margin
15519 && CHARPOS (startp
) != BEGV
)
15524 /* Cursor did not move. So don't scroll even if cursor line
15525 is partially visible, as it was so before. */
15526 rc
= CURSOR_MOVEMENT_SUCCESS
;
15529 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15530 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15532 /* if PT is not in the glyph row, give up. */
15533 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15534 must_scroll
= true;
15536 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15537 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15539 struct glyph_row
*row1
;
15541 /* If rows are bidi-reordered and point moved, back up
15542 until we find a row that does not belong to a
15543 continuation line. This is because we must consider
15544 all rows of a continued line as candidates for the
15545 new cursor positioning, since row start and end
15546 positions change non-linearly with vertical position
15548 /* FIXME: Revisit this when glyph ``spilling'' in
15549 continuation lines' rows is implemented for
15550 bidi-reordered rows. */
15551 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15552 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15555 /* If we hit the beginning of the displayed portion
15556 without finding the first row of a continued
15560 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15563 eassert (row
->enabled_p
);
15568 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15569 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15570 /* Make sure this isn't a header line by any chance, since
15571 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield true. */
15572 && !row
->mode_line_p
15573 && make_cursor_line_fully_visible_p
)
15575 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15576 && !row
->ends_at_zv_p
15577 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15578 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15579 else if (row
->height
> window_box_height (w
))
15581 /* If we end up in a partially visible line, let's
15582 make it fully visible, except when it's taller
15583 than the window, in which case we can't do much
15585 *scroll_step
= true;
15586 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15590 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15591 if (!cursor_row_fully_visible_p (w
, false, true))
15592 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15594 rc
= CURSOR_MOVEMENT_SUCCESS
;
15598 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15599 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15600 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15602 /* With bidi-reordered rows, there could be more than
15603 one candidate row whose start and end positions
15604 occlude point. We need to let set_cursor_from_row
15605 find the best candidate. */
15606 /* FIXME: Revisit this when glyph ``spilling'' in
15607 continuation lines' rows is implemented for
15608 bidi-reordered rows. */
15613 bool at_zv_p
= false, exact_match_p
= false;
15615 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15616 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15617 && cursor_row_p (row
))
15618 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15620 /* As soon as we've found the exact match for point,
15621 or the first suitable row whose ends_at_zv_p flag
15622 is set, we are done. */
15625 at_zv_p
= MATRIX_ROW (w
->current_matrix
,
15626 w
->cursor
.vpos
)->ends_at_zv_p
;
15628 && w
->cursor
.hpos
>= 0
15629 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15632 struct glyph_row
*candidate
=
15633 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15635 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15636 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15639 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15640 || (NILP (g
->object
)
15641 && (g
->charpos
== PT
15642 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15644 if (at_zv_p
|| exact_match_p
)
15646 rc
= CURSOR_MOVEMENT_SUCCESS
;
15650 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15654 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15655 || row
->continued_p
)
15656 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15657 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15658 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15659 /* If we didn't find any candidate rows, or exited the
15660 loop before all the candidates were examined, signal
15661 to the caller that this method failed. */
15662 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15664 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15665 && !row
->continued_p
))
15666 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15668 rc
= CURSOR_MOVEMENT_SUCCESS
;
15674 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15676 rc
= CURSOR_MOVEMENT_SUCCESS
;
15681 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15682 && MATRIX_ROW_START_CHARPOS (row
) == PT
15683 && cursor_row_p (row
));
15693 set_vertical_scroll_bar (struct window
*w
)
15695 ptrdiff_t start
, end
, whole
;
15697 /* Calculate the start and end positions for the current window.
15698 At some point, it would be nice to choose between scrollbars
15699 which reflect the whole buffer size, with special markers
15700 indicating narrowing, and scrollbars which reflect only the
15703 Note that mini-buffers sometimes aren't displaying any text. */
15704 if (!MINI_WINDOW_P (w
)
15705 || (w
== XWINDOW (minibuf_window
)
15706 && NILP (echo_area_buffer
[0])))
15708 struct buffer
*buf
= XBUFFER (w
->contents
);
15709 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15710 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15711 /* I don't think this is guaranteed to be right. For the
15712 moment, we'll pretend it is. */
15713 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15717 if (whole
< (end
- start
))
15718 whole
= end
- start
;
15721 start
= end
= whole
= 0;
15723 /* Indicate what this scroll bar ought to be displaying now. */
15724 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15725 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15726 (w
, end
- start
, whole
, start
);
15731 set_horizontal_scroll_bar (struct window
*w
)
15733 int start
, end
, whole
, portion
;
15735 if (!MINI_WINDOW_P (w
)
15736 || (w
== XWINDOW (minibuf_window
)
15737 && NILP (echo_area_buffer
[0])))
15739 struct buffer
*b
= XBUFFER (w
->contents
);
15740 struct buffer
*old_buffer
= NULL
;
15742 struct text_pos startp
;
15744 if (b
!= current_buffer
)
15746 old_buffer
= current_buffer
;
15747 set_buffer_internal (b
);
15750 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15751 start_display (&it
, w
, startp
);
15752 it
.last_visible_x
= INT_MAX
;
15753 whole
= move_it_to (&it
, -1, INT_MAX
, window_box_height (w
), -1,
15754 MOVE_TO_X
| MOVE_TO_Y
);
15755 /* whole = move_it_to (&it, w->window_end_pos, INT_MAX,
15756 window_box_height (w), -1,
15757 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); */
15759 start
= w
->hscroll
* FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
15760 end
= start
+ window_box_width (w
, TEXT_AREA
);
15761 portion
= end
- start
;
15762 /* After enlarging a horizontally scrolled window such that it
15763 gets at least as wide as the text it contains, make sure that
15764 the thumb doesn't fill the entire scroll bar so we can still
15765 drag it back to see the entire text. */
15766 whole
= max (whole
, end
);
15772 pdir
= Fcurrent_bidi_paragraph_direction (Qnil
);
15773 if (EQ (pdir
, Qright_to_left
))
15775 start
= whole
- end
;
15776 end
= start
+ portion
;
15781 set_buffer_internal (old_buffer
);
15784 start
= end
= whole
= portion
= 0;
15786 w
->hscroll_whole
= whole
;
15788 /* Indicate what this scroll bar ought to be displaying now. */
15789 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
15790 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
15791 (w
, portion
, whole
, start
);
15795 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P means only
15796 selected_window is redisplayed.
15798 We can return without actually redisplaying the window if fonts has been
15799 changed on window's frame. In that case, redisplay_internal will retry.
15801 As one of the important parts of redisplaying a window, we need to
15802 decide whether the previous window-start position (stored in the
15803 window's w->start marker position) is still valid, and if it isn't,
15804 recompute it. Some details about that:
15806 . The previous window-start could be in a continuation line, in
15807 which case we need to recompute it when the window width
15808 changes. See compute_window_start_on_continuation_line and its
15811 . The text that changed since last redisplay could include the
15812 previous window-start position. In that case, we try to salvage
15813 what we can from the current glyph matrix by calling
15814 try_scrolling, which see.
15816 . Some Emacs command could force us to use a specific window-start
15817 position by setting the window's force_start flag, or gently
15818 propose doing that by setting the window's optional_new_start
15819 flag. In these cases, we try using the specified start point if
15820 that succeeds (i.e. the window desired matrix is successfully
15821 recomputed, and point location is within the window). In case
15822 of optional_new_start, we first check if the specified start
15823 position is feasible, i.e. if it will allow point to be
15824 displayed in the window. If using the specified start point
15825 fails, e.g., if new fonts are needed to be loaded, we abort the
15826 redisplay cycle and leave it up to the next cycle to figure out
15829 . Note that the window's force_start flag is sometimes set by
15830 redisplay itself, when it decides that the previous window start
15831 point is fine and should be kept. Search for "goto force_start"
15832 below to see the details. Like the values of window-start
15833 specified outside of redisplay, these internally-deduced values
15834 are tested for feasibility, and ignored if found to be
15837 . Note that the function try_window, used to completely redisplay
15838 a window, accepts the window's start point as its argument.
15839 This is used several times in the redisplay code to control
15840 where the window start will be, according to user options such
15841 as scroll-conservatively, and also to ensure the screen line
15842 showing point will be fully (as opposed to partially) visible on
15846 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15848 struct window
*w
= XWINDOW (window
);
15849 struct frame
*f
= XFRAME (w
->frame
);
15850 struct buffer
*buffer
= XBUFFER (w
->contents
);
15851 struct buffer
*old
= current_buffer
;
15852 struct text_pos lpoint
, opoint
, startp
;
15853 bool update_mode_line
;
15856 /* Record it now because it's overwritten. */
15857 bool current_matrix_up_to_date_p
= false;
15858 bool used_current_matrix_p
= false;
15859 /* This is less strict than current_matrix_up_to_date_p.
15860 It indicates that the buffer contents and narrowing are unchanged. */
15861 bool buffer_unchanged_p
= false;
15862 bool temp_scroll_step
= false;
15863 ptrdiff_t count
= SPECPDL_INDEX ();
15865 int centering_position
= -1;
15866 bool last_line_misfit
= false;
15867 ptrdiff_t beg_unchanged
, end_unchanged
;
15868 int frame_line_height
;
15870 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15874 *w
->desired_matrix
->method
= 0;
15877 if (!just_this_one_p
15878 && REDISPLAY_SOME_P ()
15880 && !w
->update_mode_line
15882 && !buffer
->text
->redisplay
15883 && BUF_PT (buffer
) == w
->last_point
)
15886 /* Make sure that both W's markers are valid. */
15887 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15888 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15890 /* We come here again if we need to run window-text-change-functions
15893 reconsider_clip_changes (w
);
15894 frame_line_height
= default_line_pixel_height (w
);
15896 /* Has the mode line to be updated? */
15897 update_mode_line
= (w
->update_mode_line
15898 || update_mode_lines
15899 || buffer
->clip_changed
15900 || buffer
->prevent_redisplay_optimizations_p
);
15902 if (!just_this_one_p
)
15903 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15904 cleverly elsewhere. */
15905 w
->must_be_updated_p
= true;
15907 if (MINI_WINDOW_P (w
))
15909 if (w
== XWINDOW (echo_area_window
)
15910 && !NILP (echo_area_buffer
[0]))
15912 if (update_mode_line
)
15913 /* We may have to update a tty frame's menu bar or a
15914 tool-bar. Example `M-x C-h C-h C-g'. */
15915 goto finish_menu_bars
;
15917 /* We've already displayed the echo area glyphs in this window. */
15918 goto finish_scroll_bars
;
15920 else if ((w
!= XWINDOW (minibuf_window
)
15921 || minibuf_level
== 0)
15922 /* When buffer is nonempty, redisplay window normally. */
15923 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15924 /* Quail displays non-mini buffers in minibuffer window.
15925 In that case, redisplay the window normally. */
15926 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15928 /* W is a mini-buffer window, but it's not active, so clear
15930 int yb
= window_text_bottom_y (w
);
15931 struct glyph_row
*row
;
15934 for (y
= 0, row
= w
->desired_matrix
->rows
;
15936 y
+= row
->height
, ++row
)
15937 blank_row (w
, row
, y
);
15938 goto finish_scroll_bars
;
15941 clear_glyph_matrix (w
->desired_matrix
);
15944 /* Otherwise set up data on this window; select its buffer and point
15946 /* Really select the buffer, for the sake of buffer-local
15948 set_buffer_internal_1 (XBUFFER (w
->contents
));
15950 current_matrix_up_to_date_p
15951 = (w
->window_end_valid
15952 && !current_buffer
->clip_changed
15953 && !current_buffer
->prevent_redisplay_optimizations_p
15954 && !window_outdated (w
));
15956 /* Run the window-text-change-functions
15957 if it is possible that the text on the screen has changed
15958 (either due to modification of the text, or any other reason). */
15959 if (!current_matrix_up_to_date_p
15960 && !NILP (Vwindow_text_change_functions
))
15962 safe_run_hooks (Qwindow_text_change_functions
);
15966 beg_unchanged
= BEG_UNCHANGED
;
15967 end_unchanged
= END_UNCHANGED
;
15969 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15971 specbind (Qinhibit_point_motion_hooks
, Qt
);
15974 = (w
->window_end_valid
15975 && !current_buffer
->clip_changed
15976 && !window_outdated (w
));
15978 /* When windows_or_buffers_changed is non-zero, we can't rely
15979 on the window end being valid, so set it to zero there. */
15980 if (windows_or_buffers_changed
)
15982 /* If window starts on a continuation line, maybe adjust the
15983 window start in case the window's width changed. */
15984 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15985 compute_window_start_on_continuation_line (w
);
15987 w
->window_end_valid
= false;
15988 /* If so, we also can't rely on current matrix
15989 and should not fool try_cursor_movement below. */
15990 current_matrix_up_to_date_p
= false;
15993 /* Some sanity checks. */
15994 CHECK_WINDOW_END (w
);
15995 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15997 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
16000 if (mode_line_update_needed (w
))
16001 update_mode_line
= true;
16003 /* Point refers normally to the selected window. For any other
16004 window, set up appropriate value. */
16005 if (!EQ (window
, selected_window
))
16007 ptrdiff_t new_pt
= marker_position (w
->pointm
);
16008 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
16013 new_pt_byte
= BEGV_BYTE
;
16014 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
16016 else if (new_pt
> (ZV
- 1))
16019 new_pt_byte
= ZV_BYTE
;
16020 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
16023 /* We don't use SET_PT so that the point-motion hooks don't run. */
16024 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
16027 /* If any of the character widths specified in the display table
16028 have changed, invalidate the width run cache. It's true that
16029 this may be a bit late to catch such changes, but the rest of
16030 redisplay goes (non-fatally) haywire when the display table is
16031 changed, so why should we worry about doing any better? */
16032 if (current_buffer
->width_run_cache
16033 || (current_buffer
->base_buffer
16034 && current_buffer
->base_buffer
->width_run_cache
))
16036 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
16038 if (! disptab_matches_widthtab
16039 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
16041 struct buffer
*buf
= current_buffer
;
16043 if (buf
->base_buffer
)
16044 buf
= buf
->base_buffer
;
16045 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
16046 recompute_width_table (current_buffer
, disptab
);
16050 /* If window-start is screwed up, choose a new one. */
16051 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
16054 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16056 /* If someone specified a new starting point but did not insist,
16057 check whether it can be used. */
16058 if ((w
->optional_new_start
|| window_frozen_p (w
))
16059 && CHARPOS (startp
) >= BEGV
16060 && CHARPOS (startp
) <= ZV
)
16062 ptrdiff_t it_charpos
;
16064 w
->optional_new_start
= false;
16065 start_display (&it
, w
, startp
);
16066 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
16067 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
16068 /* Record IT's position now, since line_bottom_y might change
16070 it_charpos
= IT_CHARPOS (it
);
16071 /* Make sure we set the force_start flag only if the cursor row
16072 will be fully visible. Otherwise, the code under force_start
16073 label below will try to move point back into view, which is
16074 not what the code which sets optional_new_start wants. */
16075 if ((it
.current_y
== 0 || line_bottom_y (&it
) < it
.last_visible_y
)
16076 && !w
->force_start
)
16078 if (it_charpos
== PT
)
16079 w
->force_start
= true;
16080 /* IT may overshoot PT if text at PT is invisible. */
16081 else if (it_charpos
> PT
&& CHARPOS (startp
) <= PT
)
16082 w
->force_start
= true;
16084 if (w
->force_start
)
16086 if (window_frozen_p (w
))
16087 debug_method_add (w
, "set force_start from frozen window start");
16089 debug_method_add (w
, "set force_start from optional_new_start");
16097 /* Handle case where place to start displaying has been specified,
16098 unless the specified location is outside the accessible range. */
16099 if (w
->force_start
)
16101 /* We set this later on if we have to adjust point. */
16104 w
->force_start
= false;
16106 w
->window_end_valid
= false;
16108 /* Forget any recorded base line for line number display. */
16109 if (!buffer_unchanged_p
)
16110 w
->base_line_number
= 0;
16112 /* Redisplay the mode line. Select the buffer properly for that.
16113 Also, run the hook window-scroll-functions
16114 because we have scrolled. */
16115 /* Note, we do this after clearing force_start because
16116 if there's an error, it is better to forget about force_start
16117 than to get into an infinite loop calling the hook functions
16118 and having them get more errors. */
16119 if (!update_mode_line
16120 || ! NILP (Vwindow_scroll_functions
))
16122 update_mode_line
= true;
16123 w
->update_mode_line
= true;
16124 startp
= run_window_scroll_functions (window
, startp
);
16127 if (CHARPOS (startp
) < BEGV
)
16128 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
16129 else if (CHARPOS (startp
) > ZV
)
16130 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
16132 /* Redisplay, then check if cursor has been set during the
16133 redisplay. Give up if new fonts were loaded. */
16134 /* We used to issue a CHECK_MARGINS argument to try_window here,
16135 but this causes scrolling to fail when point begins inside
16136 the scroll margin (bug#148) -- cyd */
16137 if (!try_window (window
, startp
, 0))
16139 w
->force_start
= true;
16140 clear_glyph_matrix (w
->desired_matrix
);
16141 goto need_larger_matrices
;
16144 if (w
->cursor
.vpos
< 0)
16146 /* If point does not appear, try to move point so it does
16147 appear. The desired matrix has been built above, so we
16148 can use it here. */
16149 new_vpos
= window_box_height (w
) / 2;
16152 if (!cursor_row_fully_visible_p (w
, false, false))
16154 /* Point does appear, but on a line partly visible at end of window.
16155 Move it back to a fully-visible line. */
16156 new_vpos
= window_box_height (w
);
16157 /* But if window_box_height suggests a Y coordinate that is
16158 not less than we already have, that line will clearly not
16159 be fully visible, so give up and scroll the display.
16160 This can happen when the default face uses a font whose
16161 dimensions are different from the frame's default
16163 if (new_vpos
>= w
->cursor
.y
)
16165 w
->cursor
.vpos
= -1;
16166 clear_glyph_matrix (w
->desired_matrix
);
16167 goto try_to_scroll
;
16170 else if (w
->cursor
.vpos
>= 0)
16172 /* Some people insist on not letting point enter the scroll
16173 margin, even though this part handles windows that didn't
16175 int window_total_lines
16176 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16177 int margin
= min (scroll_margin
, window_total_lines
/ 4);
16178 int pixel_margin
= margin
* frame_line_height
;
16179 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
16181 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
16182 below, which finds the row to move point to, advances by
16183 the Y coordinate of the _next_ row, see the definition of
16184 MATRIX_ROW_BOTTOM_Y. */
16185 if (w
->cursor
.vpos
< margin
+ header_line
)
16187 w
->cursor
.vpos
= -1;
16188 clear_glyph_matrix (w
->desired_matrix
);
16189 goto try_to_scroll
;
16193 int window_height
= window_box_height (w
);
16196 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
16197 if (w
->cursor
.y
>= window_height
- pixel_margin
)
16199 w
->cursor
.vpos
= -1;
16200 clear_glyph_matrix (w
->desired_matrix
);
16201 goto try_to_scroll
;
16206 /* If we need to move point for either of the above reasons,
16207 now actually do it. */
16210 struct glyph_row
*row
;
16212 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
16213 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
16216 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
16217 MATRIX_ROW_START_BYTEPOS (row
));
16219 if (w
!= XWINDOW (selected_window
))
16220 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
16221 else if (current_buffer
== old
)
16222 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16224 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
16226 /* Re-run pre-redisplay-function so it can update the region
16227 according to the new position of point. */
16228 /* Other than the cursor, w's redisplay is done so we can set its
16229 redisplay to false. Also the buffer's redisplay can be set to
16230 false, since propagate_buffer_redisplay should have already
16231 propagated its info to `w' anyway. */
16232 w
->redisplay
= false;
16233 XBUFFER (w
->contents
)->text
->redisplay
= false;
16234 safe__call1 (true, Vpre_redisplay_function
, Fcons (window
, Qnil
));
16236 if (w
->redisplay
|| XBUFFER (w
->contents
)->text
->redisplay
)
16238 /* pre-redisplay-function made changes (e.g. move the region)
16239 that require another round of redisplay. */
16240 clear_glyph_matrix (w
->desired_matrix
);
16241 if (!try_window (window
, startp
, 0))
16242 goto need_larger_matrices
;
16245 if (w
->cursor
.vpos
< 0 || !cursor_row_fully_visible_p (w
, false, false))
16247 clear_glyph_matrix (w
->desired_matrix
);
16248 goto try_to_scroll
;
16252 debug_method_add (w
, "forced window start");
16257 /* Handle case where text has not changed, only point, and it has
16258 not moved off the frame, and we are not retrying after hscroll.
16259 (current_matrix_up_to_date_p is true when retrying.) */
16260 if (current_matrix_up_to_date_p
16261 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
16262 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
16266 case CURSOR_MOVEMENT_SUCCESS
:
16267 used_current_matrix_p
= true;
16270 case CURSOR_MOVEMENT_MUST_SCROLL
:
16271 goto try_to_scroll
;
16277 /* If current starting point was originally the beginning of a line
16278 but no longer is, find a new starting point. */
16279 else if (w
->start_at_line_beg
16280 && !(CHARPOS (startp
) <= BEGV
16281 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
16284 debug_method_add (w
, "recenter 1");
16289 /* Try scrolling with try_window_id. Value is > 0 if update has
16290 been done, it is -1 if we know that the same window start will
16291 not work. It is 0 if unsuccessful for some other reason. */
16292 else if ((tem
= try_window_id (w
)) != 0)
16295 debug_method_add (w
, "try_window_id %d", tem
);
16298 if (f
->fonts_changed
)
16299 goto need_larger_matrices
;
16303 /* Otherwise try_window_id has returned -1 which means that we
16304 don't want the alternative below this comment to execute. */
16306 else if (CHARPOS (startp
) >= BEGV
16307 && CHARPOS (startp
) <= ZV
16308 && PT
>= CHARPOS (startp
)
16309 && (CHARPOS (startp
) < ZV
16310 /* Avoid starting at end of buffer. */
16311 || CHARPOS (startp
) == BEGV
16312 || !window_outdated (w
)))
16314 int d1
, d2
, d5
, d6
;
16317 /* If first window line is a continuation line, and window start
16318 is inside the modified region, but the first change is before
16319 current window start, we must select a new window start.
16321 However, if this is the result of a down-mouse event (e.g. by
16322 extending the mouse-drag-overlay), we don't want to select a
16323 new window start, since that would change the position under
16324 the mouse, resulting in an unwanted mouse-movement rather
16325 than a simple mouse-click. */
16326 if (!w
->start_at_line_beg
16327 && NILP (do_mouse_tracking
)
16328 && CHARPOS (startp
) > BEGV
16329 && CHARPOS (startp
) > BEG
+ beg_unchanged
16330 && CHARPOS (startp
) <= Z
- end_unchanged
16331 /* Even if w->start_at_line_beg is nil, a new window may
16332 start at a line_beg, since that's how set_buffer_window
16333 sets it. So, we need to check the return value of
16334 compute_window_start_on_continuation_line. (See also
16336 && XMARKER (w
->start
)->buffer
== current_buffer
16337 && compute_window_start_on_continuation_line (w
)
16338 /* It doesn't make sense to force the window start like we
16339 do at label force_start if it is already known that point
16340 will not be fully visible in the resulting window, because
16341 doing so will move point from its correct position
16342 instead of scrolling the window to bring point into view.
16344 && pos_visible_p (w
, PT
, &d1
, &d2
, &rtop
, &rbot
, &d5
, &d6
)
16345 /* A very tall row could need more than the window height,
16346 in which case we accept that it is partially visible. */
16347 && (rtop
!= 0) == (rbot
!= 0))
16349 w
->force_start
= true;
16350 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16352 debug_method_add (w
, "recomputed window start in continuation line");
16358 debug_method_add (w
, "same window start");
16361 /* Try to redisplay starting at same place as before.
16362 If point has not moved off frame, accept the results. */
16363 if (!current_matrix_up_to_date_p
16364 /* Don't use try_window_reusing_current_matrix in this case
16365 because a window scroll function can have changed the
16367 || !NILP (Vwindow_scroll_functions
)
16368 || MINI_WINDOW_P (w
)
16369 || !(used_current_matrix_p
16370 = try_window_reusing_current_matrix (w
)))
16372 IF_DEBUG (debug_method_add (w
, "1"));
16373 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16374 /* -1 means we need to scroll.
16375 0 means we need new matrices, but fonts_changed
16376 is set in that case, so we will detect it below. */
16377 goto try_to_scroll
;
16380 if (f
->fonts_changed
)
16381 goto need_larger_matrices
;
16383 if (w
->cursor
.vpos
>= 0)
16385 if (!just_this_one_p
16386 || current_buffer
->clip_changed
16387 || BEG_UNCHANGED
< CHARPOS (startp
))
16388 /* Forget any recorded base line for line number display. */
16389 w
->base_line_number
= 0;
16391 if (!cursor_row_fully_visible_p (w
, true, false))
16393 clear_glyph_matrix (w
->desired_matrix
);
16394 last_line_misfit
= true;
16396 /* Drop through and scroll. */
16401 clear_glyph_matrix (w
->desired_matrix
);
16406 /* Redisplay the mode line. Select the buffer properly for that. */
16407 if (!update_mode_line
)
16409 update_mode_line
= true;
16410 w
->update_mode_line
= true;
16413 /* Try to scroll by specified few lines. */
16414 if ((scroll_conservatively
16415 || emacs_scroll_step
16416 || temp_scroll_step
16417 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16418 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16419 && CHARPOS (startp
) >= BEGV
16420 && CHARPOS (startp
) <= ZV
)
16422 /* The function returns -1 if new fonts were loaded, 1 if
16423 successful, 0 if not successful. */
16424 int ss
= try_scrolling (window
, just_this_one_p
,
16425 scroll_conservatively
,
16427 temp_scroll_step
, last_line_misfit
);
16430 case SCROLLING_SUCCESS
:
16433 case SCROLLING_NEED_LARGER_MATRICES
:
16434 goto need_larger_matrices
;
16436 case SCROLLING_FAILED
:
16444 /* Finally, just choose a place to start which positions point
16445 according to user preferences. */
16450 debug_method_add (w
, "recenter");
16453 /* Forget any previously recorded base line for line number display. */
16454 if (!buffer_unchanged_p
)
16455 w
->base_line_number
= 0;
16457 /* Determine the window start relative to point. */
16458 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16459 it
.current_y
= it
.last_visible_y
;
16460 if (centering_position
< 0)
16462 int window_total_lines
16463 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16465 = scroll_margin
> 0
16466 ? min (scroll_margin
, window_total_lines
/ 4)
16468 ptrdiff_t margin_pos
= CHARPOS (startp
);
16469 Lisp_Object aggressive
;
16472 /* If there is a scroll margin at the top of the window, find
16473 its character position. */
16475 /* Cannot call start_display if startp is not in the
16476 accessible region of the buffer. This can happen when we
16477 have just switched to a different buffer and/or changed
16478 its restriction. In that case, startp is initialized to
16479 the character position 1 (BEGV) because we did not yet
16480 have chance to display the buffer even once. */
16481 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16484 void *it1data
= NULL
;
16486 SAVE_IT (it1
, it
, it1data
);
16487 start_display (&it1
, w
, startp
);
16488 move_it_vertically (&it1
, margin
* frame_line_height
);
16489 margin_pos
= IT_CHARPOS (it1
);
16490 RESTORE_IT (&it
, &it
, it1data
);
16492 scrolling_up
= PT
> margin_pos
;
16495 ? BVAR (current_buffer
, scroll_up_aggressively
)
16496 : BVAR (current_buffer
, scroll_down_aggressively
);
16498 if (!MINI_WINDOW_P (w
)
16499 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16503 /* Setting scroll-conservatively overrides
16504 scroll-*-aggressively. */
16505 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16507 double float_amount
= XFLOATINT (aggressive
);
16509 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16510 if (pt_offset
== 0 && float_amount
> 0)
16512 if (pt_offset
&& margin
> 0)
16515 /* Compute how much to move the window start backward from
16516 point so that point will be displayed where the user
16520 centering_position
= it
.last_visible_y
;
16522 centering_position
-= pt_offset
;
16523 centering_position
-=
16524 (frame_line_height
* (1 + margin
+ last_line_misfit
)
16525 + WINDOW_HEADER_LINE_HEIGHT (w
));
16526 /* Don't let point enter the scroll margin near top of
16528 if (centering_position
< margin
* frame_line_height
)
16529 centering_position
= margin
* frame_line_height
;
16532 centering_position
= margin
* frame_line_height
+ pt_offset
;
16535 /* Set the window start half the height of the window backward
16537 centering_position
= window_box_height (w
) / 2;
16539 move_it_vertically_backward (&it
, centering_position
);
16541 eassert (IT_CHARPOS (it
) >= BEGV
);
16543 /* The function move_it_vertically_backward may move over more
16544 than the specified y-distance. If it->w is small, e.g. a
16545 mini-buffer window, we may end up in front of the window's
16546 display area. Start displaying at the start of the line
16547 containing PT in this case. */
16548 if (it
.current_y
<= 0)
16550 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16551 move_it_vertically_backward (&it
, 0);
16555 it
.current_x
= it
.hpos
= 0;
16557 /* Set the window start position here explicitly, to avoid an
16558 infinite loop in case the functions in window-scroll-functions
16560 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16562 /* Run scroll hooks. */
16563 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16565 /* Redisplay the window. */
16566 if (!current_matrix_up_to_date_p
16567 || windows_or_buffers_changed
16568 || f
->cursor_type_changed
16569 /* Don't use try_window_reusing_current_matrix in this case
16570 because it can have changed the buffer. */
16571 || !NILP (Vwindow_scroll_functions
)
16572 || !just_this_one_p
16573 || MINI_WINDOW_P (w
)
16574 || !(used_current_matrix_p
16575 = try_window_reusing_current_matrix (w
)))
16576 try_window (window
, startp
, 0);
16578 /* If new fonts have been loaded (due to fontsets), give up. We
16579 have to start a new redisplay since we need to re-adjust glyph
16581 if (f
->fonts_changed
)
16582 goto need_larger_matrices
;
16584 /* If cursor did not appear assume that the middle of the window is
16585 in the first line of the window. Do it again with the next line.
16586 (Imagine a window of height 100, displaying two lines of height
16587 60. Moving back 50 from it->last_visible_y will end in the first
16589 if (w
->cursor
.vpos
< 0)
16591 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16593 clear_glyph_matrix (w
->desired_matrix
);
16594 move_it_by_lines (&it
, 1);
16595 try_window (window
, it
.current
.pos
, 0);
16597 else if (PT
< IT_CHARPOS (it
))
16599 clear_glyph_matrix (w
->desired_matrix
);
16600 move_it_by_lines (&it
, -1);
16601 try_window (window
, it
.current
.pos
, 0);
16605 /* Not much we can do about it. */
16609 /* Consider the following case: Window starts at BEGV, there is
16610 invisible, intangible text at BEGV, so that display starts at
16611 some point START > BEGV. It can happen that we are called with
16612 PT somewhere between BEGV and START. Try to handle that case,
16613 and similar ones. */
16614 if (w
->cursor
.vpos
< 0)
16616 /* First, try locating the proper glyph row for PT. */
16617 struct glyph_row
*row
=
16618 row_containing_pos (w
, PT
, w
->current_matrix
->rows
, NULL
, 0);
16620 /* Sometimes point is at the beginning of invisible text that is
16621 before the 1st character displayed in the row. In that case,
16622 row_containing_pos fails to find the row, because no glyphs
16623 with appropriate buffer positions are present in the row.
16624 Therefore, we next try to find the row which shows the 1st
16625 position after the invisible text. */
16629 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16632 if (TEXT_PROP_MEANS_INVISIBLE (val
) != 0)
16635 Lisp_Object invis_end
=
16636 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16639 if (NATNUMP (invis_end
))
16640 alt_pos
= XFASTINT (invis_end
);
16643 row
= row_containing_pos (w
, alt_pos
, w
->current_matrix
->rows
,
16647 /* Finally, fall back on the first row of the window after the
16648 header line (if any). This is slightly better than not
16649 displaying the cursor at all. */
16652 row
= w
->current_matrix
->rows
;
16653 if (row
->mode_line_p
)
16656 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16659 if (!cursor_row_fully_visible_p (w
, false, false))
16661 /* If vscroll is enabled, disable it and try again. */
16665 clear_glyph_matrix (w
->desired_matrix
);
16669 /* Users who set scroll-conservatively to a large number want
16670 point just above/below the scroll margin. If we ended up
16671 with point's row partially visible, move the window start to
16672 make that row fully visible and out of the margin. */
16673 if (scroll_conservatively
> SCROLL_LIMIT
)
16675 int window_total_lines
16676 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16679 ? min (scroll_margin
, window_total_lines
/ 4)
16681 bool move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16683 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16684 clear_glyph_matrix (w
->desired_matrix
);
16685 if (1 == try_window (window
, it
.current
.pos
,
16686 TRY_WINDOW_CHECK_MARGINS
))
16690 /* If centering point failed to make the whole line visible,
16691 put point at the top instead. That has to make the whole line
16692 visible, if it can be done. */
16693 if (centering_position
== 0)
16696 clear_glyph_matrix (w
->desired_matrix
);
16697 centering_position
= 0;
16703 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16704 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16705 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16707 /* Display the mode line, if we must. */
16708 if ((update_mode_line
16709 /* If window not full width, must redo its mode line
16710 if (a) the window to its side is being redone and
16711 (b) we do a frame-based redisplay. This is a consequence
16712 of how inverted lines are drawn in frame-based redisplay. */
16713 || (!just_this_one_p
16714 && !FRAME_WINDOW_P (f
)
16715 && !WINDOW_FULL_WIDTH_P (w
))
16716 /* Line number to display. */
16717 || w
->base_line_pos
> 0
16718 /* Column number is displayed and different from the one displayed. */
16719 || (w
->column_number_displayed
!= -1
16720 && (w
->column_number_displayed
!= current_column ())))
16721 /* This means that the window has a mode line. */
16722 && (WINDOW_WANTS_MODELINE_P (w
)
16723 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16726 display_mode_lines (w
);
16728 /* If mode line height has changed, arrange for a thorough
16729 immediate redisplay using the correct mode line height. */
16730 if (WINDOW_WANTS_MODELINE_P (w
)
16731 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16733 f
->fonts_changed
= true;
16734 w
->mode_line_height
= -1;
16735 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16736 = DESIRED_MODE_LINE_HEIGHT (w
);
16739 /* If header line height has changed, arrange for a thorough
16740 immediate redisplay using the correct header line height. */
16741 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16742 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16744 f
->fonts_changed
= true;
16745 w
->header_line_height
= -1;
16746 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16747 = DESIRED_HEADER_LINE_HEIGHT (w
);
16750 if (f
->fonts_changed
)
16751 goto need_larger_matrices
;
16754 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16756 w
->base_line_pos
= 0;
16757 w
->base_line_number
= 0;
16762 /* When we reach a frame's selected window, redo the frame's menu bar. */
16763 if (update_mode_line
16764 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16766 bool redisplay_menu_p
;
16768 if (FRAME_WINDOW_P (f
))
16770 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16771 || defined (HAVE_NS) || defined (USE_GTK)
16772 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16774 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16778 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16780 if (redisplay_menu_p
)
16781 display_menu_bar (w
);
16783 #ifdef HAVE_WINDOW_SYSTEM
16784 if (FRAME_WINDOW_P (f
))
16786 #if defined (USE_GTK) || defined (HAVE_NS)
16787 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16788 redisplay_tool_bar (f
);
16790 if (WINDOWP (f
->tool_bar_window
)
16791 && (FRAME_TOOL_BAR_LINES (f
) > 0
16792 || !NILP (Vauto_resize_tool_bars
))
16793 && redisplay_tool_bar (f
))
16794 ignore_mouse_drag_p
= true;
16800 #ifdef HAVE_WINDOW_SYSTEM
16801 if (FRAME_WINDOW_P (f
)
16802 && update_window_fringes (w
, (just_this_one_p
16803 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16804 || w
->pseudo_window_p
)))
16808 if (draw_window_fringes (w
, true))
16810 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
16811 x_draw_right_divider (w
);
16813 x_draw_vertical_border (w
);
16819 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
16820 x_draw_bottom_divider (w
);
16821 #endif /* HAVE_WINDOW_SYSTEM */
16823 /* We go to this label, with fonts_changed set, if it is
16824 necessary to try again using larger glyph matrices.
16825 We have to redeem the scroll bar even in this case,
16826 because the loop in redisplay_internal expects that. */
16827 need_larger_matrices
:
16829 finish_scroll_bars
:
16831 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
16833 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16834 /* Set the thumb's position and size. */
16835 set_vertical_scroll_bar (w
);
16837 if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
16838 /* Set the thumb's position and size. */
16839 set_horizontal_scroll_bar (w
);
16841 /* Note that we actually used the scroll bar attached to this
16842 window, so it shouldn't be deleted at the end of redisplay. */
16843 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16844 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16847 /* Restore current_buffer and value of point in it. The window
16848 update may have changed the buffer, so first make sure `opoint'
16849 is still valid (Bug#6177). */
16850 if (CHARPOS (opoint
) < BEGV
)
16851 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16852 else if (CHARPOS (opoint
) > ZV
)
16853 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16855 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16857 set_buffer_internal_1 (old
);
16858 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16859 shorter. This can be caused by log truncation in *Messages*. */
16860 if (CHARPOS (lpoint
) <= ZV
)
16861 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16863 unbind_to (count
, Qnil
);
16867 /* Build the complete desired matrix of WINDOW with a window start
16868 buffer position POS.
16870 Value is 1 if successful. It is zero if fonts were loaded during
16871 redisplay which makes re-adjusting glyph matrices necessary, and -1
16872 if point would appear in the scroll margins.
16873 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16874 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16878 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16880 struct window
*w
= XWINDOW (window
);
16882 struct glyph_row
*last_text_row
= NULL
;
16883 struct frame
*f
= XFRAME (w
->frame
);
16884 int frame_line_height
= default_line_pixel_height (w
);
16886 /* Make POS the new window start. */
16887 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16889 /* Mark cursor position as unknown. No overlay arrow seen. */
16890 w
->cursor
.vpos
= -1;
16891 overlay_arrow_seen
= false;
16893 /* Initialize iterator and info to start at POS. */
16894 start_display (&it
, w
, pos
);
16895 it
.glyph_row
->reversed_p
= false;
16897 /* Display all lines of W. */
16898 while (it
.current_y
< it
.last_visible_y
)
16900 if (display_line (&it
))
16901 last_text_row
= it
.glyph_row
- 1;
16902 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16906 /* Don't let the cursor end in the scroll margins. */
16907 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16908 && !MINI_WINDOW_P (w
))
16910 int this_scroll_margin
;
16911 int window_total_lines
16912 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16914 if (scroll_margin
> 0)
16916 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16917 this_scroll_margin
*= frame_line_height
;
16920 this_scroll_margin
= 0;
16922 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16923 && w
->cursor
.y
< this_scroll_margin
16924 && CHARPOS (pos
) > BEGV
16925 && IT_CHARPOS (it
) < ZV
)
16926 /* rms: considering make_cursor_line_fully_visible_p here
16927 seems to give wrong results. We don't want to recenter
16928 when the last line is partly visible, we want to allow
16929 that case to be handled in the usual way. */
16930 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16932 w
->cursor
.vpos
= -1;
16933 clear_glyph_matrix (w
->desired_matrix
);
16938 /* If bottom moved off end of frame, change mode line percentage. */
16939 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16940 w
->update_mode_line
= true;
16942 /* Set window_end_pos to the offset of the last character displayed
16943 on the window from the end of current_buffer. Set
16944 window_end_vpos to its row number. */
16947 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16948 adjust_window_ends (w
, last_text_row
, false);
16950 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16951 w
->window_end_vpos
)));
16955 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16956 w
->window_end_pos
= Z
- ZV
;
16957 w
->window_end_vpos
= 0;
16960 /* But that is not valid info until redisplay finishes. */
16961 w
->window_end_valid
= false;
16967 /************************************************************************
16968 Window redisplay reusing current matrix when buffer has not changed
16969 ************************************************************************/
16971 /* Try redisplay of window W showing an unchanged buffer with a
16972 different window start than the last time it was displayed by
16973 reusing its current matrix. Value is true if successful.
16974 W->start is the new window start. */
16977 try_window_reusing_current_matrix (struct window
*w
)
16979 struct frame
*f
= XFRAME (w
->frame
);
16980 struct glyph_row
*bottom_row
;
16983 struct text_pos start
, new_start
;
16984 int nrows_scrolled
, i
;
16985 struct glyph_row
*last_text_row
;
16986 struct glyph_row
*last_reused_text_row
;
16987 struct glyph_row
*start_row
;
16988 int start_vpos
, min_y
, max_y
;
16991 if (inhibit_try_window_reusing
)
16995 if (/* This function doesn't handle terminal frames. */
16996 !FRAME_WINDOW_P (f
)
16997 /* Don't try to reuse the display if windows have been split
16999 || windows_or_buffers_changed
17000 || f
->cursor_type_changed
)
17003 /* Can't do this if showing trailing whitespace. */
17004 if (!NILP (Vshow_trailing_whitespace
))
17007 /* If top-line visibility has changed, give up. */
17008 if (WINDOW_WANTS_HEADER_LINE_P (w
)
17009 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
17012 /* Give up if old or new display is scrolled vertically. We could
17013 make this function handle this, but right now it doesn't. */
17014 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17015 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
17018 /* The variable new_start now holds the new window start. The old
17019 start `start' can be determined from the current matrix. */
17020 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
17021 start
= start_row
->minpos
;
17022 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17024 /* Clear the desired matrix for the display below. */
17025 clear_glyph_matrix (w
->desired_matrix
);
17027 if (CHARPOS (new_start
) <= CHARPOS (start
))
17029 /* Don't use this method if the display starts with an ellipsis
17030 displayed for invisible text. It's not easy to handle that case
17031 below, and it's certainly not worth the effort since this is
17032 not a frequent case. */
17033 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
17036 IF_DEBUG (debug_method_add (w
, "twu1"));
17038 /* Display up to a row that can be reused. The variable
17039 last_text_row is set to the last row displayed that displays
17040 text. Note that it.vpos == 0 if or if not there is a
17041 header-line; it's not the same as the MATRIX_ROW_VPOS! */
17042 start_display (&it
, w
, new_start
);
17043 w
->cursor
.vpos
= -1;
17044 last_text_row
= last_reused_text_row
= NULL
;
17046 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17048 /* If we have reached into the characters in the START row,
17049 that means the line boundaries have changed. So we
17050 can't start copying with the row START. Maybe it will
17051 work to start copying with the following row. */
17052 while (IT_CHARPOS (it
) > CHARPOS (start
))
17054 /* Advance to the next row as the "start". */
17056 start
= start_row
->minpos
;
17057 /* If there are no more rows to try, or just one, give up. */
17058 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
17059 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
17060 || CHARPOS (start
) == ZV
)
17062 clear_glyph_matrix (w
->desired_matrix
);
17066 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17068 /* If we have reached alignment, we can copy the rest of the
17070 if (IT_CHARPOS (it
) == CHARPOS (start
)
17071 /* Don't accept "alignment" inside a display vector,
17072 since start_row could have started in the middle of
17073 that same display vector (thus their character
17074 positions match), and we have no way of telling if
17075 that is the case. */
17076 && it
.current
.dpvec_index
< 0)
17079 it
.glyph_row
->reversed_p
= false;
17080 if (display_line (&it
))
17081 last_text_row
= it
.glyph_row
- 1;
17085 /* A value of current_y < last_visible_y means that we stopped
17086 at the previous window start, which in turn means that we
17087 have at least one reusable row. */
17088 if (it
.current_y
< it
.last_visible_y
)
17090 struct glyph_row
*row
;
17092 /* IT.vpos always starts from 0; it counts text lines. */
17093 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
17095 /* Find PT if not already found in the lines displayed. */
17096 if (w
->cursor
.vpos
< 0)
17098 int dy
= it
.current_y
- start_row
->y
;
17100 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17101 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
17103 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
17104 dy
, nrows_scrolled
);
17107 clear_glyph_matrix (w
->desired_matrix
);
17112 /* Scroll the display. Do it before the current matrix is
17113 changed. The problem here is that update has not yet
17114 run, i.e. part of the current matrix is not up to date.
17115 scroll_run_hook will clear the cursor, and use the
17116 current matrix to get the height of the row the cursor is
17118 run
.current_y
= start_row
->y
;
17119 run
.desired_y
= it
.current_y
;
17120 run
.height
= it
.last_visible_y
- it
.current_y
;
17122 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
17125 FRAME_RIF (f
)->update_window_begin_hook (w
);
17126 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17127 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17128 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17132 /* Shift current matrix down by nrows_scrolled lines. */
17133 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17134 rotate_matrix (w
->current_matrix
,
17136 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17139 /* Disable lines that must be updated. */
17140 for (i
= 0; i
< nrows_scrolled
; ++i
)
17141 (start_row
+ i
)->enabled_p
= false;
17143 /* Re-compute Y positions. */
17144 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17145 max_y
= it
.last_visible_y
;
17146 for (row
= start_row
+ nrows_scrolled
;
17150 row
->y
= it
.current_y
;
17151 row
->visible_height
= row
->height
;
17153 if (row
->y
< min_y
)
17154 row
->visible_height
-= min_y
- row
->y
;
17155 if (row
->y
+ row
->height
> max_y
)
17156 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17157 if (row
->fringe_bitmap_periodic_p
)
17158 row
->redraw_fringe_bitmaps_p
= true;
17160 it
.current_y
+= row
->height
;
17162 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17163 last_reused_text_row
= row
;
17164 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
17168 /* Disable lines in the current matrix which are now
17169 below the window. */
17170 for (++row
; row
< bottom_row
; ++row
)
17171 row
->enabled_p
= row
->mode_line_p
= false;
17174 /* Update window_end_pos etc.; last_reused_text_row is the last
17175 reused row from the current matrix containing text, if any.
17176 The value of last_text_row is the last displayed line
17177 containing text. */
17178 if (last_reused_text_row
)
17179 adjust_window_ends (w
, last_reused_text_row
, true);
17180 else if (last_text_row
)
17181 adjust_window_ends (w
, last_text_row
, false);
17184 /* This window must be completely empty. */
17185 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17186 w
->window_end_pos
= Z
- ZV
;
17187 w
->window_end_vpos
= 0;
17189 w
->window_end_valid
= false;
17191 /* Update hint: don't try scrolling again in update_window. */
17192 w
->desired_matrix
->no_scrolling_p
= true;
17195 debug_method_add (w
, "try_window_reusing_current_matrix 1");
17199 else if (CHARPOS (new_start
) > CHARPOS (start
))
17201 struct glyph_row
*pt_row
, *row
;
17202 struct glyph_row
*first_reusable_row
;
17203 struct glyph_row
*first_row_to_display
;
17205 int yb
= window_text_bottom_y (w
);
17207 /* Find the row starting at new_start, if there is one. Don't
17208 reuse a partially visible line at the end. */
17209 first_reusable_row
= start_row
;
17210 while (first_reusable_row
->enabled_p
17211 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
17212 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17213 < CHARPOS (new_start
)))
17214 ++first_reusable_row
;
17216 /* Give up if there is no row to reuse. */
17217 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
17218 || !first_reusable_row
->enabled_p
17219 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17220 != CHARPOS (new_start
)))
17223 /* We can reuse fully visible rows beginning with
17224 first_reusable_row to the end of the window. Set
17225 first_row_to_display to the first row that cannot be reused.
17226 Set pt_row to the row containing point, if there is any. */
17228 for (first_row_to_display
= first_reusable_row
;
17229 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
17230 ++first_row_to_display
)
17232 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
17233 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17234 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17235 && first_row_to_display
->ends_at_zv_p
17236 && pt_row
== NULL
)))
17237 pt_row
= first_row_to_display
;
17240 /* Start displaying at the start of first_row_to_display. */
17241 eassert (first_row_to_display
->y
< yb
);
17242 init_to_row_start (&it
, w
, first_row_to_display
);
17244 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
17246 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
17248 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
17249 + WINDOW_HEADER_LINE_HEIGHT (w
));
17251 /* Display lines beginning with first_row_to_display in the
17252 desired matrix. Set last_text_row to the last row displayed
17253 that displays text. */
17254 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
17255 if (pt_row
== NULL
)
17256 w
->cursor
.vpos
= -1;
17257 last_text_row
= NULL
;
17258 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17259 if (display_line (&it
))
17260 last_text_row
= it
.glyph_row
- 1;
17262 /* If point is in a reused row, adjust y and vpos of the cursor
17266 w
->cursor
.vpos
-= nrows_scrolled
;
17267 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
17270 /* Give up if point isn't in a row displayed or reused. (This
17271 also handles the case where w->cursor.vpos < nrows_scrolled
17272 after the calls to display_line, which can happen with scroll
17273 margins. See bug#1295.) */
17274 if (w
->cursor
.vpos
< 0)
17276 clear_glyph_matrix (w
->desired_matrix
);
17280 /* Scroll the display. */
17281 run
.current_y
= first_reusable_row
->y
;
17282 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17283 run
.height
= it
.last_visible_y
- run
.current_y
;
17284 dy
= run
.current_y
- run
.desired_y
;
17289 FRAME_RIF (f
)->update_window_begin_hook (w
);
17290 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17291 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17292 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17296 /* Adjust Y positions of reused rows. */
17297 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17298 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17299 max_y
= it
.last_visible_y
;
17300 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
17303 row
->visible_height
= row
->height
;
17304 if (row
->y
< min_y
)
17305 row
->visible_height
-= min_y
- row
->y
;
17306 if (row
->y
+ row
->height
> max_y
)
17307 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17308 if (row
->fringe_bitmap_periodic_p
)
17309 row
->redraw_fringe_bitmaps_p
= true;
17312 /* Scroll the current matrix. */
17313 eassert (nrows_scrolled
> 0);
17314 rotate_matrix (w
->current_matrix
,
17316 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17319 /* Disable rows not reused. */
17320 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
17321 row
->enabled_p
= false;
17323 /* Point may have moved to a different line, so we cannot assume that
17324 the previous cursor position is valid; locate the correct row. */
17327 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
17329 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
17330 && !row
->ends_at_zv_p
;
17334 w
->cursor
.y
= row
->y
;
17336 if (row
< bottom_row
)
17338 /* Can't simply scan the row for point with
17339 bidi-reordered glyph rows. Let set_cursor_from_row
17340 figure out where to put the cursor, and if it fails,
17342 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
17344 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
17347 clear_glyph_matrix (w
->desired_matrix
);
17353 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
17354 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17357 && (!BUFFERP (glyph
->object
)
17358 || glyph
->charpos
< PT
);
17362 w
->cursor
.x
+= glyph
->pixel_width
;
17368 /* Adjust window end. A null value of last_text_row means that
17369 the window end is in reused rows which in turn means that
17370 only its vpos can have changed. */
17372 adjust_window_ends (w
, last_text_row
, false);
17374 w
->window_end_vpos
-= nrows_scrolled
;
17376 w
->window_end_valid
= false;
17377 w
->desired_matrix
->no_scrolling_p
= true;
17380 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17390 /************************************************************************
17391 Window redisplay reusing current matrix when buffer has changed
17392 ************************************************************************/
17394 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17395 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17396 ptrdiff_t *, ptrdiff_t *);
17397 static struct glyph_row
*
17398 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17399 struct glyph_row
*);
17402 /* Return the last row in MATRIX displaying text. If row START is
17403 non-null, start searching with that row. IT gives the dimensions
17404 of the display. Value is null if matrix is empty; otherwise it is
17405 a pointer to the row found. */
17407 static struct glyph_row
*
17408 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17409 struct glyph_row
*start
)
17411 struct glyph_row
*row
, *row_found
;
17413 /* Set row_found to the last row in IT->w's current matrix
17414 displaying text. The loop looks funny but think of partially
17417 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17418 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17420 eassert (row
->enabled_p
);
17422 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17431 /* Return the last row in the current matrix of W that is not affected
17432 by changes at the start of current_buffer that occurred since W's
17433 current matrix was built. Value is null if no such row exists.
17435 BEG_UNCHANGED us the number of characters unchanged at the start of
17436 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17437 first changed character in current_buffer. Characters at positions <
17438 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17439 when the current matrix was built. */
17441 static struct glyph_row
*
17442 find_last_unchanged_at_beg_row (struct window
*w
)
17444 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17445 struct glyph_row
*row
;
17446 struct glyph_row
*row_found
= NULL
;
17447 int yb
= window_text_bottom_y (w
);
17449 /* Find the last row displaying unchanged text. */
17450 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17451 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17452 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17455 if (/* If row ends before first_changed_pos, it is unchanged,
17456 except in some case. */
17457 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17458 /* When row ends in ZV and we write at ZV it is not
17460 && !row
->ends_at_zv_p
17461 /* When first_changed_pos is the end of a continued line,
17462 row is not unchanged because it may be no longer
17464 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17465 && (row
->continued_p
17466 || row
->exact_window_width_line_p
))
17467 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17468 needs to be recomputed, so don't consider this row as
17469 unchanged. This happens when the last line was
17470 bidi-reordered and was killed immediately before this
17471 redisplay cycle. In that case, ROW->end stores the
17472 buffer position of the first visual-order character of
17473 the killed text, which is now beyond ZV. */
17474 && CHARPOS (row
->end
.pos
) <= ZV
)
17477 /* Stop if last visible row. */
17478 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17486 /* Find the first glyph row in the current matrix of W that is not
17487 affected by changes at the end of current_buffer since the
17488 time W's current matrix was built.
17490 Return in *DELTA the number of chars by which buffer positions in
17491 unchanged text at the end of current_buffer must be adjusted.
17493 Return in *DELTA_BYTES the corresponding number of bytes.
17495 Value is null if no such row exists, i.e. all rows are affected by
17498 static struct glyph_row
*
17499 find_first_unchanged_at_end_row (struct window
*w
,
17500 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17502 struct glyph_row
*row
;
17503 struct glyph_row
*row_found
= NULL
;
17505 *delta
= *delta_bytes
= 0;
17507 /* Display must not have been paused, otherwise the current matrix
17508 is not up to date. */
17509 eassert (w
->window_end_valid
);
17511 /* A value of window_end_pos >= END_UNCHANGED means that the window
17512 end is in the range of changed text. If so, there is no
17513 unchanged row at the end of W's current matrix. */
17514 if (w
->window_end_pos
>= END_UNCHANGED
)
17517 /* Set row to the last row in W's current matrix displaying text. */
17518 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17520 /* If matrix is entirely empty, no unchanged row exists. */
17521 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17523 /* The value of row is the last glyph row in the matrix having a
17524 meaningful buffer position in it. The end position of row
17525 corresponds to window_end_pos. This allows us to translate
17526 buffer positions in the current matrix to current buffer
17527 positions for characters not in changed text. */
17529 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17530 ptrdiff_t Z_BYTE_old
=
17531 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17532 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17533 struct glyph_row
*first_text_row
17534 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17536 *delta
= Z
- Z_old
;
17537 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17539 /* Set last_unchanged_pos to the buffer position of the last
17540 character in the buffer that has not been changed. Z is the
17541 index + 1 of the last character in current_buffer, i.e. by
17542 subtracting END_UNCHANGED we get the index of the last
17543 unchanged character, and we have to add BEG to get its buffer
17545 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17546 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17548 /* Search backward from ROW for a row displaying a line that
17549 starts at a minimum position >= last_unchanged_pos_old. */
17550 for (; row
> first_text_row
; --row
)
17552 /* This used to abort, but it can happen.
17553 It is ok to just stop the search instead here. KFS. */
17554 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17557 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17562 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17568 /* Make sure that glyph rows in the current matrix of window W
17569 reference the same glyph memory as corresponding rows in the
17570 frame's frame matrix. This function is called after scrolling W's
17571 current matrix on a terminal frame in try_window_id and
17572 try_window_reusing_current_matrix. */
17575 sync_frame_with_window_matrix_rows (struct window
*w
)
17577 struct frame
*f
= XFRAME (w
->frame
);
17578 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17580 /* Preconditions: W must be a leaf window and full-width. Its frame
17581 must have a frame matrix. */
17582 eassert (BUFFERP (w
->contents
));
17583 eassert (WINDOW_FULL_WIDTH_P (w
));
17584 eassert (!FRAME_WINDOW_P (f
));
17586 /* If W is a full-width window, glyph pointers in W's current matrix
17587 have, by definition, to be the same as glyph pointers in the
17588 corresponding frame matrix. Note that frame matrices have no
17589 marginal areas (see build_frame_matrix). */
17590 window_row
= w
->current_matrix
->rows
;
17591 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17592 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17593 while (window_row
< window_row_end
)
17595 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17596 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17598 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17599 frame_row
->glyphs
[TEXT_AREA
] = start
;
17600 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17601 frame_row
->glyphs
[LAST_AREA
] = end
;
17603 /* Disable frame rows whose corresponding window rows have
17604 been disabled in try_window_id. */
17605 if (!window_row
->enabled_p
)
17606 frame_row
->enabled_p
= false;
17608 ++window_row
, ++frame_row
;
17613 /* Find the glyph row in window W containing CHARPOS. Consider all
17614 rows between START and END (not inclusive). END null means search
17615 all rows to the end of the display area of W. Value is the row
17616 containing CHARPOS or null. */
17619 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17620 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17622 struct glyph_row
*row
= start
;
17623 struct glyph_row
*best_row
= NULL
;
17624 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17627 /* If we happen to start on a header-line, skip that. */
17628 if (row
->mode_line_p
)
17631 if ((end
&& row
>= end
) || !row
->enabled_p
)
17634 last_y
= window_text_bottom_y (w
) - dy
;
17638 /* Give up if we have gone too far. */
17639 if (end
&& row
>= end
)
17641 /* This formerly returned if they were equal.
17642 I think that both quantities are of a "last plus one" type;
17643 if so, when they are equal, the row is within the screen. -- rms. */
17644 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17647 /* If it is in this row, return this row. */
17648 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17649 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17650 /* The end position of a row equals the start
17651 position of the next row. If CHARPOS is there, we
17652 would rather consider it displayed in the next
17653 line, except when this line ends in ZV. */
17654 && !row_for_charpos_p (row
, charpos
)))
17655 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17659 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17660 || (!best_row
&& !row
->continued_p
))
17662 /* In bidi-reordered rows, there could be several rows whose
17663 edges surround CHARPOS, all of these rows belonging to
17664 the same continued line. We need to find the row which
17665 fits CHARPOS the best. */
17666 for (g
= row
->glyphs
[TEXT_AREA
];
17667 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17670 if (!STRINGP (g
->object
))
17672 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17674 mindif
= eabs (g
->charpos
- charpos
);
17676 /* Exact match always wins. */
17683 else if (best_row
&& !row
->continued_p
)
17690 /* Try to redisplay window W by reusing its existing display. W's
17691 current matrix must be up to date when this function is called,
17692 i.e., window_end_valid must be true.
17696 >= 1 if successful, i.e. display has been updated
17698 1 means the changes were in front of a newline that precedes
17699 the window start, and the whole current matrix was reused
17700 2 means the changes were after the last position displayed
17701 in the window, and the whole current matrix was reused
17702 3 means portions of the current matrix were reused, while
17703 some of the screen lines were redrawn
17704 -1 if redisplay with same window start is known not to succeed
17705 0 if otherwise unsuccessful
17707 The following steps are performed:
17709 1. Find the last row in the current matrix of W that is not
17710 affected by changes at the start of current_buffer. If no such row
17713 2. Find the first row in W's current matrix that is not affected by
17714 changes at the end of current_buffer. Maybe there is no such row.
17716 3. Display lines beginning with the row + 1 found in step 1 to the
17717 row found in step 2 or, if step 2 didn't find a row, to the end of
17720 4. If cursor is not known to appear on the window, give up.
17722 5. If display stopped at the row found in step 2, scroll the
17723 display and current matrix as needed.
17725 6. Maybe display some lines at the end of W, if we must. This can
17726 happen under various circumstances, like a partially visible line
17727 becoming fully visible, or because newly displayed lines are displayed
17728 in smaller font sizes.
17730 7. Update W's window end information. */
17733 try_window_id (struct window
*w
)
17735 struct frame
*f
= XFRAME (w
->frame
);
17736 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17737 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17738 struct glyph_row
*last_unchanged_at_beg_row
;
17739 struct glyph_row
*first_unchanged_at_end_row
;
17740 struct glyph_row
*row
;
17741 struct glyph_row
*bottom_row
;
17744 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17746 struct text_pos start_pos
;
17748 int first_unchanged_at_end_vpos
= 0;
17749 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17750 struct text_pos start
;
17751 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17754 if (inhibit_try_window_id
)
17758 /* This is handy for debugging. */
17760 #define GIVE_UP(X) \
17762 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17766 #define GIVE_UP(X) return 0
17769 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17771 /* Don't use this for mini-windows because these can show
17772 messages and mini-buffers, and we don't handle that here. */
17773 if (MINI_WINDOW_P (w
))
17776 /* This flag is used to prevent redisplay optimizations. */
17777 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17780 /* This function's optimizations cannot be used if overlays have
17781 changed in the buffer displayed by the window, so give up if they
17783 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
17786 /* Verify that narrowing has not changed.
17787 Also verify that we were not told to prevent redisplay optimizations.
17788 It would be nice to further
17789 reduce the number of cases where this prevents try_window_id. */
17790 if (current_buffer
->clip_changed
17791 || current_buffer
->prevent_redisplay_optimizations_p
)
17794 /* Window must either use window-based redisplay or be full width. */
17795 if (!FRAME_WINDOW_P (f
)
17796 && (!FRAME_LINE_INS_DEL_OK (f
)
17797 || !WINDOW_FULL_WIDTH_P (w
)))
17800 /* Give up if point is known NOT to appear in W. */
17801 if (PT
< CHARPOS (start
))
17804 /* Another way to prevent redisplay optimizations. */
17805 if (w
->last_modified
== 0)
17808 /* Verify that window is not hscrolled. */
17809 if (w
->hscroll
!= 0)
17812 /* Verify that display wasn't paused. */
17813 if (!w
->window_end_valid
)
17816 /* Likewise if highlighting trailing whitespace. */
17817 if (!NILP (Vshow_trailing_whitespace
))
17820 /* Can't use this if overlay arrow position and/or string have
17822 if (overlay_arrows_changed_p ())
17825 /* When word-wrap is on, adding a space to the first word of a
17826 wrapped line can change the wrap position, altering the line
17827 above it. It might be worthwhile to handle this more
17828 intelligently, but for now just redisplay from scratch. */
17829 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17832 /* Under bidi reordering, adding or deleting a character in the
17833 beginning of a paragraph, before the first strong directional
17834 character, can change the base direction of the paragraph (unless
17835 the buffer specifies a fixed paragraph direction), which will
17836 require to redisplay the whole paragraph. It might be worthwhile
17837 to find the paragraph limits and widen the range of redisplayed
17838 lines to that, but for now just give up this optimization and
17839 redisplay from scratch. */
17840 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17841 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17844 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17845 only if buffer has really changed. The reason is that the gap is
17846 initially at Z for freshly visited files. The code below would
17847 set end_unchanged to 0 in that case. */
17848 if (MODIFF
> SAVE_MODIFF
17849 /* This seems to happen sometimes after saving a buffer. */
17850 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17852 if (GPT
- BEG
< BEG_UNCHANGED
)
17853 BEG_UNCHANGED
= GPT
- BEG
;
17854 if (Z
- GPT
< END_UNCHANGED
)
17855 END_UNCHANGED
= Z
- GPT
;
17858 /* The position of the first and last character that has been changed. */
17859 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17860 last_changed_charpos
= Z
- END_UNCHANGED
;
17862 /* If window starts after a line end, and the last change is in
17863 front of that newline, then changes don't affect the display.
17864 This case happens with stealth-fontification. Note that although
17865 the display is unchanged, glyph positions in the matrix have to
17866 be adjusted, of course. */
17867 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17868 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17869 && ((last_changed_charpos
< CHARPOS (start
)
17870 && CHARPOS (start
) == BEGV
)
17871 || (last_changed_charpos
< CHARPOS (start
) - 1
17872 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17874 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17875 struct glyph_row
*r0
;
17877 /* Compute how many chars/bytes have been added to or removed
17878 from the buffer. */
17879 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17880 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17881 Z_delta
= Z
- Z_old
;
17882 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17884 /* Give up if PT is not in the window. Note that it already has
17885 been checked at the start of try_window_id that PT is not in
17886 front of the window start. */
17887 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17890 /* If window start is unchanged, we can reuse the whole matrix
17891 as is, after adjusting glyph positions. No need to compute
17892 the window end again, since its offset from Z hasn't changed. */
17893 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17894 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17895 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17896 /* PT must not be in a partially visible line. */
17897 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17898 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17900 /* Adjust positions in the glyph matrix. */
17901 if (Z_delta
|| Z_delta_bytes
)
17903 struct glyph_row
*r1
17904 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17905 increment_matrix_positions (w
->current_matrix
,
17906 MATRIX_ROW_VPOS (r0
, current_matrix
),
17907 MATRIX_ROW_VPOS (r1
, current_matrix
),
17908 Z_delta
, Z_delta_bytes
);
17911 /* Set the cursor. */
17912 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17914 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17919 /* Handle the case that changes are all below what is displayed in
17920 the window, and that PT is in the window. This shortcut cannot
17921 be taken if ZV is visible in the window, and text has been added
17922 there that is visible in the window. */
17923 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17924 /* ZV is not visible in the window, or there are no
17925 changes at ZV, actually. */
17926 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17927 || first_changed_charpos
== last_changed_charpos
))
17929 struct glyph_row
*r0
;
17931 /* Give up if PT is not in the window. Note that it already has
17932 been checked at the start of try_window_id that PT is not in
17933 front of the window start. */
17934 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17937 /* If window start is unchanged, we can reuse the whole matrix
17938 as is, without changing glyph positions since no text has
17939 been added/removed in front of the window end. */
17940 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17941 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17942 /* PT must not be in a partially visible line. */
17943 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17944 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17946 /* We have to compute the window end anew since text
17947 could have been added/removed after it. */
17948 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17949 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17951 /* Set the cursor. */
17952 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17954 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17959 /* Give up if window start is in the changed area.
17961 The condition used to read
17963 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17965 but why that was tested escapes me at the moment. */
17966 if (CHARPOS (start
) >= first_changed_charpos
17967 && CHARPOS (start
) <= last_changed_charpos
)
17970 /* Check that window start agrees with the start of the first glyph
17971 row in its current matrix. Check this after we know the window
17972 start is not in changed text, otherwise positions would not be
17974 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17975 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17978 /* Give up if the window ends in strings. Overlay strings
17979 at the end are difficult to handle, so don't try. */
17980 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17981 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17984 /* Compute the position at which we have to start displaying new
17985 lines. Some of the lines at the top of the window might be
17986 reusable because they are not displaying changed text. Find the
17987 last row in W's current matrix not affected by changes at the
17988 start of current_buffer. Value is null if changes start in the
17989 first line of window. */
17990 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17991 if (last_unchanged_at_beg_row
)
17993 /* Avoid starting to display in the middle of a character, a TAB
17994 for instance. This is easier than to set up the iterator
17995 exactly, and it's not a frequent case, so the additional
17996 effort wouldn't really pay off. */
17997 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17998 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17999 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
18000 --last_unchanged_at_beg_row
;
18002 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
18005 if (! init_to_row_end (&it
, w
, last_unchanged_at_beg_row
))
18007 start_pos
= it
.current
.pos
;
18009 /* Start displaying new lines in the desired matrix at the same
18010 vpos we would use in the current matrix, i.e. below
18011 last_unchanged_at_beg_row. */
18012 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
18014 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18015 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
18017 eassert (it
.hpos
== 0 && it
.current_x
== 0);
18021 /* There are no reusable lines at the start of the window.
18022 Start displaying in the first text line. */
18023 start_display (&it
, w
, start
);
18024 it
.vpos
= it
.first_vpos
;
18025 start_pos
= it
.current
.pos
;
18028 /* Find the first row that is not affected by changes at the end of
18029 the buffer. Value will be null if there is no unchanged row, in
18030 which case we must redisplay to the end of the window. delta
18031 will be set to the value by which buffer positions beginning with
18032 first_unchanged_at_end_row have to be adjusted due to text
18034 first_unchanged_at_end_row
18035 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
18036 IF_DEBUG (debug_delta
= delta
);
18037 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
18039 /* Set stop_pos to the buffer position up to which we will have to
18040 display new lines. If first_unchanged_at_end_row != NULL, this
18041 is the buffer position of the start of the line displayed in that
18042 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
18043 that we don't stop at a buffer position. */
18045 if (first_unchanged_at_end_row
)
18047 eassert (last_unchanged_at_beg_row
== NULL
18048 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
18050 /* If this is a continuation line, move forward to the next one
18051 that isn't. Changes in lines above affect this line.
18052 Caution: this may move first_unchanged_at_end_row to a row
18053 not displaying text. */
18054 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
18055 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18056 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18057 < it
.last_visible_y
))
18058 ++first_unchanged_at_end_row
;
18060 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18061 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18062 >= it
.last_visible_y
))
18063 first_unchanged_at_end_row
= NULL
;
18066 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
18068 first_unchanged_at_end_vpos
18069 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
18070 eassert (stop_pos
>= Z
- END_UNCHANGED
);
18073 else if (last_unchanged_at_beg_row
== NULL
)
18079 /* Either there is no unchanged row at the end, or the one we have
18080 now displays text. This is a necessary condition for the window
18081 end pos calculation at the end of this function. */
18082 eassert (first_unchanged_at_end_row
== NULL
18083 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18085 debug_last_unchanged_at_beg_vpos
18086 = (last_unchanged_at_beg_row
18087 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
18089 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
18091 #endif /* GLYPH_DEBUG */
18094 /* Display new lines. Set last_text_row to the last new line
18095 displayed which has text on it, i.e. might end up as being the
18096 line where the window_end_vpos is. */
18097 w
->cursor
.vpos
= -1;
18098 last_text_row
= NULL
;
18099 overlay_arrow_seen
= false;
18100 if (it
.current_y
< it
.last_visible_y
18101 && !f
->fonts_changed
18102 && (first_unchanged_at_end_row
== NULL
18103 || IT_CHARPOS (it
) < stop_pos
))
18104 it
.glyph_row
->reversed_p
= false;
18105 while (it
.current_y
< it
.last_visible_y
18106 && !f
->fonts_changed
18107 && (first_unchanged_at_end_row
== NULL
18108 || IT_CHARPOS (it
) < stop_pos
))
18110 if (display_line (&it
))
18111 last_text_row
= it
.glyph_row
- 1;
18114 if (f
->fonts_changed
)
18117 /* The redisplay iterations in display_line above could have
18118 triggered font-lock, which could have done something that
18119 invalidates IT->w window's end-point information, on which we
18120 rely below. E.g., one package, which will remain unnamed, used
18121 to install a font-lock-fontify-region-function that called
18122 bury-buffer, whose side effect is to switch the buffer displayed
18123 by IT->w, and that predictably resets IT->w's window_end_valid
18124 flag, which we already tested at the entry to this function.
18125 Amply punish such packages/modes by giving up on this
18126 optimization in those cases. */
18127 if (!w
->window_end_valid
)
18129 clear_glyph_matrix (w
->desired_matrix
);
18133 /* Compute differences in buffer positions, y-positions etc. for
18134 lines reused at the bottom of the window. Compute what we can
18136 if (first_unchanged_at_end_row
18137 /* No lines reused because we displayed everything up to the
18138 bottom of the window. */
18139 && it
.current_y
< it
.last_visible_y
)
18142 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
18144 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
18145 run
.current_y
= first_unchanged_at_end_row
->y
;
18146 run
.desired_y
= run
.current_y
+ dy
;
18147 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
18151 delta
= delta_bytes
= dvpos
= dy
18152 = run
.current_y
= run
.desired_y
= run
.height
= 0;
18153 first_unchanged_at_end_row
= NULL
;
18155 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
18158 /* Find the cursor if not already found. We have to decide whether
18159 PT will appear on this window (it sometimes doesn't, but this is
18160 not a very frequent case.) This decision has to be made before
18161 the current matrix is altered. A value of cursor.vpos < 0 means
18162 that PT is either in one of the lines beginning at
18163 first_unchanged_at_end_row or below the window. Don't care for
18164 lines that might be displayed later at the window end; as
18165 mentioned, this is not a frequent case. */
18166 if (w
->cursor
.vpos
< 0)
18168 /* Cursor in unchanged rows at the top? */
18169 if (PT
< CHARPOS (start_pos
)
18170 && last_unchanged_at_beg_row
)
18172 row
= row_containing_pos (w
, PT
,
18173 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
18174 last_unchanged_at_beg_row
+ 1, 0);
18176 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
18179 /* Start from first_unchanged_at_end_row looking for PT. */
18180 else if (first_unchanged_at_end_row
)
18182 row
= row_containing_pos (w
, PT
- delta
,
18183 first_unchanged_at_end_row
, NULL
, 0);
18185 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
18186 delta_bytes
, dy
, dvpos
);
18189 /* Give up if cursor was not found. */
18190 if (w
->cursor
.vpos
< 0)
18192 clear_glyph_matrix (w
->desired_matrix
);
18197 /* Don't let the cursor end in the scroll margins. */
18199 int this_scroll_margin
, cursor_height
;
18200 int frame_line_height
= default_line_pixel_height (w
);
18201 int window_total_lines
18202 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
18204 this_scroll_margin
=
18205 max (0, min (scroll_margin
, window_total_lines
/ 4));
18206 this_scroll_margin
*= frame_line_height
;
18207 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
18209 if ((w
->cursor
.y
< this_scroll_margin
18210 && CHARPOS (start
) > BEGV
)
18211 /* Old redisplay didn't take scroll margin into account at the bottom,
18212 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
18213 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
18214 ? cursor_height
+ this_scroll_margin
18215 : 1)) > it
.last_visible_y
)
18217 w
->cursor
.vpos
= -1;
18218 clear_glyph_matrix (w
->desired_matrix
);
18223 /* Scroll the display. Do it before changing the current matrix so
18224 that xterm.c doesn't get confused about where the cursor glyph is
18226 if (dy
&& run
.height
)
18230 if (FRAME_WINDOW_P (f
))
18232 FRAME_RIF (f
)->update_window_begin_hook (w
);
18233 FRAME_RIF (f
)->clear_window_mouse_face (w
);
18234 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
18235 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
18239 /* Terminal frame. In this case, dvpos gives the number of
18240 lines to scroll by; dvpos < 0 means scroll up. */
18242 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
18243 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
18244 int end
= (WINDOW_TOP_EDGE_LINE (w
)
18245 + WINDOW_WANTS_HEADER_LINE_P (w
)
18246 + window_internal_height (w
));
18248 #if defined (HAVE_GPM) || defined (MSDOS)
18249 x_clear_window_mouse_face (w
);
18251 /* Perform the operation on the screen. */
18254 /* Scroll last_unchanged_at_beg_row to the end of the
18255 window down dvpos lines. */
18256 set_terminal_window (f
, end
);
18258 /* On dumb terminals delete dvpos lines at the end
18259 before inserting dvpos empty lines. */
18260 if (!FRAME_SCROLL_REGION_OK (f
))
18261 ins_del_lines (f
, end
- dvpos
, -dvpos
);
18263 /* Insert dvpos empty lines in front of
18264 last_unchanged_at_beg_row. */
18265 ins_del_lines (f
, from
, dvpos
);
18267 else if (dvpos
< 0)
18269 /* Scroll up last_unchanged_at_beg_vpos to the end of
18270 the window to last_unchanged_at_beg_vpos - |dvpos|. */
18271 set_terminal_window (f
, end
);
18273 /* Delete dvpos lines in front of
18274 last_unchanged_at_beg_vpos. ins_del_lines will set
18275 the cursor to the given vpos and emit |dvpos| delete
18277 ins_del_lines (f
, from
+ dvpos
, dvpos
);
18279 /* On a dumb terminal insert dvpos empty lines at the
18281 if (!FRAME_SCROLL_REGION_OK (f
))
18282 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
18285 set_terminal_window (f
, 0);
18291 /* Shift reused rows of the current matrix to the right position.
18292 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
18294 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18295 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
18298 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
18299 bottom_vpos
, dvpos
);
18300 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
18303 else if (dvpos
> 0)
18305 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
18306 bottom_vpos
, dvpos
);
18307 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
18308 first_unchanged_at_end_vpos
+ dvpos
);
18311 /* For frame-based redisplay, make sure that current frame and window
18312 matrix are in sync with respect to glyph memory. */
18313 if (!FRAME_WINDOW_P (f
))
18314 sync_frame_with_window_matrix_rows (w
);
18316 /* Adjust buffer positions in reused rows. */
18317 if (delta
|| delta_bytes
)
18318 increment_matrix_positions (current_matrix
,
18319 first_unchanged_at_end_vpos
+ dvpos
,
18320 bottom_vpos
, delta
, delta_bytes
);
18322 /* Adjust Y positions. */
18324 shift_glyph_matrix (w
, current_matrix
,
18325 first_unchanged_at_end_vpos
+ dvpos
,
18328 if (first_unchanged_at_end_row
)
18330 first_unchanged_at_end_row
+= dvpos
;
18331 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
18332 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
18333 first_unchanged_at_end_row
= NULL
;
18336 /* If scrolling up, there may be some lines to display at the end of
18338 last_text_row_at_end
= NULL
;
18341 /* Scrolling up can leave for example a partially visible line
18342 at the end of the window to be redisplayed. */
18343 /* Set last_row to the glyph row in the current matrix where the
18344 window end line is found. It has been moved up or down in
18345 the matrix by dvpos. */
18346 int last_vpos
= w
->window_end_vpos
+ dvpos
;
18347 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
18349 /* If last_row is the window end line, it should display text. */
18350 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
18352 /* If window end line was partially visible before, begin
18353 displaying at that line. Otherwise begin displaying with the
18354 line following it. */
18355 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
18357 init_to_row_start (&it
, w
, last_row
);
18358 it
.vpos
= last_vpos
;
18359 it
.current_y
= last_row
->y
;
18363 init_to_row_end (&it
, w
, last_row
);
18364 it
.vpos
= 1 + last_vpos
;
18365 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
18369 /* We may start in a continuation line. If so, we have to
18370 get the right continuation_lines_width and current_x. */
18371 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
18372 it
.hpos
= it
.current_x
= 0;
18374 /* Display the rest of the lines at the window end. */
18375 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18376 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
18378 /* Is it always sure that the display agrees with lines in
18379 the current matrix? I don't think so, so we mark rows
18380 displayed invalid in the current matrix by setting their
18381 enabled_p flag to false. */
18382 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18383 if (display_line (&it
))
18384 last_text_row_at_end
= it
.glyph_row
- 1;
18388 /* Update window_end_pos and window_end_vpos. */
18389 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18391 /* Window end line if one of the preserved rows from the current
18392 matrix. Set row to the last row displaying text in current
18393 matrix starting at first_unchanged_at_end_row, after
18395 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18396 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18397 first_unchanged_at_end_row
);
18398 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18399 adjust_window_ends (w
, row
, true);
18400 eassert (w
->window_end_bytepos
>= 0);
18401 IF_DEBUG (debug_method_add (w
, "A"));
18403 else if (last_text_row_at_end
)
18405 adjust_window_ends (w
, last_text_row_at_end
, false);
18406 eassert (w
->window_end_bytepos
>= 0);
18407 IF_DEBUG (debug_method_add (w
, "B"));
18409 else if (last_text_row
)
18411 /* We have displayed either to the end of the window or at the
18412 end of the window, i.e. the last row with text is to be found
18413 in the desired matrix. */
18414 adjust_window_ends (w
, last_text_row
, false);
18415 eassert (w
->window_end_bytepos
>= 0);
18417 else if (first_unchanged_at_end_row
== NULL
18418 && last_text_row
== NULL
18419 && last_text_row_at_end
== NULL
)
18421 /* Displayed to end of window, but no line containing text was
18422 displayed. Lines were deleted at the end of the window. */
18423 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
18424 int vpos
= w
->window_end_vpos
;
18425 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18426 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18429 row
== NULL
&& vpos
>= first_vpos
;
18430 --vpos
, --current_row
, --desired_row
)
18432 if (desired_row
->enabled_p
)
18434 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18437 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18441 eassert (row
!= NULL
);
18442 w
->window_end_vpos
= vpos
+ 1;
18443 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18444 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18445 eassert (w
->window_end_bytepos
>= 0);
18446 IF_DEBUG (debug_method_add (w
, "C"));
18451 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18452 debug_end_vpos
= w
->window_end_vpos
));
18454 /* Record that display has not been completed. */
18455 w
->window_end_valid
= false;
18456 w
->desired_matrix
->no_scrolling_p
= true;
18464 /***********************************************************************
18465 More debugging support
18466 ***********************************************************************/
18470 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18471 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18472 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18475 /* Dump the contents of glyph matrix MATRIX on stderr.
18477 GLYPHS 0 means don't show glyph contents.
18478 GLYPHS 1 means show glyphs in short form
18479 GLYPHS > 1 means show glyphs in long form. */
18482 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18485 for (i
= 0; i
< matrix
->nrows
; ++i
)
18486 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18490 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18491 the glyph row and area where the glyph comes from. */
18494 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18496 if (glyph
->type
== CHAR_GLYPH
18497 || glyph
->type
== GLYPHLESS_GLYPH
)
18500 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18501 glyph
- row
->glyphs
[TEXT_AREA
],
18502 (glyph
->type
== CHAR_GLYPH
18506 (BUFFERP (glyph
->object
)
18508 : (STRINGP (glyph
->object
)
18510 : (NILP (glyph
->object
)
18513 glyph
->pixel_width
,
18515 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18519 glyph
->left_box_line_p
,
18520 glyph
->right_box_line_p
);
18522 else if (glyph
->type
== STRETCH_GLYPH
)
18525 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18526 glyph
- row
->glyphs
[TEXT_AREA
],
18529 (BUFFERP (glyph
->object
)
18531 : (STRINGP (glyph
->object
)
18533 : (NILP (glyph
->object
)
18536 glyph
->pixel_width
,
18540 glyph
->left_box_line_p
,
18541 glyph
->right_box_line_p
);
18543 else if (glyph
->type
== IMAGE_GLYPH
)
18546 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18547 glyph
- row
->glyphs
[TEXT_AREA
],
18550 (BUFFERP (glyph
->object
)
18552 : (STRINGP (glyph
->object
)
18554 : (NILP (glyph
->object
)
18557 glyph
->pixel_width
,
18561 glyph
->left_box_line_p
,
18562 glyph
->right_box_line_p
);
18564 else if (glyph
->type
== COMPOSITE_GLYPH
)
18567 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18568 glyph
- row
->glyphs
[TEXT_AREA
],
18571 (BUFFERP (glyph
->object
)
18573 : (STRINGP (glyph
->object
)
18575 : (NILP (glyph
->object
)
18578 glyph
->pixel_width
,
18580 if (glyph
->u
.cmp
.automatic
)
18583 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18584 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18586 glyph
->left_box_line_p
,
18587 glyph
->right_box_line_p
);
18592 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18593 GLYPHS 0 means don't show glyph contents.
18594 GLYPHS 1 means show glyphs in short form
18595 GLYPHS > 1 means show glyphs in long form. */
18598 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18602 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18603 fprintf (stderr
, "==============================================================================\n");
18605 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18606 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18608 MATRIX_ROW_START_CHARPOS (row
),
18609 MATRIX_ROW_END_CHARPOS (row
),
18610 row
->used
[TEXT_AREA
],
18611 row
->contains_overlapping_glyphs_p
,
18613 row
->truncated_on_left_p
,
18614 row
->truncated_on_right_p
,
18616 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18617 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18620 row
->ends_in_middle_of_char_p
,
18621 row
->starts_in_middle_of_char_p
,
18627 row
->visible_height
,
18630 /* The next 3 lines should align to "Start" in the header. */
18631 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18632 row
->end
.overlay_string_index
,
18633 row
->continuation_lines_width
);
18634 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18635 CHARPOS (row
->start
.string_pos
),
18636 CHARPOS (row
->end
.string_pos
));
18637 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18638 row
->end
.dpvec_index
);
18645 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18647 struct glyph
*glyph
= row
->glyphs
[area
];
18648 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18650 /* Glyph for a line end in text. */
18651 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18654 if (glyph
< glyph_end
)
18655 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18657 for (; glyph
< glyph_end
; ++glyph
)
18658 dump_glyph (row
, glyph
, area
);
18661 else if (glyphs
== 1)
18664 char s
[SHRT_MAX
+ 4];
18666 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18670 for (i
= 0; i
< row
->used
[area
]; ++i
)
18672 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18673 if (i
== row
->used
[area
] - 1
18674 && area
== TEXT_AREA
18675 && NILP (glyph
->object
)
18676 && glyph
->type
== CHAR_GLYPH
18677 && glyph
->u
.ch
== ' ')
18679 strcpy (&s
[i
], "[\\n]");
18682 else if (glyph
->type
== CHAR_GLYPH
18683 && glyph
->u
.ch
< 0x80
18684 && glyph
->u
.ch
>= ' ')
18685 s
[i
] = glyph
->u
.ch
;
18691 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18697 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18698 Sdump_glyph_matrix
, 0, 1, "p",
18699 doc
: /* Dump the current matrix of the selected window to stderr.
18700 Shows contents of glyph row structures. With non-nil
18701 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18702 glyphs in short form, otherwise show glyphs in long form.
18704 Interactively, no argument means show glyphs in short form;
18705 with numeric argument, its value is passed as the GLYPHS flag. */)
18706 (Lisp_Object glyphs
)
18708 struct window
*w
= XWINDOW (selected_window
);
18709 struct buffer
*buffer
= XBUFFER (w
->contents
);
18711 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18712 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18713 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18714 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18715 fprintf (stderr
, "=============================================\n");
18716 dump_glyph_matrix (w
->current_matrix
,
18717 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18722 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18723 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* Dump the current glyph matrix of the selected frame to stderr.
18724 Only text-mode frames have frame glyph matrices. */)
18727 struct frame
*f
= XFRAME (selected_frame
);
18729 if (f
->current_matrix
)
18730 dump_glyph_matrix (f
->current_matrix
, 1);
18732 fprintf (stderr
, "*** This frame doesn't have a frame glyph matrix ***\n");
18737 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18738 doc
: /* Dump glyph row ROW to stderr.
18739 GLYPH 0 means don't dump glyphs.
18740 GLYPH 1 means dump glyphs in short form.
18741 GLYPH > 1 or omitted means dump glyphs in long form. */)
18742 (Lisp_Object row
, Lisp_Object glyphs
)
18744 struct glyph_matrix
*matrix
;
18747 CHECK_NUMBER (row
);
18748 matrix
= XWINDOW (selected_window
)->current_matrix
;
18750 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18751 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18753 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18758 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18759 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18760 GLYPH 0 means don't dump glyphs.
18761 GLYPH 1 means dump glyphs in short form.
18762 GLYPH > 1 or omitted means dump glyphs in long form.
18764 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18766 (Lisp_Object row
, Lisp_Object glyphs
)
18768 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18769 struct frame
*sf
= SELECTED_FRAME ();
18770 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18773 CHECK_NUMBER (row
);
18775 if (vpos
>= 0 && vpos
< m
->nrows
)
18776 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18777 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18783 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18784 doc
: /* Toggle tracing of redisplay.
18785 With ARG, turn tracing on if and only if ARG is positive. */)
18789 trace_redisplay_p
= !trace_redisplay_p
;
18792 arg
= Fprefix_numeric_value (arg
);
18793 trace_redisplay_p
= XINT (arg
) > 0;
18800 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18801 doc
: /* Like `format', but print result to stderr.
18802 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18803 (ptrdiff_t nargs
, Lisp_Object
*args
)
18805 Lisp_Object s
= Fformat (nargs
, args
);
18806 fwrite (SDATA (s
), 1, SBYTES (s
), stderr
);
18810 #endif /* GLYPH_DEBUG */
18814 /***********************************************************************
18815 Building Desired Matrix Rows
18816 ***********************************************************************/
18818 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18819 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18821 static struct glyph_row
*
18822 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18824 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18825 struct buffer
*buffer
= XBUFFER (w
->contents
);
18826 struct buffer
*old
= current_buffer
;
18827 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18828 ptrdiff_t arrow_len
= SCHARS (overlay_arrow_string
);
18829 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18830 const unsigned char *p
;
18833 int n_glyphs_before
;
18835 set_buffer_temp (buffer
);
18836 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18837 scratch_glyph_row
.reversed_p
= false;
18838 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18839 SET_TEXT_POS (it
.position
, 0, 0);
18841 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18843 while (p
< arrow_end
)
18845 Lisp_Object face
, ilisp
;
18847 /* Get the next character. */
18849 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18852 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18853 if (! ASCII_CHAR_P (it
.c
))
18854 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18858 /* Get its face. */
18859 ilisp
= make_number (p
- arrow_string
);
18860 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18861 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18863 /* Compute its width, get its glyphs. */
18864 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18865 SET_TEXT_POS (it
.position
, -1, -1);
18866 PRODUCE_GLYPHS (&it
);
18868 /* If this character doesn't fit any more in the line, we have
18869 to remove some glyphs. */
18870 if (it
.current_x
> it
.last_visible_x
)
18872 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18877 set_buffer_temp (old
);
18878 return it
.glyph_row
;
18882 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18883 glyphs to insert is determined by produce_special_glyphs. */
18886 insert_left_trunc_glyphs (struct it
*it
)
18888 struct it truncate_it
;
18889 struct glyph
*from
, *end
, *to
, *toend
;
18891 eassert (!FRAME_WINDOW_P (it
->f
)
18892 || (!it
->glyph_row
->reversed_p
18893 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18894 || (it
->glyph_row
->reversed_p
18895 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18897 /* Get the truncation glyphs. */
18899 truncate_it
.current_x
= 0;
18900 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18901 truncate_it
.glyph_row
= &scratch_glyph_row
;
18902 truncate_it
.area
= TEXT_AREA
;
18903 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18904 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18905 truncate_it
.object
= Qnil
;
18906 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18908 /* Overwrite glyphs from IT with truncation glyphs. */
18909 if (!it
->glyph_row
->reversed_p
)
18911 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18913 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18914 end
= from
+ tused
;
18915 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18916 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18917 if (FRAME_WINDOW_P (it
->f
))
18919 /* On GUI frames, when variable-size fonts are displayed,
18920 the truncation glyphs may need more pixels than the row's
18921 glyphs they overwrite. We overwrite more glyphs to free
18922 enough screen real estate, and enlarge the stretch glyph
18923 on the right (see display_line), if there is one, to
18924 preserve the screen position of the truncation glyphs on
18927 struct glyph
*g
= to
;
18930 /* The first glyph could be partially visible, in which case
18931 it->glyph_row->x will be negative. But we want the left
18932 truncation glyphs to be aligned at the left margin of the
18933 window, so we override the x coordinate at which the row
18935 it
->glyph_row
->x
= 0;
18936 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18938 w
+= g
->pixel_width
;
18941 if (g
- to
- tused
> 0)
18943 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18944 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18946 used
= it
->glyph_row
->used
[TEXT_AREA
];
18947 if (it
->glyph_row
->truncated_on_right_p
18948 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18949 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18952 int extra
= w
- it
->truncation_pixel_width
;
18954 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18961 /* There may be padding glyphs left over. Overwrite them too. */
18962 if (!FRAME_WINDOW_P (it
->f
))
18964 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18966 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18973 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18977 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18979 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18980 that back to front. */
18981 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18982 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18983 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18984 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18985 if (FRAME_WINDOW_P (it
->f
))
18988 struct glyph
*g
= to
;
18990 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18992 w
+= g
->pixel_width
;
18995 if (to
- g
- tused
> 0)
18997 if (it
->glyph_row
->truncated_on_right_p
18998 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18999 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
19001 int extra
= w
- it
->truncation_pixel_width
;
19003 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
19007 while (from
>= end
&& to
>= toend
)
19009 if (!FRAME_WINDOW_P (it
->f
))
19011 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
19014 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
19015 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19016 while (from
>= end
&& to
>= toend
)
19022 /* Need to free some room before prepending additional
19024 int move_by
= from
- end
+ 1;
19025 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19026 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19028 for ( ; g
>= g0
; g
--)
19030 while (from
>= end
)
19032 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
19037 /* Compute the hash code for ROW. */
19039 row_hash (struct glyph_row
*row
)
19042 unsigned hashval
= 0;
19044 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19045 for (k
= 0; k
< row
->used
[area
]; ++k
)
19046 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
19047 + row
->glyphs
[area
][k
].u
.val
19048 + row
->glyphs
[area
][k
].face_id
19049 + row
->glyphs
[area
][k
].padding_p
19050 + (row
->glyphs
[area
][k
].type
<< 2));
19055 /* Compute the pixel height and width of IT->glyph_row.
19057 Most of the time, ascent and height of a display line will be equal
19058 to the max_ascent and max_height values of the display iterator
19059 structure. This is not the case if
19061 1. We hit ZV without displaying anything. In this case, max_ascent
19062 and max_height will be zero.
19064 2. We have some glyphs that don't contribute to the line height.
19065 (The glyph row flag contributes_to_line_height_p is for future
19066 pixmap extensions).
19068 The first case is easily covered by using default values because in
19069 these cases, the line height does not really matter, except that it
19070 must not be zero. */
19073 compute_line_metrics (struct it
*it
)
19075 struct glyph_row
*row
= it
->glyph_row
;
19077 if (FRAME_WINDOW_P (it
->f
))
19079 int i
, min_y
, max_y
;
19081 /* The line may consist of one space only, that was added to
19082 place the cursor on it. If so, the row's height hasn't been
19084 if (row
->height
== 0)
19086 if (it
->max_ascent
+ it
->max_descent
== 0)
19087 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
19088 row
->ascent
= it
->max_ascent
;
19089 row
->height
= it
->max_ascent
+ it
->max_descent
;
19090 row
->phys_ascent
= it
->max_phys_ascent
;
19091 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19092 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19095 /* Compute the width of this line. */
19096 row
->pixel_width
= row
->x
;
19097 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
19098 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
19100 eassert (row
->pixel_width
>= 0);
19101 eassert (row
->ascent
>= 0 && row
->height
> 0);
19103 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
19104 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
19106 /* If first line's physical ascent is larger than its logical
19107 ascent, use the physical ascent, and make the row taller.
19108 This makes accented characters fully visible. */
19109 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
19110 && row
->phys_ascent
> row
->ascent
)
19112 row
->height
+= row
->phys_ascent
- row
->ascent
;
19113 row
->ascent
= row
->phys_ascent
;
19116 /* Compute how much of the line is visible. */
19117 row
->visible_height
= row
->height
;
19119 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
19120 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
19122 if (row
->y
< min_y
)
19123 row
->visible_height
-= min_y
- row
->y
;
19124 if (row
->y
+ row
->height
> max_y
)
19125 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
19129 row
->pixel_width
= row
->used
[TEXT_AREA
];
19130 if (row
->continued_p
)
19131 row
->pixel_width
-= it
->continuation_pixel_width
;
19132 else if (row
->truncated_on_right_p
)
19133 row
->pixel_width
-= it
->truncation_pixel_width
;
19134 row
->ascent
= row
->phys_ascent
= 0;
19135 row
->height
= row
->phys_height
= row
->visible_height
= 1;
19136 row
->extra_line_spacing
= 0;
19139 /* Compute a hash code for this row. */
19140 row
->hash
= row_hash (row
);
19142 it
->max_ascent
= it
->max_descent
= 0;
19143 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
19147 /* Append one space to the glyph row of iterator IT if doing a
19148 window-based redisplay. The space has the same face as
19149 IT->face_id. Value is true if a space was added.
19151 This function is called to make sure that there is always one glyph
19152 at the end of a glyph row that the cursor can be set on under
19153 window-systems. (If there weren't such a glyph we would not know
19154 how wide and tall a box cursor should be displayed).
19156 At the same time this space let's a nicely handle clearing to the
19157 end of the line if the row ends in italic text. */
19160 append_space_for_newline (struct it
*it
, bool default_face_p
)
19162 if (FRAME_WINDOW_P (it
->f
))
19164 int n
= it
->glyph_row
->used
[TEXT_AREA
];
19166 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
19167 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
19169 /* Save some values that must not be changed.
19170 Must save IT->c and IT->len because otherwise
19171 ITERATOR_AT_END_P wouldn't work anymore after
19172 append_space_for_newline has been called. */
19173 enum display_element_type saved_what
= it
->what
;
19174 int saved_c
= it
->c
, saved_len
= it
->len
;
19175 int saved_char_to_display
= it
->char_to_display
;
19176 int saved_x
= it
->current_x
;
19177 int saved_face_id
= it
->face_id
;
19178 bool saved_box_end
= it
->end_of_box_run_p
;
19179 struct text_pos saved_pos
;
19180 Lisp_Object saved_object
;
19184 saved_object
= it
->object
;
19185 saved_pos
= it
->position
;
19187 it
->what
= IT_CHARACTER
;
19188 memset (&it
->position
, 0, sizeof it
->position
);
19190 it
->c
= it
->char_to_display
= ' ';
19193 /* If the default face was remapped, be sure to use the
19194 remapped face for the appended newline. */
19195 if (default_face_p
)
19196 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
19197 else if (it
->face_before_selective_p
)
19198 it
->face_id
= it
->saved_face_id
;
19199 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19200 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
19201 /* In R2L rows, we will prepend a stretch glyph that will
19202 have the end_of_box_run_p flag set for it, so there's no
19203 need for the appended newline glyph to have that flag
19205 if (it
->glyph_row
->reversed_p
19206 /* But if the appended newline glyph goes all the way to
19207 the end of the row, there will be no stretch glyph,
19208 so leave the box flag set. */
19209 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
19210 it
->end_of_box_run_p
= false;
19212 PRODUCE_GLYPHS (it
);
19214 /* Make sure this space glyph has the right ascent value, or
19215 else hollow cursor at end of line will look funny. */
19216 g
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19217 g
->ascent
= it
->glyph_row
->ascent
;
19219 it
->override_ascent
= -1;
19220 it
->constrain_row_ascent_descent_p
= false;
19221 it
->current_x
= saved_x
;
19222 it
->object
= saved_object
;
19223 it
->position
= saved_pos
;
19224 it
->what
= saved_what
;
19225 it
->face_id
= saved_face_id
;
19226 it
->len
= saved_len
;
19228 it
->char_to_display
= saved_char_to_display
;
19229 it
->end_of_box_run_p
= saved_box_end
;
19238 /* Extend the face of the last glyph in the text area of IT->glyph_row
19239 to the end of the display line. Called from display_line. If the
19240 glyph row is empty, add a space glyph to it so that we know the
19241 face to draw. Set the glyph row flag fill_line_p. If the glyph
19242 row is R2L, prepend a stretch glyph to cover the empty space to the
19243 left of the leftmost glyph. */
19246 extend_face_to_end_of_line (struct it
*it
)
19248 struct face
*face
, *default_face
;
19249 struct frame
*f
= it
->f
;
19251 /* If line is already filled, do nothing. Non window-system frames
19252 get a grace of one more ``pixel'' because their characters are
19253 1-``pixel'' wide, so they hit the equality too early. This grace
19254 is needed only for R2L rows that are not continued, to produce
19255 one extra blank where we could display the cursor. */
19256 if ((it
->current_x
>= it
->last_visible_x
19257 + (!FRAME_WINDOW_P (f
)
19258 && it
->glyph_row
->reversed_p
19259 && !it
->glyph_row
->continued_p
))
19260 /* If the window has display margins, we will need to extend
19261 their face even if the text area is filled. */
19262 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19263 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
19266 /* The default face, possibly remapped. */
19267 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
19269 /* Face extension extends the background and box of IT->face_id
19270 to the end of the line. If the background equals the background
19271 of the frame, we don't have to do anything. */
19272 if (it
->face_before_selective_p
)
19273 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
19275 face
= FACE_FROM_ID (f
, it
->face_id
);
19277 if (FRAME_WINDOW_P (f
)
19278 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
19279 && face
->box
== FACE_NO_BOX
19280 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
19281 #ifdef HAVE_WINDOW_SYSTEM
19284 && !it
->glyph_row
->reversed_p
)
19287 /* Set the glyph row flag indicating that the face of the last glyph
19288 in the text area has to be drawn to the end of the text area. */
19289 it
->glyph_row
->fill_line_p
= true;
19291 /* If current character of IT is not ASCII, make sure we have the
19292 ASCII face. This will be automatically undone the next time
19293 get_next_display_element returns a multibyte character. Note
19294 that the character will always be single byte in unibyte
19296 if (!ASCII_CHAR_P (it
->c
))
19298 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
19301 if (FRAME_WINDOW_P (f
))
19303 /* If the row is empty, add a space with the current face of IT,
19304 so that we know which face to draw. */
19305 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
19307 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
19308 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
19309 it
->glyph_row
->used
[TEXT_AREA
] = 1;
19311 /* Mode line and the header line don't have margins, and
19312 likewise the frame's tool-bar window, if there is any. */
19313 if (!(it
->glyph_row
->mode_line_p
19314 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19315 || (WINDOWP (f
->tool_bar_window
)
19316 && it
->w
== XWINDOW (f
->tool_bar_window
))
19320 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19321 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
19323 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
19324 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
19326 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
19328 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19329 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
19331 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
19332 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
19334 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
19337 #ifdef HAVE_WINDOW_SYSTEM
19338 if (it
->glyph_row
->reversed_p
)
19340 /* Prepend a stretch glyph to the row, such that the
19341 rightmost glyph will be drawn flushed all the way to the
19342 right margin of the window. The stretch glyph that will
19343 occupy the empty space, if any, to the left of the
19345 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
19346 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19347 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
19349 int row_width
, stretch_ascent
, stretch_width
;
19350 struct text_pos saved_pos
;
19352 bool saved_avoid_cursor
, saved_box_start
;
19354 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
19355 row_width
+= g
->pixel_width
;
19357 /* FIXME: There are various minor display glitches in R2L
19358 rows when only one of the fringes is missing. The
19359 strange condition below produces the least bad effect. */
19360 if ((WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19361 == (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
19362 || WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
19363 stretch_width
= window_box_width (it
->w
, TEXT_AREA
);
19365 stretch_width
= it
->last_visible_x
- it
->first_visible_x
;
19366 stretch_width
-= row_width
;
19368 if (stretch_width
> 0)
19371 (((it
->ascent
+ it
->descent
)
19372 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
19373 saved_pos
= it
->position
;
19374 memset (&it
->position
, 0, sizeof it
->position
);
19375 saved_avoid_cursor
= it
->avoid_cursor_p
;
19376 it
->avoid_cursor_p
= true;
19377 saved_face_id
= it
->face_id
;
19378 saved_box_start
= it
->start_of_box_run_p
;
19379 /* The last row's stretch glyph should get the default
19380 face, to avoid painting the rest of the window with
19381 the region face, if the region ends at ZV. */
19382 if (it
->glyph_row
->ends_at_zv_p
)
19383 it
->face_id
= default_face
->id
;
19385 it
->face_id
= face
->id
;
19386 it
->start_of_box_run_p
= false;
19387 append_stretch_glyph (it
, Qnil
, stretch_width
,
19388 it
->ascent
+ it
->descent
, stretch_ascent
);
19389 it
->position
= saved_pos
;
19390 it
->avoid_cursor_p
= saved_avoid_cursor
;
19391 it
->face_id
= saved_face_id
;
19392 it
->start_of_box_run_p
= saved_box_start
;
19394 /* If stretch_width comes out negative, it means that the
19395 last glyph is only partially visible. In R2L rows, we
19396 want the leftmost glyph to be partially visible, so we
19397 need to give the row the corresponding left offset. */
19398 if (stretch_width
< 0)
19399 it
->glyph_row
->x
= stretch_width
;
19401 #endif /* HAVE_WINDOW_SYSTEM */
19405 /* Save some values that must not be changed. */
19406 int saved_x
= it
->current_x
;
19407 struct text_pos saved_pos
;
19408 Lisp_Object saved_object
;
19409 enum display_element_type saved_what
= it
->what
;
19410 int saved_face_id
= it
->face_id
;
19412 saved_object
= it
->object
;
19413 saved_pos
= it
->position
;
19415 it
->what
= IT_CHARACTER
;
19416 memset (&it
->position
, 0, sizeof it
->position
);
19418 it
->c
= it
->char_to_display
= ' ';
19421 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19422 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19423 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19424 && !it
->glyph_row
->mode_line_p
19425 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19427 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19428 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19430 for (it
->current_x
= 0; g
< e
; g
++)
19431 it
->current_x
+= g
->pixel_width
;
19433 it
->area
= LEFT_MARGIN_AREA
;
19434 it
->face_id
= default_face
->id
;
19435 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19436 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19438 PRODUCE_GLYPHS (it
);
19439 /* term.c:produce_glyphs advances it->current_x only for
19441 it
->current_x
+= it
->pixel_width
;
19444 it
->current_x
= saved_x
;
19445 it
->area
= TEXT_AREA
;
19448 /* The last row's blank glyphs should get the default face, to
19449 avoid painting the rest of the window with the region face,
19450 if the region ends at ZV. */
19451 if (it
->glyph_row
->ends_at_zv_p
)
19452 it
->face_id
= default_face
->id
;
19454 it
->face_id
= face
->id
;
19455 PRODUCE_GLYPHS (it
);
19457 while (it
->current_x
<= it
->last_visible_x
)
19458 PRODUCE_GLYPHS (it
);
19460 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19461 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19462 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19463 && !it
->glyph_row
->mode_line_p
19464 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19466 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19467 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19469 for ( ; g
< e
; g
++)
19470 it
->current_x
+= g
->pixel_width
;
19472 it
->area
= RIGHT_MARGIN_AREA
;
19473 it
->face_id
= default_face
->id
;
19474 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19475 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19477 PRODUCE_GLYPHS (it
);
19478 it
->current_x
+= it
->pixel_width
;
19481 it
->area
= TEXT_AREA
;
19484 /* Don't count these blanks really. It would let us insert a left
19485 truncation glyph below and make us set the cursor on them, maybe. */
19486 it
->current_x
= saved_x
;
19487 it
->object
= saved_object
;
19488 it
->position
= saved_pos
;
19489 it
->what
= saved_what
;
19490 it
->face_id
= saved_face_id
;
19495 /* Value is true if text starting at CHARPOS in current_buffer is
19496 trailing whitespace. */
19499 trailing_whitespace_p (ptrdiff_t charpos
)
19501 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19504 while (bytepos
< ZV_BYTE
19505 && (c
= FETCH_CHAR (bytepos
),
19506 c
== ' ' || c
== '\t'))
19509 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19511 if (bytepos
!= PT_BYTE
)
19518 /* Highlight trailing whitespace, if any, in ROW. */
19521 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19523 int used
= row
->used
[TEXT_AREA
];
19527 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19528 struct glyph
*glyph
= start
+ used
- 1;
19530 if (row
->reversed_p
)
19532 /* Right-to-left rows need to be processed in the opposite
19533 direction, so swap the edge pointers. */
19535 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19538 /* Skip over glyphs inserted to display the cursor at the
19539 end of a line, for extending the face of the last glyph
19540 to the end of the line on terminals, and for truncation
19541 and continuation glyphs. */
19542 if (!row
->reversed_p
)
19544 while (glyph
>= start
19545 && glyph
->type
== CHAR_GLYPH
19546 && NILP (glyph
->object
))
19551 while (glyph
<= start
19552 && glyph
->type
== CHAR_GLYPH
19553 && NILP (glyph
->object
))
19557 /* If last glyph is a space or stretch, and it's trailing
19558 whitespace, set the face of all trailing whitespace glyphs in
19559 IT->glyph_row to `trailing-whitespace'. */
19560 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19561 && BUFFERP (glyph
->object
)
19562 && (glyph
->type
== STRETCH_GLYPH
19563 || (glyph
->type
== CHAR_GLYPH
19564 && glyph
->u
.ch
== ' '))
19565 && trailing_whitespace_p (glyph
->charpos
))
19567 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, false);
19571 if (!row
->reversed_p
)
19573 while (glyph
>= start
19574 && BUFFERP (glyph
->object
)
19575 && (glyph
->type
== STRETCH_GLYPH
19576 || (glyph
->type
== CHAR_GLYPH
19577 && glyph
->u
.ch
== ' ')))
19578 (glyph
--)->face_id
= face_id
;
19582 while (glyph
<= start
19583 && BUFFERP (glyph
->object
)
19584 && (glyph
->type
== STRETCH_GLYPH
19585 || (glyph
->type
== CHAR_GLYPH
19586 && glyph
->u
.ch
== ' ')))
19587 (glyph
++)->face_id
= face_id
;
19594 /* Value is true if glyph row ROW should be
19595 considered to hold the buffer position CHARPOS. */
19598 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19600 bool result
= true;
19602 if (charpos
== CHARPOS (row
->end
.pos
)
19603 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19605 /* Suppose the row ends on a string.
19606 Unless the row is continued, that means it ends on a newline
19607 in the string. If it's anything other than a display string
19608 (e.g., a before-string from an overlay), we don't want the
19609 cursor there. (This heuristic seems to give the optimal
19610 behavior for the various types of multi-line strings.)
19611 One exception: if the string has `cursor' property on one of
19612 its characters, we _do_ want the cursor there. */
19613 if (CHARPOS (row
->end
.string_pos
) >= 0)
19615 if (row
->continued_p
)
19619 /* Check for `display' property. */
19620 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19621 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19622 struct glyph
*glyph
;
19625 for (glyph
= end
; glyph
>= beg
; --glyph
)
19626 if (STRINGP (glyph
->object
))
19629 = Fget_char_property (make_number (charpos
),
19633 && display_prop_string_p (prop
, glyph
->object
));
19634 /* If there's a `cursor' property on one of the
19635 string's characters, this row is a cursor row,
19636 even though this is not a display string. */
19639 Lisp_Object s
= glyph
->object
;
19641 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19643 ptrdiff_t gpos
= glyph
->charpos
;
19645 if (!NILP (Fget_char_property (make_number (gpos
),
19657 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19659 /* If the row ends in middle of a real character,
19660 and the line is continued, we want the cursor here.
19661 That's because CHARPOS (ROW->end.pos) would equal
19662 PT if PT is before the character. */
19663 if (!row
->ends_in_ellipsis_p
)
19664 result
= row
->continued_p
;
19666 /* If the row ends in an ellipsis, then
19667 CHARPOS (ROW->end.pos) will equal point after the
19668 invisible text. We want that position to be displayed
19669 after the ellipsis. */
19672 /* If the row ends at ZV, display the cursor at the end of that
19673 row instead of at the start of the row below. */
19675 result
= row
->ends_at_zv_p
;
19681 /* Value is true if glyph row ROW should be
19682 used to hold the cursor. */
19685 cursor_row_p (struct glyph_row
*row
)
19687 return row_for_charpos_p (row
, PT
);
19692 /* Push the property PROP so that it will be rendered at the current
19693 position in IT. Return true if PROP was successfully pushed, false
19694 otherwise. Called from handle_line_prefix to handle the
19695 `line-prefix' and `wrap-prefix' properties. */
19698 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19700 struct text_pos pos
=
19701 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19703 eassert (it
->method
== GET_FROM_BUFFER
19704 || it
->method
== GET_FROM_DISPLAY_VECTOR
19705 || it
->method
== GET_FROM_STRING
);
19707 /* We need to save the current buffer/string position, so it will be
19708 restored by pop_it, because iterate_out_of_display_property
19709 depends on that being set correctly, but some situations leave
19710 it->position not yet set when this function is called. */
19711 push_it (it
, &pos
);
19713 if (STRINGP (prop
))
19715 if (SCHARS (prop
) == 0)
19722 it
->string_from_prefix_prop_p
= true;
19723 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19724 it
->current
.overlay_string_index
= -1;
19725 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19726 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19727 it
->method
= GET_FROM_STRING
;
19728 it
->stop_charpos
= 0;
19730 it
->base_level_stop
= 0;
19732 /* Force paragraph direction to be that of the parent
19734 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19735 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19737 it
->paragraph_embedding
= L2R
;
19739 /* Set up the bidi iterator for this display string. */
19742 it
->bidi_it
.string
.lstring
= it
->string
;
19743 it
->bidi_it
.string
.s
= NULL
;
19744 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19745 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19746 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19747 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19748 it
->bidi_it
.w
= it
->w
;
19749 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19752 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19754 it
->method
= GET_FROM_STRETCH
;
19757 #ifdef HAVE_WINDOW_SYSTEM
19758 else if (IMAGEP (prop
))
19760 it
->what
= IT_IMAGE
;
19761 it
->image_id
= lookup_image (it
->f
, prop
);
19762 it
->method
= GET_FROM_IMAGE
;
19764 #endif /* HAVE_WINDOW_SYSTEM */
19767 pop_it (it
); /* bogus display property, give up */
19774 /* Return the character-property PROP at the current position in IT. */
19777 get_it_property (struct it
*it
, Lisp_Object prop
)
19779 Lisp_Object position
, object
= it
->object
;
19781 if (STRINGP (object
))
19782 position
= make_number (IT_STRING_CHARPOS (*it
));
19783 else if (BUFFERP (object
))
19785 position
= make_number (IT_CHARPOS (*it
));
19786 object
= it
->window
;
19791 return Fget_char_property (position
, prop
, object
);
19794 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19797 handle_line_prefix (struct it
*it
)
19799 Lisp_Object prefix
;
19801 if (it
->continuation_lines_width
> 0)
19803 prefix
= get_it_property (it
, Qwrap_prefix
);
19805 prefix
= Vwrap_prefix
;
19809 prefix
= get_it_property (it
, Qline_prefix
);
19811 prefix
= Vline_prefix
;
19813 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19815 /* If the prefix is wider than the window, and we try to wrap
19816 it, it would acquire its own wrap prefix, and so on till the
19817 iterator stack overflows. So, don't wrap the prefix. */
19818 it
->line_wrap
= TRUNCATE
;
19819 it
->avoid_cursor_p
= true;
19825 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19826 only for R2L lines from display_line and display_string, when they
19827 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19828 the line/string needs to be continued on the next glyph row. */
19830 unproduce_glyphs (struct it
*it
, int n
)
19832 struct glyph
*glyph
, *end
;
19834 eassert (it
->glyph_row
);
19835 eassert (it
->glyph_row
->reversed_p
);
19836 eassert (it
->area
== TEXT_AREA
);
19837 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19839 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19840 n
= it
->glyph_row
->used
[TEXT_AREA
];
19841 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19842 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19843 for ( ; glyph
< end
; glyph
++)
19844 glyph
[-n
] = *glyph
;
19847 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19848 and ROW->maxpos. */
19850 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19851 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19852 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19854 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19855 lines' rows is implemented for bidi-reordered rows. */
19857 /* ROW->minpos is the value of min_pos, the minimal buffer position
19858 we have in ROW, or ROW->start.pos if that is smaller. */
19859 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19860 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19862 /* We didn't find buffer positions smaller than ROW->start, or
19863 didn't find _any_ valid buffer positions in any of the glyphs,
19864 so we must trust the iterator's computed positions. */
19865 row
->minpos
= row
->start
.pos
;
19868 max_pos
= CHARPOS (it
->current
.pos
);
19869 max_bpos
= BYTEPOS (it
->current
.pos
);
19872 /* Here are the various use-cases for ending the row, and the
19873 corresponding values for ROW->maxpos:
19875 Line ends in a newline from buffer eol_pos + 1
19876 Line is continued from buffer max_pos + 1
19877 Line is truncated on right it->current.pos
19878 Line ends in a newline from string max_pos + 1(*)
19879 (*) + 1 only when line ends in a forward scan
19880 Line is continued from string max_pos
19881 Line is continued from display vector max_pos
19882 Line is entirely from a string min_pos == max_pos
19883 Line is entirely from a display vector min_pos == max_pos
19884 Line that ends at ZV ZV
19886 If you discover other use-cases, please add them here as
19888 if (row
->ends_at_zv_p
)
19889 row
->maxpos
= it
->current
.pos
;
19890 else if (row
->used
[TEXT_AREA
])
19892 bool seen_this_string
= false;
19893 struct glyph_row
*r1
= row
- 1;
19895 /* Did we see the same display string on the previous row? */
19896 if (STRINGP (it
->object
)
19897 /* this is not the first row */
19898 && row
> it
->w
->desired_matrix
->rows
19899 /* previous row is not the header line */
19900 && !r1
->mode_line_p
19901 /* previous row also ends in a newline from a string */
19902 && r1
->ends_in_newline_from_string_p
)
19904 struct glyph
*start
, *end
;
19906 /* Search for the last glyph of the previous row that came
19907 from buffer or string. Depending on whether the row is
19908 L2R or R2L, we need to process it front to back or the
19909 other way round. */
19910 if (!r1
->reversed_p
)
19912 start
= r1
->glyphs
[TEXT_AREA
];
19913 end
= start
+ r1
->used
[TEXT_AREA
];
19914 /* Glyphs inserted by redisplay have nil as their object. */
19916 && NILP ((end
- 1)->object
)
19917 && (end
- 1)->charpos
<= 0)
19921 if (EQ ((end
- 1)->object
, it
->object
))
19922 seen_this_string
= true;
19925 /* If all the glyphs of the previous row were inserted
19926 by redisplay, it means the previous row was
19927 produced from a single newline, which is only
19928 possible if that newline came from the same string
19929 as the one which produced this ROW. */
19930 seen_this_string
= true;
19934 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19935 start
= end
+ r1
->used
[TEXT_AREA
];
19937 && NILP ((end
+ 1)->object
)
19938 && (end
+ 1)->charpos
<= 0)
19942 if (EQ ((end
+ 1)->object
, it
->object
))
19943 seen_this_string
= true;
19946 seen_this_string
= true;
19949 /* Take note of each display string that covers a newline only
19950 once, the first time we see it. This is for when a display
19951 string includes more than one newline in it. */
19952 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19954 /* If we were scanning the buffer forward when we displayed
19955 the string, we want to account for at least one buffer
19956 position that belongs to this row (position covered by
19957 the display string), so that cursor positioning will
19958 consider this row as a candidate when point is at the end
19959 of the visual line represented by this row. This is not
19960 required when scanning back, because max_pos will already
19961 have a much larger value. */
19962 if (CHARPOS (row
->end
.pos
) > max_pos
)
19963 INC_BOTH (max_pos
, max_bpos
);
19964 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19966 else if (CHARPOS (it
->eol_pos
) > 0)
19967 SET_TEXT_POS (row
->maxpos
,
19968 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19969 else if (row
->continued_p
)
19971 /* If max_pos is different from IT's current position, it
19972 means IT->method does not belong to the display element
19973 at max_pos. However, it also means that the display
19974 element at max_pos was displayed in its entirety on this
19975 line, which is equivalent to saying that the next line
19976 starts at the next buffer position. */
19977 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19978 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19981 INC_BOTH (max_pos
, max_bpos
);
19982 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19985 else if (row
->truncated_on_right_p
)
19986 /* display_line already called reseat_at_next_visible_line_start,
19987 which puts the iterator at the beginning of the next line, in
19988 the logical order. */
19989 row
->maxpos
= it
->current
.pos
;
19990 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19991 /* A line that is entirely from a string/image/stretch... */
19992 row
->maxpos
= row
->minpos
;
19997 row
->maxpos
= it
->current
.pos
;
20000 /* Construct the glyph row IT->glyph_row in the desired matrix of
20001 IT->w from text at the current position of IT. See dispextern.h
20002 for an overview of struct it. Value is true if
20003 IT->glyph_row displays text, as opposed to a line displaying ZV
20007 display_line (struct it
*it
)
20009 struct glyph_row
*row
= it
->glyph_row
;
20010 Lisp_Object overlay_arrow_string
;
20012 void *wrap_data
= NULL
;
20013 bool may_wrap
= false;
20014 int wrap_x
IF_LINT (= 0);
20015 int wrap_row_used
= -1;
20016 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
20017 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
20018 int wrap_row_extra_line_spacing
IF_LINT (= 0);
20019 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
20020 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
20022 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
20023 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
20024 bool pending_handle_line_prefix
= false;
20026 /* We always start displaying at hpos zero even if hscrolled. */
20027 eassert (it
->hpos
== 0 && it
->current_x
== 0);
20029 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
20030 >= it
->w
->desired_matrix
->nrows
)
20032 it
->w
->nrows_scale_factor
++;
20033 it
->f
->fonts_changed
= true;
20037 /* Clear the result glyph row and enable it. */
20038 prepare_desired_row (it
->w
, row
, false);
20040 row
->y
= it
->current_y
;
20041 row
->start
= it
->start
;
20042 row
->continuation_lines_width
= it
->continuation_lines_width
;
20043 row
->displays_text_p
= true;
20044 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
20045 it
->starts_in_middle_of_char_p
= false;
20047 /* Arrange the overlays nicely for our purposes. Usually, we call
20048 display_line on only one line at a time, in which case this
20049 can't really hurt too much, or we call it on lines which appear
20050 one after another in the buffer, in which case all calls to
20051 recenter_overlay_lists but the first will be pretty cheap. */
20052 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
20054 /* Move over display elements that are not visible because we are
20055 hscrolled. This may stop at an x-position < IT->first_visible_x
20056 if the first glyph is partially visible or if we hit a line end. */
20057 if (it
->current_x
< it
->first_visible_x
)
20059 enum move_it_result move_result
;
20061 this_line_min_pos
= row
->start
.pos
;
20062 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
20063 MOVE_TO_POS
| MOVE_TO_X
);
20064 /* If we are under a large hscroll, move_it_in_display_line_to
20065 could hit the end of the line without reaching
20066 it->first_visible_x. Pretend that we did reach it. This is
20067 especially important on a TTY, where we will call
20068 extend_face_to_end_of_line, which needs to know how many
20069 blank glyphs to produce. */
20070 if (it
->current_x
< it
->first_visible_x
20071 && (move_result
== MOVE_NEWLINE_OR_CR
20072 || move_result
== MOVE_POS_MATCH_OR_ZV
))
20073 it
->current_x
= it
->first_visible_x
;
20075 /* Record the smallest positions seen while we moved over
20076 display elements that are not visible. This is needed by
20077 redisplay_internal for optimizing the case where the cursor
20078 stays inside the same line. The rest of this function only
20079 considers positions that are actually displayed, so
20080 RECORD_MAX_MIN_POS will not otherwise record positions that
20081 are hscrolled to the left of the left edge of the window. */
20082 min_pos
= CHARPOS (this_line_min_pos
);
20083 min_bpos
= BYTEPOS (this_line_min_pos
);
20085 else if (it
->area
== TEXT_AREA
)
20087 /* We only do this when not calling move_it_in_display_line_to
20088 above, because that function calls itself handle_line_prefix. */
20089 handle_line_prefix (it
);
20093 /* Line-prefix and wrap-prefix are always displayed in the text
20094 area. But if this is the first call to display_line after
20095 init_iterator, the iterator might have been set up to write
20096 into a marginal area, e.g. if the line begins with some
20097 display property that writes to the margins. So we need to
20098 wait with the call to handle_line_prefix until whatever
20099 writes to the margin has done its job. */
20100 pending_handle_line_prefix
= true;
20103 /* Get the initial row height. This is either the height of the
20104 text hscrolled, if there is any, or zero. */
20105 row
->ascent
= it
->max_ascent
;
20106 row
->height
= it
->max_ascent
+ it
->max_descent
;
20107 row
->phys_ascent
= it
->max_phys_ascent
;
20108 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20109 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20111 /* Utility macro to record max and min buffer positions seen until now. */
20112 #define RECORD_MAX_MIN_POS(IT) \
20115 bool composition_p \
20116 = !STRINGP ((IT)->string) && ((IT)->what == IT_COMPOSITION); \
20117 ptrdiff_t current_pos = \
20118 composition_p ? (IT)->cmp_it.charpos \
20119 : IT_CHARPOS (*(IT)); \
20120 ptrdiff_t current_bpos = \
20121 composition_p ? CHAR_TO_BYTE (current_pos) \
20122 : IT_BYTEPOS (*(IT)); \
20123 if (current_pos < min_pos) \
20125 min_pos = current_pos; \
20126 min_bpos = current_bpos; \
20128 if (IT_CHARPOS (*it) > max_pos) \
20130 max_pos = IT_CHARPOS (*it); \
20131 max_bpos = IT_BYTEPOS (*it); \
20136 /* Loop generating characters. The loop is left with IT on the next
20137 character to display. */
20140 int n_glyphs_before
, hpos_before
, x_before
;
20142 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
20144 /* Retrieve the next thing to display. Value is false if end of
20146 if (!get_next_display_element (it
))
20148 /* Maybe add a space at the end of this line that is used to
20149 display the cursor there under X. Set the charpos of the
20150 first glyph of blank lines not corresponding to any text
20152 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20153 row
->exact_window_width_line_p
= true;
20154 else if ((append_space_for_newline (it
, true)
20155 && row
->used
[TEXT_AREA
] == 1)
20156 || row
->used
[TEXT_AREA
] == 0)
20158 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
20159 row
->displays_text_p
= false;
20161 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
20162 && (!MINI_WINDOW_P (it
->w
)
20163 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
20164 row
->indicate_empty_line_p
= true;
20167 it
->continuation_lines_width
= 0;
20168 row
->ends_at_zv_p
= true;
20169 /* A row that displays right-to-left text must always have
20170 its last face extended all the way to the end of line,
20171 even if this row ends in ZV, because we still write to
20172 the screen left to right. We also need to extend the
20173 last face if the default face is remapped to some
20174 different face, otherwise the functions that clear
20175 portions of the screen will clear with the default face's
20176 background color. */
20177 if (row
->reversed_p
20178 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
20179 extend_face_to_end_of_line (it
);
20183 /* Now, get the metrics of what we want to display. This also
20184 generates glyphs in `row' (which is IT->glyph_row). */
20185 n_glyphs_before
= row
->used
[TEXT_AREA
];
20188 /* Remember the line height so far in case the next element doesn't
20189 fit on the line. */
20190 if (it
->line_wrap
!= TRUNCATE
)
20192 ascent
= it
->max_ascent
;
20193 descent
= it
->max_descent
;
20194 phys_ascent
= it
->max_phys_ascent
;
20195 phys_descent
= it
->max_phys_descent
;
20197 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
20199 if (IT_DISPLAYING_WHITESPACE (it
))
20203 SAVE_IT (wrap_it
, *it
, wrap_data
);
20205 wrap_row_used
= row
->used
[TEXT_AREA
];
20206 wrap_row_ascent
= row
->ascent
;
20207 wrap_row_height
= row
->height
;
20208 wrap_row_phys_ascent
= row
->phys_ascent
;
20209 wrap_row_phys_height
= row
->phys_height
;
20210 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
20211 wrap_row_min_pos
= min_pos
;
20212 wrap_row_min_bpos
= min_bpos
;
20213 wrap_row_max_pos
= max_pos
;
20214 wrap_row_max_bpos
= max_bpos
;
20220 PRODUCE_GLYPHS (it
);
20222 /* If this display element was in marginal areas, continue with
20224 if (it
->area
!= TEXT_AREA
)
20226 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20227 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20228 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20229 row
->phys_height
= max (row
->phys_height
,
20230 it
->max_phys_ascent
+ it
->max_phys_descent
);
20231 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20232 it
->max_extra_line_spacing
);
20233 set_iterator_to_next (it
, true);
20234 /* If we didn't handle the line/wrap prefix above, and the
20235 call to set_iterator_to_next just switched to TEXT_AREA,
20236 process the prefix now. */
20237 if (it
->area
== TEXT_AREA
&& pending_handle_line_prefix
)
20239 pending_handle_line_prefix
= false;
20240 handle_line_prefix (it
);
20245 /* Does the display element fit on the line? If we truncate
20246 lines, we should draw past the right edge of the window. If
20247 we don't truncate, we want to stop so that we can display the
20248 continuation glyph before the right margin. If lines are
20249 continued, there are two possible strategies for characters
20250 resulting in more than 1 glyph (e.g. tabs): Display as many
20251 glyphs as possible in this line and leave the rest for the
20252 continuation line, or display the whole element in the next
20253 line. Original redisplay did the former, so we do it also. */
20254 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20255 hpos_before
= it
->hpos
;
20258 if (/* Not a newline. */
20260 /* Glyphs produced fit entirely in the line. */
20261 && it
->current_x
< it
->last_visible_x
)
20263 it
->hpos
+= nglyphs
;
20264 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20265 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20266 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20267 row
->phys_height
= max (row
->phys_height
,
20268 it
->max_phys_ascent
+ it
->max_phys_descent
);
20269 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20270 it
->max_extra_line_spacing
);
20271 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
20272 /* In R2L rows, we arrange in extend_face_to_end_of_line
20273 to add a right offset to the line, by a suitable
20274 change to the stretch glyph that is the leftmost
20275 glyph of the line. */
20276 && !row
->reversed_p
)
20277 row
->x
= x
- it
->first_visible_x
;
20278 /* Record the maximum and minimum buffer positions seen so
20279 far in glyphs that will be displayed by this row. */
20281 RECORD_MAX_MIN_POS (it
);
20286 struct glyph
*glyph
;
20288 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
20290 /* Identify the glyphs added by the last call to
20291 PRODUCE_GLYPHS. In R2L rows, they are prepended to
20292 the previous glyphs. */
20293 if (!row
->reversed_p
)
20294 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20296 glyph
= row
->glyphs
[TEXT_AREA
] + nglyphs
- 1 - i
;
20297 new_x
= x
+ glyph
->pixel_width
;
20299 if (/* Lines are continued. */
20300 it
->line_wrap
!= TRUNCATE
20301 && (/* Glyph doesn't fit on the line. */
20302 new_x
> it
->last_visible_x
20303 /* Or it fits exactly on a window system frame. */
20304 || (new_x
== it
->last_visible_x
20305 && FRAME_WINDOW_P (it
->f
)
20306 && (row
->reversed_p
20307 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20308 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
20310 /* End of a continued line. */
20313 || (new_x
== it
->last_visible_x
20314 && FRAME_WINDOW_P (it
->f
)
20315 && (row
->reversed_p
20316 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20317 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
20319 /* Current glyph is the only one on the line or
20320 fits exactly on the line. We must continue
20321 the line because we can't draw the cursor
20322 after the glyph. */
20323 row
->continued_p
= true;
20324 it
->current_x
= new_x
;
20325 it
->continuation_lines_width
+= new_x
;
20327 if (i
== nglyphs
- 1)
20329 /* If line-wrap is on, check if a previous
20330 wrap point was found. */
20331 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)
20332 && wrap_row_used
> 0
20333 /* Even if there is a previous wrap
20334 point, continue the line here as
20335 usual, if (i) the previous character
20336 was a space or tab AND (ii) the
20337 current character is not. */
20339 || IT_DISPLAYING_WHITESPACE (it
)))
20342 /* Record the maximum and minimum buffer
20343 positions seen so far in glyphs that will be
20344 displayed by this row. */
20346 RECORD_MAX_MIN_POS (it
);
20347 set_iterator_to_next (it
, true);
20348 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20350 if (!get_next_display_element (it
))
20352 row
->exact_window_width_line_p
= true;
20353 it
->continuation_lines_width
= 0;
20354 row
->continued_p
= false;
20355 row
->ends_at_zv_p
= true;
20357 else if (ITERATOR_AT_END_OF_LINE_P (it
))
20359 row
->continued_p
= false;
20360 row
->exact_window_width_line_p
= true;
20362 /* If line-wrap is on, check if a
20363 previous wrap point was found. */
20364 else if (wrap_row_used
> 0
20365 /* Even if there is a previous wrap
20366 point, continue the line here as
20367 usual, if (i) the previous character
20368 was a space or tab AND (ii) the
20369 current character is not. */
20371 || IT_DISPLAYING_WHITESPACE (it
)))
20376 else if (it
->bidi_p
)
20377 RECORD_MAX_MIN_POS (it
);
20378 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20379 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20380 extend_face_to_end_of_line (it
);
20382 else if (CHAR_GLYPH_PADDING_P (*glyph
)
20383 && !FRAME_WINDOW_P (it
->f
))
20385 /* A padding glyph that doesn't fit on this line.
20386 This means the whole character doesn't fit
20388 if (row
->reversed_p
)
20389 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20390 - n_glyphs_before
);
20391 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20393 /* Fill the rest of the row with continuation
20394 glyphs like in 20.x. */
20395 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
20396 < row
->glyphs
[1 + TEXT_AREA
])
20397 produce_special_glyphs (it
, IT_CONTINUATION
);
20399 row
->continued_p
= true;
20400 it
->current_x
= x_before
;
20401 it
->continuation_lines_width
+= x_before
;
20403 /* Restore the height to what it was before the
20404 element not fitting on the line. */
20405 it
->max_ascent
= ascent
;
20406 it
->max_descent
= descent
;
20407 it
->max_phys_ascent
= phys_ascent
;
20408 it
->max_phys_descent
= phys_descent
;
20409 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20410 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20411 extend_face_to_end_of_line (it
);
20413 else if (wrap_row_used
> 0)
20416 if (row
->reversed_p
)
20417 unproduce_glyphs (it
,
20418 row
->used
[TEXT_AREA
] - wrap_row_used
);
20419 RESTORE_IT (it
, &wrap_it
, wrap_data
);
20420 it
->continuation_lines_width
+= wrap_x
;
20421 row
->used
[TEXT_AREA
] = wrap_row_used
;
20422 row
->ascent
= wrap_row_ascent
;
20423 row
->height
= wrap_row_height
;
20424 row
->phys_ascent
= wrap_row_phys_ascent
;
20425 row
->phys_height
= wrap_row_phys_height
;
20426 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
20427 min_pos
= wrap_row_min_pos
;
20428 min_bpos
= wrap_row_min_bpos
;
20429 max_pos
= wrap_row_max_pos
;
20430 max_bpos
= wrap_row_max_bpos
;
20431 row
->continued_p
= true;
20432 row
->ends_at_zv_p
= false;
20433 row
->exact_window_width_line_p
= false;
20434 it
->continuation_lines_width
+= x
;
20436 /* Make sure that a non-default face is extended
20437 up to the right margin of the window. */
20438 extend_face_to_end_of_line (it
);
20440 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
20442 /* A TAB that extends past the right edge of the
20443 window. This produces a single glyph on
20444 window system frames. We leave the glyph in
20445 this row and let it fill the row, but don't
20446 consume the TAB. */
20447 if ((row
->reversed_p
20448 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20449 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20450 produce_special_glyphs (it
, IT_CONTINUATION
);
20451 it
->continuation_lines_width
+= it
->last_visible_x
;
20452 row
->ends_in_middle_of_char_p
= true;
20453 row
->continued_p
= true;
20454 glyph
->pixel_width
= it
->last_visible_x
- x
;
20455 it
->starts_in_middle_of_char_p
= true;
20456 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20457 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20458 extend_face_to_end_of_line (it
);
20462 /* Something other than a TAB that draws past
20463 the right edge of the window. Restore
20464 positions to values before the element. */
20465 if (row
->reversed_p
)
20466 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20467 - (n_glyphs_before
+ i
));
20468 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20470 /* Display continuation glyphs. */
20471 it
->current_x
= x_before
;
20472 it
->continuation_lines_width
+= x
;
20473 if (!FRAME_WINDOW_P (it
->f
)
20474 || (row
->reversed_p
20475 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20476 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20477 produce_special_glyphs (it
, IT_CONTINUATION
);
20478 row
->continued_p
= true;
20480 extend_face_to_end_of_line (it
);
20482 if (nglyphs
> 1 && i
> 0)
20484 row
->ends_in_middle_of_char_p
= true;
20485 it
->starts_in_middle_of_char_p
= true;
20488 /* Restore the height to what it was before the
20489 element not fitting on the line. */
20490 it
->max_ascent
= ascent
;
20491 it
->max_descent
= descent
;
20492 it
->max_phys_ascent
= phys_ascent
;
20493 it
->max_phys_descent
= phys_descent
;
20498 else if (new_x
> it
->first_visible_x
)
20500 /* Increment number of glyphs actually displayed. */
20503 /* Record the maximum and minimum buffer positions
20504 seen so far in glyphs that will be displayed by
20507 RECORD_MAX_MIN_POS (it
);
20509 if (x
< it
->first_visible_x
&& !row
->reversed_p
)
20510 /* Glyph is partially visible, i.e. row starts at
20511 negative X position. Don't do that in R2L
20512 rows, where we arrange to add a right offset to
20513 the line in extend_face_to_end_of_line, by a
20514 suitable change to the stretch glyph that is
20515 the leftmost glyph of the line. */
20516 row
->x
= x
- it
->first_visible_x
;
20517 /* When the last glyph of an R2L row only fits
20518 partially on the line, we need to set row->x to a
20519 negative offset, so that the leftmost glyph is
20520 the one that is partially visible. But if we are
20521 going to produce the truncation glyph, this will
20522 be taken care of in produce_special_glyphs. */
20523 if (row
->reversed_p
20524 && new_x
> it
->last_visible_x
20525 && !(it
->line_wrap
== TRUNCATE
20526 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
20528 eassert (FRAME_WINDOW_P (it
->f
));
20529 row
->x
= it
->last_visible_x
- new_x
;
20534 /* Glyph is completely off the left margin of the
20535 window. This should not happen because of the
20536 move_it_in_display_line at the start of this
20537 function, unless the text display area of the
20538 window is empty. */
20539 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20542 /* Even if this display element produced no glyphs at all,
20543 we want to record its position. */
20544 if (it
->bidi_p
&& nglyphs
== 0)
20545 RECORD_MAX_MIN_POS (it
);
20547 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20548 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20549 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20550 row
->phys_height
= max (row
->phys_height
,
20551 it
->max_phys_ascent
+ it
->max_phys_descent
);
20552 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20553 it
->max_extra_line_spacing
);
20555 /* End of this display line if row is continued. */
20556 if (row
->continued_p
|| row
->ends_at_zv_p
)
20561 /* Is this a line end? If yes, we're also done, after making
20562 sure that a non-default face is extended up to the right
20563 margin of the window. */
20564 if (ITERATOR_AT_END_OF_LINE_P (it
))
20566 int used_before
= row
->used
[TEXT_AREA
];
20568 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20570 /* Add a space at the end of the line that is used to
20571 display the cursor there. */
20572 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20573 append_space_for_newline (it
, false);
20575 /* Extend the face to the end of the line. */
20576 extend_face_to_end_of_line (it
);
20578 /* Make sure we have the position. */
20579 if (used_before
== 0)
20580 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20582 /* Record the position of the newline, for use in
20584 it
->eol_pos
= it
->current
.pos
;
20586 /* Consume the line end. This skips over invisible lines. */
20587 set_iterator_to_next (it
, true);
20588 it
->continuation_lines_width
= 0;
20592 /* Proceed with next display element. Note that this skips
20593 over lines invisible because of selective display. */
20594 set_iterator_to_next (it
, true);
20596 /* If we truncate lines, we are done when the last displayed
20597 glyphs reach past the right margin of the window. */
20598 if (it
->line_wrap
== TRUNCATE
20599 && ((FRAME_WINDOW_P (it
->f
)
20600 /* Images are preprocessed in produce_image_glyph such
20601 that they are cropped at the right edge of the
20602 window, so an image glyph will always end exactly at
20603 last_visible_x, even if there's no right fringe. */
20604 && ((row
->reversed_p
20605 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20606 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))
20607 || it
->what
== IT_IMAGE
))
20608 ? (it
->current_x
>= it
->last_visible_x
)
20609 : (it
->current_x
> it
->last_visible_x
)))
20611 /* Maybe add truncation glyphs. */
20612 if (!FRAME_WINDOW_P (it
->f
)
20613 || (row
->reversed_p
20614 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20615 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20619 if (!row
->reversed_p
)
20621 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20622 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20627 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20628 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20630 /* Remove any padding glyphs at the front of ROW, to
20631 make room for the truncation glyphs we will be
20632 adding below. The loop below always inserts at
20633 least one truncation glyph, so also remove the
20634 last glyph added to ROW. */
20635 unproduce_glyphs (it
, i
+ 1);
20636 /* Adjust i for the loop below. */
20637 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20640 /* produce_special_glyphs overwrites the last glyph, so
20641 we don't want that if we want to keep that last
20642 glyph, which means it's an image. */
20643 if (it
->current_x
> it
->last_visible_x
)
20645 it
->current_x
= x_before
;
20646 if (!FRAME_WINDOW_P (it
->f
))
20648 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20650 row
->used
[TEXT_AREA
] = i
;
20651 produce_special_glyphs (it
, IT_TRUNCATION
);
20656 row
->used
[TEXT_AREA
] = i
;
20657 produce_special_glyphs (it
, IT_TRUNCATION
);
20659 it
->hpos
= hpos_before
;
20662 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20664 /* Don't truncate if we can overflow newline into fringe. */
20665 if (!get_next_display_element (it
))
20667 it
->continuation_lines_width
= 0;
20668 row
->ends_at_zv_p
= true;
20669 row
->exact_window_width_line_p
= true;
20672 if (ITERATOR_AT_END_OF_LINE_P (it
))
20674 row
->exact_window_width_line_p
= true;
20675 goto at_end_of_line
;
20677 it
->current_x
= x_before
;
20678 it
->hpos
= hpos_before
;
20681 row
->truncated_on_right_p
= true;
20682 it
->continuation_lines_width
= 0;
20683 reseat_at_next_visible_line_start (it
, false);
20684 /* We insist below that IT's position be at ZV because in
20685 bidi-reordered lines the character at visible line start
20686 might not be the character that follows the newline in
20687 the logical order. */
20688 if (IT_BYTEPOS (*it
) > BEG_BYTE
)
20689 row
->ends_at_zv_p
=
20690 IT_BYTEPOS (*it
) >= ZV_BYTE
&& FETCH_BYTE (ZV_BYTE
- 1) != '\n';
20692 row
->ends_at_zv_p
= false;
20698 bidi_unshelve_cache (wrap_data
, true);
20700 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20701 at the left window margin. */
20702 if (it
->first_visible_x
20703 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20705 if (!FRAME_WINDOW_P (it
->f
)
20706 || (((row
->reversed_p
20707 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20708 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20709 /* Don't let insert_left_trunc_glyphs overwrite the
20710 first glyph of the row if it is an image. */
20711 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
20712 insert_left_trunc_glyphs (it
);
20713 row
->truncated_on_left_p
= true;
20716 /* Remember the position at which this line ends.
20718 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20719 cannot be before the call to find_row_edges below, since that is
20720 where these positions are determined. */
20721 row
->end
= it
->current
;
20724 row
->minpos
= row
->start
.pos
;
20725 row
->maxpos
= row
->end
.pos
;
20729 /* ROW->minpos and ROW->maxpos must be the smallest and
20730 `1 + the largest' buffer positions in ROW. But if ROW was
20731 bidi-reordered, these two positions can be anywhere in the
20732 row, so we must determine them now. */
20733 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20736 /* If the start of this line is the overlay arrow-position, then
20737 mark this glyph row as the one containing the overlay arrow.
20738 This is clearly a mess with variable size fonts. It would be
20739 better to let it be displayed like cursors under X. */
20740 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20741 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20742 !NILP (overlay_arrow_string
)))
20744 /* Overlay arrow in window redisplay is a fringe bitmap. */
20745 if (STRINGP (overlay_arrow_string
))
20747 struct glyph_row
*arrow_row
20748 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20749 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20750 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20751 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20752 struct glyph
*p2
, *end
;
20754 /* Copy the arrow glyphs. */
20755 while (glyph
< arrow_end
)
20758 /* Throw away padding glyphs. */
20760 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20761 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20767 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20772 eassert (INTEGERP (overlay_arrow_string
));
20773 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20775 overlay_arrow_seen
= true;
20778 /* Highlight trailing whitespace. */
20779 if (!NILP (Vshow_trailing_whitespace
))
20780 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20782 /* Compute pixel dimensions of this line. */
20783 compute_line_metrics (it
);
20785 /* Implementation note: No changes in the glyphs of ROW or in their
20786 faces can be done past this point, because compute_line_metrics
20787 computes ROW's hash value and stores it within the glyph_row
20790 /* Record whether this row ends inside an ellipsis. */
20791 row
->ends_in_ellipsis_p
20792 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20793 && it
->ellipsis_p
);
20795 /* Save fringe bitmaps in this row. */
20796 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20797 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20798 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20799 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20801 it
->left_user_fringe_bitmap
= 0;
20802 it
->left_user_fringe_face_id
= 0;
20803 it
->right_user_fringe_bitmap
= 0;
20804 it
->right_user_fringe_face_id
= 0;
20806 /* Maybe set the cursor. */
20807 cvpos
= it
->w
->cursor
.vpos
;
20809 /* In bidi-reordered rows, keep checking for proper cursor
20810 position even if one has been found already, because buffer
20811 positions in such rows change non-linearly with ROW->VPOS,
20812 when a line is continued. One exception: when we are at ZV,
20813 display cursor on the first suitable glyph row, since all
20814 the empty rows after that also have their position set to ZV. */
20815 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20816 lines' rows is implemented for bidi-reordered rows. */
20818 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20819 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20820 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20821 && cursor_row_p (row
))
20822 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20824 /* Prepare for the next line. This line starts horizontally at (X
20825 HPOS) = (0 0). Vertical positions are incremented. As a
20826 convenience for the caller, IT->glyph_row is set to the next
20828 it
->current_x
= it
->hpos
= 0;
20829 it
->current_y
+= row
->height
;
20830 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20833 /* The next row should by default use the same value of the
20834 reversed_p flag as this one. set_iterator_to_next decides when
20835 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20836 the flag accordingly. */
20837 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20838 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20839 it
->start
= row
->end
;
20840 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20842 #undef RECORD_MAX_MIN_POS
20845 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20846 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20847 doc
: /* Return paragraph direction at point in BUFFER.
20848 Value is either `left-to-right' or `right-to-left'.
20849 If BUFFER is omitted or nil, it defaults to the current buffer.
20851 Paragraph direction determines how the text in the paragraph is displayed.
20852 In left-to-right paragraphs, text begins at the left margin of the window
20853 and the reading direction is generally left to right. In right-to-left
20854 paragraphs, text begins at the right margin and is read from right to left.
20856 See also `bidi-paragraph-direction'. */)
20857 (Lisp_Object buffer
)
20859 struct buffer
*buf
= current_buffer
;
20860 struct buffer
*old
= buf
;
20862 if (! NILP (buffer
))
20864 CHECK_BUFFER (buffer
);
20865 buf
= XBUFFER (buffer
);
20868 if (NILP (BVAR (buf
, bidi_display_reordering
))
20869 || NILP (BVAR (buf
, enable_multibyte_characters
))
20870 /* When we are loading loadup.el, the character property tables
20871 needed for bidi iteration are not yet available. */
20872 || !NILP (Vpurify_flag
))
20873 return Qleft_to_right
;
20874 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20875 return BVAR (buf
, bidi_paragraph_direction
);
20878 /* Determine the direction from buffer text. We could try to
20879 use current_matrix if it is up to date, but this seems fast
20880 enough as it is. */
20881 struct bidi_it itb
;
20882 ptrdiff_t pos
= BUF_PT (buf
);
20883 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20885 void *itb_data
= bidi_shelve_cache ();
20887 set_buffer_temp (buf
);
20888 /* bidi_paragraph_init finds the base direction of the paragraph
20889 by searching forward from paragraph start. We need the base
20890 direction of the current or _previous_ paragraph, so we need
20891 to make sure we are within that paragraph. To that end, find
20892 the previous non-empty line. */
20893 if (pos
>= ZV
&& pos
> BEGV
)
20894 DEC_BOTH (pos
, bytepos
);
20895 AUTO_STRING (trailing_white_space
, "[\f\t ]*\n");
20896 if (fast_looking_at (trailing_white_space
,
20897 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20899 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20900 || c
== ' ' || c
== '\t' || c
== '\f')
20902 if (bytepos
<= BEGV_BYTE
)
20907 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20910 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20911 itb
.paragraph_dir
= NEUTRAL_DIR
;
20912 itb
.string
.s
= NULL
;
20913 itb
.string
.lstring
= Qnil
;
20914 itb
.string
.bufpos
= 0;
20915 itb
.string
.from_disp_str
= false;
20916 itb
.string
.unibyte
= false;
20917 /* We have no window to use here for ignoring window-specific
20918 overlays. Using NULL for window pointer will cause
20919 compute_display_string_pos to use the current buffer. */
20921 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, true);
20922 bidi_unshelve_cache (itb_data
, false);
20923 set_buffer_temp (old
);
20924 switch (itb
.paragraph_dir
)
20927 return Qleft_to_right
;
20930 return Qright_to_left
;
20938 DEFUN ("bidi-find-overridden-directionality",
20939 Fbidi_find_overridden_directionality
,
20940 Sbidi_find_overridden_directionality
, 2, 3, 0,
20941 doc
: /* Return position between FROM and TO where directionality was overridden.
20943 This function returns the first character position in the specified
20944 region of OBJECT where there is a character whose `bidi-class' property
20945 is `L', but which was forced to display as `R' by a directional
20946 override, and likewise with characters whose `bidi-class' is `R'
20947 or `AL' that were forced to display as `L'.
20949 If no such character is found, the function returns nil.
20951 OBJECT is a Lisp string or buffer to search for overridden
20952 directionality, and defaults to the current buffer if nil or omitted.
20953 OBJECT can also be a window, in which case the function will search
20954 the buffer displayed in that window. Passing the window instead of
20955 a buffer is preferable when the buffer is displayed in some window,
20956 because this function will then be able to correctly account for
20957 window-specific overlays, which can affect the results.
20959 Strong directional characters `L', `R', and `AL' can have their
20960 intrinsic directionality overridden by directional override
20961 control characters RLO \(u+202e) and LRO \(u+202d). See the
20962 function `get-char-code-property' for a way to inquire about
20963 the `bidi-class' property of a character. */)
20964 (Lisp_Object from
, Lisp_Object to
, Lisp_Object object
)
20966 struct buffer
*buf
= current_buffer
;
20967 struct buffer
*old
= buf
;
20968 struct window
*w
= NULL
;
20969 bool frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ());
20970 struct bidi_it itb
;
20971 ptrdiff_t from_pos
, to_pos
, from_bpos
;
20974 if (!NILP (object
))
20976 if (BUFFERP (object
))
20977 buf
= XBUFFER (object
);
20978 else if (WINDOWP (object
))
20980 w
= decode_live_window (object
);
20981 buf
= XBUFFER (w
->contents
);
20982 frame_window_p
= FRAME_WINDOW_P (XFRAME (w
->frame
));
20985 CHECK_STRING (object
);
20988 if (STRINGP (object
))
20990 /* Characters in unibyte strings are always treated by bidi.c as
20992 if (!STRING_MULTIBYTE (object
)
20993 /* When we are loading loadup.el, the character property
20994 tables needed for bidi iteration are not yet
20996 || !NILP (Vpurify_flag
))
20999 validate_subarray (object
, from
, to
, SCHARS (object
), &from_pos
, &to_pos
);
21000 if (from_pos
>= SCHARS (object
))
21003 /* Set up the bidi iterator. */
21004 itb_data
= bidi_shelve_cache ();
21005 itb
.paragraph_dir
= NEUTRAL_DIR
;
21006 itb
.string
.lstring
= object
;
21007 itb
.string
.s
= NULL
;
21008 itb
.string
.schars
= SCHARS (object
);
21009 itb
.string
.bufpos
= 0;
21010 itb
.string
.from_disp_str
= false;
21011 itb
.string
.unibyte
= false;
21013 bidi_init_it (0, 0, frame_window_p
, &itb
);
21017 /* Nothing this fancy can happen in unibyte buffers, or in a
21018 buffer that disabled reordering, or if FROM is at EOB. */
21019 if (NILP (BVAR (buf
, bidi_display_reordering
))
21020 || NILP (BVAR (buf
, enable_multibyte_characters
))
21021 /* When we are loading loadup.el, the character property
21022 tables needed for bidi iteration are not yet
21024 || !NILP (Vpurify_flag
))
21027 set_buffer_temp (buf
);
21028 validate_region (&from
, &to
);
21029 from_pos
= XINT (from
);
21030 to_pos
= XINT (to
);
21031 if (from_pos
>= ZV
)
21034 /* Set up the bidi iterator. */
21035 itb_data
= bidi_shelve_cache ();
21036 from_bpos
= CHAR_TO_BYTE (from_pos
);
21037 if (from_pos
== BEGV
)
21039 itb
.charpos
= BEGV
;
21040 itb
.bytepos
= BEGV_BYTE
;
21042 else if (FETCH_CHAR (from_bpos
- 1) == '\n')
21044 itb
.charpos
= from_pos
;
21045 itb
.bytepos
= from_bpos
;
21048 itb
.charpos
= find_newline_no_quit (from_pos
, CHAR_TO_BYTE (from_pos
),
21050 itb
.paragraph_dir
= NEUTRAL_DIR
;
21051 itb
.string
.s
= NULL
;
21052 itb
.string
.lstring
= Qnil
;
21053 itb
.string
.bufpos
= 0;
21054 itb
.string
.from_disp_str
= false;
21055 itb
.string
.unibyte
= false;
21057 bidi_init_it (itb
.charpos
, itb
.bytepos
, frame_window_p
, &itb
);
21062 /* For the purposes of this function, the actual base direction of
21063 the paragraph doesn't matter, so just set it to L2R. */
21064 bidi_paragraph_init (L2R
, &itb
, false);
21065 while ((found
= bidi_find_first_overridden (&itb
)) < from_pos
)
21067 } while (found
== ZV
&& itb
.ch
== '\n' && itb
.charpos
< to_pos
);
21069 bidi_unshelve_cache (itb_data
, false);
21070 set_buffer_temp (old
);
21072 return (from_pos
<= found
&& found
< to_pos
) ? make_number (found
) : Qnil
;
21075 DEFUN ("move-point-visually", Fmove_point_visually
,
21076 Smove_point_visually
, 1, 1, 0,
21077 doc
: /* Move point in the visual order in the specified DIRECTION.
21078 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
21081 Value is the new character position of point. */)
21082 (Lisp_Object direction
)
21084 struct window
*w
= XWINDOW (selected_window
);
21085 struct buffer
*b
= XBUFFER (w
->contents
);
21086 struct glyph_row
*row
;
21088 Lisp_Object paragraph_dir
;
21090 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
21091 (!(ROW)->continued_p \
21092 && NILP ((GLYPH)->object) \
21093 && (GLYPH)->type == CHAR_GLYPH \
21094 && (GLYPH)->u.ch == ' ' \
21095 && (GLYPH)->charpos >= 0 \
21096 && !(GLYPH)->avoid_cursor_p)
21098 CHECK_NUMBER (direction
);
21099 dir
= XINT (direction
);
21105 /* If current matrix is up-to-date, we can use the information
21106 recorded in the glyphs, at least as long as the goal is on the
21108 if (w
->window_end_valid
21109 && !windows_or_buffers_changed
21111 && !b
->clip_changed
21112 && !b
->prevent_redisplay_optimizations_p
21113 && !window_outdated (w
)
21114 /* We rely below on the cursor coordinates to be up to date, but
21115 we cannot trust them if some command moved point since the
21116 last complete redisplay. */
21117 && w
->last_point
== BUF_PT (b
)
21118 && w
->cursor
.vpos
>= 0
21119 && w
->cursor
.vpos
< w
->current_matrix
->nrows
21120 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
21122 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
21123 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
21124 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
21126 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
21128 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
21130 SET_PT (g
->charpos
);
21131 w
->cursor
.vpos
= -1;
21132 return make_number (PT
);
21134 else if (!NILP (g
->object
) && !EQ (g
->object
, gpt
->object
))
21138 if (BUFFERP (gpt
->object
))
21141 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
21142 new_pos
+= (row
->reversed_p
? -dir
: dir
);
21144 new_pos
-= (row
->reversed_p
? -dir
: dir
);
21146 else if (BUFFERP (g
->object
))
21147 new_pos
= g
->charpos
;
21151 w
->cursor
.vpos
= -1;
21152 return make_number (PT
);
21154 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
21156 /* Glyphs inserted at the end of a non-empty line for
21157 positioning the cursor have zero charpos, so we must
21158 deduce the value of point by other means. */
21159 if (g
->charpos
> 0)
21160 SET_PT (g
->charpos
);
21161 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
21163 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
21164 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21167 w
->cursor
.vpos
= -1;
21168 return make_number (PT
);
21171 if (g
== e
|| NILP (g
->object
))
21173 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
21174 goto simulate_display
;
21175 if (!row
->reversed_p
)
21179 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
21180 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
21181 goto simulate_display
;
21185 if (row
->reversed_p
&& !row
->continued_p
)
21187 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21188 w
->cursor
.vpos
= -1;
21189 return make_number (PT
);
21191 g
= row
->glyphs
[TEXT_AREA
];
21192 e
= g
+ row
->used
[TEXT_AREA
];
21193 for ( ; g
< e
; g
++)
21195 if (BUFFERP (g
->object
)
21196 /* Empty lines have only one glyph, which stands
21197 for the newline, and whose charpos is the
21198 buffer position of the newline. */
21199 || ROW_GLYPH_NEWLINE_P (row
, g
)
21200 /* When the buffer ends in a newline, the line at
21201 EOB also has one glyph, but its charpos is -1. */
21202 || (row
->ends_at_zv_p
21203 && !row
->reversed_p
21204 && NILP (g
->object
)
21205 && g
->type
== CHAR_GLYPH
21206 && g
->u
.ch
== ' '))
21208 if (g
->charpos
> 0)
21209 SET_PT (g
->charpos
);
21210 else if (!row
->reversed_p
21211 && row
->ends_at_zv_p
21216 w
->cursor
.vpos
= -1;
21217 return make_number (PT
);
21223 if (!row
->reversed_p
&& !row
->continued_p
)
21225 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21226 w
->cursor
.vpos
= -1;
21227 return make_number (PT
);
21229 e
= row
->glyphs
[TEXT_AREA
];
21230 g
= e
+ row
->used
[TEXT_AREA
] - 1;
21231 for ( ; g
>= e
; g
--)
21233 if (BUFFERP (g
->object
)
21234 || (ROW_GLYPH_NEWLINE_P (row
, g
)
21236 /* Empty R2L lines on GUI frames have the buffer
21237 position of the newline stored in the stretch
21239 || g
->type
== STRETCH_GLYPH
21240 || (row
->ends_at_zv_p
21242 && NILP (g
->object
)
21243 && g
->type
== CHAR_GLYPH
21244 && g
->u
.ch
== ' '))
21246 if (g
->charpos
> 0)
21247 SET_PT (g
->charpos
);
21248 else if (row
->reversed_p
21249 && row
->ends_at_zv_p
21254 w
->cursor
.vpos
= -1;
21255 return make_number (PT
);
21264 /* If we wind up here, we failed to move by using the glyphs, so we
21265 need to simulate display instead. */
21268 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
21270 paragraph_dir
= Qleft_to_right
;
21271 if (EQ (paragraph_dir
, Qright_to_left
))
21273 if (PT
<= BEGV
&& dir
< 0)
21274 xsignal0 (Qbeginning_of_buffer
);
21275 else if (PT
>= ZV
&& dir
> 0)
21276 xsignal0 (Qend_of_buffer
);
21279 struct text_pos pt
;
21281 int pt_x
, target_x
, pixel_width
, pt_vpos
;
21283 bool overshoot_expected
= false;
21284 bool target_is_eol_p
= false;
21286 /* Setup the arena. */
21287 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
21288 start_display (&it
, w
, pt
);
21290 if (it
.cmp_it
.id
< 0
21291 && it
.method
== GET_FROM_STRING
21292 && it
.area
== TEXT_AREA
21293 && it
.string_from_display_prop_p
21294 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
21295 overshoot_expected
= true;
21297 /* Find the X coordinate of point. We start from the beginning
21298 of this or previous line to make sure we are before point in
21299 the logical order (since the move_it_* functions can only
21302 reseat_at_previous_visible_line_start (&it
);
21303 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
21304 if (IT_CHARPOS (it
) != PT
)
21306 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
21307 -1, -1, -1, MOVE_TO_POS
);
21308 /* If we missed point because the character there is
21309 displayed out of a display vector that has more than one
21310 glyph, retry expecting overshoot. */
21311 if (it
.method
== GET_FROM_DISPLAY_VECTOR
21312 && it
.current
.dpvec_index
> 0
21313 && !overshoot_expected
)
21315 overshoot_expected
= true;
21318 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
21319 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
21321 pt_x
= it
.current_x
;
21323 if (dir
> 0 || overshoot_expected
)
21325 struct glyph_row
*row
= it
.glyph_row
;
21327 /* When point is at beginning of line, we don't have
21328 information about the glyph there loaded into struct
21329 it. Calling get_next_display_element fixes that. */
21331 get_next_display_element (&it
);
21332 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21333 it
.glyph_row
= NULL
;
21334 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
21335 it
.glyph_row
= row
;
21336 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
21337 it, lest it will become out of sync with it's buffer
21339 it
.current_x
= pt_x
;
21342 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21343 pixel_width
= it
.pixel_width
;
21344 if (overshoot_expected
&& at_eol_p
)
21346 else if (pixel_width
<= 0)
21349 /* If there's a display string (or something similar) at point,
21350 we are actually at the glyph to the left of point, so we need
21351 to correct the X coordinate. */
21352 if (overshoot_expected
)
21355 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
21357 pt_x
+= pixel_width
;
21360 /* Compute target X coordinate, either to the left or to the
21361 right of point. On TTY frames, all characters have the same
21362 pixel width of 1, so we can use that. On GUI frames we don't
21363 have an easy way of getting at the pixel width of the
21364 character to the left of point, so we use a different method
21365 of getting to that place. */
21367 target_x
= pt_x
+ pixel_width
;
21369 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
21371 /* Target X coordinate could be one line above or below the line
21372 of point, in which case we need to adjust the target X
21373 coordinate. Also, if moving to the left, we need to begin at
21374 the left edge of the point's screen line. */
21379 start_display (&it
, w
, pt
);
21380 reseat_at_previous_visible_line_start (&it
);
21381 it
.current_x
= it
.current_y
= it
.hpos
= 0;
21383 move_it_by_lines (&it
, pt_vpos
);
21387 move_it_by_lines (&it
, -1);
21388 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
21389 target_is_eol_p
= true;
21390 /* Under word-wrap, we don't know the x coordinate of
21391 the last character displayed on the previous line,
21392 which immediately precedes the wrap point. To find
21393 out its x coordinate, we try moving to the right
21394 margin of the window, which will stop at the wrap
21395 point, and then reset target_x to point at the
21396 character that precedes the wrap point. This is not
21397 needed on GUI frames, because (see below) there we
21398 move from the left margin one grapheme cluster at a
21399 time, and stop when we hit the wrap point. */
21400 if (!FRAME_WINDOW_P (it
.f
) && it
.line_wrap
== WORD_WRAP
)
21402 void *it_data
= NULL
;
21405 SAVE_IT (it2
, it
, it_data
);
21406 move_it_in_display_line_to (&it
, ZV
, target_x
,
21407 MOVE_TO_POS
| MOVE_TO_X
);
21408 /* If we arrived at target_x, that _is_ the last
21409 character on the previous line. */
21410 if (it
.current_x
!= target_x
)
21411 target_x
= it
.current_x
- 1;
21412 RESTORE_IT (&it
, &it2
, it_data
);
21419 || (target_x
>= it
.last_visible_x
21420 && it
.line_wrap
!= TRUNCATE
))
21423 move_it_by_lines (&it
, 0);
21424 move_it_by_lines (&it
, 1);
21429 /* Move to the target X coordinate. */
21430 #ifdef HAVE_WINDOW_SYSTEM
21431 /* On GUI frames, as we don't know the X coordinate of the
21432 character to the left of point, moving point to the left
21433 requires walking, one grapheme cluster at a time, until we
21434 find ourself at a place immediately to the left of the
21435 character at point. */
21436 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
21438 struct text_pos new_pos
;
21439 enum move_it_result rc
= MOVE_X_REACHED
;
21441 if (it
.current_x
== 0)
21442 get_next_display_element (&it
);
21443 if (it
.what
== IT_COMPOSITION
)
21445 new_pos
.charpos
= it
.cmp_it
.charpos
;
21446 new_pos
.bytepos
= -1;
21449 new_pos
= it
.current
.pos
;
21451 while (it
.current_x
+ it
.pixel_width
<= target_x
21452 && (rc
== MOVE_X_REACHED
21453 /* Under word-wrap, move_it_in_display_line_to
21454 stops at correct coordinates, but sometimes
21455 returns MOVE_POS_MATCH_OR_ZV. */
21456 || (it
.line_wrap
== WORD_WRAP
21457 && rc
== MOVE_POS_MATCH_OR_ZV
)))
21459 int new_x
= it
.current_x
+ it
.pixel_width
;
21461 /* For composed characters, we want the position of the
21462 first character in the grapheme cluster (usually, the
21463 composition's base character), whereas it.current
21464 might give us the position of the _last_ one, e.g. if
21465 the composition is rendered in reverse due to bidi
21467 if (it
.what
== IT_COMPOSITION
)
21469 new_pos
.charpos
= it
.cmp_it
.charpos
;
21470 new_pos
.bytepos
= -1;
21473 new_pos
= it
.current
.pos
;
21474 if (new_x
== it
.current_x
)
21476 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
21477 MOVE_TO_POS
| MOVE_TO_X
);
21478 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
21481 /* The previous position we saw in the loop is the one we
21483 if (new_pos
.bytepos
== -1)
21484 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
21485 it
.current
.pos
= new_pos
;
21489 if (it
.current_x
!= target_x
)
21490 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
21492 /* When lines are truncated, the above loop will stop at the
21493 window edge. But we want to get to the end of line, even if
21494 it is beyond the window edge; automatic hscroll will then
21495 scroll the window to show point as appropriate. */
21496 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
21497 && get_next_display_element (&it
))
21499 struct text_pos new_pos
= it
.current
.pos
;
21501 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
21503 set_iterator_to_next (&it
, false);
21504 if (it
.method
== GET_FROM_BUFFER
)
21505 new_pos
= it
.current
.pos
;
21506 if (!get_next_display_element (&it
))
21510 it
.current
.pos
= new_pos
;
21513 /* If we ended up in a display string that covers point, move to
21514 buffer position to the right in the visual order. */
21517 while (IT_CHARPOS (it
) == PT
)
21519 set_iterator_to_next (&it
, false);
21520 if (!get_next_display_element (&it
))
21525 /* Move point to that position. */
21526 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
21529 return make_number (PT
);
21531 #undef ROW_GLYPH_NEWLINE_P
21534 DEFUN ("bidi-resolved-levels", Fbidi_resolved_levels
,
21535 Sbidi_resolved_levels
, 0, 1, 0,
21536 doc
: /* Return the resolved bidirectional levels of characters at VPOS.
21538 The resolved levels are produced by the Emacs bidi reordering engine
21539 that implements the UBA, the Unicode Bidirectional Algorithm. Please
21540 read the Unicode Standard Annex 9 (UAX#9) for background information
21541 about these levels.
21543 VPOS is the zero-based number of the current window's screen line
21544 for which to produce the resolved levels. If VPOS is nil or omitted,
21545 it defaults to the screen line of point. If the window displays a
21546 header line, VPOS of zero will report on the header line, and first
21547 line of text in the window will have VPOS of 1.
21549 Value is an array of resolved levels, indexed by glyph number.
21550 Glyphs are numbered from zero starting from the beginning of the
21551 screen line, i.e. the left edge of the window for left-to-right lines
21552 and from the right edge for right-to-left lines. The resolved levels
21553 are produced only for the window's text area; text in display margins
21556 If the selected window's display is not up-to-date, or if the specified
21557 screen line does not display text, this function returns nil. It is
21558 highly recommended to bind this function to some simple key, like F8,
21559 in order to avoid these problems.
21561 This function exists mainly for testing the correctness of the
21562 Emacs UBA implementation, in particular with the test suite. */)
21565 struct window
*w
= XWINDOW (selected_window
);
21566 struct buffer
*b
= XBUFFER (w
->contents
);
21568 struct glyph_row
*row
;
21572 int d1
, d2
, d3
, d4
, d5
;
21574 pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &nrow
);
21578 CHECK_NUMBER_COERCE_MARKER (vpos
);
21579 nrow
= XINT (vpos
);
21582 /* We require up-to-date glyph matrix for this window. */
21583 if (w
->window_end_valid
21584 && !windows_or_buffers_changed
21586 && !b
->clip_changed
21587 && !b
->prevent_redisplay_optimizations_p
21588 && !window_outdated (w
)
21590 && nrow
< w
->current_matrix
->nrows
21591 && (row
= MATRIX_ROW (w
->current_matrix
, nrow
))->enabled_p
21592 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
21594 struct glyph
*g
, *e
, *g1
;
21596 Lisp_Object levels
;
21598 if (!row
->reversed_p
) /* Left-to-right glyph row. */
21600 g
= g1
= row
->glyphs
[TEXT_AREA
];
21601 e
= g
+ row
->used
[TEXT_AREA
];
21603 /* Skip over glyphs at the start of the row that was
21604 generated by redisplay for its own needs. */
21606 && NILP (g
->object
)
21611 /* Count the "interesting" glyphs in this row. */
21612 for (nglyphs
= 0; g
< e
&& !NILP (g
->object
); g
++)
21615 /* Create and fill the array. */
21616 levels
= make_uninit_vector (nglyphs
);
21617 for (i
= 0; g1
< g
; i
++, g1
++)
21618 ASET (levels
, i
, make_number (g1
->resolved_level
));
21620 else /* Right-to-left glyph row. */
21622 g
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
21623 e
= row
->glyphs
[TEXT_AREA
] - 1;
21625 && NILP (g
->object
)
21629 for (nglyphs
= 0; g
> e
&& !NILP (g
->object
); g
--)
21631 levels
= make_uninit_vector (nglyphs
);
21632 for (i
= 0; g1
> g
; i
++, g1
--)
21633 ASET (levels
, i
, make_number (g1
->resolved_level
));
21643 /***********************************************************************
21645 ***********************************************************************/
21647 /* Redisplay the menu bar in the frame for window W.
21649 The menu bar of X frames that don't have X toolkit support is
21650 displayed in a special window W->frame->menu_bar_window.
21652 The menu bar of terminal frames is treated specially as far as
21653 glyph matrices are concerned. Menu bar lines are not part of
21654 windows, so the update is done directly on the frame matrix rows
21655 for the menu bar. */
21658 display_menu_bar (struct window
*w
)
21660 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21665 /* Don't do all this for graphical frames. */
21667 if (FRAME_W32_P (f
))
21670 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
21676 if (FRAME_NS_P (f
))
21678 #endif /* HAVE_NS */
21680 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
21681 eassert (!FRAME_WINDOW_P (f
));
21682 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
21683 it
.first_visible_x
= 0;
21684 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
21685 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
21686 if (FRAME_WINDOW_P (f
))
21688 /* Menu bar lines are displayed in the desired matrix of the
21689 dummy window menu_bar_window. */
21690 struct window
*menu_w
;
21691 menu_w
= XWINDOW (f
->menu_bar_window
);
21692 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
21694 it
.first_visible_x
= 0;
21695 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
21698 #endif /* not USE_X_TOOLKIT and not USE_GTK */
21700 /* This is a TTY frame, i.e. character hpos/vpos are used as
21702 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
21704 it
.first_visible_x
= 0;
21705 it
.last_visible_x
= FRAME_COLS (f
);
21708 /* FIXME: This should be controlled by a user option. See the
21709 comments in redisplay_tool_bar and display_mode_line about
21711 it
.paragraph_embedding
= L2R
;
21713 /* Clear all rows of the menu bar. */
21714 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
21716 struct glyph_row
*row
= it
.glyph_row
+ i
;
21717 clear_glyph_row (row
);
21718 row
->enabled_p
= true;
21719 row
->full_width_p
= true;
21720 row
->reversed_p
= false;
21723 /* Display all items of the menu bar. */
21724 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
21725 for (i
= 0; i
< ASIZE (items
); i
+= 4)
21727 Lisp_Object string
;
21729 /* Stop at nil string. */
21730 string
= AREF (items
, i
+ 1);
21734 /* Remember where item was displayed. */
21735 ASET (items
, i
+ 3, make_number (it
.hpos
));
21737 /* Display the item, pad with one space. */
21738 if (it
.current_x
< it
.last_visible_x
)
21739 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
21740 SCHARS (string
) + 1, 0, 0, -1);
21743 /* Fill out the line with spaces. */
21744 if (it
.current_x
< it
.last_visible_x
)
21745 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
21747 /* Compute the total height of the lines. */
21748 compute_line_metrics (&it
);
21751 /* Deep copy of a glyph row, including the glyphs. */
21753 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
21755 struct glyph
*pointers
[1 + LAST_AREA
];
21756 int to_used
= to
->used
[TEXT_AREA
];
21758 /* Save glyph pointers of TO. */
21759 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
21761 /* Do a structure assignment. */
21764 /* Restore original glyph pointers of TO. */
21765 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
21767 /* Copy the glyphs. */
21768 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
21769 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
21771 /* If we filled only part of the TO row, fill the rest with
21772 space_glyph (which will display as empty space). */
21773 if (to_used
> from
->used
[TEXT_AREA
])
21774 fill_up_frame_row_with_spaces (to
, to_used
);
21777 /* Display one menu item on a TTY, by overwriting the glyphs in the
21778 frame F's desired glyph matrix with glyphs produced from the menu
21779 item text. Called from term.c to display TTY drop-down menus one
21782 ITEM_TEXT is the menu item text as a C string.
21784 FACE_ID is the face ID to be used for this menu item. FACE_ID
21785 could specify one of 3 faces: a face for an enabled item, a face
21786 for a disabled item, or a face for a selected item.
21788 X and Y are coordinates of the first glyph in the frame's desired
21789 matrix to be overwritten by the menu item. Since this is a TTY, Y
21790 is the zero-based number of the glyph row and X is the zero-based
21791 glyph number in the row, starting from left, where to start
21792 displaying the item.
21794 SUBMENU means this menu item drops down a submenu, which
21795 should be indicated by displaying a proper visual cue after the
21799 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
21800 int x
, int y
, bool submenu
)
21803 struct frame
*f
= SELECTED_FRAME ();
21804 struct window
*w
= XWINDOW (f
->selected_window
);
21805 struct glyph_row
*row
;
21806 size_t item_len
= strlen (item_text
);
21808 eassert (FRAME_TERMCAP_P (f
));
21810 /* Don't write beyond the matrix's last row. This can happen for
21811 TTY screens that are not high enough to show the entire menu.
21812 (This is actually a bit of defensive programming, as
21813 tty_menu_display already limits the number of menu items to one
21814 less than the number of screen lines.) */
21815 if (y
>= f
->desired_matrix
->nrows
)
21818 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
21819 it
.first_visible_x
= 0;
21820 it
.last_visible_x
= FRAME_COLS (f
) - 1;
21821 row
= it
.glyph_row
;
21822 /* Start with the row contents from the current matrix. */
21823 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
21824 bool saved_width
= row
->full_width_p
;
21825 row
->full_width_p
= true;
21826 bool saved_reversed
= row
->reversed_p
;
21827 row
->reversed_p
= false;
21828 row
->enabled_p
= true;
21830 /* Arrange for the menu item glyphs to start at (X,Y) and have the
21832 eassert (x
< f
->desired_matrix
->matrix_w
);
21833 it
.current_x
= it
.hpos
= x
;
21834 it
.current_y
= it
.vpos
= y
;
21835 int saved_used
= row
->used
[TEXT_AREA
];
21836 bool saved_truncated
= row
->truncated_on_right_p
;
21837 row
->used
[TEXT_AREA
] = x
;
21838 it
.face_id
= face_id
;
21839 it
.line_wrap
= TRUNCATE
;
21841 /* FIXME: This should be controlled by a user option. See the
21842 comments in redisplay_tool_bar and display_mode_line about this.
21843 Also, if paragraph_embedding could ever be R2L, changes will be
21844 needed to avoid shifting to the right the row characters in
21845 term.c:append_glyph. */
21846 it
.paragraph_embedding
= L2R
;
21848 /* Pad with a space on the left. */
21849 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
21851 /* Display the menu item, pad with spaces to WIDTH. */
21854 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21855 item_len
, 0, FRAME_COLS (f
) - 1, -1);
21857 /* Indicate with " >" that there's a submenu. */
21858 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
21859 FRAME_COLS (f
) - 1, -1);
21862 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21863 width
, 0, FRAME_COLS (f
) - 1, -1);
21865 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
21866 row
->truncated_on_right_p
= saved_truncated
;
21867 row
->hash
= row_hash (row
);
21868 row
->full_width_p
= saved_width
;
21869 row
->reversed_p
= saved_reversed
;
21872 /***********************************************************************
21874 ***********************************************************************/
21876 /* Redisplay mode lines in the window tree whose root is WINDOW.
21877 If FORCE, redisplay mode lines unconditionally.
21878 Otherwise, redisplay only mode lines that are garbaged. Value is
21879 the number of windows whose mode lines were redisplayed. */
21882 redisplay_mode_lines (Lisp_Object window
, bool force
)
21886 while (!NILP (window
))
21888 struct window
*w
= XWINDOW (window
);
21890 if (WINDOWP (w
->contents
))
21891 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
21893 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
21894 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
21896 struct text_pos lpoint
;
21897 struct buffer
*old
= current_buffer
;
21899 /* Set the window's buffer for the mode line display. */
21900 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
21901 set_buffer_internal_1 (XBUFFER (w
->contents
));
21903 /* Point refers normally to the selected window. For any
21904 other window, set up appropriate value. */
21905 if (!EQ (window
, selected_window
))
21907 struct text_pos pt
;
21909 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
21910 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
21913 /* Display mode lines. */
21914 clear_glyph_matrix (w
->desired_matrix
);
21915 if (display_mode_lines (w
))
21918 /* Restore old settings. */
21919 set_buffer_internal_1 (old
);
21920 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
21930 /* Display the mode and/or header line of window W. Value is the
21931 sum number of mode lines and header lines displayed. */
21934 display_mode_lines (struct window
*w
)
21936 Lisp_Object old_selected_window
= selected_window
;
21937 Lisp_Object old_selected_frame
= selected_frame
;
21938 Lisp_Object new_frame
= w
->frame
;
21939 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
21942 selected_frame
= new_frame
;
21943 /* FIXME: If we were to allow the mode-line's computation changing the buffer
21944 or window's point, then we'd need select_window_1 here as well. */
21945 XSETWINDOW (selected_window
, w
);
21946 XFRAME (new_frame
)->selected_window
= selected_window
;
21948 /* These will be set while the mode line specs are processed. */
21949 line_number_displayed
= false;
21950 w
->column_number_displayed
= -1;
21952 if (WINDOW_WANTS_MODELINE_P (w
))
21954 struct window
*sel_w
= XWINDOW (old_selected_window
);
21956 /* Select mode line face based on the real selected window. */
21957 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
21958 BVAR (current_buffer
, mode_line_format
));
21962 if (WINDOW_WANTS_HEADER_LINE_P (w
))
21964 display_mode_line (w
, HEADER_LINE_FACE_ID
,
21965 BVAR (current_buffer
, header_line_format
));
21969 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
21970 selected_frame
= old_selected_frame
;
21971 selected_window
= old_selected_window
;
21973 w
->must_be_updated_p
= true;
21978 /* Display mode or header line of window W. FACE_ID specifies which
21979 line to display; it is either MODE_LINE_FACE_ID or
21980 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
21981 display. Value is the pixel height of the mode/header line
21985 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
21989 ptrdiff_t count
= SPECPDL_INDEX ();
21991 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21992 /* Don't extend on a previously drawn mode-line.
21993 This may happen if called from pos_visible_p. */
21994 it
.glyph_row
->enabled_p
= false;
21995 prepare_desired_row (w
, it
.glyph_row
, true);
21997 it
.glyph_row
->mode_line_p
= true;
21999 /* FIXME: This should be controlled by a user option. But
22000 supporting such an option is not trivial, since the mode line is
22001 made up of many separate strings. */
22002 it
.paragraph_embedding
= L2R
;
22004 record_unwind_protect (unwind_format_mode_line
,
22005 format_mode_line_unwind_data (NULL
, NULL
,
22008 mode_line_target
= MODE_LINE_DISPLAY
;
22010 /* Temporarily make frame's keyboard the current kboard so that
22011 kboard-local variables in the mode_line_format will get the right
22013 push_kboard (FRAME_KBOARD (it
.f
));
22014 record_unwind_save_match_data ();
22015 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
22018 unbind_to (count
, Qnil
);
22020 /* Fill up with spaces. */
22021 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
22023 compute_line_metrics (&it
);
22024 it
.glyph_row
->full_width_p
= true;
22025 it
.glyph_row
->continued_p
= false;
22026 it
.glyph_row
->truncated_on_left_p
= false;
22027 it
.glyph_row
->truncated_on_right_p
= false;
22029 /* Make a 3D mode-line have a shadow at its right end. */
22030 face
= FACE_FROM_ID (it
.f
, face_id
);
22031 extend_face_to_end_of_line (&it
);
22032 if (face
->box
!= FACE_NO_BOX
)
22034 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
22035 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
22036 last
->right_box_line_p
= true;
22039 return it
.glyph_row
->height
;
22042 /* Move element ELT in LIST to the front of LIST.
22043 Return the updated list. */
22046 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
22048 register Lisp_Object tail
, prev
;
22049 register Lisp_Object tem
;
22053 while (CONSP (tail
))
22059 /* Splice out the link TAIL. */
22061 list
= XCDR (tail
);
22063 Fsetcdr (prev
, XCDR (tail
));
22065 /* Now make it the first. */
22066 Fsetcdr (tail
, list
);
22071 tail
= XCDR (tail
);
22075 /* Not found--return unchanged LIST. */
22079 /* Contribute ELT to the mode line for window IT->w. How it
22080 translates into text depends on its data type.
22082 IT describes the display environment in which we display, as usual.
22084 DEPTH is the depth in recursion. It is used to prevent
22085 infinite recursion here.
22087 FIELD_WIDTH is the number of characters the display of ELT should
22088 occupy in the mode line, and PRECISION is the maximum number of
22089 characters to display from ELT's representation. See
22090 display_string for details.
22092 Returns the hpos of the end of the text generated by ELT.
22094 PROPS is a property list to add to any string we encounter.
22096 If RISKY, remove (disregard) any properties in any string
22097 we encounter, and ignore :eval and :propertize.
22099 The global variable `mode_line_target' determines whether the
22100 output is passed to `store_mode_line_noprop',
22101 `store_mode_line_string', or `display_string'. */
22104 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
22105 Lisp_Object elt
, Lisp_Object props
, bool risky
)
22107 int n
= 0, field
, prec
;
22108 bool literal
= false;
22112 elt
= build_string ("*too-deep*");
22116 switch (XTYPE (elt
))
22120 /* A string: output it and check for %-constructs within it. */
22122 ptrdiff_t offset
= 0;
22124 if (SCHARS (elt
) > 0
22125 && (!NILP (props
) || risky
))
22127 Lisp_Object oprops
, aelt
;
22128 oprops
= Ftext_properties_at (make_number (0), elt
);
22130 /* If the starting string's properties are not what
22131 we want, translate the string. Also, if the string
22132 is risky, do that anyway. */
22134 if (NILP (Fequal (props
, oprops
)) || risky
)
22136 /* If the starting string has properties,
22137 merge the specified ones onto the existing ones. */
22138 if (! NILP (oprops
) && !risky
)
22142 oprops
= Fcopy_sequence (oprops
);
22144 while (CONSP (tem
))
22146 oprops
= Fplist_put (oprops
, XCAR (tem
),
22147 XCAR (XCDR (tem
)));
22148 tem
= XCDR (XCDR (tem
));
22153 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
22154 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
22156 /* AELT is what we want. Move it to the front
22157 without consing. */
22159 mode_line_proptrans_alist
22160 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
22166 /* If AELT has the wrong props, it is useless.
22167 so get rid of it. */
22169 mode_line_proptrans_alist
22170 = Fdelq (aelt
, mode_line_proptrans_alist
);
22172 elt
= Fcopy_sequence (elt
);
22173 Fset_text_properties (make_number (0), Flength (elt
),
22175 /* Add this item to mode_line_proptrans_alist. */
22176 mode_line_proptrans_alist
22177 = Fcons (Fcons (elt
, props
),
22178 mode_line_proptrans_alist
);
22179 /* Truncate mode_line_proptrans_alist
22180 to at most 50 elements. */
22181 tem
= Fnthcdr (make_number (50),
22182 mode_line_proptrans_alist
);
22184 XSETCDR (tem
, Qnil
);
22193 prec
= precision
- n
;
22194 switch (mode_line_target
)
22196 case MODE_LINE_NOPROP
:
22197 case MODE_LINE_TITLE
:
22198 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
22200 case MODE_LINE_STRING
:
22201 n
+= store_mode_line_string (NULL
, elt
, true, 0, prec
, Qnil
);
22203 case MODE_LINE_DISPLAY
:
22204 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
22205 0, prec
, 0, STRING_MULTIBYTE (elt
));
22212 /* Handle the non-literal case. */
22214 while ((precision
<= 0 || n
< precision
)
22215 && SREF (elt
, offset
) != 0
22216 && (mode_line_target
!= MODE_LINE_DISPLAY
22217 || it
->current_x
< it
->last_visible_x
))
22219 ptrdiff_t last_offset
= offset
;
22221 /* Advance to end of string or next format specifier. */
22222 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
22225 if (offset
- 1 != last_offset
)
22227 ptrdiff_t nchars
, nbytes
;
22229 /* Output to end of string or up to '%'. Field width
22230 is length of string. Don't output more than
22231 PRECISION allows us. */
22234 prec
= c_string_width (SDATA (elt
) + last_offset
,
22235 offset
- last_offset
, precision
- n
,
22238 switch (mode_line_target
)
22240 case MODE_LINE_NOPROP
:
22241 case MODE_LINE_TITLE
:
22242 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
22244 case MODE_LINE_STRING
:
22246 ptrdiff_t bytepos
= last_offset
;
22247 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22248 ptrdiff_t endpos
= (precision
<= 0
22249 ? string_byte_to_char (elt
, offset
)
22250 : charpos
+ nchars
);
22251 Lisp_Object mode_string
22252 = Fsubstring (elt
, make_number (charpos
),
22253 make_number (endpos
));
22254 n
+= store_mode_line_string (NULL
, mode_string
, false,
22258 case MODE_LINE_DISPLAY
:
22260 ptrdiff_t bytepos
= last_offset
;
22261 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22263 if (precision
<= 0)
22264 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
22265 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
22267 STRING_MULTIBYTE (elt
));
22272 else /* c == '%' */
22274 ptrdiff_t percent_position
= offset
;
22276 /* Get the specified minimum width. Zero means
22279 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
22280 field
= field
* 10 + c
- '0';
22282 /* Don't pad beyond the total padding allowed. */
22283 if (field_width
- n
> 0 && field
> field_width
- n
)
22284 field
= field_width
- n
;
22286 /* Note that either PRECISION <= 0 or N < PRECISION. */
22287 prec
= precision
- n
;
22290 n
+= display_mode_element (it
, depth
, field
, prec
,
22291 Vglobal_mode_string
, props
,
22296 ptrdiff_t bytepos
, charpos
;
22298 Lisp_Object string
;
22300 bytepos
= percent_position
;
22301 charpos
= (STRING_MULTIBYTE (elt
)
22302 ? string_byte_to_char (elt
, bytepos
)
22304 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
22305 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
22307 switch (mode_line_target
)
22309 case MODE_LINE_NOPROP
:
22310 case MODE_LINE_TITLE
:
22311 n
+= store_mode_line_noprop (spec
, field
, prec
);
22313 case MODE_LINE_STRING
:
22315 Lisp_Object tem
= build_string (spec
);
22316 props
= Ftext_properties_at (make_number (charpos
), elt
);
22317 /* Should only keep face property in props */
22318 n
+= store_mode_line_string (NULL
, tem
, false,
22319 field
, prec
, props
);
22322 case MODE_LINE_DISPLAY
:
22324 int nglyphs_before
, nwritten
;
22326 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
22327 nwritten
= display_string (spec
, string
, elt
,
22332 /* Assign to the glyphs written above the
22333 string where the `%x' came from, position
22337 struct glyph
*glyph
22338 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
22342 for (i
= 0; i
< nwritten
; ++i
)
22344 glyph
[i
].object
= elt
;
22345 glyph
[i
].charpos
= charpos
;
22362 /* A symbol: process the value of the symbol recursively
22363 as if it appeared here directly. Avoid error if symbol void.
22364 Special case: if value of symbol is a string, output the string
22367 register Lisp_Object tem
;
22369 /* If the variable is not marked as risky to set
22370 then its contents are risky to use. */
22371 if (NILP (Fget (elt
, Qrisky_local_variable
)))
22374 tem
= Fboundp (elt
);
22377 tem
= Fsymbol_value (elt
);
22378 /* If value is a string, output that string literally:
22379 don't check for % within it. */
22383 if (!EQ (tem
, elt
))
22385 /* Give up right away for nil or t. */
22395 register Lisp_Object car
, tem
;
22397 /* A cons cell: five distinct cases.
22398 If first element is :eval or :propertize, do something special.
22399 If first element is a string or a cons, process all the elements
22400 and effectively concatenate them.
22401 If first element is a negative number, truncate displaying cdr to
22402 at most that many characters. If positive, pad (with spaces)
22403 to at least that many characters.
22404 If first element is a symbol, process the cadr or caddr recursively
22405 according to whether the symbol's value is non-nil or nil. */
22407 if (EQ (car
, QCeval
))
22409 /* An element of the form (:eval FORM) means evaluate FORM
22410 and use the result as mode line elements. */
22415 if (CONSP (XCDR (elt
)))
22418 spec
= safe__eval (true, XCAR (XCDR (elt
)));
22419 n
+= display_mode_element (it
, depth
, field_width
- n
,
22420 precision
- n
, spec
, props
,
22424 else if (EQ (car
, QCpropertize
))
22426 /* An element of the form (:propertize ELT PROPS...)
22427 means display ELT but applying properties PROPS. */
22432 if (CONSP (XCDR (elt
)))
22433 n
+= display_mode_element (it
, depth
, field_width
- n
,
22434 precision
- n
, XCAR (XCDR (elt
)),
22435 XCDR (XCDR (elt
)), risky
);
22437 else if (SYMBOLP (car
))
22439 tem
= Fboundp (car
);
22443 /* elt is now the cdr, and we know it is a cons cell.
22444 Use its car if CAR has a non-nil value. */
22447 tem
= Fsymbol_value (car
);
22454 /* Symbol's value is nil (or symbol is unbound)
22455 Get the cddr of the original list
22456 and if possible find the caddr and use that. */
22460 else if (!CONSP (elt
))
22465 else if (INTEGERP (car
))
22467 register int lim
= XINT (car
);
22471 /* Negative int means reduce maximum width. */
22472 if (precision
<= 0)
22475 precision
= min (precision
, -lim
);
22479 /* Padding specified. Don't let it be more than
22480 current maximum. */
22482 lim
= min (precision
, lim
);
22484 /* If that's more padding than already wanted, queue it.
22485 But don't reduce padding already specified even if
22486 that is beyond the current truncation point. */
22487 field_width
= max (lim
, field_width
);
22491 else if (STRINGP (car
) || CONSP (car
))
22493 Lisp_Object halftail
= elt
;
22497 && (precision
<= 0 || n
< precision
))
22499 n
+= display_mode_element (it
, depth
,
22500 /* Do padding only after the last
22501 element in the list. */
22502 (! CONSP (XCDR (elt
))
22505 precision
- n
, XCAR (elt
),
22509 if ((len
& 1) == 0)
22510 halftail
= XCDR (halftail
);
22511 /* Check for cycle. */
22512 if (EQ (halftail
, elt
))
22521 elt
= build_string ("*invalid*");
22525 /* Pad to FIELD_WIDTH. */
22526 if (field_width
> 0 && n
< field_width
)
22528 switch (mode_line_target
)
22530 case MODE_LINE_NOPROP
:
22531 case MODE_LINE_TITLE
:
22532 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
22534 case MODE_LINE_STRING
:
22535 n
+= store_mode_line_string ("", Qnil
, false, field_width
- n
, 0,
22538 case MODE_LINE_DISPLAY
:
22539 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
22548 /* Store a mode-line string element in mode_line_string_list.
22550 If STRING is non-null, display that C string. Otherwise, the Lisp
22551 string LISP_STRING is displayed.
22553 FIELD_WIDTH is the minimum number of output glyphs to produce.
22554 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22555 with spaces. FIELD_WIDTH <= 0 means don't pad.
22557 PRECISION is the maximum number of characters to output from
22558 STRING. PRECISION <= 0 means don't truncate the string.
22560 If COPY_STRING, make a copy of LISP_STRING before adding
22561 properties to the string.
22563 PROPS are the properties to add to the string.
22564 The mode_line_string_face face property is always added to the string.
22568 store_mode_line_string (const char *string
, Lisp_Object lisp_string
,
22570 int field_width
, int precision
, Lisp_Object props
)
22575 if (string
!= NULL
)
22577 len
= strlen (string
);
22578 if (precision
> 0 && len
> precision
)
22580 lisp_string
= make_string (string
, len
);
22582 props
= mode_line_string_face_prop
;
22583 else if (!NILP (mode_line_string_face
))
22585 Lisp_Object face
= Fplist_get (props
, Qface
);
22586 props
= Fcopy_sequence (props
);
22588 face
= mode_line_string_face
;
22590 face
= list2 (face
, mode_line_string_face
);
22591 props
= Fplist_put (props
, Qface
, face
);
22593 Fadd_text_properties (make_number (0), make_number (len
),
22594 props
, lisp_string
);
22598 len
= XFASTINT (Flength (lisp_string
));
22599 if (precision
> 0 && len
> precision
)
22602 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
22605 if (!NILP (mode_line_string_face
))
22609 props
= Ftext_properties_at (make_number (0), lisp_string
);
22610 face
= Fplist_get (props
, Qface
);
22612 face
= mode_line_string_face
;
22614 face
= list2 (face
, mode_line_string_face
);
22615 props
= list2 (Qface
, face
);
22617 lisp_string
= Fcopy_sequence (lisp_string
);
22620 Fadd_text_properties (make_number (0), make_number (len
),
22621 props
, lisp_string
);
22626 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22630 if (field_width
> len
)
22632 field_width
-= len
;
22633 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
22635 Fadd_text_properties (make_number (0), make_number (field_width
),
22636 props
, lisp_string
);
22637 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22645 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
22647 doc
: /* Format a string out of a mode line format specification.
22648 First arg FORMAT specifies the mode line format (see `mode-line-format'
22649 for details) to use.
22651 By default, the format is evaluated for the currently selected window.
22653 Optional second arg FACE specifies the face property to put on all
22654 characters for which no face is specified. The value nil means the
22655 default face. The value t means whatever face the window's mode line
22656 currently uses (either `mode-line' or `mode-line-inactive',
22657 depending on whether the window is the selected window or not).
22658 An integer value means the value string has no text
22661 Optional third and fourth args WINDOW and BUFFER specify the window
22662 and buffer to use as the context for the formatting (defaults
22663 are the selected window and the WINDOW's buffer). */)
22664 (Lisp_Object format
, Lisp_Object face
,
22665 Lisp_Object window
, Lisp_Object buffer
)
22670 struct buffer
*old_buffer
= NULL
;
22672 bool no_props
= INTEGERP (face
);
22673 ptrdiff_t count
= SPECPDL_INDEX ();
22675 int string_start
= 0;
22677 w
= decode_any_window (window
);
22678 XSETWINDOW (window
, w
);
22681 buffer
= w
->contents
;
22682 CHECK_BUFFER (buffer
);
22684 /* Make formatting the modeline a non-op when noninteractive, otherwise
22685 there will be problems later caused by a partially initialized frame. */
22686 if (NILP (format
) || noninteractive
)
22687 return empty_unibyte_string
;
22692 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
22693 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
22694 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
22695 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
22696 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
22697 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
22698 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
22701 old_buffer
= current_buffer
;
22703 /* Save things including mode_line_proptrans_alist,
22704 and set that to nil so that we don't alter the outer value. */
22705 record_unwind_protect (unwind_format_mode_line
,
22706 format_mode_line_unwind_data
22707 (XFRAME (WINDOW_FRAME (w
)),
22708 old_buffer
, selected_window
, true));
22709 mode_line_proptrans_alist
= Qnil
;
22711 Fselect_window (window
, Qt
);
22712 set_buffer_internal_1 (XBUFFER (buffer
));
22714 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
22718 mode_line_target
= MODE_LINE_NOPROP
;
22719 mode_line_string_face_prop
= Qnil
;
22720 mode_line_string_list
= Qnil
;
22721 string_start
= MODE_LINE_NOPROP_LEN (0);
22725 mode_line_target
= MODE_LINE_STRING
;
22726 mode_line_string_list
= Qnil
;
22727 mode_line_string_face
= face
;
22728 mode_line_string_face_prop
22729 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
22732 push_kboard (FRAME_KBOARD (it
.f
));
22733 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
22738 len
= MODE_LINE_NOPROP_LEN (string_start
);
22739 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
22743 mode_line_string_list
= Fnreverse (mode_line_string_list
);
22744 str
= Fmapconcat (Qidentity
, mode_line_string_list
,
22745 empty_unibyte_string
);
22748 unbind_to (count
, Qnil
);
22752 /* Write a null-terminated, right justified decimal representation of
22753 the positive integer D to BUF using a minimal field width WIDTH. */
22756 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
22758 register char *p
= buf
;
22766 *p
++ = d
% 10 + '0';
22771 for (width
-= (int) (p
- buf
); width
> 0; --width
)
22782 /* Write a null-terminated, right justified decimal and "human
22783 readable" representation of the nonnegative integer D to BUF using
22784 a minimal field width WIDTH. D should be smaller than 999.5e24. */
22786 static const char power_letter
[] =
22800 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
22802 /* We aim to represent the nonnegative integer D as
22803 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
22804 ptrdiff_t quotient
= d
;
22806 /* -1 means: do not use TENTHS. */
22810 /* Length of QUOTIENT.TENTHS as a string. */
22816 if (quotient
>= 1000)
22818 /* Scale to the appropriate EXPONENT. */
22821 remainder
= quotient
% 1000;
22825 while (quotient
>= 1000);
22827 /* Round to nearest and decide whether to use TENTHS or not. */
22830 tenths
= remainder
/ 100;
22831 if (remainder
% 100 >= 50)
22838 if (quotient
== 10)
22846 if (remainder
>= 500)
22848 if (quotient
< 999)
22859 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
22860 if (tenths
== -1 && quotient
<= 99)
22867 p
= psuffix
= buf
+ max (width
, length
);
22869 /* Print EXPONENT. */
22870 *psuffix
++ = power_letter
[exponent
];
22873 /* Print TENTHS. */
22876 *--p
= '0' + tenths
;
22880 /* Print QUOTIENT. */
22883 int digit
= quotient
% 10;
22884 *--p
= '0' + digit
;
22886 while ((quotient
/= 10) != 0);
22888 /* Print leading spaces. */
22893 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
22894 If EOL_FLAG, set also a mnemonic character for end-of-line
22895 type of CODING_SYSTEM. Return updated pointer into BUF. */
22897 static unsigned char invalid_eol_type
[] = "(*invalid*)";
22900 decode_mode_spec_coding (Lisp_Object coding_system
, char *buf
, bool eol_flag
)
22903 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
22904 const unsigned char *eol_str
;
22906 /* The EOL conversion we are using. */
22907 Lisp_Object eoltype
;
22909 val
= CODING_SYSTEM_SPEC (coding_system
);
22912 if (!VECTORP (val
)) /* Not yet decided. */
22914 *buf
++ = multibyte
? '-' : ' ';
22916 eoltype
= eol_mnemonic_undecided
;
22917 /* Don't mention EOL conversion if it isn't decided. */
22922 Lisp_Object eolvalue
;
22924 attrs
= AREF (val
, 0);
22925 eolvalue
= AREF (val
, 2);
22928 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
22933 /* The EOL conversion that is normal on this system. */
22935 if (NILP (eolvalue
)) /* Not yet decided. */
22936 eoltype
= eol_mnemonic_undecided
;
22937 else if (VECTORP (eolvalue
)) /* Not yet decided. */
22938 eoltype
= eol_mnemonic_undecided
;
22939 else /* eolvalue is Qunix, Qdos, or Qmac. */
22940 eoltype
= (EQ (eolvalue
, Qunix
)
22941 ? eol_mnemonic_unix
22942 : EQ (eolvalue
, Qdos
)
22943 ? eol_mnemonic_dos
: eol_mnemonic_mac
);
22949 /* Mention the EOL conversion if it is not the usual one. */
22950 if (STRINGP (eoltype
))
22952 eol_str
= SDATA (eoltype
);
22953 eol_str_len
= SBYTES (eoltype
);
22955 else if (CHARACTERP (eoltype
))
22957 int c
= XFASTINT (eoltype
);
22958 return buf
+ CHAR_STRING (c
, (unsigned char *) buf
);
22962 eol_str
= invalid_eol_type
;
22963 eol_str_len
= sizeof (invalid_eol_type
) - 1;
22965 memcpy (buf
, eol_str
, eol_str_len
);
22966 buf
+= eol_str_len
;
22972 /* Return a string for the output of a mode line %-spec for window W,
22973 generated by character C. FIELD_WIDTH > 0 means pad the string
22974 returned with spaces to that value. Return a Lisp string in
22975 *STRING if the resulting string is taken from that Lisp string.
22977 Note we operate on the current buffer for most purposes. */
22979 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
22981 static const char *
22982 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
22983 Lisp_Object
*string
)
22986 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22987 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
22988 /* We are going to use f->decode_mode_spec_buffer as the buffer to
22989 produce strings from numerical values, so limit preposterously
22990 large values of FIELD_WIDTH to avoid overrunning the buffer's
22991 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
22992 bytes plus the terminating null. */
22993 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
22994 struct buffer
*b
= current_buffer
;
23002 if (!NILP (BVAR (b
, read_only
)))
23004 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23009 /* This differs from %* only for a modified read-only buffer. */
23010 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23012 if (!NILP (BVAR (b
, read_only
)))
23017 /* This differs from %* in ignoring read-only-ness. */
23018 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23030 if (command_loop_level
> 5)
23032 p
= decode_mode_spec_buf
;
23033 for (i
= 0; i
< command_loop_level
; i
++)
23036 return decode_mode_spec_buf
;
23044 if (command_loop_level
> 5)
23046 p
= decode_mode_spec_buf
;
23047 for (i
= 0; i
< command_loop_level
; i
++)
23050 return decode_mode_spec_buf
;
23057 /* Let lots_of_dashes be a string of infinite length. */
23058 if (mode_line_target
== MODE_LINE_NOPROP
23059 || mode_line_target
== MODE_LINE_STRING
)
23061 if (field_width
<= 0
23062 || field_width
> sizeof (lots_of_dashes
))
23064 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
23065 decode_mode_spec_buf
[i
] = '-';
23066 decode_mode_spec_buf
[i
] = '\0';
23067 return decode_mode_spec_buf
;
23070 return lots_of_dashes
;
23074 obj
= BVAR (b
, name
);
23078 /* %c and %l are ignored in `frame-title-format'.
23079 (In redisplay_internal, the frame title is drawn _before_ the
23080 windows are updated, so the stuff which depends on actual
23081 window contents (such as %l) may fail to render properly, or
23082 even crash emacs.) */
23083 if (mode_line_target
== MODE_LINE_TITLE
)
23087 ptrdiff_t col
= current_column ();
23088 w
->column_number_displayed
= col
;
23089 pint2str (decode_mode_spec_buf
, width
, col
);
23090 return decode_mode_spec_buf
;
23094 #if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
23096 if (NILP (Vmemory_full
))
23099 return "!MEM FULL! ";
23106 /* %F displays the frame name. */
23107 if (!NILP (f
->title
))
23108 return SSDATA (f
->title
);
23109 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
23110 return SSDATA (f
->name
);
23114 obj
= BVAR (b
, filename
);
23119 ptrdiff_t size
= ZV
- BEGV
;
23120 pint2str (decode_mode_spec_buf
, width
, size
);
23121 return decode_mode_spec_buf
;
23126 ptrdiff_t size
= ZV
- BEGV
;
23127 pint2hrstr (decode_mode_spec_buf
, width
, size
);
23128 return decode_mode_spec_buf
;
23133 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
23134 ptrdiff_t topline
, nlines
, height
;
23137 /* %c and %l are ignored in `frame-title-format'. */
23138 if (mode_line_target
== MODE_LINE_TITLE
)
23141 startpos
= marker_position (w
->start
);
23142 startpos_byte
= marker_byte_position (w
->start
);
23143 height
= WINDOW_TOTAL_LINES (w
);
23145 /* If we decided that this buffer isn't suitable for line numbers,
23146 don't forget that too fast. */
23147 if (w
->base_line_pos
== -1)
23150 /* If the buffer is very big, don't waste time. */
23151 if (INTEGERP (Vline_number_display_limit
)
23152 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
23154 w
->base_line_pos
= 0;
23155 w
->base_line_number
= 0;
23159 if (w
->base_line_number
> 0
23160 && w
->base_line_pos
> 0
23161 && w
->base_line_pos
<= startpos
)
23163 line
= w
->base_line_number
;
23164 linepos
= w
->base_line_pos
;
23165 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
23170 linepos
= BUF_BEGV (b
);
23171 linepos_byte
= BUF_BEGV_BYTE (b
);
23174 /* Count lines from base line to window start position. */
23175 nlines
= display_count_lines (linepos_byte
,
23179 topline
= nlines
+ line
;
23181 /* Determine a new base line, if the old one is too close
23182 or too far away, or if we did not have one.
23183 "Too close" means it's plausible a scroll-down would
23184 go back past it. */
23185 if (startpos
== BUF_BEGV (b
))
23187 w
->base_line_number
= topline
;
23188 w
->base_line_pos
= BUF_BEGV (b
);
23190 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
23191 || linepos
== BUF_BEGV (b
))
23193 ptrdiff_t limit
= BUF_BEGV (b
);
23194 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
23195 ptrdiff_t position
;
23196 ptrdiff_t distance
=
23197 (height
* 2 + 30) * line_number_display_limit_width
;
23199 if (startpos
- distance
> limit
)
23201 limit
= startpos
- distance
;
23202 limit_byte
= CHAR_TO_BYTE (limit
);
23205 nlines
= display_count_lines (startpos_byte
,
23207 - (height
* 2 + 30),
23209 /* If we couldn't find the lines we wanted within
23210 line_number_display_limit_width chars per line,
23211 give up on line numbers for this window. */
23212 if (position
== limit_byte
&& limit
== startpos
- distance
)
23214 w
->base_line_pos
= -1;
23215 w
->base_line_number
= 0;
23219 w
->base_line_number
= topline
- nlines
;
23220 w
->base_line_pos
= BYTE_TO_CHAR (position
);
23223 /* Now count lines from the start pos to point. */
23224 nlines
= display_count_lines (startpos_byte
,
23225 PT_BYTE
, PT
, &junk
);
23227 /* Record that we did display the line number. */
23228 line_number_displayed
= true;
23230 /* Make the string to show. */
23231 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
23232 return decode_mode_spec_buf
;
23235 char *p
= decode_mode_spec_buf
;
23236 int pad
= width
- 2;
23242 return decode_mode_spec_buf
;
23248 obj
= BVAR (b
, mode_name
);
23252 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
23258 ptrdiff_t pos
= marker_position (w
->start
);
23259 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23261 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
23263 if (pos
<= BUF_BEGV (b
))
23268 else if (pos
<= BUF_BEGV (b
))
23272 if (total
> 1000000)
23273 /* Do it differently for a large value, to avoid overflow. */
23274 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23276 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23277 /* We can't normally display a 3-digit number,
23278 so get us a 2-digit number that is close. */
23281 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23282 return decode_mode_spec_buf
;
23286 /* Display percentage of size above the bottom of the screen. */
23289 ptrdiff_t toppos
= marker_position (w
->start
);
23290 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
23291 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23293 if (botpos
>= BUF_ZV (b
))
23295 if (toppos
<= BUF_BEGV (b
))
23302 if (total
> 1000000)
23303 /* Do it differently for a large value, to avoid overflow. */
23304 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23306 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23307 /* We can't normally display a 3-digit number,
23308 so get us a 2-digit number that is close. */
23311 if (toppos
<= BUF_BEGV (b
))
23312 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
23314 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23315 return decode_mode_spec_buf
;
23320 /* status of process */
23321 obj
= Fget_buffer_process (Fcurrent_buffer ());
23323 return "no process";
23325 obj
= Fsymbol_name (Fprocess_status (obj
));
23331 ptrdiff_t count
= inhibit_garbage_collection ();
23332 Lisp_Object curdir
= BVAR (current_buffer
, directory
);
23333 Lisp_Object val
= Qnil
;
23335 if (STRINGP (curdir
))
23336 val
= call1 (intern ("file-remote-p"), curdir
);
23338 unbind_to (count
, Qnil
);
23347 /* coding-system (not including end-of-line format) */
23349 /* coding-system (including end-of-line type) */
23351 bool eol_flag
= (c
== 'Z');
23352 char *p
= decode_mode_spec_buf
;
23354 if (! FRAME_WINDOW_P (f
))
23356 /* No need to mention EOL here--the terminal never needs
23357 to do EOL conversion. */
23358 p
= decode_mode_spec_coding (CODING_ID_NAME
23359 (FRAME_KEYBOARD_CODING (f
)->id
),
23361 p
= decode_mode_spec_coding (CODING_ID_NAME
23362 (FRAME_TERMINAL_CODING (f
)->id
),
23365 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
23368 #if false /* This proves to be annoying; I think we can do without. -- rms. */
23369 #ifdef subprocesses
23370 obj
= Fget_buffer_process (Fcurrent_buffer ());
23371 if (PROCESSP (obj
))
23373 p
= decode_mode_spec_coding
23374 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
23375 p
= decode_mode_spec_coding
23376 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
23378 #endif /* subprocesses */
23381 return decode_mode_spec_buf
;
23388 return SSDATA (obj
);
23395 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
23396 means count lines back from START_BYTE. But don't go beyond
23397 LIMIT_BYTE. Return the number of lines thus found (always
23400 Set *BYTE_POS_PTR to the byte position where we stopped. This is
23401 either the position COUNT lines after/before START_BYTE, if we
23402 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
23406 display_count_lines (ptrdiff_t start_byte
,
23407 ptrdiff_t limit_byte
, ptrdiff_t count
,
23408 ptrdiff_t *byte_pos_ptr
)
23410 register unsigned char *cursor
;
23411 unsigned char *base
;
23413 register ptrdiff_t ceiling
;
23414 register unsigned char *ceiling_addr
;
23415 ptrdiff_t orig_count
= count
;
23417 /* If we are not in selective display mode,
23418 check only for newlines. */
23419 bool selective_display
23420 = (!NILP (BVAR (current_buffer
, selective_display
))
23421 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
23425 while (start_byte
< limit_byte
)
23427 ceiling
= BUFFER_CEILING_OF (start_byte
);
23428 ceiling
= min (limit_byte
- 1, ceiling
);
23429 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
23430 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
23434 if (selective_display
)
23436 while (*cursor
!= '\n' && *cursor
!= 015
23437 && ++cursor
!= ceiling_addr
)
23439 if (cursor
== ceiling_addr
)
23444 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
23453 start_byte
+= cursor
- base
;
23454 *byte_pos_ptr
= start_byte
;
23458 while (cursor
< ceiling_addr
);
23460 start_byte
+= ceiling_addr
- base
;
23465 while (start_byte
> limit_byte
)
23467 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
23468 ceiling
= max (limit_byte
, ceiling
);
23469 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
23470 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
23473 if (selective_display
)
23475 while (--cursor
>= ceiling_addr
23476 && *cursor
!= '\n' && *cursor
!= 015)
23478 if (cursor
< ceiling_addr
)
23483 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
23490 start_byte
+= cursor
- base
+ 1;
23491 *byte_pos_ptr
= start_byte
;
23492 /* When scanning backwards, we should
23493 not count the newline posterior to which we stop. */
23494 return - orig_count
- 1;
23497 start_byte
+= ceiling_addr
- base
;
23501 *byte_pos_ptr
= limit_byte
;
23504 return - orig_count
+ count
;
23505 return orig_count
- count
;
23511 /***********************************************************************
23513 ***********************************************************************/
23515 /* Display a NUL-terminated string, starting with index START.
23517 If STRING is non-null, display that C string. Otherwise, the Lisp
23518 string LISP_STRING is displayed. There's a case that STRING is
23519 non-null and LISP_STRING is not nil. It means STRING is a string
23520 data of LISP_STRING. In that case, we display LISP_STRING while
23521 ignoring its text properties.
23523 If FACE_STRING is not nil, FACE_STRING_POS is a position in
23524 FACE_STRING. Display STRING or LISP_STRING with the face at
23525 FACE_STRING_POS in FACE_STRING:
23527 Display the string in the environment given by IT, but use the
23528 standard display table, temporarily.
23530 FIELD_WIDTH is the minimum number of output glyphs to produce.
23531 If STRING has fewer characters than FIELD_WIDTH, pad to the right
23532 with spaces. If STRING has more characters, more than FIELD_WIDTH
23533 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
23535 PRECISION is the maximum number of characters to output from
23536 STRING. PRECISION < 0 means don't truncate the string.
23538 This is roughly equivalent to printf format specifiers:
23540 FIELD_WIDTH PRECISION PRINTF
23541 ----------------------------------------
23547 MULTIBYTE zero means do not display multibyte chars, > 0 means do
23548 display them, and < 0 means obey the current buffer's value of
23549 enable_multibyte_characters.
23551 Value is the number of columns displayed. */
23554 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
23555 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
23556 int field_width
, int precision
, int max_x
, int multibyte
)
23558 int hpos_at_start
= it
->hpos
;
23559 int saved_face_id
= it
->face_id
;
23560 struct glyph_row
*row
= it
->glyph_row
;
23561 ptrdiff_t it_charpos
;
23563 /* Initialize the iterator IT for iteration over STRING beginning
23564 with index START. */
23565 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
23566 precision
, field_width
, multibyte
);
23567 if (string
&& STRINGP (lisp_string
))
23568 /* LISP_STRING is the one returned by decode_mode_spec. We should
23569 ignore its text properties. */
23570 it
->stop_charpos
= it
->end_charpos
;
23572 /* If displaying STRING, set up the face of the iterator from
23573 FACE_STRING, if that's given. */
23574 if (STRINGP (face_string
))
23580 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
23581 0, &endptr
, it
->base_face_id
, false);
23582 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23583 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
23586 /* Set max_x to the maximum allowed X position. Don't let it go
23587 beyond the right edge of the window. */
23589 max_x
= it
->last_visible_x
;
23591 max_x
= min (max_x
, it
->last_visible_x
);
23593 /* Skip over display elements that are not visible. because IT->w is
23595 if (it
->current_x
< it
->first_visible_x
)
23596 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
23597 MOVE_TO_POS
| MOVE_TO_X
);
23599 row
->ascent
= it
->max_ascent
;
23600 row
->height
= it
->max_ascent
+ it
->max_descent
;
23601 row
->phys_ascent
= it
->max_phys_ascent
;
23602 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
23603 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
23605 if (STRINGP (it
->string
))
23606 it_charpos
= IT_STRING_CHARPOS (*it
);
23608 it_charpos
= IT_CHARPOS (*it
);
23610 /* This condition is for the case that we are called with current_x
23611 past last_visible_x. */
23612 while (it
->current_x
< max_x
)
23614 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
23616 /* Get the next display element. */
23617 if (!get_next_display_element (it
))
23620 /* Produce glyphs. */
23621 x_before
= it
->current_x
;
23622 n_glyphs_before
= row
->used
[TEXT_AREA
];
23623 PRODUCE_GLYPHS (it
);
23625 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
23628 while (i
< nglyphs
)
23630 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
23632 if (it
->line_wrap
!= TRUNCATE
23633 && x
+ glyph
->pixel_width
> max_x
)
23635 /* End of continued line or max_x reached. */
23636 if (CHAR_GLYPH_PADDING_P (*glyph
))
23638 /* A wide character is unbreakable. */
23639 if (row
->reversed_p
)
23640 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23641 - n_glyphs_before
);
23642 row
->used
[TEXT_AREA
] = n_glyphs_before
;
23643 it
->current_x
= x_before
;
23647 if (row
->reversed_p
)
23648 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23649 - (n_glyphs_before
+ i
));
23650 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
23655 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
23657 /* Glyph is at least partially visible. */
23659 if (x
< it
->first_visible_x
)
23660 row
->x
= x
- it
->first_visible_x
;
23664 /* Glyph is off the left margin of the display area.
23665 Should not happen. */
23669 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
23670 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
23671 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
23672 row
->phys_height
= max (row
->phys_height
,
23673 it
->max_phys_ascent
+ it
->max_phys_descent
);
23674 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
23675 it
->max_extra_line_spacing
);
23676 x
+= glyph
->pixel_width
;
23680 /* Stop if max_x reached. */
23684 /* Stop at line ends. */
23685 if (ITERATOR_AT_END_OF_LINE_P (it
))
23687 it
->continuation_lines_width
= 0;
23691 set_iterator_to_next (it
, true);
23692 if (STRINGP (it
->string
))
23693 it_charpos
= IT_STRING_CHARPOS (*it
);
23695 it_charpos
= IT_CHARPOS (*it
);
23697 /* Stop if truncating at the right edge. */
23698 if (it
->line_wrap
== TRUNCATE
23699 && it
->current_x
>= it
->last_visible_x
)
23701 /* Add truncation mark, but don't do it if the line is
23702 truncated at a padding space. */
23703 if (it_charpos
< it
->string_nchars
)
23705 if (!FRAME_WINDOW_P (it
->f
))
23709 if (it
->current_x
> it
->last_visible_x
)
23711 if (!row
->reversed_p
)
23713 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
23714 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
23719 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
23720 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
23722 unproduce_glyphs (it
, ii
+ 1);
23723 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
23725 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
23727 row
->used
[TEXT_AREA
] = ii
;
23728 produce_special_glyphs (it
, IT_TRUNCATION
);
23731 produce_special_glyphs (it
, IT_TRUNCATION
);
23733 row
->truncated_on_right_p
= true;
23739 /* Maybe insert a truncation at the left. */
23740 if (it
->first_visible_x
23743 if (!FRAME_WINDOW_P (it
->f
)
23744 || (row
->reversed_p
23745 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23746 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
23747 insert_left_trunc_glyphs (it
);
23748 row
->truncated_on_left_p
= true;
23751 it
->face_id
= saved_face_id
;
23753 /* Value is number of columns displayed. */
23754 return it
->hpos
- hpos_at_start
;
23759 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
23760 appears as an element of LIST or as the car of an element of LIST.
23761 If PROPVAL is a list, compare each element against LIST in that
23762 way, and return 1/2 if any element of PROPVAL is found in LIST.
23763 Otherwise return 0. This function cannot quit.
23764 The return value is 2 if the text is invisible but with an ellipsis
23765 and 1 if it's invisible and without an ellipsis. */
23768 invisible_prop (Lisp_Object propval
, Lisp_Object list
)
23770 Lisp_Object tail
, proptail
;
23772 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23774 register Lisp_Object tem
;
23776 if (EQ (propval
, tem
))
23778 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
23779 return NILP (XCDR (tem
)) ? 1 : 2;
23782 if (CONSP (propval
))
23784 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
23786 Lisp_Object propelt
;
23787 propelt
= XCAR (proptail
);
23788 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23790 register Lisp_Object tem
;
23792 if (EQ (propelt
, tem
))
23794 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
23795 return NILP (XCDR (tem
)) ? 1 : 2;
23803 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
23804 doc
: /* Non-nil if the property makes the text invisible.
23805 POS-OR-PROP can be a marker or number, in which case it is taken to be
23806 a position in the current buffer and the value of the `invisible' property
23807 is checked; or it can be some other value, which is then presumed to be the
23808 value of the `invisible' property of the text of interest.
23809 The non-nil value returned can be t for truly invisible text or something
23810 else if the text is replaced by an ellipsis. */)
23811 (Lisp_Object pos_or_prop
)
23814 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
23815 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
23817 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
23818 return (invis
== 0 ? Qnil
23820 : make_number (invis
));
23823 /* Calculate a width or height in pixels from a specification using
23824 the following elements:
23827 NUM - a (fractional) multiple of the default font width/height
23828 (NUM) - specifies exactly NUM pixels
23829 UNIT - a fixed number of pixels, see below.
23830 ELEMENT - size of a display element in pixels, see below.
23831 (NUM . SPEC) - equals NUM * SPEC
23832 (+ SPEC SPEC ...) - add pixel values
23833 (- SPEC SPEC ...) - subtract pixel values
23834 (- SPEC) - negate pixel value
23837 INT or FLOAT - a number constant
23838 SYMBOL - use symbol's (buffer local) variable binding.
23841 in - pixels per inch *)
23842 mm - pixels per 1/1000 meter *)
23843 cm - pixels per 1/100 meter *)
23844 width - width of current font in pixels.
23845 height - height of current font in pixels.
23847 *) using the ratio(s) defined in display-pixels-per-inch.
23851 left-fringe - left fringe width in pixels
23852 right-fringe - right fringe width in pixels
23854 left-margin - left margin width in pixels
23855 right-margin - right margin width in pixels
23857 scroll-bar - scroll-bar area width in pixels
23861 Pixels corresponding to 5 inches:
23864 Total width of non-text areas on left side of window (if scroll-bar is on left):
23865 '(space :width (+ left-fringe left-margin scroll-bar))
23867 Align to first text column (in header line):
23868 '(space :align-to 0)
23870 Align to middle of text area minus half the width of variable `my-image'
23871 containing a loaded image:
23872 '(space :align-to (0.5 . (- text my-image)))
23874 Width of left margin minus width of 1 character in the default font:
23875 '(space :width (- left-margin 1))
23877 Width of left margin minus width of 2 characters in the current font:
23878 '(space :width (- left-margin (2 . width)))
23880 Center 1 character over left-margin (in header line):
23881 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
23883 Different ways to express width of left fringe plus left margin minus one pixel:
23884 '(space :width (- (+ left-fringe left-margin) (1)))
23885 '(space :width (+ left-fringe left-margin (- (1))))
23886 '(space :width (+ left-fringe left-margin (-1)))
23891 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
23892 struct font
*font
, bool width_p
, int *align_to
)
23896 # define OK_PIXELS(val) (*res = (val), true)
23897 # define OK_ALIGN_TO(val) (*align_to = (val), true)
23900 return OK_PIXELS (0);
23902 eassert (FRAME_LIVE_P (it
->f
));
23904 if (SYMBOLP (prop
))
23906 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
23908 char *unit
= SSDATA (SYMBOL_NAME (prop
));
23910 if (unit
[0] == 'i' && unit
[1] == 'n')
23912 else if (unit
[0] == 'm' && unit
[1] == 'm')
23914 else if (unit
[0] == 'c' && unit
[1] == 'm')
23920 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
23921 : FRAME_RES_Y (it
->f
));
23924 return OK_PIXELS (ppi
/ pixels
);
23929 #ifdef HAVE_WINDOW_SYSTEM
23930 if (EQ (prop
, Qheight
))
23931 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
23932 if (EQ (prop
, Qwidth
))
23933 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
23935 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
23936 return OK_PIXELS (1);
23939 if (EQ (prop
, Qtext
))
23940 return OK_PIXELS (width_p
23941 ? window_box_width (it
->w
, TEXT_AREA
)
23942 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
23944 if (align_to
&& *align_to
< 0)
23947 if (EQ (prop
, Qleft
))
23948 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
23949 if (EQ (prop
, Qright
))
23950 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
23951 if (EQ (prop
, Qcenter
))
23952 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
23953 + window_box_width (it
->w
, TEXT_AREA
) / 2);
23954 if (EQ (prop
, Qleft_fringe
))
23955 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23956 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
23957 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
23958 if (EQ (prop
, Qright_fringe
))
23959 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23960 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23961 : window_box_right_offset (it
->w
, TEXT_AREA
));
23962 if (EQ (prop
, Qleft_margin
))
23963 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
23964 if (EQ (prop
, Qright_margin
))
23965 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
23966 if (EQ (prop
, Qscroll_bar
))
23967 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
23969 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23970 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23971 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23976 if (EQ (prop
, Qleft_fringe
))
23977 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
23978 if (EQ (prop
, Qright_fringe
))
23979 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
23980 if (EQ (prop
, Qleft_margin
))
23981 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
23982 if (EQ (prop
, Qright_margin
))
23983 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
23984 if (EQ (prop
, Qscroll_bar
))
23985 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
23988 prop
= buffer_local_value (prop
, it
->w
->contents
);
23989 if (EQ (prop
, Qunbound
))
23993 if (INTEGERP (prop
) || FLOATP (prop
))
23995 int base_unit
= (width_p
23996 ? FRAME_COLUMN_WIDTH (it
->f
)
23997 : FRAME_LINE_HEIGHT (it
->f
));
23998 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
24003 Lisp_Object car
= XCAR (prop
);
24004 Lisp_Object cdr
= XCDR (prop
);
24008 #ifdef HAVE_WINDOW_SYSTEM
24009 if (FRAME_WINDOW_P (it
->f
)
24010 && valid_image_p (prop
))
24012 ptrdiff_t id
= lookup_image (it
->f
, prop
);
24013 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
24015 return OK_PIXELS (width_p
? img
->width
: img
->height
);
24018 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
24024 while (CONSP (cdr
))
24026 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
24027 font
, width_p
, align_to
))
24030 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= false;
24035 if (EQ (car
, Qminus
))
24037 return OK_PIXELS (pixels
);
24040 car
= buffer_local_value (car
, it
->w
->contents
);
24041 if (EQ (car
, Qunbound
))
24045 if (INTEGERP (car
) || FLOATP (car
))
24048 pixels
= XFLOATINT (car
);
24050 return OK_PIXELS (pixels
);
24051 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
24052 font
, width_p
, align_to
))
24053 return OK_PIXELS (pixels
* fact
);
24064 /***********************************************************************
24066 ***********************************************************************/
24068 #ifdef HAVE_WINDOW_SYSTEM
24073 dump_glyph_string (struct glyph_string
*s
)
24075 fprintf (stderr
, "glyph string\n");
24076 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
24077 s
->x
, s
->y
, s
->width
, s
->height
);
24078 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
24079 fprintf (stderr
, " hl = %d\n", s
->hl
);
24080 fprintf (stderr
, " left overhang = %d, right = %d\n",
24081 s
->left_overhang
, s
->right_overhang
);
24082 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
24083 fprintf (stderr
, " extends to end of line = %d\n",
24084 s
->extends_to_end_of_line_p
);
24085 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
24086 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
24089 #endif /* GLYPH_DEBUG */
24091 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
24092 of XChar2b structures for S; it can't be allocated in
24093 init_glyph_string because it must be allocated via `alloca'. W
24094 is the window on which S is drawn. ROW and AREA are the glyph row
24095 and area within the row from which S is constructed. START is the
24096 index of the first glyph structure covered by S. HL is a
24097 face-override for drawing S. */
24100 #define OPTIONAL_HDC(hdc) HDC hdc,
24101 #define DECLARE_HDC(hdc) HDC hdc;
24102 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
24103 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
24106 #ifndef OPTIONAL_HDC
24107 #define OPTIONAL_HDC(hdc)
24108 #define DECLARE_HDC(hdc)
24109 #define ALLOCATE_HDC(hdc, f)
24110 #define RELEASE_HDC(hdc, f)
24114 init_glyph_string (struct glyph_string
*s
,
24116 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
24117 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
24119 memset (s
, 0, sizeof *s
);
24121 s
->f
= XFRAME (w
->frame
);
24125 s
->display
= FRAME_X_DISPLAY (s
->f
);
24126 s
->window
= FRAME_X_WINDOW (s
->f
);
24127 s
->char2b
= char2b
;
24131 s
->first_glyph
= row
->glyphs
[area
] + start
;
24132 s
->height
= row
->height
;
24133 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
24134 s
->ybase
= s
->y
+ row
->ascent
;
24138 /* Append the list of glyph strings with head H and tail T to the list
24139 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
24142 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24143 struct glyph_string
*h
, struct glyph_string
*t
)
24157 /* Prepend the list of glyph strings with head H and tail T to the
24158 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
24162 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24163 struct glyph_string
*h
, struct glyph_string
*t
)
24177 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
24178 Set *HEAD and *TAIL to the resulting list. */
24181 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
24182 struct glyph_string
*s
)
24184 s
->next
= s
->prev
= NULL
;
24185 append_glyph_string_lists (head
, tail
, s
, s
);
24189 /* Get face and two-byte form of character C in face FACE_ID on frame F.
24190 The encoding of C is returned in *CHAR2B. DISPLAY_P means
24191 make sure that X resources for the face returned are allocated.
24192 Value is a pointer to a realized face that is ready for display if
24195 static struct face
*
24196 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
24197 XChar2b
*char2b
, bool display_p
)
24199 struct face
*face
= FACE_FROM_ID (f
, face_id
);
24204 code
= face
->font
->driver
->encode_char (face
->font
, c
);
24206 if (code
== FONT_INVALID_CODE
)
24209 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24211 /* Make sure X resources of the face are allocated. */
24212 #ifdef HAVE_X_WINDOWS
24216 eassert (face
!= NULL
);
24217 prepare_face_for_display (f
, face
);
24224 /* Get face and two-byte form of character glyph GLYPH on frame F.
24225 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
24226 a pointer to a realized face that is ready for display. */
24228 static struct face
*
24229 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
24235 eassert (glyph
->type
== CHAR_GLYPH
);
24236 face
= FACE_FROM_ID (f
, glyph
->face_id
);
24238 /* Make sure X resources of the face are allocated. */
24239 eassert (face
!= NULL
);
24240 prepare_face_for_display (f
, face
);
24244 if (CHAR_BYTE8_P (glyph
->u
.ch
))
24245 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
24247 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
24249 if (code
== FONT_INVALID_CODE
)
24253 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24258 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
24259 Return true iff FONT has a glyph for C. */
24262 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
24266 if (CHAR_BYTE8_P (c
))
24267 code
= CHAR_TO_BYTE8 (c
);
24269 code
= font
->driver
->encode_char (font
, c
);
24271 if (code
== FONT_INVALID_CODE
)
24273 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24278 /* Fill glyph string S with composition components specified by S->cmp.
24280 BASE_FACE is the base face of the composition.
24281 S->cmp_from is the index of the first component for S.
24283 OVERLAPS non-zero means S should draw the foreground only, and use
24284 its physical height for clipping. See also draw_glyphs.
24286 Value is the index of a component not in S. */
24289 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
24293 /* For all glyphs of this composition, starting at the offset
24294 S->cmp_from, until we reach the end of the definition or encounter a
24295 glyph that requires the different face, add it to S. */
24300 s
->for_overlaps
= overlaps
;
24303 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
24305 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
24307 /* TAB in a composition means display glyphs with padding space
24308 on the left or right. */
24311 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
24314 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
24315 s
->char2b
+ i
, true);
24321 s
->font
= s
->face
->font
;
24323 else if (s
->face
!= face
)
24331 if (s
->face
== NULL
)
24333 s
->face
= base_face
->ascii_face
;
24334 s
->font
= s
->face
->font
;
24337 /* All glyph strings for the same composition has the same width,
24338 i.e. the width set for the first component of the composition. */
24339 s
->width
= s
->first_glyph
->pixel_width
;
24341 /* If the specified font could not be loaded, use the frame's
24342 default font, but record the fact that we couldn't load it in
24343 the glyph string so that we can draw rectangles for the
24344 characters of the glyph string. */
24345 if (s
->font
== NULL
)
24347 s
->font_not_found_p
= true;
24348 s
->font
= FRAME_FONT (s
->f
);
24351 /* Adjust base line for subscript/superscript text. */
24352 s
->ybase
+= s
->first_glyph
->voffset
;
24358 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
24359 int start
, int end
, int overlaps
)
24361 struct glyph
*glyph
, *last
;
24362 Lisp_Object lgstring
;
24365 s
->for_overlaps
= overlaps
;
24366 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24367 last
= s
->row
->glyphs
[s
->area
] + end
;
24368 s
->cmp_id
= glyph
->u
.cmp
.id
;
24369 s
->cmp_from
= glyph
->slice
.cmp
.from
;
24370 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
24371 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24372 lgstring
= composition_gstring_from_id (s
->cmp_id
);
24373 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
24375 while (glyph
< last
24376 && glyph
->u
.cmp
.automatic
24377 && glyph
->u
.cmp
.id
== s
->cmp_id
24378 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
24379 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
24381 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
24383 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
24384 unsigned code
= LGLYPH_CODE (lglyph
);
24386 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
24388 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
24389 return glyph
- s
->row
->glyphs
[s
->area
];
24393 /* Fill glyph string S from a sequence glyphs for glyphless characters.
24394 See the comment of fill_glyph_string for arguments.
24395 Value is the index of the first glyph not in S. */
24399 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
24400 int start
, int end
, int overlaps
)
24402 struct glyph
*glyph
, *last
;
24405 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
24406 s
->for_overlaps
= overlaps
;
24407 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24408 last
= s
->row
->glyphs
[s
->area
] + end
;
24409 voffset
= glyph
->voffset
;
24410 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24411 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
24413 s
->width
= glyph
->pixel_width
;
24415 while (glyph
< last
24416 && glyph
->type
== GLYPHLESS_GLYPH
24417 && glyph
->voffset
== voffset
24418 && glyph
->face_id
== face_id
)
24421 s
->width
+= glyph
->pixel_width
;
24424 s
->ybase
+= voffset
;
24425 return glyph
- s
->row
->glyphs
[s
->area
];
24429 /* Fill glyph string S from a sequence of character glyphs.
24431 FACE_ID is the face id of the string. START is the index of the
24432 first glyph to consider, END is the index of the last + 1.
24433 OVERLAPS non-zero means S should draw the foreground only, and use
24434 its physical height for clipping. See also draw_glyphs.
24436 Value is the index of the first glyph not in S. */
24439 fill_glyph_string (struct glyph_string
*s
, int face_id
,
24440 int start
, int end
, int overlaps
)
24442 struct glyph
*glyph
, *last
;
24444 bool glyph_not_available_p
;
24446 eassert (s
->f
== XFRAME (s
->w
->frame
));
24447 eassert (s
->nchars
== 0);
24448 eassert (start
>= 0 && end
> start
);
24450 s
->for_overlaps
= overlaps
;
24451 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24452 last
= s
->row
->glyphs
[s
->area
] + end
;
24453 voffset
= glyph
->voffset
;
24454 s
->padding_p
= glyph
->padding_p
;
24455 glyph_not_available_p
= glyph
->glyph_not_available_p
;
24457 while (glyph
< last
24458 && glyph
->type
== CHAR_GLYPH
24459 && glyph
->voffset
== voffset
24460 /* Same face id implies same font, nowadays. */
24461 && glyph
->face_id
== face_id
24462 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
24464 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
24465 s
->char2b
+ s
->nchars
);
24467 eassert (s
->nchars
<= end
- start
);
24468 s
->width
+= glyph
->pixel_width
;
24469 if (glyph
++->padding_p
!= s
->padding_p
)
24473 s
->font
= s
->face
->font
;
24475 /* If the specified font could not be loaded, use the frame's font,
24476 but record the fact that we couldn't load it in
24477 S->font_not_found_p so that we can draw rectangles for the
24478 characters of the glyph string. */
24479 if (s
->font
== NULL
|| glyph_not_available_p
)
24481 s
->font_not_found_p
= true;
24482 s
->font
= FRAME_FONT (s
->f
);
24485 /* Adjust base line for subscript/superscript text. */
24486 s
->ybase
+= voffset
;
24488 eassert (s
->face
&& s
->face
->gc
);
24489 return glyph
- s
->row
->glyphs
[s
->area
];
24493 /* Fill glyph string S from image glyph S->first_glyph. */
24496 fill_image_glyph_string (struct glyph_string
*s
)
24498 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
24499 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
24501 s
->slice
= s
->first_glyph
->slice
.img
;
24502 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24503 s
->font
= s
->face
->font
;
24504 s
->width
= s
->first_glyph
->pixel_width
;
24506 /* Adjust base line for subscript/superscript text. */
24507 s
->ybase
+= s
->first_glyph
->voffset
;
24511 /* Fill glyph string S from a sequence of stretch glyphs.
24513 START is the index of the first glyph to consider,
24514 END is the index of the last + 1.
24516 Value is the index of the first glyph not in S. */
24519 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
24521 struct glyph
*glyph
, *last
;
24522 int voffset
, face_id
;
24524 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
24526 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24527 last
= s
->row
->glyphs
[s
->area
] + end
;
24528 face_id
= glyph
->face_id
;
24529 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24530 s
->font
= s
->face
->font
;
24531 s
->width
= glyph
->pixel_width
;
24533 voffset
= glyph
->voffset
;
24537 && glyph
->type
== STRETCH_GLYPH
24538 && glyph
->voffset
== voffset
24539 && glyph
->face_id
== face_id
);
24541 s
->width
+= glyph
->pixel_width
;
24543 /* Adjust base line for subscript/superscript text. */
24544 s
->ybase
+= voffset
;
24546 /* The case that face->gc == 0 is handled when drawing the glyph
24547 string by calling prepare_face_for_display. */
24549 return glyph
- s
->row
->glyphs
[s
->area
];
24552 static struct font_metrics
*
24553 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
24555 static struct font_metrics metrics
;
24560 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
24561 if (code
== FONT_INVALID_CODE
)
24563 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
24568 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
24569 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
24570 assumed to be zero. */
24573 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
24575 *left
= *right
= 0;
24577 if (glyph
->type
== CHAR_GLYPH
)
24580 struct face
*face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
);
24583 struct font_metrics
*pcm
= get_per_char_metric (face
->font
, &char2b
);
24586 if (pcm
->rbearing
> pcm
->width
)
24587 *right
= pcm
->rbearing
- pcm
->width
;
24588 if (pcm
->lbearing
< 0)
24589 *left
= -pcm
->lbearing
;
24593 else if (glyph
->type
== COMPOSITE_GLYPH
)
24595 if (! glyph
->u
.cmp
.automatic
)
24597 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
24599 if (cmp
->rbearing
> cmp
->pixel_width
)
24600 *right
= cmp
->rbearing
- cmp
->pixel_width
;
24601 if (cmp
->lbearing
< 0)
24602 *left
= - cmp
->lbearing
;
24606 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
24607 struct font_metrics metrics
;
24609 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
24610 glyph
->slice
.cmp
.to
+ 1, &metrics
);
24611 if (metrics
.rbearing
> metrics
.width
)
24612 *right
= metrics
.rbearing
- metrics
.width
;
24613 if (metrics
.lbearing
< 0)
24614 *left
= - metrics
.lbearing
;
24620 /* Return the index of the first glyph preceding glyph string S that
24621 is overwritten by S because of S's left overhang. Value is -1
24622 if no glyphs are overwritten. */
24625 left_overwritten (struct glyph_string
*s
)
24629 if (s
->left_overhang
)
24632 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24633 int first
= s
->first_glyph
- glyphs
;
24635 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
24636 x
-= glyphs
[i
].pixel_width
;
24647 /* Return the index of the first glyph preceding glyph string S that
24648 is overwriting S because of its right overhang. Value is -1 if no
24649 glyph in front of S overwrites S. */
24652 left_overwriting (struct glyph_string
*s
)
24655 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24656 int first
= s
->first_glyph
- glyphs
;
24660 for (i
= first
- 1; i
>= 0; --i
)
24663 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
24666 x
-= glyphs
[i
].pixel_width
;
24673 /* Return the index of the last glyph following glyph string S that is
24674 overwritten by S because of S's right overhang. Value is -1 if
24675 no such glyph is found. */
24678 right_overwritten (struct glyph_string
*s
)
24682 if (s
->right_overhang
)
24685 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24686 int first
= (s
->first_glyph
- glyphs
24687 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
24688 int end
= s
->row
->used
[s
->area
];
24690 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
24691 x
+= glyphs
[i
].pixel_width
;
24700 /* Return the index of the last glyph following glyph string S that
24701 overwrites S because of its left overhang. Value is negative
24702 if no such glyph is found. */
24705 right_overwriting (struct glyph_string
*s
)
24708 int end
= s
->row
->used
[s
->area
];
24709 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24710 int first
= (s
->first_glyph
- glyphs
24711 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
24715 for (i
= first
; i
< end
; ++i
)
24718 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
24721 x
+= glyphs
[i
].pixel_width
;
24728 /* Set background width of glyph string S. START is the index of the
24729 first glyph following S. LAST_X is the right-most x-position + 1
24730 in the drawing area. */
24733 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
24735 /* If the face of this glyph string has to be drawn to the end of
24736 the drawing area, set S->extends_to_end_of_line_p. */
24738 if (start
== s
->row
->used
[s
->area
]
24739 && ((s
->row
->fill_line_p
24740 && (s
->hl
== DRAW_NORMAL_TEXT
24741 || s
->hl
== DRAW_IMAGE_RAISED
24742 || s
->hl
== DRAW_IMAGE_SUNKEN
))
24743 || s
->hl
== DRAW_MOUSE_FACE
))
24744 s
->extends_to_end_of_line_p
= true;
24746 /* If S extends its face to the end of the line, set its
24747 background_width to the distance to the right edge of the drawing
24749 if (s
->extends_to_end_of_line_p
)
24750 s
->background_width
= last_x
- s
->x
+ 1;
24752 s
->background_width
= s
->width
;
24756 /* Compute overhangs and x-positions for glyph string S and its
24757 predecessors, or successors. X is the starting x-position for S.
24758 BACKWARD_P means process predecessors. */
24761 compute_overhangs_and_x (struct glyph_string
*s
, int x
, bool backward_p
)
24767 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24768 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24778 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24779 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24789 /* The following macros are only called from draw_glyphs below.
24790 They reference the following parameters of that function directly:
24791 `w', `row', `area', and `overlap_p'
24792 as well as the following local variables:
24793 `s', `f', and `hdc' (in W32) */
24796 /* On W32, silently add local `hdc' variable to argument list of
24797 init_glyph_string. */
24798 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24799 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
24801 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24802 init_glyph_string (s, char2b, w, row, area, start, hl)
24805 /* Add a glyph string for a stretch glyph to the list of strings
24806 between HEAD and TAIL. START is the index of the stretch glyph in
24807 row area AREA of glyph row ROW. END is the index of the last glyph
24808 in that glyph row area. X is the current output position assigned
24809 to the new glyph string constructed. HL overrides that face of the
24810 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24811 is the right-most x-position of the drawing area. */
24813 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
24814 and below -- keep them on one line. */
24815 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24818 s = alloca (sizeof *s); \
24819 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24820 START = fill_stretch_glyph_string (s, START, END); \
24821 append_glyph_string (&HEAD, &TAIL, s); \
24827 /* Add a glyph string for an image glyph to the list of strings
24828 between HEAD and TAIL. START is the index of the image glyph in
24829 row area AREA of glyph row ROW. END is the index of the last glyph
24830 in that glyph row area. X is the current output position assigned
24831 to the new glyph string constructed. HL overrides that face of the
24832 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24833 is the right-most x-position of the drawing area. */
24835 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24838 s = alloca (sizeof *s); \
24839 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24840 fill_image_glyph_string (s); \
24841 append_glyph_string (&HEAD, &TAIL, s); \
24848 /* Add a glyph string for a sequence of character glyphs to the list
24849 of strings between HEAD and TAIL. START is the index of the first
24850 glyph in row area AREA of glyph row ROW that is part of the new
24851 glyph string. END is the index of the last glyph in that glyph row
24852 area. X is the current output position assigned to the new glyph
24853 string constructed. HL overrides that face of the glyph; e.g. it
24854 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
24855 right-most x-position of the drawing area. */
24857 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24863 face_id = (row)->glyphs[area][START].face_id; \
24865 s = alloca (sizeof *s); \
24866 SAFE_NALLOCA (char2b, 1, (END) - (START)); \
24867 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24868 append_glyph_string (&HEAD, &TAIL, s); \
24870 START = fill_glyph_string (s, face_id, START, END, overlaps); \
24875 /* Add a glyph string for a composite sequence to the list of strings
24876 between HEAD and TAIL. START is the index of the first glyph in
24877 row area AREA of glyph row ROW that is part of the new glyph
24878 string. END is the index of the last glyph in that glyph row area.
24879 X is the current output position assigned to the new glyph string
24880 constructed. HL overrides that face of the glyph; e.g. it is
24881 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
24882 x-position of the drawing area. */
24884 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24886 int face_id = (row)->glyphs[area][START].face_id; \
24887 struct face *base_face = FACE_FROM_ID (f, face_id); \
24888 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
24889 struct composition *cmp = composition_table[cmp_id]; \
24891 struct glyph_string *first_s = NULL; \
24894 SAFE_NALLOCA (char2b, 1, cmp->glyph_len); \
24896 /* Make glyph_strings for each glyph sequence that is drawable by \
24897 the same face, and append them to HEAD/TAIL. */ \
24898 for (n = 0; n < cmp->glyph_len;) \
24900 s = alloca (sizeof *s); \
24901 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24902 append_glyph_string (&(HEAD), &(TAIL), s); \
24908 n = fill_composite_glyph_string (s, base_face, overlaps); \
24916 /* Add a glyph string for a glyph-string sequence to the list of strings
24917 between HEAD and TAIL. */
24919 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24923 Lisp_Object gstring; \
24925 face_id = (row)->glyphs[area][START].face_id; \
24926 gstring = (composition_gstring_from_id \
24927 ((row)->glyphs[area][START].u.cmp.id)); \
24928 s = alloca (sizeof *s); \
24929 SAFE_NALLOCA (char2b, 1, LGSTRING_GLYPH_LEN (gstring)); \
24930 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24931 append_glyph_string (&(HEAD), &(TAIL), s); \
24933 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
24937 /* Add a glyph string for a sequence of glyphless character's glyphs
24938 to the list of strings between HEAD and TAIL. The meanings of
24939 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
24941 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24946 face_id = (row)->glyphs[area][START].face_id; \
24948 s = alloca (sizeof *s); \
24949 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24950 append_glyph_string (&HEAD, &TAIL, s); \
24952 START = fill_glyphless_glyph_string (s, face_id, START, END, \
24958 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
24959 of AREA of glyph row ROW on window W between indices START and END.
24960 HL overrides the face for drawing glyph strings, e.g. it is
24961 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
24962 x-positions of the drawing area.
24964 This is an ugly monster macro construct because we must use alloca
24965 to allocate glyph strings (because draw_glyphs can be called
24966 asynchronously). */
24968 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24971 HEAD = TAIL = NULL; \
24972 while (START < END) \
24974 struct glyph *first_glyph = (row)->glyphs[area] + START; \
24975 switch (first_glyph->type) \
24978 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
24982 case COMPOSITE_GLYPH: \
24983 if (first_glyph->u.cmp.automatic) \
24984 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
24987 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
24991 case STRETCH_GLYPH: \
24992 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
24996 case IMAGE_GLYPH: \
24997 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
25001 case GLYPHLESS_GLYPH: \
25002 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
25012 set_glyph_string_background_width (s, START, LAST_X); \
25019 /* Draw glyphs between START and END in AREA of ROW on window W,
25020 starting at x-position X. X is relative to AREA in W. HL is a
25021 face-override with the following meaning:
25023 DRAW_NORMAL_TEXT draw normally
25024 DRAW_CURSOR draw in cursor face
25025 DRAW_MOUSE_FACE draw in mouse face.
25026 DRAW_INVERSE_VIDEO draw in mode line face
25027 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
25028 DRAW_IMAGE_RAISED draw an image with a raised relief around it
25030 If OVERLAPS is non-zero, draw only the foreground of characters and
25031 clip to the physical height of ROW. Non-zero value also defines
25032 the overlapping part to be drawn:
25034 OVERLAPS_PRED overlap with preceding rows
25035 OVERLAPS_SUCC overlap with succeeding rows
25036 OVERLAPS_BOTH overlap with both preceding/succeeding rows
25037 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
25039 Value is the x-position reached, relative to AREA of W. */
25042 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
25043 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
25044 enum draw_glyphs_face hl
, int overlaps
)
25046 struct glyph_string
*head
, *tail
;
25047 struct glyph_string
*s
;
25048 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
25049 int i
, j
, x_reached
, last_x
, area_left
= 0;
25050 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25053 ALLOCATE_HDC (hdc
, f
);
25055 /* Let's rather be paranoid than getting a SEGV. */
25056 end
= min (end
, row
->used
[area
]);
25057 start
= clip_to_bounds (0, start
, end
);
25059 /* Translate X to frame coordinates. Set last_x to the right
25060 end of the drawing area. */
25061 if (row
->full_width_p
)
25063 /* X is relative to the left edge of W, without scroll bars
25065 area_left
= WINDOW_LEFT_EDGE_X (w
);
25066 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
25067 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
25071 area_left
= window_box_left (w
, area
);
25072 last_x
= area_left
+ window_box_width (w
, area
);
25076 /* Build a doubly-linked list of glyph_string structures between
25077 head and tail from what we have to draw. Note that the macro
25078 BUILD_GLYPH_STRINGS will modify its start parameter. That's
25079 the reason we use a separate variable `i'. */
25082 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
25084 x_reached
= tail
->x
+ tail
->background_width
;
25088 /* If there are any glyphs with lbearing < 0 or rbearing > width in
25089 the row, redraw some glyphs in front or following the glyph
25090 strings built above. */
25091 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
25093 struct glyph_string
*h
, *t
;
25094 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25095 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
25096 bool check_mouse_face
= false;
25099 /* If mouse highlighting is on, we may need to draw adjacent
25100 glyphs using mouse-face highlighting. */
25101 if (area
== TEXT_AREA
&& row
->mouse_face_p
25102 && hlinfo
->mouse_face_beg_row
>= 0
25103 && hlinfo
->mouse_face_end_row
>= 0)
25105 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
25107 if (row_vpos
>= hlinfo
->mouse_face_beg_row
25108 && row_vpos
<= hlinfo
->mouse_face_end_row
)
25110 check_mouse_face
= true;
25111 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
25112 ? hlinfo
->mouse_face_beg_col
: 0;
25113 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
25114 ? hlinfo
->mouse_face_end_col
25115 : row
->used
[TEXT_AREA
];
25119 /* Compute overhangs for all glyph strings. */
25120 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
25121 for (s
= head
; s
; s
= s
->next
)
25122 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
25124 /* Prepend glyph strings for glyphs in front of the first glyph
25125 string that are overwritten because of the first glyph
25126 string's left overhang. The background of all strings
25127 prepended must be drawn because the first glyph string
25129 i
= left_overwritten (head
);
25132 enum draw_glyphs_face overlap_hl
;
25134 /* If this row contains mouse highlighting, attempt to draw
25135 the overlapped glyphs with the correct highlight. This
25136 code fails if the overlap encompasses more than one glyph
25137 and mouse-highlight spans only some of these glyphs.
25138 However, making it work perfectly involves a lot more
25139 code, and I don't know if the pathological case occurs in
25140 practice, so we'll stick to this for now. --- cyd */
25141 if (check_mouse_face
25142 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25143 overlap_hl
= DRAW_MOUSE_FACE
;
25145 overlap_hl
= DRAW_NORMAL_TEXT
;
25147 if (hl
!= overlap_hl
)
25150 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
25151 overlap_hl
, dummy_x
, last_x
);
25153 compute_overhangs_and_x (t
, head
->x
, true);
25154 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25155 if (clip_head
== NULL
)
25159 /* Prepend glyph strings for glyphs in front of the first glyph
25160 string that overwrite that glyph string because of their
25161 right overhang. For these strings, only the foreground must
25162 be drawn, because it draws over the glyph string at `head'.
25163 The background must not be drawn because this would overwrite
25164 right overhangs of preceding glyphs for which no glyph
25166 i
= left_overwriting (head
);
25169 enum draw_glyphs_face overlap_hl
;
25171 if (check_mouse_face
25172 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25173 overlap_hl
= DRAW_MOUSE_FACE
;
25175 overlap_hl
= DRAW_NORMAL_TEXT
;
25177 if (hl
== overlap_hl
|| clip_head
== NULL
)
25179 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
25180 overlap_hl
, dummy_x
, last_x
);
25181 for (s
= h
; s
; s
= s
->next
)
25182 s
->background_filled_p
= true;
25183 compute_overhangs_and_x (t
, head
->x
, true);
25184 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25187 /* Append glyphs strings for glyphs following the last glyph
25188 string tail that are overwritten by tail. The background of
25189 these strings has to be drawn because tail's foreground draws
25191 i
= right_overwritten (tail
);
25194 enum draw_glyphs_face overlap_hl
;
25196 if (check_mouse_face
25197 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25198 overlap_hl
= DRAW_MOUSE_FACE
;
25200 overlap_hl
= DRAW_NORMAL_TEXT
;
25202 if (hl
!= overlap_hl
)
25204 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25205 overlap_hl
, x
, last_x
);
25206 /* Because BUILD_GLYPH_STRINGS updates the first argument,
25207 we don't have `end = i;' here. */
25208 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25209 append_glyph_string_lists (&head
, &tail
, h
, t
);
25210 if (clip_tail
== NULL
)
25214 /* Append glyph strings for glyphs following the last glyph
25215 string tail that overwrite tail. The foreground of such
25216 glyphs has to be drawn because it writes into the background
25217 of tail. The background must not be drawn because it could
25218 paint over the foreground of following glyphs. */
25219 i
= right_overwriting (tail
);
25222 enum draw_glyphs_face overlap_hl
;
25223 if (check_mouse_face
25224 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25225 overlap_hl
= DRAW_MOUSE_FACE
;
25227 overlap_hl
= DRAW_NORMAL_TEXT
;
25229 if (hl
== overlap_hl
|| clip_tail
== NULL
)
25231 i
++; /* We must include the Ith glyph. */
25232 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25233 overlap_hl
, x
, last_x
);
25234 for (s
= h
; s
; s
= s
->next
)
25235 s
->background_filled_p
= true;
25236 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25237 append_glyph_string_lists (&head
, &tail
, h
, t
);
25239 if (clip_head
|| clip_tail
)
25240 for (s
= head
; s
; s
= s
->next
)
25242 s
->clip_head
= clip_head
;
25243 s
->clip_tail
= clip_tail
;
25247 /* Draw all strings. */
25248 for (s
= head
; s
; s
= s
->next
)
25249 FRAME_RIF (f
)->draw_glyph_string (s
);
25252 /* When focus a sole frame and move horizontally, this clears on_p
25253 causing a failure to erase prev cursor position. */
25254 if (area
== TEXT_AREA
25255 && !row
->full_width_p
25256 /* When drawing overlapping rows, only the glyph strings'
25257 foreground is drawn, which doesn't erase a cursor
25261 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
25262 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
25263 : (tail
? tail
->x
+ tail
->background_width
: x
));
25267 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
25268 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
25272 /* Value is the x-position up to which drawn, relative to AREA of W.
25273 This doesn't include parts drawn because of overhangs. */
25274 if (row
->full_width_p
)
25275 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
25277 x_reached
-= area_left
;
25279 RELEASE_HDC (hdc
, f
);
25285 /* Expand row matrix if too narrow. Don't expand if area
25288 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
25290 if (!it->f->fonts_changed \
25291 && (it->glyph_row->glyphs[area] \
25292 < it->glyph_row->glyphs[area + 1])) \
25294 it->w->ncols_scale_factor++; \
25295 it->f->fonts_changed = true; \
25299 /* Store one glyph for IT->char_to_display in IT->glyph_row.
25300 Called from x_produce_glyphs when IT->glyph_row is non-null. */
25303 append_glyph (struct it
*it
)
25305 struct glyph
*glyph
;
25306 enum glyph_row_area area
= it
->area
;
25308 eassert (it
->glyph_row
);
25309 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
25311 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25312 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25314 /* If the glyph row is reversed, we need to prepend the glyph
25315 rather than append it. */
25316 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25320 /* Make room for the additional glyph. */
25321 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25323 glyph
= it
->glyph_row
->glyphs
[area
];
25325 glyph
->charpos
= CHARPOS (it
->position
);
25326 glyph
->object
= it
->object
;
25327 if (it
->pixel_width
> 0)
25329 glyph
->pixel_width
= it
->pixel_width
;
25330 glyph
->padding_p
= false;
25334 /* Assure at least 1-pixel width. Otherwise, cursor can't
25335 be displayed correctly. */
25336 glyph
->pixel_width
= 1;
25337 glyph
->padding_p
= true;
25339 glyph
->ascent
= it
->ascent
;
25340 glyph
->descent
= it
->descent
;
25341 glyph
->voffset
= it
->voffset
;
25342 glyph
->type
= CHAR_GLYPH
;
25343 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25344 glyph
->multibyte_p
= it
->multibyte_p
;
25345 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25347 /* In R2L rows, the left and the right box edges need to be
25348 drawn in reverse direction. */
25349 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25350 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25354 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25355 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25357 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25358 || it
->phys_descent
> it
->descent
);
25359 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
25360 glyph
->face_id
= it
->face_id
;
25361 glyph
->u
.ch
= it
->char_to_display
;
25362 glyph
->slice
.img
= null_glyph_slice
;
25363 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25366 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25367 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25368 glyph
->bidi_type
= it
->bidi_it
.type
;
25372 glyph
->resolved_level
= 0;
25373 glyph
->bidi_type
= UNKNOWN_BT
;
25375 ++it
->glyph_row
->used
[area
];
25378 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25381 /* Store one glyph for the composition IT->cmp_it.id in
25382 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
25386 append_composite_glyph (struct it
*it
)
25388 struct glyph
*glyph
;
25389 enum glyph_row_area area
= it
->area
;
25391 eassert (it
->glyph_row
);
25393 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25394 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25396 /* If the glyph row is reversed, we need to prepend the glyph
25397 rather than append it. */
25398 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
25402 /* Make room for the new glyph. */
25403 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
25405 glyph
= it
->glyph_row
->glyphs
[it
->area
];
25407 glyph
->charpos
= it
->cmp_it
.charpos
;
25408 glyph
->object
= it
->object
;
25409 glyph
->pixel_width
= it
->pixel_width
;
25410 glyph
->ascent
= it
->ascent
;
25411 glyph
->descent
= it
->descent
;
25412 glyph
->voffset
= it
->voffset
;
25413 glyph
->type
= COMPOSITE_GLYPH
;
25414 if (it
->cmp_it
.ch
< 0)
25416 glyph
->u
.cmp
.automatic
= false;
25417 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25418 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
25422 glyph
->u
.cmp
.automatic
= true;
25423 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25424 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
25425 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
25427 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25428 glyph
->multibyte_p
= it
->multibyte_p
;
25429 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25431 /* In R2L rows, the left and the right box edges need to be
25432 drawn in reverse direction. */
25433 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25434 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25438 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25439 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25441 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25442 || it
->phys_descent
> it
->descent
);
25443 glyph
->padding_p
= false;
25444 glyph
->glyph_not_available_p
= false;
25445 glyph
->face_id
= it
->face_id
;
25446 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25449 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25450 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25451 glyph
->bidi_type
= it
->bidi_it
.type
;
25453 ++it
->glyph_row
->used
[area
];
25456 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25460 /* Change IT->ascent and IT->height according to the setting of
25464 take_vertical_position_into_account (struct it
*it
)
25468 if (it
->voffset
< 0)
25469 /* Increase the ascent so that we can display the text higher
25471 it
->ascent
-= it
->voffset
;
25473 /* Increase the descent so that we can display the text lower
25475 it
->descent
+= it
->voffset
;
25480 /* Produce glyphs/get display metrics for the image IT is loaded with.
25481 See the description of struct display_iterator in dispextern.h for
25482 an overview of struct display_iterator. */
25485 produce_image_glyph (struct it
*it
)
25489 int glyph_ascent
, crop
;
25490 struct glyph_slice slice
;
25492 eassert (it
->what
== IT_IMAGE
);
25494 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25496 /* Make sure X resources of the face is loaded. */
25497 prepare_face_for_display (it
->f
, face
);
25499 if (it
->image_id
< 0)
25501 /* Fringe bitmap. */
25502 it
->ascent
= it
->phys_ascent
= 0;
25503 it
->descent
= it
->phys_descent
= 0;
25504 it
->pixel_width
= 0;
25509 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
25511 /* Make sure X resources of the image is loaded. */
25512 prepare_image_for_display (it
->f
, img
);
25514 slice
.x
= slice
.y
= 0;
25515 slice
.width
= img
->width
;
25516 slice
.height
= img
->height
;
25518 if (INTEGERP (it
->slice
.x
))
25519 slice
.x
= XINT (it
->slice
.x
);
25520 else if (FLOATP (it
->slice
.x
))
25521 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
25523 if (INTEGERP (it
->slice
.y
))
25524 slice
.y
= XINT (it
->slice
.y
);
25525 else if (FLOATP (it
->slice
.y
))
25526 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
25528 if (INTEGERP (it
->slice
.width
))
25529 slice
.width
= XINT (it
->slice
.width
);
25530 else if (FLOATP (it
->slice
.width
))
25531 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
25533 if (INTEGERP (it
->slice
.height
))
25534 slice
.height
= XINT (it
->slice
.height
);
25535 else if (FLOATP (it
->slice
.height
))
25536 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
25538 if (slice
.x
>= img
->width
)
25539 slice
.x
= img
->width
;
25540 if (slice
.y
>= img
->height
)
25541 slice
.y
= img
->height
;
25542 if (slice
.x
+ slice
.width
>= img
->width
)
25543 slice
.width
= img
->width
- slice
.x
;
25544 if (slice
.y
+ slice
.height
> img
->height
)
25545 slice
.height
= img
->height
- slice
.y
;
25547 if (slice
.width
== 0 || slice
.height
== 0)
25550 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
25552 it
->descent
= slice
.height
- glyph_ascent
;
25554 it
->descent
+= img
->vmargin
;
25555 if (slice
.y
+ slice
.height
== img
->height
)
25556 it
->descent
+= img
->vmargin
;
25557 it
->phys_descent
= it
->descent
;
25559 it
->pixel_width
= slice
.width
;
25561 it
->pixel_width
+= img
->hmargin
;
25562 if (slice
.x
+ slice
.width
== img
->width
)
25563 it
->pixel_width
+= img
->hmargin
;
25565 /* It's quite possible for images to have an ascent greater than
25566 their height, so don't get confused in that case. */
25567 if (it
->descent
< 0)
25572 if (face
->box
!= FACE_NO_BOX
)
25574 if (face
->box_line_width
> 0)
25577 it
->ascent
+= face
->box_line_width
;
25578 if (slice
.y
+ slice
.height
== img
->height
)
25579 it
->descent
+= face
->box_line_width
;
25582 if (it
->start_of_box_run_p
&& slice
.x
== 0)
25583 it
->pixel_width
+= eabs (face
->box_line_width
);
25584 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
25585 it
->pixel_width
+= eabs (face
->box_line_width
);
25588 take_vertical_position_into_account (it
);
25590 /* Automatically crop wide image glyphs at right edge so we can
25591 draw the cursor on same display row. */
25592 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
25593 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
25595 it
->pixel_width
-= crop
;
25596 slice
.width
-= crop
;
25601 struct glyph
*glyph
;
25602 enum glyph_row_area area
= it
->area
;
25604 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25605 if (it
->glyph_row
->reversed_p
)
25609 /* Make room for the new glyph. */
25610 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
25612 glyph
= it
->glyph_row
->glyphs
[it
->area
];
25614 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25616 glyph
->charpos
= CHARPOS (it
->position
);
25617 glyph
->object
= it
->object
;
25618 glyph
->pixel_width
= it
->pixel_width
;
25619 glyph
->ascent
= glyph_ascent
;
25620 glyph
->descent
= it
->descent
;
25621 glyph
->voffset
= it
->voffset
;
25622 glyph
->type
= IMAGE_GLYPH
;
25623 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25624 glyph
->multibyte_p
= it
->multibyte_p
;
25625 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25627 /* In R2L rows, the left and the right box edges need to be
25628 drawn in reverse direction. */
25629 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25630 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25634 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25635 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25637 glyph
->overlaps_vertically_p
= false;
25638 glyph
->padding_p
= false;
25639 glyph
->glyph_not_available_p
= false;
25640 glyph
->face_id
= it
->face_id
;
25641 glyph
->u
.img_id
= img
->id
;
25642 glyph
->slice
.img
= slice
;
25643 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25646 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25647 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25648 glyph
->bidi_type
= it
->bidi_it
.type
;
25650 ++it
->glyph_row
->used
[area
];
25653 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25658 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
25659 of the glyph, WIDTH and HEIGHT are the width and height of the
25660 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
25663 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
25664 int width
, int height
, int ascent
)
25666 struct glyph
*glyph
;
25667 enum glyph_row_area area
= it
->area
;
25669 eassert (ascent
>= 0 && ascent
<= height
);
25671 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25672 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25674 /* If the glyph row is reversed, we need to prepend the glyph
25675 rather than append it. */
25676 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25680 /* Make room for the additional glyph. */
25681 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25683 glyph
= it
->glyph_row
->glyphs
[area
];
25685 /* Decrease the width of the first glyph of the row that
25686 begins before first_visible_x (e.g., due to hscroll).
25687 This is so the overall width of the row becomes smaller
25688 by the scroll amount, and the stretch glyph appended by
25689 extend_face_to_end_of_line will be wider, to shift the
25690 row glyphs to the right. (In L2R rows, the corresponding
25691 left-shift effect is accomplished by setting row->x to a
25692 negative value, which won't work with R2L rows.)
25694 This must leave us with a positive value of WIDTH, since
25695 otherwise the call to move_it_in_display_line_to at the
25696 beginning of display_line would have got past the entire
25697 first glyph, and then it->current_x would have been
25698 greater or equal to it->first_visible_x. */
25699 if (it
->current_x
< it
->first_visible_x
)
25700 width
-= it
->first_visible_x
- it
->current_x
;
25701 eassert (width
> 0);
25703 glyph
->charpos
= CHARPOS (it
->position
);
25704 glyph
->object
= object
;
25705 glyph
->pixel_width
= width
;
25706 glyph
->ascent
= ascent
;
25707 glyph
->descent
= height
- ascent
;
25708 glyph
->voffset
= it
->voffset
;
25709 glyph
->type
= STRETCH_GLYPH
;
25710 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25711 glyph
->multibyte_p
= it
->multibyte_p
;
25712 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25714 /* In R2L rows, the left and the right box edges need to be
25715 drawn in reverse direction. */
25716 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25717 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25721 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25722 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25724 glyph
->overlaps_vertically_p
= false;
25725 glyph
->padding_p
= false;
25726 glyph
->glyph_not_available_p
= false;
25727 glyph
->face_id
= it
->face_id
;
25728 glyph
->u
.stretch
.ascent
= ascent
;
25729 glyph
->u
.stretch
.height
= height
;
25730 glyph
->slice
.img
= null_glyph_slice
;
25731 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25734 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25735 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25736 glyph
->bidi_type
= it
->bidi_it
.type
;
25740 glyph
->resolved_level
= 0;
25741 glyph
->bidi_type
= UNKNOWN_BT
;
25743 ++it
->glyph_row
->used
[area
];
25746 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25749 #endif /* HAVE_WINDOW_SYSTEM */
25751 /* Produce a stretch glyph for iterator IT. IT->object is the value
25752 of the glyph property displayed. The value must be a list
25753 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
25756 1. `:width WIDTH' specifies that the space should be WIDTH *
25757 canonical char width wide. WIDTH may be an integer or floating
25760 2. `:relative-width FACTOR' specifies that the width of the stretch
25761 should be computed from the width of the first character having the
25762 `glyph' property, and should be FACTOR times that width.
25764 3. `:align-to HPOS' specifies that the space should be wide enough
25765 to reach HPOS, a value in canonical character units.
25767 Exactly one of the above pairs must be present.
25769 4. `:height HEIGHT' specifies that the height of the stretch produced
25770 should be HEIGHT, measured in canonical character units.
25772 5. `:relative-height FACTOR' specifies that the height of the
25773 stretch should be FACTOR times the height of the characters having
25774 the glyph property.
25776 Either none or exactly one of 4 or 5 must be present.
25778 6. `:ascent ASCENT' specifies that ASCENT percent of the height
25779 of the stretch should be used for the ascent of the stretch.
25780 ASCENT must be in the range 0 <= ASCENT <= 100. */
25783 produce_stretch_glyph (struct it
*it
)
25785 /* (space :width WIDTH :height HEIGHT ...) */
25786 Lisp_Object prop
, plist
;
25787 int width
= 0, height
= 0, align_to
= -1;
25788 bool zero_width_ok_p
= false;
25790 struct font
*font
= NULL
;
25792 #ifdef HAVE_WINDOW_SYSTEM
25794 bool zero_height_ok_p
= false;
25796 if (FRAME_WINDOW_P (it
->f
))
25798 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25799 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25800 prepare_face_for_display (it
->f
, face
);
25804 /* List should start with `space'. */
25805 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
25806 plist
= XCDR (it
->object
);
25808 /* Compute the width of the stretch. */
25809 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
25810 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true, 0))
25812 /* Absolute width `:width WIDTH' specified and valid. */
25813 zero_width_ok_p
= true;
25816 #ifdef HAVE_WINDOW_SYSTEM
25817 else if (FRAME_WINDOW_P (it
->f
)
25818 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
25820 /* Relative width `:relative-width FACTOR' specified and valid.
25821 Compute the width of the characters having the `glyph'
25824 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
25827 if (it
->multibyte_p
)
25828 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
25831 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
25832 if (! ASCII_CHAR_P (it2
.c
))
25833 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
25836 it2
.glyph_row
= NULL
;
25837 it2
.what
= IT_CHARACTER
;
25838 x_produce_glyphs (&it2
);
25839 width
= NUMVAL (prop
) * it2
.pixel_width
;
25841 #endif /* HAVE_WINDOW_SYSTEM */
25842 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
25843 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true,
25846 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
25847 align_to
= (align_to
< 0
25849 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
25850 else if (align_to
< 0)
25851 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
25852 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
25853 zero_width_ok_p
= true;
25856 /* Nothing specified -> width defaults to canonical char width. */
25857 width
= FRAME_COLUMN_WIDTH (it
->f
);
25859 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
25862 #ifdef HAVE_WINDOW_SYSTEM
25863 /* Compute height. */
25864 if (FRAME_WINDOW_P (it
->f
))
25866 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
25867 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
25870 zero_height_ok_p
= true;
25872 else if (prop
= Fplist_get (plist
, QCrelative_height
),
25874 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
25876 height
= FONT_HEIGHT (font
);
25878 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
25881 /* Compute percentage of height used for ascent. If
25882 `:ascent ASCENT' is present and valid, use that. Otherwise,
25883 derive the ascent from the font in use. */
25884 if (prop
= Fplist_get (plist
, QCascent
),
25885 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
25886 ascent
= height
* NUMVAL (prop
) / 100.0;
25887 else if (!NILP (prop
)
25888 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
25889 ascent
= min (max (0, (int)tem
), height
);
25891 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
25894 #endif /* HAVE_WINDOW_SYSTEM */
25897 if (width
> 0 && it
->line_wrap
!= TRUNCATE
25898 && it
->current_x
+ width
> it
->last_visible_x
)
25900 width
= it
->last_visible_x
- it
->current_x
;
25901 #ifdef HAVE_WINDOW_SYSTEM
25902 /* Subtract one more pixel from the stretch width, but only on
25903 GUI frames, since on a TTY each glyph is one "pixel" wide. */
25904 width
-= FRAME_WINDOW_P (it
->f
);
25908 if (width
> 0 && height
> 0 && it
->glyph_row
)
25910 Lisp_Object o_object
= it
->object
;
25911 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
25914 if (!STRINGP (object
))
25915 object
= it
->w
->contents
;
25916 #ifdef HAVE_WINDOW_SYSTEM
25917 if (FRAME_WINDOW_P (it
->f
))
25918 append_stretch_glyph (it
, object
, width
, height
, ascent
);
25922 it
->object
= object
;
25923 it
->char_to_display
= ' ';
25924 it
->pixel_width
= it
->len
= 1;
25926 tty_append_glyph (it
);
25927 it
->object
= o_object
;
25931 it
->pixel_width
= width
;
25932 #ifdef HAVE_WINDOW_SYSTEM
25933 if (FRAME_WINDOW_P (it
->f
))
25935 it
->ascent
= it
->phys_ascent
= ascent
;
25936 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
25937 it
->nglyphs
= width
> 0 && height
> 0;
25938 take_vertical_position_into_account (it
);
25942 it
->nglyphs
= width
;
25945 /* Get information about special display element WHAT in an
25946 environment described by IT. WHAT is one of IT_TRUNCATION or
25947 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
25948 non-null glyph_row member. This function ensures that fields like
25949 face_id, c, len of IT are left untouched. */
25952 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
25959 temp_it
.object
= Qnil
;
25960 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
25962 if (what
== IT_CONTINUATION
)
25964 /* Continuation glyph. For R2L lines, we mirror it by hand. */
25965 if (it
->bidi_it
.paragraph_dir
== R2L
)
25966 SET_GLYPH_FROM_CHAR (glyph
, '/');
25968 SET_GLYPH_FROM_CHAR (glyph
, '\\');
25970 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25972 /* FIXME: Should we mirror GC for R2L lines? */
25973 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25974 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25977 else if (what
== IT_TRUNCATION
)
25979 /* Truncation glyph. */
25980 SET_GLYPH_FROM_CHAR (glyph
, '$');
25982 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25984 /* FIXME: Should we mirror GC for R2L lines? */
25985 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25986 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25992 #ifdef HAVE_WINDOW_SYSTEM
25993 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
25994 is turned off, we precede the truncation/continuation glyphs by a
25995 stretch glyph whose width is computed such that these special
25996 glyphs are aligned at the window margin, even when very different
25997 fonts are used in different glyph rows. */
25998 if (FRAME_WINDOW_P (temp_it
.f
)
25999 /* init_iterator calls this with it->glyph_row == NULL, and it
26000 wants only the pixel width of the truncation/continuation
26002 && temp_it
.glyph_row
26003 /* insert_left_trunc_glyphs calls us at the beginning of the
26004 row, and it has its own calculation of the stretch glyph
26006 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
26007 && (temp_it
.glyph_row
->reversed_p
26008 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
26009 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
26011 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
26013 if (stretch_width
> 0)
26015 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
26016 struct font
*font
=
26017 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
26018 int stretch_ascent
=
26019 (((temp_it
.ascent
+ temp_it
.descent
)
26020 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
26022 append_stretch_glyph (&temp_it
, Qnil
, stretch_width
,
26023 temp_it
.ascent
+ temp_it
.descent
,
26030 temp_it
.what
= IT_CHARACTER
;
26031 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
26032 temp_it
.face_id
= GLYPH_FACE (glyph
);
26033 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
26035 PRODUCE_GLYPHS (&temp_it
);
26036 it
->pixel_width
= temp_it
.pixel_width
;
26037 it
->nglyphs
= temp_it
.nglyphs
;
26040 #ifdef HAVE_WINDOW_SYSTEM
26042 /* Calculate line-height and line-spacing properties.
26043 An integer value specifies explicit pixel value.
26044 A float value specifies relative value to current face height.
26045 A cons (float . face-name) specifies relative value to
26046 height of specified face font.
26048 Returns height in pixels, or nil. */
26051 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
26052 int boff
, bool override
)
26054 Lisp_Object face_name
= Qnil
;
26055 int ascent
, descent
, height
;
26057 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
26062 face_name
= XCAR (val
);
26064 if (!NUMBERP (val
))
26065 val
= make_number (1);
26066 if (NILP (face_name
))
26068 height
= it
->ascent
+ it
->descent
;
26073 if (NILP (face_name
))
26075 font
= FRAME_FONT (it
->f
);
26076 boff
= FRAME_BASELINE_OFFSET (it
->f
);
26078 else if (EQ (face_name
, Qt
))
26087 face_id
= lookup_named_face (it
->f
, face_name
, false);
26089 return make_number (-1);
26091 face
= FACE_FROM_ID (it
->f
, face_id
);
26094 return make_number (-1);
26095 boff
= font
->baseline_offset
;
26096 if (font
->vertical_centering
)
26097 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26100 ascent
= FONT_BASE (font
) + boff
;
26101 descent
= FONT_DESCENT (font
) - boff
;
26105 it
->override_ascent
= ascent
;
26106 it
->override_descent
= descent
;
26107 it
->override_boff
= boff
;
26110 height
= ascent
+ descent
;
26114 height
= (int)(XFLOAT_DATA (val
) * height
);
26115 else if (INTEGERP (val
))
26116 height
*= XINT (val
);
26118 return make_number (height
);
26122 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
26123 is a face ID to be used for the glyph. FOR_NO_FONT is true if
26124 and only if this is for a character for which no font was found.
26126 If the display method (it->glyphless_method) is
26127 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
26128 length of the acronym or the hexadecimal string, UPPER_XOFF and
26129 UPPER_YOFF are pixel offsets for the upper part of the string,
26130 LOWER_XOFF and LOWER_YOFF are for the lower part.
26132 For the other display methods, LEN through LOWER_YOFF are zero. */
26135 append_glyphless_glyph (struct it
*it
, int face_id
, bool for_no_font
, int len
,
26136 short upper_xoff
, short upper_yoff
,
26137 short lower_xoff
, short lower_yoff
)
26139 struct glyph
*glyph
;
26140 enum glyph_row_area area
= it
->area
;
26142 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26143 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26145 /* If the glyph row is reversed, we need to prepend the glyph
26146 rather than append it. */
26147 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26151 /* Make room for the additional glyph. */
26152 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26154 glyph
= it
->glyph_row
->glyphs
[area
];
26156 glyph
->charpos
= CHARPOS (it
->position
);
26157 glyph
->object
= it
->object
;
26158 glyph
->pixel_width
= it
->pixel_width
;
26159 glyph
->ascent
= it
->ascent
;
26160 glyph
->descent
= it
->descent
;
26161 glyph
->voffset
= it
->voffset
;
26162 glyph
->type
= GLYPHLESS_GLYPH
;
26163 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
26164 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
26165 glyph
->u
.glyphless
.len
= len
;
26166 glyph
->u
.glyphless
.ch
= it
->c
;
26167 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
26168 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
26169 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
26170 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
26171 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26172 glyph
->multibyte_p
= it
->multibyte_p
;
26173 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26175 /* In R2L rows, the left and the right box edges need to be
26176 drawn in reverse direction. */
26177 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26178 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26182 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26183 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26185 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
26186 || it
->phys_descent
> it
->descent
);
26187 glyph
->padding_p
= false;
26188 glyph
->glyph_not_available_p
= false;
26189 glyph
->face_id
= face_id
;
26190 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26193 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26194 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26195 glyph
->bidi_type
= it
->bidi_it
.type
;
26197 ++it
->glyph_row
->used
[area
];
26200 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26204 /* Produce a glyph for a glyphless character for iterator IT.
26205 IT->glyphless_method specifies which method to use for displaying
26206 the character. See the description of enum
26207 glyphless_display_method in dispextern.h for the detail.
26209 FOR_NO_FONT is true if and only if this is for a character for
26210 which no font was found. ACRONYM, if non-nil, is an acronym string
26211 for the character. */
26214 produce_glyphless_glyph (struct it
*it
, bool for_no_font
, Lisp_Object acronym
)
26219 int base_width
, base_height
, width
, height
;
26220 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
26223 /* Get the metrics of the base font. We always refer to the current
26225 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
26226 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26227 it
->ascent
= FONT_BASE (font
);
26228 it
->descent
= FONT_DESCENT (font
);
26229 /* Attempt to fix box height for fonts that claim preposterously
26231 if (FONT_TOO_HIGH (font
))
26235 /* Get metrics of a reasonably sized ASCII character. */
26236 if (get_char_glyph_code ('{', font
, &char2b
))
26238 struct font_metrics
*pcm
= get_per_char_metric (font
, &char2b
);
26240 if (!(pcm
->width
== 0 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0))
26242 it
->ascent
= pcm
->ascent
;
26243 it
->descent
= pcm
->descent
;
26247 it
->ascent
+= font
->baseline_offset
;
26248 it
->descent
-= font
->baseline_offset
;
26249 base_height
= it
->ascent
+ it
->descent
;
26250 base_width
= font
->average_width
;
26252 face_id
= merge_glyphless_glyph_face (it
);
26254 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
26256 it
->pixel_width
= THIN_SPACE_WIDTH
;
26258 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26260 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
26262 width
= CHAR_WIDTH (it
->c
);
26265 else if (width
> 4)
26267 it
->pixel_width
= base_width
* width
;
26269 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26275 unsigned int code
[6];
26277 int ascent
, descent
;
26278 struct font_metrics metrics_upper
, metrics_lower
;
26280 face
= FACE_FROM_ID (it
->f
, face_id
);
26281 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26282 prepare_face_for_display (it
->f
, face
);
26284 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
26286 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
26287 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
26288 if (CONSP (acronym
))
26289 acronym
= XCAR (acronym
);
26290 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
26294 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
26295 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
+ 0u);
26298 for (len
= 0; str
[len
] && ASCII_CHAR_P (str
[len
]) && len
< 6; len
++)
26299 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
26300 upper_len
= (len
+ 1) / 2;
26301 font
->driver
->text_extents (font
, code
, upper_len
,
26303 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
26308 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
26309 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
26310 upper_xoff
= upper_yoff
= 2; /* the typical case */
26311 if (base_width
>= width
)
26313 /* Align the upper to the left, the lower to the right. */
26314 it
->pixel_width
= base_width
;
26315 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
26319 /* Center the shorter one. */
26320 it
->pixel_width
= width
;
26321 if (metrics_upper
.width
>= metrics_lower
.width
)
26322 lower_xoff
= (width
- metrics_lower
.width
) / 2;
26325 /* FIXME: This code doesn't look right. It formerly was
26326 missing the "lower_xoff = 0;", which couldn't have
26327 been right since it left lower_xoff uninitialized. */
26329 upper_xoff
= (width
- metrics_upper
.width
) / 2;
26333 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
26334 top, bottom, and between upper and lower strings. */
26335 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
26336 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
26337 /* Center vertically.
26338 H:base_height, D:base_descent
26339 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
26341 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
26342 descent = D - H/2 + h/2;
26343 lower_yoff = descent - 2 - ld;
26344 upper_yoff = lower_yoff - la - 1 - ud; */
26345 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
26346 descent
= it
->descent
- (base_height
- height
) / 2;
26347 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
26348 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
26349 - metrics_upper
.descent
);
26350 /* Don't make the height shorter than the base height. */
26351 if (height
> base_height
)
26353 it
->ascent
= ascent
;
26354 it
->descent
= descent
;
26358 it
->phys_ascent
= it
->ascent
;
26359 it
->phys_descent
= it
->descent
;
26361 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
26362 upper_xoff
, upper_yoff
,
26363 lower_xoff
, lower_yoff
);
26365 take_vertical_position_into_account (it
);
26370 Produce glyphs/get display metrics for the display element IT is
26371 loaded with. See the description of struct it in dispextern.h
26372 for an overview of struct it. */
26375 x_produce_glyphs (struct it
*it
)
26377 int extra_line_spacing
= it
->extra_line_spacing
;
26379 it
->glyph_not_available_p
= false;
26381 if (it
->what
== IT_CHARACTER
)
26384 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26385 struct font
*font
= face
->font
;
26386 struct font_metrics
*pcm
= NULL
;
26387 int boff
; /* Baseline offset. */
26391 /* When no suitable font is found, display this character by
26392 the method specified in the first extra slot of
26393 Vglyphless_char_display. */
26394 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
26396 eassert (it
->what
== IT_GLYPHLESS
);
26397 produce_glyphless_glyph (it
, true,
26398 STRINGP (acronym
) ? acronym
: Qnil
);
26402 boff
= font
->baseline_offset
;
26403 if (font
->vertical_centering
)
26404 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26406 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
26410 if (it
->override_ascent
>= 0)
26412 it
->ascent
= it
->override_ascent
;
26413 it
->descent
= it
->override_descent
;
26414 boff
= it
->override_boff
;
26418 it
->ascent
= FONT_BASE (font
) + boff
;
26419 it
->descent
= FONT_DESCENT (font
) - boff
;
26422 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
26424 pcm
= get_per_char_metric (font
, &char2b
);
26425 if (pcm
->width
== 0
26426 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
26432 it
->phys_ascent
= pcm
->ascent
+ boff
;
26433 it
->phys_descent
= pcm
->descent
- boff
;
26434 it
->pixel_width
= pcm
->width
;
26435 /* Don't use font-global values for ascent and descent
26436 if they result in an exceedingly large line height. */
26437 if (it
->override_ascent
< 0)
26439 if (FONT_TOO_HIGH (font
))
26441 it
->ascent
= it
->phys_ascent
;
26442 it
->descent
= it
->phys_descent
;
26443 /* These limitations are enforced by an
26444 assertion near the end of this function. */
26445 if (it
->ascent
< 0)
26447 if (it
->descent
< 0)
26454 it
->glyph_not_available_p
= true;
26455 it
->phys_ascent
= it
->ascent
;
26456 it
->phys_descent
= it
->descent
;
26457 it
->pixel_width
= font
->space_width
;
26460 if (it
->constrain_row_ascent_descent_p
)
26462 if (it
->descent
> it
->max_descent
)
26464 it
->ascent
+= it
->descent
- it
->max_descent
;
26465 it
->descent
= it
->max_descent
;
26467 if (it
->ascent
> it
->max_ascent
)
26469 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
26470 it
->ascent
= it
->max_ascent
;
26472 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
26473 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
26474 extra_line_spacing
= 0;
26477 /* If this is a space inside a region of text with
26478 `space-width' property, change its width. */
26480 = it
->char_to_display
== ' ' && !NILP (it
->space_width
);
26482 it
->pixel_width
*= XFLOATINT (it
->space_width
);
26484 /* If face has a box, add the box thickness to the character
26485 height. If character has a box line to the left and/or
26486 right, add the box line width to the character's width. */
26487 if (face
->box
!= FACE_NO_BOX
)
26489 int thick
= face
->box_line_width
;
26493 it
->ascent
+= thick
;
26494 it
->descent
+= thick
;
26499 if (it
->start_of_box_run_p
)
26500 it
->pixel_width
+= thick
;
26501 if (it
->end_of_box_run_p
)
26502 it
->pixel_width
+= thick
;
26505 /* If face has an overline, add the height of the overline
26506 (1 pixel) and a 1 pixel margin to the character height. */
26507 if (face
->overline_p
)
26508 it
->ascent
+= overline_margin
;
26510 if (it
->constrain_row_ascent_descent_p
)
26512 if (it
->ascent
> it
->max_ascent
)
26513 it
->ascent
= it
->max_ascent
;
26514 if (it
->descent
> it
->max_descent
)
26515 it
->descent
= it
->max_descent
;
26518 take_vertical_position_into_account (it
);
26520 /* If we have to actually produce glyphs, do it. */
26525 /* Translate a space with a `space-width' property
26526 into a stretch glyph. */
26527 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
26528 / FONT_HEIGHT (font
));
26529 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
26530 it
->ascent
+ it
->descent
, ascent
);
26535 /* If characters with lbearing or rbearing are displayed
26536 in this line, record that fact in a flag of the
26537 glyph row. This is used to optimize X output code. */
26538 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
26539 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
26541 if (! stretched_p
&& it
->pixel_width
== 0)
26542 /* We assure that all visible glyphs have at least 1-pixel
26544 it
->pixel_width
= 1;
26546 else if (it
->char_to_display
== '\n')
26548 /* A newline has no width, but we need the height of the
26549 line. But if previous part of the line sets a height,
26550 don't increase that height. */
26552 Lisp_Object height
;
26553 Lisp_Object total_height
= Qnil
;
26555 it
->override_ascent
= -1;
26556 it
->pixel_width
= 0;
26559 height
= get_it_property (it
, Qline_height
);
26560 /* Split (line-height total-height) list. */
26562 && CONSP (XCDR (height
))
26563 && NILP (XCDR (XCDR (height
))))
26565 total_height
= XCAR (XCDR (height
));
26566 height
= XCAR (height
);
26568 height
= calc_line_height_property (it
, height
, font
, boff
, true);
26570 if (it
->override_ascent
>= 0)
26572 it
->ascent
= it
->override_ascent
;
26573 it
->descent
= it
->override_descent
;
26574 boff
= it
->override_boff
;
26578 if (FONT_TOO_HIGH (font
))
26580 it
->ascent
= font
->pixel_size
+ boff
- 1;
26581 it
->descent
= -boff
+ 1;
26582 if (it
->descent
< 0)
26587 it
->ascent
= FONT_BASE (font
) + boff
;
26588 it
->descent
= FONT_DESCENT (font
) - boff
;
26592 if (EQ (height
, Qt
))
26594 if (it
->descent
> it
->max_descent
)
26596 it
->ascent
+= it
->descent
- it
->max_descent
;
26597 it
->descent
= it
->max_descent
;
26599 if (it
->ascent
> it
->max_ascent
)
26601 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
26602 it
->ascent
= it
->max_ascent
;
26604 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
26605 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
26606 it
->constrain_row_ascent_descent_p
= true;
26607 extra_line_spacing
= 0;
26611 Lisp_Object spacing
;
26613 it
->phys_ascent
= it
->ascent
;
26614 it
->phys_descent
= it
->descent
;
26616 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
26617 && face
->box
!= FACE_NO_BOX
26618 && face
->box_line_width
> 0)
26620 it
->ascent
+= face
->box_line_width
;
26621 it
->descent
+= face
->box_line_width
;
26624 && XINT (height
) > it
->ascent
+ it
->descent
)
26625 it
->ascent
= XINT (height
) - it
->descent
;
26627 if (!NILP (total_height
))
26628 spacing
= calc_line_height_property (it
, total_height
, font
,
26632 spacing
= get_it_property (it
, Qline_spacing
);
26633 spacing
= calc_line_height_property (it
, spacing
, font
,
26636 if (INTEGERP (spacing
))
26638 extra_line_spacing
= XINT (spacing
);
26639 if (!NILP (total_height
))
26640 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
26644 else /* i.e. (it->char_to_display == '\t') */
26646 if (font
->space_width
> 0)
26648 int tab_width
= it
->tab_width
* font
->space_width
;
26649 int x
= it
->current_x
+ it
->continuation_lines_width
;
26650 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
26652 /* If the distance from the current position to the next tab
26653 stop is less than a space character width, use the
26654 tab stop after that. */
26655 if (next_tab_x
- x
< font
->space_width
)
26656 next_tab_x
+= tab_width
;
26658 it
->pixel_width
= next_tab_x
- x
;
26660 if (FONT_TOO_HIGH (font
))
26662 if (get_char_glyph_code (' ', font
, &char2b
))
26664 pcm
= get_per_char_metric (font
, &char2b
);
26665 if (pcm
->width
== 0
26666 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
26672 it
->ascent
= pcm
->ascent
+ boff
;
26673 it
->descent
= pcm
->descent
- boff
;
26677 it
->ascent
= font
->pixel_size
+ boff
- 1;
26678 it
->descent
= -boff
+ 1;
26680 if (it
->ascent
< 0)
26682 if (it
->descent
< 0)
26687 it
->ascent
= FONT_BASE (font
) + boff
;
26688 it
->descent
= FONT_DESCENT (font
) - boff
;
26690 it
->phys_ascent
= it
->ascent
;
26691 it
->phys_descent
= it
->descent
;
26695 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
26696 it
->ascent
+ it
->descent
, it
->ascent
);
26701 it
->pixel_width
= 0;
26706 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
26708 /* A static composition.
26710 Note: A composition is represented as one glyph in the
26711 glyph matrix. There are no padding glyphs.
26713 Important note: pixel_width, ascent, and descent are the
26714 values of what is drawn by draw_glyphs (i.e. the values of
26715 the overall glyphs composed). */
26716 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26717 int boff
; /* baseline offset */
26718 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
26719 int glyph_len
= cmp
->glyph_len
;
26720 struct font
*font
= face
->font
;
26724 /* If we have not yet calculated pixel size data of glyphs of
26725 the composition for the current face font, calculate them
26726 now. Theoretically, we have to check all fonts for the
26727 glyphs, but that requires much time and memory space. So,
26728 here we check only the font of the first glyph. This may
26729 lead to incorrect display, but it's very rare, and C-l
26730 (recenter-top-bottom) can correct the display anyway. */
26731 if (! cmp
->font
|| cmp
->font
!= font
)
26733 /* Ascent and descent of the font of the first character
26734 of this composition (adjusted by baseline offset).
26735 Ascent and descent of overall glyphs should not be less
26736 than these, respectively. */
26737 int font_ascent
, font_descent
, font_height
;
26738 /* Bounding box of the overall glyphs. */
26739 int leftmost
, rightmost
, lowest
, highest
;
26740 int lbearing
, rbearing
;
26741 int i
, width
, ascent
, descent
;
26742 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
26744 struct font_metrics
*pcm
;
26747 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
26748 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
26750 bool right_padded
= glyph_len
< cmp
->glyph_len
;
26751 for (i
= 0; i
< glyph_len
; i
++)
26753 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
26755 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
26757 bool left_padded
= i
> 0;
26759 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
26760 : IT_CHARPOS (*it
));
26761 /* If no suitable font is found, use the default font. */
26762 bool font_not_found_p
= font
== NULL
;
26763 if (font_not_found_p
)
26765 face
= face
->ascii_face
;
26768 boff
= font
->baseline_offset
;
26769 if (font
->vertical_centering
)
26770 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26771 font_ascent
= FONT_BASE (font
) + boff
;
26772 font_descent
= FONT_DESCENT (font
) - boff
;
26773 font_height
= FONT_HEIGHT (font
);
26778 if (! font_not_found_p
)
26780 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
26782 pcm
= get_per_char_metric (font
, &char2b
);
26785 /* Initialize the bounding box. */
26788 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
26789 ascent
= pcm
->ascent
;
26790 descent
= pcm
->descent
;
26791 lbearing
= pcm
->lbearing
;
26792 rbearing
= pcm
->rbearing
;
26796 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
26797 ascent
= FONT_BASE (font
);
26798 descent
= FONT_DESCENT (font
);
26805 lowest
= - descent
+ boff
;
26806 highest
= ascent
+ boff
;
26808 if (! font_not_found_p
26809 && font
->default_ascent
26810 && CHAR_TABLE_P (Vuse_default_ascent
)
26811 && !NILP (Faref (Vuse_default_ascent
,
26812 make_number (it
->char_to_display
))))
26813 highest
= font
->default_ascent
+ boff
;
26815 /* Draw the first glyph at the normal position. It may be
26816 shifted to right later if some other glyphs are drawn
26818 cmp
->offsets
[i
* 2] = 0;
26819 cmp
->offsets
[i
* 2 + 1] = boff
;
26820 cmp
->lbearing
= lbearing
;
26821 cmp
->rbearing
= rbearing
;
26823 /* Set cmp->offsets for the remaining glyphs. */
26824 for (i
++; i
< glyph_len
; i
++)
26826 int left
, right
, btm
, top
;
26827 int ch
= COMPOSITION_GLYPH (cmp
, i
);
26829 struct face
*this_face
;
26833 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
26834 this_face
= FACE_FROM_ID (it
->f
, face_id
);
26835 font
= this_face
->font
;
26841 get_char_face_and_encoding (it
->f
, ch
, face_id
,
26843 pcm
= get_per_char_metric (font
, &char2b
);
26846 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
26849 width
= pcm
->width
;
26850 ascent
= pcm
->ascent
;
26851 descent
= pcm
->descent
;
26852 lbearing
= pcm
->lbearing
;
26853 rbearing
= pcm
->rbearing
;
26854 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
26856 /* Relative composition with or without
26857 alternate chars. */
26858 left
= (leftmost
+ rightmost
- width
) / 2;
26859 btm
= - descent
+ boff
;
26860 if (font
->relative_compose
26861 && (! CHAR_TABLE_P (Vignore_relative_composition
)
26862 || NILP (Faref (Vignore_relative_composition
,
26863 make_number (ch
)))))
26866 if (- descent
>= font
->relative_compose
)
26867 /* One extra pixel between two glyphs. */
26869 else if (ascent
<= 0)
26870 /* One extra pixel between two glyphs. */
26871 btm
= lowest
- 1 - ascent
- descent
;
26876 /* A composition rule is specified by an integer
26877 value that encodes global and new reference
26878 points (GREF and NREF). GREF and NREF are
26879 specified by numbers as below:
26881 0---1---2 -- ascent
26885 9--10--11 -- center
26887 ---3---4---5--- baseline
26889 6---7---8 -- descent
26891 int rule
= COMPOSITION_RULE (cmp
, i
);
26892 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
26894 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
26895 grefx
= gref
% 3, nrefx
= nref
% 3;
26896 grefy
= gref
/ 3, nrefy
= nref
/ 3;
26898 xoff
= font_height
* (xoff
- 128) / 256;
26900 yoff
= font_height
* (yoff
- 128) / 256;
26903 + grefx
* (rightmost
- leftmost
) / 2
26904 - nrefx
* width
/ 2
26907 btm
= ((grefy
== 0 ? highest
26909 : grefy
== 2 ? lowest
26910 : (highest
+ lowest
) / 2)
26911 - (nrefy
== 0 ? ascent
+ descent
26912 : nrefy
== 1 ? descent
- boff
26914 : (ascent
+ descent
) / 2)
26918 cmp
->offsets
[i
* 2] = left
;
26919 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
26921 /* Update the bounding box of the overall glyphs. */
26924 right
= left
+ width
;
26925 if (left
< leftmost
)
26927 if (right
> rightmost
)
26930 top
= btm
+ descent
+ ascent
;
26936 if (cmp
->lbearing
> left
+ lbearing
)
26937 cmp
->lbearing
= left
+ lbearing
;
26938 if (cmp
->rbearing
< left
+ rbearing
)
26939 cmp
->rbearing
= left
+ rbearing
;
26943 /* If there are glyphs whose x-offsets are negative,
26944 shift all glyphs to the right and make all x-offsets
26948 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26949 cmp
->offsets
[i
* 2] -= leftmost
;
26950 rightmost
-= leftmost
;
26951 cmp
->lbearing
-= leftmost
;
26952 cmp
->rbearing
-= leftmost
;
26955 if (left_padded
&& cmp
->lbearing
< 0)
26957 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26958 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
26959 rightmost
-= cmp
->lbearing
;
26960 cmp
->rbearing
-= cmp
->lbearing
;
26963 if (right_padded
&& rightmost
< cmp
->rbearing
)
26965 rightmost
= cmp
->rbearing
;
26968 cmp
->pixel_width
= rightmost
;
26969 cmp
->ascent
= highest
;
26970 cmp
->descent
= - lowest
;
26971 if (cmp
->ascent
< font_ascent
)
26972 cmp
->ascent
= font_ascent
;
26973 if (cmp
->descent
< font_descent
)
26974 cmp
->descent
= font_descent
;
26978 && (cmp
->lbearing
< 0
26979 || cmp
->rbearing
> cmp
->pixel_width
))
26980 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
26982 it
->pixel_width
= cmp
->pixel_width
;
26983 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
26984 it
->descent
= it
->phys_descent
= cmp
->descent
;
26985 if (face
->box
!= FACE_NO_BOX
)
26987 int thick
= face
->box_line_width
;
26991 it
->ascent
+= thick
;
26992 it
->descent
+= thick
;
26997 if (it
->start_of_box_run_p
)
26998 it
->pixel_width
+= thick
;
26999 if (it
->end_of_box_run_p
)
27000 it
->pixel_width
+= thick
;
27003 /* If face has an overline, add the height of the overline
27004 (1 pixel) and a 1 pixel margin to the character height. */
27005 if (face
->overline_p
)
27006 it
->ascent
+= overline_margin
;
27008 take_vertical_position_into_account (it
);
27009 if (it
->ascent
< 0)
27011 if (it
->descent
< 0)
27014 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
27015 append_composite_glyph (it
);
27017 else if (it
->what
== IT_COMPOSITION
)
27019 /* A dynamic (automatic) composition. */
27020 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27021 Lisp_Object gstring
;
27022 struct font_metrics metrics
;
27026 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
27028 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
27031 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
27032 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27033 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
27034 it
->descent
= it
->phys_descent
= metrics
.descent
;
27035 if (face
->box
!= FACE_NO_BOX
)
27037 int thick
= face
->box_line_width
;
27041 it
->ascent
+= thick
;
27042 it
->descent
+= thick
;
27047 if (it
->start_of_box_run_p
)
27048 it
->pixel_width
+= thick
;
27049 if (it
->end_of_box_run_p
)
27050 it
->pixel_width
+= thick
;
27052 /* If face has an overline, add the height of the overline
27053 (1 pixel) and a 1 pixel margin to the character height. */
27054 if (face
->overline_p
)
27055 it
->ascent
+= overline_margin
;
27056 take_vertical_position_into_account (it
);
27057 if (it
->ascent
< 0)
27059 if (it
->descent
< 0)
27063 append_composite_glyph (it
);
27065 else if (it
->what
== IT_GLYPHLESS
)
27066 produce_glyphless_glyph (it
, false, Qnil
);
27067 else if (it
->what
== IT_IMAGE
)
27068 produce_image_glyph (it
);
27069 else if (it
->what
== IT_STRETCH
)
27070 produce_stretch_glyph (it
);
27073 /* Accumulate dimensions. Note: can't assume that it->descent > 0
27074 because this isn't true for images with `:ascent 100'. */
27075 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
27076 if (it
->area
== TEXT_AREA
)
27077 it
->current_x
+= it
->pixel_width
;
27079 if (extra_line_spacing
> 0)
27081 it
->descent
+= extra_line_spacing
;
27082 if (extra_line_spacing
> it
->max_extra_line_spacing
)
27083 it
->max_extra_line_spacing
= extra_line_spacing
;
27086 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
27087 it
->max_descent
= max (it
->max_descent
, it
->descent
);
27088 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
27089 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
27093 Output LEN glyphs starting at START at the nominal cursor position.
27094 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
27095 being updated, and UPDATED_AREA is the area of that row being updated. */
27098 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27099 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27101 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
27103 eassert (updated_row
);
27104 /* When the window is hscrolled, cursor hpos can legitimately be out
27105 of bounds, but we draw the cursor at the corresponding window
27106 margin in that case. */
27107 if (!updated_row
->reversed_p
&& chpos
< 0)
27109 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
27110 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
27114 /* Write glyphs. */
27116 hpos
= start
- updated_row
->glyphs
[updated_area
];
27117 x
= draw_glyphs (w
, w
->output_cursor
.x
,
27118 updated_row
, updated_area
,
27120 DRAW_NORMAL_TEXT
, 0);
27122 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
27123 if (updated_area
== TEXT_AREA
27124 && w
->phys_cursor_on_p
27125 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
27127 && chpos
< hpos
+ len
)
27128 w
->phys_cursor_on_p
= false;
27132 /* Advance the output cursor. */
27133 w
->output_cursor
.hpos
+= len
;
27134 w
->output_cursor
.x
= x
;
27139 Insert LEN glyphs from START at the nominal cursor position. */
27142 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27143 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27146 int line_height
, shift_by_width
, shifted_region_width
;
27147 struct glyph_row
*row
;
27148 struct glyph
*glyph
;
27149 int frame_x
, frame_y
;
27152 eassert (updated_row
);
27154 f
= XFRAME (WINDOW_FRAME (w
));
27156 /* Get the height of the line we are in. */
27158 line_height
= row
->height
;
27160 /* Get the width of the glyphs to insert. */
27161 shift_by_width
= 0;
27162 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
27163 shift_by_width
+= glyph
->pixel_width
;
27165 /* Get the width of the region to shift right. */
27166 shifted_region_width
= (window_box_width (w
, updated_area
)
27167 - w
->output_cursor
.x
27171 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
27172 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
27174 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
27175 line_height
, shift_by_width
);
27177 /* Write the glyphs. */
27178 hpos
= start
- row
->glyphs
[updated_area
];
27179 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
27181 DRAW_NORMAL_TEXT
, 0);
27183 /* Advance the output cursor. */
27184 w
->output_cursor
.hpos
+= len
;
27185 w
->output_cursor
.x
+= shift_by_width
;
27191 Erase the current text line from the nominal cursor position
27192 (inclusive) to pixel column TO_X (exclusive). The idea is that
27193 everything from TO_X onward is already erased.
27195 TO_X is a pixel position relative to UPDATED_AREA of currently
27196 updated window W. TO_X == -1 means clear to the end of this area. */
27199 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
27200 enum glyph_row_area updated_area
, int to_x
)
27203 int max_x
, min_y
, max_y
;
27204 int from_x
, from_y
, to_y
;
27206 eassert (updated_row
);
27207 f
= XFRAME (w
->frame
);
27209 if (updated_row
->full_width_p
)
27210 max_x
= (WINDOW_PIXEL_WIDTH (w
)
27211 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
27213 max_x
= window_box_width (w
, updated_area
);
27214 max_y
= window_text_bottom_y (w
);
27216 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
27217 of window. For TO_X > 0, truncate to end of drawing area. */
27223 to_x
= min (to_x
, max_x
);
27225 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
27227 /* Notice if the cursor will be cleared by this operation. */
27228 if (!updated_row
->full_width_p
)
27229 notice_overwritten_cursor (w
, updated_area
,
27230 w
->output_cursor
.x
, -1,
27232 MATRIX_ROW_BOTTOM_Y (updated_row
));
27234 from_x
= w
->output_cursor
.x
;
27236 /* Translate to frame coordinates. */
27237 if (updated_row
->full_width_p
)
27239 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
27240 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
27244 int area_left
= window_box_left (w
, updated_area
);
27245 from_x
+= area_left
;
27249 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
27250 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
27251 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
27253 /* Prevent inadvertently clearing to end of the X window. */
27254 if (to_x
> from_x
&& to_y
> from_y
)
27257 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
27258 to_x
- from_x
, to_y
- from_y
);
27263 #endif /* HAVE_WINDOW_SYSTEM */
27267 /***********************************************************************
27269 ***********************************************************************/
27271 /* Value is the internal representation of the specified cursor type
27272 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
27273 of the bar cursor. */
27275 static enum text_cursor_kinds
27276 get_specified_cursor_type (Lisp_Object arg
, int *width
)
27278 enum text_cursor_kinds type
;
27283 if (EQ (arg
, Qbox
))
27284 return FILLED_BOX_CURSOR
;
27286 if (EQ (arg
, Qhollow
))
27287 return HOLLOW_BOX_CURSOR
;
27289 if (EQ (arg
, Qbar
))
27296 && EQ (XCAR (arg
), Qbar
)
27297 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27299 *width
= XINT (XCDR (arg
));
27303 if (EQ (arg
, Qhbar
))
27306 return HBAR_CURSOR
;
27310 && EQ (XCAR (arg
), Qhbar
)
27311 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27313 *width
= XINT (XCDR (arg
));
27314 return HBAR_CURSOR
;
27317 /* Treat anything unknown as "hollow box cursor".
27318 It was bad to signal an error; people have trouble fixing
27319 .Xdefaults with Emacs, when it has something bad in it. */
27320 type
= HOLLOW_BOX_CURSOR
;
27325 /* Set the default cursor types for specified frame. */
27327 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
27332 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
27333 FRAME_CURSOR_WIDTH (f
) = width
;
27335 /* By default, set up the blink-off state depending on the on-state. */
27337 tem
= Fassoc (arg
, Vblink_cursor_alist
);
27340 FRAME_BLINK_OFF_CURSOR (f
)
27341 = get_specified_cursor_type (XCDR (tem
), &width
);
27342 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
27345 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
27347 /* Make sure the cursor gets redrawn. */
27348 f
->cursor_type_changed
= true;
27352 #ifdef HAVE_WINDOW_SYSTEM
27354 /* Return the cursor we want to be displayed in window W. Return
27355 width of bar/hbar cursor through WIDTH arg. Return with
27356 ACTIVE_CURSOR arg set to true if cursor in window W is `active'
27357 (i.e. if the `system caret' should track this cursor).
27359 In a mini-buffer window, we want the cursor only to appear if we
27360 are reading input from this window. For the selected window, we
27361 want the cursor type given by the frame parameter or buffer local
27362 setting of cursor-type. If explicitly marked off, draw no cursor.
27363 In all other cases, we want a hollow box cursor. */
27365 static enum text_cursor_kinds
27366 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
27367 bool *active_cursor
)
27369 struct frame
*f
= XFRAME (w
->frame
);
27370 struct buffer
*b
= XBUFFER (w
->contents
);
27371 int cursor_type
= DEFAULT_CURSOR
;
27372 Lisp_Object alt_cursor
;
27373 bool non_selected
= false;
27375 *active_cursor
= true;
27378 if (cursor_in_echo_area
27379 && FRAME_HAS_MINIBUF_P (f
)
27380 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
27382 if (w
== XWINDOW (echo_area_window
))
27384 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
27386 *width
= FRAME_CURSOR_WIDTH (f
);
27387 return FRAME_DESIRED_CURSOR (f
);
27390 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27393 *active_cursor
= false;
27394 non_selected
= true;
27397 /* Detect a nonselected window or nonselected frame. */
27398 else if (w
!= XWINDOW (f
->selected_window
)
27399 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
27401 *active_cursor
= false;
27403 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
27406 non_selected
= true;
27409 /* Never display a cursor in a window in which cursor-type is nil. */
27410 if (NILP (BVAR (b
, cursor_type
)))
27413 /* Get the normal cursor type for this window. */
27414 if (EQ (BVAR (b
, cursor_type
), Qt
))
27416 cursor_type
= FRAME_DESIRED_CURSOR (f
);
27417 *width
= FRAME_CURSOR_WIDTH (f
);
27420 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27422 /* Use cursor-in-non-selected-windows instead
27423 for non-selected window or frame. */
27426 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
27427 if (!EQ (Qt
, alt_cursor
))
27428 return get_specified_cursor_type (alt_cursor
, width
);
27429 /* t means modify the normal cursor type. */
27430 if (cursor_type
== FILLED_BOX_CURSOR
)
27431 cursor_type
= HOLLOW_BOX_CURSOR
;
27432 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
27434 return cursor_type
;
27437 /* Use normal cursor if not blinked off. */
27438 if (!w
->cursor_off_p
)
27440 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27442 if (cursor_type
== FILLED_BOX_CURSOR
)
27444 /* Using a block cursor on large images can be very annoying.
27445 So use a hollow cursor for "large" images.
27446 If image is not transparent (no mask), also use hollow cursor. */
27447 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27448 if (img
!= NULL
&& IMAGEP (img
->spec
))
27450 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
27451 where N = size of default frame font size.
27452 This should cover most of the "tiny" icons people may use. */
27454 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
27455 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
27456 cursor_type
= HOLLOW_BOX_CURSOR
;
27459 else if (cursor_type
!= NO_CURSOR
)
27461 /* Display current only supports BOX and HOLLOW cursors for images.
27462 So for now, unconditionally use a HOLLOW cursor when cursor is
27463 not a solid box cursor. */
27464 cursor_type
= HOLLOW_BOX_CURSOR
;
27467 return cursor_type
;
27470 /* Cursor is blinked off, so determine how to "toggle" it. */
27472 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
27473 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
27474 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
27476 /* Then see if frame has specified a specific blink off cursor type. */
27477 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
27479 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
27480 return FRAME_BLINK_OFF_CURSOR (f
);
27484 /* Some people liked having a permanently visible blinking cursor,
27485 while others had very strong opinions against it. So it was
27486 decided to remove it. KFS 2003-09-03 */
27488 /* Finally perform built-in cursor blinking:
27489 filled box <-> hollow box
27490 wide [h]bar <-> narrow [h]bar
27491 narrow [h]bar <-> no cursor
27492 other type <-> no cursor */
27494 if (cursor_type
== FILLED_BOX_CURSOR
)
27495 return HOLLOW_BOX_CURSOR
;
27497 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
27500 return cursor_type
;
27508 /* Notice when the text cursor of window W has been completely
27509 overwritten by a drawing operation that outputs glyphs in AREA
27510 starting at X0 and ending at X1 in the line starting at Y0 and
27511 ending at Y1. X coordinates are area-relative. X1 < 0 means all
27512 the rest of the line after X0 has been written. Y coordinates
27513 are window-relative. */
27516 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
27517 int x0
, int x1
, int y0
, int y1
)
27519 int cx0
, cx1
, cy0
, cy1
;
27520 struct glyph_row
*row
;
27522 if (!w
->phys_cursor_on_p
)
27524 if (area
!= TEXT_AREA
)
27527 if (w
->phys_cursor
.vpos
< 0
27528 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
27529 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
27530 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
27533 if (row
->cursor_in_fringe_p
)
27535 row
->cursor_in_fringe_p
= false;
27536 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
27537 w
->phys_cursor_on_p
= false;
27541 cx0
= w
->phys_cursor
.x
;
27542 cx1
= cx0
+ w
->phys_cursor_width
;
27543 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
27546 /* The cursor image will be completely removed from the
27547 screen if the output area intersects the cursor area in
27548 y-direction. When we draw in [y0 y1[, and some part of
27549 the cursor is at y < y0, that part must have been drawn
27550 before. When scrolling, the cursor is erased before
27551 actually scrolling, so we don't come here. When not
27552 scrolling, the rows above the old cursor row must have
27553 changed, and in this case these rows must have written
27554 over the cursor image.
27556 Likewise if part of the cursor is below y1, with the
27557 exception of the cursor being in the first blank row at
27558 the buffer and window end because update_text_area
27559 doesn't draw that row. (Except when it does, but
27560 that's handled in update_text_area.) */
27562 cy0
= w
->phys_cursor
.y
;
27563 cy1
= cy0
+ w
->phys_cursor_height
;
27564 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
27567 w
->phys_cursor_on_p
= false;
27570 #endif /* HAVE_WINDOW_SYSTEM */
27573 /************************************************************************
27575 ************************************************************************/
27577 #ifdef HAVE_WINDOW_SYSTEM
27580 Fix the display of area AREA of overlapping row ROW in window W
27581 with respect to the overlapping part OVERLAPS. */
27584 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
27585 enum glyph_row_area area
, int overlaps
)
27592 for (i
= 0; i
< row
->used
[area
];)
27594 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
27596 int start
= i
, start_x
= x
;
27600 x
+= row
->glyphs
[area
][i
].pixel_width
;
27603 while (i
< row
->used
[area
]
27604 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
27606 draw_glyphs (w
, start_x
, row
, area
,
27608 DRAW_NORMAL_TEXT
, overlaps
);
27612 x
+= row
->glyphs
[area
][i
].pixel_width
;
27622 Draw the cursor glyph of window W in glyph row ROW. See the
27623 comment of draw_glyphs for the meaning of HL. */
27626 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
27627 enum draw_glyphs_face hl
)
27629 /* If cursor hpos is out of bounds, don't draw garbage. This can
27630 happen in mini-buffer windows when switching between echo area
27631 glyphs and mini-buffer. */
27632 if ((row
->reversed_p
27633 ? (w
->phys_cursor
.hpos
>= 0)
27634 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
27636 bool on_p
= w
->phys_cursor_on_p
;
27638 int hpos
= w
->phys_cursor
.hpos
;
27640 /* When the window is hscrolled, cursor hpos can legitimately be
27641 out of bounds, but we draw the cursor at the corresponding
27642 window margin in that case. */
27643 if (!row
->reversed_p
&& hpos
< 0)
27645 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27646 hpos
= row
->used
[TEXT_AREA
] - 1;
27648 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
27650 w
->phys_cursor_on_p
= on_p
;
27652 if (hl
== DRAW_CURSOR
)
27653 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
27654 /* When we erase the cursor, and ROW is overlapped by other
27655 rows, make sure that these overlapping parts of other rows
27657 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
27659 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
27661 if (row
> w
->current_matrix
->rows
27662 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
27663 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
27664 OVERLAPS_ERASED_CURSOR
);
27666 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
27667 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
27668 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
27669 OVERLAPS_ERASED_CURSOR
);
27675 /* Erase the image of a cursor of window W from the screen. */
27678 erase_phys_cursor (struct window
*w
)
27680 struct frame
*f
= XFRAME (w
->frame
);
27681 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27682 int hpos
= w
->phys_cursor
.hpos
;
27683 int vpos
= w
->phys_cursor
.vpos
;
27684 bool mouse_face_here_p
= false;
27685 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
27686 struct glyph_row
*cursor_row
;
27687 struct glyph
*cursor_glyph
;
27688 enum draw_glyphs_face hl
;
27690 /* No cursor displayed or row invalidated => nothing to do on the
27692 if (w
->phys_cursor_type
== NO_CURSOR
)
27693 goto mark_cursor_off
;
27695 /* VPOS >= active_glyphs->nrows means that window has been resized.
27696 Don't bother to erase the cursor. */
27697 if (vpos
>= active_glyphs
->nrows
)
27698 goto mark_cursor_off
;
27700 /* If row containing cursor is marked invalid, there is nothing we
27702 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
27703 if (!cursor_row
->enabled_p
)
27704 goto mark_cursor_off
;
27706 /* If line spacing is > 0, old cursor may only be partially visible in
27707 window after split-window. So adjust visible height. */
27708 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
27709 window_text_bottom_y (w
) - cursor_row
->y
);
27711 /* If row is completely invisible, don't attempt to delete a cursor which
27712 isn't there. This can happen if cursor is at top of a window, and
27713 we switch to a buffer with a header line in that window. */
27714 if (cursor_row
->visible_height
<= 0)
27715 goto mark_cursor_off
;
27717 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
27718 if (cursor_row
->cursor_in_fringe_p
)
27720 cursor_row
->cursor_in_fringe_p
= false;
27721 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
27722 goto mark_cursor_off
;
27725 /* This can happen when the new row is shorter than the old one.
27726 In this case, either draw_glyphs or clear_end_of_line
27727 should have cleared the cursor. Note that we wouldn't be
27728 able to erase the cursor in this case because we don't have a
27729 cursor glyph at hand. */
27730 if ((cursor_row
->reversed_p
27731 ? (w
->phys_cursor
.hpos
< 0)
27732 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
27733 goto mark_cursor_off
;
27735 /* When the window is hscrolled, cursor hpos can legitimately be out
27736 of bounds, but we draw the cursor at the corresponding window
27737 margin in that case. */
27738 if (!cursor_row
->reversed_p
&& hpos
< 0)
27740 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
27741 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
27743 /* If the cursor is in the mouse face area, redisplay that when
27744 we clear the cursor. */
27745 if (! NILP (hlinfo
->mouse_face_window
)
27746 && coords_in_mouse_face_p (w
, hpos
, vpos
)
27747 /* Don't redraw the cursor's spot in mouse face if it is at the
27748 end of a line (on a newline). The cursor appears there, but
27749 mouse highlighting does not. */
27750 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
27751 mouse_face_here_p
= true;
27753 /* Maybe clear the display under the cursor. */
27754 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
27757 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
27760 cursor_glyph
= get_phys_cursor_glyph (w
);
27761 if (cursor_glyph
== NULL
)
27762 goto mark_cursor_off
;
27764 width
= cursor_glyph
->pixel_width
;
27765 x
= w
->phys_cursor
.x
;
27771 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
27772 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
27773 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
27776 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
27779 /* Erase the cursor by redrawing the character underneath it. */
27780 if (mouse_face_here_p
)
27781 hl
= DRAW_MOUSE_FACE
;
27783 hl
= DRAW_NORMAL_TEXT
;
27784 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
27787 w
->phys_cursor_on_p
= false;
27788 w
->phys_cursor_type
= NO_CURSOR
;
27792 /* Display or clear cursor of window W. If !ON, clear the cursor.
27793 If ON, display the cursor; where to put the cursor is specified by
27794 HPOS, VPOS, X and Y. */
27797 display_and_set_cursor (struct window
*w
, bool on
,
27798 int hpos
, int vpos
, int x
, int y
)
27800 struct frame
*f
= XFRAME (w
->frame
);
27801 int new_cursor_type
;
27802 int new_cursor_width
;
27803 bool active_cursor
;
27804 struct glyph_row
*glyph_row
;
27805 struct glyph
*glyph
;
27807 /* This is pointless on invisible frames, and dangerous on garbaged
27808 windows and frames; in the latter case, the frame or window may
27809 be in the midst of changing its size, and x and y may be off the
27811 if (! FRAME_VISIBLE_P (f
)
27812 || FRAME_GARBAGED_P (f
)
27813 || vpos
>= w
->current_matrix
->nrows
27814 || hpos
>= w
->current_matrix
->matrix_w
)
27817 /* If cursor is off and we want it off, return quickly. */
27818 if (!on
&& !w
->phys_cursor_on_p
)
27821 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27822 /* If cursor row is not enabled, we don't really know where to
27823 display the cursor. */
27824 if (!glyph_row
->enabled_p
)
27826 w
->phys_cursor_on_p
= false;
27831 if (!glyph_row
->exact_window_width_line_p
27832 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
27833 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
27835 eassert (input_blocked_p ());
27837 /* Set new_cursor_type to the cursor we want to be displayed. */
27838 new_cursor_type
= get_window_cursor_type (w
, glyph
,
27839 &new_cursor_width
, &active_cursor
);
27841 /* If cursor is currently being shown and we don't want it to be or
27842 it is in the wrong place, or the cursor type is not what we want,
27844 if (w
->phys_cursor_on_p
27846 || w
->phys_cursor
.x
!= x
27847 || w
->phys_cursor
.y
!= y
27848 /* HPOS can be negative in R2L rows whose
27849 exact_window_width_line_p flag is set (i.e. their newline
27850 would "overflow into the fringe"). */
27852 || new_cursor_type
!= w
->phys_cursor_type
27853 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
27854 && new_cursor_width
!= w
->phys_cursor_width
)))
27855 erase_phys_cursor (w
);
27857 /* Don't check phys_cursor_on_p here because that flag is only set
27858 to false in some cases where we know that the cursor has been
27859 completely erased, to avoid the extra work of erasing the cursor
27860 twice. In other words, phys_cursor_on_p can be true and the cursor
27861 still not be visible, or it has only been partly erased. */
27864 w
->phys_cursor_ascent
= glyph_row
->ascent
;
27865 w
->phys_cursor_height
= glyph_row
->height
;
27867 /* Set phys_cursor_.* before x_draw_.* is called because some
27868 of them may need the information. */
27869 w
->phys_cursor
.x
= x
;
27870 w
->phys_cursor
.y
= glyph_row
->y
;
27871 w
->phys_cursor
.hpos
= hpos
;
27872 w
->phys_cursor
.vpos
= vpos
;
27875 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
27876 new_cursor_type
, new_cursor_width
,
27877 on
, active_cursor
);
27881 /* Switch the display of W's cursor on or off, according to the value
27885 update_window_cursor (struct window
*w
, bool on
)
27887 /* Don't update cursor in windows whose frame is in the process
27888 of being deleted. */
27889 if (w
->current_matrix
)
27891 int hpos
= w
->phys_cursor
.hpos
;
27892 int vpos
= w
->phys_cursor
.vpos
;
27893 struct glyph_row
*row
;
27895 if (vpos
>= w
->current_matrix
->nrows
27896 || hpos
>= w
->current_matrix
->matrix_w
)
27899 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27901 /* When the window is hscrolled, cursor hpos can legitimately be
27902 out of bounds, but we draw the cursor at the corresponding
27903 window margin in that case. */
27904 if (!row
->reversed_p
&& hpos
< 0)
27906 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27907 hpos
= row
->used
[TEXT_AREA
] - 1;
27910 display_and_set_cursor (w
, on
, hpos
, vpos
,
27911 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27917 /* Call update_window_cursor with parameter ON_P on all leaf windows
27918 in the window tree rooted at W. */
27921 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
27925 if (WINDOWP (w
->contents
))
27926 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
27928 update_window_cursor (w
, on_p
);
27930 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
27936 Display the cursor on window W, or clear it, according to ON_P.
27937 Don't change the cursor's position. */
27940 x_update_cursor (struct frame
*f
, bool on_p
)
27942 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
27947 Clear the cursor of window W to background color, and mark the
27948 cursor as not shown. This is used when the text where the cursor
27949 is about to be rewritten. */
27952 x_clear_cursor (struct window
*w
)
27954 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
27955 update_window_cursor (w
, false);
27958 #endif /* HAVE_WINDOW_SYSTEM */
27960 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
27963 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
27964 int start_hpos
, int end_hpos
,
27965 enum draw_glyphs_face draw
)
27967 #ifdef HAVE_WINDOW_SYSTEM
27968 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
27970 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
27974 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
27975 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
27979 /* Display the active region described by mouse_face_* according to DRAW. */
27982 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
27984 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
27985 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27987 if (/* If window is in the process of being destroyed, don't bother
27989 w
->current_matrix
!= NULL
27990 /* Don't update mouse highlight if hidden. */
27991 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
27992 /* Recognize when we are called to operate on rows that don't exist
27993 anymore. This can happen when a window is split. */
27994 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
27996 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
27997 struct glyph_row
*row
, *first
, *last
;
27999 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
28000 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
28002 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
28004 int start_hpos
, end_hpos
, start_x
;
28006 /* For all but the first row, the highlight starts at column 0. */
28009 /* R2L rows have BEG and END in reversed order, but the
28010 screen drawing geometry is always left to right. So
28011 we need to mirror the beginning and end of the
28012 highlighted area in R2L rows. */
28013 if (!row
->reversed_p
)
28015 start_hpos
= hlinfo
->mouse_face_beg_col
;
28016 start_x
= hlinfo
->mouse_face_beg_x
;
28018 else if (row
== last
)
28020 start_hpos
= hlinfo
->mouse_face_end_col
;
28021 start_x
= hlinfo
->mouse_face_end_x
;
28029 else if (row
->reversed_p
&& row
== last
)
28031 start_hpos
= hlinfo
->mouse_face_end_col
;
28032 start_x
= hlinfo
->mouse_face_end_x
;
28042 if (!row
->reversed_p
)
28043 end_hpos
= hlinfo
->mouse_face_end_col
;
28044 else if (row
== first
)
28045 end_hpos
= hlinfo
->mouse_face_beg_col
;
28048 end_hpos
= row
->used
[TEXT_AREA
];
28049 if (draw
== DRAW_NORMAL_TEXT
)
28050 row
->fill_line_p
= true; /* Clear to end of line. */
28053 else if (row
->reversed_p
&& row
== first
)
28054 end_hpos
= hlinfo
->mouse_face_beg_col
;
28057 end_hpos
= row
->used
[TEXT_AREA
];
28058 if (draw
== DRAW_NORMAL_TEXT
)
28059 row
->fill_line_p
= true; /* Clear to end of line. */
28062 if (end_hpos
> start_hpos
)
28064 draw_row_with_mouse_face (w
, start_x
, row
,
28065 start_hpos
, end_hpos
, draw
);
28068 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
28072 #ifdef HAVE_WINDOW_SYSTEM
28073 /* When we've written over the cursor, arrange for it to
28074 be displayed again. */
28075 if (FRAME_WINDOW_P (f
)
28076 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
28078 int hpos
= w
->phys_cursor
.hpos
;
28080 /* When the window is hscrolled, cursor hpos can legitimately be
28081 out of bounds, but we draw the cursor at the corresponding
28082 window margin in that case. */
28083 if (!row
->reversed_p
&& hpos
< 0)
28085 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28086 hpos
= row
->used
[TEXT_AREA
] - 1;
28089 display_and_set_cursor (w
, true, hpos
, w
->phys_cursor
.vpos
,
28090 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28093 #endif /* HAVE_WINDOW_SYSTEM */
28096 #ifdef HAVE_WINDOW_SYSTEM
28097 /* Change the mouse cursor. */
28098 if (FRAME_WINDOW_P (f
) && NILP (do_mouse_tracking
))
28100 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
28101 if (draw
== DRAW_NORMAL_TEXT
28102 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
28103 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
28106 if (draw
== DRAW_MOUSE_FACE
)
28107 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
28109 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
28111 #endif /* HAVE_WINDOW_SYSTEM */
28115 Clear out the mouse-highlighted active region.
28116 Redraw it un-highlighted first. Value is true if mouse
28117 face was actually drawn unhighlighted. */
28120 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
28123 = !hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
);
28125 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
28126 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28127 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28128 hlinfo
->mouse_face_window
= Qnil
;
28129 hlinfo
->mouse_face_overlay
= Qnil
;
28133 /* Return true if the coordinates HPOS and VPOS on windows W are
28134 within the mouse face on that window. */
28136 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
28138 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28140 /* Quickly resolve the easy cases. */
28141 if (!(WINDOWP (hlinfo
->mouse_face_window
)
28142 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
28144 if (vpos
< hlinfo
->mouse_face_beg_row
28145 || vpos
> hlinfo
->mouse_face_end_row
)
28147 if (vpos
> hlinfo
->mouse_face_beg_row
28148 && vpos
< hlinfo
->mouse_face_end_row
)
28151 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
28153 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28155 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
28158 else if ((vpos
== hlinfo
->mouse_face_beg_row
28159 && hpos
>= hlinfo
->mouse_face_beg_col
)
28160 || (vpos
== hlinfo
->mouse_face_end_row
28161 && hpos
< hlinfo
->mouse_face_end_col
))
28166 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28168 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
28171 else if ((vpos
== hlinfo
->mouse_face_beg_row
28172 && hpos
<= hlinfo
->mouse_face_beg_col
)
28173 || (vpos
== hlinfo
->mouse_face_end_row
28174 && hpos
> hlinfo
->mouse_face_end_col
))
28182 True if physical cursor of window W is within mouse face. */
28185 cursor_in_mouse_face_p (struct window
*w
)
28187 int hpos
= w
->phys_cursor
.hpos
;
28188 int vpos
= w
->phys_cursor
.vpos
;
28189 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28191 /* When the window is hscrolled, cursor hpos can legitimately be out
28192 of bounds, but we draw the cursor at the corresponding window
28193 margin in that case. */
28194 if (!row
->reversed_p
&& hpos
< 0)
28196 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28197 hpos
= row
->used
[TEXT_AREA
] - 1;
28199 return coords_in_mouse_face_p (w
, hpos
, vpos
);
28204 /* Find the glyph rows START_ROW and END_ROW of window W that display
28205 characters between buffer positions START_CHARPOS and END_CHARPOS
28206 (excluding END_CHARPOS). DISP_STRING is a display string that
28207 covers these buffer positions. This is similar to
28208 row_containing_pos, but is more accurate when bidi reordering makes
28209 buffer positions change non-linearly with glyph rows. */
28211 rows_from_pos_range (struct window
*w
,
28212 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
28213 Lisp_Object disp_string
,
28214 struct glyph_row
**start
, struct glyph_row
**end
)
28216 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28217 int last_y
= window_text_bottom_y (w
);
28218 struct glyph_row
*row
;
28223 while (!first
->enabled_p
28224 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
28227 /* Find the START row. */
28229 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
28232 /* A row can potentially be the START row if the range of the
28233 characters it displays intersects the range
28234 [START_CHARPOS..END_CHARPOS). */
28235 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
28236 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
28237 /* See the commentary in row_containing_pos, for the
28238 explanation of the complicated way to check whether
28239 some position is beyond the end of the characters
28240 displayed by a row. */
28241 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28242 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28243 && !row
->ends_at_zv_p
28244 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
28245 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28246 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28247 && !row
->ends_at_zv_p
28248 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
28250 /* Found a candidate row. Now make sure at least one of the
28251 glyphs it displays has a charpos from the range
28252 [START_CHARPOS..END_CHARPOS).
28254 This is not obvious because bidi reordering could make
28255 buffer positions of a row be 1,2,3,102,101,100, and if we
28256 want to highlight characters in [50..60), we don't want
28257 this row, even though [50..60) does intersect [1..103),
28258 the range of character positions given by the row's start
28259 and end positions. */
28260 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
28261 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
28265 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28266 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28267 /* A glyph that comes from DISP_STRING is by
28268 definition to be highlighted. */
28269 || EQ (g
->object
, disp_string
))
28278 /* Find the END row. */
28280 /* If the last row is partially visible, start looking for END
28281 from that row, instead of starting from FIRST. */
28282 && !(row
->enabled_p
28283 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
28285 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
28287 struct glyph_row
*next
= row
+ 1;
28288 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
28290 if (!next
->enabled_p
28291 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
28292 /* The first row >= START whose range of displayed characters
28293 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
28294 is the row END + 1. */
28295 || (start_charpos
< next_start
28296 && end_charpos
< next_start
)
28297 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28298 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28299 && !next
->ends_at_zv_p
28300 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
28301 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28302 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28303 && !next
->ends_at_zv_p
28304 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
28311 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
28312 but none of the characters it displays are in the range, it is
28314 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
28315 struct glyph
*s
= g
;
28316 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
28320 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28321 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28322 /* If the buffer position of the first glyph in
28323 the row is equal to END_CHARPOS, it means
28324 the last character to be highlighted is the
28325 newline of ROW, and we must consider NEXT as
28327 || (((!next
->reversed_p
&& g
== s
)
28328 || (next
->reversed_p
&& g
== e
- 1))
28329 && (g
->charpos
== end_charpos
28330 /* Special case for when NEXT is an
28331 empty line at ZV. */
28332 || (g
->charpos
== -1
28333 && !row
->ends_at_zv_p
28334 && next_start
== end_charpos
)))))
28335 /* A glyph that comes from DISP_STRING is by
28336 definition to be highlighted. */
28337 || EQ (g
->object
, disp_string
))
28346 /* The first row that ends at ZV must be the last to be
28348 else if (next
->ends_at_zv_p
)
28357 /* This function sets the mouse_face_* elements of HLINFO, assuming
28358 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
28359 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
28360 for the overlay or run of text properties specifying the mouse
28361 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
28362 before-string and after-string that must also be highlighted.
28363 DISP_STRING, if non-nil, is a display string that may cover some
28364 or all of the highlighted text. */
28367 mouse_face_from_buffer_pos (Lisp_Object window
,
28368 Mouse_HLInfo
*hlinfo
,
28369 ptrdiff_t mouse_charpos
,
28370 ptrdiff_t start_charpos
,
28371 ptrdiff_t end_charpos
,
28372 Lisp_Object before_string
,
28373 Lisp_Object after_string
,
28374 Lisp_Object disp_string
)
28376 struct window
*w
= XWINDOW (window
);
28377 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28378 struct glyph_row
*r1
, *r2
;
28379 struct glyph
*glyph
, *end
;
28380 ptrdiff_t ignore
, pos
;
28383 eassert (NILP (disp_string
) || STRINGP (disp_string
));
28384 eassert (NILP (before_string
) || STRINGP (before_string
));
28385 eassert (NILP (after_string
) || STRINGP (after_string
));
28387 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
28388 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
28390 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28391 /* If the before-string or display-string contains newlines,
28392 rows_from_pos_range skips to its last row. Move back. */
28393 if (!NILP (before_string
) || !NILP (disp_string
))
28395 struct glyph_row
*prev
;
28396 while ((prev
= r1
- 1, prev
>= first
)
28397 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
28398 && prev
->used
[TEXT_AREA
] > 0)
28400 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
28401 glyph
= beg
+ prev
->used
[TEXT_AREA
];
28402 while (--glyph
>= beg
&& NILP (glyph
->object
));
28404 || !(EQ (glyph
->object
, before_string
)
28405 || EQ (glyph
->object
, disp_string
)))
28412 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28413 hlinfo
->mouse_face_past_end
= true;
28415 else if (!NILP (after_string
))
28417 /* If the after-string has newlines, advance to its last row. */
28418 struct glyph_row
*next
;
28419 struct glyph_row
*last
28420 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28422 for (next
= r2
+ 1;
28424 && next
->used
[TEXT_AREA
] > 0
28425 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
28429 /* The rest of the display engine assumes that mouse_face_beg_row is
28430 either above mouse_face_end_row or identical to it. But with
28431 bidi-reordered continued lines, the row for START_CHARPOS could
28432 be below the row for END_CHARPOS. If so, swap the rows and store
28433 them in correct order. */
28436 struct glyph_row
*tem
= r2
;
28442 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
28443 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
28445 /* For a bidi-reordered row, the positions of BEFORE_STRING,
28446 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
28447 could be anywhere in the row and in any order. The strategy
28448 below is to find the leftmost and the rightmost glyph that
28449 belongs to either of these 3 strings, or whose position is
28450 between START_CHARPOS and END_CHARPOS, and highlight all the
28451 glyphs between those two. This may cover more than just the text
28452 between START_CHARPOS and END_CHARPOS if the range of characters
28453 strides the bidi level boundary, e.g. if the beginning is in R2L
28454 text while the end is in L2R text or vice versa. */
28455 if (!r1
->reversed_p
)
28457 /* This row is in a left to right paragraph. Scan it left to
28459 glyph
= r1
->glyphs
[TEXT_AREA
];
28460 end
= glyph
+ r1
->used
[TEXT_AREA
];
28463 /* Skip truncation glyphs at the start of the glyph row. */
28464 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
28466 && NILP (glyph
->object
)
28467 && glyph
->charpos
< 0;
28469 x
+= glyph
->pixel_width
;
28471 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
28472 or DISP_STRING, and the first glyph from buffer whose
28473 position is between START_CHARPOS and END_CHARPOS. */
28475 && !NILP (glyph
->object
)
28476 && !EQ (glyph
->object
, disp_string
)
28477 && !(BUFFERP (glyph
->object
)
28478 && (glyph
->charpos
>= start_charpos
28479 && glyph
->charpos
< end_charpos
));
28482 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28483 are present at buffer positions between START_CHARPOS and
28484 END_CHARPOS, or if they come from an overlay. */
28485 if (EQ (glyph
->object
, before_string
))
28487 pos
= string_buffer_position (before_string
,
28489 /* If pos == 0, it means before_string came from an
28490 overlay, not from a buffer position. */
28491 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28494 else if (EQ (glyph
->object
, after_string
))
28496 pos
= string_buffer_position (after_string
, end_charpos
);
28497 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28500 x
+= glyph
->pixel_width
;
28502 hlinfo
->mouse_face_beg_x
= x
;
28503 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
28507 /* This row is in a right to left paragraph. Scan it right to
28511 end
= r1
->glyphs
[TEXT_AREA
] - 1;
28512 glyph
= end
+ r1
->used
[TEXT_AREA
];
28514 /* Skip truncation glyphs at the start of the glyph row. */
28515 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
28517 && NILP (glyph
->object
)
28518 && glyph
->charpos
< 0;
28522 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
28523 or DISP_STRING, and the first glyph from buffer whose
28524 position is between START_CHARPOS and END_CHARPOS. */
28526 && !NILP (glyph
->object
)
28527 && !EQ (glyph
->object
, disp_string
)
28528 && !(BUFFERP (glyph
->object
)
28529 && (glyph
->charpos
>= start_charpos
28530 && glyph
->charpos
< end_charpos
));
28533 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28534 are present at buffer positions between START_CHARPOS and
28535 END_CHARPOS, or if they come from an overlay. */
28536 if (EQ (glyph
->object
, before_string
))
28538 pos
= string_buffer_position (before_string
, start_charpos
);
28539 /* If pos == 0, it means before_string came from an
28540 overlay, not from a buffer position. */
28541 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28544 else if (EQ (glyph
->object
, after_string
))
28546 pos
= string_buffer_position (after_string
, end_charpos
);
28547 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28552 glyph
++; /* first glyph to the right of the highlighted area */
28553 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
28554 x
+= g
->pixel_width
;
28555 hlinfo
->mouse_face_beg_x
= x
;
28556 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
28559 /* If the highlight ends in a different row, compute GLYPH and END
28560 for the end row. Otherwise, reuse the values computed above for
28561 the row where the highlight begins. */
28564 if (!r2
->reversed_p
)
28566 glyph
= r2
->glyphs
[TEXT_AREA
];
28567 end
= glyph
+ r2
->used
[TEXT_AREA
];
28572 end
= r2
->glyphs
[TEXT_AREA
] - 1;
28573 glyph
= end
+ r2
->used
[TEXT_AREA
];
28577 if (!r2
->reversed_p
)
28579 /* Skip truncation and continuation glyphs near the end of the
28580 row, and also blanks and stretch glyphs inserted by
28581 extend_face_to_end_of_line. */
28583 && NILP ((end
- 1)->object
))
28585 /* Scan the rest of the glyph row from the end, looking for the
28586 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
28587 DISP_STRING, or whose position is between START_CHARPOS
28591 && !NILP (end
->object
)
28592 && !EQ (end
->object
, disp_string
)
28593 && !(BUFFERP (end
->object
)
28594 && (end
->charpos
>= start_charpos
28595 && end
->charpos
< end_charpos
));
28598 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28599 are present at buffer positions between START_CHARPOS and
28600 END_CHARPOS, or if they come from an overlay. */
28601 if (EQ (end
->object
, before_string
))
28603 pos
= string_buffer_position (before_string
, start_charpos
);
28604 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28607 else if (EQ (end
->object
, after_string
))
28609 pos
= string_buffer_position (after_string
, end_charpos
);
28610 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28614 /* Find the X coordinate of the last glyph to be highlighted. */
28615 for (; glyph
<= end
; ++glyph
)
28616 x
+= glyph
->pixel_width
;
28618 hlinfo
->mouse_face_end_x
= x
;
28619 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
28623 /* Skip truncation and continuation glyphs near the end of the
28624 row, and also blanks and stretch glyphs inserted by
28625 extend_face_to_end_of_line. */
28629 && NILP (end
->object
))
28631 x
+= end
->pixel_width
;
28634 /* Scan the rest of the glyph row from the end, looking for the
28635 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
28636 DISP_STRING, or whose position is between START_CHARPOS
28640 && !NILP (end
->object
)
28641 && !EQ (end
->object
, disp_string
)
28642 && !(BUFFERP (end
->object
)
28643 && (end
->charpos
>= start_charpos
28644 && end
->charpos
< end_charpos
));
28647 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28648 are present at buffer positions between START_CHARPOS and
28649 END_CHARPOS, or if they come from an overlay. */
28650 if (EQ (end
->object
, before_string
))
28652 pos
= string_buffer_position (before_string
, start_charpos
);
28653 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28656 else if (EQ (end
->object
, after_string
))
28658 pos
= string_buffer_position (after_string
, end_charpos
);
28659 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28662 x
+= end
->pixel_width
;
28664 /* If we exited the above loop because we arrived at the last
28665 glyph of the row, and its buffer position is still not in
28666 range, it means the last character in range is the preceding
28667 newline. Bump the end column and x values to get past the
28670 && BUFFERP (end
->object
)
28671 && (end
->charpos
< start_charpos
28672 || end
->charpos
>= end_charpos
))
28674 x
+= end
->pixel_width
;
28677 hlinfo
->mouse_face_end_x
= x
;
28678 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
28681 hlinfo
->mouse_face_window
= window
;
28682 hlinfo
->mouse_face_face_id
28683 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
28685 !hlinfo
->mouse_face_hidden
, -1);
28686 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28689 /* The following function is not used anymore (replaced with
28690 mouse_face_from_string_pos), but I leave it here for the time
28691 being, in case someone would. */
28693 #if false /* not used */
28695 /* Find the position of the glyph for position POS in OBJECT in
28696 window W's current matrix, and return in *X, *Y the pixel
28697 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
28699 RIGHT_P means return the position of the right edge of the glyph.
28700 !RIGHT_P means return the left edge position.
28702 If no glyph for POS exists in the matrix, return the position of
28703 the glyph with the next smaller position that is in the matrix, if
28704 RIGHT_P is false. If RIGHT_P, and no glyph for POS
28705 exists in the matrix, return the position of the glyph with the
28706 next larger position in OBJECT.
28708 Value is true if a glyph was found. */
28711 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
28712 int *hpos
, int *vpos
, int *x
, int *y
, bool right_p
)
28714 int yb
= window_text_bottom_y (w
);
28715 struct glyph_row
*r
;
28716 struct glyph
*best_glyph
= NULL
;
28717 struct glyph_row
*best_row
= NULL
;
28720 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28721 r
->enabled_p
&& r
->y
< yb
;
28724 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
28725 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
28728 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
28729 if (EQ (g
->object
, object
))
28731 if (g
->charpos
== pos
)
28738 else if (best_glyph
== NULL
28739 || ((eabs (g
->charpos
- pos
)
28740 < eabs (best_glyph
->charpos
- pos
))
28743 : g
->charpos
> pos
)))
28757 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
28761 *x
+= best_glyph
->pixel_width
;
28766 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
28769 return best_glyph
!= NULL
;
28771 #endif /* not used */
28773 /* Find the positions of the first and the last glyphs in window W's
28774 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
28775 (assumed to be a string), and return in HLINFO's mouse_face_*
28776 members the pixel and column/row coordinates of those glyphs. */
28779 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
28780 Lisp_Object object
,
28781 ptrdiff_t startpos
, ptrdiff_t endpos
)
28783 int yb
= window_text_bottom_y (w
);
28784 struct glyph_row
*r
;
28785 struct glyph
*g
, *e
;
28787 bool found
= false;
28789 /* Find the glyph row with at least one position in the range
28790 [STARTPOS..ENDPOS), and the first glyph in that row whose
28791 position belongs to that range. */
28792 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28793 r
->enabled_p
&& r
->y
< yb
;
28796 if (!r
->reversed_p
)
28798 g
= r
->glyphs
[TEXT_AREA
];
28799 e
= g
+ r
->used
[TEXT_AREA
];
28800 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
28801 if (EQ (g
->object
, object
)
28802 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
28804 hlinfo
->mouse_face_beg_row
28805 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
28806 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
28807 hlinfo
->mouse_face_beg_x
= gx
;
28816 e
= r
->glyphs
[TEXT_AREA
];
28817 g
= e
+ r
->used
[TEXT_AREA
];
28818 for ( ; g
> e
; --g
)
28819 if (EQ ((g
-1)->object
, object
)
28820 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
28822 hlinfo
->mouse_face_beg_row
28823 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
28824 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
28825 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
28826 gx
+= g1
->pixel_width
;
28827 hlinfo
->mouse_face_beg_x
= gx
;
28839 /* Starting with the next row, look for the first row which does NOT
28840 include any glyphs whose positions are in the range. */
28841 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
28843 g
= r
->glyphs
[TEXT_AREA
];
28844 e
= g
+ r
->used
[TEXT_AREA
];
28846 for ( ; g
< e
; ++g
)
28847 if (EQ (g
->object
, object
)
28848 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
28857 /* The highlighted region ends on the previous row. */
28860 /* Set the end row. */
28861 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
28863 /* Compute and set the end column and the end column's horizontal
28864 pixel coordinate. */
28865 if (!r
->reversed_p
)
28867 g
= r
->glyphs
[TEXT_AREA
];
28868 e
= g
+ r
->used
[TEXT_AREA
];
28869 for ( ; e
> g
; --e
)
28870 if (EQ ((e
-1)->object
, object
)
28871 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
28873 hlinfo
->mouse_face_end_col
= e
- g
;
28875 for (gx
= r
->x
; g
< e
; ++g
)
28876 gx
+= g
->pixel_width
;
28877 hlinfo
->mouse_face_end_x
= gx
;
28881 e
= r
->glyphs
[TEXT_AREA
];
28882 g
= e
+ r
->used
[TEXT_AREA
];
28883 for (gx
= r
->x
; e
< g
; ++e
)
28885 if (EQ (e
->object
, object
)
28886 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
28888 gx
+= e
->pixel_width
;
28890 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
28891 hlinfo
->mouse_face_end_x
= gx
;
28895 #ifdef HAVE_WINDOW_SYSTEM
28897 /* See if position X, Y is within a hot-spot of an image. */
28900 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
28902 if (!CONSP (hot_spot
))
28905 if (EQ (XCAR (hot_spot
), Qrect
))
28907 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
28908 Lisp_Object rect
= XCDR (hot_spot
);
28912 if (!CONSP (XCAR (rect
)))
28914 if (!CONSP (XCDR (rect
)))
28916 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
28918 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
28920 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
28922 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
28926 else if (EQ (XCAR (hot_spot
), Qcircle
))
28928 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
28929 Lisp_Object circ
= XCDR (hot_spot
);
28930 Lisp_Object lr
, lx0
, ly0
;
28932 && CONSP (XCAR (circ
))
28933 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
28934 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
28935 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
28937 double r
= XFLOATINT (lr
);
28938 double dx
= XINT (lx0
) - x
;
28939 double dy
= XINT (ly0
) - y
;
28940 return (dx
* dx
+ dy
* dy
<= r
* r
);
28943 else if (EQ (XCAR (hot_spot
), Qpoly
))
28945 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
28946 if (VECTORP (XCDR (hot_spot
)))
28948 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
28949 Lisp_Object
*poly
= v
->contents
;
28950 ptrdiff_t n
= v
->header
.size
;
28952 bool inside
= false;
28953 Lisp_Object lx
, ly
;
28956 /* Need an even number of coordinates, and at least 3 edges. */
28957 if (n
< 6 || n
& 1)
28960 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
28961 If count is odd, we are inside polygon. Pixels on edges
28962 may or may not be included depending on actual geometry of the
28964 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
28965 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
28967 x0
= XINT (lx
), y0
= XINT (ly
);
28968 for (i
= 0; i
< n
; i
+= 2)
28970 int x1
= x0
, y1
= y0
;
28971 if ((lx
= poly
[i
], !INTEGERP (lx
))
28972 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
28974 x0
= XINT (lx
), y0
= XINT (ly
);
28976 /* Does this segment cross the X line? */
28984 if (y
> y0
&& y
> y1
)
28986 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
28996 find_hot_spot (Lisp_Object map
, int x
, int y
)
28998 while (CONSP (map
))
29000 if (CONSP (XCAR (map
))
29001 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
29009 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
29011 doc
: /* Lookup in image map MAP coordinates X and Y.
29012 An image map is an alist where each element has the format (AREA ID PLIST).
29013 An AREA is specified as either a rectangle, a circle, or a polygon:
29014 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
29015 pixel coordinates of the upper left and bottom right corners.
29016 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
29017 and the radius of the circle; r may be a float or integer.
29018 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
29019 vector describes one corner in the polygon.
29020 Returns the alist element for the first matching AREA in MAP. */)
29021 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
29029 return find_hot_spot (map
,
29030 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
29031 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
29035 /* Display frame CURSOR, optionally using shape defined by POINTER. */
29037 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
29039 /* Do not change cursor shape while dragging mouse. */
29040 if (!NILP (do_mouse_tracking
))
29043 if (!NILP (pointer
))
29045 if (EQ (pointer
, Qarrow
))
29046 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29047 else if (EQ (pointer
, Qhand
))
29048 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
29049 else if (EQ (pointer
, Qtext
))
29050 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
29051 else if (EQ (pointer
, intern ("hdrag")))
29052 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29053 else if (EQ (pointer
, intern ("nhdrag")))
29054 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
29055 #ifdef HAVE_X_WINDOWS
29056 else if (EQ (pointer
, intern ("vdrag")))
29057 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29059 else if (EQ (pointer
, intern ("hourglass")))
29060 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
29061 else if (EQ (pointer
, Qmodeline
))
29062 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
29064 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29067 if (cursor
!= No_Cursor
)
29068 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
29071 #endif /* HAVE_WINDOW_SYSTEM */
29073 /* Take proper action when mouse has moved to the mode or header line
29074 or marginal area AREA of window W, x-position X and y-position Y.
29075 X is relative to the start of the text display area of W, so the
29076 width of bitmap areas and scroll bars must be subtracted to get a
29077 position relative to the start of the mode line. */
29080 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
29081 enum window_part area
)
29083 struct window
*w
= XWINDOW (window
);
29084 struct frame
*f
= XFRAME (w
->frame
);
29085 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29086 #ifdef HAVE_WINDOW_SYSTEM
29087 Display_Info
*dpyinfo
;
29089 Cursor cursor
= No_Cursor
;
29090 Lisp_Object pointer
= Qnil
;
29091 int dx
, dy
, width
, height
;
29093 Lisp_Object string
, object
= Qnil
;
29094 Lisp_Object pos
IF_LINT (= Qnil
), help
;
29096 Lisp_Object mouse_face
;
29097 int original_x_pixel
= x
;
29098 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
29099 struct glyph_row
*row
IF_LINT (= 0);
29101 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
29106 /* Kludge alert: mode_line_string takes X/Y in pixels, but
29107 returns them in row/column units! */
29108 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
29109 &object
, &dx
, &dy
, &width
, &height
);
29111 row
= (area
== ON_MODE_LINE
29112 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
29113 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
29115 /* Find the glyph under the mouse pointer. */
29116 if (row
->mode_line_p
&& row
->enabled_p
)
29118 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
29119 end
= glyph
+ row
->used
[TEXT_AREA
];
29121 for (x0
= original_x_pixel
;
29122 glyph
< end
&& x0
>= glyph
->pixel_width
;
29124 x0
-= glyph
->pixel_width
;
29132 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
29133 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
29134 returns them in row/column units! */
29135 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
29136 &object
, &dx
, &dy
, &width
, &height
);
29141 #ifdef HAVE_WINDOW_SYSTEM
29142 if (IMAGEP (object
))
29144 Lisp_Object image_map
, hotspot
;
29145 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
29147 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
29149 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29153 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
29154 If so, we could look for mouse-enter, mouse-leave
29155 properties in PLIST (and do something...). */
29156 hotspot
= XCDR (hotspot
);
29157 if (CONSP (hotspot
)
29158 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29160 pointer
= Fplist_get (plist
, Qpointer
);
29161 if (NILP (pointer
))
29163 help
= Fplist_get (plist
, Qhelp_echo
);
29166 help_echo_string
= help
;
29167 XSETWINDOW (help_echo_window
, w
);
29168 help_echo_object
= w
->contents
;
29169 help_echo_pos
= charpos
;
29173 if (NILP (pointer
))
29174 pointer
= Fplist_get (XCDR (object
), QCpointer
);
29176 #endif /* HAVE_WINDOW_SYSTEM */
29178 if (STRINGP (string
))
29179 pos
= make_number (charpos
);
29181 /* Set the help text and mouse pointer. If the mouse is on a part
29182 of the mode line without any text (e.g. past the right edge of
29183 the mode line text), use the default help text and pointer. */
29184 if (STRINGP (string
) || area
== ON_MODE_LINE
)
29186 /* Arrange to display the help by setting the global variables
29187 help_echo_string, help_echo_object, and help_echo_pos. */
29190 if (STRINGP (string
))
29191 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
29195 help_echo_string
= help
;
29196 XSETWINDOW (help_echo_window
, w
);
29197 help_echo_object
= string
;
29198 help_echo_pos
= charpos
;
29200 else if (area
== ON_MODE_LINE
)
29202 Lisp_Object default_help
29203 = buffer_local_value (Qmode_line_default_help_echo
,
29206 if (STRINGP (default_help
))
29208 help_echo_string
= default_help
;
29209 XSETWINDOW (help_echo_window
, w
);
29210 help_echo_object
= Qnil
;
29211 help_echo_pos
= -1;
29216 #ifdef HAVE_WINDOW_SYSTEM
29217 /* Change the mouse pointer according to what is under it. */
29218 if (FRAME_WINDOW_P (f
))
29220 bool draggable
= (! WINDOW_BOTTOMMOST_P (w
)
29222 || NILP (Vresize_mini_windows
));
29224 dpyinfo
= FRAME_DISPLAY_INFO (f
);
29225 if (STRINGP (string
))
29227 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29229 if (NILP (pointer
))
29230 pointer
= Fget_text_property (pos
, Qpointer
, string
);
29232 /* Change the mouse pointer according to what is under X/Y. */
29234 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
29237 map
= Fget_text_property (pos
, Qlocal_map
, string
);
29238 if (!KEYMAPP (map
))
29239 map
= Fget_text_property (pos
, Qkeymap
, string
);
29240 if (!KEYMAPP (map
) && draggable
)
29241 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
29244 else if (draggable
)
29245 /* Default mode-line pointer. */
29246 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29251 /* Change the mouse face according to what is under X/Y. */
29252 bool mouse_face_shown
= false;
29253 if (STRINGP (string
))
29255 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
29256 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
29257 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
29262 struct glyph
* tmp_glyph
;
29266 int total_pixel_width
;
29267 ptrdiff_t begpos
, endpos
, ignore
;
29271 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
29272 Qmouse_face
, string
, Qnil
);
29278 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
29280 endpos
= SCHARS (string
);
29284 /* Calculate the glyph position GPOS of GLYPH in the
29285 displayed string, relative to the beginning of the
29286 highlighted part of the string.
29288 Note: GPOS is different from CHARPOS. CHARPOS is the
29289 position of GLYPH in the internal string object. A mode
29290 line string format has structures which are converted to
29291 a flattened string by the Emacs Lisp interpreter. The
29292 internal string is an element of those structures. The
29293 displayed string is the flattened string. */
29294 tmp_glyph
= row_start_glyph
;
29295 while (tmp_glyph
< glyph
29296 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29297 && begpos
<= tmp_glyph
->charpos
29298 && tmp_glyph
->charpos
< endpos
)))
29300 gpos
= glyph
- tmp_glyph
;
29302 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
29303 the highlighted part of the displayed string to which
29304 GLYPH belongs. Note: GSEQ_LENGTH is different from
29305 SCHARS (STRING), because the latter returns the length of
29306 the internal string. */
29307 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
29309 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29310 && begpos
<= tmp_glyph
->charpos
29311 && tmp_glyph
->charpos
< endpos
));
29314 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
29316 /* Calculate the total pixel width of all the glyphs between
29317 the beginning of the highlighted area and GLYPH. */
29318 total_pixel_width
= 0;
29319 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
29320 total_pixel_width
+= tmp_glyph
->pixel_width
;
29322 /* Pre calculation of re-rendering position. Note: X is in
29323 column units here, after the call to mode_line_string or
29324 marginal_area_string. */
29326 vpos
= (area
== ON_MODE_LINE
29327 ? (w
->current_matrix
)->nrows
- 1
29330 /* If GLYPH's position is included in the region that is
29331 already drawn in mouse face, we have nothing to do. */
29332 if ( EQ (window
, hlinfo
->mouse_face_window
)
29333 && (!row
->reversed_p
29334 ? (hlinfo
->mouse_face_beg_col
<= hpos
29335 && hpos
< hlinfo
->mouse_face_end_col
)
29336 /* In R2L rows we swap BEG and END, see below. */
29337 : (hlinfo
->mouse_face_end_col
<= hpos
29338 && hpos
< hlinfo
->mouse_face_beg_col
))
29339 && hlinfo
->mouse_face_beg_row
== vpos
)
29342 if (clear_mouse_face (hlinfo
))
29343 cursor
= No_Cursor
;
29345 if (!row
->reversed_p
)
29347 hlinfo
->mouse_face_beg_col
= hpos
;
29348 hlinfo
->mouse_face_beg_x
= original_x_pixel
29349 - (total_pixel_width
+ dx
);
29350 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
29351 hlinfo
->mouse_face_end_x
= 0;
29355 /* In R2L rows, show_mouse_face expects BEG and END
29356 coordinates to be swapped. */
29357 hlinfo
->mouse_face_end_col
= hpos
;
29358 hlinfo
->mouse_face_end_x
= original_x_pixel
29359 - (total_pixel_width
+ dx
);
29360 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
29361 hlinfo
->mouse_face_beg_x
= 0;
29364 hlinfo
->mouse_face_beg_row
= vpos
;
29365 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
29366 hlinfo
->mouse_face_past_end
= false;
29367 hlinfo
->mouse_face_window
= window
;
29369 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
29374 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29375 mouse_face_shown
= true;
29377 if (NILP (pointer
))
29382 /* If mouse-face doesn't need to be shown, clear any existing
29384 if ((area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
) && !mouse_face_shown
)
29385 clear_mouse_face (hlinfo
);
29387 #ifdef HAVE_WINDOW_SYSTEM
29388 if (FRAME_WINDOW_P (f
))
29389 define_frame_cursor1 (f
, cursor
, pointer
);
29395 Take proper action when the mouse has moved to position X, Y on
29396 frame F with regards to highlighting portions of display that have
29397 mouse-face properties. Also de-highlight portions of display where
29398 the mouse was before, set the mouse pointer shape as appropriate
29399 for the mouse coordinates, and activate help echo (tooltips).
29400 X and Y can be negative or out of range. */
29403 note_mouse_highlight (struct frame
*f
, int x
, int y
)
29405 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29406 enum window_part part
= ON_NOTHING
;
29407 Lisp_Object window
;
29409 Cursor cursor
= No_Cursor
;
29410 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
29413 /* When a menu is active, don't highlight because this looks odd. */
29414 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
29415 if (popup_activated ())
29419 if (!f
->glyphs_initialized_p
29420 || f
->pointer_invisible
)
29423 hlinfo
->mouse_face_mouse_x
= x
;
29424 hlinfo
->mouse_face_mouse_y
= y
;
29425 hlinfo
->mouse_face_mouse_frame
= f
;
29427 if (hlinfo
->mouse_face_defer
)
29430 /* Which window is that in? */
29431 window
= window_from_coordinates (f
, x
, y
, &part
, true);
29433 /* If displaying active text in another window, clear that. */
29434 if (! EQ (window
, hlinfo
->mouse_face_window
)
29435 /* Also clear if we move out of text area in same window. */
29436 || (!NILP (hlinfo
->mouse_face_window
)
29439 && part
!= ON_MODE_LINE
29440 && part
!= ON_HEADER_LINE
))
29441 clear_mouse_face (hlinfo
);
29443 /* Not on a window -> return. */
29444 if (!WINDOWP (window
))
29447 /* Reset help_echo_string. It will get recomputed below. */
29448 help_echo_string
= Qnil
;
29450 /* Convert to window-relative pixel coordinates. */
29451 w
= XWINDOW (window
);
29452 frame_to_window_pixel_xy (w
, &x
, &y
);
29454 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
29455 /* Handle tool-bar window differently since it doesn't display a
29457 if (EQ (window
, f
->tool_bar_window
))
29459 note_tool_bar_highlight (f
, x
, y
);
29464 /* Mouse is on the mode, header line or margin? */
29465 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
29466 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
29468 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
29470 #ifdef HAVE_WINDOW_SYSTEM
29471 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
29473 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29474 /* Show non-text cursor (Bug#16647). */
29482 #ifdef HAVE_WINDOW_SYSTEM
29483 if (part
== ON_VERTICAL_BORDER
)
29485 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29486 help_echo_string
= build_string ("drag-mouse-1: resize");
29488 else if (part
== ON_RIGHT_DIVIDER
)
29490 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29491 help_echo_string
= build_string ("drag-mouse-1: resize");
29493 else if (part
== ON_BOTTOM_DIVIDER
)
29494 if (! WINDOW_BOTTOMMOST_P (w
)
29496 || NILP (Vresize_mini_windows
))
29498 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
29499 help_echo_string
= build_string ("drag-mouse-1: resize");
29502 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29503 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
29504 || part
== ON_VERTICAL_SCROLL_BAR
29505 || part
== ON_HORIZONTAL_SCROLL_BAR
)
29506 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29508 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
29511 /* Are we in a window whose display is up to date?
29512 And verify the buffer's text has not changed. */
29513 b
= XBUFFER (w
->contents
);
29514 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
29516 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
29518 struct glyph
*glyph
;
29519 Lisp_Object object
;
29520 Lisp_Object mouse_face
= Qnil
, position
;
29521 Lisp_Object
*overlay_vec
= NULL
;
29522 ptrdiff_t i
, noverlays
;
29523 struct buffer
*obuf
;
29524 ptrdiff_t obegv
, ozv
;
29527 /* Find the glyph under X/Y. */
29528 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
29530 #ifdef HAVE_WINDOW_SYSTEM
29531 /* Look for :pointer property on image. */
29532 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
29534 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
29535 if (img
!= NULL
&& IMAGEP (img
->spec
))
29537 Lisp_Object image_map
, hotspot
;
29538 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
29540 && (hotspot
= find_hot_spot (image_map
,
29541 glyph
->slice
.img
.x
+ dx
,
29542 glyph
->slice
.img
.y
+ dy
),
29544 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29548 /* Could check XCAR (hotspot) to see if we enter/leave
29550 If so, we could look for mouse-enter, mouse-leave
29551 properties in PLIST (and do something...). */
29552 hotspot
= XCDR (hotspot
);
29553 if (CONSP (hotspot
)
29554 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29556 pointer
= Fplist_get (plist
, Qpointer
);
29557 if (NILP (pointer
))
29559 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
29560 if (!NILP (help_echo_string
))
29562 help_echo_window
= window
;
29563 help_echo_object
= glyph
->object
;
29564 help_echo_pos
= glyph
->charpos
;
29568 if (NILP (pointer
))
29569 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
29572 #endif /* HAVE_WINDOW_SYSTEM */
29574 /* Clear mouse face if X/Y not over text. */
29576 || area
!= TEXT_AREA
29577 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
29578 /* Glyph's OBJECT is nil for glyphs inserted by the
29579 display engine for its internal purposes, like truncation
29580 and continuation glyphs and blanks beyond the end of
29581 line's text on text terminals. If we are over such a
29582 glyph, we are not over any text. */
29583 || NILP (glyph
->object
)
29584 /* R2L rows have a stretch glyph at their front, which
29585 stands for no text, whereas L2R rows have no glyphs at
29586 all beyond the end of text. Treat such stretch glyphs
29587 like we do with NULL glyphs in L2R rows. */
29588 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
29589 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
29590 && glyph
->type
== STRETCH_GLYPH
29591 && glyph
->avoid_cursor_p
))
29593 if (clear_mouse_face (hlinfo
))
29594 cursor
= No_Cursor
;
29595 #ifdef HAVE_WINDOW_SYSTEM
29596 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
29598 if (area
!= TEXT_AREA
)
29599 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29601 pointer
= Vvoid_text_area_pointer
;
29607 pos
= glyph
->charpos
;
29608 object
= glyph
->object
;
29609 if (!STRINGP (object
) && !BUFFERP (object
))
29612 /* If we get an out-of-range value, return now; avoid an error. */
29613 if (BUFFERP (object
) && pos
> BUF_Z (b
))
29616 /* Make the window's buffer temporarily current for
29617 overlays_at and compute_char_face. */
29618 obuf
= current_buffer
;
29619 current_buffer
= b
;
29625 /* Is this char mouse-active or does it have help-echo? */
29626 position
= make_number (pos
);
29630 if (BUFFERP (object
))
29632 /* Put all the overlays we want in a vector in overlay_vec. */
29633 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, false);
29634 /* Sort overlays into increasing priority order. */
29635 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
29640 if (NILP (Vmouse_highlight
))
29642 clear_mouse_face (hlinfo
);
29643 goto check_help_echo
;
29646 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
29649 cursor
= No_Cursor
;
29651 /* Check mouse-face highlighting. */
29653 /* If there exists an overlay with mouse-face overlapping
29654 the one we are currently highlighting, we have to
29655 check if we enter the overlapping overlay, and then
29656 highlight only that. */
29657 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
29658 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
29660 /* Find the highest priority overlay with a mouse-face. */
29661 Lisp_Object overlay
= Qnil
;
29662 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
29664 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
29665 if (!NILP (mouse_face
))
29666 overlay
= overlay_vec
[i
];
29669 /* If we're highlighting the same overlay as before, there's
29670 no need to do that again. */
29671 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
29672 goto check_help_echo
;
29673 hlinfo
->mouse_face_overlay
= overlay
;
29675 /* Clear the display of the old active region, if any. */
29676 if (clear_mouse_face (hlinfo
))
29677 cursor
= No_Cursor
;
29679 /* If no overlay applies, get a text property. */
29680 if (NILP (overlay
))
29681 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
29683 /* Next, compute the bounds of the mouse highlighting and
29685 if (!NILP (mouse_face
) && STRINGP (object
))
29687 /* The mouse-highlighting comes from a display string
29688 with a mouse-face. */
29692 s
= Fprevious_single_property_change
29693 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
29694 e
= Fnext_single_property_change
29695 (position
, Qmouse_face
, object
, Qnil
);
29697 s
= make_number (0);
29699 e
= make_number (SCHARS (object
));
29700 mouse_face_from_string_pos (w
, hlinfo
, object
,
29701 XINT (s
), XINT (e
));
29702 hlinfo
->mouse_face_past_end
= false;
29703 hlinfo
->mouse_face_window
= window
;
29704 hlinfo
->mouse_face_face_id
29705 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
29706 glyph
->face_id
, true);
29707 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29708 cursor
= No_Cursor
;
29712 /* The mouse-highlighting, if any, comes from an overlay
29713 or text property in the buffer. */
29714 Lisp_Object buffer
IF_LINT (= Qnil
);
29715 Lisp_Object disp_string
IF_LINT (= Qnil
);
29717 if (STRINGP (object
))
29719 /* If we are on a display string with no mouse-face,
29720 check if the text under it has one. */
29721 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
29722 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29723 pos
= string_buffer_position (object
, start
);
29726 mouse_face
= get_char_property_and_overlay
29727 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
29728 buffer
= w
->contents
;
29729 disp_string
= object
;
29735 disp_string
= Qnil
;
29738 if (!NILP (mouse_face
))
29740 Lisp_Object before
, after
;
29741 Lisp_Object before_string
, after_string
;
29742 /* To correctly find the limits of mouse highlight
29743 in a bidi-reordered buffer, we must not use the
29744 optimization of limiting the search in
29745 previous-single-property-change and
29746 next-single-property-change, because
29747 rows_from_pos_range needs the real start and end
29748 positions to DTRT in this case. That's because
29749 the first row visible in a window does not
29750 necessarily display the character whose position
29751 is the smallest. */
29753 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
29754 ? Fmarker_position (w
->start
)
29757 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
29758 ? make_number (BUF_Z (XBUFFER (buffer
))
29759 - w
->window_end_pos
)
29762 if (NILP (overlay
))
29764 /* Handle the text property case. */
29765 before
= Fprevious_single_property_change
29766 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
29767 after
= Fnext_single_property_change
29768 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
29769 before_string
= after_string
= Qnil
;
29773 /* Handle the overlay case. */
29774 before
= Foverlay_start (overlay
);
29775 after
= Foverlay_end (overlay
);
29776 before_string
= Foverlay_get (overlay
, Qbefore_string
);
29777 after_string
= Foverlay_get (overlay
, Qafter_string
);
29779 if (!STRINGP (before_string
)) before_string
= Qnil
;
29780 if (!STRINGP (after_string
)) after_string
= Qnil
;
29783 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
29786 : XFASTINT (before
),
29788 ? BUF_Z (XBUFFER (buffer
))
29789 : XFASTINT (after
),
29790 before_string
, after_string
,
29792 cursor
= No_Cursor
;
29799 /* Look for a `help-echo' property. */
29800 if (NILP (help_echo_string
)) {
29801 Lisp_Object help
, overlay
;
29803 /* Check overlays first. */
29804 help
= overlay
= Qnil
;
29805 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
29807 overlay
= overlay_vec
[i
];
29808 help
= Foverlay_get (overlay
, Qhelp_echo
);
29813 help_echo_string
= help
;
29814 help_echo_window
= window
;
29815 help_echo_object
= overlay
;
29816 help_echo_pos
= pos
;
29820 Lisp_Object obj
= glyph
->object
;
29821 ptrdiff_t charpos
= glyph
->charpos
;
29823 /* Try text properties. */
29826 && charpos
< SCHARS (obj
))
29828 help
= Fget_text_property (make_number (charpos
),
29832 /* If the string itself doesn't specify a help-echo,
29833 see if the buffer text ``under'' it does. */
29834 struct glyph_row
*r
29835 = MATRIX_ROW (w
->current_matrix
, vpos
);
29836 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29837 ptrdiff_t p
= string_buffer_position (obj
, start
);
29840 help
= Fget_char_property (make_number (p
),
29841 Qhelp_echo
, w
->contents
);
29850 else if (BUFFERP (obj
)
29853 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
29858 help_echo_string
= help
;
29859 help_echo_window
= window
;
29860 help_echo_object
= obj
;
29861 help_echo_pos
= charpos
;
29866 #ifdef HAVE_WINDOW_SYSTEM
29867 /* Look for a `pointer' property. */
29868 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
29870 /* Check overlays first. */
29871 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
29872 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
29874 if (NILP (pointer
))
29876 Lisp_Object obj
= glyph
->object
;
29877 ptrdiff_t charpos
= glyph
->charpos
;
29879 /* Try text properties. */
29882 && charpos
< SCHARS (obj
))
29884 pointer
= Fget_text_property (make_number (charpos
),
29886 if (NILP (pointer
))
29888 /* If the string itself doesn't specify a pointer,
29889 see if the buffer text ``under'' it does. */
29890 struct glyph_row
*r
29891 = MATRIX_ROW (w
->current_matrix
, vpos
);
29892 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29893 ptrdiff_t p
= string_buffer_position (obj
, start
);
29895 pointer
= Fget_char_property (make_number (p
),
29896 Qpointer
, w
->contents
);
29899 else if (BUFFERP (obj
)
29902 pointer
= Fget_text_property (make_number (charpos
),
29906 #endif /* HAVE_WINDOW_SYSTEM */
29910 current_buffer
= obuf
;
29916 #ifdef HAVE_WINDOW_SYSTEM
29917 if (FRAME_WINDOW_P (f
))
29918 define_frame_cursor1 (f
, cursor
, pointer
);
29920 /* This is here to prevent a compiler error, about "label at end of
29921 compound statement". */
29928 Clear any mouse-face on window W. This function is part of the
29929 redisplay interface, and is called from try_window_id and similar
29930 functions to ensure the mouse-highlight is off. */
29933 x_clear_window_mouse_face (struct window
*w
)
29935 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
29936 Lisp_Object window
;
29939 XSETWINDOW (window
, w
);
29940 if (EQ (window
, hlinfo
->mouse_face_window
))
29941 clear_mouse_face (hlinfo
);
29947 Just discard the mouse face information for frame F, if any.
29948 This is used when the size of F is changed. */
29951 cancel_mouse_face (struct frame
*f
)
29953 Lisp_Object window
;
29954 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29956 window
= hlinfo
->mouse_face_window
;
29957 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
29958 reset_mouse_highlight (hlinfo
);
29963 /***********************************************************************
29965 ***********************************************************************/
29967 #ifdef HAVE_WINDOW_SYSTEM
29969 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
29970 which intersects rectangle R. R is in window-relative coordinates. */
29973 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
29974 enum glyph_row_area area
)
29976 struct glyph
*first
= row
->glyphs
[area
];
29977 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
29978 struct glyph
*last
;
29979 int first_x
, start_x
, x
;
29981 if (area
== TEXT_AREA
&& row
->fill_line_p
)
29982 /* If row extends face to end of line write the whole line. */
29983 draw_glyphs (w
, 0, row
, area
,
29984 0, row
->used
[area
],
29985 DRAW_NORMAL_TEXT
, 0);
29988 /* Set START_X to the window-relative start position for drawing glyphs of
29989 AREA. The first glyph of the text area can be partially visible.
29990 The first glyphs of other areas cannot. */
29991 start_x
= window_box_left_offset (w
, area
);
29993 if (area
== TEXT_AREA
)
29996 /* Find the first glyph that must be redrawn. */
29998 && x
+ first
->pixel_width
< r
->x
)
30000 x
+= first
->pixel_width
;
30004 /* Find the last one. */
30008 && x
< r
->x
+ r
->width
)
30010 x
+= last
->pixel_width
;
30016 draw_glyphs (w
, first_x
- start_x
, row
, area
,
30017 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
30018 DRAW_NORMAL_TEXT
, 0);
30023 /* Redraw the parts of the glyph row ROW on window W intersecting
30024 rectangle R. R is in window-relative coordinates. Value is
30025 true if mouse-face was overwritten. */
30028 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
30030 eassert (row
->enabled_p
);
30032 if (row
->mode_line_p
|| w
->pseudo_window_p
)
30033 draw_glyphs (w
, 0, row
, TEXT_AREA
,
30034 0, row
->used
[TEXT_AREA
],
30035 DRAW_NORMAL_TEXT
, 0);
30038 if (row
->used
[LEFT_MARGIN_AREA
])
30039 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
30040 if (row
->used
[TEXT_AREA
])
30041 expose_area (w
, row
, r
, TEXT_AREA
);
30042 if (row
->used
[RIGHT_MARGIN_AREA
])
30043 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
30044 draw_row_fringe_bitmaps (w
, row
);
30047 return row
->mouse_face_p
;
30051 /* Redraw those parts of glyphs rows during expose event handling that
30052 overlap other rows. Redrawing of an exposed line writes over parts
30053 of lines overlapping that exposed line; this function fixes that.
30055 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
30056 row in W's current matrix that is exposed and overlaps other rows.
30057 LAST_OVERLAPPING_ROW is the last such row. */
30060 expose_overlaps (struct window
*w
,
30061 struct glyph_row
*first_overlapping_row
,
30062 struct glyph_row
*last_overlapping_row
,
30065 struct glyph_row
*row
;
30067 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
30068 if (row
->overlapping_p
)
30070 eassert (row
->enabled_p
&& !row
->mode_line_p
);
30073 if (row
->used
[LEFT_MARGIN_AREA
])
30074 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
30076 if (row
->used
[TEXT_AREA
])
30077 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
30079 if (row
->used
[RIGHT_MARGIN_AREA
])
30080 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
30086 /* Return true if W's cursor intersects rectangle R. */
30089 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
30091 XRectangle cr
, result
;
30092 struct glyph
*cursor_glyph
;
30093 struct glyph_row
*row
;
30095 if (w
->phys_cursor
.vpos
>= 0
30096 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
30097 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
30099 && row
->cursor_in_fringe_p
)
30101 /* Cursor is in the fringe. */
30102 cr
.x
= window_box_right_offset (w
,
30103 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
30104 ? RIGHT_MARGIN_AREA
30107 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
30108 cr
.height
= row
->height
;
30109 return x_intersect_rectangles (&cr
, r
, &result
);
30112 cursor_glyph
= get_phys_cursor_glyph (w
);
30115 /* r is relative to W's box, but w->phys_cursor.x is relative
30116 to left edge of W's TEXT area. Adjust it. */
30117 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
30118 cr
.y
= w
->phys_cursor
.y
;
30119 cr
.width
= cursor_glyph
->pixel_width
;
30120 cr
.height
= w
->phys_cursor_height
;
30121 /* ++KFS: W32 version used W32-specific IntersectRect here, but
30122 I assume the effect is the same -- and this is portable. */
30123 return x_intersect_rectangles (&cr
, r
, &result
);
30125 /* If we don't understand the format, pretend we're not in the hot-spot. */
30131 Draw a vertical window border to the right of window W if W doesn't
30132 have vertical scroll bars. */
30135 x_draw_vertical_border (struct window
*w
)
30137 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30139 /* We could do better, if we knew what type of scroll-bar the adjacent
30140 windows (on either side) have... But we don't :-(
30141 However, I think this works ok. ++KFS 2003-04-25 */
30143 /* Redraw borders between horizontally adjacent windows. Don't
30144 do it for frames with vertical scroll bars because either the
30145 right scroll bar of a window, or the left scroll bar of its
30146 neighbor will suffice as a border. */
30147 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
30150 /* Note: It is necessary to redraw both the left and the right
30151 borders, for when only this single window W is being
30153 if (!WINDOW_RIGHTMOST_P (w
)
30154 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
30156 int x0
, x1
, y0
, y1
;
30158 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30161 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30164 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
30167 if (!WINDOW_LEFTMOST_P (w
)
30168 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
30170 int x0
, x1
, y0
, y1
;
30172 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30175 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30178 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
30183 /* Draw window dividers for window W. */
30186 x_draw_right_divider (struct window
*w
)
30188 struct frame
*f
= WINDOW_XFRAME (w
);
30190 if (w
->mini
|| w
->pseudo_window_p
)
30192 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30194 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
30195 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30196 int y0
= WINDOW_TOP_EDGE_Y (w
);
30197 /* The bottom divider prevails. */
30198 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30200 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30205 x_draw_bottom_divider (struct window
*w
)
30207 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30209 if (w
->mini
|| w
->pseudo_window_p
)
30211 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30213 int x0
= WINDOW_LEFT_EDGE_X (w
);
30214 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30215 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30216 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
30218 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30222 /* Redraw the part of window W intersection rectangle FR. Pixel
30223 coordinates in FR are frame-relative. Call this function with
30224 input blocked. Value is true if the exposure overwrites
30228 expose_window (struct window
*w
, XRectangle
*fr
)
30230 struct frame
*f
= XFRAME (w
->frame
);
30232 bool mouse_face_overwritten_p
= false;
30234 /* If window is not yet fully initialized, do nothing. This can
30235 happen when toolkit scroll bars are used and a window is split.
30236 Reconfiguring the scroll bar will generate an expose for a newly
30238 if (w
->current_matrix
== NULL
)
30241 /* When we're currently updating the window, display and current
30242 matrix usually don't agree. Arrange for a thorough display
30244 if (w
->must_be_updated_p
)
30246 SET_FRAME_GARBAGED (f
);
30250 /* Frame-relative pixel rectangle of W. */
30251 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
30252 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
30253 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
30254 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
30256 if (x_intersect_rectangles (fr
, &wr
, &r
))
30258 int yb
= window_text_bottom_y (w
);
30259 struct glyph_row
*row
;
30260 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
30262 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
30263 r
.x
, r
.y
, r
.width
, r
.height
));
30265 /* Convert to window coordinates. */
30266 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
30267 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
30269 /* Turn off the cursor. */
30270 bool cursor_cleared_p
= (!w
->pseudo_window_p
30271 && phys_cursor_in_rect_p (w
, &r
));
30272 if (cursor_cleared_p
)
30273 x_clear_cursor (w
);
30275 /* If the row containing the cursor extends face to end of line,
30276 then expose_area might overwrite the cursor outside the
30277 rectangle and thus notice_overwritten_cursor might clear
30278 w->phys_cursor_on_p. We remember the original value and
30279 check later if it is changed. */
30280 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
30282 /* Update lines intersecting rectangle R. */
30283 first_overlapping_row
= last_overlapping_row
= NULL
;
30284 for (row
= w
->current_matrix
->rows
;
30289 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
30291 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
30292 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
30293 || (r
.y
>= y0
&& r
.y
< y1
)
30294 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
30296 /* A header line may be overlapping, but there is no need
30297 to fix overlapping areas for them. KFS 2005-02-12 */
30298 if (row
->overlapping_p
&& !row
->mode_line_p
)
30300 if (first_overlapping_row
== NULL
)
30301 first_overlapping_row
= row
;
30302 last_overlapping_row
= row
;
30306 if (expose_line (w
, row
, &r
))
30307 mouse_face_overwritten_p
= true;
30310 else if (row
->overlapping_p
)
30312 /* We must redraw a row overlapping the exposed area. */
30314 ? y0
+ row
->phys_height
> r
.y
30315 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
30317 if (first_overlapping_row
== NULL
)
30318 first_overlapping_row
= row
;
30319 last_overlapping_row
= row
;
30327 /* Display the mode line if there is one. */
30328 if (WINDOW_WANTS_MODELINE_P (w
)
30329 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
30331 && row
->y
< r
.y
+ r
.height
)
30333 if (expose_line (w
, row
, &r
))
30334 mouse_face_overwritten_p
= true;
30337 if (!w
->pseudo_window_p
)
30339 /* Fix the display of overlapping rows. */
30340 if (first_overlapping_row
)
30341 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
30344 /* Draw border between windows. */
30345 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30346 x_draw_right_divider (w
);
30348 x_draw_vertical_border (w
);
30350 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30351 x_draw_bottom_divider (w
);
30353 /* Turn the cursor on again. */
30354 if (cursor_cleared_p
30355 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
30356 update_window_cursor (w
, true);
30360 return mouse_face_overwritten_p
;
30365 /* Redraw (parts) of all windows in the window tree rooted at W that
30366 intersect R. R contains frame pixel coordinates. Value is
30367 true if the exposure overwrites mouse-face. */
30370 expose_window_tree (struct window
*w
, XRectangle
*r
)
30372 struct frame
*f
= XFRAME (w
->frame
);
30373 bool mouse_face_overwritten_p
= false;
30375 while (w
&& !FRAME_GARBAGED_P (f
))
30377 mouse_face_overwritten_p
30378 |= (WINDOWP (w
->contents
)
30379 ? expose_window_tree (XWINDOW (w
->contents
), r
)
30380 : expose_window (w
, r
));
30382 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
30385 return mouse_face_overwritten_p
;
30390 Redisplay an exposed area of frame F. X and Y are the upper-left
30391 corner of the exposed rectangle. W and H are width and height of
30392 the exposed area. All are pixel values. W or H zero means redraw
30393 the entire frame. */
30396 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
30399 bool mouse_face_overwritten_p
= false;
30401 TRACE ((stderr
, "expose_frame "));
30403 /* No need to redraw if frame will be redrawn soon. */
30404 if (FRAME_GARBAGED_P (f
))
30406 TRACE ((stderr
, " garbaged\n"));
30410 /* If basic faces haven't been realized yet, there is no point in
30411 trying to redraw anything. This can happen when we get an expose
30412 event while Emacs is starting, e.g. by moving another window. */
30413 if (FRAME_FACE_CACHE (f
) == NULL
30414 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
30416 TRACE ((stderr
, " no faces\n"));
30420 if (w
== 0 || h
== 0)
30423 r
.width
= FRAME_TEXT_WIDTH (f
);
30424 r
.height
= FRAME_TEXT_HEIGHT (f
);
30434 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
30435 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
30437 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
30438 if (WINDOWP (f
->tool_bar_window
))
30439 mouse_face_overwritten_p
30440 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
30443 #ifdef HAVE_X_WINDOWS
30445 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
30446 if (WINDOWP (f
->menu_bar_window
))
30447 mouse_face_overwritten_p
30448 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
30449 #endif /* not USE_X_TOOLKIT and not USE_GTK */
30453 /* Some window managers support a focus-follows-mouse style with
30454 delayed raising of frames. Imagine a partially obscured frame,
30455 and moving the mouse into partially obscured mouse-face on that
30456 frame. The visible part of the mouse-face will be highlighted,
30457 then the WM raises the obscured frame. With at least one WM, KDE
30458 2.1, Emacs is not getting any event for the raising of the frame
30459 (even tried with SubstructureRedirectMask), only Expose events.
30460 These expose events will draw text normally, i.e. not
30461 highlighted. Which means we must redo the highlight here.
30462 Subsume it under ``we love X''. --gerd 2001-08-15 */
30463 /* Included in Windows version because Windows most likely does not
30464 do the right thing if any third party tool offers
30465 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
30466 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
30468 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
30469 if (f
== hlinfo
->mouse_face_mouse_frame
)
30471 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
30472 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
30473 clear_mouse_face (hlinfo
);
30474 note_mouse_highlight (f
, mouse_x
, mouse_y
);
30481 Determine the intersection of two rectangles R1 and R2. Return
30482 the intersection in *RESULT. Value is true if RESULT is not
30486 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
30488 XRectangle
*left
, *right
;
30489 XRectangle
*upper
, *lower
;
30490 bool intersection_p
= false;
30492 /* Rearrange so that R1 is the left-most rectangle. */
30494 left
= r1
, right
= r2
;
30496 left
= r2
, right
= r1
;
30498 /* X0 of the intersection is right.x0, if this is inside R1,
30499 otherwise there is no intersection. */
30500 if (right
->x
<= left
->x
+ left
->width
)
30502 result
->x
= right
->x
;
30504 /* The right end of the intersection is the minimum of
30505 the right ends of left and right. */
30506 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
30509 /* Same game for Y. */
30511 upper
= r1
, lower
= r2
;
30513 upper
= r2
, lower
= r1
;
30515 /* The upper end of the intersection is lower.y0, if this is inside
30516 of upper. Otherwise, there is no intersection. */
30517 if (lower
->y
<= upper
->y
+ upper
->height
)
30519 result
->y
= lower
->y
;
30521 /* The lower end of the intersection is the minimum of the lower
30522 ends of upper and lower. */
30523 result
->height
= (min (lower
->y
+ lower
->height
,
30524 upper
->y
+ upper
->height
)
30526 intersection_p
= true;
30530 return intersection_p
;
30533 #endif /* HAVE_WINDOW_SYSTEM */
30536 /***********************************************************************
30538 ***********************************************************************/
30541 syms_of_xdisp (void)
30543 Vwith_echo_area_save_vector
= Qnil
;
30544 staticpro (&Vwith_echo_area_save_vector
);
30546 Vmessage_stack
= Qnil
;
30547 staticpro (&Vmessage_stack
);
30549 /* Non-nil means don't actually do any redisplay. */
30550 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
30552 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
30554 DEFVAR_BOOL("inhibit-message", inhibit_message
,
30555 doc
: /* Non-nil means calls to `message' are not displayed.
30556 They are still logged to the *Messages* buffer. */);
30557 inhibit_message
= 0;
30559 message_dolog_marker1
= Fmake_marker ();
30560 staticpro (&message_dolog_marker1
);
30561 message_dolog_marker2
= Fmake_marker ();
30562 staticpro (&message_dolog_marker2
);
30563 message_dolog_marker3
= Fmake_marker ();
30564 staticpro (&message_dolog_marker3
);
30567 defsubr (&Sdump_frame_glyph_matrix
);
30568 defsubr (&Sdump_glyph_matrix
);
30569 defsubr (&Sdump_glyph_row
);
30570 defsubr (&Sdump_tool_bar_row
);
30571 defsubr (&Strace_redisplay
);
30572 defsubr (&Strace_to_stderr
);
30574 #ifdef HAVE_WINDOW_SYSTEM
30575 defsubr (&Stool_bar_height
);
30576 defsubr (&Slookup_image_map
);
30578 defsubr (&Sline_pixel_height
);
30579 defsubr (&Sformat_mode_line
);
30580 defsubr (&Sinvisible_p
);
30581 defsubr (&Scurrent_bidi_paragraph_direction
);
30582 defsubr (&Swindow_text_pixel_size
);
30583 defsubr (&Smove_point_visually
);
30584 defsubr (&Sbidi_find_overridden_directionality
);
30586 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
30587 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
30588 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
30589 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
30590 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
30591 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
30592 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
30593 DEFSYM (Qeval
, "eval");
30594 DEFSYM (QCdata
, ":data");
30596 /* Names of text properties relevant for redisplay. */
30597 DEFSYM (Qdisplay
, "display");
30598 DEFSYM (Qspace_width
, "space-width");
30599 DEFSYM (Qraise
, "raise");
30600 DEFSYM (Qslice
, "slice");
30601 DEFSYM (Qspace
, "space");
30602 DEFSYM (Qmargin
, "margin");
30603 DEFSYM (Qpointer
, "pointer");
30604 DEFSYM (Qleft_margin
, "left-margin");
30605 DEFSYM (Qright_margin
, "right-margin");
30606 DEFSYM (Qcenter
, "center");
30607 DEFSYM (Qline_height
, "line-height");
30608 DEFSYM (QCalign_to
, ":align-to");
30609 DEFSYM (QCrelative_width
, ":relative-width");
30610 DEFSYM (QCrelative_height
, ":relative-height");
30611 DEFSYM (QCeval
, ":eval");
30612 DEFSYM (QCpropertize
, ":propertize");
30613 DEFSYM (QCfile
, ":file");
30614 DEFSYM (Qfontified
, "fontified");
30615 DEFSYM (Qfontification_functions
, "fontification-functions");
30617 /* Name of the face used to highlight trailing whitespace. */
30618 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
30620 /* Name and number of the face used to highlight escape glyphs. */
30621 DEFSYM (Qescape_glyph
, "escape-glyph");
30623 /* Name and number of the face used to highlight non-breaking spaces. */
30624 DEFSYM (Qnobreak_space
, "nobreak-space");
30626 /* The symbol 'image' which is the car of the lists used to represent
30627 images in Lisp. Also a tool bar style. */
30628 DEFSYM (Qimage
, "image");
30630 /* Tool bar styles. */
30631 DEFSYM (Qtext
, "text");
30632 DEFSYM (Qboth
, "both");
30633 DEFSYM (Qboth_horiz
, "both-horiz");
30634 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
30636 /* The image map types. */
30637 DEFSYM (QCmap
, ":map");
30638 DEFSYM (QCpointer
, ":pointer");
30639 DEFSYM (Qrect
, "rect");
30640 DEFSYM (Qcircle
, "circle");
30641 DEFSYM (Qpoly
, "poly");
30643 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
30644 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
30645 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
30647 DEFSYM (Qgrow_only
, "grow-only");
30648 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
30649 DEFSYM (Qposition
, "position");
30650 DEFSYM (Qbuffer_position
, "buffer-position");
30651 DEFSYM (Qobject
, "object");
30653 /* Cursor shapes. */
30654 DEFSYM (Qbar
, "bar");
30655 DEFSYM (Qhbar
, "hbar");
30656 DEFSYM (Qbox
, "box");
30657 DEFSYM (Qhollow
, "hollow");
30659 /* Pointer shapes. */
30660 DEFSYM (Qhand
, "hand");
30661 DEFSYM (Qarrow
, "arrow");
30664 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
30666 list_of_error
= list1 (list2 (Qerror
, Qvoid_variable
));
30667 staticpro (&list_of_error
);
30669 /* Values of those variables at last redisplay are stored as
30670 properties on 'overlay-arrow-position' symbol. However, if
30671 Voverlay_arrow_position is a marker, last-arrow-position is its
30672 numerical position. */
30673 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
30674 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
30676 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
30677 properties on a symbol in overlay-arrow-variable-list. */
30678 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
30679 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
30681 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
30682 staticpro (&echo_buffer
[0]);
30683 staticpro (&echo_buffer
[1]);
30685 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
30686 staticpro (&echo_area_buffer
[0]);
30687 staticpro (&echo_area_buffer
[1]);
30689 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
30690 staticpro (&Vmessages_buffer_name
);
30692 mode_line_proptrans_alist
= Qnil
;
30693 staticpro (&mode_line_proptrans_alist
);
30694 mode_line_string_list
= Qnil
;
30695 staticpro (&mode_line_string_list
);
30696 mode_line_string_face
= Qnil
;
30697 staticpro (&mode_line_string_face
);
30698 mode_line_string_face_prop
= Qnil
;
30699 staticpro (&mode_line_string_face_prop
);
30700 Vmode_line_unwind_vector
= Qnil
;
30701 staticpro (&Vmode_line_unwind_vector
);
30703 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
30705 help_echo_string
= Qnil
;
30706 staticpro (&help_echo_string
);
30707 help_echo_object
= Qnil
;
30708 staticpro (&help_echo_object
);
30709 help_echo_window
= Qnil
;
30710 staticpro (&help_echo_window
);
30711 previous_help_echo_string
= Qnil
;
30712 staticpro (&previous_help_echo_string
);
30713 help_echo_pos
= -1;
30715 DEFSYM (Qright_to_left
, "right-to-left");
30716 DEFSYM (Qleft_to_right
, "left-to-right");
30717 defsubr (&Sbidi_resolved_levels
);
30719 #ifdef HAVE_WINDOW_SYSTEM
30720 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
30721 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
30722 For example, if a block cursor is over a tab, it will be drawn as
30723 wide as that tab on the display. */);
30724 x_stretch_cursor_p
= 0;
30727 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
30728 doc
: /* Non-nil means highlight trailing whitespace.
30729 The face used for trailing whitespace is `trailing-whitespace'. */);
30730 Vshow_trailing_whitespace
= Qnil
;
30732 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
30733 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
30734 If the value is t, Emacs highlights non-ASCII chars which have the
30735 same appearance as an ASCII space or hyphen, using the `nobreak-space'
30736 or `escape-glyph' face respectively.
30738 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
30739 U+2011 (non-breaking hyphen) are affected.
30741 Any other non-nil value means to display these characters as a escape
30742 glyph followed by an ordinary space or hyphen.
30744 A value of nil means no special handling of these characters. */);
30745 Vnobreak_char_display
= Qt
;
30747 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
30748 doc
: /* The pointer shape to show in void text areas.
30749 A value of nil means to show the text pointer. Other options are
30750 `arrow', `text', `hand', `vdrag', `hdrag', `nhdrag', `modeline', and
30752 Vvoid_text_area_pointer
= Qarrow
;
30754 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
30755 doc
: /* Non-nil means don't actually do any redisplay.
30756 This is used for internal purposes. */);
30757 Vinhibit_redisplay
= Qnil
;
30759 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
30760 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
30761 Vglobal_mode_string
= Qnil
;
30763 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
30764 doc
: /* Marker for where to display an arrow on top of the buffer text.
30765 This must be the beginning of a line in order to work.
30766 See also `overlay-arrow-string'. */);
30767 Voverlay_arrow_position
= Qnil
;
30769 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
30770 doc
: /* String to display as an arrow in non-window frames.
30771 See also `overlay-arrow-position'. */);
30772 Voverlay_arrow_string
= build_pure_c_string ("=>");
30774 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
30775 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
30776 The symbols on this list are examined during redisplay to determine
30777 where to display overlay arrows. */);
30778 Voverlay_arrow_variable_list
30779 = list1 (intern_c_string ("overlay-arrow-position"));
30781 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
30782 doc
: /* The number of lines to try scrolling a window by when point moves out.
30783 If that fails to bring point back on frame, point is centered instead.
30784 If this is zero, point is always centered after it moves off frame.
30785 If you want scrolling to always be a line at a time, you should set
30786 `scroll-conservatively' to a large value rather than set this to 1. */);
30788 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
30789 doc
: /* Scroll up to this many lines, to bring point back on screen.
30790 If point moves off-screen, redisplay will scroll by up to
30791 `scroll-conservatively' lines in order to bring point just barely
30792 onto the screen again. If that cannot be done, then redisplay
30793 recenters point as usual.
30795 If the value is greater than 100, redisplay will never recenter point,
30796 but will always scroll just enough text to bring point into view, even
30797 if you move far away.
30799 A value of zero means always recenter point if it moves off screen. */);
30800 scroll_conservatively
= 0;
30802 DEFVAR_INT ("scroll-margin", scroll_margin
,
30803 doc
: /* Number of lines of margin at the top and bottom of a window.
30804 Recenter the window whenever point gets within this many lines
30805 of the top or bottom of the window. */);
30808 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
30809 doc
: /* Pixels per inch value for non-window system displays.
30810 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
30811 Vdisplay_pixels_per_inch
= make_float (72.0);
30814 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
30817 DEFVAR_LISP ("truncate-partial-width-windows",
30818 Vtruncate_partial_width_windows
,
30819 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
30820 For an integer value, truncate lines in each window narrower than the
30821 full frame width, provided the window width is less than that integer;
30822 otherwise, respect the value of `truncate-lines'.
30824 For any other non-nil value, truncate lines in all windows that do
30825 not span the full frame width.
30827 A value of nil means to respect the value of `truncate-lines'.
30829 If `word-wrap' is enabled, you might want to reduce this. */);
30830 Vtruncate_partial_width_windows
= make_number (50);
30832 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
30833 doc
: /* Maximum buffer size for which line number should be displayed.
30834 If the buffer is bigger than this, the line number does not appear
30835 in the mode line. A value of nil means no limit. */);
30836 Vline_number_display_limit
= Qnil
;
30838 DEFVAR_INT ("line-number-display-limit-width",
30839 line_number_display_limit_width
,
30840 doc
: /* Maximum line width (in characters) for line number display.
30841 If the average length of the lines near point is bigger than this, then the
30842 line number may be omitted from the mode line. */);
30843 line_number_display_limit_width
= 200;
30845 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
30846 doc
: /* Non-nil means highlight region even in nonselected windows. */);
30847 highlight_nonselected_windows
= false;
30849 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
30850 doc
: /* Non-nil if more than one frame is visible on this display.
30851 Minibuffer-only frames don't count, but iconified frames do.
30852 This variable is not guaranteed to be accurate except while processing
30853 `frame-title-format' and `icon-title-format'. */);
30855 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
30856 doc
: /* Template for displaying the title bar of visible frames.
30857 \(Assuming the window manager supports this feature.)
30859 This variable has the same structure as `mode-line-format', except that
30860 the %c and %l constructs are ignored. It is used only on frames for
30861 which no explicit name has been set \(see `modify-frame-parameters'). */);
30863 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
30864 doc
: /* Template for displaying the title bar of an iconified frame.
30865 \(Assuming the window manager supports this feature.)
30866 This variable has the same structure as `mode-line-format' (which see),
30867 and is used only on frames for which no explicit name has been set
30868 \(see `modify-frame-parameters'). */);
30870 = Vframe_title_format
30871 = listn (CONSTYPE_PURE
, 3,
30872 intern_c_string ("multiple-frames"),
30873 build_pure_c_string ("%b"),
30874 listn (CONSTYPE_PURE
, 4,
30875 empty_unibyte_string
,
30876 intern_c_string ("invocation-name"),
30877 build_pure_c_string ("@"),
30878 intern_c_string ("system-name")));
30880 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
30881 doc
: /* Maximum number of lines to keep in the message log buffer.
30882 If nil, disable message logging. If t, log messages but don't truncate
30883 the buffer when it becomes large. */);
30884 Vmessage_log_max
= make_number (1000);
30886 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
30887 doc
: /* Functions called before redisplay, if window sizes have changed.
30888 The value should be a list of functions that take one argument.
30889 Just before redisplay, for each frame, if any of its windows have changed
30890 size since the last redisplay, or have been split or deleted,
30891 all the functions in the list are called, with the frame as argument. */);
30892 Vwindow_size_change_functions
= Qnil
;
30894 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
30895 doc
: /* List of functions to call before redisplaying a window with scrolling.
30896 Each function is called with two arguments, the window and its new
30897 display-start position.
30898 These functions are called whenever the `window-start' marker is modified,
30899 either to point into another buffer (e.g. via `set-window-buffer') or another
30900 place in the same buffer.
30901 Note that the value of `window-end' is not valid when these functions are
30904 Warning: Do not use this feature to alter the way the window
30905 is scrolled. It is not designed for that, and such use probably won't
30907 Vwindow_scroll_functions
= Qnil
;
30909 DEFVAR_LISP ("window-text-change-functions",
30910 Vwindow_text_change_functions
,
30911 doc
: /* Functions to call in redisplay when text in the window might change. */);
30912 Vwindow_text_change_functions
= Qnil
;
30914 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
30915 doc
: /* Functions called when redisplay of a window reaches the end trigger.
30916 Each function is called with two arguments, the window and the end trigger value.
30917 See `set-window-redisplay-end-trigger'. */);
30918 Vredisplay_end_trigger_functions
= Qnil
;
30920 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
30921 doc
: /* Non-nil means autoselect window with mouse pointer.
30922 If nil, do not autoselect windows.
30923 A positive number means delay autoselection by that many seconds: a
30924 window is autoselected only after the mouse has remained in that
30925 window for the duration of the delay.
30926 A negative number has a similar effect, but causes windows to be
30927 autoselected only after the mouse has stopped moving. \(Because of
30928 the way Emacs compares mouse events, you will occasionally wait twice
30929 that time before the window gets selected.\)
30930 Any other value means to autoselect window instantaneously when the
30931 mouse pointer enters it.
30933 Autoselection selects the minibuffer only if it is active, and never
30934 unselects the minibuffer if it is active.
30936 When customizing this variable make sure that the actual value of
30937 `focus-follows-mouse' matches the behavior of your window manager. */);
30938 Vmouse_autoselect_window
= Qnil
;
30940 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
30941 doc
: /* Non-nil means automatically resize tool-bars.
30942 This dynamically changes the tool-bar's height to the minimum height
30943 that is needed to make all tool-bar items visible.
30944 If value is `grow-only', the tool-bar's height is only increased
30945 automatically; to decrease the tool-bar height, use \\[recenter]. */);
30946 Vauto_resize_tool_bars
= Qt
;
30948 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
30949 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
30950 auto_raise_tool_bar_buttons_p
= true;
30952 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
30953 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
30954 make_cursor_line_fully_visible_p
= true;
30956 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
30957 doc
: /* Border below tool-bar in pixels.
30958 If an integer, use it as the height of the border.
30959 If it is one of `internal-border-width' or `border-width', use the
30960 value of the corresponding frame parameter.
30961 Otherwise, no border is added below the tool-bar. */);
30962 Vtool_bar_border
= Qinternal_border_width
;
30964 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
30965 doc
: /* Margin around tool-bar buttons in pixels.
30966 If an integer, use that for both horizontal and vertical margins.
30967 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
30968 HORZ specifying the horizontal margin, and VERT specifying the
30969 vertical margin. */);
30970 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
30972 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
30973 doc
: /* Relief thickness of tool-bar buttons. */);
30974 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
30976 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
30977 doc
: /* Tool bar style to use.
30979 image - show images only
30980 text - show text only
30981 both - show both, text below image
30982 both-horiz - show text to the right of the image
30983 text-image-horiz - show text to the left of the image
30984 any other - use system default or image if no system default.
30986 This variable only affects the GTK+ toolkit version of Emacs. */);
30987 Vtool_bar_style
= Qnil
;
30989 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
30990 doc
: /* Maximum number of characters a label can have to be shown.
30991 The tool bar style must also show labels for this to have any effect, see
30992 `tool-bar-style'. */);
30993 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
30995 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
30996 doc
: /* List of functions to call to fontify regions of text.
30997 Each function is called with one argument POS. Functions must
30998 fontify a region starting at POS in the current buffer, and give
30999 fontified regions the property `fontified'. */);
31000 Vfontification_functions
= Qnil
;
31001 Fmake_variable_buffer_local (Qfontification_functions
);
31003 DEFVAR_BOOL ("unibyte-display-via-language-environment",
31004 unibyte_display_via_language_environment
,
31005 doc
: /* Non-nil means display unibyte text according to language environment.
31006 Specifically, this means that raw bytes in the range 160-255 decimal
31007 are displayed by converting them to the equivalent multibyte characters
31008 according to the current language environment. As a result, they are
31009 displayed according to the current fontset.
31011 Note that this variable affects only how these bytes are displayed,
31012 but does not change the fact they are interpreted as raw bytes. */);
31013 unibyte_display_via_language_environment
= false;
31015 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
31016 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
31017 If a float, it specifies a fraction of the mini-window frame's height.
31018 If an integer, it specifies a number of lines. */);
31019 Vmax_mini_window_height
= make_float (0.25);
31021 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
31022 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
31023 A value of nil means don't automatically resize mini-windows.
31024 A value of t means resize them to fit the text displayed in them.
31025 A value of `grow-only', the default, means let mini-windows grow only;
31026 they return to their normal size when the minibuffer is closed, or the
31027 echo area becomes empty. */);
31028 Vresize_mini_windows
= Qgrow_only
;
31030 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
31031 doc
: /* Alist specifying how to blink the cursor off.
31032 Each element has the form (ON-STATE . OFF-STATE). Whenever the
31033 `cursor-type' frame-parameter or variable equals ON-STATE,
31034 comparing using `equal', Emacs uses OFF-STATE to specify
31035 how to blink it off. ON-STATE and OFF-STATE are values for
31036 the `cursor-type' frame parameter.
31038 If a frame's ON-STATE has no entry in this list,
31039 the frame's other specifications determine how to blink the cursor off. */);
31040 Vblink_cursor_alist
= Qnil
;
31042 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
31043 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
31044 If non-nil, windows are automatically scrolled horizontally to make
31045 point visible. */);
31046 automatic_hscrolling_p
= true;
31047 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
31049 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
31050 doc
: /* How many columns away from the window edge point is allowed to get
31051 before automatic hscrolling will horizontally scroll the window. */);
31052 hscroll_margin
= 5;
31054 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
31055 doc
: /* How many columns to scroll the window when point gets too close to the edge.
31056 When point is less than `hscroll-margin' columns from the window
31057 edge, automatic hscrolling will scroll the window by the amount of columns
31058 determined by this variable. If its value is a positive integer, scroll that
31059 many columns. If it's a positive floating-point number, it specifies the
31060 fraction of the window's width to scroll. If it's nil or zero, point will be
31061 centered horizontally after the scroll. Any other value, including negative
31062 numbers, are treated as if the value were zero.
31064 Automatic hscrolling always moves point outside the scroll margin, so if
31065 point was more than scroll step columns inside the margin, the window will
31066 scroll more than the value given by the scroll step.
31068 Note that the lower bound for automatic hscrolling specified by `scroll-left'
31069 and `scroll-right' overrides this variable's effect. */);
31070 Vhscroll_step
= make_number (0);
31072 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
31073 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
31074 Bind this around calls to `message' to let it take effect. */);
31075 message_truncate_lines
= false;
31077 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
31078 doc
: /* Normal hook run to update the menu bar definitions.
31079 Redisplay runs this hook before it redisplays the menu bar.
31080 This is used to update menus such as Buffers, whose contents depend on
31082 Vmenu_bar_update_hook
= Qnil
;
31084 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
31085 doc
: /* Frame for which we are updating a menu.
31086 The enable predicate for a menu binding should check this variable. */);
31087 Vmenu_updating_frame
= Qnil
;
31089 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
31090 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
31091 inhibit_menubar_update
= false;
31093 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
31094 doc
: /* Prefix prepended to all continuation lines at display time.
31095 The value may be a string, an image, or a stretch-glyph; it is
31096 interpreted in the same way as the value of a `display' text property.
31098 This variable is overridden by any `wrap-prefix' text or overlay
31101 To add a prefix to non-continuation lines, use `line-prefix'. */);
31102 Vwrap_prefix
= Qnil
;
31103 DEFSYM (Qwrap_prefix
, "wrap-prefix");
31104 Fmake_variable_buffer_local (Qwrap_prefix
);
31106 DEFVAR_LISP ("line-prefix", Vline_prefix
,
31107 doc
: /* Prefix prepended to all non-continuation lines at display time.
31108 The value may be a string, an image, or a stretch-glyph; it is
31109 interpreted in the same way as the value of a `display' text property.
31111 This variable is overridden by any `line-prefix' text or overlay
31114 To add a prefix to continuation lines, use `wrap-prefix'. */);
31115 Vline_prefix
= Qnil
;
31116 DEFSYM (Qline_prefix
, "line-prefix");
31117 Fmake_variable_buffer_local (Qline_prefix
);
31119 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
31120 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
31121 inhibit_eval_during_redisplay
= false;
31123 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
31124 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
31125 inhibit_free_realized_faces
= false;
31127 DEFVAR_BOOL ("inhibit-bidi-mirroring", inhibit_bidi_mirroring
,
31128 doc
: /* Non-nil means don't mirror characters even when bidi context requires that.
31129 Intended for use during debugging and for testing bidi display;
31130 see biditest.el in the test suite. */);
31131 inhibit_bidi_mirroring
= false;
31134 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
31135 doc
: /* Inhibit try_window_id display optimization. */);
31136 inhibit_try_window_id
= false;
31138 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
31139 doc
: /* Inhibit try_window_reusing display optimization. */);
31140 inhibit_try_window_reusing
= false;
31142 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
31143 doc
: /* Inhibit try_cursor_movement display optimization. */);
31144 inhibit_try_cursor_movement
= false;
31145 #endif /* GLYPH_DEBUG */
31147 DEFVAR_INT ("overline-margin", overline_margin
,
31148 doc
: /* Space between overline and text, in pixels.
31149 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
31150 margin to the character height. */);
31151 overline_margin
= 2;
31153 DEFVAR_INT ("underline-minimum-offset",
31154 underline_minimum_offset
,
31155 doc
: /* Minimum distance between baseline and underline.
31156 This can improve legibility of underlined text at small font sizes,
31157 particularly when using variable `x-use-underline-position-properties'
31158 with fonts that specify an UNDERLINE_POSITION relatively close to the
31159 baseline. The default value is 1. */);
31160 underline_minimum_offset
= 1;
31162 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
31163 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
31164 This feature only works when on a window system that can change
31165 cursor shapes. */);
31166 display_hourglass_p
= true;
31168 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
31169 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
31170 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
31172 #ifdef HAVE_WINDOW_SYSTEM
31173 hourglass_atimer
= NULL
;
31174 hourglass_shown_p
= false;
31175 #endif /* HAVE_WINDOW_SYSTEM */
31177 /* Name of the face used to display glyphless characters. */
31178 DEFSYM (Qglyphless_char
, "glyphless-char");
31180 /* Method symbols for Vglyphless_char_display. */
31181 DEFSYM (Qhex_code
, "hex-code");
31182 DEFSYM (Qempty_box
, "empty-box");
31183 DEFSYM (Qthin_space
, "thin-space");
31184 DEFSYM (Qzero_width
, "zero-width");
31186 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
31187 doc
: /* Function run just before redisplay.
31188 It is called with one argument, which is the set of windows that are to
31189 be redisplayed. This set can be nil (meaning, only the selected window),
31190 or t (meaning all windows). */);
31191 Vpre_redisplay_function
= intern ("ignore");
31193 /* Symbol for the purpose of Vglyphless_char_display. */
31194 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
31195 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
31197 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
31198 doc
: /* Char-table defining glyphless characters.
31199 Each element, if non-nil, should be one of the following:
31200 an ASCII acronym string: display this string in a box
31201 `hex-code': display the hexadecimal code of a character in a box
31202 `empty-box': display as an empty box
31203 `thin-space': display as 1-pixel width space
31204 `zero-width': don't display
31205 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
31206 display method for graphical terminals and text terminals respectively.
31207 GRAPHICAL and TEXT should each have one of the values listed above.
31209 The char-table has one extra slot to control the display of a character for
31210 which no font is found. This slot only takes effect on graphical terminals.
31211 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
31212 `thin-space'. The default is `empty-box'.
31214 If a character has a non-nil entry in an active display table, the
31215 display table takes effect; in this case, Emacs does not consult
31216 `glyphless-char-display' at all. */);
31217 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
31218 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
31221 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
31222 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
31223 Vdebug_on_message
= Qnil
;
31225 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
31227 Vredisplay__all_windows_cause
31228 = Fmake_vector (make_number (100), make_number (0));
31230 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
31232 Vredisplay__mode_lines_cause
31233 = Fmake_vector (make_number (100), make_number (0));
31237 /* Initialize this module when Emacs starts. */
31242 CHARPOS (this_line_start_pos
) = 0;
31244 if (!noninteractive
)
31246 struct window
*m
= XWINDOW (minibuf_window
);
31247 Lisp_Object frame
= m
->frame
;
31248 struct frame
*f
= XFRAME (frame
);
31249 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
31250 struct window
*r
= XWINDOW (root
);
31253 echo_area_window
= minibuf_window
;
31255 r
->top_line
= FRAME_TOP_MARGIN (f
);
31256 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
31257 r
->total_cols
= FRAME_COLS (f
);
31258 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31259 r
->total_lines
= FRAME_TOTAL_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
31260 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
31262 m
->top_line
= FRAME_TOTAL_LINES (f
) - 1;
31263 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
31264 m
->total_cols
= FRAME_COLS (f
);
31265 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31266 m
->total_lines
= 1;
31267 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
31269 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
31270 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
31271 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
31273 /* The default ellipsis glyphs `...'. */
31274 for (i
= 0; i
< 3; ++i
)
31275 default_invis_vector
[i
] = make_number ('.');
31279 /* Allocate the buffer for frame titles.
31280 Also used for `format-mode-line'. */
31282 mode_line_noprop_buf
= xmalloc (size
);
31283 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
31284 mode_line_noprop_ptr
= mode_line_noprop_buf
;
31285 mode_line_target
= MODE_LINE_DISPLAY
;
31288 help_echo_showing_p
= false;
31291 #ifdef HAVE_WINDOW_SYSTEM
31293 /* Platform-independent portion of hourglass implementation. */
31295 /* Timer function of hourglass_atimer. */
31298 show_hourglass (struct atimer
*timer
)
31300 /* The timer implementation will cancel this timer automatically
31301 after this function has run. Set hourglass_atimer to null
31302 so that we know the timer doesn't have to be canceled. */
31303 hourglass_atimer
= NULL
;
31305 if (!hourglass_shown_p
)
31307 Lisp_Object tail
, frame
;
31311 FOR_EACH_FRAME (tail
, frame
)
31313 struct frame
*f
= XFRAME (frame
);
31315 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31316 && FRAME_RIF (f
)->show_hourglass
)
31317 FRAME_RIF (f
)->show_hourglass (f
);
31320 hourglass_shown_p
= true;
31325 /* Cancel a currently active hourglass timer, and start a new one. */
31328 start_hourglass (void)
31330 struct timespec delay
;
31332 cancel_hourglass ();
31334 if (INTEGERP (Vhourglass_delay
)
31335 && XINT (Vhourglass_delay
) > 0)
31336 delay
= make_timespec (min (XINT (Vhourglass_delay
),
31337 TYPE_MAXIMUM (time_t)),
31339 else if (FLOATP (Vhourglass_delay
)
31340 && XFLOAT_DATA (Vhourglass_delay
) > 0)
31341 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
31343 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
31345 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
31346 show_hourglass
, NULL
);
31349 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
31353 cancel_hourglass (void)
31355 if (hourglass_atimer
)
31357 cancel_atimer (hourglass_atimer
);
31358 hourglass_atimer
= NULL
;
31361 if (hourglass_shown_p
)
31363 Lisp_Object tail
, frame
;
31367 FOR_EACH_FRAME (tail
, frame
)
31369 struct frame
*f
= XFRAME (frame
);
31371 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31372 && FRAME_RIF (f
)->hide_hourglass
)
31373 FRAME_RIF (f
)->hide_hourglass (f
);
31375 /* No cursors on non GUI frames - restore to stock arrow cursor. */
31376 else if (!FRAME_W32_P (f
))
31377 w32_arrow_cursor ();
31381 hourglass_shown_p
= false;
31386 #endif /* HAVE_WINDOW_SYSTEM */